]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.5.2-201208222031.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.5.2-201208222031.patch
CommitLineData
911f1fc3
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 5caa2fa..5fc9329 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 GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS 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+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
379+$(filter-out $(init-y),$(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..9ac0642 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+" subs %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+" sbcs %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+" sbcs %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+" adcs %H0, %H0, %H6\n"
1394+
1395+#ifdef CONFIG_PAX_REFCOUNT
1396+" bvc 3f\n"
1397+"2: bkpt 0xf103\n"
1398+"3:\n"
1399+#endif
1400+
1401 " strexd %2, %0, %H0, [%4]\n"
1402 " teq %2, #0\n"
1403 " bne 1b\n"
1404-"2:"
1405+"4:\n"
1406+
1407+#ifdef CONFIG_PAX_REFCOUNT
1408+ _ASM_EXTABLE(2b, 4b)
1409+#endif
1410+
1411 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1412 : "r" (&v->counter), "r" (u), "r" (a)
1413 : "cc");
1414@@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1415
1416 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1417 #define atomic64_inc(v) atomic64_add(1LL, (v))
1418+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1419 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1420+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1421 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1422 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1423 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1424+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1425 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1426 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1427 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1428diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1429index 75fe66b..2255c86 100644
1430--- a/arch/arm/include/asm/cache.h
1431+++ b/arch/arm/include/asm/cache.h
1432@@ -4,8 +4,10 @@
1433 #ifndef __ASMARM_CACHE_H
1434 #define __ASMARM_CACHE_H
1435
1436+#include <linux/const.h>
1437+
1438 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1439-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1440+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1441
1442 /*
1443 * Memory returned by kmalloc() may be used for DMA, so we must make
1444diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1445index e4448e1..7bc86b7 100644
1446--- a/arch/arm/include/asm/cacheflush.h
1447+++ b/arch/arm/include/asm/cacheflush.h
1448@@ -108,7 +108,7 @@ struct cpu_cache_fns {
1449 void (*dma_unmap_area)(const void *, size_t, int);
1450
1451 void (*dma_flush_range)(const void *, const void *);
1452-};
1453+} __no_const;
1454
1455 /*
1456 * Select the calling method
1457diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1458index 7eb18c1..e38b6d2 100644
1459--- a/arch/arm/include/asm/cmpxchg.h
1460+++ b/arch/arm/include/asm/cmpxchg.h
1461@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1462
1463 #define xchg(ptr,x) \
1464 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1465+#define xchg_unchecked(ptr,x) \
1466+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1467
1468 #include <asm-generic/cmpxchg-local.h>
1469
1470diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1471index 38050b1..9d90e8b 100644
1472--- a/arch/arm/include/asm/elf.h
1473+++ b/arch/arm/include/asm/elf.h
1474@@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1475 the loader. We need to make sure that it is out of the way of the program
1476 that it will "exec", and that there is sufficient room for the brk. */
1477
1478-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1479+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1480+
1481+#ifdef CONFIG_PAX_ASLR
1482+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1483+
1484+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1485+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1486+#endif
1487
1488 /* When the program starts, a1 contains a pointer to a function to be
1489 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1490@@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1491 extern void elf_set_personality(const struct elf32_hdr *);
1492 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1493
1494-struct mm_struct;
1495-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1496-#define arch_randomize_brk arch_randomize_brk
1497-
1498 #endif
1499diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1500index e51b1e8..32a3113 100644
1501--- a/arch/arm/include/asm/kmap_types.h
1502+++ b/arch/arm/include/asm/kmap_types.h
1503@@ -21,6 +21,7 @@ enum km_type {
1504 KM_L1_CACHE,
1505 KM_L2_CACHE,
1506 KM_KDB,
1507+ KM_CLEARPAGE,
1508 KM_TYPE_NR
1509 };
1510
1511diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1512index 53426c6..c7baff3 100644
1513--- a/arch/arm/include/asm/outercache.h
1514+++ b/arch/arm/include/asm/outercache.h
1515@@ -35,7 +35,7 @@ struct outer_cache_fns {
1516 #endif
1517 void (*set_debug)(unsigned long);
1518 void (*resume)(void);
1519-};
1520+} __no_const;
1521
1522 #ifdef CONFIG_OUTER_CACHE
1523
1524diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1525index ecf9019..b71d9a1 100644
1526--- a/arch/arm/include/asm/page.h
1527+++ b/arch/arm/include/asm/page.h
1528@@ -114,7 +114,7 @@ struct cpu_user_fns {
1529 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1530 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1531 unsigned long vaddr, struct vm_area_struct *vma);
1532-};
1533+} __no_const;
1534
1535 #ifdef MULTI_USER
1536 extern struct cpu_user_fns cpu_user;
1537diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1538index 943504f..bf8d667 100644
1539--- a/arch/arm/include/asm/pgalloc.h
1540+++ b/arch/arm/include/asm/pgalloc.h
1541@@ -43,6 +43,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1542 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1543 }
1544
1545+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1546+{
1547+ pud_populate(mm, pud, pmd);
1548+}
1549+
1550 #else /* !CONFIG_ARM_LPAE */
1551
1552 /*
1553@@ -51,6 +56,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1554 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1555 #define pmd_free(mm, pmd) do { } while (0)
1556 #define pud_populate(mm,pmd,pte) BUG()
1557+#define pud_populate_kernel(mm,pmd,pte) BUG()
1558
1559 #endif /* CONFIG_ARM_LPAE */
1560
1561diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1562index af7b0bd..6750a8c 100644
1563--- a/arch/arm/include/asm/thread_info.h
1564+++ b/arch/arm/include/asm/thread_info.h
1565@@ -148,6 +148,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1566 #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
1567 #define TIF_SYSCALL_TRACE 8
1568 #define TIF_SYSCALL_AUDIT 9
1569+
1570+/* within 8 bits of TIF_SYSCALL_TRACE
1571+ to meet flexible second operand requirements
1572+*/
1573+#define TIF_GRSEC_SETXID 10
1574+
1575 #define TIF_POLLING_NRFLAG 16
1576 #define TIF_USING_IWMMXT 17
1577 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1578@@ -163,9 +169,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1579 #define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)
1580 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1581 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1582+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1583
1584 /* Checks for any syscall work in entry-common.S */
1585-#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
1586+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
1587+ _TIF_GRSEC_SETXID)
1588
1589 /*
1590 * Change these and you break ASM code in entry-common.S
1591diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1592index 71f6536..602f279 100644
1593--- a/arch/arm/include/asm/uaccess.h
1594+++ b/arch/arm/include/asm/uaccess.h
1595@@ -22,6 +22,8 @@
1596 #define VERIFY_READ 0
1597 #define VERIFY_WRITE 1
1598
1599+extern void check_object_size(const void *ptr, unsigned long n, bool to);
1600+
1601 /*
1602 * The exception table consists of pairs of addresses: the first is the
1603 * address of an instruction that is allowed to fault, and the second is
1604@@ -387,8 +389,23 @@ do { \
1605
1606
1607 #ifdef CONFIG_MMU
1608-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1609-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1610+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1611+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1612+
1613+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1614+{
1615+ if (!__builtin_constant_p(n))
1616+ check_object_size(to, n, false);
1617+ return ___copy_from_user(to, from, n);
1618+}
1619+
1620+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1621+{
1622+ if (!__builtin_constant_p(n))
1623+ check_object_size(from, n, true);
1624+ return ___copy_to_user(to, from, n);
1625+}
1626+
1627 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1628 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1629 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1630@@ -403,6 +420,9 @@ extern unsigned long __must_check __strnlen_user(const char __user *s, long n);
1631
1632 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1633 {
1634+ if ((long)n < 0)
1635+ return n;
1636+
1637 if (access_ok(VERIFY_READ, from, n))
1638 n = __copy_from_user(to, from, n);
1639 else /* security hole - plug it */
1640@@ -412,6 +432,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1641
1642 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1643 {
1644+ if ((long)n < 0)
1645+ return n;
1646+
1647 if (access_ok(VERIFY_WRITE, to, n))
1648 n = __copy_to_user(to, from, n);
1649 return n;
1650diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1651index b57c75e..ed2d6b2 100644
1652--- a/arch/arm/kernel/armksyms.c
1653+++ b/arch/arm/kernel/armksyms.c
1654@@ -94,8 +94,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
1655 #ifdef CONFIG_MMU
1656 EXPORT_SYMBOL(copy_page);
1657
1658-EXPORT_SYMBOL(__copy_from_user);
1659-EXPORT_SYMBOL(__copy_to_user);
1660+EXPORT_SYMBOL(___copy_from_user);
1661+EXPORT_SYMBOL(___copy_to_user);
1662 EXPORT_SYMBOL(__clear_user);
1663
1664 EXPORT_SYMBOL(__get_user_1);
1665diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1666index 693b744..e684262 100644
1667--- a/arch/arm/kernel/process.c
1668+++ b/arch/arm/kernel/process.c
1669@@ -28,7 +28,6 @@
1670 #include <linux/tick.h>
1671 #include <linux/utsname.h>
1672 #include <linux/uaccess.h>
1673-#include <linux/random.h>
1674 #include <linux/hw_breakpoint.h>
1675 #include <linux/cpuidle.h>
1676
1677@@ -256,9 +255,10 @@ void machine_power_off(void)
1678 machine_shutdown();
1679 if (pm_power_off)
1680 pm_power_off();
1681+ BUG();
1682 }
1683
1684-void machine_restart(char *cmd)
1685+__noreturn void machine_restart(char *cmd)
1686 {
1687 machine_shutdown();
1688
1689@@ -501,12 +501,6 @@ unsigned long get_wchan(struct task_struct *p)
1690 return 0;
1691 }
1692
1693-unsigned long arch_randomize_brk(struct mm_struct *mm)
1694-{
1695- unsigned long range_end = mm->brk + 0x02000000;
1696- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1697-}
1698-
1699 #ifdef CONFIG_MMU
1700 /*
1701 * The vectors page is always readable from user space for the
1702diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
1703index 14e3826..d832d89 100644
1704--- a/arch/arm/kernel/ptrace.c
1705+++ b/arch/arm/kernel/ptrace.c
1706@@ -907,10 +907,19 @@ long arch_ptrace(struct task_struct *child, long request,
1707 return ret;
1708 }
1709
1710+#ifdef CONFIG_GRKERNSEC_SETXID
1711+extern void gr_delayed_cred_worker(void);
1712+#endif
1713+
1714 asmlinkage int syscall_trace(int why, struct pt_regs *regs, int scno)
1715 {
1716 unsigned long ip;
1717
1718+#ifdef CONFIG_GRKERNSEC_SETXID
1719+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
1720+ gr_delayed_cred_worker();
1721+#endif
1722+
1723 if (why)
1724 audit_syscall_exit(regs);
1725 else
1726diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1727index e15d83b..8c466dd 100644
1728--- a/arch/arm/kernel/setup.c
1729+++ b/arch/arm/kernel/setup.c
1730@@ -112,13 +112,13 @@ struct processor processor __read_mostly;
1731 struct cpu_tlb_fns cpu_tlb __read_mostly;
1732 #endif
1733 #ifdef MULTI_USER
1734-struct cpu_user_fns cpu_user __read_mostly;
1735+struct cpu_user_fns cpu_user __read_only;
1736 #endif
1737 #ifdef MULTI_CACHE
1738-struct cpu_cache_fns cpu_cache __read_mostly;
1739+struct cpu_cache_fns cpu_cache __read_only;
1740 #endif
1741 #ifdef CONFIG_OUTER_CACHE
1742-struct outer_cache_fns outer_cache __read_mostly;
1743+struct outer_cache_fns outer_cache __read_only;
1744 EXPORT_SYMBOL(outer_cache);
1745 #endif
1746
1747diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1748index c7cae6b..e1e523c 100644
1749--- a/arch/arm/kernel/traps.c
1750+++ b/arch/arm/kernel/traps.c
1751@@ -264,6 +264,8 @@ static int __die(const char *str, int err, struct thread_info *thread, struct pt
1752
1753 static DEFINE_RAW_SPINLOCK(die_lock);
1754
1755+extern void gr_handle_kernel_exploit(void);
1756+
1757 /*
1758 * This function is protected against re-entrancy.
1759 */
1760@@ -296,6 +298,9 @@ void die(const char *str, struct pt_regs *regs, int err)
1761 panic("Fatal exception in interrupt");
1762 if (panic_on_oops)
1763 panic("Fatal exception");
1764+
1765+ gr_handle_kernel_exploit();
1766+
1767 if (ret != NOTIFY_STOP)
1768 do_exit(SIGSEGV);
1769 }
1770diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1771index 66a477a..bee61d3 100644
1772--- a/arch/arm/lib/copy_from_user.S
1773+++ b/arch/arm/lib/copy_from_user.S
1774@@ -16,7 +16,7 @@
1775 /*
1776 * Prototype:
1777 *
1778- * size_t __copy_from_user(void *to, const void *from, size_t n)
1779+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
1780 *
1781 * Purpose:
1782 *
1783@@ -84,11 +84,11 @@
1784
1785 .text
1786
1787-ENTRY(__copy_from_user)
1788+ENTRY(___copy_from_user)
1789
1790 #include "copy_template.S"
1791
1792-ENDPROC(__copy_from_user)
1793+ENDPROC(___copy_from_user)
1794
1795 .pushsection .fixup,"ax"
1796 .align 0
1797diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1798index 6ee2f67..d1cce76 100644
1799--- a/arch/arm/lib/copy_page.S
1800+++ b/arch/arm/lib/copy_page.S
1801@@ -10,6 +10,7 @@
1802 * ASM optimised string functions
1803 */
1804 #include <linux/linkage.h>
1805+#include <linux/const.h>
1806 #include <asm/assembler.h>
1807 #include <asm/asm-offsets.h>
1808 #include <asm/cache.h>
1809diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1810index d066df6..df28194 100644
1811--- a/arch/arm/lib/copy_to_user.S
1812+++ b/arch/arm/lib/copy_to_user.S
1813@@ -16,7 +16,7 @@
1814 /*
1815 * Prototype:
1816 *
1817- * size_t __copy_to_user(void *to, const void *from, size_t n)
1818+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
1819 *
1820 * Purpose:
1821 *
1822@@ -88,11 +88,11 @@
1823 .text
1824
1825 ENTRY(__copy_to_user_std)
1826-WEAK(__copy_to_user)
1827+WEAK(___copy_to_user)
1828
1829 #include "copy_template.S"
1830
1831-ENDPROC(__copy_to_user)
1832+ENDPROC(___copy_to_user)
1833 ENDPROC(__copy_to_user_std)
1834
1835 .pushsection .fixup,"ax"
1836diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1837index 025f742..8432b08 100644
1838--- a/arch/arm/lib/uaccess_with_memcpy.c
1839+++ b/arch/arm/lib/uaccess_with_memcpy.c
1840@@ -104,7 +104,7 @@ out:
1841 }
1842
1843 unsigned long
1844-__copy_to_user(void __user *to, const void *from, unsigned long n)
1845+___copy_to_user(void __user *to, const void *from, unsigned long n)
1846 {
1847 /*
1848 * This test is stubbed out of the main function above to keep
1849diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
1850index f261cd2..4ae63fb 100644
1851--- a/arch/arm/mach-kirkwood/common.c
1852+++ b/arch/arm/mach-kirkwood/common.c
1853@@ -128,7 +128,7 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
1854 clk_gate_ops.disable(hw);
1855 }
1856
1857-static struct clk_ops clk_gate_fn_ops;
1858+static clk_ops_no_const clk_gate_fn_ops;
1859
1860 static struct clk __init *clk_register_gate_fn(struct device *dev,
1861 const char *name,
1862diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1863index 2c5d0ed..7d9099c 100644
1864--- a/arch/arm/mach-omap2/board-n8x0.c
1865+++ b/arch/arm/mach-omap2/board-n8x0.c
1866@@ -594,7 +594,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1867 }
1868 #endif
1869
1870-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1871+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1872 .late_init = n8x0_menelaus_late_init,
1873 };
1874
1875diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1876index c3bd834..e81ef02 100644
1877--- a/arch/arm/mm/fault.c
1878+++ b/arch/arm/mm/fault.c
1879@@ -174,6 +174,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1880 }
1881 #endif
1882
1883+#ifdef CONFIG_PAX_PAGEEXEC
1884+ if (fsr & FSR_LNX_PF) {
1885+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1886+ do_group_exit(SIGKILL);
1887+ }
1888+#endif
1889+
1890 tsk->thread.address = addr;
1891 tsk->thread.error_code = fsr;
1892 tsk->thread.trap_no = 14;
1893@@ -397,6 +404,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1894 }
1895 #endif /* CONFIG_MMU */
1896
1897+#ifdef CONFIG_PAX_PAGEEXEC
1898+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1899+{
1900+ long i;
1901+
1902+ printk(KERN_ERR "PAX: bytes at PC: ");
1903+ for (i = 0; i < 20; i++) {
1904+ unsigned char c;
1905+ if (get_user(c, (__force unsigned char __user *)pc+i))
1906+ printk(KERN_CONT "?? ");
1907+ else
1908+ printk(KERN_CONT "%02x ", c);
1909+ }
1910+ printk("\n");
1911+
1912+ printk(KERN_ERR "PAX: bytes at SP-4: ");
1913+ for (i = -1; i < 20; i++) {
1914+ unsigned long c;
1915+ if (get_user(c, (__force unsigned long __user *)sp+i))
1916+ printk(KERN_CONT "???????? ");
1917+ else
1918+ printk(KERN_CONT "%08lx ", c);
1919+ }
1920+ printk("\n");
1921+}
1922+#endif
1923+
1924 /*
1925 * First Level Translation Fault Handler
1926 *
1927@@ -574,6 +608,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1928 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1929 struct siginfo info;
1930
1931+#ifdef CONFIG_PAX_REFCOUNT
1932+ if (fsr_fs(ifsr) == 2) {
1933+ unsigned int bkpt;
1934+
1935+ if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1936+ current->thread.error_code = ifsr;
1937+ current->thread.trap_no = 0;
1938+ pax_report_refcount_overflow(regs);
1939+ fixup_exception(regs);
1940+ return;
1941+ }
1942+ }
1943+#endif
1944+
1945 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1946 return;
1947
1948diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1949index ce8cb19..3ec539d 100644
1950--- a/arch/arm/mm/mmap.c
1951+++ b/arch/arm/mm/mmap.c
1952@@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1953 if (len > TASK_SIZE)
1954 return -ENOMEM;
1955
1956+#ifdef CONFIG_PAX_RANDMMAP
1957+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1958+#endif
1959+
1960 if (addr) {
1961 if (do_align)
1962 addr = COLOUR_ALIGN(addr, pgoff);
1963@@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1964 addr = PAGE_ALIGN(addr);
1965
1966 vma = find_vma(mm, addr);
1967- if (TASK_SIZE - len >= addr &&
1968- (!vma || addr + len <= vma->vm_start))
1969+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1970 return addr;
1971 }
1972 if (len > mm->cached_hole_size) {
1973- start_addr = addr = mm->free_area_cache;
1974+ start_addr = addr = mm->free_area_cache;
1975 } else {
1976- start_addr = addr = mm->mmap_base;
1977- mm->cached_hole_size = 0;
1978+ start_addr = addr = mm->mmap_base;
1979+ mm->cached_hole_size = 0;
1980 }
1981
1982 full_search:
1983@@ -124,14 +127,14 @@ full_search:
1984 * Start a new search - just in case we missed
1985 * some holes.
1986 */
1987- if (start_addr != TASK_UNMAPPED_BASE) {
1988- start_addr = addr = TASK_UNMAPPED_BASE;
1989+ if (start_addr != mm->mmap_base) {
1990+ start_addr = addr = mm->mmap_base;
1991 mm->cached_hole_size = 0;
1992 goto full_search;
1993 }
1994 return -ENOMEM;
1995 }
1996- if (!vma || addr + len <= vma->vm_start) {
1997+ if (check_heap_stack_gap(vma, addr, len)) {
1998 /*
1999 * Remember the place where we stopped the search:
2000 */
2001@@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2002
2003 if (mmap_is_legacy()) {
2004 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
2005+
2006+#ifdef CONFIG_PAX_RANDMMAP
2007+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2008+ mm->mmap_base += mm->delta_mmap;
2009+#endif
2010+
2011 mm->get_unmapped_area = arch_get_unmapped_area;
2012 mm->unmap_area = arch_unmap_area;
2013 } else {
2014 mm->mmap_base = mmap_base(random_factor);
2015+
2016+#ifdef CONFIG_PAX_RANDMMAP
2017+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2018+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2019+#endif
2020+
2021 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2022 mm->unmap_area = arch_unmap_area_topdown;
2023 }
2024diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2025index fd556f7..af2e7d2 100644
2026--- a/arch/arm/plat-orion/include/plat/addr-map.h
2027+++ b/arch/arm/plat-orion/include/plat/addr-map.h
2028@@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2029 value in bridge_virt_base */
2030 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2031 const int win);
2032-};
2033+} __no_const;
2034
2035 /*
2036 * Information needed to setup one address mapping.
2037diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2038index 71a6827..e7fbc23 100644
2039--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2040+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2041@@ -43,7 +43,7 @@ struct samsung_dma_ops {
2042 int (*started)(unsigned ch);
2043 int (*flush)(unsigned ch);
2044 int (*stop)(unsigned ch);
2045-};
2046+} __no_const;
2047
2048 extern void *samsung_dmadev_get_ops(void);
2049 extern void *s3c_dma_get_ops(void);
2050diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
2051index 5f28cae..3d23723 100644
2052--- a/arch/arm/plat-samsung/include/plat/ehci.h
2053+++ b/arch/arm/plat-samsung/include/plat/ehci.h
2054@@ -14,7 +14,7 @@
2055 struct s5p_ehci_platdata {
2056 int (*phy_init)(struct platform_device *pdev, int type);
2057 int (*phy_exit)(struct platform_device *pdev, int type);
2058-};
2059+} __no_const;
2060
2061 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
2062
2063diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2064index c3a58a1..78fbf54 100644
2065--- a/arch/avr32/include/asm/cache.h
2066+++ b/arch/avr32/include/asm/cache.h
2067@@ -1,8 +1,10 @@
2068 #ifndef __ASM_AVR32_CACHE_H
2069 #define __ASM_AVR32_CACHE_H
2070
2071+#include <linux/const.h>
2072+
2073 #define L1_CACHE_SHIFT 5
2074-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2075+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2076
2077 /*
2078 * Memory returned by kmalloc() may be used for DMA, so we must make
2079diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2080index 3b3159b..425ea94 100644
2081--- a/arch/avr32/include/asm/elf.h
2082+++ b/arch/avr32/include/asm/elf.h
2083@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2084 the loader. We need to make sure that it is out of the way of the program
2085 that it will "exec", and that there is sufficient room for the brk. */
2086
2087-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2088+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2089
2090+#ifdef CONFIG_PAX_ASLR
2091+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2092+
2093+#define PAX_DELTA_MMAP_LEN 15
2094+#define PAX_DELTA_STACK_LEN 15
2095+#endif
2096
2097 /* This yields a mask that user programs can use to figure out what
2098 instruction set this CPU supports. This could be done in user space,
2099diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2100index b7f5c68..556135c 100644
2101--- a/arch/avr32/include/asm/kmap_types.h
2102+++ b/arch/avr32/include/asm/kmap_types.h
2103@@ -22,7 +22,8 @@ D(10) KM_IRQ0,
2104 D(11) KM_IRQ1,
2105 D(12) KM_SOFTIRQ0,
2106 D(13) KM_SOFTIRQ1,
2107-D(14) KM_TYPE_NR
2108+D(14) KM_CLEARPAGE,
2109+D(15) KM_TYPE_NR
2110 };
2111
2112 #undef D
2113diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2114index f7040a1..db9f300 100644
2115--- a/arch/avr32/mm/fault.c
2116+++ b/arch/avr32/mm/fault.c
2117@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2118
2119 int exception_trace = 1;
2120
2121+#ifdef CONFIG_PAX_PAGEEXEC
2122+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2123+{
2124+ unsigned long i;
2125+
2126+ printk(KERN_ERR "PAX: bytes at PC: ");
2127+ for (i = 0; i < 20; i++) {
2128+ unsigned char c;
2129+ if (get_user(c, (unsigned char *)pc+i))
2130+ printk(KERN_CONT "???????? ");
2131+ else
2132+ printk(KERN_CONT "%02x ", c);
2133+ }
2134+ printk("\n");
2135+}
2136+#endif
2137+
2138 /*
2139 * This routine handles page faults. It determines the address and the
2140 * problem, and then passes it off to one of the appropriate routines.
2141@@ -156,6 +173,16 @@ bad_area:
2142 up_read(&mm->mmap_sem);
2143
2144 if (user_mode(regs)) {
2145+
2146+#ifdef CONFIG_PAX_PAGEEXEC
2147+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2148+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2149+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2150+ do_group_exit(SIGKILL);
2151+ }
2152+ }
2153+#endif
2154+
2155 if (exception_trace && printk_ratelimit())
2156 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2157 "sp %08lx ecr %lu\n",
2158diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2159index 568885a..f8008df 100644
2160--- a/arch/blackfin/include/asm/cache.h
2161+++ b/arch/blackfin/include/asm/cache.h
2162@@ -7,6 +7,7 @@
2163 #ifndef __ARCH_BLACKFIN_CACHE_H
2164 #define __ARCH_BLACKFIN_CACHE_H
2165
2166+#include <linux/const.h>
2167 #include <linux/linkage.h> /* for asmlinkage */
2168
2169 /*
2170@@ -14,7 +15,7 @@
2171 * Blackfin loads 32 bytes for cache
2172 */
2173 #define L1_CACHE_SHIFT 5
2174-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2175+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2176 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2177
2178 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2179diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2180index aea2718..3639a60 100644
2181--- a/arch/cris/include/arch-v10/arch/cache.h
2182+++ b/arch/cris/include/arch-v10/arch/cache.h
2183@@ -1,8 +1,9 @@
2184 #ifndef _ASM_ARCH_CACHE_H
2185 #define _ASM_ARCH_CACHE_H
2186
2187+#include <linux/const.h>
2188 /* Etrax 100LX have 32-byte cache-lines. */
2189-#define L1_CACHE_BYTES 32
2190 #define L1_CACHE_SHIFT 5
2191+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2192
2193 #endif /* _ASM_ARCH_CACHE_H */
2194diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2195index 7caf25d..ee65ac5 100644
2196--- a/arch/cris/include/arch-v32/arch/cache.h
2197+++ b/arch/cris/include/arch-v32/arch/cache.h
2198@@ -1,11 +1,12 @@
2199 #ifndef _ASM_CRIS_ARCH_CACHE_H
2200 #define _ASM_CRIS_ARCH_CACHE_H
2201
2202+#include <linux/const.h>
2203 #include <arch/hwregs/dma.h>
2204
2205 /* A cache-line is 32 bytes. */
2206-#define L1_CACHE_BYTES 32
2207 #define L1_CACHE_SHIFT 5
2208+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2209
2210 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
2211
2212diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2213index b86329d..6709906 100644
2214--- a/arch/frv/include/asm/atomic.h
2215+++ b/arch/frv/include/asm/atomic.h
2216@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
2217 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2218 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2219
2220+#define atomic64_read_unchecked(v) atomic64_read(v)
2221+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2222+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2223+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2224+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2225+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2226+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2227+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2228+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2229+
2230 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2231 {
2232 int c, old;
2233diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2234index 2797163..c2a401d 100644
2235--- a/arch/frv/include/asm/cache.h
2236+++ b/arch/frv/include/asm/cache.h
2237@@ -12,10 +12,11 @@
2238 #ifndef __ASM_CACHE_H
2239 #define __ASM_CACHE_H
2240
2241+#include <linux/const.h>
2242
2243 /* bytes per L1 cache line */
2244 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2245-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2246+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2247
2248 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2249 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2250diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2251index f8e16b2..c73ff79 100644
2252--- a/arch/frv/include/asm/kmap_types.h
2253+++ b/arch/frv/include/asm/kmap_types.h
2254@@ -23,6 +23,7 @@ enum km_type {
2255 KM_IRQ1,
2256 KM_SOFTIRQ0,
2257 KM_SOFTIRQ1,
2258+ KM_CLEARPAGE,
2259 KM_TYPE_NR
2260 };
2261
2262diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2263index 385fd30..6c3d97e 100644
2264--- a/arch/frv/mm/elf-fdpic.c
2265+++ b/arch/frv/mm/elf-fdpic.c
2266@@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2267 if (addr) {
2268 addr = PAGE_ALIGN(addr);
2269 vma = find_vma(current->mm, addr);
2270- if (TASK_SIZE - len >= addr &&
2271- (!vma || addr + len <= vma->vm_start))
2272+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2273 goto success;
2274 }
2275
2276@@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2277 for (; vma; vma = vma->vm_next) {
2278 if (addr > limit)
2279 break;
2280- if (addr + len <= vma->vm_start)
2281+ if (check_heap_stack_gap(vma, addr, len))
2282 goto success;
2283 addr = vma->vm_end;
2284 }
2285@@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2286 for (; vma; vma = vma->vm_next) {
2287 if (addr > limit)
2288 break;
2289- if (addr + len <= vma->vm_start)
2290+ if (check_heap_stack_gap(vma, addr, len))
2291 goto success;
2292 addr = vma->vm_end;
2293 }
2294diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2295index c635028..6d9445a 100644
2296--- a/arch/h8300/include/asm/cache.h
2297+++ b/arch/h8300/include/asm/cache.h
2298@@ -1,8 +1,10 @@
2299 #ifndef __ARCH_H8300_CACHE_H
2300 #define __ARCH_H8300_CACHE_H
2301
2302+#include <linux/const.h>
2303+
2304 /* bytes per L1 cache line */
2305-#define L1_CACHE_BYTES 4
2306+#define L1_CACHE_BYTES _AC(4,UL)
2307
2308 /* m68k-elf-gcc 2.95.2 doesn't like these */
2309
2310diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2311index 0f01de2..d37d309 100644
2312--- a/arch/hexagon/include/asm/cache.h
2313+++ b/arch/hexagon/include/asm/cache.h
2314@@ -21,9 +21,11 @@
2315 #ifndef __ASM_CACHE_H
2316 #define __ASM_CACHE_H
2317
2318+#include <linux/const.h>
2319+
2320 /* Bytes per L1 cache line */
2321-#define L1_CACHE_SHIFT (5)
2322-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2323+#define L1_CACHE_SHIFT 5
2324+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2325
2326 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2327 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2328diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2329index 6e6fe18..a6ae668 100644
2330--- a/arch/ia64/include/asm/atomic.h
2331+++ b/arch/ia64/include/asm/atomic.h
2332@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2333 #define atomic64_inc(v) atomic64_add(1, (v))
2334 #define atomic64_dec(v) atomic64_sub(1, (v))
2335
2336+#define atomic64_read_unchecked(v) atomic64_read(v)
2337+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2338+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2339+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2340+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2341+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2342+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2343+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2344+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2345+
2346 /* Atomic operations are already serializing */
2347 #define smp_mb__before_atomic_dec() barrier()
2348 #define smp_mb__after_atomic_dec() barrier()
2349diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2350index 988254a..e1ee885 100644
2351--- a/arch/ia64/include/asm/cache.h
2352+++ b/arch/ia64/include/asm/cache.h
2353@@ -1,6 +1,7 @@
2354 #ifndef _ASM_IA64_CACHE_H
2355 #define _ASM_IA64_CACHE_H
2356
2357+#include <linux/const.h>
2358
2359 /*
2360 * Copyright (C) 1998-2000 Hewlett-Packard Co
2361@@ -9,7 +10,7 @@
2362
2363 /* Bytes per L1 (data) cache line. */
2364 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2365-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2366+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2367
2368 #ifdef CONFIG_SMP
2369 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2370diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2371index b5298eb..67c6e62 100644
2372--- a/arch/ia64/include/asm/elf.h
2373+++ b/arch/ia64/include/asm/elf.h
2374@@ -42,6 +42,13 @@
2375 */
2376 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2377
2378+#ifdef CONFIG_PAX_ASLR
2379+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2380+
2381+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2382+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2383+#endif
2384+
2385 #define PT_IA_64_UNWIND 0x70000001
2386
2387 /* IA-64 relocations: */
2388diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
2389index 96a8d92..617a1cf 100644
2390--- a/arch/ia64/include/asm/pgalloc.h
2391+++ b/arch/ia64/include/asm/pgalloc.h
2392@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2393 pgd_val(*pgd_entry) = __pa(pud);
2394 }
2395
2396+static inline void
2397+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2398+{
2399+ pgd_populate(mm, pgd_entry, pud);
2400+}
2401+
2402 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
2403 {
2404 return quicklist_alloc(0, GFP_KERNEL, NULL);
2405@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2406 pud_val(*pud_entry) = __pa(pmd);
2407 }
2408
2409+static inline void
2410+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2411+{
2412+ pud_populate(mm, pud_entry, pmd);
2413+}
2414+
2415 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
2416 {
2417 return quicklist_alloc(0, GFP_KERNEL, NULL);
2418diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2419index 815810c..d60bd4c 100644
2420--- a/arch/ia64/include/asm/pgtable.h
2421+++ b/arch/ia64/include/asm/pgtable.h
2422@@ -12,7 +12,7 @@
2423 * David Mosberger-Tang <davidm@hpl.hp.com>
2424 */
2425
2426-
2427+#include <linux/const.h>
2428 #include <asm/mman.h>
2429 #include <asm/page.h>
2430 #include <asm/processor.h>
2431@@ -142,6 +142,17 @@
2432 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2433 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2434 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2435+
2436+#ifdef CONFIG_PAX_PAGEEXEC
2437+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2438+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2439+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2440+#else
2441+# define PAGE_SHARED_NOEXEC PAGE_SHARED
2442+# define PAGE_READONLY_NOEXEC PAGE_READONLY
2443+# define PAGE_COPY_NOEXEC PAGE_COPY
2444+#endif
2445+
2446 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2447 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2448 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2449diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2450index 54ff557..70c88b7 100644
2451--- a/arch/ia64/include/asm/spinlock.h
2452+++ b/arch/ia64/include/asm/spinlock.h
2453@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2454 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2455
2456 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2457- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2458+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2459 }
2460
2461 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2462diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2463index 449c8c0..432a3d2 100644
2464--- a/arch/ia64/include/asm/uaccess.h
2465+++ b/arch/ia64/include/asm/uaccess.h
2466@@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2467 const void *__cu_from = (from); \
2468 long __cu_len = (n); \
2469 \
2470- if (__access_ok(__cu_to, __cu_len, get_fs())) \
2471+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2472 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2473 __cu_len; \
2474 })
2475@@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2476 long __cu_len = (n); \
2477 \
2478 __chk_user_ptr(__cu_from); \
2479- if (__access_ok(__cu_from, __cu_len, get_fs())) \
2480+ if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2481 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2482 __cu_len; \
2483 })
2484diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2485index 24603be..948052d 100644
2486--- a/arch/ia64/kernel/module.c
2487+++ b/arch/ia64/kernel/module.c
2488@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2489 void
2490 module_free (struct module *mod, void *module_region)
2491 {
2492- if (mod && mod->arch.init_unw_table &&
2493- module_region == mod->module_init) {
2494+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2495 unw_remove_unwind_table(mod->arch.init_unw_table);
2496 mod->arch.init_unw_table = NULL;
2497 }
2498@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2499 }
2500
2501 static inline int
2502+in_init_rx (const struct module *mod, uint64_t addr)
2503+{
2504+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2505+}
2506+
2507+static inline int
2508+in_init_rw (const struct module *mod, uint64_t addr)
2509+{
2510+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2511+}
2512+
2513+static inline int
2514 in_init (const struct module *mod, uint64_t addr)
2515 {
2516- return addr - (uint64_t) mod->module_init < mod->init_size;
2517+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2518+}
2519+
2520+static inline int
2521+in_core_rx (const struct module *mod, uint64_t addr)
2522+{
2523+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2524+}
2525+
2526+static inline int
2527+in_core_rw (const struct module *mod, uint64_t addr)
2528+{
2529+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2530 }
2531
2532 static inline int
2533 in_core (const struct module *mod, uint64_t addr)
2534 {
2535- return addr - (uint64_t) mod->module_core < mod->core_size;
2536+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2537 }
2538
2539 static inline int
2540@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2541 break;
2542
2543 case RV_BDREL:
2544- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2545+ if (in_init_rx(mod, val))
2546+ val -= (uint64_t) mod->module_init_rx;
2547+ else if (in_init_rw(mod, val))
2548+ val -= (uint64_t) mod->module_init_rw;
2549+ else if (in_core_rx(mod, val))
2550+ val -= (uint64_t) mod->module_core_rx;
2551+ else if (in_core_rw(mod, val))
2552+ val -= (uint64_t) mod->module_core_rw;
2553 break;
2554
2555 case RV_LTV:
2556@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2557 * addresses have been selected...
2558 */
2559 uint64_t gp;
2560- if (mod->core_size > MAX_LTOFF)
2561+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2562 /*
2563 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2564 * at the end of the module.
2565 */
2566- gp = mod->core_size - MAX_LTOFF / 2;
2567+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2568 else
2569- gp = mod->core_size / 2;
2570- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2571+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2572+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2573 mod->arch.gp = gp;
2574 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2575 }
2576diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2577index d9439ef..b9a4303 100644
2578--- a/arch/ia64/kernel/sys_ia64.c
2579+++ b/arch/ia64/kernel/sys_ia64.c
2580@@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2581 if (REGION_NUMBER(addr) == RGN_HPAGE)
2582 addr = 0;
2583 #endif
2584+
2585+#ifdef CONFIG_PAX_RANDMMAP
2586+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2587+ addr = mm->free_area_cache;
2588+ else
2589+#endif
2590+
2591 if (!addr)
2592 addr = mm->free_area_cache;
2593
2594@@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2595 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2596 /* At this point: (!vma || addr < vma->vm_end). */
2597 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2598- if (start_addr != TASK_UNMAPPED_BASE) {
2599+ if (start_addr != mm->mmap_base) {
2600 /* Start a new search --- just in case we missed some holes. */
2601- addr = TASK_UNMAPPED_BASE;
2602+ addr = mm->mmap_base;
2603 goto full_search;
2604 }
2605 return -ENOMEM;
2606 }
2607- if (!vma || addr + len <= vma->vm_start) {
2608+ if (check_heap_stack_gap(vma, addr, len)) {
2609 /* Remember the address where we stopped this search: */
2610 mm->free_area_cache = addr + len;
2611 return addr;
2612diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2613index 0ccb28f..8992469 100644
2614--- a/arch/ia64/kernel/vmlinux.lds.S
2615+++ b/arch/ia64/kernel/vmlinux.lds.S
2616@@ -198,7 +198,7 @@ SECTIONS {
2617 /* Per-cpu data: */
2618 . = ALIGN(PERCPU_PAGE_SIZE);
2619 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2620- __phys_per_cpu_start = __per_cpu_load;
2621+ __phys_per_cpu_start = per_cpu_load;
2622 /*
2623 * ensure percpu data fits
2624 * into percpu page size
2625diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2626index 02d29c2..ea893df 100644
2627--- a/arch/ia64/mm/fault.c
2628+++ b/arch/ia64/mm/fault.c
2629@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
2630 return pte_present(pte);
2631 }
2632
2633+#ifdef CONFIG_PAX_PAGEEXEC
2634+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2635+{
2636+ unsigned long i;
2637+
2638+ printk(KERN_ERR "PAX: bytes at PC: ");
2639+ for (i = 0; i < 8; i++) {
2640+ unsigned int c;
2641+ if (get_user(c, (unsigned int *)pc+i))
2642+ printk(KERN_CONT "???????? ");
2643+ else
2644+ printk(KERN_CONT "%08x ", c);
2645+ }
2646+ printk("\n");
2647+}
2648+#endif
2649+
2650 void __kprobes
2651 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
2652 {
2653@@ -145,9 +162,23 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
2654 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
2655 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
2656
2657- if ((vma->vm_flags & mask) != mask)
2658+ if ((vma->vm_flags & mask) != mask) {
2659+
2660+#ifdef CONFIG_PAX_PAGEEXEC
2661+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2662+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2663+ goto bad_area;
2664+
2665+ up_read(&mm->mmap_sem);
2666+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2667+ do_group_exit(SIGKILL);
2668+ }
2669+#endif
2670+
2671 goto bad_area;
2672
2673+ }
2674+
2675 /*
2676 * If for any reason at all we couldn't handle the fault, make
2677 * sure we exit gracefully rather than endlessly redo the
2678diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2679index 5ca674b..e0e1b70 100644
2680--- a/arch/ia64/mm/hugetlbpage.c
2681+++ b/arch/ia64/mm/hugetlbpage.c
2682@@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2683 /* At this point: (!vmm || addr < vmm->vm_end). */
2684 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2685 return -ENOMEM;
2686- if (!vmm || (addr + len) <= vmm->vm_start)
2687+ if (check_heap_stack_gap(vmm, addr, len))
2688 return addr;
2689 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2690 }
2691diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2692index 0eab454..bd794f2 100644
2693--- a/arch/ia64/mm/init.c
2694+++ b/arch/ia64/mm/init.c
2695@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
2696 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2697 vma->vm_end = vma->vm_start + PAGE_SIZE;
2698 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2699+
2700+#ifdef CONFIG_PAX_PAGEEXEC
2701+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2702+ vma->vm_flags &= ~VM_EXEC;
2703+
2704+#ifdef CONFIG_PAX_MPROTECT
2705+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
2706+ vma->vm_flags &= ~VM_MAYEXEC;
2707+#endif
2708+
2709+ }
2710+#endif
2711+
2712 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2713 down_write(&current->mm->mmap_sem);
2714 if (insert_vm_struct(current->mm, vma)) {
2715diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2716index 40b3ee9..8c2c112 100644
2717--- a/arch/m32r/include/asm/cache.h
2718+++ b/arch/m32r/include/asm/cache.h
2719@@ -1,8 +1,10 @@
2720 #ifndef _ASM_M32R_CACHE_H
2721 #define _ASM_M32R_CACHE_H
2722
2723+#include <linux/const.h>
2724+
2725 /* L1 cache line size */
2726 #define L1_CACHE_SHIFT 4
2727-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2728+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2729
2730 #endif /* _ASM_M32R_CACHE_H */
2731diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2732index 82abd15..d95ae5d 100644
2733--- a/arch/m32r/lib/usercopy.c
2734+++ b/arch/m32r/lib/usercopy.c
2735@@ -14,6 +14,9 @@
2736 unsigned long
2737 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2738 {
2739+ if ((long)n < 0)
2740+ return n;
2741+
2742 prefetch(from);
2743 if (access_ok(VERIFY_WRITE, to, n))
2744 __copy_user(to,from,n);
2745@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2746 unsigned long
2747 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2748 {
2749+ if ((long)n < 0)
2750+ return n;
2751+
2752 prefetchw(to);
2753 if (access_ok(VERIFY_READ, from, n))
2754 __copy_user_zeroing(to,from,n);
2755diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2756index 0395c51..5f26031 100644
2757--- a/arch/m68k/include/asm/cache.h
2758+++ b/arch/m68k/include/asm/cache.h
2759@@ -4,9 +4,11 @@
2760 #ifndef __ARCH_M68K_CACHE_H
2761 #define __ARCH_M68K_CACHE_H
2762
2763+#include <linux/const.h>
2764+
2765 /* bytes per L1 cache line */
2766 #define L1_CACHE_SHIFT 4
2767-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2768+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2769
2770 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2771
2772diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2773index 4efe96a..60e8699 100644
2774--- a/arch/microblaze/include/asm/cache.h
2775+++ b/arch/microblaze/include/asm/cache.h
2776@@ -13,11 +13,12 @@
2777 #ifndef _ASM_MICROBLAZE_CACHE_H
2778 #define _ASM_MICROBLAZE_CACHE_H
2779
2780+#include <linux/const.h>
2781 #include <asm/registers.h>
2782
2783 #define L1_CACHE_SHIFT 5
2784 /* word-granular cache in microblaze */
2785-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2786+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2787
2788 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2789
2790diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2791index 3f4c5cb..3439c6e 100644
2792--- a/arch/mips/include/asm/atomic.h
2793+++ b/arch/mips/include/asm/atomic.h
2794@@ -21,6 +21,10 @@
2795 #include <asm/cmpxchg.h>
2796 #include <asm/war.h>
2797
2798+#ifdef CONFIG_GENERIC_ATOMIC64
2799+#include <asm-generic/atomic64.h>
2800+#endif
2801+
2802 #define ATOMIC_INIT(i) { (i) }
2803
2804 /*
2805@@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2806 */
2807 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2808
2809+#define atomic64_read_unchecked(v) atomic64_read(v)
2810+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2811+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2812+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2813+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2814+#define atomic64_inc_unchecked(v) atomic64_inc(v)
2815+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2816+#define atomic64_dec_unchecked(v) atomic64_dec(v)
2817+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2818+
2819 #endif /* CONFIG_64BIT */
2820
2821 /*
2822diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2823index b4db69f..8f3b093 100644
2824--- a/arch/mips/include/asm/cache.h
2825+++ b/arch/mips/include/asm/cache.h
2826@@ -9,10 +9,11 @@
2827 #ifndef _ASM_CACHE_H
2828 #define _ASM_CACHE_H
2829
2830+#include <linux/const.h>
2831 #include <kmalloc.h>
2832
2833 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2834-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2835+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2836
2837 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2838 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2839diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2840index 455c0ac..ad65fbe 100644
2841--- a/arch/mips/include/asm/elf.h
2842+++ b/arch/mips/include/asm/elf.h
2843@@ -372,13 +372,16 @@ extern const char *__elf_platform;
2844 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2845 #endif
2846
2847+#ifdef CONFIG_PAX_ASLR
2848+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2849+
2850+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2851+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2852+#endif
2853+
2854 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2855 struct linux_binprm;
2856 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2857 int uses_interp);
2858
2859-struct mm_struct;
2860-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2861-#define arch_randomize_brk arch_randomize_brk
2862-
2863 #endif /* _ASM_ELF_H */
2864diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
2865index c1f6afa..38cc6e9 100644
2866--- a/arch/mips/include/asm/exec.h
2867+++ b/arch/mips/include/asm/exec.h
2868@@ -12,6 +12,6 @@
2869 #ifndef _ASM_EXEC_H
2870 #define _ASM_EXEC_H
2871
2872-extern unsigned long arch_align_stack(unsigned long sp);
2873+#define arch_align_stack(x) ((x) & ~0xfUL)
2874
2875 #endif /* _ASM_EXEC_H */
2876diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2877index da9bd7d..91aa7ab 100644
2878--- a/arch/mips/include/asm/page.h
2879+++ b/arch/mips/include/asm/page.h
2880@@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2881 #ifdef CONFIG_CPU_MIPS32
2882 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2883 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2884- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2885+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2886 #else
2887 typedef struct { unsigned long long pte; } pte_t;
2888 #define pte_val(x) ((x).pte)
2889diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
2890index 881d18b..cea38bc 100644
2891--- a/arch/mips/include/asm/pgalloc.h
2892+++ b/arch/mips/include/asm/pgalloc.h
2893@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2894 {
2895 set_pud(pud, __pud((unsigned long)pmd));
2896 }
2897+
2898+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2899+{
2900+ pud_populate(mm, pud, pmd);
2901+}
2902 #endif
2903
2904 /*
2905diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
2906index ca97e0e..cd08920 100644
2907--- a/arch/mips/include/asm/thread_info.h
2908+++ b/arch/mips/include/asm/thread_info.h
2909@@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
2910 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
2911 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
2912 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
2913+/* li takes a 32bit immediate */
2914+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
2915 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
2916
2917 #ifdef CONFIG_MIPS32_O32
2918@@ -134,15 +136,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
2919 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
2920 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
2921 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
2922+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
2923+
2924+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2925
2926 /* work to do in syscall_trace_leave() */
2927-#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
2928+#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2929
2930 /* work to do on interrupt/exception return */
2931 #define _TIF_WORK_MASK (0x0000ffef & \
2932 ~(_TIF_SECCOMP | _TIF_SYSCALL_AUDIT))
2933 /* work to do on any return to u-space */
2934-#define _TIF_ALLWORK_MASK (0x8000ffff & ~_TIF_SECCOMP)
2935+#define _TIF_ALLWORK_MASK ((0x8000ffff & ~_TIF_SECCOMP) | _TIF_GRSEC_SETXID)
2936
2937 #endif /* __KERNEL__ */
2938
2939diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2940index 9fdd8bc..4bd7f1a 100644
2941--- a/arch/mips/kernel/binfmt_elfn32.c
2942+++ b/arch/mips/kernel/binfmt_elfn32.c
2943@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2944 #undef ELF_ET_DYN_BASE
2945 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2946
2947+#ifdef CONFIG_PAX_ASLR
2948+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2949+
2950+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2951+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2952+#endif
2953+
2954 #include <asm/processor.h>
2955 #include <linux/module.h>
2956 #include <linux/elfcore.h>
2957diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2958index ff44823..97f8906 100644
2959--- a/arch/mips/kernel/binfmt_elfo32.c
2960+++ b/arch/mips/kernel/binfmt_elfo32.c
2961@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2962 #undef ELF_ET_DYN_BASE
2963 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2964
2965+#ifdef CONFIG_PAX_ASLR
2966+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2967+
2968+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2969+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2970+#endif
2971+
2972 #include <asm/processor.h>
2973
2974 /*
2975diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2976index e9a5fd7..378809a 100644
2977--- a/arch/mips/kernel/process.c
2978+++ b/arch/mips/kernel/process.c
2979@@ -480,15 +480,3 @@ unsigned long get_wchan(struct task_struct *task)
2980 out:
2981 return pc;
2982 }
2983-
2984-/*
2985- * Don't forget that the stack pointer must be aligned on a 8 bytes
2986- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2987- */
2988-unsigned long arch_align_stack(unsigned long sp)
2989-{
2990- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2991- sp -= get_random_int() & ~PAGE_MASK;
2992-
2993- return sp & ALMASK;
2994-}
2995diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
2996index 4812c6d..2069554 100644
2997--- a/arch/mips/kernel/ptrace.c
2998+++ b/arch/mips/kernel/ptrace.c
2999@@ -528,6 +528,10 @@ static inline int audit_arch(void)
3000 return arch;
3001 }
3002
3003+#ifdef CONFIG_GRKERNSEC_SETXID
3004+extern void gr_delayed_cred_worker(void);
3005+#endif
3006+
3007 /*
3008 * Notification of system call entry/exit
3009 * - triggered by current->work.syscall_trace
3010@@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
3011 /* do the secure computing check first */
3012 secure_computing_strict(regs->regs[2]);
3013
3014+#ifdef CONFIG_GRKERNSEC_SETXID
3015+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3016+ gr_delayed_cred_worker();
3017+#endif
3018+
3019 if (!(current->ptrace & PT_PTRACED))
3020 goto out;
3021
3022diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3023index a632bc1..0b77c7c 100644
3024--- a/arch/mips/kernel/scall32-o32.S
3025+++ b/arch/mips/kernel/scall32-o32.S
3026@@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3027
3028 stack_done:
3029 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3030- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3031+ li t1, _TIF_SYSCALL_WORK
3032 and t0, t1
3033 bnez t0, syscall_trace_entry # -> yes
3034
3035diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3036index 3b5a5e9..e1ee86d 100644
3037--- a/arch/mips/kernel/scall64-64.S
3038+++ b/arch/mips/kernel/scall64-64.S
3039@@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
3040
3041 sd a3, PT_R26(sp) # save a3 for syscall restarting
3042
3043- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3044+ li t1, _TIF_SYSCALL_WORK
3045 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3046 and t0, t1, t0
3047 bnez t0, syscall_trace_entry
3048diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
3049index 6be6f70..1859577 100644
3050--- a/arch/mips/kernel/scall64-n32.S
3051+++ b/arch/mips/kernel/scall64-n32.S
3052@@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
3053
3054 sd a3, PT_R26(sp) # save a3 for syscall restarting
3055
3056- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3057+ li t1, _TIF_SYSCALL_WORK
3058 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3059 and t0, t1, t0
3060 bnez t0, n32_syscall_trace_entry
3061diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3062index 5422855..74e63a3 100644
3063--- a/arch/mips/kernel/scall64-o32.S
3064+++ b/arch/mips/kernel/scall64-o32.S
3065@@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3066 PTR 4b, bad_stack
3067 .previous
3068
3069- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3070+ li t1, _TIF_SYSCALL_WORK
3071 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3072 and t0, t1, t0
3073 bnez t0, trace_a_syscall
3074diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
3075index c14f6df..537e729 100644
3076--- a/arch/mips/mm/fault.c
3077+++ b/arch/mips/mm/fault.c
3078@@ -27,6 +27,23 @@
3079 #include <asm/highmem.h> /* For VMALLOC_END */
3080 #include <linux/kdebug.h>
3081
3082+#ifdef CONFIG_PAX_PAGEEXEC
3083+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3084+{
3085+ unsigned long i;
3086+
3087+ printk(KERN_ERR "PAX: bytes at PC: ");
3088+ for (i = 0; i < 5; i++) {
3089+ unsigned int c;
3090+ if (get_user(c, (unsigned int *)pc+i))
3091+ printk(KERN_CONT "???????? ");
3092+ else
3093+ printk(KERN_CONT "%08x ", c);
3094+ }
3095+ printk("\n");
3096+}
3097+#endif
3098+
3099 /*
3100 * This routine handles page faults. It determines the address,
3101 * and the problem, and then passes it off to one of the appropriate
3102diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
3103index 302d779..7d35bf8 100644
3104--- a/arch/mips/mm/mmap.c
3105+++ b/arch/mips/mm/mmap.c
3106@@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3107 do_color_align = 1;
3108
3109 /* requesting a specific address */
3110+
3111+#ifdef CONFIG_PAX_RANDMMAP
3112+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
3113+#endif
3114+
3115 if (addr) {
3116 if (do_color_align)
3117 addr = COLOUR_ALIGN(addr, pgoff);
3118@@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3119 addr = PAGE_ALIGN(addr);
3120
3121 vma = find_vma(mm, addr);
3122- if (TASK_SIZE - len >= addr &&
3123- (!vma || addr + len <= vma->vm_start))
3124+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
3125 return addr;
3126 }
3127
3128@@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3129 /* At this point: (!vma || addr < vma->vm_end). */
3130 if (TASK_SIZE - len < addr)
3131 return -ENOMEM;
3132- if (!vma || addr + len <= vma->vm_start)
3133+ if (check_heap_stack_gap(vmm, addr, len))
3134 return addr;
3135 addr = vma->vm_end;
3136 if (do_color_align)
3137@@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3138 /* make sure it can fit in the remaining address space */
3139 if (likely(addr > len)) {
3140 vma = find_vma(mm, addr - len);
3141- if (!vma || addr <= vma->vm_start) {
3142+ if (check_heap_stack_gap(vmm, addr - len, len))
3143 /* cache the address as a hint for next time */
3144 return mm->free_area_cache = addr - len;
3145 }
3146@@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3147 * return with success:
3148 */
3149 vma = find_vma(mm, addr);
3150- if (likely(!vma || addr + len <= vma->vm_start)) {
3151+ if (check_heap_stack_gap(vmm, addr, len)) {
3152 /* cache the address as a hint for next time */
3153 return mm->free_area_cache = addr;
3154 }
3155@@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3156 mm->unmap_area = arch_unmap_area_topdown;
3157 }
3158 }
3159-
3160-static inline unsigned long brk_rnd(void)
3161-{
3162- unsigned long rnd = get_random_int();
3163-
3164- rnd = rnd << PAGE_SHIFT;
3165- /* 8MB for 32bit, 256MB for 64bit */
3166- if (TASK_IS_32BIT_ADDR)
3167- rnd = rnd & 0x7ffffful;
3168- else
3169- rnd = rnd & 0xffffffful;
3170-
3171- return rnd;
3172-}
3173-
3174-unsigned long arch_randomize_brk(struct mm_struct *mm)
3175-{
3176- unsigned long base = mm->brk;
3177- unsigned long ret;
3178-
3179- ret = PAGE_ALIGN(base + brk_rnd());
3180-
3181- if (ret < mm->brk)
3182- return mm->brk;
3183-
3184- return ret;
3185-}
3186diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3187index 967d144..db12197 100644
3188--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
3189+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3190@@ -11,12 +11,14 @@
3191 #ifndef _ASM_PROC_CACHE_H
3192 #define _ASM_PROC_CACHE_H
3193
3194+#include <linux/const.h>
3195+
3196 /* L1 cache */
3197
3198 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3199 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
3200-#define L1_CACHE_BYTES 16 /* bytes per entry */
3201 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
3202+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3203 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
3204
3205 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3206diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3207index bcb5df2..84fabd2 100644
3208--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3209+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3210@@ -16,13 +16,15 @@
3211 #ifndef _ASM_PROC_CACHE_H
3212 #define _ASM_PROC_CACHE_H
3213
3214+#include <linux/const.h>
3215+
3216 /*
3217 * L1 cache
3218 */
3219 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3220 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
3221-#define L1_CACHE_BYTES 32 /* bytes per entry */
3222 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
3223+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3224 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
3225
3226 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3227diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
3228index 4ce7a01..449202a 100644
3229--- a/arch/openrisc/include/asm/cache.h
3230+++ b/arch/openrisc/include/asm/cache.h
3231@@ -19,11 +19,13 @@
3232 #ifndef __ASM_OPENRISC_CACHE_H
3233 #define __ASM_OPENRISC_CACHE_H
3234
3235+#include <linux/const.h>
3236+
3237 /* FIXME: How can we replace these with values from the CPU...
3238 * they shouldn't be hard-coded!
3239 */
3240
3241-#define L1_CACHE_BYTES 16
3242 #define L1_CACHE_SHIFT 4
3243+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3244
3245 #endif /* __ASM_OPENRISC_CACHE_H */
3246diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
3247index 6c6defc..d30653d 100644
3248--- a/arch/parisc/include/asm/atomic.h
3249+++ b/arch/parisc/include/asm/atomic.h
3250@@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3251
3252 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3253
3254+#define atomic64_read_unchecked(v) atomic64_read(v)
3255+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3256+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3257+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3258+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3259+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3260+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3261+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3262+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3263+
3264 #endif /* !CONFIG_64BIT */
3265
3266
3267diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
3268index 47f11c7..3420df2 100644
3269--- a/arch/parisc/include/asm/cache.h
3270+++ b/arch/parisc/include/asm/cache.h
3271@@ -5,6 +5,7 @@
3272 #ifndef __ARCH_PARISC_CACHE_H
3273 #define __ARCH_PARISC_CACHE_H
3274
3275+#include <linux/const.h>
3276
3277 /*
3278 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
3279@@ -15,13 +16,13 @@
3280 * just ruin performance.
3281 */
3282 #ifdef CONFIG_PA20
3283-#define L1_CACHE_BYTES 64
3284 #define L1_CACHE_SHIFT 6
3285 #else
3286-#define L1_CACHE_BYTES 32
3287 #define L1_CACHE_SHIFT 5
3288 #endif
3289
3290+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3291+
3292 #ifndef __ASSEMBLY__
3293
3294 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3295diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
3296index 19f6cb1..6c78cf2 100644
3297--- a/arch/parisc/include/asm/elf.h
3298+++ b/arch/parisc/include/asm/elf.h
3299@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
3300
3301 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
3302
3303+#ifdef CONFIG_PAX_ASLR
3304+#define PAX_ELF_ET_DYN_BASE 0x10000UL
3305+
3306+#define PAX_DELTA_MMAP_LEN 16
3307+#define PAX_DELTA_STACK_LEN 16
3308+#endif
3309+
3310 /* This yields a mask that user programs can use to figure out what
3311 instruction set this CPU supports. This could be done in user space,
3312 but it's not easy, and we've already done it here. */
3313diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
3314index fc987a1..6e068ef 100644
3315--- a/arch/parisc/include/asm/pgalloc.h
3316+++ b/arch/parisc/include/asm/pgalloc.h
3317@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3318 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
3319 }
3320
3321+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3322+{
3323+ pgd_populate(mm, pgd, pmd);
3324+}
3325+
3326 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
3327 {
3328 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
3329@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
3330 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
3331 #define pmd_free(mm, x) do { } while (0)
3332 #define pgd_populate(mm, pmd, pte) BUG()
3333+#define pgd_populate_kernel(mm, pmd, pte) BUG()
3334
3335 #endif
3336
3337diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
3338index ee99f23..802b0a1 100644
3339--- a/arch/parisc/include/asm/pgtable.h
3340+++ b/arch/parisc/include/asm/pgtable.h
3341@@ -212,6 +212,17 @@ struct vm_area_struct;
3342 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
3343 #define PAGE_COPY PAGE_EXECREAD
3344 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3345+
3346+#ifdef CONFIG_PAX_PAGEEXEC
3347+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3348+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3349+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3350+#else
3351+# define PAGE_SHARED_NOEXEC PAGE_SHARED
3352+# define PAGE_COPY_NOEXEC PAGE_COPY
3353+# define PAGE_READONLY_NOEXEC PAGE_READONLY
3354+#endif
3355+
3356 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3357 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3358 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3359diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
3360index 4ba2c93..f5e3974 100644
3361--- a/arch/parisc/include/asm/uaccess.h
3362+++ b/arch/parisc/include/asm/uaccess.h
3363@@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
3364 const void __user *from,
3365 unsigned long n)
3366 {
3367- int sz = __compiletime_object_size(to);
3368+ size_t sz = __compiletime_object_size(to);
3369 int ret = -EFAULT;
3370
3371- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
3372+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
3373 ret = __copy_from_user(to, from, n);
3374 else
3375 copy_from_user_overflow();
3376diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3377index 5e34ccf..672bc9c 100644
3378--- a/arch/parisc/kernel/module.c
3379+++ b/arch/parisc/kernel/module.c
3380@@ -98,16 +98,38 @@
3381
3382 /* three functions to determine where in the module core
3383 * or init pieces the location is */
3384+static inline int in_init_rx(struct module *me, void *loc)
3385+{
3386+ return (loc >= me->module_init_rx &&
3387+ loc < (me->module_init_rx + me->init_size_rx));
3388+}
3389+
3390+static inline int in_init_rw(struct module *me, void *loc)
3391+{
3392+ return (loc >= me->module_init_rw &&
3393+ loc < (me->module_init_rw + me->init_size_rw));
3394+}
3395+
3396 static inline int in_init(struct module *me, void *loc)
3397 {
3398- return (loc >= me->module_init &&
3399- loc <= (me->module_init + me->init_size));
3400+ return in_init_rx(me, loc) || in_init_rw(me, loc);
3401+}
3402+
3403+static inline int in_core_rx(struct module *me, void *loc)
3404+{
3405+ return (loc >= me->module_core_rx &&
3406+ loc < (me->module_core_rx + me->core_size_rx));
3407+}
3408+
3409+static inline int in_core_rw(struct module *me, void *loc)
3410+{
3411+ return (loc >= me->module_core_rw &&
3412+ loc < (me->module_core_rw + me->core_size_rw));
3413 }
3414
3415 static inline int in_core(struct module *me, void *loc)
3416 {
3417- return (loc >= me->module_core &&
3418- loc <= (me->module_core + me->core_size));
3419+ return in_core_rx(me, loc) || in_core_rw(me, loc);
3420 }
3421
3422 static inline int in_local(struct module *me, void *loc)
3423@@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3424 }
3425
3426 /* align things a bit */
3427- me->core_size = ALIGN(me->core_size, 16);
3428- me->arch.got_offset = me->core_size;
3429- me->core_size += gots * sizeof(struct got_entry);
3430+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
3431+ me->arch.got_offset = me->core_size_rw;
3432+ me->core_size_rw += gots * sizeof(struct got_entry);
3433
3434- me->core_size = ALIGN(me->core_size, 16);
3435- me->arch.fdesc_offset = me->core_size;
3436- me->core_size += fdescs * sizeof(Elf_Fdesc);
3437+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
3438+ me->arch.fdesc_offset = me->core_size_rw;
3439+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3440
3441 me->arch.got_max = gots;
3442 me->arch.fdesc_max = fdescs;
3443@@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3444
3445 BUG_ON(value == 0);
3446
3447- got = me->module_core + me->arch.got_offset;
3448+ got = me->module_core_rw + me->arch.got_offset;
3449 for (i = 0; got[i].addr; i++)
3450 if (got[i].addr == value)
3451 goto out;
3452@@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3453 #ifdef CONFIG_64BIT
3454 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3455 {
3456- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3457+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3458
3459 if (!value) {
3460 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3461@@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3462
3463 /* Create new one */
3464 fdesc->addr = value;
3465- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3466+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3467 return (Elf_Addr)fdesc;
3468 }
3469 #endif /* CONFIG_64BIT */
3470@@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3471
3472 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3473 end = table + sechdrs[me->arch.unwind_section].sh_size;
3474- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3475+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3476
3477 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3478 me->arch.unwind_section, table, end, gp);
3479diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3480index c9b9322..02d8940 100644
3481--- a/arch/parisc/kernel/sys_parisc.c
3482+++ b/arch/parisc/kernel/sys_parisc.c
3483@@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3484 /* At this point: (!vma || addr < vma->vm_end). */
3485 if (TASK_SIZE - len < addr)
3486 return -ENOMEM;
3487- if (!vma || addr + len <= vma->vm_start)
3488+ if (check_heap_stack_gap(vma, addr, len))
3489 return addr;
3490 addr = vma->vm_end;
3491 }
3492@@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3493 /* At this point: (!vma || addr < vma->vm_end). */
3494 if (TASK_SIZE - len < addr)
3495 return -ENOMEM;
3496- if (!vma || addr + len <= vma->vm_start)
3497+ if (check_heap_stack_gap(vma, addr, len))
3498 return addr;
3499 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3500 if (addr < vma->vm_end) /* handle wraparound */
3501@@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3502 if (flags & MAP_FIXED)
3503 return addr;
3504 if (!addr)
3505- addr = TASK_UNMAPPED_BASE;
3506+ addr = current->mm->mmap_base;
3507
3508 if (filp) {
3509 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3510diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3511index 45ba99f..8e22c33 100644
3512--- a/arch/parisc/kernel/traps.c
3513+++ b/arch/parisc/kernel/traps.c
3514@@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3515
3516 down_read(&current->mm->mmap_sem);
3517 vma = find_vma(current->mm,regs->iaoq[0]);
3518- if (vma && (regs->iaoq[0] >= vma->vm_start)
3519- && (vma->vm_flags & VM_EXEC)) {
3520-
3521+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3522 fault_address = regs->iaoq[0];
3523 fault_space = regs->iasq[0];
3524
3525diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3526index 18162ce..94de376 100644
3527--- a/arch/parisc/mm/fault.c
3528+++ b/arch/parisc/mm/fault.c
3529@@ -15,6 +15,7 @@
3530 #include <linux/sched.h>
3531 #include <linux/interrupt.h>
3532 #include <linux/module.h>
3533+#include <linux/unistd.h>
3534
3535 #include <asm/uaccess.h>
3536 #include <asm/traps.h>
3537@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3538 static unsigned long
3539 parisc_acctyp(unsigned long code, unsigned int inst)
3540 {
3541- if (code == 6 || code == 16)
3542+ if (code == 6 || code == 7 || code == 16)
3543 return VM_EXEC;
3544
3545 switch (inst & 0xf0000000) {
3546@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3547 }
3548 #endif
3549
3550+#ifdef CONFIG_PAX_PAGEEXEC
3551+/*
3552+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3553+ *
3554+ * returns 1 when task should be killed
3555+ * 2 when rt_sigreturn trampoline was detected
3556+ * 3 when unpatched PLT trampoline was detected
3557+ */
3558+static int pax_handle_fetch_fault(struct pt_regs *regs)
3559+{
3560+
3561+#ifdef CONFIG_PAX_EMUPLT
3562+ int err;
3563+
3564+ do { /* PaX: unpatched PLT emulation */
3565+ unsigned int bl, depwi;
3566+
3567+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3568+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3569+
3570+ if (err)
3571+ break;
3572+
3573+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3574+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3575+
3576+ err = get_user(ldw, (unsigned int *)addr);
3577+ err |= get_user(bv, (unsigned int *)(addr+4));
3578+ err |= get_user(ldw2, (unsigned int *)(addr+8));
3579+
3580+ if (err)
3581+ break;
3582+
3583+ if (ldw == 0x0E801096U &&
3584+ bv == 0xEAC0C000U &&
3585+ ldw2 == 0x0E881095U)
3586+ {
3587+ unsigned int resolver, map;
3588+
3589+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3590+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3591+ if (err)
3592+ break;
3593+
3594+ regs->gr[20] = instruction_pointer(regs)+8;
3595+ regs->gr[21] = map;
3596+ regs->gr[22] = resolver;
3597+ regs->iaoq[0] = resolver | 3UL;
3598+ regs->iaoq[1] = regs->iaoq[0] + 4;
3599+ return 3;
3600+ }
3601+ }
3602+ } while (0);
3603+#endif
3604+
3605+#ifdef CONFIG_PAX_EMUTRAMP
3606+
3607+#ifndef CONFIG_PAX_EMUSIGRT
3608+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3609+ return 1;
3610+#endif
3611+
3612+ do { /* PaX: rt_sigreturn emulation */
3613+ unsigned int ldi1, ldi2, bel, nop;
3614+
3615+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3616+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3617+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3618+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3619+
3620+ if (err)
3621+ break;
3622+
3623+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3624+ ldi2 == 0x3414015AU &&
3625+ bel == 0xE4008200U &&
3626+ nop == 0x08000240U)
3627+ {
3628+ regs->gr[25] = (ldi1 & 2) >> 1;
3629+ regs->gr[20] = __NR_rt_sigreturn;
3630+ regs->gr[31] = regs->iaoq[1] + 16;
3631+ regs->sr[0] = regs->iasq[1];
3632+ regs->iaoq[0] = 0x100UL;
3633+ regs->iaoq[1] = regs->iaoq[0] + 4;
3634+ regs->iasq[0] = regs->sr[2];
3635+ regs->iasq[1] = regs->sr[2];
3636+ return 2;
3637+ }
3638+ } while (0);
3639+#endif
3640+
3641+ return 1;
3642+}
3643+
3644+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3645+{
3646+ unsigned long i;
3647+
3648+ printk(KERN_ERR "PAX: bytes at PC: ");
3649+ for (i = 0; i < 5; i++) {
3650+ unsigned int c;
3651+ if (get_user(c, (unsigned int *)pc+i))
3652+ printk(KERN_CONT "???????? ");
3653+ else
3654+ printk(KERN_CONT "%08x ", c);
3655+ }
3656+ printk("\n");
3657+}
3658+#endif
3659+
3660 int fixup_exception(struct pt_regs *regs)
3661 {
3662 const struct exception_table_entry *fix;
3663@@ -192,8 +303,33 @@ good_area:
3664
3665 acc_type = parisc_acctyp(code,regs->iir);
3666
3667- if ((vma->vm_flags & acc_type) != acc_type)
3668+ if ((vma->vm_flags & acc_type) != acc_type) {
3669+
3670+#ifdef CONFIG_PAX_PAGEEXEC
3671+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3672+ (address & ~3UL) == instruction_pointer(regs))
3673+ {
3674+ up_read(&mm->mmap_sem);
3675+ switch (pax_handle_fetch_fault(regs)) {
3676+
3677+#ifdef CONFIG_PAX_EMUPLT
3678+ case 3:
3679+ return;
3680+#endif
3681+
3682+#ifdef CONFIG_PAX_EMUTRAMP
3683+ case 2:
3684+ return;
3685+#endif
3686+
3687+ }
3688+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3689+ do_group_exit(SIGKILL);
3690+ }
3691+#endif
3692+
3693 goto bad_area;
3694+ }
3695
3696 /*
3697 * If for any reason at all we couldn't handle the fault, make
3698diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3699index da29032..f76c24c 100644
3700--- a/arch/powerpc/include/asm/atomic.h
3701+++ b/arch/powerpc/include/asm/atomic.h
3702@@ -522,6 +522,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
3703 return t1;
3704 }
3705
3706+#define atomic64_read_unchecked(v) atomic64_read(v)
3707+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3708+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3709+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3710+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3711+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3712+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3713+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3714+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3715+
3716 #endif /* __powerpc64__ */
3717
3718 #endif /* __KERNEL__ */
3719diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3720index 9e495c9..b6878e5 100644
3721--- a/arch/powerpc/include/asm/cache.h
3722+++ b/arch/powerpc/include/asm/cache.h
3723@@ -3,6 +3,7 @@
3724
3725 #ifdef __KERNEL__
3726
3727+#include <linux/const.h>
3728
3729 /* bytes per L1 cache line */
3730 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3731@@ -22,7 +23,7 @@
3732 #define L1_CACHE_SHIFT 7
3733 #endif
3734
3735-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3736+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3737
3738 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3739
3740diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3741index 3bf9cca..e7457d0 100644
3742--- a/arch/powerpc/include/asm/elf.h
3743+++ b/arch/powerpc/include/asm/elf.h
3744@@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3745 the loader. We need to make sure that it is out of the way of the program
3746 that it will "exec", and that there is sufficient room for the brk. */
3747
3748-extern unsigned long randomize_et_dyn(unsigned long base);
3749-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3750+#define ELF_ET_DYN_BASE (0x20000000)
3751+
3752+#ifdef CONFIG_PAX_ASLR
3753+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3754+
3755+#ifdef __powerpc64__
3756+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3757+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3758+#else
3759+#define PAX_DELTA_MMAP_LEN 15
3760+#define PAX_DELTA_STACK_LEN 15
3761+#endif
3762+#endif
3763
3764 /*
3765 * Our registers are always unsigned longs, whether we're a 32 bit
3766@@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3767 (0x7ff >> (PAGE_SHIFT - 12)) : \
3768 (0x3ffff >> (PAGE_SHIFT - 12)))
3769
3770-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3771-#define arch_randomize_brk arch_randomize_brk
3772-
3773 #endif /* __KERNEL__ */
3774
3775 /*
3776diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
3777index 8196e9c..d83a9f3 100644
3778--- a/arch/powerpc/include/asm/exec.h
3779+++ b/arch/powerpc/include/asm/exec.h
3780@@ -4,6 +4,6 @@
3781 #ifndef _ASM_POWERPC_EXEC_H
3782 #define _ASM_POWERPC_EXEC_H
3783
3784-extern unsigned long arch_align_stack(unsigned long sp);
3785+#define arch_align_stack(x) ((x) & ~0xfUL)
3786
3787 #endif /* _ASM_POWERPC_EXEC_H */
3788diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3789index bca8fdc..61e9580 100644
3790--- a/arch/powerpc/include/asm/kmap_types.h
3791+++ b/arch/powerpc/include/asm/kmap_types.h
3792@@ -27,6 +27,7 @@ enum km_type {
3793 KM_PPC_SYNC_PAGE,
3794 KM_PPC_SYNC_ICACHE,
3795 KM_KDB,
3796+ KM_CLEARPAGE,
3797 KM_TYPE_NR
3798 };
3799
3800diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3801index d4a7f64..451de1c 100644
3802--- a/arch/powerpc/include/asm/mman.h
3803+++ b/arch/powerpc/include/asm/mman.h
3804@@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3805 }
3806 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3807
3808-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3809+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3810 {
3811 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3812 }
3813diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3814index f072e97..b436dee 100644
3815--- a/arch/powerpc/include/asm/page.h
3816+++ b/arch/powerpc/include/asm/page.h
3817@@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3818 * and needs to be executable. This means the whole heap ends
3819 * up being executable.
3820 */
3821-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3822- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3823+#define VM_DATA_DEFAULT_FLAGS32 \
3824+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3825+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3826
3827 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3828 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3829@@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3830 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3831 #endif
3832
3833+#define ktla_ktva(addr) (addr)
3834+#define ktva_ktla(addr) (addr)
3835+
3836 /*
3837 * Use the top bit of the higher-level page table entries to indicate whether
3838 * the entries we point to contain hugepages. This works because we know that
3839diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3840index fed85e6..da5c71b 100644
3841--- a/arch/powerpc/include/asm/page_64.h
3842+++ b/arch/powerpc/include/asm/page_64.h
3843@@ -146,15 +146,18 @@ do { \
3844 * stack by default, so in the absence of a PT_GNU_STACK program header
3845 * we turn execute permission off.
3846 */
3847-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3848- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3849+#define VM_STACK_DEFAULT_FLAGS32 \
3850+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3851+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3852
3853 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3854 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3855
3856+#ifndef CONFIG_PAX_PAGEEXEC
3857 #define VM_STACK_DEFAULT_FLAGS \
3858 (is_32bit_task() ? \
3859 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3860+#endif
3861
3862 #include <asm-generic/getorder.h>
3863
3864diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
3865index 292725c..f87ae14 100644
3866--- a/arch/powerpc/include/asm/pgalloc-64.h
3867+++ b/arch/powerpc/include/asm/pgalloc-64.h
3868@@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
3869 #ifndef CONFIG_PPC_64K_PAGES
3870
3871 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
3872+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
3873
3874 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3875 {
3876@@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3877 pud_set(pud, (unsigned long)pmd);
3878 }
3879
3880+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3881+{
3882+ pud_populate(mm, pud, pmd);
3883+}
3884+
3885 #define pmd_populate(mm, pmd, pte_page) \
3886 pmd_populate_kernel(mm, pmd, page_address(pte_page))
3887 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
3888@@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3889 #else /* CONFIG_PPC_64K_PAGES */
3890
3891 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
3892+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
3893
3894 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
3895 pte_t *pte)
3896diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3897index 2e0e411..7899c68 100644
3898--- a/arch/powerpc/include/asm/pgtable.h
3899+++ b/arch/powerpc/include/asm/pgtable.h
3900@@ -2,6 +2,7 @@
3901 #define _ASM_POWERPC_PGTABLE_H
3902 #ifdef __KERNEL__
3903
3904+#include <linux/const.h>
3905 #ifndef __ASSEMBLY__
3906 #include <asm/processor.h> /* For TASK_SIZE */
3907 #include <asm/mmu.h>
3908diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3909index 4aad413..85d86bf 100644
3910--- a/arch/powerpc/include/asm/pte-hash32.h
3911+++ b/arch/powerpc/include/asm/pte-hash32.h
3912@@ -21,6 +21,7 @@
3913 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3914 #define _PAGE_USER 0x004 /* usermode access allowed */
3915 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3916+#define _PAGE_EXEC _PAGE_GUARDED
3917 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3918 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3919 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3920diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3921index 360585d..c3930ef 100644
3922--- a/arch/powerpc/include/asm/reg.h
3923+++ b/arch/powerpc/include/asm/reg.h
3924@@ -212,6 +212,7 @@
3925 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3926 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3927 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3928+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3929 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3930 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3931 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3932diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
3933index 68831e9..379c695 100644
3934--- a/arch/powerpc/include/asm/thread_info.h
3935+++ b/arch/powerpc/include/asm/thread_info.h
3936@@ -91,12 +91,14 @@ static inline struct thread_info *current_thread_info(void)
3937 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
3938 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
3939 #define TIF_SINGLESTEP 8 /* singlestepping active */
3940-#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
3941 #define TIF_SECCOMP 10 /* secure computing */
3942 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
3943 #define TIF_NOERROR 12 /* Force successful syscall return */
3944 #define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
3945 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
3946+#define TIF_MEMDIE 16 /* is terminating due to OOM killer */
3947+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
3948+#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
3949
3950 /* as above, but as bit values */
3951 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3952@@ -113,8 +115,10 @@ static inline struct thread_info *current_thread_info(void)
3953 #define _TIF_NOERROR (1<<TIF_NOERROR)
3954 #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
3955 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
3956+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3957 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
3958- _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
3959+ _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
3960+ _TIF_GRSEC_SETXID)
3961
3962 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
3963 _TIF_NOTIFY_RESUME)
3964diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3965index 17bb40c..353c98b 100644
3966--- a/arch/powerpc/include/asm/uaccess.h
3967+++ b/arch/powerpc/include/asm/uaccess.h
3968@@ -13,6 +13,8 @@
3969 #define VERIFY_READ 0
3970 #define VERIFY_WRITE 1
3971
3972+extern void check_object_size(const void *ptr, unsigned long n, bool to);
3973+
3974 /*
3975 * The fs value determines whether argument validity checking should be
3976 * performed or not. If get_fs() == USER_DS, checking is performed, with
3977@@ -329,52 +331,6 @@ do { \
3978 extern unsigned long __copy_tofrom_user(void __user *to,
3979 const void __user *from, unsigned long size);
3980
3981-#ifndef __powerpc64__
3982-
3983-static inline unsigned long copy_from_user(void *to,
3984- const void __user *from, unsigned long n)
3985-{
3986- unsigned long over;
3987-
3988- if (access_ok(VERIFY_READ, from, n))
3989- return __copy_tofrom_user((__force void __user *)to, from, n);
3990- if ((unsigned long)from < TASK_SIZE) {
3991- over = (unsigned long)from + n - TASK_SIZE;
3992- return __copy_tofrom_user((__force void __user *)to, from,
3993- n - over) + over;
3994- }
3995- return n;
3996-}
3997-
3998-static inline unsigned long copy_to_user(void __user *to,
3999- const void *from, unsigned long n)
4000-{
4001- unsigned long over;
4002-
4003- if (access_ok(VERIFY_WRITE, to, n))
4004- return __copy_tofrom_user(to, (__force void __user *)from, n);
4005- if ((unsigned long)to < TASK_SIZE) {
4006- over = (unsigned long)to + n - TASK_SIZE;
4007- return __copy_tofrom_user(to, (__force void __user *)from,
4008- n - over) + over;
4009- }
4010- return n;
4011-}
4012-
4013-#else /* __powerpc64__ */
4014-
4015-#define __copy_in_user(to, from, size) \
4016- __copy_tofrom_user((to), (from), (size))
4017-
4018-extern unsigned long copy_from_user(void *to, const void __user *from,
4019- unsigned long n);
4020-extern unsigned long copy_to_user(void __user *to, const void *from,
4021- unsigned long n);
4022-extern unsigned long copy_in_user(void __user *to, const void __user *from,
4023- unsigned long n);
4024-
4025-#endif /* __powerpc64__ */
4026-
4027 static inline unsigned long __copy_from_user_inatomic(void *to,
4028 const void __user *from, unsigned long n)
4029 {
4030@@ -398,6 +354,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
4031 if (ret == 0)
4032 return 0;
4033 }
4034+
4035+ if (!__builtin_constant_p(n))
4036+ check_object_size(to, n, false);
4037+
4038 return __copy_tofrom_user((__force void __user *)to, from, n);
4039 }
4040
4041@@ -424,6 +384,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
4042 if (ret == 0)
4043 return 0;
4044 }
4045+
4046+ if (!__builtin_constant_p(n))
4047+ check_object_size(from, n, true);
4048+
4049 return __copy_tofrom_user(to, (__force const void __user *)from, n);
4050 }
4051
4052@@ -441,6 +405,92 @@ static inline unsigned long __copy_to_user(void __user *to,
4053 return __copy_to_user_inatomic(to, from, size);
4054 }
4055
4056+#ifndef __powerpc64__
4057+
4058+static inline unsigned long __must_check copy_from_user(void *to,
4059+ const void __user *from, unsigned long n)
4060+{
4061+ unsigned long over;
4062+
4063+ if ((long)n < 0)
4064+ return n;
4065+
4066+ if (access_ok(VERIFY_READ, from, n)) {
4067+ if (!__builtin_constant_p(n))
4068+ check_object_size(to, n, false);
4069+ return __copy_tofrom_user((__force void __user *)to, from, n);
4070+ }
4071+ if ((unsigned long)from < TASK_SIZE) {
4072+ over = (unsigned long)from + n - TASK_SIZE;
4073+ if (!__builtin_constant_p(n - over))
4074+ check_object_size(to, n - over, false);
4075+ return __copy_tofrom_user((__force void __user *)to, from,
4076+ n - over) + over;
4077+ }
4078+ return n;
4079+}
4080+
4081+static inline unsigned long __must_check copy_to_user(void __user *to,
4082+ const void *from, unsigned long n)
4083+{
4084+ unsigned long over;
4085+
4086+ if ((long)n < 0)
4087+ return n;
4088+
4089+ if (access_ok(VERIFY_WRITE, to, n)) {
4090+ if (!__builtin_constant_p(n))
4091+ check_object_size(from, n, true);
4092+ return __copy_tofrom_user(to, (__force void __user *)from, n);
4093+ }
4094+ if ((unsigned long)to < TASK_SIZE) {
4095+ over = (unsigned long)to + n - TASK_SIZE;
4096+ if (!__builtin_constant_p(n))
4097+ check_object_size(from, n - over, true);
4098+ return __copy_tofrom_user(to, (__force void __user *)from,
4099+ n - over) + over;
4100+ }
4101+ return n;
4102+}
4103+
4104+#else /* __powerpc64__ */
4105+
4106+#define __copy_in_user(to, from, size) \
4107+ __copy_tofrom_user((to), (from), (size))
4108+
4109+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
4110+{
4111+ if ((long)n < 0 || n > INT_MAX)
4112+ return n;
4113+
4114+ if (!__builtin_constant_p(n))
4115+ check_object_size(to, n, false);
4116+
4117+ if (likely(access_ok(VERIFY_READ, from, n)))
4118+ n = __copy_from_user(to, from, n);
4119+ else
4120+ memset(to, 0, n);
4121+ return n;
4122+}
4123+
4124+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
4125+{
4126+ if ((long)n < 0 || n > INT_MAX)
4127+ return n;
4128+
4129+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
4130+ if (!__builtin_constant_p(n))
4131+ check_object_size(from, n, true);
4132+ n = __copy_to_user(to, from, n);
4133+ }
4134+ return n;
4135+}
4136+
4137+extern unsigned long copy_in_user(void __user *to, const void __user *from,
4138+ unsigned long n);
4139+
4140+#endif /* __powerpc64__ */
4141+
4142 extern unsigned long __clear_user(void __user *addr, unsigned long size);
4143
4144 static inline unsigned long clear_user(void __user *addr, unsigned long size)
4145diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
4146index 7215cc2..a9730c1 100644
4147--- a/arch/powerpc/kernel/exceptions-64e.S
4148+++ b/arch/powerpc/kernel/exceptions-64e.S
4149@@ -661,6 +661,7 @@ storage_fault_common:
4150 std r14,_DAR(r1)
4151 std r15,_DSISR(r1)
4152 addi r3,r1,STACK_FRAME_OVERHEAD
4153+ bl .save_nvgprs
4154 mr r4,r14
4155 mr r5,r15
4156 ld r14,PACA_EXGEN+EX_R14(r13)
4157@@ -669,8 +670,7 @@ storage_fault_common:
4158 cmpdi r3,0
4159 bne- 1f
4160 b .ret_from_except_lite
4161-1: bl .save_nvgprs
4162- mr r5,r3
4163+1: mr r5,r3
4164 addi r3,r1,STACK_FRAME_OVERHEAD
4165 ld r4,_DAR(r1)
4166 bl .bad_page_fault
4167diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
4168index 1c06d29..c2a339b 100644
4169--- a/arch/powerpc/kernel/exceptions-64s.S
4170+++ b/arch/powerpc/kernel/exceptions-64s.S
4171@@ -888,10 +888,10 @@ handle_page_fault:
4172 11: ld r4,_DAR(r1)
4173 ld r5,_DSISR(r1)
4174 addi r3,r1,STACK_FRAME_OVERHEAD
4175+ bl .save_nvgprs
4176 bl .do_page_fault
4177 cmpdi r3,0
4178 beq+ 12f
4179- bl .save_nvgprs
4180 mr r5,r3
4181 addi r3,r1,STACK_FRAME_OVERHEAD
4182 lwz r4,_DAR(r1)
4183diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
4184index 2e3200c..72095ce 100644
4185--- a/arch/powerpc/kernel/module_32.c
4186+++ b/arch/powerpc/kernel/module_32.c
4187@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
4188 me->arch.core_plt_section = i;
4189 }
4190 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
4191- printk("Module doesn't contain .plt or .init.plt sections.\n");
4192+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
4193 return -ENOEXEC;
4194 }
4195
4196@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
4197
4198 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
4199 /* Init, or core PLT? */
4200- if (location >= mod->module_core
4201- && location < mod->module_core + mod->core_size)
4202+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
4203+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
4204 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
4205- else
4206+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
4207+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
4208 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
4209+ else {
4210+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
4211+ return ~0UL;
4212+ }
4213
4214 /* Find this entry, or if that fails, the next avail. entry */
4215 while (entry->jump[0]) {
4216diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
4217index 710f400..d00ebe6 100644
4218--- a/arch/powerpc/kernel/process.c
4219+++ b/arch/powerpc/kernel/process.c
4220@@ -681,8 +681,8 @@ void show_regs(struct pt_regs * regs)
4221 * Lookup NIP late so we have the best change of getting the
4222 * above info out without failing
4223 */
4224- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
4225- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
4226+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
4227+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
4228 #endif
4229 show_stack(current, (unsigned long *) regs->gpr[1]);
4230 if (!user_mode(regs))
4231@@ -1189,10 +1189,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4232 newsp = stack[0];
4233 ip = stack[STACK_FRAME_LR_SAVE];
4234 if (!firstframe || ip != lr) {
4235- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
4236+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
4237 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4238 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
4239- printk(" (%pS)",
4240+ printk(" (%pA)",
4241 (void *)current->ret_stack[curr_frame].ret);
4242 curr_frame--;
4243 }
4244@@ -1212,7 +1212,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4245 struct pt_regs *regs = (struct pt_regs *)
4246 (sp + STACK_FRAME_OVERHEAD);
4247 lr = regs->link;
4248- printk("--- Exception: %lx at %pS\n LR = %pS\n",
4249+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
4250 regs->trap, (void *)regs->nip, (void *)lr);
4251 firstframe = 1;
4252 }
4253@@ -1254,58 +1254,3 @@ void __ppc64_runlatch_off(void)
4254 mtspr(SPRN_CTRLT, ctrl);
4255 }
4256 #endif /* CONFIG_PPC64 */
4257-
4258-unsigned long arch_align_stack(unsigned long sp)
4259-{
4260- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4261- sp -= get_random_int() & ~PAGE_MASK;
4262- return sp & ~0xf;
4263-}
4264-
4265-static inline unsigned long brk_rnd(void)
4266-{
4267- unsigned long rnd = 0;
4268-
4269- /* 8MB for 32bit, 1GB for 64bit */
4270- if (is_32bit_task())
4271- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
4272- else
4273- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
4274-
4275- return rnd << PAGE_SHIFT;
4276-}
4277-
4278-unsigned long arch_randomize_brk(struct mm_struct *mm)
4279-{
4280- unsigned long base = mm->brk;
4281- unsigned long ret;
4282-
4283-#ifdef CONFIG_PPC_STD_MMU_64
4284- /*
4285- * If we are using 1TB segments and we are allowed to randomise
4286- * the heap, we can put it above 1TB so it is backed by a 1TB
4287- * segment. Otherwise the heap will be in the bottom 1TB
4288- * which always uses 256MB segments and this may result in a
4289- * performance penalty.
4290- */
4291- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
4292- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
4293-#endif
4294-
4295- ret = PAGE_ALIGN(base + brk_rnd());
4296-
4297- if (ret < mm->brk)
4298- return mm->brk;
4299-
4300- return ret;
4301-}
4302-
4303-unsigned long randomize_et_dyn(unsigned long base)
4304-{
4305- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4306-
4307- if (ret < base)
4308- return base;
4309-
4310- return ret;
4311-}
4312diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
4313index c10fc28..c4ef063 100644
4314--- a/arch/powerpc/kernel/ptrace.c
4315+++ b/arch/powerpc/kernel/ptrace.c
4316@@ -1660,6 +1660,10 @@ long arch_ptrace(struct task_struct *child, long request,
4317 return ret;
4318 }
4319
4320+#ifdef CONFIG_GRKERNSEC_SETXID
4321+extern void gr_delayed_cred_worker(void);
4322+#endif
4323+
4324 /*
4325 * We must return the syscall number to actually look up in the table.
4326 * This can be -1L to skip running any syscall at all.
4327@@ -1670,6 +1674,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
4328
4329 secure_computing_strict(regs->gpr[0]);
4330
4331+#ifdef CONFIG_GRKERNSEC_SETXID
4332+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4333+ gr_delayed_cred_worker();
4334+#endif
4335+
4336 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
4337 tracehook_report_syscall_entry(regs))
4338 /*
4339@@ -1704,6 +1713,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
4340 {
4341 int step;
4342
4343+#ifdef CONFIG_GRKERNSEC_SETXID
4344+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4345+ gr_delayed_cred_worker();
4346+#endif
4347+
4348 audit_syscall_exit(regs);
4349
4350 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
4351diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
4352index 8b4c049..dcd6ef3 100644
4353--- a/arch/powerpc/kernel/signal_32.c
4354+++ b/arch/powerpc/kernel/signal_32.c
4355@@ -852,7 +852,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
4356 /* Save user registers on the stack */
4357 frame = &rt_sf->uc.uc_mcontext;
4358 addr = frame;
4359- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4360+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4361 if (save_user_regs(regs, frame, 0, 1))
4362 goto badframe;
4363 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4364diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
4365index d183f87..1867f1a 100644
4366--- a/arch/powerpc/kernel/signal_64.c
4367+++ b/arch/powerpc/kernel/signal_64.c
4368@@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
4369 current->thread.fpscr.val = 0;
4370
4371 /* Set up to return from userspace. */
4372- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4373+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4374 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4375 } else {
4376 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4377diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
4378index 1589723..cefe690 100644
4379--- a/arch/powerpc/kernel/traps.c
4380+++ b/arch/powerpc/kernel/traps.c
4381@@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
4382 return flags;
4383 }
4384
4385+extern void gr_handle_kernel_exploit(void);
4386+
4387 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4388 int signr)
4389 {
4390@@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4391 panic("Fatal exception in interrupt");
4392 if (panic_on_oops)
4393 panic("Fatal exception");
4394+
4395+ gr_handle_kernel_exploit();
4396+
4397 do_exit(signr);
4398 }
4399
4400diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
4401index 9eb5b9b..e45498a 100644
4402--- a/arch/powerpc/kernel/vdso.c
4403+++ b/arch/powerpc/kernel/vdso.c
4404@@ -34,6 +34,7 @@
4405 #include <asm/firmware.h>
4406 #include <asm/vdso.h>
4407 #include <asm/vdso_datapage.h>
4408+#include <asm/mman.h>
4409
4410 #include "setup.h"
4411
4412@@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4413 vdso_base = VDSO32_MBASE;
4414 #endif
4415
4416- current->mm->context.vdso_base = 0;
4417+ current->mm->context.vdso_base = ~0UL;
4418
4419 /* vDSO has a problem and was disabled, just don't "enable" it for the
4420 * process
4421@@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4422 vdso_base = get_unmapped_area(NULL, vdso_base,
4423 (vdso_pages << PAGE_SHIFT) +
4424 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4425- 0, 0);
4426+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
4427 if (IS_ERR_VALUE(vdso_base)) {
4428 rc = vdso_base;
4429 goto fail_mmapsem;
4430diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4431index 5eea6f3..5d10396 100644
4432--- a/arch/powerpc/lib/usercopy_64.c
4433+++ b/arch/powerpc/lib/usercopy_64.c
4434@@ -9,22 +9,6 @@
4435 #include <linux/module.h>
4436 #include <asm/uaccess.h>
4437
4438-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4439-{
4440- if (likely(access_ok(VERIFY_READ, from, n)))
4441- n = __copy_from_user(to, from, n);
4442- else
4443- memset(to, 0, n);
4444- return n;
4445-}
4446-
4447-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4448-{
4449- if (likely(access_ok(VERIFY_WRITE, to, n)))
4450- n = __copy_to_user(to, from, n);
4451- return n;
4452-}
4453-
4454 unsigned long copy_in_user(void __user *to, const void __user *from,
4455 unsigned long n)
4456 {
4457@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4458 return n;
4459 }
4460
4461-EXPORT_SYMBOL(copy_from_user);
4462-EXPORT_SYMBOL(copy_to_user);
4463 EXPORT_SYMBOL(copy_in_user);
4464
4465diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4466index 08ffcf5..a0ab912 100644
4467--- a/arch/powerpc/mm/fault.c
4468+++ b/arch/powerpc/mm/fault.c
4469@@ -32,6 +32,10 @@
4470 #include <linux/perf_event.h>
4471 #include <linux/magic.h>
4472 #include <linux/ratelimit.h>
4473+#include <linux/slab.h>
4474+#include <linux/pagemap.h>
4475+#include <linux/compiler.h>
4476+#include <linux/unistd.h>
4477
4478 #include <asm/firmware.h>
4479 #include <asm/page.h>
4480@@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4481 }
4482 #endif
4483
4484+#ifdef CONFIG_PAX_PAGEEXEC
4485+/*
4486+ * PaX: decide what to do with offenders (regs->nip = fault address)
4487+ *
4488+ * returns 1 when task should be killed
4489+ */
4490+static int pax_handle_fetch_fault(struct pt_regs *regs)
4491+{
4492+ return 1;
4493+}
4494+
4495+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4496+{
4497+ unsigned long i;
4498+
4499+ printk(KERN_ERR "PAX: bytes at PC: ");
4500+ for (i = 0; i < 5; i++) {
4501+ unsigned int c;
4502+ if (get_user(c, (unsigned int __user *)pc+i))
4503+ printk(KERN_CONT "???????? ");
4504+ else
4505+ printk(KERN_CONT "%08x ", c);
4506+ }
4507+ printk("\n");
4508+}
4509+#endif
4510+
4511 /*
4512 * Check whether the instruction at regs->nip is a store using
4513 * an update addressing form which will update r1.
4514@@ -215,7 +246,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4515 * indicate errors in DSISR but can validly be set in SRR1.
4516 */
4517 if (trap == 0x400)
4518- error_code &= 0x48200000;
4519+ error_code &= 0x58200000;
4520 else
4521 is_write = error_code & DSISR_ISSTORE;
4522 #else
4523@@ -366,7 +397,7 @@ good_area:
4524 * "undefined". Of those that can be set, this is the only
4525 * one which seems bad.
4526 */
4527- if (error_code & 0x10000000)
4528+ if (error_code & DSISR_GUARDED)
4529 /* Guarded storage error. */
4530 goto bad_area;
4531 #endif /* CONFIG_8xx */
4532@@ -381,7 +412,7 @@ good_area:
4533 * processors use the same I/D cache coherency mechanism
4534 * as embedded.
4535 */
4536- if (error_code & DSISR_PROTFAULT)
4537+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4538 goto bad_area;
4539 #endif /* CONFIG_PPC_STD_MMU */
4540
4541@@ -463,6 +494,23 @@ bad_area:
4542 bad_area_nosemaphore:
4543 /* User mode accesses cause a SIGSEGV */
4544 if (user_mode(regs)) {
4545+
4546+#ifdef CONFIG_PAX_PAGEEXEC
4547+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4548+#ifdef CONFIG_PPC_STD_MMU
4549+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4550+#else
4551+ if (is_exec && regs->nip == address) {
4552+#endif
4553+ switch (pax_handle_fetch_fault(regs)) {
4554+ }
4555+
4556+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4557+ do_group_exit(SIGKILL);
4558+ }
4559+ }
4560+#endif
4561+
4562 _exception(SIGSEGV, regs, code, address);
4563 return 0;
4564 }
4565diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4566index 67a42ed..1c7210c 100644
4567--- a/arch/powerpc/mm/mmap_64.c
4568+++ b/arch/powerpc/mm/mmap_64.c
4569@@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4570 */
4571 if (mmap_is_legacy()) {
4572 mm->mmap_base = TASK_UNMAPPED_BASE;
4573+
4574+#ifdef CONFIG_PAX_RANDMMAP
4575+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4576+ mm->mmap_base += mm->delta_mmap;
4577+#endif
4578+
4579 mm->get_unmapped_area = arch_get_unmapped_area;
4580 mm->unmap_area = arch_unmap_area;
4581 } else {
4582 mm->mmap_base = mmap_base();
4583+
4584+#ifdef CONFIG_PAX_RANDMMAP
4585+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4586+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4587+#endif
4588+
4589 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4590 mm->unmap_area = arch_unmap_area_topdown;
4591 }
4592diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4593index 73709f7..6b90313 100644
4594--- a/arch/powerpc/mm/slice.c
4595+++ b/arch/powerpc/mm/slice.c
4596@@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4597 if ((mm->task_size - len) < addr)
4598 return 0;
4599 vma = find_vma(mm, addr);
4600- return (!vma || (addr + len) <= vma->vm_start);
4601+ return check_heap_stack_gap(vma, addr, len);
4602 }
4603
4604 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4605@@ -256,7 +256,7 @@ full_search:
4606 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4607 continue;
4608 }
4609- if (!vma || addr + len <= vma->vm_start) {
4610+ if (check_heap_stack_gap(vma, addr, len)) {
4611 /*
4612 * Remember the place where we stopped the search:
4613 */
4614@@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4615 }
4616 }
4617
4618- addr = mm->mmap_base;
4619- while (addr > len) {
4620+ if (mm->mmap_base < len)
4621+ addr = -ENOMEM;
4622+ else
4623+ addr = mm->mmap_base - len;
4624+
4625+ while (!IS_ERR_VALUE(addr)) {
4626 /* Go down by chunk size */
4627- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4628+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
4629
4630 /* Check for hit with different page size */
4631 mask = slice_range_to_mask(addr, len);
4632@@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4633 * return with success:
4634 */
4635 vma = find_vma(mm, addr);
4636- if (!vma || (addr + len) <= vma->vm_start) {
4637+ if (check_heap_stack_gap(vma, addr, len)) {
4638 /* remember the address as a hint for next time */
4639 if (use_cache)
4640 mm->free_area_cache = addr;
4641@@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4642 mm->cached_hole_size = vma->vm_start - addr;
4643
4644 /* try just below the current vma->vm_start */
4645- addr = vma->vm_start;
4646+ addr = skip_heap_stack_gap(vma, len);
4647 }
4648
4649 /*
4650@@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4651 if (fixed && addr > (mm->task_size - len))
4652 return -EINVAL;
4653
4654+#ifdef CONFIG_PAX_RANDMMAP
4655+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4656+ addr = 0;
4657+#endif
4658+
4659 /* If hint, make sure it matches our alignment restrictions */
4660 if (!fixed && addr) {
4661 addr = _ALIGN_UP(addr, 1ul << pshift);
4662diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4663index 748347b..81bc6c7 100644
4664--- a/arch/s390/include/asm/atomic.h
4665+++ b/arch/s390/include/asm/atomic.h
4666@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4667 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4668 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4669
4670+#define atomic64_read_unchecked(v) atomic64_read(v)
4671+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4672+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4673+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4674+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4675+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4676+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4677+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4678+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4679+
4680 #define smp_mb__before_atomic_dec() smp_mb()
4681 #define smp_mb__after_atomic_dec() smp_mb()
4682 #define smp_mb__before_atomic_inc() smp_mb()
4683diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4684index 2a30d5a..5e5586f 100644
4685--- a/arch/s390/include/asm/cache.h
4686+++ b/arch/s390/include/asm/cache.h
4687@@ -11,8 +11,10 @@
4688 #ifndef __ARCH_S390_CACHE_H
4689 #define __ARCH_S390_CACHE_H
4690
4691-#define L1_CACHE_BYTES 256
4692+#include <linux/const.h>
4693+
4694 #define L1_CACHE_SHIFT 8
4695+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4696 #define NET_SKB_PAD 32
4697
4698 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4699diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4700index 06151e6..c08cb52 100644
4701--- a/arch/s390/include/asm/elf.h
4702+++ b/arch/s390/include/asm/elf.h
4703@@ -161,8 +161,14 @@ extern unsigned int vdso_enabled;
4704 the loader. We need to make sure that it is out of the way of the program
4705 that it will "exec", and that there is sufficient room for the brk. */
4706
4707-extern unsigned long randomize_et_dyn(unsigned long base);
4708-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4709+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4710+
4711+#ifdef CONFIG_PAX_ASLR
4712+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4713+
4714+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4715+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4716+#endif
4717
4718 /* This yields a mask that user programs can use to figure out what
4719 instruction set this CPU supports. */
4720@@ -210,7 +216,4 @@ struct linux_binprm;
4721 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4722 int arch_setup_additional_pages(struct linux_binprm *, int);
4723
4724-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4725-#define arch_randomize_brk arch_randomize_brk
4726-
4727 #endif
4728diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
4729index c4a93d6..4d2a9b4 100644
4730--- a/arch/s390/include/asm/exec.h
4731+++ b/arch/s390/include/asm/exec.h
4732@@ -7,6 +7,6 @@
4733 #ifndef __ASM_EXEC_H
4734 #define __ASM_EXEC_H
4735
4736-extern unsigned long arch_align_stack(unsigned long sp);
4737+#define arch_align_stack(x) ((x) & ~0xfUL)
4738
4739 #endif /* __ASM_EXEC_H */
4740diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4741index 1f3a79b..44d7f9c 100644
4742--- a/arch/s390/include/asm/uaccess.h
4743+++ b/arch/s390/include/asm/uaccess.h
4744@@ -241,6 +241,10 @@ static inline unsigned long __must_check
4745 copy_to_user(void __user *to, const void *from, unsigned long n)
4746 {
4747 might_fault();
4748+
4749+ if ((long)n < 0)
4750+ return n;
4751+
4752 if (access_ok(VERIFY_WRITE, to, n))
4753 n = __copy_to_user(to, from, n);
4754 return n;
4755@@ -266,6 +270,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4756 static inline unsigned long __must_check
4757 __copy_from_user(void *to, const void __user *from, unsigned long n)
4758 {
4759+ if ((long)n < 0)
4760+ return n;
4761+
4762 if (__builtin_constant_p(n) && (n <= 256))
4763 return uaccess.copy_from_user_small(n, from, to);
4764 else
4765@@ -297,10 +304,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
4766 static inline unsigned long __must_check
4767 copy_from_user(void *to, const void __user *from, unsigned long n)
4768 {
4769- unsigned int sz = __compiletime_object_size(to);
4770+ size_t sz = __compiletime_object_size(to);
4771
4772 might_fault();
4773- if (unlikely(sz != -1 && sz < n)) {
4774+
4775+ if ((long)n < 0)
4776+ return n;
4777+
4778+ if (unlikely(sz != (size_t)-1 && sz < n)) {
4779 copy_from_user_overflow();
4780 return n;
4781 }
4782diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4783index dfcb343..eda788a 100644
4784--- a/arch/s390/kernel/module.c
4785+++ b/arch/s390/kernel/module.c
4786@@ -161,11 +161,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4787
4788 /* Increase core size by size of got & plt and set start
4789 offsets for got and plt. */
4790- me->core_size = ALIGN(me->core_size, 4);
4791- me->arch.got_offset = me->core_size;
4792- me->core_size += me->arch.got_size;
4793- me->arch.plt_offset = me->core_size;
4794- me->core_size += me->arch.plt_size;
4795+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
4796+ me->arch.got_offset = me->core_size_rw;
4797+ me->core_size_rw += me->arch.got_size;
4798+ me->arch.plt_offset = me->core_size_rx;
4799+ me->core_size_rx += me->arch.plt_size;
4800 return 0;
4801 }
4802
4803@@ -242,7 +242,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4804 if (info->got_initialized == 0) {
4805 Elf_Addr *gotent;
4806
4807- gotent = me->module_core + me->arch.got_offset +
4808+ gotent = me->module_core_rw + me->arch.got_offset +
4809 info->got_offset;
4810 *gotent = val;
4811 info->got_initialized = 1;
4812@@ -266,7 +266,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4813 else if (r_type == R_390_GOTENT ||
4814 r_type == R_390_GOTPLTENT)
4815 *(unsigned int *) loc =
4816- (val + (Elf_Addr) me->module_core - loc) >> 1;
4817+ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4818 else if (r_type == R_390_GOT64 ||
4819 r_type == R_390_GOTPLT64)
4820 *(unsigned long *) loc = val;
4821@@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4822 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4823 if (info->plt_initialized == 0) {
4824 unsigned int *ip;
4825- ip = me->module_core + me->arch.plt_offset +
4826+ ip = me->module_core_rx + me->arch.plt_offset +
4827 info->plt_offset;
4828 #ifndef CONFIG_64BIT
4829 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4830@@ -305,7 +305,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4831 val - loc + 0xffffUL < 0x1ffffeUL) ||
4832 (r_type == R_390_PLT32DBL &&
4833 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4834- val = (Elf_Addr) me->module_core +
4835+ val = (Elf_Addr) me->module_core_rx +
4836 me->arch.plt_offset +
4837 info->plt_offset;
4838 val += rela->r_addend - loc;
4839@@ -327,7 +327,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4840 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4841 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4842 val = val + rela->r_addend -
4843- ((Elf_Addr) me->module_core + me->arch.got_offset);
4844+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4845 if (r_type == R_390_GOTOFF16)
4846 *(unsigned short *) loc = val;
4847 else if (r_type == R_390_GOTOFF32)
4848@@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4849 break;
4850 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4851 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4852- val = (Elf_Addr) me->module_core + me->arch.got_offset +
4853+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4854 rela->r_addend - loc;
4855 if (r_type == R_390_GOTPC)
4856 *(unsigned int *) loc = val;
4857diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4858index 60055ce..ee4b252 100644
4859--- a/arch/s390/kernel/process.c
4860+++ b/arch/s390/kernel/process.c
4861@@ -316,39 +316,3 @@ unsigned long get_wchan(struct task_struct *p)
4862 }
4863 return 0;
4864 }
4865-
4866-unsigned long arch_align_stack(unsigned long sp)
4867-{
4868- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4869- sp -= get_random_int() & ~PAGE_MASK;
4870- return sp & ~0xf;
4871-}
4872-
4873-static inline unsigned long brk_rnd(void)
4874-{
4875- /* 8MB for 32bit, 1GB for 64bit */
4876- if (is_32bit_task())
4877- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4878- else
4879- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4880-}
4881-
4882-unsigned long arch_randomize_brk(struct mm_struct *mm)
4883-{
4884- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4885-
4886- if (ret < mm->brk)
4887- return mm->brk;
4888- return ret;
4889-}
4890-
4891-unsigned long randomize_et_dyn(unsigned long base)
4892-{
4893- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4894-
4895- if (!(current->flags & PF_RANDOMIZE))
4896- return base;
4897- if (ret < base)
4898- return base;
4899- return ret;
4900-}
4901diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4902index a64fe53..5c66963 100644
4903--- a/arch/s390/mm/mmap.c
4904+++ b/arch/s390/mm/mmap.c
4905@@ -92,10 +92,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4906 */
4907 if (mmap_is_legacy()) {
4908 mm->mmap_base = TASK_UNMAPPED_BASE;
4909+
4910+#ifdef CONFIG_PAX_RANDMMAP
4911+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4912+ mm->mmap_base += mm->delta_mmap;
4913+#endif
4914+
4915 mm->get_unmapped_area = arch_get_unmapped_area;
4916 mm->unmap_area = arch_unmap_area;
4917 } else {
4918 mm->mmap_base = mmap_base();
4919+
4920+#ifdef CONFIG_PAX_RANDMMAP
4921+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4922+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4923+#endif
4924+
4925 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4926 mm->unmap_area = arch_unmap_area_topdown;
4927 }
4928@@ -174,10 +186,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4929 */
4930 if (mmap_is_legacy()) {
4931 mm->mmap_base = TASK_UNMAPPED_BASE;
4932+
4933+#ifdef CONFIG_PAX_RANDMMAP
4934+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4935+ mm->mmap_base += mm->delta_mmap;
4936+#endif
4937+
4938 mm->get_unmapped_area = s390_get_unmapped_area;
4939 mm->unmap_area = arch_unmap_area;
4940 } else {
4941 mm->mmap_base = mmap_base();
4942+
4943+#ifdef CONFIG_PAX_RANDMMAP
4944+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4945+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4946+#endif
4947+
4948 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4949 mm->unmap_area = arch_unmap_area_topdown;
4950 }
4951diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4952index ae3d59f..f65f075 100644
4953--- a/arch/score/include/asm/cache.h
4954+++ b/arch/score/include/asm/cache.h
4955@@ -1,7 +1,9 @@
4956 #ifndef _ASM_SCORE_CACHE_H
4957 #define _ASM_SCORE_CACHE_H
4958
4959+#include <linux/const.h>
4960+
4961 #define L1_CACHE_SHIFT 4
4962-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4963+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4964
4965 #endif /* _ASM_SCORE_CACHE_H */
4966diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
4967index f9f3cd5..58ff438 100644
4968--- a/arch/score/include/asm/exec.h
4969+++ b/arch/score/include/asm/exec.h
4970@@ -1,6 +1,6 @@
4971 #ifndef _ASM_SCORE_EXEC_H
4972 #define _ASM_SCORE_EXEC_H
4973
4974-extern unsigned long arch_align_stack(unsigned long sp);
4975+#define arch_align_stack(x) (x)
4976
4977 #endif /* _ASM_SCORE_EXEC_H */
4978diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4979index 2707023..1c2a3b7 100644
4980--- a/arch/score/kernel/process.c
4981+++ b/arch/score/kernel/process.c
4982@@ -159,8 +159,3 @@ unsigned long get_wchan(struct task_struct *task)
4983
4984 return task_pt_regs(task)->cp0_epc;
4985 }
4986-
4987-unsigned long arch_align_stack(unsigned long sp)
4988-{
4989- return sp;
4990-}
4991diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
4992index ef9e555..331bd29 100644
4993--- a/arch/sh/include/asm/cache.h
4994+++ b/arch/sh/include/asm/cache.h
4995@@ -9,10 +9,11 @@
4996 #define __ASM_SH_CACHE_H
4997 #ifdef __KERNEL__
4998
4999+#include <linux/const.h>
5000 #include <linux/init.h>
5001 #include <cpu/cache.h>
5002
5003-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5004+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5005
5006 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5007
5008diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
5009index afeb710..d1d1289 100644
5010--- a/arch/sh/mm/mmap.c
5011+++ b/arch/sh/mm/mmap.c
5012@@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5013 addr = PAGE_ALIGN(addr);
5014
5015 vma = find_vma(mm, addr);
5016- if (TASK_SIZE - len >= addr &&
5017- (!vma || addr + len <= vma->vm_start))
5018+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5019 return addr;
5020 }
5021
5022@@ -106,7 +105,7 @@ full_search:
5023 }
5024 return -ENOMEM;
5025 }
5026- if (likely(!vma || addr + len <= vma->vm_start)) {
5027+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5028 /*
5029 * Remember the place where we stopped the search:
5030 */
5031@@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5032 addr = PAGE_ALIGN(addr);
5033
5034 vma = find_vma(mm, addr);
5035- if (TASK_SIZE - len >= addr &&
5036- (!vma || addr + len <= vma->vm_start))
5037+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5038 return addr;
5039 }
5040
5041@@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5042 /* make sure it can fit in the remaining address space */
5043 if (likely(addr > len)) {
5044 vma = find_vma(mm, addr-len);
5045- if (!vma || addr <= vma->vm_start) {
5046+ if (check_heap_stack_gap(vma, addr - len, len)) {
5047 /* remember the address as a hint for next time */
5048 return (mm->free_area_cache = addr-len);
5049 }
5050@@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5051 if (unlikely(mm->mmap_base < len))
5052 goto bottomup;
5053
5054- addr = mm->mmap_base-len;
5055- if (do_colour_align)
5056- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5057+ addr = mm->mmap_base - len;
5058
5059 do {
5060+ if (do_colour_align)
5061+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5062 /*
5063 * Lookup failure means no vma is above this address,
5064 * else if new region fits below vma->vm_start,
5065 * return with success:
5066 */
5067 vma = find_vma(mm, addr);
5068- if (likely(!vma || addr+len <= vma->vm_start)) {
5069+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5070 /* remember the address as a hint for next time */
5071 return (mm->free_area_cache = addr);
5072 }
5073@@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5074 mm->cached_hole_size = vma->vm_start - addr;
5075
5076 /* try just below the current vma->vm_start */
5077- addr = vma->vm_start-len;
5078- if (do_colour_align)
5079- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5080- } while (likely(len < vma->vm_start));
5081+ addr = skip_heap_stack_gap(vma, len);
5082+ } while (!IS_ERR_VALUE(addr));
5083
5084 bottomup:
5085 /*
5086diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5087index ce35a1c..2e7b8f9 100644
5088--- a/arch/sparc/include/asm/atomic_64.h
5089+++ b/arch/sparc/include/asm/atomic_64.h
5090@@ -14,18 +14,40 @@
5091 #define ATOMIC64_INIT(i) { (i) }
5092
5093 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5094+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5095+{
5096+ return v->counter;
5097+}
5098 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5099+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5100+{
5101+ return v->counter;
5102+}
5103
5104 #define atomic_set(v, i) (((v)->counter) = i)
5105+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5106+{
5107+ v->counter = i;
5108+}
5109 #define atomic64_set(v, i) (((v)->counter) = i)
5110+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5111+{
5112+ v->counter = i;
5113+}
5114
5115 extern void atomic_add(int, atomic_t *);
5116+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5117 extern void atomic64_add(long, atomic64_t *);
5118+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5119 extern void atomic_sub(int, atomic_t *);
5120+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5121 extern void atomic64_sub(long, atomic64_t *);
5122+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5123
5124 extern int atomic_add_ret(int, atomic_t *);
5125+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5126 extern long atomic64_add_ret(long, atomic64_t *);
5127+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5128 extern int atomic_sub_ret(int, atomic_t *);
5129 extern long atomic64_sub_ret(long, atomic64_t *);
5130
5131@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5132 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5133
5134 #define atomic_inc_return(v) atomic_add_ret(1, v)
5135+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5136+{
5137+ return atomic_add_ret_unchecked(1, v);
5138+}
5139 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5140+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5141+{
5142+ return atomic64_add_ret_unchecked(1, v);
5143+}
5144
5145 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5146 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5147
5148 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5149+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5150+{
5151+ return atomic_add_ret_unchecked(i, v);
5152+}
5153 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5154+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5155+{
5156+ return atomic64_add_ret_unchecked(i, v);
5157+}
5158
5159 /*
5160 * atomic_inc_and_test - increment and test
5161@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5162 * other cases.
5163 */
5164 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5165+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5166+{
5167+ return atomic_inc_return_unchecked(v) == 0;
5168+}
5169 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5170
5171 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5172@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5173 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5174
5175 #define atomic_inc(v) atomic_add(1, v)
5176+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5177+{
5178+ atomic_add_unchecked(1, v);
5179+}
5180 #define atomic64_inc(v) atomic64_add(1, v)
5181+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5182+{
5183+ atomic64_add_unchecked(1, v);
5184+}
5185
5186 #define atomic_dec(v) atomic_sub(1, v)
5187+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5188+{
5189+ atomic_sub_unchecked(1, v);
5190+}
5191 #define atomic64_dec(v) atomic64_sub(1, v)
5192+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5193+{
5194+ atomic64_sub_unchecked(1, v);
5195+}
5196
5197 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5198 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5199
5200 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5201+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
5202+{
5203+ return cmpxchg(&v->counter, old, new);
5204+}
5205 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5206+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5207+{
5208+ return xchg(&v->counter, new);
5209+}
5210
5211 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5212 {
5213- int c, old;
5214+ int c, old, new;
5215 c = atomic_read(v);
5216 for (;;) {
5217- if (unlikely(c == (u)))
5218+ if (unlikely(c == u))
5219 break;
5220- old = atomic_cmpxchg((v), c, c + (a));
5221+
5222+ asm volatile("addcc %2, %0, %0\n"
5223+
5224+#ifdef CONFIG_PAX_REFCOUNT
5225+ "tvs %%icc, 6\n"
5226+#endif
5227+
5228+ : "=r" (new)
5229+ : "0" (c), "ir" (a)
5230+ : "cc");
5231+
5232+ old = atomic_cmpxchg(v, c, new);
5233 if (likely(old == c))
5234 break;
5235 c = old;
5236@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5237 #define atomic64_cmpxchg(v, o, n) \
5238 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
5239 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
5240+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
5241+{
5242+ return xchg(&v->counter, new);
5243+}
5244
5245 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5246 {
5247- long c, old;
5248+ long c, old, new;
5249 c = atomic64_read(v);
5250 for (;;) {
5251- if (unlikely(c == (u)))
5252+ if (unlikely(c == u))
5253 break;
5254- old = atomic64_cmpxchg((v), c, c + (a));
5255+
5256+ asm volatile("addcc %2, %0, %0\n"
5257+
5258+#ifdef CONFIG_PAX_REFCOUNT
5259+ "tvs %%xcc, 6\n"
5260+#endif
5261+
5262+ : "=r" (new)
5263+ : "0" (c), "ir" (a)
5264+ : "cc");
5265+
5266+ old = atomic64_cmpxchg(v, c, new);
5267 if (likely(old == c))
5268 break;
5269 c = old;
5270 }
5271- return c != (u);
5272+ return c != u;
5273 }
5274
5275 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5276diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
5277index 5bb6991..5c2132e 100644
5278--- a/arch/sparc/include/asm/cache.h
5279+++ b/arch/sparc/include/asm/cache.h
5280@@ -7,10 +7,12 @@
5281 #ifndef _SPARC_CACHE_H
5282 #define _SPARC_CACHE_H
5283
5284+#include <linux/const.h>
5285+
5286 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5287
5288 #define L1_CACHE_SHIFT 5
5289-#define L1_CACHE_BYTES 32
5290+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5291
5292 #ifdef CONFIG_SPARC32
5293 #define SMP_CACHE_BYTES_SHIFT 5
5294diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
5295index 2d4d755..81b6662 100644
5296--- a/arch/sparc/include/asm/elf_32.h
5297+++ b/arch/sparc/include/asm/elf_32.h
5298@@ -114,6 +114,13 @@ typedef struct {
5299
5300 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5301
5302+#ifdef CONFIG_PAX_ASLR
5303+#define PAX_ELF_ET_DYN_BASE 0x10000UL
5304+
5305+#define PAX_DELTA_MMAP_LEN 16
5306+#define PAX_DELTA_STACK_LEN 16
5307+#endif
5308+
5309 /* This yields a mask that user programs can use to figure out what
5310 instruction set this cpu supports. This can NOT be done in userspace
5311 on Sparc. */
5312diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
5313index 7df8b7f..4946269 100644
5314--- a/arch/sparc/include/asm/elf_64.h
5315+++ b/arch/sparc/include/asm/elf_64.h
5316@@ -180,6 +180,13 @@ typedef struct {
5317 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5318 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5319
5320+#ifdef CONFIG_PAX_ASLR
5321+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5322+
5323+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5324+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5325+#endif
5326+
5327 extern unsigned long sparc64_elf_hwcap;
5328 #define ELF_HWCAP sparc64_elf_hwcap
5329
5330diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
5331index e5b169b46..e90b4fa 100644
5332--- a/arch/sparc/include/asm/pgalloc_32.h
5333+++ b/arch/sparc/include/asm/pgalloc_32.h
5334@@ -46,6 +46,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
5335 }
5336
5337 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
5338+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
5339
5340 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
5341 unsigned long address)
5342diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
5343index 40b2d7a..22a665b 100644
5344--- a/arch/sparc/include/asm/pgalloc_64.h
5345+++ b/arch/sparc/include/asm/pgalloc_64.h
5346@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
5347 }
5348
5349 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
5350+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
5351
5352 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5353 {
5354diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
5355index cbbbed5..0983069 100644
5356--- a/arch/sparc/include/asm/pgtable_32.h
5357+++ b/arch/sparc/include/asm/pgtable_32.h
5358@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
5359 #define PAGE_SHARED SRMMU_PAGE_SHARED
5360 #define PAGE_COPY SRMMU_PAGE_COPY
5361 #define PAGE_READONLY SRMMU_PAGE_RDONLY
5362+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
5363+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
5364+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
5365 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
5366
5367 /* Top-level page directory */
5368@@ -61,18 +64,18 @@ extern unsigned long ptr_in_current_pgd;
5369
5370 /* xwr */
5371 #define __P000 PAGE_NONE
5372-#define __P001 PAGE_READONLY
5373-#define __P010 PAGE_COPY
5374-#define __P011 PAGE_COPY
5375+#define __P001 PAGE_READONLY_NOEXEC
5376+#define __P010 PAGE_COPY_NOEXEC
5377+#define __P011 PAGE_COPY_NOEXEC
5378 #define __P100 PAGE_READONLY
5379 #define __P101 PAGE_READONLY
5380 #define __P110 PAGE_COPY
5381 #define __P111 PAGE_COPY
5382
5383 #define __S000 PAGE_NONE
5384-#define __S001 PAGE_READONLY
5385-#define __S010 PAGE_SHARED
5386-#define __S011 PAGE_SHARED
5387+#define __S001 PAGE_READONLY_NOEXEC
5388+#define __S010 PAGE_SHARE_NOEXEC
5389+#define __S011 PAGE_SHARE_NOEXEC
5390 #define __S100 PAGE_READONLY
5391 #define __S101 PAGE_READONLY
5392 #define __S110 PAGE_SHARED
5393diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
5394index 79da178..c2eede8 100644
5395--- a/arch/sparc/include/asm/pgtsrmmu.h
5396+++ b/arch/sparc/include/asm/pgtsrmmu.h
5397@@ -115,6 +115,11 @@
5398 SRMMU_EXEC | SRMMU_REF)
5399 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5400 SRMMU_EXEC | SRMMU_REF)
5401+
5402+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5403+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5404+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5405+
5406 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5407 SRMMU_DIRTY | SRMMU_REF)
5408
5409diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
5410index 9689176..63c18ea 100644
5411--- a/arch/sparc/include/asm/spinlock_64.h
5412+++ b/arch/sparc/include/asm/spinlock_64.h
5413@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
5414
5415 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5416
5417-static void inline arch_read_lock(arch_rwlock_t *lock)
5418+static inline void arch_read_lock(arch_rwlock_t *lock)
5419 {
5420 unsigned long tmp1, tmp2;
5421
5422 __asm__ __volatile__ (
5423 "1: ldsw [%2], %0\n"
5424 " brlz,pn %0, 2f\n"
5425-"4: add %0, 1, %1\n"
5426+"4: addcc %0, 1, %1\n"
5427+
5428+#ifdef CONFIG_PAX_REFCOUNT
5429+" tvs %%icc, 6\n"
5430+#endif
5431+
5432 " cas [%2], %0, %1\n"
5433 " cmp %0, %1\n"
5434 " bne,pn %%icc, 1b\n"
5435@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5436 " .previous"
5437 : "=&r" (tmp1), "=&r" (tmp2)
5438 : "r" (lock)
5439- : "memory");
5440+ : "memory", "cc");
5441 }
5442
5443-static int inline arch_read_trylock(arch_rwlock_t *lock)
5444+static inline int arch_read_trylock(arch_rwlock_t *lock)
5445 {
5446 int tmp1, tmp2;
5447
5448@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5449 "1: ldsw [%2], %0\n"
5450 " brlz,a,pn %0, 2f\n"
5451 " mov 0, %0\n"
5452-" add %0, 1, %1\n"
5453+" addcc %0, 1, %1\n"
5454+
5455+#ifdef CONFIG_PAX_REFCOUNT
5456+" tvs %%icc, 6\n"
5457+#endif
5458+
5459 " cas [%2], %0, %1\n"
5460 " cmp %0, %1\n"
5461 " bne,pn %%icc, 1b\n"
5462@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5463 return tmp1;
5464 }
5465
5466-static void inline arch_read_unlock(arch_rwlock_t *lock)
5467+static inline void arch_read_unlock(arch_rwlock_t *lock)
5468 {
5469 unsigned long tmp1, tmp2;
5470
5471 __asm__ __volatile__(
5472 "1: lduw [%2], %0\n"
5473-" sub %0, 1, %1\n"
5474+" subcc %0, 1, %1\n"
5475+
5476+#ifdef CONFIG_PAX_REFCOUNT
5477+" tvs %%icc, 6\n"
5478+#endif
5479+
5480 " cas [%2], %0, %1\n"
5481 " cmp %0, %1\n"
5482 " bne,pn %%xcc, 1b\n"
5483@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5484 : "memory");
5485 }
5486
5487-static void inline arch_write_lock(arch_rwlock_t *lock)
5488+static inline void arch_write_lock(arch_rwlock_t *lock)
5489 {
5490 unsigned long mask, tmp1, tmp2;
5491
5492@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5493 : "memory");
5494 }
5495
5496-static void inline arch_write_unlock(arch_rwlock_t *lock)
5497+static inline void arch_write_unlock(arch_rwlock_t *lock)
5498 {
5499 __asm__ __volatile__(
5500 " stw %%g0, [%0]"
5501@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5502 : "memory");
5503 }
5504
5505-static int inline arch_write_trylock(arch_rwlock_t *lock)
5506+static inline int arch_write_trylock(arch_rwlock_t *lock)
5507 {
5508 unsigned long mask, tmp1, tmp2, result;
5509
5510diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5511index e6cd224..3a71793 100644
5512--- a/arch/sparc/include/asm/thread_info_32.h
5513+++ b/arch/sparc/include/asm/thread_info_32.h
5514@@ -49,6 +49,8 @@ struct thread_info {
5515 unsigned long w_saved;
5516
5517 struct restart_block restart_block;
5518+
5519+ unsigned long lowest_stack;
5520 };
5521
5522 /*
5523diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5524index cfa8c38..13f30d3 100644
5525--- a/arch/sparc/include/asm/thread_info_64.h
5526+++ b/arch/sparc/include/asm/thread_info_64.h
5527@@ -63,6 +63,8 @@ struct thread_info {
5528 struct pt_regs *kern_una_regs;
5529 unsigned int kern_una_insn;
5530
5531+ unsigned long lowest_stack;
5532+
5533 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5534 };
5535
5536@@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
5537 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
5538 /* flag bit 6 is available */
5539 #define TIF_32BIT 7 /* 32-bit binary */
5540-/* flag bit 8 is available */
5541+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
5542 #define TIF_SECCOMP 9 /* secure computing */
5543 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
5544 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
5545+
5546 /* NOTE: Thread flags >= 12 should be ones we have no interest
5547 * in using in assembly, else we can't use the mask as
5548 * an immediate value in instructions such as andcc.
5549@@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
5550 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
5551 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5552 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
5553+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5554
5555 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
5556 _TIF_DO_NOTIFY_RESUME_MASK | \
5557 _TIF_NEED_RESCHED)
5558 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
5559
5560+#define _TIF_WORK_SYSCALL \
5561+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
5562+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
5563+
5564+
5565 /*
5566 * Thread-synchronous status.
5567 *
5568diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5569index 0167d26..9acd8ed 100644
5570--- a/arch/sparc/include/asm/uaccess.h
5571+++ b/arch/sparc/include/asm/uaccess.h
5572@@ -1,5 +1,13 @@
5573 #ifndef ___ASM_SPARC_UACCESS_H
5574 #define ___ASM_SPARC_UACCESS_H
5575+
5576+#ifdef __KERNEL__
5577+#ifndef __ASSEMBLY__
5578+#include <linux/types.h>
5579+extern void check_object_size(const void *ptr, unsigned long n, bool to);
5580+#endif
5581+#endif
5582+
5583 #if defined(__sparc__) && defined(__arch64__)
5584 #include <asm/uaccess_64.h>
5585 #else
5586diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5587index 53a28dd..50c38c3 100644
5588--- a/arch/sparc/include/asm/uaccess_32.h
5589+++ b/arch/sparc/include/asm/uaccess_32.h
5590@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5591
5592 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5593 {
5594- if (n && __access_ok((unsigned long) to, n))
5595+ if ((long)n < 0)
5596+ return n;
5597+
5598+ if (n && __access_ok((unsigned long) to, n)) {
5599+ if (!__builtin_constant_p(n))
5600+ check_object_size(from, n, true);
5601 return __copy_user(to, (__force void __user *) from, n);
5602- else
5603+ } else
5604 return n;
5605 }
5606
5607 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5608 {
5609+ if ((long)n < 0)
5610+ return n;
5611+
5612+ if (!__builtin_constant_p(n))
5613+ check_object_size(from, n, true);
5614+
5615 return __copy_user(to, (__force void __user *) from, n);
5616 }
5617
5618 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5619 {
5620- if (n && __access_ok((unsigned long) from, n))
5621+ if ((long)n < 0)
5622+ return n;
5623+
5624+ if (n && __access_ok((unsigned long) from, n)) {
5625+ if (!__builtin_constant_p(n))
5626+ check_object_size(to, n, false);
5627 return __copy_user((__force void __user *) to, from, n);
5628- else
5629+ } else
5630 return n;
5631 }
5632
5633 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5634 {
5635+ if ((long)n < 0)
5636+ return n;
5637+
5638 return __copy_user((__force void __user *) to, from, n);
5639 }
5640
5641diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5642index 7c831d8..d440ca7 100644
5643--- a/arch/sparc/include/asm/uaccess_64.h
5644+++ b/arch/sparc/include/asm/uaccess_64.h
5645@@ -10,6 +10,7 @@
5646 #include <linux/compiler.h>
5647 #include <linux/string.h>
5648 #include <linux/thread_info.h>
5649+#include <linux/kernel.h>
5650 #include <asm/asi.h>
5651 #include <asm/spitfire.h>
5652 #include <asm-generic/uaccess-unaligned.h>
5653@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5654 static inline unsigned long __must_check
5655 copy_from_user(void *to, const void __user *from, unsigned long size)
5656 {
5657- unsigned long ret = ___copy_from_user(to, from, size);
5658+ unsigned long ret;
5659
5660+ if ((long)size < 0 || size > INT_MAX)
5661+ return size;
5662+
5663+ if (!__builtin_constant_p(size))
5664+ check_object_size(to, size, false);
5665+
5666+ ret = ___copy_from_user(to, from, size);
5667 if (unlikely(ret))
5668 ret = copy_from_user_fixup(to, from, size);
5669
5670@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5671 static inline unsigned long __must_check
5672 copy_to_user(void __user *to, const void *from, unsigned long size)
5673 {
5674- unsigned long ret = ___copy_to_user(to, from, size);
5675+ unsigned long ret;
5676
5677+ if ((long)size < 0 || size > INT_MAX)
5678+ return size;
5679+
5680+ if (!__builtin_constant_p(size))
5681+ check_object_size(from, size, true);
5682+
5683+ ret = ___copy_to_user(to, from, size);
5684 if (unlikely(ret))
5685 ret = copy_to_user_fixup(to, from, size);
5686 return ret;
5687diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5688index 6cf591b..b49e65a 100644
5689--- a/arch/sparc/kernel/Makefile
5690+++ b/arch/sparc/kernel/Makefile
5691@@ -3,7 +3,7 @@
5692 #
5693
5694 asflags-y := -ansi
5695-ccflags-y := -Werror
5696+#ccflags-y := -Werror
5697
5698 extra-y := head_$(BITS).o
5699
5700diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5701index cb36e82..1c1462f 100644
5702--- a/arch/sparc/kernel/process_32.c
5703+++ b/arch/sparc/kernel/process_32.c
5704@@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
5705
5706 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5707 r->psr, r->pc, r->npc, r->y, print_tainted());
5708- printk("PC: <%pS>\n", (void *) r->pc);
5709+ printk("PC: <%pA>\n", (void *) r->pc);
5710 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5711 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5712 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5713 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5714 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5715 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5716- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5717+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5718
5719 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5720 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5721@@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5722 rw = (struct reg_window32 *) fp;
5723 pc = rw->ins[7];
5724 printk("[%08lx : ", pc);
5725- printk("%pS ] ", (void *) pc);
5726+ printk("%pA ] ", (void *) pc);
5727 fp = rw->ins[6];
5728 } while (++count < 16);
5729 printk("\n");
5730diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5731index aff0c72..9067b39 100644
5732--- a/arch/sparc/kernel/process_64.c
5733+++ b/arch/sparc/kernel/process_64.c
5734@@ -179,14 +179,14 @@ static void show_regwindow(struct pt_regs *regs)
5735 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5736 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5737 if (regs->tstate & TSTATE_PRIV)
5738- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5739+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5740 }
5741
5742 void show_regs(struct pt_regs *regs)
5743 {
5744 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5745 regs->tpc, regs->tnpc, regs->y, print_tainted());
5746- printk("TPC: <%pS>\n", (void *) regs->tpc);
5747+ printk("TPC: <%pA>\n", (void *) regs->tpc);
5748 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5749 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5750 regs->u_regs[3]);
5751@@ -199,7 +199,7 @@ void show_regs(struct pt_regs *regs)
5752 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5753 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5754 regs->u_regs[15]);
5755- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5756+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5757 show_regwindow(regs);
5758 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5759 }
5760@@ -284,7 +284,7 @@ void arch_trigger_all_cpu_backtrace(void)
5761 ((tp && tp->task) ? tp->task->pid : -1));
5762
5763 if (gp->tstate & TSTATE_PRIV) {
5764- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5765+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5766 (void *) gp->tpc,
5767 (void *) gp->o7,
5768 (void *) gp->i7,
5769diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
5770index 484daba..0674139 100644
5771--- a/arch/sparc/kernel/ptrace_64.c
5772+++ b/arch/sparc/kernel/ptrace_64.c
5773@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
5774 return ret;
5775 }
5776
5777+#ifdef CONFIG_GRKERNSEC_SETXID
5778+extern void gr_delayed_cred_worker(void);
5779+#endif
5780+
5781 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5782 {
5783 int ret = 0;
5784@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5785 /* do the secure computing check first */
5786 secure_computing_strict(regs->u_regs[UREG_G1]);
5787
5788+#ifdef CONFIG_GRKERNSEC_SETXID
5789+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5790+ gr_delayed_cred_worker();
5791+#endif
5792+
5793 if (test_thread_flag(TIF_SYSCALL_TRACE))
5794 ret = tracehook_report_syscall_entry(regs);
5795
5796@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5797
5798 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
5799 {
5800+#ifdef CONFIG_GRKERNSEC_SETXID
5801+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5802+ gr_delayed_cred_worker();
5803+#endif
5804+
5805 audit_syscall_exit(regs);
5806
5807 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5808diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5809index 0c9b31b..7cb7aee 100644
5810--- a/arch/sparc/kernel/sys_sparc_32.c
5811+++ b/arch/sparc/kernel/sys_sparc_32.c
5812@@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5813 if (len > TASK_SIZE - PAGE_SIZE)
5814 return -ENOMEM;
5815 if (!addr)
5816- addr = TASK_UNMAPPED_BASE;
5817+ addr = current->mm->mmap_base;
5818
5819 if (flags & MAP_SHARED)
5820 addr = COLOUR_ALIGN(addr);
5821@@ -65,7 +65,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5822 /* At this point: (!vmm || addr < vmm->vm_end). */
5823 if (TASK_SIZE - PAGE_SIZE - len < addr)
5824 return -ENOMEM;
5825- if (!vmm || addr + len <= vmm->vm_start)
5826+ if (check_heap_stack_gap(vmm, addr, len))
5827 return addr;
5828 addr = vmm->vm_end;
5829 if (flags & MAP_SHARED)
5830diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5831index 275f74f..81bf5b8 100644
5832--- a/arch/sparc/kernel/sys_sparc_64.c
5833+++ b/arch/sparc/kernel/sys_sparc_64.c
5834@@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5835 /* We do not accept a shared mapping if it would violate
5836 * cache aliasing constraints.
5837 */
5838- if ((flags & MAP_SHARED) &&
5839+ if ((filp || (flags & MAP_SHARED)) &&
5840 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5841 return -EINVAL;
5842 return addr;
5843@@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5844 if (filp || (flags & MAP_SHARED))
5845 do_color_align = 1;
5846
5847+#ifdef CONFIG_PAX_RANDMMAP
5848+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5849+#endif
5850+
5851 if (addr) {
5852 if (do_color_align)
5853 addr = COLOUR_ALIGN(addr, pgoff);
5854@@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5855 addr = PAGE_ALIGN(addr);
5856
5857 vma = find_vma(mm, addr);
5858- if (task_size - len >= addr &&
5859- (!vma || addr + len <= vma->vm_start))
5860+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5861 return addr;
5862 }
5863
5864 if (len > mm->cached_hole_size) {
5865- start_addr = addr = mm->free_area_cache;
5866+ start_addr = addr = mm->free_area_cache;
5867 } else {
5868- start_addr = addr = TASK_UNMAPPED_BASE;
5869+ start_addr = addr = mm->mmap_base;
5870 mm->cached_hole_size = 0;
5871 }
5872
5873@@ -174,14 +177,14 @@ full_search:
5874 vma = find_vma(mm, VA_EXCLUDE_END);
5875 }
5876 if (unlikely(task_size < addr)) {
5877- if (start_addr != TASK_UNMAPPED_BASE) {
5878- start_addr = addr = TASK_UNMAPPED_BASE;
5879+ if (start_addr != mm->mmap_base) {
5880+ start_addr = addr = mm->mmap_base;
5881 mm->cached_hole_size = 0;
5882 goto full_search;
5883 }
5884 return -ENOMEM;
5885 }
5886- if (likely(!vma || addr + len <= vma->vm_start)) {
5887+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5888 /*
5889 * Remember the place where we stopped the search:
5890 */
5891@@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5892 /* We do not accept a shared mapping if it would violate
5893 * cache aliasing constraints.
5894 */
5895- if ((flags & MAP_SHARED) &&
5896+ if ((filp || (flags & MAP_SHARED)) &&
5897 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5898 return -EINVAL;
5899 return addr;
5900@@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5901 addr = PAGE_ALIGN(addr);
5902
5903 vma = find_vma(mm, addr);
5904- if (task_size - len >= addr &&
5905- (!vma || addr + len <= vma->vm_start))
5906+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5907 return addr;
5908 }
5909
5910@@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5911 /* make sure it can fit in the remaining address space */
5912 if (likely(addr > len)) {
5913 vma = find_vma(mm, addr-len);
5914- if (!vma || addr <= vma->vm_start) {
5915+ if (check_heap_stack_gap(vma, addr - len, len)) {
5916 /* remember the address as a hint for next time */
5917 return (mm->free_area_cache = addr-len);
5918 }
5919@@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5920 if (unlikely(mm->mmap_base < len))
5921 goto bottomup;
5922
5923- addr = mm->mmap_base-len;
5924- if (do_color_align)
5925- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5926+ addr = mm->mmap_base - len;
5927
5928 do {
5929+ if (do_color_align)
5930+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5931 /*
5932 * Lookup failure means no vma is above this address,
5933 * else if new region fits below vma->vm_start,
5934 * return with success:
5935 */
5936 vma = find_vma(mm, addr);
5937- if (likely(!vma || addr+len <= vma->vm_start)) {
5938+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5939 /* remember the address as a hint for next time */
5940 return (mm->free_area_cache = addr);
5941 }
5942@@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5943 mm->cached_hole_size = vma->vm_start - addr;
5944
5945 /* try just below the current vma->vm_start */
5946- addr = vma->vm_start-len;
5947- if (do_color_align)
5948- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5949- } while (likely(len < vma->vm_start));
5950+ addr = skip_heap_stack_gap(vma, len);
5951+ } while (!IS_ERR_VALUE(addr));
5952
5953 bottomup:
5954 /*
5955@@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5956 gap == RLIM_INFINITY ||
5957 sysctl_legacy_va_layout) {
5958 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5959+
5960+#ifdef CONFIG_PAX_RANDMMAP
5961+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5962+ mm->mmap_base += mm->delta_mmap;
5963+#endif
5964+
5965 mm->get_unmapped_area = arch_get_unmapped_area;
5966 mm->unmap_area = arch_unmap_area;
5967 } else {
5968@@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5969 gap = (task_size / 6 * 5);
5970
5971 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5972+
5973+#ifdef CONFIG_PAX_RANDMMAP
5974+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5975+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5976+#endif
5977+
5978 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5979 mm->unmap_area = arch_unmap_area_topdown;
5980 }
5981diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
5982index 1d7e274..b39c527 100644
5983--- a/arch/sparc/kernel/syscalls.S
5984+++ b/arch/sparc/kernel/syscalls.S
5985@@ -62,7 +62,7 @@ sys32_rt_sigreturn:
5986 #endif
5987 .align 32
5988 1: ldx [%g6 + TI_FLAGS], %l5
5989- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5990+ andcc %l5, _TIF_WORK_SYSCALL, %g0
5991 be,pt %icc, rtrap
5992 nop
5993 call syscall_trace_leave
5994@@ -179,7 +179,7 @@ linux_sparc_syscall32:
5995
5996 srl %i5, 0, %o5 ! IEU1
5997 srl %i2, 0, %o2 ! IEU0 Group
5998- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5999+ andcc %l0, _TIF_WORK_SYSCALL, %g0
6000 bne,pn %icc, linux_syscall_trace32 ! CTI
6001 mov %i0, %l5 ! IEU1
6002 call %l7 ! CTI Group brk forced
6003@@ -202,7 +202,7 @@ linux_sparc_syscall:
6004
6005 mov %i3, %o3 ! IEU1
6006 mov %i4, %o4 ! IEU0 Group
6007- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6008+ andcc %l0, _TIF_WORK_SYSCALL, %g0
6009 bne,pn %icc, linux_syscall_trace ! CTI Group
6010 mov %i0, %l5 ! IEU0
6011 2: call %l7 ! CTI Group brk forced
6012@@ -226,7 +226,7 @@ ret_sys_call:
6013
6014 cmp %o0, -ERESTART_RESTARTBLOCK
6015 bgeu,pn %xcc, 1f
6016- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6017+ andcc %l0, _TIF_WORK_SYSCALL, %l6
6018 80:
6019 /* System call success, clear Carry condition code. */
6020 andn %g3, %g2, %g3
6021@@ -241,7 +241,7 @@ ret_sys_call:
6022 /* System call failure, set Carry condition code.
6023 * Also, get abs(errno) to return to the process.
6024 */
6025- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6026+ andcc %l0, _TIF_WORK_SYSCALL, %l6
6027 sub %g0, %o0, %o0
6028 or %g3, %g2, %g3
6029 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
6030diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6031index a5785ea..405c5f7 100644
6032--- a/arch/sparc/kernel/traps_32.c
6033+++ b/arch/sparc/kernel/traps_32.c
6034@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
6035 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6036 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6037
6038+extern void gr_handle_kernel_exploit(void);
6039+
6040 void die_if_kernel(char *str, struct pt_regs *regs)
6041 {
6042 static int die_counter;
6043@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6044 count++ < 30 &&
6045 (((unsigned long) rw) >= PAGE_OFFSET) &&
6046 !(((unsigned long) rw) & 0x7)) {
6047- printk("Caller[%08lx]: %pS\n", rw->ins[7],
6048+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
6049 (void *) rw->ins[7]);
6050 rw = (struct reg_window32 *)rw->ins[6];
6051 }
6052 }
6053 printk("Instruction DUMP:");
6054 instruction_dump ((unsigned long *) regs->pc);
6055- if(regs->psr & PSR_PS)
6056+ if(regs->psr & PSR_PS) {
6057+ gr_handle_kernel_exploit();
6058 do_exit(SIGKILL);
6059+ }
6060 do_exit(SIGSEGV);
6061 }
6062
6063diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6064index 3b05e66..6ea2917 100644
6065--- a/arch/sparc/kernel/traps_64.c
6066+++ b/arch/sparc/kernel/traps_64.c
6067@@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6068 i + 1,
6069 p->trapstack[i].tstate, p->trapstack[i].tpc,
6070 p->trapstack[i].tnpc, p->trapstack[i].tt);
6071- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6072+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6073 }
6074 }
6075
6076@@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6077
6078 lvl -= 0x100;
6079 if (regs->tstate & TSTATE_PRIV) {
6080+
6081+#ifdef CONFIG_PAX_REFCOUNT
6082+ if (lvl == 6)
6083+ pax_report_refcount_overflow(regs);
6084+#endif
6085+
6086 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6087 die_if_kernel(buffer, regs);
6088 }
6089@@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6090 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6091 {
6092 char buffer[32];
6093-
6094+
6095 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6096 0, lvl, SIGTRAP) == NOTIFY_STOP)
6097 return;
6098
6099+#ifdef CONFIG_PAX_REFCOUNT
6100+ if (lvl == 6)
6101+ pax_report_refcount_overflow(regs);
6102+#endif
6103+
6104 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6105
6106 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6107@@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6108 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6109 printk("%s" "ERROR(%d): ",
6110 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6111- printk("TPC<%pS>\n", (void *) regs->tpc);
6112+ printk("TPC<%pA>\n", (void *) regs->tpc);
6113 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6114 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6115 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6116@@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6117 smp_processor_id(),
6118 (type & 0x1) ? 'I' : 'D',
6119 regs->tpc);
6120- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6121+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6122 panic("Irrecoverable Cheetah+ parity error.");
6123 }
6124
6125@@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6126 smp_processor_id(),
6127 (type & 0x1) ? 'I' : 'D',
6128 regs->tpc);
6129- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6130+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6131 }
6132
6133 struct sun4v_error_entry {
6134@@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6135
6136 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6137 regs->tpc, tl);
6138- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6139+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6140 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6141- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6142+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6143 (void *) regs->u_regs[UREG_I7]);
6144 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6145 "pte[%lx] error[%lx]\n",
6146@@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6147
6148 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6149 regs->tpc, tl);
6150- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6151+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6152 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6153- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6154+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6155 (void *) regs->u_regs[UREG_I7]);
6156 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6157 "pte[%lx] error[%lx]\n",
6158@@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6159 fp = (unsigned long)sf->fp + STACK_BIAS;
6160 }
6161
6162- printk(" [%016lx] %pS\n", pc, (void *) pc);
6163+ printk(" [%016lx] %pA\n", pc, (void *) pc);
6164 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6165 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6166 int index = tsk->curr_ret_stack;
6167 if (tsk->ret_stack && index >= graph) {
6168 pc = tsk->ret_stack[index - graph].ret;
6169- printk(" [%016lx] %pS\n", pc, (void *) pc);
6170+ printk(" [%016lx] %pA\n", pc, (void *) pc);
6171 graph++;
6172 }
6173 }
6174@@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6175 return (struct reg_window *) (fp + STACK_BIAS);
6176 }
6177
6178+extern void gr_handle_kernel_exploit(void);
6179+
6180 void die_if_kernel(char *str, struct pt_regs *regs)
6181 {
6182 static int die_counter;
6183@@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6184 while (rw &&
6185 count++ < 30 &&
6186 kstack_valid(tp, (unsigned long) rw)) {
6187- printk("Caller[%016lx]: %pS\n", rw->ins[7],
6188+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
6189 (void *) rw->ins[7]);
6190
6191 rw = kernel_stack_up(rw);
6192@@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6193 }
6194 user_instruction_dump ((unsigned int __user *) regs->tpc);
6195 }
6196- if (regs->tstate & TSTATE_PRIV)
6197+ if (regs->tstate & TSTATE_PRIV) {
6198+ gr_handle_kernel_exploit();
6199 do_exit(SIGKILL);
6200+ }
6201 do_exit(SIGSEGV);
6202 }
6203 EXPORT_SYMBOL(die_if_kernel);
6204diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6205index f81d038..e7a4680 100644
6206--- a/arch/sparc/kernel/unaligned_64.c
6207+++ b/arch/sparc/kernel/unaligned_64.c
6208@@ -278,7 +278,7 @@ static void log_unaligned(struct pt_regs *regs)
6209 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6210
6211 if (__ratelimit(&ratelimit)) {
6212- printk("Kernel unaligned access at TPC[%lx] %pS\n",
6213+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
6214 regs->tpc, (void *) regs->tpc);
6215 }
6216 }
6217diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6218index dff4096..bd9a388 100644
6219--- a/arch/sparc/lib/Makefile
6220+++ b/arch/sparc/lib/Makefile
6221@@ -2,7 +2,7 @@
6222 #
6223
6224 asflags-y := -ansi -DST_DIV0=0x02
6225-ccflags-y := -Werror
6226+#ccflags-y := -Werror
6227
6228 lib-$(CONFIG_SPARC32) += ashrdi3.o
6229 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6230diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6231index 4d502da..527c48d 100644
6232--- a/arch/sparc/lib/atomic_64.S
6233+++ b/arch/sparc/lib/atomic_64.S
6234@@ -17,7 +17,12 @@
6235 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6236 BACKOFF_SETUP(%o2)
6237 1: lduw [%o1], %g1
6238- add %g1, %o0, %g7
6239+ addcc %g1, %o0, %g7
6240+
6241+#ifdef CONFIG_PAX_REFCOUNT
6242+ tvs %icc, 6
6243+#endif
6244+
6245 cas [%o1], %g1, %g7
6246 cmp %g1, %g7
6247 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6248@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6249 2: BACKOFF_SPIN(%o2, %o3, 1b)
6250 ENDPROC(atomic_add)
6251
6252+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6253+ BACKOFF_SETUP(%o2)
6254+1: lduw [%o1], %g1
6255+ add %g1, %o0, %g7
6256+ cas [%o1], %g1, %g7
6257+ cmp %g1, %g7
6258+ bne,pn %icc, 2f
6259+ nop
6260+ retl
6261+ nop
6262+2: BACKOFF_SPIN(%o2, %o3, 1b)
6263+ENDPROC(atomic_add_unchecked)
6264+
6265 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6266 BACKOFF_SETUP(%o2)
6267 1: lduw [%o1], %g1
6268- sub %g1, %o0, %g7
6269+ subcc %g1, %o0, %g7
6270+
6271+#ifdef CONFIG_PAX_REFCOUNT
6272+ tvs %icc, 6
6273+#endif
6274+
6275 cas [%o1], %g1, %g7
6276 cmp %g1, %g7
6277 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6278@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6279 2: BACKOFF_SPIN(%o2, %o3, 1b)
6280 ENDPROC(atomic_sub)
6281
6282+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6283+ BACKOFF_SETUP(%o2)
6284+1: lduw [%o1], %g1
6285+ sub %g1, %o0, %g7
6286+ cas [%o1], %g1, %g7
6287+ cmp %g1, %g7
6288+ bne,pn %icc, 2f
6289+ nop
6290+ retl
6291+ nop
6292+2: BACKOFF_SPIN(%o2, %o3, 1b)
6293+ENDPROC(atomic_sub_unchecked)
6294+
6295 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6296 BACKOFF_SETUP(%o2)
6297 1: lduw [%o1], %g1
6298- add %g1, %o0, %g7
6299+ addcc %g1, %o0, %g7
6300+
6301+#ifdef CONFIG_PAX_REFCOUNT
6302+ tvs %icc, 6
6303+#endif
6304+
6305 cas [%o1], %g1, %g7
6306 cmp %g1, %g7
6307 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6308@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6309 2: BACKOFF_SPIN(%o2, %o3, 1b)
6310 ENDPROC(atomic_add_ret)
6311
6312+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6313+ BACKOFF_SETUP(%o2)
6314+1: lduw [%o1], %g1
6315+ addcc %g1, %o0, %g7
6316+ cas [%o1], %g1, %g7
6317+ cmp %g1, %g7
6318+ bne,pn %icc, 2f
6319+ add %g7, %o0, %g7
6320+ sra %g7, 0, %o0
6321+ retl
6322+ nop
6323+2: BACKOFF_SPIN(%o2, %o3, 1b)
6324+ENDPROC(atomic_add_ret_unchecked)
6325+
6326 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6327 BACKOFF_SETUP(%o2)
6328 1: lduw [%o1], %g1
6329- sub %g1, %o0, %g7
6330+ subcc %g1, %o0, %g7
6331+
6332+#ifdef CONFIG_PAX_REFCOUNT
6333+ tvs %icc, 6
6334+#endif
6335+
6336 cas [%o1], %g1, %g7
6337 cmp %g1, %g7
6338 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6339@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
6340 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6341 BACKOFF_SETUP(%o2)
6342 1: ldx [%o1], %g1
6343- add %g1, %o0, %g7
6344+ addcc %g1, %o0, %g7
6345+
6346+#ifdef CONFIG_PAX_REFCOUNT
6347+ tvs %xcc, 6
6348+#endif
6349+
6350 casx [%o1], %g1, %g7
6351 cmp %g1, %g7
6352 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6353@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6354 2: BACKOFF_SPIN(%o2, %o3, 1b)
6355 ENDPROC(atomic64_add)
6356
6357+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6358+ BACKOFF_SETUP(%o2)
6359+1: ldx [%o1], %g1
6360+ addcc %g1, %o0, %g7
6361+ casx [%o1], %g1, %g7
6362+ cmp %g1, %g7
6363+ bne,pn %xcc, 2f
6364+ nop
6365+ retl
6366+ nop
6367+2: BACKOFF_SPIN(%o2, %o3, 1b)
6368+ENDPROC(atomic64_add_unchecked)
6369+
6370 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6371 BACKOFF_SETUP(%o2)
6372 1: ldx [%o1], %g1
6373- sub %g1, %o0, %g7
6374+ subcc %g1, %o0, %g7
6375+
6376+#ifdef CONFIG_PAX_REFCOUNT
6377+ tvs %xcc, 6
6378+#endif
6379+
6380 casx [%o1], %g1, %g7
6381 cmp %g1, %g7
6382 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6383@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6384 2: BACKOFF_SPIN(%o2, %o3, 1b)
6385 ENDPROC(atomic64_sub)
6386
6387+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6388+ BACKOFF_SETUP(%o2)
6389+1: ldx [%o1], %g1
6390+ subcc %g1, %o0, %g7
6391+ casx [%o1], %g1, %g7
6392+ cmp %g1, %g7
6393+ bne,pn %xcc, 2f
6394+ nop
6395+ retl
6396+ nop
6397+2: BACKOFF_SPIN(%o2, %o3, 1b)
6398+ENDPROC(atomic64_sub_unchecked)
6399+
6400 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6401 BACKOFF_SETUP(%o2)
6402 1: ldx [%o1], %g1
6403- add %g1, %o0, %g7
6404+ addcc %g1, %o0, %g7
6405+
6406+#ifdef CONFIG_PAX_REFCOUNT
6407+ tvs %xcc, 6
6408+#endif
6409+
6410 casx [%o1], %g1, %g7
6411 cmp %g1, %g7
6412 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6413@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6414 2: BACKOFF_SPIN(%o2, %o3, 1b)
6415 ENDPROC(atomic64_add_ret)
6416
6417+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6418+ BACKOFF_SETUP(%o2)
6419+1: ldx [%o1], %g1
6420+ addcc %g1, %o0, %g7
6421+ casx [%o1], %g1, %g7
6422+ cmp %g1, %g7
6423+ bne,pn %xcc, 2f
6424+ add %g7, %o0, %g7
6425+ mov %g7, %o0
6426+ retl
6427+ nop
6428+2: BACKOFF_SPIN(%o2, %o3, 1b)
6429+ENDPROC(atomic64_add_ret_unchecked)
6430+
6431 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6432 BACKOFF_SETUP(%o2)
6433 1: ldx [%o1], %g1
6434- sub %g1, %o0, %g7
6435+ subcc %g1, %o0, %g7
6436+
6437+#ifdef CONFIG_PAX_REFCOUNT
6438+ tvs %xcc, 6
6439+#endif
6440+
6441 casx [%o1], %g1, %g7
6442 cmp %g1, %g7
6443 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6444diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6445index 3b31218..345c609 100644
6446--- a/arch/sparc/lib/ksyms.c
6447+++ b/arch/sparc/lib/ksyms.c
6448@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
6449
6450 /* Atomic counter implementation. */
6451 EXPORT_SYMBOL(atomic_add);
6452+EXPORT_SYMBOL(atomic_add_unchecked);
6453 EXPORT_SYMBOL(atomic_add_ret);
6454+EXPORT_SYMBOL(atomic_add_ret_unchecked);
6455 EXPORT_SYMBOL(atomic_sub);
6456+EXPORT_SYMBOL(atomic_sub_unchecked);
6457 EXPORT_SYMBOL(atomic_sub_ret);
6458 EXPORT_SYMBOL(atomic64_add);
6459+EXPORT_SYMBOL(atomic64_add_unchecked);
6460 EXPORT_SYMBOL(atomic64_add_ret);
6461+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6462 EXPORT_SYMBOL(atomic64_sub);
6463+EXPORT_SYMBOL(atomic64_sub_unchecked);
6464 EXPORT_SYMBOL(atomic64_sub_ret);
6465
6466 /* Atomic bit operations. */
6467diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6468index 30c3ecc..736f015 100644
6469--- a/arch/sparc/mm/Makefile
6470+++ b/arch/sparc/mm/Makefile
6471@@ -2,7 +2,7 @@
6472 #
6473
6474 asflags-y := -ansi
6475-ccflags-y := -Werror
6476+#ccflags-y := -Werror
6477
6478 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6479 obj-y += fault_$(BITS).o
6480diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6481index f46cf6b..cc0666bae 100644
6482--- a/arch/sparc/mm/fault_32.c
6483+++ b/arch/sparc/mm/fault_32.c
6484@@ -21,6 +21,9 @@
6485 #include <linux/perf_event.h>
6486 #include <linux/interrupt.h>
6487 #include <linux/kdebug.h>
6488+#include <linux/slab.h>
6489+#include <linux/pagemap.h>
6490+#include <linux/compiler.h>
6491
6492 #include <asm/page.h>
6493 #include <asm/pgtable.h>
6494@@ -177,6 +180,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6495 return safe_compute_effective_address(regs, insn);
6496 }
6497
6498+#ifdef CONFIG_PAX_PAGEEXEC
6499+#ifdef CONFIG_PAX_DLRESOLVE
6500+static void pax_emuplt_close(struct vm_area_struct *vma)
6501+{
6502+ vma->vm_mm->call_dl_resolve = 0UL;
6503+}
6504+
6505+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6506+{
6507+ unsigned int *kaddr;
6508+
6509+ vmf->page = alloc_page(GFP_HIGHUSER);
6510+ if (!vmf->page)
6511+ return VM_FAULT_OOM;
6512+
6513+ kaddr = kmap(vmf->page);
6514+ memset(kaddr, 0, PAGE_SIZE);
6515+ kaddr[0] = 0x9DE3BFA8U; /* save */
6516+ flush_dcache_page(vmf->page);
6517+ kunmap(vmf->page);
6518+ return VM_FAULT_MAJOR;
6519+}
6520+
6521+static const struct vm_operations_struct pax_vm_ops = {
6522+ .close = pax_emuplt_close,
6523+ .fault = pax_emuplt_fault
6524+};
6525+
6526+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6527+{
6528+ int ret;
6529+
6530+ INIT_LIST_HEAD(&vma->anon_vma_chain);
6531+ vma->vm_mm = current->mm;
6532+ vma->vm_start = addr;
6533+ vma->vm_end = addr + PAGE_SIZE;
6534+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6535+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6536+ vma->vm_ops = &pax_vm_ops;
6537+
6538+ ret = insert_vm_struct(current->mm, vma);
6539+ if (ret)
6540+ return ret;
6541+
6542+ ++current->mm->total_vm;
6543+ return 0;
6544+}
6545+#endif
6546+
6547+/*
6548+ * PaX: decide what to do with offenders (regs->pc = fault address)
6549+ *
6550+ * returns 1 when task should be killed
6551+ * 2 when patched PLT trampoline was detected
6552+ * 3 when unpatched PLT trampoline was detected
6553+ */
6554+static int pax_handle_fetch_fault(struct pt_regs *regs)
6555+{
6556+
6557+#ifdef CONFIG_PAX_EMUPLT
6558+ int err;
6559+
6560+ do { /* PaX: patched PLT emulation #1 */
6561+ unsigned int sethi1, sethi2, jmpl;
6562+
6563+ err = get_user(sethi1, (unsigned int *)regs->pc);
6564+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6565+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6566+
6567+ if (err)
6568+ break;
6569+
6570+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6571+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
6572+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
6573+ {
6574+ unsigned int addr;
6575+
6576+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6577+ addr = regs->u_regs[UREG_G1];
6578+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6579+ regs->pc = addr;
6580+ regs->npc = addr+4;
6581+ return 2;
6582+ }
6583+ } while (0);
6584+
6585+ do { /* PaX: patched PLT emulation #2 */
6586+ unsigned int ba;
6587+
6588+ err = get_user(ba, (unsigned int *)regs->pc);
6589+
6590+ if (err)
6591+ break;
6592+
6593+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6594+ unsigned int addr;
6595+
6596+ if ((ba & 0xFFC00000U) == 0x30800000U)
6597+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6598+ else
6599+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6600+ regs->pc = addr;
6601+ regs->npc = addr+4;
6602+ return 2;
6603+ }
6604+ } while (0);
6605+
6606+ do { /* PaX: patched PLT emulation #3 */
6607+ unsigned int sethi, bajmpl, nop;
6608+
6609+ err = get_user(sethi, (unsigned int *)regs->pc);
6610+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
6611+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
6612+
6613+ if (err)
6614+ break;
6615+
6616+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6617+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6618+ nop == 0x01000000U)
6619+ {
6620+ unsigned int addr;
6621+
6622+ addr = (sethi & 0x003FFFFFU) << 10;
6623+ regs->u_regs[UREG_G1] = addr;
6624+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6625+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6626+ else
6627+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6628+ regs->pc = addr;
6629+ regs->npc = addr+4;
6630+ return 2;
6631+ }
6632+ } while (0);
6633+
6634+ do { /* PaX: unpatched PLT emulation step 1 */
6635+ unsigned int sethi, ba, nop;
6636+
6637+ err = get_user(sethi, (unsigned int *)regs->pc);
6638+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
6639+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
6640+
6641+ if (err)
6642+ break;
6643+
6644+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6645+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6646+ nop == 0x01000000U)
6647+ {
6648+ unsigned int addr, save, call;
6649+
6650+ if ((ba & 0xFFC00000U) == 0x30800000U)
6651+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6652+ else
6653+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6654+
6655+ err = get_user(save, (unsigned int *)addr);
6656+ err |= get_user(call, (unsigned int *)(addr+4));
6657+ err |= get_user(nop, (unsigned int *)(addr+8));
6658+ if (err)
6659+ break;
6660+
6661+#ifdef CONFIG_PAX_DLRESOLVE
6662+ if (save == 0x9DE3BFA8U &&
6663+ (call & 0xC0000000U) == 0x40000000U &&
6664+ nop == 0x01000000U)
6665+ {
6666+ struct vm_area_struct *vma;
6667+ unsigned long call_dl_resolve;
6668+
6669+ down_read(&current->mm->mmap_sem);
6670+ call_dl_resolve = current->mm->call_dl_resolve;
6671+ up_read(&current->mm->mmap_sem);
6672+ if (likely(call_dl_resolve))
6673+ goto emulate;
6674+
6675+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6676+
6677+ down_write(&current->mm->mmap_sem);
6678+ if (current->mm->call_dl_resolve) {
6679+ call_dl_resolve = current->mm->call_dl_resolve;
6680+ up_write(&current->mm->mmap_sem);
6681+ if (vma)
6682+ kmem_cache_free(vm_area_cachep, vma);
6683+ goto emulate;
6684+ }
6685+
6686+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6687+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6688+ up_write(&current->mm->mmap_sem);
6689+ if (vma)
6690+ kmem_cache_free(vm_area_cachep, vma);
6691+ return 1;
6692+ }
6693+
6694+ if (pax_insert_vma(vma, call_dl_resolve)) {
6695+ up_write(&current->mm->mmap_sem);
6696+ kmem_cache_free(vm_area_cachep, vma);
6697+ return 1;
6698+ }
6699+
6700+ current->mm->call_dl_resolve = call_dl_resolve;
6701+ up_write(&current->mm->mmap_sem);
6702+
6703+emulate:
6704+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6705+ regs->pc = call_dl_resolve;
6706+ regs->npc = addr+4;
6707+ return 3;
6708+ }
6709+#endif
6710+
6711+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6712+ if ((save & 0xFFC00000U) == 0x05000000U &&
6713+ (call & 0xFFFFE000U) == 0x85C0A000U &&
6714+ nop == 0x01000000U)
6715+ {
6716+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6717+ regs->u_regs[UREG_G2] = addr + 4;
6718+ addr = (save & 0x003FFFFFU) << 10;
6719+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6720+ regs->pc = addr;
6721+ regs->npc = addr+4;
6722+ return 3;
6723+ }
6724+ }
6725+ } while (0);
6726+
6727+ do { /* PaX: unpatched PLT emulation step 2 */
6728+ unsigned int save, call, nop;
6729+
6730+ err = get_user(save, (unsigned int *)(regs->pc-4));
6731+ err |= get_user(call, (unsigned int *)regs->pc);
6732+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
6733+ if (err)
6734+ break;
6735+
6736+ if (save == 0x9DE3BFA8U &&
6737+ (call & 0xC0000000U) == 0x40000000U &&
6738+ nop == 0x01000000U)
6739+ {
6740+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6741+
6742+ regs->u_regs[UREG_RETPC] = regs->pc;
6743+ regs->pc = dl_resolve;
6744+ regs->npc = dl_resolve+4;
6745+ return 3;
6746+ }
6747+ } while (0);
6748+#endif
6749+
6750+ return 1;
6751+}
6752+
6753+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6754+{
6755+ unsigned long i;
6756+
6757+ printk(KERN_ERR "PAX: bytes at PC: ");
6758+ for (i = 0; i < 8; i++) {
6759+ unsigned int c;
6760+ if (get_user(c, (unsigned int *)pc+i))
6761+ printk(KERN_CONT "???????? ");
6762+ else
6763+ printk(KERN_CONT "%08x ", c);
6764+ }
6765+ printk("\n");
6766+}
6767+#endif
6768+
6769 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6770 int text_fault)
6771 {
6772@@ -248,6 +522,24 @@ good_area:
6773 if (!(vma->vm_flags & VM_WRITE))
6774 goto bad_area;
6775 } else {
6776+
6777+#ifdef CONFIG_PAX_PAGEEXEC
6778+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6779+ up_read(&mm->mmap_sem);
6780+ switch (pax_handle_fetch_fault(regs)) {
6781+
6782+#ifdef CONFIG_PAX_EMUPLT
6783+ case 2:
6784+ case 3:
6785+ return;
6786+#endif
6787+
6788+ }
6789+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6790+ do_group_exit(SIGKILL);
6791+ }
6792+#endif
6793+
6794 /* Allow reads even for write-only mappings */
6795 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
6796 goto bad_area;
6797diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6798index 1fe0429..8dd5dd5 100644
6799--- a/arch/sparc/mm/fault_64.c
6800+++ b/arch/sparc/mm/fault_64.c
6801@@ -21,6 +21,9 @@
6802 #include <linux/kprobes.h>
6803 #include <linux/kdebug.h>
6804 #include <linux/percpu.h>
6805+#include <linux/slab.h>
6806+#include <linux/pagemap.h>
6807+#include <linux/compiler.h>
6808
6809 #include <asm/page.h>
6810 #include <asm/pgtable.h>
6811@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6812 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6813 regs->tpc);
6814 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6815- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6816+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6817 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6818 dump_stack();
6819 unhandled_fault(regs->tpc, current, regs);
6820@@ -272,6 +275,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6821 show_regs(regs);
6822 }
6823
6824+#ifdef CONFIG_PAX_PAGEEXEC
6825+#ifdef CONFIG_PAX_DLRESOLVE
6826+static void pax_emuplt_close(struct vm_area_struct *vma)
6827+{
6828+ vma->vm_mm->call_dl_resolve = 0UL;
6829+}
6830+
6831+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6832+{
6833+ unsigned int *kaddr;
6834+
6835+ vmf->page = alloc_page(GFP_HIGHUSER);
6836+ if (!vmf->page)
6837+ return VM_FAULT_OOM;
6838+
6839+ kaddr = kmap(vmf->page);
6840+ memset(kaddr, 0, PAGE_SIZE);
6841+ kaddr[0] = 0x9DE3BFA8U; /* save */
6842+ flush_dcache_page(vmf->page);
6843+ kunmap(vmf->page);
6844+ return VM_FAULT_MAJOR;
6845+}
6846+
6847+static const struct vm_operations_struct pax_vm_ops = {
6848+ .close = pax_emuplt_close,
6849+ .fault = pax_emuplt_fault
6850+};
6851+
6852+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6853+{
6854+ int ret;
6855+
6856+ INIT_LIST_HEAD(&vma->anon_vma_chain);
6857+ vma->vm_mm = current->mm;
6858+ vma->vm_start = addr;
6859+ vma->vm_end = addr + PAGE_SIZE;
6860+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6861+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6862+ vma->vm_ops = &pax_vm_ops;
6863+
6864+ ret = insert_vm_struct(current->mm, vma);
6865+ if (ret)
6866+ return ret;
6867+
6868+ ++current->mm->total_vm;
6869+ return 0;
6870+}
6871+#endif
6872+
6873+/*
6874+ * PaX: decide what to do with offenders (regs->tpc = fault address)
6875+ *
6876+ * returns 1 when task should be killed
6877+ * 2 when patched PLT trampoline was detected
6878+ * 3 when unpatched PLT trampoline was detected
6879+ */
6880+static int pax_handle_fetch_fault(struct pt_regs *regs)
6881+{
6882+
6883+#ifdef CONFIG_PAX_EMUPLT
6884+ int err;
6885+
6886+ do { /* PaX: patched PLT emulation #1 */
6887+ unsigned int sethi1, sethi2, jmpl;
6888+
6889+ err = get_user(sethi1, (unsigned int *)regs->tpc);
6890+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6891+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6892+
6893+ if (err)
6894+ break;
6895+
6896+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6897+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
6898+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
6899+ {
6900+ unsigned long addr;
6901+
6902+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6903+ addr = regs->u_regs[UREG_G1];
6904+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6905+
6906+ if (test_thread_flag(TIF_32BIT))
6907+ addr &= 0xFFFFFFFFUL;
6908+
6909+ regs->tpc = addr;
6910+ regs->tnpc = addr+4;
6911+ return 2;
6912+ }
6913+ } while (0);
6914+
6915+ do { /* PaX: patched PLT emulation #2 */
6916+ unsigned int ba;
6917+
6918+ err = get_user(ba, (unsigned int *)regs->tpc);
6919+
6920+ if (err)
6921+ break;
6922+
6923+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6924+ unsigned long addr;
6925+
6926+ if ((ba & 0xFFC00000U) == 0x30800000U)
6927+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6928+ else
6929+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6930+
6931+ if (test_thread_flag(TIF_32BIT))
6932+ addr &= 0xFFFFFFFFUL;
6933+
6934+ regs->tpc = addr;
6935+ regs->tnpc = addr+4;
6936+ return 2;
6937+ }
6938+ } while (0);
6939+
6940+ do { /* PaX: patched PLT emulation #3 */
6941+ unsigned int sethi, bajmpl, nop;
6942+
6943+ err = get_user(sethi, (unsigned int *)regs->tpc);
6944+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
6945+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6946+
6947+ if (err)
6948+ break;
6949+
6950+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6951+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6952+ nop == 0x01000000U)
6953+ {
6954+ unsigned long addr;
6955+
6956+ addr = (sethi & 0x003FFFFFU) << 10;
6957+ regs->u_regs[UREG_G1] = addr;
6958+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6959+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6960+ else
6961+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6962+
6963+ if (test_thread_flag(TIF_32BIT))
6964+ addr &= 0xFFFFFFFFUL;
6965+
6966+ regs->tpc = addr;
6967+ regs->tnpc = addr+4;
6968+ return 2;
6969+ }
6970+ } while (0);
6971+
6972+ do { /* PaX: patched PLT emulation #4 */
6973+ unsigned int sethi, mov1, call, mov2;
6974+
6975+ err = get_user(sethi, (unsigned int *)regs->tpc);
6976+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6977+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
6978+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6979+
6980+ if (err)
6981+ break;
6982+
6983+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6984+ mov1 == 0x8210000FU &&
6985+ (call & 0xC0000000U) == 0x40000000U &&
6986+ mov2 == 0x9E100001U)
6987+ {
6988+ unsigned long addr;
6989+
6990+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6991+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6992+
6993+ if (test_thread_flag(TIF_32BIT))
6994+ addr &= 0xFFFFFFFFUL;
6995+
6996+ regs->tpc = addr;
6997+ regs->tnpc = addr+4;
6998+ return 2;
6999+ }
7000+ } while (0);
7001+
7002+ do { /* PaX: patched PLT emulation #5 */
7003+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
7004+
7005+ err = get_user(sethi, (unsigned int *)regs->tpc);
7006+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7007+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7008+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
7009+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
7010+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
7011+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
7012+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
7013+
7014+ if (err)
7015+ break;
7016+
7017+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7018+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
7019+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7020+ (or1 & 0xFFFFE000U) == 0x82106000U &&
7021+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
7022+ sllx == 0x83287020U &&
7023+ jmpl == 0x81C04005U &&
7024+ nop == 0x01000000U)
7025+ {
7026+ unsigned long addr;
7027+
7028+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7029+ regs->u_regs[UREG_G1] <<= 32;
7030+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7031+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7032+ regs->tpc = addr;
7033+ regs->tnpc = addr+4;
7034+ return 2;
7035+ }
7036+ } while (0);
7037+
7038+ do { /* PaX: patched PLT emulation #6 */
7039+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7040+
7041+ err = get_user(sethi, (unsigned int *)regs->tpc);
7042+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7043+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7044+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7045+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
7046+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7047+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7048+
7049+ if (err)
7050+ break;
7051+
7052+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7053+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
7054+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7055+ sllx == 0x83287020U &&
7056+ (or & 0xFFFFE000U) == 0x8A116000U &&
7057+ jmpl == 0x81C04005U &&
7058+ nop == 0x01000000U)
7059+ {
7060+ unsigned long addr;
7061+
7062+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7063+ regs->u_regs[UREG_G1] <<= 32;
7064+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7065+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7066+ regs->tpc = addr;
7067+ regs->tnpc = addr+4;
7068+ return 2;
7069+ }
7070+ } while (0);
7071+
7072+ do { /* PaX: unpatched PLT emulation step 1 */
7073+ unsigned int sethi, ba, nop;
7074+
7075+ err = get_user(sethi, (unsigned int *)regs->tpc);
7076+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7077+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7078+
7079+ if (err)
7080+ break;
7081+
7082+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7083+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7084+ nop == 0x01000000U)
7085+ {
7086+ unsigned long addr;
7087+ unsigned int save, call;
7088+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7089+
7090+ if ((ba & 0xFFC00000U) == 0x30800000U)
7091+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7092+ else
7093+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7094+
7095+ if (test_thread_flag(TIF_32BIT))
7096+ addr &= 0xFFFFFFFFUL;
7097+
7098+ err = get_user(save, (unsigned int *)addr);
7099+ err |= get_user(call, (unsigned int *)(addr+4));
7100+ err |= get_user(nop, (unsigned int *)(addr+8));
7101+ if (err)
7102+ break;
7103+
7104+#ifdef CONFIG_PAX_DLRESOLVE
7105+ if (save == 0x9DE3BFA8U &&
7106+ (call & 0xC0000000U) == 0x40000000U &&
7107+ nop == 0x01000000U)
7108+ {
7109+ struct vm_area_struct *vma;
7110+ unsigned long call_dl_resolve;
7111+
7112+ down_read(&current->mm->mmap_sem);
7113+ call_dl_resolve = current->mm->call_dl_resolve;
7114+ up_read(&current->mm->mmap_sem);
7115+ if (likely(call_dl_resolve))
7116+ goto emulate;
7117+
7118+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7119+
7120+ down_write(&current->mm->mmap_sem);
7121+ if (current->mm->call_dl_resolve) {
7122+ call_dl_resolve = current->mm->call_dl_resolve;
7123+ up_write(&current->mm->mmap_sem);
7124+ if (vma)
7125+ kmem_cache_free(vm_area_cachep, vma);
7126+ goto emulate;
7127+ }
7128+
7129+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7130+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7131+ up_write(&current->mm->mmap_sem);
7132+ if (vma)
7133+ kmem_cache_free(vm_area_cachep, vma);
7134+ return 1;
7135+ }
7136+
7137+ if (pax_insert_vma(vma, call_dl_resolve)) {
7138+ up_write(&current->mm->mmap_sem);
7139+ kmem_cache_free(vm_area_cachep, vma);
7140+ return 1;
7141+ }
7142+
7143+ current->mm->call_dl_resolve = call_dl_resolve;
7144+ up_write(&current->mm->mmap_sem);
7145+
7146+emulate:
7147+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7148+ regs->tpc = call_dl_resolve;
7149+ regs->tnpc = addr+4;
7150+ return 3;
7151+ }
7152+#endif
7153+
7154+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7155+ if ((save & 0xFFC00000U) == 0x05000000U &&
7156+ (call & 0xFFFFE000U) == 0x85C0A000U &&
7157+ nop == 0x01000000U)
7158+ {
7159+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7160+ regs->u_regs[UREG_G2] = addr + 4;
7161+ addr = (save & 0x003FFFFFU) << 10;
7162+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7163+
7164+ if (test_thread_flag(TIF_32BIT))
7165+ addr &= 0xFFFFFFFFUL;
7166+
7167+ regs->tpc = addr;
7168+ regs->tnpc = addr+4;
7169+ return 3;
7170+ }
7171+
7172+ /* PaX: 64-bit PLT stub */
7173+ err = get_user(sethi1, (unsigned int *)addr);
7174+ err |= get_user(sethi2, (unsigned int *)(addr+4));
7175+ err |= get_user(or1, (unsigned int *)(addr+8));
7176+ err |= get_user(or2, (unsigned int *)(addr+12));
7177+ err |= get_user(sllx, (unsigned int *)(addr+16));
7178+ err |= get_user(add, (unsigned int *)(addr+20));
7179+ err |= get_user(jmpl, (unsigned int *)(addr+24));
7180+ err |= get_user(nop, (unsigned int *)(addr+28));
7181+ if (err)
7182+ break;
7183+
7184+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7185+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7186+ (or1 & 0xFFFFE000U) == 0x88112000U &&
7187+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
7188+ sllx == 0x89293020U &&
7189+ add == 0x8A010005U &&
7190+ jmpl == 0x89C14000U &&
7191+ nop == 0x01000000U)
7192+ {
7193+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7194+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7195+ regs->u_regs[UREG_G4] <<= 32;
7196+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7197+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7198+ regs->u_regs[UREG_G4] = addr + 24;
7199+ addr = regs->u_regs[UREG_G5];
7200+ regs->tpc = addr;
7201+ regs->tnpc = addr+4;
7202+ return 3;
7203+ }
7204+ }
7205+ } while (0);
7206+
7207+#ifdef CONFIG_PAX_DLRESOLVE
7208+ do { /* PaX: unpatched PLT emulation step 2 */
7209+ unsigned int save, call, nop;
7210+
7211+ err = get_user(save, (unsigned int *)(regs->tpc-4));
7212+ err |= get_user(call, (unsigned int *)regs->tpc);
7213+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7214+ if (err)
7215+ break;
7216+
7217+ if (save == 0x9DE3BFA8U &&
7218+ (call & 0xC0000000U) == 0x40000000U &&
7219+ nop == 0x01000000U)
7220+ {
7221+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7222+
7223+ if (test_thread_flag(TIF_32BIT))
7224+ dl_resolve &= 0xFFFFFFFFUL;
7225+
7226+ regs->u_regs[UREG_RETPC] = regs->tpc;
7227+ regs->tpc = dl_resolve;
7228+ regs->tnpc = dl_resolve+4;
7229+ return 3;
7230+ }
7231+ } while (0);
7232+#endif
7233+
7234+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7235+ unsigned int sethi, ba, nop;
7236+
7237+ err = get_user(sethi, (unsigned int *)regs->tpc);
7238+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7239+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7240+
7241+ if (err)
7242+ break;
7243+
7244+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7245+ (ba & 0xFFF00000U) == 0x30600000U &&
7246+ nop == 0x01000000U)
7247+ {
7248+ unsigned long addr;
7249+
7250+ addr = (sethi & 0x003FFFFFU) << 10;
7251+ regs->u_regs[UREG_G1] = addr;
7252+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7253+
7254+ if (test_thread_flag(TIF_32BIT))
7255+ addr &= 0xFFFFFFFFUL;
7256+
7257+ regs->tpc = addr;
7258+ regs->tnpc = addr+4;
7259+ return 2;
7260+ }
7261+ } while (0);
7262+
7263+#endif
7264+
7265+ return 1;
7266+}
7267+
7268+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7269+{
7270+ unsigned long i;
7271+
7272+ printk(KERN_ERR "PAX: bytes at PC: ");
7273+ for (i = 0; i < 8; i++) {
7274+ unsigned int c;
7275+ if (get_user(c, (unsigned int *)pc+i))
7276+ printk(KERN_CONT "???????? ");
7277+ else
7278+ printk(KERN_CONT "%08x ", c);
7279+ }
7280+ printk("\n");
7281+}
7282+#endif
7283+
7284 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7285 {
7286 struct mm_struct *mm = current->mm;
7287@@ -343,6 +806,29 @@ retry:
7288 if (!vma)
7289 goto bad_area;
7290
7291+#ifdef CONFIG_PAX_PAGEEXEC
7292+ /* PaX: detect ITLB misses on non-exec pages */
7293+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7294+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7295+ {
7296+ if (address != regs->tpc)
7297+ goto good_area;
7298+
7299+ up_read(&mm->mmap_sem);
7300+ switch (pax_handle_fetch_fault(regs)) {
7301+
7302+#ifdef CONFIG_PAX_EMUPLT
7303+ case 2:
7304+ case 3:
7305+ return;
7306+#endif
7307+
7308+ }
7309+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7310+ do_group_exit(SIGKILL);
7311+ }
7312+#endif
7313+
7314 /* Pure DTLB misses do not tell us whether the fault causing
7315 * load/store/atomic was a write or not, it only says that there
7316 * was no match. So in such a case we (carefully) read the
7317diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7318index 07e1453..0a7d9e9 100644
7319--- a/arch/sparc/mm/hugetlbpage.c
7320+++ b/arch/sparc/mm/hugetlbpage.c
7321@@ -67,7 +67,7 @@ full_search:
7322 }
7323 return -ENOMEM;
7324 }
7325- if (likely(!vma || addr + len <= vma->vm_start)) {
7326+ if (likely(check_heap_stack_gap(vma, addr, len))) {
7327 /*
7328 * Remember the place where we stopped the search:
7329 */
7330@@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7331 /* make sure it can fit in the remaining address space */
7332 if (likely(addr > len)) {
7333 vma = find_vma(mm, addr-len);
7334- if (!vma || addr <= vma->vm_start) {
7335+ if (check_heap_stack_gap(vma, addr - len, len)) {
7336 /* remember the address as a hint for next time */
7337 return (mm->free_area_cache = addr-len);
7338 }
7339@@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7340 if (unlikely(mm->mmap_base < len))
7341 goto bottomup;
7342
7343- addr = (mm->mmap_base-len) & HPAGE_MASK;
7344+ addr = mm->mmap_base - len;
7345
7346 do {
7347+ addr &= HPAGE_MASK;
7348 /*
7349 * Lookup failure means no vma is above this address,
7350 * else if new region fits below vma->vm_start,
7351 * return with success:
7352 */
7353 vma = find_vma(mm, addr);
7354- if (likely(!vma || addr+len <= vma->vm_start)) {
7355+ if (likely(check_heap_stack_gap(vma, addr, len))) {
7356 /* remember the address as a hint for next time */
7357 return (mm->free_area_cache = addr);
7358 }
7359@@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7360 mm->cached_hole_size = vma->vm_start - addr;
7361
7362 /* try just below the current vma->vm_start */
7363- addr = (vma->vm_start-len) & HPAGE_MASK;
7364- } while (likely(len < vma->vm_start));
7365+ addr = skip_heap_stack_gap(vma, len);
7366+ } while (!IS_ERR_VALUE(addr));
7367
7368 bottomup:
7369 /*
7370@@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7371 if (addr) {
7372 addr = ALIGN(addr, HPAGE_SIZE);
7373 vma = find_vma(mm, addr);
7374- if (task_size - len >= addr &&
7375- (!vma || addr + len <= vma->vm_start))
7376+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7377 return addr;
7378 }
7379 if (mm->get_unmapped_area == arch_get_unmapped_area)
7380diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7381index f4500c6..889656c 100644
7382--- a/arch/tile/include/asm/atomic_64.h
7383+++ b/arch/tile/include/asm/atomic_64.h
7384@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7385
7386 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7387
7388+#define atomic64_read_unchecked(v) atomic64_read(v)
7389+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7390+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7391+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7392+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7393+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7394+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7395+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7396+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7397+
7398 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7399 #define smp_mb__before_atomic_dec() smp_mb()
7400 #define smp_mb__after_atomic_dec() smp_mb()
7401diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7402index 392e533..536b092 100644
7403--- a/arch/tile/include/asm/cache.h
7404+++ b/arch/tile/include/asm/cache.h
7405@@ -15,11 +15,12 @@
7406 #ifndef _ASM_TILE_CACHE_H
7407 #define _ASM_TILE_CACHE_H
7408
7409+#include <linux/const.h>
7410 #include <arch/chip.h>
7411
7412 /* bytes per L1 data cache line */
7413 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7414-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7415+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7416
7417 /* bytes per L2 cache line */
7418 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7419diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
7420index 9ab078a..d6635c2 100644
7421--- a/arch/tile/include/asm/uaccess.h
7422+++ b/arch/tile/include/asm/uaccess.h
7423@@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
7424 const void __user *from,
7425 unsigned long n)
7426 {
7427- int sz = __compiletime_object_size(to);
7428+ size_t sz = __compiletime_object_size(to);
7429
7430- if (likely(sz == -1 || sz >= n))
7431+ if (likely(sz == (size_t)-1 || sz >= n))
7432 n = _copy_from_user(to, from, n);
7433 else
7434 copy_from_user_overflow();
7435diff --git a/arch/um/Makefile b/arch/um/Makefile
7436index 0970910..13adb57a 100644
7437--- a/arch/um/Makefile
7438+++ b/arch/um/Makefile
7439@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7440 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7441 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7442
7443+ifdef CONSTIFY_PLUGIN
7444+USER_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7445+endif
7446+
7447 #This will adjust *FLAGS accordingly to the platform.
7448 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7449
7450diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7451index 19e1bdd..3665b77 100644
7452--- a/arch/um/include/asm/cache.h
7453+++ b/arch/um/include/asm/cache.h
7454@@ -1,6 +1,7 @@
7455 #ifndef __UM_CACHE_H
7456 #define __UM_CACHE_H
7457
7458+#include <linux/const.h>
7459
7460 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7461 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7462@@ -12,6 +13,6 @@
7463 # define L1_CACHE_SHIFT 5
7464 #endif
7465
7466-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7467+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7468
7469 #endif
7470diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7471index 6c03acd..a5e0215 100644
7472--- a/arch/um/include/asm/kmap_types.h
7473+++ b/arch/um/include/asm/kmap_types.h
7474@@ -23,6 +23,7 @@ enum km_type {
7475 KM_IRQ1,
7476 KM_SOFTIRQ0,
7477 KM_SOFTIRQ1,
7478+ KM_CLEARPAGE,
7479 KM_TYPE_NR
7480 };
7481
7482diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7483index 7cfc3ce..cbd1a58 100644
7484--- a/arch/um/include/asm/page.h
7485+++ b/arch/um/include/asm/page.h
7486@@ -14,6 +14,9 @@
7487 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7488 #define PAGE_MASK (~(PAGE_SIZE-1))
7489
7490+#define ktla_ktva(addr) (addr)
7491+#define ktva_ktla(addr) (addr)
7492+
7493 #ifndef __ASSEMBLY__
7494
7495 struct page;
7496diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7497index 0032f92..cd151e0 100644
7498--- a/arch/um/include/asm/pgtable-3level.h
7499+++ b/arch/um/include/asm/pgtable-3level.h
7500@@ -58,6 +58,7 @@
7501 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7502 #define pud_populate(mm, pud, pmd) \
7503 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7504+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7505
7506 #ifdef CONFIG_64BIT
7507 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7508diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7509index ccb9a9d..cc425bb 100644
7510--- a/arch/um/kernel/process.c
7511+++ b/arch/um/kernel/process.c
7512@@ -407,22 +407,6 @@ int singlestepping(void * t)
7513 return 2;
7514 }
7515
7516-/*
7517- * Only x86 and x86_64 have an arch_align_stack().
7518- * All other arches have "#define arch_align_stack(x) (x)"
7519- * in their asm/system.h
7520- * As this is included in UML from asm-um/system-generic.h,
7521- * we can use it to behave as the subarch does.
7522- */
7523-#ifndef arch_align_stack
7524-unsigned long arch_align_stack(unsigned long sp)
7525-{
7526- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7527- sp -= get_random_int() % 8192;
7528- return sp & ~0xf;
7529-}
7530-#endif
7531-
7532 unsigned long get_wchan(struct task_struct *p)
7533 {
7534 unsigned long stack_page, sp, ip;
7535diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7536index ad8f795..2c7eec6 100644
7537--- a/arch/unicore32/include/asm/cache.h
7538+++ b/arch/unicore32/include/asm/cache.h
7539@@ -12,8 +12,10 @@
7540 #ifndef __UNICORE_CACHE_H__
7541 #define __UNICORE_CACHE_H__
7542
7543-#define L1_CACHE_SHIFT (5)
7544-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7545+#include <linux/const.h>
7546+
7547+#define L1_CACHE_SHIFT 5
7548+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7549
7550 /*
7551 * Memory returned by kmalloc() may be used for DMA, so we must make
7552diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7553index c70684f..698fa4b 100644
7554--- a/arch/x86/Kconfig
7555+++ b/arch/x86/Kconfig
7556@@ -218,7 +218,7 @@ config X86_HT
7557
7558 config X86_32_LAZY_GS
7559 def_bool y
7560- depends on X86_32 && !CC_STACKPROTECTOR
7561+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7562
7563 config ARCH_HWEIGHT_CFLAGS
7564 string
7565@@ -1047,7 +1047,7 @@ choice
7566
7567 config NOHIGHMEM
7568 bool "off"
7569- depends on !X86_NUMAQ
7570+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7571 ---help---
7572 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7573 However, the address space of 32-bit x86 processors is only 4
7574@@ -1084,7 +1084,7 @@ config NOHIGHMEM
7575
7576 config HIGHMEM4G
7577 bool "4GB"
7578- depends on !X86_NUMAQ
7579+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7580 ---help---
7581 Select this if you have a 32-bit processor and between 1 and 4
7582 gigabytes of physical RAM.
7583@@ -1138,7 +1138,7 @@ config PAGE_OFFSET
7584 hex
7585 default 0xB0000000 if VMSPLIT_3G_OPT
7586 default 0x80000000 if VMSPLIT_2G
7587- default 0x78000000 if VMSPLIT_2G_OPT
7588+ default 0x70000000 if VMSPLIT_2G_OPT
7589 default 0x40000000 if VMSPLIT_1G
7590 default 0xC0000000
7591 depends on X86_32
7592@@ -1526,6 +1526,7 @@ config SECCOMP
7593
7594 config CC_STACKPROTECTOR
7595 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
7596+ depends on X86_64 || !PAX_MEMORY_UDEREF
7597 ---help---
7598 This option turns on the -fstack-protector GCC feature. This
7599 feature puts, at the beginning of functions, a canary value on
7600@@ -1583,6 +1584,7 @@ config KEXEC_JUMP
7601 config PHYSICAL_START
7602 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7603 default "0x1000000"
7604+ range 0x400000 0x40000000
7605 ---help---
7606 This gives the physical address where the kernel is loaded.
7607
7608@@ -1646,6 +1648,7 @@ config X86_NEED_RELOCS
7609 config PHYSICAL_ALIGN
7610 hex "Alignment value to which kernel should be aligned" if X86_32
7611 default "0x1000000"
7612+ range 0x400000 0x1000000 if PAX_KERNEXEC
7613 range 0x2000 0x1000000
7614 ---help---
7615 This value puts the alignment restrictions on physical address
7616@@ -1677,9 +1680,10 @@ config HOTPLUG_CPU
7617 Say N if you want to disable CPU hotplug.
7618
7619 config COMPAT_VDSO
7620- def_bool y
7621+ def_bool n
7622 prompt "Compat VDSO support"
7623 depends on X86_32 || IA32_EMULATION
7624+ depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7625 ---help---
7626 Map the 32-bit VDSO to the predictable old-style address too.
7627
7628diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7629index 706e12e..62e4feb 100644
7630--- a/arch/x86/Kconfig.cpu
7631+++ b/arch/x86/Kconfig.cpu
7632@@ -334,7 +334,7 @@ config X86_PPRO_FENCE
7633
7634 config X86_F00F_BUG
7635 def_bool y
7636- depends on M586MMX || M586TSC || M586 || M486 || M386
7637+ depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7638
7639 config X86_INVD_BUG
7640 def_bool y
7641@@ -358,7 +358,7 @@ config X86_POPAD_OK
7642
7643 config X86_ALIGNMENT_16
7644 def_bool y
7645- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7646+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7647
7648 config X86_INTEL_USERCOPY
7649 def_bool y
7650@@ -404,7 +404,7 @@ config X86_CMPXCHG64
7651 # generates cmov.
7652 config X86_CMOV
7653 def_bool y
7654- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7655+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7656
7657 config X86_MINIMUM_CPU_FAMILY
7658 int
7659diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7660index e46c214..ab62fd1 100644
7661--- a/arch/x86/Kconfig.debug
7662+++ b/arch/x86/Kconfig.debug
7663@@ -84,7 +84,7 @@ config X86_PTDUMP
7664 config DEBUG_RODATA
7665 bool "Write protect kernel read-only data structures"
7666 default y
7667- depends on DEBUG_KERNEL
7668+ depends on DEBUG_KERNEL && BROKEN
7669 ---help---
7670 Mark the kernel read-only data as write-protected in the pagetables,
7671 in order to catch accidental (and incorrect) writes to such const
7672@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7673
7674 config DEBUG_SET_MODULE_RONX
7675 bool "Set loadable kernel module data as NX and text as RO"
7676- depends on MODULES
7677+ depends on MODULES && BROKEN
7678 ---help---
7679 This option helps catch unintended modifications to loadable
7680 kernel module's text and read-only data. It also prevents execution
7681@@ -275,7 +275,7 @@ config OPTIMIZE_INLINING
7682
7683 config DEBUG_STRICT_USER_COPY_CHECKS
7684 bool "Strict copy size checks"
7685- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
7686+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
7687 ---help---
7688 Enabling this option turns a certain set of sanity checks for user
7689 copy operations into compile time failures.
7690diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7691index 1f25214..39422b3 100644
7692--- a/arch/x86/Makefile
7693+++ b/arch/x86/Makefile
7694@@ -46,6 +46,7 @@ else
7695 UTS_MACHINE := x86_64
7696 CHECKFLAGS += -D__x86_64__ -m64
7697
7698+ biarch := $(call cc-option,-m64)
7699 KBUILD_AFLAGS += -m64
7700 KBUILD_CFLAGS += -m64
7701
7702@@ -222,3 +223,12 @@ define archhelp
7703 echo ' FDARGS="..." arguments for the booted kernel'
7704 echo ' FDINITRD=file initrd for the booted kernel'
7705 endef
7706+
7707+define OLD_LD
7708+
7709+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7710+*** Please upgrade your binutils to 2.18 or newer
7711+endef
7712+
7713+archprepare:
7714+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7715diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7716index 5a747dd..ff7b12c 100644
7717--- a/arch/x86/boot/Makefile
7718+++ b/arch/x86/boot/Makefile
7719@@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7720 $(call cc-option, -fno-stack-protector) \
7721 $(call cc-option, -mpreferred-stack-boundary=2)
7722 KBUILD_CFLAGS += $(call cc-option, -m32)
7723+ifdef CONSTIFY_PLUGIN
7724+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7725+endif
7726 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7727 GCOV_PROFILE := n
7728
7729diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7730index 878e4b9..20537ab 100644
7731--- a/arch/x86/boot/bitops.h
7732+++ b/arch/x86/boot/bitops.h
7733@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7734 u8 v;
7735 const u32 *p = (const u32 *)addr;
7736
7737- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7738+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7739 return v;
7740 }
7741
7742@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7743
7744 static inline void set_bit(int nr, void *addr)
7745 {
7746- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7747+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7748 }
7749
7750 #endif /* BOOT_BITOPS_H */
7751diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7752index 18997e5..83d9c67 100644
7753--- a/arch/x86/boot/boot.h
7754+++ b/arch/x86/boot/boot.h
7755@@ -85,7 +85,7 @@ static inline void io_delay(void)
7756 static inline u16 ds(void)
7757 {
7758 u16 seg;
7759- asm("movw %%ds,%0" : "=rm" (seg));
7760+ asm volatile("movw %%ds,%0" : "=rm" (seg));
7761 return seg;
7762 }
7763
7764@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7765 static inline int memcmp(const void *s1, const void *s2, size_t len)
7766 {
7767 u8 diff;
7768- asm("repe; cmpsb; setnz %0"
7769+ asm volatile("repe; cmpsb; setnz %0"
7770 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7771 return diff;
7772 }
7773diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7774index e398bb5..3a382ca 100644
7775--- a/arch/x86/boot/compressed/Makefile
7776+++ b/arch/x86/boot/compressed/Makefile
7777@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7778 KBUILD_CFLAGS += $(cflags-y)
7779 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7780 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7781+ifdef CONSTIFY_PLUGIN
7782+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7783+endif
7784
7785 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7786 GCOV_PROFILE := n
7787diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7788index 4e85f5f..39fa641 100644
7789--- a/arch/x86/boot/compressed/eboot.c
7790+++ b/arch/x86/boot/compressed/eboot.c
7791@@ -142,7 +142,6 @@ again:
7792 *addr = max_addr;
7793 }
7794
7795-free_pool:
7796 efi_call_phys1(sys_table->boottime->free_pool, map);
7797
7798 fail:
7799@@ -206,7 +205,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7800 if (i == map_size / desc_size)
7801 status = EFI_NOT_FOUND;
7802
7803-free_pool:
7804 efi_call_phys1(sys_table->boottime->free_pool, map);
7805 fail:
7806 return status;
7807diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7808index c85e3ac..6f5aa80 100644
7809--- a/arch/x86/boot/compressed/head_32.S
7810+++ b/arch/x86/boot/compressed/head_32.S
7811@@ -106,7 +106,7 @@ preferred_addr:
7812 notl %eax
7813 andl %eax, %ebx
7814 #else
7815- movl $LOAD_PHYSICAL_ADDR, %ebx
7816+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7817 #endif
7818
7819 /* Target address to relocate to for decompression */
7820@@ -192,7 +192,7 @@ relocated:
7821 * and where it was actually loaded.
7822 */
7823 movl %ebp, %ebx
7824- subl $LOAD_PHYSICAL_ADDR, %ebx
7825+ subl $____LOAD_PHYSICAL_ADDR, %ebx
7826 jz 2f /* Nothing to be done if loaded at compiled addr. */
7827 /*
7828 * Process relocations.
7829@@ -200,8 +200,7 @@ relocated:
7830
7831 1: subl $4, %edi
7832 movl (%edi), %ecx
7833- testl %ecx, %ecx
7834- jz 2f
7835+ jecxz 2f
7836 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7837 jmp 1b
7838 2:
7839diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7840index 87e03a1..0d94c76 100644
7841--- a/arch/x86/boot/compressed/head_64.S
7842+++ b/arch/x86/boot/compressed/head_64.S
7843@@ -91,7 +91,7 @@ ENTRY(startup_32)
7844 notl %eax
7845 andl %eax, %ebx
7846 #else
7847- movl $LOAD_PHYSICAL_ADDR, %ebx
7848+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7849 #endif
7850
7851 /* Target address to relocate to for decompression */
7852@@ -263,7 +263,7 @@ preferred_addr:
7853 notq %rax
7854 andq %rax, %rbp
7855 #else
7856- movq $LOAD_PHYSICAL_ADDR, %rbp
7857+ movq $____LOAD_PHYSICAL_ADDR, %rbp
7858 #endif
7859
7860 /* Target address to relocate to for decompression */
7861diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7862index 7116dcb..d9ae1d7 100644
7863--- a/arch/x86/boot/compressed/misc.c
7864+++ b/arch/x86/boot/compressed/misc.c
7865@@ -310,7 +310,7 @@ static void parse_elf(void *output)
7866 case PT_LOAD:
7867 #ifdef CONFIG_RELOCATABLE
7868 dest = output;
7869- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7870+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7871 #else
7872 dest = (void *)(phdr->p_paddr);
7873 #endif
7874@@ -365,7 +365,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7875 error("Destination address too large");
7876 #endif
7877 #ifndef CONFIG_RELOCATABLE
7878- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7879+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7880 error("Wrong destination address");
7881 #endif
7882
7883diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7884index 4d3ff03..e4972ff 100644
7885--- a/arch/x86/boot/cpucheck.c
7886+++ b/arch/x86/boot/cpucheck.c
7887@@ -74,7 +74,7 @@ static int has_fpu(void)
7888 u16 fcw = -1, fsw = -1;
7889 u32 cr0;
7890
7891- asm("movl %%cr0,%0" : "=r" (cr0));
7892+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
7893 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7894 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7895 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7896@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7897 {
7898 u32 f0, f1;
7899
7900- asm("pushfl ; "
7901+ asm volatile("pushfl ; "
7902 "pushfl ; "
7903 "popl %0 ; "
7904 "movl %0,%1 ; "
7905@@ -115,7 +115,7 @@ static void get_flags(void)
7906 set_bit(X86_FEATURE_FPU, cpu.flags);
7907
7908 if (has_eflag(X86_EFLAGS_ID)) {
7909- asm("cpuid"
7910+ asm volatile("cpuid"
7911 : "=a" (max_intel_level),
7912 "=b" (cpu_vendor[0]),
7913 "=d" (cpu_vendor[1]),
7914@@ -124,7 +124,7 @@ static void get_flags(void)
7915
7916 if (max_intel_level >= 0x00000001 &&
7917 max_intel_level <= 0x0000ffff) {
7918- asm("cpuid"
7919+ asm volatile("cpuid"
7920 : "=a" (tfms),
7921 "=c" (cpu.flags[4]),
7922 "=d" (cpu.flags[0])
7923@@ -136,7 +136,7 @@ static void get_flags(void)
7924 cpu.model += ((tfms >> 16) & 0xf) << 4;
7925 }
7926
7927- asm("cpuid"
7928+ asm volatile("cpuid"
7929 : "=a" (max_amd_level)
7930 : "a" (0x80000000)
7931 : "ebx", "ecx", "edx");
7932@@ -144,7 +144,7 @@ static void get_flags(void)
7933 if (max_amd_level >= 0x80000001 &&
7934 max_amd_level <= 0x8000ffff) {
7935 u32 eax = 0x80000001;
7936- asm("cpuid"
7937+ asm volatile("cpuid"
7938 : "+a" (eax),
7939 "=c" (cpu.flags[6]),
7940 "=d" (cpu.flags[1])
7941@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7942 u32 ecx = MSR_K7_HWCR;
7943 u32 eax, edx;
7944
7945- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7946+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7947 eax &= ~(1 << 15);
7948- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7949+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7950
7951 get_flags(); /* Make sure it really did something */
7952 err = check_flags();
7953@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7954 u32 ecx = MSR_VIA_FCR;
7955 u32 eax, edx;
7956
7957- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7958+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7959 eax |= (1<<1)|(1<<7);
7960- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7961+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7962
7963 set_bit(X86_FEATURE_CX8, cpu.flags);
7964 err = check_flags();
7965@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7966 u32 eax, edx;
7967 u32 level = 1;
7968
7969- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7970- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7971- asm("cpuid"
7972+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7973+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7974+ asm volatile("cpuid"
7975 : "+a" (level), "=d" (cpu.flags[0])
7976 : : "ecx", "ebx");
7977- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7978+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7979
7980 err = check_flags();
7981 }
7982diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
7983index efe5acf..22a3784 100644
7984--- a/arch/x86/boot/header.S
7985+++ b/arch/x86/boot/header.S
7986@@ -391,10 +391,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
7987 # single linked list of
7988 # struct setup_data
7989
7990-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
7991+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
7992
7993 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
7994+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
7995+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
7996+#else
7997 #define VO_INIT_SIZE (VO__end - VO__text)
7998+#endif
7999 #if ZO_INIT_SIZE > VO_INIT_SIZE
8000 #define INIT_SIZE ZO_INIT_SIZE
8001 #else
8002diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
8003index db75d07..8e6d0af 100644
8004--- a/arch/x86/boot/memory.c
8005+++ b/arch/x86/boot/memory.c
8006@@ -19,7 +19,7 @@
8007
8008 static int detect_memory_e820(void)
8009 {
8010- int count = 0;
8011+ unsigned int count = 0;
8012 struct biosregs ireg, oreg;
8013 struct e820entry *desc = boot_params.e820_map;
8014 static struct e820entry buf; /* static so it is zeroed */
8015diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
8016index 11e8c6e..fdbb1ed 100644
8017--- a/arch/x86/boot/video-vesa.c
8018+++ b/arch/x86/boot/video-vesa.c
8019@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
8020
8021 boot_params.screen_info.vesapm_seg = oreg.es;
8022 boot_params.screen_info.vesapm_off = oreg.di;
8023+ boot_params.screen_info.vesapm_size = oreg.cx;
8024 }
8025
8026 /*
8027diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
8028index 43eda28..5ab5fdb 100644
8029--- a/arch/x86/boot/video.c
8030+++ b/arch/x86/boot/video.c
8031@@ -96,7 +96,7 @@ static void store_mode_params(void)
8032 static unsigned int get_entry(void)
8033 {
8034 char entry_buf[4];
8035- int i, len = 0;
8036+ unsigned int i, len = 0;
8037 int key;
8038 unsigned int v;
8039
8040diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8041index 5b577d5..3c1fed4 100644
8042--- a/arch/x86/crypto/aes-x86_64-asm_64.S
8043+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8044@@ -8,6 +8,8 @@
8045 * including this sentence is retained in full.
8046 */
8047
8048+#include <asm/alternative-asm.h>
8049+
8050 .extern crypto_ft_tab
8051 .extern crypto_it_tab
8052 .extern crypto_fl_tab
8053@@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8054 je B192; \
8055 leaq 32(r9),r9;
8056
8057+#define ret pax_force_retaddr 0, 1; ret
8058+
8059 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8060 movq r1,r2; \
8061 movq r3,r4; \
8062diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8063index 3470624..201259d 100644
8064--- a/arch/x86/crypto/aesni-intel_asm.S
8065+++ b/arch/x86/crypto/aesni-intel_asm.S
8066@@ -31,6 +31,7 @@
8067
8068 #include <linux/linkage.h>
8069 #include <asm/inst.h>
8070+#include <asm/alternative-asm.h>
8071
8072 #ifdef __x86_64__
8073 .data
8074@@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8075 pop %r14
8076 pop %r13
8077 pop %r12
8078+ pax_force_retaddr 0, 1
8079 ret
8080+ENDPROC(aesni_gcm_dec)
8081
8082
8083 /*****************************************************************************
8084@@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8085 pop %r14
8086 pop %r13
8087 pop %r12
8088+ pax_force_retaddr 0, 1
8089 ret
8090+ENDPROC(aesni_gcm_enc)
8091
8092 #endif
8093
8094@@ -1714,6 +1719,7 @@ _key_expansion_256a:
8095 pxor %xmm1, %xmm0
8096 movaps %xmm0, (TKEYP)
8097 add $0x10, TKEYP
8098+ pax_force_retaddr_bts
8099 ret
8100
8101 .align 4
8102@@ -1738,6 +1744,7 @@ _key_expansion_192a:
8103 shufps $0b01001110, %xmm2, %xmm1
8104 movaps %xmm1, 0x10(TKEYP)
8105 add $0x20, TKEYP
8106+ pax_force_retaddr_bts
8107 ret
8108
8109 .align 4
8110@@ -1757,6 +1764,7 @@ _key_expansion_192b:
8111
8112 movaps %xmm0, (TKEYP)
8113 add $0x10, TKEYP
8114+ pax_force_retaddr_bts
8115 ret
8116
8117 .align 4
8118@@ -1769,6 +1777,7 @@ _key_expansion_256b:
8119 pxor %xmm1, %xmm2
8120 movaps %xmm2, (TKEYP)
8121 add $0x10, TKEYP
8122+ pax_force_retaddr_bts
8123 ret
8124
8125 /*
8126@@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8127 #ifndef __x86_64__
8128 popl KEYP
8129 #endif
8130+ pax_force_retaddr 0, 1
8131 ret
8132+ENDPROC(aesni_set_key)
8133
8134 /*
8135 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8136@@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8137 popl KLEN
8138 popl KEYP
8139 #endif
8140+ pax_force_retaddr 0, 1
8141 ret
8142+ENDPROC(aesni_enc)
8143
8144 /*
8145 * _aesni_enc1: internal ABI
8146@@ -1959,6 +1972,7 @@ _aesni_enc1:
8147 AESENC KEY STATE
8148 movaps 0x70(TKEYP), KEY
8149 AESENCLAST KEY STATE
8150+ pax_force_retaddr_bts
8151 ret
8152
8153 /*
8154@@ -2067,6 +2081,7 @@ _aesni_enc4:
8155 AESENCLAST KEY STATE2
8156 AESENCLAST KEY STATE3
8157 AESENCLAST KEY STATE4
8158+ pax_force_retaddr_bts
8159 ret
8160
8161 /*
8162@@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8163 popl KLEN
8164 popl KEYP
8165 #endif
8166+ pax_force_retaddr 0, 1
8167 ret
8168+ENDPROC(aesni_dec)
8169
8170 /*
8171 * _aesni_dec1: internal ABI
8172@@ -2146,6 +2163,7 @@ _aesni_dec1:
8173 AESDEC KEY STATE
8174 movaps 0x70(TKEYP), KEY
8175 AESDECLAST KEY STATE
8176+ pax_force_retaddr_bts
8177 ret
8178
8179 /*
8180@@ -2254,6 +2272,7 @@ _aesni_dec4:
8181 AESDECLAST KEY STATE2
8182 AESDECLAST KEY STATE3
8183 AESDECLAST KEY STATE4
8184+ pax_force_retaddr_bts
8185 ret
8186
8187 /*
8188@@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8189 popl KEYP
8190 popl LEN
8191 #endif
8192+ pax_force_retaddr 0, 1
8193 ret
8194+ENDPROC(aesni_ecb_enc)
8195
8196 /*
8197 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8198@@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8199 popl KEYP
8200 popl LEN
8201 #endif
8202+ pax_force_retaddr 0, 1
8203 ret
8204+ENDPROC(aesni_ecb_dec)
8205
8206 /*
8207 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8208@@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8209 popl LEN
8210 popl IVP
8211 #endif
8212+ pax_force_retaddr 0, 1
8213 ret
8214+ENDPROC(aesni_cbc_enc)
8215
8216 /*
8217 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8218@@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
8219 popl LEN
8220 popl IVP
8221 #endif
8222+ pax_force_retaddr 0, 1
8223 ret
8224+ENDPROC(aesni_cbc_dec)
8225
8226 #ifdef __x86_64__
8227 .align 16
8228@@ -2526,6 +2553,7 @@ _aesni_inc_init:
8229 mov $1, TCTR_LOW
8230 MOVQ_R64_XMM TCTR_LOW INC
8231 MOVQ_R64_XMM CTR TCTR_LOW
8232+ pax_force_retaddr_bts
8233 ret
8234
8235 /*
8236@@ -2554,6 +2582,7 @@ _aesni_inc:
8237 .Linc_low:
8238 movaps CTR, IV
8239 PSHUFB_XMM BSWAP_MASK IV
8240+ pax_force_retaddr_bts
8241 ret
8242
8243 /*
8244@@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
8245 .Lctr_enc_ret:
8246 movups IV, (IVP)
8247 .Lctr_enc_just_ret:
8248+ pax_force_retaddr 0, 1
8249 ret
8250+ENDPROC(aesni_ctr_enc)
8251 #endif
8252diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8253index 391d245..67f35c2 100644
8254--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8255+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8256@@ -20,6 +20,8 @@
8257 *
8258 */
8259
8260+#include <asm/alternative-asm.h>
8261+
8262 .file "blowfish-x86_64-asm.S"
8263 .text
8264
8265@@ -151,9 +153,11 @@ __blowfish_enc_blk:
8266 jnz __enc_xor;
8267
8268 write_block();
8269+ pax_force_retaddr 0, 1
8270 ret;
8271 __enc_xor:
8272 xor_block();
8273+ pax_force_retaddr 0, 1
8274 ret;
8275
8276 .align 8
8277@@ -188,6 +192,7 @@ blowfish_dec_blk:
8278
8279 movq %r11, %rbp;
8280
8281+ pax_force_retaddr 0, 1
8282 ret;
8283
8284 /**********************************************************************
8285@@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8286
8287 popq %rbx;
8288 popq %rbp;
8289+ pax_force_retaddr 0, 1
8290 ret;
8291
8292 __enc_xor4:
8293@@ -349,6 +355,7 @@ __enc_xor4:
8294
8295 popq %rbx;
8296 popq %rbp;
8297+ pax_force_retaddr 0, 1
8298 ret;
8299
8300 .align 8
8301@@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8302 popq %rbx;
8303 popq %rbp;
8304
8305+ pax_force_retaddr 0, 1
8306 ret;
8307
8308diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
8309index 0b33743..7a56206 100644
8310--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
8311+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
8312@@ -20,6 +20,8 @@
8313 *
8314 */
8315
8316+#include <asm/alternative-asm.h>
8317+
8318 .file "camellia-x86_64-asm_64.S"
8319 .text
8320
8321@@ -229,12 +231,14 @@ __enc_done:
8322 enc_outunpack(mov, RT1);
8323
8324 movq RRBP, %rbp;
8325+ pax_force_retaddr 0, 1
8326 ret;
8327
8328 __enc_xor:
8329 enc_outunpack(xor, RT1);
8330
8331 movq RRBP, %rbp;
8332+ pax_force_retaddr 0, 1
8333 ret;
8334
8335 .global camellia_dec_blk;
8336@@ -275,6 +279,7 @@ __dec_rounds16:
8337 dec_outunpack();
8338
8339 movq RRBP, %rbp;
8340+ pax_force_retaddr 0, 1
8341 ret;
8342
8343 /**********************************************************************
8344@@ -468,6 +473,7 @@ __enc2_done:
8345
8346 movq RRBP, %rbp;
8347 popq %rbx;
8348+ pax_force_retaddr 0, 1
8349 ret;
8350
8351 __enc2_xor:
8352@@ -475,6 +481,7 @@ __enc2_xor:
8353
8354 movq RRBP, %rbp;
8355 popq %rbx;
8356+ pax_force_retaddr 0, 1
8357 ret;
8358
8359 .global camellia_dec_blk_2way;
8360@@ -517,4 +524,5 @@ __dec2_rounds16:
8361
8362 movq RRBP, %rbp;
8363 movq RXOR, %rbx;
8364+ pax_force_retaddr 0, 1
8365 ret;
8366diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8367index 6214a9b..1f4fc9a 100644
8368--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8369+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8370@@ -1,3 +1,5 @@
8371+#include <asm/alternative-asm.h>
8372+
8373 # enter ECRYPT_encrypt_bytes
8374 .text
8375 .p2align 5
8376@@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8377 add %r11,%rsp
8378 mov %rdi,%rax
8379 mov %rsi,%rdx
8380+ pax_force_retaddr 0, 1
8381 ret
8382 # bytesatleast65:
8383 ._bytesatleast65:
8384@@ -891,6 +894,7 @@ ECRYPT_keysetup:
8385 add %r11,%rsp
8386 mov %rdi,%rax
8387 mov %rsi,%rdx
8388+ pax_force_retaddr
8389 ret
8390 # enter ECRYPT_ivsetup
8391 .text
8392@@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8393 add %r11,%rsp
8394 mov %rdi,%rax
8395 mov %rsi,%rdx
8396+ pax_force_retaddr
8397 ret
8398diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8399index 3ee1ff0..cbc568b 100644
8400--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8401+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8402@@ -24,6 +24,8 @@
8403 *
8404 */
8405
8406+#include <asm/alternative-asm.h>
8407+
8408 .file "serpent-sse2-x86_64-asm_64.S"
8409 .text
8410
8411@@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
8412 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8413 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8414
8415+ pax_force_retaddr
8416 ret;
8417
8418 __enc_xor8:
8419 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8420 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8421
8422+ pax_force_retaddr
8423 ret;
8424
8425 .align 8
8426@@ -755,4 +759,5 @@ serpent_dec_blk_8way:
8427 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8428 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8429
8430+ pax_force_retaddr
8431 ret;
8432diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8433index b2c2f57..8470cab 100644
8434--- a/arch/x86/crypto/sha1_ssse3_asm.S
8435+++ b/arch/x86/crypto/sha1_ssse3_asm.S
8436@@ -28,6 +28,8 @@
8437 * (at your option) any later version.
8438 */
8439
8440+#include <asm/alternative-asm.h>
8441+
8442 #define CTX %rdi // arg1
8443 #define BUF %rsi // arg2
8444 #define CNT %rdx // arg3
8445@@ -104,6 +106,7 @@
8446 pop %r12
8447 pop %rbp
8448 pop %rbx
8449+ pax_force_retaddr 0, 1
8450 ret
8451
8452 .size \name, .-\name
8453diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8454index 5b012a2..36d5364 100644
8455--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8456+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8457@@ -20,6 +20,8 @@
8458 *
8459 */
8460
8461+#include <asm/alternative-asm.h>
8462+
8463 .file "twofish-x86_64-asm-3way.S"
8464 .text
8465
8466@@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8467 popq %r13;
8468 popq %r14;
8469 popq %r15;
8470+ pax_force_retaddr 0, 1
8471 ret;
8472
8473 __enc_xor3:
8474@@ -271,6 +274,7 @@ __enc_xor3:
8475 popq %r13;
8476 popq %r14;
8477 popq %r15;
8478+ pax_force_retaddr 0, 1
8479 ret;
8480
8481 .global twofish_dec_blk_3way
8482@@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8483 popq %r13;
8484 popq %r14;
8485 popq %r15;
8486+ pax_force_retaddr 0, 1
8487 ret;
8488
8489diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8490index 7bcf3fc..f53832f 100644
8491--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8492+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8493@@ -21,6 +21,7 @@
8494 .text
8495
8496 #include <asm/asm-offsets.h>
8497+#include <asm/alternative-asm.h>
8498
8499 #define a_offset 0
8500 #define b_offset 4
8501@@ -268,6 +269,7 @@ twofish_enc_blk:
8502
8503 popq R1
8504 movq $1,%rax
8505+ pax_force_retaddr 0, 1
8506 ret
8507
8508 twofish_dec_blk:
8509@@ -319,4 +321,5 @@ twofish_dec_blk:
8510
8511 popq R1
8512 movq $1,%rax
8513+ pax_force_retaddr 0, 1
8514 ret
8515diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8516index 07b3a68..bd2a388 100644
8517--- a/arch/x86/ia32/ia32_aout.c
8518+++ b/arch/x86/ia32/ia32_aout.c
8519@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8520 unsigned long dump_start, dump_size;
8521 struct user32 dump;
8522
8523+ memset(&dump, 0, sizeof(dump));
8524+
8525 fs = get_fs();
8526 set_fs(KERNEL_DS);
8527 has_dumped = 1;
8528diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8529index 673ac9b..7a8c5df 100644
8530--- a/arch/x86/ia32/ia32_signal.c
8531+++ b/arch/x86/ia32/ia32_signal.c
8532@@ -162,7 +162,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8533 }
8534 seg = get_fs();
8535 set_fs(KERNEL_DS);
8536- ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8537+ ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8538 set_fs(seg);
8539 if (ret >= 0 && uoss_ptr) {
8540 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8541@@ -361,7 +361,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8542 */
8543 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8544 size_t frame_size,
8545- void **fpstate)
8546+ void __user **fpstate)
8547 {
8548 unsigned long sp;
8549
8550@@ -382,7 +382,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8551
8552 if (used_math()) {
8553 sp = sp - sig_xstate_ia32_size;
8554- *fpstate = (struct _fpstate_ia32 *) sp;
8555+ *fpstate = (struct _fpstate_ia32 __user *) sp;
8556 if (save_i387_xstate_ia32(*fpstate) < 0)
8557 return (void __user *) -1L;
8558 }
8559@@ -390,7 +390,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8560 sp -= frame_size;
8561 /* Align the stack pointer according to the i386 ABI,
8562 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8563- sp = ((sp + 4) & -16ul) - 4;
8564+ sp = ((sp - 12) & -16ul) - 4;
8565 return (void __user *) sp;
8566 }
8567
8568@@ -448,7 +448,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8569 * These are actually not used anymore, but left because some
8570 * gdb versions depend on them as a marker.
8571 */
8572- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8573+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8574 } put_user_catch(err);
8575
8576 if (err)
8577@@ -490,7 +490,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8578 0xb8,
8579 __NR_ia32_rt_sigreturn,
8580 0x80cd,
8581- 0,
8582+ 0
8583 };
8584
8585 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8586@@ -520,16 +520,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8587
8588 if (ka->sa.sa_flags & SA_RESTORER)
8589 restorer = ka->sa.sa_restorer;
8590+ else if (current->mm->context.vdso)
8591+ /* Return stub is in 32bit vsyscall page */
8592+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8593 else
8594- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8595- rt_sigreturn);
8596+ restorer = &frame->retcode;
8597 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8598
8599 /*
8600 * Not actually used anymore, but left because some gdb
8601 * versions need it.
8602 */
8603- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8604+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8605 } put_user_catch(err);
8606
8607 if (err)
8608diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8609index 20e5f7b..eab8751 100644
8610--- a/arch/x86/ia32/ia32entry.S
8611+++ b/arch/x86/ia32/ia32entry.S
8612@@ -14,8 +14,10 @@
8613 #include <asm/segment.h>
8614 #include <asm/irqflags.h>
8615 #include <asm/asm.h>
8616+#include <asm/pgtable.h>
8617 #include <linux/linkage.h>
8618 #include <linux/err.h>
8619+#include <asm/alternative-asm.h>
8620
8621 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8622 #include <linux/elf-em.h>
8623@@ -95,6 +97,32 @@ ENTRY(native_irq_enable_sysexit)
8624 ENDPROC(native_irq_enable_sysexit)
8625 #endif
8626
8627+ .macro pax_enter_kernel_user
8628+ pax_set_fptr_mask
8629+#ifdef CONFIG_PAX_MEMORY_UDEREF
8630+ call pax_enter_kernel_user
8631+#endif
8632+ .endm
8633+
8634+ .macro pax_exit_kernel_user
8635+#ifdef CONFIG_PAX_MEMORY_UDEREF
8636+ call pax_exit_kernel_user
8637+#endif
8638+#ifdef CONFIG_PAX_RANDKSTACK
8639+ pushq %rax
8640+ pushq %r11
8641+ call pax_randomize_kstack
8642+ popq %r11
8643+ popq %rax
8644+#endif
8645+ .endm
8646+
8647+.macro pax_erase_kstack
8648+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8649+ call pax_erase_kstack
8650+#endif
8651+.endm
8652+
8653 /*
8654 * 32bit SYSENTER instruction entry.
8655 *
8656@@ -121,12 +149,6 @@ ENTRY(ia32_sysenter_target)
8657 CFI_REGISTER rsp,rbp
8658 SWAPGS_UNSAFE_STACK
8659 movq PER_CPU_VAR(kernel_stack), %rsp
8660- addq $(KERNEL_STACK_OFFSET),%rsp
8661- /*
8662- * No need to follow this irqs on/off section: the syscall
8663- * disabled irqs, here we enable it straight after entry:
8664- */
8665- ENABLE_INTERRUPTS(CLBR_NONE)
8666 movl %ebp,%ebp /* zero extension */
8667 pushq_cfi $__USER32_DS
8668 /*CFI_REL_OFFSET ss,0*/
8669@@ -134,22 +156,37 @@ ENTRY(ia32_sysenter_target)
8670 CFI_REL_OFFSET rsp,0
8671 pushfq_cfi
8672 /*CFI_REL_OFFSET rflags,0*/
8673- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8674- CFI_REGISTER rip,r10
8675+ orl $X86_EFLAGS_IF,(%rsp)
8676+ GET_THREAD_INFO(%r11)
8677+ movl TI_sysenter_return(%r11), %r11d
8678+ CFI_REGISTER rip,r11
8679 pushq_cfi $__USER32_CS
8680 /*CFI_REL_OFFSET cs,0*/
8681 movl %eax, %eax
8682- pushq_cfi %r10
8683+ pushq_cfi %r11
8684 CFI_REL_OFFSET rip,0
8685 pushq_cfi %rax
8686 cld
8687 SAVE_ARGS 0,1,0
8688+ pax_enter_kernel_user
8689+ /*
8690+ * No need to follow this irqs on/off section: the syscall
8691+ * disabled irqs, here we enable it straight after entry:
8692+ */
8693+ ENABLE_INTERRUPTS(CLBR_NONE)
8694 /* no need to do an access_ok check here because rbp has been
8695 32bit zero extended */
8696+
8697+#ifdef CONFIG_PAX_MEMORY_UDEREF
8698+ mov $PAX_USER_SHADOW_BASE,%r11
8699+ add %r11,%rbp
8700+#endif
8701+
8702 1: movl (%rbp),%ebp
8703 _ASM_EXTABLE(1b,ia32_badarg)
8704- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8705- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8706+ GET_THREAD_INFO(%r11)
8707+ orl $TS_COMPAT,TI_status(%r11)
8708+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8709 CFI_REMEMBER_STATE
8710 jnz sysenter_tracesys
8711 cmpq $(IA32_NR_syscalls-1),%rax
8712@@ -159,12 +196,15 @@ sysenter_do_call:
8713 sysenter_dispatch:
8714 call *ia32_sys_call_table(,%rax,8)
8715 movq %rax,RAX-ARGOFFSET(%rsp)
8716+ GET_THREAD_INFO(%r11)
8717 DISABLE_INTERRUPTS(CLBR_NONE)
8718 TRACE_IRQS_OFF
8719- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8720+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8721 jnz sysexit_audit
8722 sysexit_from_sys_call:
8723- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8724+ pax_exit_kernel_user
8725+ pax_erase_kstack
8726+ andl $~TS_COMPAT,TI_status(%r11)
8727 /* clear IF, that popfq doesn't enable interrupts early */
8728 andl $~0x200,EFLAGS-R11(%rsp)
8729 movl RIP-R11(%rsp),%edx /* User %eip */
8730@@ -190,6 +230,9 @@ sysexit_from_sys_call:
8731 movl %eax,%esi /* 2nd arg: syscall number */
8732 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8733 call __audit_syscall_entry
8734+
8735+ pax_erase_kstack
8736+
8737 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8738 cmpq $(IA32_NR_syscalls-1),%rax
8739 ja ia32_badsys
8740@@ -201,7 +244,7 @@ sysexit_from_sys_call:
8741 .endm
8742
8743 .macro auditsys_exit exit
8744- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8745+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8746 jnz ia32_ret_from_sys_call
8747 TRACE_IRQS_ON
8748 sti
8749@@ -212,11 +255,12 @@ sysexit_from_sys_call:
8750 1: setbe %al /* 1 if error, 0 if not */
8751 movzbl %al,%edi /* zero-extend that into %edi */
8752 call __audit_syscall_exit
8753+ GET_THREAD_INFO(%r11)
8754 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8755 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8756 cli
8757 TRACE_IRQS_OFF
8758- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8759+ testl %edi,TI_flags(%r11)
8760 jz \exit
8761 CLEAR_RREGS -ARGOFFSET
8762 jmp int_with_check
8763@@ -234,7 +278,7 @@ sysexit_audit:
8764
8765 sysenter_tracesys:
8766 #ifdef CONFIG_AUDITSYSCALL
8767- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8768+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8769 jz sysenter_auditsys
8770 #endif
8771 SAVE_REST
8772@@ -242,6 +286,9 @@ sysenter_tracesys:
8773 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
8774 movq %rsp,%rdi /* &pt_regs -> arg1 */
8775 call syscall_trace_enter
8776+
8777+ pax_erase_kstack
8778+
8779 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8780 RESTORE_REST
8781 cmpq $(IA32_NR_syscalls-1),%rax
8782@@ -273,19 +320,20 @@ ENDPROC(ia32_sysenter_target)
8783 ENTRY(ia32_cstar_target)
8784 CFI_STARTPROC32 simple
8785 CFI_SIGNAL_FRAME
8786- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8787+ CFI_DEF_CFA rsp,0
8788 CFI_REGISTER rip,rcx
8789 /*CFI_REGISTER rflags,r11*/
8790 SWAPGS_UNSAFE_STACK
8791 movl %esp,%r8d
8792 CFI_REGISTER rsp,r8
8793 movq PER_CPU_VAR(kernel_stack),%rsp
8794+ SAVE_ARGS 8*6,0,0
8795+ pax_enter_kernel_user
8796 /*
8797 * No need to follow this irqs on/off section: the syscall
8798 * disabled irqs and here we enable it straight after entry:
8799 */
8800 ENABLE_INTERRUPTS(CLBR_NONE)
8801- SAVE_ARGS 8,0,0
8802 movl %eax,%eax /* zero extension */
8803 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8804 movq %rcx,RIP-ARGOFFSET(%rsp)
8805@@ -301,10 +349,17 @@ ENTRY(ia32_cstar_target)
8806 /* no need to do an access_ok check here because r8 has been
8807 32bit zero extended */
8808 /* hardware stack frame is complete now */
8809+
8810+#ifdef CONFIG_PAX_MEMORY_UDEREF
8811+ mov $PAX_USER_SHADOW_BASE,%r11
8812+ add %r11,%r8
8813+#endif
8814+
8815 1: movl (%r8),%r9d
8816 _ASM_EXTABLE(1b,ia32_badarg)
8817- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8818- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8819+ GET_THREAD_INFO(%r11)
8820+ orl $TS_COMPAT,TI_status(%r11)
8821+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8822 CFI_REMEMBER_STATE
8823 jnz cstar_tracesys
8824 cmpq $IA32_NR_syscalls-1,%rax
8825@@ -314,12 +369,15 @@ cstar_do_call:
8826 cstar_dispatch:
8827 call *ia32_sys_call_table(,%rax,8)
8828 movq %rax,RAX-ARGOFFSET(%rsp)
8829+ GET_THREAD_INFO(%r11)
8830 DISABLE_INTERRUPTS(CLBR_NONE)
8831 TRACE_IRQS_OFF
8832- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8833+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8834 jnz sysretl_audit
8835 sysretl_from_sys_call:
8836- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8837+ pax_exit_kernel_user
8838+ pax_erase_kstack
8839+ andl $~TS_COMPAT,TI_status(%r11)
8840 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8841 movl RIP-ARGOFFSET(%rsp),%ecx
8842 CFI_REGISTER rip,rcx
8843@@ -347,7 +405,7 @@ sysretl_audit:
8844
8845 cstar_tracesys:
8846 #ifdef CONFIG_AUDITSYSCALL
8847- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8848+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8849 jz cstar_auditsys
8850 #endif
8851 xchgl %r9d,%ebp
8852@@ -356,6 +414,9 @@ cstar_tracesys:
8853 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8854 movq %rsp,%rdi /* &pt_regs -> arg1 */
8855 call syscall_trace_enter
8856+
8857+ pax_erase_kstack
8858+
8859 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
8860 RESTORE_REST
8861 xchgl %ebp,%r9d
8862@@ -401,19 +462,21 @@ ENTRY(ia32_syscall)
8863 CFI_REL_OFFSET rip,RIP-RIP
8864 PARAVIRT_ADJUST_EXCEPTION_FRAME
8865 SWAPGS
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 movl %eax,%eax
8872 pushq_cfi %rax
8873 cld
8874 /* note the registers are not zero extended to the sf.
8875 this could be a problem. */
8876 SAVE_ARGS 0,1,0
8877- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8878- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8879+ pax_enter_kernel_user
8880+ /*
8881+ * No need to follow this irqs on/off section: the syscall
8882+ * disabled irqs and here we enable it straight after entry:
8883+ */
8884+ ENABLE_INTERRUPTS(CLBR_NONE)
8885+ GET_THREAD_INFO(%r11)
8886+ orl $TS_COMPAT,TI_status(%r11)
8887+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8888 jnz ia32_tracesys
8889 cmpq $(IA32_NR_syscalls-1),%rax
8890 ja ia32_badsys
8891@@ -432,6 +495,9 @@ ia32_tracesys:
8892 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8893 movq %rsp,%rdi /* &pt_regs -> arg1 */
8894 call syscall_trace_enter
8895+
8896+ pax_erase_kstack
8897+
8898 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8899 RESTORE_REST
8900 cmpq $(IA32_NR_syscalls-1),%rax
8901diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8902index 4540bec..714d913 100644
8903--- a/arch/x86/ia32/sys_ia32.c
8904+++ b/arch/x86/ia32/sys_ia32.c
8905@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8906 */
8907 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8908 {
8909- typeof(ubuf->st_uid) uid = 0;
8910- typeof(ubuf->st_gid) gid = 0;
8911+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
8912+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
8913 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
8914 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
8915 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8916@@ -287,7 +287,7 @@ asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 __user *act,
8917 return ret;
8918 }
8919
8920-asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
8921+asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
8922 int options)
8923 {
8924 return compat_sys_wait4(pid, stat_addr, options, NULL);
8925@@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8926 mm_segment_t old_fs = get_fs();
8927
8928 set_fs(KERNEL_DS);
8929- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
8930+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
8931 set_fs(old_fs);
8932 if (put_compat_timespec(&t, interval))
8933 return -EFAULT;
8934@@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
8935 mm_segment_t old_fs = get_fs();
8936
8937 set_fs(KERNEL_DS);
8938- ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
8939+ ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
8940 set_fs(old_fs);
8941 if (!ret) {
8942 switch (_NSIG_WORDS) {
8943@@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
8944 if (copy_siginfo_from_user32(&info, uinfo))
8945 return -EFAULT;
8946 set_fs(KERNEL_DS);
8947- ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
8948+ ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
8949 set_fs(old_fs);
8950 return ret;
8951 }
8952@@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
8953 return -EFAULT;
8954
8955 set_fs(KERNEL_DS);
8956- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
8957+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
8958 count);
8959 set_fs(old_fs);
8960
8961diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
8962index 952bd01..7692c6f 100644
8963--- a/arch/x86/include/asm/alternative-asm.h
8964+++ b/arch/x86/include/asm/alternative-asm.h
8965@@ -15,6 +15,45 @@
8966 .endm
8967 #endif
8968
8969+#ifdef KERNEXEC_PLUGIN
8970+ .macro pax_force_retaddr_bts rip=0
8971+ btsq $63,\rip(%rsp)
8972+ .endm
8973+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
8974+ .macro pax_force_retaddr rip=0, reload=0
8975+ btsq $63,\rip(%rsp)
8976+ .endm
8977+ .macro pax_force_fptr ptr
8978+ btsq $63,\ptr
8979+ .endm
8980+ .macro pax_set_fptr_mask
8981+ .endm
8982+#endif
8983+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
8984+ .macro pax_force_retaddr rip=0, reload=0
8985+ .if \reload
8986+ pax_set_fptr_mask
8987+ .endif
8988+ orq %r10,\rip(%rsp)
8989+ .endm
8990+ .macro pax_force_fptr ptr
8991+ orq %r10,\ptr
8992+ .endm
8993+ .macro pax_set_fptr_mask
8994+ movabs $0x8000000000000000,%r10
8995+ .endm
8996+#endif
8997+#else
8998+ .macro pax_force_retaddr rip=0, reload=0
8999+ .endm
9000+ .macro pax_force_fptr ptr
9001+ .endm
9002+ .macro pax_force_retaddr_bts rip=0
9003+ .endm
9004+ .macro pax_set_fptr_mask
9005+ .endm
9006+#endif
9007+
9008 .macro altinstruction_entry orig alt feature orig_len alt_len
9009 .long \orig - .
9010 .long \alt - .
9011diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9012index 49331be..9706065 100644
9013--- a/arch/x86/include/asm/alternative.h
9014+++ b/arch/x86/include/asm/alternative.h
9015@@ -89,7 +89,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9016 ".section .discard,\"aw\",@progbits\n" \
9017 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
9018 ".previous\n" \
9019- ".section .altinstr_replacement, \"ax\"\n" \
9020+ ".section .altinstr_replacement, \"a\"\n" \
9021 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
9022 ".previous"
9023
9024diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9025index eaff479..3025a63 100644
9026--- a/arch/x86/include/asm/apic.h
9027+++ b/arch/x86/include/asm/apic.h
9028@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9029
9030 #ifdef CONFIG_X86_LOCAL_APIC
9031
9032-extern unsigned int apic_verbosity;
9033+extern int apic_verbosity;
9034 extern int local_apic_timer_c2_ok;
9035
9036 extern int disable_apic;
9037diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9038index 20370c6..a2eb9b0 100644
9039--- a/arch/x86/include/asm/apm.h
9040+++ b/arch/x86/include/asm/apm.h
9041@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9042 __asm__ __volatile__(APM_DO_ZERO_SEGS
9043 "pushl %%edi\n\t"
9044 "pushl %%ebp\n\t"
9045- "lcall *%%cs:apm_bios_entry\n\t"
9046+ "lcall *%%ss:apm_bios_entry\n\t"
9047 "setc %%al\n\t"
9048 "popl %%ebp\n\t"
9049 "popl %%edi\n\t"
9050@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9051 __asm__ __volatile__(APM_DO_ZERO_SEGS
9052 "pushl %%edi\n\t"
9053 "pushl %%ebp\n\t"
9054- "lcall *%%cs:apm_bios_entry\n\t"
9055+ "lcall *%%ss:apm_bios_entry\n\t"
9056 "setc %%bl\n\t"
9057 "popl %%ebp\n\t"
9058 "popl %%edi\n\t"
9059diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9060index 58cb6d4..a4b806c 100644
9061--- a/arch/x86/include/asm/atomic.h
9062+++ b/arch/x86/include/asm/atomic.h
9063@@ -22,7 +22,18 @@
9064 */
9065 static inline int atomic_read(const atomic_t *v)
9066 {
9067- return (*(volatile int *)&(v)->counter);
9068+ return (*(volatile const int *)&(v)->counter);
9069+}
9070+
9071+/**
9072+ * atomic_read_unchecked - read atomic variable
9073+ * @v: pointer of type atomic_unchecked_t
9074+ *
9075+ * Atomically reads the value of @v.
9076+ */
9077+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9078+{
9079+ return (*(volatile const int *)&(v)->counter);
9080 }
9081
9082 /**
9083@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9084 }
9085
9086 /**
9087+ * atomic_set_unchecked - set atomic variable
9088+ * @v: pointer of type atomic_unchecked_t
9089+ * @i: required value
9090+ *
9091+ * Atomically sets the value of @v to @i.
9092+ */
9093+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9094+{
9095+ v->counter = i;
9096+}
9097+
9098+/**
9099 * atomic_add - add integer to atomic variable
9100 * @i: integer value to add
9101 * @v: pointer of type atomic_t
9102@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9103 */
9104 static inline void atomic_add(int i, atomic_t *v)
9105 {
9106- asm volatile(LOCK_PREFIX "addl %1,%0"
9107+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
9108+
9109+#ifdef CONFIG_PAX_REFCOUNT
9110+ "jno 0f\n"
9111+ LOCK_PREFIX "subl %1,%0\n"
9112+ "int $4\n0:\n"
9113+ _ASM_EXTABLE(0b, 0b)
9114+#endif
9115+
9116+ : "+m" (v->counter)
9117+ : "ir" (i));
9118+}
9119+
9120+/**
9121+ * atomic_add_unchecked - add integer to atomic variable
9122+ * @i: integer value to add
9123+ * @v: pointer of type atomic_unchecked_t
9124+ *
9125+ * Atomically adds @i to @v.
9126+ */
9127+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9128+{
9129+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
9130 : "+m" (v->counter)
9131 : "ir" (i));
9132 }
9133@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9134 */
9135 static inline void atomic_sub(int i, atomic_t *v)
9136 {
9137- asm volatile(LOCK_PREFIX "subl %1,%0"
9138+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
9139+
9140+#ifdef CONFIG_PAX_REFCOUNT
9141+ "jno 0f\n"
9142+ LOCK_PREFIX "addl %1,%0\n"
9143+ "int $4\n0:\n"
9144+ _ASM_EXTABLE(0b, 0b)
9145+#endif
9146+
9147+ : "+m" (v->counter)
9148+ : "ir" (i));
9149+}
9150+
9151+/**
9152+ * atomic_sub_unchecked - subtract integer from atomic variable
9153+ * @i: integer value to subtract
9154+ * @v: pointer of type atomic_unchecked_t
9155+ *
9156+ * Atomically subtracts @i from @v.
9157+ */
9158+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9159+{
9160+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
9161 : "+m" (v->counter)
9162 : "ir" (i));
9163 }
9164@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9165 {
9166 unsigned char c;
9167
9168- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9169+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
9170+
9171+#ifdef CONFIG_PAX_REFCOUNT
9172+ "jno 0f\n"
9173+ LOCK_PREFIX "addl %2,%0\n"
9174+ "int $4\n0:\n"
9175+ _ASM_EXTABLE(0b, 0b)
9176+#endif
9177+
9178+ "sete %1\n"
9179 : "+m" (v->counter), "=qm" (c)
9180 : "ir" (i) : "memory");
9181 return c;
9182@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9183 */
9184 static inline void atomic_inc(atomic_t *v)
9185 {
9186- asm volatile(LOCK_PREFIX "incl %0"
9187+ asm volatile(LOCK_PREFIX "incl %0\n"
9188+
9189+#ifdef CONFIG_PAX_REFCOUNT
9190+ "jno 0f\n"
9191+ LOCK_PREFIX "decl %0\n"
9192+ "int $4\n0:\n"
9193+ _ASM_EXTABLE(0b, 0b)
9194+#endif
9195+
9196+ : "+m" (v->counter));
9197+}
9198+
9199+/**
9200+ * atomic_inc_unchecked - increment atomic variable
9201+ * @v: pointer of type atomic_unchecked_t
9202+ *
9203+ * Atomically increments @v by 1.
9204+ */
9205+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9206+{
9207+ asm volatile(LOCK_PREFIX "incl %0\n"
9208 : "+m" (v->counter));
9209 }
9210
9211@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9212 */
9213 static inline void atomic_dec(atomic_t *v)
9214 {
9215- asm volatile(LOCK_PREFIX "decl %0"
9216+ asm volatile(LOCK_PREFIX "decl %0\n"
9217+
9218+#ifdef CONFIG_PAX_REFCOUNT
9219+ "jno 0f\n"
9220+ LOCK_PREFIX "incl %0\n"
9221+ "int $4\n0:\n"
9222+ _ASM_EXTABLE(0b, 0b)
9223+#endif
9224+
9225+ : "+m" (v->counter));
9226+}
9227+
9228+/**
9229+ * atomic_dec_unchecked - decrement atomic variable
9230+ * @v: pointer of type atomic_unchecked_t
9231+ *
9232+ * Atomically decrements @v by 1.
9233+ */
9234+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9235+{
9236+ asm volatile(LOCK_PREFIX "decl %0\n"
9237 : "+m" (v->counter));
9238 }
9239
9240@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9241 {
9242 unsigned char c;
9243
9244- asm volatile(LOCK_PREFIX "decl %0; sete %1"
9245+ asm volatile(LOCK_PREFIX "decl %0\n"
9246+
9247+#ifdef CONFIG_PAX_REFCOUNT
9248+ "jno 0f\n"
9249+ LOCK_PREFIX "incl %0\n"
9250+ "int $4\n0:\n"
9251+ _ASM_EXTABLE(0b, 0b)
9252+#endif
9253+
9254+ "sete %1\n"
9255 : "+m" (v->counter), "=qm" (c)
9256 : : "memory");
9257 return c != 0;
9258@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9259 {
9260 unsigned char c;
9261
9262- asm volatile(LOCK_PREFIX "incl %0; sete %1"
9263+ asm volatile(LOCK_PREFIX "incl %0\n"
9264+
9265+#ifdef CONFIG_PAX_REFCOUNT
9266+ "jno 0f\n"
9267+ LOCK_PREFIX "decl %0\n"
9268+ "int $4\n0:\n"
9269+ _ASM_EXTABLE(0b, 0b)
9270+#endif
9271+
9272+ "sete %1\n"
9273+ : "+m" (v->counter), "=qm" (c)
9274+ : : "memory");
9275+ return c != 0;
9276+}
9277+
9278+/**
9279+ * atomic_inc_and_test_unchecked - increment and test
9280+ * @v: pointer of type atomic_unchecked_t
9281+ *
9282+ * Atomically increments @v by 1
9283+ * and returns true if the result is zero, or false for all
9284+ * other cases.
9285+ */
9286+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9287+{
9288+ unsigned char c;
9289+
9290+ asm volatile(LOCK_PREFIX "incl %0\n"
9291+ "sete %1\n"
9292 : "+m" (v->counter), "=qm" (c)
9293 : : "memory");
9294 return c != 0;
9295@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9296 {
9297 unsigned char c;
9298
9299- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9300+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
9301+
9302+#ifdef CONFIG_PAX_REFCOUNT
9303+ "jno 0f\n"
9304+ LOCK_PREFIX "subl %2,%0\n"
9305+ "int $4\n0:\n"
9306+ _ASM_EXTABLE(0b, 0b)
9307+#endif
9308+
9309+ "sets %1\n"
9310 : "+m" (v->counter), "=qm" (c)
9311 : "ir" (i) : "memory");
9312 return c;
9313@@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9314 goto no_xadd;
9315 #endif
9316 /* Modern 486+ processor */
9317- return i + xadd(&v->counter, i);
9318+ return i + xadd_check_overflow(&v->counter, i);
9319
9320 #ifdef CONFIG_M386
9321 no_xadd: /* Legacy 386 processor */
9322@@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9323 }
9324
9325 /**
9326+ * atomic_add_return_unchecked - add integer and return
9327+ * @i: integer value to add
9328+ * @v: pointer of type atomic_unchecked_t
9329+ *
9330+ * Atomically adds @i to @v and returns @i + @v
9331+ */
9332+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9333+{
9334+#ifdef CONFIG_M386
9335+ int __i;
9336+ unsigned long flags;
9337+ if (unlikely(boot_cpu_data.x86 <= 3))
9338+ goto no_xadd;
9339+#endif
9340+ /* Modern 486+ processor */
9341+ return i + xadd(&v->counter, i);
9342+
9343+#ifdef CONFIG_M386
9344+no_xadd: /* Legacy 386 processor */
9345+ raw_local_irq_save(flags);
9346+ __i = atomic_read_unchecked(v);
9347+ atomic_set_unchecked(v, i + __i);
9348+ raw_local_irq_restore(flags);
9349+ return i + __i;
9350+#endif
9351+}
9352+
9353+/**
9354 * atomic_sub_return - subtract integer and return
9355 * @v: pointer of type atomic_t
9356 * @i: integer value to subtract
9357@@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9358 }
9359
9360 #define atomic_inc_return(v) (atomic_add_return(1, v))
9361+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9362+{
9363+ return atomic_add_return_unchecked(1, v);
9364+}
9365 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9366
9367 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9368@@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9369 return cmpxchg(&v->counter, old, new);
9370 }
9371
9372+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9373+{
9374+ return cmpxchg(&v->counter, old, new);
9375+}
9376+
9377 static inline int atomic_xchg(atomic_t *v, int new)
9378 {
9379 return xchg(&v->counter, new);
9380 }
9381
9382+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9383+{
9384+ return xchg(&v->counter, new);
9385+}
9386+
9387 /**
9388 * __atomic_add_unless - add unless the number is already a given value
9389 * @v: pointer of type atomic_t
9390@@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9391 */
9392 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9393 {
9394- int c, old;
9395+ int c, old, new;
9396 c = atomic_read(v);
9397 for (;;) {
9398- if (unlikely(c == (u)))
9399+ if (unlikely(c == u))
9400 break;
9401- old = atomic_cmpxchg((v), c, c + (a));
9402+
9403+ asm volatile("addl %2,%0\n"
9404+
9405+#ifdef CONFIG_PAX_REFCOUNT
9406+ "jno 0f\n"
9407+ "subl %2,%0\n"
9408+ "int $4\n0:\n"
9409+ _ASM_EXTABLE(0b, 0b)
9410+#endif
9411+
9412+ : "=r" (new)
9413+ : "0" (c), "ir" (a));
9414+
9415+ old = atomic_cmpxchg(v, c, new);
9416 if (likely(old == c))
9417 break;
9418 c = old;
9419@@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9420 return c;
9421 }
9422
9423+/**
9424+ * atomic_inc_not_zero_hint - increment if not null
9425+ * @v: pointer of type atomic_t
9426+ * @hint: probable value of the atomic before the increment
9427+ *
9428+ * This version of atomic_inc_not_zero() gives a hint of probable
9429+ * value of the atomic. This helps processor to not read the memory
9430+ * before doing the atomic read/modify/write cycle, lowering
9431+ * number of bus transactions on some arches.
9432+ *
9433+ * Returns: 0 if increment was not done, 1 otherwise.
9434+ */
9435+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9436+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9437+{
9438+ int val, c = hint, new;
9439+
9440+ /* sanity test, should be removed by compiler if hint is a constant */
9441+ if (!hint)
9442+ return __atomic_add_unless(v, 1, 0);
9443+
9444+ do {
9445+ asm volatile("incl %0\n"
9446+
9447+#ifdef CONFIG_PAX_REFCOUNT
9448+ "jno 0f\n"
9449+ "decl %0\n"
9450+ "int $4\n0:\n"
9451+ _ASM_EXTABLE(0b, 0b)
9452+#endif
9453+
9454+ : "=r" (new)
9455+ : "0" (c));
9456+
9457+ val = atomic_cmpxchg(v, c, new);
9458+ if (val == c)
9459+ return 1;
9460+ c = val;
9461+ } while (c);
9462+
9463+ return 0;
9464+}
9465
9466 /*
9467 * atomic_dec_if_positive - decrement by 1 if old value positive
9468@@ -293,14 +552,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
9469 #endif
9470
9471 /* These are x86-specific, used by some header files */
9472-#define atomic_clear_mask(mask, addr) \
9473- asm volatile(LOCK_PREFIX "andl %0,%1" \
9474- : : "r" (~(mask)), "m" (*(addr)) : "memory")
9475+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
9476+{
9477+ asm volatile(LOCK_PREFIX "andl %1,%0"
9478+ : "+m" (v->counter)
9479+ : "r" (~(mask))
9480+ : "memory");
9481+}
9482
9483-#define atomic_set_mask(mask, addr) \
9484- asm volatile(LOCK_PREFIX "orl %0,%1" \
9485- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
9486- : "memory")
9487+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9488+{
9489+ asm volatile(LOCK_PREFIX "andl %1,%0"
9490+ : "+m" (v->counter)
9491+ : "r" (~(mask))
9492+ : "memory");
9493+}
9494+
9495+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
9496+{
9497+ asm volatile(LOCK_PREFIX "orl %1,%0"
9498+ : "+m" (v->counter)
9499+ : "r" (mask)
9500+ : "memory");
9501+}
9502+
9503+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9504+{
9505+ asm volatile(LOCK_PREFIX "orl %1,%0"
9506+ : "+m" (v->counter)
9507+ : "r" (mask)
9508+ : "memory");
9509+}
9510
9511 /* Atomic operations are already serializing on x86 */
9512 #define smp_mb__before_atomic_dec() barrier()
9513diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9514index b154de7..aadebd8 100644
9515--- a/arch/x86/include/asm/atomic64_32.h
9516+++ b/arch/x86/include/asm/atomic64_32.h
9517@@ -12,6 +12,14 @@ typedef struct {
9518 u64 __aligned(8) counter;
9519 } atomic64_t;
9520
9521+#ifdef CONFIG_PAX_REFCOUNT
9522+typedef struct {
9523+ u64 __aligned(8) counter;
9524+} atomic64_unchecked_t;
9525+#else
9526+typedef atomic64_t atomic64_unchecked_t;
9527+#endif
9528+
9529 #define ATOMIC64_INIT(val) { (val) }
9530
9531 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
9532@@ -37,21 +45,31 @@ typedef struct {
9533 ATOMIC64_DECL_ONE(sym##_386)
9534
9535 ATOMIC64_DECL_ONE(add_386);
9536+ATOMIC64_DECL_ONE(add_unchecked_386);
9537 ATOMIC64_DECL_ONE(sub_386);
9538+ATOMIC64_DECL_ONE(sub_unchecked_386);
9539 ATOMIC64_DECL_ONE(inc_386);
9540+ATOMIC64_DECL_ONE(inc_unchecked_386);
9541 ATOMIC64_DECL_ONE(dec_386);
9542+ATOMIC64_DECL_ONE(dec_unchecked_386);
9543 #endif
9544
9545 #define alternative_atomic64(f, out, in...) \
9546 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
9547
9548 ATOMIC64_DECL(read);
9549+ATOMIC64_DECL(read_unchecked);
9550 ATOMIC64_DECL(set);
9551+ATOMIC64_DECL(set_unchecked);
9552 ATOMIC64_DECL(xchg);
9553 ATOMIC64_DECL(add_return);
9554+ATOMIC64_DECL(add_return_unchecked);
9555 ATOMIC64_DECL(sub_return);
9556+ATOMIC64_DECL(sub_return_unchecked);
9557 ATOMIC64_DECL(inc_return);
9558+ATOMIC64_DECL(inc_return_unchecked);
9559 ATOMIC64_DECL(dec_return);
9560+ATOMIC64_DECL(dec_return_unchecked);
9561 ATOMIC64_DECL(dec_if_positive);
9562 ATOMIC64_DECL(inc_not_zero);
9563 ATOMIC64_DECL(add_unless);
9564@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9565 }
9566
9567 /**
9568+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9569+ * @p: pointer to type atomic64_unchecked_t
9570+ * @o: expected value
9571+ * @n: new value
9572+ *
9573+ * Atomically sets @v to @n if it was equal to @o and returns
9574+ * the old value.
9575+ */
9576+
9577+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9578+{
9579+ return cmpxchg64(&v->counter, o, n);
9580+}
9581+
9582+/**
9583 * atomic64_xchg - xchg atomic64 variable
9584 * @v: pointer to type atomic64_t
9585 * @n: value to assign
9586@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9587 }
9588
9589 /**
9590+ * atomic64_set_unchecked - set atomic64 variable
9591+ * @v: pointer to type atomic64_unchecked_t
9592+ * @n: value to assign
9593+ *
9594+ * Atomically sets the value of @v to @n.
9595+ */
9596+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9597+{
9598+ unsigned high = (unsigned)(i >> 32);
9599+ unsigned low = (unsigned)i;
9600+ alternative_atomic64(set, /* no output */,
9601+ "S" (v), "b" (low), "c" (high)
9602+ : "eax", "edx", "memory");
9603+}
9604+
9605+/**
9606 * atomic64_read - read atomic64 variable
9607 * @v: pointer to type atomic64_t
9608 *
9609@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
9610 }
9611
9612 /**
9613+ * atomic64_read_unchecked - read atomic64 variable
9614+ * @v: pointer to type atomic64_unchecked_t
9615+ *
9616+ * Atomically reads the value of @v and returns it.
9617+ */
9618+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9619+{
9620+ long long r;
9621+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
9622+ return r;
9623+ }
9624+
9625+/**
9626 * atomic64_add_return - add and return
9627 * @i: integer value to add
9628 * @v: pointer to type atomic64_t
9629@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9630 return i;
9631 }
9632
9633+/**
9634+ * atomic64_add_return_unchecked - add and return
9635+ * @i: integer value to add
9636+ * @v: pointer to type atomic64_unchecked_t
9637+ *
9638+ * Atomically adds @i to @v and returns @i + *@v
9639+ */
9640+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9641+{
9642+ alternative_atomic64(add_return_unchecked,
9643+ ASM_OUTPUT2("+A" (i), "+c" (v)),
9644+ ASM_NO_INPUT_CLOBBER("memory"));
9645+ return i;
9646+}
9647+
9648 /*
9649 * Other variants with different arithmetic operators:
9650 */
9651@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9652 return a;
9653 }
9654
9655+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9656+{
9657+ long long a;
9658+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
9659+ "S" (v) : "memory", "ecx");
9660+ return a;
9661+}
9662+
9663 static inline long long atomic64_dec_return(atomic64_t *v)
9664 {
9665 long long a;
9666@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9667 }
9668
9669 /**
9670+ * atomic64_add_unchecked - add integer to atomic64 variable
9671+ * @i: integer value to add
9672+ * @v: pointer to type atomic64_unchecked_t
9673+ *
9674+ * Atomically adds @i to @v.
9675+ */
9676+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9677+{
9678+ __alternative_atomic64(add_unchecked, add_return_unchecked,
9679+ ASM_OUTPUT2("+A" (i), "+c" (v)),
9680+ ASM_NO_INPUT_CLOBBER("memory"));
9681+ return i;
9682+}
9683+
9684+/**
9685 * atomic64_sub - subtract the atomic64 variable
9686 * @i: integer value to subtract
9687 * @v: pointer to type atomic64_t
9688diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9689index 0e1cbfc..5623683 100644
9690--- a/arch/x86/include/asm/atomic64_64.h
9691+++ b/arch/x86/include/asm/atomic64_64.h
9692@@ -18,7 +18,19 @@
9693 */
9694 static inline long atomic64_read(const atomic64_t *v)
9695 {
9696- return (*(volatile long *)&(v)->counter);
9697+ return (*(volatile const long *)&(v)->counter);
9698+}
9699+
9700+/**
9701+ * atomic64_read_unchecked - read atomic64 variable
9702+ * @v: pointer of type atomic64_unchecked_t
9703+ *
9704+ * Atomically reads the value of @v.
9705+ * Doesn't imply a read memory barrier.
9706+ */
9707+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9708+{
9709+ return (*(volatile const long *)&(v)->counter);
9710 }
9711
9712 /**
9713@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9714 }
9715
9716 /**
9717+ * atomic64_set_unchecked - set atomic64 variable
9718+ * @v: pointer to type atomic64_unchecked_t
9719+ * @i: required value
9720+ *
9721+ * Atomically sets the value of @v to @i.
9722+ */
9723+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9724+{
9725+ v->counter = i;
9726+}
9727+
9728+/**
9729 * atomic64_add - add integer to atomic64 variable
9730 * @i: integer value to add
9731 * @v: pointer to type atomic64_t
9732@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9733 */
9734 static inline void atomic64_add(long i, atomic64_t *v)
9735 {
9736+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
9737+
9738+#ifdef CONFIG_PAX_REFCOUNT
9739+ "jno 0f\n"
9740+ LOCK_PREFIX "subq %1,%0\n"
9741+ "int $4\n0:\n"
9742+ _ASM_EXTABLE(0b, 0b)
9743+#endif
9744+
9745+ : "=m" (v->counter)
9746+ : "er" (i), "m" (v->counter));
9747+}
9748+
9749+/**
9750+ * atomic64_add_unchecked - add integer to atomic64 variable
9751+ * @i: integer value to add
9752+ * @v: pointer to type atomic64_unchecked_t
9753+ *
9754+ * Atomically adds @i to @v.
9755+ */
9756+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9757+{
9758 asm volatile(LOCK_PREFIX "addq %1,%0"
9759 : "=m" (v->counter)
9760 : "er" (i), "m" (v->counter));
9761@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9762 */
9763 static inline void atomic64_sub(long i, atomic64_t *v)
9764 {
9765- asm volatile(LOCK_PREFIX "subq %1,%0"
9766+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
9767+
9768+#ifdef CONFIG_PAX_REFCOUNT
9769+ "jno 0f\n"
9770+ LOCK_PREFIX "addq %1,%0\n"
9771+ "int $4\n0:\n"
9772+ _ASM_EXTABLE(0b, 0b)
9773+#endif
9774+
9775+ : "=m" (v->counter)
9776+ : "er" (i), "m" (v->counter));
9777+}
9778+
9779+/**
9780+ * atomic64_sub_unchecked - subtract the atomic64 variable
9781+ * @i: integer value to subtract
9782+ * @v: pointer to type atomic64_unchecked_t
9783+ *
9784+ * Atomically subtracts @i from @v.
9785+ */
9786+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9787+{
9788+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
9789 : "=m" (v->counter)
9790 : "er" (i), "m" (v->counter));
9791 }
9792@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9793 {
9794 unsigned char c;
9795
9796- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9797+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
9798+
9799+#ifdef CONFIG_PAX_REFCOUNT
9800+ "jno 0f\n"
9801+ LOCK_PREFIX "addq %2,%0\n"
9802+ "int $4\n0:\n"
9803+ _ASM_EXTABLE(0b, 0b)
9804+#endif
9805+
9806+ "sete %1\n"
9807 : "=m" (v->counter), "=qm" (c)
9808 : "er" (i), "m" (v->counter) : "memory");
9809 return c;
9810@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9811 */
9812 static inline void atomic64_inc(atomic64_t *v)
9813 {
9814+ asm volatile(LOCK_PREFIX "incq %0\n"
9815+
9816+#ifdef CONFIG_PAX_REFCOUNT
9817+ "jno 0f\n"
9818+ LOCK_PREFIX "decq %0\n"
9819+ "int $4\n0:\n"
9820+ _ASM_EXTABLE(0b, 0b)
9821+#endif
9822+
9823+ : "=m" (v->counter)
9824+ : "m" (v->counter));
9825+}
9826+
9827+/**
9828+ * atomic64_inc_unchecked - increment atomic64 variable
9829+ * @v: pointer to type atomic64_unchecked_t
9830+ *
9831+ * Atomically increments @v by 1.
9832+ */
9833+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9834+{
9835 asm volatile(LOCK_PREFIX "incq %0"
9836 : "=m" (v->counter)
9837 : "m" (v->counter));
9838@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9839 */
9840 static inline void atomic64_dec(atomic64_t *v)
9841 {
9842- asm volatile(LOCK_PREFIX "decq %0"
9843+ asm volatile(LOCK_PREFIX "decq %0\n"
9844+
9845+#ifdef CONFIG_PAX_REFCOUNT
9846+ "jno 0f\n"
9847+ LOCK_PREFIX "incq %0\n"
9848+ "int $4\n0:\n"
9849+ _ASM_EXTABLE(0b, 0b)
9850+#endif
9851+
9852+ : "=m" (v->counter)
9853+ : "m" (v->counter));
9854+}
9855+
9856+/**
9857+ * atomic64_dec_unchecked - decrement atomic64 variable
9858+ * @v: pointer to type atomic64_t
9859+ *
9860+ * Atomically decrements @v by 1.
9861+ */
9862+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9863+{
9864+ asm volatile(LOCK_PREFIX "decq %0\n"
9865 : "=m" (v->counter)
9866 : "m" (v->counter));
9867 }
9868@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9869 {
9870 unsigned char c;
9871
9872- asm volatile(LOCK_PREFIX "decq %0; sete %1"
9873+ asm volatile(LOCK_PREFIX "decq %0\n"
9874+
9875+#ifdef CONFIG_PAX_REFCOUNT
9876+ "jno 0f\n"
9877+ LOCK_PREFIX "incq %0\n"
9878+ "int $4\n0:\n"
9879+ _ASM_EXTABLE(0b, 0b)
9880+#endif
9881+
9882+ "sete %1\n"
9883 : "=m" (v->counter), "=qm" (c)
9884 : "m" (v->counter) : "memory");
9885 return c != 0;
9886@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9887 {
9888 unsigned char c;
9889
9890- asm volatile(LOCK_PREFIX "incq %0; sete %1"
9891+ asm volatile(LOCK_PREFIX "incq %0\n"
9892+
9893+#ifdef CONFIG_PAX_REFCOUNT
9894+ "jno 0f\n"
9895+ LOCK_PREFIX "decq %0\n"
9896+ "int $4\n0:\n"
9897+ _ASM_EXTABLE(0b, 0b)
9898+#endif
9899+
9900+ "sete %1\n"
9901 : "=m" (v->counter), "=qm" (c)
9902 : "m" (v->counter) : "memory");
9903 return c != 0;
9904@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9905 {
9906 unsigned char c;
9907
9908- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9909+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
9910+
9911+#ifdef CONFIG_PAX_REFCOUNT
9912+ "jno 0f\n"
9913+ LOCK_PREFIX "subq %2,%0\n"
9914+ "int $4\n0:\n"
9915+ _ASM_EXTABLE(0b, 0b)
9916+#endif
9917+
9918+ "sets %1\n"
9919 : "=m" (v->counter), "=qm" (c)
9920 : "er" (i), "m" (v->counter) : "memory");
9921 return c;
9922@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9923 */
9924 static inline long atomic64_add_return(long i, atomic64_t *v)
9925 {
9926+ return i + xadd_check_overflow(&v->counter, i);
9927+}
9928+
9929+/**
9930+ * atomic64_add_return_unchecked - add and return
9931+ * @i: integer value to add
9932+ * @v: pointer to type atomic64_unchecked_t
9933+ *
9934+ * Atomically adds @i to @v and returns @i + @v
9935+ */
9936+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9937+{
9938 return i + xadd(&v->counter, i);
9939 }
9940
9941@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
9942 }
9943
9944 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
9945+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9946+{
9947+ return atomic64_add_return_unchecked(1, v);
9948+}
9949 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
9950
9951 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9952@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9953 return cmpxchg(&v->counter, old, new);
9954 }
9955
9956+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
9957+{
9958+ return cmpxchg(&v->counter, old, new);
9959+}
9960+
9961 static inline long atomic64_xchg(atomic64_t *v, long new)
9962 {
9963 return xchg(&v->counter, new);
9964@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
9965 */
9966 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
9967 {
9968- long c, old;
9969+ long c, old, new;
9970 c = atomic64_read(v);
9971 for (;;) {
9972- if (unlikely(c == (u)))
9973+ if (unlikely(c == u))
9974 break;
9975- old = atomic64_cmpxchg((v), c, c + (a));
9976+
9977+ asm volatile("add %2,%0\n"
9978+
9979+#ifdef CONFIG_PAX_REFCOUNT
9980+ "jno 0f\n"
9981+ "sub %2,%0\n"
9982+ "int $4\n0:\n"
9983+ _ASM_EXTABLE(0b, 0b)
9984+#endif
9985+
9986+ : "=r" (new)
9987+ : "0" (c), "ir" (a));
9988+
9989+ old = atomic64_cmpxchg(v, c, new);
9990 if (likely(old == c))
9991 break;
9992 c = old;
9993 }
9994- return c != (u);
9995+ return c != u;
9996 }
9997
9998 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9999diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10000index a6983b2..63f48a2 100644
10001--- a/arch/x86/include/asm/bitops.h
10002+++ b/arch/x86/include/asm/bitops.h
10003@@ -40,7 +40,7 @@
10004 * a mask operation on a byte.
10005 */
10006 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10007-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10008+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10009 #define CONST_MASK(nr) (1 << ((nr) & 7))
10010
10011 /**
10012diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10013index b13fe63..0dab13a 100644
10014--- a/arch/x86/include/asm/boot.h
10015+++ b/arch/x86/include/asm/boot.h
10016@@ -11,10 +11,15 @@
10017 #include <asm/pgtable_types.h>
10018
10019 /* Physical address where kernel should be loaded. */
10020-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10021+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10022 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10023 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10024
10025+#ifndef __ASSEMBLY__
10026+extern unsigned char __LOAD_PHYSICAL_ADDR[];
10027+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10028+#endif
10029+
10030 /* Minimum kernel alignment, as a power of two */
10031 #ifdef CONFIG_X86_64
10032 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10033diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10034index 48f99f1..d78ebf9 100644
10035--- a/arch/x86/include/asm/cache.h
10036+++ b/arch/x86/include/asm/cache.h
10037@@ -5,12 +5,13 @@
10038
10039 /* L1 cache line size */
10040 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10041-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10042+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10043
10044 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10045+#define __read_only __attribute__((__section__(".data..read_only")))
10046
10047 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10048-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10049+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10050
10051 #ifdef CONFIG_X86_VSMP
10052 #ifdef CONFIG_SMP
10053diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10054index 9863ee3..4a1f8e1 100644
10055--- a/arch/x86/include/asm/cacheflush.h
10056+++ b/arch/x86/include/asm/cacheflush.h
10057@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10058 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10059
10060 if (pg_flags == _PGMT_DEFAULT)
10061- return -1;
10062+ return ~0UL;
10063 else if (pg_flags == _PGMT_WC)
10064 return _PAGE_CACHE_WC;
10065 else if (pg_flags == _PGMT_UC_MINUS)
10066diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10067index 46fc474..b02b0f9 100644
10068--- a/arch/x86/include/asm/checksum_32.h
10069+++ b/arch/x86/include/asm/checksum_32.h
10070@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10071 int len, __wsum sum,
10072 int *src_err_ptr, int *dst_err_ptr);
10073
10074+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10075+ int len, __wsum sum,
10076+ int *src_err_ptr, int *dst_err_ptr);
10077+
10078+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10079+ int len, __wsum sum,
10080+ int *src_err_ptr, int *dst_err_ptr);
10081+
10082 /*
10083 * Note: when you get a NULL pointer exception here this means someone
10084 * passed in an incorrect kernel address to one of these functions.
10085@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10086 int *err_ptr)
10087 {
10088 might_sleep();
10089- return csum_partial_copy_generic((__force void *)src, dst,
10090+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
10091 len, sum, err_ptr, NULL);
10092 }
10093
10094@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10095 {
10096 might_sleep();
10097 if (access_ok(VERIFY_WRITE, dst, len))
10098- return csum_partial_copy_generic(src, (__force void *)dst,
10099+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10100 len, sum, NULL, err_ptr);
10101
10102 if (len)
10103diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10104index 99480e5..d81165b 100644
10105--- a/arch/x86/include/asm/cmpxchg.h
10106+++ b/arch/x86/include/asm/cmpxchg.h
10107@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10108 __compiletime_error("Bad argument size for cmpxchg");
10109 extern void __xadd_wrong_size(void)
10110 __compiletime_error("Bad argument size for xadd");
10111+extern void __xadd_check_overflow_wrong_size(void)
10112+ __compiletime_error("Bad argument size for xadd_check_overflow");
10113 extern void __add_wrong_size(void)
10114 __compiletime_error("Bad argument size for add");
10115+extern void __add_check_overflow_wrong_size(void)
10116+ __compiletime_error("Bad argument size for add_check_overflow");
10117
10118 /*
10119 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10120@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10121 __ret; \
10122 })
10123
10124+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10125+ ({ \
10126+ __typeof__ (*(ptr)) __ret = (arg); \
10127+ switch (sizeof(*(ptr))) { \
10128+ case __X86_CASE_L: \
10129+ asm volatile (lock #op "l %0, %1\n" \
10130+ "jno 0f\n" \
10131+ "mov %0,%1\n" \
10132+ "int $4\n0:\n" \
10133+ _ASM_EXTABLE(0b, 0b) \
10134+ : "+r" (__ret), "+m" (*(ptr)) \
10135+ : : "memory", "cc"); \
10136+ break; \
10137+ case __X86_CASE_Q: \
10138+ asm volatile (lock #op "q %q0, %1\n" \
10139+ "jno 0f\n" \
10140+ "mov %0,%1\n" \
10141+ "int $4\n0:\n" \
10142+ _ASM_EXTABLE(0b, 0b) \
10143+ : "+r" (__ret), "+m" (*(ptr)) \
10144+ : : "memory", "cc"); \
10145+ break; \
10146+ default: \
10147+ __ ## op ## _check_overflow_wrong_size(); \
10148+ } \
10149+ __ret; \
10150+ })
10151+
10152 /*
10153 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10154 * Since this is generally used to protect other memory information, we
10155@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10156 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10157 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10158
10159+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10160+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10161+
10162 #define __add(ptr, inc, lock) \
10163 ({ \
10164 __typeof__ (*(ptr)) __ret = (inc); \
10165diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10166index f91e80f..7f9bd27 100644
10167--- a/arch/x86/include/asm/cpufeature.h
10168+++ b/arch/x86/include/asm/cpufeature.h
10169@@ -371,7 +371,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10170 ".section .discard,\"aw\",@progbits\n"
10171 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10172 ".previous\n"
10173- ".section .altinstr_replacement,\"ax\"\n"
10174+ ".section .altinstr_replacement,\"a\"\n"
10175 "3: movb $1,%0\n"
10176 "4:\n"
10177 ".previous\n"
10178diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10179index 8bf1c06..f723dfd 100644
10180--- a/arch/x86/include/asm/desc.h
10181+++ b/arch/x86/include/asm/desc.h
10182@@ -4,6 +4,7 @@
10183 #include <asm/desc_defs.h>
10184 #include <asm/ldt.h>
10185 #include <asm/mmu.h>
10186+#include <asm/pgtable.h>
10187
10188 #include <linux/smp.h>
10189 #include <linux/percpu.h>
10190@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10191
10192 desc->type = (info->read_exec_only ^ 1) << 1;
10193 desc->type |= info->contents << 2;
10194+ desc->type |= info->seg_not_present ^ 1;
10195
10196 desc->s = 1;
10197 desc->dpl = 0x3;
10198@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10199 }
10200
10201 extern struct desc_ptr idt_descr;
10202-extern gate_desc idt_table[];
10203 extern struct desc_ptr nmi_idt_descr;
10204-extern gate_desc nmi_idt_table[];
10205-
10206-struct gdt_page {
10207- struct desc_struct gdt[GDT_ENTRIES];
10208-} __attribute__((aligned(PAGE_SIZE)));
10209-
10210-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10211+extern gate_desc idt_table[256];
10212+extern gate_desc nmi_idt_table[256];
10213
10214+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10215 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10216 {
10217- return per_cpu(gdt_page, cpu).gdt;
10218+ return cpu_gdt_table[cpu];
10219 }
10220
10221 #ifdef CONFIG_X86_64
10222@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10223 unsigned long base, unsigned dpl, unsigned flags,
10224 unsigned short seg)
10225 {
10226- gate->a = (seg << 16) | (base & 0xffff);
10227- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10228+ gate->gate.offset_low = base;
10229+ gate->gate.seg = seg;
10230+ gate->gate.reserved = 0;
10231+ gate->gate.type = type;
10232+ gate->gate.s = 0;
10233+ gate->gate.dpl = dpl;
10234+ gate->gate.p = 1;
10235+ gate->gate.offset_high = base >> 16;
10236 }
10237
10238 #endif
10239@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10240
10241 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10242 {
10243+ pax_open_kernel();
10244 memcpy(&idt[entry], gate, sizeof(*gate));
10245+ pax_close_kernel();
10246 }
10247
10248 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10249 {
10250+ pax_open_kernel();
10251 memcpy(&ldt[entry], desc, 8);
10252+ pax_close_kernel();
10253 }
10254
10255 static inline void
10256@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10257 default: size = sizeof(*gdt); break;
10258 }
10259
10260+ pax_open_kernel();
10261 memcpy(&gdt[entry], desc, size);
10262+ pax_close_kernel();
10263 }
10264
10265 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10266@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10267
10268 static inline void native_load_tr_desc(void)
10269 {
10270+ pax_open_kernel();
10271 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10272+ pax_close_kernel();
10273 }
10274
10275 static inline void native_load_gdt(const struct desc_ptr *dtr)
10276@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10277 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10278 unsigned int i;
10279
10280+ pax_open_kernel();
10281 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10282 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10283+ pax_close_kernel();
10284 }
10285
10286 #define _LDT_empty(info) \
10287@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10288 }
10289
10290 #ifdef CONFIG_X86_64
10291-static inline void set_nmi_gate(int gate, void *addr)
10292+static inline void set_nmi_gate(int gate, const void *addr)
10293 {
10294 gate_desc s;
10295
10296@@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10297 }
10298 #endif
10299
10300-static inline void _set_gate(int gate, unsigned type, void *addr,
10301+static inline void _set_gate(int gate, unsigned type, const void *addr,
10302 unsigned dpl, unsigned ist, unsigned seg)
10303 {
10304 gate_desc s;
10305@@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10306 * Pentium F0 0F bugfix can have resulted in the mapped
10307 * IDT being write-protected.
10308 */
10309-static inline void set_intr_gate(unsigned int n, void *addr)
10310+static inline void set_intr_gate(unsigned int n, const void *addr)
10311 {
10312 BUG_ON((unsigned)n > 0xFF);
10313 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10314@@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10315 /*
10316 * This routine sets up an interrupt gate at directory privilege level 3.
10317 */
10318-static inline void set_system_intr_gate(unsigned int n, void *addr)
10319+static inline void set_system_intr_gate(unsigned int n, const void *addr)
10320 {
10321 BUG_ON((unsigned)n > 0xFF);
10322 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10323 }
10324
10325-static inline void set_system_trap_gate(unsigned int n, void *addr)
10326+static inline void set_system_trap_gate(unsigned int n, const void *addr)
10327 {
10328 BUG_ON((unsigned)n > 0xFF);
10329 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10330 }
10331
10332-static inline void set_trap_gate(unsigned int n, void *addr)
10333+static inline void set_trap_gate(unsigned int n, const void *addr)
10334 {
10335 BUG_ON((unsigned)n > 0xFF);
10336 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10337@@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10338 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10339 {
10340 BUG_ON((unsigned)n > 0xFF);
10341- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10342+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10343 }
10344
10345-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10346+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10347 {
10348 BUG_ON((unsigned)n > 0xFF);
10349 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10350 }
10351
10352-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10353+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10354 {
10355 BUG_ON((unsigned)n > 0xFF);
10356 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10357 }
10358
10359+#ifdef CONFIG_X86_32
10360+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10361+{
10362+ struct desc_struct d;
10363+
10364+ if (likely(limit))
10365+ limit = (limit - 1UL) >> PAGE_SHIFT;
10366+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
10367+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10368+}
10369+#endif
10370+
10371 #endif /* _ASM_X86_DESC_H */
10372diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10373index 278441f..b95a174 100644
10374--- a/arch/x86/include/asm/desc_defs.h
10375+++ b/arch/x86/include/asm/desc_defs.h
10376@@ -31,6 +31,12 @@ struct desc_struct {
10377 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10378 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10379 };
10380+ struct {
10381+ u16 offset_low;
10382+ u16 seg;
10383+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10384+ unsigned offset_high: 16;
10385+ } gate;
10386 };
10387 } __attribute__((packed));
10388
10389diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10390index 3778256..c5d4fce 100644
10391--- a/arch/x86/include/asm/e820.h
10392+++ b/arch/x86/include/asm/e820.h
10393@@ -69,7 +69,7 @@ struct e820map {
10394 #define ISA_START_ADDRESS 0xa0000
10395 #define ISA_END_ADDRESS 0x100000
10396
10397-#define BIOS_BEGIN 0x000a0000
10398+#define BIOS_BEGIN 0x000c0000
10399 #define BIOS_END 0x00100000
10400
10401 #define BIOS_ROM_BASE 0xffe00000
10402diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10403index 5939f44..f8845f6 100644
10404--- a/arch/x86/include/asm/elf.h
10405+++ b/arch/x86/include/asm/elf.h
10406@@ -243,7 +243,25 @@ extern int force_personality32;
10407 the loader. We need to make sure that it is out of the way of the program
10408 that it will "exec", and that there is sufficient room for the brk. */
10409
10410+#ifdef CONFIG_PAX_SEGMEXEC
10411+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10412+#else
10413 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10414+#endif
10415+
10416+#ifdef CONFIG_PAX_ASLR
10417+#ifdef CONFIG_X86_32
10418+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10419+
10420+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10421+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10422+#else
10423+#define PAX_ELF_ET_DYN_BASE 0x400000UL
10424+
10425+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10426+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10427+#endif
10428+#endif
10429
10430 /* This yields a mask that user programs can use to figure out what
10431 instruction set this CPU supports. This could be done in user space,
10432@@ -296,16 +314,12 @@ do { \
10433
10434 #define ARCH_DLINFO \
10435 do { \
10436- if (vdso_enabled) \
10437- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10438- (unsigned long)current->mm->context.vdso); \
10439+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10440 } while (0)
10441
10442 #define ARCH_DLINFO_X32 \
10443 do { \
10444- if (vdso_enabled) \
10445- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10446- (unsigned long)current->mm->context.vdso); \
10447+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10448 } while (0)
10449
10450 #define AT_SYSINFO 32
10451@@ -320,7 +334,7 @@ else \
10452
10453 #endif /* !CONFIG_X86_32 */
10454
10455-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10456+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10457
10458 #define VDSO_ENTRY \
10459 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10460@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
10461 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10462 #define compat_arch_setup_additional_pages syscall32_setup_pages
10463
10464-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10465-#define arch_randomize_brk arch_randomize_brk
10466-
10467 /*
10468 * True on X86_32 or when emulating IA32 on X86_64
10469 */
10470diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10471index cc70c1c..d96d011 100644
10472--- a/arch/x86/include/asm/emergency-restart.h
10473+++ b/arch/x86/include/asm/emergency-restart.h
10474@@ -15,6 +15,6 @@ enum reboot_type {
10475
10476 extern enum reboot_type reboot_type;
10477
10478-extern void machine_emergency_restart(void);
10479+extern void machine_emergency_restart(void) __noreturn;
10480
10481 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10482diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
10483index 75f4c6d..ee3eb8f 100644
10484--- a/arch/x86/include/asm/fpu-internal.h
10485+++ b/arch/x86/include/asm/fpu-internal.h
10486@@ -86,6 +86,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10487 {
10488 int err;
10489
10490+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10491+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10492+ fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10493+#endif
10494+
10495 /* See comment in fxsave() below. */
10496 #ifdef CONFIG_AS_FXSAVEQ
10497 asm volatile("1: fxrstorq %[fx]\n\t"
10498@@ -115,6 +120,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10499 {
10500 int err;
10501
10502+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10503+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10504+ fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10505+#endif
10506+
10507 /*
10508 * Clear the bytes not touched by the fxsave and reserved
10509 * for the SW usage.
10510@@ -271,7 +281,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10511 "emms\n\t" /* clear stack tags */
10512 "fildl %P[addr]", /* set F?P to defined value */
10513 X86_FEATURE_FXSAVE_LEAK,
10514- [addr] "m" (tsk->thread.fpu.has_fpu));
10515+ [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10516
10517 return fpu_restore_checking(&tsk->thread.fpu);
10518 }
10519diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10520index 71ecbcb..bac10b7 100644
10521--- a/arch/x86/include/asm/futex.h
10522+++ b/arch/x86/include/asm/futex.h
10523@@ -11,16 +11,18 @@
10524 #include <asm/processor.h>
10525
10526 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10527+ typecheck(u32 __user *, uaddr); \
10528 asm volatile("1:\t" insn "\n" \
10529 "2:\t.section .fixup,\"ax\"\n" \
10530 "3:\tmov\t%3, %1\n" \
10531 "\tjmp\t2b\n" \
10532 "\t.previous\n" \
10533 _ASM_EXTABLE(1b, 3b) \
10534- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10535+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10536 : "i" (-EFAULT), "0" (oparg), "1" (0))
10537
10538 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10539+ typecheck(u32 __user *, uaddr); \
10540 asm volatile("1:\tmovl %2, %0\n" \
10541 "\tmovl\t%0, %3\n" \
10542 "\t" insn "\n" \
10543@@ -33,7 +35,7 @@
10544 _ASM_EXTABLE(1b, 4b) \
10545 _ASM_EXTABLE(2b, 4b) \
10546 : "=&a" (oldval), "=&r" (ret), \
10547- "+m" (*uaddr), "=&r" (tem) \
10548+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10549 : "r" (oparg), "i" (-EFAULT), "1" (0))
10550
10551 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10552@@ -60,10 +62,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10553
10554 switch (op) {
10555 case FUTEX_OP_SET:
10556- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10557+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10558 break;
10559 case FUTEX_OP_ADD:
10560- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10561+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10562 uaddr, oparg);
10563 break;
10564 case FUTEX_OP_OR:
10565@@ -122,13 +124,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10566 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10567 return -EFAULT;
10568
10569- asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10570+ asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10571 "2:\t.section .fixup, \"ax\"\n"
10572 "3:\tmov %3, %0\n"
10573 "\tjmp 2b\n"
10574 "\t.previous\n"
10575 _ASM_EXTABLE(1b, 3b)
10576- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10577+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10578 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10579 : "memory"
10580 );
10581diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10582index eb92a6e..b98b2f4 100644
10583--- a/arch/x86/include/asm/hw_irq.h
10584+++ b/arch/x86/include/asm/hw_irq.h
10585@@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10586 extern void enable_IO_APIC(void);
10587
10588 /* Statistics */
10589-extern atomic_t irq_err_count;
10590-extern atomic_t irq_mis_count;
10591+extern atomic_unchecked_t irq_err_count;
10592+extern atomic_unchecked_t irq_mis_count;
10593
10594 /* EISA */
10595 extern void eisa_set_level_irq(unsigned int irq);
10596diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10597index d8e8eef..99f81ae 100644
10598--- a/arch/x86/include/asm/io.h
10599+++ b/arch/x86/include/asm/io.h
10600@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10601
10602 #include <linux/vmalloc.h>
10603
10604+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10605+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10606+{
10607+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10608+}
10609+
10610+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10611+{
10612+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10613+}
10614+
10615 /*
10616 * Convert a virtual cached pointer to an uncached pointer
10617 */
10618diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10619index bba3cf8..06bc8da 100644
10620--- a/arch/x86/include/asm/irqflags.h
10621+++ b/arch/x86/include/asm/irqflags.h
10622@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10623 sti; \
10624 sysexit
10625
10626+#define GET_CR0_INTO_RDI mov %cr0, %rdi
10627+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10628+#define GET_CR3_INTO_RDI mov %cr3, %rdi
10629+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10630+
10631 #else
10632 #define INTERRUPT_RETURN iret
10633 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10634diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10635index 5478825..839e88c 100644
10636--- a/arch/x86/include/asm/kprobes.h
10637+++ b/arch/x86/include/asm/kprobes.h
10638@@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10639 #define RELATIVEJUMP_SIZE 5
10640 #define RELATIVECALL_OPCODE 0xe8
10641 #define RELATIVE_ADDR_SIZE 4
10642-#define MAX_STACK_SIZE 64
10643-#define MIN_STACK_SIZE(ADDR) \
10644- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10645- THREAD_SIZE - (unsigned long)(ADDR))) \
10646- ? (MAX_STACK_SIZE) \
10647- : (((unsigned long)current_thread_info()) + \
10648- THREAD_SIZE - (unsigned long)(ADDR)))
10649+#define MAX_STACK_SIZE 64UL
10650+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10651
10652 #define flush_insn_slot(p) do { } while (0)
10653
10654diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10655index db7c1f2..92f130a 100644
10656--- a/arch/x86/include/asm/kvm_host.h
10657+++ b/arch/x86/include/asm/kvm_host.h
10658@@ -680,7 +680,7 @@ struct kvm_x86_ops {
10659 int (*check_intercept)(struct kvm_vcpu *vcpu,
10660 struct x86_instruction_info *info,
10661 enum x86_intercept_stage stage);
10662-};
10663+} __do_const;
10664
10665 struct kvm_arch_async_pf {
10666 u32 token;
10667diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10668index c8bed0d..e5721fa 100644
10669--- a/arch/x86/include/asm/local.h
10670+++ b/arch/x86/include/asm/local.h
10671@@ -17,26 +17,58 @@ typedef struct {
10672
10673 static inline void local_inc(local_t *l)
10674 {
10675- asm volatile(_ASM_INC "%0"
10676+ asm volatile(_ASM_INC "%0\n"
10677+
10678+#ifdef CONFIG_PAX_REFCOUNT
10679+ "jno 0f\n"
10680+ _ASM_DEC "%0\n"
10681+ "int $4\n0:\n"
10682+ _ASM_EXTABLE(0b, 0b)
10683+#endif
10684+
10685 : "+m" (l->a.counter));
10686 }
10687
10688 static inline void local_dec(local_t *l)
10689 {
10690- asm volatile(_ASM_DEC "%0"
10691+ asm volatile(_ASM_DEC "%0\n"
10692+
10693+#ifdef CONFIG_PAX_REFCOUNT
10694+ "jno 0f\n"
10695+ _ASM_INC "%0\n"
10696+ "int $4\n0:\n"
10697+ _ASM_EXTABLE(0b, 0b)
10698+#endif
10699+
10700 : "+m" (l->a.counter));
10701 }
10702
10703 static inline void local_add(long i, local_t *l)
10704 {
10705- asm volatile(_ASM_ADD "%1,%0"
10706+ asm volatile(_ASM_ADD "%1,%0\n"
10707+
10708+#ifdef CONFIG_PAX_REFCOUNT
10709+ "jno 0f\n"
10710+ _ASM_SUB "%1,%0\n"
10711+ "int $4\n0:\n"
10712+ _ASM_EXTABLE(0b, 0b)
10713+#endif
10714+
10715 : "+m" (l->a.counter)
10716 : "ir" (i));
10717 }
10718
10719 static inline void local_sub(long i, local_t *l)
10720 {
10721- asm volatile(_ASM_SUB "%1,%0"
10722+ asm volatile(_ASM_SUB "%1,%0\n"
10723+
10724+#ifdef CONFIG_PAX_REFCOUNT
10725+ "jno 0f\n"
10726+ _ASM_ADD "%1,%0\n"
10727+ "int $4\n0:\n"
10728+ _ASM_EXTABLE(0b, 0b)
10729+#endif
10730+
10731 : "+m" (l->a.counter)
10732 : "ir" (i));
10733 }
10734@@ -54,7 +86,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10735 {
10736 unsigned char c;
10737
10738- asm volatile(_ASM_SUB "%2,%0; sete %1"
10739+ asm volatile(_ASM_SUB "%2,%0\n"
10740+
10741+#ifdef CONFIG_PAX_REFCOUNT
10742+ "jno 0f\n"
10743+ _ASM_ADD "%2,%0\n"
10744+ "int $4\n0:\n"
10745+ _ASM_EXTABLE(0b, 0b)
10746+#endif
10747+
10748+ "sete %1\n"
10749 : "+m" (l->a.counter), "=qm" (c)
10750 : "ir" (i) : "memory");
10751 return c;
10752@@ -72,7 +113,16 @@ static inline int local_dec_and_test(local_t *l)
10753 {
10754 unsigned char c;
10755
10756- asm volatile(_ASM_DEC "%0; sete %1"
10757+ asm volatile(_ASM_DEC "%0\n"
10758+
10759+#ifdef CONFIG_PAX_REFCOUNT
10760+ "jno 0f\n"
10761+ _ASM_INC "%0\n"
10762+ "int $4\n0:\n"
10763+ _ASM_EXTABLE(0b, 0b)
10764+#endif
10765+
10766+ "sete %1\n"
10767 : "+m" (l->a.counter), "=qm" (c)
10768 : : "memory");
10769 return c != 0;
10770@@ -90,7 +140,16 @@ static inline int local_inc_and_test(local_t *l)
10771 {
10772 unsigned char c;
10773
10774- asm volatile(_ASM_INC "%0; sete %1"
10775+ asm volatile(_ASM_INC "%0\n"
10776+
10777+#ifdef CONFIG_PAX_REFCOUNT
10778+ "jno 0f\n"
10779+ _ASM_DEC "%0\n"
10780+ "int $4\n0:\n"
10781+ _ASM_EXTABLE(0b, 0b)
10782+#endif
10783+
10784+ "sete %1\n"
10785 : "+m" (l->a.counter), "=qm" (c)
10786 : : "memory");
10787 return c != 0;
10788@@ -109,7 +168,16 @@ static inline int local_add_negative(long i, local_t *l)
10789 {
10790 unsigned char c;
10791
10792- asm volatile(_ASM_ADD "%2,%0; sets %1"
10793+ asm volatile(_ASM_ADD "%2,%0\n"
10794+
10795+#ifdef CONFIG_PAX_REFCOUNT
10796+ "jno 0f\n"
10797+ _ASM_SUB "%2,%0\n"
10798+ "int $4\n0:\n"
10799+ _ASM_EXTABLE(0b, 0b)
10800+#endif
10801+
10802+ "sets %1\n"
10803 : "+m" (l->a.counter), "=qm" (c)
10804 : "ir" (i) : "memory");
10805 return c;
10806@@ -132,7 +200,15 @@ static inline long local_add_return(long i, local_t *l)
10807 #endif
10808 /* Modern 486+ processor */
10809 __i = i;
10810- asm volatile(_ASM_XADD "%0, %1;"
10811+ asm volatile(_ASM_XADD "%0, %1\n"
10812+
10813+#ifdef CONFIG_PAX_REFCOUNT
10814+ "jno 0f\n"
10815+ _ASM_MOV "%0,%1\n"
10816+ "int $4\n0:\n"
10817+ _ASM_EXTABLE(0b, 0b)
10818+#endif
10819+
10820 : "+r" (i), "+m" (l->a.counter)
10821 : : "memory");
10822 return i + __i;
10823diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10824index 593e51d..fa69c9a 100644
10825--- a/arch/x86/include/asm/mman.h
10826+++ b/arch/x86/include/asm/mman.h
10827@@ -5,4 +5,14 @@
10828
10829 #include <asm-generic/mman.h>
10830
10831+#ifdef __KERNEL__
10832+#ifndef __ASSEMBLY__
10833+#ifdef CONFIG_X86_32
10834+#define arch_mmap_check i386_mmap_check
10835+int i386_mmap_check(unsigned long addr, unsigned long len,
10836+ unsigned long flags);
10837+#endif
10838+#endif
10839+#endif
10840+
10841 #endif /* _ASM_X86_MMAN_H */
10842diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10843index 5f55e69..e20bfb1 100644
10844--- a/arch/x86/include/asm/mmu.h
10845+++ b/arch/x86/include/asm/mmu.h
10846@@ -9,7 +9,7 @@
10847 * we put the segment information here.
10848 */
10849 typedef struct {
10850- void *ldt;
10851+ struct desc_struct *ldt;
10852 int size;
10853
10854 #ifdef CONFIG_X86_64
10855@@ -18,7 +18,19 @@ typedef struct {
10856 #endif
10857
10858 struct mutex lock;
10859- void *vdso;
10860+ unsigned long vdso;
10861+
10862+#ifdef CONFIG_X86_32
10863+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10864+ unsigned long user_cs_base;
10865+ unsigned long user_cs_limit;
10866+
10867+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10868+ cpumask_t cpu_user_cs_mask;
10869+#endif
10870+
10871+#endif
10872+#endif
10873 } mm_context_t;
10874
10875 #ifdef CONFIG_SMP
10876diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10877index cdbf367..adb37ac 100644
10878--- a/arch/x86/include/asm/mmu_context.h
10879+++ b/arch/x86/include/asm/mmu_context.h
10880@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10881
10882 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10883 {
10884+
10885+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10886+ unsigned int i;
10887+ pgd_t *pgd;
10888+
10889+ pax_open_kernel();
10890+ pgd = get_cpu_pgd(smp_processor_id());
10891+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10892+ set_pgd_batched(pgd+i, native_make_pgd(0));
10893+ pax_close_kernel();
10894+#endif
10895+
10896 #ifdef CONFIG_SMP
10897 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10898 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10899@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10900 struct task_struct *tsk)
10901 {
10902 unsigned cpu = smp_processor_id();
10903+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10904+ int tlbstate = TLBSTATE_OK;
10905+#endif
10906
10907 if (likely(prev != next)) {
10908 #ifdef CONFIG_SMP
10909+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10910+ tlbstate = this_cpu_read(cpu_tlbstate.state);
10911+#endif
10912 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10913 this_cpu_write(cpu_tlbstate.active_mm, next);
10914 #endif
10915 cpumask_set_cpu(cpu, mm_cpumask(next));
10916
10917 /* Re-load page tables */
10918+#ifdef CONFIG_PAX_PER_CPU_PGD
10919+ pax_open_kernel();
10920+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
10921+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
10922+ pax_close_kernel();
10923+ load_cr3(get_cpu_pgd(cpu));
10924+#else
10925 load_cr3(next->pgd);
10926+#endif
10927
10928 /* stop flush ipis for the previous mm */
10929 cpumask_clear_cpu(cpu, mm_cpumask(prev));
10930@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10931 */
10932 if (unlikely(prev->context.ldt != next->context.ldt))
10933 load_LDT_nolock(&next->context);
10934- }
10935+
10936+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10937+ if (!(__supported_pte_mask & _PAGE_NX)) {
10938+ smp_mb__before_clear_bit();
10939+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
10940+ smp_mb__after_clear_bit();
10941+ cpu_set(cpu, next->context.cpu_user_cs_mask);
10942+ }
10943+#endif
10944+
10945+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10946+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
10947+ prev->context.user_cs_limit != next->context.user_cs_limit))
10948+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10949 #ifdef CONFIG_SMP
10950+ else if (unlikely(tlbstate != TLBSTATE_OK))
10951+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10952+#endif
10953+#endif
10954+
10955+ }
10956 else {
10957+
10958+#ifdef CONFIG_PAX_PER_CPU_PGD
10959+ pax_open_kernel();
10960+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
10961+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
10962+ pax_close_kernel();
10963+ load_cr3(get_cpu_pgd(cpu));
10964+#endif
10965+
10966+#ifdef CONFIG_SMP
10967 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10968 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
10969
10970@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10971 * tlb flush IPI delivery. We must reload CR3
10972 * to make sure to use no freed page tables.
10973 */
10974+
10975+#ifndef CONFIG_PAX_PER_CPU_PGD
10976 load_cr3(next->pgd);
10977+#endif
10978+
10979 load_LDT_nolock(&next->context);
10980+
10981+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
10982+ if (!(__supported_pte_mask & _PAGE_NX))
10983+ cpu_set(cpu, next->context.cpu_user_cs_mask);
10984+#endif
10985+
10986+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10987+#ifdef CONFIG_PAX_PAGEEXEC
10988+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
10989+#endif
10990+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10991+#endif
10992+
10993 }
10994+#endif
10995 }
10996-#endif
10997 }
10998
10999 #define activate_mm(prev, next) \
11000diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
11001index 9eae775..c914fea 100644
11002--- a/arch/x86/include/asm/module.h
11003+++ b/arch/x86/include/asm/module.h
11004@@ -5,6 +5,7 @@
11005
11006 #ifdef CONFIG_X86_64
11007 /* X86_64 does not define MODULE_PROC_FAMILY */
11008+#define MODULE_PROC_FAMILY ""
11009 #elif defined CONFIG_M386
11010 #define MODULE_PROC_FAMILY "386 "
11011 #elif defined CONFIG_M486
11012@@ -59,8 +60,20 @@
11013 #error unknown processor family
11014 #endif
11015
11016-#ifdef CONFIG_X86_32
11017-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11018+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11019+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11020+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11021+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11022+#else
11023+#define MODULE_PAX_KERNEXEC ""
11024 #endif
11025
11026+#ifdef CONFIG_PAX_MEMORY_UDEREF
11027+#define MODULE_PAX_UDEREF "UDEREF "
11028+#else
11029+#define MODULE_PAX_UDEREF ""
11030+#endif
11031+
11032+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11033+
11034 #endif /* _ASM_X86_MODULE_H */
11035diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11036index 320f7bb..e89f8f8 100644
11037--- a/arch/x86/include/asm/page_64_types.h
11038+++ b/arch/x86/include/asm/page_64_types.h
11039@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11040
11041 /* duplicated to the one in bootmem.h */
11042 extern unsigned long max_pfn;
11043-extern unsigned long phys_base;
11044+extern const unsigned long phys_base;
11045
11046 extern unsigned long __phys_addr(unsigned long);
11047 #define __phys_reloc_hide(x) (x)
11048diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11049index 6cbbabf..11b3aed 100644
11050--- a/arch/x86/include/asm/paravirt.h
11051+++ b/arch/x86/include/asm/paravirt.h
11052@@ -668,6 +668,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11053 val);
11054 }
11055
11056+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11057+{
11058+ pgdval_t val = native_pgd_val(pgd);
11059+
11060+ if (sizeof(pgdval_t) > sizeof(long))
11061+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11062+ val, (u64)val >> 32);
11063+ else
11064+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11065+ val);
11066+}
11067+
11068 static inline void pgd_clear(pgd_t *pgdp)
11069 {
11070 set_pgd(pgdp, __pgd(0));
11071@@ -749,6 +761,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11072 pv_mmu_ops.set_fixmap(idx, phys, flags);
11073 }
11074
11075+#ifdef CONFIG_PAX_KERNEXEC
11076+static inline unsigned long pax_open_kernel(void)
11077+{
11078+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11079+}
11080+
11081+static inline unsigned long pax_close_kernel(void)
11082+{
11083+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11084+}
11085+#else
11086+static inline unsigned long pax_open_kernel(void) { return 0; }
11087+static inline unsigned long pax_close_kernel(void) { return 0; }
11088+#endif
11089+
11090 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11091
11092 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11093@@ -965,7 +992,7 @@ extern void default_banner(void);
11094
11095 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11096 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11097-#define PARA_INDIRECT(addr) *%cs:addr
11098+#define PARA_INDIRECT(addr) *%ss:addr
11099 #endif
11100
11101 #define INTERRUPT_RETURN \
11102@@ -1040,6 +1067,21 @@ extern void default_banner(void);
11103 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11104 CLBR_NONE, \
11105 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11106+
11107+#define GET_CR0_INTO_RDI \
11108+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11109+ mov %rax,%rdi
11110+
11111+#define SET_RDI_INTO_CR0 \
11112+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11113+
11114+#define GET_CR3_INTO_RDI \
11115+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11116+ mov %rax,%rdi
11117+
11118+#define SET_RDI_INTO_CR3 \
11119+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11120+
11121 #endif /* CONFIG_X86_32 */
11122
11123 #endif /* __ASSEMBLY__ */
11124diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11125index 8e8b9a4..f07d725 100644
11126--- a/arch/x86/include/asm/paravirt_types.h
11127+++ b/arch/x86/include/asm/paravirt_types.h
11128@@ -84,20 +84,20 @@ struct pv_init_ops {
11129 */
11130 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11131 unsigned long addr, unsigned len);
11132-};
11133+} __no_const;
11134
11135
11136 struct pv_lazy_ops {
11137 /* Set deferred update mode, used for batching operations. */
11138 void (*enter)(void);
11139 void (*leave)(void);
11140-};
11141+} __no_const;
11142
11143 struct pv_time_ops {
11144 unsigned long long (*sched_clock)(void);
11145 unsigned long long (*steal_clock)(int cpu);
11146 unsigned long (*get_tsc_khz)(void);
11147-};
11148+} __no_const;
11149
11150 struct pv_cpu_ops {
11151 /* hooks for various privileged instructions */
11152@@ -193,7 +193,7 @@ struct pv_cpu_ops {
11153
11154 void (*start_context_switch)(struct task_struct *prev);
11155 void (*end_context_switch)(struct task_struct *next);
11156-};
11157+} __no_const;
11158
11159 struct pv_irq_ops {
11160 /*
11161@@ -224,7 +224,7 @@ struct pv_apic_ops {
11162 unsigned long start_eip,
11163 unsigned long start_esp);
11164 #endif
11165-};
11166+} __no_const;
11167
11168 struct pv_mmu_ops {
11169 unsigned long (*read_cr2)(void);
11170@@ -313,6 +313,7 @@ struct pv_mmu_ops {
11171 struct paravirt_callee_save make_pud;
11172
11173 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11174+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11175 #endif /* PAGETABLE_LEVELS == 4 */
11176 #endif /* PAGETABLE_LEVELS >= 3 */
11177
11178@@ -324,6 +325,12 @@ struct pv_mmu_ops {
11179 an mfn. We can tell which is which from the index. */
11180 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11181 phys_addr_t phys, pgprot_t flags);
11182+
11183+#ifdef CONFIG_PAX_KERNEXEC
11184+ unsigned long (*pax_open_kernel)(void);
11185+ unsigned long (*pax_close_kernel)(void);
11186+#endif
11187+
11188 };
11189
11190 struct arch_spinlock;
11191@@ -334,7 +341,7 @@ struct pv_lock_ops {
11192 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11193 int (*spin_trylock)(struct arch_spinlock *lock);
11194 void (*spin_unlock)(struct arch_spinlock *lock);
11195-};
11196+} __no_const;
11197
11198 /* This contains all the paravirt structures: we get a convenient
11199 * number for each function using the offset which we use to indicate
11200diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11201index b4389a4..7024269 100644
11202--- a/arch/x86/include/asm/pgalloc.h
11203+++ b/arch/x86/include/asm/pgalloc.h
11204@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11205 pmd_t *pmd, pte_t *pte)
11206 {
11207 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11208+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11209+}
11210+
11211+static inline void pmd_populate_user(struct mm_struct *mm,
11212+ pmd_t *pmd, pte_t *pte)
11213+{
11214+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11215 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11216 }
11217
11218@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11219
11220 #ifdef CONFIG_X86_PAE
11221 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11222+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11223+{
11224+ pud_populate(mm, pudp, pmd);
11225+}
11226 #else /* !CONFIG_X86_PAE */
11227 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11228 {
11229 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11230 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11231 }
11232+
11233+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11234+{
11235+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11236+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11237+}
11238 #endif /* CONFIG_X86_PAE */
11239
11240 #if PAGETABLE_LEVELS > 3
11241@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11242 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11243 }
11244
11245+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11246+{
11247+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11248+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11249+}
11250+
11251 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11252 {
11253 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11254diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11255index 98391db..8f6984e 100644
11256--- a/arch/x86/include/asm/pgtable-2level.h
11257+++ b/arch/x86/include/asm/pgtable-2level.h
11258@@ -18,7 +18,9 @@ static inline void native_set_pte(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 *pmdp = pmd;
11264+ pax_close_kernel();
11265 }
11266
11267 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11268diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11269index cb00ccc..17e9054 100644
11270--- a/arch/x86/include/asm/pgtable-3level.h
11271+++ b/arch/x86/include/asm/pgtable-3level.h
11272@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11273
11274 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11275 {
11276+ pax_open_kernel();
11277 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11278+ pax_close_kernel();
11279 }
11280
11281 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11282 {
11283+ pax_open_kernel();
11284 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11285+ pax_close_kernel();
11286 }
11287
11288 /*
11289diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11290index 49afb3f..91a8c63 100644
11291--- a/arch/x86/include/asm/pgtable.h
11292+++ b/arch/x86/include/asm/pgtable.h
11293@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11294
11295 #ifndef __PAGETABLE_PUD_FOLDED
11296 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11297+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11298 #define pgd_clear(pgd) native_pgd_clear(pgd)
11299 #endif
11300
11301@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11302
11303 #define arch_end_context_switch(prev) do {} while(0)
11304
11305+#define pax_open_kernel() native_pax_open_kernel()
11306+#define pax_close_kernel() native_pax_close_kernel()
11307 #endif /* CONFIG_PARAVIRT */
11308
11309+#define __HAVE_ARCH_PAX_OPEN_KERNEL
11310+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11311+
11312+#ifdef CONFIG_PAX_KERNEXEC
11313+static inline unsigned long native_pax_open_kernel(void)
11314+{
11315+ unsigned long cr0;
11316+
11317+ preempt_disable();
11318+ barrier();
11319+ cr0 = read_cr0() ^ X86_CR0_WP;
11320+ BUG_ON(unlikely(cr0 & X86_CR0_WP));
11321+ write_cr0(cr0);
11322+ return cr0 ^ X86_CR0_WP;
11323+}
11324+
11325+static inline unsigned long native_pax_close_kernel(void)
11326+{
11327+ unsigned long cr0;
11328+
11329+ cr0 = read_cr0() ^ X86_CR0_WP;
11330+ BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11331+ write_cr0(cr0);
11332+ barrier();
11333+ preempt_enable_no_resched();
11334+ return cr0 ^ X86_CR0_WP;
11335+}
11336+#else
11337+static inline unsigned long native_pax_open_kernel(void) { return 0; }
11338+static inline unsigned long native_pax_close_kernel(void) { return 0; }
11339+#endif
11340+
11341 /*
11342 * The following only work if pte_present() is true.
11343 * Undefined behaviour if not..
11344 */
11345+static inline int pte_user(pte_t pte)
11346+{
11347+ return pte_val(pte) & _PAGE_USER;
11348+}
11349+
11350 static inline int pte_dirty(pte_t pte)
11351 {
11352 return pte_flags(pte) & _PAGE_DIRTY;
11353@@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11354 return pte_clear_flags(pte, _PAGE_RW);
11355 }
11356
11357+static inline pte_t pte_mkread(pte_t pte)
11358+{
11359+ return __pte(pte_val(pte) | _PAGE_USER);
11360+}
11361+
11362 static inline pte_t pte_mkexec(pte_t pte)
11363 {
11364- return pte_clear_flags(pte, _PAGE_NX);
11365+#ifdef CONFIG_X86_PAE
11366+ if (__supported_pte_mask & _PAGE_NX)
11367+ return pte_clear_flags(pte, _PAGE_NX);
11368+ else
11369+#endif
11370+ return pte_set_flags(pte, _PAGE_USER);
11371+}
11372+
11373+static inline pte_t pte_exprotect(pte_t pte)
11374+{
11375+#ifdef CONFIG_X86_PAE
11376+ if (__supported_pte_mask & _PAGE_NX)
11377+ return pte_set_flags(pte, _PAGE_NX);
11378+ else
11379+#endif
11380+ return pte_clear_flags(pte, _PAGE_USER);
11381 }
11382
11383 static inline pte_t pte_mkdirty(pte_t pte)
11384@@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11385 #endif
11386
11387 #ifndef __ASSEMBLY__
11388+
11389+#ifdef CONFIG_PAX_PER_CPU_PGD
11390+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11391+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11392+{
11393+ return cpu_pgd[cpu];
11394+}
11395+#endif
11396+
11397 #include <linux/mm_types.h>
11398
11399 static inline int pte_none(pte_t pte)
11400@@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11401
11402 static inline int pgd_bad(pgd_t pgd)
11403 {
11404- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11405+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11406 }
11407
11408 static inline int pgd_none(pgd_t pgd)
11409@@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
11410 * pgd_offset() returns a (pgd_t *)
11411 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11412 */
11413-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11414+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11415+
11416+#ifdef CONFIG_PAX_PER_CPU_PGD
11417+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11418+#endif
11419+
11420 /*
11421 * a shortcut which implies the use of the kernel's pgd, instead
11422 * of a process's
11423@@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
11424 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11425 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11426
11427+#ifdef CONFIG_X86_32
11428+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11429+#else
11430+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11431+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11432+
11433+#ifdef CONFIG_PAX_MEMORY_UDEREF
11434+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11435+#else
11436+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11437+#endif
11438+
11439+#endif
11440+
11441 #ifndef __ASSEMBLY__
11442
11443 extern int direct_gbpages;
11444@@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11445 * dst and src can be on the same page, but the range must not overlap,
11446 * and must not cross a page boundary.
11447 */
11448-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11449+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11450 {
11451- memcpy(dst, src, count * sizeof(pgd_t));
11452+ pax_open_kernel();
11453+ while (count--)
11454+ *dst++ = *src++;
11455+ pax_close_kernel();
11456 }
11457
11458+#ifdef CONFIG_PAX_PER_CPU_PGD
11459+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11460+#endif
11461+
11462+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11463+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11464+#else
11465+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11466+#endif
11467
11468 #include <asm-generic/pgtable.h>
11469 #endif /* __ASSEMBLY__ */
11470diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11471index 0c92113..34a77c6 100644
11472--- a/arch/x86/include/asm/pgtable_32.h
11473+++ b/arch/x86/include/asm/pgtable_32.h
11474@@ -25,9 +25,6 @@
11475 struct mm_struct;
11476 struct vm_area_struct;
11477
11478-extern pgd_t swapper_pg_dir[1024];
11479-extern pgd_t initial_page_table[1024];
11480-
11481 static inline void pgtable_cache_init(void) { }
11482 static inline void check_pgt_cache(void) { }
11483 void paging_init(void);
11484@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11485 # include <asm/pgtable-2level.h>
11486 #endif
11487
11488+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11489+extern pgd_t initial_page_table[PTRS_PER_PGD];
11490+#ifdef CONFIG_X86_PAE
11491+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11492+#endif
11493+
11494 #if defined(CONFIG_HIGHPTE)
11495 #define pte_offset_map(dir, address) \
11496 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11497@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11498 /* Clear a kernel PTE and flush it from the TLB */
11499 #define kpte_clear_flush(ptep, vaddr) \
11500 do { \
11501+ pax_open_kernel(); \
11502 pte_clear(&init_mm, (vaddr), (ptep)); \
11503+ pax_close_kernel(); \
11504 __flush_tlb_one((vaddr)); \
11505 } while (0)
11506
11507@@ -74,6 +79,9 @@ do { \
11508
11509 #endif /* !__ASSEMBLY__ */
11510
11511+#define HAVE_ARCH_UNMAPPED_AREA
11512+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11513+
11514 /*
11515 * kern_addr_valid() is (1) for FLATMEM and (0) for
11516 * SPARSEMEM and DISCONTIGMEM
11517diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11518index ed5903b..c7fe163 100644
11519--- a/arch/x86/include/asm/pgtable_32_types.h
11520+++ b/arch/x86/include/asm/pgtable_32_types.h
11521@@ -8,7 +8,7 @@
11522 */
11523 #ifdef CONFIG_X86_PAE
11524 # include <asm/pgtable-3level_types.h>
11525-# define PMD_SIZE (1UL << PMD_SHIFT)
11526+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11527 # define PMD_MASK (~(PMD_SIZE - 1))
11528 #else
11529 # include <asm/pgtable-2level_types.h>
11530@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11531 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11532 #endif
11533
11534+#ifdef CONFIG_PAX_KERNEXEC
11535+#ifndef __ASSEMBLY__
11536+extern unsigned char MODULES_EXEC_VADDR[];
11537+extern unsigned char MODULES_EXEC_END[];
11538+#endif
11539+#include <asm/boot.h>
11540+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11541+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11542+#else
11543+#define ktla_ktva(addr) (addr)
11544+#define ktva_ktla(addr) (addr)
11545+#endif
11546+
11547 #define MODULES_VADDR VMALLOC_START
11548 #define MODULES_END VMALLOC_END
11549 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11550diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11551index 975f709..9f779c9 100644
11552--- a/arch/x86/include/asm/pgtable_64.h
11553+++ b/arch/x86/include/asm/pgtable_64.h
11554@@ -16,10 +16,14 @@
11555
11556 extern pud_t level3_kernel_pgt[512];
11557 extern pud_t level3_ident_pgt[512];
11558+extern pud_t level3_vmalloc_start_pgt[512];
11559+extern pud_t level3_vmalloc_end_pgt[512];
11560+extern pud_t level3_vmemmap_pgt[512];
11561+extern pud_t level2_vmemmap_pgt[512];
11562 extern pmd_t level2_kernel_pgt[512];
11563 extern pmd_t level2_fixmap_pgt[512];
11564-extern pmd_t level2_ident_pgt[512];
11565-extern pgd_t init_level4_pgt[];
11566+extern pmd_t level2_ident_pgt[512*2];
11567+extern pgd_t init_level4_pgt[512];
11568
11569 #define swapper_pg_dir init_level4_pgt
11570
11571@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11572
11573 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11574 {
11575+ pax_open_kernel();
11576 *pmdp = pmd;
11577+ pax_close_kernel();
11578 }
11579
11580 static inline void native_pmd_clear(pmd_t *pmd)
11581@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11582
11583 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11584 {
11585+ pax_open_kernel();
11586 *pudp = pud;
11587+ pax_close_kernel();
11588 }
11589
11590 static inline void native_pud_clear(pud_t *pud)
11591@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11592
11593 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11594 {
11595+ pax_open_kernel();
11596+ *pgdp = pgd;
11597+ pax_close_kernel();
11598+}
11599+
11600+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11601+{
11602 *pgdp = pgd;
11603 }
11604
11605diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11606index 766ea16..5b96cb3 100644
11607--- a/arch/x86/include/asm/pgtable_64_types.h
11608+++ b/arch/x86/include/asm/pgtable_64_types.h
11609@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11610 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11611 #define MODULES_END _AC(0xffffffffff000000, UL)
11612 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11613+#define MODULES_EXEC_VADDR MODULES_VADDR
11614+#define MODULES_EXEC_END MODULES_END
11615+
11616+#define ktla_ktva(addr) (addr)
11617+#define ktva_ktla(addr) (addr)
11618
11619 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11620diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11621index 013286a..8b42f4f 100644
11622--- a/arch/x86/include/asm/pgtable_types.h
11623+++ b/arch/x86/include/asm/pgtable_types.h
11624@@ -16,13 +16,12 @@
11625 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11626 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11627 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11628-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11629+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11630 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11631 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11632 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11633-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11634-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11635-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11636+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11637+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11638 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11639
11640 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11641@@ -40,7 +39,6 @@
11642 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11643 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11644 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11645-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11646 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11647 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11648 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11649@@ -57,8 +55,10 @@
11650
11651 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11652 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11653-#else
11654+#elif defined(CONFIG_KMEMCHECK)
11655 #define _PAGE_NX (_AT(pteval_t, 0))
11656+#else
11657+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11658 #endif
11659
11660 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11661@@ -96,6 +96,9 @@
11662 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11663 _PAGE_ACCESSED)
11664
11665+#define PAGE_READONLY_NOEXEC PAGE_READONLY
11666+#define PAGE_SHARED_NOEXEC PAGE_SHARED
11667+
11668 #define __PAGE_KERNEL_EXEC \
11669 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11670 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11671@@ -106,7 +109,7 @@
11672 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11673 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11674 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11675-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11676+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11677 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11678 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11679 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11680@@ -168,8 +171,8 @@
11681 * bits are combined, this will alow user to access the high address mapped
11682 * VDSO in the presence of CONFIG_COMPAT_VDSO
11683 */
11684-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11685-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11686+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11687+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11688 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11689 #endif
11690
11691@@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11692 {
11693 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11694 }
11695+#endif
11696
11697+#if PAGETABLE_LEVELS == 3
11698+#include <asm-generic/pgtable-nopud.h>
11699+#endif
11700+
11701+#if PAGETABLE_LEVELS == 2
11702+#include <asm-generic/pgtable-nopmd.h>
11703+#endif
11704+
11705+#ifndef __ASSEMBLY__
11706 #if PAGETABLE_LEVELS > 3
11707 typedef struct { pudval_t pud; } pud_t;
11708
11709@@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11710 return pud.pud;
11711 }
11712 #else
11713-#include <asm-generic/pgtable-nopud.h>
11714-
11715 static inline pudval_t native_pud_val(pud_t pud)
11716 {
11717 return native_pgd_val(pud.pgd);
11718@@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11719 return pmd.pmd;
11720 }
11721 #else
11722-#include <asm-generic/pgtable-nopmd.h>
11723-
11724 static inline pmdval_t native_pmd_val(pmd_t pmd)
11725 {
11726 return native_pgd_val(pmd.pud.pgd);
11727@@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11728
11729 extern pteval_t __supported_pte_mask;
11730 extern void set_nx(void);
11731-extern int nx_enabled;
11732
11733 #define pgprot_writecombine pgprot_writecombine
11734 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11735diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11736index 39bc577..538233f 100644
11737--- a/arch/x86/include/asm/processor.h
11738+++ b/arch/x86/include/asm/processor.h
11739@@ -276,7 +276,7 @@ struct tss_struct {
11740
11741 } ____cacheline_aligned;
11742
11743-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11744+extern struct tss_struct init_tss[NR_CPUS];
11745
11746 /*
11747 * Save the original ist values for checking stack pointers during debugging
11748@@ -809,11 +809,18 @@ static inline void spin_lock_prefetch(const void *x)
11749 */
11750 #define TASK_SIZE PAGE_OFFSET
11751 #define TASK_SIZE_MAX TASK_SIZE
11752+
11753+#ifdef CONFIG_PAX_SEGMEXEC
11754+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11755+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11756+#else
11757 #define STACK_TOP TASK_SIZE
11758-#define STACK_TOP_MAX STACK_TOP
11759+#endif
11760+
11761+#define STACK_TOP_MAX TASK_SIZE
11762
11763 #define INIT_THREAD { \
11764- .sp0 = sizeof(init_stack) + (long)&init_stack, \
11765+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11766 .vm86_info = NULL, \
11767 .sysenter_cs = __KERNEL_CS, \
11768 .io_bitmap_ptr = NULL, \
11769@@ -827,7 +834,7 @@ static inline void spin_lock_prefetch(const void *x)
11770 */
11771 #define INIT_TSS { \
11772 .x86_tss = { \
11773- .sp0 = sizeof(init_stack) + (long)&init_stack, \
11774+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11775 .ss0 = __KERNEL_DS, \
11776 .ss1 = __KERNEL_CS, \
11777 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11778@@ -838,11 +845,7 @@ static inline void spin_lock_prefetch(const void *x)
11779 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11780
11781 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11782-#define KSTK_TOP(info) \
11783-({ \
11784- unsigned long *__ptr = (unsigned long *)(info); \
11785- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11786-})
11787+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11788
11789 /*
11790 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11791@@ -857,7 +860,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11792 #define task_pt_regs(task) \
11793 ({ \
11794 struct pt_regs *__regs__; \
11795- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11796+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11797 __regs__ - 1; \
11798 })
11799
11800@@ -867,13 +870,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11801 /*
11802 * User space process size. 47bits minus one guard page.
11803 */
11804-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11805+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11806
11807 /* This decides where the kernel will search for a free chunk of vm
11808 * space during mmap's.
11809 */
11810 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11811- 0xc0000000 : 0xFFFFe000)
11812+ 0xc0000000 : 0xFFFFf000)
11813
11814 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
11815 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11816@@ -884,11 +887,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11817 #define STACK_TOP_MAX TASK_SIZE_MAX
11818
11819 #define INIT_THREAD { \
11820- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11821+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11822 }
11823
11824 #define INIT_TSS { \
11825- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11826+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11827 }
11828
11829 /*
11830@@ -916,6 +919,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11831 */
11832 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11833
11834+#ifdef CONFIG_PAX_SEGMEXEC
11835+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11836+#endif
11837+
11838 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11839
11840 /* Get/set a process' ability to use the timestamp counter instruction */
11841@@ -976,12 +983,12 @@ extern bool cpu_has_amd_erratum(const int *);
11842 #define cpu_has_amd_erratum(x) (false)
11843 #endif /* CONFIG_CPU_SUP_AMD */
11844
11845-extern unsigned long arch_align_stack(unsigned long sp);
11846+#define arch_align_stack(x) ((x) & ~0xfUL)
11847 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11848
11849 void default_idle(void);
11850 bool set_pm_idle_to_default(void);
11851
11852-void stop_this_cpu(void *dummy);
11853+void stop_this_cpu(void *dummy) __noreturn;
11854
11855 #endif /* _ASM_X86_PROCESSOR_H */
11856diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11857index dcfde52..dbfea06 100644
11858--- a/arch/x86/include/asm/ptrace.h
11859+++ b/arch/x86/include/asm/ptrace.h
11860@@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11861 }
11862
11863 /*
11864- * user_mode_vm(regs) determines whether a register set came from user mode.
11865+ * user_mode(regs) determines whether a register set came from user mode.
11866 * This is true if V8086 mode was enabled OR if the register set was from
11867 * protected mode with RPL-3 CS value. This tricky test checks that with
11868 * one comparison. Many places in the kernel can bypass this full check
11869- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11870+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11871+ * be used.
11872 */
11873-static inline int user_mode(struct pt_regs *regs)
11874+static inline int user_mode_novm(struct pt_regs *regs)
11875 {
11876 #ifdef CONFIG_X86_32
11877 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11878 #else
11879- return !!(regs->cs & 3);
11880+ return !!(regs->cs & SEGMENT_RPL_MASK);
11881 #endif
11882 }
11883
11884-static inline int user_mode_vm(struct pt_regs *regs)
11885+static inline int user_mode(struct pt_regs *regs)
11886 {
11887 #ifdef CONFIG_X86_32
11888 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11889 USER_RPL;
11890 #else
11891- return user_mode(regs);
11892+ return user_mode_novm(regs);
11893 #endif
11894 }
11895
11896@@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
11897 #ifdef CONFIG_X86_64
11898 static inline bool user_64bit_mode(struct pt_regs *regs)
11899 {
11900+ unsigned long cs = regs->cs & 0xffff;
11901 #ifndef CONFIG_PARAVIRT
11902 /*
11903 * On non-paravirt systems, this is the only long mode CPL 3
11904 * selector. We do not allow long mode selectors in the LDT.
11905 */
11906- return regs->cs == __USER_CS;
11907+ return cs == __USER_CS;
11908 #else
11909 /* Headers are too twisted for this to go in paravirt.h. */
11910- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
11911+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
11912 #endif
11913 }
11914 #endif
11915diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
11916index fce3f4a..3f69f2a 100644
11917--- a/arch/x86/include/asm/realmode.h
11918+++ b/arch/x86/include/asm/realmode.h
11919@@ -30,7 +30,7 @@ struct real_mode_header {
11920 struct trampoline_header {
11921 #ifdef CONFIG_X86_32
11922 u32 start;
11923- u16 gdt_pad;
11924+ u16 boot_cs;
11925 u16 gdt_limit;
11926 u32 gdt_base;
11927 #else
11928diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
11929index 92f29706..a79cbbb 100644
11930--- a/arch/x86/include/asm/reboot.h
11931+++ b/arch/x86/include/asm/reboot.h
11932@@ -6,19 +6,19 @@
11933 struct pt_regs;
11934
11935 struct machine_ops {
11936- void (*restart)(char *cmd);
11937- void (*halt)(void);
11938- void (*power_off)(void);
11939+ void (* __noreturn restart)(char *cmd);
11940+ void (* __noreturn halt)(void);
11941+ void (* __noreturn power_off)(void);
11942 void (*shutdown)(void);
11943 void (*crash_shutdown)(struct pt_regs *);
11944- void (*emergency_restart)(void);
11945-};
11946+ void (* __noreturn emergency_restart)(void);
11947+} __no_const;
11948
11949 extern struct machine_ops machine_ops;
11950
11951 void native_machine_crash_shutdown(struct pt_regs *regs);
11952 void native_machine_shutdown(void);
11953-void machine_real_restart(unsigned int type);
11954+void machine_real_restart(unsigned int type) __noreturn;
11955 /* These must match dispatch_table in reboot_32.S */
11956 #define MRR_BIOS 0
11957 #define MRR_APM 1
11958diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
11959index 2dbe4a7..ce1db00 100644
11960--- a/arch/x86/include/asm/rwsem.h
11961+++ b/arch/x86/include/asm/rwsem.h
11962@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
11963 {
11964 asm volatile("# beginning down_read\n\t"
11965 LOCK_PREFIX _ASM_INC "(%1)\n\t"
11966+
11967+#ifdef CONFIG_PAX_REFCOUNT
11968+ "jno 0f\n"
11969+ LOCK_PREFIX _ASM_DEC "(%1)\n"
11970+ "int $4\n0:\n"
11971+ _ASM_EXTABLE(0b, 0b)
11972+#endif
11973+
11974 /* adds 0x00000001 */
11975 " jns 1f\n"
11976 " call call_rwsem_down_read_failed\n"
11977@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
11978 "1:\n\t"
11979 " mov %1,%2\n\t"
11980 " add %3,%2\n\t"
11981+
11982+#ifdef CONFIG_PAX_REFCOUNT
11983+ "jno 0f\n"
11984+ "sub %3,%2\n"
11985+ "int $4\n0:\n"
11986+ _ASM_EXTABLE(0b, 0b)
11987+#endif
11988+
11989 " jle 2f\n\t"
11990 LOCK_PREFIX " cmpxchg %2,%0\n\t"
11991 " jnz 1b\n\t"
11992@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
11993 long tmp;
11994 asm volatile("# beginning down_write\n\t"
11995 LOCK_PREFIX " xadd %1,(%2)\n\t"
11996+
11997+#ifdef CONFIG_PAX_REFCOUNT
11998+ "jno 0f\n"
11999+ "mov %1,(%2)\n"
12000+ "int $4\n0:\n"
12001+ _ASM_EXTABLE(0b, 0b)
12002+#endif
12003+
12004 /* adds 0xffff0001, returns the old value */
12005 " test %1,%1\n\t"
12006 /* was the count 0 before? */
12007@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12008 long tmp;
12009 asm volatile("# beginning __up_read\n\t"
12010 LOCK_PREFIX " xadd %1,(%2)\n\t"
12011+
12012+#ifdef CONFIG_PAX_REFCOUNT
12013+ "jno 0f\n"
12014+ "mov %1,(%2)\n"
12015+ "int $4\n0:\n"
12016+ _ASM_EXTABLE(0b, 0b)
12017+#endif
12018+
12019 /* subtracts 1, returns the old value */
12020 " jns 1f\n\t"
12021 " call call_rwsem_wake\n" /* expects old value in %edx */
12022@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12023 long tmp;
12024 asm volatile("# beginning __up_write\n\t"
12025 LOCK_PREFIX " xadd %1,(%2)\n\t"
12026+
12027+#ifdef CONFIG_PAX_REFCOUNT
12028+ "jno 0f\n"
12029+ "mov %1,(%2)\n"
12030+ "int $4\n0:\n"
12031+ _ASM_EXTABLE(0b, 0b)
12032+#endif
12033+
12034 /* subtracts 0xffff0001, returns the old value */
12035 " jns 1f\n\t"
12036 " call call_rwsem_wake\n" /* expects old value in %edx */
12037@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12038 {
12039 asm volatile("# beginning __downgrade_write\n\t"
12040 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12041+
12042+#ifdef CONFIG_PAX_REFCOUNT
12043+ "jno 0f\n"
12044+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12045+ "int $4\n0:\n"
12046+ _ASM_EXTABLE(0b, 0b)
12047+#endif
12048+
12049 /*
12050 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12051 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12052@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12053 */
12054 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12055 {
12056- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12057+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12058+
12059+#ifdef CONFIG_PAX_REFCOUNT
12060+ "jno 0f\n"
12061+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
12062+ "int $4\n0:\n"
12063+ _ASM_EXTABLE(0b, 0b)
12064+#endif
12065+
12066 : "+m" (sem->count)
12067 : "er" (delta));
12068 }
12069@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12070 */
12071 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12072 {
12073- return delta + xadd(&sem->count, delta);
12074+ return delta + xadd_check_overflow(&sem->count, delta);
12075 }
12076
12077 #endif /* __KERNEL__ */
12078diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12079index c48a950..c6d7468 100644
12080--- a/arch/x86/include/asm/segment.h
12081+++ b/arch/x86/include/asm/segment.h
12082@@ -64,10 +64,15 @@
12083 * 26 - ESPFIX small SS
12084 * 27 - per-cpu [ offset to per-cpu data area ]
12085 * 28 - stack_canary-20 [ for stack protector ]
12086- * 29 - unused
12087- * 30 - unused
12088+ * 29 - PCI BIOS CS
12089+ * 30 - PCI BIOS DS
12090 * 31 - TSS for double fault handler
12091 */
12092+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12093+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12094+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12095+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12096+
12097 #define GDT_ENTRY_TLS_MIN 6
12098 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12099
12100@@ -79,6 +84,8 @@
12101
12102 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12103
12104+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12105+
12106 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12107
12108 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12109@@ -104,6 +111,12 @@
12110 #define __KERNEL_STACK_CANARY 0
12111 #endif
12112
12113+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12114+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12115+
12116+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12117+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12118+
12119 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12120
12121 /*
12122@@ -141,7 +154,7 @@
12123 */
12124
12125 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12126-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12127+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12128
12129
12130 #else
12131@@ -165,6 +178,8 @@
12132 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12133 #define __USER32_DS __USER_DS
12134
12135+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12136+
12137 #define GDT_ENTRY_TSS 8 /* needs two entries */
12138 #define GDT_ENTRY_LDT 10 /* needs two entries */
12139 #define GDT_ENTRY_TLS_MIN 12
12140@@ -185,6 +200,7 @@
12141 #endif
12142
12143 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12144+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12145 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12146 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12147 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12148@@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
12149 {
12150 unsigned long __limit;
12151 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12152- return __limit + 1;
12153+ return __limit;
12154 }
12155
12156 #endif /* !__ASSEMBLY__ */
12157diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12158index f483945..64a7851 100644
12159--- a/arch/x86/include/asm/smp.h
12160+++ b/arch/x86/include/asm/smp.h
12161@@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
12162 /* cpus sharing the last level cache: */
12163 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
12164 DECLARE_PER_CPU(u16, cpu_llc_id);
12165-DECLARE_PER_CPU(int, cpu_number);
12166+DECLARE_PER_CPU(unsigned int, cpu_number);
12167
12168 static inline struct cpumask *cpu_sibling_mask(int cpu)
12169 {
12170@@ -79,7 +79,7 @@ struct smp_ops {
12171
12172 void (*send_call_func_ipi)(const struct cpumask *mask);
12173 void (*send_call_func_single_ipi)(int cpu);
12174-};
12175+} __no_const;
12176
12177 /* Globals due to paravirt */
12178 extern void set_cpu_sibling_map(int cpu);
12179@@ -195,14 +195,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12180 extern int safe_smp_processor_id(void);
12181
12182 #elif defined(CONFIG_X86_64_SMP)
12183-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12184-
12185-#define stack_smp_processor_id() \
12186-({ \
12187- struct thread_info *ti; \
12188- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12189- ti->cpu; \
12190-})
12191+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12192+#define stack_smp_processor_id() raw_smp_processor_id()
12193 #define safe_smp_processor_id() smp_processor_id()
12194
12195 #endif
12196diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12197index b315a33..8849ab0 100644
12198--- a/arch/x86/include/asm/spinlock.h
12199+++ b/arch/x86/include/asm/spinlock.h
12200@@ -173,6 +173,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12201 static inline void arch_read_lock(arch_rwlock_t *rw)
12202 {
12203 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12204+
12205+#ifdef CONFIG_PAX_REFCOUNT
12206+ "jno 0f\n"
12207+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12208+ "int $4\n0:\n"
12209+ _ASM_EXTABLE(0b, 0b)
12210+#endif
12211+
12212 "jns 1f\n"
12213 "call __read_lock_failed\n\t"
12214 "1:\n"
12215@@ -182,6 +190,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12216 static inline void arch_write_lock(arch_rwlock_t *rw)
12217 {
12218 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12219+
12220+#ifdef CONFIG_PAX_REFCOUNT
12221+ "jno 0f\n"
12222+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12223+ "int $4\n0:\n"
12224+ _ASM_EXTABLE(0b, 0b)
12225+#endif
12226+
12227 "jz 1f\n"
12228 "call __write_lock_failed\n\t"
12229 "1:\n"
12230@@ -211,13 +227,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12231
12232 static inline void arch_read_unlock(arch_rwlock_t *rw)
12233 {
12234- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12235+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12236+
12237+#ifdef CONFIG_PAX_REFCOUNT
12238+ "jno 0f\n"
12239+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12240+ "int $4\n0:\n"
12241+ _ASM_EXTABLE(0b, 0b)
12242+#endif
12243+
12244 :"+m" (rw->lock) : : "memory");
12245 }
12246
12247 static inline void arch_write_unlock(arch_rwlock_t *rw)
12248 {
12249- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12250+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12251+
12252+#ifdef CONFIG_PAX_REFCOUNT
12253+ "jno 0f\n"
12254+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12255+ "int $4\n0:\n"
12256+ _ASM_EXTABLE(0b, 0b)
12257+#endif
12258+
12259 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12260 }
12261
12262diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12263index 6a99859..03cb807 100644
12264--- a/arch/x86/include/asm/stackprotector.h
12265+++ b/arch/x86/include/asm/stackprotector.h
12266@@ -47,7 +47,7 @@
12267 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12268 */
12269 #define GDT_STACK_CANARY_INIT \
12270- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12271+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12272
12273 /*
12274 * Initialize the stackprotector canary value.
12275@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
12276
12277 static inline void load_stack_canary_segment(void)
12278 {
12279-#ifdef CONFIG_X86_32
12280+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12281 asm volatile ("mov %0, %%gs" : : "r" (0));
12282 #endif
12283 }
12284diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12285index 70bbe39..4ae2bd4 100644
12286--- a/arch/x86/include/asm/stacktrace.h
12287+++ b/arch/x86/include/asm/stacktrace.h
12288@@ -11,28 +11,20 @@
12289
12290 extern int kstack_depth_to_print;
12291
12292-struct thread_info;
12293+struct task_struct;
12294 struct stacktrace_ops;
12295
12296-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12297- unsigned long *stack,
12298- unsigned long bp,
12299- const struct stacktrace_ops *ops,
12300- void *data,
12301- unsigned long *end,
12302- int *graph);
12303+typedef unsigned long walk_stack_t(struct task_struct *task,
12304+ void *stack_start,
12305+ unsigned long *stack,
12306+ unsigned long bp,
12307+ const struct stacktrace_ops *ops,
12308+ void *data,
12309+ unsigned long *end,
12310+ int *graph);
12311
12312-extern unsigned long
12313-print_context_stack(struct thread_info *tinfo,
12314- unsigned long *stack, unsigned long bp,
12315- const struct stacktrace_ops *ops, void *data,
12316- unsigned long *end, int *graph);
12317-
12318-extern unsigned long
12319-print_context_stack_bp(struct thread_info *tinfo,
12320- unsigned long *stack, unsigned long bp,
12321- const struct stacktrace_ops *ops, void *data,
12322- unsigned long *end, int *graph);
12323+extern walk_stack_t print_context_stack;
12324+extern walk_stack_t print_context_stack_bp;
12325
12326 /* Generic stack tracer with callbacks */
12327
12328@@ -40,7 +32,7 @@ struct stacktrace_ops {
12329 void (*address)(void *data, unsigned long address, int reliable);
12330 /* On negative return stop dumping */
12331 int (*stack)(void *data, char *name);
12332- walk_stack_t walk_stack;
12333+ walk_stack_t *walk_stack;
12334 };
12335
12336 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12337diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
12338index 4ec45b3..a4f0a8a 100644
12339--- a/arch/x86/include/asm/switch_to.h
12340+++ b/arch/x86/include/asm/switch_to.h
12341@@ -108,7 +108,7 @@ do { \
12342 "call __switch_to\n\t" \
12343 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12344 __switch_canary \
12345- "movq %P[thread_info](%%rsi),%%r8\n\t" \
12346+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12347 "movq %%rax,%%rdi\n\t" \
12348 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12349 "jnz ret_from_fork\n\t" \
12350@@ -119,7 +119,7 @@ do { \
12351 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12352 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12353 [_tif_fork] "i" (_TIF_FORK), \
12354- [thread_info] "i" (offsetof(struct task_struct, stack)), \
12355+ [thread_info] "m" (current_tinfo), \
12356 [current_task] "m" (current_task) \
12357 __switch_canary_iparam \
12358 : "memory", "cc" __EXTRA_CLOBBER)
12359diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12360index 3fda9db4..4ca1c61 100644
12361--- a/arch/x86/include/asm/sys_ia32.h
12362+++ b/arch/x86/include/asm/sys_ia32.h
12363@@ -40,7 +40,7 @@ asmlinkage long sys32_sigaction(int, struct old_sigaction32 __user *,
12364 struct old_sigaction32 __user *);
12365 asmlinkage long sys32_alarm(unsigned int);
12366
12367-asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12368+asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12369 asmlinkage long sys32_sysfs(int, u32, u32);
12370
12371 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12372diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12373index 89f794f..1422765 100644
12374--- a/arch/x86/include/asm/thread_info.h
12375+++ b/arch/x86/include/asm/thread_info.h
12376@@ -10,6 +10,7 @@
12377 #include <linux/compiler.h>
12378 #include <asm/page.h>
12379 #include <asm/types.h>
12380+#include <asm/percpu.h>
12381
12382 /*
12383 * low level task data that entry.S needs immediate access to
12384@@ -24,7 +25,6 @@ struct exec_domain;
12385 #include <linux/atomic.h>
12386
12387 struct thread_info {
12388- struct task_struct *task; /* main task structure */
12389 struct exec_domain *exec_domain; /* execution domain */
12390 __u32 flags; /* low level flags */
12391 __u32 status; /* thread synchronous flags */
12392@@ -34,19 +34,13 @@ struct thread_info {
12393 mm_segment_t addr_limit;
12394 struct restart_block restart_block;
12395 void __user *sysenter_return;
12396-#ifdef CONFIG_X86_32
12397- unsigned long previous_esp; /* ESP of the previous stack in
12398- case of nested (IRQ) stacks
12399- */
12400- __u8 supervisor_stack[0];
12401-#endif
12402+ unsigned long lowest_stack;
12403 unsigned int sig_on_uaccess_error:1;
12404 unsigned int uaccess_err:1; /* uaccess failed */
12405 };
12406
12407-#define INIT_THREAD_INFO(tsk) \
12408+#define INIT_THREAD_INFO \
12409 { \
12410- .task = &tsk, \
12411 .exec_domain = &default_exec_domain, \
12412 .flags = 0, \
12413 .cpu = 0, \
12414@@ -57,7 +51,7 @@ struct thread_info {
12415 }, \
12416 }
12417
12418-#define init_thread_info (init_thread_union.thread_info)
12419+#define init_thread_info (init_thread_union.stack)
12420 #define init_stack (init_thread_union.stack)
12421
12422 #else /* !__ASSEMBLY__ */
12423@@ -98,6 +92,7 @@ struct thread_info {
12424 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12425 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
12426 #define TIF_X32 30 /* 32-bit native x86-64 binary */
12427+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
12428
12429 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12430 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12431@@ -122,16 +117,18 @@ struct thread_info {
12432 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12433 #define _TIF_ADDR32 (1 << TIF_ADDR32)
12434 #define _TIF_X32 (1 << TIF_X32)
12435+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12436
12437 /* work to do in syscall_trace_enter() */
12438 #define _TIF_WORK_SYSCALL_ENTRY \
12439 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12440- _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12441+ _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
12442+ _TIF_GRSEC_SETXID)
12443
12444 /* work to do in syscall_trace_leave() */
12445 #define _TIF_WORK_SYSCALL_EXIT \
12446 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12447- _TIF_SYSCALL_TRACEPOINT)
12448+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12449
12450 /* work to do on interrupt/exception return */
12451 #define _TIF_WORK_MASK \
12452@@ -141,7 +138,8 @@ struct thread_info {
12453
12454 /* work to do on any return to user space */
12455 #define _TIF_ALLWORK_MASK \
12456- ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12457+ ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12458+ _TIF_GRSEC_SETXID)
12459
12460 /* Only used for 64 bit */
12461 #define _TIF_DO_NOTIFY_MASK \
12462@@ -157,45 +155,40 @@ struct thread_info {
12463
12464 #define PREEMPT_ACTIVE 0x10000000
12465
12466-#ifdef CONFIG_X86_32
12467-
12468-#define STACK_WARN (THREAD_SIZE/8)
12469-/*
12470- * macros/functions for gaining access to the thread information structure
12471- *
12472- * preempt_count needs to be 1 initially, until the scheduler is functional.
12473- */
12474-#ifndef __ASSEMBLY__
12475-
12476-
12477-/* how to get the current stack pointer from C */
12478-register unsigned long current_stack_pointer asm("esp") __used;
12479-
12480-/* how to get the thread information struct from C */
12481-static inline struct thread_info *current_thread_info(void)
12482-{
12483- return (struct thread_info *)
12484- (current_stack_pointer & ~(THREAD_SIZE - 1));
12485-}
12486-
12487-#else /* !__ASSEMBLY__ */
12488-
12489+#ifdef __ASSEMBLY__
12490 /* how to get the thread information struct from ASM */
12491 #define GET_THREAD_INFO(reg) \
12492- movl $-THREAD_SIZE, reg; \
12493- andl %esp, reg
12494+ mov PER_CPU_VAR(current_tinfo), reg
12495
12496 /* use this one if reg already contains %esp */
12497-#define GET_THREAD_INFO_WITH_ESP(reg) \
12498- andl $-THREAD_SIZE, reg
12499+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12500+#else
12501+/* how to get the thread information struct from C */
12502+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12503+
12504+static __always_inline struct thread_info *current_thread_info(void)
12505+{
12506+ return this_cpu_read_stable(current_tinfo);
12507+}
12508+#endif
12509+
12510+#ifdef CONFIG_X86_32
12511+
12512+#define STACK_WARN (THREAD_SIZE/8)
12513+/*
12514+ * macros/functions for gaining access to the thread information structure
12515+ *
12516+ * preempt_count needs to be 1 initially, until the scheduler is functional.
12517+ */
12518+#ifndef __ASSEMBLY__
12519+
12520+/* how to get the current stack pointer from C */
12521+register unsigned long current_stack_pointer asm("esp") __used;
12522
12523 #endif
12524
12525 #else /* X86_32 */
12526
12527-#include <asm/percpu.h>
12528-#define KERNEL_STACK_OFFSET (5*8)
12529-
12530 /*
12531 * macros/functions for gaining access to the thread information structure
12532 * preempt_count needs to be 1 initially, until the scheduler is functional.
12533@@ -203,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
12534 #ifndef __ASSEMBLY__
12535 DECLARE_PER_CPU(unsigned long, kernel_stack);
12536
12537-static inline struct thread_info *current_thread_info(void)
12538-{
12539- struct thread_info *ti;
12540- ti = (void *)(this_cpu_read_stable(kernel_stack) +
12541- KERNEL_STACK_OFFSET - THREAD_SIZE);
12542- return ti;
12543-}
12544-
12545-#else /* !__ASSEMBLY__ */
12546-
12547-/* how to get the thread information struct from ASM */
12548-#define GET_THREAD_INFO(reg) \
12549- movq PER_CPU_VAR(kernel_stack),reg ; \
12550- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12551-
12552-/*
12553- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12554- * a certain register (to be used in assembler memory operands).
12555- */
12556-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12557-
12558+/* how to get the current stack pointer from C */
12559+register unsigned long current_stack_pointer asm("rsp") __used;
12560 #endif
12561
12562 #endif /* !X86_32 */
12563@@ -284,5 +258,12 @@ static inline bool is_ia32_task(void)
12564 extern void arch_task_cache_init(void);
12565 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12566 extern void arch_release_task_struct(struct task_struct *tsk);
12567+
12568+#define __HAVE_THREAD_FUNCTIONS
12569+#define task_thread_info(task) (&(task)->tinfo)
12570+#define task_stack_page(task) ((task)->stack)
12571+#define setup_thread_stack(p, org) do {} while (0)
12572+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12573+
12574 #endif
12575 #endif /* _ASM_X86_THREAD_INFO_H */
12576diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12577index e1f3a17..1ab364d 100644
12578--- a/arch/x86/include/asm/uaccess.h
12579+++ b/arch/x86/include/asm/uaccess.h
12580@@ -7,12 +7,15 @@
12581 #include <linux/compiler.h>
12582 #include <linux/thread_info.h>
12583 #include <linux/string.h>
12584+#include <linux/sched.h>
12585 #include <asm/asm.h>
12586 #include <asm/page.h>
12587
12588 #define VERIFY_READ 0
12589 #define VERIFY_WRITE 1
12590
12591+extern void check_object_size(const void *ptr, unsigned long n, bool to);
12592+
12593 /*
12594 * The fs value determines whether argument validity checking should be
12595 * performed or not. If get_fs() == USER_DS, checking is performed, with
12596@@ -28,7 +31,12 @@
12597
12598 #define get_ds() (KERNEL_DS)
12599 #define get_fs() (current_thread_info()->addr_limit)
12600+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12601+void __set_fs(mm_segment_t x);
12602+void set_fs(mm_segment_t x);
12603+#else
12604 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12605+#endif
12606
12607 #define segment_eq(a, b) ((a).seg == (b).seg)
12608
12609@@ -76,8 +84,33 @@
12610 * checks that the pointer is in the user space range - after calling
12611 * this function, memory access functions may still return -EFAULT.
12612 */
12613-#define access_ok(type, addr, size) \
12614- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12615+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12616+#define access_ok(type, addr, size) \
12617+({ \
12618+ long __size = size; \
12619+ unsigned long __addr = (unsigned long)addr; \
12620+ unsigned long __addr_ao = __addr & PAGE_MASK; \
12621+ unsigned long __end_ao = __addr + __size - 1; \
12622+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
12623+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12624+ while(__addr_ao <= __end_ao) { \
12625+ char __c_ao; \
12626+ __addr_ao += PAGE_SIZE; \
12627+ if (__size > PAGE_SIZE) \
12628+ cond_resched(); \
12629+ if (__get_user(__c_ao, (char __user *)__addr)) \
12630+ break; \
12631+ if (type != VERIFY_WRITE) { \
12632+ __addr = __addr_ao; \
12633+ continue; \
12634+ } \
12635+ if (__put_user(__c_ao, (char __user *)__addr)) \
12636+ break; \
12637+ __addr = __addr_ao; \
12638+ } \
12639+ } \
12640+ __ret_ao; \
12641+})
12642
12643 /*
12644 * The exception table consists of pairs of addresses relative to the
12645@@ -188,12 +221,20 @@ extern int __get_user_bad(void);
12646 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12647 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12648
12649-
12650+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12651+#define __copyuser_seg "gs;"
12652+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12653+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12654+#else
12655+#define __copyuser_seg
12656+#define __COPYUSER_SET_ES
12657+#define __COPYUSER_RESTORE_ES
12658+#endif
12659
12660 #ifdef CONFIG_X86_32
12661 #define __put_user_asm_u64(x, addr, err, errret) \
12662- asm volatile("1: movl %%eax,0(%2)\n" \
12663- "2: movl %%edx,4(%2)\n" \
12664+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12665+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12666 "3:\n" \
12667 ".section .fixup,\"ax\"\n" \
12668 "4: movl %3,%0\n" \
12669@@ -205,8 +246,8 @@ extern int __get_user_bad(void);
12670 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12671
12672 #define __put_user_asm_ex_u64(x, addr) \
12673- asm volatile("1: movl %%eax,0(%1)\n" \
12674- "2: movl %%edx,4(%1)\n" \
12675+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12676+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12677 "3:\n" \
12678 _ASM_EXTABLE_EX(1b, 2b) \
12679 _ASM_EXTABLE_EX(2b, 3b) \
12680@@ -258,7 +299,7 @@ extern void __put_user_8(void);
12681 __typeof__(*(ptr)) __pu_val; \
12682 __chk_user_ptr(ptr); \
12683 might_fault(); \
12684- __pu_val = x; \
12685+ __pu_val = (x); \
12686 switch (sizeof(*(ptr))) { \
12687 case 1: \
12688 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12689@@ -379,7 +420,7 @@ do { \
12690 } while (0)
12691
12692 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12693- asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12694+ asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12695 "2:\n" \
12696 ".section .fixup,\"ax\"\n" \
12697 "3: mov %3,%0\n" \
12698@@ -387,7 +428,7 @@ do { \
12699 " jmp 2b\n" \
12700 ".previous\n" \
12701 _ASM_EXTABLE(1b, 3b) \
12702- : "=r" (err), ltype(x) \
12703+ : "=r" (err), ltype (x) \
12704 : "m" (__m(addr)), "i" (errret), "0" (err))
12705
12706 #define __get_user_size_ex(x, ptr, size) \
12707@@ -412,7 +453,7 @@ do { \
12708 } while (0)
12709
12710 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12711- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12712+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12713 "2:\n" \
12714 _ASM_EXTABLE_EX(1b, 2b) \
12715 : ltype(x) : "m" (__m(addr)))
12716@@ -429,13 +470,24 @@ do { \
12717 int __gu_err; \
12718 unsigned long __gu_val; \
12719 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12720- (x) = (__force __typeof__(*(ptr)))__gu_val; \
12721+ (x) = (__typeof__(*(ptr)))__gu_val; \
12722 __gu_err; \
12723 })
12724
12725 /* FIXME: this hack is definitely wrong -AK */
12726 struct __large_struct { unsigned long buf[100]; };
12727-#define __m(x) (*(struct __large_struct __user *)(x))
12728+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12729+#define ____m(x) \
12730+({ \
12731+ unsigned long ____x = (unsigned long)(x); \
12732+ if (____x < PAX_USER_SHADOW_BASE) \
12733+ ____x += PAX_USER_SHADOW_BASE; \
12734+ (void __user *)____x; \
12735+})
12736+#else
12737+#define ____m(x) (x)
12738+#endif
12739+#define __m(x) (*(struct __large_struct __user *)____m(x))
12740
12741 /*
12742 * Tell gcc we read from memory instead of writing: this is because
12743@@ -443,7 +495,7 @@ struct __large_struct { unsigned long buf[100]; };
12744 * aliasing issues.
12745 */
12746 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12747- asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12748+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12749 "2:\n" \
12750 ".section .fixup,\"ax\"\n" \
12751 "3: mov %3,%0\n" \
12752@@ -451,10 +503,10 @@ struct __large_struct { unsigned long buf[100]; };
12753 ".previous\n" \
12754 _ASM_EXTABLE(1b, 3b) \
12755 : "=r"(err) \
12756- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12757+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12758
12759 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12760- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12761+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12762 "2:\n" \
12763 _ASM_EXTABLE_EX(1b, 2b) \
12764 : : ltype(x), "m" (__m(addr)))
12765@@ -493,8 +545,12 @@ struct __large_struct { unsigned long buf[100]; };
12766 * On error, the variable @x is set to zero.
12767 */
12768
12769+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12770+#define __get_user(x, ptr) get_user((x), (ptr))
12771+#else
12772 #define __get_user(x, ptr) \
12773 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12774+#endif
12775
12776 /**
12777 * __put_user: - Write a simple value into user space, with less checking.
12778@@ -516,8 +572,12 @@ struct __large_struct { unsigned long buf[100]; };
12779 * Returns zero on success, or -EFAULT on error.
12780 */
12781
12782+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12783+#define __put_user(x, ptr) put_user((x), (ptr))
12784+#else
12785 #define __put_user(x, ptr) \
12786 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12787+#endif
12788
12789 #define __get_user_unaligned __get_user
12790 #define __put_user_unaligned __put_user
12791@@ -535,7 +595,7 @@ struct __large_struct { unsigned long buf[100]; };
12792 #define get_user_ex(x, ptr) do { \
12793 unsigned long __gue_val; \
12794 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12795- (x) = (__force __typeof__(*(ptr)))__gue_val; \
12796+ (x) = (__typeof__(*(ptr)))__gue_val; \
12797 } while (0)
12798
12799 #ifdef CONFIG_X86_WP_WORKS_OK
12800diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12801index 576e39b..ccd0a39 100644
12802--- a/arch/x86/include/asm/uaccess_32.h
12803+++ b/arch/x86/include/asm/uaccess_32.h
12804@@ -11,15 +11,15 @@
12805 #include <asm/page.h>
12806
12807 unsigned long __must_check __copy_to_user_ll
12808- (void __user *to, const void *from, unsigned long n);
12809+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12810 unsigned long __must_check __copy_from_user_ll
12811- (void *to, const void __user *from, unsigned long n);
12812+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12813 unsigned long __must_check __copy_from_user_ll_nozero
12814- (void *to, const void __user *from, unsigned long n);
12815+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12816 unsigned long __must_check __copy_from_user_ll_nocache
12817- (void *to, const void __user *from, unsigned long n);
12818+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12819 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12820- (void *to, const void __user *from, unsigned long n);
12821+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12822
12823 /**
12824 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12825@@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12826 static __always_inline unsigned long __must_check
12827 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12828 {
12829+ if ((long)n < 0)
12830+ return n;
12831+
12832 if (__builtin_constant_p(n)) {
12833 unsigned long ret;
12834
12835@@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12836 return ret;
12837 }
12838 }
12839+ if (!__builtin_constant_p(n))
12840+ check_object_size(from, n, true);
12841 return __copy_to_user_ll(to, from, n);
12842 }
12843
12844@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
12845 __copy_to_user(void __user *to, const void *from, unsigned long n)
12846 {
12847 might_fault();
12848+
12849 return __copy_to_user_inatomic(to, from, n);
12850 }
12851
12852 static __always_inline unsigned long
12853 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12854 {
12855+ if ((long)n < 0)
12856+ return n;
12857+
12858 /* Avoid zeroing the tail if the copy fails..
12859 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12860 * but as the zeroing behaviour is only significant when n is not
12861@@ -137,6 +146,10 @@ static __always_inline unsigned long
12862 __copy_from_user(void *to, const void __user *from, unsigned long n)
12863 {
12864 might_fault();
12865+
12866+ if ((long)n < 0)
12867+ return n;
12868+
12869 if (__builtin_constant_p(n)) {
12870 unsigned long ret;
12871
12872@@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12873 return ret;
12874 }
12875 }
12876+ if (!__builtin_constant_p(n))
12877+ check_object_size(to, n, false);
12878 return __copy_from_user_ll(to, from, n);
12879 }
12880
12881@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12882 const void __user *from, unsigned long n)
12883 {
12884 might_fault();
12885+
12886+ if ((long)n < 0)
12887+ return n;
12888+
12889 if (__builtin_constant_p(n)) {
12890 unsigned long ret;
12891
12892@@ -181,15 +200,19 @@ static __always_inline unsigned long
12893 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
12894 unsigned long n)
12895 {
12896- return __copy_from_user_ll_nocache_nozero(to, from, n);
12897+ if ((long)n < 0)
12898+ return n;
12899+
12900+ return __copy_from_user_ll_nocache_nozero(to, from, n);
12901 }
12902
12903-unsigned long __must_check copy_to_user(void __user *to,
12904- const void *from, unsigned long n);
12905-unsigned long __must_check _copy_from_user(void *to,
12906- const void __user *from,
12907- unsigned long n);
12908-
12909+extern void copy_to_user_overflow(void)
12910+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12911+ __compiletime_error("copy_to_user() buffer size is not provably correct")
12912+#else
12913+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
12914+#endif
12915+;
12916
12917 extern void copy_from_user_overflow(void)
12918 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12919@@ -199,21 +222,65 @@ extern void copy_from_user_overflow(void)
12920 #endif
12921 ;
12922
12923-static inline unsigned long __must_check copy_from_user(void *to,
12924- const void __user *from,
12925- unsigned long n)
12926+/**
12927+ * copy_to_user: - Copy a block of data into user space.
12928+ * @to: Destination address, in user space.
12929+ * @from: Source address, in kernel space.
12930+ * @n: Number of bytes to copy.
12931+ *
12932+ * Context: User context only. This function may sleep.
12933+ *
12934+ * Copy data from kernel space to user space.
12935+ *
12936+ * Returns number of bytes that could not be copied.
12937+ * On success, this will be zero.
12938+ */
12939+static inline unsigned long __must_check
12940+copy_to_user(void __user *to, const void *from, unsigned long n)
12941 {
12942- int sz = __compiletime_object_size(to);
12943+ size_t sz = __compiletime_object_size(from);
12944
12945- if (likely(sz == -1 || sz >= n))
12946- n = _copy_from_user(to, from, n);
12947- else
12948+ if (unlikely(sz != (size_t)-1 && sz < n))
12949+ copy_to_user_overflow();
12950+ else if (access_ok(VERIFY_WRITE, to, n))
12951+ n = __copy_to_user(to, from, n);
12952+ return n;
12953+}
12954+
12955+/**
12956+ * copy_from_user: - Copy a block of data from user space.
12957+ * @to: Destination address, in kernel space.
12958+ * @from: Source address, in user space.
12959+ * @n: Number of bytes to copy.
12960+ *
12961+ * Context: User context only. This function may sleep.
12962+ *
12963+ * Copy data from user space to kernel space.
12964+ *
12965+ * Returns number of bytes that could not be copied.
12966+ * On success, this will be zero.
12967+ *
12968+ * If some data could not be copied, this function will pad the copied
12969+ * data to the requested size using zero bytes.
12970+ */
12971+static inline unsigned long __must_check
12972+copy_from_user(void *to, const void __user *from, unsigned long n)
12973+{
12974+ size_t sz = __compiletime_object_size(to);
12975+
12976+ if (unlikely(sz != (size_t)-1 && sz < n))
12977 copy_from_user_overflow();
12978-
12979+ else if (access_ok(VERIFY_READ, from, n))
12980+ n = __copy_from_user(to, from, n);
12981+ else if ((long)n > 0) {
12982+ if (!__builtin_constant_p(n))
12983+ check_object_size(to, n, false);
12984+ memset(to, 0, n);
12985+ }
12986 return n;
12987 }
12988
12989-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
12990-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
12991+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12992+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12993
12994 #endif /* _ASM_X86_UACCESS_32_H */
12995diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
12996index 8e796fb..72fd934 100644
12997--- a/arch/x86/include/asm/uaccess_64.h
12998+++ b/arch/x86/include/asm/uaccess_64.h
12999@@ -10,6 +10,9 @@
13000 #include <asm/alternative.h>
13001 #include <asm/cpufeature.h>
13002 #include <asm/page.h>
13003+#include <asm/pgtable.h>
13004+
13005+#define set_fs(x) (current_thread_info()->addr_limit = (x))
13006
13007 /*
13008 * Copy To/From Userspace
13009@@ -17,12 +20,14 @@
13010
13011 /* Handles exceptions in both to and from, but doesn't do access_ok */
13012 __must_check unsigned long
13013-copy_user_generic_string(void *to, const void *from, unsigned len);
13014+copy_user_generic_string(void *to, const void *from, unsigned long len) __size_overflow(3);
13015 __must_check unsigned long
13016-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13017+copy_user_generic_unrolled(void *to, const void *from, unsigned long len) __size_overflow(3);
13018
13019 static __always_inline __must_check unsigned long
13020-copy_user_generic(void *to, const void *from, unsigned len)
13021+copy_user_generic(void *to, const void *from, unsigned long len) __size_overflow(3);
13022+static __always_inline __must_check unsigned long
13023+copy_user_generic(void *to, const void *from, unsigned long len)
13024 {
13025 unsigned ret;
13026
13027@@ -32,142 +37,238 @@ copy_user_generic(void *to, const void *from, unsigned len)
13028 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13029 "=d" (len)),
13030 "1" (to), "2" (from), "3" (len)
13031- : "memory", "rcx", "r8", "r9", "r10", "r11");
13032+ : "memory", "rcx", "r8", "r9", "r11");
13033 return ret;
13034 }
13035
13036+static __always_inline __must_check unsigned long
13037+__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13038+static __always_inline __must_check unsigned long
13039+__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13040 __must_check unsigned long
13041-_copy_to_user(void __user *to, const void *from, unsigned len);
13042-__must_check unsigned long
13043-_copy_from_user(void *to, const void __user *from, unsigned len);
13044-__must_check unsigned long
13045-copy_in_user(void __user *to, const void __user *from, unsigned len);
13046+copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13047+
13048+extern void copy_to_user_overflow(void)
13049+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13050+ __compiletime_error("copy_to_user() buffer size is not provably correct")
13051+#else
13052+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
13053+#endif
13054+;
13055+
13056+extern void copy_from_user_overflow(void)
13057+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13058+ __compiletime_error("copy_from_user() buffer size is not provably correct")
13059+#else
13060+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
13061+#endif
13062+;
13063
13064 static inline unsigned long __must_check copy_from_user(void *to,
13065 const void __user *from,
13066 unsigned long n)
13067 {
13068- int sz = __compiletime_object_size(to);
13069-
13070 might_fault();
13071- if (likely(sz == -1 || sz >= n))
13072- n = _copy_from_user(to, from, n);
13073-#ifdef CONFIG_DEBUG_VM
13074- else
13075- WARN(1, "Buffer overflow detected!\n");
13076-#endif
13077+
13078+ if (access_ok(VERIFY_READ, from, n))
13079+ n = __copy_from_user(to, from, n);
13080+ else if (n < INT_MAX) {
13081+ if (!__builtin_constant_p(n))
13082+ check_object_size(to, n, false);
13083+ memset(to, 0, n);
13084+ }
13085 return n;
13086 }
13087
13088 static __always_inline __must_check
13089-int copy_to_user(void __user *dst, const void *src, unsigned size)
13090+int copy_to_user(void __user *dst, const void *src, unsigned long size)
13091 {
13092 might_fault();
13093
13094- return _copy_to_user(dst, src, size);
13095+ if (access_ok(VERIFY_WRITE, dst, size))
13096+ size = __copy_to_user(dst, src, size);
13097+ return size;
13098 }
13099
13100 static __always_inline __must_check
13101-int __copy_from_user(void *dst, const void __user *src, unsigned size)
13102+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13103 {
13104- int ret = 0;
13105+ size_t sz = __compiletime_object_size(dst);
13106+ unsigned ret = 0;
13107
13108 might_fault();
13109- if (!__builtin_constant_p(size))
13110- return copy_user_generic(dst, (__force void *)src, size);
13111+
13112+ if (size > INT_MAX)
13113+ return size;
13114+
13115+#ifdef CONFIG_PAX_MEMORY_UDEREF
13116+ if (!__access_ok(VERIFY_READ, src, size))
13117+ return size;
13118+#endif
13119+
13120+ if (unlikely(sz != (size_t)-1 && sz < size)) {
13121+ copy_from_user_overflow();
13122+ return size;
13123+ }
13124+
13125+ if (!__builtin_constant_p(size)) {
13126+ check_object_size(dst, size, false);
13127+
13128+#ifdef CONFIG_PAX_MEMORY_UDEREF
13129+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13130+ src += PAX_USER_SHADOW_BASE;
13131+#endif
13132+
13133+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13134+ }
13135 switch (size) {
13136- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13137+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13138 ret, "b", "b", "=q", 1);
13139 return ret;
13140- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13141+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13142 ret, "w", "w", "=r", 2);
13143 return ret;
13144- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13145+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13146 ret, "l", "k", "=r", 4);
13147 return ret;
13148- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13149+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13150 ret, "q", "", "=r", 8);
13151 return ret;
13152 case 10:
13153- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13154+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13155 ret, "q", "", "=r", 10);
13156 if (unlikely(ret))
13157 return ret;
13158 __get_user_asm(*(u16 *)(8 + (char *)dst),
13159- (u16 __user *)(8 + (char __user *)src),
13160+ (const u16 __user *)(8 + (const char __user *)src),
13161 ret, "w", "w", "=r", 2);
13162 return ret;
13163 case 16:
13164- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13165+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13166 ret, "q", "", "=r", 16);
13167 if (unlikely(ret))
13168 return ret;
13169 __get_user_asm(*(u64 *)(8 + (char *)dst),
13170- (u64 __user *)(8 + (char __user *)src),
13171+ (const u64 __user *)(8 + (const char __user *)src),
13172 ret, "q", "", "=r", 8);
13173 return ret;
13174 default:
13175- return copy_user_generic(dst, (__force void *)src, size);
13176+
13177+#ifdef CONFIG_PAX_MEMORY_UDEREF
13178+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13179+ src += PAX_USER_SHADOW_BASE;
13180+#endif
13181+
13182+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13183 }
13184 }
13185
13186 static __always_inline __must_check
13187-int __copy_to_user(void __user *dst, const void *src, unsigned size)
13188+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13189 {
13190- int ret = 0;
13191+ size_t sz = __compiletime_object_size(src);
13192+ unsigned ret = 0;
13193
13194 might_fault();
13195- if (!__builtin_constant_p(size))
13196- return copy_user_generic((__force void *)dst, src, size);
13197+
13198+ if (size > INT_MAX)
13199+ return size;
13200+
13201+#ifdef CONFIG_PAX_MEMORY_UDEREF
13202+ if (!__access_ok(VERIFY_WRITE, dst, size))
13203+ return size;
13204+#endif
13205+
13206+ if (unlikely(sz != (size_t)-1 && sz < size)) {
13207+ copy_to_user_overflow();
13208+ return size;
13209+ }
13210+
13211+ if (!__builtin_constant_p(size)) {
13212+ check_object_size(src, size, true);
13213+
13214+#ifdef CONFIG_PAX_MEMORY_UDEREF
13215+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13216+ dst += PAX_USER_SHADOW_BASE;
13217+#endif
13218+
13219+ return copy_user_generic((__force_kernel void *)dst, src, size);
13220+ }
13221 switch (size) {
13222- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13223+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13224 ret, "b", "b", "iq", 1);
13225 return ret;
13226- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13227+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13228 ret, "w", "w", "ir", 2);
13229 return ret;
13230- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13231+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13232 ret, "l", "k", "ir", 4);
13233 return ret;
13234- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13235+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13236 ret, "q", "", "er", 8);
13237 return ret;
13238 case 10:
13239- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13240+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13241 ret, "q", "", "er", 10);
13242 if (unlikely(ret))
13243 return ret;
13244 asm("":::"memory");
13245- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13246+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13247 ret, "w", "w", "ir", 2);
13248 return ret;
13249 case 16:
13250- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13251+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13252 ret, "q", "", "er", 16);
13253 if (unlikely(ret))
13254 return ret;
13255 asm("":::"memory");
13256- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13257+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13258 ret, "q", "", "er", 8);
13259 return ret;
13260 default:
13261- return copy_user_generic((__force void *)dst, src, size);
13262+
13263+#ifdef CONFIG_PAX_MEMORY_UDEREF
13264+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13265+ dst += PAX_USER_SHADOW_BASE;
13266+#endif
13267+
13268+ return copy_user_generic((__force_kernel void *)dst, src, size);
13269 }
13270 }
13271
13272 static __always_inline __must_check
13273-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13274+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13275 {
13276- int ret = 0;
13277+ unsigned ret = 0;
13278
13279 might_fault();
13280- if (!__builtin_constant_p(size))
13281- return copy_user_generic((__force void *)dst,
13282- (__force void *)src, size);
13283+
13284+ if (size > INT_MAX)
13285+ return size;
13286+
13287+#ifdef CONFIG_PAX_MEMORY_UDEREF
13288+ if (!__access_ok(VERIFY_READ, src, size))
13289+ return size;
13290+ if (!__access_ok(VERIFY_WRITE, dst, size))
13291+ return size;
13292+#endif
13293+
13294+ if (!__builtin_constant_p(size)) {
13295+
13296+#ifdef CONFIG_PAX_MEMORY_UDEREF
13297+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13298+ src += PAX_USER_SHADOW_BASE;
13299+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13300+ dst += PAX_USER_SHADOW_BASE;
13301+#endif
13302+
13303+ return copy_user_generic((__force_kernel void *)dst,
13304+ (__force_kernel const void *)src, size);
13305+ }
13306 switch (size) {
13307 case 1: {
13308 u8 tmp;
13309- __get_user_asm(tmp, (u8 __user *)src,
13310+ __get_user_asm(tmp, (const u8 __user *)src,
13311 ret, "b", "b", "=q", 1);
13312 if (likely(!ret))
13313 __put_user_asm(tmp, (u8 __user *)dst,
13314@@ -176,7 +277,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13315 }
13316 case 2: {
13317 u16 tmp;
13318- __get_user_asm(tmp, (u16 __user *)src,
13319+ __get_user_asm(tmp, (const u16 __user *)src,
13320 ret, "w", "w", "=r", 2);
13321 if (likely(!ret))
13322 __put_user_asm(tmp, (u16 __user *)dst,
13323@@ -186,7 +287,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13324
13325 case 4: {
13326 u32 tmp;
13327- __get_user_asm(tmp, (u32 __user *)src,
13328+ __get_user_asm(tmp, (const u32 __user *)src,
13329 ret, "l", "k", "=r", 4);
13330 if (likely(!ret))
13331 __put_user_asm(tmp, (u32 __user *)dst,
13332@@ -195,7 +296,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13333 }
13334 case 8: {
13335 u64 tmp;
13336- __get_user_asm(tmp, (u64 __user *)src,
13337+ __get_user_asm(tmp, (const u64 __user *)src,
13338 ret, "q", "", "=r", 8);
13339 if (likely(!ret))
13340 __put_user_asm(tmp, (u64 __user *)dst,
13341@@ -203,44 +304,89 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13342 return ret;
13343 }
13344 default:
13345- return copy_user_generic((__force void *)dst,
13346- (__force void *)src, size);
13347+
13348+#ifdef CONFIG_PAX_MEMORY_UDEREF
13349+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13350+ src += PAX_USER_SHADOW_BASE;
13351+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13352+ dst += PAX_USER_SHADOW_BASE;
13353+#endif
13354+
13355+ return copy_user_generic((__force_kernel void *)dst,
13356+ (__force_kernel const void *)src, size);
13357 }
13358 }
13359
13360-__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13361-__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13362+__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13363+__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13364
13365 static __must_check __always_inline int
13366-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13367+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13368 {
13369- return copy_user_generic(dst, (__force const void *)src, size);
13370+ if (size > INT_MAX)
13371+ return size;
13372+
13373+#ifdef CONFIG_PAX_MEMORY_UDEREF
13374+ if (!__access_ok(VERIFY_READ, src, size))
13375+ return size;
13376+
13377+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13378+ src += PAX_USER_SHADOW_BASE;
13379+#endif
13380+
13381+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13382 }
13383
13384-static __must_check __always_inline int
13385-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13386+static __must_check __always_inline unsigned long
13387+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13388 {
13389- return copy_user_generic((__force void *)dst, src, size);
13390+ if (size > INT_MAX)
13391+ return size;
13392+
13393+#ifdef CONFIG_PAX_MEMORY_UDEREF
13394+ if (!__access_ok(VERIFY_WRITE, dst, size))
13395+ return size;
13396+
13397+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13398+ dst += PAX_USER_SHADOW_BASE;
13399+#endif
13400+
13401+ return copy_user_generic((__force_kernel void *)dst, src, size);
13402 }
13403
13404-extern long __copy_user_nocache(void *dst, const void __user *src,
13405- unsigned size, int zerorest);
13406+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13407+ unsigned long size, int zerorest) __size_overflow(3);
13408
13409-static inline int
13410-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13411+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13412 {
13413 might_sleep();
13414+
13415+ if (size > INT_MAX)
13416+ return size;
13417+
13418+#ifdef CONFIG_PAX_MEMORY_UDEREF
13419+ if (!__access_ok(VERIFY_READ, src, size))
13420+ return size;
13421+#endif
13422+
13423 return __copy_user_nocache(dst, src, size, 1);
13424 }
13425
13426-static inline int
13427-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13428- unsigned size)
13429+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13430+ unsigned long size)
13431 {
13432+ if (size > INT_MAX)
13433+ return size;
13434+
13435+#ifdef CONFIG_PAX_MEMORY_UDEREF
13436+ if (!__access_ok(VERIFY_READ, src, size))
13437+ return size;
13438+#endif
13439+
13440 return __copy_user_nocache(dst, src, size, 0);
13441 }
13442
13443-unsigned long
13444-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13445+extern unsigned long
13446+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13447
13448 #endif /* _ASM_X86_UACCESS_64_H */
13449diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13450index bb05228..d763d5b 100644
13451--- a/arch/x86/include/asm/vdso.h
13452+++ b/arch/x86/include/asm/vdso.h
13453@@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13454 #define VDSO32_SYMBOL(base, name) \
13455 ({ \
13456 extern const char VDSO32_##name[]; \
13457- (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13458+ (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13459 })
13460 #endif
13461
13462diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
13463index 5b238981..77fdd78 100644
13464--- a/arch/x86/include/asm/word-at-a-time.h
13465+++ b/arch/x86/include/asm/word-at-a-time.h
13466@@ -11,7 +11,7 @@
13467 * and shift, for example.
13468 */
13469 struct word_at_a_time {
13470- const unsigned long one_bits, high_bits;
13471+ unsigned long one_bits, high_bits;
13472 };
13473
13474 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
13475diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13476index c090af1..7e7bf16 100644
13477--- a/arch/x86/include/asm/x86_init.h
13478+++ b/arch/x86/include/asm/x86_init.h
13479@@ -29,7 +29,7 @@ struct x86_init_mpparse {
13480 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13481 void (*find_smp_config)(void);
13482 void (*get_smp_config)(unsigned int early);
13483-};
13484+} __no_const;
13485
13486 /**
13487 * struct x86_init_resources - platform specific resource related ops
13488@@ -43,7 +43,7 @@ struct x86_init_resources {
13489 void (*probe_roms)(void);
13490 void (*reserve_resources)(void);
13491 char *(*memory_setup)(void);
13492-};
13493+} __no_const;
13494
13495 /**
13496 * struct x86_init_irqs - platform specific interrupt setup
13497@@ -56,7 +56,7 @@ struct x86_init_irqs {
13498 void (*pre_vector_init)(void);
13499 void (*intr_init)(void);
13500 void (*trap_init)(void);
13501-};
13502+} __no_const;
13503
13504 /**
13505 * struct x86_init_oem - oem platform specific customizing functions
13506@@ -66,7 +66,7 @@ struct x86_init_irqs {
13507 struct x86_init_oem {
13508 void (*arch_setup)(void);
13509 void (*banner)(void);
13510-};
13511+} __no_const;
13512
13513 /**
13514 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13515@@ -77,7 +77,7 @@ struct x86_init_oem {
13516 */
13517 struct x86_init_mapping {
13518 void (*pagetable_reserve)(u64 start, u64 end);
13519-};
13520+} __no_const;
13521
13522 /**
13523 * struct x86_init_paging - platform specific paging functions
13524@@ -87,7 +87,7 @@ struct x86_init_mapping {
13525 struct x86_init_paging {
13526 void (*pagetable_setup_start)(pgd_t *base);
13527 void (*pagetable_setup_done)(pgd_t *base);
13528-};
13529+} __no_const;
13530
13531 /**
13532 * struct x86_init_timers - platform specific timer setup
13533@@ -102,7 +102,7 @@ struct x86_init_timers {
13534 void (*tsc_pre_init)(void);
13535 void (*timer_init)(void);
13536 void (*wallclock_init)(void);
13537-};
13538+} __no_const;
13539
13540 /**
13541 * struct x86_init_iommu - platform specific iommu setup
13542@@ -110,7 +110,7 @@ struct x86_init_timers {
13543 */
13544 struct x86_init_iommu {
13545 int (*iommu_init)(void);
13546-};
13547+} __no_const;
13548
13549 /**
13550 * struct x86_init_pci - platform specific pci init functions
13551@@ -124,7 +124,7 @@ struct x86_init_pci {
13552 int (*init)(void);
13553 void (*init_irq)(void);
13554 void (*fixup_irqs)(void);
13555-};
13556+} __no_const;
13557
13558 /**
13559 * struct x86_init_ops - functions for platform specific setup
13560@@ -140,7 +140,7 @@ struct x86_init_ops {
13561 struct x86_init_timers timers;
13562 struct x86_init_iommu iommu;
13563 struct x86_init_pci pci;
13564-};
13565+} __no_const;
13566
13567 /**
13568 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13569@@ -151,7 +151,7 @@ struct x86_cpuinit_ops {
13570 void (*setup_percpu_clockev)(void);
13571 void (*early_percpu_clock_init)(void);
13572 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13573-};
13574+} __no_const;
13575
13576 /**
13577 * struct x86_platform_ops - platform specific runtime functions
13578@@ -177,7 +177,7 @@ struct x86_platform_ops {
13579 int (*i8042_detect)(void);
13580 void (*save_sched_clock_state)(void);
13581 void (*restore_sched_clock_state)(void);
13582-};
13583+} __no_const;
13584
13585 struct pci_dev;
13586
13587@@ -186,14 +186,14 @@ struct x86_msi_ops {
13588 void (*teardown_msi_irq)(unsigned int irq);
13589 void (*teardown_msi_irqs)(struct pci_dev *dev);
13590 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13591-};
13592+} __no_const;
13593
13594 struct x86_io_apic_ops {
13595 void (*init) (void);
13596 unsigned int (*read) (unsigned int apic, unsigned int reg);
13597 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
13598 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
13599-};
13600+} __no_const;
13601
13602 extern struct x86_init_ops x86_init;
13603 extern struct x86_cpuinit_ops x86_cpuinit;
13604diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13605index 8a1b6f9..a29c4e4 100644
13606--- a/arch/x86/include/asm/xsave.h
13607+++ b/arch/x86/include/asm/xsave.h
13608@@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13609 {
13610 int err;
13611
13612+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13613+ if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13614+ buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13615+#endif
13616+
13617 /*
13618 * Clear the xsave header first, so that reserved fields are
13619 * initialized to zero.
13620@@ -93,10 +98,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13621 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13622 {
13623 int err;
13624- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13625+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13626 u32 lmask = mask;
13627 u32 hmask = mask >> 32;
13628
13629+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13630+ if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13631+ xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13632+#endif
13633+
13634 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13635 "2:\n"
13636 ".section .fixup,\"ax\"\n"
13637diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13638index 95bf99de..de9235c 100644
13639--- a/arch/x86/kernel/acpi/sleep.c
13640+++ b/arch/x86/kernel/acpi/sleep.c
13641@@ -73,8 +73,12 @@ int acpi_suspend_lowlevel(void)
13642 #else /* CONFIG_64BIT */
13643 #ifdef CONFIG_SMP
13644 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13645+
13646+ pax_open_kernel();
13647 early_gdt_descr.address =
13648 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13649+ pax_close_kernel();
13650+
13651 initial_gs = per_cpu_offset(smp_processor_id());
13652 #endif
13653 initial_code = (unsigned long)wakeup_long64;
13654diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13655index 7261083..5c12053 100644
13656--- a/arch/x86/kernel/acpi/wakeup_32.S
13657+++ b/arch/x86/kernel/acpi/wakeup_32.S
13658@@ -30,13 +30,11 @@ wakeup_pmode_return:
13659 # and restore the stack ... but you need gdt for this to work
13660 movl saved_context_esp, %esp
13661
13662- movl %cs:saved_magic, %eax
13663- cmpl $0x12345678, %eax
13664+ cmpl $0x12345678, saved_magic
13665 jne bogus_magic
13666
13667 # jump to place where we left off
13668- movl saved_eip, %eax
13669- jmp *%eax
13670+ jmp *(saved_eip)
13671
13672 bogus_magic:
13673 jmp bogus_magic
13674diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13675index 73ef56c..0238021 100644
13676--- a/arch/x86/kernel/alternative.c
13677+++ b/arch/x86/kernel/alternative.c
13678@@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13679 */
13680 for (a = start; a < end; a++) {
13681 instr = (u8 *)&a->instr_offset + a->instr_offset;
13682+
13683+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13684+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13685+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13686+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13687+#endif
13688+
13689 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13690 BUG_ON(a->replacementlen > a->instrlen);
13691 BUG_ON(a->instrlen > sizeof(insnbuf));
13692@@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13693 for (poff = start; poff < end; poff++) {
13694 u8 *ptr = (u8 *)poff + *poff;
13695
13696+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13697+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13698+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13699+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13700+#endif
13701+
13702 if (!*poff || ptr < text || ptr >= text_end)
13703 continue;
13704 /* turn DS segment override prefix into lock prefix */
13705- if (*ptr == 0x3e)
13706+ if (*ktla_ktva(ptr) == 0x3e)
13707 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13708 };
13709 mutex_unlock(&text_mutex);
13710@@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13711 for (poff = start; poff < end; poff++) {
13712 u8 *ptr = (u8 *)poff + *poff;
13713
13714+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13715+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13716+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13717+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13718+#endif
13719+
13720 if (!*poff || ptr < text || ptr >= text_end)
13721 continue;
13722 /* turn lock prefix into DS segment override prefix */
13723- if (*ptr == 0xf0)
13724+ if (*ktla_ktva(ptr) == 0xf0)
13725 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13726 };
13727 mutex_unlock(&text_mutex);
13728@@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13729
13730 BUG_ON(p->len > MAX_PATCH_LEN);
13731 /* prep the buffer with the original instructions */
13732- memcpy(insnbuf, p->instr, p->len);
13733+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13734 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13735 (unsigned long)p->instr, p->len);
13736
13737@@ -568,7 +587,7 @@ void __init alternative_instructions(void)
13738 if (smp_alt_once)
13739 free_init_pages("SMP alternatives",
13740 (unsigned long)__smp_locks,
13741- (unsigned long)__smp_locks_end);
13742+ PAGE_ALIGN((unsigned long)__smp_locks_end));
13743
13744 restart_nmi();
13745 }
13746@@ -585,13 +604,17 @@ void __init alternative_instructions(void)
13747 * instructions. And on the local CPU you need to be protected again NMI or MCE
13748 * handlers seeing an inconsistent instruction while you patch.
13749 */
13750-void *__init_or_module text_poke_early(void *addr, const void *opcode,
13751+void *__kprobes text_poke_early(void *addr, const void *opcode,
13752 size_t len)
13753 {
13754 unsigned long flags;
13755 local_irq_save(flags);
13756- memcpy(addr, opcode, len);
13757+
13758+ pax_open_kernel();
13759+ memcpy(ktla_ktva(addr), opcode, len);
13760 sync_core();
13761+ pax_close_kernel();
13762+
13763 local_irq_restore(flags);
13764 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13765 that causes hangs on some VIA CPUs. */
13766@@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13767 */
13768 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13769 {
13770- unsigned long flags;
13771- char *vaddr;
13772+ unsigned char *vaddr = ktla_ktva(addr);
13773 struct page *pages[2];
13774- int i;
13775+ size_t i;
13776
13777 if (!core_kernel_text((unsigned long)addr)) {
13778- pages[0] = vmalloc_to_page(addr);
13779- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13780+ pages[0] = vmalloc_to_page(vaddr);
13781+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13782 } else {
13783- pages[0] = virt_to_page(addr);
13784+ pages[0] = virt_to_page(vaddr);
13785 WARN_ON(!PageReserved(pages[0]));
13786- pages[1] = virt_to_page(addr + PAGE_SIZE);
13787+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13788 }
13789 BUG_ON(!pages[0]);
13790- local_irq_save(flags);
13791- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13792- if (pages[1])
13793- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13794- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13795- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13796- clear_fixmap(FIX_TEXT_POKE0);
13797- if (pages[1])
13798- clear_fixmap(FIX_TEXT_POKE1);
13799- local_flush_tlb();
13800- sync_core();
13801- /* Could also do a CLFLUSH here to speed up CPU recovery; but
13802- that causes hangs on some VIA CPUs. */
13803+ text_poke_early(addr, opcode, len);
13804 for (i = 0; i < len; i++)
13805- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13806- local_irq_restore(flags);
13807+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13808 return addr;
13809 }
13810
13811diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13812index 39a222e..85a7767 100644
13813--- a/arch/x86/kernel/apic/apic.c
13814+++ b/arch/x86/kernel/apic/apic.c
13815@@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
13816 /*
13817 * Debug level, exported for io_apic.c
13818 */
13819-unsigned int apic_verbosity;
13820+int apic_verbosity;
13821
13822 int pic_mode;
13823
13824@@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13825 apic_write(APIC_ESR, 0);
13826 v1 = apic_read(APIC_ESR);
13827 ack_APIC_irq();
13828- atomic_inc(&irq_err_count);
13829+ atomic_inc_unchecked(&irq_err_count);
13830
13831 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13832 smp_processor_id(), v0 , v1);
13833diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13834index 5f0ff59..f9e01bc 100644
13835--- a/arch/x86/kernel/apic/io_apic.c
13836+++ b/arch/x86/kernel/apic/io_apic.c
13837@@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13838 }
13839 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13840
13841-void lock_vector_lock(void)
13842+void lock_vector_lock(void) __acquires(vector_lock)
13843 {
13844 /* Used to the online set of cpus does not change
13845 * during assign_irq_vector.
13846@@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
13847 raw_spin_lock(&vector_lock);
13848 }
13849
13850-void unlock_vector_lock(void)
13851+void unlock_vector_lock(void) __releases(vector_lock)
13852 {
13853 raw_spin_unlock(&vector_lock);
13854 }
13855@@ -2369,7 +2369,7 @@ static void ack_apic_edge(struct irq_data *data)
13856 ack_APIC_irq();
13857 }
13858
13859-atomic_t irq_mis_count;
13860+atomic_unchecked_t irq_mis_count;
13861
13862 #ifdef CONFIG_GENERIC_PENDING_IRQ
13863 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
13864@@ -2510,7 +2510,7 @@ static void ack_apic_level(struct irq_data *data)
13865 * at the cpu.
13866 */
13867 if (!(v & (1 << (i & 0x1f)))) {
13868- atomic_inc(&irq_mis_count);
13869+ atomic_inc_unchecked(&irq_mis_count);
13870
13871 eoi_ioapic_irq(irq, cfg);
13872 }
13873diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13874index 07b0c0d..1df6f42 100644
13875--- a/arch/x86/kernel/apm_32.c
13876+++ b/arch/x86/kernel/apm_32.c
13877@@ -410,7 +410,7 @@ static DEFINE_MUTEX(apm_mutex);
13878 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13879 * even though they are called in protected mode.
13880 */
13881-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
13882+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
13883 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
13884
13885 static const char driver_version[] = "1.16ac"; /* no spaces */
13886@@ -588,7 +588,10 @@ static long __apm_bios_call(void *_call)
13887 BUG_ON(cpu != 0);
13888 gdt = get_cpu_gdt_table(cpu);
13889 save_desc_40 = gdt[0x40 / 8];
13890+
13891+ pax_open_kernel();
13892 gdt[0x40 / 8] = bad_bios_desc;
13893+ pax_close_kernel();
13894
13895 apm_irq_save(flags);
13896 APM_DO_SAVE_SEGS;
13897@@ -597,7 +600,11 @@ static long __apm_bios_call(void *_call)
13898 &call->esi);
13899 APM_DO_RESTORE_SEGS;
13900 apm_irq_restore(flags);
13901+
13902+ pax_open_kernel();
13903 gdt[0x40 / 8] = save_desc_40;
13904+ pax_close_kernel();
13905+
13906 put_cpu();
13907
13908 return call->eax & 0xff;
13909@@ -664,7 +671,10 @@ static long __apm_bios_call_simple(void *_call)
13910 BUG_ON(cpu != 0);
13911 gdt = get_cpu_gdt_table(cpu);
13912 save_desc_40 = gdt[0x40 / 8];
13913+
13914+ pax_open_kernel();
13915 gdt[0x40 / 8] = bad_bios_desc;
13916+ pax_close_kernel();
13917
13918 apm_irq_save(flags);
13919 APM_DO_SAVE_SEGS;
13920@@ -672,7 +682,11 @@ static long __apm_bios_call_simple(void *_call)
13921 &call->eax);
13922 APM_DO_RESTORE_SEGS;
13923 apm_irq_restore(flags);
13924+
13925+ pax_open_kernel();
13926 gdt[0x40 / 8] = save_desc_40;
13927+ pax_close_kernel();
13928+
13929 put_cpu();
13930 return error;
13931 }
13932@@ -2345,12 +2359,15 @@ static int __init apm_init(void)
13933 * code to that CPU.
13934 */
13935 gdt = get_cpu_gdt_table(0);
13936+
13937+ pax_open_kernel();
13938 set_desc_base(&gdt[APM_CS >> 3],
13939 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
13940 set_desc_base(&gdt[APM_CS_16 >> 3],
13941 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
13942 set_desc_base(&gdt[APM_DS >> 3],
13943 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
13944+ pax_close_kernel();
13945
13946 proc_create("apm", 0, NULL, &apm_file_ops);
13947
13948diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
13949index 68de2dc..1f3c720 100644
13950--- a/arch/x86/kernel/asm-offsets.c
13951+++ b/arch/x86/kernel/asm-offsets.c
13952@@ -33,6 +33,8 @@ void common(void) {
13953 OFFSET(TI_status, thread_info, status);
13954 OFFSET(TI_addr_limit, thread_info, addr_limit);
13955 OFFSET(TI_preempt_count, thread_info, preempt_count);
13956+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
13957+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
13958
13959 BLANK();
13960 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
13961@@ -53,8 +55,26 @@ void common(void) {
13962 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
13963 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
13964 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
13965+
13966+#ifdef CONFIG_PAX_KERNEXEC
13967+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
13968 #endif
13969
13970+#ifdef CONFIG_PAX_MEMORY_UDEREF
13971+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
13972+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
13973+#ifdef CONFIG_X86_64
13974+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
13975+#endif
13976+#endif
13977+
13978+#endif
13979+
13980+ BLANK();
13981+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
13982+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
13983+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
13984+
13985 #ifdef CONFIG_XEN
13986 BLANK();
13987 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
13988diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
13989index 1b4754f..fbb4227 100644
13990--- a/arch/x86/kernel/asm-offsets_64.c
13991+++ b/arch/x86/kernel/asm-offsets_64.c
13992@@ -76,6 +76,7 @@ int main(void)
13993 BLANK();
13994 #undef ENTRY
13995
13996+ DEFINE(TSS_size, sizeof(struct tss_struct));
13997 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
13998 BLANK();
13999
14000diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14001index 6ab6aa2..8f71507 100644
14002--- a/arch/x86/kernel/cpu/Makefile
14003+++ b/arch/x86/kernel/cpu/Makefile
14004@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14005 CFLAGS_REMOVE_perf_event.o = -pg
14006 endif
14007
14008-# Make sure load_percpu_segment has no stackprotector
14009-nostackp := $(call cc-option, -fno-stack-protector)
14010-CFLAGS_common.o := $(nostackp)
14011-
14012 obj-y := intel_cacheinfo.o scattered.o topology.o
14013 obj-y += proc.o capflags.o powerflags.o common.o
14014 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
14015diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14016index 146bb62..ac9c74a 100644
14017--- a/arch/x86/kernel/cpu/amd.c
14018+++ b/arch/x86/kernel/cpu/amd.c
14019@@ -691,7 +691,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14020 unsigned int size)
14021 {
14022 /* AMD errata T13 (order #21922) */
14023- if ((c->x86 == 6)) {
14024+ if (c->x86 == 6) {
14025 /* Duron Rev A0 */
14026 if (c->x86_model == 3 && c->x86_mask == 0)
14027 size = 64;
14028diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14029index 6b9333b..4c3083a 100644
14030--- a/arch/x86/kernel/cpu/common.c
14031+++ b/arch/x86/kernel/cpu/common.c
14032@@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14033
14034 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14035
14036-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14037-#ifdef CONFIG_X86_64
14038- /*
14039- * We need valid kernel segments for data and code in long mode too
14040- * IRET will check the segment types kkeil 2000/10/28
14041- * Also sysret mandates a special GDT layout
14042- *
14043- * TLS descriptors are currently at a different place compared to i386.
14044- * Hopefully nobody expects them at a fixed place (Wine?)
14045- */
14046- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14047- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14048- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14049- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14050- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14051- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14052-#else
14053- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14054- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14055- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14056- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14057- /*
14058- * Segments used for calling PnP BIOS have byte granularity.
14059- * They code segments and data segments have fixed 64k limits,
14060- * the transfer segment sizes are set at run time.
14061- */
14062- /* 32-bit code */
14063- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14064- /* 16-bit code */
14065- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14066- /* 16-bit data */
14067- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14068- /* 16-bit data */
14069- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14070- /* 16-bit data */
14071- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14072- /*
14073- * The APM segments have byte granularity and their bases
14074- * are set at run time. All have 64k limits.
14075- */
14076- /* 32-bit code */
14077- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14078- /* 16-bit code */
14079- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14080- /* data */
14081- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14082-
14083- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14084- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14085- GDT_STACK_CANARY_INIT
14086-#endif
14087-} };
14088-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14089-
14090 static int __init x86_xsave_setup(char *s)
14091 {
14092 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14093@@ -374,7 +320,7 @@ void switch_to_new_gdt(int cpu)
14094 {
14095 struct desc_ptr gdt_descr;
14096
14097- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14098+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14099 gdt_descr.size = GDT_SIZE - 1;
14100 load_gdt(&gdt_descr);
14101 /* Reload the per-cpu base */
14102@@ -841,6 +787,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14103 /* Filter out anything that depends on CPUID levels we don't have */
14104 filter_cpuid_features(c, true);
14105
14106+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14107+ setup_clear_cpu_cap(X86_FEATURE_SEP);
14108+#endif
14109+
14110 /* If the model name is still unset, do table lookup. */
14111 if (!c->x86_model_id[0]) {
14112 const char *p;
14113@@ -1021,10 +971,12 @@ static __init int setup_disablecpuid(char *arg)
14114 }
14115 __setup("clearcpuid=", setup_disablecpuid);
14116
14117+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14118+EXPORT_PER_CPU_SYMBOL(current_tinfo);
14119+
14120 #ifdef CONFIG_X86_64
14121 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14122-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14123- (unsigned long) nmi_idt_table };
14124+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14125
14126 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14127 irq_stack_union) __aligned(PAGE_SIZE);
14128@@ -1038,7 +990,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14129 EXPORT_PER_CPU_SYMBOL(current_task);
14130
14131 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14132- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14133+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14134 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14135
14136 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14137@@ -1132,7 +1084,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14138 {
14139 memset(regs, 0, sizeof(struct pt_regs));
14140 regs->fs = __KERNEL_PERCPU;
14141- regs->gs = __KERNEL_STACK_CANARY;
14142+ savesegment(gs, regs->gs);
14143
14144 return regs;
14145 }
14146@@ -1187,7 +1139,7 @@ void __cpuinit cpu_init(void)
14147 int i;
14148
14149 cpu = stack_smp_processor_id();
14150- t = &per_cpu(init_tss, cpu);
14151+ t = init_tss + cpu;
14152 oist = &per_cpu(orig_ist, cpu);
14153
14154 #ifdef CONFIG_NUMA
14155@@ -1213,7 +1165,7 @@ void __cpuinit cpu_init(void)
14156 switch_to_new_gdt(cpu);
14157 loadsegment(fs, 0);
14158
14159- load_idt((const struct desc_ptr *)&idt_descr);
14160+ load_idt(&idt_descr);
14161
14162 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14163 syscall_init();
14164@@ -1222,7 +1174,6 @@ void __cpuinit cpu_init(void)
14165 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14166 barrier();
14167
14168- x86_configure_nx();
14169 if (cpu != 0)
14170 enable_x2apic();
14171
14172@@ -1278,7 +1229,7 @@ void __cpuinit cpu_init(void)
14173 {
14174 int cpu = smp_processor_id();
14175 struct task_struct *curr = current;
14176- struct tss_struct *t = &per_cpu(init_tss, cpu);
14177+ struct tss_struct *t = init_tss + cpu;
14178 struct thread_struct *thread = &curr->thread;
14179
14180 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14181diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14182index 3e6ff6c..54b4992 100644
14183--- a/arch/x86/kernel/cpu/intel.c
14184+++ b/arch/x86/kernel/cpu/intel.c
14185@@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14186 * Update the IDT descriptor and reload the IDT so that
14187 * it uses the read-only mapped virtual address.
14188 */
14189- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14190+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14191 load_idt(&idt_descr);
14192 }
14193 #endif
14194diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14195index c46ed49..5dc0a53 100644
14196--- a/arch/x86/kernel/cpu/mcheck/mce.c
14197+++ b/arch/x86/kernel/cpu/mcheck/mce.c
14198@@ -42,6 +42,7 @@
14199 #include <asm/processor.h>
14200 #include <asm/mce.h>
14201 #include <asm/msr.h>
14202+#include <asm/local.h>
14203
14204 #include "mce-internal.h"
14205
14206@@ -250,7 +251,7 @@ static void print_mce(struct mce *m)
14207 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14208 m->cs, m->ip);
14209
14210- if (m->cs == __KERNEL_CS)
14211+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14212 print_symbol("{%s}", m->ip);
14213 pr_cont("\n");
14214 }
14215@@ -283,10 +284,10 @@ static void print_mce(struct mce *m)
14216
14217 #define PANIC_TIMEOUT 5 /* 5 seconds */
14218
14219-static atomic_t mce_paniced;
14220+static atomic_unchecked_t mce_paniced;
14221
14222 static int fake_panic;
14223-static atomic_t mce_fake_paniced;
14224+static atomic_unchecked_t mce_fake_paniced;
14225
14226 /* Panic in progress. Enable interrupts and wait for final IPI */
14227 static void wait_for_panic(void)
14228@@ -310,7 +311,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14229 /*
14230 * Make sure only one CPU runs in machine check panic
14231 */
14232- if (atomic_inc_return(&mce_paniced) > 1)
14233+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14234 wait_for_panic();
14235 barrier();
14236
14237@@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14238 console_verbose();
14239 } else {
14240 /* Don't log too much for fake panic */
14241- if (atomic_inc_return(&mce_fake_paniced) > 1)
14242+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14243 return;
14244 }
14245 /* First print corrected ones that are still unlogged */
14246@@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
14247 * might have been modified by someone else.
14248 */
14249 rmb();
14250- if (atomic_read(&mce_paniced))
14251+ if (atomic_read_unchecked(&mce_paniced))
14252 wait_for_panic();
14253 if (!monarch_timeout)
14254 goto out;
14255@@ -1581,7 +1582,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14256 }
14257
14258 /* Call the installed machine check handler for this CPU setup. */
14259-void (*machine_check_vector)(struct pt_regs *, long error_code) =
14260+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14261 unexpected_machine_check;
14262
14263 /*
14264@@ -1604,7 +1605,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14265 return;
14266 }
14267
14268+ pax_open_kernel();
14269 machine_check_vector = do_machine_check;
14270+ pax_close_kernel();
14271
14272 __mcheck_cpu_init_generic();
14273 __mcheck_cpu_init_vendor(c);
14274@@ -1618,7 +1621,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14275 */
14276
14277 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14278-static int mce_chrdev_open_count; /* #times opened */
14279+static local_t mce_chrdev_open_count; /* #times opened */
14280 static int mce_chrdev_open_exclu; /* already open exclusive? */
14281
14282 static int mce_chrdev_open(struct inode *inode, struct file *file)
14283@@ -1626,7 +1629,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14284 spin_lock(&mce_chrdev_state_lock);
14285
14286 if (mce_chrdev_open_exclu ||
14287- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14288+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14289 spin_unlock(&mce_chrdev_state_lock);
14290
14291 return -EBUSY;
14292@@ -1634,7 +1637,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14293
14294 if (file->f_flags & O_EXCL)
14295 mce_chrdev_open_exclu = 1;
14296- mce_chrdev_open_count++;
14297+ local_inc(&mce_chrdev_open_count);
14298
14299 spin_unlock(&mce_chrdev_state_lock);
14300
14301@@ -1645,7 +1648,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14302 {
14303 spin_lock(&mce_chrdev_state_lock);
14304
14305- mce_chrdev_open_count--;
14306+ local_dec(&mce_chrdev_open_count);
14307 mce_chrdev_open_exclu = 0;
14308
14309 spin_unlock(&mce_chrdev_state_lock);
14310@@ -2370,7 +2373,7 @@ struct dentry *mce_get_debugfs_dir(void)
14311 static void mce_reset(void)
14312 {
14313 cpu_missing = 0;
14314- atomic_set(&mce_fake_paniced, 0);
14315+ atomic_set_unchecked(&mce_fake_paniced, 0);
14316 atomic_set(&mce_executing, 0);
14317 atomic_set(&mce_callin, 0);
14318 atomic_set(&global_nwo, 0);
14319diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14320index 2d5454c..51987eb 100644
14321--- a/arch/x86/kernel/cpu/mcheck/p5.c
14322+++ b/arch/x86/kernel/cpu/mcheck/p5.c
14323@@ -11,6 +11,7 @@
14324 #include <asm/processor.h>
14325 #include <asm/mce.h>
14326 #include <asm/msr.h>
14327+#include <asm/pgtable.h>
14328
14329 /* By default disabled */
14330 int mce_p5_enabled __read_mostly;
14331@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14332 if (!cpu_has(c, X86_FEATURE_MCE))
14333 return;
14334
14335+ pax_open_kernel();
14336 machine_check_vector = pentium_machine_check;
14337+ pax_close_kernel();
14338 /* Make sure the vector pointer is visible before we enable MCEs: */
14339 wmb();
14340
14341diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14342index 2d7998f..17c9de1 100644
14343--- a/arch/x86/kernel/cpu/mcheck/winchip.c
14344+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14345@@ -10,6 +10,7 @@
14346 #include <asm/processor.h>
14347 #include <asm/mce.h>
14348 #include <asm/msr.h>
14349+#include <asm/pgtable.h>
14350
14351 /* Machine check handler for WinChip C6: */
14352 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14353@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14354 {
14355 u32 lo, hi;
14356
14357+ pax_open_kernel();
14358 machine_check_vector = winchip_machine_check;
14359+ pax_close_kernel();
14360 /* Make sure the vector pointer is visible before we enable MCEs: */
14361 wmb();
14362
14363diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14364index 6b96110..0da73eb 100644
14365--- a/arch/x86/kernel/cpu/mtrr/main.c
14366+++ b/arch/x86/kernel/cpu/mtrr/main.c
14367@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14368 u64 size_or_mask, size_and_mask;
14369 static bool mtrr_aps_delayed_init;
14370
14371-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14372+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14373
14374 const struct mtrr_ops *mtrr_if;
14375
14376diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14377index df5e41f..816c719 100644
14378--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14379+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14380@@ -25,7 +25,7 @@ struct mtrr_ops {
14381 int (*validate_add_page)(unsigned long base, unsigned long size,
14382 unsigned int type);
14383 int (*have_wrcomb)(void);
14384-};
14385+} __do_const;
14386
14387 extern int generic_get_free_region(unsigned long base, unsigned long size,
14388 int replace_reg);
14389diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14390index c4706cf..264b0f7 100644
14391--- a/arch/x86/kernel/cpu/perf_event.c
14392+++ b/arch/x86/kernel/cpu/perf_event.c
14393@@ -1837,7 +1837,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14394 break;
14395
14396 perf_callchain_store(entry, frame.return_address);
14397- fp = frame.next_frame;
14398+ fp = (const void __force_user *)frame.next_frame;
14399 }
14400 }
14401
14402diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14403index 13ad899..f642b9a 100644
14404--- a/arch/x86/kernel/crash.c
14405+++ b/arch/x86/kernel/crash.c
14406@@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14407 {
14408 #ifdef CONFIG_X86_32
14409 struct pt_regs fixed_regs;
14410-#endif
14411
14412-#ifdef CONFIG_X86_32
14413- if (!user_mode_vm(regs)) {
14414+ if (!user_mode(regs)) {
14415 crash_fixup_ss_esp(&fixed_regs, regs);
14416 regs = &fixed_regs;
14417 }
14418diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14419index 37250fe..bf2ec74 100644
14420--- a/arch/x86/kernel/doublefault_32.c
14421+++ b/arch/x86/kernel/doublefault_32.c
14422@@ -11,7 +11,7 @@
14423
14424 #define DOUBLEFAULT_STACKSIZE (1024)
14425 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14426-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14427+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14428
14429 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14430
14431@@ -21,7 +21,7 @@ static void doublefault_fn(void)
14432 unsigned long gdt, tss;
14433
14434 store_gdt(&gdt_desc);
14435- gdt = gdt_desc.address;
14436+ gdt = (unsigned long)gdt_desc.address;
14437
14438 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14439
14440@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14441 /* 0x2 bit is always set */
14442 .flags = X86_EFLAGS_SF | 0x2,
14443 .sp = STACK_START,
14444- .es = __USER_DS,
14445+ .es = __KERNEL_DS,
14446 .cs = __KERNEL_CS,
14447 .ss = __KERNEL_DS,
14448- .ds = __USER_DS,
14449+ .ds = __KERNEL_DS,
14450 .fs = __KERNEL_PERCPU,
14451
14452 .__cr3 = __pa_nodebug(swapper_pg_dir),
14453diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14454index 571246d..81f335c 100644
14455--- a/arch/x86/kernel/dumpstack.c
14456+++ b/arch/x86/kernel/dumpstack.c
14457@@ -2,6 +2,9 @@
14458 * Copyright (C) 1991, 1992 Linus Torvalds
14459 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14460 */
14461+#ifdef CONFIG_GRKERNSEC_HIDESYM
14462+#define __INCLUDED_BY_HIDESYM 1
14463+#endif
14464 #include <linux/kallsyms.h>
14465 #include <linux/kprobes.h>
14466 #include <linux/uaccess.h>
14467@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
14468 static void
14469 print_ftrace_graph_addr(unsigned long addr, void *data,
14470 const struct stacktrace_ops *ops,
14471- struct thread_info *tinfo, int *graph)
14472+ struct task_struct *task, int *graph)
14473 {
14474- struct task_struct *task;
14475 unsigned long ret_addr;
14476 int index;
14477
14478 if (addr != (unsigned long)return_to_handler)
14479 return;
14480
14481- task = tinfo->task;
14482 index = task->curr_ret_stack;
14483
14484 if (!task->ret_stack || index < *graph)
14485@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14486 static inline void
14487 print_ftrace_graph_addr(unsigned long addr, void *data,
14488 const struct stacktrace_ops *ops,
14489- struct thread_info *tinfo, int *graph)
14490+ struct task_struct *task, int *graph)
14491 { }
14492 #endif
14493
14494@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14495 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14496 */
14497
14498-static inline int valid_stack_ptr(struct thread_info *tinfo,
14499- void *p, unsigned int size, void *end)
14500+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14501 {
14502- void *t = tinfo;
14503 if (end) {
14504 if (p < end && p >= (end-THREAD_SIZE))
14505 return 1;
14506@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14507 }
14508
14509 unsigned long
14510-print_context_stack(struct thread_info *tinfo,
14511+print_context_stack(struct task_struct *task, void *stack_start,
14512 unsigned long *stack, unsigned long bp,
14513 const struct stacktrace_ops *ops, void *data,
14514 unsigned long *end, int *graph)
14515 {
14516 struct stack_frame *frame = (struct stack_frame *)bp;
14517
14518- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14519+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14520 unsigned long addr;
14521
14522 addr = *stack;
14523@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
14524 } else {
14525 ops->address(data, addr, 0);
14526 }
14527- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14528+ print_ftrace_graph_addr(addr, data, ops, task, graph);
14529 }
14530 stack++;
14531 }
14532@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
14533 EXPORT_SYMBOL_GPL(print_context_stack);
14534
14535 unsigned long
14536-print_context_stack_bp(struct thread_info *tinfo,
14537+print_context_stack_bp(struct task_struct *task, void *stack_start,
14538 unsigned long *stack, unsigned long bp,
14539 const struct stacktrace_ops *ops, void *data,
14540 unsigned long *end, int *graph)
14541@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14542 struct stack_frame *frame = (struct stack_frame *)bp;
14543 unsigned long *ret_addr = &frame->return_address;
14544
14545- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14546+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14547 unsigned long addr = *ret_addr;
14548
14549 if (!__kernel_text_address(addr))
14550@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14551 ops->address(data, addr, 1);
14552 frame = frame->next_frame;
14553 ret_addr = &frame->return_address;
14554- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14555+ print_ftrace_graph_addr(addr, data, ops, task, graph);
14556 }
14557
14558 return (unsigned long)frame;
14559@@ -189,7 +188,7 @@ void dump_stack(void)
14560
14561 bp = stack_frame(current, NULL);
14562 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14563- current->pid, current->comm, print_tainted(),
14564+ task_pid_nr(current), current->comm, print_tainted(),
14565 init_utsname()->release,
14566 (int)strcspn(init_utsname()->version, " "),
14567 init_utsname()->version);
14568@@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
14569 }
14570 EXPORT_SYMBOL_GPL(oops_begin);
14571
14572+extern void gr_handle_kernel_exploit(void);
14573+
14574 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14575 {
14576 if (regs && kexec_should_crash(current))
14577@@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14578 panic("Fatal exception in interrupt");
14579 if (panic_on_oops)
14580 panic("Fatal exception");
14581- do_exit(signr);
14582+
14583+ gr_handle_kernel_exploit();
14584+
14585+ do_group_exit(signr);
14586 }
14587
14588 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14589@@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14590
14591 show_regs(regs);
14592 #ifdef CONFIG_X86_32
14593- if (user_mode_vm(regs)) {
14594+ if (user_mode(regs)) {
14595 sp = regs->sp;
14596 ss = regs->ss & 0xffff;
14597 } else {
14598@@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14599 unsigned long flags = oops_begin();
14600 int sig = SIGSEGV;
14601
14602- if (!user_mode_vm(regs))
14603+ if (!user_mode(regs))
14604 report_bug(regs->ip, regs);
14605
14606 if (__die(str, regs, err))
14607diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14608index e0b1d78..a8ade5e 100644
14609--- a/arch/x86/kernel/dumpstack_32.c
14610+++ b/arch/x86/kernel/dumpstack_32.c
14611@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14612 bp = stack_frame(task, regs);
14613
14614 for (;;) {
14615- struct thread_info *context;
14616+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14617
14618- context = (struct thread_info *)
14619- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14620- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14621+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14622
14623- stack = (unsigned long *)context->previous_esp;
14624- if (!stack)
14625+ if (stack_start == task_stack_page(task))
14626 break;
14627+ stack = *(unsigned long **)stack_start;
14628 if (ops->stack(data, "IRQ") < 0)
14629 break;
14630 touch_nmi_watchdog();
14631@@ -87,7 +85,7 @@ void show_regs(struct pt_regs *regs)
14632 int i;
14633
14634 print_modules();
14635- __show_regs(regs, !user_mode_vm(regs));
14636+ __show_regs(regs, !user_mode(regs));
14637
14638 printk(KERN_EMERG "Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
14639 TASK_COMM_LEN, current->comm, task_pid_nr(current),
14640@@ -96,21 +94,22 @@ void show_regs(struct pt_regs *regs)
14641 * When in-kernel, we also print out the stack and code at the
14642 * time of the fault..
14643 */
14644- if (!user_mode_vm(regs)) {
14645+ if (!user_mode(regs)) {
14646 unsigned int code_prologue = code_bytes * 43 / 64;
14647 unsigned int code_len = code_bytes;
14648 unsigned char c;
14649 u8 *ip;
14650+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14651
14652 printk(KERN_EMERG "Stack:\n");
14653 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14654
14655 printk(KERN_EMERG "Code: ");
14656
14657- ip = (u8 *)regs->ip - code_prologue;
14658+ ip = (u8 *)regs->ip - code_prologue + cs_base;
14659 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14660 /* try starting at IP */
14661- ip = (u8 *)regs->ip;
14662+ ip = (u8 *)regs->ip + cs_base;
14663 code_len = code_len - code_prologue + 1;
14664 }
14665 for (i = 0; i < code_len; i++, ip++) {
14666@@ -119,7 +118,7 @@ void show_regs(struct pt_regs *regs)
14667 printk(KERN_CONT " Bad EIP value.");
14668 break;
14669 }
14670- if (ip == (u8 *)regs->ip)
14671+ if (ip == (u8 *)regs->ip + cs_base)
14672 printk(KERN_CONT "<%02x> ", c);
14673 else
14674 printk(KERN_CONT "%02x ", c);
14675@@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
14676 {
14677 unsigned short ud2;
14678
14679+ ip = ktla_ktva(ip);
14680 if (ip < PAGE_OFFSET)
14681 return 0;
14682 if (probe_kernel_address((unsigned short *)ip, ud2))
14683@@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
14684
14685 return ud2 == 0x0b0f;
14686 }
14687+
14688+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14689+void pax_check_alloca(unsigned long size)
14690+{
14691+ unsigned long sp = (unsigned long)&sp, stack_left;
14692+
14693+ /* all kernel stacks are of the same size */
14694+ stack_left = sp & (THREAD_SIZE - 1);
14695+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14696+}
14697+EXPORT_SYMBOL(pax_check_alloca);
14698+#endif
14699diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14700index 791b761..2ab6e33 100644
14701--- a/arch/x86/kernel/dumpstack_64.c
14702+++ b/arch/x86/kernel/dumpstack_64.c
14703@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14704 unsigned long *irq_stack_end =
14705 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14706 unsigned used = 0;
14707- struct thread_info *tinfo;
14708 int graph = 0;
14709 unsigned long dummy;
14710+ void *stack_start;
14711
14712 if (!task)
14713 task = current;
14714@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14715 * current stack address. If the stacks consist of nested
14716 * exceptions
14717 */
14718- tinfo = task_thread_info(task);
14719 for (;;) {
14720 char *id;
14721 unsigned long *estack_end;
14722+
14723 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14724 &used, &id);
14725
14726@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14727 if (ops->stack(data, id) < 0)
14728 break;
14729
14730- bp = ops->walk_stack(tinfo, stack, bp, ops,
14731+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14732 data, estack_end, &graph);
14733 ops->stack(data, "<EOE>");
14734 /*
14735@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14736 * second-to-last pointer (index -2 to end) in the
14737 * exception stack:
14738 */
14739+ if ((u16)estack_end[-1] != __KERNEL_DS)
14740+ goto out;
14741 stack = (unsigned long *) estack_end[-2];
14742 continue;
14743 }
14744@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14745 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14746 if (ops->stack(data, "IRQ") < 0)
14747 break;
14748- bp = ops->walk_stack(tinfo, stack, bp,
14749+ bp = ops->walk_stack(task, irq_stack, stack, bp,
14750 ops, data, irq_stack_end, &graph);
14751 /*
14752 * We link to the next stack (which would be
14753@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14754 /*
14755 * This handles the process stack:
14756 */
14757- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14758+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14759+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14760+out:
14761 put_cpu();
14762 }
14763 EXPORT_SYMBOL(dump_trace);
14764@@ -305,3 +309,50 @@ int is_valid_bugaddr(unsigned long ip)
14765
14766 return ud2 == 0x0b0f;
14767 }
14768+
14769+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14770+void pax_check_alloca(unsigned long size)
14771+{
14772+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14773+ unsigned cpu, used;
14774+ char *id;
14775+
14776+ /* check the process stack first */
14777+ stack_start = (unsigned long)task_stack_page(current);
14778+ stack_end = stack_start + THREAD_SIZE;
14779+ if (likely(stack_start <= sp && sp < stack_end)) {
14780+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
14781+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14782+ return;
14783+ }
14784+
14785+ cpu = get_cpu();
14786+
14787+ /* check the irq stacks */
14788+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14789+ stack_start = stack_end - IRQ_STACK_SIZE;
14790+ if (stack_start <= sp && sp < stack_end) {
14791+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14792+ put_cpu();
14793+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14794+ return;
14795+ }
14796+
14797+ /* check the exception stacks */
14798+ used = 0;
14799+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14800+ stack_start = stack_end - EXCEPTION_STKSZ;
14801+ if (stack_end && stack_start <= sp && sp < stack_end) {
14802+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14803+ put_cpu();
14804+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14805+ return;
14806+ }
14807+
14808+ put_cpu();
14809+
14810+ /* unknown stack */
14811+ BUG();
14812+}
14813+EXPORT_SYMBOL(pax_check_alloca);
14814+#endif
14815diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14816index 9b9f18b..9fcaa04 100644
14817--- a/arch/x86/kernel/early_printk.c
14818+++ b/arch/x86/kernel/early_printk.c
14819@@ -7,6 +7,7 @@
14820 #include <linux/pci_regs.h>
14821 #include <linux/pci_ids.h>
14822 #include <linux/errno.h>
14823+#include <linux/sched.h>
14824 #include <asm/io.h>
14825 #include <asm/processor.h>
14826 #include <asm/fcntl.h>
14827diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14828index 623f288..0683156 100644
14829--- a/arch/x86/kernel/entry_32.S
14830+++ b/arch/x86/kernel/entry_32.S
14831@@ -176,13 +176,146 @@
14832 /*CFI_REL_OFFSET gs, PT_GS*/
14833 .endm
14834 .macro SET_KERNEL_GS reg
14835+
14836+#ifdef CONFIG_CC_STACKPROTECTOR
14837 movl $(__KERNEL_STACK_CANARY), \reg
14838+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14839+ movl $(__USER_DS), \reg
14840+#else
14841+ xorl \reg, \reg
14842+#endif
14843+
14844 movl \reg, %gs
14845 .endm
14846
14847 #endif /* CONFIG_X86_32_LAZY_GS */
14848
14849-.macro SAVE_ALL
14850+.macro pax_enter_kernel
14851+#ifdef CONFIG_PAX_KERNEXEC
14852+ call pax_enter_kernel
14853+#endif
14854+.endm
14855+
14856+.macro pax_exit_kernel
14857+#ifdef CONFIG_PAX_KERNEXEC
14858+ call pax_exit_kernel
14859+#endif
14860+.endm
14861+
14862+#ifdef CONFIG_PAX_KERNEXEC
14863+ENTRY(pax_enter_kernel)
14864+#ifdef CONFIG_PARAVIRT
14865+ pushl %eax
14866+ pushl %ecx
14867+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
14868+ mov %eax, %esi
14869+#else
14870+ mov %cr0, %esi
14871+#endif
14872+ bts $16, %esi
14873+ jnc 1f
14874+ mov %cs, %esi
14875+ cmp $__KERNEL_CS, %esi
14876+ jz 3f
14877+ ljmp $__KERNEL_CS, $3f
14878+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
14879+2:
14880+#ifdef CONFIG_PARAVIRT
14881+ mov %esi, %eax
14882+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14883+#else
14884+ mov %esi, %cr0
14885+#endif
14886+3:
14887+#ifdef CONFIG_PARAVIRT
14888+ popl %ecx
14889+ popl %eax
14890+#endif
14891+ ret
14892+ENDPROC(pax_enter_kernel)
14893+
14894+ENTRY(pax_exit_kernel)
14895+#ifdef CONFIG_PARAVIRT
14896+ pushl %eax
14897+ pushl %ecx
14898+#endif
14899+ mov %cs, %esi
14900+ cmp $__KERNEXEC_KERNEL_CS, %esi
14901+ jnz 2f
14902+#ifdef CONFIG_PARAVIRT
14903+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
14904+ mov %eax, %esi
14905+#else
14906+ mov %cr0, %esi
14907+#endif
14908+ btr $16, %esi
14909+ ljmp $__KERNEL_CS, $1f
14910+1:
14911+#ifdef CONFIG_PARAVIRT
14912+ mov %esi, %eax
14913+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
14914+#else
14915+ mov %esi, %cr0
14916+#endif
14917+2:
14918+#ifdef CONFIG_PARAVIRT
14919+ popl %ecx
14920+ popl %eax
14921+#endif
14922+ ret
14923+ENDPROC(pax_exit_kernel)
14924+#endif
14925+
14926+.macro pax_erase_kstack
14927+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14928+ call pax_erase_kstack
14929+#endif
14930+.endm
14931+
14932+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14933+/*
14934+ * ebp: thread_info
14935+ * ecx, edx: can be clobbered
14936+ */
14937+ENTRY(pax_erase_kstack)
14938+ pushl %edi
14939+ pushl %eax
14940+
14941+ mov TI_lowest_stack(%ebp), %edi
14942+ mov $-0xBEEF, %eax
14943+ std
14944+
14945+1: mov %edi, %ecx
14946+ and $THREAD_SIZE_asm - 1, %ecx
14947+ shr $2, %ecx
14948+ repne scasl
14949+ jecxz 2f
14950+
14951+ cmp $2*16, %ecx
14952+ jc 2f
14953+
14954+ mov $2*16, %ecx
14955+ repe scasl
14956+ jecxz 2f
14957+ jne 1b
14958+
14959+2: cld
14960+ mov %esp, %ecx
14961+ sub %edi, %ecx
14962+ shr $2, %ecx
14963+ rep stosl
14964+
14965+ mov TI_task_thread_sp0(%ebp), %edi
14966+ sub $128, %edi
14967+ mov %edi, TI_lowest_stack(%ebp)
14968+
14969+ popl %eax
14970+ popl %edi
14971+ ret
14972+ENDPROC(pax_erase_kstack)
14973+#endif
14974+
14975+.macro __SAVE_ALL _DS
14976 cld
14977 PUSH_GS
14978 pushl_cfi %fs
14979@@ -205,7 +338,7 @@
14980 CFI_REL_OFFSET ecx, 0
14981 pushl_cfi %ebx
14982 CFI_REL_OFFSET ebx, 0
14983- movl $(__USER_DS), %edx
14984+ movl $\_DS, %edx
14985 movl %edx, %ds
14986 movl %edx, %es
14987 movl $(__KERNEL_PERCPU), %edx
14988@@ -213,6 +346,15 @@
14989 SET_KERNEL_GS %edx
14990 .endm
14991
14992+.macro SAVE_ALL
14993+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
14994+ __SAVE_ALL __KERNEL_DS
14995+ pax_enter_kernel
14996+#else
14997+ __SAVE_ALL __USER_DS
14998+#endif
14999+.endm
15000+
15001 .macro RESTORE_INT_REGS
15002 popl_cfi %ebx
15003 CFI_RESTORE ebx
15004@@ -296,7 +438,7 @@ ENTRY(ret_from_fork)
15005 popfl_cfi
15006 jmp syscall_exit
15007 CFI_ENDPROC
15008-END(ret_from_fork)
15009+ENDPROC(ret_from_fork)
15010
15011 /*
15012 * Interrupt exit functions should be protected against kprobes
15013@@ -329,7 +471,15 @@ ret_from_intr:
15014 andl $SEGMENT_RPL_MASK, %eax
15015 #endif
15016 cmpl $USER_RPL, %eax
15017+
15018+#ifdef CONFIG_PAX_KERNEXEC
15019+ jae resume_userspace
15020+
15021+ pax_exit_kernel
15022+ jmp resume_kernel
15023+#else
15024 jb resume_kernel # not returning to v8086 or userspace
15025+#endif
15026
15027 ENTRY(resume_userspace)
15028 LOCKDEP_SYS_EXIT
15029@@ -341,8 +491,8 @@ ENTRY(resume_userspace)
15030 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15031 # int/exception return?
15032 jne work_pending
15033- jmp restore_all
15034-END(ret_from_exception)
15035+ jmp restore_all_pax
15036+ENDPROC(ret_from_exception)
15037
15038 #ifdef CONFIG_PREEMPT
15039 ENTRY(resume_kernel)
15040@@ -357,7 +507,7 @@ need_resched:
15041 jz restore_all
15042 call preempt_schedule_irq
15043 jmp need_resched
15044-END(resume_kernel)
15045+ENDPROC(resume_kernel)
15046 #endif
15047 CFI_ENDPROC
15048 /*
15049@@ -391,23 +541,34 @@ sysenter_past_esp:
15050 /*CFI_REL_OFFSET cs, 0*/
15051 /*
15052 * Push current_thread_info()->sysenter_return to the stack.
15053- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15054- * pushed above; +8 corresponds to copy_thread's esp0 setting.
15055 */
15056- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15057+ pushl_cfi $0
15058 CFI_REL_OFFSET eip, 0
15059
15060 pushl_cfi %eax
15061 SAVE_ALL
15062+ GET_THREAD_INFO(%ebp)
15063+ movl TI_sysenter_return(%ebp),%ebp
15064+ movl %ebp,PT_EIP(%esp)
15065 ENABLE_INTERRUPTS(CLBR_NONE)
15066
15067 /*
15068 * Load the potential sixth argument from user stack.
15069 * Careful about security.
15070 */
15071+ movl PT_OLDESP(%esp),%ebp
15072+
15073+#ifdef CONFIG_PAX_MEMORY_UDEREF
15074+ mov PT_OLDSS(%esp),%ds
15075+1: movl %ds:(%ebp),%ebp
15076+ push %ss
15077+ pop %ds
15078+#else
15079 cmpl $__PAGE_OFFSET-3,%ebp
15080 jae syscall_fault
15081 1: movl (%ebp),%ebp
15082+#endif
15083+
15084 movl %ebp,PT_EBP(%esp)
15085 _ASM_EXTABLE(1b,syscall_fault)
15086
15087@@ -427,12 +588,24 @@ sysenter_do_call:
15088 testl $_TIF_ALLWORK_MASK, %ecx
15089 jne sysexit_audit
15090 sysenter_exit:
15091+
15092+#ifdef CONFIG_PAX_RANDKSTACK
15093+ pushl_cfi %eax
15094+ movl %esp, %eax
15095+ call pax_randomize_kstack
15096+ popl_cfi %eax
15097+#endif
15098+
15099+ pax_erase_kstack
15100+
15101 /* if something modifies registers it must also disable sysexit */
15102 movl PT_EIP(%esp), %edx
15103 movl PT_OLDESP(%esp), %ecx
15104 xorl %ebp,%ebp
15105 TRACE_IRQS_ON
15106 1: mov PT_FS(%esp), %fs
15107+2: mov PT_DS(%esp), %ds
15108+3: mov PT_ES(%esp), %es
15109 PTGS_TO_GS
15110 ENABLE_INTERRUPTS_SYSEXIT
15111
15112@@ -449,6 +622,9 @@ sysenter_audit:
15113 movl %eax,%edx /* 2nd arg: syscall number */
15114 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15115 call __audit_syscall_entry
15116+
15117+ pax_erase_kstack
15118+
15119 pushl_cfi %ebx
15120 movl PT_EAX(%esp),%eax /* reload syscall number */
15121 jmp sysenter_do_call
15122@@ -474,10 +650,16 @@ sysexit_audit:
15123
15124 CFI_ENDPROC
15125 .pushsection .fixup,"ax"
15126-2: movl $0,PT_FS(%esp)
15127+4: movl $0,PT_FS(%esp)
15128+ jmp 1b
15129+5: movl $0,PT_DS(%esp)
15130+ jmp 1b
15131+6: movl $0,PT_ES(%esp)
15132 jmp 1b
15133 .popsection
15134- _ASM_EXTABLE(1b,2b)
15135+ _ASM_EXTABLE(1b,4b)
15136+ _ASM_EXTABLE(2b,5b)
15137+ _ASM_EXTABLE(3b,6b)
15138 PTGS_TO_GS_EX
15139 ENDPROC(ia32_sysenter_target)
15140
15141@@ -509,6 +691,15 @@ syscall_exit:
15142 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15143 jne syscall_exit_work
15144
15145+restore_all_pax:
15146+
15147+#ifdef CONFIG_PAX_RANDKSTACK
15148+ movl %esp, %eax
15149+ call pax_randomize_kstack
15150+#endif
15151+
15152+ pax_erase_kstack
15153+
15154 restore_all:
15155 TRACE_IRQS_IRET
15156 restore_all_notrace:
15157@@ -565,14 +756,34 @@ ldt_ss:
15158 * compensating for the offset by changing to the ESPFIX segment with
15159 * a base address that matches for the difference.
15160 */
15161-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15162+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15163 mov %esp, %edx /* load kernel esp */
15164 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15165 mov %dx, %ax /* eax: new kernel esp */
15166 sub %eax, %edx /* offset (low word is 0) */
15167+#ifdef CONFIG_SMP
15168+ movl PER_CPU_VAR(cpu_number), %ebx
15169+ shll $PAGE_SHIFT_asm, %ebx
15170+ addl $cpu_gdt_table, %ebx
15171+#else
15172+ movl $cpu_gdt_table, %ebx
15173+#endif
15174 shr $16, %edx
15175- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15176- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15177+
15178+#ifdef CONFIG_PAX_KERNEXEC
15179+ mov %cr0, %esi
15180+ btr $16, %esi
15181+ mov %esi, %cr0
15182+#endif
15183+
15184+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15185+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15186+
15187+#ifdef CONFIG_PAX_KERNEXEC
15188+ bts $16, %esi
15189+ mov %esi, %cr0
15190+#endif
15191+
15192 pushl_cfi $__ESPFIX_SS
15193 pushl_cfi %eax /* new kernel esp */
15194 /* Disable interrupts, but do not irqtrace this section: we
15195@@ -601,35 +812,23 @@ work_resched:
15196 movl TI_flags(%ebp), %ecx
15197 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15198 # than syscall tracing?
15199- jz restore_all
15200+ jz restore_all_pax
15201 testb $_TIF_NEED_RESCHED, %cl
15202 jnz work_resched
15203
15204 work_notifysig: # deal with pending signals and
15205 # notify-resume requests
15206+ movl %esp, %eax
15207 #ifdef CONFIG_VM86
15208 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15209- movl %esp, %eax
15210- jne work_notifysig_v86 # returning to kernel-space or
15211+ jz 1f # returning to kernel-space or
15212 # vm86-space
15213- TRACE_IRQS_ON
15214- ENABLE_INTERRUPTS(CLBR_NONE)
15215- movb PT_CS(%esp), %bl
15216- andb $SEGMENT_RPL_MASK, %bl
15217- cmpb $USER_RPL, %bl
15218- jb resume_kernel
15219- xorl %edx, %edx
15220- call do_notify_resume
15221- jmp resume_userspace
15222
15223- ALIGN
15224-work_notifysig_v86:
15225 pushl_cfi %ecx # save ti_flags for do_notify_resume
15226 call save_v86_state # %eax contains pt_regs pointer
15227 popl_cfi %ecx
15228 movl %eax, %esp
15229-#else
15230- movl %esp, %eax
15231+1:
15232 #endif
15233 TRACE_IRQS_ON
15234 ENABLE_INTERRUPTS(CLBR_NONE)
15235@@ -640,7 +839,7 @@ work_notifysig_v86:
15236 xorl %edx, %edx
15237 call do_notify_resume
15238 jmp resume_userspace
15239-END(work_pending)
15240+ENDPROC(work_pending)
15241
15242 # perform syscall exit tracing
15243 ALIGN
15244@@ -648,11 +847,14 @@ syscall_trace_entry:
15245 movl $-ENOSYS,PT_EAX(%esp)
15246 movl %esp, %eax
15247 call syscall_trace_enter
15248+
15249+ pax_erase_kstack
15250+
15251 /* What it returned is what we'll actually use. */
15252 cmpl $(NR_syscalls), %eax
15253 jnae syscall_call
15254 jmp syscall_exit
15255-END(syscall_trace_entry)
15256+ENDPROC(syscall_trace_entry)
15257
15258 # perform syscall exit tracing
15259 ALIGN
15260@@ -665,20 +867,24 @@ syscall_exit_work:
15261 movl %esp, %eax
15262 call syscall_trace_leave
15263 jmp resume_userspace
15264-END(syscall_exit_work)
15265+ENDPROC(syscall_exit_work)
15266 CFI_ENDPROC
15267
15268 RING0_INT_FRAME # can't unwind into user space anyway
15269 syscall_fault:
15270+#ifdef CONFIG_PAX_MEMORY_UDEREF
15271+ push %ss
15272+ pop %ds
15273+#endif
15274 GET_THREAD_INFO(%ebp)
15275 movl $-EFAULT,PT_EAX(%esp)
15276 jmp resume_userspace
15277-END(syscall_fault)
15278+ENDPROC(syscall_fault)
15279
15280 syscall_badsys:
15281 movl $-ENOSYS,PT_EAX(%esp)
15282 jmp resume_userspace
15283-END(syscall_badsys)
15284+ENDPROC(syscall_badsys)
15285 CFI_ENDPROC
15286 /*
15287 * End of kprobes section
15288@@ -750,6 +956,36 @@ ENTRY(ptregs_clone)
15289 CFI_ENDPROC
15290 ENDPROC(ptregs_clone)
15291
15292+ ALIGN;
15293+ENTRY(kernel_execve)
15294+ CFI_STARTPROC
15295+ pushl_cfi %ebp
15296+ sub $PT_OLDSS+4,%esp
15297+ pushl_cfi %edi
15298+ pushl_cfi %ecx
15299+ pushl_cfi %eax
15300+ lea 3*4(%esp),%edi
15301+ mov $PT_OLDSS/4+1,%ecx
15302+ xorl %eax,%eax
15303+ rep stosl
15304+ popl_cfi %eax
15305+ popl_cfi %ecx
15306+ popl_cfi %edi
15307+ movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15308+ pushl_cfi %esp
15309+ call sys_execve
15310+ add $4,%esp
15311+ CFI_ADJUST_CFA_OFFSET -4
15312+ GET_THREAD_INFO(%ebp)
15313+ test %eax,%eax
15314+ jz syscall_exit
15315+ add $PT_OLDSS+4,%esp
15316+ CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15317+ popl_cfi %ebp
15318+ ret
15319+ CFI_ENDPROC
15320+ENDPROC(kernel_execve)
15321+
15322 .macro FIXUP_ESPFIX_STACK
15323 /*
15324 * Switch back for ESPFIX stack to the normal zerobased stack
15325@@ -759,8 +995,15 @@ ENDPROC(ptregs_clone)
15326 * normal stack and adjusts ESP with the matching offset.
15327 */
15328 /* fixup the stack */
15329- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15330- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15331+#ifdef CONFIG_SMP
15332+ movl PER_CPU_VAR(cpu_number), %ebx
15333+ shll $PAGE_SHIFT_asm, %ebx
15334+ addl $cpu_gdt_table, %ebx
15335+#else
15336+ movl $cpu_gdt_table, %ebx
15337+#endif
15338+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15339+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15340 shl $16, %eax
15341 addl %esp, %eax /* the adjusted stack pointer */
15342 pushl_cfi $__KERNEL_DS
15343@@ -813,7 +1056,7 @@ vector=vector+1
15344 .endr
15345 2: jmp common_interrupt
15346 .endr
15347-END(irq_entries_start)
15348+ENDPROC(irq_entries_start)
15349
15350 .previous
15351 END(interrupt)
15352@@ -861,7 +1104,7 @@ ENTRY(coprocessor_error)
15353 pushl_cfi $do_coprocessor_error
15354 jmp error_code
15355 CFI_ENDPROC
15356-END(coprocessor_error)
15357+ENDPROC(coprocessor_error)
15358
15359 ENTRY(simd_coprocessor_error)
15360 RING0_INT_FRAME
15361@@ -882,7 +1125,7 @@ ENTRY(simd_coprocessor_error)
15362 #endif
15363 jmp error_code
15364 CFI_ENDPROC
15365-END(simd_coprocessor_error)
15366+ENDPROC(simd_coprocessor_error)
15367
15368 ENTRY(device_not_available)
15369 RING0_INT_FRAME
15370@@ -890,18 +1133,18 @@ ENTRY(device_not_available)
15371 pushl_cfi $do_device_not_available
15372 jmp error_code
15373 CFI_ENDPROC
15374-END(device_not_available)
15375+ENDPROC(device_not_available)
15376
15377 #ifdef CONFIG_PARAVIRT
15378 ENTRY(native_iret)
15379 iret
15380 _ASM_EXTABLE(native_iret, iret_exc)
15381-END(native_iret)
15382+ENDPROC(native_iret)
15383
15384 ENTRY(native_irq_enable_sysexit)
15385 sti
15386 sysexit
15387-END(native_irq_enable_sysexit)
15388+ENDPROC(native_irq_enable_sysexit)
15389 #endif
15390
15391 ENTRY(overflow)
15392@@ -910,7 +1153,7 @@ ENTRY(overflow)
15393 pushl_cfi $do_overflow
15394 jmp error_code
15395 CFI_ENDPROC
15396-END(overflow)
15397+ENDPROC(overflow)
15398
15399 ENTRY(bounds)
15400 RING0_INT_FRAME
15401@@ -918,7 +1161,7 @@ ENTRY(bounds)
15402 pushl_cfi $do_bounds
15403 jmp error_code
15404 CFI_ENDPROC
15405-END(bounds)
15406+ENDPROC(bounds)
15407
15408 ENTRY(invalid_op)
15409 RING0_INT_FRAME
15410@@ -926,7 +1169,7 @@ ENTRY(invalid_op)
15411 pushl_cfi $do_invalid_op
15412 jmp error_code
15413 CFI_ENDPROC
15414-END(invalid_op)
15415+ENDPROC(invalid_op)
15416
15417 ENTRY(coprocessor_segment_overrun)
15418 RING0_INT_FRAME
15419@@ -934,35 +1177,35 @@ ENTRY(coprocessor_segment_overrun)
15420 pushl_cfi $do_coprocessor_segment_overrun
15421 jmp error_code
15422 CFI_ENDPROC
15423-END(coprocessor_segment_overrun)
15424+ENDPROC(coprocessor_segment_overrun)
15425
15426 ENTRY(invalid_TSS)
15427 RING0_EC_FRAME
15428 pushl_cfi $do_invalid_TSS
15429 jmp error_code
15430 CFI_ENDPROC
15431-END(invalid_TSS)
15432+ENDPROC(invalid_TSS)
15433
15434 ENTRY(segment_not_present)
15435 RING0_EC_FRAME
15436 pushl_cfi $do_segment_not_present
15437 jmp error_code
15438 CFI_ENDPROC
15439-END(segment_not_present)
15440+ENDPROC(segment_not_present)
15441
15442 ENTRY(stack_segment)
15443 RING0_EC_FRAME
15444 pushl_cfi $do_stack_segment
15445 jmp error_code
15446 CFI_ENDPROC
15447-END(stack_segment)
15448+ENDPROC(stack_segment)
15449
15450 ENTRY(alignment_check)
15451 RING0_EC_FRAME
15452 pushl_cfi $do_alignment_check
15453 jmp error_code
15454 CFI_ENDPROC
15455-END(alignment_check)
15456+ENDPROC(alignment_check)
15457
15458 ENTRY(divide_error)
15459 RING0_INT_FRAME
15460@@ -970,7 +1213,7 @@ ENTRY(divide_error)
15461 pushl_cfi $do_divide_error
15462 jmp error_code
15463 CFI_ENDPROC
15464-END(divide_error)
15465+ENDPROC(divide_error)
15466
15467 #ifdef CONFIG_X86_MCE
15468 ENTRY(machine_check)
15469@@ -979,7 +1222,7 @@ ENTRY(machine_check)
15470 pushl_cfi machine_check_vector
15471 jmp error_code
15472 CFI_ENDPROC
15473-END(machine_check)
15474+ENDPROC(machine_check)
15475 #endif
15476
15477 ENTRY(spurious_interrupt_bug)
15478@@ -988,7 +1231,7 @@ ENTRY(spurious_interrupt_bug)
15479 pushl_cfi $do_spurious_interrupt_bug
15480 jmp error_code
15481 CFI_ENDPROC
15482-END(spurious_interrupt_bug)
15483+ENDPROC(spurious_interrupt_bug)
15484 /*
15485 * End of kprobes section
15486 */
15487@@ -1100,7 +1343,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15488
15489 ENTRY(mcount)
15490 ret
15491-END(mcount)
15492+ENDPROC(mcount)
15493
15494 ENTRY(ftrace_caller)
15495 cmpl $0, function_trace_stop
15496@@ -1129,7 +1372,7 @@ ftrace_graph_call:
15497 .globl ftrace_stub
15498 ftrace_stub:
15499 ret
15500-END(ftrace_caller)
15501+ENDPROC(ftrace_caller)
15502
15503 #else /* ! CONFIG_DYNAMIC_FTRACE */
15504
15505@@ -1165,7 +1408,7 @@ trace:
15506 popl %ecx
15507 popl %eax
15508 jmp ftrace_stub
15509-END(mcount)
15510+ENDPROC(mcount)
15511 #endif /* CONFIG_DYNAMIC_FTRACE */
15512 #endif /* CONFIG_FUNCTION_TRACER */
15513
15514@@ -1186,7 +1429,7 @@ ENTRY(ftrace_graph_caller)
15515 popl %ecx
15516 popl %eax
15517 ret
15518-END(ftrace_graph_caller)
15519+ENDPROC(ftrace_graph_caller)
15520
15521 .globl return_to_handler
15522 return_to_handler:
15523@@ -1241,15 +1484,18 @@ error_code:
15524 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15525 REG_TO_PTGS %ecx
15526 SET_KERNEL_GS %ecx
15527- movl $(__USER_DS), %ecx
15528+ movl $(__KERNEL_DS), %ecx
15529 movl %ecx, %ds
15530 movl %ecx, %es
15531+
15532+ pax_enter_kernel
15533+
15534 TRACE_IRQS_OFF
15535 movl %esp,%eax # pt_regs pointer
15536 call *%edi
15537 jmp ret_from_exception
15538 CFI_ENDPROC
15539-END(page_fault)
15540+ENDPROC(page_fault)
15541
15542 /*
15543 * Debug traps and NMI can happen at the one SYSENTER instruction
15544@@ -1291,7 +1537,7 @@ debug_stack_correct:
15545 call do_debug
15546 jmp ret_from_exception
15547 CFI_ENDPROC
15548-END(debug)
15549+ENDPROC(debug)
15550
15551 /*
15552 * NMI is doubly nasty. It can happen _while_ we're handling
15553@@ -1328,6 +1574,9 @@ nmi_stack_correct:
15554 xorl %edx,%edx # zero error code
15555 movl %esp,%eax # pt_regs pointer
15556 call do_nmi
15557+
15558+ pax_exit_kernel
15559+
15560 jmp restore_all_notrace
15561 CFI_ENDPROC
15562
15563@@ -1364,12 +1613,15 @@ nmi_espfix_stack:
15564 FIXUP_ESPFIX_STACK # %eax == %esp
15565 xorl %edx,%edx # zero error code
15566 call do_nmi
15567+
15568+ pax_exit_kernel
15569+
15570 RESTORE_REGS
15571 lss 12+4(%esp), %esp # back to espfix stack
15572 CFI_ADJUST_CFA_OFFSET -24
15573 jmp irq_return
15574 CFI_ENDPROC
15575-END(nmi)
15576+ENDPROC(nmi)
15577
15578 ENTRY(int3)
15579 RING0_INT_FRAME
15580@@ -1381,14 +1633,14 @@ ENTRY(int3)
15581 call do_int3
15582 jmp ret_from_exception
15583 CFI_ENDPROC
15584-END(int3)
15585+ENDPROC(int3)
15586
15587 ENTRY(general_protection)
15588 RING0_EC_FRAME
15589 pushl_cfi $do_general_protection
15590 jmp error_code
15591 CFI_ENDPROC
15592-END(general_protection)
15593+ENDPROC(general_protection)
15594
15595 #ifdef CONFIG_KVM_GUEST
15596 ENTRY(async_page_fault)
15597@@ -1396,7 +1648,7 @@ ENTRY(async_page_fault)
15598 pushl_cfi $do_async_page_fault
15599 jmp error_code
15600 CFI_ENDPROC
15601-END(async_page_fault)
15602+ENDPROC(async_page_fault)
15603 #endif
15604
15605 /*
15606diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15607index 7d65133..27bce5b 100644
15608--- a/arch/x86/kernel/entry_64.S
15609+++ b/arch/x86/kernel/entry_64.S
15610@@ -57,6 +57,8 @@
15611 #include <asm/percpu.h>
15612 #include <asm/asm.h>
15613 #include <linux/err.h>
15614+#include <asm/pgtable.h>
15615+#include <asm/alternative-asm.h>
15616
15617 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15618 #include <linux/elf-em.h>
15619@@ -70,8 +72,9 @@
15620 #ifdef CONFIG_FUNCTION_TRACER
15621 #ifdef CONFIG_DYNAMIC_FTRACE
15622 ENTRY(mcount)
15623+ pax_force_retaddr
15624 retq
15625-END(mcount)
15626+ENDPROC(mcount)
15627
15628 ENTRY(ftrace_caller)
15629 cmpl $0, function_trace_stop
15630@@ -94,8 +97,9 @@ GLOBAL(ftrace_graph_call)
15631 #endif
15632
15633 GLOBAL(ftrace_stub)
15634+ pax_force_retaddr
15635 retq
15636-END(ftrace_caller)
15637+ENDPROC(ftrace_caller)
15638
15639 #else /* ! CONFIG_DYNAMIC_FTRACE */
15640 ENTRY(mcount)
15641@@ -114,6 +118,7 @@ ENTRY(mcount)
15642 #endif
15643
15644 GLOBAL(ftrace_stub)
15645+ pax_force_retaddr
15646 retq
15647
15648 trace:
15649@@ -123,12 +128,13 @@ trace:
15650 movq 8(%rbp), %rsi
15651 subq $MCOUNT_INSN_SIZE, %rdi
15652
15653+ pax_force_fptr ftrace_trace_function
15654 call *ftrace_trace_function
15655
15656 MCOUNT_RESTORE_FRAME
15657
15658 jmp ftrace_stub
15659-END(mcount)
15660+ENDPROC(mcount)
15661 #endif /* CONFIG_DYNAMIC_FTRACE */
15662 #endif /* CONFIG_FUNCTION_TRACER */
15663
15664@@ -148,8 +154,9 @@ ENTRY(ftrace_graph_caller)
15665
15666 MCOUNT_RESTORE_FRAME
15667
15668+ pax_force_retaddr
15669 retq
15670-END(ftrace_graph_caller)
15671+ENDPROC(ftrace_graph_caller)
15672
15673 GLOBAL(return_to_handler)
15674 subq $24, %rsp
15675@@ -165,6 +172,7 @@ GLOBAL(return_to_handler)
15676 movq 8(%rsp), %rdx
15677 movq (%rsp), %rax
15678 addq $24, %rsp
15679+ pax_force_fptr %rdi
15680 jmp *%rdi
15681 #endif
15682
15683@@ -180,6 +188,282 @@ ENTRY(native_usergs_sysret64)
15684 ENDPROC(native_usergs_sysret64)
15685 #endif /* CONFIG_PARAVIRT */
15686
15687+ .macro ljmpq sel, off
15688+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15689+ .byte 0x48; ljmp *1234f(%rip)
15690+ .pushsection .rodata
15691+ .align 16
15692+ 1234: .quad \off; .word \sel
15693+ .popsection
15694+#else
15695+ pushq $\sel
15696+ pushq $\off
15697+ lretq
15698+#endif
15699+ .endm
15700+
15701+ .macro pax_enter_kernel
15702+ pax_set_fptr_mask
15703+#ifdef CONFIG_PAX_KERNEXEC
15704+ call pax_enter_kernel
15705+#endif
15706+ .endm
15707+
15708+ .macro pax_exit_kernel
15709+#ifdef CONFIG_PAX_KERNEXEC
15710+ call pax_exit_kernel
15711+#endif
15712+ .endm
15713+
15714+#ifdef CONFIG_PAX_KERNEXEC
15715+ENTRY(pax_enter_kernel)
15716+ pushq %rdi
15717+
15718+#ifdef CONFIG_PARAVIRT
15719+ PV_SAVE_REGS(CLBR_RDI)
15720+#endif
15721+
15722+ GET_CR0_INTO_RDI
15723+ bts $16,%rdi
15724+ jnc 3f
15725+ mov %cs,%edi
15726+ cmp $__KERNEL_CS,%edi
15727+ jnz 2f
15728+1:
15729+
15730+#ifdef CONFIG_PARAVIRT
15731+ PV_RESTORE_REGS(CLBR_RDI)
15732+#endif
15733+
15734+ popq %rdi
15735+ pax_force_retaddr
15736+ retq
15737+
15738+2: ljmpq __KERNEL_CS,1f
15739+3: ljmpq __KERNEXEC_KERNEL_CS,4f
15740+4: SET_RDI_INTO_CR0
15741+ jmp 1b
15742+ENDPROC(pax_enter_kernel)
15743+
15744+ENTRY(pax_exit_kernel)
15745+ pushq %rdi
15746+
15747+#ifdef CONFIG_PARAVIRT
15748+ PV_SAVE_REGS(CLBR_RDI)
15749+#endif
15750+
15751+ mov %cs,%rdi
15752+ cmp $__KERNEXEC_KERNEL_CS,%edi
15753+ jz 2f
15754+1:
15755+
15756+#ifdef CONFIG_PARAVIRT
15757+ PV_RESTORE_REGS(CLBR_RDI);
15758+#endif
15759+
15760+ popq %rdi
15761+ pax_force_retaddr
15762+ retq
15763+
15764+2: GET_CR0_INTO_RDI
15765+ btr $16,%rdi
15766+ ljmpq __KERNEL_CS,3f
15767+3: SET_RDI_INTO_CR0
15768+ jmp 1b
15769+#ifdef CONFIG_PARAVIRT
15770+ PV_RESTORE_REGS(CLBR_RDI);
15771+#endif
15772+
15773+ popq %rdi
15774+ pax_force_retaddr
15775+ retq
15776+ENDPROC(pax_exit_kernel)
15777+#endif
15778+
15779+ .macro pax_enter_kernel_user
15780+ pax_set_fptr_mask
15781+#ifdef CONFIG_PAX_MEMORY_UDEREF
15782+ call pax_enter_kernel_user
15783+#endif
15784+ .endm
15785+
15786+ .macro pax_exit_kernel_user
15787+#ifdef CONFIG_PAX_MEMORY_UDEREF
15788+ call pax_exit_kernel_user
15789+#endif
15790+#ifdef CONFIG_PAX_RANDKSTACK
15791+ pushq %rax
15792+ call pax_randomize_kstack
15793+ popq %rax
15794+#endif
15795+ .endm
15796+
15797+#ifdef CONFIG_PAX_MEMORY_UDEREF
15798+ENTRY(pax_enter_kernel_user)
15799+ pushq %rdi
15800+ pushq %rbx
15801+
15802+#ifdef CONFIG_PARAVIRT
15803+ PV_SAVE_REGS(CLBR_RDI)
15804+#endif
15805+
15806+ GET_CR3_INTO_RDI
15807+ mov %rdi,%rbx
15808+ add $__START_KERNEL_map,%rbx
15809+ sub phys_base(%rip),%rbx
15810+
15811+#ifdef CONFIG_PARAVIRT
15812+ pushq %rdi
15813+ cmpl $0, pv_info+PARAVIRT_enabled
15814+ jz 1f
15815+ i = 0
15816+ .rept USER_PGD_PTRS
15817+ mov i*8(%rbx),%rsi
15818+ mov $0,%sil
15819+ lea i*8(%rbx),%rdi
15820+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15821+ i = i + 1
15822+ .endr
15823+ jmp 2f
15824+1:
15825+#endif
15826+
15827+ i = 0
15828+ .rept USER_PGD_PTRS
15829+ movb $0,i*8(%rbx)
15830+ i = i + 1
15831+ .endr
15832+
15833+#ifdef CONFIG_PARAVIRT
15834+2: popq %rdi
15835+#endif
15836+ SET_RDI_INTO_CR3
15837+
15838+#ifdef CONFIG_PAX_KERNEXEC
15839+ GET_CR0_INTO_RDI
15840+ bts $16,%rdi
15841+ SET_RDI_INTO_CR0
15842+#endif
15843+
15844+#ifdef CONFIG_PARAVIRT
15845+ PV_RESTORE_REGS(CLBR_RDI)
15846+#endif
15847+
15848+ popq %rbx
15849+ popq %rdi
15850+ pax_force_retaddr
15851+ retq
15852+ENDPROC(pax_enter_kernel_user)
15853+
15854+ENTRY(pax_exit_kernel_user)
15855+ push %rdi
15856+
15857+#ifdef CONFIG_PARAVIRT
15858+ pushq %rbx
15859+ PV_SAVE_REGS(CLBR_RDI)
15860+#endif
15861+
15862+#ifdef CONFIG_PAX_KERNEXEC
15863+ GET_CR0_INTO_RDI
15864+ btr $16,%rdi
15865+ SET_RDI_INTO_CR0
15866+#endif
15867+
15868+ GET_CR3_INTO_RDI
15869+ add $__START_KERNEL_map,%rdi
15870+ sub phys_base(%rip),%rdi
15871+
15872+#ifdef CONFIG_PARAVIRT
15873+ cmpl $0, pv_info+PARAVIRT_enabled
15874+ jz 1f
15875+ mov %rdi,%rbx
15876+ i = 0
15877+ .rept USER_PGD_PTRS
15878+ mov i*8(%rbx),%rsi
15879+ mov $0x67,%sil
15880+ lea i*8(%rbx),%rdi
15881+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15882+ i = i + 1
15883+ .endr
15884+ jmp 2f
15885+1:
15886+#endif
15887+
15888+ i = 0
15889+ .rept USER_PGD_PTRS
15890+ movb $0x67,i*8(%rdi)
15891+ i = i + 1
15892+ .endr
15893+
15894+#ifdef CONFIG_PARAVIRT
15895+2: PV_RESTORE_REGS(CLBR_RDI)
15896+ popq %rbx
15897+#endif
15898+
15899+ popq %rdi
15900+ pax_force_retaddr
15901+ retq
15902+ENDPROC(pax_exit_kernel_user)
15903+#endif
15904+
15905+.macro pax_erase_kstack
15906+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15907+ call pax_erase_kstack
15908+#endif
15909+.endm
15910+
15911+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15912+/*
15913+ * r11: thread_info
15914+ * rcx, rdx: can be clobbered
15915+ */
15916+ENTRY(pax_erase_kstack)
15917+ pushq %rdi
15918+ pushq %rax
15919+ pushq %r11
15920+
15921+ GET_THREAD_INFO(%r11)
15922+ mov TI_lowest_stack(%r11), %rdi
15923+ mov $-0xBEEF, %rax
15924+ std
15925+
15926+1: mov %edi, %ecx
15927+ and $THREAD_SIZE_asm - 1, %ecx
15928+ shr $3, %ecx
15929+ repne scasq
15930+ jecxz 2f
15931+
15932+ cmp $2*8, %ecx
15933+ jc 2f
15934+
15935+ mov $2*8, %ecx
15936+ repe scasq
15937+ jecxz 2f
15938+ jne 1b
15939+
15940+2: cld
15941+ mov %esp, %ecx
15942+ sub %edi, %ecx
15943+
15944+ cmp $THREAD_SIZE_asm, %rcx
15945+ jb 3f
15946+ ud2
15947+3:
15948+
15949+ shr $3, %ecx
15950+ rep stosq
15951+
15952+ mov TI_task_thread_sp0(%r11), %rdi
15953+ sub $256, %rdi
15954+ mov %rdi, TI_lowest_stack(%r11)
15955+
15956+ popq %r11
15957+ popq %rax
15958+ popq %rdi
15959+ pax_force_retaddr
15960+ ret
15961+ENDPROC(pax_erase_kstack)
15962+#endif
15963
15964 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
15965 #ifdef CONFIG_TRACE_IRQFLAGS
15966@@ -271,8 +555,8 @@ ENDPROC(native_usergs_sysret64)
15967 .endm
15968
15969 .macro UNFAKE_STACK_FRAME
15970- addq $8*6, %rsp
15971- CFI_ADJUST_CFA_OFFSET -(6*8)
15972+ addq $8*6 + ARG_SKIP, %rsp
15973+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
15974 .endm
15975
15976 /*
15977@@ -359,7 +643,7 @@ ENDPROC(native_usergs_sysret64)
15978 movq %rsp, %rsi
15979
15980 leaq -RBP(%rsp),%rdi /* arg1 for handler */
15981- testl $3, CS-RBP(%rsi)
15982+ testb $3, CS-RBP(%rsi)
15983 je 1f
15984 SWAPGS
15985 /*
15986@@ -394,9 +678,10 @@ ENTRY(save_rest)
15987 movq_cfi r15, R15+16
15988 movq %r11, 8(%rsp) /* return address */
15989 FIXUP_TOP_OF_STACK %r11, 16
15990+ pax_force_retaddr
15991 ret
15992 CFI_ENDPROC
15993-END(save_rest)
15994+ENDPROC(save_rest)
15995
15996 /* save complete stack frame */
15997 .pushsection .kprobes.text, "ax"
15998@@ -425,9 +710,10 @@ ENTRY(save_paranoid)
15999 js 1f /* negative -> in kernel */
16000 SWAPGS
16001 xorl %ebx,%ebx
16002-1: ret
16003+1: pax_force_retaddr_bts
16004+ ret
16005 CFI_ENDPROC
16006-END(save_paranoid)
16007+ENDPROC(save_paranoid)
16008 .popsection
16009
16010 /*
16011@@ -449,7 +735,7 @@ ENTRY(ret_from_fork)
16012
16013 RESTORE_REST
16014
16015- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16016+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16017 jz retint_restore_args
16018
16019 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16020@@ -459,7 +745,7 @@ ENTRY(ret_from_fork)
16021 jmp ret_from_sys_call # go to the SYSRET fastpath
16022
16023 CFI_ENDPROC
16024-END(ret_from_fork)
16025+ENDPROC(ret_from_fork)
16026
16027 /*
16028 * System call entry. Up to 6 arguments in registers are supported.
16029@@ -495,7 +781,7 @@ END(ret_from_fork)
16030 ENTRY(system_call)
16031 CFI_STARTPROC simple
16032 CFI_SIGNAL_FRAME
16033- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16034+ CFI_DEF_CFA rsp,0
16035 CFI_REGISTER rip,rcx
16036 /*CFI_REGISTER rflags,r11*/
16037 SWAPGS_UNSAFE_STACK
16038@@ -508,16 +794,18 @@ GLOBAL(system_call_after_swapgs)
16039
16040 movq %rsp,PER_CPU_VAR(old_rsp)
16041 movq PER_CPU_VAR(kernel_stack),%rsp
16042+ SAVE_ARGS 8*6,0
16043+ pax_enter_kernel_user
16044 /*
16045 * No need to follow this irqs off/on section - it's straight
16046 * and short:
16047 */
16048 ENABLE_INTERRUPTS(CLBR_NONE)
16049- SAVE_ARGS 8,0
16050 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16051 movq %rcx,RIP-ARGOFFSET(%rsp)
16052 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16053- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16054+ GET_THREAD_INFO(%rcx)
16055+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16056 jnz tracesys
16057 system_call_fastpath:
16058 #if __SYSCALL_MASK == ~0
16059@@ -527,7 +815,7 @@ system_call_fastpath:
16060 cmpl $__NR_syscall_max,%eax
16061 #endif
16062 ja badsys
16063- movq %r10,%rcx
16064+ movq R10-ARGOFFSET(%rsp),%rcx
16065 call *sys_call_table(,%rax,8) # XXX: rip relative
16066 movq %rax,RAX-ARGOFFSET(%rsp)
16067 /*
16068@@ -541,10 +829,13 @@ sysret_check:
16069 LOCKDEP_SYS_EXIT
16070 DISABLE_INTERRUPTS(CLBR_NONE)
16071 TRACE_IRQS_OFF
16072- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16073+ GET_THREAD_INFO(%rcx)
16074+ movl TI_flags(%rcx),%edx
16075 andl %edi,%edx
16076 jnz sysret_careful
16077 CFI_REMEMBER_STATE
16078+ pax_exit_kernel_user
16079+ pax_erase_kstack
16080 /*
16081 * sysretq will re-enable interrupts:
16082 */
16083@@ -596,14 +887,18 @@ badsys:
16084 * jump back to the normal fast path.
16085 */
16086 auditsys:
16087- movq %r10,%r9 /* 6th arg: 4th syscall arg */
16088+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16089 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16090 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16091 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16092 movq %rax,%rsi /* 2nd arg: syscall number */
16093 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16094 call __audit_syscall_entry
16095+
16096+ pax_erase_kstack
16097+
16098 LOAD_ARGS 0 /* reload call-clobbered registers */
16099+ pax_set_fptr_mask
16100 jmp system_call_fastpath
16101
16102 /*
16103@@ -624,7 +919,7 @@ sysret_audit:
16104 /* Do syscall tracing */
16105 tracesys:
16106 #ifdef CONFIG_AUDITSYSCALL
16107- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16108+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16109 jz auditsys
16110 #endif
16111 SAVE_REST
16112@@ -632,12 +927,16 @@ tracesys:
16113 FIXUP_TOP_OF_STACK %rdi
16114 movq %rsp,%rdi
16115 call syscall_trace_enter
16116+
16117+ pax_erase_kstack
16118+
16119 /*
16120 * Reload arg registers from stack in case ptrace changed them.
16121 * We don't reload %rax because syscall_trace_enter() returned
16122 * the value it wants us to use in the table lookup.
16123 */
16124 LOAD_ARGS ARGOFFSET, 1
16125+ pax_set_fptr_mask
16126 RESTORE_REST
16127 #if __SYSCALL_MASK == ~0
16128 cmpq $__NR_syscall_max,%rax
16129@@ -646,7 +945,7 @@ tracesys:
16130 cmpl $__NR_syscall_max,%eax
16131 #endif
16132 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16133- movq %r10,%rcx /* fixup for C */
16134+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16135 call *sys_call_table(,%rax,8)
16136 movq %rax,RAX-ARGOFFSET(%rsp)
16137 /* Use IRET because user could have changed frame */
16138@@ -667,6 +966,7 @@ GLOBAL(int_with_check)
16139 andl %edi,%edx
16140 jnz int_careful
16141 andl $~TS_COMPAT,TI_status(%rcx)
16142+ pax_erase_kstack
16143 jmp retint_swapgs
16144
16145 /* Either reschedule or signal or syscall exit tracking needed. */
16146@@ -713,7 +1013,7 @@ int_restore_rest:
16147 TRACE_IRQS_OFF
16148 jmp int_with_check
16149 CFI_ENDPROC
16150-END(system_call)
16151+ENDPROC(system_call)
16152
16153 /*
16154 * Certain special system calls that need to save a complete full stack frame.
16155@@ -729,7 +1029,7 @@ ENTRY(\label)
16156 call \func
16157 jmp ptregscall_common
16158 CFI_ENDPROC
16159-END(\label)
16160+ENDPROC(\label)
16161 .endm
16162
16163 PTREGSCALL stub_clone, sys_clone, %r8
16164@@ -747,9 +1047,10 @@ ENTRY(ptregscall_common)
16165 movq_cfi_restore R12+8, r12
16166 movq_cfi_restore RBP+8, rbp
16167 movq_cfi_restore RBX+8, rbx
16168+ pax_force_retaddr
16169 ret $REST_SKIP /* pop extended registers */
16170 CFI_ENDPROC
16171-END(ptregscall_common)
16172+ENDPROC(ptregscall_common)
16173
16174 ENTRY(stub_execve)
16175 CFI_STARTPROC
16176@@ -764,7 +1065,7 @@ ENTRY(stub_execve)
16177 RESTORE_REST
16178 jmp int_ret_from_sys_call
16179 CFI_ENDPROC
16180-END(stub_execve)
16181+ENDPROC(stub_execve)
16182
16183 /*
16184 * sigreturn is special because it needs to restore all registers on return.
16185@@ -782,7 +1083,7 @@ ENTRY(stub_rt_sigreturn)
16186 RESTORE_REST
16187 jmp int_ret_from_sys_call
16188 CFI_ENDPROC
16189-END(stub_rt_sigreturn)
16190+ENDPROC(stub_rt_sigreturn)
16191
16192 #ifdef CONFIG_X86_X32_ABI
16193 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16194@@ -851,7 +1152,7 @@ vector=vector+1
16195 2: jmp common_interrupt
16196 .endr
16197 CFI_ENDPROC
16198-END(irq_entries_start)
16199+ENDPROC(irq_entries_start)
16200
16201 .previous
16202 END(interrupt)
16203@@ -871,6 +1172,16 @@ END(interrupt)
16204 subq $ORIG_RAX-RBP, %rsp
16205 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16206 SAVE_ARGS_IRQ
16207+#ifdef CONFIG_PAX_MEMORY_UDEREF
16208+ testb $3, CS(%rdi)
16209+ jnz 1f
16210+ pax_enter_kernel
16211+ jmp 2f
16212+1: pax_enter_kernel_user
16213+2:
16214+#else
16215+ pax_enter_kernel
16216+#endif
16217 call \func
16218 .endm
16219
16220@@ -902,7 +1213,7 @@ ret_from_intr:
16221
16222 exit_intr:
16223 GET_THREAD_INFO(%rcx)
16224- testl $3,CS-ARGOFFSET(%rsp)
16225+ testb $3,CS-ARGOFFSET(%rsp)
16226 je retint_kernel
16227
16228 /* Interrupt came from user space */
16229@@ -924,12 +1235,15 @@ retint_swapgs: /* return to user-space */
16230 * The iretq could re-enable interrupts:
16231 */
16232 DISABLE_INTERRUPTS(CLBR_ANY)
16233+ pax_exit_kernel_user
16234 TRACE_IRQS_IRETQ
16235 SWAPGS
16236 jmp restore_args
16237
16238 retint_restore_args: /* return to kernel space */
16239 DISABLE_INTERRUPTS(CLBR_ANY)
16240+ pax_exit_kernel
16241+ pax_force_retaddr RIP-ARGOFFSET
16242 /*
16243 * The iretq could re-enable interrupts:
16244 */
16245@@ -1012,7 +1326,7 @@ ENTRY(retint_kernel)
16246 #endif
16247
16248 CFI_ENDPROC
16249-END(common_interrupt)
16250+ENDPROC(common_interrupt)
16251 /*
16252 * End of kprobes section
16253 */
16254@@ -1029,7 +1343,7 @@ ENTRY(\sym)
16255 interrupt \do_sym
16256 jmp ret_from_intr
16257 CFI_ENDPROC
16258-END(\sym)
16259+ENDPROC(\sym)
16260 .endm
16261
16262 #ifdef CONFIG_SMP
16263@@ -1102,12 +1416,22 @@ ENTRY(\sym)
16264 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16265 call error_entry
16266 DEFAULT_FRAME 0
16267+#ifdef CONFIG_PAX_MEMORY_UDEREF
16268+ testb $3, CS(%rsp)
16269+ jnz 1f
16270+ pax_enter_kernel
16271+ jmp 2f
16272+1: pax_enter_kernel_user
16273+2:
16274+#else
16275+ pax_enter_kernel
16276+#endif
16277 movq %rsp,%rdi /* pt_regs pointer */
16278 xorl %esi,%esi /* no error code */
16279 call \do_sym
16280 jmp error_exit /* %ebx: no swapgs flag */
16281 CFI_ENDPROC
16282-END(\sym)
16283+ENDPROC(\sym)
16284 .endm
16285
16286 .macro paranoidzeroentry sym do_sym
16287@@ -1119,15 +1443,25 @@ ENTRY(\sym)
16288 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16289 call save_paranoid
16290 TRACE_IRQS_OFF
16291+#ifdef CONFIG_PAX_MEMORY_UDEREF
16292+ testb $3, CS(%rsp)
16293+ jnz 1f
16294+ pax_enter_kernel
16295+ jmp 2f
16296+1: pax_enter_kernel_user
16297+2:
16298+#else
16299+ pax_enter_kernel
16300+#endif
16301 movq %rsp,%rdi /* pt_regs pointer */
16302 xorl %esi,%esi /* no error code */
16303 call \do_sym
16304 jmp paranoid_exit /* %ebx: no swapgs flag */
16305 CFI_ENDPROC
16306-END(\sym)
16307+ENDPROC(\sym)
16308 .endm
16309
16310-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16311+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16312 .macro paranoidzeroentry_ist sym do_sym ist
16313 ENTRY(\sym)
16314 INTR_FRAME
16315@@ -1137,14 +1471,30 @@ ENTRY(\sym)
16316 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16317 call save_paranoid
16318 TRACE_IRQS_OFF_DEBUG
16319+#ifdef CONFIG_PAX_MEMORY_UDEREF
16320+ testb $3, CS(%rsp)
16321+ jnz 1f
16322+ pax_enter_kernel
16323+ jmp 2f
16324+1: pax_enter_kernel_user
16325+2:
16326+#else
16327+ pax_enter_kernel
16328+#endif
16329 movq %rsp,%rdi /* pt_regs pointer */
16330 xorl %esi,%esi /* no error code */
16331+#ifdef CONFIG_SMP
16332+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16333+ lea init_tss(%r12), %r12
16334+#else
16335+ lea init_tss(%rip), %r12
16336+#endif
16337 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16338 call \do_sym
16339 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16340 jmp paranoid_exit /* %ebx: no swapgs flag */
16341 CFI_ENDPROC
16342-END(\sym)
16343+ENDPROC(\sym)
16344 .endm
16345
16346 .macro errorentry sym do_sym
16347@@ -1155,13 +1505,23 @@ ENTRY(\sym)
16348 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16349 call error_entry
16350 DEFAULT_FRAME 0
16351+#ifdef CONFIG_PAX_MEMORY_UDEREF
16352+ testb $3, CS(%rsp)
16353+ jnz 1f
16354+ pax_enter_kernel
16355+ jmp 2f
16356+1: pax_enter_kernel_user
16357+2:
16358+#else
16359+ pax_enter_kernel
16360+#endif
16361 movq %rsp,%rdi /* pt_regs pointer */
16362 movq ORIG_RAX(%rsp),%rsi /* get error code */
16363 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16364 call \do_sym
16365 jmp error_exit /* %ebx: no swapgs flag */
16366 CFI_ENDPROC
16367-END(\sym)
16368+ENDPROC(\sym)
16369 .endm
16370
16371 /* error code is on the stack already */
16372@@ -1174,13 +1534,23 @@ ENTRY(\sym)
16373 call save_paranoid
16374 DEFAULT_FRAME 0
16375 TRACE_IRQS_OFF
16376+#ifdef CONFIG_PAX_MEMORY_UDEREF
16377+ testb $3, CS(%rsp)
16378+ jnz 1f
16379+ pax_enter_kernel
16380+ jmp 2f
16381+1: pax_enter_kernel_user
16382+2:
16383+#else
16384+ pax_enter_kernel
16385+#endif
16386 movq %rsp,%rdi /* pt_regs pointer */
16387 movq ORIG_RAX(%rsp),%rsi /* get error code */
16388 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16389 call \do_sym
16390 jmp paranoid_exit /* %ebx: no swapgs flag */
16391 CFI_ENDPROC
16392-END(\sym)
16393+ENDPROC(\sym)
16394 .endm
16395
16396 zeroentry divide_error do_divide_error
16397@@ -1210,9 +1580,10 @@ gs_change:
16398 2: mfence /* workaround */
16399 SWAPGS
16400 popfq_cfi
16401+ pax_force_retaddr
16402 ret
16403 CFI_ENDPROC
16404-END(native_load_gs_index)
16405+ENDPROC(native_load_gs_index)
16406
16407 _ASM_EXTABLE(gs_change,bad_gs)
16408 .section .fixup,"ax"
16409@@ -1231,13 +1602,14 @@ ENTRY(kernel_thread_helper)
16410 * Here we are in the child and the registers are set as they were
16411 * at kernel_thread() invocation in the parent.
16412 */
16413+ pax_force_fptr %rsi
16414 call *%rsi
16415 # exit
16416 mov %eax, %edi
16417 call do_exit
16418 ud2 # padding for call trace
16419 CFI_ENDPROC
16420-END(kernel_thread_helper)
16421+ENDPROC(kernel_thread_helper)
16422
16423 /*
16424 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16425@@ -1264,11 +1636,11 @@ ENTRY(kernel_execve)
16426 RESTORE_REST
16427 testq %rax,%rax
16428 je int_ret_from_sys_call
16429- RESTORE_ARGS
16430 UNFAKE_STACK_FRAME
16431+ pax_force_retaddr
16432 ret
16433 CFI_ENDPROC
16434-END(kernel_execve)
16435+ENDPROC(kernel_execve)
16436
16437 /* Call softirq on interrupt stack. Interrupts are off. */
16438 ENTRY(call_softirq)
16439@@ -1286,9 +1658,10 @@ ENTRY(call_softirq)
16440 CFI_DEF_CFA_REGISTER rsp
16441 CFI_ADJUST_CFA_OFFSET -8
16442 decl PER_CPU_VAR(irq_count)
16443+ pax_force_retaddr
16444 ret
16445 CFI_ENDPROC
16446-END(call_softirq)
16447+ENDPROC(call_softirq)
16448
16449 #ifdef CONFIG_XEN
16450 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16451@@ -1326,7 +1699,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16452 decl PER_CPU_VAR(irq_count)
16453 jmp error_exit
16454 CFI_ENDPROC
16455-END(xen_do_hypervisor_callback)
16456+ENDPROC(xen_do_hypervisor_callback)
16457
16458 /*
16459 * Hypervisor uses this for application faults while it executes.
16460@@ -1385,7 +1758,7 @@ ENTRY(xen_failsafe_callback)
16461 SAVE_ALL
16462 jmp error_exit
16463 CFI_ENDPROC
16464-END(xen_failsafe_callback)
16465+ENDPROC(xen_failsafe_callback)
16466
16467 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16468 xen_hvm_callback_vector xen_evtchn_do_upcall
16469@@ -1434,16 +1807,31 @@ ENTRY(paranoid_exit)
16470 TRACE_IRQS_OFF_DEBUG
16471 testl %ebx,%ebx /* swapgs needed? */
16472 jnz paranoid_restore
16473- testl $3,CS(%rsp)
16474+ testb $3,CS(%rsp)
16475 jnz paranoid_userspace
16476+#ifdef CONFIG_PAX_MEMORY_UDEREF
16477+ pax_exit_kernel
16478+ TRACE_IRQS_IRETQ 0
16479+ SWAPGS_UNSAFE_STACK
16480+ RESTORE_ALL 8
16481+ pax_force_retaddr_bts
16482+ jmp irq_return
16483+#endif
16484 paranoid_swapgs:
16485+#ifdef CONFIG_PAX_MEMORY_UDEREF
16486+ pax_exit_kernel_user
16487+#else
16488+ pax_exit_kernel
16489+#endif
16490 TRACE_IRQS_IRETQ 0
16491 SWAPGS_UNSAFE_STACK
16492 RESTORE_ALL 8
16493 jmp irq_return
16494 paranoid_restore:
16495+ pax_exit_kernel
16496 TRACE_IRQS_IRETQ_DEBUG 0
16497 RESTORE_ALL 8
16498+ pax_force_retaddr_bts
16499 jmp irq_return
16500 paranoid_userspace:
16501 GET_THREAD_INFO(%rcx)
16502@@ -1472,7 +1860,7 @@ paranoid_schedule:
16503 TRACE_IRQS_OFF
16504 jmp paranoid_userspace
16505 CFI_ENDPROC
16506-END(paranoid_exit)
16507+ENDPROC(paranoid_exit)
16508
16509 /*
16510 * Exception entry point. This expects an error code/orig_rax on the stack.
16511@@ -1499,12 +1887,13 @@ ENTRY(error_entry)
16512 movq_cfi r14, R14+8
16513 movq_cfi r15, R15+8
16514 xorl %ebx,%ebx
16515- testl $3,CS+8(%rsp)
16516+ testb $3,CS+8(%rsp)
16517 je error_kernelspace
16518 error_swapgs:
16519 SWAPGS
16520 error_sti:
16521 TRACE_IRQS_OFF
16522+ pax_force_retaddr_bts
16523 ret
16524
16525 /*
16526@@ -1531,7 +1920,7 @@ bstep_iret:
16527 movq %rcx,RIP+8(%rsp)
16528 jmp error_swapgs
16529 CFI_ENDPROC
16530-END(error_entry)
16531+ENDPROC(error_entry)
16532
16533
16534 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16535@@ -1551,7 +1940,7 @@ ENTRY(error_exit)
16536 jnz retint_careful
16537 jmp retint_swapgs
16538 CFI_ENDPROC
16539-END(error_exit)
16540+ENDPROC(error_exit)
16541
16542 /*
16543 * Test if a given stack is an NMI stack or not.
16544@@ -1609,9 +1998,11 @@ ENTRY(nmi)
16545 * If %cs was not the kernel segment, then the NMI triggered in user
16546 * space, which means it is definitely not nested.
16547 */
16548+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16549+ je 1f
16550 cmpl $__KERNEL_CS, 16(%rsp)
16551 jne first_nmi
16552-
16553+1:
16554 /*
16555 * Check the special variable on the stack to see if NMIs are
16556 * executing.
16557@@ -1758,6 +2149,16 @@ end_repeat_nmi:
16558 */
16559 call save_paranoid
16560 DEFAULT_FRAME 0
16561+#ifdef CONFIG_PAX_MEMORY_UDEREF
16562+ testb $3, CS(%rsp)
16563+ jnz 1f
16564+ pax_enter_kernel
16565+ jmp 2f
16566+1: pax_enter_kernel_user
16567+2:
16568+#else
16569+ pax_enter_kernel
16570+#endif
16571 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16572 movq %rsp,%rdi
16573 movq $-1,%rsi
16574@@ -1765,21 +2166,32 @@ end_repeat_nmi:
16575 testl %ebx,%ebx /* swapgs needed? */
16576 jnz nmi_restore
16577 nmi_swapgs:
16578+#ifdef CONFIG_PAX_MEMORY_UDEREF
16579+ pax_exit_kernel_user
16580+#else
16581+ pax_exit_kernel
16582+#endif
16583 SWAPGS_UNSAFE_STACK
16584+ RESTORE_ALL 8
16585+ /* Clear the NMI executing stack variable */
16586+ movq $0, 10*8(%rsp)
16587+ jmp irq_return
16588 nmi_restore:
16589+ pax_exit_kernel
16590 RESTORE_ALL 8
16591+ pax_force_retaddr_bts
16592 /* Clear the NMI executing stack variable */
16593 movq $0, 10*8(%rsp)
16594 jmp irq_return
16595 CFI_ENDPROC
16596-END(nmi)
16597+ENDPROC(nmi)
16598
16599 ENTRY(ignore_sysret)
16600 CFI_STARTPROC
16601 mov $-ENOSYS,%eax
16602 sysret
16603 CFI_ENDPROC
16604-END(ignore_sysret)
16605+ENDPROC(ignore_sysret)
16606
16607 /*
16608 * End of kprobes section
16609diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16610index c3a7cb4..3ad00dc 100644
16611--- a/arch/x86/kernel/ftrace.c
16612+++ b/arch/x86/kernel/ftrace.c
16613@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
16614 {
16615 unsigned char replaced[MCOUNT_INSN_SIZE];
16616
16617+ ip = ktla_ktva(ip);
16618+
16619 /*
16620 * Note: Due to modules and __init, code can
16621 * disappear and change, we need to protect against faulting
16622@@ -212,7 +214,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16623 unsigned char old[MCOUNT_INSN_SIZE], *new;
16624 int ret;
16625
16626- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16627+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16628 new = ftrace_call_replace(ip, (unsigned long)func);
16629
16630 /* See comment above by declaration of modifying_ftrace_code */
16631@@ -605,6 +607,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16632 {
16633 unsigned char code[MCOUNT_INSN_SIZE];
16634
16635+ ip = ktla_ktva(ip);
16636+
16637 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16638 return -EFAULT;
16639
16640diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16641index c18f59d..9c0c9f6 100644
16642--- a/arch/x86/kernel/head32.c
16643+++ b/arch/x86/kernel/head32.c
16644@@ -18,6 +18,7 @@
16645 #include <asm/io_apic.h>
16646 #include <asm/bios_ebda.h>
16647 #include <asm/tlbflush.h>
16648+#include <asm/boot.h>
16649
16650 static void __init i386_default_early_setup(void)
16651 {
16652@@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
16653
16654 void __init i386_start_kernel(void)
16655 {
16656- memblock_reserve(__pa_symbol(&_text),
16657- __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16658+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16659
16660 #ifdef CONFIG_BLK_DEV_INITRD
16661 /* Reserve INITRD */
16662diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16663index d42ab17..cb1b997 100644
16664--- a/arch/x86/kernel/head_32.S
16665+++ b/arch/x86/kernel/head_32.S
16666@@ -26,6 +26,12 @@
16667 /* Physical address */
16668 #define pa(X) ((X) - __PAGE_OFFSET)
16669
16670+#ifdef CONFIG_PAX_KERNEXEC
16671+#define ta(X) (X)
16672+#else
16673+#define ta(X) ((X) - __PAGE_OFFSET)
16674+#endif
16675+
16676 /*
16677 * References to members of the new_cpu_data structure.
16678 */
16679@@ -55,11 +61,7 @@
16680 * and small than max_low_pfn, otherwise will waste some page table entries
16681 */
16682
16683-#if PTRS_PER_PMD > 1
16684-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16685-#else
16686-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16687-#endif
16688+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16689
16690 /* Number of possible pages in the lowmem region */
16691 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16692@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16693 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16694
16695 /*
16696+ * Real beginning of normal "text" segment
16697+ */
16698+ENTRY(stext)
16699+ENTRY(_stext)
16700+
16701+/*
16702 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16703 * %esi points to the real-mode code as a 32-bit pointer.
16704 * CS and DS must be 4 GB flat segments, but we don't depend on
16705@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16706 * can.
16707 */
16708 __HEAD
16709+
16710+#ifdef CONFIG_PAX_KERNEXEC
16711+ jmp startup_32
16712+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16713+.fill PAGE_SIZE-5,1,0xcc
16714+#endif
16715+
16716 ENTRY(startup_32)
16717 movl pa(stack_start),%ecx
16718
16719@@ -106,6 +121,57 @@ ENTRY(startup_32)
16720 2:
16721 leal -__PAGE_OFFSET(%ecx),%esp
16722
16723+#ifdef CONFIG_SMP
16724+ movl $pa(cpu_gdt_table),%edi
16725+ movl $__per_cpu_load,%eax
16726+ movw %ax,__KERNEL_PERCPU + 2(%edi)
16727+ rorl $16,%eax
16728+ movb %al,__KERNEL_PERCPU + 4(%edi)
16729+ movb %ah,__KERNEL_PERCPU + 7(%edi)
16730+ movl $__per_cpu_end - 1,%eax
16731+ subl $__per_cpu_start,%eax
16732+ movw %ax,__KERNEL_PERCPU + 0(%edi)
16733+#endif
16734+
16735+#ifdef CONFIG_PAX_MEMORY_UDEREF
16736+ movl $NR_CPUS,%ecx
16737+ movl $pa(cpu_gdt_table),%edi
16738+1:
16739+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16740+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16741+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16742+ addl $PAGE_SIZE_asm,%edi
16743+ loop 1b
16744+#endif
16745+
16746+#ifdef CONFIG_PAX_KERNEXEC
16747+ movl $pa(boot_gdt),%edi
16748+ movl $__LOAD_PHYSICAL_ADDR,%eax
16749+ movw %ax,__BOOT_CS + 2(%edi)
16750+ rorl $16,%eax
16751+ movb %al,__BOOT_CS + 4(%edi)
16752+ movb %ah,__BOOT_CS + 7(%edi)
16753+ rorl $16,%eax
16754+
16755+ ljmp $(__BOOT_CS),$1f
16756+1:
16757+
16758+ movl $NR_CPUS,%ecx
16759+ movl $pa(cpu_gdt_table),%edi
16760+ addl $__PAGE_OFFSET,%eax
16761+1:
16762+ movw %ax,__KERNEL_CS + 2(%edi)
16763+ movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16764+ rorl $16,%eax
16765+ movb %al,__KERNEL_CS + 4(%edi)
16766+ movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16767+ movb %ah,__KERNEL_CS + 7(%edi)
16768+ movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16769+ rorl $16,%eax
16770+ addl $PAGE_SIZE_asm,%edi
16771+ loop 1b
16772+#endif
16773+
16774 /*
16775 * Clear BSS first so that there are no surprises...
16776 */
16777@@ -196,8 +262,11 @@ ENTRY(startup_32)
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_pg_pmd+0x1000*KPMDS-8)
16783+#ifdef CONFIG_COMPAT_VDSO
16784+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16785+#else
16786+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16787+#endif
16788 #else /* Not PAE */
16789
16790 page_pde_offset = (__PAGE_OFFSET >> 20);
16791@@ -227,8 +296,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16792 movl %eax, pa(max_pfn_mapped)
16793
16794 /* Do early initialization of the fixmap area */
16795- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16796- movl %eax,pa(initial_page_table+0xffc)
16797+#ifdef CONFIG_COMPAT_VDSO
16798+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16799+#else
16800+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16801+#endif
16802 #endif
16803
16804 #ifdef CONFIG_PARAVIRT
16805@@ -242,9 +314,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16806 cmpl $num_subarch_entries, %eax
16807 jae bad_subarch
16808
16809- movl pa(subarch_entries)(,%eax,4), %eax
16810- subl $__PAGE_OFFSET, %eax
16811- jmp *%eax
16812+ jmp *pa(subarch_entries)(,%eax,4)
16813
16814 bad_subarch:
16815 WEAK(lguest_entry)
16816@@ -256,10 +326,10 @@ WEAK(xen_entry)
16817 __INITDATA
16818
16819 subarch_entries:
16820- .long default_entry /* normal x86/PC */
16821- .long lguest_entry /* lguest hypervisor */
16822- .long xen_entry /* Xen hypervisor */
16823- .long default_entry /* Moorestown MID */
16824+ .long ta(default_entry) /* normal x86/PC */
16825+ .long ta(lguest_entry) /* lguest hypervisor */
16826+ .long ta(xen_entry) /* Xen hypervisor */
16827+ .long ta(default_entry) /* Moorestown MID */
16828 num_subarch_entries = (. - subarch_entries) / 4
16829 .previous
16830 #else
16831@@ -310,6 +380,7 @@ default_entry:
16832 orl %edx,%eax
16833 movl %eax,%cr4
16834
16835+#ifdef CONFIG_X86_PAE
16836 testb $X86_CR4_PAE, %al # check if PAE is enabled
16837 jz 6f
16838
16839@@ -338,6 +409,9 @@ default_entry:
16840 /* Make changes effective */
16841 wrmsr
16842
16843+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
16844+#endif
16845+
16846 6:
16847
16848 /*
16849@@ -436,14 +510,20 @@ is386: movl $2,%ecx # set MP
16850 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
16851 movl %eax,%ss # after changing gdt.
16852
16853- movl $(__USER_DS),%eax # DS/ES contains default USER segment
16854+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
16855 movl %eax,%ds
16856 movl %eax,%es
16857
16858 movl $(__KERNEL_PERCPU), %eax
16859 movl %eax,%fs # set this cpu's percpu
16860
16861+#ifdef CONFIG_CC_STACKPROTECTOR
16862 movl $(__KERNEL_STACK_CANARY),%eax
16863+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
16864+ movl $(__USER_DS),%eax
16865+#else
16866+ xorl %eax,%eax
16867+#endif
16868 movl %eax,%gs
16869
16870 xorl %eax,%eax # Clear LDT
16871@@ -520,8 +600,11 @@ setup_once:
16872 * relocation. Manually set base address in stack canary
16873 * segment descriptor.
16874 */
16875- movl $gdt_page,%eax
16876+ movl $cpu_gdt_table,%eax
16877 movl $stack_canary,%ecx
16878+#ifdef CONFIG_SMP
16879+ addl $__per_cpu_load,%ecx
16880+#endif
16881 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
16882 shrl $16, %ecx
16883 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
16884@@ -552,7 +635,7 @@ ENDPROC(early_idt_handlers)
16885 /* This is global to keep gas from relaxing the jumps */
16886 ENTRY(early_idt_handler)
16887 cld
16888- cmpl $2,%ss:early_recursion_flag
16889+ cmpl $1,%ss:early_recursion_flag
16890 je hlt_loop
16891 incl %ss:early_recursion_flag
16892
16893@@ -590,8 +673,8 @@ ENTRY(early_idt_handler)
16894 pushl (20+6*4)(%esp) /* trapno */
16895 pushl $fault_msg
16896 call printk
16897-#endif
16898 call dump_stack
16899+#endif
16900 hlt_loop:
16901 hlt
16902 jmp hlt_loop
16903@@ -610,8 +693,11 @@ ENDPROC(early_idt_handler)
16904 /* This is the default interrupt "handler" :-) */
16905 ALIGN
16906 ignore_int:
16907- cld
16908 #ifdef CONFIG_PRINTK
16909+ cmpl $2,%ss:early_recursion_flag
16910+ je hlt_loop
16911+ incl %ss:early_recursion_flag
16912+ cld
16913 pushl %eax
16914 pushl %ecx
16915 pushl %edx
16916@@ -620,9 +706,6 @@ ignore_int:
16917 movl $(__KERNEL_DS),%eax
16918 movl %eax,%ds
16919 movl %eax,%es
16920- cmpl $2,early_recursion_flag
16921- je hlt_loop
16922- incl early_recursion_flag
16923 pushl 16(%esp)
16924 pushl 24(%esp)
16925 pushl 32(%esp)
16926@@ -656,29 +739,43 @@ ENTRY(setup_once_ref)
16927 /*
16928 * BSS section
16929 */
16930-__PAGE_ALIGNED_BSS
16931- .align PAGE_SIZE
16932 #ifdef CONFIG_X86_PAE
16933+.section .initial_pg_pmd,"a",@progbits
16934 initial_pg_pmd:
16935 .fill 1024*KPMDS,4,0
16936 #else
16937+.section .initial_page_table,"a",@progbits
16938 ENTRY(initial_page_table)
16939 .fill 1024,4,0
16940 #endif
16941+.section .initial_pg_fixmap,"a",@progbits
16942 initial_pg_fixmap:
16943 .fill 1024,4,0
16944+.section .empty_zero_page,"a",@progbits
16945 ENTRY(empty_zero_page)
16946 .fill 4096,1,0
16947+.section .swapper_pg_dir,"a",@progbits
16948 ENTRY(swapper_pg_dir)
16949+#ifdef CONFIG_X86_PAE
16950+ .fill 4,8,0
16951+#else
16952 .fill 1024,4,0
16953+#endif
16954+
16955+/*
16956+ * The IDT has to be page-aligned to simplify the Pentium
16957+ * F0 0F bug workaround.. We have a special link segment
16958+ * for this.
16959+ */
16960+.section .idt,"a",@progbits
16961+ENTRY(idt_table)
16962+ .fill 256,8,0
16963
16964 /*
16965 * This starts the data section.
16966 */
16967 #ifdef CONFIG_X86_PAE
16968-__PAGE_ALIGNED_DATA
16969- /* Page-aligned for the benefit of paravirt? */
16970- .align PAGE_SIZE
16971+.section .initial_page_table,"a",@progbits
16972 ENTRY(initial_page_table)
16973 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
16974 # if KPMDS == 3
16975@@ -697,12 +794,20 @@ ENTRY(initial_page_table)
16976 # error "Kernel PMDs should be 1, 2 or 3"
16977 # endif
16978 .align PAGE_SIZE /* needs to be page-sized too */
16979+
16980+#ifdef CONFIG_PAX_PER_CPU_PGD
16981+ENTRY(cpu_pgd)
16982+ .rept NR_CPUS
16983+ .fill 4,8,0
16984+ .endr
16985+#endif
16986+
16987 #endif
16988
16989 .data
16990 .balign 4
16991 ENTRY(stack_start)
16992- .long init_thread_union+THREAD_SIZE
16993+ .long init_thread_union+THREAD_SIZE-8
16994
16995 __INITRODATA
16996 int_msg:
16997@@ -730,7 +835,7 @@ fault_msg:
16998 * segment size, and 32-bit linear address value:
16999 */
17000
17001- .data
17002+.section .rodata,"a",@progbits
17003 .globl boot_gdt_descr
17004 .globl idt_descr
17005
17006@@ -739,7 +844,7 @@ fault_msg:
17007 .word 0 # 32 bit align gdt_desc.address
17008 boot_gdt_descr:
17009 .word __BOOT_DS+7
17010- .long boot_gdt - __PAGE_OFFSET
17011+ .long pa(boot_gdt)
17012
17013 .word 0 # 32-bit align idt_desc.address
17014 idt_descr:
17015@@ -750,7 +855,7 @@ idt_descr:
17016 .word 0 # 32 bit align gdt_desc.address
17017 ENTRY(early_gdt_descr)
17018 .word GDT_ENTRIES*8-1
17019- .long gdt_page /* Overwritten for secondary CPUs */
17020+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
17021
17022 /*
17023 * The boot_gdt must mirror the equivalent in setup.S and is
17024@@ -759,5 +864,65 @@ ENTRY(early_gdt_descr)
17025 .align L1_CACHE_BYTES
17026 ENTRY(boot_gdt)
17027 .fill GDT_ENTRY_BOOT_CS,8,0
17028- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17029- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17030+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17031+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17032+
17033+ .align PAGE_SIZE_asm
17034+ENTRY(cpu_gdt_table)
17035+ .rept NR_CPUS
17036+ .quad 0x0000000000000000 /* NULL descriptor */
17037+ .quad 0x0000000000000000 /* 0x0b reserved */
17038+ .quad 0x0000000000000000 /* 0x13 reserved */
17039+ .quad 0x0000000000000000 /* 0x1b reserved */
17040+
17041+#ifdef CONFIG_PAX_KERNEXEC
17042+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17043+#else
17044+ .quad 0x0000000000000000 /* 0x20 unused */
17045+#endif
17046+
17047+ .quad 0x0000000000000000 /* 0x28 unused */
17048+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17049+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17050+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17051+ .quad 0x0000000000000000 /* 0x4b reserved */
17052+ .quad 0x0000000000000000 /* 0x53 reserved */
17053+ .quad 0x0000000000000000 /* 0x5b reserved */
17054+
17055+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17056+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17057+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17058+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17059+
17060+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17061+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17062+
17063+ /*
17064+ * Segments used for calling PnP BIOS have byte granularity.
17065+ * The code segments and data segments have fixed 64k limits,
17066+ * the transfer segment sizes are set at run time.
17067+ */
17068+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
17069+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
17070+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
17071+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
17072+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
17073+
17074+ /*
17075+ * The APM segments have byte granularity and their bases
17076+ * are set at run time. All have 64k limits.
17077+ */
17078+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17079+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17080+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
17081+
17082+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17083+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17084+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17085+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17086+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17087+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17088+
17089+ /* Be sure this is zeroed to avoid false validations in Xen */
17090+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17091+ .endr
17092diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17093index 94bf9cc..400455a 100644
17094--- a/arch/x86/kernel/head_64.S
17095+++ b/arch/x86/kernel/head_64.S
17096@@ -20,6 +20,8 @@
17097 #include <asm/processor-flags.h>
17098 #include <asm/percpu.h>
17099 #include <asm/nops.h>
17100+#include <asm/cpufeature.h>
17101+#include <asm/alternative-asm.h>
17102
17103 #ifdef CONFIG_PARAVIRT
17104 #include <asm/asm-offsets.h>
17105@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17106 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17107 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17108 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17109+L4_VMALLOC_START = pgd_index(VMALLOC_START)
17110+L3_VMALLOC_START = pud_index(VMALLOC_START)
17111+L4_VMALLOC_END = pgd_index(VMALLOC_END)
17112+L3_VMALLOC_END = pud_index(VMALLOC_END)
17113+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17114+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17115
17116 .text
17117 __HEAD
17118@@ -88,35 +96,23 @@ startup_64:
17119 */
17120 addq %rbp, init_level4_pgt + 0(%rip)
17121 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17122+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17123+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17124+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17125 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17126
17127 addq %rbp, level3_ident_pgt + 0(%rip)
17128+#ifndef CONFIG_XEN
17129+ addq %rbp, level3_ident_pgt + 8(%rip)
17130+#endif
17131
17132- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17133- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17134+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17135+
17136+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17137+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17138
17139 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17140-
17141- /* Add an Identity mapping if I am above 1G */
17142- leaq _text(%rip), %rdi
17143- andq $PMD_PAGE_MASK, %rdi
17144-
17145- movq %rdi, %rax
17146- shrq $PUD_SHIFT, %rax
17147- andq $(PTRS_PER_PUD - 1), %rax
17148- jz ident_complete
17149-
17150- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17151- leaq level3_ident_pgt(%rip), %rbx
17152- movq %rdx, 0(%rbx, %rax, 8)
17153-
17154- movq %rdi, %rax
17155- shrq $PMD_SHIFT, %rax
17156- andq $(PTRS_PER_PMD - 1), %rax
17157- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17158- leaq level2_spare_pgt(%rip), %rbx
17159- movq %rdx, 0(%rbx, %rax, 8)
17160-ident_complete:
17161+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17162
17163 /*
17164 * Fixup the kernel text+data virtual addresses. Note that
17165@@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
17166 * after the boot processor executes this code.
17167 */
17168
17169- /* Enable PAE mode and PGE */
17170- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17171+ /* Enable PAE mode and PSE/PGE */
17172+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17173 movq %rax, %cr4
17174
17175 /* Setup early boot stage 4 level pagetables. */
17176@@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
17177 movl $MSR_EFER, %ecx
17178 rdmsr
17179 btsl $_EFER_SCE, %eax /* Enable System Call */
17180- btl $20,%edi /* No Execute supported? */
17181+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17182 jnc 1f
17183 btsl $_EFER_NX, %eax
17184+ leaq init_level4_pgt(%rip), %rdi
17185+#ifndef CONFIG_EFI
17186+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17187+#endif
17188+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17189+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17190+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17191+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17192 1: wrmsr /* Make changes effective */
17193
17194 /* Setup cr0 */
17195@@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
17196 * jump. In addition we need to ensure %cs is set so we make this
17197 * a far return.
17198 */
17199+ pax_set_fptr_mask
17200 movq initial_code(%rip),%rax
17201 pushq $0 # fake return address to stop unwinder
17202 pushq $__KERNEL_CS # set correct cs
17203@@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
17204 bad_address:
17205 jmp bad_address
17206
17207- .section ".init.text","ax"
17208+ __INIT
17209 .globl early_idt_handlers
17210 early_idt_handlers:
17211 # 104(%rsp) %rflags
17212@@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
17213 addq $16,%rsp # drop vector number and error code
17214 decl early_recursion_flag(%rip)
17215 INTERRUPT_RETURN
17216+ .previous
17217
17218+ __INITDATA
17219 .balign 4
17220 early_recursion_flag:
17221 .long 0
17222+ .previous
17223
17224+ .section .rodata,"a",@progbits
17225 #ifdef CONFIG_EARLY_PRINTK
17226 early_idt_msg:
17227 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17228@@ -360,6 +369,7 @@ early_idt_ripmsg:
17229 #endif /* CONFIG_EARLY_PRINTK */
17230 .previous
17231
17232+ .section .rodata,"a",@progbits
17233 #define NEXT_PAGE(name) \
17234 .balign PAGE_SIZE; \
17235 ENTRY(name)
17236@@ -372,7 +382,6 @@ ENTRY(name)
17237 i = i + 1 ; \
17238 .endr
17239
17240- .data
17241 /*
17242 * This default setting generates an ident mapping at address 0x100000
17243 * and a mapping for the kernel that precisely maps virtual address
17244@@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
17245 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17246 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17247 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17248+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
17249+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17250+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
17251+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17252+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17253+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17254 .org init_level4_pgt + L4_START_KERNEL*8, 0
17255 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17256 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17257
17258+#ifdef CONFIG_PAX_PER_CPU_PGD
17259+NEXT_PAGE(cpu_pgd)
17260+ .rept NR_CPUS
17261+ .fill 512,8,0
17262+ .endr
17263+#endif
17264+
17265 NEXT_PAGE(level3_ident_pgt)
17266 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17267+#ifdef CONFIG_XEN
17268 .fill 511,8,0
17269+#else
17270+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17271+ .fill 510,8,0
17272+#endif
17273+
17274+NEXT_PAGE(level3_vmalloc_start_pgt)
17275+ .fill 512,8,0
17276+
17277+NEXT_PAGE(level3_vmalloc_end_pgt)
17278+ .fill 512,8,0
17279+
17280+NEXT_PAGE(level3_vmemmap_pgt)
17281+ .fill L3_VMEMMAP_START,8,0
17282+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17283
17284 NEXT_PAGE(level3_kernel_pgt)
17285 .fill L3_START_KERNEL,8,0
17286@@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
17287 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17288 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17289
17290+NEXT_PAGE(level2_vmemmap_pgt)
17291+ .fill 512,8,0
17292+
17293 NEXT_PAGE(level2_fixmap_pgt)
17294- .fill 506,8,0
17295- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17296- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17297- .fill 5,8,0
17298+ .fill 507,8,0
17299+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17300+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17301+ .fill 4,8,0
17302
17303-NEXT_PAGE(level1_fixmap_pgt)
17304+NEXT_PAGE(level1_vsyscall_pgt)
17305 .fill 512,8,0
17306
17307-NEXT_PAGE(level2_ident_pgt)
17308- /* Since I easily can, map the first 1G.
17309+ /* Since I easily can, map the first 2G.
17310 * Don't set NX because code runs from these pages.
17311 */
17312- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17313+NEXT_PAGE(level2_ident_pgt)
17314+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17315
17316 NEXT_PAGE(level2_kernel_pgt)
17317 /*
17318@@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
17319 * If you want to increase this then increase MODULES_VADDR
17320 * too.)
17321 */
17322- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17323- KERNEL_IMAGE_SIZE/PMD_SIZE)
17324-
17325-NEXT_PAGE(level2_spare_pgt)
17326- .fill 512, 8, 0
17327+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17328
17329 #undef PMDS
17330 #undef NEXT_PAGE
17331
17332- .data
17333+ .align PAGE_SIZE
17334+ENTRY(cpu_gdt_table)
17335+ .rept NR_CPUS
17336+ .quad 0x0000000000000000 /* NULL descriptor */
17337+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17338+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
17339+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
17340+ .quad 0x00cffb000000ffff /* __USER32_CS */
17341+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17342+ .quad 0x00affb000000ffff /* __USER_CS */
17343+
17344+#ifdef CONFIG_PAX_KERNEXEC
17345+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17346+#else
17347+ .quad 0x0 /* unused */
17348+#endif
17349+
17350+ .quad 0,0 /* TSS */
17351+ .quad 0,0 /* LDT */
17352+ .quad 0,0,0 /* three TLS descriptors */
17353+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
17354+ /* asm/segment.h:GDT_ENTRIES must match this */
17355+
17356+ /* zero the remaining page */
17357+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17358+ .endr
17359+
17360 .align 16
17361 .globl early_gdt_descr
17362 early_gdt_descr:
17363 .word GDT_ENTRIES*8-1
17364 early_gdt_descr_base:
17365- .quad INIT_PER_CPU_VAR(gdt_page)
17366+ .quad cpu_gdt_table
17367
17368 ENTRY(phys_base)
17369 /* This must match the first entry in level2_kernel_pgt */
17370 .quad 0x0000000000000000
17371
17372 #include "../../x86/xen/xen-head.S"
17373-
17374- .section .bss, "aw", @nobits
17375+
17376+ .section .rodata,"a",@progbits
17377 .align L1_CACHE_BYTES
17378 ENTRY(idt_table)
17379- .skip IDT_ENTRIES * 16
17380+ .fill 512,8,0
17381
17382 .align L1_CACHE_BYTES
17383 ENTRY(nmi_idt_table)
17384- .skip IDT_ENTRIES * 16
17385+ .fill 512,8,0
17386
17387 __PAGE_ALIGNED_BSS
17388 .align PAGE_SIZE
17389diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17390index 9c3bd4a..e1d9b35 100644
17391--- a/arch/x86/kernel/i386_ksyms_32.c
17392+++ b/arch/x86/kernel/i386_ksyms_32.c
17393@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17394 EXPORT_SYMBOL(cmpxchg8b_emu);
17395 #endif
17396
17397+EXPORT_SYMBOL_GPL(cpu_gdt_table);
17398+
17399 /* Networking helper routines. */
17400 EXPORT_SYMBOL(csum_partial_copy_generic);
17401+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17402+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17403
17404 EXPORT_SYMBOL(__get_user_1);
17405 EXPORT_SYMBOL(__get_user_2);
17406@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17407
17408 EXPORT_SYMBOL(csum_partial);
17409 EXPORT_SYMBOL(empty_zero_page);
17410+
17411+#ifdef CONFIG_PAX_KERNEXEC
17412+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17413+#endif
17414diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17415index f250431..54097e7 100644
17416--- a/arch/x86/kernel/i387.c
17417+++ b/arch/x86/kernel/i387.c
17418@@ -59,7 +59,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17419 static inline bool interrupted_user_mode(void)
17420 {
17421 struct pt_regs *regs = get_irq_regs();
17422- return regs && user_mode_vm(regs);
17423+ return regs && user_mode(regs);
17424 }
17425
17426 /*
17427diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17428index 36d1853..bf25736 100644
17429--- a/arch/x86/kernel/i8259.c
17430+++ b/arch/x86/kernel/i8259.c
17431@@ -209,7 +209,7 @@ spurious_8259A_irq:
17432 "spurious 8259A interrupt: IRQ%d.\n", irq);
17433 spurious_irq_mask |= irqmask;
17434 }
17435- atomic_inc(&irq_err_count);
17436+ atomic_inc_unchecked(&irq_err_count);
17437 /*
17438 * Theoretically we do not have to handle this IRQ,
17439 * but in Linux this does not cause problems and is
17440diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17441index 8c96897..be66bfa 100644
17442--- a/arch/x86/kernel/ioport.c
17443+++ b/arch/x86/kernel/ioport.c
17444@@ -6,6 +6,7 @@
17445 #include <linux/sched.h>
17446 #include <linux/kernel.h>
17447 #include <linux/capability.h>
17448+#include <linux/security.h>
17449 #include <linux/errno.h>
17450 #include <linux/types.h>
17451 #include <linux/ioport.h>
17452@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17453
17454 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17455 return -EINVAL;
17456+#ifdef CONFIG_GRKERNSEC_IO
17457+ if (turn_on && grsec_disable_privio) {
17458+ gr_handle_ioperm();
17459+ return -EPERM;
17460+ }
17461+#endif
17462 if (turn_on && !capable(CAP_SYS_RAWIO))
17463 return -EPERM;
17464
17465@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17466 * because the ->io_bitmap_max value must match the bitmap
17467 * contents:
17468 */
17469- tss = &per_cpu(init_tss, get_cpu());
17470+ tss = init_tss + get_cpu();
17471
17472 if (turn_on)
17473 bitmap_clear(t->io_bitmap_ptr, from, num);
17474@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17475 return -EINVAL;
17476 /* Trying to gain more privileges? */
17477 if (level > old) {
17478+#ifdef CONFIG_GRKERNSEC_IO
17479+ if (grsec_disable_privio) {
17480+ gr_handle_iopl();
17481+ return -EPERM;
17482+ }
17483+#endif
17484 if (!capable(CAP_SYS_RAWIO))
17485 return -EPERM;
17486 }
17487diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17488index 3dafc60..aa8e9c4 100644
17489--- a/arch/x86/kernel/irq.c
17490+++ b/arch/x86/kernel/irq.c
17491@@ -18,7 +18,7 @@
17492 #include <asm/mce.h>
17493 #include <asm/hw_irq.h>
17494
17495-atomic_t irq_err_count;
17496+atomic_unchecked_t irq_err_count;
17497
17498 /* Function pointer for generic interrupt vector handling */
17499 void (*x86_platform_ipi_callback)(void) = NULL;
17500@@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17501 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17502 seq_printf(p, " Machine check polls\n");
17503 #endif
17504- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17505+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17506 #if defined(CONFIG_X86_IO_APIC)
17507- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17508+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17509 #endif
17510 return 0;
17511 }
17512@@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17513
17514 u64 arch_irq_stat(void)
17515 {
17516- u64 sum = atomic_read(&irq_err_count);
17517+ u64 sum = atomic_read_unchecked(&irq_err_count);
17518
17519 #ifdef CONFIG_X86_IO_APIC
17520- sum += atomic_read(&irq_mis_count);
17521+ sum += atomic_read_unchecked(&irq_mis_count);
17522 #endif
17523 return sum;
17524 }
17525diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17526index 344faf8..355f60d 100644
17527--- a/arch/x86/kernel/irq_32.c
17528+++ b/arch/x86/kernel/irq_32.c
17529@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17530 __asm__ __volatile__("andl %%esp,%0" :
17531 "=r" (sp) : "0" (THREAD_SIZE - 1));
17532
17533- return sp < (sizeof(struct thread_info) + STACK_WARN);
17534+ return sp < STACK_WARN;
17535 }
17536
17537 static void print_stack_overflow(void)
17538@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17539 * per-CPU IRQ handling contexts (thread information and stack)
17540 */
17541 union irq_ctx {
17542- struct thread_info tinfo;
17543- u32 stack[THREAD_SIZE/sizeof(u32)];
17544+ unsigned long previous_esp;
17545+ u32 stack[THREAD_SIZE/sizeof(u32)];
17546 } __attribute__((aligned(THREAD_SIZE)));
17547
17548 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17549@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17550 static inline int
17551 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17552 {
17553- union irq_ctx *curctx, *irqctx;
17554+ union irq_ctx *irqctx;
17555 u32 *isp, arg1, arg2;
17556
17557- curctx = (union irq_ctx *) current_thread_info();
17558 irqctx = __this_cpu_read(hardirq_ctx);
17559
17560 /*
17561@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17562 * handler) we can't do that and just have to keep using the
17563 * current stack (which is the irq stack already after all)
17564 */
17565- if (unlikely(curctx == irqctx))
17566+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17567 return 0;
17568
17569 /* build the stack frame on the IRQ stack */
17570- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17571- irqctx->tinfo.task = curctx->tinfo.task;
17572- irqctx->tinfo.previous_esp = current_stack_pointer;
17573+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17574+ irqctx->previous_esp = current_stack_pointer;
17575
17576- /* Copy the preempt_count so that the [soft]irq checks work. */
17577- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17578+#ifdef CONFIG_PAX_MEMORY_UDEREF
17579+ __set_fs(MAKE_MM_SEG(0));
17580+#endif
17581
17582 if (unlikely(overflow))
17583 call_on_stack(print_stack_overflow, isp);
17584@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17585 : "0" (irq), "1" (desc), "2" (isp),
17586 "D" (desc->handle_irq)
17587 : "memory", "cc", "ecx");
17588+
17589+#ifdef CONFIG_PAX_MEMORY_UDEREF
17590+ __set_fs(current_thread_info()->addr_limit);
17591+#endif
17592+
17593 return 1;
17594 }
17595
17596@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17597 */
17598 void __cpuinit irq_ctx_init(int cpu)
17599 {
17600- union irq_ctx *irqctx;
17601-
17602 if (per_cpu(hardirq_ctx, cpu))
17603 return;
17604
17605- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17606- THREADINFO_GFP,
17607- THREAD_SIZE_ORDER));
17608- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17609- irqctx->tinfo.cpu = cpu;
17610- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17611- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17612-
17613- per_cpu(hardirq_ctx, cpu) = irqctx;
17614-
17615- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17616- THREADINFO_GFP,
17617- THREAD_SIZE_ORDER));
17618- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17619- irqctx->tinfo.cpu = cpu;
17620- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17621-
17622- per_cpu(softirq_ctx, cpu) = irqctx;
17623+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17624+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17625+
17626+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17627+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17628
17629 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17630 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17631@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
17632 asmlinkage void do_softirq(void)
17633 {
17634 unsigned long flags;
17635- struct thread_info *curctx;
17636 union irq_ctx *irqctx;
17637 u32 *isp;
17638
17639@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
17640 local_irq_save(flags);
17641
17642 if (local_softirq_pending()) {
17643- curctx = current_thread_info();
17644 irqctx = __this_cpu_read(softirq_ctx);
17645- irqctx->tinfo.task = curctx->task;
17646- irqctx->tinfo.previous_esp = current_stack_pointer;
17647+ irqctx->previous_esp = current_stack_pointer;
17648
17649 /* build the stack frame on the softirq stack */
17650- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17651+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17652+
17653+#ifdef CONFIG_PAX_MEMORY_UDEREF
17654+ __set_fs(MAKE_MM_SEG(0));
17655+#endif
17656
17657 call_on_stack(__do_softirq, isp);
17658+
17659+#ifdef CONFIG_PAX_MEMORY_UDEREF
17660+ __set_fs(current_thread_info()->addr_limit);
17661+#endif
17662+
17663 /*
17664 * Shouldn't happen, we returned above if in_interrupt():
17665 */
17666@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17667 if (unlikely(!desc))
17668 return false;
17669
17670- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17671+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17672 if (unlikely(overflow))
17673 print_stack_overflow();
17674 desc->handle_irq(irq, desc);
17675diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17676index d04d3ec..ea4b374 100644
17677--- a/arch/x86/kernel/irq_64.c
17678+++ b/arch/x86/kernel/irq_64.c
17679@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17680 u64 estack_top, estack_bottom;
17681 u64 curbase = (u64)task_stack_page(current);
17682
17683- if (user_mode_vm(regs))
17684+ if (user_mode(regs))
17685 return;
17686
17687 if (regs->sp >= curbase + sizeof(struct thread_info) +
17688diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17689index 1d5d31e..72731d4 100644
17690--- a/arch/x86/kernel/kdebugfs.c
17691+++ b/arch/x86/kernel/kdebugfs.c
17692@@ -27,7 +27,7 @@ struct setup_data_node {
17693 u32 len;
17694 };
17695
17696-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17697+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
17698 size_t count, loff_t *ppos)
17699 {
17700 struct setup_data_node *node = file->private_data;
17701diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17702index 3f61904..873cea9 100644
17703--- a/arch/x86/kernel/kgdb.c
17704+++ b/arch/x86/kernel/kgdb.c
17705@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17706 #ifdef CONFIG_X86_32
17707 switch (regno) {
17708 case GDB_SS:
17709- if (!user_mode_vm(regs))
17710+ if (!user_mode(regs))
17711 *(unsigned long *)mem = __KERNEL_DS;
17712 break;
17713 case GDB_SP:
17714- if (!user_mode_vm(regs))
17715+ if (!user_mode(regs))
17716 *(unsigned long *)mem = kernel_stack_pointer(regs);
17717 break;
17718 case GDB_GS:
17719@@ -476,12 +476,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17720 case 'k':
17721 /* clear the trace bit */
17722 linux_regs->flags &= ~X86_EFLAGS_TF;
17723- atomic_set(&kgdb_cpu_doing_single_step, -1);
17724+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17725
17726 /* set the trace bit if we're stepping */
17727 if (remcomInBuffer[0] == 's') {
17728 linux_regs->flags |= X86_EFLAGS_TF;
17729- atomic_set(&kgdb_cpu_doing_single_step,
17730+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17731 raw_smp_processor_id());
17732 }
17733
17734@@ -546,7 +546,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17735
17736 switch (cmd) {
17737 case DIE_DEBUG:
17738- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17739+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17740 if (user_mode(regs))
17741 return single_step_cont(regs, args);
17742 break;
17743diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
17744index c5e410e..da6aaf9 100644
17745--- a/arch/x86/kernel/kprobes-opt.c
17746+++ b/arch/x86/kernel/kprobes-opt.c
17747@@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17748 * Verify if the address gap is in 2GB range, because this uses
17749 * a relative jump.
17750 */
17751- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17752+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17753 if (abs(rel) > 0x7fffffff)
17754 return -ERANGE;
17755
17756@@ -359,11 +359,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17757 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17758
17759 /* Set probe function call */
17760- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17761+ synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17762
17763 /* Set returning jmp instruction at the tail of out-of-line buffer */
17764 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17765- (u8 *)op->kp.addr + op->optinsn.size);
17766+ (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17767
17768 flush_icache_range((unsigned long) buf,
17769 (unsigned long) buf + TMPL_END_IDX +
17770@@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17771 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17772
17773 /* Backup instructions which will be replaced by jump address */
17774- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17775+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17776 RELATIVE_ADDR_SIZE);
17777
17778 insn_buf[0] = RELATIVEJUMP_OPCODE;
17779diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17780index e2f751e..dffa2a0 100644
17781--- a/arch/x86/kernel/kprobes.c
17782+++ b/arch/x86/kernel/kprobes.c
17783@@ -120,8 +120,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17784 } __attribute__((packed)) *insn;
17785
17786 insn = (struct __arch_relative_insn *)from;
17787+
17788+ pax_open_kernel();
17789 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17790 insn->op = op;
17791+ pax_close_kernel();
17792 }
17793
17794 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17795@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
17796 kprobe_opcode_t opcode;
17797 kprobe_opcode_t *orig_opcodes = opcodes;
17798
17799- if (search_exception_tables((unsigned long)opcodes))
17800+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17801 return 0; /* Page fault may occur on this address. */
17802
17803 retry:
17804@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17805 /* Another subsystem puts a breakpoint, failed to recover */
17806 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
17807 return 0;
17808+ pax_open_kernel();
17809 memcpy(dest, insn.kaddr, insn.length);
17810+ pax_close_kernel();
17811
17812 #ifdef CONFIG_X86_64
17813 if (insn_rip_relative(&insn)) {
17814@@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17815 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
17816 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
17817 disp = (u8 *) dest + insn_offset_displacement(&insn);
17818+ pax_open_kernel();
17819 *(s32 *) disp = (s32) newdisp;
17820+ pax_close_kernel();
17821 }
17822 #endif
17823 return insn.length;
17824@@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17825 * nor set current_kprobe, because it doesn't use single
17826 * stepping.
17827 */
17828- regs->ip = (unsigned long)p->ainsn.insn;
17829+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17830 preempt_enable_no_resched();
17831 return;
17832 }
17833@@ -504,7 +511,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17834 if (p->opcode == BREAKPOINT_INSTRUCTION)
17835 regs->ip = (unsigned long)p->addr;
17836 else
17837- regs->ip = (unsigned long)p->ainsn.insn;
17838+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17839 }
17840
17841 /*
17842@@ -583,7 +590,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
17843 setup_singlestep(p, regs, kcb, 0);
17844 return 1;
17845 }
17846- } else if (*addr != BREAKPOINT_INSTRUCTION) {
17847+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
17848 /*
17849 * The breakpoint instruction was removed right
17850 * after we hit it. Another cpu has removed
17851@@ -628,6 +635,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
17852 " movq %rax, 152(%rsp)\n"
17853 RESTORE_REGS_STRING
17854 " popfq\n"
17855+#ifdef KERNEXEC_PLUGIN
17856+ " btsq $63,(%rsp)\n"
17857+#endif
17858 #else
17859 " pushf\n"
17860 SAVE_REGS_STRING
17861@@ -765,7 +775,7 @@ static void __kprobes
17862 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
17863 {
17864 unsigned long *tos = stack_addr(regs);
17865- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
17866+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
17867 unsigned long orig_ip = (unsigned long)p->addr;
17868 kprobe_opcode_t *insn = p->ainsn.insn;
17869
17870@@ -947,7 +957,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
17871 struct die_args *args = data;
17872 int ret = NOTIFY_DONE;
17873
17874- if (args->regs && user_mode_vm(args->regs))
17875+ if (args->regs && user_mode(args->regs))
17876 return ret;
17877
17878 switch (val) {
17879diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
17880index ebc9873..1b9724b 100644
17881--- a/arch/x86/kernel/ldt.c
17882+++ b/arch/x86/kernel/ldt.c
17883@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
17884 if (reload) {
17885 #ifdef CONFIG_SMP
17886 preempt_disable();
17887- load_LDT(pc);
17888+ load_LDT_nolock(pc);
17889 if (!cpumask_equal(mm_cpumask(current->mm),
17890 cpumask_of(smp_processor_id())))
17891 smp_call_function(flush_ldt, current->mm, 1);
17892 preempt_enable();
17893 #else
17894- load_LDT(pc);
17895+ load_LDT_nolock(pc);
17896 #endif
17897 }
17898 if (oldsize) {
17899@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
17900 return err;
17901
17902 for (i = 0; i < old->size; i++)
17903- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
17904+ write_ldt_entry(new->ldt, i, old->ldt + i);
17905 return 0;
17906 }
17907
17908@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
17909 retval = copy_ldt(&mm->context, &old_mm->context);
17910 mutex_unlock(&old_mm->context.lock);
17911 }
17912+
17913+ if (tsk == current) {
17914+ mm->context.vdso = 0;
17915+
17916+#ifdef CONFIG_X86_32
17917+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17918+ mm->context.user_cs_base = 0UL;
17919+ mm->context.user_cs_limit = ~0UL;
17920+
17921+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17922+ cpus_clear(mm->context.cpu_user_cs_mask);
17923+#endif
17924+
17925+#endif
17926+#endif
17927+
17928+ }
17929+
17930 return retval;
17931 }
17932
17933@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
17934 }
17935 }
17936
17937+#ifdef CONFIG_PAX_SEGMEXEC
17938+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
17939+ error = -EINVAL;
17940+ goto out_unlock;
17941+ }
17942+#endif
17943+
17944 fill_ldt(&ldt, &ldt_info);
17945 if (oldmode)
17946 ldt.avl = 0;
17947diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
17948index 5b19e4d..6476a76 100644
17949--- a/arch/x86/kernel/machine_kexec_32.c
17950+++ b/arch/x86/kernel/machine_kexec_32.c
17951@@ -26,7 +26,7 @@
17952 #include <asm/cacheflush.h>
17953 #include <asm/debugreg.h>
17954
17955-static void set_idt(void *newidt, __u16 limit)
17956+static void set_idt(struct desc_struct *newidt, __u16 limit)
17957 {
17958 struct desc_ptr curidt;
17959
17960@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
17961 }
17962
17963
17964-static void set_gdt(void *newgdt, __u16 limit)
17965+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
17966 {
17967 struct desc_ptr curgdt;
17968
17969@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
17970 }
17971
17972 control_page = page_address(image->control_code_page);
17973- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
17974+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
17975
17976 relocate_kernel_ptr = control_page;
17977 page_list[PA_CONTROL_PAGE] = __pa(control_page);
17978diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
17979index 0327e2b..e43737b 100644
17980--- a/arch/x86/kernel/microcode_intel.c
17981+++ b/arch/x86/kernel/microcode_intel.c
17982@@ -430,13 +430,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
17983
17984 static int get_ucode_user(void *to, const void *from, size_t n)
17985 {
17986- return copy_from_user(to, from, n);
17987+ return copy_from_user(to, (const void __force_user *)from, n);
17988 }
17989
17990 static enum ucode_state
17991 request_microcode_user(int cpu, const void __user *buf, size_t size)
17992 {
17993- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
17994+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
17995 }
17996
17997 static void microcode_fini_cpu(int cpu)
17998diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
17999index f21fd94..61565cd 100644
18000--- a/arch/x86/kernel/module.c
18001+++ b/arch/x86/kernel/module.c
18002@@ -35,15 +35,60 @@
18003 #define DEBUGP(fmt...)
18004 #endif
18005
18006-void *module_alloc(unsigned long size)
18007+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18008 {
18009- if (PAGE_ALIGN(size) > MODULES_LEN)
18010+ if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18011 return NULL;
18012 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18013- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18014+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18015 -1, __builtin_return_address(0));
18016 }
18017
18018+void *module_alloc(unsigned long size)
18019+{
18020+
18021+#ifdef CONFIG_PAX_KERNEXEC
18022+ return __module_alloc(size, PAGE_KERNEL);
18023+#else
18024+ return __module_alloc(size, PAGE_KERNEL_EXEC);
18025+#endif
18026+
18027+}
18028+
18029+#ifdef CONFIG_PAX_KERNEXEC
18030+#ifdef CONFIG_X86_32
18031+void *module_alloc_exec(unsigned long size)
18032+{
18033+ struct vm_struct *area;
18034+
18035+ if (size == 0)
18036+ return NULL;
18037+
18038+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18039+ return area ? area->addr : NULL;
18040+}
18041+EXPORT_SYMBOL(module_alloc_exec);
18042+
18043+void module_free_exec(struct module *mod, void *module_region)
18044+{
18045+ vunmap(module_region);
18046+}
18047+EXPORT_SYMBOL(module_free_exec);
18048+#else
18049+void module_free_exec(struct module *mod, void *module_region)
18050+{
18051+ module_free(mod, module_region);
18052+}
18053+EXPORT_SYMBOL(module_free_exec);
18054+
18055+void *module_alloc_exec(unsigned long size)
18056+{
18057+ return __module_alloc(size, PAGE_KERNEL_RX);
18058+}
18059+EXPORT_SYMBOL(module_alloc_exec);
18060+#endif
18061+#endif
18062+
18063 #ifdef CONFIG_X86_32
18064 int apply_relocate(Elf32_Shdr *sechdrs,
18065 const char *strtab,
18066@@ -54,14 +99,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18067 unsigned int i;
18068 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18069 Elf32_Sym *sym;
18070- uint32_t *location;
18071+ uint32_t *plocation, location;
18072
18073 DEBUGP("Applying relocate section %u to %u\n", relsec,
18074 sechdrs[relsec].sh_info);
18075 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18076 /* This is where to make the change */
18077- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18078- + rel[i].r_offset;
18079+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18080+ location = (uint32_t)plocation;
18081+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18082+ plocation = ktla_ktva((void *)plocation);
18083 /* This is the symbol it is referring to. Note that all
18084 undefined symbols have been resolved. */
18085 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18086@@ -70,11 +117,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18087 switch (ELF32_R_TYPE(rel[i].r_info)) {
18088 case R_386_32:
18089 /* We add the value into the location given */
18090- *location += sym->st_value;
18091+ pax_open_kernel();
18092+ *plocation += sym->st_value;
18093+ pax_close_kernel();
18094 break;
18095 case R_386_PC32:
18096 /* Add the value, subtract its postition */
18097- *location += sym->st_value - (uint32_t)location;
18098+ pax_open_kernel();
18099+ *plocation += sym->st_value - location;
18100+ pax_close_kernel();
18101 break;
18102 default:
18103 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
18104@@ -119,21 +170,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18105 case R_X86_64_NONE:
18106 break;
18107 case R_X86_64_64:
18108+ pax_open_kernel();
18109 *(u64 *)loc = val;
18110+ pax_close_kernel();
18111 break;
18112 case R_X86_64_32:
18113+ pax_open_kernel();
18114 *(u32 *)loc = val;
18115+ pax_close_kernel();
18116 if (val != *(u32 *)loc)
18117 goto overflow;
18118 break;
18119 case R_X86_64_32S:
18120+ pax_open_kernel();
18121 *(s32 *)loc = val;
18122+ pax_close_kernel();
18123 if ((s64)val != *(s32 *)loc)
18124 goto overflow;
18125 break;
18126 case R_X86_64_PC32:
18127 val -= (u64)loc;
18128+ pax_open_kernel();
18129 *(u32 *)loc = val;
18130+ pax_close_kernel();
18131+
18132 #if 0
18133 if ((s64)val != *(s32 *)loc)
18134 goto overflow;
18135diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18136index a0b2f84..875ab81 100644
18137--- a/arch/x86/kernel/nmi.c
18138+++ b/arch/x86/kernel/nmi.c
18139@@ -460,6 +460,17 @@ static inline void nmi_nesting_postprocess(void)
18140 dotraplinkage notrace __kprobes void
18141 do_nmi(struct pt_regs *regs, long error_code)
18142 {
18143+
18144+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18145+ if (!user_mode(regs)) {
18146+ unsigned long cs = regs->cs & 0xFFFF;
18147+ unsigned long ip = ktva_ktla(regs->ip);
18148+
18149+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18150+ regs->ip = ip;
18151+ }
18152+#endif
18153+
18154 nmi_nesting_preprocess(regs);
18155
18156 nmi_enter();
18157diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18158index 676b8c7..870ba04 100644
18159--- a/arch/x86/kernel/paravirt-spinlocks.c
18160+++ b/arch/x86/kernel/paravirt-spinlocks.c
18161@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18162 arch_spin_lock(lock);
18163 }
18164
18165-struct pv_lock_ops pv_lock_ops = {
18166+struct pv_lock_ops pv_lock_ops __read_only = {
18167 #ifdef CONFIG_SMP
18168 .spin_is_locked = __ticket_spin_is_locked,
18169 .spin_is_contended = __ticket_spin_is_contended,
18170diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18171index 9ce8859..b49bf51 100644
18172--- a/arch/x86/kernel/paravirt.c
18173+++ b/arch/x86/kernel/paravirt.c
18174@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18175 {
18176 return x;
18177 }
18178+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18179+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18180+#endif
18181
18182 void __init default_banner(void)
18183 {
18184@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18185 if (opfunc == NULL)
18186 /* If there's no function, patch it with a ud2a (BUG) */
18187 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18188- else if (opfunc == _paravirt_nop)
18189+ else if (opfunc == (void *)_paravirt_nop)
18190 /* If the operation is a nop, then nop the callsite */
18191 ret = paravirt_patch_nop();
18192
18193 /* identity functions just return their single argument */
18194- else if (opfunc == _paravirt_ident_32)
18195+ else if (opfunc == (void *)_paravirt_ident_32)
18196 ret = paravirt_patch_ident_32(insnbuf, len);
18197- else if (opfunc == _paravirt_ident_64)
18198+ else if (opfunc == (void *)_paravirt_ident_64)
18199 ret = paravirt_patch_ident_64(insnbuf, len);
18200+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18201+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18202+ ret = paravirt_patch_ident_64(insnbuf, len);
18203+#endif
18204
18205 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18206 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18207@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18208 if (insn_len > len || start == NULL)
18209 insn_len = len;
18210 else
18211- memcpy(insnbuf, start, insn_len);
18212+ memcpy(insnbuf, ktla_ktva(start), insn_len);
18213
18214 return insn_len;
18215 }
18216@@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18217 preempt_enable();
18218 }
18219
18220-struct pv_info pv_info = {
18221+struct pv_info pv_info __read_only = {
18222 .name = "bare hardware",
18223 .paravirt_enabled = 0,
18224 .kernel_rpl = 0,
18225@@ -315,16 +322,16 @@ struct pv_info pv_info = {
18226 #endif
18227 };
18228
18229-struct pv_init_ops pv_init_ops = {
18230+struct pv_init_ops pv_init_ops __read_only = {
18231 .patch = native_patch,
18232 };
18233
18234-struct pv_time_ops pv_time_ops = {
18235+struct pv_time_ops pv_time_ops __read_only = {
18236 .sched_clock = native_sched_clock,
18237 .steal_clock = native_steal_clock,
18238 };
18239
18240-struct pv_irq_ops pv_irq_ops = {
18241+struct pv_irq_ops pv_irq_ops __read_only = {
18242 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18243 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18244 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18245@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18246 #endif
18247 };
18248
18249-struct pv_cpu_ops pv_cpu_ops = {
18250+struct pv_cpu_ops pv_cpu_ops __read_only = {
18251 .cpuid = native_cpuid,
18252 .get_debugreg = native_get_debugreg,
18253 .set_debugreg = native_set_debugreg,
18254@@ -397,21 +404,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18255 .end_context_switch = paravirt_nop,
18256 };
18257
18258-struct pv_apic_ops pv_apic_ops = {
18259+struct pv_apic_ops pv_apic_ops __read_only = {
18260 #ifdef CONFIG_X86_LOCAL_APIC
18261 .startup_ipi_hook = paravirt_nop,
18262 #endif
18263 };
18264
18265-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18266+#ifdef CONFIG_X86_32
18267+#ifdef CONFIG_X86_PAE
18268+/* 64-bit pagetable entries */
18269+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18270+#else
18271 /* 32-bit pagetable entries */
18272 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18273+#endif
18274 #else
18275 /* 64-bit pagetable entries */
18276 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18277 #endif
18278
18279-struct pv_mmu_ops pv_mmu_ops = {
18280+struct pv_mmu_ops pv_mmu_ops __read_only = {
18281
18282 .read_cr2 = native_read_cr2,
18283 .write_cr2 = native_write_cr2,
18284@@ -461,6 +473,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18285 .make_pud = PTE_IDENT,
18286
18287 .set_pgd = native_set_pgd,
18288+ .set_pgd_batched = native_set_pgd_batched,
18289 #endif
18290 #endif /* PAGETABLE_LEVELS >= 3 */
18291
18292@@ -480,6 +493,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18293 },
18294
18295 .set_fixmap = native_set_fixmap,
18296+
18297+#ifdef CONFIG_PAX_KERNEXEC
18298+ .pax_open_kernel = native_pax_open_kernel,
18299+ .pax_close_kernel = native_pax_close_kernel,
18300+#endif
18301+
18302 };
18303
18304 EXPORT_SYMBOL_GPL(pv_time_ops);
18305diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18306index 35ccf75..7a15747 100644
18307--- a/arch/x86/kernel/pci-iommu_table.c
18308+++ b/arch/x86/kernel/pci-iommu_table.c
18309@@ -2,7 +2,7 @@
18310 #include <asm/iommu_table.h>
18311 #include <linux/string.h>
18312 #include <linux/kallsyms.h>
18313-
18314+#include <linux/sched.h>
18315
18316 #define DEBUG 1
18317
18318diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18319index 735279e..5008677 100644
18320--- a/arch/x86/kernel/process.c
18321+++ b/arch/x86/kernel/process.c
18322@@ -34,7 +34,8 @@
18323 * section. Since TSS's are completely CPU-local, we want them
18324 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
18325 */
18326-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
18327+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
18328+EXPORT_SYMBOL(init_tss);
18329
18330 #ifdef CONFIG_X86_64
18331 static DEFINE_PER_CPU(unsigned char, is_idle);
18332@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
18333 task_xstate_cachep =
18334 kmem_cache_create("task_xstate", xstate_size,
18335 __alignof__(union thread_xstate),
18336- SLAB_PANIC | SLAB_NOTRACK, NULL);
18337+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18338 }
18339
18340 static inline void drop_fpu(struct task_struct *tsk)
18341@@ -115,7 +116,7 @@ void exit_thread(void)
18342 unsigned long *bp = t->io_bitmap_ptr;
18343
18344 if (bp) {
18345- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18346+ struct tss_struct *tss = init_tss + get_cpu();
18347
18348 t->io_bitmap_ptr = NULL;
18349 clear_thread_flag(TIF_IO_BITMAP);
18350@@ -147,7 +148,7 @@ void show_regs_common(void)
18351
18352 printk(KERN_CONT "\n");
18353 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
18354- current->pid, current->comm, print_tainted(),
18355+ task_pid_nr(current), current->comm, print_tainted(),
18356 init_utsname()->release,
18357 (int)strcspn(init_utsname()->version, " "),
18358 init_utsname()->version);
18359@@ -161,6 +162,9 @@ void flush_thread(void)
18360 {
18361 struct task_struct *tsk = current;
18362
18363+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18364+ loadsegment(gs, 0);
18365+#endif
18366 flush_ptrace_hw_breakpoint(tsk);
18367 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18368 drop_fpu(tsk);
18369@@ -318,10 +322,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18370 regs.di = (unsigned long) arg;
18371
18372 #ifdef CONFIG_X86_32
18373- regs.ds = __USER_DS;
18374- regs.es = __USER_DS;
18375+ regs.ds = __KERNEL_DS;
18376+ regs.es = __KERNEL_DS;
18377 regs.fs = __KERNEL_PERCPU;
18378- regs.gs = __KERNEL_STACK_CANARY;
18379+ savesegment(gs, regs.gs);
18380 #else
18381 regs.ss = __KERNEL_DS;
18382 #endif
18383@@ -407,7 +411,7 @@ static void __exit_idle(void)
18384 void exit_idle(void)
18385 {
18386 /* idle loop has pid 0 */
18387- if (current->pid)
18388+ if (task_pid_nr(current))
18389 return;
18390 __exit_idle();
18391 }
18392@@ -516,7 +520,7 @@ bool set_pm_idle_to_default(void)
18393
18394 return ret;
18395 }
18396-void stop_this_cpu(void *dummy)
18397+__noreturn void stop_this_cpu(void *dummy)
18398 {
18399 local_irq_disable();
18400 /*
18401@@ -746,16 +750,37 @@ static int __init idle_setup(char *str)
18402 }
18403 early_param("idle", idle_setup);
18404
18405-unsigned long arch_align_stack(unsigned long sp)
18406+#ifdef CONFIG_PAX_RANDKSTACK
18407+void pax_randomize_kstack(struct pt_regs *regs)
18408 {
18409- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18410- sp -= get_random_int() % 8192;
18411- return sp & ~0xf;
18412-}
18413+ struct thread_struct *thread = &current->thread;
18414+ unsigned long time;
18415
18416-unsigned long arch_randomize_brk(struct mm_struct *mm)
18417-{
18418- unsigned long range_end = mm->brk + 0x02000000;
18419- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18420-}
18421+ if (!randomize_va_space)
18422+ return;
18423+
18424+ if (v8086_mode(regs))
18425+ return;
18426
18427+ rdtscl(time);
18428+
18429+ /* P4 seems to return a 0 LSB, ignore it */
18430+#ifdef CONFIG_MPENTIUM4
18431+ time &= 0x3EUL;
18432+ time <<= 2;
18433+#elif defined(CONFIG_X86_64)
18434+ time &= 0xFUL;
18435+ time <<= 4;
18436+#else
18437+ time &= 0x1FUL;
18438+ time <<= 3;
18439+#endif
18440+
18441+ thread->sp0 ^= time;
18442+ load_sp0(init_tss + smp_processor_id(), thread);
18443+
18444+#ifdef CONFIG_X86_64
18445+ this_cpu_write(kernel_stack, thread->sp0);
18446+#endif
18447+}
18448+#endif
18449diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18450index 516fa18..80bd9e6 100644
18451--- a/arch/x86/kernel/process_32.c
18452+++ b/arch/x86/kernel/process_32.c
18453@@ -64,6 +64,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18454 unsigned long thread_saved_pc(struct task_struct *tsk)
18455 {
18456 return ((unsigned long *)tsk->thread.sp)[3];
18457+//XXX return tsk->thread.eip;
18458 }
18459
18460 void __show_regs(struct pt_regs *regs, int all)
18461@@ -73,15 +74,14 @@ void __show_regs(struct pt_regs *regs, int all)
18462 unsigned long sp;
18463 unsigned short ss, gs;
18464
18465- if (user_mode_vm(regs)) {
18466+ if (user_mode(regs)) {
18467 sp = regs->sp;
18468 ss = regs->ss & 0xffff;
18469- gs = get_user_gs(regs);
18470 } else {
18471 sp = kernel_stack_pointer(regs);
18472 savesegment(ss, ss);
18473- savesegment(gs, gs);
18474 }
18475+ gs = get_user_gs(regs);
18476
18477 show_regs_common();
18478
18479@@ -134,13 +134,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18480 struct task_struct *tsk;
18481 int err;
18482
18483- childregs = task_pt_regs(p);
18484+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18485 *childregs = *regs;
18486 childregs->ax = 0;
18487 childregs->sp = sp;
18488
18489 p->thread.sp = (unsigned long) childregs;
18490 p->thread.sp0 = (unsigned long) (childregs+1);
18491+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18492
18493 p->thread.ip = (unsigned long) ret_from_fork;
18494
18495@@ -231,7 +232,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18496 struct thread_struct *prev = &prev_p->thread,
18497 *next = &next_p->thread;
18498 int cpu = smp_processor_id();
18499- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18500+ struct tss_struct *tss = init_tss + cpu;
18501 fpu_switch_t fpu;
18502
18503 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18504@@ -255,6 +256,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18505 */
18506 lazy_save_gs(prev->gs);
18507
18508+#ifdef CONFIG_PAX_MEMORY_UDEREF
18509+ __set_fs(task_thread_info(next_p)->addr_limit);
18510+#endif
18511+
18512 /*
18513 * Load the per-thread Thread-Local Storage descriptor.
18514 */
18515@@ -285,6 +290,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18516 */
18517 arch_end_context_switch(next_p);
18518
18519+ this_cpu_write(current_task, next_p);
18520+ this_cpu_write(current_tinfo, &next_p->tinfo);
18521+
18522 /*
18523 * Restore %gs if needed (which is common)
18524 */
18525@@ -293,8 +301,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18526
18527 switch_fpu_finish(next_p, fpu);
18528
18529- this_cpu_write(current_task, next_p);
18530-
18531 return prev_p;
18532 }
18533
18534@@ -324,4 +330,3 @@ unsigned long get_wchan(struct task_struct *p)
18535 } while (count++ < 16);
18536 return 0;
18537 }
18538-
18539diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18540index 61cdf7f..797f06a 100644
18541--- a/arch/x86/kernel/process_64.c
18542+++ b/arch/x86/kernel/process_64.c
18543@@ -153,8 +153,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18544 struct pt_regs *childregs;
18545 struct task_struct *me = current;
18546
18547- childregs = ((struct pt_regs *)
18548- (THREAD_SIZE + task_stack_page(p))) - 1;
18549+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18550 *childregs = *regs;
18551
18552 childregs->ax = 0;
18553@@ -166,6 +165,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18554 p->thread.sp = (unsigned long) childregs;
18555 p->thread.sp0 = (unsigned long) (childregs+1);
18556 p->thread.usersp = me->thread.usersp;
18557+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18558
18559 set_tsk_thread_flag(p, TIF_FORK);
18560
18561@@ -271,7 +271,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18562 struct thread_struct *prev = &prev_p->thread;
18563 struct thread_struct *next = &next_p->thread;
18564 int cpu = smp_processor_id();
18565- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18566+ struct tss_struct *tss = init_tss + cpu;
18567 unsigned fsindex, gsindex;
18568 fpu_switch_t fpu;
18569
18570@@ -353,10 +353,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18571 prev->usersp = this_cpu_read(old_rsp);
18572 this_cpu_write(old_rsp, next->usersp);
18573 this_cpu_write(current_task, next_p);
18574+ this_cpu_write(current_tinfo, &next_p->tinfo);
18575
18576- this_cpu_write(kernel_stack,
18577- (unsigned long)task_stack_page(next_p) +
18578- THREAD_SIZE - KERNEL_STACK_OFFSET);
18579+ this_cpu_write(kernel_stack, next->sp0);
18580
18581 /*
18582 * Now maybe reload the debug registers and handle I/O bitmaps
18583@@ -425,12 +424,11 @@ unsigned long get_wchan(struct task_struct *p)
18584 if (!p || p == current || p->state == TASK_RUNNING)
18585 return 0;
18586 stack = (unsigned long)task_stack_page(p);
18587- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18588+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18589 return 0;
18590 fp = *(u64 *)(p->thread.sp);
18591 do {
18592- if (fp < (unsigned long)stack ||
18593- fp >= (unsigned long)stack+THREAD_SIZE)
18594+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18595 return 0;
18596 ip = *(u64 *)(fp+8);
18597 if (!in_sched_functions(ip))
18598diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18599index c4c6a5c..905f440 100644
18600--- a/arch/x86/kernel/ptrace.c
18601+++ b/arch/x86/kernel/ptrace.c
18602@@ -824,7 +824,7 @@ long arch_ptrace(struct task_struct *child, long request,
18603 unsigned long addr, unsigned long data)
18604 {
18605 int ret;
18606- unsigned long __user *datap = (unsigned long __user *)data;
18607+ unsigned long __user *datap = (__force unsigned long __user *)data;
18608
18609 switch (request) {
18610 /* read the word at location addr in the USER area. */
18611@@ -909,14 +909,14 @@ long arch_ptrace(struct task_struct *child, long request,
18612 if ((int) addr < 0)
18613 return -EIO;
18614 ret = do_get_thread_area(child, addr,
18615- (struct user_desc __user *)data);
18616+ (__force struct user_desc __user *) data);
18617 break;
18618
18619 case PTRACE_SET_THREAD_AREA:
18620 if ((int) addr < 0)
18621 return -EIO;
18622 ret = do_set_thread_area(child, addr,
18623- (struct user_desc __user *)data, 0);
18624+ (__force struct user_desc __user *) data, 0);
18625 break;
18626 #endif
18627
18628@@ -1426,7 +1426,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18629 memset(info, 0, sizeof(*info));
18630 info->si_signo = SIGTRAP;
18631 info->si_code = si_code;
18632- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18633+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18634 }
18635
18636 void user_single_step_siginfo(struct task_struct *tsk,
18637@@ -1455,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18638 # define IS_IA32 0
18639 #endif
18640
18641+#ifdef CONFIG_GRKERNSEC_SETXID
18642+extern void gr_delayed_cred_worker(void);
18643+#endif
18644+
18645 /*
18646 * We must return the syscall number to actually look up in the table.
18647 * This can be -1L to skip running any syscall at all.
18648@@ -1463,6 +1467,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18649 {
18650 long ret = 0;
18651
18652+#ifdef CONFIG_GRKERNSEC_SETXID
18653+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18654+ gr_delayed_cred_worker();
18655+#endif
18656+
18657 /*
18658 * If we stepped into a sysenter/syscall insn, it trapped in
18659 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18660@@ -1511,6 +1520,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18661 {
18662 bool step;
18663
18664+#ifdef CONFIG_GRKERNSEC_SETXID
18665+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18666+ gr_delayed_cred_worker();
18667+#endif
18668+
18669 audit_syscall_exit(regs);
18670
18671 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18672diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18673index 42eb330..139955c 100644
18674--- a/arch/x86/kernel/pvclock.c
18675+++ b/arch/x86/kernel/pvclock.c
18676@@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18677 return pv_tsc_khz;
18678 }
18679
18680-static atomic64_t last_value = ATOMIC64_INIT(0);
18681+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18682
18683 void pvclock_resume(void)
18684 {
18685- atomic64_set(&last_value, 0);
18686+ atomic64_set_unchecked(&last_value, 0);
18687 }
18688
18689 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18690@@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18691 * updating at the same time, and one of them could be slightly behind,
18692 * making the assumption that last_value always go forward fail to hold.
18693 */
18694- last = atomic64_read(&last_value);
18695+ last = atomic64_read_unchecked(&last_value);
18696 do {
18697 if (ret < last)
18698 return last;
18699- last = atomic64_cmpxchg(&last_value, last, ret);
18700+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18701 } while (unlikely(last != ret));
18702
18703 return ret;
18704diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18705index 5de92f1..2732385 100644
18706--- a/arch/x86/kernel/reboot.c
18707+++ b/arch/x86/kernel/reboot.c
18708@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
18709 EXPORT_SYMBOL(pm_power_off);
18710
18711 static const struct desc_ptr no_idt = {};
18712-static int reboot_mode;
18713+static unsigned short reboot_mode;
18714 enum reboot_type reboot_type = BOOT_ACPI;
18715 int reboot_force;
18716
18717@@ -157,11 +157,15 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
18718 return 0;
18719 }
18720
18721-void machine_real_restart(unsigned int type)
18722+__noreturn void machine_real_restart(unsigned int type)
18723 {
18724- void (*restart_lowmem)(unsigned int) = (void (*)(unsigned int))
18725+ void (* restart_lowmem)(unsigned int) = (void (*)(unsigned int))
18726 real_mode_header->machine_real_restart_asm;
18727
18728+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18729+ struct desc_struct *gdt;
18730+#endif
18731+
18732 local_irq_disable();
18733
18734 /*
18735@@ -189,10 +193,36 @@ void machine_real_restart(unsigned int type)
18736 * boot)". This seems like a fairly standard thing that gets set by
18737 * REBOOT.COM programs, and the previous reset routine did this
18738 * too. */
18739- *((unsigned short *)0x472) = reboot_mode;
18740+ *(unsigned short *)(__va(0x472)) = reboot_mode;
18741
18742 /* Jump to the identity-mapped low memory code */
18743+
18744+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18745+ gdt = get_cpu_gdt_table(smp_processor_id());
18746+ pax_open_kernel();
18747+#ifdef CONFIG_PAX_MEMORY_UDEREF
18748+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18749+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18750+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
18751+#endif
18752+#ifdef CONFIG_PAX_KERNEXEC
18753+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18754+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18755+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18756+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18757+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18758+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18759+#endif
18760+ pax_close_kernel();
18761+#endif
18762+
18763+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18764+ asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
18765+ unreachable();
18766+#else
18767 restart_lowmem(type);
18768+#endif
18769+
18770 }
18771 #ifdef CONFIG_APM_MODULE
18772 EXPORT_SYMBOL(machine_real_restart);
18773@@ -543,7 +573,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18774 * try to force a triple fault and then cycle between hitting the keyboard
18775 * controller and doing that
18776 */
18777-static void native_machine_emergency_restart(void)
18778+__noreturn static void native_machine_emergency_restart(void)
18779 {
18780 int i;
18781 int attempt = 0;
18782@@ -670,13 +700,13 @@ void native_machine_shutdown(void)
18783 #endif
18784 }
18785
18786-static void __machine_emergency_restart(int emergency)
18787+static __noreturn void __machine_emergency_restart(int emergency)
18788 {
18789 reboot_emergency = emergency;
18790 machine_ops.emergency_restart();
18791 }
18792
18793-static void native_machine_restart(char *__unused)
18794+static __noreturn void native_machine_restart(char *__unused)
18795 {
18796 printk("machine restart\n");
18797
18798@@ -685,7 +715,7 @@ static void native_machine_restart(char *__unused)
18799 __machine_emergency_restart(0);
18800 }
18801
18802-static void native_machine_halt(void)
18803+static __noreturn void native_machine_halt(void)
18804 {
18805 /* Stop other cpus and apics */
18806 machine_shutdown();
18807@@ -695,7 +725,7 @@ static void native_machine_halt(void)
18808 stop_this_cpu(NULL);
18809 }
18810
18811-static void native_machine_power_off(void)
18812+__noreturn static void native_machine_power_off(void)
18813 {
18814 if (pm_power_off) {
18815 if (!reboot_force)
18816@@ -704,6 +734,7 @@ static void native_machine_power_off(void)
18817 }
18818 /* A fallback in case there is no PM info available */
18819 tboot_shutdown(TB_SHUTDOWN_HALT);
18820+ unreachable();
18821 }
18822
18823 struct machine_ops machine_ops = {
18824diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
18825index 7a6f3b3..bed145d7 100644
18826--- a/arch/x86/kernel/relocate_kernel_64.S
18827+++ b/arch/x86/kernel/relocate_kernel_64.S
18828@@ -11,6 +11,7 @@
18829 #include <asm/kexec.h>
18830 #include <asm/processor-flags.h>
18831 #include <asm/pgtable_types.h>
18832+#include <asm/alternative-asm.h>
18833
18834 /*
18835 * Must be relocatable PIC code callable as a C function
18836@@ -160,13 +161,14 @@ identity_mapped:
18837 xorq %rbp, %rbp
18838 xorq %r8, %r8
18839 xorq %r9, %r9
18840- xorq %r10, %r9
18841+ xorq %r10, %r10
18842 xorq %r11, %r11
18843 xorq %r12, %r12
18844 xorq %r13, %r13
18845 xorq %r14, %r14
18846 xorq %r15, %r15
18847
18848+ pax_force_retaddr 0, 1
18849 ret
18850
18851 1:
18852diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
18853index 16be6dc..4686132 100644
18854--- a/arch/x86/kernel/setup.c
18855+++ b/arch/x86/kernel/setup.c
18856@@ -440,7 +440,7 @@ static void __init parse_setup_data(void)
18857
18858 switch (data->type) {
18859 case SETUP_E820_EXT:
18860- parse_e820_ext(data);
18861+ parse_e820_ext((struct setup_data __force_kernel *)data);
18862 break;
18863 case SETUP_DTB:
18864 add_dtb(pa_data);
18865@@ -632,7 +632,7 @@ static void __init trim_bios_range(void)
18866 * area (640->1Mb) as ram even though it is not.
18867 * take them out.
18868 */
18869- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
18870+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
18871 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
18872 }
18873
18874@@ -755,14 +755,14 @@ void __init setup_arch(char **cmdline_p)
18875
18876 if (!boot_params.hdr.root_flags)
18877 root_mountflags &= ~MS_RDONLY;
18878- init_mm.start_code = (unsigned long) _text;
18879- init_mm.end_code = (unsigned long) _etext;
18880+ init_mm.start_code = ktla_ktva((unsigned long) _text);
18881+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
18882 init_mm.end_data = (unsigned long) _edata;
18883 init_mm.brk = _brk_end;
18884
18885- code_resource.start = virt_to_phys(_text);
18886- code_resource.end = virt_to_phys(_etext)-1;
18887- data_resource.start = virt_to_phys(_etext);
18888+ code_resource.start = virt_to_phys(ktla_ktva(_text));
18889+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
18890+ data_resource.start = virt_to_phys(_sdata);
18891 data_resource.end = virt_to_phys(_edata)-1;
18892 bss_resource.start = virt_to_phys(&__bss_start);
18893 bss_resource.end = virt_to_phys(&__bss_stop)-1;
18894diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
18895index 5a98aa2..2f9288d 100644
18896--- a/arch/x86/kernel/setup_percpu.c
18897+++ b/arch/x86/kernel/setup_percpu.c
18898@@ -21,19 +21,17 @@
18899 #include <asm/cpu.h>
18900 #include <asm/stackprotector.h>
18901
18902-DEFINE_PER_CPU(int, cpu_number);
18903+#ifdef CONFIG_SMP
18904+DEFINE_PER_CPU(unsigned int, cpu_number);
18905 EXPORT_PER_CPU_SYMBOL(cpu_number);
18906+#endif
18907
18908-#ifdef CONFIG_X86_64
18909 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
18910-#else
18911-#define BOOT_PERCPU_OFFSET 0
18912-#endif
18913
18914 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
18915 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
18916
18917-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
18918+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
18919 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
18920 };
18921 EXPORT_SYMBOL(__per_cpu_offset);
18922@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
18923 {
18924 #ifdef CONFIG_X86_32
18925 struct desc_struct gdt;
18926+ unsigned long base = per_cpu_offset(cpu);
18927
18928- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
18929- 0x2 | DESCTYPE_S, 0x8);
18930- gdt.s = 1;
18931+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
18932+ 0x83 | DESCTYPE_S, 0xC);
18933 write_gdt_entry(get_cpu_gdt_table(cpu),
18934 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
18935 #endif
18936@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
18937 /* alrighty, percpu areas up and running */
18938 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
18939 for_each_possible_cpu(cpu) {
18940+#ifdef CONFIG_CC_STACKPROTECTOR
18941+#ifdef CONFIG_X86_32
18942+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
18943+#endif
18944+#endif
18945 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
18946 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
18947 per_cpu(cpu_number, cpu) = cpu;
18948@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
18949 */
18950 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
18951 #endif
18952+#ifdef CONFIG_CC_STACKPROTECTOR
18953+#ifdef CONFIG_X86_32
18954+ if (!cpu)
18955+ per_cpu(stack_canary.canary, cpu) = canary;
18956+#endif
18957+#endif
18958 /*
18959 * Up to this point, the boot CPU has been using .init.data
18960 * area. Reload any changed state for the boot CPU.
18961diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
18962index 21af737..fb45e22 100644
18963--- a/arch/x86/kernel/signal.c
18964+++ b/arch/x86/kernel/signal.c
18965@@ -191,7 +191,7 @@ static unsigned long align_sigframe(unsigned long sp)
18966 * Align the stack pointer according to the i386 ABI,
18967 * i.e. so that on function entry ((sp + 4) & 15) == 0.
18968 */
18969- sp = ((sp + 4) & -16ul) - 4;
18970+ sp = ((sp - 12) & -16ul) - 4;
18971 #else /* !CONFIG_X86_32 */
18972 sp = round_down(sp, 16) - 8;
18973 #endif
18974@@ -242,11 +242,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
18975 * Return an always-bogus address instead so we will die with SIGSEGV.
18976 */
18977 if (onsigstack && !likely(on_sig_stack(sp)))
18978- return (void __user *)-1L;
18979+ return (__force void __user *)-1L;
18980
18981 /* save i387 state */
18982 if (used_math() && save_i387_xstate(*fpstate) < 0)
18983- return (void __user *)-1L;
18984+ return (__force void __user *)-1L;
18985
18986 return (void __user *)sp;
18987 }
18988@@ -301,9 +301,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
18989 }
18990
18991 if (current->mm->context.vdso)
18992- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
18993+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
18994 else
18995- restorer = &frame->retcode;
18996+ restorer = (void __user *)&frame->retcode;
18997 if (ka->sa.sa_flags & SA_RESTORER)
18998 restorer = ka->sa.sa_restorer;
18999
19000@@ -317,7 +317,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19001 * reasons and because gdb uses it as a signature to notice
19002 * signal handler stack frames.
19003 */
19004- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19005+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19006
19007 if (err)
19008 return -EFAULT;
19009@@ -371,7 +371,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19010 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19011
19012 /* Set up to return from userspace. */
19013- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19014+ if (current->mm->context.vdso)
19015+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19016+ else
19017+ restorer = (void __user *)&frame->retcode;
19018 if (ka->sa.sa_flags & SA_RESTORER)
19019 restorer = ka->sa.sa_restorer;
19020 put_user_ex(restorer, &frame->pretcode);
19021@@ -383,7 +386,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19022 * reasons and because gdb uses it as a signature to notice
19023 * signal handler stack frames.
19024 */
19025- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19026+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19027 } put_user_catch(err);
19028
19029 if (err)
19030diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19031index 7bd8a08..2659b5b 100644
19032--- a/arch/x86/kernel/smpboot.c
19033+++ b/arch/x86/kernel/smpboot.c
19034@@ -679,6 +679,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19035 idle->thread.sp = (unsigned long) (((struct pt_regs *)
19036 (THREAD_SIZE + task_stack_page(idle))) - 1);
19037 per_cpu(current_task, cpu) = idle;
19038+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
19039
19040 #ifdef CONFIG_X86_32
19041 /* Stack for startup_32 can be just as for start_secondary onwards */
19042@@ -686,11 +687,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19043 #else
19044 clear_tsk_thread_flag(idle, TIF_FORK);
19045 initial_gs = per_cpu_offset(cpu);
19046- per_cpu(kernel_stack, cpu) =
19047- (unsigned long)task_stack_page(idle) -
19048- KERNEL_STACK_OFFSET + THREAD_SIZE;
19049+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
19050 #endif
19051+
19052+ pax_open_kernel();
19053 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19054+ pax_close_kernel();
19055+
19056 initial_code = (unsigned long)start_secondary;
19057 stack_start = idle->thread.sp;
19058
19059@@ -826,6 +829,12 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
19060
19061 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19062
19063+#ifdef CONFIG_PAX_PER_CPU_PGD
19064+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19065+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19066+ KERNEL_PGD_PTRS);
19067+#endif
19068+
19069 err = do_boot_cpu(apicid, cpu, tidle);
19070 if (err) {
19071 pr_debug("do_boot_cpu failed %d\n", err);
19072diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19073index c346d11..d43b163 100644
19074--- a/arch/x86/kernel/step.c
19075+++ b/arch/x86/kernel/step.c
19076@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19077 struct desc_struct *desc;
19078 unsigned long base;
19079
19080- seg &= ~7UL;
19081+ seg >>= 3;
19082
19083 mutex_lock(&child->mm->context.lock);
19084- if (unlikely((seg >> 3) >= child->mm->context.size))
19085+ if (unlikely(seg >= child->mm->context.size))
19086 addr = -1L; /* bogus selector, access would fault */
19087 else {
19088 desc = child->mm->context.ldt + seg;
19089@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19090 addr += base;
19091 }
19092 mutex_unlock(&child->mm->context.lock);
19093- }
19094+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19095+ addr = ktla_ktva(addr);
19096
19097 return addr;
19098 }
19099@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19100 unsigned char opcode[15];
19101 unsigned long addr = convert_ip_to_linear(child, regs);
19102
19103+ if (addr == -EINVAL)
19104+ return 0;
19105+
19106 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19107 for (i = 0; i < copied; i++) {
19108 switch (opcode[i]) {
19109diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19110index 0b0cb5f..db6b9ed 100644
19111--- a/arch/x86/kernel/sys_i386_32.c
19112+++ b/arch/x86/kernel/sys_i386_32.c
19113@@ -24,17 +24,224 @@
19114
19115 #include <asm/syscalls.h>
19116
19117-/*
19118- * Do a system call from kernel instead of calling sys_execve so we
19119- * end up with proper pt_regs.
19120- */
19121-int kernel_execve(const char *filename,
19122- const char *const argv[],
19123- const char *const envp[])
19124+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19125 {
19126- long __res;
19127- asm volatile ("int $0x80"
19128- : "=a" (__res)
19129- : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19130- return __res;
19131+ unsigned long pax_task_size = TASK_SIZE;
19132+
19133+#ifdef CONFIG_PAX_SEGMEXEC
19134+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19135+ pax_task_size = SEGMEXEC_TASK_SIZE;
19136+#endif
19137+
19138+ if (len > pax_task_size || addr > pax_task_size - len)
19139+ return -EINVAL;
19140+
19141+ return 0;
19142+}
19143+
19144+unsigned long
19145+arch_get_unmapped_area(struct file *filp, unsigned long addr,
19146+ unsigned long len, unsigned long pgoff, unsigned long flags)
19147+{
19148+ struct mm_struct *mm = current->mm;
19149+ struct vm_area_struct *vma;
19150+ unsigned long start_addr, pax_task_size = TASK_SIZE;
19151+
19152+#ifdef CONFIG_PAX_SEGMEXEC
19153+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19154+ pax_task_size = SEGMEXEC_TASK_SIZE;
19155+#endif
19156+
19157+ pax_task_size -= PAGE_SIZE;
19158+
19159+ if (len > pax_task_size)
19160+ return -ENOMEM;
19161+
19162+ if (flags & MAP_FIXED)
19163+ return addr;
19164+
19165+#ifdef CONFIG_PAX_RANDMMAP
19166+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19167+#endif
19168+
19169+ if (addr) {
19170+ addr = PAGE_ALIGN(addr);
19171+ if (pax_task_size - len >= addr) {
19172+ vma = find_vma(mm, addr);
19173+ if (check_heap_stack_gap(vma, addr, len))
19174+ return addr;
19175+ }
19176+ }
19177+ if (len > mm->cached_hole_size) {
19178+ start_addr = addr = mm->free_area_cache;
19179+ } else {
19180+ start_addr = addr = mm->mmap_base;
19181+ mm->cached_hole_size = 0;
19182+ }
19183+
19184+#ifdef CONFIG_PAX_PAGEEXEC
19185+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19186+ start_addr = 0x00110000UL;
19187+
19188+#ifdef CONFIG_PAX_RANDMMAP
19189+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19190+ start_addr += mm->delta_mmap & 0x03FFF000UL;
19191+#endif
19192+
19193+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19194+ start_addr = addr = mm->mmap_base;
19195+ else
19196+ addr = start_addr;
19197+ }
19198+#endif
19199+
19200+full_search:
19201+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19202+ /* At this point: (!vma || addr < vma->vm_end). */
19203+ if (pax_task_size - len < addr) {
19204+ /*
19205+ * Start a new search - just in case we missed
19206+ * some holes.
19207+ */
19208+ if (start_addr != mm->mmap_base) {
19209+ start_addr = addr = mm->mmap_base;
19210+ mm->cached_hole_size = 0;
19211+ goto full_search;
19212+ }
19213+ return -ENOMEM;
19214+ }
19215+ if (check_heap_stack_gap(vma, addr, len))
19216+ break;
19217+ if (addr + mm->cached_hole_size < vma->vm_start)
19218+ mm->cached_hole_size = vma->vm_start - addr;
19219+ addr = vma->vm_end;
19220+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
19221+ start_addr = addr = mm->mmap_base;
19222+ mm->cached_hole_size = 0;
19223+ goto full_search;
19224+ }
19225+ }
19226+
19227+ /*
19228+ * Remember the place where we stopped the search:
19229+ */
19230+ mm->free_area_cache = addr + len;
19231+ return addr;
19232+}
19233+
19234+unsigned long
19235+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19236+ const unsigned long len, const unsigned long pgoff,
19237+ const unsigned long flags)
19238+{
19239+ struct vm_area_struct *vma;
19240+ struct mm_struct *mm = current->mm;
19241+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19242+
19243+#ifdef CONFIG_PAX_SEGMEXEC
19244+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19245+ pax_task_size = SEGMEXEC_TASK_SIZE;
19246+#endif
19247+
19248+ pax_task_size -= PAGE_SIZE;
19249+
19250+ /* requested length too big for entire address space */
19251+ if (len > pax_task_size)
19252+ return -ENOMEM;
19253+
19254+ if (flags & MAP_FIXED)
19255+ return addr;
19256+
19257+#ifdef CONFIG_PAX_PAGEEXEC
19258+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19259+ goto bottomup;
19260+#endif
19261+
19262+#ifdef CONFIG_PAX_RANDMMAP
19263+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19264+#endif
19265+
19266+ /* requesting a specific address */
19267+ if (addr) {
19268+ addr = PAGE_ALIGN(addr);
19269+ if (pax_task_size - len >= addr) {
19270+ vma = find_vma(mm, addr);
19271+ if (check_heap_stack_gap(vma, addr, len))
19272+ return addr;
19273+ }
19274+ }
19275+
19276+ /* check if free_area_cache is useful for us */
19277+ if (len <= mm->cached_hole_size) {
19278+ mm->cached_hole_size = 0;
19279+ mm->free_area_cache = mm->mmap_base;
19280+ }
19281+
19282+ /* either no address requested or can't fit in requested address hole */
19283+ addr = mm->free_area_cache;
19284+
19285+ /* make sure it can fit in the remaining address space */
19286+ if (addr > len) {
19287+ vma = find_vma(mm, addr-len);
19288+ if (check_heap_stack_gap(vma, addr - len, len))
19289+ /* remember the address as a hint for next time */
19290+ return (mm->free_area_cache = addr-len);
19291+ }
19292+
19293+ if (mm->mmap_base < len)
19294+ goto bottomup;
19295+
19296+ addr = mm->mmap_base-len;
19297+
19298+ do {
19299+ /*
19300+ * Lookup failure means no vma is above this address,
19301+ * else if new region fits below vma->vm_start,
19302+ * return with success:
19303+ */
19304+ vma = find_vma(mm, addr);
19305+ if (check_heap_stack_gap(vma, addr, len))
19306+ /* remember the address as a hint for next time */
19307+ return (mm->free_area_cache = addr);
19308+
19309+ /* remember the largest hole we saw so far */
19310+ if (addr + mm->cached_hole_size < vma->vm_start)
19311+ mm->cached_hole_size = vma->vm_start - addr;
19312+
19313+ /* try just below the current vma->vm_start */
19314+ addr = skip_heap_stack_gap(vma, len);
19315+ } while (!IS_ERR_VALUE(addr));
19316+
19317+bottomup:
19318+ /*
19319+ * A failed mmap() very likely causes application failure,
19320+ * so fall back to the bottom-up function here. This scenario
19321+ * can happen with large stack limits and large mmap()
19322+ * allocations.
19323+ */
19324+
19325+#ifdef CONFIG_PAX_SEGMEXEC
19326+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19327+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19328+ else
19329+#endif
19330+
19331+ mm->mmap_base = TASK_UNMAPPED_BASE;
19332+
19333+#ifdef CONFIG_PAX_RANDMMAP
19334+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19335+ mm->mmap_base += mm->delta_mmap;
19336+#endif
19337+
19338+ mm->free_area_cache = mm->mmap_base;
19339+ mm->cached_hole_size = ~0UL;
19340+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19341+ /*
19342+ * Restore the topdown base:
19343+ */
19344+ mm->mmap_base = base;
19345+ mm->free_area_cache = base;
19346+ mm->cached_hole_size = ~0UL;
19347+
19348+ return addr;
19349 }
19350diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19351index b4d3c39..82bb73b 100644
19352--- a/arch/x86/kernel/sys_x86_64.c
19353+++ b/arch/x86/kernel/sys_x86_64.c
19354@@ -95,8 +95,8 @@ out:
19355 return error;
19356 }
19357
19358-static void find_start_end(unsigned long flags, unsigned long *begin,
19359- unsigned long *end)
19360+static void find_start_end(struct mm_struct *mm, unsigned long flags,
19361+ unsigned long *begin, unsigned long *end)
19362 {
19363 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19364 unsigned long new_begin;
19365@@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19366 *begin = new_begin;
19367 }
19368 } else {
19369- *begin = TASK_UNMAPPED_BASE;
19370+ *begin = mm->mmap_base;
19371 *end = TASK_SIZE;
19372 }
19373 }
19374@@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19375 if (flags & MAP_FIXED)
19376 return addr;
19377
19378- find_start_end(flags, &begin, &end);
19379+ find_start_end(mm, flags, &begin, &end);
19380
19381 if (len > end)
19382 return -ENOMEM;
19383
19384+#ifdef CONFIG_PAX_RANDMMAP
19385+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19386+#endif
19387+
19388 if (addr) {
19389 addr = PAGE_ALIGN(addr);
19390 vma = find_vma(mm, addr);
19391- if (end - len >= addr &&
19392- (!vma || addr + len <= vma->vm_start))
19393+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19394 return addr;
19395 }
19396 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19397@@ -172,7 +175,7 @@ full_search:
19398 }
19399 return -ENOMEM;
19400 }
19401- if (!vma || addr + len <= vma->vm_start) {
19402+ if (check_heap_stack_gap(vma, addr, len)) {
19403 /*
19404 * Remember the place where we stopped the search:
19405 */
19406@@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19407 {
19408 struct vm_area_struct *vma;
19409 struct mm_struct *mm = current->mm;
19410- unsigned long addr = addr0, start_addr;
19411+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19412
19413 /* requested length too big for entire address space */
19414 if (len > TASK_SIZE)
19415@@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19416 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19417 goto bottomup;
19418
19419+#ifdef CONFIG_PAX_RANDMMAP
19420+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19421+#endif
19422+
19423 /* requesting a specific address */
19424 if (addr) {
19425 addr = PAGE_ALIGN(addr);
19426- vma = find_vma(mm, addr);
19427- if (TASK_SIZE - len >= addr &&
19428- (!vma || addr + len <= vma->vm_start))
19429- return addr;
19430+ if (TASK_SIZE - len >= addr) {
19431+ vma = find_vma(mm, addr);
19432+ if (check_heap_stack_gap(vma, addr, len))
19433+ return addr;
19434+ }
19435 }
19436
19437 /* check if free_area_cache is useful for us */
19438@@ -240,7 +248,7 @@ try_again:
19439 * return with success:
19440 */
19441 vma = find_vma(mm, addr);
19442- if (!vma || addr+len <= vma->vm_start)
19443+ if (check_heap_stack_gap(vma, addr, len))
19444 /* remember the address as a hint for next time */
19445 return mm->free_area_cache = addr;
19446
19447@@ -249,8 +257,8 @@ try_again:
19448 mm->cached_hole_size = vma->vm_start - addr;
19449
19450 /* try just below the current vma->vm_start */
19451- addr = vma->vm_start-len;
19452- } while (len < vma->vm_start);
19453+ addr = skip_heap_stack_gap(vma, len);
19454+ } while (!IS_ERR_VALUE(addr));
19455
19456 fail:
19457 /*
19458@@ -270,13 +278,21 @@ bottomup:
19459 * can happen with large stack limits and large mmap()
19460 * allocations.
19461 */
19462+ mm->mmap_base = TASK_UNMAPPED_BASE;
19463+
19464+#ifdef CONFIG_PAX_RANDMMAP
19465+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19466+ mm->mmap_base += mm->delta_mmap;
19467+#endif
19468+
19469+ mm->free_area_cache = mm->mmap_base;
19470 mm->cached_hole_size = ~0UL;
19471- mm->free_area_cache = TASK_UNMAPPED_BASE;
19472 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19473 /*
19474 * Restore the topdown base:
19475 */
19476- mm->free_area_cache = mm->mmap_base;
19477+ mm->mmap_base = base;
19478+ mm->free_area_cache = base;
19479 mm->cached_hole_size = ~0UL;
19480
19481 return addr;
19482diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19483index f84fe00..93fe08f 100644
19484--- a/arch/x86/kernel/tboot.c
19485+++ b/arch/x86/kernel/tboot.c
19486@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
19487
19488 void tboot_shutdown(u32 shutdown_type)
19489 {
19490- void (*shutdown)(void);
19491+ void (* __noreturn shutdown)(void);
19492
19493 if (!tboot_enabled())
19494 return;
19495@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
19496
19497 switch_to_tboot_pt();
19498
19499- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19500+ shutdown = (void *)tboot->shutdown_entry;
19501 shutdown();
19502
19503 /* should not reach here */
19504@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19505 return 0;
19506 }
19507
19508-static atomic_t ap_wfs_count;
19509+static atomic_unchecked_t ap_wfs_count;
19510
19511 static int tboot_wait_for_aps(int num_aps)
19512 {
19513@@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19514 {
19515 switch (action) {
19516 case CPU_DYING:
19517- atomic_inc(&ap_wfs_count);
19518+ atomic_inc_unchecked(&ap_wfs_count);
19519 if (num_online_cpus() == 1)
19520- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19521+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19522 return NOTIFY_BAD;
19523 break;
19524 }
19525@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
19526
19527 tboot_create_trampoline();
19528
19529- atomic_set(&ap_wfs_count, 0);
19530+ atomic_set_unchecked(&ap_wfs_count, 0);
19531 register_hotcpu_notifier(&tboot_cpu_notifier);
19532
19533 acpi_os_set_prepare_sleep(&tboot_sleep);
19534diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19535index 24d3c91..d06b473 100644
19536--- a/arch/x86/kernel/time.c
19537+++ b/arch/x86/kernel/time.c
19538@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19539 {
19540 unsigned long pc = instruction_pointer(regs);
19541
19542- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19543+ if (!user_mode(regs) && in_lock_functions(pc)) {
19544 #ifdef CONFIG_FRAME_POINTER
19545- return *(unsigned long *)(regs->bp + sizeof(long));
19546+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19547 #else
19548 unsigned long *sp =
19549 (unsigned long *)kernel_stack_pointer(regs);
19550@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19551 * or above a saved flags. Eflags has bits 22-31 zero,
19552 * kernel addresses don't.
19553 */
19554+
19555+#ifdef CONFIG_PAX_KERNEXEC
19556+ return ktla_ktva(sp[0]);
19557+#else
19558 if (sp[0] >> 22)
19559 return sp[0];
19560 if (sp[1] >> 22)
19561 return sp[1];
19562 #endif
19563+
19564+#endif
19565 }
19566 return pc;
19567 }
19568diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19569index 9d9d2f9..ed344e4 100644
19570--- a/arch/x86/kernel/tls.c
19571+++ b/arch/x86/kernel/tls.c
19572@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19573 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19574 return -EINVAL;
19575
19576+#ifdef CONFIG_PAX_SEGMEXEC
19577+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19578+ return -EINVAL;
19579+#endif
19580+
19581 set_tls_desc(p, idx, &info, 1);
19582
19583 return 0;
19584diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19585index 05b31d9..501d3ba 100644
19586--- a/arch/x86/kernel/traps.c
19587+++ b/arch/x86/kernel/traps.c
19588@@ -67,12 +67,6 @@ asmlinkage int system_call(void);
19589
19590 /* Do we ignore FPU interrupts ? */
19591 char ignore_fpu_irq;
19592-
19593-/*
19594- * The IDT has to be page-aligned to simplify the Pentium
19595- * F0 0F bug workaround.
19596- */
19597-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19598 #endif
19599
19600 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19601@@ -105,13 +99,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19602 }
19603
19604 static void __kprobes
19605-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19606+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19607 long error_code, siginfo_t *info)
19608 {
19609 struct task_struct *tsk = current;
19610
19611 #ifdef CONFIG_X86_32
19612- if (regs->flags & X86_VM_MASK) {
19613+ if (v8086_mode(regs)) {
19614 /*
19615 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19616 * On nmi (interrupt 2), do_trap should not be called.
19617@@ -122,7 +116,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19618 }
19619 #endif
19620
19621- if (!user_mode(regs))
19622+ if (!user_mode_novm(regs))
19623 goto kernel_trap;
19624
19625 #ifdef CONFIG_X86_32
19626@@ -145,7 +139,7 @@ trap_signal:
19627 printk_ratelimit()) {
19628 printk(KERN_INFO
19629 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19630- tsk->comm, tsk->pid, str,
19631+ tsk->comm, task_pid_nr(tsk), str,
19632 regs->ip, regs->sp, error_code);
19633 print_vma_addr(" in ", regs->ip);
19634 printk("\n");
19635@@ -162,8 +156,20 @@ kernel_trap:
19636 if (!fixup_exception(regs)) {
19637 tsk->thread.error_code = error_code;
19638 tsk->thread.trap_nr = trapnr;
19639+
19640+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19641+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19642+ str = "PAX: suspicious stack segment fault";
19643+#endif
19644+
19645 die(str, regs, error_code);
19646 }
19647+
19648+#ifdef CONFIG_PAX_REFCOUNT
19649+ if (trapnr == 4)
19650+ pax_report_refcount_overflow(regs);
19651+#endif
19652+
19653 return;
19654
19655 #ifdef CONFIG_X86_32
19656@@ -256,14 +262,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19657 conditional_sti(regs);
19658
19659 #ifdef CONFIG_X86_32
19660- if (regs->flags & X86_VM_MASK)
19661+ if (v8086_mode(regs))
19662 goto gp_in_vm86;
19663 #endif
19664
19665 tsk = current;
19666- if (!user_mode(regs))
19667+ if (!user_mode_novm(regs))
19668 goto gp_in_kernel;
19669
19670+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19671+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19672+ struct mm_struct *mm = tsk->mm;
19673+ unsigned long limit;
19674+
19675+ down_write(&mm->mmap_sem);
19676+ limit = mm->context.user_cs_limit;
19677+ if (limit < TASK_SIZE) {
19678+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19679+ up_write(&mm->mmap_sem);
19680+ return;
19681+ }
19682+ up_write(&mm->mmap_sem);
19683+ }
19684+#endif
19685+
19686 tsk->thread.error_code = error_code;
19687 tsk->thread.trap_nr = X86_TRAP_GP;
19688
19689@@ -296,6 +318,13 @@ gp_in_kernel:
19690 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
19691 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
19692 return;
19693+
19694+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19695+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19696+ die("PAX: suspicious general protection fault", regs, error_code);
19697+ else
19698+#endif
19699+
19700 die("general protection fault", regs, error_code);
19701 }
19702
19703@@ -431,7 +460,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19704 /* It's safe to allow irq's after DR6 has been saved */
19705 preempt_conditional_sti(regs);
19706
19707- if (regs->flags & X86_VM_MASK) {
19708+ if (v8086_mode(regs)) {
19709 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
19710 X86_TRAP_DB);
19711 preempt_conditional_cli(regs);
19712@@ -446,7 +475,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19713 * We already checked v86 mode above, so we can check for kernel mode
19714 * by just checking the CPL of CS.
19715 */
19716- if ((dr6 & DR_STEP) && !user_mode(regs)) {
19717+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19718 tsk->thread.debugreg6 &= ~DR_STEP;
19719 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19720 regs->flags &= ~X86_EFLAGS_TF;
19721@@ -477,7 +506,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19722 return;
19723 conditional_sti(regs);
19724
19725- if (!user_mode_vm(regs))
19726+ if (!user_mode(regs))
19727 {
19728 if (!fixup_exception(regs)) {
19729 task->thread.error_code = error_code;
19730diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
19731index dc4e910..c9dedab 100644
19732--- a/arch/x86/kernel/uprobes.c
19733+++ b/arch/x86/kernel/uprobes.c
19734@@ -606,7 +606,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
19735 int ret = NOTIFY_DONE;
19736
19737 /* We are only interested in userspace traps */
19738- if (regs && !user_mode_vm(regs))
19739+ if (regs && !user_mode(regs))
19740 return NOTIFY_DONE;
19741
19742 switch (val) {
19743diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19744index b9242ba..50c5edd 100644
19745--- a/arch/x86/kernel/verify_cpu.S
19746+++ b/arch/x86/kernel/verify_cpu.S
19747@@ -20,6 +20,7 @@
19748 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19749 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19750 * arch/x86/kernel/head_32.S: processor startup
19751+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19752 *
19753 * verify_cpu, returns the status of longmode and SSE in register %eax.
19754 * 0: Success 1: Failure
19755diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19756index 255f58a..5e91150 100644
19757--- a/arch/x86/kernel/vm86_32.c
19758+++ b/arch/x86/kernel/vm86_32.c
19759@@ -41,6 +41,7 @@
19760 #include <linux/ptrace.h>
19761 #include <linux/audit.h>
19762 #include <linux/stddef.h>
19763+#include <linux/grsecurity.h>
19764
19765 #include <asm/uaccess.h>
19766 #include <asm/io.h>
19767@@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19768 do_exit(SIGSEGV);
19769 }
19770
19771- tss = &per_cpu(init_tss, get_cpu());
19772+ tss = init_tss + get_cpu();
19773 current->thread.sp0 = current->thread.saved_sp0;
19774 current->thread.sysenter_cs = __KERNEL_CS;
19775 load_sp0(tss, &current->thread);
19776@@ -210,6 +211,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19777 struct task_struct *tsk;
19778 int tmp, ret = -EPERM;
19779
19780+#ifdef CONFIG_GRKERNSEC_VM86
19781+ if (!capable(CAP_SYS_RAWIO)) {
19782+ gr_handle_vm86();
19783+ goto out;
19784+ }
19785+#endif
19786+
19787 tsk = current;
19788 if (tsk->thread.saved_sp0)
19789 goto out;
19790@@ -240,6 +248,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19791 int tmp, ret;
19792 struct vm86plus_struct __user *v86;
19793
19794+#ifdef CONFIG_GRKERNSEC_VM86
19795+ if (!capable(CAP_SYS_RAWIO)) {
19796+ gr_handle_vm86();
19797+ ret = -EPERM;
19798+ goto out;
19799+ }
19800+#endif
19801+
19802 tsk = current;
19803 switch (cmd) {
19804 case VM86_REQUEST_IRQ:
19805@@ -326,7 +342,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
19806 tsk->thread.saved_fs = info->regs32->fs;
19807 tsk->thread.saved_gs = get_user_gs(info->regs32);
19808
19809- tss = &per_cpu(init_tss, get_cpu());
19810+ tss = init_tss + get_cpu();
19811 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
19812 if (cpu_has_sep)
19813 tsk->thread.sysenter_cs = 0;
19814@@ -533,7 +549,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
19815 goto cannot_handle;
19816 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
19817 goto cannot_handle;
19818- intr_ptr = (unsigned long __user *) (i << 2);
19819+ intr_ptr = (__force unsigned long __user *) (i << 2);
19820 if (get_user(segoffs, intr_ptr))
19821 goto cannot_handle;
19822 if ((segoffs >> 16) == BIOSSEG)
19823diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
19824index 22a1530..8fbaaad 100644
19825--- a/arch/x86/kernel/vmlinux.lds.S
19826+++ b/arch/x86/kernel/vmlinux.lds.S
19827@@ -26,6 +26,13 @@
19828 #include <asm/page_types.h>
19829 #include <asm/cache.h>
19830 #include <asm/boot.h>
19831+#include <asm/segment.h>
19832+
19833+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19834+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
19835+#else
19836+#define __KERNEL_TEXT_OFFSET 0
19837+#endif
19838
19839 #undef i386 /* in case the preprocessor is a 32bit one */
19840
19841@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
19842
19843 PHDRS {
19844 text PT_LOAD FLAGS(5); /* R_E */
19845+#ifdef CONFIG_X86_32
19846+ module PT_LOAD FLAGS(5); /* R_E */
19847+#endif
19848+#ifdef CONFIG_XEN
19849+ rodata PT_LOAD FLAGS(5); /* R_E */
19850+#else
19851+ rodata PT_LOAD FLAGS(4); /* R__ */
19852+#endif
19853 data PT_LOAD FLAGS(6); /* RW_ */
19854-#ifdef CONFIG_X86_64
19855+ init.begin PT_LOAD FLAGS(6); /* RW_ */
19856 #ifdef CONFIG_SMP
19857 percpu PT_LOAD FLAGS(6); /* RW_ */
19858 #endif
19859+ text.init PT_LOAD FLAGS(5); /* R_E */
19860+ text.exit PT_LOAD FLAGS(5); /* R_E */
19861 init PT_LOAD FLAGS(7); /* RWE */
19862-#endif
19863 note PT_NOTE FLAGS(0); /* ___ */
19864 }
19865
19866 SECTIONS
19867 {
19868 #ifdef CONFIG_X86_32
19869- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
19870- phys_startup_32 = startup_32 - LOAD_OFFSET;
19871+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
19872 #else
19873- . = __START_KERNEL;
19874- phys_startup_64 = startup_64 - LOAD_OFFSET;
19875+ . = __START_KERNEL;
19876 #endif
19877
19878 /* Text and read-only data */
19879- .text : AT(ADDR(.text) - LOAD_OFFSET) {
19880- _text = .;
19881+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19882 /* bootstrapping code */
19883+#ifdef CONFIG_X86_32
19884+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19885+#else
19886+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19887+#endif
19888+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19889+ _text = .;
19890 HEAD_TEXT
19891 #ifdef CONFIG_X86_32
19892 . = ALIGN(PAGE_SIZE);
19893@@ -108,13 +128,48 @@ SECTIONS
19894 IRQENTRY_TEXT
19895 *(.fixup)
19896 *(.gnu.warning)
19897- /* End of text section */
19898- _etext = .;
19899 } :text = 0x9090
19900
19901- NOTES :text :note
19902+ . += __KERNEL_TEXT_OFFSET;
19903
19904- EXCEPTION_TABLE(16) :text = 0x9090
19905+#ifdef CONFIG_X86_32
19906+ . = ALIGN(PAGE_SIZE);
19907+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
19908+
19909+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
19910+ MODULES_EXEC_VADDR = .;
19911+ BYTE(0)
19912+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
19913+ . = ALIGN(HPAGE_SIZE) - 1;
19914+ MODULES_EXEC_END = .;
19915+#endif
19916+
19917+ } :module
19918+#endif
19919+
19920+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
19921+ /* End of text section */
19922+ BYTE(0)
19923+ _etext = . - __KERNEL_TEXT_OFFSET;
19924+ }
19925+
19926+#ifdef CONFIG_X86_32
19927+ . = ALIGN(PAGE_SIZE);
19928+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
19929+ *(.idt)
19930+ . = ALIGN(PAGE_SIZE);
19931+ *(.empty_zero_page)
19932+ *(.initial_pg_fixmap)
19933+ *(.initial_pg_pmd)
19934+ *(.initial_page_table)
19935+ *(.swapper_pg_dir)
19936+ } :rodata
19937+#endif
19938+
19939+ . = ALIGN(PAGE_SIZE);
19940+ NOTES :rodata :note
19941+
19942+ EXCEPTION_TABLE(16) :rodata
19943
19944 #if defined(CONFIG_DEBUG_RODATA)
19945 /* .text should occupy whole number of pages */
19946@@ -126,16 +181,20 @@ SECTIONS
19947
19948 /* Data */
19949 .data : AT(ADDR(.data) - LOAD_OFFSET) {
19950+
19951+#ifdef CONFIG_PAX_KERNEXEC
19952+ . = ALIGN(HPAGE_SIZE);
19953+#else
19954+ . = ALIGN(PAGE_SIZE);
19955+#endif
19956+
19957 /* Start of data section */
19958 _sdata = .;
19959
19960 /* init_task */
19961 INIT_TASK_DATA(THREAD_SIZE)
19962
19963-#ifdef CONFIG_X86_32
19964- /* 32 bit has nosave before _edata */
19965 NOSAVE_DATA
19966-#endif
19967
19968 PAGE_ALIGNED_DATA(PAGE_SIZE)
19969
19970@@ -176,12 +235,19 @@ SECTIONS
19971 #endif /* CONFIG_X86_64 */
19972
19973 /* Init code and data - will be freed after init */
19974- . = ALIGN(PAGE_SIZE);
19975 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
19976+ BYTE(0)
19977+
19978+#ifdef CONFIG_PAX_KERNEXEC
19979+ . = ALIGN(HPAGE_SIZE);
19980+#else
19981+ . = ALIGN(PAGE_SIZE);
19982+#endif
19983+
19984 __init_begin = .; /* paired with __init_end */
19985- }
19986+ } :init.begin
19987
19988-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
19989+#ifdef CONFIG_SMP
19990 /*
19991 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
19992 * output PHDR, so the next output section - .init.text - should
19993@@ -190,12 +256,27 @@ SECTIONS
19994 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
19995 #endif
19996
19997- INIT_TEXT_SECTION(PAGE_SIZE)
19998-#ifdef CONFIG_X86_64
19999- :init
20000-#endif
20001+ . = ALIGN(PAGE_SIZE);
20002+ init_begin = .;
20003+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20004+ VMLINUX_SYMBOL(_sinittext) = .;
20005+ INIT_TEXT
20006+ VMLINUX_SYMBOL(_einittext) = .;
20007+ . = ALIGN(PAGE_SIZE);
20008+ } :text.init
20009
20010- INIT_DATA_SECTION(16)
20011+ /*
20012+ * .exit.text is discard at runtime, not link time, to deal with
20013+ * references from .altinstructions and .eh_frame
20014+ */
20015+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20016+ EXIT_TEXT
20017+ . = ALIGN(16);
20018+ } :text.exit
20019+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20020+
20021+ . = ALIGN(PAGE_SIZE);
20022+ INIT_DATA_SECTION(16) :init
20023
20024 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
20025 __x86_cpu_dev_start = .;
20026@@ -257,19 +338,12 @@ SECTIONS
20027 }
20028
20029 . = ALIGN(8);
20030- /*
20031- * .exit.text is discard at runtime, not link time, to deal with
20032- * references from .altinstructions and .eh_frame
20033- */
20034- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20035- EXIT_TEXT
20036- }
20037
20038 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20039 EXIT_DATA
20040 }
20041
20042-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20043+#ifndef CONFIG_SMP
20044 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20045 #endif
20046
20047@@ -288,16 +362,10 @@ SECTIONS
20048 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20049 __smp_locks = .;
20050 *(.smp_locks)
20051- . = ALIGN(PAGE_SIZE);
20052 __smp_locks_end = .;
20053+ . = ALIGN(PAGE_SIZE);
20054 }
20055
20056-#ifdef CONFIG_X86_64
20057- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20058- NOSAVE_DATA
20059- }
20060-#endif
20061-
20062 /* BSS */
20063 . = ALIGN(PAGE_SIZE);
20064 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20065@@ -313,6 +381,7 @@ SECTIONS
20066 __brk_base = .;
20067 . += 64 * 1024; /* 64k alignment slop space */
20068 *(.brk_reservation) /* areas brk users have reserved */
20069+ . = ALIGN(HPAGE_SIZE);
20070 __brk_limit = .;
20071 }
20072
20073@@ -339,13 +408,12 @@ SECTIONS
20074 * for the boot processor.
20075 */
20076 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20077-INIT_PER_CPU(gdt_page);
20078 INIT_PER_CPU(irq_stack_union);
20079
20080 /*
20081 * Build-time check on the image size:
20082 */
20083-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20084+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20085 "kernel image bigger than KERNEL_IMAGE_SIZE");
20086
20087 #ifdef CONFIG_SMP
20088diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20089index 5db36ca..2938af9 100644
20090--- a/arch/x86/kernel/vsyscall_64.c
20091+++ b/arch/x86/kernel/vsyscall_64.c
20092@@ -54,15 +54,13 @@
20093 DEFINE_VVAR(int, vgetcpu_mode);
20094 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20095
20096-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20097+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20098
20099 static int __init vsyscall_setup(char *str)
20100 {
20101 if (str) {
20102 if (!strcmp("emulate", str))
20103 vsyscall_mode = EMULATE;
20104- else if (!strcmp("native", str))
20105- vsyscall_mode = NATIVE;
20106 else if (!strcmp("none", str))
20107 vsyscall_mode = NONE;
20108 else
20109@@ -309,8 +307,7 @@ done:
20110 return true;
20111
20112 sigsegv:
20113- force_sig(SIGSEGV, current);
20114- return true;
20115+ do_group_exit(SIGKILL);
20116 }
20117
20118 /*
20119@@ -363,10 +360,7 @@ void __init map_vsyscall(void)
20120 extern char __vvar_page;
20121 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20122
20123- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20124- vsyscall_mode == NATIVE
20125- ? PAGE_KERNEL_VSYSCALL
20126- : PAGE_KERNEL_VVAR);
20127+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20128 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20129 (unsigned long)VSYSCALL_START);
20130
20131diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20132index 9796c2f..f686fbf 100644
20133--- a/arch/x86/kernel/x8664_ksyms_64.c
20134+++ b/arch/x86/kernel/x8664_ksyms_64.c
20135@@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
20136 EXPORT_SYMBOL(copy_user_generic_string);
20137 EXPORT_SYMBOL(copy_user_generic_unrolled);
20138 EXPORT_SYMBOL(__copy_user_nocache);
20139-EXPORT_SYMBOL(_copy_from_user);
20140-EXPORT_SYMBOL(_copy_to_user);
20141
20142 EXPORT_SYMBOL(copy_page);
20143 EXPORT_SYMBOL(clear_page);
20144diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20145index bd18149..2ea0183 100644
20146--- a/arch/x86/kernel/xsave.c
20147+++ b/arch/x86/kernel/xsave.c
20148@@ -129,7 +129,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20149 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20150 return -EINVAL;
20151
20152- err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20153+ err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20154 fx_sw_user->extended_size -
20155 FP_XSTATE_MAGIC2_SIZE));
20156 if (err)
20157@@ -265,7 +265,7 @@ fx_only:
20158 * the other extended state.
20159 */
20160 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20161- return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20162+ return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20163 }
20164
20165 /*
20166@@ -294,7 +294,7 @@ int restore_i387_xstate(void __user *buf)
20167 if (use_xsave())
20168 err = restore_user_xstate(buf);
20169 else
20170- err = fxrstor_checking((__force struct i387_fxsave_struct *)
20171+ err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20172 buf);
20173 if (unlikely(err)) {
20174 /*
20175diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20176index 7df1c6d..9ea7c79 100644
20177--- a/arch/x86/kvm/cpuid.c
20178+++ b/arch/x86/kvm/cpuid.c
20179@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20180 struct kvm_cpuid2 *cpuid,
20181 struct kvm_cpuid_entry2 __user *entries)
20182 {
20183- int r;
20184+ int r, i;
20185
20186 r = -E2BIG;
20187 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20188 goto out;
20189 r = -EFAULT;
20190- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20191- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20192+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20193 goto out;
20194+ for (i = 0; i < cpuid->nent; ++i) {
20195+ struct kvm_cpuid_entry2 cpuid_entry;
20196+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20197+ goto out;
20198+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
20199+ }
20200 vcpu->arch.cpuid_nent = cpuid->nent;
20201 kvm_apic_set_version(vcpu);
20202 kvm_x86_ops->cpuid_update(vcpu);
20203@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20204 struct kvm_cpuid2 *cpuid,
20205 struct kvm_cpuid_entry2 __user *entries)
20206 {
20207- int r;
20208+ int r, i;
20209
20210 r = -E2BIG;
20211 if (cpuid->nent < vcpu->arch.cpuid_nent)
20212 goto out;
20213 r = -EFAULT;
20214- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20215- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20216+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20217 goto out;
20218+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20219+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20220+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20221+ goto out;
20222+ }
20223 return 0;
20224
20225 out:
20226diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20227index f95d242..3b49a90 100644
20228--- a/arch/x86/kvm/emulate.c
20229+++ b/arch/x86/kvm/emulate.c
20230@@ -256,6 +256,7 @@ struct gprefix {
20231
20232 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20233 do { \
20234+ unsigned long _tmp; \
20235 __asm__ __volatile__ ( \
20236 _PRE_EFLAGS("0", "4", "2") \
20237 _op _suffix " %"_x"3,%1; " \
20238@@ -270,8 +271,6 @@ struct gprefix {
20239 /* Raw emulation: instruction has two explicit operands. */
20240 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20241 do { \
20242- unsigned long _tmp; \
20243- \
20244 switch ((ctxt)->dst.bytes) { \
20245 case 2: \
20246 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20247@@ -287,7 +286,6 @@ struct gprefix {
20248
20249 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20250 do { \
20251- unsigned long _tmp; \
20252 switch ((ctxt)->dst.bytes) { \
20253 case 1: \
20254 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20255diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20256index 93c1574..d6097dc 100644
20257--- a/arch/x86/kvm/lapic.c
20258+++ b/arch/x86/kvm/lapic.c
20259@@ -54,7 +54,7 @@
20260 #define APIC_BUS_CYCLE_NS 1
20261
20262 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20263-#define apic_debug(fmt, arg...)
20264+#define apic_debug(fmt, arg...) do {} while (0)
20265
20266 #define APIC_LVT_NUM 6
20267 /* 14 is the version for Xeon and Pentium 8.4.8*/
20268diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20269index 34f9709..8eca2d5 100644
20270--- a/arch/x86/kvm/paging_tmpl.h
20271+++ b/arch/x86/kvm/paging_tmpl.h
20272@@ -197,7 +197,7 @@ retry_walk:
20273 if (unlikely(kvm_is_error_hva(host_addr)))
20274 goto error;
20275
20276- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20277+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20278 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20279 goto error;
20280
20281diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20282index f75af40..285b18f 100644
20283--- a/arch/x86/kvm/svm.c
20284+++ b/arch/x86/kvm/svm.c
20285@@ -3516,7 +3516,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20286 int cpu = raw_smp_processor_id();
20287
20288 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20289+
20290+ pax_open_kernel();
20291 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20292+ pax_close_kernel();
20293+
20294 load_TR_desc();
20295 }
20296
20297@@ -3894,6 +3898,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20298 #endif
20299 #endif
20300
20301+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20302+ __set_fs(current_thread_info()->addr_limit);
20303+#endif
20304+
20305 reload_tss(vcpu);
20306
20307 local_irq_disable();
20308diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20309index 32eb588..19c4fe3 100644
20310--- a/arch/x86/kvm/vmx.c
20311+++ b/arch/x86/kvm/vmx.c
20312@@ -1313,7 +1313,11 @@ static void reload_tss(void)
20313 struct desc_struct *descs;
20314
20315 descs = (void *)gdt->address;
20316+
20317+ pax_open_kernel();
20318 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20319+ pax_close_kernel();
20320+
20321 load_TR_desc();
20322 }
20323
20324@@ -1475,8 +1479,8 @@ static void __vmx_load_host_state(struct vcpu_vmx *vmx)
20325 * The sysexit path does not restore ds/es, so we must set them to
20326 * a reasonable value ourselves.
20327 */
20328- loadsegment(ds, __USER_DS);
20329- loadsegment(es, __USER_DS);
20330+ loadsegment(ds, __KERNEL_DS);
20331+ loadsegment(es, __KERNEL_DS);
20332 #endif
20333 reload_tss();
20334 #ifdef CONFIG_X86_64
20335@@ -2653,8 +2657,11 @@ static __init int hardware_setup(void)
20336 if (!cpu_has_vmx_flexpriority())
20337 flexpriority_enabled = 0;
20338
20339- if (!cpu_has_vmx_tpr_shadow())
20340- kvm_x86_ops->update_cr8_intercept = NULL;
20341+ if (!cpu_has_vmx_tpr_shadow()) {
20342+ pax_open_kernel();
20343+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20344+ pax_close_kernel();
20345+ }
20346
20347 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20348 kvm_disable_largepages();
20349@@ -3680,7 +3687,7 @@ static void vmx_set_constant_host_state(void)
20350 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20351
20352 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20353- vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20354+ vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20355
20356 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20357 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20358@@ -6218,6 +6225,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20359 "jmp .Lkvm_vmx_return \n\t"
20360 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20361 ".Lkvm_vmx_return: "
20362+
20363+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20364+ "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20365+ ".Lkvm_vmx_return2: "
20366+#endif
20367+
20368 /* Save guest registers, load host registers, keep flags */
20369 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20370 "pop %0 \n\t"
20371@@ -6266,6 +6279,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20372 #endif
20373 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20374 [wordsize]"i"(sizeof(ulong))
20375+
20376+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20377+ ,[cs]"i"(__KERNEL_CS)
20378+#endif
20379+
20380 : "cc", "memory"
20381 , R"ax", R"bx", R"di", R"si"
20382 #ifdef CONFIG_X86_64
20383@@ -6294,6 +6312,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20384 }
20385 }
20386
20387+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
20388+
20389+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20390+ loadsegment(fs, __KERNEL_PERCPU);
20391+#endif
20392+
20393+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20394+ __set_fs(current_thread_info()->addr_limit);
20395+#endif
20396+
20397 vmx->loaded_vmcs->launched = 1;
20398
20399 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
20400diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20401index be6d549..b0ba2bf 100644
20402--- a/arch/x86/kvm/x86.c
20403+++ b/arch/x86/kvm/x86.c
20404@@ -1357,8 +1357,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20405 {
20406 struct kvm *kvm = vcpu->kvm;
20407 int lm = is_long_mode(vcpu);
20408- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20409- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20410+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20411+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20412 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20413 : kvm->arch.xen_hvm_config.blob_size_32;
20414 u32 page_num = data & ~PAGE_MASK;
20415@@ -2214,6 +2214,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20416 if (n < msr_list.nmsrs)
20417 goto out;
20418 r = -EFAULT;
20419+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20420+ goto out;
20421 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20422 num_msrs_to_save * sizeof(u32)))
20423 goto out;
20424@@ -2339,7 +2341,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20425 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20426 struct kvm_interrupt *irq)
20427 {
20428- if (irq->irq < 0 || irq->irq >= 256)
20429+ if (irq->irq >= 256)
20430 return -EINVAL;
20431 if (irqchip_in_kernel(vcpu->kvm))
20432 return -ENXIO;
20433@@ -4876,7 +4878,7 @@ static void kvm_set_mmio_spte_mask(void)
20434 kvm_mmu_set_mmio_spte_mask(mask);
20435 }
20436
20437-int kvm_arch_init(void *opaque)
20438+int kvm_arch_init(const void *opaque)
20439 {
20440 int r;
20441 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20442diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20443index 642d880..44e0f3f 100644
20444--- a/arch/x86/lguest/boot.c
20445+++ b/arch/x86/lguest/boot.c
20446@@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20447 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20448 * Launcher to reboot us.
20449 */
20450-static void lguest_restart(char *reason)
20451+static __noreturn void lguest_restart(char *reason)
20452 {
20453 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20454+ BUG();
20455 }
20456
20457 /*G:050
20458diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20459index 00933d5..3a64af9 100644
20460--- a/arch/x86/lib/atomic64_386_32.S
20461+++ b/arch/x86/lib/atomic64_386_32.S
20462@@ -48,6 +48,10 @@ BEGIN(read)
20463 movl (v), %eax
20464 movl 4(v), %edx
20465 RET_ENDP
20466+BEGIN(read_unchecked)
20467+ movl (v), %eax
20468+ movl 4(v), %edx
20469+RET_ENDP
20470 #undef v
20471
20472 #define v %esi
20473@@ -55,6 +59,10 @@ BEGIN(set)
20474 movl %ebx, (v)
20475 movl %ecx, 4(v)
20476 RET_ENDP
20477+BEGIN(set_unchecked)
20478+ movl %ebx, (v)
20479+ movl %ecx, 4(v)
20480+RET_ENDP
20481 #undef v
20482
20483 #define v %esi
20484@@ -70,6 +78,20 @@ RET_ENDP
20485 BEGIN(add)
20486 addl %eax, (v)
20487 adcl %edx, 4(v)
20488+
20489+#ifdef CONFIG_PAX_REFCOUNT
20490+ jno 0f
20491+ subl %eax, (v)
20492+ sbbl %edx, 4(v)
20493+ int $4
20494+0:
20495+ _ASM_EXTABLE(0b, 0b)
20496+#endif
20497+
20498+RET_ENDP
20499+BEGIN(add_unchecked)
20500+ addl %eax, (v)
20501+ adcl %edx, 4(v)
20502 RET_ENDP
20503 #undef v
20504
20505@@ -77,6 +99,24 @@ RET_ENDP
20506 BEGIN(add_return)
20507 addl (v), %eax
20508 adcl 4(v), %edx
20509+
20510+#ifdef CONFIG_PAX_REFCOUNT
20511+ into
20512+1234:
20513+ _ASM_EXTABLE(1234b, 2f)
20514+#endif
20515+
20516+ movl %eax, (v)
20517+ movl %edx, 4(v)
20518+
20519+#ifdef CONFIG_PAX_REFCOUNT
20520+2:
20521+#endif
20522+
20523+RET_ENDP
20524+BEGIN(add_return_unchecked)
20525+ addl (v), %eax
20526+ adcl 4(v), %edx
20527 movl %eax, (v)
20528 movl %edx, 4(v)
20529 RET_ENDP
20530@@ -86,6 +126,20 @@ RET_ENDP
20531 BEGIN(sub)
20532 subl %eax, (v)
20533 sbbl %edx, 4(v)
20534+
20535+#ifdef CONFIG_PAX_REFCOUNT
20536+ jno 0f
20537+ addl %eax, (v)
20538+ adcl %edx, 4(v)
20539+ int $4
20540+0:
20541+ _ASM_EXTABLE(0b, 0b)
20542+#endif
20543+
20544+RET_ENDP
20545+BEGIN(sub_unchecked)
20546+ subl %eax, (v)
20547+ sbbl %edx, 4(v)
20548 RET_ENDP
20549 #undef v
20550
20551@@ -96,6 +150,27 @@ BEGIN(sub_return)
20552 sbbl $0, %edx
20553 addl (v), %eax
20554 adcl 4(v), %edx
20555+
20556+#ifdef CONFIG_PAX_REFCOUNT
20557+ into
20558+1234:
20559+ _ASM_EXTABLE(1234b, 2f)
20560+#endif
20561+
20562+ movl %eax, (v)
20563+ movl %edx, 4(v)
20564+
20565+#ifdef CONFIG_PAX_REFCOUNT
20566+2:
20567+#endif
20568+
20569+RET_ENDP
20570+BEGIN(sub_return_unchecked)
20571+ negl %edx
20572+ negl %eax
20573+ sbbl $0, %edx
20574+ addl (v), %eax
20575+ adcl 4(v), %edx
20576 movl %eax, (v)
20577 movl %edx, 4(v)
20578 RET_ENDP
20579@@ -105,6 +180,20 @@ RET_ENDP
20580 BEGIN(inc)
20581 addl $1, (v)
20582 adcl $0, 4(v)
20583+
20584+#ifdef CONFIG_PAX_REFCOUNT
20585+ jno 0f
20586+ subl $1, (v)
20587+ sbbl $0, 4(v)
20588+ int $4
20589+0:
20590+ _ASM_EXTABLE(0b, 0b)
20591+#endif
20592+
20593+RET_ENDP
20594+BEGIN(inc_unchecked)
20595+ addl $1, (v)
20596+ adcl $0, 4(v)
20597 RET_ENDP
20598 #undef v
20599
20600@@ -114,6 +203,26 @@ BEGIN(inc_return)
20601 movl 4(v), %edx
20602 addl $1, %eax
20603 adcl $0, %edx
20604+
20605+#ifdef CONFIG_PAX_REFCOUNT
20606+ into
20607+1234:
20608+ _ASM_EXTABLE(1234b, 2f)
20609+#endif
20610+
20611+ movl %eax, (v)
20612+ movl %edx, 4(v)
20613+
20614+#ifdef CONFIG_PAX_REFCOUNT
20615+2:
20616+#endif
20617+
20618+RET_ENDP
20619+BEGIN(inc_return_unchecked)
20620+ movl (v), %eax
20621+ movl 4(v), %edx
20622+ addl $1, %eax
20623+ adcl $0, %edx
20624 movl %eax, (v)
20625 movl %edx, 4(v)
20626 RET_ENDP
20627@@ -123,6 +232,20 @@ RET_ENDP
20628 BEGIN(dec)
20629 subl $1, (v)
20630 sbbl $0, 4(v)
20631+
20632+#ifdef CONFIG_PAX_REFCOUNT
20633+ jno 0f
20634+ addl $1, (v)
20635+ adcl $0, 4(v)
20636+ int $4
20637+0:
20638+ _ASM_EXTABLE(0b, 0b)
20639+#endif
20640+
20641+RET_ENDP
20642+BEGIN(dec_unchecked)
20643+ subl $1, (v)
20644+ sbbl $0, 4(v)
20645 RET_ENDP
20646 #undef v
20647
20648@@ -132,6 +255,26 @@ BEGIN(dec_return)
20649 movl 4(v), %edx
20650 subl $1, %eax
20651 sbbl $0, %edx
20652+
20653+#ifdef CONFIG_PAX_REFCOUNT
20654+ into
20655+1234:
20656+ _ASM_EXTABLE(1234b, 2f)
20657+#endif
20658+
20659+ movl %eax, (v)
20660+ movl %edx, 4(v)
20661+
20662+#ifdef CONFIG_PAX_REFCOUNT
20663+2:
20664+#endif
20665+
20666+RET_ENDP
20667+BEGIN(dec_return_unchecked)
20668+ movl (v), %eax
20669+ movl 4(v), %edx
20670+ subl $1, %eax
20671+ sbbl $0, %edx
20672 movl %eax, (v)
20673 movl %edx, 4(v)
20674 RET_ENDP
20675@@ -143,6 +286,13 @@ BEGIN(add_unless)
20676 adcl %edx, %edi
20677 addl (v), %eax
20678 adcl 4(v), %edx
20679+
20680+#ifdef CONFIG_PAX_REFCOUNT
20681+ into
20682+1234:
20683+ _ASM_EXTABLE(1234b, 2f)
20684+#endif
20685+
20686 cmpl %eax, %ecx
20687 je 3f
20688 1:
20689@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20690 1:
20691 addl $1, %eax
20692 adcl $0, %edx
20693+
20694+#ifdef CONFIG_PAX_REFCOUNT
20695+ into
20696+1234:
20697+ _ASM_EXTABLE(1234b, 2f)
20698+#endif
20699+
20700 movl %eax, (v)
20701 movl %edx, 4(v)
20702 movl $1, %eax
20703@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20704 movl 4(v), %edx
20705 subl $1, %eax
20706 sbbl $0, %edx
20707+
20708+#ifdef CONFIG_PAX_REFCOUNT
20709+ into
20710+1234:
20711+ _ASM_EXTABLE(1234b, 1f)
20712+#endif
20713+
20714 js 1f
20715 movl %eax, (v)
20716 movl %edx, 4(v)
20717diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20718index f5cc9eb..51fa319 100644
20719--- a/arch/x86/lib/atomic64_cx8_32.S
20720+++ b/arch/x86/lib/atomic64_cx8_32.S
20721@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20722 CFI_STARTPROC
20723
20724 read64 %ecx
20725+ pax_force_retaddr
20726 ret
20727 CFI_ENDPROC
20728 ENDPROC(atomic64_read_cx8)
20729
20730+ENTRY(atomic64_read_unchecked_cx8)
20731+ CFI_STARTPROC
20732+
20733+ read64 %ecx
20734+ pax_force_retaddr
20735+ ret
20736+ CFI_ENDPROC
20737+ENDPROC(atomic64_read_unchecked_cx8)
20738+
20739 ENTRY(atomic64_set_cx8)
20740 CFI_STARTPROC
20741
20742@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20743 cmpxchg8b (%esi)
20744 jne 1b
20745
20746+ pax_force_retaddr
20747 ret
20748 CFI_ENDPROC
20749 ENDPROC(atomic64_set_cx8)
20750
20751+ENTRY(atomic64_set_unchecked_cx8)
20752+ CFI_STARTPROC
20753+
20754+1:
20755+/* we don't need LOCK_PREFIX since aligned 64-bit writes
20756+ * are atomic on 586 and newer */
20757+ cmpxchg8b (%esi)
20758+ jne 1b
20759+
20760+ pax_force_retaddr
20761+ ret
20762+ CFI_ENDPROC
20763+ENDPROC(atomic64_set_unchecked_cx8)
20764+
20765 ENTRY(atomic64_xchg_cx8)
20766 CFI_STARTPROC
20767
20768@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
20769 cmpxchg8b (%esi)
20770 jne 1b
20771
20772+ pax_force_retaddr
20773 ret
20774 CFI_ENDPROC
20775 ENDPROC(atomic64_xchg_cx8)
20776
20777-.macro addsub_return func ins insc
20778-ENTRY(atomic64_\func\()_return_cx8)
20779+.macro addsub_return func ins insc unchecked=""
20780+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20781 CFI_STARTPROC
20782 SAVE ebp
20783 SAVE ebx
20784@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
20785 movl %edx, %ecx
20786 \ins\()l %esi, %ebx
20787 \insc\()l %edi, %ecx
20788+
20789+.ifb \unchecked
20790+#ifdef CONFIG_PAX_REFCOUNT
20791+ into
20792+2:
20793+ _ASM_EXTABLE(2b, 3f)
20794+#endif
20795+.endif
20796+
20797 LOCK_PREFIX
20798 cmpxchg8b (%ebp)
20799 jne 1b
20800-
20801-10:
20802 movl %ebx, %eax
20803 movl %ecx, %edx
20804+
20805+.ifb \unchecked
20806+#ifdef CONFIG_PAX_REFCOUNT
20807+3:
20808+#endif
20809+.endif
20810+
20811 RESTORE edi
20812 RESTORE esi
20813 RESTORE ebx
20814 RESTORE ebp
20815+ pax_force_retaddr
20816 ret
20817 CFI_ENDPROC
20818-ENDPROC(atomic64_\func\()_return_cx8)
20819+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20820 .endm
20821
20822 addsub_return add add adc
20823 addsub_return sub sub sbb
20824+addsub_return add add adc _unchecked
20825+addsub_return sub sub sbb _unchecked
20826
20827-.macro incdec_return func ins insc
20828-ENTRY(atomic64_\func\()_return_cx8)
20829+.macro incdec_return func ins insc unchecked=""
20830+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20831 CFI_STARTPROC
20832 SAVE ebx
20833
20834@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
20835 movl %edx, %ecx
20836 \ins\()l $1, %ebx
20837 \insc\()l $0, %ecx
20838+
20839+.ifb \unchecked
20840+#ifdef CONFIG_PAX_REFCOUNT
20841+ into
20842+2:
20843+ _ASM_EXTABLE(2b, 3f)
20844+#endif
20845+.endif
20846+
20847 LOCK_PREFIX
20848 cmpxchg8b (%esi)
20849 jne 1b
20850
20851-10:
20852 movl %ebx, %eax
20853 movl %ecx, %edx
20854+
20855+.ifb \unchecked
20856+#ifdef CONFIG_PAX_REFCOUNT
20857+3:
20858+#endif
20859+.endif
20860+
20861 RESTORE ebx
20862+ pax_force_retaddr
20863 ret
20864 CFI_ENDPROC
20865-ENDPROC(atomic64_\func\()_return_cx8)
20866+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20867 .endm
20868
20869 incdec_return inc add adc
20870 incdec_return dec sub sbb
20871+incdec_return inc add adc _unchecked
20872+incdec_return dec sub sbb _unchecked
20873
20874 ENTRY(atomic64_dec_if_positive_cx8)
20875 CFI_STARTPROC
20876@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
20877 movl %edx, %ecx
20878 subl $1, %ebx
20879 sbb $0, %ecx
20880+
20881+#ifdef CONFIG_PAX_REFCOUNT
20882+ into
20883+1234:
20884+ _ASM_EXTABLE(1234b, 2f)
20885+#endif
20886+
20887 js 2f
20888 LOCK_PREFIX
20889 cmpxchg8b (%esi)
20890@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
20891 movl %ebx, %eax
20892 movl %ecx, %edx
20893 RESTORE ebx
20894+ pax_force_retaddr
20895 ret
20896 CFI_ENDPROC
20897 ENDPROC(atomic64_dec_if_positive_cx8)
20898@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
20899 movl %edx, %ecx
20900 addl %ebp, %ebx
20901 adcl %edi, %ecx
20902+
20903+#ifdef CONFIG_PAX_REFCOUNT
20904+ into
20905+1234:
20906+ _ASM_EXTABLE(1234b, 3f)
20907+#endif
20908+
20909 LOCK_PREFIX
20910 cmpxchg8b (%esi)
20911 jne 1b
20912@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
20913 CFI_ADJUST_CFA_OFFSET -8
20914 RESTORE ebx
20915 RESTORE ebp
20916+ pax_force_retaddr
20917 ret
20918 4:
20919 cmpl %edx, 4(%esp)
20920@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
20921 xorl %ecx, %ecx
20922 addl $1, %ebx
20923 adcl %edx, %ecx
20924+
20925+#ifdef CONFIG_PAX_REFCOUNT
20926+ into
20927+1234:
20928+ _ASM_EXTABLE(1234b, 3f)
20929+#endif
20930+
20931 LOCK_PREFIX
20932 cmpxchg8b (%esi)
20933 jne 1b
20934@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
20935 movl $1, %eax
20936 3:
20937 RESTORE ebx
20938+ pax_force_retaddr
20939 ret
20940 CFI_ENDPROC
20941 ENDPROC(atomic64_inc_not_zero_cx8)
20942diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
20943index 2af5df3..62b1a5a 100644
20944--- a/arch/x86/lib/checksum_32.S
20945+++ b/arch/x86/lib/checksum_32.S
20946@@ -29,7 +29,8 @@
20947 #include <asm/dwarf2.h>
20948 #include <asm/errno.h>
20949 #include <asm/asm.h>
20950-
20951+#include <asm/segment.h>
20952+
20953 /*
20954 * computes a partial checksum, e.g. for TCP/UDP fragments
20955 */
20956@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
20957
20958 #define ARGBASE 16
20959 #define FP 12
20960-
20961-ENTRY(csum_partial_copy_generic)
20962+
20963+ENTRY(csum_partial_copy_generic_to_user)
20964 CFI_STARTPROC
20965+
20966+#ifdef CONFIG_PAX_MEMORY_UDEREF
20967+ pushl_cfi %gs
20968+ popl_cfi %es
20969+ jmp csum_partial_copy_generic
20970+#endif
20971+
20972+ENTRY(csum_partial_copy_generic_from_user)
20973+
20974+#ifdef CONFIG_PAX_MEMORY_UDEREF
20975+ pushl_cfi %gs
20976+ popl_cfi %ds
20977+#endif
20978+
20979+ENTRY(csum_partial_copy_generic)
20980 subl $4,%esp
20981 CFI_ADJUST_CFA_OFFSET 4
20982 pushl_cfi %edi
20983@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
20984 jmp 4f
20985 SRC(1: movw (%esi), %bx )
20986 addl $2, %esi
20987-DST( movw %bx, (%edi) )
20988+DST( movw %bx, %es:(%edi) )
20989 addl $2, %edi
20990 addw %bx, %ax
20991 adcl $0, %eax
20992@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
20993 SRC(1: movl (%esi), %ebx )
20994 SRC( movl 4(%esi), %edx )
20995 adcl %ebx, %eax
20996-DST( movl %ebx, (%edi) )
20997+DST( movl %ebx, %es:(%edi) )
20998 adcl %edx, %eax
20999-DST( movl %edx, 4(%edi) )
21000+DST( movl %edx, %es:4(%edi) )
21001
21002 SRC( movl 8(%esi), %ebx )
21003 SRC( movl 12(%esi), %edx )
21004 adcl %ebx, %eax
21005-DST( movl %ebx, 8(%edi) )
21006+DST( movl %ebx, %es:8(%edi) )
21007 adcl %edx, %eax
21008-DST( movl %edx, 12(%edi) )
21009+DST( movl %edx, %es:12(%edi) )
21010
21011 SRC( movl 16(%esi), %ebx )
21012 SRC( movl 20(%esi), %edx )
21013 adcl %ebx, %eax
21014-DST( movl %ebx, 16(%edi) )
21015+DST( movl %ebx, %es:16(%edi) )
21016 adcl %edx, %eax
21017-DST( movl %edx, 20(%edi) )
21018+DST( movl %edx, %es:20(%edi) )
21019
21020 SRC( movl 24(%esi), %ebx )
21021 SRC( movl 28(%esi), %edx )
21022 adcl %ebx, %eax
21023-DST( movl %ebx, 24(%edi) )
21024+DST( movl %ebx, %es:24(%edi) )
21025 adcl %edx, %eax
21026-DST( movl %edx, 28(%edi) )
21027+DST( movl %edx, %es:28(%edi) )
21028
21029 lea 32(%esi), %esi
21030 lea 32(%edi), %edi
21031@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
21032 shrl $2, %edx # This clears CF
21033 SRC(3: movl (%esi), %ebx )
21034 adcl %ebx, %eax
21035-DST( movl %ebx, (%edi) )
21036+DST( movl %ebx, %es:(%edi) )
21037 lea 4(%esi), %esi
21038 lea 4(%edi), %edi
21039 dec %edx
21040@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
21041 jb 5f
21042 SRC( movw (%esi), %cx )
21043 leal 2(%esi), %esi
21044-DST( movw %cx, (%edi) )
21045+DST( movw %cx, %es:(%edi) )
21046 leal 2(%edi), %edi
21047 je 6f
21048 shll $16,%ecx
21049 SRC(5: movb (%esi), %cl )
21050-DST( movb %cl, (%edi) )
21051+DST( movb %cl, %es:(%edi) )
21052 6: addl %ecx, %eax
21053 adcl $0, %eax
21054 7:
21055@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
21056
21057 6001:
21058 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21059- movl $-EFAULT, (%ebx)
21060+ movl $-EFAULT, %ss:(%ebx)
21061
21062 # zero the complete destination - computing the rest
21063 # is too much work
21064@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
21065
21066 6002:
21067 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21068- movl $-EFAULT,(%ebx)
21069+ movl $-EFAULT,%ss:(%ebx)
21070 jmp 5000b
21071
21072 .previous
21073
21074+ pushl_cfi %ss
21075+ popl_cfi %ds
21076+ pushl_cfi %ss
21077+ popl_cfi %es
21078 popl_cfi %ebx
21079 CFI_RESTORE ebx
21080 popl_cfi %esi
21081@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
21082 popl_cfi %ecx # equivalent to addl $4,%esp
21083 ret
21084 CFI_ENDPROC
21085-ENDPROC(csum_partial_copy_generic)
21086+ENDPROC(csum_partial_copy_generic_to_user)
21087
21088 #else
21089
21090 /* Version for PentiumII/PPro */
21091
21092 #define ROUND1(x) \
21093+ nop; nop; nop; \
21094 SRC(movl x(%esi), %ebx ) ; \
21095 addl %ebx, %eax ; \
21096- DST(movl %ebx, x(%edi) ) ;
21097+ DST(movl %ebx, %es:x(%edi)) ;
21098
21099 #define ROUND(x) \
21100+ nop; nop; nop; \
21101 SRC(movl x(%esi), %ebx ) ; \
21102 adcl %ebx, %eax ; \
21103- DST(movl %ebx, x(%edi) ) ;
21104+ DST(movl %ebx, %es:x(%edi)) ;
21105
21106 #define ARGBASE 12
21107-
21108-ENTRY(csum_partial_copy_generic)
21109+
21110+ENTRY(csum_partial_copy_generic_to_user)
21111 CFI_STARTPROC
21112+
21113+#ifdef CONFIG_PAX_MEMORY_UDEREF
21114+ pushl_cfi %gs
21115+ popl_cfi %es
21116+ jmp csum_partial_copy_generic
21117+#endif
21118+
21119+ENTRY(csum_partial_copy_generic_from_user)
21120+
21121+#ifdef CONFIG_PAX_MEMORY_UDEREF
21122+ pushl_cfi %gs
21123+ popl_cfi %ds
21124+#endif
21125+
21126+ENTRY(csum_partial_copy_generic)
21127 pushl_cfi %ebx
21128 CFI_REL_OFFSET ebx, 0
21129 pushl_cfi %edi
21130@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
21131 subl %ebx, %edi
21132 lea -1(%esi),%edx
21133 andl $-32,%edx
21134- lea 3f(%ebx,%ebx), %ebx
21135+ lea 3f(%ebx,%ebx,2), %ebx
21136 testl %esi, %esi
21137 jmp *%ebx
21138 1: addl $64,%esi
21139@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
21140 jb 5f
21141 SRC( movw (%esi), %dx )
21142 leal 2(%esi), %esi
21143-DST( movw %dx, (%edi) )
21144+DST( movw %dx, %es:(%edi) )
21145 leal 2(%edi), %edi
21146 je 6f
21147 shll $16,%edx
21148 5:
21149 SRC( movb (%esi), %dl )
21150-DST( movb %dl, (%edi) )
21151+DST( movb %dl, %es:(%edi) )
21152 6: addl %edx, %eax
21153 adcl $0, %eax
21154 7:
21155 .section .fixup, "ax"
21156 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21157- movl $-EFAULT, (%ebx)
21158+ movl $-EFAULT, %ss:(%ebx)
21159 # zero the complete destination (computing the rest is too much work)
21160 movl ARGBASE+8(%esp),%edi # dst
21161 movl ARGBASE+12(%esp),%ecx # len
21162@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
21163 rep; stosb
21164 jmp 7b
21165 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21166- movl $-EFAULT, (%ebx)
21167+ movl $-EFAULT, %ss:(%ebx)
21168 jmp 7b
21169 .previous
21170
21171+#ifdef CONFIG_PAX_MEMORY_UDEREF
21172+ pushl_cfi %ss
21173+ popl_cfi %ds
21174+ pushl_cfi %ss
21175+ popl_cfi %es
21176+#endif
21177+
21178 popl_cfi %esi
21179 CFI_RESTORE esi
21180 popl_cfi %edi
21181@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
21182 CFI_RESTORE ebx
21183 ret
21184 CFI_ENDPROC
21185-ENDPROC(csum_partial_copy_generic)
21186+ENDPROC(csum_partial_copy_generic_to_user)
21187
21188 #undef ROUND
21189 #undef ROUND1
21190diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21191index f2145cf..cea889d 100644
21192--- a/arch/x86/lib/clear_page_64.S
21193+++ b/arch/x86/lib/clear_page_64.S
21194@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21195 movl $4096/8,%ecx
21196 xorl %eax,%eax
21197 rep stosq
21198+ pax_force_retaddr
21199 ret
21200 CFI_ENDPROC
21201 ENDPROC(clear_page_c)
21202@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21203 movl $4096,%ecx
21204 xorl %eax,%eax
21205 rep stosb
21206+ pax_force_retaddr
21207 ret
21208 CFI_ENDPROC
21209 ENDPROC(clear_page_c_e)
21210@@ -43,6 +45,7 @@ ENTRY(clear_page)
21211 leaq 64(%rdi),%rdi
21212 jnz .Lloop
21213 nop
21214+ pax_force_retaddr
21215 ret
21216 CFI_ENDPROC
21217 .Lclear_page_end:
21218@@ -58,7 +61,7 @@ ENDPROC(clear_page)
21219
21220 #include <asm/cpufeature.h>
21221
21222- .section .altinstr_replacement,"ax"
21223+ .section .altinstr_replacement,"a"
21224 1: .byte 0xeb /* jmp <disp8> */
21225 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21226 2: .byte 0xeb /* jmp <disp8> */
21227diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21228index 1e572c5..2a162cd 100644
21229--- a/arch/x86/lib/cmpxchg16b_emu.S
21230+++ b/arch/x86/lib/cmpxchg16b_emu.S
21231@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21232
21233 popf
21234 mov $1, %al
21235+ pax_force_retaddr
21236 ret
21237
21238 not_same:
21239 popf
21240 xor %al,%al
21241+ pax_force_retaddr
21242 ret
21243
21244 CFI_ENDPROC
21245diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21246index 6b34d04..dccb07f 100644
21247--- a/arch/x86/lib/copy_page_64.S
21248+++ b/arch/x86/lib/copy_page_64.S
21249@@ -9,6 +9,7 @@ copy_page_c:
21250 CFI_STARTPROC
21251 movl $4096/8,%ecx
21252 rep movsq
21253+ pax_force_retaddr
21254 ret
21255 CFI_ENDPROC
21256 ENDPROC(copy_page_c)
21257@@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21258
21259 ENTRY(copy_page)
21260 CFI_STARTPROC
21261- subq $2*8,%rsp
21262- CFI_ADJUST_CFA_OFFSET 2*8
21263+ subq $3*8,%rsp
21264+ CFI_ADJUST_CFA_OFFSET 3*8
21265 movq %rbx,(%rsp)
21266 CFI_REL_OFFSET rbx, 0
21267 movq %r12,1*8(%rsp)
21268 CFI_REL_OFFSET r12, 1*8
21269+ movq %r13,2*8(%rsp)
21270+ CFI_REL_OFFSET r13, 2*8
21271
21272 movl $(4096/64)-5,%ecx
21273 .p2align 4
21274@@ -37,7 +40,7 @@ ENTRY(copy_page)
21275 movq 16 (%rsi), %rdx
21276 movq 24 (%rsi), %r8
21277 movq 32 (%rsi), %r9
21278- movq 40 (%rsi), %r10
21279+ movq 40 (%rsi), %r13
21280 movq 48 (%rsi), %r11
21281 movq 56 (%rsi), %r12
21282
21283@@ -48,7 +51,7 @@ ENTRY(copy_page)
21284 movq %rdx, 16 (%rdi)
21285 movq %r8, 24 (%rdi)
21286 movq %r9, 32 (%rdi)
21287- movq %r10, 40 (%rdi)
21288+ movq %r13, 40 (%rdi)
21289 movq %r11, 48 (%rdi)
21290 movq %r12, 56 (%rdi)
21291
21292@@ -67,7 +70,7 @@ ENTRY(copy_page)
21293 movq 16 (%rsi), %rdx
21294 movq 24 (%rsi), %r8
21295 movq 32 (%rsi), %r9
21296- movq 40 (%rsi), %r10
21297+ movq 40 (%rsi), %r13
21298 movq 48 (%rsi), %r11
21299 movq 56 (%rsi), %r12
21300
21301@@ -76,7 +79,7 @@ ENTRY(copy_page)
21302 movq %rdx, 16 (%rdi)
21303 movq %r8, 24 (%rdi)
21304 movq %r9, 32 (%rdi)
21305- movq %r10, 40 (%rdi)
21306+ movq %r13, 40 (%rdi)
21307 movq %r11, 48 (%rdi)
21308 movq %r12, 56 (%rdi)
21309
21310@@ -89,8 +92,11 @@ ENTRY(copy_page)
21311 CFI_RESTORE rbx
21312 movq 1*8(%rsp),%r12
21313 CFI_RESTORE r12
21314- addq $2*8,%rsp
21315- CFI_ADJUST_CFA_OFFSET -2*8
21316+ movq 2*8(%rsp),%r13
21317+ CFI_RESTORE r13
21318+ addq $3*8,%rsp
21319+ CFI_ADJUST_CFA_OFFSET -3*8
21320+ pax_force_retaddr
21321 ret
21322 .Lcopy_page_end:
21323 CFI_ENDPROC
21324@@ -101,7 +107,7 @@ ENDPROC(copy_page)
21325
21326 #include <asm/cpufeature.h>
21327
21328- .section .altinstr_replacement,"ax"
21329+ .section .altinstr_replacement,"a"
21330 1: .byte 0xeb /* jmp <disp8> */
21331 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21332 2:
21333diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21334index 5b2995f..78e7644 100644
21335--- a/arch/x86/lib/copy_user_64.S
21336+++ b/arch/x86/lib/copy_user_64.S
21337@@ -17,6 +17,7 @@
21338 #include <asm/cpufeature.h>
21339 #include <asm/alternative-asm.h>
21340 #include <asm/asm.h>
21341+#include <asm/pgtable.h>
21342
21343 /*
21344 * By placing feature2 after feature1 in altinstructions section, we logically
21345@@ -30,7 +31,7 @@
21346 .byte 0xe9 /* 32bit jump */
21347 .long \orig-1f /* by default jump to orig */
21348 1:
21349- .section .altinstr_replacement,"ax"
21350+ .section .altinstr_replacement,"a"
21351 2: .byte 0xe9 /* near jump with 32bit immediate */
21352 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21353 3: .byte 0xe9 /* near jump with 32bit immediate */
21354@@ -69,47 +70,20 @@
21355 #endif
21356 .endm
21357
21358-/* Standard copy_to_user with segment limit checking */
21359-ENTRY(_copy_to_user)
21360- CFI_STARTPROC
21361- GET_THREAD_INFO(%rax)
21362- movq %rdi,%rcx
21363- addq %rdx,%rcx
21364- jc bad_to_user
21365- cmpq TI_addr_limit(%rax),%rcx
21366- ja bad_to_user
21367- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21368- copy_user_generic_unrolled,copy_user_generic_string, \
21369- copy_user_enhanced_fast_string
21370- CFI_ENDPROC
21371-ENDPROC(_copy_to_user)
21372-
21373-/* Standard copy_from_user with segment limit checking */
21374-ENTRY(_copy_from_user)
21375- CFI_STARTPROC
21376- GET_THREAD_INFO(%rax)
21377- movq %rsi,%rcx
21378- addq %rdx,%rcx
21379- jc bad_from_user
21380- cmpq TI_addr_limit(%rax),%rcx
21381- ja bad_from_user
21382- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21383- copy_user_generic_unrolled,copy_user_generic_string, \
21384- copy_user_enhanced_fast_string
21385- CFI_ENDPROC
21386-ENDPROC(_copy_from_user)
21387-
21388 .section .fixup,"ax"
21389 /* must zero dest */
21390 ENTRY(bad_from_user)
21391 bad_from_user:
21392 CFI_STARTPROC
21393+ testl %edx,%edx
21394+ js bad_to_user
21395 movl %edx,%ecx
21396 xorl %eax,%eax
21397 rep
21398 stosb
21399 bad_to_user:
21400 movl %edx,%eax
21401+ pax_force_retaddr
21402 ret
21403 CFI_ENDPROC
21404 ENDPROC(bad_from_user)
21405@@ -139,19 +113,19 @@ ENTRY(copy_user_generic_unrolled)
21406 jz 17f
21407 1: movq (%rsi),%r8
21408 2: movq 1*8(%rsi),%r9
21409-3: movq 2*8(%rsi),%r10
21410+3: movq 2*8(%rsi),%rax
21411 4: movq 3*8(%rsi),%r11
21412 5: movq %r8,(%rdi)
21413 6: movq %r9,1*8(%rdi)
21414-7: movq %r10,2*8(%rdi)
21415+7: movq %rax,2*8(%rdi)
21416 8: movq %r11,3*8(%rdi)
21417 9: movq 4*8(%rsi),%r8
21418 10: movq 5*8(%rsi),%r9
21419-11: movq 6*8(%rsi),%r10
21420+11: movq 6*8(%rsi),%rax
21421 12: movq 7*8(%rsi),%r11
21422 13: movq %r8,4*8(%rdi)
21423 14: movq %r9,5*8(%rdi)
21424-15: movq %r10,6*8(%rdi)
21425+15: movq %rax,6*8(%rdi)
21426 16: movq %r11,7*8(%rdi)
21427 leaq 64(%rsi),%rsi
21428 leaq 64(%rdi),%rdi
21429@@ -177,6 +151,7 @@ ENTRY(copy_user_generic_unrolled)
21430 decl %ecx
21431 jnz 21b
21432 23: xor %eax,%eax
21433+ pax_force_retaddr
21434 ret
21435
21436 .section .fixup,"ax"
21437@@ -246,6 +221,7 @@ ENTRY(copy_user_generic_string)
21438 3: rep
21439 movsb
21440 4: xorl %eax,%eax
21441+ pax_force_retaddr
21442 ret
21443
21444 .section .fixup,"ax"
21445@@ -279,6 +255,7 @@ ENTRY(copy_user_enhanced_fast_string)
21446 1: rep
21447 movsb
21448 2: xorl %eax,%eax
21449+ pax_force_retaddr
21450 ret
21451
21452 .section .fixup,"ax"
21453diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21454index cacddc7..09d49e4 100644
21455--- a/arch/x86/lib/copy_user_nocache_64.S
21456+++ b/arch/x86/lib/copy_user_nocache_64.S
21457@@ -8,6 +8,7 @@
21458
21459 #include <linux/linkage.h>
21460 #include <asm/dwarf2.h>
21461+#include <asm/alternative-asm.h>
21462
21463 #define FIX_ALIGNMENT 1
21464
21465@@ -15,6 +16,7 @@
21466 #include <asm/asm-offsets.h>
21467 #include <asm/thread_info.h>
21468 #include <asm/asm.h>
21469+#include <asm/pgtable.h>
21470
21471 .macro ALIGN_DESTINATION
21472 #ifdef FIX_ALIGNMENT
21473@@ -48,6 +50,15 @@
21474 */
21475 ENTRY(__copy_user_nocache)
21476 CFI_STARTPROC
21477+
21478+#ifdef CONFIG_PAX_MEMORY_UDEREF
21479+ mov $PAX_USER_SHADOW_BASE,%rcx
21480+ cmp %rcx,%rsi
21481+ jae 1f
21482+ add %rcx,%rsi
21483+1:
21484+#endif
21485+
21486 cmpl $8,%edx
21487 jb 20f /* less then 8 bytes, go to byte copy loop */
21488 ALIGN_DESTINATION
21489@@ -57,19 +68,19 @@ ENTRY(__copy_user_nocache)
21490 jz 17f
21491 1: movq (%rsi),%r8
21492 2: movq 1*8(%rsi),%r9
21493-3: movq 2*8(%rsi),%r10
21494+3: movq 2*8(%rsi),%rax
21495 4: movq 3*8(%rsi),%r11
21496 5: movnti %r8,(%rdi)
21497 6: movnti %r9,1*8(%rdi)
21498-7: movnti %r10,2*8(%rdi)
21499+7: movnti %rax,2*8(%rdi)
21500 8: movnti %r11,3*8(%rdi)
21501 9: movq 4*8(%rsi),%r8
21502 10: movq 5*8(%rsi),%r9
21503-11: movq 6*8(%rsi),%r10
21504+11: movq 6*8(%rsi),%rax
21505 12: movq 7*8(%rsi),%r11
21506 13: movnti %r8,4*8(%rdi)
21507 14: movnti %r9,5*8(%rdi)
21508-15: movnti %r10,6*8(%rdi)
21509+15: movnti %rax,6*8(%rdi)
21510 16: movnti %r11,7*8(%rdi)
21511 leaq 64(%rsi),%rsi
21512 leaq 64(%rdi),%rdi
21513@@ -96,6 +107,7 @@ ENTRY(__copy_user_nocache)
21514 jnz 21b
21515 23: xorl %eax,%eax
21516 sfence
21517+ pax_force_retaddr
21518 ret
21519
21520 .section .fixup,"ax"
21521diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21522index 2419d5f..953ee51 100644
21523--- a/arch/x86/lib/csum-copy_64.S
21524+++ b/arch/x86/lib/csum-copy_64.S
21525@@ -9,6 +9,7 @@
21526 #include <asm/dwarf2.h>
21527 #include <asm/errno.h>
21528 #include <asm/asm.h>
21529+#include <asm/alternative-asm.h>
21530
21531 /*
21532 * Checksum copy with exception handling.
21533@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
21534 CFI_RESTORE rbp
21535 addq $7*8, %rsp
21536 CFI_ADJUST_CFA_OFFSET -7*8
21537+ pax_force_retaddr 0, 1
21538 ret
21539 CFI_RESTORE_STATE
21540
21541diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21542index 25b7ae8..3b52ccd 100644
21543--- a/arch/x86/lib/csum-wrappers_64.c
21544+++ b/arch/x86/lib/csum-wrappers_64.c
21545@@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21546 len -= 2;
21547 }
21548 }
21549- isum = csum_partial_copy_generic((__force const void *)src,
21550+
21551+#ifdef CONFIG_PAX_MEMORY_UDEREF
21552+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21553+ src += PAX_USER_SHADOW_BASE;
21554+#endif
21555+
21556+ isum = csum_partial_copy_generic((const void __force_kernel *)src,
21557 dst, len, isum, errp, NULL);
21558 if (unlikely(*errp))
21559 goto out_err;
21560@@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21561 }
21562
21563 *errp = 0;
21564- return csum_partial_copy_generic(src, (void __force *)dst,
21565+
21566+#ifdef CONFIG_PAX_MEMORY_UDEREF
21567+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21568+ dst += PAX_USER_SHADOW_BASE;
21569+#endif
21570+
21571+ return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21572 len, isum, NULL, errp);
21573 }
21574 EXPORT_SYMBOL(csum_partial_copy_to_user);
21575diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21576index b33b1fb..219f389 100644
21577--- a/arch/x86/lib/getuser.S
21578+++ b/arch/x86/lib/getuser.S
21579@@ -33,15 +33,38 @@
21580 #include <asm/asm-offsets.h>
21581 #include <asm/thread_info.h>
21582 #include <asm/asm.h>
21583+#include <asm/segment.h>
21584+#include <asm/pgtable.h>
21585+#include <asm/alternative-asm.h>
21586+
21587+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21588+#define __copyuser_seg gs;
21589+#else
21590+#define __copyuser_seg
21591+#endif
21592
21593 .text
21594 ENTRY(__get_user_1)
21595 CFI_STARTPROC
21596+
21597+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21598 GET_THREAD_INFO(%_ASM_DX)
21599 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21600 jae bad_get_user
21601-1: movzb (%_ASM_AX),%edx
21602+
21603+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21604+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21605+ cmp %_ASM_DX,%_ASM_AX
21606+ jae 1234f
21607+ add %_ASM_DX,%_ASM_AX
21608+1234:
21609+#endif
21610+
21611+#endif
21612+
21613+1: __copyuser_seg movzb (%_ASM_AX),%edx
21614 xor %eax,%eax
21615+ pax_force_retaddr
21616 ret
21617 CFI_ENDPROC
21618 ENDPROC(__get_user_1)
21619@@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21620 ENTRY(__get_user_2)
21621 CFI_STARTPROC
21622 add $1,%_ASM_AX
21623+
21624+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21625 jc bad_get_user
21626 GET_THREAD_INFO(%_ASM_DX)
21627 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21628 jae bad_get_user
21629-2: movzwl -1(%_ASM_AX),%edx
21630+
21631+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21632+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21633+ cmp %_ASM_DX,%_ASM_AX
21634+ jae 1234f
21635+ add %_ASM_DX,%_ASM_AX
21636+1234:
21637+#endif
21638+
21639+#endif
21640+
21641+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21642 xor %eax,%eax
21643+ pax_force_retaddr
21644 ret
21645 CFI_ENDPROC
21646 ENDPROC(__get_user_2)
21647@@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21648 ENTRY(__get_user_4)
21649 CFI_STARTPROC
21650 add $3,%_ASM_AX
21651+
21652+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21653 jc bad_get_user
21654 GET_THREAD_INFO(%_ASM_DX)
21655 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21656 jae bad_get_user
21657-3: mov -3(%_ASM_AX),%edx
21658+
21659+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21660+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21661+ cmp %_ASM_DX,%_ASM_AX
21662+ jae 1234f
21663+ add %_ASM_DX,%_ASM_AX
21664+1234:
21665+#endif
21666+
21667+#endif
21668+
21669+3: __copyuser_seg mov -3(%_ASM_AX),%edx
21670 xor %eax,%eax
21671+ pax_force_retaddr
21672 ret
21673 CFI_ENDPROC
21674 ENDPROC(__get_user_4)
21675@@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21676 GET_THREAD_INFO(%_ASM_DX)
21677 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21678 jae bad_get_user
21679+
21680+#ifdef CONFIG_PAX_MEMORY_UDEREF
21681+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21682+ cmp %_ASM_DX,%_ASM_AX
21683+ jae 1234f
21684+ add %_ASM_DX,%_ASM_AX
21685+1234:
21686+#endif
21687+
21688 4: movq -7(%_ASM_AX),%_ASM_DX
21689 xor %eax,%eax
21690+ pax_force_retaddr
21691 ret
21692 CFI_ENDPROC
21693 ENDPROC(__get_user_8)
21694@@ -91,6 +152,7 @@ bad_get_user:
21695 CFI_STARTPROC
21696 xor %edx,%edx
21697 mov $(-EFAULT),%_ASM_AX
21698+ pax_force_retaddr
21699 ret
21700 CFI_ENDPROC
21701 END(bad_get_user)
21702diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21703index b1e6c4b..21ae8fc 100644
21704--- a/arch/x86/lib/insn.c
21705+++ b/arch/x86/lib/insn.c
21706@@ -21,6 +21,11 @@
21707 #include <linux/string.h>
21708 #include <asm/inat.h>
21709 #include <asm/insn.h>
21710+#ifdef __KERNEL__
21711+#include <asm/pgtable_types.h>
21712+#else
21713+#define ktla_ktva(addr) addr
21714+#endif
21715
21716 /* Verify next sizeof(t) bytes can be on the same instruction */
21717 #define validate_next(t, insn, n) \
21718@@ -49,8 +54,8 @@
21719 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21720 {
21721 memset(insn, 0, sizeof(*insn));
21722- insn->kaddr = kaddr;
21723- insn->next_byte = kaddr;
21724+ insn->kaddr = ktla_ktva(kaddr);
21725+ insn->next_byte = ktla_ktva(kaddr);
21726 insn->x86_64 = x86_64 ? 1 : 0;
21727 insn->opnd_bytes = 4;
21728 if (x86_64)
21729diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21730index 05a95e7..326f2fa 100644
21731--- a/arch/x86/lib/iomap_copy_64.S
21732+++ b/arch/x86/lib/iomap_copy_64.S
21733@@ -17,6 +17,7 @@
21734
21735 #include <linux/linkage.h>
21736 #include <asm/dwarf2.h>
21737+#include <asm/alternative-asm.h>
21738
21739 /*
21740 * override generic version in lib/iomap_copy.c
21741@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21742 CFI_STARTPROC
21743 movl %edx,%ecx
21744 rep movsd
21745+ pax_force_retaddr
21746 ret
21747 CFI_ENDPROC
21748 ENDPROC(__iowrite32_copy)
21749diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21750index 1c273be..da9cc0e 100644
21751--- a/arch/x86/lib/memcpy_64.S
21752+++ b/arch/x86/lib/memcpy_64.S
21753@@ -33,6 +33,7 @@
21754 rep movsq
21755 movl %edx, %ecx
21756 rep movsb
21757+ pax_force_retaddr
21758 ret
21759 .Lmemcpy_e:
21760 .previous
21761@@ -49,6 +50,7 @@
21762 movq %rdi, %rax
21763 movq %rdx, %rcx
21764 rep movsb
21765+ pax_force_retaddr
21766 ret
21767 .Lmemcpy_e_e:
21768 .previous
21769@@ -76,13 +78,13 @@ ENTRY(memcpy)
21770 */
21771 movq 0*8(%rsi), %r8
21772 movq 1*8(%rsi), %r9
21773- movq 2*8(%rsi), %r10
21774+ movq 2*8(%rsi), %rcx
21775 movq 3*8(%rsi), %r11
21776 leaq 4*8(%rsi), %rsi
21777
21778 movq %r8, 0*8(%rdi)
21779 movq %r9, 1*8(%rdi)
21780- movq %r10, 2*8(%rdi)
21781+ movq %rcx, 2*8(%rdi)
21782 movq %r11, 3*8(%rdi)
21783 leaq 4*8(%rdi), %rdi
21784 jae .Lcopy_forward_loop
21785@@ -105,12 +107,12 @@ ENTRY(memcpy)
21786 subq $0x20, %rdx
21787 movq -1*8(%rsi), %r8
21788 movq -2*8(%rsi), %r9
21789- movq -3*8(%rsi), %r10
21790+ movq -3*8(%rsi), %rcx
21791 movq -4*8(%rsi), %r11
21792 leaq -4*8(%rsi), %rsi
21793 movq %r8, -1*8(%rdi)
21794 movq %r9, -2*8(%rdi)
21795- movq %r10, -3*8(%rdi)
21796+ movq %rcx, -3*8(%rdi)
21797 movq %r11, -4*8(%rdi)
21798 leaq -4*8(%rdi), %rdi
21799 jae .Lcopy_backward_loop
21800@@ -130,12 +132,13 @@ ENTRY(memcpy)
21801 */
21802 movq 0*8(%rsi), %r8
21803 movq 1*8(%rsi), %r9
21804- movq -2*8(%rsi, %rdx), %r10
21805+ movq -2*8(%rsi, %rdx), %rcx
21806 movq -1*8(%rsi, %rdx), %r11
21807 movq %r8, 0*8(%rdi)
21808 movq %r9, 1*8(%rdi)
21809- movq %r10, -2*8(%rdi, %rdx)
21810+ movq %rcx, -2*8(%rdi, %rdx)
21811 movq %r11, -1*8(%rdi, %rdx)
21812+ pax_force_retaddr
21813 retq
21814 .p2align 4
21815 .Lless_16bytes:
21816@@ -148,6 +151,7 @@ ENTRY(memcpy)
21817 movq -1*8(%rsi, %rdx), %r9
21818 movq %r8, 0*8(%rdi)
21819 movq %r9, -1*8(%rdi, %rdx)
21820+ pax_force_retaddr
21821 retq
21822 .p2align 4
21823 .Lless_8bytes:
21824@@ -161,6 +165,7 @@ ENTRY(memcpy)
21825 movl -4(%rsi, %rdx), %r8d
21826 movl %ecx, (%rdi)
21827 movl %r8d, -4(%rdi, %rdx)
21828+ pax_force_retaddr
21829 retq
21830 .p2align 4
21831 .Lless_3bytes:
21832@@ -179,6 +184,7 @@ ENTRY(memcpy)
21833 movb %cl, (%rdi)
21834
21835 .Lend:
21836+ pax_force_retaddr
21837 retq
21838 CFI_ENDPROC
21839 ENDPROC(memcpy)
21840diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
21841index ee16461..c39c199 100644
21842--- a/arch/x86/lib/memmove_64.S
21843+++ b/arch/x86/lib/memmove_64.S
21844@@ -61,13 +61,13 @@ ENTRY(memmove)
21845 5:
21846 sub $0x20, %rdx
21847 movq 0*8(%rsi), %r11
21848- movq 1*8(%rsi), %r10
21849+ movq 1*8(%rsi), %rcx
21850 movq 2*8(%rsi), %r9
21851 movq 3*8(%rsi), %r8
21852 leaq 4*8(%rsi), %rsi
21853
21854 movq %r11, 0*8(%rdi)
21855- movq %r10, 1*8(%rdi)
21856+ movq %rcx, 1*8(%rdi)
21857 movq %r9, 2*8(%rdi)
21858 movq %r8, 3*8(%rdi)
21859 leaq 4*8(%rdi), %rdi
21860@@ -81,10 +81,10 @@ ENTRY(memmove)
21861 4:
21862 movq %rdx, %rcx
21863 movq -8(%rsi, %rdx), %r11
21864- lea -8(%rdi, %rdx), %r10
21865+ lea -8(%rdi, %rdx), %r9
21866 shrq $3, %rcx
21867 rep movsq
21868- movq %r11, (%r10)
21869+ movq %r11, (%r9)
21870 jmp 13f
21871 .Lmemmove_end_forward:
21872
21873@@ -95,14 +95,14 @@ ENTRY(memmove)
21874 7:
21875 movq %rdx, %rcx
21876 movq (%rsi), %r11
21877- movq %rdi, %r10
21878+ movq %rdi, %r9
21879 leaq -8(%rsi, %rdx), %rsi
21880 leaq -8(%rdi, %rdx), %rdi
21881 shrq $3, %rcx
21882 std
21883 rep movsq
21884 cld
21885- movq %r11, (%r10)
21886+ movq %r11, (%r9)
21887 jmp 13f
21888
21889 /*
21890@@ -127,13 +127,13 @@ ENTRY(memmove)
21891 8:
21892 subq $0x20, %rdx
21893 movq -1*8(%rsi), %r11
21894- movq -2*8(%rsi), %r10
21895+ movq -2*8(%rsi), %rcx
21896 movq -3*8(%rsi), %r9
21897 movq -4*8(%rsi), %r8
21898 leaq -4*8(%rsi), %rsi
21899
21900 movq %r11, -1*8(%rdi)
21901- movq %r10, -2*8(%rdi)
21902+ movq %rcx, -2*8(%rdi)
21903 movq %r9, -3*8(%rdi)
21904 movq %r8, -4*8(%rdi)
21905 leaq -4*8(%rdi), %rdi
21906@@ -151,11 +151,11 @@ ENTRY(memmove)
21907 * Move data from 16 bytes to 31 bytes.
21908 */
21909 movq 0*8(%rsi), %r11
21910- movq 1*8(%rsi), %r10
21911+ movq 1*8(%rsi), %rcx
21912 movq -2*8(%rsi, %rdx), %r9
21913 movq -1*8(%rsi, %rdx), %r8
21914 movq %r11, 0*8(%rdi)
21915- movq %r10, 1*8(%rdi)
21916+ movq %rcx, 1*8(%rdi)
21917 movq %r9, -2*8(%rdi, %rdx)
21918 movq %r8, -1*8(%rdi, %rdx)
21919 jmp 13f
21920@@ -167,9 +167,9 @@ ENTRY(memmove)
21921 * Move data from 8 bytes to 15 bytes.
21922 */
21923 movq 0*8(%rsi), %r11
21924- movq -1*8(%rsi, %rdx), %r10
21925+ movq -1*8(%rsi, %rdx), %r9
21926 movq %r11, 0*8(%rdi)
21927- movq %r10, -1*8(%rdi, %rdx)
21928+ movq %r9, -1*8(%rdi, %rdx)
21929 jmp 13f
21930 10:
21931 cmpq $4, %rdx
21932@@ -178,9 +178,9 @@ ENTRY(memmove)
21933 * Move data from 4 bytes to 7 bytes.
21934 */
21935 movl (%rsi), %r11d
21936- movl -4(%rsi, %rdx), %r10d
21937+ movl -4(%rsi, %rdx), %r9d
21938 movl %r11d, (%rdi)
21939- movl %r10d, -4(%rdi, %rdx)
21940+ movl %r9d, -4(%rdi, %rdx)
21941 jmp 13f
21942 11:
21943 cmp $2, %rdx
21944@@ -189,9 +189,9 @@ ENTRY(memmove)
21945 * Move data from 2 bytes to 3 bytes.
21946 */
21947 movw (%rsi), %r11w
21948- movw -2(%rsi, %rdx), %r10w
21949+ movw -2(%rsi, %rdx), %r9w
21950 movw %r11w, (%rdi)
21951- movw %r10w, -2(%rdi, %rdx)
21952+ movw %r9w, -2(%rdi, %rdx)
21953 jmp 13f
21954 12:
21955 cmp $1, %rdx
21956@@ -202,6 +202,7 @@ ENTRY(memmove)
21957 movb (%rsi), %r11b
21958 movb %r11b, (%rdi)
21959 13:
21960+ pax_force_retaddr
21961 retq
21962 CFI_ENDPROC
21963
21964@@ -210,6 +211,7 @@ ENTRY(memmove)
21965 /* Forward moving data. */
21966 movq %rdx, %rcx
21967 rep movsb
21968+ pax_force_retaddr
21969 retq
21970 .Lmemmove_end_forward_efs:
21971 .previous
21972diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
21973index 2dcb380..963660a 100644
21974--- a/arch/x86/lib/memset_64.S
21975+++ b/arch/x86/lib/memset_64.S
21976@@ -30,6 +30,7 @@
21977 movl %edx,%ecx
21978 rep stosb
21979 movq %r9,%rax
21980+ pax_force_retaddr
21981 ret
21982 .Lmemset_e:
21983 .previous
21984@@ -52,6 +53,7 @@
21985 movq %rdx,%rcx
21986 rep stosb
21987 movq %r9,%rax
21988+ pax_force_retaddr
21989 ret
21990 .Lmemset_e_e:
21991 .previous
21992@@ -59,7 +61,7 @@
21993 ENTRY(memset)
21994 ENTRY(__memset)
21995 CFI_STARTPROC
21996- movq %rdi,%r10
21997+ movq %rdi,%r11
21998
21999 /* expand byte value */
22000 movzbl %sil,%ecx
22001@@ -117,7 +119,8 @@ ENTRY(__memset)
22002 jnz .Lloop_1
22003
22004 .Lende:
22005- movq %r10,%rax
22006+ movq %r11,%rax
22007+ pax_force_retaddr
22008 ret
22009
22010 CFI_RESTORE_STATE
22011diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22012index c9f2d9b..e7fd2c0 100644
22013--- a/arch/x86/lib/mmx_32.c
22014+++ b/arch/x86/lib/mmx_32.c
22015@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22016 {
22017 void *p;
22018 int i;
22019+ unsigned long cr0;
22020
22021 if (unlikely(in_interrupt()))
22022 return __memcpy(to, from, len);
22023@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22024 kernel_fpu_begin();
22025
22026 __asm__ __volatile__ (
22027- "1: prefetch (%0)\n" /* This set is 28 bytes */
22028- " prefetch 64(%0)\n"
22029- " prefetch 128(%0)\n"
22030- " prefetch 192(%0)\n"
22031- " prefetch 256(%0)\n"
22032+ "1: prefetch (%1)\n" /* This set is 28 bytes */
22033+ " prefetch 64(%1)\n"
22034+ " prefetch 128(%1)\n"
22035+ " prefetch 192(%1)\n"
22036+ " prefetch 256(%1)\n"
22037 "2: \n"
22038 ".section .fixup, \"ax\"\n"
22039- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22040+ "3: \n"
22041+
22042+#ifdef CONFIG_PAX_KERNEXEC
22043+ " movl %%cr0, %0\n"
22044+ " movl %0, %%eax\n"
22045+ " andl $0xFFFEFFFF, %%eax\n"
22046+ " movl %%eax, %%cr0\n"
22047+#endif
22048+
22049+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22050+
22051+#ifdef CONFIG_PAX_KERNEXEC
22052+ " movl %0, %%cr0\n"
22053+#endif
22054+
22055 " jmp 2b\n"
22056 ".previous\n"
22057 _ASM_EXTABLE(1b, 3b)
22058- : : "r" (from));
22059+ : "=&r" (cr0) : "r" (from) : "ax");
22060
22061 for ( ; i > 5; i--) {
22062 __asm__ __volatile__ (
22063- "1: prefetch 320(%0)\n"
22064- "2: movq (%0), %%mm0\n"
22065- " movq 8(%0), %%mm1\n"
22066- " movq 16(%0), %%mm2\n"
22067- " movq 24(%0), %%mm3\n"
22068- " movq %%mm0, (%1)\n"
22069- " movq %%mm1, 8(%1)\n"
22070- " movq %%mm2, 16(%1)\n"
22071- " movq %%mm3, 24(%1)\n"
22072- " movq 32(%0), %%mm0\n"
22073- " movq 40(%0), %%mm1\n"
22074- " movq 48(%0), %%mm2\n"
22075- " movq 56(%0), %%mm3\n"
22076- " movq %%mm0, 32(%1)\n"
22077- " movq %%mm1, 40(%1)\n"
22078- " movq %%mm2, 48(%1)\n"
22079- " movq %%mm3, 56(%1)\n"
22080+ "1: prefetch 320(%1)\n"
22081+ "2: movq (%1), %%mm0\n"
22082+ " movq 8(%1), %%mm1\n"
22083+ " movq 16(%1), %%mm2\n"
22084+ " movq 24(%1), %%mm3\n"
22085+ " movq %%mm0, (%2)\n"
22086+ " movq %%mm1, 8(%2)\n"
22087+ " movq %%mm2, 16(%2)\n"
22088+ " movq %%mm3, 24(%2)\n"
22089+ " movq 32(%1), %%mm0\n"
22090+ " movq 40(%1), %%mm1\n"
22091+ " movq 48(%1), %%mm2\n"
22092+ " movq 56(%1), %%mm3\n"
22093+ " movq %%mm0, 32(%2)\n"
22094+ " movq %%mm1, 40(%2)\n"
22095+ " movq %%mm2, 48(%2)\n"
22096+ " movq %%mm3, 56(%2)\n"
22097 ".section .fixup, \"ax\"\n"
22098- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22099+ "3:\n"
22100+
22101+#ifdef CONFIG_PAX_KERNEXEC
22102+ " movl %%cr0, %0\n"
22103+ " movl %0, %%eax\n"
22104+ " andl $0xFFFEFFFF, %%eax\n"
22105+ " movl %%eax, %%cr0\n"
22106+#endif
22107+
22108+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22109+
22110+#ifdef CONFIG_PAX_KERNEXEC
22111+ " movl %0, %%cr0\n"
22112+#endif
22113+
22114 " jmp 2b\n"
22115 ".previous\n"
22116 _ASM_EXTABLE(1b, 3b)
22117- : : "r" (from), "r" (to) : "memory");
22118+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22119
22120 from += 64;
22121 to += 64;
22122@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22123 static void fast_copy_page(void *to, void *from)
22124 {
22125 int i;
22126+ unsigned long cr0;
22127
22128 kernel_fpu_begin();
22129
22130@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22131 * but that is for later. -AV
22132 */
22133 __asm__ __volatile__(
22134- "1: prefetch (%0)\n"
22135- " prefetch 64(%0)\n"
22136- " prefetch 128(%0)\n"
22137- " prefetch 192(%0)\n"
22138- " prefetch 256(%0)\n"
22139+ "1: prefetch (%1)\n"
22140+ " prefetch 64(%1)\n"
22141+ " prefetch 128(%1)\n"
22142+ " prefetch 192(%1)\n"
22143+ " prefetch 256(%1)\n"
22144 "2: \n"
22145 ".section .fixup, \"ax\"\n"
22146- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22147+ "3: \n"
22148+
22149+#ifdef CONFIG_PAX_KERNEXEC
22150+ " movl %%cr0, %0\n"
22151+ " movl %0, %%eax\n"
22152+ " andl $0xFFFEFFFF, %%eax\n"
22153+ " movl %%eax, %%cr0\n"
22154+#endif
22155+
22156+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22157+
22158+#ifdef CONFIG_PAX_KERNEXEC
22159+ " movl %0, %%cr0\n"
22160+#endif
22161+
22162 " jmp 2b\n"
22163 ".previous\n"
22164- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22165+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22166
22167 for (i = 0; i < (4096-320)/64; i++) {
22168 __asm__ __volatile__ (
22169- "1: prefetch 320(%0)\n"
22170- "2: movq (%0), %%mm0\n"
22171- " movntq %%mm0, (%1)\n"
22172- " movq 8(%0), %%mm1\n"
22173- " movntq %%mm1, 8(%1)\n"
22174- " movq 16(%0), %%mm2\n"
22175- " movntq %%mm2, 16(%1)\n"
22176- " movq 24(%0), %%mm3\n"
22177- " movntq %%mm3, 24(%1)\n"
22178- " movq 32(%0), %%mm4\n"
22179- " movntq %%mm4, 32(%1)\n"
22180- " movq 40(%0), %%mm5\n"
22181- " movntq %%mm5, 40(%1)\n"
22182- " movq 48(%0), %%mm6\n"
22183- " movntq %%mm6, 48(%1)\n"
22184- " movq 56(%0), %%mm7\n"
22185- " movntq %%mm7, 56(%1)\n"
22186+ "1: prefetch 320(%1)\n"
22187+ "2: movq (%1), %%mm0\n"
22188+ " movntq %%mm0, (%2)\n"
22189+ " movq 8(%1), %%mm1\n"
22190+ " movntq %%mm1, 8(%2)\n"
22191+ " movq 16(%1), %%mm2\n"
22192+ " movntq %%mm2, 16(%2)\n"
22193+ " movq 24(%1), %%mm3\n"
22194+ " movntq %%mm3, 24(%2)\n"
22195+ " movq 32(%1), %%mm4\n"
22196+ " movntq %%mm4, 32(%2)\n"
22197+ " movq 40(%1), %%mm5\n"
22198+ " movntq %%mm5, 40(%2)\n"
22199+ " movq 48(%1), %%mm6\n"
22200+ " movntq %%mm6, 48(%2)\n"
22201+ " movq 56(%1), %%mm7\n"
22202+ " movntq %%mm7, 56(%2)\n"
22203 ".section .fixup, \"ax\"\n"
22204- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22205+ "3:\n"
22206+
22207+#ifdef CONFIG_PAX_KERNEXEC
22208+ " movl %%cr0, %0\n"
22209+ " movl %0, %%eax\n"
22210+ " andl $0xFFFEFFFF, %%eax\n"
22211+ " movl %%eax, %%cr0\n"
22212+#endif
22213+
22214+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22215+
22216+#ifdef CONFIG_PAX_KERNEXEC
22217+ " movl %0, %%cr0\n"
22218+#endif
22219+
22220 " jmp 2b\n"
22221 ".previous\n"
22222- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22223+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22224
22225 from += 64;
22226 to += 64;
22227@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22228 static void fast_copy_page(void *to, void *from)
22229 {
22230 int i;
22231+ unsigned long cr0;
22232
22233 kernel_fpu_begin();
22234
22235 __asm__ __volatile__ (
22236- "1: prefetch (%0)\n"
22237- " prefetch 64(%0)\n"
22238- " prefetch 128(%0)\n"
22239- " prefetch 192(%0)\n"
22240- " prefetch 256(%0)\n"
22241+ "1: prefetch (%1)\n"
22242+ " prefetch 64(%1)\n"
22243+ " prefetch 128(%1)\n"
22244+ " prefetch 192(%1)\n"
22245+ " prefetch 256(%1)\n"
22246 "2: \n"
22247 ".section .fixup, \"ax\"\n"
22248- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22249+ "3: \n"
22250+
22251+#ifdef CONFIG_PAX_KERNEXEC
22252+ " movl %%cr0, %0\n"
22253+ " movl %0, %%eax\n"
22254+ " andl $0xFFFEFFFF, %%eax\n"
22255+ " movl %%eax, %%cr0\n"
22256+#endif
22257+
22258+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22259+
22260+#ifdef CONFIG_PAX_KERNEXEC
22261+ " movl %0, %%cr0\n"
22262+#endif
22263+
22264 " jmp 2b\n"
22265 ".previous\n"
22266- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22267+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22268
22269 for (i = 0; i < 4096/64; i++) {
22270 __asm__ __volatile__ (
22271- "1: prefetch 320(%0)\n"
22272- "2: movq (%0), %%mm0\n"
22273- " movq 8(%0), %%mm1\n"
22274- " movq 16(%0), %%mm2\n"
22275- " movq 24(%0), %%mm3\n"
22276- " movq %%mm0, (%1)\n"
22277- " movq %%mm1, 8(%1)\n"
22278- " movq %%mm2, 16(%1)\n"
22279- " movq %%mm3, 24(%1)\n"
22280- " movq 32(%0), %%mm0\n"
22281- " movq 40(%0), %%mm1\n"
22282- " movq 48(%0), %%mm2\n"
22283- " movq 56(%0), %%mm3\n"
22284- " movq %%mm0, 32(%1)\n"
22285- " movq %%mm1, 40(%1)\n"
22286- " movq %%mm2, 48(%1)\n"
22287- " movq %%mm3, 56(%1)\n"
22288+ "1: prefetch 320(%1)\n"
22289+ "2: movq (%1), %%mm0\n"
22290+ " movq 8(%1), %%mm1\n"
22291+ " movq 16(%1), %%mm2\n"
22292+ " movq 24(%1), %%mm3\n"
22293+ " movq %%mm0, (%2)\n"
22294+ " movq %%mm1, 8(%2)\n"
22295+ " movq %%mm2, 16(%2)\n"
22296+ " movq %%mm3, 24(%2)\n"
22297+ " movq 32(%1), %%mm0\n"
22298+ " movq 40(%1), %%mm1\n"
22299+ " movq 48(%1), %%mm2\n"
22300+ " movq 56(%1), %%mm3\n"
22301+ " movq %%mm0, 32(%2)\n"
22302+ " movq %%mm1, 40(%2)\n"
22303+ " movq %%mm2, 48(%2)\n"
22304+ " movq %%mm3, 56(%2)\n"
22305 ".section .fixup, \"ax\"\n"
22306- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22307+ "3:\n"
22308+
22309+#ifdef CONFIG_PAX_KERNEXEC
22310+ " movl %%cr0, %0\n"
22311+ " movl %0, %%eax\n"
22312+ " andl $0xFFFEFFFF, %%eax\n"
22313+ " movl %%eax, %%cr0\n"
22314+#endif
22315+
22316+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22317+
22318+#ifdef CONFIG_PAX_KERNEXEC
22319+ " movl %0, %%cr0\n"
22320+#endif
22321+
22322 " jmp 2b\n"
22323 ".previous\n"
22324 _ASM_EXTABLE(1b, 3b)
22325- : : "r" (from), "r" (to) : "memory");
22326+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22327
22328 from += 64;
22329 to += 64;
22330diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22331index 69fa106..adda88b 100644
22332--- a/arch/x86/lib/msr-reg.S
22333+++ b/arch/x86/lib/msr-reg.S
22334@@ -3,6 +3,7 @@
22335 #include <asm/dwarf2.h>
22336 #include <asm/asm.h>
22337 #include <asm/msr.h>
22338+#include <asm/alternative-asm.h>
22339
22340 #ifdef CONFIG_X86_64
22341 /*
22342@@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
22343 CFI_STARTPROC
22344 pushq_cfi %rbx
22345 pushq_cfi %rbp
22346- movq %rdi, %r10 /* Save pointer */
22347+ movq %rdi, %r9 /* Save pointer */
22348 xorl %r11d, %r11d /* Return value */
22349 movl (%rdi), %eax
22350 movl 4(%rdi), %ecx
22351@@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
22352 movl 28(%rdi), %edi
22353 CFI_REMEMBER_STATE
22354 1: \op
22355-2: movl %eax, (%r10)
22356+2: movl %eax, (%r9)
22357 movl %r11d, %eax /* Return value */
22358- movl %ecx, 4(%r10)
22359- movl %edx, 8(%r10)
22360- movl %ebx, 12(%r10)
22361- movl %ebp, 20(%r10)
22362- movl %esi, 24(%r10)
22363- movl %edi, 28(%r10)
22364+ movl %ecx, 4(%r9)
22365+ movl %edx, 8(%r9)
22366+ movl %ebx, 12(%r9)
22367+ movl %ebp, 20(%r9)
22368+ movl %esi, 24(%r9)
22369+ movl %edi, 28(%r9)
22370 popq_cfi %rbp
22371 popq_cfi %rbx
22372+ pax_force_retaddr
22373 ret
22374 3:
22375 CFI_RESTORE_STATE
22376diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22377index 7f951c8..ebd573a 100644
22378--- a/arch/x86/lib/putuser.S
22379+++ b/arch/x86/lib/putuser.S
22380@@ -15,7 +15,9 @@
22381 #include <asm/thread_info.h>
22382 #include <asm/errno.h>
22383 #include <asm/asm.h>
22384-
22385+#include <asm/segment.h>
22386+#include <asm/pgtable.h>
22387+#include <asm/alternative-asm.h>
22388
22389 /*
22390 * __put_user_X
22391@@ -29,52 +31,119 @@
22392 * as they get called from within inline assembly.
22393 */
22394
22395-#define ENTER CFI_STARTPROC ; \
22396- GET_THREAD_INFO(%_ASM_BX)
22397-#define EXIT ret ; \
22398+#define ENTER CFI_STARTPROC
22399+#define EXIT pax_force_retaddr; ret ; \
22400 CFI_ENDPROC
22401
22402+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22403+#define _DEST %_ASM_CX,%_ASM_BX
22404+#else
22405+#define _DEST %_ASM_CX
22406+#endif
22407+
22408+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22409+#define __copyuser_seg gs;
22410+#else
22411+#define __copyuser_seg
22412+#endif
22413+
22414 .text
22415 ENTRY(__put_user_1)
22416 ENTER
22417+
22418+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22419+ GET_THREAD_INFO(%_ASM_BX)
22420 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22421 jae bad_put_user
22422-1: movb %al,(%_ASM_CX)
22423+
22424+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22425+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22426+ cmp %_ASM_BX,%_ASM_CX
22427+ jb 1234f
22428+ xor %ebx,%ebx
22429+1234:
22430+#endif
22431+
22432+#endif
22433+
22434+1: __copyuser_seg movb %al,(_DEST)
22435 xor %eax,%eax
22436 EXIT
22437 ENDPROC(__put_user_1)
22438
22439 ENTRY(__put_user_2)
22440 ENTER
22441+
22442+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22443+ GET_THREAD_INFO(%_ASM_BX)
22444 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22445 sub $1,%_ASM_BX
22446 cmp %_ASM_BX,%_ASM_CX
22447 jae bad_put_user
22448-2: movw %ax,(%_ASM_CX)
22449+
22450+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22451+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22452+ cmp %_ASM_BX,%_ASM_CX
22453+ jb 1234f
22454+ xor %ebx,%ebx
22455+1234:
22456+#endif
22457+
22458+#endif
22459+
22460+2: __copyuser_seg movw %ax,(_DEST)
22461 xor %eax,%eax
22462 EXIT
22463 ENDPROC(__put_user_2)
22464
22465 ENTRY(__put_user_4)
22466 ENTER
22467+
22468+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22469+ GET_THREAD_INFO(%_ASM_BX)
22470 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22471 sub $3,%_ASM_BX
22472 cmp %_ASM_BX,%_ASM_CX
22473 jae bad_put_user
22474-3: movl %eax,(%_ASM_CX)
22475+
22476+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22477+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22478+ cmp %_ASM_BX,%_ASM_CX
22479+ jb 1234f
22480+ xor %ebx,%ebx
22481+1234:
22482+#endif
22483+
22484+#endif
22485+
22486+3: __copyuser_seg movl %eax,(_DEST)
22487 xor %eax,%eax
22488 EXIT
22489 ENDPROC(__put_user_4)
22490
22491 ENTRY(__put_user_8)
22492 ENTER
22493+
22494+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22495+ GET_THREAD_INFO(%_ASM_BX)
22496 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22497 sub $7,%_ASM_BX
22498 cmp %_ASM_BX,%_ASM_CX
22499 jae bad_put_user
22500-4: mov %_ASM_AX,(%_ASM_CX)
22501+
22502+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22503+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22504+ cmp %_ASM_BX,%_ASM_CX
22505+ jb 1234f
22506+ xor %ebx,%ebx
22507+1234:
22508+#endif
22509+
22510+#endif
22511+
22512+4: __copyuser_seg mov %_ASM_AX,(_DEST)
22513 #ifdef CONFIG_X86_32
22514-5: movl %edx,4(%_ASM_CX)
22515+5: __copyuser_seg movl %edx,4(_DEST)
22516 #endif
22517 xor %eax,%eax
22518 EXIT
22519diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22520index 1cad221..de671ee 100644
22521--- a/arch/x86/lib/rwlock.S
22522+++ b/arch/x86/lib/rwlock.S
22523@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22524 FRAME
22525 0: LOCK_PREFIX
22526 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22527+
22528+#ifdef CONFIG_PAX_REFCOUNT
22529+ jno 1234f
22530+ LOCK_PREFIX
22531+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22532+ int $4
22533+1234:
22534+ _ASM_EXTABLE(1234b, 1234b)
22535+#endif
22536+
22537 1: rep; nop
22538 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22539 jne 1b
22540 LOCK_PREFIX
22541 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22542+
22543+#ifdef CONFIG_PAX_REFCOUNT
22544+ jno 1234f
22545+ LOCK_PREFIX
22546+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22547+ int $4
22548+1234:
22549+ _ASM_EXTABLE(1234b, 1234b)
22550+#endif
22551+
22552 jnz 0b
22553 ENDFRAME
22554+ pax_force_retaddr
22555 ret
22556 CFI_ENDPROC
22557 END(__write_lock_failed)
22558@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22559 FRAME
22560 0: LOCK_PREFIX
22561 READ_LOCK_SIZE(inc) (%__lock_ptr)
22562+
22563+#ifdef CONFIG_PAX_REFCOUNT
22564+ jno 1234f
22565+ LOCK_PREFIX
22566+ READ_LOCK_SIZE(dec) (%__lock_ptr)
22567+ int $4
22568+1234:
22569+ _ASM_EXTABLE(1234b, 1234b)
22570+#endif
22571+
22572 1: rep; nop
22573 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22574 js 1b
22575 LOCK_PREFIX
22576 READ_LOCK_SIZE(dec) (%__lock_ptr)
22577+
22578+#ifdef CONFIG_PAX_REFCOUNT
22579+ jno 1234f
22580+ LOCK_PREFIX
22581+ READ_LOCK_SIZE(inc) (%__lock_ptr)
22582+ int $4
22583+1234:
22584+ _ASM_EXTABLE(1234b, 1234b)
22585+#endif
22586+
22587 js 0b
22588 ENDFRAME
22589+ pax_force_retaddr
22590 ret
22591 CFI_ENDPROC
22592 END(__read_lock_failed)
22593diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22594index 5dff5f0..cadebf4 100644
22595--- a/arch/x86/lib/rwsem.S
22596+++ b/arch/x86/lib/rwsem.S
22597@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22598 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22599 CFI_RESTORE __ASM_REG(dx)
22600 restore_common_regs
22601+ pax_force_retaddr
22602 ret
22603 CFI_ENDPROC
22604 ENDPROC(call_rwsem_down_read_failed)
22605@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22606 movq %rax,%rdi
22607 call rwsem_down_write_failed
22608 restore_common_regs
22609+ pax_force_retaddr
22610 ret
22611 CFI_ENDPROC
22612 ENDPROC(call_rwsem_down_write_failed)
22613@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22614 movq %rax,%rdi
22615 call rwsem_wake
22616 restore_common_regs
22617-1: ret
22618+1: pax_force_retaddr
22619+ ret
22620 CFI_ENDPROC
22621 ENDPROC(call_rwsem_wake)
22622
22623@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22624 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22625 CFI_RESTORE __ASM_REG(dx)
22626 restore_common_regs
22627+ pax_force_retaddr
22628 ret
22629 CFI_ENDPROC
22630 ENDPROC(call_rwsem_downgrade_wake)
22631diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22632index a63efd6..ccecad8 100644
22633--- a/arch/x86/lib/thunk_64.S
22634+++ b/arch/x86/lib/thunk_64.S
22635@@ -8,6 +8,7 @@
22636 #include <linux/linkage.h>
22637 #include <asm/dwarf2.h>
22638 #include <asm/calling.h>
22639+#include <asm/alternative-asm.h>
22640
22641 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22642 .macro THUNK name, func, put_ret_addr_in_rdi=0
22643@@ -41,5 +42,6 @@
22644 SAVE_ARGS
22645 restore:
22646 RESTORE_ARGS
22647+ pax_force_retaddr
22648 ret
22649 CFI_ENDPROC
22650diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22651index 1781b2f..90368dd 100644
22652--- a/arch/x86/lib/usercopy_32.c
22653+++ b/arch/x86/lib/usercopy_32.c
22654@@ -42,10 +42,12 @@ do { \
22655 int __d0; \
22656 might_fault(); \
22657 __asm__ __volatile__( \
22658+ __COPYUSER_SET_ES \
22659 "0: rep; stosl\n" \
22660 " movl %2,%0\n" \
22661 "1: rep; stosb\n" \
22662 "2:\n" \
22663+ __COPYUSER_RESTORE_ES \
22664 ".section .fixup,\"ax\"\n" \
22665 "3: lea 0(%2,%0,4),%0\n" \
22666 " jmp 2b\n" \
22667@@ -97,7 +99,7 @@ EXPORT_SYMBOL(__clear_user);
22668
22669 #ifdef CONFIG_X86_INTEL_USERCOPY
22670 static unsigned long
22671-__copy_user_intel(void __user *to, const void *from, unsigned long size)
22672+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22673 {
22674 int d0, d1;
22675 __asm__ __volatile__(
22676@@ -109,36 +111,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22677 " .align 2,0x90\n"
22678 "3: movl 0(%4), %%eax\n"
22679 "4: movl 4(%4), %%edx\n"
22680- "5: movl %%eax, 0(%3)\n"
22681- "6: movl %%edx, 4(%3)\n"
22682+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22683+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22684 "7: movl 8(%4), %%eax\n"
22685 "8: movl 12(%4),%%edx\n"
22686- "9: movl %%eax, 8(%3)\n"
22687- "10: movl %%edx, 12(%3)\n"
22688+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22689+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22690 "11: movl 16(%4), %%eax\n"
22691 "12: movl 20(%4), %%edx\n"
22692- "13: movl %%eax, 16(%3)\n"
22693- "14: movl %%edx, 20(%3)\n"
22694+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22695+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22696 "15: movl 24(%4), %%eax\n"
22697 "16: movl 28(%4), %%edx\n"
22698- "17: movl %%eax, 24(%3)\n"
22699- "18: movl %%edx, 28(%3)\n"
22700+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22701+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22702 "19: movl 32(%4), %%eax\n"
22703 "20: movl 36(%4), %%edx\n"
22704- "21: movl %%eax, 32(%3)\n"
22705- "22: movl %%edx, 36(%3)\n"
22706+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22707+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22708 "23: movl 40(%4), %%eax\n"
22709 "24: movl 44(%4), %%edx\n"
22710- "25: movl %%eax, 40(%3)\n"
22711- "26: movl %%edx, 44(%3)\n"
22712+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22713+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22714 "27: movl 48(%4), %%eax\n"
22715 "28: movl 52(%4), %%edx\n"
22716- "29: movl %%eax, 48(%3)\n"
22717- "30: movl %%edx, 52(%3)\n"
22718+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22719+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22720 "31: movl 56(%4), %%eax\n"
22721 "32: movl 60(%4), %%edx\n"
22722- "33: movl %%eax, 56(%3)\n"
22723- "34: movl %%edx, 60(%3)\n"
22724+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22725+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22726 " addl $-64, %0\n"
22727 " addl $64, %4\n"
22728 " addl $64, %3\n"
22729@@ -148,10 +150,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22730 " shrl $2, %0\n"
22731 " andl $3, %%eax\n"
22732 " cld\n"
22733+ __COPYUSER_SET_ES
22734 "99: rep; movsl\n"
22735 "36: movl %%eax, %0\n"
22736 "37: rep; movsb\n"
22737 "100:\n"
22738+ __COPYUSER_RESTORE_ES
22739 ".section .fixup,\"ax\"\n"
22740 "101: lea 0(%%eax,%0,4),%0\n"
22741 " jmp 100b\n"
22742@@ -201,46 +205,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22743 }
22744
22745 static unsigned long
22746+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22747+{
22748+ int d0, d1;
22749+ __asm__ __volatile__(
22750+ " .align 2,0x90\n"
22751+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22752+ " cmpl $67, %0\n"
22753+ " jbe 3f\n"
22754+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
22755+ " .align 2,0x90\n"
22756+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
22757+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
22758+ "5: movl %%eax, 0(%3)\n"
22759+ "6: movl %%edx, 4(%3)\n"
22760+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
22761+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
22762+ "9: movl %%eax, 8(%3)\n"
22763+ "10: movl %%edx, 12(%3)\n"
22764+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
22765+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
22766+ "13: movl %%eax, 16(%3)\n"
22767+ "14: movl %%edx, 20(%3)\n"
22768+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
22769+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
22770+ "17: movl %%eax, 24(%3)\n"
22771+ "18: movl %%edx, 28(%3)\n"
22772+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
22773+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
22774+ "21: movl %%eax, 32(%3)\n"
22775+ "22: movl %%edx, 36(%3)\n"
22776+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
22777+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
22778+ "25: movl %%eax, 40(%3)\n"
22779+ "26: movl %%edx, 44(%3)\n"
22780+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
22781+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
22782+ "29: movl %%eax, 48(%3)\n"
22783+ "30: movl %%edx, 52(%3)\n"
22784+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
22785+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
22786+ "33: movl %%eax, 56(%3)\n"
22787+ "34: movl %%edx, 60(%3)\n"
22788+ " addl $-64, %0\n"
22789+ " addl $64, %4\n"
22790+ " addl $64, %3\n"
22791+ " cmpl $63, %0\n"
22792+ " ja 1b\n"
22793+ "35: movl %0, %%eax\n"
22794+ " shrl $2, %0\n"
22795+ " andl $3, %%eax\n"
22796+ " cld\n"
22797+ "99: rep; "__copyuser_seg" movsl\n"
22798+ "36: movl %%eax, %0\n"
22799+ "37: rep; "__copyuser_seg" movsb\n"
22800+ "100:\n"
22801+ ".section .fixup,\"ax\"\n"
22802+ "101: lea 0(%%eax,%0,4),%0\n"
22803+ " jmp 100b\n"
22804+ ".previous\n"
22805+ _ASM_EXTABLE(1b,100b)
22806+ _ASM_EXTABLE(2b,100b)
22807+ _ASM_EXTABLE(3b,100b)
22808+ _ASM_EXTABLE(4b,100b)
22809+ _ASM_EXTABLE(5b,100b)
22810+ _ASM_EXTABLE(6b,100b)
22811+ _ASM_EXTABLE(7b,100b)
22812+ _ASM_EXTABLE(8b,100b)
22813+ _ASM_EXTABLE(9b,100b)
22814+ _ASM_EXTABLE(10b,100b)
22815+ _ASM_EXTABLE(11b,100b)
22816+ _ASM_EXTABLE(12b,100b)
22817+ _ASM_EXTABLE(13b,100b)
22818+ _ASM_EXTABLE(14b,100b)
22819+ _ASM_EXTABLE(15b,100b)
22820+ _ASM_EXTABLE(16b,100b)
22821+ _ASM_EXTABLE(17b,100b)
22822+ _ASM_EXTABLE(18b,100b)
22823+ _ASM_EXTABLE(19b,100b)
22824+ _ASM_EXTABLE(20b,100b)
22825+ _ASM_EXTABLE(21b,100b)
22826+ _ASM_EXTABLE(22b,100b)
22827+ _ASM_EXTABLE(23b,100b)
22828+ _ASM_EXTABLE(24b,100b)
22829+ _ASM_EXTABLE(25b,100b)
22830+ _ASM_EXTABLE(26b,100b)
22831+ _ASM_EXTABLE(27b,100b)
22832+ _ASM_EXTABLE(28b,100b)
22833+ _ASM_EXTABLE(29b,100b)
22834+ _ASM_EXTABLE(30b,100b)
22835+ _ASM_EXTABLE(31b,100b)
22836+ _ASM_EXTABLE(32b,100b)
22837+ _ASM_EXTABLE(33b,100b)
22838+ _ASM_EXTABLE(34b,100b)
22839+ _ASM_EXTABLE(35b,100b)
22840+ _ASM_EXTABLE(36b,100b)
22841+ _ASM_EXTABLE(37b,100b)
22842+ _ASM_EXTABLE(99b,101b)
22843+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
22844+ : "1"(to), "2"(from), "0"(size)
22845+ : "eax", "edx", "memory");
22846+ return size;
22847+}
22848+
22849+static unsigned long __size_overflow(3)
22850 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22851 {
22852 int d0, d1;
22853 __asm__ __volatile__(
22854 " .align 2,0x90\n"
22855- "0: movl 32(%4), %%eax\n"
22856+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22857 " cmpl $67, %0\n"
22858 " jbe 2f\n"
22859- "1: movl 64(%4), %%eax\n"
22860+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22861 " .align 2,0x90\n"
22862- "2: movl 0(%4), %%eax\n"
22863- "21: movl 4(%4), %%edx\n"
22864+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22865+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22866 " movl %%eax, 0(%3)\n"
22867 " movl %%edx, 4(%3)\n"
22868- "3: movl 8(%4), %%eax\n"
22869- "31: movl 12(%4),%%edx\n"
22870+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22871+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22872 " movl %%eax, 8(%3)\n"
22873 " movl %%edx, 12(%3)\n"
22874- "4: movl 16(%4), %%eax\n"
22875- "41: movl 20(%4), %%edx\n"
22876+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22877+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22878 " movl %%eax, 16(%3)\n"
22879 " movl %%edx, 20(%3)\n"
22880- "10: movl 24(%4), %%eax\n"
22881- "51: movl 28(%4), %%edx\n"
22882+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22883+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22884 " movl %%eax, 24(%3)\n"
22885 " movl %%edx, 28(%3)\n"
22886- "11: movl 32(%4), %%eax\n"
22887- "61: movl 36(%4), %%edx\n"
22888+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22889+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22890 " movl %%eax, 32(%3)\n"
22891 " movl %%edx, 36(%3)\n"
22892- "12: movl 40(%4), %%eax\n"
22893- "71: movl 44(%4), %%edx\n"
22894+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22895+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22896 " movl %%eax, 40(%3)\n"
22897 " movl %%edx, 44(%3)\n"
22898- "13: movl 48(%4), %%eax\n"
22899- "81: movl 52(%4), %%edx\n"
22900+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22901+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22902 " movl %%eax, 48(%3)\n"
22903 " movl %%edx, 52(%3)\n"
22904- "14: movl 56(%4), %%eax\n"
22905- "91: movl 60(%4), %%edx\n"
22906+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22907+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22908 " movl %%eax, 56(%3)\n"
22909 " movl %%edx, 60(%3)\n"
22910 " addl $-64, %0\n"
22911@@ -252,9 +360,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22912 " shrl $2, %0\n"
22913 " andl $3, %%eax\n"
22914 " cld\n"
22915- "6: rep; movsl\n"
22916+ "6: rep; "__copyuser_seg" movsl\n"
22917 " movl %%eax,%0\n"
22918- "7: rep; movsb\n"
22919+ "7: rep; "__copyuser_seg" movsb\n"
22920 "8:\n"
22921 ".section .fixup,\"ax\"\n"
22922 "9: lea 0(%%eax,%0,4),%0\n"
22923@@ -297,48 +405,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22924 * hyoshiok@miraclelinux.com
22925 */
22926
22927-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22928+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
22929 const void __user *from, unsigned long size)
22930 {
22931 int d0, d1;
22932
22933 __asm__ __volatile__(
22934 " .align 2,0x90\n"
22935- "0: movl 32(%4), %%eax\n"
22936+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22937 " cmpl $67, %0\n"
22938 " jbe 2f\n"
22939- "1: movl 64(%4), %%eax\n"
22940+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22941 " .align 2,0x90\n"
22942- "2: movl 0(%4), %%eax\n"
22943- "21: movl 4(%4), %%edx\n"
22944+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22945+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22946 " movnti %%eax, 0(%3)\n"
22947 " movnti %%edx, 4(%3)\n"
22948- "3: movl 8(%4), %%eax\n"
22949- "31: movl 12(%4),%%edx\n"
22950+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22951+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22952 " movnti %%eax, 8(%3)\n"
22953 " movnti %%edx, 12(%3)\n"
22954- "4: movl 16(%4), %%eax\n"
22955- "41: movl 20(%4), %%edx\n"
22956+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22957+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22958 " movnti %%eax, 16(%3)\n"
22959 " movnti %%edx, 20(%3)\n"
22960- "10: movl 24(%4), %%eax\n"
22961- "51: movl 28(%4), %%edx\n"
22962+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22963+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22964 " movnti %%eax, 24(%3)\n"
22965 " movnti %%edx, 28(%3)\n"
22966- "11: movl 32(%4), %%eax\n"
22967- "61: movl 36(%4), %%edx\n"
22968+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22969+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22970 " movnti %%eax, 32(%3)\n"
22971 " movnti %%edx, 36(%3)\n"
22972- "12: movl 40(%4), %%eax\n"
22973- "71: movl 44(%4), %%edx\n"
22974+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22975+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22976 " movnti %%eax, 40(%3)\n"
22977 " movnti %%edx, 44(%3)\n"
22978- "13: movl 48(%4), %%eax\n"
22979- "81: movl 52(%4), %%edx\n"
22980+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22981+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22982 " movnti %%eax, 48(%3)\n"
22983 " movnti %%edx, 52(%3)\n"
22984- "14: movl 56(%4), %%eax\n"
22985- "91: movl 60(%4), %%edx\n"
22986+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22987+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22988 " movnti %%eax, 56(%3)\n"
22989 " movnti %%edx, 60(%3)\n"
22990 " addl $-64, %0\n"
22991@@ -351,9 +459,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22992 " shrl $2, %0\n"
22993 " andl $3, %%eax\n"
22994 " cld\n"
22995- "6: rep; movsl\n"
22996+ "6: rep; "__copyuser_seg" movsl\n"
22997 " movl %%eax,%0\n"
22998- "7: rep; movsb\n"
22999+ "7: rep; "__copyuser_seg" movsb\n"
23000 "8:\n"
23001 ".section .fixup,\"ax\"\n"
23002 "9: lea 0(%%eax,%0,4),%0\n"
23003@@ -391,48 +499,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23004 return size;
23005 }
23006
23007-static unsigned long __copy_user_intel_nocache(void *to,
23008+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
23009 const void __user *from, unsigned long size)
23010 {
23011 int d0, d1;
23012
23013 __asm__ __volatile__(
23014 " .align 2,0x90\n"
23015- "0: movl 32(%4), %%eax\n"
23016+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23017 " cmpl $67, %0\n"
23018 " jbe 2f\n"
23019- "1: movl 64(%4), %%eax\n"
23020+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23021 " .align 2,0x90\n"
23022- "2: movl 0(%4), %%eax\n"
23023- "21: movl 4(%4), %%edx\n"
23024+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23025+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23026 " movnti %%eax, 0(%3)\n"
23027 " movnti %%edx, 4(%3)\n"
23028- "3: movl 8(%4), %%eax\n"
23029- "31: movl 12(%4),%%edx\n"
23030+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23031+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23032 " movnti %%eax, 8(%3)\n"
23033 " movnti %%edx, 12(%3)\n"
23034- "4: movl 16(%4), %%eax\n"
23035- "41: movl 20(%4), %%edx\n"
23036+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23037+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23038 " movnti %%eax, 16(%3)\n"
23039 " movnti %%edx, 20(%3)\n"
23040- "10: movl 24(%4), %%eax\n"
23041- "51: movl 28(%4), %%edx\n"
23042+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23043+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23044 " movnti %%eax, 24(%3)\n"
23045 " movnti %%edx, 28(%3)\n"
23046- "11: movl 32(%4), %%eax\n"
23047- "61: movl 36(%4), %%edx\n"
23048+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23049+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23050 " movnti %%eax, 32(%3)\n"
23051 " movnti %%edx, 36(%3)\n"
23052- "12: movl 40(%4), %%eax\n"
23053- "71: movl 44(%4), %%edx\n"
23054+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23055+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23056 " movnti %%eax, 40(%3)\n"
23057 " movnti %%edx, 44(%3)\n"
23058- "13: movl 48(%4), %%eax\n"
23059- "81: movl 52(%4), %%edx\n"
23060+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23061+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23062 " movnti %%eax, 48(%3)\n"
23063 " movnti %%edx, 52(%3)\n"
23064- "14: movl 56(%4), %%eax\n"
23065- "91: movl 60(%4), %%edx\n"
23066+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23067+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23068 " movnti %%eax, 56(%3)\n"
23069 " movnti %%edx, 60(%3)\n"
23070 " addl $-64, %0\n"
23071@@ -445,9 +553,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23072 " shrl $2, %0\n"
23073 " andl $3, %%eax\n"
23074 " cld\n"
23075- "6: rep; movsl\n"
23076+ "6: rep; "__copyuser_seg" movsl\n"
23077 " movl %%eax,%0\n"
23078- "7: rep; movsb\n"
23079+ "7: rep; "__copyuser_seg" movsb\n"
23080 "8:\n"
23081 ".section .fixup,\"ax\"\n"
23082 "9: lea 0(%%eax,%0,4),%0\n"
23083@@ -487,32 +595,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23084 */
23085 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23086 unsigned long size);
23087-unsigned long __copy_user_intel(void __user *to, const void *from,
23088+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23089+ unsigned long size);
23090+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23091 unsigned long size);
23092 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23093 const void __user *from, unsigned long size);
23094 #endif /* CONFIG_X86_INTEL_USERCOPY */
23095
23096 /* Generic arbitrary sized copy. */
23097-#define __copy_user(to, from, size) \
23098+#define __copy_user(to, from, size, prefix, set, restore) \
23099 do { \
23100 int __d0, __d1, __d2; \
23101 __asm__ __volatile__( \
23102+ set \
23103 " cmp $7,%0\n" \
23104 " jbe 1f\n" \
23105 " movl %1,%0\n" \
23106 " negl %0\n" \
23107 " andl $7,%0\n" \
23108 " subl %0,%3\n" \
23109- "4: rep; movsb\n" \
23110+ "4: rep; "prefix"movsb\n" \
23111 " movl %3,%0\n" \
23112 " shrl $2,%0\n" \
23113 " andl $3,%3\n" \
23114 " .align 2,0x90\n" \
23115- "0: rep; movsl\n" \
23116+ "0: rep; "prefix"movsl\n" \
23117 " movl %3,%0\n" \
23118- "1: rep; movsb\n" \
23119+ "1: rep; "prefix"movsb\n" \
23120 "2:\n" \
23121+ restore \
23122 ".section .fixup,\"ax\"\n" \
23123 "5: addl %3,%0\n" \
23124 " jmp 2b\n" \
23125@@ -537,14 +649,14 @@ do { \
23126 " negl %0\n" \
23127 " andl $7,%0\n" \
23128 " subl %0,%3\n" \
23129- "4: rep; movsb\n" \
23130+ "4: rep; "__copyuser_seg"movsb\n" \
23131 " movl %3,%0\n" \
23132 " shrl $2,%0\n" \
23133 " andl $3,%3\n" \
23134 " .align 2,0x90\n" \
23135- "0: rep; movsl\n" \
23136+ "0: rep; "__copyuser_seg"movsl\n" \
23137 " movl %3,%0\n" \
23138- "1: rep; movsb\n" \
23139+ "1: rep; "__copyuser_seg"movsb\n" \
23140 "2:\n" \
23141 ".section .fixup,\"ax\"\n" \
23142 "5: addl %3,%0\n" \
23143@@ -627,9 +739,9 @@ survive:
23144 }
23145 #endif
23146 if (movsl_is_ok(to, from, n))
23147- __copy_user(to, from, n);
23148+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23149 else
23150- n = __copy_user_intel(to, from, n);
23151+ n = __generic_copy_to_user_intel(to, from, n);
23152 return n;
23153 }
23154 EXPORT_SYMBOL(__copy_to_user_ll);
23155@@ -649,10 +761,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23156 unsigned long n)
23157 {
23158 if (movsl_is_ok(to, from, n))
23159- __copy_user(to, from, n);
23160+ __copy_user(to, from, n, __copyuser_seg, "", "");
23161 else
23162- n = __copy_user_intel((void __user *)to,
23163- (const void *)from, n);
23164+ n = __generic_copy_from_user_intel(to, from, n);
23165 return n;
23166 }
23167 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23168@@ -679,65 +790,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23169 if (n > 64 && cpu_has_xmm2)
23170 n = __copy_user_intel_nocache(to, from, n);
23171 else
23172- __copy_user(to, from, n);
23173+ __copy_user(to, from, n, __copyuser_seg, "", "");
23174 #else
23175- __copy_user(to, from, n);
23176+ __copy_user(to, from, n, __copyuser_seg, "", "");
23177 #endif
23178 return n;
23179 }
23180 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23181
23182-/**
23183- * copy_to_user: - Copy a block of data into user space.
23184- * @to: Destination address, in user space.
23185- * @from: Source address, in kernel space.
23186- * @n: Number of bytes to copy.
23187- *
23188- * Context: User context only. This function may sleep.
23189- *
23190- * Copy data from kernel space to user space.
23191- *
23192- * Returns number of bytes that could not be copied.
23193- * On success, this will be zero.
23194- */
23195-unsigned long
23196-copy_to_user(void __user *to, const void *from, unsigned long n)
23197-{
23198- if (access_ok(VERIFY_WRITE, to, n))
23199- n = __copy_to_user(to, from, n);
23200- return n;
23201-}
23202-EXPORT_SYMBOL(copy_to_user);
23203-
23204-/**
23205- * copy_from_user: - Copy a block of data from user space.
23206- * @to: Destination address, in kernel space.
23207- * @from: Source address, in user space.
23208- * @n: Number of bytes to copy.
23209- *
23210- * Context: User context only. This function may sleep.
23211- *
23212- * Copy data from user space to kernel space.
23213- *
23214- * Returns number of bytes that could not be copied.
23215- * On success, this will be zero.
23216- *
23217- * If some data could not be copied, this function will pad the copied
23218- * data to the requested size using zero bytes.
23219- */
23220-unsigned long
23221-_copy_from_user(void *to, const void __user *from, unsigned long n)
23222-{
23223- if (access_ok(VERIFY_READ, from, n))
23224- n = __copy_from_user(to, from, n);
23225- else
23226- memset(to, 0, n);
23227- return n;
23228-}
23229-EXPORT_SYMBOL(_copy_from_user);
23230-
23231 void copy_from_user_overflow(void)
23232 {
23233 WARN(1, "Buffer overflow detected!\n");
23234 }
23235 EXPORT_SYMBOL(copy_from_user_overflow);
23236+
23237+void copy_to_user_overflow(void)
23238+{
23239+ WARN(1, "Buffer overflow detected!\n");
23240+}
23241+EXPORT_SYMBOL(copy_to_user_overflow);
23242+
23243+#ifdef CONFIG_PAX_MEMORY_UDEREF
23244+void __set_fs(mm_segment_t x)
23245+{
23246+ switch (x.seg) {
23247+ case 0:
23248+ loadsegment(gs, 0);
23249+ break;
23250+ case TASK_SIZE_MAX:
23251+ loadsegment(gs, __USER_DS);
23252+ break;
23253+ case -1UL:
23254+ loadsegment(gs, __KERNEL_DS);
23255+ break;
23256+ default:
23257+ BUG();
23258+ }
23259+ return;
23260+}
23261+EXPORT_SYMBOL(__set_fs);
23262+
23263+void set_fs(mm_segment_t x)
23264+{
23265+ current_thread_info()->addr_limit = x;
23266+ __set_fs(x);
23267+}
23268+EXPORT_SYMBOL(set_fs);
23269+#endif
23270diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23271index e5b130b..6690d31 100644
23272--- a/arch/x86/lib/usercopy_64.c
23273+++ b/arch/x86/lib/usercopy_64.c
23274@@ -16,6 +16,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23275 {
23276 long __d0;
23277 might_fault();
23278+
23279+#ifdef CONFIG_PAX_MEMORY_UDEREF
23280+ if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23281+ addr += PAX_USER_SHADOW_BASE;
23282+#endif
23283+
23284 /* no memory constraint because it doesn't change any memory gcc knows
23285 about */
23286 asm volatile(
23287@@ -52,12 +58,20 @@ unsigned long clear_user(void __user *to, unsigned long n)
23288 }
23289 EXPORT_SYMBOL(clear_user);
23290
23291-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23292+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23293 {
23294- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23295- return copy_user_generic((__force void *)to, (__force void *)from, len);
23296- }
23297- return len;
23298+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23299+
23300+#ifdef CONFIG_PAX_MEMORY_UDEREF
23301+ if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23302+ to += PAX_USER_SHADOW_BASE;
23303+ if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23304+ from += PAX_USER_SHADOW_BASE;
23305+#endif
23306+
23307+ return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23308+ }
23309+ return len;
23310 }
23311 EXPORT_SYMBOL(copy_in_user);
23312
23313@@ -67,7 +81,7 @@ EXPORT_SYMBOL(copy_in_user);
23314 * it is not necessary to optimize tail handling.
23315 */
23316 unsigned long
23317-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23318+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23319 {
23320 char c;
23321 unsigned zero_len;
23322@@ -84,3 +98,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23323 break;
23324 return len;
23325 }
23326+
23327+void copy_from_user_overflow(void)
23328+{
23329+ WARN(1, "Buffer overflow detected!\n");
23330+}
23331+EXPORT_SYMBOL(copy_from_user_overflow);
23332+
23333+void copy_to_user_overflow(void)
23334+{
23335+ WARN(1, "Buffer overflow detected!\n");
23336+}
23337+EXPORT_SYMBOL(copy_to_user_overflow);
23338diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23339index 903ec1e..833f340 100644
23340--- a/arch/x86/mm/extable.c
23341+++ b/arch/x86/mm/extable.c
23342@@ -6,12 +6,25 @@
23343 static inline unsigned long
23344 ex_insn_addr(const struct exception_table_entry *x)
23345 {
23346- return (unsigned long)&x->insn + x->insn;
23347+//printk(KERN_ERR "fixup %p insn:%x fixup:%x\n", x, x->insn, 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->insn + x->insn + reloc;
23355 }
23356 static inline unsigned long
23357 ex_fixup_addr(const struct exception_table_entry *x)
23358 {
23359- return (unsigned long)&x->fixup + x->fixup;
23360+ unsigned long reloc = 0;
23361+
23362+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
23363+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23364+#endif
23365+
23366+ return (unsigned long)&x->fixup + x->fixup + reloc;
23367 }
23368
23369 int fixup_exception(struct pt_regs *regs)
23370@@ -20,7 +33,7 @@ int fixup_exception(struct pt_regs *regs)
23371 unsigned long new_ip;
23372
23373 #ifdef CONFIG_PNPBIOS
23374- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23375+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23376 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23377 extern u32 pnp_bios_is_utter_crap;
23378 pnp_bios_is_utter_crap = 1;
23379@@ -34,6 +47,7 @@ int fixup_exception(struct pt_regs *regs)
23380 #endif
23381
23382 fixup = search_exception_tables(regs->ip);
23383+//printk(KERN_ERR "fixup %p %lx\n", fixup, regs->ip);
23384 if (fixup) {
23385 new_ip = ex_fixup_addr(fixup);
23386
23387diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23388index 76dcd9d..e9dffde 100644
23389--- a/arch/x86/mm/fault.c
23390+++ b/arch/x86/mm/fault.c
23391@@ -13,11 +13,18 @@
23392 #include <linux/perf_event.h> /* perf_sw_event */
23393 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23394 #include <linux/prefetch.h> /* prefetchw */
23395+#include <linux/unistd.h>
23396+#include <linux/compiler.h>
23397
23398 #include <asm/traps.h> /* dotraplinkage, ... */
23399 #include <asm/pgalloc.h> /* pgd_*(), ... */
23400 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23401 #include <asm/fixmap.h> /* VSYSCALL_START */
23402+#include <asm/tlbflush.h>
23403+
23404+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23405+#include <asm/stacktrace.h>
23406+#endif
23407
23408 /*
23409 * Page fault error code bits:
23410@@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23411 int ret = 0;
23412
23413 /* kprobe_running() needs smp_processor_id() */
23414- if (kprobes_built_in() && !user_mode_vm(regs)) {
23415+ if (kprobes_built_in() && !user_mode(regs)) {
23416 preempt_disable();
23417 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23418 ret = 1;
23419@@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23420 return !instr_lo || (instr_lo>>1) == 1;
23421 case 0x00:
23422 /* Prefetch instruction is 0x0F0D or 0x0F18 */
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+ return 0;
23427+ } else if (probe_kernel_address(instr, opcode))
23428 return 0;
23429
23430 *prefetch = (instr_lo == 0xF) &&
23431@@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23432 while (instr < max_instr) {
23433 unsigned char opcode;
23434
23435- if (probe_kernel_address(instr, opcode))
23436+ if (user_mode(regs)) {
23437+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23438+ break;
23439+ } else if (probe_kernel_address(instr, opcode))
23440 break;
23441
23442 instr++;
23443@@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23444 force_sig_info(si_signo, &info, tsk);
23445 }
23446
23447+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23448+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23449+#endif
23450+
23451+#ifdef CONFIG_PAX_EMUTRAMP
23452+static int pax_handle_fetch_fault(struct pt_regs *regs);
23453+#endif
23454+
23455+#ifdef CONFIG_PAX_PAGEEXEC
23456+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23457+{
23458+ pgd_t *pgd;
23459+ pud_t *pud;
23460+ pmd_t *pmd;
23461+
23462+ pgd = pgd_offset(mm, address);
23463+ if (!pgd_present(*pgd))
23464+ return NULL;
23465+ pud = pud_offset(pgd, address);
23466+ if (!pud_present(*pud))
23467+ return NULL;
23468+ pmd = pmd_offset(pud, address);
23469+ if (!pmd_present(*pmd))
23470+ return NULL;
23471+ return pmd;
23472+}
23473+#endif
23474+
23475 DEFINE_SPINLOCK(pgd_lock);
23476 LIST_HEAD(pgd_list);
23477
23478@@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23479 for (address = VMALLOC_START & PMD_MASK;
23480 address >= TASK_SIZE && address < FIXADDR_TOP;
23481 address += PMD_SIZE) {
23482+
23483+#ifdef CONFIG_PAX_PER_CPU_PGD
23484+ unsigned long cpu;
23485+#else
23486 struct page *page;
23487+#endif
23488
23489 spin_lock(&pgd_lock);
23490+
23491+#ifdef CONFIG_PAX_PER_CPU_PGD
23492+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23493+ pgd_t *pgd = get_cpu_pgd(cpu);
23494+ pmd_t *ret;
23495+#else
23496 list_for_each_entry(page, &pgd_list, lru) {
23497+ pgd_t *pgd = page_address(page);
23498 spinlock_t *pgt_lock;
23499 pmd_t *ret;
23500
23501@@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23502 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23503
23504 spin_lock(pgt_lock);
23505- ret = vmalloc_sync_one(page_address(page), address);
23506+#endif
23507+
23508+ ret = vmalloc_sync_one(pgd, address);
23509+
23510+#ifndef CONFIG_PAX_PER_CPU_PGD
23511 spin_unlock(pgt_lock);
23512+#endif
23513
23514 if (!ret)
23515 break;
23516@@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23517 * an interrupt in the middle of a task switch..
23518 */
23519 pgd_paddr = read_cr3();
23520+
23521+#ifdef CONFIG_PAX_PER_CPU_PGD
23522+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23523+#endif
23524+
23525 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23526 if (!pmd_k)
23527 return -1;
23528@@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23529 * happen within a race in page table update. In the later
23530 * case just flush:
23531 */
23532+
23533+#ifdef CONFIG_PAX_PER_CPU_PGD
23534+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23535+ pgd = pgd_offset_cpu(smp_processor_id(), address);
23536+#else
23537 pgd = pgd_offset(current->active_mm, address);
23538+#endif
23539+
23540 pgd_ref = pgd_offset_k(address);
23541 if (pgd_none(*pgd_ref))
23542 return -1;
23543@@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23544 static int is_errata100(struct pt_regs *regs, unsigned long address)
23545 {
23546 #ifdef CONFIG_X86_64
23547- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23548+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23549 return 1;
23550 #endif
23551 return 0;
23552@@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23553 }
23554
23555 static const char nx_warning[] = KERN_CRIT
23556-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23557+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23558
23559 static void
23560 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23561@@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23562 if (!oops_may_print())
23563 return;
23564
23565- if (error_code & PF_INSTR) {
23566+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23567 unsigned int level;
23568
23569 pte_t *pte = lookup_address(address, &level);
23570
23571 if (pte && pte_present(*pte) && !pte_exec(*pte))
23572- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
23573+ printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
23574 }
23575
23576+#ifdef CONFIG_PAX_KERNEXEC
23577+ if (init_mm.start_code <= address && address < init_mm.end_code) {
23578+ if (current->signal->curr_ip)
23579+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23580+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23581+ else
23582+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23583+ current->comm, task_pid_nr(current), current_uid(), current_euid());
23584+ }
23585+#endif
23586+
23587 printk(KERN_ALERT "BUG: unable to handle kernel ");
23588 if (address < PAGE_SIZE)
23589 printk(KERN_CONT "NULL pointer dereference");
23590@@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23591 }
23592 #endif
23593
23594+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23595+ if (pax_is_fetch_fault(regs, error_code, address)) {
23596+
23597+#ifdef CONFIG_PAX_EMUTRAMP
23598+ switch (pax_handle_fetch_fault(regs)) {
23599+ case 2:
23600+ return;
23601+ }
23602+#endif
23603+
23604+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23605+ do_group_exit(SIGKILL);
23606+ }
23607+#endif
23608+
23609 if (unlikely(show_unhandled_signals))
23610 show_signal_msg(regs, error_code, address, tsk);
23611
23612@@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23613 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23614 printk(KERN_ERR
23615 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23616- tsk->comm, tsk->pid, address);
23617+ tsk->comm, task_pid_nr(tsk), address);
23618 code = BUS_MCEERR_AR;
23619 }
23620 #endif
23621@@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23622 return 1;
23623 }
23624
23625+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23626+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23627+{
23628+ pte_t *pte;
23629+ pmd_t *pmd;
23630+ spinlock_t *ptl;
23631+ unsigned char pte_mask;
23632+
23633+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23634+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
23635+ return 0;
23636+
23637+ /* PaX: it's our fault, let's handle it if we can */
23638+
23639+ /* PaX: take a look at read faults before acquiring any locks */
23640+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23641+ /* instruction fetch attempt from a protected page in user mode */
23642+ up_read(&mm->mmap_sem);
23643+
23644+#ifdef CONFIG_PAX_EMUTRAMP
23645+ switch (pax_handle_fetch_fault(regs)) {
23646+ case 2:
23647+ return 1;
23648+ }
23649+#endif
23650+
23651+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23652+ do_group_exit(SIGKILL);
23653+ }
23654+
23655+ pmd = pax_get_pmd(mm, address);
23656+ if (unlikely(!pmd))
23657+ return 0;
23658+
23659+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23660+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23661+ pte_unmap_unlock(pte, ptl);
23662+ return 0;
23663+ }
23664+
23665+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23666+ /* write attempt to a protected page in user mode */
23667+ pte_unmap_unlock(pte, ptl);
23668+ return 0;
23669+ }
23670+
23671+#ifdef CONFIG_SMP
23672+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23673+#else
23674+ if (likely(address > get_limit(regs->cs)))
23675+#endif
23676+ {
23677+ set_pte(pte, pte_mkread(*pte));
23678+ __flush_tlb_one(address);
23679+ pte_unmap_unlock(pte, ptl);
23680+ up_read(&mm->mmap_sem);
23681+ return 1;
23682+ }
23683+
23684+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23685+
23686+ /*
23687+ * PaX: fill DTLB with user rights and retry
23688+ */
23689+ __asm__ __volatile__ (
23690+ "orb %2,(%1)\n"
23691+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23692+/*
23693+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23694+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23695+ * page fault when examined during a TLB load attempt. this is true not only
23696+ * for PTEs holding a non-present entry but also present entries that will
23697+ * raise a page fault (such as those set up by PaX, or the copy-on-write
23698+ * mechanism). in effect it means that we do *not* need to flush the TLBs
23699+ * for our target pages since their PTEs are simply not in the TLBs at all.
23700+
23701+ * the best thing in omitting it is that we gain around 15-20% speed in the
23702+ * fast path of the page fault handler and can get rid of tracing since we
23703+ * can no longer flush unintended entries.
23704+ */
23705+ "invlpg (%0)\n"
23706+#endif
23707+ __copyuser_seg"testb $0,(%0)\n"
23708+ "xorb %3,(%1)\n"
23709+ :
23710+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23711+ : "memory", "cc");
23712+ pte_unmap_unlock(pte, ptl);
23713+ up_read(&mm->mmap_sem);
23714+ return 1;
23715+}
23716+#endif
23717+
23718 /*
23719 * Handle a spurious fault caused by a stale TLB entry.
23720 *
23721@@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23722 static inline int
23723 access_error(unsigned long error_code, struct vm_area_struct *vma)
23724 {
23725+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23726+ return 1;
23727+
23728 if (error_code & PF_WRITE) {
23729 /* write, present and write, not present: */
23730 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23731@@ -1005,18 +1197,33 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23732 {
23733 struct vm_area_struct *vma;
23734 struct task_struct *tsk;
23735- unsigned long address;
23736 struct mm_struct *mm;
23737 int fault;
23738 int write = error_code & PF_WRITE;
23739 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23740 (write ? FAULT_FLAG_WRITE : 0);
23741
23742- tsk = current;
23743- mm = tsk->mm;
23744-
23745 /* Get the faulting address: */
23746- address = read_cr2();
23747+ unsigned long address = read_cr2();
23748+
23749+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23750+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23751+ if (!search_exception_tables(regs->ip)) {
23752+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23753+ bad_area_nosemaphore(regs, error_code, address);
23754+ return;
23755+ }
23756+ if (address < PAX_USER_SHADOW_BASE) {
23757+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23758+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
23759+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
23760+ } else
23761+ address -= PAX_USER_SHADOW_BASE;
23762+ }
23763+#endif
23764+
23765+ tsk = current;
23766+ mm = tsk->mm;
23767
23768 /*
23769 * Detect and handle instructions that would cause a page fault for
23770@@ -1077,7 +1284,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23771 * User-mode registers count as a user access even for any
23772 * potential system fault or CPU buglet:
23773 */
23774- if (user_mode_vm(regs)) {
23775+ if (user_mode(regs)) {
23776 local_irq_enable();
23777 error_code |= PF_USER;
23778 } else {
23779@@ -1132,6 +1339,11 @@ retry:
23780 might_sleep();
23781 }
23782
23783+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23784+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
23785+ return;
23786+#endif
23787+
23788 vma = find_vma(mm, address);
23789 if (unlikely(!vma)) {
23790 bad_area(regs, error_code, address);
23791@@ -1143,18 +1355,24 @@ retry:
23792 bad_area(regs, error_code, address);
23793 return;
23794 }
23795- if (error_code & PF_USER) {
23796- /*
23797- * Accessing the stack below %sp is always a bug.
23798- * The large cushion allows instructions like enter
23799- * and pusha to work. ("enter $65535, $31" pushes
23800- * 32 pointers and then decrements %sp by 65535.)
23801- */
23802- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
23803- bad_area(regs, error_code, address);
23804- return;
23805- }
23806+ /*
23807+ * Accessing the stack below %sp is always a bug.
23808+ * The large cushion allows instructions like enter
23809+ * and pusha to work. ("enter $65535, $31" pushes
23810+ * 32 pointers and then decrements %sp by 65535.)
23811+ */
23812+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
23813+ bad_area(regs, error_code, address);
23814+ return;
23815 }
23816+
23817+#ifdef CONFIG_PAX_SEGMEXEC
23818+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
23819+ bad_area(regs, error_code, address);
23820+ return;
23821+ }
23822+#endif
23823+
23824 if (unlikely(expand_stack(vma, address))) {
23825 bad_area(regs, error_code, address);
23826 return;
23827@@ -1209,3 +1427,292 @@ good_area:
23828
23829 up_read(&mm->mmap_sem);
23830 }
23831+
23832+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23833+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
23834+{
23835+ struct mm_struct *mm = current->mm;
23836+ unsigned long ip = regs->ip;
23837+
23838+ if (v8086_mode(regs))
23839+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
23840+
23841+#ifdef CONFIG_PAX_PAGEEXEC
23842+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
23843+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
23844+ return true;
23845+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
23846+ return true;
23847+ return false;
23848+ }
23849+#endif
23850+
23851+#ifdef CONFIG_PAX_SEGMEXEC
23852+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
23853+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
23854+ return true;
23855+ return false;
23856+ }
23857+#endif
23858+
23859+ return false;
23860+}
23861+#endif
23862+
23863+#ifdef CONFIG_PAX_EMUTRAMP
23864+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
23865+{
23866+ int err;
23867+
23868+ do { /* PaX: libffi trampoline emulation */
23869+ unsigned char mov, jmp;
23870+ unsigned int addr1, addr2;
23871+
23872+#ifdef CONFIG_X86_64
23873+ if ((regs->ip + 9) >> 32)
23874+ break;
23875+#endif
23876+
23877+ err = get_user(mov, (unsigned char __user *)regs->ip);
23878+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23879+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23880+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23881+
23882+ if (err)
23883+ break;
23884+
23885+ if (mov == 0xB8 && jmp == 0xE9) {
23886+ regs->ax = addr1;
23887+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
23888+ return 2;
23889+ }
23890+ } while (0);
23891+
23892+ do { /* PaX: gcc trampoline emulation #1 */
23893+ unsigned char mov1, mov2;
23894+ unsigned short jmp;
23895+ unsigned int addr1, addr2;
23896+
23897+#ifdef CONFIG_X86_64
23898+ if ((regs->ip + 11) >> 32)
23899+ break;
23900+#endif
23901+
23902+ err = get_user(mov1, (unsigned char __user *)regs->ip);
23903+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23904+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
23905+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23906+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
23907+
23908+ if (err)
23909+ break;
23910+
23911+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
23912+ regs->cx = addr1;
23913+ regs->ax = addr2;
23914+ regs->ip = addr2;
23915+ return 2;
23916+ }
23917+ } while (0);
23918+
23919+ do { /* PaX: gcc trampoline emulation #2 */
23920+ unsigned char mov, jmp;
23921+ unsigned int addr1, addr2;
23922+
23923+#ifdef CONFIG_X86_64
23924+ if ((regs->ip + 9) >> 32)
23925+ break;
23926+#endif
23927+
23928+ err = get_user(mov, (unsigned char __user *)regs->ip);
23929+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23930+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23931+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23932+
23933+ if (err)
23934+ break;
23935+
23936+ if (mov == 0xB9 && jmp == 0xE9) {
23937+ regs->cx = addr1;
23938+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
23939+ return 2;
23940+ }
23941+ } while (0);
23942+
23943+ return 1; /* PaX in action */
23944+}
23945+
23946+#ifdef CONFIG_X86_64
23947+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
23948+{
23949+ int err;
23950+
23951+ do { /* PaX: libffi trampoline emulation */
23952+ unsigned short mov1, mov2, jmp1;
23953+ unsigned char stcclc, jmp2;
23954+ unsigned long addr1, addr2;
23955+
23956+ err = get_user(mov1, (unsigned short __user *)regs->ip);
23957+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
23958+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
23959+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
23960+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
23961+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
23962+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
23963+
23964+ if (err)
23965+ break;
23966+
23967+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23968+ regs->r11 = addr1;
23969+ regs->r10 = addr2;
23970+ if (stcclc == 0xF8)
23971+ regs->flags &= ~X86_EFLAGS_CF;
23972+ else
23973+ regs->flags |= X86_EFLAGS_CF;
23974+ regs->ip = addr1;
23975+ return 2;
23976+ }
23977+ } while (0);
23978+
23979+ do { /* PaX: gcc trampoline emulation #1 */
23980+ unsigned short mov1, mov2, jmp1;
23981+ unsigned char jmp2;
23982+ unsigned int addr1;
23983+ unsigned long addr2;
23984+
23985+ err = get_user(mov1, (unsigned short __user *)regs->ip);
23986+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
23987+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
23988+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
23989+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
23990+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
23991+
23992+ if (err)
23993+ break;
23994+
23995+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
23996+ regs->r11 = addr1;
23997+ regs->r10 = addr2;
23998+ regs->ip = addr1;
23999+ return 2;
24000+ }
24001+ } while (0);
24002+
24003+ do { /* PaX: gcc trampoline emulation #2 */
24004+ unsigned short mov1, mov2, jmp1;
24005+ unsigned char jmp2;
24006+ unsigned long addr1, addr2;
24007+
24008+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24009+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24010+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24011+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24012+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24013+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24014+
24015+ if (err)
24016+ break;
24017+
24018+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24019+ regs->r11 = addr1;
24020+ regs->r10 = addr2;
24021+ regs->ip = addr1;
24022+ return 2;
24023+ }
24024+ } while (0);
24025+
24026+ return 1; /* PaX in action */
24027+}
24028+#endif
24029+
24030+/*
24031+ * PaX: decide what to do with offenders (regs->ip = fault address)
24032+ *
24033+ * returns 1 when task should be killed
24034+ * 2 when gcc trampoline was detected
24035+ */
24036+static int pax_handle_fetch_fault(struct pt_regs *regs)
24037+{
24038+ if (v8086_mode(regs))
24039+ return 1;
24040+
24041+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24042+ return 1;
24043+
24044+#ifdef CONFIG_X86_32
24045+ return pax_handle_fetch_fault_32(regs);
24046+#else
24047+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24048+ return pax_handle_fetch_fault_32(regs);
24049+ else
24050+ return pax_handle_fetch_fault_64(regs);
24051+#endif
24052+}
24053+#endif
24054+
24055+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24056+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24057+{
24058+ long i;
24059+
24060+ printk(KERN_ERR "PAX: bytes at PC: ");
24061+ for (i = 0; i < 20; i++) {
24062+ unsigned char c;
24063+ if (get_user(c, (unsigned char __force_user *)pc+i))
24064+ printk(KERN_CONT "?? ");
24065+ else
24066+ printk(KERN_CONT "%02x ", c);
24067+ }
24068+ printk("\n");
24069+
24070+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24071+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
24072+ unsigned long c;
24073+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
24074+#ifdef CONFIG_X86_32
24075+ printk(KERN_CONT "???????? ");
24076+#else
24077+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24078+ printk(KERN_CONT "???????? ???????? ");
24079+ else
24080+ printk(KERN_CONT "???????????????? ");
24081+#endif
24082+ } else {
24083+#ifdef CONFIG_X86_64
24084+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24085+ printk(KERN_CONT "%08x ", (unsigned int)c);
24086+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24087+ } else
24088+#endif
24089+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24090+ }
24091+ }
24092+ printk("\n");
24093+}
24094+#endif
24095+
24096+/**
24097+ * probe_kernel_write(): safely attempt to write to a location
24098+ * @dst: address to write to
24099+ * @src: pointer to the data that shall be written
24100+ * @size: size of the data chunk
24101+ *
24102+ * Safely write to address @dst from the buffer at @src. If a kernel fault
24103+ * happens, handle that and return -EFAULT.
24104+ */
24105+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24106+{
24107+ long ret;
24108+ mm_segment_t old_fs = get_fs();
24109+
24110+ set_fs(KERNEL_DS);
24111+ pagefault_disable();
24112+ pax_open_kernel();
24113+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24114+ pax_close_kernel();
24115+ pagefault_enable();
24116+ set_fs(old_fs);
24117+
24118+ return ret ? -EFAULT : 0;
24119+}
24120diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24121index dd74e46..7d26398 100644
24122--- a/arch/x86/mm/gup.c
24123+++ b/arch/x86/mm/gup.c
24124@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24125 addr = start;
24126 len = (unsigned long) nr_pages << PAGE_SHIFT;
24127 end = start + len;
24128- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24129+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24130 (void __user *)start, len)))
24131 return 0;
24132
24133diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24134index 6f31ee5..8ee4164 100644
24135--- a/arch/x86/mm/highmem_32.c
24136+++ b/arch/x86/mm/highmem_32.c
24137@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24138 idx = type + KM_TYPE_NR*smp_processor_id();
24139 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24140 BUG_ON(!pte_none(*(kmap_pte-idx)));
24141+
24142+ pax_open_kernel();
24143 set_pte(kmap_pte-idx, mk_pte(page, prot));
24144+ pax_close_kernel();
24145+
24146 arch_flush_lazy_mmu_mode();
24147
24148 return (void *)vaddr;
24149diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24150index f6679a7..8f795a3 100644
24151--- a/arch/x86/mm/hugetlbpage.c
24152+++ b/arch/x86/mm/hugetlbpage.c
24153@@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24154 struct hstate *h = hstate_file(file);
24155 struct mm_struct *mm = current->mm;
24156 struct vm_area_struct *vma;
24157- unsigned long start_addr;
24158+ unsigned long start_addr, pax_task_size = TASK_SIZE;
24159+
24160+#ifdef CONFIG_PAX_SEGMEXEC
24161+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24162+ pax_task_size = SEGMEXEC_TASK_SIZE;
24163+#endif
24164+
24165+ pax_task_size -= PAGE_SIZE;
24166
24167 if (len > mm->cached_hole_size) {
24168- start_addr = mm->free_area_cache;
24169+ start_addr = mm->free_area_cache;
24170 } else {
24171- start_addr = TASK_UNMAPPED_BASE;
24172- mm->cached_hole_size = 0;
24173+ start_addr = mm->mmap_base;
24174+ mm->cached_hole_size = 0;
24175 }
24176
24177 full_search:
24178@@ -280,26 +287,27 @@ full_search:
24179
24180 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24181 /* At this point: (!vma || addr < vma->vm_end). */
24182- if (TASK_SIZE - len < addr) {
24183+ if (pax_task_size - len < addr) {
24184 /*
24185 * Start a new search - just in case we missed
24186 * some holes.
24187 */
24188- if (start_addr != TASK_UNMAPPED_BASE) {
24189- start_addr = TASK_UNMAPPED_BASE;
24190+ if (start_addr != mm->mmap_base) {
24191+ start_addr = mm->mmap_base;
24192 mm->cached_hole_size = 0;
24193 goto full_search;
24194 }
24195 return -ENOMEM;
24196 }
24197- if (!vma || addr + len <= vma->vm_start) {
24198- mm->free_area_cache = addr + len;
24199- return addr;
24200- }
24201+ if (check_heap_stack_gap(vma, addr, len))
24202+ break;
24203 if (addr + mm->cached_hole_size < vma->vm_start)
24204 mm->cached_hole_size = vma->vm_start - addr;
24205 addr = ALIGN(vma->vm_end, huge_page_size(h));
24206 }
24207+
24208+ mm->free_area_cache = addr + len;
24209+ return addr;
24210 }
24211
24212 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24213@@ -310,9 +318,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24214 struct mm_struct *mm = current->mm;
24215 struct vm_area_struct *vma;
24216 unsigned long base = mm->mmap_base;
24217- unsigned long addr = addr0;
24218+ unsigned long addr;
24219 unsigned long largest_hole = mm->cached_hole_size;
24220- unsigned long start_addr;
24221
24222 /* don't allow allocations above current base */
24223 if (mm->free_area_cache > base)
24224@@ -322,16 +329,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24225 largest_hole = 0;
24226 mm->free_area_cache = base;
24227 }
24228-try_again:
24229- start_addr = mm->free_area_cache;
24230
24231 /* make sure it can fit in the remaining address space */
24232 if (mm->free_area_cache < len)
24233 goto fail;
24234
24235 /* either no address requested or can't fit in requested address hole */
24236- addr = (mm->free_area_cache - len) & huge_page_mask(h);
24237+ addr = mm->free_area_cache - len;
24238 do {
24239+ addr &= huge_page_mask(h);
24240 /*
24241 * Lookup failure means no vma is above this address,
24242 * i.e. return with success:
24243@@ -340,10 +346,10 @@ try_again:
24244 if (!vma)
24245 return addr;
24246
24247- if (addr + len <= vma->vm_start) {
24248+ if (check_heap_stack_gap(vma, addr, len)) {
24249 /* remember the address as a hint for next time */
24250- mm->cached_hole_size = largest_hole;
24251- return (mm->free_area_cache = addr);
24252+ mm->cached_hole_size = largest_hole;
24253+ return (mm->free_area_cache = addr);
24254 } else if (mm->free_area_cache == vma->vm_end) {
24255 /* pull free_area_cache down to the first hole */
24256 mm->free_area_cache = vma->vm_start;
24257@@ -352,29 +358,34 @@ try_again:
24258
24259 /* remember the largest hole we saw so far */
24260 if (addr + largest_hole < vma->vm_start)
24261- largest_hole = vma->vm_start - addr;
24262+ largest_hole = vma->vm_start - addr;
24263
24264 /* try just below the current vma->vm_start */
24265- addr = (vma->vm_start - len) & huge_page_mask(h);
24266- } while (len <= vma->vm_start);
24267+ addr = skip_heap_stack_gap(vma, len);
24268+ } while (!IS_ERR_VALUE(addr));
24269
24270 fail:
24271 /*
24272- * if hint left us with no space for the requested
24273- * mapping then try again:
24274- */
24275- if (start_addr != base) {
24276- mm->free_area_cache = base;
24277- largest_hole = 0;
24278- goto try_again;
24279- }
24280- /*
24281 * A failed mmap() very likely causes application failure,
24282 * so fall back to the bottom-up function here. This scenario
24283 * can happen with large stack limits and large mmap()
24284 * allocations.
24285 */
24286- mm->free_area_cache = TASK_UNMAPPED_BASE;
24287+
24288+#ifdef CONFIG_PAX_SEGMEXEC
24289+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24290+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24291+ else
24292+#endif
24293+
24294+ mm->mmap_base = TASK_UNMAPPED_BASE;
24295+
24296+#ifdef CONFIG_PAX_RANDMMAP
24297+ if (mm->pax_flags & MF_PAX_RANDMMAP)
24298+ mm->mmap_base += mm->delta_mmap;
24299+#endif
24300+
24301+ mm->free_area_cache = mm->mmap_base;
24302 mm->cached_hole_size = ~0UL;
24303 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24304 len, pgoff, flags);
24305@@ -382,6 +393,7 @@ fail:
24306 /*
24307 * Restore the topdown base:
24308 */
24309+ mm->mmap_base = base;
24310 mm->free_area_cache = base;
24311 mm->cached_hole_size = ~0UL;
24312
24313@@ -395,10 +407,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24314 struct hstate *h = hstate_file(file);
24315 struct mm_struct *mm = current->mm;
24316 struct vm_area_struct *vma;
24317+ unsigned long pax_task_size = TASK_SIZE;
24318
24319 if (len & ~huge_page_mask(h))
24320 return -EINVAL;
24321- if (len > TASK_SIZE)
24322+
24323+#ifdef CONFIG_PAX_SEGMEXEC
24324+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24325+ pax_task_size = SEGMEXEC_TASK_SIZE;
24326+#endif
24327+
24328+ pax_task_size -= PAGE_SIZE;
24329+
24330+ if (len > pax_task_size)
24331 return -ENOMEM;
24332
24333 if (flags & MAP_FIXED) {
24334@@ -410,8 +431,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24335 if (addr) {
24336 addr = ALIGN(addr, huge_page_size(h));
24337 vma = find_vma(mm, addr);
24338- if (TASK_SIZE - len >= addr &&
24339- (!vma || addr + len <= vma->vm_start))
24340+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24341 return addr;
24342 }
24343 if (mm->get_unmapped_area == arch_get_unmapped_area)
24344diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24345index bc4e9d8..ca4c14b 100644
24346--- a/arch/x86/mm/init.c
24347+++ b/arch/x86/mm/init.c
24348@@ -16,6 +16,8 @@
24349 #include <asm/tlb.h>
24350 #include <asm/proto.h>
24351 #include <asm/dma.h> /* for MAX_DMA_PFN */
24352+#include <asm/desc.h>
24353+#include <asm/bios_ebda.h>
24354
24355 unsigned long __initdata pgt_buf_start;
24356 unsigned long __meminitdata pgt_buf_end;
24357@@ -38,7 +40,7 @@ struct map_range {
24358 static void __init find_early_table_space(struct map_range *mr, unsigned long end,
24359 int use_pse, int use_gbpages)
24360 {
24361- unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
24362+ unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
24363 phys_addr_t base;
24364
24365 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
24366@@ -317,10 +319,37 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24367 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24368 * mmio resources as well as potential bios/acpi data regions.
24369 */
24370+
24371+#ifdef CONFIG_GRKERNSEC_KMEM
24372+static unsigned int ebda_start __read_only;
24373+static unsigned int ebda_end __read_only;
24374+#endif
24375+
24376 int devmem_is_allowed(unsigned long pagenr)
24377 {
24378+#ifdef CONFIG_GRKERNSEC_KMEM
24379+ /* allow BDA */
24380+ if (!pagenr)
24381+ return 1;
24382+ /* allow EBDA */
24383+ if (pagenr >= ebda_start && pagenr < ebda_end)
24384+ return 1;
24385+#else
24386+ if (!pagenr)
24387+ return 1;
24388+#ifdef CONFIG_VM86
24389+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24390+ return 1;
24391+#endif
24392+#endif
24393+
24394+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24395+ return 1;
24396+#ifdef CONFIG_GRKERNSEC_KMEM
24397+ /* throw out everything else below 1MB */
24398 if (pagenr <= 256)
24399- return 1;
24400+ return 0;
24401+#endif
24402 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24403 return 0;
24404 if (!page_is_ram(pagenr))
24405@@ -377,8 +406,116 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24406 #endif
24407 }
24408
24409+#ifdef CONFIG_GRKERNSEC_KMEM
24410+static inline void gr_init_ebda(void)
24411+{
24412+ unsigned int ebda_addr;
24413+ unsigned int ebda_size = 0;
24414+
24415+ ebda_addr = get_bios_ebda();
24416+ if (ebda_addr) {
24417+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24418+ ebda_size <<= 10;
24419+ }
24420+ if (ebda_addr && ebda_size) {
24421+ ebda_start = ebda_addr >> PAGE_SHIFT;
24422+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24423+ } else {
24424+ ebda_start = 0x9f000 >> PAGE_SHIFT;
24425+ ebda_end = 0xa0000 >> PAGE_SHIFT;
24426+ }
24427+}
24428+#else
24429+static inline void gr_init_ebda(void) { }
24430+#endif
24431+
24432 void free_initmem(void)
24433 {
24434+#ifdef CONFIG_PAX_KERNEXEC
24435+#ifdef CONFIG_X86_32
24436+ /* PaX: limit KERNEL_CS to actual size */
24437+ unsigned long addr, limit;
24438+ struct desc_struct d;
24439+ int cpu;
24440+#else
24441+ pgd_t *pgd;
24442+ pud_t *pud;
24443+ pmd_t *pmd;
24444+ unsigned long addr, end;
24445+#endif
24446+#endif
24447+
24448+ gr_init_ebda();
24449+
24450+#ifdef CONFIG_PAX_KERNEXEC
24451+#ifdef CONFIG_X86_32
24452+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24453+ limit = (limit - 1UL) >> PAGE_SHIFT;
24454+
24455+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24456+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24457+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24458+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24459+ }
24460+
24461+ /* PaX: make KERNEL_CS read-only */
24462+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24463+ if (!paravirt_enabled())
24464+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24465+/*
24466+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24467+ pgd = pgd_offset_k(addr);
24468+ pud = pud_offset(pgd, addr);
24469+ pmd = pmd_offset(pud, addr);
24470+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24471+ }
24472+*/
24473+#ifdef CONFIG_X86_PAE
24474+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24475+/*
24476+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24477+ pgd = pgd_offset_k(addr);
24478+ pud = pud_offset(pgd, addr);
24479+ pmd = pmd_offset(pud, addr);
24480+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24481+ }
24482+*/
24483+#endif
24484+
24485+#ifdef CONFIG_MODULES
24486+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24487+#endif
24488+
24489+#else
24490+ /* PaX: make kernel code/rodata read-only, rest non-executable */
24491+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24492+ pgd = pgd_offset_k(addr);
24493+ pud = pud_offset(pgd, addr);
24494+ pmd = pmd_offset(pud, addr);
24495+ if (!pmd_present(*pmd))
24496+ continue;
24497+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24498+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24499+ else
24500+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24501+ }
24502+
24503+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24504+ end = addr + KERNEL_IMAGE_SIZE;
24505+ for (; addr < end; addr += PMD_SIZE) {
24506+ pgd = pgd_offset_k(addr);
24507+ pud = pud_offset(pgd, addr);
24508+ pmd = pmd_offset(pud, addr);
24509+ if (!pmd_present(*pmd))
24510+ continue;
24511+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24512+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24513+ }
24514+#endif
24515+
24516+ flush_tlb_all();
24517+#endif
24518+
24519 free_init_pages("unused kernel memory",
24520 (unsigned long)(&__init_begin),
24521 (unsigned long)(&__init_end));
24522diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24523index 575d86f..4987469 100644
24524--- a/arch/x86/mm/init_32.c
24525+++ b/arch/x86/mm/init_32.c
24526@@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24527 }
24528
24529 /*
24530- * Creates a middle page table and puts a pointer to it in the
24531- * given global directory entry. This only returns the gd entry
24532- * in non-PAE compilation mode, since the middle layer is folded.
24533- */
24534-static pmd_t * __init one_md_table_init(pgd_t *pgd)
24535-{
24536- pud_t *pud;
24537- pmd_t *pmd_table;
24538-
24539-#ifdef CONFIG_X86_PAE
24540- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24541- if (after_bootmem)
24542- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24543- else
24544- pmd_table = (pmd_t *)alloc_low_page();
24545- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24546- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24547- pud = pud_offset(pgd, 0);
24548- BUG_ON(pmd_table != pmd_offset(pud, 0));
24549-
24550- return pmd_table;
24551- }
24552-#endif
24553- pud = pud_offset(pgd, 0);
24554- pmd_table = pmd_offset(pud, 0);
24555-
24556- return pmd_table;
24557-}
24558-
24559-/*
24560 * Create a page table and place a pointer to it in a middle page
24561 * directory entry:
24562 */
24563@@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24564 page_table = (pte_t *)alloc_low_page();
24565
24566 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24567+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24568+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24569+#else
24570 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24571+#endif
24572 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24573 }
24574
24575 return pte_offset_kernel(pmd, 0);
24576 }
24577
24578+static pmd_t * __init one_md_table_init(pgd_t *pgd)
24579+{
24580+ pud_t *pud;
24581+ pmd_t *pmd_table;
24582+
24583+ pud = pud_offset(pgd, 0);
24584+ pmd_table = pmd_offset(pud, 0);
24585+
24586+ return pmd_table;
24587+}
24588+
24589 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24590 {
24591 int pgd_idx = pgd_index(vaddr);
24592@@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24593 int pgd_idx, pmd_idx;
24594 unsigned long vaddr;
24595 pgd_t *pgd;
24596+ pud_t *pud;
24597 pmd_t *pmd;
24598 pte_t *pte = NULL;
24599
24600@@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24601 pgd = pgd_base + pgd_idx;
24602
24603 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24604- pmd = one_md_table_init(pgd);
24605- pmd = pmd + pmd_index(vaddr);
24606+ pud = pud_offset(pgd, vaddr);
24607+ pmd = pmd_offset(pud, vaddr);
24608+
24609+#ifdef CONFIG_X86_PAE
24610+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24611+#endif
24612+
24613 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24614 pmd++, pmd_idx++) {
24615 pte = page_table_kmap_check(one_page_table_init(pmd),
24616@@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24617 }
24618 }
24619
24620-static inline int is_kernel_text(unsigned long addr)
24621+static inline int is_kernel_text(unsigned long start, unsigned long end)
24622 {
24623- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24624- return 1;
24625- return 0;
24626+ if ((start > ktla_ktva((unsigned long)_etext) ||
24627+ end <= ktla_ktva((unsigned long)_stext)) &&
24628+ (start > ktla_ktva((unsigned long)_einittext) ||
24629+ end <= ktla_ktva((unsigned long)_sinittext)) &&
24630+
24631+#ifdef CONFIG_ACPI_SLEEP
24632+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24633+#endif
24634+
24635+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24636+ return 0;
24637+ return 1;
24638 }
24639
24640 /*
24641@@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24642 unsigned long last_map_addr = end;
24643 unsigned long start_pfn, end_pfn;
24644 pgd_t *pgd_base = swapper_pg_dir;
24645- int pgd_idx, pmd_idx, pte_ofs;
24646+ unsigned int pgd_idx, pmd_idx, pte_ofs;
24647 unsigned long pfn;
24648 pgd_t *pgd;
24649+ pud_t *pud;
24650 pmd_t *pmd;
24651 pte_t *pte;
24652 unsigned pages_2m, pages_4k;
24653@@ -280,8 +281,13 @@ repeat:
24654 pfn = start_pfn;
24655 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24656 pgd = pgd_base + pgd_idx;
24657- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24658- pmd = one_md_table_init(pgd);
24659+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24660+ pud = pud_offset(pgd, 0);
24661+ pmd = pmd_offset(pud, 0);
24662+
24663+#ifdef CONFIG_X86_PAE
24664+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24665+#endif
24666
24667 if (pfn >= end_pfn)
24668 continue;
24669@@ -293,14 +299,13 @@ repeat:
24670 #endif
24671 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24672 pmd++, pmd_idx++) {
24673- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24674+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24675
24676 /*
24677 * Map with big pages if possible, otherwise
24678 * create normal page tables:
24679 */
24680 if (use_pse) {
24681- unsigned int addr2;
24682 pgprot_t prot = PAGE_KERNEL_LARGE;
24683 /*
24684 * first pass will use the same initial
24685@@ -310,11 +315,7 @@ repeat:
24686 __pgprot(PTE_IDENT_ATTR |
24687 _PAGE_PSE);
24688
24689- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24690- PAGE_OFFSET + PAGE_SIZE-1;
24691-
24692- if (is_kernel_text(addr) ||
24693- is_kernel_text(addr2))
24694+ if (is_kernel_text(address, address + PMD_SIZE))
24695 prot = PAGE_KERNEL_LARGE_EXEC;
24696
24697 pages_2m++;
24698@@ -331,7 +332,7 @@ repeat:
24699 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24700 pte += pte_ofs;
24701 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24702- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24703+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24704 pgprot_t prot = PAGE_KERNEL;
24705 /*
24706 * first pass will use the same initial
24707@@ -339,7 +340,7 @@ repeat:
24708 */
24709 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24710
24711- if (is_kernel_text(addr))
24712+ if (is_kernel_text(address, address + PAGE_SIZE))
24713 prot = PAGE_KERNEL_EXEC;
24714
24715 pages_4k++;
24716@@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24717
24718 pud = pud_offset(pgd, va);
24719 pmd = pmd_offset(pud, va);
24720- if (!pmd_present(*pmd))
24721+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
24722 break;
24723
24724 pte = pte_offset_kernel(pmd, va);
24725@@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
24726
24727 static void __init pagetable_init(void)
24728 {
24729- pgd_t *pgd_base = swapper_pg_dir;
24730-
24731- permanent_kmaps_init(pgd_base);
24732+ permanent_kmaps_init(swapper_pg_dir);
24733 }
24734
24735-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24736+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24737 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24738
24739 /* user-defined highmem size */
24740@@ -734,6 +733,12 @@ void __init mem_init(void)
24741
24742 pci_iommu_alloc();
24743
24744+#ifdef CONFIG_PAX_PER_CPU_PGD
24745+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24746+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24747+ KERNEL_PGD_PTRS);
24748+#endif
24749+
24750 #ifdef CONFIG_FLATMEM
24751 BUG_ON(!mem_map);
24752 #endif
24753@@ -760,7 +765,7 @@ void __init mem_init(void)
24754 reservedpages++;
24755
24756 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24757- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
24758+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
24759 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
24760
24761 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
24762@@ -801,10 +806,10 @@ void __init mem_init(void)
24763 ((unsigned long)&__init_end -
24764 (unsigned long)&__init_begin) >> 10,
24765
24766- (unsigned long)&_etext, (unsigned long)&_edata,
24767- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
24768+ (unsigned long)&_sdata, (unsigned long)&_edata,
24769+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
24770
24771- (unsigned long)&_text, (unsigned long)&_etext,
24772+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
24773 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
24774
24775 /*
24776@@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
24777 if (!kernel_set_to_readonly)
24778 return;
24779
24780+ start = ktla_ktva(start);
24781 pr_debug("Set kernel text: %lx - %lx for read write\n",
24782 start, start+size);
24783
24784@@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
24785 if (!kernel_set_to_readonly)
24786 return;
24787
24788+ start = ktla_ktva(start);
24789 pr_debug("Set kernel text: %lx - %lx for read only\n",
24790 start, start+size);
24791
24792@@ -924,6 +931,7 @@ void mark_rodata_ro(void)
24793 unsigned long start = PFN_ALIGN(_text);
24794 unsigned long size = PFN_ALIGN(_etext) - start;
24795
24796+ start = ktla_ktva(start);
24797 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
24798 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
24799 size >> 10);
24800diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
24801index 2b6b4a3..c17210d 100644
24802--- a/arch/x86/mm/init_64.c
24803+++ b/arch/x86/mm/init_64.c
24804@@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
24805 * around without checking the pgd every time.
24806 */
24807
24808-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
24809+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
24810 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24811
24812 int force_personality32;
24813@@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24814
24815 for (address = start; address <= end; address += PGDIR_SIZE) {
24816 const pgd_t *pgd_ref = pgd_offset_k(address);
24817+
24818+#ifdef CONFIG_PAX_PER_CPU_PGD
24819+ unsigned long cpu;
24820+#else
24821 struct page *page;
24822+#endif
24823
24824 if (pgd_none(*pgd_ref))
24825 continue;
24826
24827 spin_lock(&pgd_lock);
24828+
24829+#ifdef CONFIG_PAX_PER_CPU_PGD
24830+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
24831+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
24832+#else
24833 list_for_each_entry(page, &pgd_list, lru) {
24834 pgd_t *pgd;
24835 spinlock_t *pgt_lock;
24836@@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24837 /* the pgt_lock only for Xen */
24838 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
24839 spin_lock(pgt_lock);
24840+#endif
24841
24842 if (pgd_none(*pgd))
24843 set_pgd(pgd, *pgd_ref);
24844@@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24845 BUG_ON(pgd_page_vaddr(*pgd)
24846 != pgd_page_vaddr(*pgd_ref));
24847
24848+#ifndef CONFIG_PAX_PER_CPU_PGD
24849 spin_unlock(pgt_lock);
24850+#endif
24851+
24852 }
24853 spin_unlock(&pgd_lock);
24854 }
24855@@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
24856 {
24857 if (pgd_none(*pgd)) {
24858 pud_t *pud = (pud_t *)spp_getpage();
24859- pgd_populate(&init_mm, pgd, pud);
24860+ pgd_populate_kernel(&init_mm, pgd, pud);
24861 if (pud != pud_offset(pgd, 0))
24862 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
24863 pud, pud_offset(pgd, 0));
24864@@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
24865 {
24866 if (pud_none(*pud)) {
24867 pmd_t *pmd = (pmd_t *) spp_getpage();
24868- pud_populate(&init_mm, pud, pmd);
24869+ pud_populate_kernel(&init_mm, pud, pmd);
24870 if (pmd != pmd_offset(pud, 0))
24871 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
24872 pmd, pmd_offset(pud, 0));
24873@@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
24874 pmd = fill_pmd(pud, vaddr);
24875 pte = fill_pte(pmd, vaddr);
24876
24877+ pax_open_kernel();
24878 set_pte(pte, new_pte);
24879+ pax_close_kernel();
24880
24881 /*
24882 * It's enough to flush this one mapping.
24883@@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
24884 pgd = pgd_offset_k((unsigned long)__va(phys));
24885 if (pgd_none(*pgd)) {
24886 pud = (pud_t *) spp_getpage();
24887- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
24888- _PAGE_USER));
24889+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
24890 }
24891 pud = pud_offset(pgd, (unsigned long)__va(phys));
24892 if (pud_none(*pud)) {
24893 pmd = (pmd_t *) spp_getpage();
24894- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
24895- _PAGE_USER));
24896+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
24897 }
24898 pmd = pmd_offset(pud, phys);
24899 BUG_ON(!pmd_none(*pmd));
24900@@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
24901 if (pfn >= pgt_buf_top)
24902 panic("alloc_low_page: ran out of memory");
24903
24904- adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24905+ adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24906 clear_page(adr);
24907 *phys = pfn * PAGE_SIZE;
24908 return adr;
24909@@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
24910
24911 phys = __pa(virt);
24912 left = phys & (PAGE_SIZE - 1);
24913- adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24914+ adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24915 adr = (void *)(((unsigned long)adr) | left);
24916
24917 return adr;
24918@@ -548,7 +562,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
24919 unmap_low_page(pmd);
24920
24921 spin_lock(&init_mm.page_table_lock);
24922- pud_populate(&init_mm, pud, __va(pmd_phys));
24923+ pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
24924 spin_unlock(&init_mm.page_table_lock);
24925 }
24926 __flush_tlb_all();
24927@@ -594,7 +608,7 @@ kernel_physical_mapping_init(unsigned long start,
24928 unmap_low_page(pud);
24929
24930 spin_lock(&init_mm.page_table_lock);
24931- pgd_populate(&init_mm, pgd, __va(pud_phys));
24932+ pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
24933 spin_unlock(&init_mm.page_table_lock);
24934 pgd_changed = true;
24935 }
24936@@ -686,6 +700,12 @@ void __init mem_init(void)
24937
24938 pci_iommu_alloc();
24939
24940+#ifdef CONFIG_PAX_PER_CPU_PGD
24941+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24942+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24943+ KERNEL_PGD_PTRS);
24944+#endif
24945+
24946 /* clear_bss() already clear the empty_zero_page */
24947
24948 reservedpages = 0;
24949@@ -846,8 +866,8 @@ int kern_addr_valid(unsigned long addr)
24950 static struct vm_area_struct gate_vma = {
24951 .vm_start = VSYSCALL_START,
24952 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
24953- .vm_page_prot = PAGE_READONLY_EXEC,
24954- .vm_flags = VM_READ | VM_EXEC
24955+ .vm_page_prot = PAGE_READONLY,
24956+ .vm_flags = VM_READ
24957 };
24958
24959 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
24960@@ -881,7 +901,7 @@ int in_gate_area_no_mm(unsigned long addr)
24961
24962 const char *arch_vma_name(struct vm_area_struct *vma)
24963 {
24964- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
24965+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
24966 return "[vdso]";
24967 if (vma == &gate_vma)
24968 return "[vsyscall]";
24969diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
24970index 7b179b4..6bd1777 100644
24971--- a/arch/x86/mm/iomap_32.c
24972+++ b/arch/x86/mm/iomap_32.c
24973@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
24974 type = kmap_atomic_idx_push();
24975 idx = type + KM_TYPE_NR * smp_processor_id();
24976 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24977+
24978+ pax_open_kernel();
24979 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
24980+ pax_close_kernel();
24981+
24982 arch_flush_lazy_mmu_mode();
24983
24984 return (void *)vaddr;
24985diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
24986index 78fe3f1..8293b6f 100644
24987--- a/arch/x86/mm/ioremap.c
24988+++ b/arch/x86/mm/ioremap.c
24989@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
24990 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
24991 int is_ram = page_is_ram(pfn);
24992
24993- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
24994+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
24995 return NULL;
24996 WARN_ON_ONCE(is_ram);
24997 }
24998@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
24999
25000 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25001 if (page_is_ram(start >> PAGE_SHIFT))
25002+#ifdef CONFIG_HIGHMEM
25003+ if ((start >> PAGE_SHIFT) < max_low_pfn)
25004+#endif
25005 return __va(phys);
25006
25007 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25008@@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25009 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25010
25011 static __initdata int after_paging_init;
25012-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25013+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25014
25015 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25016 {
25017@@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25018 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25019
25020 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25021- memset(bm_pte, 0, sizeof(bm_pte));
25022- pmd_populate_kernel(&init_mm, pmd, bm_pte);
25023+ pmd_populate_user(&init_mm, pmd, bm_pte);
25024
25025 /*
25026 * The boot-ioremap range spans multiple pmds, for which
25027diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25028index d87dd6d..bf3fa66 100644
25029--- a/arch/x86/mm/kmemcheck/kmemcheck.c
25030+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25031@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25032 * memory (e.g. tracked pages)? For now, we need this to avoid
25033 * invoking kmemcheck for PnP BIOS calls.
25034 */
25035- if (regs->flags & X86_VM_MASK)
25036+ if (v8086_mode(regs))
25037 return false;
25038- if (regs->cs != __KERNEL_CS)
25039+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25040 return false;
25041
25042 pte = kmemcheck_pte_lookup(address);
25043diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25044index 845df68..1d8d29f 100644
25045--- a/arch/x86/mm/mmap.c
25046+++ b/arch/x86/mm/mmap.c
25047@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25048 * Leave an at least ~128 MB hole with possible stack randomization.
25049 */
25050 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25051-#define MAX_GAP (TASK_SIZE/6*5)
25052+#define MAX_GAP (pax_task_size/6*5)
25053
25054 static int mmap_is_legacy(void)
25055 {
25056@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25057 return rnd << PAGE_SHIFT;
25058 }
25059
25060-static unsigned long mmap_base(void)
25061+static unsigned long mmap_base(struct mm_struct *mm)
25062 {
25063 unsigned long gap = rlimit(RLIMIT_STACK);
25064+ unsigned long pax_task_size = TASK_SIZE;
25065+
25066+#ifdef CONFIG_PAX_SEGMEXEC
25067+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25068+ pax_task_size = SEGMEXEC_TASK_SIZE;
25069+#endif
25070
25071 if (gap < MIN_GAP)
25072 gap = MIN_GAP;
25073 else if (gap > MAX_GAP)
25074 gap = MAX_GAP;
25075
25076- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25077+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25078 }
25079
25080 /*
25081 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25082 * does, but not when emulating X86_32
25083 */
25084-static unsigned long mmap_legacy_base(void)
25085+static unsigned long mmap_legacy_base(struct mm_struct *mm)
25086 {
25087- if (mmap_is_ia32())
25088+ if (mmap_is_ia32()) {
25089+
25090+#ifdef CONFIG_PAX_SEGMEXEC
25091+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25092+ return SEGMEXEC_TASK_UNMAPPED_BASE;
25093+ else
25094+#endif
25095+
25096 return TASK_UNMAPPED_BASE;
25097- else
25098+ } else
25099 return TASK_UNMAPPED_BASE + mmap_rnd();
25100 }
25101
25102@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25103 void arch_pick_mmap_layout(struct mm_struct *mm)
25104 {
25105 if (mmap_is_legacy()) {
25106- mm->mmap_base = mmap_legacy_base();
25107+ mm->mmap_base = mmap_legacy_base(mm);
25108+
25109+#ifdef CONFIG_PAX_RANDMMAP
25110+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25111+ mm->mmap_base += mm->delta_mmap;
25112+#endif
25113+
25114 mm->get_unmapped_area = arch_get_unmapped_area;
25115 mm->unmap_area = arch_unmap_area;
25116 } else {
25117- mm->mmap_base = mmap_base();
25118+ mm->mmap_base = mmap_base(mm);
25119+
25120+#ifdef CONFIG_PAX_RANDMMAP
25121+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25122+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25123+#endif
25124+
25125 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25126 mm->unmap_area = arch_unmap_area_topdown;
25127 }
25128diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25129index dc0b727..dc9d71a 100644
25130--- a/arch/x86/mm/mmio-mod.c
25131+++ b/arch/x86/mm/mmio-mod.c
25132@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25133 break;
25134 default:
25135 {
25136- unsigned char *ip = (unsigned char *)instptr;
25137+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25138 my_trace->opcode = MMIO_UNKNOWN_OP;
25139 my_trace->width = 0;
25140 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25141@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25142 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25143 void __iomem *addr)
25144 {
25145- static atomic_t next_id;
25146+ static atomic_unchecked_t next_id;
25147 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25148 /* These are page-unaligned. */
25149 struct mmiotrace_map map = {
25150@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25151 .private = trace
25152 },
25153 .phys = offset,
25154- .id = atomic_inc_return(&next_id)
25155+ .id = atomic_inc_return_unchecked(&next_id)
25156 };
25157 map.map_id = trace->id;
25158
25159diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25160index b008656..773eac2 100644
25161--- a/arch/x86/mm/pageattr-test.c
25162+++ b/arch/x86/mm/pageattr-test.c
25163@@ -36,7 +36,7 @@ enum {
25164
25165 static int pte_testbit(pte_t pte)
25166 {
25167- return pte_flags(pte) & _PAGE_UNUSED1;
25168+ return pte_flags(pte) & _PAGE_CPA_TEST;
25169 }
25170
25171 struct split_state {
25172diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25173index a718e0d..45efc32 100644
25174--- a/arch/x86/mm/pageattr.c
25175+++ b/arch/x86/mm/pageattr.c
25176@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25177 */
25178 #ifdef CONFIG_PCI_BIOS
25179 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25180- pgprot_val(forbidden) |= _PAGE_NX;
25181+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25182 #endif
25183
25184 /*
25185@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25186 * Does not cover __inittext since that is gone later on. On
25187 * 64bit we do not enforce !NX on the low mapping
25188 */
25189- if (within(address, (unsigned long)_text, (unsigned long)_etext))
25190- pgprot_val(forbidden) |= _PAGE_NX;
25191+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25192+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25193
25194+#ifdef CONFIG_DEBUG_RODATA
25195 /*
25196 * The .rodata section needs to be read-only. Using the pfn
25197 * catches all aliases.
25198@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25199 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25200 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25201 pgprot_val(forbidden) |= _PAGE_RW;
25202+#endif
25203
25204 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25205 /*
25206@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25207 }
25208 #endif
25209
25210+#ifdef CONFIG_PAX_KERNEXEC
25211+ if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25212+ pgprot_val(forbidden) |= _PAGE_RW;
25213+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25214+ }
25215+#endif
25216+
25217 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25218
25219 return prot;
25220@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25221 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25222 {
25223 /* change init_mm */
25224+ pax_open_kernel();
25225 set_pte_atomic(kpte, pte);
25226+
25227 #ifdef CONFIG_X86_32
25228 if (!SHARED_KERNEL_PMD) {
25229+
25230+#ifdef CONFIG_PAX_PER_CPU_PGD
25231+ unsigned long cpu;
25232+#else
25233 struct page *page;
25234+#endif
25235
25236+#ifdef CONFIG_PAX_PER_CPU_PGD
25237+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25238+ pgd_t *pgd = get_cpu_pgd(cpu);
25239+#else
25240 list_for_each_entry(page, &pgd_list, lru) {
25241- pgd_t *pgd;
25242+ pgd_t *pgd = (pgd_t *)page_address(page);
25243+#endif
25244+
25245 pud_t *pud;
25246 pmd_t *pmd;
25247
25248- pgd = (pgd_t *)page_address(page) + pgd_index(address);
25249+ pgd += pgd_index(address);
25250 pud = pud_offset(pgd, address);
25251 pmd = pmd_offset(pud, address);
25252 set_pte_atomic((pte_t *)pmd, pte);
25253 }
25254 }
25255 #endif
25256+ pax_close_kernel();
25257 }
25258
25259 static int
25260diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25261index 3d68ef6..7f69136 100644
25262--- a/arch/x86/mm/pat.c
25263+++ b/arch/x86/mm/pat.c
25264@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
25265
25266 if (!entry) {
25267 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
25268- current->comm, current->pid, start, end - 1);
25269+ current->comm, task_pid_nr(current), start, end - 1);
25270 return -EINVAL;
25271 }
25272
25273@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25274
25275 while (cursor < to) {
25276 if (!devmem_is_allowed(pfn)) {
25277- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
25278- current->comm, from, to - 1);
25279+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
25280+ current->comm, from, to - 1, cursor);
25281 return 0;
25282 }
25283 cursor += PAGE_SIZE;
25284@@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25285 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
25286 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
25287 "for [mem %#010Lx-%#010Lx]\n",
25288- current->comm, current->pid,
25289+ current->comm, task_pid_nr(current),
25290 cattr_name(flags),
25291 base, (unsigned long long)(base + size-1));
25292 return -EINVAL;
25293@@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25294 flags = lookup_memtype(paddr);
25295 if (want_flags != flags) {
25296 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
25297- current->comm, current->pid,
25298+ current->comm, task_pid_nr(current),
25299 cattr_name(want_flags),
25300 (unsigned long long)paddr,
25301 (unsigned long long)(paddr + size - 1),
25302@@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25303 free_memtype(paddr, paddr + size);
25304 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25305 " for [mem %#010Lx-%#010Lx], got %s\n",
25306- current->comm, current->pid,
25307+ current->comm, task_pid_nr(current),
25308 cattr_name(want_flags),
25309 (unsigned long long)paddr,
25310 (unsigned long long)(paddr + size - 1),
25311diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25312index 9f0614d..92ae64a 100644
25313--- a/arch/x86/mm/pf_in.c
25314+++ b/arch/x86/mm/pf_in.c
25315@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25316 int i;
25317 enum reason_type rv = OTHERS;
25318
25319- p = (unsigned char *)ins_addr;
25320+ p = (unsigned char *)ktla_ktva(ins_addr);
25321 p += skip_prefix(p, &prf);
25322 p += get_opcode(p, &opcode);
25323
25324@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25325 struct prefix_bits prf;
25326 int i;
25327
25328- p = (unsigned char *)ins_addr;
25329+ p = (unsigned char *)ktla_ktva(ins_addr);
25330 p += skip_prefix(p, &prf);
25331 p += get_opcode(p, &opcode);
25332
25333@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25334 struct prefix_bits prf;
25335 int i;
25336
25337- p = (unsigned char *)ins_addr;
25338+ p = (unsigned char *)ktla_ktva(ins_addr);
25339 p += skip_prefix(p, &prf);
25340 p += get_opcode(p, &opcode);
25341
25342@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25343 struct prefix_bits prf;
25344 int i;
25345
25346- p = (unsigned char *)ins_addr;
25347+ p = (unsigned char *)ktla_ktva(ins_addr);
25348 p += skip_prefix(p, &prf);
25349 p += get_opcode(p, &opcode);
25350 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25351@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25352 struct prefix_bits prf;
25353 int i;
25354
25355- p = (unsigned char *)ins_addr;
25356+ p = (unsigned char *)ktla_ktva(ins_addr);
25357 p += skip_prefix(p, &prf);
25358 p += get_opcode(p, &opcode);
25359 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25360diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25361index 8573b83..4f3ed7e 100644
25362--- a/arch/x86/mm/pgtable.c
25363+++ b/arch/x86/mm/pgtable.c
25364@@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25365 list_del(&page->lru);
25366 }
25367
25368-#define UNSHARED_PTRS_PER_PGD \
25369- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25370+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25371+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25372
25373+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25374+{
25375+ unsigned int count = USER_PGD_PTRS;
25376
25377+ while (count--)
25378+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25379+}
25380+#endif
25381+
25382+#ifdef CONFIG_PAX_PER_CPU_PGD
25383+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25384+{
25385+ unsigned int count = USER_PGD_PTRS;
25386+
25387+ while (count--) {
25388+ pgd_t pgd;
25389+
25390+#ifdef CONFIG_X86_64
25391+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25392+#else
25393+ pgd = *src++;
25394+#endif
25395+
25396+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25397+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25398+#endif
25399+
25400+ *dst++ = pgd;
25401+ }
25402+
25403+}
25404+#endif
25405+
25406+#ifdef CONFIG_X86_64
25407+#define pxd_t pud_t
25408+#define pyd_t pgd_t
25409+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25410+#define pxd_free(mm, pud) pud_free((mm), (pud))
25411+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25412+#define pyd_offset(mm, address) pgd_offset((mm), (address))
25413+#define PYD_SIZE PGDIR_SIZE
25414+#else
25415+#define pxd_t pmd_t
25416+#define pyd_t pud_t
25417+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25418+#define pxd_free(mm, pud) pmd_free((mm), (pud))
25419+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25420+#define pyd_offset(mm, address) pud_offset((mm), (address))
25421+#define PYD_SIZE PUD_SIZE
25422+#endif
25423+
25424+#ifdef CONFIG_PAX_PER_CPU_PGD
25425+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25426+static inline void pgd_dtor(pgd_t *pgd) {}
25427+#else
25428 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25429 {
25430 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25431@@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25432 pgd_list_del(pgd);
25433 spin_unlock(&pgd_lock);
25434 }
25435+#endif
25436
25437 /*
25438 * List of all pgd's needed for non-PAE so it can invalidate entries
25439@@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25440 * -- wli
25441 */
25442
25443-#ifdef CONFIG_X86_PAE
25444+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25445 /*
25446 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25447 * updating the top-level pagetable entries to guarantee the
25448@@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25449 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25450 * and initialize the kernel pmds here.
25451 */
25452-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25453+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25454
25455 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25456 {
25457@@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25458 */
25459 flush_tlb_mm(mm);
25460 }
25461+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25462+#define PREALLOCATED_PXDS USER_PGD_PTRS
25463 #else /* !CONFIG_X86_PAE */
25464
25465 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25466-#define PREALLOCATED_PMDS 0
25467+#define PREALLOCATED_PXDS 0
25468
25469 #endif /* CONFIG_X86_PAE */
25470
25471-static void free_pmds(pmd_t *pmds[])
25472+static void free_pxds(pxd_t *pxds[])
25473 {
25474 int i;
25475
25476- for(i = 0; i < PREALLOCATED_PMDS; i++)
25477- if (pmds[i])
25478- free_page((unsigned long)pmds[i]);
25479+ for(i = 0; i < PREALLOCATED_PXDS; i++)
25480+ if (pxds[i])
25481+ free_page((unsigned long)pxds[i]);
25482 }
25483
25484-static int preallocate_pmds(pmd_t *pmds[])
25485+static int preallocate_pxds(pxd_t *pxds[])
25486 {
25487 int i;
25488 bool failed = false;
25489
25490- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25491- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25492- if (pmd == NULL)
25493+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25494+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25495+ if (pxd == NULL)
25496 failed = true;
25497- pmds[i] = pmd;
25498+ pxds[i] = pxd;
25499 }
25500
25501 if (failed) {
25502- free_pmds(pmds);
25503+ free_pxds(pxds);
25504 return -ENOMEM;
25505 }
25506
25507@@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25508 * preallocate which never got a corresponding vma will need to be
25509 * freed manually.
25510 */
25511-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25512+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25513 {
25514 int i;
25515
25516- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25517+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25518 pgd_t pgd = pgdp[i];
25519
25520 if (pgd_val(pgd) != 0) {
25521- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25522+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25523
25524- pgdp[i] = native_make_pgd(0);
25525+ set_pgd(pgdp + i, native_make_pgd(0));
25526
25527- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25528- pmd_free(mm, pmd);
25529+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25530+ pxd_free(mm, pxd);
25531 }
25532 }
25533 }
25534
25535-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25536+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25537 {
25538- pud_t *pud;
25539+ pyd_t *pyd;
25540 unsigned long addr;
25541 int i;
25542
25543- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25544+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25545 return;
25546
25547- pud = pud_offset(pgd, 0);
25548+#ifdef CONFIG_X86_64
25549+ pyd = pyd_offset(mm, 0L);
25550+#else
25551+ pyd = pyd_offset(pgd, 0L);
25552+#endif
25553
25554- for (addr = i = 0; i < PREALLOCATED_PMDS;
25555- i++, pud++, addr += PUD_SIZE) {
25556- pmd_t *pmd = pmds[i];
25557+ for (addr = i = 0; i < PREALLOCATED_PXDS;
25558+ i++, pyd++, addr += PYD_SIZE) {
25559+ pxd_t *pxd = pxds[i];
25560
25561 if (i >= KERNEL_PGD_BOUNDARY)
25562- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25563- sizeof(pmd_t) * PTRS_PER_PMD);
25564+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25565+ sizeof(pxd_t) * PTRS_PER_PMD);
25566
25567- pud_populate(mm, pud, pmd);
25568+ pyd_populate(mm, pyd, pxd);
25569 }
25570 }
25571
25572 pgd_t *pgd_alloc(struct mm_struct *mm)
25573 {
25574 pgd_t *pgd;
25575- pmd_t *pmds[PREALLOCATED_PMDS];
25576+ pxd_t *pxds[PREALLOCATED_PXDS];
25577
25578 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25579
25580@@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25581
25582 mm->pgd = pgd;
25583
25584- if (preallocate_pmds(pmds) != 0)
25585+ if (preallocate_pxds(pxds) != 0)
25586 goto out_free_pgd;
25587
25588 if (paravirt_pgd_alloc(mm) != 0)
25589- goto out_free_pmds;
25590+ goto out_free_pxds;
25591
25592 /*
25593 * Make sure that pre-populating the pmds is atomic with
25594@@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25595 spin_lock(&pgd_lock);
25596
25597 pgd_ctor(mm, pgd);
25598- pgd_prepopulate_pmd(mm, pgd, pmds);
25599+ pgd_prepopulate_pxd(mm, pgd, pxds);
25600
25601 spin_unlock(&pgd_lock);
25602
25603 return pgd;
25604
25605-out_free_pmds:
25606- free_pmds(pmds);
25607+out_free_pxds:
25608+ free_pxds(pxds);
25609 out_free_pgd:
25610 free_page((unsigned long)pgd);
25611 out:
25612@@ -295,7 +356,7 @@ out:
25613
25614 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25615 {
25616- pgd_mop_up_pmds(mm, pgd);
25617+ pgd_mop_up_pxds(mm, pgd);
25618 pgd_dtor(pgd);
25619 paravirt_pgd_free(mm, pgd);
25620 free_page((unsigned long)pgd);
25621diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25622index a69bcb8..19068ab 100644
25623--- a/arch/x86/mm/pgtable_32.c
25624+++ b/arch/x86/mm/pgtable_32.c
25625@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25626 return;
25627 }
25628 pte = pte_offset_kernel(pmd, vaddr);
25629+
25630+ pax_open_kernel();
25631 if (pte_val(pteval))
25632 set_pte_at(&init_mm, vaddr, pte, pteval);
25633 else
25634 pte_clear(&init_mm, vaddr, pte);
25635+ pax_close_kernel();
25636
25637 /*
25638 * It's enough to flush this one mapping.
25639diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25640index 410531d..0f16030 100644
25641--- a/arch/x86/mm/setup_nx.c
25642+++ b/arch/x86/mm/setup_nx.c
25643@@ -5,8 +5,10 @@
25644 #include <asm/pgtable.h>
25645 #include <asm/proto.h>
25646
25647+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25648 static int disable_nx __cpuinitdata;
25649
25650+#ifndef CONFIG_PAX_PAGEEXEC
25651 /*
25652 * noexec = on|off
25653 *
25654@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25655 return 0;
25656 }
25657 early_param("noexec", noexec_setup);
25658+#endif
25659+
25660+#endif
25661
25662 void __cpuinit x86_configure_nx(void)
25663 {
25664+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25665 if (cpu_has_nx && !disable_nx)
25666 __supported_pte_mask |= _PAGE_NX;
25667 else
25668+#endif
25669 __supported_pte_mask &= ~_PAGE_NX;
25670 }
25671
25672diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25673index 5e57e11..64874249 100644
25674--- a/arch/x86/mm/tlb.c
25675+++ b/arch/x86/mm/tlb.c
25676@@ -66,7 +66,11 @@ void leave_mm(int cpu)
25677 BUG();
25678 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
25679 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
25680+
25681+#ifndef CONFIG_PAX_PER_CPU_PGD
25682 load_cr3(swapper_pg_dir);
25683+#endif
25684+
25685 }
25686 }
25687 EXPORT_SYMBOL_GPL(leave_mm);
25688diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25689index 877b9a1..a8ecf42 100644
25690--- a/arch/x86/net/bpf_jit.S
25691+++ b/arch/x86/net/bpf_jit.S
25692@@ -9,6 +9,7 @@
25693 */
25694 #include <linux/linkage.h>
25695 #include <asm/dwarf2.h>
25696+#include <asm/alternative-asm.h>
25697
25698 /*
25699 * Calling convention :
25700@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
25701 jle bpf_slow_path_word
25702 mov (SKBDATA,%rsi),%eax
25703 bswap %eax /* ntohl() */
25704+ pax_force_retaddr
25705 ret
25706
25707 sk_load_half:
25708@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
25709 jle bpf_slow_path_half
25710 movzwl (SKBDATA,%rsi),%eax
25711 rol $8,%ax # ntohs()
25712+ pax_force_retaddr
25713 ret
25714
25715 sk_load_byte:
25716@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
25717 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25718 jle bpf_slow_path_byte
25719 movzbl (SKBDATA,%rsi),%eax
25720+ pax_force_retaddr
25721 ret
25722
25723 /**
25724@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
25725 movzbl (SKBDATA,%rsi),%ebx
25726 and $15,%bl
25727 shl $2,%bl
25728+ pax_force_retaddr
25729 ret
25730
25731 /* rsi contains offset and can be scratched */
25732@@ -109,6 +114,7 @@ bpf_slow_path_word:
25733 js bpf_error
25734 mov -12(%rbp),%eax
25735 bswap %eax
25736+ pax_force_retaddr
25737 ret
25738
25739 bpf_slow_path_half:
25740@@ -117,12 +123,14 @@ bpf_slow_path_half:
25741 mov -12(%rbp),%ax
25742 rol $8,%ax
25743 movzwl %ax,%eax
25744+ pax_force_retaddr
25745 ret
25746
25747 bpf_slow_path_byte:
25748 bpf_slow_path_common(1)
25749 js bpf_error
25750 movzbl -12(%rbp),%eax
25751+ pax_force_retaddr
25752 ret
25753
25754 bpf_slow_path_byte_msh:
25755@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
25756 and $15,%al
25757 shl $2,%al
25758 xchg %eax,%ebx
25759+ pax_force_retaddr
25760 ret
25761
25762 #define sk_negative_common(SIZE) \
25763@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
25764 sk_negative_common(4)
25765 mov (%rax), %eax
25766 bswap %eax
25767+ pax_force_retaddr
25768 ret
25769
25770 bpf_slow_path_half_neg:
25771@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
25772 mov (%rax),%ax
25773 rol $8,%ax
25774 movzwl %ax,%eax
25775+ pax_force_retaddr
25776 ret
25777
25778 bpf_slow_path_byte_neg:
25779@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
25780 .globl sk_load_byte_negative_offset
25781 sk_negative_common(1)
25782 movzbl (%rax), %eax
25783+ pax_force_retaddr
25784 ret
25785
25786 bpf_slow_path_byte_msh_neg:
25787@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
25788 and $15,%al
25789 shl $2,%al
25790 xchg %eax,%ebx
25791+ pax_force_retaddr
25792 ret
25793
25794 bpf_error:
25795@@ -197,4 +210,5 @@ bpf_error:
25796 xor %eax,%eax
25797 mov -8(%rbp),%rbx
25798 leaveq
25799+ pax_force_retaddr
25800 ret
25801diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
25802index 0597f95..a12c36e 100644
25803--- a/arch/x86/net/bpf_jit_comp.c
25804+++ b/arch/x86/net/bpf_jit_comp.c
25805@@ -120,6 +120,11 @@ static inline void bpf_flush_icache(void *start, void *end)
25806 set_fs(old_fs);
25807 }
25808
25809+struct bpf_jit_work {
25810+ struct work_struct work;
25811+ void *image;
25812+};
25813+
25814 #define CHOOSE_LOAD_FUNC(K, func) \
25815 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
25816
25817@@ -146,6 +151,10 @@ void bpf_jit_compile(struct sk_filter *fp)
25818 if (addrs == NULL)
25819 return;
25820
25821+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
25822+ if (!fp->work)
25823+ goto out;
25824+
25825 /* Before first pass, make a rough estimation of addrs[]
25826 * each bpf instruction is translated to less than 64 bytes
25827 */
25828@@ -589,17 +598,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25829 break;
25830 default:
25831 /* hmm, too complex filter, give up with jit compiler */
25832- goto out;
25833+ goto error;
25834 }
25835 ilen = prog - temp;
25836 if (image) {
25837 if (unlikely(proglen + ilen > oldproglen)) {
25838 pr_err("bpb_jit_compile fatal error\n");
25839- kfree(addrs);
25840- module_free(NULL, image);
25841- return;
25842+ module_free_exec(NULL, image);
25843+ goto error;
25844 }
25845+ pax_open_kernel();
25846 memcpy(image + proglen, temp, ilen);
25847+ pax_close_kernel();
25848 }
25849 proglen += ilen;
25850 addrs[i] = proglen;
25851@@ -620,11 +630,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25852 break;
25853 }
25854 if (proglen == oldproglen) {
25855- image = module_alloc(max_t(unsigned int,
25856- proglen,
25857- sizeof(struct work_struct)));
25858+ image = module_alloc_exec(proglen);
25859 if (!image)
25860- goto out;
25861+ goto error;
25862 }
25863 oldproglen = proglen;
25864 }
25865@@ -640,7 +648,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25866 bpf_flush_icache(image, image + proglen);
25867
25868 fp->bpf_func = (void *)image;
25869- }
25870+ } else
25871+error:
25872+ kfree(fp->work);
25873+
25874 out:
25875 kfree(addrs);
25876 return;
25877@@ -648,18 +659,20 @@ out:
25878
25879 static void jit_free_defer(struct work_struct *arg)
25880 {
25881- module_free(NULL, arg);
25882+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
25883+ kfree(arg);
25884 }
25885
25886 /* run from softirq, we must use a work_struct to call
25887- * module_free() from process context
25888+ * module_free_exec() from process context
25889 */
25890 void bpf_jit_free(struct sk_filter *fp)
25891 {
25892 if (fp->bpf_func != sk_run_filter) {
25893- struct work_struct *work = (struct work_struct *)fp->bpf_func;
25894+ struct work_struct *work = &fp->work->work;
25895
25896 INIT_WORK(work, jit_free_defer);
25897+ fp->work->image = fp->bpf_func;
25898 schedule_work(work);
25899 }
25900 }
25901diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
25902index d6aa6e8..266395a 100644
25903--- a/arch/x86/oprofile/backtrace.c
25904+++ b/arch/x86/oprofile/backtrace.c
25905@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
25906 struct stack_frame_ia32 *fp;
25907 unsigned long bytes;
25908
25909- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25910+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25911 if (bytes != sizeof(bufhead))
25912 return NULL;
25913
25914- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
25915+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
25916
25917 oprofile_add_trace(bufhead[0].return_address);
25918
25919@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
25920 struct stack_frame bufhead[2];
25921 unsigned long bytes;
25922
25923- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25924+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25925 if (bytes != sizeof(bufhead))
25926 return NULL;
25927
25928@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
25929 {
25930 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
25931
25932- if (!user_mode_vm(regs)) {
25933+ if (!user_mode(regs)) {
25934 unsigned long stack = kernel_stack_pointer(regs);
25935 if (depth)
25936 dump_trace(NULL, regs, (unsigned long *)stack, 0,
25937diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
25938index 140942f..8a5cc55 100644
25939--- a/arch/x86/pci/mrst.c
25940+++ b/arch/x86/pci/mrst.c
25941@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
25942 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
25943 pci_mmcfg_late_init();
25944 pcibios_enable_irq = mrst_pci_irq_enable;
25945- pci_root_ops = pci_mrst_ops;
25946+ pax_open_kernel();
25947+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
25948+ pax_close_kernel();
25949 pci_soc_mode = 1;
25950 /* Continue with standard init */
25951 return 1;
25952diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
25953index da8fe05..7ee6704 100644
25954--- a/arch/x86/pci/pcbios.c
25955+++ b/arch/x86/pci/pcbios.c
25956@@ -79,50 +79,93 @@ union bios32 {
25957 static struct {
25958 unsigned long address;
25959 unsigned short segment;
25960-} bios32_indirect = { 0, __KERNEL_CS };
25961+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
25962
25963 /*
25964 * Returns the entry point for the given service, NULL on error
25965 */
25966
25967-static unsigned long bios32_service(unsigned long service)
25968+static unsigned long __devinit bios32_service(unsigned long service)
25969 {
25970 unsigned char return_code; /* %al */
25971 unsigned long address; /* %ebx */
25972 unsigned long length; /* %ecx */
25973 unsigned long entry; /* %edx */
25974 unsigned long flags;
25975+ struct desc_struct d, *gdt;
25976
25977 local_irq_save(flags);
25978- __asm__("lcall *(%%edi); cld"
25979+
25980+ gdt = get_cpu_gdt_table(smp_processor_id());
25981+
25982+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
25983+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
25984+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
25985+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
25986+
25987+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
25988 : "=a" (return_code),
25989 "=b" (address),
25990 "=c" (length),
25991 "=d" (entry)
25992 : "0" (service),
25993 "1" (0),
25994- "D" (&bios32_indirect));
25995+ "D" (&bios32_indirect),
25996+ "r"(__PCIBIOS_DS)
25997+ : "memory");
25998+
25999+ pax_open_kernel();
26000+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26001+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26002+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26003+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26004+ pax_close_kernel();
26005+
26006 local_irq_restore(flags);
26007
26008 switch (return_code) {
26009- case 0:
26010- return address + entry;
26011- case 0x80: /* Not present */
26012- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26013- return 0;
26014- default: /* Shouldn't happen */
26015- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26016- service, return_code);
26017+ case 0: {
26018+ int cpu;
26019+ unsigned char flags;
26020+
26021+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26022+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26023+ printk(KERN_WARNING "bios32_service: not valid\n");
26024 return 0;
26025+ }
26026+ address = address + PAGE_OFFSET;
26027+ length += 16UL; /* some BIOSs underreport this... */
26028+ flags = 4;
26029+ if (length >= 64*1024*1024) {
26030+ length >>= PAGE_SHIFT;
26031+ flags |= 8;
26032+ }
26033+
26034+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26035+ gdt = get_cpu_gdt_table(cpu);
26036+ pack_descriptor(&d, address, length, 0x9b, flags);
26037+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26038+ pack_descriptor(&d, address, length, 0x93, flags);
26039+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26040+ }
26041+ return entry;
26042+ }
26043+ case 0x80: /* Not present */
26044+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26045+ return 0;
26046+ default: /* Shouldn't happen */
26047+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26048+ service, return_code);
26049+ return 0;
26050 }
26051 }
26052
26053 static struct {
26054 unsigned long address;
26055 unsigned short segment;
26056-} pci_indirect = { 0, __KERNEL_CS };
26057+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26058
26059-static int pci_bios_present;
26060+static int pci_bios_present __read_only;
26061
26062 static int __devinit check_pcibios(void)
26063 {
26064@@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26065 unsigned long flags, pcibios_entry;
26066
26067 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26068- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26069+ pci_indirect.address = pcibios_entry;
26070
26071 local_irq_save(flags);
26072- __asm__(
26073- "lcall *(%%edi); cld\n\t"
26074+ __asm__("movw %w6, %%ds\n\t"
26075+ "lcall *%%ss:(%%edi); cld\n\t"
26076+ "push %%ss\n\t"
26077+ "pop %%ds\n\t"
26078 "jc 1f\n\t"
26079 "xor %%ah, %%ah\n"
26080 "1:"
26081@@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26082 "=b" (ebx),
26083 "=c" (ecx)
26084 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26085- "D" (&pci_indirect)
26086+ "D" (&pci_indirect),
26087+ "r" (__PCIBIOS_DS)
26088 : "memory");
26089 local_irq_restore(flags);
26090
26091@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26092
26093 switch (len) {
26094 case 1:
26095- __asm__("lcall *(%%esi); cld\n\t"
26096+ __asm__("movw %w6, %%ds\n\t"
26097+ "lcall *%%ss:(%%esi); cld\n\t"
26098+ "push %%ss\n\t"
26099+ "pop %%ds\n\t"
26100 "jc 1f\n\t"
26101 "xor %%ah, %%ah\n"
26102 "1:"
26103@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26104 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26105 "b" (bx),
26106 "D" ((long)reg),
26107- "S" (&pci_indirect));
26108+ "S" (&pci_indirect),
26109+ "r" (__PCIBIOS_DS));
26110 /*
26111 * Zero-extend the result beyond 8 bits, do not trust the
26112 * BIOS having done it:
26113@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26114 *value &= 0xff;
26115 break;
26116 case 2:
26117- __asm__("lcall *(%%esi); cld\n\t"
26118+ __asm__("movw %w6, %%ds\n\t"
26119+ "lcall *%%ss:(%%esi); cld\n\t"
26120+ "push %%ss\n\t"
26121+ "pop %%ds\n\t"
26122 "jc 1f\n\t"
26123 "xor %%ah, %%ah\n"
26124 "1:"
26125@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26126 : "1" (PCIBIOS_READ_CONFIG_WORD),
26127 "b" (bx),
26128 "D" ((long)reg),
26129- "S" (&pci_indirect));
26130+ "S" (&pci_indirect),
26131+ "r" (__PCIBIOS_DS));
26132 /*
26133 * Zero-extend the result beyond 16 bits, do not trust the
26134 * BIOS having done it:
26135@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26136 *value &= 0xffff;
26137 break;
26138 case 4:
26139- __asm__("lcall *(%%esi); cld\n\t"
26140+ __asm__("movw %w6, %%ds\n\t"
26141+ "lcall *%%ss:(%%esi); cld\n\t"
26142+ "push %%ss\n\t"
26143+ "pop %%ds\n\t"
26144 "jc 1f\n\t"
26145 "xor %%ah, %%ah\n"
26146 "1:"
26147@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26148 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26149 "b" (bx),
26150 "D" ((long)reg),
26151- "S" (&pci_indirect));
26152+ "S" (&pci_indirect),
26153+ "r" (__PCIBIOS_DS));
26154 break;
26155 }
26156
26157@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26158
26159 switch (len) {
26160 case 1:
26161- __asm__("lcall *(%%esi); cld\n\t"
26162+ __asm__("movw %w6, %%ds\n\t"
26163+ "lcall *%%ss:(%%esi); cld\n\t"
26164+ "push %%ss\n\t"
26165+ "pop %%ds\n\t"
26166 "jc 1f\n\t"
26167 "xor %%ah, %%ah\n"
26168 "1:"
26169@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26170 "c" (value),
26171 "b" (bx),
26172 "D" ((long)reg),
26173- "S" (&pci_indirect));
26174+ "S" (&pci_indirect),
26175+ "r" (__PCIBIOS_DS));
26176 break;
26177 case 2:
26178- __asm__("lcall *(%%esi); cld\n\t"
26179+ __asm__("movw %w6, %%ds\n\t"
26180+ "lcall *%%ss:(%%esi); cld\n\t"
26181+ "push %%ss\n\t"
26182+ "pop %%ds\n\t"
26183 "jc 1f\n\t"
26184 "xor %%ah, %%ah\n"
26185 "1:"
26186@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26187 "c" (value),
26188 "b" (bx),
26189 "D" ((long)reg),
26190- "S" (&pci_indirect));
26191+ "S" (&pci_indirect),
26192+ "r" (__PCIBIOS_DS));
26193 break;
26194 case 4:
26195- __asm__("lcall *(%%esi); cld\n\t"
26196+ __asm__("movw %w6, %%ds\n\t"
26197+ "lcall *%%ss:(%%esi); cld\n\t"
26198+ "push %%ss\n\t"
26199+ "pop %%ds\n\t"
26200 "jc 1f\n\t"
26201 "xor %%ah, %%ah\n"
26202 "1:"
26203@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26204 "c" (value),
26205 "b" (bx),
26206 "D" ((long)reg),
26207- "S" (&pci_indirect));
26208+ "S" (&pci_indirect),
26209+ "r" (__PCIBIOS_DS));
26210 break;
26211 }
26212
26213@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26214
26215 DBG("PCI: Fetching IRQ routing table... ");
26216 __asm__("push %%es\n\t"
26217+ "movw %w8, %%ds\n\t"
26218 "push %%ds\n\t"
26219 "pop %%es\n\t"
26220- "lcall *(%%esi); cld\n\t"
26221+ "lcall *%%ss:(%%esi); cld\n\t"
26222 "pop %%es\n\t"
26223+ "push %%ss\n\t"
26224+ "pop %%ds\n"
26225 "jc 1f\n\t"
26226 "xor %%ah, %%ah\n"
26227 "1:"
26228@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26229 "1" (0),
26230 "D" ((long) &opt),
26231 "S" (&pci_indirect),
26232- "m" (opt)
26233+ "m" (opt),
26234+ "r" (__PCIBIOS_DS)
26235 : "memory");
26236 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26237 if (ret & 0xff00)
26238@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26239 {
26240 int ret;
26241
26242- __asm__("lcall *(%%esi); cld\n\t"
26243+ __asm__("movw %w5, %%ds\n\t"
26244+ "lcall *%%ss:(%%esi); cld\n\t"
26245+ "push %%ss\n\t"
26246+ "pop %%ds\n"
26247 "jc 1f\n\t"
26248 "xor %%ah, %%ah\n"
26249 "1:"
26250@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26251 : "0" (PCIBIOS_SET_PCI_HW_INT),
26252 "b" ((dev->bus->number << 8) | dev->devfn),
26253 "c" ((irq << 8) | (pin + 10)),
26254- "S" (&pci_indirect));
26255+ "S" (&pci_indirect),
26256+ "r" (__PCIBIOS_DS));
26257 return !(ret & 0xff00);
26258 }
26259 EXPORT_SYMBOL(pcibios_set_irq_routing);
26260diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26261index 40e4469..1ab536e 100644
26262--- a/arch/x86/platform/efi/efi_32.c
26263+++ b/arch/x86/platform/efi/efi_32.c
26264@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26265 {
26266 struct desc_ptr gdt_descr;
26267
26268+#ifdef CONFIG_PAX_KERNEXEC
26269+ struct desc_struct d;
26270+#endif
26271+
26272 local_irq_save(efi_rt_eflags);
26273
26274 load_cr3(initial_page_table);
26275 __flush_tlb_all();
26276
26277+#ifdef CONFIG_PAX_KERNEXEC
26278+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26279+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26280+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26281+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26282+#endif
26283+
26284 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26285 gdt_descr.size = GDT_SIZE - 1;
26286 load_gdt(&gdt_descr);
26287@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26288 {
26289 struct desc_ptr gdt_descr;
26290
26291+#ifdef CONFIG_PAX_KERNEXEC
26292+ struct desc_struct d;
26293+
26294+ memset(&d, 0, sizeof d);
26295+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26296+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26297+#endif
26298+
26299 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26300 gdt_descr.size = GDT_SIZE - 1;
26301 load_gdt(&gdt_descr);
26302diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26303index fbe66e6..eae5e38 100644
26304--- a/arch/x86/platform/efi/efi_stub_32.S
26305+++ b/arch/x86/platform/efi/efi_stub_32.S
26306@@ -6,7 +6,9 @@
26307 */
26308
26309 #include <linux/linkage.h>
26310+#include <linux/init.h>
26311 #include <asm/page_types.h>
26312+#include <asm/segment.h>
26313
26314 /*
26315 * efi_call_phys(void *, ...) is a function with variable parameters.
26316@@ -20,7 +22,7 @@
26317 * service functions will comply with gcc calling convention, too.
26318 */
26319
26320-.text
26321+__INIT
26322 ENTRY(efi_call_phys)
26323 /*
26324 * 0. The function can only be called in Linux kernel. So CS has been
26325@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
26326 * The mapping of lower virtual memory has been created in prelog and
26327 * epilog.
26328 */
26329- movl $1f, %edx
26330- subl $__PAGE_OFFSET, %edx
26331- jmp *%edx
26332+#ifdef CONFIG_PAX_KERNEXEC
26333+ movl $(__KERNEXEC_EFI_DS), %edx
26334+ mov %edx, %ds
26335+ mov %edx, %es
26336+ mov %edx, %ss
26337+ addl $2f,(1f)
26338+ ljmp *(1f)
26339+
26340+__INITDATA
26341+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
26342+.previous
26343+
26344+2:
26345+ subl $2b,(1b)
26346+#else
26347+ jmp 1f-__PAGE_OFFSET
26348 1:
26349+#endif
26350
26351 /*
26352 * 2. Now on the top of stack is the return
26353@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
26354 * parameter 2, ..., param n. To make things easy, we save the return
26355 * address of efi_call_phys in a global variable.
26356 */
26357- popl %edx
26358- movl %edx, saved_return_addr
26359- /* get the function pointer into ECX*/
26360- popl %ecx
26361- movl %ecx, efi_rt_function_ptr
26362- movl $2f, %edx
26363- subl $__PAGE_OFFSET, %edx
26364- pushl %edx
26365+ popl (saved_return_addr)
26366+ popl (efi_rt_function_ptr)
26367
26368 /*
26369 * 3. Clear PG bit in %CR0.
26370@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
26371 /*
26372 * 5. Call the physical function.
26373 */
26374- jmp *%ecx
26375+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
26376
26377-2:
26378 /*
26379 * 6. After EFI runtime service returns, control will return to
26380 * following instruction. We'd better readjust stack pointer first.
26381@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
26382 movl %cr0, %edx
26383 orl $0x80000000, %edx
26384 movl %edx, %cr0
26385- jmp 1f
26386-1:
26387+
26388 /*
26389 * 8. Now restore the virtual mode from flat mode by
26390 * adding EIP with PAGE_OFFSET.
26391 */
26392- movl $1f, %edx
26393- jmp *%edx
26394+#ifdef CONFIG_PAX_KERNEXEC
26395+ movl $(__KERNEL_DS), %edx
26396+ mov %edx, %ds
26397+ mov %edx, %es
26398+ mov %edx, %ss
26399+ ljmp $(__KERNEL_CS),$1f
26400+#else
26401+ jmp 1f+__PAGE_OFFSET
26402+#endif
26403 1:
26404
26405 /*
26406 * 9. Balance the stack. And because EAX contain the return value,
26407 * we'd better not clobber it.
26408 */
26409- leal efi_rt_function_ptr, %edx
26410- movl (%edx), %ecx
26411- pushl %ecx
26412+ pushl (efi_rt_function_ptr)
26413
26414 /*
26415- * 10. Push the saved return address onto the stack and return.
26416+ * 10. Return to the saved return address.
26417 */
26418- leal saved_return_addr, %edx
26419- movl (%edx), %ecx
26420- pushl %ecx
26421- ret
26422+ jmpl *(saved_return_addr)
26423 ENDPROC(efi_call_phys)
26424 .previous
26425
26426-.data
26427+__INITDATA
26428 saved_return_addr:
26429 .long 0
26430 efi_rt_function_ptr:
26431diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26432index 4c07cca..2c8427d 100644
26433--- a/arch/x86/platform/efi/efi_stub_64.S
26434+++ b/arch/x86/platform/efi/efi_stub_64.S
26435@@ -7,6 +7,7 @@
26436 */
26437
26438 #include <linux/linkage.h>
26439+#include <asm/alternative-asm.h>
26440
26441 #define SAVE_XMM \
26442 mov %rsp, %rax; \
26443@@ -40,6 +41,7 @@ ENTRY(efi_call0)
26444 call *%rdi
26445 addq $32, %rsp
26446 RESTORE_XMM
26447+ pax_force_retaddr 0, 1
26448 ret
26449 ENDPROC(efi_call0)
26450
26451@@ -50,6 +52,7 @@ ENTRY(efi_call1)
26452 call *%rdi
26453 addq $32, %rsp
26454 RESTORE_XMM
26455+ pax_force_retaddr 0, 1
26456 ret
26457 ENDPROC(efi_call1)
26458
26459@@ -60,6 +63,7 @@ ENTRY(efi_call2)
26460 call *%rdi
26461 addq $32, %rsp
26462 RESTORE_XMM
26463+ pax_force_retaddr 0, 1
26464 ret
26465 ENDPROC(efi_call2)
26466
26467@@ -71,6 +75,7 @@ ENTRY(efi_call3)
26468 call *%rdi
26469 addq $32, %rsp
26470 RESTORE_XMM
26471+ pax_force_retaddr 0, 1
26472 ret
26473 ENDPROC(efi_call3)
26474
26475@@ -83,6 +88,7 @@ ENTRY(efi_call4)
26476 call *%rdi
26477 addq $32, %rsp
26478 RESTORE_XMM
26479+ pax_force_retaddr 0, 1
26480 ret
26481 ENDPROC(efi_call4)
26482
26483@@ -96,6 +102,7 @@ ENTRY(efi_call5)
26484 call *%rdi
26485 addq $48, %rsp
26486 RESTORE_XMM
26487+ pax_force_retaddr 0, 1
26488 ret
26489 ENDPROC(efi_call5)
26490
26491@@ -112,5 +119,6 @@ ENTRY(efi_call6)
26492 call *%rdi
26493 addq $48, %rsp
26494 RESTORE_XMM
26495+ pax_force_retaddr 0, 1
26496 ret
26497 ENDPROC(efi_call6)
26498diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26499index fd41a92..9c33628 100644
26500--- a/arch/x86/platform/mrst/mrst.c
26501+++ b/arch/x86/platform/mrst/mrst.c
26502@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26503 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26504 int sfi_mrtc_num;
26505
26506-static void mrst_power_off(void)
26507+static __noreturn void mrst_power_off(void)
26508 {
26509+ BUG();
26510 }
26511
26512-static void mrst_reboot(void)
26513+static __noreturn void mrst_reboot(void)
26514 {
26515 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26516+ BUG();
26517 }
26518
26519 /* parse all the mtimer info to a static mtimer array */
26520diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26521index 218cdb1..fd55c08 100644
26522--- a/arch/x86/power/cpu.c
26523+++ b/arch/x86/power/cpu.c
26524@@ -132,7 +132,7 @@ static void do_fpu_end(void)
26525 static void fix_processor_context(void)
26526 {
26527 int cpu = smp_processor_id();
26528- struct tss_struct *t = &per_cpu(init_tss, cpu);
26529+ struct tss_struct *t = init_tss + cpu;
26530
26531 set_tss_desc(cpu, t); /*
26532 * This just modifies memory; should not be
26533@@ -142,7 +142,9 @@ static void fix_processor_context(void)
26534 */
26535
26536 #ifdef CONFIG_X86_64
26537+ pax_open_kernel();
26538 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26539+ pax_close_kernel();
26540
26541 syscall_init(); /* This sets MSR_*STAR and related */
26542 #endif
26543diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
26544index cbca565..35ce1d7 100644
26545--- a/arch/x86/realmode/init.c
26546+++ b/arch/x86/realmode/init.c
26547@@ -62,7 +62,13 @@ void __init setup_real_mode(void)
26548 __va(real_mode_header->trampoline_header);
26549
26550 #ifdef CONFIG_X86_32
26551- trampoline_header->start = __pa(startup_32_smp);
26552+ trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
26553+
26554+#ifdef CONFIG_PAX_KERNEXEC
26555+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
26556+#endif
26557+
26558+ trampoline_header->boot_cs = __BOOT_CS;
26559 trampoline_header->gdt_limit = __BOOT_DS + 7;
26560 trampoline_header->gdt_base = __pa(boot_gdt);
26561 #else
26562diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
26563index 5b84a2d..a004393 100644
26564--- a/arch/x86/realmode/rm/Makefile
26565+++ b/arch/x86/realmode/rm/Makefile
26566@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
26567 $(call cc-option, -fno-unit-at-a-time)) \
26568 $(call cc-option, -fno-stack-protector) \
26569 $(call cc-option, -mpreferred-stack-boundary=2)
26570+ifdef CONSTIFY_PLUGIN
26571+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
26572+endif
26573 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
26574 GCOV_PROFILE := n
26575diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
26576index c1b2791..f9e31c7 100644
26577--- a/arch/x86/realmode/rm/trampoline_32.S
26578+++ b/arch/x86/realmode/rm/trampoline_32.S
26579@@ -25,6 +25,12 @@
26580 #include <asm/page_types.h>
26581 #include "realmode.h"
26582
26583+#ifdef CONFIG_PAX_KERNEXEC
26584+#define ta(X) (X)
26585+#else
26586+#define ta(X) (pa_ ## X)
26587+#endif
26588+
26589 .text
26590 .code16
26591
26592@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
26593
26594 cli # We should be safe anyway
26595
26596- movl tr_start, %eax # where we need to go
26597-
26598 movl $0xA5A5A5A5, trampoline_status
26599 # write marker for master knows we're running
26600
26601@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
26602 movw $1, %dx # protected mode (PE) bit
26603 lmsw %dx # into protected mode
26604
26605- ljmpl $__BOOT_CS, $pa_startup_32
26606+ ljmpl *(trampoline_header)
26607
26608 .section ".text32","ax"
26609 .code32
26610@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
26611 .balign 8
26612 GLOBAL(trampoline_header)
26613 tr_start: .space 4
26614- tr_gdt_pad: .space 2
26615+ tr_boot_cs: .space 2
26616 tr_gdt: .space 6
26617 END(trampoline_header)
26618
26619diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
26620index bb360dc..3e5945f 100644
26621--- a/arch/x86/realmode/rm/trampoline_64.S
26622+++ b/arch/x86/realmode/rm/trampoline_64.S
26623@@ -107,7 +107,7 @@ ENTRY(startup_32)
26624 wrmsr
26625
26626 # Enable paging and in turn activate Long Mode
26627- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
26628+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
26629 movl %eax, %cr0
26630
26631 /*
26632diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
26633index 5a1847d..deccb30 100644
26634--- a/arch/x86/tools/relocs.c
26635+++ b/arch/x86/tools/relocs.c
26636@@ -12,10 +12,13 @@
26637 #include <regex.h>
26638 #include <tools/le_byteshift.h>
26639
26640+#include "../../../include/generated/autoconf.h"
26641+
26642 static void die(char *fmt, ...);
26643
26644 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
26645 static Elf32_Ehdr ehdr;
26646+static Elf32_Phdr *phdr;
26647 static unsigned long reloc_count, reloc_idx;
26648 static unsigned long *relocs;
26649 static unsigned long reloc16_count, reloc16_idx;
26650@@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
26651 }
26652 }
26653
26654+static void read_phdrs(FILE *fp)
26655+{
26656+ unsigned int i;
26657+
26658+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
26659+ if (!phdr) {
26660+ die("Unable to allocate %d program headers\n",
26661+ ehdr.e_phnum);
26662+ }
26663+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
26664+ die("Seek to %d failed: %s\n",
26665+ ehdr.e_phoff, strerror(errno));
26666+ }
26667+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
26668+ die("Cannot read ELF program headers: %s\n",
26669+ strerror(errno));
26670+ }
26671+ for(i = 0; i < ehdr.e_phnum; i++) {
26672+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
26673+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
26674+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
26675+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
26676+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
26677+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
26678+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
26679+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
26680+ }
26681+
26682+}
26683+
26684 static void read_shdrs(FILE *fp)
26685 {
26686- int i;
26687+ unsigned int i;
26688 Elf32_Shdr shdr;
26689
26690 secs = calloc(ehdr.e_shnum, sizeof(struct section));
26691@@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
26692
26693 static void read_strtabs(FILE *fp)
26694 {
26695- int i;
26696+ unsigned int i;
26697 for (i = 0; i < ehdr.e_shnum; i++) {
26698 struct section *sec = &secs[i];
26699 if (sec->shdr.sh_type != SHT_STRTAB) {
26700@@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
26701
26702 static void read_symtabs(FILE *fp)
26703 {
26704- int i,j;
26705+ unsigned int i,j;
26706 for (i = 0; i < ehdr.e_shnum; i++) {
26707 struct section *sec = &secs[i];
26708 if (sec->shdr.sh_type != SHT_SYMTAB) {
26709@@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
26710 }
26711
26712
26713-static void read_relocs(FILE *fp)
26714+static void read_relocs(FILE *fp, int use_real_mode)
26715 {
26716- int i,j;
26717+ unsigned int i,j;
26718+ uint32_t base;
26719+
26720 for (i = 0; i < ehdr.e_shnum; i++) {
26721 struct section *sec = &secs[i];
26722 if (sec->shdr.sh_type != SHT_REL) {
26723@@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
26724 die("Cannot read symbol table: %s\n",
26725 strerror(errno));
26726 }
26727+ base = 0;
26728+
26729+#ifdef CONFIG_X86_32
26730+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
26731+ if (phdr[j].p_type != PT_LOAD )
26732+ continue;
26733+ 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)
26734+ continue;
26735+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
26736+ break;
26737+ }
26738+#endif
26739+
26740 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
26741 Elf32_Rel *rel = &sec->reltab[j];
26742- rel->r_offset = elf32_to_cpu(rel->r_offset);
26743+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
26744 rel->r_info = elf32_to_cpu(rel->r_info);
26745 }
26746 }
26747@@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
26748
26749 static void print_absolute_symbols(void)
26750 {
26751- int i;
26752+ unsigned int i;
26753 printf("Absolute symbols\n");
26754 printf(" Num: Value Size Type Bind Visibility Name\n");
26755 for (i = 0; i < ehdr.e_shnum; i++) {
26756 struct section *sec = &secs[i];
26757 char *sym_strtab;
26758- int j;
26759+ unsigned int j;
26760
26761 if (sec->shdr.sh_type != SHT_SYMTAB) {
26762 continue;
26763@@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
26764
26765 static void print_absolute_relocs(void)
26766 {
26767- int i, printed = 0;
26768+ unsigned int i, printed = 0;
26769
26770 for (i = 0; i < ehdr.e_shnum; i++) {
26771 struct section *sec = &secs[i];
26772 struct section *sec_applies, *sec_symtab;
26773 char *sym_strtab;
26774 Elf32_Sym *sh_symtab;
26775- int j;
26776+ unsigned int j;
26777 if (sec->shdr.sh_type != SHT_REL) {
26778 continue;
26779 }
26780@@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
26781 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26782 int use_real_mode)
26783 {
26784- int i;
26785+ unsigned int i;
26786 /* Walk through the relocations */
26787 for (i = 0; i < ehdr.e_shnum; i++) {
26788 char *sym_strtab;
26789 Elf32_Sym *sh_symtab;
26790 struct section *sec_applies, *sec_symtab;
26791- int j;
26792+ unsigned int j;
26793 struct section *sec = &secs[i];
26794
26795 if (sec->shdr.sh_type != SHT_REL) {
26796@@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26797 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
26798 r_type = ELF32_R_TYPE(rel->r_info);
26799
26800+ if (!use_real_mode) {
26801+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
26802+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
26803+ continue;
26804+
26805+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
26806+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
26807+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
26808+ continue;
26809+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
26810+ continue;
26811+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
26812+ continue;
26813+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
26814+ continue;
26815+#endif
26816+ }
26817+
26818 shn_abs = sym->st_shndx == SHN_ABS;
26819
26820 switch (r_type) {
26821@@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
26822
26823 static void emit_relocs(int as_text, int use_real_mode)
26824 {
26825- int i;
26826+ unsigned int i;
26827 /* Count how many relocations I have and allocate space for them. */
26828 reloc_count = 0;
26829 walk_relocs(count_reloc, use_real_mode);
26830@@ -808,10 +874,11 @@ int main(int argc, char **argv)
26831 fname, strerror(errno));
26832 }
26833 read_ehdr(fp);
26834+ read_phdrs(fp);
26835 read_shdrs(fp);
26836 read_strtabs(fp);
26837 read_symtabs(fp);
26838- read_relocs(fp);
26839+ read_relocs(fp, use_real_mode);
26840 if (show_absolute_syms) {
26841 print_absolute_symbols();
26842 return 0;
26843diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
26844index fd14be1..e3c79c0 100644
26845--- a/arch/x86/vdso/Makefile
26846+++ b/arch/x86/vdso/Makefile
26847@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
26848 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
26849 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
26850
26851-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26852+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26853 GCOV_PROFILE := n
26854
26855 #
26856diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
26857index 66e6d93..587f435 100644
26858--- a/arch/x86/vdso/vdso32-setup.c
26859+++ b/arch/x86/vdso/vdso32-setup.c
26860@@ -25,6 +25,7 @@
26861 #include <asm/tlbflush.h>
26862 #include <asm/vdso.h>
26863 #include <asm/proto.h>
26864+#include <asm/mman.h>
26865
26866 enum {
26867 VDSO_DISABLED = 0,
26868@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
26869 void enable_sep_cpu(void)
26870 {
26871 int cpu = get_cpu();
26872- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26873+ struct tss_struct *tss = init_tss + cpu;
26874
26875 if (!boot_cpu_has(X86_FEATURE_SEP)) {
26876 put_cpu();
26877@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
26878 gate_vma.vm_start = FIXADDR_USER_START;
26879 gate_vma.vm_end = FIXADDR_USER_END;
26880 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
26881- gate_vma.vm_page_prot = __P101;
26882+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
26883
26884 return 0;
26885 }
26886@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26887 if (compat)
26888 addr = VDSO_HIGH_BASE;
26889 else {
26890- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
26891+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
26892 if (IS_ERR_VALUE(addr)) {
26893 ret = addr;
26894 goto up_fail;
26895 }
26896 }
26897
26898- current->mm->context.vdso = (void *)addr;
26899+ current->mm->context.vdso = addr;
26900
26901 if (compat_uses_vma || !compat) {
26902 /*
26903@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26904 }
26905
26906 current_thread_info()->sysenter_return =
26907- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26908+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26909
26910 up_fail:
26911 if (ret)
26912- current->mm->context.vdso = NULL;
26913+ current->mm->context.vdso = 0;
26914
26915 up_write(&mm->mmap_sem);
26916
26917@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
26918
26919 const char *arch_vma_name(struct vm_area_struct *vma)
26920 {
26921- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26922+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26923 return "[vdso]";
26924+
26925+#ifdef CONFIG_PAX_SEGMEXEC
26926+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
26927+ return "[vdso]";
26928+#endif
26929+
26930 return NULL;
26931 }
26932
26933@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
26934 * Check to see if the corresponding task was created in compat vdso
26935 * mode.
26936 */
26937- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
26938+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
26939 return &gate_vma;
26940 return NULL;
26941 }
26942diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
26943index 00aaf04..4a26505 100644
26944--- a/arch/x86/vdso/vma.c
26945+++ b/arch/x86/vdso/vma.c
26946@@ -16,8 +16,6 @@
26947 #include <asm/vdso.h>
26948 #include <asm/page.h>
26949
26950-unsigned int __read_mostly vdso_enabled = 1;
26951-
26952 extern char vdso_start[], vdso_end[];
26953 extern unsigned short vdso_sync_cpuid;
26954
26955@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
26956 * unaligned here as a result of stack start randomization.
26957 */
26958 addr = PAGE_ALIGN(addr);
26959- addr = align_addr(addr, NULL, ALIGN_VDSO);
26960
26961 return addr;
26962 }
26963@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
26964 unsigned size)
26965 {
26966 struct mm_struct *mm = current->mm;
26967- unsigned long addr;
26968+ unsigned long addr = 0;
26969 int ret;
26970
26971- if (!vdso_enabled)
26972- return 0;
26973-
26974 down_write(&mm->mmap_sem);
26975+
26976+#ifdef CONFIG_PAX_RANDMMAP
26977+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26978+#endif
26979+
26980 addr = vdso_addr(mm->start_stack, size);
26981+ addr = align_addr(addr, NULL, ALIGN_VDSO);
26982 addr = get_unmapped_area(NULL, addr, size, 0, 0);
26983 if (IS_ERR_VALUE(addr)) {
26984 ret = addr;
26985 goto up_fail;
26986 }
26987
26988- current->mm->context.vdso = (void *)addr;
26989+ mm->context.vdso = addr;
26990
26991 ret = install_special_mapping(mm, addr, size,
26992 VM_READ|VM_EXEC|
26993 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
26994 pages);
26995- if (ret) {
26996- current->mm->context.vdso = NULL;
26997- goto up_fail;
26998- }
26999+ if (ret)
27000+ mm->context.vdso = 0;
27001
27002 up_fail:
27003 up_write(&mm->mmap_sem);
27004@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27005 vdsox32_size);
27006 }
27007 #endif
27008-
27009-static __init int vdso_setup(char *s)
27010-{
27011- vdso_enabled = simple_strtoul(s, NULL, 0);
27012- return 0;
27013-}
27014-__setup("vdso=", vdso_setup);
27015diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27016index ff962d4..2bb5e83 100644
27017--- a/arch/x86/xen/enlighten.c
27018+++ b/arch/x86/xen/enlighten.c
27019@@ -97,8 +97,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27020
27021 struct shared_info xen_dummy_shared_info;
27022
27023-void *xen_initial_gdt;
27024-
27025 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27026 __read_mostly int xen_have_vector_callback;
27027 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27028@@ -1175,30 +1173,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27029 #endif
27030 };
27031
27032-static void xen_reboot(int reason)
27033+static __noreturn void xen_reboot(int reason)
27034 {
27035 struct sched_shutdown r = { .reason = reason };
27036
27037- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27038- BUG();
27039+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27040+ BUG();
27041 }
27042
27043-static void xen_restart(char *msg)
27044+static __noreturn void xen_restart(char *msg)
27045 {
27046 xen_reboot(SHUTDOWN_reboot);
27047 }
27048
27049-static void xen_emergency_restart(void)
27050+static __noreturn void xen_emergency_restart(void)
27051 {
27052 xen_reboot(SHUTDOWN_reboot);
27053 }
27054
27055-static void xen_machine_halt(void)
27056+static __noreturn void xen_machine_halt(void)
27057 {
27058 xen_reboot(SHUTDOWN_poweroff);
27059 }
27060
27061-static void xen_machine_power_off(void)
27062+static __noreturn void xen_machine_power_off(void)
27063 {
27064 if (pm_power_off)
27065 pm_power_off();
27066@@ -1301,7 +1299,17 @@ asmlinkage void __init xen_start_kernel(void)
27067 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27068
27069 /* Work out if we support NX */
27070- x86_configure_nx();
27071+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27072+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27073+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27074+ unsigned l, h;
27075+
27076+ __supported_pte_mask |= _PAGE_NX;
27077+ rdmsr(MSR_EFER, l, h);
27078+ l |= EFER_NX;
27079+ wrmsr(MSR_EFER, l, h);
27080+ }
27081+#endif
27082
27083 xen_setup_features();
27084
27085@@ -1332,13 +1340,6 @@ asmlinkage void __init xen_start_kernel(void)
27086
27087 machine_ops = xen_machine_ops;
27088
27089- /*
27090- * The only reliable way to retain the initial address of the
27091- * percpu gdt_page is to remember it here, so we can go and
27092- * mark it RW later, when the initial percpu area is freed.
27093- */
27094- xen_initial_gdt = &per_cpu(gdt_page, 0);
27095-
27096 xen_smp_init();
27097
27098 #ifdef CONFIG_ACPI_NUMA
27099diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27100index 3a73785..0d30df2 100644
27101--- a/arch/x86/xen/mmu.c
27102+++ b/arch/x86/xen/mmu.c
27103@@ -1738,6 +1738,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27104 convert_pfn_mfn(init_level4_pgt);
27105 convert_pfn_mfn(level3_ident_pgt);
27106 convert_pfn_mfn(level3_kernel_pgt);
27107+ convert_pfn_mfn(level3_vmalloc_start_pgt);
27108+ convert_pfn_mfn(level3_vmalloc_end_pgt);
27109+ convert_pfn_mfn(level3_vmemmap_pgt);
27110
27111 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27112 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27113@@ -1756,7 +1759,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27114 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27115 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27116 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27117+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27118+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27119+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27120 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27121+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27122 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27123 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27124
27125@@ -1940,6 +1947,7 @@ static void __init xen_post_allocator_init(void)
27126 pv_mmu_ops.set_pud = xen_set_pud;
27127 #if PAGETABLE_LEVELS == 4
27128 pv_mmu_ops.set_pgd = xen_set_pgd;
27129+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27130 #endif
27131
27132 /* This will work as long as patching hasn't happened yet
27133@@ -2021,6 +2029,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27134 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27135 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27136 .set_pgd = xen_set_pgd_hyper,
27137+ .set_pgd_batched = xen_set_pgd_hyper,
27138
27139 .alloc_pud = xen_alloc_pmd_init,
27140 .release_pud = xen_release_pmd_init,
27141diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27142index afb250d..627075f 100644
27143--- a/arch/x86/xen/smp.c
27144+++ b/arch/x86/xen/smp.c
27145@@ -231,11 +231,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27146 {
27147 BUG_ON(smp_processor_id() != 0);
27148 native_smp_prepare_boot_cpu();
27149-
27150- /* We've switched to the "real" per-cpu gdt, so make sure the
27151- old memory can be recycled */
27152- make_lowmem_page_readwrite(xen_initial_gdt);
27153-
27154 xen_filter_cpu_maps();
27155 xen_setup_vcpu_info_placement();
27156 }
27157@@ -302,12 +297,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27158 gdt = get_cpu_gdt_table(cpu);
27159
27160 ctxt->flags = VGCF_IN_KERNEL;
27161- ctxt->user_regs.ds = __USER_DS;
27162- ctxt->user_regs.es = __USER_DS;
27163+ ctxt->user_regs.ds = __KERNEL_DS;
27164+ ctxt->user_regs.es = __KERNEL_DS;
27165 ctxt->user_regs.ss = __KERNEL_DS;
27166 #ifdef CONFIG_X86_32
27167 ctxt->user_regs.fs = __KERNEL_PERCPU;
27168- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27169+ savesegment(gs, ctxt->user_regs.gs);
27170 #else
27171 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27172 #endif
27173@@ -357,13 +352,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
27174 int rc;
27175
27176 per_cpu(current_task, cpu) = idle;
27177+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
27178 #ifdef CONFIG_X86_32
27179 irq_ctx_init(cpu);
27180 #else
27181 clear_tsk_thread_flag(idle, TIF_FORK);
27182- per_cpu(kernel_stack, cpu) =
27183- (unsigned long)task_stack_page(idle) -
27184- KERNEL_STACK_OFFSET + THREAD_SIZE;
27185+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27186 #endif
27187 xen_setup_runstate_info(cpu);
27188 xen_setup_timer(cpu);
27189diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27190index f9643fc..602e8af 100644
27191--- a/arch/x86/xen/xen-asm_32.S
27192+++ b/arch/x86/xen/xen-asm_32.S
27193@@ -84,14 +84,14 @@ ENTRY(xen_iret)
27194 ESP_OFFSET=4 # bytes pushed onto stack
27195
27196 /*
27197- * Store vcpu_info pointer for easy access. Do it this way to
27198- * avoid having to reload %fs
27199+ * Store vcpu_info pointer for easy access.
27200 */
27201 #ifdef CONFIG_SMP
27202- GET_THREAD_INFO(%eax)
27203- movl TI_cpu(%eax), %eax
27204- movl __per_cpu_offset(,%eax,4), %eax
27205- mov xen_vcpu(%eax), %eax
27206+ push %fs
27207+ mov $(__KERNEL_PERCPU), %eax
27208+ mov %eax, %fs
27209+ mov PER_CPU_VAR(xen_vcpu), %eax
27210+ pop %fs
27211 #else
27212 movl xen_vcpu, %eax
27213 #endif
27214diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27215index aaa7291..3f77960 100644
27216--- a/arch/x86/xen/xen-head.S
27217+++ b/arch/x86/xen/xen-head.S
27218@@ -19,6 +19,17 @@ ENTRY(startup_xen)
27219 #ifdef CONFIG_X86_32
27220 mov %esi,xen_start_info
27221 mov $init_thread_union+THREAD_SIZE,%esp
27222+#ifdef CONFIG_SMP
27223+ movl $cpu_gdt_table,%edi
27224+ movl $__per_cpu_load,%eax
27225+ movw %ax,__KERNEL_PERCPU + 2(%edi)
27226+ rorl $16,%eax
27227+ movb %al,__KERNEL_PERCPU + 4(%edi)
27228+ movb %ah,__KERNEL_PERCPU + 7(%edi)
27229+ movl $__per_cpu_end - 1,%eax
27230+ subl $__per_cpu_start,%eax
27231+ movw %ax,__KERNEL_PERCPU + 0(%edi)
27232+#endif
27233 #else
27234 mov %rsi,xen_start_info
27235 mov $init_thread_union+THREAD_SIZE,%rsp
27236diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27237index 202d4c1..99b072a 100644
27238--- a/arch/x86/xen/xen-ops.h
27239+++ b/arch/x86/xen/xen-ops.h
27240@@ -10,8 +10,6 @@
27241 extern const char xen_hypervisor_callback[];
27242 extern const char xen_failsafe_callback[];
27243
27244-extern void *xen_initial_gdt;
27245-
27246 struct trap_info;
27247 void xen_copy_trap_info(struct trap_info *traps);
27248
27249diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27250index 525bd3d..ef888b1 100644
27251--- a/arch/xtensa/variants/dc232b/include/variant/core.h
27252+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27253@@ -119,9 +119,9 @@
27254 ----------------------------------------------------------------------*/
27255
27256 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27257-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27258 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27259 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27260+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27261
27262 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27263 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27264diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27265index 2f33760..835e50a 100644
27266--- a/arch/xtensa/variants/fsf/include/variant/core.h
27267+++ b/arch/xtensa/variants/fsf/include/variant/core.h
27268@@ -11,6 +11,7 @@
27269 #ifndef _XTENSA_CORE_H
27270 #define _XTENSA_CORE_H
27271
27272+#include <linux/const.h>
27273
27274 /****************************************************************************
27275 Parameters Useful for Any Code, USER or PRIVILEGED
27276@@ -112,9 +113,9 @@
27277 ----------------------------------------------------------------------*/
27278
27279 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27280-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27281 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27282 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27283+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27284
27285 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27286 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27287diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27288index af00795..2bb8105 100644
27289--- a/arch/xtensa/variants/s6000/include/variant/core.h
27290+++ b/arch/xtensa/variants/s6000/include/variant/core.h
27291@@ -11,6 +11,7 @@
27292 #ifndef _XTENSA_CORE_CONFIGURATION_H
27293 #define _XTENSA_CORE_CONFIGURATION_H
27294
27295+#include <linux/const.h>
27296
27297 /****************************************************************************
27298 Parameters Useful for Any Code, USER or PRIVILEGED
27299@@ -118,9 +119,9 @@
27300 ----------------------------------------------------------------------*/
27301
27302 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27303-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27304 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27305 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27306+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27307
27308 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27309 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27310diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27311index 58916af..9cb880b 100644
27312--- a/block/blk-iopoll.c
27313+++ b/block/blk-iopoll.c
27314@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27315 }
27316 EXPORT_SYMBOL(blk_iopoll_complete);
27317
27318-static void blk_iopoll_softirq(struct softirq_action *h)
27319+static void blk_iopoll_softirq(void)
27320 {
27321 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27322 int rearm = 0, budget = blk_iopoll_budget;
27323diff --git a/block/blk-map.c b/block/blk-map.c
27324index 623e1cd..ca1e109 100644
27325--- a/block/blk-map.c
27326+++ b/block/blk-map.c
27327@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27328 if (!len || !kbuf)
27329 return -EINVAL;
27330
27331- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27332+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27333 if (do_copy)
27334 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27335 else
27336diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27337index 467c8de..4bddc6d 100644
27338--- a/block/blk-softirq.c
27339+++ b/block/blk-softirq.c
27340@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27341 * Softirq action handler - move entries to local list and loop over them
27342 * while passing them to the queue registered handler.
27343 */
27344-static void blk_done_softirq(struct softirq_action *h)
27345+static void blk_done_softirq(void)
27346 {
27347 struct list_head *cpu_list, local_list;
27348
27349diff --git a/block/bsg.c b/block/bsg.c
27350index ff64ae3..593560c 100644
27351--- a/block/bsg.c
27352+++ b/block/bsg.c
27353@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27354 struct sg_io_v4 *hdr, struct bsg_device *bd,
27355 fmode_t has_write_perm)
27356 {
27357+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27358+ unsigned char *cmdptr;
27359+
27360 if (hdr->request_len > BLK_MAX_CDB) {
27361 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27362 if (!rq->cmd)
27363 return -ENOMEM;
27364- }
27365+ cmdptr = rq->cmd;
27366+ } else
27367+ cmdptr = tmpcmd;
27368
27369- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27370+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27371 hdr->request_len))
27372 return -EFAULT;
27373
27374+ if (cmdptr != rq->cmd)
27375+ memcpy(rq->cmd, cmdptr, hdr->request_len);
27376+
27377 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27378 if (blk_verify_command(rq->cmd, has_write_perm))
27379 return -EPERM;
27380diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27381index 7c668c8..db3521c 100644
27382--- a/block/compat_ioctl.c
27383+++ b/block/compat_ioctl.c
27384@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27385 err |= __get_user(f->spec1, &uf->spec1);
27386 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27387 err |= __get_user(name, &uf->name);
27388- f->name = compat_ptr(name);
27389+ f->name = (void __force_kernel *)compat_ptr(name);
27390 if (err) {
27391 err = -EFAULT;
27392 goto out;
27393diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27394index 6296b40..417c00f 100644
27395--- a/block/partitions/efi.c
27396+++ b/block/partitions/efi.c
27397@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27398 if (!gpt)
27399 return NULL;
27400
27401+ if (!le32_to_cpu(gpt->num_partition_entries))
27402+ return NULL;
27403+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27404+ if (!pte)
27405+ return NULL;
27406+
27407 count = le32_to_cpu(gpt->num_partition_entries) *
27408 le32_to_cpu(gpt->sizeof_partition_entry);
27409- if (!count)
27410- return NULL;
27411- pte = kzalloc(count, GFP_KERNEL);
27412- if (!pte)
27413- return NULL;
27414-
27415 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27416 (u8 *) pte,
27417 count) < count) {
27418diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27419index 9a87daa..fb17486 100644
27420--- a/block/scsi_ioctl.c
27421+++ b/block/scsi_ioctl.c
27422@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27423 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27424 struct sg_io_hdr *hdr, fmode_t mode)
27425 {
27426- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27427+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27428+ unsigned char *cmdptr;
27429+
27430+ if (rq->cmd != rq->__cmd)
27431+ cmdptr = rq->cmd;
27432+ else
27433+ cmdptr = tmpcmd;
27434+
27435+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27436 return -EFAULT;
27437+
27438+ if (cmdptr != rq->cmd)
27439+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27440+
27441 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27442 return -EPERM;
27443
27444@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27445 int err;
27446 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27447 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27448+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27449+ unsigned char *cmdptr;
27450
27451 if (!sic)
27452 return -EINVAL;
27453@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27454 */
27455 err = -EFAULT;
27456 rq->cmd_len = cmdlen;
27457- if (copy_from_user(rq->cmd, sic->data, cmdlen))
27458+
27459+ if (rq->cmd != rq->__cmd)
27460+ cmdptr = rq->cmd;
27461+ else
27462+ cmdptr = tmpcmd;
27463+
27464+ if (copy_from_user(cmdptr, sic->data, cmdlen))
27465 goto error;
27466
27467+ if (rq->cmd != cmdptr)
27468+ memcpy(rq->cmd, cmdptr, cmdlen);
27469+
27470 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27471 goto error;
27472
27473diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27474index 671d4d6..5f24030 100644
27475--- a/crypto/cryptd.c
27476+++ b/crypto/cryptd.c
27477@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27478
27479 struct cryptd_blkcipher_request_ctx {
27480 crypto_completion_t complete;
27481-};
27482+} __no_const;
27483
27484 struct cryptd_hash_ctx {
27485 struct crypto_shash *child;
27486@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27487
27488 struct cryptd_aead_request_ctx {
27489 crypto_completion_t complete;
27490-};
27491+} __no_const;
27492
27493 static void cryptd_queue_worker(struct work_struct *work);
27494
27495diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27496index e6defd8..c26a225 100644
27497--- a/drivers/acpi/apei/cper.c
27498+++ b/drivers/acpi/apei/cper.c
27499@@ -38,12 +38,12 @@
27500 */
27501 u64 cper_next_record_id(void)
27502 {
27503- static atomic64_t seq;
27504+ static atomic64_unchecked_t seq;
27505
27506- if (!atomic64_read(&seq))
27507- atomic64_set(&seq, ((u64)get_seconds()) << 32);
27508+ if (!atomic64_read_unchecked(&seq))
27509+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27510
27511- return atomic64_inc_return(&seq);
27512+ return atomic64_inc_return_unchecked(&seq);
27513 }
27514 EXPORT_SYMBOL_GPL(cper_next_record_id);
27515
27516diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27517index 7586544..636a2f0 100644
27518--- a/drivers/acpi/ec_sys.c
27519+++ b/drivers/acpi/ec_sys.c
27520@@ -12,6 +12,7 @@
27521 #include <linux/acpi.h>
27522 #include <linux/debugfs.h>
27523 #include <linux/module.h>
27524+#include <linux/uaccess.h>
27525 #include "internal.h"
27526
27527 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27528@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27529 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27530 */
27531 unsigned int size = EC_SPACE_SIZE;
27532- u8 *data = (u8 *) buf;
27533+ u8 data;
27534 loff_t init_off = *off;
27535 int err = 0;
27536
27537@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27538 size = count;
27539
27540 while (size) {
27541- err = ec_read(*off, &data[*off - init_off]);
27542+ err = ec_read(*off, &data);
27543 if (err)
27544 return err;
27545+ if (put_user(data, &buf[*off - init_off]))
27546+ return -EFAULT;
27547 *off += 1;
27548 size--;
27549 }
27550@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27551
27552 unsigned int size = count;
27553 loff_t init_off = *off;
27554- u8 *data = (u8 *) buf;
27555 int err = 0;
27556
27557 if (*off >= EC_SPACE_SIZE)
27558@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27559 }
27560
27561 while (size) {
27562- u8 byte_write = data[*off - init_off];
27563+ u8 byte_write;
27564+ if (get_user(byte_write, &buf[*off - init_off]))
27565+ return -EFAULT;
27566 err = ec_write(*off, byte_write);
27567 if (err)
27568 return err;
27569diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27570index 251c7b62..000462d 100644
27571--- a/drivers/acpi/proc.c
27572+++ b/drivers/acpi/proc.c
27573@@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27574 size_t count, loff_t * ppos)
27575 {
27576 struct list_head *node, *next;
27577- char strbuf[5];
27578- char str[5] = "";
27579- unsigned int len = count;
27580+ char strbuf[5] = {0};
27581
27582- if (len > 4)
27583- len = 4;
27584- if (len < 0)
27585+ if (count > 4)
27586+ count = 4;
27587+ if (copy_from_user(strbuf, buffer, count))
27588 return -EFAULT;
27589-
27590- if (copy_from_user(strbuf, buffer, len))
27591- return -EFAULT;
27592- strbuf[len] = '\0';
27593- sscanf(strbuf, "%s", str);
27594+ strbuf[count] = '\0';
27595
27596 mutex_lock(&acpi_device_lock);
27597 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27598@@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27599 if (!dev->wakeup.flags.valid)
27600 continue;
27601
27602- if (!strncmp(dev->pnp.bus_id, str, 4)) {
27603+ if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27604 if (device_can_wakeup(&dev->dev)) {
27605 bool enable = !device_may_wakeup(&dev->dev);
27606 device_set_wakeup_enable(&dev->dev, enable);
27607diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27608index bbac51e..4c094f9 100644
27609--- a/drivers/acpi/processor_driver.c
27610+++ b/drivers/acpi/processor_driver.c
27611@@ -556,7 +556,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27612 return 0;
27613 #endif
27614
27615- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27616+ BUG_ON(pr->id >= nr_cpu_ids);
27617
27618 /*
27619 * Buggy BIOS check
27620diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27621index cece3a4..0845256 100644
27622--- a/drivers/ata/libata-core.c
27623+++ b/drivers/ata/libata-core.c
27624@@ -4743,7 +4743,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27625 struct ata_port *ap;
27626 unsigned int tag;
27627
27628- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27629+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27630 ap = qc->ap;
27631
27632 qc->flags = 0;
27633@@ -4759,7 +4759,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27634 struct ata_port *ap;
27635 struct ata_link *link;
27636
27637- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27638+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27639 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27640 ap = qc->ap;
27641 link = qc->dev->link;
27642@@ -5823,6 +5823,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27643 return;
27644
27645 spin_lock(&lock);
27646+ pax_open_kernel();
27647
27648 for (cur = ops->inherits; cur; cur = cur->inherits) {
27649 void **inherit = (void **)cur;
27650@@ -5836,8 +5837,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27651 if (IS_ERR(*pp))
27652 *pp = NULL;
27653
27654- ops->inherits = NULL;
27655+ *(struct ata_port_operations **)&ops->inherits = NULL;
27656
27657+ pax_close_kernel();
27658 spin_unlock(&lock);
27659 }
27660
27661diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27662index ac6a5be..c7176b1 100644
27663--- a/drivers/ata/pata_arasan_cf.c
27664+++ b/drivers/ata/pata_arasan_cf.c
27665@@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27666 /* Handle platform specific quirks */
27667 if (pdata->quirk) {
27668 if (pdata->quirk & CF_BROKEN_PIO) {
27669- ap->ops->set_piomode = NULL;
27670+ pax_open_kernel();
27671+ *(void **)&ap->ops->set_piomode = NULL;
27672+ pax_close_kernel();
27673 ap->pio_mask = 0;
27674 }
27675 if (pdata->quirk & CF_BROKEN_MWDMA)
27676diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27677index f9b983a..887b9d8 100644
27678--- a/drivers/atm/adummy.c
27679+++ b/drivers/atm/adummy.c
27680@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27681 vcc->pop(vcc, skb);
27682 else
27683 dev_kfree_skb_any(skb);
27684- atomic_inc(&vcc->stats->tx);
27685+ atomic_inc_unchecked(&vcc->stats->tx);
27686
27687 return 0;
27688 }
27689diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27690index 89b30f3..7964211 100644
27691--- a/drivers/atm/ambassador.c
27692+++ b/drivers/atm/ambassador.c
27693@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27694 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27695
27696 // VC layer stats
27697- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27698+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27699
27700 // free the descriptor
27701 kfree (tx_descr);
27702@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27703 dump_skb ("<<<", vc, skb);
27704
27705 // VC layer stats
27706- atomic_inc(&atm_vcc->stats->rx);
27707+ atomic_inc_unchecked(&atm_vcc->stats->rx);
27708 __net_timestamp(skb);
27709 // end of our responsibility
27710 atm_vcc->push (atm_vcc, skb);
27711@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27712 } else {
27713 PRINTK (KERN_INFO, "dropped over-size frame");
27714 // should we count this?
27715- atomic_inc(&atm_vcc->stats->rx_drop);
27716+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27717 }
27718
27719 } else {
27720@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
27721 }
27722
27723 if (check_area (skb->data, skb->len)) {
27724- atomic_inc(&atm_vcc->stats->tx_err);
27725+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
27726 return -ENOMEM; // ?
27727 }
27728
27729diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
27730index b22d71c..d6e1049 100644
27731--- a/drivers/atm/atmtcp.c
27732+++ b/drivers/atm/atmtcp.c
27733@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27734 if (vcc->pop) vcc->pop(vcc,skb);
27735 else dev_kfree_skb(skb);
27736 if (dev_data) return 0;
27737- atomic_inc(&vcc->stats->tx_err);
27738+ atomic_inc_unchecked(&vcc->stats->tx_err);
27739 return -ENOLINK;
27740 }
27741 size = skb->len+sizeof(struct atmtcp_hdr);
27742@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27743 if (!new_skb) {
27744 if (vcc->pop) vcc->pop(vcc,skb);
27745 else dev_kfree_skb(skb);
27746- atomic_inc(&vcc->stats->tx_err);
27747+ atomic_inc_unchecked(&vcc->stats->tx_err);
27748 return -ENOBUFS;
27749 }
27750 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
27751@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27752 if (vcc->pop) vcc->pop(vcc,skb);
27753 else dev_kfree_skb(skb);
27754 out_vcc->push(out_vcc,new_skb);
27755- atomic_inc(&vcc->stats->tx);
27756- atomic_inc(&out_vcc->stats->rx);
27757+ atomic_inc_unchecked(&vcc->stats->tx);
27758+ atomic_inc_unchecked(&out_vcc->stats->rx);
27759 return 0;
27760 }
27761
27762@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27763 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
27764 read_unlock(&vcc_sklist_lock);
27765 if (!out_vcc) {
27766- atomic_inc(&vcc->stats->tx_err);
27767+ atomic_inc_unchecked(&vcc->stats->tx_err);
27768 goto done;
27769 }
27770 skb_pull(skb,sizeof(struct atmtcp_hdr));
27771@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27772 __net_timestamp(new_skb);
27773 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
27774 out_vcc->push(out_vcc,new_skb);
27775- atomic_inc(&vcc->stats->tx);
27776- atomic_inc(&out_vcc->stats->rx);
27777+ atomic_inc_unchecked(&vcc->stats->tx);
27778+ atomic_inc_unchecked(&out_vcc->stats->rx);
27779 done:
27780 if (vcc->pop) vcc->pop(vcc,skb);
27781 else dev_kfree_skb(skb);
27782diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
27783index 2059ee4..faf51c7 100644
27784--- a/drivers/atm/eni.c
27785+++ b/drivers/atm/eni.c
27786@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
27787 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
27788 vcc->dev->number);
27789 length = 0;
27790- atomic_inc(&vcc->stats->rx_err);
27791+ atomic_inc_unchecked(&vcc->stats->rx_err);
27792 }
27793 else {
27794 length = ATM_CELL_SIZE-1; /* no HEC */
27795@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27796 size);
27797 }
27798 eff = length = 0;
27799- atomic_inc(&vcc->stats->rx_err);
27800+ atomic_inc_unchecked(&vcc->stats->rx_err);
27801 }
27802 else {
27803 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
27804@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27805 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
27806 vcc->dev->number,vcc->vci,length,size << 2,descr);
27807 length = eff = 0;
27808- atomic_inc(&vcc->stats->rx_err);
27809+ atomic_inc_unchecked(&vcc->stats->rx_err);
27810 }
27811 }
27812 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
27813@@ -767,7 +767,7 @@ rx_dequeued++;
27814 vcc->push(vcc,skb);
27815 pushed++;
27816 }
27817- atomic_inc(&vcc->stats->rx);
27818+ atomic_inc_unchecked(&vcc->stats->rx);
27819 }
27820 wake_up(&eni_dev->rx_wait);
27821 }
27822@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
27823 PCI_DMA_TODEVICE);
27824 if (vcc->pop) vcc->pop(vcc,skb);
27825 else dev_kfree_skb_irq(skb);
27826- atomic_inc(&vcc->stats->tx);
27827+ atomic_inc_unchecked(&vcc->stats->tx);
27828 wake_up(&eni_dev->tx_wait);
27829 dma_complete++;
27830 }
27831@@ -1567,7 +1567,7 @@ tx_complete++;
27832 /*--------------------------------- entries ---------------------------------*/
27833
27834
27835-static const char *media_name[] __devinitdata = {
27836+static const char *media_name[] __devinitconst = {
27837 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
27838 "UTP", "05?", "06?", "07?", /* 4- 7 */
27839 "TAXI","09?", "10?", "11?", /* 8-11 */
27840diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
27841index 86fed1b..6dc4721 100644
27842--- a/drivers/atm/firestream.c
27843+++ b/drivers/atm/firestream.c
27844@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
27845 }
27846 }
27847
27848- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27849+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27850
27851 fs_dprintk (FS_DEBUG_TXMEM, "i");
27852 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
27853@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27854 #endif
27855 skb_put (skb, qe->p1 & 0xffff);
27856 ATM_SKB(skb)->vcc = atm_vcc;
27857- atomic_inc(&atm_vcc->stats->rx);
27858+ atomic_inc_unchecked(&atm_vcc->stats->rx);
27859 __net_timestamp(skb);
27860 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
27861 atm_vcc->push (atm_vcc, skb);
27862@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27863 kfree (pe);
27864 }
27865 if (atm_vcc)
27866- atomic_inc(&atm_vcc->stats->rx_drop);
27867+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27868 break;
27869 case 0x1f: /* Reassembly abort: no buffers. */
27870 /* Silently increment error counter. */
27871 if (atm_vcc)
27872- atomic_inc(&atm_vcc->stats->rx_drop);
27873+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27874 break;
27875 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
27876 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
27877diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
27878index 361f5ae..7fc552d 100644
27879--- a/drivers/atm/fore200e.c
27880+++ b/drivers/atm/fore200e.c
27881@@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
27882 #endif
27883 /* check error condition */
27884 if (*entry->status & STATUS_ERROR)
27885- atomic_inc(&vcc->stats->tx_err);
27886+ atomic_inc_unchecked(&vcc->stats->tx_err);
27887 else
27888- atomic_inc(&vcc->stats->tx);
27889+ atomic_inc_unchecked(&vcc->stats->tx);
27890 }
27891 }
27892
27893@@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27894 if (skb == NULL) {
27895 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
27896
27897- atomic_inc(&vcc->stats->rx_drop);
27898+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27899 return -ENOMEM;
27900 }
27901
27902@@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27903
27904 dev_kfree_skb_any(skb);
27905
27906- atomic_inc(&vcc->stats->rx_drop);
27907+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27908 return -ENOMEM;
27909 }
27910
27911 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27912
27913 vcc->push(vcc, skb);
27914- atomic_inc(&vcc->stats->rx);
27915+ atomic_inc_unchecked(&vcc->stats->rx);
27916
27917 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27918
27919@@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
27920 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
27921 fore200e->atm_dev->number,
27922 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
27923- atomic_inc(&vcc->stats->rx_err);
27924+ atomic_inc_unchecked(&vcc->stats->rx_err);
27925 }
27926 }
27927
27928@@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
27929 goto retry_here;
27930 }
27931
27932- atomic_inc(&vcc->stats->tx_err);
27933+ atomic_inc_unchecked(&vcc->stats->tx_err);
27934
27935 fore200e->tx_sat++;
27936 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
27937diff --git a/drivers/atm/he.c b/drivers/atm/he.c
27938index b182c2f..1c6fa8a 100644
27939--- a/drivers/atm/he.c
27940+++ b/drivers/atm/he.c
27941@@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27942
27943 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
27944 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
27945- atomic_inc(&vcc->stats->rx_drop);
27946+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27947 goto return_host_buffers;
27948 }
27949
27950@@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27951 RBRQ_LEN_ERR(he_dev->rbrq_head)
27952 ? "LEN_ERR" : "",
27953 vcc->vpi, vcc->vci);
27954- atomic_inc(&vcc->stats->rx_err);
27955+ atomic_inc_unchecked(&vcc->stats->rx_err);
27956 goto return_host_buffers;
27957 }
27958
27959@@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27960 vcc->push(vcc, skb);
27961 spin_lock(&he_dev->global_lock);
27962
27963- atomic_inc(&vcc->stats->rx);
27964+ atomic_inc_unchecked(&vcc->stats->rx);
27965
27966 return_host_buffers:
27967 ++pdus_assembled;
27968@@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
27969 tpd->vcc->pop(tpd->vcc, tpd->skb);
27970 else
27971 dev_kfree_skb_any(tpd->skb);
27972- atomic_inc(&tpd->vcc->stats->tx_err);
27973+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
27974 }
27975 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
27976 return;
27977@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27978 vcc->pop(vcc, skb);
27979 else
27980 dev_kfree_skb_any(skb);
27981- atomic_inc(&vcc->stats->tx_err);
27982+ atomic_inc_unchecked(&vcc->stats->tx_err);
27983 return -EINVAL;
27984 }
27985
27986@@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27987 vcc->pop(vcc, skb);
27988 else
27989 dev_kfree_skb_any(skb);
27990- atomic_inc(&vcc->stats->tx_err);
27991+ atomic_inc_unchecked(&vcc->stats->tx_err);
27992 return -EINVAL;
27993 }
27994 #endif
27995@@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27996 vcc->pop(vcc, skb);
27997 else
27998 dev_kfree_skb_any(skb);
27999- atomic_inc(&vcc->stats->tx_err);
28000+ atomic_inc_unchecked(&vcc->stats->tx_err);
28001 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28002 return -ENOMEM;
28003 }
28004@@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28005 vcc->pop(vcc, skb);
28006 else
28007 dev_kfree_skb_any(skb);
28008- atomic_inc(&vcc->stats->tx_err);
28009+ atomic_inc_unchecked(&vcc->stats->tx_err);
28010 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28011 return -ENOMEM;
28012 }
28013@@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28014 __enqueue_tpd(he_dev, tpd, cid);
28015 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28016
28017- atomic_inc(&vcc->stats->tx);
28018+ atomic_inc_unchecked(&vcc->stats->tx);
28019
28020 return 0;
28021 }
28022diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28023index 7d01c2a..4e3ac01 100644
28024--- a/drivers/atm/horizon.c
28025+++ b/drivers/atm/horizon.c
28026@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28027 {
28028 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28029 // VC layer stats
28030- atomic_inc(&vcc->stats->rx);
28031+ atomic_inc_unchecked(&vcc->stats->rx);
28032 __net_timestamp(skb);
28033 // end of our responsibility
28034 vcc->push (vcc, skb);
28035@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28036 dev->tx_iovec = NULL;
28037
28038 // VC layer stats
28039- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28040+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28041
28042 // free the skb
28043 hrz_kfree_skb (skb);
28044diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28045index 8974bd2..b856f85 100644
28046--- a/drivers/atm/idt77252.c
28047+++ b/drivers/atm/idt77252.c
28048@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28049 else
28050 dev_kfree_skb(skb);
28051
28052- atomic_inc(&vcc->stats->tx);
28053+ atomic_inc_unchecked(&vcc->stats->tx);
28054 }
28055
28056 atomic_dec(&scq->used);
28057@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28058 if ((sb = dev_alloc_skb(64)) == NULL) {
28059 printk("%s: Can't allocate buffers for aal0.\n",
28060 card->name);
28061- atomic_add(i, &vcc->stats->rx_drop);
28062+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
28063 break;
28064 }
28065 if (!atm_charge(vcc, sb->truesize)) {
28066 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28067 card->name);
28068- atomic_add(i - 1, &vcc->stats->rx_drop);
28069+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28070 dev_kfree_skb(sb);
28071 break;
28072 }
28073@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28074 ATM_SKB(sb)->vcc = vcc;
28075 __net_timestamp(sb);
28076 vcc->push(vcc, sb);
28077- atomic_inc(&vcc->stats->rx);
28078+ atomic_inc_unchecked(&vcc->stats->rx);
28079
28080 cell += ATM_CELL_PAYLOAD;
28081 }
28082@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28083 "(CDC: %08x)\n",
28084 card->name, len, rpp->len, readl(SAR_REG_CDC));
28085 recycle_rx_pool_skb(card, rpp);
28086- atomic_inc(&vcc->stats->rx_err);
28087+ atomic_inc_unchecked(&vcc->stats->rx_err);
28088 return;
28089 }
28090 if (stat & SAR_RSQE_CRC) {
28091 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28092 recycle_rx_pool_skb(card, rpp);
28093- atomic_inc(&vcc->stats->rx_err);
28094+ atomic_inc_unchecked(&vcc->stats->rx_err);
28095 return;
28096 }
28097 if (skb_queue_len(&rpp->queue) > 1) {
28098@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28099 RXPRINTK("%s: Can't alloc RX skb.\n",
28100 card->name);
28101 recycle_rx_pool_skb(card, rpp);
28102- atomic_inc(&vcc->stats->rx_err);
28103+ atomic_inc_unchecked(&vcc->stats->rx_err);
28104 return;
28105 }
28106 if (!atm_charge(vcc, skb->truesize)) {
28107@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28108 __net_timestamp(skb);
28109
28110 vcc->push(vcc, skb);
28111- atomic_inc(&vcc->stats->rx);
28112+ atomic_inc_unchecked(&vcc->stats->rx);
28113
28114 return;
28115 }
28116@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28117 __net_timestamp(skb);
28118
28119 vcc->push(vcc, skb);
28120- atomic_inc(&vcc->stats->rx);
28121+ atomic_inc_unchecked(&vcc->stats->rx);
28122
28123 if (skb->truesize > SAR_FB_SIZE_3)
28124 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28125@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28126 if (vcc->qos.aal != ATM_AAL0) {
28127 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28128 card->name, vpi, vci);
28129- atomic_inc(&vcc->stats->rx_drop);
28130+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28131 goto drop;
28132 }
28133
28134 if ((sb = dev_alloc_skb(64)) == NULL) {
28135 printk("%s: Can't allocate buffers for AAL0.\n",
28136 card->name);
28137- atomic_inc(&vcc->stats->rx_err);
28138+ atomic_inc_unchecked(&vcc->stats->rx_err);
28139 goto drop;
28140 }
28141
28142@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28143 ATM_SKB(sb)->vcc = vcc;
28144 __net_timestamp(sb);
28145 vcc->push(vcc, sb);
28146- atomic_inc(&vcc->stats->rx);
28147+ atomic_inc_unchecked(&vcc->stats->rx);
28148
28149 drop:
28150 skb_pull(queue, 64);
28151@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28152
28153 if (vc == NULL) {
28154 printk("%s: NULL connection in send().\n", card->name);
28155- atomic_inc(&vcc->stats->tx_err);
28156+ atomic_inc_unchecked(&vcc->stats->tx_err);
28157 dev_kfree_skb(skb);
28158 return -EINVAL;
28159 }
28160 if (!test_bit(VCF_TX, &vc->flags)) {
28161 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28162- atomic_inc(&vcc->stats->tx_err);
28163+ atomic_inc_unchecked(&vcc->stats->tx_err);
28164 dev_kfree_skb(skb);
28165 return -EINVAL;
28166 }
28167@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28168 break;
28169 default:
28170 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28171- atomic_inc(&vcc->stats->tx_err);
28172+ atomic_inc_unchecked(&vcc->stats->tx_err);
28173 dev_kfree_skb(skb);
28174 return -EINVAL;
28175 }
28176
28177 if (skb_shinfo(skb)->nr_frags != 0) {
28178 printk("%s: No scatter-gather yet.\n", card->name);
28179- atomic_inc(&vcc->stats->tx_err);
28180+ atomic_inc_unchecked(&vcc->stats->tx_err);
28181 dev_kfree_skb(skb);
28182 return -EINVAL;
28183 }
28184@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28185
28186 err = queue_skb(card, vc, skb, oam);
28187 if (err) {
28188- atomic_inc(&vcc->stats->tx_err);
28189+ atomic_inc_unchecked(&vcc->stats->tx_err);
28190 dev_kfree_skb(skb);
28191 return err;
28192 }
28193@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28194 skb = dev_alloc_skb(64);
28195 if (!skb) {
28196 printk("%s: Out of memory in send_oam().\n", card->name);
28197- atomic_inc(&vcc->stats->tx_err);
28198+ atomic_inc_unchecked(&vcc->stats->tx_err);
28199 return -ENOMEM;
28200 }
28201 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28202diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28203index d438601..8b98495 100644
28204--- a/drivers/atm/iphase.c
28205+++ b/drivers/atm/iphase.c
28206@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28207 status = (u_short) (buf_desc_ptr->desc_mode);
28208 if (status & (RX_CER | RX_PTE | RX_OFL))
28209 {
28210- atomic_inc(&vcc->stats->rx_err);
28211+ atomic_inc_unchecked(&vcc->stats->rx_err);
28212 IF_ERR(printk("IA: bad packet, dropping it");)
28213 if (status & RX_CER) {
28214 IF_ERR(printk(" cause: packet CRC error\n");)
28215@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28216 len = dma_addr - buf_addr;
28217 if (len > iadev->rx_buf_sz) {
28218 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28219- atomic_inc(&vcc->stats->rx_err);
28220+ atomic_inc_unchecked(&vcc->stats->rx_err);
28221 goto out_free_desc;
28222 }
28223
28224@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28225 ia_vcc = INPH_IA_VCC(vcc);
28226 if (ia_vcc == NULL)
28227 {
28228- atomic_inc(&vcc->stats->rx_err);
28229+ atomic_inc_unchecked(&vcc->stats->rx_err);
28230 atm_return(vcc, skb->truesize);
28231 dev_kfree_skb_any(skb);
28232 goto INCR_DLE;
28233@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28234 if ((length > iadev->rx_buf_sz) || (length >
28235 (skb->len - sizeof(struct cpcs_trailer))))
28236 {
28237- atomic_inc(&vcc->stats->rx_err);
28238+ atomic_inc_unchecked(&vcc->stats->rx_err);
28239 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28240 length, skb->len);)
28241 atm_return(vcc, skb->truesize);
28242@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28243
28244 IF_RX(printk("rx_dle_intr: skb push");)
28245 vcc->push(vcc,skb);
28246- atomic_inc(&vcc->stats->rx);
28247+ atomic_inc_unchecked(&vcc->stats->rx);
28248 iadev->rx_pkt_cnt++;
28249 }
28250 INCR_DLE:
28251@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28252 {
28253 struct k_sonet_stats *stats;
28254 stats = &PRIV(_ia_dev[board])->sonet_stats;
28255- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28256- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28257- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28258- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28259- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28260- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28261- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28262- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28263- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28264+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28265+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28266+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28267+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28268+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28269+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28270+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28271+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28272+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28273 }
28274 ia_cmds.status = 0;
28275 break;
28276@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28277 if ((desc == 0) || (desc > iadev->num_tx_desc))
28278 {
28279 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28280- atomic_inc(&vcc->stats->tx);
28281+ atomic_inc_unchecked(&vcc->stats->tx);
28282 if (vcc->pop)
28283 vcc->pop(vcc, skb);
28284 else
28285@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28286 ATM_DESC(skb) = vcc->vci;
28287 skb_queue_tail(&iadev->tx_dma_q, skb);
28288
28289- atomic_inc(&vcc->stats->tx);
28290+ atomic_inc_unchecked(&vcc->stats->tx);
28291 iadev->tx_pkt_cnt++;
28292 /* Increment transaction counter */
28293 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28294
28295 #if 0
28296 /* add flow control logic */
28297- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28298+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28299 if (iavcc->vc_desc_cnt > 10) {
28300 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28301 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28302diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28303index 68c7588..7036683 100644
28304--- a/drivers/atm/lanai.c
28305+++ b/drivers/atm/lanai.c
28306@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28307 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28308 lanai_endtx(lanai, lvcc);
28309 lanai_free_skb(lvcc->tx.atmvcc, skb);
28310- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28311+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28312 }
28313
28314 /* Try to fill the buffer - don't call unless there is backlog */
28315@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28316 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28317 __net_timestamp(skb);
28318 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28319- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28320+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28321 out:
28322 lvcc->rx.buf.ptr = end;
28323 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28324@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28325 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28326 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28327 lanai->stats.service_rxnotaal5++;
28328- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28329+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28330 return 0;
28331 }
28332 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28333@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28334 int bytes;
28335 read_unlock(&vcc_sklist_lock);
28336 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28337- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28338+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28339 lvcc->stats.x.aal5.service_trash++;
28340 bytes = (SERVICE_GET_END(s) * 16) -
28341 (((unsigned long) lvcc->rx.buf.ptr) -
28342@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28343 }
28344 if (s & SERVICE_STREAM) {
28345 read_unlock(&vcc_sklist_lock);
28346- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28347+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28348 lvcc->stats.x.aal5.service_stream++;
28349 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28350 "PDU on VCI %d!\n", lanai->number, vci);
28351@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28352 return 0;
28353 }
28354 DPRINTK("got rx crc error on vci %d\n", vci);
28355- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28356+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28357 lvcc->stats.x.aal5.service_rxcrc++;
28358 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28359 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28360diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28361index 1c70c45..300718d 100644
28362--- a/drivers/atm/nicstar.c
28363+++ b/drivers/atm/nicstar.c
28364@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28365 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28366 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28367 card->index);
28368- atomic_inc(&vcc->stats->tx_err);
28369+ atomic_inc_unchecked(&vcc->stats->tx_err);
28370 dev_kfree_skb_any(skb);
28371 return -EINVAL;
28372 }
28373@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28374 if (!vc->tx) {
28375 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28376 card->index);
28377- atomic_inc(&vcc->stats->tx_err);
28378+ atomic_inc_unchecked(&vcc->stats->tx_err);
28379 dev_kfree_skb_any(skb);
28380 return -EINVAL;
28381 }
28382@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28383 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28384 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28385 card->index);
28386- atomic_inc(&vcc->stats->tx_err);
28387+ atomic_inc_unchecked(&vcc->stats->tx_err);
28388 dev_kfree_skb_any(skb);
28389 return -EINVAL;
28390 }
28391
28392 if (skb_shinfo(skb)->nr_frags != 0) {
28393 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28394- atomic_inc(&vcc->stats->tx_err);
28395+ atomic_inc_unchecked(&vcc->stats->tx_err);
28396 dev_kfree_skb_any(skb);
28397 return -EINVAL;
28398 }
28399@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28400 }
28401
28402 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28403- atomic_inc(&vcc->stats->tx_err);
28404+ atomic_inc_unchecked(&vcc->stats->tx_err);
28405 dev_kfree_skb_any(skb);
28406 return -EIO;
28407 }
28408- atomic_inc(&vcc->stats->tx);
28409+ atomic_inc_unchecked(&vcc->stats->tx);
28410
28411 return 0;
28412 }
28413@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28414 printk
28415 ("nicstar%d: Can't allocate buffers for aal0.\n",
28416 card->index);
28417- atomic_add(i, &vcc->stats->rx_drop);
28418+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
28419 break;
28420 }
28421 if (!atm_charge(vcc, sb->truesize)) {
28422 RXPRINTK
28423 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28424 card->index);
28425- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28426+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28427 dev_kfree_skb_any(sb);
28428 break;
28429 }
28430@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28431 ATM_SKB(sb)->vcc = vcc;
28432 __net_timestamp(sb);
28433 vcc->push(vcc, sb);
28434- atomic_inc(&vcc->stats->rx);
28435+ atomic_inc_unchecked(&vcc->stats->rx);
28436 cell += ATM_CELL_PAYLOAD;
28437 }
28438
28439@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28440 if (iovb == NULL) {
28441 printk("nicstar%d: Out of iovec buffers.\n",
28442 card->index);
28443- atomic_inc(&vcc->stats->rx_drop);
28444+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28445 recycle_rx_buf(card, skb);
28446 return;
28447 }
28448@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28449 small or large buffer itself. */
28450 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28451 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28452- atomic_inc(&vcc->stats->rx_err);
28453+ atomic_inc_unchecked(&vcc->stats->rx_err);
28454 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28455 NS_MAX_IOVECS);
28456 NS_PRV_IOVCNT(iovb) = 0;
28457@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28458 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28459 card->index);
28460 which_list(card, skb);
28461- atomic_inc(&vcc->stats->rx_err);
28462+ atomic_inc_unchecked(&vcc->stats->rx_err);
28463 recycle_rx_buf(card, skb);
28464 vc->rx_iov = NULL;
28465 recycle_iov_buf(card, iovb);
28466@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28467 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28468 card->index);
28469 which_list(card, skb);
28470- atomic_inc(&vcc->stats->rx_err);
28471+ atomic_inc_unchecked(&vcc->stats->rx_err);
28472 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28473 NS_PRV_IOVCNT(iovb));
28474 vc->rx_iov = NULL;
28475@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28476 printk(" - PDU size mismatch.\n");
28477 else
28478 printk(".\n");
28479- atomic_inc(&vcc->stats->rx_err);
28480+ atomic_inc_unchecked(&vcc->stats->rx_err);
28481 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28482 NS_PRV_IOVCNT(iovb));
28483 vc->rx_iov = NULL;
28484@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28485 /* skb points to a small buffer */
28486 if (!atm_charge(vcc, skb->truesize)) {
28487 push_rxbufs(card, skb);
28488- atomic_inc(&vcc->stats->rx_drop);
28489+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28490 } else {
28491 skb_put(skb, len);
28492 dequeue_sm_buf(card, skb);
28493@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28494 ATM_SKB(skb)->vcc = vcc;
28495 __net_timestamp(skb);
28496 vcc->push(vcc, skb);
28497- atomic_inc(&vcc->stats->rx);
28498+ atomic_inc_unchecked(&vcc->stats->rx);
28499 }
28500 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28501 struct sk_buff *sb;
28502@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28503 if (len <= NS_SMBUFSIZE) {
28504 if (!atm_charge(vcc, sb->truesize)) {
28505 push_rxbufs(card, sb);
28506- atomic_inc(&vcc->stats->rx_drop);
28507+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28508 } else {
28509 skb_put(sb, len);
28510 dequeue_sm_buf(card, sb);
28511@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28512 ATM_SKB(sb)->vcc = vcc;
28513 __net_timestamp(sb);
28514 vcc->push(vcc, sb);
28515- atomic_inc(&vcc->stats->rx);
28516+ atomic_inc_unchecked(&vcc->stats->rx);
28517 }
28518
28519 push_rxbufs(card, skb);
28520@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28521
28522 if (!atm_charge(vcc, skb->truesize)) {
28523 push_rxbufs(card, skb);
28524- atomic_inc(&vcc->stats->rx_drop);
28525+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28526 } else {
28527 dequeue_lg_buf(card, skb);
28528 #ifdef NS_USE_DESTRUCTORS
28529@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28530 ATM_SKB(skb)->vcc = vcc;
28531 __net_timestamp(skb);
28532 vcc->push(vcc, skb);
28533- atomic_inc(&vcc->stats->rx);
28534+ atomic_inc_unchecked(&vcc->stats->rx);
28535 }
28536
28537 push_rxbufs(card, sb);
28538@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28539 printk
28540 ("nicstar%d: Out of huge buffers.\n",
28541 card->index);
28542- atomic_inc(&vcc->stats->rx_drop);
28543+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28544 recycle_iovec_rx_bufs(card,
28545 (struct iovec *)
28546 iovb->data,
28547@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28548 card->hbpool.count++;
28549 } else
28550 dev_kfree_skb_any(hb);
28551- atomic_inc(&vcc->stats->rx_drop);
28552+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28553 } else {
28554 /* Copy the small buffer to the huge buffer */
28555 sb = (struct sk_buff *)iov->iov_base;
28556@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28557 #endif /* NS_USE_DESTRUCTORS */
28558 __net_timestamp(hb);
28559 vcc->push(vcc, hb);
28560- atomic_inc(&vcc->stats->rx);
28561+ atomic_inc_unchecked(&vcc->stats->rx);
28562 }
28563 }
28564
28565diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28566index 9851093..adb2b1e 100644
28567--- a/drivers/atm/solos-pci.c
28568+++ b/drivers/atm/solos-pci.c
28569@@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28570 }
28571 atm_charge(vcc, skb->truesize);
28572 vcc->push(vcc, skb);
28573- atomic_inc(&vcc->stats->rx);
28574+ atomic_inc_unchecked(&vcc->stats->rx);
28575 break;
28576
28577 case PKT_STATUS:
28578@@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28579 vcc = SKB_CB(oldskb)->vcc;
28580
28581 if (vcc) {
28582- atomic_inc(&vcc->stats->tx);
28583+ atomic_inc_unchecked(&vcc->stats->tx);
28584 solos_pop(vcc, oldskb);
28585 } else
28586 dev_kfree_skb_irq(oldskb);
28587diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28588index 0215934..ce9f5b1 100644
28589--- a/drivers/atm/suni.c
28590+++ b/drivers/atm/suni.c
28591@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28592
28593
28594 #define ADD_LIMITED(s,v) \
28595- atomic_add((v),&stats->s); \
28596- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28597+ atomic_add_unchecked((v),&stats->s); \
28598+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28599
28600
28601 static void suni_hz(unsigned long from_timer)
28602diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28603index 5120a96..e2572bd 100644
28604--- a/drivers/atm/uPD98402.c
28605+++ b/drivers/atm/uPD98402.c
28606@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28607 struct sonet_stats tmp;
28608 int error = 0;
28609
28610- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28611+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28612 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28613 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28614 if (zero && !error) {
28615@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28616
28617
28618 #define ADD_LIMITED(s,v) \
28619- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28620- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28621- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28622+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28623+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28624+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28625
28626
28627 static void stat_event(struct atm_dev *dev)
28628@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28629 if (reason & uPD98402_INT_PFM) stat_event(dev);
28630 if (reason & uPD98402_INT_PCO) {
28631 (void) GET(PCOCR); /* clear interrupt cause */
28632- atomic_add(GET(HECCT),
28633+ atomic_add_unchecked(GET(HECCT),
28634 &PRIV(dev)->sonet_stats.uncorr_hcs);
28635 }
28636 if ((reason & uPD98402_INT_RFO) &&
28637@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28638 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28639 uPD98402_INT_LOS),PIMR); /* enable them */
28640 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28641- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28642- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28643- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28644+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28645+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28646+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28647 return 0;
28648 }
28649
28650diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28651index abe4e20..83c4727 100644
28652--- a/drivers/atm/zatm.c
28653+++ b/drivers/atm/zatm.c
28654@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28655 }
28656 if (!size) {
28657 dev_kfree_skb_irq(skb);
28658- if (vcc) atomic_inc(&vcc->stats->rx_err);
28659+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28660 continue;
28661 }
28662 if (!atm_charge(vcc,skb->truesize)) {
28663@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28664 skb->len = size;
28665 ATM_SKB(skb)->vcc = vcc;
28666 vcc->push(vcc,skb);
28667- atomic_inc(&vcc->stats->rx);
28668+ atomic_inc_unchecked(&vcc->stats->rx);
28669 }
28670 zout(pos & 0xffff,MTA(mbx));
28671 #if 0 /* probably a stupid idea */
28672@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28673 skb_queue_head(&zatm_vcc->backlog,skb);
28674 break;
28675 }
28676- atomic_inc(&vcc->stats->tx);
28677+ atomic_inc_unchecked(&vcc->stats->tx);
28678 wake_up(&zatm_vcc->tx_wait);
28679 }
28680
28681diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28682index 765c3a2..771ace6 100644
28683--- a/drivers/base/devtmpfs.c
28684+++ b/drivers/base/devtmpfs.c
28685@@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
28686 if (!thread)
28687 return 0;
28688
28689- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28690+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28691 if (err)
28692 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28693 else
28694diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28695index cbb463b..babe2cf 100644
28696--- a/drivers/base/power/wakeup.c
28697+++ b/drivers/base/power/wakeup.c
28698@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
28699 * They need to be modified together atomically, so it's better to use one
28700 * atomic variable to hold them both.
28701 */
28702-static atomic_t combined_event_count = ATOMIC_INIT(0);
28703+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
28704
28705 #define IN_PROGRESS_BITS (sizeof(int) * 4)
28706 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
28707
28708 static void split_counters(unsigned int *cnt, unsigned int *inpr)
28709 {
28710- unsigned int comb = atomic_read(&combined_event_count);
28711+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
28712
28713 *cnt = (comb >> IN_PROGRESS_BITS);
28714 *inpr = comb & MAX_IN_PROGRESS;
28715@@ -385,7 +385,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
28716 ws->start_prevent_time = ws->last_time;
28717
28718 /* Increment the counter of events in progress. */
28719- cec = atomic_inc_return(&combined_event_count);
28720+ cec = atomic_inc_return_unchecked(&combined_event_count);
28721
28722 trace_wakeup_source_activate(ws->name, cec);
28723 }
28724@@ -511,7 +511,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
28725 * Increment the counter of registered wakeup events and decrement the
28726 * couter of wakeup events in progress simultaneously.
28727 */
28728- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
28729+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
28730 trace_wakeup_source_deactivate(ws->name, cec);
28731
28732 split_counters(&cnt, &inpr);
28733diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
28734index b0f553b..77b928b 100644
28735--- a/drivers/block/cciss.c
28736+++ b/drivers/block/cciss.c
28737@@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
28738 int err;
28739 u32 cp;
28740
28741+ memset(&arg64, 0, sizeof(arg64));
28742+
28743 err = 0;
28744 err |=
28745 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
28746@@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
28747 while (!list_empty(&h->reqQ)) {
28748 c = list_entry(h->reqQ.next, CommandList_struct, list);
28749 /* can't do anything if fifo is full */
28750- if ((h->access.fifo_full(h))) {
28751+ if ((h->access->fifo_full(h))) {
28752 dev_warn(&h->pdev->dev, "fifo full\n");
28753 break;
28754 }
28755@@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
28756 h->Qdepth--;
28757
28758 /* Tell the controller execute command */
28759- h->access.submit_command(h, c);
28760+ h->access->submit_command(h, c);
28761
28762 /* Put job onto the completed Q */
28763 addQ(&h->cmpQ, c);
28764@@ -3443,17 +3445,17 @@ startio:
28765
28766 static inline unsigned long get_next_completion(ctlr_info_t *h)
28767 {
28768- return h->access.command_completed(h);
28769+ return h->access->command_completed(h);
28770 }
28771
28772 static inline int interrupt_pending(ctlr_info_t *h)
28773 {
28774- return h->access.intr_pending(h);
28775+ return h->access->intr_pending(h);
28776 }
28777
28778 static inline long interrupt_not_for_us(ctlr_info_t *h)
28779 {
28780- return ((h->access.intr_pending(h) == 0) ||
28781+ return ((h->access->intr_pending(h) == 0) ||
28782 (h->interrupts_enabled == 0));
28783 }
28784
28785@@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
28786 u32 a;
28787
28788 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
28789- return h->access.command_completed(h);
28790+ return h->access->command_completed(h);
28791
28792 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
28793 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
28794@@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
28795 trans_support & CFGTBL_Trans_use_short_tags);
28796
28797 /* Change the access methods to the performant access methods */
28798- h->access = SA5_performant_access;
28799+ h->access = &SA5_performant_access;
28800 h->transMethod = CFGTBL_Trans_Performant;
28801
28802 return;
28803@@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
28804 if (prod_index < 0)
28805 return -ENODEV;
28806 h->product_name = products[prod_index].product_name;
28807- h->access = *(products[prod_index].access);
28808+ h->access = products[prod_index].access;
28809
28810 if (cciss_board_disabled(h)) {
28811 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
28812@@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
28813 }
28814
28815 /* make sure the board interrupts are off */
28816- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28817+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28818 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
28819 if (rc)
28820 goto clean2;
28821@@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
28822 * fake ones to scoop up any residual completions.
28823 */
28824 spin_lock_irqsave(&h->lock, flags);
28825- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28826+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28827 spin_unlock_irqrestore(&h->lock, flags);
28828 free_irq(h->intr[h->intr_mode], h);
28829 rc = cciss_request_irq(h, cciss_msix_discard_completions,
28830@@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
28831 dev_info(&h->pdev->dev, "Board READY.\n");
28832 dev_info(&h->pdev->dev,
28833 "Waiting for stale completions to drain.\n");
28834- h->access.set_intr_mask(h, CCISS_INTR_ON);
28835+ h->access->set_intr_mask(h, CCISS_INTR_ON);
28836 msleep(10000);
28837- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28838+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28839
28840 rc = controller_reset_failed(h->cfgtable);
28841 if (rc)
28842@@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
28843 cciss_scsi_setup(h);
28844
28845 /* Turn the interrupts on so we can service requests */
28846- h->access.set_intr_mask(h, CCISS_INTR_ON);
28847+ h->access->set_intr_mask(h, CCISS_INTR_ON);
28848
28849 /* Get the firmware version */
28850 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
28851@@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
28852 kfree(flush_buf);
28853 if (return_code != IO_OK)
28854 dev_warn(&h->pdev->dev, "Error flushing cache\n");
28855- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28856+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28857 free_irq(h->intr[h->intr_mode], h);
28858 }
28859
28860diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
28861index 7fda30e..eb5dfe0 100644
28862--- a/drivers/block/cciss.h
28863+++ b/drivers/block/cciss.h
28864@@ -101,7 +101,7 @@ struct ctlr_info
28865 /* information about each logical volume */
28866 drive_info_struct *drv[CISS_MAX_LUN];
28867
28868- struct access_method access;
28869+ struct access_method *access;
28870
28871 /* queue and queue Info */
28872 struct list_head reqQ;
28873diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
28874index 9125bbe..eede5c8 100644
28875--- a/drivers/block/cpqarray.c
28876+++ b/drivers/block/cpqarray.c
28877@@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28878 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
28879 goto Enomem4;
28880 }
28881- hba[i]->access.set_intr_mask(hba[i], 0);
28882+ hba[i]->access->set_intr_mask(hba[i], 0);
28883 if (request_irq(hba[i]->intr, do_ida_intr,
28884 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
28885 {
28886@@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28887 add_timer(&hba[i]->timer);
28888
28889 /* Enable IRQ now that spinlock and rate limit timer are set up */
28890- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28891+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28892
28893 for(j=0; j<NWD; j++) {
28894 struct gendisk *disk = ida_gendisk[i][j];
28895@@ -694,7 +694,7 @@ DBGINFO(
28896 for(i=0; i<NR_PRODUCTS; i++) {
28897 if (board_id == products[i].board_id) {
28898 c->product_name = products[i].product_name;
28899- c->access = *(products[i].access);
28900+ c->access = products[i].access;
28901 break;
28902 }
28903 }
28904@@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
28905 hba[ctlr]->intr = intr;
28906 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
28907 hba[ctlr]->product_name = products[j].product_name;
28908- hba[ctlr]->access = *(products[j].access);
28909+ hba[ctlr]->access = products[j].access;
28910 hba[ctlr]->ctlr = ctlr;
28911 hba[ctlr]->board_id = board_id;
28912 hba[ctlr]->pci_dev = NULL; /* not PCI */
28913@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
28914
28915 while((c = h->reqQ) != NULL) {
28916 /* Can't do anything if we're busy */
28917- if (h->access.fifo_full(h) == 0)
28918+ if (h->access->fifo_full(h) == 0)
28919 return;
28920
28921 /* Get the first entry from the request Q */
28922@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
28923 h->Qdepth--;
28924
28925 /* Tell the controller to do our bidding */
28926- h->access.submit_command(h, c);
28927+ h->access->submit_command(h, c);
28928
28929 /* Get onto the completion Q */
28930 addQ(&h->cmpQ, c);
28931@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28932 unsigned long flags;
28933 __u32 a,a1;
28934
28935- istat = h->access.intr_pending(h);
28936+ istat = h->access->intr_pending(h);
28937 /* Is this interrupt for us? */
28938 if (istat == 0)
28939 return IRQ_NONE;
28940@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28941 */
28942 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
28943 if (istat & FIFO_NOT_EMPTY) {
28944- while((a = h->access.command_completed(h))) {
28945+ while((a = h->access->command_completed(h))) {
28946 a1 = a; a &= ~3;
28947 if ((c = h->cmpQ) == NULL)
28948 {
28949@@ -1449,11 +1449,11 @@ static int sendcmd(
28950 /*
28951 * Disable interrupt
28952 */
28953- info_p->access.set_intr_mask(info_p, 0);
28954+ info_p->access->set_intr_mask(info_p, 0);
28955 /* Make sure there is room in the command FIFO */
28956 /* Actually it should be completely empty at this time. */
28957 for (i = 200000; i > 0; i--) {
28958- temp = info_p->access.fifo_full(info_p);
28959+ temp = info_p->access->fifo_full(info_p);
28960 if (temp != 0) {
28961 break;
28962 }
28963@@ -1466,7 +1466,7 @@ DBG(
28964 /*
28965 * Send the cmd
28966 */
28967- info_p->access.submit_command(info_p, c);
28968+ info_p->access->submit_command(info_p, c);
28969 complete = pollcomplete(ctlr);
28970
28971 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
28972@@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
28973 * we check the new geometry. Then turn interrupts back on when
28974 * we're done.
28975 */
28976- host->access.set_intr_mask(host, 0);
28977+ host->access->set_intr_mask(host, 0);
28978 getgeometry(ctlr);
28979- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
28980+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
28981
28982 for(i=0; i<NWD; i++) {
28983 struct gendisk *disk = ida_gendisk[ctlr][i];
28984@@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
28985 /* Wait (up to 2 seconds) for a command to complete */
28986
28987 for (i = 200000; i > 0; i--) {
28988- done = hba[ctlr]->access.command_completed(hba[ctlr]);
28989+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
28990 if (done == 0) {
28991 udelay(10); /* a short fixed delay */
28992 } else
28993diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
28994index be73e9d..7fbf140 100644
28995--- a/drivers/block/cpqarray.h
28996+++ b/drivers/block/cpqarray.h
28997@@ -99,7 +99,7 @@ struct ctlr_info {
28998 drv_info_t drv[NWD];
28999 struct proc_dir_entry *proc;
29000
29001- struct access_method access;
29002+ struct access_method *access;
29003
29004 cmdlist_t *reqQ;
29005 cmdlist_t *cmpQ;
29006diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29007index 02f013a..afeba24 100644
29008--- a/drivers/block/drbd/drbd_int.h
29009+++ b/drivers/block/drbd/drbd_int.h
29010@@ -735,7 +735,7 @@ struct drbd_request;
29011 struct drbd_epoch {
29012 struct list_head list;
29013 unsigned int barrier_nr;
29014- atomic_t epoch_size; /* increased on every request added. */
29015+ atomic_unchecked_t epoch_size; /* increased on every request added. */
29016 atomic_t active; /* increased on every req. added, and dec on every finished. */
29017 unsigned long flags;
29018 };
29019@@ -1110,7 +1110,7 @@ struct drbd_conf {
29020 void *int_dig_in;
29021 void *int_dig_vv;
29022 wait_queue_head_t seq_wait;
29023- atomic_t packet_seq;
29024+ atomic_unchecked_t packet_seq;
29025 unsigned int peer_seq;
29026 spinlock_t peer_seq_lock;
29027 unsigned int minor;
29028@@ -1651,30 +1651,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29029
29030 static inline void drbd_tcp_cork(struct socket *sock)
29031 {
29032- int __user val = 1;
29033+ int val = 1;
29034 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29035- (char __user *)&val, sizeof(val));
29036+ (char __force_user *)&val, sizeof(val));
29037 }
29038
29039 static inline void drbd_tcp_uncork(struct socket *sock)
29040 {
29041- int __user val = 0;
29042+ int val = 0;
29043 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29044- (char __user *)&val, sizeof(val));
29045+ (char __force_user *)&val, sizeof(val));
29046 }
29047
29048 static inline void drbd_tcp_nodelay(struct socket *sock)
29049 {
29050- int __user val = 1;
29051+ int val = 1;
29052 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29053- (char __user *)&val, sizeof(val));
29054+ (char __force_user *)&val, sizeof(val));
29055 }
29056
29057 static inline void drbd_tcp_quickack(struct socket *sock)
29058 {
29059- int __user val = 2;
29060+ int val = 2;
29061 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29062- (char __user *)&val, sizeof(val));
29063+ (char __force_user *)&val, sizeof(val));
29064 }
29065
29066 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29067diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29068index 920ede2..cb827ba 100644
29069--- a/drivers/block/drbd/drbd_main.c
29070+++ b/drivers/block/drbd/drbd_main.c
29071@@ -2555,7 +2555,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29072 p.sector = sector;
29073 p.block_id = block_id;
29074 p.blksize = blksize;
29075- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29076+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29077
29078 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29079 return false;
29080@@ -2853,7 +2853,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29081
29082 p.sector = cpu_to_be64(req->sector);
29083 p.block_id = (unsigned long)req;
29084- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29085+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29086
29087 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29088
29089@@ -3138,7 +3138,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29090 atomic_set(&mdev->unacked_cnt, 0);
29091 atomic_set(&mdev->local_cnt, 0);
29092 atomic_set(&mdev->net_cnt, 0);
29093- atomic_set(&mdev->packet_seq, 0);
29094+ atomic_set_unchecked(&mdev->packet_seq, 0);
29095 atomic_set(&mdev->pp_in_use, 0);
29096 atomic_set(&mdev->pp_in_use_by_net, 0);
29097 atomic_set(&mdev->rs_sect_in, 0);
29098@@ -3220,8 +3220,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29099 mdev->receiver.t_state);
29100
29101 /* no need to lock it, I'm the only thread alive */
29102- if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29103- dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29104+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29105+ dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29106 mdev->al_writ_cnt =
29107 mdev->bm_writ_cnt =
29108 mdev->read_cnt =
29109diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29110index 6d4de6a..7b7ad4b 100644
29111--- a/drivers/block/drbd/drbd_nl.c
29112+++ b/drivers/block/drbd/drbd_nl.c
29113@@ -2387,7 +2387,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29114 module_put(THIS_MODULE);
29115 }
29116
29117-static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29118+static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29119
29120 static unsigned short *
29121 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29122@@ -2458,7 +2458,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29123 cn_reply->id.idx = CN_IDX_DRBD;
29124 cn_reply->id.val = CN_VAL_DRBD;
29125
29126- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29127+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29128 cn_reply->ack = 0; /* not used here. */
29129 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29130 (int)((char *)tl - (char *)reply->tag_list);
29131@@ -2490,7 +2490,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29132 cn_reply->id.idx = CN_IDX_DRBD;
29133 cn_reply->id.val = CN_VAL_DRBD;
29134
29135- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29136+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29137 cn_reply->ack = 0; /* not used here. */
29138 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29139 (int)((char *)tl - (char *)reply->tag_list);
29140@@ -2568,7 +2568,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29141 cn_reply->id.idx = CN_IDX_DRBD;
29142 cn_reply->id.val = CN_VAL_DRBD;
29143
29144- cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29145+ cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29146 cn_reply->ack = 0; // not used here.
29147 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29148 (int)((char*)tl - (char*)reply->tag_list);
29149@@ -2607,7 +2607,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29150 cn_reply->id.idx = CN_IDX_DRBD;
29151 cn_reply->id.val = CN_VAL_DRBD;
29152
29153- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29154+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29155 cn_reply->ack = 0; /* not used here. */
29156 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29157 (int)((char *)tl - (char *)reply->tag_list);
29158diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29159index ea4836e..272d72a 100644
29160--- a/drivers/block/drbd/drbd_receiver.c
29161+++ b/drivers/block/drbd/drbd_receiver.c
29162@@ -893,7 +893,7 @@ retry:
29163 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29164 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29165
29166- atomic_set(&mdev->packet_seq, 0);
29167+ atomic_set_unchecked(&mdev->packet_seq, 0);
29168 mdev->peer_seq = 0;
29169
29170 if (drbd_send_protocol(mdev) == -1)
29171@@ -994,7 +994,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29172 do {
29173 next_epoch = NULL;
29174
29175- epoch_size = atomic_read(&epoch->epoch_size);
29176+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29177
29178 switch (ev & ~EV_CLEANUP) {
29179 case EV_PUT:
29180@@ -1030,7 +1030,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29181 rv = FE_DESTROYED;
29182 } else {
29183 epoch->flags = 0;
29184- atomic_set(&epoch->epoch_size, 0);
29185+ atomic_set_unchecked(&epoch->epoch_size, 0);
29186 /* atomic_set(&epoch->active, 0); is already zero */
29187 if (rv == FE_STILL_LIVE)
29188 rv = FE_RECYCLED;
29189@@ -1205,14 +1205,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29190 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29191 drbd_flush(mdev);
29192
29193- if (atomic_read(&mdev->current_epoch->epoch_size)) {
29194+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29195 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29196 if (epoch)
29197 break;
29198 }
29199
29200 epoch = mdev->current_epoch;
29201- wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29202+ wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29203
29204 D_ASSERT(atomic_read(&epoch->active) == 0);
29205 D_ASSERT(epoch->flags == 0);
29206@@ -1224,11 +1224,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29207 }
29208
29209 epoch->flags = 0;
29210- atomic_set(&epoch->epoch_size, 0);
29211+ atomic_set_unchecked(&epoch->epoch_size, 0);
29212 atomic_set(&epoch->active, 0);
29213
29214 spin_lock(&mdev->epoch_lock);
29215- if (atomic_read(&mdev->current_epoch->epoch_size)) {
29216+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29217 list_add(&epoch->list, &mdev->current_epoch->list);
29218 mdev->current_epoch = epoch;
29219 mdev->epochs++;
29220@@ -1695,7 +1695,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29221 spin_unlock(&mdev->peer_seq_lock);
29222
29223 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29224- atomic_inc(&mdev->current_epoch->epoch_size);
29225+ atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29226 return drbd_drain_block(mdev, data_size);
29227 }
29228
29229@@ -1721,7 +1721,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29230
29231 spin_lock(&mdev->epoch_lock);
29232 e->epoch = mdev->current_epoch;
29233- atomic_inc(&e->epoch->epoch_size);
29234+ atomic_inc_unchecked(&e->epoch->epoch_size);
29235 atomic_inc(&e->epoch->active);
29236 spin_unlock(&mdev->epoch_lock);
29237
29238@@ -3936,7 +3936,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29239 D_ASSERT(list_empty(&mdev->done_ee));
29240
29241 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29242- atomic_set(&mdev->current_epoch->epoch_size, 0);
29243+ atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29244 D_ASSERT(list_empty(&mdev->current_epoch->list));
29245 }
29246
29247diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29248index 3bba655..6151b66 100644
29249--- a/drivers/block/loop.c
29250+++ b/drivers/block/loop.c
29251@@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29252 mm_segment_t old_fs = get_fs();
29253
29254 set_fs(get_ds());
29255- bw = file->f_op->write(file, buf, len, &pos);
29256+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29257 set_fs(old_fs);
29258 if (likely(bw == len))
29259 return 0;
29260diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29261index ea6f632..eafb192 100644
29262--- a/drivers/char/Kconfig
29263+++ b/drivers/char/Kconfig
29264@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29265
29266 config DEVKMEM
29267 bool "/dev/kmem virtual device support"
29268- default y
29269+ default n
29270+ depends on !GRKERNSEC_KMEM
29271 help
29272 Say Y here if you want to support the /dev/kmem device. The
29273 /dev/kmem device is rarely used, but can be used for certain
29274@@ -581,6 +582,7 @@ config DEVPORT
29275 bool
29276 depends on !M68K
29277 depends on ISA || PCI
29278+ depends on !GRKERNSEC_KMEM
29279 default y
29280
29281 source "drivers/s390/char/Kconfig"
29282diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29283index 2e04433..22afc64 100644
29284--- a/drivers/char/agp/frontend.c
29285+++ b/drivers/char/agp/frontend.c
29286@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29287 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29288 return -EFAULT;
29289
29290- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29291+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29292 return -EFAULT;
29293
29294 client = agp_find_client_by_pid(reserve.pid);
29295diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29296index 21cb980..f15107c 100644
29297--- a/drivers/char/genrtc.c
29298+++ b/drivers/char/genrtc.c
29299@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29300 switch (cmd) {
29301
29302 case RTC_PLL_GET:
29303+ memset(&pll, 0, sizeof(pll));
29304 if (get_rtc_pll(&pll))
29305 return -EINVAL;
29306 else
29307diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29308index dfd7876..c0b0885 100644
29309--- a/drivers/char/hpet.c
29310+++ b/drivers/char/hpet.c
29311@@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29312 }
29313
29314 static int
29315-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29316+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29317 struct hpet_info *info)
29318 {
29319 struct hpet_timer __iomem *timer;
29320diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29321index 2c29942..604c5ba 100644
29322--- a/drivers/char/ipmi/ipmi_msghandler.c
29323+++ b/drivers/char/ipmi/ipmi_msghandler.c
29324@@ -420,7 +420,7 @@ struct ipmi_smi {
29325 struct proc_dir_entry *proc_dir;
29326 char proc_dir_name[10];
29327
29328- atomic_t stats[IPMI_NUM_STATS];
29329+ atomic_unchecked_t stats[IPMI_NUM_STATS];
29330
29331 /*
29332 * run_to_completion duplicate of smb_info, smi_info
29333@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29334
29335
29336 #define ipmi_inc_stat(intf, stat) \
29337- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29338+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29339 #define ipmi_get_stat(intf, stat) \
29340- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29341+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29342
29343 static int is_lan_addr(struct ipmi_addr *addr)
29344 {
29345@@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29346 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29347 init_waitqueue_head(&intf->waitq);
29348 for (i = 0; i < IPMI_NUM_STATS; i++)
29349- atomic_set(&intf->stats[i], 0);
29350+ atomic_set_unchecked(&intf->stats[i], 0);
29351
29352 intf->proc_dir = NULL;
29353
29354diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29355index 1e638ff..a869ef5 100644
29356--- a/drivers/char/ipmi/ipmi_si_intf.c
29357+++ b/drivers/char/ipmi/ipmi_si_intf.c
29358@@ -275,7 +275,7 @@ struct smi_info {
29359 unsigned char slave_addr;
29360
29361 /* Counters and things for the proc filesystem. */
29362- atomic_t stats[SI_NUM_STATS];
29363+ atomic_unchecked_t stats[SI_NUM_STATS];
29364
29365 struct task_struct *thread;
29366
29367@@ -284,9 +284,9 @@ struct smi_info {
29368 };
29369
29370 #define smi_inc_stat(smi, stat) \
29371- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29372+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29373 #define smi_get_stat(smi, stat) \
29374- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29375+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29376
29377 #define SI_MAX_PARMS 4
29378
29379@@ -3209,7 +3209,7 @@ static int try_smi_init(struct smi_info *new_smi)
29380 atomic_set(&new_smi->req_events, 0);
29381 new_smi->run_to_completion = 0;
29382 for (i = 0; i < SI_NUM_STATS; i++)
29383- atomic_set(&new_smi->stats[i], 0);
29384+ atomic_set_unchecked(&new_smi->stats[i], 0);
29385
29386 new_smi->interrupt_disabled = 1;
29387 atomic_set(&new_smi->stop_operation, 0);
29388diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29389index 47ff7e4..0c7d340 100644
29390--- a/drivers/char/mbcs.c
29391+++ b/drivers/char/mbcs.c
29392@@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
29393 return 0;
29394 }
29395
29396-static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29397+static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29398 {
29399 .part_num = MBCS_PART_NUM,
29400 .mfg_num = MBCS_MFG_NUM,
29401diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29402index 67c3371..ba8429d 100644
29403--- a/drivers/char/mem.c
29404+++ b/drivers/char/mem.c
29405@@ -18,6 +18,7 @@
29406 #include <linux/raw.h>
29407 #include <linux/tty.h>
29408 #include <linux/capability.h>
29409+#include <linux/security.h>
29410 #include <linux/ptrace.h>
29411 #include <linux/device.h>
29412 #include <linux/highmem.h>
29413@@ -35,6 +36,10 @@
29414 # include <linux/efi.h>
29415 #endif
29416
29417+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29418+extern const struct file_operations grsec_fops;
29419+#endif
29420+
29421 static inline unsigned long size_inside_page(unsigned long start,
29422 unsigned long size)
29423 {
29424@@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29425
29426 while (cursor < to) {
29427 if (!devmem_is_allowed(pfn)) {
29428+#ifdef CONFIG_GRKERNSEC_KMEM
29429+ gr_handle_mem_readwrite(from, to);
29430+#else
29431 printk(KERN_INFO
29432 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29433 current->comm, from, to);
29434+#endif
29435 return 0;
29436 }
29437 cursor += PAGE_SIZE;
29438@@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29439 }
29440 return 1;
29441 }
29442+#elif defined(CONFIG_GRKERNSEC_KMEM)
29443+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29444+{
29445+ return 0;
29446+}
29447 #else
29448 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29449 {
29450@@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29451
29452 while (count > 0) {
29453 unsigned long remaining;
29454+ char *temp;
29455
29456 sz = size_inside_page(p, count);
29457
29458@@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29459 if (!ptr)
29460 return -EFAULT;
29461
29462- remaining = copy_to_user(buf, ptr, sz);
29463+#ifdef CONFIG_PAX_USERCOPY
29464+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29465+ if (!temp) {
29466+ unxlate_dev_mem_ptr(p, ptr);
29467+ return -ENOMEM;
29468+ }
29469+ memcpy(temp, ptr, sz);
29470+#else
29471+ temp = ptr;
29472+#endif
29473+
29474+ remaining = copy_to_user(buf, temp, sz);
29475+
29476+#ifdef CONFIG_PAX_USERCOPY
29477+ kfree(temp);
29478+#endif
29479+
29480 unxlate_dev_mem_ptr(p, ptr);
29481 if (remaining)
29482 return -EFAULT;
29483@@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29484 size_t count, loff_t *ppos)
29485 {
29486 unsigned long p = *ppos;
29487- ssize_t low_count, read, sz;
29488+ ssize_t low_count, read, sz, err = 0;
29489 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29490- int err = 0;
29491
29492 read = 0;
29493 if (p < (unsigned long) high_memory) {
29494@@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29495 }
29496 #endif
29497 while (low_count > 0) {
29498+ char *temp;
29499+
29500 sz = size_inside_page(p, low_count);
29501
29502 /*
29503@@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29504 */
29505 kbuf = xlate_dev_kmem_ptr((char *)p);
29506
29507- if (copy_to_user(buf, kbuf, sz))
29508+#ifdef CONFIG_PAX_USERCOPY
29509+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29510+ if (!temp)
29511+ return -ENOMEM;
29512+ memcpy(temp, kbuf, sz);
29513+#else
29514+ temp = kbuf;
29515+#endif
29516+
29517+ err = copy_to_user(buf, temp, sz);
29518+
29519+#ifdef CONFIG_PAX_USERCOPY
29520+ kfree(temp);
29521+#endif
29522+
29523+ if (err)
29524 return -EFAULT;
29525 buf += sz;
29526 p += sz;
29527@@ -831,6 +878,9 @@ static const struct memdev {
29528 #ifdef CONFIG_CRASH_DUMP
29529 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29530 #endif
29531+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29532+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29533+#endif
29534 };
29535
29536 static int memory_open(struct inode *inode, struct file *filp)
29537diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29538index 9df78e2..01ba9ae 100644
29539--- a/drivers/char/nvram.c
29540+++ b/drivers/char/nvram.c
29541@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29542
29543 spin_unlock_irq(&rtc_lock);
29544
29545- if (copy_to_user(buf, contents, tmp - contents))
29546+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29547 return -EFAULT;
29548
29549 *ppos = i;
29550diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
29551index 0a484b4..f48ccd1 100644
29552--- a/drivers/char/pcmcia/synclink_cs.c
29553+++ b/drivers/char/pcmcia/synclink_cs.c
29554@@ -2340,9 +2340,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29555
29556 if (debug_level >= DEBUG_LEVEL_INFO)
29557 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
29558- __FILE__,__LINE__, info->device_name, port->count);
29559+ __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
29560
29561- WARN_ON(!port->count);
29562+ WARN_ON(!atomic_read(&port->count));
29563
29564 if (tty_port_close_start(port, tty, filp) == 0)
29565 goto cleanup;
29566@@ -2360,7 +2360,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29567 cleanup:
29568 if (debug_level >= DEBUG_LEVEL_INFO)
29569 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
29570- tty->driver->name, port->count);
29571+ tty->driver->name, atomic_read(&port->count));
29572 }
29573
29574 /* Wait until the transmitter is empty.
29575@@ -2502,7 +2502,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29576
29577 if (debug_level >= DEBUG_LEVEL_INFO)
29578 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
29579- __FILE__,__LINE__,tty->driver->name, port->count);
29580+ __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
29581
29582 /* If port is closing, signal caller to try again */
29583 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
29584@@ -2522,11 +2522,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29585 goto cleanup;
29586 }
29587 spin_lock(&port->lock);
29588- port->count++;
29589+ atomic_inc(&port->count);
29590 spin_unlock(&port->lock);
29591 spin_unlock_irqrestore(&info->netlock, flags);
29592
29593- if (port->count == 1) {
29594+ if (atomic_read(&port->count) == 1) {
29595 /* 1st open on this device, init hardware */
29596 retval = startup(info, tty);
29597 if (retval < 0)
29598@@ -3891,7 +3891,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
29599 unsigned short new_crctype;
29600
29601 /* return error if TTY interface open */
29602- if (info->port.count)
29603+ if (atomic_read(&info->port.count))
29604 return -EBUSY;
29605
29606 switch (encoding)
29607@@ -3994,7 +3994,7 @@ static int hdlcdev_open(struct net_device *dev)
29608
29609 /* arbitrate between network and tty opens */
29610 spin_lock_irqsave(&info->netlock, flags);
29611- if (info->port.count != 0 || info->netcount != 0) {
29612+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
29613 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
29614 spin_unlock_irqrestore(&info->netlock, flags);
29615 return -EBUSY;
29616@@ -4083,7 +4083,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
29617 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
29618
29619 /* return error if TTY interface open */
29620- if (info->port.count)
29621+ if (atomic_read(&info->port.count))
29622 return -EBUSY;
29623
29624 if (cmd != SIOCWANDEV)
29625diff --git a/drivers/char/random.c b/drivers/char/random.c
29626index d98b2a6..f0ceb97 100644
29627--- a/drivers/char/random.c
29628+++ b/drivers/char/random.c
29629@@ -272,8 +272,13 @@
29630 /*
29631 * Configuration information
29632 */
29633+#ifdef CONFIG_GRKERNSEC_RANDNET
29634+#define INPUT_POOL_WORDS 512
29635+#define OUTPUT_POOL_WORDS 128
29636+#else
29637 #define INPUT_POOL_WORDS 128
29638 #define OUTPUT_POOL_WORDS 32
29639+#endif
29640 #define SEC_XFER_SIZE 512
29641 #define EXTRACT_SIZE 10
29642
29643@@ -313,10 +318,17 @@ static struct poolinfo {
29644 int poolwords;
29645 int tap1, tap2, tap3, tap4, tap5;
29646 } poolinfo_table[] = {
29647+#ifdef CONFIG_GRKERNSEC_RANDNET
29648+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29649+ { 512, 411, 308, 208, 104, 1 },
29650+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29651+ { 128, 103, 76, 51, 25, 1 },
29652+#else
29653 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29654 { 128, 103, 76, 51, 25, 1 },
29655 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29656 { 32, 26, 20, 14, 7, 1 },
29657+#endif
29658 #if 0
29659 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29660 { 2048, 1638, 1231, 819, 411, 1 },
29661@@ -527,8 +539,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
29662 input_rotate += i ? 7 : 14;
29663 }
29664
29665- ACCESS_ONCE(r->input_rotate) = input_rotate;
29666- ACCESS_ONCE(r->add_ptr) = i;
29667+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
29668+ ACCESS_ONCE_RW(r->add_ptr) = i;
29669 smp_wmb();
29670
29671 if (out)
29672@@ -799,6 +811,17 @@ void add_disk_randomness(struct gendisk *disk)
29673 }
29674 #endif
29675
29676+#ifdef CONFIG_PAX_LATENT_ENTROPY
29677+u64 latent_entropy;
29678+
29679+__init void transfer_latent_entropy(void)
29680+{
29681+ mix_pool_bytes(&input_pool, &latent_entropy, sizeof(latent_entropy), NULL);
29682+ mix_pool_bytes(&nonblocking_pool, &latent_entropy, sizeof(latent_entropy), NULL);
29683+// printk(KERN_INFO "PAX: transferring latent entropy: %16llx\n", latent_entropy);
29684+}
29685+#endif
29686+
29687 /*********************************************************************
29688 *
29689 * Entropy extraction routines
29690@@ -1008,7 +1031,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29691
29692 extract_buf(r, tmp);
29693 i = min_t(int, nbytes, EXTRACT_SIZE);
29694- if (copy_to_user(buf, tmp, i)) {
29695+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29696 ret = -EFAULT;
29697 break;
29698 }
29699@@ -1342,7 +1365,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29700 #include <linux/sysctl.h>
29701
29702 static int min_read_thresh = 8, min_write_thresh;
29703-static int max_read_thresh = INPUT_POOL_WORDS * 32;
29704+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29705 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29706 static char sysctl_bootid[16];
29707
29708diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
29709index 45713f0..8286d21 100644
29710--- a/drivers/char/sonypi.c
29711+++ b/drivers/char/sonypi.c
29712@@ -54,6 +54,7 @@
29713
29714 #include <asm/uaccess.h>
29715 #include <asm/io.h>
29716+#include <asm/local.h>
29717
29718 #include <linux/sonypi.h>
29719
29720@@ -490,7 +491,7 @@ static struct sonypi_device {
29721 spinlock_t fifo_lock;
29722 wait_queue_head_t fifo_proc_list;
29723 struct fasync_struct *fifo_async;
29724- int open_count;
29725+ local_t open_count;
29726 int model;
29727 struct input_dev *input_jog_dev;
29728 struct input_dev *input_key_dev;
29729@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
29730 static int sonypi_misc_release(struct inode *inode, struct file *file)
29731 {
29732 mutex_lock(&sonypi_device.lock);
29733- sonypi_device.open_count--;
29734+ local_dec(&sonypi_device.open_count);
29735 mutex_unlock(&sonypi_device.lock);
29736 return 0;
29737 }
29738@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
29739 {
29740 mutex_lock(&sonypi_device.lock);
29741 /* Flush input queue on first open */
29742- if (!sonypi_device.open_count)
29743+ if (!local_read(&sonypi_device.open_count))
29744 kfifo_reset(&sonypi_device.fifo);
29745- sonypi_device.open_count++;
29746+ local_inc(&sonypi_device.open_count);
29747 mutex_unlock(&sonypi_device.lock);
29748
29749 return 0;
29750diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
29751index 08427ab..1ab10b7 100644
29752--- a/drivers/char/tpm/tpm.c
29753+++ b/drivers/char/tpm/tpm.c
29754@@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
29755 chip->vendor.req_complete_val)
29756 goto out_recv;
29757
29758- if ((status == chip->vendor.req_canceled)) {
29759+ if (status == chip->vendor.req_canceled) {
29760 dev_err(chip->dev, "Operation Canceled\n");
29761 rc = -ECANCELED;
29762 goto out;
29763diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
29764index 0636520..169c1d0 100644
29765--- a/drivers/char/tpm/tpm_bios.c
29766+++ b/drivers/char/tpm/tpm_bios.c
29767@@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
29768 event = addr;
29769
29770 if ((event->event_type == 0 && event->event_size == 0) ||
29771- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
29772+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
29773 return NULL;
29774
29775 return addr;
29776@@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
29777 return NULL;
29778
29779 if ((event->event_type == 0 && event->event_size == 0) ||
29780- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
29781+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
29782 return NULL;
29783
29784 (*pos)++;
29785@@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
29786 int i;
29787
29788 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
29789- seq_putc(m, data[i]);
29790+ if (!seq_putc(m, data[i]))
29791+ return -EFAULT;
29792
29793 return 0;
29794 }
29795@@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
29796 log->bios_event_log_end = log->bios_event_log + len;
29797
29798 virt = acpi_os_map_memory(start, len);
29799+ if (!virt) {
29800+ kfree(log->bios_event_log);
29801+ log->bios_event_log = NULL;
29802+ return -EFAULT;
29803+ }
29804
29805- memcpy(log->bios_event_log, virt, len);
29806+ memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
29807
29808 acpi_os_unmap_memory(virt, len);
29809 return 0;
29810diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
29811index cdf2f54..e55c197 100644
29812--- a/drivers/char/virtio_console.c
29813+++ b/drivers/char/virtio_console.c
29814@@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
29815 if (to_user) {
29816 ssize_t ret;
29817
29818- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
29819+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
29820 if (ret)
29821 return -EFAULT;
29822 } else {
29823@@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
29824 if (!port_has_data(port) && !port->host_connected)
29825 return 0;
29826
29827- return fill_readbuf(port, ubuf, count, true);
29828+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
29829 }
29830
29831 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
29832diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
29833index 97f5064..202b6e6 100644
29834--- a/drivers/edac/edac_pci_sysfs.c
29835+++ b/drivers/edac/edac_pci_sysfs.c
29836@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
29837 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
29838 static int edac_pci_poll_msec = 1000; /* one second workq period */
29839
29840-static atomic_t pci_parity_count = ATOMIC_INIT(0);
29841-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
29842+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
29843+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
29844
29845 static struct kobject *edac_pci_top_main_kobj;
29846 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
29847@@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29848 edac_printk(KERN_CRIT, EDAC_PCI,
29849 "Signaled System Error on %s\n",
29850 pci_name(dev));
29851- atomic_inc(&pci_nonparity_count);
29852+ atomic_inc_unchecked(&pci_nonparity_count);
29853 }
29854
29855 if (status & (PCI_STATUS_PARITY)) {
29856@@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29857 "Master Data Parity Error on %s\n",
29858 pci_name(dev));
29859
29860- atomic_inc(&pci_parity_count);
29861+ atomic_inc_unchecked(&pci_parity_count);
29862 }
29863
29864 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29865@@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29866 "Detected Parity Error on %s\n",
29867 pci_name(dev));
29868
29869- atomic_inc(&pci_parity_count);
29870+ atomic_inc_unchecked(&pci_parity_count);
29871 }
29872 }
29873
29874@@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29875 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
29876 "Signaled System Error on %s\n",
29877 pci_name(dev));
29878- atomic_inc(&pci_nonparity_count);
29879+ atomic_inc_unchecked(&pci_nonparity_count);
29880 }
29881
29882 if (status & (PCI_STATUS_PARITY)) {
29883@@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29884 "Master Data Parity Error on "
29885 "%s\n", pci_name(dev));
29886
29887- atomic_inc(&pci_parity_count);
29888+ atomic_inc_unchecked(&pci_parity_count);
29889 }
29890
29891 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29892@@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29893 "Detected Parity Error on %s\n",
29894 pci_name(dev));
29895
29896- atomic_inc(&pci_parity_count);
29897+ atomic_inc_unchecked(&pci_parity_count);
29898 }
29899 }
29900 }
29901@@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
29902 if (!check_pci_errors)
29903 return;
29904
29905- before_count = atomic_read(&pci_parity_count);
29906+ before_count = atomic_read_unchecked(&pci_parity_count);
29907
29908 /* scan all PCI devices looking for a Parity Error on devices and
29909 * bridges.
29910@@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
29911 /* Only if operator has selected panic on PCI Error */
29912 if (edac_pci_get_panic_on_pe()) {
29913 /* If the count is different 'after' from 'before' */
29914- if (before_count != atomic_read(&pci_parity_count))
29915+ if (before_count != atomic_read_unchecked(&pci_parity_count))
29916 panic("EDAC: PCI Parity Error");
29917 }
29918 }
29919diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
29920index 8c87a5e..a19cbd7 100644
29921--- a/drivers/edac/mce_amd.h
29922+++ b/drivers/edac/mce_amd.h
29923@@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
29924 struct amd_decoder_ops {
29925 bool (*dc_mce)(u16, u8);
29926 bool (*ic_mce)(u16, u8);
29927-};
29928+} __no_const;
29929
29930 void amd_report_gart_errors(bool);
29931 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
29932diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
29933index 57ea7f4..789e3c3 100644
29934--- a/drivers/firewire/core-card.c
29935+++ b/drivers/firewire/core-card.c
29936@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
29937
29938 void fw_core_remove_card(struct fw_card *card)
29939 {
29940- struct fw_card_driver dummy_driver = dummy_driver_template;
29941+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
29942
29943 card->driver->update_phy_reg(card, 4,
29944 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
29945diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
29946index 2783f69..9f4b0cc 100644
29947--- a/drivers/firewire/core-cdev.c
29948+++ b/drivers/firewire/core-cdev.c
29949@@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
29950 int ret;
29951
29952 if ((request->channels == 0 && request->bandwidth == 0) ||
29953- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
29954- request->bandwidth < 0)
29955+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
29956 return -EINVAL;
29957
29958 r = kmalloc(sizeof(*r), GFP_KERNEL);
29959diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
29960index 780708d..ad60a66 100644
29961--- a/drivers/firewire/core-transaction.c
29962+++ b/drivers/firewire/core-transaction.c
29963@@ -37,6 +37,7 @@
29964 #include <linux/timer.h>
29965 #include <linux/types.h>
29966 #include <linux/workqueue.h>
29967+#include <linux/sched.h>
29968
29969 #include <asm/byteorder.h>
29970
29971diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
29972index 515a42c..5ecf3ba 100644
29973--- a/drivers/firewire/core.h
29974+++ b/drivers/firewire/core.h
29975@@ -111,6 +111,7 @@ struct fw_card_driver {
29976
29977 int (*stop_iso)(struct fw_iso_context *ctx);
29978 };
29979+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
29980
29981 void fw_card_initialize(struct fw_card *card,
29982 const struct fw_card_driver *driver, struct device *device);
29983diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
29984index b298158..7ed8432 100644
29985--- a/drivers/firmware/dmi_scan.c
29986+++ b/drivers/firmware/dmi_scan.c
29987@@ -452,11 +452,6 @@ void __init dmi_scan_machine(void)
29988 }
29989 }
29990 else {
29991- /*
29992- * no iounmap() for that ioremap(); it would be a no-op, but
29993- * it's so early in setup that sucker gets confused into doing
29994- * what it shouldn't if we actually call it.
29995- */
29996 p = dmi_ioremap(0xF0000, 0x10000);
29997 if (p == NULL)
29998 goto error;
29999@@ -726,7 +721,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30000 if (buf == NULL)
30001 return -1;
30002
30003- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30004+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30005
30006 iounmap(buf);
30007 return 0;
30008diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30009index 82d5c20..44a7177 100644
30010--- a/drivers/gpio/gpio-vr41xx.c
30011+++ b/drivers/gpio/gpio-vr41xx.c
30012@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30013 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30014 maskl, pendl, maskh, pendh);
30015
30016- atomic_inc(&irq_err_count);
30017+ atomic_inc_unchecked(&irq_err_count);
30018
30019 return -EINVAL;
30020 }
30021diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30022index 3252e70..b5314ace 100644
30023--- a/drivers/gpu/drm/drm_crtc_helper.c
30024+++ b/drivers/gpu/drm/drm_crtc_helper.c
30025@@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30026 struct drm_crtc *tmp;
30027 int crtc_mask = 1;
30028
30029- WARN(!crtc, "checking null crtc?\n");
30030+ BUG_ON(!crtc);
30031
30032 dev = crtc->dev;
30033
30034diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30035index 8a9d079..606cdd5 100644
30036--- a/drivers/gpu/drm/drm_drv.c
30037+++ b/drivers/gpu/drm/drm_drv.c
30038@@ -318,7 +318,7 @@ module_exit(drm_core_exit);
30039 /**
30040 * Copy and IOCTL return string to user space
30041 */
30042-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30043+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30044 {
30045 int len;
30046
30047@@ -401,7 +401,7 @@ long drm_ioctl(struct file *filp,
30048 return -ENODEV;
30049
30050 atomic_inc(&dev->ioctl_count);
30051- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30052+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30053 ++file_priv->ioctl_count;
30054
30055 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30056diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30057index 123de28..43a0897 100644
30058--- a/drivers/gpu/drm/drm_fops.c
30059+++ b/drivers/gpu/drm/drm_fops.c
30060@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30061 }
30062
30063 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30064- atomic_set(&dev->counts[i], 0);
30065+ atomic_set_unchecked(&dev->counts[i], 0);
30066
30067 dev->sigdata.lock = NULL;
30068
30069@@ -138,8 +138,8 @@ int drm_open(struct inode *inode, struct file *filp)
30070
30071 retcode = drm_open_helper(inode, filp, dev);
30072 if (!retcode) {
30073- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30074- if (!dev->open_count++)
30075+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30076+ if (local_inc_return(&dev->open_count) == 1)
30077 retcode = drm_setup(dev);
30078 }
30079 if (!retcode) {
30080@@ -482,7 +482,7 @@ int drm_release(struct inode *inode, struct file *filp)
30081
30082 mutex_lock(&drm_global_mutex);
30083
30084- DRM_DEBUG("open_count = %d\n", dev->open_count);
30085+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30086
30087 if (dev->driver->preclose)
30088 dev->driver->preclose(dev, file_priv);
30089@@ -491,10 +491,10 @@ int drm_release(struct inode *inode, struct file *filp)
30090 * Begin inline drm_release
30091 */
30092
30093- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30094+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30095 task_pid_nr(current),
30096 (long)old_encode_dev(file_priv->minor->device),
30097- dev->open_count);
30098+ local_read(&dev->open_count));
30099
30100 /* Release any auth tokens that might point to this file_priv,
30101 (do that under the drm_global_mutex) */
30102@@ -584,8 +584,8 @@ int drm_release(struct inode *inode, struct file *filp)
30103 * End inline drm_release
30104 */
30105
30106- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30107- if (!--dev->open_count) {
30108+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30109+ if (local_dec_and_test(&dev->open_count)) {
30110 if (atomic_read(&dev->ioctl_count)) {
30111 DRM_ERROR("Device busy: %d\n",
30112 atomic_read(&dev->ioctl_count));
30113diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30114index c87dc96..326055d 100644
30115--- a/drivers/gpu/drm/drm_global.c
30116+++ b/drivers/gpu/drm/drm_global.c
30117@@ -36,7 +36,7 @@
30118 struct drm_global_item {
30119 struct mutex mutex;
30120 void *object;
30121- int refcount;
30122+ atomic_t refcount;
30123 };
30124
30125 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30126@@ -49,7 +49,7 @@ void drm_global_init(void)
30127 struct drm_global_item *item = &glob[i];
30128 mutex_init(&item->mutex);
30129 item->object = NULL;
30130- item->refcount = 0;
30131+ atomic_set(&item->refcount, 0);
30132 }
30133 }
30134
30135@@ -59,7 +59,7 @@ void drm_global_release(void)
30136 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30137 struct drm_global_item *item = &glob[i];
30138 BUG_ON(item->object != NULL);
30139- BUG_ON(item->refcount != 0);
30140+ BUG_ON(atomic_read(&item->refcount) != 0);
30141 }
30142 }
30143
30144@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30145 void *object;
30146
30147 mutex_lock(&item->mutex);
30148- if (item->refcount == 0) {
30149+ if (atomic_read(&item->refcount) == 0) {
30150 item->object = kzalloc(ref->size, GFP_KERNEL);
30151 if (unlikely(item->object == NULL)) {
30152 ret = -ENOMEM;
30153@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30154 goto out_err;
30155
30156 }
30157- ++item->refcount;
30158+ atomic_inc(&item->refcount);
30159 ref->object = item->object;
30160 object = item->object;
30161 mutex_unlock(&item->mutex);
30162@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30163 struct drm_global_item *item = &glob[ref->global_type];
30164
30165 mutex_lock(&item->mutex);
30166- BUG_ON(item->refcount == 0);
30167+ BUG_ON(atomic_read(&item->refcount) == 0);
30168 BUG_ON(ref->object != item->object);
30169- if (--item->refcount == 0) {
30170+ if (atomic_dec_and_test(&item->refcount)) {
30171 ref->release(ref);
30172 item->object = NULL;
30173 }
30174diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30175index ab1162d..42587b2 100644
30176--- a/drivers/gpu/drm/drm_info.c
30177+++ b/drivers/gpu/drm/drm_info.c
30178@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30179 struct drm_local_map *map;
30180 struct drm_map_list *r_list;
30181
30182- /* Hardcoded from _DRM_FRAME_BUFFER,
30183- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30184- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30185- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30186+ static const char * const types[] = {
30187+ [_DRM_FRAME_BUFFER] = "FB",
30188+ [_DRM_REGISTERS] = "REG",
30189+ [_DRM_SHM] = "SHM",
30190+ [_DRM_AGP] = "AGP",
30191+ [_DRM_SCATTER_GATHER] = "SG",
30192+ [_DRM_CONSISTENT] = "PCI",
30193+ [_DRM_GEM] = "GEM" };
30194 const char *type;
30195 int i;
30196
30197@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30198 map = r_list->map;
30199 if (!map)
30200 continue;
30201- if (map->type < 0 || map->type > 5)
30202+ if (map->type >= ARRAY_SIZE(types))
30203 type = "??";
30204 else
30205 type = types[map->type];
30206@@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30207 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30208 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30209 vma->vm_flags & VM_IO ? 'i' : '-',
30210+#ifdef CONFIG_GRKERNSEC_HIDESYM
30211+ 0);
30212+#else
30213 vma->vm_pgoff);
30214+#endif
30215
30216 #if defined(__i386__)
30217 pgprot = pgprot_val(vma->vm_page_prot);
30218diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30219index 637fcc3..e890b33 100644
30220--- a/drivers/gpu/drm/drm_ioc32.c
30221+++ b/drivers/gpu/drm/drm_ioc32.c
30222@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30223 request = compat_alloc_user_space(nbytes);
30224 if (!access_ok(VERIFY_WRITE, request, nbytes))
30225 return -EFAULT;
30226- list = (struct drm_buf_desc *) (request + 1);
30227+ list = (struct drm_buf_desc __user *) (request + 1);
30228
30229 if (__put_user(count, &request->count)
30230 || __put_user(list, &request->list))
30231@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30232 request = compat_alloc_user_space(nbytes);
30233 if (!access_ok(VERIFY_WRITE, request, nbytes))
30234 return -EFAULT;
30235- list = (struct drm_buf_pub *) (request + 1);
30236+ list = (struct drm_buf_pub __user *) (request + 1);
30237
30238 if (__put_user(count, &request->count)
30239 || __put_user(list, &request->list))
30240diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30241index 64a62c6..ceab35e 100644
30242--- a/drivers/gpu/drm/drm_ioctl.c
30243+++ b/drivers/gpu/drm/drm_ioctl.c
30244@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30245 stats->data[i].value =
30246 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30247 else
30248- stats->data[i].value = atomic_read(&dev->counts[i]);
30249+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30250 stats->data[i].type = dev->types[i];
30251 }
30252
30253diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30254index 5211520..c744d85 100644
30255--- a/drivers/gpu/drm/drm_lock.c
30256+++ b/drivers/gpu/drm/drm_lock.c
30257@@ -90,7 +90,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30258 if (drm_lock_take(&master->lock, lock->context)) {
30259 master->lock.file_priv = file_priv;
30260 master->lock.lock_time = jiffies;
30261- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30262+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30263 break; /* Got lock */
30264 }
30265
30266@@ -161,7 +161,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30267 return -EINVAL;
30268 }
30269
30270- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30271+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30272
30273 if (drm_lock_free(&master->lock, lock->context)) {
30274 /* FIXME: Should really bail out here. */
30275diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30276index 21bcd4a..8e074e0 100644
30277--- a/drivers/gpu/drm/drm_stub.c
30278+++ b/drivers/gpu/drm/drm_stub.c
30279@@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
30280
30281 drm_device_set_unplugged(dev);
30282
30283- if (dev->open_count == 0) {
30284+ if (local_read(&dev->open_count) == 0) {
30285 drm_put_dev(dev);
30286 }
30287 mutex_unlock(&drm_global_mutex);
30288diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30289index fa94391..ed26ec8 100644
30290--- a/drivers/gpu/drm/i810/i810_dma.c
30291+++ b/drivers/gpu/drm/i810/i810_dma.c
30292@@ -943,8 +943,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30293 dma->buflist[vertex->idx],
30294 vertex->discard, vertex->used);
30295
30296- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30297- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30298+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30299+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30300 sarea_priv->last_enqueue = dev_priv->counter - 1;
30301 sarea_priv->last_dispatch = (int)hw_status[5];
30302
30303@@ -1104,8 +1104,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30304 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30305 mc->last_render);
30306
30307- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30308- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30309+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30310+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30311 sarea_priv->last_enqueue = dev_priv->counter - 1;
30312 sarea_priv->last_dispatch = (int)hw_status[5];
30313
30314diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30315index c9339f4..f5e1b9d 100644
30316--- a/drivers/gpu/drm/i810/i810_drv.h
30317+++ b/drivers/gpu/drm/i810/i810_drv.h
30318@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30319 int page_flipping;
30320
30321 wait_queue_head_t irq_queue;
30322- atomic_t irq_received;
30323- atomic_t irq_emitted;
30324+ atomic_unchecked_t irq_received;
30325+ atomic_unchecked_t irq_emitted;
30326
30327 int front_offset;
30328 } drm_i810_private_t;
30329diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30330index 5363e9c..59360d1 100644
30331--- a/drivers/gpu/drm/i915/i915_debugfs.c
30332+++ b/drivers/gpu/drm/i915/i915_debugfs.c
30333@@ -518,7 +518,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30334 I915_READ(GTIMR));
30335 }
30336 seq_printf(m, "Interrupts received: %d\n",
30337- atomic_read(&dev_priv->irq_received));
30338+ atomic_read_unchecked(&dev_priv->irq_received));
30339 for (i = 0; i < I915_NUM_RINGS; i++) {
30340 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30341 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30342diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30343index 36822b9..b725e1b 100644
30344--- a/drivers/gpu/drm/i915/i915_dma.c
30345+++ b/drivers/gpu/drm/i915/i915_dma.c
30346@@ -1266,7 +1266,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30347 bool can_switch;
30348
30349 spin_lock(&dev->count_lock);
30350- can_switch = (dev->open_count == 0);
30351+ can_switch = (local_read(&dev->open_count) == 0);
30352 spin_unlock(&dev->count_lock);
30353 return can_switch;
30354 }
30355diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30356index b0b676a..d107105 100644
30357--- a/drivers/gpu/drm/i915/i915_drv.h
30358+++ b/drivers/gpu/drm/i915/i915_drv.h
30359@@ -268,7 +268,7 @@ struct drm_i915_display_funcs {
30360 /* render clock increase/decrease */
30361 /* display clock increase/decrease */
30362 /* pll clock increase/decrease */
30363-};
30364+} __no_const;
30365
30366 struct intel_device_info {
30367 u8 gen;
30368@@ -386,7 +386,7 @@ typedef struct drm_i915_private {
30369 int current_page;
30370 int page_flipping;
30371
30372- atomic_t irq_received;
30373+ atomic_unchecked_t irq_received;
30374
30375 /* protects the irq masks */
30376 spinlock_t irq_lock;
30377@@ -985,7 +985,7 @@ struct drm_i915_gem_object {
30378 * will be page flipped away on the next vblank. When it
30379 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30380 */
30381- atomic_t pending_flip;
30382+ atomic_unchecked_t pending_flip;
30383 };
30384
30385 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30386@@ -1434,7 +1434,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
30387 struct drm_i915_private *dev_priv, unsigned port);
30388 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30389 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30390-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30391+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30392 {
30393 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30394 }
30395diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30396index 974a9f1..b3ebd45 100644
30397--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30398+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30399@@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30400 i915_gem_clflush_object(obj);
30401
30402 if (obj->base.pending_write_domain)
30403- cd->flips |= atomic_read(&obj->pending_flip);
30404+ cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30405
30406 /* The actual obj->write_domain will be updated with
30407 * pending_write_domain after we emit the accumulated flush for all
30408@@ -916,9 +916,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30409
30410 static int
30411 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30412- int count)
30413+ unsigned int count)
30414 {
30415- int i;
30416+ unsigned int i;
30417
30418 for (i = 0; i < count; i++) {
30419 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30420diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30421index ed3224c..6618589 100644
30422--- a/drivers/gpu/drm/i915/i915_irq.c
30423+++ b/drivers/gpu/drm/i915/i915_irq.c
30424@@ -433,7 +433,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
30425 int vblank = 0;
30426 bool blc_event;
30427
30428- atomic_inc(&dev_priv->irq_received);
30429+ atomic_inc_unchecked(&dev_priv->irq_received);
30430
30431 vblank_status = PIPE_START_VBLANK_INTERRUPT_STATUS |
30432 PIPE_VBLANK_INTERRUPT_STATUS;
30433@@ -586,7 +586,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30434 irqreturn_t ret = IRQ_NONE;
30435 int i;
30436
30437- atomic_inc(&dev_priv->irq_received);
30438+ atomic_inc_unchecked(&dev_priv->irq_received);
30439
30440 /* disable master interrupt before clearing iir */
30441 de_ier = I915_READ(DEIER);
30442@@ -661,7 +661,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30443 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30444 u32 hotplug_mask;
30445
30446- atomic_inc(&dev_priv->irq_received);
30447+ atomic_inc_unchecked(&dev_priv->irq_received);
30448
30449 /* disable master interrupt before clearing iir */
30450 de_ier = I915_READ(DEIER);
30451@@ -1646,7 +1646,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30452 {
30453 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30454
30455- atomic_set(&dev_priv->irq_received, 0);
30456+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30457
30458
30459 I915_WRITE(HWSTAM, 0xeffe);
30460@@ -1673,7 +1673,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
30461 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30462 int pipe;
30463
30464- atomic_set(&dev_priv->irq_received, 0);
30465+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30466
30467 /* VLV magic */
30468 I915_WRITE(VLV_IMR, 0);
30469@@ -1969,7 +1969,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
30470 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30471 int pipe;
30472
30473- atomic_set(&dev_priv->irq_received, 0);
30474+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30475
30476 for_each_pipe(pipe)
30477 I915_WRITE(PIPESTAT(pipe), 0);
30478@@ -2020,7 +2020,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
30479 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
30480 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
30481
30482- atomic_inc(&dev_priv->irq_received);
30483+ atomic_inc_unchecked(&dev_priv->irq_received);
30484
30485 iir = I915_READ16(IIR);
30486 if (iir == 0)
30487@@ -2105,7 +2105,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
30488 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30489 int pipe;
30490
30491- atomic_set(&dev_priv->irq_received, 0);
30492+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30493
30494 if (I915_HAS_HOTPLUG(dev)) {
30495 I915_WRITE(PORT_HOTPLUG_EN, 0);
30496@@ -2200,7 +2200,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
30497 };
30498 int pipe, ret = IRQ_NONE;
30499
30500- atomic_inc(&dev_priv->irq_received);
30501+ atomic_inc_unchecked(&dev_priv->irq_received);
30502
30503 iir = I915_READ(IIR);
30504 do {
30505@@ -2326,7 +2326,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
30506 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30507 int pipe;
30508
30509- atomic_set(&dev_priv->irq_received, 0);
30510+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30511
30512 if (I915_HAS_HOTPLUG(dev)) {
30513 I915_WRITE(PORT_HOTPLUG_EN, 0);
30514@@ -2436,7 +2436,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
30515 int irq_received;
30516 int ret = IRQ_NONE, pipe;
30517
30518- atomic_inc(&dev_priv->irq_received);
30519+ atomic_inc_unchecked(&dev_priv->irq_received);
30520
30521 iir = I915_READ(IIR);
30522
30523diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30524index a8538ac..4868a05 100644
30525--- a/drivers/gpu/drm/i915/intel_display.c
30526+++ b/drivers/gpu/drm/i915/intel_display.c
30527@@ -2000,7 +2000,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
30528
30529 wait_event(dev_priv->pending_flip_queue,
30530 atomic_read(&dev_priv->mm.wedged) ||
30531- atomic_read(&obj->pending_flip) == 0);
30532+ atomic_read_unchecked(&obj->pending_flip) == 0);
30533
30534 /* Big Hammer, we also need to ensure that any pending
30535 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30536@@ -5925,9 +5925,8 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30537
30538 obj = work->old_fb_obj;
30539
30540- atomic_clear_mask(1 << intel_crtc->plane,
30541- &obj->pending_flip.counter);
30542- if (atomic_read(&obj->pending_flip) == 0)
30543+ atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
30544+ if (atomic_read_unchecked(&obj->pending_flip) == 0)
30545 wake_up(&dev_priv->pending_flip_queue);
30546
30547 schedule_work(&work->work);
30548@@ -6264,7 +6263,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30549 /* Block clients from rendering to the new back buffer until
30550 * the flip occurs and the object is no longer visible.
30551 */
30552- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30553+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30554
30555 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30556 if (ret)
30557@@ -6279,7 +6278,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30558 return 0;
30559
30560 cleanup_pending:
30561- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30562+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30563 drm_gem_object_unreference(&work->old_fb_obj->base);
30564 drm_gem_object_unreference(&obj->base);
30565 mutex_unlock(&dev->struct_mutex);
30566diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30567index 54558a0..2d97005 100644
30568--- a/drivers/gpu/drm/mga/mga_drv.h
30569+++ b/drivers/gpu/drm/mga/mga_drv.h
30570@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30571 u32 clear_cmd;
30572 u32 maccess;
30573
30574- atomic_t vbl_received; /**< Number of vblanks received. */
30575+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30576 wait_queue_head_t fence_queue;
30577- atomic_t last_fence_retired;
30578+ atomic_unchecked_t last_fence_retired;
30579 u32 next_fence_to_post;
30580
30581 unsigned int fb_cpp;
30582diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30583index 2581202..f230a8d9 100644
30584--- a/drivers/gpu/drm/mga/mga_irq.c
30585+++ b/drivers/gpu/drm/mga/mga_irq.c
30586@@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30587 if (crtc != 0)
30588 return 0;
30589
30590- return atomic_read(&dev_priv->vbl_received);
30591+ return atomic_read_unchecked(&dev_priv->vbl_received);
30592 }
30593
30594
30595@@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30596 /* VBLANK interrupt */
30597 if (status & MGA_VLINEPEN) {
30598 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30599- atomic_inc(&dev_priv->vbl_received);
30600+ atomic_inc_unchecked(&dev_priv->vbl_received);
30601 drm_handle_vblank(dev, 0);
30602 handled = 1;
30603 }
30604@@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30605 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30606 MGA_WRITE(MGA_PRIMEND, prim_end);
30607
30608- atomic_inc(&dev_priv->last_fence_retired);
30609+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
30610 DRM_WAKEUP(&dev_priv->fence_queue);
30611 handled = 1;
30612 }
30613@@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30614 * using fences.
30615 */
30616 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30617- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30618+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30619 - *sequence) <= (1 << 23)));
30620
30621 *sequence = cur_fence;
30622diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30623index 2f11e16..191267e 100644
30624--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30625+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30626@@ -5340,7 +5340,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30627 struct bit_table {
30628 const char id;
30629 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30630-};
30631+} __no_const;
30632
30633 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30634
30635diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30636index b863a3a..c55e0dc 100644
30637--- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30638+++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30639@@ -302,7 +302,7 @@ struct nouveau_exec_engine {
30640 u32 handle, u16 class);
30641 void (*set_tile_region)(struct drm_device *dev, int i);
30642 void (*tlb_flush)(struct drm_device *, int engine);
30643-};
30644+} __no_const;
30645
30646 struct nouveau_instmem_engine {
30647 void *priv;
30648@@ -324,13 +324,13 @@ struct nouveau_instmem_engine {
30649 struct nouveau_mc_engine {
30650 int (*init)(struct drm_device *dev);
30651 void (*takedown)(struct drm_device *dev);
30652-};
30653+} __no_const;
30654
30655 struct nouveau_timer_engine {
30656 int (*init)(struct drm_device *dev);
30657 void (*takedown)(struct drm_device *dev);
30658 uint64_t (*read)(struct drm_device *dev);
30659-};
30660+} __no_const;
30661
30662 struct nouveau_fb_engine {
30663 int num_tiles;
30664@@ -547,7 +547,7 @@ struct nouveau_vram_engine {
30665 void (*put)(struct drm_device *, struct nouveau_mem **);
30666
30667 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30668-};
30669+} __no_const;
30670
30671 struct nouveau_engine {
30672 struct nouveau_instmem_engine instmem;
30673@@ -693,7 +693,7 @@ struct drm_nouveau_private {
30674 struct drm_global_reference mem_global_ref;
30675 struct ttm_bo_global_ref bo_global_ref;
30676 struct ttm_bo_device bdev;
30677- atomic_t validate_sequence;
30678+ atomic_unchecked_t validate_sequence;
30679 int (*move)(struct nouveau_channel *,
30680 struct ttm_buffer_object *,
30681 struct ttm_mem_reg *, struct ttm_mem_reg *);
30682diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30683index 30f5423..abca136 100644
30684--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30685+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30686@@ -319,7 +319,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30687 int trycnt = 0;
30688 int ret, i;
30689
30690- sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30691+ sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30692 retry:
30693 if (++trycnt > 100000) {
30694 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30695diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30696index 19706f0..f257368 100644
30697--- a/drivers/gpu/drm/nouveau/nouveau_state.c
30698+++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30699@@ -490,7 +490,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30700 bool can_switch;
30701
30702 spin_lock(&dev->count_lock);
30703- can_switch = (dev->open_count == 0);
30704+ can_switch = (local_read(&dev->open_count) == 0);
30705 spin_unlock(&dev->count_lock);
30706 return can_switch;
30707 }
30708diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
30709index a9514ea..369d511 100644
30710--- a/drivers/gpu/drm/nouveau/nv50_sor.c
30711+++ b/drivers/gpu/drm/nouveau/nv50_sor.c
30712@@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
30713 }
30714
30715 if (nv_encoder->dcb->type == OUTPUT_DP) {
30716- struct dp_train_func func = {
30717+ static struct dp_train_func func = {
30718 .link_set = nv50_sor_dp_link_set,
30719 .train_set = nv50_sor_dp_train_set,
30720 .train_adj = nv50_sor_dp_train_adj
30721diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
30722index c486d3c..3a7d6f4 100644
30723--- a/drivers/gpu/drm/nouveau/nvd0_display.c
30724+++ b/drivers/gpu/drm/nouveau/nvd0_display.c
30725@@ -1366,7 +1366,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
30726 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
30727
30728 if (nv_encoder->dcb->type == OUTPUT_DP) {
30729- struct dp_train_func func = {
30730+ static struct dp_train_func func = {
30731 .link_set = nvd0_sor_dp_link_set,
30732 .train_set = nvd0_sor_dp_train_set,
30733 .train_adj = nvd0_sor_dp_train_adj
30734diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
30735index bcac90b..53bfc76 100644
30736--- a/drivers/gpu/drm/r128/r128_cce.c
30737+++ b/drivers/gpu/drm/r128/r128_cce.c
30738@@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
30739
30740 /* GH: Simple idle check.
30741 */
30742- atomic_set(&dev_priv->idle_count, 0);
30743+ atomic_set_unchecked(&dev_priv->idle_count, 0);
30744
30745 /* We don't support anything other than bus-mastering ring mode,
30746 * but the ring can be in either AGP or PCI space for the ring
30747diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
30748index 930c71b..499aded 100644
30749--- a/drivers/gpu/drm/r128/r128_drv.h
30750+++ b/drivers/gpu/drm/r128/r128_drv.h
30751@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
30752 int is_pci;
30753 unsigned long cce_buffers_offset;
30754
30755- atomic_t idle_count;
30756+ atomic_unchecked_t idle_count;
30757
30758 int page_flipping;
30759 int current_page;
30760 u32 crtc_offset;
30761 u32 crtc_offset_cntl;
30762
30763- atomic_t vbl_received;
30764+ atomic_unchecked_t vbl_received;
30765
30766 u32 color_fmt;
30767 unsigned int front_offset;
30768diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
30769index 429d5a0..7e899ed 100644
30770--- a/drivers/gpu/drm/r128/r128_irq.c
30771+++ b/drivers/gpu/drm/r128/r128_irq.c
30772@@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
30773 if (crtc != 0)
30774 return 0;
30775
30776- return atomic_read(&dev_priv->vbl_received);
30777+ return atomic_read_unchecked(&dev_priv->vbl_received);
30778 }
30779
30780 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30781@@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30782 /* VBLANK interrupt */
30783 if (status & R128_CRTC_VBLANK_INT) {
30784 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
30785- atomic_inc(&dev_priv->vbl_received);
30786+ atomic_inc_unchecked(&dev_priv->vbl_received);
30787 drm_handle_vblank(dev, 0);
30788 return IRQ_HANDLED;
30789 }
30790diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
30791index a9e33ce..09edd4b 100644
30792--- a/drivers/gpu/drm/r128/r128_state.c
30793+++ b/drivers/gpu/drm/r128/r128_state.c
30794@@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
30795
30796 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
30797 {
30798- if (atomic_read(&dev_priv->idle_count) == 0)
30799+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
30800 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
30801 else
30802- atomic_set(&dev_priv->idle_count, 0);
30803+ atomic_set_unchecked(&dev_priv->idle_count, 0);
30804 }
30805
30806 #endif
30807diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
30808index 5a82b6b..9e69c73 100644
30809--- a/drivers/gpu/drm/radeon/mkregtable.c
30810+++ b/drivers/gpu/drm/radeon/mkregtable.c
30811@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
30812 regex_t mask_rex;
30813 regmatch_t match[4];
30814 char buf[1024];
30815- size_t end;
30816+ long end;
30817 int len;
30818 int done = 0;
30819 int r;
30820 unsigned o;
30821 struct offset *offset;
30822 char last_reg_s[10];
30823- int last_reg;
30824+ unsigned long last_reg;
30825
30826 if (regcomp
30827 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
30828diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
30829index fefcca5..20a5b90 100644
30830--- a/drivers/gpu/drm/radeon/radeon.h
30831+++ b/drivers/gpu/drm/radeon/radeon.h
30832@@ -743,7 +743,7 @@ struct r600_blit_cp_primitives {
30833 int x2, int y2);
30834 void (*draw_auto)(struct radeon_device *rdev);
30835 void (*set_default_state)(struct radeon_device *rdev);
30836-};
30837+} __no_const;
30838
30839 struct r600_blit {
30840 struct radeon_bo *shader_obj;
30841@@ -1244,7 +1244,7 @@ struct radeon_asic {
30842 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
30843 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
30844 } pflip;
30845-};
30846+} __no_const;
30847
30848 /*
30849 * Asic structures
30850diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
30851index 066c98b..96ab858 100644
30852--- a/drivers/gpu/drm/radeon/radeon_device.c
30853+++ b/drivers/gpu/drm/radeon/radeon_device.c
30854@@ -692,7 +692,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
30855 bool can_switch;
30856
30857 spin_lock(&dev->count_lock);
30858- can_switch = (dev->open_count == 0);
30859+ can_switch = (local_read(&dev->open_count) == 0);
30860 spin_unlock(&dev->count_lock);
30861 return can_switch;
30862 }
30863diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
30864index a1b59ca..86f2d44 100644
30865--- a/drivers/gpu/drm/radeon/radeon_drv.h
30866+++ b/drivers/gpu/drm/radeon/radeon_drv.h
30867@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
30868
30869 /* SW interrupt */
30870 wait_queue_head_t swi_queue;
30871- atomic_t swi_emitted;
30872+ atomic_unchecked_t swi_emitted;
30873 int vblank_crtc;
30874 uint32_t irq_enable_reg;
30875 uint32_t r500_disp_irq_reg;
30876diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
30877index 48b7cea..342236f 100644
30878--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
30879+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
30880@@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
30881 request = compat_alloc_user_space(sizeof(*request));
30882 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
30883 || __put_user(req32.param, &request->param)
30884- || __put_user((void __user *)(unsigned long)req32.value,
30885+ || __put_user((unsigned long)req32.value,
30886 &request->value))
30887 return -EFAULT;
30888
30889diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
30890index 00da384..32f972d 100644
30891--- a/drivers/gpu/drm/radeon/radeon_irq.c
30892+++ b/drivers/gpu/drm/radeon/radeon_irq.c
30893@@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
30894 unsigned int ret;
30895 RING_LOCALS;
30896
30897- atomic_inc(&dev_priv->swi_emitted);
30898- ret = atomic_read(&dev_priv->swi_emitted);
30899+ atomic_inc_unchecked(&dev_priv->swi_emitted);
30900+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
30901
30902 BEGIN_RING(4);
30903 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
30904@@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
30905 drm_radeon_private_t *dev_priv =
30906 (drm_radeon_private_t *) dev->dev_private;
30907
30908- atomic_set(&dev_priv->swi_emitted, 0);
30909+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
30910 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
30911
30912 dev->max_vblank_count = 0x001fffff;
30913diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
30914index e8422ae..d22d4a8 100644
30915--- a/drivers/gpu/drm/radeon/radeon_state.c
30916+++ b/drivers/gpu/drm/radeon/radeon_state.c
30917@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
30918 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
30919 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
30920
30921- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30922+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30923 sarea_priv->nbox * sizeof(depth_boxes[0])))
30924 return -EFAULT;
30925
30926@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
30927 {
30928 drm_radeon_private_t *dev_priv = dev->dev_private;
30929 drm_radeon_getparam_t *param = data;
30930- int value;
30931+ int value = 0;
30932
30933 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
30934
30935diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
30936index c94a225..5795d34 100644
30937--- a/drivers/gpu/drm/radeon/radeon_ttm.c
30938+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
30939@@ -852,8 +852,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
30940 }
30941 if (unlikely(ttm_vm_ops == NULL)) {
30942 ttm_vm_ops = vma->vm_ops;
30943- radeon_ttm_vm_ops = *ttm_vm_ops;
30944- radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30945+ pax_open_kernel();
30946+ memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
30947+ *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30948+ pax_close_kernel();
30949 }
30950 vma->vm_ops = &radeon_ttm_vm_ops;
30951 return 0;
30952diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
30953index 159b6a4..fa82487 100644
30954--- a/drivers/gpu/drm/radeon/rs690.c
30955+++ b/drivers/gpu/drm/radeon/rs690.c
30956@@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
30957 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
30958 rdev->pm.sideport_bandwidth.full)
30959 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
30960- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
30961+ read_delay_latency.full = dfixed_const(800 * 1000);
30962 read_delay_latency.full = dfixed_div(read_delay_latency,
30963 rdev->pm.igp_sideport_mclk);
30964+ a.full = dfixed_const(370);
30965+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
30966 } else {
30967 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
30968 rdev->pm.k8_bandwidth.full)
30969diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30970index ebc6fac..a8313ed 100644
30971--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
30972+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
30973@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
30974 static int ttm_pool_mm_shrink(struct shrinker *shrink,
30975 struct shrink_control *sc)
30976 {
30977- static atomic_t start_pool = ATOMIC_INIT(0);
30978+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
30979 unsigned i;
30980- unsigned pool_offset = atomic_add_return(1, &start_pool);
30981+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
30982 struct ttm_page_pool *pool;
30983 int shrink_pages = sc->nr_to_scan;
30984
30985diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
30986index 88edacc..1e5412b 100644
30987--- a/drivers/gpu/drm/via/via_drv.h
30988+++ b/drivers/gpu/drm/via/via_drv.h
30989@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
30990 typedef uint32_t maskarray_t[5];
30991
30992 typedef struct drm_via_irq {
30993- atomic_t irq_received;
30994+ atomic_unchecked_t irq_received;
30995 uint32_t pending_mask;
30996 uint32_t enable_mask;
30997 wait_queue_head_t irq_queue;
30998@@ -75,7 +75,7 @@ typedef struct drm_via_private {
30999 struct timeval last_vblank;
31000 int last_vblank_valid;
31001 unsigned usec_per_vblank;
31002- atomic_t vbl_received;
31003+ atomic_unchecked_t vbl_received;
31004 drm_via_state_t hc_state;
31005 char pci_buf[VIA_PCI_BUF_SIZE];
31006 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31007diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31008index d391f48..10c8ca3 100644
31009--- a/drivers/gpu/drm/via/via_irq.c
31010+++ b/drivers/gpu/drm/via/via_irq.c
31011@@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31012 if (crtc != 0)
31013 return 0;
31014
31015- return atomic_read(&dev_priv->vbl_received);
31016+ return atomic_read_unchecked(&dev_priv->vbl_received);
31017 }
31018
31019 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31020@@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31021
31022 status = VIA_READ(VIA_REG_INTERRUPT);
31023 if (status & VIA_IRQ_VBLANK_PENDING) {
31024- atomic_inc(&dev_priv->vbl_received);
31025- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31026+ atomic_inc_unchecked(&dev_priv->vbl_received);
31027+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31028 do_gettimeofday(&cur_vblank);
31029 if (dev_priv->last_vblank_valid) {
31030 dev_priv->usec_per_vblank =
31031@@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31032 dev_priv->last_vblank = cur_vblank;
31033 dev_priv->last_vblank_valid = 1;
31034 }
31035- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31036+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31037 DRM_DEBUG("US per vblank is: %u\n",
31038 dev_priv->usec_per_vblank);
31039 }
31040@@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31041
31042 for (i = 0; i < dev_priv->num_irqs; ++i) {
31043 if (status & cur_irq->pending_mask) {
31044- atomic_inc(&cur_irq->irq_received);
31045+ atomic_inc_unchecked(&cur_irq->irq_received);
31046 DRM_WAKEUP(&cur_irq->irq_queue);
31047 handled = 1;
31048 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31049@@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31050 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31051 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31052 masks[irq][4]));
31053- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31054+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31055 } else {
31056 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31057 (((cur_irq_sequence =
31058- atomic_read(&cur_irq->irq_received)) -
31059+ atomic_read_unchecked(&cur_irq->irq_received)) -
31060 *sequence) <= (1 << 23)));
31061 }
31062 *sequence = cur_irq_sequence;
31063@@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31064 }
31065
31066 for (i = 0; i < dev_priv->num_irqs; ++i) {
31067- atomic_set(&cur_irq->irq_received, 0);
31068+ atomic_set_unchecked(&cur_irq->irq_received, 0);
31069 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31070 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31071 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31072@@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31073 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31074 case VIA_IRQ_RELATIVE:
31075 irqwait->request.sequence +=
31076- atomic_read(&cur_irq->irq_received);
31077+ atomic_read_unchecked(&cur_irq->irq_received);
31078 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31079 case VIA_IRQ_ABSOLUTE:
31080 break;
31081diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31082index d0f2c07..9ebd9c3 100644
31083--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31084+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31085@@ -263,7 +263,7 @@ struct vmw_private {
31086 * Fencing and IRQs.
31087 */
31088
31089- atomic_t marker_seq;
31090+ atomic_unchecked_t marker_seq;
31091 wait_queue_head_t fence_queue;
31092 wait_queue_head_t fifo_queue;
31093 int fence_queue_waiters; /* Protected by hw_mutex */
31094diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31095index a0c2f12..68ae6cb 100644
31096--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31097+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31098@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31099 (unsigned int) min,
31100 (unsigned int) fifo->capabilities);
31101
31102- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31103+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31104 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31105 vmw_marker_queue_init(&fifo->marker_queue);
31106 return vmw_fifo_send_fence(dev_priv, &dummy);
31107@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31108 if (reserveable)
31109 iowrite32(bytes, fifo_mem +
31110 SVGA_FIFO_RESERVED);
31111- return fifo_mem + (next_cmd >> 2);
31112+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31113 } else {
31114 need_bounce = true;
31115 }
31116@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31117
31118 fm = vmw_fifo_reserve(dev_priv, bytes);
31119 if (unlikely(fm == NULL)) {
31120- *seqno = atomic_read(&dev_priv->marker_seq);
31121+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31122 ret = -ENOMEM;
31123 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31124 false, 3*HZ);
31125@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31126 }
31127
31128 do {
31129- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31130+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31131 } while (*seqno == 0);
31132
31133 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31134diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31135index cabc95f..14b3d77 100644
31136--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31137+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31138@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31139 * emitted. Then the fence is stale and signaled.
31140 */
31141
31142- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31143+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31144 > VMW_FENCE_WRAP);
31145
31146 return ret;
31147@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31148
31149 if (fifo_idle)
31150 down_read(&fifo_state->rwsem);
31151- signal_seq = atomic_read(&dev_priv->marker_seq);
31152+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31153 ret = 0;
31154
31155 for (;;) {
31156diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31157index 8a8725c..afed796 100644
31158--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31159+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31160@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31161 while (!vmw_lag_lt(queue, us)) {
31162 spin_lock(&queue->lock);
31163 if (list_empty(&queue->head))
31164- seqno = atomic_read(&dev_priv->marker_seq);
31165+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31166 else {
31167 marker = list_first_entry(&queue->head,
31168 struct vmw_marker, head);
31169diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31170index 1f6957c..b579481 100644
31171--- a/drivers/hid/hid-core.c
31172+++ b/drivers/hid/hid-core.c
31173@@ -2153,7 +2153,7 @@ static bool hid_ignore(struct hid_device *hdev)
31174
31175 int hid_add_device(struct hid_device *hdev)
31176 {
31177- static atomic_t id = ATOMIC_INIT(0);
31178+ static atomic_unchecked_t id = ATOMIC_INIT(0);
31179 int ret;
31180
31181 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31182@@ -2188,7 +2188,7 @@ int hid_add_device(struct hid_device *hdev)
31183 /* XXX hack, any other cleaner solution after the driver core
31184 * is converted to allow more than 20 bytes as the device name? */
31185 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31186- hdev->vendor, hdev->product, atomic_inc_return(&id));
31187+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31188
31189 hid_debug_register(hdev, dev_name(&hdev->dev));
31190 ret = device_add(&hdev->dev);
31191diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31192index eec3291..8ed706b 100644
31193--- a/drivers/hid/hid-wiimote-debug.c
31194+++ b/drivers/hid/hid-wiimote-debug.c
31195@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31196 else if (size == 0)
31197 return -EIO;
31198
31199- if (copy_to_user(u, buf, size))
31200+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
31201 return -EFAULT;
31202
31203 *off += size;
31204diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31205index 14599e2..711c965 100644
31206--- a/drivers/hid/usbhid/hiddev.c
31207+++ b/drivers/hid/usbhid/hiddev.c
31208@@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31209 break;
31210
31211 case HIDIOCAPPLICATION:
31212- if (arg < 0 || arg >= hid->maxapplication)
31213+ if (arg >= hid->maxapplication)
31214 break;
31215
31216 for (i = 0; i < hid->maxcollection; i++)
31217diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31218index 4065374..10ed7dc 100644
31219--- a/drivers/hv/channel.c
31220+++ b/drivers/hv/channel.c
31221@@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31222 int ret = 0;
31223 int t;
31224
31225- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31226- atomic_inc(&vmbus_connection.next_gpadl_handle);
31227+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31228+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31229
31230 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31231 if (ret)
31232diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31233index 86f8885..ab9cb2b 100644
31234--- a/drivers/hv/hv.c
31235+++ b/drivers/hv/hv.c
31236@@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31237 u64 output_address = (output) ? virt_to_phys(output) : 0;
31238 u32 output_address_hi = output_address >> 32;
31239 u32 output_address_lo = output_address & 0xFFFFFFFF;
31240- void *hypercall_page = hv_context.hypercall_page;
31241+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31242
31243 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31244 "=a"(hv_status_lo) : "d" (control_hi),
31245diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31246index b9426a6..677ce34 100644
31247--- a/drivers/hv/hyperv_vmbus.h
31248+++ b/drivers/hv/hyperv_vmbus.h
31249@@ -555,7 +555,7 @@ enum vmbus_connect_state {
31250 struct vmbus_connection {
31251 enum vmbus_connect_state conn_state;
31252
31253- atomic_t next_gpadl_handle;
31254+ atomic_unchecked_t next_gpadl_handle;
31255
31256 /*
31257 * Represents channel interrupts. Each bit position represents a
31258diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31259index a220e57..428f54d 100644
31260--- a/drivers/hv/vmbus_drv.c
31261+++ b/drivers/hv/vmbus_drv.c
31262@@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31263 {
31264 int ret = 0;
31265
31266- static atomic_t device_num = ATOMIC_INIT(0);
31267+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31268
31269 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31270- atomic_inc_return(&device_num));
31271+ atomic_inc_return_unchecked(&device_num));
31272
31273 child_device_obj->device.bus = &hv_bus;
31274 child_device_obj->device.parent = &hv_acpi_dev->dev;
31275diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
31276index 34ad5a2..e2b0ae8 100644
31277--- a/drivers/hwmon/acpi_power_meter.c
31278+++ b/drivers/hwmon/acpi_power_meter.c
31279@@ -308,8 +308,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
31280 return res;
31281
31282 temp /= 1000;
31283- if (temp < 0)
31284- return -EINVAL;
31285
31286 mutex_lock(&resource->lock);
31287 resource->trip[attr->index - 7] = temp;
31288diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31289index 8b011d0..3de24a1 100644
31290--- a/drivers/hwmon/sht15.c
31291+++ b/drivers/hwmon/sht15.c
31292@@ -166,7 +166,7 @@ struct sht15_data {
31293 int supply_uV;
31294 bool supply_uV_valid;
31295 struct work_struct update_supply_work;
31296- atomic_t interrupt_handled;
31297+ atomic_unchecked_t interrupt_handled;
31298 };
31299
31300 /**
31301@@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31302 return ret;
31303
31304 gpio_direction_input(data->pdata->gpio_data);
31305- atomic_set(&data->interrupt_handled, 0);
31306+ atomic_set_unchecked(&data->interrupt_handled, 0);
31307
31308 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31309 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31310 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31311 /* Only relevant if the interrupt hasn't occurred. */
31312- if (!atomic_read(&data->interrupt_handled))
31313+ if (!atomic_read_unchecked(&data->interrupt_handled))
31314 schedule_work(&data->read_work);
31315 }
31316 ret = wait_event_timeout(data->wait_queue,
31317@@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31318
31319 /* First disable the interrupt */
31320 disable_irq_nosync(irq);
31321- atomic_inc(&data->interrupt_handled);
31322+ atomic_inc_unchecked(&data->interrupt_handled);
31323 /* Then schedule a reading work struct */
31324 if (data->state != SHT15_READING_NOTHING)
31325 schedule_work(&data->read_work);
31326@@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31327 * If not, then start the interrupt again - care here as could
31328 * have gone low in meantime so verify it hasn't!
31329 */
31330- atomic_set(&data->interrupt_handled, 0);
31331+ atomic_set_unchecked(&data->interrupt_handled, 0);
31332 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31333 /* If still not occurred or another handler was scheduled */
31334 if (gpio_get_value(data->pdata->gpio_data)
31335- || atomic_read(&data->interrupt_handled))
31336+ || atomic_read_unchecked(&data->interrupt_handled))
31337 return;
31338 }
31339
31340diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31341index 378fcb5..5e91fa8 100644
31342--- a/drivers/i2c/busses/i2c-amd756-s4882.c
31343+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31344@@ -43,7 +43,7 @@
31345 extern struct i2c_adapter amd756_smbus;
31346
31347 static struct i2c_adapter *s4882_adapter;
31348-static struct i2c_algorithm *s4882_algo;
31349+static i2c_algorithm_no_const *s4882_algo;
31350
31351 /* Wrapper access functions for multiplexed SMBus */
31352 static DEFINE_MUTEX(amd756_lock);
31353diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31354index 29015eb..af2d8e9 100644
31355--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31356+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31357@@ -41,7 +41,7 @@
31358 extern struct i2c_adapter *nforce2_smbus;
31359
31360 static struct i2c_adapter *s4985_adapter;
31361-static struct i2c_algorithm *s4985_algo;
31362+static i2c_algorithm_no_const *s4985_algo;
31363
31364 /* Wrapper access functions for multiplexed SMBus */
31365 static DEFINE_MUTEX(nforce2_lock);
31366diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31367index 1038c38..eb92f51 100644
31368--- a/drivers/i2c/i2c-mux.c
31369+++ b/drivers/i2c/i2c-mux.c
31370@@ -30,7 +30,7 @@
31371 /* multiplexer per channel data */
31372 struct i2c_mux_priv {
31373 struct i2c_adapter adap;
31374- struct i2c_algorithm algo;
31375+ i2c_algorithm_no_const algo;
31376
31377 struct i2c_adapter *parent;
31378 void *mux_priv; /* the mux chip/device */
31379diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31380index 57d00ca..0145194 100644
31381--- a/drivers/ide/aec62xx.c
31382+++ b/drivers/ide/aec62xx.c
31383@@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31384 .cable_detect = atp86x_cable_detect,
31385 };
31386
31387-static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31388+static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31389 { /* 0: AEC6210 */
31390 .name = DRV_NAME,
31391 .init_chipset = init_chipset_aec62xx,
31392diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31393index 2c8016a..911a27c 100644
31394--- a/drivers/ide/alim15x3.c
31395+++ b/drivers/ide/alim15x3.c
31396@@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31397 .dma_sff_read_status = ide_dma_sff_read_status,
31398 };
31399
31400-static const struct ide_port_info ali15x3_chipset __devinitdata = {
31401+static const struct ide_port_info ali15x3_chipset __devinitconst = {
31402 .name = DRV_NAME,
31403 .init_chipset = init_chipset_ali15x3,
31404 .init_hwif = init_hwif_ali15x3,
31405diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31406index 3747b25..56fc995 100644
31407--- a/drivers/ide/amd74xx.c
31408+++ b/drivers/ide/amd74xx.c
31409@@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31410 .udma_mask = udma, \
31411 }
31412
31413-static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31414+static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31415 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31416 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31417 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31418diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31419index 15f0ead..cb43480 100644
31420--- a/drivers/ide/atiixp.c
31421+++ b/drivers/ide/atiixp.c
31422@@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31423 .cable_detect = atiixp_cable_detect,
31424 };
31425
31426-static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31427+static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31428 { /* 0: IXP200/300/400/700 */
31429 .name = DRV_NAME,
31430 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31431diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31432index 5f80312..d1fc438 100644
31433--- a/drivers/ide/cmd64x.c
31434+++ b/drivers/ide/cmd64x.c
31435@@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31436 .dma_sff_read_status = ide_dma_sff_read_status,
31437 };
31438
31439-static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31440+static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31441 { /* 0: CMD643 */
31442 .name = DRV_NAME,
31443 .init_chipset = init_chipset_cmd64x,
31444diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31445index 2c1e5f7..1444762 100644
31446--- a/drivers/ide/cs5520.c
31447+++ b/drivers/ide/cs5520.c
31448@@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31449 .set_dma_mode = cs5520_set_dma_mode,
31450 };
31451
31452-static const struct ide_port_info cyrix_chipset __devinitdata = {
31453+static const struct ide_port_info cyrix_chipset __devinitconst = {
31454 .name = DRV_NAME,
31455 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31456 .port_ops = &cs5520_port_ops,
31457diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31458index 4dc4eb9..49b40ad 100644
31459--- a/drivers/ide/cs5530.c
31460+++ b/drivers/ide/cs5530.c
31461@@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31462 .udma_filter = cs5530_udma_filter,
31463 };
31464
31465-static const struct ide_port_info cs5530_chipset __devinitdata = {
31466+static const struct ide_port_info cs5530_chipset __devinitconst = {
31467 .name = DRV_NAME,
31468 .init_chipset = init_chipset_cs5530,
31469 .init_hwif = init_hwif_cs5530,
31470diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31471index 5059faf..18d4c85 100644
31472--- a/drivers/ide/cs5535.c
31473+++ b/drivers/ide/cs5535.c
31474@@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31475 .cable_detect = cs5535_cable_detect,
31476 };
31477
31478-static const struct ide_port_info cs5535_chipset __devinitdata = {
31479+static const struct ide_port_info cs5535_chipset __devinitconst = {
31480 .name = DRV_NAME,
31481 .port_ops = &cs5535_port_ops,
31482 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31483diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31484index 847553f..3ffb49d 100644
31485--- a/drivers/ide/cy82c693.c
31486+++ b/drivers/ide/cy82c693.c
31487@@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31488 .set_dma_mode = cy82c693_set_dma_mode,
31489 };
31490
31491-static const struct ide_port_info cy82c693_chipset __devinitdata = {
31492+static const struct ide_port_info cy82c693_chipset __devinitconst = {
31493 .name = DRV_NAME,
31494 .init_iops = init_iops_cy82c693,
31495 .port_ops = &cy82c693_port_ops,
31496diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31497index 58c51cd..4aec3b8 100644
31498--- a/drivers/ide/hpt366.c
31499+++ b/drivers/ide/hpt366.c
31500@@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31501 }
31502 };
31503
31504-static const struct hpt_info hpt36x __devinitdata = {
31505+static const struct hpt_info hpt36x __devinitconst = {
31506 .chip_name = "HPT36x",
31507 .chip_type = HPT36x,
31508 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31509@@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31510 .timings = &hpt36x_timings
31511 };
31512
31513-static const struct hpt_info hpt370 __devinitdata = {
31514+static const struct hpt_info hpt370 __devinitconst = {
31515 .chip_name = "HPT370",
31516 .chip_type = HPT370,
31517 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31518@@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31519 .timings = &hpt37x_timings
31520 };
31521
31522-static const struct hpt_info hpt370a __devinitdata = {
31523+static const struct hpt_info hpt370a __devinitconst = {
31524 .chip_name = "HPT370A",
31525 .chip_type = HPT370A,
31526 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31527@@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31528 .timings = &hpt37x_timings
31529 };
31530
31531-static const struct hpt_info hpt374 __devinitdata = {
31532+static const struct hpt_info hpt374 __devinitconst = {
31533 .chip_name = "HPT374",
31534 .chip_type = HPT374,
31535 .udma_mask = ATA_UDMA5,
31536@@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31537 .timings = &hpt37x_timings
31538 };
31539
31540-static const struct hpt_info hpt372 __devinitdata = {
31541+static const struct hpt_info hpt372 __devinitconst = {
31542 .chip_name = "HPT372",
31543 .chip_type = HPT372,
31544 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31545@@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31546 .timings = &hpt37x_timings
31547 };
31548
31549-static const struct hpt_info hpt372a __devinitdata = {
31550+static const struct hpt_info hpt372a __devinitconst = {
31551 .chip_name = "HPT372A",
31552 .chip_type = HPT372A,
31553 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31554@@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31555 .timings = &hpt37x_timings
31556 };
31557
31558-static const struct hpt_info hpt302 __devinitdata = {
31559+static const struct hpt_info hpt302 __devinitconst = {
31560 .chip_name = "HPT302",
31561 .chip_type = HPT302,
31562 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31563@@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31564 .timings = &hpt37x_timings
31565 };
31566
31567-static const struct hpt_info hpt371 __devinitdata = {
31568+static const struct hpt_info hpt371 __devinitconst = {
31569 .chip_name = "HPT371",
31570 .chip_type = HPT371,
31571 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31572@@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31573 .timings = &hpt37x_timings
31574 };
31575
31576-static const struct hpt_info hpt372n __devinitdata = {
31577+static const struct hpt_info hpt372n __devinitconst = {
31578 .chip_name = "HPT372N",
31579 .chip_type = HPT372N,
31580 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31581@@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31582 .timings = &hpt37x_timings
31583 };
31584
31585-static const struct hpt_info hpt302n __devinitdata = {
31586+static const struct hpt_info hpt302n __devinitconst = {
31587 .chip_name = "HPT302N",
31588 .chip_type = HPT302N,
31589 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31590@@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31591 .timings = &hpt37x_timings
31592 };
31593
31594-static const struct hpt_info hpt371n __devinitdata = {
31595+static const struct hpt_info hpt371n __devinitconst = {
31596 .chip_name = "HPT371N",
31597 .chip_type = HPT371N,
31598 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31599@@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31600 .dma_sff_read_status = ide_dma_sff_read_status,
31601 };
31602
31603-static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31604+static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31605 { /* 0: HPT36x */
31606 .name = DRV_NAME,
31607 .init_chipset = init_chipset_hpt366,
31608diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31609index 8126824..55a2798 100644
31610--- a/drivers/ide/ide-cd.c
31611+++ b/drivers/ide/ide-cd.c
31612@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31613 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31614 if ((unsigned long)buf & alignment
31615 || blk_rq_bytes(rq) & q->dma_pad_mask
31616- || object_is_on_stack(buf))
31617+ || object_starts_on_stack(buf))
31618 drive->dma = 0;
31619 }
31620 }
31621diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31622index 7f56b73..dab5b67 100644
31623--- a/drivers/ide/ide-pci-generic.c
31624+++ b/drivers/ide/ide-pci-generic.c
31625@@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31626 .udma_mask = ATA_UDMA6, \
31627 }
31628
31629-static const struct ide_port_info generic_chipsets[] __devinitdata = {
31630+static const struct ide_port_info generic_chipsets[] __devinitconst = {
31631 /* 0: Unknown */
31632 DECLARE_GENERIC_PCI_DEV(0),
31633
31634diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31635index 560e66d..d5dd180 100644
31636--- a/drivers/ide/it8172.c
31637+++ b/drivers/ide/it8172.c
31638@@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31639 .set_dma_mode = it8172_set_dma_mode,
31640 };
31641
31642-static const struct ide_port_info it8172_port_info __devinitdata = {
31643+static const struct ide_port_info it8172_port_info __devinitconst = {
31644 .name = DRV_NAME,
31645 .port_ops = &it8172_port_ops,
31646 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31647diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31648index 46816ba..1847aeb 100644
31649--- a/drivers/ide/it8213.c
31650+++ b/drivers/ide/it8213.c
31651@@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31652 .cable_detect = it8213_cable_detect,
31653 };
31654
31655-static const struct ide_port_info it8213_chipset __devinitdata = {
31656+static const struct ide_port_info it8213_chipset __devinitconst = {
31657 .name = DRV_NAME,
31658 .enablebits = { {0x41, 0x80, 0x80} },
31659 .port_ops = &it8213_port_ops,
31660diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31661index 2e3169f..c5611db 100644
31662--- a/drivers/ide/it821x.c
31663+++ b/drivers/ide/it821x.c
31664@@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31665 .cable_detect = it821x_cable_detect,
31666 };
31667
31668-static const struct ide_port_info it821x_chipset __devinitdata = {
31669+static const struct ide_port_info it821x_chipset __devinitconst = {
31670 .name = DRV_NAME,
31671 .init_chipset = init_chipset_it821x,
31672 .init_hwif = init_hwif_it821x,
31673diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31674index 74c2c4a..efddd7d 100644
31675--- a/drivers/ide/jmicron.c
31676+++ b/drivers/ide/jmicron.c
31677@@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31678 .cable_detect = jmicron_cable_detect,
31679 };
31680
31681-static const struct ide_port_info jmicron_chipset __devinitdata = {
31682+static const struct ide_port_info jmicron_chipset __devinitconst = {
31683 .name = DRV_NAME,
31684 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31685 .port_ops = &jmicron_port_ops,
31686diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31687index 95327a2..73f78d8 100644
31688--- a/drivers/ide/ns87415.c
31689+++ b/drivers/ide/ns87415.c
31690@@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31691 .dma_sff_read_status = superio_dma_sff_read_status,
31692 };
31693
31694-static const struct ide_port_info ns87415_chipset __devinitdata = {
31695+static const struct ide_port_info ns87415_chipset __devinitconst = {
31696 .name = DRV_NAME,
31697 .init_hwif = init_hwif_ns87415,
31698 .tp_ops = &ns87415_tp_ops,
31699diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31700index 1a53a4c..39edc66 100644
31701--- a/drivers/ide/opti621.c
31702+++ b/drivers/ide/opti621.c
31703@@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31704 .set_pio_mode = opti621_set_pio_mode,
31705 };
31706
31707-static const struct ide_port_info opti621_chipset __devinitdata = {
31708+static const struct ide_port_info opti621_chipset __devinitconst = {
31709 .name = DRV_NAME,
31710 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31711 .port_ops = &opti621_port_ops,
31712diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31713index 9546fe2..2e5ceb6 100644
31714--- a/drivers/ide/pdc202xx_new.c
31715+++ b/drivers/ide/pdc202xx_new.c
31716@@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
31717 .udma_mask = udma, \
31718 }
31719
31720-static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
31721+static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
31722 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
31723 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
31724 };
31725diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
31726index 3a35ec6..5634510 100644
31727--- a/drivers/ide/pdc202xx_old.c
31728+++ b/drivers/ide/pdc202xx_old.c
31729@@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
31730 .max_sectors = sectors, \
31731 }
31732
31733-static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
31734+static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
31735 { /* 0: PDC20246 */
31736 .name = DRV_NAME,
31737 .init_chipset = init_chipset_pdc202xx,
31738diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
31739index 1892e81..fe0fd60 100644
31740--- a/drivers/ide/piix.c
31741+++ b/drivers/ide/piix.c
31742@@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
31743 .udma_mask = udma, \
31744 }
31745
31746-static const struct ide_port_info piix_pci_info[] __devinitdata = {
31747+static const struct ide_port_info piix_pci_info[] __devinitconst = {
31748 /* 0: MPIIX */
31749 { /*
31750 * MPIIX actually has only a single IDE channel mapped to
31751diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
31752index a6414a8..c04173e 100644
31753--- a/drivers/ide/rz1000.c
31754+++ b/drivers/ide/rz1000.c
31755@@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
31756 }
31757 }
31758
31759-static const struct ide_port_info rz1000_chipset __devinitdata = {
31760+static const struct ide_port_info rz1000_chipset __devinitconst = {
31761 .name = DRV_NAME,
31762 .host_flags = IDE_HFLAG_NO_DMA,
31763 };
31764diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
31765index 356b9b5..d4758eb 100644
31766--- a/drivers/ide/sc1200.c
31767+++ b/drivers/ide/sc1200.c
31768@@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
31769 .dma_sff_read_status = ide_dma_sff_read_status,
31770 };
31771
31772-static const struct ide_port_info sc1200_chipset __devinitdata = {
31773+static const struct ide_port_info sc1200_chipset __devinitconst = {
31774 .name = DRV_NAME,
31775 .port_ops = &sc1200_port_ops,
31776 .dma_ops = &sc1200_dma_ops,
31777diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
31778index b7f5b0c..9701038 100644
31779--- a/drivers/ide/scc_pata.c
31780+++ b/drivers/ide/scc_pata.c
31781@@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
31782 .dma_sff_read_status = scc_dma_sff_read_status,
31783 };
31784
31785-static const struct ide_port_info scc_chipset __devinitdata = {
31786+static const struct ide_port_info scc_chipset __devinitconst = {
31787 .name = "sccIDE",
31788 .init_iops = init_iops_scc,
31789 .init_dma = scc_init_dma,
31790diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
31791index 35fb8da..24d72ef 100644
31792--- a/drivers/ide/serverworks.c
31793+++ b/drivers/ide/serverworks.c
31794@@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
31795 .cable_detect = svwks_cable_detect,
31796 };
31797
31798-static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
31799+static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
31800 { /* 0: OSB4 */
31801 .name = DRV_NAME,
31802 .init_chipset = init_chipset_svwks,
31803diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
31804index ddeda44..46f7e30 100644
31805--- a/drivers/ide/siimage.c
31806+++ b/drivers/ide/siimage.c
31807@@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
31808 .udma_mask = ATA_UDMA6, \
31809 }
31810
31811-static const struct ide_port_info siimage_chipsets[] __devinitdata = {
31812+static const struct ide_port_info siimage_chipsets[] __devinitconst = {
31813 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
31814 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
31815 };
31816diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
31817index 4a00225..09e61b4 100644
31818--- a/drivers/ide/sis5513.c
31819+++ b/drivers/ide/sis5513.c
31820@@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
31821 .cable_detect = sis_cable_detect,
31822 };
31823
31824-static const struct ide_port_info sis5513_chipset __devinitdata = {
31825+static const struct ide_port_info sis5513_chipset __devinitconst = {
31826 .name = DRV_NAME,
31827 .init_chipset = init_chipset_sis5513,
31828 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
31829diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
31830index f21dc2a..d051cd2 100644
31831--- a/drivers/ide/sl82c105.c
31832+++ b/drivers/ide/sl82c105.c
31833@@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
31834 .dma_sff_read_status = ide_dma_sff_read_status,
31835 };
31836
31837-static const struct ide_port_info sl82c105_chipset __devinitdata = {
31838+static const struct ide_port_info sl82c105_chipset __devinitconst = {
31839 .name = DRV_NAME,
31840 .init_chipset = init_chipset_sl82c105,
31841 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
31842diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
31843index 864ffe0..863a5e9 100644
31844--- a/drivers/ide/slc90e66.c
31845+++ b/drivers/ide/slc90e66.c
31846@@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
31847 .cable_detect = slc90e66_cable_detect,
31848 };
31849
31850-static const struct ide_port_info slc90e66_chipset __devinitdata = {
31851+static const struct ide_port_info slc90e66_chipset __devinitconst = {
31852 .name = DRV_NAME,
31853 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
31854 .port_ops = &slc90e66_port_ops,
31855diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
31856index 4799d5c..1794678 100644
31857--- a/drivers/ide/tc86c001.c
31858+++ b/drivers/ide/tc86c001.c
31859@@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
31860 .dma_sff_read_status = ide_dma_sff_read_status,
31861 };
31862
31863-static const struct ide_port_info tc86c001_chipset __devinitdata = {
31864+static const struct ide_port_info tc86c001_chipset __devinitconst = {
31865 .name = DRV_NAME,
31866 .init_hwif = init_hwif_tc86c001,
31867 .port_ops = &tc86c001_port_ops,
31868diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
31869index 281c914..55ce1b8 100644
31870--- a/drivers/ide/triflex.c
31871+++ b/drivers/ide/triflex.c
31872@@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
31873 .set_dma_mode = triflex_set_mode,
31874 };
31875
31876-static const struct ide_port_info triflex_device __devinitdata = {
31877+static const struct ide_port_info triflex_device __devinitconst = {
31878 .name = DRV_NAME,
31879 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
31880 .port_ops = &triflex_port_ops,
31881diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
31882index 4b42ca0..e494a98 100644
31883--- a/drivers/ide/trm290.c
31884+++ b/drivers/ide/trm290.c
31885@@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
31886 .dma_check = trm290_dma_check,
31887 };
31888
31889-static const struct ide_port_info trm290_chipset __devinitdata = {
31890+static const struct ide_port_info trm290_chipset __devinitconst = {
31891 .name = DRV_NAME,
31892 .init_hwif = init_hwif_trm290,
31893 .tp_ops = &trm290_tp_ops,
31894diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
31895index f46f49c..eb77678 100644
31896--- a/drivers/ide/via82cxxx.c
31897+++ b/drivers/ide/via82cxxx.c
31898@@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
31899 .cable_detect = via82cxxx_cable_detect,
31900 };
31901
31902-static const struct ide_port_info via82cxxx_chipset __devinitdata = {
31903+static const struct ide_port_info via82cxxx_chipset __devinitconst = {
31904 .name = DRV_NAME,
31905 .init_chipset = init_chipset_via82cxxx,
31906 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
31907diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
31908index 73d4531..c90cd2d 100644
31909--- a/drivers/ieee802154/fakehard.c
31910+++ b/drivers/ieee802154/fakehard.c
31911@@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
31912 phy->transmit_power = 0xbf;
31913
31914 dev->netdev_ops = &fake_ops;
31915- dev->ml_priv = &fake_mlme;
31916+ dev->ml_priv = (void *)&fake_mlme;
31917
31918 priv = netdev_priv(dev);
31919 priv->phy = phy;
31920diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
31921index c889aae..6cf5aa7 100644
31922--- a/drivers/infiniband/core/cm.c
31923+++ b/drivers/infiniband/core/cm.c
31924@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
31925
31926 struct cm_counter_group {
31927 struct kobject obj;
31928- atomic_long_t counter[CM_ATTR_COUNT];
31929+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
31930 };
31931
31932 struct cm_counter_attribute {
31933@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
31934 struct ib_mad_send_buf *msg = NULL;
31935 int ret;
31936
31937- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31938+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31939 counter[CM_REQ_COUNTER]);
31940
31941 /* Quick state check to discard duplicate REQs. */
31942@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
31943 if (!cm_id_priv)
31944 return;
31945
31946- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31947+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31948 counter[CM_REP_COUNTER]);
31949 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
31950 if (ret)
31951@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
31952 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
31953 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
31954 spin_unlock_irq(&cm_id_priv->lock);
31955- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31956+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31957 counter[CM_RTU_COUNTER]);
31958 goto out;
31959 }
31960@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
31961 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
31962 dreq_msg->local_comm_id);
31963 if (!cm_id_priv) {
31964- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31965+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31966 counter[CM_DREQ_COUNTER]);
31967 cm_issue_drep(work->port, work->mad_recv_wc);
31968 return -EINVAL;
31969@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
31970 case IB_CM_MRA_REP_RCVD:
31971 break;
31972 case IB_CM_TIMEWAIT:
31973- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31974+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31975 counter[CM_DREQ_COUNTER]);
31976 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
31977 goto unlock;
31978@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
31979 cm_free_msg(msg);
31980 goto deref;
31981 case IB_CM_DREQ_RCVD:
31982- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31983+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31984 counter[CM_DREQ_COUNTER]);
31985 goto unlock;
31986 default:
31987@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
31988 ib_modify_mad(cm_id_priv->av.port->mad_agent,
31989 cm_id_priv->msg, timeout)) {
31990 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
31991- atomic_long_inc(&work->port->
31992+ atomic_long_inc_unchecked(&work->port->
31993 counter_group[CM_RECV_DUPLICATES].
31994 counter[CM_MRA_COUNTER]);
31995 goto out;
31996@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
31997 break;
31998 case IB_CM_MRA_REQ_RCVD:
31999 case IB_CM_MRA_REP_RCVD:
32000- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32001+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32002 counter[CM_MRA_COUNTER]);
32003 /* fall through */
32004 default:
32005@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32006 case IB_CM_LAP_IDLE:
32007 break;
32008 case IB_CM_MRA_LAP_SENT:
32009- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32010+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32011 counter[CM_LAP_COUNTER]);
32012 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32013 goto unlock;
32014@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32015 cm_free_msg(msg);
32016 goto deref;
32017 case IB_CM_LAP_RCVD:
32018- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32019+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32020 counter[CM_LAP_COUNTER]);
32021 goto unlock;
32022 default:
32023@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32024 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32025 if (cur_cm_id_priv) {
32026 spin_unlock_irq(&cm.lock);
32027- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32028+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32029 counter[CM_SIDR_REQ_COUNTER]);
32030 goto out; /* Duplicate message. */
32031 }
32032@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32033 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32034 msg->retries = 1;
32035
32036- atomic_long_add(1 + msg->retries,
32037+ atomic_long_add_unchecked(1 + msg->retries,
32038 &port->counter_group[CM_XMIT].counter[attr_index]);
32039 if (msg->retries)
32040- atomic_long_add(msg->retries,
32041+ atomic_long_add_unchecked(msg->retries,
32042 &port->counter_group[CM_XMIT_RETRIES].
32043 counter[attr_index]);
32044
32045@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32046 }
32047
32048 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32049- atomic_long_inc(&port->counter_group[CM_RECV].
32050+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32051 counter[attr_id - CM_ATTR_ID_OFFSET]);
32052
32053 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32054@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32055 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32056
32057 return sprintf(buf, "%ld\n",
32058- atomic_long_read(&group->counter[cm_attr->index]));
32059+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32060 }
32061
32062 static const struct sysfs_ops cm_counter_ops = {
32063diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32064index 176c8f9..2627b62 100644
32065--- a/drivers/infiniband/core/fmr_pool.c
32066+++ b/drivers/infiniband/core/fmr_pool.c
32067@@ -98,8 +98,8 @@ struct ib_fmr_pool {
32068
32069 struct task_struct *thread;
32070
32071- atomic_t req_ser;
32072- atomic_t flush_ser;
32073+ atomic_unchecked_t req_ser;
32074+ atomic_unchecked_t flush_ser;
32075
32076 wait_queue_head_t force_wait;
32077 };
32078@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32079 struct ib_fmr_pool *pool = pool_ptr;
32080
32081 do {
32082- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32083+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32084 ib_fmr_batch_release(pool);
32085
32086- atomic_inc(&pool->flush_ser);
32087+ atomic_inc_unchecked(&pool->flush_ser);
32088 wake_up_interruptible(&pool->force_wait);
32089
32090 if (pool->flush_function)
32091@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32092 }
32093
32094 set_current_state(TASK_INTERRUPTIBLE);
32095- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32096+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32097 !kthread_should_stop())
32098 schedule();
32099 __set_current_state(TASK_RUNNING);
32100@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32101 pool->dirty_watermark = params->dirty_watermark;
32102 pool->dirty_len = 0;
32103 spin_lock_init(&pool->pool_lock);
32104- atomic_set(&pool->req_ser, 0);
32105- atomic_set(&pool->flush_ser, 0);
32106+ atomic_set_unchecked(&pool->req_ser, 0);
32107+ atomic_set_unchecked(&pool->flush_ser, 0);
32108 init_waitqueue_head(&pool->force_wait);
32109
32110 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32111@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32112 }
32113 spin_unlock_irq(&pool->pool_lock);
32114
32115- serial = atomic_inc_return(&pool->req_ser);
32116+ serial = atomic_inc_return_unchecked(&pool->req_ser);
32117 wake_up_process(pool->thread);
32118
32119 if (wait_event_interruptible(pool->force_wait,
32120- atomic_read(&pool->flush_ser) - serial >= 0))
32121+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32122 return -EINTR;
32123
32124 return 0;
32125@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32126 } else {
32127 list_add_tail(&fmr->list, &pool->dirty_list);
32128 if (++pool->dirty_len >= pool->dirty_watermark) {
32129- atomic_inc(&pool->req_ser);
32130+ atomic_inc_unchecked(&pool->req_ser);
32131 wake_up_process(pool->thread);
32132 }
32133 }
32134diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32135index 57e07c6..56d09d4 100644
32136--- a/drivers/infiniband/hw/cxgb4/mem.c
32137+++ b/drivers/infiniband/hw/cxgb4/mem.c
32138@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32139 int err;
32140 struct fw_ri_tpte tpt;
32141 u32 stag_idx;
32142- static atomic_t key;
32143+ static atomic_unchecked_t key;
32144
32145 if (c4iw_fatal_error(rdev))
32146 return -EIO;
32147@@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32148 if (rdev->stats.stag.cur > rdev->stats.stag.max)
32149 rdev->stats.stag.max = rdev->stats.stag.cur;
32150 mutex_unlock(&rdev->stats.lock);
32151- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32152+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32153 }
32154 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32155 __func__, stag_state, type, pdid, stag_idx);
32156diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32157index 79b3dbc..96e5fcc 100644
32158--- a/drivers/infiniband/hw/ipath/ipath_rc.c
32159+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32160@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32161 struct ib_atomic_eth *ateth;
32162 struct ipath_ack_entry *e;
32163 u64 vaddr;
32164- atomic64_t *maddr;
32165+ atomic64_unchecked_t *maddr;
32166 u64 sdata;
32167 u32 rkey;
32168 u8 next;
32169@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32170 IB_ACCESS_REMOTE_ATOMIC)))
32171 goto nack_acc_unlck;
32172 /* Perform atomic OP and save result. */
32173- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32174+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32175 sdata = be64_to_cpu(ateth->swap_data);
32176 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32177 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32178- (u64) atomic64_add_return(sdata, maddr) - sdata :
32179+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32180 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32181 be64_to_cpu(ateth->compare_data),
32182 sdata);
32183diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32184index 1f95bba..9530f87 100644
32185--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32186+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32187@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32188 unsigned long flags;
32189 struct ib_wc wc;
32190 u64 sdata;
32191- atomic64_t *maddr;
32192+ atomic64_unchecked_t *maddr;
32193 enum ib_wc_status send_status;
32194
32195 /*
32196@@ -382,11 +382,11 @@ again:
32197 IB_ACCESS_REMOTE_ATOMIC)))
32198 goto acc_err;
32199 /* Perform atomic OP and save result. */
32200- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32201+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32202 sdata = wqe->wr.wr.atomic.compare_add;
32203 *(u64 *) sqp->s_sge.sge.vaddr =
32204 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32205- (u64) atomic64_add_return(sdata, maddr) - sdata :
32206+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32207 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32208 sdata, wqe->wr.wr.atomic.swap);
32209 goto send_comp;
32210diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32211index 7140199..da60063 100644
32212--- a/drivers/infiniband/hw/nes/nes.c
32213+++ b/drivers/infiniband/hw/nes/nes.c
32214@@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32215 LIST_HEAD(nes_adapter_list);
32216 static LIST_HEAD(nes_dev_list);
32217
32218-atomic_t qps_destroyed;
32219+atomic_unchecked_t qps_destroyed;
32220
32221 static unsigned int ee_flsh_adapter;
32222 static unsigned int sysfs_nonidx_addr;
32223@@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32224 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32225 struct nes_adapter *nesadapter = nesdev->nesadapter;
32226
32227- atomic_inc(&qps_destroyed);
32228+ atomic_inc_unchecked(&qps_destroyed);
32229
32230 /* Free the control structures */
32231
32232diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32233index c438e46..ca30356 100644
32234--- a/drivers/infiniband/hw/nes/nes.h
32235+++ b/drivers/infiniband/hw/nes/nes.h
32236@@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32237 extern unsigned int wqm_quanta;
32238 extern struct list_head nes_adapter_list;
32239
32240-extern atomic_t cm_connects;
32241-extern atomic_t cm_accepts;
32242-extern atomic_t cm_disconnects;
32243-extern atomic_t cm_closes;
32244-extern atomic_t cm_connecteds;
32245-extern atomic_t cm_connect_reqs;
32246-extern atomic_t cm_rejects;
32247-extern atomic_t mod_qp_timouts;
32248-extern atomic_t qps_created;
32249-extern atomic_t qps_destroyed;
32250-extern atomic_t sw_qps_destroyed;
32251+extern atomic_unchecked_t cm_connects;
32252+extern atomic_unchecked_t cm_accepts;
32253+extern atomic_unchecked_t cm_disconnects;
32254+extern atomic_unchecked_t cm_closes;
32255+extern atomic_unchecked_t cm_connecteds;
32256+extern atomic_unchecked_t cm_connect_reqs;
32257+extern atomic_unchecked_t cm_rejects;
32258+extern atomic_unchecked_t mod_qp_timouts;
32259+extern atomic_unchecked_t qps_created;
32260+extern atomic_unchecked_t qps_destroyed;
32261+extern atomic_unchecked_t sw_qps_destroyed;
32262 extern u32 mh_detected;
32263 extern u32 mh_pauses_sent;
32264 extern u32 cm_packets_sent;
32265@@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32266 extern u32 cm_packets_received;
32267 extern u32 cm_packets_dropped;
32268 extern u32 cm_packets_retrans;
32269-extern atomic_t cm_listens_created;
32270-extern atomic_t cm_listens_destroyed;
32271+extern atomic_unchecked_t cm_listens_created;
32272+extern atomic_unchecked_t cm_listens_destroyed;
32273 extern u32 cm_backlog_drops;
32274-extern atomic_t cm_loopbacks;
32275-extern atomic_t cm_nodes_created;
32276-extern atomic_t cm_nodes_destroyed;
32277-extern atomic_t cm_accel_dropped_pkts;
32278-extern atomic_t cm_resets_recvd;
32279-extern atomic_t pau_qps_created;
32280-extern atomic_t pau_qps_destroyed;
32281+extern atomic_unchecked_t cm_loopbacks;
32282+extern atomic_unchecked_t cm_nodes_created;
32283+extern atomic_unchecked_t cm_nodes_destroyed;
32284+extern atomic_unchecked_t cm_accel_dropped_pkts;
32285+extern atomic_unchecked_t cm_resets_recvd;
32286+extern atomic_unchecked_t pau_qps_created;
32287+extern atomic_unchecked_t pau_qps_destroyed;
32288
32289 extern u32 int_mod_timer_init;
32290 extern u32 int_mod_cq_depth_256;
32291diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32292index 020e95c..fbb3450 100644
32293--- a/drivers/infiniband/hw/nes/nes_cm.c
32294+++ b/drivers/infiniband/hw/nes/nes_cm.c
32295@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32296 u32 cm_packets_retrans;
32297 u32 cm_packets_created;
32298 u32 cm_packets_received;
32299-atomic_t cm_listens_created;
32300-atomic_t cm_listens_destroyed;
32301+atomic_unchecked_t cm_listens_created;
32302+atomic_unchecked_t cm_listens_destroyed;
32303 u32 cm_backlog_drops;
32304-atomic_t cm_loopbacks;
32305-atomic_t cm_nodes_created;
32306-atomic_t cm_nodes_destroyed;
32307-atomic_t cm_accel_dropped_pkts;
32308-atomic_t cm_resets_recvd;
32309+atomic_unchecked_t cm_loopbacks;
32310+atomic_unchecked_t cm_nodes_created;
32311+atomic_unchecked_t cm_nodes_destroyed;
32312+atomic_unchecked_t cm_accel_dropped_pkts;
32313+atomic_unchecked_t cm_resets_recvd;
32314
32315 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32316 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32317@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32318
32319 static struct nes_cm_core *g_cm_core;
32320
32321-atomic_t cm_connects;
32322-atomic_t cm_accepts;
32323-atomic_t cm_disconnects;
32324-atomic_t cm_closes;
32325-atomic_t cm_connecteds;
32326-atomic_t cm_connect_reqs;
32327-atomic_t cm_rejects;
32328+atomic_unchecked_t cm_connects;
32329+atomic_unchecked_t cm_accepts;
32330+atomic_unchecked_t cm_disconnects;
32331+atomic_unchecked_t cm_closes;
32332+atomic_unchecked_t cm_connecteds;
32333+atomic_unchecked_t cm_connect_reqs;
32334+atomic_unchecked_t cm_rejects;
32335
32336 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32337 {
32338@@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32339 kfree(listener);
32340 listener = NULL;
32341 ret = 0;
32342- atomic_inc(&cm_listens_destroyed);
32343+ atomic_inc_unchecked(&cm_listens_destroyed);
32344 } else {
32345 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32346 }
32347@@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32348 cm_node->rem_mac);
32349
32350 add_hte_node(cm_core, cm_node);
32351- atomic_inc(&cm_nodes_created);
32352+ atomic_inc_unchecked(&cm_nodes_created);
32353
32354 return cm_node;
32355 }
32356@@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32357 }
32358
32359 atomic_dec(&cm_core->node_cnt);
32360- atomic_inc(&cm_nodes_destroyed);
32361+ atomic_inc_unchecked(&cm_nodes_destroyed);
32362 nesqp = cm_node->nesqp;
32363 if (nesqp) {
32364 nesqp->cm_node = NULL;
32365@@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32366
32367 static void drop_packet(struct sk_buff *skb)
32368 {
32369- atomic_inc(&cm_accel_dropped_pkts);
32370+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
32371 dev_kfree_skb_any(skb);
32372 }
32373
32374@@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32375 {
32376
32377 int reset = 0; /* whether to send reset in case of err.. */
32378- atomic_inc(&cm_resets_recvd);
32379+ atomic_inc_unchecked(&cm_resets_recvd);
32380 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32381 " refcnt=%d\n", cm_node, cm_node->state,
32382 atomic_read(&cm_node->ref_count));
32383@@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32384 rem_ref_cm_node(cm_node->cm_core, cm_node);
32385 return NULL;
32386 }
32387- atomic_inc(&cm_loopbacks);
32388+ atomic_inc_unchecked(&cm_loopbacks);
32389 loopbackremotenode->loopbackpartner = cm_node;
32390 loopbackremotenode->tcp_cntxt.rcv_wscale =
32391 NES_CM_DEFAULT_RCV_WND_SCALE;
32392@@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32393 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32394 else {
32395 rem_ref_cm_node(cm_core, cm_node);
32396- atomic_inc(&cm_accel_dropped_pkts);
32397+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
32398 dev_kfree_skb_any(skb);
32399 }
32400 break;
32401@@ -2891,7 +2891,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32402
32403 if ((cm_id) && (cm_id->event_handler)) {
32404 if (issue_disconn) {
32405- atomic_inc(&cm_disconnects);
32406+ atomic_inc_unchecked(&cm_disconnects);
32407 cm_event.event = IW_CM_EVENT_DISCONNECT;
32408 cm_event.status = disconn_status;
32409 cm_event.local_addr = cm_id->local_addr;
32410@@ -2913,7 +2913,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32411 }
32412
32413 if (issue_close) {
32414- atomic_inc(&cm_closes);
32415+ atomic_inc_unchecked(&cm_closes);
32416 nes_disconnect(nesqp, 1);
32417
32418 cm_id->provider_data = nesqp;
32419@@ -3049,7 +3049,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32420
32421 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32422 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32423- atomic_inc(&cm_accepts);
32424+ atomic_inc_unchecked(&cm_accepts);
32425
32426 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32427 netdev_refcnt_read(nesvnic->netdev));
32428@@ -3251,7 +3251,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32429 struct nes_cm_core *cm_core;
32430 u8 *start_buff;
32431
32432- atomic_inc(&cm_rejects);
32433+ atomic_inc_unchecked(&cm_rejects);
32434 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32435 loopback = cm_node->loopbackpartner;
32436 cm_core = cm_node->cm_core;
32437@@ -3311,7 +3311,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32438 ntohl(cm_id->local_addr.sin_addr.s_addr),
32439 ntohs(cm_id->local_addr.sin_port));
32440
32441- atomic_inc(&cm_connects);
32442+ atomic_inc_unchecked(&cm_connects);
32443 nesqp->active_conn = 1;
32444
32445 /* cache the cm_id in the qp */
32446@@ -3421,7 +3421,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32447 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32448 return err;
32449 }
32450- atomic_inc(&cm_listens_created);
32451+ atomic_inc_unchecked(&cm_listens_created);
32452 }
32453
32454 cm_id->add_ref(cm_id);
32455@@ -3522,7 +3522,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32456
32457 if (nesqp->destroyed)
32458 return;
32459- atomic_inc(&cm_connecteds);
32460+ atomic_inc_unchecked(&cm_connecteds);
32461 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32462 " local port 0x%04X. jiffies = %lu.\n",
32463 nesqp->hwqp.qp_id,
32464@@ -3709,7 +3709,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32465
32466 cm_id->add_ref(cm_id);
32467 ret = cm_id->event_handler(cm_id, &cm_event);
32468- atomic_inc(&cm_closes);
32469+ atomic_inc_unchecked(&cm_closes);
32470 cm_event.event = IW_CM_EVENT_CLOSE;
32471 cm_event.status = 0;
32472 cm_event.provider_data = cm_id->provider_data;
32473@@ -3745,7 +3745,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32474 return;
32475 cm_id = cm_node->cm_id;
32476
32477- atomic_inc(&cm_connect_reqs);
32478+ atomic_inc_unchecked(&cm_connect_reqs);
32479 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32480 cm_node, cm_id, jiffies);
32481
32482@@ -3785,7 +3785,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32483 return;
32484 cm_id = cm_node->cm_id;
32485
32486- atomic_inc(&cm_connect_reqs);
32487+ atomic_inc_unchecked(&cm_connect_reqs);
32488 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32489 cm_node, cm_id, jiffies);
32490
32491diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32492index 3ba7be3..c81f6ff 100644
32493--- a/drivers/infiniband/hw/nes/nes_mgt.c
32494+++ b/drivers/infiniband/hw/nes/nes_mgt.c
32495@@ -40,8 +40,8 @@
32496 #include "nes.h"
32497 #include "nes_mgt.h"
32498
32499-atomic_t pau_qps_created;
32500-atomic_t pau_qps_destroyed;
32501+atomic_unchecked_t pau_qps_created;
32502+atomic_unchecked_t pau_qps_destroyed;
32503
32504 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32505 {
32506@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32507 {
32508 struct sk_buff *skb;
32509 unsigned long flags;
32510- atomic_inc(&pau_qps_destroyed);
32511+ atomic_inc_unchecked(&pau_qps_destroyed);
32512
32513 /* Free packets that have not yet been forwarded */
32514 /* Lock is acquired by skb_dequeue when removing the skb */
32515@@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32516 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32517 skb_queue_head_init(&nesqp->pau_list);
32518 spin_lock_init(&nesqp->pau_lock);
32519- atomic_inc(&pau_qps_created);
32520+ atomic_inc_unchecked(&pau_qps_created);
32521 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32522 }
32523
32524diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32525index f3a3ecf..57d311d 100644
32526--- a/drivers/infiniband/hw/nes/nes_nic.c
32527+++ b/drivers/infiniband/hw/nes/nes_nic.c
32528@@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32529 target_stat_values[++index] = mh_detected;
32530 target_stat_values[++index] = mh_pauses_sent;
32531 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32532- target_stat_values[++index] = atomic_read(&cm_connects);
32533- target_stat_values[++index] = atomic_read(&cm_accepts);
32534- target_stat_values[++index] = atomic_read(&cm_disconnects);
32535- target_stat_values[++index] = atomic_read(&cm_connecteds);
32536- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32537- target_stat_values[++index] = atomic_read(&cm_rejects);
32538- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32539- target_stat_values[++index] = atomic_read(&qps_created);
32540- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32541- target_stat_values[++index] = atomic_read(&qps_destroyed);
32542- target_stat_values[++index] = atomic_read(&cm_closes);
32543+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32544+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32545+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32546+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32547+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32548+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32549+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32550+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32551+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32552+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32553+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32554 target_stat_values[++index] = cm_packets_sent;
32555 target_stat_values[++index] = cm_packets_bounced;
32556 target_stat_values[++index] = cm_packets_created;
32557 target_stat_values[++index] = cm_packets_received;
32558 target_stat_values[++index] = cm_packets_dropped;
32559 target_stat_values[++index] = cm_packets_retrans;
32560- target_stat_values[++index] = atomic_read(&cm_listens_created);
32561- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32562+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32563+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32564 target_stat_values[++index] = cm_backlog_drops;
32565- target_stat_values[++index] = atomic_read(&cm_loopbacks);
32566- target_stat_values[++index] = atomic_read(&cm_nodes_created);
32567- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32568- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32569- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32570+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32571+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32572+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32573+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32574+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32575 target_stat_values[++index] = nesadapter->free_4kpbl;
32576 target_stat_values[++index] = nesadapter->free_256pbl;
32577 target_stat_values[++index] = int_mod_timer_init;
32578 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32579 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32580 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32581- target_stat_values[++index] = atomic_read(&pau_qps_created);
32582- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32583+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32584+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32585 }
32586
32587 /**
32588diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32589index 8b8812d..a5e1133 100644
32590--- a/drivers/infiniband/hw/nes/nes_verbs.c
32591+++ b/drivers/infiniband/hw/nes/nes_verbs.c
32592@@ -46,9 +46,9 @@
32593
32594 #include <rdma/ib_umem.h>
32595
32596-atomic_t mod_qp_timouts;
32597-atomic_t qps_created;
32598-atomic_t sw_qps_destroyed;
32599+atomic_unchecked_t mod_qp_timouts;
32600+atomic_unchecked_t qps_created;
32601+atomic_unchecked_t sw_qps_destroyed;
32602
32603 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32604
32605@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32606 if (init_attr->create_flags)
32607 return ERR_PTR(-EINVAL);
32608
32609- atomic_inc(&qps_created);
32610+ atomic_inc_unchecked(&qps_created);
32611 switch (init_attr->qp_type) {
32612 case IB_QPT_RC:
32613 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32614@@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32615 struct iw_cm_event cm_event;
32616 int ret = 0;
32617
32618- atomic_inc(&sw_qps_destroyed);
32619+ atomic_inc_unchecked(&sw_qps_destroyed);
32620 nesqp->destroyed = 1;
32621
32622 /* Blow away the connection if it exists. */
32623diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32624index 7e62f41..4c2b8e2 100644
32625--- a/drivers/infiniband/hw/qib/qib.h
32626+++ b/drivers/infiniband/hw/qib/qib.h
32627@@ -51,6 +51,7 @@
32628 #include <linux/completion.h>
32629 #include <linux/kref.h>
32630 #include <linux/sched.h>
32631+#include <linux/slab.h>
32632
32633 #include "qib_common.h"
32634 #include "qib_verbs.h"
32635diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32636index da739d9..da1c7f4 100644
32637--- a/drivers/input/gameport/gameport.c
32638+++ b/drivers/input/gameport/gameport.c
32639@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32640 */
32641 static void gameport_init_port(struct gameport *gameport)
32642 {
32643- static atomic_t gameport_no = ATOMIC_INIT(0);
32644+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32645
32646 __module_get(THIS_MODULE);
32647
32648 mutex_init(&gameport->drv_mutex);
32649 device_initialize(&gameport->dev);
32650 dev_set_name(&gameport->dev, "gameport%lu",
32651- (unsigned long)atomic_inc_return(&gameport_no) - 1);
32652+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32653 gameport->dev.bus = &gameport_bus;
32654 gameport->dev.release = gameport_release_port;
32655 if (gameport->parent)
32656diff --git a/drivers/input/input.c b/drivers/input/input.c
32657index 8921c61..f5cd63d 100644
32658--- a/drivers/input/input.c
32659+++ b/drivers/input/input.c
32660@@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32661 */
32662 int input_register_device(struct input_dev *dev)
32663 {
32664- static atomic_t input_no = ATOMIC_INIT(0);
32665+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32666 struct input_handler *handler;
32667 const char *path;
32668 int error;
32669@@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32670 dev->setkeycode = input_default_setkeycode;
32671
32672 dev_set_name(&dev->dev, "input%ld",
32673- (unsigned long) atomic_inc_return(&input_no) - 1);
32674+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32675
32676 error = device_add(&dev->dev);
32677 if (error)
32678diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32679index 04c69af..5f92d00 100644
32680--- a/drivers/input/joystick/sidewinder.c
32681+++ b/drivers/input/joystick/sidewinder.c
32682@@ -30,6 +30,7 @@
32683 #include <linux/kernel.h>
32684 #include <linux/module.h>
32685 #include <linux/slab.h>
32686+#include <linux/sched.h>
32687 #include <linux/init.h>
32688 #include <linux/input.h>
32689 #include <linux/gameport.h>
32690diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32691index 83811e4..0822b90 100644
32692--- a/drivers/input/joystick/xpad.c
32693+++ b/drivers/input/joystick/xpad.c
32694@@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32695
32696 static int xpad_led_probe(struct usb_xpad *xpad)
32697 {
32698- static atomic_t led_seq = ATOMIC_INIT(0);
32699+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32700 long led_no;
32701 struct xpad_led *led;
32702 struct led_classdev *led_cdev;
32703@@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32704 if (!led)
32705 return -ENOMEM;
32706
32707- led_no = (long)atomic_inc_return(&led_seq) - 1;
32708+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32709
32710 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32711 led->xpad = xpad;
32712diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32713index 0110b5a..d3ad144 100644
32714--- a/drivers/input/mousedev.c
32715+++ b/drivers/input/mousedev.c
32716@@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32717
32718 spin_unlock_irq(&client->packet_lock);
32719
32720- if (copy_to_user(buffer, data, count))
32721+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
32722 return -EFAULT;
32723
32724 return count;
32725diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
32726index d0f7533..fb8215b 100644
32727--- a/drivers/input/serio/serio.c
32728+++ b/drivers/input/serio/serio.c
32729@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
32730 */
32731 static void serio_init_port(struct serio *serio)
32732 {
32733- static atomic_t serio_no = ATOMIC_INIT(0);
32734+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
32735
32736 __module_get(THIS_MODULE);
32737
32738@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
32739 mutex_init(&serio->drv_mutex);
32740 device_initialize(&serio->dev);
32741 dev_set_name(&serio->dev, "serio%ld",
32742- (long)atomic_inc_return(&serio_no) - 1);
32743+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
32744 serio->dev.bus = &serio_bus;
32745 serio->dev.release = serio_release_port;
32746 serio->dev.groups = serio_device_attr_groups;
32747diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
32748index 38c4bd8..58965d9 100644
32749--- a/drivers/isdn/capi/capi.c
32750+++ b/drivers/isdn/capi/capi.c
32751@@ -83,8 +83,8 @@ struct capiminor {
32752
32753 struct capi20_appl *ap;
32754 u32 ncci;
32755- atomic_t datahandle;
32756- atomic_t msgid;
32757+ atomic_unchecked_t datahandle;
32758+ atomic_unchecked_t msgid;
32759
32760 struct tty_port port;
32761 int ttyinstop;
32762@@ -392,7 +392,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
32763 capimsg_setu16(s, 2, mp->ap->applid);
32764 capimsg_setu8 (s, 4, CAPI_DATA_B3);
32765 capimsg_setu8 (s, 5, CAPI_RESP);
32766- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
32767+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
32768 capimsg_setu32(s, 8, mp->ncci);
32769 capimsg_setu16(s, 12, datahandle);
32770 }
32771@@ -513,14 +513,14 @@ static void handle_minor_send(struct capiminor *mp)
32772 mp->outbytes -= len;
32773 spin_unlock_bh(&mp->outlock);
32774
32775- datahandle = atomic_inc_return(&mp->datahandle);
32776+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
32777 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
32778 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32779 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32780 capimsg_setu16(skb->data, 2, mp->ap->applid);
32781 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
32782 capimsg_setu8 (skb->data, 5, CAPI_REQ);
32783- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
32784+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
32785 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
32786 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
32787 capimsg_setu16(skb->data, 16, len); /* Data length */
32788diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
32789index a6d9fd2..afdb8a3 100644
32790--- a/drivers/isdn/gigaset/interface.c
32791+++ b/drivers/isdn/gigaset/interface.c
32792@@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
32793 }
32794 tty->driver_data = cs;
32795
32796- ++cs->port.count;
32797+ atomic_inc(&cs->port.count);
32798
32799- if (cs->port.count == 1) {
32800+ if (atomic_read(&cs->port.count) == 1) {
32801 tty_port_tty_set(&cs->port, tty);
32802 tty->low_latency = 1;
32803 }
32804@@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
32805
32806 if (!cs->connected)
32807 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32808- else if (!cs->port.count)
32809+ else if (!atomic_read(&cs->port.count))
32810 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32811- else if (!--cs->port.count)
32812+ else if (!atomic_dec_return(&cs->port.count))
32813 tty_port_tty_set(&cs->port, NULL);
32814
32815 mutex_unlock(&cs->mutex);
32816diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
32817index 821f7ac..28d4030 100644
32818--- a/drivers/isdn/hardware/avm/b1.c
32819+++ b/drivers/isdn/hardware/avm/b1.c
32820@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
32821 }
32822 if (left) {
32823 if (t4file->user) {
32824- if (copy_from_user(buf, dp, left))
32825+ if (left > sizeof buf || copy_from_user(buf, dp, left))
32826 return -EFAULT;
32827 } else {
32828 memcpy(buf, dp, left);
32829@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
32830 }
32831 if (left) {
32832 if (config->user) {
32833- if (copy_from_user(buf, dp, left))
32834+ if (left > sizeof buf || copy_from_user(buf, dp, left))
32835 return -EFAULT;
32836 } else {
32837 memcpy(buf, dp, left);
32838diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
32839index dd6b53a..19d9ee6 100644
32840--- a/drivers/isdn/hardware/eicon/divasync.h
32841+++ b/drivers/isdn/hardware/eicon/divasync.h
32842@@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
32843 } diva_didd_add_adapter_t;
32844 typedef struct _diva_didd_remove_adapter {
32845 IDI_CALL p_request;
32846-} diva_didd_remove_adapter_t;
32847+} __no_const diva_didd_remove_adapter_t;
32848 typedef struct _diva_didd_read_adapter_array {
32849 void *buffer;
32850 dword length;
32851diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
32852index d303e65..28bcb7b 100644
32853--- a/drivers/isdn/hardware/eicon/xdi_adapter.h
32854+++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
32855@@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
32856 typedef struct _diva_os_idi_adapter_interface {
32857 diva_init_card_proc_t cleanup_adapter_proc;
32858 diva_cmd_card_proc_t cmd_proc;
32859-} diva_os_idi_adapter_interface_t;
32860+} __no_const diva_os_idi_adapter_interface_t;
32861
32862 typedef struct _diva_os_xdi_adapter {
32863 struct list_head link;
32864diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
32865index 7bc5067..fd36232 100644
32866--- a/drivers/isdn/i4l/isdn_tty.c
32867+++ b/drivers/isdn/i4l/isdn_tty.c
32868@@ -1505,9 +1505,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
32869 port = &info->port;
32870 #ifdef ISDN_DEBUG_MODEM_OPEN
32871 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
32872- port->count);
32873+ atomic_read(&port->count))
32874 #endif
32875- port->count++;
32876+ atomic_inc(&port->count);
32877 tty->driver_data = info;
32878 port->tty = tty;
32879 tty->port = port;
32880@@ -1553,7 +1553,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
32881 #endif
32882 return;
32883 }
32884- if ((tty->count == 1) && (port->count != 1)) {
32885+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
32886 /*
32887 * Uh, oh. tty->count is 1, which means that the tty
32888 * structure will be freed. Info->count should always
32889@@ -1562,15 +1562,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
32890 * serial port won't be shutdown.
32891 */
32892 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
32893- "info->count is %d\n", port->count);
32894- port->count = 1;
32895+ "info->count is %d\n", atomic_read(&port->count));
32896+ atomic_set(&port->count, 1);
32897 }
32898- if (--port->count < 0) {
32899+ if (atomic_dec_return(&port->count) < 0) {
32900 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
32901- info->line, port->count);
32902- port->count = 0;
32903+ info->line, atomic_read(&port->count));
32904+ atomic_set(&port->count, 0);
32905 }
32906- if (port->count) {
32907+ if (atomic_read(&port->count)) {
32908 #ifdef ISDN_DEBUG_MODEM_OPEN
32909 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
32910 #endif
32911@@ -1624,7 +1624,7 @@ isdn_tty_hangup(struct tty_struct *tty)
32912 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
32913 return;
32914 isdn_tty_shutdown(info);
32915- port->count = 0;
32916+ atomic_set(&port->count, 0);
32917 port->flags &= ~ASYNC_NORMAL_ACTIVE;
32918 port->tty = NULL;
32919 wake_up_interruptible(&port->open_wait);
32920@@ -1964,7 +1964,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
32921 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
32922 modem_info *info = &dev->mdm.info[i];
32923
32924- if (info->port.count == 0)
32925+ if (atomic_read(&info->port.count) == 0)
32926 continue;
32927 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
32928 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
32929diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
32930index e74df7c..03a03ba 100644
32931--- a/drivers/isdn/icn/icn.c
32932+++ b/drivers/isdn/icn/icn.c
32933@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
32934 if (count > len)
32935 count = len;
32936 if (user) {
32937- if (copy_from_user(msg, buf, count))
32938+ if (count > sizeof msg || copy_from_user(msg, buf, count))
32939 return -EFAULT;
32940 } else
32941 memcpy(msg, buf, count);
32942diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
32943index b5fdcb7..5b6c59f 100644
32944--- a/drivers/lguest/core.c
32945+++ b/drivers/lguest/core.c
32946@@ -92,9 +92,17 @@ static __init int map_switcher(void)
32947 * it's worked so far. The end address needs +1 because __get_vm_area
32948 * allocates an extra guard page, so we need space for that.
32949 */
32950+
32951+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32952+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32953+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
32954+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32955+#else
32956 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
32957 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
32958 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
32959+#endif
32960+
32961 if (!switcher_vma) {
32962 err = -ENOMEM;
32963 printk("lguest: could not map switcher pages high\n");
32964@@ -119,7 +127,7 @@ static __init int map_switcher(void)
32965 * Now the Switcher is mapped at the right address, we can't fail!
32966 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
32967 */
32968- memcpy(switcher_vma->addr, start_switcher_text,
32969+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
32970 end_switcher_text - start_switcher_text);
32971
32972 printk(KERN_INFO "lguest: mapped switcher at %p\n",
32973diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
32974index 39809035..ce25c5e 100644
32975--- a/drivers/lguest/x86/core.c
32976+++ b/drivers/lguest/x86/core.c
32977@@ -59,7 +59,7 @@ static struct {
32978 /* Offset from where switcher.S was compiled to where we've copied it */
32979 static unsigned long switcher_offset(void)
32980 {
32981- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
32982+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
32983 }
32984
32985 /* This cpu's struct lguest_pages. */
32986@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
32987 * These copies are pretty cheap, so we do them unconditionally: */
32988 /* Save the current Host top-level page directory.
32989 */
32990+
32991+#ifdef CONFIG_PAX_PER_CPU_PGD
32992+ pages->state.host_cr3 = read_cr3();
32993+#else
32994 pages->state.host_cr3 = __pa(current->mm->pgd);
32995+#endif
32996+
32997 /*
32998 * Set up the Guest's page tables to see this CPU's pages (and no
32999 * other CPU's pages).
33000@@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
33001 * compiled-in switcher code and the high-mapped copy we just made.
33002 */
33003 for (i = 0; i < IDT_ENTRIES; i++)
33004- default_idt_entries[i] += switcher_offset();
33005+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33006
33007 /*
33008 * Set up the Switcher's per-cpu areas.
33009@@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
33010 * it will be undisturbed when we switch. To change %cs and jump we
33011 * need this structure to feed to Intel's "lcall" instruction.
33012 */
33013- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33014+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33015 lguest_entry.segment = LGUEST_CS;
33016
33017 /*
33018diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33019index 40634b0..4f5855e 100644
33020--- a/drivers/lguest/x86/switcher_32.S
33021+++ b/drivers/lguest/x86/switcher_32.S
33022@@ -87,6 +87,7 @@
33023 #include <asm/page.h>
33024 #include <asm/segment.h>
33025 #include <asm/lguest.h>
33026+#include <asm/processor-flags.h>
33027
33028 // We mark the start of the code to copy
33029 // It's placed in .text tho it's never run here
33030@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33031 // Changes type when we load it: damn Intel!
33032 // For after we switch over our page tables
33033 // That entry will be read-only: we'd crash.
33034+
33035+#ifdef CONFIG_PAX_KERNEXEC
33036+ mov %cr0, %edx
33037+ xor $X86_CR0_WP, %edx
33038+ mov %edx, %cr0
33039+#endif
33040+
33041 movl $(GDT_ENTRY_TSS*8), %edx
33042 ltr %dx
33043
33044@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33045 // Let's clear it again for our return.
33046 // The GDT descriptor of the Host
33047 // Points to the table after two "size" bytes
33048- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33049+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33050 // Clear "used" from type field (byte 5, bit 2)
33051- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33052+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33053+
33054+#ifdef CONFIG_PAX_KERNEXEC
33055+ mov %cr0, %eax
33056+ xor $X86_CR0_WP, %eax
33057+ mov %eax, %cr0
33058+#endif
33059
33060 // Once our page table's switched, the Guest is live!
33061 // The Host fades as we run this final step.
33062@@ -295,13 +309,12 @@ deliver_to_host:
33063 // I consulted gcc, and it gave
33064 // These instructions, which I gladly credit:
33065 leal (%edx,%ebx,8), %eax
33066- movzwl (%eax),%edx
33067- movl 4(%eax), %eax
33068- xorw %ax, %ax
33069- orl %eax, %edx
33070+ movl 4(%eax), %edx
33071+ movw (%eax), %dx
33072 // Now the address of the handler's in %edx
33073 // We call it now: its "iret" drops us home.
33074- jmp *%edx
33075+ ljmp $__KERNEL_CS, $1f
33076+1: jmp *%edx
33077
33078 // Every interrupt can come to us here
33079 // But we must truly tell each apart.
33080diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33081index 20e5c2c..9e849a9 100644
33082--- a/drivers/macintosh/macio_asic.c
33083+++ b/drivers/macintosh/macio_asic.c
33084@@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33085 * MacIO is matched against any Apple ID, it's probe() function
33086 * will then decide wether it applies or not
33087 */
33088-static const struct pci_device_id __devinitdata pci_ids [] = { {
33089+static const struct pci_device_id __devinitconst pci_ids [] = { {
33090 .vendor = PCI_VENDOR_ID_APPLE,
33091 .device = PCI_ANY_ID,
33092 .subvendor = PCI_ANY_ID,
33093diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33094index 15dbe03..743fc65 100644
33095--- a/drivers/md/bitmap.c
33096+++ b/drivers/md/bitmap.c
33097@@ -1786,7 +1786,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33098 chunk_kb ? "KB" : "B");
33099 if (bitmap->storage.file) {
33100 seq_printf(seq, ", file: ");
33101- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
33102+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
33103 }
33104
33105 seq_printf(seq, "\n");
33106diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33107index a1a3e6d..1918bfc 100644
33108--- a/drivers/md/dm-ioctl.c
33109+++ b/drivers/md/dm-ioctl.c
33110@@ -1590,7 +1590,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33111 cmd == DM_LIST_VERSIONS_CMD)
33112 return 0;
33113
33114- if ((cmd == DM_DEV_CREATE_CMD)) {
33115+ if (cmd == DM_DEV_CREATE_CMD) {
33116 if (!*param->name) {
33117 DMWARN("name not supplied when creating device");
33118 return -EINVAL;
33119diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33120index b58b7a3..8018b19 100644
33121--- a/drivers/md/dm-raid1.c
33122+++ b/drivers/md/dm-raid1.c
33123@@ -40,7 +40,7 @@ enum dm_raid1_error {
33124
33125 struct mirror {
33126 struct mirror_set *ms;
33127- atomic_t error_count;
33128+ atomic_unchecked_t error_count;
33129 unsigned long error_type;
33130 struct dm_dev *dev;
33131 sector_t offset;
33132@@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33133 struct mirror *m;
33134
33135 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33136- if (!atomic_read(&m->error_count))
33137+ if (!atomic_read_unchecked(&m->error_count))
33138 return m;
33139
33140 return NULL;
33141@@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33142 * simple way to tell if a device has encountered
33143 * errors.
33144 */
33145- atomic_inc(&m->error_count);
33146+ atomic_inc_unchecked(&m->error_count);
33147
33148 if (test_and_set_bit(error_type, &m->error_type))
33149 return;
33150@@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33151 struct mirror *m = get_default_mirror(ms);
33152
33153 do {
33154- if (likely(!atomic_read(&m->error_count)))
33155+ if (likely(!atomic_read_unchecked(&m->error_count)))
33156 return m;
33157
33158 if (m-- == ms->mirror)
33159@@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33160 {
33161 struct mirror *default_mirror = get_default_mirror(m->ms);
33162
33163- return !atomic_read(&default_mirror->error_count);
33164+ return !atomic_read_unchecked(&default_mirror->error_count);
33165 }
33166
33167 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33168@@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33169 */
33170 if (likely(region_in_sync(ms, region, 1)))
33171 m = choose_mirror(ms, bio->bi_sector);
33172- else if (m && atomic_read(&m->error_count))
33173+ else if (m && atomic_read_unchecked(&m->error_count))
33174 m = NULL;
33175
33176 if (likely(m))
33177@@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33178 }
33179
33180 ms->mirror[mirror].ms = ms;
33181- atomic_set(&(ms->mirror[mirror].error_count), 0);
33182+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33183 ms->mirror[mirror].error_type = 0;
33184 ms->mirror[mirror].offset = offset;
33185
33186@@ -1352,7 +1352,7 @@ static void mirror_resume(struct dm_target *ti)
33187 */
33188 static char device_status_char(struct mirror *m)
33189 {
33190- if (!atomic_read(&(m->error_count)))
33191+ if (!atomic_read_unchecked(&(m->error_count)))
33192 return 'A';
33193
33194 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33195diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33196index 35c94ff..20d4c17 100644
33197--- a/drivers/md/dm-stripe.c
33198+++ b/drivers/md/dm-stripe.c
33199@@ -20,7 +20,7 @@ struct stripe {
33200 struct dm_dev *dev;
33201 sector_t physical_start;
33202
33203- atomic_t error_count;
33204+ atomic_unchecked_t error_count;
33205 };
33206
33207 struct stripe_c {
33208@@ -193,7 +193,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33209 kfree(sc);
33210 return r;
33211 }
33212- atomic_set(&(sc->stripe[i].error_count), 0);
33213+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33214 }
33215
33216 ti->private = sc;
33217@@ -315,7 +315,7 @@ static int stripe_status(struct dm_target *ti,
33218 DMEMIT("%d ", sc->stripes);
33219 for (i = 0; i < sc->stripes; i++) {
33220 DMEMIT("%s ", sc->stripe[i].dev->name);
33221- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33222+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33223 'D' : 'A';
33224 }
33225 buffer[i] = '\0';
33226@@ -362,8 +362,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33227 */
33228 for (i = 0; i < sc->stripes; i++)
33229 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33230- atomic_inc(&(sc->stripe[i].error_count));
33231- if (atomic_read(&(sc->stripe[i].error_count)) <
33232+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
33233+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33234 DM_IO_ERROR_THRESHOLD)
33235 schedule_work(&sc->trigger_event);
33236 }
33237diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33238index 2e227fb..44ead1f 100644
33239--- a/drivers/md/dm-table.c
33240+++ b/drivers/md/dm-table.c
33241@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33242 if (!dev_size)
33243 return 0;
33244
33245- if ((start >= dev_size) || (start + len > dev_size)) {
33246+ if ((start >= dev_size) || (len > dev_size - start)) {
33247 DMWARN("%s: %s too small for target: "
33248 "start=%llu, len=%llu, dev_size=%llu",
33249 dm_device_name(ti->table->md), bdevname(bdev, b),
33250diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33251index 3e2907f..c28851a 100644
33252--- a/drivers/md/dm-thin-metadata.c
33253+++ b/drivers/md/dm-thin-metadata.c
33254@@ -432,7 +432,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33255
33256 pmd->info.tm = tm;
33257 pmd->info.levels = 2;
33258- pmd->info.value_type.context = pmd->data_sm;
33259+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33260 pmd->info.value_type.size = sizeof(__le64);
33261 pmd->info.value_type.inc = data_block_inc;
33262 pmd->info.value_type.dec = data_block_dec;
33263@@ -451,7 +451,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33264
33265 pmd->bl_info.tm = tm;
33266 pmd->bl_info.levels = 1;
33267- pmd->bl_info.value_type.context = pmd->data_sm;
33268+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33269 pmd->bl_info.value_type.size = sizeof(__le64);
33270 pmd->bl_info.value_type.inc = data_block_inc;
33271 pmd->bl_info.value_type.dec = data_block_dec;
33272diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33273index e24143c..ce2f21a1 100644
33274--- a/drivers/md/dm.c
33275+++ b/drivers/md/dm.c
33276@@ -176,9 +176,9 @@ struct mapped_device {
33277 /*
33278 * Event handling.
33279 */
33280- atomic_t event_nr;
33281+ atomic_unchecked_t event_nr;
33282 wait_queue_head_t eventq;
33283- atomic_t uevent_seq;
33284+ atomic_unchecked_t uevent_seq;
33285 struct list_head uevent_list;
33286 spinlock_t uevent_lock; /* Protect access to uevent_list */
33287
33288@@ -1845,8 +1845,8 @@ static struct mapped_device *alloc_dev(int minor)
33289 rwlock_init(&md->map_lock);
33290 atomic_set(&md->holders, 1);
33291 atomic_set(&md->open_count, 0);
33292- atomic_set(&md->event_nr, 0);
33293- atomic_set(&md->uevent_seq, 0);
33294+ atomic_set_unchecked(&md->event_nr, 0);
33295+ atomic_set_unchecked(&md->uevent_seq, 0);
33296 INIT_LIST_HEAD(&md->uevent_list);
33297 spin_lock_init(&md->uevent_lock);
33298
33299@@ -1980,7 +1980,7 @@ static void event_callback(void *context)
33300
33301 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33302
33303- atomic_inc(&md->event_nr);
33304+ atomic_inc_unchecked(&md->event_nr);
33305 wake_up(&md->eventq);
33306 }
33307
33308@@ -2622,18 +2622,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33309
33310 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33311 {
33312- return atomic_add_return(1, &md->uevent_seq);
33313+ return atomic_add_return_unchecked(1, &md->uevent_seq);
33314 }
33315
33316 uint32_t dm_get_event_nr(struct mapped_device *md)
33317 {
33318- return atomic_read(&md->event_nr);
33319+ return atomic_read_unchecked(&md->event_nr);
33320 }
33321
33322 int dm_wait_event(struct mapped_device *md, int event_nr)
33323 {
33324 return wait_event_interruptible(md->eventq,
33325- (event_nr != atomic_read(&md->event_nr)));
33326+ (event_nr != atomic_read_unchecked(&md->event_nr)));
33327 }
33328
33329 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33330diff --git a/drivers/md/md.c b/drivers/md/md.c
33331index d5ab449..7e9ed7b 100644
33332--- a/drivers/md/md.c
33333+++ b/drivers/md/md.c
33334@@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33335 * start build, activate spare
33336 */
33337 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33338-static atomic_t md_event_count;
33339+static atomic_unchecked_t md_event_count;
33340 void md_new_event(struct mddev *mddev)
33341 {
33342- atomic_inc(&md_event_count);
33343+ atomic_inc_unchecked(&md_event_count);
33344 wake_up(&md_event_waiters);
33345 }
33346 EXPORT_SYMBOL_GPL(md_new_event);
33347@@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33348 */
33349 static void md_new_event_inintr(struct mddev *mddev)
33350 {
33351- atomic_inc(&md_event_count);
33352+ atomic_inc_unchecked(&md_event_count);
33353 wake_up(&md_event_waiters);
33354 }
33355
33356@@ -1565,7 +1565,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33357 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
33358 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
33359 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
33360- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33361+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33362
33363 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33364 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33365@@ -1809,7 +1809,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33366 else
33367 sb->resync_offset = cpu_to_le64(0);
33368
33369- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33370+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33371
33372 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33373 sb->size = cpu_to_le64(mddev->dev_sectors);
33374@@ -2803,7 +2803,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33375 static ssize_t
33376 errors_show(struct md_rdev *rdev, char *page)
33377 {
33378- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33379+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33380 }
33381
33382 static ssize_t
33383@@ -2812,7 +2812,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33384 char *e;
33385 unsigned long n = simple_strtoul(buf, &e, 10);
33386 if (*buf && (*e == 0 || *e == '\n')) {
33387- atomic_set(&rdev->corrected_errors, n);
33388+ atomic_set_unchecked(&rdev->corrected_errors, n);
33389 return len;
33390 }
33391 return -EINVAL;
33392@@ -3259,8 +3259,8 @@ int md_rdev_init(struct md_rdev *rdev)
33393 rdev->sb_loaded = 0;
33394 rdev->bb_page = NULL;
33395 atomic_set(&rdev->nr_pending, 0);
33396- atomic_set(&rdev->read_errors, 0);
33397- atomic_set(&rdev->corrected_errors, 0);
33398+ atomic_set_unchecked(&rdev->read_errors, 0);
33399+ atomic_set_unchecked(&rdev->corrected_errors, 0);
33400
33401 INIT_LIST_HEAD(&rdev->same_set);
33402 init_waitqueue_head(&rdev->blocked_wait);
33403@@ -6997,7 +6997,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33404
33405 spin_unlock(&pers_lock);
33406 seq_printf(seq, "\n");
33407- seq->poll_event = atomic_read(&md_event_count);
33408+ seq->poll_event = atomic_read_unchecked(&md_event_count);
33409 return 0;
33410 }
33411 if (v == (void*)2) {
33412@@ -7100,7 +7100,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33413 return error;
33414
33415 seq = file->private_data;
33416- seq->poll_event = atomic_read(&md_event_count);
33417+ seq->poll_event = atomic_read_unchecked(&md_event_count);
33418 return error;
33419 }
33420
33421@@ -7114,7 +7114,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33422 /* always allow read */
33423 mask = POLLIN | POLLRDNORM;
33424
33425- if (seq->poll_event != atomic_read(&md_event_count))
33426+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33427 mask |= POLLERR | POLLPRI;
33428 return mask;
33429 }
33430@@ -7158,7 +7158,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33431 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33432 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33433 (int)part_stat_read(&disk->part0, sectors[1]) -
33434- atomic_read(&disk->sync_io);
33435+ atomic_read_unchecked(&disk->sync_io);
33436 /* sync IO will cause sync_io to increase before the disk_stats
33437 * as sync_io is counted when a request starts, and
33438 * disk_stats is counted when it completes.
33439diff --git a/drivers/md/md.h b/drivers/md/md.h
33440index 7b4a3c3..994ad4f 100644
33441--- a/drivers/md/md.h
33442+++ b/drivers/md/md.h
33443@@ -94,13 +94,13 @@ struct md_rdev {
33444 * only maintained for arrays that
33445 * support hot removal
33446 */
33447- atomic_t read_errors; /* number of consecutive read errors that
33448+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
33449 * we have tried to ignore.
33450 */
33451 struct timespec last_read_error; /* monotonic time since our
33452 * last read error
33453 */
33454- atomic_t corrected_errors; /* number of corrected read errors,
33455+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33456 * for reporting to userspace and storing
33457 * in superblock.
33458 */
33459@@ -435,7 +435,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33460
33461 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33462 {
33463- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33464+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33465 }
33466
33467 struct md_personality
33468diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
33469index fc90c11..c8cd9a9 100644
33470--- a/drivers/md/persistent-data/dm-space-map-checker.c
33471+++ b/drivers/md/persistent-data/dm-space-map-checker.c
33472@@ -167,7 +167,7 @@ static int ca_commit(struct count_array *old, struct count_array *new)
33473 /*----------------------------------------------------------------*/
33474
33475 struct sm_checker {
33476- struct dm_space_map sm;
33477+ dm_space_map_no_const sm;
33478
33479 struct count_array old_counts;
33480 struct count_array counts;
33481diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33482index 3d0ed53..35dc592 100644
33483--- a/drivers/md/persistent-data/dm-space-map-disk.c
33484+++ b/drivers/md/persistent-data/dm-space-map-disk.c
33485@@ -23,7 +23,7 @@
33486 * Space map interface.
33487 */
33488 struct sm_disk {
33489- struct dm_space_map sm;
33490+ dm_space_map_no_const sm;
33491
33492 struct ll_disk ll;
33493 struct ll_disk old_ll;
33494diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33495index e89ae5e..062e4c2 100644
33496--- a/drivers/md/persistent-data/dm-space-map-metadata.c
33497+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33498@@ -43,7 +43,7 @@ struct block_op {
33499 };
33500
33501 struct sm_metadata {
33502- struct dm_space_map sm;
33503+ dm_space_map_no_const sm;
33504
33505 struct ll_disk ll;
33506 struct ll_disk old_ll;
33507diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33508index 1cbfc6b..56e1dbb 100644
33509--- a/drivers/md/persistent-data/dm-space-map.h
33510+++ b/drivers/md/persistent-data/dm-space-map.h
33511@@ -60,6 +60,7 @@ struct dm_space_map {
33512 int (*root_size)(struct dm_space_map *sm, size_t *result);
33513 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33514 };
33515+typedef struct dm_space_map __no_const dm_space_map_no_const;
33516
33517 /*----------------------------------------------------------------*/
33518
33519diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33520index 53aec45..250851c 100644
33521--- a/drivers/md/raid1.c
33522+++ b/drivers/md/raid1.c
33523@@ -1685,7 +1685,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33524 if (r1_sync_page_io(rdev, sect, s,
33525 bio->bi_io_vec[idx].bv_page,
33526 READ) != 0)
33527- atomic_add(s, &rdev->corrected_errors);
33528+ atomic_add_unchecked(s, &rdev->corrected_errors);
33529 }
33530 sectors -= s;
33531 sect += s;
33532@@ -1907,7 +1907,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33533 test_bit(In_sync, &rdev->flags)) {
33534 if (r1_sync_page_io(rdev, sect, s,
33535 conf->tmppage, READ)) {
33536- atomic_add(s, &rdev->corrected_errors);
33537+ atomic_add_unchecked(s, &rdev->corrected_errors);
33538 printk(KERN_INFO
33539 "md/raid1:%s: read error corrected "
33540 "(%d sectors at %llu on %s)\n",
33541diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33542index 8da6282..8ec7103 100644
33543--- a/drivers/md/raid10.c
33544+++ b/drivers/md/raid10.c
33545@@ -1784,7 +1784,7 @@ static void end_sync_read(struct bio *bio, int error)
33546 /* The write handler will notice the lack of
33547 * R10BIO_Uptodate and record any errors etc
33548 */
33549- atomic_add(r10_bio->sectors,
33550+ atomic_add_unchecked(r10_bio->sectors,
33551 &conf->mirrors[d].rdev->corrected_errors);
33552
33553 /* for reconstruct, we always reschedule after a read.
33554@@ -2133,7 +2133,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33555 {
33556 struct timespec cur_time_mon;
33557 unsigned long hours_since_last;
33558- unsigned int read_errors = atomic_read(&rdev->read_errors);
33559+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33560
33561 ktime_get_ts(&cur_time_mon);
33562
33563@@ -2155,9 +2155,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33564 * overflowing the shift of read_errors by hours_since_last.
33565 */
33566 if (hours_since_last >= 8 * sizeof(read_errors))
33567- atomic_set(&rdev->read_errors, 0);
33568+ atomic_set_unchecked(&rdev->read_errors, 0);
33569 else
33570- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33571+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33572 }
33573
33574 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33575@@ -2211,8 +2211,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33576 return;
33577
33578 check_decay_read_errors(mddev, rdev);
33579- atomic_inc(&rdev->read_errors);
33580- if (atomic_read(&rdev->read_errors) > max_read_errors) {
33581+ atomic_inc_unchecked(&rdev->read_errors);
33582+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33583 char b[BDEVNAME_SIZE];
33584 bdevname(rdev->bdev, b);
33585
33586@@ -2220,7 +2220,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33587 "md/raid10:%s: %s: Raid device exceeded "
33588 "read_error threshold [cur %d:max %d]\n",
33589 mdname(mddev), b,
33590- atomic_read(&rdev->read_errors), max_read_errors);
33591+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33592 printk(KERN_NOTICE
33593 "md/raid10:%s: %s: Failing raid device\n",
33594 mdname(mddev), b);
33595@@ -2375,7 +2375,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33596 sect +
33597 choose_data_offset(r10_bio, rdev)),
33598 bdevname(rdev->bdev, b));
33599- atomic_add(s, &rdev->corrected_errors);
33600+ atomic_add_unchecked(s, &rdev->corrected_errors);
33601 }
33602
33603 rdev_dec_pending(rdev, mddev);
33604diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33605index 04348d7..62a4b9b 100644
33606--- a/drivers/md/raid5.c
33607+++ b/drivers/md/raid5.c
33608@@ -1736,19 +1736,19 @@ static void raid5_end_read_request(struct bio * bi, int error)
33609 mdname(conf->mddev), STRIPE_SECTORS,
33610 (unsigned long long)s,
33611 bdevname(rdev->bdev, b));
33612- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33613+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33614 clear_bit(R5_ReadError, &sh->dev[i].flags);
33615 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33616 }
33617- if (atomic_read(&rdev->read_errors))
33618- atomic_set(&rdev->read_errors, 0);
33619+ if (atomic_read_unchecked(&rdev->read_errors))
33620+ atomic_set_unchecked(&rdev->read_errors, 0);
33621 } else {
33622 const char *bdn = bdevname(rdev->bdev, b);
33623 int retry = 0;
33624 int set_bad = 0;
33625
33626 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33627- atomic_inc(&rdev->read_errors);
33628+ atomic_inc_unchecked(&rdev->read_errors);
33629 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33630 printk_ratelimited(
33631 KERN_WARNING
33632@@ -1776,7 +1776,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33633 mdname(conf->mddev),
33634 (unsigned long long)s,
33635 bdn);
33636- } else if (atomic_read(&rdev->read_errors)
33637+ } else if (atomic_read_unchecked(&rdev->read_errors)
33638 > conf->max_nr_stripes)
33639 printk(KERN_WARNING
33640 "md/raid:%s: Too many read errors, failing device %s.\n",
33641diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33642index 131b938..8572ed1 100644
33643--- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33644+++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33645@@ -1678,7 +1678,7 @@ static struct ddb_info ddb_v6 = {
33646 .subvendor = _subvend, .subdevice = _subdev, \
33647 .driver_data = (unsigned long)&_driverdata }
33648
33649-static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33650+static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33651 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33652 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33653 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33654diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33655index fa7188a..04a045e 100644
33656--- a/drivers/media/dvb/dvb-core/dvb_demux.h
33657+++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33658@@ -73,7 +73,7 @@ struct dvb_demux_feed {
33659 union {
33660 dmx_ts_cb ts;
33661 dmx_section_cb sec;
33662- } cb;
33663+ } __no_const cb;
33664
33665 struct dvb_demux *demux;
33666 void *priv;
33667diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33668index 39eab73..60033e7 100644
33669--- a/drivers/media/dvb/dvb-core/dvbdev.c
33670+++ b/drivers/media/dvb/dvb-core/dvbdev.c
33671@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33672 const struct dvb_device *template, void *priv, int type)
33673 {
33674 struct dvb_device *dvbdev;
33675- struct file_operations *dvbdevfops;
33676+ file_operations_no_const *dvbdevfops;
33677 struct device *clsdev;
33678 int minor;
33679 int id;
33680diff --git a/drivers/media/dvb/dvb-usb/az6007.c b/drivers/media/dvb/dvb-usb/az6007.c
33681index 4008b9c..ce714f5 100644
33682--- a/drivers/media/dvb/dvb-usb/az6007.c
33683+++ b/drivers/media/dvb/dvb-usb/az6007.c
33684@@ -590,7 +590,7 @@ static int az6007_read_mac_addr(struct dvb_usb_device *d, u8 mac[6])
33685 int ret;
33686
33687 ret = az6007_read(d, AZ6007_READ_DATA, 6, 0, st->data, 6);
33688- memcpy(mac, st->data, sizeof(mac));
33689+ memcpy(mac, st->data, 6);
33690
33691 if (ret > 0)
33692 deb_info("%s: mac is %02x:%02x:%02x:%02x:%02x:%02x\n",
33693diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33694index 3940bb0..fb3952a 100644
33695--- a/drivers/media/dvb/dvb-usb/cxusb.c
33696+++ b/drivers/media/dvb/dvb-usb/cxusb.c
33697@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33698
33699 struct dib0700_adapter_state {
33700 int (*set_param_save) (struct dvb_frontend *);
33701-};
33702+} __no_const;
33703
33704 static int dib7070_set_param_override(struct dvb_frontend *fe)
33705 {
33706diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33707index 9382895..ac8093c 100644
33708--- a/drivers/media/dvb/dvb-usb/dw2102.c
33709+++ b/drivers/media/dvb/dvb-usb/dw2102.c
33710@@ -95,7 +95,7 @@ struct su3000_state {
33711
33712 struct s6x0_state {
33713 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33714-};
33715+} __no_const;
33716
33717 /* debug */
33718 static int dvb_usb_dw2102_debug;
33719diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33720index 404f63a..4796533 100644
33721--- a/drivers/media/dvb/frontends/dib3000.h
33722+++ b/drivers/media/dvb/frontends/dib3000.h
33723@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33724 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33725 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33726 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33727-};
33728+} __no_const;
33729
33730 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33731 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33732diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33733index 7539a5d..06531a6 100644
33734--- a/drivers/media/dvb/ngene/ngene-cards.c
33735+++ b/drivers/media/dvb/ngene/ngene-cards.c
33736@@ -478,7 +478,7 @@ static struct ngene_info ngene_info_m780 = {
33737
33738 /****************************************************************************/
33739
33740-static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33741+static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
33742 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
33743 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
33744 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
33745diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
33746index 16a089f..1661b11 100644
33747--- a/drivers/media/radio/radio-cadet.c
33748+++ b/drivers/media/radio/radio-cadet.c
33749@@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33750 unsigned char readbuf[RDS_BUFFER];
33751 int i = 0;
33752
33753+ if (count > RDS_BUFFER)
33754+ return -EFAULT;
33755 mutex_lock(&dev->lock);
33756 if (dev->rdsstat == 0) {
33757 dev->rdsstat = 1;
33758@@ -347,7 +349,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33759 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
33760 mutex_unlock(&dev->lock);
33761
33762- if (copy_to_user(data, readbuf, i))
33763+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
33764 return -EFAULT;
33765 return i;
33766 }
33767diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
33768index 9cde353..8c6a1c3 100644
33769--- a/drivers/media/video/au0828/au0828.h
33770+++ b/drivers/media/video/au0828/au0828.h
33771@@ -191,7 +191,7 @@ struct au0828_dev {
33772
33773 /* I2C */
33774 struct i2c_adapter i2c_adap;
33775- struct i2c_algorithm i2c_algo;
33776+ i2c_algorithm_no_const i2c_algo;
33777 struct i2c_client i2c_client;
33778 u32 i2c_rc;
33779
33780diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
33781index 04bf662..e0ac026 100644
33782--- a/drivers/media/video/cx88/cx88-alsa.c
33783+++ b/drivers/media/video/cx88/cx88-alsa.c
33784@@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
33785 * Only boards with eeprom and byte 1 at eeprom=1 have it
33786 */
33787
33788-static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
33789+static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
33790 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33791 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33792 {0, }
33793diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
33794index 88cf9d9..bbc4b2c 100644
33795--- a/drivers/media/video/omap/omap_vout.c
33796+++ b/drivers/media/video/omap/omap_vout.c
33797@@ -64,7 +64,6 @@ enum omap_vout_channels {
33798 OMAP_VIDEO2,
33799 };
33800
33801-static struct videobuf_queue_ops video_vbq_ops;
33802 /* Variables configurable through module params*/
33803 static u32 video1_numbuffers = 3;
33804 static u32 video2_numbuffers = 3;
33805@@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
33806 {
33807 struct videobuf_queue *q;
33808 struct omap_vout_device *vout = NULL;
33809+ static struct videobuf_queue_ops video_vbq_ops = {
33810+ .buf_setup = omap_vout_buffer_setup,
33811+ .buf_prepare = omap_vout_buffer_prepare,
33812+ .buf_release = omap_vout_buffer_release,
33813+ .buf_queue = omap_vout_buffer_queue,
33814+ };
33815
33816 vout = video_drvdata(file);
33817 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
33818@@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
33819 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
33820
33821 q = &vout->vbq;
33822- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
33823- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
33824- video_vbq_ops.buf_release = omap_vout_buffer_release;
33825- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
33826 spin_lock_init(&vout->vbq_lock);
33827
33828 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
33829diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33830index 036952f..80d356d 100644
33831--- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33832+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33833@@ -196,7 +196,7 @@ struct pvr2_hdw {
33834
33835 /* I2C stuff */
33836 struct i2c_adapter i2c_adap;
33837- struct i2c_algorithm i2c_algo;
33838+ i2c_algorithm_no_const i2c_algo;
33839 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
33840 int i2c_cx25840_hack_state;
33841 int i2c_linked;
33842diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
33843index 02194c0..091733b 100644
33844--- a/drivers/media/video/timblogiw.c
33845+++ b/drivers/media/video/timblogiw.c
33846@@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
33847
33848 /* Platform device functions */
33849
33850-static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33851+static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
33852 .vidioc_querycap = timblogiw_querycap,
33853 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
33854 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
33855@@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33856 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
33857 };
33858
33859-static __devinitconst struct v4l2_file_operations timblogiw_fops = {
33860+static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
33861 .owner = THIS_MODULE,
33862 .open = timblogiw_open,
33863 .release = timblogiw_close,
33864diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
33865index d99db56..a16b959 100644
33866--- a/drivers/message/fusion/mptbase.c
33867+++ b/drivers/message/fusion/mptbase.c
33868@@ -6751,8 +6751,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
33869 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
33870 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
33871
33872+#ifdef CONFIG_GRKERNSEC_HIDESYM
33873+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
33874+#else
33875 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33876 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
33877+#endif
33878+
33879 /*
33880 * Rounding UP to nearest 4-kB boundary here...
33881 */
33882diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
33883index 551262e..7551198 100644
33884--- a/drivers/message/fusion/mptsas.c
33885+++ b/drivers/message/fusion/mptsas.c
33886@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
33887 return 0;
33888 }
33889
33890+static inline void
33891+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33892+{
33893+ if (phy_info->port_details) {
33894+ phy_info->port_details->rphy = rphy;
33895+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33896+ ioc->name, rphy));
33897+ }
33898+
33899+ if (rphy) {
33900+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33901+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33902+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33903+ ioc->name, rphy, rphy->dev.release));
33904+ }
33905+}
33906+
33907 /* no mutex */
33908 static void
33909 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
33910@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
33911 return NULL;
33912 }
33913
33914-static inline void
33915-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33916-{
33917- if (phy_info->port_details) {
33918- phy_info->port_details->rphy = rphy;
33919- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33920- ioc->name, rphy));
33921- }
33922-
33923- if (rphy) {
33924- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33925- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33926- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33927- ioc->name, rphy, rphy->dev.release));
33928- }
33929-}
33930-
33931 static inline struct sas_port *
33932 mptsas_get_port(struct mptsas_phyinfo *phy_info)
33933 {
33934diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
33935index 0c3ced7..1fe34ec 100644
33936--- a/drivers/message/fusion/mptscsih.c
33937+++ b/drivers/message/fusion/mptscsih.c
33938@@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
33939
33940 h = shost_priv(SChost);
33941
33942- if (h) {
33943- if (h->info_kbuf == NULL)
33944- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33945- return h->info_kbuf;
33946- h->info_kbuf[0] = '\0';
33947+ if (!h)
33948+ return NULL;
33949
33950- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33951- h->info_kbuf[size-1] = '\0';
33952- }
33953+ if (h->info_kbuf == NULL)
33954+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33955+ return h->info_kbuf;
33956+ h->info_kbuf[0] = '\0';
33957+
33958+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
33959+ h->info_kbuf[size-1] = '\0';
33960
33961 return h->info_kbuf;
33962 }
33963diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
33964index 506c36f..b137580 100644
33965--- a/drivers/message/i2o/i2o_proc.c
33966+++ b/drivers/message/i2o/i2o_proc.c
33967@@ -255,13 +255,6 @@ static char *scsi_devices[] = {
33968 "Array Controller Device"
33969 };
33970
33971-static char *chtostr(u8 * chars, int n)
33972-{
33973- char tmp[256];
33974- tmp[0] = 0;
33975- return strncat(tmp, (char *)chars, n);
33976-}
33977-
33978 static int i2o_report_query_status(struct seq_file *seq, int block_status,
33979 char *group)
33980 {
33981@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
33982
33983 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
33984 seq_printf(seq, "%-#8x", ddm_table.module_id);
33985- seq_printf(seq, "%-29s",
33986- chtostr(ddm_table.module_name_version, 28));
33987+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
33988 seq_printf(seq, "%9d ", ddm_table.data_size);
33989 seq_printf(seq, "%8d", ddm_table.code_size);
33990
33991@@ -927,8 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
33992
33993 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
33994 seq_printf(seq, "%-#8x", dst->module_id);
33995- seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
33996- seq_printf(seq, "%-9s", chtostr(dst->date, 8));
33997+ seq_printf(seq, "%-.28s", dst->module_name_version);
33998+ seq_printf(seq, "%-.8s", dst->date);
33999 seq_printf(seq, "%8d ", dst->module_size);
34000 seq_printf(seq, "%8d ", dst->mpb_size);
34001 seq_printf(seq, "0x%04x", dst->module_flags);
34002@@ -1259,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34003 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34004 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34005 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34006- seq_printf(seq, "Vendor info : %s\n",
34007- chtostr((u8 *) (work32 + 2), 16));
34008- seq_printf(seq, "Product info : %s\n",
34009- chtostr((u8 *) (work32 + 6), 16));
34010- seq_printf(seq, "Description : %s\n",
34011- chtostr((u8 *) (work32 + 10), 16));
34012- seq_printf(seq, "Product rev. : %s\n",
34013- chtostr((u8 *) (work32 + 14), 8));
34014+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34015+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34016+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34017+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34018
34019 seq_printf(seq, "Serial number : ");
34020 print_serial_number(seq, (u8 *) (work32 + 16),
34021@@ -1311,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34022 }
34023
34024 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34025- seq_printf(seq, "Module name : %s\n",
34026- chtostr(result.module_name, 24));
34027- seq_printf(seq, "Module revision : %s\n",
34028- chtostr(result.module_rev, 8));
34029+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
34030+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34031
34032 seq_printf(seq, "Serial number : ");
34033 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34034@@ -1345,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34035 return 0;
34036 }
34037
34038- seq_printf(seq, "Device name : %s\n",
34039- chtostr(result.device_name, 64));
34040- seq_printf(seq, "Service name : %s\n",
34041- chtostr(result.service_name, 64));
34042- seq_printf(seq, "Physical name : %s\n",
34043- chtostr(result.physical_location, 64));
34044- seq_printf(seq, "Instance number : %s\n",
34045- chtostr(result.instance_number, 4));
34046+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
34047+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
34048+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34049+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34050
34051 return 0;
34052 }
34053diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34054index a8c08f3..155fe3d 100644
34055--- a/drivers/message/i2o/iop.c
34056+++ b/drivers/message/i2o/iop.c
34057@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34058
34059 spin_lock_irqsave(&c->context_list_lock, flags);
34060
34061- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34062- atomic_inc(&c->context_list_counter);
34063+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34064+ atomic_inc_unchecked(&c->context_list_counter);
34065
34066- entry->context = atomic_read(&c->context_list_counter);
34067+ entry->context = atomic_read_unchecked(&c->context_list_counter);
34068
34069 list_add(&entry->list, &c->context_list);
34070
34071@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34072
34073 #if BITS_PER_LONG == 64
34074 spin_lock_init(&c->context_list_lock);
34075- atomic_set(&c->context_list_counter, 0);
34076+ atomic_set_unchecked(&c->context_list_counter, 0);
34077 INIT_LIST_HEAD(&c->context_list);
34078 #endif
34079
34080diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34081index 7ce65f4..e66e9bc 100644
34082--- a/drivers/mfd/abx500-core.c
34083+++ b/drivers/mfd/abx500-core.c
34084@@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34085
34086 struct abx500_device_entry {
34087 struct list_head list;
34088- struct abx500_ops ops;
34089+ abx500_ops_no_const ops;
34090 struct device *dev;
34091 };
34092
34093diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34094index 2ea9998..51dabee 100644
34095--- a/drivers/mfd/janz-cmodio.c
34096+++ b/drivers/mfd/janz-cmodio.c
34097@@ -13,6 +13,7 @@
34098
34099 #include <linux/kernel.h>
34100 #include <linux/module.h>
34101+#include <linux/slab.h>
34102 #include <linux/init.h>
34103 #include <linux/pci.h>
34104 #include <linux/interrupt.h>
34105diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34106index a981e2a..5ca0c8b 100644
34107--- a/drivers/misc/lis3lv02d/lis3lv02d.c
34108+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34109@@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34110 * the lid is closed. This leads to interrupts as soon as a little move
34111 * is done.
34112 */
34113- atomic_inc(&lis3->count);
34114+ atomic_inc_unchecked(&lis3->count);
34115
34116 wake_up_interruptible(&lis3->misc_wait);
34117 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34118@@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34119 if (lis3->pm_dev)
34120 pm_runtime_get_sync(lis3->pm_dev);
34121
34122- atomic_set(&lis3->count, 0);
34123+ atomic_set_unchecked(&lis3->count, 0);
34124 return 0;
34125 }
34126
34127@@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34128 add_wait_queue(&lis3->misc_wait, &wait);
34129 while (true) {
34130 set_current_state(TASK_INTERRUPTIBLE);
34131- data = atomic_xchg(&lis3->count, 0);
34132+ data = atomic_xchg_unchecked(&lis3->count, 0);
34133 if (data)
34134 break;
34135
34136@@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34137 struct lis3lv02d, miscdev);
34138
34139 poll_wait(file, &lis3->misc_wait, wait);
34140- if (atomic_read(&lis3->count))
34141+ if (atomic_read_unchecked(&lis3->count))
34142 return POLLIN | POLLRDNORM;
34143 return 0;
34144 }
34145diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34146index 2b1482a..5d33616 100644
34147--- a/drivers/misc/lis3lv02d/lis3lv02d.h
34148+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34149@@ -266,7 +266,7 @@ struct lis3lv02d {
34150 struct input_polled_dev *idev; /* input device */
34151 struct platform_device *pdev; /* platform device */
34152 struct regulator_bulk_data regulators[2];
34153- atomic_t count; /* interrupt count after last read */
34154+ atomic_unchecked_t count; /* interrupt count after last read */
34155 union axis_conversion ac; /* hw -> logical axis */
34156 int mapped_btns[3];
34157
34158diff --git a/drivers/misc/lkdtm.c b/drivers/misc/lkdtm.c
34159index 28adefe..08aad69 100644
34160--- a/drivers/misc/lkdtm.c
34161+++ b/drivers/misc/lkdtm.c
34162@@ -477,6 +477,8 @@ static ssize_t lkdtm_debugfs_read(struct file *f, char __user *user_buf,
34163 int i, n, out;
34164
34165 buf = (char *)__get_free_page(GFP_KERNEL);
34166+ if (buf == NULL)
34167+ return -ENOMEM;
34168
34169 n = snprintf(buf, PAGE_SIZE, "Available crash types:\n");
34170 for (i = 0; i < ARRAY_SIZE(cp_type); i++)
34171diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34172index 2f30bad..c4c13d0 100644
34173--- a/drivers/misc/sgi-gru/gruhandles.c
34174+++ b/drivers/misc/sgi-gru/gruhandles.c
34175@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34176 unsigned long nsec;
34177
34178 nsec = CLKS2NSEC(clks);
34179- atomic_long_inc(&mcs_op_statistics[op].count);
34180- atomic_long_add(nsec, &mcs_op_statistics[op].total);
34181+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34182+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34183 if (mcs_op_statistics[op].max < nsec)
34184 mcs_op_statistics[op].max = nsec;
34185 }
34186diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34187index 950dbe9..eeef0f8 100644
34188--- a/drivers/misc/sgi-gru/gruprocfs.c
34189+++ b/drivers/misc/sgi-gru/gruprocfs.c
34190@@ -32,9 +32,9 @@
34191
34192 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34193
34194-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34195+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34196 {
34197- unsigned long val = atomic_long_read(v);
34198+ unsigned long val = atomic_long_read_unchecked(v);
34199
34200 seq_printf(s, "%16lu %s\n", val, id);
34201 }
34202@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34203
34204 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34205 for (op = 0; op < mcsop_last; op++) {
34206- count = atomic_long_read(&mcs_op_statistics[op].count);
34207- total = atomic_long_read(&mcs_op_statistics[op].total);
34208+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34209+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34210 max = mcs_op_statistics[op].max;
34211 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34212 count ? total / count : 0, max);
34213diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34214index 5c3ce24..4915ccb 100644
34215--- a/drivers/misc/sgi-gru/grutables.h
34216+++ b/drivers/misc/sgi-gru/grutables.h
34217@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34218 * GRU statistics.
34219 */
34220 struct gru_stats_s {
34221- atomic_long_t vdata_alloc;
34222- atomic_long_t vdata_free;
34223- atomic_long_t gts_alloc;
34224- atomic_long_t gts_free;
34225- atomic_long_t gms_alloc;
34226- atomic_long_t gms_free;
34227- atomic_long_t gts_double_allocate;
34228- atomic_long_t assign_context;
34229- atomic_long_t assign_context_failed;
34230- atomic_long_t free_context;
34231- atomic_long_t load_user_context;
34232- atomic_long_t load_kernel_context;
34233- atomic_long_t lock_kernel_context;
34234- atomic_long_t unlock_kernel_context;
34235- atomic_long_t steal_user_context;
34236- atomic_long_t steal_kernel_context;
34237- atomic_long_t steal_context_failed;
34238- atomic_long_t nopfn;
34239- atomic_long_t asid_new;
34240- atomic_long_t asid_next;
34241- atomic_long_t asid_wrap;
34242- atomic_long_t asid_reuse;
34243- atomic_long_t intr;
34244- atomic_long_t intr_cbr;
34245- atomic_long_t intr_tfh;
34246- atomic_long_t intr_spurious;
34247- atomic_long_t intr_mm_lock_failed;
34248- atomic_long_t call_os;
34249- atomic_long_t call_os_wait_queue;
34250- atomic_long_t user_flush_tlb;
34251- atomic_long_t user_unload_context;
34252- atomic_long_t user_exception;
34253- atomic_long_t set_context_option;
34254- atomic_long_t check_context_retarget_intr;
34255- atomic_long_t check_context_unload;
34256- atomic_long_t tlb_dropin;
34257- atomic_long_t tlb_preload_page;
34258- atomic_long_t tlb_dropin_fail_no_asid;
34259- atomic_long_t tlb_dropin_fail_upm;
34260- atomic_long_t tlb_dropin_fail_invalid;
34261- atomic_long_t tlb_dropin_fail_range_active;
34262- atomic_long_t tlb_dropin_fail_idle;
34263- atomic_long_t tlb_dropin_fail_fmm;
34264- atomic_long_t tlb_dropin_fail_no_exception;
34265- atomic_long_t tfh_stale_on_fault;
34266- atomic_long_t mmu_invalidate_range;
34267- atomic_long_t mmu_invalidate_page;
34268- atomic_long_t flush_tlb;
34269- atomic_long_t flush_tlb_gru;
34270- atomic_long_t flush_tlb_gru_tgh;
34271- atomic_long_t flush_tlb_gru_zero_asid;
34272+ atomic_long_unchecked_t vdata_alloc;
34273+ atomic_long_unchecked_t vdata_free;
34274+ atomic_long_unchecked_t gts_alloc;
34275+ atomic_long_unchecked_t gts_free;
34276+ atomic_long_unchecked_t gms_alloc;
34277+ atomic_long_unchecked_t gms_free;
34278+ atomic_long_unchecked_t gts_double_allocate;
34279+ atomic_long_unchecked_t assign_context;
34280+ atomic_long_unchecked_t assign_context_failed;
34281+ atomic_long_unchecked_t free_context;
34282+ atomic_long_unchecked_t load_user_context;
34283+ atomic_long_unchecked_t load_kernel_context;
34284+ atomic_long_unchecked_t lock_kernel_context;
34285+ atomic_long_unchecked_t unlock_kernel_context;
34286+ atomic_long_unchecked_t steal_user_context;
34287+ atomic_long_unchecked_t steal_kernel_context;
34288+ atomic_long_unchecked_t steal_context_failed;
34289+ atomic_long_unchecked_t nopfn;
34290+ atomic_long_unchecked_t asid_new;
34291+ atomic_long_unchecked_t asid_next;
34292+ atomic_long_unchecked_t asid_wrap;
34293+ atomic_long_unchecked_t asid_reuse;
34294+ atomic_long_unchecked_t intr;
34295+ atomic_long_unchecked_t intr_cbr;
34296+ atomic_long_unchecked_t intr_tfh;
34297+ atomic_long_unchecked_t intr_spurious;
34298+ atomic_long_unchecked_t intr_mm_lock_failed;
34299+ atomic_long_unchecked_t call_os;
34300+ atomic_long_unchecked_t call_os_wait_queue;
34301+ atomic_long_unchecked_t user_flush_tlb;
34302+ atomic_long_unchecked_t user_unload_context;
34303+ atomic_long_unchecked_t user_exception;
34304+ atomic_long_unchecked_t set_context_option;
34305+ atomic_long_unchecked_t check_context_retarget_intr;
34306+ atomic_long_unchecked_t check_context_unload;
34307+ atomic_long_unchecked_t tlb_dropin;
34308+ atomic_long_unchecked_t tlb_preload_page;
34309+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34310+ atomic_long_unchecked_t tlb_dropin_fail_upm;
34311+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
34312+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
34313+ atomic_long_unchecked_t tlb_dropin_fail_idle;
34314+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
34315+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34316+ atomic_long_unchecked_t tfh_stale_on_fault;
34317+ atomic_long_unchecked_t mmu_invalidate_range;
34318+ atomic_long_unchecked_t mmu_invalidate_page;
34319+ atomic_long_unchecked_t flush_tlb;
34320+ atomic_long_unchecked_t flush_tlb_gru;
34321+ atomic_long_unchecked_t flush_tlb_gru_tgh;
34322+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34323
34324- atomic_long_t copy_gpa;
34325- atomic_long_t read_gpa;
34326+ atomic_long_unchecked_t copy_gpa;
34327+ atomic_long_unchecked_t read_gpa;
34328
34329- atomic_long_t mesq_receive;
34330- atomic_long_t mesq_receive_none;
34331- atomic_long_t mesq_send;
34332- atomic_long_t mesq_send_failed;
34333- atomic_long_t mesq_noop;
34334- atomic_long_t mesq_send_unexpected_error;
34335- atomic_long_t mesq_send_lb_overflow;
34336- atomic_long_t mesq_send_qlimit_reached;
34337- atomic_long_t mesq_send_amo_nacked;
34338- atomic_long_t mesq_send_put_nacked;
34339- atomic_long_t mesq_page_overflow;
34340- atomic_long_t mesq_qf_locked;
34341- atomic_long_t mesq_qf_noop_not_full;
34342- atomic_long_t mesq_qf_switch_head_failed;
34343- atomic_long_t mesq_qf_unexpected_error;
34344- atomic_long_t mesq_noop_unexpected_error;
34345- atomic_long_t mesq_noop_lb_overflow;
34346- atomic_long_t mesq_noop_qlimit_reached;
34347- atomic_long_t mesq_noop_amo_nacked;
34348- atomic_long_t mesq_noop_put_nacked;
34349- atomic_long_t mesq_noop_page_overflow;
34350+ atomic_long_unchecked_t mesq_receive;
34351+ atomic_long_unchecked_t mesq_receive_none;
34352+ atomic_long_unchecked_t mesq_send;
34353+ atomic_long_unchecked_t mesq_send_failed;
34354+ atomic_long_unchecked_t mesq_noop;
34355+ atomic_long_unchecked_t mesq_send_unexpected_error;
34356+ atomic_long_unchecked_t mesq_send_lb_overflow;
34357+ atomic_long_unchecked_t mesq_send_qlimit_reached;
34358+ atomic_long_unchecked_t mesq_send_amo_nacked;
34359+ atomic_long_unchecked_t mesq_send_put_nacked;
34360+ atomic_long_unchecked_t mesq_page_overflow;
34361+ atomic_long_unchecked_t mesq_qf_locked;
34362+ atomic_long_unchecked_t mesq_qf_noop_not_full;
34363+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
34364+ atomic_long_unchecked_t mesq_qf_unexpected_error;
34365+ atomic_long_unchecked_t mesq_noop_unexpected_error;
34366+ atomic_long_unchecked_t mesq_noop_lb_overflow;
34367+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
34368+ atomic_long_unchecked_t mesq_noop_amo_nacked;
34369+ atomic_long_unchecked_t mesq_noop_put_nacked;
34370+ atomic_long_unchecked_t mesq_noop_page_overflow;
34371
34372 };
34373
34374@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34375 tghop_invalidate, mcsop_last};
34376
34377 struct mcs_op_statistic {
34378- atomic_long_t count;
34379- atomic_long_t total;
34380+ atomic_long_unchecked_t count;
34381+ atomic_long_unchecked_t total;
34382 unsigned long max;
34383 };
34384
34385@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34386
34387 #define STAT(id) do { \
34388 if (gru_options & OPT_STATS) \
34389- atomic_long_inc(&gru_stats.id); \
34390+ atomic_long_inc_unchecked(&gru_stats.id); \
34391 } while (0)
34392
34393 #ifdef CONFIG_SGI_GRU_DEBUG
34394diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34395index c862cd4..0d176fe 100644
34396--- a/drivers/misc/sgi-xp/xp.h
34397+++ b/drivers/misc/sgi-xp/xp.h
34398@@ -288,7 +288,7 @@ struct xpc_interface {
34399 xpc_notify_func, void *);
34400 void (*received) (short, int, void *);
34401 enum xp_retval (*partid_to_nasids) (short, void *);
34402-};
34403+} __no_const;
34404
34405 extern struct xpc_interface xpc_interface;
34406
34407diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34408index b94d5f7..7f494c5 100644
34409--- a/drivers/misc/sgi-xp/xpc.h
34410+++ b/drivers/misc/sgi-xp/xpc.h
34411@@ -835,6 +835,7 @@ struct xpc_arch_operations {
34412 void (*received_payload) (struct xpc_channel *, void *);
34413 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34414 };
34415+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34416
34417 /* struct xpc_partition act_state values (for XPC HB) */
34418
34419@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34420 /* found in xpc_main.c */
34421 extern struct device *xpc_part;
34422 extern struct device *xpc_chan;
34423-extern struct xpc_arch_operations xpc_arch_ops;
34424+extern xpc_arch_operations_no_const xpc_arch_ops;
34425 extern int xpc_disengage_timelimit;
34426 extern int xpc_disengage_timedout;
34427 extern int xpc_activate_IRQ_rcvd;
34428diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34429index 8d082b4..aa749ae 100644
34430--- a/drivers/misc/sgi-xp/xpc_main.c
34431+++ b/drivers/misc/sgi-xp/xpc_main.c
34432@@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34433 .notifier_call = xpc_system_die,
34434 };
34435
34436-struct xpc_arch_operations xpc_arch_ops;
34437+xpc_arch_operations_no_const xpc_arch_ops;
34438
34439 /*
34440 * Timer function to enforce the timelimit on the partition disengage.
34441diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c
34442index 2b62232..acfaeeb 100644
34443--- a/drivers/misc/ti-st/st_core.c
34444+++ b/drivers/misc/ti-st/st_core.c
34445@@ -349,6 +349,11 @@ void st_int_recv(void *disc_data,
34446 st_gdata->rx_skb = alloc_skb(
34447 st_gdata->list[type]->max_frame_size,
34448 GFP_ATOMIC);
34449+ if (st_gdata->rx_skb == NULL) {
34450+ pr_err("out of memory: dropping\n");
34451+ goto done;
34452+ }
34453+
34454 skb_reserve(st_gdata->rx_skb,
34455 st_gdata->list[type]->reserve);
34456 /* next 2 required for BT only */
34457diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34458index 504da71..9722d43 100644
34459--- a/drivers/mmc/host/sdhci-pci.c
34460+++ b/drivers/mmc/host/sdhci-pci.c
34461@@ -653,7 +653,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34462 .probe = via_probe,
34463 };
34464
34465-static const struct pci_device_id pci_ids[] __devinitdata = {
34466+static const struct pci_device_id pci_ids[] __devinitconst = {
34467 {
34468 .vendor = PCI_VENDOR_ID_RICOH,
34469 .device = PCI_DEVICE_ID_RICOH_R5C822,
34470diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34471index a4eb8b5..8c0628f 100644
34472--- a/drivers/mtd/devices/doc2000.c
34473+++ b/drivers/mtd/devices/doc2000.c
34474@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34475
34476 /* The ECC will not be calculated correctly if less than 512 is written */
34477 /* DBB-
34478- if (len != 0x200 && eccbuf)
34479+ if (len != 0x200)
34480 printk(KERN_WARNING
34481 "ECC needs a full sector write (adr: %lx size %lx)\n",
34482 (long) to, (long) len);
34483diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34484index 0650aaf..7718762 100644
34485--- a/drivers/mtd/nand/denali.c
34486+++ b/drivers/mtd/nand/denali.c
34487@@ -26,6 +26,7 @@
34488 #include <linux/pci.h>
34489 #include <linux/mtd/mtd.h>
34490 #include <linux/module.h>
34491+#include <linux/slab.h>
34492
34493 #include "denali.h"
34494
34495diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34496index 51b9d6a..52af9a7 100644
34497--- a/drivers/mtd/nftlmount.c
34498+++ b/drivers/mtd/nftlmount.c
34499@@ -24,6 +24,7 @@
34500 #include <asm/errno.h>
34501 #include <linux/delay.h>
34502 #include <linux/slab.h>
34503+#include <linux/sched.h>
34504 #include <linux/mtd/mtd.h>
34505 #include <linux/mtd/nand.h>
34506 #include <linux/mtd/nftl.h>
34507diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34508index 6762dc4..9956862 100644
34509--- a/drivers/net/ethernet/atheros/atlx/atl2.c
34510+++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34511@@ -2859,7 +2859,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34512 */
34513
34514 #define ATL2_PARAM(X, desc) \
34515- static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34516+ static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34517 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34518 MODULE_PARM_DESC(X, desc);
34519 #else
34520diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34521index efd80bd..21fcff0 100644
34522--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34523+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34524@@ -487,7 +487,7 @@ struct bnx2x_rx_mode_obj {
34525
34526 int (*wait_comp)(struct bnx2x *bp,
34527 struct bnx2x_rx_mode_ramrod_params *p);
34528-};
34529+} __no_const;
34530
34531 /********************** Set multicast group ***********************************/
34532
34533diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34534index 93865f8..5448741 100644
34535--- a/drivers/net/ethernet/broadcom/tg3.h
34536+++ b/drivers/net/ethernet/broadcom/tg3.h
34537@@ -140,6 +140,7 @@
34538 #define CHIPREV_ID_5750_A0 0x4000
34539 #define CHIPREV_ID_5750_A1 0x4001
34540 #define CHIPREV_ID_5750_A3 0x4003
34541+#define CHIPREV_ID_5750_C1 0x4201
34542 #define CHIPREV_ID_5750_C2 0x4202
34543 #define CHIPREV_ID_5752_A0_HW 0x5000
34544 #define CHIPREV_ID_5752_A0 0x6000
34545diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34546index c4e8643..0979484 100644
34547--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34548+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34549@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34550 */
34551 struct l2t_skb_cb {
34552 arp_failure_handler_func arp_failure_handler;
34553-};
34554+} __no_const;
34555
34556 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34557
34558diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34559index d3cd489..0fd52dd 100644
34560--- a/drivers/net/ethernet/dec/tulip/de4x5.c
34561+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34562@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34563 for (i=0; i<ETH_ALEN; i++) {
34564 tmp.addr[i] = dev->dev_addr[i];
34565 }
34566- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34567+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34568 break;
34569
34570 case DE4X5_SET_HWADDR: /* Set the hardware address */
34571@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34572 spin_lock_irqsave(&lp->lock, flags);
34573 memcpy(&statbuf, &lp->pktStats, ioc->len);
34574 spin_unlock_irqrestore(&lp->lock, flags);
34575- if (copy_to_user(ioc->data, &statbuf, ioc->len))
34576+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34577 return -EFAULT;
34578 break;
34579 }
34580diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34581index ed7d1dc..d426748 100644
34582--- a/drivers/net/ethernet/dec/tulip/eeprom.c
34583+++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34584@@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34585 {NULL}};
34586
34587
34588-static const char *block_name[] __devinitdata = {
34589+static const char *block_name[] __devinitconst = {
34590 "21140 non-MII",
34591 "21140 MII PHY",
34592 "21142 Serial PHY",
34593diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
34594index 75d45f8..3d9c55b 100644
34595--- a/drivers/net/ethernet/dec/tulip/uli526x.c
34596+++ b/drivers/net/ethernet/dec/tulip/uli526x.c
34597@@ -129,7 +129,7 @@ struct uli526x_board_info {
34598 struct uli_phy_ops {
34599 void (*write)(struct uli526x_board_info *, u8, u8, u16);
34600 u16 (*read)(struct uli526x_board_info *, u8, u8);
34601- } phy;
34602+ } __no_const phy;
34603 struct net_device *next_dev; /* next device */
34604 struct pci_dev *pdev; /* PCI device */
34605 spinlock_t lock;
34606diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34607index 4d1ffca..7c1ec4d 100644
34608--- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34609+++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34610@@ -236,7 +236,7 @@ struct pci_id_info {
34611 int drv_flags; /* Driver use, intended as capability flags. */
34612 };
34613
34614-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34615+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34616 { /* Sometime a Level-One switch card. */
34617 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34618 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34619diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34620index d7bb52a..3b83588 100644
34621--- a/drivers/net/ethernet/dlink/sundance.c
34622+++ b/drivers/net/ethernet/dlink/sundance.c
34623@@ -218,7 +218,7 @@ enum {
34624 struct pci_id_info {
34625 const char *name;
34626 };
34627-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34628+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34629 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34630 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34631 {"D-Link DFE-580TX 4 port Server Adapter"},
34632diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34633index bd5cf7e..c165651 100644
34634--- a/drivers/net/ethernet/emulex/benet/be_main.c
34635+++ b/drivers/net/ethernet/emulex/benet/be_main.c
34636@@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34637
34638 if (wrapped)
34639 newacc += 65536;
34640- ACCESS_ONCE(*acc) = newacc;
34641+ ACCESS_ONCE_RW(*acc) = newacc;
34642 }
34643
34644 void be_parse_stats(struct be_adapter *adapter)
34645diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34646index 16b0704..d2c07d7 100644
34647--- a/drivers/net/ethernet/faraday/ftgmac100.c
34648+++ b/drivers/net/ethernet/faraday/ftgmac100.c
34649@@ -31,6 +31,8 @@
34650 #include <linux/netdevice.h>
34651 #include <linux/phy.h>
34652 #include <linux/platform_device.h>
34653+#include <linux/interrupt.h>
34654+#include <linux/irqreturn.h>
34655 #include <net/ip.h>
34656
34657 #include "ftgmac100.h"
34658diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34659index 829b109..4ae5f6a 100644
34660--- a/drivers/net/ethernet/faraday/ftmac100.c
34661+++ b/drivers/net/ethernet/faraday/ftmac100.c
34662@@ -31,6 +31,8 @@
34663 #include <linux/module.h>
34664 #include <linux/netdevice.h>
34665 #include <linux/platform_device.h>
34666+#include <linux/interrupt.h>
34667+#include <linux/irqreturn.h>
34668
34669 #include "ftmac100.h"
34670
34671diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34672index 9d71c9c..0e4a0ac 100644
34673--- a/drivers/net/ethernet/fealnx.c
34674+++ b/drivers/net/ethernet/fealnx.c
34675@@ -150,7 +150,7 @@ struct chip_info {
34676 int flags;
34677 };
34678
34679-static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
34680+static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
34681 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34682 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
34683 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34684diff --git a/drivers/net/ethernet/intel/e1000e/e1000.h b/drivers/net/ethernet/intel/e1000e/e1000.h
34685index 6e6fffb..588f361 100644
34686--- a/drivers/net/ethernet/intel/e1000e/e1000.h
34687+++ b/drivers/net/ethernet/intel/e1000e/e1000.h
34688@@ -181,7 +181,7 @@ struct e1000_info;
34689 #define E1000_TXDCTL_DMA_BURST_ENABLE \
34690 (E1000_TXDCTL_GRAN | /* set descriptor granularity */ \
34691 E1000_TXDCTL_COUNT_DESC | \
34692- (5 << 16) | /* wthresh must be +1 more than desired */\
34693+ (1 << 16) | /* wthresh must be +1 more than desired */\
34694 (1 << 8) | /* hthresh */ \
34695 0x1f) /* pthresh */
34696
34697diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34698index ed5b409..ec37828 100644
34699--- a/drivers/net/ethernet/intel/e1000e/hw.h
34700+++ b/drivers/net/ethernet/intel/e1000e/hw.h
34701@@ -797,6 +797,7 @@ struct e1000_mac_operations {
34702 void (*rar_set)(struct e1000_hw *, u8 *, u32);
34703 s32 (*read_mac_addr)(struct e1000_hw *);
34704 };
34705+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34706
34707 /*
34708 * When to use various PHY register access functions:
34709@@ -837,6 +838,7 @@ struct e1000_phy_operations {
34710 void (*power_up)(struct e1000_hw *);
34711 void (*power_down)(struct e1000_hw *);
34712 };
34713+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34714
34715 /* Function pointers for the NVM. */
34716 struct e1000_nvm_operations {
34717@@ -849,9 +851,10 @@ struct e1000_nvm_operations {
34718 s32 (*validate)(struct e1000_hw *);
34719 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34720 };
34721+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34722
34723 struct e1000_mac_info {
34724- struct e1000_mac_operations ops;
34725+ e1000_mac_operations_no_const ops;
34726 u8 addr[ETH_ALEN];
34727 u8 perm_addr[ETH_ALEN];
34728
34729@@ -892,7 +895,7 @@ struct e1000_mac_info {
34730 };
34731
34732 struct e1000_phy_info {
34733- struct e1000_phy_operations ops;
34734+ e1000_phy_operations_no_const ops;
34735
34736 enum e1000_phy_type type;
34737
34738@@ -926,7 +929,7 @@ struct e1000_phy_info {
34739 };
34740
34741 struct e1000_nvm_info {
34742- struct e1000_nvm_operations ops;
34743+ e1000_nvm_operations_no_const ops;
34744
34745 enum e1000_nvm_type type;
34746 enum e1000_nvm_override override;
34747diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
34748index c2a51dc..c2bd262 100644
34749--- a/drivers/net/ethernet/intel/igb/e1000_hw.h
34750+++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
34751@@ -327,6 +327,7 @@ struct e1000_mac_operations {
34752 void (*release_swfw_sync)(struct e1000_hw *, u16);
34753
34754 };
34755+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34756
34757 struct e1000_phy_operations {
34758 s32 (*acquire)(struct e1000_hw *);
34759@@ -343,6 +344,7 @@ struct e1000_phy_operations {
34760 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
34761 s32 (*write_reg)(struct e1000_hw *, u32, u16);
34762 };
34763+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34764
34765 struct e1000_nvm_operations {
34766 s32 (*acquire)(struct e1000_hw *);
34767@@ -353,6 +355,7 @@ struct e1000_nvm_operations {
34768 s32 (*validate)(struct e1000_hw *);
34769 s32 (*valid_led_default)(struct e1000_hw *, u16 *);
34770 };
34771+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34772
34773 struct e1000_info {
34774 s32 (*get_invariants)(struct e1000_hw *);
34775@@ -364,7 +367,7 @@ struct e1000_info {
34776 extern const struct e1000_info e1000_82575_info;
34777
34778 struct e1000_mac_info {
34779- struct e1000_mac_operations ops;
34780+ e1000_mac_operations_no_const ops;
34781
34782 u8 addr[6];
34783 u8 perm_addr[6];
34784@@ -402,7 +405,7 @@ struct e1000_mac_info {
34785 };
34786
34787 struct e1000_phy_info {
34788- struct e1000_phy_operations ops;
34789+ e1000_phy_operations_no_const ops;
34790
34791 enum e1000_phy_type type;
34792
34793@@ -437,7 +440,7 @@ struct e1000_phy_info {
34794 };
34795
34796 struct e1000_nvm_info {
34797- struct e1000_nvm_operations ops;
34798+ e1000_nvm_operations_no_const ops;
34799 enum e1000_nvm_type type;
34800 enum e1000_nvm_override override;
34801
34802@@ -482,6 +485,7 @@ struct e1000_mbx_operations {
34803 s32 (*check_for_ack)(struct e1000_hw *, u16);
34804 s32 (*check_for_rst)(struct e1000_hw *, u16);
34805 };
34806+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34807
34808 struct e1000_mbx_stats {
34809 u32 msgs_tx;
34810@@ -493,7 +497,7 @@ struct e1000_mbx_stats {
34811 };
34812
34813 struct e1000_mbx_info {
34814- struct e1000_mbx_operations ops;
34815+ e1000_mbx_operations_no_const ops;
34816 struct e1000_mbx_stats stats;
34817 u32 timeout;
34818 u32 usec_delay;
34819diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
34820index 57db3c6..aa825fc 100644
34821--- a/drivers/net/ethernet/intel/igbvf/vf.h
34822+++ b/drivers/net/ethernet/intel/igbvf/vf.h
34823@@ -189,9 +189,10 @@ struct e1000_mac_operations {
34824 s32 (*read_mac_addr)(struct e1000_hw *);
34825 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
34826 };
34827+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34828
34829 struct e1000_mac_info {
34830- struct e1000_mac_operations ops;
34831+ e1000_mac_operations_no_const ops;
34832 u8 addr[6];
34833 u8 perm_addr[6];
34834
34835@@ -213,6 +214,7 @@ struct e1000_mbx_operations {
34836 s32 (*check_for_ack)(struct e1000_hw *);
34837 s32 (*check_for_rst)(struct e1000_hw *);
34838 };
34839+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34840
34841 struct e1000_mbx_stats {
34842 u32 msgs_tx;
34843@@ -224,7 +226,7 @@ struct e1000_mbx_stats {
34844 };
34845
34846 struct e1000_mbx_info {
34847- struct e1000_mbx_operations ops;
34848+ e1000_mbx_operations_no_const ops;
34849 struct e1000_mbx_stats stats;
34850 u32 timeout;
34851 u32 usec_delay;
34852diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34853index dcebd12..c1fe8be 100644
34854--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34855+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34856@@ -805,7 +805,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
34857 /* store the new cycle speed */
34858 adapter->cycle_speed = cycle_speed;
34859
34860- ACCESS_ONCE(adapter->base_incval) = incval;
34861+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
34862 smp_mb();
34863
34864 /* grab the ptp lock */
34865diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34866index 204848d..d8aeaec 100644
34867--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34868+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34869@@ -2791,6 +2791,7 @@ struct ixgbe_eeprom_operations {
34870 s32 (*update_checksum)(struct ixgbe_hw *);
34871 u16 (*calc_checksum)(struct ixgbe_hw *);
34872 };
34873+typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
34874
34875 struct ixgbe_mac_operations {
34876 s32 (*init_hw)(struct ixgbe_hw *);
34877@@ -2856,6 +2857,7 @@ struct ixgbe_mac_operations {
34878 s32 (*get_thermal_sensor_data)(struct ixgbe_hw *);
34879 s32 (*init_thermal_sensor_thresh)(struct ixgbe_hw *hw);
34880 };
34881+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34882
34883 struct ixgbe_phy_operations {
34884 s32 (*identify)(struct ixgbe_hw *);
34885@@ -2875,9 +2877,10 @@ struct ixgbe_phy_operations {
34886 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
34887 s32 (*check_overtemp)(struct ixgbe_hw *);
34888 };
34889+typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
34890
34891 struct ixgbe_eeprom_info {
34892- struct ixgbe_eeprom_operations ops;
34893+ ixgbe_eeprom_operations_no_const ops;
34894 enum ixgbe_eeprom_type type;
34895 u32 semaphore_delay;
34896 u16 word_size;
34897@@ -2887,7 +2890,7 @@ struct ixgbe_eeprom_info {
34898
34899 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
34900 struct ixgbe_mac_info {
34901- struct ixgbe_mac_operations ops;
34902+ ixgbe_mac_operations_no_const ops;
34903 enum ixgbe_mac_type type;
34904 u8 addr[ETH_ALEN];
34905 u8 perm_addr[ETH_ALEN];
34906@@ -2916,7 +2919,7 @@ struct ixgbe_mac_info {
34907 };
34908
34909 struct ixgbe_phy_info {
34910- struct ixgbe_phy_operations ops;
34911+ ixgbe_phy_operations_no_const ops;
34912 struct mdio_if_info mdio;
34913 enum ixgbe_phy_type type;
34914 u32 id;
34915@@ -2944,6 +2947,7 @@ struct ixgbe_mbx_operations {
34916 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
34917 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
34918 };
34919+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34920
34921 struct ixgbe_mbx_stats {
34922 u32 msgs_tx;
34923@@ -2955,7 +2959,7 @@ struct ixgbe_mbx_stats {
34924 };
34925
34926 struct ixgbe_mbx_info {
34927- struct ixgbe_mbx_operations ops;
34928+ ixgbe_mbx_operations_no_const ops;
34929 struct ixgbe_mbx_stats stats;
34930 u32 timeout;
34931 u32 usec_delay;
34932diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
34933index 25c951d..cc7cf33 100644
34934--- a/drivers/net/ethernet/intel/ixgbevf/vf.h
34935+++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
34936@@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
34937 s32 (*clear_vfta)(struct ixgbe_hw *);
34938 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
34939 };
34940+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34941
34942 enum ixgbe_mac_type {
34943 ixgbe_mac_unknown = 0,
34944@@ -79,7 +80,7 @@ enum ixgbe_mac_type {
34945 };
34946
34947 struct ixgbe_mac_info {
34948- struct ixgbe_mac_operations ops;
34949+ ixgbe_mac_operations_no_const ops;
34950 u8 addr[6];
34951 u8 perm_addr[6];
34952
34953@@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
34954 s32 (*check_for_ack)(struct ixgbe_hw *);
34955 s32 (*check_for_rst)(struct ixgbe_hw *);
34956 };
34957+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34958
34959 struct ixgbe_mbx_stats {
34960 u32 msgs_tx;
34961@@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
34962 };
34963
34964 struct ixgbe_mbx_info {
34965- struct ixgbe_mbx_operations ops;
34966+ ixgbe_mbx_operations_no_const ops;
34967 struct ixgbe_mbx_stats stats;
34968 u32 timeout;
34969 u32 udelay;
34970diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
34971index a0313de..e83a572 100644
34972--- a/drivers/net/ethernet/mellanox/mlx4/main.c
34973+++ b/drivers/net/ethernet/mellanox/mlx4/main.c
34974@@ -41,6 +41,7 @@
34975 #include <linux/slab.h>
34976 #include <linux/io-mapping.h>
34977 #include <linux/delay.h>
34978+#include <linux/sched.h>
34979
34980 #include <linux/mlx4/device.h>
34981 #include <linux/mlx4/doorbell.h>
34982diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
34983index 5046a64..71ca936 100644
34984--- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
34985+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
34986@@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
34987 void (*link_down)(struct __vxge_hw_device *devh);
34988 void (*crit_err)(struct __vxge_hw_device *devh,
34989 enum vxge_hw_event type, u64 ext_data);
34990-};
34991+} __no_const;
34992
34993 /*
34994 * struct __vxge_hw_blockpool_entry - Block private data structure
34995diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34996index 4a518a3..936b334 100644
34997--- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34998+++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
34999@@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35000 struct vxge_hw_mempool_dma *dma_object,
35001 u32 index,
35002 u32 is_last);
35003-};
35004+} __no_const;
35005
35006 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35007 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35008diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35009index eb81da4..1592b62 100644
35010--- a/drivers/net/ethernet/realtek/r8169.c
35011+++ b/drivers/net/ethernet/realtek/r8169.c
35012@@ -723,22 +723,22 @@ struct rtl8169_private {
35013 struct mdio_ops {
35014 void (*write)(void __iomem *, int, int);
35015 int (*read)(void __iomem *, int);
35016- } mdio_ops;
35017+ } __no_const mdio_ops;
35018
35019 struct pll_power_ops {
35020 void (*down)(struct rtl8169_private *);
35021 void (*up)(struct rtl8169_private *);
35022- } pll_power_ops;
35023+ } __no_const pll_power_ops;
35024
35025 struct jumbo_ops {
35026 void (*enable)(struct rtl8169_private *);
35027 void (*disable)(struct rtl8169_private *);
35028- } jumbo_ops;
35029+ } __no_const jumbo_ops;
35030
35031 struct csi_ops {
35032 void (*write)(void __iomem *, int, int);
35033 u32 (*read)(void __iomem *, int);
35034- } csi_ops;
35035+ } __no_const csi_ops;
35036
35037 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35038 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35039diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35040index 4613591..d816601 100644
35041--- a/drivers/net/ethernet/sis/sis190.c
35042+++ b/drivers/net/ethernet/sis/sis190.c
35043@@ -1618,7 +1618,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35044 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35045 struct net_device *dev)
35046 {
35047- static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35048+ static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35049 struct sis190_private *tp = netdev_priv(dev);
35050 struct pci_dev *isa_bridge;
35051 u8 reg, tmp8;
35052diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35053index c07cfe9..81cbf7e 100644
35054--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35055+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35056@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35057
35058 writel(value, ioaddr + MMC_CNTRL);
35059
35060- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35061- MMC_CNTRL, value);
35062+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35063+// MMC_CNTRL, value);
35064 }
35065
35066 /* To mask all all interrupts.*/
35067diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35068index 2857ab0..9a1f9b0 100644
35069--- a/drivers/net/hyperv/hyperv_net.h
35070+++ b/drivers/net/hyperv/hyperv_net.h
35071@@ -99,7 +99,7 @@ struct rndis_device {
35072
35073 enum rndis_device_state state;
35074 bool link_state;
35075- atomic_t new_req_id;
35076+ atomic_unchecked_t new_req_id;
35077
35078 spinlock_t request_lock;
35079 struct list_head req_list;
35080diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35081index 981ebb1..b34959b 100644
35082--- a/drivers/net/hyperv/rndis_filter.c
35083+++ b/drivers/net/hyperv/rndis_filter.c
35084@@ -97,7 +97,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35085 * template
35086 */
35087 set = &rndis_msg->msg.set_req;
35088- set->req_id = atomic_inc_return(&dev->new_req_id);
35089+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35090
35091 /* Add to the request list */
35092 spin_lock_irqsave(&dev->request_lock, flags);
35093@@ -648,7 +648,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35094
35095 /* Setup the rndis set */
35096 halt = &request->request_msg.msg.halt_req;
35097- halt->req_id = atomic_inc_return(&dev->new_req_id);
35098+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35099
35100 /* Ignore return since this msg is optional. */
35101 rndis_filter_send_request(dev, request);
35102diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35103index 5c05572..389610b 100644
35104--- a/drivers/net/ppp/ppp_generic.c
35105+++ b/drivers/net/ppp/ppp_generic.c
35106@@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35107 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35108 struct ppp_stats stats;
35109 struct ppp_comp_stats cstats;
35110- char *vers;
35111
35112 switch (cmd) {
35113 case SIOCGPPPSTATS:
35114@@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35115 break;
35116
35117 case SIOCGPPPVER:
35118- vers = PPP_VERSION;
35119- if (copy_to_user(addr, vers, strlen(vers) + 1))
35120+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35121 break;
35122 err = 0;
35123 break;
35124diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35125index 62f30b4..ff99dfd 100644
35126--- a/drivers/net/usb/hso.c
35127+++ b/drivers/net/usb/hso.c
35128@@ -71,7 +71,7 @@
35129 #include <asm/byteorder.h>
35130 #include <linux/serial_core.h>
35131 #include <linux/serial.h>
35132-
35133+#include <asm/local.h>
35134
35135 #define MOD_AUTHOR "Option Wireless"
35136 #define MOD_DESCRIPTION "USB High Speed Option driver"
35137@@ -1182,7 +1182,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35138 struct urb *urb;
35139
35140 urb = serial->rx_urb[0];
35141- if (serial->port.count > 0) {
35142+ if (atomic_read(&serial->port.count) > 0) {
35143 count = put_rxbuf_data(urb, serial);
35144 if (count == -1)
35145 return;
35146@@ -1218,7 +1218,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35147 DUMP1(urb->transfer_buffer, urb->actual_length);
35148
35149 /* Anyone listening? */
35150- if (serial->port.count == 0)
35151+ if (atomic_read(&serial->port.count) == 0)
35152 return;
35153
35154 if (status == 0) {
35155@@ -1300,8 +1300,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35156 tty_port_tty_set(&serial->port, tty);
35157
35158 /* check for port already opened, if not set the termios */
35159- serial->port.count++;
35160- if (serial->port.count == 1) {
35161+ if (atomic_inc_return(&serial->port.count) == 1) {
35162 serial->rx_state = RX_IDLE;
35163 /* Force default termio settings */
35164 _hso_serial_set_termios(tty, NULL);
35165@@ -1313,7 +1312,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35166 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35167 if (result) {
35168 hso_stop_serial_device(serial->parent);
35169- serial->port.count--;
35170+ atomic_dec(&serial->port.count);
35171 kref_put(&serial->parent->ref, hso_serial_ref_free);
35172 }
35173 } else {
35174@@ -1350,10 +1349,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35175
35176 /* reset the rts and dtr */
35177 /* do the actual close */
35178- serial->port.count--;
35179+ atomic_dec(&serial->port.count);
35180
35181- if (serial->port.count <= 0) {
35182- serial->port.count = 0;
35183+ if (atomic_read(&serial->port.count) <= 0) {
35184+ atomic_set(&serial->port.count, 0);
35185 tty_port_tty_set(&serial->port, NULL);
35186 if (!usb_gone)
35187 hso_stop_serial_device(serial->parent);
35188@@ -1429,7 +1428,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35189
35190 /* the actual setup */
35191 spin_lock_irqsave(&serial->serial_lock, flags);
35192- if (serial->port.count)
35193+ if (atomic_read(&serial->port.count))
35194 _hso_serial_set_termios(tty, old);
35195 else
35196 tty->termios = old;
35197@@ -1888,7 +1887,7 @@ static void intr_callback(struct urb *urb)
35198 D1("Pending read interrupt on port %d\n", i);
35199 spin_lock(&serial->serial_lock);
35200 if (serial->rx_state == RX_IDLE &&
35201- serial->port.count > 0) {
35202+ atomic_read(&serial->port.count) > 0) {
35203 /* Setup and send a ctrl req read on
35204 * port i */
35205 if (!serial->rx_urb_filled[0]) {
35206@@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
35207 /* Start all serial ports */
35208 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35209 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35210- if (dev2ser(serial_table[i])->port.count) {
35211+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
35212 result =
35213 hso_start_serial_device(serial_table[i], GFP_NOIO);
35214 hso_kick_transmit(dev2ser(serial_table[i]));
35215diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35216index 420d69b..74f90a2 100644
35217--- a/drivers/net/wireless/ath/ath.h
35218+++ b/drivers/net/wireless/ath/ath.h
35219@@ -119,6 +119,7 @@ struct ath_ops {
35220 void (*write_flush) (void *);
35221 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35222 };
35223+typedef struct ath_ops __no_const ath_ops_no_const;
35224
35225 struct ath_common;
35226 struct ath_bus_ops;
35227diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35228index 8d78253..bebbb68 100644
35229--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35230+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35231@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35232 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35233 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35234
35235- ACCESS_ONCE(ads->ds_link) = i->link;
35236- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35237+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
35238+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35239
35240 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35241 ctl6 = SM(i->keytype, AR_EncrType);
35242@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35243
35244 if ((i->is_first || i->is_last) &&
35245 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35246- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35247+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35248 | set11nTries(i->rates, 1)
35249 | set11nTries(i->rates, 2)
35250 | set11nTries(i->rates, 3)
35251 | (i->dur_update ? AR_DurUpdateEna : 0)
35252 | SM(0, AR_BurstDur);
35253
35254- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35255+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35256 | set11nRate(i->rates, 1)
35257 | set11nRate(i->rates, 2)
35258 | set11nRate(i->rates, 3);
35259 } else {
35260- ACCESS_ONCE(ads->ds_ctl2) = 0;
35261- ACCESS_ONCE(ads->ds_ctl3) = 0;
35262+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35263+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35264 }
35265
35266 if (!i->is_first) {
35267- ACCESS_ONCE(ads->ds_ctl0) = 0;
35268- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35269- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35270+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35271+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35272+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35273 return;
35274 }
35275
35276@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35277 break;
35278 }
35279
35280- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35281+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35282 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35283 | SM(i->txpower, AR_XmitPower)
35284 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35285@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35286 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35287 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35288
35289- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35290- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35291+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35292+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35293
35294 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35295 return;
35296
35297- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35298+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35299 | set11nPktDurRTSCTS(i->rates, 1);
35300
35301- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35302+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35303 | set11nPktDurRTSCTS(i->rates, 3);
35304
35305- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35306+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35307 | set11nRateFlags(i->rates, 1)
35308 | set11nRateFlags(i->rates, 2)
35309 | set11nRateFlags(i->rates, 3)
35310diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35311index d9e0824..1a874e7 100644
35312--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35313+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35314@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35315 (i->qcu << AR_TxQcuNum_S) | desc_len;
35316
35317 checksum += val;
35318- ACCESS_ONCE(ads->info) = val;
35319+ ACCESS_ONCE_RW(ads->info) = val;
35320
35321 checksum += i->link;
35322- ACCESS_ONCE(ads->link) = i->link;
35323+ ACCESS_ONCE_RW(ads->link) = i->link;
35324
35325 checksum += i->buf_addr[0];
35326- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35327+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35328 checksum += i->buf_addr[1];
35329- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35330+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35331 checksum += i->buf_addr[2];
35332- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35333+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35334 checksum += i->buf_addr[3];
35335- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35336+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35337
35338 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35339- ACCESS_ONCE(ads->ctl3) = val;
35340+ ACCESS_ONCE_RW(ads->ctl3) = val;
35341 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35342- ACCESS_ONCE(ads->ctl5) = val;
35343+ ACCESS_ONCE_RW(ads->ctl5) = val;
35344 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35345- ACCESS_ONCE(ads->ctl7) = val;
35346+ ACCESS_ONCE_RW(ads->ctl7) = val;
35347 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35348- ACCESS_ONCE(ads->ctl9) = val;
35349+ ACCESS_ONCE_RW(ads->ctl9) = val;
35350
35351 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35352- ACCESS_ONCE(ads->ctl10) = checksum;
35353+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
35354
35355 if (i->is_first || i->is_last) {
35356- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35357+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35358 | set11nTries(i->rates, 1)
35359 | set11nTries(i->rates, 2)
35360 | set11nTries(i->rates, 3)
35361 | (i->dur_update ? AR_DurUpdateEna : 0)
35362 | SM(0, AR_BurstDur);
35363
35364- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35365+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35366 | set11nRate(i->rates, 1)
35367 | set11nRate(i->rates, 2)
35368 | set11nRate(i->rates, 3);
35369 } else {
35370- ACCESS_ONCE(ads->ctl13) = 0;
35371- ACCESS_ONCE(ads->ctl14) = 0;
35372+ ACCESS_ONCE_RW(ads->ctl13) = 0;
35373+ ACCESS_ONCE_RW(ads->ctl14) = 0;
35374 }
35375
35376 ads->ctl20 = 0;
35377@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35378
35379 ctl17 = SM(i->keytype, AR_EncrType);
35380 if (!i->is_first) {
35381- ACCESS_ONCE(ads->ctl11) = 0;
35382- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35383- ACCESS_ONCE(ads->ctl15) = 0;
35384- ACCESS_ONCE(ads->ctl16) = 0;
35385- ACCESS_ONCE(ads->ctl17) = ctl17;
35386- ACCESS_ONCE(ads->ctl18) = 0;
35387- ACCESS_ONCE(ads->ctl19) = 0;
35388+ ACCESS_ONCE_RW(ads->ctl11) = 0;
35389+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35390+ ACCESS_ONCE_RW(ads->ctl15) = 0;
35391+ ACCESS_ONCE_RW(ads->ctl16) = 0;
35392+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35393+ ACCESS_ONCE_RW(ads->ctl18) = 0;
35394+ ACCESS_ONCE_RW(ads->ctl19) = 0;
35395 return;
35396 }
35397
35398- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35399+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35400 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35401 | SM(i->txpower, AR_XmitPower)
35402 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35403@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35404 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35405 ctl12 |= SM(val, AR_PAPRDChainMask);
35406
35407- ACCESS_ONCE(ads->ctl12) = ctl12;
35408- ACCESS_ONCE(ads->ctl17) = ctl17;
35409+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35410+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35411
35412- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35413+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35414 | set11nPktDurRTSCTS(i->rates, 1);
35415
35416- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35417+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35418 | set11nPktDurRTSCTS(i->rates, 3);
35419
35420- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35421+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35422 | set11nRateFlags(i->rates, 1)
35423 | set11nRateFlags(i->rates, 2)
35424 | set11nRateFlags(i->rates, 3)
35425 | SM(i->rtscts_rate, AR_RTSCTSRate);
35426
35427- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35428+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35429 }
35430
35431 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35432diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35433index 02f5007..bd0bd8f 100644
35434--- a/drivers/net/wireless/ath/ath9k/hw.h
35435+++ b/drivers/net/wireless/ath/ath9k/hw.h
35436@@ -610,7 +610,7 @@ struct ath_hw_private_ops {
35437
35438 /* ANI */
35439 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35440-};
35441+} __no_const;
35442
35443 /**
35444 * struct ath_hw_ops - callbacks used by hardware code and driver code
35445@@ -640,7 +640,7 @@ struct ath_hw_ops {
35446 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35447 struct ath_hw_antcomb_conf *antconf);
35448
35449-};
35450+} __no_const;
35451
35452 struct ath_nf_limits {
35453 s16 max;
35454@@ -660,7 +660,7 @@ enum ath_cal_list {
35455 #define AH_FASTCC 0x4
35456
35457 struct ath_hw {
35458- struct ath_ops reg_ops;
35459+ ath_ops_no_const reg_ops;
35460
35461 struct ieee80211_hw *hw;
35462 struct ath_common common;
35463diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35464index af00e2c..ab04d34 100644
35465--- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35466+++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35467@@ -545,7 +545,7 @@ struct phy_func_ptr {
35468 void (*carrsuppr)(struct brcms_phy *);
35469 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35470 void (*detach)(struct brcms_phy *);
35471-};
35472+} __no_const;
35473
35474 struct brcms_phy {
35475 struct brcms_phy_pub pubpi_ro;
35476diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35477index faec404..a5277f1 100644
35478--- a/drivers/net/wireless/iwlegacy/3945-mac.c
35479+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35480@@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35481 */
35482 if (il3945_mod_params.disable_hw_scan) {
35483 D_INFO("Disabling hw_scan\n");
35484- il3945_mac_ops.hw_scan = NULL;
35485+ pax_open_kernel();
35486+ *(void **)&il3945_mac_ops.hw_scan = NULL;
35487+ pax_close_kernel();
35488 }
35489
35490 D_INFO("*** LOAD DRIVER ***\n");
35491diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35492index a0b7cfd..20b49f7 100644
35493--- a/drivers/net/wireless/mac80211_hwsim.c
35494+++ b/drivers/net/wireless/mac80211_hwsim.c
35495@@ -1752,9 +1752,11 @@ static int __init init_mac80211_hwsim(void)
35496 return -EINVAL;
35497
35498 if (fake_hw_scan) {
35499- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35500- mac80211_hwsim_ops.sw_scan_start = NULL;
35501- mac80211_hwsim_ops.sw_scan_complete = NULL;
35502+ pax_open_kernel();
35503+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35504+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35505+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35506+ pax_close_kernel();
35507 }
35508
35509 spin_lock_init(&hwsim_radio_lock);
35510diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35511index bd3b0bf..f9db92a 100644
35512--- a/drivers/net/wireless/mwifiex/main.h
35513+++ b/drivers/net/wireless/mwifiex/main.h
35514@@ -567,7 +567,7 @@ struct mwifiex_if_ops {
35515 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35516 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
35517 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
35518-};
35519+} __no_const;
35520
35521 struct mwifiex_adapter {
35522 u8 iface_type;
35523diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35524index dfcd02a..a42a59d 100644
35525--- a/drivers/net/wireless/rndis_wlan.c
35526+++ b/drivers/net/wireless/rndis_wlan.c
35527@@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35528
35529 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35530
35531- if (rts_threshold < 0 || rts_threshold > 2347)
35532+ if (rts_threshold > 2347)
35533 rts_threshold = 2347;
35534
35535 tmp = cpu_to_le32(rts_threshold);
35536diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
35537index 8f75402..eed109d 100644
35538--- a/drivers/net/wireless/rt2x00/rt2x00.h
35539+++ b/drivers/net/wireless/rt2x00/rt2x00.h
35540@@ -396,7 +396,7 @@ struct rt2x00_intf {
35541 * for hardware which doesn't support hardware
35542 * sequence counting.
35543 */
35544- atomic_t seqno;
35545+ atomic_unchecked_t seqno;
35546 };
35547
35548 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
35549diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
35550index 2fd8301..9767e8c 100644
35551--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
35552+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
35553@@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
35554 * sequence counter given by mac80211.
35555 */
35556 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
35557- seqno = atomic_add_return(0x10, &intf->seqno);
35558+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
35559 else
35560- seqno = atomic_read(&intf->seqno);
35561+ seqno = atomic_read_unchecked(&intf->seqno);
35562
35563 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
35564 hdr->seq_ctrl |= cpu_to_le16(seqno);
35565diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
35566index 9d8f581..0f6589e 100644
35567--- a/drivers/net/wireless/ti/wl1251/wl1251.h
35568+++ b/drivers/net/wireless/ti/wl1251/wl1251.h
35569@@ -266,7 +266,7 @@ struct wl1251_if_operations {
35570 void (*reset)(struct wl1251 *wl);
35571 void (*enable_irq)(struct wl1251 *wl);
35572 void (*disable_irq)(struct wl1251 *wl);
35573-};
35574+} __no_const;
35575
35576 struct wl1251 {
35577 struct ieee80211_hw *hw;
35578diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
35579index 0b3f0b5..62f68bd 100644
35580--- a/drivers/net/wireless/ti/wlcore/wlcore.h
35581+++ b/drivers/net/wireless/ti/wlcore/wlcore.h
35582@@ -61,7 +61,7 @@ struct wlcore_ops {
35583 struct wl12xx_vif *wlvif);
35584 s8 (*get_pg_ver)(struct wl1271 *wl);
35585 void (*get_mac)(struct wl1271 *wl);
35586-};
35587+} __no_const;
35588
35589 enum wlcore_partitions {
35590 PART_DOWN,
35591diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
35592index f34b5b2..b5abb9f 100644
35593--- a/drivers/oprofile/buffer_sync.c
35594+++ b/drivers/oprofile/buffer_sync.c
35595@@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
35596 if (cookie == NO_COOKIE)
35597 offset = pc;
35598 if (cookie == INVALID_COOKIE) {
35599- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35600+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35601 offset = pc;
35602 }
35603 if (cookie != last_cookie) {
35604@@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
35605 /* add userspace sample */
35606
35607 if (!mm) {
35608- atomic_inc(&oprofile_stats.sample_lost_no_mm);
35609+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
35610 return 0;
35611 }
35612
35613 cookie = lookup_dcookie(mm, s->eip, &offset);
35614
35615 if (cookie == INVALID_COOKIE) {
35616- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35617+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35618 return 0;
35619 }
35620
35621@@ -563,7 +563,7 @@ void sync_buffer(int cpu)
35622 /* ignore backtraces if failed to add a sample */
35623 if (state == sb_bt_start) {
35624 state = sb_bt_ignore;
35625- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
35626+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
35627 }
35628 }
35629 release_mm(mm);
35630diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
35631index c0cc4e7..44d4e54 100644
35632--- a/drivers/oprofile/event_buffer.c
35633+++ b/drivers/oprofile/event_buffer.c
35634@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
35635 }
35636
35637 if (buffer_pos == buffer_size) {
35638- atomic_inc(&oprofile_stats.event_lost_overflow);
35639+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
35640 return;
35641 }
35642
35643diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
35644index ed2c3ec..deda85a 100644
35645--- a/drivers/oprofile/oprof.c
35646+++ b/drivers/oprofile/oprof.c
35647@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
35648 if (oprofile_ops.switch_events())
35649 return;
35650
35651- atomic_inc(&oprofile_stats.multiplex_counter);
35652+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
35653 start_switch_worker();
35654 }
35655
35656diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
35657index 917d28e..d62d981 100644
35658--- a/drivers/oprofile/oprofile_stats.c
35659+++ b/drivers/oprofile/oprofile_stats.c
35660@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
35661 cpu_buf->sample_invalid_eip = 0;
35662 }
35663
35664- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
35665- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
35666- atomic_set(&oprofile_stats.event_lost_overflow, 0);
35667- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
35668- atomic_set(&oprofile_stats.multiplex_counter, 0);
35669+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
35670+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
35671+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
35672+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
35673+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
35674 }
35675
35676
35677diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
35678index 38b6fc0..b5cbfce 100644
35679--- a/drivers/oprofile/oprofile_stats.h
35680+++ b/drivers/oprofile/oprofile_stats.h
35681@@ -13,11 +13,11 @@
35682 #include <linux/atomic.h>
35683
35684 struct oprofile_stat_struct {
35685- atomic_t sample_lost_no_mm;
35686- atomic_t sample_lost_no_mapping;
35687- atomic_t bt_lost_no_mapping;
35688- atomic_t event_lost_overflow;
35689- atomic_t multiplex_counter;
35690+ atomic_unchecked_t sample_lost_no_mm;
35691+ atomic_unchecked_t sample_lost_no_mapping;
35692+ atomic_unchecked_t bt_lost_no_mapping;
35693+ atomic_unchecked_t event_lost_overflow;
35694+ atomic_unchecked_t multiplex_counter;
35695 };
35696
35697 extern struct oprofile_stat_struct oprofile_stats;
35698diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
35699index 849357c..b83c1e0 100644
35700--- a/drivers/oprofile/oprofilefs.c
35701+++ b/drivers/oprofile/oprofilefs.c
35702@@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
35703
35704
35705 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
35706- char const *name, atomic_t *val)
35707+ char const *name, atomic_unchecked_t *val)
35708 {
35709 return __oprofilefs_create_file(sb, root, name,
35710 &atomic_ro_fops, 0444, val);
35711diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
35712index 3f56bc0..707d642 100644
35713--- a/drivers/parport/procfs.c
35714+++ b/drivers/parport/procfs.c
35715@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
35716
35717 *ppos += len;
35718
35719- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
35720+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
35721 }
35722
35723 #ifdef CONFIG_PARPORT_1284
35724@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
35725
35726 *ppos += len;
35727
35728- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
35729+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
35730 }
35731 #endif /* IEEE1284.3 support. */
35732
35733diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
35734index 9fff878..ad0ad53 100644
35735--- a/drivers/pci/hotplug/cpci_hotplug.h
35736+++ b/drivers/pci/hotplug/cpci_hotplug.h
35737@@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
35738 int (*hardware_test) (struct slot* slot, u32 value);
35739 u8 (*get_power) (struct slot* slot);
35740 int (*set_power) (struct slot* slot, int value);
35741-};
35742+} __no_const;
35743
35744 struct cpci_hp_controller {
35745 unsigned int irq;
35746diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
35747index 76ba8a1..20ca857 100644
35748--- a/drivers/pci/hotplug/cpqphp_nvram.c
35749+++ b/drivers/pci/hotplug/cpqphp_nvram.c
35750@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
35751
35752 void compaq_nvram_init (void __iomem *rom_start)
35753 {
35754+
35755+#ifndef CONFIG_PAX_KERNEXEC
35756 if (rom_start) {
35757 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
35758 }
35759+#endif
35760+
35761 dbg("int15 entry = %p\n", compaq_int15_entry_point);
35762
35763 /* initialize our int15 lock */
35764diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
35765index b500840..d7159d3 100644
35766--- a/drivers/pci/pcie/aspm.c
35767+++ b/drivers/pci/pcie/aspm.c
35768@@ -27,9 +27,9 @@
35769 #define MODULE_PARAM_PREFIX "pcie_aspm."
35770
35771 /* Note: those are not register definitions */
35772-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
35773-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
35774-#define ASPM_STATE_L1 (4) /* L1 state */
35775+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
35776+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
35777+#define ASPM_STATE_L1 (4U) /* L1 state */
35778 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
35779 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
35780
35781diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
35782index 658ac97..05e1b90 100644
35783--- a/drivers/pci/probe.c
35784+++ b/drivers/pci/probe.c
35785@@ -137,7 +137,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
35786 u16 orig_cmd;
35787 struct pci_bus_region region;
35788
35789- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
35790+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
35791
35792 if (!dev->mmio_always_on) {
35793 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
35794diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
35795index 27911b5..5b6db88 100644
35796--- a/drivers/pci/proc.c
35797+++ b/drivers/pci/proc.c
35798@@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
35799 static int __init pci_proc_init(void)
35800 {
35801 struct pci_dev *dev = NULL;
35802+
35803+#ifdef CONFIG_GRKERNSEC_PROC_ADD
35804+#ifdef CONFIG_GRKERNSEC_PROC_USER
35805+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
35806+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
35807+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
35808+#endif
35809+#else
35810 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
35811+#endif
35812 proc_create("devices", 0, proc_bus_pci_dir,
35813 &proc_bus_pci_dev_operations);
35814 proc_initialized = 1;
35815diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
35816index 8b5610d..a4c22bb 100644
35817--- a/drivers/platform/x86/thinkpad_acpi.c
35818+++ b/drivers/platform/x86/thinkpad_acpi.c
35819@@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
35820 return 0;
35821 }
35822
35823-void static hotkey_mask_warn_incomplete_mask(void)
35824+static void hotkey_mask_warn_incomplete_mask(void)
35825 {
35826 /* log only what the user can fix... */
35827 const u32 wantedmask = hotkey_driver_mask &
35828@@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
35829 }
35830 }
35831
35832-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35833- struct tp_nvram_state *newn,
35834- const u32 event_mask)
35835-{
35836-
35837 #define TPACPI_COMPARE_KEY(__scancode, __member) \
35838 do { \
35839 if ((event_mask & (1 << __scancode)) && \
35840@@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35841 tpacpi_hotkey_send_key(__scancode); \
35842 } while (0)
35843
35844- void issue_volchange(const unsigned int oldvol,
35845- const unsigned int newvol)
35846- {
35847- unsigned int i = oldvol;
35848+static void issue_volchange(const unsigned int oldvol,
35849+ const unsigned int newvol,
35850+ const u32 event_mask)
35851+{
35852+ unsigned int i = oldvol;
35853
35854- while (i > newvol) {
35855- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35856- i--;
35857- }
35858- while (i < newvol) {
35859- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35860- i++;
35861- }
35862+ while (i > newvol) {
35863+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35864+ i--;
35865 }
35866+ while (i < newvol) {
35867+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35868+ i++;
35869+ }
35870+}
35871
35872- void issue_brightnesschange(const unsigned int oldbrt,
35873- const unsigned int newbrt)
35874- {
35875- unsigned int i = oldbrt;
35876+static void issue_brightnesschange(const unsigned int oldbrt,
35877+ const unsigned int newbrt,
35878+ const u32 event_mask)
35879+{
35880+ unsigned int i = oldbrt;
35881
35882- while (i > newbrt) {
35883- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35884- i--;
35885- }
35886- while (i < newbrt) {
35887- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35888- i++;
35889- }
35890+ while (i > newbrt) {
35891+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35892+ i--;
35893+ }
35894+ while (i < newbrt) {
35895+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35896+ i++;
35897 }
35898+}
35899
35900+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35901+ struct tp_nvram_state *newn,
35902+ const u32 event_mask)
35903+{
35904 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
35905 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
35906 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
35907@@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35908 oldn->volume_level != newn->volume_level) {
35909 /* recently muted, or repeated mute keypress, or
35910 * multiple presses ending in mute */
35911- issue_volchange(oldn->volume_level, newn->volume_level);
35912+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35913 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
35914 }
35915 } else {
35916@@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35917 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35918 }
35919 if (oldn->volume_level != newn->volume_level) {
35920- issue_volchange(oldn->volume_level, newn->volume_level);
35921+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35922 } else if (oldn->volume_toggle != newn->volume_toggle) {
35923 /* repeated vol up/down keypress at end of scale ? */
35924 if (newn->volume_level == 0)
35925@@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35926 /* handle brightness */
35927 if (oldn->brightness_level != newn->brightness_level) {
35928 issue_brightnesschange(oldn->brightness_level,
35929- newn->brightness_level);
35930+ newn->brightness_level,
35931+ event_mask);
35932 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
35933 /* repeated key presses that didn't change state */
35934 if (newn->brightness_level == 0)
35935@@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35936 && !tp_features.bright_unkfw)
35937 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35938 }
35939+}
35940
35941 #undef TPACPI_COMPARE_KEY
35942 #undef TPACPI_MAY_SEND_KEY
35943-}
35944
35945 /*
35946 * Polling driver
35947diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
35948index 769d265..a3a05ca 100644
35949--- a/drivers/pnp/pnpbios/bioscalls.c
35950+++ b/drivers/pnp/pnpbios/bioscalls.c
35951@@ -58,7 +58,7 @@ do { \
35952 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
35953 } while(0)
35954
35955-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
35956+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
35957 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
35958
35959 /*
35960@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
35961
35962 cpu = get_cpu();
35963 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
35964+
35965+ pax_open_kernel();
35966 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
35967+ pax_close_kernel();
35968
35969 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
35970 spin_lock_irqsave(&pnp_bios_lock, flags);
35971@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
35972 :"memory");
35973 spin_unlock_irqrestore(&pnp_bios_lock, flags);
35974
35975+ pax_open_kernel();
35976 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
35977+ pax_close_kernel();
35978+
35979 put_cpu();
35980
35981 /* If we get here and this is set then the PnP BIOS faulted on us. */
35982@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
35983 return status;
35984 }
35985
35986-void pnpbios_calls_init(union pnp_bios_install_struct *header)
35987+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
35988 {
35989 int i;
35990
35991@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
35992 pnp_bios_callpoint.offset = header->fields.pm16offset;
35993 pnp_bios_callpoint.segment = PNP_CS16;
35994
35995+ pax_open_kernel();
35996+
35997 for_each_possible_cpu(i) {
35998 struct desc_struct *gdt = get_cpu_gdt_table(i);
35999 if (!gdt)
36000@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36001 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36002 (unsigned long)__va(header->fields.pm16dseg));
36003 }
36004+
36005+ pax_close_kernel();
36006 }
36007diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36008index b0ecacb..7c9da2e 100644
36009--- a/drivers/pnp/resource.c
36010+++ b/drivers/pnp/resource.c
36011@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36012 return 1;
36013
36014 /* check if the resource is valid */
36015- if (*irq < 0 || *irq > 15)
36016+ if (*irq > 15)
36017 return 0;
36018
36019 /* check if the resource is reserved */
36020@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36021 return 1;
36022
36023 /* check if the resource is valid */
36024- if (*dma < 0 || *dma == 4 || *dma > 7)
36025+ if (*dma == 4 || *dma > 7)
36026 return 0;
36027
36028 /* check if the resource is reserved */
36029diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36030index f5d6d37..739f6a9 100644
36031--- a/drivers/power/bq27x00_battery.c
36032+++ b/drivers/power/bq27x00_battery.c
36033@@ -72,7 +72,7 @@
36034 struct bq27x00_device_info;
36035 struct bq27x00_access_methods {
36036 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36037-};
36038+} __no_const;
36039
36040 enum bq27x00_chip { BQ27000, BQ27500 };
36041
36042diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36043index 8d53174..04c65de 100644
36044--- a/drivers/regulator/max8660.c
36045+++ b/drivers/regulator/max8660.c
36046@@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36047 max8660->shadow_regs[MAX8660_OVER1] = 5;
36048 } else {
36049 /* Otherwise devices can be toggled via software */
36050- max8660_dcdc_ops.enable = max8660_dcdc_enable;
36051- max8660_dcdc_ops.disable = max8660_dcdc_disable;
36052+ pax_open_kernel();
36053+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36054+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36055+ pax_close_kernel();
36056 }
36057
36058 /*
36059diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36060index 970a233..ee1f241 100644
36061--- a/drivers/regulator/mc13892-regulator.c
36062+++ b/drivers/regulator/mc13892-regulator.c
36063@@ -566,10 +566,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36064 }
36065 mc13xxx_unlock(mc13892);
36066
36067- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36068+ pax_open_kernel();
36069+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36070 = mc13892_vcam_set_mode;
36071- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36072+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36073 = mc13892_vcam_get_mode;
36074+ pax_close_kernel();
36075
36076 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36077 ARRAY_SIZE(mc13892_regulators));
36078diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36079index cace6d3..f623fda 100644
36080--- a/drivers/rtc/rtc-dev.c
36081+++ b/drivers/rtc/rtc-dev.c
36082@@ -14,6 +14,7 @@
36083 #include <linux/module.h>
36084 #include <linux/rtc.h>
36085 #include <linux/sched.h>
36086+#include <linux/grsecurity.h>
36087 #include "rtc-core.h"
36088
36089 static dev_t rtc_devt;
36090@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36091 if (copy_from_user(&tm, uarg, sizeof(tm)))
36092 return -EFAULT;
36093
36094+ gr_log_timechange();
36095+
36096 return rtc_set_time(rtc, &tm);
36097
36098 case RTC_PIE_ON:
36099diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36100index 3fcf627..f334910 100644
36101--- a/drivers/scsi/aacraid/aacraid.h
36102+++ b/drivers/scsi/aacraid/aacraid.h
36103@@ -492,7 +492,7 @@ struct adapter_ops
36104 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36105 /* Administrative operations */
36106 int (*adapter_comm)(struct aac_dev * dev, int comm);
36107-};
36108+} __no_const;
36109
36110 /*
36111 * Define which interrupt handler needs to be installed
36112diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36113index 0d279c44..3d25a97 100644
36114--- a/drivers/scsi/aacraid/linit.c
36115+++ b/drivers/scsi/aacraid/linit.c
36116@@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36117 #elif defined(__devinitconst)
36118 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36119 #else
36120-static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36121+static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36122 #endif
36123 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36124 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36125diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36126index ff80552..1c4120c 100644
36127--- a/drivers/scsi/aic94xx/aic94xx_init.c
36128+++ b/drivers/scsi/aic94xx/aic94xx_init.c
36129@@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36130 .lldd_ata_set_dmamode = asd_set_dmamode,
36131 };
36132
36133-static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36134+static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36135 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36136 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36137 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36138diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36139index 4ad7e36..d004679 100644
36140--- a/drivers/scsi/bfa/bfa.h
36141+++ b/drivers/scsi/bfa/bfa.h
36142@@ -196,7 +196,7 @@ struct bfa_hwif_s {
36143 u32 *end);
36144 int cpe_vec_q0;
36145 int rme_vec_q0;
36146-};
36147+} __no_const;
36148 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36149
36150 struct bfa_faa_cbfn_s {
36151diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36152index f0f80e2..8ec946b 100644
36153--- a/drivers/scsi/bfa/bfa_fcpim.c
36154+++ b/drivers/scsi/bfa/bfa_fcpim.c
36155@@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36156
36157 bfa_iotag_attach(fcp);
36158
36159- fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36160+ fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36161 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36162 (fcp->num_itns * sizeof(struct bfa_itn_s));
36163 memset(fcp->itn_arr, 0,
36164@@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36165 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36166 {
36167 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36168- struct bfa_itn_s *itn;
36169+ bfa_itn_s_no_const *itn;
36170
36171 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36172 itn->isr = isr;
36173diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36174index 36f26da..38a34a8 100644
36175--- a/drivers/scsi/bfa/bfa_fcpim.h
36176+++ b/drivers/scsi/bfa/bfa_fcpim.h
36177@@ -37,6 +37,7 @@ struct bfa_iotag_s {
36178 struct bfa_itn_s {
36179 bfa_isr_func_t isr;
36180 };
36181+typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36182
36183 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36184 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36185@@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36186 struct list_head iotag_tio_free_q; /* free IO resources */
36187 struct list_head iotag_unused_q; /* unused IO resources*/
36188 struct bfa_iotag_s *iotag_arr;
36189- struct bfa_itn_s *itn_arr;
36190+ bfa_itn_s_no_const *itn_arr;
36191 int num_ioim_reqs;
36192 int num_fwtio_reqs;
36193 int num_itns;
36194diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36195index 1a99d4b..e85d64b 100644
36196--- a/drivers/scsi/bfa/bfa_ioc.h
36197+++ b/drivers/scsi/bfa/bfa_ioc.h
36198@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36199 bfa_ioc_disable_cbfn_t disable_cbfn;
36200 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36201 bfa_ioc_reset_cbfn_t reset_cbfn;
36202-};
36203+} __no_const;
36204
36205 /*
36206 * IOC event notification mechanism.
36207@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36208 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36209 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36210 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36211-};
36212+} __no_const;
36213
36214 /*
36215 * Queue element to wait for room in request queue. FIFO order is
36216diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36217index b48c24f..dac0fbc 100644
36218--- a/drivers/scsi/hosts.c
36219+++ b/drivers/scsi/hosts.c
36220@@ -42,7 +42,7 @@
36221 #include "scsi_logging.h"
36222
36223
36224-static atomic_t scsi_host_next_hn; /* host_no for next new host */
36225+static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
36226
36227
36228 static void scsi_host_cls_release(struct device *dev)
36229@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36230 * subtract one because we increment first then return, but we need to
36231 * know what the next host number was before increment
36232 */
36233- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36234+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36235 shost->dma_channel = 0xff;
36236
36237 /* These three are default values which can be overridden */
36238diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36239index 796482b..d08435c 100644
36240--- a/drivers/scsi/hpsa.c
36241+++ b/drivers/scsi/hpsa.c
36242@@ -536,7 +536,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
36243 unsigned long flags;
36244
36245 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36246- return h->access.command_completed(h, q);
36247+ return h->access->command_completed(h, q);
36248
36249 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
36250 a = rq->head[rq->current_entry];
36251@@ -3354,7 +3354,7 @@ static void start_io(struct ctlr_info *h)
36252 while (!list_empty(&h->reqQ)) {
36253 c = list_entry(h->reqQ.next, struct CommandList, list);
36254 /* can't do anything if fifo is full */
36255- if ((h->access.fifo_full(h))) {
36256+ if ((h->access->fifo_full(h))) {
36257 dev_warn(&h->pdev->dev, "fifo full\n");
36258 break;
36259 }
36260@@ -3376,7 +3376,7 @@ static void start_io(struct ctlr_info *h)
36261
36262 /* Tell the controller execute command */
36263 spin_unlock_irqrestore(&h->lock, flags);
36264- h->access.submit_command(h, c);
36265+ h->access->submit_command(h, c);
36266 spin_lock_irqsave(&h->lock, flags);
36267 }
36268 spin_unlock_irqrestore(&h->lock, flags);
36269@@ -3384,17 +3384,17 @@ static void start_io(struct ctlr_info *h)
36270
36271 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
36272 {
36273- return h->access.command_completed(h, q);
36274+ return h->access->command_completed(h, q);
36275 }
36276
36277 static inline bool interrupt_pending(struct ctlr_info *h)
36278 {
36279- return h->access.intr_pending(h);
36280+ return h->access->intr_pending(h);
36281 }
36282
36283 static inline long interrupt_not_for_us(struct ctlr_info *h)
36284 {
36285- return (h->access.intr_pending(h) == 0) ||
36286+ return (h->access->intr_pending(h) == 0) ||
36287 (h->interrupts_enabled == 0);
36288 }
36289
36290@@ -4298,7 +4298,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36291 if (prod_index < 0)
36292 return -ENODEV;
36293 h->product_name = products[prod_index].product_name;
36294- h->access = *(products[prod_index].access);
36295+ h->access = products[prod_index].access;
36296
36297 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
36298 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
36299@@ -4580,7 +4580,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36300
36301 assert_spin_locked(&lockup_detector_lock);
36302 remove_ctlr_from_lockup_detector_list(h);
36303- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36304+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36305 spin_lock_irqsave(&h->lock, flags);
36306 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36307 spin_unlock_irqrestore(&h->lock, flags);
36308@@ -4758,7 +4758,7 @@ reinit_after_soft_reset:
36309 }
36310
36311 /* make sure the board interrupts are off */
36312- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36313+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36314
36315 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36316 goto clean2;
36317@@ -4792,7 +4792,7 @@ reinit_after_soft_reset:
36318 * fake ones to scoop up any residual completions.
36319 */
36320 spin_lock_irqsave(&h->lock, flags);
36321- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36322+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36323 spin_unlock_irqrestore(&h->lock, flags);
36324 free_irqs(h);
36325 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36326@@ -4811,9 +4811,9 @@ reinit_after_soft_reset:
36327 dev_info(&h->pdev->dev, "Board READY.\n");
36328 dev_info(&h->pdev->dev,
36329 "Waiting for stale completions to drain.\n");
36330- h->access.set_intr_mask(h, HPSA_INTR_ON);
36331+ h->access->set_intr_mask(h, HPSA_INTR_ON);
36332 msleep(10000);
36333- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36334+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36335
36336 rc = controller_reset_failed(h->cfgtable);
36337 if (rc)
36338@@ -4834,7 +4834,7 @@ reinit_after_soft_reset:
36339 }
36340
36341 /* Turn the interrupts on so we can service requests */
36342- h->access.set_intr_mask(h, HPSA_INTR_ON);
36343+ h->access->set_intr_mask(h, HPSA_INTR_ON);
36344
36345 hpsa_hba_inquiry(h);
36346 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36347@@ -4886,7 +4886,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36348 * To write all data in the battery backed cache to disks
36349 */
36350 hpsa_flush_cache(h);
36351- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36352+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36353 hpsa_free_irqs_and_disable_msix(h);
36354 }
36355
36356@@ -5055,7 +5055,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36357 return;
36358 }
36359 /* Change the access methods to the performant access methods */
36360- h->access = SA5_performant_access;
36361+ h->access = &SA5_performant_access;
36362 h->transMethod = CFGTBL_Trans_Performant;
36363 }
36364
36365diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36366index 9816479..c5d4e97 100644
36367--- a/drivers/scsi/hpsa.h
36368+++ b/drivers/scsi/hpsa.h
36369@@ -79,7 +79,7 @@ struct ctlr_info {
36370 unsigned int msix_vector;
36371 unsigned int msi_vector;
36372 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36373- struct access_method access;
36374+ struct access_method *access;
36375
36376 /* queue and queue Info */
36377 struct list_head reqQ;
36378diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36379index f2df059..a3a9930 100644
36380--- a/drivers/scsi/ips.h
36381+++ b/drivers/scsi/ips.h
36382@@ -1027,7 +1027,7 @@ typedef struct {
36383 int (*intr)(struct ips_ha *);
36384 void (*enableint)(struct ips_ha *);
36385 uint32_t (*statupd)(struct ips_ha *);
36386-} ips_hw_func_t;
36387+} __no_const ips_hw_func_t;
36388
36389 typedef struct ips_ha {
36390 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36391diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36392index aceffad..c35c08d 100644
36393--- a/drivers/scsi/libfc/fc_exch.c
36394+++ b/drivers/scsi/libfc/fc_exch.c
36395@@ -105,12 +105,12 @@ struct fc_exch_mgr {
36396 * all together if not used XXX
36397 */
36398 struct {
36399- atomic_t no_free_exch;
36400- atomic_t no_free_exch_xid;
36401- atomic_t xid_not_found;
36402- atomic_t xid_busy;
36403- atomic_t seq_not_found;
36404- atomic_t non_bls_resp;
36405+ atomic_unchecked_t no_free_exch;
36406+ atomic_unchecked_t no_free_exch_xid;
36407+ atomic_unchecked_t xid_not_found;
36408+ atomic_unchecked_t xid_busy;
36409+ atomic_unchecked_t seq_not_found;
36410+ atomic_unchecked_t non_bls_resp;
36411 } stats;
36412 };
36413
36414@@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36415 /* allocate memory for exchange */
36416 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36417 if (!ep) {
36418- atomic_inc(&mp->stats.no_free_exch);
36419+ atomic_inc_unchecked(&mp->stats.no_free_exch);
36420 goto out;
36421 }
36422 memset(ep, 0, sizeof(*ep));
36423@@ -780,7 +780,7 @@ out:
36424 return ep;
36425 err:
36426 spin_unlock_bh(&pool->lock);
36427- atomic_inc(&mp->stats.no_free_exch_xid);
36428+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36429 mempool_free(ep, mp->ep_pool);
36430 return NULL;
36431 }
36432@@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36433 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36434 ep = fc_exch_find(mp, xid);
36435 if (!ep) {
36436- atomic_inc(&mp->stats.xid_not_found);
36437+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36438 reject = FC_RJT_OX_ID;
36439 goto out;
36440 }
36441@@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36442 ep = fc_exch_find(mp, xid);
36443 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36444 if (ep) {
36445- atomic_inc(&mp->stats.xid_busy);
36446+ atomic_inc_unchecked(&mp->stats.xid_busy);
36447 reject = FC_RJT_RX_ID;
36448 goto rel;
36449 }
36450@@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36451 }
36452 xid = ep->xid; /* get our XID */
36453 } else if (!ep) {
36454- atomic_inc(&mp->stats.xid_not_found);
36455+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36456 reject = FC_RJT_RX_ID; /* XID not found */
36457 goto out;
36458 }
36459@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36460 } else {
36461 sp = &ep->seq;
36462 if (sp->id != fh->fh_seq_id) {
36463- atomic_inc(&mp->stats.seq_not_found);
36464+ atomic_inc_unchecked(&mp->stats.seq_not_found);
36465 if (f_ctl & FC_FC_END_SEQ) {
36466 /*
36467 * Update sequence_id based on incoming last
36468@@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36469
36470 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36471 if (!ep) {
36472- atomic_inc(&mp->stats.xid_not_found);
36473+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36474 goto out;
36475 }
36476 if (ep->esb_stat & ESB_ST_COMPLETE) {
36477- atomic_inc(&mp->stats.xid_not_found);
36478+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36479 goto rel;
36480 }
36481 if (ep->rxid == FC_XID_UNKNOWN)
36482 ep->rxid = ntohs(fh->fh_rx_id);
36483 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36484- atomic_inc(&mp->stats.xid_not_found);
36485+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36486 goto rel;
36487 }
36488 if (ep->did != ntoh24(fh->fh_s_id) &&
36489 ep->did != FC_FID_FLOGI) {
36490- atomic_inc(&mp->stats.xid_not_found);
36491+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36492 goto rel;
36493 }
36494 sof = fr_sof(fp);
36495@@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36496 sp->ssb_stat |= SSB_ST_RESP;
36497 sp->id = fh->fh_seq_id;
36498 } else if (sp->id != fh->fh_seq_id) {
36499- atomic_inc(&mp->stats.seq_not_found);
36500+ atomic_inc_unchecked(&mp->stats.seq_not_found);
36501 goto rel;
36502 }
36503
36504@@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36505 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36506
36507 if (!sp)
36508- atomic_inc(&mp->stats.xid_not_found);
36509+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36510 else
36511- atomic_inc(&mp->stats.non_bls_resp);
36512+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
36513
36514 fc_frame_free(fp);
36515 }
36516diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36517index d109cc3..09f4e7d 100644
36518--- a/drivers/scsi/libsas/sas_ata.c
36519+++ b/drivers/scsi/libsas/sas_ata.c
36520@@ -529,7 +529,7 @@ static struct ata_port_operations sas_sata_ops = {
36521 .postreset = ata_std_postreset,
36522 .error_handler = ata_std_error_handler,
36523 .post_internal_cmd = sas_ata_post_internal,
36524- .qc_defer = ata_std_qc_defer,
36525+ .qc_defer = ata_std_qc_defer,
36526 .qc_prep = ata_noop_qc_prep,
36527 .qc_issue = sas_ata_qc_issue,
36528 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36529diff --git a/drivers/scsi/lpfc/Makefile b/drivers/scsi/lpfc/Makefile
36530index fe5d396..e93d526 100644
36531--- a/drivers/scsi/lpfc/Makefile
36532+++ b/drivers/scsi/lpfc/Makefile
36533@@ -22,7 +22,7 @@
36534 ccflags-$(GCOV) := -fprofile-arcs -ftest-coverage
36535 ccflags-$(GCOV) += -O0
36536
36537-ccflags-y += -Werror
36538+#ccflags-y += -Werror
36539
36540 obj-$(CONFIG_SCSI_LPFC) := lpfc.o
36541
36542diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36543index e5da6da..c888d48 100644
36544--- a/drivers/scsi/lpfc/lpfc.h
36545+++ b/drivers/scsi/lpfc/lpfc.h
36546@@ -416,7 +416,7 @@ struct lpfc_vport {
36547 struct dentry *debug_nodelist;
36548 struct dentry *vport_debugfs_root;
36549 struct lpfc_debugfs_trc *disc_trc;
36550- atomic_t disc_trc_cnt;
36551+ atomic_unchecked_t disc_trc_cnt;
36552 #endif
36553 uint8_t stat_data_enabled;
36554 uint8_t stat_data_blocked;
36555@@ -830,8 +830,8 @@ struct lpfc_hba {
36556 struct timer_list fabric_block_timer;
36557 unsigned long bit_flags;
36558 #define FABRIC_COMANDS_BLOCKED 0
36559- atomic_t num_rsrc_err;
36560- atomic_t num_cmd_success;
36561+ atomic_unchecked_t num_rsrc_err;
36562+ atomic_unchecked_t num_cmd_success;
36563 unsigned long last_rsrc_error_time;
36564 unsigned long last_ramp_down_time;
36565 unsigned long last_ramp_up_time;
36566@@ -867,7 +867,7 @@ struct lpfc_hba {
36567
36568 struct dentry *debug_slow_ring_trc;
36569 struct lpfc_debugfs_trc *slow_ring_trc;
36570- atomic_t slow_ring_trc_cnt;
36571+ atomic_unchecked_t slow_ring_trc_cnt;
36572 /* iDiag debugfs sub-directory */
36573 struct dentry *idiag_root;
36574 struct dentry *idiag_pci_cfg;
36575diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
36576index 3217d63..c417981 100644
36577--- a/drivers/scsi/lpfc/lpfc_debugfs.c
36578+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
36579@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
36580
36581 #include <linux/debugfs.h>
36582
36583-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36584+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36585 static unsigned long lpfc_debugfs_start_time = 0L;
36586
36587 /* iDiag */
36588@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
36589 lpfc_debugfs_enable = 0;
36590
36591 len = 0;
36592- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
36593+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
36594 (lpfc_debugfs_max_disc_trc - 1);
36595 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
36596 dtp = vport->disc_trc + i;
36597@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
36598 lpfc_debugfs_enable = 0;
36599
36600 len = 0;
36601- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
36602+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
36603 (lpfc_debugfs_max_slow_ring_trc - 1);
36604 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
36605 dtp = phba->slow_ring_trc + i;
36606@@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
36607 !vport || !vport->disc_trc)
36608 return;
36609
36610- index = atomic_inc_return(&vport->disc_trc_cnt) &
36611+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
36612 (lpfc_debugfs_max_disc_trc - 1);
36613 dtp = vport->disc_trc + index;
36614 dtp->fmt = fmt;
36615 dtp->data1 = data1;
36616 dtp->data2 = data2;
36617 dtp->data3 = data3;
36618- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36619+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36620 dtp->jif = jiffies;
36621 #endif
36622 return;
36623@@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
36624 !phba || !phba->slow_ring_trc)
36625 return;
36626
36627- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
36628+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
36629 (lpfc_debugfs_max_slow_ring_trc - 1);
36630 dtp = phba->slow_ring_trc + index;
36631 dtp->fmt = fmt;
36632 dtp->data1 = data1;
36633 dtp->data2 = data2;
36634 dtp->data3 = data3;
36635- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36636+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36637 dtp->jif = jiffies;
36638 #endif
36639 return;
36640@@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36641 "slow_ring buffer\n");
36642 goto debug_failed;
36643 }
36644- atomic_set(&phba->slow_ring_trc_cnt, 0);
36645+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
36646 memset(phba->slow_ring_trc, 0,
36647 (sizeof(struct lpfc_debugfs_trc) *
36648 lpfc_debugfs_max_slow_ring_trc));
36649@@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36650 "buffer\n");
36651 goto debug_failed;
36652 }
36653- atomic_set(&vport->disc_trc_cnt, 0);
36654+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
36655
36656 snprintf(name, sizeof(name), "discovery_trace");
36657 vport->debug_disc_trc =
36658diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
36659index 411ed48..967f553 100644
36660--- a/drivers/scsi/lpfc/lpfc_init.c
36661+++ b/drivers/scsi/lpfc/lpfc_init.c
36662@@ -10341,8 +10341,10 @@ lpfc_init(void)
36663 "misc_register returned with status %d", error);
36664
36665 if (lpfc_enable_npiv) {
36666- lpfc_transport_functions.vport_create = lpfc_vport_create;
36667- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36668+ pax_open_kernel();
36669+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
36670+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36671+ pax_close_kernel();
36672 }
36673 lpfc_transport_template =
36674 fc_attach_transport(&lpfc_transport_functions);
36675diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
36676index 66e0906..1620281 100644
36677--- a/drivers/scsi/lpfc/lpfc_scsi.c
36678+++ b/drivers/scsi/lpfc/lpfc_scsi.c
36679@@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
36680 uint32_t evt_posted;
36681
36682 spin_lock_irqsave(&phba->hbalock, flags);
36683- atomic_inc(&phba->num_rsrc_err);
36684+ atomic_inc_unchecked(&phba->num_rsrc_err);
36685 phba->last_rsrc_error_time = jiffies;
36686
36687 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
36688@@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
36689 unsigned long flags;
36690 struct lpfc_hba *phba = vport->phba;
36691 uint32_t evt_posted;
36692- atomic_inc(&phba->num_cmd_success);
36693+ atomic_inc_unchecked(&phba->num_cmd_success);
36694
36695 if (vport->cfg_lun_queue_depth <= queue_depth)
36696 return;
36697@@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36698 unsigned long num_rsrc_err, num_cmd_success;
36699 int i;
36700
36701- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
36702- num_cmd_success = atomic_read(&phba->num_cmd_success);
36703+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
36704+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
36705
36706 /*
36707 * The error and success command counters are global per
36708@@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36709 }
36710 }
36711 lpfc_destroy_vport_work_array(phba, vports);
36712- atomic_set(&phba->num_rsrc_err, 0);
36713- atomic_set(&phba->num_cmd_success, 0);
36714+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
36715+ atomic_set_unchecked(&phba->num_cmd_success, 0);
36716 }
36717
36718 /**
36719@@ -460,8 +460,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
36720 }
36721 }
36722 lpfc_destroy_vport_work_array(phba, vports);
36723- atomic_set(&phba->num_rsrc_err, 0);
36724- atomic_set(&phba->num_cmd_success, 0);
36725+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
36726+ atomic_set_unchecked(&phba->num_cmd_success, 0);
36727 }
36728
36729 /**
36730diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
36731index ea8a0b4..812a124 100644
36732--- a/drivers/scsi/pmcraid.c
36733+++ b/drivers/scsi/pmcraid.c
36734@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
36735 res->scsi_dev = scsi_dev;
36736 scsi_dev->hostdata = res;
36737 res->change_detected = 0;
36738- atomic_set(&res->read_failures, 0);
36739- atomic_set(&res->write_failures, 0);
36740+ atomic_set_unchecked(&res->read_failures, 0);
36741+ atomic_set_unchecked(&res->write_failures, 0);
36742 rc = 0;
36743 }
36744 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
36745@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
36746
36747 /* If this was a SCSI read/write command keep count of errors */
36748 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
36749- atomic_inc(&res->read_failures);
36750+ atomic_inc_unchecked(&res->read_failures);
36751 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
36752- atomic_inc(&res->write_failures);
36753+ atomic_inc_unchecked(&res->write_failures);
36754
36755 if (!RES_IS_GSCSI(res->cfg_entry) &&
36756 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
36757@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
36758 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36759 * hrrq_id assigned here in queuecommand
36760 */
36761- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36762+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36763 pinstance->num_hrrq;
36764 cmd->cmd_done = pmcraid_io_done;
36765
36766@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
36767 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36768 * hrrq_id assigned here in queuecommand
36769 */
36770- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36771+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36772 pinstance->num_hrrq;
36773
36774 if (request_size) {
36775@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
36776
36777 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
36778 /* add resources only after host is added into system */
36779- if (!atomic_read(&pinstance->expose_resources))
36780+ if (!atomic_read_unchecked(&pinstance->expose_resources))
36781 return;
36782
36783 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
36784@@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
36785 init_waitqueue_head(&pinstance->reset_wait_q);
36786
36787 atomic_set(&pinstance->outstanding_cmds, 0);
36788- atomic_set(&pinstance->last_message_id, 0);
36789- atomic_set(&pinstance->expose_resources, 0);
36790+ atomic_set_unchecked(&pinstance->last_message_id, 0);
36791+ atomic_set_unchecked(&pinstance->expose_resources, 0);
36792
36793 INIT_LIST_HEAD(&pinstance->free_res_q);
36794 INIT_LIST_HEAD(&pinstance->used_res_q);
36795@@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
36796 /* Schedule worker thread to handle CCN and take care of adding and
36797 * removing devices to OS
36798 */
36799- atomic_set(&pinstance->expose_resources, 1);
36800+ atomic_set_unchecked(&pinstance->expose_resources, 1);
36801 schedule_work(&pinstance->worker_q);
36802 return rc;
36803
36804diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
36805index e1d150f..6c6df44 100644
36806--- a/drivers/scsi/pmcraid.h
36807+++ b/drivers/scsi/pmcraid.h
36808@@ -748,7 +748,7 @@ struct pmcraid_instance {
36809 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
36810
36811 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
36812- atomic_t last_message_id;
36813+ atomic_unchecked_t last_message_id;
36814
36815 /* configuration table */
36816 struct pmcraid_config_table *cfg_table;
36817@@ -777,7 +777,7 @@ struct pmcraid_instance {
36818 atomic_t outstanding_cmds;
36819
36820 /* should add/delete resources to mid-layer now ?*/
36821- atomic_t expose_resources;
36822+ atomic_unchecked_t expose_resources;
36823
36824
36825
36826@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
36827 struct pmcraid_config_table_entry_ext cfg_entry_ext;
36828 };
36829 struct scsi_device *scsi_dev; /* Link scsi_device structure */
36830- atomic_t read_failures; /* count of failed READ commands */
36831- atomic_t write_failures; /* count of failed WRITE commands */
36832+ atomic_unchecked_t read_failures; /* count of failed READ commands */
36833+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
36834
36835 /* To indicate add/delete/modify during CCN */
36836 u8 change_detected;
36837diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
36838index 5ab9530..2dd80f7 100644
36839--- a/drivers/scsi/qla2xxx/qla_attr.c
36840+++ b/drivers/scsi/qla2xxx/qla_attr.c
36841@@ -1855,7 +1855,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
36842 return 0;
36843 }
36844
36845-struct fc_function_template qla2xxx_transport_functions = {
36846+fc_function_template_no_const qla2xxx_transport_functions = {
36847
36848 .show_host_node_name = 1,
36849 .show_host_port_name = 1,
36850@@ -1902,7 +1902,7 @@ struct fc_function_template qla2xxx_transport_functions = {
36851 .bsg_timeout = qla24xx_bsg_timeout,
36852 };
36853
36854-struct fc_function_template qla2xxx_transport_vport_functions = {
36855+fc_function_template_no_const qla2xxx_transport_vport_functions = {
36856
36857 .show_host_node_name = 1,
36858 .show_host_port_name = 1,
36859diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
36860index 39007f5..7fafc64 100644
36861--- a/drivers/scsi/qla2xxx/qla_def.h
36862+++ b/drivers/scsi/qla2xxx/qla_def.h
36863@@ -2284,7 +2284,7 @@ struct isp_operations {
36864 int (*start_scsi) (srb_t *);
36865 int (*abort_isp) (struct scsi_qla_host *);
36866 int (*iospace_config)(struct qla_hw_data*);
36867-};
36868+} __no_const;
36869
36870 /* MSI-X Support *************************************************************/
36871
36872diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
36873index 9eacd2d..d79629c 100644
36874--- a/drivers/scsi/qla2xxx/qla_gbl.h
36875+++ b/drivers/scsi/qla2xxx/qla_gbl.h
36876@@ -484,8 +484,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
36877 struct device_attribute;
36878 extern struct device_attribute *qla2x00_host_attrs[];
36879 struct fc_function_template;
36880-extern struct fc_function_template qla2xxx_transport_functions;
36881-extern struct fc_function_template qla2xxx_transport_vport_functions;
36882+extern fc_function_template_no_const qla2xxx_transport_functions;
36883+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
36884 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
36885 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
36886 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
36887diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
36888index 96a5616..eeb185a 100644
36889--- a/drivers/scsi/qla4xxx/ql4_def.h
36890+++ b/drivers/scsi/qla4xxx/ql4_def.h
36891@@ -268,7 +268,7 @@ struct ddb_entry {
36892 * (4000 only) */
36893 atomic_t relogin_timer; /* Max Time to wait for
36894 * relogin to complete */
36895- atomic_t relogin_retry_count; /* Num of times relogin has been
36896+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
36897 * retried */
36898 uint32_t default_time2wait; /* Default Min time between
36899 * relogins (+aens) */
36900diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
36901index cd15678..f7e6846 100644
36902--- a/drivers/scsi/qla4xxx/ql4_os.c
36903+++ b/drivers/scsi/qla4xxx/ql4_os.c
36904@@ -2615,12 +2615,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
36905 */
36906 if (!iscsi_is_session_online(cls_sess)) {
36907 /* Reset retry relogin timer */
36908- atomic_inc(&ddb_entry->relogin_retry_count);
36909+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
36910 DEBUG2(ql4_printk(KERN_INFO, ha,
36911 "%s: index[%d] relogin timed out-retrying"
36912 " relogin (%d), retry (%d)\n", __func__,
36913 ddb_entry->fw_ddb_index,
36914- atomic_read(&ddb_entry->relogin_retry_count),
36915+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
36916 ddb_entry->default_time2wait + 4));
36917 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
36918 atomic_set(&ddb_entry->retry_relogin_timer,
36919@@ -4517,7 +4517,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
36920
36921 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
36922 atomic_set(&ddb_entry->relogin_timer, 0);
36923- atomic_set(&ddb_entry->relogin_retry_count, 0);
36924+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
36925 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
36926 ddb_entry->default_relogin_timeout =
36927 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
36928diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
36929index bbbc9c9..ce22f77 100644
36930--- a/drivers/scsi/scsi.c
36931+++ b/drivers/scsi/scsi.c
36932@@ -659,7 +659,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
36933 unsigned long timeout;
36934 int rtn = 0;
36935
36936- atomic_inc(&cmd->device->iorequest_cnt);
36937+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
36938
36939 /* check if the device is still usable */
36940 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
36941diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
36942index 495db80..fb37d59 100644
36943--- a/drivers/scsi/scsi_lib.c
36944+++ b/drivers/scsi/scsi_lib.c
36945@@ -1422,7 +1422,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
36946 shost = sdev->host;
36947 scsi_init_cmd_errh(cmd);
36948 cmd->result = DID_NO_CONNECT << 16;
36949- atomic_inc(&cmd->device->iorequest_cnt);
36950+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
36951
36952 /*
36953 * SCSI request completion path will do scsi_device_unbusy(),
36954@@ -1448,9 +1448,9 @@ static void scsi_softirq_done(struct request *rq)
36955
36956 INIT_LIST_HEAD(&cmd->eh_entry);
36957
36958- atomic_inc(&cmd->device->iodone_cnt);
36959+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
36960 if (cmd->result)
36961- atomic_inc(&cmd->device->ioerr_cnt);
36962+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
36963
36964 disposition = scsi_decide_disposition(cmd);
36965 if (disposition != SUCCESS &&
36966diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
36967index bb7c482..7551a95 100644
36968--- a/drivers/scsi/scsi_sysfs.c
36969+++ b/drivers/scsi/scsi_sysfs.c
36970@@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
36971 char *buf) \
36972 { \
36973 struct scsi_device *sdev = to_scsi_device(dev); \
36974- unsigned long long count = atomic_read(&sdev->field); \
36975+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
36976 return snprintf(buf, 20, "0x%llx\n", count); \
36977 } \
36978 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
36979diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
36980index 84a1fdf..693b0d6 100644
36981--- a/drivers/scsi/scsi_tgt_lib.c
36982+++ b/drivers/scsi/scsi_tgt_lib.c
36983@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
36984 int err;
36985
36986 dprintk("%lx %u\n", uaddr, len);
36987- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
36988+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
36989 if (err) {
36990 /*
36991 * TODO: need to fixup sg_tablesize, max_segment_size,
36992diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
36993index 5797604..289a5b5 100644
36994--- a/drivers/scsi/scsi_transport_fc.c
36995+++ b/drivers/scsi/scsi_transport_fc.c
36996@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
36997 * Netlink Infrastructure
36998 */
36999
37000-static atomic_t fc_event_seq;
37001+static atomic_unchecked_t fc_event_seq;
37002
37003 /**
37004 * fc_get_event_number - Obtain the next sequential FC event number
37005@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
37006 u32
37007 fc_get_event_number(void)
37008 {
37009- return atomic_add_return(1, &fc_event_seq);
37010+ return atomic_add_return_unchecked(1, &fc_event_seq);
37011 }
37012 EXPORT_SYMBOL(fc_get_event_number);
37013
37014@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
37015 {
37016 int error;
37017
37018- atomic_set(&fc_event_seq, 0);
37019+ atomic_set_unchecked(&fc_event_seq, 0);
37020
37021 error = transport_class_register(&fc_host_class);
37022 if (error)
37023@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37024 char *cp;
37025
37026 *val = simple_strtoul(buf, &cp, 0);
37027- if ((*cp && (*cp != '\n')) || (*val < 0))
37028+ if (*cp && (*cp != '\n'))
37029 return -EINVAL;
37030 /*
37031 * Check for overflow; dev_loss_tmo is u32
37032diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37033index 1cf640e..78e9014 100644
37034--- a/drivers/scsi/scsi_transport_iscsi.c
37035+++ b/drivers/scsi/scsi_transport_iscsi.c
37036@@ -79,7 +79,7 @@ struct iscsi_internal {
37037 struct transport_container session_cont;
37038 };
37039
37040-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37041+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37042 static struct workqueue_struct *iscsi_eh_timer_workq;
37043
37044 static DEFINE_IDA(iscsi_sess_ida);
37045@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37046 int err;
37047
37048 ihost = shost->shost_data;
37049- session->sid = atomic_add_return(1, &iscsi_session_nr);
37050+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37051
37052 if (target_id == ISCSI_MAX_TARGET) {
37053 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37054@@ -2940,7 +2940,7 @@ static __init int iscsi_transport_init(void)
37055 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37056 ISCSI_TRANSPORT_VERSION);
37057
37058- atomic_set(&iscsi_session_nr, 0);
37059+ atomic_set_unchecked(&iscsi_session_nr, 0);
37060
37061 err = class_register(&iscsi_transport_class);
37062 if (err)
37063diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37064index 21a045e..ec89e03 100644
37065--- a/drivers/scsi/scsi_transport_srp.c
37066+++ b/drivers/scsi/scsi_transport_srp.c
37067@@ -33,7 +33,7 @@
37068 #include "scsi_transport_srp_internal.h"
37069
37070 struct srp_host_attrs {
37071- atomic_t next_port_id;
37072+ atomic_unchecked_t next_port_id;
37073 };
37074 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37075
37076@@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37077 struct Scsi_Host *shost = dev_to_shost(dev);
37078 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37079
37080- atomic_set(&srp_host->next_port_id, 0);
37081+ atomic_set_unchecked(&srp_host->next_port_id, 0);
37082 return 0;
37083 }
37084
37085@@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37086 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37087 rport->roles = ids->roles;
37088
37089- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37090+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37091 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37092
37093 transport_setup_device(&rport->dev);
37094diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37095index 9c5c5f2..8414557 100644
37096--- a/drivers/scsi/sg.c
37097+++ b/drivers/scsi/sg.c
37098@@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37099 sdp->disk->disk_name,
37100 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37101 NULL,
37102- (char *)arg);
37103+ (char __user *)arg);
37104 case BLKTRACESTART:
37105 return blk_trace_startstop(sdp->device->request_queue, 1);
37106 case BLKTRACESTOP:
37107diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37108index 1041cb8..4a946fa 100644
37109--- a/drivers/spi/spi.c
37110+++ b/drivers/spi/spi.c
37111@@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
37112 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37113
37114 /* portable code must never pass more than 32 bytes */
37115-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37116+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37117
37118 static u8 *buf;
37119
37120diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37121index 34afc16..ffe44dd 100644
37122--- a/drivers/staging/octeon/ethernet-rx.c
37123+++ b/drivers/staging/octeon/ethernet-rx.c
37124@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37125 /* Increment RX stats for virtual ports */
37126 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37127 #ifdef CONFIG_64BIT
37128- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37129- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37130+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37131+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37132 #else
37133- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37134- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37135+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37136+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37137 #endif
37138 }
37139 netif_receive_skb(skb);
37140@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37141 dev->name);
37142 */
37143 #ifdef CONFIG_64BIT
37144- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37145+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37146 #else
37147- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37148+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37149 #endif
37150 dev_kfree_skb_irq(skb);
37151 }
37152diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37153index 18f7a79..cc3bc24 100644
37154--- a/drivers/staging/octeon/ethernet.c
37155+++ b/drivers/staging/octeon/ethernet.c
37156@@ -259,11 +259,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37157 * since the RX tasklet also increments it.
37158 */
37159 #ifdef CONFIG_64BIT
37160- atomic64_add(rx_status.dropped_packets,
37161- (atomic64_t *)&priv->stats.rx_dropped);
37162+ atomic64_add_unchecked(rx_status.dropped_packets,
37163+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37164 #else
37165- atomic_add(rx_status.dropped_packets,
37166- (atomic_t *)&priv->stats.rx_dropped);
37167+ atomic_add_unchecked(rx_status.dropped_packets,
37168+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
37169 #endif
37170 }
37171
37172diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37173index dc23395..cf7e9b1 100644
37174--- a/drivers/staging/rtl8712/rtl871x_io.h
37175+++ b/drivers/staging/rtl8712/rtl871x_io.h
37176@@ -108,7 +108,7 @@ struct _io_ops {
37177 u8 *pmem);
37178 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37179 u8 *pmem);
37180-};
37181+} __no_const;
37182
37183 struct io_req {
37184 struct list_head list;
37185diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37186index c7b5e8b..783d6cb 100644
37187--- a/drivers/staging/sbe-2t3e3/netdev.c
37188+++ b/drivers/staging/sbe-2t3e3/netdev.c
37189@@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37190 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37191
37192 if (rlen)
37193- if (copy_to_user(data, &resp, rlen))
37194+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37195 return -EFAULT;
37196
37197 return 0;
37198diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c
37199index 42cdafe..2769103 100644
37200--- a/drivers/staging/speakup/speakup_soft.c
37201+++ b/drivers/staging/speakup/speakup_soft.c
37202@@ -241,11 +241,11 @@ static ssize_t softsynth_read(struct file *fp, char *buf, size_t count,
37203 break;
37204 } else if (!initialized) {
37205 if (*init) {
37206- ch = *init;
37207 init++;
37208 } else {
37209 initialized = 1;
37210 }
37211+ ch = *init;
37212 } else {
37213 ch = synth_buffer_getc();
37214 }
37215diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37216index 5d89c0f..9261317 100644
37217--- a/drivers/staging/usbip/usbip_common.h
37218+++ b/drivers/staging/usbip/usbip_common.h
37219@@ -289,7 +289,7 @@ struct usbip_device {
37220 void (*shutdown)(struct usbip_device *);
37221 void (*reset)(struct usbip_device *);
37222 void (*unusable)(struct usbip_device *);
37223- } eh_ops;
37224+ } __no_const eh_ops;
37225 };
37226
37227 #define kthread_get_run(threadfn, data, namefmt, ...) \
37228diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37229index 88b3298..3783eee 100644
37230--- a/drivers/staging/usbip/vhci.h
37231+++ b/drivers/staging/usbip/vhci.h
37232@@ -88,7 +88,7 @@ struct vhci_hcd {
37233 unsigned resuming:1;
37234 unsigned long re_timeout;
37235
37236- atomic_t seqnum;
37237+ atomic_unchecked_t seqnum;
37238
37239 /*
37240 * NOTE:
37241diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37242index f708cba..2de6d72 100644
37243--- a/drivers/staging/usbip/vhci_hcd.c
37244+++ b/drivers/staging/usbip/vhci_hcd.c
37245@@ -488,7 +488,7 @@ static void vhci_tx_urb(struct urb *urb)
37246 return;
37247 }
37248
37249- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37250+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37251 if (priv->seqnum == 0xffff)
37252 dev_info(&urb->dev->dev, "seqnum max\n");
37253
37254@@ -740,7 +740,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37255 return -ENOMEM;
37256 }
37257
37258- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37259+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37260 if (unlink->seqnum == 0xffff)
37261 pr_info("seqnum max\n");
37262
37263@@ -928,7 +928,7 @@ static int vhci_start(struct usb_hcd *hcd)
37264 vdev->rhport = rhport;
37265 }
37266
37267- atomic_set(&vhci->seqnum, 0);
37268+ atomic_set_unchecked(&vhci->seqnum, 0);
37269 spin_lock_init(&vhci->lock);
37270
37271 hcd->power_budget = 0; /* no limit */
37272diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37273index f0eaf04..5a82e06 100644
37274--- a/drivers/staging/usbip/vhci_rx.c
37275+++ b/drivers/staging/usbip/vhci_rx.c
37276@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37277 if (!urb) {
37278 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37279 pr_info("max seqnum %d\n",
37280- atomic_read(&the_controller->seqnum));
37281+ atomic_read_unchecked(&the_controller->seqnum));
37282 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37283 return;
37284 }
37285diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37286index 7735027..30eed13 100644
37287--- a/drivers/staging/vt6655/hostap.c
37288+++ b/drivers/staging/vt6655/hostap.c
37289@@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
37290 *
37291 */
37292
37293+static net_device_ops_no_const apdev_netdev_ops;
37294+
37295 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37296 {
37297 PSDevice apdev_priv;
37298 struct net_device *dev = pDevice->dev;
37299 int ret;
37300- const struct net_device_ops apdev_netdev_ops = {
37301- .ndo_start_xmit = pDevice->tx_80211,
37302- };
37303
37304 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37305
37306@@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37307 *apdev_priv = *pDevice;
37308 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37309
37310+ /* only half broken now */
37311+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37312 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37313
37314 pDevice->apdev->type = ARPHRD_IEEE80211;
37315diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37316index 51b5adf..098e320 100644
37317--- a/drivers/staging/vt6656/hostap.c
37318+++ b/drivers/staging/vt6656/hostap.c
37319@@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
37320 *
37321 */
37322
37323+static net_device_ops_no_const apdev_netdev_ops;
37324+
37325 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37326 {
37327 PSDevice apdev_priv;
37328 struct net_device *dev = pDevice->dev;
37329 int ret;
37330- const struct net_device_ops apdev_netdev_ops = {
37331- .ndo_start_xmit = pDevice->tx_80211,
37332- };
37333
37334 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37335
37336@@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37337 *apdev_priv = *pDevice;
37338 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37339
37340+ /* only half broken now */
37341+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37342 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37343
37344 pDevice->apdev->type = ARPHRD_IEEE80211;
37345diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37346index 7843dfd..3db105f 100644
37347--- a/drivers/staging/wlan-ng/hfa384x_usb.c
37348+++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37349@@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37350
37351 struct usbctlx_completor {
37352 int (*complete) (struct usbctlx_completor *);
37353-};
37354+} __no_const;
37355
37356 static int
37357 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37358diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37359index 1ca66ea..76f1343 100644
37360--- a/drivers/staging/zcache/tmem.c
37361+++ b/drivers/staging/zcache/tmem.c
37362@@ -39,7 +39,7 @@
37363 * A tmem host implementation must use this function to register callbacks
37364 * for memory allocation.
37365 */
37366-static struct tmem_hostops tmem_hostops;
37367+static tmem_hostops_no_const tmem_hostops;
37368
37369 static void tmem_objnode_tree_init(void);
37370
37371@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37372 * A tmem host implementation must use this function to register
37373 * callbacks for a page-accessible memory (PAM) implementation
37374 */
37375-static struct tmem_pamops tmem_pamops;
37376+static tmem_pamops_no_const tmem_pamops;
37377
37378 void tmem_register_pamops(struct tmem_pamops *m)
37379 {
37380diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37381index 0d4aa82..f7832d4 100644
37382--- a/drivers/staging/zcache/tmem.h
37383+++ b/drivers/staging/zcache/tmem.h
37384@@ -180,6 +180,7 @@ struct tmem_pamops {
37385 void (*new_obj)(struct tmem_obj *);
37386 int (*replace_in_obj)(void *, struct tmem_obj *);
37387 };
37388+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37389 extern void tmem_register_pamops(struct tmem_pamops *m);
37390
37391 /* memory allocation methods provided by the host implementation */
37392@@ -189,6 +190,7 @@ struct tmem_hostops {
37393 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37394 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37395 };
37396+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37397 extern void tmem_register_hostops(struct tmem_hostops *m);
37398
37399 /* core tmem accessor functions */
37400diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37401index c6c385f..b23c65d 100644
37402--- a/drivers/target/target_core_transport.c
37403+++ b/drivers/target/target_core_transport.c
37404@@ -1233,7 +1233,7 @@ struct se_device *transport_add_device_to_core_hba(
37405 spin_lock_init(&dev->se_port_lock);
37406 spin_lock_init(&dev->se_tmr_lock);
37407 spin_lock_init(&dev->qf_cmd_lock);
37408- atomic_set(&dev->dev_ordered_id, 0);
37409+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
37410
37411 se_dev_set_default_attribs(dev, dev_limits);
37412
37413@@ -1402,7 +1402,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37414 * Used to determine when ORDERED commands should go from
37415 * Dormant to Active status.
37416 */
37417- cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37418+ cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37419 smp_mb__after_atomic_inc();
37420 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37421 cmd->se_ordered_id, cmd->sam_task_attr,
37422diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
37423index e61cabd..7617d26 100644
37424--- a/drivers/tty/cyclades.c
37425+++ b/drivers/tty/cyclades.c
37426@@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
37427 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
37428 info->port.count);
37429 #endif
37430- info->port.count++;
37431+ atomic_inc(&info->port.count);
37432 #ifdef CY_DEBUG_COUNT
37433 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
37434- current->pid, info->port.count);
37435+ current->pid, atomic_read(&info->port.count));
37436 #endif
37437
37438 /*
37439@@ -3987,7 +3987,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
37440 for (j = 0; j < cy_card[i].nports; j++) {
37441 info = &cy_card[i].ports[j];
37442
37443- if (info->port.count) {
37444+ if (atomic_read(&info->port.count)) {
37445 /* XXX is the ldisc num worth this? */
37446 struct tty_struct *tty;
37447 struct tty_ldisc *ld;
37448diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
37449index 2d691eb..be02ebd 100644
37450--- a/drivers/tty/hvc/hvc_console.c
37451+++ b/drivers/tty/hvc/hvc_console.c
37452@@ -315,7 +315,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
37453
37454 spin_lock_irqsave(&hp->port.lock, flags);
37455 /* Check and then increment for fast path open. */
37456- if (hp->port.count++ > 0) {
37457+ if (atomic_inc_return(&hp->port.count) > 1) {
37458 spin_unlock_irqrestore(&hp->port.lock, flags);
37459 hvc_kick();
37460 return 0;
37461@@ -366,7 +366,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37462
37463 spin_lock_irqsave(&hp->port.lock, flags);
37464
37465- if (--hp->port.count == 0) {
37466+ if (atomic_dec_return(&hp->port.count) == 0) {
37467 spin_unlock_irqrestore(&hp->port.lock, flags);
37468 /* We are done with the tty pointer now. */
37469 tty_port_tty_set(&hp->port, NULL);
37470@@ -384,9 +384,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37471 */
37472 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
37473 } else {
37474- if (hp->port.count < 0)
37475+ if (atomic_read(&hp->port.count) < 0)
37476 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
37477- hp->vtermno, hp->port.count);
37478+ hp->vtermno, atomic_read(&hp->port.count));
37479 spin_unlock_irqrestore(&hp->port.lock, flags);
37480 }
37481
37482@@ -412,13 +412,13 @@ static void hvc_hangup(struct tty_struct *tty)
37483 * open->hangup case this can be called after the final close so prevent
37484 * that from happening for now.
37485 */
37486- if (hp->port.count <= 0) {
37487+ if (atomic_read(&hp->port.count) <= 0) {
37488 spin_unlock_irqrestore(&hp->port.lock, flags);
37489 return;
37490 }
37491
37492- temp_open_count = hp->port.count;
37493- hp->port.count = 0;
37494+ temp_open_count = atomic_read(&hp->port.count);
37495+ atomic_set(&hp->port.count, 0);
37496 spin_unlock_irqrestore(&hp->port.lock, flags);
37497 tty_port_tty_set(&hp->port, NULL);
37498
37499@@ -471,7 +471,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
37500 return -EPIPE;
37501
37502 /* FIXME what's this (unprotected) check for? */
37503- if (hp->port.count <= 0)
37504+ if (atomic_read(&hp->port.count) <= 0)
37505 return -EIO;
37506
37507 spin_lock_irqsave(&hp->lock, flags);
37508diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37509index d56788c..12d8f85 100644
37510--- a/drivers/tty/hvc/hvcs.c
37511+++ b/drivers/tty/hvc/hvcs.c
37512@@ -83,6 +83,7 @@
37513 #include <asm/hvcserver.h>
37514 #include <asm/uaccess.h>
37515 #include <asm/vio.h>
37516+#include <asm/local.h>
37517
37518 /*
37519 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37520@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37521
37522 spin_lock_irqsave(&hvcsd->lock, flags);
37523
37524- if (hvcsd->port.count > 0) {
37525+ if (atomic_read(&hvcsd->port.count) > 0) {
37526 spin_unlock_irqrestore(&hvcsd->lock, flags);
37527 printk(KERN_INFO "HVCS: vterm state unchanged. "
37528 "The hvcs device node is still in use.\n");
37529@@ -1134,7 +1135,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37530 if ((retval = hvcs_partner_connect(hvcsd)))
37531 goto error_release;
37532
37533- hvcsd->port.count = 1;
37534+ atomic_set(&hvcsd->port.count, 1);
37535 hvcsd->port.tty = tty;
37536 tty->driver_data = hvcsd;
37537
37538@@ -1168,7 +1169,7 @@ fast_open:
37539
37540 spin_lock_irqsave(&hvcsd->lock, flags);
37541 tty_port_get(&hvcsd->port);
37542- hvcsd->port.count++;
37543+ atomic_inc(&hvcsd->port.count);
37544 hvcsd->todo_mask |= HVCS_SCHED_READ;
37545 spin_unlock_irqrestore(&hvcsd->lock, flags);
37546
37547@@ -1212,7 +1213,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37548 hvcsd = tty->driver_data;
37549
37550 spin_lock_irqsave(&hvcsd->lock, flags);
37551- if (--hvcsd->port.count == 0) {
37552+ if (atomic_dec_and_test(&hvcsd->port.count)) {
37553
37554 vio_disable_interrupts(hvcsd->vdev);
37555
37556@@ -1238,10 +1239,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37557 free_irq(irq, hvcsd);
37558 tty_port_put(&hvcsd->port);
37559 return;
37560- } else if (hvcsd->port.count < 0) {
37561+ } else if (atomic_read(&hvcsd->port.count) < 0) {
37562 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
37563 " is missmanaged.\n",
37564- hvcsd->vdev->unit_address, hvcsd->port.count);
37565+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
37566 }
37567
37568 spin_unlock_irqrestore(&hvcsd->lock, flags);
37569@@ -1257,7 +1258,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37570
37571 spin_lock_irqsave(&hvcsd->lock, flags);
37572 /* Preserve this so that we know how many kref refs to put */
37573- temp_open_count = hvcsd->port.count;
37574+ temp_open_count = atomic_read(&hvcsd->port.count);
37575
37576 /*
37577 * Don't kref put inside the spinlock because the destruction
37578@@ -1272,7 +1273,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37579 tty->driver_data = NULL;
37580 hvcsd->port.tty = NULL;
37581
37582- hvcsd->port.count = 0;
37583+ atomic_set(&hvcsd->port.count, 0);
37584
37585 /* This will drop any buffered data on the floor which is OK in a hangup
37586 * scenario. */
37587@@ -1343,7 +1344,7 @@ static int hvcs_write(struct tty_struct *tty,
37588 * the middle of a write operation? This is a crummy place to do this
37589 * but we want to keep it all in the spinlock.
37590 */
37591- if (hvcsd->port.count <= 0) {
37592+ if (atomic_read(&hvcsd->port.count) <= 0) {
37593 spin_unlock_irqrestore(&hvcsd->lock, flags);
37594 return -ENODEV;
37595 }
37596@@ -1417,7 +1418,7 @@ static int hvcs_write_room(struct tty_struct *tty)
37597 {
37598 struct hvcs_struct *hvcsd = tty->driver_data;
37599
37600- if (!hvcsd || hvcsd->port.count <= 0)
37601+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
37602 return 0;
37603
37604 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
37605diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
37606index f8b5fa0..4ba9f89 100644
37607--- a/drivers/tty/ipwireless/tty.c
37608+++ b/drivers/tty/ipwireless/tty.c
37609@@ -29,6 +29,7 @@
37610 #include <linux/tty_driver.h>
37611 #include <linux/tty_flip.h>
37612 #include <linux/uaccess.h>
37613+#include <asm/local.h>
37614
37615 #include "tty.h"
37616 #include "network.h"
37617@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37618 mutex_unlock(&tty->ipw_tty_mutex);
37619 return -ENODEV;
37620 }
37621- if (tty->port.count == 0)
37622+ if (atomic_read(&tty->port.count) == 0)
37623 tty->tx_bytes_queued = 0;
37624
37625- tty->port.count++;
37626+ atomic_inc(&tty->port.count);
37627
37628 tty->port.tty = linux_tty;
37629 linux_tty->driver_data = tty;
37630@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37631
37632 static void do_ipw_close(struct ipw_tty *tty)
37633 {
37634- tty->port.count--;
37635-
37636- if (tty->port.count == 0) {
37637+ if (atomic_dec_return(&tty->port.count) == 0) {
37638 struct tty_struct *linux_tty = tty->port.tty;
37639
37640 if (linux_tty != NULL) {
37641@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
37642 return;
37643
37644 mutex_lock(&tty->ipw_tty_mutex);
37645- if (tty->port.count == 0) {
37646+ if (atomic_read(&tty->port.count) == 0) {
37647 mutex_unlock(&tty->ipw_tty_mutex);
37648 return;
37649 }
37650@@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
37651 return;
37652 }
37653
37654- if (!tty->port.count) {
37655+ if (!atomic_read(&tty->port.count)) {
37656 mutex_unlock(&tty->ipw_tty_mutex);
37657 return;
37658 }
37659@@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
37660 return -ENODEV;
37661
37662 mutex_lock(&tty->ipw_tty_mutex);
37663- if (!tty->port.count) {
37664+ if (!atomic_read(&tty->port.count)) {
37665 mutex_unlock(&tty->ipw_tty_mutex);
37666 return -EINVAL;
37667 }
37668@@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
37669 if (!tty)
37670 return -ENODEV;
37671
37672- if (!tty->port.count)
37673+ if (!atomic_read(&tty->port.count))
37674 return -EINVAL;
37675
37676 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
37677@@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
37678 if (!tty)
37679 return 0;
37680
37681- if (!tty->port.count)
37682+ if (!atomic_read(&tty->port.count))
37683 return 0;
37684
37685 return tty->tx_bytes_queued;
37686@@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
37687 if (!tty)
37688 return -ENODEV;
37689
37690- if (!tty->port.count)
37691+ if (!atomic_read(&tty->port.count))
37692 return -EINVAL;
37693
37694 return get_control_lines(tty);
37695@@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
37696 if (!tty)
37697 return -ENODEV;
37698
37699- if (!tty->port.count)
37700+ if (!atomic_read(&tty->port.count))
37701 return -EINVAL;
37702
37703 return set_control_lines(tty, set, clear);
37704@@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
37705 if (!tty)
37706 return -ENODEV;
37707
37708- if (!tty->port.count)
37709+ if (!atomic_read(&tty->port.count))
37710 return -EINVAL;
37711
37712 /* FIXME: Exactly how is the tty object locked here .. */
37713@@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
37714 * are gone */
37715 mutex_lock(&ttyj->ipw_tty_mutex);
37716 }
37717- while (ttyj->port.count)
37718+ while (atomic_read(&ttyj->port.count))
37719 do_ipw_close(ttyj);
37720 ipwireless_disassociate_network_ttys(network,
37721 ttyj->channel_idx);
37722diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
37723index 324467d..504cc25 100644
37724--- a/drivers/tty/moxa.c
37725+++ b/drivers/tty/moxa.c
37726@@ -1172,7 +1172,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
37727 }
37728
37729 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
37730- ch->port.count++;
37731+ atomic_inc(&ch->port.count);
37732 tty->driver_data = ch;
37733 tty_port_tty_set(&ch->port, tty);
37734 mutex_lock(&ch->port.mutex);
37735diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
37736index c43b683..4dab83e 100644
37737--- a/drivers/tty/n_gsm.c
37738+++ b/drivers/tty/n_gsm.c
37739@@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
37740 kref_init(&dlci->ref);
37741 mutex_init(&dlci->mutex);
37742 dlci->fifo = &dlci->_fifo;
37743- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
37744+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
37745 kfree(dlci);
37746 return NULL;
37747 }
37748@@ -2895,7 +2895,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
37749 if (dlci == NULL)
37750 return -ENOMEM;
37751 port = &dlci->port;
37752- port->count++;
37753+ atomic_inc(&port->count);
37754 tty->driver_data = dlci;
37755 dlci_get(dlci);
37756 dlci_get(dlci->gsm->dlci[0]);
37757diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
37758index ee1c268..0e97caf 100644
37759--- a/drivers/tty/n_tty.c
37760+++ b/drivers/tty/n_tty.c
37761@@ -2123,6 +2123,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
37762 {
37763 *ops = tty_ldisc_N_TTY;
37764 ops->owner = NULL;
37765- ops->refcount = ops->flags = 0;
37766+ atomic_set(&ops->refcount, 0);
37767+ ops->flags = 0;
37768 }
37769 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
37770diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
37771index 5505ffc..7affff9 100644
37772--- a/drivers/tty/pty.c
37773+++ b/drivers/tty/pty.c
37774@@ -718,8 +718,10 @@ static void __init unix98_pty_init(void)
37775 panic("Couldn't register Unix98 pts driver");
37776
37777 /* Now create the /dev/ptmx special device */
37778+ pax_open_kernel();
37779 tty_default_fops(&ptmx_fops);
37780- ptmx_fops.open = ptmx_open;
37781+ *(void **)&ptmx_fops.open = ptmx_open;
37782+ pax_close_kernel();
37783
37784 cdev_init(&ptmx_cdev, &ptmx_fops);
37785 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
37786diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
37787index 777d5f9..56d67ca 100644
37788--- a/drivers/tty/rocket.c
37789+++ b/drivers/tty/rocket.c
37790@@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
37791 tty->driver_data = info;
37792 tty_port_tty_set(port, tty);
37793
37794- if (port->count++ == 0) {
37795+ if (atomic_inc_return(&port->count) == 1) {
37796 atomic_inc(&rp_num_ports_open);
37797
37798 #ifdef ROCKET_DEBUG_OPEN
37799@@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
37800 #endif
37801 }
37802 #ifdef ROCKET_DEBUG_OPEN
37803- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
37804+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
37805 #endif
37806
37807 /*
37808@@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
37809 spin_unlock_irqrestore(&info->port.lock, flags);
37810 return;
37811 }
37812- if (info->port.count)
37813+ if (atomic_read(&info->port.count))
37814 atomic_dec(&rp_num_ports_open);
37815 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
37816 spin_unlock_irqrestore(&info->port.lock, flags);
37817diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
37818index 2b42a01..32a2ed3 100644
37819--- a/drivers/tty/serial/kgdboc.c
37820+++ b/drivers/tty/serial/kgdboc.c
37821@@ -24,8 +24,9 @@
37822 #define MAX_CONFIG_LEN 40
37823
37824 static struct kgdb_io kgdboc_io_ops;
37825+static struct kgdb_io kgdboc_io_ops_console;
37826
37827-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
37828+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
37829 static int configured = -1;
37830
37831 static char config[MAX_CONFIG_LEN];
37832@@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
37833 kgdboc_unregister_kbd();
37834 if (configured == 1)
37835 kgdb_unregister_io_module(&kgdboc_io_ops);
37836+ else if (configured == 2)
37837+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
37838 }
37839
37840 static int configure_kgdboc(void)
37841@@ -157,13 +160,13 @@ static int configure_kgdboc(void)
37842 int err;
37843 char *cptr = config;
37844 struct console *cons;
37845+ int is_console = 0;
37846
37847 err = kgdboc_option_setup(config);
37848 if (err || !strlen(config) || isspace(config[0]))
37849 goto noconfig;
37850
37851 err = -ENODEV;
37852- kgdboc_io_ops.is_console = 0;
37853 kgdb_tty_driver = NULL;
37854
37855 kgdboc_use_kms = 0;
37856@@ -184,7 +187,7 @@ static int configure_kgdboc(void)
37857 int idx;
37858 if (cons->device && cons->device(cons, &idx) == p &&
37859 idx == tty_line) {
37860- kgdboc_io_ops.is_console = 1;
37861+ is_console = 1;
37862 break;
37863 }
37864 cons = cons->next;
37865@@ -194,12 +197,16 @@ static int configure_kgdboc(void)
37866 kgdb_tty_line = tty_line;
37867
37868 do_register:
37869- err = kgdb_register_io_module(&kgdboc_io_ops);
37870+ if (is_console) {
37871+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
37872+ configured = 2;
37873+ } else {
37874+ err = kgdb_register_io_module(&kgdboc_io_ops);
37875+ configured = 1;
37876+ }
37877 if (err)
37878 goto noconfig;
37879
37880- configured = 1;
37881-
37882 return 0;
37883
37884 noconfig:
37885@@ -213,7 +220,7 @@ noconfig:
37886 static int __init init_kgdboc(void)
37887 {
37888 /* Already configured? */
37889- if (configured == 1)
37890+ if (configured >= 1)
37891 return 0;
37892
37893 return configure_kgdboc();
37894@@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
37895 if (config[len - 1] == '\n')
37896 config[len - 1] = '\0';
37897
37898- if (configured == 1)
37899+ if (configured >= 1)
37900 cleanup_kgdboc();
37901
37902 /* Go and configure with the new params. */
37903@@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
37904 .post_exception = kgdboc_post_exp_handler,
37905 };
37906
37907+static struct kgdb_io kgdboc_io_ops_console = {
37908+ .name = "kgdboc",
37909+ .read_char = kgdboc_get_char,
37910+ .write_char = kgdboc_put_char,
37911+ .pre_exception = kgdboc_pre_exp_handler,
37912+ .post_exception = kgdboc_post_exp_handler,
37913+ .is_console = 1
37914+};
37915+
37916 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
37917 /* This is only available if kgdboc is a built in for early debugging */
37918 static int __init kgdboc_early_init(char *opt)
37919diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
37920index 246b823..9e0db76 100644
37921--- a/drivers/tty/serial/serial_core.c
37922+++ b/drivers/tty/serial/serial_core.c
37923@@ -1392,7 +1392,7 @@ static void uart_hangup(struct tty_struct *tty)
37924 uart_flush_buffer(tty);
37925 uart_shutdown(tty, state);
37926 spin_lock_irqsave(&port->lock, flags);
37927- port->count = 0;
37928+ atomic_set(&port->count, 0);
37929 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
37930 spin_unlock_irqrestore(&port->lock, flags);
37931 tty_port_tty_set(port, NULL);
37932@@ -1488,7 +1488,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
37933 goto end;
37934 }
37935
37936- port->count++;
37937+ atomic_inc(&port->count);
37938 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
37939 retval = -ENXIO;
37940 goto err_dec_count;
37941@@ -1515,7 +1515,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
37942 /*
37943 * Make sure the device is in D0 state.
37944 */
37945- if (port->count == 1)
37946+ if (atomic_read(&port->count) == 1)
37947 uart_change_pm(state, 0);
37948
37949 /*
37950@@ -1533,7 +1533,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
37951 end:
37952 return retval;
37953 err_dec_count:
37954- port->count--;
37955+ atomic_inc(&port->count);
37956 mutex_unlock(&port->mutex);
37957 goto end;
37958 }
37959diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
37960index 593d40a..bdc61f3 100644
37961--- a/drivers/tty/synclink.c
37962+++ b/drivers/tty/synclink.c
37963@@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
37964
37965 if (debug_level >= DEBUG_LEVEL_INFO)
37966 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
37967- __FILE__,__LINE__, info->device_name, info->port.count);
37968+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
37969
37970 if (tty_port_close_start(&info->port, tty, filp) == 0)
37971 goto cleanup;
37972@@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
37973 cleanup:
37974 if (debug_level >= DEBUG_LEVEL_INFO)
37975 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
37976- tty->driver->name, info->port.count);
37977+ tty->driver->name, atomic_read(&info->port.count));
37978
37979 } /* end of mgsl_close() */
37980
37981@@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
37982
37983 mgsl_flush_buffer(tty);
37984 shutdown(info);
37985-
37986- info->port.count = 0;
37987+
37988+ atomic_set(&info->port.count, 0);
37989 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
37990 info->port.tty = NULL;
37991
37992@@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
37993
37994 if (debug_level >= DEBUG_LEVEL_INFO)
37995 printk("%s(%d):block_til_ready before block on %s count=%d\n",
37996- __FILE__,__LINE__, tty->driver->name, port->count );
37997+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
37998
37999 spin_lock_irqsave(&info->irq_spinlock, flags);
38000 if (!tty_hung_up_p(filp)) {
38001 extra_count = true;
38002- port->count--;
38003+ atomic_dec(&port->count);
38004 }
38005 spin_unlock_irqrestore(&info->irq_spinlock, flags);
38006 port->blocked_open++;
38007@@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38008
38009 if (debug_level >= DEBUG_LEVEL_INFO)
38010 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
38011- __FILE__,__LINE__, tty->driver->name, port->count );
38012+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38013
38014 tty_unlock();
38015 schedule();
38016@@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38017
38018 /* FIXME: Racy on hangup during close wait */
38019 if (extra_count)
38020- port->count++;
38021+ atomic_inc(&port->count);
38022 port->blocked_open--;
38023
38024 if (debug_level >= DEBUG_LEVEL_INFO)
38025 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
38026- __FILE__,__LINE__, tty->driver->name, port->count );
38027+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38028
38029 if (!retval)
38030 port->flags |= ASYNC_NORMAL_ACTIVE;
38031@@ -3398,7 +3398,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38032
38033 if (debug_level >= DEBUG_LEVEL_INFO)
38034 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
38035- __FILE__,__LINE__,tty->driver->name, info->port.count);
38036+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38037
38038 /* If port is closing, signal caller to try again */
38039 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38040@@ -3417,10 +3417,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38041 spin_unlock_irqrestore(&info->netlock, flags);
38042 goto cleanup;
38043 }
38044- info->port.count++;
38045+ atomic_inc(&info->port.count);
38046 spin_unlock_irqrestore(&info->netlock, flags);
38047
38048- if (info->port.count == 1) {
38049+ if (atomic_read(&info->port.count) == 1) {
38050 /* 1st open on this device, init hardware */
38051 retval = startup(info);
38052 if (retval < 0)
38053@@ -3444,8 +3444,8 @@ cleanup:
38054 if (retval) {
38055 if (tty->count == 1)
38056 info->port.tty = NULL; /* tty layer will release tty struct */
38057- if(info->port.count)
38058- info->port.count--;
38059+ if (atomic_read(&info->port.count))
38060+ atomic_dec(&info->port.count);
38061 }
38062
38063 return retval;
38064@@ -7653,7 +7653,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38065 unsigned short new_crctype;
38066
38067 /* return error if TTY interface open */
38068- if (info->port.count)
38069+ if (atomic_read(&info->port.count))
38070 return -EBUSY;
38071
38072 switch (encoding)
38073@@ -7748,7 +7748,7 @@ static int hdlcdev_open(struct net_device *dev)
38074
38075 /* arbitrate between network and tty opens */
38076 spin_lock_irqsave(&info->netlock, flags);
38077- if (info->port.count != 0 || info->netcount != 0) {
38078+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38079 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38080 spin_unlock_irqrestore(&info->netlock, flags);
38081 return -EBUSY;
38082@@ -7834,7 +7834,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38083 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38084
38085 /* return error if TTY interface open */
38086- if (info->port.count)
38087+ if (atomic_read(&info->port.count))
38088 return -EBUSY;
38089
38090 if (cmd != SIOCWANDEV)
38091diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
38092index aa1debf..9297a16 100644
38093--- a/drivers/tty/synclink_gt.c
38094+++ b/drivers/tty/synclink_gt.c
38095@@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38096 tty->driver_data = info;
38097 info->port.tty = tty;
38098
38099- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
38100+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
38101
38102 /* If port is closing, signal caller to try again */
38103 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38104@@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38105 mutex_unlock(&info->port.mutex);
38106 goto cleanup;
38107 }
38108- info->port.count++;
38109+ atomic_inc(&info->port.count);
38110 spin_unlock_irqrestore(&info->netlock, flags);
38111
38112- if (info->port.count == 1) {
38113+ if (atomic_read(&info->port.count) == 1) {
38114 /* 1st open on this device, init hardware */
38115 retval = startup(info);
38116 if (retval < 0) {
38117@@ -716,8 +716,8 @@ cleanup:
38118 if (retval) {
38119 if (tty->count == 1)
38120 info->port.tty = NULL; /* tty layer will release tty struct */
38121- if(info->port.count)
38122- info->port.count--;
38123+ if(atomic_read(&info->port.count))
38124+ atomic_dec(&info->port.count);
38125 }
38126
38127 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
38128@@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38129
38130 if (sanity_check(info, tty->name, "close"))
38131 return;
38132- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
38133+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
38134
38135 if (tty_port_close_start(&info->port, tty, filp) == 0)
38136 goto cleanup;
38137@@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38138 tty_port_close_end(&info->port, tty);
38139 info->port.tty = NULL;
38140 cleanup:
38141- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
38142+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
38143 }
38144
38145 static void hangup(struct tty_struct *tty)
38146@@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
38147 shutdown(info);
38148
38149 spin_lock_irqsave(&info->port.lock, flags);
38150- info->port.count = 0;
38151+ atomic_set(&info->port.count, 0);
38152 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38153 info->port.tty = NULL;
38154 spin_unlock_irqrestore(&info->port.lock, flags);
38155@@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38156 unsigned short new_crctype;
38157
38158 /* return error if TTY interface open */
38159- if (info->port.count)
38160+ if (atomic_read(&info->port.count))
38161 return -EBUSY;
38162
38163 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
38164@@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
38165
38166 /* arbitrate between network and tty opens */
38167 spin_lock_irqsave(&info->netlock, flags);
38168- if (info->port.count != 0 || info->netcount != 0) {
38169+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38170 DBGINFO(("%s hdlc_open busy\n", dev->name));
38171 spin_unlock_irqrestore(&info->netlock, flags);
38172 return -EBUSY;
38173@@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38174 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
38175
38176 /* return error if TTY interface open */
38177- if (info->port.count)
38178+ if (atomic_read(&info->port.count))
38179 return -EBUSY;
38180
38181 if (cmd != SIOCWANDEV)
38182@@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
38183 if (port == NULL)
38184 continue;
38185 spin_lock(&port->lock);
38186- if ((port->port.count || port->netcount) &&
38187+ if ((atomic_read(&port->port.count) || port->netcount) &&
38188 port->pending_bh && !port->bh_running &&
38189 !port->bh_requested) {
38190 DBGISR(("%s bh queued\n", port->device_name));
38191@@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38192 spin_lock_irqsave(&info->lock, flags);
38193 if (!tty_hung_up_p(filp)) {
38194 extra_count = true;
38195- port->count--;
38196+ atomic_dec(&port->count);
38197 }
38198 spin_unlock_irqrestore(&info->lock, flags);
38199 port->blocked_open++;
38200@@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38201 remove_wait_queue(&port->open_wait, &wait);
38202
38203 if (extra_count)
38204- port->count++;
38205+ atomic_inc(&port->count);
38206 port->blocked_open--;
38207
38208 if (!retval)
38209diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
38210index a3dddc1..8905ab2 100644
38211--- a/drivers/tty/synclinkmp.c
38212+++ b/drivers/tty/synclinkmp.c
38213@@ -742,7 +742,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38214
38215 if (debug_level >= DEBUG_LEVEL_INFO)
38216 printk("%s(%d):%s open(), old ref count = %d\n",
38217- __FILE__,__LINE__,tty->driver->name, info->port.count);
38218+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38219
38220 /* If port is closing, signal caller to try again */
38221 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38222@@ -761,10 +761,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38223 spin_unlock_irqrestore(&info->netlock, flags);
38224 goto cleanup;
38225 }
38226- info->port.count++;
38227+ atomic_inc(&info->port.count);
38228 spin_unlock_irqrestore(&info->netlock, flags);
38229
38230- if (info->port.count == 1) {
38231+ if (atomic_read(&info->port.count) == 1) {
38232 /* 1st open on this device, init hardware */
38233 retval = startup(info);
38234 if (retval < 0)
38235@@ -788,8 +788,8 @@ cleanup:
38236 if (retval) {
38237 if (tty->count == 1)
38238 info->port.tty = NULL; /* tty layer will release tty struct */
38239- if(info->port.count)
38240- info->port.count--;
38241+ if(atomic_read(&info->port.count))
38242+ atomic_dec(&info->port.count);
38243 }
38244
38245 return retval;
38246@@ -807,7 +807,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38247
38248 if (debug_level >= DEBUG_LEVEL_INFO)
38249 printk("%s(%d):%s close() entry, count=%d\n",
38250- __FILE__,__LINE__, info->device_name, info->port.count);
38251+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38252
38253 if (tty_port_close_start(&info->port, tty, filp) == 0)
38254 goto cleanup;
38255@@ -826,7 +826,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38256 cleanup:
38257 if (debug_level >= DEBUG_LEVEL_INFO)
38258 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
38259- tty->driver->name, info->port.count);
38260+ tty->driver->name, atomic_read(&info->port.count));
38261 }
38262
38263 /* Called by tty_hangup() when a hangup is signaled.
38264@@ -849,7 +849,7 @@ static void hangup(struct tty_struct *tty)
38265 shutdown(info);
38266
38267 spin_lock_irqsave(&info->port.lock, flags);
38268- info->port.count = 0;
38269+ atomic_set(&info->port.count, 0);
38270 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38271 info->port.tty = NULL;
38272 spin_unlock_irqrestore(&info->port.lock, flags);
38273@@ -1557,7 +1557,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38274 unsigned short new_crctype;
38275
38276 /* return error if TTY interface open */
38277- if (info->port.count)
38278+ if (atomic_read(&info->port.count))
38279 return -EBUSY;
38280
38281 switch (encoding)
38282@@ -1652,7 +1652,7 @@ static int hdlcdev_open(struct net_device *dev)
38283
38284 /* arbitrate between network and tty opens */
38285 spin_lock_irqsave(&info->netlock, flags);
38286- if (info->port.count != 0 || info->netcount != 0) {
38287+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38288 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38289 spin_unlock_irqrestore(&info->netlock, flags);
38290 return -EBUSY;
38291@@ -1738,7 +1738,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38292 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38293
38294 /* return error if TTY interface open */
38295- if (info->port.count)
38296+ if (atomic_read(&info->port.count))
38297 return -EBUSY;
38298
38299 if (cmd != SIOCWANDEV)
38300@@ -2623,7 +2623,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
38301 * do not request bottom half processing if the
38302 * device is not open in a normal mode.
38303 */
38304- if ( port && (port->port.count || port->netcount) &&
38305+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
38306 port->pending_bh && !port->bh_running &&
38307 !port->bh_requested ) {
38308 if ( debug_level >= DEBUG_LEVEL_ISR )
38309@@ -3321,12 +3321,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38310
38311 if (debug_level >= DEBUG_LEVEL_INFO)
38312 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
38313- __FILE__,__LINE__, tty->driver->name, port->count );
38314+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38315
38316 spin_lock_irqsave(&info->lock, flags);
38317 if (!tty_hung_up_p(filp)) {
38318 extra_count = true;
38319- port->count--;
38320+ atomic_dec(&port->count);
38321 }
38322 spin_unlock_irqrestore(&info->lock, flags);
38323 port->blocked_open++;
38324@@ -3355,7 +3355,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38325
38326 if (debug_level >= DEBUG_LEVEL_INFO)
38327 printk("%s(%d):%s block_til_ready() count=%d\n",
38328- __FILE__,__LINE__, tty->driver->name, port->count );
38329+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38330
38331 tty_unlock();
38332 schedule();
38333@@ -3366,12 +3366,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38334 remove_wait_queue(&port->open_wait, &wait);
38335
38336 if (extra_count)
38337- port->count++;
38338+ atomic_inc(&port->count);
38339 port->blocked_open--;
38340
38341 if (debug_level >= DEBUG_LEVEL_INFO)
38342 printk("%s(%d):%s block_til_ready() after, count=%d\n",
38343- __FILE__,__LINE__, tty->driver->name, port->count );
38344+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38345
38346 if (!retval)
38347 port->flags |= ASYNC_NORMAL_ACTIVE;
38348diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38349index 05728894..b9d44c6 100644
38350--- a/drivers/tty/sysrq.c
38351+++ b/drivers/tty/sysrq.c
38352@@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38353 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38354 size_t count, loff_t *ppos)
38355 {
38356- if (count) {
38357+ if (count && capable(CAP_SYS_ADMIN)) {
38358 char c;
38359
38360 if (get_user(c, buf))
38361diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38362index b425c79..08a3f06 100644
38363--- a/drivers/tty/tty_io.c
38364+++ b/drivers/tty/tty_io.c
38365@@ -3283,7 +3283,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38366
38367 void tty_default_fops(struct file_operations *fops)
38368 {
38369- *fops = tty_fops;
38370+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38371 }
38372
38373 /*
38374diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38375index 9911eb6..5abe0e1 100644
38376--- a/drivers/tty/tty_ldisc.c
38377+++ b/drivers/tty/tty_ldisc.c
38378@@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38379 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38380 struct tty_ldisc_ops *ldo = ld->ops;
38381
38382- ldo->refcount--;
38383+ atomic_dec(&ldo->refcount);
38384 module_put(ldo->owner);
38385 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38386
38387@@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38388 spin_lock_irqsave(&tty_ldisc_lock, flags);
38389 tty_ldiscs[disc] = new_ldisc;
38390 new_ldisc->num = disc;
38391- new_ldisc->refcount = 0;
38392+ atomic_set(&new_ldisc->refcount, 0);
38393 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38394
38395 return ret;
38396@@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
38397 return -EINVAL;
38398
38399 spin_lock_irqsave(&tty_ldisc_lock, flags);
38400- if (tty_ldiscs[disc]->refcount)
38401+ if (atomic_read(&tty_ldiscs[disc]->refcount))
38402 ret = -EBUSY;
38403 else
38404 tty_ldiscs[disc] = NULL;
38405@@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38406 if (ldops) {
38407 ret = ERR_PTR(-EAGAIN);
38408 if (try_module_get(ldops->owner)) {
38409- ldops->refcount++;
38410+ atomic_inc(&ldops->refcount);
38411 ret = ldops;
38412 }
38413 }
38414@@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38415 unsigned long flags;
38416
38417 spin_lock_irqsave(&tty_ldisc_lock, flags);
38418- ldops->refcount--;
38419+ atomic_dec(&ldops->refcount);
38420 module_put(ldops->owner);
38421 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38422 }
38423diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
38424index bf6e238..d401c04 100644
38425--- a/drivers/tty/tty_port.c
38426+++ b/drivers/tty/tty_port.c
38427@@ -138,7 +138,7 @@ void tty_port_hangup(struct tty_port *port)
38428 unsigned long flags;
38429
38430 spin_lock_irqsave(&port->lock, flags);
38431- port->count = 0;
38432+ atomic_set(&port->count, 0);
38433 port->flags &= ~ASYNC_NORMAL_ACTIVE;
38434 if (port->tty) {
38435 set_bit(TTY_IO_ERROR, &port->tty->flags);
38436@@ -264,7 +264,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38437 /* The port lock protects the port counts */
38438 spin_lock_irqsave(&port->lock, flags);
38439 if (!tty_hung_up_p(filp))
38440- port->count--;
38441+ atomic_dec(&port->count);
38442 port->blocked_open++;
38443 spin_unlock_irqrestore(&port->lock, flags);
38444
38445@@ -306,7 +306,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38446 we must not mess that up further */
38447 spin_lock_irqsave(&port->lock, flags);
38448 if (!tty_hung_up_p(filp))
38449- port->count++;
38450+ atomic_inc(&port->count);
38451 port->blocked_open--;
38452 if (retval == 0)
38453 port->flags |= ASYNC_NORMAL_ACTIVE;
38454@@ -326,19 +326,19 @@ int tty_port_close_start(struct tty_port *port,
38455 return 0;
38456 }
38457
38458- if (tty->count == 1 && port->count != 1) {
38459+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
38460 printk(KERN_WARNING
38461 "tty_port_close_start: tty->count = 1 port count = %d.\n",
38462- port->count);
38463- port->count = 1;
38464+ atomic_read(&port->count));
38465+ atomic_set(&port->count, 1);
38466 }
38467- if (--port->count < 0) {
38468+ if (atomic_dec_return(&port->count) < 0) {
38469 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
38470- port->count);
38471- port->count = 0;
38472+ atomic_read(&port->count));
38473+ atomic_set(&port->count, 0);
38474 }
38475
38476- if (port->count) {
38477+ if (atomic_read(&port->count)) {
38478 spin_unlock_irqrestore(&port->lock, flags);
38479 if (port->ops->drop)
38480 port->ops->drop(port);
38481@@ -418,7 +418,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
38482 {
38483 spin_lock_irq(&port->lock);
38484 if (!tty_hung_up_p(filp))
38485- ++port->count;
38486+ atomic_inc(&port->count);
38487 spin_unlock_irq(&port->lock);
38488 tty_port_tty_set(port, tty);
38489
38490diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
38491index 48cc6f2..85584dd 100644
38492--- a/drivers/tty/vt/keyboard.c
38493+++ b/drivers/tty/vt/keyboard.c
38494@@ -659,6 +659,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
38495 kbd->kbdmode == VC_OFF) &&
38496 value != KVAL(K_SAK))
38497 return; /* SAK is allowed even in raw mode */
38498+
38499+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
38500+ {
38501+ void *func = fn_handler[value];
38502+ if (func == fn_show_state || func == fn_show_ptregs ||
38503+ func == fn_show_mem)
38504+ return;
38505+ }
38506+#endif
38507+
38508 fn_handler[value](vc);
38509 }
38510
38511@@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38512 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
38513 return -EFAULT;
38514
38515- if (!capable(CAP_SYS_TTY_CONFIG))
38516- perm = 0;
38517-
38518 switch (cmd) {
38519 case KDGKBENT:
38520 /* Ensure another thread doesn't free it under us */
38521@@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38522 spin_unlock_irqrestore(&kbd_event_lock, flags);
38523 return put_user(val, &user_kbe->kb_value);
38524 case KDSKBENT:
38525+ if (!capable(CAP_SYS_TTY_CONFIG))
38526+ perm = 0;
38527+
38528 if (!perm)
38529 return -EPERM;
38530 if (!i && v == K_NOSUCHMAP) {
38531@@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38532 int i, j, k;
38533 int ret;
38534
38535- if (!capable(CAP_SYS_TTY_CONFIG))
38536- perm = 0;
38537-
38538 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
38539 if (!kbs) {
38540 ret = -ENOMEM;
38541@@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38542 kfree(kbs);
38543 return ((p && *p) ? -EOVERFLOW : 0);
38544 case KDSKBSENT:
38545+ if (!capable(CAP_SYS_TTY_CONFIG))
38546+ perm = 0;
38547+
38548 if (!perm) {
38549 ret = -EPERM;
38550 goto reterr;
38551diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
38552index a783d53..cb30d94 100644
38553--- a/drivers/uio/uio.c
38554+++ b/drivers/uio/uio.c
38555@@ -25,6 +25,7 @@
38556 #include <linux/kobject.h>
38557 #include <linux/cdev.h>
38558 #include <linux/uio_driver.h>
38559+#include <asm/local.h>
38560
38561 #define UIO_MAX_DEVICES (1U << MINORBITS)
38562
38563@@ -32,10 +33,10 @@ struct uio_device {
38564 struct module *owner;
38565 struct device *dev;
38566 int minor;
38567- atomic_t event;
38568+ atomic_unchecked_t event;
38569 struct fasync_struct *async_queue;
38570 wait_queue_head_t wait;
38571- int vma_count;
38572+ local_t vma_count;
38573 struct uio_info *info;
38574 struct kobject *map_dir;
38575 struct kobject *portio_dir;
38576@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
38577 struct device_attribute *attr, char *buf)
38578 {
38579 struct uio_device *idev = dev_get_drvdata(dev);
38580- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
38581+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
38582 }
38583
38584 static struct device_attribute uio_class_attributes[] = {
38585@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
38586 {
38587 struct uio_device *idev = info->uio_dev;
38588
38589- atomic_inc(&idev->event);
38590+ atomic_inc_unchecked(&idev->event);
38591 wake_up_interruptible(&idev->wait);
38592 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
38593 }
38594@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
38595 }
38596
38597 listener->dev = idev;
38598- listener->event_count = atomic_read(&idev->event);
38599+ listener->event_count = atomic_read_unchecked(&idev->event);
38600 filep->private_data = listener;
38601
38602 if (idev->info->open) {
38603@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
38604 return -EIO;
38605
38606 poll_wait(filep, &idev->wait, wait);
38607- if (listener->event_count != atomic_read(&idev->event))
38608+ if (listener->event_count != atomic_read_unchecked(&idev->event))
38609 return POLLIN | POLLRDNORM;
38610 return 0;
38611 }
38612@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
38613 do {
38614 set_current_state(TASK_INTERRUPTIBLE);
38615
38616- event_count = atomic_read(&idev->event);
38617+ event_count = atomic_read_unchecked(&idev->event);
38618 if (event_count != listener->event_count) {
38619 if (copy_to_user(buf, &event_count, count))
38620 retval = -EFAULT;
38621@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
38622 static void uio_vma_open(struct vm_area_struct *vma)
38623 {
38624 struct uio_device *idev = vma->vm_private_data;
38625- idev->vma_count++;
38626+ local_inc(&idev->vma_count);
38627 }
38628
38629 static void uio_vma_close(struct vm_area_struct *vma)
38630 {
38631 struct uio_device *idev = vma->vm_private_data;
38632- idev->vma_count--;
38633+ local_dec(&idev->vma_count);
38634 }
38635
38636 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38637@@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
38638 idev->owner = owner;
38639 idev->info = info;
38640 init_waitqueue_head(&idev->wait);
38641- atomic_set(&idev->event, 0);
38642+ atomic_set_unchecked(&idev->event, 0);
38643
38644 ret = uio_get_minor(idev);
38645 if (ret)
38646diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
38647index b7eb86a..36d28af 100644
38648--- a/drivers/usb/atm/cxacru.c
38649+++ b/drivers/usb/atm/cxacru.c
38650@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
38651 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
38652 if (ret < 2)
38653 return -EINVAL;
38654- if (index < 0 || index > 0x7f)
38655+ if (index > 0x7f)
38656 return -EINVAL;
38657 pos += tmp;
38658
38659diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
38660index ee62b35..b663594 100644
38661--- a/drivers/usb/atm/usbatm.c
38662+++ b/drivers/usb/atm/usbatm.c
38663@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38664 if (printk_ratelimit())
38665 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
38666 __func__, vpi, vci);
38667- atomic_inc(&vcc->stats->rx_err);
38668+ atomic_inc_unchecked(&vcc->stats->rx_err);
38669 return;
38670 }
38671
38672@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38673 if (length > ATM_MAX_AAL5_PDU) {
38674 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
38675 __func__, length, vcc);
38676- atomic_inc(&vcc->stats->rx_err);
38677+ atomic_inc_unchecked(&vcc->stats->rx_err);
38678 goto out;
38679 }
38680
38681@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38682 if (sarb->len < pdu_length) {
38683 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
38684 __func__, pdu_length, sarb->len, vcc);
38685- atomic_inc(&vcc->stats->rx_err);
38686+ atomic_inc_unchecked(&vcc->stats->rx_err);
38687 goto out;
38688 }
38689
38690 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
38691 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
38692 __func__, vcc);
38693- atomic_inc(&vcc->stats->rx_err);
38694+ atomic_inc_unchecked(&vcc->stats->rx_err);
38695 goto out;
38696 }
38697
38698@@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38699 if (printk_ratelimit())
38700 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
38701 __func__, length);
38702- atomic_inc(&vcc->stats->rx_drop);
38703+ atomic_inc_unchecked(&vcc->stats->rx_drop);
38704 goto out;
38705 }
38706
38707@@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38708
38709 vcc->push(vcc, skb);
38710
38711- atomic_inc(&vcc->stats->rx);
38712+ atomic_inc_unchecked(&vcc->stats->rx);
38713 out:
38714 skb_trim(sarb, 0);
38715 }
38716@@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
38717 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
38718
38719 usbatm_pop(vcc, skb);
38720- atomic_inc(&vcc->stats->tx);
38721+ atomic_inc_unchecked(&vcc->stats->tx);
38722
38723 skb = skb_dequeue(&instance->sndqueue);
38724 }
38725@@ -770,11 +770,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
38726 if (!left--)
38727 return sprintf(page,
38728 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
38729- atomic_read(&atm_dev->stats.aal5.tx),
38730- atomic_read(&atm_dev->stats.aal5.tx_err),
38731- atomic_read(&atm_dev->stats.aal5.rx),
38732- atomic_read(&atm_dev->stats.aal5.rx_err),
38733- atomic_read(&atm_dev->stats.aal5.rx_drop));
38734+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
38735+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
38736+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
38737+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
38738+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
38739
38740 if (!left--) {
38741 if (instance->disconnected)
38742diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
38743index d956965..4179a77 100644
38744--- a/drivers/usb/core/devices.c
38745+++ b/drivers/usb/core/devices.c
38746@@ -126,7 +126,7 @@ static const char format_endpt[] =
38747 * time it gets called.
38748 */
38749 static struct device_connect_event {
38750- atomic_t count;
38751+ atomic_unchecked_t count;
38752 wait_queue_head_t wait;
38753 } device_event = {
38754 .count = ATOMIC_INIT(1),
38755@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
38756
38757 void usbfs_conn_disc_event(void)
38758 {
38759- atomic_add(2, &device_event.count);
38760+ atomic_add_unchecked(2, &device_event.count);
38761 wake_up(&device_event.wait);
38762 }
38763
38764@@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
38765
38766 poll_wait(file, &device_event.wait, wait);
38767
38768- event_count = atomic_read(&device_event.count);
38769+ event_count = atomic_read_unchecked(&device_event.count);
38770 if (file->f_version != event_count) {
38771 file->f_version = event_count;
38772 return POLLIN | POLLRDNORM;
38773diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
38774index 347bb05..63e1b73 100644
38775--- a/drivers/usb/early/ehci-dbgp.c
38776+++ b/drivers/usb/early/ehci-dbgp.c
38777@@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
38778
38779 #ifdef CONFIG_KGDB
38780 static struct kgdb_io kgdbdbgp_io_ops;
38781-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
38782+static struct kgdb_io kgdbdbgp_io_ops_console;
38783+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
38784 #else
38785 #define dbgp_kgdb_mode (0)
38786 #endif
38787@@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
38788 .write_char = kgdbdbgp_write_char,
38789 };
38790
38791+static struct kgdb_io kgdbdbgp_io_ops_console = {
38792+ .name = "kgdbdbgp",
38793+ .read_char = kgdbdbgp_read_char,
38794+ .write_char = kgdbdbgp_write_char,
38795+ .is_console = 1
38796+};
38797+
38798 static int kgdbdbgp_wait_time;
38799
38800 static int __init kgdbdbgp_parse_config(char *str)
38801@@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
38802 ptr++;
38803 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
38804 }
38805- kgdb_register_io_module(&kgdbdbgp_io_ops);
38806- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
38807+ if (early_dbgp_console.index != -1)
38808+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
38809+ else
38810+ kgdb_register_io_module(&kgdbdbgp_io_ops);
38811
38812 return 0;
38813 }
38814diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
38815index 5b3f5ff..6e00893 100644
38816--- a/drivers/usb/gadget/u_serial.c
38817+++ b/drivers/usb/gadget/u_serial.c
38818@@ -731,9 +731,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
38819 spin_lock_irq(&port->port_lock);
38820
38821 /* already open? Great. */
38822- if (port->port.count) {
38823+ if (atomic_read(&port->port.count)) {
38824 status = 0;
38825- port->port.count++;
38826+ atomic_inc(&port->port.count);
38827
38828 /* currently opening/closing? wait ... */
38829 } else if (port->openclose) {
38830@@ -792,7 +792,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
38831 tty->driver_data = port;
38832 port->port.tty = tty;
38833
38834- port->port.count = 1;
38835+ atomic_set(&port->port.count, 1);
38836 port->openclose = false;
38837
38838 /* if connected, start the I/O stream */
38839@@ -834,11 +834,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
38840
38841 spin_lock_irq(&port->port_lock);
38842
38843- if (port->port.count != 1) {
38844- if (port->port.count == 0)
38845+ if (atomic_read(&port->port.count) != 1) {
38846+ if (atomic_read(&port->port.count) == 0)
38847 WARN_ON(1);
38848 else
38849- --port->port.count;
38850+ atomic_dec(&port->port.count);
38851 goto exit;
38852 }
38853
38854@@ -848,7 +848,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
38855 * and sleep if necessary
38856 */
38857 port->openclose = true;
38858- port->port.count = 0;
38859+ atomic_set(&port->port.count, 0);
38860
38861 gser = port->port_usb;
38862 if (gser && gser->disconnect)
38863@@ -1152,7 +1152,7 @@ static int gs_closed(struct gs_port *port)
38864 int cond;
38865
38866 spin_lock_irq(&port->port_lock);
38867- cond = (port->port.count == 0) && !port->openclose;
38868+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
38869 spin_unlock_irq(&port->port_lock);
38870 return cond;
38871 }
38872@@ -1265,7 +1265,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
38873 /* if it's already open, start I/O ... and notify the serial
38874 * protocol about open/close status (connect/disconnect).
38875 */
38876- if (port->port.count) {
38877+ if (atomic_read(&port->port.count)) {
38878 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
38879 gs_start_io(port);
38880 if (gser->connect)
38881@@ -1312,7 +1312,7 @@ void gserial_disconnect(struct gserial *gser)
38882
38883 port->port_usb = NULL;
38884 gser->ioport = NULL;
38885- if (port->port.count > 0 || port->openclose) {
38886+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
38887 wake_up_interruptible(&port->drain_wait);
38888 if (port->port.tty)
38889 tty_hangup(port->port.tty);
38890@@ -1328,7 +1328,7 @@ void gserial_disconnect(struct gserial *gser)
38891
38892 /* finally, free any unused/unusable I/O buffers */
38893 spin_lock_irqsave(&port->port_lock, flags);
38894- if (port->port.count == 0 && !port->openclose)
38895+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
38896 gs_buf_free(&port->port_write_buf);
38897 gs_free_requests(gser->out, &port->read_pool, NULL);
38898 gs_free_requests(gser->out, &port->read_queue, NULL);
38899diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
38900index b9cca6d..75c75df 100644
38901--- a/drivers/usb/serial/console.c
38902+++ b/drivers/usb/serial/console.c
38903@@ -127,7 +127,7 @@ static int usb_console_setup(struct console *co, char *options)
38904
38905 info->port = port;
38906
38907- ++port->port.count;
38908+ atomic_inc(&port->port.count);
38909 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
38910 if (serial->type->set_termios) {
38911 /*
38912@@ -177,7 +177,7 @@ static int usb_console_setup(struct console *co, char *options)
38913 }
38914 /* Now that any required fake tty operations are completed restore
38915 * the tty port count */
38916- --port->port.count;
38917+ atomic_dec(&port->port.count);
38918 /* The console is special in terms of closing the device so
38919 * indicate this port is now acting as a system console. */
38920 port->port.console = 1;
38921@@ -190,7 +190,7 @@ static int usb_console_setup(struct console *co, char *options)
38922 free_tty:
38923 kfree(tty);
38924 reset_open_count:
38925- port->port.count = 0;
38926+ atomic_set(&port->port.count, 0);
38927 usb_autopm_put_interface(serial->interface);
38928 error_get_interface:
38929 usb_serial_put(serial);
38930diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
38931index d6bea3e..60b250e 100644
38932--- a/drivers/usb/wusbcore/wa-hc.h
38933+++ b/drivers/usb/wusbcore/wa-hc.h
38934@@ -192,7 +192,7 @@ struct wahc {
38935 struct list_head xfer_delayed_list;
38936 spinlock_t xfer_list_lock;
38937 struct work_struct xfer_work;
38938- atomic_t xfer_id_count;
38939+ atomic_unchecked_t xfer_id_count;
38940 };
38941
38942
38943@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
38944 INIT_LIST_HEAD(&wa->xfer_delayed_list);
38945 spin_lock_init(&wa->xfer_list_lock);
38946 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
38947- atomic_set(&wa->xfer_id_count, 1);
38948+ atomic_set_unchecked(&wa->xfer_id_count, 1);
38949 }
38950
38951 /**
38952diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
38953index 57c01ab..8a05959 100644
38954--- a/drivers/usb/wusbcore/wa-xfer.c
38955+++ b/drivers/usb/wusbcore/wa-xfer.c
38956@@ -296,7 +296,7 @@ out:
38957 */
38958 static void wa_xfer_id_init(struct wa_xfer *xfer)
38959 {
38960- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
38961+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
38962 }
38963
38964 /*
38965diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
38966index 112156f..eb81154 100644
38967--- a/drivers/vhost/vhost.c
38968+++ b/drivers/vhost/vhost.c
38969@@ -635,7 +635,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
38970 return 0;
38971 }
38972
38973-static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
38974+static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
38975 {
38976 struct file *eventfp, *filep = NULL,
38977 *pollstart = NULL, *pollstop = NULL;
38978diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
38979index b0b2ac3..89a4399 100644
38980--- a/drivers/video/aty/aty128fb.c
38981+++ b/drivers/video/aty/aty128fb.c
38982@@ -148,7 +148,7 @@ enum {
38983 };
38984
38985 /* Must match above enum */
38986-static const char *r128_family[] __devinitdata = {
38987+static const char *r128_family[] __devinitconst = {
38988 "AGP",
38989 "PCI",
38990 "PRO AGP",
38991diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
38992index 5c3960d..15cf8fc 100644
38993--- a/drivers/video/fbcmap.c
38994+++ b/drivers/video/fbcmap.c
38995@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
38996 rc = -ENODEV;
38997 goto out;
38998 }
38999- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
39000- !info->fbops->fb_setcmap)) {
39001+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
39002 rc = -EINVAL;
39003 goto out1;
39004 }
39005diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
39006index 0dff12a..2ef47b3 100644
39007--- a/drivers/video/fbmem.c
39008+++ b/drivers/video/fbmem.c
39009@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39010 image->dx += image->width + 8;
39011 }
39012 } else if (rotate == FB_ROTATE_UD) {
39013- for (x = 0; x < num && image->dx >= 0; x++) {
39014+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
39015 info->fbops->fb_imageblit(info, image);
39016 image->dx -= image->width + 8;
39017 }
39018@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39019 image->dy += image->height + 8;
39020 }
39021 } else if (rotate == FB_ROTATE_CCW) {
39022- for (x = 0; x < num && image->dy >= 0; x++) {
39023+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39024 info->fbops->fb_imageblit(info, image);
39025 image->dy -= image->height + 8;
39026 }
39027@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
39028 return -EFAULT;
39029 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39030 return -EINVAL;
39031- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39032+ if (con2fb.framebuffer >= FB_MAX)
39033 return -EINVAL;
39034 if (!registered_fb[con2fb.framebuffer])
39035 request_module("fb%d", con2fb.framebuffer);
39036diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
39037index 5a5d092..265c5ed 100644
39038--- a/drivers/video/geode/gx1fb_core.c
39039+++ b/drivers/video/geode/gx1fb_core.c
39040@@ -29,7 +29,7 @@ static int crt_option = 1;
39041 static char panel_option[32] = "";
39042
39043 /* Modes relevant to the GX1 (taken from modedb.c) */
39044-static const struct fb_videomode __devinitdata gx1_modedb[] = {
39045+static const struct fb_videomode __devinitconst gx1_modedb[] = {
39046 /* 640x480-60 VESA */
39047 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
39048 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
39049diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
39050index 0fad23f..0e9afa4 100644
39051--- a/drivers/video/gxt4500.c
39052+++ b/drivers/video/gxt4500.c
39053@@ -156,7 +156,7 @@ struct gxt4500_par {
39054 static char *mode_option;
39055
39056 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
39057-static const struct fb_videomode defaultmode __devinitdata = {
39058+static const struct fb_videomode defaultmode __devinitconst = {
39059 .refresh = 60,
39060 .xres = 1280,
39061 .yres = 1024,
39062@@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
39063 return 0;
39064 }
39065
39066-static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
39067+static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
39068 .id = "IBM GXT4500P",
39069 .type = FB_TYPE_PACKED_PIXELS,
39070 .visual = FB_VISUAL_PSEUDOCOLOR,
39071diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39072index 7672d2e..b56437f 100644
39073--- a/drivers/video/i810/i810_accel.c
39074+++ b/drivers/video/i810/i810_accel.c
39075@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39076 }
39077 }
39078 printk("ringbuffer lockup!!!\n");
39079+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39080 i810_report_error(mmio);
39081 par->dev_flags |= LOCKUP;
39082 info->pixmap.scan_align = 1;
39083diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
39084index b83f361..2b05a91 100644
39085--- a/drivers/video/i810/i810_main.c
39086+++ b/drivers/video/i810/i810_main.c
39087@@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
39088 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
39089
39090 /* PCI */
39091-static const char *i810_pci_list[] __devinitdata = {
39092+static const char *i810_pci_list[] __devinitconst = {
39093 "Intel(R) 810 Framebuffer Device" ,
39094 "Intel(R) 810-DC100 Framebuffer Device" ,
39095 "Intel(R) 810E Framebuffer Device" ,
39096diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
39097index de36693..3c63fc2 100644
39098--- a/drivers/video/jz4740_fb.c
39099+++ b/drivers/video/jz4740_fb.c
39100@@ -136,7 +136,7 @@ struct jzfb {
39101 uint32_t pseudo_palette[16];
39102 };
39103
39104-static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
39105+static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
39106 .id = "JZ4740 FB",
39107 .type = FB_TYPE_PACKED_PIXELS,
39108 .visual = FB_VISUAL_TRUECOLOR,
39109diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39110index 3c14e43..eafa544 100644
39111--- a/drivers/video/logo/logo_linux_clut224.ppm
39112+++ b/drivers/video/logo/logo_linux_clut224.ppm
39113@@ -1,1604 +1,1123 @@
39114 P3
39115-# Standard 224-color Linux logo
39116 80 80
39117 255
39118- 0 0 0 0 0 0 0 0 0 0 0 0
39119- 0 0 0 0 0 0 0 0 0 0 0 0
39120- 0 0 0 0 0 0 0 0 0 0 0 0
39121- 0 0 0 0 0 0 0 0 0 0 0 0
39122- 0 0 0 0 0 0 0 0 0 0 0 0
39123- 0 0 0 0 0 0 0 0 0 0 0 0
39124- 0 0 0 0 0 0 0 0 0 0 0 0
39125- 0 0 0 0 0 0 0 0 0 0 0 0
39126- 0 0 0 0 0 0 0 0 0 0 0 0
39127- 6 6 6 6 6 6 10 10 10 10 10 10
39128- 10 10 10 6 6 6 6 6 6 6 6 6
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 0 0 0 0 0 0 0
39137- 0 0 0 0 0 0 0 0 0 0 0 0
39138- 0 0 0 0 0 0 0 0 0 0 0 0
39139- 0 0 0 0 0 0 0 0 0 0 0 0
39140- 0 0 0 0 0 0 0 0 0 0 0 0
39141- 0 0 0 0 0 0 0 0 0 0 0 0
39142- 0 0 0 0 0 0 0 0 0 0 0 0
39143- 0 0 0 0 0 0 0 0 0 0 0 0
39144- 0 0 0 0 0 0 0 0 0 0 0 0
39145- 0 0 0 0 0 0 0 0 0 0 0 0
39146- 0 0 0 6 6 6 10 10 10 14 14 14
39147- 22 22 22 26 26 26 30 30 30 34 34 34
39148- 30 30 30 30 30 30 26 26 26 18 18 18
39149- 14 14 14 10 10 10 6 6 6 0 0 0
39150- 0 0 0 0 0 0 0 0 0 0 0 0
39151- 0 0 0 0 0 0 0 0 0 0 0 0
39152- 0 0 0 0 0 0 0 0 0 0 0 0
39153- 0 0 0 0 0 0 0 0 0 0 0 0
39154- 0 0 0 0 0 0 0 0 0 0 0 0
39155- 0 0 0 0 0 0 0 0 0 0 0 0
39156- 0 0 0 0 0 0 0 0 0 0 0 0
39157- 0 0 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 1 0 0 1 0 0 0
39160- 0 0 0 0 0 0 0 0 0 0 0 0
39161- 0 0 0 0 0 0 0 0 0 0 0 0
39162- 0 0 0 0 0 0 0 0 0 0 0 0
39163- 0 0 0 0 0 0 0 0 0 0 0 0
39164- 0 0 0 0 0 0 0 0 0 0 0 0
39165- 0 0 0 0 0 0 0 0 0 0 0 0
39166- 6 6 6 14 14 14 26 26 26 42 42 42
39167- 54 54 54 66 66 66 78 78 78 78 78 78
39168- 78 78 78 74 74 74 66 66 66 54 54 54
39169- 42 42 42 26 26 26 18 18 18 10 10 10
39170- 6 6 6 0 0 0 0 0 0 0 0 0
39171- 0 0 0 0 0 0 0 0 0 0 0 0
39172- 0 0 0 0 0 0 0 0 0 0 0 0
39173- 0 0 0 0 0 0 0 0 0 0 0 0
39174- 0 0 0 0 0 0 0 0 0 0 0 0
39175- 0 0 0 0 0 0 0 0 0 0 0 0
39176- 0 0 0 0 0 0 0 0 0 0 0 0
39177- 0 0 0 0 0 0 0 0 0 0 0 0
39178- 0 0 0 0 0 0 0 0 0 0 0 0
39179- 0 0 1 0 0 0 0 0 0 0 0 0
39180- 0 0 0 0 0 0 0 0 0 0 0 0
39181- 0 0 0 0 0 0 0 0 0 0 0 0
39182- 0 0 0 0 0 0 0 0 0 0 0 0
39183- 0 0 0 0 0 0 0 0 0 0 0 0
39184- 0 0 0 0 0 0 0 0 0 0 0 0
39185- 0 0 0 0 0 0 0 0 0 10 10 10
39186- 22 22 22 42 42 42 66 66 66 86 86 86
39187- 66 66 66 38 38 38 38 38 38 22 22 22
39188- 26 26 26 34 34 34 54 54 54 66 66 66
39189- 86 86 86 70 70 70 46 46 46 26 26 26
39190- 14 14 14 6 6 6 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 1 0 0 1 0 0 1 0 0 0
39200- 0 0 0 0 0 0 0 0 0 0 0 0
39201- 0 0 0 0 0 0 0 0 0 0 0 0
39202- 0 0 0 0 0 0 0 0 0 0 0 0
39203- 0 0 0 0 0 0 0 0 0 0 0 0
39204- 0 0 0 0 0 0 0 0 0 0 0 0
39205- 0 0 0 0 0 0 10 10 10 26 26 26
39206- 50 50 50 82 82 82 58 58 58 6 6 6
39207- 2 2 6 2 2 6 2 2 6 2 2 6
39208- 2 2 6 2 2 6 2 2 6 2 2 6
39209- 6 6 6 54 54 54 86 86 86 66 66 66
39210- 38 38 38 18 18 18 6 6 6 0 0 0
39211- 0 0 0 0 0 0 0 0 0 0 0 0
39212- 0 0 0 0 0 0 0 0 0 0 0 0
39213- 0 0 0 0 0 0 0 0 0 0 0 0
39214- 0 0 0 0 0 0 0 0 0 0 0 0
39215- 0 0 0 0 0 0 0 0 0 0 0 0
39216- 0 0 0 0 0 0 0 0 0 0 0 0
39217- 0 0 0 0 0 0 0 0 0 0 0 0
39218- 0 0 0 0 0 0 0 0 0 0 0 0
39219- 0 0 0 0 0 0 0 0 0 0 0 0
39220- 0 0 0 0 0 0 0 0 0 0 0 0
39221- 0 0 0 0 0 0 0 0 0 0 0 0
39222- 0 0 0 0 0 0 0 0 0 0 0 0
39223- 0 0 0 0 0 0 0 0 0 0 0 0
39224- 0 0 0 0 0 0 0 0 0 0 0 0
39225- 0 0 0 6 6 6 22 22 22 50 50 50
39226- 78 78 78 34 34 34 2 2 6 2 2 6
39227- 2 2 6 2 2 6 2 2 6 2 2 6
39228- 2 2 6 2 2 6 2 2 6 2 2 6
39229- 2 2 6 2 2 6 6 6 6 70 70 70
39230- 78 78 78 46 46 46 22 22 22 6 6 6
39231- 0 0 0 0 0 0 0 0 0 0 0 0
39232- 0 0 0 0 0 0 0 0 0 0 0 0
39233- 0 0 0 0 0 0 0 0 0 0 0 0
39234- 0 0 0 0 0 0 0 0 0 0 0 0
39235- 0 0 0 0 0 0 0 0 0 0 0 0
39236- 0 0 0 0 0 0 0 0 0 0 0 0
39237- 0 0 0 0 0 0 0 0 0 0 0 0
39238- 0 0 0 0 0 0 0 0 0 0 0 0
39239- 0 0 1 0 0 1 0 0 1 0 0 0
39240- 0 0 0 0 0 0 0 0 0 0 0 0
39241- 0 0 0 0 0 0 0 0 0 0 0 0
39242- 0 0 0 0 0 0 0 0 0 0 0 0
39243- 0 0 0 0 0 0 0 0 0 0 0 0
39244- 0 0 0 0 0 0 0 0 0 0 0 0
39245- 6 6 6 18 18 18 42 42 42 82 82 82
39246- 26 26 26 2 2 6 2 2 6 2 2 6
39247- 2 2 6 2 2 6 2 2 6 2 2 6
39248- 2 2 6 2 2 6 2 2 6 14 14 14
39249- 46 46 46 34 34 34 6 6 6 2 2 6
39250- 42 42 42 78 78 78 42 42 42 18 18 18
39251- 6 6 6 0 0 0 0 0 0 0 0 0
39252- 0 0 0 0 0 0 0 0 0 0 0 0
39253- 0 0 0 0 0 0 0 0 0 0 0 0
39254- 0 0 0 0 0 0 0 0 0 0 0 0
39255- 0 0 0 0 0 0 0 0 0 0 0 0
39256- 0 0 0 0 0 0 0 0 0 0 0 0
39257- 0 0 0 0 0 0 0 0 0 0 0 0
39258- 0 0 0 0 0 0 0 0 0 0 0 0
39259- 0 0 1 0 0 0 0 0 1 0 0 0
39260- 0 0 0 0 0 0 0 0 0 0 0 0
39261- 0 0 0 0 0 0 0 0 0 0 0 0
39262- 0 0 0 0 0 0 0 0 0 0 0 0
39263- 0 0 0 0 0 0 0 0 0 0 0 0
39264- 0 0 0 0 0 0 0 0 0 0 0 0
39265- 10 10 10 30 30 30 66 66 66 58 58 58
39266- 2 2 6 2 2 6 2 2 6 2 2 6
39267- 2 2 6 2 2 6 2 2 6 2 2 6
39268- 2 2 6 2 2 6 2 2 6 26 26 26
39269- 86 86 86 101 101 101 46 46 46 10 10 10
39270- 2 2 6 58 58 58 70 70 70 34 34 34
39271- 10 10 10 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 1 0 0 1 0 0 1 0 0 0
39280- 0 0 0 0 0 0 0 0 0 0 0 0
39281- 0 0 0 0 0 0 0 0 0 0 0 0
39282- 0 0 0 0 0 0 0 0 0 0 0 0
39283- 0 0 0 0 0 0 0 0 0 0 0 0
39284- 0 0 0 0 0 0 0 0 0 0 0 0
39285- 14 14 14 42 42 42 86 86 86 10 10 10
39286- 2 2 6 2 2 6 2 2 6 2 2 6
39287- 2 2 6 2 2 6 2 2 6 2 2 6
39288- 2 2 6 2 2 6 2 2 6 30 30 30
39289- 94 94 94 94 94 94 58 58 58 26 26 26
39290- 2 2 6 6 6 6 78 78 78 54 54 54
39291- 22 22 22 6 6 6 0 0 0 0 0 0
39292- 0 0 0 0 0 0 0 0 0 0 0 0
39293- 0 0 0 0 0 0 0 0 0 0 0 0
39294- 0 0 0 0 0 0 0 0 0 0 0 0
39295- 0 0 0 0 0 0 0 0 0 0 0 0
39296- 0 0 0 0 0 0 0 0 0 0 0 0
39297- 0 0 0 0 0 0 0 0 0 0 0 0
39298- 0 0 0 0 0 0 0 0 0 0 0 0
39299- 0 0 0 0 0 0 0 0 0 0 0 0
39300- 0 0 0 0 0 0 0 0 0 0 0 0
39301- 0 0 0 0 0 0 0 0 0 0 0 0
39302- 0 0 0 0 0 0 0 0 0 0 0 0
39303- 0 0 0 0 0 0 0 0 0 0 0 0
39304- 0 0 0 0 0 0 0 0 0 6 6 6
39305- 22 22 22 62 62 62 62 62 62 2 2 6
39306- 2 2 6 2 2 6 2 2 6 2 2 6
39307- 2 2 6 2 2 6 2 2 6 2 2 6
39308- 2 2 6 2 2 6 2 2 6 26 26 26
39309- 54 54 54 38 38 38 18 18 18 10 10 10
39310- 2 2 6 2 2 6 34 34 34 82 82 82
39311- 38 38 38 14 14 14 0 0 0 0 0 0
39312- 0 0 0 0 0 0 0 0 0 0 0 0
39313- 0 0 0 0 0 0 0 0 0 0 0 0
39314- 0 0 0 0 0 0 0 0 0 0 0 0
39315- 0 0 0 0 0 0 0 0 0 0 0 0
39316- 0 0 0 0 0 0 0 0 0 0 0 0
39317- 0 0 0 0 0 0 0 0 0 0 0 0
39318- 0 0 0 0 0 0 0 0 0 0 0 0
39319- 0 0 0 0 0 1 0 0 1 0 0 0
39320- 0 0 0 0 0 0 0 0 0 0 0 0
39321- 0 0 0 0 0 0 0 0 0 0 0 0
39322- 0 0 0 0 0 0 0 0 0 0 0 0
39323- 0 0 0 0 0 0 0 0 0 0 0 0
39324- 0 0 0 0 0 0 0 0 0 6 6 6
39325- 30 30 30 78 78 78 30 30 30 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 2 2 6
39328- 2 2 6 2 2 6 2 2 6 10 10 10
39329- 10 10 10 2 2 6 2 2 6 2 2 6
39330- 2 2 6 2 2 6 2 2 6 78 78 78
39331- 50 50 50 18 18 18 6 6 6 0 0 0
39332- 0 0 0 0 0 0 0 0 0 0 0 0
39333- 0 0 0 0 0 0 0 0 0 0 0 0
39334- 0 0 0 0 0 0 0 0 0 0 0 0
39335- 0 0 0 0 0 0 0 0 0 0 0 0
39336- 0 0 0 0 0 0 0 0 0 0 0 0
39337- 0 0 0 0 0 0 0 0 0 0 0 0
39338- 0 0 0 0 0 0 0 0 0 0 0 0
39339- 0 0 1 0 0 0 0 0 0 0 0 0
39340- 0 0 0 0 0 0 0 0 0 0 0 0
39341- 0 0 0 0 0 0 0 0 0 0 0 0
39342- 0 0 0 0 0 0 0 0 0 0 0 0
39343- 0 0 0 0 0 0 0 0 0 0 0 0
39344- 0 0 0 0 0 0 0 0 0 10 10 10
39345- 38 38 38 86 86 86 14 14 14 2 2 6
39346- 2 2 6 2 2 6 2 2 6 2 2 6
39347- 2 2 6 2 2 6 2 2 6 2 2 6
39348- 2 2 6 2 2 6 2 2 6 2 2 6
39349- 2 2 6 2 2 6 2 2 6 2 2 6
39350- 2 2 6 2 2 6 2 2 6 54 54 54
39351- 66 66 66 26 26 26 6 6 6 0 0 0
39352- 0 0 0 0 0 0 0 0 0 0 0 0
39353- 0 0 0 0 0 0 0 0 0 0 0 0
39354- 0 0 0 0 0 0 0 0 0 0 0 0
39355- 0 0 0 0 0 0 0 0 0 0 0 0
39356- 0 0 0 0 0 0 0 0 0 0 0 0
39357- 0 0 0 0 0 0 0 0 0 0 0 0
39358- 0 0 0 0 0 0 0 0 0 0 0 0
39359- 0 0 0 0 0 1 0 0 1 0 0 0
39360- 0 0 0 0 0 0 0 0 0 0 0 0
39361- 0 0 0 0 0 0 0 0 0 0 0 0
39362- 0 0 0 0 0 0 0 0 0 0 0 0
39363- 0 0 0 0 0 0 0 0 0 0 0 0
39364- 0 0 0 0 0 0 0 0 0 14 14 14
39365- 42 42 42 82 82 82 2 2 6 2 2 6
39366- 2 2 6 6 6 6 10 10 10 2 2 6
39367- 2 2 6 2 2 6 2 2 6 2 2 6
39368- 2 2 6 2 2 6 2 2 6 6 6 6
39369- 14 14 14 10 10 10 2 2 6 2 2 6
39370- 2 2 6 2 2 6 2 2 6 18 18 18
39371- 82 82 82 34 34 34 10 10 10 0 0 0
39372- 0 0 0 0 0 0 0 0 0 0 0 0
39373- 0 0 0 0 0 0 0 0 0 0 0 0
39374- 0 0 0 0 0 0 0 0 0 0 0 0
39375- 0 0 0 0 0 0 0 0 0 0 0 0
39376- 0 0 0 0 0 0 0 0 0 0 0 0
39377- 0 0 0 0 0 0 0 0 0 0 0 0
39378- 0 0 0 0 0 0 0 0 0 0 0 0
39379- 0 0 1 0 0 0 0 0 0 0 0 0
39380- 0 0 0 0 0 0 0 0 0 0 0 0
39381- 0 0 0 0 0 0 0 0 0 0 0 0
39382- 0 0 0 0 0 0 0 0 0 0 0 0
39383- 0 0 0 0 0 0 0 0 0 0 0 0
39384- 0 0 0 0 0 0 0 0 0 14 14 14
39385- 46 46 46 86 86 86 2 2 6 2 2 6
39386- 6 6 6 6 6 6 22 22 22 34 34 34
39387- 6 6 6 2 2 6 2 2 6 2 2 6
39388- 2 2 6 2 2 6 18 18 18 34 34 34
39389- 10 10 10 50 50 50 22 22 22 2 2 6
39390- 2 2 6 2 2 6 2 2 6 10 10 10
39391- 86 86 86 42 42 42 14 14 14 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 1 0 0 1 0 0 1 0 0 0
39400- 0 0 0 0 0 0 0 0 0 0 0 0
39401- 0 0 0 0 0 0 0 0 0 0 0 0
39402- 0 0 0 0 0 0 0 0 0 0 0 0
39403- 0 0 0 0 0 0 0 0 0 0 0 0
39404- 0 0 0 0 0 0 0 0 0 14 14 14
39405- 46 46 46 86 86 86 2 2 6 2 2 6
39406- 38 38 38 116 116 116 94 94 94 22 22 22
39407- 22 22 22 2 2 6 2 2 6 2 2 6
39408- 14 14 14 86 86 86 138 138 138 162 162 162
39409-154 154 154 38 38 38 26 26 26 6 6 6
39410- 2 2 6 2 2 6 2 2 6 2 2 6
39411- 86 86 86 46 46 46 14 14 14 0 0 0
39412- 0 0 0 0 0 0 0 0 0 0 0 0
39413- 0 0 0 0 0 0 0 0 0 0 0 0
39414- 0 0 0 0 0 0 0 0 0 0 0 0
39415- 0 0 0 0 0 0 0 0 0 0 0 0
39416- 0 0 0 0 0 0 0 0 0 0 0 0
39417- 0 0 0 0 0 0 0 0 0 0 0 0
39418- 0 0 0 0 0 0 0 0 0 0 0 0
39419- 0 0 0 0 0 0 0 0 0 0 0 0
39420- 0 0 0 0 0 0 0 0 0 0 0 0
39421- 0 0 0 0 0 0 0 0 0 0 0 0
39422- 0 0 0 0 0 0 0 0 0 0 0 0
39423- 0 0 0 0 0 0 0 0 0 0 0 0
39424- 0 0 0 0 0 0 0 0 0 14 14 14
39425- 46 46 46 86 86 86 2 2 6 14 14 14
39426-134 134 134 198 198 198 195 195 195 116 116 116
39427- 10 10 10 2 2 6 2 2 6 6 6 6
39428-101 98 89 187 187 187 210 210 210 218 218 218
39429-214 214 214 134 134 134 14 14 14 6 6 6
39430- 2 2 6 2 2 6 2 2 6 2 2 6
39431- 86 86 86 50 50 50 18 18 18 6 6 6
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 1 0 0 0
39439- 0 0 1 0 0 1 0 0 1 0 0 0
39440- 0 0 0 0 0 0 0 0 0 0 0 0
39441- 0 0 0 0 0 0 0 0 0 0 0 0
39442- 0 0 0 0 0 0 0 0 0 0 0 0
39443- 0 0 0 0 0 0 0 0 0 0 0 0
39444- 0 0 0 0 0 0 0 0 0 14 14 14
39445- 46 46 46 86 86 86 2 2 6 54 54 54
39446-218 218 218 195 195 195 226 226 226 246 246 246
39447- 58 58 58 2 2 6 2 2 6 30 30 30
39448-210 210 210 253 253 253 174 174 174 123 123 123
39449-221 221 221 234 234 234 74 74 74 2 2 6
39450- 2 2 6 2 2 6 2 2 6 2 2 6
39451- 70 70 70 58 58 58 22 22 22 6 6 6
39452- 0 0 0 0 0 0 0 0 0 0 0 0
39453- 0 0 0 0 0 0 0 0 0 0 0 0
39454- 0 0 0 0 0 0 0 0 0 0 0 0
39455- 0 0 0 0 0 0 0 0 0 0 0 0
39456- 0 0 0 0 0 0 0 0 0 0 0 0
39457- 0 0 0 0 0 0 0 0 0 0 0 0
39458- 0 0 0 0 0 0 0 0 0 0 0 0
39459- 0 0 0 0 0 0 0 0 0 0 0 0
39460- 0 0 0 0 0 0 0 0 0 0 0 0
39461- 0 0 0 0 0 0 0 0 0 0 0 0
39462- 0 0 0 0 0 0 0 0 0 0 0 0
39463- 0 0 0 0 0 0 0 0 0 0 0 0
39464- 0 0 0 0 0 0 0 0 0 14 14 14
39465- 46 46 46 82 82 82 2 2 6 106 106 106
39466-170 170 170 26 26 26 86 86 86 226 226 226
39467-123 123 123 10 10 10 14 14 14 46 46 46
39468-231 231 231 190 190 190 6 6 6 70 70 70
39469- 90 90 90 238 238 238 158 158 158 2 2 6
39470- 2 2 6 2 2 6 2 2 6 2 2 6
39471- 70 70 70 58 58 58 22 22 22 6 6 6
39472- 0 0 0 0 0 0 0 0 0 0 0 0
39473- 0 0 0 0 0 0 0 0 0 0 0 0
39474- 0 0 0 0 0 0 0 0 0 0 0 0
39475- 0 0 0 0 0 0 0 0 0 0 0 0
39476- 0 0 0 0 0 0 0 0 0 0 0 0
39477- 0 0 0 0 0 0 0 0 0 0 0 0
39478- 0 0 0 0 0 0 0 0 1 0 0 0
39479- 0 0 1 0 0 1 0 0 1 0 0 0
39480- 0 0 0 0 0 0 0 0 0 0 0 0
39481- 0 0 0 0 0 0 0 0 0 0 0 0
39482- 0 0 0 0 0 0 0 0 0 0 0 0
39483- 0 0 0 0 0 0 0 0 0 0 0 0
39484- 0 0 0 0 0 0 0 0 0 14 14 14
39485- 42 42 42 86 86 86 6 6 6 116 116 116
39486-106 106 106 6 6 6 70 70 70 149 149 149
39487-128 128 128 18 18 18 38 38 38 54 54 54
39488-221 221 221 106 106 106 2 2 6 14 14 14
39489- 46 46 46 190 190 190 198 198 198 2 2 6
39490- 2 2 6 2 2 6 2 2 6 2 2 6
39491- 74 74 74 62 62 62 22 22 22 6 6 6
39492- 0 0 0 0 0 0 0 0 0 0 0 0
39493- 0 0 0 0 0 0 0 0 0 0 0 0
39494- 0 0 0 0 0 0 0 0 0 0 0 0
39495- 0 0 0 0 0 0 0 0 0 0 0 0
39496- 0 0 0 0 0 0 0 0 0 0 0 0
39497- 0 0 0 0 0 0 0 0 0 0 0 0
39498- 0 0 0 0 0 0 0 0 1 0 0 0
39499- 0 0 1 0 0 0 0 0 1 0 0 0
39500- 0 0 0 0 0 0 0 0 0 0 0 0
39501- 0 0 0 0 0 0 0 0 0 0 0 0
39502- 0 0 0 0 0 0 0 0 0 0 0 0
39503- 0 0 0 0 0 0 0 0 0 0 0 0
39504- 0 0 0 0 0 0 0 0 0 14 14 14
39505- 42 42 42 94 94 94 14 14 14 101 101 101
39506-128 128 128 2 2 6 18 18 18 116 116 116
39507-118 98 46 121 92 8 121 92 8 98 78 10
39508-162 162 162 106 106 106 2 2 6 2 2 6
39509- 2 2 6 195 195 195 195 195 195 6 6 6
39510- 2 2 6 2 2 6 2 2 6 2 2 6
39511- 74 74 74 62 62 62 22 22 22 6 6 6
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 1 0 0 1
39519- 0 0 1 0 0 0 0 0 1 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 0 0 0
39522- 0 0 0 0 0 0 0 0 0 0 0 0
39523- 0 0 0 0 0 0 0 0 0 0 0 0
39524- 0 0 0 0 0 0 0 0 0 10 10 10
39525- 38 38 38 90 90 90 14 14 14 58 58 58
39526-210 210 210 26 26 26 54 38 6 154 114 10
39527-226 170 11 236 186 11 225 175 15 184 144 12
39528-215 174 15 175 146 61 37 26 9 2 2 6
39529- 70 70 70 246 246 246 138 138 138 2 2 6
39530- 2 2 6 2 2 6 2 2 6 2 2 6
39531- 70 70 70 66 66 66 26 26 26 6 6 6
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 0 0 0
39542- 0 0 0 0 0 0 0 0 0 0 0 0
39543- 0 0 0 0 0 0 0 0 0 0 0 0
39544- 0 0 0 0 0 0 0 0 0 10 10 10
39545- 38 38 38 86 86 86 14 14 14 10 10 10
39546-195 195 195 188 164 115 192 133 9 225 175 15
39547-239 182 13 234 190 10 232 195 16 232 200 30
39548-245 207 45 241 208 19 232 195 16 184 144 12
39549-218 194 134 211 206 186 42 42 42 2 2 6
39550- 2 2 6 2 2 6 2 2 6 2 2 6
39551- 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0
39562- 0 0 0 0 0 0 0 0 0 0 0 0
39563- 0 0 0 0 0 0 0 0 0 0 0 0
39564- 0 0 0 0 0 0 0 0 0 10 10 10
39565- 34 34 34 86 86 86 14 14 14 2 2 6
39566-121 87 25 192 133 9 219 162 10 239 182 13
39567-236 186 11 232 195 16 241 208 19 244 214 54
39568-246 218 60 246 218 38 246 215 20 241 208 19
39569-241 208 19 226 184 13 121 87 25 2 2 6
39570- 2 2 6 2 2 6 2 2 6 2 2 6
39571- 50 50 50 82 82 82 34 34 34 10 10 10
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 0 0 0
39582- 0 0 0 0 0 0 0 0 0 0 0 0
39583- 0 0 0 0 0 0 0 0 0 0 0 0
39584- 0 0 0 0 0 0 0 0 0 10 10 10
39585- 34 34 34 82 82 82 30 30 30 61 42 6
39586-180 123 7 206 145 10 230 174 11 239 182 13
39587-234 190 10 238 202 15 241 208 19 246 218 74
39588-246 218 38 246 215 20 246 215 20 246 215 20
39589-226 184 13 215 174 15 184 144 12 6 6 6
39590- 2 2 6 2 2 6 2 2 6 2 2 6
39591- 26 26 26 94 94 94 42 42 42 14 14 14
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 0 0 0
39602- 0 0 0 0 0 0 0 0 0 0 0 0
39603- 0 0 0 0 0 0 0 0 0 0 0 0
39604- 0 0 0 0 0 0 0 0 0 10 10 10
39605- 30 30 30 78 78 78 50 50 50 104 69 6
39606-192 133 9 216 158 10 236 178 12 236 186 11
39607-232 195 16 241 208 19 244 214 54 245 215 43
39608-246 215 20 246 215 20 241 208 19 198 155 10
39609-200 144 11 216 158 10 156 118 10 2 2 6
39610- 2 2 6 2 2 6 2 2 6 2 2 6
39611- 6 6 6 90 90 90 54 54 54 18 18 18
39612- 6 6 6 0 0 0 0 0 0 0 0 0
39613- 0 0 0 0 0 0 0 0 0 0 0 0
39614- 0 0 0 0 0 0 0 0 0 0 0 0
39615- 0 0 0 0 0 0 0 0 0 0 0 0
39616- 0 0 0 0 0 0 0 0 0 0 0 0
39617- 0 0 0 0 0 0 0 0 0 0 0 0
39618- 0 0 0 0 0 0 0 0 0 0 0 0
39619- 0 0 0 0 0 0 0 0 0 0 0 0
39620- 0 0 0 0 0 0 0 0 0 0 0 0
39621- 0 0 0 0 0 0 0 0 0 0 0 0
39622- 0 0 0 0 0 0 0 0 0 0 0 0
39623- 0 0 0 0 0 0 0 0 0 0 0 0
39624- 0 0 0 0 0 0 0 0 0 10 10 10
39625- 30 30 30 78 78 78 46 46 46 22 22 22
39626-137 92 6 210 162 10 239 182 13 238 190 10
39627-238 202 15 241 208 19 246 215 20 246 215 20
39628-241 208 19 203 166 17 185 133 11 210 150 10
39629-216 158 10 210 150 10 102 78 10 2 2 6
39630- 6 6 6 54 54 54 14 14 14 2 2 6
39631- 2 2 6 62 62 62 74 74 74 30 30 30
39632- 10 10 10 0 0 0 0 0 0 0 0 0
39633- 0 0 0 0 0 0 0 0 0 0 0 0
39634- 0 0 0 0 0 0 0 0 0 0 0 0
39635- 0 0 0 0 0 0 0 0 0 0 0 0
39636- 0 0 0 0 0 0 0 0 0 0 0 0
39637- 0 0 0 0 0 0 0 0 0 0 0 0
39638- 0 0 0 0 0 0 0 0 0 0 0 0
39639- 0 0 0 0 0 0 0 0 0 0 0 0
39640- 0 0 0 0 0 0 0 0 0 0 0 0
39641- 0 0 0 0 0 0 0 0 0 0 0 0
39642- 0 0 0 0 0 0 0 0 0 0 0 0
39643- 0 0 0 0 0 0 0 0 0 0 0 0
39644- 0 0 0 0 0 0 0 0 0 10 10 10
39645- 34 34 34 78 78 78 50 50 50 6 6 6
39646- 94 70 30 139 102 15 190 146 13 226 184 13
39647-232 200 30 232 195 16 215 174 15 190 146 13
39648-168 122 10 192 133 9 210 150 10 213 154 11
39649-202 150 34 182 157 106 101 98 89 2 2 6
39650- 2 2 6 78 78 78 116 116 116 58 58 58
39651- 2 2 6 22 22 22 90 90 90 46 46 46
39652- 18 18 18 6 6 6 0 0 0 0 0 0
39653- 0 0 0 0 0 0 0 0 0 0 0 0
39654- 0 0 0 0 0 0 0 0 0 0 0 0
39655- 0 0 0 0 0 0 0 0 0 0 0 0
39656- 0 0 0 0 0 0 0 0 0 0 0 0
39657- 0 0 0 0 0 0 0 0 0 0 0 0
39658- 0 0 0 0 0 0 0 0 0 0 0 0
39659- 0 0 0 0 0 0 0 0 0 0 0 0
39660- 0 0 0 0 0 0 0 0 0 0 0 0
39661- 0 0 0 0 0 0 0 0 0 0 0 0
39662- 0 0 0 0 0 0 0 0 0 0 0 0
39663- 0 0 0 0 0 0 0 0 0 0 0 0
39664- 0 0 0 0 0 0 0 0 0 10 10 10
39665- 38 38 38 86 86 86 50 50 50 6 6 6
39666-128 128 128 174 154 114 156 107 11 168 122 10
39667-198 155 10 184 144 12 197 138 11 200 144 11
39668-206 145 10 206 145 10 197 138 11 188 164 115
39669-195 195 195 198 198 198 174 174 174 14 14 14
39670- 2 2 6 22 22 22 116 116 116 116 116 116
39671- 22 22 22 2 2 6 74 74 74 70 70 70
39672- 30 30 30 10 10 10 0 0 0 0 0 0
39673- 0 0 0 0 0 0 0 0 0 0 0 0
39674- 0 0 0 0 0 0 0 0 0 0 0 0
39675- 0 0 0 0 0 0 0 0 0 0 0 0
39676- 0 0 0 0 0 0 0 0 0 0 0 0
39677- 0 0 0 0 0 0 0 0 0 0 0 0
39678- 0 0 0 0 0 0 0 0 0 0 0 0
39679- 0 0 0 0 0 0 0 0 0 0 0 0
39680- 0 0 0 0 0 0 0 0 0 0 0 0
39681- 0 0 0 0 0 0 0 0 0 0 0 0
39682- 0 0 0 0 0 0 0 0 0 0 0 0
39683- 0 0 0 0 0 0 0 0 0 0 0 0
39684- 0 0 0 0 0 0 6 6 6 18 18 18
39685- 50 50 50 101 101 101 26 26 26 10 10 10
39686-138 138 138 190 190 190 174 154 114 156 107 11
39687-197 138 11 200 144 11 197 138 11 192 133 9
39688-180 123 7 190 142 34 190 178 144 187 187 187
39689-202 202 202 221 221 221 214 214 214 66 66 66
39690- 2 2 6 2 2 6 50 50 50 62 62 62
39691- 6 6 6 2 2 6 10 10 10 90 90 90
39692- 50 50 50 18 18 18 6 6 6 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 0 0 0 0 0 0 0 0 0
39702- 0 0 0 0 0 0 0 0 0 0 0 0
39703- 0 0 0 0 0 0 0 0 0 0 0 0
39704- 0 0 0 0 0 0 10 10 10 34 34 34
39705- 74 74 74 74 74 74 2 2 6 6 6 6
39706-144 144 144 198 198 198 190 190 190 178 166 146
39707-154 121 60 156 107 11 156 107 11 168 124 44
39708-174 154 114 187 187 187 190 190 190 210 210 210
39709-246 246 246 253 253 253 253 253 253 182 182 182
39710- 6 6 6 2 2 6 2 2 6 2 2 6
39711- 2 2 6 2 2 6 2 2 6 62 62 62
39712- 74 74 74 34 34 34 14 14 14 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- 0 0 0 0 0 0 0 0 0 0 0 0
39722- 0 0 0 0 0 0 0 0 0 0 0 0
39723- 0 0 0 0 0 0 0 0 0 0 0 0
39724- 0 0 0 10 10 10 22 22 22 54 54 54
39725- 94 94 94 18 18 18 2 2 6 46 46 46
39726-234 234 234 221 221 221 190 190 190 190 190 190
39727-190 190 190 187 187 187 187 187 187 190 190 190
39728-190 190 190 195 195 195 214 214 214 242 242 242
39729-253 253 253 253 253 253 253 253 253 253 253 253
39730- 82 82 82 2 2 6 2 2 6 2 2 6
39731- 2 2 6 2 2 6 2 2 6 14 14 14
39732- 86 86 86 54 54 54 22 22 22 6 6 6
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 0 0 0
39741- 0 0 0 0 0 0 0 0 0 0 0 0
39742- 0 0 0 0 0 0 0 0 0 0 0 0
39743- 0 0 0 0 0 0 0 0 0 0 0 0
39744- 6 6 6 18 18 18 46 46 46 90 90 90
39745- 46 46 46 18 18 18 6 6 6 182 182 182
39746-253 253 253 246 246 246 206 206 206 190 190 190
39747-190 190 190 190 190 190 190 190 190 190 190 190
39748-206 206 206 231 231 231 250 250 250 253 253 253
39749-253 253 253 253 253 253 253 253 253 253 253 253
39750-202 202 202 14 14 14 2 2 6 2 2 6
39751- 2 2 6 2 2 6 2 2 6 2 2 6
39752- 42 42 42 86 86 86 42 42 42 18 18 18
39753- 6 6 6 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 0 0 0
39761- 0 0 0 0 0 0 0 0 0 0 0 0
39762- 0 0 0 0 0 0 0 0 0 0 0 0
39763- 0 0 0 0 0 0 0 0 0 6 6 6
39764- 14 14 14 38 38 38 74 74 74 66 66 66
39765- 2 2 6 6 6 6 90 90 90 250 250 250
39766-253 253 253 253 253 253 238 238 238 198 198 198
39767-190 190 190 190 190 190 195 195 195 221 221 221
39768-246 246 246 253 253 253 253 253 253 253 253 253
39769-253 253 253 253 253 253 253 253 253 253 253 253
39770-253 253 253 82 82 82 2 2 6 2 2 6
39771- 2 2 6 2 2 6 2 2 6 2 2 6
39772- 2 2 6 78 78 78 70 70 70 34 34 34
39773- 14 14 14 6 6 6 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 0 0 0 0 0 0
39781- 0 0 0 0 0 0 0 0 0 0 0 0
39782- 0 0 0 0 0 0 0 0 0 0 0 0
39783- 0 0 0 0 0 0 0 0 0 14 14 14
39784- 34 34 34 66 66 66 78 78 78 6 6 6
39785- 2 2 6 18 18 18 218 218 218 253 253 253
39786-253 253 253 253 253 253 253 253 253 246 246 246
39787-226 226 226 231 231 231 246 246 246 253 253 253
39788-253 253 253 253 253 253 253 253 253 253 253 253
39789-253 253 253 253 253 253 253 253 253 253 253 253
39790-253 253 253 178 178 178 2 2 6 2 2 6
39791- 2 2 6 2 2 6 2 2 6 2 2 6
39792- 2 2 6 18 18 18 90 90 90 62 62 62
39793- 30 30 30 10 10 10 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 0 0 0 0 0 0 0 0 0
39801- 0 0 0 0 0 0 0 0 0 0 0 0
39802- 0 0 0 0 0 0 0 0 0 0 0 0
39803- 0 0 0 0 0 0 10 10 10 26 26 26
39804- 58 58 58 90 90 90 18 18 18 2 2 6
39805- 2 2 6 110 110 110 253 253 253 253 253 253
39806-253 253 253 253 253 253 253 253 253 253 253 253
39807-250 250 250 253 253 253 253 253 253 253 253 253
39808-253 253 253 253 253 253 253 253 253 253 253 253
39809-253 253 253 253 253 253 253 253 253 253 253 253
39810-253 253 253 231 231 231 18 18 18 2 2 6
39811- 2 2 6 2 2 6 2 2 6 2 2 6
39812- 2 2 6 2 2 6 18 18 18 94 94 94
39813- 54 54 54 26 26 26 10 10 10 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- 0 0 0 0 0 0 0 0 0 0 0 0
39821- 0 0 0 0 0 0 0 0 0 0 0 0
39822- 0 0 0 0 0 0 0 0 0 0 0 0
39823- 0 0 0 6 6 6 22 22 22 50 50 50
39824- 90 90 90 26 26 26 2 2 6 2 2 6
39825- 14 14 14 195 195 195 250 250 250 253 253 253
39826-253 253 253 253 253 253 253 253 253 253 253 253
39827-253 253 253 253 253 253 253 253 253 253 253 253
39828-253 253 253 253 253 253 253 253 253 253 253 253
39829-253 253 253 253 253 253 253 253 253 253 253 253
39830-250 250 250 242 242 242 54 54 54 2 2 6
39831- 2 2 6 2 2 6 2 2 6 2 2 6
39832- 2 2 6 2 2 6 2 2 6 38 38 38
39833- 86 86 86 50 50 50 22 22 22 6 6 6
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- 0 0 0 0 0 0 0 0 0 0 0 0
39841- 0 0 0 0 0 0 0 0 0 0 0 0
39842- 0 0 0 0 0 0 0 0 0 0 0 0
39843- 6 6 6 14 14 14 38 38 38 82 82 82
39844- 34 34 34 2 2 6 2 2 6 2 2 6
39845- 42 42 42 195 195 195 246 246 246 253 253 253
39846-253 253 253 253 253 253 253 253 253 250 250 250
39847-242 242 242 242 242 242 250 250 250 253 253 253
39848-253 253 253 253 253 253 253 253 253 253 253 253
39849-253 253 253 250 250 250 246 246 246 238 238 238
39850-226 226 226 231 231 231 101 101 101 6 6 6
39851- 2 2 6 2 2 6 2 2 6 2 2 6
39852- 2 2 6 2 2 6 2 2 6 2 2 6
39853- 38 38 38 82 82 82 42 42 42 14 14 14
39854- 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
39861- 0 0 0 0 0 0 0 0 0 0 0 0
39862- 0 0 0 0 0 0 0 0 0 0 0 0
39863- 10 10 10 26 26 26 62 62 62 66 66 66
39864- 2 2 6 2 2 6 2 2 6 6 6 6
39865- 70 70 70 170 170 170 206 206 206 234 234 234
39866-246 246 246 250 250 250 250 250 250 238 238 238
39867-226 226 226 231 231 231 238 238 238 250 250 250
39868-250 250 250 250 250 250 246 246 246 231 231 231
39869-214 214 214 206 206 206 202 202 202 202 202 202
39870-198 198 198 202 202 202 182 182 182 18 18 18
39871- 2 2 6 2 2 6 2 2 6 2 2 6
39872- 2 2 6 2 2 6 2 2 6 2 2 6
39873- 2 2 6 62 62 62 66 66 66 30 30 30
39874- 10 10 10 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 0 0 0
39880- 0 0 0 0 0 0 0 0 0 0 0 0
39881- 0 0 0 0 0 0 0 0 0 0 0 0
39882- 0 0 0 0 0 0 0 0 0 0 0 0
39883- 14 14 14 42 42 42 82 82 82 18 18 18
39884- 2 2 6 2 2 6 2 2 6 10 10 10
39885- 94 94 94 182 182 182 218 218 218 242 242 242
39886-250 250 250 253 253 253 253 253 253 250 250 250
39887-234 234 234 253 253 253 253 253 253 253 253 253
39888-253 253 253 253 253 253 253 253 253 246 246 246
39889-238 238 238 226 226 226 210 210 210 202 202 202
39890-195 195 195 195 195 195 210 210 210 158 158 158
39891- 6 6 6 14 14 14 50 50 50 14 14 14
39892- 2 2 6 2 2 6 2 2 6 2 2 6
39893- 2 2 6 6 6 6 86 86 86 46 46 46
39894- 18 18 18 6 6 6 0 0 0 0 0 0
39895- 0 0 0 0 0 0 0 0 0 0 0 0
39896- 0 0 0 0 0 0 0 0 0 0 0 0
39897- 0 0 0 0 0 0 0 0 0 0 0 0
39898- 0 0 0 0 0 0 0 0 0 0 0 0
39899- 0 0 0 0 0 0 0 0 0 0 0 0
39900- 0 0 0 0 0 0 0 0 0 0 0 0
39901- 0 0 0 0 0 0 0 0 0 0 0 0
39902- 0 0 0 0 0 0 0 0 0 6 6 6
39903- 22 22 22 54 54 54 70 70 70 2 2 6
39904- 2 2 6 10 10 10 2 2 6 22 22 22
39905-166 166 166 231 231 231 250 250 250 253 253 253
39906-253 253 253 253 253 253 253 253 253 250 250 250
39907-242 242 242 253 253 253 253 253 253 253 253 253
39908-253 253 253 253 253 253 253 253 253 253 253 253
39909-253 253 253 253 253 253 253 253 253 246 246 246
39910-231 231 231 206 206 206 198 198 198 226 226 226
39911- 94 94 94 2 2 6 6 6 6 38 38 38
39912- 30 30 30 2 2 6 2 2 6 2 2 6
39913- 2 2 6 2 2 6 62 62 62 66 66 66
39914- 26 26 26 10 10 10 0 0 0 0 0 0
39915- 0 0 0 0 0 0 0 0 0 0 0 0
39916- 0 0 0 0 0 0 0 0 0 0 0 0
39917- 0 0 0 0 0 0 0 0 0 0 0 0
39918- 0 0 0 0 0 0 0 0 0 0 0 0
39919- 0 0 0 0 0 0 0 0 0 0 0 0
39920- 0 0 0 0 0 0 0 0 0 0 0 0
39921- 0 0 0 0 0 0 0 0 0 0 0 0
39922- 0 0 0 0 0 0 0 0 0 10 10 10
39923- 30 30 30 74 74 74 50 50 50 2 2 6
39924- 26 26 26 26 26 26 2 2 6 106 106 106
39925-238 238 238 253 253 253 253 253 253 253 253 253
39926-253 253 253 253 253 253 253 253 253 253 253 253
39927-253 253 253 253 253 253 253 253 253 253 253 253
39928-253 253 253 253 253 253 253 253 253 253 253 253
39929-253 253 253 253 253 253 253 253 253 253 253 253
39930-253 253 253 246 246 246 218 218 218 202 202 202
39931-210 210 210 14 14 14 2 2 6 2 2 6
39932- 30 30 30 22 22 22 2 2 6 2 2 6
39933- 2 2 6 2 2 6 18 18 18 86 86 86
39934- 42 42 42 14 14 14 0 0 0 0 0 0
39935- 0 0 0 0 0 0 0 0 0 0 0 0
39936- 0 0 0 0 0 0 0 0 0 0 0 0
39937- 0 0 0 0 0 0 0 0 0 0 0 0
39938- 0 0 0 0 0 0 0 0 0 0 0 0
39939- 0 0 0 0 0 0 0 0 0 0 0 0
39940- 0 0 0 0 0 0 0 0 0 0 0 0
39941- 0 0 0 0 0 0 0 0 0 0 0 0
39942- 0 0 0 0 0 0 0 0 0 14 14 14
39943- 42 42 42 90 90 90 22 22 22 2 2 6
39944- 42 42 42 2 2 6 18 18 18 218 218 218
39945-253 253 253 253 253 253 253 253 253 253 253 253
39946-253 253 253 253 253 253 253 253 253 253 253 253
39947-253 253 253 253 253 253 253 253 253 253 253 253
39948-253 253 253 253 253 253 253 253 253 253 253 253
39949-253 253 253 253 253 253 253 253 253 253 253 253
39950-253 253 253 253 253 253 250 250 250 221 221 221
39951-218 218 218 101 101 101 2 2 6 14 14 14
39952- 18 18 18 38 38 38 10 10 10 2 2 6
39953- 2 2 6 2 2 6 2 2 6 78 78 78
39954- 58 58 58 22 22 22 6 6 6 0 0 0
39955- 0 0 0 0 0 0 0 0 0 0 0 0
39956- 0 0 0 0 0 0 0 0 0 0 0 0
39957- 0 0 0 0 0 0 0 0 0 0 0 0
39958- 0 0 0 0 0 0 0 0 0 0 0 0
39959- 0 0 0 0 0 0 0 0 0 0 0 0
39960- 0 0 0 0 0 0 0 0 0 0 0 0
39961- 0 0 0 0 0 0 0 0 0 0 0 0
39962- 0 0 0 0 0 0 6 6 6 18 18 18
39963- 54 54 54 82 82 82 2 2 6 26 26 26
39964- 22 22 22 2 2 6 123 123 123 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 253 253 253 253 253 253 253 253 253
39969-253 253 253 253 253 253 253 253 253 253 253 253
39970-253 253 253 253 253 253 253 253 253 250 250 250
39971-238 238 238 198 198 198 6 6 6 38 38 38
39972- 58 58 58 26 26 26 38 38 38 2 2 6
39973- 2 2 6 2 2 6 2 2 6 46 46 46
39974- 78 78 78 30 30 30 10 10 10 0 0 0
39975- 0 0 0 0 0 0 0 0 0 0 0 0
39976- 0 0 0 0 0 0 0 0 0 0 0 0
39977- 0 0 0 0 0 0 0 0 0 0 0 0
39978- 0 0 0 0 0 0 0 0 0 0 0 0
39979- 0 0 0 0 0 0 0 0 0 0 0 0
39980- 0 0 0 0 0 0 0 0 0 0 0 0
39981- 0 0 0 0 0 0 0 0 0 0 0 0
39982- 0 0 0 0 0 0 10 10 10 30 30 30
39983- 74 74 74 58 58 58 2 2 6 42 42 42
39984- 2 2 6 22 22 22 231 231 231 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 250 250 250
39987-253 253 253 253 253 253 253 253 253 253 253 253
39988-253 253 253 253 253 253 253 253 253 253 253 253
39989-253 253 253 253 253 253 253 253 253 253 253 253
39990-253 253 253 253 253 253 253 253 253 253 253 253
39991-253 253 253 246 246 246 46 46 46 38 38 38
39992- 42 42 42 14 14 14 38 38 38 14 14 14
39993- 2 2 6 2 2 6 2 2 6 6 6 6
39994- 86 86 86 46 46 46 14 14 14 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 0 0 0 0 0 0 0 0 0
40000- 0 0 0 0 0 0 0 0 0 0 0 0
40001- 0 0 0 0 0 0 0 0 0 0 0 0
40002- 0 0 0 6 6 6 14 14 14 42 42 42
40003- 90 90 90 18 18 18 18 18 18 26 26 26
40004- 2 2 6 116 116 116 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 250 250 250 238 238 238
40007-253 253 253 253 253 253 253 253 253 253 253 253
40008-253 253 253 253 253 253 253 253 253 253 253 253
40009-253 253 253 253 253 253 253 253 253 253 253 253
40010-253 253 253 253 253 253 253 253 253 253 253 253
40011-253 253 253 253 253 253 94 94 94 6 6 6
40012- 2 2 6 2 2 6 10 10 10 34 34 34
40013- 2 2 6 2 2 6 2 2 6 2 2 6
40014- 74 74 74 58 58 58 22 22 22 6 6 6
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- 0 0 0 0 0 0 0 0 0 0 0 0
40020- 0 0 0 0 0 0 0 0 0 0 0 0
40021- 0 0 0 0 0 0 0 0 0 0 0 0
40022- 0 0 0 10 10 10 26 26 26 66 66 66
40023- 82 82 82 2 2 6 38 38 38 6 6 6
40024- 14 14 14 210 210 210 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 246 246 246 242 242 242
40027-253 253 253 253 253 253 253 253 253 253 253 253
40028-253 253 253 253 253 253 253 253 253 253 253 253
40029-253 253 253 253 253 253 253 253 253 253 253 253
40030-253 253 253 253 253 253 253 253 253 253 253 253
40031-253 253 253 253 253 253 144 144 144 2 2 6
40032- 2 2 6 2 2 6 2 2 6 46 46 46
40033- 2 2 6 2 2 6 2 2 6 2 2 6
40034- 42 42 42 74 74 74 30 30 30 10 10 10
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- 0 0 0 0 0 0 0 0 0 0 0 0
40040- 0 0 0 0 0 0 0 0 0 0 0 0
40041- 0 0 0 0 0 0 0 0 0 0 0 0
40042- 6 6 6 14 14 14 42 42 42 90 90 90
40043- 26 26 26 6 6 6 42 42 42 2 2 6
40044- 74 74 74 250 250 250 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 242 242 242 242 242 242
40047-253 253 253 253 253 253 253 253 253 253 253 253
40048-253 253 253 253 253 253 253 253 253 253 253 253
40049-253 253 253 253 253 253 253 253 253 253 253 253
40050-253 253 253 253 253 253 253 253 253 253 253 253
40051-253 253 253 253 253 253 182 182 182 2 2 6
40052- 2 2 6 2 2 6 2 2 6 46 46 46
40053- 2 2 6 2 2 6 2 2 6 2 2 6
40054- 10 10 10 86 86 86 38 38 38 10 10 10
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 0 0 0
40059- 0 0 0 0 0 0 0 0 0 0 0 0
40060- 0 0 0 0 0 0 0 0 0 0 0 0
40061- 0 0 0 0 0 0 0 0 0 0 0 0
40062- 10 10 10 26 26 26 66 66 66 82 82 82
40063- 2 2 6 22 22 22 18 18 18 2 2 6
40064-149 149 149 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 234 234 234 242 242 242
40067-253 253 253 253 253 253 253 253 253 253 253 253
40068-253 253 253 253 253 253 253 253 253 253 253 253
40069-253 253 253 253 253 253 253 253 253 253 253 253
40070-253 253 253 253 253 253 253 253 253 253 253 253
40071-253 253 253 253 253 253 206 206 206 2 2 6
40072- 2 2 6 2 2 6 2 2 6 38 38 38
40073- 2 2 6 2 2 6 2 2 6 2 2 6
40074- 6 6 6 86 86 86 46 46 46 14 14 14
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 0 0 0
40079- 0 0 0 0 0 0 0 0 0 0 0 0
40080- 0 0 0 0 0 0 0 0 0 0 0 0
40081- 0 0 0 0 0 0 0 0 0 6 6 6
40082- 18 18 18 46 46 46 86 86 86 18 18 18
40083- 2 2 6 34 34 34 10 10 10 6 6 6
40084-210 210 210 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 234 234 234 242 242 242
40087-253 253 253 253 253 253 253 253 253 253 253 253
40088-253 253 253 253 253 253 253 253 253 253 253 253
40089-253 253 253 253 253 253 253 253 253 253 253 253
40090-253 253 253 253 253 253 253 253 253 253 253 253
40091-253 253 253 253 253 253 221 221 221 6 6 6
40092- 2 2 6 2 2 6 6 6 6 30 30 30
40093- 2 2 6 2 2 6 2 2 6 2 2 6
40094- 2 2 6 82 82 82 54 54 54 18 18 18
40095- 6 6 6 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 0 0 0
40099- 0 0 0 0 0 0 0 0 0 0 0 0
40100- 0 0 0 0 0 0 0 0 0 0 0 0
40101- 0 0 0 0 0 0 0 0 0 10 10 10
40102- 26 26 26 66 66 66 62 62 62 2 2 6
40103- 2 2 6 38 38 38 10 10 10 26 26 26
40104-238 238 238 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 231 231 231 238 238 238
40107-253 253 253 253 253 253 253 253 253 253 253 253
40108-253 253 253 253 253 253 253 253 253 253 253 253
40109-253 253 253 253 253 253 253 253 253 253 253 253
40110-253 253 253 253 253 253 253 253 253 253 253 253
40111-253 253 253 253 253 253 231 231 231 6 6 6
40112- 2 2 6 2 2 6 10 10 10 30 30 30
40113- 2 2 6 2 2 6 2 2 6 2 2 6
40114- 2 2 6 66 66 66 58 58 58 22 22 22
40115- 6 6 6 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 0 0 0 0 0 0
40119- 0 0 0 0 0 0 0 0 0 0 0 0
40120- 0 0 0 0 0 0 0 0 0 0 0 0
40121- 0 0 0 0 0 0 0 0 0 10 10 10
40122- 38 38 38 78 78 78 6 6 6 2 2 6
40123- 2 2 6 46 46 46 14 14 14 42 42 42
40124-246 246 246 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 231 231 231 242 242 242
40127-253 253 253 253 253 253 253 253 253 253 253 253
40128-253 253 253 253 253 253 253 253 253 253 253 253
40129-253 253 253 253 253 253 253 253 253 253 253 253
40130-253 253 253 253 253 253 253 253 253 253 253 253
40131-253 253 253 253 253 253 234 234 234 10 10 10
40132- 2 2 6 2 2 6 22 22 22 14 14 14
40133- 2 2 6 2 2 6 2 2 6 2 2 6
40134- 2 2 6 66 66 66 62 62 62 22 22 22
40135- 6 6 6 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 0 0 0 0 0 0
40139- 0 0 0 0 0 0 0 0 0 0 0 0
40140- 0 0 0 0 0 0 0 0 0 0 0 0
40141- 0 0 0 0 0 0 6 6 6 18 18 18
40142- 50 50 50 74 74 74 2 2 6 2 2 6
40143- 14 14 14 70 70 70 34 34 34 62 62 62
40144-250 250 250 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 231 231 231 246 246 246
40147-253 253 253 253 253 253 253 253 253 253 253 253
40148-253 253 253 253 253 253 253 253 253 253 253 253
40149-253 253 253 253 253 253 253 253 253 253 253 253
40150-253 253 253 253 253 253 253 253 253 253 253 253
40151-253 253 253 253 253 253 234 234 234 14 14 14
40152- 2 2 6 2 2 6 30 30 30 2 2 6
40153- 2 2 6 2 2 6 2 2 6 2 2 6
40154- 2 2 6 66 66 66 62 62 62 22 22 22
40155- 6 6 6 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 0 0 0 0 0 0
40159- 0 0 0 0 0 0 0 0 0 0 0 0
40160- 0 0 0 0 0 0 0 0 0 0 0 0
40161- 0 0 0 0 0 0 6 6 6 18 18 18
40162- 54 54 54 62 62 62 2 2 6 2 2 6
40163- 2 2 6 30 30 30 46 46 46 70 70 70
40164-250 250 250 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 231 231 231 246 246 246
40167-253 253 253 253 253 253 253 253 253 253 253 253
40168-253 253 253 253 253 253 253 253 253 253 253 253
40169-253 253 253 253 253 253 253 253 253 253 253 253
40170-253 253 253 253 253 253 253 253 253 253 253 253
40171-253 253 253 253 253 253 226 226 226 10 10 10
40172- 2 2 6 6 6 6 30 30 30 2 2 6
40173- 2 2 6 2 2 6 2 2 6 2 2 6
40174- 2 2 6 66 66 66 58 58 58 22 22 22
40175- 6 6 6 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 0 0 0 0 0 0
40179- 0 0 0 0 0 0 0 0 0 0 0 0
40180- 0 0 0 0 0 0 0 0 0 0 0 0
40181- 0 0 0 0 0 0 6 6 6 22 22 22
40182- 58 58 58 62 62 62 2 2 6 2 2 6
40183- 2 2 6 2 2 6 30 30 30 78 78 78
40184-250 250 250 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 231 231 231 246 246 246
40187-253 253 253 253 253 253 253 253 253 253 253 253
40188-253 253 253 253 253 253 253 253 253 253 253 253
40189-253 253 253 253 253 253 253 253 253 253 253 253
40190-253 253 253 253 253 253 253 253 253 253 253 253
40191-253 253 253 253 253 253 206 206 206 2 2 6
40192- 22 22 22 34 34 34 18 14 6 22 22 22
40193- 26 26 26 18 18 18 6 6 6 2 2 6
40194- 2 2 6 82 82 82 54 54 54 18 18 18
40195- 6 6 6 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 0 0 0
40198- 0 0 0 0 0 0 0 0 0 0 0 0
40199- 0 0 0 0 0 0 0 0 0 0 0 0
40200- 0 0 0 0 0 0 0 0 0 0 0 0
40201- 0 0 0 0 0 0 6 6 6 26 26 26
40202- 62 62 62 106 106 106 74 54 14 185 133 11
40203-210 162 10 121 92 8 6 6 6 62 62 62
40204-238 238 238 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 231 231 231 246 246 246
40207-253 253 253 253 253 253 253 253 253 253 253 253
40208-253 253 253 253 253 253 253 253 253 253 253 253
40209-253 253 253 253 253 253 253 253 253 253 253 253
40210-253 253 253 253 253 253 253 253 253 253 253 253
40211-253 253 253 253 253 253 158 158 158 18 18 18
40212- 14 14 14 2 2 6 2 2 6 2 2 6
40213- 6 6 6 18 18 18 66 66 66 38 38 38
40214- 6 6 6 94 94 94 50 50 50 18 18 18
40215- 6 6 6 0 0 0 0 0 0 0 0 0
40216- 0 0 0 0 0 0 0 0 0 0 0 0
40217- 0 0 0 0 0 0 0 0 0 0 0 0
40218- 0 0 0 0 0 0 0 0 0 0 0 0
40219- 0 0 0 0 0 0 0 0 0 0 0 0
40220- 0 0 0 0 0 0 0 0 0 6 6 6
40221- 10 10 10 10 10 10 18 18 18 38 38 38
40222- 78 78 78 142 134 106 216 158 10 242 186 14
40223-246 190 14 246 190 14 156 118 10 10 10 10
40224- 90 90 90 238 238 238 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 231 231 231 250 250 250
40227-253 253 253 253 253 253 253 253 253 253 253 253
40228-253 253 253 253 253 253 253 253 253 253 253 253
40229-253 253 253 253 253 253 253 253 253 253 253 253
40230-253 253 253 253 253 253 253 253 253 246 230 190
40231-238 204 91 238 204 91 181 142 44 37 26 9
40232- 2 2 6 2 2 6 2 2 6 2 2 6
40233- 2 2 6 2 2 6 38 38 38 46 46 46
40234- 26 26 26 106 106 106 54 54 54 18 18 18
40235- 6 6 6 0 0 0 0 0 0 0 0 0
40236- 0 0 0 0 0 0 0 0 0 0 0 0
40237- 0 0 0 0 0 0 0 0 0 0 0 0
40238- 0 0 0 0 0 0 0 0 0 0 0 0
40239- 0 0 0 0 0 0 0 0 0 0 0 0
40240- 0 0 0 6 6 6 14 14 14 22 22 22
40241- 30 30 30 38 38 38 50 50 50 70 70 70
40242-106 106 106 190 142 34 226 170 11 242 186 14
40243-246 190 14 246 190 14 246 190 14 154 114 10
40244- 6 6 6 74 74 74 226 226 226 253 253 253
40245-253 253 253 253 253 253 253 253 253 253 253 253
40246-253 253 253 253 253 253 231 231 231 250 250 250
40247-253 253 253 253 253 253 253 253 253 253 253 253
40248-253 253 253 253 253 253 253 253 253 253 253 253
40249-253 253 253 253 253 253 253 253 253 253 253 253
40250-253 253 253 253 253 253 253 253 253 228 184 62
40251-241 196 14 241 208 19 232 195 16 38 30 10
40252- 2 2 6 2 2 6 2 2 6 2 2 6
40253- 2 2 6 6 6 6 30 30 30 26 26 26
40254-203 166 17 154 142 90 66 66 66 26 26 26
40255- 6 6 6 0 0 0 0 0 0 0 0 0
40256- 0 0 0 0 0 0 0 0 0 0 0 0
40257- 0 0 0 0 0 0 0 0 0 0 0 0
40258- 0 0 0 0 0 0 0 0 0 0 0 0
40259- 0 0 0 0 0 0 0 0 0 0 0 0
40260- 6 6 6 18 18 18 38 38 38 58 58 58
40261- 78 78 78 86 86 86 101 101 101 123 123 123
40262-175 146 61 210 150 10 234 174 13 246 186 14
40263-246 190 14 246 190 14 246 190 14 238 190 10
40264-102 78 10 2 2 6 46 46 46 198 198 198
40265-253 253 253 253 253 253 253 253 253 253 253 253
40266-253 253 253 253 253 253 234 234 234 242 242 242
40267-253 253 253 253 253 253 253 253 253 253 253 253
40268-253 253 253 253 253 253 253 253 253 253 253 253
40269-253 253 253 253 253 253 253 253 253 253 253 253
40270-253 253 253 253 253 253 253 253 253 224 178 62
40271-242 186 14 241 196 14 210 166 10 22 18 6
40272- 2 2 6 2 2 6 2 2 6 2 2 6
40273- 2 2 6 2 2 6 6 6 6 121 92 8
40274-238 202 15 232 195 16 82 82 82 34 34 34
40275- 10 10 10 0 0 0 0 0 0 0 0 0
40276- 0 0 0 0 0 0 0 0 0 0 0 0
40277- 0 0 0 0 0 0 0 0 0 0 0 0
40278- 0 0 0 0 0 0 0 0 0 0 0 0
40279- 0 0 0 0 0 0 0 0 0 0 0 0
40280- 14 14 14 38 38 38 70 70 70 154 122 46
40281-190 142 34 200 144 11 197 138 11 197 138 11
40282-213 154 11 226 170 11 242 186 14 246 190 14
40283-246 190 14 246 190 14 246 190 14 246 190 14
40284-225 175 15 46 32 6 2 2 6 22 22 22
40285-158 158 158 250 250 250 253 253 253 253 253 253
40286-253 253 253 253 253 253 253 253 253 253 253 253
40287-253 253 253 253 253 253 253 253 253 253 253 253
40288-253 253 253 253 253 253 253 253 253 253 253 253
40289-253 253 253 253 253 253 253 253 253 253 253 253
40290-253 253 253 250 250 250 242 242 242 224 178 62
40291-239 182 13 236 186 11 213 154 11 46 32 6
40292- 2 2 6 2 2 6 2 2 6 2 2 6
40293- 2 2 6 2 2 6 61 42 6 225 175 15
40294-238 190 10 236 186 11 112 100 78 42 42 42
40295- 14 14 14 0 0 0 0 0 0 0 0 0
40296- 0 0 0 0 0 0 0 0 0 0 0 0
40297- 0 0 0 0 0 0 0 0 0 0 0 0
40298- 0 0 0 0 0 0 0 0 0 0 0 0
40299- 0 0 0 0 0 0 0 0 0 6 6 6
40300- 22 22 22 54 54 54 154 122 46 213 154 11
40301-226 170 11 230 174 11 226 170 11 226 170 11
40302-236 178 12 242 186 14 246 190 14 246 190 14
40303-246 190 14 246 190 14 246 190 14 246 190 14
40304-241 196 14 184 144 12 10 10 10 2 2 6
40305- 6 6 6 116 116 116 242 242 242 253 253 253
40306-253 253 253 253 253 253 253 253 253 253 253 253
40307-253 253 253 253 253 253 253 253 253 253 253 253
40308-253 253 253 253 253 253 253 253 253 253 253 253
40309-253 253 253 253 253 253 253 253 253 253 253 253
40310-253 253 253 231 231 231 198 198 198 214 170 54
40311-236 178 12 236 178 12 210 150 10 137 92 6
40312- 18 14 6 2 2 6 2 2 6 2 2 6
40313- 6 6 6 70 47 6 200 144 11 236 178 12
40314-239 182 13 239 182 13 124 112 88 58 58 58
40315- 22 22 22 6 6 6 0 0 0 0 0 0
40316- 0 0 0 0 0 0 0 0 0 0 0 0
40317- 0 0 0 0 0 0 0 0 0 0 0 0
40318- 0 0 0 0 0 0 0 0 0 0 0 0
40319- 0 0 0 0 0 0 0 0 0 10 10 10
40320- 30 30 30 70 70 70 180 133 36 226 170 11
40321-239 182 13 242 186 14 242 186 14 246 186 14
40322-246 190 14 246 190 14 246 190 14 246 190 14
40323-246 190 14 246 190 14 246 190 14 246 190 14
40324-246 190 14 232 195 16 98 70 6 2 2 6
40325- 2 2 6 2 2 6 66 66 66 221 221 221
40326-253 253 253 253 253 253 253 253 253 253 253 253
40327-253 253 253 253 253 253 253 253 253 253 253 253
40328-253 253 253 253 253 253 253 253 253 253 253 253
40329-253 253 253 253 253 253 253 253 253 253 253 253
40330-253 253 253 206 206 206 198 198 198 214 166 58
40331-230 174 11 230 174 11 216 158 10 192 133 9
40332-163 110 8 116 81 8 102 78 10 116 81 8
40333-167 114 7 197 138 11 226 170 11 239 182 13
40334-242 186 14 242 186 14 162 146 94 78 78 78
40335- 34 34 34 14 14 14 6 6 6 0 0 0
40336- 0 0 0 0 0 0 0 0 0 0 0 0
40337- 0 0 0 0 0 0 0 0 0 0 0 0
40338- 0 0 0 0 0 0 0 0 0 0 0 0
40339- 0 0 0 0 0 0 0 0 0 6 6 6
40340- 30 30 30 78 78 78 190 142 34 226 170 11
40341-239 182 13 246 190 14 246 190 14 246 190 14
40342-246 190 14 246 190 14 246 190 14 246 190 14
40343-246 190 14 246 190 14 246 190 14 246 190 14
40344-246 190 14 241 196 14 203 166 17 22 18 6
40345- 2 2 6 2 2 6 2 2 6 38 38 38
40346-218 218 218 253 253 253 253 253 253 253 253 253
40347-253 253 253 253 253 253 253 253 253 253 253 253
40348-253 253 253 253 253 253 253 253 253 253 253 253
40349-253 253 253 253 253 253 253 253 253 253 253 253
40350-250 250 250 206 206 206 198 198 198 202 162 69
40351-226 170 11 236 178 12 224 166 10 210 150 10
40352-200 144 11 197 138 11 192 133 9 197 138 11
40353-210 150 10 226 170 11 242 186 14 246 190 14
40354-246 190 14 246 186 14 225 175 15 124 112 88
40355- 62 62 62 30 30 30 14 14 14 6 6 6
40356- 0 0 0 0 0 0 0 0 0 0 0 0
40357- 0 0 0 0 0 0 0 0 0 0 0 0
40358- 0 0 0 0 0 0 0 0 0 0 0 0
40359- 0 0 0 0 0 0 0 0 0 10 10 10
40360- 30 30 30 78 78 78 174 135 50 224 166 10
40361-239 182 13 246 190 14 246 190 14 246 190 14
40362-246 190 14 246 190 14 246 190 14 246 190 14
40363-246 190 14 246 190 14 246 190 14 246 190 14
40364-246 190 14 246 190 14 241 196 14 139 102 15
40365- 2 2 6 2 2 6 2 2 6 2 2 6
40366- 78 78 78 250 250 250 253 253 253 253 253 253
40367-253 253 253 253 253 253 253 253 253 253 253 253
40368-253 253 253 253 253 253 253 253 253 253 253 253
40369-253 253 253 253 253 253 253 253 253 253 253 253
40370-250 250 250 214 214 214 198 198 198 190 150 46
40371-219 162 10 236 178 12 234 174 13 224 166 10
40372-216 158 10 213 154 11 213 154 11 216 158 10
40373-226 170 11 239 182 13 246 190 14 246 190 14
40374-246 190 14 246 190 14 242 186 14 206 162 42
40375-101 101 101 58 58 58 30 30 30 14 14 14
40376- 6 6 6 0 0 0 0 0 0 0 0 0
40377- 0 0 0 0 0 0 0 0 0 0 0 0
40378- 0 0 0 0 0 0 0 0 0 0 0 0
40379- 0 0 0 0 0 0 0 0 0 10 10 10
40380- 30 30 30 74 74 74 174 135 50 216 158 10
40381-236 178 12 246 190 14 246 190 14 246 190 14
40382-246 190 14 246 190 14 246 190 14 246 190 14
40383-246 190 14 246 190 14 246 190 14 246 190 14
40384-246 190 14 246 190 14 241 196 14 226 184 13
40385- 61 42 6 2 2 6 2 2 6 2 2 6
40386- 22 22 22 238 238 238 253 253 253 253 253 253
40387-253 253 253 253 253 253 253 253 253 253 253 253
40388-253 253 253 253 253 253 253 253 253 253 253 253
40389-253 253 253 253 253 253 253 253 253 253 253 253
40390-253 253 253 226 226 226 187 187 187 180 133 36
40391-216 158 10 236 178 12 239 182 13 236 178 12
40392-230 174 11 226 170 11 226 170 11 230 174 11
40393-236 178 12 242 186 14 246 190 14 246 190 14
40394-246 190 14 246 190 14 246 186 14 239 182 13
40395-206 162 42 106 106 106 66 66 66 34 34 34
40396- 14 14 14 6 6 6 0 0 0 0 0 0
40397- 0 0 0 0 0 0 0 0 0 0 0 0
40398- 0 0 0 0 0 0 0 0 0 0 0 0
40399- 0 0 0 0 0 0 0 0 0 6 6 6
40400- 26 26 26 70 70 70 163 133 67 213 154 11
40401-236 178 12 246 190 14 246 190 14 246 190 14
40402-246 190 14 246 190 14 246 190 14 246 190 14
40403-246 190 14 246 190 14 246 190 14 246 190 14
40404-246 190 14 246 190 14 246 190 14 241 196 14
40405-190 146 13 18 14 6 2 2 6 2 2 6
40406- 46 46 46 246 246 246 253 253 253 253 253 253
40407-253 253 253 253 253 253 253 253 253 253 253 253
40408-253 253 253 253 253 253 253 253 253 253 253 253
40409-253 253 253 253 253 253 253 253 253 253 253 253
40410-253 253 253 221 221 221 86 86 86 156 107 11
40411-216 158 10 236 178 12 242 186 14 246 186 14
40412-242 186 14 239 182 13 239 182 13 242 186 14
40413-242 186 14 246 186 14 246 190 14 246 190 14
40414-246 190 14 246 190 14 246 190 14 246 190 14
40415-242 186 14 225 175 15 142 122 72 66 66 66
40416- 30 30 30 10 10 10 0 0 0 0 0 0
40417- 0 0 0 0 0 0 0 0 0 0 0 0
40418- 0 0 0 0 0 0 0 0 0 0 0 0
40419- 0 0 0 0 0 0 0 0 0 6 6 6
40420- 26 26 26 70 70 70 163 133 67 210 150 10
40421-236 178 12 246 190 14 246 190 14 246 190 14
40422-246 190 14 246 190 14 246 190 14 246 190 14
40423-246 190 14 246 190 14 246 190 14 246 190 14
40424-246 190 14 246 190 14 246 190 14 246 190 14
40425-232 195 16 121 92 8 34 34 34 106 106 106
40426-221 221 221 253 253 253 253 253 253 253 253 253
40427-253 253 253 253 253 253 253 253 253 253 253 253
40428-253 253 253 253 253 253 253 253 253 253 253 253
40429-253 253 253 253 253 253 253 253 253 253 253 253
40430-242 242 242 82 82 82 18 14 6 163 110 8
40431-216 158 10 236 178 12 242 186 14 246 190 14
40432-246 190 14 246 190 14 246 190 14 246 190 14
40433-246 190 14 246 190 14 246 190 14 246 190 14
40434-246 190 14 246 190 14 246 190 14 246 190 14
40435-246 190 14 246 190 14 242 186 14 163 133 67
40436- 46 46 46 18 18 18 6 6 6 0 0 0
40437- 0 0 0 0 0 0 0 0 0 0 0 0
40438- 0 0 0 0 0 0 0 0 0 0 0 0
40439- 0 0 0 0 0 0 0 0 0 10 10 10
40440- 30 30 30 78 78 78 163 133 67 210 150 10
40441-236 178 12 246 186 14 246 190 14 246 190 14
40442-246 190 14 246 190 14 246 190 14 246 190 14
40443-246 190 14 246 190 14 246 190 14 246 190 14
40444-246 190 14 246 190 14 246 190 14 246 190 14
40445-241 196 14 215 174 15 190 178 144 253 253 253
40446-253 253 253 253 253 253 253 253 253 253 253 253
40447-253 253 253 253 253 253 253 253 253 253 253 253
40448-253 253 253 253 253 253 253 253 253 253 253 253
40449-253 253 253 253 253 253 253 253 253 218 218 218
40450- 58 58 58 2 2 6 22 18 6 167 114 7
40451-216 158 10 236 178 12 246 186 14 246 190 14
40452-246 190 14 246 190 14 246 190 14 246 190 14
40453-246 190 14 246 190 14 246 190 14 246 190 14
40454-246 190 14 246 190 14 246 190 14 246 190 14
40455-246 190 14 246 186 14 242 186 14 190 150 46
40456- 54 54 54 22 22 22 6 6 6 0 0 0
40457- 0 0 0 0 0 0 0 0 0 0 0 0
40458- 0 0 0 0 0 0 0 0 0 0 0 0
40459- 0 0 0 0 0 0 0 0 0 14 14 14
40460- 38 38 38 86 86 86 180 133 36 213 154 11
40461-236 178 12 246 186 14 246 190 14 246 190 14
40462-246 190 14 246 190 14 246 190 14 246 190 14
40463-246 190 14 246 190 14 246 190 14 246 190 14
40464-246 190 14 246 190 14 246 190 14 246 190 14
40465-246 190 14 232 195 16 190 146 13 214 214 214
40466-253 253 253 253 253 253 253 253 253 253 253 253
40467-253 253 253 253 253 253 253 253 253 253 253 253
40468-253 253 253 253 253 253 253 253 253 253 253 253
40469-253 253 253 250 250 250 170 170 170 26 26 26
40470- 2 2 6 2 2 6 37 26 9 163 110 8
40471-219 162 10 239 182 13 246 186 14 246 190 14
40472-246 190 14 246 190 14 246 190 14 246 190 14
40473-246 190 14 246 190 14 246 190 14 246 190 14
40474-246 190 14 246 190 14 246 190 14 246 190 14
40475-246 186 14 236 178 12 224 166 10 142 122 72
40476- 46 46 46 18 18 18 6 6 6 0 0 0
40477- 0 0 0 0 0 0 0 0 0 0 0 0
40478- 0 0 0 0 0 0 0 0 0 0 0 0
40479- 0 0 0 0 0 0 6 6 6 18 18 18
40480- 50 50 50 109 106 95 192 133 9 224 166 10
40481-242 186 14 246 190 14 246 190 14 246 190 14
40482-246 190 14 246 190 14 246 190 14 246 190 14
40483-246 190 14 246 190 14 246 190 14 246 190 14
40484-246 190 14 246 190 14 246 190 14 246 190 14
40485-242 186 14 226 184 13 210 162 10 142 110 46
40486-226 226 226 253 253 253 253 253 253 253 253 253
40487-253 253 253 253 253 253 253 253 253 253 253 253
40488-253 253 253 253 253 253 253 253 253 253 253 253
40489-198 198 198 66 66 66 2 2 6 2 2 6
40490- 2 2 6 2 2 6 50 34 6 156 107 11
40491-219 162 10 239 182 13 246 186 14 246 190 14
40492-246 190 14 246 190 14 246 190 14 246 190 14
40493-246 190 14 246 190 14 246 190 14 246 190 14
40494-246 190 14 246 190 14 246 190 14 242 186 14
40495-234 174 13 213 154 11 154 122 46 66 66 66
40496- 30 30 30 10 10 10 0 0 0 0 0 0
40497- 0 0 0 0 0 0 0 0 0 0 0 0
40498- 0 0 0 0 0 0 0 0 0 0 0 0
40499- 0 0 0 0 0 0 6 6 6 22 22 22
40500- 58 58 58 154 121 60 206 145 10 234 174 13
40501-242 186 14 246 186 14 246 190 14 246 190 14
40502-246 190 14 246 190 14 246 190 14 246 190 14
40503-246 190 14 246 190 14 246 190 14 246 190 14
40504-246 190 14 246 190 14 246 190 14 246 190 14
40505-246 186 14 236 178 12 210 162 10 163 110 8
40506- 61 42 6 138 138 138 218 218 218 250 250 250
40507-253 253 253 253 253 253 253 253 253 250 250 250
40508-242 242 242 210 210 210 144 144 144 66 66 66
40509- 6 6 6 2 2 6 2 2 6 2 2 6
40510- 2 2 6 2 2 6 61 42 6 163 110 8
40511-216 158 10 236 178 12 246 190 14 246 190 14
40512-246 190 14 246 190 14 246 190 14 246 190 14
40513-246 190 14 246 190 14 246 190 14 246 190 14
40514-246 190 14 239 182 13 230 174 11 216 158 10
40515-190 142 34 124 112 88 70 70 70 38 38 38
40516- 18 18 18 6 6 6 0 0 0 0 0 0
40517- 0 0 0 0 0 0 0 0 0 0 0 0
40518- 0 0 0 0 0 0 0 0 0 0 0 0
40519- 0 0 0 0 0 0 6 6 6 22 22 22
40520- 62 62 62 168 124 44 206 145 10 224 166 10
40521-236 178 12 239 182 13 242 186 14 242 186 14
40522-246 186 14 246 190 14 246 190 14 246 190 14
40523-246 190 14 246 190 14 246 190 14 246 190 14
40524-246 190 14 246 190 14 246 190 14 246 190 14
40525-246 190 14 236 178 12 216 158 10 175 118 6
40526- 80 54 7 2 2 6 6 6 6 30 30 30
40527- 54 54 54 62 62 62 50 50 50 38 38 38
40528- 14 14 14 2 2 6 2 2 6 2 2 6
40529- 2 2 6 2 2 6 2 2 6 2 2 6
40530- 2 2 6 6 6 6 80 54 7 167 114 7
40531-213 154 11 236 178 12 246 190 14 246 190 14
40532-246 190 14 246 190 14 246 190 14 246 190 14
40533-246 190 14 242 186 14 239 182 13 239 182 13
40534-230 174 11 210 150 10 174 135 50 124 112 88
40535- 82 82 82 54 54 54 34 34 34 18 18 18
40536- 6 6 6 0 0 0 0 0 0 0 0 0
40537- 0 0 0 0 0 0 0 0 0 0 0 0
40538- 0 0 0 0 0 0 0 0 0 0 0 0
40539- 0 0 0 0 0 0 6 6 6 18 18 18
40540- 50 50 50 158 118 36 192 133 9 200 144 11
40541-216 158 10 219 162 10 224 166 10 226 170 11
40542-230 174 11 236 178 12 239 182 13 239 182 13
40543-242 186 14 246 186 14 246 190 14 246 190 14
40544-246 190 14 246 190 14 246 190 14 246 190 14
40545-246 186 14 230 174 11 210 150 10 163 110 8
40546-104 69 6 10 10 10 2 2 6 2 2 6
40547- 2 2 6 2 2 6 2 2 6 2 2 6
40548- 2 2 6 2 2 6 2 2 6 2 2 6
40549- 2 2 6 2 2 6 2 2 6 2 2 6
40550- 2 2 6 6 6 6 91 60 6 167 114 7
40551-206 145 10 230 174 11 242 186 14 246 190 14
40552-246 190 14 246 190 14 246 186 14 242 186 14
40553-239 182 13 230 174 11 224 166 10 213 154 11
40554-180 133 36 124 112 88 86 86 86 58 58 58
40555- 38 38 38 22 22 22 10 10 10 6 6 6
40556- 0 0 0 0 0 0 0 0 0 0 0 0
40557- 0 0 0 0 0 0 0 0 0 0 0 0
40558- 0 0 0 0 0 0 0 0 0 0 0 0
40559- 0 0 0 0 0 0 0 0 0 14 14 14
40560- 34 34 34 70 70 70 138 110 50 158 118 36
40561-167 114 7 180 123 7 192 133 9 197 138 11
40562-200 144 11 206 145 10 213 154 11 219 162 10
40563-224 166 10 230 174 11 239 182 13 242 186 14
40564-246 186 14 246 186 14 246 186 14 246 186 14
40565-239 182 13 216 158 10 185 133 11 152 99 6
40566-104 69 6 18 14 6 2 2 6 2 2 6
40567- 2 2 6 2 2 6 2 2 6 2 2 6
40568- 2 2 6 2 2 6 2 2 6 2 2 6
40569- 2 2 6 2 2 6 2 2 6 2 2 6
40570- 2 2 6 6 6 6 80 54 7 152 99 6
40571-192 133 9 219 162 10 236 178 12 239 182 13
40572-246 186 14 242 186 14 239 182 13 236 178 12
40573-224 166 10 206 145 10 192 133 9 154 121 60
40574- 94 94 94 62 62 62 42 42 42 22 22 22
40575- 14 14 14 6 6 6 0 0 0 0 0 0
40576- 0 0 0 0 0 0 0 0 0 0 0 0
40577- 0 0 0 0 0 0 0 0 0 0 0 0
40578- 0 0 0 0 0 0 0 0 0 0 0 0
40579- 0 0 0 0 0 0 0 0 0 6 6 6
40580- 18 18 18 34 34 34 58 58 58 78 78 78
40581-101 98 89 124 112 88 142 110 46 156 107 11
40582-163 110 8 167 114 7 175 118 6 180 123 7
40583-185 133 11 197 138 11 210 150 10 219 162 10
40584-226 170 11 236 178 12 236 178 12 234 174 13
40585-219 162 10 197 138 11 163 110 8 130 83 6
40586- 91 60 6 10 10 10 2 2 6 2 2 6
40587- 18 18 18 38 38 38 38 38 38 38 38 38
40588- 38 38 38 38 38 38 38 38 38 38 38 38
40589- 38 38 38 38 38 38 26 26 26 2 2 6
40590- 2 2 6 6 6 6 70 47 6 137 92 6
40591-175 118 6 200 144 11 219 162 10 230 174 11
40592-234 174 13 230 174 11 219 162 10 210 150 10
40593-192 133 9 163 110 8 124 112 88 82 82 82
40594- 50 50 50 30 30 30 14 14 14 6 6 6
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 0 0 0 0 0 0
40598- 0 0 0 0 0 0 0 0 0 0 0 0
40599- 0 0 0 0 0 0 0 0 0 0 0 0
40600- 6 6 6 14 14 14 22 22 22 34 34 34
40601- 42 42 42 58 58 58 74 74 74 86 86 86
40602-101 98 89 122 102 70 130 98 46 121 87 25
40603-137 92 6 152 99 6 163 110 8 180 123 7
40604-185 133 11 197 138 11 206 145 10 200 144 11
40605-180 123 7 156 107 11 130 83 6 104 69 6
40606- 50 34 6 54 54 54 110 110 110 101 98 89
40607- 86 86 86 82 82 82 78 78 78 78 78 78
40608- 78 78 78 78 78 78 78 78 78 78 78 78
40609- 78 78 78 82 82 82 86 86 86 94 94 94
40610-106 106 106 101 101 101 86 66 34 124 80 6
40611-156 107 11 180 123 7 192 133 9 200 144 11
40612-206 145 10 200 144 11 192 133 9 175 118 6
40613-139 102 15 109 106 95 70 70 70 42 42 42
40614- 22 22 22 10 10 10 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 0 0 0 0 0 0 0 0 0
40619- 0 0 0 0 0 0 0 0 0 0 0 0
40620- 0 0 0 0 0 0 6 6 6 10 10 10
40621- 14 14 14 22 22 22 30 30 30 38 38 38
40622- 50 50 50 62 62 62 74 74 74 90 90 90
40623-101 98 89 112 100 78 121 87 25 124 80 6
40624-137 92 6 152 99 6 152 99 6 152 99 6
40625-138 86 6 124 80 6 98 70 6 86 66 30
40626-101 98 89 82 82 82 58 58 58 46 46 46
40627- 38 38 38 34 34 34 34 34 34 34 34 34
40628- 34 34 34 34 34 34 34 34 34 34 34 34
40629- 34 34 34 34 34 34 38 38 38 42 42 42
40630- 54 54 54 82 82 82 94 86 76 91 60 6
40631-134 86 6 156 107 11 167 114 7 175 118 6
40632-175 118 6 167 114 7 152 99 6 121 87 25
40633-101 98 89 62 62 62 34 34 34 18 18 18
40634- 6 6 6 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 0 0 0 0 0 0 0 0 0
40640- 0 0 0 0 0 0 0 0 0 0 0 0
40641- 0 0 0 6 6 6 6 6 6 10 10 10
40642- 18 18 18 22 22 22 30 30 30 42 42 42
40643- 50 50 50 66 66 66 86 86 86 101 98 89
40644-106 86 58 98 70 6 104 69 6 104 69 6
40645-104 69 6 91 60 6 82 62 34 90 90 90
40646- 62 62 62 38 38 38 22 22 22 14 14 14
40647- 10 10 10 10 10 10 10 10 10 10 10 10
40648- 10 10 10 10 10 10 6 6 6 10 10 10
40649- 10 10 10 10 10 10 10 10 10 14 14 14
40650- 22 22 22 42 42 42 70 70 70 89 81 66
40651- 80 54 7 104 69 6 124 80 6 137 92 6
40652-134 86 6 116 81 8 100 82 52 86 86 86
40653- 58 58 58 30 30 30 14 14 14 6 6 6
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- 0 0 0 0 0 0 0 0 0 0 0 0
40661- 0 0 0 0 0 0 0 0 0 0 0 0
40662- 0 0 0 6 6 6 10 10 10 14 14 14
40663- 18 18 18 26 26 26 38 38 38 54 54 54
40664- 70 70 70 86 86 86 94 86 76 89 81 66
40665- 89 81 66 86 86 86 74 74 74 50 50 50
40666- 30 30 30 14 14 14 6 6 6 0 0 0
40667- 0 0 0 0 0 0 0 0 0 0 0 0
40668- 0 0 0 0 0 0 0 0 0 0 0 0
40669- 0 0 0 0 0 0 0 0 0 0 0 0
40670- 6 6 6 18 18 18 34 34 34 58 58 58
40671- 82 82 82 89 81 66 89 81 66 89 81 66
40672- 94 86 66 94 86 76 74 74 74 50 50 50
40673- 26 26 26 14 14 14 6 6 6 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 0 0 0
40681- 0 0 0 0 0 0 0 0 0 0 0 0
40682- 0 0 0 0 0 0 0 0 0 0 0 0
40683- 6 6 6 6 6 6 14 14 14 18 18 18
40684- 30 30 30 38 38 38 46 46 46 54 54 54
40685- 50 50 50 42 42 42 30 30 30 18 18 18
40686- 10 10 10 0 0 0 0 0 0 0 0 0
40687- 0 0 0 0 0 0 0 0 0 0 0 0
40688- 0 0 0 0 0 0 0 0 0 0 0 0
40689- 0 0 0 0 0 0 0 0 0 0 0 0
40690- 0 0 0 6 6 6 14 14 14 26 26 26
40691- 38 38 38 50 50 50 58 58 58 58 58 58
40692- 54 54 54 42 42 42 30 30 30 18 18 18
40693- 10 10 10 0 0 0 0 0 0 0 0 0
40694- 0 0 0 0 0 0 0 0 0 0 0 0
40695- 0 0 0 0 0 0 0 0 0 0 0 0
40696- 0 0 0 0 0 0 0 0 0 0 0 0
40697- 0 0 0 0 0 0 0 0 0 0 0 0
40698- 0 0 0 0 0 0 0 0 0 0 0 0
40699- 0 0 0 0 0 0 0 0 0 0 0 0
40700- 0 0 0 0 0 0 0 0 0 0 0 0
40701- 0 0 0 0 0 0 0 0 0 0 0 0
40702- 0 0 0 0 0 0 0 0 0 0 0 0
40703- 0 0 0 0 0 0 0 0 0 6 6 6
40704- 6 6 6 10 10 10 14 14 14 18 18 18
40705- 18 18 18 14 14 14 10 10 10 6 6 6
40706- 0 0 0 0 0 0 0 0 0 0 0 0
40707- 0 0 0 0 0 0 0 0 0 0 0 0
40708- 0 0 0 0 0 0 0 0 0 0 0 0
40709- 0 0 0 0 0 0 0 0 0 0 0 0
40710- 0 0 0 0 0 0 0 0 0 6 6 6
40711- 14 14 14 18 18 18 22 22 22 22 22 22
40712- 18 18 18 14 14 14 10 10 10 6 6 6
40713- 0 0 0 0 0 0 0 0 0 0 0 0
40714- 0 0 0 0 0 0 0 0 0 0 0 0
40715- 0 0 0 0 0 0 0 0 0 0 0 0
40716- 0 0 0 0 0 0 0 0 0 0 0 0
40717- 0 0 0 0 0 0 0 0 0 0 0 0
40718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40719+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40720+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40721+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40727+4 4 4 4 4 4 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
40732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40733+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40734+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40735+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40736+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40738+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40741+4 4 4 4 4 4 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
40746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40747+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40748+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40755+4 4 4 4 4 4 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
40760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40761+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40762+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40766+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40769+4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
40779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40780+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40781+4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
40784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40786+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40787+4 4 4 4 4 4
40788+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40789+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40793+4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
40798+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40799+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40800+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40801+4 4 4 4 4 4
40802+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40803+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40804+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40806+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
40807+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
40812+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40813+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
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
40816+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40817+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40818+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40820+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
40821+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
40822+5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
40825+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
40826+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
40827+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
40828+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40829+4 4 4 4 4 4
40830+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40831+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40834+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
40835+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
40836+0 0 0 3 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40839+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
40840+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
40841+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
40842+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
40843+4 4 4 4 4 4
40844+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40845+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40846+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40847+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
40848+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
40849+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
40850+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
40851+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40852+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40853+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
40854+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
40855+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
40856+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
40857+4 4 4 4 4 4
40858+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40859+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40860+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40861+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
40862+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
40863+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
40864+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
40865+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40866+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
40867+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
40868+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
40869+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
40870+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
40871+4 4 4 4 4 4
40872+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40873+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40874+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40875+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
40876+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
40877+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
40878+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
40879+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
40880+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
40881+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
40882+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
40883+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
40884+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
40885+4 4 4 4 4 4
40886+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40887+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40888+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
40889+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
40890+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
40891+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
40892+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
40893+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
40894+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
40895+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
40896+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
40897+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
40898+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
40899+4 4 4 4 4 4
40900+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40901+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40902+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
40903+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
40904+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
40905+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
40906+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
40907+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
40908+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
40909+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
40910+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
40911+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
40912+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
40913+4 4 4 4 4 4
40914+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40915+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40916+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
40917+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
40918+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
40919+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
40920+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
40921+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
40922+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
40923+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
40924+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
40925+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
40926+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40927+4 4 4 4 4 4
40928+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40929+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40930+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
40931+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
40932+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
40933+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
40934+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
40935+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
40936+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
40937+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
40938+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
40939+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
40940+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
40941+4 4 4 4 4 4
40942+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40943+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
40944+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
40945+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
40946+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
40947+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
40948+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
40949+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
40950+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
40951+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
40952+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
40953+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
40954+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
40955+4 4 4 4 4 4
40956+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40957+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
40958+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
40959+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
40960+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
40961+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
40962+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
40963+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
40964+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
40965+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
40966+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
40967+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
40968+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
40969+0 0 0 4 4 4
40970+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40971+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
40972+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
40973+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
40974+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
40975+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
40976+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
40977+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
40978+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
40979+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
40980+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
40981+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
40982+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
40983+2 0 0 0 0 0
40984+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
40985+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
40986+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
40987+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
40988+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
40989+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
40990+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
40991+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
40992+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
40993+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
40994+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
40995+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
40996+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
40997+37 38 37 0 0 0
40998+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40999+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
41000+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
41001+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
41002+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
41003+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
41004+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
41005+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
41006+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
41007+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
41008+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
41009+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
41010+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
41011+85 115 134 4 0 0
41012+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
41013+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
41014+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
41015+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
41016+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
41017+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
41018+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
41019+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
41020+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
41021+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
41022+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
41023+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
41024+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
41025+60 73 81 4 0 0
41026+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
41027+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
41028+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
41029+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
41030+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
41031+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41032+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41033+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41034+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41035+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41036+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41037+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41038+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41039+16 19 21 4 0 0
41040+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41041+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41042+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41043+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41044+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41045+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41046+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41047+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41048+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41049+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41050+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41051+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41052+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41053+4 0 0 4 3 3
41054+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41055+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41056+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41057+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41058+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41059+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41060+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41061+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41062+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41063+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41064+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41065+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41066+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41067+3 2 2 4 4 4
41068+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41069+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41070+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41071+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41072+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41073+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41074+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41075+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41076+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41077+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41078+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41079+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41080+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41081+4 4 4 4 4 4
41082+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41083+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41084+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41085+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41086+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41087+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41088+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41089+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41090+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41091+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41092+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41093+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41094+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41095+4 4 4 4 4 4
41096+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41097+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41098+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41099+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41100+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41101+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41102+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41103+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41104+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41105+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41106+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41107+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41108+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41109+5 5 5 5 5 5
41110+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41111+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41112+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41113+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41114+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41115+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41116+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41117+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41118+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41119+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41120+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41121+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41122+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41123+5 5 5 4 4 4
41124+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41125+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41126+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41127+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41128+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41129+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41130+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41131+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41132+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41133+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41134+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41135+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41136+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41137+4 4 4 4 4 4
41138+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41139+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41140+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41141+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41142+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41143+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41144+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41145+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41146+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41147+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41148+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41149+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
41150+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41151+4 4 4 4 4 4
41152+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
41153+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41154+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41155+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41156+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41157+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41158+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41159+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41160+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41161+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41162+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
41163+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41164+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41165+4 4 4 4 4 4
41166+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41167+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41168+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41169+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41170+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41171+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41172+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41173+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41174+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41175+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41176+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
41177+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41178+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41179+4 4 4 4 4 4
41180+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41181+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41182+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41183+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41184+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41185+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41186+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41187+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41188+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41189+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41190+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41191+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41192+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41193+4 4 4 4 4 4
41194+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41195+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
41196+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
41197+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
41198+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41199+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
41200+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
41201+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
41202+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
41203+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
41204+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
41205+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41206+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41207+4 4 4 4 4 4
41208+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
41209+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
41210+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
41211+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
41212+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41213+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
41214+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
41215+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
41216+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
41217+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
41218+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
41219+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41220+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41221+4 4 4 4 4 4
41222+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
41223+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
41224+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
41225+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41226+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
41227+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
41228+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
41229+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
41230+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
41231+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
41232+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41233+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41234+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41235+4 4 4 4 4 4
41236+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
41237+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
41238+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
41239+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41240+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41241+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
41242+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
41243+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
41244+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
41245+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
41246+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41247+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41248+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41249+4 4 4 4 4 4
41250+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
41251+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
41252+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41253+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41254+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41255+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
41256+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
41257+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
41258+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
41259+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
41260+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41261+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41262+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41263+4 4 4 4 4 4
41264+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41265+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41266+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41267+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41268+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41269+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41270+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41271+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41272+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41273+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41274+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41275+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41276+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41277+4 4 4 4 4 4
41278+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41279+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41280+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41281+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41282+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41283+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41284+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41285+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41286+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41287+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41288+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41289+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41290+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41291+4 4 4 4 4 4
41292+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41293+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41294+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41295+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41296+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41297+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41298+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41299+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41300+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41301+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41302+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41303+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41304+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41305+4 4 4 4 4 4
41306+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41307+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41308+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41309+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41310+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41311+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41312+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41313+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41314+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41315+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41316+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41317+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41318+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41319+4 4 4 4 4 4
41320+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41321+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41322+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41323+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41324+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41325+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41326+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41327+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41328+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41329+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41330+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41331+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41332+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41333+4 4 4 4 4 4
41334+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41335+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41336+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41337+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41338+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41339+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41340+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41341+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41342+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41343+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41344+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41345+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41346+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41347+4 4 4 4 4 4
41348+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41349+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41350+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41351+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41352+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41353+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41354+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41355+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41356+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41357+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41358+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41359+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41360+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41361+4 4 4 4 4 4
41362+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41363+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41364+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41365+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41366+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41367+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41368+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41369+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41370+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41371+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41372+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41373+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41374+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41375+4 4 4 4 4 4
41376+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41377+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41378+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41379+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41380+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41381+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41382+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41383+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41384+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41385+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41386+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41387+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41388+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41389+4 4 4 4 4 4
41390+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41391+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41392+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41393+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41394+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41395+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41396+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41397+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41398+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41399+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41400+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41401+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41402+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41403+4 4 4 4 4 4
41404+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41405+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41406+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41407+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41408+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41409+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41410+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41411+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41412+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41413+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41414+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41415+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41416+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41417+4 4 4 4 4 4
41418+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41419+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41420+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41421+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41422+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41423+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41424+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41425+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41426+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41427+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41428+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41429+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41430+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41431+4 4 4 4 4 4
41432+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41433+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41434+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41435+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41436+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41437+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41438+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41439+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41440+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41441+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41442+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41443+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41444+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41445+4 4 4 4 4 4
41446+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
41447+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
41448+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
41449+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
41450+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41451+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
41452+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
41453+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
41454+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
41455+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41456+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41457+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41458+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41459+4 4 4 4 4 4
41460+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41461+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
41462+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
41463+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
41464+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
41465+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
41466+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
41467+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
41468+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
41469+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41470+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41471+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41472+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41473+4 4 4 4 4 4
41474+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
41475+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
41476+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
41477+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
41478+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
41479+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
41480+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
41481+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
41482+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
41483+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
41484+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41485+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41486+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41487+4 4 4 4 4 4
41488+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
41489+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41490+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
41491+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
41492+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
41493+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
41494+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
41495+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
41496+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
41497+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
41498+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41499+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41500+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41501+4 4 4 4 4 4
41502+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
41503+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41504+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
41505+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
41506+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
41507+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
41508+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41509+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
41510+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
41511+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
41512+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41513+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41514+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41515+4 4 4 4 4 4
41516+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
41517+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
41518+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
41519+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
41520+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
41521+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
41522+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
41523+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
41524+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
41525+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
41526+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41527+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41528+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41529+4 4 4 4 4 4
41530+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
41531+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
41532+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41533+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
41534+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
41535+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
41536+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
41537+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
41538+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
41539+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
41540+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41541+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41542+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41543+4 4 4 4 4 4
41544+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41545+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
41546+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
41547+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
41548+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
41549+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
41550+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
41551+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
41552+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
41553+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41554+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41555+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41556+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41557+4 4 4 4 4 4
41558+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
41559+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
41560+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
41561+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
41562+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
41563+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
41564+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
41565+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
41566+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
41567+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41568+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41569+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41570+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41571+4 4 4 4 4 4
41572+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
41573+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
41574+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
41575+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
41576+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
41577+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
41578+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
41579+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
41580+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41581+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41582+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41583+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41584+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41585+4 4 4 4 4 4
41586+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
41587+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41588+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
41589+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41590+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
41591+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
41592+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
41593+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
41594+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
41595+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41596+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41597+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41598+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41599+4 4 4 4 4 4
41600+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
41601+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
41602+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
41603+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
41604+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
41605+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
41606+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
41607+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
41608+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
41609+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41610+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41611+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41612+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41613+4 4 4 4 4 4
41614+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41615+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
41616+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
41617+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
41618+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
41619+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
41620+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
41621+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
41622+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41623+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41624+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41625+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41626+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41627+4 4 4 4 4 4
41628+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
41629+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
41630+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41631+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
41632+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
41633+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
41634+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
41635+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
41636+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41637+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41638+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41639+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41640+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41641+4 4 4 4 4 4
41642+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41643+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
41644+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
41645+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
41646+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
41647+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
41648+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
41649+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41650+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41651+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41652+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41653+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41654+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41655+4 4 4 4 4 4
41656+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41657+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
41658+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41659+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
41660+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
41661+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
41662+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
41663+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
41664+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41665+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41666+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41668+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41669+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 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
41672+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
41673+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
41674+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
41675+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
41676+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
41677+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
41678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41682+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41683+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 5 5 5 5 5 5 5 5 5
41686+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
41687+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41688+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
41689+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
41690+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
41691+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41697+4 4 4 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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41701+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
41702+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
41703+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
41704+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
41705+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41707+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41710+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41711+4 4 4 4 4 4
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 5 5 5
41715+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41716+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
41717+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
41718+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
41719+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41720+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41721+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41725+4 4 4 4 4 4
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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41730+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41731+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
41732+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
41733+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41734+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41735+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41736+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41738+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41739+4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5 6 6 6
41744+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41745+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41746+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
41747+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41748+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41753+4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5
41758+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
41759+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
41760+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
41761+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41762+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41766+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41767+4 4 4 4 4 4
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 5 5 5
41772+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
41773+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41774+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41775+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41780+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41781+4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
41787+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
41788+4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4
41792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41794+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41795+4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
41801+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
41802+5 5 5 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 4 4 4 4 4 4
41806+4 4 4 4 4 4 4 4 4 4 4 4 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
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 4 4 4 5 5 5 4 3 3 6 6 6
41815+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
41816+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41817+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41818+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41820+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41821+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41822+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41823+4 4 4 4 4 4
41824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41825+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41826+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41827+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41828+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41829+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
41830+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41831+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41834+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41835+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41836+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41837+4 4 4 4 4 4
41838diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
41839index 8af6414..658c030 100644
41840--- a/drivers/video/udlfb.c
41841+++ b/drivers/video/udlfb.c
41842@@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
41843 dlfb_urb_completion(urb);
41844
41845 error:
41846- atomic_add(bytes_sent, &dev->bytes_sent);
41847- atomic_add(bytes_identical, &dev->bytes_identical);
41848- atomic_add(width*height*2, &dev->bytes_rendered);
41849+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41850+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41851+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
41852 end_cycles = get_cycles();
41853- atomic_add(((unsigned int) ((end_cycles - start_cycles)
41854+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41855 >> 10)), /* Kcycles */
41856 &dev->cpu_kcycles_used);
41857
41858@@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
41859 dlfb_urb_completion(urb);
41860
41861 error:
41862- atomic_add(bytes_sent, &dev->bytes_sent);
41863- atomic_add(bytes_identical, &dev->bytes_identical);
41864- atomic_add(bytes_rendered, &dev->bytes_rendered);
41865+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41866+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41867+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
41868 end_cycles = get_cycles();
41869- atomic_add(((unsigned int) ((end_cycles - start_cycles)
41870+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41871 >> 10)), /* Kcycles */
41872 &dev->cpu_kcycles_used);
41873 }
41874@@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
41875 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41876 struct dlfb_data *dev = fb_info->par;
41877 return snprintf(buf, PAGE_SIZE, "%u\n",
41878- atomic_read(&dev->bytes_rendered));
41879+ atomic_read_unchecked(&dev->bytes_rendered));
41880 }
41881
41882 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41883@@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41884 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41885 struct dlfb_data *dev = fb_info->par;
41886 return snprintf(buf, PAGE_SIZE, "%u\n",
41887- atomic_read(&dev->bytes_identical));
41888+ atomic_read_unchecked(&dev->bytes_identical));
41889 }
41890
41891 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41892@@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41893 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41894 struct dlfb_data *dev = fb_info->par;
41895 return snprintf(buf, PAGE_SIZE, "%u\n",
41896- atomic_read(&dev->bytes_sent));
41897+ atomic_read_unchecked(&dev->bytes_sent));
41898 }
41899
41900 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41901@@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41902 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41903 struct dlfb_data *dev = fb_info->par;
41904 return snprintf(buf, PAGE_SIZE, "%u\n",
41905- atomic_read(&dev->cpu_kcycles_used));
41906+ atomic_read_unchecked(&dev->cpu_kcycles_used));
41907 }
41908
41909 static ssize_t edid_show(
41910@@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
41911 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41912 struct dlfb_data *dev = fb_info->par;
41913
41914- atomic_set(&dev->bytes_rendered, 0);
41915- atomic_set(&dev->bytes_identical, 0);
41916- atomic_set(&dev->bytes_sent, 0);
41917- atomic_set(&dev->cpu_kcycles_used, 0);
41918+ atomic_set_unchecked(&dev->bytes_rendered, 0);
41919+ atomic_set_unchecked(&dev->bytes_identical, 0);
41920+ atomic_set_unchecked(&dev->bytes_sent, 0);
41921+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
41922
41923 return count;
41924 }
41925diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
41926index b0e2a42..e2df3ad 100644
41927--- a/drivers/video/uvesafb.c
41928+++ b/drivers/video/uvesafb.c
41929@@ -19,6 +19,7 @@
41930 #include <linux/io.h>
41931 #include <linux/mutex.h>
41932 #include <linux/slab.h>
41933+#include <linux/moduleloader.h>
41934 #include <video/edid.h>
41935 #include <video/uvesafb.h>
41936 #ifdef CONFIG_X86
41937@@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
41938 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
41939 par->pmi_setpal = par->ypan = 0;
41940 } else {
41941+
41942+#ifdef CONFIG_PAX_KERNEXEC
41943+#ifdef CONFIG_MODULES
41944+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
41945+#endif
41946+ if (!par->pmi_code) {
41947+ par->pmi_setpal = par->ypan = 0;
41948+ return 0;
41949+ }
41950+#endif
41951+
41952 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
41953 + task->t.regs.edi);
41954+
41955+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41956+ pax_open_kernel();
41957+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
41958+ pax_close_kernel();
41959+
41960+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
41961+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
41962+#else
41963 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
41964 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
41965+#endif
41966+
41967 printk(KERN_INFO "uvesafb: protected mode interface info at "
41968 "%04x:%04x\n",
41969 (u16)task->t.regs.es, (u16)task->t.regs.edi);
41970@@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
41971 par->ypan = ypan;
41972
41973 if (par->pmi_setpal || par->ypan) {
41974+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
41975 if (__supported_pte_mask & _PAGE_NX) {
41976 par->pmi_setpal = par->ypan = 0;
41977 printk(KERN_WARNING "uvesafb: NX protection is actively."
41978 "We have better not to use the PMI.\n");
41979- } else {
41980+ } else
41981+#endif
41982 uvesafb_vbe_getpmi(task, par);
41983- }
41984 }
41985 #else
41986 /* The protected mode interface is not available on non-x86. */
41987@@ -1836,6 +1860,11 @@ out:
41988 if (par->vbe_modes)
41989 kfree(par->vbe_modes);
41990
41991+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41992+ if (par->pmi_code)
41993+ module_free_exec(NULL, par->pmi_code);
41994+#endif
41995+
41996 framebuffer_release(info);
41997 return err;
41998 }
41999@@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
42000 kfree(par->vbe_state_orig);
42001 if (par->vbe_state_saved)
42002 kfree(par->vbe_state_saved);
42003+
42004+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42005+ if (par->pmi_code)
42006+ module_free_exec(NULL, par->pmi_code);
42007+#endif
42008+
42009 }
42010
42011 framebuffer_release(info);
42012diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
42013index 501b340..86bd4cf 100644
42014--- a/drivers/video/vesafb.c
42015+++ b/drivers/video/vesafb.c
42016@@ -9,6 +9,7 @@
42017 */
42018
42019 #include <linux/module.h>
42020+#include <linux/moduleloader.h>
42021 #include <linux/kernel.h>
42022 #include <linux/errno.h>
42023 #include <linux/string.h>
42024@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
42025 static int vram_total __initdata; /* Set total amount of memory */
42026 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
42027 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
42028-static void (*pmi_start)(void) __read_mostly;
42029-static void (*pmi_pal) (void) __read_mostly;
42030+static void (*pmi_start)(void) __read_only;
42031+static void (*pmi_pal) (void) __read_only;
42032 static int depth __read_mostly;
42033 static int vga_compat __read_mostly;
42034 /* --------------------------------------------------------------------- */
42035@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
42036 unsigned int size_vmode;
42037 unsigned int size_remap;
42038 unsigned int size_total;
42039+ void *pmi_code = NULL;
42040
42041 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42042 return -ENODEV;
42043@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
42044 size_remap = size_total;
42045 vesafb_fix.smem_len = size_remap;
42046
42047-#ifndef __i386__
42048- screen_info.vesapm_seg = 0;
42049-#endif
42050-
42051 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42052 printk(KERN_WARNING
42053 "vesafb: cannot reserve video memory at 0x%lx\n",
42054@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42055 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42056 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42057
42058+#ifdef __i386__
42059+
42060+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42061+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
42062+ if (!pmi_code)
42063+#elif !defined(CONFIG_PAX_KERNEXEC)
42064+ if (0)
42065+#endif
42066+
42067+#endif
42068+ screen_info.vesapm_seg = 0;
42069+
42070 if (screen_info.vesapm_seg) {
42071- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42072- screen_info.vesapm_seg,screen_info.vesapm_off);
42073+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42074+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42075 }
42076
42077 if (screen_info.vesapm_seg < 0xc000)
42078@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42079
42080 if (ypan || pmi_setpal) {
42081 unsigned short *pmi_base;
42082+
42083 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42084- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42085- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42086+
42087+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42088+ pax_open_kernel();
42089+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42090+#else
42091+ pmi_code = pmi_base;
42092+#endif
42093+
42094+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42095+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42096+
42097+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42098+ pmi_start = ktva_ktla(pmi_start);
42099+ pmi_pal = ktva_ktla(pmi_pal);
42100+ pax_close_kernel();
42101+#endif
42102+
42103 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42104 if (pmi_base[3]) {
42105 printk(KERN_INFO "vesafb: pmi: ports = ");
42106@@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42107 info->node, info->fix.id);
42108 return 0;
42109 err:
42110+
42111+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42112+ module_free_exec(NULL, pmi_code);
42113+#endif
42114+
42115 if (info->screen_base)
42116 iounmap(info->screen_base);
42117 framebuffer_release(info);
42118diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42119index 88714ae..16c2e11 100644
42120--- a/drivers/video/via/via_clock.h
42121+++ b/drivers/video/via/via_clock.h
42122@@ -56,7 +56,7 @@ struct via_clock {
42123
42124 void (*set_engine_pll_state)(u8 state);
42125 void (*set_engine_pll)(struct via_pll_config config);
42126-};
42127+} __no_const;
42128
42129
42130 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42131diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
42132index e56c934..fc22f4b 100644
42133--- a/drivers/xen/xen-pciback/conf_space.h
42134+++ b/drivers/xen/xen-pciback/conf_space.h
42135@@ -44,15 +44,15 @@ struct config_field {
42136 struct {
42137 conf_dword_write write;
42138 conf_dword_read read;
42139- } dw;
42140+ } __no_const dw;
42141 struct {
42142 conf_word_write write;
42143 conf_word_read read;
42144- } w;
42145+ } __no_const w;
42146 struct {
42147 conf_byte_write write;
42148 conf_byte_read read;
42149- } b;
42150+ } __no_const b;
42151 } u;
42152 struct list_head list;
42153 };
42154diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
42155index 57ccb75..f6d05f8 100644
42156--- a/fs/9p/vfs_inode.c
42157+++ b/fs/9p/vfs_inode.c
42158@@ -1303,7 +1303,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42159 void
42160 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42161 {
42162- char *s = nd_get_link(nd);
42163+ const char *s = nd_get_link(nd);
42164
42165 p9_debug(P9_DEBUG_VFS, " %s %s\n",
42166 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
42167diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
42168index 0225742..1cd4732 100644
42169--- a/fs/Kconfig.binfmt
42170+++ b/fs/Kconfig.binfmt
42171@@ -89,7 +89,7 @@ config HAVE_AOUT
42172
42173 config BINFMT_AOUT
42174 tristate "Kernel support for a.out and ECOFF binaries"
42175- depends on HAVE_AOUT
42176+ depends on HAVE_AOUT && BROKEN
42177 ---help---
42178 A.out (Assembler.OUTput) is a set of formats for libraries and
42179 executables used in the earliest versions of UNIX. Linux used
42180diff --git a/fs/aio.c b/fs/aio.c
42181index 55c4c76..11aee6f 100644
42182--- a/fs/aio.c
42183+++ b/fs/aio.c
42184@@ -118,7 +118,7 @@ static int aio_setup_ring(struct kioctx *ctx)
42185 size += sizeof(struct io_event) * nr_events;
42186 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
42187
42188- if (nr_pages < 0)
42189+ if (nr_pages <= 0)
42190 return -EINVAL;
42191
42192 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
42193@@ -1440,18 +1440,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
42194 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42195 {
42196 ssize_t ret;
42197+ struct iovec iovstack;
42198
42199 #ifdef CONFIG_COMPAT
42200 if (compat)
42201 ret = compat_rw_copy_check_uvector(type,
42202 (struct compat_iovec __user *)kiocb->ki_buf,
42203- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42204+ kiocb->ki_nbytes, 1, &iovstack,
42205 &kiocb->ki_iovec);
42206 else
42207 #endif
42208 ret = rw_copy_check_uvector(type,
42209 (struct iovec __user *)kiocb->ki_buf,
42210- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42211+ kiocb->ki_nbytes, 1, &iovstack,
42212 &kiocb->ki_iovec);
42213 if (ret < 0)
42214 goto out;
42215@@ -1460,6 +1461,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42216 if (ret < 0)
42217 goto out;
42218
42219+ if (kiocb->ki_iovec == &iovstack) {
42220+ kiocb->ki_inline_vec = iovstack;
42221+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
42222+ }
42223 kiocb->ki_nr_segs = kiocb->ki_nbytes;
42224 kiocb->ki_cur_seg = 0;
42225 /* ki_nbytes/left now reflect bytes instead of segs */
42226diff --git a/fs/attr.c b/fs/attr.c
42227index 0da9095..1386693 100644
42228--- a/fs/attr.c
42229+++ b/fs/attr.c
42230@@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
42231 unsigned long limit;
42232
42233 limit = rlimit(RLIMIT_FSIZE);
42234+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
42235 if (limit != RLIM_INFINITY && offset > limit)
42236 goto out_sig;
42237 if (offset > inode->i_sb->s_maxbytes)
42238diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
42239index da8876d..9f3e6d8 100644
42240--- a/fs/autofs4/waitq.c
42241+++ b/fs/autofs4/waitq.c
42242@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
42243 {
42244 unsigned long sigpipe, flags;
42245 mm_segment_t fs;
42246- const char *data = (const char *)addr;
42247+ const char __user *data = (const char __force_user *)addr;
42248 ssize_t wr = 0;
42249
42250 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
42251diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
42252index e18da23..affc30e 100644
42253--- a/fs/befs/linuxvfs.c
42254+++ b/fs/befs/linuxvfs.c
42255@@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42256 {
42257 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
42258 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
42259- char *link = nd_get_link(nd);
42260+ const char *link = nd_get_link(nd);
42261 if (!IS_ERR(link))
42262 kfree(link);
42263 }
42264diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
42265index d146e18..12d1bd1 100644
42266--- a/fs/binfmt_aout.c
42267+++ b/fs/binfmt_aout.c
42268@@ -16,6 +16,7 @@
42269 #include <linux/string.h>
42270 #include <linux/fs.h>
42271 #include <linux/file.h>
42272+#include <linux/security.h>
42273 #include <linux/stat.h>
42274 #include <linux/fcntl.h>
42275 #include <linux/ptrace.h>
42276@@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42277 #endif
42278 # define START_STACK(u) ((void __user *)u.start_stack)
42279
42280+ memset(&dump, 0, sizeof(dump));
42281+
42282 fs = get_fs();
42283 set_fs(KERNEL_DS);
42284 has_dumped = 1;
42285@@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42286
42287 /* If the size of the dump file exceeds the rlimit, then see what would happen
42288 if we wrote the stack, but not the data area. */
42289+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42290 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42291 dump.u_dsize = 0;
42292
42293 /* Make sure we have enough room to write the stack and data areas. */
42294+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42295 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42296 dump.u_ssize = 0;
42297
42298@@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42299 rlim = rlimit(RLIMIT_DATA);
42300 if (rlim >= RLIM_INFINITY)
42301 rlim = ~0;
42302+
42303+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42304 if (ex.a_data + ex.a_bss > rlim)
42305 return -ENOMEM;
42306
42307@@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42308
42309 install_exec_creds(bprm);
42310
42311+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42312+ current->mm->pax_flags = 0UL;
42313+#endif
42314+
42315+#ifdef CONFIG_PAX_PAGEEXEC
42316+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42317+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42318+
42319+#ifdef CONFIG_PAX_EMUTRAMP
42320+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42321+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42322+#endif
42323+
42324+#ifdef CONFIG_PAX_MPROTECT
42325+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42326+ current->mm->pax_flags |= MF_PAX_MPROTECT;
42327+#endif
42328+
42329+ }
42330+#endif
42331+
42332 if (N_MAGIC(ex) == OMAGIC) {
42333 unsigned long text_addr, map_size;
42334 loff_t pos;
42335@@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42336 }
42337
42338 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42339- PROT_READ | PROT_WRITE | PROT_EXEC,
42340+ PROT_READ | PROT_WRITE,
42341 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42342 fd_offset + ex.a_text);
42343 if (error != N_DATADDR(ex)) {
42344diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42345index 1b52956..271266e 100644
42346--- a/fs/binfmt_elf.c
42347+++ b/fs/binfmt_elf.c
42348@@ -32,6 +32,7 @@
42349 #include <linux/elf.h>
42350 #include <linux/utsname.h>
42351 #include <linux/coredump.h>
42352+#include <linux/xattr.h>
42353 #include <asm/uaccess.h>
42354 #include <asm/param.h>
42355 #include <asm/page.h>
42356@@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42357 #define elf_core_dump NULL
42358 #endif
42359
42360+#ifdef CONFIG_PAX_MPROTECT
42361+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42362+#endif
42363+
42364 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42365 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42366 #else
42367@@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
42368 .load_binary = load_elf_binary,
42369 .load_shlib = load_elf_library,
42370 .core_dump = elf_core_dump,
42371+
42372+#ifdef CONFIG_PAX_MPROTECT
42373+ .handle_mprotect= elf_handle_mprotect,
42374+#endif
42375+
42376 .min_coredump = ELF_EXEC_PAGESIZE,
42377 };
42378
42379@@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
42380
42381 static int set_brk(unsigned long start, unsigned long end)
42382 {
42383+ unsigned long e = end;
42384+
42385 start = ELF_PAGEALIGN(start);
42386 end = ELF_PAGEALIGN(end);
42387 if (end > start) {
42388@@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
42389 if (BAD_ADDR(addr))
42390 return addr;
42391 }
42392- current->mm->start_brk = current->mm->brk = end;
42393+ current->mm->start_brk = current->mm->brk = e;
42394 return 0;
42395 }
42396
42397@@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42398 elf_addr_t __user *u_rand_bytes;
42399 const char *k_platform = ELF_PLATFORM;
42400 const char *k_base_platform = ELF_BASE_PLATFORM;
42401- unsigned char k_rand_bytes[16];
42402+ u32 k_rand_bytes[4];
42403 int items;
42404 elf_addr_t *elf_info;
42405 int ei_index = 0;
42406 const struct cred *cred = current_cred();
42407 struct vm_area_struct *vma;
42408+ unsigned long saved_auxv[AT_VECTOR_SIZE];
42409
42410 /*
42411 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42412@@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42413 * Generate 16 random bytes for userspace PRNG seeding.
42414 */
42415 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42416- u_rand_bytes = (elf_addr_t __user *)
42417- STACK_ALLOC(p, sizeof(k_rand_bytes));
42418+ srandom32(k_rand_bytes[0] ^ random32());
42419+ srandom32(k_rand_bytes[1] ^ random32());
42420+ srandom32(k_rand_bytes[2] ^ random32());
42421+ srandom32(k_rand_bytes[3] ^ random32());
42422+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
42423+ u_rand_bytes = (elf_addr_t __user *) p;
42424 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
42425 return -EFAULT;
42426
42427@@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42428 return -EFAULT;
42429 current->mm->env_end = p;
42430
42431+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
42432+
42433 /* Put the elf_info on the stack in the right place. */
42434 sp = (elf_addr_t __user *)envp + 1;
42435- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
42436+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
42437 return -EFAULT;
42438 return 0;
42439 }
42440@@ -378,10 +397,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42441 {
42442 struct elf_phdr *elf_phdata;
42443 struct elf_phdr *eppnt;
42444- unsigned long load_addr = 0;
42445+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
42446 int load_addr_set = 0;
42447 unsigned long last_bss = 0, elf_bss = 0;
42448- unsigned long error = ~0UL;
42449+ unsigned long error = -EINVAL;
42450 unsigned long total_size;
42451 int retval, i, size;
42452
42453@@ -427,6 +446,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42454 goto out_close;
42455 }
42456
42457+#ifdef CONFIG_PAX_SEGMEXEC
42458+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
42459+ pax_task_size = SEGMEXEC_TASK_SIZE;
42460+#endif
42461+
42462 eppnt = elf_phdata;
42463 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
42464 if (eppnt->p_type == PT_LOAD) {
42465@@ -470,8 +494,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42466 k = load_addr + eppnt->p_vaddr;
42467 if (BAD_ADDR(k) ||
42468 eppnt->p_filesz > eppnt->p_memsz ||
42469- eppnt->p_memsz > TASK_SIZE ||
42470- TASK_SIZE - eppnt->p_memsz < k) {
42471+ eppnt->p_memsz > pax_task_size ||
42472+ pax_task_size - eppnt->p_memsz < k) {
42473 error = -ENOMEM;
42474 goto out_close;
42475 }
42476@@ -523,6 +547,311 @@ out:
42477 return error;
42478 }
42479
42480+#ifdef CONFIG_PAX_PT_PAX_FLAGS
42481+#ifdef CONFIG_PAX_SOFTMODE
42482+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
42483+{
42484+ unsigned long pax_flags = 0UL;
42485+
42486+#ifdef CONFIG_PAX_PAGEEXEC
42487+ if (elf_phdata->p_flags & PF_PAGEEXEC)
42488+ pax_flags |= MF_PAX_PAGEEXEC;
42489+#endif
42490+
42491+#ifdef CONFIG_PAX_SEGMEXEC
42492+ if (elf_phdata->p_flags & PF_SEGMEXEC)
42493+ pax_flags |= MF_PAX_SEGMEXEC;
42494+#endif
42495+
42496+#ifdef CONFIG_PAX_EMUTRAMP
42497+ if (elf_phdata->p_flags & PF_EMUTRAMP)
42498+ pax_flags |= MF_PAX_EMUTRAMP;
42499+#endif
42500+
42501+#ifdef CONFIG_PAX_MPROTECT
42502+ if (elf_phdata->p_flags & PF_MPROTECT)
42503+ pax_flags |= MF_PAX_MPROTECT;
42504+#endif
42505+
42506+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42507+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
42508+ pax_flags |= MF_PAX_RANDMMAP;
42509+#endif
42510+
42511+ return pax_flags;
42512+}
42513+#endif
42514+
42515+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
42516+{
42517+ unsigned long pax_flags = 0UL;
42518+
42519+#ifdef CONFIG_PAX_PAGEEXEC
42520+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
42521+ pax_flags |= MF_PAX_PAGEEXEC;
42522+#endif
42523+
42524+#ifdef CONFIG_PAX_SEGMEXEC
42525+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
42526+ pax_flags |= MF_PAX_SEGMEXEC;
42527+#endif
42528+
42529+#ifdef CONFIG_PAX_EMUTRAMP
42530+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
42531+ pax_flags |= MF_PAX_EMUTRAMP;
42532+#endif
42533+
42534+#ifdef CONFIG_PAX_MPROTECT
42535+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
42536+ pax_flags |= MF_PAX_MPROTECT;
42537+#endif
42538+
42539+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42540+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
42541+ pax_flags |= MF_PAX_RANDMMAP;
42542+#endif
42543+
42544+ return pax_flags;
42545+}
42546+#endif
42547+
42548+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42549+#ifdef CONFIG_PAX_SOFTMODE
42550+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
42551+{
42552+ unsigned long pax_flags = 0UL;
42553+
42554+#ifdef CONFIG_PAX_PAGEEXEC
42555+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
42556+ pax_flags |= MF_PAX_PAGEEXEC;
42557+#endif
42558+
42559+#ifdef CONFIG_PAX_SEGMEXEC
42560+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
42561+ pax_flags |= MF_PAX_SEGMEXEC;
42562+#endif
42563+
42564+#ifdef CONFIG_PAX_EMUTRAMP
42565+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
42566+ pax_flags |= MF_PAX_EMUTRAMP;
42567+#endif
42568+
42569+#ifdef CONFIG_PAX_MPROTECT
42570+ if (pax_flags_softmode & MF_PAX_MPROTECT)
42571+ pax_flags |= MF_PAX_MPROTECT;
42572+#endif
42573+
42574+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42575+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
42576+ pax_flags |= MF_PAX_RANDMMAP;
42577+#endif
42578+
42579+ return pax_flags;
42580+}
42581+#endif
42582+
42583+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
42584+{
42585+ unsigned long pax_flags = 0UL;
42586+
42587+#ifdef CONFIG_PAX_PAGEEXEC
42588+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
42589+ pax_flags |= MF_PAX_PAGEEXEC;
42590+#endif
42591+
42592+#ifdef CONFIG_PAX_SEGMEXEC
42593+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
42594+ pax_flags |= MF_PAX_SEGMEXEC;
42595+#endif
42596+
42597+#ifdef CONFIG_PAX_EMUTRAMP
42598+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
42599+ pax_flags |= MF_PAX_EMUTRAMP;
42600+#endif
42601+
42602+#ifdef CONFIG_PAX_MPROTECT
42603+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
42604+ pax_flags |= MF_PAX_MPROTECT;
42605+#endif
42606+
42607+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42608+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
42609+ pax_flags |= MF_PAX_RANDMMAP;
42610+#endif
42611+
42612+ return pax_flags;
42613+}
42614+#endif
42615+
42616+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42617+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
42618+{
42619+ unsigned long pax_flags = 0UL;
42620+
42621+#ifdef CONFIG_PAX_EI_PAX
42622+
42623+#ifdef CONFIG_PAX_PAGEEXEC
42624+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
42625+ pax_flags |= MF_PAX_PAGEEXEC;
42626+#endif
42627+
42628+#ifdef CONFIG_PAX_SEGMEXEC
42629+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
42630+ pax_flags |= MF_PAX_SEGMEXEC;
42631+#endif
42632+
42633+#ifdef CONFIG_PAX_EMUTRAMP
42634+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
42635+ pax_flags |= MF_PAX_EMUTRAMP;
42636+#endif
42637+
42638+#ifdef CONFIG_PAX_MPROTECT
42639+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
42640+ pax_flags |= MF_PAX_MPROTECT;
42641+#endif
42642+
42643+#ifdef CONFIG_PAX_ASLR
42644+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
42645+ pax_flags |= MF_PAX_RANDMMAP;
42646+#endif
42647+
42648+#else
42649+
42650+#ifdef CONFIG_PAX_PAGEEXEC
42651+ pax_flags |= MF_PAX_PAGEEXEC;
42652+#endif
42653+
42654+#ifdef CONFIG_PAX_SEGMEXEC
42655+ pax_flags |= MF_PAX_SEGMEXEC;
42656+#endif
42657+
42658+#ifdef CONFIG_PAX_MPROTECT
42659+ pax_flags |= MF_PAX_MPROTECT;
42660+#endif
42661+
42662+#ifdef CONFIG_PAX_RANDMMAP
42663+ if (randomize_va_space)
42664+ pax_flags |= MF_PAX_RANDMMAP;
42665+#endif
42666+
42667+#endif
42668+
42669+ return pax_flags;
42670+}
42671+
42672+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
42673+{
42674+
42675+#ifdef CONFIG_PAX_PT_PAX_FLAGS
42676+ unsigned long i;
42677+
42678+ for (i = 0UL; i < elf_ex->e_phnum; i++)
42679+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
42680+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
42681+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
42682+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
42683+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
42684+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
42685+ return ~0UL;
42686+
42687+#ifdef CONFIG_PAX_SOFTMODE
42688+ if (pax_softmode)
42689+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
42690+ else
42691+#endif
42692+
42693+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
42694+ break;
42695+ }
42696+#endif
42697+
42698+ return ~0UL;
42699+}
42700+
42701+static unsigned long pax_parse_xattr_pax(struct file * const file)
42702+{
42703+
42704+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42705+ ssize_t xattr_size, i;
42706+ unsigned char xattr_value[5];
42707+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
42708+
42709+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
42710+ if (xattr_size <= 0)
42711+ return ~0UL;
42712+
42713+ for (i = 0; i < xattr_size; i++)
42714+ switch (xattr_value[i]) {
42715+ default:
42716+ return ~0UL;
42717+
42718+#define parse_flag(option1, option2, flag) \
42719+ case option1: \
42720+ pax_flags_hardmode |= MF_PAX_##flag; \
42721+ break; \
42722+ case option2: \
42723+ pax_flags_softmode |= MF_PAX_##flag; \
42724+ break;
42725+
42726+ parse_flag('p', 'P', PAGEEXEC);
42727+ parse_flag('e', 'E', EMUTRAMP);
42728+ parse_flag('m', 'M', MPROTECT);
42729+ parse_flag('r', 'R', RANDMMAP);
42730+ parse_flag('s', 'S', SEGMEXEC);
42731+
42732+#undef parse_flag
42733+ }
42734+
42735+ if (pax_flags_hardmode & pax_flags_softmode)
42736+ return ~0UL;
42737+
42738+#ifdef CONFIG_PAX_SOFTMODE
42739+ if (pax_softmode)
42740+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
42741+ else
42742+#endif
42743+
42744+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
42745+#else
42746+ return ~0UL;
42747+#endif
42748+
42749+}
42750+
42751+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
42752+{
42753+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
42754+
42755+ pax_flags = pax_parse_ei_pax(elf_ex);
42756+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
42757+ xattr_pax_flags = pax_parse_xattr_pax(file);
42758+
42759+ if (pt_pax_flags == ~0UL)
42760+ pt_pax_flags = xattr_pax_flags;
42761+ else if (xattr_pax_flags == ~0UL)
42762+ xattr_pax_flags = pt_pax_flags;
42763+ if (pt_pax_flags != xattr_pax_flags)
42764+ return -EINVAL;
42765+ if (pt_pax_flags != ~0UL)
42766+ pax_flags = pt_pax_flags;
42767+
42768+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42769+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42770+ if ((__supported_pte_mask & _PAGE_NX))
42771+ pax_flags &= ~MF_PAX_SEGMEXEC;
42772+ else
42773+ pax_flags &= ~MF_PAX_PAGEEXEC;
42774+ }
42775+#endif
42776+
42777+ if (0 > pax_check_flags(&pax_flags))
42778+ return -EINVAL;
42779+
42780+ current->mm->pax_flags = pax_flags;
42781+ return 0;
42782+}
42783+#endif
42784+
42785 /*
42786 * These are the functions used to load ELF style executables and shared
42787 * libraries. There is no binary dependent code anywhere else.
42788@@ -539,6 +868,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
42789 {
42790 unsigned int random_variable = 0;
42791
42792+#ifdef CONFIG_PAX_RANDUSTACK
42793+ if (randomize_va_space)
42794+ return stack_top - current->mm->delta_stack;
42795+#endif
42796+
42797 if ((current->flags & PF_RANDOMIZE) &&
42798 !(current->personality & ADDR_NO_RANDOMIZE)) {
42799 random_variable = get_random_int() & STACK_RND_MASK;
42800@@ -557,7 +891,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42801 unsigned long load_addr = 0, load_bias = 0;
42802 int load_addr_set = 0;
42803 char * elf_interpreter = NULL;
42804- unsigned long error;
42805+ unsigned long error = 0;
42806 struct elf_phdr *elf_ppnt, *elf_phdata;
42807 unsigned long elf_bss, elf_brk;
42808 int retval, i;
42809@@ -567,11 +901,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42810 unsigned long start_code, end_code, start_data, end_data;
42811 unsigned long reloc_func_desc __maybe_unused = 0;
42812 int executable_stack = EXSTACK_DEFAULT;
42813- unsigned long def_flags = 0;
42814 struct {
42815 struct elfhdr elf_ex;
42816 struct elfhdr interp_elf_ex;
42817 } *loc;
42818+ unsigned long pax_task_size = TASK_SIZE;
42819
42820 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
42821 if (!loc) {
42822@@ -707,11 +1041,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42823 goto out_free_dentry;
42824
42825 /* OK, This is the point of no return */
42826- current->mm->def_flags = def_flags;
42827+
42828+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42829+ current->mm->pax_flags = 0UL;
42830+#endif
42831+
42832+#ifdef CONFIG_PAX_DLRESOLVE
42833+ current->mm->call_dl_resolve = 0UL;
42834+#endif
42835+
42836+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
42837+ current->mm->call_syscall = 0UL;
42838+#endif
42839+
42840+#ifdef CONFIG_PAX_ASLR
42841+ current->mm->delta_mmap = 0UL;
42842+ current->mm->delta_stack = 0UL;
42843+#endif
42844+
42845+ current->mm->def_flags = 0;
42846+
42847+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42848+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
42849+ send_sig(SIGKILL, current, 0);
42850+ goto out_free_dentry;
42851+ }
42852+#endif
42853+
42854+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
42855+ pax_set_initial_flags(bprm);
42856+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
42857+ if (pax_set_initial_flags_func)
42858+ (pax_set_initial_flags_func)(bprm);
42859+#endif
42860+
42861+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
42862+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
42863+ current->mm->context.user_cs_limit = PAGE_SIZE;
42864+ current->mm->def_flags |= VM_PAGEEXEC;
42865+ }
42866+#endif
42867+
42868+#ifdef CONFIG_PAX_SEGMEXEC
42869+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
42870+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
42871+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
42872+ pax_task_size = SEGMEXEC_TASK_SIZE;
42873+ current->mm->def_flags |= VM_NOHUGEPAGE;
42874+ }
42875+#endif
42876+
42877+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
42878+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42879+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
42880+ put_cpu();
42881+ }
42882+#endif
42883
42884 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
42885 may depend on the personality. */
42886 SET_PERSONALITY(loc->elf_ex);
42887+
42888+#ifdef CONFIG_PAX_ASLR
42889+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42890+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
42891+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
42892+ }
42893+#endif
42894+
42895+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
42896+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42897+ executable_stack = EXSTACK_DISABLE_X;
42898+ current->personality &= ~READ_IMPLIES_EXEC;
42899+ } else
42900+#endif
42901+
42902 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
42903 current->personality |= READ_IMPLIES_EXEC;
42904
42905@@ -802,6 +1206,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42906 #else
42907 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
42908 #endif
42909+
42910+#ifdef CONFIG_PAX_RANDMMAP
42911+ /* PaX: randomize base address at the default exe base if requested */
42912+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
42913+#ifdef CONFIG_SPARC64
42914+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
42915+#else
42916+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
42917+#endif
42918+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
42919+ elf_flags |= MAP_FIXED;
42920+ }
42921+#endif
42922+
42923 }
42924
42925 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
42926@@ -834,9 +1252,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42927 * allowed task size. Note that p_filesz must always be
42928 * <= p_memsz so it is only necessary to check p_memsz.
42929 */
42930- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42931- elf_ppnt->p_memsz > TASK_SIZE ||
42932- TASK_SIZE - elf_ppnt->p_memsz < k) {
42933+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42934+ elf_ppnt->p_memsz > pax_task_size ||
42935+ pax_task_size - elf_ppnt->p_memsz < k) {
42936 /* set_brk can never work. Avoid overflows. */
42937 send_sig(SIGKILL, current, 0);
42938 retval = -EINVAL;
42939@@ -875,11 +1293,41 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42940 goto out_free_dentry;
42941 }
42942 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
42943- send_sig(SIGSEGV, current, 0);
42944- retval = -EFAULT; /* Nobody gets to see this, but.. */
42945- goto out_free_dentry;
42946+ /*
42947+ * This bss-zeroing can fail if the ELF
42948+ * file specifies odd protections. So
42949+ * we don't check the return value
42950+ */
42951 }
42952
42953+#ifdef CONFIG_PAX_RANDMMAP
42954+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42955+ unsigned long start, size;
42956+
42957+ start = ELF_PAGEALIGN(elf_brk);
42958+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
42959+ down_read(&current->mm->mmap_sem);
42960+ retval = -ENOMEM;
42961+ if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
42962+ unsigned long prot = PROT_NONE;
42963+
42964+ up_read(&current->mm->mmap_sem);
42965+ current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
42966+// if (current->personality & ADDR_NO_RANDOMIZE)
42967+// prot = PROT_READ;
42968+ start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
42969+ retval = IS_ERR_VALUE(start) ? start : 0;
42970+ } else
42971+ up_read(&current->mm->mmap_sem);
42972+ if (retval == 0)
42973+ retval = set_brk(start + size, start + size + PAGE_SIZE);
42974+ if (retval < 0) {
42975+ send_sig(SIGKILL, current, 0);
42976+ goto out_free_dentry;
42977+ }
42978+ }
42979+#endif
42980+
42981 if (elf_interpreter) {
42982 unsigned long uninitialized_var(interp_map_addr);
42983
42984@@ -1107,7 +1555,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
42985 * Decide what to dump of a segment, part, all or none.
42986 */
42987 static unsigned long vma_dump_size(struct vm_area_struct *vma,
42988- unsigned long mm_flags)
42989+ unsigned long mm_flags, long signr)
42990 {
42991 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
42992
42993@@ -1144,7 +1592,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
42994 if (vma->vm_file == NULL)
42995 return 0;
42996
42997- if (FILTER(MAPPED_PRIVATE))
42998+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
42999 goto whole;
43000
43001 /*
43002@@ -1366,9 +1814,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
43003 {
43004 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
43005 int i = 0;
43006- do
43007+ do {
43008 i += 2;
43009- while (auxv[i - 2] != AT_NULL);
43010+ } while (auxv[i - 2] != AT_NULL);
43011 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43012 }
43013
43014@@ -1890,14 +2338,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
43015 }
43016
43017 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43018- unsigned long mm_flags)
43019+ struct coredump_params *cprm)
43020 {
43021 struct vm_area_struct *vma;
43022 size_t size = 0;
43023
43024 for (vma = first_vma(current, gate_vma); vma != NULL;
43025 vma = next_vma(vma, gate_vma))
43026- size += vma_dump_size(vma, mm_flags);
43027+ size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43028 return size;
43029 }
43030
43031@@ -1991,7 +2439,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43032
43033 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43034
43035- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43036+ offset += elf_core_vma_data_size(gate_vma, cprm);
43037 offset += elf_core_extra_data_size();
43038 e_shoff = offset;
43039
43040@@ -2005,10 +2453,12 @@ static int elf_core_dump(struct coredump_params *cprm)
43041 offset = dataoff;
43042
43043 size += sizeof(*elf);
43044+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43045 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43046 goto end_coredump;
43047
43048 size += sizeof(*phdr4note);
43049+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43050 if (size > cprm->limit
43051 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43052 goto end_coredump;
43053@@ -2022,7 +2472,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43054 phdr.p_offset = offset;
43055 phdr.p_vaddr = vma->vm_start;
43056 phdr.p_paddr = 0;
43057- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43058+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43059 phdr.p_memsz = vma->vm_end - vma->vm_start;
43060 offset += phdr.p_filesz;
43061 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43062@@ -2033,6 +2483,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43063 phdr.p_align = ELF_EXEC_PAGESIZE;
43064
43065 size += sizeof(phdr);
43066+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43067 if (size > cprm->limit
43068 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
43069 goto end_coredump;
43070@@ -2057,7 +2508,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43071 unsigned long addr;
43072 unsigned long end;
43073
43074- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
43075+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43076
43077 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43078 struct page *page;
43079@@ -2066,6 +2517,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43080 page = get_dump_page(addr);
43081 if (page) {
43082 void *kaddr = kmap(page);
43083+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43084 stop = ((size += PAGE_SIZE) > cprm->limit) ||
43085 !dump_write(cprm->file, kaddr,
43086 PAGE_SIZE);
43087@@ -2083,6 +2535,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43088
43089 if (e_phnum == PN_XNUM) {
43090 size += sizeof(*shdr4extnum);
43091+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43092 if (size > cprm->limit
43093 || !dump_write(cprm->file, shdr4extnum,
43094 sizeof(*shdr4extnum)))
43095@@ -2103,6 +2556,97 @@ out:
43096
43097 #endif /* CONFIG_ELF_CORE */
43098
43099+#ifdef CONFIG_PAX_MPROTECT
43100+/* PaX: non-PIC ELF libraries need relocations on their executable segments
43101+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43102+ * we'll remove VM_MAYWRITE for good on RELRO segments.
43103+ *
43104+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43105+ * basis because we want to allow the common case and not the special ones.
43106+ */
43107+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43108+{
43109+ struct elfhdr elf_h;
43110+ struct elf_phdr elf_p;
43111+ unsigned long i;
43112+ unsigned long oldflags;
43113+ bool is_textrel_rw, is_textrel_rx, is_relro;
43114+
43115+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
43116+ return;
43117+
43118+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
43119+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
43120+
43121+#ifdef CONFIG_PAX_ELFRELOCS
43122+ /* possible TEXTREL */
43123+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
43124+ 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);
43125+#else
43126+ is_textrel_rw = false;
43127+ is_textrel_rx = false;
43128+#endif
43129+
43130+ /* possible RELRO */
43131+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
43132+
43133+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
43134+ return;
43135+
43136+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
43137+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
43138+
43139+#ifdef CONFIG_PAX_ETEXECRELOCS
43140+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43141+#else
43142+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
43143+#endif
43144+
43145+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43146+ !elf_check_arch(&elf_h) ||
43147+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
43148+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
43149+ return;
43150+
43151+ for (i = 0UL; i < elf_h.e_phnum; i++) {
43152+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
43153+ return;
43154+ switch (elf_p.p_type) {
43155+ case PT_DYNAMIC:
43156+ if (!is_textrel_rw && !is_textrel_rx)
43157+ continue;
43158+ i = 0UL;
43159+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
43160+ elf_dyn dyn;
43161+
43162+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
43163+ return;
43164+ if (dyn.d_tag == DT_NULL)
43165+ return;
43166+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
43167+ gr_log_textrel(vma);
43168+ if (is_textrel_rw)
43169+ vma->vm_flags |= VM_MAYWRITE;
43170+ else
43171+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
43172+ vma->vm_flags &= ~VM_MAYWRITE;
43173+ return;
43174+ }
43175+ i++;
43176+ }
43177+ return;
43178+
43179+ case PT_GNU_RELRO:
43180+ if (!is_relro)
43181+ continue;
43182+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
43183+ vma->vm_flags &= ~VM_MAYWRITE;
43184+ return;
43185+ }
43186+ }
43187+}
43188+#endif
43189+
43190 static int __init init_elf_binfmt(void)
43191 {
43192 register_binfmt(&elf_format);
43193diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
43194index 178cb70..8972997 100644
43195--- a/fs/binfmt_flat.c
43196+++ b/fs/binfmt_flat.c
43197@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
43198 realdatastart = (unsigned long) -ENOMEM;
43199 printk("Unable to allocate RAM for process data, errno %d\n",
43200 (int)-realdatastart);
43201+ down_write(&current->mm->mmap_sem);
43202 vm_munmap(textpos, text_len);
43203+ up_write(&current->mm->mmap_sem);
43204 ret = realdatastart;
43205 goto err;
43206 }
43207@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43208 }
43209 if (IS_ERR_VALUE(result)) {
43210 printk("Unable to read data+bss, errno %d\n", (int)-result);
43211+ down_write(&current->mm->mmap_sem);
43212 vm_munmap(textpos, text_len);
43213 vm_munmap(realdatastart, len);
43214+ up_write(&current->mm->mmap_sem);
43215 ret = result;
43216 goto err;
43217 }
43218@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43219 }
43220 if (IS_ERR_VALUE(result)) {
43221 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
43222+ down_write(&current->mm->mmap_sem);
43223 vm_munmap(textpos, text_len + data_len + extra +
43224 MAX_SHARED_LIBS * sizeof(unsigned long));
43225+ up_write(&current->mm->mmap_sem);
43226 ret = result;
43227 goto err;
43228 }
43229diff --git a/fs/bio.c b/fs/bio.c
43230index 73922ab..16642dd 100644
43231--- a/fs/bio.c
43232+++ b/fs/bio.c
43233@@ -841,7 +841,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
43234 /*
43235 * Overflow, abort
43236 */
43237- if (end < start)
43238+ if (end < start || end - start > INT_MAX - nr_pages)
43239 return ERR_PTR(-EINVAL);
43240
43241 nr_pages += end - start;
43242@@ -975,7 +975,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
43243 /*
43244 * Overflow, abort
43245 */
43246- if (end < start)
43247+ if (end < start || end - start > INT_MAX - nr_pages)
43248 return ERR_PTR(-EINVAL);
43249
43250 nr_pages += end - start;
43251@@ -1237,7 +1237,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43252 const int read = bio_data_dir(bio) == READ;
43253 struct bio_map_data *bmd = bio->bi_private;
43254 int i;
43255- char *p = bmd->sgvecs[0].iov_base;
43256+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43257
43258 __bio_for_each_segment(bvec, bio, i, 0) {
43259 char *addr = page_address(bvec->bv_page);
43260diff --git a/fs/block_dev.c b/fs/block_dev.c
43261index c2bbe1f..9dfbc23 100644
43262--- a/fs/block_dev.c
43263+++ b/fs/block_dev.c
43264@@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43265 else if (bdev->bd_contains == bdev)
43266 return true; /* is a whole device which isn't held */
43267
43268- else if (whole->bd_holder == bd_may_claim)
43269+ else if (whole->bd_holder == (void *)bd_may_claim)
43270 return true; /* is a partition of a device that is being partitioned */
43271 else if (whole->bd_holder != NULL)
43272 return false; /* is a partition of a held device */
43273diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
43274index da6e936..1598dd0 100644
43275--- a/fs/btrfs/check-integrity.c
43276+++ b/fs/btrfs/check-integrity.c
43277@@ -155,7 +155,7 @@ struct btrfsic_block {
43278 union {
43279 bio_end_io_t *bio;
43280 bh_end_io_t *bh;
43281- } orig_bio_bh_end_io;
43282+ } __no_const orig_bio_bh_end_io;
43283 int submit_bio_bh_rw;
43284 u64 flush_gen; /* only valid if !never_written */
43285 };
43286diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
43287index 8206b39..06d5654 100644
43288--- a/fs/btrfs/ctree.c
43289+++ b/fs/btrfs/ctree.c
43290@@ -973,9 +973,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
43291 free_extent_buffer(buf);
43292 add_root_to_dirty_list(root);
43293 } else {
43294- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43295- parent_start = parent->start;
43296- else
43297+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43298+ if (parent)
43299+ parent_start = parent->start;
43300+ else
43301+ parent_start = 0;
43302+ } else
43303 parent_start = 0;
43304
43305 WARN_ON(trans->transid != btrfs_header_generation(parent));
43306diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43307index a7d1921..a32dba2 100644
43308--- a/fs/btrfs/inode.c
43309+++ b/fs/btrfs/inode.c
43310@@ -7111,7 +7111,7 @@ fail:
43311 return -ENOMEM;
43312 }
43313
43314-static int btrfs_getattr(struct vfsmount *mnt,
43315+int btrfs_getattr(struct vfsmount *mnt,
43316 struct dentry *dentry, struct kstat *stat)
43317 {
43318 struct inode *inode = dentry->d_inode;
43319@@ -7125,6 +7125,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43320 return 0;
43321 }
43322
43323+EXPORT_SYMBOL(btrfs_getattr);
43324+
43325+dev_t get_btrfs_dev_from_inode(struct inode *inode)
43326+{
43327+ return BTRFS_I(inode)->root->anon_dev;
43328+}
43329+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43330+
43331 /*
43332 * If a file is moved, it will inherit the cow and compression flags of the new
43333 * directory.
43334diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43335index 0e92e57..8b560de 100644
43336--- a/fs/btrfs/ioctl.c
43337+++ b/fs/btrfs/ioctl.c
43338@@ -2902,9 +2902,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43339 for (i = 0; i < num_types; i++) {
43340 struct btrfs_space_info *tmp;
43341
43342+ /* Don't copy in more than we allocated */
43343 if (!slot_count)
43344 break;
43345
43346+ slot_count--;
43347+
43348 info = NULL;
43349 rcu_read_lock();
43350 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43351@@ -2926,10 +2929,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43352 memcpy(dest, &space, sizeof(space));
43353 dest++;
43354 space_args.total_spaces++;
43355- slot_count--;
43356 }
43357- if (!slot_count)
43358- break;
43359 }
43360 up_read(&info->groups_sem);
43361 }
43362diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43363index 646ee21..f020f87 100644
43364--- a/fs/btrfs/relocation.c
43365+++ b/fs/btrfs/relocation.c
43366@@ -1268,7 +1268,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43367 }
43368 spin_unlock(&rc->reloc_root_tree.lock);
43369
43370- BUG_ON((struct btrfs_root *)node->data != root);
43371+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
43372
43373 if (!del) {
43374 spin_lock(&rc->reloc_root_tree.lock);
43375diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43376index 622f469..e8d2d55 100644
43377--- a/fs/cachefiles/bind.c
43378+++ b/fs/cachefiles/bind.c
43379@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43380 args);
43381
43382 /* start by checking things over */
43383- ASSERT(cache->fstop_percent >= 0 &&
43384- cache->fstop_percent < cache->fcull_percent &&
43385+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
43386 cache->fcull_percent < cache->frun_percent &&
43387 cache->frun_percent < 100);
43388
43389- ASSERT(cache->bstop_percent >= 0 &&
43390- cache->bstop_percent < cache->bcull_percent &&
43391+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
43392 cache->bcull_percent < cache->brun_percent &&
43393 cache->brun_percent < 100);
43394
43395diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
43396index 0a1467b..6a53245 100644
43397--- a/fs/cachefiles/daemon.c
43398+++ b/fs/cachefiles/daemon.c
43399@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
43400 if (n > buflen)
43401 return -EMSGSIZE;
43402
43403- if (copy_to_user(_buffer, buffer, n) != 0)
43404+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
43405 return -EFAULT;
43406
43407 return n;
43408@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
43409 if (test_bit(CACHEFILES_DEAD, &cache->flags))
43410 return -EIO;
43411
43412- if (datalen < 0 || datalen > PAGE_SIZE - 1)
43413+ if (datalen > PAGE_SIZE - 1)
43414 return -EOPNOTSUPP;
43415
43416 /* drag the command string into the kernel so we can parse it */
43417@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
43418 if (args[0] != '%' || args[1] != '\0')
43419 return -EINVAL;
43420
43421- if (fstop < 0 || fstop >= cache->fcull_percent)
43422+ if (fstop >= cache->fcull_percent)
43423 return cachefiles_daemon_range_error(cache, args);
43424
43425 cache->fstop_percent = fstop;
43426@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
43427 if (args[0] != '%' || args[1] != '\0')
43428 return -EINVAL;
43429
43430- if (bstop < 0 || bstop >= cache->bcull_percent)
43431+ if (bstop >= cache->bcull_percent)
43432 return cachefiles_daemon_range_error(cache, args);
43433
43434 cache->bstop_percent = bstop;
43435diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
43436index bd6bc1b..b627b53 100644
43437--- a/fs/cachefiles/internal.h
43438+++ b/fs/cachefiles/internal.h
43439@@ -57,7 +57,7 @@ struct cachefiles_cache {
43440 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
43441 struct rb_root active_nodes; /* active nodes (can't be culled) */
43442 rwlock_t active_lock; /* lock for active_nodes */
43443- atomic_t gravecounter; /* graveyard uniquifier */
43444+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
43445 unsigned frun_percent; /* when to stop culling (% files) */
43446 unsigned fcull_percent; /* when to start culling (% files) */
43447 unsigned fstop_percent; /* when to stop allocating (% files) */
43448@@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
43449 * proc.c
43450 */
43451 #ifdef CONFIG_CACHEFILES_HISTOGRAM
43452-extern atomic_t cachefiles_lookup_histogram[HZ];
43453-extern atomic_t cachefiles_mkdir_histogram[HZ];
43454-extern atomic_t cachefiles_create_histogram[HZ];
43455+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43456+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43457+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
43458
43459 extern int __init cachefiles_proc_init(void);
43460 extern void cachefiles_proc_cleanup(void);
43461 static inline
43462-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
43463+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
43464 {
43465 unsigned long jif = jiffies - start_jif;
43466 if (jif >= HZ)
43467 jif = HZ - 1;
43468- atomic_inc(&histogram[jif]);
43469+ atomic_inc_unchecked(&histogram[jif]);
43470 }
43471
43472 #else
43473diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
43474index 7f0771d..87d4f36 100644
43475--- a/fs/cachefiles/namei.c
43476+++ b/fs/cachefiles/namei.c
43477@@ -318,7 +318,7 @@ try_again:
43478 /* first step is to make up a grave dentry in the graveyard */
43479 sprintf(nbuffer, "%08x%08x",
43480 (uint32_t) get_seconds(),
43481- (uint32_t) atomic_inc_return(&cache->gravecounter));
43482+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
43483
43484 /* do the multiway lock magic */
43485 trap = lock_rename(cache->graveyard, dir);
43486diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
43487index eccd339..4c1d995 100644
43488--- a/fs/cachefiles/proc.c
43489+++ b/fs/cachefiles/proc.c
43490@@ -14,9 +14,9 @@
43491 #include <linux/seq_file.h>
43492 #include "internal.h"
43493
43494-atomic_t cachefiles_lookup_histogram[HZ];
43495-atomic_t cachefiles_mkdir_histogram[HZ];
43496-atomic_t cachefiles_create_histogram[HZ];
43497+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43498+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43499+atomic_unchecked_t cachefiles_create_histogram[HZ];
43500
43501 /*
43502 * display the latency histogram
43503@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
43504 return 0;
43505 default:
43506 index = (unsigned long) v - 3;
43507- x = atomic_read(&cachefiles_lookup_histogram[index]);
43508- y = atomic_read(&cachefiles_mkdir_histogram[index]);
43509- z = atomic_read(&cachefiles_create_histogram[index]);
43510+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
43511+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
43512+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
43513 if (x == 0 && y == 0 && z == 0)
43514 return 0;
43515
43516diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
43517index 0e3c092..818480e 100644
43518--- a/fs/cachefiles/rdwr.c
43519+++ b/fs/cachefiles/rdwr.c
43520@@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
43521 old_fs = get_fs();
43522 set_fs(KERNEL_DS);
43523 ret = file->f_op->write(
43524- file, (const void __user *) data, len, &pos);
43525+ file, (const void __force_user *) data, len, &pos);
43526 set_fs(old_fs);
43527 kunmap(page);
43528 if (ret != len)
43529diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
43530index 3e8094b..cb3ff3d 100644
43531--- a/fs/ceph/dir.c
43532+++ b/fs/ceph/dir.c
43533@@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
43534 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
43535 struct ceph_mds_client *mdsc = fsc->mdsc;
43536 unsigned frag = fpos_frag(filp->f_pos);
43537- int off = fpos_off(filp->f_pos);
43538+ unsigned int off = fpos_off(filp->f_pos);
43539 int err;
43540 u32 ftype;
43541 struct ceph_mds_reply_info_parsed *rinfo;
43542@@ -598,7 +598,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
43543 if (nd &&
43544 (nd->flags & LOOKUP_OPEN) &&
43545 !(nd->intent.open.flags & O_CREAT)) {
43546- int mode = nd->intent.open.create_mode & ~current->fs->umask;
43547+ int mode = nd->intent.open.create_mode & ~current_umask();
43548 return ceph_lookup_open(dir, dentry, nd, mode, 1);
43549 }
43550
43551diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
43552index e814052..28dcdf7 100644
43553--- a/fs/cifs/cifs_debug.c
43554+++ b/fs/cifs/cifs_debug.c
43555@@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43556
43557 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
43558 #ifdef CONFIG_CIFS_STATS2
43559- atomic_set(&totBufAllocCount, 0);
43560- atomic_set(&totSmBufAllocCount, 0);
43561+ atomic_set_unchecked(&totBufAllocCount, 0);
43562+ atomic_set_unchecked(&totSmBufAllocCount, 0);
43563 #endif /* CONFIG_CIFS_STATS2 */
43564 spin_lock(&cifs_tcp_ses_lock);
43565 list_for_each(tmp1, &cifs_tcp_ses_list) {
43566@@ -281,25 +281,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43567 tcon = list_entry(tmp3,
43568 struct cifs_tcon,
43569 tcon_list);
43570- atomic_set(&tcon->num_smbs_sent, 0);
43571- atomic_set(&tcon->num_writes, 0);
43572- atomic_set(&tcon->num_reads, 0);
43573- atomic_set(&tcon->num_oplock_brks, 0);
43574- atomic_set(&tcon->num_opens, 0);
43575- atomic_set(&tcon->num_posixopens, 0);
43576- atomic_set(&tcon->num_posixmkdirs, 0);
43577- atomic_set(&tcon->num_closes, 0);
43578- atomic_set(&tcon->num_deletes, 0);
43579- atomic_set(&tcon->num_mkdirs, 0);
43580- atomic_set(&tcon->num_rmdirs, 0);
43581- atomic_set(&tcon->num_renames, 0);
43582- atomic_set(&tcon->num_t2renames, 0);
43583- atomic_set(&tcon->num_ffirst, 0);
43584- atomic_set(&tcon->num_fnext, 0);
43585- atomic_set(&tcon->num_fclose, 0);
43586- atomic_set(&tcon->num_hardlinks, 0);
43587- atomic_set(&tcon->num_symlinks, 0);
43588- atomic_set(&tcon->num_locks, 0);
43589+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
43590+ atomic_set_unchecked(&tcon->num_writes, 0);
43591+ atomic_set_unchecked(&tcon->num_reads, 0);
43592+ atomic_set_unchecked(&tcon->num_oplock_brks, 0);
43593+ atomic_set_unchecked(&tcon->num_opens, 0);
43594+ atomic_set_unchecked(&tcon->num_posixopens, 0);
43595+ atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
43596+ atomic_set_unchecked(&tcon->num_closes, 0);
43597+ atomic_set_unchecked(&tcon->num_deletes, 0);
43598+ atomic_set_unchecked(&tcon->num_mkdirs, 0);
43599+ atomic_set_unchecked(&tcon->num_rmdirs, 0);
43600+ atomic_set_unchecked(&tcon->num_renames, 0);
43601+ atomic_set_unchecked(&tcon->num_t2renames, 0);
43602+ atomic_set_unchecked(&tcon->num_ffirst, 0);
43603+ atomic_set_unchecked(&tcon->num_fnext, 0);
43604+ atomic_set_unchecked(&tcon->num_fclose, 0);
43605+ atomic_set_unchecked(&tcon->num_hardlinks, 0);
43606+ atomic_set_unchecked(&tcon->num_symlinks, 0);
43607+ atomic_set_unchecked(&tcon->num_locks, 0);
43608 }
43609 }
43610 }
43611@@ -329,8 +329,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43612 smBufAllocCount.counter, cifs_min_small);
43613 #ifdef CONFIG_CIFS_STATS2
43614 seq_printf(m, "Total Large %d Small %d Allocations\n",
43615- atomic_read(&totBufAllocCount),
43616- atomic_read(&totSmBufAllocCount));
43617+ atomic_read_unchecked(&totBufAllocCount),
43618+ atomic_read_unchecked(&totSmBufAllocCount));
43619 #endif /* CONFIG_CIFS_STATS2 */
43620
43621 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
43622@@ -359,41 +359,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43623 if (tcon->need_reconnect)
43624 seq_puts(m, "\tDISCONNECTED ");
43625 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
43626- atomic_read(&tcon->num_smbs_sent),
43627- atomic_read(&tcon->num_oplock_brks));
43628+ atomic_read_unchecked(&tcon->num_smbs_sent),
43629+ atomic_read_unchecked(&tcon->num_oplock_brks));
43630 seq_printf(m, "\nReads: %d Bytes: %lld",
43631- atomic_read(&tcon->num_reads),
43632+ atomic_read_unchecked(&tcon->num_reads),
43633 (long long)(tcon->bytes_read));
43634 seq_printf(m, "\nWrites: %d Bytes: %lld",
43635- atomic_read(&tcon->num_writes),
43636+ atomic_read_unchecked(&tcon->num_writes),
43637 (long long)(tcon->bytes_written));
43638 seq_printf(m, "\nFlushes: %d",
43639- atomic_read(&tcon->num_flushes));
43640+ atomic_read_unchecked(&tcon->num_flushes));
43641 seq_printf(m, "\nLocks: %d HardLinks: %d "
43642 "Symlinks: %d",
43643- atomic_read(&tcon->num_locks),
43644- atomic_read(&tcon->num_hardlinks),
43645- atomic_read(&tcon->num_symlinks));
43646+ atomic_read_unchecked(&tcon->num_locks),
43647+ atomic_read_unchecked(&tcon->num_hardlinks),
43648+ atomic_read_unchecked(&tcon->num_symlinks));
43649 seq_printf(m, "\nOpens: %d Closes: %d "
43650 "Deletes: %d",
43651- atomic_read(&tcon->num_opens),
43652- atomic_read(&tcon->num_closes),
43653- atomic_read(&tcon->num_deletes));
43654+ atomic_read_unchecked(&tcon->num_opens),
43655+ atomic_read_unchecked(&tcon->num_closes),
43656+ atomic_read_unchecked(&tcon->num_deletes));
43657 seq_printf(m, "\nPosix Opens: %d "
43658 "Posix Mkdirs: %d",
43659- atomic_read(&tcon->num_posixopens),
43660- atomic_read(&tcon->num_posixmkdirs));
43661+ atomic_read_unchecked(&tcon->num_posixopens),
43662+ atomic_read_unchecked(&tcon->num_posixmkdirs));
43663 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
43664- atomic_read(&tcon->num_mkdirs),
43665- atomic_read(&tcon->num_rmdirs));
43666+ atomic_read_unchecked(&tcon->num_mkdirs),
43667+ atomic_read_unchecked(&tcon->num_rmdirs));
43668 seq_printf(m, "\nRenames: %d T2 Renames %d",
43669- atomic_read(&tcon->num_renames),
43670- atomic_read(&tcon->num_t2renames));
43671+ atomic_read_unchecked(&tcon->num_renames),
43672+ atomic_read_unchecked(&tcon->num_t2renames));
43673 seq_printf(m, "\nFindFirst: %d FNext %d "
43674 "FClose %d",
43675- atomic_read(&tcon->num_ffirst),
43676- atomic_read(&tcon->num_fnext),
43677- atomic_read(&tcon->num_fclose));
43678+ atomic_read_unchecked(&tcon->num_ffirst),
43679+ atomic_read_unchecked(&tcon->num_fnext),
43680+ atomic_read_unchecked(&tcon->num_fclose));
43681 }
43682 }
43683 }
43684diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
43685index 8b6e344..303a662 100644
43686--- a/fs/cifs/cifsfs.c
43687+++ b/fs/cifs/cifsfs.c
43688@@ -994,7 +994,7 @@ cifs_init_request_bufs(void)
43689 cifs_req_cachep = kmem_cache_create("cifs_request",
43690 CIFSMaxBufSize +
43691 MAX_CIFS_HDR_SIZE, 0,
43692- SLAB_HWCACHE_ALIGN, NULL);
43693+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
43694 if (cifs_req_cachep == NULL)
43695 return -ENOMEM;
43696
43697@@ -1021,7 +1021,7 @@ cifs_init_request_bufs(void)
43698 efficient to alloc 1 per page off the slab compared to 17K (5page)
43699 alloc of large cifs buffers even when page debugging is on */
43700 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
43701- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
43702+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
43703 NULL);
43704 if (cifs_sm_req_cachep == NULL) {
43705 mempool_destroy(cifs_req_poolp);
43706@@ -1106,8 +1106,8 @@ init_cifs(void)
43707 atomic_set(&bufAllocCount, 0);
43708 atomic_set(&smBufAllocCount, 0);
43709 #ifdef CONFIG_CIFS_STATS2
43710- atomic_set(&totBufAllocCount, 0);
43711- atomic_set(&totSmBufAllocCount, 0);
43712+ atomic_set_unchecked(&totBufAllocCount, 0);
43713+ atomic_set_unchecked(&totSmBufAllocCount, 0);
43714 #endif /* CONFIG_CIFS_STATS2 */
43715
43716 atomic_set(&midCount, 0);
43717diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
43718index d86ba9f..e80049d 100644
43719--- a/fs/cifs/cifsglob.h
43720+++ b/fs/cifs/cifsglob.h
43721@@ -491,28 +491,28 @@ struct cifs_tcon {
43722 __u16 Flags; /* optional support bits */
43723 enum statusEnum tidStatus;
43724 #ifdef CONFIG_CIFS_STATS
43725- atomic_t num_smbs_sent;
43726- atomic_t num_writes;
43727- atomic_t num_reads;
43728- atomic_t num_flushes;
43729- atomic_t num_oplock_brks;
43730- atomic_t num_opens;
43731- atomic_t num_closes;
43732- atomic_t num_deletes;
43733- atomic_t num_mkdirs;
43734- atomic_t num_posixopens;
43735- atomic_t num_posixmkdirs;
43736- atomic_t num_rmdirs;
43737- atomic_t num_renames;
43738- atomic_t num_t2renames;
43739- atomic_t num_ffirst;
43740- atomic_t num_fnext;
43741- atomic_t num_fclose;
43742- atomic_t num_hardlinks;
43743- atomic_t num_symlinks;
43744- atomic_t num_locks;
43745- atomic_t num_acl_get;
43746- atomic_t num_acl_set;
43747+ atomic_unchecked_t num_smbs_sent;
43748+ atomic_unchecked_t num_writes;
43749+ atomic_unchecked_t num_reads;
43750+ atomic_unchecked_t num_flushes;
43751+ atomic_unchecked_t num_oplock_brks;
43752+ atomic_unchecked_t num_opens;
43753+ atomic_unchecked_t num_closes;
43754+ atomic_unchecked_t num_deletes;
43755+ atomic_unchecked_t num_mkdirs;
43756+ atomic_unchecked_t num_posixopens;
43757+ atomic_unchecked_t num_posixmkdirs;
43758+ atomic_unchecked_t num_rmdirs;
43759+ atomic_unchecked_t num_renames;
43760+ atomic_unchecked_t num_t2renames;
43761+ atomic_unchecked_t num_ffirst;
43762+ atomic_unchecked_t num_fnext;
43763+ atomic_unchecked_t num_fclose;
43764+ atomic_unchecked_t num_hardlinks;
43765+ atomic_unchecked_t num_symlinks;
43766+ atomic_unchecked_t num_locks;
43767+ atomic_unchecked_t num_acl_get;
43768+ atomic_unchecked_t num_acl_set;
43769 #ifdef CONFIG_CIFS_STATS2
43770 unsigned long long time_writes;
43771 unsigned long long time_reads;
43772@@ -735,7 +735,7 @@ convert_delimiter(char *path, char delim)
43773 }
43774
43775 #ifdef CONFIG_CIFS_STATS
43776-#define cifs_stats_inc atomic_inc
43777+#define cifs_stats_inc atomic_inc_unchecked
43778
43779 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
43780 unsigned int bytes)
43781@@ -1093,8 +1093,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
43782 /* Various Debug counters */
43783 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
43784 #ifdef CONFIG_CIFS_STATS2
43785-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
43786-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
43787+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
43788+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
43789 #endif
43790 GLOBAL_EXTERN atomic_t smBufAllocCount;
43791 GLOBAL_EXTERN atomic_t midCount;
43792diff --git a/fs/cifs/link.c b/fs/cifs/link.c
43793index 6b0e064..94e6c3c 100644
43794--- a/fs/cifs/link.c
43795+++ b/fs/cifs/link.c
43796@@ -600,7 +600,7 @@ symlink_exit:
43797
43798 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
43799 {
43800- char *p = nd_get_link(nd);
43801+ const char *p = nd_get_link(nd);
43802 if (!IS_ERR(p))
43803 kfree(p);
43804 }
43805diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
43806index 557506a..2fd3816 100644
43807--- a/fs/cifs/misc.c
43808+++ b/fs/cifs/misc.c
43809@@ -156,7 +156,7 @@ cifs_buf_get(void)
43810 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
43811 atomic_inc(&bufAllocCount);
43812 #ifdef CONFIG_CIFS_STATS2
43813- atomic_inc(&totBufAllocCount);
43814+ atomic_inc_unchecked(&totBufAllocCount);
43815 #endif /* CONFIG_CIFS_STATS2 */
43816 }
43817
43818@@ -191,7 +191,7 @@ cifs_small_buf_get(void)
43819 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
43820 atomic_inc(&smBufAllocCount);
43821 #ifdef CONFIG_CIFS_STATS2
43822- atomic_inc(&totSmBufAllocCount);
43823+ atomic_inc_unchecked(&totSmBufAllocCount);
43824 #endif /* CONFIG_CIFS_STATS2 */
43825
43826 }
43827diff --git a/fs/coda/cache.c b/fs/coda/cache.c
43828index 6901578..d402eb5 100644
43829--- a/fs/coda/cache.c
43830+++ b/fs/coda/cache.c
43831@@ -24,7 +24,7 @@
43832 #include "coda_linux.h"
43833 #include "coda_cache.h"
43834
43835-static atomic_t permission_epoch = ATOMIC_INIT(0);
43836+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
43837
43838 /* replace or extend an acl cache hit */
43839 void coda_cache_enter(struct inode *inode, int mask)
43840@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
43841 struct coda_inode_info *cii = ITOC(inode);
43842
43843 spin_lock(&cii->c_lock);
43844- cii->c_cached_epoch = atomic_read(&permission_epoch);
43845+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
43846 if (cii->c_uid != current_fsuid()) {
43847 cii->c_uid = current_fsuid();
43848 cii->c_cached_perm = mask;
43849@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
43850 {
43851 struct coda_inode_info *cii = ITOC(inode);
43852 spin_lock(&cii->c_lock);
43853- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
43854+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
43855 spin_unlock(&cii->c_lock);
43856 }
43857
43858 /* remove all acl caches */
43859 void coda_cache_clear_all(struct super_block *sb)
43860 {
43861- atomic_inc(&permission_epoch);
43862+ atomic_inc_unchecked(&permission_epoch);
43863 }
43864
43865
43866@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
43867 spin_lock(&cii->c_lock);
43868 hit = (mask & cii->c_cached_perm) == mask &&
43869 cii->c_uid == current_fsuid() &&
43870- cii->c_cached_epoch == atomic_read(&permission_epoch);
43871+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
43872 spin_unlock(&cii->c_lock);
43873
43874 return hit;
43875diff --git a/fs/compat.c b/fs/compat.c
43876index 6161255..9f28287 100644
43877--- a/fs/compat.c
43878+++ b/fs/compat.c
43879@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
43880
43881 set_fs(KERNEL_DS);
43882 /* The __user pointer cast is valid because of the set_fs() */
43883- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
43884+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
43885 set_fs(oldfs);
43886 /* truncating is ok because it's a user address */
43887 if (!ret)
43888@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
43889 goto out;
43890
43891 ret = -EINVAL;
43892- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
43893+ if (nr_segs > UIO_MAXIOV)
43894 goto out;
43895 if (nr_segs > fast_segs) {
43896 ret = -ENOMEM;
43897@@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
43898
43899 struct compat_readdir_callback {
43900 struct compat_old_linux_dirent __user *dirent;
43901+ struct file * file;
43902 int result;
43903 };
43904
43905@@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
43906 buf->result = -EOVERFLOW;
43907 return -EOVERFLOW;
43908 }
43909+
43910+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43911+ return 0;
43912+
43913 buf->result++;
43914 dirent = buf->dirent;
43915 if (!access_ok(VERIFY_WRITE, dirent,
43916@@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
43917
43918 buf.result = 0;
43919 buf.dirent = dirent;
43920+ buf.file = file;
43921
43922 error = vfs_readdir(file, compat_fillonedir, &buf);
43923 if (buf.result)
43924@@ -899,6 +905,7 @@ struct compat_linux_dirent {
43925 struct compat_getdents_callback {
43926 struct compat_linux_dirent __user *current_dir;
43927 struct compat_linux_dirent __user *previous;
43928+ struct file * file;
43929 int count;
43930 int error;
43931 };
43932@@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
43933 buf->error = -EOVERFLOW;
43934 return -EOVERFLOW;
43935 }
43936+
43937+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43938+ return 0;
43939+
43940 dirent = buf->previous;
43941 if (dirent) {
43942 if (__put_user(offset, &dirent->d_off))
43943@@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
43944 buf.previous = NULL;
43945 buf.count = count;
43946 buf.error = 0;
43947+ buf.file = file;
43948
43949 error = vfs_readdir(file, compat_filldir, &buf);
43950 if (error >= 0)
43951@@ -986,6 +998,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
43952 struct compat_getdents_callback64 {
43953 struct linux_dirent64 __user *current_dir;
43954 struct linux_dirent64 __user *previous;
43955+ struct file * file;
43956 int count;
43957 int error;
43958 };
43959@@ -1002,6 +1015,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
43960 buf->error = -EINVAL; /* only used if we fail.. */
43961 if (reclen > buf->count)
43962 return -EINVAL;
43963+
43964+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43965+ return 0;
43966+
43967 dirent = buf->previous;
43968
43969 if (dirent) {
43970@@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
43971 buf.previous = NULL;
43972 buf.count = count;
43973 buf.error = 0;
43974+ buf.file = file;
43975
43976 error = vfs_readdir(file, compat_filldir64, &buf);
43977 if (error >= 0)
43978 error = buf.error;
43979 lastdirent = buf.previous;
43980 if (lastdirent) {
43981- typeof(lastdirent->d_off) d_off = file->f_pos;
43982+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
43983 if (__put_user_unaligned(d_off, &lastdirent->d_off))
43984 error = -EFAULT;
43985 else
43986@@ -1155,11 +1173,14 @@ compat_sys_readv(unsigned long fd, const struct compat_iovec __user *vec,
43987 struct file *file;
43988 int fput_needed;
43989 ssize_t ret;
43990+ loff_t pos;
43991
43992 file = fget_light(fd, &fput_needed);
43993 if (!file)
43994 return -EBADF;
43995- ret = compat_readv(file, vec, vlen, &file->f_pos);
43996+ pos = file->f_pos;
43997+ ret = compat_readv(file, vec, vlen, &pos);
43998+ file->f_pos = pos;
43999 fput_light(file, fput_needed);
44000 return ret;
44001 }
44002@@ -1221,11 +1242,14 @@ compat_sys_writev(unsigned long fd, const struct compat_iovec __user *vec,
44003 struct file *file;
44004 int fput_needed;
44005 ssize_t ret;
44006+ loff_t pos;
44007
44008 file = fget_light(fd, &fput_needed);
44009 if (!file)
44010 return -EBADF;
44011- ret = compat_writev(file, vec, vlen, &file->f_pos);
44012+ pos = file->f_pos;
44013+ ret = compat_writev(file, vec, vlen, &pos);
44014+ file->f_pos = pos;
44015 fput_light(file, fput_needed);
44016 return ret;
44017 }
44018diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
44019index 112e45a..b59845b 100644
44020--- a/fs/compat_binfmt_elf.c
44021+++ b/fs/compat_binfmt_elf.c
44022@@ -30,11 +30,13 @@
44023 #undef elf_phdr
44024 #undef elf_shdr
44025 #undef elf_note
44026+#undef elf_dyn
44027 #undef elf_addr_t
44028 #define elfhdr elf32_hdr
44029 #define elf_phdr elf32_phdr
44030 #define elf_shdr elf32_shdr
44031 #define elf_note elf32_note
44032+#define elf_dyn Elf32_Dyn
44033 #define elf_addr_t Elf32_Addr
44034
44035 /*
44036diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
44037index debdfe0..75d31d4 100644
44038--- a/fs/compat_ioctl.c
44039+++ b/fs/compat_ioctl.c
44040@@ -210,6 +210,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
44041
44042 err = get_user(palp, &up->palette);
44043 err |= get_user(length, &up->length);
44044+ if (err)
44045+ return -EFAULT;
44046
44047 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
44048 err = put_user(compat_ptr(palp), &up_native->palette);
44049@@ -621,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
44050 return -EFAULT;
44051 if (__get_user(udata, &ss32->iomem_base))
44052 return -EFAULT;
44053- ss.iomem_base = compat_ptr(udata);
44054+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
44055 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
44056 __get_user(ss.port_high, &ss32->port_high))
44057 return -EFAULT;
44058@@ -796,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
44059 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
44060 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
44061 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
44062- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44063+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44064 return -EFAULT;
44065
44066 return ioctl_preallocate(file, p);
44067@@ -1610,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
44068 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
44069 {
44070 unsigned int a, b;
44071- a = *(unsigned int *)p;
44072- b = *(unsigned int *)q;
44073+ a = *(const unsigned int *)p;
44074+ b = *(const unsigned int *)q;
44075 if (a > b)
44076 return 1;
44077 if (a < b)
44078diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
44079index 7e6c52d..94bc756 100644
44080--- a/fs/configfs/dir.c
44081+++ b/fs/configfs/dir.c
44082@@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44083 }
44084 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
44085 struct configfs_dirent *next;
44086- const char * name;
44087+ const unsigned char * name;
44088+ char d_name[sizeof(next->s_dentry->d_iname)];
44089 int len;
44090 struct inode *inode = NULL;
44091
44092@@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44093 continue;
44094
44095 name = configfs_get_name(next);
44096- len = strlen(name);
44097+ if (next->s_dentry && name == next->s_dentry->d_iname) {
44098+ len = next->s_dentry->d_name.len;
44099+ memcpy(d_name, name, len);
44100+ name = d_name;
44101+ } else
44102+ len = strlen(name);
44103
44104 /*
44105 * We'll have a dentry and an inode for
44106diff --git a/fs/dcache.c b/fs/dcache.c
44107index 4046904..5e31505 100644
44108--- a/fs/dcache.c
44109+++ b/fs/dcache.c
44110@@ -3154,7 +3154,7 @@ void __init vfs_caches_init(unsigned long mempages)
44111 mempages -= reserve;
44112
44113 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
44114- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
44115+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
44116
44117 dcache_init();
44118 inode_init();
44119diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
44120index b80bc84..0d46d1a 100644
44121--- a/fs/debugfs/inode.c
44122+++ b/fs/debugfs/inode.c
44123@@ -408,7 +408,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
44124 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
44125 {
44126 return debugfs_create_file(name,
44127+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
44128+ S_IFDIR | S_IRWXU,
44129+#else
44130 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
44131+#endif
44132 parent, NULL, NULL);
44133 }
44134 EXPORT_SYMBOL_GPL(debugfs_create_dir);
44135diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
44136index a07441a..046fc0d 100644
44137--- a/fs/ecryptfs/inode.c
44138+++ b/fs/ecryptfs/inode.c
44139@@ -671,7 +671,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
44140 old_fs = get_fs();
44141 set_fs(get_ds());
44142 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
44143- (char __user *)lower_buf,
44144+ (char __force_user *)lower_buf,
44145 PATH_MAX);
44146 set_fs(old_fs);
44147 if (rc < 0)
44148@@ -703,7 +703,7 @@ out:
44149 static void
44150 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
44151 {
44152- char *buf = nd_get_link(nd);
44153+ const char *buf = nd_get_link(nd);
44154 if (!IS_ERR(buf)) {
44155 /* Free the char* */
44156 kfree(buf);
44157diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
44158index c0038f6..47ab347 100644
44159--- a/fs/ecryptfs/miscdev.c
44160+++ b/fs/ecryptfs/miscdev.c
44161@@ -355,7 +355,7 @@ check_list:
44162 goto out_unlock_msg_ctx;
44163 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
44164 if (msg_ctx->msg) {
44165- if (copy_to_user(&buf[i], packet_length, packet_length_size))
44166+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
44167 goto out_unlock_msg_ctx;
44168 i += packet_length_size;
44169 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
44170diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
44171index b2a34a1..162fa69 100644
44172--- a/fs/ecryptfs/read_write.c
44173+++ b/fs/ecryptfs/read_write.c
44174@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
44175 return -EIO;
44176 fs_save = get_fs();
44177 set_fs(get_ds());
44178- rc = vfs_write(lower_file, data, size, &offset);
44179+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
44180 set_fs(fs_save);
44181 mark_inode_dirty_sync(ecryptfs_inode);
44182 return rc;
44183@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
44184 return -EIO;
44185 fs_save = get_fs();
44186 set_fs(get_ds());
44187- rc = vfs_read(lower_file, data, size, &offset);
44188+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
44189 set_fs(fs_save);
44190 return rc;
44191 }
44192diff --git a/fs/exec.c b/fs/exec.c
44193index e95aeed..a943469 100644
44194--- a/fs/exec.c
44195+++ b/fs/exec.c
44196@@ -55,6 +55,15 @@
44197 #include <linux/pipe_fs_i.h>
44198 #include <linux/oom.h>
44199 #include <linux/compat.h>
44200+#include <linux/random.h>
44201+#include <linux/seq_file.h>
44202+
44203+#ifdef CONFIG_PAX_REFCOUNT
44204+#include <linux/kallsyms.h>
44205+#include <linux/kdebug.h>
44206+#endif
44207+
44208+#include <trace/events/fs.h>
44209
44210 #include <asm/uaccess.h>
44211 #include <asm/mmu_context.h>
44212@@ -66,6 +75,18 @@
44213
44214 #include <trace/events/sched.h>
44215
44216+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
44217+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
44218+{
44219+ 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");
44220+}
44221+#endif
44222+
44223+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
44224+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
44225+EXPORT_SYMBOL(pax_set_initial_flags_func);
44226+#endif
44227+
44228 int core_uses_pid;
44229 char core_pattern[CORENAME_MAX_SIZE] = "core";
44230 unsigned int core_pipe_limit;
44231@@ -75,7 +96,7 @@ struct core_name {
44232 char *corename;
44233 int used, size;
44234 };
44235-static atomic_t call_count = ATOMIC_INIT(1);
44236+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
44237
44238 /* The maximal length of core_pattern is also specified in sysctl.c */
44239
44240@@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44241 int write)
44242 {
44243 struct page *page;
44244- int ret;
44245
44246-#ifdef CONFIG_STACK_GROWSUP
44247- if (write) {
44248- ret = expand_downwards(bprm->vma, pos);
44249- if (ret < 0)
44250- return NULL;
44251- }
44252-#endif
44253- ret = get_user_pages(current, bprm->mm, pos,
44254- 1, write, 1, &page, NULL);
44255- if (ret <= 0)
44256+ if (0 > expand_downwards(bprm->vma, pos))
44257+ return NULL;
44258+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
44259 return NULL;
44260
44261 if (write) {
44262@@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44263 if (size <= ARG_MAX)
44264 return page;
44265
44266+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44267+ // only allow 512KB for argv+env on suid/sgid binaries
44268+ // to prevent easy ASLR exhaustion
44269+ if (((bprm->cred->euid != current_euid()) ||
44270+ (bprm->cred->egid != current_egid())) &&
44271+ (size > (512 * 1024))) {
44272+ put_page(page);
44273+ return NULL;
44274+ }
44275+#endif
44276+
44277 /*
44278 * Limit to 1/4-th the stack size for the argv+env strings.
44279 * This ensures that:
44280@@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44281 vma->vm_end = STACK_TOP_MAX;
44282 vma->vm_start = vma->vm_end - PAGE_SIZE;
44283 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
44284+
44285+#ifdef CONFIG_PAX_SEGMEXEC
44286+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
44287+#endif
44288+
44289 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
44290 INIT_LIST_HEAD(&vma->anon_vma_chain);
44291
44292@@ -287,6 +316,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44293 mm->stack_vm = mm->total_vm = 1;
44294 up_write(&mm->mmap_sem);
44295 bprm->p = vma->vm_end - sizeof(void *);
44296+
44297+#ifdef CONFIG_PAX_RANDUSTACK
44298+ if (randomize_va_space)
44299+ bprm->p ^= random32() & ~PAGE_MASK;
44300+#endif
44301+
44302 return 0;
44303 err:
44304 up_write(&mm->mmap_sem);
44305@@ -395,19 +430,7 @@ err:
44306 return err;
44307 }
44308
44309-struct user_arg_ptr {
44310-#ifdef CONFIG_COMPAT
44311- bool is_compat;
44312-#endif
44313- union {
44314- const char __user *const __user *native;
44315-#ifdef CONFIG_COMPAT
44316- compat_uptr_t __user *compat;
44317-#endif
44318- } ptr;
44319-};
44320-
44321-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44322+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44323 {
44324 const char __user *native;
44325
44326@@ -416,14 +439,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44327 compat_uptr_t compat;
44328
44329 if (get_user(compat, argv.ptr.compat + nr))
44330- return ERR_PTR(-EFAULT);
44331+ return (const char __force_user *)ERR_PTR(-EFAULT);
44332
44333 return compat_ptr(compat);
44334 }
44335 #endif
44336
44337 if (get_user(native, argv.ptr.native + nr))
44338- return ERR_PTR(-EFAULT);
44339+ return (const char __force_user *)ERR_PTR(-EFAULT);
44340
44341 return native;
44342 }
44343@@ -442,7 +465,7 @@ static int count(struct user_arg_ptr argv, int max)
44344 if (!p)
44345 break;
44346
44347- if (IS_ERR(p))
44348+ if (IS_ERR((const char __force_kernel *)p))
44349 return -EFAULT;
44350
44351 if (i++ >= max)
44352@@ -476,7 +499,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
44353
44354 ret = -EFAULT;
44355 str = get_user_arg_ptr(argv, argc);
44356- if (IS_ERR(str))
44357+ if (IS_ERR((const char __force_kernel *)str))
44358 goto out;
44359
44360 len = strnlen_user(str, MAX_ARG_STRLEN);
44361@@ -558,7 +581,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
44362 int r;
44363 mm_segment_t oldfs = get_fs();
44364 struct user_arg_ptr argv = {
44365- .ptr.native = (const char __user *const __user *)__argv,
44366+ .ptr.native = (const char __force_user *const __force_user *)__argv,
44367 };
44368
44369 set_fs(KERNEL_DS);
44370@@ -593,7 +616,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44371 unsigned long new_end = old_end - shift;
44372 struct mmu_gather tlb;
44373
44374- BUG_ON(new_start > new_end);
44375+ if (new_start >= new_end || new_start < mmap_min_addr)
44376+ return -ENOMEM;
44377
44378 /*
44379 * ensure there are no vmas between where we want to go
44380@@ -602,6 +626,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44381 if (vma != find_vma(mm, new_start))
44382 return -EFAULT;
44383
44384+#ifdef CONFIG_PAX_SEGMEXEC
44385+ BUG_ON(pax_find_mirror_vma(vma));
44386+#endif
44387+
44388 /*
44389 * cover the whole range: [new_start, old_end)
44390 */
44391@@ -682,10 +710,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44392 stack_top = arch_align_stack(stack_top);
44393 stack_top = PAGE_ALIGN(stack_top);
44394
44395- if (unlikely(stack_top < mmap_min_addr) ||
44396- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
44397- return -ENOMEM;
44398-
44399 stack_shift = vma->vm_end - stack_top;
44400
44401 bprm->p -= stack_shift;
44402@@ -697,8 +721,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
44403 bprm->exec -= stack_shift;
44404
44405 down_write(&mm->mmap_sem);
44406+
44407+ /* Move stack pages down in memory. */
44408+ if (stack_shift) {
44409+ ret = shift_arg_pages(vma, stack_shift);
44410+ if (ret)
44411+ goto out_unlock;
44412+ }
44413+
44414 vm_flags = VM_STACK_FLAGS;
44415
44416+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44417+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44418+ vm_flags &= ~VM_EXEC;
44419+
44420+#ifdef CONFIG_PAX_MPROTECT
44421+ if (mm->pax_flags & MF_PAX_MPROTECT)
44422+ vm_flags &= ~VM_MAYEXEC;
44423+#endif
44424+
44425+ }
44426+#endif
44427+
44428 /*
44429 * Adjust stack execute permissions; explicitly enable for
44430 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
44431@@ -717,13 +761,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44432 goto out_unlock;
44433 BUG_ON(prev != vma);
44434
44435- /* Move stack pages down in memory. */
44436- if (stack_shift) {
44437- ret = shift_arg_pages(vma, stack_shift);
44438- if (ret)
44439- goto out_unlock;
44440- }
44441-
44442 /* mprotect_fixup is overkill to remove the temporary stack flags */
44443 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
44444
44445@@ -781,6 +818,8 @@ struct file *open_exec(const char *name)
44446
44447 fsnotify_open(file);
44448
44449+ trace_open_exec(name);
44450+
44451 err = deny_write_access(file);
44452 if (err)
44453 goto exit;
44454@@ -804,7 +843,7 @@ int kernel_read(struct file *file, loff_t offset,
44455 old_fs = get_fs();
44456 set_fs(get_ds());
44457 /* The cast to a user pointer is valid due to the set_fs() */
44458- result = vfs_read(file, (void __user *)addr, count, &pos);
44459+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
44460 set_fs(old_fs);
44461 return result;
44462 }
44463@@ -1257,7 +1296,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
44464 }
44465 rcu_read_unlock();
44466
44467- if (p->fs->users > n_fs) {
44468+ if (atomic_read(&p->fs->users) > n_fs) {
44469 bprm->unsafe |= LSM_UNSAFE_SHARE;
44470 } else {
44471 res = -EAGAIN;
44472@@ -1460,6 +1499,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
44473
44474 EXPORT_SYMBOL(search_binary_handler);
44475
44476+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44477+static DEFINE_PER_CPU(u64, exec_counter);
44478+static int __init init_exec_counters(void)
44479+{
44480+ unsigned int cpu;
44481+
44482+ for_each_possible_cpu(cpu) {
44483+ per_cpu(exec_counter, cpu) = (u64)cpu;
44484+ }
44485+
44486+ return 0;
44487+}
44488+early_initcall(init_exec_counters);
44489+static inline void increment_exec_counter(void)
44490+{
44491+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
44492+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
44493+}
44494+#else
44495+static inline void increment_exec_counter(void) {}
44496+#endif
44497+
44498 /*
44499 * sys_execve() executes a new program.
44500 */
44501@@ -1468,6 +1529,11 @@ static int do_execve_common(const char *filename,
44502 struct user_arg_ptr envp,
44503 struct pt_regs *regs)
44504 {
44505+#ifdef CONFIG_GRKERNSEC
44506+ struct file *old_exec_file;
44507+ struct acl_subject_label *old_acl;
44508+ struct rlimit old_rlim[RLIM_NLIMITS];
44509+#endif
44510 struct linux_binprm *bprm;
44511 struct file *file;
44512 struct files_struct *displaced;
44513@@ -1475,6 +1541,8 @@ static int do_execve_common(const char *filename,
44514 int retval;
44515 const struct cred *cred = current_cred();
44516
44517+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
44518+
44519 /*
44520 * We move the actual failure in case of RLIMIT_NPROC excess from
44521 * set*uid() to execve() because too many poorly written programs
44522@@ -1515,12 +1583,27 @@ static int do_execve_common(const char *filename,
44523 if (IS_ERR(file))
44524 goto out_unmark;
44525
44526+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
44527+ retval = -EPERM;
44528+ goto out_file;
44529+ }
44530+
44531 sched_exec();
44532
44533 bprm->file = file;
44534 bprm->filename = filename;
44535 bprm->interp = filename;
44536
44537+ if (gr_process_user_ban()) {
44538+ retval = -EPERM;
44539+ goto out_file;
44540+ }
44541+
44542+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
44543+ retval = -EACCES;
44544+ goto out_file;
44545+ }
44546+
44547 retval = bprm_mm_init(bprm);
44548 if (retval)
44549 goto out_file;
44550@@ -1537,24 +1620,65 @@ static int do_execve_common(const char *filename,
44551 if (retval < 0)
44552 goto out;
44553
44554+#ifdef CONFIG_GRKERNSEC
44555+ old_acl = current->acl;
44556+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
44557+ old_exec_file = current->exec_file;
44558+ get_file(file);
44559+ current->exec_file = file;
44560+#endif
44561+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44562+ /* limit suid stack to 8MB
44563+ we saved the old limits above and will restore them if this exec fails
44564+ */
44565+ if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
44566+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
44567+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
44568+#endif
44569+
44570+ if (!gr_tpe_allow(file)) {
44571+ retval = -EACCES;
44572+ goto out_fail;
44573+ }
44574+
44575+ if (gr_check_crash_exec(file)) {
44576+ retval = -EACCES;
44577+ goto out_fail;
44578+ }
44579+
44580+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
44581+ bprm->unsafe);
44582+ if (retval < 0)
44583+ goto out_fail;
44584+
44585 retval = copy_strings_kernel(1, &bprm->filename, bprm);
44586 if (retval < 0)
44587- goto out;
44588+ goto out_fail;
44589
44590 bprm->exec = bprm->p;
44591 retval = copy_strings(bprm->envc, envp, bprm);
44592 if (retval < 0)
44593- goto out;
44594+ goto out_fail;
44595
44596 retval = copy_strings(bprm->argc, argv, bprm);
44597 if (retval < 0)
44598- goto out;
44599+ goto out_fail;
44600+
44601+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
44602+
44603+ gr_handle_exec_args(bprm, argv);
44604
44605 retval = search_binary_handler(bprm,regs);
44606 if (retval < 0)
44607- goto out;
44608+ goto out_fail;
44609+#ifdef CONFIG_GRKERNSEC
44610+ if (old_exec_file)
44611+ fput(old_exec_file);
44612+#endif
44613
44614 /* execve succeeded */
44615+
44616+ increment_exec_counter();
44617 current->fs->in_exec = 0;
44618 current->in_execve = 0;
44619 acct_update_integrals(current);
44620@@ -1563,6 +1687,14 @@ static int do_execve_common(const char *filename,
44621 put_files_struct(displaced);
44622 return retval;
44623
44624+out_fail:
44625+#ifdef CONFIG_GRKERNSEC
44626+ current->acl = old_acl;
44627+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
44628+ fput(current->exec_file);
44629+ current->exec_file = old_exec_file;
44630+#endif
44631+
44632 out:
44633 if (bprm->mm) {
44634 acct_arg_size(bprm, 0);
44635@@ -1636,7 +1768,7 @@ static int expand_corename(struct core_name *cn)
44636 {
44637 char *old_corename = cn->corename;
44638
44639- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
44640+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
44641 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
44642
44643 if (!cn->corename) {
44644@@ -1733,7 +1865,7 @@ static int format_corename(struct core_name *cn, long signr)
44645 int pid_in_pattern = 0;
44646 int err = 0;
44647
44648- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
44649+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
44650 cn->corename = kmalloc(cn->size, GFP_KERNEL);
44651 cn->used = 0;
44652
44653@@ -1830,6 +1962,250 @@ out:
44654 return ispipe;
44655 }
44656
44657+int pax_check_flags(unsigned long *flags)
44658+{
44659+ int retval = 0;
44660+
44661+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
44662+ if (*flags & MF_PAX_SEGMEXEC)
44663+ {
44664+ *flags &= ~MF_PAX_SEGMEXEC;
44665+ retval = -EINVAL;
44666+ }
44667+#endif
44668+
44669+ if ((*flags & MF_PAX_PAGEEXEC)
44670+
44671+#ifdef CONFIG_PAX_PAGEEXEC
44672+ && (*flags & MF_PAX_SEGMEXEC)
44673+#endif
44674+
44675+ )
44676+ {
44677+ *flags &= ~MF_PAX_PAGEEXEC;
44678+ retval = -EINVAL;
44679+ }
44680+
44681+ if ((*flags & MF_PAX_MPROTECT)
44682+
44683+#ifdef CONFIG_PAX_MPROTECT
44684+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44685+#endif
44686+
44687+ )
44688+ {
44689+ *flags &= ~MF_PAX_MPROTECT;
44690+ retval = -EINVAL;
44691+ }
44692+
44693+ if ((*flags & MF_PAX_EMUTRAMP)
44694+
44695+#ifdef CONFIG_PAX_EMUTRAMP
44696+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44697+#endif
44698+
44699+ )
44700+ {
44701+ *flags &= ~MF_PAX_EMUTRAMP;
44702+ retval = -EINVAL;
44703+ }
44704+
44705+ return retval;
44706+}
44707+
44708+EXPORT_SYMBOL(pax_check_flags);
44709+
44710+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44711+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
44712+{
44713+ struct task_struct *tsk = current;
44714+ struct mm_struct *mm = current->mm;
44715+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
44716+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
44717+ char *path_exec = NULL;
44718+ char *path_fault = NULL;
44719+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
44720+
44721+ if (buffer_exec && buffer_fault) {
44722+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
44723+
44724+ down_read(&mm->mmap_sem);
44725+ vma = mm->mmap;
44726+ while (vma && (!vma_exec || !vma_fault)) {
44727+ if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
44728+ vma_exec = vma;
44729+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
44730+ vma_fault = vma;
44731+ vma = vma->vm_next;
44732+ }
44733+ if (vma_exec) {
44734+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
44735+ if (IS_ERR(path_exec))
44736+ path_exec = "<path too long>";
44737+ else {
44738+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
44739+ if (path_exec) {
44740+ *path_exec = 0;
44741+ path_exec = buffer_exec;
44742+ } else
44743+ path_exec = "<path too long>";
44744+ }
44745+ }
44746+ if (vma_fault) {
44747+ start = vma_fault->vm_start;
44748+ end = vma_fault->vm_end;
44749+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
44750+ if (vma_fault->vm_file) {
44751+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
44752+ if (IS_ERR(path_fault))
44753+ path_fault = "<path too long>";
44754+ else {
44755+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
44756+ if (path_fault) {
44757+ *path_fault = 0;
44758+ path_fault = buffer_fault;
44759+ } else
44760+ path_fault = "<path too long>";
44761+ }
44762+ } else
44763+ path_fault = "<anonymous mapping>";
44764+ }
44765+ up_read(&mm->mmap_sem);
44766+ }
44767+ if (tsk->signal->curr_ip)
44768+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
44769+ else
44770+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
44771+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
44772+ "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
44773+ task_uid(tsk), task_euid(tsk), pc, sp);
44774+ free_page((unsigned long)buffer_exec);
44775+ free_page((unsigned long)buffer_fault);
44776+ pax_report_insns(regs, pc, sp);
44777+ do_coredump(SIGKILL, SIGKILL, regs);
44778+}
44779+#endif
44780+
44781+#ifdef CONFIG_PAX_REFCOUNT
44782+void pax_report_refcount_overflow(struct pt_regs *regs)
44783+{
44784+ if (current->signal->curr_ip)
44785+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44786+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
44787+ else
44788+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44789+ current->comm, task_pid_nr(current), current_uid(), current_euid());
44790+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
44791+ show_regs(regs);
44792+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
44793+}
44794+#endif
44795+
44796+#ifdef CONFIG_PAX_USERCOPY
44797+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
44798+static noinline int check_stack_object(const void *obj, unsigned long len)
44799+{
44800+ const void * const stack = task_stack_page(current);
44801+ const void * const stackend = stack + THREAD_SIZE;
44802+
44803+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44804+ const void *frame = NULL;
44805+ const void *oldframe;
44806+#endif
44807+
44808+ if (obj + len < obj)
44809+ return -1;
44810+
44811+ if (obj + len <= stack || stackend <= obj)
44812+ return 0;
44813+
44814+ if (obj < stack || stackend < obj + len)
44815+ return -1;
44816+
44817+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44818+ oldframe = __builtin_frame_address(1);
44819+ if (oldframe)
44820+ frame = __builtin_frame_address(2);
44821+ /*
44822+ low ----------------------------------------------> high
44823+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
44824+ ^----------------^
44825+ allow copies only within here
44826+ */
44827+ while (stack <= frame && frame < stackend) {
44828+ /* if obj + len extends past the last frame, this
44829+ check won't pass and the next frame will be 0,
44830+ causing us to bail out and correctly report
44831+ the copy as invalid
44832+ */
44833+ if (obj + len <= frame)
44834+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
44835+ oldframe = frame;
44836+ frame = *(const void * const *)frame;
44837+ }
44838+ return -1;
44839+#else
44840+ return 1;
44841+#endif
44842+}
44843+
44844+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
44845+{
44846+ if (current->signal->curr_ip)
44847+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44848+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44849+ else
44850+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44851+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44852+ dump_stack();
44853+ gr_handle_kernel_exploit();
44854+ do_group_exit(SIGKILL);
44855+}
44856+#endif
44857+
44858+void check_object_size(const void *ptr, unsigned long n, bool to)
44859+{
44860+
44861+#ifdef CONFIG_PAX_USERCOPY
44862+ const char *type;
44863+
44864+ if (!n)
44865+ return;
44866+
44867+ type = check_heap_object(ptr, n, to);
44868+ if (!type) {
44869+ if (check_stack_object(ptr, n) != -1)
44870+ return;
44871+ type = "<process stack>";
44872+ }
44873+
44874+ pax_report_usercopy(ptr, n, to, type);
44875+#endif
44876+
44877+}
44878+EXPORT_SYMBOL(check_object_size);
44879+
44880+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
44881+void pax_track_stack(void)
44882+{
44883+ unsigned long sp = (unsigned long)&sp;
44884+ if (sp < current_thread_info()->lowest_stack &&
44885+ sp > (unsigned long)task_stack_page(current))
44886+ current_thread_info()->lowest_stack = sp;
44887+}
44888+EXPORT_SYMBOL(pax_track_stack);
44889+#endif
44890+
44891+#ifdef CONFIG_PAX_SIZE_OVERFLOW
44892+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
44893+{
44894+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
44895+ dump_stack();
44896+ do_group_exit(SIGKILL);
44897+}
44898+EXPORT_SYMBOL(report_size_overflow);
44899+#endif
44900+
44901 static int zap_process(struct task_struct *start, int exit_code)
44902 {
44903 struct task_struct *t;
44904@@ -2002,17 +2378,17 @@ static void coredump_finish(struct mm_struct *mm)
44905 void set_dumpable(struct mm_struct *mm, int value)
44906 {
44907 switch (value) {
44908- case 0:
44909+ case SUID_DUMPABLE_DISABLED:
44910 clear_bit(MMF_DUMPABLE, &mm->flags);
44911 smp_wmb();
44912 clear_bit(MMF_DUMP_SECURELY, &mm->flags);
44913 break;
44914- case 1:
44915+ case SUID_DUMPABLE_ENABLED:
44916 set_bit(MMF_DUMPABLE, &mm->flags);
44917 smp_wmb();
44918 clear_bit(MMF_DUMP_SECURELY, &mm->flags);
44919 break;
44920- case 2:
44921+ case SUID_DUMPABLE_SAFE:
44922 set_bit(MMF_DUMP_SECURELY, &mm->flags);
44923 smp_wmb();
44924 set_bit(MMF_DUMPABLE, &mm->flags);
44925@@ -2025,7 +2401,7 @@ static int __get_dumpable(unsigned long mm_flags)
44926 int ret;
44927
44928 ret = mm_flags & MMF_DUMPABLE_MASK;
44929- return (ret >= 2) ? 2 : ret;
44930+ return (ret > SUID_DUMPABLE_ENABLED) ? SUID_DUMPABLE_SAFE : ret;
44931 }
44932
44933 int get_dumpable(struct mm_struct *mm)
44934@@ -2040,17 +2416,17 @@ static void wait_for_dump_helpers(struct file *file)
44935 pipe = file->f_path.dentry->d_inode->i_pipe;
44936
44937 pipe_lock(pipe);
44938- pipe->readers++;
44939- pipe->writers--;
44940+ atomic_inc(&pipe->readers);
44941+ atomic_dec(&pipe->writers);
44942
44943- while ((pipe->readers > 1) && (!signal_pending(current))) {
44944+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
44945 wake_up_interruptible_sync(&pipe->wait);
44946 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
44947 pipe_wait(pipe);
44948 }
44949
44950- pipe->readers--;
44951- pipe->writers++;
44952+ atomic_dec(&pipe->readers);
44953+ atomic_inc(&pipe->writers);
44954 pipe_unlock(pipe);
44955
44956 }
44957@@ -2111,7 +2487,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44958 int retval = 0;
44959 int flag = 0;
44960 int ispipe;
44961- static atomic_t core_dump_count = ATOMIC_INIT(0);
44962+ bool need_nonrelative = false;
44963+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
44964 struct coredump_params cprm = {
44965 .signr = signr,
44966 .regs = regs,
44967@@ -2126,6 +2503,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44968
44969 audit_core_dumps(signr);
44970
44971+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
44972+ gr_handle_brute_attach(current, cprm.mm_flags);
44973+
44974 binfmt = mm->binfmt;
44975 if (!binfmt || !binfmt->core_dump)
44976 goto fail;
44977@@ -2136,14 +2516,16 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44978 if (!cred)
44979 goto fail;
44980 /*
44981- * We cannot trust fsuid as being the "true" uid of the
44982- * process nor do we know its entire history. We only know it
44983- * was tainted so we dump it as root in mode 2.
44984+ * We cannot trust fsuid as being the "true" uid of the process
44985+ * nor do we know its entire history. We only know it was tainted
44986+ * so we dump it as root in mode 2, and only into a controlled
44987+ * environment (pipe handler or fully qualified path).
44988 */
44989- if (__get_dumpable(cprm.mm_flags) == 2) {
44990+ if (__get_dumpable(cprm.mm_flags) == SUID_DUMPABLE_SAFE) {
44991 /* Setuid core dump mode */
44992 flag = O_EXCL; /* Stop rewrite attacks */
44993 cred->fsuid = GLOBAL_ROOT_UID; /* Dump root private */
44994+ need_nonrelative = true;
44995 }
44996
44997 retval = coredump_wait(exit_code, &core_state);
44998@@ -2193,7 +2575,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44999 }
45000 cprm.limit = RLIM_INFINITY;
45001
45002- dump_count = atomic_inc_return(&core_dump_count);
45003+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
45004 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
45005 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
45006 task_tgid_vnr(current), current->comm);
45007@@ -2220,9 +2602,19 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45008 } else {
45009 struct inode *inode;
45010
45011+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
45012+
45013 if (cprm.limit < binfmt->min_coredump)
45014 goto fail_unlock;
45015
45016+ if (need_nonrelative && cn.corename[0] != '/') {
45017+ printk(KERN_WARNING "Pid %d(%s) can only dump core "\
45018+ "to fully qualified path!\n",
45019+ task_tgid_vnr(current), current->comm);
45020+ printk(KERN_WARNING "Skipping core dump\n");
45021+ goto fail_unlock;
45022+ }
45023+
45024 cprm.file = filp_open(cn.corename,
45025 O_CREAT | 2 | O_NOFOLLOW | O_LARGEFILE | flag,
45026 0600);
45027@@ -2263,7 +2655,7 @@ close_fail:
45028 filp_close(cprm.file, NULL);
45029 fail_dropcount:
45030 if (ispipe)
45031- atomic_dec(&core_dump_count);
45032+ atomic_dec_unchecked(&core_dump_count);
45033 fail_unlock:
45034 kfree(cn.corename);
45035 fail_corename:
45036@@ -2282,7 +2674,7 @@ fail:
45037 */
45038 int dump_write(struct file *file, const void *addr, int nr)
45039 {
45040- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
45041+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
45042 }
45043 EXPORT_SYMBOL(dump_write);
45044
45045diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
45046index 1c36139..cf6b350 100644
45047--- a/fs/ext2/balloc.c
45048+++ b/fs/ext2/balloc.c
45049@@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
45050
45051 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45052 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45053- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45054+ if (free_blocks < root_blocks + 1 &&
45055 !uid_eq(sbi->s_resuid, current_fsuid()) &&
45056 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45057- !in_group_p (sbi->s_resgid))) {
45058+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45059 return 0;
45060 }
45061 return 1;
45062diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
45063index 25cd608..9ed5294 100644
45064--- a/fs/ext3/balloc.c
45065+++ b/fs/ext3/balloc.c
45066@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
45067
45068 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45069 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45070- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45071+ if (free_blocks < root_blocks + 1 &&
45072 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
45073 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45074- !in_group_p (sbi->s_resgid))) {
45075+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45076 return 0;
45077 }
45078 return 1;
45079diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
45080index d23b31c..0585239 100644
45081--- a/fs/ext4/balloc.c
45082+++ b/fs/ext4/balloc.c
45083@@ -488,8 +488,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
45084 /* Hm, nope. Are (enough) root reserved clusters available? */
45085 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
45086 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
45087- capable(CAP_SYS_RESOURCE) ||
45088- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
45089+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
45090+ capable_nolog(CAP_SYS_RESOURCE)) {
45091
45092 if (free_clusters >= (nclusters + dirty_clusters))
45093 return 1;
45094diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
45095index 01434f2..bd995b4 100644
45096--- a/fs/ext4/ext4.h
45097+++ b/fs/ext4/ext4.h
45098@@ -1246,19 +1246,19 @@ struct ext4_sb_info {
45099 unsigned long s_mb_last_start;
45100
45101 /* stats for buddy allocator */
45102- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45103- atomic_t s_bal_success; /* we found long enough chunks */
45104- atomic_t s_bal_allocated; /* in blocks */
45105- atomic_t s_bal_ex_scanned; /* total extents scanned */
45106- atomic_t s_bal_goals; /* goal hits */
45107- atomic_t s_bal_breaks; /* too long searches */
45108- atomic_t s_bal_2orders; /* 2^order hits */
45109+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45110+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45111+ atomic_unchecked_t s_bal_allocated; /* in blocks */
45112+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45113+ atomic_unchecked_t s_bal_goals; /* goal hits */
45114+ atomic_unchecked_t s_bal_breaks; /* too long searches */
45115+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45116 spinlock_t s_bal_lock;
45117 unsigned long s_mb_buddies_generated;
45118 unsigned long long s_mb_generation_time;
45119- atomic_t s_mb_lost_chunks;
45120- atomic_t s_mb_preallocated;
45121- atomic_t s_mb_discarded;
45122+ atomic_unchecked_t s_mb_lost_chunks;
45123+ atomic_unchecked_t s_mb_preallocated;
45124+ atomic_unchecked_t s_mb_discarded;
45125 atomic_t s_lock_busy;
45126
45127 /* locality groups */
45128diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
45129index 58a75fe..9752106 100644
45130--- a/fs/ext4/extents.c
45131+++ b/fs/ext4/extents.c
45132@@ -2663,6 +2663,7 @@ cont:
45133 }
45134 path[0].p_depth = depth;
45135 path[0].p_hdr = ext_inode_hdr(inode);
45136+ i = 0;
45137
45138 if (ext4_ext_check(inode, path[0].p_hdr, depth)) {
45139 err = -EIO;
45140diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
45141index 1cd6994..5799d45 100644
45142--- a/fs/ext4/mballoc.c
45143+++ b/fs/ext4/mballoc.c
45144@@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
45145 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45146
45147 if (EXT4_SB(sb)->s_mb_stats)
45148- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45149+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45150
45151 break;
45152 }
45153@@ -2041,7 +2041,7 @@ repeat:
45154 ac->ac_status = AC_STATUS_CONTINUE;
45155 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45156 cr = 3;
45157- atomic_inc(&sbi->s_mb_lost_chunks);
45158+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45159 goto repeat;
45160 }
45161 }
45162@@ -2545,25 +2545,25 @@ int ext4_mb_release(struct super_block *sb)
45163 if (sbi->s_mb_stats) {
45164 ext4_msg(sb, KERN_INFO,
45165 "mballoc: %u blocks %u reqs (%u success)",
45166- atomic_read(&sbi->s_bal_allocated),
45167- atomic_read(&sbi->s_bal_reqs),
45168- atomic_read(&sbi->s_bal_success));
45169+ atomic_read_unchecked(&sbi->s_bal_allocated),
45170+ atomic_read_unchecked(&sbi->s_bal_reqs),
45171+ atomic_read_unchecked(&sbi->s_bal_success));
45172 ext4_msg(sb, KERN_INFO,
45173 "mballoc: %u extents scanned, %u goal hits, "
45174 "%u 2^N hits, %u breaks, %u lost",
45175- atomic_read(&sbi->s_bal_ex_scanned),
45176- atomic_read(&sbi->s_bal_goals),
45177- atomic_read(&sbi->s_bal_2orders),
45178- atomic_read(&sbi->s_bal_breaks),
45179- atomic_read(&sbi->s_mb_lost_chunks));
45180+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45181+ atomic_read_unchecked(&sbi->s_bal_goals),
45182+ atomic_read_unchecked(&sbi->s_bal_2orders),
45183+ atomic_read_unchecked(&sbi->s_bal_breaks),
45184+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45185 ext4_msg(sb, KERN_INFO,
45186 "mballoc: %lu generated and it took %Lu",
45187 sbi->s_mb_buddies_generated,
45188 sbi->s_mb_generation_time);
45189 ext4_msg(sb, KERN_INFO,
45190 "mballoc: %u preallocated, %u discarded",
45191- atomic_read(&sbi->s_mb_preallocated),
45192- atomic_read(&sbi->s_mb_discarded));
45193+ atomic_read_unchecked(&sbi->s_mb_preallocated),
45194+ atomic_read_unchecked(&sbi->s_mb_discarded));
45195 }
45196
45197 free_percpu(sbi->s_locality_groups);
45198@@ -3047,16 +3047,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
45199 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45200
45201 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45202- atomic_inc(&sbi->s_bal_reqs);
45203- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45204+ atomic_inc_unchecked(&sbi->s_bal_reqs);
45205+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45206 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
45207- atomic_inc(&sbi->s_bal_success);
45208- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45209+ atomic_inc_unchecked(&sbi->s_bal_success);
45210+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45211 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45212 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45213- atomic_inc(&sbi->s_bal_goals);
45214+ atomic_inc_unchecked(&sbi->s_bal_goals);
45215 if (ac->ac_found > sbi->s_mb_max_to_scan)
45216- atomic_inc(&sbi->s_bal_breaks);
45217+ atomic_inc_unchecked(&sbi->s_bal_breaks);
45218 }
45219
45220 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45221@@ -3456,7 +3456,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
45222 trace_ext4_mb_new_inode_pa(ac, pa);
45223
45224 ext4_mb_use_inode_pa(ac, pa);
45225- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
45226+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
45227
45228 ei = EXT4_I(ac->ac_inode);
45229 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45230@@ -3516,7 +3516,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
45231 trace_ext4_mb_new_group_pa(ac, pa);
45232
45233 ext4_mb_use_group_pa(ac, pa);
45234- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45235+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45236
45237 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45238 lg = ac->ac_lg;
45239@@ -3605,7 +3605,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
45240 * from the bitmap and continue.
45241 */
45242 }
45243- atomic_add(free, &sbi->s_mb_discarded);
45244+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
45245
45246 return err;
45247 }
45248@@ -3623,7 +3623,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
45249 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
45250 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
45251 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
45252- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45253+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45254 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
45255
45256 return 0;
45257diff --git a/fs/fcntl.c b/fs/fcntl.c
45258index 81b70e6..d9ae6cf 100644
45259--- a/fs/fcntl.c
45260+++ b/fs/fcntl.c
45261@@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
45262 if (err)
45263 return err;
45264
45265+ if (gr_handle_chroot_fowner(pid, type))
45266+ return -ENOENT;
45267+ if (gr_check_protected_task_fowner(pid, type))
45268+ return -EACCES;
45269+
45270 f_modown(filp, pid, type, force);
45271 return 0;
45272 }
45273@@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
45274
45275 static int f_setown_ex(struct file *filp, unsigned long arg)
45276 {
45277- struct f_owner_ex * __user owner_p = (void * __user)arg;
45278+ struct f_owner_ex __user *owner_p = (void __user *)arg;
45279 struct f_owner_ex owner;
45280 struct pid *pid;
45281 int type;
45282@@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
45283
45284 static int f_getown_ex(struct file *filp, unsigned long arg)
45285 {
45286- struct f_owner_ex * __user owner_p = (void * __user)arg;
45287+ struct f_owner_ex __user *owner_p = (void __user *)arg;
45288 struct f_owner_ex owner;
45289 int ret = 0;
45290
45291@@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
45292 switch (cmd) {
45293 case F_DUPFD:
45294 case F_DUPFD_CLOEXEC:
45295+ gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
45296 if (arg >= rlimit(RLIMIT_NOFILE))
45297 break;
45298 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
45299diff --git a/fs/fifo.c b/fs/fifo.c
45300index cf6f434..3d7942c 100644
45301--- a/fs/fifo.c
45302+++ b/fs/fifo.c
45303@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
45304 */
45305 filp->f_op = &read_pipefifo_fops;
45306 pipe->r_counter++;
45307- if (pipe->readers++ == 0)
45308+ if (atomic_inc_return(&pipe->readers) == 1)
45309 wake_up_partner(inode);
45310
45311- if (!pipe->writers) {
45312+ if (!atomic_read(&pipe->writers)) {
45313 if ((filp->f_flags & O_NONBLOCK)) {
45314 /* suppress POLLHUP until we have
45315 * seen a writer */
45316@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
45317 * errno=ENXIO when there is no process reading the FIFO.
45318 */
45319 ret = -ENXIO;
45320- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
45321+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
45322 goto err;
45323
45324 filp->f_op = &write_pipefifo_fops;
45325 pipe->w_counter++;
45326- if (!pipe->writers++)
45327+ if (atomic_inc_return(&pipe->writers) == 1)
45328 wake_up_partner(inode);
45329
45330- if (!pipe->readers) {
45331+ if (!atomic_read(&pipe->readers)) {
45332 if (wait_for_partner(inode, &pipe->r_counter))
45333 goto err_wr;
45334 }
45335@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
45336 */
45337 filp->f_op = &rdwr_pipefifo_fops;
45338
45339- pipe->readers++;
45340- pipe->writers++;
45341+ atomic_inc(&pipe->readers);
45342+ atomic_inc(&pipe->writers);
45343 pipe->r_counter++;
45344 pipe->w_counter++;
45345- if (pipe->readers == 1 || pipe->writers == 1)
45346+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
45347 wake_up_partner(inode);
45348 break;
45349
45350@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
45351 return 0;
45352
45353 err_rd:
45354- if (!--pipe->readers)
45355+ if (atomic_dec_and_test(&pipe->readers))
45356 wake_up_interruptible(&pipe->wait);
45357 ret = -ERESTARTSYS;
45358 goto err;
45359
45360 err_wr:
45361- if (!--pipe->writers)
45362+ if (atomic_dec_and_test(&pipe->writers))
45363 wake_up_interruptible(&pipe->wait);
45364 ret = -ERESTARTSYS;
45365 goto err;
45366
45367 err:
45368- if (!pipe->readers && !pipe->writers)
45369+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
45370 free_pipe_info(inode);
45371
45372 err_nocleanup:
45373diff --git a/fs/file.c b/fs/file.c
45374index ba3f605..fade102 100644
45375--- a/fs/file.c
45376+++ b/fs/file.c
45377@@ -15,6 +15,7 @@
45378 #include <linux/slab.h>
45379 #include <linux/vmalloc.h>
45380 #include <linux/file.h>
45381+#include <linux/security.h>
45382 #include <linux/fdtable.h>
45383 #include <linux/bitops.h>
45384 #include <linux/interrupt.h>
45385@@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
45386 * N.B. For clone tasks sharing a files structure, this test
45387 * will limit the total number of files that can be opened.
45388 */
45389+ gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
45390 if (nr >= rlimit(RLIMIT_NOFILE))
45391 return -EMFILE;
45392
45393diff --git a/fs/filesystems.c b/fs/filesystems.c
45394index 96f2428..f5eeb8e 100644
45395--- a/fs/filesystems.c
45396+++ b/fs/filesystems.c
45397@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
45398 int len = dot ? dot - name : strlen(name);
45399
45400 fs = __get_fs_type(name, len);
45401+
45402+#ifdef CONFIG_GRKERNSEC_MODHARDEN
45403+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
45404+#else
45405 if (!fs && (request_module("%.*s", len, name) == 0))
45406+#endif
45407 fs = __get_fs_type(name, len);
45408
45409 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
45410diff --git a/fs/fs_struct.c b/fs/fs_struct.c
45411index e159e68..e7d2a6f 100644
45412--- a/fs/fs_struct.c
45413+++ b/fs/fs_struct.c
45414@@ -4,6 +4,7 @@
45415 #include <linux/path.h>
45416 #include <linux/slab.h>
45417 #include <linux/fs_struct.h>
45418+#include <linux/grsecurity.h>
45419 #include "internal.h"
45420
45421 static inline void path_get_longterm(struct path *path)
45422@@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
45423 write_seqcount_begin(&fs->seq);
45424 old_root = fs->root;
45425 fs->root = *path;
45426+ gr_set_chroot_entries(current, path);
45427 write_seqcount_end(&fs->seq);
45428 spin_unlock(&fs->lock);
45429 if (old_root.dentry)
45430@@ -65,6 +67,17 @@ static inline int replace_path(struct path *p, const struct path *old, const str
45431 return 1;
45432 }
45433
45434+static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
45435+{
45436+ if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
45437+ return 0;
45438+ *p = *new;
45439+
45440+ gr_set_chroot_entries(task, new);
45441+
45442+ return 1;
45443+}
45444+
45445 void chroot_fs_refs(struct path *old_root, struct path *new_root)
45446 {
45447 struct task_struct *g, *p;
45448@@ -79,7 +92,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
45449 int hits = 0;
45450 spin_lock(&fs->lock);
45451 write_seqcount_begin(&fs->seq);
45452- hits += replace_path(&fs->root, old_root, new_root);
45453+ hits += replace_root_path(p, &fs->root, old_root, new_root);
45454 hits += replace_path(&fs->pwd, old_root, new_root);
45455 write_seqcount_end(&fs->seq);
45456 while (hits--) {
45457@@ -111,7 +124,8 @@ void exit_fs(struct task_struct *tsk)
45458 task_lock(tsk);
45459 spin_lock(&fs->lock);
45460 tsk->fs = NULL;
45461- kill = !--fs->users;
45462+ gr_clear_chroot_entries(tsk);
45463+ kill = !atomic_dec_return(&fs->users);
45464 spin_unlock(&fs->lock);
45465 task_unlock(tsk);
45466 if (kill)
45467@@ -124,7 +138,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45468 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
45469 /* We don't need to lock fs - think why ;-) */
45470 if (fs) {
45471- fs->users = 1;
45472+ atomic_set(&fs->users, 1);
45473 fs->in_exec = 0;
45474 spin_lock_init(&fs->lock);
45475 seqcount_init(&fs->seq);
45476@@ -133,6 +147,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45477 spin_lock(&old->lock);
45478 fs->root = old->root;
45479 path_get_longterm(&fs->root);
45480+ /* instead of calling gr_set_chroot_entries here,
45481+ we call it from every caller of this function
45482+ */
45483 fs->pwd = old->pwd;
45484 path_get_longterm(&fs->pwd);
45485 spin_unlock(&old->lock);
45486@@ -151,8 +168,9 @@ int unshare_fs_struct(void)
45487
45488 task_lock(current);
45489 spin_lock(&fs->lock);
45490- kill = !--fs->users;
45491+ kill = !atomic_dec_return(&fs->users);
45492 current->fs = new_fs;
45493+ gr_set_chroot_entries(current, &new_fs->root);
45494 spin_unlock(&fs->lock);
45495 task_unlock(current);
45496
45497@@ -165,13 +183,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
45498
45499 int current_umask(void)
45500 {
45501- return current->fs->umask;
45502+ return current->fs->umask | gr_acl_umask();
45503 }
45504 EXPORT_SYMBOL(current_umask);
45505
45506 /* to be mentioned only in INIT_TASK */
45507 struct fs_struct init_fs = {
45508- .users = 1,
45509+ .users = ATOMIC_INIT(1),
45510 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
45511 .seq = SEQCNT_ZERO,
45512 .umask = 0022,
45513@@ -187,12 +205,13 @@ void daemonize_fs_struct(void)
45514 task_lock(current);
45515
45516 spin_lock(&init_fs.lock);
45517- init_fs.users++;
45518+ atomic_inc(&init_fs.users);
45519 spin_unlock(&init_fs.lock);
45520
45521 spin_lock(&fs->lock);
45522 current->fs = &init_fs;
45523- kill = !--fs->users;
45524+ gr_set_chroot_entries(current, &current->fs->root);
45525+ kill = !atomic_dec_return(&fs->users);
45526 spin_unlock(&fs->lock);
45527
45528 task_unlock(current);
45529diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
45530index 9905350..02eaec4 100644
45531--- a/fs/fscache/cookie.c
45532+++ b/fs/fscache/cookie.c
45533@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
45534 parent ? (char *) parent->def->name : "<no-parent>",
45535 def->name, netfs_data);
45536
45537- fscache_stat(&fscache_n_acquires);
45538+ fscache_stat_unchecked(&fscache_n_acquires);
45539
45540 /* if there's no parent cookie, then we don't create one here either */
45541 if (!parent) {
45542- fscache_stat(&fscache_n_acquires_null);
45543+ fscache_stat_unchecked(&fscache_n_acquires_null);
45544 _leave(" [no parent]");
45545 return NULL;
45546 }
45547@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
45548 /* allocate and initialise a cookie */
45549 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
45550 if (!cookie) {
45551- fscache_stat(&fscache_n_acquires_oom);
45552+ fscache_stat_unchecked(&fscache_n_acquires_oom);
45553 _leave(" [ENOMEM]");
45554 return NULL;
45555 }
45556@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45557
45558 switch (cookie->def->type) {
45559 case FSCACHE_COOKIE_TYPE_INDEX:
45560- fscache_stat(&fscache_n_cookie_index);
45561+ fscache_stat_unchecked(&fscache_n_cookie_index);
45562 break;
45563 case FSCACHE_COOKIE_TYPE_DATAFILE:
45564- fscache_stat(&fscache_n_cookie_data);
45565+ fscache_stat_unchecked(&fscache_n_cookie_data);
45566 break;
45567 default:
45568- fscache_stat(&fscache_n_cookie_special);
45569+ fscache_stat_unchecked(&fscache_n_cookie_special);
45570 break;
45571 }
45572
45573@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45574 if (fscache_acquire_non_index_cookie(cookie) < 0) {
45575 atomic_dec(&parent->n_children);
45576 __fscache_cookie_put(cookie);
45577- fscache_stat(&fscache_n_acquires_nobufs);
45578+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
45579 _leave(" = NULL");
45580 return NULL;
45581 }
45582 }
45583
45584- fscache_stat(&fscache_n_acquires_ok);
45585+ fscache_stat_unchecked(&fscache_n_acquires_ok);
45586 _leave(" = %p", cookie);
45587 return cookie;
45588 }
45589@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
45590 cache = fscache_select_cache_for_object(cookie->parent);
45591 if (!cache) {
45592 up_read(&fscache_addremove_sem);
45593- fscache_stat(&fscache_n_acquires_no_cache);
45594+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
45595 _leave(" = -ENOMEDIUM [no cache]");
45596 return -ENOMEDIUM;
45597 }
45598@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
45599 object = cache->ops->alloc_object(cache, cookie);
45600 fscache_stat_d(&fscache_n_cop_alloc_object);
45601 if (IS_ERR(object)) {
45602- fscache_stat(&fscache_n_object_no_alloc);
45603+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
45604 ret = PTR_ERR(object);
45605 goto error;
45606 }
45607
45608- fscache_stat(&fscache_n_object_alloc);
45609+ fscache_stat_unchecked(&fscache_n_object_alloc);
45610
45611 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
45612
45613@@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
45614 struct fscache_object *object;
45615 struct hlist_node *_p;
45616
45617- fscache_stat(&fscache_n_updates);
45618+ fscache_stat_unchecked(&fscache_n_updates);
45619
45620 if (!cookie) {
45621- fscache_stat(&fscache_n_updates_null);
45622+ fscache_stat_unchecked(&fscache_n_updates_null);
45623 _leave(" [no cookie]");
45624 return;
45625 }
45626@@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45627 struct fscache_object *object;
45628 unsigned long event;
45629
45630- fscache_stat(&fscache_n_relinquishes);
45631+ fscache_stat_unchecked(&fscache_n_relinquishes);
45632 if (retire)
45633- fscache_stat(&fscache_n_relinquishes_retire);
45634+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
45635
45636 if (!cookie) {
45637- fscache_stat(&fscache_n_relinquishes_null);
45638+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
45639 _leave(" [no cookie]");
45640 return;
45641 }
45642@@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45643
45644 /* wait for the cookie to finish being instantiated (or to fail) */
45645 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
45646- fscache_stat(&fscache_n_relinquishes_waitcrt);
45647+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
45648 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
45649 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
45650 }
45651diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
45652index f6aad48..88dcf26 100644
45653--- a/fs/fscache/internal.h
45654+++ b/fs/fscache/internal.h
45655@@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
45656 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
45657 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
45658
45659-extern atomic_t fscache_n_op_pend;
45660-extern atomic_t fscache_n_op_run;
45661-extern atomic_t fscache_n_op_enqueue;
45662-extern atomic_t fscache_n_op_deferred_release;
45663-extern atomic_t fscache_n_op_release;
45664-extern atomic_t fscache_n_op_gc;
45665-extern atomic_t fscache_n_op_cancelled;
45666-extern atomic_t fscache_n_op_rejected;
45667+extern atomic_unchecked_t fscache_n_op_pend;
45668+extern atomic_unchecked_t fscache_n_op_run;
45669+extern atomic_unchecked_t fscache_n_op_enqueue;
45670+extern atomic_unchecked_t fscache_n_op_deferred_release;
45671+extern atomic_unchecked_t fscache_n_op_release;
45672+extern atomic_unchecked_t fscache_n_op_gc;
45673+extern atomic_unchecked_t fscache_n_op_cancelled;
45674+extern atomic_unchecked_t fscache_n_op_rejected;
45675
45676-extern atomic_t fscache_n_attr_changed;
45677-extern atomic_t fscache_n_attr_changed_ok;
45678-extern atomic_t fscache_n_attr_changed_nobufs;
45679-extern atomic_t fscache_n_attr_changed_nomem;
45680-extern atomic_t fscache_n_attr_changed_calls;
45681+extern atomic_unchecked_t fscache_n_attr_changed;
45682+extern atomic_unchecked_t fscache_n_attr_changed_ok;
45683+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
45684+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
45685+extern atomic_unchecked_t fscache_n_attr_changed_calls;
45686
45687-extern atomic_t fscache_n_allocs;
45688-extern atomic_t fscache_n_allocs_ok;
45689-extern atomic_t fscache_n_allocs_wait;
45690-extern atomic_t fscache_n_allocs_nobufs;
45691-extern atomic_t fscache_n_allocs_intr;
45692-extern atomic_t fscache_n_allocs_object_dead;
45693-extern atomic_t fscache_n_alloc_ops;
45694-extern atomic_t fscache_n_alloc_op_waits;
45695+extern atomic_unchecked_t fscache_n_allocs;
45696+extern atomic_unchecked_t fscache_n_allocs_ok;
45697+extern atomic_unchecked_t fscache_n_allocs_wait;
45698+extern atomic_unchecked_t fscache_n_allocs_nobufs;
45699+extern atomic_unchecked_t fscache_n_allocs_intr;
45700+extern atomic_unchecked_t fscache_n_allocs_object_dead;
45701+extern atomic_unchecked_t fscache_n_alloc_ops;
45702+extern atomic_unchecked_t fscache_n_alloc_op_waits;
45703
45704-extern atomic_t fscache_n_retrievals;
45705-extern atomic_t fscache_n_retrievals_ok;
45706-extern atomic_t fscache_n_retrievals_wait;
45707-extern atomic_t fscache_n_retrievals_nodata;
45708-extern atomic_t fscache_n_retrievals_nobufs;
45709-extern atomic_t fscache_n_retrievals_intr;
45710-extern atomic_t fscache_n_retrievals_nomem;
45711-extern atomic_t fscache_n_retrievals_object_dead;
45712-extern atomic_t fscache_n_retrieval_ops;
45713-extern atomic_t fscache_n_retrieval_op_waits;
45714+extern atomic_unchecked_t fscache_n_retrievals;
45715+extern atomic_unchecked_t fscache_n_retrievals_ok;
45716+extern atomic_unchecked_t fscache_n_retrievals_wait;
45717+extern atomic_unchecked_t fscache_n_retrievals_nodata;
45718+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
45719+extern atomic_unchecked_t fscache_n_retrievals_intr;
45720+extern atomic_unchecked_t fscache_n_retrievals_nomem;
45721+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
45722+extern atomic_unchecked_t fscache_n_retrieval_ops;
45723+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
45724
45725-extern atomic_t fscache_n_stores;
45726-extern atomic_t fscache_n_stores_ok;
45727-extern atomic_t fscache_n_stores_again;
45728-extern atomic_t fscache_n_stores_nobufs;
45729-extern atomic_t fscache_n_stores_oom;
45730-extern atomic_t fscache_n_store_ops;
45731-extern atomic_t fscache_n_store_calls;
45732-extern atomic_t fscache_n_store_pages;
45733-extern atomic_t fscache_n_store_radix_deletes;
45734-extern atomic_t fscache_n_store_pages_over_limit;
45735+extern atomic_unchecked_t fscache_n_stores;
45736+extern atomic_unchecked_t fscache_n_stores_ok;
45737+extern atomic_unchecked_t fscache_n_stores_again;
45738+extern atomic_unchecked_t fscache_n_stores_nobufs;
45739+extern atomic_unchecked_t fscache_n_stores_oom;
45740+extern atomic_unchecked_t fscache_n_store_ops;
45741+extern atomic_unchecked_t fscache_n_store_calls;
45742+extern atomic_unchecked_t fscache_n_store_pages;
45743+extern atomic_unchecked_t fscache_n_store_radix_deletes;
45744+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
45745
45746-extern atomic_t fscache_n_store_vmscan_not_storing;
45747-extern atomic_t fscache_n_store_vmscan_gone;
45748-extern atomic_t fscache_n_store_vmscan_busy;
45749-extern atomic_t fscache_n_store_vmscan_cancelled;
45750+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45751+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
45752+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
45753+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45754
45755-extern atomic_t fscache_n_marks;
45756-extern atomic_t fscache_n_uncaches;
45757+extern atomic_unchecked_t fscache_n_marks;
45758+extern atomic_unchecked_t fscache_n_uncaches;
45759
45760-extern atomic_t fscache_n_acquires;
45761-extern atomic_t fscache_n_acquires_null;
45762-extern atomic_t fscache_n_acquires_no_cache;
45763-extern atomic_t fscache_n_acquires_ok;
45764-extern atomic_t fscache_n_acquires_nobufs;
45765-extern atomic_t fscache_n_acquires_oom;
45766+extern atomic_unchecked_t fscache_n_acquires;
45767+extern atomic_unchecked_t fscache_n_acquires_null;
45768+extern atomic_unchecked_t fscache_n_acquires_no_cache;
45769+extern atomic_unchecked_t fscache_n_acquires_ok;
45770+extern atomic_unchecked_t fscache_n_acquires_nobufs;
45771+extern atomic_unchecked_t fscache_n_acquires_oom;
45772
45773-extern atomic_t fscache_n_updates;
45774-extern atomic_t fscache_n_updates_null;
45775-extern atomic_t fscache_n_updates_run;
45776+extern atomic_unchecked_t fscache_n_updates;
45777+extern atomic_unchecked_t fscache_n_updates_null;
45778+extern atomic_unchecked_t fscache_n_updates_run;
45779
45780-extern atomic_t fscache_n_relinquishes;
45781-extern atomic_t fscache_n_relinquishes_null;
45782-extern atomic_t fscache_n_relinquishes_waitcrt;
45783-extern atomic_t fscache_n_relinquishes_retire;
45784+extern atomic_unchecked_t fscache_n_relinquishes;
45785+extern atomic_unchecked_t fscache_n_relinquishes_null;
45786+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
45787+extern atomic_unchecked_t fscache_n_relinquishes_retire;
45788
45789-extern atomic_t fscache_n_cookie_index;
45790-extern atomic_t fscache_n_cookie_data;
45791-extern atomic_t fscache_n_cookie_special;
45792+extern atomic_unchecked_t fscache_n_cookie_index;
45793+extern atomic_unchecked_t fscache_n_cookie_data;
45794+extern atomic_unchecked_t fscache_n_cookie_special;
45795
45796-extern atomic_t fscache_n_object_alloc;
45797-extern atomic_t fscache_n_object_no_alloc;
45798-extern atomic_t fscache_n_object_lookups;
45799-extern atomic_t fscache_n_object_lookups_negative;
45800-extern atomic_t fscache_n_object_lookups_positive;
45801-extern atomic_t fscache_n_object_lookups_timed_out;
45802-extern atomic_t fscache_n_object_created;
45803-extern atomic_t fscache_n_object_avail;
45804-extern atomic_t fscache_n_object_dead;
45805+extern atomic_unchecked_t fscache_n_object_alloc;
45806+extern atomic_unchecked_t fscache_n_object_no_alloc;
45807+extern atomic_unchecked_t fscache_n_object_lookups;
45808+extern atomic_unchecked_t fscache_n_object_lookups_negative;
45809+extern atomic_unchecked_t fscache_n_object_lookups_positive;
45810+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
45811+extern atomic_unchecked_t fscache_n_object_created;
45812+extern atomic_unchecked_t fscache_n_object_avail;
45813+extern atomic_unchecked_t fscache_n_object_dead;
45814
45815-extern atomic_t fscache_n_checkaux_none;
45816-extern atomic_t fscache_n_checkaux_okay;
45817-extern atomic_t fscache_n_checkaux_update;
45818-extern atomic_t fscache_n_checkaux_obsolete;
45819+extern atomic_unchecked_t fscache_n_checkaux_none;
45820+extern atomic_unchecked_t fscache_n_checkaux_okay;
45821+extern atomic_unchecked_t fscache_n_checkaux_update;
45822+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
45823
45824 extern atomic_t fscache_n_cop_alloc_object;
45825 extern atomic_t fscache_n_cop_lookup_object;
45826@@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
45827 atomic_inc(stat);
45828 }
45829
45830+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
45831+{
45832+ atomic_inc_unchecked(stat);
45833+}
45834+
45835 static inline void fscache_stat_d(atomic_t *stat)
45836 {
45837 atomic_dec(stat);
45838@@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
45839
45840 #define __fscache_stat(stat) (NULL)
45841 #define fscache_stat(stat) do {} while (0)
45842+#define fscache_stat_unchecked(stat) do {} while (0)
45843 #define fscache_stat_d(stat) do {} while (0)
45844 #endif
45845
45846diff --git a/fs/fscache/object.c b/fs/fscache/object.c
45847index b6b897c..0ffff9c 100644
45848--- a/fs/fscache/object.c
45849+++ b/fs/fscache/object.c
45850@@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45851 /* update the object metadata on disk */
45852 case FSCACHE_OBJECT_UPDATING:
45853 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
45854- fscache_stat(&fscache_n_updates_run);
45855+ fscache_stat_unchecked(&fscache_n_updates_run);
45856 fscache_stat(&fscache_n_cop_update_object);
45857 object->cache->ops->update_object(object);
45858 fscache_stat_d(&fscache_n_cop_update_object);
45859@@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45860 spin_lock(&object->lock);
45861 object->state = FSCACHE_OBJECT_DEAD;
45862 spin_unlock(&object->lock);
45863- fscache_stat(&fscache_n_object_dead);
45864+ fscache_stat_unchecked(&fscache_n_object_dead);
45865 goto terminal_transit;
45866
45867 /* handle the parent cache of this object being withdrawn from
45868@@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45869 spin_lock(&object->lock);
45870 object->state = FSCACHE_OBJECT_DEAD;
45871 spin_unlock(&object->lock);
45872- fscache_stat(&fscache_n_object_dead);
45873+ fscache_stat_unchecked(&fscache_n_object_dead);
45874 goto terminal_transit;
45875
45876 /* complain about the object being woken up once it is
45877@@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45878 parent->cookie->def->name, cookie->def->name,
45879 object->cache->tag->name);
45880
45881- fscache_stat(&fscache_n_object_lookups);
45882+ fscache_stat_unchecked(&fscache_n_object_lookups);
45883 fscache_stat(&fscache_n_cop_lookup_object);
45884 ret = object->cache->ops->lookup_object(object);
45885 fscache_stat_d(&fscache_n_cop_lookup_object);
45886@@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45887 if (ret == -ETIMEDOUT) {
45888 /* probably stuck behind another object, so move this one to
45889 * the back of the queue */
45890- fscache_stat(&fscache_n_object_lookups_timed_out);
45891+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
45892 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45893 }
45894
45895@@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
45896
45897 spin_lock(&object->lock);
45898 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45899- fscache_stat(&fscache_n_object_lookups_negative);
45900+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
45901
45902 /* transit here to allow write requests to begin stacking up
45903 * and read requests to begin returning ENODATA */
45904@@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
45905 * result, in which case there may be data available */
45906 spin_lock(&object->lock);
45907 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45908- fscache_stat(&fscache_n_object_lookups_positive);
45909+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
45910
45911 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
45912
45913@@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
45914 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45915 } else {
45916 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
45917- fscache_stat(&fscache_n_object_created);
45918+ fscache_stat_unchecked(&fscache_n_object_created);
45919
45920 object->state = FSCACHE_OBJECT_AVAILABLE;
45921 spin_unlock(&object->lock);
45922@@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
45923 fscache_enqueue_dependents(object);
45924
45925 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
45926- fscache_stat(&fscache_n_object_avail);
45927+ fscache_stat_unchecked(&fscache_n_object_avail);
45928
45929 _leave("");
45930 }
45931@@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45932 enum fscache_checkaux result;
45933
45934 if (!object->cookie->def->check_aux) {
45935- fscache_stat(&fscache_n_checkaux_none);
45936+ fscache_stat_unchecked(&fscache_n_checkaux_none);
45937 return FSCACHE_CHECKAUX_OKAY;
45938 }
45939
45940@@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45941 switch (result) {
45942 /* entry okay as is */
45943 case FSCACHE_CHECKAUX_OKAY:
45944- fscache_stat(&fscache_n_checkaux_okay);
45945+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
45946 break;
45947
45948 /* entry requires update */
45949 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
45950- fscache_stat(&fscache_n_checkaux_update);
45951+ fscache_stat_unchecked(&fscache_n_checkaux_update);
45952 break;
45953
45954 /* entry requires deletion */
45955 case FSCACHE_CHECKAUX_OBSOLETE:
45956- fscache_stat(&fscache_n_checkaux_obsolete);
45957+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
45958 break;
45959
45960 default:
45961diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
45962index 30afdfa..2256596 100644
45963--- a/fs/fscache/operation.c
45964+++ b/fs/fscache/operation.c
45965@@ -17,7 +17,7 @@
45966 #include <linux/slab.h>
45967 #include "internal.h"
45968
45969-atomic_t fscache_op_debug_id;
45970+atomic_unchecked_t fscache_op_debug_id;
45971 EXPORT_SYMBOL(fscache_op_debug_id);
45972
45973 /**
45974@@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
45975 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
45976 ASSERTCMP(atomic_read(&op->usage), >, 0);
45977
45978- fscache_stat(&fscache_n_op_enqueue);
45979+ fscache_stat_unchecked(&fscache_n_op_enqueue);
45980 switch (op->flags & FSCACHE_OP_TYPE) {
45981 case FSCACHE_OP_ASYNC:
45982 _debug("queue async");
45983@@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
45984 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
45985 if (op->processor)
45986 fscache_enqueue_operation(op);
45987- fscache_stat(&fscache_n_op_run);
45988+ fscache_stat_unchecked(&fscache_n_op_run);
45989 }
45990
45991 /*
45992@@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45993 if (object->n_ops > 1) {
45994 atomic_inc(&op->usage);
45995 list_add_tail(&op->pend_link, &object->pending_ops);
45996- fscache_stat(&fscache_n_op_pend);
45997+ fscache_stat_unchecked(&fscache_n_op_pend);
45998 } else if (!list_empty(&object->pending_ops)) {
45999 atomic_inc(&op->usage);
46000 list_add_tail(&op->pend_link, &object->pending_ops);
46001- fscache_stat(&fscache_n_op_pend);
46002+ fscache_stat_unchecked(&fscache_n_op_pend);
46003 fscache_start_operations(object);
46004 } else {
46005 ASSERTCMP(object->n_in_progress, ==, 0);
46006@@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46007 object->n_exclusive++; /* reads and writes must wait */
46008 atomic_inc(&op->usage);
46009 list_add_tail(&op->pend_link, &object->pending_ops);
46010- fscache_stat(&fscache_n_op_pend);
46011+ fscache_stat_unchecked(&fscache_n_op_pend);
46012 ret = 0;
46013 } else {
46014 /* not allowed to submit ops in any other state */
46015@@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
46016 if (object->n_exclusive > 0) {
46017 atomic_inc(&op->usage);
46018 list_add_tail(&op->pend_link, &object->pending_ops);
46019- fscache_stat(&fscache_n_op_pend);
46020+ fscache_stat_unchecked(&fscache_n_op_pend);
46021 } else if (!list_empty(&object->pending_ops)) {
46022 atomic_inc(&op->usage);
46023 list_add_tail(&op->pend_link, &object->pending_ops);
46024- fscache_stat(&fscache_n_op_pend);
46025+ fscache_stat_unchecked(&fscache_n_op_pend);
46026 fscache_start_operations(object);
46027 } else {
46028 ASSERTCMP(object->n_exclusive, ==, 0);
46029@@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
46030 object->n_ops++;
46031 atomic_inc(&op->usage);
46032 list_add_tail(&op->pend_link, &object->pending_ops);
46033- fscache_stat(&fscache_n_op_pend);
46034+ fscache_stat_unchecked(&fscache_n_op_pend);
46035 ret = 0;
46036 } else if (object->state == FSCACHE_OBJECT_DYING ||
46037 object->state == FSCACHE_OBJECT_LC_DYING ||
46038 object->state == FSCACHE_OBJECT_WITHDRAWING) {
46039- fscache_stat(&fscache_n_op_rejected);
46040+ fscache_stat_unchecked(&fscache_n_op_rejected);
46041 ret = -ENOBUFS;
46042 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
46043 fscache_report_unexpected_submission(object, op, ostate);
46044@@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
46045
46046 ret = -EBUSY;
46047 if (!list_empty(&op->pend_link)) {
46048- fscache_stat(&fscache_n_op_cancelled);
46049+ fscache_stat_unchecked(&fscache_n_op_cancelled);
46050 list_del_init(&op->pend_link);
46051 object->n_ops--;
46052 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
46053@@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
46054 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
46055 BUG();
46056
46057- fscache_stat(&fscache_n_op_release);
46058+ fscache_stat_unchecked(&fscache_n_op_release);
46059
46060 if (op->release) {
46061 op->release(op);
46062@@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
46063 * lock, and defer it otherwise */
46064 if (!spin_trylock(&object->lock)) {
46065 _debug("defer put");
46066- fscache_stat(&fscache_n_op_deferred_release);
46067+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
46068
46069 cache = object->cache;
46070 spin_lock(&cache->op_gc_list_lock);
46071@@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
46072
46073 _debug("GC DEFERRED REL OBJ%x OP%x",
46074 object->debug_id, op->debug_id);
46075- fscache_stat(&fscache_n_op_gc);
46076+ fscache_stat_unchecked(&fscache_n_op_gc);
46077
46078 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46079
46080diff --git a/fs/fscache/page.c b/fs/fscache/page.c
46081index 3f7a59b..cf196cc 100644
46082--- a/fs/fscache/page.c
46083+++ b/fs/fscache/page.c
46084@@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46085 val = radix_tree_lookup(&cookie->stores, page->index);
46086 if (!val) {
46087 rcu_read_unlock();
46088- fscache_stat(&fscache_n_store_vmscan_not_storing);
46089+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46090 __fscache_uncache_page(cookie, page);
46091 return true;
46092 }
46093@@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46094 spin_unlock(&cookie->stores_lock);
46095
46096 if (xpage) {
46097- fscache_stat(&fscache_n_store_vmscan_cancelled);
46098- fscache_stat(&fscache_n_store_radix_deletes);
46099+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46100+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46101 ASSERTCMP(xpage, ==, page);
46102 } else {
46103- fscache_stat(&fscache_n_store_vmscan_gone);
46104+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46105 }
46106
46107 wake_up_bit(&cookie->flags, 0);
46108@@ -107,7 +107,7 @@ page_busy:
46109 /* we might want to wait here, but that could deadlock the allocator as
46110 * the work threads writing to the cache may all end up sleeping
46111 * on memory allocation */
46112- fscache_stat(&fscache_n_store_vmscan_busy);
46113+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46114 return false;
46115 }
46116 EXPORT_SYMBOL(__fscache_maybe_release_page);
46117@@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
46118 FSCACHE_COOKIE_STORING_TAG);
46119 if (!radix_tree_tag_get(&cookie->stores, page->index,
46120 FSCACHE_COOKIE_PENDING_TAG)) {
46121- fscache_stat(&fscache_n_store_radix_deletes);
46122+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46123 xpage = radix_tree_delete(&cookie->stores, page->index);
46124 }
46125 spin_unlock(&cookie->stores_lock);
46126@@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
46127
46128 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46129
46130- fscache_stat(&fscache_n_attr_changed_calls);
46131+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46132
46133 if (fscache_object_is_active(object)) {
46134 fscache_stat(&fscache_n_cop_attr_changed);
46135@@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46136
46137 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46138
46139- fscache_stat(&fscache_n_attr_changed);
46140+ fscache_stat_unchecked(&fscache_n_attr_changed);
46141
46142 op = kzalloc(sizeof(*op), GFP_KERNEL);
46143 if (!op) {
46144- fscache_stat(&fscache_n_attr_changed_nomem);
46145+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46146 _leave(" = -ENOMEM");
46147 return -ENOMEM;
46148 }
46149@@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46150 if (fscache_submit_exclusive_op(object, op) < 0)
46151 goto nobufs;
46152 spin_unlock(&cookie->lock);
46153- fscache_stat(&fscache_n_attr_changed_ok);
46154+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46155 fscache_put_operation(op);
46156 _leave(" = 0");
46157 return 0;
46158@@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46159 nobufs:
46160 spin_unlock(&cookie->lock);
46161 kfree(op);
46162- fscache_stat(&fscache_n_attr_changed_nobufs);
46163+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46164 _leave(" = %d", -ENOBUFS);
46165 return -ENOBUFS;
46166 }
46167@@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
46168 /* allocate a retrieval operation and attempt to submit it */
46169 op = kzalloc(sizeof(*op), GFP_NOIO);
46170 if (!op) {
46171- fscache_stat(&fscache_n_retrievals_nomem);
46172+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46173 return NULL;
46174 }
46175
46176@@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46177 return 0;
46178 }
46179
46180- fscache_stat(&fscache_n_retrievals_wait);
46181+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
46182
46183 jif = jiffies;
46184 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46185 fscache_wait_bit_interruptible,
46186 TASK_INTERRUPTIBLE) != 0) {
46187- fscache_stat(&fscache_n_retrievals_intr);
46188+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
46189 _leave(" = -ERESTARTSYS");
46190 return -ERESTARTSYS;
46191 }
46192@@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46193 */
46194 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46195 struct fscache_retrieval *op,
46196- atomic_t *stat_op_waits,
46197- atomic_t *stat_object_dead)
46198+ atomic_unchecked_t *stat_op_waits,
46199+ atomic_unchecked_t *stat_object_dead)
46200 {
46201 int ret;
46202
46203@@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46204 goto check_if_dead;
46205
46206 _debug(">>> WT");
46207- fscache_stat(stat_op_waits);
46208+ fscache_stat_unchecked(stat_op_waits);
46209 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46210 fscache_wait_bit_interruptible,
46211 TASK_INTERRUPTIBLE) < 0) {
46212@@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46213
46214 check_if_dead:
46215 if (unlikely(fscache_object_is_dead(object))) {
46216- fscache_stat(stat_object_dead);
46217+ fscache_stat_unchecked(stat_object_dead);
46218 return -ENOBUFS;
46219 }
46220 return 0;
46221@@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46222
46223 _enter("%p,%p,,,", cookie, page);
46224
46225- fscache_stat(&fscache_n_retrievals);
46226+ fscache_stat_unchecked(&fscache_n_retrievals);
46227
46228 if (hlist_empty(&cookie->backing_objects))
46229 goto nobufs;
46230@@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46231 goto nobufs_unlock;
46232 spin_unlock(&cookie->lock);
46233
46234- fscache_stat(&fscache_n_retrieval_ops);
46235+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
46236
46237 /* pin the netfs read context in case we need to do the actual netfs
46238 * read because we've encountered a cache read failure */
46239@@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46240
46241 error:
46242 if (ret == -ENOMEM)
46243- fscache_stat(&fscache_n_retrievals_nomem);
46244+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46245 else if (ret == -ERESTARTSYS)
46246- fscache_stat(&fscache_n_retrievals_intr);
46247+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
46248 else if (ret == -ENODATA)
46249- fscache_stat(&fscache_n_retrievals_nodata);
46250+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46251 else if (ret < 0)
46252- fscache_stat(&fscache_n_retrievals_nobufs);
46253+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46254 else
46255- fscache_stat(&fscache_n_retrievals_ok);
46256+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
46257
46258 fscache_put_retrieval(op);
46259 _leave(" = %d", ret);
46260@@ -429,7 +429,7 @@ nobufs_unlock:
46261 spin_unlock(&cookie->lock);
46262 kfree(op);
46263 nobufs:
46264- fscache_stat(&fscache_n_retrievals_nobufs);
46265+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46266 _leave(" = -ENOBUFS");
46267 return -ENOBUFS;
46268 }
46269@@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46270
46271 _enter("%p,,%d,,,", cookie, *nr_pages);
46272
46273- fscache_stat(&fscache_n_retrievals);
46274+ fscache_stat_unchecked(&fscache_n_retrievals);
46275
46276 if (hlist_empty(&cookie->backing_objects))
46277 goto nobufs;
46278@@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46279 goto nobufs_unlock;
46280 spin_unlock(&cookie->lock);
46281
46282- fscache_stat(&fscache_n_retrieval_ops);
46283+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
46284
46285 /* pin the netfs read context in case we need to do the actual netfs
46286 * read because we've encountered a cache read failure */
46287@@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46288
46289 error:
46290 if (ret == -ENOMEM)
46291- fscache_stat(&fscache_n_retrievals_nomem);
46292+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46293 else if (ret == -ERESTARTSYS)
46294- fscache_stat(&fscache_n_retrievals_intr);
46295+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
46296 else if (ret == -ENODATA)
46297- fscache_stat(&fscache_n_retrievals_nodata);
46298+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46299 else if (ret < 0)
46300- fscache_stat(&fscache_n_retrievals_nobufs);
46301+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46302 else
46303- fscache_stat(&fscache_n_retrievals_ok);
46304+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
46305
46306 fscache_put_retrieval(op);
46307 _leave(" = %d", ret);
46308@@ -545,7 +545,7 @@ nobufs_unlock:
46309 spin_unlock(&cookie->lock);
46310 kfree(op);
46311 nobufs:
46312- fscache_stat(&fscache_n_retrievals_nobufs);
46313+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46314 _leave(" = -ENOBUFS");
46315 return -ENOBUFS;
46316 }
46317@@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46318
46319 _enter("%p,%p,,,", cookie, page);
46320
46321- fscache_stat(&fscache_n_allocs);
46322+ fscache_stat_unchecked(&fscache_n_allocs);
46323
46324 if (hlist_empty(&cookie->backing_objects))
46325 goto nobufs;
46326@@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46327 goto nobufs_unlock;
46328 spin_unlock(&cookie->lock);
46329
46330- fscache_stat(&fscache_n_alloc_ops);
46331+ fscache_stat_unchecked(&fscache_n_alloc_ops);
46332
46333 ret = fscache_wait_for_retrieval_activation(
46334 object, op,
46335@@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46336
46337 error:
46338 if (ret == -ERESTARTSYS)
46339- fscache_stat(&fscache_n_allocs_intr);
46340+ fscache_stat_unchecked(&fscache_n_allocs_intr);
46341 else if (ret < 0)
46342- fscache_stat(&fscache_n_allocs_nobufs);
46343+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46344 else
46345- fscache_stat(&fscache_n_allocs_ok);
46346+ fscache_stat_unchecked(&fscache_n_allocs_ok);
46347
46348 fscache_put_retrieval(op);
46349 _leave(" = %d", ret);
46350@@ -625,7 +625,7 @@ nobufs_unlock:
46351 spin_unlock(&cookie->lock);
46352 kfree(op);
46353 nobufs:
46354- fscache_stat(&fscache_n_allocs_nobufs);
46355+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46356 _leave(" = -ENOBUFS");
46357 return -ENOBUFS;
46358 }
46359@@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46360
46361 spin_lock(&cookie->stores_lock);
46362
46363- fscache_stat(&fscache_n_store_calls);
46364+ fscache_stat_unchecked(&fscache_n_store_calls);
46365
46366 /* find a page to store */
46367 page = NULL;
46368@@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46369 page = results[0];
46370 _debug("gang %d [%lx]", n, page->index);
46371 if (page->index > op->store_limit) {
46372- fscache_stat(&fscache_n_store_pages_over_limit);
46373+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
46374 goto superseded;
46375 }
46376
46377@@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46378 spin_unlock(&cookie->stores_lock);
46379 spin_unlock(&object->lock);
46380
46381- fscache_stat(&fscache_n_store_pages);
46382+ fscache_stat_unchecked(&fscache_n_store_pages);
46383 fscache_stat(&fscache_n_cop_write_page);
46384 ret = object->cache->ops->write_page(op, page);
46385 fscache_stat_d(&fscache_n_cop_write_page);
46386@@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46387 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46388 ASSERT(PageFsCache(page));
46389
46390- fscache_stat(&fscache_n_stores);
46391+ fscache_stat_unchecked(&fscache_n_stores);
46392
46393 op = kzalloc(sizeof(*op), GFP_NOIO);
46394 if (!op)
46395@@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46396 spin_unlock(&cookie->stores_lock);
46397 spin_unlock(&object->lock);
46398
46399- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
46400+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
46401 op->store_limit = object->store_limit;
46402
46403 if (fscache_submit_op(object, &op->op) < 0)
46404@@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46405
46406 spin_unlock(&cookie->lock);
46407 radix_tree_preload_end();
46408- fscache_stat(&fscache_n_store_ops);
46409- fscache_stat(&fscache_n_stores_ok);
46410+ fscache_stat_unchecked(&fscache_n_store_ops);
46411+ fscache_stat_unchecked(&fscache_n_stores_ok);
46412
46413 /* the work queue now carries its own ref on the object */
46414 fscache_put_operation(&op->op);
46415@@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46416 return 0;
46417
46418 already_queued:
46419- fscache_stat(&fscache_n_stores_again);
46420+ fscache_stat_unchecked(&fscache_n_stores_again);
46421 already_pending:
46422 spin_unlock(&cookie->stores_lock);
46423 spin_unlock(&object->lock);
46424 spin_unlock(&cookie->lock);
46425 radix_tree_preload_end();
46426 kfree(op);
46427- fscache_stat(&fscache_n_stores_ok);
46428+ fscache_stat_unchecked(&fscache_n_stores_ok);
46429 _leave(" = 0");
46430 return 0;
46431
46432@@ -851,14 +851,14 @@ nobufs:
46433 spin_unlock(&cookie->lock);
46434 radix_tree_preload_end();
46435 kfree(op);
46436- fscache_stat(&fscache_n_stores_nobufs);
46437+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
46438 _leave(" = -ENOBUFS");
46439 return -ENOBUFS;
46440
46441 nomem_free:
46442 kfree(op);
46443 nomem:
46444- fscache_stat(&fscache_n_stores_oom);
46445+ fscache_stat_unchecked(&fscache_n_stores_oom);
46446 _leave(" = -ENOMEM");
46447 return -ENOMEM;
46448 }
46449@@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
46450 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46451 ASSERTCMP(page, !=, NULL);
46452
46453- fscache_stat(&fscache_n_uncaches);
46454+ fscache_stat_unchecked(&fscache_n_uncaches);
46455
46456 /* cache withdrawal may beat us to it */
46457 if (!PageFsCache(page))
46458@@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
46459 unsigned long loop;
46460
46461 #ifdef CONFIG_FSCACHE_STATS
46462- atomic_add(pagevec->nr, &fscache_n_marks);
46463+ atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
46464 #endif
46465
46466 for (loop = 0; loop < pagevec->nr; loop++) {
46467diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
46468index 4765190..2a067f2 100644
46469--- a/fs/fscache/stats.c
46470+++ b/fs/fscache/stats.c
46471@@ -18,95 +18,95 @@
46472 /*
46473 * operation counters
46474 */
46475-atomic_t fscache_n_op_pend;
46476-atomic_t fscache_n_op_run;
46477-atomic_t fscache_n_op_enqueue;
46478-atomic_t fscache_n_op_requeue;
46479-atomic_t fscache_n_op_deferred_release;
46480-atomic_t fscache_n_op_release;
46481-atomic_t fscache_n_op_gc;
46482-atomic_t fscache_n_op_cancelled;
46483-atomic_t fscache_n_op_rejected;
46484+atomic_unchecked_t fscache_n_op_pend;
46485+atomic_unchecked_t fscache_n_op_run;
46486+atomic_unchecked_t fscache_n_op_enqueue;
46487+atomic_unchecked_t fscache_n_op_requeue;
46488+atomic_unchecked_t fscache_n_op_deferred_release;
46489+atomic_unchecked_t fscache_n_op_release;
46490+atomic_unchecked_t fscache_n_op_gc;
46491+atomic_unchecked_t fscache_n_op_cancelled;
46492+atomic_unchecked_t fscache_n_op_rejected;
46493
46494-atomic_t fscache_n_attr_changed;
46495-atomic_t fscache_n_attr_changed_ok;
46496-atomic_t fscache_n_attr_changed_nobufs;
46497-atomic_t fscache_n_attr_changed_nomem;
46498-atomic_t fscache_n_attr_changed_calls;
46499+atomic_unchecked_t fscache_n_attr_changed;
46500+atomic_unchecked_t fscache_n_attr_changed_ok;
46501+atomic_unchecked_t fscache_n_attr_changed_nobufs;
46502+atomic_unchecked_t fscache_n_attr_changed_nomem;
46503+atomic_unchecked_t fscache_n_attr_changed_calls;
46504
46505-atomic_t fscache_n_allocs;
46506-atomic_t fscache_n_allocs_ok;
46507-atomic_t fscache_n_allocs_wait;
46508-atomic_t fscache_n_allocs_nobufs;
46509-atomic_t fscache_n_allocs_intr;
46510-atomic_t fscache_n_allocs_object_dead;
46511-atomic_t fscache_n_alloc_ops;
46512-atomic_t fscache_n_alloc_op_waits;
46513+atomic_unchecked_t fscache_n_allocs;
46514+atomic_unchecked_t fscache_n_allocs_ok;
46515+atomic_unchecked_t fscache_n_allocs_wait;
46516+atomic_unchecked_t fscache_n_allocs_nobufs;
46517+atomic_unchecked_t fscache_n_allocs_intr;
46518+atomic_unchecked_t fscache_n_allocs_object_dead;
46519+atomic_unchecked_t fscache_n_alloc_ops;
46520+atomic_unchecked_t fscache_n_alloc_op_waits;
46521
46522-atomic_t fscache_n_retrievals;
46523-atomic_t fscache_n_retrievals_ok;
46524-atomic_t fscache_n_retrievals_wait;
46525-atomic_t fscache_n_retrievals_nodata;
46526-atomic_t fscache_n_retrievals_nobufs;
46527-atomic_t fscache_n_retrievals_intr;
46528-atomic_t fscache_n_retrievals_nomem;
46529-atomic_t fscache_n_retrievals_object_dead;
46530-atomic_t fscache_n_retrieval_ops;
46531-atomic_t fscache_n_retrieval_op_waits;
46532+atomic_unchecked_t fscache_n_retrievals;
46533+atomic_unchecked_t fscache_n_retrievals_ok;
46534+atomic_unchecked_t fscache_n_retrievals_wait;
46535+atomic_unchecked_t fscache_n_retrievals_nodata;
46536+atomic_unchecked_t fscache_n_retrievals_nobufs;
46537+atomic_unchecked_t fscache_n_retrievals_intr;
46538+atomic_unchecked_t fscache_n_retrievals_nomem;
46539+atomic_unchecked_t fscache_n_retrievals_object_dead;
46540+atomic_unchecked_t fscache_n_retrieval_ops;
46541+atomic_unchecked_t fscache_n_retrieval_op_waits;
46542
46543-atomic_t fscache_n_stores;
46544-atomic_t fscache_n_stores_ok;
46545-atomic_t fscache_n_stores_again;
46546-atomic_t fscache_n_stores_nobufs;
46547-atomic_t fscache_n_stores_oom;
46548-atomic_t fscache_n_store_ops;
46549-atomic_t fscache_n_store_calls;
46550-atomic_t fscache_n_store_pages;
46551-atomic_t fscache_n_store_radix_deletes;
46552-atomic_t fscache_n_store_pages_over_limit;
46553+atomic_unchecked_t fscache_n_stores;
46554+atomic_unchecked_t fscache_n_stores_ok;
46555+atomic_unchecked_t fscache_n_stores_again;
46556+atomic_unchecked_t fscache_n_stores_nobufs;
46557+atomic_unchecked_t fscache_n_stores_oom;
46558+atomic_unchecked_t fscache_n_store_ops;
46559+atomic_unchecked_t fscache_n_store_calls;
46560+atomic_unchecked_t fscache_n_store_pages;
46561+atomic_unchecked_t fscache_n_store_radix_deletes;
46562+atomic_unchecked_t fscache_n_store_pages_over_limit;
46563
46564-atomic_t fscache_n_store_vmscan_not_storing;
46565-atomic_t fscache_n_store_vmscan_gone;
46566-atomic_t fscache_n_store_vmscan_busy;
46567-atomic_t fscache_n_store_vmscan_cancelled;
46568+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46569+atomic_unchecked_t fscache_n_store_vmscan_gone;
46570+atomic_unchecked_t fscache_n_store_vmscan_busy;
46571+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46572
46573-atomic_t fscache_n_marks;
46574-atomic_t fscache_n_uncaches;
46575+atomic_unchecked_t fscache_n_marks;
46576+atomic_unchecked_t fscache_n_uncaches;
46577
46578-atomic_t fscache_n_acquires;
46579-atomic_t fscache_n_acquires_null;
46580-atomic_t fscache_n_acquires_no_cache;
46581-atomic_t fscache_n_acquires_ok;
46582-atomic_t fscache_n_acquires_nobufs;
46583-atomic_t fscache_n_acquires_oom;
46584+atomic_unchecked_t fscache_n_acquires;
46585+atomic_unchecked_t fscache_n_acquires_null;
46586+atomic_unchecked_t fscache_n_acquires_no_cache;
46587+atomic_unchecked_t fscache_n_acquires_ok;
46588+atomic_unchecked_t fscache_n_acquires_nobufs;
46589+atomic_unchecked_t fscache_n_acquires_oom;
46590
46591-atomic_t fscache_n_updates;
46592-atomic_t fscache_n_updates_null;
46593-atomic_t fscache_n_updates_run;
46594+atomic_unchecked_t fscache_n_updates;
46595+atomic_unchecked_t fscache_n_updates_null;
46596+atomic_unchecked_t fscache_n_updates_run;
46597
46598-atomic_t fscache_n_relinquishes;
46599-atomic_t fscache_n_relinquishes_null;
46600-atomic_t fscache_n_relinquishes_waitcrt;
46601-atomic_t fscache_n_relinquishes_retire;
46602+atomic_unchecked_t fscache_n_relinquishes;
46603+atomic_unchecked_t fscache_n_relinquishes_null;
46604+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46605+atomic_unchecked_t fscache_n_relinquishes_retire;
46606
46607-atomic_t fscache_n_cookie_index;
46608-atomic_t fscache_n_cookie_data;
46609-atomic_t fscache_n_cookie_special;
46610+atomic_unchecked_t fscache_n_cookie_index;
46611+atomic_unchecked_t fscache_n_cookie_data;
46612+atomic_unchecked_t fscache_n_cookie_special;
46613
46614-atomic_t fscache_n_object_alloc;
46615-atomic_t fscache_n_object_no_alloc;
46616-atomic_t fscache_n_object_lookups;
46617-atomic_t fscache_n_object_lookups_negative;
46618-atomic_t fscache_n_object_lookups_positive;
46619-atomic_t fscache_n_object_lookups_timed_out;
46620-atomic_t fscache_n_object_created;
46621-atomic_t fscache_n_object_avail;
46622-atomic_t fscache_n_object_dead;
46623+atomic_unchecked_t fscache_n_object_alloc;
46624+atomic_unchecked_t fscache_n_object_no_alloc;
46625+atomic_unchecked_t fscache_n_object_lookups;
46626+atomic_unchecked_t fscache_n_object_lookups_negative;
46627+atomic_unchecked_t fscache_n_object_lookups_positive;
46628+atomic_unchecked_t fscache_n_object_lookups_timed_out;
46629+atomic_unchecked_t fscache_n_object_created;
46630+atomic_unchecked_t fscache_n_object_avail;
46631+atomic_unchecked_t fscache_n_object_dead;
46632
46633-atomic_t fscache_n_checkaux_none;
46634-atomic_t fscache_n_checkaux_okay;
46635-atomic_t fscache_n_checkaux_update;
46636-atomic_t fscache_n_checkaux_obsolete;
46637+atomic_unchecked_t fscache_n_checkaux_none;
46638+atomic_unchecked_t fscache_n_checkaux_okay;
46639+atomic_unchecked_t fscache_n_checkaux_update;
46640+atomic_unchecked_t fscache_n_checkaux_obsolete;
46641
46642 atomic_t fscache_n_cop_alloc_object;
46643 atomic_t fscache_n_cop_lookup_object;
46644@@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
46645 seq_puts(m, "FS-Cache statistics\n");
46646
46647 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
46648- atomic_read(&fscache_n_cookie_index),
46649- atomic_read(&fscache_n_cookie_data),
46650- atomic_read(&fscache_n_cookie_special));
46651+ atomic_read_unchecked(&fscache_n_cookie_index),
46652+ atomic_read_unchecked(&fscache_n_cookie_data),
46653+ atomic_read_unchecked(&fscache_n_cookie_special));
46654
46655 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
46656- atomic_read(&fscache_n_object_alloc),
46657- atomic_read(&fscache_n_object_no_alloc),
46658- atomic_read(&fscache_n_object_avail),
46659- atomic_read(&fscache_n_object_dead));
46660+ atomic_read_unchecked(&fscache_n_object_alloc),
46661+ atomic_read_unchecked(&fscache_n_object_no_alloc),
46662+ atomic_read_unchecked(&fscache_n_object_avail),
46663+ atomic_read_unchecked(&fscache_n_object_dead));
46664 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
46665- atomic_read(&fscache_n_checkaux_none),
46666- atomic_read(&fscache_n_checkaux_okay),
46667- atomic_read(&fscache_n_checkaux_update),
46668- atomic_read(&fscache_n_checkaux_obsolete));
46669+ atomic_read_unchecked(&fscache_n_checkaux_none),
46670+ atomic_read_unchecked(&fscache_n_checkaux_okay),
46671+ atomic_read_unchecked(&fscache_n_checkaux_update),
46672+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
46673
46674 seq_printf(m, "Pages : mrk=%u unc=%u\n",
46675- atomic_read(&fscache_n_marks),
46676- atomic_read(&fscache_n_uncaches));
46677+ atomic_read_unchecked(&fscache_n_marks),
46678+ atomic_read_unchecked(&fscache_n_uncaches));
46679
46680 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
46681 " oom=%u\n",
46682- atomic_read(&fscache_n_acquires),
46683- atomic_read(&fscache_n_acquires_null),
46684- atomic_read(&fscache_n_acquires_no_cache),
46685- atomic_read(&fscache_n_acquires_ok),
46686- atomic_read(&fscache_n_acquires_nobufs),
46687- atomic_read(&fscache_n_acquires_oom));
46688+ atomic_read_unchecked(&fscache_n_acquires),
46689+ atomic_read_unchecked(&fscache_n_acquires_null),
46690+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
46691+ atomic_read_unchecked(&fscache_n_acquires_ok),
46692+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
46693+ atomic_read_unchecked(&fscache_n_acquires_oom));
46694
46695 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
46696- atomic_read(&fscache_n_object_lookups),
46697- atomic_read(&fscache_n_object_lookups_negative),
46698- atomic_read(&fscache_n_object_lookups_positive),
46699- atomic_read(&fscache_n_object_created),
46700- atomic_read(&fscache_n_object_lookups_timed_out));
46701+ atomic_read_unchecked(&fscache_n_object_lookups),
46702+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
46703+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
46704+ atomic_read_unchecked(&fscache_n_object_created),
46705+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
46706
46707 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
46708- atomic_read(&fscache_n_updates),
46709- atomic_read(&fscache_n_updates_null),
46710- atomic_read(&fscache_n_updates_run));
46711+ atomic_read_unchecked(&fscache_n_updates),
46712+ atomic_read_unchecked(&fscache_n_updates_null),
46713+ atomic_read_unchecked(&fscache_n_updates_run));
46714
46715 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
46716- atomic_read(&fscache_n_relinquishes),
46717- atomic_read(&fscache_n_relinquishes_null),
46718- atomic_read(&fscache_n_relinquishes_waitcrt),
46719- atomic_read(&fscache_n_relinquishes_retire));
46720+ atomic_read_unchecked(&fscache_n_relinquishes),
46721+ atomic_read_unchecked(&fscache_n_relinquishes_null),
46722+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
46723+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
46724
46725 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
46726- atomic_read(&fscache_n_attr_changed),
46727- atomic_read(&fscache_n_attr_changed_ok),
46728- atomic_read(&fscache_n_attr_changed_nobufs),
46729- atomic_read(&fscache_n_attr_changed_nomem),
46730- atomic_read(&fscache_n_attr_changed_calls));
46731+ atomic_read_unchecked(&fscache_n_attr_changed),
46732+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
46733+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
46734+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
46735+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
46736
46737 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
46738- atomic_read(&fscache_n_allocs),
46739- atomic_read(&fscache_n_allocs_ok),
46740- atomic_read(&fscache_n_allocs_wait),
46741- atomic_read(&fscache_n_allocs_nobufs),
46742- atomic_read(&fscache_n_allocs_intr));
46743+ atomic_read_unchecked(&fscache_n_allocs),
46744+ atomic_read_unchecked(&fscache_n_allocs_ok),
46745+ atomic_read_unchecked(&fscache_n_allocs_wait),
46746+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
46747+ atomic_read_unchecked(&fscache_n_allocs_intr));
46748 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
46749- atomic_read(&fscache_n_alloc_ops),
46750- atomic_read(&fscache_n_alloc_op_waits),
46751- atomic_read(&fscache_n_allocs_object_dead));
46752+ atomic_read_unchecked(&fscache_n_alloc_ops),
46753+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
46754+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
46755
46756 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
46757 " int=%u oom=%u\n",
46758- atomic_read(&fscache_n_retrievals),
46759- atomic_read(&fscache_n_retrievals_ok),
46760- atomic_read(&fscache_n_retrievals_wait),
46761- atomic_read(&fscache_n_retrievals_nodata),
46762- atomic_read(&fscache_n_retrievals_nobufs),
46763- atomic_read(&fscache_n_retrievals_intr),
46764- atomic_read(&fscache_n_retrievals_nomem));
46765+ atomic_read_unchecked(&fscache_n_retrievals),
46766+ atomic_read_unchecked(&fscache_n_retrievals_ok),
46767+ atomic_read_unchecked(&fscache_n_retrievals_wait),
46768+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
46769+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
46770+ atomic_read_unchecked(&fscache_n_retrievals_intr),
46771+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
46772 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
46773- atomic_read(&fscache_n_retrieval_ops),
46774- atomic_read(&fscache_n_retrieval_op_waits),
46775- atomic_read(&fscache_n_retrievals_object_dead));
46776+ atomic_read_unchecked(&fscache_n_retrieval_ops),
46777+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
46778+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
46779
46780 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
46781- atomic_read(&fscache_n_stores),
46782- atomic_read(&fscache_n_stores_ok),
46783- atomic_read(&fscache_n_stores_again),
46784- atomic_read(&fscache_n_stores_nobufs),
46785- atomic_read(&fscache_n_stores_oom));
46786+ atomic_read_unchecked(&fscache_n_stores),
46787+ atomic_read_unchecked(&fscache_n_stores_ok),
46788+ atomic_read_unchecked(&fscache_n_stores_again),
46789+ atomic_read_unchecked(&fscache_n_stores_nobufs),
46790+ atomic_read_unchecked(&fscache_n_stores_oom));
46791 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
46792- atomic_read(&fscache_n_store_ops),
46793- atomic_read(&fscache_n_store_calls),
46794- atomic_read(&fscache_n_store_pages),
46795- atomic_read(&fscache_n_store_radix_deletes),
46796- atomic_read(&fscache_n_store_pages_over_limit));
46797+ atomic_read_unchecked(&fscache_n_store_ops),
46798+ atomic_read_unchecked(&fscache_n_store_calls),
46799+ atomic_read_unchecked(&fscache_n_store_pages),
46800+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
46801+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
46802
46803 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
46804- atomic_read(&fscache_n_store_vmscan_not_storing),
46805- atomic_read(&fscache_n_store_vmscan_gone),
46806- atomic_read(&fscache_n_store_vmscan_busy),
46807- atomic_read(&fscache_n_store_vmscan_cancelled));
46808+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
46809+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
46810+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
46811+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
46812
46813 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
46814- atomic_read(&fscache_n_op_pend),
46815- atomic_read(&fscache_n_op_run),
46816- atomic_read(&fscache_n_op_enqueue),
46817- atomic_read(&fscache_n_op_cancelled),
46818- atomic_read(&fscache_n_op_rejected));
46819+ atomic_read_unchecked(&fscache_n_op_pend),
46820+ atomic_read_unchecked(&fscache_n_op_run),
46821+ atomic_read_unchecked(&fscache_n_op_enqueue),
46822+ atomic_read_unchecked(&fscache_n_op_cancelled),
46823+ atomic_read_unchecked(&fscache_n_op_rejected));
46824 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
46825- atomic_read(&fscache_n_op_deferred_release),
46826- atomic_read(&fscache_n_op_release),
46827- atomic_read(&fscache_n_op_gc));
46828+ atomic_read_unchecked(&fscache_n_op_deferred_release),
46829+ atomic_read_unchecked(&fscache_n_op_release),
46830+ atomic_read_unchecked(&fscache_n_op_gc));
46831
46832 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
46833 atomic_read(&fscache_n_cop_alloc_object),
46834diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
46835index 3426521..3b75162 100644
46836--- a/fs/fuse/cuse.c
46837+++ b/fs/fuse/cuse.c
46838@@ -587,10 +587,12 @@ static int __init cuse_init(void)
46839 INIT_LIST_HEAD(&cuse_conntbl[i]);
46840
46841 /* inherit and extend fuse_dev_operations */
46842- cuse_channel_fops = fuse_dev_operations;
46843- cuse_channel_fops.owner = THIS_MODULE;
46844- cuse_channel_fops.open = cuse_channel_open;
46845- cuse_channel_fops.release = cuse_channel_release;
46846+ pax_open_kernel();
46847+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
46848+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
46849+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
46850+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
46851+ pax_close_kernel();
46852
46853 cuse_class = class_create(THIS_MODULE, "cuse");
46854 if (IS_ERR(cuse_class))
46855diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
46856index 7df2b5e..5804aa7 100644
46857--- a/fs/fuse/dev.c
46858+++ b/fs/fuse/dev.c
46859@@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
46860 ret = 0;
46861 pipe_lock(pipe);
46862
46863- if (!pipe->readers) {
46864+ if (!atomic_read(&pipe->readers)) {
46865 send_sig(SIGPIPE, current, 0);
46866 if (!ret)
46867 ret = -EPIPE;
46868diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
46869index 334e0b1..fc571e8 100644
46870--- a/fs/fuse/dir.c
46871+++ b/fs/fuse/dir.c
46872@@ -1189,7 +1189,7 @@ static char *read_link(struct dentry *dentry)
46873 return link;
46874 }
46875
46876-static void free_link(char *link)
46877+static void free_link(const char *link)
46878 {
46879 if (!IS_ERR(link))
46880 free_page((unsigned long) link);
46881diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
46882index a9ba244..d9df391 100644
46883--- a/fs/gfs2/inode.c
46884+++ b/fs/gfs2/inode.c
46885@@ -1496,7 +1496,7 @@ out:
46886
46887 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46888 {
46889- char *s = nd_get_link(nd);
46890+ const char *s = nd_get_link(nd);
46891 if (!IS_ERR(s))
46892 kfree(s);
46893 }
46894diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
46895index cc9281b..58996fb 100644
46896--- a/fs/hugetlbfs/inode.c
46897+++ b/fs/hugetlbfs/inode.c
46898@@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
46899 .kill_sb = kill_litter_super,
46900 };
46901
46902-static struct vfsmount *hugetlbfs_vfsmount;
46903+struct vfsmount *hugetlbfs_vfsmount;
46904
46905 static int can_do_hugetlb_shm(void)
46906 {
46907diff --git a/fs/inode.c b/fs/inode.c
46908index c99163b..a11ad40 100644
46909--- a/fs/inode.c
46910+++ b/fs/inode.c
46911@@ -867,8 +867,8 @@ unsigned int get_next_ino(void)
46912
46913 #ifdef CONFIG_SMP
46914 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
46915- static atomic_t shared_last_ino;
46916- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
46917+ static atomic_unchecked_t shared_last_ino;
46918+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
46919
46920 res = next - LAST_INO_BATCH;
46921 }
46922diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
46923index 4a6cf28..d3a29d3 100644
46924--- a/fs/jffs2/erase.c
46925+++ b/fs/jffs2/erase.c
46926@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
46927 struct jffs2_unknown_node marker = {
46928 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
46929 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46930- .totlen = cpu_to_je32(c->cleanmarker_size)
46931+ .totlen = cpu_to_je32(c->cleanmarker_size),
46932+ .hdr_crc = cpu_to_je32(0)
46933 };
46934
46935 jffs2_prealloc_raw_node_refs(c, jeb, 1);
46936diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
46937index 6f4529d..bf12806 100644
46938--- a/fs/jffs2/wbuf.c
46939+++ b/fs/jffs2/wbuf.c
46940@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
46941 {
46942 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
46943 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46944- .totlen = constant_cpu_to_je32(8)
46945+ .totlen = constant_cpu_to_je32(8),
46946+ .hdr_crc = constant_cpu_to_je32(0)
46947 };
46948
46949 /*
46950diff --git a/fs/jfs/super.c b/fs/jfs/super.c
46951index 4a82950..bcaa0cb 100644
46952--- a/fs/jfs/super.c
46953+++ b/fs/jfs/super.c
46954@@ -801,7 +801,7 @@ static int __init init_jfs_fs(void)
46955
46956 jfs_inode_cachep =
46957 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
46958- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
46959+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
46960 init_once);
46961 if (jfs_inode_cachep == NULL)
46962 return -ENOMEM;
46963diff --git a/fs/libfs.c b/fs/libfs.c
46964index f86ec27..4734776 100644
46965--- a/fs/libfs.c
46966+++ b/fs/libfs.c
46967@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46968
46969 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
46970 struct dentry *next;
46971+ char d_name[sizeof(next->d_iname)];
46972+ const unsigned char *name;
46973+
46974 next = list_entry(p, struct dentry, d_u.d_child);
46975 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
46976 if (!simple_positive(next)) {
46977@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46978
46979 spin_unlock(&next->d_lock);
46980 spin_unlock(&dentry->d_lock);
46981- if (filldir(dirent, next->d_name.name,
46982+ name = next->d_name.name;
46983+ if (name == next->d_iname) {
46984+ memcpy(d_name, name, next->d_name.len);
46985+ name = d_name;
46986+ }
46987+ if (filldir(dirent, name,
46988 next->d_name.len, filp->f_pos,
46989 next->d_inode->i_ino,
46990 dt_type(next->d_inode)) < 0)
46991diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
46992index 8392cb8..80d6193 100644
46993--- a/fs/lockd/clntproc.c
46994+++ b/fs/lockd/clntproc.c
46995@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
46996 /*
46997 * Cookie counter for NLM requests
46998 */
46999-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
47000+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
47001
47002 void nlmclnt_next_cookie(struct nlm_cookie *c)
47003 {
47004- u32 cookie = atomic_inc_return(&nlm_cookie);
47005+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
47006
47007 memcpy(c->data, &cookie, 4);
47008 c->len=4;
47009diff --git a/fs/locks.c b/fs/locks.c
47010index 82c3533..34e929c 100644
47011--- a/fs/locks.c
47012+++ b/fs/locks.c
47013@@ -2076,16 +2076,16 @@ void locks_remove_flock(struct file *filp)
47014 return;
47015
47016 if (filp->f_op && filp->f_op->flock) {
47017- struct file_lock fl = {
47018+ struct file_lock flock = {
47019 .fl_pid = current->tgid,
47020 .fl_file = filp,
47021 .fl_flags = FL_FLOCK,
47022 .fl_type = F_UNLCK,
47023 .fl_end = OFFSET_MAX,
47024 };
47025- filp->f_op->flock(filp, F_SETLKW, &fl);
47026- if (fl.fl_ops && fl.fl_ops->fl_release_private)
47027- fl.fl_ops->fl_release_private(&fl);
47028+ filp->f_op->flock(filp, F_SETLKW, &flock);
47029+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
47030+ flock.fl_ops->fl_release_private(&flock);
47031 }
47032
47033 lock_flocks();
47034diff --git a/fs/namei.c b/fs/namei.c
47035index 7d69419..10c6af6 100644
47036--- a/fs/namei.c
47037+++ b/fs/namei.c
47038@@ -265,16 +265,32 @@ int generic_permission(struct inode *inode, int mask)
47039 if (ret != -EACCES)
47040 return ret;
47041
47042+#ifdef CONFIG_GRKERNSEC
47043+ /* we'll block if we have to log due to a denied capability use */
47044+ if (mask & MAY_NOT_BLOCK)
47045+ return -ECHILD;
47046+#endif
47047+
47048 if (S_ISDIR(inode->i_mode)) {
47049 /* DACs are overridable for directories */
47050- if (inode_capable(inode, CAP_DAC_OVERRIDE))
47051- return 0;
47052 if (!(mask & MAY_WRITE))
47053- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47054+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47055+ inode_capable(inode, CAP_DAC_READ_SEARCH))
47056 return 0;
47057+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
47058+ return 0;
47059 return -EACCES;
47060 }
47061 /*
47062+ * Searching includes executable on directories, else just read.
47063+ */
47064+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47065+ if (mask == MAY_READ)
47066+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47067+ inode_capable(inode, CAP_DAC_READ_SEARCH))
47068+ return 0;
47069+
47070+ /*
47071 * Read/write DACs are always overridable.
47072 * Executable DACs are overridable when there is
47073 * at least one exec bit set.
47074@@ -283,14 +299,6 @@ int generic_permission(struct inode *inode, int mask)
47075 if (inode_capable(inode, CAP_DAC_OVERRIDE))
47076 return 0;
47077
47078- /*
47079- * Searching includes executable on directories, else just read.
47080- */
47081- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47082- if (mask == MAY_READ)
47083- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47084- return 0;
47085-
47086 return -EACCES;
47087 }
47088
47089@@ -639,11 +647,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47090 return error;
47091 }
47092
47093+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
47094+ dentry->d_inode, dentry, nd->path.mnt)) {
47095+ error = -EACCES;
47096+ *p = ERR_PTR(error); /* no ->put_link(), please */
47097+ path_put(&nd->path);
47098+ return error;
47099+ }
47100+
47101 nd->last_type = LAST_BIND;
47102 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
47103 error = PTR_ERR(*p);
47104 if (!IS_ERR(*p)) {
47105- char *s = nd_get_link(nd);
47106+ const char *s = nd_get_link(nd);
47107 error = 0;
47108 if (s)
47109 error = __vfs_follow_link(nd, s);
47110@@ -1386,6 +1402,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
47111 if (!res)
47112 res = walk_component(nd, path, &nd->last,
47113 nd->last_type, LOOKUP_FOLLOW);
47114+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
47115+ res = -EACCES;
47116 put_link(nd, &link, cookie);
47117 } while (res > 0);
47118
47119@@ -1779,6 +1797,8 @@ static int path_lookupat(int dfd, const char *name,
47120 err = follow_link(&link, nd, &cookie);
47121 if (!err)
47122 err = lookup_last(nd, &path);
47123+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
47124+ err = -EACCES;
47125 put_link(nd, &link, cookie);
47126 }
47127 }
47128@@ -1786,6 +1806,21 @@ static int path_lookupat(int dfd, const char *name,
47129 if (!err)
47130 err = complete_walk(nd);
47131
47132+ if (!(nd->flags & LOOKUP_PARENT)) {
47133+#ifdef CONFIG_GRKERNSEC
47134+ if (flags & LOOKUP_RCU) {
47135+ if (!err)
47136+ path_put(&nd->path);
47137+ err = -ECHILD;
47138+ } else
47139+#endif
47140+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47141+ if (!err)
47142+ path_put(&nd->path);
47143+ err = -ENOENT;
47144+ }
47145+ }
47146+
47147 if (!err && nd->flags & LOOKUP_DIRECTORY) {
47148 if (!nd->inode->i_op->lookup) {
47149 path_put(&nd->path);
47150@@ -1813,6 +1848,15 @@ static int do_path_lookup(int dfd, const char *name,
47151 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
47152
47153 if (likely(!retval)) {
47154+ if (*name != '/' && nd->path.dentry && nd->inode) {
47155+#ifdef CONFIG_GRKERNSEC
47156+ if (flags & LOOKUP_RCU)
47157+ return -ECHILD;
47158+#endif
47159+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
47160+ return -ENOENT;
47161+ }
47162+
47163 if (unlikely(!audit_dummy_context())) {
47164 if (nd->path.dentry && nd->inode)
47165 audit_inode(name, nd->path.dentry);
47166@@ -2155,6 +2199,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
47167 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
47168 return -EPERM;
47169
47170+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
47171+ return -EPERM;
47172+ if (gr_handle_rawio(inode))
47173+ return -EPERM;
47174+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
47175+ return -EACCES;
47176+
47177 return 0;
47178 }
47179
47180@@ -2190,7 +2241,7 @@ static inline int open_to_namei_flags(int flag)
47181 /*
47182 * Handle the last step of open()
47183 */
47184-static struct file *do_last(struct nameidata *nd, struct path *path,
47185+static struct file *do_last(struct nameidata *nd, struct path *path, struct path *link,
47186 const struct open_flags *op, const char *pathname)
47187 {
47188 struct dentry *dir = nd->path.dentry;
47189@@ -2220,16 +2271,44 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47190 error = complete_walk(nd);
47191 if (error)
47192 return ERR_PTR(error);
47193+#ifdef CONFIG_GRKERNSEC
47194+ if (nd->flags & LOOKUP_RCU) {
47195+ error = -ECHILD;
47196+ goto exit;
47197+ }
47198+#endif
47199+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47200+ error = -ENOENT;
47201+ goto exit;
47202+ }
47203 audit_inode(pathname, nd->path.dentry);
47204 if (open_flag & O_CREAT) {
47205 error = -EISDIR;
47206 goto exit;
47207 }
47208+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
47209+ error = -EACCES;
47210+ goto exit;
47211+ }
47212 goto ok;
47213 case LAST_BIND:
47214 error = complete_walk(nd);
47215 if (error)
47216 return ERR_PTR(error);
47217+#ifdef CONFIG_GRKERNSEC
47218+ if (nd->flags & LOOKUP_RCU) {
47219+ error = -ECHILD;
47220+ goto exit;
47221+ }
47222+#endif
47223+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
47224+ error = -ENOENT;
47225+ goto exit;
47226+ }
47227+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
47228+ error = -EACCES;
47229+ goto exit;
47230+ }
47231 audit_inode(pathname, dir);
47232 goto ok;
47233 }
47234@@ -2285,6 +2364,12 @@ retry_lookup:
47235 /* Negative dentry, just create the file */
47236 if (!dentry->d_inode) {
47237 umode_t mode = op->mode;
47238+
47239+ if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
47240+ error = -EACCES;
47241+ goto exit_mutex_unlock;
47242+ }
47243+
47244 if (!IS_POSIXACL(dir->d_inode))
47245 mode &= ~current_umask();
47246 /*
47247@@ -2308,6 +2393,8 @@ retry_lookup:
47248 error = vfs_create(dir->d_inode, dentry, mode, nd);
47249 if (error)
47250 goto exit_mutex_unlock;
47251+ else
47252+ gr_handle_create(path->dentry, path->mnt);
47253 mutex_unlock(&dir->d_inode->i_mutex);
47254 dput(nd->path.dentry);
47255 nd->path.dentry = dentry;
47256@@ -2317,6 +2404,23 @@ retry_lookup:
47257 /*
47258 * It already exists.
47259 */
47260+
47261+ if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
47262+ error = -ENOENT;
47263+ goto exit_mutex_unlock;
47264+ }
47265+ if (link && gr_handle_symlink_owner(link, dentry->d_inode)) {
47266+ error = -EACCES;
47267+ goto exit_mutex_unlock;
47268+ }
47269+
47270+ /* only check if O_CREAT is specified, all other checks need to go
47271+ into may_open */
47272+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
47273+ error = -EACCES;
47274+ goto exit_mutex_unlock;
47275+ }
47276+
47277 mutex_unlock(&dir->d_inode->i_mutex);
47278 audit_inode(pathname, path->dentry);
47279
47280@@ -2349,6 +2453,11 @@ finish_lookup:
47281 }
47282 }
47283 BUG_ON(inode != path->dentry->d_inode);
47284+ /* if we're resolving a symlink to another symlink */
47285+ if (link && gr_handle_symlink_owner(link, inode)) {
47286+ error = -EACCES;
47287+ goto exit;
47288+ }
47289 return NULL;
47290 }
47291
47292@@ -2358,7 +2467,6 @@ finish_lookup:
47293 save_parent.dentry = nd->path.dentry;
47294 save_parent.mnt = mntget(path->mnt);
47295 nd->path.dentry = path->dentry;
47296-
47297 }
47298 nd->inode = inode;
47299 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
47300@@ -2367,6 +2475,21 @@ finish_lookup:
47301 path_put(&save_parent);
47302 return ERR_PTR(error);
47303 }
47304+#ifdef CONFIG_GRKERNSEC
47305+ if (nd->flags & LOOKUP_RCU) {
47306+ error = -ECHILD;
47307+ goto exit;
47308+ }
47309+#endif
47310+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47311+ error = -ENOENT;
47312+ goto exit;
47313+ }
47314+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
47315+ error = -EACCES;
47316+ goto exit;
47317+ }
47318+
47319 error = -EISDIR;
47320 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
47321 goto exit;
47322@@ -2461,7 +2584,7 @@ static struct file *path_openat(int dfd, const char *pathname,
47323 if (unlikely(error))
47324 goto out_filp;
47325
47326- filp = do_last(nd, &path, op, pathname);
47327+ filp = do_last(nd, &path, NULL, op, pathname);
47328 while (unlikely(!filp)) { /* trailing symlink */
47329 struct path link = path;
47330 void *cookie;
47331@@ -2476,8 +2599,9 @@ static struct file *path_openat(int dfd, const char *pathname,
47332 error = follow_link(&link, nd, &cookie);
47333 if (unlikely(error))
47334 filp = ERR_PTR(error);
47335- else
47336- filp = do_last(nd, &path, op, pathname);
47337+ else {
47338+ filp = do_last(nd, &path, &link, op, pathname);
47339+ }
47340 put_link(nd, &link, cookie);
47341 }
47342 out:
47343@@ -2577,6 +2701,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
47344 *path = nd.path;
47345 return dentry;
47346 eexist:
47347+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
47348+ dput(dentry);
47349+ dentry = ERR_PTR(-ENOENT);
47350+ goto fail;
47351+ }
47352 dput(dentry);
47353 dentry = ERR_PTR(-EEXIST);
47354 fail:
47355@@ -2599,6 +2728,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
47356 }
47357 EXPORT_SYMBOL(user_path_create);
47358
47359+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
47360+{
47361+ char *tmp = getname(pathname);
47362+ struct dentry *res;
47363+ if (IS_ERR(tmp))
47364+ return ERR_CAST(tmp);
47365+ res = kern_path_create(dfd, tmp, path, is_dir);
47366+ if (IS_ERR(res))
47367+ putname(tmp);
47368+ else
47369+ *to = tmp;
47370+ return res;
47371+}
47372+
47373 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
47374 {
47375 int error = may_create(dir, dentry);
47376@@ -2665,6 +2808,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47377 error = mnt_want_write(path.mnt);
47378 if (error)
47379 goto out_dput;
47380+
47381+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
47382+ error = -EPERM;
47383+ goto out_drop_write;
47384+ }
47385+
47386+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
47387+ error = -EACCES;
47388+ goto out_drop_write;
47389+ }
47390+
47391 error = security_path_mknod(&path, dentry, mode, dev);
47392 if (error)
47393 goto out_drop_write;
47394@@ -2682,6 +2836,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47395 }
47396 out_drop_write:
47397 mnt_drop_write(path.mnt);
47398+
47399+ if (!error)
47400+ gr_handle_create(dentry, path.mnt);
47401 out_dput:
47402 dput(dentry);
47403 mutex_unlock(&path.dentry->d_inode->i_mutex);
47404@@ -2735,12 +2892,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
47405 error = mnt_want_write(path.mnt);
47406 if (error)
47407 goto out_dput;
47408+
47409+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
47410+ error = -EACCES;
47411+ goto out_drop_write;
47412+ }
47413+
47414 error = security_path_mkdir(&path, dentry, mode);
47415 if (error)
47416 goto out_drop_write;
47417 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
47418 out_drop_write:
47419 mnt_drop_write(path.mnt);
47420+
47421+ if (!error)
47422+ gr_handle_create(dentry, path.mnt);
47423 out_dput:
47424 dput(dentry);
47425 mutex_unlock(&path.dentry->d_inode->i_mutex);
47426@@ -2820,6 +2986,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47427 char * name;
47428 struct dentry *dentry;
47429 struct nameidata nd;
47430+ ino_t saved_ino = 0;
47431+ dev_t saved_dev = 0;
47432
47433 error = user_path_parent(dfd, pathname, &nd, &name);
47434 if (error)
47435@@ -2848,6 +3016,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
47436 error = -ENOENT;
47437 goto exit3;
47438 }
47439+
47440+ saved_ino = dentry->d_inode->i_ino;
47441+ saved_dev = gr_get_dev_from_dentry(dentry);
47442+
47443+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
47444+ error = -EACCES;
47445+ goto exit3;
47446+ }
47447+
47448 error = mnt_want_write(nd.path.mnt);
47449 if (error)
47450 goto exit3;
47451@@ -2855,6 +3032,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47452 if (error)
47453 goto exit4;
47454 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
47455+ if (!error && (saved_dev || saved_ino))
47456+ gr_handle_delete(saved_ino, saved_dev);
47457 exit4:
47458 mnt_drop_write(nd.path.mnt);
47459 exit3:
47460@@ -2917,6 +3096,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47461 struct dentry *dentry;
47462 struct nameidata nd;
47463 struct inode *inode = NULL;
47464+ ino_t saved_ino = 0;
47465+ dev_t saved_dev = 0;
47466
47467 error = user_path_parent(dfd, pathname, &nd, &name);
47468 if (error)
47469@@ -2939,6 +3120,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47470 if (!inode)
47471 goto slashes;
47472 ihold(inode);
47473+
47474+ if (inode->i_nlink <= 1) {
47475+ saved_ino = inode->i_ino;
47476+ saved_dev = gr_get_dev_from_dentry(dentry);
47477+ }
47478+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
47479+ error = -EACCES;
47480+ goto exit2;
47481+ }
47482+
47483 error = mnt_want_write(nd.path.mnt);
47484 if (error)
47485 goto exit2;
47486@@ -2946,6 +3137,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47487 if (error)
47488 goto exit3;
47489 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
47490+ if (!error && (saved_ino || saved_dev))
47491+ gr_handle_delete(saved_ino, saved_dev);
47492 exit3:
47493 mnt_drop_write(nd.path.mnt);
47494 exit2:
47495@@ -3021,10 +3214,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
47496 error = mnt_want_write(path.mnt);
47497 if (error)
47498 goto out_dput;
47499+
47500+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
47501+ error = -EACCES;
47502+ goto out_drop_write;
47503+ }
47504+
47505 error = security_path_symlink(&path, dentry, from);
47506 if (error)
47507 goto out_drop_write;
47508 error = vfs_symlink(path.dentry->d_inode, dentry, from);
47509+ if (!error)
47510+ gr_handle_create(dentry, path.mnt);
47511 out_drop_write:
47512 mnt_drop_write(path.mnt);
47513 out_dput:
47514@@ -3099,6 +3300,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47515 {
47516 struct dentry *new_dentry;
47517 struct path old_path, new_path;
47518+ char *to = NULL;
47519 int how = 0;
47520 int error;
47521
47522@@ -3122,7 +3324,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47523 if (error)
47524 return error;
47525
47526- new_dentry = user_path_create(newdfd, newname, &new_path, 0);
47527+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
47528 error = PTR_ERR(new_dentry);
47529 if (IS_ERR(new_dentry))
47530 goto out;
47531@@ -3133,13 +3335,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47532 error = mnt_want_write(new_path.mnt);
47533 if (error)
47534 goto out_dput;
47535+
47536+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
47537+ old_path.dentry->d_inode,
47538+ old_path.dentry->d_inode->i_mode, to)) {
47539+ error = -EACCES;
47540+ goto out_drop_write;
47541+ }
47542+
47543+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
47544+ old_path.dentry, old_path.mnt, to)) {
47545+ error = -EACCES;
47546+ goto out_drop_write;
47547+ }
47548+
47549 error = security_path_link(old_path.dentry, &new_path, new_dentry);
47550 if (error)
47551 goto out_drop_write;
47552 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
47553+ if (!error)
47554+ gr_handle_create(new_dentry, new_path.mnt);
47555 out_drop_write:
47556 mnt_drop_write(new_path.mnt);
47557 out_dput:
47558+ putname(to);
47559 dput(new_dentry);
47560 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
47561 path_put(&new_path);
47562@@ -3373,6 +3592,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47563 if (new_dentry == trap)
47564 goto exit5;
47565
47566+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
47567+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
47568+ to);
47569+ if (error)
47570+ goto exit5;
47571+
47572 error = mnt_want_write(oldnd.path.mnt);
47573 if (error)
47574 goto exit5;
47575@@ -3382,6 +3607,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47576 goto exit6;
47577 error = vfs_rename(old_dir->d_inode, old_dentry,
47578 new_dir->d_inode, new_dentry);
47579+ if (!error)
47580+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
47581+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
47582 exit6:
47583 mnt_drop_write(oldnd.path.mnt);
47584 exit5:
47585@@ -3407,6 +3635,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
47586
47587 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
47588 {
47589+ char tmpbuf[64];
47590+ const char *newlink;
47591 int len;
47592
47593 len = PTR_ERR(link);
47594@@ -3416,7 +3646,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
47595 len = strlen(link);
47596 if (len > (unsigned) buflen)
47597 len = buflen;
47598- if (copy_to_user(buffer, link, len))
47599+
47600+ if (len < sizeof(tmpbuf)) {
47601+ memcpy(tmpbuf, link, len);
47602+ newlink = tmpbuf;
47603+ } else
47604+ newlink = link;
47605+
47606+ if (copy_to_user(buffer, newlink, len))
47607 len = -EFAULT;
47608 out:
47609 return len;
47610diff --git a/fs/namespace.c b/fs/namespace.c
47611index 1e4a5fe..a5ce747 100644
47612--- a/fs/namespace.c
47613+++ b/fs/namespace.c
47614@@ -1157,6 +1157,9 @@ static int do_umount(struct mount *mnt, int flags)
47615 if (!(sb->s_flags & MS_RDONLY))
47616 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
47617 up_write(&sb->s_umount);
47618+
47619+ gr_log_remount(mnt->mnt_devname, retval);
47620+
47621 return retval;
47622 }
47623
47624@@ -1176,6 +1179,9 @@ static int do_umount(struct mount *mnt, int flags)
47625 br_write_unlock(&vfsmount_lock);
47626 up_write(&namespace_sem);
47627 release_mounts(&umount_list);
47628+
47629+ gr_log_unmount(mnt->mnt_devname, retval);
47630+
47631 return retval;
47632 }
47633
47634@@ -2177,6 +2183,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47635 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
47636 MS_STRICTATIME);
47637
47638+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
47639+ retval = -EPERM;
47640+ goto dput_out;
47641+ }
47642+
47643+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
47644+ retval = -EPERM;
47645+ goto dput_out;
47646+ }
47647+
47648 if (flags & MS_REMOUNT)
47649 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
47650 data_page);
47651@@ -2191,6 +2207,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47652 dev_name, data_page);
47653 dput_out:
47654 path_put(&path);
47655+
47656+ gr_log_mount(dev_name, dir_name, retval);
47657+
47658 return retval;
47659 }
47660
47661@@ -2472,6 +2491,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
47662 if (error)
47663 goto out2;
47664
47665+ if (gr_handle_chroot_pivot()) {
47666+ error = -EPERM;
47667+ goto out2;
47668+ }
47669+
47670 get_fs_root(current->fs, &root);
47671 error = lock_mount(&old);
47672 if (error)
47673diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
47674index f729698..2bac081 100644
47675--- a/fs/nfs/inode.c
47676+++ b/fs/nfs/inode.c
47677@@ -152,7 +152,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
47678 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
47679 nfsi->attrtimeo_timestamp = jiffies;
47680
47681- memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
47682+ memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
47683 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
47684 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
47685 else
47686@@ -1008,16 +1008,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
47687 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
47688 }
47689
47690-static atomic_long_t nfs_attr_generation_counter;
47691+static atomic_long_unchecked_t nfs_attr_generation_counter;
47692
47693 static unsigned long nfs_read_attr_generation_counter(void)
47694 {
47695- return atomic_long_read(&nfs_attr_generation_counter);
47696+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
47697 }
47698
47699 unsigned long nfs_inc_attr_generation_counter(void)
47700 {
47701- return atomic_long_inc_return(&nfs_attr_generation_counter);
47702+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
47703 }
47704
47705 void nfs_fattr_init(struct nfs_fattr *fattr)
47706diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
47707index c8bd9c3..4f83416 100644
47708--- a/fs/nfsd/vfs.c
47709+++ b/fs/nfsd/vfs.c
47710@@ -933,7 +933,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47711 } else {
47712 oldfs = get_fs();
47713 set_fs(KERNEL_DS);
47714- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
47715+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
47716 set_fs(oldfs);
47717 }
47718
47719@@ -1037,7 +1037,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47720
47721 /* Write the data. */
47722 oldfs = get_fs(); set_fs(KERNEL_DS);
47723- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
47724+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
47725 set_fs(oldfs);
47726 if (host_err < 0)
47727 goto out_nfserr;
47728@@ -1573,7 +1573,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
47729 */
47730
47731 oldfs = get_fs(); set_fs(KERNEL_DS);
47732- host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
47733+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
47734 set_fs(oldfs);
47735
47736 if (host_err < 0)
47737diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
47738index 3568c8a..e0240d8 100644
47739--- a/fs/notify/fanotify/fanotify_user.c
47740+++ b/fs/notify/fanotify/fanotify_user.c
47741@@ -278,7 +278,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
47742 goto out_close_fd;
47743
47744 ret = -EFAULT;
47745- if (copy_to_user(buf, &fanotify_event_metadata,
47746+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
47747+ copy_to_user(buf, &fanotify_event_metadata,
47748 fanotify_event_metadata.event_len))
47749 goto out_kill_access_response;
47750
47751diff --git a/fs/notify/notification.c b/fs/notify/notification.c
47752index c887b13..0fdf472 100644
47753--- a/fs/notify/notification.c
47754+++ b/fs/notify/notification.c
47755@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
47756 * get set to 0 so it will never get 'freed'
47757 */
47758 static struct fsnotify_event *q_overflow_event;
47759-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47760+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47761
47762 /**
47763 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
47764@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47765 */
47766 u32 fsnotify_get_cookie(void)
47767 {
47768- return atomic_inc_return(&fsnotify_sync_cookie);
47769+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
47770 }
47771 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
47772
47773diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
47774index 99e3610..02c1068 100644
47775--- a/fs/ntfs/dir.c
47776+++ b/fs/ntfs/dir.c
47777@@ -1329,7 +1329,7 @@ find_next_index_buffer:
47778 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
47779 ~(s64)(ndir->itype.index.block_size - 1)));
47780 /* Bounds checks. */
47781- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47782+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47783 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
47784 "inode 0x%lx or driver bug.", vdir->i_ino);
47785 goto err_out;
47786diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
47787index 7389d2d..dfd5dbe 100644
47788--- a/fs/ntfs/file.c
47789+++ b/fs/ntfs/file.c
47790@@ -2231,6 +2231,6 @@ const struct inode_operations ntfs_file_inode_ops = {
47791 #endif /* NTFS_RW */
47792 };
47793
47794-const struct file_operations ntfs_empty_file_ops = {};
47795+const struct file_operations ntfs_empty_file_ops __read_only;
47796
47797-const struct inode_operations ntfs_empty_inode_ops = {};
47798+const struct inode_operations ntfs_empty_inode_ops __read_only;
47799diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
47800index 210c352..a174f83 100644
47801--- a/fs/ocfs2/localalloc.c
47802+++ b/fs/ocfs2/localalloc.c
47803@@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
47804 goto bail;
47805 }
47806
47807- atomic_inc(&osb->alloc_stats.moves);
47808+ atomic_inc_unchecked(&osb->alloc_stats.moves);
47809
47810 bail:
47811 if (handle)
47812diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
47813index d355e6e..578d905 100644
47814--- a/fs/ocfs2/ocfs2.h
47815+++ b/fs/ocfs2/ocfs2.h
47816@@ -235,11 +235,11 @@ enum ocfs2_vol_state
47817
47818 struct ocfs2_alloc_stats
47819 {
47820- atomic_t moves;
47821- atomic_t local_data;
47822- atomic_t bitmap_data;
47823- atomic_t bg_allocs;
47824- atomic_t bg_extends;
47825+ atomic_unchecked_t moves;
47826+ atomic_unchecked_t local_data;
47827+ atomic_unchecked_t bitmap_data;
47828+ atomic_unchecked_t bg_allocs;
47829+ atomic_unchecked_t bg_extends;
47830 };
47831
47832 enum ocfs2_local_alloc_state
47833diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
47834index f169da4..9112253 100644
47835--- a/fs/ocfs2/suballoc.c
47836+++ b/fs/ocfs2/suballoc.c
47837@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
47838 mlog_errno(status);
47839 goto bail;
47840 }
47841- atomic_inc(&osb->alloc_stats.bg_extends);
47842+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
47843
47844 /* You should never ask for this much metadata */
47845 BUG_ON(bits_wanted >
47846@@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
47847 mlog_errno(status);
47848 goto bail;
47849 }
47850- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47851+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47852
47853 *suballoc_loc = res.sr_bg_blkno;
47854 *suballoc_bit_start = res.sr_bit_offset;
47855@@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
47856 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
47857 res->sr_bits);
47858
47859- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47860+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47861
47862 BUG_ON(res->sr_bits != 1);
47863
47864@@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
47865 mlog_errno(status);
47866 goto bail;
47867 }
47868- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47869+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47870
47871 BUG_ON(res.sr_bits != 1);
47872
47873@@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47874 cluster_start,
47875 num_clusters);
47876 if (!status)
47877- atomic_inc(&osb->alloc_stats.local_data);
47878+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
47879 } else {
47880 if (min_clusters > (osb->bitmap_cpg - 1)) {
47881 /* The only paths asking for contiguousness
47882@@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47883 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
47884 res.sr_bg_blkno,
47885 res.sr_bit_offset);
47886- atomic_inc(&osb->alloc_stats.bitmap_data);
47887+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
47888 *num_clusters = res.sr_bits;
47889 }
47890 }
47891diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
47892index 68f4541..89cfe6a 100644
47893--- a/fs/ocfs2/super.c
47894+++ b/fs/ocfs2/super.c
47895@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
47896 "%10s => GlobalAllocs: %d LocalAllocs: %d "
47897 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
47898 "Stats",
47899- atomic_read(&osb->alloc_stats.bitmap_data),
47900- atomic_read(&osb->alloc_stats.local_data),
47901- atomic_read(&osb->alloc_stats.bg_allocs),
47902- atomic_read(&osb->alloc_stats.moves),
47903- atomic_read(&osb->alloc_stats.bg_extends));
47904+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
47905+ atomic_read_unchecked(&osb->alloc_stats.local_data),
47906+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
47907+ atomic_read_unchecked(&osb->alloc_stats.moves),
47908+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
47909
47910 out += snprintf(buf + out, len - out,
47911 "%10s => State: %u Descriptor: %llu Size: %u bits "
47912@@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
47913 spin_lock_init(&osb->osb_xattr_lock);
47914 ocfs2_init_steal_slots(osb);
47915
47916- atomic_set(&osb->alloc_stats.moves, 0);
47917- atomic_set(&osb->alloc_stats.local_data, 0);
47918- atomic_set(&osb->alloc_stats.bitmap_data, 0);
47919- atomic_set(&osb->alloc_stats.bg_allocs, 0);
47920- atomic_set(&osb->alloc_stats.bg_extends, 0);
47921+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
47922+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
47923+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
47924+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
47925+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
47926
47927 /* Copy the blockcheck stats from the superblock probe */
47928 osb->osb_ecc_stats = *stats;
47929diff --git a/fs/open.c b/fs/open.c
47930index 1540632..79d7242 100644
47931--- a/fs/open.c
47932+++ b/fs/open.c
47933@@ -31,6 +31,8 @@
47934 #include <linux/ima.h>
47935 #include <linux/dnotify.h>
47936
47937+#define CREATE_TRACE_POINTS
47938+#include <trace/events/fs.h>
47939 #include "internal.h"
47940
47941 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
47942@@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
47943 error = locks_verify_truncate(inode, NULL, length);
47944 if (!error)
47945 error = security_path_truncate(&path);
47946+
47947+ if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
47948+ error = -EACCES;
47949+
47950 if (!error)
47951 error = do_truncate(path.dentry, length, 0, NULL);
47952
47953@@ -359,6 +365,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
47954 if (__mnt_is_readonly(path.mnt))
47955 res = -EROFS;
47956
47957+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
47958+ res = -EACCES;
47959+
47960 out_path_release:
47961 path_put(&path);
47962 out:
47963@@ -385,6 +394,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
47964 if (error)
47965 goto dput_and_out;
47966
47967+ gr_log_chdir(path.dentry, path.mnt);
47968+
47969 set_fs_pwd(current->fs, &path);
47970
47971 dput_and_out:
47972@@ -411,6 +422,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
47973 goto out_putf;
47974
47975 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
47976+
47977+ if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
47978+ error = -EPERM;
47979+
47980+ if (!error)
47981+ gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
47982+
47983 if (!error)
47984 set_fs_pwd(current->fs, &file->f_path);
47985 out_putf:
47986@@ -439,7 +457,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
47987 if (error)
47988 goto dput_and_out;
47989
47990+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
47991+ goto dput_and_out;
47992+
47993 set_fs_root(current->fs, &path);
47994+
47995+ gr_handle_chroot_chdir(&path);
47996+
47997 error = 0;
47998 dput_and_out:
47999 path_put(&path);
48000@@ -457,6 +481,16 @@ static int chmod_common(struct path *path, umode_t mode)
48001 if (error)
48002 return error;
48003 mutex_lock(&inode->i_mutex);
48004+
48005+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
48006+ error = -EACCES;
48007+ goto out_unlock;
48008+ }
48009+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
48010+ error = -EACCES;
48011+ goto out_unlock;
48012+ }
48013+
48014 error = security_path_chmod(path, mode);
48015 if (error)
48016 goto out_unlock;
48017@@ -512,6 +546,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
48018 uid = make_kuid(current_user_ns(), user);
48019 gid = make_kgid(current_user_ns(), group);
48020
48021+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
48022+ return -EACCES;
48023+
48024 newattrs.ia_valid = ATTR_CTIME;
48025 if (user != (uid_t) -1) {
48026 if (!uid_valid(uid))
48027@@ -1035,6 +1072,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
48028 } else {
48029 fsnotify_open(f);
48030 fd_install(fd, f);
48031+ trace_do_sys_open(tmp, flags, mode);
48032 }
48033 }
48034 putname(tmp);
48035diff --git a/fs/pipe.c b/fs/pipe.c
48036index 49c1065..13b9e12 100644
48037--- a/fs/pipe.c
48038+++ b/fs/pipe.c
48039@@ -438,9 +438,9 @@ redo:
48040 }
48041 if (bufs) /* More to do? */
48042 continue;
48043- if (!pipe->writers)
48044+ if (!atomic_read(&pipe->writers))
48045 break;
48046- if (!pipe->waiting_writers) {
48047+ if (!atomic_read(&pipe->waiting_writers)) {
48048 /* syscall merging: Usually we must not sleep
48049 * if O_NONBLOCK is set, or if we got some data.
48050 * But if a writer sleeps in kernel space, then
48051@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
48052 mutex_lock(&inode->i_mutex);
48053 pipe = inode->i_pipe;
48054
48055- if (!pipe->readers) {
48056+ if (!atomic_read(&pipe->readers)) {
48057 send_sig(SIGPIPE, current, 0);
48058 ret = -EPIPE;
48059 goto out;
48060@@ -553,7 +553,7 @@ redo1:
48061 for (;;) {
48062 int bufs;
48063
48064- if (!pipe->readers) {
48065+ if (!atomic_read(&pipe->readers)) {
48066 send_sig(SIGPIPE, current, 0);
48067 if (!ret)
48068 ret = -EPIPE;
48069@@ -644,9 +644,9 @@ redo2:
48070 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
48071 do_wakeup = 0;
48072 }
48073- pipe->waiting_writers++;
48074+ atomic_inc(&pipe->waiting_writers);
48075 pipe_wait(pipe);
48076- pipe->waiting_writers--;
48077+ atomic_dec(&pipe->waiting_writers);
48078 }
48079 out:
48080 mutex_unlock(&inode->i_mutex);
48081@@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48082 mask = 0;
48083 if (filp->f_mode & FMODE_READ) {
48084 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
48085- if (!pipe->writers && filp->f_version != pipe->w_counter)
48086+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
48087 mask |= POLLHUP;
48088 }
48089
48090@@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48091 * Most Unices do not set POLLERR for FIFOs but on Linux they
48092 * behave exactly like pipes for poll().
48093 */
48094- if (!pipe->readers)
48095+ if (!atomic_read(&pipe->readers))
48096 mask |= POLLERR;
48097 }
48098
48099@@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
48100
48101 mutex_lock(&inode->i_mutex);
48102 pipe = inode->i_pipe;
48103- pipe->readers -= decr;
48104- pipe->writers -= decw;
48105+ atomic_sub(decr, &pipe->readers);
48106+ atomic_sub(decw, &pipe->writers);
48107
48108- if (!pipe->readers && !pipe->writers) {
48109+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
48110 free_pipe_info(inode);
48111 } else {
48112 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
48113@@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
48114
48115 if (inode->i_pipe) {
48116 ret = 0;
48117- inode->i_pipe->readers++;
48118+ atomic_inc(&inode->i_pipe->readers);
48119 }
48120
48121 mutex_unlock(&inode->i_mutex);
48122@@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
48123
48124 if (inode->i_pipe) {
48125 ret = 0;
48126- inode->i_pipe->writers++;
48127+ atomic_inc(&inode->i_pipe->writers);
48128 }
48129
48130 mutex_unlock(&inode->i_mutex);
48131@@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
48132 if (inode->i_pipe) {
48133 ret = 0;
48134 if (filp->f_mode & FMODE_READ)
48135- inode->i_pipe->readers++;
48136+ atomic_inc(&inode->i_pipe->readers);
48137 if (filp->f_mode & FMODE_WRITE)
48138- inode->i_pipe->writers++;
48139+ atomic_inc(&inode->i_pipe->writers);
48140 }
48141
48142 mutex_unlock(&inode->i_mutex);
48143@@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
48144 inode->i_pipe = NULL;
48145 }
48146
48147-static struct vfsmount *pipe_mnt __read_mostly;
48148+struct vfsmount *pipe_mnt __read_mostly;
48149
48150 /*
48151 * pipefs_dname() is called from d_path().
48152@@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
48153 goto fail_iput;
48154 inode->i_pipe = pipe;
48155
48156- pipe->readers = pipe->writers = 1;
48157+ atomic_set(&pipe->readers, 1);
48158+ atomic_set(&pipe->writers, 1);
48159 inode->i_fop = &rdwr_pipefifo_fops;
48160
48161 /*
48162diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
48163index 15af622..0e9f4467 100644
48164--- a/fs/proc/Kconfig
48165+++ b/fs/proc/Kconfig
48166@@ -30,12 +30,12 @@ config PROC_FS
48167
48168 config PROC_KCORE
48169 bool "/proc/kcore support" if !ARM
48170- depends on PROC_FS && MMU
48171+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
48172
48173 config PROC_VMCORE
48174 bool "/proc/vmcore support"
48175- depends on PROC_FS && CRASH_DUMP
48176- default y
48177+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
48178+ default n
48179 help
48180 Exports the dump image of crashed kernel in ELF format.
48181
48182@@ -59,8 +59,8 @@ config PROC_SYSCTL
48183 limited in memory.
48184
48185 config PROC_PAGE_MONITOR
48186- default y
48187- depends on PROC_FS && MMU
48188+ default n
48189+ depends on PROC_FS && MMU && !GRKERNSEC
48190 bool "Enable /proc page monitoring" if EXPERT
48191 help
48192 Various /proc files exist to monitor process memory utilization:
48193diff --git a/fs/proc/array.c b/fs/proc/array.c
48194index c1c207c..5179411 100644
48195--- a/fs/proc/array.c
48196+++ b/fs/proc/array.c
48197@@ -60,6 +60,7 @@
48198 #include <linux/tty.h>
48199 #include <linux/string.h>
48200 #include <linux/mman.h>
48201+#include <linux/grsecurity.h>
48202 #include <linux/proc_fs.h>
48203 #include <linux/ioport.h>
48204 #include <linux/uaccess.h>
48205@@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
48206 seq_putc(m, '\n');
48207 }
48208
48209+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48210+static inline void task_pax(struct seq_file *m, struct task_struct *p)
48211+{
48212+ if (p->mm)
48213+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
48214+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
48215+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
48216+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
48217+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
48218+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
48219+ else
48220+ seq_printf(m, "PaX:\t-----\n");
48221+}
48222+#endif
48223+
48224 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48225 struct pid *pid, struct task_struct *task)
48226 {
48227@@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48228 task_cpus_allowed(m, task);
48229 cpuset_task_status_allowed(m, task);
48230 task_context_switch_counts(m, task);
48231+
48232+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48233+ task_pax(m, task);
48234+#endif
48235+
48236+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
48237+ task_grsec_rbac(m, task);
48238+#endif
48239+
48240 return 0;
48241 }
48242
48243+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48244+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48245+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
48246+ _mm->pax_flags & MF_PAX_SEGMEXEC))
48247+#endif
48248+
48249 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48250 struct pid *pid, struct task_struct *task, int whole)
48251 {
48252@@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48253 char tcomm[sizeof(task->comm)];
48254 unsigned long flags;
48255
48256+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48257+ if (current->exec_id != m->exec_id) {
48258+ gr_log_badprocpid("stat");
48259+ return 0;
48260+ }
48261+#endif
48262+
48263 state = *get_task_state(task);
48264 vsize = eip = esp = 0;
48265 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48266@@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48267 gtime = task->gtime;
48268 }
48269
48270+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48271+ if (PAX_RAND_FLAGS(mm)) {
48272+ eip = 0;
48273+ esp = 0;
48274+ wchan = 0;
48275+ }
48276+#endif
48277+#ifdef CONFIG_GRKERNSEC_HIDESYM
48278+ wchan = 0;
48279+ eip =0;
48280+ esp =0;
48281+#endif
48282+
48283 /* scale priority and nice values from timeslices to -20..20 */
48284 /* to make it look like a "normal" Unix priority/nice value */
48285 priority = task_prio(task);
48286@@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48287 seq_put_decimal_ull(m, ' ', vsize);
48288 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
48289 seq_put_decimal_ull(m, ' ', rsslim);
48290+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48291+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
48292+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
48293+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
48294+#else
48295 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
48296 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
48297 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
48298+#endif
48299 seq_put_decimal_ull(m, ' ', esp);
48300 seq_put_decimal_ull(m, ' ', eip);
48301 /* The signal information here is obsolete.
48302@@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48303 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
48304 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
48305
48306- if (mm && permitted) {
48307+ if (mm && permitted
48308+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48309+ && !PAX_RAND_FLAGS(mm)
48310+#endif
48311+ ) {
48312 seq_put_decimal_ull(m, ' ', mm->start_data);
48313 seq_put_decimal_ull(m, ' ', mm->end_data);
48314 seq_put_decimal_ull(m, ' ', mm->start_brk);
48315@@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48316 struct pid *pid, struct task_struct *task)
48317 {
48318 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
48319- struct mm_struct *mm = get_task_mm(task);
48320+ struct mm_struct *mm;
48321
48322+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48323+ if (current->exec_id != m->exec_id) {
48324+ gr_log_badprocpid("statm");
48325+ return 0;
48326+ }
48327+#endif
48328+ mm = get_task_mm(task);
48329 if (mm) {
48330 size = task_statm(mm, &shared, &text, &data, &resident);
48331 mmput(mm);
48332@@ -580,6 +648,21 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48333 return 0;
48334 }
48335
48336+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48337+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
48338+{
48339+ u32 curr_ip = 0;
48340+ unsigned long flags;
48341+
48342+ if (lock_task_sighand(task, &flags)) {
48343+ curr_ip = task->signal->curr_ip;
48344+ unlock_task_sighand(task, &flags);
48345+ }
48346+
48347+ return sprintf(buffer, "%pI4\n", &curr_ip);
48348+}
48349+#endif
48350+
48351 #ifdef CONFIG_CHECKPOINT_RESTORE
48352 static struct pid *
48353 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
48354diff --git a/fs/proc/base.c b/fs/proc/base.c
48355index 437195f..cd2210d 100644
48356--- a/fs/proc/base.c
48357+++ b/fs/proc/base.c
48358@@ -110,6 +110,14 @@ struct pid_entry {
48359 union proc_op op;
48360 };
48361
48362+struct getdents_callback {
48363+ struct linux_dirent __user * current_dir;
48364+ struct linux_dirent __user * previous;
48365+ struct file * file;
48366+ int count;
48367+ int error;
48368+};
48369+
48370 #define NOD(NAME, MODE, IOP, FOP, OP) { \
48371 .name = (NAME), \
48372 .len = sizeof(NAME) - 1, \
48373@@ -209,6 +217,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
48374 if (!mm->arg_end)
48375 goto out_mm; /* Shh! No looking before we're done */
48376
48377+ if (gr_acl_handle_procpidmem(task))
48378+ goto out_mm;
48379+
48380 len = mm->arg_end - mm->arg_start;
48381
48382 if (len > PAGE_SIZE)
48383@@ -236,12 +247,28 @@ out:
48384 return res;
48385 }
48386
48387+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48388+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48389+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
48390+ _mm->pax_flags & MF_PAX_SEGMEXEC))
48391+#endif
48392+
48393 static int proc_pid_auxv(struct task_struct *task, char *buffer)
48394 {
48395 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
48396 int res = PTR_ERR(mm);
48397 if (mm && !IS_ERR(mm)) {
48398 unsigned int nwords = 0;
48399+
48400+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48401+ /* allow if we're currently ptracing this task */
48402+ if (PAX_RAND_FLAGS(mm) &&
48403+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
48404+ mmput(mm);
48405+ return 0;
48406+ }
48407+#endif
48408+
48409 do {
48410 nwords += 2;
48411 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
48412@@ -255,7 +282,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
48413 }
48414
48415
48416-#ifdef CONFIG_KALLSYMS
48417+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48418 /*
48419 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
48420 * Returns the resolved symbol. If that fails, simply return the address.
48421@@ -294,7 +321,7 @@ static void unlock_trace(struct task_struct *task)
48422 mutex_unlock(&task->signal->cred_guard_mutex);
48423 }
48424
48425-#ifdef CONFIG_STACKTRACE
48426+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48427
48428 #define MAX_STACK_TRACE_DEPTH 64
48429
48430@@ -486,7 +513,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
48431 return count;
48432 }
48433
48434-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48435+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48436 static int proc_pid_syscall(struct task_struct *task, char *buffer)
48437 {
48438 long nr;
48439@@ -515,7 +542,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
48440 /************************************************************************/
48441
48442 /* permission checks */
48443-static int proc_fd_access_allowed(struct inode *inode)
48444+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
48445 {
48446 struct task_struct *task;
48447 int allowed = 0;
48448@@ -525,7 +552,10 @@ static int proc_fd_access_allowed(struct inode *inode)
48449 */
48450 task = get_proc_task(inode);
48451 if (task) {
48452- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48453+ if (log)
48454+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48455+ else
48456+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48457 put_task_struct(task);
48458 }
48459 return allowed;
48460@@ -563,10 +593,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
48461 struct task_struct *task,
48462 int hide_pid_min)
48463 {
48464+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48465+ return false;
48466+
48467+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48468+ rcu_read_lock();
48469+ {
48470+ const struct cred *tmpcred = current_cred();
48471+ const struct cred *cred = __task_cred(task);
48472+
48473+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
48474+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48475+ || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
48476+#endif
48477+ ) {
48478+ rcu_read_unlock();
48479+ return true;
48480+ }
48481+ }
48482+ rcu_read_unlock();
48483+
48484+ if (!pid->hide_pid)
48485+ return false;
48486+#endif
48487+
48488 if (pid->hide_pid < hide_pid_min)
48489 return true;
48490 if (in_group_p(pid->pid_gid))
48491 return true;
48492+
48493 return ptrace_may_access(task, PTRACE_MODE_READ);
48494 }
48495
48496@@ -584,7 +639,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
48497 put_task_struct(task);
48498
48499 if (!has_perms) {
48500+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48501+ {
48502+#else
48503 if (pid->hide_pid == 2) {
48504+#endif
48505 /*
48506 * Let's make getdents(), stat(), and open()
48507 * consistent with each other. If a process
48508@@ -682,6 +741,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
48509 if (!task)
48510 return -ESRCH;
48511
48512+ if (gr_acl_handle_procpidmem(task)) {
48513+ put_task_struct(task);
48514+ return -EPERM;
48515+ }
48516+
48517 mm = mm_access(task, mode);
48518 put_task_struct(task);
48519
48520@@ -695,16 +759,24 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
48521 mmput(mm);
48522 }
48523
48524- /* OK to pass negative loff_t, we can catch out-of-range */
48525- file->f_mode |= FMODE_UNSIGNED_OFFSET;
48526 file->private_data = mm;
48527
48528+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48529+ file->f_version = current->exec_id;
48530+#endif
48531+
48532 return 0;
48533 }
48534
48535 static int mem_open(struct inode *inode, struct file *file)
48536 {
48537- return __mem_open(inode, file, PTRACE_MODE_ATTACH);
48538+ int ret;
48539+ ret = __mem_open(inode, file, PTRACE_MODE_ATTACH);
48540+
48541+ /* OK to pass negative loff_t, we can catch out-of-range */
48542+ file->f_mode |= FMODE_UNSIGNED_OFFSET;
48543+
48544+ return ret;
48545 }
48546
48547 static ssize_t mem_rw(struct file *file, char __user *buf,
48548@@ -715,6 +787,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
48549 ssize_t copied;
48550 char *page;
48551
48552+#ifdef CONFIG_GRKERNSEC
48553+ if (write)
48554+ return -EPERM;
48555+#endif
48556+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48557+ if (file->f_version != current->exec_id) {
48558+ gr_log_badprocpid("mem");
48559+ return 0;
48560+ }
48561+#endif
48562+
48563 if (!mm)
48564 return 0;
48565
48566@@ -819,6 +902,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
48567 if (!mm)
48568 return 0;
48569
48570+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48571+ if (file->f_version != current->exec_id) {
48572+ gr_log_badprocpid("environ");
48573+ return 0;
48574+ }
48575+#endif
48576+
48577 page = (char *)__get_free_page(GFP_TEMPORARY);
48578 if (!page)
48579 return -ENOMEM;
48580@@ -827,15 +917,17 @@ static ssize_t environ_read(struct file *file, char __user *buf,
48581 if (!atomic_inc_not_zero(&mm->mm_users))
48582 goto free;
48583 while (count > 0) {
48584- int this_len, retval, max_len;
48585+ size_t this_len, max_len;
48586+ int retval;
48587+
48588+ if (src >= (mm->env_end - mm->env_start))
48589+ break;
48590
48591 this_len = mm->env_end - (mm->env_start + src);
48592
48593- if (this_len <= 0)
48594- break;
48595
48596- max_len = (count > PAGE_SIZE) ? PAGE_SIZE : count;
48597- this_len = (this_len > max_len) ? max_len : this_len;
48598+ max_len = min_t(size_t, PAGE_SIZE, count);
48599+ this_len = min(max_len, this_len);
48600
48601 retval = access_remote_vm(mm, (mm->env_start + src),
48602 page, this_len, 0);
48603@@ -1433,7 +1525,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
48604 path_put(&nd->path);
48605
48606 /* Are we allowed to snoop on the tasks file descriptors? */
48607- if (!proc_fd_access_allowed(inode))
48608+ if (!proc_fd_access_allowed(inode, 0))
48609 goto out;
48610
48611 error = PROC_I(inode)->op.proc_get_link(dentry, &nd->path);
48612@@ -1472,8 +1564,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
48613 struct path path;
48614
48615 /* Are we allowed to snoop on the tasks file descriptors? */
48616- if (!proc_fd_access_allowed(inode))
48617- goto out;
48618+ /* logging this is needed for learning on chromium to work properly,
48619+ but we don't want to flood the logs from 'ps' which does a readlink
48620+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
48621+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
48622+ */
48623+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
48624+ if (!proc_fd_access_allowed(inode,0))
48625+ goto out;
48626+ } else {
48627+ if (!proc_fd_access_allowed(inode,1))
48628+ goto out;
48629+ }
48630
48631 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
48632 if (error)
48633@@ -1538,7 +1640,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
48634 rcu_read_lock();
48635 cred = __task_cred(task);
48636 inode->i_uid = cred->euid;
48637+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48638+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48639+#else
48640 inode->i_gid = cred->egid;
48641+#endif
48642 rcu_read_unlock();
48643 }
48644 security_task_to_inode(task, inode);
48645@@ -1574,10 +1680,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
48646 return -ENOENT;
48647 }
48648 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48649+#ifdef CONFIG_GRKERNSEC_PROC_USER
48650+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48651+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48652+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48653+#endif
48654 task_dumpable(task)) {
48655 cred = __task_cred(task);
48656 stat->uid = cred->euid;
48657+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48658+ stat->gid = CONFIG_GRKERNSEC_PROC_GID;
48659+#else
48660 stat->gid = cred->egid;
48661+#endif
48662 }
48663 }
48664 rcu_read_unlock();
48665@@ -1615,11 +1730,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
48666
48667 if (task) {
48668 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48669+#ifdef CONFIG_GRKERNSEC_PROC_USER
48670+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48671+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48672+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48673+#endif
48674 task_dumpable(task)) {
48675 rcu_read_lock();
48676 cred = __task_cred(task);
48677 inode->i_uid = cred->euid;
48678+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48679+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48680+#else
48681 inode->i_gid = cred->egid;
48682+#endif
48683 rcu_read_unlock();
48684 } else {
48685 inode->i_uid = GLOBAL_ROOT_UID;
48686@@ -1737,7 +1861,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
48687 int fd = proc_fd(inode);
48688
48689 if (task) {
48690- files = get_files_struct(task);
48691+ if (!gr_acl_handle_procpidmem(task))
48692+ files = get_files_struct(task);
48693 put_task_struct(task);
48694 }
48695 if (files) {
48696@@ -2336,11 +2461,21 @@ static const struct file_operations proc_map_files_operations = {
48697 */
48698 static int proc_fd_permission(struct inode *inode, int mask)
48699 {
48700+ struct task_struct *task;
48701 int rv = generic_permission(inode, mask);
48702- if (rv == 0)
48703- return 0;
48704+
48705 if (task_pid(current) == proc_pid(inode))
48706 rv = 0;
48707+
48708+ task = get_proc_task(inode);
48709+ if (task == NULL)
48710+ return rv;
48711+
48712+ if (gr_acl_handle_procpidmem(task))
48713+ rv = -EACCES;
48714+
48715+ put_task_struct(task);
48716+
48717 return rv;
48718 }
48719
48720@@ -2450,6 +2585,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
48721 if (!task)
48722 goto out_no_task;
48723
48724+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48725+ goto out;
48726+
48727 /*
48728 * Yes, it does not scale. And it should not. Don't add
48729 * new entries into /proc/<tgid>/ without very good reasons.
48730@@ -2494,6 +2632,9 @@ static int proc_pident_readdir(struct file *filp,
48731 if (!task)
48732 goto out_no_task;
48733
48734+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48735+ goto out;
48736+
48737 ret = 0;
48738 i = filp->f_pos;
48739 switch (i) {
48740@@ -2764,7 +2905,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
48741 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
48742 void *cookie)
48743 {
48744- char *s = nd_get_link(nd);
48745+ const char *s = nd_get_link(nd);
48746 if (!IS_ERR(s))
48747 __putname(s);
48748 }
48749@@ -3033,7 +3174,7 @@ static const struct pid_entry tgid_base_stuff[] = {
48750 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
48751 #endif
48752 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48753-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48754+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48755 INF("syscall", S_IRUGO, proc_pid_syscall),
48756 #endif
48757 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48758@@ -3058,10 +3199,10 @@ static const struct pid_entry tgid_base_stuff[] = {
48759 #ifdef CONFIG_SECURITY
48760 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48761 #endif
48762-#ifdef CONFIG_KALLSYMS
48763+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48764 INF("wchan", S_IRUGO, proc_pid_wchan),
48765 #endif
48766-#ifdef CONFIG_STACKTRACE
48767+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48768 ONE("stack", S_IRUGO, proc_pid_stack),
48769 #endif
48770 #ifdef CONFIG_SCHEDSTATS
48771@@ -3095,6 +3236,9 @@ static const struct pid_entry tgid_base_stuff[] = {
48772 #ifdef CONFIG_HARDWALL
48773 INF("hardwall", S_IRUGO, proc_pid_hardwall),
48774 #endif
48775+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48776+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
48777+#endif
48778 #ifdef CONFIG_USER_NS
48779 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
48780 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
48781@@ -3225,7 +3369,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
48782 if (!inode)
48783 goto out;
48784
48785+#ifdef CONFIG_GRKERNSEC_PROC_USER
48786+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
48787+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48788+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48789+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
48790+#else
48791 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
48792+#endif
48793 inode->i_op = &proc_tgid_base_inode_operations;
48794 inode->i_fop = &proc_tgid_base_operations;
48795 inode->i_flags|=S_IMMUTABLE;
48796@@ -3267,7 +3418,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
48797 if (!task)
48798 goto out;
48799
48800+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48801+ goto out_put_task;
48802+
48803 result = proc_pid_instantiate(dir, dentry, task, NULL);
48804+out_put_task:
48805 put_task_struct(task);
48806 out:
48807 return result;
48808@@ -3330,6 +3485,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
48809 static int fake_filldir(void *buf, const char *name, int namelen,
48810 loff_t offset, u64 ino, unsigned d_type)
48811 {
48812+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
48813+ __buf->error = -EINVAL;
48814 return 0;
48815 }
48816
48817@@ -3396,7 +3553,7 @@ static const struct pid_entry tid_base_stuff[] = {
48818 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
48819 #endif
48820 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48821-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48822+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48823 INF("syscall", S_IRUGO, proc_pid_syscall),
48824 #endif
48825 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48826@@ -3423,10 +3580,10 @@ static const struct pid_entry tid_base_stuff[] = {
48827 #ifdef CONFIG_SECURITY
48828 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48829 #endif
48830-#ifdef CONFIG_KALLSYMS
48831+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48832 INF("wchan", S_IRUGO, proc_pid_wchan),
48833 #endif
48834-#ifdef CONFIG_STACKTRACE
48835+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48836 ONE("stack", S_IRUGO, proc_pid_stack),
48837 #endif
48838 #ifdef CONFIG_SCHEDSTATS
48839diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
48840index 82676e3..5f8518a 100644
48841--- a/fs/proc/cmdline.c
48842+++ b/fs/proc/cmdline.c
48843@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
48844
48845 static int __init proc_cmdline_init(void)
48846 {
48847+#ifdef CONFIG_GRKERNSEC_PROC_ADD
48848+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
48849+#else
48850 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
48851+#endif
48852 return 0;
48853 }
48854 module_init(proc_cmdline_init);
48855diff --git a/fs/proc/devices.c b/fs/proc/devices.c
48856index b143471..bb105e5 100644
48857--- a/fs/proc/devices.c
48858+++ b/fs/proc/devices.c
48859@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
48860
48861 static int __init proc_devices_init(void)
48862 {
48863+#ifdef CONFIG_GRKERNSEC_PROC_ADD
48864+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
48865+#else
48866 proc_create("devices", 0, NULL, &proc_devinfo_operations);
48867+#endif
48868 return 0;
48869 }
48870 module_init(proc_devices_init);
48871diff --git a/fs/proc/inode.c b/fs/proc/inode.c
48872index 7ac817b..abab1a5 100644
48873--- a/fs/proc/inode.c
48874+++ b/fs/proc/inode.c
48875@@ -21,11 +21,17 @@
48876 #include <linux/seq_file.h>
48877 #include <linux/slab.h>
48878 #include <linux/mount.h>
48879+#include <linux/grsecurity.h>
48880
48881 #include <asm/uaccess.h>
48882
48883 #include "internal.h"
48884
48885+#ifdef CONFIG_PROC_SYSCTL
48886+extern const struct inode_operations proc_sys_inode_operations;
48887+extern const struct inode_operations proc_sys_dir_operations;
48888+#endif
48889+
48890 static void proc_evict_inode(struct inode *inode)
48891 {
48892 struct proc_dir_entry *de;
48893@@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
48894 ns_ops = PROC_I(inode)->ns_ops;
48895 if (ns_ops && ns_ops->put)
48896 ns_ops->put(PROC_I(inode)->ns);
48897+
48898+#ifdef CONFIG_PROC_SYSCTL
48899+ if (inode->i_op == &proc_sys_inode_operations ||
48900+ inode->i_op == &proc_sys_dir_operations)
48901+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
48902+#endif
48903+
48904 }
48905
48906 static struct kmem_cache * proc_inode_cachep;
48907@@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
48908 if (de->mode) {
48909 inode->i_mode = de->mode;
48910 inode->i_uid = de->uid;
48911+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48912+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48913+#else
48914 inode->i_gid = de->gid;
48915+#endif
48916 }
48917 if (de->size)
48918 inode->i_size = de->size;
48919diff --git a/fs/proc/internal.h b/fs/proc/internal.h
48920index eca4aca..19166b2 100644
48921--- a/fs/proc/internal.h
48922+++ b/fs/proc/internal.h
48923@@ -52,6 +52,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48924 struct pid *pid, struct task_struct *task);
48925 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48926 struct pid *pid, struct task_struct *task);
48927+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48928+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
48929+#endif
48930 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
48931
48932 extern const struct file_operations proc_tid_children_operations;
48933diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
48934index 86c67ee..cdca321 100644
48935--- a/fs/proc/kcore.c
48936+++ b/fs/proc/kcore.c
48937@@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48938 * the addresses in the elf_phdr on our list.
48939 */
48940 start = kc_offset_to_vaddr(*fpos - elf_buflen);
48941- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
48942+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
48943+ if (tsz > buflen)
48944 tsz = buflen;
48945-
48946+
48947 while (buflen) {
48948 struct kcore_list *m;
48949
48950@@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48951 kfree(elf_buf);
48952 } else {
48953 if (kern_addr_valid(start)) {
48954- unsigned long n;
48955+ char *elf_buf;
48956+ mm_segment_t oldfs;
48957
48958- n = copy_to_user(buffer, (char *)start, tsz);
48959- /*
48960- * We cannot distinguish between fault on source
48961- * and fault on destination. When this happens
48962- * we clear too and hope it will trigger the
48963- * EFAULT again.
48964- */
48965- if (n) {
48966- if (clear_user(buffer + tsz - n,
48967- n))
48968+ elf_buf = kmalloc(tsz, GFP_KERNEL);
48969+ if (!elf_buf)
48970+ return -ENOMEM;
48971+ oldfs = get_fs();
48972+ set_fs(KERNEL_DS);
48973+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
48974+ set_fs(oldfs);
48975+ if (copy_to_user(buffer, elf_buf, tsz)) {
48976+ kfree(elf_buf);
48977 return -EFAULT;
48978+ }
48979 }
48980+ set_fs(oldfs);
48981+ kfree(elf_buf);
48982 } else {
48983 if (clear_user(buffer, tsz))
48984 return -EFAULT;
48985@@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48986
48987 static int open_kcore(struct inode *inode, struct file *filp)
48988 {
48989+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
48990+ return -EPERM;
48991+#endif
48992 if (!capable(CAP_SYS_RAWIO))
48993 return -EPERM;
48994 if (kcore_need_update)
48995diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
48996index 80e4645..53e5fcf 100644
48997--- a/fs/proc/meminfo.c
48998+++ b/fs/proc/meminfo.c
48999@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
49000 vmi.used >> 10,
49001 vmi.largest_chunk >> 10
49002 #ifdef CONFIG_MEMORY_FAILURE
49003- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
49004+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
49005 #endif
49006 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
49007 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
49008diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
49009index b1822dd..df622cb 100644
49010--- a/fs/proc/nommu.c
49011+++ b/fs/proc/nommu.c
49012@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
49013 if (len < 1)
49014 len = 1;
49015 seq_printf(m, "%*c", len, ' ');
49016- seq_path(m, &file->f_path, "");
49017+ seq_path(m, &file->f_path, "\n\\");
49018 }
49019
49020 seq_putc(m, '\n');
49021diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
49022index 06e1cc1..177cd98 100644
49023--- a/fs/proc/proc_net.c
49024+++ b/fs/proc/proc_net.c
49025@@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
49026 struct task_struct *task;
49027 struct nsproxy *ns;
49028 struct net *net = NULL;
49029+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49030+ const struct cred *cred = current_cred();
49031+#endif
49032+
49033+#ifdef CONFIG_GRKERNSEC_PROC_USER
49034+ if (cred->fsuid)
49035+ return net;
49036+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49037+ if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
49038+ return net;
49039+#endif
49040
49041 rcu_read_lock();
49042 task = pid_task(proc_pid(dir), PIDTYPE_PID);
49043diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
49044index 3476bca..cb6d86a 100644
49045--- a/fs/proc/proc_sysctl.c
49046+++ b/fs/proc/proc_sysctl.c
49047@@ -12,11 +12,15 @@
49048 #include <linux/module.h>
49049 #include "internal.h"
49050
49051+extern int gr_handle_chroot_sysctl(const int op);
49052+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
49053+ const int op);
49054+
49055 static const struct dentry_operations proc_sys_dentry_operations;
49056 static const struct file_operations proc_sys_file_operations;
49057-static const struct inode_operations proc_sys_inode_operations;
49058+const struct inode_operations proc_sys_inode_operations;
49059 static const struct file_operations proc_sys_dir_file_operations;
49060-static const struct inode_operations proc_sys_dir_operations;
49061+const struct inode_operations proc_sys_dir_operations;
49062
49063 void proc_sys_poll_notify(struct ctl_table_poll *poll)
49064 {
49065@@ -470,8 +474,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
49066
49067 err = NULL;
49068 d_set_d_op(dentry, &proc_sys_dentry_operations);
49069+
49070+ gr_handle_proc_create(dentry, inode);
49071+
49072 d_add(dentry, inode);
49073
49074+ if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt))
49075+ err = ERR_PTR(-ENOENT);
49076+
49077 out:
49078 sysctl_head_finish(head);
49079 return err;
49080@@ -483,18 +493,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49081 struct inode *inode = filp->f_path.dentry->d_inode;
49082 struct ctl_table_header *head = grab_header(inode);
49083 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
49084+ int op = write ? MAY_WRITE : MAY_READ;
49085 ssize_t error;
49086 size_t res;
49087
49088 if (IS_ERR(head))
49089 return PTR_ERR(head);
49090
49091+
49092 /*
49093 * At this point we know that the sysctl was not unregistered
49094 * and won't be until we finish.
49095 */
49096 error = -EPERM;
49097- if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
49098+ if (sysctl_perm(head->root, table, op))
49099 goto out;
49100
49101 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
49102@@ -502,6 +514,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49103 if (!table->proc_handler)
49104 goto out;
49105
49106+#ifdef CONFIG_GRKERNSEC
49107+ error = -EPERM;
49108+ if (gr_handle_chroot_sysctl(op))
49109+ goto out;
49110+ dget(filp->f_path.dentry);
49111+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
49112+ dput(filp->f_path.dentry);
49113+ goto out;
49114+ }
49115+ dput(filp->f_path.dentry);
49116+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
49117+ goto out;
49118+ if (write && !capable(CAP_SYS_ADMIN))
49119+ goto out;
49120+#endif
49121+
49122 /* careful: calling conventions are nasty here */
49123 res = count;
49124 error = table->proc_handler(table, write, buf, &res, ppos);
49125@@ -599,6 +627,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
49126 return -ENOMEM;
49127 } else {
49128 d_set_d_op(child, &proc_sys_dentry_operations);
49129+
49130+ gr_handle_proc_create(child, inode);
49131+
49132 d_add(child, inode);
49133 }
49134 } else {
49135@@ -642,6 +673,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
49136 if ((*pos)++ < file->f_pos)
49137 return 0;
49138
49139+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
49140+ return 0;
49141+
49142 if (unlikely(S_ISLNK(table->mode)))
49143 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
49144 else
49145@@ -759,6 +793,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
49146 if (IS_ERR(head))
49147 return PTR_ERR(head);
49148
49149+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
49150+ return -ENOENT;
49151+
49152 generic_fillattr(inode, stat);
49153 if (table)
49154 stat->mode = (stat->mode & S_IFMT) | table->mode;
49155@@ -781,13 +818,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
49156 .llseek = generic_file_llseek,
49157 };
49158
49159-static const struct inode_operations proc_sys_inode_operations = {
49160+const struct inode_operations proc_sys_inode_operations = {
49161 .permission = proc_sys_permission,
49162 .setattr = proc_sys_setattr,
49163 .getattr = proc_sys_getattr,
49164 };
49165
49166-static const struct inode_operations proc_sys_dir_operations = {
49167+const struct inode_operations proc_sys_dir_operations = {
49168 .lookup = proc_sys_lookup,
49169 .permission = proc_sys_permission,
49170 .setattr = proc_sys_setattr,
49171diff --git a/fs/proc/root.c b/fs/proc/root.c
49172index 7c30fce..b3d3aa2 100644
49173--- a/fs/proc/root.c
49174+++ b/fs/proc/root.c
49175@@ -188,7 +188,15 @@ void __init proc_root_init(void)
49176 #ifdef CONFIG_PROC_DEVICETREE
49177 proc_device_tree_init();
49178 #endif
49179+#ifdef CONFIG_GRKERNSEC_PROC_ADD
49180+#ifdef CONFIG_GRKERNSEC_PROC_USER
49181+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
49182+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49183+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
49184+#endif
49185+#else
49186 proc_mkdir("bus", NULL);
49187+#endif
49188 proc_sys_init();
49189 }
49190
49191diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
49192index 4540b8f..1b9772f 100644
49193--- a/fs/proc/task_mmu.c
49194+++ b/fs/proc/task_mmu.c
49195@@ -11,12 +11,19 @@
49196 #include <linux/rmap.h>
49197 #include <linux/swap.h>
49198 #include <linux/swapops.h>
49199+#include <linux/grsecurity.h>
49200
49201 #include <asm/elf.h>
49202 #include <asm/uaccess.h>
49203 #include <asm/tlbflush.h>
49204 #include "internal.h"
49205
49206+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49207+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49208+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
49209+ _mm->pax_flags & MF_PAX_SEGMEXEC))
49210+#endif
49211+
49212 void task_mem(struct seq_file *m, struct mm_struct *mm)
49213 {
49214 unsigned long data, text, lib, swap;
49215@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49216 "VmExe:\t%8lu kB\n"
49217 "VmLib:\t%8lu kB\n"
49218 "VmPTE:\t%8lu kB\n"
49219- "VmSwap:\t%8lu kB\n",
49220- hiwater_vm << (PAGE_SHIFT-10),
49221+ "VmSwap:\t%8lu kB\n"
49222+
49223+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49224+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
49225+#endif
49226+
49227+ ,hiwater_vm << (PAGE_SHIFT-10),
49228 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
49229 mm->locked_vm << (PAGE_SHIFT-10),
49230 mm->pinned_vm << (PAGE_SHIFT-10),
49231@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49232 data << (PAGE_SHIFT-10),
49233 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
49234 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
49235- swap << (PAGE_SHIFT-10));
49236+ swap << (PAGE_SHIFT-10)
49237+
49238+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49239+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49240+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
49241+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
49242+#else
49243+ , mm->context.user_cs_base
49244+ , mm->context.user_cs_limit
49245+#endif
49246+#endif
49247+
49248+ );
49249 }
49250
49251 unsigned long task_vsize(struct mm_struct *mm)
49252@@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49253 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
49254 }
49255
49256- /* We don't show the stack guard page in /proc/maps */
49257+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49258+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
49259+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
49260+#else
49261 start = vma->vm_start;
49262- if (stack_guard_page_start(vma, start))
49263- start += PAGE_SIZE;
49264 end = vma->vm_end;
49265- if (stack_guard_page_end(vma, end))
49266- end -= PAGE_SIZE;
49267+#endif
49268
49269 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
49270 start,
49271@@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49272 flags & VM_WRITE ? 'w' : '-',
49273 flags & VM_EXEC ? 'x' : '-',
49274 flags & VM_MAYSHARE ? 's' : 'p',
49275+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49276+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
49277+#else
49278 pgoff,
49279+#endif
49280 MAJOR(dev), MINOR(dev), ino, &len);
49281
49282 /*
49283@@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49284 */
49285 if (file) {
49286 pad_len_spaces(m, len);
49287- seq_path(m, &file->f_path, "\n");
49288+ seq_path(m, &file->f_path, "\n\\");
49289 goto done;
49290 }
49291
49292@@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49293 * Thread stack in /proc/PID/task/TID/maps or
49294 * the main process stack.
49295 */
49296- if (!is_pid || (vma->vm_start <= mm->start_stack &&
49297- vma->vm_end >= mm->start_stack)) {
49298+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
49299+ (vma->vm_start <= mm->start_stack &&
49300+ vma->vm_end >= mm->start_stack)) {
49301 name = "[stack]";
49302 } else {
49303 /* Thread stack in /proc/PID/maps */
49304@@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
49305 struct proc_maps_private *priv = m->private;
49306 struct task_struct *task = priv->task;
49307
49308+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49309+ if (current->exec_id != m->exec_id) {
49310+ gr_log_badprocpid("maps");
49311+ return 0;
49312+ }
49313+#endif
49314+
49315 show_map_vma(m, vma, is_pid);
49316
49317 if (m->count < m->size) /* vma is copied successfully */
49318@@ -492,12 +528,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49319 .private = &mss,
49320 };
49321
49322+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49323+ if (current->exec_id != m->exec_id) {
49324+ gr_log_badprocpid("smaps");
49325+ return 0;
49326+ }
49327+#endif
49328 memset(&mss, 0, sizeof mss);
49329- mss.vma = vma;
49330- /* mmap_sem is held in m_start */
49331- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49332- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49333-
49334+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49335+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
49336+#endif
49337+ mss.vma = vma;
49338+ /* mmap_sem is held in m_start */
49339+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49340+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49341+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49342+ }
49343+#endif
49344 show_map_vma(m, vma, is_pid);
49345
49346 seq_printf(m,
49347@@ -515,7 +562,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49348 "KernelPageSize: %8lu kB\n"
49349 "MMUPageSize: %8lu kB\n"
49350 "Locked: %8lu kB\n",
49351+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49352+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
49353+#else
49354 (vma->vm_end - vma->vm_start) >> 10,
49355+#endif
49356 mss.resident >> 10,
49357 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
49358 mss.shared_clean >> 10,
49359@@ -1164,6 +1215,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49360 int n;
49361 char buffer[50];
49362
49363+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49364+ if (current->exec_id != m->exec_id) {
49365+ gr_log_badprocpid("numa_maps");
49366+ return 0;
49367+ }
49368+#endif
49369+
49370 if (!mm)
49371 return 0;
49372
49373@@ -1181,11 +1239,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49374 mpol_to_str(buffer, sizeof(buffer), pol, 0);
49375 mpol_cond_put(pol);
49376
49377+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49378+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
49379+#else
49380 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
49381+#endif
49382
49383 if (file) {
49384 seq_printf(m, " file=");
49385- seq_path(m, &file->f_path, "\n\t= ");
49386+ seq_path(m, &file->f_path, "\n\t\\= ");
49387 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
49388 seq_printf(m, " heap");
49389 } else {
49390diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
49391index 1ccfa53..0848f95 100644
49392--- a/fs/proc/task_nommu.c
49393+++ b/fs/proc/task_nommu.c
49394@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49395 else
49396 bytes += kobjsize(mm);
49397
49398- if (current->fs && current->fs->users > 1)
49399+ if (current->fs && atomic_read(&current->fs->users) > 1)
49400 sbytes += kobjsize(current->fs);
49401 else
49402 bytes += kobjsize(current->fs);
49403@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
49404
49405 if (file) {
49406 pad_len_spaces(m, len);
49407- seq_path(m, &file->f_path, "");
49408+ seq_path(m, &file->f_path, "\n\\");
49409 } else if (mm) {
49410 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
49411
49412diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
49413index d67908b..d13f6a6 100644
49414--- a/fs/quota/netlink.c
49415+++ b/fs/quota/netlink.c
49416@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
49417 void quota_send_warning(short type, unsigned int id, dev_t dev,
49418 const char warntype)
49419 {
49420- static atomic_t seq;
49421+ static atomic_unchecked_t seq;
49422 struct sk_buff *skb;
49423 void *msg_head;
49424 int ret;
49425@@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
49426 "VFS: Not enough memory to send quota warning.\n");
49427 return;
49428 }
49429- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
49430+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
49431 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
49432 if (!msg_head) {
49433 printk(KERN_ERR
49434diff --git a/fs/readdir.c b/fs/readdir.c
49435index 39e3370..20d446d 100644
49436--- a/fs/readdir.c
49437+++ b/fs/readdir.c
49438@@ -17,6 +17,7 @@
49439 #include <linux/security.h>
49440 #include <linux/syscalls.h>
49441 #include <linux/unistd.h>
49442+#include <linux/namei.h>
49443
49444 #include <asm/uaccess.h>
49445
49446@@ -67,6 +68,7 @@ struct old_linux_dirent {
49447
49448 struct readdir_callback {
49449 struct old_linux_dirent __user * dirent;
49450+ struct file * file;
49451 int result;
49452 };
49453
49454@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
49455 buf->result = -EOVERFLOW;
49456 return -EOVERFLOW;
49457 }
49458+
49459+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49460+ return 0;
49461+
49462 buf->result++;
49463 dirent = buf->dirent;
49464 if (!access_ok(VERIFY_WRITE, dirent,
49465@@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
49466
49467 buf.result = 0;
49468 buf.dirent = dirent;
49469+ buf.file = file;
49470
49471 error = vfs_readdir(file, fillonedir, &buf);
49472 if (buf.result)
49473@@ -141,6 +148,7 @@ struct linux_dirent {
49474 struct getdents_callback {
49475 struct linux_dirent __user * current_dir;
49476 struct linux_dirent __user * previous;
49477+ struct file * file;
49478 int count;
49479 int error;
49480 };
49481@@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
49482 buf->error = -EOVERFLOW;
49483 return -EOVERFLOW;
49484 }
49485+
49486+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49487+ return 0;
49488+
49489 dirent = buf->previous;
49490 if (dirent) {
49491 if (__put_user(offset, &dirent->d_off))
49492@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49493 buf.previous = NULL;
49494 buf.count = count;
49495 buf.error = 0;
49496+ buf.file = file;
49497
49498 error = vfs_readdir(file, filldir, &buf);
49499 if (error >= 0)
49500@@ -226,6 +239,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49501 struct getdents_callback64 {
49502 struct linux_dirent64 __user * current_dir;
49503 struct linux_dirent64 __user * previous;
49504+ struct file *file;
49505 int count;
49506 int error;
49507 };
49508@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
49509 buf->error = -EINVAL; /* only used if we fail.. */
49510 if (reclen > buf->count)
49511 return -EINVAL;
49512+
49513+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49514+ return 0;
49515+
49516 dirent = buf->previous;
49517 if (dirent) {
49518 if (__put_user(offset, &dirent->d_off))
49519@@ -287,6 +305,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49520
49521 buf.current_dir = dirent;
49522 buf.previous = NULL;
49523+ buf.file = file;
49524 buf.count = count;
49525 buf.error = 0;
49526
49527@@ -295,7 +314,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49528 error = buf.error;
49529 lastdirent = buf.previous;
49530 if (lastdirent) {
49531- typeof(lastdirent->d_off) d_off = file->f_pos;
49532+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
49533 if (__put_user(d_off, &lastdirent->d_off))
49534 error = -EFAULT;
49535 else
49536diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
49537index 2b7882b..1c5ef48 100644
49538--- a/fs/reiserfs/do_balan.c
49539+++ b/fs/reiserfs/do_balan.c
49540@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
49541 return;
49542 }
49543
49544- atomic_inc(&(fs_generation(tb->tb_sb)));
49545+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
49546 do_balance_starts(tb);
49547
49548 /* balance leaf returns 0 except if combining L R and S into
49549diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
49550index 2c1ade6..8c59d8d 100644
49551--- a/fs/reiserfs/procfs.c
49552+++ b/fs/reiserfs/procfs.c
49553@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
49554 "SMALL_TAILS " : "NO_TAILS ",
49555 replay_only(sb) ? "REPLAY_ONLY " : "",
49556 convert_reiserfs(sb) ? "CONV " : "",
49557- atomic_read(&r->s_generation_counter),
49558+ atomic_read_unchecked(&r->s_generation_counter),
49559 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
49560 SF(s_do_balance), SF(s_unneeded_left_neighbor),
49561 SF(s_good_search_by_key_reada), SF(s_bmaps),
49562diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
49563index 33215f5..c5d427a 100644
49564--- a/fs/reiserfs/reiserfs.h
49565+++ b/fs/reiserfs/reiserfs.h
49566@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
49567 /* Comment? -Hans */
49568 wait_queue_head_t s_wait;
49569 /* To be obsoleted soon by per buffer seals.. -Hans */
49570- atomic_t s_generation_counter; // increased by one every time the
49571+ atomic_unchecked_t s_generation_counter; // increased by one every time the
49572 // tree gets re-balanced
49573 unsigned long s_properties; /* File system properties. Currently holds
49574 on-disk FS format */
49575@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
49576 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
49577
49578 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
49579-#define get_generation(s) atomic_read (&fs_generation(s))
49580+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
49581 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
49582 #define __fs_changed(gen,s) (gen != get_generation (s))
49583 #define fs_changed(gen,s) \
49584diff --git a/fs/select.c b/fs/select.c
49585index db14c78..3aae1bd 100644
49586--- a/fs/select.c
49587+++ b/fs/select.c
49588@@ -20,6 +20,7 @@
49589 #include <linux/export.h>
49590 #include <linux/slab.h>
49591 #include <linux/poll.h>
49592+#include <linux/security.h>
49593 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
49594 #include <linux/file.h>
49595 #include <linux/fdtable.h>
49596@@ -831,6 +832,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
49597 struct poll_list *walk = head;
49598 unsigned long todo = nfds;
49599
49600+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
49601 if (nfds > rlimit(RLIMIT_NOFILE))
49602 return -EINVAL;
49603
49604diff --git a/fs/seq_file.c b/fs/seq_file.c
49605index 0cbd049..64e705c 100644
49606--- a/fs/seq_file.c
49607+++ b/fs/seq_file.c
49608@@ -9,6 +9,7 @@
49609 #include <linux/export.h>
49610 #include <linux/seq_file.h>
49611 #include <linux/slab.h>
49612+#include <linux/sched.h>
49613
49614 #include <asm/uaccess.h>
49615 #include <asm/page.h>
49616@@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
49617 memset(p, 0, sizeof(*p));
49618 mutex_init(&p->lock);
49619 p->op = op;
49620+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49621+ p->exec_id = current->exec_id;
49622+#endif
49623
49624 /*
49625 * Wrappers around seq_open(e.g. swaps_open) need to be
49626@@ -92,7 +96,7 @@ static int traverse(struct seq_file *m, loff_t offset)
49627 return 0;
49628 }
49629 if (!m->buf) {
49630- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
49631+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
49632 if (!m->buf)
49633 return -ENOMEM;
49634 }
49635@@ -132,7 +136,7 @@ static int traverse(struct seq_file *m, loff_t offset)
49636 Eoverflow:
49637 m->op->stop(m, p);
49638 kfree(m->buf);
49639- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
49640+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
49641 return !m->buf ? -ENOMEM : -EAGAIN;
49642 }
49643
49644@@ -187,7 +191,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
49645
49646 /* grab buffer if we didn't have one */
49647 if (!m->buf) {
49648- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
49649+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
49650 if (!m->buf)
49651 goto Enomem;
49652 }
49653@@ -228,7 +232,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
49654 goto Fill;
49655 m->op->stop(m, p);
49656 kfree(m->buf);
49657- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
49658+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
49659 if (!m->buf)
49660 goto Enomem;
49661 m->count = 0;
49662@@ -567,7 +571,7 @@ static void single_stop(struct seq_file *p, void *v)
49663 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
49664 void *data)
49665 {
49666- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
49667+ seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
49668 int res = -ENOMEM;
49669
49670 if (op) {
49671diff --git a/fs/splice.c b/fs/splice.c
49672index 7bf08fa..eb35c2f 100644
49673--- a/fs/splice.c
49674+++ b/fs/splice.c
49675@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49676 pipe_lock(pipe);
49677
49678 for (;;) {
49679- if (!pipe->readers) {
49680+ if (!atomic_read(&pipe->readers)) {
49681 send_sig(SIGPIPE, current, 0);
49682 if (!ret)
49683 ret = -EPIPE;
49684@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49685 do_wakeup = 0;
49686 }
49687
49688- pipe->waiting_writers++;
49689+ atomic_inc(&pipe->waiting_writers);
49690 pipe_wait(pipe);
49691- pipe->waiting_writers--;
49692+ atomic_dec(&pipe->waiting_writers);
49693 }
49694
49695 pipe_unlock(pipe);
49696@@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
49697 old_fs = get_fs();
49698 set_fs(get_ds());
49699 /* The cast to a user pointer is valid due to the set_fs() */
49700- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
49701+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
49702 set_fs(old_fs);
49703
49704 return res;
49705@@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
49706 old_fs = get_fs();
49707 set_fs(get_ds());
49708 /* The cast to a user pointer is valid due to the set_fs() */
49709- res = vfs_write(file, (const char __user *)buf, count, &pos);
49710+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
49711 set_fs(old_fs);
49712
49713 return res;
49714@@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
49715 goto err;
49716
49717 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
49718- vec[i].iov_base = (void __user *) page_address(page);
49719+ vec[i].iov_base = (void __force_user *) page_address(page);
49720 vec[i].iov_len = this_len;
49721 spd.pages[i] = page;
49722 spd.nr_pages++;
49723@@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
49724 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
49725 {
49726 while (!pipe->nrbufs) {
49727- if (!pipe->writers)
49728+ if (!atomic_read(&pipe->writers))
49729 return 0;
49730
49731- if (!pipe->waiting_writers && sd->num_spliced)
49732+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
49733 return 0;
49734
49735 if (sd->flags & SPLICE_F_NONBLOCK)
49736@@ -1187,7 +1187,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
49737 * out of the pipe right after the splice_to_pipe(). So set
49738 * PIPE_READERS appropriately.
49739 */
49740- pipe->readers = 1;
49741+ atomic_set(&pipe->readers, 1);
49742
49743 current->splice_pipe = pipe;
49744 }
49745@@ -1740,9 +1740,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49746 ret = -ERESTARTSYS;
49747 break;
49748 }
49749- if (!pipe->writers)
49750+ if (!atomic_read(&pipe->writers))
49751 break;
49752- if (!pipe->waiting_writers) {
49753+ if (!atomic_read(&pipe->waiting_writers)) {
49754 if (flags & SPLICE_F_NONBLOCK) {
49755 ret = -EAGAIN;
49756 break;
49757@@ -1774,7 +1774,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49758 pipe_lock(pipe);
49759
49760 while (pipe->nrbufs >= pipe->buffers) {
49761- if (!pipe->readers) {
49762+ if (!atomic_read(&pipe->readers)) {
49763 send_sig(SIGPIPE, current, 0);
49764 ret = -EPIPE;
49765 break;
49766@@ -1787,9 +1787,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49767 ret = -ERESTARTSYS;
49768 break;
49769 }
49770- pipe->waiting_writers++;
49771+ atomic_inc(&pipe->waiting_writers);
49772 pipe_wait(pipe);
49773- pipe->waiting_writers--;
49774+ atomic_dec(&pipe->waiting_writers);
49775 }
49776
49777 pipe_unlock(pipe);
49778@@ -1825,14 +1825,14 @@ retry:
49779 pipe_double_lock(ipipe, opipe);
49780
49781 do {
49782- if (!opipe->readers) {
49783+ if (!atomic_read(&opipe->readers)) {
49784 send_sig(SIGPIPE, current, 0);
49785 if (!ret)
49786 ret = -EPIPE;
49787 break;
49788 }
49789
49790- if (!ipipe->nrbufs && !ipipe->writers)
49791+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
49792 break;
49793
49794 /*
49795@@ -1929,7 +1929,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49796 pipe_double_lock(ipipe, opipe);
49797
49798 do {
49799- if (!opipe->readers) {
49800+ if (!atomic_read(&opipe->readers)) {
49801 send_sig(SIGPIPE, current, 0);
49802 if (!ret)
49803 ret = -EPIPE;
49804@@ -1974,7 +1974,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49805 * return EAGAIN if we have the potential of some data in the
49806 * future, otherwise just return 0
49807 */
49808- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
49809+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
49810 ret = -EAGAIN;
49811
49812 pipe_unlock(ipipe);
49813diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
49814index e6bb9b2..d8e3951 100644
49815--- a/fs/sysfs/dir.c
49816+++ b/fs/sysfs/dir.c
49817@@ -678,6 +678,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
49818 struct sysfs_dirent *sd;
49819 int rc;
49820
49821+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
49822+ const char *parent_name = parent_sd->s_name;
49823+
49824+ mode = S_IFDIR | S_IRWXU;
49825+
49826+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
49827+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
49828+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
49829+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
49830+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
49831+#endif
49832+
49833 /* allocate */
49834 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
49835 if (!sd)
49836diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
49837index 00012e3..8392349 100644
49838--- a/fs/sysfs/file.c
49839+++ b/fs/sysfs/file.c
49840@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
49841
49842 struct sysfs_open_dirent {
49843 atomic_t refcnt;
49844- atomic_t event;
49845+ atomic_unchecked_t event;
49846 wait_queue_head_t poll;
49847 struct list_head buffers; /* goes through sysfs_buffer.list */
49848 };
49849@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
49850 if (!sysfs_get_active(attr_sd))
49851 return -ENODEV;
49852
49853- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
49854+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
49855 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
49856
49857 sysfs_put_active(attr_sd);
49858@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
49859 return -ENOMEM;
49860
49861 atomic_set(&new_od->refcnt, 0);
49862- atomic_set(&new_od->event, 1);
49863+ atomic_set_unchecked(&new_od->event, 1);
49864 init_waitqueue_head(&new_od->poll);
49865 INIT_LIST_HEAD(&new_od->buffers);
49866 goto retry;
49867@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
49868
49869 sysfs_put_active(attr_sd);
49870
49871- if (buffer->event != atomic_read(&od->event))
49872+ if (buffer->event != atomic_read_unchecked(&od->event))
49873 goto trigger;
49874
49875 return DEFAULT_POLLMASK;
49876@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
49877
49878 od = sd->s_attr.open;
49879 if (od) {
49880- atomic_inc(&od->event);
49881+ atomic_inc_unchecked(&od->event);
49882 wake_up_interruptible(&od->poll);
49883 }
49884
49885diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
49886index a7ac78f..02158e1 100644
49887--- a/fs/sysfs/symlink.c
49888+++ b/fs/sysfs/symlink.c
49889@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
49890
49891 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
49892 {
49893- char *page = nd_get_link(nd);
49894+ const char *page = nd_get_link(nd);
49895 if (!IS_ERR(page))
49896 free_page((unsigned long)page);
49897 }
49898diff --git a/fs/udf/misc.c b/fs/udf/misc.c
49899index c175b4d..8f36a16 100644
49900--- a/fs/udf/misc.c
49901+++ b/fs/udf/misc.c
49902@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
49903
49904 u8 udf_tag_checksum(const struct tag *t)
49905 {
49906- u8 *data = (u8 *)t;
49907+ const u8 *data = (const u8 *)t;
49908 u8 checksum = 0;
49909 int i;
49910 for (i = 0; i < sizeof(struct tag); ++i)
49911diff --git a/fs/utimes.c b/fs/utimes.c
49912index fa4dbe4..e12d1b9 100644
49913--- a/fs/utimes.c
49914+++ b/fs/utimes.c
49915@@ -1,6 +1,7 @@
49916 #include <linux/compiler.h>
49917 #include <linux/file.h>
49918 #include <linux/fs.h>
49919+#include <linux/security.h>
49920 #include <linux/linkage.h>
49921 #include <linux/mount.h>
49922 #include <linux/namei.h>
49923@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
49924 goto mnt_drop_write_and_out;
49925 }
49926 }
49927+
49928+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
49929+ error = -EACCES;
49930+ goto mnt_drop_write_and_out;
49931+ }
49932+
49933 mutex_lock(&inode->i_mutex);
49934 error = notify_change(path->dentry, &newattrs);
49935 mutex_unlock(&inode->i_mutex);
49936diff --git a/fs/xattr.c b/fs/xattr.c
49937index 1d7ac37..23cb9ec 100644
49938--- a/fs/xattr.c
49939+++ b/fs/xattr.c
49940@@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
49941 * Extended attribute SET operations
49942 */
49943 static long
49944-setxattr(struct dentry *d, const char __user *name, const void __user *value,
49945+setxattr(struct path *path, const char __user *name, const void __user *value,
49946 size_t size, int flags)
49947 {
49948 int error;
49949@@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
49950 }
49951 }
49952
49953- error = vfs_setxattr(d, kname, kvalue, size, flags);
49954+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
49955+ error = -EACCES;
49956+ goto out;
49957+ }
49958+
49959+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
49960 out:
49961 if (vvalue)
49962 vfree(vvalue);
49963@@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
49964 return error;
49965 error = mnt_want_write(path.mnt);
49966 if (!error) {
49967- error = setxattr(path.dentry, name, value, size, flags);
49968+ error = setxattr(&path, name, value, size, flags);
49969 mnt_drop_write(path.mnt);
49970 }
49971 path_put(&path);
49972@@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
49973 return error;
49974 error = mnt_want_write(path.mnt);
49975 if (!error) {
49976- error = setxattr(path.dentry, name, value, size, flags);
49977+ error = setxattr(&path, name, value, size, flags);
49978 mnt_drop_write(path.mnt);
49979 }
49980 path_put(&path);
49981@@ -401,17 +406,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
49982 {
49983 int fput_needed;
49984 struct file *f;
49985- struct dentry *dentry;
49986 int error = -EBADF;
49987
49988 f = fget_light(fd, &fput_needed);
49989 if (!f)
49990 return error;
49991- dentry = f->f_path.dentry;
49992- audit_inode(NULL, dentry);
49993+ audit_inode(NULL, f->f_path.dentry);
49994 error = mnt_want_write_file(f);
49995 if (!error) {
49996- error = setxattr(dentry, name, value, size, flags);
49997+ error = setxattr(&f->f_path, name, value, size, flags);
49998 mnt_drop_write_file(f);
49999 }
50000 fput_light(f, fput_needed);
50001diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
50002index 69d06b0..c0996e5 100644
50003--- a/fs/xattr_acl.c
50004+++ b/fs/xattr_acl.c
50005@@ -17,8 +17,8 @@
50006 struct posix_acl *
50007 posix_acl_from_xattr(const void *value, size_t size)
50008 {
50009- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
50010- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
50011+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
50012+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
50013 int count;
50014 struct posix_acl *acl;
50015 struct posix_acl_entry *acl_e;
50016diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
50017index 58b815e..595ddee 100644
50018--- a/fs/xfs/xfs_bmap.c
50019+++ b/fs/xfs/xfs_bmap.c
50020@@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
50021 int nmap,
50022 int ret_nmap);
50023 #else
50024-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
50025+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
50026 #endif /* DEBUG */
50027
50028 STATIC int
50029diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
50030index 19bf0c5..9f26b02 100644
50031--- a/fs/xfs/xfs_dir2_sf.c
50032+++ b/fs/xfs/xfs_dir2_sf.c
50033@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
50034 }
50035
50036 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
50037- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50038+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
50039+ char name[sfep->namelen];
50040+ memcpy(name, sfep->name, sfep->namelen);
50041+ if (filldir(dirent, name, sfep->namelen,
50042+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
50043+ *offset = off & 0x7fffffff;
50044+ return 0;
50045+ }
50046+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50047 off & 0x7fffffff, ino, DT_UNKNOWN)) {
50048 *offset = off & 0x7fffffff;
50049 return 0;
50050diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
50051index 3a05a41..320bec6 100644
50052--- a/fs/xfs/xfs_ioctl.c
50053+++ b/fs/xfs/xfs_ioctl.c
50054@@ -126,7 +126,7 @@ xfs_find_handle(
50055 }
50056
50057 error = -EFAULT;
50058- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
50059+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
50060 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
50061 goto out_put;
50062
50063diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
50064index 1a25fd8..e935581 100644
50065--- a/fs/xfs/xfs_iops.c
50066+++ b/fs/xfs/xfs_iops.c
50067@@ -394,7 +394,7 @@ xfs_vn_put_link(
50068 struct nameidata *nd,
50069 void *p)
50070 {
50071- char *s = nd_get_link(nd);
50072+ const char *s = nd_get_link(nd);
50073
50074 if (!IS_ERR(s))
50075 kfree(s);
50076diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
50077new file mode 100644
50078index 0000000..4d533f1
50079--- /dev/null
50080+++ b/grsecurity/Kconfig
50081@@ -0,0 +1,941 @@
50082+#
50083+# grecurity configuration
50084+#
50085+menu "Memory Protections"
50086+depends on GRKERNSEC
50087+
50088+config GRKERNSEC_KMEM
50089+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
50090+ default y if GRKERNSEC_CONFIG_AUTO
50091+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
50092+ help
50093+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
50094+ be written to or read from to modify or leak the contents of the running
50095+ kernel. /dev/port will also not be allowed to be opened. If you have module
50096+ support disabled, enabling this will close up four ways that are
50097+ currently used to insert malicious code into the running kernel.
50098+ Even with all these features enabled, we still highly recommend that
50099+ you use the RBAC system, as it is still possible for an attacker to
50100+ modify the running kernel through privileged I/O granted by ioperm/iopl.
50101+ If you are not using XFree86, you may be able to stop this additional
50102+ case by enabling the 'Disable privileged I/O' option. Though nothing
50103+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
50104+ but only to video memory, which is the only writing we allow in this
50105+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
50106+ not be allowed to mprotect it with PROT_WRITE later.
50107+ It is highly recommended that you say Y here if you meet all the
50108+ conditions above.
50109+
50110+config GRKERNSEC_VM86
50111+ bool "Restrict VM86 mode"
50112+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50113+ depends on X86_32
50114+
50115+ help
50116+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
50117+ make use of a special execution mode on 32bit x86 processors called
50118+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
50119+ video cards and will still work with this option enabled. The purpose
50120+ of the option is to prevent exploitation of emulation errors in
50121+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
50122+ Nearly all users should be able to enable this option.
50123+
50124+config GRKERNSEC_IO
50125+ bool "Disable privileged I/O"
50126+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50127+ depends on X86
50128+ select RTC_CLASS
50129+ select RTC_INTF_DEV
50130+ select RTC_DRV_CMOS
50131+
50132+ help
50133+ If you say Y here, all ioperm and iopl calls will return an error.
50134+ Ioperm and iopl can be used to modify the running kernel.
50135+ Unfortunately, some programs need this access to operate properly,
50136+ the most notable of which are XFree86 and hwclock. hwclock can be
50137+ remedied by having RTC support in the kernel, so real-time
50138+ clock support is enabled if this option is enabled, to ensure
50139+ that hwclock operates correctly. XFree86 still will not
50140+ operate correctly with this option enabled, so DO NOT CHOOSE Y
50141+ IF YOU USE XFree86. If you use XFree86 and you still want to
50142+ protect your kernel against modification, use the RBAC system.
50143+
50144+config GRKERNSEC_PROC_MEMMAP
50145+ bool "Harden ASLR against information leaks and entropy reduction"
50146+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
50147+ depends on PAX_NOEXEC || PAX_ASLR
50148+ help
50149+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
50150+ give no information about the addresses of its mappings if
50151+ PaX features that rely on random addresses are enabled on the task.
50152+ In addition to sanitizing this information and disabling other
50153+ dangerous sources of information, this option causes reads of sensitive
50154+ /proc/<pid> entries where the file descriptor was opened in a different
50155+ task than the one performing the read. Such attempts are logged.
50156+ This option also limits argv/env strings for suid/sgid binaries
50157+ to 512KB to prevent a complete exhaustion of the stack entropy provided
50158+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
50159+ binaries to prevent alternative mmap layouts from being abused.
50160+
50161+ If you use PaX it is essential that you say Y here as it closes up
50162+ several holes that make full ASLR useless locally.
50163+
50164+config GRKERNSEC_BRUTE
50165+ bool "Deter exploit bruteforcing"
50166+ default y if GRKERNSEC_CONFIG_AUTO
50167+ help
50168+ If you say Y here, attempts to bruteforce exploits against forking
50169+ daemons such as apache or sshd, as well as against suid/sgid binaries
50170+ will be deterred. When a child of a forking daemon is killed by PaX
50171+ or crashes due to an illegal instruction or other suspicious signal,
50172+ the parent process will be delayed 30 seconds upon every subsequent
50173+ fork until the administrator is able to assess the situation and
50174+ restart the daemon.
50175+ In the suid/sgid case, the attempt is logged, the user has all their
50176+ processes terminated, and they are prevented from executing any further
50177+ processes for 15 minutes.
50178+ It is recommended that you also enable signal logging in the auditing
50179+ section so that logs are generated when a process triggers a suspicious
50180+ signal.
50181+ If the sysctl option is enabled, a sysctl option with name
50182+ "deter_bruteforce" is created.
50183+
50184+
50185+config GRKERNSEC_MODHARDEN
50186+ bool "Harden module auto-loading"
50187+ default y if GRKERNSEC_CONFIG_AUTO
50188+ depends on MODULES
50189+ help
50190+ If you say Y here, module auto-loading in response to use of some
50191+ feature implemented by an unloaded module will be restricted to
50192+ root users. Enabling this option helps defend against attacks
50193+ by unprivileged users who abuse the auto-loading behavior to
50194+ cause a vulnerable module to load that is then exploited.
50195+
50196+ If this option prevents a legitimate use of auto-loading for a
50197+ non-root user, the administrator can execute modprobe manually
50198+ with the exact name of the module mentioned in the alert log.
50199+ Alternatively, the administrator can add the module to the list
50200+ of modules loaded at boot by modifying init scripts.
50201+
50202+ Modification of init scripts will most likely be needed on
50203+ Ubuntu servers with encrypted home directory support enabled,
50204+ as the first non-root user logging in will cause the ecb(aes),
50205+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
50206+
50207+config GRKERNSEC_HIDESYM
50208+ bool "Hide kernel symbols"
50209+ default y if GRKERNSEC_CONFIG_AUTO
50210+ select PAX_USERCOPY_SLABS
50211+ help
50212+ If you say Y here, getting information on loaded modules, and
50213+ displaying all kernel symbols through a syscall will be restricted
50214+ to users with CAP_SYS_MODULE. For software compatibility reasons,
50215+ /proc/kallsyms will be restricted to the root user. The RBAC
50216+ system can hide that entry even from root.
50217+
50218+ This option also prevents leaking of kernel addresses through
50219+ several /proc entries.
50220+
50221+ Note that this option is only effective provided the following
50222+ conditions are met:
50223+ 1) The kernel using grsecurity is not precompiled by some distribution
50224+ 2) You have also enabled GRKERNSEC_DMESG
50225+ 3) You are using the RBAC system and hiding other files such as your
50226+ kernel image and System.map. Alternatively, enabling this option
50227+ causes the permissions on /boot, /lib/modules, and the kernel
50228+ source directory to change at compile time to prevent
50229+ reading by non-root users.
50230+ If the above conditions are met, this option will aid in providing a
50231+ useful protection against local kernel exploitation of overflows
50232+ and arbitrary read/write vulnerabilities.
50233+
50234+config GRKERNSEC_KERN_LOCKOUT
50235+ bool "Active kernel exploit response"
50236+ default y if GRKERNSEC_CONFIG_AUTO
50237+ depends on X86 || ARM || PPC || SPARC
50238+ help
50239+ If you say Y here, when a PaX alert is triggered due to suspicious
50240+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
50241+ or an OOPS occurs due to bad memory accesses, instead of just
50242+ terminating the offending process (and potentially allowing
50243+ a subsequent exploit from the same user), we will take one of two
50244+ actions:
50245+ If the user was root, we will panic the system
50246+ If the user was non-root, we will log the attempt, terminate
50247+ all processes owned by the user, then prevent them from creating
50248+ any new processes until the system is restarted
50249+ This deters repeated kernel exploitation/bruteforcing attempts
50250+ and is useful for later forensics.
50251+
50252+endmenu
50253+menu "Role Based Access Control Options"
50254+depends on GRKERNSEC
50255+
50256+config GRKERNSEC_RBAC_DEBUG
50257+ bool
50258+
50259+config GRKERNSEC_NO_RBAC
50260+ bool "Disable RBAC system"
50261+ help
50262+ If you say Y here, the /dev/grsec device will be removed from the kernel,
50263+ preventing the RBAC system from being enabled. You should only say Y
50264+ here if you have no intention of using the RBAC system, so as to prevent
50265+ an attacker with root access from misusing the RBAC system to hide files
50266+ and processes when loadable module support and /dev/[k]mem have been
50267+ locked down.
50268+
50269+config GRKERNSEC_ACL_HIDEKERN
50270+ bool "Hide kernel processes"
50271+ help
50272+ If you say Y here, all kernel threads will be hidden to all
50273+ processes but those whose subject has the "view hidden processes"
50274+ flag.
50275+
50276+config GRKERNSEC_ACL_MAXTRIES
50277+ int "Maximum tries before password lockout"
50278+ default 3
50279+ help
50280+ This option enforces the maximum number of times a user can attempt
50281+ to authorize themselves with the grsecurity RBAC system before being
50282+ denied the ability to attempt authorization again for a specified time.
50283+ The lower the number, the harder it will be to brute-force a password.
50284+
50285+config GRKERNSEC_ACL_TIMEOUT
50286+ int "Time to wait after max password tries, in seconds"
50287+ default 30
50288+ help
50289+ This option specifies the time the user must wait after attempting to
50290+ authorize to the RBAC system with the maximum number of invalid
50291+ passwords. The higher the number, the harder it will be to brute-force
50292+ a password.
50293+
50294+endmenu
50295+menu "Filesystem Protections"
50296+depends on GRKERNSEC
50297+
50298+config GRKERNSEC_PROC
50299+ bool "Proc restrictions"
50300+ default y if GRKERNSEC_CONFIG_AUTO
50301+ help
50302+ If you say Y here, the permissions of the /proc filesystem
50303+ will be altered to enhance system security and privacy. You MUST
50304+ choose either a user only restriction or a user and group restriction.
50305+ Depending upon the option you choose, you can either restrict users to
50306+ see only the processes they themselves run, or choose a group that can
50307+ view all processes and files normally restricted to root if you choose
50308+ the "restrict to user only" option. NOTE: If you're running identd or
50309+ ntpd as a non-root user, you will have to run it as the group you
50310+ specify here.
50311+
50312+config GRKERNSEC_PROC_USER
50313+ bool "Restrict /proc to user only"
50314+ depends on GRKERNSEC_PROC
50315+ help
50316+ If you say Y here, non-root users will only be able to view their own
50317+ processes, and restricts them from viewing network-related information,
50318+ and viewing kernel symbol and module information.
50319+
50320+config GRKERNSEC_PROC_USERGROUP
50321+ bool "Allow special group"
50322+ default y if GRKERNSEC_CONFIG_AUTO
50323+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
50324+ help
50325+ If you say Y here, you will be able to select a group that will be
50326+ able to view all processes and network-related information. If you've
50327+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
50328+ remain hidden. This option is useful if you want to run identd as
50329+ a non-root user.
50330+
50331+config GRKERNSEC_PROC_GID
50332+ int "GID for special group"
50333+ depends on GRKERNSEC_PROC_USERGROUP
50334+ default 1001
50335+
50336+config GRKERNSEC_PROC_ADD
50337+ bool "Additional restrictions"
50338+ default y if GRKERNSEC_CONFIG_AUTO
50339+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
50340+ help
50341+ If you say Y here, additional restrictions will be placed on
50342+ /proc that keep normal users from viewing device information and
50343+ slabinfo information that could be useful for exploits.
50344+
50345+config GRKERNSEC_LINK
50346+ bool "Linking restrictions"
50347+ default y if GRKERNSEC_CONFIG_AUTO
50348+ help
50349+ If you say Y here, /tmp race exploits will be prevented, since users
50350+ will no longer be able to follow symlinks owned by other users in
50351+ world-writable +t directories (e.g. /tmp), unless the owner of the
50352+ symlink is the owner of the directory. users will also not be
50353+ able to hardlink to files they do not own. If the sysctl option is
50354+ enabled, a sysctl option with name "linking_restrictions" is created.
50355+
50356+config GRKERNSEC_SYMLINKOWN
50357+ bool "Kernel-enforced SymlinksIfOwnerMatch"
50358+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
50359+ help
50360+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
50361+ that prevents it from being used as a security feature. As Apache
50362+ verifies the symlink by performing a stat() against the target of
50363+ the symlink before it is followed, an attacker can setup a symlink
50364+ to point to a same-owned file, then replace the symlink with one
50365+ that targets another user's file just after Apache "validates" the
50366+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
50367+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
50368+ will be in place for the group you specify. If the sysctl option
50369+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
50370+ created.
50371+
50372+config GRKERNSEC_SYMLINKOWN_GID
50373+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
50374+ depends on GRKERNSEC_SYMLINKOWN
50375+ default 1006
50376+ help
50377+ Setting this GID determines what group kernel-enforced
50378+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
50379+ is enabled, a sysctl option with name "symlinkown_gid" is created.
50380+
50381+config GRKERNSEC_FIFO
50382+ bool "FIFO restrictions"
50383+ default y if GRKERNSEC_CONFIG_AUTO
50384+ help
50385+ If you say Y here, users will not be able to write to FIFOs they don't
50386+ own in world-writable +t directories (e.g. /tmp), unless the owner of
50387+ the FIFO is the same owner of the directory it's held in. If the sysctl
50388+ option is enabled, a sysctl option with name "fifo_restrictions" is
50389+ created.
50390+
50391+config GRKERNSEC_SYSFS_RESTRICT
50392+ bool "Sysfs/debugfs restriction"
50393+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50394+ depends on SYSFS
50395+ help
50396+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
50397+ any filesystem normally mounted under it (e.g. debugfs) will be
50398+ mostly accessible only by root. These filesystems generally provide access
50399+ to hardware and debug information that isn't appropriate for unprivileged
50400+ users of the system. Sysfs and debugfs have also become a large source
50401+ of new vulnerabilities, ranging from infoleaks to local compromise.
50402+ There has been very little oversight with an eye toward security involved
50403+ in adding new exporters of information to these filesystems, so their
50404+ use is discouraged.
50405+ For reasons of compatibility, a few directories have been whitelisted
50406+ for access by non-root users:
50407+ /sys/fs/selinux
50408+ /sys/fs/fuse
50409+ /sys/devices/system/cpu
50410+
50411+config GRKERNSEC_ROFS
50412+ bool "Runtime read-only mount protection"
50413+ help
50414+ If you say Y here, a sysctl option with name "romount_protect" will
50415+ be created. By setting this option to 1 at runtime, filesystems
50416+ will be protected in the following ways:
50417+ * No new writable mounts will be allowed
50418+ * Existing read-only mounts won't be able to be remounted read/write
50419+ * Write operations will be denied on all block devices
50420+ This option acts independently of grsec_lock: once it is set to 1,
50421+ it cannot be turned off. Therefore, please be mindful of the resulting
50422+ behavior if this option is enabled in an init script on a read-only
50423+ filesystem. This feature is mainly intended for secure embedded systems.
50424+
50425+config GRKERNSEC_CHROOT
50426+ bool "Chroot jail restrictions"
50427+ default y if GRKERNSEC_CONFIG_AUTO
50428+ help
50429+ If you say Y here, you will be able to choose several options that will
50430+ make breaking out of a chrooted jail much more difficult. If you
50431+ encounter no software incompatibilities with the following options, it
50432+ is recommended that you enable each one.
50433+
50434+config GRKERNSEC_CHROOT_MOUNT
50435+ bool "Deny mounts"
50436+ default y if GRKERNSEC_CONFIG_AUTO
50437+ depends on GRKERNSEC_CHROOT
50438+ help
50439+ If you say Y here, processes inside a chroot will not be able to
50440+ mount or remount filesystems. If the sysctl option is enabled, a
50441+ sysctl option with name "chroot_deny_mount" is created.
50442+
50443+config GRKERNSEC_CHROOT_DOUBLE
50444+ bool "Deny double-chroots"
50445+ default y if GRKERNSEC_CONFIG_AUTO
50446+ depends on GRKERNSEC_CHROOT
50447+ help
50448+ If you say Y here, processes inside a chroot will not be able to chroot
50449+ again outside the chroot. This is a widely used method of breaking
50450+ out of a chroot jail and should not be allowed. If the sysctl
50451+ option is enabled, a sysctl option with name
50452+ "chroot_deny_chroot" is created.
50453+
50454+config GRKERNSEC_CHROOT_PIVOT
50455+ bool "Deny pivot_root in chroot"
50456+ default y if GRKERNSEC_CONFIG_AUTO
50457+ depends on GRKERNSEC_CHROOT
50458+ help
50459+ If you say Y here, processes inside a chroot will not be able to use
50460+ a function called pivot_root() that was introduced in Linux 2.3.41. It
50461+ works similar to chroot in that it changes the root filesystem. This
50462+ function could be misused in a chrooted process to attempt to break out
50463+ of the chroot, and therefore should not be allowed. If the sysctl
50464+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
50465+ created.
50466+
50467+config GRKERNSEC_CHROOT_CHDIR
50468+ bool "Enforce chdir(\"/\") on all chroots"
50469+ default y if GRKERNSEC_CONFIG_AUTO
50470+ depends on GRKERNSEC_CHROOT
50471+ help
50472+ If you say Y here, the current working directory of all newly-chrooted
50473+ applications will be set to the the root directory of the chroot.
50474+ The man page on chroot(2) states:
50475+ Note that this call does not change the current working
50476+ directory, so that `.' can be outside the tree rooted at
50477+ `/'. In particular, the super-user can escape from a
50478+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
50479+
50480+ It is recommended that you say Y here, since it's not known to break
50481+ any software. If the sysctl option is enabled, a sysctl option with
50482+ name "chroot_enforce_chdir" is created.
50483+
50484+config GRKERNSEC_CHROOT_CHMOD
50485+ bool "Deny (f)chmod +s"
50486+ default y if GRKERNSEC_CONFIG_AUTO
50487+ depends on GRKERNSEC_CHROOT
50488+ help
50489+ If you say Y here, processes inside a chroot will not be able to chmod
50490+ or fchmod files to make them have suid or sgid bits. This protects
50491+ against another published method of breaking a chroot. If the sysctl
50492+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
50493+ created.
50494+
50495+config GRKERNSEC_CHROOT_FCHDIR
50496+ bool "Deny fchdir out of chroot"
50497+ default y if GRKERNSEC_CONFIG_AUTO
50498+ depends on GRKERNSEC_CHROOT
50499+ help
50500+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
50501+ to a file descriptor of the chrooting process that points to a directory
50502+ outside the filesystem will be stopped. If the sysctl option
50503+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
50504+
50505+config GRKERNSEC_CHROOT_MKNOD
50506+ bool "Deny mknod"
50507+ default y if GRKERNSEC_CONFIG_AUTO
50508+ depends on GRKERNSEC_CHROOT
50509+ help
50510+ If you say Y here, processes inside a chroot will not be allowed to
50511+ mknod. The problem with using mknod inside a chroot is that it
50512+ would allow an attacker to create a device entry that is the same
50513+ as one on the physical root of your system, which could range from
50514+ anything from the console device to a device for your harddrive (which
50515+ they could then use to wipe the drive or steal data). It is recommended
50516+ that you say Y here, unless you run into software incompatibilities.
50517+ If the sysctl option is enabled, a sysctl option with name
50518+ "chroot_deny_mknod" is created.
50519+
50520+config GRKERNSEC_CHROOT_SHMAT
50521+ bool "Deny shmat() out of chroot"
50522+ default y if GRKERNSEC_CONFIG_AUTO
50523+ depends on GRKERNSEC_CHROOT
50524+ help
50525+ If you say Y here, processes inside a chroot will not be able to attach
50526+ to shared memory segments that were created outside of the chroot jail.
50527+ It is recommended that you say Y here. If the sysctl option is enabled,
50528+ a sysctl option with name "chroot_deny_shmat" is created.
50529+
50530+config GRKERNSEC_CHROOT_UNIX
50531+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
50532+ default y if GRKERNSEC_CONFIG_AUTO
50533+ depends on GRKERNSEC_CHROOT
50534+ help
50535+ If you say Y here, processes inside a chroot will not be able to
50536+ connect to abstract (meaning not belonging to a filesystem) Unix
50537+ domain sockets that were bound outside of a chroot. It is recommended
50538+ that you say Y here. If the sysctl option is enabled, a sysctl option
50539+ with name "chroot_deny_unix" is created.
50540+
50541+config GRKERNSEC_CHROOT_FINDTASK
50542+ bool "Protect outside processes"
50543+ default y if GRKERNSEC_CONFIG_AUTO
50544+ depends on GRKERNSEC_CHROOT
50545+ help
50546+ If you say Y here, processes inside a chroot will not be able to
50547+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
50548+ getsid, or view any process outside of the chroot. If the sysctl
50549+ option is enabled, a sysctl option with name "chroot_findtask" is
50550+ created.
50551+
50552+config GRKERNSEC_CHROOT_NICE
50553+ bool "Restrict priority changes"
50554+ default y if GRKERNSEC_CONFIG_AUTO
50555+ depends on GRKERNSEC_CHROOT
50556+ help
50557+ If you say Y here, processes inside a chroot will not be able to raise
50558+ the priority of processes in the chroot, or alter the priority of
50559+ processes outside the chroot. This provides more security than simply
50560+ removing CAP_SYS_NICE from the process' capability set. If the
50561+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
50562+ is created.
50563+
50564+config GRKERNSEC_CHROOT_SYSCTL
50565+ bool "Deny sysctl writes"
50566+ default y if GRKERNSEC_CONFIG_AUTO
50567+ depends on GRKERNSEC_CHROOT
50568+ help
50569+ If you say Y here, an attacker in a chroot will not be able to
50570+ write to sysctl entries, either by sysctl(2) or through a /proc
50571+ interface. It is strongly recommended that you say Y here. If the
50572+ sysctl option is enabled, a sysctl option with name
50573+ "chroot_deny_sysctl" is created.
50574+
50575+config GRKERNSEC_CHROOT_CAPS
50576+ bool "Capability restrictions"
50577+ default y if GRKERNSEC_CONFIG_AUTO
50578+ depends on GRKERNSEC_CHROOT
50579+ help
50580+ If you say Y here, the capabilities on all processes within a
50581+ chroot jail will be lowered to stop module insertion, raw i/o,
50582+ system and net admin tasks, rebooting the system, modifying immutable
50583+ files, modifying IPC owned by another, and changing the system time.
50584+ This is left an option because it can break some apps. Disable this
50585+ if your chrooted apps are having problems performing those kinds of
50586+ tasks. If the sysctl option is enabled, a sysctl option with
50587+ name "chroot_caps" is created.
50588+
50589+endmenu
50590+menu "Kernel Auditing"
50591+depends on GRKERNSEC
50592+
50593+config GRKERNSEC_AUDIT_GROUP
50594+ bool "Single group for auditing"
50595+ help
50596+ If you say Y here, the exec, chdir, and (un)mount logging features
50597+ will only operate on a group you specify. This option is recommended
50598+ if you only want to watch certain users instead of having a large
50599+ amount of logs from the entire system. If the sysctl option is enabled,
50600+ a sysctl option with name "audit_group" is created.
50601+
50602+config GRKERNSEC_AUDIT_GID
50603+ int "GID for auditing"
50604+ depends on GRKERNSEC_AUDIT_GROUP
50605+ default 1007
50606+
50607+config GRKERNSEC_EXECLOG
50608+ bool "Exec logging"
50609+ help
50610+ If you say Y here, all execve() calls will be logged (since the
50611+ other exec*() calls are frontends to execve(), all execution
50612+ will be logged). Useful for shell-servers that like to keep track
50613+ of their users. If the sysctl option is enabled, a sysctl option with
50614+ name "exec_logging" is created.
50615+ WARNING: This option when enabled will produce a LOT of logs, especially
50616+ on an active system.
50617+
50618+config GRKERNSEC_RESLOG
50619+ bool "Resource logging"
50620+ default y if GRKERNSEC_CONFIG_AUTO
50621+ help
50622+ If you say Y here, all attempts to overstep resource limits will
50623+ be logged with the resource name, the requested size, and the current
50624+ limit. It is highly recommended that you say Y here. If the sysctl
50625+ option is enabled, a sysctl option with name "resource_logging" is
50626+ created. If the RBAC system is enabled, the sysctl value is ignored.
50627+
50628+config GRKERNSEC_CHROOT_EXECLOG
50629+ bool "Log execs within chroot"
50630+ help
50631+ If you say Y here, all executions inside a chroot jail will be logged
50632+ to syslog. This can cause a large amount of logs if certain
50633+ applications (eg. djb's daemontools) are installed on the system, and
50634+ is therefore left as an option. If the sysctl option is enabled, a
50635+ sysctl option with name "chroot_execlog" is created.
50636+
50637+config GRKERNSEC_AUDIT_PTRACE
50638+ bool "Ptrace logging"
50639+ help
50640+ If you say Y here, all attempts to attach to a process via ptrace
50641+ will be logged. If the sysctl option is enabled, a sysctl option
50642+ with name "audit_ptrace" is created.
50643+
50644+config GRKERNSEC_AUDIT_CHDIR
50645+ bool "Chdir logging"
50646+ help
50647+ If you say Y here, all chdir() calls will be logged. If the sysctl
50648+ option is enabled, a sysctl option with name "audit_chdir" is created.
50649+
50650+config GRKERNSEC_AUDIT_MOUNT
50651+ bool "(Un)Mount logging"
50652+ help
50653+ If you say Y here, all mounts and unmounts will be logged. If the
50654+ sysctl option is enabled, a sysctl option with name "audit_mount" is
50655+ created.
50656+
50657+config GRKERNSEC_SIGNAL
50658+ bool "Signal logging"
50659+ default y if GRKERNSEC_CONFIG_AUTO
50660+ help
50661+ If you say Y here, certain important signals will be logged, such as
50662+ SIGSEGV, which will as a result inform you of when a error in a program
50663+ occurred, which in some cases could mean a possible exploit attempt.
50664+ If the sysctl option is enabled, a sysctl option with name
50665+ "signal_logging" is created.
50666+
50667+config GRKERNSEC_FORKFAIL
50668+ bool "Fork failure logging"
50669+ help
50670+ If you say Y here, all failed fork() attempts will be logged.
50671+ This could suggest a fork bomb, or someone attempting to overstep
50672+ their process limit. If the sysctl option is enabled, a sysctl option
50673+ with name "forkfail_logging" is created.
50674+
50675+config GRKERNSEC_TIME
50676+ bool "Time change logging"
50677+ default y if GRKERNSEC_CONFIG_AUTO
50678+ help
50679+ If you say Y here, any changes of the system clock will be logged.
50680+ If the sysctl option is enabled, a sysctl option with name
50681+ "timechange_logging" is created.
50682+
50683+config GRKERNSEC_PROC_IPADDR
50684+ bool "/proc/<pid>/ipaddr support"
50685+ default y if GRKERNSEC_CONFIG_AUTO
50686+ help
50687+ If you say Y here, a new entry will be added to each /proc/<pid>
50688+ directory that contains the IP address of the person using the task.
50689+ The IP is carried across local TCP and AF_UNIX stream sockets.
50690+ This information can be useful for IDS/IPSes to perform remote response
50691+ to a local attack. The entry is readable by only the owner of the
50692+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
50693+ the RBAC system), and thus does not create privacy concerns.
50694+
50695+config GRKERNSEC_RWXMAP_LOG
50696+ bool 'Denied RWX mmap/mprotect logging'
50697+ default y if GRKERNSEC_CONFIG_AUTO
50698+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
50699+ help
50700+ If you say Y here, calls to mmap() and mprotect() with explicit
50701+ usage of PROT_WRITE and PROT_EXEC together will be logged when
50702+ denied by the PAX_MPROTECT feature. If the sysctl option is
50703+ enabled, a sysctl option with name "rwxmap_logging" is created.
50704+
50705+config GRKERNSEC_AUDIT_TEXTREL
50706+ bool 'ELF text relocations logging (READ HELP)'
50707+ depends on PAX_MPROTECT
50708+ help
50709+ If you say Y here, text relocations will be logged with the filename
50710+ of the offending library or binary. The purpose of the feature is
50711+ to help Linux distribution developers get rid of libraries and
50712+ binaries that need text relocations which hinder the future progress
50713+ of PaX. Only Linux distribution developers should say Y here, and
50714+ never on a production machine, as this option creates an information
50715+ leak that could aid an attacker in defeating the randomization of
50716+ a single memory region. If the sysctl option is enabled, a sysctl
50717+ option with name "audit_textrel" is created.
50718+
50719+endmenu
50720+
50721+menu "Executable Protections"
50722+depends on GRKERNSEC
50723+
50724+config GRKERNSEC_DMESG
50725+ bool "Dmesg(8) restriction"
50726+ default y if GRKERNSEC_CONFIG_AUTO
50727+ help
50728+ If you say Y here, non-root users will not be able to use dmesg(8)
50729+ to view up to the last 4kb of messages in the kernel's log buffer.
50730+ The kernel's log buffer often contains kernel addresses and other
50731+ identifying information useful to an attacker in fingerprinting a
50732+ system for a targeted exploit.
50733+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
50734+ created.
50735+
50736+config GRKERNSEC_HARDEN_PTRACE
50737+ bool "Deter ptrace-based process snooping"
50738+ default y if GRKERNSEC_CONFIG_AUTO
50739+ help
50740+ If you say Y here, TTY sniffers and other malicious monitoring
50741+ programs implemented through ptrace will be defeated. If you
50742+ have been using the RBAC system, this option has already been
50743+ enabled for several years for all users, with the ability to make
50744+ fine-grained exceptions.
50745+
50746+ This option only affects the ability of non-root users to ptrace
50747+ processes that are not a descendent of the ptracing process.
50748+ This means that strace ./binary and gdb ./binary will still work,
50749+ but attaching to arbitrary processes will not. If the sysctl
50750+ option is enabled, a sysctl option with name "harden_ptrace" is
50751+ created.
50752+
50753+config GRKERNSEC_PTRACE_READEXEC
50754+ bool "Require read access to ptrace sensitive binaries"
50755+ default y if GRKERNSEC_CONFIG_AUTO
50756+ help
50757+ If you say Y here, unprivileged users will not be able to ptrace unreadable
50758+ binaries. This option is useful in environments that
50759+ remove the read bits (e.g. file mode 4711) from suid binaries to
50760+ prevent infoleaking of their contents. This option adds
50761+ consistency to the use of that file mode, as the binary could normally
50762+ be read out when run without privileges while ptracing.
50763+
50764+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
50765+ is created.
50766+
50767+config GRKERNSEC_SETXID
50768+ bool "Enforce consistent multithreaded privileges"
50769+ default y if GRKERNSEC_CONFIG_AUTO
50770+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
50771+ help
50772+ If you say Y here, a change from a root uid to a non-root uid
50773+ in a multithreaded application will cause the resulting uids,
50774+ gids, supplementary groups, and capabilities in that thread
50775+ to be propagated to the other threads of the process. In most
50776+ cases this is unnecessary, as glibc will emulate this behavior
50777+ on behalf of the application. Other libcs do not act in the
50778+ same way, allowing the other threads of the process to continue
50779+ running with root privileges. If the sysctl option is enabled,
50780+ a sysctl option with name "consistent_setxid" is created.
50781+
50782+config GRKERNSEC_TPE
50783+ bool "Trusted Path Execution (TPE)"
50784+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
50785+ help
50786+ If you say Y here, you will be able to choose a gid to add to the
50787+ supplementary groups of users you want to mark as "untrusted."
50788+ These users will not be able to execute any files that are not in
50789+ root-owned directories writable only by root. If the sysctl option
50790+ is enabled, a sysctl option with name "tpe" is created.
50791+
50792+config GRKERNSEC_TPE_ALL
50793+ bool "Partially restrict all non-root users"
50794+ depends on GRKERNSEC_TPE
50795+ help
50796+ If you say Y here, all non-root users will be covered under
50797+ a weaker TPE restriction. This is separate from, and in addition to,
50798+ the main TPE options that you have selected elsewhere. Thus, if a
50799+ "trusted" GID is chosen, this restriction applies to even that GID.
50800+ Under this restriction, all non-root users will only be allowed to
50801+ execute files in directories they own that are not group or
50802+ world-writable, or in directories owned by root and writable only by
50803+ root. If the sysctl option is enabled, a sysctl option with name
50804+ "tpe_restrict_all" is created.
50805+
50806+config GRKERNSEC_TPE_INVERT
50807+ bool "Invert GID option"
50808+ depends on GRKERNSEC_TPE
50809+ help
50810+ If you say Y here, the group you specify in the TPE configuration will
50811+ decide what group TPE restrictions will be *disabled* for. This
50812+ option is useful if you want TPE restrictions to be applied to most
50813+ users on the system. If the sysctl option is enabled, a sysctl option
50814+ with name "tpe_invert" is created. Unlike other sysctl options, this
50815+ entry will default to on for backward-compatibility.
50816+
50817+config GRKERNSEC_TPE_GID
50818+ int "GID for untrusted users"
50819+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
50820+ default 1005
50821+ help
50822+ Setting this GID determines what group TPE restrictions will be
50823+ *enabled* for. If the sysctl option is enabled, a sysctl option
50824+ with name "tpe_gid" is created.
50825+
50826+config GRKERNSEC_TPE_GID
50827+ int "GID for trusted users"
50828+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
50829+ default 1005
50830+ help
50831+ Setting this GID determines what group TPE restrictions will be
50832+ *disabled* for. If the sysctl option is enabled, a sysctl option
50833+ with name "tpe_gid" is created.
50834+
50835+endmenu
50836+menu "Network Protections"
50837+depends on GRKERNSEC
50838+
50839+config GRKERNSEC_RANDNET
50840+ bool "Larger entropy pools"
50841+ default y if GRKERNSEC_CONFIG_AUTO
50842+ help
50843+ If you say Y here, the entropy pools used for many features of Linux
50844+ and grsecurity will be doubled in size. Since several grsecurity
50845+ features use additional randomness, it is recommended that you say Y
50846+ here. Saying Y here has a similar effect as modifying
50847+ /proc/sys/kernel/random/poolsize.
50848+
50849+config GRKERNSEC_BLACKHOLE
50850+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
50851+ default y if GRKERNSEC_CONFIG_AUTO
50852+ depends on NET
50853+ help
50854+ If you say Y here, neither TCP resets nor ICMP
50855+ destination-unreachable packets will be sent in response to packets
50856+ sent to ports for which no associated listening process exists.
50857+ This feature supports both IPV4 and IPV6 and exempts the
50858+ loopback interface from blackholing. Enabling this feature
50859+ makes a host more resilient to DoS attacks and reduces network
50860+ visibility against scanners.
50861+
50862+ The blackhole feature as-implemented is equivalent to the FreeBSD
50863+ blackhole feature, as it prevents RST responses to all packets, not
50864+ just SYNs. Under most application behavior this causes no
50865+ problems, but applications (like haproxy) may not close certain
50866+ connections in a way that cleanly terminates them on the remote
50867+ end, leaving the remote host in LAST_ACK state. Because of this
50868+ side-effect and to prevent intentional LAST_ACK DoSes, this
50869+ feature also adds automatic mitigation against such attacks.
50870+ The mitigation drastically reduces the amount of time a socket
50871+ can spend in LAST_ACK state. If you're using haproxy and not
50872+ all servers it connects to have this option enabled, consider
50873+ disabling this feature on the haproxy host.
50874+
50875+ If the sysctl option is enabled, two sysctl options with names
50876+ "ip_blackhole" and "lastack_retries" will be created.
50877+ While "ip_blackhole" takes the standard zero/non-zero on/off
50878+ toggle, "lastack_retries" uses the same kinds of values as
50879+ "tcp_retries1" and "tcp_retries2". The default value of 4
50880+ prevents a socket from lasting more than 45 seconds in LAST_ACK
50881+ state.
50882+
50883+config GRKERNSEC_SOCKET
50884+ bool "Socket restrictions"
50885+ depends on NET
50886+ help
50887+ If you say Y here, you will be able to choose from several options.
50888+ If you assign a GID on your system and add it to the supplementary
50889+ groups of users you want to restrict socket access to, this patch
50890+ will perform up to three things, based on the option(s) you choose.
50891+
50892+config GRKERNSEC_SOCKET_ALL
50893+ bool "Deny any sockets to group"
50894+ depends on GRKERNSEC_SOCKET
50895+ help
50896+ If you say Y here, you will be able to choose a GID of whose users will
50897+ be unable to connect to other hosts from your machine or run server
50898+ applications from your machine. If the sysctl option is enabled, a
50899+ sysctl option with name "socket_all" is created.
50900+
50901+config GRKERNSEC_SOCKET_ALL_GID
50902+ int "GID to deny all sockets for"
50903+ depends on GRKERNSEC_SOCKET_ALL
50904+ default 1004
50905+ help
50906+ Here you can choose the GID to disable socket access for. Remember to
50907+ add the users you want socket access disabled for to the GID
50908+ specified here. If the sysctl option is enabled, a sysctl option
50909+ with name "socket_all_gid" is created.
50910+
50911+config GRKERNSEC_SOCKET_CLIENT
50912+ bool "Deny client sockets to group"
50913+ depends on GRKERNSEC_SOCKET
50914+ help
50915+ If you say Y here, you will be able to choose a GID of whose users will
50916+ be unable to connect to other hosts from your machine, but will be
50917+ able to run servers. If this option is enabled, all users in the group
50918+ you specify will have to use passive mode when initiating ftp transfers
50919+ from the shell on your machine. If the sysctl option is enabled, a
50920+ sysctl option with name "socket_client" is created.
50921+
50922+config GRKERNSEC_SOCKET_CLIENT_GID
50923+ int "GID to deny client sockets for"
50924+ depends on GRKERNSEC_SOCKET_CLIENT
50925+ default 1003
50926+ help
50927+ Here you can choose the GID to disable client socket access for.
50928+ Remember to add the users you want client socket access disabled for to
50929+ the GID specified here. If the sysctl option is enabled, a sysctl
50930+ option with name "socket_client_gid" is created.
50931+
50932+config GRKERNSEC_SOCKET_SERVER
50933+ bool "Deny server sockets to group"
50934+ depends on GRKERNSEC_SOCKET
50935+ help
50936+ If you say Y here, you will be able to choose a GID of whose users will
50937+ be unable to run server applications from your machine. If the sysctl
50938+ option is enabled, a sysctl option with name "socket_server" is created.
50939+
50940+config GRKERNSEC_SOCKET_SERVER_GID
50941+ int "GID to deny server sockets for"
50942+ depends on GRKERNSEC_SOCKET_SERVER
50943+ default 1002
50944+ help
50945+ Here you can choose the GID to disable server socket access for.
50946+ Remember to add the users you want server socket access disabled for to
50947+ the GID specified here. If the sysctl option is enabled, a sysctl
50948+ option with name "socket_server_gid" is created.
50949+
50950+endmenu
50951+menu "Sysctl Support"
50952+depends on GRKERNSEC && SYSCTL
50953+
50954+config GRKERNSEC_SYSCTL
50955+ bool "Sysctl support"
50956+ default y if GRKERNSEC_CONFIG_AUTO
50957+ help
50958+ If you say Y here, you will be able to change the options that
50959+ grsecurity runs with at bootup, without having to recompile your
50960+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
50961+ to enable (1) or disable (0) various features. All the sysctl entries
50962+ are mutable until the "grsec_lock" entry is set to a non-zero value.
50963+ All features enabled in the kernel configuration are disabled at boot
50964+ if you do not say Y to the "Turn on features by default" option.
50965+ All options should be set at startup, and the grsec_lock entry should
50966+ be set to a non-zero value after all the options are set.
50967+ *THIS IS EXTREMELY IMPORTANT*
50968+
50969+config GRKERNSEC_SYSCTL_DISTRO
50970+ bool "Extra sysctl support for distro makers (READ HELP)"
50971+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
50972+ help
50973+ If you say Y here, additional sysctl options will be created
50974+ for features that affect processes running as root. Therefore,
50975+ it is critical when using this option that the grsec_lock entry be
50976+ enabled after boot. Only distros with prebuilt kernel packages
50977+ with this option enabled that can ensure grsec_lock is enabled
50978+ after boot should use this option.
50979+ *Failure to set grsec_lock after boot makes all grsec features
50980+ this option covers useless*
50981+
50982+ Currently this option creates the following sysctl entries:
50983+ "Disable Privileged I/O": "disable_priv_io"
50984+
50985+config GRKERNSEC_SYSCTL_ON
50986+ bool "Turn on features by default"
50987+ default y if GRKERNSEC_CONFIG_AUTO
50988+ depends on GRKERNSEC_SYSCTL
50989+ help
50990+ If you say Y here, instead of having all features enabled in the
50991+ kernel configuration disabled at boot time, the features will be
50992+ enabled at boot time. It is recommended you say Y here unless
50993+ there is some reason you would want all sysctl-tunable features to
50994+ be disabled by default. As mentioned elsewhere, it is important
50995+ to enable the grsec_lock entry once you have finished modifying
50996+ the sysctl entries.
50997+
50998+endmenu
50999+menu "Logging Options"
51000+depends on GRKERNSEC
51001+
51002+config GRKERNSEC_FLOODTIME
51003+ int "Seconds in between log messages (minimum)"
51004+ default 10
51005+ help
51006+ This option allows you to enforce the number of seconds between
51007+ grsecurity log messages. The default should be suitable for most
51008+ people, however, if you choose to change it, choose a value small enough
51009+ to allow informative logs to be produced, but large enough to
51010+ prevent flooding.
51011+
51012+config GRKERNSEC_FLOODBURST
51013+ int "Number of messages in a burst (maximum)"
51014+ default 6
51015+ help
51016+ This option allows you to choose the maximum number of messages allowed
51017+ within the flood time interval you chose in a separate option. The
51018+ default should be suitable for most people, however if you find that
51019+ many of your logs are being interpreted as flooding, you may want to
51020+ raise this value.
51021+
51022+endmenu
51023diff --git a/grsecurity/Makefile b/grsecurity/Makefile
51024new file mode 100644
51025index 0000000..1b9afa9
51026--- /dev/null
51027+++ b/grsecurity/Makefile
51028@@ -0,0 +1,38 @@
51029+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
51030+# during 2001-2009 it has been completely redesigned by Brad Spengler
51031+# into an RBAC system
51032+#
51033+# All code in this directory and various hooks inserted throughout the kernel
51034+# are copyright Brad Spengler - Open Source Security, Inc., and released
51035+# under the GPL v2 or higher
51036+
51037+KBUILD_CFLAGS += -Werror
51038+
51039+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
51040+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
51041+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
51042+
51043+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
51044+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
51045+ gracl_learn.o grsec_log.o
51046+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
51047+
51048+ifdef CONFIG_NET
51049+obj-y += grsec_sock.o
51050+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
51051+endif
51052+
51053+ifndef CONFIG_GRKERNSEC
51054+obj-y += grsec_disabled.o
51055+endif
51056+
51057+ifdef CONFIG_GRKERNSEC_HIDESYM
51058+extra-y := grsec_hidesym.o
51059+$(obj)/grsec_hidesym.o:
51060+ @-chmod -f 500 /boot
51061+ @-chmod -f 500 /lib/modules
51062+ @-chmod -f 500 /lib64/modules
51063+ @-chmod -f 500 /lib32/modules
51064+ @-chmod -f 700 .
51065+ @echo ' grsec: protected kernel image paths'
51066+endif
51067diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
51068new file mode 100644
51069index 0000000..1561617
51070--- /dev/null
51071+++ b/grsecurity/gracl.c
51072@@ -0,0 +1,4017 @@
51073+#include <linux/kernel.h>
51074+#include <linux/module.h>
51075+#include <linux/sched.h>
51076+#include <linux/mm.h>
51077+#include <linux/file.h>
51078+#include <linux/fs.h>
51079+#include <linux/namei.h>
51080+#include <linux/mount.h>
51081+#include <linux/tty.h>
51082+#include <linux/proc_fs.h>
51083+#include <linux/lglock.h>
51084+#include <linux/slab.h>
51085+#include <linux/vmalloc.h>
51086+#include <linux/types.h>
51087+#include <linux/sysctl.h>
51088+#include <linux/netdevice.h>
51089+#include <linux/ptrace.h>
51090+#include <linux/gracl.h>
51091+#include <linux/gralloc.h>
51092+#include <linux/security.h>
51093+#include <linux/grinternal.h>
51094+#include <linux/pid_namespace.h>
51095+#include <linux/stop_machine.h>
51096+#include <linux/fdtable.h>
51097+#include <linux/percpu.h>
51098+#include <linux/lglock.h>
51099+#include "../fs/mount.h"
51100+
51101+#include <asm/uaccess.h>
51102+#include <asm/errno.h>
51103+#include <asm/mman.h>
51104+
51105+extern struct lglock vfsmount_lock;
51106+
51107+static struct acl_role_db acl_role_set;
51108+static struct name_db name_set;
51109+static struct inodev_db inodev_set;
51110+
51111+/* for keeping track of userspace pointers used for subjects, so we
51112+ can share references in the kernel as well
51113+*/
51114+
51115+static struct path real_root;
51116+
51117+static struct acl_subj_map_db subj_map_set;
51118+
51119+static struct acl_role_label *default_role;
51120+
51121+static struct acl_role_label *role_list;
51122+
51123+static u16 acl_sp_role_value;
51124+
51125+extern char *gr_shared_page[4];
51126+static DEFINE_MUTEX(gr_dev_mutex);
51127+DEFINE_RWLOCK(gr_inode_lock);
51128+
51129+struct gr_arg *gr_usermode;
51130+
51131+static unsigned int gr_status __read_only = GR_STATUS_INIT;
51132+
51133+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51134+extern void gr_clear_learn_entries(void);
51135+
51136+#ifdef CONFIG_GRKERNSEC_RESLOG
51137+extern void gr_log_resource(const struct task_struct *task,
51138+ const int res, const unsigned long wanted, const int gt);
51139+#endif
51140+
51141+unsigned char *gr_system_salt;
51142+unsigned char *gr_system_sum;
51143+
51144+static struct sprole_pw **acl_special_roles = NULL;
51145+static __u16 num_sprole_pws = 0;
51146+
51147+static struct acl_role_label *kernel_role = NULL;
51148+
51149+static unsigned int gr_auth_attempts = 0;
51150+static unsigned long gr_auth_expires = 0UL;
51151+
51152+#ifdef CONFIG_NET
51153+extern struct vfsmount *sock_mnt;
51154+#endif
51155+
51156+extern struct vfsmount *pipe_mnt;
51157+extern struct vfsmount *shm_mnt;
51158+#ifdef CONFIG_HUGETLBFS
51159+extern struct vfsmount *hugetlbfs_vfsmount;
51160+#endif
51161+
51162+static struct acl_object_label *fakefs_obj_rw;
51163+static struct acl_object_label *fakefs_obj_rwx;
51164+
51165+extern int gr_init_uidset(void);
51166+extern void gr_free_uidset(void);
51167+extern void gr_remove_uid(uid_t uid);
51168+extern int gr_find_uid(uid_t uid);
51169+
51170+__inline__ int
51171+gr_acl_is_enabled(void)
51172+{
51173+ return (gr_status & GR_READY);
51174+}
51175+
51176+#ifdef CONFIG_BTRFS_FS
51177+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51178+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51179+#endif
51180+
51181+static inline dev_t __get_dev(const struct dentry *dentry)
51182+{
51183+#ifdef CONFIG_BTRFS_FS
51184+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51185+ return get_btrfs_dev_from_inode(dentry->d_inode);
51186+ else
51187+#endif
51188+ return dentry->d_inode->i_sb->s_dev;
51189+}
51190+
51191+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51192+{
51193+ return __get_dev(dentry);
51194+}
51195+
51196+static char gr_task_roletype_to_char(struct task_struct *task)
51197+{
51198+ switch (task->role->roletype &
51199+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51200+ GR_ROLE_SPECIAL)) {
51201+ case GR_ROLE_DEFAULT:
51202+ return 'D';
51203+ case GR_ROLE_USER:
51204+ return 'U';
51205+ case GR_ROLE_GROUP:
51206+ return 'G';
51207+ case GR_ROLE_SPECIAL:
51208+ return 'S';
51209+ }
51210+
51211+ return 'X';
51212+}
51213+
51214+char gr_roletype_to_char(void)
51215+{
51216+ return gr_task_roletype_to_char(current);
51217+}
51218+
51219+__inline__ int
51220+gr_acl_tpe_check(void)
51221+{
51222+ if (unlikely(!(gr_status & GR_READY)))
51223+ return 0;
51224+ if (current->role->roletype & GR_ROLE_TPE)
51225+ return 1;
51226+ else
51227+ return 0;
51228+}
51229+
51230+int
51231+gr_handle_rawio(const struct inode *inode)
51232+{
51233+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51234+ if (inode && S_ISBLK(inode->i_mode) &&
51235+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51236+ !capable(CAP_SYS_RAWIO))
51237+ return 1;
51238+#endif
51239+ return 0;
51240+}
51241+
51242+static int
51243+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51244+{
51245+ if (likely(lena != lenb))
51246+ return 0;
51247+
51248+ return !memcmp(a, b, lena);
51249+}
51250+
51251+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51252+{
51253+ *buflen -= namelen;
51254+ if (*buflen < 0)
51255+ return -ENAMETOOLONG;
51256+ *buffer -= namelen;
51257+ memcpy(*buffer, str, namelen);
51258+ return 0;
51259+}
51260+
51261+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51262+{
51263+ return prepend(buffer, buflen, name->name, name->len);
51264+}
51265+
51266+static int prepend_path(const struct path *path, struct path *root,
51267+ char **buffer, int *buflen)
51268+{
51269+ struct dentry *dentry = path->dentry;
51270+ struct vfsmount *vfsmnt = path->mnt;
51271+ struct mount *mnt = real_mount(vfsmnt);
51272+ bool slash = false;
51273+ int error = 0;
51274+
51275+ while (dentry != root->dentry || vfsmnt != root->mnt) {
51276+ struct dentry * parent;
51277+
51278+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51279+ /* Global root? */
51280+ if (!mnt_has_parent(mnt)) {
51281+ goto out;
51282+ }
51283+ dentry = mnt->mnt_mountpoint;
51284+ mnt = mnt->mnt_parent;
51285+ vfsmnt = &mnt->mnt;
51286+ continue;
51287+ }
51288+ parent = dentry->d_parent;
51289+ prefetch(parent);
51290+ spin_lock(&dentry->d_lock);
51291+ error = prepend_name(buffer, buflen, &dentry->d_name);
51292+ spin_unlock(&dentry->d_lock);
51293+ if (!error)
51294+ error = prepend(buffer, buflen, "/", 1);
51295+ if (error)
51296+ break;
51297+
51298+ slash = true;
51299+ dentry = parent;
51300+ }
51301+
51302+out:
51303+ if (!error && !slash)
51304+ error = prepend(buffer, buflen, "/", 1);
51305+
51306+ return error;
51307+}
51308+
51309+/* this must be called with vfsmount_lock and rename_lock held */
51310+
51311+static char *__our_d_path(const struct path *path, struct path *root,
51312+ char *buf, int buflen)
51313+{
51314+ char *res = buf + buflen;
51315+ int error;
51316+
51317+ prepend(&res, &buflen, "\0", 1);
51318+ error = prepend_path(path, root, &res, &buflen);
51319+ if (error)
51320+ return ERR_PTR(error);
51321+
51322+ return res;
51323+}
51324+
51325+static char *
51326+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
51327+{
51328+ char *retval;
51329+
51330+ retval = __our_d_path(path, root, buf, buflen);
51331+ if (unlikely(IS_ERR(retval)))
51332+ retval = strcpy(buf, "<path too long>");
51333+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
51334+ retval[1] = '\0';
51335+
51336+ return retval;
51337+}
51338+
51339+static char *
51340+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51341+ char *buf, int buflen)
51342+{
51343+ struct path path;
51344+ char *res;
51345+
51346+ path.dentry = (struct dentry *)dentry;
51347+ path.mnt = (struct vfsmount *)vfsmnt;
51348+
51349+ /* we can use real_root.dentry, real_root.mnt, because this is only called
51350+ by the RBAC system */
51351+ res = gen_full_path(&path, &real_root, buf, buflen);
51352+
51353+ return res;
51354+}
51355+
51356+static char *
51357+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51358+ char *buf, int buflen)
51359+{
51360+ char *res;
51361+ struct path path;
51362+ struct path root;
51363+ struct task_struct *reaper = init_pid_ns.child_reaper;
51364+
51365+ path.dentry = (struct dentry *)dentry;
51366+ path.mnt = (struct vfsmount *)vfsmnt;
51367+
51368+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
51369+ get_fs_root(reaper->fs, &root);
51370+
51371+ write_seqlock(&rename_lock);
51372+ br_read_lock(&vfsmount_lock);
51373+ res = gen_full_path(&path, &root, buf, buflen);
51374+ br_read_unlock(&vfsmount_lock);
51375+ write_sequnlock(&rename_lock);
51376+
51377+ path_put(&root);
51378+ return res;
51379+}
51380+
51381+static char *
51382+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51383+{
51384+ char *ret;
51385+ write_seqlock(&rename_lock);
51386+ br_read_lock(&vfsmount_lock);
51387+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51388+ PAGE_SIZE);
51389+ br_read_unlock(&vfsmount_lock);
51390+ write_sequnlock(&rename_lock);
51391+ return ret;
51392+}
51393+
51394+static char *
51395+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51396+{
51397+ char *ret;
51398+ char *buf;
51399+ int buflen;
51400+
51401+ write_seqlock(&rename_lock);
51402+ br_read_lock(&vfsmount_lock);
51403+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
51404+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
51405+ buflen = (int)(ret - buf);
51406+ if (buflen >= 5)
51407+ prepend(&ret, &buflen, "/proc", 5);
51408+ else
51409+ ret = strcpy(buf, "<path too long>");
51410+ br_read_unlock(&vfsmount_lock);
51411+ write_sequnlock(&rename_lock);
51412+ return ret;
51413+}
51414+
51415+char *
51416+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
51417+{
51418+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51419+ PAGE_SIZE);
51420+}
51421+
51422+char *
51423+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
51424+{
51425+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
51426+ PAGE_SIZE);
51427+}
51428+
51429+char *
51430+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
51431+{
51432+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
51433+ PAGE_SIZE);
51434+}
51435+
51436+char *
51437+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
51438+{
51439+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
51440+ PAGE_SIZE);
51441+}
51442+
51443+char *
51444+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
51445+{
51446+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
51447+ PAGE_SIZE);
51448+}
51449+
51450+__inline__ __u32
51451+to_gr_audit(const __u32 reqmode)
51452+{
51453+ /* masks off auditable permission flags, then shifts them to create
51454+ auditing flags, and adds the special case of append auditing if
51455+ we're requesting write */
51456+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
51457+}
51458+
51459+struct acl_subject_label *
51460+lookup_subject_map(const struct acl_subject_label *userp)
51461+{
51462+ unsigned int index = shash(userp, subj_map_set.s_size);
51463+ struct subject_map *match;
51464+
51465+ match = subj_map_set.s_hash[index];
51466+
51467+ while (match && match->user != userp)
51468+ match = match->next;
51469+
51470+ if (match != NULL)
51471+ return match->kernel;
51472+ else
51473+ return NULL;
51474+}
51475+
51476+static void
51477+insert_subj_map_entry(struct subject_map *subjmap)
51478+{
51479+ unsigned int index = shash(subjmap->user, subj_map_set.s_size);
51480+ struct subject_map **curr;
51481+
51482+ subjmap->prev = NULL;
51483+
51484+ curr = &subj_map_set.s_hash[index];
51485+ if (*curr != NULL)
51486+ (*curr)->prev = subjmap;
51487+
51488+ subjmap->next = *curr;
51489+ *curr = subjmap;
51490+
51491+ return;
51492+}
51493+
51494+static struct acl_role_label *
51495+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
51496+ const gid_t gid)
51497+{
51498+ unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
51499+ struct acl_role_label *match;
51500+ struct role_allowed_ip *ipp;
51501+ unsigned int x;
51502+ u32 curr_ip = task->signal->curr_ip;
51503+
51504+ task->signal->saved_ip = curr_ip;
51505+
51506+ match = acl_role_set.r_hash[index];
51507+
51508+ while (match) {
51509+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
51510+ for (x = 0; x < match->domain_child_num; x++) {
51511+ if (match->domain_children[x] == uid)
51512+ goto found;
51513+ }
51514+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
51515+ break;
51516+ match = match->next;
51517+ }
51518+found:
51519+ if (match == NULL) {
51520+ try_group:
51521+ index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
51522+ match = acl_role_set.r_hash[index];
51523+
51524+ while (match) {
51525+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
51526+ for (x = 0; x < match->domain_child_num; x++) {
51527+ if (match->domain_children[x] == gid)
51528+ goto found2;
51529+ }
51530+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
51531+ break;
51532+ match = match->next;
51533+ }
51534+found2:
51535+ if (match == NULL)
51536+ match = default_role;
51537+ if (match->allowed_ips == NULL)
51538+ return match;
51539+ else {
51540+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51541+ if (likely
51542+ ((ntohl(curr_ip) & ipp->netmask) ==
51543+ (ntohl(ipp->addr) & ipp->netmask)))
51544+ return match;
51545+ }
51546+ match = default_role;
51547+ }
51548+ } else if (match->allowed_ips == NULL) {
51549+ return match;
51550+ } else {
51551+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51552+ if (likely
51553+ ((ntohl(curr_ip) & ipp->netmask) ==
51554+ (ntohl(ipp->addr) & ipp->netmask)))
51555+ return match;
51556+ }
51557+ goto try_group;
51558+ }
51559+
51560+ return match;
51561+}
51562+
51563+struct acl_subject_label *
51564+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
51565+ const struct acl_role_label *role)
51566+{
51567+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
51568+ struct acl_subject_label *match;
51569+
51570+ match = role->subj_hash[index];
51571+
51572+ while (match && (match->inode != ino || match->device != dev ||
51573+ (match->mode & GR_DELETED))) {
51574+ match = match->next;
51575+ }
51576+
51577+ if (match && !(match->mode & GR_DELETED))
51578+ return match;
51579+ else
51580+ return NULL;
51581+}
51582+
51583+struct acl_subject_label *
51584+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
51585+ const struct acl_role_label *role)
51586+{
51587+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
51588+ struct acl_subject_label *match;
51589+
51590+ match = role->subj_hash[index];
51591+
51592+ while (match && (match->inode != ino || match->device != dev ||
51593+ !(match->mode & GR_DELETED))) {
51594+ match = match->next;
51595+ }
51596+
51597+ if (match && (match->mode & GR_DELETED))
51598+ return match;
51599+ else
51600+ return NULL;
51601+}
51602+
51603+static struct acl_object_label *
51604+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
51605+ const struct acl_subject_label *subj)
51606+{
51607+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51608+ struct acl_object_label *match;
51609+
51610+ match = subj->obj_hash[index];
51611+
51612+ while (match && (match->inode != ino || match->device != dev ||
51613+ (match->mode & GR_DELETED))) {
51614+ match = match->next;
51615+ }
51616+
51617+ if (match && !(match->mode & GR_DELETED))
51618+ return match;
51619+ else
51620+ return NULL;
51621+}
51622+
51623+static struct acl_object_label *
51624+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
51625+ const struct acl_subject_label *subj)
51626+{
51627+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51628+ struct acl_object_label *match;
51629+
51630+ match = subj->obj_hash[index];
51631+
51632+ while (match && (match->inode != ino || match->device != dev ||
51633+ !(match->mode & GR_DELETED))) {
51634+ match = match->next;
51635+ }
51636+
51637+ if (match && (match->mode & GR_DELETED))
51638+ return match;
51639+
51640+ match = subj->obj_hash[index];
51641+
51642+ while (match && (match->inode != ino || match->device != dev ||
51643+ (match->mode & GR_DELETED))) {
51644+ match = match->next;
51645+ }
51646+
51647+ if (match && !(match->mode & GR_DELETED))
51648+ return match;
51649+ else
51650+ return NULL;
51651+}
51652+
51653+static struct name_entry *
51654+lookup_name_entry(const char *name)
51655+{
51656+ unsigned int len = strlen(name);
51657+ unsigned int key = full_name_hash(name, len);
51658+ unsigned int index = key % name_set.n_size;
51659+ struct name_entry *match;
51660+
51661+ match = name_set.n_hash[index];
51662+
51663+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
51664+ match = match->next;
51665+
51666+ return match;
51667+}
51668+
51669+static struct name_entry *
51670+lookup_name_entry_create(const char *name)
51671+{
51672+ unsigned int len = strlen(name);
51673+ unsigned int key = full_name_hash(name, len);
51674+ unsigned int index = key % name_set.n_size;
51675+ struct name_entry *match;
51676+
51677+ match = name_set.n_hash[index];
51678+
51679+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51680+ !match->deleted))
51681+ match = match->next;
51682+
51683+ if (match && match->deleted)
51684+ return match;
51685+
51686+ match = name_set.n_hash[index];
51687+
51688+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51689+ match->deleted))
51690+ match = match->next;
51691+
51692+ if (match && !match->deleted)
51693+ return match;
51694+ else
51695+ return NULL;
51696+}
51697+
51698+static struct inodev_entry *
51699+lookup_inodev_entry(const ino_t ino, const dev_t dev)
51700+{
51701+ unsigned int index = fhash(ino, dev, inodev_set.i_size);
51702+ struct inodev_entry *match;
51703+
51704+ match = inodev_set.i_hash[index];
51705+
51706+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
51707+ match = match->next;
51708+
51709+ return match;
51710+}
51711+
51712+static void
51713+insert_inodev_entry(struct inodev_entry *entry)
51714+{
51715+ unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
51716+ inodev_set.i_size);
51717+ struct inodev_entry **curr;
51718+
51719+ entry->prev = NULL;
51720+
51721+ curr = &inodev_set.i_hash[index];
51722+ if (*curr != NULL)
51723+ (*curr)->prev = entry;
51724+
51725+ entry->next = *curr;
51726+ *curr = entry;
51727+
51728+ return;
51729+}
51730+
51731+static void
51732+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
51733+{
51734+ unsigned int index =
51735+ rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
51736+ struct acl_role_label **curr;
51737+ struct acl_role_label *tmp, *tmp2;
51738+
51739+ curr = &acl_role_set.r_hash[index];
51740+
51741+ /* simple case, slot is empty, just set it to our role */
51742+ if (*curr == NULL) {
51743+ *curr = role;
51744+ } else {
51745+ /* example:
51746+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
51747+ 2 -> 3
51748+ */
51749+ /* first check to see if we can already be reached via this slot */
51750+ tmp = *curr;
51751+ while (tmp && tmp != role)
51752+ tmp = tmp->next;
51753+ if (tmp == role) {
51754+ /* we don't need to add ourselves to this slot's chain */
51755+ return;
51756+ }
51757+ /* we need to add ourselves to this chain, two cases */
51758+ if (role->next == NULL) {
51759+ /* simple case, append the current chain to our role */
51760+ role->next = *curr;
51761+ *curr = role;
51762+ } else {
51763+ /* 1 -> 2 -> 3 -> 4
51764+ 2 -> 3 -> 4
51765+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
51766+ */
51767+ /* trickier case: walk our role's chain until we find
51768+ the role for the start of the current slot's chain */
51769+ tmp = role;
51770+ tmp2 = *curr;
51771+ while (tmp->next && tmp->next != tmp2)
51772+ tmp = tmp->next;
51773+ if (tmp->next == tmp2) {
51774+ /* from example above, we found 3, so just
51775+ replace this slot's chain with ours */
51776+ *curr = role;
51777+ } else {
51778+ /* we didn't find a subset of our role's chain
51779+ in the current slot's chain, so append their
51780+ chain to ours, and set us as the first role in
51781+ the slot's chain
51782+
51783+ we could fold this case with the case above,
51784+ but making it explicit for clarity
51785+ */
51786+ tmp->next = tmp2;
51787+ *curr = role;
51788+ }
51789+ }
51790+ }
51791+
51792+ return;
51793+}
51794+
51795+static void
51796+insert_acl_role_label(struct acl_role_label *role)
51797+{
51798+ int i;
51799+
51800+ if (role_list == NULL) {
51801+ role_list = role;
51802+ role->prev = NULL;
51803+ } else {
51804+ role->prev = role_list;
51805+ role_list = role;
51806+ }
51807+
51808+ /* used for hash chains */
51809+ role->next = NULL;
51810+
51811+ if (role->roletype & GR_ROLE_DOMAIN) {
51812+ for (i = 0; i < role->domain_child_num; i++)
51813+ __insert_acl_role_label(role, role->domain_children[i]);
51814+ } else
51815+ __insert_acl_role_label(role, role->uidgid);
51816+}
51817+
51818+static int
51819+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
51820+{
51821+ struct name_entry **curr, *nentry;
51822+ struct inodev_entry *ientry;
51823+ unsigned int len = strlen(name);
51824+ unsigned int key = full_name_hash(name, len);
51825+ unsigned int index = key % name_set.n_size;
51826+
51827+ curr = &name_set.n_hash[index];
51828+
51829+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
51830+ curr = &((*curr)->next);
51831+
51832+ if (*curr != NULL)
51833+ return 1;
51834+
51835+ nentry = acl_alloc(sizeof (struct name_entry));
51836+ if (nentry == NULL)
51837+ return 0;
51838+ ientry = acl_alloc(sizeof (struct inodev_entry));
51839+ if (ientry == NULL)
51840+ return 0;
51841+ ientry->nentry = nentry;
51842+
51843+ nentry->key = key;
51844+ nentry->name = name;
51845+ nentry->inode = inode;
51846+ nentry->device = device;
51847+ nentry->len = len;
51848+ nentry->deleted = deleted;
51849+
51850+ nentry->prev = NULL;
51851+ curr = &name_set.n_hash[index];
51852+ if (*curr != NULL)
51853+ (*curr)->prev = nentry;
51854+ nentry->next = *curr;
51855+ *curr = nentry;
51856+
51857+ /* insert us into the table searchable by inode/dev */
51858+ insert_inodev_entry(ientry);
51859+
51860+ return 1;
51861+}
51862+
51863+static void
51864+insert_acl_obj_label(struct acl_object_label *obj,
51865+ struct acl_subject_label *subj)
51866+{
51867+ unsigned int index =
51868+ fhash(obj->inode, obj->device, subj->obj_hash_size);
51869+ struct acl_object_label **curr;
51870+
51871+
51872+ obj->prev = NULL;
51873+
51874+ curr = &subj->obj_hash[index];
51875+ if (*curr != NULL)
51876+ (*curr)->prev = obj;
51877+
51878+ obj->next = *curr;
51879+ *curr = obj;
51880+
51881+ return;
51882+}
51883+
51884+static void
51885+insert_acl_subj_label(struct acl_subject_label *obj,
51886+ struct acl_role_label *role)
51887+{
51888+ unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
51889+ struct acl_subject_label **curr;
51890+
51891+ obj->prev = NULL;
51892+
51893+ curr = &role->subj_hash[index];
51894+ if (*curr != NULL)
51895+ (*curr)->prev = obj;
51896+
51897+ obj->next = *curr;
51898+ *curr = obj;
51899+
51900+ return;
51901+}
51902+
51903+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
51904+
51905+static void *
51906+create_table(__u32 * len, int elementsize)
51907+{
51908+ unsigned int table_sizes[] = {
51909+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
51910+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
51911+ 4194301, 8388593, 16777213, 33554393, 67108859
51912+ };
51913+ void *newtable = NULL;
51914+ unsigned int pwr = 0;
51915+
51916+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
51917+ table_sizes[pwr] <= *len)
51918+ pwr++;
51919+
51920+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
51921+ return newtable;
51922+
51923+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
51924+ newtable =
51925+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
51926+ else
51927+ newtable = vmalloc(table_sizes[pwr] * elementsize);
51928+
51929+ *len = table_sizes[pwr];
51930+
51931+ return newtable;
51932+}
51933+
51934+static int
51935+init_variables(const struct gr_arg *arg)
51936+{
51937+ struct task_struct *reaper = init_pid_ns.child_reaper;
51938+ unsigned int stacksize;
51939+
51940+ subj_map_set.s_size = arg->role_db.num_subjects;
51941+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
51942+ name_set.n_size = arg->role_db.num_objects;
51943+ inodev_set.i_size = arg->role_db.num_objects;
51944+
51945+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
51946+ !name_set.n_size || !inodev_set.i_size)
51947+ return 1;
51948+
51949+ if (!gr_init_uidset())
51950+ return 1;
51951+
51952+ /* set up the stack that holds allocation info */
51953+
51954+ stacksize = arg->role_db.num_pointers + 5;
51955+
51956+ if (!acl_alloc_stack_init(stacksize))
51957+ return 1;
51958+
51959+ /* grab reference for the real root dentry and vfsmount */
51960+ get_fs_root(reaper->fs, &real_root);
51961+
51962+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51963+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
51964+#endif
51965+
51966+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
51967+ if (fakefs_obj_rw == NULL)
51968+ return 1;
51969+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
51970+
51971+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
51972+ if (fakefs_obj_rwx == NULL)
51973+ return 1;
51974+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
51975+
51976+ subj_map_set.s_hash =
51977+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
51978+ acl_role_set.r_hash =
51979+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
51980+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
51981+ inodev_set.i_hash =
51982+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
51983+
51984+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
51985+ !name_set.n_hash || !inodev_set.i_hash)
51986+ return 1;
51987+
51988+ memset(subj_map_set.s_hash, 0,
51989+ sizeof(struct subject_map *) * subj_map_set.s_size);
51990+ memset(acl_role_set.r_hash, 0,
51991+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
51992+ memset(name_set.n_hash, 0,
51993+ sizeof (struct name_entry *) * name_set.n_size);
51994+ memset(inodev_set.i_hash, 0,
51995+ sizeof (struct inodev_entry *) * inodev_set.i_size);
51996+
51997+ return 0;
51998+}
51999+
52000+/* free information not needed after startup
52001+ currently contains user->kernel pointer mappings for subjects
52002+*/
52003+
52004+static void
52005+free_init_variables(void)
52006+{
52007+ __u32 i;
52008+
52009+ if (subj_map_set.s_hash) {
52010+ for (i = 0; i < subj_map_set.s_size; i++) {
52011+ if (subj_map_set.s_hash[i]) {
52012+ kfree(subj_map_set.s_hash[i]);
52013+ subj_map_set.s_hash[i] = NULL;
52014+ }
52015+ }
52016+
52017+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
52018+ PAGE_SIZE)
52019+ kfree(subj_map_set.s_hash);
52020+ else
52021+ vfree(subj_map_set.s_hash);
52022+ }
52023+
52024+ return;
52025+}
52026+
52027+static void
52028+free_variables(void)
52029+{
52030+ struct acl_subject_label *s;
52031+ struct acl_role_label *r;
52032+ struct task_struct *task, *task2;
52033+ unsigned int x;
52034+
52035+ gr_clear_learn_entries();
52036+
52037+ read_lock(&tasklist_lock);
52038+ do_each_thread(task2, task) {
52039+ task->acl_sp_role = 0;
52040+ task->acl_role_id = 0;
52041+ task->acl = NULL;
52042+ task->role = NULL;
52043+ } while_each_thread(task2, task);
52044+ read_unlock(&tasklist_lock);
52045+
52046+ /* release the reference to the real root dentry and vfsmount */
52047+ path_put(&real_root);
52048+ memset(&real_root, 0, sizeof(real_root));
52049+
52050+ /* free all object hash tables */
52051+
52052+ FOR_EACH_ROLE_START(r)
52053+ if (r->subj_hash == NULL)
52054+ goto next_role;
52055+ FOR_EACH_SUBJECT_START(r, s, x)
52056+ if (s->obj_hash == NULL)
52057+ break;
52058+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52059+ kfree(s->obj_hash);
52060+ else
52061+ vfree(s->obj_hash);
52062+ FOR_EACH_SUBJECT_END(s, x)
52063+ FOR_EACH_NESTED_SUBJECT_START(r, s)
52064+ if (s->obj_hash == NULL)
52065+ break;
52066+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52067+ kfree(s->obj_hash);
52068+ else
52069+ vfree(s->obj_hash);
52070+ FOR_EACH_NESTED_SUBJECT_END(s)
52071+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
52072+ kfree(r->subj_hash);
52073+ else
52074+ vfree(r->subj_hash);
52075+ r->subj_hash = NULL;
52076+next_role:
52077+ FOR_EACH_ROLE_END(r)
52078+
52079+ acl_free_all();
52080+
52081+ if (acl_role_set.r_hash) {
52082+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
52083+ PAGE_SIZE)
52084+ kfree(acl_role_set.r_hash);
52085+ else
52086+ vfree(acl_role_set.r_hash);
52087+ }
52088+ if (name_set.n_hash) {
52089+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
52090+ PAGE_SIZE)
52091+ kfree(name_set.n_hash);
52092+ else
52093+ vfree(name_set.n_hash);
52094+ }
52095+
52096+ if (inodev_set.i_hash) {
52097+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
52098+ PAGE_SIZE)
52099+ kfree(inodev_set.i_hash);
52100+ else
52101+ vfree(inodev_set.i_hash);
52102+ }
52103+
52104+ gr_free_uidset();
52105+
52106+ memset(&name_set, 0, sizeof (struct name_db));
52107+ memset(&inodev_set, 0, sizeof (struct inodev_db));
52108+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52109+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52110+
52111+ default_role = NULL;
52112+ kernel_role = NULL;
52113+ role_list = NULL;
52114+
52115+ return;
52116+}
52117+
52118+static __u32
52119+count_user_objs(struct acl_object_label *userp)
52120+{
52121+ struct acl_object_label o_tmp;
52122+ __u32 num = 0;
52123+
52124+ while (userp) {
52125+ if (copy_from_user(&o_tmp, userp,
52126+ sizeof (struct acl_object_label)))
52127+ break;
52128+
52129+ userp = o_tmp.prev;
52130+ num++;
52131+ }
52132+
52133+ return num;
52134+}
52135+
52136+static struct acl_subject_label *
52137+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
52138+
52139+static int
52140+copy_user_glob(struct acl_object_label *obj)
52141+{
52142+ struct acl_object_label *g_tmp, **guser;
52143+ unsigned int len;
52144+ char *tmp;
52145+
52146+ if (obj->globbed == NULL)
52147+ return 0;
52148+
52149+ guser = &obj->globbed;
52150+ while (*guser) {
52151+ g_tmp = (struct acl_object_label *)
52152+ acl_alloc(sizeof (struct acl_object_label));
52153+ if (g_tmp == NULL)
52154+ return -ENOMEM;
52155+
52156+ if (copy_from_user(g_tmp, *guser,
52157+ sizeof (struct acl_object_label)))
52158+ return -EFAULT;
52159+
52160+ len = strnlen_user(g_tmp->filename, PATH_MAX);
52161+
52162+ if (!len || len >= PATH_MAX)
52163+ return -EINVAL;
52164+
52165+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52166+ return -ENOMEM;
52167+
52168+ if (copy_from_user(tmp, g_tmp->filename, len))
52169+ return -EFAULT;
52170+ tmp[len-1] = '\0';
52171+ g_tmp->filename = tmp;
52172+
52173+ *guser = g_tmp;
52174+ guser = &(g_tmp->next);
52175+ }
52176+
52177+ return 0;
52178+}
52179+
52180+static int
52181+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52182+ struct acl_role_label *role)
52183+{
52184+ struct acl_object_label *o_tmp;
52185+ unsigned int len;
52186+ int ret;
52187+ char *tmp;
52188+
52189+ while (userp) {
52190+ if ((o_tmp = (struct acl_object_label *)
52191+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
52192+ return -ENOMEM;
52193+
52194+ if (copy_from_user(o_tmp, userp,
52195+ sizeof (struct acl_object_label)))
52196+ return -EFAULT;
52197+
52198+ userp = o_tmp->prev;
52199+
52200+ len = strnlen_user(o_tmp->filename, PATH_MAX);
52201+
52202+ if (!len || len >= PATH_MAX)
52203+ return -EINVAL;
52204+
52205+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52206+ return -ENOMEM;
52207+
52208+ if (copy_from_user(tmp, o_tmp->filename, len))
52209+ return -EFAULT;
52210+ tmp[len-1] = '\0';
52211+ o_tmp->filename = tmp;
52212+
52213+ insert_acl_obj_label(o_tmp, subj);
52214+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52215+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52216+ return -ENOMEM;
52217+
52218+ ret = copy_user_glob(o_tmp);
52219+ if (ret)
52220+ return ret;
52221+
52222+ if (o_tmp->nested) {
52223+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
52224+ if (IS_ERR(o_tmp->nested))
52225+ return PTR_ERR(o_tmp->nested);
52226+
52227+ /* insert into nested subject list */
52228+ o_tmp->nested->next = role->hash->first;
52229+ role->hash->first = o_tmp->nested;
52230+ }
52231+ }
52232+
52233+ return 0;
52234+}
52235+
52236+static __u32
52237+count_user_subjs(struct acl_subject_label *userp)
52238+{
52239+ struct acl_subject_label s_tmp;
52240+ __u32 num = 0;
52241+
52242+ while (userp) {
52243+ if (copy_from_user(&s_tmp, userp,
52244+ sizeof (struct acl_subject_label)))
52245+ break;
52246+
52247+ userp = s_tmp.prev;
52248+ /* do not count nested subjects against this count, since
52249+ they are not included in the hash table, but are
52250+ attached to objects. We have already counted
52251+ the subjects in userspace for the allocation
52252+ stack
52253+ */
52254+ if (!(s_tmp.mode & GR_NESTED))
52255+ num++;
52256+ }
52257+
52258+ return num;
52259+}
52260+
52261+static int
52262+copy_user_allowedips(struct acl_role_label *rolep)
52263+{
52264+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52265+
52266+ ruserip = rolep->allowed_ips;
52267+
52268+ while (ruserip) {
52269+ rlast = rtmp;
52270+
52271+ if ((rtmp = (struct role_allowed_ip *)
52272+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52273+ return -ENOMEM;
52274+
52275+ if (copy_from_user(rtmp, ruserip,
52276+ sizeof (struct role_allowed_ip)))
52277+ return -EFAULT;
52278+
52279+ ruserip = rtmp->prev;
52280+
52281+ if (!rlast) {
52282+ rtmp->prev = NULL;
52283+ rolep->allowed_ips = rtmp;
52284+ } else {
52285+ rlast->next = rtmp;
52286+ rtmp->prev = rlast;
52287+ }
52288+
52289+ if (!ruserip)
52290+ rtmp->next = NULL;
52291+ }
52292+
52293+ return 0;
52294+}
52295+
52296+static int
52297+copy_user_transitions(struct acl_role_label *rolep)
52298+{
52299+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
52300+
52301+ unsigned int len;
52302+ char *tmp;
52303+
52304+ rusertp = rolep->transitions;
52305+
52306+ while (rusertp) {
52307+ rlast = rtmp;
52308+
52309+ if ((rtmp = (struct role_transition *)
52310+ acl_alloc(sizeof (struct role_transition))) == NULL)
52311+ return -ENOMEM;
52312+
52313+ if (copy_from_user(rtmp, rusertp,
52314+ sizeof (struct role_transition)))
52315+ return -EFAULT;
52316+
52317+ rusertp = rtmp->prev;
52318+
52319+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52320+
52321+ if (!len || len >= GR_SPROLE_LEN)
52322+ return -EINVAL;
52323+
52324+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52325+ return -ENOMEM;
52326+
52327+ if (copy_from_user(tmp, rtmp->rolename, len))
52328+ return -EFAULT;
52329+ tmp[len-1] = '\0';
52330+ rtmp->rolename = tmp;
52331+
52332+ if (!rlast) {
52333+ rtmp->prev = NULL;
52334+ rolep->transitions = rtmp;
52335+ } else {
52336+ rlast->next = rtmp;
52337+ rtmp->prev = rlast;
52338+ }
52339+
52340+ if (!rusertp)
52341+ rtmp->next = NULL;
52342+ }
52343+
52344+ return 0;
52345+}
52346+
52347+static struct acl_subject_label *
52348+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
52349+{
52350+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
52351+ unsigned int len;
52352+ char *tmp;
52353+ __u32 num_objs;
52354+ struct acl_ip_label **i_tmp, *i_utmp2;
52355+ struct gr_hash_struct ghash;
52356+ struct subject_map *subjmap;
52357+ unsigned int i_num;
52358+ int err;
52359+
52360+ s_tmp = lookup_subject_map(userp);
52361+
52362+ /* we've already copied this subject into the kernel, just return
52363+ the reference to it, and don't copy it over again
52364+ */
52365+ if (s_tmp)
52366+ return(s_tmp);
52367+
52368+ if ((s_tmp = (struct acl_subject_label *)
52369+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
52370+ return ERR_PTR(-ENOMEM);
52371+
52372+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
52373+ if (subjmap == NULL)
52374+ return ERR_PTR(-ENOMEM);
52375+
52376+ subjmap->user = userp;
52377+ subjmap->kernel = s_tmp;
52378+ insert_subj_map_entry(subjmap);
52379+
52380+ if (copy_from_user(s_tmp, userp,
52381+ sizeof (struct acl_subject_label)))
52382+ return ERR_PTR(-EFAULT);
52383+
52384+ len = strnlen_user(s_tmp->filename, PATH_MAX);
52385+
52386+ if (!len || len >= PATH_MAX)
52387+ return ERR_PTR(-EINVAL);
52388+
52389+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52390+ return ERR_PTR(-ENOMEM);
52391+
52392+ if (copy_from_user(tmp, s_tmp->filename, len))
52393+ return ERR_PTR(-EFAULT);
52394+ tmp[len-1] = '\0';
52395+ s_tmp->filename = tmp;
52396+
52397+ if (!strcmp(s_tmp->filename, "/"))
52398+ role->root_label = s_tmp;
52399+
52400+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
52401+ return ERR_PTR(-EFAULT);
52402+
52403+ /* copy user and group transition tables */
52404+
52405+ if (s_tmp->user_trans_num) {
52406+ uid_t *uidlist;
52407+
52408+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
52409+ if (uidlist == NULL)
52410+ return ERR_PTR(-ENOMEM);
52411+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
52412+ return ERR_PTR(-EFAULT);
52413+
52414+ s_tmp->user_transitions = uidlist;
52415+ }
52416+
52417+ if (s_tmp->group_trans_num) {
52418+ gid_t *gidlist;
52419+
52420+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
52421+ if (gidlist == NULL)
52422+ return ERR_PTR(-ENOMEM);
52423+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
52424+ return ERR_PTR(-EFAULT);
52425+
52426+ s_tmp->group_transitions = gidlist;
52427+ }
52428+
52429+ /* set up object hash table */
52430+ num_objs = count_user_objs(ghash.first);
52431+
52432+ s_tmp->obj_hash_size = num_objs;
52433+ s_tmp->obj_hash =
52434+ (struct acl_object_label **)
52435+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
52436+
52437+ if (!s_tmp->obj_hash)
52438+ return ERR_PTR(-ENOMEM);
52439+
52440+ memset(s_tmp->obj_hash, 0,
52441+ s_tmp->obj_hash_size *
52442+ sizeof (struct acl_object_label *));
52443+
52444+ /* add in objects */
52445+ err = copy_user_objs(ghash.first, s_tmp, role);
52446+
52447+ if (err)
52448+ return ERR_PTR(err);
52449+
52450+ /* set pointer for parent subject */
52451+ if (s_tmp->parent_subject) {
52452+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
52453+
52454+ if (IS_ERR(s_tmp2))
52455+ return s_tmp2;
52456+
52457+ s_tmp->parent_subject = s_tmp2;
52458+ }
52459+
52460+ /* add in ip acls */
52461+
52462+ if (!s_tmp->ip_num) {
52463+ s_tmp->ips = NULL;
52464+ goto insert;
52465+ }
52466+
52467+ i_tmp =
52468+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
52469+ sizeof (struct acl_ip_label *));
52470+
52471+ if (!i_tmp)
52472+ return ERR_PTR(-ENOMEM);
52473+
52474+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
52475+ *(i_tmp + i_num) =
52476+ (struct acl_ip_label *)
52477+ acl_alloc(sizeof (struct acl_ip_label));
52478+ if (!*(i_tmp + i_num))
52479+ return ERR_PTR(-ENOMEM);
52480+
52481+ if (copy_from_user
52482+ (&i_utmp2, s_tmp->ips + i_num,
52483+ sizeof (struct acl_ip_label *)))
52484+ return ERR_PTR(-EFAULT);
52485+
52486+ if (copy_from_user
52487+ (*(i_tmp + i_num), i_utmp2,
52488+ sizeof (struct acl_ip_label)))
52489+ return ERR_PTR(-EFAULT);
52490+
52491+ if ((*(i_tmp + i_num))->iface == NULL)
52492+ continue;
52493+
52494+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
52495+ if (!len || len >= IFNAMSIZ)
52496+ return ERR_PTR(-EINVAL);
52497+ tmp = acl_alloc(len);
52498+ if (tmp == NULL)
52499+ return ERR_PTR(-ENOMEM);
52500+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
52501+ return ERR_PTR(-EFAULT);
52502+ (*(i_tmp + i_num))->iface = tmp;
52503+ }
52504+
52505+ s_tmp->ips = i_tmp;
52506+
52507+insert:
52508+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
52509+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
52510+ return ERR_PTR(-ENOMEM);
52511+
52512+ return s_tmp;
52513+}
52514+
52515+static int
52516+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
52517+{
52518+ struct acl_subject_label s_pre;
52519+ struct acl_subject_label * ret;
52520+ int err;
52521+
52522+ while (userp) {
52523+ if (copy_from_user(&s_pre, userp,
52524+ sizeof (struct acl_subject_label)))
52525+ return -EFAULT;
52526+
52527+ /* do not add nested subjects here, add
52528+ while parsing objects
52529+ */
52530+
52531+ if (s_pre.mode & GR_NESTED) {
52532+ userp = s_pre.prev;
52533+ continue;
52534+ }
52535+
52536+ ret = do_copy_user_subj(userp, role);
52537+
52538+ err = PTR_ERR(ret);
52539+ if (IS_ERR(ret))
52540+ return err;
52541+
52542+ insert_acl_subj_label(ret, role);
52543+
52544+ userp = s_pre.prev;
52545+ }
52546+
52547+ return 0;
52548+}
52549+
52550+static int
52551+copy_user_acl(struct gr_arg *arg)
52552+{
52553+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
52554+ struct sprole_pw *sptmp;
52555+ struct gr_hash_struct *ghash;
52556+ uid_t *domainlist;
52557+ unsigned int r_num;
52558+ unsigned int len;
52559+ char *tmp;
52560+ int err = 0;
52561+ __u16 i;
52562+ __u32 num_subjs;
52563+
52564+ /* we need a default and kernel role */
52565+ if (arg->role_db.num_roles < 2)
52566+ return -EINVAL;
52567+
52568+ /* copy special role authentication info from userspace */
52569+
52570+ num_sprole_pws = arg->num_sprole_pws;
52571+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
52572+
52573+ if (!acl_special_roles && num_sprole_pws)
52574+ return -ENOMEM;
52575+
52576+ for (i = 0; i < num_sprole_pws; i++) {
52577+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
52578+ if (!sptmp)
52579+ return -ENOMEM;
52580+ if (copy_from_user(sptmp, arg->sprole_pws + i,
52581+ sizeof (struct sprole_pw)))
52582+ return -EFAULT;
52583+
52584+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
52585+
52586+ if (!len || len >= GR_SPROLE_LEN)
52587+ return -EINVAL;
52588+
52589+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52590+ return -ENOMEM;
52591+
52592+ if (copy_from_user(tmp, sptmp->rolename, len))
52593+ return -EFAULT;
52594+
52595+ tmp[len-1] = '\0';
52596+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52597+ printk(KERN_ALERT "Copying special role %s\n", tmp);
52598+#endif
52599+ sptmp->rolename = tmp;
52600+ acl_special_roles[i] = sptmp;
52601+ }
52602+
52603+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
52604+
52605+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
52606+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
52607+
52608+ if (!r_tmp)
52609+ return -ENOMEM;
52610+
52611+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
52612+ sizeof (struct acl_role_label *)))
52613+ return -EFAULT;
52614+
52615+ if (copy_from_user(r_tmp, r_utmp2,
52616+ sizeof (struct acl_role_label)))
52617+ return -EFAULT;
52618+
52619+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
52620+
52621+ if (!len || len >= PATH_MAX)
52622+ return -EINVAL;
52623+
52624+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52625+ return -ENOMEM;
52626+
52627+ if (copy_from_user(tmp, r_tmp->rolename, len))
52628+ return -EFAULT;
52629+
52630+ tmp[len-1] = '\0';
52631+ r_tmp->rolename = tmp;
52632+
52633+ if (!strcmp(r_tmp->rolename, "default")
52634+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
52635+ default_role = r_tmp;
52636+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
52637+ kernel_role = r_tmp;
52638+ }
52639+
52640+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
52641+ return -ENOMEM;
52642+
52643+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
52644+ return -EFAULT;
52645+
52646+ r_tmp->hash = ghash;
52647+
52648+ num_subjs = count_user_subjs(r_tmp->hash->first);
52649+
52650+ r_tmp->subj_hash_size = num_subjs;
52651+ r_tmp->subj_hash =
52652+ (struct acl_subject_label **)
52653+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
52654+
52655+ if (!r_tmp->subj_hash)
52656+ return -ENOMEM;
52657+
52658+ err = copy_user_allowedips(r_tmp);
52659+ if (err)
52660+ return err;
52661+
52662+ /* copy domain info */
52663+ if (r_tmp->domain_children != NULL) {
52664+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
52665+ if (domainlist == NULL)
52666+ return -ENOMEM;
52667+
52668+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
52669+ return -EFAULT;
52670+
52671+ r_tmp->domain_children = domainlist;
52672+ }
52673+
52674+ err = copy_user_transitions(r_tmp);
52675+ if (err)
52676+ return err;
52677+
52678+ memset(r_tmp->subj_hash, 0,
52679+ r_tmp->subj_hash_size *
52680+ sizeof (struct acl_subject_label *));
52681+
52682+ err = copy_user_subjs(r_tmp->hash->first, r_tmp);
52683+
52684+ if (err)
52685+ return err;
52686+
52687+ /* set nested subject list to null */
52688+ r_tmp->hash->first = NULL;
52689+
52690+ insert_acl_role_label(r_tmp);
52691+ }
52692+
52693+ if (default_role == NULL || kernel_role == NULL)
52694+ return -EINVAL;
52695+
52696+ return err;
52697+}
52698+
52699+static int
52700+gracl_init(struct gr_arg *args)
52701+{
52702+ int error = 0;
52703+
52704+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
52705+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
52706+
52707+ if (init_variables(args)) {
52708+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
52709+ error = -ENOMEM;
52710+ free_variables();
52711+ goto out;
52712+ }
52713+
52714+ error = copy_user_acl(args);
52715+ free_init_variables();
52716+ if (error) {
52717+ free_variables();
52718+ goto out;
52719+ }
52720+
52721+ if ((error = gr_set_acls(0))) {
52722+ free_variables();
52723+ goto out;
52724+ }
52725+
52726+ pax_open_kernel();
52727+ gr_status |= GR_READY;
52728+ pax_close_kernel();
52729+
52730+ out:
52731+ return error;
52732+}
52733+
52734+/* derived from glibc fnmatch() 0: match, 1: no match*/
52735+
52736+static int
52737+glob_match(const char *p, const char *n)
52738+{
52739+ char c;
52740+
52741+ while ((c = *p++) != '\0') {
52742+ switch (c) {
52743+ case '?':
52744+ if (*n == '\0')
52745+ return 1;
52746+ else if (*n == '/')
52747+ return 1;
52748+ break;
52749+ case '\\':
52750+ if (*n != c)
52751+ return 1;
52752+ break;
52753+ case '*':
52754+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
52755+ if (*n == '/')
52756+ return 1;
52757+ else if (c == '?') {
52758+ if (*n == '\0')
52759+ return 1;
52760+ else
52761+ ++n;
52762+ }
52763+ }
52764+ if (c == '\0') {
52765+ return 0;
52766+ } else {
52767+ const char *endp;
52768+
52769+ if ((endp = strchr(n, '/')) == NULL)
52770+ endp = n + strlen(n);
52771+
52772+ if (c == '[') {
52773+ for (--p; n < endp; ++n)
52774+ if (!glob_match(p, n))
52775+ return 0;
52776+ } else if (c == '/') {
52777+ while (*n != '\0' && *n != '/')
52778+ ++n;
52779+ if (*n == '/' && !glob_match(p, n + 1))
52780+ return 0;
52781+ } else {
52782+ for (--p; n < endp; ++n)
52783+ if (*n == c && !glob_match(p, n))
52784+ return 0;
52785+ }
52786+
52787+ return 1;
52788+ }
52789+ case '[':
52790+ {
52791+ int not;
52792+ char cold;
52793+
52794+ if (*n == '\0' || *n == '/')
52795+ return 1;
52796+
52797+ not = (*p == '!' || *p == '^');
52798+ if (not)
52799+ ++p;
52800+
52801+ c = *p++;
52802+ for (;;) {
52803+ unsigned char fn = (unsigned char)*n;
52804+
52805+ if (c == '\0')
52806+ return 1;
52807+ else {
52808+ if (c == fn)
52809+ goto matched;
52810+ cold = c;
52811+ c = *p++;
52812+
52813+ if (c == '-' && *p != ']') {
52814+ unsigned char cend = *p++;
52815+
52816+ if (cend == '\0')
52817+ return 1;
52818+
52819+ if (cold <= fn && fn <= cend)
52820+ goto matched;
52821+
52822+ c = *p++;
52823+ }
52824+ }
52825+
52826+ if (c == ']')
52827+ break;
52828+ }
52829+ if (!not)
52830+ return 1;
52831+ break;
52832+ matched:
52833+ while (c != ']') {
52834+ if (c == '\0')
52835+ return 1;
52836+
52837+ c = *p++;
52838+ }
52839+ if (not)
52840+ return 1;
52841+ }
52842+ break;
52843+ default:
52844+ if (c != *n)
52845+ return 1;
52846+ }
52847+
52848+ ++n;
52849+ }
52850+
52851+ if (*n == '\0')
52852+ return 0;
52853+
52854+ if (*n == '/')
52855+ return 0;
52856+
52857+ return 1;
52858+}
52859+
52860+static struct acl_object_label *
52861+chk_glob_label(struct acl_object_label *globbed,
52862+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
52863+{
52864+ struct acl_object_label *tmp;
52865+
52866+ if (*path == NULL)
52867+ *path = gr_to_filename_nolock(dentry, mnt);
52868+
52869+ tmp = globbed;
52870+
52871+ while (tmp) {
52872+ if (!glob_match(tmp->filename, *path))
52873+ return tmp;
52874+ tmp = tmp->next;
52875+ }
52876+
52877+ return NULL;
52878+}
52879+
52880+static struct acl_object_label *
52881+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52882+ const ino_t curr_ino, const dev_t curr_dev,
52883+ const struct acl_subject_label *subj, char **path, const int checkglob)
52884+{
52885+ struct acl_subject_label *tmpsubj;
52886+ struct acl_object_label *retval;
52887+ struct acl_object_label *retval2;
52888+
52889+ tmpsubj = (struct acl_subject_label *) subj;
52890+ read_lock(&gr_inode_lock);
52891+ do {
52892+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
52893+ if (retval) {
52894+ if (checkglob && retval->globbed) {
52895+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
52896+ if (retval2)
52897+ retval = retval2;
52898+ }
52899+ break;
52900+ }
52901+ } while ((tmpsubj = tmpsubj->parent_subject));
52902+ read_unlock(&gr_inode_lock);
52903+
52904+ return retval;
52905+}
52906+
52907+static __inline__ struct acl_object_label *
52908+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52909+ struct dentry *curr_dentry,
52910+ const struct acl_subject_label *subj, char **path, const int checkglob)
52911+{
52912+ int newglob = checkglob;
52913+ ino_t inode;
52914+ dev_t device;
52915+
52916+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
52917+ as we don't want a / * rule to match instead of the / object
52918+ don't do this for create lookups that call this function though, since they're looking up
52919+ on the parent and thus need globbing checks on all paths
52920+ */
52921+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
52922+ newglob = GR_NO_GLOB;
52923+
52924+ spin_lock(&curr_dentry->d_lock);
52925+ inode = curr_dentry->d_inode->i_ino;
52926+ device = __get_dev(curr_dentry);
52927+ spin_unlock(&curr_dentry->d_lock);
52928+
52929+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
52930+}
52931+
52932+static struct acl_object_label *
52933+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52934+ const struct acl_subject_label *subj, char *path, const int checkglob)
52935+{
52936+ struct dentry *dentry = (struct dentry *) l_dentry;
52937+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52938+ struct mount *real_mnt = real_mount(mnt);
52939+ struct acl_object_label *retval;
52940+ struct dentry *parent;
52941+
52942+ write_seqlock(&rename_lock);
52943+ br_read_lock(&vfsmount_lock);
52944+
52945+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
52946+#ifdef CONFIG_NET
52947+ mnt == sock_mnt ||
52948+#endif
52949+#ifdef CONFIG_HUGETLBFS
52950+ (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
52951+#endif
52952+ /* ignore Eric Biederman */
52953+ IS_PRIVATE(l_dentry->d_inode))) {
52954+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
52955+ goto out;
52956+ }
52957+
52958+ for (;;) {
52959+ if (dentry == real_root.dentry && mnt == real_root.mnt)
52960+ break;
52961+
52962+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52963+ if (!mnt_has_parent(real_mnt))
52964+ break;
52965+
52966+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52967+ if (retval != NULL)
52968+ goto out;
52969+
52970+ dentry = real_mnt->mnt_mountpoint;
52971+ real_mnt = real_mnt->mnt_parent;
52972+ mnt = &real_mnt->mnt;
52973+ continue;
52974+ }
52975+
52976+ parent = dentry->d_parent;
52977+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52978+ if (retval != NULL)
52979+ goto out;
52980+
52981+ dentry = parent;
52982+ }
52983+
52984+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52985+
52986+ /* real_root is pinned so we don't have to hold a reference */
52987+ if (retval == NULL)
52988+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
52989+out:
52990+ br_read_unlock(&vfsmount_lock);
52991+ write_sequnlock(&rename_lock);
52992+
52993+ BUG_ON(retval == NULL);
52994+
52995+ return retval;
52996+}
52997+
52998+static __inline__ struct acl_object_label *
52999+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53000+ const struct acl_subject_label *subj)
53001+{
53002+ char *path = NULL;
53003+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
53004+}
53005+
53006+static __inline__ struct acl_object_label *
53007+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53008+ const struct acl_subject_label *subj)
53009+{
53010+ char *path = NULL;
53011+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
53012+}
53013+
53014+static __inline__ struct acl_object_label *
53015+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53016+ const struct acl_subject_label *subj, char *path)
53017+{
53018+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
53019+}
53020+
53021+static struct acl_subject_label *
53022+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53023+ const struct acl_role_label *role)
53024+{
53025+ struct dentry *dentry = (struct dentry *) l_dentry;
53026+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53027+ struct mount *real_mnt = real_mount(mnt);
53028+ struct acl_subject_label *retval;
53029+ struct dentry *parent;
53030+
53031+ write_seqlock(&rename_lock);
53032+ br_read_lock(&vfsmount_lock);
53033+
53034+ for (;;) {
53035+ if (dentry == real_root.dentry && mnt == real_root.mnt)
53036+ break;
53037+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53038+ if (!mnt_has_parent(real_mnt))
53039+ break;
53040+
53041+ spin_lock(&dentry->d_lock);
53042+ read_lock(&gr_inode_lock);
53043+ retval =
53044+ lookup_acl_subj_label(dentry->d_inode->i_ino,
53045+ __get_dev(dentry), role);
53046+ read_unlock(&gr_inode_lock);
53047+ spin_unlock(&dentry->d_lock);
53048+ if (retval != NULL)
53049+ goto out;
53050+
53051+ dentry = real_mnt->mnt_mountpoint;
53052+ real_mnt = real_mnt->mnt_parent;
53053+ mnt = &real_mnt->mnt;
53054+ continue;
53055+ }
53056+
53057+ spin_lock(&dentry->d_lock);
53058+ read_lock(&gr_inode_lock);
53059+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53060+ __get_dev(dentry), role);
53061+ read_unlock(&gr_inode_lock);
53062+ parent = dentry->d_parent;
53063+ spin_unlock(&dentry->d_lock);
53064+
53065+ if (retval != NULL)
53066+ goto out;
53067+
53068+ dentry = parent;
53069+ }
53070+
53071+ spin_lock(&dentry->d_lock);
53072+ read_lock(&gr_inode_lock);
53073+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53074+ __get_dev(dentry), role);
53075+ read_unlock(&gr_inode_lock);
53076+ spin_unlock(&dentry->d_lock);
53077+
53078+ if (unlikely(retval == NULL)) {
53079+ /* real_root is pinned, we don't need to hold a reference */
53080+ read_lock(&gr_inode_lock);
53081+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
53082+ __get_dev(real_root.dentry), role);
53083+ read_unlock(&gr_inode_lock);
53084+ }
53085+out:
53086+ br_read_unlock(&vfsmount_lock);
53087+ write_sequnlock(&rename_lock);
53088+
53089+ BUG_ON(retval == NULL);
53090+
53091+ return retval;
53092+}
53093+
53094+static void
53095+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
53096+{
53097+ struct task_struct *task = current;
53098+ const struct cred *cred = current_cred();
53099+
53100+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53101+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53102+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53103+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53104+
53105+ return;
53106+}
53107+
53108+static void
53109+gr_log_learn_id_change(const char type, const unsigned int real,
53110+ const unsigned int effective, const unsigned int fs)
53111+{
53112+ struct task_struct *task = current;
53113+ const struct cred *cred = current_cred();
53114+
53115+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53116+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53117+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53118+ type, real, effective, fs, &task->signal->saved_ip);
53119+
53120+ return;
53121+}
53122+
53123+__u32
53124+gr_search_file(const struct dentry * dentry, const __u32 mode,
53125+ const struct vfsmount * mnt)
53126+{
53127+ __u32 retval = mode;
53128+ struct acl_subject_label *curracl;
53129+ struct acl_object_label *currobj;
53130+
53131+ if (unlikely(!(gr_status & GR_READY)))
53132+ return (mode & ~GR_AUDITS);
53133+
53134+ curracl = current->acl;
53135+
53136+ currobj = chk_obj_label(dentry, mnt, curracl);
53137+ retval = currobj->mode & mode;
53138+
53139+ /* if we're opening a specified transfer file for writing
53140+ (e.g. /dev/initctl), then transfer our role to init
53141+ */
53142+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53143+ current->role->roletype & GR_ROLE_PERSIST)) {
53144+ struct task_struct *task = init_pid_ns.child_reaper;
53145+
53146+ if (task->role != current->role) {
53147+ task->acl_sp_role = 0;
53148+ task->acl_role_id = current->acl_role_id;
53149+ task->role = current->role;
53150+ rcu_read_lock();
53151+ read_lock(&grsec_exec_file_lock);
53152+ gr_apply_subject_to_task(task);
53153+ read_unlock(&grsec_exec_file_lock);
53154+ rcu_read_unlock();
53155+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53156+ }
53157+ }
53158+
53159+ if (unlikely
53160+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53161+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53162+ __u32 new_mode = mode;
53163+
53164+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53165+
53166+ retval = new_mode;
53167+
53168+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53169+ new_mode |= GR_INHERIT;
53170+
53171+ if (!(mode & GR_NOLEARN))
53172+ gr_log_learn(dentry, mnt, new_mode);
53173+ }
53174+
53175+ return retval;
53176+}
53177+
53178+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
53179+ const struct dentry *parent,
53180+ const struct vfsmount *mnt)
53181+{
53182+ struct name_entry *match;
53183+ struct acl_object_label *matchpo;
53184+ struct acl_subject_label *curracl;
53185+ char *path;
53186+
53187+ if (unlikely(!(gr_status & GR_READY)))
53188+ return NULL;
53189+
53190+ preempt_disable();
53191+ path = gr_to_filename_rbac(new_dentry, mnt);
53192+ match = lookup_name_entry_create(path);
53193+
53194+ curracl = current->acl;
53195+
53196+ if (match) {
53197+ read_lock(&gr_inode_lock);
53198+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53199+ read_unlock(&gr_inode_lock);
53200+
53201+ if (matchpo) {
53202+ preempt_enable();
53203+ return matchpo;
53204+ }
53205+ }
53206+
53207+ // lookup parent
53208+
53209+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53210+
53211+ preempt_enable();
53212+ return matchpo;
53213+}
53214+
53215+__u32
53216+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53217+ const struct vfsmount * mnt, const __u32 mode)
53218+{
53219+ struct acl_object_label *matchpo;
53220+ __u32 retval;
53221+
53222+ if (unlikely(!(gr_status & GR_READY)))
53223+ return (mode & ~GR_AUDITS);
53224+
53225+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
53226+
53227+ retval = matchpo->mode & mode;
53228+
53229+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53230+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53231+ __u32 new_mode = mode;
53232+
53233+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53234+
53235+ gr_log_learn(new_dentry, mnt, new_mode);
53236+ return new_mode;
53237+ }
53238+
53239+ return retval;
53240+}
53241+
53242+__u32
53243+gr_check_link(const struct dentry * new_dentry,
53244+ const struct dentry * parent_dentry,
53245+ const struct vfsmount * parent_mnt,
53246+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53247+{
53248+ struct acl_object_label *obj;
53249+ __u32 oldmode, newmode;
53250+ __u32 needmode;
53251+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
53252+ GR_DELETE | GR_INHERIT;
53253+
53254+ if (unlikely(!(gr_status & GR_READY)))
53255+ return (GR_CREATE | GR_LINK);
53256+
53257+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53258+ oldmode = obj->mode;
53259+
53260+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
53261+ newmode = obj->mode;
53262+
53263+ needmode = newmode & checkmodes;
53264+
53265+ // old name for hardlink must have at least the permissions of the new name
53266+ if ((oldmode & needmode) != needmode)
53267+ goto bad;
53268+
53269+ // if old name had restrictions/auditing, make sure the new name does as well
53270+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53271+
53272+ // don't allow hardlinking of suid/sgid/fcapped files without permission
53273+ if (is_privileged_binary(old_dentry))
53274+ needmode |= GR_SETID;
53275+
53276+ if ((newmode & needmode) != needmode)
53277+ goto bad;
53278+
53279+ // enforce minimum permissions
53280+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53281+ return newmode;
53282+bad:
53283+ needmode = oldmode;
53284+ if (is_privileged_binary(old_dentry))
53285+ needmode |= GR_SETID;
53286+
53287+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53288+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
53289+ return (GR_CREATE | GR_LINK);
53290+ } else if (newmode & GR_SUPPRESS)
53291+ return GR_SUPPRESS;
53292+ else
53293+ return 0;
53294+}
53295+
53296+int
53297+gr_check_hidden_task(const struct task_struct *task)
53298+{
53299+ if (unlikely(!(gr_status & GR_READY)))
53300+ return 0;
53301+
53302+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53303+ return 1;
53304+
53305+ return 0;
53306+}
53307+
53308+int
53309+gr_check_protected_task(const struct task_struct *task)
53310+{
53311+ if (unlikely(!(gr_status & GR_READY) || !task))
53312+ return 0;
53313+
53314+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53315+ task->acl != current->acl)
53316+ return 1;
53317+
53318+ return 0;
53319+}
53320+
53321+int
53322+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53323+{
53324+ struct task_struct *p;
53325+ int ret = 0;
53326+
53327+ if (unlikely(!(gr_status & GR_READY) || !pid))
53328+ return ret;
53329+
53330+ read_lock(&tasklist_lock);
53331+ do_each_pid_task(pid, type, p) {
53332+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53333+ p->acl != current->acl) {
53334+ ret = 1;
53335+ goto out;
53336+ }
53337+ } while_each_pid_task(pid, type, p);
53338+out:
53339+ read_unlock(&tasklist_lock);
53340+
53341+ return ret;
53342+}
53343+
53344+void
53345+gr_copy_label(struct task_struct *tsk)
53346+{
53347+ tsk->signal->used_accept = 0;
53348+ tsk->acl_sp_role = 0;
53349+ tsk->acl_role_id = current->acl_role_id;
53350+ tsk->acl = current->acl;
53351+ tsk->role = current->role;
53352+ tsk->signal->curr_ip = current->signal->curr_ip;
53353+ tsk->signal->saved_ip = current->signal->saved_ip;
53354+ if (current->exec_file)
53355+ get_file(current->exec_file);
53356+ tsk->exec_file = current->exec_file;
53357+ tsk->is_writable = current->is_writable;
53358+ if (unlikely(current->signal->used_accept)) {
53359+ current->signal->curr_ip = 0;
53360+ current->signal->saved_ip = 0;
53361+ }
53362+
53363+ return;
53364+}
53365+
53366+static void
53367+gr_set_proc_res(struct task_struct *task)
53368+{
53369+ struct acl_subject_label *proc;
53370+ unsigned short i;
53371+
53372+ proc = task->acl;
53373+
53374+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
53375+ return;
53376+
53377+ for (i = 0; i < RLIM_NLIMITS; i++) {
53378+ if (!(proc->resmask & (1 << i)))
53379+ continue;
53380+
53381+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
53382+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
53383+ }
53384+
53385+ return;
53386+}
53387+
53388+extern int __gr_process_user_ban(struct user_struct *user);
53389+
53390+int
53391+gr_check_user_change(int real, int effective, int fs)
53392+{
53393+ unsigned int i;
53394+ __u16 num;
53395+ uid_t *uidlist;
53396+ int curuid;
53397+ int realok = 0;
53398+ int effectiveok = 0;
53399+ int fsok = 0;
53400+
53401+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
53402+ struct user_struct *user;
53403+
53404+ if (real == -1)
53405+ goto skipit;
53406+
53407+ user = find_user(real);
53408+ if (user == NULL)
53409+ goto skipit;
53410+
53411+ if (__gr_process_user_ban(user)) {
53412+ /* for find_user */
53413+ free_uid(user);
53414+ return 1;
53415+ }
53416+
53417+ /* for find_user */
53418+ free_uid(user);
53419+
53420+skipit:
53421+#endif
53422+
53423+ if (unlikely(!(gr_status & GR_READY)))
53424+ return 0;
53425+
53426+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53427+ gr_log_learn_id_change('u', real, effective, fs);
53428+
53429+ num = current->acl->user_trans_num;
53430+ uidlist = current->acl->user_transitions;
53431+
53432+ if (uidlist == NULL)
53433+ return 0;
53434+
53435+ if (real == -1)
53436+ realok = 1;
53437+ if (effective == -1)
53438+ effectiveok = 1;
53439+ if (fs == -1)
53440+ fsok = 1;
53441+
53442+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
53443+ for (i = 0; i < num; i++) {
53444+ curuid = (int)uidlist[i];
53445+ if (real == curuid)
53446+ realok = 1;
53447+ if (effective == curuid)
53448+ effectiveok = 1;
53449+ if (fs == curuid)
53450+ fsok = 1;
53451+ }
53452+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
53453+ for (i = 0; i < num; i++) {
53454+ curuid = (int)uidlist[i];
53455+ if (real == curuid)
53456+ break;
53457+ if (effective == curuid)
53458+ break;
53459+ if (fs == curuid)
53460+ break;
53461+ }
53462+ /* not in deny list */
53463+ if (i == num) {
53464+ realok = 1;
53465+ effectiveok = 1;
53466+ fsok = 1;
53467+ }
53468+ }
53469+
53470+ if (realok && effectiveok && fsok)
53471+ return 0;
53472+ else {
53473+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53474+ return 1;
53475+ }
53476+}
53477+
53478+int
53479+gr_check_group_change(int real, int effective, int fs)
53480+{
53481+ unsigned int i;
53482+ __u16 num;
53483+ gid_t *gidlist;
53484+ int curgid;
53485+ int realok = 0;
53486+ int effectiveok = 0;
53487+ int fsok = 0;
53488+
53489+ if (unlikely(!(gr_status & GR_READY)))
53490+ return 0;
53491+
53492+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53493+ gr_log_learn_id_change('g', real, effective, fs);
53494+
53495+ num = current->acl->group_trans_num;
53496+ gidlist = current->acl->group_transitions;
53497+
53498+ if (gidlist == NULL)
53499+ return 0;
53500+
53501+ if (real == -1)
53502+ realok = 1;
53503+ if (effective == -1)
53504+ effectiveok = 1;
53505+ if (fs == -1)
53506+ fsok = 1;
53507+
53508+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
53509+ for (i = 0; i < num; i++) {
53510+ curgid = (int)gidlist[i];
53511+ if (real == curgid)
53512+ realok = 1;
53513+ if (effective == curgid)
53514+ effectiveok = 1;
53515+ if (fs == curgid)
53516+ fsok = 1;
53517+ }
53518+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
53519+ for (i = 0; i < num; i++) {
53520+ curgid = (int)gidlist[i];
53521+ if (real == curgid)
53522+ break;
53523+ if (effective == curgid)
53524+ break;
53525+ if (fs == curgid)
53526+ break;
53527+ }
53528+ /* not in deny list */
53529+ if (i == num) {
53530+ realok = 1;
53531+ effectiveok = 1;
53532+ fsok = 1;
53533+ }
53534+ }
53535+
53536+ if (realok && effectiveok && fsok)
53537+ return 0;
53538+ else {
53539+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53540+ return 1;
53541+ }
53542+}
53543+
53544+extern int gr_acl_is_capable(const int cap);
53545+
53546+void
53547+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
53548+{
53549+ struct acl_role_label *role = task->role;
53550+ struct acl_subject_label *subj = NULL;
53551+ struct acl_object_label *obj;
53552+ struct file *filp;
53553+
53554+ if (unlikely(!(gr_status & GR_READY)))
53555+ return;
53556+
53557+ filp = task->exec_file;
53558+
53559+ /* kernel process, we'll give them the kernel role */
53560+ if (unlikely(!filp)) {
53561+ task->role = kernel_role;
53562+ task->acl = kernel_role->root_label;
53563+ return;
53564+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
53565+ role = lookup_acl_role_label(task, uid, gid);
53566+
53567+ /* don't change the role if we're not a privileged process */
53568+ if (role && task->role != role &&
53569+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
53570+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
53571+ return;
53572+
53573+ /* perform subject lookup in possibly new role
53574+ we can use this result below in the case where role == task->role
53575+ */
53576+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
53577+
53578+ /* if we changed uid/gid, but result in the same role
53579+ and are using inheritance, don't lose the inherited subject
53580+ if current subject is other than what normal lookup
53581+ would result in, we arrived via inheritance, don't
53582+ lose subject
53583+ */
53584+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
53585+ (subj == task->acl)))
53586+ task->acl = subj;
53587+
53588+ task->role = role;
53589+
53590+ task->is_writable = 0;
53591+
53592+ /* ignore additional mmap checks for processes that are writable
53593+ by the default ACL */
53594+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53595+ if (unlikely(obj->mode & GR_WRITE))
53596+ task->is_writable = 1;
53597+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53598+ if (unlikely(obj->mode & GR_WRITE))
53599+ task->is_writable = 1;
53600+
53601+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53602+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53603+#endif
53604+
53605+ gr_set_proc_res(task);
53606+
53607+ return;
53608+}
53609+
53610+int
53611+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
53612+ const int unsafe_flags)
53613+{
53614+ struct task_struct *task = current;
53615+ struct acl_subject_label *newacl;
53616+ struct acl_object_label *obj;
53617+ __u32 retmode;
53618+
53619+ if (unlikely(!(gr_status & GR_READY)))
53620+ return 0;
53621+
53622+ newacl = chk_subj_label(dentry, mnt, task->role);
53623+
53624+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
53625+ did an exec
53626+ */
53627+ rcu_read_lock();
53628+ read_lock(&tasklist_lock);
53629+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
53630+ (task->parent->acl->mode & GR_POVERRIDE))) {
53631+ read_unlock(&tasklist_lock);
53632+ rcu_read_unlock();
53633+ goto skip_check;
53634+ }
53635+ read_unlock(&tasklist_lock);
53636+ rcu_read_unlock();
53637+
53638+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
53639+ !(task->role->roletype & GR_ROLE_GOD) &&
53640+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
53641+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53642+ if (unsafe_flags & LSM_UNSAFE_SHARE)
53643+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
53644+ else
53645+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
53646+ return -EACCES;
53647+ }
53648+
53649+skip_check:
53650+
53651+ obj = chk_obj_label(dentry, mnt, task->acl);
53652+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
53653+
53654+ if (!(task->acl->mode & GR_INHERITLEARN) &&
53655+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
53656+ if (obj->nested)
53657+ task->acl = obj->nested;
53658+ else
53659+ task->acl = newacl;
53660+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
53661+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
53662+
53663+ task->is_writable = 0;
53664+
53665+ /* ignore additional mmap checks for processes that are writable
53666+ by the default ACL */
53667+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
53668+ if (unlikely(obj->mode & GR_WRITE))
53669+ task->is_writable = 1;
53670+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
53671+ if (unlikely(obj->mode & GR_WRITE))
53672+ task->is_writable = 1;
53673+
53674+ gr_set_proc_res(task);
53675+
53676+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53677+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53678+#endif
53679+ return 0;
53680+}
53681+
53682+/* always called with valid inodev ptr */
53683+static void
53684+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
53685+{
53686+ struct acl_object_label *matchpo;
53687+ struct acl_subject_label *matchps;
53688+ struct acl_subject_label *subj;
53689+ struct acl_role_label *role;
53690+ unsigned int x;
53691+
53692+ FOR_EACH_ROLE_START(role)
53693+ FOR_EACH_SUBJECT_START(role, subj, x)
53694+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
53695+ matchpo->mode |= GR_DELETED;
53696+ FOR_EACH_SUBJECT_END(subj,x)
53697+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
53698+ if (subj->inode == ino && subj->device == dev)
53699+ subj->mode |= GR_DELETED;
53700+ FOR_EACH_NESTED_SUBJECT_END(subj)
53701+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
53702+ matchps->mode |= GR_DELETED;
53703+ FOR_EACH_ROLE_END(role)
53704+
53705+ inodev->nentry->deleted = 1;
53706+
53707+ return;
53708+}
53709+
53710+void
53711+gr_handle_delete(const ino_t ino, const dev_t dev)
53712+{
53713+ struct inodev_entry *inodev;
53714+
53715+ if (unlikely(!(gr_status & GR_READY)))
53716+ return;
53717+
53718+ write_lock(&gr_inode_lock);
53719+ inodev = lookup_inodev_entry(ino, dev);
53720+ if (inodev != NULL)
53721+ do_handle_delete(inodev, ino, dev);
53722+ write_unlock(&gr_inode_lock);
53723+
53724+ return;
53725+}
53726+
53727+static void
53728+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
53729+ const ino_t newinode, const dev_t newdevice,
53730+ struct acl_subject_label *subj)
53731+{
53732+ unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
53733+ struct acl_object_label *match;
53734+
53735+ match = subj->obj_hash[index];
53736+
53737+ while (match && (match->inode != oldinode ||
53738+ match->device != olddevice ||
53739+ !(match->mode & GR_DELETED)))
53740+ match = match->next;
53741+
53742+ if (match && (match->inode == oldinode)
53743+ && (match->device == olddevice)
53744+ && (match->mode & GR_DELETED)) {
53745+ if (match->prev == NULL) {
53746+ subj->obj_hash[index] = match->next;
53747+ if (match->next != NULL)
53748+ match->next->prev = NULL;
53749+ } else {
53750+ match->prev->next = match->next;
53751+ if (match->next != NULL)
53752+ match->next->prev = match->prev;
53753+ }
53754+ match->prev = NULL;
53755+ match->next = NULL;
53756+ match->inode = newinode;
53757+ match->device = newdevice;
53758+ match->mode &= ~GR_DELETED;
53759+
53760+ insert_acl_obj_label(match, subj);
53761+ }
53762+
53763+ return;
53764+}
53765+
53766+static void
53767+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
53768+ const ino_t newinode, const dev_t newdevice,
53769+ struct acl_role_label *role)
53770+{
53771+ unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
53772+ struct acl_subject_label *match;
53773+
53774+ match = role->subj_hash[index];
53775+
53776+ while (match && (match->inode != oldinode ||
53777+ match->device != olddevice ||
53778+ !(match->mode & GR_DELETED)))
53779+ match = match->next;
53780+
53781+ if (match && (match->inode == oldinode)
53782+ && (match->device == olddevice)
53783+ && (match->mode & GR_DELETED)) {
53784+ if (match->prev == NULL) {
53785+ role->subj_hash[index] = match->next;
53786+ if (match->next != NULL)
53787+ match->next->prev = NULL;
53788+ } else {
53789+ match->prev->next = match->next;
53790+ if (match->next != NULL)
53791+ match->next->prev = match->prev;
53792+ }
53793+ match->prev = NULL;
53794+ match->next = NULL;
53795+ match->inode = newinode;
53796+ match->device = newdevice;
53797+ match->mode &= ~GR_DELETED;
53798+
53799+ insert_acl_subj_label(match, role);
53800+ }
53801+
53802+ return;
53803+}
53804+
53805+static void
53806+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
53807+ const ino_t newinode, const dev_t newdevice)
53808+{
53809+ unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
53810+ struct inodev_entry *match;
53811+
53812+ match = inodev_set.i_hash[index];
53813+
53814+ while (match && (match->nentry->inode != oldinode ||
53815+ match->nentry->device != olddevice || !match->nentry->deleted))
53816+ match = match->next;
53817+
53818+ if (match && (match->nentry->inode == oldinode)
53819+ && (match->nentry->device == olddevice) &&
53820+ match->nentry->deleted) {
53821+ if (match->prev == NULL) {
53822+ inodev_set.i_hash[index] = match->next;
53823+ if (match->next != NULL)
53824+ match->next->prev = NULL;
53825+ } else {
53826+ match->prev->next = match->next;
53827+ if (match->next != NULL)
53828+ match->next->prev = match->prev;
53829+ }
53830+ match->prev = NULL;
53831+ match->next = NULL;
53832+ match->nentry->inode = newinode;
53833+ match->nentry->device = newdevice;
53834+ match->nentry->deleted = 0;
53835+
53836+ insert_inodev_entry(match);
53837+ }
53838+
53839+ return;
53840+}
53841+
53842+static void
53843+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
53844+{
53845+ struct acl_subject_label *subj;
53846+ struct acl_role_label *role;
53847+ unsigned int x;
53848+
53849+ FOR_EACH_ROLE_START(role)
53850+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
53851+
53852+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
53853+ if ((subj->inode == ino) && (subj->device == dev)) {
53854+ subj->inode = ino;
53855+ subj->device = dev;
53856+ }
53857+ FOR_EACH_NESTED_SUBJECT_END(subj)
53858+ FOR_EACH_SUBJECT_START(role, subj, x)
53859+ update_acl_obj_label(matchn->inode, matchn->device,
53860+ ino, dev, subj);
53861+ FOR_EACH_SUBJECT_END(subj,x)
53862+ FOR_EACH_ROLE_END(role)
53863+
53864+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
53865+
53866+ return;
53867+}
53868+
53869+static void
53870+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
53871+ const struct vfsmount *mnt)
53872+{
53873+ ino_t ino = dentry->d_inode->i_ino;
53874+ dev_t dev = __get_dev(dentry);
53875+
53876+ __do_handle_create(matchn, ino, dev);
53877+
53878+ return;
53879+}
53880+
53881+void
53882+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
53883+{
53884+ struct name_entry *matchn;
53885+
53886+ if (unlikely(!(gr_status & GR_READY)))
53887+ return;
53888+
53889+ preempt_disable();
53890+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
53891+
53892+ if (unlikely((unsigned long)matchn)) {
53893+ write_lock(&gr_inode_lock);
53894+ do_handle_create(matchn, dentry, mnt);
53895+ write_unlock(&gr_inode_lock);
53896+ }
53897+ preempt_enable();
53898+
53899+ return;
53900+}
53901+
53902+void
53903+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
53904+{
53905+ struct name_entry *matchn;
53906+
53907+ if (unlikely(!(gr_status & GR_READY)))
53908+ return;
53909+
53910+ preempt_disable();
53911+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
53912+
53913+ if (unlikely((unsigned long)matchn)) {
53914+ write_lock(&gr_inode_lock);
53915+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
53916+ write_unlock(&gr_inode_lock);
53917+ }
53918+ preempt_enable();
53919+
53920+ return;
53921+}
53922+
53923+void
53924+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
53925+ struct dentry *old_dentry,
53926+ struct dentry *new_dentry,
53927+ struct vfsmount *mnt, const __u8 replace)
53928+{
53929+ struct name_entry *matchn;
53930+ struct inodev_entry *inodev;
53931+ struct inode *inode = new_dentry->d_inode;
53932+ ino_t old_ino = old_dentry->d_inode->i_ino;
53933+ dev_t old_dev = __get_dev(old_dentry);
53934+
53935+ /* vfs_rename swaps the name and parent link for old_dentry and
53936+ new_dentry
53937+ at this point, old_dentry has the new name, parent link, and inode
53938+ for the renamed file
53939+ if a file is being replaced by a rename, new_dentry has the inode
53940+ and name for the replaced file
53941+ */
53942+
53943+ if (unlikely(!(gr_status & GR_READY)))
53944+ return;
53945+
53946+ preempt_disable();
53947+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
53948+
53949+ /* we wouldn't have to check d_inode if it weren't for
53950+ NFS silly-renaming
53951+ */
53952+
53953+ write_lock(&gr_inode_lock);
53954+ if (unlikely(replace && inode)) {
53955+ ino_t new_ino = inode->i_ino;
53956+ dev_t new_dev = __get_dev(new_dentry);
53957+
53958+ inodev = lookup_inodev_entry(new_ino, new_dev);
53959+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
53960+ do_handle_delete(inodev, new_ino, new_dev);
53961+ }
53962+
53963+ inodev = lookup_inodev_entry(old_ino, old_dev);
53964+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
53965+ do_handle_delete(inodev, old_ino, old_dev);
53966+
53967+ if (unlikely((unsigned long)matchn))
53968+ do_handle_create(matchn, old_dentry, mnt);
53969+
53970+ write_unlock(&gr_inode_lock);
53971+ preempt_enable();
53972+
53973+ return;
53974+}
53975+
53976+static int
53977+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
53978+ unsigned char **sum)
53979+{
53980+ struct acl_role_label *r;
53981+ struct role_allowed_ip *ipp;
53982+ struct role_transition *trans;
53983+ unsigned int i;
53984+ int found = 0;
53985+ u32 curr_ip = current->signal->curr_ip;
53986+
53987+ current->signal->saved_ip = curr_ip;
53988+
53989+ /* check transition table */
53990+
53991+ for (trans = current->role->transitions; trans; trans = trans->next) {
53992+ if (!strcmp(rolename, trans->rolename)) {
53993+ found = 1;
53994+ break;
53995+ }
53996+ }
53997+
53998+ if (!found)
53999+ return 0;
54000+
54001+ /* handle special roles that do not require authentication
54002+ and check ip */
54003+
54004+ FOR_EACH_ROLE_START(r)
54005+ if (!strcmp(rolename, r->rolename) &&
54006+ (r->roletype & GR_ROLE_SPECIAL)) {
54007+ found = 0;
54008+ if (r->allowed_ips != NULL) {
54009+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
54010+ if ((ntohl(curr_ip) & ipp->netmask) ==
54011+ (ntohl(ipp->addr) & ipp->netmask))
54012+ found = 1;
54013+ }
54014+ } else
54015+ found = 2;
54016+ if (!found)
54017+ return 0;
54018+
54019+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
54020+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
54021+ *salt = NULL;
54022+ *sum = NULL;
54023+ return 1;
54024+ }
54025+ }
54026+ FOR_EACH_ROLE_END(r)
54027+
54028+ for (i = 0; i < num_sprole_pws; i++) {
54029+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
54030+ *salt = acl_special_roles[i]->salt;
54031+ *sum = acl_special_roles[i]->sum;
54032+ return 1;
54033+ }
54034+ }
54035+
54036+ return 0;
54037+}
54038+
54039+static void
54040+assign_special_role(char *rolename)
54041+{
54042+ struct acl_object_label *obj;
54043+ struct acl_role_label *r;
54044+ struct acl_role_label *assigned = NULL;
54045+ struct task_struct *tsk;
54046+ struct file *filp;
54047+
54048+ FOR_EACH_ROLE_START(r)
54049+ if (!strcmp(rolename, r->rolename) &&
54050+ (r->roletype & GR_ROLE_SPECIAL)) {
54051+ assigned = r;
54052+ break;
54053+ }
54054+ FOR_EACH_ROLE_END(r)
54055+
54056+ if (!assigned)
54057+ return;
54058+
54059+ read_lock(&tasklist_lock);
54060+ read_lock(&grsec_exec_file_lock);
54061+
54062+ tsk = current->real_parent;
54063+ if (tsk == NULL)
54064+ goto out_unlock;
54065+
54066+ filp = tsk->exec_file;
54067+ if (filp == NULL)
54068+ goto out_unlock;
54069+
54070+ tsk->is_writable = 0;
54071+
54072+ tsk->acl_sp_role = 1;
54073+ tsk->acl_role_id = ++acl_sp_role_value;
54074+ tsk->role = assigned;
54075+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
54076+
54077+ /* ignore additional mmap checks for processes that are writable
54078+ by the default ACL */
54079+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54080+ if (unlikely(obj->mode & GR_WRITE))
54081+ tsk->is_writable = 1;
54082+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
54083+ if (unlikely(obj->mode & GR_WRITE))
54084+ tsk->is_writable = 1;
54085+
54086+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54087+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
54088+#endif
54089+
54090+out_unlock:
54091+ read_unlock(&grsec_exec_file_lock);
54092+ read_unlock(&tasklist_lock);
54093+ return;
54094+}
54095+
54096+int gr_check_secure_terminal(struct task_struct *task)
54097+{
54098+ struct task_struct *p, *p2, *p3;
54099+ struct files_struct *files;
54100+ struct fdtable *fdt;
54101+ struct file *our_file = NULL, *file;
54102+ int i;
54103+
54104+ if (task->signal->tty == NULL)
54105+ return 1;
54106+
54107+ files = get_files_struct(task);
54108+ if (files != NULL) {
54109+ rcu_read_lock();
54110+ fdt = files_fdtable(files);
54111+ for (i=0; i < fdt->max_fds; i++) {
54112+ file = fcheck_files(files, i);
54113+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54114+ get_file(file);
54115+ our_file = file;
54116+ }
54117+ }
54118+ rcu_read_unlock();
54119+ put_files_struct(files);
54120+ }
54121+
54122+ if (our_file == NULL)
54123+ return 1;
54124+
54125+ read_lock(&tasklist_lock);
54126+ do_each_thread(p2, p) {
54127+ files = get_files_struct(p);
54128+ if (files == NULL ||
54129+ (p->signal && p->signal->tty == task->signal->tty)) {
54130+ if (files != NULL)
54131+ put_files_struct(files);
54132+ continue;
54133+ }
54134+ rcu_read_lock();
54135+ fdt = files_fdtable(files);
54136+ for (i=0; i < fdt->max_fds; i++) {
54137+ file = fcheck_files(files, i);
54138+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54139+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54140+ p3 = task;
54141+ while (p3->pid > 0) {
54142+ if (p3 == p)
54143+ break;
54144+ p3 = p3->real_parent;
54145+ }
54146+ if (p3 == p)
54147+ break;
54148+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54149+ gr_handle_alertkill(p);
54150+ rcu_read_unlock();
54151+ put_files_struct(files);
54152+ read_unlock(&tasklist_lock);
54153+ fput(our_file);
54154+ return 0;
54155+ }
54156+ }
54157+ rcu_read_unlock();
54158+ put_files_struct(files);
54159+ } while_each_thread(p2, p);
54160+ read_unlock(&tasklist_lock);
54161+
54162+ fput(our_file);
54163+ return 1;
54164+}
54165+
54166+static int gr_rbac_disable(void *unused)
54167+{
54168+ pax_open_kernel();
54169+ gr_status &= ~GR_READY;
54170+ pax_close_kernel();
54171+
54172+ return 0;
54173+}
54174+
54175+ssize_t
54176+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54177+{
54178+ struct gr_arg_wrapper uwrap;
54179+ unsigned char *sprole_salt = NULL;
54180+ unsigned char *sprole_sum = NULL;
54181+ int error = sizeof (struct gr_arg_wrapper);
54182+ int error2 = 0;
54183+
54184+ mutex_lock(&gr_dev_mutex);
54185+
54186+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54187+ error = -EPERM;
54188+ goto out;
54189+ }
54190+
54191+ if (count != sizeof (struct gr_arg_wrapper)) {
54192+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54193+ error = -EINVAL;
54194+ goto out;
54195+ }
54196+
54197+
54198+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54199+ gr_auth_expires = 0;
54200+ gr_auth_attempts = 0;
54201+ }
54202+
54203+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54204+ error = -EFAULT;
54205+ goto out;
54206+ }
54207+
54208+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54209+ error = -EINVAL;
54210+ goto out;
54211+ }
54212+
54213+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54214+ error = -EFAULT;
54215+ goto out;
54216+ }
54217+
54218+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54219+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54220+ time_after(gr_auth_expires, get_seconds())) {
54221+ error = -EBUSY;
54222+ goto out;
54223+ }
54224+
54225+ /* if non-root trying to do anything other than use a special role,
54226+ do not attempt authentication, do not count towards authentication
54227+ locking
54228+ */
54229+
54230+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54231+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54232+ !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
54233+ error = -EPERM;
54234+ goto out;
54235+ }
54236+
54237+ /* ensure pw and special role name are null terminated */
54238+
54239+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54240+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54241+
54242+ /* Okay.
54243+ * We have our enough of the argument structure..(we have yet
54244+ * to copy_from_user the tables themselves) . Copy the tables
54245+ * only if we need them, i.e. for loading operations. */
54246+
54247+ switch (gr_usermode->mode) {
54248+ case GR_STATUS:
54249+ if (gr_status & GR_READY) {
54250+ error = 1;
54251+ if (!gr_check_secure_terminal(current))
54252+ error = 3;
54253+ } else
54254+ error = 2;
54255+ goto out;
54256+ case GR_SHUTDOWN:
54257+ if ((gr_status & GR_READY)
54258+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54259+ stop_machine(gr_rbac_disable, NULL, NULL);
54260+ free_variables();
54261+ memset(gr_usermode, 0, sizeof (struct gr_arg));
54262+ memset(gr_system_salt, 0, GR_SALT_LEN);
54263+ memset(gr_system_sum, 0, GR_SHA_LEN);
54264+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54265+ } else if (gr_status & GR_READY) {
54266+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54267+ error = -EPERM;
54268+ } else {
54269+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54270+ error = -EAGAIN;
54271+ }
54272+ break;
54273+ case GR_ENABLE:
54274+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54275+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54276+ else {
54277+ if (gr_status & GR_READY)
54278+ error = -EAGAIN;
54279+ else
54280+ error = error2;
54281+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54282+ }
54283+ break;
54284+ case GR_RELOAD:
54285+ if (!(gr_status & GR_READY)) {
54286+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54287+ error = -EAGAIN;
54288+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54289+ stop_machine(gr_rbac_disable, NULL, NULL);
54290+ free_variables();
54291+ error2 = gracl_init(gr_usermode);
54292+ if (!error2)
54293+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54294+ else {
54295+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54296+ error = error2;
54297+ }
54298+ } else {
54299+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54300+ error = -EPERM;
54301+ }
54302+ break;
54303+ case GR_SEGVMOD:
54304+ if (unlikely(!(gr_status & GR_READY))) {
54305+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54306+ error = -EAGAIN;
54307+ break;
54308+ }
54309+
54310+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54311+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54312+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
54313+ struct acl_subject_label *segvacl;
54314+ segvacl =
54315+ lookup_acl_subj_label(gr_usermode->segv_inode,
54316+ gr_usermode->segv_device,
54317+ current->role);
54318+ if (segvacl) {
54319+ segvacl->crashes = 0;
54320+ segvacl->expires = 0;
54321+ }
54322+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
54323+ gr_remove_uid(gr_usermode->segv_uid);
54324+ }
54325+ } else {
54326+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
54327+ error = -EPERM;
54328+ }
54329+ break;
54330+ case GR_SPROLE:
54331+ case GR_SPROLEPAM:
54332+ if (unlikely(!(gr_status & GR_READY))) {
54333+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
54334+ error = -EAGAIN;
54335+ break;
54336+ }
54337+
54338+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
54339+ current->role->expires = 0;
54340+ current->role->auth_attempts = 0;
54341+ }
54342+
54343+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54344+ time_after(current->role->expires, get_seconds())) {
54345+ error = -EBUSY;
54346+ goto out;
54347+ }
54348+
54349+ if (lookup_special_role_auth
54350+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
54351+ && ((!sprole_salt && !sprole_sum)
54352+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
54353+ char *p = "";
54354+ assign_special_role(gr_usermode->sp_role);
54355+ read_lock(&tasklist_lock);
54356+ if (current->real_parent)
54357+ p = current->real_parent->role->rolename;
54358+ read_unlock(&tasklist_lock);
54359+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
54360+ p, acl_sp_role_value);
54361+ } else {
54362+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
54363+ error = -EPERM;
54364+ if(!(current->role->auth_attempts++))
54365+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54366+
54367+ goto out;
54368+ }
54369+ break;
54370+ case GR_UNSPROLE:
54371+ if (unlikely(!(gr_status & GR_READY))) {
54372+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
54373+ error = -EAGAIN;
54374+ break;
54375+ }
54376+
54377+ if (current->role->roletype & GR_ROLE_SPECIAL) {
54378+ char *p = "";
54379+ int i = 0;
54380+
54381+ read_lock(&tasklist_lock);
54382+ if (current->real_parent) {
54383+ p = current->real_parent->role->rolename;
54384+ i = current->real_parent->acl_role_id;
54385+ }
54386+ read_unlock(&tasklist_lock);
54387+
54388+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
54389+ gr_set_acls(1);
54390+ } else {
54391+ error = -EPERM;
54392+ goto out;
54393+ }
54394+ break;
54395+ default:
54396+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
54397+ error = -EINVAL;
54398+ break;
54399+ }
54400+
54401+ if (error != -EPERM)
54402+ goto out;
54403+
54404+ if(!(gr_auth_attempts++))
54405+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54406+
54407+ out:
54408+ mutex_unlock(&gr_dev_mutex);
54409+ return error;
54410+}
54411+
54412+/* must be called with
54413+ rcu_read_lock();
54414+ read_lock(&tasklist_lock);
54415+ read_lock(&grsec_exec_file_lock);
54416+*/
54417+int gr_apply_subject_to_task(struct task_struct *task)
54418+{
54419+ struct acl_object_label *obj;
54420+ char *tmpname;
54421+ struct acl_subject_label *tmpsubj;
54422+ struct file *filp;
54423+ struct name_entry *nmatch;
54424+
54425+ filp = task->exec_file;
54426+ if (filp == NULL)
54427+ return 0;
54428+
54429+ /* the following is to apply the correct subject
54430+ on binaries running when the RBAC system
54431+ is enabled, when the binaries have been
54432+ replaced or deleted since their execution
54433+ -----
54434+ when the RBAC system starts, the inode/dev
54435+ from exec_file will be one the RBAC system
54436+ is unaware of. It only knows the inode/dev
54437+ of the present file on disk, or the absence
54438+ of it.
54439+ */
54440+ preempt_disable();
54441+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
54442+
54443+ nmatch = lookup_name_entry(tmpname);
54444+ preempt_enable();
54445+ tmpsubj = NULL;
54446+ if (nmatch) {
54447+ if (nmatch->deleted)
54448+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
54449+ else
54450+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
54451+ if (tmpsubj != NULL)
54452+ task->acl = tmpsubj;
54453+ }
54454+ if (tmpsubj == NULL)
54455+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
54456+ task->role);
54457+ if (task->acl) {
54458+ task->is_writable = 0;
54459+ /* ignore additional mmap checks for processes that are writable
54460+ by the default ACL */
54461+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54462+ if (unlikely(obj->mode & GR_WRITE))
54463+ task->is_writable = 1;
54464+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54465+ if (unlikely(obj->mode & GR_WRITE))
54466+ task->is_writable = 1;
54467+
54468+ gr_set_proc_res(task);
54469+
54470+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54471+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54472+#endif
54473+ } else {
54474+ return 1;
54475+ }
54476+
54477+ return 0;
54478+}
54479+
54480+int
54481+gr_set_acls(const int type)
54482+{
54483+ struct task_struct *task, *task2;
54484+ struct acl_role_label *role = current->role;
54485+ __u16 acl_role_id = current->acl_role_id;
54486+ const struct cred *cred;
54487+ int ret;
54488+
54489+ rcu_read_lock();
54490+ read_lock(&tasklist_lock);
54491+ read_lock(&grsec_exec_file_lock);
54492+ do_each_thread(task2, task) {
54493+ /* check to see if we're called from the exit handler,
54494+ if so, only replace ACLs that have inherited the admin
54495+ ACL */
54496+
54497+ if (type && (task->role != role ||
54498+ task->acl_role_id != acl_role_id))
54499+ continue;
54500+
54501+ task->acl_role_id = 0;
54502+ task->acl_sp_role = 0;
54503+
54504+ if (task->exec_file) {
54505+ cred = __task_cred(task);
54506+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
54507+ ret = gr_apply_subject_to_task(task);
54508+ if (ret) {
54509+ read_unlock(&grsec_exec_file_lock);
54510+ read_unlock(&tasklist_lock);
54511+ rcu_read_unlock();
54512+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
54513+ return ret;
54514+ }
54515+ } else {
54516+ // it's a kernel process
54517+ task->role = kernel_role;
54518+ task->acl = kernel_role->root_label;
54519+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
54520+ task->acl->mode &= ~GR_PROCFIND;
54521+#endif
54522+ }
54523+ } while_each_thread(task2, task);
54524+ read_unlock(&grsec_exec_file_lock);
54525+ read_unlock(&tasklist_lock);
54526+ rcu_read_unlock();
54527+
54528+ return 0;
54529+}
54530+
54531+void
54532+gr_learn_resource(const struct task_struct *task,
54533+ const int res, const unsigned long wanted, const int gt)
54534+{
54535+ struct acl_subject_label *acl;
54536+ const struct cred *cred;
54537+
54538+ if (unlikely((gr_status & GR_READY) &&
54539+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
54540+ goto skip_reslog;
54541+
54542+#ifdef CONFIG_GRKERNSEC_RESLOG
54543+ gr_log_resource(task, res, wanted, gt);
54544+#endif
54545+ skip_reslog:
54546+
54547+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
54548+ return;
54549+
54550+ acl = task->acl;
54551+
54552+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
54553+ !(acl->resmask & (1 << (unsigned short) res))))
54554+ return;
54555+
54556+ if (wanted >= acl->res[res].rlim_cur) {
54557+ unsigned long res_add;
54558+
54559+ res_add = wanted;
54560+ switch (res) {
54561+ case RLIMIT_CPU:
54562+ res_add += GR_RLIM_CPU_BUMP;
54563+ break;
54564+ case RLIMIT_FSIZE:
54565+ res_add += GR_RLIM_FSIZE_BUMP;
54566+ break;
54567+ case RLIMIT_DATA:
54568+ res_add += GR_RLIM_DATA_BUMP;
54569+ break;
54570+ case RLIMIT_STACK:
54571+ res_add += GR_RLIM_STACK_BUMP;
54572+ break;
54573+ case RLIMIT_CORE:
54574+ res_add += GR_RLIM_CORE_BUMP;
54575+ break;
54576+ case RLIMIT_RSS:
54577+ res_add += GR_RLIM_RSS_BUMP;
54578+ break;
54579+ case RLIMIT_NPROC:
54580+ res_add += GR_RLIM_NPROC_BUMP;
54581+ break;
54582+ case RLIMIT_NOFILE:
54583+ res_add += GR_RLIM_NOFILE_BUMP;
54584+ break;
54585+ case RLIMIT_MEMLOCK:
54586+ res_add += GR_RLIM_MEMLOCK_BUMP;
54587+ break;
54588+ case RLIMIT_AS:
54589+ res_add += GR_RLIM_AS_BUMP;
54590+ break;
54591+ case RLIMIT_LOCKS:
54592+ res_add += GR_RLIM_LOCKS_BUMP;
54593+ break;
54594+ case RLIMIT_SIGPENDING:
54595+ res_add += GR_RLIM_SIGPENDING_BUMP;
54596+ break;
54597+ case RLIMIT_MSGQUEUE:
54598+ res_add += GR_RLIM_MSGQUEUE_BUMP;
54599+ break;
54600+ case RLIMIT_NICE:
54601+ res_add += GR_RLIM_NICE_BUMP;
54602+ break;
54603+ case RLIMIT_RTPRIO:
54604+ res_add += GR_RLIM_RTPRIO_BUMP;
54605+ break;
54606+ case RLIMIT_RTTIME:
54607+ res_add += GR_RLIM_RTTIME_BUMP;
54608+ break;
54609+ }
54610+
54611+ acl->res[res].rlim_cur = res_add;
54612+
54613+ if (wanted > acl->res[res].rlim_max)
54614+ acl->res[res].rlim_max = res_add;
54615+
54616+ /* only log the subject filename, since resource logging is supported for
54617+ single-subject learning only */
54618+ rcu_read_lock();
54619+ cred = __task_cred(task);
54620+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54621+ task->role->roletype, cred->uid, cred->gid, acl->filename,
54622+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
54623+ "", (unsigned long) res, &task->signal->saved_ip);
54624+ rcu_read_unlock();
54625+ }
54626+
54627+ return;
54628+}
54629+
54630+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
54631+void
54632+pax_set_initial_flags(struct linux_binprm *bprm)
54633+{
54634+ struct task_struct *task = current;
54635+ struct acl_subject_label *proc;
54636+ unsigned long flags;
54637+
54638+ if (unlikely(!(gr_status & GR_READY)))
54639+ return;
54640+
54641+ flags = pax_get_flags(task);
54642+
54643+ proc = task->acl;
54644+
54645+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
54646+ flags &= ~MF_PAX_PAGEEXEC;
54647+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
54648+ flags &= ~MF_PAX_SEGMEXEC;
54649+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
54650+ flags &= ~MF_PAX_RANDMMAP;
54651+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
54652+ flags &= ~MF_PAX_EMUTRAMP;
54653+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
54654+ flags &= ~MF_PAX_MPROTECT;
54655+
54656+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
54657+ flags |= MF_PAX_PAGEEXEC;
54658+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
54659+ flags |= MF_PAX_SEGMEXEC;
54660+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
54661+ flags |= MF_PAX_RANDMMAP;
54662+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
54663+ flags |= MF_PAX_EMUTRAMP;
54664+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
54665+ flags |= MF_PAX_MPROTECT;
54666+
54667+ pax_set_flags(task, flags);
54668+
54669+ return;
54670+}
54671+#endif
54672+
54673+int
54674+gr_handle_proc_ptrace(struct task_struct *task)
54675+{
54676+ struct file *filp;
54677+ struct task_struct *tmp = task;
54678+ struct task_struct *curtemp = current;
54679+ __u32 retmode;
54680+
54681+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54682+ if (unlikely(!(gr_status & GR_READY)))
54683+ return 0;
54684+#endif
54685+
54686+ read_lock(&tasklist_lock);
54687+ read_lock(&grsec_exec_file_lock);
54688+ filp = task->exec_file;
54689+
54690+ while (tmp->pid > 0) {
54691+ if (tmp == curtemp)
54692+ break;
54693+ tmp = tmp->real_parent;
54694+ }
54695+
54696+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
54697+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
54698+ read_unlock(&grsec_exec_file_lock);
54699+ read_unlock(&tasklist_lock);
54700+ return 1;
54701+ }
54702+
54703+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54704+ if (!(gr_status & GR_READY)) {
54705+ read_unlock(&grsec_exec_file_lock);
54706+ read_unlock(&tasklist_lock);
54707+ return 0;
54708+ }
54709+#endif
54710+
54711+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
54712+ read_unlock(&grsec_exec_file_lock);
54713+ read_unlock(&tasklist_lock);
54714+
54715+ if (retmode & GR_NOPTRACE)
54716+ return 1;
54717+
54718+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
54719+ && (current->acl != task->acl || (current->acl != current->role->root_label
54720+ && current->pid != task->pid)))
54721+ return 1;
54722+
54723+ return 0;
54724+}
54725+
54726+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
54727+{
54728+ if (unlikely(!(gr_status & GR_READY)))
54729+ return;
54730+
54731+ if (!(current->role->roletype & GR_ROLE_GOD))
54732+ return;
54733+
54734+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
54735+ p->role->rolename, gr_task_roletype_to_char(p),
54736+ p->acl->filename);
54737+}
54738+
54739+int
54740+gr_handle_ptrace(struct task_struct *task, const long request)
54741+{
54742+ struct task_struct *tmp = task;
54743+ struct task_struct *curtemp = current;
54744+ __u32 retmode;
54745+
54746+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54747+ if (unlikely(!(gr_status & GR_READY)))
54748+ return 0;
54749+#endif
54750+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
54751+ read_lock(&tasklist_lock);
54752+ while (tmp->pid > 0) {
54753+ if (tmp == curtemp)
54754+ break;
54755+ tmp = tmp->real_parent;
54756+ }
54757+
54758+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
54759+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
54760+ read_unlock(&tasklist_lock);
54761+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54762+ return 1;
54763+ }
54764+ read_unlock(&tasklist_lock);
54765+ }
54766+
54767+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54768+ if (!(gr_status & GR_READY))
54769+ return 0;
54770+#endif
54771+
54772+ read_lock(&grsec_exec_file_lock);
54773+ if (unlikely(!task->exec_file)) {
54774+ read_unlock(&grsec_exec_file_lock);
54775+ return 0;
54776+ }
54777+
54778+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
54779+ read_unlock(&grsec_exec_file_lock);
54780+
54781+ if (retmode & GR_NOPTRACE) {
54782+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54783+ return 1;
54784+ }
54785+
54786+ if (retmode & GR_PTRACERD) {
54787+ switch (request) {
54788+ case PTRACE_SEIZE:
54789+ case PTRACE_POKETEXT:
54790+ case PTRACE_POKEDATA:
54791+ case PTRACE_POKEUSR:
54792+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
54793+ case PTRACE_SETREGS:
54794+ case PTRACE_SETFPREGS:
54795+#endif
54796+#ifdef CONFIG_X86
54797+ case PTRACE_SETFPXREGS:
54798+#endif
54799+#ifdef CONFIG_ALTIVEC
54800+ case PTRACE_SETVRREGS:
54801+#endif
54802+ return 1;
54803+ default:
54804+ return 0;
54805+ }
54806+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
54807+ !(current->role->roletype & GR_ROLE_GOD) &&
54808+ (current->acl != task->acl)) {
54809+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54810+ return 1;
54811+ }
54812+
54813+ return 0;
54814+}
54815+
54816+static int is_writable_mmap(const struct file *filp)
54817+{
54818+ struct task_struct *task = current;
54819+ struct acl_object_label *obj, *obj2;
54820+
54821+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
54822+ !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))) {
54823+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54824+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
54825+ task->role->root_label);
54826+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
54827+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
54828+ return 1;
54829+ }
54830+ }
54831+ return 0;
54832+}
54833+
54834+int
54835+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
54836+{
54837+ __u32 mode;
54838+
54839+ if (unlikely(!file || !(prot & PROT_EXEC)))
54840+ return 1;
54841+
54842+ if (is_writable_mmap(file))
54843+ return 0;
54844+
54845+ mode =
54846+ gr_search_file(file->f_path.dentry,
54847+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54848+ file->f_path.mnt);
54849+
54850+ if (!gr_tpe_allow(file))
54851+ return 0;
54852+
54853+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54854+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54855+ return 0;
54856+ } else if (unlikely(!(mode & GR_EXEC))) {
54857+ return 0;
54858+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54859+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54860+ return 1;
54861+ }
54862+
54863+ return 1;
54864+}
54865+
54866+int
54867+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
54868+{
54869+ __u32 mode;
54870+
54871+ if (unlikely(!file || !(prot & PROT_EXEC)))
54872+ return 1;
54873+
54874+ if (is_writable_mmap(file))
54875+ return 0;
54876+
54877+ mode =
54878+ gr_search_file(file->f_path.dentry,
54879+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54880+ file->f_path.mnt);
54881+
54882+ if (!gr_tpe_allow(file))
54883+ return 0;
54884+
54885+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54886+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54887+ return 0;
54888+ } else if (unlikely(!(mode & GR_EXEC))) {
54889+ return 0;
54890+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54891+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54892+ return 1;
54893+ }
54894+
54895+ return 1;
54896+}
54897+
54898+void
54899+gr_acl_handle_psacct(struct task_struct *task, const long code)
54900+{
54901+ unsigned long runtime;
54902+ unsigned long cputime;
54903+ unsigned int wday, cday;
54904+ __u8 whr, chr;
54905+ __u8 wmin, cmin;
54906+ __u8 wsec, csec;
54907+ struct timespec timeval;
54908+
54909+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
54910+ !(task->acl->mode & GR_PROCACCT)))
54911+ return;
54912+
54913+ do_posix_clock_monotonic_gettime(&timeval);
54914+ runtime = timeval.tv_sec - task->start_time.tv_sec;
54915+ wday = runtime / (3600 * 24);
54916+ runtime -= wday * (3600 * 24);
54917+ whr = runtime / 3600;
54918+ runtime -= whr * 3600;
54919+ wmin = runtime / 60;
54920+ runtime -= wmin * 60;
54921+ wsec = runtime;
54922+
54923+ cputime = (task->utime + task->stime) / HZ;
54924+ cday = cputime / (3600 * 24);
54925+ cputime -= cday * (3600 * 24);
54926+ chr = cputime / 3600;
54927+ cputime -= chr * 3600;
54928+ cmin = cputime / 60;
54929+ cputime -= cmin * 60;
54930+ csec = cputime;
54931+
54932+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
54933+
54934+ return;
54935+}
54936+
54937+void gr_set_kernel_label(struct task_struct *task)
54938+{
54939+ if (gr_status & GR_READY) {
54940+ task->role = kernel_role;
54941+ task->acl = kernel_role->root_label;
54942+ }
54943+ return;
54944+}
54945+
54946+#ifdef CONFIG_TASKSTATS
54947+int gr_is_taskstats_denied(int pid)
54948+{
54949+ struct task_struct *task;
54950+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54951+ const struct cred *cred;
54952+#endif
54953+ int ret = 0;
54954+
54955+ /* restrict taskstats viewing to un-chrooted root users
54956+ who have the 'view' subject flag if the RBAC system is enabled
54957+ */
54958+
54959+ rcu_read_lock();
54960+ read_lock(&tasklist_lock);
54961+ task = find_task_by_vpid(pid);
54962+ if (task) {
54963+#ifdef CONFIG_GRKERNSEC_CHROOT
54964+ if (proc_is_chrooted(task))
54965+ ret = -EACCES;
54966+#endif
54967+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54968+ cred = __task_cred(task);
54969+#ifdef CONFIG_GRKERNSEC_PROC_USER
54970+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
54971+ ret = -EACCES;
54972+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54973+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
54974+ ret = -EACCES;
54975+#endif
54976+#endif
54977+ if (gr_status & GR_READY) {
54978+ if (!(task->acl->mode & GR_VIEW))
54979+ ret = -EACCES;
54980+ }
54981+ } else
54982+ ret = -ENOENT;
54983+
54984+ read_unlock(&tasklist_lock);
54985+ rcu_read_unlock();
54986+
54987+ return ret;
54988+}
54989+#endif
54990+
54991+/* AUXV entries are filled via a descendant of search_binary_handler
54992+ after we've already applied the subject for the target
54993+*/
54994+int gr_acl_enable_at_secure(void)
54995+{
54996+ if (unlikely(!(gr_status & GR_READY)))
54997+ return 0;
54998+
54999+ if (current->acl->mode & GR_ATSECURE)
55000+ return 1;
55001+
55002+ return 0;
55003+}
55004+
55005+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
55006+{
55007+ struct task_struct *task = current;
55008+ struct dentry *dentry = file->f_path.dentry;
55009+ struct vfsmount *mnt = file->f_path.mnt;
55010+ struct acl_object_label *obj, *tmp;
55011+ struct acl_subject_label *subj;
55012+ unsigned int bufsize;
55013+ int is_not_root;
55014+ char *path;
55015+ dev_t dev = __get_dev(dentry);
55016+
55017+ if (unlikely(!(gr_status & GR_READY)))
55018+ return 1;
55019+
55020+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55021+ return 1;
55022+
55023+ /* ignore Eric Biederman */
55024+ if (IS_PRIVATE(dentry->d_inode))
55025+ return 1;
55026+
55027+ subj = task->acl;
55028+ read_lock(&gr_inode_lock);
55029+ do {
55030+ obj = lookup_acl_obj_label(ino, dev, subj);
55031+ if (obj != NULL) {
55032+ read_unlock(&gr_inode_lock);
55033+ return (obj->mode & GR_FIND) ? 1 : 0;
55034+ }
55035+ } while ((subj = subj->parent_subject));
55036+ read_unlock(&gr_inode_lock);
55037+
55038+ /* this is purely an optimization since we're looking for an object
55039+ for the directory we're doing a readdir on
55040+ if it's possible for any globbed object to match the entry we're
55041+ filling into the directory, then the object we find here will be
55042+ an anchor point with attached globbed objects
55043+ */
55044+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
55045+ if (obj->globbed == NULL)
55046+ return (obj->mode & GR_FIND) ? 1 : 0;
55047+
55048+ is_not_root = ((obj->filename[0] == '/') &&
55049+ (obj->filename[1] == '\0')) ? 0 : 1;
55050+ bufsize = PAGE_SIZE - namelen - is_not_root;
55051+
55052+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
55053+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
55054+ return 1;
55055+
55056+ preempt_disable();
55057+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55058+ bufsize);
55059+
55060+ bufsize = strlen(path);
55061+
55062+ /* if base is "/", don't append an additional slash */
55063+ if (is_not_root)
55064+ *(path + bufsize) = '/';
55065+ memcpy(path + bufsize + is_not_root, name, namelen);
55066+ *(path + bufsize + namelen + is_not_root) = '\0';
55067+
55068+ tmp = obj->globbed;
55069+ while (tmp) {
55070+ if (!glob_match(tmp->filename, path)) {
55071+ preempt_enable();
55072+ return (tmp->mode & GR_FIND) ? 1 : 0;
55073+ }
55074+ tmp = tmp->next;
55075+ }
55076+ preempt_enable();
55077+ return (obj->mode & GR_FIND) ? 1 : 0;
55078+}
55079+
55080+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55081+EXPORT_SYMBOL(gr_acl_is_enabled);
55082+#endif
55083+EXPORT_SYMBOL(gr_learn_resource);
55084+EXPORT_SYMBOL(gr_set_kernel_label);
55085+#ifdef CONFIG_SECURITY
55086+EXPORT_SYMBOL(gr_check_user_change);
55087+EXPORT_SYMBOL(gr_check_group_change);
55088+#endif
55089+
55090diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
55091new file mode 100644
55092index 0000000..34fefda
55093--- /dev/null
55094+++ b/grsecurity/gracl_alloc.c
55095@@ -0,0 +1,105 @@
55096+#include <linux/kernel.h>
55097+#include <linux/mm.h>
55098+#include <linux/slab.h>
55099+#include <linux/vmalloc.h>
55100+#include <linux/gracl.h>
55101+#include <linux/grsecurity.h>
55102+
55103+static unsigned long alloc_stack_next = 1;
55104+static unsigned long alloc_stack_size = 1;
55105+static void **alloc_stack;
55106+
55107+static __inline__ int
55108+alloc_pop(void)
55109+{
55110+ if (alloc_stack_next == 1)
55111+ return 0;
55112+
55113+ kfree(alloc_stack[alloc_stack_next - 2]);
55114+
55115+ alloc_stack_next--;
55116+
55117+ return 1;
55118+}
55119+
55120+static __inline__ int
55121+alloc_push(void *buf)
55122+{
55123+ if (alloc_stack_next >= alloc_stack_size)
55124+ return 1;
55125+
55126+ alloc_stack[alloc_stack_next - 1] = buf;
55127+
55128+ alloc_stack_next++;
55129+
55130+ return 0;
55131+}
55132+
55133+void *
55134+acl_alloc(unsigned long len)
55135+{
55136+ void *ret = NULL;
55137+
55138+ if (!len || len > PAGE_SIZE)
55139+ goto out;
55140+
55141+ ret = kmalloc(len, GFP_KERNEL);
55142+
55143+ if (ret) {
55144+ if (alloc_push(ret)) {
55145+ kfree(ret);
55146+ ret = NULL;
55147+ }
55148+ }
55149+
55150+out:
55151+ return ret;
55152+}
55153+
55154+void *
55155+acl_alloc_num(unsigned long num, unsigned long len)
55156+{
55157+ if (!len || (num > (PAGE_SIZE / len)))
55158+ return NULL;
55159+
55160+ return acl_alloc(num * len);
55161+}
55162+
55163+void
55164+acl_free_all(void)
55165+{
55166+ if (gr_acl_is_enabled() || !alloc_stack)
55167+ return;
55168+
55169+ while (alloc_pop()) ;
55170+
55171+ if (alloc_stack) {
55172+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
55173+ kfree(alloc_stack);
55174+ else
55175+ vfree(alloc_stack);
55176+ }
55177+
55178+ alloc_stack = NULL;
55179+ alloc_stack_size = 1;
55180+ alloc_stack_next = 1;
55181+
55182+ return;
55183+}
55184+
55185+int
55186+acl_alloc_stack_init(unsigned long size)
55187+{
55188+ if ((size * sizeof (void *)) <= PAGE_SIZE)
55189+ alloc_stack =
55190+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
55191+ else
55192+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
55193+
55194+ alloc_stack_size = size;
55195+
55196+ if (!alloc_stack)
55197+ return 0;
55198+ else
55199+ return 1;
55200+}
55201diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
55202new file mode 100644
55203index 0000000..6d21049
55204--- /dev/null
55205+++ b/grsecurity/gracl_cap.c
55206@@ -0,0 +1,110 @@
55207+#include <linux/kernel.h>
55208+#include <linux/module.h>
55209+#include <linux/sched.h>
55210+#include <linux/gracl.h>
55211+#include <linux/grsecurity.h>
55212+#include <linux/grinternal.h>
55213+
55214+extern const char *captab_log[];
55215+extern int captab_log_entries;
55216+
55217+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
55218+{
55219+ struct acl_subject_label *curracl;
55220+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55221+ kernel_cap_t cap_audit = __cap_empty_set;
55222+
55223+ if (!gr_acl_is_enabled())
55224+ return 1;
55225+
55226+ curracl = task->acl;
55227+
55228+ cap_drop = curracl->cap_lower;
55229+ cap_mask = curracl->cap_mask;
55230+ cap_audit = curracl->cap_invert_audit;
55231+
55232+ while ((curracl = curracl->parent_subject)) {
55233+ /* if the cap isn't specified in the current computed mask but is specified in the
55234+ current level subject, and is lowered in the current level subject, then add
55235+ it to the set of dropped capabilities
55236+ otherwise, add the current level subject's mask to the current computed mask
55237+ */
55238+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55239+ cap_raise(cap_mask, cap);
55240+ if (cap_raised(curracl->cap_lower, cap))
55241+ cap_raise(cap_drop, cap);
55242+ if (cap_raised(curracl->cap_invert_audit, cap))
55243+ cap_raise(cap_audit, cap);
55244+ }
55245+ }
55246+
55247+ if (!cap_raised(cap_drop, cap)) {
55248+ if (cap_raised(cap_audit, cap))
55249+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55250+ return 1;
55251+ }
55252+
55253+ curracl = task->acl;
55254+
55255+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55256+ && cap_raised(cred->cap_effective, cap)) {
55257+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55258+ task->role->roletype, cred->uid,
55259+ cred->gid, task->exec_file ?
55260+ gr_to_filename(task->exec_file->f_path.dentry,
55261+ task->exec_file->f_path.mnt) : curracl->filename,
55262+ curracl->filename, 0UL,
55263+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55264+ return 1;
55265+ }
55266+
55267+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55268+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55269+
55270+ return 0;
55271+}
55272+
55273+int
55274+gr_acl_is_capable(const int cap)
55275+{
55276+ return gr_task_acl_is_capable(current, current_cred(), cap);
55277+}
55278+
55279+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
55280+{
55281+ struct acl_subject_label *curracl;
55282+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55283+
55284+ if (!gr_acl_is_enabled())
55285+ return 1;
55286+
55287+ curracl = task->acl;
55288+
55289+ cap_drop = curracl->cap_lower;
55290+ cap_mask = curracl->cap_mask;
55291+
55292+ while ((curracl = curracl->parent_subject)) {
55293+ /* if the cap isn't specified in the current computed mask but is specified in the
55294+ current level subject, and is lowered in the current level subject, then add
55295+ it to the set of dropped capabilities
55296+ otherwise, add the current level subject's mask to the current computed mask
55297+ */
55298+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55299+ cap_raise(cap_mask, cap);
55300+ if (cap_raised(curracl->cap_lower, cap))
55301+ cap_raise(cap_drop, cap);
55302+ }
55303+ }
55304+
55305+ if (!cap_raised(cap_drop, cap))
55306+ return 1;
55307+
55308+ return 0;
55309+}
55310+
55311+int
55312+gr_acl_is_capable_nolog(const int cap)
55313+{
55314+ return gr_task_acl_is_capable_nolog(current, cap);
55315+}
55316+
55317diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
55318new file mode 100644
55319index 0000000..d28e241
55320--- /dev/null
55321+++ b/grsecurity/gracl_fs.c
55322@@ -0,0 +1,437 @@
55323+#include <linux/kernel.h>
55324+#include <linux/sched.h>
55325+#include <linux/types.h>
55326+#include <linux/fs.h>
55327+#include <linux/file.h>
55328+#include <linux/stat.h>
55329+#include <linux/grsecurity.h>
55330+#include <linux/grinternal.h>
55331+#include <linux/gracl.h>
55332+
55333+umode_t
55334+gr_acl_umask(void)
55335+{
55336+ if (unlikely(!gr_acl_is_enabled()))
55337+ return 0;
55338+
55339+ return current->role->umask;
55340+}
55341+
55342+__u32
55343+gr_acl_handle_hidden_file(const struct dentry * dentry,
55344+ const struct vfsmount * mnt)
55345+{
55346+ __u32 mode;
55347+
55348+ if (unlikely(!dentry->d_inode))
55349+ return GR_FIND;
55350+
55351+ mode =
55352+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55353+
55354+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55355+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55356+ return mode;
55357+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55358+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55359+ return 0;
55360+ } else if (unlikely(!(mode & GR_FIND)))
55361+ return 0;
55362+
55363+ return GR_FIND;
55364+}
55365+
55366+__u32
55367+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55368+ int acc_mode)
55369+{
55370+ __u32 reqmode = GR_FIND;
55371+ __u32 mode;
55372+
55373+ if (unlikely(!dentry->d_inode))
55374+ return reqmode;
55375+
55376+ if (acc_mode & MAY_APPEND)
55377+ reqmode |= GR_APPEND;
55378+ else if (acc_mode & MAY_WRITE)
55379+ reqmode |= GR_WRITE;
55380+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
55381+ reqmode |= GR_READ;
55382+
55383+ mode =
55384+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55385+ mnt);
55386+
55387+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55388+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55389+ reqmode & GR_READ ? " reading" : "",
55390+ reqmode & GR_WRITE ? " writing" : reqmode &
55391+ GR_APPEND ? " appending" : "");
55392+ return reqmode;
55393+ } else
55394+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55395+ {
55396+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55397+ reqmode & GR_READ ? " reading" : "",
55398+ reqmode & GR_WRITE ? " writing" : reqmode &
55399+ GR_APPEND ? " appending" : "");
55400+ return 0;
55401+ } else if (unlikely((mode & reqmode) != reqmode))
55402+ return 0;
55403+
55404+ return reqmode;
55405+}
55406+
55407+__u32
55408+gr_acl_handle_creat(const struct dentry * dentry,
55409+ const struct dentry * p_dentry,
55410+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
55411+ const int imode)
55412+{
55413+ __u32 reqmode = GR_WRITE | GR_CREATE;
55414+ __u32 mode;
55415+
55416+ if (acc_mode & MAY_APPEND)
55417+ reqmode |= GR_APPEND;
55418+ // if a directory was required or the directory already exists, then
55419+ // don't count this open as a read
55420+ if ((acc_mode & MAY_READ) &&
55421+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
55422+ reqmode |= GR_READ;
55423+ if ((open_flags & O_CREAT) &&
55424+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
55425+ reqmode |= GR_SETID;
55426+
55427+ mode =
55428+ gr_check_create(dentry, p_dentry, p_mnt,
55429+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55430+
55431+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55432+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55433+ reqmode & GR_READ ? " reading" : "",
55434+ reqmode & GR_WRITE ? " writing" : reqmode &
55435+ GR_APPEND ? " appending" : "");
55436+ return reqmode;
55437+ } else
55438+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55439+ {
55440+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55441+ reqmode & GR_READ ? " reading" : "",
55442+ reqmode & GR_WRITE ? " writing" : reqmode &
55443+ GR_APPEND ? " appending" : "");
55444+ return 0;
55445+ } else if (unlikely((mode & reqmode) != reqmode))
55446+ return 0;
55447+
55448+ return reqmode;
55449+}
55450+
55451+__u32
55452+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
55453+ const int fmode)
55454+{
55455+ __u32 mode, reqmode = GR_FIND;
55456+
55457+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
55458+ reqmode |= GR_EXEC;
55459+ if (fmode & S_IWOTH)
55460+ reqmode |= GR_WRITE;
55461+ if (fmode & S_IROTH)
55462+ reqmode |= GR_READ;
55463+
55464+ mode =
55465+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55466+ mnt);
55467+
55468+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55469+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55470+ reqmode & GR_READ ? " reading" : "",
55471+ reqmode & GR_WRITE ? " writing" : "",
55472+ reqmode & GR_EXEC ? " executing" : "");
55473+ return reqmode;
55474+ } else
55475+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55476+ {
55477+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55478+ reqmode & GR_READ ? " reading" : "",
55479+ reqmode & GR_WRITE ? " writing" : "",
55480+ reqmode & GR_EXEC ? " executing" : "");
55481+ return 0;
55482+ } else if (unlikely((mode & reqmode) != reqmode))
55483+ return 0;
55484+
55485+ return reqmode;
55486+}
55487+
55488+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55489+{
55490+ __u32 mode;
55491+
55492+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55493+
55494+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55495+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55496+ return mode;
55497+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55498+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55499+ return 0;
55500+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
55501+ return 0;
55502+
55503+ return (reqmode);
55504+}
55505+
55506+__u32
55507+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
55508+{
55509+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
55510+}
55511+
55512+__u32
55513+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
55514+{
55515+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
55516+}
55517+
55518+__u32
55519+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
55520+{
55521+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
55522+}
55523+
55524+__u32
55525+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
55526+{
55527+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
55528+}
55529+
55530+__u32
55531+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
55532+ umode_t *modeptr)
55533+{
55534+ umode_t mode;
55535+
55536+ *modeptr &= ~gr_acl_umask();
55537+ mode = *modeptr;
55538+
55539+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
55540+ return 1;
55541+
55542+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
55543+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
55544+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55545+ GR_CHMOD_ACL_MSG);
55546+ } else {
55547+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
55548+ }
55549+}
55550+
55551+__u32
55552+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
55553+{
55554+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
55555+}
55556+
55557+__u32
55558+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
55559+{
55560+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
55561+}
55562+
55563+__u32
55564+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
55565+{
55566+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
55567+}
55568+
55569+__u32
55570+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
55571+{
55572+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
55573+ GR_UNIXCONNECT_ACL_MSG);
55574+}
55575+
55576+/* hardlinks require at minimum create and link permission,
55577+ any additional privilege required is based on the
55578+ privilege of the file being linked to
55579+*/
55580+__u32
55581+gr_acl_handle_link(const struct dentry * new_dentry,
55582+ const struct dentry * parent_dentry,
55583+ const struct vfsmount * parent_mnt,
55584+ const struct dentry * old_dentry,
55585+ const struct vfsmount * old_mnt, const char *to)
55586+{
55587+ __u32 mode;
55588+ __u32 needmode = GR_CREATE | GR_LINK;
55589+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
55590+
55591+ mode =
55592+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
55593+ old_mnt);
55594+
55595+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
55596+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55597+ return mode;
55598+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55599+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55600+ return 0;
55601+ } else if (unlikely((mode & needmode) != needmode))
55602+ return 0;
55603+
55604+ return 1;
55605+}
55606+
55607+__u32
55608+gr_acl_handle_symlink(const struct dentry * new_dentry,
55609+ const struct dentry * parent_dentry,
55610+ const struct vfsmount * parent_mnt, const char *from)
55611+{
55612+ __u32 needmode = GR_WRITE | GR_CREATE;
55613+ __u32 mode;
55614+
55615+ mode =
55616+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
55617+ GR_CREATE | GR_AUDIT_CREATE |
55618+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
55619+
55620+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
55621+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55622+ return mode;
55623+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55624+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55625+ return 0;
55626+ } else if (unlikely((mode & needmode) != needmode))
55627+ return 0;
55628+
55629+ return (GR_WRITE | GR_CREATE);
55630+}
55631+
55632+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)
55633+{
55634+ __u32 mode;
55635+
55636+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55637+
55638+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55639+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
55640+ return mode;
55641+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55642+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
55643+ return 0;
55644+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
55645+ return 0;
55646+
55647+ return (reqmode);
55648+}
55649+
55650+__u32
55651+gr_acl_handle_mknod(const struct dentry * new_dentry,
55652+ const struct dentry * parent_dentry,
55653+ const struct vfsmount * parent_mnt,
55654+ const int mode)
55655+{
55656+ __u32 reqmode = GR_WRITE | GR_CREATE;
55657+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
55658+ reqmode |= GR_SETID;
55659+
55660+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55661+ reqmode, GR_MKNOD_ACL_MSG);
55662+}
55663+
55664+__u32
55665+gr_acl_handle_mkdir(const struct dentry *new_dentry,
55666+ const struct dentry *parent_dentry,
55667+ const struct vfsmount *parent_mnt)
55668+{
55669+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55670+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
55671+}
55672+
55673+#define RENAME_CHECK_SUCCESS(old, new) \
55674+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
55675+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
55676+
55677+int
55678+gr_acl_handle_rename(struct dentry *new_dentry,
55679+ struct dentry *parent_dentry,
55680+ const struct vfsmount *parent_mnt,
55681+ struct dentry *old_dentry,
55682+ struct inode *old_parent_inode,
55683+ struct vfsmount *old_mnt, const char *newname)
55684+{
55685+ __u32 comp1, comp2;
55686+ int error = 0;
55687+
55688+ if (unlikely(!gr_acl_is_enabled()))
55689+ return 0;
55690+
55691+ if (!new_dentry->d_inode) {
55692+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
55693+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
55694+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
55695+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
55696+ GR_DELETE | GR_AUDIT_DELETE |
55697+ GR_AUDIT_READ | GR_AUDIT_WRITE |
55698+ GR_SUPPRESS, old_mnt);
55699+ } else {
55700+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
55701+ GR_CREATE | GR_DELETE |
55702+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
55703+ GR_AUDIT_READ | GR_AUDIT_WRITE |
55704+ GR_SUPPRESS, parent_mnt);
55705+ comp2 =
55706+ gr_search_file(old_dentry,
55707+ GR_READ | GR_WRITE | GR_AUDIT_READ |
55708+ GR_DELETE | GR_AUDIT_DELETE |
55709+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
55710+ }
55711+
55712+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
55713+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
55714+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55715+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
55716+ && !(comp2 & GR_SUPPRESS)) {
55717+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55718+ error = -EACCES;
55719+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
55720+ error = -EACCES;
55721+
55722+ return error;
55723+}
55724+
55725+void
55726+gr_acl_handle_exit(void)
55727+{
55728+ u16 id;
55729+ char *rolename;
55730+ struct file *exec_file;
55731+
55732+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
55733+ !(current->role->roletype & GR_ROLE_PERSIST))) {
55734+ id = current->acl_role_id;
55735+ rolename = current->role->rolename;
55736+ gr_set_acls(1);
55737+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
55738+ }
55739+
55740+ write_lock(&grsec_exec_file_lock);
55741+ exec_file = current->exec_file;
55742+ current->exec_file = NULL;
55743+ write_unlock(&grsec_exec_file_lock);
55744+
55745+ if (exec_file)
55746+ fput(exec_file);
55747+}
55748+
55749+int
55750+gr_acl_handle_procpidmem(const struct task_struct *task)
55751+{
55752+ if (unlikely(!gr_acl_is_enabled()))
55753+ return 0;
55754+
55755+ if (task != current && task->acl->mode & GR_PROTPROCFD)
55756+ return -EACCES;
55757+
55758+ return 0;
55759+}
55760diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
55761new file mode 100644
55762index 0000000..58800a7
55763--- /dev/null
55764+++ b/grsecurity/gracl_ip.c
55765@@ -0,0 +1,384 @@
55766+#include <linux/kernel.h>
55767+#include <asm/uaccess.h>
55768+#include <asm/errno.h>
55769+#include <net/sock.h>
55770+#include <linux/file.h>
55771+#include <linux/fs.h>
55772+#include <linux/net.h>
55773+#include <linux/in.h>
55774+#include <linux/skbuff.h>
55775+#include <linux/ip.h>
55776+#include <linux/udp.h>
55777+#include <linux/types.h>
55778+#include <linux/sched.h>
55779+#include <linux/netdevice.h>
55780+#include <linux/inetdevice.h>
55781+#include <linux/gracl.h>
55782+#include <linux/grsecurity.h>
55783+#include <linux/grinternal.h>
55784+
55785+#define GR_BIND 0x01
55786+#define GR_CONNECT 0x02
55787+#define GR_INVERT 0x04
55788+#define GR_BINDOVERRIDE 0x08
55789+#define GR_CONNECTOVERRIDE 0x10
55790+#define GR_SOCK_FAMILY 0x20
55791+
55792+static const char * gr_protocols[IPPROTO_MAX] = {
55793+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
55794+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
55795+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
55796+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
55797+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
55798+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
55799+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
55800+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
55801+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
55802+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
55803+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
55804+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
55805+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
55806+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
55807+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
55808+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
55809+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
55810+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
55811+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
55812+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
55813+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
55814+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
55815+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
55816+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
55817+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
55818+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
55819+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
55820+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
55821+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
55822+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
55823+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
55824+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
55825+ };
55826+
55827+static const char * gr_socktypes[SOCK_MAX] = {
55828+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
55829+ "unknown:7", "unknown:8", "unknown:9", "packet"
55830+ };
55831+
55832+static const char * gr_sockfamilies[AF_MAX+1] = {
55833+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
55834+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
55835+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
55836+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
55837+ };
55838+
55839+const char *
55840+gr_proto_to_name(unsigned char proto)
55841+{
55842+ return gr_protocols[proto];
55843+}
55844+
55845+const char *
55846+gr_socktype_to_name(unsigned char type)
55847+{
55848+ return gr_socktypes[type];
55849+}
55850+
55851+const char *
55852+gr_sockfamily_to_name(unsigned char family)
55853+{
55854+ return gr_sockfamilies[family];
55855+}
55856+
55857+int
55858+gr_search_socket(const int domain, const int type, const int protocol)
55859+{
55860+ struct acl_subject_label *curr;
55861+ const struct cred *cred = current_cred();
55862+
55863+ if (unlikely(!gr_acl_is_enabled()))
55864+ goto exit;
55865+
55866+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
55867+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
55868+ goto exit; // let the kernel handle it
55869+
55870+ curr = current->acl;
55871+
55872+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
55873+ /* the family is allowed, if this is PF_INET allow it only if
55874+ the extra sock type/protocol checks pass */
55875+ if (domain == PF_INET)
55876+ goto inet_check;
55877+ goto exit;
55878+ } else {
55879+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55880+ __u32 fakeip = 0;
55881+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55882+ current->role->roletype, cred->uid,
55883+ cred->gid, current->exec_file ?
55884+ gr_to_filename(current->exec_file->f_path.dentry,
55885+ current->exec_file->f_path.mnt) :
55886+ curr->filename, curr->filename,
55887+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
55888+ &current->signal->saved_ip);
55889+ goto exit;
55890+ }
55891+ goto exit_fail;
55892+ }
55893+
55894+inet_check:
55895+ /* the rest of this checking is for IPv4 only */
55896+ if (!curr->ips)
55897+ goto exit;
55898+
55899+ if ((curr->ip_type & (1 << type)) &&
55900+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
55901+ goto exit;
55902+
55903+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55904+ /* we don't place acls on raw sockets , and sometimes
55905+ dgram/ip sockets are opened for ioctl and not
55906+ bind/connect, so we'll fake a bind learn log */
55907+ if (type == SOCK_RAW || type == SOCK_PACKET) {
55908+ __u32 fakeip = 0;
55909+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55910+ current->role->roletype, cred->uid,
55911+ cred->gid, current->exec_file ?
55912+ gr_to_filename(current->exec_file->f_path.dentry,
55913+ current->exec_file->f_path.mnt) :
55914+ curr->filename, curr->filename,
55915+ &fakeip, 0, type,
55916+ protocol, GR_CONNECT, &current->signal->saved_ip);
55917+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
55918+ __u32 fakeip = 0;
55919+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55920+ current->role->roletype, cred->uid,
55921+ cred->gid, current->exec_file ?
55922+ gr_to_filename(current->exec_file->f_path.dentry,
55923+ current->exec_file->f_path.mnt) :
55924+ curr->filename, curr->filename,
55925+ &fakeip, 0, type,
55926+ protocol, GR_BIND, &current->signal->saved_ip);
55927+ }
55928+ /* we'll log when they use connect or bind */
55929+ goto exit;
55930+ }
55931+
55932+exit_fail:
55933+ if (domain == PF_INET)
55934+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
55935+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
55936+ else
55937+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
55938+ gr_socktype_to_name(type), protocol);
55939+
55940+ return 0;
55941+exit:
55942+ return 1;
55943+}
55944+
55945+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)
55946+{
55947+ if ((ip->mode & mode) &&
55948+ (ip_port >= ip->low) &&
55949+ (ip_port <= ip->high) &&
55950+ ((ntohl(ip_addr) & our_netmask) ==
55951+ (ntohl(our_addr) & our_netmask))
55952+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
55953+ && (ip->type & (1 << type))) {
55954+ if (ip->mode & GR_INVERT)
55955+ return 2; // specifically denied
55956+ else
55957+ return 1; // allowed
55958+ }
55959+
55960+ return 0; // not specifically allowed, may continue parsing
55961+}
55962+
55963+static int
55964+gr_search_connectbind(const int full_mode, struct sock *sk,
55965+ struct sockaddr_in *addr, const int type)
55966+{
55967+ char iface[IFNAMSIZ] = {0};
55968+ struct acl_subject_label *curr;
55969+ struct acl_ip_label *ip;
55970+ struct inet_sock *isk;
55971+ struct net_device *dev;
55972+ struct in_device *idev;
55973+ unsigned long i;
55974+ int ret;
55975+ int mode = full_mode & (GR_BIND | GR_CONNECT);
55976+ __u32 ip_addr = 0;
55977+ __u32 our_addr;
55978+ __u32 our_netmask;
55979+ char *p;
55980+ __u16 ip_port = 0;
55981+ const struct cred *cred = current_cred();
55982+
55983+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
55984+ return 0;
55985+
55986+ curr = current->acl;
55987+ isk = inet_sk(sk);
55988+
55989+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
55990+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
55991+ addr->sin_addr.s_addr = curr->inaddr_any_override;
55992+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
55993+ struct sockaddr_in saddr;
55994+ int err;
55995+
55996+ saddr.sin_family = AF_INET;
55997+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
55998+ saddr.sin_port = isk->inet_sport;
55999+
56000+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56001+ if (err)
56002+ return err;
56003+
56004+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56005+ if (err)
56006+ return err;
56007+ }
56008+
56009+ if (!curr->ips)
56010+ return 0;
56011+
56012+ ip_addr = addr->sin_addr.s_addr;
56013+ ip_port = ntohs(addr->sin_port);
56014+
56015+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56016+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56017+ current->role->roletype, cred->uid,
56018+ cred->gid, current->exec_file ?
56019+ gr_to_filename(current->exec_file->f_path.dentry,
56020+ current->exec_file->f_path.mnt) :
56021+ curr->filename, curr->filename,
56022+ &ip_addr, ip_port, type,
56023+ sk->sk_protocol, mode, &current->signal->saved_ip);
56024+ return 0;
56025+ }
56026+
56027+ for (i = 0; i < curr->ip_num; i++) {
56028+ ip = *(curr->ips + i);
56029+ if (ip->iface != NULL) {
56030+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
56031+ p = strchr(iface, ':');
56032+ if (p != NULL)
56033+ *p = '\0';
56034+ dev = dev_get_by_name(sock_net(sk), iface);
56035+ if (dev == NULL)
56036+ continue;
56037+ idev = in_dev_get(dev);
56038+ if (idev == NULL) {
56039+ dev_put(dev);
56040+ continue;
56041+ }
56042+ rcu_read_lock();
56043+ for_ifa(idev) {
56044+ if (!strcmp(ip->iface, ifa->ifa_label)) {
56045+ our_addr = ifa->ifa_address;
56046+ our_netmask = 0xffffffff;
56047+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56048+ if (ret == 1) {
56049+ rcu_read_unlock();
56050+ in_dev_put(idev);
56051+ dev_put(dev);
56052+ return 0;
56053+ } else if (ret == 2) {
56054+ rcu_read_unlock();
56055+ in_dev_put(idev);
56056+ dev_put(dev);
56057+ goto denied;
56058+ }
56059+ }
56060+ } endfor_ifa(idev);
56061+ rcu_read_unlock();
56062+ in_dev_put(idev);
56063+ dev_put(dev);
56064+ } else {
56065+ our_addr = ip->addr;
56066+ our_netmask = ip->netmask;
56067+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56068+ if (ret == 1)
56069+ return 0;
56070+ else if (ret == 2)
56071+ goto denied;
56072+ }
56073+ }
56074+
56075+denied:
56076+ if (mode == GR_BIND)
56077+ 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));
56078+ else if (mode == GR_CONNECT)
56079+ 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));
56080+
56081+ return -EACCES;
56082+}
56083+
56084+int
56085+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56086+{
56087+ /* always allow disconnection of dgram sockets with connect */
56088+ if (addr->sin_family == AF_UNSPEC)
56089+ return 0;
56090+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56091+}
56092+
56093+int
56094+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56095+{
56096+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56097+}
56098+
56099+int gr_search_listen(struct socket *sock)
56100+{
56101+ struct sock *sk = sock->sk;
56102+ struct sockaddr_in addr;
56103+
56104+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56105+ addr.sin_port = inet_sk(sk)->inet_sport;
56106+
56107+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56108+}
56109+
56110+int gr_search_accept(struct socket *sock)
56111+{
56112+ struct sock *sk = sock->sk;
56113+ struct sockaddr_in addr;
56114+
56115+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56116+ addr.sin_port = inet_sk(sk)->inet_sport;
56117+
56118+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56119+}
56120+
56121+int
56122+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56123+{
56124+ if (addr)
56125+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56126+ else {
56127+ struct sockaddr_in sin;
56128+ const struct inet_sock *inet = inet_sk(sk);
56129+
56130+ sin.sin_addr.s_addr = inet->inet_daddr;
56131+ sin.sin_port = inet->inet_dport;
56132+
56133+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56134+ }
56135+}
56136+
56137+int
56138+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56139+{
56140+ struct sockaddr_in sin;
56141+
56142+ if (unlikely(skb->len < sizeof (struct udphdr)))
56143+ return 0; // skip this packet
56144+
56145+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56146+ sin.sin_port = udp_hdr(skb)->source;
56147+
56148+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56149+}
56150diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
56151new file mode 100644
56152index 0000000..25f54ef
56153--- /dev/null
56154+++ b/grsecurity/gracl_learn.c
56155@@ -0,0 +1,207 @@
56156+#include <linux/kernel.h>
56157+#include <linux/mm.h>
56158+#include <linux/sched.h>
56159+#include <linux/poll.h>
56160+#include <linux/string.h>
56161+#include <linux/file.h>
56162+#include <linux/types.h>
56163+#include <linux/vmalloc.h>
56164+#include <linux/grinternal.h>
56165+
56166+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56167+ size_t count, loff_t *ppos);
56168+extern int gr_acl_is_enabled(void);
56169+
56170+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56171+static int gr_learn_attached;
56172+
56173+/* use a 512k buffer */
56174+#define LEARN_BUFFER_SIZE (512 * 1024)
56175+
56176+static DEFINE_SPINLOCK(gr_learn_lock);
56177+static DEFINE_MUTEX(gr_learn_user_mutex);
56178+
56179+/* we need to maintain two buffers, so that the kernel context of grlearn
56180+ uses a semaphore around the userspace copying, and the other kernel contexts
56181+ use a spinlock when copying into the buffer, since they cannot sleep
56182+*/
56183+static char *learn_buffer;
56184+static char *learn_buffer_user;
56185+static int learn_buffer_len;
56186+static int learn_buffer_user_len;
56187+
56188+static ssize_t
56189+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56190+{
56191+ DECLARE_WAITQUEUE(wait, current);
56192+ ssize_t retval = 0;
56193+
56194+ add_wait_queue(&learn_wait, &wait);
56195+ set_current_state(TASK_INTERRUPTIBLE);
56196+ do {
56197+ mutex_lock(&gr_learn_user_mutex);
56198+ spin_lock(&gr_learn_lock);
56199+ if (learn_buffer_len)
56200+ break;
56201+ spin_unlock(&gr_learn_lock);
56202+ mutex_unlock(&gr_learn_user_mutex);
56203+ if (file->f_flags & O_NONBLOCK) {
56204+ retval = -EAGAIN;
56205+ goto out;
56206+ }
56207+ if (signal_pending(current)) {
56208+ retval = -ERESTARTSYS;
56209+ goto out;
56210+ }
56211+
56212+ schedule();
56213+ } while (1);
56214+
56215+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56216+ learn_buffer_user_len = learn_buffer_len;
56217+ retval = learn_buffer_len;
56218+ learn_buffer_len = 0;
56219+
56220+ spin_unlock(&gr_learn_lock);
56221+
56222+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56223+ retval = -EFAULT;
56224+
56225+ mutex_unlock(&gr_learn_user_mutex);
56226+out:
56227+ set_current_state(TASK_RUNNING);
56228+ remove_wait_queue(&learn_wait, &wait);
56229+ return retval;
56230+}
56231+
56232+static unsigned int
56233+poll_learn(struct file * file, poll_table * wait)
56234+{
56235+ poll_wait(file, &learn_wait, wait);
56236+
56237+ if (learn_buffer_len)
56238+ return (POLLIN | POLLRDNORM);
56239+
56240+ return 0;
56241+}
56242+
56243+void
56244+gr_clear_learn_entries(void)
56245+{
56246+ char *tmp;
56247+
56248+ mutex_lock(&gr_learn_user_mutex);
56249+ spin_lock(&gr_learn_lock);
56250+ tmp = learn_buffer;
56251+ learn_buffer = NULL;
56252+ spin_unlock(&gr_learn_lock);
56253+ if (tmp)
56254+ vfree(tmp);
56255+ if (learn_buffer_user != NULL) {
56256+ vfree(learn_buffer_user);
56257+ learn_buffer_user = NULL;
56258+ }
56259+ learn_buffer_len = 0;
56260+ mutex_unlock(&gr_learn_user_mutex);
56261+
56262+ return;
56263+}
56264+
56265+void
56266+gr_add_learn_entry(const char *fmt, ...)
56267+{
56268+ va_list args;
56269+ unsigned int len;
56270+
56271+ if (!gr_learn_attached)
56272+ return;
56273+
56274+ spin_lock(&gr_learn_lock);
56275+
56276+ /* leave a gap at the end so we know when it's "full" but don't have to
56277+ compute the exact length of the string we're trying to append
56278+ */
56279+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56280+ spin_unlock(&gr_learn_lock);
56281+ wake_up_interruptible(&learn_wait);
56282+ return;
56283+ }
56284+ if (learn_buffer == NULL) {
56285+ spin_unlock(&gr_learn_lock);
56286+ return;
56287+ }
56288+
56289+ va_start(args, fmt);
56290+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56291+ va_end(args);
56292+
56293+ learn_buffer_len += len + 1;
56294+
56295+ spin_unlock(&gr_learn_lock);
56296+ wake_up_interruptible(&learn_wait);
56297+
56298+ return;
56299+}
56300+
56301+static int
56302+open_learn(struct inode *inode, struct file *file)
56303+{
56304+ if (file->f_mode & FMODE_READ && gr_learn_attached)
56305+ return -EBUSY;
56306+ if (file->f_mode & FMODE_READ) {
56307+ int retval = 0;
56308+ mutex_lock(&gr_learn_user_mutex);
56309+ if (learn_buffer == NULL)
56310+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56311+ if (learn_buffer_user == NULL)
56312+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56313+ if (learn_buffer == NULL) {
56314+ retval = -ENOMEM;
56315+ goto out_error;
56316+ }
56317+ if (learn_buffer_user == NULL) {
56318+ retval = -ENOMEM;
56319+ goto out_error;
56320+ }
56321+ learn_buffer_len = 0;
56322+ learn_buffer_user_len = 0;
56323+ gr_learn_attached = 1;
56324+out_error:
56325+ mutex_unlock(&gr_learn_user_mutex);
56326+ return retval;
56327+ }
56328+ return 0;
56329+}
56330+
56331+static int
56332+close_learn(struct inode *inode, struct file *file)
56333+{
56334+ if (file->f_mode & FMODE_READ) {
56335+ char *tmp = NULL;
56336+ mutex_lock(&gr_learn_user_mutex);
56337+ spin_lock(&gr_learn_lock);
56338+ tmp = learn_buffer;
56339+ learn_buffer = NULL;
56340+ spin_unlock(&gr_learn_lock);
56341+ if (tmp)
56342+ vfree(tmp);
56343+ if (learn_buffer_user != NULL) {
56344+ vfree(learn_buffer_user);
56345+ learn_buffer_user = NULL;
56346+ }
56347+ learn_buffer_len = 0;
56348+ learn_buffer_user_len = 0;
56349+ gr_learn_attached = 0;
56350+ mutex_unlock(&gr_learn_user_mutex);
56351+ }
56352+
56353+ return 0;
56354+}
56355+
56356+const struct file_operations grsec_fops = {
56357+ .read = read_learn,
56358+ .write = write_grsec_handler,
56359+ .open = open_learn,
56360+ .release = close_learn,
56361+ .poll = poll_learn,
56362+};
56363diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
56364new file mode 100644
56365index 0000000..39645c9
56366--- /dev/null
56367+++ b/grsecurity/gracl_res.c
56368@@ -0,0 +1,68 @@
56369+#include <linux/kernel.h>
56370+#include <linux/sched.h>
56371+#include <linux/gracl.h>
56372+#include <linux/grinternal.h>
56373+
56374+static const char *restab_log[] = {
56375+ [RLIMIT_CPU] = "RLIMIT_CPU",
56376+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56377+ [RLIMIT_DATA] = "RLIMIT_DATA",
56378+ [RLIMIT_STACK] = "RLIMIT_STACK",
56379+ [RLIMIT_CORE] = "RLIMIT_CORE",
56380+ [RLIMIT_RSS] = "RLIMIT_RSS",
56381+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
56382+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56383+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56384+ [RLIMIT_AS] = "RLIMIT_AS",
56385+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56386+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56387+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56388+ [RLIMIT_NICE] = "RLIMIT_NICE",
56389+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56390+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56391+ [GR_CRASH_RES] = "RLIMIT_CRASH"
56392+};
56393+
56394+void
56395+gr_log_resource(const struct task_struct *task,
56396+ const int res, const unsigned long wanted, const int gt)
56397+{
56398+ const struct cred *cred;
56399+ unsigned long rlim;
56400+
56401+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
56402+ return;
56403+
56404+ // not yet supported resource
56405+ if (unlikely(!restab_log[res]))
56406+ return;
56407+
56408+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56409+ rlim = task_rlimit_max(task, res);
56410+ else
56411+ rlim = task_rlimit(task, res);
56412+
56413+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
56414+ return;
56415+
56416+ rcu_read_lock();
56417+ cred = __task_cred(task);
56418+
56419+ if (res == RLIMIT_NPROC &&
56420+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
56421+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
56422+ goto out_rcu_unlock;
56423+ else if (res == RLIMIT_MEMLOCK &&
56424+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
56425+ goto out_rcu_unlock;
56426+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
56427+ goto out_rcu_unlock;
56428+ rcu_read_unlock();
56429+
56430+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
56431+
56432+ return;
56433+out_rcu_unlock:
56434+ rcu_read_unlock();
56435+ return;
56436+}
56437diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
56438new file mode 100644
56439index 0000000..25197e9
56440--- /dev/null
56441+++ b/grsecurity/gracl_segv.c
56442@@ -0,0 +1,299 @@
56443+#include <linux/kernel.h>
56444+#include <linux/mm.h>
56445+#include <asm/uaccess.h>
56446+#include <asm/errno.h>
56447+#include <asm/mman.h>
56448+#include <net/sock.h>
56449+#include <linux/file.h>
56450+#include <linux/fs.h>
56451+#include <linux/net.h>
56452+#include <linux/in.h>
56453+#include <linux/slab.h>
56454+#include <linux/types.h>
56455+#include <linux/sched.h>
56456+#include <linux/timer.h>
56457+#include <linux/gracl.h>
56458+#include <linux/grsecurity.h>
56459+#include <linux/grinternal.h>
56460+
56461+static struct crash_uid *uid_set;
56462+static unsigned short uid_used;
56463+static DEFINE_SPINLOCK(gr_uid_lock);
56464+extern rwlock_t gr_inode_lock;
56465+extern struct acl_subject_label *
56466+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
56467+ struct acl_role_label *role);
56468+
56469+#ifdef CONFIG_BTRFS_FS
56470+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56471+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56472+#endif
56473+
56474+static inline dev_t __get_dev(const struct dentry *dentry)
56475+{
56476+#ifdef CONFIG_BTRFS_FS
56477+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56478+ return get_btrfs_dev_from_inode(dentry->d_inode);
56479+ else
56480+#endif
56481+ return dentry->d_inode->i_sb->s_dev;
56482+}
56483+
56484+int
56485+gr_init_uidset(void)
56486+{
56487+ uid_set =
56488+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56489+ uid_used = 0;
56490+
56491+ return uid_set ? 1 : 0;
56492+}
56493+
56494+void
56495+gr_free_uidset(void)
56496+{
56497+ if (uid_set)
56498+ kfree(uid_set);
56499+
56500+ return;
56501+}
56502+
56503+int
56504+gr_find_uid(const uid_t uid)
56505+{
56506+ struct crash_uid *tmp = uid_set;
56507+ uid_t buid;
56508+ int low = 0, high = uid_used - 1, mid;
56509+
56510+ while (high >= low) {
56511+ mid = (low + high) >> 1;
56512+ buid = tmp[mid].uid;
56513+ if (buid == uid)
56514+ return mid;
56515+ if (buid > uid)
56516+ high = mid - 1;
56517+ if (buid < uid)
56518+ low = mid + 1;
56519+ }
56520+
56521+ return -1;
56522+}
56523+
56524+static __inline__ void
56525+gr_insertsort(void)
56526+{
56527+ unsigned short i, j;
56528+ struct crash_uid index;
56529+
56530+ for (i = 1; i < uid_used; i++) {
56531+ index = uid_set[i];
56532+ j = i;
56533+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
56534+ uid_set[j] = uid_set[j - 1];
56535+ j--;
56536+ }
56537+ uid_set[j] = index;
56538+ }
56539+
56540+ return;
56541+}
56542+
56543+static __inline__ void
56544+gr_insert_uid(const uid_t uid, const unsigned long expires)
56545+{
56546+ int loc;
56547+
56548+ if (uid_used == GR_UIDTABLE_MAX)
56549+ return;
56550+
56551+ loc = gr_find_uid(uid);
56552+
56553+ if (loc >= 0) {
56554+ uid_set[loc].expires = expires;
56555+ return;
56556+ }
56557+
56558+ uid_set[uid_used].uid = uid;
56559+ uid_set[uid_used].expires = expires;
56560+ uid_used++;
56561+
56562+ gr_insertsort();
56563+
56564+ return;
56565+}
56566+
56567+void
56568+gr_remove_uid(const unsigned short loc)
56569+{
56570+ unsigned short i;
56571+
56572+ for (i = loc + 1; i < uid_used; i++)
56573+ uid_set[i - 1] = uid_set[i];
56574+
56575+ uid_used--;
56576+
56577+ return;
56578+}
56579+
56580+int
56581+gr_check_crash_uid(const uid_t uid)
56582+{
56583+ int loc;
56584+ int ret = 0;
56585+
56586+ if (unlikely(!gr_acl_is_enabled()))
56587+ return 0;
56588+
56589+ spin_lock(&gr_uid_lock);
56590+ loc = gr_find_uid(uid);
56591+
56592+ if (loc < 0)
56593+ goto out_unlock;
56594+
56595+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
56596+ gr_remove_uid(loc);
56597+ else
56598+ ret = 1;
56599+
56600+out_unlock:
56601+ spin_unlock(&gr_uid_lock);
56602+ return ret;
56603+}
56604+
56605+static __inline__ int
56606+proc_is_setxid(const struct cred *cred)
56607+{
56608+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
56609+ !uid_eq(cred->uid, cred->fsuid))
56610+ return 1;
56611+ if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
56612+ !uid_eq(cred->gid, cred->fsgid))
56613+ return 1;
56614+
56615+ return 0;
56616+}
56617+
56618+extern int gr_fake_force_sig(int sig, struct task_struct *t);
56619+
56620+void
56621+gr_handle_crash(struct task_struct *task, const int sig)
56622+{
56623+ struct acl_subject_label *curr;
56624+ struct task_struct *tsk, *tsk2;
56625+ const struct cred *cred;
56626+ const struct cred *cred2;
56627+
56628+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
56629+ return;
56630+
56631+ if (unlikely(!gr_acl_is_enabled()))
56632+ return;
56633+
56634+ curr = task->acl;
56635+
56636+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
56637+ return;
56638+
56639+ if (time_before_eq(curr->expires, get_seconds())) {
56640+ curr->expires = 0;
56641+ curr->crashes = 0;
56642+ }
56643+
56644+ curr->crashes++;
56645+
56646+ if (!curr->expires)
56647+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
56648+
56649+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56650+ time_after(curr->expires, get_seconds())) {
56651+ rcu_read_lock();
56652+ cred = __task_cred(task);
56653+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
56654+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56655+ spin_lock(&gr_uid_lock);
56656+ gr_insert_uid(cred->uid, curr->expires);
56657+ spin_unlock(&gr_uid_lock);
56658+ curr->expires = 0;
56659+ curr->crashes = 0;
56660+ read_lock(&tasklist_lock);
56661+ do_each_thread(tsk2, tsk) {
56662+ cred2 = __task_cred(tsk);
56663+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
56664+ gr_fake_force_sig(SIGKILL, tsk);
56665+ } while_each_thread(tsk2, tsk);
56666+ read_unlock(&tasklist_lock);
56667+ } else {
56668+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56669+ read_lock(&tasklist_lock);
56670+ read_lock(&grsec_exec_file_lock);
56671+ do_each_thread(tsk2, tsk) {
56672+ if (likely(tsk != task)) {
56673+ // if this thread has the same subject as the one that triggered
56674+ // RES_CRASH and it's the same binary, kill it
56675+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
56676+ gr_fake_force_sig(SIGKILL, tsk);
56677+ }
56678+ } while_each_thread(tsk2, tsk);
56679+ read_unlock(&grsec_exec_file_lock);
56680+ read_unlock(&tasklist_lock);
56681+ }
56682+ rcu_read_unlock();
56683+ }
56684+
56685+ return;
56686+}
56687+
56688+int
56689+gr_check_crash_exec(const struct file *filp)
56690+{
56691+ struct acl_subject_label *curr;
56692+
56693+ if (unlikely(!gr_acl_is_enabled()))
56694+ return 0;
56695+
56696+ read_lock(&gr_inode_lock);
56697+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
56698+ __get_dev(filp->f_path.dentry),
56699+ current->role);
56700+ read_unlock(&gr_inode_lock);
56701+
56702+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
56703+ (!curr->crashes && !curr->expires))
56704+ return 0;
56705+
56706+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56707+ time_after(curr->expires, get_seconds()))
56708+ return 1;
56709+ else if (time_before_eq(curr->expires, get_seconds())) {
56710+ curr->crashes = 0;
56711+ curr->expires = 0;
56712+ }
56713+
56714+ return 0;
56715+}
56716+
56717+void
56718+gr_handle_alertkill(struct task_struct *task)
56719+{
56720+ struct acl_subject_label *curracl;
56721+ __u32 curr_ip;
56722+ struct task_struct *p, *p2;
56723+
56724+ if (unlikely(!gr_acl_is_enabled()))
56725+ return;
56726+
56727+ curracl = task->acl;
56728+ curr_ip = task->signal->curr_ip;
56729+
56730+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
56731+ read_lock(&tasklist_lock);
56732+ do_each_thread(p2, p) {
56733+ if (p->signal->curr_ip == curr_ip)
56734+ gr_fake_force_sig(SIGKILL, p);
56735+ } while_each_thread(p2, p);
56736+ read_unlock(&tasklist_lock);
56737+ } else if (curracl->mode & GR_KILLPROC)
56738+ gr_fake_force_sig(SIGKILL, task);
56739+
56740+ return;
56741+}
56742diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
56743new file mode 100644
56744index 0000000..9d83a69
56745--- /dev/null
56746+++ b/grsecurity/gracl_shm.c
56747@@ -0,0 +1,40 @@
56748+#include <linux/kernel.h>
56749+#include <linux/mm.h>
56750+#include <linux/sched.h>
56751+#include <linux/file.h>
56752+#include <linux/ipc.h>
56753+#include <linux/gracl.h>
56754+#include <linux/grsecurity.h>
56755+#include <linux/grinternal.h>
56756+
56757+int
56758+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56759+ const time_t shm_createtime, const uid_t cuid, const int shmid)
56760+{
56761+ struct task_struct *task;
56762+
56763+ if (!gr_acl_is_enabled())
56764+ return 1;
56765+
56766+ rcu_read_lock();
56767+ read_lock(&tasklist_lock);
56768+
56769+ task = find_task_by_vpid(shm_cprid);
56770+
56771+ if (unlikely(!task))
56772+ task = find_task_by_vpid(shm_lapid);
56773+
56774+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
56775+ (task->pid == shm_lapid)) &&
56776+ (task->acl->mode & GR_PROTSHM) &&
56777+ (task->acl != current->acl))) {
56778+ read_unlock(&tasklist_lock);
56779+ rcu_read_unlock();
56780+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
56781+ return 0;
56782+ }
56783+ read_unlock(&tasklist_lock);
56784+ rcu_read_unlock();
56785+
56786+ return 1;
56787+}
56788diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
56789new file mode 100644
56790index 0000000..bc0be01
56791--- /dev/null
56792+++ b/grsecurity/grsec_chdir.c
56793@@ -0,0 +1,19 @@
56794+#include <linux/kernel.h>
56795+#include <linux/sched.h>
56796+#include <linux/fs.h>
56797+#include <linux/file.h>
56798+#include <linux/grsecurity.h>
56799+#include <linux/grinternal.h>
56800+
56801+void
56802+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
56803+{
56804+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
56805+ if ((grsec_enable_chdir && grsec_enable_group &&
56806+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
56807+ !grsec_enable_group)) {
56808+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
56809+ }
56810+#endif
56811+ return;
56812+}
56813diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
56814new file mode 100644
56815index 0000000..9807ee2
56816--- /dev/null
56817+++ b/grsecurity/grsec_chroot.c
56818@@ -0,0 +1,368 @@
56819+#include <linux/kernel.h>
56820+#include <linux/module.h>
56821+#include <linux/sched.h>
56822+#include <linux/file.h>
56823+#include <linux/fs.h>
56824+#include <linux/mount.h>
56825+#include <linux/types.h>
56826+#include "../fs/mount.h"
56827+#include <linux/grsecurity.h>
56828+#include <linux/grinternal.h>
56829+
56830+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
56831+{
56832+#ifdef CONFIG_GRKERNSEC
56833+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
56834+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
56835+ task->gr_is_chrooted = 1;
56836+ else
56837+ task->gr_is_chrooted = 0;
56838+
56839+ task->gr_chroot_dentry = path->dentry;
56840+#endif
56841+ return;
56842+}
56843+
56844+void gr_clear_chroot_entries(struct task_struct *task)
56845+{
56846+#ifdef CONFIG_GRKERNSEC
56847+ task->gr_is_chrooted = 0;
56848+ task->gr_chroot_dentry = NULL;
56849+#endif
56850+ return;
56851+}
56852+
56853+int
56854+gr_handle_chroot_unix(const pid_t pid)
56855+{
56856+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
56857+ struct task_struct *p;
56858+
56859+ if (unlikely(!grsec_enable_chroot_unix))
56860+ return 1;
56861+
56862+ if (likely(!proc_is_chrooted(current)))
56863+ return 1;
56864+
56865+ rcu_read_lock();
56866+ read_lock(&tasklist_lock);
56867+ p = find_task_by_vpid_unrestricted(pid);
56868+ if (unlikely(p && !have_same_root(current, p))) {
56869+ read_unlock(&tasklist_lock);
56870+ rcu_read_unlock();
56871+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
56872+ return 0;
56873+ }
56874+ read_unlock(&tasklist_lock);
56875+ rcu_read_unlock();
56876+#endif
56877+ return 1;
56878+}
56879+
56880+int
56881+gr_handle_chroot_nice(void)
56882+{
56883+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56884+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
56885+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
56886+ return -EPERM;
56887+ }
56888+#endif
56889+ return 0;
56890+}
56891+
56892+int
56893+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
56894+{
56895+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56896+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
56897+ && proc_is_chrooted(current)) {
56898+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
56899+ return -EACCES;
56900+ }
56901+#endif
56902+ return 0;
56903+}
56904+
56905+int
56906+gr_handle_chroot_rawio(const struct inode *inode)
56907+{
56908+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56909+ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
56910+ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
56911+ return 1;
56912+#endif
56913+ return 0;
56914+}
56915+
56916+int
56917+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
56918+{
56919+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56920+ struct task_struct *p;
56921+ int ret = 0;
56922+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
56923+ return ret;
56924+
56925+ read_lock(&tasklist_lock);
56926+ do_each_pid_task(pid, type, p) {
56927+ if (!have_same_root(current, p)) {
56928+ ret = 1;
56929+ goto out;
56930+ }
56931+ } while_each_pid_task(pid, type, p);
56932+out:
56933+ read_unlock(&tasklist_lock);
56934+ return ret;
56935+#endif
56936+ return 0;
56937+}
56938+
56939+int
56940+gr_pid_is_chrooted(struct task_struct *p)
56941+{
56942+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56943+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
56944+ return 0;
56945+
56946+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
56947+ !have_same_root(current, p)) {
56948+ return 1;
56949+ }
56950+#endif
56951+ return 0;
56952+}
56953+
56954+EXPORT_SYMBOL(gr_pid_is_chrooted);
56955+
56956+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
56957+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
56958+{
56959+ struct path path, currentroot;
56960+ int ret = 0;
56961+
56962+ path.dentry = (struct dentry *)u_dentry;
56963+ path.mnt = (struct vfsmount *)u_mnt;
56964+ get_fs_root(current->fs, &currentroot);
56965+ if (path_is_under(&path, &currentroot))
56966+ ret = 1;
56967+ path_put(&currentroot);
56968+
56969+ return ret;
56970+}
56971+#endif
56972+
56973+int
56974+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
56975+{
56976+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
56977+ if (!grsec_enable_chroot_fchdir)
56978+ return 1;
56979+
56980+ if (!proc_is_chrooted(current))
56981+ return 1;
56982+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
56983+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
56984+ return 0;
56985+ }
56986+#endif
56987+ return 1;
56988+}
56989+
56990+int
56991+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56992+ const time_t shm_createtime)
56993+{
56994+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
56995+ struct task_struct *p;
56996+ time_t starttime;
56997+
56998+ if (unlikely(!grsec_enable_chroot_shmat))
56999+ return 1;
57000+
57001+ if (likely(!proc_is_chrooted(current)))
57002+ return 1;
57003+
57004+ rcu_read_lock();
57005+ read_lock(&tasklist_lock);
57006+
57007+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
57008+ starttime = p->start_time.tv_sec;
57009+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
57010+ if (have_same_root(current, p)) {
57011+ goto allow;
57012+ } else {
57013+ read_unlock(&tasklist_lock);
57014+ rcu_read_unlock();
57015+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57016+ return 0;
57017+ }
57018+ }
57019+ /* creator exited, pid reuse, fall through to next check */
57020+ }
57021+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
57022+ if (unlikely(!have_same_root(current, p))) {
57023+ read_unlock(&tasklist_lock);
57024+ rcu_read_unlock();
57025+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57026+ return 0;
57027+ }
57028+ }
57029+
57030+allow:
57031+ read_unlock(&tasklist_lock);
57032+ rcu_read_unlock();
57033+#endif
57034+ return 1;
57035+}
57036+
57037+void
57038+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
57039+{
57040+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57041+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
57042+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
57043+#endif
57044+ return;
57045+}
57046+
57047+int
57048+gr_handle_chroot_mknod(const struct dentry *dentry,
57049+ const struct vfsmount *mnt, const int mode)
57050+{
57051+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57052+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
57053+ proc_is_chrooted(current)) {
57054+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57055+ return -EPERM;
57056+ }
57057+#endif
57058+ return 0;
57059+}
57060+
57061+int
57062+gr_handle_chroot_mount(const struct dentry *dentry,
57063+ const struct vfsmount *mnt, const char *dev_name)
57064+{
57065+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57066+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57067+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
57068+ return -EPERM;
57069+ }
57070+#endif
57071+ return 0;
57072+}
57073+
57074+int
57075+gr_handle_chroot_pivot(void)
57076+{
57077+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57078+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57079+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57080+ return -EPERM;
57081+ }
57082+#endif
57083+ return 0;
57084+}
57085+
57086+int
57087+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57088+{
57089+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57090+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57091+ !gr_is_outside_chroot(dentry, mnt)) {
57092+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57093+ return -EPERM;
57094+ }
57095+#endif
57096+ return 0;
57097+}
57098+
57099+extern const char *captab_log[];
57100+extern int captab_log_entries;
57101+
57102+int
57103+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57104+{
57105+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57106+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57107+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57108+ if (cap_raised(chroot_caps, cap)) {
57109+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
57110+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
57111+ }
57112+ return 0;
57113+ }
57114+ }
57115+#endif
57116+ return 1;
57117+}
57118+
57119+int
57120+gr_chroot_is_capable(const int cap)
57121+{
57122+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57123+ return gr_task_chroot_is_capable(current, current_cred(), cap);
57124+#endif
57125+ return 1;
57126+}
57127+
57128+int
57129+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
57130+{
57131+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57132+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57133+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57134+ if (cap_raised(chroot_caps, cap)) {
57135+ return 0;
57136+ }
57137+ }
57138+#endif
57139+ return 1;
57140+}
57141+
57142+int
57143+gr_chroot_is_capable_nolog(const int cap)
57144+{
57145+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57146+ return gr_task_chroot_is_capable_nolog(current, cap);
57147+#endif
57148+ return 1;
57149+}
57150+
57151+int
57152+gr_handle_chroot_sysctl(const int op)
57153+{
57154+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57155+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57156+ proc_is_chrooted(current))
57157+ return -EACCES;
57158+#endif
57159+ return 0;
57160+}
57161+
57162+void
57163+gr_handle_chroot_chdir(struct path *path)
57164+{
57165+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57166+ if (grsec_enable_chroot_chdir)
57167+ set_fs_pwd(current->fs, path);
57168+#endif
57169+ return;
57170+}
57171+
57172+int
57173+gr_handle_chroot_chmod(const struct dentry *dentry,
57174+ const struct vfsmount *mnt, const int mode)
57175+{
57176+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57177+ /* allow chmod +s on directories, but not files */
57178+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57179+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57180+ proc_is_chrooted(current)) {
57181+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57182+ return -EPERM;
57183+ }
57184+#endif
57185+ return 0;
57186+}
57187diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
57188new file mode 100644
57189index 0000000..213ad8b
57190--- /dev/null
57191+++ b/grsecurity/grsec_disabled.c
57192@@ -0,0 +1,437 @@
57193+#include <linux/kernel.h>
57194+#include <linux/module.h>
57195+#include <linux/sched.h>
57196+#include <linux/file.h>
57197+#include <linux/fs.h>
57198+#include <linux/kdev_t.h>
57199+#include <linux/net.h>
57200+#include <linux/in.h>
57201+#include <linux/ip.h>
57202+#include <linux/skbuff.h>
57203+#include <linux/sysctl.h>
57204+
57205+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57206+void
57207+pax_set_initial_flags(struct linux_binprm *bprm)
57208+{
57209+ return;
57210+}
57211+#endif
57212+
57213+#ifdef CONFIG_SYSCTL
57214+__u32
57215+gr_handle_sysctl(const struct ctl_table * table, const int op)
57216+{
57217+ return 0;
57218+}
57219+#endif
57220+
57221+#ifdef CONFIG_TASKSTATS
57222+int gr_is_taskstats_denied(int pid)
57223+{
57224+ return 0;
57225+}
57226+#endif
57227+
57228+int
57229+gr_acl_is_enabled(void)
57230+{
57231+ return 0;
57232+}
57233+
57234+void
57235+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57236+{
57237+ return;
57238+}
57239+
57240+int
57241+gr_handle_rawio(const struct inode *inode)
57242+{
57243+ return 0;
57244+}
57245+
57246+void
57247+gr_acl_handle_psacct(struct task_struct *task, const long code)
57248+{
57249+ return;
57250+}
57251+
57252+int
57253+gr_handle_ptrace(struct task_struct *task, const long request)
57254+{
57255+ return 0;
57256+}
57257+
57258+int
57259+gr_handle_proc_ptrace(struct task_struct *task)
57260+{
57261+ return 0;
57262+}
57263+
57264+void
57265+gr_learn_resource(const struct task_struct *task,
57266+ const int res, const unsigned long wanted, const int gt)
57267+{
57268+ return;
57269+}
57270+
57271+int
57272+gr_set_acls(const int type)
57273+{
57274+ return 0;
57275+}
57276+
57277+int
57278+gr_check_hidden_task(const struct task_struct *tsk)
57279+{
57280+ return 0;
57281+}
57282+
57283+int
57284+gr_check_protected_task(const struct task_struct *task)
57285+{
57286+ return 0;
57287+}
57288+
57289+int
57290+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57291+{
57292+ return 0;
57293+}
57294+
57295+void
57296+gr_copy_label(struct task_struct *tsk)
57297+{
57298+ return;
57299+}
57300+
57301+void
57302+gr_set_pax_flags(struct task_struct *task)
57303+{
57304+ return;
57305+}
57306+
57307+int
57308+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57309+ const int unsafe_share)
57310+{
57311+ return 0;
57312+}
57313+
57314+void
57315+gr_handle_delete(const ino_t ino, const dev_t dev)
57316+{
57317+ return;
57318+}
57319+
57320+void
57321+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57322+{
57323+ return;
57324+}
57325+
57326+void
57327+gr_handle_crash(struct task_struct *task, const int sig)
57328+{
57329+ return;
57330+}
57331+
57332+int
57333+gr_check_crash_exec(const struct file *filp)
57334+{
57335+ return 0;
57336+}
57337+
57338+int
57339+gr_check_crash_uid(const uid_t uid)
57340+{
57341+ return 0;
57342+}
57343+
57344+void
57345+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57346+ struct dentry *old_dentry,
57347+ struct dentry *new_dentry,
57348+ struct vfsmount *mnt, const __u8 replace)
57349+{
57350+ return;
57351+}
57352+
57353+int
57354+gr_search_socket(const int family, const int type, const int protocol)
57355+{
57356+ return 1;
57357+}
57358+
57359+int
57360+gr_search_connectbind(const int mode, const struct socket *sock,
57361+ const struct sockaddr_in *addr)
57362+{
57363+ return 0;
57364+}
57365+
57366+void
57367+gr_handle_alertkill(struct task_struct *task)
57368+{
57369+ return;
57370+}
57371+
57372+__u32
57373+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57374+{
57375+ return 1;
57376+}
57377+
57378+__u32
57379+gr_acl_handle_hidden_file(const struct dentry * dentry,
57380+ const struct vfsmount * mnt)
57381+{
57382+ return 1;
57383+}
57384+
57385+__u32
57386+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57387+ int acc_mode)
57388+{
57389+ return 1;
57390+}
57391+
57392+__u32
57393+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57394+{
57395+ return 1;
57396+}
57397+
57398+__u32
57399+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57400+{
57401+ return 1;
57402+}
57403+
57404+int
57405+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57406+ unsigned int *vm_flags)
57407+{
57408+ return 1;
57409+}
57410+
57411+__u32
57412+gr_acl_handle_truncate(const struct dentry * dentry,
57413+ const struct vfsmount * mnt)
57414+{
57415+ return 1;
57416+}
57417+
57418+__u32
57419+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
57420+{
57421+ return 1;
57422+}
57423+
57424+__u32
57425+gr_acl_handle_access(const struct dentry * dentry,
57426+ const struct vfsmount * mnt, const int fmode)
57427+{
57428+ return 1;
57429+}
57430+
57431+__u32
57432+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
57433+ umode_t *mode)
57434+{
57435+ return 1;
57436+}
57437+
57438+__u32
57439+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
57440+{
57441+ return 1;
57442+}
57443+
57444+__u32
57445+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
57446+{
57447+ return 1;
57448+}
57449+
57450+void
57451+grsecurity_init(void)
57452+{
57453+ return;
57454+}
57455+
57456+umode_t gr_acl_umask(void)
57457+{
57458+ return 0;
57459+}
57460+
57461+__u32
57462+gr_acl_handle_mknod(const struct dentry * new_dentry,
57463+ const struct dentry * parent_dentry,
57464+ const struct vfsmount * parent_mnt,
57465+ const int mode)
57466+{
57467+ return 1;
57468+}
57469+
57470+__u32
57471+gr_acl_handle_mkdir(const struct dentry * new_dentry,
57472+ const struct dentry * parent_dentry,
57473+ const struct vfsmount * parent_mnt)
57474+{
57475+ return 1;
57476+}
57477+
57478+__u32
57479+gr_acl_handle_symlink(const struct dentry * new_dentry,
57480+ const struct dentry * parent_dentry,
57481+ const struct vfsmount * parent_mnt, const char *from)
57482+{
57483+ return 1;
57484+}
57485+
57486+__u32
57487+gr_acl_handle_link(const struct dentry * new_dentry,
57488+ const struct dentry * parent_dentry,
57489+ const struct vfsmount * parent_mnt,
57490+ const struct dentry * old_dentry,
57491+ const struct vfsmount * old_mnt, const char *to)
57492+{
57493+ return 1;
57494+}
57495+
57496+int
57497+gr_acl_handle_rename(const struct dentry *new_dentry,
57498+ const struct dentry *parent_dentry,
57499+ const struct vfsmount *parent_mnt,
57500+ const struct dentry *old_dentry,
57501+ const struct inode *old_parent_inode,
57502+ const struct vfsmount *old_mnt, const char *newname)
57503+{
57504+ return 0;
57505+}
57506+
57507+int
57508+gr_acl_handle_filldir(const struct file *file, const char *name,
57509+ const int namelen, const ino_t ino)
57510+{
57511+ return 1;
57512+}
57513+
57514+int
57515+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57516+ const time_t shm_createtime, const uid_t cuid, const int shmid)
57517+{
57518+ return 1;
57519+}
57520+
57521+int
57522+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
57523+{
57524+ return 0;
57525+}
57526+
57527+int
57528+gr_search_accept(const struct socket *sock)
57529+{
57530+ return 0;
57531+}
57532+
57533+int
57534+gr_search_listen(const struct socket *sock)
57535+{
57536+ return 0;
57537+}
57538+
57539+int
57540+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
57541+{
57542+ return 0;
57543+}
57544+
57545+__u32
57546+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
57547+{
57548+ return 1;
57549+}
57550+
57551+__u32
57552+gr_acl_handle_creat(const struct dentry * dentry,
57553+ const struct dentry * p_dentry,
57554+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
57555+ const int imode)
57556+{
57557+ return 1;
57558+}
57559+
57560+void
57561+gr_acl_handle_exit(void)
57562+{
57563+ return;
57564+}
57565+
57566+int
57567+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57568+{
57569+ return 1;
57570+}
57571+
57572+void
57573+gr_set_role_label(const uid_t uid, const gid_t gid)
57574+{
57575+ return;
57576+}
57577+
57578+int
57579+gr_acl_handle_procpidmem(const struct task_struct *task)
57580+{
57581+ return 0;
57582+}
57583+
57584+int
57585+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
57586+{
57587+ return 0;
57588+}
57589+
57590+int
57591+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
57592+{
57593+ return 0;
57594+}
57595+
57596+void
57597+gr_set_kernel_label(struct task_struct *task)
57598+{
57599+ return;
57600+}
57601+
57602+int
57603+gr_check_user_change(int real, int effective, int fs)
57604+{
57605+ return 0;
57606+}
57607+
57608+int
57609+gr_check_group_change(int real, int effective, int fs)
57610+{
57611+ return 0;
57612+}
57613+
57614+int gr_acl_enable_at_secure(void)
57615+{
57616+ return 0;
57617+}
57618+
57619+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57620+{
57621+ return dentry->d_inode->i_sb->s_dev;
57622+}
57623+
57624+EXPORT_SYMBOL(gr_learn_resource);
57625+EXPORT_SYMBOL(gr_set_kernel_label);
57626+#ifdef CONFIG_SECURITY
57627+EXPORT_SYMBOL(gr_check_user_change);
57628+EXPORT_SYMBOL(gr_check_group_change);
57629+#endif
57630diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
57631new file mode 100644
57632index 0000000..abfa971
57633--- /dev/null
57634+++ b/grsecurity/grsec_exec.c
57635@@ -0,0 +1,174 @@
57636+#include <linux/kernel.h>
57637+#include <linux/sched.h>
57638+#include <linux/file.h>
57639+#include <linux/binfmts.h>
57640+#include <linux/fs.h>
57641+#include <linux/types.h>
57642+#include <linux/grdefs.h>
57643+#include <linux/grsecurity.h>
57644+#include <linux/grinternal.h>
57645+#include <linux/capability.h>
57646+#include <linux/module.h>
57647+
57648+#include <asm/uaccess.h>
57649+
57650+#ifdef CONFIG_GRKERNSEC_EXECLOG
57651+static char gr_exec_arg_buf[132];
57652+static DEFINE_MUTEX(gr_exec_arg_mutex);
57653+#endif
57654+
57655+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
57656+
57657+void
57658+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
57659+{
57660+#ifdef CONFIG_GRKERNSEC_EXECLOG
57661+ char *grarg = gr_exec_arg_buf;
57662+ unsigned int i, x, execlen = 0;
57663+ char c;
57664+
57665+ if (!((grsec_enable_execlog && grsec_enable_group &&
57666+ in_group_p(grsec_audit_gid))
57667+ || (grsec_enable_execlog && !grsec_enable_group)))
57668+ return;
57669+
57670+ mutex_lock(&gr_exec_arg_mutex);
57671+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
57672+
57673+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
57674+ const char __user *p;
57675+ unsigned int len;
57676+
57677+ p = get_user_arg_ptr(argv, i);
57678+ if (IS_ERR(p))
57679+ goto log;
57680+
57681+ len = strnlen_user(p, 128 - execlen);
57682+ if (len > 128 - execlen)
57683+ len = 128 - execlen;
57684+ else if (len > 0)
57685+ len--;
57686+ if (copy_from_user(grarg + execlen, p, len))
57687+ goto log;
57688+
57689+ /* rewrite unprintable characters */
57690+ for (x = 0; x < len; x++) {
57691+ c = *(grarg + execlen + x);
57692+ if (c < 32 || c > 126)
57693+ *(grarg + execlen + x) = ' ';
57694+ }
57695+
57696+ execlen += len;
57697+ *(grarg + execlen) = ' ';
57698+ *(grarg + execlen + 1) = '\0';
57699+ execlen++;
57700+ }
57701+
57702+ log:
57703+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
57704+ bprm->file->f_path.mnt, grarg);
57705+ mutex_unlock(&gr_exec_arg_mutex);
57706+#endif
57707+ return;
57708+}
57709+
57710+#ifdef CONFIG_GRKERNSEC
57711+extern int gr_acl_is_capable(const int cap);
57712+extern int gr_acl_is_capable_nolog(const int cap);
57713+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57714+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
57715+extern int gr_chroot_is_capable(const int cap);
57716+extern int gr_chroot_is_capable_nolog(const int cap);
57717+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57718+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
57719+#endif
57720+
57721+const char *captab_log[] = {
57722+ "CAP_CHOWN",
57723+ "CAP_DAC_OVERRIDE",
57724+ "CAP_DAC_READ_SEARCH",
57725+ "CAP_FOWNER",
57726+ "CAP_FSETID",
57727+ "CAP_KILL",
57728+ "CAP_SETGID",
57729+ "CAP_SETUID",
57730+ "CAP_SETPCAP",
57731+ "CAP_LINUX_IMMUTABLE",
57732+ "CAP_NET_BIND_SERVICE",
57733+ "CAP_NET_BROADCAST",
57734+ "CAP_NET_ADMIN",
57735+ "CAP_NET_RAW",
57736+ "CAP_IPC_LOCK",
57737+ "CAP_IPC_OWNER",
57738+ "CAP_SYS_MODULE",
57739+ "CAP_SYS_RAWIO",
57740+ "CAP_SYS_CHROOT",
57741+ "CAP_SYS_PTRACE",
57742+ "CAP_SYS_PACCT",
57743+ "CAP_SYS_ADMIN",
57744+ "CAP_SYS_BOOT",
57745+ "CAP_SYS_NICE",
57746+ "CAP_SYS_RESOURCE",
57747+ "CAP_SYS_TIME",
57748+ "CAP_SYS_TTY_CONFIG",
57749+ "CAP_MKNOD",
57750+ "CAP_LEASE",
57751+ "CAP_AUDIT_WRITE",
57752+ "CAP_AUDIT_CONTROL",
57753+ "CAP_SETFCAP",
57754+ "CAP_MAC_OVERRIDE",
57755+ "CAP_MAC_ADMIN",
57756+ "CAP_SYSLOG",
57757+ "CAP_WAKE_ALARM"
57758+};
57759+
57760+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
57761+
57762+int gr_is_capable(const int cap)
57763+{
57764+#ifdef CONFIG_GRKERNSEC
57765+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
57766+ return 1;
57767+ return 0;
57768+#else
57769+ return 1;
57770+#endif
57771+}
57772+
57773+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57774+{
57775+#ifdef CONFIG_GRKERNSEC
57776+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
57777+ return 1;
57778+ return 0;
57779+#else
57780+ return 1;
57781+#endif
57782+}
57783+
57784+int gr_is_capable_nolog(const int cap)
57785+{
57786+#ifdef CONFIG_GRKERNSEC
57787+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
57788+ return 1;
57789+ return 0;
57790+#else
57791+ return 1;
57792+#endif
57793+}
57794+
57795+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
57796+{
57797+#ifdef CONFIG_GRKERNSEC
57798+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
57799+ return 1;
57800+ return 0;
57801+#else
57802+ return 1;
57803+#endif
57804+}
57805+
57806+EXPORT_SYMBOL(gr_is_capable);
57807+EXPORT_SYMBOL(gr_is_capable_nolog);
57808+EXPORT_SYMBOL(gr_task_is_capable);
57809+EXPORT_SYMBOL(gr_task_is_capable_nolog);
57810diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
57811new file mode 100644
57812index 0000000..d3ee748
57813--- /dev/null
57814+++ b/grsecurity/grsec_fifo.c
57815@@ -0,0 +1,24 @@
57816+#include <linux/kernel.h>
57817+#include <linux/sched.h>
57818+#include <linux/fs.h>
57819+#include <linux/file.h>
57820+#include <linux/grinternal.h>
57821+
57822+int
57823+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
57824+ const struct dentry *dir, const int flag, const int acc_mode)
57825+{
57826+#ifdef CONFIG_GRKERNSEC_FIFO
57827+ const struct cred *cred = current_cred();
57828+
57829+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
57830+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
57831+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
57832+ (cred->fsuid != dentry->d_inode->i_uid)) {
57833+ if (!inode_permission(dentry->d_inode, acc_mode))
57834+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
57835+ return -EACCES;
57836+ }
57837+#endif
57838+ return 0;
57839+}
57840diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
57841new file mode 100644
57842index 0000000..8ca18bf
57843--- /dev/null
57844+++ b/grsecurity/grsec_fork.c
57845@@ -0,0 +1,23 @@
57846+#include <linux/kernel.h>
57847+#include <linux/sched.h>
57848+#include <linux/grsecurity.h>
57849+#include <linux/grinternal.h>
57850+#include <linux/errno.h>
57851+
57852+void
57853+gr_log_forkfail(const int retval)
57854+{
57855+#ifdef CONFIG_GRKERNSEC_FORKFAIL
57856+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
57857+ switch (retval) {
57858+ case -EAGAIN:
57859+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
57860+ break;
57861+ case -ENOMEM:
57862+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
57863+ break;
57864+ }
57865+ }
57866+#endif
57867+ return;
57868+}
57869diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
57870new file mode 100644
57871index 0000000..05a6015
57872--- /dev/null
57873+++ b/grsecurity/grsec_init.c
57874@@ -0,0 +1,283 @@
57875+#include <linux/kernel.h>
57876+#include <linux/sched.h>
57877+#include <linux/mm.h>
57878+#include <linux/gracl.h>
57879+#include <linux/slab.h>
57880+#include <linux/vmalloc.h>
57881+#include <linux/percpu.h>
57882+#include <linux/module.h>
57883+
57884+int grsec_enable_ptrace_readexec;
57885+int grsec_enable_setxid;
57886+int grsec_enable_symlinkown;
57887+int grsec_symlinkown_gid;
57888+int grsec_enable_brute;
57889+int grsec_enable_link;
57890+int grsec_enable_dmesg;
57891+int grsec_enable_harden_ptrace;
57892+int grsec_enable_fifo;
57893+int grsec_enable_execlog;
57894+int grsec_enable_signal;
57895+int grsec_enable_forkfail;
57896+int grsec_enable_audit_ptrace;
57897+int grsec_enable_time;
57898+int grsec_enable_audit_textrel;
57899+int grsec_enable_group;
57900+int grsec_audit_gid;
57901+int grsec_enable_chdir;
57902+int grsec_enable_mount;
57903+int grsec_enable_rofs;
57904+int grsec_enable_chroot_findtask;
57905+int grsec_enable_chroot_mount;
57906+int grsec_enable_chroot_shmat;
57907+int grsec_enable_chroot_fchdir;
57908+int grsec_enable_chroot_double;
57909+int grsec_enable_chroot_pivot;
57910+int grsec_enable_chroot_chdir;
57911+int grsec_enable_chroot_chmod;
57912+int grsec_enable_chroot_mknod;
57913+int grsec_enable_chroot_nice;
57914+int grsec_enable_chroot_execlog;
57915+int grsec_enable_chroot_caps;
57916+int grsec_enable_chroot_sysctl;
57917+int grsec_enable_chroot_unix;
57918+int grsec_enable_tpe;
57919+int grsec_tpe_gid;
57920+int grsec_enable_blackhole;
57921+#ifdef CONFIG_IPV6_MODULE
57922+EXPORT_SYMBOL(grsec_enable_blackhole);
57923+#endif
57924+int grsec_lastack_retries;
57925+int grsec_enable_tpe_all;
57926+int grsec_enable_tpe_invert;
57927+int grsec_enable_socket_all;
57928+int grsec_socket_all_gid;
57929+int grsec_enable_socket_client;
57930+int grsec_socket_client_gid;
57931+int grsec_enable_socket_server;
57932+int grsec_socket_server_gid;
57933+int grsec_resource_logging;
57934+int grsec_disable_privio;
57935+int grsec_enable_log_rwxmaps;
57936+int grsec_lock;
57937+
57938+DEFINE_SPINLOCK(grsec_alert_lock);
57939+unsigned long grsec_alert_wtime = 0;
57940+unsigned long grsec_alert_fyet = 0;
57941+
57942+DEFINE_SPINLOCK(grsec_audit_lock);
57943+
57944+DEFINE_RWLOCK(grsec_exec_file_lock);
57945+
57946+char *gr_shared_page[4];
57947+
57948+char *gr_alert_log_fmt;
57949+char *gr_audit_log_fmt;
57950+char *gr_alert_log_buf;
57951+char *gr_audit_log_buf;
57952+
57953+extern struct gr_arg *gr_usermode;
57954+extern unsigned char *gr_system_salt;
57955+extern unsigned char *gr_system_sum;
57956+
57957+void __init
57958+grsecurity_init(void)
57959+{
57960+ int j;
57961+ /* create the per-cpu shared pages */
57962+
57963+#ifdef CONFIG_X86
57964+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
57965+#endif
57966+
57967+ for (j = 0; j < 4; j++) {
57968+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
57969+ if (gr_shared_page[j] == NULL) {
57970+ panic("Unable to allocate grsecurity shared page");
57971+ return;
57972+ }
57973+ }
57974+
57975+ /* allocate log buffers */
57976+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
57977+ if (!gr_alert_log_fmt) {
57978+ panic("Unable to allocate grsecurity alert log format buffer");
57979+ return;
57980+ }
57981+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
57982+ if (!gr_audit_log_fmt) {
57983+ panic("Unable to allocate grsecurity audit log format buffer");
57984+ return;
57985+ }
57986+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57987+ if (!gr_alert_log_buf) {
57988+ panic("Unable to allocate grsecurity alert log buffer");
57989+ return;
57990+ }
57991+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57992+ if (!gr_audit_log_buf) {
57993+ panic("Unable to allocate grsecurity audit log buffer");
57994+ return;
57995+ }
57996+
57997+ /* allocate memory for authentication structure */
57998+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
57999+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
58000+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
58001+
58002+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
58003+ panic("Unable to allocate grsecurity authentication structure");
58004+ return;
58005+ }
58006+
58007+
58008+#ifdef CONFIG_GRKERNSEC_IO
58009+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
58010+ grsec_disable_privio = 1;
58011+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58012+ grsec_disable_privio = 1;
58013+#else
58014+ grsec_disable_privio = 0;
58015+#endif
58016+#endif
58017+
58018+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58019+ /* for backward compatibility, tpe_invert always defaults to on if
58020+ enabled in the kernel
58021+ */
58022+ grsec_enable_tpe_invert = 1;
58023+#endif
58024+
58025+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58026+#ifndef CONFIG_GRKERNSEC_SYSCTL
58027+ grsec_lock = 1;
58028+#endif
58029+
58030+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58031+ grsec_enable_audit_textrel = 1;
58032+#endif
58033+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58034+ grsec_enable_log_rwxmaps = 1;
58035+#endif
58036+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58037+ grsec_enable_group = 1;
58038+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
58039+#endif
58040+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58041+ grsec_enable_ptrace_readexec = 1;
58042+#endif
58043+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58044+ grsec_enable_chdir = 1;
58045+#endif
58046+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58047+ grsec_enable_harden_ptrace = 1;
58048+#endif
58049+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58050+ grsec_enable_mount = 1;
58051+#endif
58052+#ifdef CONFIG_GRKERNSEC_LINK
58053+ grsec_enable_link = 1;
58054+#endif
58055+#ifdef CONFIG_GRKERNSEC_BRUTE
58056+ grsec_enable_brute = 1;
58057+#endif
58058+#ifdef CONFIG_GRKERNSEC_DMESG
58059+ grsec_enable_dmesg = 1;
58060+#endif
58061+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58062+ grsec_enable_blackhole = 1;
58063+ grsec_lastack_retries = 4;
58064+#endif
58065+#ifdef CONFIG_GRKERNSEC_FIFO
58066+ grsec_enable_fifo = 1;
58067+#endif
58068+#ifdef CONFIG_GRKERNSEC_EXECLOG
58069+ grsec_enable_execlog = 1;
58070+#endif
58071+#ifdef CONFIG_GRKERNSEC_SETXID
58072+ grsec_enable_setxid = 1;
58073+#endif
58074+#ifdef CONFIG_GRKERNSEC_SIGNAL
58075+ grsec_enable_signal = 1;
58076+#endif
58077+#ifdef CONFIG_GRKERNSEC_FORKFAIL
58078+ grsec_enable_forkfail = 1;
58079+#endif
58080+#ifdef CONFIG_GRKERNSEC_TIME
58081+ grsec_enable_time = 1;
58082+#endif
58083+#ifdef CONFIG_GRKERNSEC_RESLOG
58084+ grsec_resource_logging = 1;
58085+#endif
58086+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58087+ grsec_enable_chroot_findtask = 1;
58088+#endif
58089+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58090+ grsec_enable_chroot_unix = 1;
58091+#endif
58092+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58093+ grsec_enable_chroot_mount = 1;
58094+#endif
58095+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58096+ grsec_enable_chroot_fchdir = 1;
58097+#endif
58098+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58099+ grsec_enable_chroot_shmat = 1;
58100+#endif
58101+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58102+ grsec_enable_audit_ptrace = 1;
58103+#endif
58104+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58105+ grsec_enable_chroot_double = 1;
58106+#endif
58107+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58108+ grsec_enable_chroot_pivot = 1;
58109+#endif
58110+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58111+ grsec_enable_chroot_chdir = 1;
58112+#endif
58113+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58114+ grsec_enable_chroot_chmod = 1;
58115+#endif
58116+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58117+ grsec_enable_chroot_mknod = 1;
58118+#endif
58119+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58120+ grsec_enable_chroot_nice = 1;
58121+#endif
58122+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58123+ grsec_enable_chroot_execlog = 1;
58124+#endif
58125+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58126+ grsec_enable_chroot_caps = 1;
58127+#endif
58128+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58129+ grsec_enable_chroot_sysctl = 1;
58130+#endif
58131+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58132+ grsec_enable_symlinkown = 1;
58133+ grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
58134+#endif
58135+#ifdef CONFIG_GRKERNSEC_TPE
58136+ grsec_enable_tpe = 1;
58137+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58138+#ifdef CONFIG_GRKERNSEC_TPE_ALL
58139+ grsec_enable_tpe_all = 1;
58140+#endif
58141+#endif
58142+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58143+ grsec_enable_socket_all = 1;
58144+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58145+#endif
58146+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58147+ grsec_enable_socket_client = 1;
58148+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58149+#endif
58150+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58151+ grsec_enable_socket_server = 1;
58152+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58153+#endif
58154+#endif
58155+
58156+ return;
58157+}
58158diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
58159new file mode 100644
58160index 0000000..589481f
58161--- /dev/null
58162+++ b/grsecurity/grsec_link.c
58163@@ -0,0 +1,58 @@
58164+#include <linux/kernel.h>
58165+#include <linux/sched.h>
58166+#include <linux/fs.h>
58167+#include <linux/file.h>
58168+#include <linux/grinternal.h>
58169+
58170+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
58171+{
58172+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58173+ const struct inode *link_inode = link->dentry->d_inode;
58174+
58175+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
58176+ /* ignore root-owned links, e.g. /proc/self */
58177+ !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
58178+ !uid_eq(link_inode->i_uid, target->i_uid)) {
58179+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
58180+ return 1;
58181+ }
58182+#endif
58183+ return 0;
58184+}
58185+
58186+int
58187+gr_handle_follow_link(const struct inode *parent,
58188+ const struct inode *inode,
58189+ const struct dentry *dentry, const struct vfsmount *mnt)
58190+{
58191+#ifdef CONFIG_GRKERNSEC_LINK
58192+ const struct cred *cred = current_cred();
58193+
58194+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58195+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
58196+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
58197+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58198+ return -EACCES;
58199+ }
58200+#endif
58201+ return 0;
58202+}
58203+
58204+int
58205+gr_handle_hardlink(const struct dentry *dentry,
58206+ const struct vfsmount *mnt,
58207+ struct inode *inode, const int mode, const char *to)
58208+{
58209+#ifdef CONFIG_GRKERNSEC_LINK
58210+ const struct cred *cred = current_cred();
58211+
58212+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
58213+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
58214+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58215+ !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
58216+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
58217+ return -EPERM;
58218+ }
58219+#endif
58220+ return 0;
58221+}
58222diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
58223new file mode 100644
58224index 0000000..a45d2e9
58225--- /dev/null
58226+++ b/grsecurity/grsec_log.c
58227@@ -0,0 +1,322 @@
58228+#include <linux/kernel.h>
58229+#include <linux/sched.h>
58230+#include <linux/file.h>
58231+#include <linux/tty.h>
58232+#include <linux/fs.h>
58233+#include <linux/grinternal.h>
58234+
58235+#ifdef CONFIG_TREE_PREEMPT_RCU
58236+#define DISABLE_PREEMPT() preempt_disable()
58237+#define ENABLE_PREEMPT() preempt_enable()
58238+#else
58239+#define DISABLE_PREEMPT()
58240+#define ENABLE_PREEMPT()
58241+#endif
58242+
58243+#define BEGIN_LOCKS(x) \
58244+ DISABLE_PREEMPT(); \
58245+ rcu_read_lock(); \
58246+ read_lock(&tasklist_lock); \
58247+ read_lock(&grsec_exec_file_lock); \
58248+ if (x != GR_DO_AUDIT) \
58249+ spin_lock(&grsec_alert_lock); \
58250+ else \
58251+ spin_lock(&grsec_audit_lock)
58252+
58253+#define END_LOCKS(x) \
58254+ if (x != GR_DO_AUDIT) \
58255+ spin_unlock(&grsec_alert_lock); \
58256+ else \
58257+ spin_unlock(&grsec_audit_lock); \
58258+ read_unlock(&grsec_exec_file_lock); \
58259+ read_unlock(&tasklist_lock); \
58260+ rcu_read_unlock(); \
58261+ ENABLE_PREEMPT(); \
58262+ if (x == GR_DONT_AUDIT) \
58263+ gr_handle_alertkill(current)
58264+
58265+enum {
58266+ FLOODING,
58267+ NO_FLOODING
58268+};
58269+
58270+extern char *gr_alert_log_fmt;
58271+extern char *gr_audit_log_fmt;
58272+extern char *gr_alert_log_buf;
58273+extern char *gr_audit_log_buf;
58274+
58275+static int gr_log_start(int audit)
58276+{
58277+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58278+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58279+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58280+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
58281+ unsigned long curr_secs = get_seconds();
58282+
58283+ if (audit == GR_DO_AUDIT)
58284+ goto set_fmt;
58285+
58286+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
58287+ grsec_alert_wtime = curr_secs;
58288+ grsec_alert_fyet = 0;
58289+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
58290+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58291+ grsec_alert_fyet++;
58292+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58293+ grsec_alert_wtime = curr_secs;
58294+ grsec_alert_fyet++;
58295+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58296+ return FLOODING;
58297+ }
58298+ else return FLOODING;
58299+
58300+set_fmt:
58301+#endif
58302+ memset(buf, 0, PAGE_SIZE);
58303+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
58304+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58305+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58306+ } else if (current->signal->curr_ip) {
58307+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58308+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58309+ } else if (gr_acl_is_enabled()) {
58310+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58311+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58312+ } else {
58313+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
58314+ strcpy(buf, fmt);
58315+ }
58316+
58317+ return NO_FLOODING;
58318+}
58319+
58320+static void gr_log_middle(int audit, const char *msg, va_list ap)
58321+ __attribute__ ((format (printf, 2, 0)));
58322+
58323+static void gr_log_middle(int audit, const char *msg, va_list ap)
58324+{
58325+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58326+ unsigned int len = strlen(buf);
58327+
58328+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58329+
58330+ return;
58331+}
58332+
58333+static void gr_log_middle_varargs(int audit, const char *msg, ...)
58334+ __attribute__ ((format (printf, 2, 3)));
58335+
58336+static void gr_log_middle_varargs(int audit, const char *msg, ...)
58337+{
58338+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58339+ unsigned int len = strlen(buf);
58340+ va_list ap;
58341+
58342+ va_start(ap, msg);
58343+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58344+ va_end(ap);
58345+
58346+ return;
58347+}
58348+
58349+static void gr_log_end(int audit, int append_default)
58350+{
58351+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58352+
58353+ if (append_default) {
58354+ unsigned int len = strlen(buf);
58355+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58356+ }
58357+
58358+ printk("%s\n", buf);
58359+
58360+ return;
58361+}
58362+
58363+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58364+{
58365+ int logtype;
58366+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58367+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58368+ void *voidptr = NULL;
58369+ int num1 = 0, num2 = 0;
58370+ unsigned long ulong1 = 0, ulong2 = 0;
58371+ struct dentry *dentry = NULL;
58372+ struct vfsmount *mnt = NULL;
58373+ struct file *file = NULL;
58374+ struct task_struct *task = NULL;
58375+ const struct cred *cred, *pcred;
58376+ va_list ap;
58377+
58378+ BEGIN_LOCKS(audit);
58379+ logtype = gr_log_start(audit);
58380+ if (logtype == FLOODING) {
58381+ END_LOCKS(audit);
58382+ return;
58383+ }
58384+ va_start(ap, argtypes);
58385+ switch (argtypes) {
58386+ case GR_TTYSNIFF:
58387+ task = va_arg(ap, struct task_struct *);
58388+ 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);
58389+ break;
58390+ case GR_SYSCTL_HIDDEN:
58391+ str1 = va_arg(ap, char *);
58392+ gr_log_middle_varargs(audit, msg, result, str1);
58393+ break;
58394+ case GR_RBAC:
58395+ dentry = va_arg(ap, struct dentry *);
58396+ mnt = va_arg(ap, struct vfsmount *);
58397+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58398+ break;
58399+ case GR_RBAC_STR:
58400+ dentry = va_arg(ap, struct dentry *);
58401+ mnt = va_arg(ap, struct vfsmount *);
58402+ str1 = va_arg(ap, char *);
58403+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58404+ break;
58405+ case GR_STR_RBAC:
58406+ str1 = va_arg(ap, char *);
58407+ dentry = va_arg(ap, struct dentry *);
58408+ mnt = va_arg(ap, struct vfsmount *);
58409+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
58410+ break;
58411+ case GR_RBAC_MODE2:
58412+ dentry = va_arg(ap, struct dentry *);
58413+ mnt = va_arg(ap, struct vfsmount *);
58414+ str1 = va_arg(ap, char *);
58415+ str2 = va_arg(ap, char *);
58416+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
58417+ break;
58418+ case GR_RBAC_MODE3:
58419+ dentry = va_arg(ap, struct dentry *);
58420+ mnt = va_arg(ap, struct vfsmount *);
58421+ str1 = va_arg(ap, char *);
58422+ str2 = va_arg(ap, char *);
58423+ str3 = va_arg(ap, char *);
58424+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
58425+ break;
58426+ case GR_FILENAME:
58427+ dentry = va_arg(ap, struct dentry *);
58428+ mnt = va_arg(ap, struct vfsmount *);
58429+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
58430+ break;
58431+ case GR_STR_FILENAME:
58432+ str1 = va_arg(ap, char *);
58433+ dentry = va_arg(ap, struct dentry *);
58434+ mnt = va_arg(ap, struct vfsmount *);
58435+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
58436+ break;
58437+ case GR_FILENAME_STR:
58438+ dentry = va_arg(ap, struct dentry *);
58439+ mnt = va_arg(ap, struct vfsmount *);
58440+ str1 = va_arg(ap, char *);
58441+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
58442+ break;
58443+ case GR_FILENAME_TWO_INT:
58444+ dentry = va_arg(ap, struct dentry *);
58445+ mnt = va_arg(ap, struct vfsmount *);
58446+ num1 = va_arg(ap, int);
58447+ num2 = va_arg(ap, int);
58448+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
58449+ break;
58450+ case GR_FILENAME_TWO_INT_STR:
58451+ dentry = va_arg(ap, struct dentry *);
58452+ mnt = va_arg(ap, struct vfsmount *);
58453+ num1 = va_arg(ap, int);
58454+ num2 = va_arg(ap, int);
58455+ str1 = va_arg(ap, char *);
58456+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
58457+ break;
58458+ case GR_TEXTREL:
58459+ file = va_arg(ap, struct file *);
58460+ ulong1 = va_arg(ap, unsigned long);
58461+ ulong2 = va_arg(ap, unsigned long);
58462+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
58463+ break;
58464+ case GR_PTRACE:
58465+ task = va_arg(ap, struct task_struct *);
58466+ 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);
58467+ break;
58468+ case GR_RESOURCE:
58469+ task = va_arg(ap, struct task_struct *);
58470+ cred = __task_cred(task);
58471+ pcred = __task_cred(task->real_parent);
58472+ ulong1 = va_arg(ap, unsigned long);
58473+ str1 = va_arg(ap, char *);
58474+ ulong2 = va_arg(ap, unsigned long);
58475+ 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);
58476+ break;
58477+ case GR_CAP:
58478+ task = va_arg(ap, struct task_struct *);
58479+ cred = __task_cred(task);
58480+ pcred = __task_cred(task->real_parent);
58481+ str1 = va_arg(ap, char *);
58482+ 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);
58483+ break;
58484+ case GR_SIG:
58485+ str1 = va_arg(ap, char *);
58486+ voidptr = va_arg(ap, void *);
58487+ gr_log_middle_varargs(audit, msg, str1, voidptr);
58488+ break;
58489+ case GR_SIG2:
58490+ task = va_arg(ap, struct task_struct *);
58491+ cred = __task_cred(task);
58492+ pcred = __task_cred(task->real_parent);
58493+ num1 = va_arg(ap, int);
58494+ 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);
58495+ break;
58496+ case GR_CRASH1:
58497+ task = va_arg(ap, struct task_struct *);
58498+ cred = __task_cred(task);
58499+ pcred = __task_cred(task->real_parent);
58500+ ulong1 = va_arg(ap, unsigned long);
58501+ 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);
58502+ break;
58503+ case GR_CRASH2:
58504+ task = va_arg(ap, struct task_struct *);
58505+ cred = __task_cred(task);
58506+ pcred = __task_cred(task->real_parent);
58507+ ulong1 = va_arg(ap, unsigned long);
58508+ 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);
58509+ break;
58510+ case GR_RWXMAP:
58511+ file = va_arg(ap, struct file *);
58512+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
58513+ break;
58514+ case GR_PSACCT:
58515+ {
58516+ unsigned int wday, cday;
58517+ __u8 whr, chr;
58518+ __u8 wmin, cmin;
58519+ __u8 wsec, csec;
58520+ char cur_tty[64] = { 0 };
58521+ char parent_tty[64] = { 0 };
58522+
58523+ task = va_arg(ap, struct task_struct *);
58524+ wday = va_arg(ap, unsigned int);
58525+ cday = va_arg(ap, unsigned int);
58526+ whr = va_arg(ap, int);
58527+ chr = va_arg(ap, int);
58528+ wmin = va_arg(ap, int);
58529+ cmin = va_arg(ap, int);
58530+ wsec = va_arg(ap, int);
58531+ csec = va_arg(ap, int);
58532+ ulong1 = va_arg(ap, unsigned long);
58533+ cred = __task_cred(task);
58534+ pcred = __task_cred(task->real_parent);
58535+
58536+ 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);
58537+ }
58538+ break;
58539+ default:
58540+ gr_log_middle(audit, msg, ap);
58541+ }
58542+ va_end(ap);
58543+ // these don't need DEFAULTSECARGS printed on the end
58544+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
58545+ gr_log_end(audit, 0);
58546+ else
58547+ gr_log_end(audit, 1);
58548+ END_LOCKS(audit);
58549+}
58550diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
58551new file mode 100644
58552index 0000000..f536303
58553--- /dev/null
58554+++ b/grsecurity/grsec_mem.c
58555@@ -0,0 +1,40 @@
58556+#include <linux/kernel.h>
58557+#include <linux/sched.h>
58558+#include <linux/mm.h>
58559+#include <linux/mman.h>
58560+#include <linux/grinternal.h>
58561+
58562+void
58563+gr_handle_ioperm(void)
58564+{
58565+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
58566+ return;
58567+}
58568+
58569+void
58570+gr_handle_iopl(void)
58571+{
58572+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
58573+ return;
58574+}
58575+
58576+void
58577+gr_handle_mem_readwrite(u64 from, u64 to)
58578+{
58579+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
58580+ return;
58581+}
58582+
58583+void
58584+gr_handle_vm86(void)
58585+{
58586+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
58587+ return;
58588+}
58589+
58590+void
58591+gr_log_badprocpid(const char *entry)
58592+{
58593+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
58594+ return;
58595+}
58596diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
58597new file mode 100644
58598index 0000000..2131422
58599--- /dev/null
58600+++ b/grsecurity/grsec_mount.c
58601@@ -0,0 +1,62 @@
58602+#include <linux/kernel.h>
58603+#include <linux/sched.h>
58604+#include <linux/mount.h>
58605+#include <linux/grsecurity.h>
58606+#include <linux/grinternal.h>
58607+
58608+void
58609+gr_log_remount(const char *devname, const int retval)
58610+{
58611+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58612+ if (grsec_enable_mount && (retval >= 0))
58613+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
58614+#endif
58615+ return;
58616+}
58617+
58618+void
58619+gr_log_unmount(const char *devname, const int retval)
58620+{
58621+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58622+ if (grsec_enable_mount && (retval >= 0))
58623+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
58624+#endif
58625+ return;
58626+}
58627+
58628+void
58629+gr_log_mount(const char *from, const char *to, const int retval)
58630+{
58631+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58632+ if (grsec_enable_mount && (retval >= 0))
58633+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
58634+#endif
58635+ return;
58636+}
58637+
58638+int
58639+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
58640+{
58641+#ifdef CONFIG_GRKERNSEC_ROFS
58642+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
58643+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
58644+ return -EPERM;
58645+ } else
58646+ return 0;
58647+#endif
58648+ return 0;
58649+}
58650+
58651+int
58652+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
58653+{
58654+#ifdef CONFIG_GRKERNSEC_ROFS
58655+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
58656+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
58657+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
58658+ return -EPERM;
58659+ } else
58660+ return 0;
58661+#endif
58662+ return 0;
58663+}
58664diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
58665new file mode 100644
58666index 0000000..a3b12a0
58667--- /dev/null
58668+++ b/grsecurity/grsec_pax.c
58669@@ -0,0 +1,36 @@
58670+#include <linux/kernel.h>
58671+#include <linux/sched.h>
58672+#include <linux/mm.h>
58673+#include <linux/file.h>
58674+#include <linux/grinternal.h>
58675+#include <linux/grsecurity.h>
58676+
58677+void
58678+gr_log_textrel(struct vm_area_struct * vma)
58679+{
58680+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58681+ if (grsec_enable_audit_textrel)
58682+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
58683+#endif
58684+ return;
58685+}
58686+
58687+void
58688+gr_log_rwxmmap(struct file *file)
58689+{
58690+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58691+ if (grsec_enable_log_rwxmaps)
58692+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
58693+#endif
58694+ return;
58695+}
58696+
58697+void
58698+gr_log_rwxmprotect(struct file *file)
58699+{
58700+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58701+ if (grsec_enable_log_rwxmaps)
58702+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
58703+#endif
58704+ return;
58705+}
58706diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
58707new file mode 100644
58708index 0000000..f7f29aa
58709--- /dev/null
58710+++ b/grsecurity/grsec_ptrace.c
58711@@ -0,0 +1,30 @@
58712+#include <linux/kernel.h>
58713+#include <linux/sched.h>
58714+#include <linux/grinternal.h>
58715+#include <linux/security.h>
58716+
58717+void
58718+gr_audit_ptrace(struct task_struct *task)
58719+{
58720+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58721+ if (grsec_enable_audit_ptrace)
58722+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
58723+#endif
58724+ return;
58725+}
58726+
58727+int
58728+gr_ptrace_readexec(struct file *file, int unsafe_flags)
58729+{
58730+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58731+ const struct dentry *dentry = file->f_path.dentry;
58732+ const struct vfsmount *mnt = file->f_path.mnt;
58733+
58734+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
58735+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
58736+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
58737+ return -EACCES;
58738+ }
58739+#endif
58740+ return 0;
58741+}
58742diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
58743new file mode 100644
58744index 0000000..b4ac94c
58745--- /dev/null
58746+++ b/grsecurity/grsec_sig.c
58747@@ -0,0 +1,209 @@
58748+#include <linux/kernel.h>
58749+#include <linux/sched.h>
58750+#include <linux/delay.h>
58751+#include <linux/grsecurity.h>
58752+#include <linux/grinternal.h>
58753+#include <linux/hardirq.h>
58754+
58755+char *signames[] = {
58756+ [SIGSEGV] = "Segmentation fault",
58757+ [SIGILL] = "Illegal instruction",
58758+ [SIGABRT] = "Abort",
58759+ [SIGBUS] = "Invalid alignment/Bus error"
58760+};
58761+
58762+void
58763+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
58764+{
58765+#ifdef CONFIG_GRKERNSEC_SIGNAL
58766+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
58767+ (sig == SIGABRT) || (sig == SIGBUS))) {
58768+ if (t->pid == current->pid) {
58769+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
58770+ } else {
58771+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
58772+ }
58773+ }
58774+#endif
58775+ return;
58776+}
58777+
58778+int
58779+gr_handle_signal(const struct task_struct *p, const int sig)
58780+{
58781+#ifdef CONFIG_GRKERNSEC
58782+ /* ignore the 0 signal for protected task checks */
58783+ if (current->pid > 1 && sig && gr_check_protected_task(p)) {
58784+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
58785+ return -EPERM;
58786+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
58787+ return -EPERM;
58788+ }
58789+#endif
58790+ return 0;
58791+}
58792+
58793+#ifdef CONFIG_GRKERNSEC
58794+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
58795+
58796+int gr_fake_force_sig(int sig, struct task_struct *t)
58797+{
58798+ unsigned long int flags;
58799+ int ret, blocked, ignored;
58800+ struct k_sigaction *action;
58801+
58802+ spin_lock_irqsave(&t->sighand->siglock, flags);
58803+ action = &t->sighand->action[sig-1];
58804+ ignored = action->sa.sa_handler == SIG_IGN;
58805+ blocked = sigismember(&t->blocked, sig);
58806+ if (blocked || ignored) {
58807+ action->sa.sa_handler = SIG_DFL;
58808+ if (blocked) {
58809+ sigdelset(&t->blocked, sig);
58810+ recalc_sigpending_and_wake(t);
58811+ }
58812+ }
58813+ if (action->sa.sa_handler == SIG_DFL)
58814+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
58815+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
58816+
58817+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
58818+
58819+ return ret;
58820+}
58821+#endif
58822+
58823+#ifdef CONFIG_GRKERNSEC_BRUTE
58824+#define GR_USER_BAN_TIME (15 * 60)
58825+
58826+static int __get_dumpable(unsigned long mm_flags)
58827+{
58828+ int ret;
58829+
58830+ ret = mm_flags & MMF_DUMPABLE_MASK;
58831+ return (ret >= 2) ? 2 : ret;
58832+}
58833+#endif
58834+
58835+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
58836+{
58837+#ifdef CONFIG_GRKERNSEC_BRUTE
58838+ kuid_t uid = GLOBAL_ROOT_UID;
58839+
58840+ if (!grsec_enable_brute)
58841+ return;
58842+
58843+ rcu_read_lock();
58844+ read_lock(&tasklist_lock);
58845+ read_lock(&grsec_exec_file_lock);
58846+ if (p->real_parent && p->real_parent->exec_file == p->exec_file)
58847+ p->real_parent->brute = 1;
58848+ else {
58849+ const struct cred *cred = __task_cred(p), *cred2;
58850+ struct task_struct *tsk, *tsk2;
58851+
58852+ if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
58853+ struct user_struct *user;
58854+
58855+ uid = cred->uid;
58856+
58857+ /* this is put upon execution past expiration */
58858+ user = find_user(uid);
58859+ if (user == NULL)
58860+ goto unlock;
58861+ user->banned = 1;
58862+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
58863+ if (user->ban_expires == ~0UL)
58864+ user->ban_expires--;
58865+
58866+ do_each_thread(tsk2, tsk) {
58867+ cred2 = __task_cred(tsk);
58868+ if (tsk != p && uid_eq(cred2->uid, uid))
58869+ gr_fake_force_sig(SIGKILL, tsk);
58870+ } while_each_thread(tsk2, tsk);
58871+ }
58872+ }
58873+unlock:
58874+ read_unlock(&grsec_exec_file_lock);
58875+ read_unlock(&tasklist_lock);
58876+ rcu_read_unlock();
58877+
58878+ if (!uid_eq(uid, GLOBAL_ROOT_UID))
58879+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
58880+ from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
58881+
58882+#endif
58883+ return;
58884+}
58885+
58886+void gr_handle_brute_check(void)
58887+{
58888+#ifdef CONFIG_GRKERNSEC_BRUTE
58889+ if (current->brute)
58890+ msleep(30 * 1000);
58891+#endif
58892+ return;
58893+}
58894+
58895+void gr_handle_kernel_exploit(void)
58896+{
58897+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
58898+ const struct cred *cred;
58899+ struct task_struct *tsk, *tsk2;
58900+ struct user_struct *user;
58901+ kuid_t uid;
58902+
58903+ if (in_irq() || in_serving_softirq() || in_nmi())
58904+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
58905+
58906+ uid = current_uid();
58907+
58908+ if (uid_eq(uid, GLOBAL_ROOT_UID))
58909+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
58910+ else {
58911+ /* kill all the processes of this user, hold a reference
58912+ to their creds struct, and prevent them from creating
58913+ another process until system reset
58914+ */
58915+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
58916+ from_kuid_munged(&init_user_ns, uid));
58917+ /* we intentionally leak this ref */
58918+ user = get_uid(current->cred->user);
58919+ if (user) {
58920+ user->banned = 1;
58921+ user->ban_expires = ~0UL;
58922+ }
58923+
58924+ read_lock(&tasklist_lock);
58925+ do_each_thread(tsk2, tsk) {
58926+ cred = __task_cred(tsk);
58927+ if (uid_eq(cred->uid, uid))
58928+ gr_fake_force_sig(SIGKILL, tsk);
58929+ } while_each_thread(tsk2, tsk);
58930+ read_unlock(&tasklist_lock);
58931+ }
58932+#endif
58933+}
58934+
58935+int __gr_process_user_ban(struct user_struct *user)
58936+{
58937+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58938+ if (unlikely(user->banned)) {
58939+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
58940+ user->banned = 0;
58941+ user->ban_expires = 0;
58942+ free_uid(user);
58943+ } else
58944+ return -EPERM;
58945+ }
58946+#endif
58947+ return 0;
58948+}
58949+
58950+int gr_process_user_ban(void)
58951+{
58952+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58953+ return __gr_process_user_ban(current->cred->user);
58954+#endif
58955+ return 0;
58956+}
58957diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
58958new file mode 100644
58959index 0000000..4030d57
58960--- /dev/null
58961+++ b/grsecurity/grsec_sock.c
58962@@ -0,0 +1,244 @@
58963+#include <linux/kernel.h>
58964+#include <linux/module.h>
58965+#include <linux/sched.h>
58966+#include <linux/file.h>
58967+#include <linux/net.h>
58968+#include <linux/in.h>
58969+#include <linux/ip.h>
58970+#include <net/sock.h>
58971+#include <net/inet_sock.h>
58972+#include <linux/grsecurity.h>
58973+#include <linux/grinternal.h>
58974+#include <linux/gracl.h>
58975+
58976+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
58977+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
58978+
58979+EXPORT_SYMBOL(gr_search_udp_recvmsg);
58980+EXPORT_SYMBOL(gr_search_udp_sendmsg);
58981+
58982+#ifdef CONFIG_UNIX_MODULE
58983+EXPORT_SYMBOL(gr_acl_handle_unix);
58984+EXPORT_SYMBOL(gr_acl_handle_mknod);
58985+EXPORT_SYMBOL(gr_handle_chroot_unix);
58986+EXPORT_SYMBOL(gr_handle_create);
58987+#endif
58988+
58989+#ifdef CONFIG_GRKERNSEC
58990+#define gr_conn_table_size 32749
58991+struct conn_table_entry {
58992+ struct conn_table_entry *next;
58993+ struct signal_struct *sig;
58994+};
58995+
58996+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
58997+DEFINE_SPINLOCK(gr_conn_table_lock);
58998+
58999+extern const char * gr_socktype_to_name(unsigned char type);
59000+extern const char * gr_proto_to_name(unsigned char proto);
59001+extern const char * gr_sockfamily_to_name(unsigned char family);
59002+
59003+static __inline__ int
59004+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
59005+{
59006+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
59007+}
59008+
59009+static __inline__ int
59010+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
59011+ __u16 sport, __u16 dport)
59012+{
59013+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
59014+ sig->gr_sport == sport && sig->gr_dport == dport))
59015+ return 1;
59016+ else
59017+ return 0;
59018+}
59019+
59020+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
59021+{
59022+ struct conn_table_entry **match;
59023+ unsigned int index;
59024+
59025+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59026+ sig->gr_sport, sig->gr_dport,
59027+ gr_conn_table_size);
59028+
59029+ newent->sig = sig;
59030+
59031+ match = &gr_conn_table[index];
59032+ newent->next = *match;
59033+ *match = newent;
59034+
59035+ return;
59036+}
59037+
59038+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
59039+{
59040+ struct conn_table_entry *match, *last = NULL;
59041+ unsigned int index;
59042+
59043+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59044+ sig->gr_sport, sig->gr_dport,
59045+ gr_conn_table_size);
59046+
59047+ match = gr_conn_table[index];
59048+ while (match && !conn_match(match->sig,
59049+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
59050+ sig->gr_dport)) {
59051+ last = match;
59052+ match = match->next;
59053+ }
59054+
59055+ if (match) {
59056+ if (last)
59057+ last->next = match->next;
59058+ else
59059+ gr_conn_table[index] = NULL;
59060+ kfree(match);
59061+ }
59062+
59063+ return;
59064+}
59065+
59066+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
59067+ __u16 sport, __u16 dport)
59068+{
59069+ struct conn_table_entry *match;
59070+ unsigned int index;
59071+
59072+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
59073+
59074+ match = gr_conn_table[index];
59075+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
59076+ match = match->next;
59077+
59078+ if (match)
59079+ return match->sig;
59080+ else
59081+ return NULL;
59082+}
59083+
59084+#endif
59085+
59086+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59087+{
59088+#ifdef CONFIG_GRKERNSEC
59089+ struct signal_struct *sig = task->signal;
59090+ struct conn_table_entry *newent;
59091+
59092+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59093+ if (newent == NULL)
59094+ return;
59095+ /* no bh lock needed since we are called with bh disabled */
59096+ spin_lock(&gr_conn_table_lock);
59097+ gr_del_task_from_ip_table_nolock(sig);
59098+ sig->gr_saddr = inet->inet_rcv_saddr;
59099+ sig->gr_daddr = inet->inet_daddr;
59100+ sig->gr_sport = inet->inet_sport;
59101+ sig->gr_dport = inet->inet_dport;
59102+ gr_add_to_task_ip_table_nolock(sig, newent);
59103+ spin_unlock(&gr_conn_table_lock);
59104+#endif
59105+ return;
59106+}
59107+
59108+void gr_del_task_from_ip_table(struct task_struct *task)
59109+{
59110+#ifdef CONFIG_GRKERNSEC
59111+ spin_lock_bh(&gr_conn_table_lock);
59112+ gr_del_task_from_ip_table_nolock(task->signal);
59113+ spin_unlock_bh(&gr_conn_table_lock);
59114+#endif
59115+ return;
59116+}
59117+
59118+void
59119+gr_attach_curr_ip(const struct sock *sk)
59120+{
59121+#ifdef CONFIG_GRKERNSEC
59122+ struct signal_struct *p, *set;
59123+ const struct inet_sock *inet = inet_sk(sk);
59124+
59125+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59126+ return;
59127+
59128+ set = current->signal;
59129+
59130+ spin_lock_bh(&gr_conn_table_lock);
59131+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59132+ inet->inet_dport, inet->inet_sport);
59133+ if (unlikely(p != NULL)) {
59134+ set->curr_ip = p->curr_ip;
59135+ set->used_accept = 1;
59136+ gr_del_task_from_ip_table_nolock(p);
59137+ spin_unlock_bh(&gr_conn_table_lock);
59138+ return;
59139+ }
59140+ spin_unlock_bh(&gr_conn_table_lock);
59141+
59142+ set->curr_ip = inet->inet_daddr;
59143+ set->used_accept = 1;
59144+#endif
59145+ return;
59146+}
59147+
59148+int
59149+gr_handle_sock_all(const int family, const int type, const int protocol)
59150+{
59151+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59152+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59153+ (family != AF_UNIX)) {
59154+ if (family == AF_INET)
59155+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59156+ else
59157+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59158+ return -EACCES;
59159+ }
59160+#endif
59161+ return 0;
59162+}
59163+
59164+int
59165+gr_handle_sock_server(const struct sockaddr *sck)
59166+{
59167+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59168+ if (grsec_enable_socket_server &&
59169+ in_group_p(grsec_socket_server_gid) &&
59170+ sck && (sck->sa_family != AF_UNIX) &&
59171+ (sck->sa_family != AF_LOCAL)) {
59172+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59173+ return -EACCES;
59174+ }
59175+#endif
59176+ return 0;
59177+}
59178+
59179+int
59180+gr_handle_sock_server_other(const struct sock *sck)
59181+{
59182+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59183+ if (grsec_enable_socket_server &&
59184+ in_group_p(grsec_socket_server_gid) &&
59185+ sck && (sck->sk_family != AF_UNIX) &&
59186+ (sck->sk_family != AF_LOCAL)) {
59187+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59188+ return -EACCES;
59189+ }
59190+#endif
59191+ return 0;
59192+}
59193+
59194+int
59195+gr_handle_sock_client(const struct sockaddr *sck)
59196+{
59197+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59198+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59199+ sck && (sck->sa_family != AF_UNIX) &&
59200+ (sck->sa_family != AF_LOCAL)) {
59201+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59202+ return -EACCES;
59203+ }
59204+#endif
59205+ return 0;
59206+}
59207diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
59208new file mode 100644
59209index 0000000..f55ef0f
59210--- /dev/null
59211+++ b/grsecurity/grsec_sysctl.c
59212@@ -0,0 +1,469 @@
59213+#include <linux/kernel.h>
59214+#include <linux/sched.h>
59215+#include <linux/sysctl.h>
59216+#include <linux/grsecurity.h>
59217+#include <linux/grinternal.h>
59218+
59219+int
59220+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59221+{
59222+#ifdef CONFIG_GRKERNSEC_SYSCTL
59223+ if (dirname == NULL || name == NULL)
59224+ return 0;
59225+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59226+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59227+ return -EACCES;
59228+ }
59229+#endif
59230+ return 0;
59231+}
59232+
59233+#ifdef CONFIG_GRKERNSEC_ROFS
59234+static int __maybe_unused one = 1;
59235+#endif
59236+
59237+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59238+struct ctl_table grsecurity_table[] = {
59239+#ifdef CONFIG_GRKERNSEC_SYSCTL
59240+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59241+#ifdef CONFIG_GRKERNSEC_IO
59242+ {
59243+ .procname = "disable_priv_io",
59244+ .data = &grsec_disable_privio,
59245+ .maxlen = sizeof(int),
59246+ .mode = 0600,
59247+ .proc_handler = &proc_dointvec,
59248+ },
59249+#endif
59250+#endif
59251+#ifdef CONFIG_GRKERNSEC_LINK
59252+ {
59253+ .procname = "linking_restrictions",
59254+ .data = &grsec_enable_link,
59255+ .maxlen = sizeof(int),
59256+ .mode = 0600,
59257+ .proc_handler = &proc_dointvec,
59258+ },
59259+#endif
59260+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59261+ {
59262+ .procname = "enforce_symlinksifowner",
59263+ .data = &grsec_enable_symlinkown,
59264+ .maxlen = sizeof(int),
59265+ .mode = 0600,
59266+ .proc_handler = &proc_dointvec,
59267+ },
59268+ {
59269+ .procname = "symlinkown_gid",
59270+ .data = &grsec_symlinkown_gid,
59271+ .maxlen = sizeof(int),
59272+ .mode = 0600,
59273+ .proc_handler = &proc_dointvec,
59274+ },
59275+#endif
59276+#ifdef CONFIG_GRKERNSEC_BRUTE
59277+ {
59278+ .procname = "deter_bruteforce",
59279+ .data = &grsec_enable_brute,
59280+ .maxlen = sizeof(int),
59281+ .mode = 0600,
59282+ .proc_handler = &proc_dointvec,
59283+ },
59284+#endif
59285+#ifdef CONFIG_GRKERNSEC_FIFO
59286+ {
59287+ .procname = "fifo_restrictions",
59288+ .data = &grsec_enable_fifo,
59289+ .maxlen = sizeof(int),
59290+ .mode = 0600,
59291+ .proc_handler = &proc_dointvec,
59292+ },
59293+#endif
59294+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59295+ {
59296+ .procname = "ptrace_readexec",
59297+ .data = &grsec_enable_ptrace_readexec,
59298+ .maxlen = sizeof(int),
59299+ .mode = 0600,
59300+ .proc_handler = &proc_dointvec,
59301+ },
59302+#endif
59303+#ifdef CONFIG_GRKERNSEC_SETXID
59304+ {
59305+ .procname = "consistent_setxid",
59306+ .data = &grsec_enable_setxid,
59307+ .maxlen = sizeof(int),
59308+ .mode = 0600,
59309+ .proc_handler = &proc_dointvec,
59310+ },
59311+#endif
59312+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59313+ {
59314+ .procname = "ip_blackhole",
59315+ .data = &grsec_enable_blackhole,
59316+ .maxlen = sizeof(int),
59317+ .mode = 0600,
59318+ .proc_handler = &proc_dointvec,
59319+ },
59320+ {
59321+ .procname = "lastack_retries",
59322+ .data = &grsec_lastack_retries,
59323+ .maxlen = sizeof(int),
59324+ .mode = 0600,
59325+ .proc_handler = &proc_dointvec,
59326+ },
59327+#endif
59328+#ifdef CONFIG_GRKERNSEC_EXECLOG
59329+ {
59330+ .procname = "exec_logging",
59331+ .data = &grsec_enable_execlog,
59332+ .maxlen = sizeof(int),
59333+ .mode = 0600,
59334+ .proc_handler = &proc_dointvec,
59335+ },
59336+#endif
59337+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59338+ {
59339+ .procname = "rwxmap_logging",
59340+ .data = &grsec_enable_log_rwxmaps,
59341+ .maxlen = sizeof(int),
59342+ .mode = 0600,
59343+ .proc_handler = &proc_dointvec,
59344+ },
59345+#endif
59346+#ifdef CONFIG_GRKERNSEC_SIGNAL
59347+ {
59348+ .procname = "signal_logging",
59349+ .data = &grsec_enable_signal,
59350+ .maxlen = sizeof(int),
59351+ .mode = 0600,
59352+ .proc_handler = &proc_dointvec,
59353+ },
59354+#endif
59355+#ifdef CONFIG_GRKERNSEC_FORKFAIL
59356+ {
59357+ .procname = "forkfail_logging",
59358+ .data = &grsec_enable_forkfail,
59359+ .maxlen = sizeof(int),
59360+ .mode = 0600,
59361+ .proc_handler = &proc_dointvec,
59362+ },
59363+#endif
59364+#ifdef CONFIG_GRKERNSEC_TIME
59365+ {
59366+ .procname = "timechange_logging",
59367+ .data = &grsec_enable_time,
59368+ .maxlen = sizeof(int),
59369+ .mode = 0600,
59370+ .proc_handler = &proc_dointvec,
59371+ },
59372+#endif
59373+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59374+ {
59375+ .procname = "chroot_deny_shmat",
59376+ .data = &grsec_enable_chroot_shmat,
59377+ .maxlen = sizeof(int),
59378+ .mode = 0600,
59379+ .proc_handler = &proc_dointvec,
59380+ },
59381+#endif
59382+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59383+ {
59384+ .procname = "chroot_deny_unix",
59385+ .data = &grsec_enable_chroot_unix,
59386+ .maxlen = sizeof(int),
59387+ .mode = 0600,
59388+ .proc_handler = &proc_dointvec,
59389+ },
59390+#endif
59391+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59392+ {
59393+ .procname = "chroot_deny_mount",
59394+ .data = &grsec_enable_chroot_mount,
59395+ .maxlen = sizeof(int),
59396+ .mode = 0600,
59397+ .proc_handler = &proc_dointvec,
59398+ },
59399+#endif
59400+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59401+ {
59402+ .procname = "chroot_deny_fchdir",
59403+ .data = &grsec_enable_chroot_fchdir,
59404+ .maxlen = sizeof(int),
59405+ .mode = 0600,
59406+ .proc_handler = &proc_dointvec,
59407+ },
59408+#endif
59409+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59410+ {
59411+ .procname = "chroot_deny_chroot",
59412+ .data = &grsec_enable_chroot_double,
59413+ .maxlen = sizeof(int),
59414+ .mode = 0600,
59415+ .proc_handler = &proc_dointvec,
59416+ },
59417+#endif
59418+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59419+ {
59420+ .procname = "chroot_deny_pivot",
59421+ .data = &grsec_enable_chroot_pivot,
59422+ .maxlen = sizeof(int),
59423+ .mode = 0600,
59424+ .proc_handler = &proc_dointvec,
59425+ },
59426+#endif
59427+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59428+ {
59429+ .procname = "chroot_enforce_chdir",
59430+ .data = &grsec_enable_chroot_chdir,
59431+ .maxlen = sizeof(int),
59432+ .mode = 0600,
59433+ .proc_handler = &proc_dointvec,
59434+ },
59435+#endif
59436+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59437+ {
59438+ .procname = "chroot_deny_chmod",
59439+ .data = &grsec_enable_chroot_chmod,
59440+ .maxlen = sizeof(int),
59441+ .mode = 0600,
59442+ .proc_handler = &proc_dointvec,
59443+ },
59444+#endif
59445+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59446+ {
59447+ .procname = "chroot_deny_mknod",
59448+ .data = &grsec_enable_chroot_mknod,
59449+ .maxlen = sizeof(int),
59450+ .mode = 0600,
59451+ .proc_handler = &proc_dointvec,
59452+ },
59453+#endif
59454+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59455+ {
59456+ .procname = "chroot_restrict_nice",
59457+ .data = &grsec_enable_chroot_nice,
59458+ .maxlen = sizeof(int),
59459+ .mode = 0600,
59460+ .proc_handler = &proc_dointvec,
59461+ },
59462+#endif
59463+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59464+ {
59465+ .procname = "chroot_execlog",
59466+ .data = &grsec_enable_chroot_execlog,
59467+ .maxlen = sizeof(int),
59468+ .mode = 0600,
59469+ .proc_handler = &proc_dointvec,
59470+ },
59471+#endif
59472+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59473+ {
59474+ .procname = "chroot_caps",
59475+ .data = &grsec_enable_chroot_caps,
59476+ .maxlen = sizeof(int),
59477+ .mode = 0600,
59478+ .proc_handler = &proc_dointvec,
59479+ },
59480+#endif
59481+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59482+ {
59483+ .procname = "chroot_deny_sysctl",
59484+ .data = &grsec_enable_chroot_sysctl,
59485+ .maxlen = sizeof(int),
59486+ .mode = 0600,
59487+ .proc_handler = &proc_dointvec,
59488+ },
59489+#endif
59490+#ifdef CONFIG_GRKERNSEC_TPE
59491+ {
59492+ .procname = "tpe",
59493+ .data = &grsec_enable_tpe,
59494+ .maxlen = sizeof(int),
59495+ .mode = 0600,
59496+ .proc_handler = &proc_dointvec,
59497+ },
59498+ {
59499+ .procname = "tpe_gid",
59500+ .data = &grsec_tpe_gid,
59501+ .maxlen = sizeof(int),
59502+ .mode = 0600,
59503+ .proc_handler = &proc_dointvec,
59504+ },
59505+#endif
59506+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59507+ {
59508+ .procname = "tpe_invert",
59509+ .data = &grsec_enable_tpe_invert,
59510+ .maxlen = sizeof(int),
59511+ .mode = 0600,
59512+ .proc_handler = &proc_dointvec,
59513+ },
59514+#endif
59515+#ifdef CONFIG_GRKERNSEC_TPE_ALL
59516+ {
59517+ .procname = "tpe_restrict_all",
59518+ .data = &grsec_enable_tpe_all,
59519+ .maxlen = sizeof(int),
59520+ .mode = 0600,
59521+ .proc_handler = &proc_dointvec,
59522+ },
59523+#endif
59524+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59525+ {
59526+ .procname = "socket_all",
59527+ .data = &grsec_enable_socket_all,
59528+ .maxlen = sizeof(int),
59529+ .mode = 0600,
59530+ .proc_handler = &proc_dointvec,
59531+ },
59532+ {
59533+ .procname = "socket_all_gid",
59534+ .data = &grsec_socket_all_gid,
59535+ .maxlen = sizeof(int),
59536+ .mode = 0600,
59537+ .proc_handler = &proc_dointvec,
59538+ },
59539+#endif
59540+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59541+ {
59542+ .procname = "socket_client",
59543+ .data = &grsec_enable_socket_client,
59544+ .maxlen = sizeof(int),
59545+ .mode = 0600,
59546+ .proc_handler = &proc_dointvec,
59547+ },
59548+ {
59549+ .procname = "socket_client_gid",
59550+ .data = &grsec_socket_client_gid,
59551+ .maxlen = sizeof(int),
59552+ .mode = 0600,
59553+ .proc_handler = &proc_dointvec,
59554+ },
59555+#endif
59556+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59557+ {
59558+ .procname = "socket_server",
59559+ .data = &grsec_enable_socket_server,
59560+ .maxlen = sizeof(int),
59561+ .mode = 0600,
59562+ .proc_handler = &proc_dointvec,
59563+ },
59564+ {
59565+ .procname = "socket_server_gid",
59566+ .data = &grsec_socket_server_gid,
59567+ .maxlen = sizeof(int),
59568+ .mode = 0600,
59569+ .proc_handler = &proc_dointvec,
59570+ },
59571+#endif
59572+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
59573+ {
59574+ .procname = "audit_group",
59575+ .data = &grsec_enable_group,
59576+ .maxlen = sizeof(int),
59577+ .mode = 0600,
59578+ .proc_handler = &proc_dointvec,
59579+ },
59580+ {
59581+ .procname = "audit_gid",
59582+ .data = &grsec_audit_gid,
59583+ .maxlen = sizeof(int),
59584+ .mode = 0600,
59585+ .proc_handler = &proc_dointvec,
59586+ },
59587+#endif
59588+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59589+ {
59590+ .procname = "audit_chdir",
59591+ .data = &grsec_enable_chdir,
59592+ .maxlen = sizeof(int),
59593+ .mode = 0600,
59594+ .proc_handler = &proc_dointvec,
59595+ },
59596+#endif
59597+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59598+ {
59599+ .procname = "audit_mount",
59600+ .data = &grsec_enable_mount,
59601+ .maxlen = sizeof(int),
59602+ .mode = 0600,
59603+ .proc_handler = &proc_dointvec,
59604+ },
59605+#endif
59606+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59607+ {
59608+ .procname = "audit_textrel",
59609+ .data = &grsec_enable_audit_textrel,
59610+ .maxlen = sizeof(int),
59611+ .mode = 0600,
59612+ .proc_handler = &proc_dointvec,
59613+ },
59614+#endif
59615+#ifdef CONFIG_GRKERNSEC_DMESG
59616+ {
59617+ .procname = "dmesg",
59618+ .data = &grsec_enable_dmesg,
59619+ .maxlen = sizeof(int),
59620+ .mode = 0600,
59621+ .proc_handler = &proc_dointvec,
59622+ },
59623+#endif
59624+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59625+ {
59626+ .procname = "chroot_findtask",
59627+ .data = &grsec_enable_chroot_findtask,
59628+ .maxlen = sizeof(int),
59629+ .mode = 0600,
59630+ .proc_handler = &proc_dointvec,
59631+ },
59632+#endif
59633+#ifdef CONFIG_GRKERNSEC_RESLOG
59634+ {
59635+ .procname = "resource_logging",
59636+ .data = &grsec_resource_logging,
59637+ .maxlen = sizeof(int),
59638+ .mode = 0600,
59639+ .proc_handler = &proc_dointvec,
59640+ },
59641+#endif
59642+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59643+ {
59644+ .procname = "audit_ptrace",
59645+ .data = &grsec_enable_audit_ptrace,
59646+ .maxlen = sizeof(int),
59647+ .mode = 0600,
59648+ .proc_handler = &proc_dointvec,
59649+ },
59650+#endif
59651+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59652+ {
59653+ .procname = "harden_ptrace",
59654+ .data = &grsec_enable_harden_ptrace,
59655+ .maxlen = sizeof(int),
59656+ .mode = 0600,
59657+ .proc_handler = &proc_dointvec,
59658+ },
59659+#endif
59660+ {
59661+ .procname = "grsec_lock",
59662+ .data = &grsec_lock,
59663+ .maxlen = sizeof(int),
59664+ .mode = 0600,
59665+ .proc_handler = &proc_dointvec,
59666+ },
59667+#endif
59668+#ifdef CONFIG_GRKERNSEC_ROFS
59669+ {
59670+ .procname = "romount_protect",
59671+ .data = &grsec_enable_rofs,
59672+ .maxlen = sizeof(int),
59673+ .mode = 0600,
59674+ .proc_handler = &proc_dointvec_minmax,
59675+ .extra1 = &one,
59676+ .extra2 = &one,
59677+ },
59678+#endif
59679+ { }
59680+};
59681+#endif
59682diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
59683new file mode 100644
59684index 0000000..0dc13c3
59685--- /dev/null
59686+++ b/grsecurity/grsec_time.c
59687@@ -0,0 +1,16 @@
59688+#include <linux/kernel.h>
59689+#include <linux/sched.h>
59690+#include <linux/grinternal.h>
59691+#include <linux/module.h>
59692+
59693+void
59694+gr_log_timechange(void)
59695+{
59696+#ifdef CONFIG_GRKERNSEC_TIME
59697+ if (grsec_enable_time)
59698+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
59699+#endif
59700+ return;
59701+}
59702+
59703+EXPORT_SYMBOL(gr_log_timechange);
59704diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
59705new file mode 100644
59706index 0000000..07e0dc0
59707--- /dev/null
59708+++ b/grsecurity/grsec_tpe.c
59709@@ -0,0 +1,73 @@
59710+#include <linux/kernel.h>
59711+#include <linux/sched.h>
59712+#include <linux/file.h>
59713+#include <linux/fs.h>
59714+#include <linux/grinternal.h>
59715+
59716+extern int gr_acl_tpe_check(void);
59717+
59718+int
59719+gr_tpe_allow(const struct file *file)
59720+{
59721+#ifdef CONFIG_GRKERNSEC
59722+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
59723+ const struct cred *cred = current_cred();
59724+ char *msg = NULL;
59725+ char *msg2 = NULL;
59726+
59727+ // never restrict root
59728+ if (!cred->uid)
59729+ return 1;
59730+
59731+ if (grsec_enable_tpe) {
59732+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59733+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
59734+ msg = "not being in trusted group";
59735+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
59736+ msg = "being in untrusted group";
59737+#else
59738+ if (in_group_p(grsec_tpe_gid))
59739+ msg = "being in untrusted group";
59740+#endif
59741+ }
59742+ if (!msg && gr_acl_tpe_check())
59743+ msg = "being in untrusted role";
59744+
59745+ // not in any affected group/role
59746+ if (!msg)
59747+ goto next_check;
59748+
59749+ if (inode->i_uid)
59750+ msg2 = "file in non-root-owned directory";
59751+ else if (inode->i_mode & S_IWOTH)
59752+ msg2 = "file in world-writable directory";
59753+ else if (inode->i_mode & S_IWGRP)
59754+ msg2 = "file in group-writable directory";
59755+
59756+ if (msg && msg2) {
59757+ char fullmsg[70] = {0};
59758+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
59759+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
59760+ return 0;
59761+ }
59762+ msg = NULL;
59763+next_check:
59764+#ifdef CONFIG_GRKERNSEC_TPE_ALL
59765+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
59766+ return 1;
59767+
59768+ if (inode->i_uid && (inode->i_uid != cred->uid))
59769+ msg = "directory not owned by user";
59770+ else if (inode->i_mode & S_IWOTH)
59771+ msg = "file in world-writable directory";
59772+ else if (inode->i_mode & S_IWGRP)
59773+ msg = "file in group-writable directory";
59774+
59775+ if (msg) {
59776+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
59777+ return 0;
59778+ }
59779+#endif
59780+#endif
59781+ return 1;
59782+}
59783diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
59784new file mode 100644
59785index 0000000..9f7b1ac
59786--- /dev/null
59787+++ b/grsecurity/grsum.c
59788@@ -0,0 +1,61 @@
59789+#include <linux/err.h>
59790+#include <linux/kernel.h>
59791+#include <linux/sched.h>
59792+#include <linux/mm.h>
59793+#include <linux/scatterlist.h>
59794+#include <linux/crypto.h>
59795+#include <linux/gracl.h>
59796+
59797+
59798+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
59799+#error "crypto and sha256 must be built into the kernel"
59800+#endif
59801+
59802+int
59803+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
59804+{
59805+ char *p;
59806+ struct crypto_hash *tfm;
59807+ struct hash_desc desc;
59808+ struct scatterlist sg;
59809+ unsigned char temp_sum[GR_SHA_LEN];
59810+ volatile int retval = 0;
59811+ volatile int dummy = 0;
59812+ unsigned int i;
59813+
59814+ sg_init_table(&sg, 1);
59815+
59816+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
59817+ if (IS_ERR(tfm)) {
59818+ /* should never happen, since sha256 should be built in */
59819+ return 1;
59820+ }
59821+
59822+ desc.tfm = tfm;
59823+ desc.flags = 0;
59824+
59825+ crypto_hash_init(&desc);
59826+
59827+ p = salt;
59828+ sg_set_buf(&sg, p, GR_SALT_LEN);
59829+ crypto_hash_update(&desc, &sg, sg.length);
59830+
59831+ p = entry->pw;
59832+ sg_set_buf(&sg, p, strlen(p));
59833+
59834+ crypto_hash_update(&desc, &sg, sg.length);
59835+
59836+ crypto_hash_final(&desc, temp_sum);
59837+
59838+ memset(entry->pw, 0, GR_PW_LEN);
59839+
59840+ for (i = 0; i < GR_SHA_LEN; i++)
59841+ if (sum[i] != temp_sum[i])
59842+ retval = 1;
59843+ else
59844+ dummy = 1; // waste a cycle
59845+
59846+ crypto_free_hash(tfm);
59847+
59848+ return retval;
59849+}
59850diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
59851index 9e6e1c6..d47b906 100644
59852--- a/include/acpi/acpi_bus.h
59853+++ b/include/acpi/acpi_bus.h
59854@@ -138,7 +138,7 @@ struct acpi_device_ops {
59855 acpi_op_bind bind;
59856 acpi_op_unbind unbind;
59857 acpi_op_notify notify;
59858-};
59859+} __no_const;
59860
59861 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
59862
59863diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
59864index b7babf0..3ba8aee 100644
59865--- a/include/asm-generic/atomic-long.h
59866+++ b/include/asm-generic/atomic-long.h
59867@@ -22,6 +22,12 @@
59868
59869 typedef atomic64_t atomic_long_t;
59870
59871+#ifdef CONFIG_PAX_REFCOUNT
59872+typedef atomic64_unchecked_t atomic_long_unchecked_t;
59873+#else
59874+typedef atomic64_t atomic_long_unchecked_t;
59875+#endif
59876+
59877 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
59878
59879 static inline long atomic_long_read(atomic_long_t *l)
59880@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59881 return (long)atomic64_read(v);
59882 }
59883
59884+#ifdef CONFIG_PAX_REFCOUNT
59885+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59886+{
59887+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59888+
59889+ return (long)atomic64_read_unchecked(v);
59890+}
59891+#endif
59892+
59893 static inline void atomic_long_set(atomic_long_t *l, long i)
59894 {
59895 atomic64_t *v = (atomic64_t *)l;
59896@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59897 atomic64_set(v, i);
59898 }
59899
59900+#ifdef CONFIG_PAX_REFCOUNT
59901+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59902+{
59903+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59904+
59905+ atomic64_set_unchecked(v, i);
59906+}
59907+#endif
59908+
59909 static inline void atomic_long_inc(atomic_long_t *l)
59910 {
59911 atomic64_t *v = (atomic64_t *)l;
59912@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59913 atomic64_inc(v);
59914 }
59915
59916+#ifdef CONFIG_PAX_REFCOUNT
59917+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59918+{
59919+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59920+
59921+ atomic64_inc_unchecked(v);
59922+}
59923+#endif
59924+
59925 static inline void atomic_long_dec(atomic_long_t *l)
59926 {
59927 atomic64_t *v = (atomic64_t *)l;
59928@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59929 atomic64_dec(v);
59930 }
59931
59932+#ifdef CONFIG_PAX_REFCOUNT
59933+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59934+{
59935+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59936+
59937+ atomic64_dec_unchecked(v);
59938+}
59939+#endif
59940+
59941 static inline void atomic_long_add(long i, atomic_long_t *l)
59942 {
59943 atomic64_t *v = (atomic64_t *)l;
59944@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59945 atomic64_add(i, v);
59946 }
59947
59948+#ifdef CONFIG_PAX_REFCOUNT
59949+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59950+{
59951+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59952+
59953+ atomic64_add_unchecked(i, v);
59954+}
59955+#endif
59956+
59957 static inline void atomic_long_sub(long i, atomic_long_t *l)
59958 {
59959 atomic64_t *v = (atomic64_t *)l;
59960@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59961 atomic64_sub(i, v);
59962 }
59963
59964+#ifdef CONFIG_PAX_REFCOUNT
59965+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59966+{
59967+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59968+
59969+ atomic64_sub_unchecked(i, v);
59970+}
59971+#endif
59972+
59973 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59974 {
59975 atomic64_t *v = (atomic64_t *)l;
59976@@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59977 return (long)atomic64_inc_return(v);
59978 }
59979
59980+#ifdef CONFIG_PAX_REFCOUNT
59981+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59982+{
59983+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59984+
59985+ return (long)atomic64_inc_return_unchecked(v);
59986+}
59987+#endif
59988+
59989 static inline long atomic_long_dec_return(atomic_long_t *l)
59990 {
59991 atomic64_t *v = (atomic64_t *)l;
59992@@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59993
59994 typedef atomic_t atomic_long_t;
59995
59996+#ifdef CONFIG_PAX_REFCOUNT
59997+typedef atomic_unchecked_t atomic_long_unchecked_t;
59998+#else
59999+typedef atomic_t atomic_long_unchecked_t;
60000+#endif
60001+
60002 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
60003 static inline long atomic_long_read(atomic_long_t *l)
60004 {
60005@@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60006 return (long)atomic_read(v);
60007 }
60008
60009+#ifdef CONFIG_PAX_REFCOUNT
60010+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60011+{
60012+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60013+
60014+ return (long)atomic_read_unchecked(v);
60015+}
60016+#endif
60017+
60018 static inline void atomic_long_set(atomic_long_t *l, long i)
60019 {
60020 atomic_t *v = (atomic_t *)l;
60021@@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60022 atomic_set(v, i);
60023 }
60024
60025+#ifdef CONFIG_PAX_REFCOUNT
60026+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60027+{
60028+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60029+
60030+ atomic_set_unchecked(v, i);
60031+}
60032+#endif
60033+
60034 static inline void atomic_long_inc(atomic_long_t *l)
60035 {
60036 atomic_t *v = (atomic_t *)l;
60037@@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60038 atomic_inc(v);
60039 }
60040
60041+#ifdef CONFIG_PAX_REFCOUNT
60042+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60043+{
60044+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60045+
60046+ atomic_inc_unchecked(v);
60047+}
60048+#endif
60049+
60050 static inline void atomic_long_dec(atomic_long_t *l)
60051 {
60052 atomic_t *v = (atomic_t *)l;
60053@@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60054 atomic_dec(v);
60055 }
60056
60057+#ifdef CONFIG_PAX_REFCOUNT
60058+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60059+{
60060+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60061+
60062+ atomic_dec_unchecked(v);
60063+}
60064+#endif
60065+
60066 static inline void atomic_long_add(long i, atomic_long_t *l)
60067 {
60068 atomic_t *v = (atomic_t *)l;
60069@@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60070 atomic_add(i, v);
60071 }
60072
60073+#ifdef CONFIG_PAX_REFCOUNT
60074+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60075+{
60076+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60077+
60078+ atomic_add_unchecked(i, v);
60079+}
60080+#endif
60081+
60082 static inline void atomic_long_sub(long i, atomic_long_t *l)
60083 {
60084 atomic_t *v = (atomic_t *)l;
60085@@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60086 atomic_sub(i, v);
60087 }
60088
60089+#ifdef CONFIG_PAX_REFCOUNT
60090+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60091+{
60092+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60093+
60094+ atomic_sub_unchecked(i, v);
60095+}
60096+#endif
60097+
60098 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60099 {
60100 atomic_t *v = (atomic_t *)l;
60101@@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60102 return (long)atomic_inc_return(v);
60103 }
60104
60105+#ifdef CONFIG_PAX_REFCOUNT
60106+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60107+{
60108+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60109+
60110+ return (long)atomic_inc_return_unchecked(v);
60111+}
60112+#endif
60113+
60114 static inline long atomic_long_dec_return(atomic_long_t *l)
60115 {
60116 atomic_t *v = (atomic_t *)l;
60117@@ -255,4 +393,55 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60118
60119 #endif /* BITS_PER_LONG == 64 */
60120
60121+#ifdef CONFIG_PAX_REFCOUNT
60122+static inline void pax_refcount_needs_these_functions(void)
60123+{
60124+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
60125+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
60126+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
60127+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
60128+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
60129+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
60130+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
60131+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
60132+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
60133+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
60134+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
60135+#ifdef CONFIG_X86
60136+ atomic_clear_mask_unchecked(0, NULL);
60137+ atomic_set_mask_unchecked(0, NULL);
60138+#endif
60139+
60140+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
60141+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
60142+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
60143+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
60144+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
60145+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
60146+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
60147+}
60148+#else
60149+#define atomic_read_unchecked(v) atomic_read(v)
60150+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
60151+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
60152+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
60153+#define atomic_inc_unchecked(v) atomic_inc(v)
60154+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
60155+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
60156+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
60157+#define atomic_dec_unchecked(v) atomic_dec(v)
60158+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
60159+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
60160+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
60161+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
60162+
60163+#define atomic_long_read_unchecked(v) atomic_long_read(v)
60164+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
60165+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
60166+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
60167+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
60168+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
60169+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
60170+#endif
60171+
60172 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
60173diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
60174index 1ced641..c896ee8 100644
60175--- a/include/asm-generic/atomic.h
60176+++ b/include/asm-generic/atomic.h
60177@@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
60178 * Atomically clears the bits set in @mask from @v
60179 */
60180 #ifndef atomic_clear_mask
60181-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
60182+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
60183 {
60184 unsigned long flags;
60185
60186diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
60187index b18ce4f..2ee2843 100644
60188--- a/include/asm-generic/atomic64.h
60189+++ b/include/asm-generic/atomic64.h
60190@@ -16,6 +16,8 @@ typedef struct {
60191 long long counter;
60192 } atomic64_t;
60193
60194+typedef atomic64_t atomic64_unchecked_t;
60195+
60196 #define ATOMIC64_INIT(i) { (i) }
60197
60198 extern long long atomic64_read(const atomic64_t *v);
60199@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
60200 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
60201 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
60202
60203+#define atomic64_read_unchecked(v) atomic64_read(v)
60204+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
60205+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
60206+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
60207+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
60208+#define atomic64_inc_unchecked(v) atomic64_inc(v)
60209+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
60210+#define atomic64_dec_unchecked(v) atomic64_dec(v)
60211+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
60212+
60213 #endif /* _ASM_GENERIC_ATOMIC64_H */
60214diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
60215index 1bfcfe5..e04c5c9 100644
60216--- a/include/asm-generic/cache.h
60217+++ b/include/asm-generic/cache.h
60218@@ -6,7 +6,7 @@
60219 * cache lines need to provide their own cache.h.
60220 */
60221
60222-#define L1_CACHE_SHIFT 5
60223-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
60224+#define L1_CACHE_SHIFT 5UL
60225+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
60226
60227 #endif /* __ASM_GENERIC_CACHE_H */
60228diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
60229index 0d68a1e..b74a761 100644
60230--- a/include/asm-generic/emergency-restart.h
60231+++ b/include/asm-generic/emergency-restart.h
60232@@ -1,7 +1,7 @@
60233 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
60234 #define _ASM_GENERIC_EMERGENCY_RESTART_H
60235
60236-static inline void machine_emergency_restart(void)
60237+static inline __noreturn void machine_emergency_restart(void)
60238 {
60239 machine_restart(NULL);
60240 }
60241diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
60242index 0232ccb..13d9165 100644
60243--- a/include/asm-generic/kmap_types.h
60244+++ b/include/asm-generic/kmap_types.h
60245@@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
60246 KMAP_D(17) KM_NMI,
60247 KMAP_D(18) KM_NMI_PTE,
60248 KMAP_D(19) KM_KDB,
60249+KMAP_D(20) KM_CLEARPAGE,
60250 /*
60251 * Remember to update debug_kmap_atomic() when adding new kmap types!
60252 */
60253-KMAP_D(20) KM_TYPE_NR
60254+KMAP_D(21) KM_TYPE_NR
60255 };
60256
60257 #undef KMAP_D
60258diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
60259index 9ceb03b..2efbcbd 100644
60260--- a/include/asm-generic/local.h
60261+++ b/include/asm-generic/local.h
60262@@ -39,6 +39,7 @@ typedef struct
60263 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
60264 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
60265 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
60266+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
60267
60268 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
60269 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
60270diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
60271index 725612b..9cc513a 100644
60272--- a/include/asm-generic/pgtable-nopmd.h
60273+++ b/include/asm-generic/pgtable-nopmd.h
60274@@ -1,14 +1,19 @@
60275 #ifndef _PGTABLE_NOPMD_H
60276 #define _PGTABLE_NOPMD_H
60277
60278-#ifndef __ASSEMBLY__
60279-
60280 #include <asm-generic/pgtable-nopud.h>
60281
60282-struct mm_struct;
60283-
60284 #define __PAGETABLE_PMD_FOLDED
60285
60286+#define PMD_SHIFT PUD_SHIFT
60287+#define PTRS_PER_PMD 1
60288+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
60289+#define PMD_MASK (~(PMD_SIZE-1))
60290+
60291+#ifndef __ASSEMBLY__
60292+
60293+struct mm_struct;
60294+
60295 /*
60296 * Having the pmd type consist of a pud gets the size right, and allows
60297 * us to conceptually access the pud entry that this pmd is folded into
60298@@ -16,11 +21,6 @@ struct mm_struct;
60299 */
60300 typedef struct { pud_t pud; } pmd_t;
60301
60302-#define PMD_SHIFT PUD_SHIFT
60303-#define PTRS_PER_PMD 1
60304-#define PMD_SIZE (1UL << PMD_SHIFT)
60305-#define PMD_MASK (~(PMD_SIZE-1))
60306-
60307 /*
60308 * The "pud_xxx()" functions here are trivial for a folded two-level
60309 * setup: the pmd is never bad, and a pmd always exists (as it's folded
60310diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
60311index 810431d..0ec4804f 100644
60312--- a/include/asm-generic/pgtable-nopud.h
60313+++ b/include/asm-generic/pgtable-nopud.h
60314@@ -1,10 +1,15 @@
60315 #ifndef _PGTABLE_NOPUD_H
60316 #define _PGTABLE_NOPUD_H
60317
60318-#ifndef __ASSEMBLY__
60319-
60320 #define __PAGETABLE_PUD_FOLDED
60321
60322+#define PUD_SHIFT PGDIR_SHIFT
60323+#define PTRS_PER_PUD 1
60324+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
60325+#define PUD_MASK (~(PUD_SIZE-1))
60326+
60327+#ifndef __ASSEMBLY__
60328+
60329 /*
60330 * Having the pud type consist of a pgd gets the size right, and allows
60331 * us to conceptually access the pgd entry that this pud is folded into
60332@@ -12,11 +17,6 @@
60333 */
60334 typedef struct { pgd_t pgd; } pud_t;
60335
60336-#define PUD_SHIFT PGDIR_SHIFT
60337-#define PTRS_PER_PUD 1
60338-#define PUD_SIZE (1UL << PUD_SHIFT)
60339-#define PUD_MASK (~(PUD_SIZE-1))
60340-
60341 /*
60342 * The "pgd_xxx()" functions here are trivial for a folded two-level
60343 * setup: the pud is never bad, and a pud always exists (as it's folded
60344@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
60345 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
60346
60347 #define pgd_populate(mm, pgd, pud) do { } while (0)
60348+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
60349 /*
60350 * (puds are folded into pgds so this doesn't get actually called,
60351 * but the define is needed for a generic inline function.)
60352diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
60353index ff4947b..f48183f 100644
60354--- a/include/asm-generic/pgtable.h
60355+++ b/include/asm-generic/pgtable.h
60356@@ -530,6 +530,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
60357 #endif
60358 }
60359
60360+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
60361+static inline unsigned long pax_open_kernel(void) { return 0; }
60362+#endif
60363+
60364+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
60365+static inline unsigned long pax_close_kernel(void) { return 0; }
60366+#endif
60367+
60368 #endif /* CONFIG_MMU */
60369
60370 #endif /* !__ASSEMBLY__ */
60371diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
60372index 4e2e1cc..12c266b 100644
60373--- a/include/asm-generic/vmlinux.lds.h
60374+++ b/include/asm-generic/vmlinux.lds.h
60375@@ -218,6 +218,7 @@
60376 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
60377 VMLINUX_SYMBOL(__start_rodata) = .; \
60378 *(.rodata) *(.rodata.*) \
60379+ *(.data..read_only) \
60380 *(__vermagic) /* Kernel version magic */ \
60381 . = ALIGN(8); \
60382 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
60383@@ -716,17 +717,18 @@
60384 * section in the linker script will go there too. @phdr should have
60385 * a leading colon.
60386 *
60387- * Note that this macros defines __per_cpu_load as an absolute symbol.
60388+ * Note that this macros defines per_cpu_load as an absolute symbol.
60389 * If there is no need to put the percpu section at a predetermined
60390 * address, use PERCPU_SECTION.
60391 */
60392 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
60393- VMLINUX_SYMBOL(__per_cpu_load) = .; \
60394- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
60395+ per_cpu_load = .; \
60396+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
60397 - LOAD_OFFSET) { \
60398+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
60399 PERCPU_INPUT(cacheline) \
60400 } phdr \
60401- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
60402+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
60403
60404 /**
60405 * PERCPU_SECTION - define output section for percpu area, simple version
60406diff --git a/include/drm/drmP.h b/include/drm/drmP.h
60407index 31ad880..4e79884 100644
60408--- a/include/drm/drmP.h
60409+++ b/include/drm/drmP.h
60410@@ -72,6 +72,7 @@
60411 #include <linux/workqueue.h>
60412 #include <linux/poll.h>
60413 #include <asm/pgalloc.h>
60414+#include <asm/local.h>
60415 #include "drm.h"
60416
60417 #include <linux/idr.h>
60418@@ -1074,7 +1075,7 @@ struct drm_device {
60419
60420 /** \name Usage Counters */
60421 /*@{ */
60422- int open_count; /**< Outstanding files open */
60423+ local_t open_count; /**< Outstanding files open */
60424 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
60425 atomic_t vma_count; /**< Outstanding vma areas open */
60426 int buf_use; /**< Buffers in use -- cannot alloc */
60427@@ -1085,7 +1086,7 @@ struct drm_device {
60428 /*@{ */
60429 unsigned long counters;
60430 enum drm_stat_type types[15];
60431- atomic_t counts[15];
60432+ atomic_unchecked_t counts[15];
60433 /*@} */
60434
60435 struct list_head filelist;
60436diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
60437index 7988e55..ec974c9 100644
60438--- a/include/drm/drm_crtc_helper.h
60439+++ b/include/drm/drm_crtc_helper.h
60440@@ -81,7 +81,7 @@ struct drm_crtc_helper_funcs {
60441
60442 /* disable crtc when not in use - more explicit than dpms off */
60443 void (*disable)(struct drm_crtc *crtc);
60444-};
60445+} __no_const;
60446
60447 /**
60448 * drm_encoder_helper_funcs - helper operations for encoders
60449@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
60450 struct drm_connector *connector);
60451 /* disable encoder when not in use - more explicit than dpms off */
60452 void (*disable)(struct drm_encoder *encoder);
60453-};
60454+} __no_const;
60455
60456 /**
60457 * drm_connector_helper_funcs - helper operations for connectors
60458diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
60459index d6d1da4..fdd1ac5 100644
60460--- a/include/drm/ttm/ttm_memory.h
60461+++ b/include/drm/ttm/ttm_memory.h
60462@@ -48,7 +48,7 @@
60463
60464 struct ttm_mem_shrink {
60465 int (*do_shrink) (struct ttm_mem_shrink *);
60466-};
60467+} __no_const;
60468
60469 /**
60470 * struct ttm_mem_global - Global memory accounting structure.
60471diff --git a/include/linux/a.out.h b/include/linux/a.out.h
60472index e86dfca..40cc55f 100644
60473--- a/include/linux/a.out.h
60474+++ b/include/linux/a.out.h
60475@@ -39,6 +39,14 @@ enum machine_type {
60476 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
60477 };
60478
60479+/* Constants for the N_FLAGS field */
60480+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60481+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
60482+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
60483+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
60484+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60485+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60486+
60487 #if !defined (N_MAGIC)
60488 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
60489 #endif
60490diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
60491index 06fd4bb..1caec0d 100644
60492--- a/include/linux/atmdev.h
60493+++ b/include/linux/atmdev.h
60494@@ -237,7 +237,7 @@ struct compat_atm_iobuf {
60495 #endif
60496
60497 struct k_atm_aal_stats {
60498-#define __HANDLE_ITEM(i) atomic_t i
60499+#define __HANDLE_ITEM(i) atomic_unchecked_t i
60500 __AAL_STAT_ITEMS
60501 #undef __HANDLE_ITEM
60502 };
60503diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
60504index 366422b..1fa7f84 100644
60505--- a/include/linux/binfmts.h
60506+++ b/include/linux/binfmts.h
60507@@ -89,6 +89,7 @@ struct linux_binfmt {
60508 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
60509 int (*load_shlib)(struct file *);
60510 int (*core_dump)(struct coredump_params *cprm);
60511+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
60512 unsigned long min_coredump; /* minimal dump size */
60513 };
60514
60515diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
60516index 07954b0..cb2ae71 100644
60517--- a/include/linux/blkdev.h
60518+++ b/include/linux/blkdev.h
60519@@ -1393,7 +1393,7 @@ struct block_device_operations {
60520 /* this callback is with swap_lock and sometimes page table lock held */
60521 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
60522 struct module *owner;
60523-};
60524+} __do_const;
60525
60526 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
60527 unsigned long);
60528diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
60529index 4d1a074..88f929a 100644
60530--- a/include/linux/blktrace_api.h
60531+++ b/include/linux/blktrace_api.h
60532@@ -162,7 +162,7 @@ struct blk_trace {
60533 struct dentry *dir;
60534 struct dentry *dropped_file;
60535 struct dentry *msg_file;
60536- atomic_t dropped;
60537+ atomic_unchecked_t dropped;
60538 };
60539
60540 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
60541diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
60542index 83195fb..0b0f77d 100644
60543--- a/include/linux/byteorder/little_endian.h
60544+++ b/include/linux/byteorder/little_endian.h
60545@@ -42,51 +42,51 @@
60546
60547 static inline __le64 __cpu_to_le64p(const __u64 *p)
60548 {
60549- return (__force __le64)*p;
60550+ return (__force const __le64)*p;
60551 }
60552 static inline __u64 __le64_to_cpup(const __le64 *p)
60553 {
60554- return (__force __u64)*p;
60555+ return (__force const __u64)*p;
60556 }
60557 static inline __le32 __cpu_to_le32p(const __u32 *p)
60558 {
60559- return (__force __le32)*p;
60560+ return (__force const __le32)*p;
60561 }
60562 static inline __u32 __le32_to_cpup(const __le32 *p)
60563 {
60564- return (__force __u32)*p;
60565+ return (__force const __u32)*p;
60566 }
60567 static inline __le16 __cpu_to_le16p(const __u16 *p)
60568 {
60569- return (__force __le16)*p;
60570+ return (__force const __le16)*p;
60571 }
60572 static inline __u16 __le16_to_cpup(const __le16 *p)
60573 {
60574- return (__force __u16)*p;
60575+ return (__force const __u16)*p;
60576 }
60577 static inline __be64 __cpu_to_be64p(const __u64 *p)
60578 {
60579- return (__force __be64)__swab64p(p);
60580+ return (__force const __be64)__swab64p(p);
60581 }
60582 static inline __u64 __be64_to_cpup(const __be64 *p)
60583 {
60584- return __swab64p((__u64 *)p);
60585+ return __swab64p((const __u64 *)p);
60586 }
60587 static inline __be32 __cpu_to_be32p(const __u32 *p)
60588 {
60589- return (__force __be32)__swab32p(p);
60590+ return (__force const __be32)__swab32p(p);
60591 }
60592 static inline __u32 __be32_to_cpup(const __be32 *p)
60593 {
60594- return __swab32p((__u32 *)p);
60595+ return __swab32p((const __u32 *)p);
60596 }
60597 static inline __be16 __cpu_to_be16p(const __u16 *p)
60598 {
60599- return (__force __be16)__swab16p(p);
60600+ return (__force const __be16)__swab16p(p);
60601 }
60602 static inline __u16 __be16_to_cpup(const __be16 *p)
60603 {
60604- return __swab16p((__u16 *)p);
60605+ return __swab16p((const __u16 *)p);
60606 }
60607 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
60608 #define __le64_to_cpus(x) do { (void)(x); } while (0)
60609diff --git a/include/linux/cache.h b/include/linux/cache.h
60610index 4c57065..4307975 100644
60611--- a/include/linux/cache.h
60612+++ b/include/linux/cache.h
60613@@ -16,6 +16,10 @@
60614 #define __read_mostly
60615 #endif
60616
60617+#ifndef __read_only
60618+#define __read_only __read_mostly
60619+#endif
60620+
60621 #ifndef ____cacheline_aligned
60622 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
60623 #endif
60624diff --git a/include/linux/capability.h b/include/linux/capability.h
60625index d10b7ed..0288b79 100644
60626--- a/include/linux/capability.h
60627+++ b/include/linux/capability.h
60628@@ -553,10 +553,15 @@ extern bool capable(int cap);
60629 extern bool ns_capable(struct user_namespace *ns, int cap);
60630 extern bool nsown_capable(int cap);
60631 extern bool inode_capable(const struct inode *inode, int cap);
60632+extern bool capable_nolog(int cap);
60633+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
60634+extern bool inode_capable_nolog(const struct inode *inode, int cap);
60635
60636 /* audit system wants to get cap info from files as well */
60637 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
60638
60639+extern int is_privileged_binary(const struct dentry *dentry);
60640+
60641 #endif /* __KERNEL__ */
60642
60643 #endif /* !_LINUX_CAPABILITY_H */
60644diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
60645index 42e55de..1cd0e66 100644
60646--- a/include/linux/cleancache.h
60647+++ b/include/linux/cleancache.h
60648@@ -31,7 +31,7 @@ struct cleancache_ops {
60649 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
60650 void (*invalidate_inode)(int, struct cleancache_filekey);
60651 void (*invalidate_fs)(int);
60652-};
60653+} __no_const;
60654
60655 extern struct cleancache_ops
60656 cleancache_register_ops(struct cleancache_ops *ops);
60657diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
60658index 4a0b483..f1f70ba 100644
60659--- a/include/linux/clk-provider.h
60660+++ b/include/linux/clk-provider.h
60661@@ -110,6 +110,7 @@ struct clk_ops {
60662 unsigned long);
60663 void (*init)(struct clk_hw *hw);
60664 };
60665+typedef struct clk_ops __no_const clk_ops_no_const;
60666
60667 /**
60668 * struct clk_init_data - holds init data that's common to all clocks and is
60669diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
60670index 2f40791..9c9e13c 100644
60671--- a/include/linux/compiler-gcc4.h
60672+++ b/include/linux/compiler-gcc4.h
60673@@ -32,6 +32,20 @@
60674 #define __linktime_error(message) __attribute__((__error__(message)))
60675
60676 #if __GNUC_MINOR__ >= 5
60677+
60678+#ifdef CONSTIFY_PLUGIN
60679+#define __no_const __attribute__((no_const))
60680+#define __do_const __attribute__((do_const))
60681+#endif
60682+
60683+#ifdef SIZE_OVERFLOW_PLUGIN
60684+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
60685+#endif
60686+
60687+#ifdef LATENT_ENTROPY_PLUGIN
60688+#define __latent_entropy __attribute__((latent_entropy))
60689+#endif
60690+
60691 /*
60692 * Mark a position in code as unreachable. This can be used to
60693 * suppress control flow warnings after asm blocks that transfer
60694@@ -47,6 +61,11 @@
60695 #define __noclone __attribute__((__noclone__))
60696
60697 #endif
60698+
60699+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
60700+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
60701+#define __bos0(ptr) __bos((ptr), 0)
60702+#define __bos1(ptr) __bos((ptr), 1)
60703 #endif
60704
60705 #if __GNUC_MINOR__ > 0
60706diff --git a/include/linux/compiler.h b/include/linux/compiler.h
60707index 923d093..1fef491 100644
60708--- a/include/linux/compiler.h
60709+++ b/include/linux/compiler.h
60710@@ -5,31 +5,62 @@
60711
60712 #ifdef __CHECKER__
60713 # define __user __attribute__((noderef, address_space(1)))
60714+# define __force_user __force __user
60715 # define __kernel __attribute__((address_space(0)))
60716+# define __force_kernel __force __kernel
60717 # define __safe __attribute__((safe))
60718 # define __force __attribute__((force))
60719 # define __nocast __attribute__((nocast))
60720 # define __iomem __attribute__((noderef, address_space(2)))
60721+# define __force_iomem __force __iomem
60722 # define __acquires(x) __attribute__((context(x,0,1)))
60723 # define __releases(x) __attribute__((context(x,1,0)))
60724 # define __acquire(x) __context__(x,1)
60725 # define __release(x) __context__(x,-1)
60726 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
60727 # define __percpu __attribute__((noderef, address_space(3)))
60728+# define __force_percpu __force __percpu
60729 #ifdef CONFIG_SPARSE_RCU_POINTER
60730 # define __rcu __attribute__((noderef, address_space(4)))
60731+# define __force_rcu __force __rcu
60732 #else
60733 # define __rcu
60734+# define __force_rcu
60735 #endif
60736 extern void __chk_user_ptr(const volatile void __user *);
60737 extern void __chk_io_ptr(const volatile void __iomem *);
60738+#elif defined(CHECKER_PLUGIN)
60739+//# define __user
60740+//# define __force_user
60741+//# define __kernel
60742+//# define __force_kernel
60743+# define __safe
60744+# define __force
60745+# define __nocast
60746+# define __iomem
60747+# define __force_iomem
60748+# define __chk_user_ptr(x) (void)0
60749+# define __chk_io_ptr(x) (void)0
60750+# define __builtin_warning(x, y...) (1)
60751+# define __acquires(x)
60752+# define __releases(x)
60753+# define __acquire(x) (void)0
60754+# define __release(x) (void)0
60755+# define __cond_lock(x,c) (c)
60756+# define __percpu
60757+# define __force_percpu
60758+# define __rcu
60759+# define __force_rcu
60760 #else
60761 # define __user
60762+# define __force_user
60763 # define __kernel
60764+# define __force_kernel
60765 # define __safe
60766 # define __force
60767 # define __nocast
60768 # define __iomem
60769+# define __force_iomem
60770 # define __chk_user_ptr(x) (void)0
60771 # define __chk_io_ptr(x) (void)0
60772 # define __builtin_warning(x, y...) (1)
60773@@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
60774 # define __release(x) (void)0
60775 # define __cond_lock(x,c) (c)
60776 # define __percpu
60777+# define __force_percpu
60778 # define __rcu
60779+# define __force_rcu
60780 #endif
60781
60782 #ifdef __KERNEL__
60783@@ -264,6 +297,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60784 # define __attribute_const__ /* unimplemented */
60785 #endif
60786
60787+#ifndef __no_const
60788+# define __no_const
60789+#endif
60790+
60791+#ifndef __do_const
60792+# define __do_const
60793+#endif
60794+
60795+#ifndef __size_overflow
60796+# define __size_overflow(...)
60797+#endif
60798+
60799+#ifndef __latent_entropy
60800+# define __latent_entropy
60801+#endif
60802+
60803 /*
60804 * Tell gcc if a function is cold. The compiler will assume any path
60805 * directly leading to the call is unlikely.
60806@@ -273,6 +322,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60807 #define __cold
60808 #endif
60809
60810+#ifndef __alloc_size
60811+#define __alloc_size(...)
60812+#endif
60813+
60814+#ifndef __bos
60815+#define __bos(ptr, arg)
60816+#endif
60817+
60818+#ifndef __bos0
60819+#define __bos0(ptr)
60820+#endif
60821+
60822+#ifndef __bos1
60823+#define __bos1(ptr)
60824+#endif
60825+
60826 /* Simple shorthand for a section definition */
60827 #ifndef __section
60828 # define __section(S) __attribute__ ((__section__(#S)))
60829@@ -308,6 +373,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60830 * use is to mediate communication between process-level code and irq/NMI
60831 * handlers, all running on the same CPU.
60832 */
60833-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
60834+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
60835+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
60836
60837 #endif /* __LINUX_COMPILER_H */
60838diff --git a/include/linux/cred.h b/include/linux/cred.h
60839index ebbed2c..908cc2c 100644
60840--- a/include/linux/cred.h
60841+++ b/include/linux/cred.h
60842@@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
60843 static inline void validate_process_creds(void)
60844 {
60845 }
60846+static inline void validate_task_creds(struct task_struct *task)
60847+{
60848+}
60849 #endif
60850
60851 /**
60852diff --git a/include/linux/crypto.h b/include/linux/crypto.h
60853index b92eadf..b4ecdc1 100644
60854--- a/include/linux/crypto.h
60855+++ b/include/linux/crypto.h
60856@@ -373,7 +373,7 @@ struct cipher_tfm {
60857 const u8 *key, unsigned int keylen);
60858 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60859 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60860-};
60861+} __no_const;
60862
60863 struct hash_tfm {
60864 int (*init)(struct hash_desc *desc);
60865@@ -394,13 +394,13 @@ struct compress_tfm {
60866 int (*cot_decompress)(struct crypto_tfm *tfm,
60867 const u8 *src, unsigned int slen,
60868 u8 *dst, unsigned int *dlen);
60869-};
60870+} __no_const;
60871
60872 struct rng_tfm {
60873 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
60874 unsigned int dlen);
60875 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
60876-};
60877+} __no_const;
60878
60879 #define crt_ablkcipher crt_u.ablkcipher
60880 #define crt_aead crt_u.aead
60881diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
60882index 7925bf0..d5143d2 100644
60883--- a/include/linux/decompress/mm.h
60884+++ b/include/linux/decompress/mm.h
60885@@ -77,7 +77,7 @@ static void free(void *where)
60886 * warnings when not needed (indeed large_malloc / large_free are not
60887 * needed by inflate */
60888
60889-#define malloc(a) kmalloc(a, GFP_KERNEL)
60890+#define malloc(a) kmalloc((a), GFP_KERNEL)
60891 #define free(a) kfree(a)
60892
60893 #define large_malloc(a) vmalloc(a)
60894diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
60895index dfc099e..e583e66 100644
60896--- a/include/linux/dma-mapping.h
60897+++ b/include/linux/dma-mapping.h
60898@@ -51,7 +51,7 @@ struct dma_map_ops {
60899 u64 (*get_required_mask)(struct device *dev);
60900 #endif
60901 int is_phys;
60902-};
60903+} __do_const;
60904
60905 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
60906
60907diff --git a/include/linux/efi.h b/include/linux/efi.h
60908index ec45ccd..9923c32 100644
60909--- a/include/linux/efi.h
60910+++ b/include/linux/efi.h
60911@@ -635,7 +635,7 @@ struct efivar_operations {
60912 efi_get_variable_t *get_variable;
60913 efi_get_next_variable_t *get_next_variable;
60914 efi_set_variable_t *set_variable;
60915-};
60916+} __no_const;
60917
60918 struct efivars {
60919 /*
60920diff --git a/include/linux/elf.h b/include/linux/elf.h
60921index 999b4f5..57753b4 100644
60922--- a/include/linux/elf.h
60923+++ b/include/linux/elf.h
60924@@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
60925 #define PT_GNU_EH_FRAME 0x6474e550
60926
60927 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
60928+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
60929+
60930+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
60931+
60932+/* Constants for the e_flags field */
60933+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60934+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
60935+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
60936+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
60937+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60938+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60939
60940 /*
60941 * Extended Numbering
60942@@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
60943 #define DT_DEBUG 21
60944 #define DT_TEXTREL 22
60945 #define DT_JMPREL 23
60946+#define DT_FLAGS 30
60947+ #define DF_TEXTREL 0x00000004
60948 #define DT_ENCODING 32
60949 #define OLD_DT_LOOS 0x60000000
60950 #define DT_LOOS 0x6000000d
60951@@ -243,6 +256,19 @@ typedef struct elf64_hdr {
60952 #define PF_W 0x2
60953 #define PF_X 0x1
60954
60955+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
60956+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
60957+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
60958+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
60959+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
60960+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
60961+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
60962+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
60963+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
60964+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
60965+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
60966+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
60967+
60968 typedef struct elf32_phdr{
60969 Elf32_Word p_type;
60970 Elf32_Off p_offset;
60971@@ -335,6 +361,8 @@ typedef struct elf64_shdr {
60972 #define EI_OSABI 7
60973 #define EI_PAD 8
60974
60975+#define EI_PAX 14
60976+
60977 #define ELFMAG0 0x7f /* EI_MAG */
60978 #define ELFMAG1 'E'
60979 #define ELFMAG2 'L'
60980@@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
60981 #define elf_note elf32_note
60982 #define elf_addr_t Elf32_Off
60983 #define Elf_Half Elf32_Half
60984+#define elf_dyn Elf32_Dyn
60985
60986 #else
60987
60988@@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
60989 #define elf_note elf64_note
60990 #define elf_addr_t Elf64_Off
60991 #define Elf_Half Elf64_Half
60992+#define elf_dyn Elf64_Dyn
60993
60994 #endif
60995
60996diff --git a/include/linux/filter.h b/include/linux/filter.h
60997index 82b0135..917914d 100644
60998--- a/include/linux/filter.h
60999+++ b/include/linux/filter.h
61000@@ -146,6 +146,7 @@ struct compat_sock_fprog {
61001
61002 struct sk_buff;
61003 struct sock;
61004+struct bpf_jit_work;
61005
61006 struct sk_filter
61007 {
61008@@ -153,6 +154,9 @@ struct sk_filter
61009 unsigned int len; /* Number of filter blocks */
61010 unsigned int (*bpf_func)(const struct sk_buff *skb,
61011 const struct sock_filter *filter);
61012+#ifdef CONFIG_BPF_JIT
61013+ struct bpf_jit_work *work;
61014+#endif
61015 struct rcu_head rcu;
61016 struct sock_filter insns[0];
61017 };
61018diff --git a/include/linux/firewire.h b/include/linux/firewire.h
61019index 7edcf10..714d5e8 100644
61020--- a/include/linux/firewire.h
61021+++ b/include/linux/firewire.h
61022@@ -430,7 +430,7 @@ struct fw_iso_context {
61023 union {
61024 fw_iso_callback_t sc;
61025 fw_iso_mc_callback_t mc;
61026- } callback;
61027+ } __no_const callback;
61028 void *callback_data;
61029 };
61030
61031diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
61032index 0e4e2ee..4ff4312 100644
61033--- a/include/linux/frontswap.h
61034+++ b/include/linux/frontswap.h
61035@@ -11,7 +11,7 @@ struct frontswap_ops {
61036 int (*load)(unsigned, pgoff_t, struct page *);
61037 void (*invalidate_page)(unsigned, pgoff_t);
61038 void (*invalidate_area)(unsigned);
61039-};
61040+} __no_const;
61041
61042 extern bool frontswap_enabled;
61043 extern struct frontswap_ops
61044diff --git a/include/linux/fs.h b/include/linux/fs.h
61045index 17fd887..8eebca0 100644
61046--- a/include/linux/fs.h
61047+++ b/include/linux/fs.h
61048@@ -1663,7 +1663,8 @@ struct file_operations {
61049 int (*setlease)(struct file *, long, struct file_lock **);
61050 long (*fallocate)(struct file *file, int mode, loff_t offset,
61051 loff_t len);
61052-};
61053+} __do_const;
61054+typedef struct file_operations __no_const file_operations_no_const;
61055
61056 struct inode_operations {
61057 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
61058diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
61059index 003dc0f..3c4ea97 100644
61060--- a/include/linux/fs_struct.h
61061+++ b/include/linux/fs_struct.h
61062@@ -6,7 +6,7 @@
61063 #include <linux/seqlock.h>
61064
61065 struct fs_struct {
61066- int users;
61067+ atomic_t users;
61068 spinlock_t lock;
61069 seqcount_t seq;
61070 int umask;
61071diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
61072index ce31408..b1ad003 100644
61073--- a/include/linux/fscache-cache.h
61074+++ b/include/linux/fscache-cache.h
61075@@ -102,7 +102,7 @@ struct fscache_operation {
61076 fscache_operation_release_t release;
61077 };
61078
61079-extern atomic_t fscache_op_debug_id;
61080+extern atomic_unchecked_t fscache_op_debug_id;
61081 extern void fscache_op_work_func(struct work_struct *work);
61082
61083 extern void fscache_enqueue_operation(struct fscache_operation *);
61084@@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
61085 {
61086 INIT_WORK(&op->work, fscache_op_work_func);
61087 atomic_set(&op->usage, 1);
61088- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
61089+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61090 op->processor = processor;
61091 op->release = release;
61092 INIT_LIST_HEAD(&op->pend_link);
61093diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
61094index a6dfe69..569586df 100644
61095--- a/include/linux/fsnotify.h
61096+++ b/include/linux/fsnotify.h
61097@@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
61098 */
61099 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
61100 {
61101- return kstrdup(name, GFP_KERNEL);
61102+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
61103 }
61104
61105 /*
61106diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
61107index 63d966d..cdcb717 100644
61108--- a/include/linux/fsnotify_backend.h
61109+++ b/include/linux/fsnotify_backend.h
61110@@ -105,6 +105,7 @@ struct fsnotify_ops {
61111 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
61112 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
61113 };
61114+typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
61115
61116 /*
61117 * A group is a "thing" that wants to receive notification about filesystem
61118diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
61119index 176a939..1462211 100644
61120--- a/include/linux/ftrace_event.h
61121+++ b/include/linux/ftrace_event.h
61122@@ -97,7 +97,7 @@ struct trace_event_functions {
61123 trace_print_func raw;
61124 trace_print_func hex;
61125 trace_print_func binary;
61126-};
61127+} __no_const;
61128
61129 struct trace_event {
61130 struct hlist_node node;
61131@@ -263,7 +263,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
61132 extern int trace_add_event_call(struct ftrace_event_call *call);
61133 extern void trace_remove_event_call(struct ftrace_event_call *call);
61134
61135-#define is_signed_type(type) (((type)(-1)) < 0)
61136+#define is_signed_type(type) (((type)(-1)) < (type)1)
61137
61138 int trace_set_clr_event(const char *system, const char *event, int set);
61139
61140diff --git a/include/linux/genhd.h b/include/linux/genhd.h
61141index 017a7fb..33a8507 100644
61142--- a/include/linux/genhd.h
61143+++ b/include/linux/genhd.h
61144@@ -185,7 +185,7 @@ struct gendisk {
61145 struct kobject *slave_dir;
61146
61147 struct timer_rand_state *random;
61148- atomic_t sync_io; /* RAID */
61149+ atomic_unchecked_t sync_io; /* RAID */
61150 struct disk_events *ev;
61151 #ifdef CONFIG_BLK_DEV_INTEGRITY
61152 struct blk_integrity *integrity;
61153diff --git a/include/linux/gfp.h b/include/linux/gfp.h
61154index 1e49be4..b8a9305 100644
61155--- a/include/linux/gfp.h
61156+++ b/include/linux/gfp.h
61157@@ -38,6 +38,12 @@ struct vm_area_struct;
61158 #define ___GFP_OTHER_NODE 0x800000u
61159 #define ___GFP_WRITE 0x1000000u
61160
61161+#ifdef CONFIG_PAX_USERCOPY_SLABS
61162+#define ___GFP_USERCOPY 0x2000000u
61163+#else
61164+#define ___GFP_USERCOPY 0
61165+#endif
61166+
61167 /*
61168 * GFP bitmasks..
61169 *
61170@@ -87,6 +93,7 @@ struct vm_area_struct;
61171 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
61172 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
61173 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
61174+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
61175
61176 /*
61177 * This may seem redundant, but it's a way of annotating false positives vs.
61178@@ -94,7 +101,7 @@ struct vm_area_struct;
61179 */
61180 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
61181
61182-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
61183+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
61184 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
61185
61186 /* This equals 0, but use constants in case they ever change */
61187@@ -148,6 +155,8 @@ struct vm_area_struct;
61188 /* 4GB DMA on some platforms */
61189 #define GFP_DMA32 __GFP_DMA32
61190
61191+#define GFP_USERCOPY __GFP_USERCOPY
61192+
61193 /* Convert GFP flags to their corresponding migrate type */
61194 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
61195 {
61196diff --git a/include/linux/gracl.h b/include/linux/gracl.h
61197new file mode 100644
61198index 0000000..c938b1f
61199--- /dev/null
61200+++ b/include/linux/gracl.h
61201@@ -0,0 +1,319 @@
61202+#ifndef GR_ACL_H
61203+#define GR_ACL_H
61204+
61205+#include <linux/grdefs.h>
61206+#include <linux/resource.h>
61207+#include <linux/capability.h>
61208+#include <linux/dcache.h>
61209+#include <asm/resource.h>
61210+
61211+/* Major status information */
61212+
61213+#define GR_VERSION "grsecurity 2.9.1"
61214+#define GRSECURITY_VERSION 0x2901
61215+
61216+enum {
61217+ GR_SHUTDOWN = 0,
61218+ GR_ENABLE = 1,
61219+ GR_SPROLE = 2,
61220+ GR_RELOAD = 3,
61221+ GR_SEGVMOD = 4,
61222+ GR_STATUS = 5,
61223+ GR_UNSPROLE = 6,
61224+ GR_PASSSET = 7,
61225+ GR_SPROLEPAM = 8,
61226+};
61227+
61228+/* Password setup definitions
61229+ * kernel/grhash.c */
61230+enum {
61231+ GR_PW_LEN = 128,
61232+ GR_SALT_LEN = 16,
61233+ GR_SHA_LEN = 32,
61234+};
61235+
61236+enum {
61237+ GR_SPROLE_LEN = 64,
61238+};
61239+
61240+enum {
61241+ GR_NO_GLOB = 0,
61242+ GR_REG_GLOB,
61243+ GR_CREATE_GLOB
61244+};
61245+
61246+#define GR_NLIMITS 32
61247+
61248+/* Begin Data Structures */
61249+
61250+struct sprole_pw {
61251+ unsigned char *rolename;
61252+ unsigned char salt[GR_SALT_LEN];
61253+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
61254+};
61255+
61256+struct name_entry {
61257+ __u32 key;
61258+ ino_t inode;
61259+ dev_t device;
61260+ char *name;
61261+ __u16 len;
61262+ __u8 deleted;
61263+ struct name_entry *prev;
61264+ struct name_entry *next;
61265+};
61266+
61267+struct inodev_entry {
61268+ struct name_entry *nentry;
61269+ struct inodev_entry *prev;
61270+ struct inodev_entry *next;
61271+};
61272+
61273+struct acl_role_db {
61274+ struct acl_role_label **r_hash;
61275+ __u32 r_size;
61276+};
61277+
61278+struct inodev_db {
61279+ struct inodev_entry **i_hash;
61280+ __u32 i_size;
61281+};
61282+
61283+struct name_db {
61284+ struct name_entry **n_hash;
61285+ __u32 n_size;
61286+};
61287+
61288+struct crash_uid {
61289+ uid_t uid;
61290+ unsigned long expires;
61291+};
61292+
61293+struct gr_hash_struct {
61294+ void **table;
61295+ void **nametable;
61296+ void *first;
61297+ __u32 table_size;
61298+ __u32 used_size;
61299+ int type;
61300+};
61301+
61302+/* Userspace Grsecurity ACL data structures */
61303+
61304+struct acl_subject_label {
61305+ char *filename;
61306+ ino_t inode;
61307+ dev_t device;
61308+ __u32 mode;
61309+ kernel_cap_t cap_mask;
61310+ kernel_cap_t cap_lower;
61311+ kernel_cap_t cap_invert_audit;
61312+
61313+ struct rlimit res[GR_NLIMITS];
61314+ __u32 resmask;
61315+
61316+ __u8 user_trans_type;
61317+ __u8 group_trans_type;
61318+ uid_t *user_transitions;
61319+ gid_t *group_transitions;
61320+ __u16 user_trans_num;
61321+ __u16 group_trans_num;
61322+
61323+ __u32 sock_families[2];
61324+ __u32 ip_proto[8];
61325+ __u32 ip_type;
61326+ struct acl_ip_label **ips;
61327+ __u32 ip_num;
61328+ __u32 inaddr_any_override;
61329+
61330+ __u32 crashes;
61331+ unsigned long expires;
61332+
61333+ struct acl_subject_label *parent_subject;
61334+ struct gr_hash_struct *hash;
61335+ struct acl_subject_label *prev;
61336+ struct acl_subject_label *next;
61337+
61338+ struct acl_object_label **obj_hash;
61339+ __u32 obj_hash_size;
61340+ __u16 pax_flags;
61341+};
61342+
61343+struct role_allowed_ip {
61344+ __u32 addr;
61345+ __u32 netmask;
61346+
61347+ struct role_allowed_ip *prev;
61348+ struct role_allowed_ip *next;
61349+};
61350+
61351+struct role_transition {
61352+ char *rolename;
61353+
61354+ struct role_transition *prev;
61355+ struct role_transition *next;
61356+};
61357+
61358+struct acl_role_label {
61359+ char *rolename;
61360+ uid_t uidgid;
61361+ __u16 roletype;
61362+
61363+ __u16 auth_attempts;
61364+ unsigned long expires;
61365+
61366+ struct acl_subject_label *root_label;
61367+ struct gr_hash_struct *hash;
61368+
61369+ struct acl_role_label *prev;
61370+ struct acl_role_label *next;
61371+
61372+ struct role_transition *transitions;
61373+ struct role_allowed_ip *allowed_ips;
61374+ uid_t *domain_children;
61375+ __u16 domain_child_num;
61376+
61377+ umode_t umask;
61378+
61379+ struct acl_subject_label **subj_hash;
61380+ __u32 subj_hash_size;
61381+};
61382+
61383+struct user_acl_role_db {
61384+ struct acl_role_label **r_table;
61385+ __u32 num_pointers; /* Number of allocations to track */
61386+ __u32 num_roles; /* Number of roles */
61387+ __u32 num_domain_children; /* Number of domain children */
61388+ __u32 num_subjects; /* Number of subjects */
61389+ __u32 num_objects; /* Number of objects */
61390+};
61391+
61392+struct acl_object_label {
61393+ char *filename;
61394+ ino_t inode;
61395+ dev_t device;
61396+ __u32 mode;
61397+
61398+ struct acl_subject_label *nested;
61399+ struct acl_object_label *globbed;
61400+
61401+ /* next two structures not used */
61402+
61403+ struct acl_object_label *prev;
61404+ struct acl_object_label *next;
61405+};
61406+
61407+struct acl_ip_label {
61408+ char *iface;
61409+ __u32 addr;
61410+ __u32 netmask;
61411+ __u16 low, high;
61412+ __u8 mode;
61413+ __u32 type;
61414+ __u32 proto[8];
61415+
61416+ /* next two structures not used */
61417+
61418+ struct acl_ip_label *prev;
61419+ struct acl_ip_label *next;
61420+};
61421+
61422+struct gr_arg {
61423+ struct user_acl_role_db role_db;
61424+ unsigned char pw[GR_PW_LEN];
61425+ unsigned char salt[GR_SALT_LEN];
61426+ unsigned char sum[GR_SHA_LEN];
61427+ unsigned char sp_role[GR_SPROLE_LEN];
61428+ struct sprole_pw *sprole_pws;
61429+ dev_t segv_device;
61430+ ino_t segv_inode;
61431+ uid_t segv_uid;
61432+ __u16 num_sprole_pws;
61433+ __u16 mode;
61434+};
61435+
61436+struct gr_arg_wrapper {
61437+ struct gr_arg *arg;
61438+ __u32 version;
61439+ __u32 size;
61440+};
61441+
61442+struct subject_map {
61443+ struct acl_subject_label *user;
61444+ struct acl_subject_label *kernel;
61445+ struct subject_map *prev;
61446+ struct subject_map *next;
61447+};
61448+
61449+struct acl_subj_map_db {
61450+ struct subject_map **s_hash;
61451+ __u32 s_size;
61452+};
61453+
61454+/* End Data Structures Section */
61455+
61456+/* Hash functions generated by empirical testing by Brad Spengler
61457+ Makes good use of the low bits of the inode. Generally 0-1 times
61458+ in loop for successful match. 0-3 for unsuccessful match.
61459+ Shift/add algorithm with modulus of table size and an XOR*/
61460+
61461+static __inline__ unsigned int
61462+rhash(const uid_t uid, const __u16 type, const unsigned int sz)
61463+{
61464+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
61465+}
61466+
61467+ static __inline__ unsigned int
61468+shash(const struct acl_subject_label *userp, const unsigned int sz)
61469+{
61470+ return ((const unsigned long)userp % sz);
61471+}
61472+
61473+static __inline__ unsigned int
61474+fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
61475+{
61476+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
61477+}
61478+
61479+static __inline__ unsigned int
61480+nhash(const char *name, const __u16 len, const unsigned int sz)
61481+{
61482+ return full_name_hash((const unsigned char *)name, len) % sz;
61483+}
61484+
61485+#define FOR_EACH_ROLE_START(role) \
61486+ role = role_list; \
61487+ while (role) {
61488+
61489+#define FOR_EACH_ROLE_END(role) \
61490+ role = role->prev; \
61491+ }
61492+
61493+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
61494+ subj = NULL; \
61495+ iter = 0; \
61496+ while (iter < role->subj_hash_size) { \
61497+ if (subj == NULL) \
61498+ subj = role->subj_hash[iter]; \
61499+ if (subj == NULL) { \
61500+ iter++; \
61501+ continue; \
61502+ }
61503+
61504+#define FOR_EACH_SUBJECT_END(subj,iter) \
61505+ subj = subj->next; \
61506+ if (subj == NULL) \
61507+ iter++; \
61508+ }
61509+
61510+
61511+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
61512+ subj = role->hash->first; \
61513+ while (subj != NULL) {
61514+
61515+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
61516+ subj = subj->next; \
61517+ }
61518+
61519+#endif
61520+
61521diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
61522new file mode 100644
61523index 0000000..323ecf2
61524--- /dev/null
61525+++ b/include/linux/gralloc.h
61526@@ -0,0 +1,9 @@
61527+#ifndef __GRALLOC_H
61528+#define __GRALLOC_H
61529+
61530+void acl_free_all(void);
61531+int acl_alloc_stack_init(unsigned long size);
61532+void *acl_alloc(unsigned long len);
61533+void *acl_alloc_num(unsigned long num, unsigned long len);
61534+
61535+#endif
61536diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
61537new file mode 100644
61538index 0000000..b30e9bc
61539--- /dev/null
61540+++ b/include/linux/grdefs.h
61541@@ -0,0 +1,140 @@
61542+#ifndef GRDEFS_H
61543+#define GRDEFS_H
61544+
61545+/* Begin grsecurity status declarations */
61546+
61547+enum {
61548+ GR_READY = 0x01,
61549+ GR_STATUS_INIT = 0x00 // disabled state
61550+};
61551+
61552+/* Begin ACL declarations */
61553+
61554+/* Role flags */
61555+
61556+enum {
61557+ GR_ROLE_USER = 0x0001,
61558+ GR_ROLE_GROUP = 0x0002,
61559+ GR_ROLE_DEFAULT = 0x0004,
61560+ GR_ROLE_SPECIAL = 0x0008,
61561+ GR_ROLE_AUTH = 0x0010,
61562+ GR_ROLE_NOPW = 0x0020,
61563+ GR_ROLE_GOD = 0x0040,
61564+ GR_ROLE_LEARN = 0x0080,
61565+ GR_ROLE_TPE = 0x0100,
61566+ GR_ROLE_DOMAIN = 0x0200,
61567+ GR_ROLE_PAM = 0x0400,
61568+ GR_ROLE_PERSIST = 0x0800
61569+};
61570+
61571+/* ACL Subject and Object mode flags */
61572+enum {
61573+ GR_DELETED = 0x80000000
61574+};
61575+
61576+/* ACL Object-only mode flags */
61577+enum {
61578+ GR_READ = 0x00000001,
61579+ GR_APPEND = 0x00000002,
61580+ GR_WRITE = 0x00000004,
61581+ GR_EXEC = 0x00000008,
61582+ GR_FIND = 0x00000010,
61583+ GR_INHERIT = 0x00000020,
61584+ GR_SETID = 0x00000040,
61585+ GR_CREATE = 0x00000080,
61586+ GR_DELETE = 0x00000100,
61587+ GR_LINK = 0x00000200,
61588+ GR_AUDIT_READ = 0x00000400,
61589+ GR_AUDIT_APPEND = 0x00000800,
61590+ GR_AUDIT_WRITE = 0x00001000,
61591+ GR_AUDIT_EXEC = 0x00002000,
61592+ GR_AUDIT_FIND = 0x00004000,
61593+ GR_AUDIT_INHERIT= 0x00008000,
61594+ GR_AUDIT_SETID = 0x00010000,
61595+ GR_AUDIT_CREATE = 0x00020000,
61596+ GR_AUDIT_DELETE = 0x00040000,
61597+ GR_AUDIT_LINK = 0x00080000,
61598+ GR_PTRACERD = 0x00100000,
61599+ GR_NOPTRACE = 0x00200000,
61600+ GR_SUPPRESS = 0x00400000,
61601+ GR_NOLEARN = 0x00800000,
61602+ GR_INIT_TRANSFER= 0x01000000
61603+};
61604+
61605+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
61606+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
61607+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
61608+
61609+/* ACL subject-only mode flags */
61610+enum {
61611+ GR_KILL = 0x00000001,
61612+ GR_VIEW = 0x00000002,
61613+ GR_PROTECTED = 0x00000004,
61614+ GR_LEARN = 0x00000008,
61615+ GR_OVERRIDE = 0x00000010,
61616+ /* just a placeholder, this mode is only used in userspace */
61617+ GR_DUMMY = 0x00000020,
61618+ GR_PROTSHM = 0x00000040,
61619+ GR_KILLPROC = 0x00000080,
61620+ GR_KILLIPPROC = 0x00000100,
61621+ /* just a placeholder, this mode is only used in userspace */
61622+ GR_NOTROJAN = 0x00000200,
61623+ GR_PROTPROCFD = 0x00000400,
61624+ GR_PROCACCT = 0x00000800,
61625+ GR_RELAXPTRACE = 0x00001000,
61626+ GR_NESTED = 0x00002000,
61627+ GR_INHERITLEARN = 0x00004000,
61628+ GR_PROCFIND = 0x00008000,
61629+ GR_POVERRIDE = 0x00010000,
61630+ GR_KERNELAUTH = 0x00020000,
61631+ GR_ATSECURE = 0x00040000,
61632+ GR_SHMEXEC = 0x00080000
61633+};
61634+
61635+enum {
61636+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
61637+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
61638+ GR_PAX_ENABLE_MPROTECT = 0x0004,
61639+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
61640+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
61641+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
61642+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
61643+ GR_PAX_DISABLE_MPROTECT = 0x0400,
61644+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
61645+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
61646+};
61647+
61648+enum {
61649+ GR_ID_USER = 0x01,
61650+ GR_ID_GROUP = 0x02,
61651+};
61652+
61653+enum {
61654+ GR_ID_ALLOW = 0x01,
61655+ GR_ID_DENY = 0x02,
61656+};
61657+
61658+#define GR_CRASH_RES 31
61659+#define GR_UIDTABLE_MAX 500
61660+
61661+/* begin resource learning section */
61662+enum {
61663+ GR_RLIM_CPU_BUMP = 60,
61664+ GR_RLIM_FSIZE_BUMP = 50000,
61665+ GR_RLIM_DATA_BUMP = 10000,
61666+ GR_RLIM_STACK_BUMP = 1000,
61667+ GR_RLIM_CORE_BUMP = 10000,
61668+ GR_RLIM_RSS_BUMP = 500000,
61669+ GR_RLIM_NPROC_BUMP = 1,
61670+ GR_RLIM_NOFILE_BUMP = 5,
61671+ GR_RLIM_MEMLOCK_BUMP = 50000,
61672+ GR_RLIM_AS_BUMP = 500000,
61673+ GR_RLIM_LOCKS_BUMP = 2,
61674+ GR_RLIM_SIGPENDING_BUMP = 5,
61675+ GR_RLIM_MSGQUEUE_BUMP = 10000,
61676+ GR_RLIM_NICE_BUMP = 1,
61677+ GR_RLIM_RTPRIO_BUMP = 1,
61678+ GR_RLIM_RTTIME_BUMP = 1000000
61679+};
61680+
61681+#endif
61682diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
61683new file mode 100644
61684index 0000000..c9292f7
61685--- /dev/null
61686+++ b/include/linux/grinternal.h
61687@@ -0,0 +1,223 @@
61688+#ifndef __GRINTERNAL_H
61689+#define __GRINTERNAL_H
61690+
61691+#ifdef CONFIG_GRKERNSEC
61692+
61693+#include <linux/fs.h>
61694+#include <linux/mnt_namespace.h>
61695+#include <linux/nsproxy.h>
61696+#include <linux/gracl.h>
61697+#include <linux/grdefs.h>
61698+#include <linux/grmsg.h>
61699+
61700+void gr_add_learn_entry(const char *fmt, ...)
61701+ __attribute__ ((format (printf, 1, 2)));
61702+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
61703+ const struct vfsmount *mnt);
61704+__u32 gr_check_create(const struct dentry *new_dentry,
61705+ const struct dentry *parent,
61706+ const struct vfsmount *mnt, const __u32 mode);
61707+int gr_check_protected_task(const struct task_struct *task);
61708+__u32 to_gr_audit(const __u32 reqmode);
61709+int gr_set_acls(const int type);
61710+int gr_apply_subject_to_task(struct task_struct *task);
61711+int gr_acl_is_enabled(void);
61712+char gr_roletype_to_char(void);
61713+
61714+void gr_handle_alertkill(struct task_struct *task);
61715+char *gr_to_filename(const struct dentry *dentry,
61716+ const struct vfsmount *mnt);
61717+char *gr_to_filename1(const struct dentry *dentry,
61718+ const struct vfsmount *mnt);
61719+char *gr_to_filename2(const struct dentry *dentry,
61720+ const struct vfsmount *mnt);
61721+char *gr_to_filename3(const struct dentry *dentry,
61722+ const struct vfsmount *mnt);
61723+
61724+extern int grsec_enable_ptrace_readexec;
61725+extern int grsec_enable_harden_ptrace;
61726+extern int grsec_enable_link;
61727+extern int grsec_enable_fifo;
61728+extern int grsec_enable_execve;
61729+extern int grsec_enable_shm;
61730+extern int grsec_enable_execlog;
61731+extern int grsec_enable_signal;
61732+extern int grsec_enable_audit_ptrace;
61733+extern int grsec_enable_forkfail;
61734+extern int grsec_enable_time;
61735+extern int grsec_enable_rofs;
61736+extern int grsec_enable_chroot_shmat;
61737+extern int grsec_enable_chroot_mount;
61738+extern int grsec_enable_chroot_double;
61739+extern int grsec_enable_chroot_pivot;
61740+extern int grsec_enable_chroot_chdir;
61741+extern int grsec_enable_chroot_chmod;
61742+extern int grsec_enable_chroot_mknod;
61743+extern int grsec_enable_chroot_fchdir;
61744+extern int grsec_enable_chroot_nice;
61745+extern int grsec_enable_chroot_execlog;
61746+extern int grsec_enable_chroot_caps;
61747+extern int grsec_enable_chroot_sysctl;
61748+extern int grsec_enable_chroot_unix;
61749+extern int grsec_enable_symlinkown;
61750+extern int grsec_symlinkown_gid;
61751+extern int grsec_enable_tpe;
61752+extern int grsec_tpe_gid;
61753+extern int grsec_enable_tpe_all;
61754+extern int grsec_enable_tpe_invert;
61755+extern int grsec_enable_socket_all;
61756+extern int grsec_socket_all_gid;
61757+extern int grsec_enable_socket_client;
61758+extern int grsec_socket_client_gid;
61759+extern int grsec_enable_socket_server;
61760+extern int grsec_socket_server_gid;
61761+extern int grsec_audit_gid;
61762+extern int grsec_enable_group;
61763+extern int grsec_enable_audit_textrel;
61764+extern int grsec_enable_log_rwxmaps;
61765+extern int grsec_enable_mount;
61766+extern int grsec_enable_chdir;
61767+extern int grsec_resource_logging;
61768+extern int grsec_enable_blackhole;
61769+extern int grsec_lastack_retries;
61770+extern int grsec_enable_brute;
61771+extern int grsec_lock;
61772+
61773+extern spinlock_t grsec_alert_lock;
61774+extern unsigned long grsec_alert_wtime;
61775+extern unsigned long grsec_alert_fyet;
61776+
61777+extern spinlock_t grsec_audit_lock;
61778+
61779+extern rwlock_t grsec_exec_file_lock;
61780+
61781+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
61782+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
61783+ (tsk)->exec_file->f_vfsmnt) : "/")
61784+
61785+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
61786+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
61787+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61788+
61789+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
61790+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
61791+ (tsk)->exec_file->f_vfsmnt) : "/")
61792+
61793+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
61794+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
61795+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61796+
61797+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
61798+
61799+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
61800+
61801+#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
61802+ (task)->pid, (cred)->uid, \
61803+ (cred)->euid, (cred)->gid, (cred)->egid, \
61804+ gr_parent_task_fullpath(task), \
61805+ (task)->real_parent->comm, (task)->real_parent->pid, \
61806+ (pcred)->uid, (pcred)->euid, \
61807+ (pcred)->gid, (pcred)->egid
61808+
61809+#define GR_CHROOT_CAPS {{ \
61810+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
61811+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
61812+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
61813+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
61814+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
61815+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
61816+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
61817+
61818+#define security_learn(normal_msg,args...) \
61819+({ \
61820+ read_lock(&grsec_exec_file_lock); \
61821+ gr_add_learn_entry(normal_msg "\n", ## args); \
61822+ read_unlock(&grsec_exec_file_lock); \
61823+})
61824+
61825+enum {
61826+ GR_DO_AUDIT,
61827+ GR_DONT_AUDIT,
61828+ /* used for non-audit messages that we shouldn't kill the task on */
61829+ GR_DONT_AUDIT_GOOD
61830+};
61831+
61832+enum {
61833+ GR_TTYSNIFF,
61834+ GR_RBAC,
61835+ GR_RBAC_STR,
61836+ GR_STR_RBAC,
61837+ GR_RBAC_MODE2,
61838+ GR_RBAC_MODE3,
61839+ GR_FILENAME,
61840+ GR_SYSCTL_HIDDEN,
61841+ GR_NOARGS,
61842+ GR_ONE_INT,
61843+ GR_ONE_INT_TWO_STR,
61844+ GR_ONE_STR,
61845+ GR_STR_INT,
61846+ GR_TWO_STR_INT,
61847+ GR_TWO_INT,
61848+ GR_TWO_U64,
61849+ GR_THREE_INT,
61850+ GR_FIVE_INT_TWO_STR,
61851+ GR_TWO_STR,
61852+ GR_THREE_STR,
61853+ GR_FOUR_STR,
61854+ GR_STR_FILENAME,
61855+ GR_FILENAME_STR,
61856+ GR_FILENAME_TWO_INT,
61857+ GR_FILENAME_TWO_INT_STR,
61858+ GR_TEXTREL,
61859+ GR_PTRACE,
61860+ GR_RESOURCE,
61861+ GR_CAP,
61862+ GR_SIG,
61863+ GR_SIG2,
61864+ GR_CRASH1,
61865+ GR_CRASH2,
61866+ GR_PSACCT,
61867+ GR_RWXMAP
61868+};
61869+
61870+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
61871+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
61872+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
61873+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
61874+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
61875+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
61876+#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)
61877+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
61878+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
61879+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
61880+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
61881+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
61882+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
61883+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
61884+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
61885+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
61886+#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)
61887+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
61888+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
61889+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
61890+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
61891+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
61892+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
61893+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
61894+#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)
61895+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
61896+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
61897+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
61898+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
61899+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
61900+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
61901+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
61902+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
61903+#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)
61904+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
61905+
61906+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
61907+
61908+#endif
61909+
61910+#endif
61911diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
61912new file mode 100644
61913index 0000000..54f4e85
61914--- /dev/null
61915+++ b/include/linux/grmsg.h
61916@@ -0,0 +1,110 @@
61917+#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"
61918+#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"
61919+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
61920+#define GR_STOPMOD_MSG "denied modification of module state by "
61921+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
61922+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
61923+#define GR_IOPERM_MSG "denied use of ioperm() by "
61924+#define GR_IOPL_MSG "denied use of iopl() by "
61925+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
61926+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
61927+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
61928+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
61929+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
61930+#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"
61931+#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"
61932+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
61933+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
61934+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
61935+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
61936+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
61937+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
61938+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
61939+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
61940+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
61941+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
61942+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
61943+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
61944+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
61945+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
61946+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
61947+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
61948+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
61949+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
61950+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
61951+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
61952+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
61953+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
61954+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
61955+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
61956+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
61957+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
61958+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
61959+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
61960+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
61961+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
61962+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
61963+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
61964+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
61965+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
61966+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
61967+#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"
61968+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
61969+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
61970+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
61971+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
61972+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
61973+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
61974+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
61975+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
61976+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
61977+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
61978+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
61979+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
61980+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
61981+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
61982+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
61983+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
61984+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
61985+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
61986+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
61987+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
61988+#define GR_FAILFORK_MSG "failed fork with errno %s by "
61989+#define GR_NICE_CHROOT_MSG "denied priority change by "
61990+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
61991+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
61992+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
61993+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
61994+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
61995+#define GR_TIME_MSG "time set by "
61996+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
61997+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
61998+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
61999+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
62000+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
62001+#define GR_BIND_MSG "denied bind() by "
62002+#define GR_CONNECT_MSG "denied connect() by "
62003+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
62004+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
62005+#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"
62006+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
62007+#define GR_CAP_ACL_MSG "use of %s denied for "
62008+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
62009+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
62010+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
62011+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
62012+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
62013+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
62014+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
62015+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
62016+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
62017+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
62018+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
62019+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
62020+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
62021+#define GR_VM86_MSG "denied use of vm86 by "
62022+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
62023+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
62024+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
62025+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
62026+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
62027diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
62028new file mode 100644
62029index 0000000..38bfb04
62030--- /dev/null
62031+++ b/include/linux/grsecurity.h
62032@@ -0,0 +1,233 @@
62033+#ifndef GR_SECURITY_H
62034+#define GR_SECURITY_H
62035+#include <linux/fs.h>
62036+#include <linux/fs_struct.h>
62037+#include <linux/binfmts.h>
62038+#include <linux/gracl.h>
62039+
62040+/* notify of brain-dead configs */
62041+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62042+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
62043+#endif
62044+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
62045+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
62046+#endif
62047+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
62048+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
62049+#endif
62050+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
62051+#error "CONFIG_PAX enabled, but no PaX options are enabled."
62052+#endif
62053+
62054+#include <linux/compat.h>
62055+
62056+struct user_arg_ptr {
62057+#ifdef CONFIG_COMPAT
62058+ bool is_compat;
62059+#endif
62060+ union {
62061+ const char __user *const __user *native;
62062+#ifdef CONFIG_COMPAT
62063+ compat_uptr_t __user *compat;
62064+#endif
62065+ } ptr;
62066+};
62067+
62068+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
62069+void gr_handle_brute_check(void);
62070+void gr_handle_kernel_exploit(void);
62071+int gr_process_user_ban(void);
62072+
62073+char gr_roletype_to_char(void);
62074+
62075+int gr_acl_enable_at_secure(void);
62076+
62077+int gr_check_user_change(int real, int effective, int fs);
62078+int gr_check_group_change(int real, int effective, int fs);
62079+
62080+void gr_del_task_from_ip_table(struct task_struct *p);
62081+
62082+int gr_pid_is_chrooted(struct task_struct *p);
62083+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
62084+int gr_handle_chroot_nice(void);
62085+int gr_handle_chroot_sysctl(const int op);
62086+int gr_handle_chroot_setpriority(struct task_struct *p,
62087+ const int niceval);
62088+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
62089+int gr_handle_chroot_chroot(const struct dentry *dentry,
62090+ const struct vfsmount *mnt);
62091+void gr_handle_chroot_chdir(struct path *path);
62092+int gr_handle_chroot_chmod(const struct dentry *dentry,
62093+ const struct vfsmount *mnt, const int mode);
62094+int gr_handle_chroot_mknod(const struct dentry *dentry,
62095+ const struct vfsmount *mnt, const int mode);
62096+int gr_handle_chroot_mount(const struct dentry *dentry,
62097+ const struct vfsmount *mnt,
62098+ const char *dev_name);
62099+int gr_handle_chroot_pivot(void);
62100+int gr_handle_chroot_unix(const pid_t pid);
62101+
62102+int gr_handle_rawio(const struct inode *inode);
62103+
62104+void gr_handle_ioperm(void);
62105+void gr_handle_iopl(void);
62106+
62107+umode_t gr_acl_umask(void);
62108+
62109+int gr_tpe_allow(const struct file *file);
62110+
62111+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
62112+void gr_clear_chroot_entries(struct task_struct *task);
62113+
62114+void gr_log_forkfail(const int retval);
62115+void gr_log_timechange(void);
62116+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
62117+void gr_log_chdir(const struct dentry *dentry,
62118+ const struct vfsmount *mnt);
62119+void gr_log_chroot_exec(const struct dentry *dentry,
62120+ const struct vfsmount *mnt);
62121+void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
62122+void gr_log_remount(const char *devname, const int retval);
62123+void gr_log_unmount(const char *devname, const int retval);
62124+void gr_log_mount(const char *from, const char *to, const int retval);
62125+void gr_log_textrel(struct vm_area_struct *vma);
62126+void gr_log_rwxmmap(struct file *file);
62127+void gr_log_rwxmprotect(struct file *file);
62128+
62129+int gr_handle_follow_link(const struct inode *parent,
62130+ const struct inode *inode,
62131+ const struct dentry *dentry,
62132+ const struct vfsmount *mnt);
62133+int gr_handle_fifo(const struct dentry *dentry,
62134+ const struct vfsmount *mnt,
62135+ const struct dentry *dir, const int flag,
62136+ const int acc_mode);
62137+int gr_handle_hardlink(const struct dentry *dentry,
62138+ const struct vfsmount *mnt,
62139+ struct inode *inode,
62140+ const int mode, const char *to);
62141+
62142+int gr_is_capable(const int cap);
62143+int gr_is_capable_nolog(const int cap);
62144+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
62145+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
62146+
62147+void gr_learn_resource(const struct task_struct *task, const int limit,
62148+ const unsigned long wanted, const int gt);
62149+void gr_copy_label(struct task_struct *tsk);
62150+void gr_handle_crash(struct task_struct *task, const int sig);
62151+int gr_handle_signal(const struct task_struct *p, const int sig);
62152+int gr_check_crash_uid(const uid_t uid);
62153+int gr_check_protected_task(const struct task_struct *task);
62154+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
62155+int gr_acl_handle_mmap(const struct file *file,
62156+ const unsigned long prot);
62157+int gr_acl_handle_mprotect(const struct file *file,
62158+ const unsigned long prot);
62159+int gr_check_hidden_task(const struct task_struct *tsk);
62160+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
62161+ const struct vfsmount *mnt);
62162+__u32 gr_acl_handle_utime(const struct dentry *dentry,
62163+ const struct vfsmount *mnt);
62164+__u32 gr_acl_handle_access(const struct dentry *dentry,
62165+ const struct vfsmount *mnt, const int fmode);
62166+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
62167+ const struct vfsmount *mnt, umode_t *mode);
62168+__u32 gr_acl_handle_chown(const struct dentry *dentry,
62169+ const struct vfsmount *mnt);
62170+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
62171+ const struct vfsmount *mnt);
62172+int gr_handle_ptrace(struct task_struct *task, const long request);
62173+int gr_handle_proc_ptrace(struct task_struct *task);
62174+__u32 gr_acl_handle_execve(const struct dentry *dentry,
62175+ const struct vfsmount *mnt);
62176+int gr_check_crash_exec(const struct file *filp);
62177+int gr_acl_is_enabled(void);
62178+void gr_set_kernel_label(struct task_struct *task);
62179+void gr_set_role_label(struct task_struct *task, const uid_t uid,
62180+ const gid_t gid);
62181+int gr_set_proc_label(const struct dentry *dentry,
62182+ const struct vfsmount *mnt,
62183+ const int unsafe_flags);
62184+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
62185+ const struct vfsmount *mnt);
62186+__u32 gr_acl_handle_open(const struct dentry *dentry,
62187+ const struct vfsmount *mnt, int acc_mode);
62188+__u32 gr_acl_handle_creat(const struct dentry *dentry,
62189+ const struct dentry *p_dentry,
62190+ const struct vfsmount *p_mnt,
62191+ int open_flags, int acc_mode, const int imode);
62192+void gr_handle_create(const struct dentry *dentry,
62193+ const struct vfsmount *mnt);
62194+void gr_handle_proc_create(const struct dentry *dentry,
62195+ const struct inode *inode);
62196+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
62197+ const struct dentry *parent_dentry,
62198+ const struct vfsmount *parent_mnt,
62199+ const int mode);
62200+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
62201+ const struct dentry *parent_dentry,
62202+ const struct vfsmount *parent_mnt);
62203+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
62204+ const struct vfsmount *mnt);
62205+void gr_handle_delete(const ino_t ino, const dev_t dev);
62206+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
62207+ const struct vfsmount *mnt);
62208+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
62209+ const struct dentry *parent_dentry,
62210+ const struct vfsmount *parent_mnt,
62211+ const char *from);
62212+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
62213+ const struct dentry *parent_dentry,
62214+ const struct vfsmount *parent_mnt,
62215+ const struct dentry *old_dentry,
62216+ const struct vfsmount *old_mnt, const char *to);
62217+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
62218+int gr_acl_handle_rename(struct dentry *new_dentry,
62219+ struct dentry *parent_dentry,
62220+ const struct vfsmount *parent_mnt,
62221+ struct dentry *old_dentry,
62222+ struct inode *old_parent_inode,
62223+ struct vfsmount *old_mnt, const char *newname);
62224+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
62225+ struct dentry *old_dentry,
62226+ struct dentry *new_dentry,
62227+ struct vfsmount *mnt, const __u8 replace);
62228+__u32 gr_check_link(const struct dentry *new_dentry,
62229+ const struct dentry *parent_dentry,
62230+ const struct vfsmount *parent_mnt,
62231+ const struct dentry *old_dentry,
62232+ const struct vfsmount *old_mnt);
62233+int gr_acl_handle_filldir(const struct file *file, const char *name,
62234+ const unsigned int namelen, const ino_t ino);
62235+
62236+__u32 gr_acl_handle_unix(const struct dentry *dentry,
62237+ const struct vfsmount *mnt);
62238+void gr_acl_handle_exit(void);
62239+void gr_acl_handle_psacct(struct task_struct *task, const long code);
62240+int gr_acl_handle_procpidmem(const struct task_struct *task);
62241+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
62242+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
62243+void gr_audit_ptrace(struct task_struct *task);
62244+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
62245+
62246+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
62247+
62248+#ifdef CONFIG_GRKERNSEC
62249+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
62250+void gr_handle_vm86(void);
62251+void gr_handle_mem_readwrite(u64 from, u64 to);
62252+
62253+void gr_log_badprocpid(const char *entry);
62254+
62255+extern int grsec_enable_dmesg;
62256+extern int grsec_disable_privio;
62257+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62258+extern int grsec_enable_chroot_findtask;
62259+#endif
62260+#ifdef CONFIG_GRKERNSEC_SETXID
62261+extern int grsec_enable_setxid;
62262+#endif
62263+#endif
62264+
62265+#endif
62266diff --git a/include/linux/grsock.h b/include/linux/grsock.h
62267new file mode 100644
62268index 0000000..e7ffaaf
62269--- /dev/null
62270+++ b/include/linux/grsock.h
62271@@ -0,0 +1,19 @@
62272+#ifndef __GRSOCK_H
62273+#define __GRSOCK_H
62274+
62275+extern void gr_attach_curr_ip(const struct sock *sk);
62276+extern int gr_handle_sock_all(const int family, const int type,
62277+ const int protocol);
62278+extern int gr_handle_sock_server(const struct sockaddr *sck);
62279+extern int gr_handle_sock_server_other(const struct sock *sck);
62280+extern int gr_handle_sock_client(const struct sockaddr *sck);
62281+extern int gr_search_connect(struct socket * sock,
62282+ struct sockaddr_in * addr);
62283+extern int gr_search_bind(struct socket * sock,
62284+ struct sockaddr_in * addr);
62285+extern int gr_search_listen(struct socket * sock);
62286+extern int gr_search_accept(struct socket * sock);
62287+extern int gr_search_socket(const int domain, const int type,
62288+ const int protocol);
62289+
62290+#endif
62291diff --git a/include/linux/hid.h b/include/linux/hid.h
62292index 449fa38..b37c8cc 100644
62293--- a/include/linux/hid.h
62294+++ b/include/linux/hid.h
62295@@ -704,7 +704,7 @@ struct hid_ll_driver {
62296 unsigned int code, int value);
62297
62298 int (*parse)(struct hid_device *hdev);
62299-};
62300+} __no_const;
62301
62302 #define PM_HINT_FULLON 1<<5
62303 #define PM_HINT_NORMAL 1<<1
62304diff --git a/include/linux/highmem.h b/include/linux/highmem.h
62305index d3999b4..1304cb4 100644
62306--- a/include/linux/highmem.h
62307+++ b/include/linux/highmem.h
62308@@ -221,6 +221,18 @@ static inline void clear_highpage(struct page *page)
62309 kunmap_atomic(kaddr);
62310 }
62311
62312+static inline void sanitize_highpage(struct page *page)
62313+{
62314+ void *kaddr;
62315+ unsigned long flags;
62316+
62317+ local_irq_save(flags);
62318+ kaddr = kmap_atomic(page);
62319+ clear_page(kaddr);
62320+ kunmap_atomic(kaddr);
62321+ local_irq_restore(flags);
62322+}
62323+
62324 static inline void zero_user_segments(struct page *page,
62325 unsigned start1, unsigned end1,
62326 unsigned start2, unsigned end2)
62327diff --git a/include/linux/i2c.h b/include/linux/i2c.h
62328index ddfa041..a44cfff 100644
62329--- a/include/linux/i2c.h
62330+++ b/include/linux/i2c.h
62331@@ -366,6 +366,7 @@ struct i2c_algorithm {
62332 /* To determine what the adapter supports */
62333 u32 (*functionality) (struct i2c_adapter *);
62334 };
62335+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
62336
62337 /*
62338 * i2c_adapter is the structure used to identify a physical i2c bus along
62339diff --git a/include/linux/i2o.h b/include/linux/i2o.h
62340index d23c3c2..eb63c81 100644
62341--- a/include/linux/i2o.h
62342+++ b/include/linux/i2o.h
62343@@ -565,7 +565,7 @@ struct i2o_controller {
62344 struct i2o_device *exec; /* Executive */
62345 #if BITS_PER_LONG == 64
62346 spinlock_t context_list_lock; /* lock for context_list */
62347- atomic_t context_list_counter; /* needed for unique contexts */
62348+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
62349 struct list_head context_list; /* list of context id's
62350 and pointers */
62351 #endif
62352diff --git a/include/linux/if_team.h b/include/linux/if_team.h
62353index 8185f57..7b2d222 100644
62354--- a/include/linux/if_team.h
62355+++ b/include/linux/if_team.h
62356@@ -74,6 +74,7 @@ struct team_mode_ops {
62357 void (*port_leave)(struct team *team, struct team_port *port);
62358 void (*port_change_mac)(struct team *team, struct team_port *port);
62359 };
62360+typedef struct team_mode_ops __no_const team_mode_ops_no_const;
62361
62362 enum team_option_type {
62363 TEAM_OPTION_TYPE_U32,
62364@@ -136,7 +137,7 @@ struct team {
62365 struct list_head option_inst_list; /* list of option instances */
62366
62367 const struct team_mode *mode;
62368- struct team_mode_ops ops;
62369+ team_mode_ops_no_const ops;
62370 long mode_priv[TEAM_MODE_PRIV_LONGS];
62371 };
62372
62373diff --git a/include/linux/init.h b/include/linux/init.h
62374index 6b95109..bcbdd68 100644
62375--- a/include/linux/init.h
62376+++ b/include/linux/init.h
62377@@ -39,9 +39,15 @@
62378 * Also note, that this data cannot be "const".
62379 */
62380
62381+#ifdef MODULE
62382+#define add_latent_entropy
62383+#else
62384+#define add_latent_entropy __latent_entropy
62385+#endif
62386+
62387 /* These are for everybody (although not all archs will actually
62388 discard it in modules) */
62389-#define __init __section(.init.text) __cold notrace
62390+#define __init __section(.init.text) __cold notrace add_latent_entropy
62391 #define __initdata __section(.init.data)
62392 #define __initconst __section(.init.rodata)
62393 #define __exitdata __section(.exit.data)
62394@@ -83,7 +89,7 @@
62395 #define __exit __section(.exit.text) __exitused __cold notrace
62396
62397 /* Used for HOTPLUG */
62398-#define __devinit __section(.devinit.text) __cold notrace
62399+#define __devinit __section(.devinit.text) __cold notrace add_latent_entropy
62400 #define __devinitdata __section(.devinit.data)
62401 #define __devinitconst __section(.devinit.rodata)
62402 #define __devexit __section(.devexit.text) __exitused __cold notrace
62403@@ -91,7 +97,7 @@
62404 #define __devexitconst __section(.devexit.rodata)
62405
62406 /* Used for HOTPLUG_CPU */
62407-#define __cpuinit __section(.cpuinit.text) __cold notrace
62408+#define __cpuinit __section(.cpuinit.text) __cold notrace add_latent_entropy
62409 #define __cpuinitdata __section(.cpuinit.data)
62410 #define __cpuinitconst __section(.cpuinit.rodata)
62411 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
62412@@ -99,7 +105,7 @@
62413 #define __cpuexitconst __section(.cpuexit.rodata)
62414
62415 /* Used for MEMORY_HOTPLUG */
62416-#define __meminit __section(.meminit.text) __cold notrace
62417+#define __meminit __section(.meminit.text) __cold notrace add_latent_entropy
62418 #define __meminitdata __section(.meminit.data)
62419 #define __meminitconst __section(.meminit.rodata)
62420 #define __memexit __section(.memexit.text) __exitused __cold notrace
62421@@ -294,13 +300,13 @@ void __init parse_early_options(char *cmdline);
62422
62423 /* Each module must use one module_init(). */
62424 #define module_init(initfn) \
62425- static inline initcall_t __inittest(void) \
62426+ static inline __used initcall_t __inittest(void) \
62427 { return initfn; } \
62428 int init_module(void) __attribute__((alias(#initfn)));
62429
62430 /* This is only required if you want to be unloadable. */
62431 #define module_exit(exitfn) \
62432- static inline exitcall_t __exittest(void) \
62433+ static inline __used exitcall_t __exittest(void) \
62434 { return exitfn; } \
62435 void cleanup_module(void) __attribute__((alias(#exitfn)));
62436
62437diff --git a/include/linux/init_task.h b/include/linux/init_task.h
62438index 9e65eff..b131e8b 100644
62439--- a/include/linux/init_task.h
62440+++ b/include/linux/init_task.h
62441@@ -134,6 +134,12 @@ extern struct cred init_cred;
62442
62443 #define INIT_TASK_COMM "swapper"
62444
62445+#ifdef CONFIG_X86
62446+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
62447+#else
62448+#define INIT_TASK_THREAD_INFO
62449+#endif
62450+
62451 /*
62452 * INIT_TASK is used to set up the first task table, touch at
62453 * your own risk!. Base=0, limit=0x1fffff (=2MB)
62454@@ -172,6 +178,7 @@ extern struct cred init_cred;
62455 RCU_INIT_POINTER(.cred, &init_cred), \
62456 .comm = INIT_TASK_COMM, \
62457 .thread = INIT_THREAD, \
62458+ INIT_TASK_THREAD_INFO \
62459 .fs = &init_fs, \
62460 .files = &init_files, \
62461 .signal = &init_signals, \
62462diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
62463index e6ca56d..8583707 100644
62464--- a/include/linux/intel-iommu.h
62465+++ b/include/linux/intel-iommu.h
62466@@ -296,7 +296,7 @@ struct iommu_flush {
62467 u8 fm, u64 type);
62468 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
62469 unsigned int size_order, u64 type);
62470-};
62471+} __no_const;
62472
62473 enum {
62474 SR_DMAR_FECTL_REG,
62475diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
62476index e68a8e5..811b9af 100644
62477--- a/include/linux/interrupt.h
62478+++ b/include/linux/interrupt.h
62479@@ -435,7 +435,7 @@ enum
62480 /* map softirq index to softirq name. update 'softirq_to_name' in
62481 * kernel/softirq.c when adding a new softirq.
62482 */
62483-extern char *softirq_to_name[NR_SOFTIRQS];
62484+extern const char * const softirq_to_name[NR_SOFTIRQS];
62485
62486 /* softirq mask and active fields moved to irq_cpustat_t in
62487 * asm/hardirq.h to get better cache usage. KAO
62488@@ -443,12 +443,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
62489
62490 struct softirq_action
62491 {
62492- void (*action)(struct softirq_action *);
62493+ void (*action)(void);
62494 };
62495
62496 asmlinkage void do_softirq(void);
62497 asmlinkage void __do_softirq(void);
62498-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
62499+extern void open_softirq(int nr, void (*action)(void));
62500 extern void softirq_init(void);
62501 extern void __raise_softirq_irqoff(unsigned int nr);
62502
62503diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
62504index 6883e19..06992b1 100644
62505--- a/include/linux/kallsyms.h
62506+++ b/include/linux/kallsyms.h
62507@@ -15,7 +15,8 @@
62508
62509 struct module;
62510
62511-#ifdef CONFIG_KALLSYMS
62512+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
62513+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62514 /* Lookup the address for a symbol. Returns 0 if not found. */
62515 unsigned long kallsyms_lookup_name(const char *name);
62516
62517@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
62518 /* Stupid that this does nothing, but I didn't create this mess. */
62519 #define __print_symbol(fmt, addr)
62520 #endif /*CONFIG_KALLSYMS*/
62521+#else /* when included by kallsyms.c, vsnprintf.c, or
62522+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
62523+extern void __print_symbol(const char *fmt, unsigned long address);
62524+extern int sprint_backtrace(char *buffer, unsigned long address);
62525+extern int sprint_symbol(char *buffer, unsigned long address);
62526+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
62527+const char *kallsyms_lookup(unsigned long addr,
62528+ unsigned long *symbolsize,
62529+ unsigned long *offset,
62530+ char **modname, char *namebuf);
62531+#endif
62532
62533 /* This macro allows us to keep printk typechecking */
62534 static __printf(1, 2)
62535diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
62536index c4d2fc1..5df9c19 100644
62537--- a/include/linux/kgdb.h
62538+++ b/include/linux/kgdb.h
62539@@ -53,7 +53,7 @@ extern int kgdb_connected;
62540 extern int kgdb_io_module_registered;
62541
62542 extern atomic_t kgdb_setting_breakpoint;
62543-extern atomic_t kgdb_cpu_doing_single_step;
62544+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
62545
62546 extern struct task_struct *kgdb_usethread;
62547 extern struct task_struct *kgdb_contthread;
62548@@ -252,7 +252,7 @@ struct kgdb_arch {
62549 void (*disable_hw_break)(struct pt_regs *regs);
62550 void (*remove_all_hw_break)(void);
62551 void (*correct_hw_break)(void);
62552-};
62553+} __do_const;
62554
62555 /**
62556 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
62557@@ -277,7 +277,7 @@ struct kgdb_io {
62558 void (*pre_exception) (void);
62559 void (*post_exception) (void);
62560 int is_console;
62561-};
62562+} __do_const;
62563
62564 extern struct kgdb_arch arch_kgdb_ops;
62565
62566diff --git a/include/linux/kmod.h b/include/linux/kmod.h
62567index 5398d58..5883a34 100644
62568--- a/include/linux/kmod.h
62569+++ b/include/linux/kmod.h
62570@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
62571 * usually useless though. */
62572 extern __printf(2, 3)
62573 int __request_module(bool wait, const char *name, ...);
62574+extern __printf(3, 4)
62575+int ___request_module(bool wait, char *param_name, const char *name, ...);
62576 #define request_module(mod...) __request_module(true, mod)
62577 #define request_module_nowait(mod...) __request_module(false, mod)
62578 #define try_then_request_module(x, mod...) \
62579diff --git a/include/linux/kref.h b/include/linux/kref.h
62580index 9c07dce..a92fa71 100644
62581--- a/include/linux/kref.h
62582+++ b/include/linux/kref.h
62583@@ -63,7 +63,7 @@ static inline void kref_get(struct kref *kref)
62584 static inline int kref_sub(struct kref *kref, unsigned int count,
62585 void (*release)(struct kref *kref))
62586 {
62587- WARN_ON(release == NULL);
62588+ BUG_ON(release == NULL);
62589
62590 if (atomic_sub_and_test((int) count, &kref->refcount)) {
62591 release(kref);
62592diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
62593index 96c158a..1864db5 100644
62594--- a/include/linux/kvm_host.h
62595+++ b/include/linux/kvm_host.h
62596@@ -345,7 +345,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
62597 void vcpu_load(struct kvm_vcpu *vcpu);
62598 void vcpu_put(struct kvm_vcpu *vcpu);
62599
62600-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62601+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62602 struct module *module);
62603 void kvm_exit(void);
62604
62605@@ -511,7 +511,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
62606 struct kvm_guest_debug *dbg);
62607 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
62608
62609-int kvm_arch_init(void *opaque);
62610+int kvm_arch_init(const void *opaque);
62611 void kvm_arch_exit(void);
62612
62613 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
62614diff --git a/include/linux/libata.h b/include/linux/libata.h
62615index 6e887c7..4539601 100644
62616--- a/include/linux/libata.h
62617+++ b/include/linux/libata.h
62618@@ -910,7 +910,7 @@ struct ata_port_operations {
62619 * fields must be pointers.
62620 */
62621 const struct ata_port_operations *inherits;
62622-};
62623+} __do_const;
62624
62625 struct ata_port_info {
62626 unsigned long flags;
62627diff --git a/include/linux/memory.h b/include/linux/memory.h
62628index 1ac7f6e..a5794d0 100644
62629--- a/include/linux/memory.h
62630+++ b/include/linux/memory.h
62631@@ -143,7 +143,7 @@ struct memory_accessor {
62632 size_t count);
62633 ssize_t (*write)(struct memory_accessor *, const char *buf,
62634 off_t offset, size_t count);
62635-};
62636+} __no_const;
62637
62638 /*
62639 * Kernel text modification mutex, used for code patching. Users of this lock
62640diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
62641index 1318ca6..7521340 100644
62642--- a/include/linux/mfd/abx500.h
62643+++ b/include/linux/mfd/abx500.h
62644@@ -452,6 +452,7 @@ struct abx500_ops {
62645 int (*event_registers_startup_state_get) (struct device *, u8 *);
62646 int (*startup_irq_enabled) (struct device *, unsigned int);
62647 };
62648+typedef struct abx500_ops __no_const abx500_ops_no_const;
62649
62650 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
62651 void abx500_remove_ops(struct device *dev);
62652diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
62653index 9b07725..3d55001 100644
62654--- a/include/linux/mfd/abx500/ux500_chargalg.h
62655+++ b/include/linux/mfd/abx500/ux500_chargalg.h
62656@@ -19,7 +19,7 @@ struct ux500_charger_ops {
62657 int (*enable) (struct ux500_charger *, int, int, int);
62658 int (*kick_wd) (struct ux500_charger *);
62659 int (*update_curr) (struct ux500_charger *, int);
62660-};
62661+} __no_const;
62662
62663 /**
62664 * struct ux500_charger - power supply ux500 charger sub class
62665diff --git a/include/linux/mm.h b/include/linux/mm.h
62666index f9f279c..198da78 100644
62667--- a/include/linux/mm.h
62668+++ b/include/linux/mm.h
62669@@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
62670
62671 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
62672 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
62673+
62674+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
62675+#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
62676+#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
62677+#else
62678 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
62679+#endif
62680+
62681 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
62682 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
62683
62684@@ -1009,34 +1016,6 @@ int set_page_dirty(struct page *page);
62685 int set_page_dirty_lock(struct page *page);
62686 int clear_page_dirty_for_io(struct page *page);
62687
62688-/* Is the vma a continuation of the stack vma above it? */
62689-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
62690-{
62691- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
62692-}
62693-
62694-static inline int stack_guard_page_start(struct vm_area_struct *vma,
62695- unsigned long addr)
62696-{
62697- return (vma->vm_flags & VM_GROWSDOWN) &&
62698- (vma->vm_start == addr) &&
62699- !vma_growsdown(vma->vm_prev, addr);
62700-}
62701-
62702-/* Is the vma a continuation of the stack vma below it? */
62703-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
62704-{
62705- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
62706-}
62707-
62708-static inline int stack_guard_page_end(struct vm_area_struct *vma,
62709- unsigned long addr)
62710-{
62711- return (vma->vm_flags & VM_GROWSUP) &&
62712- (vma->vm_end == addr) &&
62713- !vma_growsup(vma->vm_next, addr);
62714-}
62715-
62716 extern pid_t
62717 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
62718
62719@@ -1135,6 +1114,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
62720 }
62721 #endif
62722
62723+#ifdef CONFIG_MMU
62724+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
62725+#else
62726+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
62727+{
62728+ return __pgprot(0);
62729+}
62730+#endif
62731+
62732 int vma_wants_writenotify(struct vm_area_struct *vma);
62733
62734 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
62735@@ -1153,8 +1141,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
62736 {
62737 return 0;
62738 }
62739+
62740+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
62741+ unsigned long address)
62742+{
62743+ return 0;
62744+}
62745 #else
62746 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
62747+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
62748 #endif
62749
62750 #ifdef __PAGETABLE_PMD_FOLDED
62751@@ -1163,8 +1158,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
62752 {
62753 return 0;
62754 }
62755+
62756+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
62757+ unsigned long address)
62758+{
62759+ return 0;
62760+}
62761 #else
62762 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
62763+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
62764 #endif
62765
62766 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
62767@@ -1182,11 +1184,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
62768 NULL: pud_offset(pgd, address);
62769 }
62770
62771+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
62772+{
62773+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
62774+ NULL: pud_offset(pgd, address);
62775+}
62776+
62777 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
62778 {
62779 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
62780 NULL: pmd_offset(pud, address);
62781 }
62782+
62783+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
62784+{
62785+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
62786+ NULL: pmd_offset(pud, address);
62787+}
62788 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
62789
62790 #if USE_SPLIT_PTLOCKS
62791@@ -1396,6 +1410,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
62792 unsigned long, unsigned long,
62793 unsigned long, unsigned long);
62794 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
62795+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
62796
62797 /* These take the mm semaphore themselves */
62798 extern unsigned long vm_brk(unsigned long, unsigned long);
62799@@ -1458,6 +1473,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
62800 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
62801 struct vm_area_struct **pprev);
62802
62803+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
62804+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
62805+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
62806+
62807 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
62808 NULL if none. Assume start_addr < end_addr. */
62809 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
62810@@ -1486,15 +1505,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
62811 return vma;
62812 }
62813
62814-#ifdef CONFIG_MMU
62815-pgprot_t vm_get_page_prot(unsigned long vm_flags);
62816-#else
62817-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
62818-{
62819- return __pgprot(0);
62820-}
62821-#endif
62822-
62823 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
62824 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
62825 unsigned long pfn, unsigned long size, pgprot_t);
62826@@ -1599,7 +1609,7 @@ extern int unpoison_memory(unsigned long pfn);
62827 extern int sysctl_memory_failure_early_kill;
62828 extern int sysctl_memory_failure_recovery;
62829 extern void shake_page(struct page *p, int access);
62830-extern atomic_long_t mce_bad_pages;
62831+extern atomic_long_unchecked_t mce_bad_pages;
62832 extern int soft_offline_page(struct page *page, int flags);
62833
62834 extern void dump_page(struct page *page);
62835@@ -1630,5 +1640,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
62836 static inline bool page_is_guard(struct page *page) { return false; }
62837 #endif /* CONFIG_DEBUG_PAGEALLOC */
62838
62839+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
62840+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
62841+#else
62842+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
62843+#endif
62844+
62845 #endif /* __KERNEL__ */
62846 #endif /* _LINUX_MM_H */
62847diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
62848index 704a626..bb0705a 100644
62849--- a/include/linux/mm_types.h
62850+++ b/include/linux/mm_types.h
62851@@ -263,6 +263,8 @@ struct vm_area_struct {
62852 #ifdef CONFIG_NUMA
62853 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
62854 #endif
62855+
62856+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
62857 };
62858
62859 struct core_thread {
62860@@ -337,7 +339,7 @@ struct mm_struct {
62861 unsigned long def_flags;
62862 unsigned long nr_ptes; /* Page table pages */
62863 unsigned long start_code, end_code, start_data, end_data;
62864- unsigned long start_brk, brk, start_stack;
62865+ unsigned long brk_gap, start_brk, brk, start_stack;
62866 unsigned long arg_start, arg_end, env_start, env_end;
62867
62868 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
62869@@ -389,6 +391,24 @@ struct mm_struct {
62870 struct cpumask cpumask_allocation;
62871 #endif
62872 struct uprobes_state uprobes_state;
62873+
62874+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62875+ unsigned long pax_flags;
62876+#endif
62877+
62878+#ifdef CONFIG_PAX_DLRESOLVE
62879+ unsigned long call_dl_resolve;
62880+#endif
62881+
62882+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
62883+ unsigned long call_syscall;
62884+#endif
62885+
62886+#ifdef CONFIG_PAX_ASLR
62887+ unsigned long delta_mmap; /* randomized offset */
62888+ unsigned long delta_stack; /* randomized offset */
62889+#endif
62890+
62891 };
62892
62893 static inline void mm_init_cpumask(struct mm_struct *mm)
62894diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
62895index 1d1b1e1..2a13c78 100644
62896--- a/include/linux/mmu_notifier.h
62897+++ b/include/linux/mmu_notifier.h
62898@@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
62899 */
62900 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
62901 ({ \
62902- pte_t __pte; \
62903+ pte_t ___pte; \
62904 struct vm_area_struct *___vma = __vma; \
62905 unsigned long ___address = __address; \
62906- __pte = ptep_clear_flush(___vma, ___address, __ptep); \
62907+ ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
62908 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
62909- __pte; \
62910+ ___pte; \
62911 })
62912
62913 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
62914diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
62915index 68c569f..5f43753 100644
62916--- a/include/linux/mmzone.h
62917+++ b/include/linux/mmzone.h
62918@@ -411,7 +411,7 @@ struct zone {
62919 unsigned long flags; /* zone flags, see below */
62920
62921 /* Zone statistics */
62922- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62923+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62924
62925 /*
62926 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
62927diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
62928index 5db9382..50e801d 100644
62929--- a/include/linux/mod_devicetable.h
62930+++ b/include/linux/mod_devicetable.h
62931@@ -12,7 +12,7 @@
62932 typedef unsigned long kernel_ulong_t;
62933 #endif
62934
62935-#define PCI_ANY_ID (~0)
62936+#define PCI_ANY_ID ((__u16)~0)
62937
62938 struct pci_device_id {
62939 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
62940@@ -131,7 +131,7 @@ struct usb_device_id {
62941 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
62942 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
62943
62944-#define HID_ANY_ID (~0)
62945+#define HID_ANY_ID (~0U)
62946 #define HID_BUS_ANY 0xffff
62947 #define HID_GROUP_ANY 0x0000
62948
62949diff --git a/include/linux/module.h b/include/linux/module.h
62950index fbcafe2..e5d9587 100644
62951--- a/include/linux/module.h
62952+++ b/include/linux/module.h
62953@@ -17,6 +17,7 @@
62954 #include <linux/moduleparam.h>
62955 #include <linux/tracepoint.h>
62956 #include <linux/export.h>
62957+#include <linux/fs.h>
62958
62959 #include <linux/percpu.h>
62960 #include <asm/module.h>
62961@@ -273,19 +274,16 @@ struct module
62962 int (*init)(void);
62963
62964 /* If this is non-NULL, vfree after init() returns */
62965- void *module_init;
62966+ void *module_init_rx, *module_init_rw;
62967
62968 /* Here is the actual code + data, vfree'd on unload. */
62969- void *module_core;
62970+ void *module_core_rx, *module_core_rw;
62971
62972 /* Here are the sizes of the init and core sections */
62973- unsigned int init_size, core_size;
62974+ unsigned int init_size_rw, core_size_rw;
62975
62976 /* The size of the executable code in each section. */
62977- unsigned int init_text_size, core_text_size;
62978-
62979- /* Size of RO sections of the module (text+rodata) */
62980- unsigned int init_ro_size, core_ro_size;
62981+ unsigned int init_size_rx, core_size_rx;
62982
62983 /* Arch-specific module values */
62984 struct mod_arch_specific arch;
62985@@ -341,6 +339,10 @@ struct module
62986 #ifdef CONFIG_EVENT_TRACING
62987 struct ftrace_event_call **trace_events;
62988 unsigned int num_trace_events;
62989+ struct file_operations trace_id;
62990+ struct file_operations trace_enable;
62991+ struct file_operations trace_format;
62992+ struct file_operations trace_filter;
62993 #endif
62994 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
62995 unsigned int num_ftrace_callsites;
62996@@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
62997 bool is_module_percpu_address(unsigned long addr);
62998 bool is_module_text_address(unsigned long addr);
62999
63000+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
63001+{
63002+
63003+#ifdef CONFIG_PAX_KERNEXEC
63004+ if (ktla_ktva(addr) >= (unsigned long)start &&
63005+ ktla_ktva(addr) < (unsigned long)start + size)
63006+ return 1;
63007+#endif
63008+
63009+ return ((void *)addr >= start && (void *)addr < start + size);
63010+}
63011+
63012+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
63013+{
63014+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
63015+}
63016+
63017+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
63018+{
63019+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
63020+}
63021+
63022+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
63023+{
63024+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
63025+}
63026+
63027+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
63028+{
63029+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
63030+}
63031+
63032 static inline int within_module_core(unsigned long addr, struct module *mod)
63033 {
63034- return (unsigned long)mod->module_core <= addr &&
63035- addr < (unsigned long)mod->module_core + mod->core_size;
63036+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
63037 }
63038
63039 static inline int within_module_init(unsigned long addr, struct module *mod)
63040 {
63041- return (unsigned long)mod->module_init <= addr &&
63042- addr < (unsigned long)mod->module_init + mod->init_size;
63043+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
63044 }
63045
63046 /* Search for module by name: must hold module_mutex. */
63047diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
63048index b2be02e..72d2f78 100644
63049--- a/include/linux/moduleloader.h
63050+++ b/include/linux/moduleloader.h
63051@@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
63052
63053 /* Allocator used for allocating struct module, core sections and init
63054 sections. Returns NULL on failure. */
63055-void *module_alloc(unsigned long size);
63056+void *module_alloc(unsigned long size) __size_overflow(1);
63057+
63058+#ifdef CONFIG_PAX_KERNEXEC
63059+void *module_alloc_exec(unsigned long size) __size_overflow(1);
63060+#else
63061+#define module_alloc_exec(x) module_alloc(x)
63062+#endif
63063
63064 /* Free memory returned from module_alloc. */
63065 void module_free(struct module *mod, void *module_region);
63066
63067+#ifdef CONFIG_PAX_KERNEXEC
63068+void module_free_exec(struct module *mod, void *module_region);
63069+#else
63070+#define module_free_exec(x, y) module_free((x), (y))
63071+#endif
63072+
63073 /* Apply the given relocation to the (simplified) ELF. Return -error
63074 or 0. */
63075 int apply_relocate(Elf_Shdr *sechdrs,
63076diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
63077index d6a5806..7c13347 100644
63078--- a/include/linux/moduleparam.h
63079+++ b/include/linux/moduleparam.h
63080@@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
63081 * @len is usually just sizeof(string).
63082 */
63083 #define module_param_string(name, string, len, perm) \
63084- static const struct kparam_string __param_string_##name \
63085+ static const struct kparam_string __param_string_##name __used \
63086 = { len, string }; \
63087 __module_param_call(MODULE_PARAM_PREFIX, name, \
63088 &param_ops_string, \
63089@@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
63090 */
63091 #define module_param_array_named(name, array, type, nump, perm) \
63092 param_check_##type(name, &(array)[0]); \
63093- static const struct kparam_array __param_arr_##name \
63094+ static const struct kparam_array __param_arr_##name __used \
63095 = { .max = ARRAY_SIZE(array), .num = nump, \
63096 .ops = &param_ops_##type, \
63097 .elemsize = sizeof(array[0]), .elem = array }; \
63098diff --git a/include/linux/namei.h b/include/linux/namei.h
63099index ffc0213..2c1f2cb 100644
63100--- a/include/linux/namei.h
63101+++ b/include/linux/namei.h
63102@@ -24,7 +24,7 @@ struct nameidata {
63103 unsigned seq;
63104 int last_type;
63105 unsigned depth;
63106- char *saved_names[MAX_NESTED_LINKS + 1];
63107+ const char *saved_names[MAX_NESTED_LINKS + 1];
63108
63109 /* Intent data */
63110 union {
63111@@ -94,12 +94,12 @@ extern int follow_up(struct path *);
63112 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
63113 extern void unlock_rename(struct dentry *, struct dentry *);
63114
63115-static inline void nd_set_link(struct nameidata *nd, char *path)
63116+static inline void nd_set_link(struct nameidata *nd, const char *path)
63117 {
63118 nd->saved_names[nd->depth] = path;
63119 }
63120
63121-static inline char *nd_get_link(struct nameidata *nd)
63122+static inline const char *nd_get_link(const struct nameidata *nd)
63123 {
63124 return nd->saved_names[nd->depth];
63125 }
63126diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
63127index d94cb14..e64c951 100644
63128--- a/include/linux/netdevice.h
63129+++ b/include/linux/netdevice.h
63130@@ -1026,6 +1026,7 @@ struct net_device_ops {
63131 struct net_device *dev,
63132 int idx);
63133 };
63134+typedef struct net_device_ops __no_const net_device_ops_no_const;
63135
63136 /*
63137 * The DEVICE structure.
63138@@ -1087,7 +1088,7 @@ struct net_device {
63139 int iflink;
63140
63141 struct net_device_stats stats;
63142- atomic_long_t rx_dropped; /* dropped packets by core network
63143+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
63144 * Do not use this in drivers.
63145 */
63146
63147diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
63148new file mode 100644
63149index 0000000..33f4af8
63150--- /dev/null
63151+++ b/include/linux/netfilter/xt_gradm.h
63152@@ -0,0 +1,9 @@
63153+#ifndef _LINUX_NETFILTER_XT_GRADM_H
63154+#define _LINUX_NETFILTER_XT_GRADM_H 1
63155+
63156+struct xt_gradm_mtinfo {
63157+ __u16 flags;
63158+ __u16 invflags;
63159+};
63160+
63161+#endif
63162diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
63163index c65a18a..0c05f3a 100644
63164--- a/include/linux/of_pdt.h
63165+++ b/include/linux/of_pdt.h
63166@@ -32,7 +32,7 @@ struct of_pdt_ops {
63167
63168 /* return 0 on success; fill in 'len' with number of bytes in path */
63169 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
63170-};
63171+} __no_const;
63172
63173 extern void *prom_early_alloc(unsigned long size);
63174
63175diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
63176index a4c5624..79d6d88 100644
63177--- a/include/linux/oprofile.h
63178+++ b/include/linux/oprofile.h
63179@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
63180 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
63181 char const * name, ulong * val);
63182
63183-/** Create a file for read-only access to an atomic_t. */
63184+/** Create a file for read-only access to an atomic_unchecked_t. */
63185 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
63186- char const * name, atomic_t * val);
63187+ char const * name, atomic_unchecked_t * val);
63188
63189 /** create a directory */
63190 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
63191diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
63192index 45db49f..386788e 100644
63193--- a/include/linux/perf_event.h
63194+++ b/include/linux/perf_event.h
63195@@ -879,8 +879,8 @@ struct perf_event {
63196
63197 enum perf_event_active_state state;
63198 unsigned int attach_state;
63199- local64_t count;
63200- atomic64_t child_count;
63201+ local64_t count; /* PaX: fix it one day */
63202+ atomic64_unchecked_t child_count;
63203
63204 /*
63205 * These are the total time in nanoseconds that the event
63206@@ -931,8 +931,8 @@ struct perf_event {
63207 * These accumulate total time (in nanoseconds) that children
63208 * events have been enabled and running, respectively.
63209 */
63210- atomic64_t child_total_time_enabled;
63211- atomic64_t child_total_time_running;
63212+ atomic64_unchecked_t child_total_time_enabled;
63213+ atomic64_unchecked_t child_total_time_running;
63214
63215 /*
63216 * Protect attach/detach and child_list:
63217diff --git a/include/linux/personality.h b/include/linux/personality.h
63218index 8fc7dd1a..c19d89e 100644
63219--- a/include/linux/personality.h
63220+++ b/include/linux/personality.h
63221@@ -44,6 +44,7 @@ enum {
63222 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
63223 ADDR_NO_RANDOMIZE | \
63224 ADDR_COMPAT_LAYOUT | \
63225+ ADDR_LIMIT_3GB | \
63226 MMAP_PAGE_ZERO)
63227
63228 /*
63229diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
63230index e1ac1ce..0675fed 100644
63231--- a/include/linux/pipe_fs_i.h
63232+++ b/include/linux/pipe_fs_i.h
63233@@ -45,9 +45,9 @@ struct pipe_buffer {
63234 struct pipe_inode_info {
63235 wait_queue_head_t wait;
63236 unsigned int nrbufs, curbuf, buffers;
63237- unsigned int readers;
63238- unsigned int writers;
63239- unsigned int waiting_writers;
63240+ atomic_t readers;
63241+ atomic_t writers;
63242+ atomic_t waiting_writers;
63243 unsigned int r_counter;
63244 unsigned int w_counter;
63245 struct page *tmp_page;
63246diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
63247index f271860..6b3bec5 100644
63248--- a/include/linux/pm_runtime.h
63249+++ b/include/linux/pm_runtime.h
63250@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
63251
63252 static inline void pm_runtime_mark_last_busy(struct device *dev)
63253 {
63254- ACCESS_ONCE(dev->power.last_busy) = jiffies;
63255+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
63256 }
63257
63258 #else /* !CONFIG_PM_RUNTIME */
63259diff --git a/include/linux/poison.h b/include/linux/poison.h
63260index 2110a81..13a11bb 100644
63261--- a/include/linux/poison.h
63262+++ b/include/linux/poison.h
63263@@ -19,8 +19,8 @@
63264 * under normal circumstances, used to verify that nobody uses
63265 * non-initialized list entries.
63266 */
63267-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
63268-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
63269+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
63270+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
63271
63272 /********** include/linux/timer.h **********/
63273 /*
63274diff --git a/include/linux/preempt.h b/include/linux/preempt.h
63275index 5a710b9..0b0dab9 100644
63276--- a/include/linux/preempt.h
63277+++ b/include/linux/preempt.h
63278@@ -126,7 +126,7 @@ struct preempt_ops {
63279 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
63280 void (*sched_out)(struct preempt_notifier *notifier,
63281 struct task_struct *next);
63282-};
63283+} __no_const;
63284
63285 /**
63286 * preempt_notifier - key for installing preemption notifiers
63287diff --git a/include/linux/printk.h b/include/linux/printk.h
63288index 1bec2f7..b66e833 100644
63289--- a/include/linux/printk.h
63290+++ b/include/linux/printk.h
63291@@ -94,6 +94,8 @@ void early_printk(const char *fmt, ...);
63292 extern int printk_needs_cpu(int cpu);
63293 extern void printk_tick(void);
63294
63295+extern int kptr_restrict;
63296+
63297 #ifdef CONFIG_PRINTK
63298 asmlinkage __printf(5, 0)
63299 int vprintk_emit(int facility, int level,
63300@@ -128,7 +130,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
63301
63302 extern int printk_delay_msec;
63303 extern int dmesg_restrict;
63304-extern int kptr_restrict;
63305
63306 void log_buf_kexec_setup(void);
63307 void __init setup_log_buf(int early);
63308diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
63309index 3fd2e87..d93a721 100644
63310--- a/include/linux/proc_fs.h
63311+++ b/include/linux/proc_fs.h
63312@@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
63313 return proc_create_data(name, mode, parent, proc_fops, NULL);
63314 }
63315
63316+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
63317+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
63318+{
63319+#ifdef CONFIG_GRKERNSEC_PROC_USER
63320+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
63321+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63322+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
63323+#else
63324+ return proc_create_data(name, mode, parent, proc_fops, NULL);
63325+#endif
63326+}
63327+
63328 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
63329 umode_t mode, struct proc_dir_entry *base,
63330 read_proc_t *read_proc, void * data)
63331@@ -258,7 +270,7 @@ union proc_op {
63332 int (*proc_show)(struct seq_file *m,
63333 struct pid_namespace *ns, struct pid *pid,
63334 struct task_struct *task);
63335-};
63336+} __no_const;
63337
63338 struct ctl_table_header;
63339 struct ctl_table;
63340diff --git a/include/linux/random.h b/include/linux/random.h
63341index ac621ce..c1215f3 100644
63342--- a/include/linux/random.h
63343+++ b/include/linux/random.h
63344@@ -53,6 +53,10 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
63345 unsigned int value);
63346 extern void add_interrupt_randomness(int irq, int irq_flags);
63347
63348+#ifdef CONFIG_PAX_LATENT_ENTROPY
63349+extern void transfer_latent_entropy(void);
63350+#endif
63351+
63352 extern void get_random_bytes(void *buf, int nbytes);
63353 extern void get_random_bytes_arch(void *buf, int nbytes);
63354 void generate_random_uuid(unsigned char uuid_out[16]);
63355@@ -69,12 +73,17 @@ void srandom32(u32 seed);
63356
63357 u32 prandom32(struct rnd_state *);
63358
63359+static inline unsigned long pax_get_random_long(void)
63360+{
63361+ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
63362+}
63363+
63364 /*
63365 * Handle minimum values for seeds
63366 */
63367 static inline u32 __seed(u32 x, u32 m)
63368 {
63369- return (x < m) ? x + m : x;
63370+ return (x <= m) ? x + m + 1 : x;
63371 }
63372
63373 /**
63374diff --git a/include/linux/reboot.h b/include/linux/reboot.h
63375index e0879a7..a12f962 100644
63376--- a/include/linux/reboot.h
63377+++ b/include/linux/reboot.h
63378@@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
63379 * Architecture-specific implementations of sys_reboot commands.
63380 */
63381
63382-extern void machine_restart(char *cmd);
63383-extern void machine_halt(void);
63384-extern void machine_power_off(void);
63385+extern void machine_restart(char *cmd) __noreturn;
63386+extern void machine_halt(void) __noreturn;
63387+extern void machine_power_off(void) __noreturn;
63388
63389 extern void machine_shutdown(void);
63390 struct pt_regs;
63391@@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
63392 */
63393
63394 extern void kernel_restart_prepare(char *cmd);
63395-extern void kernel_restart(char *cmd);
63396-extern void kernel_halt(void);
63397-extern void kernel_power_off(void);
63398+extern void kernel_restart(char *cmd) __noreturn;
63399+extern void kernel_halt(void) __noreturn;
63400+extern void kernel_power_off(void) __noreturn;
63401
63402 extern int C_A_D; /* for sysctl */
63403 void ctrl_alt_del(void);
63404@@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
63405 * Emergency restart, callable from an interrupt handler.
63406 */
63407
63408-extern void emergency_restart(void);
63409+extern void emergency_restart(void) __noreturn;
63410 #include <asm/emergency-restart.h>
63411
63412 #endif
63413diff --git a/include/linux/relay.h b/include/linux/relay.h
63414index 91cacc3..b55ff74 100644
63415--- a/include/linux/relay.h
63416+++ b/include/linux/relay.h
63417@@ -160,7 +160,7 @@ struct rchan_callbacks
63418 * The callback should return 0 if successful, negative if not.
63419 */
63420 int (*remove_buf_file)(struct dentry *dentry);
63421-};
63422+} __no_const;
63423
63424 /*
63425 * CONFIG_RELAY kernel API, kernel/relay.c
63426diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
63427index 6fdf027..ff72610 100644
63428--- a/include/linux/rfkill.h
63429+++ b/include/linux/rfkill.h
63430@@ -147,6 +147,7 @@ struct rfkill_ops {
63431 void (*query)(struct rfkill *rfkill, void *data);
63432 int (*set_block)(void *data, bool blocked);
63433 };
63434+typedef struct rfkill_ops __no_const rfkill_ops_no_const;
63435
63436 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
63437 /**
63438diff --git a/include/linux/rio.h b/include/linux/rio.h
63439index a90ebad..fd87b5d 100644
63440--- a/include/linux/rio.h
63441+++ b/include/linux/rio.h
63442@@ -321,7 +321,7 @@ struct rio_ops {
63443 int mbox, void *buffer, size_t len);
63444 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
63445 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
63446-};
63447+} __no_const;
63448
63449 #define RIO_RESOURCE_MEM 0x00000100
63450 #define RIO_RESOURCE_DOORBELL 0x00000200
63451diff --git a/include/linux/rmap.h b/include/linux/rmap.h
63452index 3fce545..b4fed6e 100644
63453--- a/include/linux/rmap.h
63454+++ b/include/linux/rmap.h
63455@@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
63456 void anon_vma_init(void); /* create anon_vma_cachep */
63457 int anon_vma_prepare(struct vm_area_struct *);
63458 void unlink_anon_vmas(struct vm_area_struct *);
63459-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
63460+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
63461 void anon_vma_moveto_tail(struct vm_area_struct *);
63462-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
63463+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
63464
63465 static inline void anon_vma_merge(struct vm_area_struct *vma,
63466 struct vm_area_struct *next)
63467diff --git a/include/linux/sched.h b/include/linux/sched.h
63468index 4a1f493..5812aeb 100644
63469--- a/include/linux/sched.h
63470+++ b/include/linux/sched.h
63471@@ -101,6 +101,7 @@ struct bio_list;
63472 struct fs_struct;
63473 struct perf_event_context;
63474 struct blk_plug;
63475+struct linux_binprm;
63476
63477 /*
63478 * List of flags we want to share for kernel threads,
63479@@ -384,10 +385,13 @@ struct user_namespace;
63480 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
63481
63482 extern int sysctl_max_map_count;
63483+extern unsigned long sysctl_heap_stack_gap;
63484
63485 #include <linux/aio.h>
63486
63487 #ifdef CONFIG_MMU
63488+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
63489+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
63490 extern void arch_pick_mmap_layout(struct mm_struct *mm);
63491 extern unsigned long
63492 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
63493@@ -406,6 +410,11 @@ static inline void arch_pick_mmap_layout(struct mm_struct *mm) {}
63494 extern void set_dumpable(struct mm_struct *mm, int value);
63495 extern int get_dumpable(struct mm_struct *mm);
63496
63497+/* get/set_dumpable() values */
63498+#define SUID_DUMPABLE_DISABLED 0
63499+#define SUID_DUMPABLE_ENABLED 1
63500+#define SUID_DUMPABLE_SAFE 2
63501+
63502 /* mm flags */
63503 /* dumpable bits */
63504 #define MMF_DUMPABLE 0 /* core dump is permitted */
63505@@ -646,6 +655,17 @@ struct signal_struct {
63506 #ifdef CONFIG_TASKSTATS
63507 struct taskstats *stats;
63508 #endif
63509+
63510+#ifdef CONFIG_GRKERNSEC
63511+ u32 curr_ip;
63512+ u32 saved_ip;
63513+ u32 gr_saddr;
63514+ u32 gr_daddr;
63515+ u16 gr_sport;
63516+ u16 gr_dport;
63517+ u8 used_accept:1;
63518+#endif
63519+
63520 #ifdef CONFIG_AUDIT
63521 unsigned audit_tty;
63522 struct tty_audit_buf *tty_audit_buf;
63523@@ -729,6 +749,11 @@ struct user_struct {
63524 struct key *session_keyring; /* UID's default session keyring */
63525 #endif
63526
63527+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
63528+ unsigned int banned;
63529+ unsigned long ban_expires;
63530+#endif
63531+
63532 /* Hash table maintenance information */
63533 struct hlist_node uidhash_node;
63534 kuid_t uid;
63535@@ -1348,8 +1373,8 @@ struct task_struct {
63536 struct list_head thread_group;
63537
63538 struct completion *vfork_done; /* for vfork() */
63539- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
63540- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63541+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
63542+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63543
63544 cputime_t utime, stime, utimescaled, stimescaled;
63545 cputime_t gtime;
63546@@ -1365,11 +1390,6 @@ struct task_struct {
63547 struct task_cputime cputime_expires;
63548 struct list_head cpu_timers[3];
63549
63550-/* process credentials */
63551- const struct cred __rcu *real_cred; /* objective and real subjective task
63552- * credentials (COW) */
63553- const struct cred __rcu *cred; /* effective (overridable) subjective task
63554- * credentials (COW) */
63555 char comm[TASK_COMM_LEN]; /* executable name excluding path
63556 - access with [gs]et_task_comm (which lock
63557 it with task_lock())
63558@@ -1386,8 +1406,16 @@ struct task_struct {
63559 #endif
63560 /* CPU-specific state of this task */
63561 struct thread_struct thread;
63562+/* thread_info moved to task_struct */
63563+#ifdef CONFIG_X86
63564+ struct thread_info tinfo;
63565+#endif
63566 /* filesystem information */
63567 struct fs_struct *fs;
63568+
63569+ const struct cred __rcu *cred; /* effective (overridable) subjective task
63570+ * credentials (COW) */
63571+
63572 /* open file information */
63573 struct files_struct *files;
63574 /* namespaces */
63575@@ -1431,6 +1459,11 @@ struct task_struct {
63576 struct rt_mutex_waiter *pi_blocked_on;
63577 #endif
63578
63579+/* process credentials */
63580+ const struct cred __rcu *real_cred; /* objective and real subjective task
63581+ * credentials (COW) */
63582+ struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63583+
63584 #ifdef CONFIG_DEBUG_MUTEXES
63585 /* mutex deadlock detection */
63586 struct mutex_waiter *blocked_on;
63587@@ -1547,6 +1580,27 @@ struct task_struct {
63588 unsigned long default_timer_slack_ns;
63589
63590 struct list_head *scm_work_list;
63591+
63592+#ifdef CONFIG_GRKERNSEC
63593+ /* grsecurity */
63594+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63595+ u64 exec_id;
63596+#endif
63597+#ifdef CONFIG_GRKERNSEC_SETXID
63598+ const struct cred *delayed_cred;
63599+#endif
63600+ struct dentry *gr_chroot_dentry;
63601+ struct acl_subject_label *acl;
63602+ struct acl_role_label *role;
63603+ struct file *exec_file;
63604+ u16 acl_role_id;
63605+ /* is this the task that authenticated to the special role */
63606+ u8 acl_sp_role;
63607+ u8 is_writable;
63608+ u8 brute;
63609+ u8 gr_is_chrooted;
63610+#endif
63611+
63612 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
63613 /* Index of current stored address in ret_stack */
63614 int curr_ret_stack;
63615@@ -1585,6 +1639,51 @@ struct task_struct {
63616 #endif
63617 };
63618
63619+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
63620+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
63621+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
63622+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
63623+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
63624+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
63625+
63626+#ifdef CONFIG_PAX_SOFTMODE
63627+extern int pax_softmode;
63628+#endif
63629+
63630+extern int pax_check_flags(unsigned long *);
63631+
63632+/* if tsk != current then task_lock must be held on it */
63633+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63634+static inline unsigned long pax_get_flags(struct task_struct *tsk)
63635+{
63636+ if (likely(tsk->mm))
63637+ return tsk->mm->pax_flags;
63638+ else
63639+ return 0UL;
63640+}
63641+
63642+/* if tsk != current then task_lock must be held on it */
63643+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
63644+{
63645+ if (likely(tsk->mm)) {
63646+ tsk->mm->pax_flags = flags;
63647+ return 0;
63648+ }
63649+ return -EINVAL;
63650+}
63651+#endif
63652+
63653+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
63654+extern void pax_set_initial_flags(struct linux_binprm *bprm);
63655+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
63656+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
63657+#endif
63658+
63659+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
63660+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
63661+extern void pax_report_refcount_overflow(struct pt_regs *regs);
63662+extern void check_object_size(const void *ptr, unsigned long n, bool to);
63663+
63664 /* Future-safe accessor for struct task_struct's cpus_allowed. */
63665 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
63666
63667@@ -2112,7 +2211,9 @@ void yield(void);
63668 extern struct exec_domain default_exec_domain;
63669
63670 union thread_union {
63671+#ifndef CONFIG_X86
63672 struct thread_info thread_info;
63673+#endif
63674 unsigned long stack[THREAD_SIZE/sizeof(long)];
63675 };
63676
63677@@ -2145,6 +2246,7 @@ extern struct pid_namespace init_pid_ns;
63678 */
63679
63680 extern struct task_struct *find_task_by_vpid(pid_t nr);
63681+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
63682 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
63683 struct pid_namespace *ns);
63684
63685@@ -2301,7 +2403,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
63686 extern void exit_itimers(struct signal_struct *);
63687 extern void flush_itimer_signals(void);
63688
63689-extern void do_group_exit(int);
63690+extern __noreturn void do_group_exit(int);
63691
63692 extern void daemonize(const char *, ...);
63693 extern int allow_signal(int);
63694@@ -2502,9 +2604,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
63695
63696 #endif
63697
63698-static inline int object_is_on_stack(void *obj)
63699+static inline int object_starts_on_stack(void *obj)
63700 {
63701- void *stack = task_stack_page(current);
63702+ const void *stack = task_stack_page(current);
63703
63704 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
63705 }
63706diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
63707index 899fbb4..1cb4138 100644
63708--- a/include/linux/screen_info.h
63709+++ b/include/linux/screen_info.h
63710@@ -43,7 +43,8 @@ struct screen_info {
63711 __u16 pages; /* 0x32 */
63712 __u16 vesa_attributes; /* 0x34 */
63713 __u32 capabilities; /* 0x36 */
63714- __u8 _reserved[6]; /* 0x3a */
63715+ __u16 vesapm_size; /* 0x3a */
63716+ __u8 _reserved[4]; /* 0x3c */
63717 } __attribute__((packed));
63718
63719 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
63720diff --git a/include/linux/security.h b/include/linux/security.h
63721index 3dea6a9..81fd81f 100644
63722--- a/include/linux/security.h
63723+++ b/include/linux/security.h
63724@@ -26,6 +26,7 @@
63725 #include <linux/capability.h>
63726 #include <linux/slab.h>
63727 #include <linux/err.h>
63728+#include <linux/grsecurity.h>
63729
63730 struct linux_binprm;
63731 struct cred;
63732diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
63733index fc61854..d7c490b 100644
63734--- a/include/linux/seq_file.h
63735+++ b/include/linux/seq_file.h
63736@@ -25,6 +25,9 @@ struct seq_file {
63737 struct mutex lock;
63738 const struct seq_operations *op;
63739 int poll_event;
63740+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63741+ u64 exec_id;
63742+#endif
63743 void *private;
63744 };
63745
63746@@ -34,6 +37,7 @@ struct seq_operations {
63747 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
63748 int (*show) (struct seq_file *m, void *v);
63749 };
63750+typedef struct seq_operations __no_const seq_operations_no_const;
63751
63752 #define SEQ_SKIP 1
63753
63754diff --git a/include/linux/shm.h b/include/linux/shm.h
63755index 92808b8..c28cac4 100644
63756--- a/include/linux/shm.h
63757+++ b/include/linux/shm.h
63758@@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
63759
63760 /* The task created the shm object. NULL if the task is dead. */
63761 struct task_struct *shm_creator;
63762+#ifdef CONFIG_GRKERNSEC
63763+ time_t shm_createtime;
63764+ pid_t shm_lapid;
63765+#endif
63766 };
63767
63768 /* shm_mode upper byte flags */
63769diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
63770index 642cb73..7ff7f9f 100644
63771--- a/include/linux/skbuff.h
63772+++ b/include/linux/skbuff.h
63773@@ -680,7 +680,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
63774 */
63775 static inline int skb_queue_empty(const struct sk_buff_head *list)
63776 {
63777- return list->next == (struct sk_buff *)list;
63778+ return list->next == (const struct sk_buff *)list;
63779 }
63780
63781 /**
63782@@ -693,7 +693,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
63783 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63784 const struct sk_buff *skb)
63785 {
63786- return skb->next == (struct sk_buff *)list;
63787+ return skb->next == (const struct sk_buff *)list;
63788 }
63789
63790 /**
63791@@ -706,7 +706,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63792 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
63793 const struct sk_buff *skb)
63794 {
63795- return skb->prev == (struct sk_buff *)list;
63796+ return skb->prev == (const struct sk_buff *)list;
63797 }
63798
63799 /**
63800@@ -1605,7 +1605,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
63801 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
63802 */
63803 #ifndef NET_SKB_PAD
63804-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
63805+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
63806 #endif
63807
63808 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
63809diff --git a/include/linux/slab.h b/include/linux/slab.h
63810index 67d5d94..bbd740b 100644
63811--- a/include/linux/slab.h
63812+++ b/include/linux/slab.h
63813@@ -11,12 +11,20 @@
63814
63815 #include <linux/gfp.h>
63816 #include <linux/types.h>
63817+#include <linux/err.h>
63818
63819 /*
63820 * Flags to pass to kmem_cache_create().
63821 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
63822 */
63823 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
63824+
63825+#ifdef CONFIG_PAX_USERCOPY_SLABS
63826+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
63827+#else
63828+#define SLAB_USERCOPY 0x00000000UL
63829+#endif
63830+
63831 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
63832 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
63833 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
63834@@ -87,10 +95,13 @@
63835 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
63836 * Both make kfree a no-op.
63837 */
63838-#define ZERO_SIZE_PTR ((void *)16)
63839+#define ZERO_SIZE_PTR \
63840+({ \
63841+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
63842+ (void *)(-MAX_ERRNO-1L); \
63843+})
63844
63845-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
63846- (unsigned long)ZERO_SIZE_PTR)
63847+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
63848
63849 /*
63850 * struct kmem_cache related prototypes
63851@@ -161,6 +172,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
63852 void kfree(const void *);
63853 void kzfree(const void *);
63854 size_t ksize(const void *);
63855+const char *check_heap_object(const void *ptr, unsigned long n, bool to);
63856+bool is_usercopy_object(const void *ptr);
63857
63858 /*
63859 * Allocator specific definitions. These are mainly used to establish optimized
63860@@ -298,7 +311,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
63861 */
63862 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63863 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63864-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63865+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
63866 #define kmalloc_track_caller(size, flags) \
63867 __kmalloc_track_caller(size, flags, _RET_IP_)
63868 #else
63869@@ -317,7 +330,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63870 */
63871 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63872 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63873-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
63874+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
63875 #define kmalloc_node_track_caller(size, flags, node) \
63876 __kmalloc_node_track_caller(size, flags, node, \
63877 _RET_IP_)
63878diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
63879index fbd1117..0a3d314 100644
63880--- a/include/linux/slab_def.h
63881+++ b/include/linux/slab_def.h
63882@@ -66,10 +66,10 @@ struct kmem_cache {
63883 unsigned long node_allocs;
63884 unsigned long node_frees;
63885 unsigned long node_overflow;
63886- atomic_t allochit;
63887- atomic_t allocmiss;
63888- atomic_t freehit;
63889- atomic_t freemiss;
63890+ atomic_unchecked_t allochit;
63891+ atomic_unchecked_t allocmiss;
63892+ atomic_unchecked_t freehit;
63893+ atomic_unchecked_t freemiss;
63894
63895 /*
63896 * If debugging is enabled, then the allocator can add additional
63897@@ -103,11 +103,16 @@ struct cache_sizes {
63898 #ifdef CONFIG_ZONE_DMA
63899 struct kmem_cache *cs_dmacachep;
63900 #endif
63901+
63902+#ifdef CONFIG_PAX_USERCOPY_SLABS
63903+ struct kmem_cache *cs_usercopycachep;
63904+#endif
63905+
63906 };
63907 extern struct cache_sizes malloc_sizes[];
63908
63909 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63910-void *__kmalloc(size_t size, gfp_t flags);
63911+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63912
63913 #ifdef CONFIG_TRACING
63914 extern void *kmem_cache_alloc_trace(size_t size,
63915@@ -150,6 +155,13 @@ found:
63916 cachep = malloc_sizes[i].cs_dmacachep;
63917 else
63918 #endif
63919+
63920+#ifdef CONFIG_PAX_USERCOPY_SLABS
63921+ if (flags & GFP_USERCOPY)
63922+ cachep = malloc_sizes[i].cs_usercopycachep;
63923+ else
63924+#endif
63925+
63926 cachep = malloc_sizes[i].cs_cachep;
63927
63928 ret = kmem_cache_alloc_trace(size, cachep, flags);
63929@@ -160,7 +172,7 @@ found:
63930 }
63931
63932 #ifdef CONFIG_NUMA
63933-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
63934+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63935 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
63936
63937 #ifdef CONFIG_TRACING
63938@@ -203,6 +215,13 @@ found:
63939 cachep = malloc_sizes[i].cs_dmacachep;
63940 else
63941 #endif
63942+
63943+#ifdef CONFIG_PAX_USERCOPY_SLABS
63944+ if (flags & GFP_USERCOPY)
63945+ cachep = malloc_sizes[i].cs_usercopycachep;
63946+ else
63947+#endif
63948+
63949 cachep = malloc_sizes[i].cs_cachep;
63950
63951 return kmem_cache_alloc_node_trace(size, cachep, flags, node);
63952diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
63953index 0ec00b3..22b4715 100644
63954--- a/include/linux/slob_def.h
63955+++ b/include/linux/slob_def.h
63956@@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
63957 return kmem_cache_alloc_node(cachep, flags, -1);
63958 }
63959
63960-void *__kmalloc_node(size_t size, gfp_t flags, int node);
63961+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63962
63963 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63964 {
63965@@ -29,7 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
63966 return __kmalloc_node(size, flags, -1);
63967 }
63968
63969-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
63970+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
63971 {
63972 return kmalloc(size, flags);
63973 }
63974diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
63975index c2f8c8b..d992a41 100644
63976--- a/include/linux/slub_def.h
63977+++ b/include/linux/slub_def.h
63978@@ -92,7 +92,7 @@ struct kmem_cache {
63979 struct kmem_cache_order_objects max;
63980 struct kmem_cache_order_objects min;
63981 gfp_t allocflags; /* gfp flags to use on each alloc */
63982- int refcount; /* Refcount for slab cache destroy */
63983+ atomic_t refcount; /* Refcount for slab cache destroy */
63984 void (*ctor)(void *);
63985 int inuse; /* Offset to metadata */
63986 int align; /* Alignment */
63987@@ -153,7 +153,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
63988 * Sorry that the following has to be that ugly but some versions of GCC
63989 * have trouble with constant propagation and loops.
63990 */
63991-static __always_inline int kmalloc_index(size_t size)
63992+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
63993 {
63994 if (!size)
63995 return 0;
63996@@ -218,7 +218,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
63997 }
63998
63999 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64000-void *__kmalloc(size_t size, gfp_t flags);
64001+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
64002
64003 static __always_inline void *
64004 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
64005@@ -259,7 +259,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
64006 }
64007 #endif
64008
64009-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
64010+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
64011 {
64012 unsigned int order = get_order(size);
64013 return kmalloc_order_trace(size, flags, order);
64014@@ -284,7 +284,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64015 }
64016
64017 #ifdef CONFIG_NUMA
64018-void *__kmalloc_node(size_t size, gfp_t flags, int node);
64019+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64020 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64021
64022 #ifdef CONFIG_TRACING
64023diff --git a/include/linux/sonet.h b/include/linux/sonet.h
64024index de8832d..0147b46 100644
64025--- a/include/linux/sonet.h
64026+++ b/include/linux/sonet.h
64027@@ -61,7 +61,7 @@ struct sonet_stats {
64028 #include <linux/atomic.h>
64029
64030 struct k_sonet_stats {
64031-#define __HANDLE_ITEM(i) atomic_t i
64032+#define __HANDLE_ITEM(i) atomic_unchecked_t i
64033 __SONET_ITEMS
64034 #undef __HANDLE_ITEM
64035 };
64036diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
64037index 523547e..2cb7140 100644
64038--- a/include/linux/sunrpc/clnt.h
64039+++ b/include/linux/sunrpc/clnt.h
64040@@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
64041 {
64042 switch (sap->sa_family) {
64043 case AF_INET:
64044- return ntohs(((struct sockaddr_in *)sap)->sin_port);
64045+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
64046 case AF_INET6:
64047- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
64048+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
64049 }
64050 return 0;
64051 }
64052@@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
64053 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
64054 const struct sockaddr *src)
64055 {
64056- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
64057+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
64058 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
64059
64060 dsin->sin_family = ssin->sin_family;
64061@@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
64062 if (sa->sa_family != AF_INET6)
64063 return 0;
64064
64065- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
64066+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
64067 }
64068
64069 #endif /* __KERNEL__ */
64070diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
64071index dc0c3cc..8503fb6 100644
64072--- a/include/linux/sunrpc/sched.h
64073+++ b/include/linux/sunrpc/sched.h
64074@@ -106,6 +106,7 @@ struct rpc_call_ops {
64075 void (*rpc_count_stats)(struct rpc_task *, void *);
64076 void (*rpc_release)(void *);
64077 };
64078+typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
64079
64080 struct rpc_task_setup {
64081 struct rpc_task *task;
64082diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
64083index 0b8e3e6..33e0a01 100644
64084--- a/include/linux/sunrpc/svc_rdma.h
64085+++ b/include/linux/sunrpc/svc_rdma.h
64086@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
64087 extern unsigned int svcrdma_max_requests;
64088 extern unsigned int svcrdma_max_req_size;
64089
64090-extern atomic_t rdma_stat_recv;
64091-extern atomic_t rdma_stat_read;
64092-extern atomic_t rdma_stat_write;
64093-extern atomic_t rdma_stat_sq_starve;
64094-extern atomic_t rdma_stat_rq_starve;
64095-extern atomic_t rdma_stat_rq_poll;
64096-extern atomic_t rdma_stat_rq_prod;
64097-extern atomic_t rdma_stat_sq_poll;
64098-extern atomic_t rdma_stat_sq_prod;
64099+extern atomic_unchecked_t rdma_stat_recv;
64100+extern atomic_unchecked_t rdma_stat_read;
64101+extern atomic_unchecked_t rdma_stat_write;
64102+extern atomic_unchecked_t rdma_stat_sq_starve;
64103+extern atomic_unchecked_t rdma_stat_rq_starve;
64104+extern atomic_unchecked_t rdma_stat_rq_poll;
64105+extern atomic_unchecked_t rdma_stat_rq_prod;
64106+extern atomic_unchecked_t rdma_stat_sq_poll;
64107+extern atomic_unchecked_t rdma_stat_sq_prod;
64108
64109 #define RPCRDMA_VERSION 1
64110
64111diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
64112index c34b4c8..a65b67d 100644
64113--- a/include/linux/sysctl.h
64114+++ b/include/linux/sysctl.h
64115@@ -155,7 +155,11 @@ enum
64116 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
64117 };
64118
64119-
64120+#ifdef CONFIG_PAX_SOFTMODE
64121+enum {
64122+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
64123+};
64124+#endif
64125
64126 /* CTL_VM names: */
64127 enum
64128@@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
64129
64130 extern int proc_dostring(struct ctl_table *, int,
64131 void __user *, size_t *, loff_t *);
64132+extern int proc_dostring_modpriv(struct ctl_table *, int,
64133+ void __user *, size_t *, loff_t *);
64134 extern int proc_dointvec(struct ctl_table *, int,
64135 void __user *, size_t *, loff_t *);
64136 extern int proc_dointvec_minmax(struct ctl_table *, int,
64137diff --git a/include/linux/tty.h b/include/linux/tty.h
64138index 9f47ab5..73da944 100644
64139--- a/include/linux/tty.h
64140+++ b/include/linux/tty.h
64141@@ -225,7 +225,7 @@ struct tty_port {
64142 const struct tty_port_operations *ops; /* Port operations */
64143 spinlock_t lock; /* Lock protecting tty field */
64144 int blocked_open; /* Waiting to open */
64145- int count; /* Usage count */
64146+ atomic_t count; /* Usage count */
64147 wait_queue_head_t open_wait; /* Open waiters */
64148 wait_queue_head_t close_wait; /* Close waiters */
64149 wait_queue_head_t delta_msr_wait; /* Modem status change */
64150@@ -525,7 +525,7 @@ extern int tty_port_open(struct tty_port *port,
64151 struct tty_struct *tty, struct file *filp);
64152 static inline int tty_port_users(struct tty_port *port)
64153 {
64154- return port->count + port->blocked_open;
64155+ return atomic_read(&port->count) + port->blocked_open;
64156 }
64157
64158 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
64159diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
64160index fb79dd8d..07d4773 100644
64161--- a/include/linux/tty_ldisc.h
64162+++ b/include/linux/tty_ldisc.h
64163@@ -149,7 +149,7 @@ struct tty_ldisc_ops {
64164
64165 struct module *owner;
64166
64167- int refcount;
64168+ atomic_t refcount;
64169 };
64170
64171 struct tty_ldisc {
64172diff --git a/include/linux/types.h b/include/linux/types.h
64173index 9c1bd53..c2370f6 100644
64174--- a/include/linux/types.h
64175+++ b/include/linux/types.h
64176@@ -220,10 +220,26 @@ typedef struct {
64177 int counter;
64178 } atomic_t;
64179
64180+#ifdef CONFIG_PAX_REFCOUNT
64181+typedef struct {
64182+ int counter;
64183+} atomic_unchecked_t;
64184+#else
64185+typedef atomic_t atomic_unchecked_t;
64186+#endif
64187+
64188 #ifdef CONFIG_64BIT
64189 typedef struct {
64190 long counter;
64191 } atomic64_t;
64192+
64193+#ifdef CONFIG_PAX_REFCOUNT
64194+typedef struct {
64195+ long counter;
64196+} atomic64_unchecked_t;
64197+#else
64198+typedef atomic64_t atomic64_unchecked_t;
64199+#endif
64200 #endif
64201
64202 struct list_head {
64203diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
64204index 5ca0951..ab496a5 100644
64205--- a/include/linux/uaccess.h
64206+++ b/include/linux/uaccess.h
64207@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
64208 long ret; \
64209 mm_segment_t old_fs = get_fs(); \
64210 \
64211- set_fs(KERNEL_DS); \
64212 pagefault_disable(); \
64213- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
64214- pagefault_enable(); \
64215+ set_fs(KERNEL_DS); \
64216+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
64217 set_fs(old_fs); \
64218+ pagefault_enable(); \
64219 ret; \
64220 })
64221
64222diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
64223index 99c1b4d..bb94261 100644
64224--- a/include/linux/unaligned/access_ok.h
64225+++ b/include/linux/unaligned/access_ok.h
64226@@ -6,32 +6,32 @@
64227
64228 static inline u16 get_unaligned_le16(const void *p)
64229 {
64230- return le16_to_cpup((__le16 *)p);
64231+ return le16_to_cpup((const __le16 *)p);
64232 }
64233
64234 static inline u32 get_unaligned_le32(const void *p)
64235 {
64236- return le32_to_cpup((__le32 *)p);
64237+ return le32_to_cpup((const __le32 *)p);
64238 }
64239
64240 static inline u64 get_unaligned_le64(const void *p)
64241 {
64242- return le64_to_cpup((__le64 *)p);
64243+ return le64_to_cpup((const __le64 *)p);
64244 }
64245
64246 static inline u16 get_unaligned_be16(const void *p)
64247 {
64248- return be16_to_cpup((__be16 *)p);
64249+ return be16_to_cpup((const __be16 *)p);
64250 }
64251
64252 static inline u32 get_unaligned_be32(const void *p)
64253 {
64254- return be32_to_cpup((__be32 *)p);
64255+ return be32_to_cpup((const __be32 *)p);
64256 }
64257
64258 static inline u64 get_unaligned_be64(const void *p)
64259 {
64260- return be64_to_cpup((__be64 *)p);
64261+ return be64_to_cpup((const __be64 *)p);
64262 }
64263
64264 static inline void put_unaligned_le16(u16 val, void *p)
64265diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
64266index 547e59c..db6ad19 100644
64267--- a/include/linux/usb/renesas_usbhs.h
64268+++ b/include/linux/usb/renesas_usbhs.h
64269@@ -39,7 +39,7 @@ enum {
64270 */
64271 struct renesas_usbhs_driver_callback {
64272 int (*notify_hotplug)(struct platform_device *pdev);
64273-};
64274+} __no_const;
64275
64276 /*
64277 * callback functions for platform
64278@@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
64279 * VBUS control is needed for Host
64280 */
64281 int (*set_vbus)(struct platform_device *pdev, int enable);
64282-};
64283+} __no_const;
64284
64285 /*
64286 * parameters for renesas usbhs
64287diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
64288index 6f8fbcf..8259001 100644
64289--- a/include/linux/vermagic.h
64290+++ b/include/linux/vermagic.h
64291@@ -25,9 +25,35 @@
64292 #define MODULE_ARCH_VERMAGIC ""
64293 #endif
64294
64295+#ifdef CONFIG_PAX_REFCOUNT
64296+#define MODULE_PAX_REFCOUNT "REFCOUNT "
64297+#else
64298+#define MODULE_PAX_REFCOUNT ""
64299+#endif
64300+
64301+#ifdef CONSTIFY_PLUGIN
64302+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
64303+#else
64304+#define MODULE_CONSTIFY_PLUGIN ""
64305+#endif
64306+
64307+#ifdef STACKLEAK_PLUGIN
64308+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
64309+#else
64310+#define MODULE_STACKLEAK_PLUGIN ""
64311+#endif
64312+
64313+#ifdef CONFIG_GRKERNSEC
64314+#define MODULE_GRSEC "GRSEC "
64315+#else
64316+#define MODULE_GRSEC ""
64317+#endif
64318+
64319 #define VERMAGIC_STRING \
64320 UTS_RELEASE " " \
64321 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
64322 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
64323- MODULE_ARCH_VERMAGIC
64324+ MODULE_ARCH_VERMAGIC \
64325+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
64326+ MODULE_GRSEC
64327
64328diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
64329index dcdfc2b..ec79ab5 100644
64330--- a/include/linux/vmalloc.h
64331+++ b/include/linux/vmalloc.h
64332@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
64333 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
64334 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
64335 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
64336+
64337+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
64338+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
64339+#endif
64340+
64341 /* bits [20..32] reserved for arch specific ioremap internals */
64342
64343 /*
64344@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
64345 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
64346 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
64347 unsigned long start, unsigned long end, gfp_t gfp_mask,
64348- pgprot_t prot, int node, void *caller);
64349+ pgprot_t prot, int node, void *caller) __size_overflow(1);
64350 extern void vfree(const void *addr);
64351
64352 extern void *vmap(struct page **pages, unsigned int count,
64353@@ -123,8 +128,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
64354 extern void free_vm_area(struct vm_struct *area);
64355
64356 /* for /dev/kmem */
64357-extern long vread(char *buf, char *addr, unsigned long count);
64358-extern long vwrite(char *buf, char *addr, unsigned long count);
64359+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
64360+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
64361
64362 /*
64363 * Internals. Dont't use..
64364diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
64365index 65efb92..137adbb 100644
64366--- a/include/linux/vmstat.h
64367+++ b/include/linux/vmstat.h
64368@@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
64369 /*
64370 * Zone based page accounting with per cpu differentials.
64371 */
64372-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64373+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64374
64375 static inline void zone_page_state_add(long x, struct zone *zone,
64376 enum zone_stat_item item)
64377 {
64378- atomic_long_add(x, &zone->vm_stat[item]);
64379- atomic_long_add(x, &vm_stat[item]);
64380+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
64381+ atomic_long_add_unchecked(x, &vm_stat[item]);
64382 }
64383
64384 static inline unsigned long global_page_state(enum zone_stat_item item)
64385 {
64386- long x = atomic_long_read(&vm_stat[item]);
64387+ long x = atomic_long_read_unchecked(&vm_stat[item]);
64388 #ifdef CONFIG_SMP
64389 if (x < 0)
64390 x = 0;
64391@@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
64392 static inline unsigned long zone_page_state(struct zone *zone,
64393 enum zone_stat_item item)
64394 {
64395- long x = atomic_long_read(&zone->vm_stat[item]);
64396+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64397 #ifdef CONFIG_SMP
64398 if (x < 0)
64399 x = 0;
64400@@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
64401 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
64402 enum zone_stat_item item)
64403 {
64404- long x = atomic_long_read(&zone->vm_stat[item]);
64405+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64406
64407 #ifdef CONFIG_SMP
64408 int cpu;
64409@@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
64410
64411 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
64412 {
64413- atomic_long_inc(&zone->vm_stat[item]);
64414- atomic_long_inc(&vm_stat[item]);
64415+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
64416+ atomic_long_inc_unchecked(&vm_stat[item]);
64417 }
64418
64419 static inline void __inc_zone_page_state(struct page *page,
64420@@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
64421
64422 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
64423 {
64424- atomic_long_dec(&zone->vm_stat[item]);
64425- atomic_long_dec(&vm_stat[item]);
64426+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
64427+ atomic_long_dec_unchecked(&vm_stat[item]);
64428 }
64429
64430 static inline void __dec_zone_page_state(struct page *page,
64431diff --git a/include/linux/xattr.h b/include/linux/xattr.h
64432index e5d1220..ef6e406 100644
64433--- a/include/linux/xattr.h
64434+++ b/include/linux/xattr.h
64435@@ -57,6 +57,11 @@
64436 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
64437 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
64438
64439+/* User namespace */
64440+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
64441+#define XATTR_PAX_FLAGS_SUFFIX "flags"
64442+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
64443+
64444 #ifdef __KERNEL__
64445
64446 #include <linux/types.h>
64447diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
64448index 944ecdf..a3994fc 100644
64449--- a/include/media/saa7146_vv.h
64450+++ b/include/media/saa7146_vv.h
64451@@ -161,8 +161,8 @@ struct saa7146_ext_vv
64452 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
64453
64454 /* the extension can override this */
64455- struct v4l2_ioctl_ops vid_ops;
64456- struct v4l2_ioctl_ops vbi_ops;
64457+ v4l2_ioctl_ops_no_const vid_ops;
64458+ v4l2_ioctl_ops_no_const vbi_ops;
64459 /* pointer to the saa7146 core ops */
64460 const struct v4l2_ioctl_ops *core_ops;
64461
64462diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
64463index a056e6e..31023a5 100644
64464--- a/include/media/v4l2-dev.h
64465+++ b/include/media/v4l2-dev.h
64466@@ -73,7 +73,8 @@ struct v4l2_file_operations {
64467 int (*mmap) (struct file *, struct vm_area_struct *);
64468 int (*open) (struct file *);
64469 int (*release) (struct file *);
64470-};
64471+} __do_const;
64472+typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
64473
64474 /*
64475 * Newer version of video_device, handled by videodev2.c
64476diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
64477index d8b76f7..7d5aa18 100644
64478--- a/include/media/v4l2-ioctl.h
64479+++ b/include/media/v4l2-ioctl.h
64480@@ -287,7 +287,7 @@ struct v4l2_ioctl_ops {
64481 long (*vidioc_default) (struct file *file, void *fh,
64482 bool valid_prio, int cmd, void *arg);
64483 };
64484-
64485+typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
64486
64487 /* v4l debugging and diagnostics */
64488
64489diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
64490index 439dadc..1c67e3f 100644
64491--- a/include/net/caif/caif_hsi.h
64492+++ b/include/net/caif/caif_hsi.h
64493@@ -98,7 +98,7 @@ struct cfhsi_drv {
64494 void (*rx_done_cb) (struct cfhsi_drv *drv);
64495 void (*wake_up_cb) (struct cfhsi_drv *drv);
64496 void (*wake_down_cb) (struct cfhsi_drv *drv);
64497-};
64498+} __no_const;
64499
64500 /* Structure implemented by HSI device. */
64501 struct cfhsi_dev {
64502diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
64503index 9e5425b..8136ffc 100644
64504--- a/include/net/caif/cfctrl.h
64505+++ b/include/net/caif/cfctrl.h
64506@@ -52,7 +52,7 @@ struct cfctrl_rsp {
64507 void (*radioset_rsp)(void);
64508 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
64509 struct cflayer *client_layer);
64510-};
64511+} __no_const;
64512
64513 /* Link Setup Parameters for CAIF-Links. */
64514 struct cfctrl_link_param {
64515@@ -101,8 +101,8 @@ struct cfctrl_request_info {
64516 struct cfctrl {
64517 struct cfsrvl serv;
64518 struct cfctrl_rsp res;
64519- atomic_t req_seq_no;
64520- atomic_t rsp_seq_no;
64521+ atomic_unchecked_t req_seq_no;
64522+ atomic_unchecked_t rsp_seq_no;
64523 struct list_head list;
64524 /* Protects from simultaneous access to first_req list */
64525 spinlock_t info_list_lock;
64526diff --git a/include/net/flow.h b/include/net/flow.h
64527index 6c469db..7743b8e 100644
64528--- a/include/net/flow.h
64529+++ b/include/net/flow.h
64530@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
64531
64532 extern void flow_cache_flush(void);
64533 extern void flow_cache_flush_deferred(void);
64534-extern atomic_t flow_cache_genid;
64535+extern atomic_unchecked_t flow_cache_genid;
64536
64537 #endif
64538diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
64539index 2040bff..f4c0733 100644
64540--- a/include/net/inetpeer.h
64541+++ b/include/net/inetpeer.h
64542@@ -51,8 +51,8 @@ struct inet_peer {
64543 */
64544 union {
64545 struct {
64546- atomic_t rid; /* Frag reception counter */
64547- atomic_t ip_id_count; /* IP ID for the next packet */
64548+ atomic_unchecked_t rid; /* Frag reception counter */
64549+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
64550 __u32 tcp_ts;
64551 __u32 tcp_ts_stamp;
64552 };
64553@@ -118,11 +118,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
64554 more++;
64555 inet_peer_refcheck(p);
64556 do {
64557- old = atomic_read(&p->ip_id_count);
64558+ old = atomic_read_unchecked(&p->ip_id_count);
64559 new = old + more;
64560 if (!new)
64561 new = 1;
64562- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
64563+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
64564 return new;
64565 }
64566
64567diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
64568index 78df0866..00e5c9b 100644
64569--- a/include/net/ip_fib.h
64570+++ b/include/net/ip_fib.h
64571@@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
64572
64573 #define FIB_RES_SADDR(net, res) \
64574 ((FIB_RES_NH(res).nh_saddr_genid == \
64575- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
64576+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
64577 FIB_RES_NH(res).nh_saddr : \
64578 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
64579 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
64580diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
64581index 95374d1..2300e36 100644
64582--- a/include/net/ip_vs.h
64583+++ b/include/net/ip_vs.h
64584@@ -510,7 +510,7 @@ struct ip_vs_conn {
64585 struct ip_vs_conn *control; /* Master control connection */
64586 atomic_t n_control; /* Number of controlled ones */
64587 struct ip_vs_dest *dest; /* real server */
64588- atomic_t in_pkts; /* incoming packet counter */
64589+ atomic_unchecked_t in_pkts; /* incoming packet counter */
64590
64591 /* packet transmitter for different forwarding methods. If it
64592 mangles the packet, it must return NF_DROP or better NF_STOLEN,
64593@@ -648,7 +648,7 @@ struct ip_vs_dest {
64594 __be16 port; /* port number of the server */
64595 union nf_inet_addr addr; /* IP address of the server */
64596 volatile unsigned int flags; /* dest status flags */
64597- atomic_t conn_flags; /* flags to copy to conn */
64598+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
64599 atomic_t weight; /* server weight */
64600
64601 atomic_t refcnt; /* reference counter */
64602diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
64603index 69b610a..fe3962c 100644
64604--- a/include/net/irda/ircomm_core.h
64605+++ b/include/net/irda/ircomm_core.h
64606@@ -51,7 +51,7 @@ typedef struct {
64607 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
64608 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
64609 struct ircomm_info *);
64610-} call_t;
64611+} __no_const call_t;
64612
64613 struct ircomm_cb {
64614 irda_queue_t queue;
64615diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
64616index 59ba38bc..d515662 100644
64617--- a/include/net/irda/ircomm_tty.h
64618+++ b/include/net/irda/ircomm_tty.h
64619@@ -35,6 +35,7 @@
64620 #include <linux/termios.h>
64621 #include <linux/timer.h>
64622 #include <linux/tty.h> /* struct tty_struct */
64623+#include <asm/local.h>
64624
64625 #include <net/irda/irias_object.h>
64626 #include <net/irda/ircomm_core.h>
64627@@ -105,8 +106,8 @@ struct ircomm_tty_cb {
64628 unsigned short close_delay;
64629 unsigned short closing_wait; /* time to wait before closing */
64630
64631- int open_count;
64632- int blocked_open; /* # of blocked opens */
64633+ local_t open_count;
64634+ local_t blocked_open; /* # of blocked opens */
64635
64636 /* Protect concurent access to :
64637 * o self->open_count
64638diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
64639index cc7c197..9f2da2a 100644
64640--- a/include/net/iucv/af_iucv.h
64641+++ b/include/net/iucv/af_iucv.h
64642@@ -141,7 +141,7 @@ struct iucv_sock {
64643 struct iucv_sock_list {
64644 struct hlist_head head;
64645 rwlock_t lock;
64646- atomic_t autobind_name;
64647+ atomic_unchecked_t autobind_name;
64648 };
64649
64650 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
64651diff --git a/include/net/neighbour.h b/include/net/neighbour.h
64652index 6cdfeed..55a0256 100644
64653--- a/include/net/neighbour.h
64654+++ b/include/net/neighbour.h
64655@@ -123,7 +123,7 @@ struct neigh_ops {
64656 void (*error_report)(struct neighbour *, struct sk_buff *);
64657 int (*output)(struct neighbour *, struct sk_buff *);
64658 int (*connected_output)(struct neighbour *, struct sk_buff *);
64659-};
64660+} __do_const;
64661
64662 struct pneigh_entry {
64663 struct pneigh_entry *next;
64664diff --git a/include/net/netlink.h b/include/net/netlink.h
64665index 785f37a..c81dc0c 100644
64666--- a/include/net/netlink.h
64667+++ b/include/net/netlink.h
64668@@ -520,7 +520,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
64669 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
64670 {
64671 if (mark)
64672- skb_trim(skb, (unsigned char *) mark - skb->data);
64673+ skb_trim(skb, (const unsigned char *) mark - skb->data);
64674 }
64675
64676 /**
64677diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
64678index bbd023a..97c6d0d 100644
64679--- a/include/net/netns/ipv4.h
64680+++ b/include/net/netns/ipv4.h
64681@@ -57,8 +57,8 @@ struct netns_ipv4 {
64682 unsigned int sysctl_ping_group_range[2];
64683 long sysctl_tcp_mem[3];
64684
64685- atomic_t rt_genid;
64686- atomic_t dev_addr_genid;
64687+ atomic_unchecked_t rt_genid;
64688+ atomic_unchecked_t dev_addr_genid;
64689
64690 #ifdef CONFIG_IP_MROUTE
64691 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
64692diff --git a/include/net/scm.h b/include/net/scm.h
64693index d456f4c..0c0017c 100644
64694--- a/include/net/scm.h
64695+++ b/include/net/scm.h
64696@@ -71,9 +71,11 @@ static __inline__ void scm_destroy(struct scm_cookie *scm)
64697 }
64698
64699 static __inline__ int scm_send(struct socket *sock, struct msghdr *msg,
64700- struct scm_cookie *scm)
64701+ struct scm_cookie *scm, bool forcecreds)
64702 {
64703 memset(scm, 0, sizeof(*scm));
64704+ if (forcecreds)
64705+ scm_set_cred(scm, task_tgid(current), current_cred());
64706 unix_get_peersec_dgram(sock, scm);
64707 if (msg->msg_controllen <= 0)
64708 return 0;
64709diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
64710index a2ef814..31a8e3f 100644
64711--- a/include/net/sctp/sctp.h
64712+++ b/include/net/sctp/sctp.h
64713@@ -318,9 +318,9 @@ do { \
64714
64715 #else /* SCTP_DEBUG */
64716
64717-#define SCTP_DEBUG_PRINTK(whatever...)
64718-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
64719-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
64720+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
64721+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
64722+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
64723 #define SCTP_ENABLE_DEBUG
64724 #define SCTP_DISABLE_DEBUG
64725 #define SCTP_ASSERT(expr, str, func)
64726diff --git a/include/net/sock.h b/include/net/sock.h
64727index 4a45216..7af2578 100644
64728--- a/include/net/sock.h
64729+++ b/include/net/sock.h
64730@@ -303,7 +303,7 @@ struct sock {
64731 #ifdef CONFIG_RPS
64732 __u32 sk_rxhash;
64733 #endif
64734- atomic_t sk_drops;
64735+ atomic_unchecked_t sk_drops;
64736 int sk_rcvbuf;
64737
64738 struct sk_filter __rcu *sk_filter;
64739@@ -1726,7 +1726,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
64740 }
64741
64742 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
64743- char __user *from, char *to,
64744+ char __user *from, unsigned char *to,
64745 int copy, int offset)
64746 {
64747 if (skb->ip_summed == CHECKSUM_NONE) {
64748diff --git a/include/net/tcp.h b/include/net/tcp.h
64749index e79aa48..9929421 100644
64750--- a/include/net/tcp.h
64751+++ b/include/net/tcp.h
64752@@ -1459,7 +1459,7 @@ struct tcp_seq_afinfo {
64753 char *name;
64754 sa_family_t family;
64755 const struct file_operations *seq_fops;
64756- struct seq_operations seq_ops;
64757+ seq_operations_no_const seq_ops;
64758 };
64759
64760 struct tcp_iter_state {
64761diff --git a/include/net/udp.h b/include/net/udp.h
64762index 065f379..b661b40 100644
64763--- a/include/net/udp.h
64764+++ b/include/net/udp.h
64765@@ -244,7 +244,7 @@ struct udp_seq_afinfo {
64766 sa_family_t family;
64767 struct udp_table *udp_table;
64768 const struct file_operations *seq_fops;
64769- struct seq_operations seq_ops;
64770+ seq_operations_no_const seq_ops;
64771 };
64772
64773 struct udp_iter_state {
64774diff --git a/include/net/xfrm.h b/include/net/xfrm.h
64775index e0a55df..5890bca07 100644
64776--- a/include/net/xfrm.h
64777+++ b/include/net/xfrm.h
64778@@ -505,7 +505,7 @@ struct xfrm_policy {
64779 struct timer_list timer;
64780
64781 struct flow_cache_object flo;
64782- atomic_t genid;
64783+ atomic_unchecked_t genid;
64784 u32 priority;
64785 u32 index;
64786 struct xfrm_mark mark;
64787diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
64788index 1a046b1..ee0bef0 100644
64789--- a/include/rdma/iw_cm.h
64790+++ b/include/rdma/iw_cm.h
64791@@ -122,7 +122,7 @@ struct iw_cm_verbs {
64792 int backlog);
64793
64794 int (*destroy_listen)(struct iw_cm_id *cm_id);
64795-};
64796+} __no_const;
64797
64798 /**
64799 * iw_create_cm_id - Create an IW CM identifier.
64800diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
64801index 8f9dfba..610ab6c 100644
64802--- a/include/scsi/libfc.h
64803+++ b/include/scsi/libfc.h
64804@@ -756,6 +756,7 @@ struct libfc_function_template {
64805 */
64806 void (*disc_stop_final) (struct fc_lport *);
64807 };
64808+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
64809
64810 /**
64811 * struct fc_disc - Discovery context
64812@@ -861,7 +862,7 @@ struct fc_lport {
64813 struct fc_vport *vport;
64814
64815 /* Operational Information */
64816- struct libfc_function_template tt;
64817+ libfc_function_template_no_const tt;
64818 u8 link_up;
64819 u8 qfull;
64820 enum fc_lport_state state;
64821diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
64822index ba96988..ecf2eb9 100644
64823--- a/include/scsi/scsi_device.h
64824+++ b/include/scsi/scsi_device.h
64825@@ -163,9 +163,9 @@ struct scsi_device {
64826 unsigned int max_device_blocked; /* what device_blocked counts down from */
64827 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
64828
64829- atomic_t iorequest_cnt;
64830- atomic_t iodone_cnt;
64831- atomic_t ioerr_cnt;
64832+ atomic_unchecked_t iorequest_cnt;
64833+ atomic_unchecked_t iodone_cnt;
64834+ atomic_unchecked_t ioerr_cnt;
64835
64836 struct device sdev_gendev,
64837 sdev_dev;
64838diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
64839index 719faf1..07b6728 100644
64840--- a/include/scsi/scsi_transport_fc.h
64841+++ b/include/scsi/scsi_transport_fc.h
64842@@ -739,7 +739,8 @@ struct fc_function_template {
64843 unsigned long show_host_system_hostname:1;
64844
64845 unsigned long disable_target_scan:1;
64846-};
64847+} __do_const;
64848+typedef struct fc_function_template __no_const fc_function_template_no_const;
64849
64850
64851 /**
64852diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
64853index 030b87c..98a6954 100644
64854--- a/include/sound/ak4xxx-adda.h
64855+++ b/include/sound/ak4xxx-adda.h
64856@@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
64857 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
64858 unsigned char val);
64859 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
64860-};
64861+} __no_const;
64862
64863 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
64864
64865diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
64866index 8c05e47..2b5df97 100644
64867--- a/include/sound/hwdep.h
64868+++ b/include/sound/hwdep.h
64869@@ -49,7 +49,7 @@ struct snd_hwdep_ops {
64870 struct snd_hwdep_dsp_status *status);
64871 int (*dsp_load)(struct snd_hwdep *hw,
64872 struct snd_hwdep_dsp_image *image);
64873-};
64874+} __no_const;
64875
64876 struct snd_hwdep {
64877 struct snd_card *card;
64878diff --git a/include/sound/info.h b/include/sound/info.h
64879index 9ca1a49..aba1728 100644
64880--- a/include/sound/info.h
64881+++ b/include/sound/info.h
64882@@ -44,7 +44,7 @@ struct snd_info_entry_text {
64883 struct snd_info_buffer *buffer);
64884 void (*write)(struct snd_info_entry *entry,
64885 struct snd_info_buffer *buffer);
64886-};
64887+} __no_const;
64888
64889 struct snd_info_entry_ops {
64890 int (*open)(struct snd_info_entry *entry,
64891diff --git a/include/sound/pcm.h b/include/sound/pcm.h
64892index 0d11128..814178e 100644
64893--- a/include/sound/pcm.h
64894+++ b/include/sound/pcm.h
64895@@ -81,6 +81,7 @@ struct snd_pcm_ops {
64896 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
64897 int (*ack)(struct snd_pcm_substream *substream);
64898 };
64899+typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
64900
64901 /*
64902 *
64903diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
64904index af1b49e..a5d55a5 100644
64905--- a/include/sound/sb16_csp.h
64906+++ b/include/sound/sb16_csp.h
64907@@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
64908 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
64909 int (*csp_stop) (struct snd_sb_csp * p);
64910 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
64911-};
64912+} __no_const;
64913
64914 /*
64915 * CSP private data
64916diff --git a/include/sound/soc.h b/include/sound/soc.h
64917index c703871..f7fbbbd 100644
64918--- a/include/sound/soc.h
64919+++ b/include/sound/soc.h
64920@@ -757,7 +757,7 @@ struct snd_soc_platform_driver {
64921 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
64922 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
64923 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
64924-};
64925+} __do_const;
64926
64927 struct snd_soc_platform {
64928 const char *name;
64929@@ -949,7 +949,7 @@ struct snd_soc_pcm_runtime {
64930 struct snd_soc_dai_link *dai_link;
64931 struct mutex pcm_mutex;
64932 enum snd_soc_pcm_subclass pcm_subclass;
64933- struct snd_pcm_ops ops;
64934+ snd_pcm_ops_no_const ops;
64935
64936 unsigned int dev_registered:1;
64937
64938diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
64939index 0c3c2fb..d9d9990 100644
64940--- a/include/sound/tea575x-tuner.h
64941+++ b/include/sound/tea575x-tuner.h
64942@@ -44,7 +44,7 @@ struct snd_tea575x_ops {
64943
64944 struct snd_tea575x {
64945 struct v4l2_device *v4l2_dev;
64946- struct v4l2_file_operations fops;
64947+ v4l2_file_operations_no_const fops;
64948 struct video_device vd; /* video device */
64949 int radio_nr; /* radio_nr */
64950 bool tea5759; /* 5759 chip is present */
64951diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
64952index 4119966..1a4671c 100644
64953--- a/include/sound/ymfpci.h
64954+++ b/include/sound/ymfpci.h
64955@@ -358,7 +358,7 @@ struct snd_ymfpci {
64956 spinlock_t reg_lock;
64957 spinlock_t voice_lock;
64958 wait_queue_head_t interrupt_sleep;
64959- atomic_t interrupt_sleep_count;
64960+ atomic_unchecked_t interrupt_sleep_count;
64961 struct snd_info_entry *proc_entry;
64962 const struct firmware *dsp_microcode;
64963 const struct firmware *controller_microcode;
64964diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
64965index 362e0d9..36b9a83 100644
64966--- a/include/target/target_core_base.h
64967+++ b/include/target/target_core_base.h
64968@@ -441,7 +441,7 @@ struct t10_reservation_ops {
64969 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
64970 int (*t10_pr_register)(struct se_cmd *);
64971 int (*t10_pr_clear)(struct se_cmd *);
64972-};
64973+} __no_const;
64974
64975 struct t10_reservation {
64976 /* Reservation effects all target ports */
64977@@ -780,7 +780,7 @@ struct se_device {
64978 spinlock_t stats_lock;
64979 /* Active commands on this virtual SE device */
64980 atomic_t simple_cmds;
64981- atomic_t dev_ordered_id;
64982+ atomic_unchecked_t dev_ordered_id;
64983 atomic_t execute_tasks;
64984 atomic_t dev_ordered_sync;
64985 atomic_t dev_qf_count;
64986diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
64987new file mode 100644
64988index 0000000..2efe49d
64989--- /dev/null
64990+++ b/include/trace/events/fs.h
64991@@ -0,0 +1,53 @@
64992+#undef TRACE_SYSTEM
64993+#define TRACE_SYSTEM fs
64994+
64995+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
64996+#define _TRACE_FS_H
64997+
64998+#include <linux/fs.h>
64999+#include <linux/tracepoint.h>
65000+
65001+TRACE_EVENT(do_sys_open,
65002+
65003+ TP_PROTO(char *filename, int flags, int mode),
65004+
65005+ TP_ARGS(filename, flags, mode),
65006+
65007+ TP_STRUCT__entry(
65008+ __string( filename, filename )
65009+ __field( int, flags )
65010+ __field( int, mode )
65011+ ),
65012+
65013+ TP_fast_assign(
65014+ __assign_str(filename, filename);
65015+ __entry->flags = flags;
65016+ __entry->mode = mode;
65017+ ),
65018+
65019+ TP_printk("\"%s\" %x %o",
65020+ __get_str(filename), __entry->flags, __entry->mode)
65021+);
65022+
65023+TRACE_EVENT(open_exec,
65024+
65025+ TP_PROTO(const char *filename),
65026+
65027+ TP_ARGS(filename),
65028+
65029+ TP_STRUCT__entry(
65030+ __string( filename, filename )
65031+ ),
65032+
65033+ TP_fast_assign(
65034+ __assign_str(filename, filename);
65035+ ),
65036+
65037+ TP_printk("\"%s\"",
65038+ __get_str(filename))
65039+);
65040+
65041+#endif /* _TRACE_FS_H */
65042+
65043+/* This part must be outside protection */
65044+#include <trace/define_trace.h>
65045diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
65046index 1c09820..7f5ec79 100644
65047--- a/include/trace/events/irq.h
65048+++ b/include/trace/events/irq.h
65049@@ -36,7 +36,7 @@ struct softirq_action;
65050 */
65051 TRACE_EVENT(irq_handler_entry,
65052
65053- TP_PROTO(int irq, struct irqaction *action),
65054+ TP_PROTO(int irq, const struct irqaction *action),
65055
65056 TP_ARGS(irq, action),
65057
65058@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
65059 */
65060 TRACE_EVENT(irq_handler_exit,
65061
65062- TP_PROTO(int irq, struct irqaction *action, int ret),
65063+ TP_PROTO(int irq, const struct irqaction *action, int ret),
65064
65065 TP_ARGS(irq, action, ret),
65066
65067diff --git a/include/video/udlfb.h b/include/video/udlfb.h
65068index f9466fa..f4e2b81 100644
65069--- a/include/video/udlfb.h
65070+++ b/include/video/udlfb.h
65071@@ -53,10 +53,10 @@ struct dlfb_data {
65072 u32 pseudo_palette[256];
65073 int blank_mode; /*one of FB_BLANK_ */
65074 /* blit-only rendering path metrics, exposed through sysfs */
65075- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65076- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
65077- atomic_t bytes_sent; /* to usb, after compression including overhead */
65078- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
65079+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65080+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
65081+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
65082+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
65083 };
65084
65085 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
65086diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
65087index 0993a22..32ba2fe 100644
65088--- a/include/video/uvesafb.h
65089+++ b/include/video/uvesafb.h
65090@@ -177,6 +177,7 @@ struct uvesafb_par {
65091 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
65092 u8 pmi_setpal; /* PMI for palette changes */
65093 u16 *pmi_base; /* protected mode interface location */
65094+ u8 *pmi_code; /* protected mode code location */
65095 void *pmi_start;
65096 void *pmi_pal;
65097 u8 *vbe_state_orig; /*
65098diff --git a/init/Kconfig b/init/Kconfig
65099index d07dcf9..fa47d0e 100644
65100--- a/init/Kconfig
65101+++ b/init/Kconfig
65102@@ -835,6 +835,7 @@ endif # CGROUPS
65103
65104 config CHECKPOINT_RESTORE
65105 bool "Checkpoint/restore support" if EXPERT
65106+ depends on !GRKERNSEC
65107 default n
65108 help
65109 Enables additional kernel features in a sake of checkpoint/restore.
65110@@ -1014,6 +1015,7 @@ config UIDGID_CONVERTED
65111 # Security modules
65112 depends on SECURITY_TOMOYO = n
65113 depends on SECURITY_APPARMOR = n
65114+ depends on GRKERNSEC = n
65115
65116 config UIDGID_STRICT_TYPE_CHECKS
65117 bool "Require conversions between uid/gids and their internal representation"
65118@@ -1401,7 +1403,7 @@ config SLUB_DEBUG
65119
65120 config COMPAT_BRK
65121 bool "Disable heap randomization"
65122- default y
65123+ default n
65124 help
65125 Randomizing heap placement makes heap exploits harder, but it
65126 also breaks ancient binaries (including anything libc5 based).
65127@@ -1584,7 +1586,7 @@ config INIT_ALL_POSSIBLE
65128 config STOP_MACHINE
65129 bool
65130 default y
65131- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
65132+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
65133 help
65134 Need stop_machine() primitive.
65135
65136diff --git a/init/Makefile b/init/Makefile
65137index 7bc47ee..6da2dc7 100644
65138--- a/init/Makefile
65139+++ b/init/Makefile
65140@@ -2,6 +2,9 @@
65141 # Makefile for the linux kernel.
65142 #
65143
65144+ccflags-y := $(GCC_PLUGINS_CFLAGS)
65145+asflags-y := $(GCC_PLUGINS_AFLAGS)
65146+
65147 obj-y := main.o version.o mounts.o
65148 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
65149 obj-y += noinitramfs.o
65150diff --git a/init/do_mounts.c b/init/do_mounts.c
65151index d3f0aee..c9322f5 100644
65152--- a/init/do_mounts.c
65153+++ b/init/do_mounts.c
65154@@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
65155 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
65156 {
65157 struct super_block *s;
65158- int err = sys_mount(name, "/root", fs, flags, data);
65159+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
65160 if (err)
65161 return err;
65162
65163- sys_chdir("/root");
65164+ sys_chdir((const char __force_user *)"/root");
65165 s = current->fs->pwd.dentry->d_sb;
65166 ROOT_DEV = s->s_dev;
65167 printk(KERN_INFO
65168@@ -460,18 +460,18 @@ void __init change_floppy(char *fmt, ...)
65169 va_start(args, fmt);
65170 vsprintf(buf, fmt, args);
65171 va_end(args);
65172- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
65173+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
65174 if (fd >= 0) {
65175 sys_ioctl(fd, FDEJECT, 0);
65176 sys_close(fd);
65177 }
65178 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
65179- fd = sys_open("/dev/console", O_RDWR, 0);
65180+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
65181 if (fd >= 0) {
65182 sys_ioctl(fd, TCGETS, (long)&termios);
65183 termios.c_lflag &= ~ICANON;
65184 sys_ioctl(fd, TCSETSF, (long)&termios);
65185- sys_read(fd, &c, 1);
65186+ sys_read(fd, (char __user *)&c, 1);
65187 termios.c_lflag |= ICANON;
65188 sys_ioctl(fd, TCSETSF, (long)&termios);
65189 sys_close(fd);
65190@@ -565,6 +565,6 @@ void __init prepare_namespace(void)
65191 mount_root();
65192 out:
65193 devtmpfs_mount("dev");
65194- sys_mount(".", "/", NULL, MS_MOVE, NULL);
65195- sys_chroot(".");
65196+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65197+ sys_chroot((const char __force_user *)".");
65198 }
65199diff --git a/init/do_mounts.h b/init/do_mounts.h
65200index f5b978a..69dbfe8 100644
65201--- a/init/do_mounts.h
65202+++ b/init/do_mounts.h
65203@@ -15,15 +15,15 @@ extern int root_mountflags;
65204
65205 static inline int create_dev(char *name, dev_t dev)
65206 {
65207- sys_unlink(name);
65208- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
65209+ sys_unlink((char __force_user *)name);
65210+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
65211 }
65212
65213 #if BITS_PER_LONG == 32
65214 static inline u32 bstat(char *name)
65215 {
65216 struct stat64 stat;
65217- if (sys_stat64(name, &stat) != 0)
65218+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
65219 return 0;
65220 if (!S_ISBLK(stat.st_mode))
65221 return 0;
65222@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
65223 static inline u32 bstat(char *name)
65224 {
65225 struct stat stat;
65226- if (sys_newstat(name, &stat) != 0)
65227+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
65228 return 0;
65229 if (!S_ISBLK(stat.st_mode))
65230 return 0;
65231diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
65232index 135959a2..28a3f43 100644
65233--- a/init/do_mounts_initrd.c
65234+++ b/init/do_mounts_initrd.c
65235@@ -53,13 +53,13 @@ static void __init handle_initrd(void)
65236 create_dev("/dev/root.old", Root_RAM0);
65237 /* mount initrd on rootfs' /root */
65238 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
65239- sys_mkdir("/old", 0700);
65240- root_fd = sys_open("/", 0, 0);
65241- old_fd = sys_open("/old", 0, 0);
65242+ sys_mkdir((const char __force_user *)"/old", 0700);
65243+ root_fd = sys_open((const char __force_user *)"/", 0, 0);
65244+ old_fd = sys_open((const char __force_user *)"/old", 0, 0);
65245 /* move initrd over / and chdir/chroot in initrd root */
65246- sys_chdir("/root");
65247- sys_mount(".", "/", NULL, MS_MOVE, NULL);
65248- sys_chroot(".");
65249+ sys_chdir((const char __force_user *)"/root");
65250+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65251+ sys_chroot((const char __force_user *)".");
65252
65253 /*
65254 * In case that a resume from disk is carried out by linuxrc or one of
65255@@ -76,15 +76,15 @@ static void __init handle_initrd(void)
65256
65257 /* move initrd to rootfs' /old */
65258 sys_fchdir(old_fd);
65259- sys_mount("/", ".", NULL, MS_MOVE, NULL);
65260+ sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
65261 /* switch root and cwd back to / of rootfs */
65262 sys_fchdir(root_fd);
65263- sys_chroot(".");
65264+ sys_chroot((const char __force_user *)".");
65265 sys_close(old_fd);
65266 sys_close(root_fd);
65267
65268 if (new_decode_dev(real_root_dev) == Root_RAM0) {
65269- sys_chdir("/old");
65270+ sys_chdir((const char __force_user *)"/old");
65271 return;
65272 }
65273
65274@@ -92,17 +92,17 @@ static void __init handle_initrd(void)
65275 mount_root();
65276
65277 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
65278- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
65279+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
65280 if (!error)
65281 printk("okay\n");
65282 else {
65283- int fd = sys_open("/dev/root.old", O_RDWR, 0);
65284+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
65285 if (error == -ENOENT)
65286 printk("/initrd does not exist. Ignored.\n");
65287 else
65288 printk("failed\n");
65289 printk(KERN_NOTICE "Unmounting old root\n");
65290- sys_umount("/old", MNT_DETACH);
65291+ sys_umount((char __force_user *)"/old", MNT_DETACH);
65292 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
65293 if (fd < 0) {
65294 error = fd;
65295@@ -125,11 +125,11 @@ int __init initrd_load(void)
65296 * mounted in the normal path.
65297 */
65298 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
65299- sys_unlink("/initrd.image");
65300+ sys_unlink((const char __force_user *)"/initrd.image");
65301 handle_initrd();
65302 return 1;
65303 }
65304 }
65305- sys_unlink("/initrd.image");
65306+ sys_unlink((const char __force_user *)"/initrd.image");
65307 return 0;
65308 }
65309diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
65310index 8cb6db5..d729f50 100644
65311--- a/init/do_mounts_md.c
65312+++ b/init/do_mounts_md.c
65313@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
65314 partitioned ? "_d" : "", minor,
65315 md_setup_args[ent].device_names);
65316
65317- fd = sys_open(name, 0, 0);
65318+ fd = sys_open((char __force_user *)name, 0, 0);
65319 if (fd < 0) {
65320 printk(KERN_ERR "md: open failed - cannot start "
65321 "array %s\n", name);
65322@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
65323 * array without it
65324 */
65325 sys_close(fd);
65326- fd = sys_open(name, 0, 0);
65327+ fd = sys_open((char __force_user *)name, 0, 0);
65328 sys_ioctl(fd, BLKRRPART, 0);
65329 }
65330 sys_close(fd);
65331@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
65332
65333 wait_for_device_probe();
65334
65335- fd = sys_open("/dev/md0", 0, 0);
65336+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
65337 if (fd >= 0) {
65338 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
65339 sys_close(fd);
65340diff --git a/init/init_task.c b/init/init_task.c
65341index 8b2f399..f0797c9 100644
65342--- a/init/init_task.c
65343+++ b/init/init_task.c
65344@@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
65345 * Initial thread structure. Alignment of this is handled by a special
65346 * linker map entry.
65347 */
65348+#ifdef CONFIG_X86
65349+union thread_union init_thread_union __init_task_data;
65350+#else
65351 union thread_union init_thread_union __init_task_data =
65352 { INIT_THREAD_INFO(init_task) };
65353+#endif
65354diff --git a/init/initramfs.c b/init/initramfs.c
65355index 84c6bf1..8899338 100644
65356--- a/init/initramfs.c
65357+++ b/init/initramfs.c
65358@@ -84,7 +84,7 @@ static void __init free_hash(void)
65359 }
65360 }
65361
65362-static long __init do_utime(char *filename, time_t mtime)
65363+static long __init do_utime(char __force_user *filename, time_t mtime)
65364 {
65365 struct timespec t[2];
65366
65367@@ -119,7 +119,7 @@ static void __init dir_utime(void)
65368 struct dir_entry *de, *tmp;
65369 list_for_each_entry_safe(de, tmp, &dir_list, list) {
65370 list_del(&de->list);
65371- do_utime(de->name, de->mtime);
65372+ do_utime((char __force_user *)de->name, de->mtime);
65373 kfree(de->name);
65374 kfree(de);
65375 }
65376@@ -281,7 +281,7 @@ static int __init maybe_link(void)
65377 if (nlink >= 2) {
65378 char *old = find_link(major, minor, ino, mode, collected);
65379 if (old)
65380- return (sys_link(old, collected) < 0) ? -1 : 1;
65381+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
65382 }
65383 return 0;
65384 }
65385@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
65386 {
65387 struct stat st;
65388
65389- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
65390+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
65391 if (S_ISDIR(st.st_mode))
65392- sys_rmdir(path);
65393+ sys_rmdir((char __force_user *)path);
65394 else
65395- sys_unlink(path);
65396+ sys_unlink((char __force_user *)path);
65397 }
65398 }
65399
65400@@ -315,7 +315,7 @@ static int __init do_name(void)
65401 int openflags = O_WRONLY|O_CREAT;
65402 if (ml != 1)
65403 openflags |= O_TRUNC;
65404- wfd = sys_open(collected, openflags, mode);
65405+ wfd = sys_open((char __force_user *)collected, openflags, mode);
65406
65407 if (wfd >= 0) {
65408 sys_fchown(wfd, uid, gid);
65409@@ -327,17 +327,17 @@ static int __init do_name(void)
65410 }
65411 }
65412 } else if (S_ISDIR(mode)) {
65413- sys_mkdir(collected, mode);
65414- sys_chown(collected, uid, gid);
65415- sys_chmod(collected, mode);
65416+ sys_mkdir((char __force_user *)collected, mode);
65417+ sys_chown((char __force_user *)collected, uid, gid);
65418+ sys_chmod((char __force_user *)collected, mode);
65419 dir_add(collected, mtime);
65420 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
65421 S_ISFIFO(mode) || S_ISSOCK(mode)) {
65422 if (maybe_link() == 0) {
65423- sys_mknod(collected, mode, rdev);
65424- sys_chown(collected, uid, gid);
65425- sys_chmod(collected, mode);
65426- do_utime(collected, mtime);
65427+ sys_mknod((char __force_user *)collected, mode, rdev);
65428+ sys_chown((char __force_user *)collected, uid, gid);
65429+ sys_chmod((char __force_user *)collected, mode);
65430+ do_utime((char __force_user *)collected, mtime);
65431 }
65432 }
65433 return 0;
65434@@ -346,15 +346,15 @@ static int __init do_name(void)
65435 static int __init do_copy(void)
65436 {
65437 if (count >= body_len) {
65438- sys_write(wfd, victim, body_len);
65439+ sys_write(wfd, (char __force_user *)victim, body_len);
65440 sys_close(wfd);
65441- do_utime(vcollected, mtime);
65442+ do_utime((char __force_user *)vcollected, mtime);
65443 kfree(vcollected);
65444 eat(body_len);
65445 state = SkipIt;
65446 return 0;
65447 } else {
65448- sys_write(wfd, victim, count);
65449+ sys_write(wfd, (char __force_user *)victim, count);
65450 body_len -= count;
65451 eat(count);
65452 return 1;
65453@@ -365,9 +365,9 @@ static int __init do_symlink(void)
65454 {
65455 collected[N_ALIGN(name_len) + body_len] = '\0';
65456 clean_path(collected, 0);
65457- sys_symlink(collected + N_ALIGN(name_len), collected);
65458- sys_lchown(collected, uid, gid);
65459- do_utime(collected, mtime);
65460+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
65461+ sys_lchown((char __force_user *)collected, uid, gid);
65462+ do_utime((char __force_user *)collected, mtime);
65463 state = SkipIt;
65464 next_state = Reset;
65465 return 0;
65466diff --git a/init/main.c b/init/main.c
65467index b5cc0a7..5605c91 100644
65468--- a/init/main.c
65469+++ b/init/main.c
65470@@ -95,6 +95,8 @@ static inline void mark_rodata_ro(void) { }
65471 extern void tc_init(void);
65472 #endif
65473
65474+extern void grsecurity_init(void);
65475+
65476 /*
65477 * Debug helper: via this flag we know that we are in 'early bootup code'
65478 * where only the boot processor is running with IRQ disabled. This means
65479@@ -148,6 +150,49 @@ static int __init set_reset_devices(char *str)
65480
65481 __setup("reset_devices", set_reset_devices);
65482
65483+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
65484+extern char pax_enter_kernel_user[];
65485+extern char pax_exit_kernel_user[];
65486+extern pgdval_t clone_pgd_mask;
65487+#endif
65488+
65489+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
65490+static int __init setup_pax_nouderef(char *str)
65491+{
65492+#ifdef CONFIG_X86_32
65493+ unsigned int cpu;
65494+ struct desc_struct *gdt;
65495+
65496+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
65497+ gdt = get_cpu_gdt_table(cpu);
65498+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
65499+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
65500+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
65501+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
65502+ }
65503+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
65504+#else
65505+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
65506+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
65507+ clone_pgd_mask = ~(pgdval_t)0UL;
65508+#endif
65509+
65510+ return 0;
65511+}
65512+early_param("pax_nouderef", setup_pax_nouderef);
65513+#endif
65514+
65515+#ifdef CONFIG_PAX_SOFTMODE
65516+int pax_softmode;
65517+
65518+static int __init setup_pax_softmode(char *str)
65519+{
65520+ get_option(&str, &pax_softmode);
65521+ return 1;
65522+}
65523+__setup("pax_softmode=", setup_pax_softmode);
65524+#endif
65525+
65526 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
65527 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
65528 static const char *panic_later, *panic_param;
65529@@ -674,6 +719,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
65530 {
65531 int count = preempt_count();
65532 int ret;
65533+ const char *msg1 = "", *msg2 = "";
65534
65535 if (initcall_debug)
65536 ret = do_one_initcall_debug(fn);
65537@@ -686,15 +732,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
65538 sprintf(msgbuf, "error code %d ", ret);
65539
65540 if (preempt_count() != count) {
65541- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
65542+ msg1 = " preemption imbalance";
65543 preempt_count() = count;
65544 }
65545 if (irqs_disabled()) {
65546- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
65547+ msg2 = " disabled interrupts";
65548 local_irq_enable();
65549 }
65550- if (msgbuf[0]) {
65551- printk("initcall %pF returned with %s\n", fn, msgbuf);
65552+ if (msgbuf[0] || *msg1 || *msg2) {
65553+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
65554 }
65555
65556 return ret;
65557@@ -747,8 +793,14 @@ static void __init do_initcall_level(int level)
65558 level, level,
65559 &repair_env_string);
65560
65561- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
65562+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
65563 do_one_initcall(*fn);
65564+
65565+#ifdef CONFIG_PAX_LATENT_ENTROPY
65566+ transfer_latent_entropy();
65567+#endif
65568+
65569+ }
65570 }
65571
65572 static void __init do_initcalls(void)
65573@@ -782,8 +834,14 @@ static void __init do_pre_smp_initcalls(void)
65574 {
65575 initcall_t *fn;
65576
65577- for (fn = __initcall_start; fn < __initcall0_start; fn++)
65578+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
65579 do_one_initcall(*fn);
65580+
65581+#ifdef CONFIG_PAX_LATENT_ENTROPY
65582+ transfer_latent_entropy();
65583+#endif
65584+
65585+ }
65586 }
65587
65588 static void run_init_process(const char *init_filename)
65589@@ -865,7 +923,7 @@ static int __init kernel_init(void * unused)
65590 do_basic_setup();
65591
65592 /* Open the /dev/console on the rootfs, this should never fail */
65593- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
65594+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
65595 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
65596
65597 (void) sys_dup(0);
65598@@ -878,11 +936,13 @@ static int __init kernel_init(void * unused)
65599 if (!ramdisk_execute_command)
65600 ramdisk_execute_command = "/init";
65601
65602- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
65603+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
65604 ramdisk_execute_command = NULL;
65605 prepare_namespace();
65606 }
65607
65608+ grsecurity_init();
65609+
65610 /*
65611 * Ok, we have completed the initial bootup, and
65612 * we're essentially up and running. Get rid of the
65613diff --git a/ipc/mqueue.c b/ipc/mqueue.c
65614index 8ce5769..4666884 100644
65615--- a/ipc/mqueue.c
65616+++ b/ipc/mqueue.c
65617@@ -279,6 +279,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
65618 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
65619 info->attr.mq_msgsize);
65620
65621+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
65622 spin_lock(&mq_lock);
65623 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
65624 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
65625diff --git a/ipc/msg.c b/ipc/msg.c
65626index 7385de2..a8180e08 100644
65627--- a/ipc/msg.c
65628+++ b/ipc/msg.c
65629@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
65630 return security_msg_queue_associate(msq, msgflg);
65631 }
65632
65633+static struct ipc_ops msg_ops = {
65634+ .getnew = newque,
65635+ .associate = msg_security,
65636+ .more_checks = NULL
65637+};
65638+
65639 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
65640 {
65641 struct ipc_namespace *ns;
65642- struct ipc_ops msg_ops;
65643 struct ipc_params msg_params;
65644
65645 ns = current->nsproxy->ipc_ns;
65646
65647- msg_ops.getnew = newque;
65648- msg_ops.associate = msg_security;
65649- msg_ops.more_checks = NULL;
65650-
65651 msg_params.key = key;
65652 msg_params.flg = msgflg;
65653
65654diff --git a/ipc/sem.c b/ipc/sem.c
65655index 5215a81..cfc0cac 100644
65656--- a/ipc/sem.c
65657+++ b/ipc/sem.c
65658@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
65659 return 0;
65660 }
65661
65662+static struct ipc_ops sem_ops = {
65663+ .getnew = newary,
65664+ .associate = sem_security,
65665+ .more_checks = sem_more_checks
65666+};
65667+
65668 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65669 {
65670 struct ipc_namespace *ns;
65671- struct ipc_ops sem_ops;
65672 struct ipc_params sem_params;
65673
65674 ns = current->nsproxy->ipc_ns;
65675@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65676 if (nsems < 0 || nsems > ns->sc_semmsl)
65677 return -EINVAL;
65678
65679- sem_ops.getnew = newary;
65680- sem_ops.associate = sem_security;
65681- sem_ops.more_checks = sem_more_checks;
65682-
65683 sem_params.key = key;
65684 sem_params.flg = semflg;
65685 sem_params.u.nsems = nsems;
65686diff --git a/ipc/shm.c b/ipc/shm.c
65687index 41c1285..cf6404c 100644
65688--- a/ipc/shm.c
65689+++ b/ipc/shm.c
65690@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
65691 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
65692 #endif
65693
65694+#ifdef CONFIG_GRKERNSEC
65695+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65696+ const time_t shm_createtime, const uid_t cuid,
65697+ const int shmid);
65698+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65699+ const time_t shm_createtime);
65700+#endif
65701+
65702 void shm_init_ns(struct ipc_namespace *ns)
65703 {
65704 ns->shm_ctlmax = SHMMAX;
65705@@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
65706 shp->shm_lprid = 0;
65707 shp->shm_atim = shp->shm_dtim = 0;
65708 shp->shm_ctim = get_seconds();
65709+#ifdef CONFIG_GRKERNSEC
65710+ {
65711+ struct timespec timeval;
65712+ do_posix_clock_monotonic_gettime(&timeval);
65713+
65714+ shp->shm_createtime = timeval.tv_sec;
65715+ }
65716+#endif
65717 shp->shm_segsz = size;
65718 shp->shm_nattch = 0;
65719 shp->shm_file = file;
65720@@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
65721 return 0;
65722 }
65723
65724+static struct ipc_ops shm_ops = {
65725+ .getnew = newseg,
65726+ .associate = shm_security,
65727+ .more_checks = shm_more_checks
65728+};
65729+
65730 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
65731 {
65732 struct ipc_namespace *ns;
65733- struct ipc_ops shm_ops;
65734 struct ipc_params shm_params;
65735
65736 ns = current->nsproxy->ipc_ns;
65737
65738- shm_ops.getnew = newseg;
65739- shm_ops.associate = shm_security;
65740- shm_ops.more_checks = shm_more_checks;
65741-
65742 shm_params.key = key;
65743 shm_params.flg = shmflg;
65744 shm_params.u.size = size;
65745@@ -1000,6 +1017,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65746 f_mode = FMODE_READ | FMODE_WRITE;
65747 }
65748 if (shmflg & SHM_EXEC) {
65749+
65750+#ifdef CONFIG_PAX_MPROTECT
65751+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
65752+ goto out;
65753+#endif
65754+
65755 prot |= PROT_EXEC;
65756 acc_mode |= S_IXUGO;
65757 }
65758@@ -1023,9 +1046,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65759 if (err)
65760 goto out_unlock;
65761
65762+#ifdef CONFIG_GRKERNSEC
65763+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
65764+ shp->shm_perm.cuid, shmid) ||
65765+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
65766+ err = -EACCES;
65767+ goto out_unlock;
65768+ }
65769+#endif
65770+
65771 path = shp->shm_file->f_path;
65772 path_get(&path);
65773 shp->shm_nattch++;
65774+#ifdef CONFIG_GRKERNSEC
65775+ shp->shm_lapid = current->pid;
65776+#endif
65777 size = i_size_read(path.dentry->d_inode);
65778 shm_unlock(shp);
65779
65780diff --git a/kernel/acct.c b/kernel/acct.c
65781index 02e6167..54824f7 100644
65782--- a/kernel/acct.c
65783+++ b/kernel/acct.c
65784@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
65785 */
65786 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
65787 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
65788- file->f_op->write(file, (char *)&ac,
65789+ file->f_op->write(file, (char __force_user *)&ac,
65790 sizeof(acct_t), &file->f_pos);
65791 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
65792 set_fs(fs);
65793diff --git a/kernel/audit.c b/kernel/audit.c
65794index 1c7f2c6..9ba5359 100644
65795--- a/kernel/audit.c
65796+++ b/kernel/audit.c
65797@@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
65798 3) suppressed due to audit_rate_limit
65799 4) suppressed due to audit_backlog_limit
65800 */
65801-static atomic_t audit_lost = ATOMIC_INIT(0);
65802+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
65803
65804 /* The netlink socket. */
65805 static struct sock *audit_sock;
65806@@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
65807 unsigned long now;
65808 int print;
65809
65810- atomic_inc(&audit_lost);
65811+ atomic_inc_unchecked(&audit_lost);
65812
65813 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
65814
65815@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
65816 printk(KERN_WARNING
65817 "audit: audit_lost=%d audit_rate_limit=%d "
65818 "audit_backlog_limit=%d\n",
65819- atomic_read(&audit_lost),
65820+ atomic_read_unchecked(&audit_lost),
65821 audit_rate_limit,
65822 audit_backlog_limit);
65823 audit_panic(message);
65824@@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
65825 status_set.pid = audit_pid;
65826 status_set.rate_limit = audit_rate_limit;
65827 status_set.backlog_limit = audit_backlog_limit;
65828- status_set.lost = atomic_read(&audit_lost);
65829+ status_set.lost = atomic_read_unchecked(&audit_lost);
65830 status_set.backlog = skb_queue_len(&audit_skb_queue);
65831 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
65832 &status_set, sizeof(status_set));
65833diff --git a/kernel/auditsc.c b/kernel/auditsc.c
65834index 4b96415..d8c16ee 100644
65835--- a/kernel/auditsc.c
65836+++ b/kernel/auditsc.c
65837@@ -2289,7 +2289,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
65838 }
65839
65840 /* global counter which is incremented every time something logs in */
65841-static atomic_t session_id = ATOMIC_INIT(0);
65842+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
65843
65844 /**
65845 * audit_set_loginuid - set current task's audit_context loginuid
65846@@ -2313,7 +2313,7 @@ int audit_set_loginuid(uid_t loginuid)
65847 return -EPERM;
65848 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
65849
65850- sessionid = atomic_inc_return(&session_id);
65851+ sessionid = atomic_inc_return_unchecked(&session_id);
65852 if (context && context->in_syscall) {
65853 struct audit_buffer *ab;
65854
65855diff --git a/kernel/capability.c b/kernel/capability.c
65856index 493d972..ea17248 100644
65857--- a/kernel/capability.c
65858+++ b/kernel/capability.c
65859@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
65860 * before modification is attempted and the application
65861 * fails.
65862 */
65863+ if (tocopy > ARRAY_SIZE(kdata))
65864+ return -EFAULT;
65865+
65866 if (copy_to_user(dataptr, kdata, tocopy
65867 * sizeof(struct __user_cap_data_struct))) {
65868 return -EFAULT;
65869@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
65870 int ret;
65871
65872 rcu_read_lock();
65873- ret = security_capable(__task_cred(t), ns, cap);
65874+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
65875+ gr_task_is_capable(t, __task_cred(t), cap);
65876 rcu_read_unlock();
65877
65878- return (ret == 0);
65879+ return ret;
65880 }
65881
65882 /**
65883@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
65884 int ret;
65885
65886 rcu_read_lock();
65887- ret = security_capable_noaudit(__task_cred(t), ns, cap);
65888+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
65889 rcu_read_unlock();
65890
65891- return (ret == 0);
65892+ return ret;
65893 }
65894
65895 /**
65896@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
65897 BUG();
65898 }
65899
65900- if (security_capable(current_cred(), ns, cap) == 0) {
65901+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
65902 current->flags |= PF_SUPERPRIV;
65903 return true;
65904 }
65905@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
65906 }
65907 EXPORT_SYMBOL(ns_capable);
65908
65909+bool ns_capable_nolog(struct user_namespace *ns, int cap)
65910+{
65911+ if (unlikely(!cap_valid(cap))) {
65912+ printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
65913+ BUG();
65914+ }
65915+
65916+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
65917+ current->flags |= PF_SUPERPRIV;
65918+ return true;
65919+ }
65920+ return false;
65921+}
65922+EXPORT_SYMBOL(ns_capable_nolog);
65923+
65924 /**
65925 * capable - Determine if the current task has a superior capability in effect
65926 * @cap: The capability to be tested for
65927@@ -408,6 +427,12 @@ bool capable(int cap)
65928 }
65929 EXPORT_SYMBOL(capable);
65930
65931+bool capable_nolog(int cap)
65932+{
65933+ return ns_capable_nolog(&init_user_ns, cap);
65934+}
65935+EXPORT_SYMBOL(capable_nolog);
65936+
65937 /**
65938 * nsown_capable - Check superior capability to one's own user_ns
65939 * @cap: The capability in question
65940@@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
65941
65942 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
65943 }
65944+
65945+bool inode_capable_nolog(const struct inode *inode, int cap)
65946+{
65947+ struct user_namespace *ns = current_user_ns();
65948+
65949+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
65950+}
65951diff --git a/kernel/compat.c b/kernel/compat.c
65952index c28a306..b4d0cf3 100644
65953--- a/kernel/compat.c
65954+++ b/kernel/compat.c
65955@@ -13,6 +13,7 @@
65956
65957 #include <linux/linkage.h>
65958 #include <linux/compat.h>
65959+#include <linux/module.h>
65960 #include <linux/errno.h>
65961 #include <linux/time.h>
65962 #include <linux/signal.h>
65963@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
65964 mm_segment_t oldfs;
65965 long ret;
65966
65967- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
65968+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
65969 oldfs = get_fs();
65970 set_fs(KERNEL_DS);
65971 ret = hrtimer_nanosleep_restart(restart);
65972@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
65973 oldfs = get_fs();
65974 set_fs(KERNEL_DS);
65975 ret = hrtimer_nanosleep(&tu,
65976- rmtp ? (struct timespec __user *)&rmt : NULL,
65977+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
65978 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
65979 set_fs(oldfs);
65980
65981@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
65982 mm_segment_t old_fs = get_fs();
65983
65984 set_fs(KERNEL_DS);
65985- ret = sys_sigpending((old_sigset_t __user *) &s);
65986+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
65987 set_fs(old_fs);
65988 if (ret == 0)
65989 ret = put_user(s, set);
65990@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
65991 mm_segment_t old_fs = get_fs();
65992
65993 set_fs(KERNEL_DS);
65994- ret = sys_old_getrlimit(resource, &r);
65995+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
65996 set_fs(old_fs);
65997
65998 if (!ret) {
65999@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
66000 mm_segment_t old_fs = get_fs();
66001
66002 set_fs(KERNEL_DS);
66003- ret = sys_getrusage(who, (struct rusage __user *) &r);
66004+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
66005 set_fs(old_fs);
66006
66007 if (ret)
66008@@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
66009 set_fs (KERNEL_DS);
66010 ret = sys_wait4(pid,
66011 (stat_addr ?
66012- (unsigned int __user *) &status : NULL),
66013- options, (struct rusage __user *) &r);
66014+ (unsigned int __force_user *) &status : NULL),
66015+ options, (struct rusage __force_user *) &r);
66016 set_fs (old_fs);
66017
66018 if (ret > 0) {
66019@@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
66020 memset(&info, 0, sizeof(info));
66021
66022 set_fs(KERNEL_DS);
66023- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
66024- uru ? (struct rusage __user *)&ru : NULL);
66025+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
66026+ uru ? (struct rusage __force_user *)&ru : NULL);
66027 set_fs(old_fs);
66028
66029 if ((ret < 0) || (info.si_signo == 0))
66030@@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
66031 oldfs = get_fs();
66032 set_fs(KERNEL_DS);
66033 err = sys_timer_settime(timer_id, flags,
66034- (struct itimerspec __user *) &newts,
66035- (struct itimerspec __user *) &oldts);
66036+ (struct itimerspec __force_user *) &newts,
66037+ (struct itimerspec __force_user *) &oldts);
66038 set_fs(oldfs);
66039 if (!err && old && put_compat_itimerspec(old, &oldts))
66040 return -EFAULT;
66041@@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
66042 oldfs = get_fs();
66043 set_fs(KERNEL_DS);
66044 err = sys_timer_gettime(timer_id,
66045- (struct itimerspec __user *) &ts);
66046+ (struct itimerspec __force_user *) &ts);
66047 set_fs(oldfs);
66048 if (!err && put_compat_itimerspec(setting, &ts))
66049 return -EFAULT;
66050@@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
66051 oldfs = get_fs();
66052 set_fs(KERNEL_DS);
66053 err = sys_clock_settime(which_clock,
66054- (struct timespec __user *) &ts);
66055+ (struct timespec __force_user *) &ts);
66056 set_fs(oldfs);
66057 return err;
66058 }
66059@@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
66060 oldfs = get_fs();
66061 set_fs(KERNEL_DS);
66062 err = sys_clock_gettime(which_clock,
66063- (struct timespec __user *) &ts);
66064+ (struct timespec __force_user *) &ts);
66065 set_fs(oldfs);
66066 if (!err && put_compat_timespec(&ts, tp))
66067 return -EFAULT;
66068@@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
66069
66070 oldfs = get_fs();
66071 set_fs(KERNEL_DS);
66072- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
66073+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
66074 set_fs(oldfs);
66075
66076 err = compat_put_timex(utp, &txc);
66077@@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
66078 oldfs = get_fs();
66079 set_fs(KERNEL_DS);
66080 err = sys_clock_getres(which_clock,
66081- (struct timespec __user *) &ts);
66082+ (struct timespec __force_user *) &ts);
66083 set_fs(oldfs);
66084 if (!err && tp && put_compat_timespec(&ts, tp))
66085 return -EFAULT;
66086@@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
66087 long err;
66088 mm_segment_t oldfs;
66089 struct timespec tu;
66090- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
66091+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
66092
66093- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
66094+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
66095 oldfs = get_fs();
66096 set_fs(KERNEL_DS);
66097 err = clock_nanosleep_restart(restart);
66098@@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
66099 oldfs = get_fs();
66100 set_fs(KERNEL_DS);
66101 err = sys_clock_nanosleep(which_clock, flags,
66102- (struct timespec __user *) &in,
66103- (struct timespec __user *) &out);
66104+ (struct timespec __force_user *) &in,
66105+ (struct timespec __force_user *) &out);
66106 set_fs(oldfs);
66107
66108 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
66109diff --git a/kernel/configs.c b/kernel/configs.c
66110index 42e8fa0..9e7406b 100644
66111--- a/kernel/configs.c
66112+++ b/kernel/configs.c
66113@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
66114 struct proc_dir_entry *entry;
66115
66116 /* create the current config file */
66117+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66118+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
66119+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
66120+ &ikconfig_file_ops);
66121+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66122+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
66123+ &ikconfig_file_ops);
66124+#endif
66125+#else
66126 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
66127 &ikconfig_file_ops);
66128+#endif
66129+
66130 if (!entry)
66131 return -ENOMEM;
66132
66133diff --git a/kernel/cred.c b/kernel/cred.c
66134index de728ac..e3c267c 100644
66135--- a/kernel/cred.c
66136+++ b/kernel/cred.c
66137@@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
66138 validate_creds(cred);
66139 alter_cred_subscribers(cred, -1);
66140 put_cred(cred);
66141+
66142+#ifdef CONFIG_GRKERNSEC_SETXID
66143+ cred = (struct cred *) tsk->delayed_cred;
66144+ if (cred != NULL) {
66145+ tsk->delayed_cred = NULL;
66146+ validate_creds(cred);
66147+ alter_cred_subscribers(cred, -1);
66148+ put_cred(cred);
66149+ }
66150+#endif
66151 }
66152
66153 /**
66154@@ -469,7 +479,7 @@ error_put:
66155 * Always returns 0 thus allowing this function to be tail-called at the end
66156 * of, say, sys_setgid().
66157 */
66158-int commit_creds(struct cred *new)
66159+static int __commit_creds(struct cred *new)
66160 {
66161 struct task_struct *task = current;
66162 const struct cred *old = task->real_cred;
66163@@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
66164
66165 get_cred(new); /* we will require a ref for the subj creds too */
66166
66167+ gr_set_role_label(task, new->uid, new->gid);
66168+
66169 /* dumpability changes */
66170 if (!uid_eq(old->euid, new->euid) ||
66171 !gid_eq(old->egid, new->egid) ||
66172@@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
66173 put_cred(old);
66174 return 0;
66175 }
66176+#ifdef CONFIG_GRKERNSEC_SETXID
66177+extern int set_user(struct cred *new);
66178+
66179+void gr_delayed_cred_worker(void)
66180+{
66181+ const struct cred *new = current->delayed_cred;
66182+ struct cred *ncred;
66183+
66184+ current->delayed_cred = NULL;
66185+
66186+ if (current_uid() && new != NULL) {
66187+ // from doing get_cred on it when queueing this
66188+ put_cred(new);
66189+ return;
66190+ } else if (new == NULL)
66191+ return;
66192+
66193+ ncred = prepare_creds();
66194+ if (!ncred)
66195+ goto die;
66196+ // uids
66197+ ncred->uid = new->uid;
66198+ ncred->euid = new->euid;
66199+ ncred->suid = new->suid;
66200+ ncred->fsuid = new->fsuid;
66201+ // gids
66202+ ncred->gid = new->gid;
66203+ ncred->egid = new->egid;
66204+ ncred->sgid = new->sgid;
66205+ ncred->fsgid = new->fsgid;
66206+ // groups
66207+ if (set_groups(ncred, new->group_info) < 0) {
66208+ abort_creds(ncred);
66209+ goto die;
66210+ }
66211+ // caps
66212+ ncred->securebits = new->securebits;
66213+ ncred->cap_inheritable = new->cap_inheritable;
66214+ ncred->cap_permitted = new->cap_permitted;
66215+ ncred->cap_effective = new->cap_effective;
66216+ ncred->cap_bset = new->cap_bset;
66217+
66218+ if (set_user(ncred)) {
66219+ abort_creds(ncred);
66220+ goto die;
66221+ }
66222+
66223+ // from doing get_cred on it when queueing this
66224+ put_cred(new);
66225+
66226+ __commit_creds(ncred);
66227+ return;
66228+die:
66229+ // from doing get_cred on it when queueing this
66230+ put_cred(new);
66231+ do_group_exit(SIGKILL);
66232+}
66233+#endif
66234+
66235+int commit_creds(struct cred *new)
66236+{
66237+#ifdef CONFIG_GRKERNSEC_SETXID
66238+ int ret;
66239+ int schedule_it = 0;
66240+ struct task_struct *t;
66241+
66242+ /* we won't get called with tasklist_lock held for writing
66243+ and interrupts disabled as the cred struct in that case is
66244+ init_cred
66245+ */
66246+ if (grsec_enable_setxid && !current_is_single_threaded() &&
66247+ !current_uid() && new->uid) {
66248+ schedule_it = 1;
66249+ }
66250+ ret = __commit_creds(new);
66251+ if (schedule_it) {
66252+ rcu_read_lock();
66253+ read_lock(&tasklist_lock);
66254+ for (t = next_thread(current); t != current;
66255+ t = next_thread(t)) {
66256+ if (t->delayed_cred == NULL) {
66257+ t->delayed_cred = get_cred(new);
66258+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
66259+ set_tsk_need_resched(t);
66260+ }
66261+ }
66262+ read_unlock(&tasklist_lock);
66263+ rcu_read_unlock();
66264+ }
66265+ return ret;
66266+#else
66267+ return __commit_creds(new);
66268+#endif
66269+}
66270+
66271 EXPORT_SYMBOL(commit_creds);
66272
66273 /**
66274diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
66275index 0557f24..1a00d9a 100644
66276--- a/kernel/debug/debug_core.c
66277+++ b/kernel/debug/debug_core.c
66278@@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
66279 */
66280 static atomic_t masters_in_kgdb;
66281 static atomic_t slaves_in_kgdb;
66282-static atomic_t kgdb_break_tasklet_var;
66283+static atomic_unchecked_t kgdb_break_tasklet_var;
66284 atomic_t kgdb_setting_breakpoint;
66285
66286 struct task_struct *kgdb_usethread;
66287@@ -132,7 +132,7 @@ int kgdb_single_step;
66288 static pid_t kgdb_sstep_pid;
66289
66290 /* to keep track of the CPU which is doing the single stepping*/
66291-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66292+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66293
66294 /*
66295 * If you are debugging a problem where roundup (the collection of
66296@@ -540,7 +540,7 @@ return_normal:
66297 * kernel will only try for the value of sstep_tries before
66298 * giving up and continuing on.
66299 */
66300- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
66301+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
66302 (kgdb_info[cpu].task &&
66303 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
66304 atomic_set(&kgdb_active, -1);
66305@@ -634,8 +634,8 @@ cpu_master_loop:
66306 }
66307
66308 kgdb_restore:
66309- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
66310- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
66311+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
66312+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
66313 if (kgdb_info[sstep_cpu].task)
66314 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
66315 else
66316@@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
66317 static void kgdb_tasklet_bpt(unsigned long ing)
66318 {
66319 kgdb_breakpoint();
66320- atomic_set(&kgdb_break_tasklet_var, 0);
66321+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
66322 }
66323
66324 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
66325
66326 void kgdb_schedule_breakpoint(void)
66327 {
66328- if (atomic_read(&kgdb_break_tasklet_var) ||
66329+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
66330 atomic_read(&kgdb_active) != -1 ||
66331 atomic_read(&kgdb_setting_breakpoint))
66332 return;
66333- atomic_inc(&kgdb_break_tasklet_var);
66334+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
66335 tasklet_schedule(&kgdb_tasklet_breakpoint);
66336 }
66337 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
66338diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
66339index 1f91413..362a0a1 100644
66340--- a/kernel/debug/kdb/kdb_main.c
66341+++ b/kernel/debug/kdb/kdb_main.c
66342@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
66343 list_for_each_entry(mod, kdb_modules, list) {
66344
66345 kdb_printf("%-20s%8u 0x%p ", mod->name,
66346- mod->core_size, (void *)mod);
66347+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
66348 #ifdef CONFIG_MODULE_UNLOAD
66349 kdb_printf("%4ld ", module_refcount(mod));
66350 #endif
66351@@ -1994,7 +1994,7 @@ static int kdb_lsmod(int argc, const char **argv)
66352 kdb_printf(" (Loading)");
66353 else
66354 kdb_printf(" (Live)");
66355- kdb_printf(" 0x%p", mod->module_core);
66356+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
66357
66358 #ifdef CONFIG_MODULE_UNLOAD
66359 {
66360diff --git a/kernel/events/core.c b/kernel/events/core.c
66361index d7d71d6..f54b76f 100644
66362--- a/kernel/events/core.c
66363+++ b/kernel/events/core.c
66364@@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
66365 return 0;
66366 }
66367
66368-static atomic64_t perf_event_id;
66369+static atomic64_unchecked_t perf_event_id;
66370
66371 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
66372 enum event_type_t event_type);
66373@@ -2663,7 +2663,7 @@ static void __perf_event_read(void *info)
66374
66375 static inline u64 perf_event_count(struct perf_event *event)
66376 {
66377- return local64_read(&event->count) + atomic64_read(&event->child_count);
66378+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
66379 }
66380
66381 static u64 perf_event_read(struct perf_event *event)
66382@@ -2987,9 +2987,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
66383 mutex_lock(&event->child_mutex);
66384 total += perf_event_read(event);
66385 *enabled += event->total_time_enabled +
66386- atomic64_read(&event->child_total_time_enabled);
66387+ atomic64_read_unchecked(&event->child_total_time_enabled);
66388 *running += event->total_time_running +
66389- atomic64_read(&event->child_total_time_running);
66390+ atomic64_read_unchecked(&event->child_total_time_running);
66391
66392 list_for_each_entry(child, &event->child_list, child_list) {
66393 total += perf_event_read(child);
66394@@ -3396,10 +3396,10 @@ void perf_event_update_userpage(struct perf_event *event)
66395 userpg->offset -= local64_read(&event->hw.prev_count);
66396
66397 userpg->time_enabled = enabled +
66398- atomic64_read(&event->child_total_time_enabled);
66399+ atomic64_read_unchecked(&event->child_total_time_enabled);
66400
66401 userpg->time_running = running +
66402- atomic64_read(&event->child_total_time_running);
66403+ atomic64_read_unchecked(&event->child_total_time_running);
66404
66405 arch_perf_update_userpage(userpg, now);
66406
66407@@ -3832,11 +3832,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
66408 values[n++] = perf_event_count(event);
66409 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
66410 values[n++] = enabled +
66411- atomic64_read(&event->child_total_time_enabled);
66412+ atomic64_read_unchecked(&event->child_total_time_enabled);
66413 }
66414 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
66415 values[n++] = running +
66416- atomic64_read(&event->child_total_time_running);
66417+ atomic64_read_unchecked(&event->child_total_time_running);
66418 }
66419 if (read_format & PERF_FORMAT_ID)
66420 values[n++] = primary_event_id(event);
66421@@ -4514,12 +4514,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
66422 * need to add enough zero bytes after the string to handle
66423 * the 64bit alignment we do later.
66424 */
66425- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
66426+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
66427 if (!buf) {
66428 name = strncpy(tmp, "//enomem", sizeof(tmp));
66429 goto got_name;
66430 }
66431- name = d_path(&file->f_path, buf, PATH_MAX);
66432+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
66433 if (IS_ERR(name)) {
66434 name = strncpy(tmp, "//toolong", sizeof(tmp));
66435 goto got_name;
66436@@ -5931,7 +5931,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
66437 event->parent = parent_event;
66438
66439 event->ns = get_pid_ns(current->nsproxy->pid_ns);
66440- event->id = atomic64_inc_return(&perf_event_id);
66441+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
66442
66443 event->state = PERF_EVENT_STATE_INACTIVE;
66444
66445@@ -6493,10 +6493,10 @@ static void sync_child_event(struct perf_event *child_event,
66446 /*
66447 * Add back the child's count to the parent's count:
66448 */
66449- atomic64_add(child_val, &parent_event->child_count);
66450- atomic64_add(child_event->total_time_enabled,
66451+ atomic64_add_unchecked(child_val, &parent_event->child_count);
66452+ atomic64_add_unchecked(child_event->total_time_enabled,
66453 &parent_event->child_total_time_enabled);
66454- atomic64_add(child_event->total_time_running,
66455+ atomic64_add_unchecked(child_event->total_time_running,
66456 &parent_event->child_total_time_running);
66457
66458 /*
66459diff --git a/kernel/exit.c b/kernel/exit.c
66460index 46ce8da..c648f3a 100644
66461--- a/kernel/exit.c
66462+++ b/kernel/exit.c
66463@@ -59,6 +59,10 @@
66464 #include <asm/pgtable.h>
66465 #include <asm/mmu_context.h>
66466
66467+#ifdef CONFIG_GRKERNSEC
66468+extern rwlock_t grsec_exec_file_lock;
66469+#endif
66470+
66471 static void exit_mm(struct task_struct * tsk);
66472
66473 static void __unhash_process(struct task_struct *p, bool group_dead)
66474@@ -182,6 +186,10 @@ void release_task(struct task_struct * p)
66475 struct task_struct *leader;
66476 int zap_leader;
66477 repeat:
66478+#ifdef CONFIG_NET
66479+ gr_del_task_from_ip_table(p);
66480+#endif
66481+
66482 /* don't need to get the RCU readlock here - the process is dead and
66483 * can't be modifying its own credentials. But shut RCU-lockdep up */
66484 rcu_read_lock();
66485@@ -394,7 +402,7 @@ int allow_signal(int sig)
66486 * know it'll be handled, so that they don't get converted to
66487 * SIGKILL or just silently dropped.
66488 */
66489- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
66490+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
66491 recalc_sigpending();
66492 spin_unlock_irq(&current->sighand->siglock);
66493 return 0;
66494@@ -430,6 +438,17 @@ void daemonize(const char *name, ...)
66495 vsnprintf(current->comm, sizeof(current->comm), name, args);
66496 va_end(args);
66497
66498+#ifdef CONFIG_GRKERNSEC
66499+ write_lock(&grsec_exec_file_lock);
66500+ if (current->exec_file) {
66501+ fput(current->exec_file);
66502+ current->exec_file = NULL;
66503+ }
66504+ write_unlock(&grsec_exec_file_lock);
66505+#endif
66506+
66507+ gr_set_kernel_label(current);
66508+
66509 /*
66510 * If we were started as result of loading a module, close all of the
66511 * user space pages. We don't need them, and if we didn't close them
66512@@ -907,6 +926,8 @@ void do_exit(long code)
66513 struct task_struct *tsk = current;
66514 int group_dead;
66515
66516+ set_fs(USER_DS);
66517+
66518 profile_task_exit(tsk);
66519
66520 WARN_ON(blk_needs_flush_plug(tsk));
66521@@ -923,7 +944,6 @@ void do_exit(long code)
66522 * mm_release()->clear_child_tid() from writing to a user-controlled
66523 * kernel address.
66524 */
66525- set_fs(USER_DS);
66526
66527 ptrace_event(PTRACE_EVENT_EXIT, code);
66528
66529@@ -985,6 +1005,9 @@ void do_exit(long code)
66530 tsk->exit_code = code;
66531 taskstats_exit(tsk, group_dead);
66532
66533+ gr_acl_handle_psacct(tsk, code);
66534+ gr_acl_handle_exit();
66535+
66536 exit_mm(tsk);
66537
66538 if (group_dead)
66539@@ -1101,7 +1124,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
66540 * Take down every thread in the group. This is called by fatal signals
66541 * as well as by sys_exit_group (below).
66542 */
66543-void
66544+__noreturn void
66545 do_group_exit(int exit_code)
66546 {
66547 struct signal_struct *sig = current->signal;
66548diff --git a/kernel/fork.c b/kernel/fork.c
66549index f00e319..c212fbc 100644
66550--- a/kernel/fork.c
66551+++ b/kernel/fork.c
66552@@ -321,7 +321,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
66553 *stackend = STACK_END_MAGIC; /* for overflow detection */
66554
66555 #ifdef CONFIG_CC_STACKPROTECTOR
66556- tsk->stack_canary = get_random_int();
66557+ tsk->stack_canary = pax_get_random_long();
66558 #endif
66559
66560 /*
66561@@ -345,13 +345,78 @@ out:
66562 }
66563
66564 #ifdef CONFIG_MMU
66565+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
66566+{
66567+ struct vm_area_struct *tmp;
66568+ unsigned long charge;
66569+ struct mempolicy *pol;
66570+ struct file *file;
66571+
66572+ charge = 0;
66573+ if (mpnt->vm_flags & VM_ACCOUNT) {
66574+ unsigned long len;
66575+ len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66576+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
66577+ goto fail_nomem;
66578+ charge = len;
66579+ }
66580+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66581+ if (!tmp)
66582+ goto fail_nomem;
66583+ *tmp = *mpnt;
66584+ tmp->vm_mm = mm;
66585+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
66586+ pol = mpol_dup(vma_policy(mpnt));
66587+ if (IS_ERR(pol))
66588+ goto fail_nomem_policy;
66589+ vma_set_policy(tmp, pol);
66590+ if (anon_vma_fork(tmp, mpnt))
66591+ goto fail_nomem_anon_vma_fork;
66592+ tmp->vm_flags &= ~VM_LOCKED;
66593+ tmp->vm_next = tmp->vm_prev = NULL;
66594+ tmp->vm_mirror = NULL;
66595+ file = tmp->vm_file;
66596+ if (file) {
66597+ struct inode *inode = file->f_path.dentry->d_inode;
66598+ struct address_space *mapping = file->f_mapping;
66599+
66600+ get_file(file);
66601+ if (tmp->vm_flags & VM_DENYWRITE)
66602+ atomic_dec(&inode->i_writecount);
66603+ mutex_lock(&mapping->i_mmap_mutex);
66604+ if (tmp->vm_flags & VM_SHARED)
66605+ mapping->i_mmap_writable++;
66606+ flush_dcache_mmap_lock(mapping);
66607+ /* insert tmp into the share list, just after mpnt */
66608+ vma_prio_tree_add(tmp, mpnt);
66609+ flush_dcache_mmap_unlock(mapping);
66610+ mutex_unlock(&mapping->i_mmap_mutex);
66611+ }
66612+
66613+ /*
66614+ * Clear hugetlb-related page reserves for children. This only
66615+ * affects MAP_PRIVATE mappings. Faults generated by the child
66616+ * are not guaranteed to succeed, even if read-only
66617+ */
66618+ if (is_vm_hugetlb_page(tmp))
66619+ reset_vma_resv_huge_pages(tmp);
66620+
66621+ return tmp;
66622+
66623+fail_nomem_anon_vma_fork:
66624+ mpol_put(pol);
66625+fail_nomem_policy:
66626+ kmem_cache_free(vm_area_cachep, tmp);
66627+fail_nomem:
66628+ vm_unacct_memory(charge);
66629+ return NULL;
66630+}
66631+
66632 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66633 {
66634 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
66635 struct rb_node **rb_link, *rb_parent;
66636 int retval;
66637- unsigned long charge;
66638- struct mempolicy *pol;
66639
66640 down_write(&oldmm->mmap_sem);
66641 flush_cache_dup_mm(oldmm);
66642@@ -363,8 +428,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66643 mm->locked_vm = 0;
66644 mm->mmap = NULL;
66645 mm->mmap_cache = NULL;
66646- mm->free_area_cache = oldmm->mmap_base;
66647- mm->cached_hole_size = ~0UL;
66648+ mm->free_area_cache = oldmm->free_area_cache;
66649+ mm->cached_hole_size = oldmm->cached_hole_size;
66650 mm->map_count = 0;
66651 cpumask_clear(mm_cpumask(mm));
66652 mm->mm_rb = RB_ROOT;
66653@@ -380,8 +445,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66654
66655 prev = NULL;
66656 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
66657- struct file *file;
66658-
66659 if (mpnt->vm_flags & VM_DONTCOPY) {
66660 long pages = vma_pages(mpnt);
66661 mm->total_vm -= pages;
66662@@ -389,54 +452,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66663 -pages);
66664 continue;
66665 }
66666- charge = 0;
66667- if (mpnt->vm_flags & VM_ACCOUNT) {
66668- unsigned long len;
66669- len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66670- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
66671- goto fail_nomem;
66672- charge = len;
66673+ tmp = dup_vma(mm, oldmm, mpnt);
66674+ if (!tmp) {
66675+ retval = -ENOMEM;
66676+ goto out;
66677 }
66678- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66679- if (!tmp)
66680- goto fail_nomem;
66681- *tmp = *mpnt;
66682- INIT_LIST_HEAD(&tmp->anon_vma_chain);
66683- pol = mpol_dup(vma_policy(mpnt));
66684- retval = PTR_ERR(pol);
66685- if (IS_ERR(pol))
66686- goto fail_nomem_policy;
66687- vma_set_policy(tmp, pol);
66688- tmp->vm_mm = mm;
66689- if (anon_vma_fork(tmp, mpnt))
66690- goto fail_nomem_anon_vma_fork;
66691- tmp->vm_flags &= ~VM_LOCKED;
66692- tmp->vm_next = tmp->vm_prev = NULL;
66693- file = tmp->vm_file;
66694- if (file) {
66695- struct inode *inode = file->f_path.dentry->d_inode;
66696- struct address_space *mapping = file->f_mapping;
66697-
66698- get_file(file);
66699- if (tmp->vm_flags & VM_DENYWRITE)
66700- atomic_dec(&inode->i_writecount);
66701- mutex_lock(&mapping->i_mmap_mutex);
66702- if (tmp->vm_flags & VM_SHARED)
66703- mapping->i_mmap_writable++;
66704- flush_dcache_mmap_lock(mapping);
66705- /* insert tmp into the share list, just after mpnt */
66706- vma_prio_tree_add(tmp, mpnt);
66707- flush_dcache_mmap_unlock(mapping);
66708- mutex_unlock(&mapping->i_mmap_mutex);
66709- }
66710-
66711- /*
66712- * Clear hugetlb-related page reserves for children. This only
66713- * affects MAP_PRIVATE mappings. Faults generated by the child
66714- * are not guaranteed to succeed, even if read-only
66715- */
66716- if (is_vm_hugetlb_page(tmp))
66717- reset_vma_resv_huge_pages(tmp);
66718
66719 /*
66720 * Link in the new vma and copy the page table entries.
66721@@ -459,9 +479,34 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66722 if (retval)
66723 goto out;
66724
66725- if (file && uprobe_mmap(tmp))
66726+ if (tmp->vm_file && uprobe_mmap(tmp))
66727 goto out;
66728 }
66729+
66730+#ifdef CONFIG_PAX_SEGMEXEC
66731+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
66732+ struct vm_area_struct *mpnt_m;
66733+
66734+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
66735+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
66736+
66737+ if (!mpnt->vm_mirror)
66738+ continue;
66739+
66740+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
66741+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
66742+ mpnt->vm_mirror = mpnt_m;
66743+ } else {
66744+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
66745+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
66746+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
66747+ mpnt->vm_mirror->vm_mirror = mpnt;
66748+ }
66749+ }
66750+ BUG_ON(mpnt_m);
66751+ }
66752+#endif
66753+
66754 /* a new mm has just been created */
66755 arch_dup_mmap(oldmm, mm);
66756 retval = 0;
66757@@ -470,14 +515,6 @@ out:
66758 flush_tlb_mm(oldmm);
66759 up_write(&oldmm->mmap_sem);
66760 return retval;
66761-fail_nomem_anon_vma_fork:
66762- mpol_put(pol);
66763-fail_nomem_policy:
66764- kmem_cache_free(vm_area_cachep, tmp);
66765-fail_nomem:
66766- retval = -ENOMEM;
66767- vm_unacct_memory(charge);
66768- goto out;
66769 }
66770
66771 static inline int mm_alloc_pgd(struct mm_struct *mm)
66772@@ -714,8 +751,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
66773 return ERR_PTR(err);
66774
66775 mm = get_task_mm(task);
66776- if (mm && mm != current->mm &&
66777- !ptrace_may_access(task, mode)) {
66778+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
66779+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
66780 mmput(mm);
66781 mm = ERR_PTR(-EACCES);
66782 }
66783@@ -936,13 +973,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
66784 spin_unlock(&fs->lock);
66785 return -EAGAIN;
66786 }
66787- fs->users++;
66788+ atomic_inc(&fs->users);
66789 spin_unlock(&fs->lock);
66790 return 0;
66791 }
66792 tsk->fs = copy_fs_struct(fs);
66793 if (!tsk->fs)
66794 return -ENOMEM;
66795+ gr_set_chroot_entries(tsk, &tsk->fs->root);
66796 return 0;
66797 }
66798
66799@@ -1209,6 +1247,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66800 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
66801 #endif
66802 retval = -EAGAIN;
66803+
66804+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
66805+
66806 if (atomic_read(&p->real_cred->user->processes) >=
66807 task_rlimit(p, RLIMIT_NPROC)) {
66808 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
66809@@ -1431,6 +1472,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66810 /* Need tasklist lock for parent etc handling! */
66811 write_lock_irq(&tasklist_lock);
66812
66813+ /* synchronizes with gr_set_acls() */
66814+ gr_copy_label(p);
66815+
66816 /* CLONE_PARENT re-uses the old parent */
66817 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
66818 p->real_parent = current->real_parent;
66819@@ -1541,6 +1585,8 @@ bad_fork_cleanup_count:
66820 bad_fork_free:
66821 free_task(p);
66822 fork_out:
66823+ gr_log_forkfail(retval);
66824+
66825 return ERR_PTR(retval);
66826 }
66827
66828@@ -1641,6 +1687,8 @@ long do_fork(unsigned long clone_flags,
66829 if (clone_flags & CLONE_PARENT_SETTID)
66830 put_user(nr, parent_tidptr);
66831
66832+ gr_handle_brute_check();
66833+
66834 if (clone_flags & CLONE_VFORK) {
66835 p->vfork_done = &vfork;
66836 init_completion(&vfork);
66837@@ -1739,7 +1787,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
66838 return 0;
66839
66840 /* don't need lock here; in the worst case we'll do useless copy */
66841- if (fs->users == 1)
66842+ if (atomic_read(&fs->users) == 1)
66843 return 0;
66844
66845 *new_fsp = copy_fs_struct(fs);
66846@@ -1828,7 +1876,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
66847 fs = current->fs;
66848 spin_lock(&fs->lock);
66849 current->fs = new_fs;
66850- if (--fs->users)
66851+ gr_set_chroot_entries(current, &current->fs->root);
66852+ if (atomic_dec_return(&fs->users))
66853 new_fs = NULL;
66854 else
66855 new_fs = fs;
66856diff --git a/kernel/futex.c b/kernel/futex.c
66857index 3717e7b..473c750 100644
66858--- a/kernel/futex.c
66859+++ b/kernel/futex.c
66860@@ -54,6 +54,7 @@
66861 #include <linux/mount.h>
66862 #include <linux/pagemap.h>
66863 #include <linux/syscalls.h>
66864+#include <linux/ptrace.h>
66865 #include <linux/signal.h>
66866 #include <linux/export.h>
66867 #include <linux/magic.h>
66868@@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
66869 struct page *page, *page_head;
66870 int err, ro = 0;
66871
66872+#ifdef CONFIG_PAX_SEGMEXEC
66873+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
66874+ return -EFAULT;
66875+#endif
66876+
66877 /*
66878 * The futex address must be "naturally" aligned.
66879 */
66880@@ -2714,6 +2720,7 @@ static int __init futex_init(void)
66881 {
66882 u32 curval;
66883 int i;
66884+ mm_segment_t oldfs;
66885
66886 /*
66887 * This will fail and we want it. Some arch implementations do
66888@@ -2725,8 +2732,11 @@ static int __init futex_init(void)
66889 * implementation, the non-functional ones will return
66890 * -ENOSYS.
66891 */
66892+ oldfs = get_fs();
66893+ set_fs(USER_DS);
66894 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
66895 futex_cmpxchg_enabled = 1;
66896+ set_fs(oldfs);
66897
66898 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
66899 plist_head_init(&futex_queues[i].chain);
66900diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
66901index 9b22d03..6295b62 100644
66902--- a/kernel/gcov/base.c
66903+++ b/kernel/gcov/base.c
66904@@ -102,11 +102,6 @@ void gcov_enable_events(void)
66905 }
66906
66907 #ifdef CONFIG_MODULES
66908-static inline int within(void *addr, void *start, unsigned long size)
66909-{
66910- return ((addr >= start) && (addr < start + size));
66911-}
66912-
66913 /* Update list and generate events when modules are unloaded. */
66914 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66915 void *data)
66916@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66917 prev = NULL;
66918 /* Remove entries located in module from linked list. */
66919 for (info = gcov_info_head; info; info = info->next) {
66920- if (within(info, mod->module_core, mod->core_size)) {
66921+ if (within_module_core_rw((unsigned long)info, mod)) {
66922 if (prev)
66923 prev->next = info->next;
66924 else
66925diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
66926index 6db7a5e..25b6648 100644
66927--- a/kernel/hrtimer.c
66928+++ b/kernel/hrtimer.c
66929@@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
66930 local_irq_restore(flags);
66931 }
66932
66933-static void run_hrtimer_softirq(struct softirq_action *h)
66934+static void run_hrtimer_softirq(void)
66935 {
66936 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
66937
66938diff --git a/kernel/jump_label.c b/kernel/jump_label.c
66939index 4304919..408c4c0 100644
66940--- a/kernel/jump_label.c
66941+++ b/kernel/jump_label.c
66942@@ -13,6 +13,7 @@
66943 #include <linux/sort.h>
66944 #include <linux/err.h>
66945 #include <linux/static_key.h>
66946+#include <linux/mm.h>
66947
66948 #ifdef HAVE_JUMP_LABEL
66949
66950@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
66951
66952 size = (((unsigned long)stop - (unsigned long)start)
66953 / sizeof(struct jump_entry));
66954+ pax_open_kernel();
66955 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
66956+ pax_close_kernel();
66957 }
66958
66959 static void jump_label_update(struct static_key *key, int enable);
66960@@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
66961 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
66962 struct jump_entry *iter;
66963
66964+ pax_open_kernel();
66965 for (iter = iter_start; iter < iter_stop; iter++) {
66966 if (within_module_init(iter->code, mod))
66967 iter->code = 0;
66968 }
66969+ pax_close_kernel();
66970 }
66971
66972 static int
66973diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
66974index 2169fee..45c017a 100644
66975--- a/kernel/kallsyms.c
66976+++ b/kernel/kallsyms.c
66977@@ -11,6 +11,9 @@
66978 * Changed the compression method from stem compression to "table lookup"
66979 * compression (see scripts/kallsyms.c for a more complete description)
66980 */
66981+#ifdef CONFIG_GRKERNSEC_HIDESYM
66982+#define __INCLUDED_BY_HIDESYM 1
66983+#endif
66984 #include <linux/kallsyms.h>
66985 #include <linux/module.h>
66986 #include <linux/init.h>
66987@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
66988
66989 static inline int is_kernel_inittext(unsigned long addr)
66990 {
66991+ if (system_state != SYSTEM_BOOTING)
66992+ return 0;
66993+
66994 if (addr >= (unsigned long)_sinittext
66995 && addr <= (unsigned long)_einittext)
66996 return 1;
66997 return 0;
66998 }
66999
67000+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67001+#ifdef CONFIG_MODULES
67002+static inline int is_module_text(unsigned long addr)
67003+{
67004+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
67005+ return 1;
67006+
67007+ addr = ktla_ktva(addr);
67008+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
67009+}
67010+#else
67011+static inline int is_module_text(unsigned long addr)
67012+{
67013+ return 0;
67014+}
67015+#endif
67016+#endif
67017+
67018 static inline int is_kernel_text(unsigned long addr)
67019 {
67020 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
67021@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
67022
67023 static inline int is_kernel(unsigned long addr)
67024 {
67025+
67026+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67027+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
67028+ return 1;
67029+
67030+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
67031+#else
67032 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
67033+#endif
67034+
67035 return 1;
67036 return in_gate_area_no_mm(addr);
67037 }
67038
67039 static int is_ksym_addr(unsigned long addr)
67040 {
67041+
67042+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67043+ if (is_module_text(addr))
67044+ return 0;
67045+#endif
67046+
67047 if (all_var)
67048 return is_kernel(addr);
67049
67050@@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
67051
67052 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
67053 {
67054- iter->name[0] = '\0';
67055 iter->nameoff = get_symbol_offset(new_pos);
67056 iter->pos = new_pos;
67057 }
67058@@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
67059 {
67060 struct kallsym_iter *iter = m->private;
67061
67062+#ifdef CONFIG_GRKERNSEC_HIDESYM
67063+ if (current_uid())
67064+ return 0;
67065+#endif
67066+
67067 /* Some debugging symbols have no name. Ignore them. */
67068 if (!iter->name[0])
67069 return 0;
67070@@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
67071 */
67072 type = iter->exported ? toupper(iter->type) :
67073 tolower(iter->type);
67074+
67075 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
67076 type, iter->name, iter->module_name);
67077 } else
67078@@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
67079 struct kallsym_iter *iter;
67080 int ret;
67081
67082- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
67083+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
67084 if (!iter)
67085 return -ENOMEM;
67086 reset_iter(iter, 0);
67087diff --git a/kernel/kexec.c b/kernel/kexec.c
67088index 4e2e472..cd0c7ae 100644
67089--- a/kernel/kexec.c
67090+++ b/kernel/kexec.c
67091@@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
67092 unsigned long flags)
67093 {
67094 struct compat_kexec_segment in;
67095- struct kexec_segment out, __user *ksegments;
67096+ struct kexec_segment out;
67097+ struct kexec_segment __user *ksegments;
67098 unsigned long i, result;
67099
67100 /* Don't allow clients that don't understand the native
67101diff --git a/kernel/kmod.c b/kernel/kmod.c
67102index ff2c7cb..085d7af 100644
67103--- a/kernel/kmod.c
67104+++ b/kernel/kmod.c
67105@@ -66,7 +66,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
67106 kfree(info->argv);
67107 }
67108
67109-static int call_modprobe(char *module_name, int wait)
67110+static int call_modprobe(char *module_name, char *module_param, int wait)
67111 {
67112 static char *envp[] = {
67113 "HOME=/",
67114@@ -75,7 +75,7 @@ static int call_modprobe(char *module_name, int wait)
67115 NULL
67116 };
67117
67118- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
67119+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
67120 if (!argv)
67121 goto out;
67122
67123@@ -87,7 +87,8 @@ static int call_modprobe(char *module_name, int wait)
67124 argv[1] = "-q";
67125 argv[2] = "--";
67126 argv[3] = module_name; /* check free_modprobe_argv() */
67127- argv[4] = NULL;
67128+ argv[4] = module_param;
67129+ argv[5] = NULL;
67130
67131 return call_usermodehelper_fns(modprobe_path, argv, envp,
67132 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
67133@@ -112,9 +113,8 @@ out:
67134 * If module auto-loading support is disabled then this function
67135 * becomes a no-operation.
67136 */
67137-int __request_module(bool wait, const char *fmt, ...)
67138+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
67139 {
67140- va_list args;
67141 char module_name[MODULE_NAME_LEN];
67142 unsigned int max_modprobes;
67143 int ret;
67144@@ -122,9 +122,7 @@ int __request_module(bool wait, const char *fmt, ...)
67145 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
67146 static int kmod_loop_msg;
67147
67148- va_start(args, fmt);
67149- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
67150- va_end(args);
67151+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
67152 if (ret >= MODULE_NAME_LEN)
67153 return -ENAMETOOLONG;
67154
67155@@ -132,6 +130,20 @@ int __request_module(bool wait, const char *fmt, ...)
67156 if (ret)
67157 return ret;
67158
67159+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67160+ if (!current_uid()) {
67161+ /* hack to workaround consolekit/udisks stupidity */
67162+ read_lock(&tasklist_lock);
67163+ if (!strcmp(current->comm, "mount") &&
67164+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
67165+ read_unlock(&tasklist_lock);
67166+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
67167+ return -EPERM;
67168+ }
67169+ read_unlock(&tasklist_lock);
67170+ }
67171+#endif
67172+
67173 /* If modprobe needs a service that is in a module, we get a recursive
67174 * loop. Limit the number of running kmod threads to max_threads/2 or
67175 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
67176@@ -160,11 +172,52 @@ int __request_module(bool wait, const char *fmt, ...)
67177
67178 trace_module_request(module_name, wait, _RET_IP_);
67179
67180- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67181+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67182
67183 atomic_dec(&kmod_concurrent);
67184 return ret;
67185 }
67186+
67187+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
67188+{
67189+ va_list args;
67190+ int ret;
67191+
67192+ va_start(args, fmt);
67193+ ret = ____request_module(wait, module_param, fmt, args);
67194+ va_end(args);
67195+
67196+ return ret;
67197+}
67198+
67199+int __request_module(bool wait, const char *fmt, ...)
67200+{
67201+ va_list args;
67202+ int ret;
67203+
67204+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67205+ if (current_uid()) {
67206+ char module_param[MODULE_NAME_LEN];
67207+
67208+ memset(module_param, 0, sizeof(module_param));
67209+
67210+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
67211+
67212+ va_start(args, fmt);
67213+ ret = ____request_module(wait, module_param, fmt, args);
67214+ va_end(args);
67215+
67216+ return ret;
67217+ }
67218+#endif
67219+
67220+ va_start(args, fmt);
67221+ ret = ____request_module(wait, NULL, fmt, args);
67222+ va_end(args);
67223+
67224+ return ret;
67225+}
67226+
67227 EXPORT_SYMBOL(__request_module);
67228 #endif /* CONFIG_MODULES */
67229
67230@@ -266,7 +319,7 @@ static int wait_for_helper(void *data)
67231 *
67232 * Thus the __user pointer cast is valid here.
67233 */
67234- sys_wait4(pid, (int __user *)&ret, 0, NULL);
67235+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
67236
67237 /*
67238 * If ret is 0, either ____call_usermodehelper failed and the
67239diff --git a/kernel/kprobes.c b/kernel/kprobes.c
67240index c62b854..cb67968 100644
67241--- a/kernel/kprobes.c
67242+++ b/kernel/kprobes.c
67243@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
67244 * kernel image and loaded module images reside. This is required
67245 * so x86_64 can correctly handle the %rip-relative fixups.
67246 */
67247- kip->insns = module_alloc(PAGE_SIZE);
67248+ kip->insns = module_alloc_exec(PAGE_SIZE);
67249 if (!kip->insns) {
67250 kfree(kip);
67251 return NULL;
67252@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
67253 */
67254 if (!list_is_singular(&kip->list)) {
67255 list_del(&kip->list);
67256- module_free(NULL, kip->insns);
67257+ module_free_exec(NULL, kip->insns);
67258 kfree(kip);
67259 }
67260 return 1;
67261@@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
67262 {
67263 int i, err = 0;
67264 unsigned long offset = 0, size = 0;
67265- char *modname, namebuf[128];
67266+ char *modname, namebuf[KSYM_NAME_LEN];
67267 const char *symbol_name;
67268 void *addr;
67269 struct kprobe_blackpoint *kb;
67270@@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
67271 const char *sym = NULL;
67272 unsigned int i = *(loff_t *) v;
67273 unsigned long offset = 0;
67274- char *modname, namebuf[128];
67275+ char *modname, namebuf[KSYM_NAME_LEN];
67276
67277 head = &kprobe_table[i];
67278 preempt_disable();
67279diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
67280index 4e316e1..5501eef 100644
67281--- a/kernel/ksysfs.c
67282+++ b/kernel/ksysfs.c
67283@@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
67284 {
67285 if (count+1 > UEVENT_HELPER_PATH_LEN)
67286 return -ENOENT;
67287+ if (!capable(CAP_SYS_ADMIN))
67288+ return -EPERM;
67289 memcpy(uevent_helper, buf, count);
67290 uevent_helper[count] = '\0';
67291 if (count && uevent_helper[count-1] == '\n')
67292diff --git a/kernel/lockdep.c b/kernel/lockdep.c
67293index ea9ee45..67ebc8f 100644
67294--- a/kernel/lockdep.c
67295+++ b/kernel/lockdep.c
67296@@ -590,6 +590,10 @@ static int static_obj(void *obj)
67297 end = (unsigned long) &_end,
67298 addr = (unsigned long) obj;
67299
67300+#ifdef CONFIG_PAX_KERNEXEC
67301+ start = ktla_ktva(start);
67302+#endif
67303+
67304 /*
67305 * static variable?
67306 */
67307@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
67308 if (!static_obj(lock->key)) {
67309 debug_locks_off();
67310 printk("INFO: trying to register non-static key.\n");
67311+ printk("lock:%pS key:%pS.\n", lock, lock->key);
67312 printk("the code is fine but needs lockdep annotation.\n");
67313 printk("turning off the locking correctness validator.\n");
67314 dump_stack();
67315@@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
67316 if (!class)
67317 return 0;
67318 }
67319- atomic_inc((atomic_t *)&class->ops);
67320+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
67321 if (very_verbose(class)) {
67322 printk("\nacquire class [%p] %s", class->key, class->name);
67323 if (class->name_version > 1)
67324diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
67325index 91c32a0..b2c71c5 100644
67326--- a/kernel/lockdep_proc.c
67327+++ b/kernel/lockdep_proc.c
67328@@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
67329
67330 static void print_name(struct seq_file *m, struct lock_class *class)
67331 {
67332- char str[128];
67333+ char str[KSYM_NAME_LEN];
67334 const char *name = class->name;
67335
67336 if (!name) {
67337diff --git a/kernel/module.c b/kernel/module.c
67338index 4edbd9c..165e780 100644
67339--- a/kernel/module.c
67340+++ b/kernel/module.c
67341@@ -58,6 +58,7 @@
67342 #include <linux/jump_label.h>
67343 #include <linux/pfn.h>
67344 #include <linux/bsearch.h>
67345+#include <linux/grsecurity.h>
67346
67347 #define CREATE_TRACE_POINTS
67348 #include <trace/events/module.h>
67349@@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
67350
67351 /* Bounds of module allocation, for speeding __module_address.
67352 * Protected by module_mutex. */
67353-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
67354+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
67355+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
67356
67357 int register_module_notifier(struct notifier_block * nb)
67358 {
67359@@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
67360 return true;
67361
67362 list_for_each_entry_rcu(mod, &modules, list) {
67363- struct symsearch arr[] = {
67364+ struct symsearch modarr[] = {
67365 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
67366 NOT_GPL_ONLY, false },
67367 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
67368@@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
67369 #endif
67370 };
67371
67372- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
67373+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
67374 return true;
67375 }
67376 return false;
67377@@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
67378 static int percpu_modalloc(struct module *mod,
67379 unsigned long size, unsigned long align)
67380 {
67381- if (align > PAGE_SIZE) {
67382+ if (align-1 >= PAGE_SIZE) {
67383 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
67384 mod->name, align, PAGE_SIZE);
67385 align = PAGE_SIZE;
67386@@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
67387 static ssize_t show_coresize(struct module_attribute *mattr,
67388 struct module_kobject *mk, char *buffer)
67389 {
67390- return sprintf(buffer, "%u\n", mk->mod->core_size);
67391+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
67392 }
67393
67394 static struct module_attribute modinfo_coresize =
67395@@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
67396 static ssize_t show_initsize(struct module_attribute *mattr,
67397 struct module_kobject *mk, char *buffer)
67398 {
67399- return sprintf(buffer, "%u\n", mk->mod->init_size);
67400+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
67401 }
67402
67403 static struct module_attribute modinfo_initsize =
67404@@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
67405 */
67406 #ifdef CONFIG_SYSFS
67407
67408-#ifdef CONFIG_KALLSYMS
67409+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67410 static inline bool sect_empty(const Elf_Shdr *sect)
67411 {
67412 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
67413@@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
67414
67415 static void unset_module_core_ro_nx(struct module *mod)
67416 {
67417- set_page_attributes(mod->module_core + mod->core_text_size,
67418- mod->module_core + mod->core_size,
67419+ set_page_attributes(mod->module_core_rw,
67420+ mod->module_core_rw + mod->core_size_rw,
67421 set_memory_x);
67422- set_page_attributes(mod->module_core,
67423- mod->module_core + mod->core_ro_size,
67424+ set_page_attributes(mod->module_core_rx,
67425+ mod->module_core_rx + mod->core_size_rx,
67426 set_memory_rw);
67427 }
67428
67429 static void unset_module_init_ro_nx(struct module *mod)
67430 {
67431- set_page_attributes(mod->module_init + mod->init_text_size,
67432- mod->module_init + mod->init_size,
67433+ set_page_attributes(mod->module_init_rw,
67434+ mod->module_init_rw + mod->init_size_rw,
67435 set_memory_x);
67436- set_page_attributes(mod->module_init,
67437- mod->module_init + mod->init_ro_size,
67438+ set_page_attributes(mod->module_init_rx,
67439+ mod->module_init_rx + mod->init_size_rx,
67440 set_memory_rw);
67441 }
67442
67443@@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
67444
67445 mutex_lock(&module_mutex);
67446 list_for_each_entry_rcu(mod, &modules, list) {
67447- if ((mod->module_core) && (mod->core_text_size)) {
67448- set_page_attributes(mod->module_core,
67449- mod->module_core + mod->core_text_size,
67450+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
67451+ set_page_attributes(mod->module_core_rx,
67452+ mod->module_core_rx + mod->core_size_rx,
67453 set_memory_rw);
67454 }
67455- if ((mod->module_init) && (mod->init_text_size)) {
67456- set_page_attributes(mod->module_init,
67457- mod->module_init + mod->init_text_size,
67458+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
67459+ set_page_attributes(mod->module_init_rx,
67460+ mod->module_init_rx + mod->init_size_rx,
67461 set_memory_rw);
67462 }
67463 }
67464@@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
67465
67466 mutex_lock(&module_mutex);
67467 list_for_each_entry_rcu(mod, &modules, list) {
67468- if ((mod->module_core) && (mod->core_text_size)) {
67469- set_page_attributes(mod->module_core,
67470- mod->module_core + mod->core_text_size,
67471+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
67472+ set_page_attributes(mod->module_core_rx,
67473+ mod->module_core_rx + mod->core_size_rx,
67474 set_memory_ro);
67475 }
67476- if ((mod->module_init) && (mod->init_text_size)) {
67477- set_page_attributes(mod->module_init,
67478- mod->module_init + mod->init_text_size,
67479+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
67480+ set_page_attributes(mod->module_init_rx,
67481+ mod->module_init_rx + mod->init_size_rx,
67482 set_memory_ro);
67483 }
67484 }
67485@@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
67486
67487 /* This may be NULL, but that's OK */
67488 unset_module_init_ro_nx(mod);
67489- module_free(mod, mod->module_init);
67490+ module_free(mod, mod->module_init_rw);
67491+ module_free_exec(mod, mod->module_init_rx);
67492 kfree(mod->args);
67493 percpu_modfree(mod);
67494
67495 /* Free lock-classes: */
67496- lockdep_free_key_range(mod->module_core, mod->core_size);
67497+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
67498+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
67499
67500 /* Finally, free the core (containing the module structure) */
67501 unset_module_core_ro_nx(mod);
67502- module_free(mod, mod->module_core);
67503+ module_free_exec(mod, mod->module_core_rx);
67504+ module_free(mod, mod->module_core_rw);
67505
67506 #ifdef CONFIG_MPU
67507 update_protections(current->mm);
67508@@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67509 int ret = 0;
67510 const struct kernel_symbol *ksym;
67511
67512+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67513+ int is_fs_load = 0;
67514+ int register_filesystem_found = 0;
67515+ char *p;
67516+
67517+ p = strstr(mod->args, "grsec_modharden_fs");
67518+ if (p) {
67519+ char *endptr = p + strlen("grsec_modharden_fs");
67520+ /* copy \0 as well */
67521+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
67522+ is_fs_load = 1;
67523+ }
67524+#endif
67525+
67526 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
67527 const char *name = info->strtab + sym[i].st_name;
67528
67529+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67530+ /* it's a real shame this will never get ripped and copied
67531+ upstream! ;(
67532+ */
67533+ if (is_fs_load && !strcmp(name, "register_filesystem"))
67534+ register_filesystem_found = 1;
67535+#endif
67536+
67537 switch (sym[i].st_shndx) {
67538 case SHN_COMMON:
67539 /* We compiled with -fno-common. These are not
67540@@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67541 ksym = resolve_symbol_wait(mod, info, name);
67542 /* Ok if resolved. */
67543 if (ksym && !IS_ERR(ksym)) {
67544+ pax_open_kernel();
67545 sym[i].st_value = ksym->value;
67546+ pax_close_kernel();
67547 break;
67548 }
67549
67550@@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67551 secbase = (unsigned long)mod_percpu(mod);
67552 else
67553 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
67554+ pax_open_kernel();
67555 sym[i].st_value += secbase;
67556+ pax_close_kernel();
67557 break;
67558 }
67559 }
67560
67561+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67562+ if (is_fs_load && !register_filesystem_found) {
67563+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
67564+ ret = -EPERM;
67565+ }
67566+#endif
67567+
67568 return ret;
67569 }
67570
67571@@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
67572 || s->sh_entsize != ~0UL
67573 || strstarts(sname, ".init"))
67574 continue;
67575- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
67576+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67577+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
67578+ else
67579+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
67580 pr_debug("\t%s\n", sname);
67581 }
67582- switch (m) {
67583- case 0: /* executable */
67584- mod->core_size = debug_align(mod->core_size);
67585- mod->core_text_size = mod->core_size;
67586- break;
67587- case 1: /* RO: text and ro-data */
67588- mod->core_size = debug_align(mod->core_size);
67589- mod->core_ro_size = mod->core_size;
67590- break;
67591- case 3: /* whole core */
67592- mod->core_size = debug_align(mod->core_size);
67593- break;
67594- }
67595 }
67596
67597 pr_debug("Init section allocation order:\n");
67598@@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
67599 || s->sh_entsize != ~0UL
67600 || !strstarts(sname, ".init"))
67601 continue;
67602- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
67603- | INIT_OFFSET_MASK);
67604+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67605+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
67606+ else
67607+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
67608+ s->sh_entsize |= INIT_OFFSET_MASK;
67609 pr_debug("\t%s\n", sname);
67610 }
67611- switch (m) {
67612- case 0: /* executable */
67613- mod->init_size = debug_align(mod->init_size);
67614- mod->init_text_size = mod->init_size;
67615- break;
67616- case 1: /* RO: text and ro-data */
67617- mod->init_size = debug_align(mod->init_size);
67618- mod->init_ro_size = mod->init_size;
67619- break;
67620- case 3: /* whole init */
67621- mod->init_size = debug_align(mod->init_size);
67622- break;
67623- }
67624 }
67625 }
67626
67627@@ -2266,7 +2284,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67628
67629 /* Put symbol section at end of init part of module. */
67630 symsect->sh_flags |= SHF_ALLOC;
67631- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
67632+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
67633 info->index.sym) | INIT_OFFSET_MASK;
67634 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
67635
67636@@ -2281,13 +2299,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67637 }
67638
67639 /* Append room for core symbols at end of core part. */
67640- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
67641- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
67642- mod->core_size += strtab_size;
67643+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
67644+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
67645+ mod->core_size_rx += strtab_size;
67646
67647 /* Put string table section at end of init part of module. */
67648 strsect->sh_flags |= SHF_ALLOC;
67649- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
67650+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
67651 info->index.str) | INIT_OFFSET_MASK;
67652 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
67653 }
67654@@ -2305,12 +2323,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67655 /* Make sure we get permanent strtab: don't use info->strtab. */
67656 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
67657
67658+ pax_open_kernel();
67659+
67660 /* Set types up while we still have access to sections. */
67661 for (i = 0; i < mod->num_symtab; i++)
67662 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
67663
67664- mod->core_symtab = dst = mod->module_core + info->symoffs;
67665- mod->core_strtab = s = mod->module_core + info->stroffs;
67666+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
67667+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
67668 src = mod->symtab;
67669 *dst = *src;
67670 *s++ = 0;
67671@@ -2323,6 +2343,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67672 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
67673 }
67674 mod->core_num_syms = ndst;
67675+
67676+ pax_close_kernel();
67677 }
67678 #else
67679 static inline void layout_symtab(struct module *mod, struct load_info *info)
67680@@ -2356,17 +2378,33 @@ void * __weak module_alloc(unsigned long size)
67681 return size == 0 ? NULL : vmalloc_exec(size);
67682 }
67683
67684-static void *module_alloc_update_bounds(unsigned long size)
67685+static void *module_alloc_update_bounds_rw(unsigned long size)
67686 {
67687 void *ret = module_alloc(size);
67688
67689 if (ret) {
67690 mutex_lock(&module_mutex);
67691 /* Update module bounds. */
67692- if ((unsigned long)ret < module_addr_min)
67693- module_addr_min = (unsigned long)ret;
67694- if ((unsigned long)ret + size > module_addr_max)
67695- module_addr_max = (unsigned long)ret + size;
67696+ if ((unsigned long)ret < module_addr_min_rw)
67697+ module_addr_min_rw = (unsigned long)ret;
67698+ if ((unsigned long)ret + size > module_addr_max_rw)
67699+ module_addr_max_rw = (unsigned long)ret + size;
67700+ mutex_unlock(&module_mutex);
67701+ }
67702+ return ret;
67703+}
67704+
67705+static void *module_alloc_update_bounds_rx(unsigned long size)
67706+{
67707+ void *ret = module_alloc_exec(size);
67708+
67709+ if (ret) {
67710+ mutex_lock(&module_mutex);
67711+ /* Update module bounds. */
67712+ if ((unsigned long)ret < module_addr_min_rx)
67713+ module_addr_min_rx = (unsigned long)ret;
67714+ if ((unsigned long)ret + size > module_addr_max_rx)
67715+ module_addr_max_rx = (unsigned long)ret + size;
67716 mutex_unlock(&module_mutex);
67717 }
67718 return ret;
67719@@ -2544,8 +2582,14 @@ static struct module *setup_load_info(struct load_info *info)
67720 static int check_modinfo(struct module *mod, struct load_info *info)
67721 {
67722 const char *modmagic = get_modinfo(info, "vermagic");
67723+ const char *license = get_modinfo(info, "license");
67724 int err;
67725
67726+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
67727+ if (!license || !license_is_gpl_compatible(license))
67728+ return -ENOEXEC;
67729+#endif
67730+
67731 /* This is allowed: modprobe --force will invalidate it. */
67732 if (!modmagic) {
67733 err = try_to_force_load(mod, "bad vermagic");
67734@@ -2568,7 +2612,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
67735 }
67736
67737 /* Set up license info based on the info section */
67738- set_license(mod, get_modinfo(info, "license"));
67739+ set_license(mod, license);
67740
67741 return 0;
67742 }
67743@@ -2662,7 +2706,7 @@ static int move_module(struct module *mod, struct load_info *info)
67744 void *ptr;
67745
67746 /* Do the allocs. */
67747- ptr = module_alloc_update_bounds(mod->core_size);
67748+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
67749 /*
67750 * The pointer to this block is stored in the module structure
67751 * which is inside the block. Just mark it as not being a
67752@@ -2672,23 +2716,50 @@ static int move_module(struct module *mod, struct load_info *info)
67753 if (!ptr)
67754 return -ENOMEM;
67755
67756- memset(ptr, 0, mod->core_size);
67757- mod->module_core = ptr;
67758+ memset(ptr, 0, mod->core_size_rw);
67759+ mod->module_core_rw = ptr;
67760
67761- ptr = module_alloc_update_bounds(mod->init_size);
67762+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
67763 /*
67764 * The pointer to this block is stored in the module structure
67765 * which is inside the block. This block doesn't need to be
67766 * scanned as it contains data and code that will be freed
67767 * after the module is initialized.
67768 */
67769- kmemleak_ignore(ptr);
67770- if (!ptr && mod->init_size) {
67771- module_free(mod, mod->module_core);
67772+ kmemleak_not_leak(ptr);
67773+ if (!ptr && mod->init_size_rw) {
67774+ module_free(mod, mod->module_core_rw);
67775 return -ENOMEM;
67776 }
67777- memset(ptr, 0, mod->init_size);
67778- mod->module_init = ptr;
67779+ memset(ptr, 0, mod->init_size_rw);
67780+ mod->module_init_rw = ptr;
67781+
67782+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
67783+ kmemleak_not_leak(ptr);
67784+ if (!ptr) {
67785+ module_free(mod, mod->module_init_rw);
67786+ module_free(mod, mod->module_core_rw);
67787+ return -ENOMEM;
67788+ }
67789+
67790+ pax_open_kernel();
67791+ memset(ptr, 0, mod->core_size_rx);
67792+ pax_close_kernel();
67793+ mod->module_core_rx = ptr;
67794+
67795+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
67796+ kmemleak_not_leak(ptr);
67797+ if (!ptr && mod->init_size_rx) {
67798+ module_free_exec(mod, mod->module_core_rx);
67799+ module_free(mod, mod->module_init_rw);
67800+ module_free(mod, mod->module_core_rw);
67801+ return -ENOMEM;
67802+ }
67803+
67804+ pax_open_kernel();
67805+ memset(ptr, 0, mod->init_size_rx);
67806+ pax_close_kernel();
67807+ mod->module_init_rx = ptr;
67808
67809 /* Transfer each section which specifies SHF_ALLOC */
67810 pr_debug("final section addresses:\n");
67811@@ -2699,16 +2770,45 @@ static int move_module(struct module *mod, struct load_info *info)
67812 if (!(shdr->sh_flags & SHF_ALLOC))
67813 continue;
67814
67815- if (shdr->sh_entsize & INIT_OFFSET_MASK)
67816- dest = mod->module_init
67817- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67818- else
67819- dest = mod->module_core + shdr->sh_entsize;
67820+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
67821+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67822+ dest = mod->module_init_rw
67823+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67824+ else
67825+ dest = mod->module_init_rx
67826+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67827+ } else {
67828+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67829+ dest = mod->module_core_rw + shdr->sh_entsize;
67830+ else
67831+ dest = mod->module_core_rx + shdr->sh_entsize;
67832+ }
67833+
67834+ if (shdr->sh_type != SHT_NOBITS) {
67835+
67836+#ifdef CONFIG_PAX_KERNEXEC
67837+#ifdef CONFIG_X86_64
67838+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
67839+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
67840+#endif
67841+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
67842+ pax_open_kernel();
67843+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67844+ pax_close_kernel();
67845+ } else
67846+#endif
67847
67848- if (shdr->sh_type != SHT_NOBITS)
67849 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67850+ }
67851 /* Update sh_addr to point to copy in image. */
67852- shdr->sh_addr = (unsigned long)dest;
67853+
67854+#ifdef CONFIG_PAX_KERNEXEC
67855+ if (shdr->sh_flags & SHF_EXECINSTR)
67856+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
67857+ else
67858+#endif
67859+
67860+ shdr->sh_addr = (unsigned long)dest;
67861 pr_debug("\t0x%lx %s\n",
67862 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
67863 }
67864@@ -2759,12 +2859,12 @@ static void flush_module_icache(const struct module *mod)
67865 * Do it before processing of module parameters, so the module
67866 * can provide parameter accessor functions of its own.
67867 */
67868- if (mod->module_init)
67869- flush_icache_range((unsigned long)mod->module_init,
67870- (unsigned long)mod->module_init
67871- + mod->init_size);
67872- flush_icache_range((unsigned long)mod->module_core,
67873- (unsigned long)mod->module_core + mod->core_size);
67874+ if (mod->module_init_rx)
67875+ flush_icache_range((unsigned long)mod->module_init_rx,
67876+ (unsigned long)mod->module_init_rx
67877+ + mod->init_size_rx);
67878+ flush_icache_range((unsigned long)mod->module_core_rx,
67879+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
67880
67881 set_fs(old_fs);
67882 }
67883@@ -2834,8 +2934,10 @@ out:
67884 static void module_deallocate(struct module *mod, struct load_info *info)
67885 {
67886 percpu_modfree(mod);
67887- module_free(mod, mod->module_init);
67888- module_free(mod, mod->module_core);
67889+ module_free_exec(mod, mod->module_init_rx);
67890+ module_free_exec(mod, mod->module_core_rx);
67891+ module_free(mod, mod->module_init_rw);
67892+ module_free(mod, mod->module_core_rw);
67893 }
67894
67895 int __weak module_finalize(const Elf_Ehdr *hdr,
67896@@ -2848,7 +2950,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
67897 static int post_relocation(struct module *mod, const struct load_info *info)
67898 {
67899 /* Sort exception table now relocations are done. */
67900+ pax_open_kernel();
67901 sort_extable(mod->extable, mod->extable + mod->num_exentries);
67902+ pax_close_kernel();
67903
67904 /* Copy relocated percpu area over. */
67905 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
67906@@ -2899,9 +3003,38 @@ static struct module *load_module(void __user *umod,
67907 if (err)
67908 goto free_unload;
67909
67910+ /* Now copy in args */
67911+ mod->args = strndup_user(uargs, ~0UL >> 1);
67912+ if (IS_ERR(mod->args)) {
67913+ err = PTR_ERR(mod->args);
67914+ goto free_unload;
67915+ }
67916+
67917 /* Set up MODINFO_ATTR fields */
67918 setup_modinfo(mod, &info);
67919
67920+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67921+ {
67922+ char *p, *p2;
67923+
67924+ if (strstr(mod->args, "grsec_modharden_netdev")) {
67925+ 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);
67926+ err = -EPERM;
67927+ goto free_modinfo;
67928+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
67929+ p += strlen("grsec_modharden_normal");
67930+ p2 = strstr(p, "_");
67931+ if (p2) {
67932+ *p2 = '\0';
67933+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
67934+ *p2 = '_';
67935+ }
67936+ err = -EPERM;
67937+ goto free_modinfo;
67938+ }
67939+ }
67940+#endif
67941+
67942 /* Fix up syms, so that st_value is a pointer to location. */
67943 err = simplify_symbols(mod, &info);
67944 if (err < 0)
67945@@ -2917,13 +3050,6 @@ static struct module *load_module(void __user *umod,
67946
67947 flush_module_icache(mod);
67948
67949- /* Now copy in args */
67950- mod->args = strndup_user(uargs, ~0UL >> 1);
67951- if (IS_ERR(mod->args)) {
67952- err = PTR_ERR(mod->args);
67953- goto free_arch_cleanup;
67954- }
67955-
67956 /* Mark state as coming so strong_try_module_get() ignores us. */
67957 mod->state = MODULE_STATE_COMING;
67958
67959@@ -2981,11 +3107,10 @@ static struct module *load_module(void __user *umod,
67960 unlock:
67961 mutex_unlock(&module_mutex);
67962 synchronize_sched();
67963- kfree(mod->args);
67964- free_arch_cleanup:
67965 module_arch_cleanup(mod);
67966 free_modinfo:
67967 free_modinfo(mod);
67968+ kfree(mod->args);
67969 free_unload:
67970 module_unload_free(mod);
67971 free_module:
67972@@ -3026,16 +3151,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67973 MODULE_STATE_COMING, mod);
67974
67975 /* Set RO and NX regions for core */
67976- set_section_ro_nx(mod->module_core,
67977- mod->core_text_size,
67978- mod->core_ro_size,
67979- mod->core_size);
67980+ set_section_ro_nx(mod->module_core_rx,
67981+ mod->core_size_rx,
67982+ mod->core_size_rx,
67983+ mod->core_size_rx);
67984
67985 /* Set RO and NX regions for init */
67986- set_section_ro_nx(mod->module_init,
67987- mod->init_text_size,
67988- mod->init_ro_size,
67989- mod->init_size);
67990+ set_section_ro_nx(mod->module_init_rx,
67991+ mod->init_size_rx,
67992+ mod->init_size_rx,
67993+ mod->init_size_rx);
67994
67995 do_mod_ctors(mod);
67996 /* Start the module */
67997@@ -3081,11 +3206,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67998 mod->strtab = mod->core_strtab;
67999 #endif
68000 unset_module_init_ro_nx(mod);
68001- module_free(mod, mod->module_init);
68002- mod->module_init = NULL;
68003- mod->init_size = 0;
68004- mod->init_ro_size = 0;
68005- mod->init_text_size = 0;
68006+ module_free(mod, mod->module_init_rw);
68007+ module_free_exec(mod, mod->module_init_rx);
68008+ mod->module_init_rw = NULL;
68009+ mod->module_init_rx = NULL;
68010+ mod->init_size_rw = 0;
68011+ mod->init_size_rx = 0;
68012 mutex_unlock(&module_mutex);
68013
68014 return 0;
68015@@ -3116,10 +3242,16 @@ static const char *get_ksymbol(struct module *mod,
68016 unsigned long nextval;
68017
68018 /* At worse, next value is at end of module */
68019- if (within_module_init(addr, mod))
68020- nextval = (unsigned long)mod->module_init+mod->init_text_size;
68021+ if (within_module_init_rx(addr, mod))
68022+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
68023+ else if (within_module_init_rw(addr, mod))
68024+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
68025+ else if (within_module_core_rx(addr, mod))
68026+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
68027+ else if (within_module_core_rw(addr, mod))
68028+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
68029 else
68030- nextval = (unsigned long)mod->module_core+mod->core_text_size;
68031+ return NULL;
68032
68033 /* Scan for closest preceding symbol, and next symbol. (ELF
68034 starts real symbols at 1). */
68035@@ -3354,7 +3486,7 @@ static int m_show(struct seq_file *m, void *p)
68036 char buf[8];
68037
68038 seq_printf(m, "%s %u",
68039- mod->name, mod->init_size + mod->core_size);
68040+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
68041 print_unload_info(m, mod);
68042
68043 /* Informative for users. */
68044@@ -3363,7 +3495,7 @@ static int m_show(struct seq_file *m, void *p)
68045 mod->state == MODULE_STATE_COMING ? "Loading":
68046 "Live");
68047 /* Used by oprofile and other similar tools. */
68048- seq_printf(m, " 0x%pK", mod->module_core);
68049+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
68050
68051 /* Taints info */
68052 if (mod->taints)
68053@@ -3399,7 +3531,17 @@ static const struct file_operations proc_modules_operations = {
68054
68055 static int __init proc_modules_init(void)
68056 {
68057+#ifndef CONFIG_GRKERNSEC_HIDESYM
68058+#ifdef CONFIG_GRKERNSEC_PROC_USER
68059+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68060+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68061+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
68062+#else
68063 proc_create("modules", 0, NULL, &proc_modules_operations);
68064+#endif
68065+#else
68066+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68067+#endif
68068 return 0;
68069 }
68070 module_init(proc_modules_init);
68071@@ -3458,12 +3600,12 @@ struct module *__module_address(unsigned long addr)
68072 {
68073 struct module *mod;
68074
68075- if (addr < module_addr_min || addr > module_addr_max)
68076+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
68077+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
68078 return NULL;
68079
68080 list_for_each_entry_rcu(mod, &modules, list)
68081- if (within_module_core(addr, mod)
68082- || within_module_init(addr, mod))
68083+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
68084 return mod;
68085 return NULL;
68086 }
68087@@ -3497,11 +3639,20 @@ bool is_module_text_address(unsigned long addr)
68088 */
68089 struct module *__module_text_address(unsigned long addr)
68090 {
68091- struct module *mod = __module_address(addr);
68092+ struct module *mod;
68093+
68094+#ifdef CONFIG_X86_32
68095+ addr = ktla_ktva(addr);
68096+#endif
68097+
68098+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
68099+ return NULL;
68100+
68101+ mod = __module_address(addr);
68102+
68103 if (mod) {
68104 /* Make sure it's within the text section. */
68105- if (!within(addr, mod->module_init, mod->init_text_size)
68106- && !within(addr, mod->module_core, mod->core_text_size))
68107+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
68108 mod = NULL;
68109 }
68110 return mod;
68111diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
68112index 7e3443f..b2a1e6b 100644
68113--- a/kernel/mutex-debug.c
68114+++ b/kernel/mutex-debug.c
68115@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
68116 }
68117
68118 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68119- struct thread_info *ti)
68120+ struct task_struct *task)
68121 {
68122 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
68123
68124 /* Mark the current thread as blocked on the lock: */
68125- ti->task->blocked_on = waiter;
68126+ task->blocked_on = waiter;
68127 }
68128
68129 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68130- struct thread_info *ti)
68131+ struct task_struct *task)
68132 {
68133 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
68134- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
68135- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
68136- ti->task->blocked_on = NULL;
68137+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
68138+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
68139+ task->blocked_on = NULL;
68140
68141 list_del_init(&waiter->list);
68142 waiter->task = NULL;
68143diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
68144index 0799fd3..d06ae3b 100644
68145--- a/kernel/mutex-debug.h
68146+++ b/kernel/mutex-debug.h
68147@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
68148 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
68149 extern void debug_mutex_add_waiter(struct mutex *lock,
68150 struct mutex_waiter *waiter,
68151- struct thread_info *ti);
68152+ struct task_struct *task);
68153 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68154- struct thread_info *ti);
68155+ struct task_struct *task);
68156 extern void debug_mutex_unlock(struct mutex *lock);
68157 extern void debug_mutex_init(struct mutex *lock, const char *name,
68158 struct lock_class_key *key);
68159diff --git a/kernel/mutex.c b/kernel/mutex.c
68160index a307cc9..27fd2e9 100644
68161--- a/kernel/mutex.c
68162+++ b/kernel/mutex.c
68163@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68164 spin_lock_mutex(&lock->wait_lock, flags);
68165
68166 debug_mutex_lock_common(lock, &waiter);
68167- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
68168+ debug_mutex_add_waiter(lock, &waiter, task);
68169
68170 /* add waiting tasks to the end of the waitqueue (FIFO): */
68171 list_add_tail(&waiter.list, &lock->wait_list);
68172@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68173 * TASK_UNINTERRUPTIBLE case.)
68174 */
68175 if (unlikely(signal_pending_state(state, task))) {
68176- mutex_remove_waiter(lock, &waiter,
68177- task_thread_info(task));
68178+ mutex_remove_waiter(lock, &waiter, task);
68179 mutex_release(&lock->dep_map, 1, ip);
68180 spin_unlock_mutex(&lock->wait_lock, flags);
68181
68182@@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68183 done:
68184 lock_acquired(&lock->dep_map, ip);
68185 /* got the lock - rejoice! */
68186- mutex_remove_waiter(lock, &waiter, current_thread_info());
68187+ mutex_remove_waiter(lock, &waiter, task);
68188 mutex_set_owner(lock);
68189
68190 /* set it to 0 if there are no waiters left: */
68191diff --git a/kernel/panic.c b/kernel/panic.c
68192index d2a5f4e..5edc1d9 100644
68193--- a/kernel/panic.c
68194+++ b/kernel/panic.c
68195@@ -75,6 +75,14 @@ void panic(const char *fmt, ...)
68196 int state = 0;
68197
68198 /*
68199+ * Disable local interrupts. This will prevent panic_smp_self_stop
68200+ * from deadlocking the first cpu that invokes the panic, since
68201+ * there is nothing to prevent an interrupt handler (that runs
68202+ * after the panic_lock is acquired) from invoking panic again.
68203+ */
68204+ local_irq_disable();
68205+
68206+ /*
68207 * It's possible to come here directly from a panic-assertion and
68208 * not have preempt disabled. Some functions called from here want
68209 * preempt to be disabled. No point enabling it later though...
68210@@ -402,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
68211 const char *board;
68212
68213 printk(KERN_WARNING "------------[ cut here ]------------\n");
68214- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
68215+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
68216 board = dmi_get_system_info(DMI_PRODUCT_NAME);
68217 if (board)
68218 printk(KERN_WARNING "Hardware name: %s\n", board);
68219@@ -457,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
68220 */
68221 void __stack_chk_fail(void)
68222 {
68223- panic("stack-protector: Kernel stack is corrupted in: %p\n",
68224+ dump_stack();
68225+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
68226 __builtin_return_address(0));
68227 }
68228 EXPORT_SYMBOL(__stack_chk_fail);
68229diff --git a/kernel/pid.c b/kernel/pid.c
68230index e86b291a..e8b0fb5 100644
68231--- a/kernel/pid.c
68232+++ b/kernel/pid.c
68233@@ -33,6 +33,7 @@
68234 #include <linux/rculist.h>
68235 #include <linux/bootmem.h>
68236 #include <linux/hash.h>
68237+#include <linux/security.h>
68238 #include <linux/pid_namespace.h>
68239 #include <linux/init_task.h>
68240 #include <linux/syscalls.h>
68241@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
68242
68243 int pid_max = PID_MAX_DEFAULT;
68244
68245-#define RESERVED_PIDS 300
68246+#define RESERVED_PIDS 500
68247
68248 int pid_max_min = RESERVED_PIDS + 1;
68249 int pid_max_max = PID_MAX_LIMIT;
68250@@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
68251 */
68252 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
68253 {
68254+ struct task_struct *task;
68255+
68256 rcu_lockdep_assert(rcu_read_lock_held(),
68257 "find_task_by_pid_ns() needs rcu_read_lock()"
68258 " protection");
68259- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68260+
68261+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68262+
68263+ if (gr_pid_is_chrooted(task))
68264+ return NULL;
68265+
68266+ return task;
68267 }
68268
68269 struct task_struct *find_task_by_vpid(pid_t vnr)
68270@@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
68271 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
68272 }
68273
68274+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
68275+{
68276+ rcu_lockdep_assert(rcu_read_lock_held(),
68277+ "find_task_by_pid_ns() needs rcu_read_lock()"
68278+ " protection");
68279+ return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
68280+}
68281+
68282 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
68283 {
68284 struct pid *pid;
68285diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
68286index 125cb67..a4d1c30 100644
68287--- a/kernel/posix-cpu-timers.c
68288+++ b/kernel/posix-cpu-timers.c
68289@@ -6,6 +6,7 @@
68290 #include <linux/posix-timers.h>
68291 #include <linux/errno.h>
68292 #include <linux/math64.h>
68293+#include <linux/security.h>
68294 #include <asm/uaccess.h>
68295 #include <linux/kernel_stat.h>
68296 #include <trace/events/timer.h>
68297@@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
68298
68299 static __init int init_posix_cpu_timers(void)
68300 {
68301- struct k_clock process = {
68302+ static struct k_clock process = {
68303 .clock_getres = process_cpu_clock_getres,
68304 .clock_get = process_cpu_clock_get,
68305 .timer_create = process_cpu_timer_create,
68306 .nsleep = process_cpu_nsleep,
68307 .nsleep_restart = process_cpu_nsleep_restart,
68308 };
68309- struct k_clock thread = {
68310+ static struct k_clock thread = {
68311 .clock_getres = thread_cpu_clock_getres,
68312 .clock_get = thread_cpu_clock_get,
68313 .timer_create = thread_cpu_timer_create,
68314diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
68315index 69185ae..cc2847a 100644
68316--- a/kernel/posix-timers.c
68317+++ b/kernel/posix-timers.c
68318@@ -43,6 +43,7 @@
68319 #include <linux/idr.h>
68320 #include <linux/posix-clock.h>
68321 #include <linux/posix-timers.h>
68322+#include <linux/grsecurity.h>
68323 #include <linux/syscalls.h>
68324 #include <linux/wait.h>
68325 #include <linux/workqueue.h>
68326@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
68327 * which we beg off on and pass to do_sys_settimeofday().
68328 */
68329
68330-static struct k_clock posix_clocks[MAX_CLOCKS];
68331+static struct k_clock *posix_clocks[MAX_CLOCKS];
68332
68333 /*
68334 * These ones are defined below.
68335@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
68336 */
68337 static __init int init_posix_timers(void)
68338 {
68339- struct k_clock clock_realtime = {
68340+ static struct k_clock clock_realtime = {
68341 .clock_getres = hrtimer_get_res,
68342 .clock_get = posix_clock_realtime_get,
68343 .clock_set = posix_clock_realtime_set,
68344@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
68345 .timer_get = common_timer_get,
68346 .timer_del = common_timer_del,
68347 };
68348- struct k_clock clock_monotonic = {
68349+ static struct k_clock clock_monotonic = {
68350 .clock_getres = hrtimer_get_res,
68351 .clock_get = posix_ktime_get_ts,
68352 .nsleep = common_nsleep,
68353@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
68354 .timer_get = common_timer_get,
68355 .timer_del = common_timer_del,
68356 };
68357- struct k_clock clock_monotonic_raw = {
68358+ static struct k_clock clock_monotonic_raw = {
68359 .clock_getres = hrtimer_get_res,
68360 .clock_get = posix_get_monotonic_raw,
68361 };
68362- struct k_clock clock_realtime_coarse = {
68363+ static struct k_clock clock_realtime_coarse = {
68364 .clock_getres = posix_get_coarse_res,
68365 .clock_get = posix_get_realtime_coarse,
68366 };
68367- struct k_clock clock_monotonic_coarse = {
68368+ static struct k_clock clock_monotonic_coarse = {
68369 .clock_getres = posix_get_coarse_res,
68370 .clock_get = posix_get_monotonic_coarse,
68371 };
68372- struct k_clock clock_boottime = {
68373+ static struct k_clock clock_boottime = {
68374 .clock_getres = hrtimer_get_res,
68375 .clock_get = posix_get_boottime,
68376 .nsleep = common_nsleep,
68377@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
68378 return;
68379 }
68380
68381- posix_clocks[clock_id] = *new_clock;
68382+ posix_clocks[clock_id] = new_clock;
68383 }
68384 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
68385
68386@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
68387 return (id & CLOCKFD_MASK) == CLOCKFD ?
68388 &clock_posix_dynamic : &clock_posix_cpu;
68389
68390- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
68391+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
68392 return NULL;
68393- return &posix_clocks[id];
68394+ return posix_clocks[id];
68395 }
68396
68397 static int common_timer_create(struct k_itimer *new_timer)
68398@@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
68399 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
68400 return -EFAULT;
68401
68402+ /* only the CLOCK_REALTIME clock can be set, all other clocks
68403+ have their clock_set fptr set to a nosettime dummy function
68404+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
68405+ call common_clock_set, which calls do_sys_settimeofday, which
68406+ we hook
68407+ */
68408+
68409 return kc->clock_set(which_clock, &new_tp);
68410 }
68411
68412diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
68413index d523593..68197a4 100644
68414--- a/kernel/power/poweroff.c
68415+++ b/kernel/power/poweroff.c
68416@@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
68417 .enable_mask = SYSRQ_ENABLE_BOOT,
68418 };
68419
68420-static int pm_sysrq_init(void)
68421+static int __init pm_sysrq_init(void)
68422 {
68423 register_sysrq_key('o', &sysrq_poweroff_op);
68424 return 0;
68425diff --git a/kernel/power/process.c b/kernel/power/process.c
68426index 19db29f..33b52b6 100644
68427--- a/kernel/power/process.c
68428+++ b/kernel/power/process.c
68429@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
68430 u64 elapsed_csecs64;
68431 unsigned int elapsed_csecs;
68432 bool wakeup = false;
68433+ bool timedout = false;
68434
68435 do_gettimeofday(&start);
68436
68437@@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
68438
68439 while (true) {
68440 todo = 0;
68441+ if (time_after(jiffies, end_time))
68442+ timedout = true;
68443 read_lock(&tasklist_lock);
68444 do_each_thread(g, p) {
68445 if (p == current || !freeze_task(p))
68446@@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
68447 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
68448 * transition can't race with task state testing here.
68449 */
68450- if (!task_is_stopped_or_traced(p) &&
68451- !freezer_should_skip(p))
68452+ if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
68453 todo++;
68454+ if (timedout) {
68455+ printk(KERN_ERR "Task refusing to freeze:\n");
68456+ sched_show_task(p);
68457+ }
68458+ }
68459 } while_each_thread(g, p);
68460 read_unlock(&tasklist_lock);
68461
68462@@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
68463 todo += wq_busy;
68464 }
68465
68466- if (!todo || time_after(jiffies, end_time))
68467+ if (!todo || timedout)
68468 break;
68469
68470 if (pm_wakeup_pending()) {
68471diff --git a/kernel/printk.c b/kernel/printk.c
68472index 146827f..a501fec 100644
68473--- a/kernel/printk.c
68474+++ b/kernel/printk.c
68475@@ -782,6 +782,11 @@ static int check_syslog_permissions(int type, bool from_file)
68476 if (from_file && type != SYSLOG_ACTION_OPEN)
68477 return 0;
68478
68479+#ifdef CONFIG_GRKERNSEC_DMESG
68480+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
68481+ return -EPERM;
68482+#endif
68483+
68484 if (syslog_action_restricted(type)) {
68485 if (capable(CAP_SYSLOG))
68486 return 0;
68487diff --git a/kernel/profile.c b/kernel/profile.c
68488index 76b8e77..a2930e8 100644
68489--- a/kernel/profile.c
68490+++ b/kernel/profile.c
68491@@ -39,7 +39,7 @@ struct profile_hit {
68492 /* Oprofile timer tick hook */
68493 static int (*timer_hook)(struct pt_regs *) __read_mostly;
68494
68495-static atomic_t *prof_buffer;
68496+static atomic_unchecked_t *prof_buffer;
68497 static unsigned long prof_len, prof_shift;
68498
68499 int prof_on __read_mostly;
68500@@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
68501 hits[i].pc = 0;
68502 continue;
68503 }
68504- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
68505+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
68506 hits[i].hits = hits[i].pc = 0;
68507 }
68508 }
68509@@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
68510 * Add the current hit(s) and flush the write-queue out
68511 * to the global buffer:
68512 */
68513- atomic_add(nr_hits, &prof_buffer[pc]);
68514+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
68515 for (i = 0; i < NR_PROFILE_HIT; ++i) {
68516- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
68517+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
68518 hits[i].pc = hits[i].hits = 0;
68519 }
68520 out:
68521@@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
68522 {
68523 unsigned long pc;
68524 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
68525- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68526+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68527 }
68528 #endif /* !CONFIG_SMP */
68529
68530@@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
68531 return -EFAULT;
68532 buf++; p++; count--; read++;
68533 }
68534- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
68535+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
68536 if (copy_to_user(buf, (void *)pnt, count))
68537 return -EFAULT;
68538 read += count;
68539@@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
68540 }
68541 #endif
68542 profile_discard_flip_buffers();
68543- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
68544+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
68545 return count;
68546 }
68547
68548diff --git a/kernel/ptrace.c b/kernel/ptrace.c
68549index a232bb5..2a65ef9 100644
68550--- a/kernel/ptrace.c
68551+++ b/kernel/ptrace.c
68552@@ -279,7 +279,7 @@ static int ptrace_attach(struct task_struct *task, long request,
68553
68554 if (seize)
68555 flags |= PT_SEIZED;
68556- if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
68557+ if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
68558 flags |= PT_PTRACE_CAP;
68559 task->ptrace = flags;
68560
68561@@ -486,7 +486,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
68562 break;
68563 return -EIO;
68564 }
68565- if (copy_to_user(dst, buf, retval))
68566+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
68567 return -EFAULT;
68568 copied += retval;
68569 src += retval;
68570@@ -671,7 +671,7 @@ int ptrace_request(struct task_struct *child, long request,
68571 bool seized = child->ptrace & PT_SEIZED;
68572 int ret = -EIO;
68573 siginfo_t siginfo, *si;
68574- void __user *datavp = (void __user *) data;
68575+ void __user *datavp = (__force void __user *) data;
68576 unsigned long __user *datalp = datavp;
68577 unsigned long flags;
68578
68579@@ -873,14 +873,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
68580 goto out;
68581 }
68582
68583+ if (gr_handle_ptrace(child, request)) {
68584+ ret = -EPERM;
68585+ goto out_put_task_struct;
68586+ }
68587+
68588 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68589 ret = ptrace_attach(child, request, addr, data);
68590 /*
68591 * Some architectures need to do book-keeping after
68592 * a ptrace attach.
68593 */
68594- if (!ret)
68595+ if (!ret) {
68596 arch_ptrace_attach(child);
68597+ gr_audit_ptrace(child);
68598+ }
68599 goto out_put_task_struct;
68600 }
68601
68602@@ -906,7 +913,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
68603 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
68604 if (copied != sizeof(tmp))
68605 return -EIO;
68606- return put_user(tmp, (unsigned long __user *)data);
68607+ return put_user(tmp, (__force unsigned long __user *)data);
68608 }
68609
68610 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
68611@@ -1016,14 +1023,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
68612 goto out;
68613 }
68614
68615+ if (gr_handle_ptrace(child, request)) {
68616+ ret = -EPERM;
68617+ goto out_put_task_struct;
68618+ }
68619+
68620 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68621 ret = ptrace_attach(child, request, addr, data);
68622 /*
68623 * Some architectures need to do book-keeping after
68624 * a ptrace attach.
68625 */
68626- if (!ret)
68627+ if (!ret) {
68628 arch_ptrace_attach(child);
68629+ gr_audit_ptrace(child);
68630+ }
68631 goto out_put_task_struct;
68632 }
68633
68634diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
68635index 37a5444..eec170a 100644
68636--- a/kernel/rcutiny.c
68637+++ b/kernel/rcutiny.c
68638@@ -46,7 +46,7 @@
68639 struct rcu_ctrlblk;
68640 static void invoke_rcu_callbacks(void);
68641 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
68642-static void rcu_process_callbacks(struct softirq_action *unused);
68643+static void rcu_process_callbacks(void);
68644 static void __call_rcu(struct rcu_head *head,
68645 void (*func)(struct rcu_head *rcu),
68646 struct rcu_ctrlblk *rcp);
68647@@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
68648 rcu_is_callbacks_kthread()));
68649 }
68650
68651-static void rcu_process_callbacks(struct softirq_action *unused)
68652+static void rcu_process_callbacks(void)
68653 {
68654 __rcu_process_callbacks(&rcu_sched_ctrlblk);
68655 __rcu_process_callbacks(&rcu_bh_ctrlblk);
68656diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
68657index fc31a2d..be2ec04 100644
68658--- a/kernel/rcutiny_plugin.h
68659+++ b/kernel/rcutiny_plugin.h
68660@@ -939,7 +939,7 @@ static int rcu_kthread(void *arg)
68661 have_rcu_kthread_work = morework;
68662 local_irq_restore(flags);
68663 if (work)
68664- rcu_process_callbacks(NULL);
68665+ rcu_process_callbacks();
68666 schedule_timeout_interruptible(1); /* Leave CPU for others. */
68667 }
68668
68669diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
68670index e66b34a..4b8b626 100644
68671--- a/kernel/rcutorture.c
68672+++ b/kernel/rcutorture.c
68673@@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
68674 { 0 };
68675 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
68676 { 0 };
68677-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68678-static atomic_t n_rcu_torture_alloc;
68679-static atomic_t n_rcu_torture_alloc_fail;
68680-static atomic_t n_rcu_torture_free;
68681-static atomic_t n_rcu_torture_mberror;
68682-static atomic_t n_rcu_torture_error;
68683+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68684+static atomic_unchecked_t n_rcu_torture_alloc;
68685+static atomic_unchecked_t n_rcu_torture_alloc_fail;
68686+static atomic_unchecked_t n_rcu_torture_free;
68687+static atomic_unchecked_t n_rcu_torture_mberror;
68688+static atomic_unchecked_t n_rcu_torture_error;
68689 static long n_rcu_torture_barrier_error;
68690 static long n_rcu_torture_boost_ktrerror;
68691 static long n_rcu_torture_boost_rterror;
68692@@ -265,11 +265,11 @@ rcu_torture_alloc(void)
68693
68694 spin_lock_bh(&rcu_torture_lock);
68695 if (list_empty(&rcu_torture_freelist)) {
68696- atomic_inc(&n_rcu_torture_alloc_fail);
68697+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
68698 spin_unlock_bh(&rcu_torture_lock);
68699 return NULL;
68700 }
68701- atomic_inc(&n_rcu_torture_alloc);
68702+ atomic_inc_unchecked(&n_rcu_torture_alloc);
68703 p = rcu_torture_freelist.next;
68704 list_del_init(p);
68705 spin_unlock_bh(&rcu_torture_lock);
68706@@ -282,7 +282,7 @@ rcu_torture_alloc(void)
68707 static void
68708 rcu_torture_free(struct rcu_torture *p)
68709 {
68710- atomic_inc(&n_rcu_torture_free);
68711+ atomic_inc_unchecked(&n_rcu_torture_free);
68712 spin_lock_bh(&rcu_torture_lock);
68713 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
68714 spin_unlock_bh(&rcu_torture_lock);
68715@@ -403,7 +403,7 @@ rcu_torture_cb(struct rcu_head *p)
68716 i = rp->rtort_pipe_count;
68717 if (i > RCU_TORTURE_PIPE_LEN)
68718 i = RCU_TORTURE_PIPE_LEN;
68719- atomic_inc(&rcu_torture_wcount[i]);
68720+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
68721 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68722 rp->rtort_mbtest = 0;
68723 rcu_torture_free(rp);
68724@@ -451,7 +451,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
68725 i = rp->rtort_pipe_count;
68726 if (i > RCU_TORTURE_PIPE_LEN)
68727 i = RCU_TORTURE_PIPE_LEN;
68728- atomic_inc(&rcu_torture_wcount[i]);
68729+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
68730 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68731 rp->rtort_mbtest = 0;
68732 list_del(&rp->rtort_free);
68733@@ -983,7 +983,7 @@ rcu_torture_writer(void *arg)
68734 i = old_rp->rtort_pipe_count;
68735 if (i > RCU_TORTURE_PIPE_LEN)
68736 i = RCU_TORTURE_PIPE_LEN;
68737- atomic_inc(&rcu_torture_wcount[i]);
68738+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
68739 old_rp->rtort_pipe_count++;
68740 cur_ops->deferred_free(old_rp);
68741 }
68742@@ -1064,7 +1064,7 @@ static void rcu_torture_timer(unsigned long unused)
68743 }
68744 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
68745 if (p->rtort_mbtest == 0)
68746- atomic_inc(&n_rcu_torture_mberror);
68747+ atomic_inc_unchecked(&n_rcu_torture_mberror);
68748 spin_lock(&rand_lock);
68749 cur_ops->read_delay(&rand);
68750 n_rcu_torture_timers++;
68751@@ -1128,7 +1128,7 @@ rcu_torture_reader(void *arg)
68752 }
68753 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
68754 if (p->rtort_mbtest == 0)
68755- atomic_inc(&n_rcu_torture_mberror);
68756+ atomic_inc_unchecked(&n_rcu_torture_mberror);
68757 cur_ops->read_delay(&rand);
68758 preempt_disable();
68759 pipe_count = p->rtort_pipe_count;
68760@@ -1191,10 +1191,10 @@ rcu_torture_printk(char *page)
68761 rcu_torture_current,
68762 rcu_torture_current_version,
68763 list_empty(&rcu_torture_freelist),
68764- atomic_read(&n_rcu_torture_alloc),
68765- atomic_read(&n_rcu_torture_alloc_fail),
68766- atomic_read(&n_rcu_torture_free),
68767- atomic_read(&n_rcu_torture_mberror),
68768+ atomic_read_unchecked(&n_rcu_torture_alloc),
68769+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
68770+ atomic_read_unchecked(&n_rcu_torture_free),
68771+ atomic_read_unchecked(&n_rcu_torture_mberror),
68772 n_rcu_torture_boost_ktrerror,
68773 n_rcu_torture_boost_rterror,
68774 n_rcu_torture_boost_failure,
68775@@ -1208,14 +1208,14 @@ rcu_torture_printk(char *page)
68776 n_barrier_attempts,
68777 n_rcu_torture_barrier_error);
68778 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
68779- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
68780+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
68781 n_rcu_torture_barrier_error != 0 ||
68782 n_rcu_torture_boost_ktrerror != 0 ||
68783 n_rcu_torture_boost_rterror != 0 ||
68784 n_rcu_torture_boost_failure != 0 ||
68785 i > 1) {
68786 cnt += sprintf(&page[cnt], "!!! ");
68787- atomic_inc(&n_rcu_torture_error);
68788+ atomic_inc_unchecked(&n_rcu_torture_error);
68789 WARN_ON_ONCE(1);
68790 }
68791 cnt += sprintf(&page[cnt], "Reader Pipe: ");
68792@@ -1229,7 +1229,7 @@ rcu_torture_printk(char *page)
68793 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
68794 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68795 cnt += sprintf(&page[cnt], " %d",
68796- atomic_read(&rcu_torture_wcount[i]));
68797+ atomic_read_unchecked(&rcu_torture_wcount[i]));
68798 }
68799 cnt += sprintf(&page[cnt], "\n");
68800 if (cur_ops->stats)
68801@@ -1888,7 +1888,7 @@ rcu_torture_cleanup(void)
68802
68803 if (cur_ops->cleanup)
68804 cur_ops->cleanup();
68805- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
68806+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
68807 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
68808 else if (n_online_successes != n_online_attempts ||
68809 n_offline_successes != n_offline_attempts)
68810@@ -1958,18 +1958,18 @@ rcu_torture_init(void)
68811
68812 rcu_torture_current = NULL;
68813 rcu_torture_current_version = 0;
68814- atomic_set(&n_rcu_torture_alloc, 0);
68815- atomic_set(&n_rcu_torture_alloc_fail, 0);
68816- atomic_set(&n_rcu_torture_free, 0);
68817- atomic_set(&n_rcu_torture_mberror, 0);
68818- atomic_set(&n_rcu_torture_error, 0);
68819+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
68820+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
68821+ atomic_set_unchecked(&n_rcu_torture_free, 0);
68822+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
68823+ atomic_set_unchecked(&n_rcu_torture_error, 0);
68824 n_rcu_torture_barrier_error = 0;
68825 n_rcu_torture_boost_ktrerror = 0;
68826 n_rcu_torture_boost_rterror = 0;
68827 n_rcu_torture_boost_failure = 0;
68828 n_rcu_torture_boosts = 0;
68829 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
68830- atomic_set(&rcu_torture_wcount[i], 0);
68831+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
68832 for_each_possible_cpu(cpu) {
68833 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68834 per_cpu(rcu_torture_count, cpu)[i] = 0;
68835diff --git a/kernel/rcutree.c b/kernel/rcutree.c
68836index 4b97bba..b92c9d2 100644
68837--- a/kernel/rcutree.c
68838+++ b/kernel/rcutree.c
68839@@ -366,9 +366,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
68840 rcu_prepare_for_idle(smp_processor_id());
68841 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68842 smp_mb__before_atomic_inc(); /* See above. */
68843- atomic_inc(&rdtp->dynticks);
68844+ atomic_inc_unchecked(&rdtp->dynticks);
68845 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
68846- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68847+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68848
68849 /*
68850 * The idle task is not permitted to enter the idle loop while
68851@@ -457,10 +457,10 @@ void rcu_irq_exit(void)
68852 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
68853 {
68854 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
68855- atomic_inc(&rdtp->dynticks);
68856+ atomic_inc_unchecked(&rdtp->dynticks);
68857 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68858 smp_mb__after_atomic_inc(); /* See above. */
68859- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68860+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68861 rcu_cleanup_after_idle(smp_processor_id());
68862 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
68863 if (!is_idle_task(current)) {
68864@@ -554,14 +554,14 @@ void rcu_nmi_enter(void)
68865 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
68866
68867 if (rdtp->dynticks_nmi_nesting == 0 &&
68868- (atomic_read(&rdtp->dynticks) & 0x1))
68869+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
68870 return;
68871 rdtp->dynticks_nmi_nesting++;
68872 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
68873- atomic_inc(&rdtp->dynticks);
68874+ atomic_inc_unchecked(&rdtp->dynticks);
68875 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68876 smp_mb__after_atomic_inc(); /* See above. */
68877- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68878+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68879 }
68880
68881 /**
68882@@ -580,9 +580,9 @@ void rcu_nmi_exit(void)
68883 return;
68884 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68885 smp_mb__before_atomic_inc(); /* See above. */
68886- atomic_inc(&rdtp->dynticks);
68887+ atomic_inc_unchecked(&rdtp->dynticks);
68888 smp_mb__after_atomic_inc(); /* Force delay to next write. */
68889- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68890+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68891 }
68892
68893 #ifdef CONFIG_PROVE_RCU
68894@@ -598,7 +598,7 @@ int rcu_is_cpu_idle(void)
68895 int ret;
68896
68897 preempt_disable();
68898- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
68899+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
68900 preempt_enable();
68901 return ret;
68902 }
68903@@ -668,7 +668,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
68904 */
68905 static int dyntick_save_progress_counter(struct rcu_data *rdp)
68906 {
68907- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
68908+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68909 return (rdp->dynticks_snap & 0x1) == 0;
68910 }
68911
68912@@ -683,7 +683,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
68913 unsigned int curr;
68914 unsigned int snap;
68915
68916- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
68917+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68918 snap = (unsigned int)rdp->dynticks_snap;
68919
68920 /*
68921@@ -713,10 +713,10 @@ static int jiffies_till_stall_check(void)
68922 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
68923 */
68924 if (till_stall_check < 3) {
68925- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
68926+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
68927 till_stall_check = 3;
68928 } else if (till_stall_check > 300) {
68929- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
68930+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
68931 till_stall_check = 300;
68932 }
68933 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
68934@@ -1824,7 +1824,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
68935 /*
68936 * Do RCU core processing for the current CPU.
68937 */
68938-static void rcu_process_callbacks(struct softirq_action *unused)
68939+static void rcu_process_callbacks(void)
68940 {
68941 trace_rcu_utilization("Start RCU core");
68942 __rcu_process_callbacks(&rcu_sched_state,
68943@@ -2042,8 +2042,8 @@ void synchronize_rcu_bh(void)
68944 }
68945 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
68946
68947-static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
68948-static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
68949+static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
68950+static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
68951
68952 static int synchronize_sched_expedited_cpu_stop(void *data)
68953 {
68954@@ -2104,7 +2104,7 @@ void synchronize_sched_expedited(void)
68955 int firstsnap, s, snap, trycount = 0;
68956
68957 /* Note that atomic_inc_return() implies full memory barrier. */
68958- firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
68959+ firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
68960 get_online_cpus();
68961 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
68962
68963@@ -2126,7 +2126,7 @@ void synchronize_sched_expedited(void)
68964 }
68965
68966 /* Check to see if someone else did our work for us. */
68967- s = atomic_read(&sync_sched_expedited_done);
68968+ s = atomic_read_unchecked(&sync_sched_expedited_done);
68969 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
68970 smp_mb(); /* ensure test happens before caller kfree */
68971 return;
68972@@ -2141,7 +2141,7 @@ void synchronize_sched_expedited(void)
68973 * grace period works for us.
68974 */
68975 get_online_cpus();
68976- snap = atomic_read(&sync_sched_expedited_started);
68977+ snap = atomic_read_unchecked(&sync_sched_expedited_started);
68978 smp_mb(); /* ensure read is before try_stop_cpus(). */
68979 }
68980
68981@@ -2152,12 +2152,12 @@ void synchronize_sched_expedited(void)
68982 * than we did beat us to the punch.
68983 */
68984 do {
68985- s = atomic_read(&sync_sched_expedited_done);
68986+ s = atomic_read_unchecked(&sync_sched_expedited_done);
68987 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
68988 smp_mb(); /* ensure test happens before caller kfree */
68989 break;
68990 }
68991- } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
68992+ } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
68993
68994 put_online_cpus();
68995 }
68996@@ -2421,7 +2421,7 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
68997 rdp->qlen = 0;
68998 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
68999 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
69000- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
69001+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
69002 rdp->cpu = cpu;
69003 rdp->rsp = rsp;
69004 raw_spin_unlock_irqrestore(&rnp->lock, flags);
69005@@ -2449,8 +2449,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
69006 rdp->n_force_qs_snap = rsp->n_force_qs;
69007 rdp->blimit = blimit;
69008 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
69009- atomic_set(&rdp->dynticks->dynticks,
69010- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
69011+ atomic_set_unchecked(&rdp->dynticks->dynticks,
69012+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
69013 rcu_prepare_for_idle_init(cpu);
69014 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
69015
69016diff --git a/kernel/rcutree.h b/kernel/rcutree.h
69017index 19b61ac..5c60a94 100644
69018--- a/kernel/rcutree.h
69019+++ b/kernel/rcutree.h
69020@@ -83,7 +83,7 @@ struct rcu_dynticks {
69021 long long dynticks_nesting; /* Track irq/process nesting level. */
69022 /* Process level is worth LLONG_MAX/2. */
69023 int dynticks_nmi_nesting; /* Track NMI nesting level. */
69024- atomic_t dynticks; /* Even value for idle, else odd. */
69025+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
69026 #ifdef CONFIG_RCU_FAST_NO_HZ
69027 int dyntick_drain; /* Prepare-for-idle state variable. */
69028 unsigned long dyntick_holdoff;
69029diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
69030index 3e48994..d94f03a 100644
69031--- a/kernel/rcutree_plugin.h
69032+++ b/kernel/rcutree_plugin.h
69033@@ -909,7 +909,7 @@ void synchronize_rcu_expedited(void)
69034
69035 /* Clean up and exit. */
69036 smp_mb(); /* ensure expedited GP seen before counter increment. */
69037- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
69038+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
69039 unlock_mb_ret:
69040 mutex_unlock(&sync_rcu_preempt_exp_mutex);
69041 mb_ret:
69042diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
69043index d4bc16d..c234a5c 100644
69044--- a/kernel/rcutree_trace.c
69045+++ b/kernel/rcutree_trace.c
69046@@ -68,7 +68,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
69047 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69048 rdp->qs_pending);
69049 seq_printf(m, " dt=%d/%llx/%d df=%lu",
69050- atomic_read(&rdp->dynticks->dynticks),
69051+ atomic_read_unchecked(&rdp->dynticks->dynticks),
69052 rdp->dynticks->dynticks_nesting,
69053 rdp->dynticks->dynticks_nmi_nesting,
69054 rdp->dynticks_fqs);
69055@@ -140,7 +140,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
69056 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69057 rdp->qs_pending);
69058 seq_printf(m, ",%d,%llx,%d,%lu",
69059- atomic_read(&rdp->dynticks->dynticks),
69060+ atomic_read_unchecked(&rdp->dynticks->dynticks),
69061 rdp->dynticks->dynticks_nesting,
69062 rdp->dynticks->dynticks_nmi_nesting,
69063 rdp->dynticks_fqs);
69064diff --git a/kernel/resource.c b/kernel/resource.c
69065index e1d2b8e..24820bb 100644
69066--- a/kernel/resource.c
69067+++ b/kernel/resource.c
69068@@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
69069
69070 static int __init ioresources_init(void)
69071 {
69072+#ifdef CONFIG_GRKERNSEC_PROC_ADD
69073+#ifdef CONFIG_GRKERNSEC_PROC_USER
69074+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
69075+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
69076+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69077+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
69078+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
69079+#endif
69080+#else
69081 proc_create("ioports", 0, NULL, &proc_ioports_operations);
69082 proc_create("iomem", 0, NULL, &proc_iomem_operations);
69083+#endif
69084 return 0;
69085 }
69086 __initcall(ioresources_init);
69087diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
69088index 98ec494..4241d6d 100644
69089--- a/kernel/rtmutex-tester.c
69090+++ b/kernel/rtmutex-tester.c
69091@@ -20,7 +20,7 @@
69092 #define MAX_RT_TEST_MUTEXES 8
69093
69094 static spinlock_t rttest_lock;
69095-static atomic_t rttest_event;
69096+static atomic_unchecked_t rttest_event;
69097
69098 struct test_thread_data {
69099 int opcode;
69100@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69101
69102 case RTTEST_LOCKCONT:
69103 td->mutexes[td->opdata] = 1;
69104- td->event = atomic_add_return(1, &rttest_event);
69105+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69106 return 0;
69107
69108 case RTTEST_RESET:
69109@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69110 return 0;
69111
69112 case RTTEST_RESETEVENT:
69113- atomic_set(&rttest_event, 0);
69114+ atomic_set_unchecked(&rttest_event, 0);
69115 return 0;
69116
69117 default:
69118@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69119 return ret;
69120
69121 td->mutexes[id] = 1;
69122- td->event = atomic_add_return(1, &rttest_event);
69123+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69124 rt_mutex_lock(&mutexes[id]);
69125- td->event = atomic_add_return(1, &rttest_event);
69126+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69127 td->mutexes[id] = 4;
69128 return 0;
69129
69130@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69131 return ret;
69132
69133 td->mutexes[id] = 1;
69134- td->event = atomic_add_return(1, &rttest_event);
69135+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69136 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
69137- td->event = atomic_add_return(1, &rttest_event);
69138+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69139 td->mutexes[id] = ret ? 0 : 4;
69140 return ret ? -EINTR : 0;
69141
69142@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69143 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
69144 return ret;
69145
69146- td->event = atomic_add_return(1, &rttest_event);
69147+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69148 rt_mutex_unlock(&mutexes[id]);
69149- td->event = atomic_add_return(1, &rttest_event);
69150+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69151 td->mutexes[id] = 0;
69152 return 0;
69153
69154@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69155 break;
69156
69157 td->mutexes[dat] = 2;
69158- td->event = atomic_add_return(1, &rttest_event);
69159+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69160 break;
69161
69162 default:
69163@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69164 return;
69165
69166 td->mutexes[dat] = 3;
69167- td->event = atomic_add_return(1, &rttest_event);
69168+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69169 break;
69170
69171 case RTTEST_LOCKNOWAIT:
69172@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69173 return;
69174
69175 td->mutexes[dat] = 1;
69176- td->event = atomic_add_return(1, &rttest_event);
69177+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69178 return;
69179
69180 default:
69181diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
69182index 0984a21..939f183 100644
69183--- a/kernel/sched/auto_group.c
69184+++ b/kernel/sched/auto_group.c
69185@@ -11,7 +11,7 @@
69186
69187 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
69188 static struct autogroup autogroup_default;
69189-static atomic_t autogroup_seq_nr;
69190+static atomic_unchecked_t autogroup_seq_nr;
69191
69192 void __init autogroup_init(struct task_struct *init_task)
69193 {
69194@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
69195
69196 kref_init(&ag->kref);
69197 init_rwsem(&ag->lock);
69198- ag->id = atomic_inc_return(&autogroup_seq_nr);
69199+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
69200 ag->tg = tg;
69201 #ifdef CONFIG_RT_GROUP_SCHED
69202 /*
69203diff --git a/kernel/sched/core.c b/kernel/sched/core.c
69204index 468bdd4..b941572 100644
69205--- a/kernel/sched/core.c
69206+++ b/kernel/sched/core.c
69207@@ -4097,6 +4097,8 @@ int can_nice(const struct task_struct *p, const int nice)
69208 /* convert nice value [19,-20] to rlimit style value [1,40] */
69209 int nice_rlim = 20 - nice;
69210
69211+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
69212+
69213 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
69214 capable(CAP_SYS_NICE));
69215 }
69216@@ -4130,7 +4132,8 @@ SYSCALL_DEFINE1(nice, int, increment)
69217 if (nice > 19)
69218 nice = 19;
69219
69220- if (increment < 0 && !can_nice(current, nice))
69221+ if (increment < 0 && (!can_nice(current, nice) ||
69222+ gr_handle_chroot_nice()))
69223 return -EPERM;
69224
69225 retval = security_task_setnice(current, nice);
69226@@ -4284,6 +4287,7 @@ recheck:
69227 unsigned long rlim_rtprio =
69228 task_rlimit(p, RLIMIT_RTPRIO);
69229
69230+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
69231 /* can't set/change the rt policy */
69232 if (policy != p->policy && !rlim_rtprio)
69233 return -EPERM;
69234diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
69235index c099cc6..06aec4f 100644
69236--- a/kernel/sched/fair.c
69237+++ b/kernel/sched/fair.c
69238@@ -4846,7 +4846,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
69239 * run_rebalance_domains is triggered when needed from the scheduler tick.
69240 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
69241 */
69242-static void run_rebalance_domains(struct softirq_action *h)
69243+static void run_rebalance_domains(void)
69244 {
69245 int this_cpu = smp_processor_id();
69246 struct rq *this_rq = cpu_rq(this_cpu);
69247diff --git a/kernel/signal.c b/kernel/signal.c
69248index 6771027..763e51e 100644
69249--- a/kernel/signal.c
69250+++ b/kernel/signal.c
69251@@ -48,12 +48,12 @@ static struct kmem_cache *sigqueue_cachep;
69252
69253 int print_fatal_signals __read_mostly;
69254
69255-static void __user *sig_handler(struct task_struct *t, int sig)
69256+static __sighandler_t sig_handler(struct task_struct *t, int sig)
69257 {
69258 return t->sighand->action[sig - 1].sa.sa_handler;
69259 }
69260
69261-static int sig_handler_ignored(void __user *handler, int sig)
69262+static int sig_handler_ignored(__sighandler_t handler, int sig)
69263 {
69264 /* Is it explicitly or implicitly ignored? */
69265 return handler == SIG_IGN ||
69266@@ -62,7 +62,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
69267
69268 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
69269 {
69270- void __user *handler;
69271+ __sighandler_t handler;
69272
69273 handler = sig_handler(t, sig);
69274
69275@@ -366,6 +366,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
69276 atomic_inc(&user->sigpending);
69277 rcu_read_unlock();
69278
69279+ if (!override_rlimit)
69280+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
69281+
69282 if (override_rlimit ||
69283 atomic_read(&user->sigpending) <=
69284 task_rlimit(t, RLIMIT_SIGPENDING)) {
69285@@ -490,7 +493,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
69286
69287 int unhandled_signal(struct task_struct *tsk, int sig)
69288 {
69289- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
69290+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
69291 if (is_global_init(tsk))
69292 return 1;
69293 if (handler != SIG_IGN && handler != SIG_DFL)
69294@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
69295 }
69296 }
69297
69298+ /* allow glibc communication via tgkill to other threads in our
69299+ thread group */
69300+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
69301+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
69302+ && gr_handle_signal(t, sig))
69303+ return -EPERM;
69304+
69305 return security_task_kill(t, info, sig, 0);
69306 }
69307
69308@@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69309 return send_signal(sig, info, p, 1);
69310 }
69311
69312-static int
69313+int
69314 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69315 {
69316 return send_signal(sig, info, t, 0);
69317@@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69318 unsigned long int flags;
69319 int ret, blocked, ignored;
69320 struct k_sigaction *action;
69321+ int is_unhandled = 0;
69322
69323 spin_lock_irqsave(&t->sighand->siglock, flags);
69324 action = &t->sighand->action[sig-1];
69325@@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69326 }
69327 if (action->sa.sa_handler == SIG_DFL)
69328 t->signal->flags &= ~SIGNAL_UNKILLABLE;
69329+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
69330+ is_unhandled = 1;
69331 ret = specific_send_sig_info(sig, info, t);
69332 spin_unlock_irqrestore(&t->sighand->siglock, flags);
69333
69334+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
69335+ normal operation */
69336+ if (is_unhandled) {
69337+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
69338+ gr_handle_crash(t, sig);
69339+ }
69340+
69341 return ret;
69342 }
69343
69344@@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69345 ret = check_kill_permission(sig, info, p);
69346 rcu_read_unlock();
69347
69348- if (!ret && sig)
69349+ if (!ret && sig) {
69350 ret = do_send_sig_info(sig, info, p, true);
69351+ if (!ret)
69352+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
69353+ }
69354
69355 return ret;
69356 }
69357@@ -2858,7 +2881,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
69358 int error = -ESRCH;
69359
69360 rcu_read_lock();
69361- p = find_task_by_vpid(pid);
69362+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69363+ /* allow glibc communication via tgkill to other threads in our
69364+ thread group */
69365+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
69366+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
69367+ p = find_task_by_vpid_unrestricted(pid);
69368+ else
69369+#endif
69370+ p = find_task_by_vpid(pid);
69371 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
69372 error = check_kill_permission(sig, info, p);
69373 /*
69374diff --git a/kernel/smp.c b/kernel/smp.c
69375index d0ae5b2..b87c5a8 100644
69376--- a/kernel/smp.c
69377+++ b/kernel/smp.c
69378@@ -582,22 +582,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
69379 }
69380 EXPORT_SYMBOL(smp_call_function);
69381
69382-void ipi_call_lock(void)
69383+void ipi_call_lock(void) __acquires(call_function.lock)
69384 {
69385 raw_spin_lock(&call_function.lock);
69386 }
69387
69388-void ipi_call_unlock(void)
69389+void ipi_call_unlock(void) __releases(call_function.lock)
69390 {
69391 raw_spin_unlock(&call_function.lock);
69392 }
69393
69394-void ipi_call_lock_irq(void)
69395+void ipi_call_lock_irq(void) __acquires(call_function.lock)
69396 {
69397 raw_spin_lock_irq(&call_function.lock);
69398 }
69399
69400-void ipi_call_unlock_irq(void)
69401+void ipi_call_unlock_irq(void) __releases(call_function.lock)
69402 {
69403 raw_spin_unlock_irq(&call_function.lock);
69404 }
69405diff --git a/kernel/softirq.c b/kernel/softirq.c
69406index 671f959..91c51cb 100644
69407--- a/kernel/softirq.c
69408+++ b/kernel/softirq.c
69409@@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
69410
69411 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
69412
69413-char *softirq_to_name[NR_SOFTIRQS] = {
69414+const char * const softirq_to_name[NR_SOFTIRQS] = {
69415 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
69416 "TASKLET", "SCHED", "HRTIMER", "RCU"
69417 };
69418@@ -235,7 +235,7 @@ restart:
69419 kstat_incr_softirqs_this_cpu(vec_nr);
69420
69421 trace_softirq_entry(vec_nr);
69422- h->action(h);
69423+ h->action();
69424 trace_softirq_exit(vec_nr);
69425 if (unlikely(prev_count != preempt_count())) {
69426 printk(KERN_ERR "huh, entered softirq %u %s %p"
69427@@ -381,9 +381,11 @@ void __raise_softirq_irqoff(unsigned int nr)
69428 or_softirq_pending(1UL << nr);
69429 }
69430
69431-void open_softirq(int nr, void (*action)(struct softirq_action *))
69432+void open_softirq(int nr, void (*action)(void))
69433 {
69434- softirq_vec[nr].action = action;
69435+ pax_open_kernel();
69436+ *(void **)&softirq_vec[nr].action = action;
69437+ pax_close_kernel();
69438 }
69439
69440 /*
69441@@ -437,7 +439,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
69442
69443 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
69444
69445-static void tasklet_action(struct softirq_action *a)
69446+static void tasklet_action(void)
69447 {
69448 struct tasklet_struct *list;
69449
69450@@ -472,7 +474,7 @@ static void tasklet_action(struct softirq_action *a)
69451 }
69452 }
69453
69454-static void tasklet_hi_action(struct softirq_action *a)
69455+static void tasklet_hi_action(void)
69456 {
69457 struct tasklet_struct *list;
69458
69459diff --git a/kernel/srcu.c b/kernel/srcu.c
69460index 2095be3..9a5b89d 100644
69461--- a/kernel/srcu.c
69462+++ b/kernel/srcu.c
69463@@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
69464 preempt_disable();
69465 idx = rcu_dereference_index_check(sp->completed,
69466 rcu_read_lock_sched_held()) & 0x1;
69467- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
69468+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
69469 smp_mb(); /* B */ /* Avoid leaking the critical section. */
69470- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
69471+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
69472 preempt_enable();
69473 return idx;
69474 }
69475@@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
69476 {
69477 preempt_disable();
69478 smp_mb(); /* C */ /* Avoid leaking the critical section. */
69479- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
69480+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
69481 preempt_enable();
69482 }
69483 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
69484diff --git a/kernel/sys.c b/kernel/sys.c
69485index 2d39a84..f778b49 100644
69486--- a/kernel/sys.c
69487+++ b/kernel/sys.c
69488@@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
69489 error = -EACCES;
69490 goto out;
69491 }
69492+
69493+ if (gr_handle_chroot_setpriority(p, niceval)) {
69494+ error = -EACCES;
69495+ goto out;
69496+ }
69497+
69498 no_nice = security_task_setnice(p, niceval);
69499 if (no_nice) {
69500 error = no_nice;
69501@@ -594,6 +600,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
69502 goto error;
69503 }
69504
69505+ if (gr_check_group_change(new->gid, new->egid, -1))
69506+ goto error;
69507+
69508 if (rgid != (gid_t) -1 ||
69509 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
69510 new->sgid = new->egid;
69511@@ -629,6 +638,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
69512 old = current_cred();
69513
69514 retval = -EPERM;
69515+
69516+ if (gr_check_group_change(kgid, kgid, kgid))
69517+ goto error;
69518+
69519 if (nsown_capable(CAP_SETGID))
69520 new->gid = new->egid = new->sgid = new->fsgid = kgid;
69521 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
69522@@ -646,7 +659,7 @@ error:
69523 /*
69524 * change the user struct in a credentials set to match the new UID
69525 */
69526-static int set_user(struct cred *new)
69527+int set_user(struct cred *new)
69528 {
69529 struct user_struct *new_user;
69530
69531@@ -726,6 +739,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
69532 goto error;
69533 }
69534
69535+ if (gr_check_user_change(new->uid, new->euid, -1))
69536+ goto error;
69537+
69538 if (!uid_eq(new->uid, old->uid)) {
69539 retval = set_user(new);
69540 if (retval < 0)
69541@@ -776,6 +792,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
69542 old = current_cred();
69543
69544 retval = -EPERM;
69545+
69546+ if (gr_check_crash_uid(kuid))
69547+ goto error;
69548+ if (gr_check_user_change(kuid, kuid, kuid))
69549+ goto error;
69550+
69551 if (nsown_capable(CAP_SETUID)) {
69552 new->suid = new->uid = kuid;
69553 if (!uid_eq(kuid, old->uid)) {
69554@@ -845,6 +867,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
69555 goto error;
69556 }
69557
69558+ if (gr_check_user_change(kruid, keuid, -1))
69559+ goto error;
69560+
69561 if (ruid != (uid_t) -1) {
69562 new->uid = kruid;
69563 if (!uid_eq(kruid, old->uid)) {
69564@@ -927,6 +952,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
69565 goto error;
69566 }
69567
69568+ if (gr_check_group_change(krgid, kegid, -1))
69569+ goto error;
69570+
69571 if (rgid != (gid_t) -1)
69572 new->gid = krgid;
69573 if (egid != (gid_t) -1)
69574@@ -980,6 +1008,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69575 if (!uid_valid(kuid))
69576 return old_fsuid;
69577
69578+ if (gr_check_user_change(-1, -1, kuid))
69579+ goto error;
69580+
69581 new = prepare_creds();
69582 if (!new)
69583 return old_fsuid;
69584@@ -994,6 +1025,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69585 }
69586 }
69587
69588+error:
69589 abort_creds(new);
69590 return old_fsuid;
69591
69592@@ -1026,12 +1058,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
69593 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
69594 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
69595 nsown_capable(CAP_SETGID)) {
69596+ if (gr_check_group_change(-1, -1, kgid))
69597+ goto error;
69598+
69599 if (!gid_eq(kgid, old->fsgid)) {
69600 new->fsgid = kgid;
69601 goto change_okay;
69602 }
69603 }
69604
69605+error:
69606 abort_creds(new);
69607 return old_fsgid;
69608
69609@@ -1283,7 +1319,10 @@ static int override_release(char __user *release, int len)
69610 }
69611 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
69612 snprintf(buf, len, "2.6.%u%s", v, rest);
69613- ret = copy_to_user(release, buf, len);
69614+ if (len > sizeof(buf))
69615+ ret = -EFAULT;
69616+ else
69617+ ret = copy_to_user(release, buf, len);
69618 }
69619 return ret;
69620 }
69621@@ -1337,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
69622 return -EFAULT;
69623
69624 down_read(&uts_sem);
69625- error = __copy_to_user(&name->sysname, &utsname()->sysname,
69626+ error = __copy_to_user(name->sysname, &utsname()->sysname,
69627 __OLD_UTS_LEN);
69628 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
69629- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
69630+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
69631 __OLD_UTS_LEN);
69632 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
69633- error |= __copy_to_user(&name->release, &utsname()->release,
69634+ error |= __copy_to_user(name->release, &utsname()->release,
69635 __OLD_UTS_LEN);
69636 error |= __put_user(0, name->release + __OLD_UTS_LEN);
69637- error |= __copy_to_user(&name->version, &utsname()->version,
69638+ error |= __copy_to_user(name->version, &utsname()->version,
69639 __OLD_UTS_LEN);
69640 error |= __put_user(0, name->version + __OLD_UTS_LEN);
69641- error |= __copy_to_user(&name->machine, &utsname()->machine,
69642+ error |= __copy_to_user(name->machine, &utsname()->machine,
69643 __OLD_UTS_LEN);
69644 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
69645 up_read(&uts_sem);
69646@@ -2024,7 +2063,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
69647 error = get_dumpable(me->mm);
69648 break;
69649 case PR_SET_DUMPABLE:
69650- if (arg2 < 0 || arg2 > 1) {
69651+ if (arg2 > 1) {
69652 error = -EINVAL;
69653 break;
69654 }
69655diff --git a/kernel/sysctl.c b/kernel/sysctl.c
69656index 4ab1187..33f4f2b 100644
69657--- a/kernel/sysctl.c
69658+++ b/kernel/sysctl.c
69659@@ -91,7 +91,6 @@
69660
69661
69662 #if defined(CONFIG_SYSCTL)
69663-
69664 /* External variables not in a header file. */
69665 extern int sysctl_overcommit_memory;
69666 extern int sysctl_overcommit_ratio;
69667@@ -169,10 +168,13 @@ static int proc_taint(struct ctl_table *table, int write,
69668 void __user *buffer, size_t *lenp, loff_t *ppos);
69669 #endif
69670
69671-#ifdef CONFIG_PRINTK
69672 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69673 void __user *buffer, size_t *lenp, loff_t *ppos);
69674-#endif
69675+
69676+static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
69677+ void __user *buffer, size_t *lenp, loff_t *ppos);
69678+static int proc_dostring_coredump(struct ctl_table *table, int write,
69679+ void __user *buffer, size_t *lenp, loff_t *ppos);
69680
69681 #ifdef CONFIG_MAGIC_SYSRQ
69682 /* Note: sysrq code uses it's own private copy */
69683@@ -196,6 +198,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
69684
69685 #endif
69686
69687+extern struct ctl_table grsecurity_table[];
69688+
69689 static struct ctl_table kern_table[];
69690 static struct ctl_table vm_table[];
69691 static struct ctl_table fs_table[];
69692@@ -210,6 +214,20 @@ extern struct ctl_table epoll_table[];
69693 int sysctl_legacy_va_layout;
69694 #endif
69695
69696+#ifdef CONFIG_PAX_SOFTMODE
69697+static ctl_table pax_table[] = {
69698+ {
69699+ .procname = "softmode",
69700+ .data = &pax_softmode,
69701+ .maxlen = sizeof(unsigned int),
69702+ .mode = 0600,
69703+ .proc_handler = &proc_dointvec,
69704+ },
69705+
69706+ { }
69707+};
69708+#endif
69709+
69710 /* The default sysctl tables: */
69711
69712 static struct ctl_table sysctl_base_table[] = {
69713@@ -256,6 +274,22 @@ static int max_extfrag_threshold = 1000;
69714 #endif
69715
69716 static struct ctl_table kern_table[] = {
69717+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
69718+ {
69719+ .procname = "grsecurity",
69720+ .mode = 0500,
69721+ .child = grsecurity_table,
69722+ },
69723+#endif
69724+
69725+#ifdef CONFIG_PAX_SOFTMODE
69726+ {
69727+ .procname = "pax",
69728+ .mode = 0500,
69729+ .child = pax_table,
69730+ },
69731+#endif
69732+
69733 {
69734 .procname = "sched_child_runs_first",
69735 .data = &sysctl_sched_child_runs_first,
69736@@ -410,7 +444,7 @@ static struct ctl_table kern_table[] = {
69737 .data = core_pattern,
69738 .maxlen = CORENAME_MAX_SIZE,
69739 .mode = 0644,
69740- .proc_handler = proc_dostring,
69741+ .proc_handler = proc_dostring_coredump,
69742 },
69743 {
69744 .procname = "core_pipe_limit",
69745@@ -540,7 +574,7 @@ static struct ctl_table kern_table[] = {
69746 .data = &modprobe_path,
69747 .maxlen = KMOD_PATH_LEN,
69748 .mode = 0644,
69749- .proc_handler = proc_dostring,
69750+ .proc_handler = proc_dostring_modpriv,
69751 },
69752 {
69753 .procname = "modules_disabled",
69754@@ -707,16 +741,20 @@ static struct ctl_table kern_table[] = {
69755 .extra1 = &zero,
69756 .extra2 = &one,
69757 },
69758+#endif
69759 {
69760 .procname = "kptr_restrict",
69761 .data = &kptr_restrict,
69762 .maxlen = sizeof(int),
69763 .mode = 0644,
69764 .proc_handler = proc_dointvec_minmax_sysadmin,
69765+#ifdef CONFIG_GRKERNSEC_HIDESYM
69766+ .extra1 = &two,
69767+#else
69768 .extra1 = &zero,
69769+#endif
69770 .extra2 = &two,
69771 },
69772-#endif
69773 {
69774 .procname = "ngroups_max",
69775 .data = &ngroups_max,
69776@@ -1215,6 +1253,13 @@ static struct ctl_table vm_table[] = {
69777 .proc_handler = proc_dointvec_minmax,
69778 .extra1 = &zero,
69779 },
69780+ {
69781+ .procname = "heap_stack_gap",
69782+ .data = &sysctl_heap_stack_gap,
69783+ .maxlen = sizeof(sysctl_heap_stack_gap),
69784+ .mode = 0644,
69785+ .proc_handler = proc_doulongvec_minmax,
69786+ },
69787 #else
69788 {
69789 .procname = "nr_trim_pages",
69790@@ -1498,7 +1543,7 @@ static struct ctl_table fs_table[] = {
69791 .data = &suid_dumpable,
69792 .maxlen = sizeof(int),
69793 .mode = 0644,
69794- .proc_handler = proc_dointvec_minmax,
69795+ .proc_handler = proc_dointvec_minmax_coredump,
69796 .extra1 = &zero,
69797 .extra2 = &two,
69798 },
69799@@ -1645,6 +1690,16 @@ int proc_dostring(struct ctl_table *table, int write,
69800 buffer, lenp, ppos);
69801 }
69802
69803+int proc_dostring_modpriv(struct ctl_table *table, int write,
69804+ void __user *buffer, size_t *lenp, loff_t *ppos)
69805+{
69806+ if (write && !capable(CAP_SYS_MODULE))
69807+ return -EPERM;
69808+
69809+ return _proc_do_string(table->data, table->maxlen, write,
69810+ buffer, lenp, ppos);
69811+}
69812+
69813 static size_t proc_skip_spaces(char **buf)
69814 {
69815 size_t ret;
69816@@ -1750,6 +1805,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
69817 len = strlen(tmp);
69818 if (len > *size)
69819 len = *size;
69820+ if (len > sizeof(tmp))
69821+ len = sizeof(tmp);
69822 if (copy_to_user(*buf, tmp, len))
69823 return -EFAULT;
69824 *size -= len;
69825@@ -1942,7 +1999,6 @@ static int proc_taint(struct ctl_table *table, int write,
69826 return err;
69827 }
69828
69829-#ifdef CONFIG_PRINTK
69830 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69831 void __user *buffer, size_t *lenp, loff_t *ppos)
69832 {
69833@@ -1951,7 +2007,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69834
69835 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
69836 }
69837-#endif
69838
69839 struct do_proc_dointvec_minmax_conv_param {
69840 int *min;
69841@@ -2009,6 +2064,34 @@ int proc_dointvec_minmax(struct ctl_table *table, int write,
69842 do_proc_dointvec_minmax_conv, &param);
69843 }
69844
69845+static void validate_coredump_safety(void)
69846+{
69847+ if (suid_dumpable == SUID_DUMPABLE_SAFE &&
69848+ core_pattern[0] != '/' && core_pattern[0] != '|') {
69849+ printk(KERN_WARNING "Unsafe core_pattern used with "\
69850+ "suid_dumpable=2. Pipe handler or fully qualified "\
69851+ "core dump path required.\n");
69852+ }
69853+}
69854+
69855+static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
69856+ void __user *buffer, size_t *lenp, loff_t *ppos)
69857+{
69858+ int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
69859+ if (!error)
69860+ validate_coredump_safety();
69861+ return error;
69862+}
69863+
69864+static int proc_dostring_coredump(struct ctl_table *table, int write,
69865+ void __user *buffer, size_t *lenp, loff_t *ppos)
69866+{
69867+ int error = proc_dostring(table, write, buffer, lenp, ppos);
69868+ if (!error)
69869+ validate_coredump_safety();
69870+ return error;
69871+}
69872+
69873 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
69874 void __user *buffer,
69875 size_t *lenp, loff_t *ppos,
69876@@ -2066,8 +2149,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
69877 *i = val;
69878 } else {
69879 val = convdiv * (*i) / convmul;
69880- if (!first)
69881+ if (!first) {
69882 err = proc_put_char(&buffer, &left, '\t');
69883+ if (err)
69884+ break;
69885+ }
69886 err = proc_put_long(&buffer, &left, val, false);
69887 if (err)
69888 break;
69889@@ -2459,6 +2545,12 @@ int proc_dostring(struct ctl_table *table, int write,
69890 return -ENOSYS;
69891 }
69892
69893+int proc_dostring_modpriv(struct ctl_table *table, int write,
69894+ void __user *buffer, size_t *lenp, loff_t *ppos)
69895+{
69896+ return -ENOSYS;
69897+}
69898+
69899 int proc_dointvec(struct ctl_table *table, int write,
69900 void __user *buffer, size_t *lenp, loff_t *ppos)
69901 {
69902@@ -2515,5 +2607,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
69903 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
69904 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
69905 EXPORT_SYMBOL(proc_dostring);
69906+EXPORT_SYMBOL(proc_dostring_modpriv);
69907 EXPORT_SYMBOL(proc_doulongvec_minmax);
69908 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
69909diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
69910index a650694..aaeeb20 100644
69911--- a/kernel/sysctl_binary.c
69912+++ b/kernel/sysctl_binary.c
69913@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
69914 int i;
69915
69916 set_fs(KERNEL_DS);
69917- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69918+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69919 set_fs(old_fs);
69920 if (result < 0)
69921 goto out_kfree;
69922@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
69923 }
69924
69925 set_fs(KERNEL_DS);
69926- result = vfs_write(file, buffer, str - buffer, &pos);
69927+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69928 set_fs(old_fs);
69929 if (result < 0)
69930 goto out_kfree;
69931@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
69932 int i;
69933
69934 set_fs(KERNEL_DS);
69935- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69936+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69937 set_fs(old_fs);
69938 if (result < 0)
69939 goto out_kfree;
69940@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
69941 }
69942
69943 set_fs(KERNEL_DS);
69944- result = vfs_write(file, buffer, str - buffer, &pos);
69945+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69946 set_fs(old_fs);
69947 if (result < 0)
69948 goto out_kfree;
69949@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
69950 int i;
69951
69952 set_fs(KERNEL_DS);
69953- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69954+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69955 set_fs(old_fs);
69956 if (result < 0)
69957 goto out;
69958@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69959 __le16 dnaddr;
69960
69961 set_fs(KERNEL_DS);
69962- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69963+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69964 set_fs(old_fs);
69965 if (result < 0)
69966 goto out;
69967@@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69968 le16_to_cpu(dnaddr) & 0x3ff);
69969
69970 set_fs(KERNEL_DS);
69971- result = vfs_write(file, buf, len, &pos);
69972+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
69973 set_fs(old_fs);
69974 if (result < 0)
69975 goto out;
69976diff --git a/kernel/taskstats.c b/kernel/taskstats.c
69977index e660464..c8b9e67 100644
69978--- a/kernel/taskstats.c
69979+++ b/kernel/taskstats.c
69980@@ -27,9 +27,12 @@
69981 #include <linux/cgroup.h>
69982 #include <linux/fs.h>
69983 #include <linux/file.h>
69984+#include <linux/grsecurity.h>
69985 #include <net/genetlink.h>
69986 #include <linux/atomic.h>
69987
69988+extern int gr_is_taskstats_denied(int pid);
69989+
69990 /*
69991 * Maximum length of a cpumask that can be specified in
69992 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
69993@@ -556,6 +559,9 @@ err:
69994
69995 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
69996 {
69997+ if (gr_is_taskstats_denied(current->pid))
69998+ return -EACCES;
69999+
70000 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
70001 return cmd_attr_register_cpumask(info);
70002 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
70003diff --git a/kernel/time.c b/kernel/time.c
70004index ba744cf..267b7c5 100644
70005--- a/kernel/time.c
70006+++ b/kernel/time.c
70007@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
70008 return error;
70009
70010 if (tz) {
70011+ /* we log in do_settimeofday called below, so don't log twice
70012+ */
70013+ if (!tv)
70014+ gr_log_timechange();
70015+
70016 sys_tz = *tz;
70017 update_vsyscall_tz();
70018 if (firsttime) {
70019diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
70020index aa27d39..34d221c 100644
70021--- a/kernel/time/alarmtimer.c
70022+++ b/kernel/time/alarmtimer.c
70023@@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
70024 struct platform_device *pdev;
70025 int error = 0;
70026 int i;
70027- struct k_clock alarm_clock = {
70028+ static struct k_clock alarm_clock = {
70029 .clock_getres = alarm_clock_getres,
70030 .clock_get = alarm_clock_get,
70031 .timer_create = alarm_timer_create,
70032diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
70033index f113755..ec24223 100644
70034--- a/kernel/time/tick-broadcast.c
70035+++ b/kernel/time/tick-broadcast.c
70036@@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
70037 * then clear the broadcast bit.
70038 */
70039 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
70040- int cpu = smp_processor_id();
70041+ cpu = smp_processor_id();
70042
70043 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
70044 tick_broadcast_clear_oneshot(cpu);
70045diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
70046index 3447cfa..291806b 100644
70047--- a/kernel/time/timekeeping.c
70048+++ b/kernel/time/timekeeping.c
70049@@ -14,6 +14,7 @@
70050 #include <linux/init.h>
70051 #include <linux/mm.h>
70052 #include <linux/sched.h>
70053+#include <linux/grsecurity.h>
70054 #include <linux/syscore_ops.h>
70055 #include <linux/clocksource.h>
70056 #include <linux/jiffies.h>
70057@@ -387,6 +388,8 @@ int do_settimeofday(const struct timespec *tv)
70058 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
70059 return -EINVAL;
70060
70061+ gr_log_timechange();
70062+
70063 write_seqlock_irqsave(&timekeeper.lock, flags);
70064
70065 timekeeping_forward_now();
70066diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
70067index 3258455..f35227d 100644
70068--- a/kernel/time/timer_list.c
70069+++ b/kernel/time/timer_list.c
70070@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
70071
70072 static void print_name_offset(struct seq_file *m, void *sym)
70073 {
70074+#ifdef CONFIG_GRKERNSEC_HIDESYM
70075+ SEQ_printf(m, "<%p>", NULL);
70076+#else
70077 char symname[KSYM_NAME_LEN];
70078
70079 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
70080 SEQ_printf(m, "<%pK>", sym);
70081 else
70082 SEQ_printf(m, "%s", symname);
70083+#endif
70084 }
70085
70086 static void
70087@@ -112,7 +116,11 @@ next_one:
70088 static void
70089 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
70090 {
70091+#ifdef CONFIG_GRKERNSEC_HIDESYM
70092+ SEQ_printf(m, " .base: %p\n", NULL);
70093+#else
70094 SEQ_printf(m, " .base: %pK\n", base);
70095+#endif
70096 SEQ_printf(m, " .index: %d\n",
70097 base->index);
70098 SEQ_printf(m, " .resolution: %Lu nsecs\n",
70099@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
70100 {
70101 struct proc_dir_entry *pe;
70102
70103+#ifdef CONFIG_GRKERNSEC_PROC_ADD
70104+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
70105+#else
70106 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
70107+#endif
70108 if (!pe)
70109 return -ENOMEM;
70110 return 0;
70111diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
70112index 0b537f2..9e71eca 100644
70113--- a/kernel/time/timer_stats.c
70114+++ b/kernel/time/timer_stats.c
70115@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
70116 static unsigned long nr_entries;
70117 static struct entry entries[MAX_ENTRIES];
70118
70119-static atomic_t overflow_count;
70120+static atomic_unchecked_t overflow_count;
70121
70122 /*
70123 * The entries are in a hash-table, for fast lookup:
70124@@ -140,7 +140,7 @@ static void reset_entries(void)
70125 nr_entries = 0;
70126 memset(entries, 0, sizeof(entries));
70127 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
70128- atomic_set(&overflow_count, 0);
70129+ atomic_set_unchecked(&overflow_count, 0);
70130 }
70131
70132 static struct entry *alloc_entry(void)
70133@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70134 if (likely(entry))
70135 entry->count++;
70136 else
70137- atomic_inc(&overflow_count);
70138+ atomic_inc_unchecked(&overflow_count);
70139
70140 out_unlock:
70141 raw_spin_unlock_irqrestore(lock, flags);
70142@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70143
70144 static void print_name_offset(struct seq_file *m, unsigned long addr)
70145 {
70146+#ifdef CONFIG_GRKERNSEC_HIDESYM
70147+ seq_printf(m, "<%p>", NULL);
70148+#else
70149 char symname[KSYM_NAME_LEN];
70150
70151 if (lookup_symbol_name(addr, symname) < 0)
70152 seq_printf(m, "<%p>", (void *)addr);
70153 else
70154 seq_printf(m, "%s", symname);
70155+#endif
70156 }
70157
70158 static int tstats_show(struct seq_file *m, void *v)
70159@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
70160
70161 seq_puts(m, "Timer Stats Version: v0.2\n");
70162 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
70163- if (atomic_read(&overflow_count))
70164+ if (atomic_read_unchecked(&overflow_count))
70165 seq_printf(m, "Overflow: %d entries\n",
70166- atomic_read(&overflow_count));
70167+ atomic_read_unchecked(&overflow_count));
70168
70169 for (i = 0; i < nr_entries; i++) {
70170 entry = entries + i;
70171@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
70172 {
70173 struct proc_dir_entry *pe;
70174
70175+#ifdef CONFIG_GRKERNSEC_PROC_ADD
70176+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
70177+#else
70178 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
70179+#endif
70180 if (!pe)
70181 return -ENOMEM;
70182 return 0;
70183diff --git a/kernel/timer.c b/kernel/timer.c
70184index 6ec7e7e..cbc448b 100644
70185--- a/kernel/timer.c
70186+++ b/kernel/timer.c
70187@@ -1362,7 +1362,7 @@ void update_process_times(int user_tick)
70188 /*
70189 * This function runs timers and the timer-tq in bottom half context.
70190 */
70191-static void run_timer_softirq(struct softirq_action *h)
70192+static void run_timer_softirq(void)
70193 {
70194 struct tvec_base *base = __this_cpu_read(tvec_bases);
70195
70196diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
70197index c0bd030..62a1927 100644
70198--- a/kernel/trace/blktrace.c
70199+++ b/kernel/trace/blktrace.c
70200@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
70201 struct blk_trace *bt = filp->private_data;
70202 char buf[16];
70203
70204- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
70205+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
70206
70207 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
70208 }
70209@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
70210 return 1;
70211
70212 bt = buf->chan->private_data;
70213- atomic_inc(&bt->dropped);
70214+ atomic_inc_unchecked(&bt->dropped);
70215 return 0;
70216 }
70217
70218@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
70219
70220 bt->dir = dir;
70221 bt->dev = dev;
70222- atomic_set(&bt->dropped, 0);
70223+ atomic_set_unchecked(&bt->dropped, 0);
70224
70225 ret = -EIO;
70226 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
70227diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
70228index a008663..30d7429 100644
70229--- a/kernel/trace/ftrace.c
70230+++ b/kernel/trace/ftrace.c
70231@@ -1785,12 +1785,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
70232 if (unlikely(ftrace_disabled))
70233 return 0;
70234
70235+ ret = ftrace_arch_code_modify_prepare();
70236+ FTRACE_WARN_ON(ret);
70237+ if (ret)
70238+ return 0;
70239+
70240 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
70241+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
70242 if (ret) {
70243 ftrace_bug(ret, ip);
70244- return 0;
70245 }
70246- return 1;
70247+ return ret ? 0 : 1;
70248 }
70249
70250 /*
70251@@ -2885,7 +2890,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
70252
70253 int
70254 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
70255- void *data)
70256+ void *data)
70257 {
70258 struct ftrace_func_probe *entry;
70259 struct ftrace_page *pg;
70260@@ -3697,8 +3702,10 @@ static int ftrace_process_locs(struct module *mod,
70261 if (!count)
70262 return 0;
70263
70264+ pax_open_kernel();
70265 sort(start, count, sizeof(*start),
70266 ftrace_cmp_ips, ftrace_swap_ips);
70267+ pax_close_kernel();
70268
70269 start_pg = ftrace_allocate_pages(count);
70270 if (!start_pg)
70271diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
70272index a7fa070..403bc8d 100644
70273--- a/kernel/trace/trace.c
70274+++ b/kernel/trace/trace.c
70275@@ -4421,10 +4421,9 @@ static const struct file_operations tracing_dyn_info_fops = {
70276 };
70277 #endif
70278
70279-static struct dentry *d_tracer;
70280-
70281 struct dentry *tracing_init_dentry(void)
70282 {
70283+ static struct dentry *d_tracer;
70284 static int once;
70285
70286 if (d_tracer)
70287@@ -4444,10 +4443,9 @@ struct dentry *tracing_init_dentry(void)
70288 return d_tracer;
70289 }
70290
70291-static struct dentry *d_percpu;
70292-
70293 struct dentry *tracing_dentry_percpu(void)
70294 {
70295+ static struct dentry *d_percpu;
70296 static int once;
70297 struct dentry *d_tracer;
70298
70299diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
70300index 29111da..d190fe2 100644
70301--- a/kernel/trace/trace_events.c
70302+++ b/kernel/trace/trace_events.c
70303@@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
70304 struct ftrace_module_file_ops {
70305 struct list_head list;
70306 struct module *mod;
70307- struct file_operations id;
70308- struct file_operations enable;
70309- struct file_operations format;
70310- struct file_operations filter;
70311 };
70312
70313 static struct ftrace_module_file_ops *
70314@@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
70315
70316 file_ops->mod = mod;
70317
70318- file_ops->id = ftrace_event_id_fops;
70319- file_ops->id.owner = mod;
70320-
70321- file_ops->enable = ftrace_enable_fops;
70322- file_ops->enable.owner = mod;
70323-
70324- file_ops->filter = ftrace_event_filter_fops;
70325- file_ops->filter.owner = mod;
70326-
70327- file_ops->format = ftrace_event_format_fops;
70328- file_ops->format.owner = mod;
70329+ pax_open_kernel();
70330+ *(void **)&mod->trace_id.owner = mod;
70331+ *(void **)&mod->trace_enable.owner = mod;
70332+ *(void **)&mod->trace_filter.owner = mod;
70333+ *(void **)&mod->trace_format.owner = mod;
70334+ pax_close_kernel();
70335
70336 list_add(&file_ops->list, &ftrace_module_file_list);
70337
70338@@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
70339
70340 for_each_event(call, start, end) {
70341 __trace_add_event_call(*call, mod,
70342- &file_ops->id, &file_ops->enable,
70343- &file_ops->filter, &file_ops->format);
70344+ &mod->trace_id, &mod->trace_enable,
70345+ &mod->trace_filter, &mod->trace_format);
70346 }
70347 }
70348
70349diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
70350index fd3c8aa..5f324a6 100644
70351--- a/kernel/trace/trace_mmiotrace.c
70352+++ b/kernel/trace/trace_mmiotrace.c
70353@@ -24,7 +24,7 @@ struct header_iter {
70354 static struct trace_array *mmio_trace_array;
70355 static bool overrun_detected;
70356 static unsigned long prev_overruns;
70357-static atomic_t dropped_count;
70358+static atomic_unchecked_t dropped_count;
70359
70360 static void mmio_reset_data(struct trace_array *tr)
70361 {
70362@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
70363
70364 static unsigned long count_overruns(struct trace_iterator *iter)
70365 {
70366- unsigned long cnt = atomic_xchg(&dropped_count, 0);
70367+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
70368 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
70369
70370 if (over > prev_overruns)
70371@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
70372 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
70373 sizeof(*entry), 0, pc);
70374 if (!event) {
70375- atomic_inc(&dropped_count);
70376+ atomic_inc_unchecked(&dropped_count);
70377 return;
70378 }
70379 entry = ring_buffer_event_data(event);
70380@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
70381 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
70382 sizeof(*entry), 0, pc);
70383 if (!event) {
70384- atomic_inc(&dropped_count);
70385+ atomic_inc_unchecked(&dropped_count);
70386 return;
70387 }
70388 entry = ring_buffer_event_data(event);
70389diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
70390index df611a0..10d8b32 100644
70391--- a/kernel/trace/trace_output.c
70392+++ b/kernel/trace/trace_output.c
70393@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
70394
70395 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
70396 if (!IS_ERR(p)) {
70397- p = mangle_path(s->buffer + s->len, p, "\n");
70398+ p = mangle_path(s->buffer + s->len, p, "\n\\");
70399 if (p) {
70400 s->len = p - s->buffer;
70401 return 1;
70402diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
70403index d4545f4..a9010a1 100644
70404--- a/kernel/trace/trace_stack.c
70405+++ b/kernel/trace/trace_stack.c
70406@@ -53,7 +53,7 @@ static inline void check_stack(void)
70407 return;
70408
70409 /* we do not handle interrupt stacks yet */
70410- if (!object_is_on_stack(&this_size))
70411+ if (!object_starts_on_stack(&this_size))
70412 return;
70413
70414 local_irq_save(flags);
70415diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
70416index ff5bdee..3eaeba6 100644
70417--- a/lib/Kconfig.debug
70418+++ b/lib/Kconfig.debug
70419@@ -1165,6 +1165,7 @@ config LATENCYTOP
70420 depends on DEBUG_KERNEL
70421 depends on STACKTRACE_SUPPORT
70422 depends on PROC_FS
70423+ depends on !GRKERNSEC_HIDESYM
70424 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
70425 select KALLSYMS
70426 select KALLSYMS_ALL
70427diff --git a/lib/bitmap.c b/lib/bitmap.c
70428index 06fdfa1..97c5c7d 100644
70429--- a/lib/bitmap.c
70430+++ b/lib/bitmap.c
70431@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
70432 {
70433 int c, old_c, totaldigits, ndigits, nchunks, nbits;
70434 u32 chunk;
70435- const char __user __force *ubuf = (const char __user __force *)buf;
70436+ const char __user *ubuf = (const char __force_user *)buf;
70437
70438 bitmap_zero(maskp, nmaskbits);
70439
70440@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
70441 {
70442 if (!access_ok(VERIFY_READ, ubuf, ulen))
70443 return -EFAULT;
70444- return __bitmap_parse((const char __force *)ubuf,
70445+ return __bitmap_parse((const char __force_kernel *)ubuf,
70446 ulen, 1, maskp, nmaskbits);
70447
70448 }
70449@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
70450 {
70451 unsigned a, b;
70452 int c, old_c, totaldigits;
70453- const char __user __force *ubuf = (const char __user __force *)buf;
70454+ const char __user *ubuf = (const char __force_user *)buf;
70455 int exp_digit, in_range;
70456
70457 totaldigits = c = 0;
70458@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
70459 {
70460 if (!access_ok(VERIFY_READ, ubuf, ulen))
70461 return -EFAULT;
70462- return __bitmap_parselist((const char __force *)ubuf,
70463+ return __bitmap_parselist((const char __force_kernel *)ubuf,
70464 ulen, 1, maskp, nmaskbits);
70465 }
70466 EXPORT_SYMBOL(bitmap_parselist_user);
70467diff --git a/lib/bug.c b/lib/bug.c
70468index a28c141..2bd3d95 100644
70469--- a/lib/bug.c
70470+++ b/lib/bug.c
70471@@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
70472 return BUG_TRAP_TYPE_NONE;
70473
70474 bug = find_bug(bugaddr);
70475+ if (!bug)
70476+ return BUG_TRAP_TYPE_NONE;
70477
70478 file = NULL;
70479 line = 0;
70480diff --git a/lib/debugobjects.c b/lib/debugobjects.c
70481index d11808c..dc2d6f8 100644
70482--- a/lib/debugobjects.c
70483+++ b/lib/debugobjects.c
70484@@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
70485 if (limit > 4)
70486 return;
70487
70488- is_on_stack = object_is_on_stack(addr);
70489+ is_on_stack = object_starts_on_stack(addr);
70490 if (is_on_stack == onstack)
70491 return;
70492
70493diff --git a/lib/devres.c b/lib/devres.c
70494index 80b9c76..9e32279 100644
70495--- a/lib/devres.c
70496+++ b/lib/devres.c
70497@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
70498 void devm_iounmap(struct device *dev, void __iomem *addr)
70499 {
70500 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
70501- (void *)addr));
70502+ (void __force *)addr));
70503 iounmap(addr);
70504 }
70505 EXPORT_SYMBOL(devm_iounmap);
70506@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
70507 {
70508 ioport_unmap(addr);
70509 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
70510- devm_ioport_map_match, (void *)addr));
70511+ devm_ioport_map_match, (void __force *)addr));
70512 }
70513 EXPORT_SYMBOL(devm_ioport_unmap);
70514
70515diff --git a/lib/dma-debug.c b/lib/dma-debug.c
70516index 66ce414..6f0a0dd 100644
70517--- a/lib/dma-debug.c
70518+++ b/lib/dma-debug.c
70519@@ -924,7 +924,7 @@ out:
70520
70521 static void check_for_stack(struct device *dev, void *addr)
70522 {
70523- if (object_is_on_stack(addr))
70524+ if (object_starts_on_stack(addr))
70525 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
70526 "stack [addr=%p]\n", addr);
70527 }
70528diff --git a/lib/extable.c b/lib/extable.c
70529index 4cac81e..4d66cfc 100644
70530--- a/lib/extable.c
70531+++ b/lib/extable.c
70532@@ -13,6 +13,7 @@
70533 #include <linux/init.h>
70534 #include <linux/sort.h>
70535 #include <asm/uaccess.h>
70536+#include <asm/pgtable.h>
70537
70538 #ifndef ARCH_HAS_SORT_EXTABLE
70539 /*
70540diff --git a/lib/inflate.c b/lib/inflate.c
70541index 013a761..c28f3fc 100644
70542--- a/lib/inflate.c
70543+++ b/lib/inflate.c
70544@@ -269,7 +269,7 @@ static void free(void *where)
70545 malloc_ptr = free_mem_ptr;
70546 }
70547 #else
70548-#define malloc(a) kmalloc(a, GFP_KERNEL)
70549+#define malloc(a) kmalloc((a), GFP_KERNEL)
70550 #define free(a) kfree(a)
70551 #endif
70552
70553diff --git a/lib/ioremap.c b/lib/ioremap.c
70554index 0c9216c..863bd89 100644
70555--- a/lib/ioremap.c
70556+++ b/lib/ioremap.c
70557@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
70558 unsigned long next;
70559
70560 phys_addr -= addr;
70561- pmd = pmd_alloc(&init_mm, pud, addr);
70562+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
70563 if (!pmd)
70564 return -ENOMEM;
70565 do {
70566@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
70567 unsigned long next;
70568
70569 phys_addr -= addr;
70570- pud = pud_alloc(&init_mm, pgd, addr);
70571+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
70572 if (!pud)
70573 return -ENOMEM;
70574 do {
70575diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
70576index bd2bea9..6b3c95e 100644
70577--- a/lib/is_single_threaded.c
70578+++ b/lib/is_single_threaded.c
70579@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
70580 struct task_struct *p, *t;
70581 bool ret;
70582
70583+ if (!mm)
70584+ return true;
70585+
70586 if (atomic_read(&task->signal->live) != 1)
70587 return false;
70588
70589diff --git a/lib/radix-tree.c b/lib/radix-tree.c
70590index e796429..6e38f9f 100644
70591--- a/lib/radix-tree.c
70592+++ b/lib/radix-tree.c
70593@@ -92,7 +92,7 @@ struct radix_tree_preload {
70594 int nr;
70595 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
70596 };
70597-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
70598+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
70599
70600 static inline void *ptr_to_indirect(void *ptr)
70601 {
70602diff --git a/lib/vsprintf.c b/lib/vsprintf.c
70603index 598a73e..5c5aeb5 100644
70604--- a/lib/vsprintf.c
70605+++ b/lib/vsprintf.c
70606@@ -16,6 +16,9 @@
70607 * - scnprintf and vscnprintf
70608 */
70609
70610+#ifdef CONFIG_GRKERNSEC_HIDESYM
70611+#define __INCLUDED_BY_HIDESYM 1
70612+#endif
70613 #include <stdarg.h>
70614 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
70615 #include <linux/types.h>
70616@@ -536,7 +539,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
70617 char sym[KSYM_SYMBOL_LEN];
70618 if (ext == 'B')
70619 sprint_backtrace(sym, value);
70620- else if (ext != 'f' && ext != 's')
70621+ else if (ext != 'f' && ext != 's' && ext != 'a')
70622 sprint_symbol(sym, value);
70623 else
70624 sprint_symbol_no_offset(sym, value);
70625@@ -912,7 +915,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
70626 return number(buf, end, *(const netdev_features_t *)addr, spec);
70627 }
70628
70629+#ifdef CONFIG_GRKERNSEC_HIDESYM
70630+int kptr_restrict __read_mostly = 2;
70631+#else
70632 int kptr_restrict __read_mostly;
70633+#endif
70634
70635 /*
70636 * Show a '%p' thing. A kernel extension is that the '%p' is followed
70637@@ -926,6 +933,8 @@ int kptr_restrict __read_mostly;
70638 * - 'S' For symbolic direct pointers with offset
70639 * - 's' For symbolic direct pointers without offset
70640 * - 'B' For backtraced symbolic direct pointers with offset
70641+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
70642+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
70643 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
70644 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
70645 * - 'M' For a 6-byte MAC address, it prints the address in the
70646@@ -973,12 +982,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70647
70648 if (!ptr && *fmt != 'K') {
70649 /*
70650- * Print (null) with the same width as a pointer so it makes
70651+ * Print (nil) with the same width as a pointer so it makes
70652 * tabular output look nice.
70653 */
70654 if (spec.field_width == -1)
70655 spec.field_width = default_width;
70656- return string(buf, end, "(null)", spec);
70657+ return string(buf, end, "(nil)", spec);
70658 }
70659
70660 switch (*fmt) {
70661@@ -988,6 +997,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70662 /* Fallthrough */
70663 case 'S':
70664 case 's':
70665+#ifdef CONFIG_GRKERNSEC_HIDESYM
70666+ break;
70667+#else
70668+ return symbol_string(buf, end, ptr, spec, *fmt);
70669+#endif
70670+ case 'A':
70671+ case 'a':
70672 case 'B':
70673 return symbol_string(buf, end, ptr, spec, *fmt);
70674 case 'R':
70675@@ -1025,6 +1041,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70676 va_end(va);
70677 return buf;
70678 }
70679+ case 'P':
70680+ break;
70681 case 'K':
70682 /*
70683 * %pK cannot be used in IRQ context because its test
70684@@ -1048,6 +1066,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70685 }
70686 break;
70687 }
70688+
70689+#ifdef CONFIG_GRKERNSEC_HIDESYM
70690+ /* 'P' = approved pointers to copy to userland,
70691+ as in the /proc/kallsyms case, as we make it display nothing
70692+ for non-root users, and the real contents for root users
70693+ Also ignore 'K' pointers, since we force their NULLing for non-root users
70694+ above
70695+ */
70696+ if (ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
70697+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
70698+ dump_stack();
70699+ ptr = NULL;
70700+ }
70701+#endif
70702+
70703 spec.flags |= SMALL;
70704 if (spec.field_width == -1) {
70705 spec.field_width = default_width;
70706@@ -1759,11 +1792,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70707 typeof(type) value; \
70708 if (sizeof(type) == 8) { \
70709 args = PTR_ALIGN(args, sizeof(u32)); \
70710- *(u32 *)&value = *(u32 *)args; \
70711- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
70712+ *(u32 *)&value = *(const u32 *)args; \
70713+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
70714 } else { \
70715 args = PTR_ALIGN(args, sizeof(type)); \
70716- value = *(typeof(type) *)args; \
70717+ value = *(const typeof(type) *)args; \
70718 } \
70719 args += sizeof(type); \
70720 value; \
70721@@ -1826,7 +1859,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70722 case FORMAT_TYPE_STR: {
70723 const char *str_arg = args;
70724 args += strlen(str_arg) + 1;
70725- str = string(str, end, (char *)str_arg, spec);
70726+ str = string(str, end, str_arg, spec);
70727 break;
70728 }
70729
70730diff --git a/localversion-grsec b/localversion-grsec
70731new file mode 100644
70732index 0000000..7cd6065
70733--- /dev/null
70734+++ b/localversion-grsec
70735@@ -0,0 +1 @@
70736+-grsec
70737diff --git a/mm/Kconfig b/mm/Kconfig
70738index 82fed4e..979e814 100644
70739--- a/mm/Kconfig
70740+++ b/mm/Kconfig
70741@@ -247,10 +247,10 @@ config KSM
70742 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
70743
70744 config DEFAULT_MMAP_MIN_ADDR
70745- int "Low address space to protect from user allocation"
70746+ int "Low address space to protect from user allocation"
70747 depends on MMU
70748- default 4096
70749- help
70750+ default 65536
70751+ help
70752 This is the portion of low virtual memory which should be protected
70753 from userspace allocation. Keeping a user from writing to low pages
70754 can help reduce the impact of kernel NULL pointer bugs.
70755@@ -280,7 +280,7 @@ config MEMORY_FAILURE
70756
70757 config HWPOISON_INJECT
70758 tristate "HWPoison pages injector"
70759- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
70760+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
70761 select PROC_PAGE_MONITOR
70762
70763 config NOMMU_INITIAL_TRIM_EXCESS
70764diff --git a/mm/filemap.c b/mm/filemap.c
70765index a4a5260..6151dc5 100644
70766--- a/mm/filemap.c
70767+++ b/mm/filemap.c
70768@@ -1723,7 +1723,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
70769 struct address_space *mapping = file->f_mapping;
70770
70771 if (!mapping->a_ops->readpage)
70772- return -ENOEXEC;
70773+ return -ENODEV;
70774 file_accessed(file);
70775 vma->vm_ops = &generic_file_vm_ops;
70776 vma->vm_flags |= VM_CAN_NONLINEAR;
70777@@ -2064,6 +2064,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
70778 *pos = i_size_read(inode);
70779
70780 if (limit != RLIM_INFINITY) {
70781+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
70782 if (*pos >= limit) {
70783 send_sig(SIGXFSZ, current, 0);
70784 return -EFBIG;
70785diff --git a/mm/fremap.c b/mm/fremap.c
70786index 9ed4fd4..c42648d 100644
70787--- a/mm/fremap.c
70788+++ b/mm/fremap.c
70789@@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
70790 retry:
70791 vma = find_vma(mm, start);
70792
70793+#ifdef CONFIG_PAX_SEGMEXEC
70794+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
70795+ goto out;
70796+#endif
70797+
70798 /*
70799 * Make sure the vma is shared, that it supports prefaulting,
70800 * and that the remapped range is valid and fully within
70801diff --git a/mm/highmem.c b/mm/highmem.c
70802index 57d82c6..e9e0552 100644
70803--- a/mm/highmem.c
70804+++ b/mm/highmem.c
70805@@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
70806 * So no dangers, even with speculative execution.
70807 */
70808 page = pte_page(pkmap_page_table[i]);
70809+ pax_open_kernel();
70810 pte_clear(&init_mm, (unsigned long)page_address(page),
70811 &pkmap_page_table[i]);
70812-
70813+ pax_close_kernel();
70814 set_page_address(page, NULL);
70815 need_flush = 1;
70816 }
70817@@ -186,9 +187,11 @@ start:
70818 }
70819 }
70820 vaddr = PKMAP_ADDR(last_pkmap_nr);
70821+
70822+ pax_open_kernel();
70823 set_pte_at(&init_mm, vaddr,
70824 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
70825-
70826+ pax_close_kernel();
70827 pkmap_count[last_pkmap_nr] = 1;
70828 set_page_address(page, (void *)vaddr);
70829
70830diff --git a/mm/huge_memory.c b/mm/huge_memory.c
70831index 57c4b93..24b8f59 100644
70832--- a/mm/huge_memory.c
70833+++ b/mm/huge_memory.c
70834@@ -735,7 +735,7 @@ out:
70835 * run pte_offset_map on the pmd, if an huge pmd could
70836 * materialize from under us from a different thread.
70837 */
70838- if (unlikely(__pte_alloc(mm, vma, pmd, address)))
70839+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
70840 return VM_FAULT_OOM;
70841 /* if an huge pmd materialized from under us just retry later */
70842 if (unlikely(pmd_trans_huge(*pmd)))
70843diff --git a/mm/hugetlb.c b/mm/hugetlb.c
70844index 19558df..f7743b3 100644
70845--- a/mm/hugetlb.c
70846+++ b/mm/hugetlb.c
70847@@ -2463,6 +2463,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
70848 return 1;
70849 }
70850
70851+#ifdef CONFIG_PAX_SEGMEXEC
70852+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
70853+{
70854+ struct mm_struct *mm = vma->vm_mm;
70855+ struct vm_area_struct *vma_m;
70856+ unsigned long address_m;
70857+ pte_t *ptep_m;
70858+
70859+ vma_m = pax_find_mirror_vma(vma);
70860+ if (!vma_m)
70861+ return;
70862+
70863+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70864+ address_m = address + SEGMEXEC_TASK_SIZE;
70865+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
70866+ get_page(page_m);
70867+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
70868+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
70869+}
70870+#endif
70871+
70872 /*
70873 * Hugetlb_cow() should be called with page lock of the original hugepage held.
70874 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
70875@@ -2575,6 +2596,11 @@ retry_avoidcopy:
70876 make_huge_pte(vma, new_page, 1));
70877 page_remove_rmap(old_page);
70878 hugepage_add_new_anon_rmap(new_page, vma, address);
70879+
70880+#ifdef CONFIG_PAX_SEGMEXEC
70881+ pax_mirror_huge_pte(vma, address, new_page);
70882+#endif
70883+
70884 /* Make the old page be freed below */
70885 new_page = old_page;
70886 mmu_notifier_invalidate_range_end(mm,
70887@@ -2729,6 +2755,10 @@ retry:
70888 && (vma->vm_flags & VM_SHARED)));
70889 set_huge_pte_at(mm, address, ptep, new_pte);
70890
70891+#ifdef CONFIG_PAX_SEGMEXEC
70892+ pax_mirror_huge_pte(vma, address, page);
70893+#endif
70894+
70895 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
70896 /* Optimization, do the COW without a second fault */
70897 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
70898@@ -2758,6 +2788,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70899 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
70900 struct hstate *h = hstate_vma(vma);
70901
70902+#ifdef CONFIG_PAX_SEGMEXEC
70903+ struct vm_area_struct *vma_m;
70904+#endif
70905+
70906 address &= huge_page_mask(h);
70907
70908 ptep = huge_pte_offset(mm, address);
70909@@ -2771,6 +2805,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70910 VM_FAULT_SET_HINDEX(h - hstates);
70911 }
70912
70913+#ifdef CONFIG_PAX_SEGMEXEC
70914+ vma_m = pax_find_mirror_vma(vma);
70915+ if (vma_m) {
70916+ unsigned long address_m;
70917+
70918+ if (vma->vm_start > vma_m->vm_start) {
70919+ address_m = address;
70920+ address -= SEGMEXEC_TASK_SIZE;
70921+ vma = vma_m;
70922+ h = hstate_vma(vma);
70923+ } else
70924+ address_m = address + SEGMEXEC_TASK_SIZE;
70925+
70926+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
70927+ return VM_FAULT_OOM;
70928+ address_m &= HPAGE_MASK;
70929+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
70930+ }
70931+#endif
70932+
70933 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
70934 if (!ptep)
70935 return VM_FAULT_OOM;
70936diff --git a/mm/internal.h b/mm/internal.h
70937index 8052379..47029d1 100644
70938--- a/mm/internal.h
70939+++ b/mm/internal.h
70940@@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
70941 * in mm/page_alloc.c
70942 */
70943 extern void __free_pages_bootmem(struct page *page, unsigned int order);
70944+extern void free_compound_page(struct page *page);
70945 extern void prep_compound_page(struct page *page, unsigned long order);
70946 #ifdef CONFIG_MEMORY_FAILURE
70947 extern bool is_free_buddy_page(struct page *page);
70948diff --git a/mm/kmemleak.c b/mm/kmemleak.c
70949index 45eb621..6ccd8ea 100644
70950--- a/mm/kmemleak.c
70951+++ b/mm/kmemleak.c
70952@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
70953
70954 for (i = 0; i < object->trace_len; i++) {
70955 void *ptr = (void *)object->trace[i];
70956- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
70957+ seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
70958 }
70959 }
70960
70961diff --git a/mm/maccess.c b/mm/maccess.c
70962index d53adf9..03a24bf 100644
70963--- a/mm/maccess.c
70964+++ b/mm/maccess.c
70965@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
70966 set_fs(KERNEL_DS);
70967 pagefault_disable();
70968 ret = __copy_from_user_inatomic(dst,
70969- (__force const void __user *)src, size);
70970+ (const void __force_user *)src, size);
70971 pagefault_enable();
70972 set_fs(old_fs);
70973
70974@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
70975
70976 set_fs(KERNEL_DS);
70977 pagefault_disable();
70978- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
70979+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
70980 pagefault_enable();
70981 set_fs(old_fs);
70982
70983diff --git a/mm/madvise.c b/mm/madvise.c
70984index 14d260f..b2a80fd 100644
70985--- a/mm/madvise.c
70986+++ b/mm/madvise.c
70987@@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
70988 pgoff_t pgoff;
70989 unsigned long new_flags = vma->vm_flags;
70990
70991+#ifdef CONFIG_PAX_SEGMEXEC
70992+ struct vm_area_struct *vma_m;
70993+#endif
70994+
70995 switch (behavior) {
70996 case MADV_NORMAL:
70997 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
70998@@ -119,6 +123,13 @@ success:
70999 /*
71000 * vm_flags is protected by the mmap_sem held in write mode.
71001 */
71002+
71003+#ifdef CONFIG_PAX_SEGMEXEC
71004+ vma_m = pax_find_mirror_vma(vma);
71005+ if (vma_m)
71006+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
71007+#endif
71008+
71009 vma->vm_flags = new_flags;
71010
71011 out:
71012@@ -177,6 +188,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71013 struct vm_area_struct ** prev,
71014 unsigned long start, unsigned long end)
71015 {
71016+
71017+#ifdef CONFIG_PAX_SEGMEXEC
71018+ struct vm_area_struct *vma_m;
71019+#endif
71020+
71021 *prev = vma;
71022 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
71023 return -EINVAL;
71024@@ -189,6 +205,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71025 zap_page_range(vma, start, end - start, &details);
71026 } else
71027 zap_page_range(vma, start, end - start, NULL);
71028+
71029+#ifdef CONFIG_PAX_SEGMEXEC
71030+ vma_m = pax_find_mirror_vma(vma);
71031+ if (vma_m) {
71032+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
71033+ struct zap_details details = {
71034+ .nonlinear_vma = vma_m,
71035+ .last_index = ULONG_MAX,
71036+ };
71037+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
71038+ } else
71039+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
71040+ }
71041+#endif
71042+
71043 return 0;
71044 }
71045
71046@@ -393,6 +424,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
71047 if (end < start)
71048 goto out;
71049
71050+#ifdef CONFIG_PAX_SEGMEXEC
71051+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
71052+ if (end > SEGMEXEC_TASK_SIZE)
71053+ goto out;
71054+ } else
71055+#endif
71056+
71057+ if (end > TASK_SIZE)
71058+ goto out;
71059+
71060 error = 0;
71061 if (end == start)
71062 goto out;
71063diff --git a/mm/memory-failure.c b/mm/memory-failure.c
71064index 6de0d61..da836cf 100644
71065--- a/mm/memory-failure.c
71066+++ b/mm/memory-failure.c
71067@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
71068
71069 int sysctl_memory_failure_recovery __read_mostly = 1;
71070
71071-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71072+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71073
71074 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
71075
71076@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
71077 pfn, t->comm, t->pid);
71078 si.si_signo = SIGBUS;
71079 si.si_errno = 0;
71080- si.si_addr = (void *)addr;
71081+ si.si_addr = (void __user *)addr;
71082 #ifdef __ARCH_SI_TRAPNO
71083 si.si_trapno = trapno;
71084 #endif
71085@@ -1038,7 +1038,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71086 }
71087
71088 nr_pages = 1 << compound_trans_order(hpage);
71089- atomic_long_add(nr_pages, &mce_bad_pages);
71090+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
71091
71092 /*
71093 * We need/can do nothing about count=0 pages.
71094@@ -1068,7 +1068,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71095 if (!PageHWPoison(hpage)
71096 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
71097 || (p != hpage && TestSetPageHWPoison(hpage))) {
71098- atomic_long_sub(nr_pages, &mce_bad_pages);
71099+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71100 return 0;
71101 }
71102 set_page_hwpoison_huge_page(hpage);
71103@@ -1126,7 +1126,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71104 }
71105 if (hwpoison_filter(p)) {
71106 if (TestClearPageHWPoison(p))
71107- atomic_long_sub(nr_pages, &mce_bad_pages);
71108+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71109 unlock_page(hpage);
71110 put_page(hpage);
71111 return 0;
71112@@ -1321,7 +1321,7 @@ int unpoison_memory(unsigned long pfn)
71113 return 0;
71114 }
71115 if (TestClearPageHWPoison(p))
71116- atomic_long_sub(nr_pages, &mce_bad_pages);
71117+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71118 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
71119 return 0;
71120 }
71121@@ -1335,7 +1335,7 @@ int unpoison_memory(unsigned long pfn)
71122 */
71123 if (TestClearPageHWPoison(page)) {
71124 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
71125- atomic_long_sub(nr_pages, &mce_bad_pages);
71126+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71127 freeit = 1;
71128 if (PageHuge(page))
71129 clear_page_hwpoison_huge_page(page);
71130@@ -1448,7 +1448,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
71131 }
71132 done:
71133 if (!PageHWPoison(hpage))
71134- atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
71135+ atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
71136 set_page_hwpoison_huge_page(hpage);
71137 dequeue_hwpoisoned_huge_page(hpage);
71138 /* keep elevated page count for bad page */
71139@@ -1579,7 +1579,7 @@ int soft_offline_page(struct page *page, int flags)
71140 return ret;
71141
71142 done:
71143- atomic_long_add(1, &mce_bad_pages);
71144+ atomic_long_add_unchecked(1, &mce_bad_pages);
71145 SetPageHWPoison(page);
71146 /* keep elevated page count for bad page */
71147 return ret;
71148diff --git a/mm/memory.c b/mm/memory.c
71149index 2466d12..08be4f6 100644
71150--- a/mm/memory.c
71151+++ b/mm/memory.c
71152@@ -434,8 +434,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71153 return;
71154
71155 pmd = pmd_offset(pud, start);
71156+
71157+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
71158 pud_clear(pud);
71159 pmd_free_tlb(tlb, pmd, start);
71160+#endif
71161+
71162 }
71163
71164 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71165@@ -466,9 +470,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71166 if (end - 1 > ceiling - 1)
71167 return;
71168
71169+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
71170 pud = pud_offset(pgd, start);
71171 pgd_clear(pgd);
71172 pud_free_tlb(tlb, pud, start);
71173+#endif
71174+
71175 }
71176
71177 /*
71178@@ -1602,12 +1609,6 @@ no_page_table:
71179 return page;
71180 }
71181
71182-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
71183-{
71184- return stack_guard_page_start(vma, addr) ||
71185- stack_guard_page_end(vma, addr+PAGE_SIZE);
71186-}
71187-
71188 /**
71189 * __get_user_pages() - pin user pages in memory
71190 * @tsk: task_struct of target task
71191@@ -1680,10 +1681,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71192 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
71193 i = 0;
71194
71195- do {
71196+ while (nr_pages) {
71197 struct vm_area_struct *vma;
71198
71199- vma = find_extend_vma(mm, start);
71200+ vma = find_vma(mm, start);
71201 if (!vma && in_gate_area(mm, start)) {
71202 unsigned long pg = start & PAGE_MASK;
71203 pgd_t *pgd;
71204@@ -1731,7 +1732,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71205 goto next_page;
71206 }
71207
71208- if (!vma ||
71209+ if (!vma || start < vma->vm_start ||
71210 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
71211 !(vm_flags & vma->vm_flags))
71212 return i ? : -EFAULT;
71213@@ -1758,11 +1759,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71214 int ret;
71215 unsigned int fault_flags = 0;
71216
71217- /* For mlock, just skip the stack guard page. */
71218- if (foll_flags & FOLL_MLOCK) {
71219- if (stack_guard_page(vma, start))
71220- goto next_page;
71221- }
71222 if (foll_flags & FOLL_WRITE)
71223 fault_flags |= FAULT_FLAG_WRITE;
71224 if (nonblocking)
71225@@ -1836,7 +1832,7 @@ next_page:
71226 start += PAGE_SIZE;
71227 nr_pages--;
71228 } while (nr_pages && start < vma->vm_end);
71229- } while (nr_pages);
71230+ }
71231 return i;
71232 }
71233 EXPORT_SYMBOL(__get_user_pages);
71234@@ -2043,6 +2039,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
71235 page_add_file_rmap(page);
71236 set_pte_at(mm, addr, pte, mk_pte(page, prot));
71237
71238+#ifdef CONFIG_PAX_SEGMEXEC
71239+ pax_mirror_file_pte(vma, addr, page, ptl);
71240+#endif
71241+
71242 retval = 0;
71243 pte_unmap_unlock(pte, ptl);
71244 return retval;
71245@@ -2077,10 +2077,22 @@ out:
71246 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
71247 struct page *page)
71248 {
71249+
71250+#ifdef CONFIG_PAX_SEGMEXEC
71251+ struct vm_area_struct *vma_m;
71252+#endif
71253+
71254 if (addr < vma->vm_start || addr >= vma->vm_end)
71255 return -EFAULT;
71256 if (!page_count(page))
71257 return -EINVAL;
71258+
71259+#ifdef CONFIG_PAX_SEGMEXEC
71260+ vma_m = pax_find_mirror_vma(vma);
71261+ if (vma_m)
71262+ vma_m->vm_flags |= VM_INSERTPAGE;
71263+#endif
71264+
71265 vma->vm_flags |= VM_INSERTPAGE;
71266 return insert_page(vma, addr, page, vma->vm_page_prot);
71267 }
71268@@ -2166,6 +2178,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
71269 unsigned long pfn)
71270 {
71271 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
71272+ BUG_ON(vma->vm_mirror);
71273
71274 if (addr < vma->vm_start || addr >= vma->vm_end)
71275 return -EFAULT;
71276@@ -2373,7 +2386,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
71277
71278 BUG_ON(pud_huge(*pud));
71279
71280- pmd = pmd_alloc(mm, pud, addr);
71281+ pmd = (mm == &init_mm) ?
71282+ pmd_alloc_kernel(mm, pud, addr) :
71283+ pmd_alloc(mm, pud, addr);
71284 if (!pmd)
71285 return -ENOMEM;
71286 do {
71287@@ -2393,7 +2408,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
71288 unsigned long next;
71289 int err;
71290
71291- pud = pud_alloc(mm, pgd, addr);
71292+ pud = (mm == &init_mm) ?
71293+ pud_alloc_kernel(mm, pgd, addr) :
71294+ pud_alloc(mm, pgd, addr);
71295 if (!pud)
71296 return -ENOMEM;
71297 do {
71298@@ -2481,6 +2498,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
71299 copy_user_highpage(dst, src, va, vma);
71300 }
71301
71302+#ifdef CONFIG_PAX_SEGMEXEC
71303+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
71304+{
71305+ struct mm_struct *mm = vma->vm_mm;
71306+ spinlock_t *ptl;
71307+ pte_t *pte, entry;
71308+
71309+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
71310+ entry = *pte;
71311+ if (!pte_present(entry)) {
71312+ if (!pte_none(entry)) {
71313+ BUG_ON(pte_file(entry));
71314+ free_swap_and_cache(pte_to_swp_entry(entry));
71315+ pte_clear_not_present_full(mm, address, pte, 0);
71316+ }
71317+ } else {
71318+ struct page *page;
71319+
71320+ flush_cache_page(vma, address, pte_pfn(entry));
71321+ entry = ptep_clear_flush(vma, address, pte);
71322+ BUG_ON(pte_dirty(entry));
71323+ page = vm_normal_page(vma, address, entry);
71324+ if (page) {
71325+ update_hiwater_rss(mm);
71326+ if (PageAnon(page))
71327+ dec_mm_counter_fast(mm, MM_ANONPAGES);
71328+ else
71329+ dec_mm_counter_fast(mm, MM_FILEPAGES);
71330+ page_remove_rmap(page);
71331+ page_cache_release(page);
71332+ }
71333+ }
71334+ pte_unmap_unlock(pte, ptl);
71335+}
71336+
71337+/* PaX: if vma is mirrored, synchronize the mirror's PTE
71338+ *
71339+ * the ptl of the lower mapped page is held on entry and is not released on exit
71340+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
71341+ */
71342+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71343+{
71344+ struct mm_struct *mm = vma->vm_mm;
71345+ unsigned long address_m;
71346+ spinlock_t *ptl_m;
71347+ struct vm_area_struct *vma_m;
71348+ pmd_t *pmd_m;
71349+ pte_t *pte_m, entry_m;
71350+
71351+ BUG_ON(!page_m || !PageAnon(page_m));
71352+
71353+ vma_m = pax_find_mirror_vma(vma);
71354+ if (!vma_m)
71355+ return;
71356+
71357+ BUG_ON(!PageLocked(page_m));
71358+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71359+ address_m = address + SEGMEXEC_TASK_SIZE;
71360+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71361+ pte_m = pte_offset_map(pmd_m, address_m);
71362+ ptl_m = pte_lockptr(mm, pmd_m);
71363+ if (ptl != ptl_m) {
71364+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71365+ if (!pte_none(*pte_m))
71366+ goto out;
71367+ }
71368+
71369+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71370+ page_cache_get(page_m);
71371+ page_add_anon_rmap(page_m, vma_m, address_m);
71372+ inc_mm_counter_fast(mm, MM_ANONPAGES);
71373+ set_pte_at(mm, address_m, pte_m, entry_m);
71374+ update_mmu_cache(vma_m, address_m, entry_m);
71375+out:
71376+ if (ptl != ptl_m)
71377+ spin_unlock(ptl_m);
71378+ pte_unmap(pte_m);
71379+ unlock_page(page_m);
71380+}
71381+
71382+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71383+{
71384+ struct mm_struct *mm = vma->vm_mm;
71385+ unsigned long address_m;
71386+ spinlock_t *ptl_m;
71387+ struct vm_area_struct *vma_m;
71388+ pmd_t *pmd_m;
71389+ pte_t *pte_m, entry_m;
71390+
71391+ BUG_ON(!page_m || PageAnon(page_m));
71392+
71393+ vma_m = pax_find_mirror_vma(vma);
71394+ if (!vma_m)
71395+ return;
71396+
71397+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71398+ address_m = address + SEGMEXEC_TASK_SIZE;
71399+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71400+ pte_m = pte_offset_map(pmd_m, address_m);
71401+ ptl_m = pte_lockptr(mm, pmd_m);
71402+ if (ptl != ptl_m) {
71403+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71404+ if (!pte_none(*pte_m))
71405+ goto out;
71406+ }
71407+
71408+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71409+ page_cache_get(page_m);
71410+ page_add_file_rmap(page_m);
71411+ inc_mm_counter_fast(mm, MM_FILEPAGES);
71412+ set_pte_at(mm, address_m, pte_m, entry_m);
71413+ update_mmu_cache(vma_m, address_m, entry_m);
71414+out:
71415+ if (ptl != ptl_m)
71416+ spin_unlock(ptl_m);
71417+ pte_unmap(pte_m);
71418+}
71419+
71420+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
71421+{
71422+ struct mm_struct *mm = vma->vm_mm;
71423+ unsigned long address_m;
71424+ spinlock_t *ptl_m;
71425+ struct vm_area_struct *vma_m;
71426+ pmd_t *pmd_m;
71427+ pte_t *pte_m, entry_m;
71428+
71429+ vma_m = pax_find_mirror_vma(vma);
71430+ if (!vma_m)
71431+ return;
71432+
71433+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71434+ address_m = address + SEGMEXEC_TASK_SIZE;
71435+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71436+ pte_m = pte_offset_map(pmd_m, address_m);
71437+ ptl_m = pte_lockptr(mm, pmd_m);
71438+ if (ptl != ptl_m) {
71439+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71440+ if (!pte_none(*pte_m))
71441+ goto out;
71442+ }
71443+
71444+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
71445+ set_pte_at(mm, address_m, pte_m, entry_m);
71446+out:
71447+ if (ptl != ptl_m)
71448+ spin_unlock(ptl_m);
71449+ pte_unmap(pte_m);
71450+}
71451+
71452+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
71453+{
71454+ struct page *page_m;
71455+ pte_t entry;
71456+
71457+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
71458+ goto out;
71459+
71460+ entry = *pte;
71461+ page_m = vm_normal_page(vma, address, entry);
71462+ if (!page_m)
71463+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
71464+ else if (PageAnon(page_m)) {
71465+ if (pax_find_mirror_vma(vma)) {
71466+ pte_unmap_unlock(pte, ptl);
71467+ lock_page(page_m);
71468+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
71469+ if (pte_same(entry, *pte))
71470+ pax_mirror_anon_pte(vma, address, page_m, ptl);
71471+ else
71472+ unlock_page(page_m);
71473+ }
71474+ } else
71475+ pax_mirror_file_pte(vma, address, page_m, ptl);
71476+
71477+out:
71478+ pte_unmap_unlock(pte, ptl);
71479+}
71480+#endif
71481+
71482 /*
71483 * This routine handles present pages, when users try to write
71484 * to a shared page. It is done by copying the page to a new address
71485@@ -2692,6 +2889,12 @@ gotten:
71486 */
71487 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71488 if (likely(pte_same(*page_table, orig_pte))) {
71489+
71490+#ifdef CONFIG_PAX_SEGMEXEC
71491+ if (pax_find_mirror_vma(vma))
71492+ BUG_ON(!trylock_page(new_page));
71493+#endif
71494+
71495 if (old_page) {
71496 if (!PageAnon(old_page)) {
71497 dec_mm_counter_fast(mm, MM_FILEPAGES);
71498@@ -2743,6 +2946,10 @@ gotten:
71499 page_remove_rmap(old_page);
71500 }
71501
71502+#ifdef CONFIG_PAX_SEGMEXEC
71503+ pax_mirror_anon_pte(vma, address, new_page, ptl);
71504+#endif
71505+
71506 /* Free the old page.. */
71507 new_page = old_page;
71508 ret |= VM_FAULT_WRITE;
71509@@ -3022,6 +3229,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
71510 swap_free(entry);
71511 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
71512 try_to_free_swap(page);
71513+
71514+#ifdef CONFIG_PAX_SEGMEXEC
71515+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
71516+#endif
71517+
71518 unlock_page(page);
71519 if (swapcache) {
71520 /*
71521@@ -3045,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
71522
71523 /* No need to invalidate - it was non-present before */
71524 update_mmu_cache(vma, address, page_table);
71525+
71526+#ifdef CONFIG_PAX_SEGMEXEC
71527+ pax_mirror_anon_pte(vma, address, page, ptl);
71528+#endif
71529+
71530 unlock:
71531 pte_unmap_unlock(page_table, ptl);
71532 out:
71533@@ -3064,40 +3281,6 @@ out_release:
71534 }
71535
71536 /*
71537- * This is like a special single-page "expand_{down|up}wards()",
71538- * except we must first make sure that 'address{-|+}PAGE_SIZE'
71539- * doesn't hit another vma.
71540- */
71541-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
71542-{
71543- address &= PAGE_MASK;
71544- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
71545- struct vm_area_struct *prev = vma->vm_prev;
71546-
71547- /*
71548- * Is there a mapping abutting this one below?
71549- *
71550- * That's only ok if it's the same stack mapping
71551- * that has gotten split..
71552- */
71553- if (prev && prev->vm_end == address)
71554- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
71555-
71556- expand_downwards(vma, address - PAGE_SIZE);
71557- }
71558- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
71559- struct vm_area_struct *next = vma->vm_next;
71560-
71561- /* As VM_GROWSDOWN but s/below/above/ */
71562- if (next && next->vm_start == address + PAGE_SIZE)
71563- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
71564-
71565- expand_upwards(vma, address + PAGE_SIZE);
71566- }
71567- return 0;
71568-}
71569-
71570-/*
71571 * We enter with non-exclusive mmap_sem (to exclude vma changes,
71572 * but allow concurrent faults), and pte mapped but not yet locked.
71573 * We return with mmap_sem still held, but pte unmapped and unlocked.
71574@@ -3106,27 +3289,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71575 unsigned long address, pte_t *page_table, pmd_t *pmd,
71576 unsigned int flags)
71577 {
71578- struct page *page;
71579+ struct page *page = NULL;
71580 spinlock_t *ptl;
71581 pte_t entry;
71582
71583- pte_unmap(page_table);
71584-
71585- /* Check if we need to add a guard page to the stack */
71586- if (check_stack_guard_page(vma, address) < 0)
71587- return VM_FAULT_SIGBUS;
71588-
71589- /* Use the zero-page for reads */
71590 if (!(flags & FAULT_FLAG_WRITE)) {
71591 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
71592 vma->vm_page_prot));
71593- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71594+ ptl = pte_lockptr(mm, pmd);
71595+ spin_lock(ptl);
71596 if (!pte_none(*page_table))
71597 goto unlock;
71598 goto setpte;
71599 }
71600
71601 /* Allocate our own private page. */
71602+ pte_unmap(page_table);
71603+
71604 if (unlikely(anon_vma_prepare(vma)))
71605 goto oom;
71606 page = alloc_zeroed_user_highpage_movable(vma, address);
71607@@ -3145,6 +3324,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71608 if (!pte_none(*page_table))
71609 goto release;
71610
71611+#ifdef CONFIG_PAX_SEGMEXEC
71612+ if (pax_find_mirror_vma(vma))
71613+ BUG_ON(!trylock_page(page));
71614+#endif
71615+
71616 inc_mm_counter_fast(mm, MM_ANONPAGES);
71617 page_add_new_anon_rmap(page, vma, address);
71618 setpte:
71619@@ -3152,6 +3336,12 @@ setpte:
71620
71621 /* No need to invalidate - it was non-present before */
71622 update_mmu_cache(vma, address, page_table);
71623+
71624+#ifdef CONFIG_PAX_SEGMEXEC
71625+ if (page)
71626+ pax_mirror_anon_pte(vma, address, page, ptl);
71627+#endif
71628+
71629 unlock:
71630 pte_unmap_unlock(page_table, ptl);
71631 return 0;
71632@@ -3295,6 +3485,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71633 */
71634 /* Only go through if we didn't race with anybody else... */
71635 if (likely(pte_same(*page_table, orig_pte))) {
71636+
71637+#ifdef CONFIG_PAX_SEGMEXEC
71638+ if (anon && pax_find_mirror_vma(vma))
71639+ BUG_ON(!trylock_page(page));
71640+#endif
71641+
71642 flush_icache_page(vma, page);
71643 entry = mk_pte(page, vma->vm_page_prot);
71644 if (flags & FAULT_FLAG_WRITE)
71645@@ -3314,6 +3510,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71646
71647 /* no need to invalidate: a not-present page won't be cached */
71648 update_mmu_cache(vma, address, page_table);
71649+
71650+#ifdef CONFIG_PAX_SEGMEXEC
71651+ if (anon)
71652+ pax_mirror_anon_pte(vma, address, page, ptl);
71653+ else
71654+ pax_mirror_file_pte(vma, address, page, ptl);
71655+#endif
71656+
71657 } else {
71658 if (cow_page)
71659 mem_cgroup_uncharge_page(cow_page);
71660@@ -3467,6 +3671,12 @@ int handle_pte_fault(struct mm_struct *mm,
71661 if (flags & FAULT_FLAG_WRITE)
71662 flush_tlb_fix_spurious_fault(vma, address);
71663 }
71664+
71665+#ifdef CONFIG_PAX_SEGMEXEC
71666+ pax_mirror_pte(vma, address, pte, pmd, ptl);
71667+ return 0;
71668+#endif
71669+
71670 unlock:
71671 pte_unmap_unlock(pte, ptl);
71672 return 0;
71673@@ -3483,6 +3693,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71674 pmd_t *pmd;
71675 pte_t *pte;
71676
71677+#ifdef CONFIG_PAX_SEGMEXEC
71678+ struct vm_area_struct *vma_m;
71679+#endif
71680+
71681 __set_current_state(TASK_RUNNING);
71682
71683 count_vm_event(PGFAULT);
71684@@ -3494,6 +3708,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71685 if (unlikely(is_vm_hugetlb_page(vma)))
71686 return hugetlb_fault(mm, vma, address, flags);
71687
71688+#ifdef CONFIG_PAX_SEGMEXEC
71689+ vma_m = pax_find_mirror_vma(vma);
71690+ if (vma_m) {
71691+ unsigned long address_m;
71692+ pgd_t *pgd_m;
71693+ pud_t *pud_m;
71694+ pmd_t *pmd_m;
71695+
71696+ if (vma->vm_start > vma_m->vm_start) {
71697+ address_m = address;
71698+ address -= SEGMEXEC_TASK_SIZE;
71699+ vma = vma_m;
71700+ } else
71701+ address_m = address + SEGMEXEC_TASK_SIZE;
71702+
71703+ pgd_m = pgd_offset(mm, address_m);
71704+ pud_m = pud_alloc(mm, pgd_m, address_m);
71705+ if (!pud_m)
71706+ return VM_FAULT_OOM;
71707+ pmd_m = pmd_alloc(mm, pud_m, address_m);
71708+ if (!pmd_m)
71709+ return VM_FAULT_OOM;
71710+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
71711+ return VM_FAULT_OOM;
71712+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
71713+ }
71714+#endif
71715+
71716 retry:
71717 pgd = pgd_offset(mm, address);
71718 pud = pud_alloc(mm, pgd, address);
71719@@ -3535,7 +3777,7 @@ retry:
71720 * run pte_offset_map on the pmd, if an huge pmd could
71721 * materialize from under us from a different thread.
71722 */
71723- if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
71724+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71725 return VM_FAULT_OOM;
71726 /* if an huge pmd materialized from under us just retry later */
71727 if (unlikely(pmd_trans_huge(*pmd)))
71728@@ -3572,6 +3814,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
71729 spin_unlock(&mm->page_table_lock);
71730 return 0;
71731 }
71732+
71733+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
71734+{
71735+ pud_t *new = pud_alloc_one(mm, address);
71736+ if (!new)
71737+ return -ENOMEM;
71738+
71739+ smp_wmb(); /* See comment in __pte_alloc */
71740+
71741+ spin_lock(&mm->page_table_lock);
71742+ if (pgd_present(*pgd)) /* Another has populated it */
71743+ pud_free(mm, new);
71744+ else
71745+ pgd_populate_kernel(mm, pgd, new);
71746+ spin_unlock(&mm->page_table_lock);
71747+ return 0;
71748+}
71749 #endif /* __PAGETABLE_PUD_FOLDED */
71750
71751 #ifndef __PAGETABLE_PMD_FOLDED
71752@@ -3602,6 +3861,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
71753 spin_unlock(&mm->page_table_lock);
71754 return 0;
71755 }
71756+
71757+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
71758+{
71759+ pmd_t *new = pmd_alloc_one(mm, address);
71760+ if (!new)
71761+ return -ENOMEM;
71762+
71763+ smp_wmb(); /* See comment in __pte_alloc */
71764+
71765+ spin_lock(&mm->page_table_lock);
71766+#ifndef __ARCH_HAS_4LEVEL_HACK
71767+ if (pud_present(*pud)) /* Another has populated it */
71768+ pmd_free(mm, new);
71769+ else
71770+ pud_populate_kernel(mm, pud, new);
71771+#else
71772+ if (pgd_present(*pud)) /* Another has populated it */
71773+ pmd_free(mm, new);
71774+ else
71775+ pgd_populate_kernel(mm, pud, new);
71776+#endif /* __ARCH_HAS_4LEVEL_HACK */
71777+ spin_unlock(&mm->page_table_lock);
71778+ return 0;
71779+}
71780 #endif /* __PAGETABLE_PMD_FOLDED */
71781
71782 int make_pages_present(unsigned long addr, unsigned long end)
71783@@ -3639,7 +3922,7 @@ static int __init gate_vma_init(void)
71784 gate_vma.vm_start = FIXADDR_USER_START;
71785 gate_vma.vm_end = FIXADDR_USER_END;
71786 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
71787- gate_vma.vm_page_prot = __P101;
71788+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
71789
71790 return 0;
71791 }
71792diff --git a/mm/mempolicy.c b/mm/mempolicy.c
71793index 1d771e4..f9a6808 100644
71794--- a/mm/mempolicy.c
71795+++ b/mm/mempolicy.c
71796@@ -619,6 +619,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71797 unsigned long vmstart;
71798 unsigned long vmend;
71799
71800+#ifdef CONFIG_PAX_SEGMEXEC
71801+ struct vm_area_struct *vma_m;
71802+#endif
71803+
71804 vma = find_vma(mm, start);
71805 if (!vma || vma->vm_start > start)
71806 return -EFAULT;
71807@@ -672,6 +676,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71808 if (err)
71809 goto out;
71810 }
71811+
71812+#ifdef CONFIG_PAX_SEGMEXEC
71813+ vma_m = pax_find_mirror_vma(vma);
71814+ if (vma_m && vma_m->vm_ops && vma_m->vm_ops->set_policy) {
71815+ err = vma_m->vm_ops->set_policy(vma_m, new_pol);
71816+ if (err)
71817+ goto out;
71818+ }
71819+#endif
71820+
71821 }
71822
71823 out:
71824@@ -1125,6 +1139,17 @@ static long do_mbind(unsigned long start, unsigned long len,
71825
71826 if (end < start)
71827 return -EINVAL;
71828+
71829+#ifdef CONFIG_PAX_SEGMEXEC
71830+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
71831+ if (end > SEGMEXEC_TASK_SIZE)
71832+ return -EINVAL;
71833+ } else
71834+#endif
71835+
71836+ if (end > TASK_SIZE)
71837+ return -EINVAL;
71838+
71839 if (end == start)
71840 return 0;
71841
71842@@ -1348,8 +1373,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71843 */
71844 tcred = __task_cred(task);
71845 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
71846- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
71847- !capable(CAP_SYS_NICE)) {
71848+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
71849 rcu_read_unlock();
71850 err = -EPERM;
71851 goto out_put;
71852@@ -1380,6 +1404,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71853 goto out;
71854 }
71855
71856+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71857+ if (mm != current->mm &&
71858+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
71859+ mmput(mm);
71860+ err = -EPERM;
71861+ goto out;
71862+ }
71863+#endif
71864+
71865 err = do_migrate_pages(mm, old, new,
71866 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
71867
71868diff --git a/mm/mlock.c b/mm/mlock.c
71869index ef726e8..cd7f1ec 100644
71870--- a/mm/mlock.c
71871+++ b/mm/mlock.c
71872@@ -13,6 +13,7 @@
71873 #include <linux/pagemap.h>
71874 #include <linux/mempolicy.h>
71875 #include <linux/syscalls.h>
71876+#include <linux/security.h>
71877 #include <linux/sched.h>
71878 #include <linux/export.h>
71879 #include <linux/rmap.h>
71880@@ -376,7 +377,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
71881 {
71882 unsigned long nstart, end, tmp;
71883 struct vm_area_struct * vma, * prev;
71884- int error;
71885+ int error = 0;
71886
71887 VM_BUG_ON(start & ~PAGE_MASK);
71888 VM_BUG_ON(len != PAGE_ALIGN(len));
71889@@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
71890 return -EINVAL;
71891 if (end == start)
71892 return 0;
71893+ if (end > TASK_SIZE)
71894+ return -EINVAL;
71895+
71896 vma = find_vma(current->mm, start);
71897 if (!vma || vma->vm_start > start)
71898 return -ENOMEM;
71899@@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
71900 for (nstart = start ; ; ) {
71901 vm_flags_t newflags;
71902
71903+#ifdef CONFIG_PAX_SEGMEXEC
71904+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71905+ break;
71906+#endif
71907+
71908 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
71909
71910 newflags = vma->vm_flags | VM_LOCKED;
71911@@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
71912 lock_limit >>= PAGE_SHIFT;
71913
71914 /* check against resource limits */
71915+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
71916 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
71917 error = do_mlock(start, len, 1);
71918 up_write(&current->mm->mmap_sem);
71919@@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
71920 static int do_mlockall(int flags)
71921 {
71922 struct vm_area_struct * vma, * prev = NULL;
71923- unsigned int def_flags = 0;
71924
71925 if (flags & MCL_FUTURE)
71926- def_flags = VM_LOCKED;
71927- current->mm->def_flags = def_flags;
71928+ current->mm->def_flags |= VM_LOCKED;
71929+ else
71930+ current->mm->def_flags &= ~VM_LOCKED;
71931 if (flags == MCL_FUTURE)
71932 goto out;
71933
71934 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
71935 vm_flags_t newflags;
71936
71937+#ifdef CONFIG_PAX_SEGMEXEC
71938+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71939+ break;
71940+#endif
71941+
71942+ BUG_ON(vma->vm_end > TASK_SIZE);
71943 newflags = vma->vm_flags | VM_LOCKED;
71944 if (!(flags & MCL_CURRENT))
71945 newflags &= ~VM_LOCKED;
71946@@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
71947 lock_limit >>= PAGE_SHIFT;
71948
71949 ret = -ENOMEM;
71950+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
71951 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
71952 capable(CAP_IPC_LOCK))
71953 ret = do_mlockall(flags);
71954diff --git a/mm/mmap.c b/mm/mmap.c
71955index 3edfcdf..4a27ae9 100644
71956--- a/mm/mmap.c
71957+++ b/mm/mmap.c
71958@@ -47,6 +47,16 @@
71959 #define arch_rebalance_pgtables(addr, len) (addr)
71960 #endif
71961
71962+static inline void verify_mm_writelocked(struct mm_struct *mm)
71963+{
71964+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
71965+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
71966+ up_read(&mm->mmap_sem);
71967+ BUG();
71968+ }
71969+#endif
71970+}
71971+
71972 static void unmap_region(struct mm_struct *mm,
71973 struct vm_area_struct *vma, struct vm_area_struct *prev,
71974 unsigned long start, unsigned long end);
71975@@ -72,22 +82,32 @@ static void unmap_region(struct mm_struct *mm,
71976 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
71977 *
71978 */
71979-pgprot_t protection_map[16] = {
71980+pgprot_t protection_map[16] __read_only = {
71981 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
71982 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
71983 };
71984
71985-pgprot_t vm_get_page_prot(unsigned long vm_flags)
71986+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
71987 {
71988- return __pgprot(pgprot_val(protection_map[vm_flags &
71989+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
71990 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
71991 pgprot_val(arch_vm_get_page_prot(vm_flags)));
71992+
71993+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71994+ if (!(__supported_pte_mask & _PAGE_NX) &&
71995+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
71996+ (vm_flags & (VM_READ | VM_WRITE)))
71997+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
71998+#endif
71999+
72000+ return prot;
72001 }
72002 EXPORT_SYMBOL(vm_get_page_prot);
72003
72004 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
72005 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
72006 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
72007+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
72008 /*
72009 * Make sure vm_committed_as in one cacheline and not cacheline shared with
72010 * other variables. It can be updated by several CPUs frequently.
72011@@ -229,6 +249,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
72012 struct vm_area_struct *next = vma->vm_next;
72013
72014 might_sleep();
72015+ BUG_ON(vma->vm_mirror);
72016 if (vma->vm_ops && vma->vm_ops->close)
72017 vma->vm_ops->close(vma);
72018 if (vma->vm_file) {
72019@@ -275,6 +296,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
72020 * not page aligned -Ram Gupta
72021 */
72022 rlim = rlimit(RLIMIT_DATA);
72023+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
72024 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
72025 (mm->end_data - mm->start_data) > rlim)
72026 goto out;
72027@@ -708,6 +730,12 @@ static int
72028 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
72029 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72030 {
72031+
72032+#ifdef CONFIG_PAX_SEGMEXEC
72033+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
72034+ return 0;
72035+#endif
72036+
72037 if (is_mergeable_vma(vma, file, vm_flags) &&
72038 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72039 if (vma->vm_pgoff == vm_pgoff)
72040@@ -727,6 +755,12 @@ static int
72041 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72042 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72043 {
72044+
72045+#ifdef CONFIG_PAX_SEGMEXEC
72046+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
72047+ return 0;
72048+#endif
72049+
72050 if (is_mergeable_vma(vma, file, vm_flags) &&
72051 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72052 pgoff_t vm_pglen;
72053@@ -769,13 +803,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72054 struct vm_area_struct *vma_merge(struct mm_struct *mm,
72055 struct vm_area_struct *prev, unsigned long addr,
72056 unsigned long end, unsigned long vm_flags,
72057- struct anon_vma *anon_vma, struct file *file,
72058+ struct anon_vma *anon_vma, struct file *file,
72059 pgoff_t pgoff, struct mempolicy *policy)
72060 {
72061 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
72062 struct vm_area_struct *area, *next;
72063 int err;
72064
72065+#ifdef CONFIG_PAX_SEGMEXEC
72066+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
72067+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
72068+
72069+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
72070+#endif
72071+
72072 /*
72073 * We later require that vma->vm_flags == vm_flags,
72074 * so this tests vma->vm_flags & VM_SPECIAL, too.
72075@@ -791,6 +832,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72076 if (next && next->vm_end == end) /* cases 6, 7, 8 */
72077 next = next->vm_next;
72078
72079+#ifdef CONFIG_PAX_SEGMEXEC
72080+ if (prev)
72081+ prev_m = pax_find_mirror_vma(prev);
72082+ if (area)
72083+ area_m = pax_find_mirror_vma(area);
72084+ if (next)
72085+ next_m = pax_find_mirror_vma(next);
72086+#endif
72087+
72088 /*
72089 * Can it merge with the predecessor?
72090 */
72091@@ -810,9 +860,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72092 /* cases 1, 6 */
72093 err = vma_adjust(prev, prev->vm_start,
72094 next->vm_end, prev->vm_pgoff, NULL);
72095- } else /* cases 2, 5, 7 */
72096+
72097+#ifdef CONFIG_PAX_SEGMEXEC
72098+ if (!err && prev_m)
72099+ err = vma_adjust(prev_m, prev_m->vm_start,
72100+ next_m->vm_end, prev_m->vm_pgoff, NULL);
72101+#endif
72102+
72103+ } else { /* cases 2, 5, 7 */
72104 err = vma_adjust(prev, prev->vm_start,
72105 end, prev->vm_pgoff, NULL);
72106+
72107+#ifdef CONFIG_PAX_SEGMEXEC
72108+ if (!err && prev_m)
72109+ err = vma_adjust(prev_m, prev_m->vm_start,
72110+ end_m, prev_m->vm_pgoff, NULL);
72111+#endif
72112+
72113+ }
72114 if (err)
72115 return NULL;
72116 khugepaged_enter_vma_merge(prev);
72117@@ -826,12 +891,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72118 mpol_equal(policy, vma_policy(next)) &&
72119 can_vma_merge_before(next, vm_flags,
72120 anon_vma, file, pgoff+pglen)) {
72121- if (prev && addr < prev->vm_end) /* case 4 */
72122+ if (prev && addr < prev->vm_end) { /* case 4 */
72123 err = vma_adjust(prev, prev->vm_start,
72124 addr, prev->vm_pgoff, NULL);
72125- else /* cases 3, 8 */
72126+
72127+#ifdef CONFIG_PAX_SEGMEXEC
72128+ if (!err && prev_m)
72129+ err = vma_adjust(prev_m, prev_m->vm_start,
72130+ addr_m, prev_m->vm_pgoff, NULL);
72131+#endif
72132+
72133+ } else { /* cases 3, 8 */
72134 err = vma_adjust(area, addr, next->vm_end,
72135 next->vm_pgoff - pglen, NULL);
72136+
72137+#ifdef CONFIG_PAX_SEGMEXEC
72138+ if (!err && area_m)
72139+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
72140+ next_m->vm_pgoff - pglen, NULL);
72141+#endif
72142+
72143+ }
72144 if (err)
72145 return NULL;
72146 khugepaged_enter_vma_merge(area);
72147@@ -940,14 +1020,11 @@ none:
72148 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
72149 struct file *file, long pages)
72150 {
72151- const unsigned long stack_flags
72152- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
72153-
72154 if (file) {
72155 mm->shared_vm += pages;
72156 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
72157 mm->exec_vm += pages;
72158- } else if (flags & stack_flags)
72159+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
72160 mm->stack_vm += pages;
72161 if (flags & (VM_RESERVED|VM_IO))
72162 mm->reserved_vm += pages;
72163@@ -985,7 +1062,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72164 * (the exception is when the underlying filesystem is noexec
72165 * mounted, in which case we dont add PROT_EXEC.)
72166 */
72167- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72168+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72169 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
72170 prot |= PROT_EXEC;
72171
72172@@ -1011,7 +1088,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72173 /* Obtain the address to map to. we verify (or select) it and ensure
72174 * that it represents a valid section of the address space.
72175 */
72176- addr = get_unmapped_area(file, addr, len, pgoff, flags);
72177+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
72178 if (addr & ~PAGE_MASK)
72179 return addr;
72180
72181@@ -1022,6 +1099,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72182 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
72183 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
72184
72185+#ifdef CONFIG_PAX_MPROTECT
72186+ if (mm->pax_flags & MF_PAX_MPROTECT) {
72187+#ifndef CONFIG_PAX_MPROTECT_COMPAT
72188+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
72189+ gr_log_rwxmmap(file);
72190+
72191+#ifdef CONFIG_PAX_EMUPLT
72192+ vm_flags &= ~VM_EXEC;
72193+#else
72194+ return -EPERM;
72195+#endif
72196+
72197+ }
72198+
72199+ if (!(vm_flags & VM_EXEC))
72200+ vm_flags &= ~VM_MAYEXEC;
72201+#else
72202+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72203+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72204+#endif
72205+ else
72206+ vm_flags &= ~VM_MAYWRITE;
72207+ }
72208+#endif
72209+
72210+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72211+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
72212+ vm_flags &= ~VM_PAGEEXEC;
72213+#endif
72214+
72215 if (flags & MAP_LOCKED)
72216 if (!can_do_mlock())
72217 return -EPERM;
72218@@ -1033,6 +1140,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72219 locked += mm->locked_vm;
72220 lock_limit = rlimit(RLIMIT_MEMLOCK);
72221 lock_limit >>= PAGE_SHIFT;
72222+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72223 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
72224 return -EAGAIN;
72225 }
72226@@ -1099,6 +1207,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72227 }
72228 }
72229
72230+ if (!gr_acl_handle_mmap(file, prot))
72231+ return -EACCES;
72232+
72233 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
72234 }
72235
72236@@ -1175,7 +1286,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
72237 vm_flags_t vm_flags = vma->vm_flags;
72238
72239 /* If it was private or non-writable, the write bit is already clear */
72240- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
72241+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
72242 return 0;
72243
72244 /* The backer wishes to know when pages are first written to? */
72245@@ -1224,14 +1335,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
72246 unsigned long charged = 0;
72247 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
72248
72249+#ifdef CONFIG_PAX_SEGMEXEC
72250+ struct vm_area_struct *vma_m = NULL;
72251+#endif
72252+
72253+ /*
72254+ * mm->mmap_sem is required to protect against another thread
72255+ * changing the mappings in case we sleep.
72256+ */
72257+ verify_mm_writelocked(mm);
72258+
72259 /* Clear old maps */
72260 error = -ENOMEM;
72261-munmap_back:
72262 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72263 if (vma && vma->vm_start < addr + len) {
72264 if (do_munmap(mm, addr, len))
72265 return -ENOMEM;
72266- goto munmap_back;
72267+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72268+ BUG_ON(vma && vma->vm_start < addr + len);
72269 }
72270
72271 /* Check against address space limit. */
72272@@ -1280,6 +1401,16 @@ munmap_back:
72273 goto unacct_error;
72274 }
72275
72276+#ifdef CONFIG_PAX_SEGMEXEC
72277+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
72278+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72279+ if (!vma_m) {
72280+ error = -ENOMEM;
72281+ goto free_vma;
72282+ }
72283+ }
72284+#endif
72285+
72286 vma->vm_mm = mm;
72287 vma->vm_start = addr;
72288 vma->vm_end = addr + len;
72289@@ -1304,6 +1435,19 @@ munmap_back:
72290 error = file->f_op->mmap(file, vma);
72291 if (error)
72292 goto unmap_and_free_vma;
72293+
72294+#ifdef CONFIG_PAX_SEGMEXEC
72295+ if (vma_m && (vm_flags & VM_EXECUTABLE))
72296+ added_exe_file_vma(mm);
72297+#endif
72298+
72299+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72300+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
72301+ vma->vm_flags |= VM_PAGEEXEC;
72302+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72303+ }
72304+#endif
72305+
72306 if (vm_flags & VM_EXECUTABLE)
72307 added_exe_file_vma(mm);
72308
72309@@ -1341,6 +1485,11 @@ munmap_back:
72310 vma_link(mm, vma, prev, rb_link, rb_parent);
72311 file = vma->vm_file;
72312
72313+#ifdef CONFIG_PAX_SEGMEXEC
72314+ if (vma_m)
72315+ BUG_ON(pax_mirror_vma(vma_m, vma));
72316+#endif
72317+
72318 /* Once vma denies write, undo our temporary denial count */
72319 if (correct_wcount)
72320 atomic_inc(&inode->i_writecount);
72321@@ -1349,6 +1498,7 @@ out:
72322
72323 mm->total_vm += len >> PAGE_SHIFT;
72324 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
72325+ track_exec_limit(mm, addr, addr + len, vm_flags);
72326 if (vm_flags & VM_LOCKED) {
72327 if (!mlock_vma_pages_range(vma, addr, addr + len))
72328 mm->locked_vm += (len >> PAGE_SHIFT);
72329@@ -1371,6 +1521,12 @@ unmap_and_free_vma:
72330 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
72331 charged = 0;
72332 free_vma:
72333+
72334+#ifdef CONFIG_PAX_SEGMEXEC
72335+ if (vma_m)
72336+ kmem_cache_free(vm_area_cachep, vma_m);
72337+#endif
72338+
72339 kmem_cache_free(vm_area_cachep, vma);
72340 unacct_error:
72341 if (charged)
72342@@ -1378,6 +1534,44 @@ unacct_error:
72343 return error;
72344 }
72345
72346+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
72347+{
72348+ if (!vma) {
72349+#ifdef CONFIG_STACK_GROWSUP
72350+ if (addr > sysctl_heap_stack_gap)
72351+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
72352+ else
72353+ vma = find_vma(current->mm, 0);
72354+ if (vma && (vma->vm_flags & VM_GROWSUP))
72355+ return false;
72356+#endif
72357+ return true;
72358+ }
72359+
72360+ if (addr + len > vma->vm_start)
72361+ return false;
72362+
72363+ if (vma->vm_flags & VM_GROWSDOWN)
72364+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
72365+#ifdef CONFIG_STACK_GROWSUP
72366+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
72367+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
72368+#endif
72369+
72370+ return true;
72371+}
72372+
72373+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
72374+{
72375+ if (vma->vm_start < len)
72376+ return -ENOMEM;
72377+ if (!(vma->vm_flags & VM_GROWSDOWN))
72378+ return vma->vm_start - len;
72379+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
72380+ return vma->vm_start - len - sysctl_heap_stack_gap;
72381+ return -ENOMEM;
72382+}
72383+
72384 /* Get an address range which is currently unmapped.
72385 * For shmat() with addr=0.
72386 *
72387@@ -1404,18 +1598,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
72388 if (flags & MAP_FIXED)
72389 return addr;
72390
72391+#ifdef CONFIG_PAX_RANDMMAP
72392+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
72393+#endif
72394+
72395 if (addr) {
72396 addr = PAGE_ALIGN(addr);
72397- vma = find_vma(mm, addr);
72398- if (TASK_SIZE - len >= addr &&
72399- (!vma || addr + len <= vma->vm_start))
72400- return addr;
72401+ if (TASK_SIZE - len >= addr) {
72402+ vma = find_vma(mm, addr);
72403+ if (check_heap_stack_gap(vma, addr, len))
72404+ return addr;
72405+ }
72406 }
72407 if (len > mm->cached_hole_size) {
72408- start_addr = addr = mm->free_area_cache;
72409+ start_addr = addr = mm->free_area_cache;
72410 } else {
72411- start_addr = addr = TASK_UNMAPPED_BASE;
72412- mm->cached_hole_size = 0;
72413+ start_addr = addr = mm->mmap_base;
72414+ mm->cached_hole_size = 0;
72415 }
72416
72417 full_search:
72418@@ -1426,34 +1625,40 @@ full_search:
72419 * Start a new search - just in case we missed
72420 * some holes.
72421 */
72422- if (start_addr != TASK_UNMAPPED_BASE) {
72423- addr = TASK_UNMAPPED_BASE;
72424- start_addr = addr;
72425+ if (start_addr != mm->mmap_base) {
72426+ start_addr = addr = mm->mmap_base;
72427 mm->cached_hole_size = 0;
72428 goto full_search;
72429 }
72430 return -ENOMEM;
72431 }
72432- if (!vma || addr + len <= vma->vm_start) {
72433- /*
72434- * Remember the place where we stopped the search:
72435- */
72436- mm->free_area_cache = addr + len;
72437- return addr;
72438- }
72439+ if (check_heap_stack_gap(vma, addr, len))
72440+ break;
72441 if (addr + mm->cached_hole_size < vma->vm_start)
72442 mm->cached_hole_size = vma->vm_start - addr;
72443 addr = vma->vm_end;
72444 }
72445+
72446+ /*
72447+ * Remember the place where we stopped the search:
72448+ */
72449+ mm->free_area_cache = addr + len;
72450+ return addr;
72451 }
72452 #endif
72453
72454 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
72455 {
72456+
72457+#ifdef CONFIG_PAX_SEGMEXEC
72458+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72459+ return;
72460+#endif
72461+
72462 /*
72463 * Is this a new hole at the lowest possible address?
72464 */
72465- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
72466+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
72467 mm->free_area_cache = addr;
72468 }
72469
72470@@ -1469,7 +1674,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72471 {
72472 struct vm_area_struct *vma;
72473 struct mm_struct *mm = current->mm;
72474- unsigned long addr = addr0, start_addr;
72475+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
72476
72477 /* requested length too big for entire address space */
72478 if (len > TASK_SIZE)
72479@@ -1478,13 +1683,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72480 if (flags & MAP_FIXED)
72481 return addr;
72482
72483+#ifdef CONFIG_PAX_RANDMMAP
72484+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
72485+#endif
72486+
72487 /* requesting a specific address */
72488 if (addr) {
72489 addr = PAGE_ALIGN(addr);
72490- vma = find_vma(mm, addr);
72491- if (TASK_SIZE - len >= addr &&
72492- (!vma || addr + len <= vma->vm_start))
72493- return addr;
72494+ if (TASK_SIZE - len >= addr) {
72495+ vma = find_vma(mm, addr);
72496+ if (check_heap_stack_gap(vma, addr, len))
72497+ return addr;
72498+ }
72499 }
72500
72501 /* check if free_area_cache is useful for us */
72502@@ -1508,7 +1718,7 @@ try_again:
72503 * return with success:
72504 */
72505 vma = find_vma(mm, addr);
72506- if (!vma || addr+len <= vma->vm_start)
72507+ if (check_heap_stack_gap(vma, addr, len))
72508 /* remember the address as a hint for next time */
72509 return (mm->free_area_cache = addr);
72510
72511@@ -1517,8 +1727,8 @@ try_again:
72512 mm->cached_hole_size = vma->vm_start - addr;
72513
72514 /* try just below the current vma->vm_start */
72515- addr = vma->vm_start-len;
72516- } while (len < vma->vm_start);
72517+ addr = skip_heap_stack_gap(vma, len);
72518+ } while (!IS_ERR_VALUE(addr));
72519
72520 fail:
72521 /*
72522@@ -1541,13 +1751,21 @@ fail:
72523 * can happen with large stack limits and large mmap()
72524 * allocations.
72525 */
72526+ mm->mmap_base = TASK_UNMAPPED_BASE;
72527+
72528+#ifdef CONFIG_PAX_RANDMMAP
72529+ if (mm->pax_flags & MF_PAX_RANDMMAP)
72530+ mm->mmap_base += mm->delta_mmap;
72531+#endif
72532+
72533+ mm->free_area_cache = mm->mmap_base;
72534 mm->cached_hole_size = ~0UL;
72535- mm->free_area_cache = TASK_UNMAPPED_BASE;
72536 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
72537 /*
72538 * Restore the topdown base:
72539 */
72540- mm->free_area_cache = mm->mmap_base;
72541+ mm->mmap_base = base;
72542+ mm->free_area_cache = base;
72543 mm->cached_hole_size = ~0UL;
72544
72545 return addr;
72546@@ -1556,6 +1774,12 @@ fail:
72547
72548 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72549 {
72550+
72551+#ifdef CONFIG_PAX_SEGMEXEC
72552+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72553+ return;
72554+#endif
72555+
72556 /*
72557 * Is this a new hole at the highest possible address?
72558 */
72559@@ -1563,8 +1787,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72560 mm->free_area_cache = addr;
72561
72562 /* dont allow allocations above current base */
72563- if (mm->free_area_cache > mm->mmap_base)
72564+ if (mm->free_area_cache > mm->mmap_base) {
72565 mm->free_area_cache = mm->mmap_base;
72566+ mm->cached_hole_size = ~0UL;
72567+ }
72568 }
72569
72570 unsigned long
72571@@ -1663,6 +1889,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
72572 return vma;
72573 }
72574
72575+#ifdef CONFIG_PAX_SEGMEXEC
72576+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
72577+{
72578+ struct vm_area_struct *vma_m;
72579+
72580+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
72581+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
72582+ BUG_ON(vma->vm_mirror);
72583+ return NULL;
72584+ }
72585+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
72586+ vma_m = vma->vm_mirror;
72587+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
72588+ BUG_ON(vma->vm_file != vma_m->vm_file);
72589+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
72590+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
72591+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
72592+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
72593+ return vma_m;
72594+}
72595+#endif
72596+
72597 /*
72598 * Verify that the stack growth is acceptable and
72599 * update accounting. This is shared with both the
72600@@ -1679,6 +1927,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72601 return -ENOMEM;
72602
72603 /* Stack limit test */
72604+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
72605 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
72606 return -ENOMEM;
72607
72608@@ -1689,6 +1938,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72609 locked = mm->locked_vm + grow;
72610 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
72611 limit >>= PAGE_SHIFT;
72612+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72613 if (locked > limit && !capable(CAP_IPC_LOCK))
72614 return -ENOMEM;
72615 }
72616@@ -1719,37 +1969,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72617 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
72618 * vma is the last one with address > vma->vm_end. Have to extend vma.
72619 */
72620+#ifndef CONFIG_IA64
72621+static
72622+#endif
72623 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72624 {
72625 int error;
72626+ bool locknext;
72627
72628 if (!(vma->vm_flags & VM_GROWSUP))
72629 return -EFAULT;
72630
72631+ /* Also guard against wrapping around to address 0. */
72632+ if (address < PAGE_ALIGN(address+1))
72633+ address = PAGE_ALIGN(address+1);
72634+ else
72635+ return -ENOMEM;
72636+
72637 /*
72638 * We must make sure the anon_vma is allocated
72639 * so that the anon_vma locking is not a noop.
72640 */
72641 if (unlikely(anon_vma_prepare(vma)))
72642 return -ENOMEM;
72643+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
72644+ if (locknext && anon_vma_prepare(vma->vm_next))
72645+ return -ENOMEM;
72646 vma_lock_anon_vma(vma);
72647+ if (locknext)
72648+ vma_lock_anon_vma(vma->vm_next);
72649
72650 /*
72651 * vma->vm_start/vm_end cannot change under us because the caller
72652 * is required to hold the mmap_sem in read mode. We need the
72653- * anon_vma lock to serialize against concurrent expand_stacks.
72654- * Also guard against wrapping around to address 0.
72655+ * anon_vma locks to serialize against concurrent expand_stacks
72656+ * and expand_upwards.
72657 */
72658- if (address < PAGE_ALIGN(address+4))
72659- address = PAGE_ALIGN(address+4);
72660- else {
72661- vma_unlock_anon_vma(vma);
72662- return -ENOMEM;
72663- }
72664 error = 0;
72665
72666 /* Somebody else might have raced and expanded it already */
72667- if (address > vma->vm_end) {
72668+ 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)
72669+ error = -ENOMEM;
72670+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
72671 unsigned long size, grow;
72672
72673 size = address - vma->vm_start;
72674@@ -1764,6 +2025,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72675 }
72676 }
72677 }
72678+ if (locknext)
72679+ vma_unlock_anon_vma(vma->vm_next);
72680 vma_unlock_anon_vma(vma);
72681 khugepaged_enter_vma_merge(vma);
72682 return error;
72683@@ -1777,6 +2040,8 @@ int expand_downwards(struct vm_area_struct *vma,
72684 unsigned long address)
72685 {
72686 int error;
72687+ bool lockprev = false;
72688+ struct vm_area_struct *prev;
72689
72690 /*
72691 * We must make sure the anon_vma is allocated
72692@@ -1790,6 +2055,15 @@ int expand_downwards(struct vm_area_struct *vma,
72693 if (error)
72694 return error;
72695
72696+ prev = vma->vm_prev;
72697+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
72698+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
72699+#endif
72700+ if (lockprev && anon_vma_prepare(prev))
72701+ return -ENOMEM;
72702+ if (lockprev)
72703+ vma_lock_anon_vma(prev);
72704+
72705 vma_lock_anon_vma(vma);
72706
72707 /*
72708@@ -1799,9 +2073,17 @@ int expand_downwards(struct vm_area_struct *vma,
72709 */
72710
72711 /* Somebody else might have raced and expanded it already */
72712- if (address < vma->vm_start) {
72713+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
72714+ error = -ENOMEM;
72715+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
72716 unsigned long size, grow;
72717
72718+#ifdef CONFIG_PAX_SEGMEXEC
72719+ struct vm_area_struct *vma_m;
72720+
72721+ vma_m = pax_find_mirror_vma(vma);
72722+#endif
72723+
72724 size = vma->vm_end - address;
72725 grow = (vma->vm_start - address) >> PAGE_SHIFT;
72726
72727@@ -1811,11 +2093,22 @@ int expand_downwards(struct vm_area_struct *vma,
72728 if (!error) {
72729 vma->vm_start = address;
72730 vma->vm_pgoff -= grow;
72731+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
72732+
72733+#ifdef CONFIG_PAX_SEGMEXEC
72734+ if (vma_m) {
72735+ vma_m->vm_start -= grow << PAGE_SHIFT;
72736+ vma_m->vm_pgoff -= grow;
72737+ }
72738+#endif
72739+
72740 perf_event_mmap(vma);
72741 }
72742 }
72743 }
72744 vma_unlock_anon_vma(vma);
72745+ if (lockprev)
72746+ vma_unlock_anon_vma(prev);
72747 khugepaged_enter_vma_merge(vma);
72748 return error;
72749 }
72750@@ -1887,6 +2180,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
72751 do {
72752 long nrpages = vma_pages(vma);
72753
72754+#ifdef CONFIG_PAX_SEGMEXEC
72755+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
72756+ vma = remove_vma(vma);
72757+ continue;
72758+ }
72759+#endif
72760+
72761 if (vma->vm_flags & VM_ACCOUNT)
72762 nr_accounted += nrpages;
72763 mm->total_vm -= nrpages;
72764@@ -1933,6 +2233,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
72765 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
72766 vma->vm_prev = NULL;
72767 do {
72768+
72769+#ifdef CONFIG_PAX_SEGMEXEC
72770+ if (vma->vm_mirror) {
72771+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
72772+ vma->vm_mirror->vm_mirror = NULL;
72773+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
72774+ vma->vm_mirror = NULL;
72775+ }
72776+#endif
72777+
72778 rb_erase(&vma->vm_rb, &mm->mm_rb);
72779 mm->map_count--;
72780 tail_vma = vma;
72781@@ -1961,14 +2271,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72782 struct vm_area_struct *new;
72783 int err = -ENOMEM;
72784
72785+#ifdef CONFIG_PAX_SEGMEXEC
72786+ struct vm_area_struct *vma_m, *new_m = NULL;
72787+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
72788+#endif
72789+
72790 if (is_vm_hugetlb_page(vma) && (addr &
72791 ~(huge_page_mask(hstate_vma(vma)))))
72792 return -EINVAL;
72793
72794+#ifdef CONFIG_PAX_SEGMEXEC
72795+ vma_m = pax_find_mirror_vma(vma);
72796+#endif
72797+
72798 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72799 if (!new)
72800 goto out_err;
72801
72802+#ifdef CONFIG_PAX_SEGMEXEC
72803+ if (vma_m) {
72804+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72805+ if (!new_m) {
72806+ kmem_cache_free(vm_area_cachep, new);
72807+ goto out_err;
72808+ }
72809+ }
72810+#endif
72811+
72812 /* most fields are the same, copy all, and then fixup */
72813 *new = *vma;
72814
72815@@ -1981,6 +2310,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72816 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
72817 }
72818
72819+#ifdef CONFIG_PAX_SEGMEXEC
72820+ if (vma_m) {
72821+ *new_m = *vma_m;
72822+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
72823+ new_m->vm_mirror = new;
72824+ new->vm_mirror = new_m;
72825+
72826+ if (new_below)
72827+ new_m->vm_end = addr_m;
72828+ else {
72829+ new_m->vm_start = addr_m;
72830+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
72831+ }
72832+ }
72833+#endif
72834+
72835 pol = mpol_dup(vma_policy(vma));
72836 if (IS_ERR(pol)) {
72837 err = PTR_ERR(pol);
72838@@ -2006,6 +2351,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72839 else
72840 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
72841
72842+#ifdef CONFIG_PAX_SEGMEXEC
72843+ if (!err && vma_m) {
72844+ if (anon_vma_clone(new_m, vma_m))
72845+ goto out_free_mpol;
72846+
72847+ mpol_get(pol);
72848+ vma_set_policy(new_m, pol);
72849+
72850+ if (new_m->vm_file) {
72851+ get_file(new_m->vm_file);
72852+ if (vma_m->vm_flags & VM_EXECUTABLE)
72853+ added_exe_file_vma(mm);
72854+ }
72855+
72856+ if (new_m->vm_ops && new_m->vm_ops->open)
72857+ new_m->vm_ops->open(new_m);
72858+
72859+ if (new_below)
72860+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
72861+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
72862+ else
72863+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
72864+
72865+ if (err) {
72866+ if (new_m->vm_ops && new_m->vm_ops->close)
72867+ new_m->vm_ops->close(new_m);
72868+ if (new_m->vm_file) {
72869+ if (vma_m->vm_flags & VM_EXECUTABLE)
72870+ removed_exe_file_vma(mm);
72871+ fput(new_m->vm_file);
72872+ }
72873+ mpol_put(pol);
72874+ }
72875+ }
72876+#endif
72877+
72878 /* Success. */
72879 if (!err)
72880 return 0;
72881@@ -2018,10 +2399,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72882 removed_exe_file_vma(mm);
72883 fput(new->vm_file);
72884 }
72885- unlink_anon_vmas(new);
72886 out_free_mpol:
72887 mpol_put(pol);
72888 out_free_vma:
72889+
72890+#ifdef CONFIG_PAX_SEGMEXEC
72891+ if (new_m) {
72892+ unlink_anon_vmas(new_m);
72893+ kmem_cache_free(vm_area_cachep, new_m);
72894+ }
72895+#endif
72896+
72897+ unlink_anon_vmas(new);
72898 kmem_cache_free(vm_area_cachep, new);
72899 out_err:
72900 return err;
72901@@ -2034,6 +2423,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72902 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72903 unsigned long addr, int new_below)
72904 {
72905+
72906+#ifdef CONFIG_PAX_SEGMEXEC
72907+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72908+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
72909+ if (mm->map_count >= sysctl_max_map_count-1)
72910+ return -ENOMEM;
72911+ } else
72912+#endif
72913+
72914 if (mm->map_count >= sysctl_max_map_count)
72915 return -ENOMEM;
72916
72917@@ -2045,11 +2443,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72918 * work. This now handles partial unmappings.
72919 * Jeremy Fitzhardinge <jeremy@goop.org>
72920 */
72921+#ifdef CONFIG_PAX_SEGMEXEC
72922 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72923 {
72924+ int ret = __do_munmap(mm, start, len);
72925+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
72926+ return ret;
72927+
72928+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
72929+}
72930+
72931+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72932+#else
72933+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72934+#endif
72935+{
72936 unsigned long end;
72937 struct vm_area_struct *vma, *prev, *last;
72938
72939+ /*
72940+ * mm->mmap_sem is required to protect against another thread
72941+ * changing the mappings in case we sleep.
72942+ */
72943+ verify_mm_writelocked(mm);
72944+
72945 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
72946 return -EINVAL;
72947
72948@@ -2124,6 +2541,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72949 /* Fix up all other VM information */
72950 remove_vma_list(mm, vma);
72951
72952+ track_exec_limit(mm, start, end, 0UL);
72953+
72954 return 0;
72955 }
72956
72957@@ -2132,6 +2551,13 @@ int vm_munmap(unsigned long start, size_t len)
72958 int ret;
72959 struct mm_struct *mm = current->mm;
72960
72961+
72962+#ifdef CONFIG_PAX_SEGMEXEC
72963+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
72964+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
72965+ return -EINVAL;
72966+#endif
72967+
72968 down_write(&mm->mmap_sem);
72969 ret = do_munmap(mm, start, len);
72970 up_write(&mm->mmap_sem);
72971@@ -2145,16 +2571,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
72972 return vm_munmap(addr, len);
72973 }
72974
72975-static inline void verify_mm_writelocked(struct mm_struct *mm)
72976-{
72977-#ifdef CONFIG_DEBUG_VM
72978- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72979- WARN_ON(1);
72980- up_read(&mm->mmap_sem);
72981- }
72982-#endif
72983-}
72984-
72985 /*
72986 * this is really a simplified "do_mmap". it only handles
72987 * anonymous maps. eventually we may be able to do some
72988@@ -2168,6 +2584,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
72989 struct rb_node ** rb_link, * rb_parent;
72990 pgoff_t pgoff = addr >> PAGE_SHIFT;
72991 int error;
72992+ unsigned long charged;
72993
72994 len = PAGE_ALIGN(len);
72995 if (!len)
72996@@ -2175,16 +2592,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
72997
72998 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
72999
73000+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
73001+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
73002+ flags &= ~VM_EXEC;
73003+
73004+#ifdef CONFIG_PAX_MPROTECT
73005+ if (mm->pax_flags & MF_PAX_MPROTECT)
73006+ flags &= ~VM_MAYEXEC;
73007+#endif
73008+
73009+ }
73010+#endif
73011+
73012 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
73013 if (error & ~PAGE_MASK)
73014 return error;
73015
73016+ charged = len >> PAGE_SHIFT;
73017+
73018 /*
73019 * mlock MCL_FUTURE?
73020 */
73021 if (mm->def_flags & VM_LOCKED) {
73022 unsigned long locked, lock_limit;
73023- locked = len >> PAGE_SHIFT;
73024+ locked = charged;
73025 locked += mm->locked_vm;
73026 lock_limit = rlimit(RLIMIT_MEMLOCK);
73027 lock_limit >>= PAGE_SHIFT;
73028@@ -2201,22 +2632,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73029 /*
73030 * Clear old maps. this also does some error checking for us
73031 */
73032- munmap_back:
73033 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73034 if (vma && vma->vm_start < addr + len) {
73035 if (do_munmap(mm, addr, len))
73036 return -ENOMEM;
73037- goto munmap_back;
73038- }
73039+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73040+ BUG_ON(vma && vma->vm_start < addr + len);
73041+ }
73042
73043 /* Check against address space limits *after* clearing old maps... */
73044- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
73045+ if (!may_expand_vm(mm, charged))
73046 return -ENOMEM;
73047
73048 if (mm->map_count > sysctl_max_map_count)
73049 return -ENOMEM;
73050
73051- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
73052+ if (security_vm_enough_memory_mm(mm, charged))
73053 return -ENOMEM;
73054
73055 /* Can we just expand an old private anonymous mapping? */
73056@@ -2230,7 +2661,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73057 */
73058 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73059 if (!vma) {
73060- vm_unacct_memory(len >> PAGE_SHIFT);
73061+ vm_unacct_memory(charged);
73062 return -ENOMEM;
73063 }
73064
73065@@ -2244,11 +2675,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73066 vma_link(mm, vma, prev, rb_link, rb_parent);
73067 out:
73068 perf_event_mmap(vma);
73069- mm->total_vm += len >> PAGE_SHIFT;
73070+ mm->total_vm += charged;
73071 if (flags & VM_LOCKED) {
73072 if (!mlock_vma_pages_range(vma, addr, addr + len))
73073- mm->locked_vm += (len >> PAGE_SHIFT);
73074+ mm->locked_vm += charged;
73075 }
73076+ track_exec_limit(mm, addr, addr + len, flags);
73077 return addr;
73078 }
73079
73080@@ -2306,6 +2738,7 @@ void exit_mmap(struct mm_struct *mm)
73081 while (vma) {
73082 if (vma->vm_flags & VM_ACCOUNT)
73083 nr_accounted += vma_pages(vma);
73084+ vma->vm_mirror = NULL;
73085 vma = remove_vma(vma);
73086 }
73087 vm_unacct_memory(nr_accounted);
73088@@ -2322,6 +2755,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73089 struct vm_area_struct * __vma, * prev;
73090 struct rb_node ** rb_link, * rb_parent;
73091
73092+#ifdef CONFIG_PAX_SEGMEXEC
73093+ struct vm_area_struct *vma_m = NULL;
73094+#endif
73095+
73096+ if (security_mmap_addr(vma->vm_start))
73097+ return -EPERM;
73098+
73099 /*
73100 * The vm_pgoff of a purely anonymous vma should be irrelevant
73101 * until its first write fault, when page's anon_vma and index
73102@@ -2348,7 +2788,21 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73103 if (vma->vm_file && uprobe_mmap(vma))
73104 return -EINVAL;
73105
73106+#ifdef CONFIG_PAX_SEGMEXEC
73107+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
73108+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73109+ if (!vma_m)
73110+ return -ENOMEM;
73111+ }
73112+#endif
73113+
73114 vma_link(mm, vma, prev, rb_link, rb_parent);
73115+
73116+#ifdef CONFIG_PAX_SEGMEXEC
73117+ if (vma_m)
73118+ BUG_ON(pax_mirror_vma(vma_m, vma));
73119+#endif
73120+
73121 return 0;
73122 }
73123
73124@@ -2367,6 +2821,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73125 struct mempolicy *pol;
73126 bool faulted_in_anon_vma = true;
73127
73128+ BUG_ON(vma->vm_mirror);
73129+
73130 /*
73131 * If anonymous vma has not yet been faulted, update new pgoff
73132 * to match new location, to increase its chance of merging.
73133@@ -2438,6 +2894,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73134 return NULL;
73135 }
73136
73137+#ifdef CONFIG_PAX_SEGMEXEC
73138+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
73139+{
73140+ struct vm_area_struct *prev_m;
73141+ struct rb_node **rb_link_m, *rb_parent_m;
73142+ struct mempolicy *pol_m;
73143+
73144+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
73145+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
73146+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
73147+ *vma_m = *vma;
73148+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
73149+ if (anon_vma_clone(vma_m, vma))
73150+ return -ENOMEM;
73151+ pol_m = vma_policy(vma_m);
73152+ mpol_get(pol_m);
73153+ vma_set_policy(vma_m, pol_m);
73154+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
73155+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
73156+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
73157+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
73158+ if (vma_m->vm_file)
73159+ get_file(vma_m->vm_file);
73160+ if (vma_m->vm_ops && vma_m->vm_ops->open)
73161+ vma_m->vm_ops->open(vma_m);
73162+ find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
73163+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
73164+ vma_m->vm_mirror = vma;
73165+ vma->vm_mirror = vma_m;
73166+ return 0;
73167+}
73168+#endif
73169+
73170 /*
73171 * Return true if the calling process may expand its vm space by the passed
73172 * number of pages
73173@@ -2449,6 +2938,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
73174
73175 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
73176
73177+#ifdef CONFIG_PAX_RANDMMAP
73178+ if (mm->pax_flags & MF_PAX_RANDMMAP)
73179+ cur -= mm->brk_gap;
73180+#endif
73181+
73182+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
73183 if (cur + npages > lim)
73184 return 0;
73185 return 1;
73186@@ -2519,6 +3014,22 @@ int install_special_mapping(struct mm_struct *mm,
73187 vma->vm_start = addr;
73188 vma->vm_end = addr + len;
73189
73190+#ifdef CONFIG_PAX_MPROTECT
73191+ if (mm->pax_flags & MF_PAX_MPROTECT) {
73192+#ifndef CONFIG_PAX_MPROTECT_COMPAT
73193+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
73194+ return -EPERM;
73195+ if (!(vm_flags & VM_EXEC))
73196+ vm_flags &= ~VM_MAYEXEC;
73197+#else
73198+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73199+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73200+#endif
73201+ else
73202+ vm_flags &= ~VM_MAYWRITE;
73203+ }
73204+#endif
73205+
73206 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
73207 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73208
73209diff --git a/mm/mprotect.c b/mm/mprotect.c
73210index a409926..8b32e6d 100644
73211--- a/mm/mprotect.c
73212+++ b/mm/mprotect.c
73213@@ -23,10 +23,17 @@
73214 #include <linux/mmu_notifier.h>
73215 #include <linux/migrate.h>
73216 #include <linux/perf_event.h>
73217+
73218+#ifdef CONFIG_PAX_MPROTECT
73219+#include <linux/elf.h>
73220+#include <linux/binfmts.h>
73221+#endif
73222+
73223 #include <asm/uaccess.h>
73224 #include <asm/pgtable.h>
73225 #include <asm/cacheflush.h>
73226 #include <asm/tlbflush.h>
73227+#include <asm/mmu_context.h>
73228
73229 #ifndef pgprot_modify
73230 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
73231@@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
73232 flush_tlb_range(vma, start, end);
73233 }
73234
73235+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73236+/* called while holding the mmap semaphor for writing except stack expansion */
73237+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
73238+{
73239+ unsigned long oldlimit, newlimit = 0UL;
73240+
73241+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
73242+ return;
73243+
73244+ spin_lock(&mm->page_table_lock);
73245+ oldlimit = mm->context.user_cs_limit;
73246+ if ((prot & VM_EXEC) && oldlimit < end)
73247+ /* USER_CS limit moved up */
73248+ newlimit = end;
73249+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
73250+ /* USER_CS limit moved down */
73251+ newlimit = start;
73252+
73253+ if (newlimit) {
73254+ mm->context.user_cs_limit = newlimit;
73255+
73256+#ifdef CONFIG_SMP
73257+ wmb();
73258+ cpus_clear(mm->context.cpu_user_cs_mask);
73259+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
73260+#endif
73261+
73262+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
73263+ }
73264+ spin_unlock(&mm->page_table_lock);
73265+ if (newlimit == end) {
73266+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
73267+
73268+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
73269+ if (is_vm_hugetlb_page(vma))
73270+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
73271+ else
73272+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
73273+ }
73274+}
73275+#endif
73276+
73277 int
73278 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73279 unsigned long start, unsigned long end, unsigned long newflags)
73280@@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73281 int error;
73282 int dirty_accountable = 0;
73283
73284+#ifdef CONFIG_PAX_SEGMEXEC
73285+ struct vm_area_struct *vma_m = NULL;
73286+ unsigned long start_m, end_m;
73287+
73288+ start_m = start + SEGMEXEC_TASK_SIZE;
73289+ end_m = end + SEGMEXEC_TASK_SIZE;
73290+#endif
73291+
73292 if (newflags == oldflags) {
73293 *pprev = vma;
73294 return 0;
73295 }
73296
73297+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
73298+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
73299+
73300+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
73301+ return -ENOMEM;
73302+
73303+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
73304+ return -ENOMEM;
73305+ }
73306+
73307 /*
73308 * If we make a private mapping writable we increase our commit;
73309 * but (without finer accounting) cannot reduce our commit if we
73310@@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73311 }
73312 }
73313
73314+#ifdef CONFIG_PAX_SEGMEXEC
73315+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
73316+ if (start != vma->vm_start) {
73317+ error = split_vma(mm, vma, start, 1);
73318+ if (error)
73319+ goto fail;
73320+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
73321+ *pprev = (*pprev)->vm_next;
73322+ }
73323+
73324+ if (end != vma->vm_end) {
73325+ error = split_vma(mm, vma, end, 0);
73326+ if (error)
73327+ goto fail;
73328+ }
73329+
73330+ if (pax_find_mirror_vma(vma)) {
73331+ error = __do_munmap(mm, start_m, end_m - start_m);
73332+ if (error)
73333+ goto fail;
73334+ } else {
73335+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73336+ if (!vma_m) {
73337+ error = -ENOMEM;
73338+ goto fail;
73339+ }
73340+ vma->vm_flags = newflags;
73341+ error = pax_mirror_vma(vma_m, vma);
73342+ if (error) {
73343+ vma->vm_flags = oldflags;
73344+ goto fail;
73345+ }
73346+ }
73347+ }
73348+#endif
73349+
73350 /*
73351 * First try to merge with previous and/or next vma.
73352 */
73353@@ -204,9 +307,21 @@ success:
73354 * vm_flags and vm_page_prot are protected by the mmap_sem
73355 * held in write mode.
73356 */
73357+
73358+#ifdef CONFIG_PAX_SEGMEXEC
73359+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
73360+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
73361+#endif
73362+
73363 vma->vm_flags = newflags;
73364+
73365+#ifdef CONFIG_PAX_MPROTECT
73366+ if (mm->binfmt && mm->binfmt->handle_mprotect)
73367+ mm->binfmt->handle_mprotect(vma, newflags);
73368+#endif
73369+
73370 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
73371- vm_get_page_prot(newflags));
73372+ vm_get_page_prot(vma->vm_flags));
73373
73374 if (vma_wants_writenotify(vma)) {
73375 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
73376@@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73377 end = start + len;
73378 if (end <= start)
73379 return -ENOMEM;
73380+
73381+#ifdef CONFIG_PAX_SEGMEXEC
73382+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
73383+ if (end > SEGMEXEC_TASK_SIZE)
73384+ return -EINVAL;
73385+ } else
73386+#endif
73387+
73388+ if (end > TASK_SIZE)
73389+ return -EINVAL;
73390+
73391 if (!arch_validate_prot(prot))
73392 return -EINVAL;
73393
73394@@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73395 /*
73396 * Does the application expect PROT_READ to imply PROT_EXEC:
73397 */
73398- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
73399+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
73400 prot |= PROT_EXEC;
73401
73402 vm_flags = calc_vm_prot_bits(prot);
73403@@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73404 if (start > vma->vm_start)
73405 prev = vma;
73406
73407+#ifdef CONFIG_PAX_MPROTECT
73408+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
73409+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
73410+#endif
73411+
73412 for (nstart = start ; ; ) {
73413 unsigned long newflags;
73414
73415@@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73416
73417 /* newflags >> 4 shift VM_MAY% in place of VM_% */
73418 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
73419+ if (prot & (PROT_WRITE | PROT_EXEC))
73420+ gr_log_rwxmprotect(vma->vm_file);
73421+
73422+ error = -EACCES;
73423+ goto out;
73424+ }
73425+
73426+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
73427 error = -EACCES;
73428 goto out;
73429 }
73430@@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73431 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
73432 if (error)
73433 goto out;
73434+
73435+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
73436+
73437 nstart = tmp;
73438
73439 if (nstart < prev->vm_end)
73440diff --git a/mm/mremap.c b/mm/mremap.c
73441index 21fed20..6822658 100644
73442--- a/mm/mremap.c
73443+++ b/mm/mremap.c
73444@@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
73445 continue;
73446 pte = ptep_get_and_clear(mm, old_addr, old_pte);
73447 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
73448+
73449+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73450+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
73451+ pte = pte_exprotect(pte);
73452+#endif
73453+
73454 set_pte_at(mm, new_addr, new_pte, pte);
73455 }
73456
73457@@ -299,6 +305,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
73458 if (is_vm_hugetlb_page(vma))
73459 goto Einval;
73460
73461+#ifdef CONFIG_PAX_SEGMEXEC
73462+ if (pax_find_mirror_vma(vma))
73463+ goto Einval;
73464+#endif
73465+
73466 /* We can't remap across vm area boundaries */
73467 if (old_len > vma->vm_end - addr)
73468 goto Efault;
73469@@ -355,20 +366,25 @@ static unsigned long mremap_to(unsigned long addr,
73470 unsigned long ret = -EINVAL;
73471 unsigned long charged = 0;
73472 unsigned long map_flags;
73473+ unsigned long pax_task_size = TASK_SIZE;
73474
73475 if (new_addr & ~PAGE_MASK)
73476 goto out;
73477
73478- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
73479+#ifdef CONFIG_PAX_SEGMEXEC
73480+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
73481+ pax_task_size = SEGMEXEC_TASK_SIZE;
73482+#endif
73483+
73484+ pax_task_size -= PAGE_SIZE;
73485+
73486+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
73487 goto out;
73488
73489 /* Check if the location we're moving into overlaps the
73490 * old location at all, and fail if it does.
73491 */
73492- if ((new_addr <= addr) && (new_addr+new_len) > addr)
73493- goto out;
73494-
73495- if ((addr <= new_addr) && (addr+old_len) > new_addr)
73496+ if (addr + old_len > new_addr && new_addr + new_len > addr)
73497 goto out;
73498
73499 ret = do_munmap(mm, new_addr, new_len);
73500@@ -436,6 +452,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73501 struct vm_area_struct *vma;
73502 unsigned long ret = -EINVAL;
73503 unsigned long charged = 0;
73504+ unsigned long pax_task_size = TASK_SIZE;
73505
73506 down_write(&current->mm->mmap_sem);
73507
73508@@ -456,6 +473,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73509 if (!new_len)
73510 goto out;
73511
73512+#ifdef CONFIG_PAX_SEGMEXEC
73513+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
73514+ pax_task_size = SEGMEXEC_TASK_SIZE;
73515+#endif
73516+
73517+ pax_task_size -= PAGE_SIZE;
73518+
73519+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
73520+ old_len > pax_task_size || addr > pax_task_size-old_len)
73521+ goto out;
73522+
73523 if (flags & MREMAP_FIXED) {
73524 if (flags & MREMAP_MAYMOVE)
73525 ret = mremap_to(addr, old_len, new_addr, new_len);
73526@@ -505,6 +533,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73527 addr + new_len);
73528 }
73529 ret = addr;
73530+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
73531 goto out;
73532 }
73533 }
73534@@ -528,7 +557,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73535 goto out;
73536 }
73537
73538+ map_flags = vma->vm_flags;
73539 ret = move_vma(vma, addr, old_len, new_len, new_addr);
73540+ if (!(ret & ~PAGE_MASK)) {
73541+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
73542+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
73543+ }
73544 }
73545 out:
73546 if (ret & ~PAGE_MASK)
73547diff --git a/mm/nommu.c b/mm/nommu.c
73548index d4b0c10..ed421b5 100644
73549--- a/mm/nommu.c
73550+++ b/mm/nommu.c
73551@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
73552 int sysctl_overcommit_ratio = 50; /* default is 50% */
73553 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
73554 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
73555-int heap_stack_gap = 0;
73556
73557 atomic_long_t mmap_pages_allocated;
73558
73559@@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
73560 EXPORT_SYMBOL(find_vma);
73561
73562 /*
73563- * find a VMA
73564- * - we don't extend stack VMAs under NOMMU conditions
73565- */
73566-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
73567-{
73568- return find_vma(mm, addr);
73569-}
73570-
73571-/*
73572 * expand a stack to a given address
73573 * - not supported under NOMMU conditions
73574 */
73575@@ -1551,6 +1541,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73576
73577 /* most fields are the same, copy all, and then fixup */
73578 *new = *vma;
73579+ INIT_LIST_HEAD(&new->anon_vma_chain);
73580 *region = *vma->vm_region;
73581 new->vm_region = region;
73582
73583diff --git a/mm/page_alloc.c b/mm/page_alloc.c
73584index 201b508..1fb51ca 100644
73585--- a/mm/page_alloc.c
73586+++ b/mm/page_alloc.c
73587@@ -336,7 +336,7 @@ out:
73588 * This usage means that zero-order pages may not be compound.
73589 */
73590
73591-static void free_compound_page(struct page *page)
73592+void free_compound_page(struct page *page)
73593 {
73594 __free_pages_ok(page, compound_order(page));
73595 }
73596@@ -693,6 +693,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73597 int i;
73598 int bad = 0;
73599
73600+#ifdef CONFIG_PAX_MEMORY_SANITIZE
73601+ unsigned long index = 1UL << order;
73602+#endif
73603+
73604 trace_mm_page_free(page, order);
73605 kmemcheck_free_shadow(page, order);
73606
73607@@ -708,6 +712,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73608 debug_check_no_obj_freed(page_address(page),
73609 PAGE_SIZE << order);
73610 }
73611+
73612+#ifdef CONFIG_PAX_MEMORY_SANITIZE
73613+ for (; index; --index)
73614+ sanitize_highpage(page + index - 1);
73615+#endif
73616+
73617 arch_free_page(page, order);
73618 kernel_map_pages(page, 1 << order, 0);
73619
73620@@ -849,8 +859,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
73621 arch_alloc_page(page, order);
73622 kernel_map_pages(page, 1 << order, 1);
73623
73624+#ifndef CONFIG_PAX_MEMORY_SANITIZE
73625 if (gfp_flags & __GFP_ZERO)
73626 prep_zero_page(page, order, gfp_flags);
73627+#endif
73628
73629 if (order && (gfp_flags & __GFP_COMP))
73630 prep_compound_page(page, order);
73631@@ -3579,7 +3591,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
73632 unsigned long pfn;
73633
73634 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
73635+#ifdef CONFIG_X86_32
73636+ /* boot failures in VMware 8 on 32bit vanilla since
73637+ this change */
73638+ if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
73639+#else
73640 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
73641+#endif
73642 return 1;
73643 }
73644 return 0;
73645diff --git a/mm/percpu.c b/mm/percpu.c
73646index bb4be74..a43ea85 100644
73647--- a/mm/percpu.c
73648+++ b/mm/percpu.c
73649@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
73650 static unsigned int pcpu_high_unit_cpu __read_mostly;
73651
73652 /* the address of the first chunk which starts with the kernel static area */
73653-void *pcpu_base_addr __read_mostly;
73654+void *pcpu_base_addr __read_only;
73655 EXPORT_SYMBOL_GPL(pcpu_base_addr);
73656
73657 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
73658diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
73659index 926b466..b23df53 100644
73660--- a/mm/process_vm_access.c
73661+++ b/mm/process_vm_access.c
73662@@ -13,6 +13,7 @@
73663 #include <linux/uio.h>
73664 #include <linux/sched.h>
73665 #include <linux/highmem.h>
73666+#include <linux/security.h>
73667 #include <linux/ptrace.h>
73668 #include <linux/slab.h>
73669 #include <linux/syscalls.h>
73670@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73671 size_t iov_l_curr_offset = 0;
73672 ssize_t iov_len;
73673
73674+ return -ENOSYS; // PaX: until properly audited
73675+
73676 /*
73677 * Work out how many pages of struct pages we're going to need
73678 * when eventually calling get_user_pages
73679 */
73680 for (i = 0; i < riovcnt; i++) {
73681 iov_len = rvec[i].iov_len;
73682- if (iov_len > 0) {
73683- nr_pages_iov = ((unsigned long)rvec[i].iov_base
73684- + iov_len)
73685- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
73686- / PAGE_SIZE + 1;
73687- nr_pages = max(nr_pages, nr_pages_iov);
73688- }
73689+ if (iov_len <= 0)
73690+ continue;
73691+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
73692+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
73693+ nr_pages = max(nr_pages, nr_pages_iov);
73694 }
73695
73696 if (nr_pages == 0)
73697@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73698 goto free_proc_pages;
73699 }
73700
73701+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
73702+ rc = -EPERM;
73703+ goto put_task_struct;
73704+ }
73705+
73706 mm = mm_access(task, PTRACE_MODE_ATTACH);
73707 if (!mm || IS_ERR(mm)) {
73708 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
73709diff --git a/mm/rmap.c b/mm/rmap.c
73710index 0f3b7cd..c5652b6 100644
73711--- a/mm/rmap.c
73712+++ b/mm/rmap.c
73713@@ -167,6 +167,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73714 struct anon_vma *anon_vma = vma->anon_vma;
73715 struct anon_vma_chain *avc;
73716
73717+#ifdef CONFIG_PAX_SEGMEXEC
73718+ struct anon_vma_chain *avc_m = NULL;
73719+#endif
73720+
73721 might_sleep();
73722 if (unlikely(!anon_vma)) {
73723 struct mm_struct *mm = vma->vm_mm;
73724@@ -176,6 +180,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73725 if (!avc)
73726 goto out_enomem;
73727
73728+#ifdef CONFIG_PAX_SEGMEXEC
73729+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
73730+ if (!avc_m)
73731+ goto out_enomem_free_avc;
73732+#endif
73733+
73734 anon_vma = find_mergeable_anon_vma(vma);
73735 allocated = NULL;
73736 if (!anon_vma) {
73737@@ -189,6 +199,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73738 /* page_table_lock to protect against threads */
73739 spin_lock(&mm->page_table_lock);
73740 if (likely(!vma->anon_vma)) {
73741+
73742+#ifdef CONFIG_PAX_SEGMEXEC
73743+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
73744+
73745+ if (vma_m) {
73746+ BUG_ON(vma_m->anon_vma);
73747+ vma_m->anon_vma = anon_vma;
73748+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
73749+ avc_m = NULL;
73750+ }
73751+#endif
73752+
73753 vma->anon_vma = anon_vma;
73754 anon_vma_chain_link(vma, avc, anon_vma);
73755 allocated = NULL;
73756@@ -199,12 +221,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73757
73758 if (unlikely(allocated))
73759 put_anon_vma(allocated);
73760+
73761+#ifdef CONFIG_PAX_SEGMEXEC
73762+ if (unlikely(avc_m))
73763+ anon_vma_chain_free(avc_m);
73764+#endif
73765+
73766 if (unlikely(avc))
73767 anon_vma_chain_free(avc);
73768 }
73769 return 0;
73770
73771 out_enomem_free_avc:
73772+
73773+#ifdef CONFIG_PAX_SEGMEXEC
73774+ if (avc_m)
73775+ anon_vma_chain_free(avc_m);
73776+#endif
73777+
73778 anon_vma_chain_free(avc);
73779 out_enomem:
73780 return -ENOMEM;
73781@@ -240,7 +274,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
73782 * Attach the anon_vmas from src to dst.
73783 * Returns 0 on success, -ENOMEM on failure.
73784 */
73785-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
73786+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
73787 {
73788 struct anon_vma_chain *avc, *pavc;
73789 struct anon_vma *root = NULL;
73790@@ -318,7 +352,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
73791 * the corresponding VMA in the parent process is attached to.
73792 * Returns 0 on success, non-zero on failure.
73793 */
73794-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
73795+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
73796 {
73797 struct anon_vma_chain *avc;
73798 struct anon_vma *anon_vma;
73799diff --git a/mm/shmem.c b/mm/shmem.c
73800index bd10636..5c16d49 100644
73801--- a/mm/shmem.c
73802+++ b/mm/shmem.c
73803@@ -31,7 +31,7 @@
73804 #include <linux/export.h>
73805 #include <linux/swap.h>
73806
73807-static struct vfsmount *shm_mnt;
73808+struct vfsmount *shm_mnt;
73809
73810 #ifdef CONFIG_SHMEM
73811 /*
73812@@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
73813 #define BOGO_DIRENT_SIZE 20
73814
73815 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
73816-#define SHORT_SYMLINK_LEN 128
73817+#define SHORT_SYMLINK_LEN 64
73818
73819 struct shmem_xattr {
73820 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
73821@@ -2590,8 +2590,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
73822 int err = -ENOMEM;
73823
73824 /* Round up to L1_CACHE_BYTES to resist false sharing */
73825- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
73826- L1_CACHE_BYTES), GFP_KERNEL);
73827+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
73828 if (!sbinfo)
73829 return -ENOMEM;
73830
73831diff --git a/mm/slab.c b/mm/slab.c
73832index e901a36..ca479fc 100644
73833--- a/mm/slab.c
73834+++ b/mm/slab.c
73835@@ -153,7 +153,7 @@
73836
73837 /* Legal flag mask for kmem_cache_create(). */
73838 #if DEBUG
73839-# define CREATE_MASK (SLAB_RED_ZONE | \
73840+# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
73841 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
73842 SLAB_CACHE_DMA | \
73843 SLAB_STORE_USER | \
73844@@ -161,7 +161,7 @@
73845 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73846 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
73847 #else
73848-# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
73849+# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
73850 SLAB_CACHE_DMA | \
73851 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
73852 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73853@@ -290,7 +290,7 @@ struct kmem_list3 {
73854 * Need this for bootstrapping a per node allocator.
73855 */
73856 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
73857-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
73858+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
73859 #define CACHE_CACHE 0
73860 #define SIZE_AC MAX_NUMNODES
73861 #define SIZE_L3 (2 * MAX_NUMNODES)
73862@@ -391,10 +391,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
73863 if ((x)->max_freeable < i) \
73864 (x)->max_freeable = i; \
73865 } while (0)
73866-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
73867-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
73868-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
73869-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
73870+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
73871+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
73872+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
73873+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
73874 #else
73875 #define STATS_INC_ACTIVE(x) do { } while (0)
73876 #define STATS_DEC_ACTIVE(x) do { } while (0)
73877@@ -542,7 +542,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
73878 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
73879 */
73880 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
73881- const struct slab *slab, void *obj)
73882+ const struct slab *slab, const void *obj)
73883 {
73884 u32 offset = (obj - slab->s_mem);
73885 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
73886@@ -563,12 +563,13 @@ EXPORT_SYMBOL(malloc_sizes);
73887 struct cache_names {
73888 char *name;
73889 char *name_dma;
73890+ char *name_usercopy;
73891 };
73892
73893 static struct cache_names __initdata cache_names[] = {
73894-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
73895+#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
73896 #include <linux/kmalloc_sizes.h>
73897- {NULL,}
73898+ {NULL}
73899 #undef CACHE
73900 };
73901
73902@@ -756,6 +757,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
73903 if (unlikely(gfpflags & GFP_DMA))
73904 return csizep->cs_dmacachep;
73905 #endif
73906+
73907+#ifdef CONFIG_PAX_USERCOPY_SLABS
73908+ if (unlikely(gfpflags & GFP_USERCOPY))
73909+ return csizep->cs_usercopycachep;
73910+#endif
73911+
73912 return csizep->cs_cachep;
73913 }
73914
73915@@ -1588,7 +1595,7 @@ void __init kmem_cache_init(void)
73916 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
73917 sizes[INDEX_AC].cs_size,
73918 ARCH_KMALLOC_MINALIGN,
73919- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73920+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73921 NULL);
73922
73923 if (INDEX_AC != INDEX_L3) {
73924@@ -1596,7 +1603,7 @@ void __init kmem_cache_init(void)
73925 kmem_cache_create(names[INDEX_L3].name,
73926 sizes[INDEX_L3].cs_size,
73927 ARCH_KMALLOC_MINALIGN,
73928- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73929+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73930 NULL);
73931 }
73932
73933@@ -1614,7 +1621,7 @@ void __init kmem_cache_init(void)
73934 sizes->cs_cachep = kmem_cache_create(names->name,
73935 sizes->cs_size,
73936 ARCH_KMALLOC_MINALIGN,
73937- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73938+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73939 NULL);
73940 }
73941 #ifdef CONFIG_ZONE_DMA
73942@@ -1626,6 +1633,16 @@ void __init kmem_cache_init(void)
73943 SLAB_PANIC,
73944 NULL);
73945 #endif
73946+
73947+#ifdef CONFIG_PAX_USERCOPY_SLABS
73948+ sizes->cs_usercopycachep = kmem_cache_create(
73949+ names->name_usercopy,
73950+ sizes->cs_size,
73951+ ARCH_KMALLOC_MINALIGN,
73952+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73953+ NULL);
73954+#endif
73955+
73956 sizes++;
73957 names++;
73958 }
73959@@ -4390,10 +4407,10 @@ static int s_show(struct seq_file *m, void *p)
73960 }
73961 /* cpu stats */
73962 {
73963- unsigned long allochit = atomic_read(&cachep->allochit);
73964- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
73965- unsigned long freehit = atomic_read(&cachep->freehit);
73966- unsigned long freemiss = atomic_read(&cachep->freemiss);
73967+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
73968+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
73969+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
73970+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
73971
73972 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
73973 allochit, allocmiss, freehit, freemiss);
73974@@ -4652,13 +4669,68 @@ static int __init slab_proc_init(void)
73975 {
73976 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
73977 #ifdef CONFIG_DEBUG_SLAB_LEAK
73978- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
73979+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
73980 #endif
73981 return 0;
73982 }
73983 module_init(slab_proc_init);
73984 #endif
73985
73986+bool is_usercopy_object(const void *ptr)
73987+{
73988+ struct page *page;
73989+ struct kmem_cache *cachep;
73990+
73991+ if (ZERO_OR_NULL_PTR(ptr))
73992+ return false;
73993+
73994+ if (!virt_addr_valid(ptr))
73995+ return false;
73996+
73997+ page = virt_to_head_page(ptr);
73998+
73999+ if (!PageSlab(page))
74000+ return false;
74001+
74002+ cachep = page_get_cache(page);
74003+ return cachep->flags & SLAB_USERCOPY;
74004+}
74005+
74006+#ifdef CONFIG_PAX_USERCOPY
74007+const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74008+{
74009+ struct page *page;
74010+ struct kmem_cache *cachep;
74011+ struct slab *slabp;
74012+ unsigned int objnr;
74013+ unsigned long offset;
74014+
74015+ if (ZERO_OR_NULL_PTR(ptr))
74016+ return "<null>";
74017+
74018+ if (!virt_addr_valid(ptr))
74019+ return NULL;
74020+
74021+ page = virt_to_head_page(ptr);
74022+
74023+ if (!PageSlab(page))
74024+ return NULL;
74025+
74026+ cachep = page_get_cache(page);
74027+ if (!(cachep->flags & SLAB_USERCOPY))
74028+ return cachep->name;
74029+
74030+ slabp = page_get_slab(page);
74031+ objnr = obj_to_index(cachep, slabp, ptr);
74032+ BUG_ON(objnr >= cachep->num);
74033+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
74034+ if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
74035+ return NULL;
74036+
74037+ return cachep->name;
74038+}
74039+#endif
74040+
74041 /**
74042 * ksize - get the actual amount of memory allocated for a given object
74043 * @objp: Pointer to the object
74044diff --git a/mm/slob.c b/mm/slob.c
74045index 8105be4..3c15e57 100644
74046--- a/mm/slob.c
74047+++ b/mm/slob.c
74048@@ -29,7 +29,7 @@
74049 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
74050 * alloc_pages() directly, allocating compound pages so the page order
74051 * does not have to be separately tracked, and also stores the exact
74052- * allocation size in page->private so that it can be used to accurately
74053+ * allocation size in slob_page->size so that it can be used to accurately
74054 * provide ksize(). These objects are detected in kfree() because slob_page()
74055 * is false for them.
74056 *
74057@@ -58,6 +58,7 @@
74058 */
74059
74060 #include <linux/kernel.h>
74061+#include <linux/sched.h>
74062 #include <linux/slab.h>
74063 #include <linux/mm.h>
74064 #include <linux/swap.h> /* struct reclaim_state */
74065@@ -102,7 +103,8 @@ struct slob_page {
74066 unsigned long flags; /* mandatory */
74067 atomic_t _count; /* mandatory */
74068 slobidx_t units; /* free units left in page */
74069- unsigned long pad[2];
74070+ unsigned long pad[1];
74071+ unsigned long size; /* size when >=PAGE_SIZE */
74072 slob_t *free; /* first free slob_t in page */
74073 struct list_head list; /* linked list of free pages */
74074 };
74075@@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
74076 */
74077 static inline int is_slob_page(struct slob_page *sp)
74078 {
74079- return PageSlab((struct page *)sp);
74080+ return PageSlab((struct page *)sp) && !sp->size;
74081 }
74082
74083 static inline void set_slob_page(struct slob_page *sp)
74084@@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
74085
74086 static inline struct slob_page *slob_page(const void *addr)
74087 {
74088- return (struct slob_page *)virt_to_page(addr);
74089+ return (struct slob_page *)virt_to_head_page(addr);
74090 }
74091
74092 /*
74093@@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
74094 /*
74095 * Return the size of a slob block.
74096 */
74097-static slobidx_t slob_units(slob_t *s)
74098+static slobidx_t slob_units(const slob_t *s)
74099 {
74100 if (s->units > 0)
74101 return s->units;
74102@@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
74103 /*
74104 * Return the next free slob block pointer after this one.
74105 */
74106-static slob_t *slob_next(slob_t *s)
74107+static slob_t *slob_next(const slob_t *s)
74108 {
74109 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
74110 slobidx_t next;
74111@@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
74112 /*
74113 * Returns true if s is the last free block in its page.
74114 */
74115-static int slob_last(slob_t *s)
74116+static int slob_last(const slob_t *s)
74117 {
74118 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
74119 }
74120@@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
74121 if (!page)
74122 return NULL;
74123
74124+ set_slob_page(page);
74125 return page_address(page);
74126 }
74127
74128@@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
74129 if (!b)
74130 return NULL;
74131 sp = slob_page(b);
74132- set_slob_page(sp);
74133
74134 spin_lock_irqsave(&slob_lock, flags);
74135 sp->units = SLOB_UNITS(PAGE_SIZE);
74136 sp->free = b;
74137+ sp->size = 0;
74138 INIT_LIST_HEAD(&sp->list);
74139 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
74140 set_slob_page_free(sp, slob_list);
74141@@ -476,10 +479,9 @@ out:
74142 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
74143 */
74144
74145-void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74146+static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
74147 {
74148- unsigned int *m;
74149- int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74150+ slob_t *m;
74151 void *ret;
74152
74153 gfp &= gfp_allowed_mask;
74154@@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74155
74156 if (!m)
74157 return NULL;
74158- *m = size;
74159+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
74160+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
74161+ m[0].units = size;
74162+ m[1].units = align;
74163 ret = (void *)m + align;
74164
74165 trace_kmalloc_node(_RET_IP_, ret,
74166@@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74167 gfp |= __GFP_COMP;
74168 ret = slob_new_pages(gfp, order, node);
74169 if (ret) {
74170- struct page *page;
74171- page = virt_to_page(ret);
74172- page->private = size;
74173+ struct slob_page *sp;
74174+ sp = slob_page(ret);
74175+ sp->size = size;
74176 }
74177
74178 trace_kmalloc_node(_RET_IP_, ret,
74179 size, PAGE_SIZE << order, gfp, node);
74180 }
74181
74182- kmemleak_alloc(ret, size, 1, gfp);
74183+ return ret;
74184+}
74185+
74186+void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74187+{
74188+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74189+ void *ret = __kmalloc_node_align(size, gfp, node, align);
74190+
74191+ if (!ZERO_OR_NULL_PTR(ret))
74192+ kmemleak_alloc(ret, size, 1, gfp);
74193 return ret;
74194 }
74195 EXPORT_SYMBOL(__kmalloc_node);
74196@@ -533,13 +547,83 @@ void kfree(const void *block)
74197 sp = slob_page(block);
74198 if (is_slob_page(sp)) {
74199 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74200- unsigned int *m = (unsigned int *)(block - align);
74201- slob_free(m, *m + align);
74202- } else
74203+ slob_t *m = (slob_t *)(block - align);
74204+ slob_free(m, m[0].units + align);
74205+ } else {
74206+ clear_slob_page(sp);
74207+ free_slob_page(sp);
74208+ sp->size = 0;
74209 put_page(&sp->page);
74210+ }
74211 }
74212 EXPORT_SYMBOL(kfree);
74213
74214+bool is_usercopy_object(const void *ptr)
74215+{
74216+ return false;
74217+}
74218+
74219+#ifdef CONFIG_PAX_USERCOPY
74220+const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74221+{
74222+ struct slob_page *sp;
74223+ const slob_t *free;
74224+ const void *base;
74225+ unsigned long flags;
74226+
74227+ if (ZERO_OR_NULL_PTR(ptr))
74228+ return "<null>";
74229+
74230+ if (!virt_addr_valid(ptr))
74231+ return NULL;
74232+
74233+ sp = slob_page(ptr);
74234+ if (!PageSlab((struct page *)sp))
74235+ return NULL;
74236+
74237+ if (sp->size) {
74238+ base = page_address(&sp->page);
74239+ if (base <= ptr && n <= sp->size - (ptr - base))
74240+ return NULL;
74241+ return "<slob>";
74242+ }
74243+
74244+ /* some tricky double walking to find the chunk */
74245+ spin_lock_irqsave(&slob_lock, flags);
74246+ base = (void *)((unsigned long)ptr & PAGE_MASK);
74247+ free = sp->free;
74248+
74249+ while (!slob_last(free) && (void *)free <= ptr) {
74250+ base = free + slob_units(free);
74251+ free = slob_next(free);
74252+ }
74253+
74254+ while (base < (void *)free) {
74255+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
74256+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
74257+ int offset;
74258+
74259+ if (ptr < base + align)
74260+ break;
74261+
74262+ offset = ptr - base - align;
74263+ if (offset >= m) {
74264+ base += size;
74265+ continue;
74266+ }
74267+
74268+ if (n > m - offset)
74269+ break;
74270+
74271+ spin_unlock_irqrestore(&slob_lock, flags);
74272+ return NULL;
74273+ }
74274+
74275+ spin_unlock_irqrestore(&slob_lock, flags);
74276+ return "<slob>";
74277+}
74278+#endif
74279+
74280 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
74281 size_t ksize(const void *block)
74282 {
74283@@ -552,10 +636,10 @@ size_t ksize(const void *block)
74284 sp = slob_page(block);
74285 if (is_slob_page(sp)) {
74286 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74287- unsigned int *m = (unsigned int *)(block - align);
74288- return SLOB_UNITS(*m) * SLOB_UNIT;
74289+ slob_t *m = (slob_t *)(block - align);
74290+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
74291 } else
74292- return sp->page.private;
74293+ return sp->size;
74294 }
74295 EXPORT_SYMBOL(ksize);
74296
74297@@ -571,8 +655,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74298 {
74299 struct kmem_cache *c;
74300
74301+#ifdef CONFIG_PAX_USERCOPY_SLABS
74302+ c = __kmalloc_node_align(sizeof(struct kmem_cache),
74303+ GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
74304+#else
74305 c = slob_alloc(sizeof(struct kmem_cache),
74306 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
74307+#endif
74308
74309 if (c) {
74310 c->name = name;
74311@@ -614,17 +703,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
74312
74313 lockdep_trace_alloc(flags);
74314
74315+#ifdef CONFIG_PAX_USERCOPY_SLABS
74316+ b = __kmalloc_node_align(c->size, flags, node, c->align);
74317+#else
74318 if (c->size < PAGE_SIZE) {
74319 b = slob_alloc(c->size, flags, c->align, node);
74320 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74321 SLOB_UNITS(c->size) * SLOB_UNIT,
74322 flags, node);
74323 } else {
74324+ struct slob_page *sp;
74325+
74326 b = slob_new_pages(flags, get_order(c->size), node);
74327+ sp = slob_page(b);
74328+ sp->size = c->size;
74329 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74330 PAGE_SIZE << get_order(c->size),
74331 flags, node);
74332 }
74333+#endif
74334
74335 if (c->ctor)
74336 c->ctor(b);
74337@@ -636,10 +733,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
74338
74339 static void __kmem_cache_free(void *b, int size)
74340 {
74341- if (size < PAGE_SIZE)
74342+ struct slob_page *sp = slob_page(b);
74343+
74344+ if (is_slob_page(sp))
74345 slob_free(b, size);
74346- else
74347+ else {
74348+ clear_slob_page(sp);
74349+ free_slob_page(sp);
74350+ sp->size = 0;
74351 slob_free_pages(b, get_order(size));
74352+ }
74353 }
74354
74355 static void kmem_rcu_free(struct rcu_head *head)
74356@@ -652,17 +755,31 @@ static void kmem_rcu_free(struct rcu_head *head)
74357
74358 void kmem_cache_free(struct kmem_cache *c, void *b)
74359 {
74360+ int size = c->size;
74361+
74362+#ifdef CONFIG_PAX_USERCOPY_SLABS
74363+ if (size + c->align < PAGE_SIZE) {
74364+ size += c->align;
74365+ b -= c->align;
74366+ }
74367+#endif
74368+
74369 kmemleak_free_recursive(b, c->flags);
74370 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
74371 struct slob_rcu *slob_rcu;
74372- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
74373- slob_rcu->size = c->size;
74374+ slob_rcu = b + (size - sizeof(struct slob_rcu));
74375+ slob_rcu->size = size;
74376 call_rcu(&slob_rcu->head, kmem_rcu_free);
74377 } else {
74378- __kmem_cache_free(b, c->size);
74379+ __kmem_cache_free(b, size);
74380 }
74381
74382+#ifdef CONFIG_PAX_USERCOPY_SLABS
74383+ trace_kfree(_RET_IP_, b);
74384+#else
74385 trace_kmem_cache_free(_RET_IP_, b);
74386+#endif
74387+
74388 }
74389 EXPORT_SYMBOL(kmem_cache_free);
74390
74391diff --git a/mm/slub.c b/mm/slub.c
74392index 8c691fa..ff23a85 100644
74393--- a/mm/slub.c
74394+++ b/mm/slub.c
74395@@ -209,7 +209,7 @@ struct track {
74396
74397 enum track_item { TRACK_ALLOC, TRACK_FREE };
74398
74399-#ifdef CONFIG_SYSFS
74400+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74401 static int sysfs_slab_add(struct kmem_cache *);
74402 static int sysfs_slab_alias(struct kmem_cache *, const char *);
74403 static void sysfs_slab_remove(struct kmem_cache *);
74404@@ -538,7 +538,7 @@ static void print_track(const char *s, struct track *t)
74405 if (!t->addr)
74406 return;
74407
74408- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
74409+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
74410 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
74411 #ifdef CONFIG_STACKTRACE
74412 {
74413@@ -2603,6 +2603,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
74414
74415 page = virt_to_head_page(x);
74416
74417+ BUG_ON(!PageSlab(page));
74418+
74419 slab_free(s, page, x, _RET_IP_);
74420
74421 trace_kmem_cache_free(_RET_IP_, x);
74422@@ -2636,7 +2638,7 @@ static int slub_min_objects;
74423 * Merge control. If this is set then no merging of slab caches will occur.
74424 * (Could be removed. This was introduced to pacify the merge skeptics.)
74425 */
74426-static int slub_nomerge;
74427+static int slub_nomerge = 1;
74428
74429 /*
74430 * Calculate the order of allocation given an slab object size.
74431@@ -3089,7 +3091,7 @@ static int kmem_cache_open(struct kmem_cache *s,
74432 else
74433 s->cpu_partial = 30;
74434
74435- s->refcount = 1;
74436+ atomic_set(&s->refcount, 1);
74437 #ifdef CONFIG_NUMA
74438 s->remote_node_defrag_ratio = 1000;
74439 #endif
74440@@ -3193,8 +3195,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
74441 void kmem_cache_destroy(struct kmem_cache *s)
74442 {
74443 down_write(&slub_lock);
74444- s->refcount--;
74445- if (!s->refcount) {
74446+ if (atomic_dec_and_test(&s->refcount)) {
74447 list_del(&s->list);
74448 up_write(&slub_lock);
74449 if (kmem_cache_close(s)) {
74450@@ -3223,6 +3224,10 @@ static struct kmem_cache *kmem_cache;
74451 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
74452 #endif
74453
74454+#ifdef CONFIG_PAX_USERCOPY_SLABS
74455+static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
74456+#endif
74457+
74458 static int __init setup_slub_min_order(char *str)
74459 {
74460 get_option(&str, &slub_min_order);
74461@@ -3337,6 +3342,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
74462 return kmalloc_dma_caches[index];
74463
74464 #endif
74465+
74466+#ifdef CONFIG_PAX_USERCOPY_SLABS
74467+ if (flags & SLAB_USERCOPY)
74468+ return kmalloc_usercopy_caches[index];
74469+
74470+#endif
74471+
74472 return kmalloc_caches[index];
74473 }
74474
74475@@ -3405,6 +3417,56 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
74476 EXPORT_SYMBOL(__kmalloc_node);
74477 #endif
74478
74479+bool is_usercopy_object(const void *ptr)
74480+{
74481+ struct page *page;
74482+ struct kmem_cache *s;
74483+
74484+ if (ZERO_OR_NULL_PTR(ptr))
74485+ return false;
74486+
74487+ if (!virt_addr_valid(ptr))
74488+ return false;
74489+
74490+ page = virt_to_head_page(ptr);
74491+
74492+ if (!PageSlab(page))
74493+ return false;
74494+
74495+ s = page->slab;
74496+ return s->flags & SLAB_USERCOPY;
74497+}
74498+
74499+#ifdef CONFIG_PAX_USERCOPY
74500+const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74501+{
74502+ struct page *page;
74503+ struct kmem_cache *s;
74504+ unsigned long offset;
74505+
74506+ if (ZERO_OR_NULL_PTR(ptr))
74507+ return "<null>";
74508+
74509+ if (!virt_addr_valid(ptr))
74510+ return NULL;
74511+
74512+ page = virt_to_head_page(ptr);
74513+
74514+ if (!PageSlab(page))
74515+ return NULL;
74516+
74517+ s = page->slab;
74518+ if (!(s->flags & SLAB_USERCOPY))
74519+ return s->name;
74520+
74521+ offset = (ptr - page_address(page)) % s->size;
74522+ if (offset <= s->objsize && n <= s->objsize - offset)
74523+ return NULL;
74524+
74525+ return s->name;
74526+}
74527+#endif
74528+
74529 size_t ksize(const void *object)
74530 {
74531 struct page *page;
74532@@ -3679,7 +3741,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
74533 int node;
74534
74535 list_add(&s->list, &slab_caches);
74536- s->refcount = -1;
74537+ atomic_set(&s->refcount, -1);
74538
74539 for_each_node_state(node, N_NORMAL_MEMORY) {
74540 struct kmem_cache_node *n = get_node(s, node);
74541@@ -3799,17 +3861,17 @@ void __init kmem_cache_init(void)
74542
74543 /* Caches that are not of the two-to-the-power-of size */
74544 if (KMALLOC_MIN_SIZE <= 32) {
74545- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
74546+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
74547 caches++;
74548 }
74549
74550 if (KMALLOC_MIN_SIZE <= 64) {
74551- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
74552+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
74553 caches++;
74554 }
74555
74556 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
74557- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
74558+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
74559 caches++;
74560 }
74561
74562@@ -3851,6 +3913,22 @@ void __init kmem_cache_init(void)
74563 }
74564 }
74565 #endif
74566+
74567+#ifdef CONFIG_PAX_USERCOPY_SLABS
74568+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
74569+ struct kmem_cache *s = kmalloc_caches[i];
74570+
74571+ if (s && s->size) {
74572+ char *name = kasprintf(GFP_NOWAIT,
74573+ "usercopy-kmalloc-%d", s->objsize);
74574+
74575+ BUG_ON(!name);
74576+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
74577+ s->objsize, SLAB_USERCOPY);
74578+ }
74579+ }
74580+#endif
74581+
74582 printk(KERN_INFO
74583 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
74584 " CPUs=%d, Nodes=%d\n",
74585@@ -3877,7 +3955,7 @@ static int slab_unmergeable(struct kmem_cache *s)
74586 /*
74587 * We may have set a slab to be unmergeable during bootstrap.
74588 */
74589- if (s->refcount < 0)
74590+ if (atomic_read(&s->refcount) < 0)
74591 return 1;
74592
74593 return 0;
74594@@ -3936,7 +4014,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74595 down_write(&slub_lock);
74596 s = find_mergeable(size, align, flags, name, ctor);
74597 if (s) {
74598- s->refcount++;
74599+ atomic_inc(&s->refcount);
74600 /*
74601 * Adjust the object sizes so that we clear
74602 * the complete object on kzalloc.
74603@@ -3945,7 +4023,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74604 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
74605
74606 if (sysfs_slab_alias(s, name)) {
74607- s->refcount--;
74608+ atomic_dec(&s->refcount);
74609 goto err;
74610 }
74611 up_write(&slub_lock);
74612@@ -4074,7 +4152,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
74613 }
74614 #endif
74615
74616-#ifdef CONFIG_SYSFS
74617+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74618 static int count_inuse(struct page *page)
74619 {
74620 return page->inuse;
74621@@ -4461,12 +4539,12 @@ static void resiliency_test(void)
74622 validate_slab_cache(kmalloc_caches[9]);
74623 }
74624 #else
74625-#ifdef CONFIG_SYSFS
74626+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74627 static void resiliency_test(void) {};
74628 #endif
74629 #endif
74630
74631-#ifdef CONFIG_SYSFS
74632+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74633 enum slab_stat_type {
74634 SL_ALL, /* All slabs */
74635 SL_PARTIAL, /* Only partially allocated slabs */
74636@@ -4709,7 +4787,7 @@ SLAB_ATTR_RO(ctor);
74637
74638 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
74639 {
74640- return sprintf(buf, "%d\n", s->refcount - 1);
74641+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
74642 }
74643 SLAB_ATTR_RO(aliases);
74644
74645@@ -5280,6 +5358,7 @@ static char *create_unique_id(struct kmem_cache *s)
74646 return name;
74647 }
74648
74649+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74650 static int sysfs_slab_add(struct kmem_cache *s)
74651 {
74652 int err;
74653@@ -5342,6 +5421,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
74654 kobject_del(&s->kobj);
74655 kobject_put(&s->kobj);
74656 }
74657+#endif
74658
74659 /*
74660 * Need to buffer aliases during bootup until sysfs becomes
74661@@ -5355,6 +5435,7 @@ struct saved_alias {
74662
74663 static struct saved_alias *alias_list;
74664
74665+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74666 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74667 {
74668 struct saved_alias *al;
74669@@ -5377,6 +5458,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74670 alias_list = al;
74671 return 0;
74672 }
74673+#endif
74674
74675 static int __init slab_sysfs_init(void)
74676 {
74677diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
74678index 1b7e22a..3fcd4f3 100644
74679--- a/mm/sparse-vmemmap.c
74680+++ b/mm/sparse-vmemmap.c
74681@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
74682 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
74683 if (!p)
74684 return NULL;
74685- pud_populate(&init_mm, pud, p);
74686+ pud_populate_kernel(&init_mm, pud, p);
74687 }
74688 return pud;
74689 }
74690@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
74691 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
74692 if (!p)
74693 return NULL;
74694- pgd_populate(&init_mm, pgd, p);
74695+ pgd_populate_kernel(&init_mm, pgd, p);
74696 }
74697 return pgd;
74698 }
74699diff --git a/mm/swap.c b/mm/swap.c
74700index 4e7e2ec..0c57830 100644
74701--- a/mm/swap.c
74702+++ b/mm/swap.c
74703@@ -30,6 +30,7 @@
74704 #include <linux/backing-dev.h>
74705 #include <linux/memcontrol.h>
74706 #include <linux/gfp.h>
74707+#include <linux/hugetlb.h>
74708
74709 #include "internal.h"
74710
74711@@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
74712
74713 __page_cache_release(page);
74714 dtor = get_compound_page_dtor(page);
74715+ if (!PageHuge(page))
74716+ BUG_ON(dtor != free_compound_page);
74717 (*dtor)(page);
74718 }
74719
74720diff --git a/mm/swapfile.c b/mm/swapfile.c
74721index 71373d0..11fa7d9 100644
74722--- a/mm/swapfile.c
74723+++ b/mm/swapfile.c
74724@@ -63,7 +63,7 @@ static DEFINE_MUTEX(swapon_mutex);
74725
74726 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
74727 /* Activity counter to indicate that a swapon or swapoff has occurred */
74728-static atomic_t proc_poll_event = ATOMIC_INIT(0);
74729+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
74730
74731 static inline unsigned char swap_count(unsigned char ent)
74732 {
74733@@ -1663,7 +1663,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
74734 }
74735 filp_close(swap_file, NULL);
74736 err = 0;
74737- atomic_inc(&proc_poll_event);
74738+ atomic_inc_unchecked(&proc_poll_event);
74739 wake_up_interruptible(&proc_poll_wait);
74740
74741 out_dput:
74742@@ -1679,8 +1679,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
74743
74744 poll_wait(file, &proc_poll_wait, wait);
74745
74746- if (seq->poll_event != atomic_read(&proc_poll_event)) {
74747- seq->poll_event = atomic_read(&proc_poll_event);
74748+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
74749+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74750 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
74751 }
74752
74753@@ -1778,7 +1778,7 @@ static int swaps_open(struct inode *inode, struct file *file)
74754 return ret;
74755
74756 seq = file->private_data;
74757- seq->poll_event = atomic_read(&proc_poll_event);
74758+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74759 return 0;
74760 }
74761
74762@@ -2120,7 +2120,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
74763 (frontswap_map) ? "FS" : "");
74764
74765 mutex_unlock(&swapon_mutex);
74766- atomic_inc(&proc_poll_event);
74767+ atomic_inc_unchecked(&proc_poll_event);
74768 wake_up_interruptible(&proc_poll_wait);
74769
74770 if (S_ISREG(inode->i_mode))
74771diff --git a/mm/util.c b/mm/util.c
74772index 8c7265a..c96d884 100644
74773--- a/mm/util.c
74774+++ b/mm/util.c
74775@@ -285,6 +285,12 @@ done:
74776 void arch_pick_mmap_layout(struct mm_struct *mm)
74777 {
74778 mm->mmap_base = TASK_UNMAPPED_BASE;
74779+
74780+#ifdef CONFIG_PAX_RANDMMAP
74781+ if (mm->pax_flags & MF_PAX_RANDMMAP)
74782+ mm->mmap_base += mm->delta_mmap;
74783+#endif
74784+
74785 mm->get_unmapped_area = arch_get_unmapped_area;
74786 mm->unmap_area = arch_unmap_area;
74787 }
74788diff --git a/mm/vmalloc.c b/mm/vmalloc.c
74789index 2aad499..4006a74 100644
74790--- a/mm/vmalloc.c
74791+++ b/mm/vmalloc.c
74792@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
74793
74794 pte = pte_offset_kernel(pmd, addr);
74795 do {
74796- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74797- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74798+
74799+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74800+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
74801+ BUG_ON(!pte_exec(*pte));
74802+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
74803+ continue;
74804+ }
74805+#endif
74806+
74807+ {
74808+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74809+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74810+ }
74811 } while (pte++, addr += PAGE_SIZE, addr != end);
74812 }
74813
74814@@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74815 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
74816 {
74817 pte_t *pte;
74818+ int ret = -ENOMEM;
74819
74820 /*
74821 * nr is a running index into the array which helps higher level
74822@@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74823 pte = pte_alloc_kernel(pmd, addr);
74824 if (!pte)
74825 return -ENOMEM;
74826+
74827+ pax_open_kernel();
74828 do {
74829 struct page *page = pages[*nr];
74830
74831- if (WARN_ON(!pte_none(*pte)))
74832- return -EBUSY;
74833- if (WARN_ON(!page))
74834- return -ENOMEM;
74835+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74836+ if (pgprot_val(prot) & _PAGE_NX)
74837+#endif
74838+
74839+ if (WARN_ON(!pte_none(*pte))) {
74840+ ret = -EBUSY;
74841+ goto out;
74842+ }
74843+ if (WARN_ON(!page)) {
74844+ ret = -ENOMEM;
74845+ goto out;
74846+ }
74847 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
74848 (*nr)++;
74849 } while (pte++, addr += PAGE_SIZE, addr != end);
74850- return 0;
74851+ ret = 0;
74852+out:
74853+ pax_close_kernel();
74854+ return ret;
74855 }
74856
74857 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
74858@@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
74859 pmd_t *pmd;
74860 unsigned long next;
74861
74862- pmd = pmd_alloc(&init_mm, pud, addr);
74863+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
74864 if (!pmd)
74865 return -ENOMEM;
74866 do {
74867@@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
74868 pud_t *pud;
74869 unsigned long next;
74870
74871- pud = pud_alloc(&init_mm, pgd, addr);
74872+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
74873 if (!pud)
74874 return -ENOMEM;
74875 do {
74876@@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
74877 * and fall back on vmalloc() if that fails. Others
74878 * just put it in the vmalloc space.
74879 */
74880-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
74881+#ifdef CONFIG_MODULES
74882+#ifdef MODULES_VADDR
74883 unsigned long addr = (unsigned long)x;
74884 if (addr >= MODULES_VADDR && addr < MODULES_END)
74885 return 1;
74886 #endif
74887+
74888+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74889+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
74890+ return 1;
74891+#endif
74892+
74893+#endif
74894+
74895 return is_vmalloc_addr(x);
74896 }
74897
74898@@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
74899
74900 if (!pgd_none(*pgd)) {
74901 pud_t *pud = pud_offset(pgd, addr);
74902+#ifdef CONFIG_X86
74903+ if (!pud_large(*pud))
74904+#endif
74905 if (!pud_none(*pud)) {
74906 pmd_t *pmd = pmd_offset(pud, addr);
74907+#ifdef CONFIG_X86
74908+ if (!pmd_large(*pmd))
74909+#endif
74910 if (!pmd_none(*pmd)) {
74911 pte_t *ptep, pte;
74912
74913@@ -329,7 +369,7 @@ static void purge_vmap_area_lazy(void);
74914 * Allocate a region of KVA of the specified size and alignment, within the
74915 * vstart and vend.
74916 */
74917-static struct vmap_area *alloc_vmap_area(unsigned long size,
74918+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
74919 unsigned long align,
74920 unsigned long vstart, unsigned long vend,
74921 int node, gfp_t gfp_mask)
74922@@ -1320,6 +1360,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
74923 struct vm_struct *area;
74924
74925 BUG_ON(in_interrupt());
74926+
74927+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74928+ if (flags & VM_KERNEXEC) {
74929+ if (start != VMALLOC_START || end != VMALLOC_END)
74930+ return NULL;
74931+ start = (unsigned long)MODULES_EXEC_VADDR;
74932+ end = (unsigned long)MODULES_EXEC_END;
74933+ }
74934+#endif
74935+
74936 if (flags & VM_IOREMAP) {
74937 int bit = fls(size);
74938
74939@@ -1552,6 +1602,11 @@ void *vmap(struct page **pages, unsigned int count,
74940 if (count > totalram_pages)
74941 return NULL;
74942
74943+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74944+ if (!(pgprot_val(prot) & _PAGE_NX))
74945+ flags |= VM_KERNEXEC;
74946+#endif
74947+
74948 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
74949 __builtin_return_address(0));
74950 if (!area)
74951@@ -1653,6 +1708,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
74952 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
74953 goto fail;
74954
74955+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74956+ if (!(pgprot_val(prot) & _PAGE_NX))
74957+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
74958+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
74959+ else
74960+#endif
74961+
74962 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
74963 start, end, node, gfp_mask, caller);
74964 if (!area)
74965@@ -1826,10 +1888,9 @@ EXPORT_SYMBOL(vzalloc_node);
74966 * For tight control over page level allocator and protection flags
74967 * use __vmalloc() instead.
74968 */
74969-
74970 void *vmalloc_exec(unsigned long size)
74971 {
74972- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
74973+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
74974 -1, __builtin_return_address(0));
74975 }
74976
74977@@ -2124,6 +2185,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
74978 unsigned long uaddr = vma->vm_start;
74979 unsigned long usize = vma->vm_end - vma->vm_start;
74980
74981+ BUG_ON(vma->vm_mirror);
74982+
74983 if ((PAGE_SIZE-1) & (unsigned long)addr)
74984 return -EINVAL;
74985
74986diff --git a/mm/vmstat.c b/mm/vmstat.c
74987index 1bbbbd9..ff35669 100644
74988--- a/mm/vmstat.c
74989+++ b/mm/vmstat.c
74990@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
74991 *
74992 * vm_stat contains the global counters
74993 */
74994-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
74995+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
74996 EXPORT_SYMBOL(vm_stat);
74997
74998 #ifdef CONFIG_SMP
74999@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
75000 v = p->vm_stat_diff[i];
75001 p->vm_stat_diff[i] = 0;
75002 local_irq_restore(flags);
75003- atomic_long_add(v, &zone->vm_stat[i]);
75004+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
75005 global_diff[i] += v;
75006 #ifdef CONFIG_NUMA
75007 /* 3 seconds idle till flush */
75008@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
75009
75010 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
75011 if (global_diff[i])
75012- atomic_long_add(global_diff[i], &vm_stat[i]);
75013+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
75014 }
75015
75016 #endif
75017@@ -1211,10 +1211,20 @@ static int __init setup_vmstat(void)
75018 start_cpu_timer(cpu);
75019 #endif
75020 #ifdef CONFIG_PROC_FS
75021- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
75022- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
75023- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
75024- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
75025+ {
75026+ mode_t gr_mode = S_IRUGO;
75027+#ifdef CONFIG_GRKERNSEC_PROC_ADD
75028+ gr_mode = S_IRUSR;
75029+#endif
75030+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
75031+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
75032+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
75033+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
75034+#else
75035+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
75036+#endif
75037+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
75038+ }
75039 #endif
75040 return 0;
75041 }
75042diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
75043index 9096bcb..43ed7bb 100644
75044--- a/net/8021q/vlan.c
75045+++ b/net/8021q/vlan.c
75046@@ -557,8 +557,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
75047 err = -EPERM;
75048 if (!capable(CAP_NET_ADMIN))
75049 break;
75050- if ((args.u.name_type >= 0) &&
75051- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
75052+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
75053 struct vlan_net *vn;
75054
75055 vn = net_generic(net, vlan_net_id);
75056diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
75057index 6449bae..8c1f454 100644
75058--- a/net/9p/trans_fd.c
75059+++ b/net/9p/trans_fd.c
75060@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
75061 oldfs = get_fs();
75062 set_fs(get_ds());
75063 /* The cast to a user pointer is valid due to the set_fs() */
75064- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
75065+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
75066 set_fs(oldfs);
75067
75068 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
75069diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
75070index 876fbe8..8bbea9f 100644
75071--- a/net/atm/atm_misc.c
75072+++ b/net/atm/atm_misc.c
75073@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
75074 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
75075 return 1;
75076 atm_return(vcc, truesize);
75077- atomic_inc(&vcc->stats->rx_drop);
75078+ atomic_inc_unchecked(&vcc->stats->rx_drop);
75079 return 0;
75080 }
75081 EXPORT_SYMBOL(atm_charge);
75082@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
75083 }
75084 }
75085 atm_return(vcc, guess);
75086- atomic_inc(&vcc->stats->rx_drop);
75087+ atomic_inc_unchecked(&vcc->stats->rx_drop);
75088 return NULL;
75089 }
75090 EXPORT_SYMBOL(atm_alloc_charge);
75091@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
75092
75093 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75094 {
75095-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75096+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75097 __SONET_ITEMS
75098 #undef __HANDLE_ITEM
75099 }
75100@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
75101
75102 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75103 {
75104-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75105+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
75106 __SONET_ITEMS
75107 #undef __HANDLE_ITEM
75108 }
75109diff --git a/net/atm/common.c b/net/atm/common.c
75110index b4b44db..0c0ad93 100644
75111--- a/net/atm/common.c
75112+++ b/net/atm/common.c
75113@@ -812,6 +812,7 @@ int vcc_getsockopt(struct socket *sock, int level, int optname,
75114
75115 if (!vcc->dev || !test_bit(ATM_VF_ADDR, &vcc->flags))
75116 return -ENOTCONN;
75117+ memset(&pvc, 0, sizeof(pvc));
75118 pvc.sap_family = AF_ATMPVC;
75119 pvc.sap_addr.itf = vcc->dev->number;
75120 pvc.sap_addr.vpi = vcc->vpi;
75121diff --git a/net/atm/lec.h b/net/atm/lec.h
75122index a86aff9..3a0d6f6 100644
75123--- a/net/atm/lec.h
75124+++ b/net/atm/lec.h
75125@@ -48,7 +48,7 @@ struct lane2_ops {
75126 const u8 *tlvs, u32 sizeoftlvs);
75127 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
75128 const u8 *tlvs, u32 sizeoftlvs);
75129-};
75130+} __no_const;
75131
75132 /*
75133 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
75134diff --git a/net/atm/mpc.h b/net/atm/mpc.h
75135index 0919a88..a23d54e 100644
75136--- a/net/atm/mpc.h
75137+++ b/net/atm/mpc.h
75138@@ -33,7 +33,7 @@ struct mpoa_client {
75139 struct mpc_parameters parameters; /* parameters for this client */
75140
75141 const struct net_device_ops *old_ops;
75142- struct net_device_ops new_ops;
75143+ net_device_ops_no_const new_ops;
75144 };
75145
75146
75147diff --git a/net/atm/proc.c b/net/atm/proc.c
75148index 0d020de..011c7bb 100644
75149--- a/net/atm/proc.c
75150+++ b/net/atm/proc.c
75151@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
75152 const struct k_atm_aal_stats *stats)
75153 {
75154 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
75155- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
75156- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
75157- atomic_read(&stats->rx_drop));
75158+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
75159+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
75160+ atomic_read_unchecked(&stats->rx_drop));
75161 }
75162
75163 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
75164diff --git a/net/atm/pvc.c b/net/atm/pvc.c
75165index 3a73491..ae03240 100644
75166--- a/net/atm/pvc.c
75167+++ b/net/atm/pvc.c
75168@@ -95,6 +95,7 @@ static int pvc_getname(struct socket *sock, struct sockaddr *sockaddr,
75169 return -ENOTCONN;
75170 *sockaddr_len = sizeof(struct sockaddr_atmpvc);
75171 addr = (struct sockaddr_atmpvc *)sockaddr;
75172+ memset(addr, 0, sizeof(*addr));
75173 addr->sap_family = AF_ATMPVC;
75174 addr->sap_addr.itf = vcc->dev->number;
75175 addr->sap_addr.vpi = vcc->vpi;
75176diff --git a/net/atm/resources.c b/net/atm/resources.c
75177index 23f45ce..c748f1a 100644
75178--- a/net/atm/resources.c
75179+++ b/net/atm/resources.c
75180@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
75181 static void copy_aal_stats(struct k_atm_aal_stats *from,
75182 struct atm_aal_stats *to)
75183 {
75184-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75185+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75186 __AAL_STAT_ITEMS
75187 #undef __HANDLE_ITEM
75188 }
75189@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
75190 static void subtract_aal_stats(struct k_atm_aal_stats *from,
75191 struct atm_aal_stats *to)
75192 {
75193-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75194+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
75195 __AAL_STAT_ITEMS
75196 #undef __HANDLE_ITEM
75197 }
75198diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
75199index dc53798..dc66333 100644
75200--- a/net/batman-adv/bat_iv_ogm.c
75201+++ b/net/batman-adv/bat_iv_ogm.c
75202@@ -63,7 +63,7 @@ static int bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
75203
75204 /* randomize initial seqno to avoid collision */
75205 get_random_bytes(&random_seqno, sizeof(random_seqno));
75206- atomic_set(&hard_iface->seqno, random_seqno);
75207+ atomic_set_unchecked(&hard_iface->seqno, random_seqno);
75208
75209 hard_iface->packet_len = BATMAN_OGM_HLEN;
75210 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
75211@@ -572,7 +572,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
75212
75213 /* change sequence number to network order */
75214 batman_ogm_packet->seqno =
75215- htonl((uint32_t)atomic_read(&hard_iface->seqno));
75216+ htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
75217
75218 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
75219 batman_ogm_packet->tt_crc = htons((uint16_t)
75220@@ -592,7 +592,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
75221 else
75222 batman_ogm_packet->gw_flags = NO_FLAGS;
75223
75224- atomic_inc(&hard_iface->seqno);
75225+ atomic_inc_unchecked(&hard_iface->seqno);
75226
75227 slide_own_bcast_window(hard_iface);
75228 bat_iv_ogm_queue_add(bat_priv, hard_iface->packet_buff,
75229@@ -956,7 +956,7 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
75230 return;
75231
75232 /* could be changed by schedule_own_packet() */
75233- if_incoming_seqno = atomic_read(&if_incoming->seqno);
75234+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
75235
75236 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
75237
75238diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
75239index dc334fa..766a01a 100644
75240--- a/net/batman-adv/hard-interface.c
75241+++ b/net/batman-adv/hard-interface.c
75242@@ -321,7 +321,7 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
75243 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
75244 dev_add_pack(&hard_iface->batman_adv_ptype);
75245
75246- atomic_set(&hard_iface->frag_seqno, 1);
75247+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
75248 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
75249 hard_iface->net_dev->name);
75250
75251@@ -444,7 +444,7 @@ static struct hard_iface *hardif_add_interface(struct net_device *net_dev)
75252 * This can't be called via a bat_priv callback because
75253 * we have no bat_priv yet.
75254 */
75255- atomic_set(&hard_iface->seqno, 1);
75256+ atomic_set_unchecked(&hard_iface->seqno, 1);
75257 hard_iface->packet_buff = NULL;
75258
75259 return hard_iface;
75260diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
75261index a0ec0e4..7beb587 100644
75262--- a/net/batman-adv/soft-interface.c
75263+++ b/net/batman-adv/soft-interface.c
75264@@ -214,7 +214,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
75265
75266 /* set broadcast sequence number */
75267 bcast_packet->seqno =
75268- htonl(atomic_inc_return(&bat_priv->bcast_seqno));
75269+ htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
75270
75271 add_bcast_packet_to_list(bat_priv, skb, 1);
75272
75273@@ -390,7 +390,7 @@ struct net_device *softif_create(const char *name)
75274 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
75275
75276 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
75277- atomic_set(&bat_priv->bcast_seqno, 1);
75278+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
75279 atomic_set(&bat_priv->ttvn, 0);
75280 atomic_set(&bat_priv->tt_local_changes, 0);
75281 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
75282diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
75283index 61308e8..2e142b2 100644
75284--- a/net/batman-adv/types.h
75285+++ b/net/batman-adv/types.h
75286@@ -38,8 +38,8 @@ struct hard_iface {
75287 int16_t if_num;
75288 char if_status;
75289 struct net_device *net_dev;
75290- atomic_t seqno;
75291- atomic_t frag_seqno;
75292+ atomic_unchecked_t seqno;
75293+ atomic_unchecked_t frag_seqno;
75294 unsigned char *packet_buff;
75295 int packet_len;
75296 struct kobject *hardif_obj;
75297@@ -163,7 +163,7 @@ struct bat_priv {
75298 atomic_t orig_interval; /* uint */
75299 atomic_t hop_penalty; /* uint */
75300 atomic_t log_level; /* uint */
75301- atomic_t bcast_seqno;
75302+ atomic_unchecked_t bcast_seqno;
75303 atomic_t bcast_queue_left;
75304 atomic_t batman_queue_left;
75305 atomic_t ttvn; /* translation table version number */
75306diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
75307index 74175c2..32f8901 100644
75308--- a/net/batman-adv/unicast.c
75309+++ b/net/batman-adv/unicast.c
75310@@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
75311 frag1->flags = UNI_FRAG_HEAD | large_tail;
75312 frag2->flags = large_tail;
75313
75314- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
75315+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
75316 frag1->seqno = htons(seqno - 1);
75317 frag2->seqno = htons(seqno);
75318
75319diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
75320index 5914623..bedc768 100644
75321--- a/net/bluetooth/hci_sock.c
75322+++ b/net/bluetooth/hci_sock.c
75323@@ -706,6 +706,7 @@ static int hci_sock_getname(struct socket *sock, struct sockaddr *addr, int *add
75324 *addr_len = sizeof(*haddr);
75325 haddr->hci_family = AF_BLUETOOTH;
75326 haddr->hci_dev = hdev->id;
75327+ haddr->hci_channel= 0;
75328
75329 release_sock(sk);
75330 return 0;
75331@@ -1016,6 +1017,7 @@ static int hci_sock_getsockopt(struct socket *sock, int level, int optname, char
75332 {
75333 struct hci_filter *f = &hci_pi(sk)->filter;
75334
75335+ memset(&uf, 0, sizeof(uf));
75336 uf.type_mask = f->type_mask;
75337 uf.opcode = f->opcode;
75338 uf.event_mask[0] = *((u32 *) f->event_mask + 0);
75339diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
75340index 4554e80..b778671 100644
75341--- a/net/bluetooth/l2cap_core.c
75342+++ b/net/bluetooth/l2cap_core.c
75343@@ -2798,8 +2798,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
75344 break;
75345
75346 case L2CAP_CONF_RFC:
75347- if (olen == sizeof(rfc))
75348- memcpy(&rfc, (void *)val, olen);
75349+ if (olen != sizeof(rfc))
75350+ break;
75351+
75352+ memcpy(&rfc, (void *)val, olen);
75353
75354 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
75355 rfc.mode != chan->mode)
75356diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
75357index 3bb1611..fcf656b 100644
75358--- a/net/bluetooth/l2cap_sock.c
75359+++ b/net/bluetooth/l2cap_sock.c
75360@@ -246,6 +246,7 @@ static int l2cap_sock_getname(struct socket *sock, struct sockaddr *addr, int *l
75361
75362 BT_DBG("sock %p, sk %p", sock, sk);
75363
75364+ memset(la, 0, sizeof(struct sockaddr_l2));
75365 addr->sa_family = AF_BLUETOOTH;
75366 *len = sizeof(struct sockaddr_l2);
75367
75368diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
75369index e8707de..2df6956 100644
75370--- a/net/bluetooth/rfcomm/sock.c
75371+++ b/net/bluetooth/rfcomm/sock.c
75372@@ -547,6 +547,7 @@ static int rfcomm_sock_getname(struct socket *sock, struct sockaddr *addr, int *
75373
75374 BT_DBG("sock %p, sk %p", sock, sk);
75375
75376+ memset(sa, 0, sizeof(*sa));
75377 sa->rc_family = AF_BLUETOOTH;
75378 sa->rc_channel = rfcomm_pi(sk)->channel;
75379 if (peer)
75380@@ -841,6 +842,7 @@ static int rfcomm_sock_getsockopt(struct socket *sock, int level, int optname, c
75381 }
75382
75383 sec.level = rfcomm_pi(sk)->sec_level;
75384+ sec.key_size = 0;
75385
75386 len = min_t(unsigned int, len, sizeof(sec));
75387 if (copy_to_user(optval, (char *) &sec, len))
75388diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
75389index d1820ff..4f8c8f6 100644
75390--- a/net/bluetooth/rfcomm/tty.c
75391+++ b/net/bluetooth/rfcomm/tty.c
75392@@ -314,7 +314,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
75393 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
75394
75395 spin_lock_irqsave(&dev->port.lock, flags);
75396- if (dev->port.count > 0) {
75397+ if (atomic_read(&dev->port.count) > 0) {
75398 spin_unlock_irqrestore(&dev->port.lock, flags);
75399 return;
75400 }
75401@@ -461,7 +461,7 @@ static int rfcomm_get_dev_list(void __user *arg)
75402
75403 size = sizeof(*dl) + dev_num * sizeof(*di);
75404
75405- dl = kmalloc(size, GFP_KERNEL);
75406+ dl = kzalloc(size, GFP_KERNEL);
75407 if (!dl)
75408 return -ENOMEM;
75409
75410@@ -669,10 +669,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
75411 return -ENODEV;
75412
75413 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
75414- dev->channel, dev->port.count);
75415+ dev->channel, atomic_read(&dev->port.count));
75416
75417 spin_lock_irqsave(&dev->port.lock, flags);
75418- if (++dev->port.count > 1) {
75419+ if (atomic_inc_return(&dev->port.count) > 1) {
75420 spin_unlock_irqrestore(&dev->port.lock, flags);
75421 return 0;
75422 }
75423@@ -737,10 +737,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
75424 return;
75425
75426 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
75427- dev->port.count);
75428+ atomic_read(&dev->port.count));
75429
75430 spin_lock_irqsave(&dev->port.lock, flags);
75431- if (!--dev->port.count) {
75432+ if (!atomic_dec_return(&dev->port.count)) {
75433 spin_unlock_irqrestore(&dev->port.lock, flags);
75434 if (dev->tty_dev->parent)
75435 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
75436diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
75437index 5fe2ff3..10968b5 100644
75438--- a/net/bridge/netfilter/ebtables.c
75439+++ b/net/bridge/netfilter/ebtables.c
75440@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
75441 tmp.valid_hooks = t->table->valid_hooks;
75442 }
75443 mutex_unlock(&ebt_mutex);
75444- if (copy_to_user(user, &tmp, *len) != 0){
75445+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
75446 BUGPRINT("c2u Didn't work\n");
75447 ret = -EFAULT;
75448 break;
75449diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
75450index 047cd0e..461fd28 100644
75451--- a/net/caif/cfctrl.c
75452+++ b/net/caif/cfctrl.c
75453@@ -10,6 +10,7 @@
75454 #include <linux/spinlock.h>
75455 #include <linux/slab.h>
75456 #include <linux/pkt_sched.h>
75457+#include <linux/sched.h>
75458 #include <net/caif/caif_layer.h>
75459 #include <net/caif/cfpkt.h>
75460 #include <net/caif/cfctrl.h>
75461@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
75462 memset(&dev_info, 0, sizeof(dev_info));
75463 dev_info.id = 0xff;
75464 cfsrvl_init(&this->serv, 0, &dev_info, false);
75465- atomic_set(&this->req_seq_no, 1);
75466- atomic_set(&this->rsp_seq_no, 1);
75467+ atomic_set_unchecked(&this->req_seq_no, 1);
75468+ atomic_set_unchecked(&this->rsp_seq_no, 1);
75469 this->serv.layer.receive = cfctrl_recv;
75470 sprintf(this->serv.layer.name, "ctrl");
75471 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
75472@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
75473 struct cfctrl_request_info *req)
75474 {
75475 spin_lock_bh(&ctrl->info_list_lock);
75476- atomic_inc(&ctrl->req_seq_no);
75477- req->sequence_no = atomic_read(&ctrl->req_seq_no);
75478+ atomic_inc_unchecked(&ctrl->req_seq_no);
75479+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
75480 list_add_tail(&req->list, &ctrl->list);
75481 spin_unlock_bh(&ctrl->info_list_lock);
75482 }
75483@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
75484 if (p != first)
75485 pr_warn("Requests are not received in order\n");
75486
75487- atomic_set(&ctrl->rsp_seq_no,
75488+ atomic_set_unchecked(&ctrl->rsp_seq_no,
75489 p->sequence_no);
75490 list_del(&p->list);
75491 goto out;
75492diff --git a/net/caif/chnl_net.c b/net/caif/chnl_net.c
75493index 69771c0..e597733 100644
75494--- a/net/caif/chnl_net.c
75495+++ b/net/caif/chnl_net.c
75496@@ -94,6 +94,10 @@ static int chnl_recv_cb(struct cflayer *layr, struct cfpkt *pkt)
75497
75498 /* check the version of IP */
75499 ip_version = skb_header_pointer(skb, 0, 1, &buf);
75500+ if (!ip_version) {
75501+ kfree_skb(skb);
75502+ return -EINVAL;
75503+ }
75504
75505 switch (*ip_version >> 4) {
75506 case 4:
75507diff --git a/net/can/gw.c b/net/can/gw.c
75508index b41acf2..3affb3a 100644
75509--- a/net/can/gw.c
75510+++ b/net/can/gw.c
75511@@ -96,7 +96,7 @@ struct cf_mod {
75512 struct {
75513 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
75514 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
75515- } csumfunc;
75516+ } __no_const csumfunc;
75517 };
75518
75519
75520diff --git a/net/compat.c b/net/compat.c
75521index 74ed1d7..62f7ea6 100644
75522--- a/net/compat.c
75523+++ b/net/compat.c
75524@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
75525 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
75526 __get_user(kmsg->msg_flags, &umsg->msg_flags))
75527 return -EFAULT;
75528- kmsg->msg_name = compat_ptr(tmp1);
75529- kmsg->msg_iov = compat_ptr(tmp2);
75530- kmsg->msg_control = compat_ptr(tmp3);
75531+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
75532+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
75533+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
75534 return 0;
75535 }
75536
75537@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75538
75539 if (kern_msg->msg_namelen) {
75540 if (mode == VERIFY_READ) {
75541- int err = move_addr_to_kernel(kern_msg->msg_name,
75542+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
75543 kern_msg->msg_namelen,
75544 kern_address);
75545 if (err < 0)
75546@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75547 kern_msg->msg_name = NULL;
75548
75549 tot_len = iov_from_user_compat_to_kern(kern_iov,
75550- (struct compat_iovec __user *)kern_msg->msg_iov,
75551+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
75552 kern_msg->msg_iovlen);
75553 if (tot_len >= 0)
75554 kern_msg->msg_iov = kern_iov;
75555@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75556
75557 #define CMSG_COMPAT_FIRSTHDR(msg) \
75558 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
75559- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
75560+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
75561 (struct compat_cmsghdr __user *)NULL)
75562
75563 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
75564 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
75565 (ucmlen) <= (unsigned long) \
75566 ((mhdr)->msg_controllen - \
75567- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
75568+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
75569
75570 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
75571 struct compat_cmsghdr __user *cmsg, int cmsg_len)
75572 {
75573 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
75574- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
75575+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
75576 msg->msg_controllen)
75577 return NULL;
75578 return (struct compat_cmsghdr __user *)ptr;
75579@@ -219,7 +219,7 @@ Efault:
75580
75581 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
75582 {
75583- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
75584+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
75585 struct compat_cmsghdr cmhdr;
75586 struct compat_timeval ctv;
75587 struct compat_timespec cts[3];
75588@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
75589
75590 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
75591 {
75592- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
75593+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
75594 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
75595 int fdnum = scm->fp->count;
75596 struct file **fp = scm->fp->fp;
75597@@ -364,7 +364,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
75598 return -EFAULT;
75599 old_fs = get_fs();
75600 set_fs(KERNEL_DS);
75601- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
75602+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
75603 set_fs(old_fs);
75604
75605 return err;
75606@@ -425,7 +425,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
75607 len = sizeof(ktime);
75608 old_fs = get_fs();
75609 set_fs(KERNEL_DS);
75610- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
75611+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
75612 set_fs(old_fs);
75613
75614 if (!err) {
75615@@ -568,7 +568,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75616 case MCAST_JOIN_GROUP:
75617 case MCAST_LEAVE_GROUP:
75618 {
75619- struct compat_group_req __user *gr32 = (void *)optval;
75620+ struct compat_group_req __user *gr32 = (void __user *)optval;
75621 struct group_req __user *kgr =
75622 compat_alloc_user_space(sizeof(struct group_req));
75623 u32 interface;
75624@@ -589,7 +589,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75625 case MCAST_BLOCK_SOURCE:
75626 case MCAST_UNBLOCK_SOURCE:
75627 {
75628- struct compat_group_source_req __user *gsr32 = (void *)optval;
75629+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
75630 struct group_source_req __user *kgsr = compat_alloc_user_space(
75631 sizeof(struct group_source_req));
75632 u32 interface;
75633@@ -610,7 +610,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75634 }
75635 case MCAST_MSFILTER:
75636 {
75637- struct compat_group_filter __user *gf32 = (void *)optval;
75638+ struct compat_group_filter __user *gf32 = (void __user *)optval;
75639 struct group_filter __user *kgf;
75640 u32 interface, fmode, numsrc;
75641
75642@@ -648,7 +648,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
75643 char __user *optval, int __user *optlen,
75644 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
75645 {
75646- struct compat_group_filter __user *gf32 = (void *)optval;
75647+ struct compat_group_filter __user *gf32 = (void __user *)optval;
75648 struct group_filter __user *kgf;
75649 int __user *koptlen;
75650 u32 interface, fmode, numsrc;
75651diff --git a/net/core/datagram.c b/net/core/datagram.c
75652index ae6acf6..d5c8f66 100644
75653--- a/net/core/datagram.c
75654+++ b/net/core/datagram.c
75655@@ -290,7 +290,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
75656 }
75657
75658 kfree_skb(skb);
75659- atomic_inc(&sk->sk_drops);
75660+ atomic_inc_unchecked(&sk->sk_drops);
75661 sk_mem_reclaim_partial(sk);
75662
75663 return err;
75664diff --git a/net/core/dev.c b/net/core/dev.c
75665index a000840..566cee1 100644
75666--- a/net/core/dev.c
75667+++ b/net/core/dev.c
75668@@ -1135,9 +1135,13 @@ void dev_load(struct net *net, const char *name)
75669 if (no_module && capable(CAP_NET_ADMIN))
75670 no_module = request_module("netdev-%s", name);
75671 if (no_module && capable(CAP_SYS_MODULE)) {
75672+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75673+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
75674+#else
75675 if (!request_module("%s", name))
75676 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
75677 name);
75678+#endif
75679 }
75680 }
75681 EXPORT_SYMBOL(dev_load);
75682@@ -1602,7 +1606,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75683 {
75684 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
75685 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
75686- atomic_long_inc(&dev->rx_dropped);
75687+ atomic_long_inc_unchecked(&dev->rx_dropped);
75688 kfree_skb(skb);
75689 return NET_RX_DROP;
75690 }
75691@@ -1612,7 +1616,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75692 nf_reset(skb);
75693
75694 if (unlikely(!is_skb_forwardable(dev, skb))) {
75695- atomic_long_inc(&dev->rx_dropped);
75696+ atomic_long_inc_unchecked(&dev->rx_dropped);
75697 kfree_skb(skb);
75698 return NET_RX_DROP;
75699 }
75700@@ -2041,7 +2045,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
75701
75702 struct dev_gso_cb {
75703 void (*destructor)(struct sk_buff *skb);
75704-};
75705+} __no_const;
75706
75707 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
75708
75709@@ -2876,7 +2880,7 @@ enqueue:
75710
75711 local_irq_restore(flags);
75712
75713- atomic_long_inc(&skb->dev->rx_dropped);
75714+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75715 kfree_skb(skb);
75716 return NET_RX_DROP;
75717 }
75718@@ -2948,7 +2952,7 @@ int netif_rx_ni(struct sk_buff *skb)
75719 }
75720 EXPORT_SYMBOL(netif_rx_ni);
75721
75722-static void net_tx_action(struct softirq_action *h)
75723+static void net_tx_action(void)
75724 {
75725 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75726
75727@@ -3235,7 +3239,7 @@ ncls:
75728 if (pt_prev) {
75729 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
75730 } else {
75731- atomic_long_inc(&skb->dev->rx_dropped);
75732+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75733 kfree_skb(skb);
75734 /* Jamal, now you will not able to escape explaining
75735 * me how you were going to use this. :-)
75736@@ -3800,7 +3804,7 @@ void netif_napi_del(struct napi_struct *napi)
75737 }
75738 EXPORT_SYMBOL(netif_napi_del);
75739
75740-static void net_rx_action(struct softirq_action *h)
75741+static void net_rx_action(void)
75742 {
75743 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75744 unsigned long time_limit = jiffies + 2;
75745@@ -4270,8 +4274,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
75746 else
75747 seq_printf(seq, "%04x", ntohs(pt->type));
75748
75749+#ifdef CONFIG_GRKERNSEC_HIDESYM
75750+ seq_printf(seq, " %-8s %p\n",
75751+ pt->dev ? pt->dev->name : "", NULL);
75752+#else
75753 seq_printf(seq, " %-8s %pF\n",
75754 pt->dev ? pt->dev->name : "", pt->func);
75755+#endif
75756 }
75757
75758 return 0;
75759@@ -5823,7 +5832,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
75760 } else {
75761 netdev_stats_to_stats64(storage, &dev->stats);
75762 }
75763- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
75764+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
75765 return storage;
75766 }
75767 EXPORT_SYMBOL(dev_get_stats);
75768diff --git a/net/core/flow.c b/net/core/flow.c
75769index e318c7e..168b1d0 100644
75770--- a/net/core/flow.c
75771+++ b/net/core/flow.c
75772@@ -61,7 +61,7 @@ struct flow_cache {
75773 struct timer_list rnd_timer;
75774 };
75775
75776-atomic_t flow_cache_genid = ATOMIC_INIT(0);
75777+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
75778 EXPORT_SYMBOL(flow_cache_genid);
75779 static struct flow_cache flow_cache_global;
75780 static struct kmem_cache *flow_cachep __read_mostly;
75781@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
75782
75783 static int flow_entry_valid(struct flow_cache_entry *fle)
75784 {
75785- if (atomic_read(&flow_cache_genid) != fle->genid)
75786+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
75787 return 0;
75788 if (fle->object && !fle->object->ops->check(fle->object))
75789 return 0;
75790@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
75791 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
75792 fcp->hash_count++;
75793 }
75794- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
75795+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
75796 flo = fle->object;
75797 if (!flo)
75798 goto ret_object;
75799@@ -280,7 +280,7 @@ nocache:
75800 }
75801 flo = resolver(net, key, family, dir, flo, ctx);
75802 if (fle) {
75803- fle->genid = atomic_read(&flow_cache_genid);
75804+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
75805 if (!IS_ERR(flo))
75806 fle->object = flo;
75807 else
75808diff --git a/net/core/iovec.c b/net/core/iovec.c
75809index 7e7aeb0..2a998cb 100644
75810--- a/net/core/iovec.c
75811+++ b/net/core/iovec.c
75812@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
75813 if (m->msg_namelen) {
75814 if (mode == VERIFY_READ) {
75815 void __user *namep;
75816- namep = (void __user __force *) m->msg_name;
75817+ namep = (void __force_user *) m->msg_name;
75818 err = move_addr_to_kernel(namep, m->msg_namelen,
75819 address);
75820 if (err < 0)
75821@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
75822 }
75823
75824 size = m->msg_iovlen * sizeof(struct iovec);
75825- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
75826+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
75827 return -EFAULT;
75828
75829 m->msg_iov = iov;
75830diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
75831index 6c50ac0..6b4c038 100644
75832--- a/net/core/rtnetlink.c
75833+++ b/net/core/rtnetlink.c
75834@@ -58,7 +58,7 @@ struct rtnl_link {
75835 rtnl_doit_func doit;
75836 rtnl_dumpit_func dumpit;
75837 rtnl_calcit_func calcit;
75838-};
75839+} __no_const;
75840
75841 static DEFINE_MUTEX(rtnl_mutex);
75842
75843diff --git a/net/core/scm.c b/net/core/scm.c
75844index 611c5ef..88f6d6d 100644
75845--- a/net/core/scm.c
75846+++ b/net/core/scm.c
75847@@ -219,7 +219,7 @@ EXPORT_SYMBOL(__scm_send);
75848 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75849 {
75850 struct cmsghdr __user *cm
75851- = (__force struct cmsghdr __user *)msg->msg_control;
75852+ = (struct cmsghdr __force_user *)msg->msg_control;
75853 struct cmsghdr cmhdr;
75854 int cmlen = CMSG_LEN(len);
75855 int err;
75856@@ -242,7 +242,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75857 err = -EFAULT;
75858 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
75859 goto out;
75860- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
75861+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
75862 goto out;
75863 cmlen = CMSG_SPACE(len);
75864 if (msg->msg_controllen < cmlen)
75865@@ -258,7 +258,7 @@ EXPORT_SYMBOL(put_cmsg);
75866 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75867 {
75868 struct cmsghdr __user *cm
75869- = (__force struct cmsghdr __user*)msg->msg_control;
75870+ = (struct cmsghdr __force_user *)msg->msg_control;
75871
75872 int fdmax = 0;
75873 int fdnum = scm->fp->count;
75874@@ -278,7 +278,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75875 if (fdnum < fdmax)
75876 fdmax = fdnum;
75877
75878- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
75879+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
75880 i++, cmfptr++)
75881 {
75882 int new_fd;
75883diff --git a/net/core/sock.c b/net/core/sock.c
75884index 9e5b71f..66dec30 100644
75885--- a/net/core/sock.c
75886+++ b/net/core/sock.c
75887@@ -344,7 +344,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75888 struct sk_buff_head *list = &sk->sk_receive_queue;
75889
75890 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
75891- atomic_inc(&sk->sk_drops);
75892+ atomic_inc_unchecked(&sk->sk_drops);
75893 trace_sock_rcvqueue_full(sk, skb);
75894 return -ENOMEM;
75895 }
75896@@ -354,7 +354,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75897 return err;
75898
75899 if (!sk_rmem_schedule(sk, skb->truesize)) {
75900- atomic_inc(&sk->sk_drops);
75901+ atomic_inc_unchecked(&sk->sk_drops);
75902 return -ENOBUFS;
75903 }
75904
75905@@ -374,7 +374,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75906 skb_dst_force(skb);
75907
75908 spin_lock_irqsave(&list->lock, flags);
75909- skb->dropcount = atomic_read(&sk->sk_drops);
75910+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
75911 __skb_queue_tail(list, skb);
75912 spin_unlock_irqrestore(&list->lock, flags);
75913
75914@@ -394,7 +394,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75915 skb->dev = NULL;
75916
75917 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
75918- atomic_inc(&sk->sk_drops);
75919+ atomic_inc_unchecked(&sk->sk_drops);
75920 goto discard_and_relse;
75921 }
75922 if (nested)
75923@@ -412,7 +412,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75924 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
75925 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
75926 bh_unlock_sock(sk);
75927- atomic_inc(&sk->sk_drops);
75928+ atomic_inc_unchecked(&sk->sk_drops);
75929 goto discard_and_relse;
75930 }
75931
75932@@ -976,7 +976,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75933 if (len > sizeof(peercred))
75934 len = sizeof(peercred);
75935 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
75936- if (copy_to_user(optval, &peercred, len))
75937+ if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
75938 return -EFAULT;
75939 goto lenout;
75940 }
75941@@ -989,7 +989,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75942 return -ENOTCONN;
75943 if (lv < len)
75944 return -EINVAL;
75945- if (copy_to_user(optval, address, len))
75946+ if (len > sizeof(address) || copy_to_user(optval, address, len))
75947 return -EFAULT;
75948 goto lenout;
75949 }
75950@@ -1035,7 +1035,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75951
75952 if (len > lv)
75953 len = lv;
75954- if (copy_to_user(optval, &v, len))
75955+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
75956 return -EFAULT;
75957 lenout:
75958 if (put_user(len, optlen))
75959@@ -2124,7 +2124,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
75960 */
75961 smp_wmb();
75962 atomic_set(&sk->sk_refcnt, 1);
75963- atomic_set(&sk->sk_drops, 0);
75964+ atomic_set_unchecked(&sk->sk_drops, 0);
75965 }
75966 EXPORT_SYMBOL(sock_init_data);
75967
75968diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
75969index 5fd1467..8b70900 100644
75970--- a/net/core/sock_diag.c
75971+++ b/net/core/sock_diag.c
75972@@ -16,20 +16,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
75973
75974 int sock_diag_check_cookie(void *sk, __u32 *cookie)
75975 {
75976+#ifndef CONFIG_GRKERNSEC_HIDESYM
75977 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
75978 cookie[1] != INET_DIAG_NOCOOKIE) &&
75979 ((u32)(unsigned long)sk != cookie[0] ||
75980 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
75981 return -ESTALE;
75982 else
75983+#endif
75984 return 0;
75985 }
75986 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
75987
75988 void sock_diag_save_cookie(void *sk, __u32 *cookie)
75989 {
75990+#ifdef CONFIG_GRKERNSEC_HIDESYM
75991+ cookie[0] = 0;
75992+ cookie[1] = 0;
75993+#else
75994 cookie[0] = (u32)(unsigned long)sk;
75995 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
75996+#endif
75997 }
75998 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
75999
76000diff --git a/net/dccp/ccid.h b/net/dccp/ccid.h
76001index 75c3582..fb85d37 100644
76002--- a/net/dccp/ccid.h
76003+++ b/net/dccp/ccid.h
76004@@ -246,7 +246,7 @@ static inline int ccid_hc_rx_getsockopt(struct ccid *ccid, struct sock *sk,
76005 u32 __user *optval, int __user *optlen)
76006 {
76007 int rc = -ENOPROTOOPT;
76008- if (ccid->ccid_ops->ccid_hc_rx_getsockopt != NULL)
76009+ if (ccid != NULL && ccid->ccid_ops->ccid_hc_rx_getsockopt != NULL)
76010 rc = ccid->ccid_ops->ccid_hc_rx_getsockopt(sk, optname, len,
76011 optval, optlen);
76012 return rc;
76013@@ -257,7 +257,7 @@ static inline int ccid_hc_tx_getsockopt(struct ccid *ccid, struct sock *sk,
76014 u32 __user *optval, int __user *optlen)
76015 {
76016 int rc = -ENOPROTOOPT;
76017- if (ccid->ccid_ops->ccid_hc_tx_getsockopt != NULL)
76018+ if (ccid != NULL && ccid->ccid_ops->ccid_hc_tx_getsockopt != NULL)
76019 rc = ccid->ccid_ops->ccid_hc_tx_getsockopt(sk, optname, len,
76020 optval, optlen);
76021 return rc;
76022diff --git a/net/dccp/ccids/ccid3.c b/net/dccp/ccids/ccid3.c
76023index 8c67bed..ce0d140 100644
76024--- a/net/dccp/ccids/ccid3.c
76025+++ b/net/dccp/ccids/ccid3.c
76026@@ -531,6 +531,7 @@ static int ccid3_hc_tx_getsockopt(struct sock *sk, const int optname, int len,
76027 case DCCP_SOCKOPT_CCID_TX_INFO:
76028 if (len < sizeof(tfrc))
76029 return -EINVAL;
76030+ memset(&tfrc, 0, sizeof(tfrc));
76031 tfrc.tfrctx_x = hc->tx_x;
76032 tfrc.tfrctx_x_recv = hc->tx_x_recv;
76033 tfrc.tfrctx_x_calc = hc->tx_x_calc;
76034diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
76035index a55eecc..dd8428c 100644
76036--- a/net/decnet/sysctl_net_decnet.c
76037+++ b/net/decnet/sysctl_net_decnet.c
76038@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
76039
76040 if (len > *lenp) len = *lenp;
76041
76042- if (copy_to_user(buffer, addr, len))
76043+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
76044 return -EFAULT;
76045
76046 *lenp = len;
76047@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
76048
76049 if (len > *lenp) len = *lenp;
76050
76051- if (copy_to_user(buffer, devname, len))
76052+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
76053 return -EFAULT;
76054
76055 *lenp = len;
76056diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
76057index 3854411..2201a94 100644
76058--- a/net/ipv4/fib_frontend.c
76059+++ b/net/ipv4/fib_frontend.c
76060@@ -969,12 +969,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
76061 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76062 fib_sync_up(dev);
76063 #endif
76064- atomic_inc(&net->ipv4.dev_addr_genid);
76065+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76066 rt_cache_flush(dev_net(dev), -1);
76067 break;
76068 case NETDEV_DOWN:
76069 fib_del_ifaddr(ifa, NULL);
76070- atomic_inc(&net->ipv4.dev_addr_genid);
76071+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76072 if (ifa->ifa_dev->ifa_list == NULL) {
76073 /* Last address was deleted from this interface.
76074 * Disable IP.
76075@@ -1010,7 +1010,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
76076 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76077 fib_sync_up(dev);
76078 #endif
76079- atomic_inc(&net->ipv4.dev_addr_genid);
76080+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76081 rt_cache_flush(dev_net(dev), -1);
76082 break;
76083 case NETDEV_DOWN:
76084diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
76085index e5b7182..570a90e 100644
76086--- a/net/ipv4/fib_semantics.c
76087+++ b/net/ipv4/fib_semantics.c
76088@@ -698,7 +698,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
76089 nh->nh_saddr = inet_select_addr(nh->nh_dev,
76090 nh->nh_gw,
76091 nh->nh_parent->fib_scope);
76092- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
76093+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
76094
76095 return nh->nh_saddr;
76096 }
76097diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
76098index 7880af9..70f92a3 100644
76099--- a/net/ipv4/inet_hashtables.c
76100+++ b/net/ipv4/inet_hashtables.c
76101@@ -18,12 +18,15 @@
76102 #include <linux/sched.h>
76103 #include <linux/slab.h>
76104 #include <linux/wait.h>
76105+#include <linux/security.h>
76106
76107 #include <net/inet_connection_sock.h>
76108 #include <net/inet_hashtables.h>
76109 #include <net/secure_seq.h>
76110 #include <net/ip.h>
76111
76112+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
76113+
76114 /*
76115 * Allocate and initialize a new local port bind bucket.
76116 * The bindhash mutex for snum's hash chain must be held here.
76117@@ -530,6 +533,8 @@ ok:
76118 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
76119 spin_unlock(&head->lock);
76120
76121+ gr_update_task_in_ip_table(current, inet_sk(sk));
76122+
76123 if (tw) {
76124 inet_twsk_deschedule(tw, death_row);
76125 while (twrefcnt) {
76126diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
76127index dfba343..c827d50 100644
76128--- a/net/ipv4/inetpeer.c
76129+++ b/net/ipv4/inetpeer.c
76130@@ -487,8 +487,8 @@ relookup:
76131 if (p) {
76132 p->daddr = *daddr;
76133 atomic_set(&p->refcnt, 1);
76134- atomic_set(&p->rid, 0);
76135- atomic_set(&p->ip_id_count,
76136+ atomic_set_unchecked(&p->rid, 0);
76137+ atomic_set_unchecked(&p->ip_id_count,
76138 (daddr->family == AF_INET) ?
76139 secure_ip_id(daddr->addr.a4) :
76140 secure_ipv6_id(daddr->addr.a6));
76141diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
76142index 9dbd3dd..0c59fb2 100644
76143--- a/net/ipv4/ip_fragment.c
76144+++ b/net/ipv4/ip_fragment.c
76145@@ -318,7 +318,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
76146 return 0;
76147
76148 start = qp->rid;
76149- end = atomic_inc_return(&peer->rid);
76150+ end = atomic_inc_return_unchecked(&peer->rid);
76151 qp->rid = end;
76152
76153 rc = qp->q.fragments && (end - start) > max;
76154diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
76155index 0d11f23..2bb3f64 100644
76156--- a/net/ipv4/ip_sockglue.c
76157+++ b/net/ipv4/ip_sockglue.c
76158@@ -1142,7 +1142,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
76159 len = min_t(unsigned int, len, opt->optlen);
76160 if (put_user(len, optlen))
76161 return -EFAULT;
76162- if (copy_to_user(optval, opt->__data, len))
76163+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
76164+ copy_to_user(optval, opt->__data, len))
76165 return -EFAULT;
76166 return 0;
76167 }
76168@@ -1273,7 +1274,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
76169 if (sk->sk_type != SOCK_STREAM)
76170 return -ENOPROTOOPT;
76171
76172- msg.msg_control = optval;
76173+ msg.msg_control = (void __force_kernel *)optval;
76174 msg.msg_controllen = len;
76175 msg.msg_flags = flags;
76176
76177diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
76178index 67e8a6b..386764d 100644
76179--- a/net/ipv4/ipconfig.c
76180+++ b/net/ipv4/ipconfig.c
76181@@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
76182
76183 mm_segment_t oldfs = get_fs();
76184 set_fs(get_ds());
76185- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
76186+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
76187 set_fs(oldfs);
76188 return res;
76189 }
76190@@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
76191
76192 mm_segment_t oldfs = get_fs();
76193 set_fs(get_ds());
76194- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
76195+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
76196 set_fs(oldfs);
76197 return res;
76198 }
76199@@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
76200
76201 mm_segment_t oldfs = get_fs();
76202 set_fs(get_ds());
76203- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
76204+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
76205 set_fs(oldfs);
76206 return res;
76207 }
76208diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
76209index 2c00e8b..45b3bdd 100644
76210--- a/net/ipv4/ping.c
76211+++ b/net/ipv4/ping.c
76212@@ -845,7 +845,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
76213 sk_rmem_alloc_get(sp),
76214 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76215 atomic_read(&sp->sk_refcnt), sp,
76216- atomic_read(&sp->sk_drops), len);
76217+ atomic_read_unchecked(&sp->sk_drops), len);
76218 }
76219
76220 static int ping_seq_show(struct seq_file *seq, void *v)
76221diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
76222index 4032b81..625143c 100644
76223--- a/net/ipv4/raw.c
76224+++ b/net/ipv4/raw.c
76225@@ -304,7 +304,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
76226 int raw_rcv(struct sock *sk, struct sk_buff *skb)
76227 {
76228 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
76229- atomic_inc(&sk->sk_drops);
76230+ atomic_inc_unchecked(&sk->sk_drops);
76231 kfree_skb(skb);
76232 return NET_RX_DROP;
76233 }
76234@@ -740,16 +740,20 @@ static int raw_init(struct sock *sk)
76235
76236 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
76237 {
76238+ struct icmp_filter filter;
76239+
76240 if (optlen > sizeof(struct icmp_filter))
76241 optlen = sizeof(struct icmp_filter);
76242- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
76243+ if (copy_from_user(&filter, optval, optlen))
76244 return -EFAULT;
76245+ raw_sk(sk)->filter = filter;
76246 return 0;
76247 }
76248
76249 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
76250 {
76251 int len, ret = -EFAULT;
76252+ struct icmp_filter filter;
76253
76254 if (get_user(len, optlen))
76255 goto out;
76256@@ -759,8 +763,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
76257 if (len > sizeof(struct icmp_filter))
76258 len = sizeof(struct icmp_filter);
76259 ret = -EFAULT;
76260- if (put_user(len, optlen) ||
76261- copy_to_user(optval, &raw_sk(sk)->filter, len))
76262+ filter = raw_sk(sk)->filter;
76263+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
76264 goto out;
76265 ret = 0;
76266 out: return ret;
76267@@ -988,7 +992,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76268 sk_wmem_alloc_get(sp),
76269 sk_rmem_alloc_get(sp),
76270 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76271- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76272+ atomic_read(&sp->sk_refcnt),
76273+#ifdef CONFIG_GRKERNSEC_HIDESYM
76274+ NULL,
76275+#else
76276+ sp,
76277+#endif
76278+ atomic_read_unchecked(&sp->sk_drops));
76279 }
76280
76281 static int raw_seq_show(struct seq_file *seq, void *v)
76282diff --git a/net/ipv4/route.c b/net/ipv4/route.c
76283index 98b30d0..cfa3cf7 100644
76284--- a/net/ipv4/route.c
76285+++ b/net/ipv4/route.c
76286@@ -313,7 +313,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
76287
76288 static inline int rt_genid(struct net *net)
76289 {
76290- return atomic_read(&net->ipv4.rt_genid);
76291+ return atomic_read_unchecked(&net->ipv4.rt_genid);
76292 }
76293
76294 #ifdef CONFIG_PROC_FS
76295@@ -937,7 +937,7 @@ static void rt_cache_invalidate(struct net *net)
76296 unsigned char shuffle;
76297
76298 get_random_bytes(&shuffle, sizeof(shuffle));
76299- atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
76300+ atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
76301 inetpeer_invalidate_tree(AF_INET);
76302 }
76303
76304@@ -3011,7 +3011,7 @@ static int rt_fill_info(struct net *net,
76305 error = rt->dst.error;
76306 if (peer) {
76307 inet_peer_refcheck(rt->peer);
76308- id = atomic_read(&peer->ip_id_count) & 0xffff;
76309+ id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
76310 if (peer->tcp_ts_stamp) {
76311 ts = peer->tcp_ts;
76312 tsage = get_seconds() - peer->tcp_ts_stamp;
76313diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
76314index c8d28c4..e40f75a 100644
76315--- a/net/ipv4/tcp_ipv4.c
76316+++ b/net/ipv4/tcp_ipv4.c
76317@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
76318 EXPORT_SYMBOL(sysctl_tcp_low_latency);
76319
76320
76321+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76322+extern int grsec_enable_blackhole;
76323+#endif
76324+
76325 #ifdef CONFIG_TCP_MD5SIG
76326 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
76327 __be32 daddr, __be32 saddr, const struct tcphdr *th);
76328@@ -1656,6 +1660,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
76329 return 0;
76330
76331 reset:
76332+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76333+ if (!grsec_enable_blackhole)
76334+#endif
76335 tcp_v4_send_reset(rsk, skb);
76336 discard:
76337 kfree_skb(skb);
76338@@ -1718,12 +1725,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
76339 TCP_SKB_CB(skb)->sacked = 0;
76340
76341 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76342- if (!sk)
76343+ if (!sk) {
76344+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76345+ ret = 1;
76346+#endif
76347 goto no_tcp_socket;
76348-
76349+ }
76350 process:
76351- if (sk->sk_state == TCP_TIME_WAIT)
76352+ if (sk->sk_state == TCP_TIME_WAIT) {
76353+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76354+ ret = 2;
76355+#endif
76356 goto do_time_wait;
76357+ }
76358
76359 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
76360 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76361@@ -1774,6 +1788,10 @@ no_tcp_socket:
76362 bad_packet:
76363 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76364 } else {
76365+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76366+ if (!grsec_enable_blackhole || (ret == 1 &&
76367+ (skb->dev->flags & IFF_LOOPBACK)))
76368+#endif
76369 tcp_v4_send_reset(NULL, skb);
76370 }
76371
76372@@ -2386,7 +2404,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
76373 0, /* non standard timer */
76374 0, /* open_requests have no inode */
76375 atomic_read(&sk->sk_refcnt),
76376+#ifdef CONFIG_GRKERNSEC_HIDESYM
76377+ NULL,
76378+#else
76379 req,
76380+#endif
76381 len);
76382 }
76383
76384@@ -2436,7 +2458,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
76385 sock_i_uid(sk),
76386 icsk->icsk_probes_out,
76387 sock_i_ino(sk),
76388- atomic_read(&sk->sk_refcnt), sk,
76389+ atomic_read(&sk->sk_refcnt),
76390+#ifdef CONFIG_GRKERNSEC_HIDESYM
76391+ NULL,
76392+#else
76393+ sk,
76394+#endif
76395 jiffies_to_clock_t(icsk->icsk_rto),
76396 jiffies_to_clock_t(icsk->icsk_ack.ato),
76397 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
76398@@ -2464,7 +2491,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
76399 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
76400 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
76401 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76402- atomic_read(&tw->tw_refcnt), tw, len);
76403+ atomic_read(&tw->tw_refcnt),
76404+#ifdef CONFIG_GRKERNSEC_HIDESYM
76405+ NULL,
76406+#else
76407+ tw,
76408+#endif
76409+ len);
76410 }
76411
76412 #define TMPSZ 150
76413diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
76414index b85d9fe..4b0eed9 100644
76415--- a/net/ipv4/tcp_minisocks.c
76416+++ b/net/ipv4/tcp_minisocks.c
76417@@ -27,6 +27,10 @@
76418 #include <net/inet_common.h>
76419 #include <net/xfrm.h>
76420
76421+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76422+extern int grsec_enable_blackhole;
76423+#endif
76424+
76425 int sysctl_tcp_syncookies __read_mostly = 1;
76426 EXPORT_SYMBOL(sysctl_tcp_syncookies);
76427
76428@@ -754,6 +758,10 @@ listen_overflow:
76429
76430 embryonic_reset:
76431 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
76432+
76433+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76434+ if (!grsec_enable_blackhole)
76435+#endif
76436 if (!(flg & TCP_FLAG_RST))
76437 req->rsk_ops->send_reset(sk, skb);
76438
76439diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
76440index 4526fe6..1a34e43 100644
76441--- a/net/ipv4/tcp_probe.c
76442+++ b/net/ipv4/tcp_probe.c
76443@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
76444 if (cnt + width >= len)
76445 break;
76446
76447- if (copy_to_user(buf + cnt, tbuf, width))
76448+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
76449 return -EFAULT;
76450 cnt += width;
76451 }
76452diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
76453index e911e6c..d0a9356 100644
76454--- a/net/ipv4/tcp_timer.c
76455+++ b/net/ipv4/tcp_timer.c
76456@@ -22,6 +22,10 @@
76457 #include <linux/gfp.h>
76458 #include <net/tcp.h>
76459
76460+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76461+extern int grsec_lastack_retries;
76462+#endif
76463+
76464 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
76465 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
76466 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
76467@@ -196,6 +200,13 @@ static int tcp_write_timeout(struct sock *sk)
76468 }
76469 }
76470
76471+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76472+ if ((sk->sk_state == TCP_LAST_ACK) &&
76473+ (grsec_lastack_retries > 0) &&
76474+ (grsec_lastack_retries < retry_until))
76475+ retry_until = grsec_lastack_retries;
76476+#endif
76477+
76478 if (retransmits_timed_out(sk, retry_until,
76479 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
76480 /* Has it gone just too far? */
76481diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
76482index eaca736..60488ae 100644
76483--- a/net/ipv4/udp.c
76484+++ b/net/ipv4/udp.c
76485@@ -87,6 +87,7 @@
76486 #include <linux/types.h>
76487 #include <linux/fcntl.h>
76488 #include <linux/module.h>
76489+#include <linux/security.h>
76490 #include <linux/socket.h>
76491 #include <linux/sockios.h>
76492 #include <linux/igmp.h>
76493@@ -110,6 +111,10 @@
76494 #include <linux/static_key.h>
76495 #include "udp_impl.h"
76496
76497+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76498+extern int grsec_enable_blackhole;
76499+#endif
76500+
76501 struct udp_table udp_table __read_mostly;
76502 EXPORT_SYMBOL(udp_table);
76503
76504@@ -568,6 +573,9 @@ found:
76505 return s;
76506 }
76507
76508+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
76509+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
76510+
76511 /*
76512 * This routine is called by the ICMP module when it gets some
76513 * sort of error condition. If err < 0 then the socket should
76514@@ -859,9 +867,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
76515 dport = usin->sin_port;
76516 if (dport == 0)
76517 return -EINVAL;
76518+
76519+ err = gr_search_udp_sendmsg(sk, usin);
76520+ if (err)
76521+ return err;
76522 } else {
76523 if (sk->sk_state != TCP_ESTABLISHED)
76524 return -EDESTADDRREQ;
76525+
76526+ err = gr_search_udp_sendmsg(sk, NULL);
76527+ if (err)
76528+ return err;
76529+
76530 daddr = inet->inet_daddr;
76531 dport = inet->inet_dport;
76532 /* Open fast path for connected socket.
76533@@ -1103,7 +1120,7 @@ static unsigned int first_packet_length(struct sock *sk)
76534 udp_lib_checksum_complete(skb)) {
76535 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76536 IS_UDPLITE(sk));
76537- atomic_inc(&sk->sk_drops);
76538+ atomic_inc_unchecked(&sk->sk_drops);
76539 __skb_unlink(skb, rcvq);
76540 __skb_queue_tail(&list_kill, skb);
76541 }
76542@@ -1189,6 +1206,10 @@ try_again:
76543 if (!skb)
76544 goto out;
76545
76546+ err = gr_search_udp_recvmsg(sk, skb);
76547+ if (err)
76548+ goto out_free;
76549+
76550 ulen = skb->len - sizeof(struct udphdr);
76551 copied = len;
76552 if (copied > ulen)
76553@@ -1498,7 +1519,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76554
76555 drop:
76556 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76557- atomic_inc(&sk->sk_drops);
76558+ atomic_inc_unchecked(&sk->sk_drops);
76559 kfree_skb(skb);
76560 return -1;
76561 }
76562@@ -1517,7 +1538,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76563 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
76564
76565 if (!skb1) {
76566- atomic_inc(&sk->sk_drops);
76567+ atomic_inc_unchecked(&sk->sk_drops);
76568 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
76569 IS_UDPLITE(sk));
76570 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76571@@ -1686,6 +1707,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76572 goto csum_error;
76573
76574 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
76575+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76576+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76577+#endif
76578 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
76579
76580 /*
76581@@ -2104,8 +2128,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
76582 sk_wmem_alloc_get(sp),
76583 sk_rmem_alloc_get(sp),
76584 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76585- atomic_read(&sp->sk_refcnt), sp,
76586- atomic_read(&sp->sk_drops), len);
76587+ atomic_read(&sp->sk_refcnt),
76588+#ifdef CONFIG_GRKERNSEC_HIDESYM
76589+ NULL,
76590+#else
76591+ sp,
76592+#endif
76593+ atomic_read_unchecked(&sp->sk_drops), len);
76594 }
76595
76596 int udp4_seq_show(struct seq_file *seq, void *v)
76597diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
76598index 8f6411c..5767579 100644
76599--- a/net/ipv6/addrconf.c
76600+++ b/net/ipv6/addrconf.c
76601@@ -2145,7 +2145,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
76602 p.iph.ihl = 5;
76603 p.iph.protocol = IPPROTO_IPV6;
76604 p.iph.ttl = 64;
76605- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
76606+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
76607
76608 if (ops->ndo_do_ioctl) {
76609 mm_segment_t oldfs = get_fs();
76610diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
76611index e6cee52..cf47476 100644
76612--- a/net/ipv6/inet6_connection_sock.c
76613+++ b/net/ipv6/inet6_connection_sock.c
76614@@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
76615 #ifdef CONFIG_XFRM
76616 {
76617 struct rt6_info *rt = (struct rt6_info *)dst;
76618- rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
76619+ rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
76620 }
76621 #endif
76622 }
76623@@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
76624 #ifdef CONFIG_XFRM
76625 if (dst) {
76626 struct rt6_info *rt = (struct rt6_info *)dst;
76627- if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
76628+ if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
76629 __sk_dst_reset(sk);
76630 dst = NULL;
76631 }
76632diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
76633index ba6d13d..6899122 100644
76634--- a/net/ipv6/ipv6_sockglue.c
76635+++ b/net/ipv6/ipv6_sockglue.c
76636@@ -989,7 +989,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
76637 if (sk->sk_type != SOCK_STREAM)
76638 return -ENOPROTOOPT;
76639
76640- msg.msg_control = optval;
76641+ msg.msg_control = (void __force_kernel *)optval;
76642 msg.msg_controllen = len;
76643 msg.msg_flags = flags;
76644
76645diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
76646index 93d6983..8e54c4d 100644
76647--- a/net/ipv6/raw.c
76648+++ b/net/ipv6/raw.c
76649@@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
76650 {
76651 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
76652 skb_checksum_complete(skb)) {
76653- atomic_inc(&sk->sk_drops);
76654+ atomic_inc_unchecked(&sk->sk_drops);
76655 kfree_skb(skb);
76656 return NET_RX_DROP;
76657 }
76658@@ -405,7 +405,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76659 struct raw6_sock *rp = raw6_sk(sk);
76660
76661 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
76662- atomic_inc(&sk->sk_drops);
76663+ atomic_inc_unchecked(&sk->sk_drops);
76664 kfree_skb(skb);
76665 return NET_RX_DROP;
76666 }
76667@@ -429,7 +429,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76668
76669 if (inet->hdrincl) {
76670 if (skb_checksum_complete(skb)) {
76671- atomic_inc(&sk->sk_drops);
76672+ atomic_inc_unchecked(&sk->sk_drops);
76673 kfree_skb(skb);
76674 return NET_RX_DROP;
76675 }
76676@@ -602,7 +602,7 @@ out:
76677 return err;
76678 }
76679
76680-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
76681+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
76682 struct flowi6 *fl6, struct dst_entry **dstp,
76683 unsigned int flags)
76684 {
76685@@ -914,12 +914,15 @@ do_confirm:
76686 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
76687 char __user *optval, int optlen)
76688 {
76689+ struct icmp6_filter filter;
76690+
76691 switch (optname) {
76692 case ICMPV6_FILTER:
76693 if (optlen > sizeof(struct icmp6_filter))
76694 optlen = sizeof(struct icmp6_filter);
76695- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
76696+ if (copy_from_user(&filter, optval, optlen))
76697 return -EFAULT;
76698+ raw6_sk(sk)->filter = filter;
76699 return 0;
76700 default:
76701 return -ENOPROTOOPT;
76702@@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76703 char __user *optval, int __user *optlen)
76704 {
76705 int len;
76706+ struct icmp6_filter filter;
76707
76708 switch (optname) {
76709 case ICMPV6_FILTER:
76710@@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76711 len = sizeof(struct icmp6_filter);
76712 if (put_user(len, optlen))
76713 return -EFAULT;
76714- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
76715+ filter = raw6_sk(sk)->filter;
76716+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
76717 return -EFAULT;
76718 return 0;
76719 default:
76720@@ -1250,7 +1255,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76721 0, 0L, 0,
76722 sock_i_uid(sp), 0,
76723 sock_i_ino(sp),
76724- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76725+ atomic_read(&sp->sk_refcnt),
76726+#ifdef CONFIG_GRKERNSEC_HIDESYM
76727+ NULL,
76728+#else
76729+ sp,
76730+#endif
76731+ atomic_read_unchecked(&sp->sk_drops));
76732 }
76733
76734 static int raw6_seq_show(struct seq_file *seq, void *v)
76735diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
76736index 9df64a5..39875da 100644
76737--- a/net/ipv6/tcp_ipv6.c
76738+++ b/net/ipv6/tcp_ipv6.c
76739@@ -94,6 +94,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
76740 }
76741 #endif
76742
76743+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76744+extern int grsec_enable_blackhole;
76745+#endif
76746+
76747 static void tcp_v6_hash(struct sock *sk)
76748 {
76749 if (sk->sk_state != TCP_CLOSE) {
76750@@ -1544,6 +1548,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
76751 return 0;
76752
76753 reset:
76754+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76755+ if (!grsec_enable_blackhole)
76756+#endif
76757 tcp_v6_send_reset(sk, skb);
76758 discard:
76759 if (opt_skb)
76760@@ -1625,12 +1632,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
76761 TCP_SKB_CB(skb)->sacked = 0;
76762
76763 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76764- if (!sk)
76765+ if (!sk) {
76766+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76767+ ret = 1;
76768+#endif
76769 goto no_tcp_socket;
76770+ }
76771
76772 process:
76773- if (sk->sk_state == TCP_TIME_WAIT)
76774+ if (sk->sk_state == TCP_TIME_WAIT) {
76775+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76776+ ret = 2;
76777+#endif
76778 goto do_time_wait;
76779+ }
76780
76781 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
76782 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76783@@ -1679,6 +1694,10 @@ no_tcp_socket:
76784 bad_packet:
76785 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76786 } else {
76787+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76788+ if (!grsec_enable_blackhole || (ret == 1 &&
76789+ (skb->dev->flags & IFF_LOOPBACK)))
76790+#endif
76791 tcp_v6_send_reset(NULL, skb);
76792 }
76793
76794@@ -1885,7 +1904,13 @@ static void get_openreq6(struct seq_file *seq,
76795 uid,
76796 0, /* non standard timer */
76797 0, /* open_requests have no inode */
76798- 0, req);
76799+ 0,
76800+#ifdef CONFIG_GRKERNSEC_HIDESYM
76801+ NULL
76802+#else
76803+ req
76804+#endif
76805+ );
76806 }
76807
76808 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76809@@ -1935,7 +1960,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76810 sock_i_uid(sp),
76811 icsk->icsk_probes_out,
76812 sock_i_ino(sp),
76813- atomic_read(&sp->sk_refcnt), sp,
76814+ atomic_read(&sp->sk_refcnt),
76815+#ifdef CONFIG_GRKERNSEC_HIDESYM
76816+ NULL,
76817+#else
76818+ sp,
76819+#endif
76820 jiffies_to_clock_t(icsk->icsk_rto),
76821 jiffies_to_clock_t(icsk->icsk_ack.ato),
76822 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
76823@@ -1970,7 +2000,13 @@ static void get_timewait6_sock(struct seq_file *seq,
76824 dest->s6_addr32[2], dest->s6_addr32[3], destp,
76825 tw->tw_substate, 0, 0,
76826 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76827- atomic_read(&tw->tw_refcnt), tw);
76828+ atomic_read(&tw->tw_refcnt),
76829+#ifdef CONFIG_GRKERNSEC_HIDESYM
76830+ NULL
76831+#else
76832+ tw
76833+#endif
76834+ );
76835 }
76836
76837 static int tcp6_seq_show(struct seq_file *seq, void *v)
76838diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
76839index f05099f..ea613f0 100644
76840--- a/net/ipv6/udp.c
76841+++ b/net/ipv6/udp.c
76842@@ -50,6 +50,10 @@
76843 #include <linux/seq_file.h>
76844 #include "udp_impl.h"
76845
76846+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76847+extern int grsec_enable_blackhole;
76848+#endif
76849+
76850 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
76851 {
76852 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
76853@@ -615,7 +619,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76854 return rc;
76855 drop:
76856 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76857- atomic_inc(&sk->sk_drops);
76858+ atomic_inc_unchecked(&sk->sk_drops);
76859 kfree_skb(skb);
76860 return -1;
76861 }
76862@@ -673,7 +677,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76863 if (likely(skb1 == NULL))
76864 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
76865 if (!skb1) {
76866- atomic_inc(&sk->sk_drops);
76867+ atomic_inc_unchecked(&sk->sk_drops);
76868 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
76869 IS_UDPLITE(sk));
76870 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76871@@ -844,6 +848,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76872 goto discard;
76873
76874 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
76875+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76876+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76877+#endif
76878 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
76879
76880 kfree_skb(skb);
76881@@ -1453,8 +1460,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
76882 0, 0L, 0,
76883 sock_i_uid(sp), 0,
76884 sock_i_ino(sp),
76885- atomic_read(&sp->sk_refcnt), sp,
76886- atomic_read(&sp->sk_drops));
76887+ atomic_read(&sp->sk_refcnt),
76888+#ifdef CONFIG_GRKERNSEC_HIDESYM
76889+ NULL,
76890+#else
76891+ sp,
76892+#endif
76893+ atomic_read_unchecked(&sp->sk_drops));
76894 }
76895
76896 int udp6_seq_show(struct seq_file *seq, void *v)
76897diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
76898index 6b9d5a0..4dffaf1 100644
76899--- a/net/irda/ircomm/ircomm_tty.c
76900+++ b/net/irda/ircomm/ircomm_tty.c
76901@@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76902 add_wait_queue(&self->open_wait, &wait);
76903
76904 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
76905- __FILE__,__LINE__, tty->driver->name, self->open_count );
76906+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76907
76908 /* As far as I can see, we protect open_count - Jean II */
76909 spin_lock_irqsave(&self->spinlock, flags);
76910 if (!tty_hung_up_p(filp)) {
76911 extra_count = 1;
76912- self->open_count--;
76913+ local_dec(&self->open_count);
76914 }
76915 spin_unlock_irqrestore(&self->spinlock, flags);
76916- self->blocked_open++;
76917+ local_inc(&self->blocked_open);
76918
76919 while (1) {
76920 if (tty->termios->c_cflag & CBAUD) {
76921@@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76922 }
76923
76924 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
76925- __FILE__,__LINE__, tty->driver->name, self->open_count );
76926+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76927
76928 schedule();
76929 }
76930@@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76931 if (extra_count) {
76932 /* ++ is not atomic, so this should be protected - Jean II */
76933 spin_lock_irqsave(&self->spinlock, flags);
76934- self->open_count++;
76935+ local_inc(&self->open_count);
76936 spin_unlock_irqrestore(&self->spinlock, flags);
76937 }
76938- self->blocked_open--;
76939+ local_dec(&self->blocked_open);
76940
76941 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
76942- __FILE__,__LINE__, tty->driver->name, self->open_count);
76943+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
76944
76945 if (!retval)
76946 self->flags |= ASYNC_NORMAL_ACTIVE;
76947@@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
76948 }
76949 /* ++ is not atomic, so this should be protected - Jean II */
76950 spin_lock_irqsave(&self->spinlock, flags);
76951- self->open_count++;
76952+ local_inc(&self->open_count);
76953
76954 tty->driver_data = self;
76955 self->tty = tty;
76956 spin_unlock_irqrestore(&self->spinlock, flags);
76957
76958 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
76959- self->line, self->open_count);
76960+ self->line, local_read(&self->open_count));
76961
76962 /* Not really used by us, but lets do it anyway */
76963 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
76964@@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76965 return;
76966 }
76967
76968- if ((tty->count == 1) && (self->open_count != 1)) {
76969+ if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
76970 /*
76971 * Uh, oh. tty->count is 1, which means that the tty
76972 * structure will be freed. state->count should always
76973@@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76974 */
76975 IRDA_DEBUG(0, "%s(), bad serial port count; "
76976 "tty->count is 1, state->count is %d\n", __func__ ,
76977- self->open_count);
76978- self->open_count = 1;
76979+ local_read(&self->open_count));
76980+ local_set(&self->open_count, 1);
76981 }
76982
76983- if (--self->open_count < 0) {
76984+ if (local_dec_return(&self->open_count) < 0) {
76985 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
76986- __func__, self->line, self->open_count);
76987- self->open_count = 0;
76988+ __func__, self->line, local_read(&self->open_count));
76989+ local_set(&self->open_count, 0);
76990 }
76991- if (self->open_count) {
76992+ if (local_read(&self->open_count)) {
76993 spin_unlock_irqrestore(&self->spinlock, flags);
76994
76995 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
76996@@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76997 tty->closing = 0;
76998 self->tty = NULL;
76999
77000- if (self->blocked_open) {
77001+ if (local_read(&self->blocked_open)) {
77002 if (self->close_delay)
77003 schedule_timeout_interruptible(self->close_delay);
77004 wake_up_interruptible(&self->open_wait);
77005@@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
77006 spin_lock_irqsave(&self->spinlock, flags);
77007 self->flags &= ~ASYNC_NORMAL_ACTIVE;
77008 self->tty = NULL;
77009- self->open_count = 0;
77010+ local_set(&self->open_count, 0);
77011 spin_unlock_irqrestore(&self->spinlock, flags);
77012
77013 wake_up_interruptible(&self->open_wait);
77014@@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
77015 seq_putc(m, '\n');
77016
77017 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
77018- seq_printf(m, "Open count: %d\n", self->open_count);
77019+ seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
77020 seq_printf(m, "Max data size: %d\n", self->max_data_size);
77021 seq_printf(m, "Max header size: %d\n", self->max_header_size);
77022
77023diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
77024index cd6f7a9..e63fe89 100644
77025--- a/net/iucv/af_iucv.c
77026+++ b/net/iucv/af_iucv.c
77027@@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
77028
77029 write_lock_bh(&iucv_sk_list.lock);
77030
77031- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
77032+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77033 while (__iucv_get_sock_by_name(name)) {
77034 sprintf(name, "%08x",
77035- atomic_inc_return(&iucv_sk_list.autobind_name));
77036+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77037 }
77038
77039 write_unlock_bh(&iucv_sk_list.lock);
77040diff --git a/net/key/af_key.c b/net/key/af_key.c
77041index 34e4185..8823368 100644
77042--- a/net/key/af_key.c
77043+++ b/net/key/af_key.c
77044@@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
77045 static u32 get_acqseq(void)
77046 {
77047 u32 res;
77048- static atomic_t acqseq;
77049+ static atomic_unchecked_t acqseq;
77050
77051 do {
77052- res = atomic_inc_return(&acqseq);
77053+ res = atomic_inc_return_unchecked(&acqseq);
77054 } while (!res);
77055 return res;
77056 }
77057diff --git a/net/l2tp/l2tp_ip6.c b/net/l2tp/l2tp_ip6.c
77058index 35e1e4b..9275471 100644
77059--- a/net/l2tp/l2tp_ip6.c
77060+++ b/net/l2tp/l2tp_ip6.c
77061@@ -410,6 +410,7 @@ static int l2tp_ip6_getname(struct socket *sock, struct sockaddr *uaddr,
77062 lsa->l2tp_family = AF_INET6;
77063 lsa->l2tp_flowinfo = 0;
77064 lsa->l2tp_scope_id = 0;
77065+ lsa->l2tp_unused = 0;
77066 if (peer) {
77067 if (!lsk->peer_conn_id)
77068 return -ENOTCONN;
77069diff --git a/net/llc/af_llc.c b/net/llc/af_llc.c
77070index fe5453c..a13c3e23 100644
77071--- a/net/llc/af_llc.c
77072+++ b/net/llc/af_llc.c
77073@@ -969,14 +969,13 @@ static int llc_ui_getname(struct socket *sock, struct sockaddr *uaddr,
77074 struct sockaddr_llc sllc;
77075 struct sock *sk = sock->sk;
77076 struct llc_sock *llc = llc_sk(sk);
77077- int rc = 0;
77078+ int rc = -EBADF;
77079
77080 memset(&sllc, 0, sizeof(sllc));
77081 lock_sock(sk);
77082 if (sock_flag(sk, SOCK_ZAPPED))
77083 goto out;
77084 *uaddrlen = sizeof(sllc);
77085- memset(uaddr, 0, *uaddrlen);
77086 if (peer) {
77087 rc = -ENOTCONN;
77088 if (sk->sk_state != TCP_ESTABLISHED)
77089diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
77090index 3f3cd50..d2cf249 100644
77091--- a/net/mac80211/ieee80211_i.h
77092+++ b/net/mac80211/ieee80211_i.h
77093@@ -28,6 +28,7 @@
77094 #include <net/ieee80211_radiotap.h>
77095 #include <net/cfg80211.h>
77096 #include <net/mac80211.h>
77097+#include <asm/local.h>
77098 #include "key.h"
77099 #include "sta_info.h"
77100
77101@@ -863,7 +864,7 @@ struct ieee80211_local {
77102 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
77103 spinlock_t queue_stop_reason_lock;
77104
77105- int open_count;
77106+ local_t open_count;
77107 int monitors, cooked_mntrs;
77108 /* number of interfaces with corresponding FIF_ flags */
77109 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
77110diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
77111index 8664111..1d6a065 100644
77112--- a/net/mac80211/iface.c
77113+++ b/net/mac80211/iface.c
77114@@ -328,7 +328,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77115 break;
77116 }
77117
77118- if (local->open_count == 0) {
77119+ if (local_read(&local->open_count) == 0) {
77120 res = drv_start(local);
77121 if (res)
77122 goto err_del_bss;
77123@@ -371,7 +371,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77124 break;
77125 }
77126
77127- if (local->monitors == 0 && local->open_count == 0) {
77128+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
77129 res = ieee80211_add_virtual_monitor(local);
77130 if (res)
77131 goto err_stop;
77132@@ -468,7 +468,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77133 mutex_unlock(&local->mtx);
77134
77135 if (coming_up)
77136- local->open_count++;
77137+ local_inc(&local->open_count);
77138
77139 if (hw_reconf_flags)
77140 ieee80211_hw_config(local, hw_reconf_flags);
77141@@ -481,7 +481,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77142 err_del_interface:
77143 drv_remove_interface(local, sdata);
77144 err_stop:
77145- if (!local->open_count)
77146+ if (!local_read(&local->open_count))
77147 drv_stop(local);
77148 err_del_bss:
77149 sdata->bss = NULL;
77150@@ -613,7 +613,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77151 }
77152
77153 if (going_down)
77154- local->open_count--;
77155+ local_dec(&local->open_count);
77156
77157 switch (sdata->vif.type) {
77158 case NL80211_IFTYPE_AP_VLAN:
77159@@ -685,7 +685,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77160
77161 ieee80211_recalc_ps(local, -1);
77162
77163- if (local->open_count == 0) {
77164+ if (local_read(&local->open_count) == 0) {
77165 if (local->ops->napi_poll)
77166 napi_disable(&local->napi);
77167 ieee80211_clear_tx_pending(local);
77168@@ -717,7 +717,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77169 }
77170 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
77171
77172- if (local->monitors == local->open_count && local->monitors > 0)
77173+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
77174 ieee80211_add_virtual_monitor(local);
77175 }
77176
77177diff --git a/net/mac80211/main.c b/net/mac80211/main.c
77178index f5548e9..474a15f 100644
77179--- a/net/mac80211/main.c
77180+++ b/net/mac80211/main.c
77181@@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
77182 local->hw.conf.power_level = power;
77183 }
77184
77185- if (changed && local->open_count) {
77186+ if (changed && local_read(&local->open_count)) {
77187 ret = drv_config(local, changed);
77188 /*
77189 * Goal:
77190diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
77191index af1c4e2..24dbbe3 100644
77192--- a/net/mac80211/pm.c
77193+++ b/net/mac80211/pm.c
77194@@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77195 struct ieee80211_sub_if_data *sdata;
77196 struct sta_info *sta;
77197
77198- if (!local->open_count)
77199+ if (!local_read(&local->open_count))
77200 goto suspend;
77201
77202 ieee80211_scan_cancel(local);
77203@@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77204 cancel_work_sync(&local->dynamic_ps_enable_work);
77205 del_timer_sync(&local->dynamic_ps_timer);
77206
77207- local->wowlan = wowlan && local->open_count;
77208+ local->wowlan = wowlan && local_read(&local->open_count);
77209 if (local->wowlan) {
77210 int err = drv_suspend(local, wowlan);
77211 if (err < 0) {
77212@@ -132,7 +132,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77213 drv_remove_interface(local, sdata);
77214
77215 /* stop hardware - this must stop RX */
77216- if (local->open_count)
77217+ if (local_read(&local->open_count))
77218 ieee80211_stop_device(local);
77219
77220 suspend:
77221diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
77222index 3313c11..bec9f17 100644
77223--- a/net/mac80211/rate.c
77224+++ b/net/mac80211/rate.c
77225@@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
77226
77227 ASSERT_RTNL();
77228
77229- if (local->open_count)
77230+ if (local_read(&local->open_count))
77231 return -EBUSY;
77232
77233 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
77234diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
77235index c97a065..ff61928 100644
77236--- a/net/mac80211/rc80211_pid_debugfs.c
77237+++ b/net/mac80211/rc80211_pid_debugfs.c
77238@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
77239
77240 spin_unlock_irqrestore(&events->lock, status);
77241
77242- if (copy_to_user(buf, pb, p))
77243+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
77244 return -EFAULT;
77245
77246 return p;
77247diff --git a/net/mac80211/util.c b/net/mac80211/util.c
77248index f564b5e..22fee47 100644
77249--- a/net/mac80211/util.c
77250+++ b/net/mac80211/util.c
77251@@ -1224,7 +1224,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
77252 }
77253 #endif
77254 /* everything else happens only if HW was up & running */
77255- if (!local->open_count)
77256+ if (!local_read(&local->open_count))
77257 goto wake_up;
77258
77259 /*
77260diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
77261index 209c1ed..39484dc 100644
77262--- a/net/netfilter/Kconfig
77263+++ b/net/netfilter/Kconfig
77264@@ -851,6 +851,16 @@ config NETFILTER_XT_MATCH_ESP
77265
77266 To compile it as a module, choose M here. If unsure, say N.
77267
77268+config NETFILTER_XT_MATCH_GRADM
77269+ tristate '"gradm" match support'
77270+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
77271+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
77272+ ---help---
77273+ The gradm match allows to match on grsecurity RBAC being enabled.
77274+ It is useful when iptables rules are applied early on bootup to
77275+ prevent connections to the machine (except from a trusted host)
77276+ while the RBAC system is disabled.
77277+
77278 config NETFILTER_XT_MATCH_HASHLIMIT
77279 tristate '"hashlimit" match support'
77280 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
77281diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
77282index 4e7960c..89e48d4 100644
77283--- a/net/netfilter/Makefile
77284+++ b/net/netfilter/Makefile
77285@@ -87,6 +87,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
77286 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
77287 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
77288 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
77289+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
77290 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
77291 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
77292 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
77293diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
77294index 1548df9..98ad9b4 100644
77295--- a/net/netfilter/ipvs/ip_vs_conn.c
77296+++ b/net/netfilter/ipvs/ip_vs_conn.c
77297@@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
77298 /* Increase the refcnt counter of the dest */
77299 atomic_inc(&dest->refcnt);
77300
77301- conn_flags = atomic_read(&dest->conn_flags);
77302+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
77303 if (cp->protocol != IPPROTO_UDP)
77304 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
77305 flags = cp->flags;
77306@@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
77307 atomic_set(&cp->refcnt, 1);
77308
77309 atomic_set(&cp->n_control, 0);
77310- atomic_set(&cp->in_pkts, 0);
77311+ atomic_set_unchecked(&cp->in_pkts, 0);
77312
77313 atomic_inc(&ipvs->conn_count);
77314 if (flags & IP_VS_CONN_F_NO_CPORT)
77315@@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
77316
77317 /* Don't drop the entry if its number of incoming packets is not
77318 located in [0, 8] */
77319- i = atomic_read(&cp->in_pkts);
77320+ i = atomic_read_unchecked(&cp->in_pkts);
77321 if (i > 8 || i < 0) return 0;
77322
77323 if (!todrop_rate[i]) return 0;
77324diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
77325index a54b018c..07e0120 100644
77326--- a/net/netfilter/ipvs/ip_vs_core.c
77327+++ b/net/netfilter/ipvs/ip_vs_core.c
77328@@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
77329 ret = cp->packet_xmit(skb, cp, pd->pp);
77330 /* do not touch skb anymore */
77331
77332- atomic_inc(&cp->in_pkts);
77333+ atomic_inc_unchecked(&cp->in_pkts);
77334 ip_vs_conn_put(cp);
77335 return ret;
77336 }
77337@@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
77338 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
77339 pkts = sysctl_sync_threshold(ipvs);
77340 else
77341- pkts = atomic_add_return(1, &cp->in_pkts);
77342+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77343
77344 if (ipvs->sync_state & IP_VS_STATE_MASTER)
77345 ip_vs_sync_conn(net, cp, pkts);
77346diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
77347index 84444dd..f91c066 100644
77348--- a/net/netfilter/ipvs/ip_vs_ctl.c
77349+++ b/net/netfilter/ipvs/ip_vs_ctl.c
77350@@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
77351 ip_vs_rs_hash(ipvs, dest);
77352 write_unlock_bh(&ipvs->rs_lock);
77353 }
77354- atomic_set(&dest->conn_flags, conn_flags);
77355+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
77356
77357 /* bind the service */
77358 if (!dest->svc) {
77359@@ -2074,7 +2074,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
77360 " %-7s %-6d %-10d %-10d\n",
77361 &dest->addr.in6,
77362 ntohs(dest->port),
77363- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77364+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77365 atomic_read(&dest->weight),
77366 atomic_read(&dest->activeconns),
77367 atomic_read(&dest->inactconns));
77368@@ -2085,7 +2085,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
77369 "%-7s %-6d %-10d %-10d\n",
77370 ntohl(dest->addr.ip),
77371 ntohs(dest->port),
77372- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77373+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77374 atomic_read(&dest->weight),
77375 atomic_read(&dest->activeconns),
77376 atomic_read(&dest->inactconns));
77377@@ -2555,7 +2555,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
77378
77379 entry.addr = dest->addr.ip;
77380 entry.port = dest->port;
77381- entry.conn_flags = atomic_read(&dest->conn_flags);
77382+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
77383 entry.weight = atomic_read(&dest->weight);
77384 entry.u_threshold = dest->u_threshold;
77385 entry.l_threshold = dest->l_threshold;
77386@@ -2759,6 +2759,7 @@ do_ip_vs_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77387 {
77388 struct ip_vs_timeout_user t;
77389
77390+ memset(&t, 0, sizeof(t));
77391 __ip_vs_get_timeouts(net, &t);
77392 if (copy_to_user(user, &t, sizeof(t)) != 0)
77393 ret = -EFAULT;
77394@@ -3089,7 +3090,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
77395 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
77396 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
77397 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
77398- (atomic_read(&dest->conn_flags) &
77399+ (atomic_read_unchecked(&dest->conn_flags) &
77400 IP_VS_CONN_F_FWD_MASK)) ||
77401 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
77402 atomic_read(&dest->weight)) ||
77403diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
77404index effa10c..9058928 100644
77405--- a/net/netfilter/ipvs/ip_vs_sync.c
77406+++ b/net/netfilter/ipvs/ip_vs_sync.c
77407@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
77408 cp = cp->control;
77409 if (cp) {
77410 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
77411- pkts = atomic_add_return(1, &cp->in_pkts);
77412+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77413 else
77414 pkts = sysctl_sync_threshold(ipvs);
77415 ip_vs_sync_conn(net, cp->control, pkts);
77416@@ -758,7 +758,7 @@ control:
77417 if (!cp)
77418 return;
77419 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
77420- pkts = atomic_add_return(1, &cp->in_pkts);
77421+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77422 else
77423 pkts = sysctl_sync_threshold(ipvs);
77424 goto sloop;
77425@@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
77426
77427 if (opt)
77428 memcpy(&cp->in_seq, opt, sizeof(*opt));
77429- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77430+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77431 cp->state = state;
77432 cp->old_state = cp->state;
77433 /*
77434diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
77435index 7fd66de..e6fb361 100644
77436--- a/net/netfilter/ipvs/ip_vs_xmit.c
77437+++ b/net/netfilter/ipvs/ip_vs_xmit.c
77438@@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
77439 else
77440 rc = NF_ACCEPT;
77441 /* do not touch skb anymore */
77442- atomic_inc(&cp->in_pkts);
77443+ atomic_inc_unchecked(&cp->in_pkts);
77444 goto out;
77445 }
77446
77447@@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
77448 else
77449 rc = NF_ACCEPT;
77450 /* do not touch skb anymore */
77451- atomic_inc(&cp->in_pkts);
77452+ atomic_inc_unchecked(&cp->in_pkts);
77453 goto out;
77454 }
77455
77456diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
77457index ac3af97..c134c21 100644
77458--- a/net/netfilter/nf_conntrack_core.c
77459+++ b/net/netfilter/nf_conntrack_core.c
77460@@ -1530,6 +1530,10 @@ err_proto:
77461 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
77462 #define DYING_NULLS_VAL ((1<<30)+1)
77463
77464+#ifdef CONFIG_GRKERNSEC_HIDESYM
77465+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
77466+#endif
77467+
77468 static int nf_conntrack_init_net(struct net *net)
77469 {
77470 int ret;
77471@@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
77472 goto err_stat;
77473 }
77474
77475+#ifdef CONFIG_GRKERNSEC_HIDESYM
77476+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
77477+#else
77478 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
77479+#endif
77480 if (!net->ct.slabname) {
77481 ret = -ENOMEM;
77482 goto err_slabname;
77483diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
77484index 3c3cfc0..7a6ea1a 100644
77485--- a/net/netfilter/nfnetlink_log.c
77486+++ b/net/netfilter/nfnetlink_log.c
77487@@ -70,7 +70,7 @@ struct nfulnl_instance {
77488 };
77489
77490 static DEFINE_SPINLOCK(instances_lock);
77491-static atomic_t global_seq;
77492+static atomic_unchecked_t global_seq;
77493
77494 #define INSTANCE_BUCKETS 16
77495 static struct hlist_head instance_table[INSTANCE_BUCKETS];
77496@@ -517,7 +517,7 @@ __build_packet_message(struct nfulnl_instance *inst,
77497 /* global sequence number */
77498 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
77499 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
77500- htonl(atomic_inc_return(&global_seq))))
77501+ htonl(atomic_inc_return_unchecked(&global_seq))))
77502 goto nla_put_failure;
77503
77504 if (data_len) {
77505diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
77506new file mode 100644
77507index 0000000..6905327
77508--- /dev/null
77509+++ b/net/netfilter/xt_gradm.c
77510@@ -0,0 +1,51 @@
77511+/*
77512+ * gradm match for netfilter
77513