]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.5.2-201208241943.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.5.2-201208241943.patch
CommitLineData
49af106a
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..f33c779 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,42 @@ 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+#ifdef CONFIG_PAX_RANDKSTACK
8691+ pax_erase_kstack
8692+#endif
8693+
8694+ /*
8695+ * No need to follow this irqs on/off section: the syscall
8696+ * disabled irqs, here we enable it straight after entry:
8697+ */
8698+ ENABLE_INTERRUPTS(CLBR_NONE)
8699 /* no need to do an access_ok check here because rbp has been
8700 32bit zero extended */
8701+
8702+#ifdef CONFIG_PAX_MEMORY_UDEREF
8703+ mov $PAX_USER_SHADOW_BASE,%r11
8704+ add %r11,%rbp
8705+#endif
8706+
8707 1: movl (%rbp),%ebp
8708 _ASM_EXTABLE(1b,ia32_badarg)
8709- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8710- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8711+ GET_THREAD_INFO(%r11)
8712+ orl $TS_COMPAT,TI_status(%r11)
8713+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8714 CFI_REMEMBER_STATE
8715 jnz sysenter_tracesys
8716 cmpq $(IA32_NR_syscalls-1),%rax
8717@@ -159,12 +201,15 @@ sysenter_do_call:
8718 sysenter_dispatch:
8719 call *ia32_sys_call_table(,%rax,8)
8720 movq %rax,RAX-ARGOFFSET(%rsp)
8721+ GET_THREAD_INFO(%r11)
8722 DISABLE_INTERRUPTS(CLBR_NONE)
8723 TRACE_IRQS_OFF
8724- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8725+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8726 jnz sysexit_audit
8727 sysexit_from_sys_call:
8728- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8729+ pax_exit_kernel_user
8730+ pax_erase_kstack
8731+ andl $~TS_COMPAT,TI_status(%r11)
8732 /* clear IF, that popfq doesn't enable interrupts early */
8733 andl $~0x200,EFLAGS-R11(%rsp)
8734 movl RIP-R11(%rsp),%edx /* User %eip */
8735@@ -190,6 +235,9 @@ sysexit_from_sys_call:
8736 movl %eax,%esi /* 2nd arg: syscall number */
8737 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8738 call __audit_syscall_entry
8739+
8740+ pax_erase_kstack
8741+
8742 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8743 cmpq $(IA32_NR_syscalls-1),%rax
8744 ja ia32_badsys
8745@@ -201,7 +249,7 @@ sysexit_from_sys_call:
8746 .endm
8747
8748 .macro auditsys_exit exit
8749- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8750+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8751 jnz ia32_ret_from_sys_call
8752 TRACE_IRQS_ON
8753 sti
8754@@ -212,11 +260,12 @@ sysexit_from_sys_call:
8755 1: setbe %al /* 1 if error, 0 if not */
8756 movzbl %al,%edi /* zero-extend that into %edi */
8757 call __audit_syscall_exit
8758+ GET_THREAD_INFO(%r11)
8759 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8760 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8761 cli
8762 TRACE_IRQS_OFF
8763- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8764+ testl %edi,TI_flags(%r11)
8765 jz \exit
8766 CLEAR_RREGS -ARGOFFSET
8767 jmp int_with_check
8768@@ -234,7 +283,7 @@ sysexit_audit:
8769
8770 sysenter_tracesys:
8771 #ifdef CONFIG_AUDITSYSCALL
8772- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8773+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8774 jz sysenter_auditsys
8775 #endif
8776 SAVE_REST
8777@@ -246,6 +295,9 @@ sysenter_tracesys:
8778 RESTORE_REST
8779 cmpq $(IA32_NR_syscalls-1),%rax
8780 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
8781+
8782+ pax_erase_kstack
8783+
8784 jmp sysenter_do_call
8785 CFI_ENDPROC
8786 ENDPROC(ia32_sysenter_target)
8787@@ -273,19 +325,25 @@ ENDPROC(ia32_sysenter_target)
8788 ENTRY(ia32_cstar_target)
8789 CFI_STARTPROC32 simple
8790 CFI_SIGNAL_FRAME
8791- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8792+ CFI_DEF_CFA rsp,0
8793 CFI_REGISTER rip,rcx
8794 /*CFI_REGISTER rflags,r11*/
8795 SWAPGS_UNSAFE_STACK
8796 movl %esp,%r8d
8797 CFI_REGISTER rsp,r8
8798 movq PER_CPU_VAR(kernel_stack),%rsp
8799+ SAVE_ARGS 8*6,0,0
8800+ pax_enter_kernel_user
8801+
8802+#ifdef CONFIG_PAX_RANDKSTACK
8803+ pax_erase_kstack
8804+#endif
8805+
8806 /*
8807 * No need to follow this irqs on/off section: the syscall
8808 * disabled irqs and here we enable it straight after entry:
8809 */
8810 ENABLE_INTERRUPTS(CLBR_NONE)
8811- SAVE_ARGS 8,0,0
8812 movl %eax,%eax /* zero extension */
8813 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8814 movq %rcx,RIP-ARGOFFSET(%rsp)
8815@@ -301,10 +359,17 @@ ENTRY(ia32_cstar_target)
8816 /* no need to do an access_ok check here because r8 has been
8817 32bit zero extended */
8818 /* hardware stack frame is complete now */
8819+
8820+#ifdef CONFIG_PAX_MEMORY_UDEREF
8821+ mov $PAX_USER_SHADOW_BASE,%r11
8822+ add %r11,%r8
8823+#endif
8824+
8825 1: movl (%r8),%r9d
8826 _ASM_EXTABLE(1b,ia32_badarg)
8827- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8828- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8829+ GET_THREAD_INFO(%r11)
8830+ orl $TS_COMPAT,TI_status(%r11)
8831+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8832 CFI_REMEMBER_STATE
8833 jnz cstar_tracesys
8834 cmpq $IA32_NR_syscalls-1,%rax
8835@@ -314,12 +379,15 @@ cstar_do_call:
8836 cstar_dispatch:
8837 call *ia32_sys_call_table(,%rax,8)
8838 movq %rax,RAX-ARGOFFSET(%rsp)
8839+ GET_THREAD_INFO(%r11)
8840 DISABLE_INTERRUPTS(CLBR_NONE)
8841 TRACE_IRQS_OFF
8842- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8843+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8844 jnz sysretl_audit
8845 sysretl_from_sys_call:
8846- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8847+ pax_exit_kernel_user
8848+ pax_erase_kstack
8849+ andl $~TS_COMPAT,TI_status(%r11)
8850 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8851 movl RIP-ARGOFFSET(%rsp),%ecx
8852 CFI_REGISTER rip,rcx
8853@@ -347,7 +415,7 @@ sysretl_audit:
8854
8855 cstar_tracesys:
8856 #ifdef CONFIG_AUDITSYSCALL
8857- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8858+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8859 jz cstar_auditsys
8860 #endif
8861 xchgl %r9d,%ebp
8862@@ -361,6 +429,9 @@ cstar_tracesys:
8863 xchgl %ebp,%r9d
8864 cmpq $(IA32_NR_syscalls-1),%rax
8865 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
8866+
8867+ pax_erase_kstack
8868+
8869 jmp cstar_do_call
8870 END(ia32_cstar_target)
8871
8872@@ -401,19 +472,26 @@ ENTRY(ia32_syscall)
8873 CFI_REL_OFFSET rip,RIP-RIP
8874 PARAVIRT_ADJUST_EXCEPTION_FRAME
8875 SWAPGS
8876- /*
8877- * No need to follow this irqs on/off section: the syscall
8878- * disabled irqs and here we enable it straight after entry:
8879- */
8880- ENABLE_INTERRUPTS(CLBR_NONE)
8881 movl %eax,%eax
8882 pushq_cfi %rax
8883 cld
8884 /* note the registers are not zero extended to the sf.
8885 this could be a problem. */
8886 SAVE_ARGS 0,1,0
8887- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8888- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8889+ pax_enter_kernel_user
8890+
8891+#ifdef CONFIG_PAX_RANDKSTACK
8892+ pax_erase_kstack
8893+#endif
8894+
8895+ /*
8896+ * No need to follow this irqs on/off section: the syscall
8897+ * disabled irqs and here we enable it straight after entry:
8898+ */
8899+ ENABLE_INTERRUPTS(CLBR_NONE)
8900+ GET_THREAD_INFO(%r11)
8901+ orl $TS_COMPAT,TI_status(%r11)
8902+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8903 jnz ia32_tracesys
8904 cmpq $(IA32_NR_syscalls-1),%rax
8905 ja ia32_badsys
8906@@ -436,6 +514,9 @@ ia32_tracesys:
8907 RESTORE_REST
8908 cmpq $(IA32_NR_syscalls-1),%rax
8909 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
8910+
8911+ pax_erase_kstack
8912+
8913 jmp ia32_do_call
8914 END(ia32_syscall)
8915
8916diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8917index 4540bec..714d913 100644
8918--- a/arch/x86/ia32/sys_ia32.c
8919+++ b/arch/x86/ia32/sys_ia32.c
8920@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8921 */
8922 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8923 {
8924- typeof(ubuf->st_uid) uid = 0;
8925- typeof(ubuf->st_gid) gid = 0;
8926+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
8927+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
8928 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
8929 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
8930 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8931@@ -287,7 +287,7 @@ asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 __user *act,
8932 return ret;
8933 }
8934
8935-asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
8936+asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
8937 int options)
8938 {
8939 return compat_sys_wait4(pid, stat_addr, options, NULL);
8940@@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8941 mm_segment_t old_fs = get_fs();
8942
8943 set_fs(KERNEL_DS);
8944- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
8945+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
8946 set_fs(old_fs);
8947 if (put_compat_timespec(&t, interval))
8948 return -EFAULT;
8949@@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
8950 mm_segment_t old_fs = get_fs();
8951
8952 set_fs(KERNEL_DS);
8953- ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
8954+ ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
8955 set_fs(old_fs);
8956 if (!ret) {
8957 switch (_NSIG_WORDS) {
8958@@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
8959 if (copy_siginfo_from_user32(&info, uinfo))
8960 return -EFAULT;
8961 set_fs(KERNEL_DS);
8962- ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
8963+ ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
8964 set_fs(old_fs);
8965 return ret;
8966 }
8967@@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
8968 return -EFAULT;
8969
8970 set_fs(KERNEL_DS);
8971- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
8972+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
8973 count);
8974 set_fs(old_fs);
8975
8976diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
8977index 952bd01..7692c6f 100644
8978--- a/arch/x86/include/asm/alternative-asm.h
8979+++ b/arch/x86/include/asm/alternative-asm.h
8980@@ -15,6 +15,45 @@
8981 .endm
8982 #endif
8983
8984+#ifdef KERNEXEC_PLUGIN
8985+ .macro pax_force_retaddr_bts rip=0
8986+ btsq $63,\rip(%rsp)
8987+ .endm
8988+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
8989+ .macro pax_force_retaddr rip=0, reload=0
8990+ btsq $63,\rip(%rsp)
8991+ .endm
8992+ .macro pax_force_fptr ptr
8993+ btsq $63,\ptr
8994+ .endm
8995+ .macro pax_set_fptr_mask
8996+ .endm
8997+#endif
8998+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
8999+ .macro pax_force_retaddr rip=0, reload=0
9000+ .if \reload
9001+ pax_set_fptr_mask
9002+ .endif
9003+ orq %r10,\rip(%rsp)
9004+ .endm
9005+ .macro pax_force_fptr ptr
9006+ orq %r10,\ptr
9007+ .endm
9008+ .macro pax_set_fptr_mask
9009+ movabs $0x8000000000000000,%r10
9010+ .endm
9011+#endif
9012+#else
9013+ .macro pax_force_retaddr rip=0, reload=0
9014+ .endm
9015+ .macro pax_force_fptr ptr
9016+ .endm
9017+ .macro pax_force_retaddr_bts rip=0
9018+ .endm
9019+ .macro pax_set_fptr_mask
9020+ .endm
9021+#endif
9022+
9023 .macro altinstruction_entry orig alt feature orig_len alt_len
9024 .long \orig - .
9025 .long \alt - .
9026diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9027index 49331be..9706065 100644
9028--- a/arch/x86/include/asm/alternative.h
9029+++ b/arch/x86/include/asm/alternative.h
9030@@ -89,7 +89,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9031 ".section .discard,\"aw\",@progbits\n" \
9032 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
9033 ".previous\n" \
9034- ".section .altinstr_replacement, \"ax\"\n" \
9035+ ".section .altinstr_replacement, \"a\"\n" \
9036 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
9037 ".previous"
9038
9039diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9040index eaff479..3025a63 100644
9041--- a/arch/x86/include/asm/apic.h
9042+++ b/arch/x86/include/asm/apic.h
9043@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9044
9045 #ifdef CONFIG_X86_LOCAL_APIC
9046
9047-extern unsigned int apic_verbosity;
9048+extern int apic_verbosity;
9049 extern int local_apic_timer_c2_ok;
9050
9051 extern int disable_apic;
9052diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9053index 20370c6..a2eb9b0 100644
9054--- a/arch/x86/include/asm/apm.h
9055+++ b/arch/x86/include/asm/apm.h
9056@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9057 __asm__ __volatile__(APM_DO_ZERO_SEGS
9058 "pushl %%edi\n\t"
9059 "pushl %%ebp\n\t"
9060- "lcall *%%cs:apm_bios_entry\n\t"
9061+ "lcall *%%ss:apm_bios_entry\n\t"
9062 "setc %%al\n\t"
9063 "popl %%ebp\n\t"
9064 "popl %%edi\n\t"
9065@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9066 __asm__ __volatile__(APM_DO_ZERO_SEGS
9067 "pushl %%edi\n\t"
9068 "pushl %%ebp\n\t"
9069- "lcall *%%cs:apm_bios_entry\n\t"
9070+ "lcall *%%ss:apm_bios_entry\n\t"
9071 "setc %%bl\n\t"
9072 "popl %%ebp\n\t"
9073 "popl %%edi\n\t"
9074diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9075index 58cb6d4..a4b806c 100644
9076--- a/arch/x86/include/asm/atomic.h
9077+++ b/arch/x86/include/asm/atomic.h
9078@@ -22,7 +22,18 @@
9079 */
9080 static inline int atomic_read(const atomic_t *v)
9081 {
9082- return (*(volatile int *)&(v)->counter);
9083+ return (*(volatile const int *)&(v)->counter);
9084+}
9085+
9086+/**
9087+ * atomic_read_unchecked - read atomic variable
9088+ * @v: pointer of type atomic_unchecked_t
9089+ *
9090+ * Atomically reads the value of @v.
9091+ */
9092+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9093+{
9094+ return (*(volatile const int *)&(v)->counter);
9095 }
9096
9097 /**
9098@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9099 }
9100
9101 /**
9102+ * atomic_set_unchecked - set atomic variable
9103+ * @v: pointer of type atomic_unchecked_t
9104+ * @i: required value
9105+ *
9106+ * Atomically sets the value of @v to @i.
9107+ */
9108+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9109+{
9110+ v->counter = i;
9111+}
9112+
9113+/**
9114 * atomic_add - add integer to atomic variable
9115 * @i: integer value to add
9116 * @v: pointer of type atomic_t
9117@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9118 */
9119 static inline void atomic_add(int i, atomic_t *v)
9120 {
9121- asm volatile(LOCK_PREFIX "addl %1,%0"
9122+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
9123+
9124+#ifdef CONFIG_PAX_REFCOUNT
9125+ "jno 0f\n"
9126+ LOCK_PREFIX "subl %1,%0\n"
9127+ "int $4\n0:\n"
9128+ _ASM_EXTABLE(0b, 0b)
9129+#endif
9130+
9131+ : "+m" (v->counter)
9132+ : "ir" (i));
9133+}
9134+
9135+/**
9136+ * atomic_add_unchecked - add integer to atomic variable
9137+ * @i: integer value to add
9138+ * @v: pointer of type atomic_unchecked_t
9139+ *
9140+ * Atomically adds @i to @v.
9141+ */
9142+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9143+{
9144+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
9145 : "+m" (v->counter)
9146 : "ir" (i));
9147 }
9148@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9149 */
9150 static inline void atomic_sub(int i, atomic_t *v)
9151 {
9152- asm volatile(LOCK_PREFIX "subl %1,%0"
9153+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
9154+
9155+#ifdef CONFIG_PAX_REFCOUNT
9156+ "jno 0f\n"
9157+ LOCK_PREFIX "addl %1,%0\n"
9158+ "int $4\n0:\n"
9159+ _ASM_EXTABLE(0b, 0b)
9160+#endif
9161+
9162+ : "+m" (v->counter)
9163+ : "ir" (i));
9164+}
9165+
9166+/**
9167+ * atomic_sub_unchecked - subtract integer from atomic variable
9168+ * @i: integer value to subtract
9169+ * @v: pointer of type atomic_unchecked_t
9170+ *
9171+ * Atomically subtracts @i from @v.
9172+ */
9173+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9174+{
9175+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
9176 : "+m" (v->counter)
9177 : "ir" (i));
9178 }
9179@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9180 {
9181 unsigned char c;
9182
9183- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9184+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
9185+
9186+#ifdef CONFIG_PAX_REFCOUNT
9187+ "jno 0f\n"
9188+ LOCK_PREFIX "addl %2,%0\n"
9189+ "int $4\n0:\n"
9190+ _ASM_EXTABLE(0b, 0b)
9191+#endif
9192+
9193+ "sete %1\n"
9194 : "+m" (v->counter), "=qm" (c)
9195 : "ir" (i) : "memory");
9196 return c;
9197@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9198 */
9199 static inline void atomic_inc(atomic_t *v)
9200 {
9201- asm volatile(LOCK_PREFIX "incl %0"
9202+ asm volatile(LOCK_PREFIX "incl %0\n"
9203+
9204+#ifdef CONFIG_PAX_REFCOUNT
9205+ "jno 0f\n"
9206+ LOCK_PREFIX "decl %0\n"
9207+ "int $4\n0:\n"
9208+ _ASM_EXTABLE(0b, 0b)
9209+#endif
9210+
9211+ : "+m" (v->counter));
9212+}
9213+
9214+/**
9215+ * atomic_inc_unchecked - increment atomic variable
9216+ * @v: pointer of type atomic_unchecked_t
9217+ *
9218+ * Atomically increments @v by 1.
9219+ */
9220+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9221+{
9222+ asm volatile(LOCK_PREFIX "incl %0\n"
9223 : "+m" (v->counter));
9224 }
9225
9226@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9227 */
9228 static inline void atomic_dec(atomic_t *v)
9229 {
9230- asm volatile(LOCK_PREFIX "decl %0"
9231+ asm volatile(LOCK_PREFIX "decl %0\n"
9232+
9233+#ifdef CONFIG_PAX_REFCOUNT
9234+ "jno 0f\n"
9235+ LOCK_PREFIX "incl %0\n"
9236+ "int $4\n0:\n"
9237+ _ASM_EXTABLE(0b, 0b)
9238+#endif
9239+
9240+ : "+m" (v->counter));
9241+}
9242+
9243+/**
9244+ * atomic_dec_unchecked - decrement atomic variable
9245+ * @v: pointer of type atomic_unchecked_t
9246+ *
9247+ * Atomically decrements @v by 1.
9248+ */
9249+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9250+{
9251+ asm volatile(LOCK_PREFIX "decl %0\n"
9252 : "+m" (v->counter));
9253 }
9254
9255@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9256 {
9257 unsigned char c;
9258
9259- asm volatile(LOCK_PREFIX "decl %0; sete %1"
9260+ asm volatile(LOCK_PREFIX "decl %0\n"
9261+
9262+#ifdef CONFIG_PAX_REFCOUNT
9263+ "jno 0f\n"
9264+ LOCK_PREFIX "incl %0\n"
9265+ "int $4\n0:\n"
9266+ _ASM_EXTABLE(0b, 0b)
9267+#endif
9268+
9269+ "sete %1\n"
9270 : "+m" (v->counter), "=qm" (c)
9271 : : "memory");
9272 return c != 0;
9273@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9274 {
9275 unsigned char c;
9276
9277- asm volatile(LOCK_PREFIX "incl %0; sete %1"
9278+ asm volatile(LOCK_PREFIX "incl %0\n"
9279+
9280+#ifdef CONFIG_PAX_REFCOUNT
9281+ "jno 0f\n"
9282+ LOCK_PREFIX "decl %0\n"
9283+ "int $4\n0:\n"
9284+ _ASM_EXTABLE(0b, 0b)
9285+#endif
9286+
9287+ "sete %1\n"
9288+ : "+m" (v->counter), "=qm" (c)
9289+ : : "memory");
9290+ return c != 0;
9291+}
9292+
9293+/**
9294+ * atomic_inc_and_test_unchecked - increment and test
9295+ * @v: pointer of type atomic_unchecked_t
9296+ *
9297+ * Atomically increments @v by 1
9298+ * and returns true if the result is zero, or false for all
9299+ * other cases.
9300+ */
9301+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9302+{
9303+ unsigned char c;
9304+
9305+ asm volatile(LOCK_PREFIX "incl %0\n"
9306+ "sete %1\n"
9307 : "+m" (v->counter), "=qm" (c)
9308 : : "memory");
9309 return c != 0;
9310@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9311 {
9312 unsigned char c;
9313
9314- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9315+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
9316+
9317+#ifdef CONFIG_PAX_REFCOUNT
9318+ "jno 0f\n"
9319+ LOCK_PREFIX "subl %2,%0\n"
9320+ "int $4\n0:\n"
9321+ _ASM_EXTABLE(0b, 0b)
9322+#endif
9323+
9324+ "sets %1\n"
9325 : "+m" (v->counter), "=qm" (c)
9326 : "ir" (i) : "memory");
9327 return c;
9328@@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9329 goto no_xadd;
9330 #endif
9331 /* Modern 486+ processor */
9332- return i + xadd(&v->counter, i);
9333+ return i + xadd_check_overflow(&v->counter, i);
9334
9335 #ifdef CONFIG_M386
9336 no_xadd: /* Legacy 386 processor */
9337@@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9338 }
9339
9340 /**
9341+ * atomic_add_return_unchecked - add integer and return
9342+ * @i: integer value to add
9343+ * @v: pointer of type atomic_unchecked_t
9344+ *
9345+ * Atomically adds @i to @v and returns @i + @v
9346+ */
9347+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9348+{
9349+#ifdef CONFIG_M386
9350+ int __i;
9351+ unsigned long flags;
9352+ if (unlikely(boot_cpu_data.x86 <= 3))
9353+ goto no_xadd;
9354+#endif
9355+ /* Modern 486+ processor */
9356+ return i + xadd(&v->counter, i);
9357+
9358+#ifdef CONFIG_M386
9359+no_xadd: /* Legacy 386 processor */
9360+ raw_local_irq_save(flags);
9361+ __i = atomic_read_unchecked(v);
9362+ atomic_set_unchecked(v, i + __i);
9363+ raw_local_irq_restore(flags);
9364+ return i + __i;
9365+#endif
9366+}
9367+
9368+/**
9369 * atomic_sub_return - subtract integer and return
9370 * @v: pointer of type atomic_t
9371 * @i: integer value to subtract
9372@@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9373 }
9374
9375 #define atomic_inc_return(v) (atomic_add_return(1, v))
9376+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9377+{
9378+ return atomic_add_return_unchecked(1, v);
9379+}
9380 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9381
9382 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9383@@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9384 return cmpxchg(&v->counter, old, new);
9385 }
9386
9387+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9388+{
9389+ return cmpxchg(&v->counter, old, new);
9390+}
9391+
9392 static inline int atomic_xchg(atomic_t *v, int new)
9393 {
9394 return xchg(&v->counter, new);
9395 }
9396
9397+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9398+{
9399+ return xchg(&v->counter, new);
9400+}
9401+
9402 /**
9403 * __atomic_add_unless - add unless the number is already a given value
9404 * @v: pointer of type atomic_t
9405@@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9406 */
9407 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9408 {
9409- int c, old;
9410+ int c, old, new;
9411 c = atomic_read(v);
9412 for (;;) {
9413- if (unlikely(c == (u)))
9414+ if (unlikely(c == u))
9415 break;
9416- old = atomic_cmpxchg((v), c, c + (a));
9417+
9418+ asm volatile("addl %2,%0\n"
9419+
9420+#ifdef CONFIG_PAX_REFCOUNT
9421+ "jno 0f\n"
9422+ "subl %2,%0\n"
9423+ "int $4\n0:\n"
9424+ _ASM_EXTABLE(0b, 0b)
9425+#endif
9426+
9427+ : "=r" (new)
9428+ : "0" (c), "ir" (a));
9429+
9430+ old = atomic_cmpxchg(v, c, new);
9431 if (likely(old == c))
9432 break;
9433 c = old;
9434@@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9435 return c;
9436 }
9437
9438+/**
9439+ * atomic_inc_not_zero_hint - increment if not null
9440+ * @v: pointer of type atomic_t
9441+ * @hint: probable value of the atomic before the increment
9442+ *
9443+ * This version of atomic_inc_not_zero() gives a hint of probable
9444+ * value of the atomic. This helps processor to not read the memory
9445+ * before doing the atomic read/modify/write cycle, lowering
9446+ * number of bus transactions on some arches.
9447+ *
9448+ * Returns: 0 if increment was not done, 1 otherwise.
9449+ */
9450+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9451+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9452+{
9453+ int val, c = hint, new;
9454+
9455+ /* sanity test, should be removed by compiler if hint is a constant */
9456+ if (!hint)
9457+ return __atomic_add_unless(v, 1, 0);
9458+
9459+ do {
9460+ asm volatile("incl %0\n"
9461+
9462+#ifdef CONFIG_PAX_REFCOUNT
9463+ "jno 0f\n"
9464+ "decl %0\n"
9465+ "int $4\n0:\n"
9466+ _ASM_EXTABLE(0b, 0b)
9467+#endif
9468+
9469+ : "=r" (new)
9470+ : "0" (c));
9471+
9472+ val = atomic_cmpxchg(v, c, new);
9473+ if (val == c)
9474+ return 1;
9475+ c = val;
9476+ } while (c);
9477+
9478+ return 0;
9479+}
9480
9481 /*
9482 * atomic_dec_if_positive - decrement by 1 if old value positive
9483@@ -293,14 +552,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
9484 #endif
9485
9486 /* These are x86-specific, used by some header files */
9487-#define atomic_clear_mask(mask, addr) \
9488- asm volatile(LOCK_PREFIX "andl %0,%1" \
9489- : : "r" (~(mask)), "m" (*(addr)) : "memory")
9490+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
9491+{
9492+ asm volatile(LOCK_PREFIX "andl %1,%0"
9493+ : "+m" (v->counter)
9494+ : "r" (~(mask))
9495+ : "memory");
9496+}
9497
9498-#define atomic_set_mask(mask, addr) \
9499- asm volatile(LOCK_PREFIX "orl %0,%1" \
9500- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
9501- : "memory")
9502+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9503+{
9504+ asm volatile(LOCK_PREFIX "andl %1,%0"
9505+ : "+m" (v->counter)
9506+ : "r" (~(mask))
9507+ : "memory");
9508+}
9509+
9510+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
9511+{
9512+ asm volatile(LOCK_PREFIX "orl %1,%0"
9513+ : "+m" (v->counter)
9514+ : "r" (mask)
9515+ : "memory");
9516+}
9517+
9518+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9519+{
9520+ asm volatile(LOCK_PREFIX "orl %1,%0"
9521+ : "+m" (v->counter)
9522+ : "r" (mask)
9523+ : "memory");
9524+}
9525
9526 /* Atomic operations are already serializing on x86 */
9527 #define smp_mb__before_atomic_dec() barrier()
9528diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9529index b154de7..aadebd8 100644
9530--- a/arch/x86/include/asm/atomic64_32.h
9531+++ b/arch/x86/include/asm/atomic64_32.h
9532@@ -12,6 +12,14 @@ typedef struct {
9533 u64 __aligned(8) counter;
9534 } atomic64_t;
9535
9536+#ifdef CONFIG_PAX_REFCOUNT
9537+typedef struct {
9538+ u64 __aligned(8) counter;
9539+} atomic64_unchecked_t;
9540+#else
9541+typedef atomic64_t atomic64_unchecked_t;
9542+#endif
9543+
9544 #define ATOMIC64_INIT(val) { (val) }
9545
9546 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
9547@@ -37,21 +45,31 @@ typedef struct {
9548 ATOMIC64_DECL_ONE(sym##_386)
9549
9550 ATOMIC64_DECL_ONE(add_386);
9551+ATOMIC64_DECL_ONE(add_unchecked_386);
9552 ATOMIC64_DECL_ONE(sub_386);
9553+ATOMIC64_DECL_ONE(sub_unchecked_386);
9554 ATOMIC64_DECL_ONE(inc_386);
9555+ATOMIC64_DECL_ONE(inc_unchecked_386);
9556 ATOMIC64_DECL_ONE(dec_386);
9557+ATOMIC64_DECL_ONE(dec_unchecked_386);
9558 #endif
9559
9560 #define alternative_atomic64(f, out, in...) \
9561 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
9562
9563 ATOMIC64_DECL(read);
9564+ATOMIC64_DECL(read_unchecked);
9565 ATOMIC64_DECL(set);
9566+ATOMIC64_DECL(set_unchecked);
9567 ATOMIC64_DECL(xchg);
9568 ATOMIC64_DECL(add_return);
9569+ATOMIC64_DECL(add_return_unchecked);
9570 ATOMIC64_DECL(sub_return);
9571+ATOMIC64_DECL(sub_return_unchecked);
9572 ATOMIC64_DECL(inc_return);
9573+ATOMIC64_DECL(inc_return_unchecked);
9574 ATOMIC64_DECL(dec_return);
9575+ATOMIC64_DECL(dec_return_unchecked);
9576 ATOMIC64_DECL(dec_if_positive);
9577 ATOMIC64_DECL(inc_not_zero);
9578 ATOMIC64_DECL(add_unless);
9579@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9580 }
9581
9582 /**
9583+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9584+ * @p: pointer to type atomic64_unchecked_t
9585+ * @o: expected value
9586+ * @n: new value
9587+ *
9588+ * Atomically sets @v to @n if it was equal to @o and returns
9589+ * the old value.
9590+ */
9591+
9592+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9593+{
9594+ return cmpxchg64(&v->counter, o, n);
9595+}
9596+
9597+/**
9598 * atomic64_xchg - xchg atomic64 variable
9599 * @v: pointer to type atomic64_t
9600 * @n: value to assign
9601@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9602 }
9603
9604 /**
9605+ * atomic64_set_unchecked - set atomic64 variable
9606+ * @v: pointer to type atomic64_unchecked_t
9607+ * @n: value to assign
9608+ *
9609+ * Atomically sets the value of @v to @n.
9610+ */
9611+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9612+{
9613+ unsigned high = (unsigned)(i >> 32);
9614+ unsigned low = (unsigned)i;
9615+ alternative_atomic64(set, /* no output */,
9616+ "S" (v), "b" (low), "c" (high)
9617+ : "eax", "edx", "memory");
9618+}
9619+
9620+/**
9621 * atomic64_read - read atomic64 variable
9622 * @v: pointer to type atomic64_t
9623 *
9624@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
9625 }
9626
9627 /**
9628+ * atomic64_read_unchecked - read atomic64 variable
9629+ * @v: pointer to type atomic64_unchecked_t
9630+ *
9631+ * Atomically reads the value of @v and returns it.
9632+ */
9633+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9634+{
9635+ long long r;
9636+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
9637+ return r;
9638+ }
9639+
9640+/**
9641 * atomic64_add_return - add and return
9642 * @i: integer value to add
9643 * @v: pointer to type atomic64_t
9644@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9645 return i;
9646 }
9647
9648+/**
9649+ * atomic64_add_return_unchecked - add and return
9650+ * @i: integer value to add
9651+ * @v: pointer to type atomic64_unchecked_t
9652+ *
9653+ * Atomically adds @i to @v and returns @i + *@v
9654+ */
9655+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9656+{
9657+ alternative_atomic64(add_return_unchecked,
9658+ ASM_OUTPUT2("+A" (i), "+c" (v)),
9659+ ASM_NO_INPUT_CLOBBER("memory"));
9660+ return i;
9661+}
9662+
9663 /*
9664 * Other variants with different arithmetic operators:
9665 */
9666@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9667 return a;
9668 }
9669
9670+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9671+{
9672+ long long a;
9673+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
9674+ "S" (v) : "memory", "ecx");
9675+ return a;
9676+}
9677+
9678 static inline long long atomic64_dec_return(atomic64_t *v)
9679 {
9680 long long a;
9681@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9682 }
9683
9684 /**
9685+ * atomic64_add_unchecked - add integer to atomic64 variable
9686+ * @i: integer value to add
9687+ * @v: pointer to type atomic64_unchecked_t
9688+ *
9689+ * Atomically adds @i to @v.
9690+ */
9691+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9692+{
9693+ __alternative_atomic64(add_unchecked, add_return_unchecked,
9694+ ASM_OUTPUT2("+A" (i), "+c" (v)),
9695+ ASM_NO_INPUT_CLOBBER("memory"));
9696+ return i;
9697+}
9698+
9699+/**
9700 * atomic64_sub - subtract the atomic64 variable
9701 * @i: integer value to subtract
9702 * @v: pointer to type atomic64_t
9703diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9704index 0e1cbfc..5623683 100644
9705--- a/arch/x86/include/asm/atomic64_64.h
9706+++ b/arch/x86/include/asm/atomic64_64.h
9707@@ -18,7 +18,19 @@
9708 */
9709 static inline long atomic64_read(const atomic64_t *v)
9710 {
9711- return (*(volatile long *)&(v)->counter);
9712+ return (*(volatile const long *)&(v)->counter);
9713+}
9714+
9715+/**
9716+ * atomic64_read_unchecked - read atomic64 variable
9717+ * @v: pointer of type atomic64_unchecked_t
9718+ *
9719+ * Atomically reads the value of @v.
9720+ * Doesn't imply a read memory barrier.
9721+ */
9722+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9723+{
9724+ return (*(volatile const long *)&(v)->counter);
9725 }
9726
9727 /**
9728@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9729 }
9730
9731 /**
9732+ * atomic64_set_unchecked - set atomic64 variable
9733+ * @v: pointer to type atomic64_unchecked_t
9734+ * @i: required value
9735+ *
9736+ * Atomically sets the value of @v to @i.
9737+ */
9738+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9739+{
9740+ v->counter = i;
9741+}
9742+
9743+/**
9744 * atomic64_add - add integer to atomic64 variable
9745 * @i: integer value to add
9746 * @v: pointer to type atomic64_t
9747@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9748 */
9749 static inline void atomic64_add(long i, atomic64_t *v)
9750 {
9751+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
9752+
9753+#ifdef CONFIG_PAX_REFCOUNT
9754+ "jno 0f\n"
9755+ LOCK_PREFIX "subq %1,%0\n"
9756+ "int $4\n0:\n"
9757+ _ASM_EXTABLE(0b, 0b)
9758+#endif
9759+
9760+ : "=m" (v->counter)
9761+ : "er" (i), "m" (v->counter));
9762+}
9763+
9764+/**
9765+ * atomic64_add_unchecked - add integer to atomic64 variable
9766+ * @i: integer value to add
9767+ * @v: pointer to type atomic64_unchecked_t
9768+ *
9769+ * Atomically adds @i to @v.
9770+ */
9771+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9772+{
9773 asm volatile(LOCK_PREFIX "addq %1,%0"
9774 : "=m" (v->counter)
9775 : "er" (i), "m" (v->counter));
9776@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9777 */
9778 static inline void atomic64_sub(long i, atomic64_t *v)
9779 {
9780- asm volatile(LOCK_PREFIX "subq %1,%0"
9781+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
9782+
9783+#ifdef CONFIG_PAX_REFCOUNT
9784+ "jno 0f\n"
9785+ LOCK_PREFIX "addq %1,%0\n"
9786+ "int $4\n0:\n"
9787+ _ASM_EXTABLE(0b, 0b)
9788+#endif
9789+
9790+ : "=m" (v->counter)
9791+ : "er" (i), "m" (v->counter));
9792+}
9793+
9794+/**
9795+ * atomic64_sub_unchecked - subtract the atomic64 variable
9796+ * @i: integer value to subtract
9797+ * @v: pointer to type atomic64_unchecked_t
9798+ *
9799+ * Atomically subtracts @i from @v.
9800+ */
9801+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9802+{
9803+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
9804 : "=m" (v->counter)
9805 : "er" (i), "m" (v->counter));
9806 }
9807@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9808 {
9809 unsigned char c;
9810
9811- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9812+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
9813+
9814+#ifdef CONFIG_PAX_REFCOUNT
9815+ "jno 0f\n"
9816+ LOCK_PREFIX "addq %2,%0\n"
9817+ "int $4\n0:\n"
9818+ _ASM_EXTABLE(0b, 0b)
9819+#endif
9820+
9821+ "sete %1\n"
9822 : "=m" (v->counter), "=qm" (c)
9823 : "er" (i), "m" (v->counter) : "memory");
9824 return c;
9825@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9826 */
9827 static inline void atomic64_inc(atomic64_t *v)
9828 {
9829+ asm volatile(LOCK_PREFIX "incq %0\n"
9830+
9831+#ifdef CONFIG_PAX_REFCOUNT
9832+ "jno 0f\n"
9833+ LOCK_PREFIX "decq %0\n"
9834+ "int $4\n0:\n"
9835+ _ASM_EXTABLE(0b, 0b)
9836+#endif
9837+
9838+ : "=m" (v->counter)
9839+ : "m" (v->counter));
9840+}
9841+
9842+/**
9843+ * atomic64_inc_unchecked - increment atomic64 variable
9844+ * @v: pointer to type atomic64_unchecked_t
9845+ *
9846+ * Atomically increments @v by 1.
9847+ */
9848+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9849+{
9850 asm volatile(LOCK_PREFIX "incq %0"
9851 : "=m" (v->counter)
9852 : "m" (v->counter));
9853@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9854 */
9855 static inline void atomic64_dec(atomic64_t *v)
9856 {
9857- asm volatile(LOCK_PREFIX "decq %0"
9858+ asm volatile(LOCK_PREFIX "decq %0\n"
9859+
9860+#ifdef CONFIG_PAX_REFCOUNT
9861+ "jno 0f\n"
9862+ LOCK_PREFIX "incq %0\n"
9863+ "int $4\n0:\n"
9864+ _ASM_EXTABLE(0b, 0b)
9865+#endif
9866+
9867+ : "=m" (v->counter)
9868+ : "m" (v->counter));
9869+}
9870+
9871+/**
9872+ * atomic64_dec_unchecked - decrement atomic64 variable
9873+ * @v: pointer to type atomic64_t
9874+ *
9875+ * Atomically decrements @v by 1.
9876+ */
9877+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9878+{
9879+ asm volatile(LOCK_PREFIX "decq %0\n"
9880 : "=m" (v->counter)
9881 : "m" (v->counter));
9882 }
9883@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9884 {
9885 unsigned char c;
9886
9887- asm volatile(LOCK_PREFIX "decq %0; sete %1"
9888+ asm volatile(LOCK_PREFIX "decq %0\n"
9889+
9890+#ifdef CONFIG_PAX_REFCOUNT
9891+ "jno 0f\n"
9892+ LOCK_PREFIX "incq %0\n"
9893+ "int $4\n0:\n"
9894+ _ASM_EXTABLE(0b, 0b)
9895+#endif
9896+
9897+ "sete %1\n"
9898 : "=m" (v->counter), "=qm" (c)
9899 : "m" (v->counter) : "memory");
9900 return c != 0;
9901@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9902 {
9903 unsigned char c;
9904
9905- asm volatile(LOCK_PREFIX "incq %0; sete %1"
9906+ asm volatile(LOCK_PREFIX "incq %0\n"
9907+
9908+#ifdef CONFIG_PAX_REFCOUNT
9909+ "jno 0f\n"
9910+ LOCK_PREFIX "decq %0\n"
9911+ "int $4\n0:\n"
9912+ _ASM_EXTABLE(0b, 0b)
9913+#endif
9914+
9915+ "sete %1\n"
9916 : "=m" (v->counter), "=qm" (c)
9917 : "m" (v->counter) : "memory");
9918 return c != 0;
9919@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9920 {
9921 unsigned char c;
9922
9923- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9924+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
9925+
9926+#ifdef CONFIG_PAX_REFCOUNT
9927+ "jno 0f\n"
9928+ LOCK_PREFIX "subq %2,%0\n"
9929+ "int $4\n0:\n"
9930+ _ASM_EXTABLE(0b, 0b)
9931+#endif
9932+
9933+ "sets %1\n"
9934 : "=m" (v->counter), "=qm" (c)
9935 : "er" (i), "m" (v->counter) : "memory");
9936 return c;
9937@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9938 */
9939 static inline long atomic64_add_return(long i, atomic64_t *v)
9940 {
9941+ return i + xadd_check_overflow(&v->counter, i);
9942+}
9943+
9944+/**
9945+ * atomic64_add_return_unchecked - add and return
9946+ * @i: integer value to add
9947+ * @v: pointer to type atomic64_unchecked_t
9948+ *
9949+ * Atomically adds @i to @v and returns @i + @v
9950+ */
9951+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9952+{
9953 return i + xadd(&v->counter, i);
9954 }
9955
9956@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
9957 }
9958
9959 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
9960+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9961+{
9962+ return atomic64_add_return_unchecked(1, v);
9963+}
9964 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
9965
9966 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9967@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9968 return cmpxchg(&v->counter, old, new);
9969 }
9970
9971+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
9972+{
9973+ return cmpxchg(&v->counter, old, new);
9974+}
9975+
9976 static inline long atomic64_xchg(atomic64_t *v, long new)
9977 {
9978 return xchg(&v->counter, new);
9979@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
9980 */
9981 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
9982 {
9983- long c, old;
9984+ long c, old, new;
9985 c = atomic64_read(v);
9986 for (;;) {
9987- if (unlikely(c == (u)))
9988+ if (unlikely(c == u))
9989 break;
9990- old = atomic64_cmpxchg((v), c, c + (a));
9991+
9992+ asm volatile("add %2,%0\n"
9993+
9994+#ifdef CONFIG_PAX_REFCOUNT
9995+ "jno 0f\n"
9996+ "sub %2,%0\n"
9997+ "int $4\n0:\n"
9998+ _ASM_EXTABLE(0b, 0b)
9999+#endif
10000+
10001+ : "=r" (new)
10002+ : "0" (c), "ir" (a));
10003+
10004+ old = atomic64_cmpxchg(v, c, new);
10005 if (likely(old == c))
10006 break;
10007 c = old;
10008 }
10009- return c != (u);
10010+ return c != u;
10011 }
10012
10013 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10014diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10015index a6983b2..63f48a2 100644
10016--- a/arch/x86/include/asm/bitops.h
10017+++ b/arch/x86/include/asm/bitops.h
10018@@ -40,7 +40,7 @@
10019 * a mask operation on a byte.
10020 */
10021 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10022-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10023+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10024 #define CONST_MASK(nr) (1 << ((nr) & 7))
10025
10026 /**
10027diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10028index b13fe63..0dab13a 100644
10029--- a/arch/x86/include/asm/boot.h
10030+++ b/arch/x86/include/asm/boot.h
10031@@ -11,10 +11,15 @@
10032 #include <asm/pgtable_types.h>
10033
10034 /* Physical address where kernel should be loaded. */
10035-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10036+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10037 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10038 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10039
10040+#ifndef __ASSEMBLY__
10041+extern unsigned char __LOAD_PHYSICAL_ADDR[];
10042+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10043+#endif
10044+
10045 /* Minimum kernel alignment, as a power of two */
10046 #ifdef CONFIG_X86_64
10047 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10048diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10049index 48f99f1..d78ebf9 100644
10050--- a/arch/x86/include/asm/cache.h
10051+++ b/arch/x86/include/asm/cache.h
10052@@ -5,12 +5,13 @@
10053
10054 /* L1 cache line size */
10055 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10056-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10057+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10058
10059 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10060+#define __read_only __attribute__((__section__(".data..read_only")))
10061
10062 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10063-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10064+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10065
10066 #ifdef CONFIG_X86_VSMP
10067 #ifdef CONFIG_SMP
10068diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10069index 9863ee3..4a1f8e1 100644
10070--- a/arch/x86/include/asm/cacheflush.h
10071+++ b/arch/x86/include/asm/cacheflush.h
10072@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10073 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10074
10075 if (pg_flags == _PGMT_DEFAULT)
10076- return -1;
10077+ return ~0UL;
10078 else if (pg_flags == _PGMT_WC)
10079 return _PAGE_CACHE_WC;
10080 else if (pg_flags == _PGMT_UC_MINUS)
10081diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10082index 46fc474..b02b0f9 100644
10083--- a/arch/x86/include/asm/checksum_32.h
10084+++ b/arch/x86/include/asm/checksum_32.h
10085@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10086 int len, __wsum sum,
10087 int *src_err_ptr, int *dst_err_ptr);
10088
10089+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10090+ int len, __wsum sum,
10091+ int *src_err_ptr, int *dst_err_ptr);
10092+
10093+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10094+ int len, __wsum sum,
10095+ int *src_err_ptr, int *dst_err_ptr);
10096+
10097 /*
10098 * Note: when you get a NULL pointer exception here this means someone
10099 * passed in an incorrect kernel address to one of these functions.
10100@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10101 int *err_ptr)
10102 {
10103 might_sleep();
10104- return csum_partial_copy_generic((__force void *)src, dst,
10105+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
10106 len, sum, err_ptr, NULL);
10107 }
10108
10109@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10110 {
10111 might_sleep();
10112 if (access_ok(VERIFY_WRITE, dst, len))
10113- return csum_partial_copy_generic(src, (__force void *)dst,
10114+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10115 len, sum, NULL, err_ptr);
10116
10117 if (len)
10118diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10119index 99480e5..d81165b 100644
10120--- a/arch/x86/include/asm/cmpxchg.h
10121+++ b/arch/x86/include/asm/cmpxchg.h
10122@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10123 __compiletime_error("Bad argument size for cmpxchg");
10124 extern void __xadd_wrong_size(void)
10125 __compiletime_error("Bad argument size for xadd");
10126+extern void __xadd_check_overflow_wrong_size(void)
10127+ __compiletime_error("Bad argument size for xadd_check_overflow");
10128 extern void __add_wrong_size(void)
10129 __compiletime_error("Bad argument size for add");
10130+extern void __add_check_overflow_wrong_size(void)
10131+ __compiletime_error("Bad argument size for add_check_overflow");
10132
10133 /*
10134 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10135@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10136 __ret; \
10137 })
10138
10139+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10140+ ({ \
10141+ __typeof__ (*(ptr)) __ret = (arg); \
10142+ switch (sizeof(*(ptr))) { \
10143+ case __X86_CASE_L: \
10144+ asm volatile (lock #op "l %0, %1\n" \
10145+ "jno 0f\n" \
10146+ "mov %0,%1\n" \
10147+ "int $4\n0:\n" \
10148+ _ASM_EXTABLE(0b, 0b) \
10149+ : "+r" (__ret), "+m" (*(ptr)) \
10150+ : : "memory", "cc"); \
10151+ break; \
10152+ case __X86_CASE_Q: \
10153+ asm volatile (lock #op "q %q0, %1\n" \
10154+ "jno 0f\n" \
10155+ "mov %0,%1\n" \
10156+ "int $4\n0:\n" \
10157+ _ASM_EXTABLE(0b, 0b) \
10158+ : "+r" (__ret), "+m" (*(ptr)) \
10159+ : : "memory", "cc"); \
10160+ break; \
10161+ default: \
10162+ __ ## op ## _check_overflow_wrong_size(); \
10163+ } \
10164+ __ret; \
10165+ })
10166+
10167 /*
10168 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10169 * Since this is generally used to protect other memory information, we
10170@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10171 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10172 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10173
10174+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10175+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10176+
10177 #define __add(ptr, inc, lock) \
10178 ({ \
10179 __typeof__ (*(ptr)) __ret = (inc); \
10180diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10181index f91e80f..7f9bd27 100644
10182--- a/arch/x86/include/asm/cpufeature.h
10183+++ b/arch/x86/include/asm/cpufeature.h
10184@@ -371,7 +371,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10185 ".section .discard,\"aw\",@progbits\n"
10186 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10187 ".previous\n"
10188- ".section .altinstr_replacement,\"ax\"\n"
10189+ ".section .altinstr_replacement,\"a\"\n"
10190 "3: movb $1,%0\n"
10191 "4:\n"
10192 ".previous\n"
10193diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10194index 8bf1c06..f723dfd 100644
10195--- a/arch/x86/include/asm/desc.h
10196+++ b/arch/x86/include/asm/desc.h
10197@@ -4,6 +4,7 @@
10198 #include <asm/desc_defs.h>
10199 #include <asm/ldt.h>
10200 #include <asm/mmu.h>
10201+#include <asm/pgtable.h>
10202
10203 #include <linux/smp.h>
10204 #include <linux/percpu.h>
10205@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10206
10207 desc->type = (info->read_exec_only ^ 1) << 1;
10208 desc->type |= info->contents << 2;
10209+ desc->type |= info->seg_not_present ^ 1;
10210
10211 desc->s = 1;
10212 desc->dpl = 0x3;
10213@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10214 }
10215
10216 extern struct desc_ptr idt_descr;
10217-extern gate_desc idt_table[];
10218 extern struct desc_ptr nmi_idt_descr;
10219-extern gate_desc nmi_idt_table[];
10220-
10221-struct gdt_page {
10222- struct desc_struct gdt[GDT_ENTRIES];
10223-} __attribute__((aligned(PAGE_SIZE)));
10224-
10225-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10226+extern gate_desc idt_table[256];
10227+extern gate_desc nmi_idt_table[256];
10228
10229+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10230 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10231 {
10232- return per_cpu(gdt_page, cpu).gdt;
10233+ return cpu_gdt_table[cpu];
10234 }
10235
10236 #ifdef CONFIG_X86_64
10237@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10238 unsigned long base, unsigned dpl, unsigned flags,
10239 unsigned short seg)
10240 {
10241- gate->a = (seg << 16) | (base & 0xffff);
10242- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10243+ gate->gate.offset_low = base;
10244+ gate->gate.seg = seg;
10245+ gate->gate.reserved = 0;
10246+ gate->gate.type = type;
10247+ gate->gate.s = 0;
10248+ gate->gate.dpl = dpl;
10249+ gate->gate.p = 1;
10250+ gate->gate.offset_high = base >> 16;
10251 }
10252
10253 #endif
10254@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10255
10256 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10257 {
10258+ pax_open_kernel();
10259 memcpy(&idt[entry], gate, sizeof(*gate));
10260+ pax_close_kernel();
10261 }
10262
10263 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10264 {
10265+ pax_open_kernel();
10266 memcpy(&ldt[entry], desc, 8);
10267+ pax_close_kernel();
10268 }
10269
10270 static inline void
10271@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10272 default: size = sizeof(*gdt); break;
10273 }
10274
10275+ pax_open_kernel();
10276 memcpy(&gdt[entry], desc, size);
10277+ pax_close_kernel();
10278 }
10279
10280 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10281@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10282
10283 static inline void native_load_tr_desc(void)
10284 {
10285+ pax_open_kernel();
10286 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10287+ pax_close_kernel();
10288 }
10289
10290 static inline void native_load_gdt(const struct desc_ptr *dtr)
10291@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10292 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10293 unsigned int i;
10294
10295+ pax_open_kernel();
10296 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10297 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10298+ pax_close_kernel();
10299 }
10300
10301 #define _LDT_empty(info) \
10302@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10303 }
10304
10305 #ifdef CONFIG_X86_64
10306-static inline void set_nmi_gate(int gate, void *addr)
10307+static inline void set_nmi_gate(int gate, const void *addr)
10308 {
10309 gate_desc s;
10310
10311@@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10312 }
10313 #endif
10314
10315-static inline void _set_gate(int gate, unsigned type, void *addr,
10316+static inline void _set_gate(int gate, unsigned type, const void *addr,
10317 unsigned dpl, unsigned ist, unsigned seg)
10318 {
10319 gate_desc s;
10320@@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10321 * Pentium F0 0F bugfix can have resulted in the mapped
10322 * IDT being write-protected.
10323 */
10324-static inline void set_intr_gate(unsigned int n, void *addr)
10325+static inline void set_intr_gate(unsigned int n, const void *addr)
10326 {
10327 BUG_ON((unsigned)n > 0xFF);
10328 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10329@@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10330 /*
10331 * This routine sets up an interrupt gate at directory privilege level 3.
10332 */
10333-static inline void set_system_intr_gate(unsigned int n, void *addr)
10334+static inline void set_system_intr_gate(unsigned int n, const void *addr)
10335 {
10336 BUG_ON((unsigned)n > 0xFF);
10337 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10338 }
10339
10340-static inline void set_system_trap_gate(unsigned int n, void *addr)
10341+static inline void set_system_trap_gate(unsigned int n, const void *addr)
10342 {
10343 BUG_ON((unsigned)n > 0xFF);
10344 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10345 }
10346
10347-static inline void set_trap_gate(unsigned int n, void *addr)
10348+static inline void set_trap_gate(unsigned int n, const void *addr)
10349 {
10350 BUG_ON((unsigned)n > 0xFF);
10351 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10352@@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10353 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10354 {
10355 BUG_ON((unsigned)n > 0xFF);
10356- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10357+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10358 }
10359
10360-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10361+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10362 {
10363 BUG_ON((unsigned)n > 0xFF);
10364 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10365 }
10366
10367-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10368+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10369 {
10370 BUG_ON((unsigned)n > 0xFF);
10371 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10372 }
10373
10374+#ifdef CONFIG_X86_32
10375+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10376+{
10377+ struct desc_struct d;
10378+
10379+ if (likely(limit))
10380+ limit = (limit - 1UL) >> PAGE_SHIFT;
10381+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
10382+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10383+}
10384+#endif
10385+
10386 #endif /* _ASM_X86_DESC_H */
10387diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10388index 278441f..b95a174 100644
10389--- a/arch/x86/include/asm/desc_defs.h
10390+++ b/arch/x86/include/asm/desc_defs.h
10391@@ -31,6 +31,12 @@ struct desc_struct {
10392 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10393 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10394 };
10395+ struct {
10396+ u16 offset_low;
10397+ u16 seg;
10398+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10399+ unsigned offset_high: 16;
10400+ } gate;
10401 };
10402 } __attribute__((packed));
10403
10404diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10405index 3778256..c5d4fce 100644
10406--- a/arch/x86/include/asm/e820.h
10407+++ b/arch/x86/include/asm/e820.h
10408@@ -69,7 +69,7 @@ struct e820map {
10409 #define ISA_START_ADDRESS 0xa0000
10410 #define ISA_END_ADDRESS 0x100000
10411
10412-#define BIOS_BEGIN 0x000a0000
10413+#define BIOS_BEGIN 0x000c0000
10414 #define BIOS_END 0x00100000
10415
10416 #define BIOS_ROM_BASE 0xffe00000
10417diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10418index 5939f44..f8845f6 100644
10419--- a/arch/x86/include/asm/elf.h
10420+++ b/arch/x86/include/asm/elf.h
10421@@ -243,7 +243,25 @@ extern int force_personality32;
10422 the loader. We need to make sure that it is out of the way of the program
10423 that it will "exec", and that there is sufficient room for the brk. */
10424
10425+#ifdef CONFIG_PAX_SEGMEXEC
10426+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10427+#else
10428 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10429+#endif
10430+
10431+#ifdef CONFIG_PAX_ASLR
10432+#ifdef CONFIG_X86_32
10433+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10434+
10435+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10436+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10437+#else
10438+#define PAX_ELF_ET_DYN_BASE 0x400000UL
10439+
10440+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10441+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10442+#endif
10443+#endif
10444
10445 /* This yields a mask that user programs can use to figure out what
10446 instruction set this CPU supports. This could be done in user space,
10447@@ -296,16 +314,12 @@ do { \
10448
10449 #define ARCH_DLINFO \
10450 do { \
10451- if (vdso_enabled) \
10452- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10453- (unsigned long)current->mm->context.vdso); \
10454+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10455 } while (0)
10456
10457 #define ARCH_DLINFO_X32 \
10458 do { \
10459- if (vdso_enabled) \
10460- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10461- (unsigned long)current->mm->context.vdso); \
10462+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10463 } while (0)
10464
10465 #define AT_SYSINFO 32
10466@@ -320,7 +334,7 @@ else \
10467
10468 #endif /* !CONFIG_X86_32 */
10469
10470-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10471+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10472
10473 #define VDSO_ENTRY \
10474 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10475@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
10476 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10477 #define compat_arch_setup_additional_pages syscall32_setup_pages
10478
10479-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10480-#define arch_randomize_brk arch_randomize_brk
10481-
10482 /*
10483 * True on X86_32 or when emulating IA32 on X86_64
10484 */
10485diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10486index cc70c1c..d96d011 100644
10487--- a/arch/x86/include/asm/emergency-restart.h
10488+++ b/arch/x86/include/asm/emergency-restart.h
10489@@ -15,6 +15,6 @@ enum reboot_type {
10490
10491 extern enum reboot_type reboot_type;
10492
10493-extern void machine_emergency_restart(void);
10494+extern void machine_emergency_restart(void) __noreturn;
10495
10496 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10497diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
10498index 75f4c6d..ee3eb8f 100644
10499--- a/arch/x86/include/asm/fpu-internal.h
10500+++ b/arch/x86/include/asm/fpu-internal.h
10501@@ -86,6 +86,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10502 {
10503 int err;
10504
10505+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10506+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10507+ fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10508+#endif
10509+
10510 /* See comment in fxsave() below. */
10511 #ifdef CONFIG_AS_FXSAVEQ
10512 asm volatile("1: fxrstorq %[fx]\n\t"
10513@@ -115,6 +120,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10514 {
10515 int err;
10516
10517+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10518+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10519+ fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10520+#endif
10521+
10522 /*
10523 * Clear the bytes not touched by the fxsave and reserved
10524 * for the SW usage.
10525@@ -271,7 +281,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10526 "emms\n\t" /* clear stack tags */
10527 "fildl %P[addr]", /* set F?P to defined value */
10528 X86_FEATURE_FXSAVE_LEAK,
10529- [addr] "m" (tsk->thread.fpu.has_fpu));
10530+ [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10531
10532 return fpu_restore_checking(&tsk->thread.fpu);
10533 }
10534diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10535index 71ecbcb..bac10b7 100644
10536--- a/arch/x86/include/asm/futex.h
10537+++ b/arch/x86/include/asm/futex.h
10538@@ -11,16 +11,18 @@
10539 #include <asm/processor.h>
10540
10541 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10542+ typecheck(u32 __user *, uaddr); \
10543 asm volatile("1:\t" insn "\n" \
10544 "2:\t.section .fixup,\"ax\"\n" \
10545 "3:\tmov\t%3, %1\n" \
10546 "\tjmp\t2b\n" \
10547 "\t.previous\n" \
10548 _ASM_EXTABLE(1b, 3b) \
10549- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10550+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10551 : "i" (-EFAULT), "0" (oparg), "1" (0))
10552
10553 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10554+ typecheck(u32 __user *, uaddr); \
10555 asm volatile("1:\tmovl %2, %0\n" \
10556 "\tmovl\t%0, %3\n" \
10557 "\t" insn "\n" \
10558@@ -33,7 +35,7 @@
10559 _ASM_EXTABLE(1b, 4b) \
10560 _ASM_EXTABLE(2b, 4b) \
10561 : "=&a" (oldval), "=&r" (ret), \
10562- "+m" (*uaddr), "=&r" (tem) \
10563+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10564 : "r" (oparg), "i" (-EFAULT), "1" (0))
10565
10566 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10567@@ -60,10 +62,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10568
10569 switch (op) {
10570 case FUTEX_OP_SET:
10571- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10572+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10573 break;
10574 case FUTEX_OP_ADD:
10575- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10576+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10577 uaddr, oparg);
10578 break;
10579 case FUTEX_OP_OR:
10580@@ -122,13 +124,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10581 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10582 return -EFAULT;
10583
10584- asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10585+ asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10586 "2:\t.section .fixup, \"ax\"\n"
10587 "3:\tmov %3, %0\n"
10588 "\tjmp 2b\n"
10589 "\t.previous\n"
10590 _ASM_EXTABLE(1b, 3b)
10591- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10592+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10593 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10594 : "memory"
10595 );
10596diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10597index eb92a6e..b98b2f4 100644
10598--- a/arch/x86/include/asm/hw_irq.h
10599+++ b/arch/x86/include/asm/hw_irq.h
10600@@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10601 extern void enable_IO_APIC(void);
10602
10603 /* Statistics */
10604-extern atomic_t irq_err_count;
10605-extern atomic_t irq_mis_count;
10606+extern atomic_unchecked_t irq_err_count;
10607+extern atomic_unchecked_t irq_mis_count;
10608
10609 /* EISA */
10610 extern void eisa_set_level_irq(unsigned int irq);
10611diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10612index d8e8eef..99f81ae 100644
10613--- a/arch/x86/include/asm/io.h
10614+++ b/arch/x86/include/asm/io.h
10615@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10616
10617 #include <linux/vmalloc.h>
10618
10619+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10620+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10621+{
10622+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10623+}
10624+
10625+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10626+{
10627+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10628+}
10629+
10630 /*
10631 * Convert a virtual cached pointer to an uncached pointer
10632 */
10633diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10634index bba3cf8..06bc8da 100644
10635--- a/arch/x86/include/asm/irqflags.h
10636+++ b/arch/x86/include/asm/irqflags.h
10637@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10638 sti; \
10639 sysexit
10640
10641+#define GET_CR0_INTO_RDI mov %cr0, %rdi
10642+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10643+#define GET_CR3_INTO_RDI mov %cr3, %rdi
10644+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10645+
10646 #else
10647 #define INTERRUPT_RETURN iret
10648 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10649diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10650index 5478825..839e88c 100644
10651--- a/arch/x86/include/asm/kprobes.h
10652+++ b/arch/x86/include/asm/kprobes.h
10653@@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10654 #define RELATIVEJUMP_SIZE 5
10655 #define RELATIVECALL_OPCODE 0xe8
10656 #define RELATIVE_ADDR_SIZE 4
10657-#define MAX_STACK_SIZE 64
10658-#define MIN_STACK_SIZE(ADDR) \
10659- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10660- THREAD_SIZE - (unsigned long)(ADDR))) \
10661- ? (MAX_STACK_SIZE) \
10662- : (((unsigned long)current_thread_info()) + \
10663- THREAD_SIZE - (unsigned long)(ADDR)))
10664+#define MAX_STACK_SIZE 64UL
10665+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10666
10667 #define flush_insn_slot(p) do { } while (0)
10668
10669diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10670index db7c1f2..92f130a 100644
10671--- a/arch/x86/include/asm/kvm_host.h
10672+++ b/arch/x86/include/asm/kvm_host.h
10673@@ -680,7 +680,7 @@ struct kvm_x86_ops {
10674 int (*check_intercept)(struct kvm_vcpu *vcpu,
10675 struct x86_instruction_info *info,
10676 enum x86_intercept_stage stage);
10677-};
10678+} __do_const;
10679
10680 struct kvm_arch_async_pf {
10681 u32 token;
10682diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10683index c8bed0d..e5721fa 100644
10684--- a/arch/x86/include/asm/local.h
10685+++ b/arch/x86/include/asm/local.h
10686@@ -17,26 +17,58 @@ typedef struct {
10687
10688 static inline void local_inc(local_t *l)
10689 {
10690- asm volatile(_ASM_INC "%0"
10691+ asm volatile(_ASM_INC "%0\n"
10692+
10693+#ifdef CONFIG_PAX_REFCOUNT
10694+ "jno 0f\n"
10695+ _ASM_DEC "%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_dec(local_t *l)
10704 {
10705- asm volatile(_ASM_DEC "%0"
10706+ asm volatile(_ASM_DEC "%0\n"
10707+
10708+#ifdef CONFIG_PAX_REFCOUNT
10709+ "jno 0f\n"
10710+ _ASM_INC "%0\n"
10711+ "int $4\n0:\n"
10712+ _ASM_EXTABLE(0b, 0b)
10713+#endif
10714+
10715 : "+m" (l->a.counter));
10716 }
10717
10718 static inline void local_add(long i, local_t *l)
10719 {
10720- asm volatile(_ASM_ADD "%1,%0"
10721+ asm volatile(_ASM_ADD "%1,%0\n"
10722+
10723+#ifdef CONFIG_PAX_REFCOUNT
10724+ "jno 0f\n"
10725+ _ASM_SUB "%1,%0\n"
10726+ "int $4\n0:\n"
10727+ _ASM_EXTABLE(0b, 0b)
10728+#endif
10729+
10730 : "+m" (l->a.counter)
10731 : "ir" (i));
10732 }
10733
10734 static inline void local_sub(long i, local_t *l)
10735 {
10736- asm volatile(_ASM_SUB "%1,%0"
10737+ asm volatile(_ASM_SUB "%1,%0\n"
10738+
10739+#ifdef CONFIG_PAX_REFCOUNT
10740+ "jno 0f\n"
10741+ _ASM_ADD "%1,%0\n"
10742+ "int $4\n0:\n"
10743+ _ASM_EXTABLE(0b, 0b)
10744+#endif
10745+
10746 : "+m" (l->a.counter)
10747 : "ir" (i));
10748 }
10749@@ -54,7 +86,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10750 {
10751 unsigned char c;
10752
10753- asm volatile(_ASM_SUB "%2,%0; sete %1"
10754+ asm volatile(_ASM_SUB "%2,%0\n"
10755+
10756+#ifdef CONFIG_PAX_REFCOUNT
10757+ "jno 0f\n"
10758+ _ASM_ADD "%2,%0\n"
10759+ "int $4\n0:\n"
10760+ _ASM_EXTABLE(0b, 0b)
10761+#endif
10762+
10763+ "sete %1\n"
10764 : "+m" (l->a.counter), "=qm" (c)
10765 : "ir" (i) : "memory");
10766 return c;
10767@@ -72,7 +113,16 @@ static inline int local_dec_and_test(local_t *l)
10768 {
10769 unsigned char c;
10770
10771- asm volatile(_ASM_DEC "%0; sete %1"
10772+ asm volatile(_ASM_DEC "%0\n"
10773+
10774+#ifdef CONFIG_PAX_REFCOUNT
10775+ "jno 0f\n"
10776+ _ASM_INC "%0\n"
10777+ "int $4\n0:\n"
10778+ _ASM_EXTABLE(0b, 0b)
10779+#endif
10780+
10781+ "sete %1\n"
10782 : "+m" (l->a.counter), "=qm" (c)
10783 : : "memory");
10784 return c != 0;
10785@@ -90,7 +140,16 @@ static inline int local_inc_and_test(local_t *l)
10786 {
10787 unsigned char c;
10788
10789- asm volatile(_ASM_INC "%0; sete %1"
10790+ asm volatile(_ASM_INC "%0\n"
10791+
10792+#ifdef CONFIG_PAX_REFCOUNT
10793+ "jno 0f\n"
10794+ _ASM_DEC "%0\n"
10795+ "int $4\n0:\n"
10796+ _ASM_EXTABLE(0b, 0b)
10797+#endif
10798+
10799+ "sete %1\n"
10800 : "+m" (l->a.counter), "=qm" (c)
10801 : : "memory");
10802 return c != 0;
10803@@ -109,7 +168,16 @@ static inline int local_add_negative(long i, local_t *l)
10804 {
10805 unsigned char c;
10806
10807- asm volatile(_ASM_ADD "%2,%0; sets %1"
10808+ asm volatile(_ASM_ADD "%2,%0\n"
10809+
10810+#ifdef CONFIG_PAX_REFCOUNT
10811+ "jno 0f\n"
10812+ _ASM_SUB "%2,%0\n"
10813+ "int $4\n0:\n"
10814+ _ASM_EXTABLE(0b, 0b)
10815+#endif
10816+
10817+ "sets %1\n"
10818 : "+m" (l->a.counter), "=qm" (c)
10819 : "ir" (i) : "memory");
10820 return c;
10821@@ -132,7 +200,15 @@ static inline long local_add_return(long i, local_t *l)
10822 #endif
10823 /* Modern 486+ processor */
10824 __i = i;
10825- asm volatile(_ASM_XADD "%0, %1;"
10826+ asm volatile(_ASM_XADD "%0, %1\n"
10827+
10828+#ifdef CONFIG_PAX_REFCOUNT
10829+ "jno 0f\n"
10830+ _ASM_MOV "%0,%1\n"
10831+ "int $4\n0:\n"
10832+ _ASM_EXTABLE(0b, 0b)
10833+#endif
10834+
10835 : "+r" (i), "+m" (l->a.counter)
10836 : : "memory");
10837 return i + __i;
10838diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10839index 593e51d..fa69c9a 100644
10840--- a/arch/x86/include/asm/mman.h
10841+++ b/arch/x86/include/asm/mman.h
10842@@ -5,4 +5,14 @@
10843
10844 #include <asm-generic/mman.h>
10845
10846+#ifdef __KERNEL__
10847+#ifndef __ASSEMBLY__
10848+#ifdef CONFIG_X86_32
10849+#define arch_mmap_check i386_mmap_check
10850+int i386_mmap_check(unsigned long addr, unsigned long len,
10851+ unsigned long flags);
10852+#endif
10853+#endif
10854+#endif
10855+
10856 #endif /* _ASM_X86_MMAN_H */
10857diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10858index 5f55e69..e20bfb1 100644
10859--- a/arch/x86/include/asm/mmu.h
10860+++ b/arch/x86/include/asm/mmu.h
10861@@ -9,7 +9,7 @@
10862 * we put the segment information here.
10863 */
10864 typedef struct {
10865- void *ldt;
10866+ struct desc_struct *ldt;
10867 int size;
10868
10869 #ifdef CONFIG_X86_64
10870@@ -18,7 +18,19 @@ typedef struct {
10871 #endif
10872
10873 struct mutex lock;
10874- void *vdso;
10875+ unsigned long vdso;
10876+
10877+#ifdef CONFIG_X86_32
10878+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10879+ unsigned long user_cs_base;
10880+ unsigned long user_cs_limit;
10881+
10882+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10883+ cpumask_t cpu_user_cs_mask;
10884+#endif
10885+
10886+#endif
10887+#endif
10888 } mm_context_t;
10889
10890 #ifdef CONFIG_SMP
10891diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10892index cdbf367..adb37ac 100644
10893--- a/arch/x86/include/asm/mmu_context.h
10894+++ b/arch/x86/include/asm/mmu_context.h
10895@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10896
10897 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10898 {
10899+
10900+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10901+ unsigned int i;
10902+ pgd_t *pgd;
10903+
10904+ pax_open_kernel();
10905+ pgd = get_cpu_pgd(smp_processor_id());
10906+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10907+ set_pgd_batched(pgd+i, native_make_pgd(0));
10908+ pax_close_kernel();
10909+#endif
10910+
10911 #ifdef CONFIG_SMP
10912 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10913 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10914@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10915 struct task_struct *tsk)
10916 {
10917 unsigned cpu = smp_processor_id();
10918+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10919+ int tlbstate = TLBSTATE_OK;
10920+#endif
10921
10922 if (likely(prev != next)) {
10923 #ifdef CONFIG_SMP
10924+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10925+ tlbstate = this_cpu_read(cpu_tlbstate.state);
10926+#endif
10927 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10928 this_cpu_write(cpu_tlbstate.active_mm, next);
10929 #endif
10930 cpumask_set_cpu(cpu, mm_cpumask(next));
10931
10932 /* Re-load page tables */
10933+#ifdef CONFIG_PAX_PER_CPU_PGD
10934+ pax_open_kernel();
10935+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
10936+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
10937+ pax_close_kernel();
10938+ load_cr3(get_cpu_pgd(cpu));
10939+#else
10940 load_cr3(next->pgd);
10941+#endif
10942
10943 /* stop flush ipis for the previous mm */
10944 cpumask_clear_cpu(cpu, mm_cpumask(prev));
10945@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10946 */
10947 if (unlikely(prev->context.ldt != next->context.ldt))
10948 load_LDT_nolock(&next->context);
10949- }
10950+
10951+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10952+ if (!(__supported_pte_mask & _PAGE_NX)) {
10953+ smp_mb__before_clear_bit();
10954+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
10955+ smp_mb__after_clear_bit();
10956+ cpu_set(cpu, next->context.cpu_user_cs_mask);
10957+ }
10958+#endif
10959+
10960+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10961+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
10962+ prev->context.user_cs_limit != next->context.user_cs_limit))
10963+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10964 #ifdef CONFIG_SMP
10965+ else if (unlikely(tlbstate != TLBSTATE_OK))
10966+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10967+#endif
10968+#endif
10969+
10970+ }
10971 else {
10972+
10973+#ifdef CONFIG_PAX_PER_CPU_PGD
10974+ pax_open_kernel();
10975+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
10976+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
10977+ pax_close_kernel();
10978+ load_cr3(get_cpu_pgd(cpu));
10979+#endif
10980+
10981+#ifdef CONFIG_SMP
10982 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10983 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
10984
10985@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10986 * tlb flush IPI delivery. We must reload CR3
10987 * to make sure to use no freed page tables.
10988 */
10989+
10990+#ifndef CONFIG_PAX_PER_CPU_PGD
10991 load_cr3(next->pgd);
10992+#endif
10993+
10994 load_LDT_nolock(&next->context);
10995+
10996+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
10997+ if (!(__supported_pte_mask & _PAGE_NX))
10998+ cpu_set(cpu, next->context.cpu_user_cs_mask);
10999+#endif
11000+
11001+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11002+#ifdef CONFIG_PAX_PAGEEXEC
11003+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
11004+#endif
11005+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11006+#endif
11007+
11008 }
11009+#endif
11010 }
11011-#endif
11012 }
11013
11014 #define activate_mm(prev, next) \
11015diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
11016index 9eae775..c914fea 100644
11017--- a/arch/x86/include/asm/module.h
11018+++ b/arch/x86/include/asm/module.h
11019@@ -5,6 +5,7 @@
11020
11021 #ifdef CONFIG_X86_64
11022 /* X86_64 does not define MODULE_PROC_FAMILY */
11023+#define MODULE_PROC_FAMILY ""
11024 #elif defined CONFIG_M386
11025 #define MODULE_PROC_FAMILY "386 "
11026 #elif defined CONFIG_M486
11027@@ -59,8 +60,20 @@
11028 #error unknown processor family
11029 #endif
11030
11031-#ifdef CONFIG_X86_32
11032-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11033+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11034+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11035+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11036+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11037+#else
11038+#define MODULE_PAX_KERNEXEC ""
11039 #endif
11040
11041+#ifdef CONFIG_PAX_MEMORY_UDEREF
11042+#define MODULE_PAX_UDEREF "UDEREF "
11043+#else
11044+#define MODULE_PAX_UDEREF ""
11045+#endif
11046+
11047+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11048+
11049 #endif /* _ASM_X86_MODULE_H */
11050diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11051index 320f7bb..e89f8f8 100644
11052--- a/arch/x86/include/asm/page_64_types.h
11053+++ b/arch/x86/include/asm/page_64_types.h
11054@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11055
11056 /* duplicated to the one in bootmem.h */
11057 extern unsigned long max_pfn;
11058-extern unsigned long phys_base;
11059+extern const unsigned long phys_base;
11060
11061 extern unsigned long __phys_addr(unsigned long);
11062 #define __phys_reloc_hide(x) (x)
11063diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11064index 6cbbabf..11b3aed 100644
11065--- a/arch/x86/include/asm/paravirt.h
11066+++ b/arch/x86/include/asm/paravirt.h
11067@@ -668,6 +668,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11068 val);
11069 }
11070
11071+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11072+{
11073+ pgdval_t val = native_pgd_val(pgd);
11074+
11075+ if (sizeof(pgdval_t) > sizeof(long))
11076+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11077+ val, (u64)val >> 32);
11078+ else
11079+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11080+ val);
11081+}
11082+
11083 static inline void pgd_clear(pgd_t *pgdp)
11084 {
11085 set_pgd(pgdp, __pgd(0));
11086@@ -749,6 +761,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11087 pv_mmu_ops.set_fixmap(idx, phys, flags);
11088 }
11089
11090+#ifdef CONFIG_PAX_KERNEXEC
11091+static inline unsigned long pax_open_kernel(void)
11092+{
11093+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11094+}
11095+
11096+static inline unsigned long pax_close_kernel(void)
11097+{
11098+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11099+}
11100+#else
11101+static inline unsigned long pax_open_kernel(void) { return 0; }
11102+static inline unsigned long pax_close_kernel(void) { return 0; }
11103+#endif
11104+
11105 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11106
11107 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11108@@ -965,7 +992,7 @@ extern void default_banner(void);
11109
11110 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11111 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11112-#define PARA_INDIRECT(addr) *%cs:addr
11113+#define PARA_INDIRECT(addr) *%ss:addr
11114 #endif
11115
11116 #define INTERRUPT_RETURN \
11117@@ -1040,6 +1067,21 @@ extern void default_banner(void);
11118 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11119 CLBR_NONE, \
11120 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11121+
11122+#define GET_CR0_INTO_RDI \
11123+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11124+ mov %rax,%rdi
11125+
11126+#define SET_RDI_INTO_CR0 \
11127+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11128+
11129+#define GET_CR3_INTO_RDI \
11130+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11131+ mov %rax,%rdi
11132+
11133+#define SET_RDI_INTO_CR3 \
11134+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11135+
11136 #endif /* CONFIG_X86_32 */
11137
11138 #endif /* __ASSEMBLY__ */
11139diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11140index 8e8b9a4..f07d725 100644
11141--- a/arch/x86/include/asm/paravirt_types.h
11142+++ b/arch/x86/include/asm/paravirt_types.h
11143@@ -84,20 +84,20 @@ struct pv_init_ops {
11144 */
11145 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11146 unsigned long addr, unsigned len);
11147-};
11148+} __no_const;
11149
11150
11151 struct pv_lazy_ops {
11152 /* Set deferred update mode, used for batching operations. */
11153 void (*enter)(void);
11154 void (*leave)(void);
11155-};
11156+} __no_const;
11157
11158 struct pv_time_ops {
11159 unsigned long long (*sched_clock)(void);
11160 unsigned long long (*steal_clock)(int cpu);
11161 unsigned long (*get_tsc_khz)(void);
11162-};
11163+} __no_const;
11164
11165 struct pv_cpu_ops {
11166 /* hooks for various privileged instructions */
11167@@ -193,7 +193,7 @@ struct pv_cpu_ops {
11168
11169 void (*start_context_switch)(struct task_struct *prev);
11170 void (*end_context_switch)(struct task_struct *next);
11171-};
11172+} __no_const;
11173
11174 struct pv_irq_ops {
11175 /*
11176@@ -224,7 +224,7 @@ struct pv_apic_ops {
11177 unsigned long start_eip,
11178 unsigned long start_esp);
11179 #endif
11180-};
11181+} __no_const;
11182
11183 struct pv_mmu_ops {
11184 unsigned long (*read_cr2)(void);
11185@@ -313,6 +313,7 @@ struct pv_mmu_ops {
11186 struct paravirt_callee_save make_pud;
11187
11188 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11189+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11190 #endif /* PAGETABLE_LEVELS == 4 */
11191 #endif /* PAGETABLE_LEVELS >= 3 */
11192
11193@@ -324,6 +325,12 @@ struct pv_mmu_ops {
11194 an mfn. We can tell which is which from the index. */
11195 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11196 phys_addr_t phys, pgprot_t flags);
11197+
11198+#ifdef CONFIG_PAX_KERNEXEC
11199+ unsigned long (*pax_open_kernel)(void);
11200+ unsigned long (*pax_close_kernel)(void);
11201+#endif
11202+
11203 };
11204
11205 struct arch_spinlock;
11206@@ -334,7 +341,7 @@ struct pv_lock_ops {
11207 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11208 int (*spin_trylock)(struct arch_spinlock *lock);
11209 void (*spin_unlock)(struct arch_spinlock *lock);
11210-};
11211+} __no_const;
11212
11213 /* This contains all the paravirt structures: we get a convenient
11214 * number for each function using the offset which we use to indicate
11215diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11216index b4389a4..7024269 100644
11217--- a/arch/x86/include/asm/pgalloc.h
11218+++ b/arch/x86/include/asm/pgalloc.h
11219@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11220 pmd_t *pmd, pte_t *pte)
11221 {
11222 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11223+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11224+}
11225+
11226+static inline void pmd_populate_user(struct mm_struct *mm,
11227+ pmd_t *pmd, pte_t *pte)
11228+{
11229+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11230 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11231 }
11232
11233@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11234
11235 #ifdef CONFIG_X86_PAE
11236 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11237+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11238+{
11239+ pud_populate(mm, pudp, pmd);
11240+}
11241 #else /* !CONFIG_X86_PAE */
11242 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11243 {
11244 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11245 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11246 }
11247+
11248+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11249+{
11250+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11251+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11252+}
11253 #endif /* CONFIG_X86_PAE */
11254
11255 #if PAGETABLE_LEVELS > 3
11256@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11257 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11258 }
11259
11260+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11261+{
11262+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11263+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11264+}
11265+
11266 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11267 {
11268 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11269diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11270index 98391db..8f6984e 100644
11271--- a/arch/x86/include/asm/pgtable-2level.h
11272+++ b/arch/x86/include/asm/pgtable-2level.h
11273@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11274
11275 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11276 {
11277+ pax_open_kernel();
11278 *pmdp = pmd;
11279+ pax_close_kernel();
11280 }
11281
11282 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11283diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11284index cb00ccc..17e9054 100644
11285--- a/arch/x86/include/asm/pgtable-3level.h
11286+++ b/arch/x86/include/asm/pgtable-3level.h
11287@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11288
11289 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11290 {
11291+ pax_open_kernel();
11292 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11293+ pax_close_kernel();
11294 }
11295
11296 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11297 {
11298+ pax_open_kernel();
11299 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11300+ pax_close_kernel();
11301 }
11302
11303 /*
11304diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11305index 49afb3f..91a8c63 100644
11306--- a/arch/x86/include/asm/pgtable.h
11307+++ b/arch/x86/include/asm/pgtable.h
11308@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11309
11310 #ifndef __PAGETABLE_PUD_FOLDED
11311 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11312+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11313 #define pgd_clear(pgd) native_pgd_clear(pgd)
11314 #endif
11315
11316@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11317
11318 #define arch_end_context_switch(prev) do {} while(0)
11319
11320+#define pax_open_kernel() native_pax_open_kernel()
11321+#define pax_close_kernel() native_pax_close_kernel()
11322 #endif /* CONFIG_PARAVIRT */
11323
11324+#define __HAVE_ARCH_PAX_OPEN_KERNEL
11325+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11326+
11327+#ifdef CONFIG_PAX_KERNEXEC
11328+static inline unsigned long native_pax_open_kernel(void)
11329+{
11330+ unsigned long cr0;
11331+
11332+ preempt_disable();
11333+ barrier();
11334+ cr0 = read_cr0() ^ X86_CR0_WP;
11335+ BUG_ON(unlikely(cr0 & X86_CR0_WP));
11336+ write_cr0(cr0);
11337+ return cr0 ^ X86_CR0_WP;
11338+}
11339+
11340+static inline unsigned long native_pax_close_kernel(void)
11341+{
11342+ unsigned long cr0;
11343+
11344+ cr0 = read_cr0() ^ X86_CR0_WP;
11345+ BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11346+ write_cr0(cr0);
11347+ barrier();
11348+ preempt_enable_no_resched();
11349+ return cr0 ^ X86_CR0_WP;
11350+}
11351+#else
11352+static inline unsigned long native_pax_open_kernel(void) { return 0; }
11353+static inline unsigned long native_pax_close_kernel(void) { return 0; }
11354+#endif
11355+
11356 /*
11357 * The following only work if pte_present() is true.
11358 * Undefined behaviour if not..
11359 */
11360+static inline int pte_user(pte_t pte)
11361+{
11362+ return pte_val(pte) & _PAGE_USER;
11363+}
11364+
11365 static inline int pte_dirty(pte_t pte)
11366 {
11367 return pte_flags(pte) & _PAGE_DIRTY;
11368@@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11369 return pte_clear_flags(pte, _PAGE_RW);
11370 }
11371
11372+static inline pte_t pte_mkread(pte_t pte)
11373+{
11374+ return __pte(pte_val(pte) | _PAGE_USER);
11375+}
11376+
11377 static inline pte_t pte_mkexec(pte_t pte)
11378 {
11379- return pte_clear_flags(pte, _PAGE_NX);
11380+#ifdef CONFIG_X86_PAE
11381+ if (__supported_pte_mask & _PAGE_NX)
11382+ return pte_clear_flags(pte, _PAGE_NX);
11383+ else
11384+#endif
11385+ return pte_set_flags(pte, _PAGE_USER);
11386+}
11387+
11388+static inline pte_t pte_exprotect(pte_t pte)
11389+{
11390+#ifdef CONFIG_X86_PAE
11391+ if (__supported_pte_mask & _PAGE_NX)
11392+ return pte_set_flags(pte, _PAGE_NX);
11393+ else
11394+#endif
11395+ return pte_clear_flags(pte, _PAGE_USER);
11396 }
11397
11398 static inline pte_t pte_mkdirty(pte_t pte)
11399@@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11400 #endif
11401
11402 #ifndef __ASSEMBLY__
11403+
11404+#ifdef CONFIG_PAX_PER_CPU_PGD
11405+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11406+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11407+{
11408+ return cpu_pgd[cpu];
11409+}
11410+#endif
11411+
11412 #include <linux/mm_types.h>
11413
11414 static inline int pte_none(pte_t pte)
11415@@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11416
11417 static inline int pgd_bad(pgd_t pgd)
11418 {
11419- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11420+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11421 }
11422
11423 static inline int pgd_none(pgd_t pgd)
11424@@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
11425 * pgd_offset() returns a (pgd_t *)
11426 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11427 */
11428-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11429+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11430+
11431+#ifdef CONFIG_PAX_PER_CPU_PGD
11432+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11433+#endif
11434+
11435 /*
11436 * a shortcut which implies the use of the kernel's pgd, instead
11437 * of a process's
11438@@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
11439 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11440 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11441
11442+#ifdef CONFIG_X86_32
11443+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11444+#else
11445+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11446+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11447+
11448+#ifdef CONFIG_PAX_MEMORY_UDEREF
11449+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11450+#else
11451+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11452+#endif
11453+
11454+#endif
11455+
11456 #ifndef __ASSEMBLY__
11457
11458 extern int direct_gbpages;
11459@@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11460 * dst and src can be on the same page, but the range must not overlap,
11461 * and must not cross a page boundary.
11462 */
11463-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11464+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11465 {
11466- memcpy(dst, src, count * sizeof(pgd_t));
11467+ pax_open_kernel();
11468+ while (count--)
11469+ *dst++ = *src++;
11470+ pax_close_kernel();
11471 }
11472
11473+#ifdef CONFIG_PAX_PER_CPU_PGD
11474+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11475+#endif
11476+
11477+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11478+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11479+#else
11480+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11481+#endif
11482
11483 #include <asm-generic/pgtable.h>
11484 #endif /* __ASSEMBLY__ */
11485diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11486index 0c92113..34a77c6 100644
11487--- a/arch/x86/include/asm/pgtable_32.h
11488+++ b/arch/x86/include/asm/pgtable_32.h
11489@@ -25,9 +25,6 @@
11490 struct mm_struct;
11491 struct vm_area_struct;
11492
11493-extern pgd_t swapper_pg_dir[1024];
11494-extern pgd_t initial_page_table[1024];
11495-
11496 static inline void pgtable_cache_init(void) { }
11497 static inline void check_pgt_cache(void) { }
11498 void paging_init(void);
11499@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11500 # include <asm/pgtable-2level.h>
11501 #endif
11502
11503+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11504+extern pgd_t initial_page_table[PTRS_PER_PGD];
11505+#ifdef CONFIG_X86_PAE
11506+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11507+#endif
11508+
11509 #if defined(CONFIG_HIGHPTE)
11510 #define pte_offset_map(dir, address) \
11511 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11512@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11513 /* Clear a kernel PTE and flush it from the TLB */
11514 #define kpte_clear_flush(ptep, vaddr) \
11515 do { \
11516+ pax_open_kernel(); \
11517 pte_clear(&init_mm, (vaddr), (ptep)); \
11518+ pax_close_kernel(); \
11519 __flush_tlb_one((vaddr)); \
11520 } while (0)
11521
11522@@ -74,6 +79,9 @@ do { \
11523
11524 #endif /* !__ASSEMBLY__ */
11525
11526+#define HAVE_ARCH_UNMAPPED_AREA
11527+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11528+
11529 /*
11530 * kern_addr_valid() is (1) for FLATMEM and (0) for
11531 * SPARSEMEM and DISCONTIGMEM
11532diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11533index ed5903b..c7fe163 100644
11534--- a/arch/x86/include/asm/pgtable_32_types.h
11535+++ b/arch/x86/include/asm/pgtable_32_types.h
11536@@ -8,7 +8,7 @@
11537 */
11538 #ifdef CONFIG_X86_PAE
11539 # include <asm/pgtable-3level_types.h>
11540-# define PMD_SIZE (1UL << PMD_SHIFT)
11541+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11542 # define PMD_MASK (~(PMD_SIZE - 1))
11543 #else
11544 # include <asm/pgtable-2level_types.h>
11545@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11546 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11547 #endif
11548
11549+#ifdef CONFIG_PAX_KERNEXEC
11550+#ifndef __ASSEMBLY__
11551+extern unsigned char MODULES_EXEC_VADDR[];
11552+extern unsigned char MODULES_EXEC_END[];
11553+#endif
11554+#include <asm/boot.h>
11555+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11556+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11557+#else
11558+#define ktla_ktva(addr) (addr)
11559+#define ktva_ktla(addr) (addr)
11560+#endif
11561+
11562 #define MODULES_VADDR VMALLOC_START
11563 #define MODULES_END VMALLOC_END
11564 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11565diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11566index 975f709..9f779c9 100644
11567--- a/arch/x86/include/asm/pgtable_64.h
11568+++ b/arch/x86/include/asm/pgtable_64.h
11569@@ -16,10 +16,14 @@
11570
11571 extern pud_t level3_kernel_pgt[512];
11572 extern pud_t level3_ident_pgt[512];
11573+extern pud_t level3_vmalloc_start_pgt[512];
11574+extern pud_t level3_vmalloc_end_pgt[512];
11575+extern pud_t level3_vmemmap_pgt[512];
11576+extern pud_t level2_vmemmap_pgt[512];
11577 extern pmd_t level2_kernel_pgt[512];
11578 extern pmd_t level2_fixmap_pgt[512];
11579-extern pmd_t level2_ident_pgt[512];
11580-extern pgd_t init_level4_pgt[];
11581+extern pmd_t level2_ident_pgt[512*2];
11582+extern pgd_t init_level4_pgt[512];
11583
11584 #define swapper_pg_dir init_level4_pgt
11585
11586@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11587
11588 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11589 {
11590+ pax_open_kernel();
11591 *pmdp = pmd;
11592+ pax_close_kernel();
11593 }
11594
11595 static inline void native_pmd_clear(pmd_t *pmd)
11596@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11597
11598 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11599 {
11600+ pax_open_kernel();
11601 *pudp = pud;
11602+ pax_close_kernel();
11603 }
11604
11605 static inline void native_pud_clear(pud_t *pud)
11606@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11607
11608 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11609 {
11610+ pax_open_kernel();
11611+ *pgdp = pgd;
11612+ pax_close_kernel();
11613+}
11614+
11615+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11616+{
11617 *pgdp = pgd;
11618 }
11619
11620diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11621index 766ea16..5b96cb3 100644
11622--- a/arch/x86/include/asm/pgtable_64_types.h
11623+++ b/arch/x86/include/asm/pgtable_64_types.h
11624@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11625 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11626 #define MODULES_END _AC(0xffffffffff000000, UL)
11627 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11628+#define MODULES_EXEC_VADDR MODULES_VADDR
11629+#define MODULES_EXEC_END MODULES_END
11630+
11631+#define ktla_ktva(addr) (addr)
11632+#define ktva_ktla(addr) (addr)
11633
11634 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11635diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11636index 013286a..8b42f4f 100644
11637--- a/arch/x86/include/asm/pgtable_types.h
11638+++ b/arch/x86/include/asm/pgtable_types.h
11639@@ -16,13 +16,12 @@
11640 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11641 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11642 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11643-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11644+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11645 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11646 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11647 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11648-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11649-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11650-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11651+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11652+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11653 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11654
11655 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11656@@ -40,7 +39,6 @@
11657 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11658 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11659 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11660-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11661 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11662 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11663 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11664@@ -57,8 +55,10 @@
11665
11666 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11667 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11668-#else
11669+#elif defined(CONFIG_KMEMCHECK)
11670 #define _PAGE_NX (_AT(pteval_t, 0))
11671+#else
11672+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11673 #endif
11674
11675 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11676@@ -96,6 +96,9 @@
11677 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11678 _PAGE_ACCESSED)
11679
11680+#define PAGE_READONLY_NOEXEC PAGE_READONLY
11681+#define PAGE_SHARED_NOEXEC PAGE_SHARED
11682+
11683 #define __PAGE_KERNEL_EXEC \
11684 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11685 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11686@@ -106,7 +109,7 @@
11687 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11688 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11689 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11690-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11691+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11692 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11693 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11694 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11695@@ -168,8 +171,8 @@
11696 * bits are combined, this will alow user to access the high address mapped
11697 * VDSO in the presence of CONFIG_COMPAT_VDSO
11698 */
11699-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11700-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11701+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11702+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11703 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11704 #endif
11705
11706@@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11707 {
11708 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11709 }
11710+#endif
11711
11712+#if PAGETABLE_LEVELS == 3
11713+#include <asm-generic/pgtable-nopud.h>
11714+#endif
11715+
11716+#if PAGETABLE_LEVELS == 2
11717+#include <asm-generic/pgtable-nopmd.h>
11718+#endif
11719+
11720+#ifndef __ASSEMBLY__
11721 #if PAGETABLE_LEVELS > 3
11722 typedef struct { pudval_t pud; } pud_t;
11723
11724@@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11725 return pud.pud;
11726 }
11727 #else
11728-#include <asm-generic/pgtable-nopud.h>
11729-
11730 static inline pudval_t native_pud_val(pud_t pud)
11731 {
11732 return native_pgd_val(pud.pgd);
11733@@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11734 return pmd.pmd;
11735 }
11736 #else
11737-#include <asm-generic/pgtable-nopmd.h>
11738-
11739 static inline pmdval_t native_pmd_val(pmd_t pmd)
11740 {
11741 return native_pgd_val(pmd.pud.pgd);
11742@@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11743
11744 extern pteval_t __supported_pte_mask;
11745 extern void set_nx(void);
11746-extern int nx_enabled;
11747
11748 #define pgprot_writecombine pgprot_writecombine
11749 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11750diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11751index 39bc577..538233f 100644
11752--- a/arch/x86/include/asm/processor.h
11753+++ b/arch/x86/include/asm/processor.h
11754@@ -276,7 +276,7 @@ struct tss_struct {
11755
11756 } ____cacheline_aligned;
11757
11758-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11759+extern struct tss_struct init_tss[NR_CPUS];
11760
11761 /*
11762 * Save the original ist values for checking stack pointers during debugging
11763@@ -809,11 +809,18 @@ static inline void spin_lock_prefetch(const void *x)
11764 */
11765 #define TASK_SIZE PAGE_OFFSET
11766 #define TASK_SIZE_MAX TASK_SIZE
11767+
11768+#ifdef CONFIG_PAX_SEGMEXEC
11769+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11770+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11771+#else
11772 #define STACK_TOP TASK_SIZE
11773-#define STACK_TOP_MAX STACK_TOP
11774+#endif
11775+
11776+#define STACK_TOP_MAX TASK_SIZE
11777
11778 #define INIT_THREAD { \
11779- .sp0 = sizeof(init_stack) + (long)&init_stack, \
11780+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11781 .vm86_info = NULL, \
11782 .sysenter_cs = __KERNEL_CS, \
11783 .io_bitmap_ptr = NULL, \
11784@@ -827,7 +834,7 @@ static inline void spin_lock_prefetch(const void *x)
11785 */
11786 #define INIT_TSS { \
11787 .x86_tss = { \
11788- .sp0 = sizeof(init_stack) + (long)&init_stack, \
11789+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11790 .ss0 = __KERNEL_DS, \
11791 .ss1 = __KERNEL_CS, \
11792 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11793@@ -838,11 +845,7 @@ static inline void spin_lock_prefetch(const void *x)
11794 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11795
11796 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11797-#define KSTK_TOP(info) \
11798-({ \
11799- unsigned long *__ptr = (unsigned long *)(info); \
11800- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11801-})
11802+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11803
11804 /*
11805 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11806@@ -857,7 +860,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11807 #define task_pt_regs(task) \
11808 ({ \
11809 struct pt_regs *__regs__; \
11810- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11811+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11812 __regs__ - 1; \
11813 })
11814
11815@@ -867,13 +870,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11816 /*
11817 * User space process size. 47bits minus one guard page.
11818 */
11819-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11820+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11821
11822 /* This decides where the kernel will search for a free chunk of vm
11823 * space during mmap's.
11824 */
11825 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11826- 0xc0000000 : 0xFFFFe000)
11827+ 0xc0000000 : 0xFFFFf000)
11828
11829 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
11830 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11831@@ -884,11 +887,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11832 #define STACK_TOP_MAX TASK_SIZE_MAX
11833
11834 #define INIT_THREAD { \
11835- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11836+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11837 }
11838
11839 #define INIT_TSS { \
11840- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11841+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11842 }
11843
11844 /*
11845@@ -916,6 +919,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11846 */
11847 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11848
11849+#ifdef CONFIG_PAX_SEGMEXEC
11850+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11851+#endif
11852+
11853 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11854
11855 /* Get/set a process' ability to use the timestamp counter instruction */
11856@@ -976,12 +983,12 @@ extern bool cpu_has_amd_erratum(const int *);
11857 #define cpu_has_amd_erratum(x) (false)
11858 #endif /* CONFIG_CPU_SUP_AMD */
11859
11860-extern unsigned long arch_align_stack(unsigned long sp);
11861+#define arch_align_stack(x) ((x) & ~0xfUL)
11862 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11863
11864 void default_idle(void);
11865 bool set_pm_idle_to_default(void);
11866
11867-void stop_this_cpu(void *dummy);
11868+void stop_this_cpu(void *dummy) __noreturn;
11869
11870 #endif /* _ASM_X86_PROCESSOR_H */
11871diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11872index dcfde52..dbfea06 100644
11873--- a/arch/x86/include/asm/ptrace.h
11874+++ b/arch/x86/include/asm/ptrace.h
11875@@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11876 }
11877
11878 /*
11879- * user_mode_vm(regs) determines whether a register set came from user mode.
11880+ * user_mode(regs) determines whether a register set came from user mode.
11881 * This is true if V8086 mode was enabled OR if the register set was from
11882 * protected mode with RPL-3 CS value. This tricky test checks that with
11883 * one comparison. Many places in the kernel can bypass this full check
11884- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11885+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11886+ * be used.
11887 */
11888-static inline int user_mode(struct pt_regs *regs)
11889+static inline int user_mode_novm(struct pt_regs *regs)
11890 {
11891 #ifdef CONFIG_X86_32
11892 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11893 #else
11894- return !!(regs->cs & 3);
11895+ return !!(regs->cs & SEGMENT_RPL_MASK);
11896 #endif
11897 }
11898
11899-static inline int user_mode_vm(struct pt_regs *regs)
11900+static inline int user_mode(struct pt_regs *regs)
11901 {
11902 #ifdef CONFIG_X86_32
11903 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11904 USER_RPL;
11905 #else
11906- return user_mode(regs);
11907+ return user_mode_novm(regs);
11908 #endif
11909 }
11910
11911@@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
11912 #ifdef CONFIG_X86_64
11913 static inline bool user_64bit_mode(struct pt_regs *regs)
11914 {
11915+ unsigned long cs = regs->cs & 0xffff;
11916 #ifndef CONFIG_PARAVIRT
11917 /*
11918 * On non-paravirt systems, this is the only long mode CPL 3
11919 * selector. We do not allow long mode selectors in the LDT.
11920 */
11921- return regs->cs == __USER_CS;
11922+ return cs == __USER_CS;
11923 #else
11924 /* Headers are too twisted for this to go in paravirt.h. */
11925- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
11926+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
11927 #endif
11928 }
11929 #endif
11930diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
11931index fce3f4a..3f69f2a 100644
11932--- a/arch/x86/include/asm/realmode.h
11933+++ b/arch/x86/include/asm/realmode.h
11934@@ -30,7 +30,7 @@ struct real_mode_header {
11935 struct trampoline_header {
11936 #ifdef CONFIG_X86_32
11937 u32 start;
11938- u16 gdt_pad;
11939+ u16 boot_cs;
11940 u16 gdt_limit;
11941 u32 gdt_base;
11942 #else
11943diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
11944index 92f29706..a79cbbb 100644
11945--- a/arch/x86/include/asm/reboot.h
11946+++ b/arch/x86/include/asm/reboot.h
11947@@ -6,19 +6,19 @@
11948 struct pt_regs;
11949
11950 struct machine_ops {
11951- void (*restart)(char *cmd);
11952- void (*halt)(void);
11953- void (*power_off)(void);
11954+ void (* __noreturn restart)(char *cmd);
11955+ void (* __noreturn halt)(void);
11956+ void (* __noreturn power_off)(void);
11957 void (*shutdown)(void);
11958 void (*crash_shutdown)(struct pt_regs *);
11959- void (*emergency_restart)(void);
11960-};
11961+ void (* __noreturn emergency_restart)(void);
11962+} __no_const;
11963
11964 extern struct machine_ops machine_ops;
11965
11966 void native_machine_crash_shutdown(struct pt_regs *regs);
11967 void native_machine_shutdown(void);
11968-void machine_real_restart(unsigned int type);
11969+void machine_real_restart(unsigned int type) __noreturn;
11970 /* These must match dispatch_table in reboot_32.S */
11971 #define MRR_BIOS 0
11972 #define MRR_APM 1
11973diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
11974index 2dbe4a7..ce1db00 100644
11975--- a/arch/x86/include/asm/rwsem.h
11976+++ b/arch/x86/include/asm/rwsem.h
11977@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
11978 {
11979 asm volatile("# beginning down_read\n\t"
11980 LOCK_PREFIX _ASM_INC "(%1)\n\t"
11981+
11982+#ifdef CONFIG_PAX_REFCOUNT
11983+ "jno 0f\n"
11984+ LOCK_PREFIX _ASM_DEC "(%1)\n"
11985+ "int $4\n0:\n"
11986+ _ASM_EXTABLE(0b, 0b)
11987+#endif
11988+
11989 /* adds 0x00000001 */
11990 " jns 1f\n"
11991 " call call_rwsem_down_read_failed\n"
11992@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
11993 "1:\n\t"
11994 " mov %1,%2\n\t"
11995 " add %3,%2\n\t"
11996+
11997+#ifdef CONFIG_PAX_REFCOUNT
11998+ "jno 0f\n"
11999+ "sub %3,%2\n"
12000+ "int $4\n0:\n"
12001+ _ASM_EXTABLE(0b, 0b)
12002+#endif
12003+
12004 " jle 2f\n\t"
12005 LOCK_PREFIX " cmpxchg %2,%0\n\t"
12006 " jnz 1b\n\t"
12007@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
12008 long tmp;
12009 asm volatile("# beginning down_write\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 /* adds 0xffff0001, returns the old value */
12020 " test %1,%1\n\t"
12021 /* was the count 0 before? */
12022@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12023 long tmp;
12024 asm volatile("# beginning __up_read\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 1, returns the old value */
12035 " jns 1f\n\t"
12036 " call call_rwsem_wake\n" /* expects old value in %edx */
12037@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12038 long tmp;
12039 asm volatile("# beginning __up_write\n\t"
12040 LOCK_PREFIX " xadd %1,(%2)\n\t"
12041+
12042+#ifdef CONFIG_PAX_REFCOUNT
12043+ "jno 0f\n"
12044+ "mov %1,(%2)\n"
12045+ "int $4\n0:\n"
12046+ _ASM_EXTABLE(0b, 0b)
12047+#endif
12048+
12049 /* subtracts 0xffff0001, returns the old value */
12050 " jns 1f\n\t"
12051 " call call_rwsem_wake\n" /* expects old value in %edx */
12052@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12053 {
12054 asm volatile("# beginning __downgrade_write\n\t"
12055 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12056+
12057+#ifdef CONFIG_PAX_REFCOUNT
12058+ "jno 0f\n"
12059+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12060+ "int $4\n0:\n"
12061+ _ASM_EXTABLE(0b, 0b)
12062+#endif
12063+
12064 /*
12065 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12066 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12067@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12068 */
12069 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12070 {
12071- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12072+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12073+
12074+#ifdef CONFIG_PAX_REFCOUNT
12075+ "jno 0f\n"
12076+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
12077+ "int $4\n0:\n"
12078+ _ASM_EXTABLE(0b, 0b)
12079+#endif
12080+
12081 : "+m" (sem->count)
12082 : "er" (delta));
12083 }
12084@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12085 */
12086 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12087 {
12088- return delta + xadd(&sem->count, delta);
12089+ return delta + xadd_check_overflow(&sem->count, delta);
12090 }
12091
12092 #endif /* __KERNEL__ */
12093diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12094index c48a950..c6d7468 100644
12095--- a/arch/x86/include/asm/segment.h
12096+++ b/arch/x86/include/asm/segment.h
12097@@ -64,10 +64,15 @@
12098 * 26 - ESPFIX small SS
12099 * 27 - per-cpu [ offset to per-cpu data area ]
12100 * 28 - stack_canary-20 [ for stack protector ]
12101- * 29 - unused
12102- * 30 - unused
12103+ * 29 - PCI BIOS CS
12104+ * 30 - PCI BIOS DS
12105 * 31 - TSS for double fault handler
12106 */
12107+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12108+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12109+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12110+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12111+
12112 #define GDT_ENTRY_TLS_MIN 6
12113 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12114
12115@@ -79,6 +84,8 @@
12116
12117 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12118
12119+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12120+
12121 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12122
12123 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12124@@ -104,6 +111,12 @@
12125 #define __KERNEL_STACK_CANARY 0
12126 #endif
12127
12128+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12129+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12130+
12131+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12132+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12133+
12134 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12135
12136 /*
12137@@ -141,7 +154,7 @@
12138 */
12139
12140 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12141-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12142+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12143
12144
12145 #else
12146@@ -165,6 +178,8 @@
12147 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12148 #define __USER32_DS __USER_DS
12149
12150+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12151+
12152 #define GDT_ENTRY_TSS 8 /* needs two entries */
12153 #define GDT_ENTRY_LDT 10 /* needs two entries */
12154 #define GDT_ENTRY_TLS_MIN 12
12155@@ -185,6 +200,7 @@
12156 #endif
12157
12158 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12159+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12160 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12161 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12162 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12163@@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
12164 {
12165 unsigned long __limit;
12166 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12167- return __limit + 1;
12168+ return __limit;
12169 }
12170
12171 #endif /* !__ASSEMBLY__ */
12172diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12173index f483945..64a7851 100644
12174--- a/arch/x86/include/asm/smp.h
12175+++ b/arch/x86/include/asm/smp.h
12176@@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
12177 /* cpus sharing the last level cache: */
12178 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
12179 DECLARE_PER_CPU(u16, cpu_llc_id);
12180-DECLARE_PER_CPU(int, cpu_number);
12181+DECLARE_PER_CPU(unsigned int, cpu_number);
12182
12183 static inline struct cpumask *cpu_sibling_mask(int cpu)
12184 {
12185@@ -79,7 +79,7 @@ struct smp_ops {
12186
12187 void (*send_call_func_ipi)(const struct cpumask *mask);
12188 void (*send_call_func_single_ipi)(int cpu);
12189-};
12190+} __no_const;
12191
12192 /* Globals due to paravirt */
12193 extern void set_cpu_sibling_map(int cpu);
12194@@ -195,14 +195,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12195 extern int safe_smp_processor_id(void);
12196
12197 #elif defined(CONFIG_X86_64_SMP)
12198-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12199-
12200-#define stack_smp_processor_id() \
12201-({ \
12202- struct thread_info *ti; \
12203- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12204- ti->cpu; \
12205-})
12206+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12207+#define stack_smp_processor_id() raw_smp_processor_id()
12208 #define safe_smp_processor_id() smp_processor_id()
12209
12210 #endif
12211diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12212index b315a33..8849ab0 100644
12213--- a/arch/x86/include/asm/spinlock.h
12214+++ b/arch/x86/include/asm/spinlock.h
12215@@ -173,6 +173,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12216 static inline void arch_read_lock(arch_rwlock_t *rw)
12217 {
12218 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12219+
12220+#ifdef CONFIG_PAX_REFCOUNT
12221+ "jno 0f\n"
12222+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12223+ "int $4\n0:\n"
12224+ _ASM_EXTABLE(0b, 0b)
12225+#endif
12226+
12227 "jns 1f\n"
12228 "call __read_lock_failed\n\t"
12229 "1:\n"
12230@@ -182,6 +190,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12231 static inline void arch_write_lock(arch_rwlock_t *rw)
12232 {
12233 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12234+
12235+#ifdef CONFIG_PAX_REFCOUNT
12236+ "jno 0f\n"
12237+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12238+ "int $4\n0:\n"
12239+ _ASM_EXTABLE(0b, 0b)
12240+#endif
12241+
12242 "jz 1f\n"
12243 "call __write_lock_failed\n\t"
12244 "1:\n"
12245@@ -211,13 +227,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12246
12247 static inline void arch_read_unlock(arch_rwlock_t *rw)
12248 {
12249- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12250+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12251+
12252+#ifdef CONFIG_PAX_REFCOUNT
12253+ "jno 0f\n"
12254+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12255+ "int $4\n0:\n"
12256+ _ASM_EXTABLE(0b, 0b)
12257+#endif
12258+
12259 :"+m" (rw->lock) : : "memory");
12260 }
12261
12262 static inline void arch_write_unlock(arch_rwlock_t *rw)
12263 {
12264- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12265+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12266+
12267+#ifdef CONFIG_PAX_REFCOUNT
12268+ "jno 0f\n"
12269+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12270+ "int $4\n0:\n"
12271+ _ASM_EXTABLE(0b, 0b)
12272+#endif
12273+
12274 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12275 }
12276
12277diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12278index 6a99859..03cb807 100644
12279--- a/arch/x86/include/asm/stackprotector.h
12280+++ b/arch/x86/include/asm/stackprotector.h
12281@@ -47,7 +47,7 @@
12282 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12283 */
12284 #define GDT_STACK_CANARY_INIT \
12285- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12286+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12287
12288 /*
12289 * Initialize the stackprotector canary value.
12290@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
12291
12292 static inline void load_stack_canary_segment(void)
12293 {
12294-#ifdef CONFIG_X86_32
12295+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12296 asm volatile ("mov %0, %%gs" : : "r" (0));
12297 #endif
12298 }
12299diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12300index 70bbe39..4ae2bd4 100644
12301--- a/arch/x86/include/asm/stacktrace.h
12302+++ b/arch/x86/include/asm/stacktrace.h
12303@@ -11,28 +11,20 @@
12304
12305 extern int kstack_depth_to_print;
12306
12307-struct thread_info;
12308+struct task_struct;
12309 struct stacktrace_ops;
12310
12311-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12312- unsigned long *stack,
12313- unsigned long bp,
12314- const struct stacktrace_ops *ops,
12315- void *data,
12316- unsigned long *end,
12317- int *graph);
12318+typedef unsigned long walk_stack_t(struct task_struct *task,
12319+ void *stack_start,
12320+ unsigned long *stack,
12321+ unsigned long bp,
12322+ const struct stacktrace_ops *ops,
12323+ void *data,
12324+ unsigned long *end,
12325+ int *graph);
12326
12327-extern unsigned long
12328-print_context_stack(struct thread_info *tinfo,
12329- unsigned long *stack, unsigned long bp,
12330- const struct stacktrace_ops *ops, void *data,
12331- unsigned long *end, int *graph);
12332-
12333-extern unsigned long
12334-print_context_stack_bp(struct thread_info *tinfo,
12335- unsigned long *stack, unsigned long bp,
12336- const struct stacktrace_ops *ops, void *data,
12337- unsigned long *end, int *graph);
12338+extern walk_stack_t print_context_stack;
12339+extern walk_stack_t print_context_stack_bp;
12340
12341 /* Generic stack tracer with callbacks */
12342
12343@@ -40,7 +32,7 @@ struct stacktrace_ops {
12344 void (*address)(void *data, unsigned long address, int reliable);
12345 /* On negative return stop dumping */
12346 int (*stack)(void *data, char *name);
12347- walk_stack_t walk_stack;
12348+ walk_stack_t *walk_stack;
12349 };
12350
12351 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12352diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
12353index 4ec45b3..a4f0a8a 100644
12354--- a/arch/x86/include/asm/switch_to.h
12355+++ b/arch/x86/include/asm/switch_to.h
12356@@ -108,7 +108,7 @@ do { \
12357 "call __switch_to\n\t" \
12358 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12359 __switch_canary \
12360- "movq %P[thread_info](%%rsi),%%r8\n\t" \
12361+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12362 "movq %%rax,%%rdi\n\t" \
12363 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12364 "jnz ret_from_fork\n\t" \
12365@@ -119,7 +119,7 @@ do { \
12366 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12367 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12368 [_tif_fork] "i" (_TIF_FORK), \
12369- [thread_info] "i" (offsetof(struct task_struct, stack)), \
12370+ [thread_info] "m" (current_tinfo), \
12371 [current_task] "m" (current_task) \
12372 __switch_canary_iparam \
12373 : "memory", "cc" __EXTRA_CLOBBER)
12374diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12375index 3fda9db4..4ca1c61 100644
12376--- a/arch/x86/include/asm/sys_ia32.h
12377+++ b/arch/x86/include/asm/sys_ia32.h
12378@@ -40,7 +40,7 @@ asmlinkage long sys32_sigaction(int, struct old_sigaction32 __user *,
12379 struct old_sigaction32 __user *);
12380 asmlinkage long sys32_alarm(unsigned int);
12381
12382-asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12383+asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12384 asmlinkage long sys32_sysfs(int, u32, u32);
12385
12386 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12387diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12388index 89f794f..1422765 100644
12389--- a/arch/x86/include/asm/thread_info.h
12390+++ b/arch/x86/include/asm/thread_info.h
12391@@ -10,6 +10,7 @@
12392 #include <linux/compiler.h>
12393 #include <asm/page.h>
12394 #include <asm/types.h>
12395+#include <asm/percpu.h>
12396
12397 /*
12398 * low level task data that entry.S needs immediate access to
12399@@ -24,7 +25,6 @@ struct exec_domain;
12400 #include <linux/atomic.h>
12401
12402 struct thread_info {
12403- struct task_struct *task; /* main task structure */
12404 struct exec_domain *exec_domain; /* execution domain */
12405 __u32 flags; /* low level flags */
12406 __u32 status; /* thread synchronous flags */
12407@@ -34,19 +34,13 @@ struct thread_info {
12408 mm_segment_t addr_limit;
12409 struct restart_block restart_block;
12410 void __user *sysenter_return;
12411-#ifdef CONFIG_X86_32
12412- unsigned long previous_esp; /* ESP of the previous stack in
12413- case of nested (IRQ) stacks
12414- */
12415- __u8 supervisor_stack[0];
12416-#endif
12417+ unsigned long lowest_stack;
12418 unsigned int sig_on_uaccess_error:1;
12419 unsigned int uaccess_err:1; /* uaccess failed */
12420 };
12421
12422-#define INIT_THREAD_INFO(tsk) \
12423+#define INIT_THREAD_INFO \
12424 { \
12425- .task = &tsk, \
12426 .exec_domain = &default_exec_domain, \
12427 .flags = 0, \
12428 .cpu = 0, \
12429@@ -57,7 +51,7 @@ struct thread_info {
12430 }, \
12431 }
12432
12433-#define init_thread_info (init_thread_union.thread_info)
12434+#define init_thread_info (init_thread_union.stack)
12435 #define init_stack (init_thread_union.stack)
12436
12437 #else /* !__ASSEMBLY__ */
12438@@ -98,6 +92,7 @@ struct thread_info {
12439 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12440 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
12441 #define TIF_X32 30 /* 32-bit native x86-64 binary */
12442+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
12443
12444 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12445 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12446@@ -122,16 +117,18 @@ struct thread_info {
12447 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12448 #define _TIF_ADDR32 (1 << TIF_ADDR32)
12449 #define _TIF_X32 (1 << TIF_X32)
12450+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12451
12452 /* work to do in syscall_trace_enter() */
12453 #define _TIF_WORK_SYSCALL_ENTRY \
12454 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12455- _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12456+ _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
12457+ _TIF_GRSEC_SETXID)
12458
12459 /* work to do in syscall_trace_leave() */
12460 #define _TIF_WORK_SYSCALL_EXIT \
12461 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12462- _TIF_SYSCALL_TRACEPOINT)
12463+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12464
12465 /* work to do on interrupt/exception return */
12466 #define _TIF_WORK_MASK \
12467@@ -141,7 +138,8 @@ struct thread_info {
12468
12469 /* work to do on any return to user space */
12470 #define _TIF_ALLWORK_MASK \
12471- ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12472+ ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12473+ _TIF_GRSEC_SETXID)
12474
12475 /* Only used for 64 bit */
12476 #define _TIF_DO_NOTIFY_MASK \
12477@@ -157,45 +155,40 @@ struct thread_info {
12478
12479 #define PREEMPT_ACTIVE 0x10000000
12480
12481-#ifdef CONFIG_X86_32
12482-
12483-#define STACK_WARN (THREAD_SIZE/8)
12484-/*
12485- * macros/functions for gaining access to the thread information structure
12486- *
12487- * preempt_count needs to be 1 initially, until the scheduler is functional.
12488- */
12489-#ifndef __ASSEMBLY__
12490-
12491-
12492-/* how to get the current stack pointer from C */
12493-register unsigned long current_stack_pointer asm("esp") __used;
12494-
12495-/* how to get the thread information struct from C */
12496-static inline struct thread_info *current_thread_info(void)
12497-{
12498- return (struct thread_info *)
12499- (current_stack_pointer & ~(THREAD_SIZE - 1));
12500-}
12501-
12502-#else /* !__ASSEMBLY__ */
12503-
12504+#ifdef __ASSEMBLY__
12505 /* how to get the thread information struct from ASM */
12506 #define GET_THREAD_INFO(reg) \
12507- movl $-THREAD_SIZE, reg; \
12508- andl %esp, reg
12509+ mov PER_CPU_VAR(current_tinfo), reg
12510
12511 /* use this one if reg already contains %esp */
12512-#define GET_THREAD_INFO_WITH_ESP(reg) \
12513- andl $-THREAD_SIZE, reg
12514+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12515+#else
12516+/* how to get the thread information struct from C */
12517+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12518+
12519+static __always_inline struct thread_info *current_thread_info(void)
12520+{
12521+ return this_cpu_read_stable(current_tinfo);
12522+}
12523+#endif
12524+
12525+#ifdef CONFIG_X86_32
12526+
12527+#define STACK_WARN (THREAD_SIZE/8)
12528+/*
12529+ * macros/functions for gaining access to the thread information structure
12530+ *
12531+ * preempt_count needs to be 1 initially, until the scheduler is functional.
12532+ */
12533+#ifndef __ASSEMBLY__
12534+
12535+/* how to get the current stack pointer from C */
12536+register unsigned long current_stack_pointer asm("esp") __used;
12537
12538 #endif
12539
12540 #else /* X86_32 */
12541
12542-#include <asm/percpu.h>
12543-#define KERNEL_STACK_OFFSET (5*8)
12544-
12545 /*
12546 * macros/functions for gaining access to the thread information structure
12547 * preempt_count needs to be 1 initially, until the scheduler is functional.
12548@@ -203,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
12549 #ifndef __ASSEMBLY__
12550 DECLARE_PER_CPU(unsigned long, kernel_stack);
12551
12552-static inline struct thread_info *current_thread_info(void)
12553-{
12554- struct thread_info *ti;
12555- ti = (void *)(this_cpu_read_stable(kernel_stack) +
12556- KERNEL_STACK_OFFSET - THREAD_SIZE);
12557- return ti;
12558-}
12559-
12560-#else /* !__ASSEMBLY__ */
12561-
12562-/* how to get the thread information struct from ASM */
12563-#define GET_THREAD_INFO(reg) \
12564- movq PER_CPU_VAR(kernel_stack),reg ; \
12565- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12566-
12567-/*
12568- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12569- * a certain register (to be used in assembler memory operands).
12570- */
12571-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12572-
12573+/* how to get the current stack pointer from C */
12574+register unsigned long current_stack_pointer asm("rsp") __used;
12575 #endif
12576
12577 #endif /* !X86_32 */
12578@@ -284,5 +258,12 @@ static inline bool is_ia32_task(void)
12579 extern void arch_task_cache_init(void);
12580 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12581 extern void arch_release_task_struct(struct task_struct *tsk);
12582+
12583+#define __HAVE_THREAD_FUNCTIONS
12584+#define task_thread_info(task) (&(task)->tinfo)
12585+#define task_stack_page(task) ((task)->stack)
12586+#define setup_thread_stack(p, org) do {} while (0)
12587+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12588+
12589 #endif
12590 #endif /* _ASM_X86_THREAD_INFO_H */
12591diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12592index e1f3a17..1ab364d 100644
12593--- a/arch/x86/include/asm/uaccess.h
12594+++ b/arch/x86/include/asm/uaccess.h
12595@@ -7,12 +7,15 @@
12596 #include <linux/compiler.h>
12597 #include <linux/thread_info.h>
12598 #include <linux/string.h>
12599+#include <linux/sched.h>
12600 #include <asm/asm.h>
12601 #include <asm/page.h>
12602
12603 #define VERIFY_READ 0
12604 #define VERIFY_WRITE 1
12605
12606+extern void check_object_size(const void *ptr, unsigned long n, bool to);
12607+
12608 /*
12609 * The fs value determines whether argument validity checking should be
12610 * performed or not. If get_fs() == USER_DS, checking is performed, with
12611@@ -28,7 +31,12 @@
12612
12613 #define get_ds() (KERNEL_DS)
12614 #define get_fs() (current_thread_info()->addr_limit)
12615+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12616+void __set_fs(mm_segment_t x);
12617+void set_fs(mm_segment_t x);
12618+#else
12619 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12620+#endif
12621
12622 #define segment_eq(a, b) ((a).seg == (b).seg)
12623
12624@@ -76,8 +84,33 @@
12625 * checks that the pointer is in the user space range - after calling
12626 * this function, memory access functions may still return -EFAULT.
12627 */
12628-#define access_ok(type, addr, size) \
12629- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12630+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12631+#define access_ok(type, addr, size) \
12632+({ \
12633+ long __size = size; \
12634+ unsigned long __addr = (unsigned long)addr; \
12635+ unsigned long __addr_ao = __addr & PAGE_MASK; \
12636+ unsigned long __end_ao = __addr + __size - 1; \
12637+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
12638+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12639+ while(__addr_ao <= __end_ao) { \
12640+ char __c_ao; \
12641+ __addr_ao += PAGE_SIZE; \
12642+ if (__size > PAGE_SIZE) \
12643+ cond_resched(); \
12644+ if (__get_user(__c_ao, (char __user *)__addr)) \
12645+ break; \
12646+ if (type != VERIFY_WRITE) { \
12647+ __addr = __addr_ao; \
12648+ continue; \
12649+ } \
12650+ if (__put_user(__c_ao, (char __user *)__addr)) \
12651+ break; \
12652+ __addr = __addr_ao; \
12653+ } \
12654+ } \
12655+ __ret_ao; \
12656+})
12657
12658 /*
12659 * The exception table consists of pairs of addresses relative to the
12660@@ -188,12 +221,20 @@ extern int __get_user_bad(void);
12661 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12662 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12663
12664-
12665+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12666+#define __copyuser_seg "gs;"
12667+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12668+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12669+#else
12670+#define __copyuser_seg
12671+#define __COPYUSER_SET_ES
12672+#define __COPYUSER_RESTORE_ES
12673+#endif
12674
12675 #ifdef CONFIG_X86_32
12676 #define __put_user_asm_u64(x, addr, err, errret) \
12677- asm volatile("1: movl %%eax,0(%2)\n" \
12678- "2: movl %%edx,4(%2)\n" \
12679+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12680+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12681 "3:\n" \
12682 ".section .fixup,\"ax\"\n" \
12683 "4: movl %3,%0\n" \
12684@@ -205,8 +246,8 @@ extern int __get_user_bad(void);
12685 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12686
12687 #define __put_user_asm_ex_u64(x, addr) \
12688- asm volatile("1: movl %%eax,0(%1)\n" \
12689- "2: movl %%edx,4(%1)\n" \
12690+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12691+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12692 "3:\n" \
12693 _ASM_EXTABLE_EX(1b, 2b) \
12694 _ASM_EXTABLE_EX(2b, 3b) \
12695@@ -258,7 +299,7 @@ extern void __put_user_8(void);
12696 __typeof__(*(ptr)) __pu_val; \
12697 __chk_user_ptr(ptr); \
12698 might_fault(); \
12699- __pu_val = x; \
12700+ __pu_val = (x); \
12701 switch (sizeof(*(ptr))) { \
12702 case 1: \
12703 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12704@@ -379,7 +420,7 @@ do { \
12705 } while (0)
12706
12707 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12708- asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12709+ asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12710 "2:\n" \
12711 ".section .fixup,\"ax\"\n" \
12712 "3: mov %3,%0\n" \
12713@@ -387,7 +428,7 @@ do { \
12714 " jmp 2b\n" \
12715 ".previous\n" \
12716 _ASM_EXTABLE(1b, 3b) \
12717- : "=r" (err), ltype(x) \
12718+ : "=r" (err), ltype (x) \
12719 : "m" (__m(addr)), "i" (errret), "0" (err))
12720
12721 #define __get_user_size_ex(x, ptr, size) \
12722@@ -412,7 +453,7 @@ do { \
12723 } while (0)
12724
12725 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12726- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12727+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12728 "2:\n" \
12729 _ASM_EXTABLE_EX(1b, 2b) \
12730 : ltype(x) : "m" (__m(addr)))
12731@@ -429,13 +470,24 @@ do { \
12732 int __gu_err; \
12733 unsigned long __gu_val; \
12734 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12735- (x) = (__force __typeof__(*(ptr)))__gu_val; \
12736+ (x) = (__typeof__(*(ptr)))__gu_val; \
12737 __gu_err; \
12738 })
12739
12740 /* FIXME: this hack is definitely wrong -AK */
12741 struct __large_struct { unsigned long buf[100]; };
12742-#define __m(x) (*(struct __large_struct __user *)(x))
12743+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12744+#define ____m(x) \
12745+({ \
12746+ unsigned long ____x = (unsigned long)(x); \
12747+ if (____x < PAX_USER_SHADOW_BASE) \
12748+ ____x += PAX_USER_SHADOW_BASE; \
12749+ (void __user *)____x; \
12750+})
12751+#else
12752+#define ____m(x) (x)
12753+#endif
12754+#define __m(x) (*(struct __large_struct __user *)____m(x))
12755
12756 /*
12757 * Tell gcc we read from memory instead of writing: this is because
12758@@ -443,7 +495,7 @@ struct __large_struct { unsigned long buf[100]; };
12759 * aliasing issues.
12760 */
12761 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12762- asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12763+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12764 "2:\n" \
12765 ".section .fixup,\"ax\"\n" \
12766 "3: mov %3,%0\n" \
12767@@ -451,10 +503,10 @@ struct __large_struct { unsigned long buf[100]; };
12768 ".previous\n" \
12769 _ASM_EXTABLE(1b, 3b) \
12770 : "=r"(err) \
12771- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12772+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12773
12774 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12775- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12776+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12777 "2:\n" \
12778 _ASM_EXTABLE_EX(1b, 2b) \
12779 : : ltype(x), "m" (__m(addr)))
12780@@ -493,8 +545,12 @@ struct __large_struct { unsigned long buf[100]; };
12781 * On error, the variable @x is set to zero.
12782 */
12783
12784+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12785+#define __get_user(x, ptr) get_user((x), (ptr))
12786+#else
12787 #define __get_user(x, ptr) \
12788 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12789+#endif
12790
12791 /**
12792 * __put_user: - Write a simple value into user space, with less checking.
12793@@ -516,8 +572,12 @@ struct __large_struct { unsigned long buf[100]; };
12794 * Returns zero on success, or -EFAULT on error.
12795 */
12796
12797+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12798+#define __put_user(x, ptr) put_user((x), (ptr))
12799+#else
12800 #define __put_user(x, ptr) \
12801 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12802+#endif
12803
12804 #define __get_user_unaligned __get_user
12805 #define __put_user_unaligned __put_user
12806@@ -535,7 +595,7 @@ struct __large_struct { unsigned long buf[100]; };
12807 #define get_user_ex(x, ptr) do { \
12808 unsigned long __gue_val; \
12809 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12810- (x) = (__force __typeof__(*(ptr)))__gue_val; \
12811+ (x) = (__typeof__(*(ptr)))__gue_val; \
12812 } while (0)
12813
12814 #ifdef CONFIG_X86_WP_WORKS_OK
12815diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12816index 576e39b..ccd0a39 100644
12817--- a/arch/x86/include/asm/uaccess_32.h
12818+++ b/arch/x86/include/asm/uaccess_32.h
12819@@ -11,15 +11,15 @@
12820 #include <asm/page.h>
12821
12822 unsigned long __must_check __copy_to_user_ll
12823- (void __user *to, const void *from, unsigned long n);
12824+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12825 unsigned long __must_check __copy_from_user_ll
12826- (void *to, const void __user *from, unsigned long n);
12827+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12828 unsigned long __must_check __copy_from_user_ll_nozero
12829- (void *to, const void __user *from, unsigned long n);
12830+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12831 unsigned long __must_check __copy_from_user_ll_nocache
12832- (void *to, const void __user *from, unsigned long n);
12833+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12834 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12835- (void *to, const void __user *from, unsigned long n);
12836+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12837
12838 /**
12839 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12840@@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12841 static __always_inline unsigned long __must_check
12842 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12843 {
12844+ if ((long)n < 0)
12845+ return n;
12846+
12847 if (__builtin_constant_p(n)) {
12848 unsigned long ret;
12849
12850@@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12851 return ret;
12852 }
12853 }
12854+ if (!__builtin_constant_p(n))
12855+ check_object_size(from, n, true);
12856 return __copy_to_user_ll(to, from, n);
12857 }
12858
12859@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
12860 __copy_to_user(void __user *to, const void *from, unsigned long n)
12861 {
12862 might_fault();
12863+
12864 return __copy_to_user_inatomic(to, from, n);
12865 }
12866
12867 static __always_inline unsigned long
12868 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12869 {
12870+ if ((long)n < 0)
12871+ return n;
12872+
12873 /* Avoid zeroing the tail if the copy fails..
12874 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12875 * but as the zeroing behaviour is only significant when n is not
12876@@ -137,6 +146,10 @@ static __always_inline unsigned long
12877 __copy_from_user(void *to, const void __user *from, unsigned long n)
12878 {
12879 might_fault();
12880+
12881+ if ((long)n < 0)
12882+ return n;
12883+
12884 if (__builtin_constant_p(n)) {
12885 unsigned long ret;
12886
12887@@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12888 return ret;
12889 }
12890 }
12891+ if (!__builtin_constant_p(n))
12892+ check_object_size(to, n, false);
12893 return __copy_from_user_ll(to, from, n);
12894 }
12895
12896@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12897 const void __user *from, unsigned long n)
12898 {
12899 might_fault();
12900+
12901+ if ((long)n < 0)
12902+ return n;
12903+
12904 if (__builtin_constant_p(n)) {
12905 unsigned long ret;
12906
12907@@ -181,15 +200,19 @@ static __always_inline unsigned long
12908 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
12909 unsigned long n)
12910 {
12911- return __copy_from_user_ll_nocache_nozero(to, from, n);
12912+ if ((long)n < 0)
12913+ return n;
12914+
12915+ return __copy_from_user_ll_nocache_nozero(to, from, n);
12916 }
12917
12918-unsigned long __must_check copy_to_user(void __user *to,
12919- const void *from, unsigned long n);
12920-unsigned long __must_check _copy_from_user(void *to,
12921- const void __user *from,
12922- unsigned long n);
12923-
12924+extern void copy_to_user_overflow(void)
12925+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12926+ __compiletime_error("copy_to_user() buffer size is not provably correct")
12927+#else
12928+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
12929+#endif
12930+;
12931
12932 extern void copy_from_user_overflow(void)
12933 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12934@@ -199,21 +222,65 @@ extern void copy_from_user_overflow(void)
12935 #endif
12936 ;
12937
12938-static inline unsigned long __must_check copy_from_user(void *to,
12939- const void __user *from,
12940- unsigned long n)
12941+/**
12942+ * copy_to_user: - Copy a block of data into user space.
12943+ * @to: Destination address, in user space.
12944+ * @from: Source address, in kernel space.
12945+ * @n: Number of bytes to copy.
12946+ *
12947+ * Context: User context only. This function may sleep.
12948+ *
12949+ * Copy data from kernel space to user space.
12950+ *
12951+ * Returns number of bytes that could not be copied.
12952+ * On success, this will be zero.
12953+ */
12954+static inline unsigned long __must_check
12955+copy_to_user(void __user *to, const void *from, unsigned long n)
12956 {
12957- int sz = __compiletime_object_size(to);
12958+ size_t sz = __compiletime_object_size(from);
12959
12960- if (likely(sz == -1 || sz >= n))
12961- n = _copy_from_user(to, from, n);
12962- else
12963+ if (unlikely(sz != (size_t)-1 && sz < n))
12964+ copy_to_user_overflow();
12965+ else if (access_ok(VERIFY_WRITE, to, n))
12966+ n = __copy_to_user(to, from, n);
12967+ return n;
12968+}
12969+
12970+/**
12971+ * copy_from_user: - Copy a block of data from user space.
12972+ * @to: Destination address, in kernel space.
12973+ * @from: Source address, in user space.
12974+ * @n: Number of bytes to copy.
12975+ *
12976+ * Context: User context only. This function may sleep.
12977+ *
12978+ * Copy data from user space to kernel space.
12979+ *
12980+ * Returns number of bytes that could not be copied.
12981+ * On success, this will be zero.
12982+ *
12983+ * If some data could not be copied, this function will pad the copied
12984+ * data to the requested size using zero bytes.
12985+ */
12986+static inline unsigned long __must_check
12987+copy_from_user(void *to, const void __user *from, unsigned long n)
12988+{
12989+ size_t sz = __compiletime_object_size(to);
12990+
12991+ if (unlikely(sz != (size_t)-1 && sz < n))
12992 copy_from_user_overflow();
12993-
12994+ else if (access_ok(VERIFY_READ, from, n))
12995+ n = __copy_from_user(to, from, n);
12996+ else if ((long)n > 0) {
12997+ if (!__builtin_constant_p(n))
12998+ check_object_size(to, n, false);
12999+ memset(to, 0, n);
13000+ }
13001 return n;
13002 }
13003
13004-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
13005-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
13006+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13007+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13008
13009 #endif /* _ASM_X86_UACCESS_32_H */
13010diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
13011index 8e796fb..72fd934 100644
13012--- a/arch/x86/include/asm/uaccess_64.h
13013+++ b/arch/x86/include/asm/uaccess_64.h
13014@@ -10,6 +10,9 @@
13015 #include <asm/alternative.h>
13016 #include <asm/cpufeature.h>
13017 #include <asm/page.h>
13018+#include <asm/pgtable.h>
13019+
13020+#define set_fs(x) (current_thread_info()->addr_limit = (x))
13021
13022 /*
13023 * Copy To/From Userspace
13024@@ -17,12 +20,14 @@
13025
13026 /* Handles exceptions in both to and from, but doesn't do access_ok */
13027 __must_check unsigned long
13028-copy_user_generic_string(void *to, const void *from, unsigned len);
13029+copy_user_generic_string(void *to, const void *from, unsigned long len) __size_overflow(3);
13030 __must_check unsigned long
13031-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13032+copy_user_generic_unrolled(void *to, const void *from, unsigned long len) __size_overflow(3);
13033
13034 static __always_inline __must_check unsigned long
13035-copy_user_generic(void *to, const void *from, unsigned len)
13036+copy_user_generic(void *to, const void *from, unsigned long len) __size_overflow(3);
13037+static __always_inline __must_check unsigned long
13038+copy_user_generic(void *to, const void *from, unsigned long len)
13039 {
13040 unsigned ret;
13041
13042@@ -32,142 +37,238 @@ copy_user_generic(void *to, const void *from, unsigned len)
13043 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13044 "=d" (len)),
13045 "1" (to), "2" (from), "3" (len)
13046- : "memory", "rcx", "r8", "r9", "r10", "r11");
13047+ : "memory", "rcx", "r8", "r9", "r11");
13048 return ret;
13049 }
13050
13051+static __always_inline __must_check unsigned long
13052+__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13053+static __always_inline __must_check unsigned long
13054+__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13055 __must_check unsigned long
13056-_copy_to_user(void __user *to, const void *from, unsigned len);
13057-__must_check unsigned long
13058-_copy_from_user(void *to, const void __user *from, unsigned len);
13059-__must_check unsigned long
13060-copy_in_user(void __user *to, const void __user *from, unsigned len);
13061+copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13062+
13063+extern void copy_to_user_overflow(void)
13064+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13065+ __compiletime_error("copy_to_user() buffer size is not provably correct")
13066+#else
13067+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
13068+#endif
13069+;
13070+
13071+extern void copy_from_user_overflow(void)
13072+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13073+ __compiletime_error("copy_from_user() buffer size is not provably correct")
13074+#else
13075+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
13076+#endif
13077+;
13078
13079 static inline unsigned long __must_check copy_from_user(void *to,
13080 const void __user *from,
13081 unsigned long n)
13082 {
13083- int sz = __compiletime_object_size(to);
13084-
13085 might_fault();
13086- if (likely(sz == -1 || sz >= n))
13087- n = _copy_from_user(to, from, n);
13088-#ifdef CONFIG_DEBUG_VM
13089- else
13090- WARN(1, "Buffer overflow detected!\n");
13091-#endif
13092+
13093+ if (access_ok(VERIFY_READ, from, n))
13094+ n = __copy_from_user(to, from, n);
13095+ else if (n < INT_MAX) {
13096+ if (!__builtin_constant_p(n))
13097+ check_object_size(to, n, false);
13098+ memset(to, 0, n);
13099+ }
13100 return n;
13101 }
13102
13103 static __always_inline __must_check
13104-int copy_to_user(void __user *dst, const void *src, unsigned size)
13105+int copy_to_user(void __user *dst, const void *src, unsigned long size)
13106 {
13107 might_fault();
13108
13109- return _copy_to_user(dst, src, size);
13110+ if (access_ok(VERIFY_WRITE, dst, size))
13111+ size = __copy_to_user(dst, src, size);
13112+ return size;
13113 }
13114
13115 static __always_inline __must_check
13116-int __copy_from_user(void *dst, const void __user *src, unsigned size)
13117+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13118 {
13119- int ret = 0;
13120+ size_t sz = __compiletime_object_size(dst);
13121+ unsigned ret = 0;
13122
13123 might_fault();
13124- if (!__builtin_constant_p(size))
13125- return copy_user_generic(dst, (__force void *)src, size);
13126+
13127+ if (size > INT_MAX)
13128+ return size;
13129+
13130+#ifdef CONFIG_PAX_MEMORY_UDEREF
13131+ if (!__access_ok(VERIFY_READ, src, size))
13132+ return size;
13133+#endif
13134+
13135+ if (unlikely(sz != (size_t)-1 && sz < size)) {
13136+ copy_from_user_overflow();
13137+ return size;
13138+ }
13139+
13140+ if (!__builtin_constant_p(size)) {
13141+ check_object_size(dst, size, false);
13142+
13143+#ifdef CONFIG_PAX_MEMORY_UDEREF
13144+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13145+ src += PAX_USER_SHADOW_BASE;
13146+#endif
13147+
13148+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13149+ }
13150 switch (size) {
13151- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13152+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13153 ret, "b", "b", "=q", 1);
13154 return ret;
13155- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13156+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13157 ret, "w", "w", "=r", 2);
13158 return ret;
13159- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13160+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13161 ret, "l", "k", "=r", 4);
13162 return ret;
13163- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13164+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13165 ret, "q", "", "=r", 8);
13166 return ret;
13167 case 10:
13168- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13169+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13170 ret, "q", "", "=r", 10);
13171 if (unlikely(ret))
13172 return ret;
13173 __get_user_asm(*(u16 *)(8 + (char *)dst),
13174- (u16 __user *)(8 + (char __user *)src),
13175+ (const u16 __user *)(8 + (const char __user *)src),
13176 ret, "w", "w", "=r", 2);
13177 return ret;
13178 case 16:
13179- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13180+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13181 ret, "q", "", "=r", 16);
13182 if (unlikely(ret))
13183 return ret;
13184 __get_user_asm(*(u64 *)(8 + (char *)dst),
13185- (u64 __user *)(8 + (char __user *)src),
13186+ (const u64 __user *)(8 + (const char __user *)src),
13187 ret, "q", "", "=r", 8);
13188 return ret;
13189 default:
13190- return copy_user_generic(dst, (__force void *)src, size);
13191+
13192+#ifdef CONFIG_PAX_MEMORY_UDEREF
13193+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13194+ src += PAX_USER_SHADOW_BASE;
13195+#endif
13196+
13197+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13198 }
13199 }
13200
13201 static __always_inline __must_check
13202-int __copy_to_user(void __user *dst, const void *src, unsigned size)
13203+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13204 {
13205- int ret = 0;
13206+ size_t sz = __compiletime_object_size(src);
13207+ unsigned ret = 0;
13208
13209 might_fault();
13210- if (!__builtin_constant_p(size))
13211- return copy_user_generic((__force void *)dst, src, size);
13212+
13213+ if (size > INT_MAX)
13214+ return size;
13215+
13216+#ifdef CONFIG_PAX_MEMORY_UDEREF
13217+ if (!__access_ok(VERIFY_WRITE, dst, size))
13218+ return size;
13219+#endif
13220+
13221+ if (unlikely(sz != (size_t)-1 && sz < size)) {
13222+ copy_to_user_overflow();
13223+ return size;
13224+ }
13225+
13226+ if (!__builtin_constant_p(size)) {
13227+ check_object_size(src, size, true);
13228+
13229+#ifdef CONFIG_PAX_MEMORY_UDEREF
13230+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13231+ dst += PAX_USER_SHADOW_BASE;
13232+#endif
13233+
13234+ return copy_user_generic((__force_kernel void *)dst, src, size);
13235+ }
13236 switch (size) {
13237- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13238+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13239 ret, "b", "b", "iq", 1);
13240 return ret;
13241- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13242+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13243 ret, "w", "w", "ir", 2);
13244 return ret;
13245- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13246+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13247 ret, "l", "k", "ir", 4);
13248 return ret;
13249- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13250+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13251 ret, "q", "", "er", 8);
13252 return ret;
13253 case 10:
13254- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13255+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13256 ret, "q", "", "er", 10);
13257 if (unlikely(ret))
13258 return ret;
13259 asm("":::"memory");
13260- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13261+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13262 ret, "w", "w", "ir", 2);
13263 return ret;
13264 case 16:
13265- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13266+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13267 ret, "q", "", "er", 16);
13268 if (unlikely(ret))
13269 return ret;
13270 asm("":::"memory");
13271- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13272+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13273 ret, "q", "", "er", 8);
13274 return ret;
13275 default:
13276- return copy_user_generic((__force void *)dst, src, size);
13277+
13278+#ifdef CONFIG_PAX_MEMORY_UDEREF
13279+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13280+ dst += PAX_USER_SHADOW_BASE;
13281+#endif
13282+
13283+ return copy_user_generic((__force_kernel void *)dst, src, size);
13284 }
13285 }
13286
13287 static __always_inline __must_check
13288-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13289+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13290 {
13291- int ret = 0;
13292+ unsigned ret = 0;
13293
13294 might_fault();
13295- if (!__builtin_constant_p(size))
13296- return copy_user_generic((__force void *)dst,
13297- (__force void *)src, size);
13298+
13299+ if (size > INT_MAX)
13300+ return size;
13301+
13302+#ifdef CONFIG_PAX_MEMORY_UDEREF
13303+ if (!__access_ok(VERIFY_READ, src, size))
13304+ return size;
13305+ if (!__access_ok(VERIFY_WRITE, dst, size))
13306+ return size;
13307+#endif
13308+
13309+ if (!__builtin_constant_p(size)) {
13310+
13311+#ifdef CONFIG_PAX_MEMORY_UDEREF
13312+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13313+ src += PAX_USER_SHADOW_BASE;
13314+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13315+ dst += PAX_USER_SHADOW_BASE;
13316+#endif
13317+
13318+ return copy_user_generic((__force_kernel void *)dst,
13319+ (__force_kernel const void *)src, size);
13320+ }
13321 switch (size) {
13322 case 1: {
13323 u8 tmp;
13324- __get_user_asm(tmp, (u8 __user *)src,
13325+ __get_user_asm(tmp, (const u8 __user *)src,
13326 ret, "b", "b", "=q", 1);
13327 if (likely(!ret))
13328 __put_user_asm(tmp, (u8 __user *)dst,
13329@@ -176,7 +277,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13330 }
13331 case 2: {
13332 u16 tmp;
13333- __get_user_asm(tmp, (u16 __user *)src,
13334+ __get_user_asm(tmp, (const u16 __user *)src,
13335 ret, "w", "w", "=r", 2);
13336 if (likely(!ret))
13337 __put_user_asm(tmp, (u16 __user *)dst,
13338@@ -186,7 +287,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13339
13340 case 4: {
13341 u32 tmp;
13342- __get_user_asm(tmp, (u32 __user *)src,
13343+ __get_user_asm(tmp, (const u32 __user *)src,
13344 ret, "l", "k", "=r", 4);
13345 if (likely(!ret))
13346 __put_user_asm(tmp, (u32 __user *)dst,
13347@@ -195,7 +296,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13348 }
13349 case 8: {
13350 u64 tmp;
13351- __get_user_asm(tmp, (u64 __user *)src,
13352+ __get_user_asm(tmp, (const u64 __user *)src,
13353 ret, "q", "", "=r", 8);
13354 if (likely(!ret))
13355 __put_user_asm(tmp, (u64 __user *)dst,
13356@@ -203,44 +304,89 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13357 return ret;
13358 }
13359 default:
13360- return copy_user_generic((__force void *)dst,
13361- (__force void *)src, size);
13362+
13363+#ifdef CONFIG_PAX_MEMORY_UDEREF
13364+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13365+ src += PAX_USER_SHADOW_BASE;
13366+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13367+ dst += PAX_USER_SHADOW_BASE;
13368+#endif
13369+
13370+ return copy_user_generic((__force_kernel void *)dst,
13371+ (__force_kernel const void *)src, size);
13372 }
13373 }
13374
13375-__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13376-__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13377+__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13378+__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13379
13380 static __must_check __always_inline int
13381-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13382+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13383 {
13384- return copy_user_generic(dst, (__force const void *)src, size);
13385+ if (size > INT_MAX)
13386+ return size;
13387+
13388+#ifdef CONFIG_PAX_MEMORY_UDEREF
13389+ if (!__access_ok(VERIFY_READ, src, size))
13390+ return size;
13391+
13392+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13393+ src += PAX_USER_SHADOW_BASE;
13394+#endif
13395+
13396+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13397 }
13398
13399-static __must_check __always_inline int
13400-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13401+static __must_check __always_inline unsigned long
13402+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13403 {
13404- return copy_user_generic((__force void *)dst, src, size);
13405+ if (size > INT_MAX)
13406+ return size;
13407+
13408+#ifdef CONFIG_PAX_MEMORY_UDEREF
13409+ if (!__access_ok(VERIFY_WRITE, dst, size))
13410+ return size;
13411+
13412+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13413+ dst += PAX_USER_SHADOW_BASE;
13414+#endif
13415+
13416+ return copy_user_generic((__force_kernel void *)dst, src, size);
13417 }
13418
13419-extern long __copy_user_nocache(void *dst, const void __user *src,
13420- unsigned size, int zerorest);
13421+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13422+ unsigned long size, int zerorest) __size_overflow(3);
13423
13424-static inline int
13425-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13426+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13427 {
13428 might_sleep();
13429+
13430+ if (size > INT_MAX)
13431+ return size;
13432+
13433+#ifdef CONFIG_PAX_MEMORY_UDEREF
13434+ if (!__access_ok(VERIFY_READ, src, size))
13435+ return size;
13436+#endif
13437+
13438 return __copy_user_nocache(dst, src, size, 1);
13439 }
13440
13441-static inline int
13442-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13443- unsigned size)
13444+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13445+ unsigned long size)
13446 {
13447+ if (size > INT_MAX)
13448+ return size;
13449+
13450+#ifdef CONFIG_PAX_MEMORY_UDEREF
13451+ if (!__access_ok(VERIFY_READ, src, size))
13452+ return size;
13453+#endif
13454+
13455 return __copy_user_nocache(dst, src, size, 0);
13456 }
13457
13458-unsigned long
13459-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13460+extern unsigned long
13461+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13462
13463 #endif /* _ASM_X86_UACCESS_64_H */
13464diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13465index bb05228..d763d5b 100644
13466--- a/arch/x86/include/asm/vdso.h
13467+++ b/arch/x86/include/asm/vdso.h
13468@@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13469 #define VDSO32_SYMBOL(base, name) \
13470 ({ \
13471 extern const char VDSO32_##name[]; \
13472- (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13473+ (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13474 })
13475 #endif
13476
13477diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
13478index 5b238981..77fdd78 100644
13479--- a/arch/x86/include/asm/word-at-a-time.h
13480+++ b/arch/x86/include/asm/word-at-a-time.h
13481@@ -11,7 +11,7 @@
13482 * and shift, for example.
13483 */
13484 struct word_at_a_time {
13485- const unsigned long one_bits, high_bits;
13486+ unsigned long one_bits, high_bits;
13487 };
13488
13489 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
13490diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13491index c090af1..7e7bf16 100644
13492--- a/arch/x86/include/asm/x86_init.h
13493+++ b/arch/x86/include/asm/x86_init.h
13494@@ -29,7 +29,7 @@ struct x86_init_mpparse {
13495 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13496 void (*find_smp_config)(void);
13497 void (*get_smp_config)(unsigned int early);
13498-};
13499+} __no_const;
13500
13501 /**
13502 * struct x86_init_resources - platform specific resource related ops
13503@@ -43,7 +43,7 @@ struct x86_init_resources {
13504 void (*probe_roms)(void);
13505 void (*reserve_resources)(void);
13506 char *(*memory_setup)(void);
13507-};
13508+} __no_const;
13509
13510 /**
13511 * struct x86_init_irqs - platform specific interrupt setup
13512@@ -56,7 +56,7 @@ struct x86_init_irqs {
13513 void (*pre_vector_init)(void);
13514 void (*intr_init)(void);
13515 void (*trap_init)(void);
13516-};
13517+} __no_const;
13518
13519 /**
13520 * struct x86_init_oem - oem platform specific customizing functions
13521@@ -66,7 +66,7 @@ struct x86_init_irqs {
13522 struct x86_init_oem {
13523 void (*arch_setup)(void);
13524 void (*banner)(void);
13525-};
13526+} __no_const;
13527
13528 /**
13529 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13530@@ -77,7 +77,7 @@ struct x86_init_oem {
13531 */
13532 struct x86_init_mapping {
13533 void (*pagetable_reserve)(u64 start, u64 end);
13534-};
13535+} __no_const;
13536
13537 /**
13538 * struct x86_init_paging - platform specific paging functions
13539@@ -87,7 +87,7 @@ struct x86_init_mapping {
13540 struct x86_init_paging {
13541 void (*pagetable_setup_start)(pgd_t *base);
13542 void (*pagetable_setup_done)(pgd_t *base);
13543-};
13544+} __no_const;
13545
13546 /**
13547 * struct x86_init_timers - platform specific timer setup
13548@@ -102,7 +102,7 @@ struct x86_init_timers {
13549 void (*tsc_pre_init)(void);
13550 void (*timer_init)(void);
13551 void (*wallclock_init)(void);
13552-};
13553+} __no_const;
13554
13555 /**
13556 * struct x86_init_iommu - platform specific iommu setup
13557@@ -110,7 +110,7 @@ struct x86_init_timers {
13558 */
13559 struct x86_init_iommu {
13560 int (*iommu_init)(void);
13561-};
13562+} __no_const;
13563
13564 /**
13565 * struct x86_init_pci - platform specific pci init functions
13566@@ -124,7 +124,7 @@ struct x86_init_pci {
13567 int (*init)(void);
13568 void (*init_irq)(void);
13569 void (*fixup_irqs)(void);
13570-};
13571+} __no_const;
13572
13573 /**
13574 * struct x86_init_ops - functions for platform specific setup
13575@@ -140,7 +140,7 @@ struct x86_init_ops {
13576 struct x86_init_timers timers;
13577 struct x86_init_iommu iommu;
13578 struct x86_init_pci pci;
13579-};
13580+} __no_const;
13581
13582 /**
13583 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13584@@ -151,7 +151,7 @@ struct x86_cpuinit_ops {
13585 void (*setup_percpu_clockev)(void);
13586 void (*early_percpu_clock_init)(void);
13587 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13588-};
13589+} __no_const;
13590
13591 /**
13592 * struct x86_platform_ops - platform specific runtime functions
13593@@ -177,7 +177,7 @@ struct x86_platform_ops {
13594 int (*i8042_detect)(void);
13595 void (*save_sched_clock_state)(void);
13596 void (*restore_sched_clock_state)(void);
13597-};
13598+} __no_const;
13599
13600 struct pci_dev;
13601
13602@@ -186,14 +186,14 @@ struct x86_msi_ops {
13603 void (*teardown_msi_irq)(unsigned int irq);
13604 void (*teardown_msi_irqs)(struct pci_dev *dev);
13605 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13606-};
13607+} __no_const;
13608
13609 struct x86_io_apic_ops {
13610 void (*init) (void);
13611 unsigned int (*read) (unsigned int apic, unsigned int reg);
13612 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
13613 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
13614-};
13615+} __no_const;
13616
13617 extern struct x86_init_ops x86_init;
13618 extern struct x86_cpuinit_ops x86_cpuinit;
13619diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13620index 8a1b6f9..a29c4e4 100644
13621--- a/arch/x86/include/asm/xsave.h
13622+++ b/arch/x86/include/asm/xsave.h
13623@@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13624 {
13625 int err;
13626
13627+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13628+ if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13629+ buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13630+#endif
13631+
13632 /*
13633 * Clear the xsave header first, so that reserved fields are
13634 * initialized to zero.
13635@@ -93,10 +98,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13636 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13637 {
13638 int err;
13639- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13640+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13641 u32 lmask = mask;
13642 u32 hmask = mask >> 32;
13643
13644+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13645+ if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13646+ xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13647+#endif
13648+
13649 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13650 "2:\n"
13651 ".section .fixup,\"ax\"\n"
13652diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13653index 95bf99de..de9235c 100644
13654--- a/arch/x86/kernel/acpi/sleep.c
13655+++ b/arch/x86/kernel/acpi/sleep.c
13656@@ -73,8 +73,12 @@ int acpi_suspend_lowlevel(void)
13657 #else /* CONFIG_64BIT */
13658 #ifdef CONFIG_SMP
13659 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13660+
13661+ pax_open_kernel();
13662 early_gdt_descr.address =
13663 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13664+ pax_close_kernel();
13665+
13666 initial_gs = per_cpu_offset(smp_processor_id());
13667 #endif
13668 initial_code = (unsigned long)wakeup_long64;
13669diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13670index 7261083..5c12053 100644
13671--- a/arch/x86/kernel/acpi/wakeup_32.S
13672+++ b/arch/x86/kernel/acpi/wakeup_32.S
13673@@ -30,13 +30,11 @@ wakeup_pmode_return:
13674 # and restore the stack ... but you need gdt for this to work
13675 movl saved_context_esp, %esp
13676
13677- movl %cs:saved_magic, %eax
13678- cmpl $0x12345678, %eax
13679+ cmpl $0x12345678, saved_magic
13680 jne bogus_magic
13681
13682 # jump to place where we left off
13683- movl saved_eip, %eax
13684- jmp *%eax
13685+ jmp *(saved_eip)
13686
13687 bogus_magic:
13688 jmp bogus_magic
13689diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13690index 73ef56c..0238021 100644
13691--- a/arch/x86/kernel/alternative.c
13692+++ b/arch/x86/kernel/alternative.c
13693@@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13694 */
13695 for (a = start; a < end; a++) {
13696 instr = (u8 *)&a->instr_offset + a->instr_offset;
13697+
13698+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13699+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13700+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13701+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13702+#endif
13703+
13704 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13705 BUG_ON(a->replacementlen > a->instrlen);
13706 BUG_ON(a->instrlen > sizeof(insnbuf));
13707@@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13708 for (poff = start; poff < end; poff++) {
13709 u8 *ptr = (u8 *)poff + *poff;
13710
13711+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13712+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13713+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13714+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13715+#endif
13716+
13717 if (!*poff || ptr < text || ptr >= text_end)
13718 continue;
13719 /* turn DS segment override prefix into lock prefix */
13720- if (*ptr == 0x3e)
13721+ if (*ktla_ktva(ptr) == 0x3e)
13722 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13723 };
13724 mutex_unlock(&text_mutex);
13725@@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13726 for (poff = start; poff < end; poff++) {
13727 u8 *ptr = (u8 *)poff + *poff;
13728
13729+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13730+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13731+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13732+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13733+#endif
13734+
13735 if (!*poff || ptr < text || ptr >= text_end)
13736 continue;
13737 /* turn lock prefix into DS segment override prefix */
13738- if (*ptr == 0xf0)
13739+ if (*ktla_ktva(ptr) == 0xf0)
13740 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13741 };
13742 mutex_unlock(&text_mutex);
13743@@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13744
13745 BUG_ON(p->len > MAX_PATCH_LEN);
13746 /* prep the buffer with the original instructions */
13747- memcpy(insnbuf, p->instr, p->len);
13748+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13749 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13750 (unsigned long)p->instr, p->len);
13751
13752@@ -568,7 +587,7 @@ void __init alternative_instructions(void)
13753 if (smp_alt_once)
13754 free_init_pages("SMP alternatives",
13755 (unsigned long)__smp_locks,
13756- (unsigned long)__smp_locks_end);
13757+ PAGE_ALIGN((unsigned long)__smp_locks_end));
13758
13759 restart_nmi();
13760 }
13761@@ -585,13 +604,17 @@ void __init alternative_instructions(void)
13762 * instructions. And on the local CPU you need to be protected again NMI or MCE
13763 * handlers seeing an inconsistent instruction while you patch.
13764 */
13765-void *__init_or_module text_poke_early(void *addr, const void *opcode,
13766+void *__kprobes text_poke_early(void *addr, const void *opcode,
13767 size_t len)
13768 {
13769 unsigned long flags;
13770 local_irq_save(flags);
13771- memcpy(addr, opcode, len);
13772+
13773+ pax_open_kernel();
13774+ memcpy(ktla_ktva(addr), opcode, len);
13775 sync_core();
13776+ pax_close_kernel();
13777+
13778 local_irq_restore(flags);
13779 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13780 that causes hangs on some VIA CPUs. */
13781@@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13782 */
13783 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13784 {
13785- unsigned long flags;
13786- char *vaddr;
13787+ unsigned char *vaddr = ktla_ktva(addr);
13788 struct page *pages[2];
13789- int i;
13790+ size_t i;
13791
13792 if (!core_kernel_text((unsigned long)addr)) {
13793- pages[0] = vmalloc_to_page(addr);
13794- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13795+ pages[0] = vmalloc_to_page(vaddr);
13796+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13797 } else {
13798- pages[0] = virt_to_page(addr);
13799+ pages[0] = virt_to_page(vaddr);
13800 WARN_ON(!PageReserved(pages[0]));
13801- pages[1] = virt_to_page(addr + PAGE_SIZE);
13802+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13803 }
13804 BUG_ON(!pages[0]);
13805- local_irq_save(flags);
13806- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13807- if (pages[1])
13808- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13809- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13810- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13811- clear_fixmap(FIX_TEXT_POKE0);
13812- if (pages[1])
13813- clear_fixmap(FIX_TEXT_POKE1);
13814- local_flush_tlb();
13815- sync_core();
13816- /* Could also do a CLFLUSH here to speed up CPU recovery; but
13817- that causes hangs on some VIA CPUs. */
13818+ text_poke_early(addr, opcode, len);
13819 for (i = 0; i < len; i++)
13820- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13821- local_irq_restore(flags);
13822+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13823 return addr;
13824 }
13825
13826diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13827index 39a222e..85a7767 100644
13828--- a/arch/x86/kernel/apic/apic.c
13829+++ b/arch/x86/kernel/apic/apic.c
13830@@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
13831 /*
13832 * Debug level, exported for io_apic.c
13833 */
13834-unsigned int apic_verbosity;
13835+int apic_verbosity;
13836
13837 int pic_mode;
13838
13839@@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13840 apic_write(APIC_ESR, 0);
13841 v1 = apic_read(APIC_ESR);
13842 ack_APIC_irq();
13843- atomic_inc(&irq_err_count);
13844+ atomic_inc_unchecked(&irq_err_count);
13845
13846 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13847 smp_processor_id(), v0 , v1);
13848diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13849index 5f0ff59..f9e01bc 100644
13850--- a/arch/x86/kernel/apic/io_apic.c
13851+++ b/arch/x86/kernel/apic/io_apic.c
13852@@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13853 }
13854 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13855
13856-void lock_vector_lock(void)
13857+void lock_vector_lock(void) __acquires(vector_lock)
13858 {
13859 /* Used to the online set of cpus does not change
13860 * during assign_irq_vector.
13861@@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
13862 raw_spin_lock(&vector_lock);
13863 }
13864
13865-void unlock_vector_lock(void)
13866+void unlock_vector_lock(void) __releases(vector_lock)
13867 {
13868 raw_spin_unlock(&vector_lock);
13869 }
13870@@ -2369,7 +2369,7 @@ static void ack_apic_edge(struct irq_data *data)
13871 ack_APIC_irq();
13872 }
13873
13874-atomic_t irq_mis_count;
13875+atomic_unchecked_t irq_mis_count;
13876
13877 #ifdef CONFIG_GENERIC_PENDING_IRQ
13878 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
13879@@ -2510,7 +2510,7 @@ static void ack_apic_level(struct irq_data *data)
13880 * at the cpu.
13881 */
13882 if (!(v & (1 << (i & 0x1f)))) {
13883- atomic_inc(&irq_mis_count);
13884+ atomic_inc_unchecked(&irq_mis_count);
13885
13886 eoi_ioapic_irq(irq, cfg);
13887 }
13888diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13889index 07b0c0d..1df6f42 100644
13890--- a/arch/x86/kernel/apm_32.c
13891+++ b/arch/x86/kernel/apm_32.c
13892@@ -410,7 +410,7 @@ static DEFINE_MUTEX(apm_mutex);
13893 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13894 * even though they are called in protected mode.
13895 */
13896-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
13897+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
13898 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
13899
13900 static const char driver_version[] = "1.16ac"; /* no spaces */
13901@@ -588,7 +588,10 @@ static long __apm_bios_call(void *_call)
13902 BUG_ON(cpu != 0);
13903 gdt = get_cpu_gdt_table(cpu);
13904 save_desc_40 = gdt[0x40 / 8];
13905+
13906+ pax_open_kernel();
13907 gdt[0x40 / 8] = bad_bios_desc;
13908+ pax_close_kernel();
13909
13910 apm_irq_save(flags);
13911 APM_DO_SAVE_SEGS;
13912@@ -597,7 +600,11 @@ static long __apm_bios_call(void *_call)
13913 &call->esi);
13914 APM_DO_RESTORE_SEGS;
13915 apm_irq_restore(flags);
13916+
13917+ pax_open_kernel();
13918 gdt[0x40 / 8] = save_desc_40;
13919+ pax_close_kernel();
13920+
13921 put_cpu();
13922
13923 return call->eax & 0xff;
13924@@ -664,7 +671,10 @@ static long __apm_bios_call_simple(void *_call)
13925 BUG_ON(cpu != 0);
13926 gdt = get_cpu_gdt_table(cpu);
13927 save_desc_40 = gdt[0x40 / 8];
13928+
13929+ pax_open_kernel();
13930 gdt[0x40 / 8] = bad_bios_desc;
13931+ pax_close_kernel();
13932
13933 apm_irq_save(flags);
13934 APM_DO_SAVE_SEGS;
13935@@ -672,7 +682,11 @@ static long __apm_bios_call_simple(void *_call)
13936 &call->eax);
13937 APM_DO_RESTORE_SEGS;
13938 apm_irq_restore(flags);
13939+
13940+ pax_open_kernel();
13941 gdt[0x40 / 8] = save_desc_40;
13942+ pax_close_kernel();
13943+
13944 put_cpu();
13945 return error;
13946 }
13947@@ -2345,12 +2359,15 @@ static int __init apm_init(void)
13948 * code to that CPU.
13949 */
13950 gdt = get_cpu_gdt_table(0);
13951+
13952+ pax_open_kernel();
13953 set_desc_base(&gdt[APM_CS >> 3],
13954 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
13955 set_desc_base(&gdt[APM_CS_16 >> 3],
13956 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
13957 set_desc_base(&gdt[APM_DS >> 3],
13958 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
13959+ pax_close_kernel();
13960
13961 proc_create("apm", 0, NULL, &apm_file_ops);
13962
13963diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
13964index 68de2dc..1f3c720 100644
13965--- a/arch/x86/kernel/asm-offsets.c
13966+++ b/arch/x86/kernel/asm-offsets.c
13967@@ -33,6 +33,8 @@ void common(void) {
13968 OFFSET(TI_status, thread_info, status);
13969 OFFSET(TI_addr_limit, thread_info, addr_limit);
13970 OFFSET(TI_preempt_count, thread_info, preempt_count);
13971+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
13972+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
13973
13974 BLANK();
13975 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
13976@@ -53,8 +55,26 @@ void common(void) {
13977 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
13978 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
13979 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
13980+
13981+#ifdef CONFIG_PAX_KERNEXEC
13982+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
13983 #endif
13984
13985+#ifdef CONFIG_PAX_MEMORY_UDEREF
13986+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
13987+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
13988+#ifdef CONFIG_X86_64
13989+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
13990+#endif
13991+#endif
13992+
13993+#endif
13994+
13995+ BLANK();
13996+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
13997+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
13998+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
13999+
14000 #ifdef CONFIG_XEN
14001 BLANK();
14002 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
14003diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
14004index 1b4754f..fbb4227 100644
14005--- a/arch/x86/kernel/asm-offsets_64.c
14006+++ b/arch/x86/kernel/asm-offsets_64.c
14007@@ -76,6 +76,7 @@ int main(void)
14008 BLANK();
14009 #undef ENTRY
14010
14011+ DEFINE(TSS_size, sizeof(struct tss_struct));
14012 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
14013 BLANK();
14014
14015diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14016index 6ab6aa2..8f71507 100644
14017--- a/arch/x86/kernel/cpu/Makefile
14018+++ b/arch/x86/kernel/cpu/Makefile
14019@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14020 CFLAGS_REMOVE_perf_event.o = -pg
14021 endif
14022
14023-# Make sure load_percpu_segment has no stackprotector
14024-nostackp := $(call cc-option, -fno-stack-protector)
14025-CFLAGS_common.o := $(nostackp)
14026-
14027 obj-y := intel_cacheinfo.o scattered.o topology.o
14028 obj-y += proc.o capflags.o powerflags.o common.o
14029 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
14030diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14031index 146bb62..ac9c74a 100644
14032--- a/arch/x86/kernel/cpu/amd.c
14033+++ b/arch/x86/kernel/cpu/amd.c
14034@@ -691,7 +691,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14035 unsigned int size)
14036 {
14037 /* AMD errata T13 (order #21922) */
14038- if ((c->x86 == 6)) {
14039+ if (c->x86 == 6) {
14040 /* Duron Rev A0 */
14041 if (c->x86_model == 3 && c->x86_mask == 0)
14042 size = 64;
14043diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14044index 6b9333b..4c3083a 100644
14045--- a/arch/x86/kernel/cpu/common.c
14046+++ b/arch/x86/kernel/cpu/common.c
14047@@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14048
14049 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14050
14051-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14052-#ifdef CONFIG_X86_64
14053- /*
14054- * We need valid kernel segments for data and code in long mode too
14055- * IRET will check the segment types kkeil 2000/10/28
14056- * Also sysret mandates a special GDT layout
14057- *
14058- * TLS descriptors are currently at a different place compared to i386.
14059- * Hopefully nobody expects them at a fixed place (Wine?)
14060- */
14061- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14062- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14063- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14064- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14065- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14066- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14067-#else
14068- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14069- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14070- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14071- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14072- /*
14073- * Segments used for calling PnP BIOS have byte granularity.
14074- * They code segments and data segments have fixed 64k limits,
14075- * the transfer segment sizes are set at run time.
14076- */
14077- /* 32-bit code */
14078- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14079- /* 16-bit code */
14080- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14081- /* 16-bit data */
14082- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14083- /* 16-bit data */
14084- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14085- /* 16-bit data */
14086- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14087- /*
14088- * The APM segments have byte granularity and their bases
14089- * are set at run time. All have 64k limits.
14090- */
14091- /* 32-bit code */
14092- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14093- /* 16-bit code */
14094- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14095- /* data */
14096- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14097-
14098- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14099- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14100- GDT_STACK_CANARY_INIT
14101-#endif
14102-} };
14103-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14104-
14105 static int __init x86_xsave_setup(char *s)
14106 {
14107 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14108@@ -374,7 +320,7 @@ void switch_to_new_gdt(int cpu)
14109 {
14110 struct desc_ptr gdt_descr;
14111
14112- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14113+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14114 gdt_descr.size = GDT_SIZE - 1;
14115 load_gdt(&gdt_descr);
14116 /* Reload the per-cpu base */
14117@@ -841,6 +787,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14118 /* Filter out anything that depends on CPUID levels we don't have */
14119 filter_cpuid_features(c, true);
14120
14121+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14122+ setup_clear_cpu_cap(X86_FEATURE_SEP);
14123+#endif
14124+
14125 /* If the model name is still unset, do table lookup. */
14126 if (!c->x86_model_id[0]) {
14127 const char *p;
14128@@ -1021,10 +971,12 @@ static __init int setup_disablecpuid(char *arg)
14129 }
14130 __setup("clearcpuid=", setup_disablecpuid);
14131
14132+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14133+EXPORT_PER_CPU_SYMBOL(current_tinfo);
14134+
14135 #ifdef CONFIG_X86_64
14136 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14137-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14138- (unsigned long) nmi_idt_table };
14139+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14140
14141 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14142 irq_stack_union) __aligned(PAGE_SIZE);
14143@@ -1038,7 +990,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14144 EXPORT_PER_CPU_SYMBOL(current_task);
14145
14146 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14147- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14148+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14149 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14150
14151 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14152@@ -1132,7 +1084,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14153 {
14154 memset(regs, 0, sizeof(struct pt_regs));
14155 regs->fs = __KERNEL_PERCPU;
14156- regs->gs = __KERNEL_STACK_CANARY;
14157+ savesegment(gs, regs->gs);
14158
14159 return regs;
14160 }
14161@@ -1187,7 +1139,7 @@ void __cpuinit cpu_init(void)
14162 int i;
14163
14164 cpu = stack_smp_processor_id();
14165- t = &per_cpu(init_tss, cpu);
14166+ t = init_tss + cpu;
14167 oist = &per_cpu(orig_ist, cpu);
14168
14169 #ifdef CONFIG_NUMA
14170@@ -1213,7 +1165,7 @@ void __cpuinit cpu_init(void)
14171 switch_to_new_gdt(cpu);
14172 loadsegment(fs, 0);
14173
14174- load_idt((const struct desc_ptr *)&idt_descr);
14175+ load_idt(&idt_descr);
14176
14177 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14178 syscall_init();
14179@@ -1222,7 +1174,6 @@ void __cpuinit cpu_init(void)
14180 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14181 barrier();
14182
14183- x86_configure_nx();
14184 if (cpu != 0)
14185 enable_x2apic();
14186
14187@@ -1278,7 +1229,7 @@ void __cpuinit cpu_init(void)
14188 {
14189 int cpu = smp_processor_id();
14190 struct task_struct *curr = current;
14191- struct tss_struct *t = &per_cpu(init_tss, cpu);
14192+ struct tss_struct *t = init_tss + cpu;
14193 struct thread_struct *thread = &curr->thread;
14194
14195 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14196diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14197index 3e6ff6c..54b4992 100644
14198--- a/arch/x86/kernel/cpu/intel.c
14199+++ b/arch/x86/kernel/cpu/intel.c
14200@@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14201 * Update the IDT descriptor and reload the IDT so that
14202 * it uses the read-only mapped virtual address.
14203 */
14204- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14205+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14206 load_idt(&idt_descr);
14207 }
14208 #endif
14209diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14210index c46ed49..5dc0a53 100644
14211--- a/arch/x86/kernel/cpu/mcheck/mce.c
14212+++ b/arch/x86/kernel/cpu/mcheck/mce.c
14213@@ -42,6 +42,7 @@
14214 #include <asm/processor.h>
14215 #include <asm/mce.h>
14216 #include <asm/msr.h>
14217+#include <asm/local.h>
14218
14219 #include "mce-internal.h"
14220
14221@@ -250,7 +251,7 @@ static void print_mce(struct mce *m)
14222 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14223 m->cs, m->ip);
14224
14225- if (m->cs == __KERNEL_CS)
14226+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14227 print_symbol("{%s}", m->ip);
14228 pr_cont("\n");
14229 }
14230@@ -283,10 +284,10 @@ static void print_mce(struct mce *m)
14231
14232 #define PANIC_TIMEOUT 5 /* 5 seconds */
14233
14234-static atomic_t mce_paniced;
14235+static atomic_unchecked_t mce_paniced;
14236
14237 static int fake_panic;
14238-static atomic_t mce_fake_paniced;
14239+static atomic_unchecked_t mce_fake_paniced;
14240
14241 /* Panic in progress. Enable interrupts and wait for final IPI */
14242 static void wait_for_panic(void)
14243@@ -310,7 +311,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14244 /*
14245 * Make sure only one CPU runs in machine check panic
14246 */
14247- if (atomic_inc_return(&mce_paniced) > 1)
14248+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14249 wait_for_panic();
14250 barrier();
14251
14252@@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14253 console_verbose();
14254 } else {
14255 /* Don't log too much for fake panic */
14256- if (atomic_inc_return(&mce_fake_paniced) > 1)
14257+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14258 return;
14259 }
14260 /* First print corrected ones that are still unlogged */
14261@@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
14262 * might have been modified by someone else.
14263 */
14264 rmb();
14265- if (atomic_read(&mce_paniced))
14266+ if (atomic_read_unchecked(&mce_paniced))
14267 wait_for_panic();
14268 if (!monarch_timeout)
14269 goto out;
14270@@ -1581,7 +1582,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14271 }
14272
14273 /* Call the installed machine check handler for this CPU setup. */
14274-void (*machine_check_vector)(struct pt_regs *, long error_code) =
14275+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14276 unexpected_machine_check;
14277
14278 /*
14279@@ -1604,7 +1605,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14280 return;
14281 }
14282
14283+ pax_open_kernel();
14284 machine_check_vector = do_machine_check;
14285+ pax_close_kernel();
14286
14287 __mcheck_cpu_init_generic();
14288 __mcheck_cpu_init_vendor(c);
14289@@ -1618,7 +1621,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14290 */
14291
14292 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14293-static int mce_chrdev_open_count; /* #times opened */
14294+static local_t mce_chrdev_open_count; /* #times opened */
14295 static int mce_chrdev_open_exclu; /* already open exclusive? */
14296
14297 static int mce_chrdev_open(struct inode *inode, struct file *file)
14298@@ -1626,7 +1629,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14299 spin_lock(&mce_chrdev_state_lock);
14300
14301 if (mce_chrdev_open_exclu ||
14302- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14303+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14304 spin_unlock(&mce_chrdev_state_lock);
14305
14306 return -EBUSY;
14307@@ -1634,7 +1637,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14308
14309 if (file->f_flags & O_EXCL)
14310 mce_chrdev_open_exclu = 1;
14311- mce_chrdev_open_count++;
14312+ local_inc(&mce_chrdev_open_count);
14313
14314 spin_unlock(&mce_chrdev_state_lock);
14315
14316@@ -1645,7 +1648,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14317 {
14318 spin_lock(&mce_chrdev_state_lock);
14319
14320- mce_chrdev_open_count--;
14321+ local_dec(&mce_chrdev_open_count);
14322 mce_chrdev_open_exclu = 0;
14323
14324 spin_unlock(&mce_chrdev_state_lock);
14325@@ -2370,7 +2373,7 @@ struct dentry *mce_get_debugfs_dir(void)
14326 static void mce_reset(void)
14327 {
14328 cpu_missing = 0;
14329- atomic_set(&mce_fake_paniced, 0);
14330+ atomic_set_unchecked(&mce_fake_paniced, 0);
14331 atomic_set(&mce_executing, 0);
14332 atomic_set(&mce_callin, 0);
14333 atomic_set(&global_nwo, 0);
14334diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14335index 2d5454c..51987eb 100644
14336--- a/arch/x86/kernel/cpu/mcheck/p5.c
14337+++ b/arch/x86/kernel/cpu/mcheck/p5.c
14338@@ -11,6 +11,7 @@
14339 #include <asm/processor.h>
14340 #include <asm/mce.h>
14341 #include <asm/msr.h>
14342+#include <asm/pgtable.h>
14343
14344 /* By default disabled */
14345 int mce_p5_enabled __read_mostly;
14346@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14347 if (!cpu_has(c, X86_FEATURE_MCE))
14348 return;
14349
14350+ pax_open_kernel();
14351 machine_check_vector = pentium_machine_check;
14352+ pax_close_kernel();
14353 /* Make sure the vector pointer is visible before we enable MCEs: */
14354 wmb();
14355
14356diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14357index 2d7998f..17c9de1 100644
14358--- a/arch/x86/kernel/cpu/mcheck/winchip.c
14359+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14360@@ -10,6 +10,7 @@
14361 #include <asm/processor.h>
14362 #include <asm/mce.h>
14363 #include <asm/msr.h>
14364+#include <asm/pgtable.h>
14365
14366 /* Machine check handler for WinChip C6: */
14367 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14368@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14369 {
14370 u32 lo, hi;
14371
14372+ pax_open_kernel();
14373 machine_check_vector = winchip_machine_check;
14374+ pax_close_kernel();
14375 /* Make sure the vector pointer is visible before we enable MCEs: */
14376 wmb();
14377
14378diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14379index 6b96110..0da73eb 100644
14380--- a/arch/x86/kernel/cpu/mtrr/main.c
14381+++ b/arch/x86/kernel/cpu/mtrr/main.c
14382@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14383 u64 size_or_mask, size_and_mask;
14384 static bool mtrr_aps_delayed_init;
14385
14386-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14387+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14388
14389 const struct mtrr_ops *mtrr_if;
14390
14391diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14392index df5e41f..816c719 100644
14393--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14394+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14395@@ -25,7 +25,7 @@ struct mtrr_ops {
14396 int (*validate_add_page)(unsigned long base, unsigned long size,
14397 unsigned int type);
14398 int (*have_wrcomb)(void);
14399-};
14400+} __do_const;
14401
14402 extern int generic_get_free_region(unsigned long base, unsigned long size,
14403 int replace_reg);
14404diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14405index c4706cf..264b0f7 100644
14406--- a/arch/x86/kernel/cpu/perf_event.c
14407+++ b/arch/x86/kernel/cpu/perf_event.c
14408@@ -1837,7 +1837,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14409 break;
14410
14411 perf_callchain_store(entry, frame.return_address);
14412- fp = frame.next_frame;
14413+ fp = (const void __force_user *)frame.next_frame;
14414 }
14415 }
14416
14417diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14418index 13ad899..f642b9a 100644
14419--- a/arch/x86/kernel/crash.c
14420+++ b/arch/x86/kernel/crash.c
14421@@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14422 {
14423 #ifdef CONFIG_X86_32
14424 struct pt_regs fixed_regs;
14425-#endif
14426
14427-#ifdef CONFIG_X86_32
14428- if (!user_mode_vm(regs)) {
14429+ if (!user_mode(regs)) {
14430 crash_fixup_ss_esp(&fixed_regs, regs);
14431 regs = &fixed_regs;
14432 }
14433diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14434index 37250fe..bf2ec74 100644
14435--- a/arch/x86/kernel/doublefault_32.c
14436+++ b/arch/x86/kernel/doublefault_32.c
14437@@ -11,7 +11,7 @@
14438
14439 #define DOUBLEFAULT_STACKSIZE (1024)
14440 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14441-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14442+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14443
14444 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14445
14446@@ -21,7 +21,7 @@ static void doublefault_fn(void)
14447 unsigned long gdt, tss;
14448
14449 store_gdt(&gdt_desc);
14450- gdt = gdt_desc.address;
14451+ gdt = (unsigned long)gdt_desc.address;
14452
14453 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14454
14455@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14456 /* 0x2 bit is always set */
14457 .flags = X86_EFLAGS_SF | 0x2,
14458 .sp = STACK_START,
14459- .es = __USER_DS,
14460+ .es = __KERNEL_DS,
14461 .cs = __KERNEL_CS,
14462 .ss = __KERNEL_DS,
14463- .ds = __USER_DS,
14464+ .ds = __KERNEL_DS,
14465 .fs = __KERNEL_PERCPU,
14466
14467 .__cr3 = __pa_nodebug(swapper_pg_dir),
14468diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14469index 571246d..81f335c 100644
14470--- a/arch/x86/kernel/dumpstack.c
14471+++ b/arch/x86/kernel/dumpstack.c
14472@@ -2,6 +2,9 @@
14473 * Copyright (C) 1991, 1992 Linus Torvalds
14474 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14475 */
14476+#ifdef CONFIG_GRKERNSEC_HIDESYM
14477+#define __INCLUDED_BY_HIDESYM 1
14478+#endif
14479 #include <linux/kallsyms.h>
14480 #include <linux/kprobes.h>
14481 #include <linux/uaccess.h>
14482@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
14483 static void
14484 print_ftrace_graph_addr(unsigned long addr, void *data,
14485 const struct stacktrace_ops *ops,
14486- struct thread_info *tinfo, int *graph)
14487+ struct task_struct *task, int *graph)
14488 {
14489- struct task_struct *task;
14490 unsigned long ret_addr;
14491 int index;
14492
14493 if (addr != (unsigned long)return_to_handler)
14494 return;
14495
14496- task = tinfo->task;
14497 index = task->curr_ret_stack;
14498
14499 if (!task->ret_stack || index < *graph)
14500@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14501 static inline void
14502 print_ftrace_graph_addr(unsigned long addr, void *data,
14503 const struct stacktrace_ops *ops,
14504- struct thread_info *tinfo, int *graph)
14505+ struct task_struct *task, int *graph)
14506 { }
14507 #endif
14508
14509@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14510 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14511 */
14512
14513-static inline int valid_stack_ptr(struct thread_info *tinfo,
14514- void *p, unsigned int size, void *end)
14515+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14516 {
14517- void *t = tinfo;
14518 if (end) {
14519 if (p < end && p >= (end-THREAD_SIZE))
14520 return 1;
14521@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14522 }
14523
14524 unsigned long
14525-print_context_stack(struct thread_info *tinfo,
14526+print_context_stack(struct task_struct *task, void *stack_start,
14527 unsigned long *stack, unsigned long bp,
14528 const struct stacktrace_ops *ops, void *data,
14529 unsigned long *end, int *graph)
14530 {
14531 struct stack_frame *frame = (struct stack_frame *)bp;
14532
14533- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14534+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14535 unsigned long addr;
14536
14537 addr = *stack;
14538@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
14539 } else {
14540 ops->address(data, addr, 0);
14541 }
14542- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14543+ print_ftrace_graph_addr(addr, data, ops, task, graph);
14544 }
14545 stack++;
14546 }
14547@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
14548 EXPORT_SYMBOL_GPL(print_context_stack);
14549
14550 unsigned long
14551-print_context_stack_bp(struct thread_info *tinfo,
14552+print_context_stack_bp(struct task_struct *task, void *stack_start,
14553 unsigned long *stack, unsigned long bp,
14554 const struct stacktrace_ops *ops, void *data,
14555 unsigned long *end, int *graph)
14556@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14557 struct stack_frame *frame = (struct stack_frame *)bp;
14558 unsigned long *ret_addr = &frame->return_address;
14559
14560- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14561+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14562 unsigned long addr = *ret_addr;
14563
14564 if (!__kernel_text_address(addr))
14565@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14566 ops->address(data, addr, 1);
14567 frame = frame->next_frame;
14568 ret_addr = &frame->return_address;
14569- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14570+ print_ftrace_graph_addr(addr, data, ops, task, graph);
14571 }
14572
14573 return (unsigned long)frame;
14574@@ -189,7 +188,7 @@ void dump_stack(void)
14575
14576 bp = stack_frame(current, NULL);
14577 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14578- current->pid, current->comm, print_tainted(),
14579+ task_pid_nr(current), current->comm, print_tainted(),
14580 init_utsname()->release,
14581 (int)strcspn(init_utsname()->version, " "),
14582 init_utsname()->version);
14583@@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
14584 }
14585 EXPORT_SYMBOL_GPL(oops_begin);
14586
14587+extern void gr_handle_kernel_exploit(void);
14588+
14589 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14590 {
14591 if (regs && kexec_should_crash(current))
14592@@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14593 panic("Fatal exception in interrupt");
14594 if (panic_on_oops)
14595 panic("Fatal exception");
14596- do_exit(signr);
14597+
14598+ gr_handle_kernel_exploit();
14599+
14600+ do_group_exit(signr);
14601 }
14602
14603 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14604@@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14605
14606 show_regs(regs);
14607 #ifdef CONFIG_X86_32
14608- if (user_mode_vm(regs)) {
14609+ if (user_mode(regs)) {
14610 sp = regs->sp;
14611 ss = regs->ss & 0xffff;
14612 } else {
14613@@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14614 unsigned long flags = oops_begin();
14615 int sig = SIGSEGV;
14616
14617- if (!user_mode_vm(regs))
14618+ if (!user_mode(regs))
14619 report_bug(regs->ip, regs);
14620
14621 if (__die(str, regs, err))
14622diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14623index e0b1d78..a8ade5e 100644
14624--- a/arch/x86/kernel/dumpstack_32.c
14625+++ b/arch/x86/kernel/dumpstack_32.c
14626@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14627 bp = stack_frame(task, regs);
14628
14629 for (;;) {
14630- struct thread_info *context;
14631+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14632
14633- context = (struct thread_info *)
14634- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14635- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14636+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14637
14638- stack = (unsigned long *)context->previous_esp;
14639- if (!stack)
14640+ if (stack_start == task_stack_page(task))
14641 break;
14642+ stack = *(unsigned long **)stack_start;
14643 if (ops->stack(data, "IRQ") < 0)
14644 break;
14645 touch_nmi_watchdog();
14646@@ -87,7 +85,7 @@ void show_regs(struct pt_regs *regs)
14647 int i;
14648
14649 print_modules();
14650- __show_regs(regs, !user_mode_vm(regs));
14651+ __show_regs(regs, !user_mode(regs));
14652
14653 printk(KERN_EMERG "Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
14654 TASK_COMM_LEN, current->comm, task_pid_nr(current),
14655@@ -96,21 +94,22 @@ void show_regs(struct pt_regs *regs)
14656 * When in-kernel, we also print out the stack and code at the
14657 * time of the fault..
14658 */
14659- if (!user_mode_vm(regs)) {
14660+ if (!user_mode(regs)) {
14661 unsigned int code_prologue = code_bytes * 43 / 64;
14662 unsigned int code_len = code_bytes;
14663 unsigned char c;
14664 u8 *ip;
14665+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14666
14667 printk(KERN_EMERG "Stack:\n");
14668 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14669
14670 printk(KERN_EMERG "Code: ");
14671
14672- ip = (u8 *)regs->ip - code_prologue;
14673+ ip = (u8 *)regs->ip - code_prologue + cs_base;
14674 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14675 /* try starting at IP */
14676- ip = (u8 *)regs->ip;
14677+ ip = (u8 *)regs->ip + cs_base;
14678 code_len = code_len - code_prologue + 1;
14679 }
14680 for (i = 0; i < code_len; i++, ip++) {
14681@@ -119,7 +118,7 @@ void show_regs(struct pt_regs *regs)
14682 printk(KERN_CONT " Bad EIP value.");
14683 break;
14684 }
14685- if (ip == (u8 *)regs->ip)
14686+ if (ip == (u8 *)regs->ip + cs_base)
14687 printk(KERN_CONT "<%02x> ", c);
14688 else
14689 printk(KERN_CONT "%02x ", c);
14690@@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
14691 {
14692 unsigned short ud2;
14693
14694+ ip = ktla_ktva(ip);
14695 if (ip < PAGE_OFFSET)
14696 return 0;
14697 if (probe_kernel_address((unsigned short *)ip, ud2))
14698@@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
14699
14700 return ud2 == 0x0b0f;
14701 }
14702+
14703+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14704+void pax_check_alloca(unsigned long size)
14705+{
14706+ unsigned long sp = (unsigned long)&sp, stack_left;
14707+
14708+ /* all kernel stacks are of the same size */
14709+ stack_left = sp & (THREAD_SIZE - 1);
14710+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14711+}
14712+EXPORT_SYMBOL(pax_check_alloca);
14713+#endif
14714diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14715index 791b761..2ab6e33 100644
14716--- a/arch/x86/kernel/dumpstack_64.c
14717+++ b/arch/x86/kernel/dumpstack_64.c
14718@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14719 unsigned long *irq_stack_end =
14720 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14721 unsigned used = 0;
14722- struct thread_info *tinfo;
14723 int graph = 0;
14724 unsigned long dummy;
14725+ void *stack_start;
14726
14727 if (!task)
14728 task = current;
14729@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14730 * current stack address. If the stacks consist of nested
14731 * exceptions
14732 */
14733- tinfo = task_thread_info(task);
14734 for (;;) {
14735 char *id;
14736 unsigned long *estack_end;
14737+
14738 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14739 &used, &id);
14740
14741@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14742 if (ops->stack(data, id) < 0)
14743 break;
14744
14745- bp = ops->walk_stack(tinfo, stack, bp, ops,
14746+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14747 data, estack_end, &graph);
14748 ops->stack(data, "<EOE>");
14749 /*
14750@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14751 * second-to-last pointer (index -2 to end) in the
14752 * exception stack:
14753 */
14754+ if ((u16)estack_end[-1] != __KERNEL_DS)
14755+ goto out;
14756 stack = (unsigned long *) estack_end[-2];
14757 continue;
14758 }
14759@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14760 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14761 if (ops->stack(data, "IRQ") < 0)
14762 break;
14763- bp = ops->walk_stack(tinfo, stack, bp,
14764+ bp = ops->walk_stack(task, irq_stack, stack, bp,
14765 ops, data, irq_stack_end, &graph);
14766 /*
14767 * We link to the next stack (which would be
14768@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14769 /*
14770 * This handles the process stack:
14771 */
14772- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14773+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14774+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14775+out:
14776 put_cpu();
14777 }
14778 EXPORT_SYMBOL(dump_trace);
14779@@ -305,3 +309,50 @@ int is_valid_bugaddr(unsigned long ip)
14780
14781 return ud2 == 0x0b0f;
14782 }
14783+
14784+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14785+void pax_check_alloca(unsigned long size)
14786+{
14787+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14788+ unsigned cpu, used;
14789+ char *id;
14790+
14791+ /* check the process stack first */
14792+ stack_start = (unsigned long)task_stack_page(current);
14793+ stack_end = stack_start + THREAD_SIZE;
14794+ if (likely(stack_start <= sp && sp < stack_end)) {
14795+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
14796+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14797+ return;
14798+ }
14799+
14800+ cpu = get_cpu();
14801+
14802+ /* check the irq stacks */
14803+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14804+ stack_start = stack_end - IRQ_STACK_SIZE;
14805+ if (stack_start <= sp && sp < stack_end) {
14806+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14807+ put_cpu();
14808+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14809+ return;
14810+ }
14811+
14812+ /* check the exception stacks */
14813+ used = 0;
14814+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14815+ stack_start = stack_end - EXCEPTION_STKSZ;
14816+ if (stack_end && stack_start <= sp && sp < stack_end) {
14817+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14818+ put_cpu();
14819+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14820+ return;
14821+ }
14822+
14823+ put_cpu();
14824+
14825+ /* unknown stack */
14826+ BUG();
14827+}
14828+EXPORT_SYMBOL(pax_check_alloca);
14829+#endif
14830diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14831index 9b9f18b..9fcaa04 100644
14832--- a/arch/x86/kernel/early_printk.c
14833+++ b/arch/x86/kernel/early_printk.c
14834@@ -7,6 +7,7 @@
14835 #include <linux/pci_regs.h>
14836 #include <linux/pci_ids.h>
14837 #include <linux/errno.h>
14838+#include <linux/sched.h>
14839 #include <asm/io.h>
14840 #include <asm/processor.h>
14841 #include <asm/fcntl.h>
14842diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14843index 623f288..8bdd78a 100644
14844--- a/arch/x86/kernel/entry_32.S
14845+++ b/arch/x86/kernel/entry_32.S
14846@@ -176,13 +176,153 @@
14847 /*CFI_REL_OFFSET gs, PT_GS*/
14848 .endm
14849 .macro SET_KERNEL_GS reg
14850+
14851+#ifdef CONFIG_CC_STACKPROTECTOR
14852 movl $(__KERNEL_STACK_CANARY), \reg
14853+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14854+ movl $(__USER_DS), \reg
14855+#else
14856+ xorl \reg, \reg
14857+#endif
14858+
14859 movl \reg, %gs
14860 .endm
14861
14862 #endif /* CONFIG_X86_32_LAZY_GS */
14863
14864-.macro SAVE_ALL
14865+.macro pax_enter_kernel
14866+#ifdef CONFIG_PAX_KERNEXEC
14867+ call pax_enter_kernel
14868+#endif
14869+.endm
14870+
14871+.macro pax_exit_kernel
14872+#ifdef CONFIG_PAX_KERNEXEC
14873+ call pax_exit_kernel
14874+#endif
14875+.endm
14876+
14877+#ifdef CONFIG_PAX_KERNEXEC
14878+ENTRY(pax_enter_kernel)
14879+#ifdef CONFIG_PARAVIRT
14880+ pushl %eax
14881+ pushl %ecx
14882+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
14883+ mov %eax, %esi
14884+#else
14885+ mov %cr0, %esi
14886+#endif
14887+ bts $16, %esi
14888+ jnc 1f
14889+ mov %cs, %esi
14890+ cmp $__KERNEL_CS, %esi
14891+ jz 3f
14892+ ljmp $__KERNEL_CS, $3f
14893+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
14894+2:
14895+#ifdef CONFIG_PARAVIRT
14896+ mov %esi, %eax
14897+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14898+#else
14899+ mov %esi, %cr0
14900+#endif
14901+3:
14902+#ifdef CONFIG_PARAVIRT
14903+ popl %ecx
14904+ popl %eax
14905+#endif
14906+ ret
14907+ENDPROC(pax_enter_kernel)
14908+
14909+ENTRY(pax_exit_kernel)
14910+#ifdef CONFIG_PARAVIRT
14911+ pushl %eax
14912+ pushl %ecx
14913+#endif
14914+ mov %cs, %esi
14915+ cmp $__KERNEXEC_KERNEL_CS, %esi
14916+ jnz 2f
14917+#ifdef CONFIG_PARAVIRT
14918+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
14919+ mov %eax, %esi
14920+#else
14921+ mov %cr0, %esi
14922+#endif
14923+ btr $16, %esi
14924+ ljmp $__KERNEL_CS, $1f
14925+1:
14926+#ifdef CONFIG_PARAVIRT
14927+ mov %esi, %eax
14928+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
14929+#else
14930+ mov %esi, %cr0
14931+#endif
14932+2:
14933+#ifdef CONFIG_PARAVIRT
14934+ popl %ecx
14935+ popl %eax
14936+#endif
14937+ ret
14938+ENDPROC(pax_exit_kernel)
14939+#endif
14940+
14941+.macro pax_erase_kstack
14942+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14943+ call pax_erase_kstack
14944+#endif
14945+.endm
14946+
14947+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14948+/*
14949+ * ebp: thread_info
14950+ */
14951+ENTRY(pax_erase_kstack)
14952+ pushl %edi
14953+ pushl %ecx
14954+ pushl %eax
14955+
14956+ mov TI_lowest_stack(%ebp), %edi
14957+ mov $-0xBEEF, %eax
14958+ std
14959+
14960+1: mov %edi, %ecx
14961+ and $THREAD_SIZE_asm - 1, %ecx
14962+ shr $2, %ecx
14963+ repne scasl
14964+ jecxz 2f
14965+
14966+ cmp $2*16, %ecx
14967+ jc 2f
14968+
14969+ mov $2*16, %ecx
14970+ repe scasl
14971+ jecxz 2f
14972+ jne 1b
14973+
14974+2: cld
14975+ mov %esp, %ecx
14976+ sub %edi, %ecx
14977+
14978+ cmp $THREAD_SIZE_asm, %ecx
14979+ jb 3f
14980+ ud2
14981+3:
14982+
14983+ shr $2, %ecx
14984+ rep stosl
14985+
14986+ mov TI_task_thread_sp0(%ebp), %edi
14987+ sub $128, %edi
14988+ mov %edi, TI_lowest_stack(%ebp)
14989+
14990+ popl %eax
14991+ popl %ecx
14992+ popl %edi
14993+ ret
14994+ENDPROC(pax_erase_kstack)
14995+#endif
14996+
14997+.macro __SAVE_ALL _DS
14998 cld
14999 PUSH_GS
15000 pushl_cfi %fs
15001@@ -205,7 +345,7 @@
15002 CFI_REL_OFFSET ecx, 0
15003 pushl_cfi %ebx
15004 CFI_REL_OFFSET ebx, 0
15005- movl $(__USER_DS), %edx
15006+ movl $\_DS, %edx
15007 movl %edx, %ds
15008 movl %edx, %es
15009 movl $(__KERNEL_PERCPU), %edx
15010@@ -213,6 +353,15 @@
15011 SET_KERNEL_GS %edx
15012 .endm
15013
15014+.macro SAVE_ALL
15015+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
15016+ __SAVE_ALL __KERNEL_DS
15017+ pax_enter_kernel
15018+#else
15019+ __SAVE_ALL __USER_DS
15020+#endif
15021+.endm
15022+
15023 .macro RESTORE_INT_REGS
15024 popl_cfi %ebx
15025 CFI_RESTORE ebx
15026@@ -296,7 +445,7 @@ ENTRY(ret_from_fork)
15027 popfl_cfi
15028 jmp syscall_exit
15029 CFI_ENDPROC
15030-END(ret_from_fork)
15031+ENDPROC(ret_from_fork)
15032
15033 /*
15034 * Interrupt exit functions should be protected against kprobes
15035@@ -329,7 +478,15 @@ ret_from_intr:
15036 andl $SEGMENT_RPL_MASK, %eax
15037 #endif
15038 cmpl $USER_RPL, %eax
15039+
15040+#ifdef CONFIG_PAX_KERNEXEC
15041+ jae resume_userspace
15042+
15043+ pax_exit_kernel
15044+ jmp resume_kernel
15045+#else
15046 jb resume_kernel # not returning to v8086 or userspace
15047+#endif
15048
15049 ENTRY(resume_userspace)
15050 LOCKDEP_SYS_EXIT
15051@@ -341,8 +498,8 @@ ENTRY(resume_userspace)
15052 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15053 # int/exception return?
15054 jne work_pending
15055- jmp restore_all
15056-END(ret_from_exception)
15057+ jmp restore_all_pax
15058+ENDPROC(ret_from_exception)
15059
15060 #ifdef CONFIG_PREEMPT
15061 ENTRY(resume_kernel)
15062@@ -357,7 +514,7 @@ need_resched:
15063 jz restore_all
15064 call preempt_schedule_irq
15065 jmp need_resched
15066-END(resume_kernel)
15067+ENDPROC(resume_kernel)
15068 #endif
15069 CFI_ENDPROC
15070 /*
15071@@ -391,28 +548,43 @@ sysenter_past_esp:
15072 /*CFI_REL_OFFSET cs, 0*/
15073 /*
15074 * Push current_thread_info()->sysenter_return to the stack.
15075- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15076- * pushed above; +8 corresponds to copy_thread's esp0 setting.
15077 */
15078- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15079+ pushl_cfi $0
15080 CFI_REL_OFFSET eip, 0
15081
15082 pushl_cfi %eax
15083 SAVE_ALL
15084+ GET_THREAD_INFO(%ebp)
15085+ movl TI_sysenter_return(%ebp),%ebp
15086+ movl %ebp,PT_EIP(%esp)
15087 ENABLE_INTERRUPTS(CLBR_NONE)
15088
15089 /*
15090 * Load the potential sixth argument from user stack.
15091 * Careful about security.
15092 */
15093+ movl PT_OLDESP(%esp),%ebp
15094+
15095+#ifdef CONFIG_PAX_MEMORY_UDEREF
15096+ mov PT_OLDSS(%esp),%ds
15097+1: movl %ds:(%ebp),%ebp
15098+ push %ss
15099+ pop %ds
15100+#else
15101 cmpl $__PAGE_OFFSET-3,%ebp
15102 jae syscall_fault
15103 1: movl (%ebp),%ebp
15104+#endif
15105+
15106 movl %ebp,PT_EBP(%esp)
15107 _ASM_EXTABLE(1b,syscall_fault)
15108
15109 GET_THREAD_INFO(%ebp)
15110
15111+#ifdef CONFIG_PAX_RANDKSTACK
15112+ pax_erase_kstack
15113+#endif
15114+
15115 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15116 jnz sysenter_audit
15117 sysenter_do_call:
15118@@ -427,12 +599,24 @@ sysenter_do_call:
15119 testl $_TIF_ALLWORK_MASK, %ecx
15120 jne sysexit_audit
15121 sysenter_exit:
15122+
15123+#ifdef CONFIG_PAX_RANDKSTACK
15124+ pushl_cfi %eax
15125+ movl %esp, %eax
15126+ call pax_randomize_kstack
15127+ popl_cfi %eax
15128+#endif
15129+
15130+ pax_erase_kstack
15131+
15132 /* if something modifies registers it must also disable sysexit */
15133 movl PT_EIP(%esp), %edx
15134 movl PT_OLDESP(%esp), %ecx
15135 xorl %ebp,%ebp
15136 TRACE_IRQS_ON
15137 1: mov PT_FS(%esp), %fs
15138+2: mov PT_DS(%esp), %ds
15139+3: mov PT_ES(%esp), %es
15140 PTGS_TO_GS
15141 ENABLE_INTERRUPTS_SYSEXIT
15142
15143@@ -449,6 +633,9 @@ sysenter_audit:
15144 movl %eax,%edx /* 2nd arg: syscall number */
15145 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15146 call __audit_syscall_entry
15147+
15148+ pax_erase_kstack
15149+
15150 pushl_cfi %ebx
15151 movl PT_EAX(%esp),%eax /* reload syscall number */
15152 jmp sysenter_do_call
15153@@ -474,10 +661,16 @@ sysexit_audit:
15154
15155 CFI_ENDPROC
15156 .pushsection .fixup,"ax"
15157-2: movl $0,PT_FS(%esp)
15158+4: movl $0,PT_FS(%esp)
15159+ jmp 1b
15160+5: movl $0,PT_DS(%esp)
15161+ jmp 1b
15162+6: movl $0,PT_ES(%esp)
15163 jmp 1b
15164 .popsection
15165- _ASM_EXTABLE(1b,2b)
15166+ _ASM_EXTABLE(1b,4b)
15167+ _ASM_EXTABLE(2b,5b)
15168+ _ASM_EXTABLE(3b,6b)
15169 PTGS_TO_GS_EX
15170 ENDPROC(ia32_sysenter_target)
15171
15172@@ -491,6 +684,11 @@ ENTRY(system_call)
15173 pushl_cfi %eax # save orig_eax
15174 SAVE_ALL
15175 GET_THREAD_INFO(%ebp)
15176+
15177+#ifdef CONFIG_PAX_RANDKSTACK
15178+ pax_erase_kstack
15179+#endif
15180+
15181 # system call tracing in operation / emulation
15182 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15183 jnz syscall_trace_entry
15184@@ -509,6 +707,15 @@ syscall_exit:
15185 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15186 jne syscall_exit_work
15187
15188+restore_all_pax:
15189+
15190+#ifdef CONFIG_PAX_RANDKSTACK
15191+ movl %esp, %eax
15192+ call pax_randomize_kstack
15193+#endif
15194+
15195+ pax_erase_kstack
15196+
15197 restore_all:
15198 TRACE_IRQS_IRET
15199 restore_all_notrace:
15200@@ -565,14 +772,34 @@ ldt_ss:
15201 * compensating for the offset by changing to the ESPFIX segment with
15202 * a base address that matches for the difference.
15203 */
15204-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15205+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15206 mov %esp, %edx /* load kernel esp */
15207 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15208 mov %dx, %ax /* eax: new kernel esp */
15209 sub %eax, %edx /* offset (low word is 0) */
15210+#ifdef CONFIG_SMP
15211+ movl PER_CPU_VAR(cpu_number), %ebx
15212+ shll $PAGE_SHIFT_asm, %ebx
15213+ addl $cpu_gdt_table, %ebx
15214+#else
15215+ movl $cpu_gdt_table, %ebx
15216+#endif
15217 shr $16, %edx
15218- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15219- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15220+
15221+#ifdef CONFIG_PAX_KERNEXEC
15222+ mov %cr0, %esi
15223+ btr $16, %esi
15224+ mov %esi, %cr0
15225+#endif
15226+
15227+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15228+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15229+
15230+#ifdef CONFIG_PAX_KERNEXEC
15231+ bts $16, %esi
15232+ mov %esi, %cr0
15233+#endif
15234+
15235 pushl_cfi $__ESPFIX_SS
15236 pushl_cfi %eax /* new kernel esp */
15237 /* Disable interrupts, but do not irqtrace this section: we
15238@@ -601,35 +828,23 @@ work_resched:
15239 movl TI_flags(%ebp), %ecx
15240 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15241 # than syscall tracing?
15242- jz restore_all
15243+ jz restore_all_pax
15244 testb $_TIF_NEED_RESCHED, %cl
15245 jnz work_resched
15246
15247 work_notifysig: # deal with pending signals and
15248 # notify-resume requests
15249+ movl %esp, %eax
15250 #ifdef CONFIG_VM86
15251 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15252- movl %esp, %eax
15253- jne work_notifysig_v86 # returning to kernel-space or
15254+ jz 1f # returning to kernel-space or
15255 # vm86-space
15256- TRACE_IRQS_ON
15257- ENABLE_INTERRUPTS(CLBR_NONE)
15258- movb PT_CS(%esp), %bl
15259- andb $SEGMENT_RPL_MASK, %bl
15260- cmpb $USER_RPL, %bl
15261- jb resume_kernel
15262- xorl %edx, %edx
15263- call do_notify_resume
15264- jmp resume_userspace
15265
15266- ALIGN
15267-work_notifysig_v86:
15268 pushl_cfi %ecx # save ti_flags for do_notify_resume
15269 call save_v86_state # %eax contains pt_regs pointer
15270 popl_cfi %ecx
15271 movl %eax, %esp
15272-#else
15273- movl %esp, %eax
15274+1:
15275 #endif
15276 TRACE_IRQS_ON
15277 ENABLE_INTERRUPTS(CLBR_NONE)
15278@@ -640,7 +855,7 @@ work_notifysig_v86:
15279 xorl %edx, %edx
15280 call do_notify_resume
15281 jmp resume_userspace
15282-END(work_pending)
15283+ENDPROC(work_pending)
15284
15285 # perform syscall exit tracing
15286 ALIGN
15287@@ -648,11 +863,14 @@ syscall_trace_entry:
15288 movl $-ENOSYS,PT_EAX(%esp)
15289 movl %esp, %eax
15290 call syscall_trace_enter
15291+
15292+ pax_erase_kstack
15293+
15294 /* What it returned is what we'll actually use. */
15295 cmpl $(NR_syscalls), %eax
15296 jnae syscall_call
15297 jmp syscall_exit
15298-END(syscall_trace_entry)
15299+ENDPROC(syscall_trace_entry)
15300
15301 # perform syscall exit tracing
15302 ALIGN
15303@@ -665,20 +883,24 @@ syscall_exit_work:
15304 movl %esp, %eax
15305 call syscall_trace_leave
15306 jmp resume_userspace
15307-END(syscall_exit_work)
15308+ENDPROC(syscall_exit_work)
15309 CFI_ENDPROC
15310
15311 RING0_INT_FRAME # can't unwind into user space anyway
15312 syscall_fault:
15313+#ifdef CONFIG_PAX_MEMORY_UDEREF
15314+ push %ss
15315+ pop %ds
15316+#endif
15317 GET_THREAD_INFO(%ebp)
15318 movl $-EFAULT,PT_EAX(%esp)
15319 jmp resume_userspace
15320-END(syscall_fault)
15321+ENDPROC(syscall_fault)
15322
15323 syscall_badsys:
15324 movl $-ENOSYS,PT_EAX(%esp)
15325 jmp resume_userspace
15326-END(syscall_badsys)
15327+ENDPROC(syscall_badsys)
15328 CFI_ENDPROC
15329 /*
15330 * End of kprobes section
15331@@ -750,6 +972,36 @@ ENTRY(ptregs_clone)
15332 CFI_ENDPROC
15333 ENDPROC(ptregs_clone)
15334
15335+ ALIGN;
15336+ENTRY(kernel_execve)
15337+ CFI_STARTPROC
15338+ pushl_cfi %ebp
15339+ sub $PT_OLDSS+4,%esp
15340+ pushl_cfi %edi
15341+ pushl_cfi %ecx
15342+ pushl_cfi %eax
15343+ lea 3*4(%esp),%edi
15344+ mov $PT_OLDSS/4+1,%ecx
15345+ xorl %eax,%eax
15346+ rep stosl
15347+ popl_cfi %eax
15348+ popl_cfi %ecx
15349+ popl_cfi %edi
15350+ movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15351+ pushl_cfi %esp
15352+ call sys_execve
15353+ add $4,%esp
15354+ CFI_ADJUST_CFA_OFFSET -4
15355+ GET_THREAD_INFO(%ebp)
15356+ test %eax,%eax
15357+ jz syscall_exit
15358+ add $PT_OLDSS+4,%esp
15359+ CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15360+ popl_cfi %ebp
15361+ ret
15362+ CFI_ENDPROC
15363+ENDPROC(kernel_execve)
15364+
15365 .macro FIXUP_ESPFIX_STACK
15366 /*
15367 * Switch back for ESPFIX stack to the normal zerobased stack
15368@@ -759,8 +1011,15 @@ ENDPROC(ptregs_clone)
15369 * normal stack and adjusts ESP with the matching offset.
15370 */
15371 /* fixup the stack */
15372- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15373- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15374+#ifdef CONFIG_SMP
15375+ movl PER_CPU_VAR(cpu_number), %ebx
15376+ shll $PAGE_SHIFT_asm, %ebx
15377+ addl $cpu_gdt_table, %ebx
15378+#else
15379+ movl $cpu_gdt_table, %ebx
15380+#endif
15381+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15382+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15383 shl $16, %eax
15384 addl %esp, %eax /* the adjusted stack pointer */
15385 pushl_cfi $__KERNEL_DS
15386@@ -813,7 +1072,7 @@ vector=vector+1
15387 .endr
15388 2: jmp common_interrupt
15389 .endr
15390-END(irq_entries_start)
15391+ENDPROC(irq_entries_start)
15392
15393 .previous
15394 END(interrupt)
15395@@ -861,7 +1120,7 @@ ENTRY(coprocessor_error)
15396 pushl_cfi $do_coprocessor_error
15397 jmp error_code
15398 CFI_ENDPROC
15399-END(coprocessor_error)
15400+ENDPROC(coprocessor_error)
15401
15402 ENTRY(simd_coprocessor_error)
15403 RING0_INT_FRAME
15404@@ -882,7 +1141,7 @@ ENTRY(simd_coprocessor_error)
15405 #endif
15406 jmp error_code
15407 CFI_ENDPROC
15408-END(simd_coprocessor_error)
15409+ENDPROC(simd_coprocessor_error)
15410
15411 ENTRY(device_not_available)
15412 RING0_INT_FRAME
15413@@ -890,18 +1149,18 @@ ENTRY(device_not_available)
15414 pushl_cfi $do_device_not_available
15415 jmp error_code
15416 CFI_ENDPROC
15417-END(device_not_available)
15418+ENDPROC(device_not_available)
15419
15420 #ifdef CONFIG_PARAVIRT
15421 ENTRY(native_iret)
15422 iret
15423 _ASM_EXTABLE(native_iret, iret_exc)
15424-END(native_iret)
15425+ENDPROC(native_iret)
15426
15427 ENTRY(native_irq_enable_sysexit)
15428 sti
15429 sysexit
15430-END(native_irq_enable_sysexit)
15431+ENDPROC(native_irq_enable_sysexit)
15432 #endif
15433
15434 ENTRY(overflow)
15435@@ -910,7 +1169,7 @@ ENTRY(overflow)
15436 pushl_cfi $do_overflow
15437 jmp error_code
15438 CFI_ENDPROC
15439-END(overflow)
15440+ENDPROC(overflow)
15441
15442 ENTRY(bounds)
15443 RING0_INT_FRAME
15444@@ -918,7 +1177,7 @@ ENTRY(bounds)
15445 pushl_cfi $do_bounds
15446 jmp error_code
15447 CFI_ENDPROC
15448-END(bounds)
15449+ENDPROC(bounds)
15450
15451 ENTRY(invalid_op)
15452 RING0_INT_FRAME
15453@@ -926,7 +1185,7 @@ ENTRY(invalid_op)
15454 pushl_cfi $do_invalid_op
15455 jmp error_code
15456 CFI_ENDPROC
15457-END(invalid_op)
15458+ENDPROC(invalid_op)
15459
15460 ENTRY(coprocessor_segment_overrun)
15461 RING0_INT_FRAME
15462@@ -934,35 +1193,35 @@ ENTRY(coprocessor_segment_overrun)
15463 pushl_cfi $do_coprocessor_segment_overrun
15464 jmp error_code
15465 CFI_ENDPROC
15466-END(coprocessor_segment_overrun)
15467+ENDPROC(coprocessor_segment_overrun)
15468
15469 ENTRY(invalid_TSS)
15470 RING0_EC_FRAME
15471 pushl_cfi $do_invalid_TSS
15472 jmp error_code
15473 CFI_ENDPROC
15474-END(invalid_TSS)
15475+ENDPROC(invalid_TSS)
15476
15477 ENTRY(segment_not_present)
15478 RING0_EC_FRAME
15479 pushl_cfi $do_segment_not_present
15480 jmp error_code
15481 CFI_ENDPROC
15482-END(segment_not_present)
15483+ENDPROC(segment_not_present)
15484
15485 ENTRY(stack_segment)
15486 RING0_EC_FRAME
15487 pushl_cfi $do_stack_segment
15488 jmp error_code
15489 CFI_ENDPROC
15490-END(stack_segment)
15491+ENDPROC(stack_segment)
15492
15493 ENTRY(alignment_check)
15494 RING0_EC_FRAME
15495 pushl_cfi $do_alignment_check
15496 jmp error_code
15497 CFI_ENDPROC
15498-END(alignment_check)
15499+ENDPROC(alignment_check)
15500
15501 ENTRY(divide_error)
15502 RING0_INT_FRAME
15503@@ -970,7 +1229,7 @@ ENTRY(divide_error)
15504 pushl_cfi $do_divide_error
15505 jmp error_code
15506 CFI_ENDPROC
15507-END(divide_error)
15508+ENDPROC(divide_error)
15509
15510 #ifdef CONFIG_X86_MCE
15511 ENTRY(machine_check)
15512@@ -979,7 +1238,7 @@ ENTRY(machine_check)
15513 pushl_cfi machine_check_vector
15514 jmp error_code
15515 CFI_ENDPROC
15516-END(machine_check)
15517+ENDPROC(machine_check)
15518 #endif
15519
15520 ENTRY(spurious_interrupt_bug)
15521@@ -988,7 +1247,7 @@ ENTRY(spurious_interrupt_bug)
15522 pushl_cfi $do_spurious_interrupt_bug
15523 jmp error_code
15524 CFI_ENDPROC
15525-END(spurious_interrupt_bug)
15526+ENDPROC(spurious_interrupt_bug)
15527 /*
15528 * End of kprobes section
15529 */
15530@@ -1100,7 +1359,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15531
15532 ENTRY(mcount)
15533 ret
15534-END(mcount)
15535+ENDPROC(mcount)
15536
15537 ENTRY(ftrace_caller)
15538 cmpl $0, function_trace_stop
15539@@ -1129,7 +1388,7 @@ ftrace_graph_call:
15540 .globl ftrace_stub
15541 ftrace_stub:
15542 ret
15543-END(ftrace_caller)
15544+ENDPROC(ftrace_caller)
15545
15546 #else /* ! CONFIG_DYNAMIC_FTRACE */
15547
15548@@ -1165,7 +1424,7 @@ trace:
15549 popl %ecx
15550 popl %eax
15551 jmp ftrace_stub
15552-END(mcount)
15553+ENDPROC(mcount)
15554 #endif /* CONFIG_DYNAMIC_FTRACE */
15555 #endif /* CONFIG_FUNCTION_TRACER */
15556
15557@@ -1186,7 +1445,7 @@ ENTRY(ftrace_graph_caller)
15558 popl %ecx
15559 popl %eax
15560 ret
15561-END(ftrace_graph_caller)
15562+ENDPROC(ftrace_graph_caller)
15563
15564 .globl return_to_handler
15565 return_to_handler:
15566@@ -1241,15 +1500,18 @@ error_code:
15567 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15568 REG_TO_PTGS %ecx
15569 SET_KERNEL_GS %ecx
15570- movl $(__USER_DS), %ecx
15571+ movl $(__KERNEL_DS), %ecx
15572 movl %ecx, %ds
15573 movl %ecx, %es
15574+
15575+ pax_enter_kernel
15576+
15577 TRACE_IRQS_OFF
15578 movl %esp,%eax # pt_regs pointer
15579 call *%edi
15580 jmp ret_from_exception
15581 CFI_ENDPROC
15582-END(page_fault)
15583+ENDPROC(page_fault)
15584
15585 /*
15586 * Debug traps and NMI can happen at the one SYSENTER instruction
15587@@ -1291,7 +1553,7 @@ debug_stack_correct:
15588 call do_debug
15589 jmp ret_from_exception
15590 CFI_ENDPROC
15591-END(debug)
15592+ENDPROC(debug)
15593
15594 /*
15595 * NMI is doubly nasty. It can happen _while_ we're handling
15596@@ -1328,6 +1590,9 @@ nmi_stack_correct:
15597 xorl %edx,%edx # zero error code
15598 movl %esp,%eax # pt_regs pointer
15599 call do_nmi
15600+
15601+ pax_exit_kernel
15602+
15603 jmp restore_all_notrace
15604 CFI_ENDPROC
15605
15606@@ -1364,12 +1629,15 @@ nmi_espfix_stack:
15607 FIXUP_ESPFIX_STACK # %eax == %esp
15608 xorl %edx,%edx # zero error code
15609 call do_nmi
15610+
15611+ pax_exit_kernel
15612+
15613 RESTORE_REGS
15614 lss 12+4(%esp), %esp # back to espfix stack
15615 CFI_ADJUST_CFA_OFFSET -24
15616 jmp irq_return
15617 CFI_ENDPROC
15618-END(nmi)
15619+ENDPROC(nmi)
15620
15621 ENTRY(int3)
15622 RING0_INT_FRAME
15623@@ -1381,14 +1649,14 @@ ENTRY(int3)
15624 call do_int3
15625 jmp ret_from_exception
15626 CFI_ENDPROC
15627-END(int3)
15628+ENDPROC(int3)
15629
15630 ENTRY(general_protection)
15631 RING0_EC_FRAME
15632 pushl_cfi $do_general_protection
15633 jmp error_code
15634 CFI_ENDPROC
15635-END(general_protection)
15636+ENDPROC(general_protection)
15637
15638 #ifdef CONFIG_KVM_GUEST
15639 ENTRY(async_page_fault)
15640@@ -1396,7 +1664,7 @@ ENTRY(async_page_fault)
15641 pushl_cfi $do_async_page_fault
15642 jmp error_code
15643 CFI_ENDPROC
15644-END(async_page_fault)
15645+ENDPROC(async_page_fault)
15646 #endif
15647
15648 /*
15649diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15650index 7d65133..c888d5f 100644
15651--- a/arch/x86/kernel/entry_64.S
15652+++ b/arch/x86/kernel/entry_64.S
15653@@ -57,6 +57,8 @@
15654 #include <asm/percpu.h>
15655 #include <asm/asm.h>
15656 #include <linux/err.h>
15657+#include <asm/pgtable.h>
15658+#include <asm/alternative-asm.h>
15659
15660 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15661 #include <linux/elf-em.h>
15662@@ -70,8 +72,9 @@
15663 #ifdef CONFIG_FUNCTION_TRACER
15664 #ifdef CONFIG_DYNAMIC_FTRACE
15665 ENTRY(mcount)
15666+ pax_force_retaddr
15667 retq
15668-END(mcount)
15669+ENDPROC(mcount)
15670
15671 ENTRY(ftrace_caller)
15672 cmpl $0, function_trace_stop
15673@@ -94,8 +97,9 @@ GLOBAL(ftrace_graph_call)
15674 #endif
15675
15676 GLOBAL(ftrace_stub)
15677+ pax_force_retaddr
15678 retq
15679-END(ftrace_caller)
15680+ENDPROC(ftrace_caller)
15681
15682 #else /* ! CONFIG_DYNAMIC_FTRACE */
15683 ENTRY(mcount)
15684@@ -114,6 +118,7 @@ ENTRY(mcount)
15685 #endif
15686
15687 GLOBAL(ftrace_stub)
15688+ pax_force_retaddr
15689 retq
15690
15691 trace:
15692@@ -123,12 +128,13 @@ trace:
15693 movq 8(%rbp), %rsi
15694 subq $MCOUNT_INSN_SIZE, %rdi
15695
15696+ pax_force_fptr ftrace_trace_function
15697 call *ftrace_trace_function
15698
15699 MCOUNT_RESTORE_FRAME
15700
15701 jmp ftrace_stub
15702-END(mcount)
15703+ENDPROC(mcount)
15704 #endif /* CONFIG_DYNAMIC_FTRACE */
15705 #endif /* CONFIG_FUNCTION_TRACER */
15706
15707@@ -148,8 +154,9 @@ ENTRY(ftrace_graph_caller)
15708
15709 MCOUNT_RESTORE_FRAME
15710
15711+ pax_force_retaddr
15712 retq
15713-END(ftrace_graph_caller)
15714+ENDPROC(ftrace_graph_caller)
15715
15716 GLOBAL(return_to_handler)
15717 subq $24, %rsp
15718@@ -165,6 +172,7 @@ GLOBAL(return_to_handler)
15719 movq 8(%rsp), %rdx
15720 movq (%rsp), %rax
15721 addq $24, %rsp
15722+ pax_force_fptr %rdi
15723 jmp *%rdi
15724 #endif
15725
15726@@ -180,6 +188,280 @@ ENTRY(native_usergs_sysret64)
15727 ENDPROC(native_usergs_sysret64)
15728 #endif /* CONFIG_PARAVIRT */
15729
15730+ .macro ljmpq sel, off
15731+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15732+ .byte 0x48; ljmp *1234f(%rip)
15733+ .pushsection .rodata
15734+ .align 16
15735+ 1234: .quad \off; .word \sel
15736+ .popsection
15737+#else
15738+ pushq $\sel
15739+ pushq $\off
15740+ lretq
15741+#endif
15742+ .endm
15743+
15744+ .macro pax_enter_kernel
15745+ pax_set_fptr_mask
15746+#ifdef CONFIG_PAX_KERNEXEC
15747+ call pax_enter_kernel
15748+#endif
15749+ .endm
15750+
15751+ .macro pax_exit_kernel
15752+#ifdef CONFIG_PAX_KERNEXEC
15753+ call pax_exit_kernel
15754+#endif
15755+ .endm
15756+
15757+#ifdef CONFIG_PAX_KERNEXEC
15758+ENTRY(pax_enter_kernel)
15759+ pushq %rdi
15760+
15761+#ifdef CONFIG_PARAVIRT
15762+ PV_SAVE_REGS(CLBR_RDI)
15763+#endif
15764+
15765+ GET_CR0_INTO_RDI
15766+ bts $16,%rdi
15767+ jnc 3f
15768+ mov %cs,%edi
15769+ cmp $__KERNEL_CS,%edi
15770+ jnz 2f
15771+1:
15772+
15773+#ifdef CONFIG_PARAVIRT
15774+ PV_RESTORE_REGS(CLBR_RDI)
15775+#endif
15776+
15777+ popq %rdi
15778+ pax_force_retaddr
15779+ retq
15780+
15781+2: ljmpq __KERNEL_CS,1f
15782+3: ljmpq __KERNEXEC_KERNEL_CS,4f
15783+4: SET_RDI_INTO_CR0
15784+ jmp 1b
15785+ENDPROC(pax_enter_kernel)
15786+
15787+ENTRY(pax_exit_kernel)
15788+ pushq %rdi
15789+
15790+#ifdef CONFIG_PARAVIRT
15791+ PV_SAVE_REGS(CLBR_RDI)
15792+#endif
15793+
15794+ mov %cs,%rdi
15795+ cmp $__KERNEXEC_KERNEL_CS,%edi
15796+ jz 2f
15797+1:
15798+
15799+#ifdef CONFIG_PARAVIRT
15800+ PV_RESTORE_REGS(CLBR_RDI);
15801+#endif
15802+
15803+ popq %rdi
15804+ pax_force_retaddr
15805+ retq
15806+
15807+2: GET_CR0_INTO_RDI
15808+ btr $16,%rdi
15809+ ljmpq __KERNEL_CS,3f
15810+3: SET_RDI_INTO_CR0
15811+ jmp 1b
15812+#ifdef CONFIG_PARAVIRT
15813+ PV_RESTORE_REGS(CLBR_RDI);
15814+#endif
15815+
15816+ popq %rdi
15817+ pax_force_retaddr
15818+ retq
15819+ENDPROC(pax_exit_kernel)
15820+#endif
15821+
15822+ .macro pax_enter_kernel_user
15823+ pax_set_fptr_mask
15824+#ifdef CONFIG_PAX_MEMORY_UDEREF
15825+ call pax_enter_kernel_user
15826+#endif
15827+ .endm
15828+
15829+ .macro pax_exit_kernel_user
15830+#ifdef CONFIG_PAX_MEMORY_UDEREF
15831+ call pax_exit_kernel_user
15832+#endif
15833+#ifdef CONFIG_PAX_RANDKSTACK
15834+ pushq %rax
15835+ call pax_randomize_kstack
15836+ popq %rax
15837+#endif
15838+ .endm
15839+
15840+#ifdef CONFIG_PAX_MEMORY_UDEREF
15841+ENTRY(pax_enter_kernel_user)
15842+ pushq %rdi
15843+ pushq %rbx
15844+
15845+#ifdef CONFIG_PARAVIRT
15846+ PV_SAVE_REGS(CLBR_RDI)
15847+#endif
15848+
15849+ GET_CR3_INTO_RDI
15850+ mov %rdi,%rbx
15851+ add $__START_KERNEL_map,%rbx
15852+ sub phys_base(%rip),%rbx
15853+
15854+#ifdef CONFIG_PARAVIRT
15855+ pushq %rdi
15856+ cmpl $0, pv_info+PARAVIRT_enabled
15857+ jz 1f
15858+ i = 0
15859+ .rept USER_PGD_PTRS
15860+ mov i*8(%rbx),%rsi
15861+ mov $0,%sil
15862+ lea i*8(%rbx),%rdi
15863+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15864+ i = i + 1
15865+ .endr
15866+ jmp 2f
15867+1:
15868+#endif
15869+
15870+ i = 0
15871+ .rept USER_PGD_PTRS
15872+ movb $0,i*8(%rbx)
15873+ i = i + 1
15874+ .endr
15875+
15876+#ifdef CONFIG_PARAVIRT
15877+2: popq %rdi
15878+#endif
15879+ SET_RDI_INTO_CR3
15880+
15881+#ifdef CONFIG_PAX_KERNEXEC
15882+ GET_CR0_INTO_RDI
15883+ bts $16,%rdi
15884+ SET_RDI_INTO_CR0
15885+#endif
15886+
15887+#ifdef CONFIG_PARAVIRT
15888+ PV_RESTORE_REGS(CLBR_RDI)
15889+#endif
15890+
15891+ popq %rbx
15892+ popq %rdi
15893+ pax_force_retaddr
15894+ retq
15895+ENDPROC(pax_enter_kernel_user)
15896+
15897+ENTRY(pax_exit_kernel_user)
15898+ push %rdi
15899+
15900+#ifdef CONFIG_PARAVIRT
15901+ pushq %rbx
15902+ PV_SAVE_REGS(CLBR_RDI)
15903+#endif
15904+
15905+#ifdef CONFIG_PAX_KERNEXEC
15906+ GET_CR0_INTO_RDI
15907+ btr $16,%rdi
15908+ SET_RDI_INTO_CR0
15909+#endif
15910+
15911+ GET_CR3_INTO_RDI
15912+ add $__START_KERNEL_map,%rdi
15913+ sub phys_base(%rip),%rdi
15914+
15915+#ifdef CONFIG_PARAVIRT
15916+ cmpl $0, pv_info+PARAVIRT_enabled
15917+ jz 1f
15918+ mov %rdi,%rbx
15919+ i = 0
15920+ .rept USER_PGD_PTRS
15921+ mov i*8(%rbx),%rsi
15922+ mov $0x67,%sil
15923+ lea i*8(%rbx),%rdi
15924+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15925+ i = i + 1
15926+ .endr
15927+ jmp 2f
15928+1:
15929+#endif
15930+
15931+ i = 0
15932+ .rept USER_PGD_PTRS
15933+ movb $0x67,i*8(%rdi)
15934+ i = i + 1
15935+ .endr
15936+
15937+#ifdef CONFIG_PARAVIRT
15938+2: PV_RESTORE_REGS(CLBR_RDI)
15939+ popq %rbx
15940+#endif
15941+
15942+ popq %rdi
15943+ pax_force_retaddr
15944+ retq
15945+ENDPROC(pax_exit_kernel_user)
15946+#endif
15947+
15948+.macro pax_erase_kstack
15949+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15950+ call pax_erase_kstack
15951+#endif
15952+.endm
15953+
15954+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15955+ENTRY(pax_erase_kstack)
15956+ pushq %rdi
15957+ pushq %rcx
15958+ pushq %rax
15959+ pushq %r11
15960+
15961+ GET_THREAD_INFO(%r11)
15962+ mov TI_lowest_stack(%r11), %rdi
15963+ mov $-0xBEEF, %rax
15964+ std
15965+
15966+1: mov %edi, %ecx
15967+ and $THREAD_SIZE_asm - 1, %ecx
15968+ shr $3, %ecx
15969+ repne scasq
15970+ jecxz 2f
15971+
15972+ cmp $2*8, %ecx
15973+ jc 2f
15974+
15975+ mov $2*8, %ecx
15976+ repe scasq
15977+ jecxz 2f
15978+ jne 1b
15979+
15980+2: cld
15981+ mov %esp, %ecx
15982+ sub %edi, %ecx
15983+
15984+ cmp $THREAD_SIZE_asm, %rcx
15985+ jb 3f
15986+ ud2
15987+3:
15988+
15989+ shr $3, %ecx
15990+ rep stosq
15991+
15992+ mov TI_task_thread_sp0(%r11), %rdi
15993+ sub $256, %rdi
15994+ mov %rdi, TI_lowest_stack(%r11)
15995+
15996+ popq %r11
15997+ popq %rax
15998+ popq %rcx
15999+ popq %rdi
16000+ pax_force_retaddr
16001+ ret
16002+ENDPROC(pax_erase_kstack)
16003+#endif
16004
16005 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
16006 #ifdef CONFIG_TRACE_IRQFLAGS
16007@@ -271,8 +553,8 @@ ENDPROC(native_usergs_sysret64)
16008 .endm
16009
16010 .macro UNFAKE_STACK_FRAME
16011- addq $8*6, %rsp
16012- CFI_ADJUST_CFA_OFFSET -(6*8)
16013+ addq $8*6 + ARG_SKIP, %rsp
16014+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
16015 .endm
16016
16017 /*
16018@@ -359,7 +641,7 @@ ENDPROC(native_usergs_sysret64)
16019 movq %rsp, %rsi
16020
16021 leaq -RBP(%rsp),%rdi /* arg1 for handler */
16022- testl $3, CS-RBP(%rsi)
16023+ testb $3, CS-RBP(%rsi)
16024 je 1f
16025 SWAPGS
16026 /*
16027@@ -394,9 +676,10 @@ ENTRY(save_rest)
16028 movq_cfi r15, R15+16
16029 movq %r11, 8(%rsp) /* return address */
16030 FIXUP_TOP_OF_STACK %r11, 16
16031+ pax_force_retaddr
16032 ret
16033 CFI_ENDPROC
16034-END(save_rest)
16035+ENDPROC(save_rest)
16036
16037 /* save complete stack frame */
16038 .pushsection .kprobes.text, "ax"
16039@@ -425,9 +708,10 @@ ENTRY(save_paranoid)
16040 js 1f /* negative -> in kernel */
16041 SWAPGS
16042 xorl %ebx,%ebx
16043-1: ret
16044+1: pax_force_retaddr_bts
16045+ ret
16046 CFI_ENDPROC
16047-END(save_paranoid)
16048+ENDPROC(save_paranoid)
16049 .popsection
16050
16051 /*
16052@@ -449,7 +733,7 @@ ENTRY(ret_from_fork)
16053
16054 RESTORE_REST
16055
16056- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16057+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16058 jz retint_restore_args
16059
16060 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16061@@ -459,7 +743,7 @@ ENTRY(ret_from_fork)
16062 jmp ret_from_sys_call # go to the SYSRET fastpath
16063
16064 CFI_ENDPROC
16065-END(ret_from_fork)
16066+ENDPROC(ret_from_fork)
16067
16068 /*
16069 * System call entry. Up to 6 arguments in registers are supported.
16070@@ -495,7 +779,7 @@ END(ret_from_fork)
16071 ENTRY(system_call)
16072 CFI_STARTPROC simple
16073 CFI_SIGNAL_FRAME
16074- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16075+ CFI_DEF_CFA rsp,0
16076 CFI_REGISTER rip,rcx
16077 /*CFI_REGISTER rflags,r11*/
16078 SWAPGS_UNSAFE_STACK
16079@@ -508,16 +792,23 @@ GLOBAL(system_call_after_swapgs)
16080
16081 movq %rsp,PER_CPU_VAR(old_rsp)
16082 movq PER_CPU_VAR(kernel_stack),%rsp
16083+ SAVE_ARGS 8*6,0
16084+ pax_enter_kernel_user
16085+
16086+#ifdef CONFIG_PAX_RANDKSTACK
16087+ pax_erase_kstack
16088+#endif
16089+
16090 /*
16091 * No need to follow this irqs off/on section - it's straight
16092 * and short:
16093 */
16094 ENABLE_INTERRUPTS(CLBR_NONE)
16095- SAVE_ARGS 8,0
16096 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16097 movq %rcx,RIP-ARGOFFSET(%rsp)
16098 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16099- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16100+ GET_THREAD_INFO(%rcx)
16101+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16102 jnz tracesys
16103 system_call_fastpath:
16104 #if __SYSCALL_MASK == ~0
16105@@ -527,7 +818,7 @@ system_call_fastpath:
16106 cmpl $__NR_syscall_max,%eax
16107 #endif
16108 ja badsys
16109- movq %r10,%rcx
16110+ movq R10-ARGOFFSET(%rsp),%rcx
16111 call *sys_call_table(,%rax,8) # XXX: rip relative
16112 movq %rax,RAX-ARGOFFSET(%rsp)
16113 /*
16114@@ -541,10 +832,13 @@ sysret_check:
16115 LOCKDEP_SYS_EXIT
16116 DISABLE_INTERRUPTS(CLBR_NONE)
16117 TRACE_IRQS_OFF
16118- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16119+ GET_THREAD_INFO(%rcx)
16120+ movl TI_flags(%rcx),%edx
16121 andl %edi,%edx
16122 jnz sysret_careful
16123 CFI_REMEMBER_STATE
16124+ pax_exit_kernel_user
16125+ pax_erase_kstack
16126 /*
16127 * sysretq will re-enable interrupts:
16128 */
16129@@ -596,14 +890,18 @@ badsys:
16130 * jump back to the normal fast path.
16131 */
16132 auditsys:
16133- movq %r10,%r9 /* 6th arg: 4th syscall arg */
16134+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16135 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16136 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16137 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16138 movq %rax,%rsi /* 2nd arg: syscall number */
16139 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16140 call __audit_syscall_entry
16141+
16142+ pax_erase_kstack
16143+
16144 LOAD_ARGS 0 /* reload call-clobbered registers */
16145+ pax_set_fptr_mask
16146 jmp system_call_fastpath
16147
16148 /*
16149@@ -624,7 +922,7 @@ sysret_audit:
16150 /* Do syscall tracing */
16151 tracesys:
16152 #ifdef CONFIG_AUDITSYSCALL
16153- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16154+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16155 jz auditsys
16156 #endif
16157 SAVE_REST
16158@@ -632,12 +930,16 @@ tracesys:
16159 FIXUP_TOP_OF_STACK %rdi
16160 movq %rsp,%rdi
16161 call syscall_trace_enter
16162+
16163+ pax_erase_kstack
16164+
16165 /*
16166 * Reload arg registers from stack in case ptrace changed them.
16167 * We don't reload %rax because syscall_trace_enter() returned
16168 * the value it wants us to use in the table lookup.
16169 */
16170 LOAD_ARGS ARGOFFSET, 1
16171+ pax_set_fptr_mask
16172 RESTORE_REST
16173 #if __SYSCALL_MASK == ~0
16174 cmpq $__NR_syscall_max,%rax
16175@@ -646,7 +948,7 @@ tracesys:
16176 cmpl $__NR_syscall_max,%eax
16177 #endif
16178 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16179- movq %r10,%rcx /* fixup for C */
16180+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16181 call *sys_call_table(,%rax,8)
16182 movq %rax,RAX-ARGOFFSET(%rsp)
16183 /* Use IRET because user could have changed frame */
16184@@ -667,7 +969,9 @@ GLOBAL(int_with_check)
16185 andl %edi,%edx
16186 jnz int_careful
16187 andl $~TS_COMPAT,TI_status(%rcx)
16188- jmp retint_swapgs
16189+ pax_exit_kernel_user
16190+ pax_erase_kstack
16191+ jmp retint_swapgs_pax
16192
16193 /* Either reschedule or signal or syscall exit tracking needed. */
16194 /* First do a reschedule test. */
16195@@ -713,7 +1017,7 @@ int_restore_rest:
16196 TRACE_IRQS_OFF
16197 jmp int_with_check
16198 CFI_ENDPROC
16199-END(system_call)
16200+ENDPROC(system_call)
16201
16202 /*
16203 * Certain special system calls that need to save a complete full stack frame.
16204@@ -729,7 +1033,7 @@ ENTRY(\label)
16205 call \func
16206 jmp ptregscall_common
16207 CFI_ENDPROC
16208-END(\label)
16209+ENDPROC(\label)
16210 .endm
16211
16212 PTREGSCALL stub_clone, sys_clone, %r8
16213@@ -747,9 +1051,10 @@ ENTRY(ptregscall_common)
16214 movq_cfi_restore R12+8, r12
16215 movq_cfi_restore RBP+8, rbp
16216 movq_cfi_restore RBX+8, rbx
16217+ pax_force_retaddr
16218 ret $REST_SKIP /* pop extended registers */
16219 CFI_ENDPROC
16220-END(ptregscall_common)
16221+ENDPROC(ptregscall_common)
16222
16223 ENTRY(stub_execve)
16224 CFI_STARTPROC
16225@@ -764,7 +1069,7 @@ ENTRY(stub_execve)
16226 RESTORE_REST
16227 jmp int_ret_from_sys_call
16228 CFI_ENDPROC
16229-END(stub_execve)
16230+ENDPROC(stub_execve)
16231
16232 /*
16233 * sigreturn is special because it needs to restore all registers on return.
16234@@ -782,7 +1087,7 @@ ENTRY(stub_rt_sigreturn)
16235 RESTORE_REST
16236 jmp int_ret_from_sys_call
16237 CFI_ENDPROC
16238-END(stub_rt_sigreturn)
16239+ENDPROC(stub_rt_sigreturn)
16240
16241 #ifdef CONFIG_X86_X32_ABI
16242 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16243@@ -851,7 +1156,7 @@ vector=vector+1
16244 2: jmp common_interrupt
16245 .endr
16246 CFI_ENDPROC
16247-END(irq_entries_start)
16248+ENDPROC(irq_entries_start)
16249
16250 .previous
16251 END(interrupt)
16252@@ -871,6 +1176,16 @@ END(interrupt)
16253 subq $ORIG_RAX-RBP, %rsp
16254 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16255 SAVE_ARGS_IRQ
16256+#ifdef CONFIG_PAX_MEMORY_UDEREF
16257+ testb $3, CS(%rdi)
16258+ jnz 1f
16259+ pax_enter_kernel
16260+ jmp 2f
16261+1: pax_enter_kernel_user
16262+2:
16263+#else
16264+ pax_enter_kernel
16265+#endif
16266 call \func
16267 .endm
16268
16269@@ -902,7 +1217,7 @@ ret_from_intr:
16270
16271 exit_intr:
16272 GET_THREAD_INFO(%rcx)
16273- testl $3,CS-ARGOFFSET(%rsp)
16274+ testb $3,CS-ARGOFFSET(%rsp)
16275 je retint_kernel
16276
16277 /* Interrupt came from user space */
16278@@ -924,12 +1239,16 @@ retint_swapgs: /* return to user-space */
16279 * The iretq could re-enable interrupts:
16280 */
16281 DISABLE_INTERRUPTS(CLBR_ANY)
16282+ pax_exit_kernel_user
16283+retint_swapgs_pax:
16284 TRACE_IRQS_IRETQ
16285 SWAPGS
16286 jmp restore_args
16287
16288 retint_restore_args: /* return to kernel space */
16289 DISABLE_INTERRUPTS(CLBR_ANY)
16290+ pax_exit_kernel
16291+ pax_force_retaddr RIP-ARGOFFSET
16292 /*
16293 * The iretq could re-enable interrupts:
16294 */
16295@@ -1012,7 +1331,7 @@ ENTRY(retint_kernel)
16296 #endif
16297
16298 CFI_ENDPROC
16299-END(common_interrupt)
16300+ENDPROC(common_interrupt)
16301 /*
16302 * End of kprobes section
16303 */
16304@@ -1029,7 +1348,7 @@ ENTRY(\sym)
16305 interrupt \do_sym
16306 jmp ret_from_intr
16307 CFI_ENDPROC
16308-END(\sym)
16309+ENDPROC(\sym)
16310 .endm
16311
16312 #ifdef CONFIG_SMP
16313@@ -1102,12 +1421,22 @@ ENTRY(\sym)
16314 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16315 call error_entry
16316 DEFAULT_FRAME 0
16317+#ifdef CONFIG_PAX_MEMORY_UDEREF
16318+ testb $3, CS(%rsp)
16319+ jnz 1f
16320+ pax_enter_kernel
16321+ jmp 2f
16322+1: pax_enter_kernel_user
16323+2:
16324+#else
16325+ pax_enter_kernel
16326+#endif
16327 movq %rsp,%rdi /* pt_regs pointer */
16328 xorl %esi,%esi /* no error code */
16329 call \do_sym
16330 jmp error_exit /* %ebx: no swapgs flag */
16331 CFI_ENDPROC
16332-END(\sym)
16333+ENDPROC(\sym)
16334 .endm
16335
16336 .macro paranoidzeroentry sym do_sym
16337@@ -1119,15 +1448,25 @@ ENTRY(\sym)
16338 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16339 call save_paranoid
16340 TRACE_IRQS_OFF
16341+#ifdef CONFIG_PAX_MEMORY_UDEREF
16342+ testb $3, CS(%rsp)
16343+ jnz 1f
16344+ pax_enter_kernel
16345+ jmp 2f
16346+1: pax_enter_kernel_user
16347+2:
16348+#else
16349+ pax_enter_kernel
16350+#endif
16351 movq %rsp,%rdi /* pt_regs pointer */
16352 xorl %esi,%esi /* no error code */
16353 call \do_sym
16354 jmp paranoid_exit /* %ebx: no swapgs flag */
16355 CFI_ENDPROC
16356-END(\sym)
16357+ENDPROC(\sym)
16358 .endm
16359
16360-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16361+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16362 .macro paranoidzeroentry_ist sym do_sym ist
16363 ENTRY(\sym)
16364 INTR_FRAME
16365@@ -1137,14 +1476,30 @@ ENTRY(\sym)
16366 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16367 call save_paranoid
16368 TRACE_IRQS_OFF_DEBUG
16369+#ifdef CONFIG_PAX_MEMORY_UDEREF
16370+ testb $3, CS(%rsp)
16371+ jnz 1f
16372+ pax_enter_kernel
16373+ jmp 2f
16374+1: pax_enter_kernel_user
16375+2:
16376+#else
16377+ pax_enter_kernel
16378+#endif
16379 movq %rsp,%rdi /* pt_regs pointer */
16380 xorl %esi,%esi /* no error code */
16381+#ifdef CONFIG_SMP
16382+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16383+ lea init_tss(%r12), %r12
16384+#else
16385+ lea init_tss(%rip), %r12
16386+#endif
16387 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16388 call \do_sym
16389 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16390 jmp paranoid_exit /* %ebx: no swapgs flag */
16391 CFI_ENDPROC
16392-END(\sym)
16393+ENDPROC(\sym)
16394 .endm
16395
16396 .macro errorentry sym do_sym
16397@@ -1155,13 +1510,23 @@ ENTRY(\sym)
16398 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16399 call error_entry
16400 DEFAULT_FRAME 0
16401+#ifdef CONFIG_PAX_MEMORY_UDEREF
16402+ testb $3, CS(%rsp)
16403+ jnz 1f
16404+ pax_enter_kernel
16405+ jmp 2f
16406+1: pax_enter_kernel_user
16407+2:
16408+#else
16409+ pax_enter_kernel
16410+#endif
16411 movq %rsp,%rdi /* pt_regs pointer */
16412 movq ORIG_RAX(%rsp),%rsi /* get error code */
16413 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16414 call \do_sym
16415 jmp error_exit /* %ebx: no swapgs flag */
16416 CFI_ENDPROC
16417-END(\sym)
16418+ENDPROC(\sym)
16419 .endm
16420
16421 /* error code is on the stack already */
16422@@ -1174,13 +1539,23 @@ ENTRY(\sym)
16423 call save_paranoid
16424 DEFAULT_FRAME 0
16425 TRACE_IRQS_OFF
16426+#ifdef CONFIG_PAX_MEMORY_UDEREF
16427+ testb $3, CS(%rsp)
16428+ jnz 1f
16429+ pax_enter_kernel
16430+ jmp 2f
16431+1: pax_enter_kernel_user
16432+2:
16433+#else
16434+ pax_enter_kernel
16435+#endif
16436 movq %rsp,%rdi /* pt_regs pointer */
16437 movq ORIG_RAX(%rsp),%rsi /* get error code */
16438 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16439 call \do_sym
16440 jmp paranoid_exit /* %ebx: no swapgs flag */
16441 CFI_ENDPROC
16442-END(\sym)
16443+ENDPROC(\sym)
16444 .endm
16445
16446 zeroentry divide_error do_divide_error
16447@@ -1210,9 +1585,10 @@ gs_change:
16448 2: mfence /* workaround */
16449 SWAPGS
16450 popfq_cfi
16451+ pax_force_retaddr
16452 ret
16453 CFI_ENDPROC
16454-END(native_load_gs_index)
16455+ENDPROC(native_load_gs_index)
16456
16457 _ASM_EXTABLE(gs_change,bad_gs)
16458 .section .fixup,"ax"
16459@@ -1231,13 +1607,14 @@ ENTRY(kernel_thread_helper)
16460 * Here we are in the child and the registers are set as they were
16461 * at kernel_thread() invocation in the parent.
16462 */
16463+ pax_force_fptr %rsi
16464 call *%rsi
16465 # exit
16466 mov %eax, %edi
16467 call do_exit
16468 ud2 # padding for call trace
16469 CFI_ENDPROC
16470-END(kernel_thread_helper)
16471+ENDPROC(kernel_thread_helper)
16472
16473 /*
16474 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16475@@ -1264,11 +1641,11 @@ ENTRY(kernel_execve)
16476 RESTORE_REST
16477 testq %rax,%rax
16478 je int_ret_from_sys_call
16479- RESTORE_ARGS
16480 UNFAKE_STACK_FRAME
16481+ pax_force_retaddr
16482 ret
16483 CFI_ENDPROC
16484-END(kernel_execve)
16485+ENDPROC(kernel_execve)
16486
16487 /* Call softirq on interrupt stack. Interrupts are off. */
16488 ENTRY(call_softirq)
16489@@ -1286,9 +1663,10 @@ ENTRY(call_softirq)
16490 CFI_DEF_CFA_REGISTER rsp
16491 CFI_ADJUST_CFA_OFFSET -8
16492 decl PER_CPU_VAR(irq_count)
16493+ pax_force_retaddr
16494 ret
16495 CFI_ENDPROC
16496-END(call_softirq)
16497+ENDPROC(call_softirq)
16498
16499 #ifdef CONFIG_XEN
16500 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16501@@ -1326,7 +1704,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16502 decl PER_CPU_VAR(irq_count)
16503 jmp error_exit
16504 CFI_ENDPROC
16505-END(xen_do_hypervisor_callback)
16506+ENDPROC(xen_do_hypervisor_callback)
16507
16508 /*
16509 * Hypervisor uses this for application faults while it executes.
16510@@ -1385,7 +1763,7 @@ ENTRY(xen_failsafe_callback)
16511 SAVE_ALL
16512 jmp error_exit
16513 CFI_ENDPROC
16514-END(xen_failsafe_callback)
16515+ENDPROC(xen_failsafe_callback)
16516
16517 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16518 xen_hvm_callback_vector xen_evtchn_do_upcall
16519@@ -1434,16 +1812,31 @@ ENTRY(paranoid_exit)
16520 TRACE_IRQS_OFF_DEBUG
16521 testl %ebx,%ebx /* swapgs needed? */
16522 jnz paranoid_restore
16523- testl $3,CS(%rsp)
16524+ testb $3,CS(%rsp)
16525 jnz paranoid_userspace
16526+#ifdef CONFIG_PAX_MEMORY_UDEREF
16527+ pax_exit_kernel
16528+ TRACE_IRQS_IRETQ 0
16529+ SWAPGS_UNSAFE_STACK
16530+ RESTORE_ALL 8
16531+ pax_force_retaddr_bts
16532+ jmp irq_return
16533+#endif
16534 paranoid_swapgs:
16535+#ifdef CONFIG_PAX_MEMORY_UDEREF
16536+ pax_exit_kernel_user
16537+#else
16538+ pax_exit_kernel
16539+#endif
16540 TRACE_IRQS_IRETQ 0
16541 SWAPGS_UNSAFE_STACK
16542 RESTORE_ALL 8
16543 jmp irq_return
16544 paranoid_restore:
16545+ pax_exit_kernel
16546 TRACE_IRQS_IRETQ_DEBUG 0
16547 RESTORE_ALL 8
16548+ pax_force_retaddr_bts
16549 jmp irq_return
16550 paranoid_userspace:
16551 GET_THREAD_INFO(%rcx)
16552@@ -1472,7 +1865,7 @@ paranoid_schedule:
16553 TRACE_IRQS_OFF
16554 jmp paranoid_userspace
16555 CFI_ENDPROC
16556-END(paranoid_exit)
16557+ENDPROC(paranoid_exit)
16558
16559 /*
16560 * Exception entry point. This expects an error code/orig_rax on the stack.
16561@@ -1499,12 +1892,13 @@ ENTRY(error_entry)
16562 movq_cfi r14, R14+8
16563 movq_cfi r15, R15+8
16564 xorl %ebx,%ebx
16565- testl $3,CS+8(%rsp)
16566+ testb $3,CS+8(%rsp)
16567 je error_kernelspace
16568 error_swapgs:
16569 SWAPGS
16570 error_sti:
16571 TRACE_IRQS_OFF
16572+ pax_force_retaddr_bts
16573 ret
16574
16575 /*
16576@@ -1531,7 +1925,7 @@ bstep_iret:
16577 movq %rcx,RIP+8(%rsp)
16578 jmp error_swapgs
16579 CFI_ENDPROC
16580-END(error_entry)
16581+ENDPROC(error_entry)
16582
16583
16584 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16585@@ -1551,7 +1945,7 @@ ENTRY(error_exit)
16586 jnz retint_careful
16587 jmp retint_swapgs
16588 CFI_ENDPROC
16589-END(error_exit)
16590+ENDPROC(error_exit)
16591
16592 /*
16593 * Test if a given stack is an NMI stack or not.
16594@@ -1609,9 +2003,11 @@ ENTRY(nmi)
16595 * If %cs was not the kernel segment, then the NMI triggered in user
16596 * space, which means it is definitely not nested.
16597 */
16598+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16599+ je 1f
16600 cmpl $__KERNEL_CS, 16(%rsp)
16601 jne first_nmi
16602-
16603+1:
16604 /*
16605 * Check the special variable on the stack to see if NMIs are
16606 * executing.
16607@@ -1758,6 +2154,16 @@ end_repeat_nmi:
16608 */
16609 call save_paranoid
16610 DEFAULT_FRAME 0
16611+#ifdef CONFIG_PAX_MEMORY_UDEREF
16612+ testb $3, CS(%rsp)
16613+ jnz 1f
16614+ pax_enter_kernel
16615+ jmp 2f
16616+1: pax_enter_kernel_user
16617+2:
16618+#else
16619+ pax_enter_kernel
16620+#endif
16621 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16622 movq %rsp,%rdi
16623 movq $-1,%rsi
16624@@ -1765,21 +2171,32 @@ end_repeat_nmi:
16625 testl %ebx,%ebx /* swapgs needed? */
16626 jnz nmi_restore
16627 nmi_swapgs:
16628+#ifdef CONFIG_PAX_MEMORY_UDEREF
16629+ pax_exit_kernel_user
16630+#else
16631+ pax_exit_kernel
16632+#endif
16633 SWAPGS_UNSAFE_STACK
16634+ RESTORE_ALL 8
16635+ /* Clear the NMI executing stack variable */
16636+ movq $0, 10*8(%rsp)
16637+ jmp irq_return
16638 nmi_restore:
16639+ pax_exit_kernel
16640 RESTORE_ALL 8
16641+ pax_force_retaddr_bts
16642 /* Clear the NMI executing stack variable */
16643 movq $0, 10*8(%rsp)
16644 jmp irq_return
16645 CFI_ENDPROC
16646-END(nmi)
16647+ENDPROC(nmi)
16648
16649 ENTRY(ignore_sysret)
16650 CFI_STARTPROC
16651 mov $-ENOSYS,%eax
16652 sysret
16653 CFI_ENDPROC
16654-END(ignore_sysret)
16655+ENDPROC(ignore_sysret)
16656
16657 /*
16658 * End of kprobes section
16659diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16660index c3a7cb4..3ad00dc 100644
16661--- a/arch/x86/kernel/ftrace.c
16662+++ b/arch/x86/kernel/ftrace.c
16663@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
16664 {
16665 unsigned char replaced[MCOUNT_INSN_SIZE];
16666
16667+ ip = ktla_ktva(ip);
16668+
16669 /*
16670 * Note: Due to modules and __init, code can
16671 * disappear and change, we need to protect against faulting
16672@@ -212,7 +214,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16673 unsigned char old[MCOUNT_INSN_SIZE], *new;
16674 int ret;
16675
16676- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16677+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16678 new = ftrace_call_replace(ip, (unsigned long)func);
16679
16680 /* See comment above by declaration of modifying_ftrace_code */
16681@@ -605,6 +607,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16682 {
16683 unsigned char code[MCOUNT_INSN_SIZE];
16684
16685+ ip = ktla_ktva(ip);
16686+
16687 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16688 return -EFAULT;
16689
16690diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16691index c18f59d..9c0c9f6 100644
16692--- a/arch/x86/kernel/head32.c
16693+++ b/arch/x86/kernel/head32.c
16694@@ -18,6 +18,7 @@
16695 #include <asm/io_apic.h>
16696 #include <asm/bios_ebda.h>
16697 #include <asm/tlbflush.h>
16698+#include <asm/boot.h>
16699
16700 static void __init i386_default_early_setup(void)
16701 {
16702@@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
16703
16704 void __init i386_start_kernel(void)
16705 {
16706- memblock_reserve(__pa_symbol(&_text),
16707- __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16708+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16709
16710 #ifdef CONFIG_BLK_DEV_INITRD
16711 /* Reserve INITRD */
16712diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16713index d42ab17..cb1b997 100644
16714--- a/arch/x86/kernel/head_32.S
16715+++ b/arch/x86/kernel/head_32.S
16716@@ -26,6 +26,12 @@
16717 /* Physical address */
16718 #define pa(X) ((X) - __PAGE_OFFSET)
16719
16720+#ifdef CONFIG_PAX_KERNEXEC
16721+#define ta(X) (X)
16722+#else
16723+#define ta(X) ((X) - __PAGE_OFFSET)
16724+#endif
16725+
16726 /*
16727 * References to members of the new_cpu_data structure.
16728 */
16729@@ -55,11 +61,7 @@
16730 * and small than max_low_pfn, otherwise will waste some page table entries
16731 */
16732
16733-#if PTRS_PER_PMD > 1
16734-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16735-#else
16736-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16737-#endif
16738+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16739
16740 /* Number of possible pages in the lowmem region */
16741 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16742@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16743 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16744
16745 /*
16746+ * Real beginning of normal "text" segment
16747+ */
16748+ENTRY(stext)
16749+ENTRY(_stext)
16750+
16751+/*
16752 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16753 * %esi points to the real-mode code as a 32-bit pointer.
16754 * CS and DS must be 4 GB flat segments, but we don't depend on
16755@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16756 * can.
16757 */
16758 __HEAD
16759+
16760+#ifdef CONFIG_PAX_KERNEXEC
16761+ jmp startup_32
16762+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16763+.fill PAGE_SIZE-5,1,0xcc
16764+#endif
16765+
16766 ENTRY(startup_32)
16767 movl pa(stack_start),%ecx
16768
16769@@ -106,6 +121,57 @@ ENTRY(startup_32)
16770 2:
16771 leal -__PAGE_OFFSET(%ecx),%esp
16772
16773+#ifdef CONFIG_SMP
16774+ movl $pa(cpu_gdt_table),%edi
16775+ movl $__per_cpu_load,%eax
16776+ movw %ax,__KERNEL_PERCPU + 2(%edi)
16777+ rorl $16,%eax
16778+ movb %al,__KERNEL_PERCPU + 4(%edi)
16779+ movb %ah,__KERNEL_PERCPU + 7(%edi)
16780+ movl $__per_cpu_end - 1,%eax
16781+ subl $__per_cpu_start,%eax
16782+ movw %ax,__KERNEL_PERCPU + 0(%edi)
16783+#endif
16784+
16785+#ifdef CONFIG_PAX_MEMORY_UDEREF
16786+ movl $NR_CPUS,%ecx
16787+ movl $pa(cpu_gdt_table),%edi
16788+1:
16789+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16790+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16791+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16792+ addl $PAGE_SIZE_asm,%edi
16793+ loop 1b
16794+#endif
16795+
16796+#ifdef CONFIG_PAX_KERNEXEC
16797+ movl $pa(boot_gdt),%edi
16798+ movl $__LOAD_PHYSICAL_ADDR,%eax
16799+ movw %ax,__BOOT_CS + 2(%edi)
16800+ rorl $16,%eax
16801+ movb %al,__BOOT_CS + 4(%edi)
16802+ movb %ah,__BOOT_CS + 7(%edi)
16803+ rorl $16,%eax
16804+
16805+ ljmp $(__BOOT_CS),$1f
16806+1:
16807+
16808+ movl $NR_CPUS,%ecx
16809+ movl $pa(cpu_gdt_table),%edi
16810+ addl $__PAGE_OFFSET,%eax
16811+1:
16812+ movw %ax,__KERNEL_CS + 2(%edi)
16813+ movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16814+ rorl $16,%eax
16815+ movb %al,__KERNEL_CS + 4(%edi)
16816+ movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16817+ movb %ah,__KERNEL_CS + 7(%edi)
16818+ movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16819+ rorl $16,%eax
16820+ addl $PAGE_SIZE_asm,%edi
16821+ loop 1b
16822+#endif
16823+
16824 /*
16825 * Clear BSS first so that there are no surprises...
16826 */
16827@@ -196,8 +262,11 @@ ENTRY(startup_32)
16828 movl %eax, pa(max_pfn_mapped)
16829
16830 /* Do early initialization of the fixmap area */
16831- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16832- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16833+#ifdef CONFIG_COMPAT_VDSO
16834+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16835+#else
16836+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16837+#endif
16838 #else /* Not PAE */
16839
16840 page_pde_offset = (__PAGE_OFFSET >> 20);
16841@@ -227,8 +296,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16842 movl %eax, pa(max_pfn_mapped)
16843
16844 /* Do early initialization of the fixmap area */
16845- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16846- movl %eax,pa(initial_page_table+0xffc)
16847+#ifdef CONFIG_COMPAT_VDSO
16848+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16849+#else
16850+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16851+#endif
16852 #endif
16853
16854 #ifdef CONFIG_PARAVIRT
16855@@ -242,9 +314,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16856 cmpl $num_subarch_entries, %eax
16857 jae bad_subarch
16858
16859- movl pa(subarch_entries)(,%eax,4), %eax
16860- subl $__PAGE_OFFSET, %eax
16861- jmp *%eax
16862+ jmp *pa(subarch_entries)(,%eax,4)
16863
16864 bad_subarch:
16865 WEAK(lguest_entry)
16866@@ -256,10 +326,10 @@ WEAK(xen_entry)
16867 __INITDATA
16868
16869 subarch_entries:
16870- .long default_entry /* normal x86/PC */
16871- .long lguest_entry /* lguest hypervisor */
16872- .long xen_entry /* Xen hypervisor */
16873- .long default_entry /* Moorestown MID */
16874+ .long ta(default_entry) /* normal x86/PC */
16875+ .long ta(lguest_entry) /* lguest hypervisor */
16876+ .long ta(xen_entry) /* Xen hypervisor */
16877+ .long ta(default_entry) /* Moorestown MID */
16878 num_subarch_entries = (. - subarch_entries) / 4
16879 .previous
16880 #else
16881@@ -310,6 +380,7 @@ default_entry:
16882 orl %edx,%eax
16883 movl %eax,%cr4
16884
16885+#ifdef CONFIG_X86_PAE
16886 testb $X86_CR4_PAE, %al # check if PAE is enabled
16887 jz 6f
16888
16889@@ -338,6 +409,9 @@ default_entry:
16890 /* Make changes effective */
16891 wrmsr
16892
16893+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
16894+#endif
16895+
16896 6:
16897
16898 /*
16899@@ -436,14 +510,20 @@ is386: movl $2,%ecx # set MP
16900 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
16901 movl %eax,%ss # after changing gdt.
16902
16903- movl $(__USER_DS),%eax # DS/ES contains default USER segment
16904+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
16905 movl %eax,%ds
16906 movl %eax,%es
16907
16908 movl $(__KERNEL_PERCPU), %eax
16909 movl %eax,%fs # set this cpu's percpu
16910
16911+#ifdef CONFIG_CC_STACKPROTECTOR
16912 movl $(__KERNEL_STACK_CANARY),%eax
16913+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
16914+ movl $(__USER_DS),%eax
16915+#else
16916+ xorl %eax,%eax
16917+#endif
16918 movl %eax,%gs
16919
16920 xorl %eax,%eax # Clear LDT
16921@@ -520,8 +600,11 @@ setup_once:
16922 * relocation. Manually set base address in stack canary
16923 * segment descriptor.
16924 */
16925- movl $gdt_page,%eax
16926+ movl $cpu_gdt_table,%eax
16927 movl $stack_canary,%ecx
16928+#ifdef CONFIG_SMP
16929+ addl $__per_cpu_load,%ecx
16930+#endif
16931 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
16932 shrl $16, %ecx
16933 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
16934@@ -552,7 +635,7 @@ ENDPROC(early_idt_handlers)
16935 /* This is global to keep gas from relaxing the jumps */
16936 ENTRY(early_idt_handler)
16937 cld
16938- cmpl $2,%ss:early_recursion_flag
16939+ cmpl $1,%ss:early_recursion_flag
16940 je hlt_loop
16941 incl %ss:early_recursion_flag
16942
16943@@ -590,8 +673,8 @@ ENTRY(early_idt_handler)
16944 pushl (20+6*4)(%esp) /* trapno */
16945 pushl $fault_msg
16946 call printk
16947-#endif
16948 call dump_stack
16949+#endif
16950 hlt_loop:
16951 hlt
16952 jmp hlt_loop
16953@@ -610,8 +693,11 @@ ENDPROC(early_idt_handler)
16954 /* This is the default interrupt "handler" :-) */
16955 ALIGN
16956 ignore_int:
16957- cld
16958 #ifdef CONFIG_PRINTK
16959+ cmpl $2,%ss:early_recursion_flag
16960+ je hlt_loop
16961+ incl %ss:early_recursion_flag
16962+ cld
16963 pushl %eax
16964 pushl %ecx
16965 pushl %edx
16966@@ -620,9 +706,6 @@ ignore_int:
16967 movl $(__KERNEL_DS),%eax
16968 movl %eax,%ds
16969 movl %eax,%es
16970- cmpl $2,early_recursion_flag
16971- je hlt_loop
16972- incl early_recursion_flag
16973 pushl 16(%esp)
16974 pushl 24(%esp)
16975 pushl 32(%esp)
16976@@ -656,29 +739,43 @@ ENTRY(setup_once_ref)
16977 /*
16978 * BSS section
16979 */
16980-__PAGE_ALIGNED_BSS
16981- .align PAGE_SIZE
16982 #ifdef CONFIG_X86_PAE
16983+.section .initial_pg_pmd,"a",@progbits
16984 initial_pg_pmd:
16985 .fill 1024*KPMDS,4,0
16986 #else
16987+.section .initial_page_table,"a",@progbits
16988 ENTRY(initial_page_table)
16989 .fill 1024,4,0
16990 #endif
16991+.section .initial_pg_fixmap,"a",@progbits
16992 initial_pg_fixmap:
16993 .fill 1024,4,0
16994+.section .empty_zero_page,"a",@progbits
16995 ENTRY(empty_zero_page)
16996 .fill 4096,1,0
16997+.section .swapper_pg_dir,"a",@progbits
16998 ENTRY(swapper_pg_dir)
16999+#ifdef CONFIG_X86_PAE
17000+ .fill 4,8,0
17001+#else
17002 .fill 1024,4,0
17003+#endif
17004+
17005+/*
17006+ * The IDT has to be page-aligned to simplify the Pentium
17007+ * F0 0F bug workaround.. We have a special link segment
17008+ * for this.
17009+ */
17010+.section .idt,"a",@progbits
17011+ENTRY(idt_table)
17012+ .fill 256,8,0
17013
17014 /*
17015 * This starts the data section.
17016 */
17017 #ifdef CONFIG_X86_PAE
17018-__PAGE_ALIGNED_DATA
17019- /* Page-aligned for the benefit of paravirt? */
17020- .align PAGE_SIZE
17021+.section .initial_page_table,"a",@progbits
17022 ENTRY(initial_page_table)
17023 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17024 # if KPMDS == 3
17025@@ -697,12 +794,20 @@ ENTRY(initial_page_table)
17026 # error "Kernel PMDs should be 1, 2 or 3"
17027 # endif
17028 .align PAGE_SIZE /* needs to be page-sized too */
17029+
17030+#ifdef CONFIG_PAX_PER_CPU_PGD
17031+ENTRY(cpu_pgd)
17032+ .rept NR_CPUS
17033+ .fill 4,8,0
17034+ .endr
17035+#endif
17036+
17037 #endif
17038
17039 .data
17040 .balign 4
17041 ENTRY(stack_start)
17042- .long init_thread_union+THREAD_SIZE
17043+ .long init_thread_union+THREAD_SIZE-8
17044
17045 __INITRODATA
17046 int_msg:
17047@@ -730,7 +835,7 @@ fault_msg:
17048 * segment size, and 32-bit linear address value:
17049 */
17050
17051- .data
17052+.section .rodata,"a",@progbits
17053 .globl boot_gdt_descr
17054 .globl idt_descr
17055
17056@@ -739,7 +844,7 @@ fault_msg:
17057 .word 0 # 32 bit align gdt_desc.address
17058 boot_gdt_descr:
17059 .word __BOOT_DS+7
17060- .long boot_gdt - __PAGE_OFFSET
17061+ .long pa(boot_gdt)
17062
17063 .word 0 # 32-bit align idt_desc.address
17064 idt_descr:
17065@@ -750,7 +855,7 @@ idt_descr:
17066 .word 0 # 32 bit align gdt_desc.address
17067 ENTRY(early_gdt_descr)
17068 .word GDT_ENTRIES*8-1
17069- .long gdt_page /* Overwritten for secondary CPUs */
17070+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
17071
17072 /*
17073 * The boot_gdt must mirror the equivalent in setup.S and is
17074@@ -759,5 +864,65 @@ ENTRY(early_gdt_descr)
17075 .align L1_CACHE_BYTES
17076 ENTRY(boot_gdt)
17077 .fill GDT_ENTRY_BOOT_CS,8,0
17078- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17079- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17080+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17081+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17082+
17083+ .align PAGE_SIZE_asm
17084+ENTRY(cpu_gdt_table)
17085+ .rept NR_CPUS
17086+ .quad 0x0000000000000000 /* NULL descriptor */
17087+ .quad 0x0000000000000000 /* 0x0b reserved */
17088+ .quad 0x0000000000000000 /* 0x13 reserved */
17089+ .quad 0x0000000000000000 /* 0x1b reserved */
17090+
17091+#ifdef CONFIG_PAX_KERNEXEC
17092+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17093+#else
17094+ .quad 0x0000000000000000 /* 0x20 unused */
17095+#endif
17096+
17097+ .quad 0x0000000000000000 /* 0x28 unused */
17098+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17099+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17100+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17101+ .quad 0x0000000000000000 /* 0x4b reserved */
17102+ .quad 0x0000000000000000 /* 0x53 reserved */
17103+ .quad 0x0000000000000000 /* 0x5b reserved */
17104+
17105+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17106+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17107+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17108+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17109+
17110+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17111+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17112+
17113+ /*
17114+ * Segments used for calling PnP BIOS have byte granularity.
17115+ * The code segments and data segments have fixed 64k limits,
17116+ * the transfer segment sizes are set at run time.
17117+ */
17118+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
17119+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
17120+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
17121+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
17122+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
17123+
17124+ /*
17125+ * The APM segments have byte granularity and their bases
17126+ * are set at run time. All have 64k limits.
17127+ */
17128+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17129+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17130+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
17131+
17132+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17133+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17134+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17135+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17136+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17137+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17138+
17139+ /* Be sure this is zeroed to avoid false validations in Xen */
17140+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17141+ .endr
17142diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17143index 94bf9cc..400455a 100644
17144--- a/arch/x86/kernel/head_64.S
17145+++ b/arch/x86/kernel/head_64.S
17146@@ -20,6 +20,8 @@
17147 #include <asm/processor-flags.h>
17148 #include <asm/percpu.h>
17149 #include <asm/nops.h>
17150+#include <asm/cpufeature.h>
17151+#include <asm/alternative-asm.h>
17152
17153 #ifdef CONFIG_PARAVIRT
17154 #include <asm/asm-offsets.h>
17155@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17156 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17157 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17158 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17159+L4_VMALLOC_START = pgd_index(VMALLOC_START)
17160+L3_VMALLOC_START = pud_index(VMALLOC_START)
17161+L4_VMALLOC_END = pgd_index(VMALLOC_END)
17162+L3_VMALLOC_END = pud_index(VMALLOC_END)
17163+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17164+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17165
17166 .text
17167 __HEAD
17168@@ -88,35 +96,23 @@ startup_64:
17169 */
17170 addq %rbp, init_level4_pgt + 0(%rip)
17171 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17172+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17173+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17174+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17175 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17176
17177 addq %rbp, level3_ident_pgt + 0(%rip)
17178+#ifndef CONFIG_XEN
17179+ addq %rbp, level3_ident_pgt + 8(%rip)
17180+#endif
17181
17182- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17183- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17184+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17185+
17186+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17187+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17188
17189 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17190-
17191- /* Add an Identity mapping if I am above 1G */
17192- leaq _text(%rip), %rdi
17193- andq $PMD_PAGE_MASK, %rdi
17194-
17195- movq %rdi, %rax
17196- shrq $PUD_SHIFT, %rax
17197- andq $(PTRS_PER_PUD - 1), %rax
17198- jz ident_complete
17199-
17200- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17201- leaq level3_ident_pgt(%rip), %rbx
17202- movq %rdx, 0(%rbx, %rax, 8)
17203-
17204- movq %rdi, %rax
17205- shrq $PMD_SHIFT, %rax
17206- andq $(PTRS_PER_PMD - 1), %rax
17207- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17208- leaq level2_spare_pgt(%rip), %rbx
17209- movq %rdx, 0(%rbx, %rax, 8)
17210-ident_complete:
17211+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17212
17213 /*
17214 * Fixup the kernel text+data virtual addresses. Note that
17215@@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
17216 * after the boot processor executes this code.
17217 */
17218
17219- /* Enable PAE mode and PGE */
17220- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17221+ /* Enable PAE mode and PSE/PGE */
17222+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17223 movq %rax, %cr4
17224
17225 /* Setup early boot stage 4 level pagetables. */
17226@@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
17227 movl $MSR_EFER, %ecx
17228 rdmsr
17229 btsl $_EFER_SCE, %eax /* Enable System Call */
17230- btl $20,%edi /* No Execute supported? */
17231+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17232 jnc 1f
17233 btsl $_EFER_NX, %eax
17234+ leaq init_level4_pgt(%rip), %rdi
17235+#ifndef CONFIG_EFI
17236+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17237+#endif
17238+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17239+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17240+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17241+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17242 1: wrmsr /* Make changes effective */
17243
17244 /* Setup cr0 */
17245@@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
17246 * jump. In addition we need to ensure %cs is set so we make this
17247 * a far return.
17248 */
17249+ pax_set_fptr_mask
17250 movq initial_code(%rip),%rax
17251 pushq $0 # fake return address to stop unwinder
17252 pushq $__KERNEL_CS # set correct cs
17253@@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
17254 bad_address:
17255 jmp bad_address
17256
17257- .section ".init.text","ax"
17258+ __INIT
17259 .globl early_idt_handlers
17260 early_idt_handlers:
17261 # 104(%rsp) %rflags
17262@@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
17263 addq $16,%rsp # drop vector number and error code
17264 decl early_recursion_flag(%rip)
17265 INTERRUPT_RETURN
17266+ .previous
17267
17268+ __INITDATA
17269 .balign 4
17270 early_recursion_flag:
17271 .long 0
17272+ .previous
17273
17274+ .section .rodata,"a",@progbits
17275 #ifdef CONFIG_EARLY_PRINTK
17276 early_idt_msg:
17277 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17278@@ -360,6 +369,7 @@ early_idt_ripmsg:
17279 #endif /* CONFIG_EARLY_PRINTK */
17280 .previous
17281
17282+ .section .rodata,"a",@progbits
17283 #define NEXT_PAGE(name) \
17284 .balign PAGE_SIZE; \
17285 ENTRY(name)
17286@@ -372,7 +382,6 @@ ENTRY(name)
17287 i = i + 1 ; \
17288 .endr
17289
17290- .data
17291 /*
17292 * This default setting generates an ident mapping at address 0x100000
17293 * and a mapping for the kernel that precisely maps virtual address
17294@@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
17295 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17296 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17297 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17298+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
17299+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17300+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
17301+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17302+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17303+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17304 .org init_level4_pgt + L4_START_KERNEL*8, 0
17305 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17306 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17307
17308+#ifdef CONFIG_PAX_PER_CPU_PGD
17309+NEXT_PAGE(cpu_pgd)
17310+ .rept NR_CPUS
17311+ .fill 512,8,0
17312+ .endr
17313+#endif
17314+
17315 NEXT_PAGE(level3_ident_pgt)
17316 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17317+#ifdef CONFIG_XEN
17318 .fill 511,8,0
17319+#else
17320+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17321+ .fill 510,8,0
17322+#endif
17323+
17324+NEXT_PAGE(level3_vmalloc_start_pgt)
17325+ .fill 512,8,0
17326+
17327+NEXT_PAGE(level3_vmalloc_end_pgt)
17328+ .fill 512,8,0
17329+
17330+NEXT_PAGE(level3_vmemmap_pgt)
17331+ .fill L3_VMEMMAP_START,8,0
17332+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17333
17334 NEXT_PAGE(level3_kernel_pgt)
17335 .fill L3_START_KERNEL,8,0
17336@@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
17337 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17338 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17339
17340+NEXT_PAGE(level2_vmemmap_pgt)
17341+ .fill 512,8,0
17342+
17343 NEXT_PAGE(level2_fixmap_pgt)
17344- .fill 506,8,0
17345- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17346- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17347- .fill 5,8,0
17348+ .fill 507,8,0
17349+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17350+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17351+ .fill 4,8,0
17352
17353-NEXT_PAGE(level1_fixmap_pgt)
17354+NEXT_PAGE(level1_vsyscall_pgt)
17355 .fill 512,8,0
17356
17357-NEXT_PAGE(level2_ident_pgt)
17358- /* Since I easily can, map the first 1G.
17359+ /* Since I easily can, map the first 2G.
17360 * Don't set NX because code runs from these pages.
17361 */
17362- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17363+NEXT_PAGE(level2_ident_pgt)
17364+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17365
17366 NEXT_PAGE(level2_kernel_pgt)
17367 /*
17368@@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
17369 * If you want to increase this then increase MODULES_VADDR
17370 * too.)
17371 */
17372- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17373- KERNEL_IMAGE_SIZE/PMD_SIZE)
17374-
17375-NEXT_PAGE(level2_spare_pgt)
17376- .fill 512, 8, 0
17377+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17378
17379 #undef PMDS
17380 #undef NEXT_PAGE
17381
17382- .data
17383+ .align PAGE_SIZE
17384+ENTRY(cpu_gdt_table)
17385+ .rept NR_CPUS
17386+ .quad 0x0000000000000000 /* NULL descriptor */
17387+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17388+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
17389+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
17390+ .quad 0x00cffb000000ffff /* __USER32_CS */
17391+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17392+ .quad 0x00affb000000ffff /* __USER_CS */
17393+
17394+#ifdef CONFIG_PAX_KERNEXEC
17395+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17396+#else
17397+ .quad 0x0 /* unused */
17398+#endif
17399+
17400+ .quad 0,0 /* TSS */
17401+ .quad 0,0 /* LDT */
17402+ .quad 0,0,0 /* three TLS descriptors */
17403+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
17404+ /* asm/segment.h:GDT_ENTRIES must match this */
17405+
17406+ /* zero the remaining page */
17407+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17408+ .endr
17409+
17410 .align 16
17411 .globl early_gdt_descr
17412 early_gdt_descr:
17413 .word GDT_ENTRIES*8-1
17414 early_gdt_descr_base:
17415- .quad INIT_PER_CPU_VAR(gdt_page)
17416+ .quad cpu_gdt_table
17417
17418 ENTRY(phys_base)
17419 /* This must match the first entry in level2_kernel_pgt */
17420 .quad 0x0000000000000000
17421
17422 #include "../../x86/xen/xen-head.S"
17423-
17424- .section .bss, "aw", @nobits
17425+
17426+ .section .rodata,"a",@progbits
17427 .align L1_CACHE_BYTES
17428 ENTRY(idt_table)
17429- .skip IDT_ENTRIES * 16
17430+ .fill 512,8,0
17431
17432 .align L1_CACHE_BYTES
17433 ENTRY(nmi_idt_table)
17434- .skip IDT_ENTRIES * 16
17435+ .fill 512,8,0
17436
17437 __PAGE_ALIGNED_BSS
17438 .align PAGE_SIZE
17439diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17440index 9c3bd4a..e1d9b35 100644
17441--- a/arch/x86/kernel/i386_ksyms_32.c
17442+++ b/arch/x86/kernel/i386_ksyms_32.c
17443@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17444 EXPORT_SYMBOL(cmpxchg8b_emu);
17445 #endif
17446
17447+EXPORT_SYMBOL_GPL(cpu_gdt_table);
17448+
17449 /* Networking helper routines. */
17450 EXPORT_SYMBOL(csum_partial_copy_generic);
17451+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17452+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17453
17454 EXPORT_SYMBOL(__get_user_1);
17455 EXPORT_SYMBOL(__get_user_2);
17456@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17457
17458 EXPORT_SYMBOL(csum_partial);
17459 EXPORT_SYMBOL(empty_zero_page);
17460+
17461+#ifdef CONFIG_PAX_KERNEXEC
17462+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17463+#endif
17464diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17465index f250431..54097e7 100644
17466--- a/arch/x86/kernel/i387.c
17467+++ b/arch/x86/kernel/i387.c
17468@@ -59,7 +59,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17469 static inline bool interrupted_user_mode(void)
17470 {
17471 struct pt_regs *regs = get_irq_regs();
17472- return regs && user_mode_vm(regs);
17473+ return regs && user_mode(regs);
17474 }
17475
17476 /*
17477diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17478index 36d1853..bf25736 100644
17479--- a/arch/x86/kernel/i8259.c
17480+++ b/arch/x86/kernel/i8259.c
17481@@ -209,7 +209,7 @@ spurious_8259A_irq:
17482 "spurious 8259A interrupt: IRQ%d.\n", irq);
17483 spurious_irq_mask |= irqmask;
17484 }
17485- atomic_inc(&irq_err_count);
17486+ atomic_inc_unchecked(&irq_err_count);
17487 /*
17488 * Theoretically we do not have to handle this IRQ,
17489 * but in Linux this does not cause problems and is
17490diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17491index 8c96897..be66bfa 100644
17492--- a/arch/x86/kernel/ioport.c
17493+++ b/arch/x86/kernel/ioport.c
17494@@ -6,6 +6,7 @@
17495 #include <linux/sched.h>
17496 #include <linux/kernel.h>
17497 #include <linux/capability.h>
17498+#include <linux/security.h>
17499 #include <linux/errno.h>
17500 #include <linux/types.h>
17501 #include <linux/ioport.h>
17502@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17503
17504 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17505 return -EINVAL;
17506+#ifdef CONFIG_GRKERNSEC_IO
17507+ if (turn_on && grsec_disable_privio) {
17508+ gr_handle_ioperm();
17509+ return -EPERM;
17510+ }
17511+#endif
17512 if (turn_on && !capable(CAP_SYS_RAWIO))
17513 return -EPERM;
17514
17515@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17516 * because the ->io_bitmap_max value must match the bitmap
17517 * contents:
17518 */
17519- tss = &per_cpu(init_tss, get_cpu());
17520+ tss = init_tss + get_cpu();
17521
17522 if (turn_on)
17523 bitmap_clear(t->io_bitmap_ptr, from, num);
17524@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17525 return -EINVAL;
17526 /* Trying to gain more privileges? */
17527 if (level > old) {
17528+#ifdef CONFIG_GRKERNSEC_IO
17529+ if (grsec_disable_privio) {
17530+ gr_handle_iopl();
17531+ return -EPERM;
17532+ }
17533+#endif
17534 if (!capable(CAP_SYS_RAWIO))
17535 return -EPERM;
17536 }
17537diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17538index 3dafc60..aa8e9c4 100644
17539--- a/arch/x86/kernel/irq.c
17540+++ b/arch/x86/kernel/irq.c
17541@@ -18,7 +18,7 @@
17542 #include <asm/mce.h>
17543 #include <asm/hw_irq.h>
17544
17545-atomic_t irq_err_count;
17546+atomic_unchecked_t irq_err_count;
17547
17548 /* Function pointer for generic interrupt vector handling */
17549 void (*x86_platform_ipi_callback)(void) = NULL;
17550@@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17551 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17552 seq_printf(p, " Machine check polls\n");
17553 #endif
17554- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17555+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17556 #if defined(CONFIG_X86_IO_APIC)
17557- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17558+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17559 #endif
17560 return 0;
17561 }
17562@@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17563
17564 u64 arch_irq_stat(void)
17565 {
17566- u64 sum = atomic_read(&irq_err_count);
17567+ u64 sum = atomic_read_unchecked(&irq_err_count);
17568
17569 #ifdef CONFIG_X86_IO_APIC
17570- sum += atomic_read(&irq_mis_count);
17571+ sum += atomic_read_unchecked(&irq_mis_count);
17572 #endif
17573 return sum;
17574 }
17575diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17576index 344faf8..355f60d 100644
17577--- a/arch/x86/kernel/irq_32.c
17578+++ b/arch/x86/kernel/irq_32.c
17579@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17580 __asm__ __volatile__("andl %%esp,%0" :
17581 "=r" (sp) : "0" (THREAD_SIZE - 1));
17582
17583- return sp < (sizeof(struct thread_info) + STACK_WARN);
17584+ return sp < STACK_WARN;
17585 }
17586
17587 static void print_stack_overflow(void)
17588@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17589 * per-CPU IRQ handling contexts (thread information and stack)
17590 */
17591 union irq_ctx {
17592- struct thread_info tinfo;
17593- u32 stack[THREAD_SIZE/sizeof(u32)];
17594+ unsigned long previous_esp;
17595+ u32 stack[THREAD_SIZE/sizeof(u32)];
17596 } __attribute__((aligned(THREAD_SIZE)));
17597
17598 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17599@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17600 static inline int
17601 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17602 {
17603- union irq_ctx *curctx, *irqctx;
17604+ union irq_ctx *irqctx;
17605 u32 *isp, arg1, arg2;
17606
17607- curctx = (union irq_ctx *) current_thread_info();
17608 irqctx = __this_cpu_read(hardirq_ctx);
17609
17610 /*
17611@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17612 * handler) we can't do that and just have to keep using the
17613 * current stack (which is the irq stack already after all)
17614 */
17615- if (unlikely(curctx == irqctx))
17616+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17617 return 0;
17618
17619 /* build the stack frame on the IRQ stack */
17620- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17621- irqctx->tinfo.task = curctx->tinfo.task;
17622- irqctx->tinfo.previous_esp = current_stack_pointer;
17623+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17624+ irqctx->previous_esp = current_stack_pointer;
17625
17626- /* Copy the preempt_count so that the [soft]irq checks work. */
17627- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17628+#ifdef CONFIG_PAX_MEMORY_UDEREF
17629+ __set_fs(MAKE_MM_SEG(0));
17630+#endif
17631
17632 if (unlikely(overflow))
17633 call_on_stack(print_stack_overflow, isp);
17634@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17635 : "0" (irq), "1" (desc), "2" (isp),
17636 "D" (desc->handle_irq)
17637 : "memory", "cc", "ecx");
17638+
17639+#ifdef CONFIG_PAX_MEMORY_UDEREF
17640+ __set_fs(current_thread_info()->addr_limit);
17641+#endif
17642+
17643 return 1;
17644 }
17645
17646@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17647 */
17648 void __cpuinit irq_ctx_init(int cpu)
17649 {
17650- union irq_ctx *irqctx;
17651-
17652 if (per_cpu(hardirq_ctx, cpu))
17653 return;
17654
17655- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17656- THREADINFO_GFP,
17657- THREAD_SIZE_ORDER));
17658- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17659- irqctx->tinfo.cpu = cpu;
17660- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17661- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17662-
17663- per_cpu(hardirq_ctx, cpu) = irqctx;
17664-
17665- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17666- THREADINFO_GFP,
17667- THREAD_SIZE_ORDER));
17668- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17669- irqctx->tinfo.cpu = cpu;
17670- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17671-
17672- per_cpu(softirq_ctx, cpu) = irqctx;
17673+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17674+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17675+
17676+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17677+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17678
17679 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17680 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17681@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
17682 asmlinkage void do_softirq(void)
17683 {
17684 unsigned long flags;
17685- struct thread_info *curctx;
17686 union irq_ctx *irqctx;
17687 u32 *isp;
17688
17689@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
17690 local_irq_save(flags);
17691
17692 if (local_softirq_pending()) {
17693- curctx = current_thread_info();
17694 irqctx = __this_cpu_read(softirq_ctx);
17695- irqctx->tinfo.task = curctx->task;
17696- irqctx->tinfo.previous_esp = current_stack_pointer;
17697+ irqctx->previous_esp = current_stack_pointer;
17698
17699 /* build the stack frame on the softirq stack */
17700- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17701+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17702+
17703+#ifdef CONFIG_PAX_MEMORY_UDEREF
17704+ __set_fs(MAKE_MM_SEG(0));
17705+#endif
17706
17707 call_on_stack(__do_softirq, isp);
17708+
17709+#ifdef CONFIG_PAX_MEMORY_UDEREF
17710+ __set_fs(current_thread_info()->addr_limit);
17711+#endif
17712+
17713 /*
17714 * Shouldn't happen, we returned above if in_interrupt():
17715 */
17716@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17717 if (unlikely(!desc))
17718 return false;
17719
17720- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17721+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17722 if (unlikely(overflow))
17723 print_stack_overflow();
17724 desc->handle_irq(irq, desc);
17725diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17726index d04d3ec..ea4b374 100644
17727--- a/arch/x86/kernel/irq_64.c
17728+++ b/arch/x86/kernel/irq_64.c
17729@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17730 u64 estack_top, estack_bottom;
17731 u64 curbase = (u64)task_stack_page(current);
17732
17733- if (user_mode_vm(regs))
17734+ if (user_mode(regs))
17735 return;
17736
17737 if (regs->sp >= curbase + sizeof(struct thread_info) +
17738diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17739index 1d5d31e..72731d4 100644
17740--- a/arch/x86/kernel/kdebugfs.c
17741+++ b/arch/x86/kernel/kdebugfs.c
17742@@ -27,7 +27,7 @@ struct setup_data_node {
17743 u32 len;
17744 };
17745
17746-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17747+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
17748 size_t count, loff_t *ppos)
17749 {
17750 struct setup_data_node *node = file->private_data;
17751diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17752index 3f61904..873cea9 100644
17753--- a/arch/x86/kernel/kgdb.c
17754+++ b/arch/x86/kernel/kgdb.c
17755@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17756 #ifdef CONFIG_X86_32
17757 switch (regno) {
17758 case GDB_SS:
17759- if (!user_mode_vm(regs))
17760+ if (!user_mode(regs))
17761 *(unsigned long *)mem = __KERNEL_DS;
17762 break;
17763 case GDB_SP:
17764- if (!user_mode_vm(regs))
17765+ if (!user_mode(regs))
17766 *(unsigned long *)mem = kernel_stack_pointer(regs);
17767 break;
17768 case GDB_GS:
17769@@ -476,12 +476,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17770 case 'k':
17771 /* clear the trace bit */
17772 linux_regs->flags &= ~X86_EFLAGS_TF;
17773- atomic_set(&kgdb_cpu_doing_single_step, -1);
17774+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17775
17776 /* set the trace bit if we're stepping */
17777 if (remcomInBuffer[0] == 's') {
17778 linux_regs->flags |= X86_EFLAGS_TF;
17779- atomic_set(&kgdb_cpu_doing_single_step,
17780+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17781 raw_smp_processor_id());
17782 }
17783
17784@@ -546,7 +546,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17785
17786 switch (cmd) {
17787 case DIE_DEBUG:
17788- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17789+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17790 if (user_mode(regs))
17791 return single_step_cont(regs, args);
17792 break;
17793diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
17794index c5e410e..da6aaf9 100644
17795--- a/arch/x86/kernel/kprobes-opt.c
17796+++ b/arch/x86/kernel/kprobes-opt.c
17797@@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17798 * Verify if the address gap is in 2GB range, because this uses
17799 * a relative jump.
17800 */
17801- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17802+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17803 if (abs(rel) > 0x7fffffff)
17804 return -ERANGE;
17805
17806@@ -359,11 +359,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17807 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17808
17809 /* Set probe function call */
17810- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17811+ synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17812
17813 /* Set returning jmp instruction at the tail of out-of-line buffer */
17814 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17815- (u8 *)op->kp.addr + op->optinsn.size);
17816+ (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17817
17818 flush_icache_range((unsigned long) buf,
17819 (unsigned long) buf + TMPL_END_IDX +
17820@@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17821 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17822
17823 /* Backup instructions which will be replaced by jump address */
17824- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17825+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17826 RELATIVE_ADDR_SIZE);
17827
17828 insn_buf[0] = RELATIVEJUMP_OPCODE;
17829diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17830index e2f751e..dffa2a0 100644
17831--- a/arch/x86/kernel/kprobes.c
17832+++ b/arch/x86/kernel/kprobes.c
17833@@ -120,8 +120,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17834 } __attribute__((packed)) *insn;
17835
17836 insn = (struct __arch_relative_insn *)from;
17837+
17838+ pax_open_kernel();
17839 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17840 insn->op = op;
17841+ pax_close_kernel();
17842 }
17843
17844 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17845@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
17846 kprobe_opcode_t opcode;
17847 kprobe_opcode_t *orig_opcodes = opcodes;
17848
17849- if (search_exception_tables((unsigned long)opcodes))
17850+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17851 return 0; /* Page fault may occur on this address. */
17852
17853 retry:
17854@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17855 /* Another subsystem puts a breakpoint, failed to recover */
17856 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
17857 return 0;
17858+ pax_open_kernel();
17859 memcpy(dest, insn.kaddr, insn.length);
17860+ pax_close_kernel();
17861
17862 #ifdef CONFIG_X86_64
17863 if (insn_rip_relative(&insn)) {
17864@@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17865 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
17866 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
17867 disp = (u8 *) dest + insn_offset_displacement(&insn);
17868+ pax_open_kernel();
17869 *(s32 *) disp = (s32) newdisp;
17870+ pax_close_kernel();
17871 }
17872 #endif
17873 return insn.length;
17874@@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17875 * nor set current_kprobe, because it doesn't use single
17876 * stepping.
17877 */
17878- regs->ip = (unsigned long)p->ainsn.insn;
17879+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17880 preempt_enable_no_resched();
17881 return;
17882 }
17883@@ -504,7 +511,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17884 if (p->opcode == BREAKPOINT_INSTRUCTION)
17885 regs->ip = (unsigned long)p->addr;
17886 else
17887- regs->ip = (unsigned long)p->ainsn.insn;
17888+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17889 }
17890
17891 /*
17892@@ -583,7 +590,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
17893 setup_singlestep(p, regs, kcb, 0);
17894 return 1;
17895 }
17896- } else if (*addr != BREAKPOINT_INSTRUCTION) {
17897+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
17898 /*
17899 * The breakpoint instruction was removed right
17900 * after we hit it. Another cpu has removed
17901@@ -628,6 +635,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
17902 " movq %rax, 152(%rsp)\n"
17903 RESTORE_REGS_STRING
17904 " popfq\n"
17905+#ifdef KERNEXEC_PLUGIN
17906+ " btsq $63,(%rsp)\n"
17907+#endif
17908 #else
17909 " pushf\n"
17910 SAVE_REGS_STRING
17911@@ -765,7 +775,7 @@ static void __kprobes
17912 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
17913 {
17914 unsigned long *tos = stack_addr(regs);
17915- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
17916+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
17917 unsigned long orig_ip = (unsigned long)p->addr;
17918 kprobe_opcode_t *insn = p->ainsn.insn;
17919
17920@@ -947,7 +957,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
17921 struct die_args *args = data;
17922 int ret = NOTIFY_DONE;
17923
17924- if (args->regs && user_mode_vm(args->regs))
17925+ if (args->regs && user_mode(args->regs))
17926 return ret;
17927
17928 switch (val) {
17929diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
17930index ebc9873..1b9724b 100644
17931--- a/arch/x86/kernel/ldt.c
17932+++ b/arch/x86/kernel/ldt.c
17933@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
17934 if (reload) {
17935 #ifdef CONFIG_SMP
17936 preempt_disable();
17937- load_LDT(pc);
17938+ load_LDT_nolock(pc);
17939 if (!cpumask_equal(mm_cpumask(current->mm),
17940 cpumask_of(smp_processor_id())))
17941 smp_call_function(flush_ldt, current->mm, 1);
17942 preempt_enable();
17943 #else
17944- load_LDT(pc);
17945+ load_LDT_nolock(pc);
17946 #endif
17947 }
17948 if (oldsize) {
17949@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
17950 return err;
17951
17952 for (i = 0; i < old->size; i++)
17953- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
17954+ write_ldt_entry(new->ldt, i, old->ldt + i);
17955 return 0;
17956 }
17957
17958@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
17959 retval = copy_ldt(&mm->context, &old_mm->context);
17960 mutex_unlock(&old_mm->context.lock);
17961 }
17962+
17963+ if (tsk == current) {
17964+ mm->context.vdso = 0;
17965+
17966+#ifdef CONFIG_X86_32
17967+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17968+ mm->context.user_cs_base = 0UL;
17969+ mm->context.user_cs_limit = ~0UL;
17970+
17971+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17972+ cpus_clear(mm->context.cpu_user_cs_mask);
17973+#endif
17974+
17975+#endif
17976+#endif
17977+
17978+ }
17979+
17980 return retval;
17981 }
17982
17983@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
17984 }
17985 }
17986
17987+#ifdef CONFIG_PAX_SEGMEXEC
17988+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
17989+ error = -EINVAL;
17990+ goto out_unlock;
17991+ }
17992+#endif
17993+
17994 fill_ldt(&ldt, &ldt_info);
17995 if (oldmode)
17996 ldt.avl = 0;
17997diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
17998index 5b19e4d..6476a76 100644
17999--- a/arch/x86/kernel/machine_kexec_32.c
18000+++ b/arch/x86/kernel/machine_kexec_32.c
18001@@ -26,7 +26,7 @@
18002 #include <asm/cacheflush.h>
18003 #include <asm/debugreg.h>
18004
18005-static void set_idt(void *newidt, __u16 limit)
18006+static void set_idt(struct desc_struct *newidt, __u16 limit)
18007 {
18008 struct desc_ptr curidt;
18009
18010@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
18011 }
18012
18013
18014-static void set_gdt(void *newgdt, __u16 limit)
18015+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18016 {
18017 struct desc_ptr curgdt;
18018
18019@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
18020 }
18021
18022 control_page = page_address(image->control_code_page);
18023- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18024+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18025
18026 relocate_kernel_ptr = control_page;
18027 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18028diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18029index 0327e2b..e43737b 100644
18030--- a/arch/x86/kernel/microcode_intel.c
18031+++ b/arch/x86/kernel/microcode_intel.c
18032@@ -430,13 +430,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
18033
18034 static int get_ucode_user(void *to, const void *from, size_t n)
18035 {
18036- return copy_from_user(to, from, n);
18037+ return copy_from_user(to, (const void __force_user *)from, n);
18038 }
18039
18040 static enum ucode_state
18041 request_microcode_user(int cpu, const void __user *buf, size_t size)
18042 {
18043- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18044+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18045 }
18046
18047 static void microcode_fini_cpu(int cpu)
18048diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18049index f21fd94..61565cd 100644
18050--- a/arch/x86/kernel/module.c
18051+++ b/arch/x86/kernel/module.c
18052@@ -35,15 +35,60 @@
18053 #define DEBUGP(fmt...)
18054 #endif
18055
18056-void *module_alloc(unsigned long size)
18057+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18058 {
18059- if (PAGE_ALIGN(size) > MODULES_LEN)
18060+ if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18061 return NULL;
18062 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18063- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18064+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18065 -1, __builtin_return_address(0));
18066 }
18067
18068+void *module_alloc(unsigned long size)
18069+{
18070+
18071+#ifdef CONFIG_PAX_KERNEXEC
18072+ return __module_alloc(size, PAGE_KERNEL);
18073+#else
18074+ return __module_alloc(size, PAGE_KERNEL_EXEC);
18075+#endif
18076+
18077+}
18078+
18079+#ifdef CONFIG_PAX_KERNEXEC
18080+#ifdef CONFIG_X86_32
18081+void *module_alloc_exec(unsigned long size)
18082+{
18083+ struct vm_struct *area;
18084+
18085+ if (size == 0)
18086+ return NULL;
18087+
18088+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18089+ return area ? area->addr : NULL;
18090+}
18091+EXPORT_SYMBOL(module_alloc_exec);
18092+
18093+void module_free_exec(struct module *mod, void *module_region)
18094+{
18095+ vunmap(module_region);
18096+}
18097+EXPORT_SYMBOL(module_free_exec);
18098+#else
18099+void module_free_exec(struct module *mod, void *module_region)
18100+{
18101+ module_free(mod, module_region);
18102+}
18103+EXPORT_SYMBOL(module_free_exec);
18104+
18105+void *module_alloc_exec(unsigned long size)
18106+{
18107+ return __module_alloc(size, PAGE_KERNEL_RX);
18108+}
18109+EXPORT_SYMBOL(module_alloc_exec);
18110+#endif
18111+#endif
18112+
18113 #ifdef CONFIG_X86_32
18114 int apply_relocate(Elf32_Shdr *sechdrs,
18115 const char *strtab,
18116@@ -54,14 +99,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18117 unsigned int i;
18118 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18119 Elf32_Sym *sym;
18120- uint32_t *location;
18121+ uint32_t *plocation, location;
18122
18123 DEBUGP("Applying relocate section %u to %u\n", relsec,
18124 sechdrs[relsec].sh_info);
18125 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18126 /* This is where to make the change */
18127- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18128- + rel[i].r_offset;
18129+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18130+ location = (uint32_t)plocation;
18131+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18132+ plocation = ktla_ktva((void *)plocation);
18133 /* This is the symbol it is referring to. Note that all
18134 undefined symbols have been resolved. */
18135 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18136@@ -70,11 +117,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18137 switch (ELF32_R_TYPE(rel[i].r_info)) {
18138 case R_386_32:
18139 /* We add the value into the location given */
18140- *location += sym->st_value;
18141+ pax_open_kernel();
18142+ *plocation += sym->st_value;
18143+ pax_close_kernel();
18144 break;
18145 case R_386_PC32:
18146 /* Add the value, subtract its postition */
18147- *location += sym->st_value - (uint32_t)location;
18148+ pax_open_kernel();
18149+ *plocation += sym->st_value - location;
18150+ pax_close_kernel();
18151 break;
18152 default:
18153 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
18154@@ -119,21 +170,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18155 case R_X86_64_NONE:
18156 break;
18157 case R_X86_64_64:
18158+ pax_open_kernel();
18159 *(u64 *)loc = val;
18160+ pax_close_kernel();
18161 break;
18162 case R_X86_64_32:
18163+ pax_open_kernel();
18164 *(u32 *)loc = val;
18165+ pax_close_kernel();
18166 if (val != *(u32 *)loc)
18167 goto overflow;
18168 break;
18169 case R_X86_64_32S:
18170+ pax_open_kernel();
18171 *(s32 *)loc = val;
18172+ pax_close_kernel();
18173 if ((s64)val != *(s32 *)loc)
18174 goto overflow;
18175 break;
18176 case R_X86_64_PC32:
18177 val -= (u64)loc;
18178+ pax_open_kernel();
18179 *(u32 *)loc = val;
18180+ pax_close_kernel();
18181+
18182 #if 0
18183 if ((s64)val != *(s32 *)loc)
18184 goto overflow;
18185diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18186index a0b2f84..875ab81 100644
18187--- a/arch/x86/kernel/nmi.c
18188+++ b/arch/x86/kernel/nmi.c
18189@@ -460,6 +460,17 @@ static inline void nmi_nesting_postprocess(void)
18190 dotraplinkage notrace __kprobes void
18191 do_nmi(struct pt_regs *regs, long error_code)
18192 {
18193+
18194+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18195+ if (!user_mode(regs)) {
18196+ unsigned long cs = regs->cs & 0xFFFF;
18197+ unsigned long ip = ktva_ktla(regs->ip);
18198+
18199+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18200+ regs->ip = ip;
18201+ }
18202+#endif
18203+
18204 nmi_nesting_preprocess(regs);
18205
18206 nmi_enter();
18207diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18208index 676b8c7..870ba04 100644
18209--- a/arch/x86/kernel/paravirt-spinlocks.c
18210+++ b/arch/x86/kernel/paravirt-spinlocks.c
18211@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18212 arch_spin_lock(lock);
18213 }
18214
18215-struct pv_lock_ops pv_lock_ops = {
18216+struct pv_lock_ops pv_lock_ops __read_only = {
18217 #ifdef CONFIG_SMP
18218 .spin_is_locked = __ticket_spin_is_locked,
18219 .spin_is_contended = __ticket_spin_is_contended,
18220diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18221index 9ce8859..b49bf51 100644
18222--- a/arch/x86/kernel/paravirt.c
18223+++ b/arch/x86/kernel/paravirt.c
18224@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18225 {
18226 return x;
18227 }
18228+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18229+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18230+#endif
18231
18232 void __init default_banner(void)
18233 {
18234@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18235 if (opfunc == NULL)
18236 /* If there's no function, patch it with a ud2a (BUG) */
18237 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18238- else if (opfunc == _paravirt_nop)
18239+ else if (opfunc == (void *)_paravirt_nop)
18240 /* If the operation is a nop, then nop the callsite */
18241 ret = paravirt_patch_nop();
18242
18243 /* identity functions just return their single argument */
18244- else if (opfunc == _paravirt_ident_32)
18245+ else if (opfunc == (void *)_paravirt_ident_32)
18246 ret = paravirt_patch_ident_32(insnbuf, len);
18247- else if (opfunc == _paravirt_ident_64)
18248+ else if (opfunc == (void *)_paravirt_ident_64)
18249 ret = paravirt_patch_ident_64(insnbuf, len);
18250+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18251+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18252+ ret = paravirt_patch_ident_64(insnbuf, len);
18253+#endif
18254
18255 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18256 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18257@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18258 if (insn_len > len || start == NULL)
18259 insn_len = len;
18260 else
18261- memcpy(insnbuf, start, insn_len);
18262+ memcpy(insnbuf, ktla_ktva(start), insn_len);
18263
18264 return insn_len;
18265 }
18266@@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18267 preempt_enable();
18268 }
18269
18270-struct pv_info pv_info = {
18271+struct pv_info pv_info __read_only = {
18272 .name = "bare hardware",
18273 .paravirt_enabled = 0,
18274 .kernel_rpl = 0,
18275@@ -315,16 +322,16 @@ struct pv_info pv_info = {
18276 #endif
18277 };
18278
18279-struct pv_init_ops pv_init_ops = {
18280+struct pv_init_ops pv_init_ops __read_only = {
18281 .patch = native_patch,
18282 };
18283
18284-struct pv_time_ops pv_time_ops = {
18285+struct pv_time_ops pv_time_ops __read_only = {
18286 .sched_clock = native_sched_clock,
18287 .steal_clock = native_steal_clock,
18288 };
18289
18290-struct pv_irq_ops pv_irq_ops = {
18291+struct pv_irq_ops pv_irq_ops __read_only = {
18292 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18293 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18294 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18295@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18296 #endif
18297 };
18298
18299-struct pv_cpu_ops pv_cpu_ops = {
18300+struct pv_cpu_ops pv_cpu_ops __read_only = {
18301 .cpuid = native_cpuid,
18302 .get_debugreg = native_get_debugreg,
18303 .set_debugreg = native_set_debugreg,
18304@@ -397,21 +404,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18305 .end_context_switch = paravirt_nop,
18306 };
18307
18308-struct pv_apic_ops pv_apic_ops = {
18309+struct pv_apic_ops pv_apic_ops __read_only = {
18310 #ifdef CONFIG_X86_LOCAL_APIC
18311 .startup_ipi_hook = paravirt_nop,
18312 #endif
18313 };
18314
18315-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18316+#ifdef CONFIG_X86_32
18317+#ifdef CONFIG_X86_PAE
18318+/* 64-bit pagetable entries */
18319+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18320+#else
18321 /* 32-bit pagetable entries */
18322 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18323+#endif
18324 #else
18325 /* 64-bit pagetable entries */
18326 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18327 #endif
18328
18329-struct pv_mmu_ops pv_mmu_ops = {
18330+struct pv_mmu_ops pv_mmu_ops __read_only = {
18331
18332 .read_cr2 = native_read_cr2,
18333 .write_cr2 = native_write_cr2,
18334@@ -461,6 +473,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18335 .make_pud = PTE_IDENT,
18336
18337 .set_pgd = native_set_pgd,
18338+ .set_pgd_batched = native_set_pgd_batched,
18339 #endif
18340 #endif /* PAGETABLE_LEVELS >= 3 */
18341
18342@@ -480,6 +493,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18343 },
18344
18345 .set_fixmap = native_set_fixmap,
18346+
18347+#ifdef CONFIG_PAX_KERNEXEC
18348+ .pax_open_kernel = native_pax_open_kernel,
18349+ .pax_close_kernel = native_pax_close_kernel,
18350+#endif
18351+
18352 };
18353
18354 EXPORT_SYMBOL_GPL(pv_time_ops);
18355diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18356index 35ccf75..7a15747 100644
18357--- a/arch/x86/kernel/pci-iommu_table.c
18358+++ b/arch/x86/kernel/pci-iommu_table.c
18359@@ -2,7 +2,7 @@
18360 #include <asm/iommu_table.h>
18361 #include <linux/string.h>
18362 #include <linux/kallsyms.h>
18363-
18364+#include <linux/sched.h>
18365
18366 #define DEBUG 1
18367
18368diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18369index 735279e..5008677 100644
18370--- a/arch/x86/kernel/process.c
18371+++ b/arch/x86/kernel/process.c
18372@@ -34,7 +34,8 @@
18373 * section. Since TSS's are completely CPU-local, we want them
18374 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
18375 */
18376-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
18377+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
18378+EXPORT_SYMBOL(init_tss);
18379
18380 #ifdef CONFIG_X86_64
18381 static DEFINE_PER_CPU(unsigned char, is_idle);
18382@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
18383 task_xstate_cachep =
18384 kmem_cache_create("task_xstate", xstate_size,
18385 __alignof__(union thread_xstate),
18386- SLAB_PANIC | SLAB_NOTRACK, NULL);
18387+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18388 }
18389
18390 static inline void drop_fpu(struct task_struct *tsk)
18391@@ -115,7 +116,7 @@ void exit_thread(void)
18392 unsigned long *bp = t->io_bitmap_ptr;
18393
18394 if (bp) {
18395- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18396+ struct tss_struct *tss = init_tss + get_cpu();
18397
18398 t->io_bitmap_ptr = NULL;
18399 clear_thread_flag(TIF_IO_BITMAP);
18400@@ -147,7 +148,7 @@ void show_regs_common(void)
18401
18402 printk(KERN_CONT "\n");
18403 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
18404- current->pid, current->comm, print_tainted(),
18405+ task_pid_nr(current), current->comm, print_tainted(),
18406 init_utsname()->release,
18407 (int)strcspn(init_utsname()->version, " "),
18408 init_utsname()->version);
18409@@ -161,6 +162,9 @@ void flush_thread(void)
18410 {
18411 struct task_struct *tsk = current;
18412
18413+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18414+ loadsegment(gs, 0);
18415+#endif
18416 flush_ptrace_hw_breakpoint(tsk);
18417 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18418 drop_fpu(tsk);
18419@@ -318,10 +322,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18420 regs.di = (unsigned long) arg;
18421
18422 #ifdef CONFIG_X86_32
18423- regs.ds = __USER_DS;
18424- regs.es = __USER_DS;
18425+ regs.ds = __KERNEL_DS;
18426+ regs.es = __KERNEL_DS;
18427 regs.fs = __KERNEL_PERCPU;
18428- regs.gs = __KERNEL_STACK_CANARY;
18429+ savesegment(gs, regs.gs);
18430 #else
18431 regs.ss = __KERNEL_DS;
18432 #endif
18433@@ -407,7 +411,7 @@ static void __exit_idle(void)
18434 void exit_idle(void)
18435 {
18436 /* idle loop has pid 0 */
18437- if (current->pid)
18438+ if (task_pid_nr(current))
18439 return;
18440 __exit_idle();
18441 }
18442@@ -516,7 +520,7 @@ bool set_pm_idle_to_default(void)
18443
18444 return ret;
18445 }
18446-void stop_this_cpu(void *dummy)
18447+__noreturn void stop_this_cpu(void *dummy)
18448 {
18449 local_irq_disable();
18450 /*
18451@@ -746,16 +750,37 @@ static int __init idle_setup(char *str)
18452 }
18453 early_param("idle", idle_setup);
18454
18455-unsigned long arch_align_stack(unsigned long sp)
18456+#ifdef CONFIG_PAX_RANDKSTACK
18457+void pax_randomize_kstack(struct pt_regs *regs)
18458 {
18459- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18460- sp -= get_random_int() % 8192;
18461- return sp & ~0xf;
18462-}
18463+ struct thread_struct *thread = &current->thread;
18464+ unsigned long time;
18465
18466-unsigned long arch_randomize_brk(struct mm_struct *mm)
18467-{
18468- unsigned long range_end = mm->brk + 0x02000000;
18469- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18470-}
18471+ if (!randomize_va_space)
18472+ return;
18473+
18474+ if (v8086_mode(regs))
18475+ return;
18476
18477+ rdtscl(time);
18478+
18479+ /* P4 seems to return a 0 LSB, ignore it */
18480+#ifdef CONFIG_MPENTIUM4
18481+ time &= 0x3EUL;
18482+ time <<= 2;
18483+#elif defined(CONFIG_X86_64)
18484+ time &= 0xFUL;
18485+ time <<= 4;
18486+#else
18487+ time &= 0x1FUL;
18488+ time <<= 3;
18489+#endif
18490+
18491+ thread->sp0 ^= time;
18492+ load_sp0(init_tss + smp_processor_id(), thread);
18493+
18494+#ifdef CONFIG_X86_64
18495+ this_cpu_write(kernel_stack, thread->sp0);
18496+#endif
18497+}
18498+#endif
18499diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18500index 516fa18..80bd9e6 100644
18501--- a/arch/x86/kernel/process_32.c
18502+++ b/arch/x86/kernel/process_32.c
18503@@ -64,6 +64,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18504 unsigned long thread_saved_pc(struct task_struct *tsk)
18505 {
18506 return ((unsigned long *)tsk->thread.sp)[3];
18507+//XXX return tsk->thread.eip;
18508 }
18509
18510 void __show_regs(struct pt_regs *regs, int all)
18511@@ -73,15 +74,14 @@ void __show_regs(struct pt_regs *regs, int all)
18512 unsigned long sp;
18513 unsigned short ss, gs;
18514
18515- if (user_mode_vm(regs)) {
18516+ if (user_mode(regs)) {
18517 sp = regs->sp;
18518 ss = regs->ss & 0xffff;
18519- gs = get_user_gs(regs);
18520 } else {
18521 sp = kernel_stack_pointer(regs);
18522 savesegment(ss, ss);
18523- savesegment(gs, gs);
18524 }
18525+ gs = get_user_gs(regs);
18526
18527 show_regs_common();
18528
18529@@ -134,13 +134,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18530 struct task_struct *tsk;
18531 int err;
18532
18533- childregs = task_pt_regs(p);
18534+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18535 *childregs = *regs;
18536 childregs->ax = 0;
18537 childregs->sp = sp;
18538
18539 p->thread.sp = (unsigned long) childregs;
18540 p->thread.sp0 = (unsigned long) (childregs+1);
18541+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18542
18543 p->thread.ip = (unsigned long) ret_from_fork;
18544
18545@@ -231,7 +232,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18546 struct thread_struct *prev = &prev_p->thread,
18547 *next = &next_p->thread;
18548 int cpu = smp_processor_id();
18549- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18550+ struct tss_struct *tss = init_tss + cpu;
18551 fpu_switch_t fpu;
18552
18553 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18554@@ -255,6 +256,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18555 */
18556 lazy_save_gs(prev->gs);
18557
18558+#ifdef CONFIG_PAX_MEMORY_UDEREF
18559+ __set_fs(task_thread_info(next_p)->addr_limit);
18560+#endif
18561+
18562 /*
18563 * Load the per-thread Thread-Local Storage descriptor.
18564 */
18565@@ -285,6 +290,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18566 */
18567 arch_end_context_switch(next_p);
18568
18569+ this_cpu_write(current_task, next_p);
18570+ this_cpu_write(current_tinfo, &next_p->tinfo);
18571+
18572 /*
18573 * Restore %gs if needed (which is common)
18574 */
18575@@ -293,8 +301,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18576
18577 switch_fpu_finish(next_p, fpu);
18578
18579- this_cpu_write(current_task, next_p);
18580-
18581 return prev_p;
18582 }
18583
18584@@ -324,4 +330,3 @@ unsigned long get_wchan(struct task_struct *p)
18585 } while (count++ < 16);
18586 return 0;
18587 }
18588-
18589diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18590index 61cdf7f..797f06a 100644
18591--- a/arch/x86/kernel/process_64.c
18592+++ b/arch/x86/kernel/process_64.c
18593@@ -153,8 +153,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18594 struct pt_regs *childregs;
18595 struct task_struct *me = current;
18596
18597- childregs = ((struct pt_regs *)
18598- (THREAD_SIZE + task_stack_page(p))) - 1;
18599+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18600 *childregs = *regs;
18601
18602 childregs->ax = 0;
18603@@ -166,6 +165,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18604 p->thread.sp = (unsigned long) childregs;
18605 p->thread.sp0 = (unsigned long) (childregs+1);
18606 p->thread.usersp = me->thread.usersp;
18607+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18608
18609 set_tsk_thread_flag(p, TIF_FORK);
18610
18611@@ -271,7 +271,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18612 struct thread_struct *prev = &prev_p->thread;
18613 struct thread_struct *next = &next_p->thread;
18614 int cpu = smp_processor_id();
18615- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18616+ struct tss_struct *tss = init_tss + cpu;
18617 unsigned fsindex, gsindex;
18618 fpu_switch_t fpu;
18619
18620@@ -353,10 +353,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18621 prev->usersp = this_cpu_read(old_rsp);
18622 this_cpu_write(old_rsp, next->usersp);
18623 this_cpu_write(current_task, next_p);
18624+ this_cpu_write(current_tinfo, &next_p->tinfo);
18625
18626- this_cpu_write(kernel_stack,
18627- (unsigned long)task_stack_page(next_p) +
18628- THREAD_SIZE - KERNEL_STACK_OFFSET);
18629+ this_cpu_write(kernel_stack, next->sp0);
18630
18631 /*
18632 * Now maybe reload the debug registers and handle I/O bitmaps
18633@@ -425,12 +424,11 @@ unsigned long get_wchan(struct task_struct *p)
18634 if (!p || p == current || p->state == TASK_RUNNING)
18635 return 0;
18636 stack = (unsigned long)task_stack_page(p);
18637- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18638+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18639 return 0;
18640 fp = *(u64 *)(p->thread.sp);
18641 do {
18642- if (fp < (unsigned long)stack ||
18643- fp >= (unsigned long)stack+THREAD_SIZE)
18644+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18645 return 0;
18646 ip = *(u64 *)(fp+8);
18647 if (!in_sched_functions(ip))
18648diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18649index c4c6a5c..905f440 100644
18650--- a/arch/x86/kernel/ptrace.c
18651+++ b/arch/x86/kernel/ptrace.c
18652@@ -824,7 +824,7 @@ long arch_ptrace(struct task_struct *child, long request,
18653 unsigned long addr, unsigned long data)
18654 {
18655 int ret;
18656- unsigned long __user *datap = (unsigned long __user *)data;
18657+ unsigned long __user *datap = (__force unsigned long __user *)data;
18658
18659 switch (request) {
18660 /* read the word at location addr in the USER area. */
18661@@ -909,14 +909,14 @@ long arch_ptrace(struct task_struct *child, long request,
18662 if ((int) addr < 0)
18663 return -EIO;
18664 ret = do_get_thread_area(child, addr,
18665- (struct user_desc __user *)data);
18666+ (__force struct user_desc __user *) data);
18667 break;
18668
18669 case PTRACE_SET_THREAD_AREA:
18670 if ((int) addr < 0)
18671 return -EIO;
18672 ret = do_set_thread_area(child, addr,
18673- (struct user_desc __user *)data, 0);
18674+ (__force struct user_desc __user *) data, 0);
18675 break;
18676 #endif
18677
18678@@ -1426,7 +1426,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18679 memset(info, 0, sizeof(*info));
18680 info->si_signo = SIGTRAP;
18681 info->si_code = si_code;
18682- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18683+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18684 }
18685
18686 void user_single_step_siginfo(struct task_struct *tsk,
18687@@ -1455,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18688 # define IS_IA32 0
18689 #endif
18690
18691+#ifdef CONFIG_GRKERNSEC_SETXID
18692+extern void gr_delayed_cred_worker(void);
18693+#endif
18694+
18695 /*
18696 * We must return the syscall number to actually look up in the table.
18697 * This can be -1L to skip running any syscall at all.
18698@@ -1463,6 +1467,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18699 {
18700 long ret = 0;
18701
18702+#ifdef CONFIG_GRKERNSEC_SETXID
18703+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18704+ gr_delayed_cred_worker();
18705+#endif
18706+
18707 /*
18708 * If we stepped into a sysenter/syscall insn, it trapped in
18709 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18710@@ -1511,6 +1520,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18711 {
18712 bool step;
18713
18714+#ifdef CONFIG_GRKERNSEC_SETXID
18715+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18716+ gr_delayed_cred_worker();
18717+#endif
18718+
18719 audit_syscall_exit(regs);
18720
18721 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18722diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18723index 42eb330..139955c 100644
18724--- a/arch/x86/kernel/pvclock.c
18725+++ b/arch/x86/kernel/pvclock.c
18726@@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18727 return pv_tsc_khz;
18728 }
18729
18730-static atomic64_t last_value = ATOMIC64_INIT(0);
18731+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18732
18733 void pvclock_resume(void)
18734 {
18735- atomic64_set(&last_value, 0);
18736+ atomic64_set_unchecked(&last_value, 0);
18737 }
18738
18739 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18740@@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18741 * updating at the same time, and one of them could be slightly behind,
18742 * making the assumption that last_value always go forward fail to hold.
18743 */
18744- last = atomic64_read(&last_value);
18745+ last = atomic64_read_unchecked(&last_value);
18746 do {
18747 if (ret < last)
18748 return last;
18749- last = atomic64_cmpxchg(&last_value, last, ret);
18750+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18751 } while (unlikely(last != ret));
18752
18753 return ret;
18754diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18755index 5de92f1..2732385 100644
18756--- a/arch/x86/kernel/reboot.c
18757+++ b/arch/x86/kernel/reboot.c
18758@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
18759 EXPORT_SYMBOL(pm_power_off);
18760
18761 static const struct desc_ptr no_idt = {};
18762-static int reboot_mode;
18763+static unsigned short reboot_mode;
18764 enum reboot_type reboot_type = BOOT_ACPI;
18765 int reboot_force;
18766
18767@@ -157,11 +157,15 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
18768 return 0;
18769 }
18770
18771-void machine_real_restart(unsigned int type)
18772+__noreturn void machine_real_restart(unsigned int type)
18773 {
18774- void (*restart_lowmem)(unsigned int) = (void (*)(unsigned int))
18775+ void (* restart_lowmem)(unsigned int) = (void (*)(unsigned int))
18776 real_mode_header->machine_real_restart_asm;
18777
18778+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18779+ struct desc_struct *gdt;
18780+#endif
18781+
18782 local_irq_disable();
18783
18784 /*
18785@@ -189,10 +193,36 @@ void machine_real_restart(unsigned int type)
18786 * boot)". This seems like a fairly standard thing that gets set by
18787 * REBOOT.COM programs, and the previous reset routine did this
18788 * too. */
18789- *((unsigned short *)0x472) = reboot_mode;
18790+ *(unsigned short *)(__va(0x472)) = reboot_mode;
18791
18792 /* Jump to the identity-mapped low memory code */
18793+
18794+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18795+ gdt = get_cpu_gdt_table(smp_processor_id());
18796+ pax_open_kernel();
18797+#ifdef CONFIG_PAX_MEMORY_UDEREF
18798+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18799+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18800+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
18801+#endif
18802+#ifdef CONFIG_PAX_KERNEXEC
18803+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18804+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18805+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18806+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18807+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18808+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18809+#endif
18810+ pax_close_kernel();
18811+#endif
18812+
18813+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18814+ asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
18815+ unreachable();
18816+#else
18817 restart_lowmem(type);
18818+#endif
18819+
18820 }
18821 #ifdef CONFIG_APM_MODULE
18822 EXPORT_SYMBOL(machine_real_restart);
18823@@ -543,7 +573,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18824 * try to force a triple fault and then cycle between hitting the keyboard
18825 * controller and doing that
18826 */
18827-static void native_machine_emergency_restart(void)
18828+__noreturn static void native_machine_emergency_restart(void)
18829 {
18830 int i;
18831 int attempt = 0;
18832@@ -670,13 +700,13 @@ void native_machine_shutdown(void)
18833 #endif
18834 }
18835
18836-static void __machine_emergency_restart(int emergency)
18837+static __noreturn void __machine_emergency_restart(int emergency)
18838 {
18839 reboot_emergency = emergency;
18840 machine_ops.emergency_restart();
18841 }
18842
18843-static void native_machine_restart(char *__unused)
18844+static __noreturn void native_machine_restart(char *__unused)
18845 {
18846 printk("machine restart\n");
18847
18848@@ -685,7 +715,7 @@ static void native_machine_restart(char *__unused)
18849 __machine_emergency_restart(0);
18850 }
18851
18852-static void native_machine_halt(void)
18853+static __noreturn void native_machine_halt(void)
18854 {
18855 /* Stop other cpus and apics */
18856 machine_shutdown();
18857@@ -695,7 +725,7 @@ static void native_machine_halt(void)
18858 stop_this_cpu(NULL);
18859 }
18860
18861-static void native_machine_power_off(void)
18862+__noreturn static void native_machine_power_off(void)
18863 {
18864 if (pm_power_off) {
18865 if (!reboot_force)
18866@@ -704,6 +734,7 @@ static void native_machine_power_off(void)
18867 }
18868 /* A fallback in case there is no PM info available */
18869 tboot_shutdown(TB_SHUTDOWN_HALT);
18870+ unreachable();
18871 }
18872
18873 struct machine_ops machine_ops = {
18874diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
18875index 7a6f3b3..bed145d7 100644
18876--- a/arch/x86/kernel/relocate_kernel_64.S
18877+++ b/arch/x86/kernel/relocate_kernel_64.S
18878@@ -11,6 +11,7 @@
18879 #include <asm/kexec.h>
18880 #include <asm/processor-flags.h>
18881 #include <asm/pgtable_types.h>
18882+#include <asm/alternative-asm.h>
18883
18884 /*
18885 * Must be relocatable PIC code callable as a C function
18886@@ -160,13 +161,14 @@ identity_mapped:
18887 xorq %rbp, %rbp
18888 xorq %r8, %r8
18889 xorq %r9, %r9
18890- xorq %r10, %r9
18891+ xorq %r10, %r10
18892 xorq %r11, %r11
18893 xorq %r12, %r12
18894 xorq %r13, %r13
18895 xorq %r14, %r14
18896 xorq %r15, %r15
18897
18898+ pax_force_retaddr 0, 1
18899 ret
18900
18901 1:
18902diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
18903index 16be6dc..4686132 100644
18904--- a/arch/x86/kernel/setup.c
18905+++ b/arch/x86/kernel/setup.c
18906@@ -440,7 +440,7 @@ static void __init parse_setup_data(void)
18907
18908 switch (data->type) {
18909 case SETUP_E820_EXT:
18910- parse_e820_ext(data);
18911+ parse_e820_ext((struct setup_data __force_kernel *)data);
18912 break;
18913 case SETUP_DTB:
18914 add_dtb(pa_data);
18915@@ -632,7 +632,7 @@ static void __init trim_bios_range(void)
18916 * area (640->1Mb) as ram even though it is not.
18917 * take them out.
18918 */
18919- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
18920+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
18921 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
18922 }
18923
18924@@ -755,14 +755,14 @@ void __init setup_arch(char **cmdline_p)
18925
18926 if (!boot_params.hdr.root_flags)
18927 root_mountflags &= ~MS_RDONLY;
18928- init_mm.start_code = (unsigned long) _text;
18929- init_mm.end_code = (unsigned long) _etext;
18930+ init_mm.start_code = ktla_ktva((unsigned long) _text);
18931+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
18932 init_mm.end_data = (unsigned long) _edata;
18933 init_mm.brk = _brk_end;
18934
18935- code_resource.start = virt_to_phys(_text);
18936- code_resource.end = virt_to_phys(_etext)-1;
18937- data_resource.start = virt_to_phys(_etext);
18938+ code_resource.start = virt_to_phys(ktla_ktva(_text));
18939+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
18940+ data_resource.start = virt_to_phys(_sdata);
18941 data_resource.end = virt_to_phys(_edata)-1;
18942 bss_resource.start = virt_to_phys(&__bss_start);
18943 bss_resource.end = virt_to_phys(&__bss_stop)-1;
18944diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
18945index 5a98aa2..2f9288d 100644
18946--- a/arch/x86/kernel/setup_percpu.c
18947+++ b/arch/x86/kernel/setup_percpu.c
18948@@ -21,19 +21,17 @@
18949 #include <asm/cpu.h>
18950 #include <asm/stackprotector.h>
18951
18952-DEFINE_PER_CPU(int, cpu_number);
18953+#ifdef CONFIG_SMP
18954+DEFINE_PER_CPU(unsigned int, cpu_number);
18955 EXPORT_PER_CPU_SYMBOL(cpu_number);
18956+#endif
18957
18958-#ifdef CONFIG_X86_64
18959 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
18960-#else
18961-#define BOOT_PERCPU_OFFSET 0
18962-#endif
18963
18964 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
18965 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
18966
18967-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
18968+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
18969 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
18970 };
18971 EXPORT_SYMBOL(__per_cpu_offset);
18972@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
18973 {
18974 #ifdef CONFIG_X86_32
18975 struct desc_struct gdt;
18976+ unsigned long base = per_cpu_offset(cpu);
18977
18978- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
18979- 0x2 | DESCTYPE_S, 0x8);
18980- gdt.s = 1;
18981+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
18982+ 0x83 | DESCTYPE_S, 0xC);
18983 write_gdt_entry(get_cpu_gdt_table(cpu),
18984 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
18985 #endif
18986@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
18987 /* alrighty, percpu areas up and running */
18988 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
18989 for_each_possible_cpu(cpu) {
18990+#ifdef CONFIG_CC_STACKPROTECTOR
18991+#ifdef CONFIG_X86_32
18992+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
18993+#endif
18994+#endif
18995 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
18996 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
18997 per_cpu(cpu_number, cpu) = cpu;
18998@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
18999 */
19000 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
19001 #endif
19002+#ifdef CONFIG_CC_STACKPROTECTOR
19003+#ifdef CONFIG_X86_32
19004+ if (!cpu)
19005+ per_cpu(stack_canary.canary, cpu) = canary;
19006+#endif
19007+#endif
19008 /*
19009 * Up to this point, the boot CPU has been using .init.data
19010 * area. Reload any changed state for the boot CPU.
19011diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19012index 21af737..fb45e22 100644
19013--- a/arch/x86/kernel/signal.c
19014+++ b/arch/x86/kernel/signal.c
19015@@ -191,7 +191,7 @@ static unsigned long align_sigframe(unsigned long sp)
19016 * Align the stack pointer according to the i386 ABI,
19017 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19018 */
19019- sp = ((sp + 4) & -16ul) - 4;
19020+ sp = ((sp - 12) & -16ul) - 4;
19021 #else /* !CONFIG_X86_32 */
19022 sp = round_down(sp, 16) - 8;
19023 #endif
19024@@ -242,11 +242,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
19025 * Return an always-bogus address instead so we will die with SIGSEGV.
19026 */
19027 if (onsigstack && !likely(on_sig_stack(sp)))
19028- return (void __user *)-1L;
19029+ return (__force void __user *)-1L;
19030
19031 /* save i387 state */
19032 if (used_math() && save_i387_xstate(*fpstate) < 0)
19033- return (void __user *)-1L;
19034+ return (__force void __user *)-1L;
19035
19036 return (void __user *)sp;
19037 }
19038@@ -301,9 +301,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19039 }
19040
19041 if (current->mm->context.vdso)
19042- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19043+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19044 else
19045- restorer = &frame->retcode;
19046+ restorer = (void __user *)&frame->retcode;
19047 if (ka->sa.sa_flags & SA_RESTORER)
19048 restorer = ka->sa.sa_restorer;
19049
19050@@ -317,7 +317,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19051 * reasons and because gdb uses it as a signature to notice
19052 * signal handler stack frames.
19053 */
19054- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19055+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19056
19057 if (err)
19058 return -EFAULT;
19059@@ -371,7 +371,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19060 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19061
19062 /* Set up to return from userspace. */
19063- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19064+ if (current->mm->context.vdso)
19065+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19066+ else
19067+ restorer = (void __user *)&frame->retcode;
19068 if (ka->sa.sa_flags & SA_RESTORER)
19069 restorer = ka->sa.sa_restorer;
19070 put_user_ex(restorer, &frame->pretcode);
19071@@ -383,7 +386,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19072 * reasons and because gdb uses it as a signature to notice
19073 * signal handler stack frames.
19074 */
19075- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19076+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19077 } put_user_catch(err);
19078
19079 if (err)
19080diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19081index 7bd8a08..2659b5b 100644
19082--- a/arch/x86/kernel/smpboot.c
19083+++ b/arch/x86/kernel/smpboot.c
19084@@ -679,6 +679,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19085 idle->thread.sp = (unsigned long) (((struct pt_regs *)
19086 (THREAD_SIZE + task_stack_page(idle))) - 1);
19087 per_cpu(current_task, cpu) = idle;
19088+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
19089
19090 #ifdef CONFIG_X86_32
19091 /* Stack for startup_32 can be just as for start_secondary onwards */
19092@@ -686,11 +687,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19093 #else
19094 clear_tsk_thread_flag(idle, TIF_FORK);
19095 initial_gs = per_cpu_offset(cpu);
19096- per_cpu(kernel_stack, cpu) =
19097- (unsigned long)task_stack_page(idle) -
19098- KERNEL_STACK_OFFSET + THREAD_SIZE;
19099+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
19100 #endif
19101+
19102+ pax_open_kernel();
19103 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19104+ pax_close_kernel();
19105+
19106 initial_code = (unsigned long)start_secondary;
19107 stack_start = idle->thread.sp;
19108
19109@@ -826,6 +829,12 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
19110
19111 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19112
19113+#ifdef CONFIG_PAX_PER_CPU_PGD
19114+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19115+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19116+ KERNEL_PGD_PTRS);
19117+#endif
19118+
19119 err = do_boot_cpu(apicid, cpu, tidle);
19120 if (err) {
19121 pr_debug("do_boot_cpu failed %d\n", err);
19122diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19123index c346d11..d43b163 100644
19124--- a/arch/x86/kernel/step.c
19125+++ b/arch/x86/kernel/step.c
19126@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19127 struct desc_struct *desc;
19128 unsigned long base;
19129
19130- seg &= ~7UL;
19131+ seg >>= 3;
19132
19133 mutex_lock(&child->mm->context.lock);
19134- if (unlikely((seg >> 3) >= child->mm->context.size))
19135+ if (unlikely(seg >= child->mm->context.size))
19136 addr = -1L; /* bogus selector, access would fault */
19137 else {
19138 desc = child->mm->context.ldt + seg;
19139@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19140 addr += base;
19141 }
19142 mutex_unlock(&child->mm->context.lock);
19143- }
19144+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19145+ addr = ktla_ktva(addr);
19146
19147 return addr;
19148 }
19149@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19150 unsigned char opcode[15];
19151 unsigned long addr = convert_ip_to_linear(child, regs);
19152
19153+ if (addr == -EINVAL)
19154+ return 0;
19155+
19156 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19157 for (i = 0; i < copied; i++) {
19158 switch (opcode[i]) {
19159diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19160index 0b0cb5f..db6b9ed 100644
19161--- a/arch/x86/kernel/sys_i386_32.c
19162+++ b/arch/x86/kernel/sys_i386_32.c
19163@@ -24,17 +24,224 @@
19164
19165 #include <asm/syscalls.h>
19166
19167-/*
19168- * Do a system call from kernel instead of calling sys_execve so we
19169- * end up with proper pt_regs.
19170- */
19171-int kernel_execve(const char *filename,
19172- const char *const argv[],
19173- const char *const envp[])
19174+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19175 {
19176- long __res;
19177- asm volatile ("int $0x80"
19178- : "=a" (__res)
19179- : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19180- return __res;
19181+ unsigned long pax_task_size = TASK_SIZE;
19182+
19183+#ifdef CONFIG_PAX_SEGMEXEC
19184+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19185+ pax_task_size = SEGMEXEC_TASK_SIZE;
19186+#endif
19187+
19188+ if (len > pax_task_size || addr > pax_task_size - len)
19189+ return -EINVAL;
19190+
19191+ return 0;
19192+}
19193+
19194+unsigned long
19195+arch_get_unmapped_area(struct file *filp, unsigned long addr,
19196+ unsigned long len, unsigned long pgoff, unsigned long flags)
19197+{
19198+ struct mm_struct *mm = current->mm;
19199+ struct vm_area_struct *vma;
19200+ unsigned long start_addr, pax_task_size = TASK_SIZE;
19201+
19202+#ifdef CONFIG_PAX_SEGMEXEC
19203+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19204+ pax_task_size = SEGMEXEC_TASK_SIZE;
19205+#endif
19206+
19207+ pax_task_size -= PAGE_SIZE;
19208+
19209+ if (len > pax_task_size)
19210+ return -ENOMEM;
19211+
19212+ if (flags & MAP_FIXED)
19213+ return addr;
19214+
19215+#ifdef CONFIG_PAX_RANDMMAP
19216+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19217+#endif
19218+
19219+ if (addr) {
19220+ addr = PAGE_ALIGN(addr);
19221+ if (pax_task_size - len >= addr) {
19222+ vma = find_vma(mm, addr);
19223+ if (check_heap_stack_gap(vma, addr, len))
19224+ return addr;
19225+ }
19226+ }
19227+ if (len > mm->cached_hole_size) {
19228+ start_addr = addr = mm->free_area_cache;
19229+ } else {
19230+ start_addr = addr = mm->mmap_base;
19231+ mm->cached_hole_size = 0;
19232+ }
19233+
19234+#ifdef CONFIG_PAX_PAGEEXEC
19235+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19236+ start_addr = 0x00110000UL;
19237+
19238+#ifdef CONFIG_PAX_RANDMMAP
19239+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19240+ start_addr += mm->delta_mmap & 0x03FFF000UL;
19241+#endif
19242+
19243+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19244+ start_addr = addr = mm->mmap_base;
19245+ else
19246+ addr = start_addr;
19247+ }
19248+#endif
19249+
19250+full_search:
19251+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19252+ /* At this point: (!vma || addr < vma->vm_end). */
19253+ if (pax_task_size - len < addr) {
19254+ /*
19255+ * Start a new search - just in case we missed
19256+ * some holes.
19257+ */
19258+ if (start_addr != mm->mmap_base) {
19259+ start_addr = addr = mm->mmap_base;
19260+ mm->cached_hole_size = 0;
19261+ goto full_search;
19262+ }
19263+ return -ENOMEM;
19264+ }
19265+ if (check_heap_stack_gap(vma, addr, len))
19266+ break;
19267+ if (addr + mm->cached_hole_size < vma->vm_start)
19268+ mm->cached_hole_size = vma->vm_start - addr;
19269+ addr = vma->vm_end;
19270+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
19271+ start_addr = addr = mm->mmap_base;
19272+ mm->cached_hole_size = 0;
19273+ goto full_search;
19274+ }
19275+ }
19276+
19277+ /*
19278+ * Remember the place where we stopped the search:
19279+ */
19280+ mm->free_area_cache = addr + len;
19281+ return addr;
19282+}
19283+
19284+unsigned long
19285+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19286+ const unsigned long len, const unsigned long pgoff,
19287+ const unsigned long flags)
19288+{
19289+ struct vm_area_struct *vma;
19290+ struct mm_struct *mm = current->mm;
19291+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19292+
19293+#ifdef CONFIG_PAX_SEGMEXEC
19294+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19295+ pax_task_size = SEGMEXEC_TASK_SIZE;
19296+#endif
19297+
19298+ pax_task_size -= PAGE_SIZE;
19299+
19300+ /* requested length too big for entire address space */
19301+ if (len > pax_task_size)
19302+ return -ENOMEM;
19303+
19304+ if (flags & MAP_FIXED)
19305+ return addr;
19306+
19307+#ifdef CONFIG_PAX_PAGEEXEC
19308+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19309+ goto bottomup;
19310+#endif
19311+
19312+#ifdef CONFIG_PAX_RANDMMAP
19313+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19314+#endif
19315+
19316+ /* requesting a specific address */
19317+ if (addr) {
19318+ addr = PAGE_ALIGN(addr);
19319+ if (pax_task_size - len >= addr) {
19320+ vma = find_vma(mm, addr);
19321+ if (check_heap_stack_gap(vma, addr, len))
19322+ return addr;
19323+ }
19324+ }
19325+
19326+ /* check if free_area_cache is useful for us */
19327+ if (len <= mm->cached_hole_size) {
19328+ mm->cached_hole_size = 0;
19329+ mm->free_area_cache = mm->mmap_base;
19330+ }
19331+
19332+ /* either no address requested or can't fit in requested address hole */
19333+ addr = mm->free_area_cache;
19334+
19335+ /* make sure it can fit in the remaining address space */
19336+ if (addr > len) {
19337+ vma = find_vma(mm, addr-len);
19338+ if (check_heap_stack_gap(vma, addr - len, len))
19339+ /* remember the address as a hint for next time */
19340+ return (mm->free_area_cache = addr-len);
19341+ }
19342+
19343+ if (mm->mmap_base < len)
19344+ goto bottomup;
19345+
19346+ addr = mm->mmap_base-len;
19347+
19348+ do {
19349+ /*
19350+ * Lookup failure means no vma is above this address,
19351+ * else if new region fits below vma->vm_start,
19352+ * return with success:
19353+ */
19354+ vma = find_vma(mm, addr);
19355+ if (check_heap_stack_gap(vma, addr, len))
19356+ /* remember the address as a hint for next time */
19357+ return (mm->free_area_cache = addr);
19358+
19359+ /* remember the largest hole we saw so far */
19360+ if (addr + mm->cached_hole_size < vma->vm_start)
19361+ mm->cached_hole_size = vma->vm_start - addr;
19362+
19363+ /* try just below the current vma->vm_start */
19364+ addr = skip_heap_stack_gap(vma, len);
19365+ } while (!IS_ERR_VALUE(addr));
19366+
19367+bottomup:
19368+ /*
19369+ * A failed mmap() very likely causes application failure,
19370+ * so fall back to the bottom-up function here. This scenario
19371+ * can happen with large stack limits and large mmap()
19372+ * allocations.
19373+ */
19374+
19375+#ifdef CONFIG_PAX_SEGMEXEC
19376+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19377+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19378+ else
19379+#endif
19380+
19381+ mm->mmap_base = TASK_UNMAPPED_BASE;
19382+
19383+#ifdef CONFIG_PAX_RANDMMAP
19384+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19385+ mm->mmap_base += mm->delta_mmap;
19386+#endif
19387+
19388+ mm->free_area_cache = mm->mmap_base;
19389+ mm->cached_hole_size = ~0UL;
19390+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19391+ /*
19392+ * Restore the topdown base:
19393+ */
19394+ mm->mmap_base = base;
19395+ mm->free_area_cache = base;
19396+ mm->cached_hole_size = ~0UL;
19397+
19398+ return addr;
19399 }
19400diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19401index b4d3c39..82bb73b 100644
19402--- a/arch/x86/kernel/sys_x86_64.c
19403+++ b/arch/x86/kernel/sys_x86_64.c
19404@@ -95,8 +95,8 @@ out:
19405 return error;
19406 }
19407
19408-static void find_start_end(unsigned long flags, unsigned long *begin,
19409- unsigned long *end)
19410+static void find_start_end(struct mm_struct *mm, unsigned long flags,
19411+ unsigned long *begin, unsigned long *end)
19412 {
19413 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19414 unsigned long new_begin;
19415@@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19416 *begin = new_begin;
19417 }
19418 } else {
19419- *begin = TASK_UNMAPPED_BASE;
19420+ *begin = mm->mmap_base;
19421 *end = TASK_SIZE;
19422 }
19423 }
19424@@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19425 if (flags & MAP_FIXED)
19426 return addr;
19427
19428- find_start_end(flags, &begin, &end);
19429+ find_start_end(mm, flags, &begin, &end);
19430
19431 if (len > end)
19432 return -ENOMEM;
19433
19434+#ifdef CONFIG_PAX_RANDMMAP
19435+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19436+#endif
19437+
19438 if (addr) {
19439 addr = PAGE_ALIGN(addr);
19440 vma = find_vma(mm, addr);
19441- if (end - len >= addr &&
19442- (!vma || addr + len <= vma->vm_start))
19443+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19444 return addr;
19445 }
19446 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19447@@ -172,7 +175,7 @@ full_search:
19448 }
19449 return -ENOMEM;
19450 }
19451- if (!vma || addr + len <= vma->vm_start) {
19452+ if (check_heap_stack_gap(vma, addr, len)) {
19453 /*
19454 * Remember the place where we stopped the search:
19455 */
19456@@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19457 {
19458 struct vm_area_struct *vma;
19459 struct mm_struct *mm = current->mm;
19460- unsigned long addr = addr0, start_addr;
19461+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19462
19463 /* requested length too big for entire address space */
19464 if (len > TASK_SIZE)
19465@@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19466 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19467 goto bottomup;
19468
19469+#ifdef CONFIG_PAX_RANDMMAP
19470+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19471+#endif
19472+
19473 /* requesting a specific address */
19474 if (addr) {
19475 addr = PAGE_ALIGN(addr);
19476- vma = find_vma(mm, addr);
19477- if (TASK_SIZE - len >= addr &&
19478- (!vma || addr + len <= vma->vm_start))
19479- return addr;
19480+ if (TASK_SIZE - len >= addr) {
19481+ vma = find_vma(mm, addr);
19482+ if (check_heap_stack_gap(vma, addr, len))
19483+ return addr;
19484+ }
19485 }
19486
19487 /* check if free_area_cache is useful for us */
19488@@ -240,7 +248,7 @@ try_again:
19489 * return with success:
19490 */
19491 vma = find_vma(mm, addr);
19492- if (!vma || addr+len <= vma->vm_start)
19493+ if (check_heap_stack_gap(vma, addr, len))
19494 /* remember the address as a hint for next time */
19495 return mm->free_area_cache = addr;
19496
19497@@ -249,8 +257,8 @@ try_again:
19498 mm->cached_hole_size = vma->vm_start - addr;
19499
19500 /* try just below the current vma->vm_start */
19501- addr = vma->vm_start-len;
19502- } while (len < vma->vm_start);
19503+ addr = skip_heap_stack_gap(vma, len);
19504+ } while (!IS_ERR_VALUE(addr));
19505
19506 fail:
19507 /*
19508@@ -270,13 +278,21 @@ bottomup:
19509 * can happen with large stack limits and large mmap()
19510 * allocations.
19511 */
19512+ mm->mmap_base = TASK_UNMAPPED_BASE;
19513+
19514+#ifdef CONFIG_PAX_RANDMMAP
19515+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19516+ mm->mmap_base += mm->delta_mmap;
19517+#endif
19518+
19519+ mm->free_area_cache = mm->mmap_base;
19520 mm->cached_hole_size = ~0UL;
19521- mm->free_area_cache = TASK_UNMAPPED_BASE;
19522 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19523 /*
19524 * Restore the topdown base:
19525 */
19526- mm->free_area_cache = mm->mmap_base;
19527+ mm->mmap_base = base;
19528+ mm->free_area_cache = base;
19529 mm->cached_hole_size = ~0UL;
19530
19531 return addr;
19532diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19533index f84fe00..93fe08f 100644
19534--- a/arch/x86/kernel/tboot.c
19535+++ b/arch/x86/kernel/tboot.c
19536@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
19537
19538 void tboot_shutdown(u32 shutdown_type)
19539 {
19540- void (*shutdown)(void);
19541+ void (* __noreturn shutdown)(void);
19542
19543 if (!tboot_enabled())
19544 return;
19545@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
19546
19547 switch_to_tboot_pt();
19548
19549- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19550+ shutdown = (void *)tboot->shutdown_entry;
19551 shutdown();
19552
19553 /* should not reach here */
19554@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19555 return 0;
19556 }
19557
19558-static atomic_t ap_wfs_count;
19559+static atomic_unchecked_t ap_wfs_count;
19560
19561 static int tboot_wait_for_aps(int num_aps)
19562 {
19563@@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19564 {
19565 switch (action) {
19566 case CPU_DYING:
19567- atomic_inc(&ap_wfs_count);
19568+ atomic_inc_unchecked(&ap_wfs_count);
19569 if (num_online_cpus() == 1)
19570- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19571+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19572 return NOTIFY_BAD;
19573 break;
19574 }
19575@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
19576
19577 tboot_create_trampoline();
19578
19579- atomic_set(&ap_wfs_count, 0);
19580+ atomic_set_unchecked(&ap_wfs_count, 0);
19581 register_hotcpu_notifier(&tboot_cpu_notifier);
19582
19583 acpi_os_set_prepare_sleep(&tboot_sleep);
19584diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19585index 24d3c91..d06b473 100644
19586--- a/arch/x86/kernel/time.c
19587+++ b/arch/x86/kernel/time.c
19588@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19589 {
19590 unsigned long pc = instruction_pointer(regs);
19591
19592- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19593+ if (!user_mode(regs) && in_lock_functions(pc)) {
19594 #ifdef CONFIG_FRAME_POINTER
19595- return *(unsigned long *)(regs->bp + sizeof(long));
19596+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19597 #else
19598 unsigned long *sp =
19599 (unsigned long *)kernel_stack_pointer(regs);
19600@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19601 * or above a saved flags. Eflags has bits 22-31 zero,
19602 * kernel addresses don't.
19603 */
19604+
19605+#ifdef CONFIG_PAX_KERNEXEC
19606+ return ktla_ktva(sp[0]);
19607+#else
19608 if (sp[0] >> 22)
19609 return sp[0];
19610 if (sp[1] >> 22)
19611 return sp[1];
19612 #endif
19613+
19614+#endif
19615 }
19616 return pc;
19617 }
19618diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19619index 9d9d2f9..ed344e4 100644
19620--- a/arch/x86/kernel/tls.c
19621+++ b/arch/x86/kernel/tls.c
19622@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19623 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19624 return -EINVAL;
19625
19626+#ifdef CONFIG_PAX_SEGMEXEC
19627+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19628+ return -EINVAL;
19629+#endif
19630+
19631 set_tls_desc(p, idx, &info, 1);
19632
19633 return 0;
19634diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19635index 05b31d9..501d3ba 100644
19636--- a/arch/x86/kernel/traps.c
19637+++ b/arch/x86/kernel/traps.c
19638@@ -67,12 +67,6 @@ asmlinkage int system_call(void);
19639
19640 /* Do we ignore FPU interrupts ? */
19641 char ignore_fpu_irq;
19642-
19643-/*
19644- * The IDT has to be page-aligned to simplify the Pentium
19645- * F0 0F bug workaround.
19646- */
19647-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19648 #endif
19649
19650 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19651@@ -105,13 +99,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19652 }
19653
19654 static void __kprobes
19655-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19656+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19657 long error_code, siginfo_t *info)
19658 {
19659 struct task_struct *tsk = current;
19660
19661 #ifdef CONFIG_X86_32
19662- if (regs->flags & X86_VM_MASK) {
19663+ if (v8086_mode(regs)) {
19664 /*
19665 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19666 * On nmi (interrupt 2), do_trap should not be called.
19667@@ -122,7 +116,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19668 }
19669 #endif
19670
19671- if (!user_mode(regs))
19672+ if (!user_mode_novm(regs))
19673 goto kernel_trap;
19674
19675 #ifdef CONFIG_X86_32
19676@@ -145,7 +139,7 @@ trap_signal:
19677 printk_ratelimit()) {
19678 printk(KERN_INFO
19679 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19680- tsk->comm, tsk->pid, str,
19681+ tsk->comm, task_pid_nr(tsk), str,
19682 regs->ip, regs->sp, error_code);
19683 print_vma_addr(" in ", regs->ip);
19684 printk("\n");
19685@@ -162,8 +156,20 @@ kernel_trap:
19686 if (!fixup_exception(regs)) {
19687 tsk->thread.error_code = error_code;
19688 tsk->thread.trap_nr = trapnr;
19689+
19690+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19691+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19692+ str = "PAX: suspicious stack segment fault";
19693+#endif
19694+
19695 die(str, regs, error_code);
19696 }
19697+
19698+#ifdef CONFIG_PAX_REFCOUNT
19699+ if (trapnr == 4)
19700+ pax_report_refcount_overflow(regs);
19701+#endif
19702+
19703 return;
19704
19705 #ifdef CONFIG_X86_32
19706@@ -256,14 +262,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19707 conditional_sti(regs);
19708
19709 #ifdef CONFIG_X86_32
19710- if (regs->flags & X86_VM_MASK)
19711+ if (v8086_mode(regs))
19712 goto gp_in_vm86;
19713 #endif
19714
19715 tsk = current;
19716- if (!user_mode(regs))
19717+ if (!user_mode_novm(regs))
19718 goto gp_in_kernel;
19719
19720+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19721+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19722+ struct mm_struct *mm = tsk->mm;
19723+ unsigned long limit;
19724+
19725+ down_write(&mm->mmap_sem);
19726+ limit = mm->context.user_cs_limit;
19727+ if (limit < TASK_SIZE) {
19728+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19729+ up_write(&mm->mmap_sem);
19730+ return;
19731+ }
19732+ up_write(&mm->mmap_sem);
19733+ }
19734+#endif
19735+
19736 tsk->thread.error_code = error_code;
19737 tsk->thread.trap_nr = X86_TRAP_GP;
19738
19739@@ -296,6 +318,13 @@ gp_in_kernel:
19740 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
19741 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
19742 return;
19743+
19744+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19745+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19746+ die("PAX: suspicious general protection fault", regs, error_code);
19747+ else
19748+#endif
19749+
19750 die("general protection fault", regs, error_code);
19751 }
19752
19753@@ -431,7 +460,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19754 /* It's safe to allow irq's after DR6 has been saved */
19755 preempt_conditional_sti(regs);
19756
19757- if (regs->flags & X86_VM_MASK) {
19758+ if (v8086_mode(regs)) {
19759 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
19760 X86_TRAP_DB);
19761 preempt_conditional_cli(regs);
19762@@ -446,7 +475,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19763 * We already checked v86 mode above, so we can check for kernel mode
19764 * by just checking the CPL of CS.
19765 */
19766- if ((dr6 & DR_STEP) && !user_mode(regs)) {
19767+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19768 tsk->thread.debugreg6 &= ~DR_STEP;
19769 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19770 regs->flags &= ~X86_EFLAGS_TF;
19771@@ -477,7 +506,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19772 return;
19773 conditional_sti(regs);
19774
19775- if (!user_mode_vm(regs))
19776+ if (!user_mode(regs))
19777 {
19778 if (!fixup_exception(regs)) {
19779 task->thread.error_code = error_code;
19780diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
19781index dc4e910..c9dedab 100644
19782--- a/arch/x86/kernel/uprobes.c
19783+++ b/arch/x86/kernel/uprobes.c
19784@@ -606,7 +606,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
19785 int ret = NOTIFY_DONE;
19786
19787 /* We are only interested in userspace traps */
19788- if (regs && !user_mode_vm(regs))
19789+ if (regs && !user_mode(regs))
19790 return NOTIFY_DONE;
19791
19792 switch (val) {
19793diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19794index b9242ba..50c5edd 100644
19795--- a/arch/x86/kernel/verify_cpu.S
19796+++ b/arch/x86/kernel/verify_cpu.S
19797@@ -20,6 +20,7 @@
19798 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19799 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19800 * arch/x86/kernel/head_32.S: processor startup
19801+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19802 *
19803 * verify_cpu, returns the status of longmode and SSE in register %eax.
19804 * 0: Success 1: Failure
19805diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19806index 255f58a..5e91150 100644
19807--- a/arch/x86/kernel/vm86_32.c
19808+++ b/arch/x86/kernel/vm86_32.c
19809@@ -41,6 +41,7 @@
19810 #include <linux/ptrace.h>
19811 #include <linux/audit.h>
19812 #include <linux/stddef.h>
19813+#include <linux/grsecurity.h>
19814
19815 #include <asm/uaccess.h>
19816 #include <asm/io.h>
19817@@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19818 do_exit(SIGSEGV);
19819 }
19820
19821- tss = &per_cpu(init_tss, get_cpu());
19822+ tss = init_tss + get_cpu();
19823 current->thread.sp0 = current->thread.saved_sp0;
19824 current->thread.sysenter_cs = __KERNEL_CS;
19825 load_sp0(tss, &current->thread);
19826@@ -210,6 +211,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19827 struct task_struct *tsk;
19828 int tmp, ret = -EPERM;
19829
19830+#ifdef CONFIG_GRKERNSEC_VM86
19831+ if (!capable(CAP_SYS_RAWIO)) {
19832+ gr_handle_vm86();
19833+ goto out;
19834+ }
19835+#endif
19836+
19837 tsk = current;
19838 if (tsk->thread.saved_sp0)
19839 goto out;
19840@@ -240,6 +248,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19841 int tmp, ret;
19842 struct vm86plus_struct __user *v86;
19843
19844+#ifdef CONFIG_GRKERNSEC_VM86
19845+ if (!capable(CAP_SYS_RAWIO)) {
19846+ gr_handle_vm86();
19847+ ret = -EPERM;
19848+ goto out;
19849+ }
19850+#endif
19851+
19852 tsk = current;
19853 switch (cmd) {
19854 case VM86_REQUEST_IRQ:
19855@@ -326,7 +342,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
19856 tsk->thread.saved_fs = info->regs32->fs;
19857 tsk->thread.saved_gs = get_user_gs(info->regs32);
19858
19859- tss = &per_cpu(init_tss, get_cpu());
19860+ tss = init_tss + get_cpu();
19861 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
19862 if (cpu_has_sep)
19863 tsk->thread.sysenter_cs = 0;
19864@@ -533,7 +549,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
19865 goto cannot_handle;
19866 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
19867 goto cannot_handle;
19868- intr_ptr = (unsigned long __user *) (i << 2);
19869+ intr_ptr = (__force unsigned long __user *) (i << 2);
19870 if (get_user(segoffs, intr_ptr))
19871 goto cannot_handle;
19872 if ((segoffs >> 16) == BIOSSEG)
19873diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
19874index 22a1530..8fbaaad 100644
19875--- a/arch/x86/kernel/vmlinux.lds.S
19876+++ b/arch/x86/kernel/vmlinux.lds.S
19877@@ -26,6 +26,13 @@
19878 #include <asm/page_types.h>
19879 #include <asm/cache.h>
19880 #include <asm/boot.h>
19881+#include <asm/segment.h>
19882+
19883+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19884+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
19885+#else
19886+#define __KERNEL_TEXT_OFFSET 0
19887+#endif
19888
19889 #undef i386 /* in case the preprocessor is a 32bit one */
19890
19891@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
19892
19893 PHDRS {
19894 text PT_LOAD FLAGS(5); /* R_E */
19895+#ifdef CONFIG_X86_32
19896+ module PT_LOAD FLAGS(5); /* R_E */
19897+#endif
19898+#ifdef CONFIG_XEN
19899+ rodata PT_LOAD FLAGS(5); /* R_E */
19900+#else
19901+ rodata PT_LOAD FLAGS(4); /* R__ */
19902+#endif
19903 data PT_LOAD FLAGS(6); /* RW_ */
19904-#ifdef CONFIG_X86_64
19905+ init.begin PT_LOAD FLAGS(6); /* RW_ */
19906 #ifdef CONFIG_SMP
19907 percpu PT_LOAD FLAGS(6); /* RW_ */
19908 #endif
19909+ text.init PT_LOAD FLAGS(5); /* R_E */
19910+ text.exit PT_LOAD FLAGS(5); /* R_E */
19911 init PT_LOAD FLAGS(7); /* RWE */
19912-#endif
19913 note PT_NOTE FLAGS(0); /* ___ */
19914 }
19915
19916 SECTIONS
19917 {
19918 #ifdef CONFIG_X86_32
19919- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
19920- phys_startup_32 = startup_32 - LOAD_OFFSET;
19921+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
19922 #else
19923- . = __START_KERNEL;
19924- phys_startup_64 = startup_64 - LOAD_OFFSET;
19925+ . = __START_KERNEL;
19926 #endif
19927
19928 /* Text and read-only data */
19929- .text : AT(ADDR(.text) - LOAD_OFFSET) {
19930- _text = .;
19931+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19932 /* bootstrapping code */
19933+#ifdef CONFIG_X86_32
19934+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19935+#else
19936+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19937+#endif
19938+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19939+ _text = .;
19940 HEAD_TEXT
19941 #ifdef CONFIG_X86_32
19942 . = ALIGN(PAGE_SIZE);
19943@@ -108,13 +128,48 @@ SECTIONS
19944 IRQENTRY_TEXT
19945 *(.fixup)
19946 *(.gnu.warning)
19947- /* End of text section */
19948- _etext = .;
19949 } :text = 0x9090
19950
19951- NOTES :text :note
19952+ . += __KERNEL_TEXT_OFFSET;
19953
19954- EXCEPTION_TABLE(16) :text = 0x9090
19955+#ifdef CONFIG_X86_32
19956+ . = ALIGN(PAGE_SIZE);
19957+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
19958+
19959+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
19960+ MODULES_EXEC_VADDR = .;
19961+ BYTE(0)
19962+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
19963+ . = ALIGN(HPAGE_SIZE) - 1;
19964+ MODULES_EXEC_END = .;
19965+#endif
19966+
19967+ } :module
19968+#endif
19969+
19970+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
19971+ /* End of text section */
19972+ BYTE(0)
19973+ _etext = . - __KERNEL_TEXT_OFFSET;
19974+ }
19975+
19976+#ifdef CONFIG_X86_32
19977+ . = ALIGN(PAGE_SIZE);
19978+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
19979+ *(.idt)
19980+ . = ALIGN(PAGE_SIZE);
19981+ *(.empty_zero_page)
19982+ *(.initial_pg_fixmap)
19983+ *(.initial_pg_pmd)
19984+ *(.initial_page_table)
19985+ *(.swapper_pg_dir)
19986+ } :rodata
19987+#endif
19988+
19989+ . = ALIGN(PAGE_SIZE);
19990+ NOTES :rodata :note
19991+
19992+ EXCEPTION_TABLE(16) :rodata
19993
19994 #if defined(CONFIG_DEBUG_RODATA)
19995 /* .text should occupy whole number of pages */
19996@@ -126,16 +181,20 @@ SECTIONS
19997
19998 /* Data */
19999 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20000+
20001+#ifdef CONFIG_PAX_KERNEXEC
20002+ . = ALIGN(HPAGE_SIZE);
20003+#else
20004+ . = ALIGN(PAGE_SIZE);
20005+#endif
20006+
20007 /* Start of data section */
20008 _sdata = .;
20009
20010 /* init_task */
20011 INIT_TASK_DATA(THREAD_SIZE)
20012
20013-#ifdef CONFIG_X86_32
20014- /* 32 bit has nosave before _edata */
20015 NOSAVE_DATA
20016-#endif
20017
20018 PAGE_ALIGNED_DATA(PAGE_SIZE)
20019
20020@@ -176,12 +235,19 @@ SECTIONS
20021 #endif /* CONFIG_X86_64 */
20022
20023 /* Init code and data - will be freed after init */
20024- . = ALIGN(PAGE_SIZE);
20025 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20026+ BYTE(0)
20027+
20028+#ifdef CONFIG_PAX_KERNEXEC
20029+ . = ALIGN(HPAGE_SIZE);
20030+#else
20031+ . = ALIGN(PAGE_SIZE);
20032+#endif
20033+
20034 __init_begin = .; /* paired with __init_end */
20035- }
20036+ } :init.begin
20037
20038-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20039+#ifdef CONFIG_SMP
20040 /*
20041 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20042 * output PHDR, so the next output section - .init.text - should
20043@@ -190,12 +256,27 @@ SECTIONS
20044 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20045 #endif
20046
20047- INIT_TEXT_SECTION(PAGE_SIZE)
20048-#ifdef CONFIG_X86_64
20049- :init
20050-#endif
20051+ . = ALIGN(PAGE_SIZE);
20052+ init_begin = .;
20053+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20054+ VMLINUX_SYMBOL(_sinittext) = .;
20055+ INIT_TEXT
20056+ VMLINUX_SYMBOL(_einittext) = .;
20057+ . = ALIGN(PAGE_SIZE);
20058+ } :text.init
20059
20060- INIT_DATA_SECTION(16)
20061+ /*
20062+ * .exit.text is discard at runtime, not link time, to deal with
20063+ * references from .altinstructions and .eh_frame
20064+ */
20065+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20066+ EXIT_TEXT
20067+ . = ALIGN(16);
20068+ } :text.exit
20069+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20070+
20071+ . = ALIGN(PAGE_SIZE);
20072+ INIT_DATA_SECTION(16) :init
20073
20074 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
20075 __x86_cpu_dev_start = .;
20076@@ -257,19 +338,12 @@ SECTIONS
20077 }
20078
20079 . = ALIGN(8);
20080- /*
20081- * .exit.text is discard at runtime, not link time, to deal with
20082- * references from .altinstructions and .eh_frame
20083- */
20084- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20085- EXIT_TEXT
20086- }
20087
20088 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20089 EXIT_DATA
20090 }
20091
20092-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20093+#ifndef CONFIG_SMP
20094 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20095 #endif
20096
20097@@ -288,16 +362,10 @@ SECTIONS
20098 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20099 __smp_locks = .;
20100 *(.smp_locks)
20101- . = ALIGN(PAGE_SIZE);
20102 __smp_locks_end = .;
20103+ . = ALIGN(PAGE_SIZE);
20104 }
20105
20106-#ifdef CONFIG_X86_64
20107- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20108- NOSAVE_DATA
20109- }
20110-#endif
20111-
20112 /* BSS */
20113 . = ALIGN(PAGE_SIZE);
20114 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20115@@ -313,6 +381,7 @@ SECTIONS
20116 __brk_base = .;
20117 . += 64 * 1024; /* 64k alignment slop space */
20118 *(.brk_reservation) /* areas brk users have reserved */
20119+ . = ALIGN(HPAGE_SIZE);
20120 __brk_limit = .;
20121 }
20122
20123@@ -339,13 +408,12 @@ SECTIONS
20124 * for the boot processor.
20125 */
20126 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20127-INIT_PER_CPU(gdt_page);
20128 INIT_PER_CPU(irq_stack_union);
20129
20130 /*
20131 * Build-time check on the image size:
20132 */
20133-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20134+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20135 "kernel image bigger than KERNEL_IMAGE_SIZE");
20136
20137 #ifdef CONFIG_SMP
20138diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20139index 5db36ca..2938af9 100644
20140--- a/arch/x86/kernel/vsyscall_64.c
20141+++ b/arch/x86/kernel/vsyscall_64.c
20142@@ -54,15 +54,13 @@
20143 DEFINE_VVAR(int, vgetcpu_mode);
20144 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20145
20146-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20147+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20148
20149 static int __init vsyscall_setup(char *str)
20150 {
20151 if (str) {
20152 if (!strcmp("emulate", str))
20153 vsyscall_mode = EMULATE;
20154- else if (!strcmp("native", str))
20155- vsyscall_mode = NATIVE;
20156 else if (!strcmp("none", str))
20157 vsyscall_mode = NONE;
20158 else
20159@@ -309,8 +307,7 @@ done:
20160 return true;
20161
20162 sigsegv:
20163- force_sig(SIGSEGV, current);
20164- return true;
20165+ do_group_exit(SIGKILL);
20166 }
20167
20168 /*
20169@@ -363,10 +360,7 @@ void __init map_vsyscall(void)
20170 extern char __vvar_page;
20171 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20172
20173- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20174- vsyscall_mode == NATIVE
20175- ? PAGE_KERNEL_VSYSCALL
20176- : PAGE_KERNEL_VVAR);
20177+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20178 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20179 (unsigned long)VSYSCALL_START);
20180
20181diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20182index 9796c2f..f686fbf 100644
20183--- a/arch/x86/kernel/x8664_ksyms_64.c
20184+++ b/arch/x86/kernel/x8664_ksyms_64.c
20185@@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
20186 EXPORT_SYMBOL(copy_user_generic_string);
20187 EXPORT_SYMBOL(copy_user_generic_unrolled);
20188 EXPORT_SYMBOL(__copy_user_nocache);
20189-EXPORT_SYMBOL(_copy_from_user);
20190-EXPORT_SYMBOL(_copy_to_user);
20191
20192 EXPORT_SYMBOL(copy_page);
20193 EXPORT_SYMBOL(clear_page);
20194diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20195index bd18149..2ea0183 100644
20196--- a/arch/x86/kernel/xsave.c
20197+++ b/arch/x86/kernel/xsave.c
20198@@ -129,7 +129,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20199 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20200 return -EINVAL;
20201
20202- err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20203+ err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20204 fx_sw_user->extended_size -
20205 FP_XSTATE_MAGIC2_SIZE));
20206 if (err)
20207@@ -265,7 +265,7 @@ fx_only:
20208 * the other extended state.
20209 */
20210 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20211- return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20212+ return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20213 }
20214
20215 /*
20216@@ -294,7 +294,7 @@ int restore_i387_xstate(void __user *buf)
20217 if (use_xsave())
20218 err = restore_user_xstate(buf);
20219 else
20220- err = fxrstor_checking((__force struct i387_fxsave_struct *)
20221+ err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20222 buf);
20223 if (unlikely(err)) {
20224 /*
20225diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20226index 7df1c6d..9ea7c79 100644
20227--- a/arch/x86/kvm/cpuid.c
20228+++ b/arch/x86/kvm/cpuid.c
20229@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20230 struct kvm_cpuid2 *cpuid,
20231 struct kvm_cpuid_entry2 __user *entries)
20232 {
20233- int r;
20234+ int r, i;
20235
20236 r = -E2BIG;
20237 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20238 goto out;
20239 r = -EFAULT;
20240- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20241- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20242+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20243 goto out;
20244+ for (i = 0; i < cpuid->nent; ++i) {
20245+ struct kvm_cpuid_entry2 cpuid_entry;
20246+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20247+ goto out;
20248+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
20249+ }
20250 vcpu->arch.cpuid_nent = cpuid->nent;
20251 kvm_apic_set_version(vcpu);
20252 kvm_x86_ops->cpuid_update(vcpu);
20253@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20254 struct kvm_cpuid2 *cpuid,
20255 struct kvm_cpuid_entry2 __user *entries)
20256 {
20257- int r;
20258+ int r, i;
20259
20260 r = -E2BIG;
20261 if (cpuid->nent < vcpu->arch.cpuid_nent)
20262 goto out;
20263 r = -EFAULT;
20264- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20265- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20266+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20267 goto out;
20268+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20269+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20270+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20271+ goto out;
20272+ }
20273 return 0;
20274
20275 out:
20276diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20277index f95d242..3b49a90 100644
20278--- a/arch/x86/kvm/emulate.c
20279+++ b/arch/x86/kvm/emulate.c
20280@@ -256,6 +256,7 @@ struct gprefix {
20281
20282 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20283 do { \
20284+ unsigned long _tmp; \
20285 __asm__ __volatile__ ( \
20286 _PRE_EFLAGS("0", "4", "2") \
20287 _op _suffix " %"_x"3,%1; " \
20288@@ -270,8 +271,6 @@ struct gprefix {
20289 /* Raw emulation: instruction has two explicit operands. */
20290 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20291 do { \
20292- unsigned long _tmp; \
20293- \
20294 switch ((ctxt)->dst.bytes) { \
20295 case 2: \
20296 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20297@@ -287,7 +286,6 @@ struct gprefix {
20298
20299 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20300 do { \
20301- unsigned long _tmp; \
20302 switch ((ctxt)->dst.bytes) { \
20303 case 1: \
20304 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20305diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20306index 93c1574..d6097dc 100644
20307--- a/arch/x86/kvm/lapic.c
20308+++ b/arch/x86/kvm/lapic.c
20309@@ -54,7 +54,7 @@
20310 #define APIC_BUS_CYCLE_NS 1
20311
20312 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20313-#define apic_debug(fmt, arg...)
20314+#define apic_debug(fmt, arg...) do {} while (0)
20315
20316 #define APIC_LVT_NUM 6
20317 /* 14 is the version for Xeon and Pentium 8.4.8*/
20318diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20319index 34f9709..8eca2d5 100644
20320--- a/arch/x86/kvm/paging_tmpl.h
20321+++ b/arch/x86/kvm/paging_tmpl.h
20322@@ -197,7 +197,7 @@ retry_walk:
20323 if (unlikely(kvm_is_error_hva(host_addr)))
20324 goto error;
20325
20326- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20327+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20328 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20329 goto error;
20330
20331diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20332index f75af40..285b18f 100644
20333--- a/arch/x86/kvm/svm.c
20334+++ b/arch/x86/kvm/svm.c
20335@@ -3516,7 +3516,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20336 int cpu = raw_smp_processor_id();
20337
20338 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20339+
20340+ pax_open_kernel();
20341 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20342+ pax_close_kernel();
20343+
20344 load_TR_desc();
20345 }
20346
20347@@ -3894,6 +3898,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20348 #endif
20349 #endif
20350
20351+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20352+ __set_fs(current_thread_info()->addr_limit);
20353+#endif
20354+
20355 reload_tss(vcpu);
20356
20357 local_irq_disable();
20358diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20359index 32eb588..19c4fe3 100644
20360--- a/arch/x86/kvm/vmx.c
20361+++ b/arch/x86/kvm/vmx.c
20362@@ -1313,7 +1313,11 @@ static void reload_tss(void)
20363 struct desc_struct *descs;
20364
20365 descs = (void *)gdt->address;
20366+
20367+ pax_open_kernel();
20368 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20369+ pax_close_kernel();
20370+
20371 load_TR_desc();
20372 }
20373
20374@@ -1475,8 +1479,8 @@ static void __vmx_load_host_state(struct vcpu_vmx *vmx)
20375 * The sysexit path does not restore ds/es, so we must set them to
20376 * a reasonable value ourselves.
20377 */
20378- loadsegment(ds, __USER_DS);
20379- loadsegment(es, __USER_DS);
20380+ loadsegment(ds, __KERNEL_DS);
20381+ loadsegment(es, __KERNEL_DS);
20382 #endif
20383 reload_tss();
20384 #ifdef CONFIG_X86_64
20385@@ -2653,8 +2657,11 @@ static __init int hardware_setup(void)
20386 if (!cpu_has_vmx_flexpriority())
20387 flexpriority_enabled = 0;
20388
20389- if (!cpu_has_vmx_tpr_shadow())
20390- kvm_x86_ops->update_cr8_intercept = NULL;
20391+ if (!cpu_has_vmx_tpr_shadow()) {
20392+ pax_open_kernel();
20393+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20394+ pax_close_kernel();
20395+ }
20396
20397 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20398 kvm_disable_largepages();
20399@@ -3680,7 +3687,7 @@ static void vmx_set_constant_host_state(void)
20400 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20401
20402 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20403- vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20404+ vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20405
20406 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20407 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20408@@ -6218,6 +6225,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20409 "jmp .Lkvm_vmx_return \n\t"
20410 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20411 ".Lkvm_vmx_return: "
20412+
20413+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20414+ "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20415+ ".Lkvm_vmx_return2: "
20416+#endif
20417+
20418 /* Save guest registers, load host registers, keep flags */
20419 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20420 "pop %0 \n\t"
20421@@ -6266,6 +6279,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20422 #endif
20423 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20424 [wordsize]"i"(sizeof(ulong))
20425+
20426+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20427+ ,[cs]"i"(__KERNEL_CS)
20428+#endif
20429+
20430 : "cc", "memory"
20431 , R"ax", R"bx", R"di", R"si"
20432 #ifdef CONFIG_X86_64
20433@@ -6294,6 +6312,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20434 }
20435 }
20436
20437+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
20438+
20439+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20440+ loadsegment(fs, __KERNEL_PERCPU);
20441+#endif
20442+
20443+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20444+ __set_fs(current_thread_info()->addr_limit);
20445+#endif
20446+
20447 vmx->loaded_vmcs->launched = 1;
20448
20449 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
20450diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20451index be6d549..b0ba2bf 100644
20452--- a/arch/x86/kvm/x86.c
20453+++ b/arch/x86/kvm/x86.c
20454@@ -1357,8 +1357,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20455 {
20456 struct kvm *kvm = vcpu->kvm;
20457 int lm = is_long_mode(vcpu);
20458- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20459- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20460+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20461+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20462 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20463 : kvm->arch.xen_hvm_config.blob_size_32;
20464 u32 page_num = data & ~PAGE_MASK;
20465@@ -2214,6 +2214,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20466 if (n < msr_list.nmsrs)
20467 goto out;
20468 r = -EFAULT;
20469+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20470+ goto out;
20471 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20472 num_msrs_to_save * sizeof(u32)))
20473 goto out;
20474@@ -2339,7 +2341,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20475 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20476 struct kvm_interrupt *irq)
20477 {
20478- if (irq->irq < 0 || irq->irq >= 256)
20479+ if (irq->irq >= 256)
20480 return -EINVAL;
20481 if (irqchip_in_kernel(vcpu->kvm))
20482 return -ENXIO;
20483@@ -4876,7 +4878,7 @@ static void kvm_set_mmio_spte_mask(void)
20484 kvm_mmu_set_mmio_spte_mask(mask);
20485 }
20486
20487-int kvm_arch_init(void *opaque)
20488+int kvm_arch_init(const void *opaque)
20489 {
20490 int r;
20491 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20492diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20493index 642d880..44e0f3f 100644
20494--- a/arch/x86/lguest/boot.c
20495+++ b/arch/x86/lguest/boot.c
20496@@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20497 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20498 * Launcher to reboot us.
20499 */
20500-static void lguest_restart(char *reason)
20501+static __noreturn void lguest_restart(char *reason)
20502 {
20503 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20504+ BUG();
20505 }
20506
20507 /*G:050
20508diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20509index 00933d5..3a64af9 100644
20510--- a/arch/x86/lib/atomic64_386_32.S
20511+++ b/arch/x86/lib/atomic64_386_32.S
20512@@ -48,6 +48,10 @@ BEGIN(read)
20513 movl (v), %eax
20514 movl 4(v), %edx
20515 RET_ENDP
20516+BEGIN(read_unchecked)
20517+ movl (v), %eax
20518+ movl 4(v), %edx
20519+RET_ENDP
20520 #undef v
20521
20522 #define v %esi
20523@@ -55,6 +59,10 @@ BEGIN(set)
20524 movl %ebx, (v)
20525 movl %ecx, 4(v)
20526 RET_ENDP
20527+BEGIN(set_unchecked)
20528+ movl %ebx, (v)
20529+ movl %ecx, 4(v)
20530+RET_ENDP
20531 #undef v
20532
20533 #define v %esi
20534@@ -70,6 +78,20 @@ RET_ENDP
20535 BEGIN(add)
20536 addl %eax, (v)
20537 adcl %edx, 4(v)
20538+
20539+#ifdef CONFIG_PAX_REFCOUNT
20540+ jno 0f
20541+ subl %eax, (v)
20542+ sbbl %edx, 4(v)
20543+ int $4
20544+0:
20545+ _ASM_EXTABLE(0b, 0b)
20546+#endif
20547+
20548+RET_ENDP
20549+BEGIN(add_unchecked)
20550+ addl %eax, (v)
20551+ adcl %edx, 4(v)
20552 RET_ENDP
20553 #undef v
20554
20555@@ -77,6 +99,24 @@ RET_ENDP
20556 BEGIN(add_return)
20557 addl (v), %eax
20558 adcl 4(v), %edx
20559+
20560+#ifdef CONFIG_PAX_REFCOUNT
20561+ into
20562+1234:
20563+ _ASM_EXTABLE(1234b, 2f)
20564+#endif
20565+
20566+ movl %eax, (v)
20567+ movl %edx, 4(v)
20568+
20569+#ifdef CONFIG_PAX_REFCOUNT
20570+2:
20571+#endif
20572+
20573+RET_ENDP
20574+BEGIN(add_return_unchecked)
20575+ addl (v), %eax
20576+ adcl 4(v), %edx
20577 movl %eax, (v)
20578 movl %edx, 4(v)
20579 RET_ENDP
20580@@ -86,6 +126,20 @@ RET_ENDP
20581 BEGIN(sub)
20582 subl %eax, (v)
20583 sbbl %edx, 4(v)
20584+
20585+#ifdef CONFIG_PAX_REFCOUNT
20586+ jno 0f
20587+ addl %eax, (v)
20588+ adcl %edx, 4(v)
20589+ int $4
20590+0:
20591+ _ASM_EXTABLE(0b, 0b)
20592+#endif
20593+
20594+RET_ENDP
20595+BEGIN(sub_unchecked)
20596+ subl %eax, (v)
20597+ sbbl %edx, 4(v)
20598 RET_ENDP
20599 #undef v
20600
20601@@ -96,6 +150,27 @@ BEGIN(sub_return)
20602 sbbl $0, %edx
20603 addl (v), %eax
20604 adcl 4(v), %edx
20605+
20606+#ifdef CONFIG_PAX_REFCOUNT
20607+ into
20608+1234:
20609+ _ASM_EXTABLE(1234b, 2f)
20610+#endif
20611+
20612+ movl %eax, (v)
20613+ movl %edx, 4(v)
20614+
20615+#ifdef CONFIG_PAX_REFCOUNT
20616+2:
20617+#endif
20618+
20619+RET_ENDP
20620+BEGIN(sub_return_unchecked)
20621+ negl %edx
20622+ negl %eax
20623+ sbbl $0, %edx
20624+ addl (v), %eax
20625+ adcl 4(v), %edx
20626 movl %eax, (v)
20627 movl %edx, 4(v)
20628 RET_ENDP
20629@@ -105,6 +180,20 @@ RET_ENDP
20630 BEGIN(inc)
20631 addl $1, (v)
20632 adcl $0, 4(v)
20633+
20634+#ifdef CONFIG_PAX_REFCOUNT
20635+ jno 0f
20636+ subl $1, (v)
20637+ sbbl $0, 4(v)
20638+ int $4
20639+0:
20640+ _ASM_EXTABLE(0b, 0b)
20641+#endif
20642+
20643+RET_ENDP
20644+BEGIN(inc_unchecked)
20645+ addl $1, (v)
20646+ adcl $0, 4(v)
20647 RET_ENDP
20648 #undef v
20649
20650@@ -114,6 +203,26 @@ BEGIN(inc_return)
20651 movl 4(v), %edx
20652 addl $1, %eax
20653 adcl $0, %edx
20654+
20655+#ifdef CONFIG_PAX_REFCOUNT
20656+ into
20657+1234:
20658+ _ASM_EXTABLE(1234b, 2f)
20659+#endif
20660+
20661+ movl %eax, (v)
20662+ movl %edx, 4(v)
20663+
20664+#ifdef CONFIG_PAX_REFCOUNT
20665+2:
20666+#endif
20667+
20668+RET_ENDP
20669+BEGIN(inc_return_unchecked)
20670+ movl (v), %eax
20671+ movl 4(v), %edx
20672+ addl $1, %eax
20673+ adcl $0, %edx
20674 movl %eax, (v)
20675 movl %edx, 4(v)
20676 RET_ENDP
20677@@ -123,6 +232,20 @@ RET_ENDP
20678 BEGIN(dec)
20679 subl $1, (v)
20680 sbbl $0, 4(v)
20681+
20682+#ifdef CONFIG_PAX_REFCOUNT
20683+ jno 0f
20684+ addl $1, (v)
20685+ adcl $0, 4(v)
20686+ int $4
20687+0:
20688+ _ASM_EXTABLE(0b, 0b)
20689+#endif
20690+
20691+RET_ENDP
20692+BEGIN(dec_unchecked)
20693+ subl $1, (v)
20694+ sbbl $0, 4(v)
20695 RET_ENDP
20696 #undef v
20697
20698@@ -132,6 +255,26 @@ BEGIN(dec_return)
20699 movl 4(v), %edx
20700 subl $1, %eax
20701 sbbl $0, %edx
20702+
20703+#ifdef CONFIG_PAX_REFCOUNT
20704+ into
20705+1234:
20706+ _ASM_EXTABLE(1234b, 2f)
20707+#endif
20708+
20709+ movl %eax, (v)
20710+ movl %edx, 4(v)
20711+
20712+#ifdef CONFIG_PAX_REFCOUNT
20713+2:
20714+#endif
20715+
20716+RET_ENDP
20717+BEGIN(dec_return_unchecked)
20718+ movl (v), %eax
20719+ movl 4(v), %edx
20720+ subl $1, %eax
20721+ sbbl $0, %edx
20722 movl %eax, (v)
20723 movl %edx, 4(v)
20724 RET_ENDP
20725@@ -143,6 +286,13 @@ BEGIN(add_unless)
20726 adcl %edx, %edi
20727 addl (v), %eax
20728 adcl 4(v), %edx
20729+
20730+#ifdef CONFIG_PAX_REFCOUNT
20731+ into
20732+1234:
20733+ _ASM_EXTABLE(1234b, 2f)
20734+#endif
20735+
20736 cmpl %eax, %ecx
20737 je 3f
20738 1:
20739@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20740 1:
20741 addl $1, %eax
20742 adcl $0, %edx
20743+
20744+#ifdef CONFIG_PAX_REFCOUNT
20745+ into
20746+1234:
20747+ _ASM_EXTABLE(1234b, 2f)
20748+#endif
20749+
20750 movl %eax, (v)
20751 movl %edx, 4(v)
20752 movl $1, %eax
20753@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20754 movl 4(v), %edx
20755 subl $1, %eax
20756 sbbl $0, %edx
20757+
20758+#ifdef CONFIG_PAX_REFCOUNT
20759+ into
20760+1234:
20761+ _ASM_EXTABLE(1234b, 1f)
20762+#endif
20763+
20764 js 1f
20765 movl %eax, (v)
20766 movl %edx, 4(v)
20767diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20768index f5cc9eb..51fa319 100644
20769--- a/arch/x86/lib/atomic64_cx8_32.S
20770+++ b/arch/x86/lib/atomic64_cx8_32.S
20771@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20772 CFI_STARTPROC
20773
20774 read64 %ecx
20775+ pax_force_retaddr
20776 ret
20777 CFI_ENDPROC
20778 ENDPROC(atomic64_read_cx8)
20779
20780+ENTRY(atomic64_read_unchecked_cx8)
20781+ CFI_STARTPROC
20782+
20783+ read64 %ecx
20784+ pax_force_retaddr
20785+ ret
20786+ CFI_ENDPROC
20787+ENDPROC(atomic64_read_unchecked_cx8)
20788+
20789 ENTRY(atomic64_set_cx8)
20790 CFI_STARTPROC
20791
20792@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20793 cmpxchg8b (%esi)
20794 jne 1b
20795
20796+ pax_force_retaddr
20797 ret
20798 CFI_ENDPROC
20799 ENDPROC(atomic64_set_cx8)
20800
20801+ENTRY(atomic64_set_unchecked_cx8)
20802+ CFI_STARTPROC
20803+
20804+1:
20805+/* we don't need LOCK_PREFIX since aligned 64-bit writes
20806+ * are atomic on 586 and newer */
20807+ cmpxchg8b (%esi)
20808+ jne 1b
20809+
20810+ pax_force_retaddr
20811+ ret
20812+ CFI_ENDPROC
20813+ENDPROC(atomic64_set_unchecked_cx8)
20814+
20815 ENTRY(atomic64_xchg_cx8)
20816 CFI_STARTPROC
20817
20818@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
20819 cmpxchg8b (%esi)
20820 jne 1b
20821
20822+ pax_force_retaddr
20823 ret
20824 CFI_ENDPROC
20825 ENDPROC(atomic64_xchg_cx8)
20826
20827-.macro addsub_return func ins insc
20828-ENTRY(atomic64_\func\()_return_cx8)
20829+.macro addsub_return func ins insc unchecked=""
20830+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20831 CFI_STARTPROC
20832 SAVE ebp
20833 SAVE ebx
20834@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
20835 movl %edx, %ecx
20836 \ins\()l %esi, %ebx
20837 \insc\()l %edi, %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 (%ebp)
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 edi
20862 RESTORE esi
20863 RESTORE ebx
20864 RESTORE ebp
20865+ pax_force_retaddr
20866 ret
20867 CFI_ENDPROC
20868-ENDPROC(atomic64_\func\()_return_cx8)
20869+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20870 .endm
20871
20872 addsub_return add add adc
20873 addsub_return sub sub sbb
20874+addsub_return add add adc _unchecked
20875+addsub_return sub sub sbb _unchecked
20876
20877-.macro incdec_return func ins insc
20878-ENTRY(atomic64_\func\()_return_cx8)
20879+.macro incdec_return func ins insc unchecked=""
20880+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20881 CFI_STARTPROC
20882 SAVE ebx
20883
20884@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
20885 movl %edx, %ecx
20886 \ins\()l $1, %ebx
20887 \insc\()l $0, %ecx
20888+
20889+.ifb \unchecked
20890+#ifdef CONFIG_PAX_REFCOUNT
20891+ into
20892+2:
20893+ _ASM_EXTABLE(2b, 3f)
20894+#endif
20895+.endif
20896+
20897 LOCK_PREFIX
20898 cmpxchg8b (%esi)
20899 jne 1b
20900
20901-10:
20902 movl %ebx, %eax
20903 movl %ecx, %edx
20904+
20905+.ifb \unchecked
20906+#ifdef CONFIG_PAX_REFCOUNT
20907+3:
20908+#endif
20909+.endif
20910+
20911 RESTORE ebx
20912+ pax_force_retaddr
20913 ret
20914 CFI_ENDPROC
20915-ENDPROC(atomic64_\func\()_return_cx8)
20916+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20917 .endm
20918
20919 incdec_return inc add adc
20920 incdec_return dec sub sbb
20921+incdec_return inc add adc _unchecked
20922+incdec_return dec sub sbb _unchecked
20923
20924 ENTRY(atomic64_dec_if_positive_cx8)
20925 CFI_STARTPROC
20926@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
20927 movl %edx, %ecx
20928 subl $1, %ebx
20929 sbb $0, %ecx
20930+
20931+#ifdef CONFIG_PAX_REFCOUNT
20932+ into
20933+1234:
20934+ _ASM_EXTABLE(1234b, 2f)
20935+#endif
20936+
20937 js 2f
20938 LOCK_PREFIX
20939 cmpxchg8b (%esi)
20940@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
20941 movl %ebx, %eax
20942 movl %ecx, %edx
20943 RESTORE ebx
20944+ pax_force_retaddr
20945 ret
20946 CFI_ENDPROC
20947 ENDPROC(atomic64_dec_if_positive_cx8)
20948@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
20949 movl %edx, %ecx
20950 addl %ebp, %ebx
20951 adcl %edi, %ecx
20952+
20953+#ifdef CONFIG_PAX_REFCOUNT
20954+ into
20955+1234:
20956+ _ASM_EXTABLE(1234b, 3f)
20957+#endif
20958+
20959 LOCK_PREFIX
20960 cmpxchg8b (%esi)
20961 jne 1b
20962@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
20963 CFI_ADJUST_CFA_OFFSET -8
20964 RESTORE ebx
20965 RESTORE ebp
20966+ pax_force_retaddr
20967 ret
20968 4:
20969 cmpl %edx, 4(%esp)
20970@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
20971 xorl %ecx, %ecx
20972 addl $1, %ebx
20973 adcl %edx, %ecx
20974+
20975+#ifdef CONFIG_PAX_REFCOUNT
20976+ into
20977+1234:
20978+ _ASM_EXTABLE(1234b, 3f)
20979+#endif
20980+
20981 LOCK_PREFIX
20982 cmpxchg8b (%esi)
20983 jne 1b
20984@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
20985 movl $1, %eax
20986 3:
20987 RESTORE ebx
20988+ pax_force_retaddr
20989 ret
20990 CFI_ENDPROC
20991 ENDPROC(atomic64_inc_not_zero_cx8)
20992diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
20993index 2af5df3..62b1a5a 100644
20994--- a/arch/x86/lib/checksum_32.S
20995+++ b/arch/x86/lib/checksum_32.S
20996@@ -29,7 +29,8 @@
20997 #include <asm/dwarf2.h>
20998 #include <asm/errno.h>
20999 #include <asm/asm.h>
21000-
21001+#include <asm/segment.h>
21002+
21003 /*
21004 * computes a partial checksum, e.g. for TCP/UDP fragments
21005 */
21006@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21007
21008 #define ARGBASE 16
21009 #define FP 12
21010-
21011-ENTRY(csum_partial_copy_generic)
21012+
21013+ENTRY(csum_partial_copy_generic_to_user)
21014 CFI_STARTPROC
21015+
21016+#ifdef CONFIG_PAX_MEMORY_UDEREF
21017+ pushl_cfi %gs
21018+ popl_cfi %es
21019+ jmp csum_partial_copy_generic
21020+#endif
21021+
21022+ENTRY(csum_partial_copy_generic_from_user)
21023+
21024+#ifdef CONFIG_PAX_MEMORY_UDEREF
21025+ pushl_cfi %gs
21026+ popl_cfi %ds
21027+#endif
21028+
21029+ENTRY(csum_partial_copy_generic)
21030 subl $4,%esp
21031 CFI_ADJUST_CFA_OFFSET 4
21032 pushl_cfi %edi
21033@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
21034 jmp 4f
21035 SRC(1: movw (%esi), %bx )
21036 addl $2, %esi
21037-DST( movw %bx, (%edi) )
21038+DST( movw %bx, %es:(%edi) )
21039 addl $2, %edi
21040 addw %bx, %ax
21041 adcl $0, %eax
21042@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
21043 SRC(1: movl (%esi), %ebx )
21044 SRC( movl 4(%esi), %edx )
21045 adcl %ebx, %eax
21046-DST( movl %ebx, (%edi) )
21047+DST( movl %ebx, %es:(%edi) )
21048 adcl %edx, %eax
21049-DST( movl %edx, 4(%edi) )
21050+DST( movl %edx, %es:4(%edi) )
21051
21052 SRC( movl 8(%esi), %ebx )
21053 SRC( movl 12(%esi), %edx )
21054 adcl %ebx, %eax
21055-DST( movl %ebx, 8(%edi) )
21056+DST( movl %ebx, %es:8(%edi) )
21057 adcl %edx, %eax
21058-DST( movl %edx, 12(%edi) )
21059+DST( movl %edx, %es:12(%edi) )
21060
21061 SRC( movl 16(%esi), %ebx )
21062 SRC( movl 20(%esi), %edx )
21063 adcl %ebx, %eax
21064-DST( movl %ebx, 16(%edi) )
21065+DST( movl %ebx, %es:16(%edi) )
21066 adcl %edx, %eax
21067-DST( movl %edx, 20(%edi) )
21068+DST( movl %edx, %es:20(%edi) )
21069
21070 SRC( movl 24(%esi), %ebx )
21071 SRC( movl 28(%esi), %edx )
21072 adcl %ebx, %eax
21073-DST( movl %ebx, 24(%edi) )
21074+DST( movl %ebx, %es:24(%edi) )
21075 adcl %edx, %eax
21076-DST( movl %edx, 28(%edi) )
21077+DST( movl %edx, %es:28(%edi) )
21078
21079 lea 32(%esi), %esi
21080 lea 32(%edi), %edi
21081@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
21082 shrl $2, %edx # This clears CF
21083 SRC(3: movl (%esi), %ebx )
21084 adcl %ebx, %eax
21085-DST( movl %ebx, (%edi) )
21086+DST( movl %ebx, %es:(%edi) )
21087 lea 4(%esi), %esi
21088 lea 4(%edi), %edi
21089 dec %edx
21090@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
21091 jb 5f
21092 SRC( movw (%esi), %cx )
21093 leal 2(%esi), %esi
21094-DST( movw %cx, (%edi) )
21095+DST( movw %cx, %es:(%edi) )
21096 leal 2(%edi), %edi
21097 je 6f
21098 shll $16,%ecx
21099 SRC(5: movb (%esi), %cl )
21100-DST( movb %cl, (%edi) )
21101+DST( movb %cl, %es:(%edi) )
21102 6: addl %ecx, %eax
21103 adcl $0, %eax
21104 7:
21105@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
21106
21107 6001:
21108 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21109- movl $-EFAULT, (%ebx)
21110+ movl $-EFAULT, %ss:(%ebx)
21111
21112 # zero the complete destination - computing the rest
21113 # is too much work
21114@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
21115
21116 6002:
21117 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21118- movl $-EFAULT,(%ebx)
21119+ movl $-EFAULT,%ss:(%ebx)
21120 jmp 5000b
21121
21122 .previous
21123
21124+ pushl_cfi %ss
21125+ popl_cfi %ds
21126+ pushl_cfi %ss
21127+ popl_cfi %es
21128 popl_cfi %ebx
21129 CFI_RESTORE ebx
21130 popl_cfi %esi
21131@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
21132 popl_cfi %ecx # equivalent to addl $4,%esp
21133 ret
21134 CFI_ENDPROC
21135-ENDPROC(csum_partial_copy_generic)
21136+ENDPROC(csum_partial_copy_generic_to_user)
21137
21138 #else
21139
21140 /* Version for PentiumII/PPro */
21141
21142 #define ROUND1(x) \
21143+ nop; nop; nop; \
21144 SRC(movl x(%esi), %ebx ) ; \
21145 addl %ebx, %eax ; \
21146- DST(movl %ebx, x(%edi) ) ;
21147+ DST(movl %ebx, %es:x(%edi)) ;
21148
21149 #define ROUND(x) \
21150+ nop; nop; nop; \
21151 SRC(movl x(%esi), %ebx ) ; \
21152 adcl %ebx, %eax ; \
21153- DST(movl %ebx, x(%edi) ) ;
21154+ DST(movl %ebx, %es:x(%edi)) ;
21155
21156 #define ARGBASE 12
21157-
21158-ENTRY(csum_partial_copy_generic)
21159+
21160+ENTRY(csum_partial_copy_generic_to_user)
21161 CFI_STARTPROC
21162+
21163+#ifdef CONFIG_PAX_MEMORY_UDEREF
21164+ pushl_cfi %gs
21165+ popl_cfi %es
21166+ jmp csum_partial_copy_generic
21167+#endif
21168+
21169+ENTRY(csum_partial_copy_generic_from_user)
21170+
21171+#ifdef CONFIG_PAX_MEMORY_UDEREF
21172+ pushl_cfi %gs
21173+ popl_cfi %ds
21174+#endif
21175+
21176+ENTRY(csum_partial_copy_generic)
21177 pushl_cfi %ebx
21178 CFI_REL_OFFSET ebx, 0
21179 pushl_cfi %edi
21180@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
21181 subl %ebx, %edi
21182 lea -1(%esi),%edx
21183 andl $-32,%edx
21184- lea 3f(%ebx,%ebx), %ebx
21185+ lea 3f(%ebx,%ebx,2), %ebx
21186 testl %esi, %esi
21187 jmp *%ebx
21188 1: addl $64,%esi
21189@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
21190 jb 5f
21191 SRC( movw (%esi), %dx )
21192 leal 2(%esi), %esi
21193-DST( movw %dx, (%edi) )
21194+DST( movw %dx, %es:(%edi) )
21195 leal 2(%edi), %edi
21196 je 6f
21197 shll $16,%edx
21198 5:
21199 SRC( movb (%esi), %dl )
21200-DST( movb %dl, (%edi) )
21201+DST( movb %dl, %es:(%edi) )
21202 6: addl %edx, %eax
21203 adcl $0, %eax
21204 7:
21205 .section .fixup, "ax"
21206 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21207- movl $-EFAULT, (%ebx)
21208+ movl $-EFAULT, %ss:(%ebx)
21209 # zero the complete destination (computing the rest is too much work)
21210 movl ARGBASE+8(%esp),%edi # dst
21211 movl ARGBASE+12(%esp),%ecx # len
21212@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
21213 rep; stosb
21214 jmp 7b
21215 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21216- movl $-EFAULT, (%ebx)
21217+ movl $-EFAULT, %ss:(%ebx)
21218 jmp 7b
21219 .previous
21220
21221+#ifdef CONFIG_PAX_MEMORY_UDEREF
21222+ pushl_cfi %ss
21223+ popl_cfi %ds
21224+ pushl_cfi %ss
21225+ popl_cfi %es
21226+#endif
21227+
21228 popl_cfi %esi
21229 CFI_RESTORE esi
21230 popl_cfi %edi
21231@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
21232 CFI_RESTORE ebx
21233 ret
21234 CFI_ENDPROC
21235-ENDPROC(csum_partial_copy_generic)
21236+ENDPROC(csum_partial_copy_generic_to_user)
21237
21238 #undef ROUND
21239 #undef ROUND1
21240diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21241index f2145cf..cea889d 100644
21242--- a/arch/x86/lib/clear_page_64.S
21243+++ b/arch/x86/lib/clear_page_64.S
21244@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21245 movl $4096/8,%ecx
21246 xorl %eax,%eax
21247 rep stosq
21248+ pax_force_retaddr
21249 ret
21250 CFI_ENDPROC
21251 ENDPROC(clear_page_c)
21252@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21253 movl $4096,%ecx
21254 xorl %eax,%eax
21255 rep stosb
21256+ pax_force_retaddr
21257 ret
21258 CFI_ENDPROC
21259 ENDPROC(clear_page_c_e)
21260@@ -43,6 +45,7 @@ ENTRY(clear_page)
21261 leaq 64(%rdi),%rdi
21262 jnz .Lloop
21263 nop
21264+ pax_force_retaddr
21265 ret
21266 CFI_ENDPROC
21267 .Lclear_page_end:
21268@@ -58,7 +61,7 @@ ENDPROC(clear_page)
21269
21270 #include <asm/cpufeature.h>
21271
21272- .section .altinstr_replacement,"ax"
21273+ .section .altinstr_replacement,"a"
21274 1: .byte 0xeb /* jmp <disp8> */
21275 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21276 2: .byte 0xeb /* jmp <disp8> */
21277diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21278index 1e572c5..2a162cd 100644
21279--- a/arch/x86/lib/cmpxchg16b_emu.S
21280+++ b/arch/x86/lib/cmpxchg16b_emu.S
21281@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21282
21283 popf
21284 mov $1, %al
21285+ pax_force_retaddr
21286 ret
21287
21288 not_same:
21289 popf
21290 xor %al,%al
21291+ pax_force_retaddr
21292 ret
21293
21294 CFI_ENDPROC
21295diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21296index 6b34d04..dccb07f 100644
21297--- a/arch/x86/lib/copy_page_64.S
21298+++ b/arch/x86/lib/copy_page_64.S
21299@@ -9,6 +9,7 @@ copy_page_c:
21300 CFI_STARTPROC
21301 movl $4096/8,%ecx
21302 rep movsq
21303+ pax_force_retaddr
21304 ret
21305 CFI_ENDPROC
21306 ENDPROC(copy_page_c)
21307@@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21308
21309 ENTRY(copy_page)
21310 CFI_STARTPROC
21311- subq $2*8,%rsp
21312- CFI_ADJUST_CFA_OFFSET 2*8
21313+ subq $3*8,%rsp
21314+ CFI_ADJUST_CFA_OFFSET 3*8
21315 movq %rbx,(%rsp)
21316 CFI_REL_OFFSET rbx, 0
21317 movq %r12,1*8(%rsp)
21318 CFI_REL_OFFSET r12, 1*8
21319+ movq %r13,2*8(%rsp)
21320+ CFI_REL_OFFSET r13, 2*8
21321
21322 movl $(4096/64)-5,%ecx
21323 .p2align 4
21324@@ -37,7 +40,7 @@ ENTRY(copy_page)
21325 movq 16 (%rsi), %rdx
21326 movq 24 (%rsi), %r8
21327 movq 32 (%rsi), %r9
21328- movq 40 (%rsi), %r10
21329+ movq 40 (%rsi), %r13
21330 movq 48 (%rsi), %r11
21331 movq 56 (%rsi), %r12
21332
21333@@ -48,7 +51,7 @@ ENTRY(copy_page)
21334 movq %rdx, 16 (%rdi)
21335 movq %r8, 24 (%rdi)
21336 movq %r9, 32 (%rdi)
21337- movq %r10, 40 (%rdi)
21338+ movq %r13, 40 (%rdi)
21339 movq %r11, 48 (%rdi)
21340 movq %r12, 56 (%rdi)
21341
21342@@ -67,7 +70,7 @@ ENTRY(copy_page)
21343 movq 16 (%rsi), %rdx
21344 movq 24 (%rsi), %r8
21345 movq 32 (%rsi), %r9
21346- movq 40 (%rsi), %r10
21347+ movq 40 (%rsi), %r13
21348 movq 48 (%rsi), %r11
21349 movq 56 (%rsi), %r12
21350
21351@@ -76,7 +79,7 @@ ENTRY(copy_page)
21352 movq %rdx, 16 (%rdi)
21353 movq %r8, 24 (%rdi)
21354 movq %r9, 32 (%rdi)
21355- movq %r10, 40 (%rdi)
21356+ movq %r13, 40 (%rdi)
21357 movq %r11, 48 (%rdi)
21358 movq %r12, 56 (%rdi)
21359
21360@@ -89,8 +92,11 @@ ENTRY(copy_page)
21361 CFI_RESTORE rbx
21362 movq 1*8(%rsp),%r12
21363 CFI_RESTORE r12
21364- addq $2*8,%rsp
21365- CFI_ADJUST_CFA_OFFSET -2*8
21366+ movq 2*8(%rsp),%r13
21367+ CFI_RESTORE r13
21368+ addq $3*8,%rsp
21369+ CFI_ADJUST_CFA_OFFSET -3*8
21370+ pax_force_retaddr
21371 ret
21372 .Lcopy_page_end:
21373 CFI_ENDPROC
21374@@ -101,7 +107,7 @@ ENDPROC(copy_page)
21375
21376 #include <asm/cpufeature.h>
21377
21378- .section .altinstr_replacement,"ax"
21379+ .section .altinstr_replacement,"a"
21380 1: .byte 0xeb /* jmp <disp8> */
21381 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21382 2:
21383diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21384index 5b2995f..78e7644 100644
21385--- a/arch/x86/lib/copy_user_64.S
21386+++ b/arch/x86/lib/copy_user_64.S
21387@@ -17,6 +17,7 @@
21388 #include <asm/cpufeature.h>
21389 #include <asm/alternative-asm.h>
21390 #include <asm/asm.h>
21391+#include <asm/pgtable.h>
21392
21393 /*
21394 * By placing feature2 after feature1 in altinstructions section, we logically
21395@@ -30,7 +31,7 @@
21396 .byte 0xe9 /* 32bit jump */
21397 .long \orig-1f /* by default jump to orig */
21398 1:
21399- .section .altinstr_replacement,"ax"
21400+ .section .altinstr_replacement,"a"
21401 2: .byte 0xe9 /* near jump with 32bit immediate */
21402 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21403 3: .byte 0xe9 /* near jump with 32bit immediate */
21404@@ -69,47 +70,20 @@
21405 #endif
21406 .endm
21407
21408-/* Standard copy_to_user with segment limit checking */
21409-ENTRY(_copy_to_user)
21410- CFI_STARTPROC
21411- GET_THREAD_INFO(%rax)
21412- movq %rdi,%rcx
21413- addq %rdx,%rcx
21414- jc bad_to_user
21415- cmpq TI_addr_limit(%rax),%rcx
21416- ja bad_to_user
21417- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21418- copy_user_generic_unrolled,copy_user_generic_string, \
21419- copy_user_enhanced_fast_string
21420- CFI_ENDPROC
21421-ENDPROC(_copy_to_user)
21422-
21423-/* Standard copy_from_user with segment limit checking */
21424-ENTRY(_copy_from_user)
21425- CFI_STARTPROC
21426- GET_THREAD_INFO(%rax)
21427- movq %rsi,%rcx
21428- addq %rdx,%rcx
21429- jc bad_from_user
21430- cmpq TI_addr_limit(%rax),%rcx
21431- ja bad_from_user
21432- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21433- copy_user_generic_unrolled,copy_user_generic_string, \
21434- copy_user_enhanced_fast_string
21435- CFI_ENDPROC
21436-ENDPROC(_copy_from_user)
21437-
21438 .section .fixup,"ax"
21439 /* must zero dest */
21440 ENTRY(bad_from_user)
21441 bad_from_user:
21442 CFI_STARTPROC
21443+ testl %edx,%edx
21444+ js bad_to_user
21445 movl %edx,%ecx
21446 xorl %eax,%eax
21447 rep
21448 stosb
21449 bad_to_user:
21450 movl %edx,%eax
21451+ pax_force_retaddr
21452 ret
21453 CFI_ENDPROC
21454 ENDPROC(bad_from_user)
21455@@ -139,19 +113,19 @@ ENTRY(copy_user_generic_unrolled)
21456 jz 17f
21457 1: movq (%rsi),%r8
21458 2: movq 1*8(%rsi),%r9
21459-3: movq 2*8(%rsi),%r10
21460+3: movq 2*8(%rsi),%rax
21461 4: movq 3*8(%rsi),%r11
21462 5: movq %r8,(%rdi)
21463 6: movq %r9,1*8(%rdi)
21464-7: movq %r10,2*8(%rdi)
21465+7: movq %rax,2*8(%rdi)
21466 8: movq %r11,3*8(%rdi)
21467 9: movq 4*8(%rsi),%r8
21468 10: movq 5*8(%rsi),%r9
21469-11: movq 6*8(%rsi),%r10
21470+11: movq 6*8(%rsi),%rax
21471 12: movq 7*8(%rsi),%r11
21472 13: movq %r8,4*8(%rdi)
21473 14: movq %r9,5*8(%rdi)
21474-15: movq %r10,6*8(%rdi)
21475+15: movq %rax,6*8(%rdi)
21476 16: movq %r11,7*8(%rdi)
21477 leaq 64(%rsi),%rsi
21478 leaq 64(%rdi),%rdi
21479@@ -177,6 +151,7 @@ ENTRY(copy_user_generic_unrolled)
21480 decl %ecx
21481 jnz 21b
21482 23: xor %eax,%eax
21483+ pax_force_retaddr
21484 ret
21485
21486 .section .fixup,"ax"
21487@@ -246,6 +221,7 @@ ENTRY(copy_user_generic_string)
21488 3: rep
21489 movsb
21490 4: xorl %eax,%eax
21491+ pax_force_retaddr
21492 ret
21493
21494 .section .fixup,"ax"
21495@@ -279,6 +255,7 @@ ENTRY(copy_user_enhanced_fast_string)
21496 1: rep
21497 movsb
21498 2: xorl %eax,%eax
21499+ pax_force_retaddr
21500 ret
21501
21502 .section .fixup,"ax"
21503diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21504index cacddc7..09d49e4 100644
21505--- a/arch/x86/lib/copy_user_nocache_64.S
21506+++ b/arch/x86/lib/copy_user_nocache_64.S
21507@@ -8,6 +8,7 @@
21508
21509 #include <linux/linkage.h>
21510 #include <asm/dwarf2.h>
21511+#include <asm/alternative-asm.h>
21512
21513 #define FIX_ALIGNMENT 1
21514
21515@@ -15,6 +16,7 @@
21516 #include <asm/asm-offsets.h>
21517 #include <asm/thread_info.h>
21518 #include <asm/asm.h>
21519+#include <asm/pgtable.h>
21520
21521 .macro ALIGN_DESTINATION
21522 #ifdef FIX_ALIGNMENT
21523@@ -48,6 +50,15 @@
21524 */
21525 ENTRY(__copy_user_nocache)
21526 CFI_STARTPROC
21527+
21528+#ifdef CONFIG_PAX_MEMORY_UDEREF
21529+ mov $PAX_USER_SHADOW_BASE,%rcx
21530+ cmp %rcx,%rsi
21531+ jae 1f
21532+ add %rcx,%rsi
21533+1:
21534+#endif
21535+
21536 cmpl $8,%edx
21537 jb 20f /* less then 8 bytes, go to byte copy loop */
21538 ALIGN_DESTINATION
21539@@ -57,19 +68,19 @@ ENTRY(__copy_user_nocache)
21540 jz 17f
21541 1: movq (%rsi),%r8
21542 2: movq 1*8(%rsi),%r9
21543-3: movq 2*8(%rsi),%r10
21544+3: movq 2*8(%rsi),%rax
21545 4: movq 3*8(%rsi),%r11
21546 5: movnti %r8,(%rdi)
21547 6: movnti %r9,1*8(%rdi)
21548-7: movnti %r10,2*8(%rdi)
21549+7: movnti %rax,2*8(%rdi)
21550 8: movnti %r11,3*8(%rdi)
21551 9: movq 4*8(%rsi),%r8
21552 10: movq 5*8(%rsi),%r9
21553-11: movq 6*8(%rsi),%r10
21554+11: movq 6*8(%rsi),%rax
21555 12: movq 7*8(%rsi),%r11
21556 13: movnti %r8,4*8(%rdi)
21557 14: movnti %r9,5*8(%rdi)
21558-15: movnti %r10,6*8(%rdi)
21559+15: movnti %rax,6*8(%rdi)
21560 16: movnti %r11,7*8(%rdi)
21561 leaq 64(%rsi),%rsi
21562 leaq 64(%rdi),%rdi
21563@@ -96,6 +107,7 @@ ENTRY(__copy_user_nocache)
21564 jnz 21b
21565 23: xorl %eax,%eax
21566 sfence
21567+ pax_force_retaddr
21568 ret
21569
21570 .section .fixup,"ax"
21571diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21572index 2419d5f..953ee51 100644
21573--- a/arch/x86/lib/csum-copy_64.S
21574+++ b/arch/x86/lib/csum-copy_64.S
21575@@ -9,6 +9,7 @@
21576 #include <asm/dwarf2.h>
21577 #include <asm/errno.h>
21578 #include <asm/asm.h>
21579+#include <asm/alternative-asm.h>
21580
21581 /*
21582 * Checksum copy with exception handling.
21583@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
21584 CFI_RESTORE rbp
21585 addq $7*8, %rsp
21586 CFI_ADJUST_CFA_OFFSET -7*8
21587+ pax_force_retaddr 0, 1
21588 ret
21589 CFI_RESTORE_STATE
21590
21591diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21592index 25b7ae8..3b52ccd 100644
21593--- a/arch/x86/lib/csum-wrappers_64.c
21594+++ b/arch/x86/lib/csum-wrappers_64.c
21595@@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21596 len -= 2;
21597 }
21598 }
21599- isum = csum_partial_copy_generic((__force const void *)src,
21600+
21601+#ifdef CONFIG_PAX_MEMORY_UDEREF
21602+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21603+ src += PAX_USER_SHADOW_BASE;
21604+#endif
21605+
21606+ isum = csum_partial_copy_generic((const void __force_kernel *)src,
21607 dst, len, isum, errp, NULL);
21608 if (unlikely(*errp))
21609 goto out_err;
21610@@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21611 }
21612
21613 *errp = 0;
21614- return csum_partial_copy_generic(src, (void __force *)dst,
21615+
21616+#ifdef CONFIG_PAX_MEMORY_UDEREF
21617+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21618+ dst += PAX_USER_SHADOW_BASE;
21619+#endif
21620+
21621+ return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21622 len, isum, NULL, errp);
21623 }
21624 EXPORT_SYMBOL(csum_partial_copy_to_user);
21625diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21626index b33b1fb..219f389 100644
21627--- a/arch/x86/lib/getuser.S
21628+++ b/arch/x86/lib/getuser.S
21629@@ -33,15 +33,38 @@
21630 #include <asm/asm-offsets.h>
21631 #include <asm/thread_info.h>
21632 #include <asm/asm.h>
21633+#include <asm/segment.h>
21634+#include <asm/pgtable.h>
21635+#include <asm/alternative-asm.h>
21636+
21637+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21638+#define __copyuser_seg gs;
21639+#else
21640+#define __copyuser_seg
21641+#endif
21642
21643 .text
21644 ENTRY(__get_user_1)
21645 CFI_STARTPROC
21646+
21647+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21648 GET_THREAD_INFO(%_ASM_DX)
21649 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21650 jae bad_get_user
21651-1: movzb (%_ASM_AX),%edx
21652+
21653+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21654+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21655+ cmp %_ASM_DX,%_ASM_AX
21656+ jae 1234f
21657+ add %_ASM_DX,%_ASM_AX
21658+1234:
21659+#endif
21660+
21661+#endif
21662+
21663+1: __copyuser_seg movzb (%_ASM_AX),%edx
21664 xor %eax,%eax
21665+ pax_force_retaddr
21666 ret
21667 CFI_ENDPROC
21668 ENDPROC(__get_user_1)
21669@@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21670 ENTRY(__get_user_2)
21671 CFI_STARTPROC
21672 add $1,%_ASM_AX
21673+
21674+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21675 jc bad_get_user
21676 GET_THREAD_INFO(%_ASM_DX)
21677 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21678 jae bad_get_user
21679-2: movzwl -1(%_ASM_AX),%edx
21680+
21681+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21682+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21683+ cmp %_ASM_DX,%_ASM_AX
21684+ jae 1234f
21685+ add %_ASM_DX,%_ASM_AX
21686+1234:
21687+#endif
21688+
21689+#endif
21690+
21691+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21692 xor %eax,%eax
21693+ pax_force_retaddr
21694 ret
21695 CFI_ENDPROC
21696 ENDPROC(__get_user_2)
21697@@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21698 ENTRY(__get_user_4)
21699 CFI_STARTPROC
21700 add $3,%_ASM_AX
21701+
21702+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21703 jc bad_get_user
21704 GET_THREAD_INFO(%_ASM_DX)
21705 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21706 jae bad_get_user
21707-3: mov -3(%_ASM_AX),%edx
21708+
21709+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21710+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21711+ cmp %_ASM_DX,%_ASM_AX
21712+ jae 1234f
21713+ add %_ASM_DX,%_ASM_AX
21714+1234:
21715+#endif
21716+
21717+#endif
21718+
21719+3: __copyuser_seg mov -3(%_ASM_AX),%edx
21720 xor %eax,%eax
21721+ pax_force_retaddr
21722 ret
21723 CFI_ENDPROC
21724 ENDPROC(__get_user_4)
21725@@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21726 GET_THREAD_INFO(%_ASM_DX)
21727 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21728 jae bad_get_user
21729+
21730+#ifdef CONFIG_PAX_MEMORY_UDEREF
21731+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21732+ cmp %_ASM_DX,%_ASM_AX
21733+ jae 1234f
21734+ add %_ASM_DX,%_ASM_AX
21735+1234:
21736+#endif
21737+
21738 4: movq -7(%_ASM_AX),%_ASM_DX
21739 xor %eax,%eax
21740+ pax_force_retaddr
21741 ret
21742 CFI_ENDPROC
21743 ENDPROC(__get_user_8)
21744@@ -91,6 +152,7 @@ bad_get_user:
21745 CFI_STARTPROC
21746 xor %edx,%edx
21747 mov $(-EFAULT),%_ASM_AX
21748+ pax_force_retaddr
21749 ret
21750 CFI_ENDPROC
21751 END(bad_get_user)
21752diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21753index b1e6c4b..21ae8fc 100644
21754--- a/arch/x86/lib/insn.c
21755+++ b/arch/x86/lib/insn.c
21756@@ -21,6 +21,11 @@
21757 #include <linux/string.h>
21758 #include <asm/inat.h>
21759 #include <asm/insn.h>
21760+#ifdef __KERNEL__
21761+#include <asm/pgtable_types.h>
21762+#else
21763+#define ktla_ktva(addr) addr
21764+#endif
21765
21766 /* Verify next sizeof(t) bytes can be on the same instruction */
21767 #define validate_next(t, insn, n) \
21768@@ -49,8 +54,8 @@
21769 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21770 {
21771 memset(insn, 0, sizeof(*insn));
21772- insn->kaddr = kaddr;
21773- insn->next_byte = kaddr;
21774+ insn->kaddr = ktla_ktva(kaddr);
21775+ insn->next_byte = ktla_ktva(kaddr);
21776 insn->x86_64 = x86_64 ? 1 : 0;
21777 insn->opnd_bytes = 4;
21778 if (x86_64)
21779diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21780index 05a95e7..326f2fa 100644
21781--- a/arch/x86/lib/iomap_copy_64.S
21782+++ b/arch/x86/lib/iomap_copy_64.S
21783@@ -17,6 +17,7 @@
21784
21785 #include <linux/linkage.h>
21786 #include <asm/dwarf2.h>
21787+#include <asm/alternative-asm.h>
21788
21789 /*
21790 * override generic version in lib/iomap_copy.c
21791@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21792 CFI_STARTPROC
21793 movl %edx,%ecx
21794 rep movsd
21795+ pax_force_retaddr
21796 ret
21797 CFI_ENDPROC
21798 ENDPROC(__iowrite32_copy)
21799diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21800index 1c273be..da9cc0e 100644
21801--- a/arch/x86/lib/memcpy_64.S
21802+++ b/arch/x86/lib/memcpy_64.S
21803@@ -33,6 +33,7 @@
21804 rep movsq
21805 movl %edx, %ecx
21806 rep movsb
21807+ pax_force_retaddr
21808 ret
21809 .Lmemcpy_e:
21810 .previous
21811@@ -49,6 +50,7 @@
21812 movq %rdi, %rax
21813 movq %rdx, %rcx
21814 rep movsb
21815+ pax_force_retaddr
21816 ret
21817 .Lmemcpy_e_e:
21818 .previous
21819@@ -76,13 +78,13 @@ ENTRY(memcpy)
21820 */
21821 movq 0*8(%rsi), %r8
21822 movq 1*8(%rsi), %r9
21823- movq 2*8(%rsi), %r10
21824+ movq 2*8(%rsi), %rcx
21825 movq 3*8(%rsi), %r11
21826 leaq 4*8(%rsi), %rsi
21827
21828 movq %r8, 0*8(%rdi)
21829 movq %r9, 1*8(%rdi)
21830- movq %r10, 2*8(%rdi)
21831+ movq %rcx, 2*8(%rdi)
21832 movq %r11, 3*8(%rdi)
21833 leaq 4*8(%rdi), %rdi
21834 jae .Lcopy_forward_loop
21835@@ -105,12 +107,12 @@ ENTRY(memcpy)
21836 subq $0x20, %rdx
21837 movq -1*8(%rsi), %r8
21838 movq -2*8(%rsi), %r9
21839- movq -3*8(%rsi), %r10
21840+ movq -3*8(%rsi), %rcx
21841 movq -4*8(%rsi), %r11
21842 leaq -4*8(%rsi), %rsi
21843 movq %r8, -1*8(%rdi)
21844 movq %r9, -2*8(%rdi)
21845- movq %r10, -3*8(%rdi)
21846+ movq %rcx, -3*8(%rdi)
21847 movq %r11, -4*8(%rdi)
21848 leaq -4*8(%rdi), %rdi
21849 jae .Lcopy_backward_loop
21850@@ -130,12 +132,13 @@ ENTRY(memcpy)
21851 */
21852 movq 0*8(%rsi), %r8
21853 movq 1*8(%rsi), %r9
21854- movq -2*8(%rsi, %rdx), %r10
21855+ movq -2*8(%rsi, %rdx), %rcx
21856 movq -1*8(%rsi, %rdx), %r11
21857 movq %r8, 0*8(%rdi)
21858 movq %r9, 1*8(%rdi)
21859- movq %r10, -2*8(%rdi, %rdx)
21860+ movq %rcx, -2*8(%rdi, %rdx)
21861 movq %r11, -1*8(%rdi, %rdx)
21862+ pax_force_retaddr
21863 retq
21864 .p2align 4
21865 .Lless_16bytes:
21866@@ -148,6 +151,7 @@ ENTRY(memcpy)
21867 movq -1*8(%rsi, %rdx), %r9
21868 movq %r8, 0*8(%rdi)
21869 movq %r9, -1*8(%rdi, %rdx)
21870+ pax_force_retaddr
21871 retq
21872 .p2align 4
21873 .Lless_8bytes:
21874@@ -161,6 +165,7 @@ ENTRY(memcpy)
21875 movl -4(%rsi, %rdx), %r8d
21876 movl %ecx, (%rdi)
21877 movl %r8d, -4(%rdi, %rdx)
21878+ pax_force_retaddr
21879 retq
21880 .p2align 4
21881 .Lless_3bytes:
21882@@ -179,6 +184,7 @@ ENTRY(memcpy)
21883 movb %cl, (%rdi)
21884
21885 .Lend:
21886+ pax_force_retaddr
21887 retq
21888 CFI_ENDPROC
21889 ENDPROC(memcpy)
21890diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
21891index ee16461..c39c199 100644
21892--- a/arch/x86/lib/memmove_64.S
21893+++ b/arch/x86/lib/memmove_64.S
21894@@ -61,13 +61,13 @@ ENTRY(memmove)
21895 5:
21896 sub $0x20, %rdx
21897 movq 0*8(%rsi), %r11
21898- movq 1*8(%rsi), %r10
21899+ movq 1*8(%rsi), %rcx
21900 movq 2*8(%rsi), %r9
21901 movq 3*8(%rsi), %r8
21902 leaq 4*8(%rsi), %rsi
21903
21904 movq %r11, 0*8(%rdi)
21905- movq %r10, 1*8(%rdi)
21906+ movq %rcx, 1*8(%rdi)
21907 movq %r9, 2*8(%rdi)
21908 movq %r8, 3*8(%rdi)
21909 leaq 4*8(%rdi), %rdi
21910@@ -81,10 +81,10 @@ ENTRY(memmove)
21911 4:
21912 movq %rdx, %rcx
21913 movq -8(%rsi, %rdx), %r11
21914- lea -8(%rdi, %rdx), %r10
21915+ lea -8(%rdi, %rdx), %r9
21916 shrq $3, %rcx
21917 rep movsq
21918- movq %r11, (%r10)
21919+ movq %r11, (%r9)
21920 jmp 13f
21921 .Lmemmove_end_forward:
21922
21923@@ -95,14 +95,14 @@ ENTRY(memmove)
21924 7:
21925 movq %rdx, %rcx
21926 movq (%rsi), %r11
21927- movq %rdi, %r10
21928+ movq %rdi, %r9
21929 leaq -8(%rsi, %rdx), %rsi
21930 leaq -8(%rdi, %rdx), %rdi
21931 shrq $3, %rcx
21932 std
21933 rep movsq
21934 cld
21935- movq %r11, (%r10)
21936+ movq %r11, (%r9)
21937 jmp 13f
21938
21939 /*
21940@@ -127,13 +127,13 @@ ENTRY(memmove)
21941 8:
21942 subq $0x20, %rdx
21943 movq -1*8(%rsi), %r11
21944- movq -2*8(%rsi), %r10
21945+ movq -2*8(%rsi), %rcx
21946 movq -3*8(%rsi), %r9
21947 movq -4*8(%rsi), %r8
21948 leaq -4*8(%rsi), %rsi
21949
21950 movq %r11, -1*8(%rdi)
21951- movq %r10, -2*8(%rdi)
21952+ movq %rcx, -2*8(%rdi)
21953 movq %r9, -3*8(%rdi)
21954 movq %r8, -4*8(%rdi)
21955 leaq -4*8(%rdi), %rdi
21956@@ -151,11 +151,11 @@ ENTRY(memmove)
21957 * Move data from 16 bytes to 31 bytes.
21958 */
21959 movq 0*8(%rsi), %r11
21960- movq 1*8(%rsi), %r10
21961+ movq 1*8(%rsi), %rcx
21962 movq -2*8(%rsi, %rdx), %r9
21963 movq -1*8(%rsi, %rdx), %r8
21964 movq %r11, 0*8(%rdi)
21965- movq %r10, 1*8(%rdi)
21966+ movq %rcx, 1*8(%rdi)
21967 movq %r9, -2*8(%rdi, %rdx)
21968 movq %r8, -1*8(%rdi, %rdx)
21969 jmp 13f
21970@@ -167,9 +167,9 @@ ENTRY(memmove)
21971 * Move data from 8 bytes to 15 bytes.
21972 */
21973 movq 0*8(%rsi), %r11
21974- movq -1*8(%rsi, %rdx), %r10
21975+ movq -1*8(%rsi, %rdx), %r9
21976 movq %r11, 0*8(%rdi)
21977- movq %r10, -1*8(%rdi, %rdx)
21978+ movq %r9, -1*8(%rdi, %rdx)
21979 jmp 13f
21980 10:
21981 cmpq $4, %rdx
21982@@ -178,9 +178,9 @@ ENTRY(memmove)
21983 * Move data from 4 bytes to 7 bytes.
21984 */
21985 movl (%rsi), %r11d
21986- movl -4(%rsi, %rdx), %r10d
21987+ movl -4(%rsi, %rdx), %r9d
21988 movl %r11d, (%rdi)
21989- movl %r10d, -4(%rdi, %rdx)
21990+ movl %r9d, -4(%rdi, %rdx)
21991 jmp 13f
21992 11:
21993 cmp $2, %rdx
21994@@ -189,9 +189,9 @@ ENTRY(memmove)
21995 * Move data from 2 bytes to 3 bytes.
21996 */
21997 movw (%rsi), %r11w
21998- movw -2(%rsi, %rdx), %r10w
21999+ movw -2(%rsi, %rdx), %r9w
22000 movw %r11w, (%rdi)
22001- movw %r10w, -2(%rdi, %rdx)
22002+ movw %r9w, -2(%rdi, %rdx)
22003 jmp 13f
22004 12:
22005 cmp $1, %rdx
22006@@ -202,6 +202,7 @@ ENTRY(memmove)
22007 movb (%rsi), %r11b
22008 movb %r11b, (%rdi)
22009 13:
22010+ pax_force_retaddr
22011 retq
22012 CFI_ENDPROC
22013
22014@@ -210,6 +211,7 @@ ENTRY(memmove)
22015 /* Forward moving data. */
22016 movq %rdx, %rcx
22017 rep movsb
22018+ pax_force_retaddr
22019 retq
22020 .Lmemmove_end_forward_efs:
22021 .previous
22022diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22023index 2dcb380..963660a 100644
22024--- a/arch/x86/lib/memset_64.S
22025+++ b/arch/x86/lib/memset_64.S
22026@@ -30,6 +30,7 @@
22027 movl %edx,%ecx
22028 rep stosb
22029 movq %r9,%rax
22030+ pax_force_retaddr
22031 ret
22032 .Lmemset_e:
22033 .previous
22034@@ -52,6 +53,7 @@
22035 movq %rdx,%rcx
22036 rep stosb
22037 movq %r9,%rax
22038+ pax_force_retaddr
22039 ret
22040 .Lmemset_e_e:
22041 .previous
22042@@ -59,7 +61,7 @@
22043 ENTRY(memset)
22044 ENTRY(__memset)
22045 CFI_STARTPROC
22046- movq %rdi,%r10
22047+ movq %rdi,%r11
22048
22049 /* expand byte value */
22050 movzbl %sil,%ecx
22051@@ -117,7 +119,8 @@ ENTRY(__memset)
22052 jnz .Lloop_1
22053
22054 .Lende:
22055- movq %r10,%rax
22056+ movq %r11,%rax
22057+ pax_force_retaddr
22058 ret
22059
22060 CFI_RESTORE_STATE
22061diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22062index c9f2d9b..e7fd2c0 100644
22063--- a/arch/x86/lib/mmx_32.c
22064+++ b/arch/x86/lib/mmx_32.c
22065@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22066 {
22067 void *p;
22068 int i;
22069+ unsigned long cr0;
22070
22071 if (unlikely(in_interrupt()))
22072 return __memcpy(to, from, len);
22073@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22074 kernel_fpu_begin();
22075
22076 __asm__ __volatile__ (
22077- "1: prefetch (%0)\n" /* This set is 28 bytes */
22078- " prefetch 64(%0)\n"
22079- " prefetch 128(%0)\n"
22080- " prefetch 192(%0)\n"
22081- " prefetch 256(%0)\n"
22082+ "1: prefetch (%1)\n" /* This set is 28 bytes */
22083+ " prefetch 64(%1)\n"
22084+ " prefetch 128(%1)\n"
22085+ " prefetch 192(%1)\n"
22086+ " prefetch 256(%1)\n"
22087 "2: \n"
22088 ".section .fixup, \"ax\"\n"
22089- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22090+ "3: \n"
22091+
22092+#ifdef CONFIG_PAX_KERNEXEC
22093+ " movl %%cr0, %0\n"
22094+ " movl %0, %%eax\n"
22095+ " andl $0xFFFEFFFF, %%eax\n"
22096+ " movl %%eax, %%cr0\n"
22097+#endif
22098+
22099+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22100+
22101+#ifdef CONFIG_PAX_KERNEXEC
22102+ " movl %0, %%cr0\n"
22103+#endif
22104+
22105 " jmp 2b\n"
22106 ".previous\n"
22107 _ASM_EXTABLE(1b, 3b)
22108- : : "r" (from));
22109+ : "=&r" (cr0) : "r" (from) : "ax");
22110
22111 for ( ; i > 5; i--) {
22112 __asm__ __volatile__ (
22113- "1: prefetch 320(%0)\n"
22114- "2: movq (%0), %%mm0\n"
22115- " movq 8(%0), %%mm1\n"
22116- " movq 16(%0), %%mm2\n"
22117- " movq 24(%0), %%mm3\n"
22118- " movq %%mm0, (%1)\n"
22119- " movq %%mm1, 8(%1)\n"
22120- " movq %%mm2, 16(%1)\n"
22121- " movq %%mm3, 24(%1)\n"
22122- " movq 32(%0), %%mm0\n"
22123- " movq 40(%0), %%mm1\n"
22124- " movq 48(%0), %%mm2\n"
22125- " movq 56(%0), %%mm3\n"
22126- " movq %%mm0, 32(%1)\n"
22127- " movq %%mm1, 40(%1)\n"
22128- " movq %%mm2, 48(%1)\n"
22129- " movq %%mm3, 56(%1)\n"
22130+ "1: prefetch 320(%1)\n"
22131+ "2: movq (%1), %%mm0\n"
22132+ " movq 8(%1), %%mm1\n"
22133+ " movq 16(%1), %%mm2\n"
22134+ " movq 24(%1), %%mm3\n"
22135+ " movq %%mm0, (%2)\n"
22136+ " movq %%mm1, 8(%2)\n"
22137+ " movq %%mm2, 16(%2)\n"
22138+ " movq %%mm3, 24(%2)\n"
22139+ " movq 32(%1), %%mm0\n"
22140+ " movq 40(%1), %%mm1\n"
22141+ " movq 48(%1), %%mm2\n"
22142+ " movq 56(%1), %%mm3\n"
22143+ " movq %%mm0, 32(%2)\n"
22144+ " movq %%mm1, 40(%2)\n"
22145+ " movq %%mm2, 48(%2)\n"
22146+ " movq %%mm3, 56(%2)\n"
22147 ".section .fixup, \"ax\"\n"
22148- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22149+ "3:\n"
22150+
22151+#ifdef CONFIG_PAX_KERNEXEC
22152+ " movl %%cr0, %0\n"
22153+ " movl %0, %%eax\n"
22154+ " andl $0xFFFEFFFF, %%eax\n"
22155+ " movl %%eax, %%cr0\n"
22156+#endif
22157+
22158+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22159+
22160+#ifdef CONFIG_PAX_KERNEXEC
22161+ " movl %0, %%cr0\n"
22162+#endif
22163+
22164 " jmp 2b\n"
22165 ".previous\n"
22166 _ASM_EXTABLE(1b, 3b)
22167- : : "r" (from), "r" (to) : "memory");
22168+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22169
22170 from += 64;
22171 to += 64;
22172@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22173 static void fast_copy_page(void *to, void *from)
22174 {
22175 int i;
22176+ unsigned long cr0;
22177
22178 kernel_fpu_begin();
22179
22180@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22181 * but that is for later. -AV
22182 */
22183 __asm__ __volatile__(
22184- "1: prefetch (%0)\n"
22185- " prefetch 64(%0)\n"
22186- " prefetch 128(%0)\n"
22187- " prefetch 192(%0)\n"
22188- " prefetch 256(%0)\n"
22189+ "1: prefetch (%1)\n"
22190+ " prefetch 64(%1)\n"
22191+ " prefetch 128(%1)\n"
22192+ " prefetch 192(%1)\n"
22193+ " prefetch 256(%1)\n"
22194 "2: \n"
22195 ".section .fixup, \"ax\"\n"
22196- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22197+ "3: \n"
22198+
22199+#ifdef CONFIG_PAX_KERNEXEC
22200+ " movl %%cr0, %0\n"
22201+ " movl %0, %%eax\n"
22202+ " andl $0xFFFEFFFF, %%eax\n"
22203+ " movl %%eax, %%cr0\n"
22204+#endif
22205+
22206+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22207+
22208+#ifdef CONFIG_PAX_KERNEXEC
22209+ " movl %0, %%cr0\n"
22210+#endif
22211+
22212 " jmp 2b\n"
22213 ".previous\n"
22214- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22215+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22216
22217 for (i = 0; i < (4096-320)/64; i++) {
22218 __asm__ __volatile__ (
22219- "1: prefetch 320(%0)\n"
22220- "2: movq (%0), %%mm0\n"
22221- " movntq %%mm0, (%1)\n"
22222- " movq 8(%0), %%mm1\n"
22223- " movntq %%mm1, 8(%1)\n"
22224- " movq 16(%0), %%mm2\n"
22225- " movntq %%mm2, 16(%1)\n"
22226- " movq 24(%0), %%mm3\n"
22227- " movntq %%mm3, 24(%1)\n"
22228- " movq 32(%0), %%mm4\n"
22229- " movntq %%mm4, 32(%1)\n"
22230- " movq 40(%0), %%mm5\n"
22231- " movntq %%mm5, 40(%1)\n"
22232- " movq 48(%0), %%mm6\n"
22233- " movntq %%mm6, 48(%1)\n"
22234- " movq 56(%0), %%mm7\n"
22235- " movntq %%mm7, 56(%1)\n"
22236+ "1: prefetch 320(%1)\n"
22237+ "2: movq (%1), %%mm0\n"
22238+ " movntq %%mm0, (%2)\n"
22239+ " movq 8(%1), %%mm1\n"
22240+ " movntq %%mm1, 8(%2)\n"
22241+ " movq 16(%1), %%mm2\n"
22242+ " movntq %%mm2, 16(%2)\n"
22243+ " movq 24(%1), %%mm3\n"
22244+ " movntq %%mm3, 24(%2)\n"
22245+ " movq 32(%1), %%mm4\n"
22246+ " movntq %%mm4, 32(%2)\n"
22247+ " movq 40(%1), %%mm5\n"
22248+ " movntq %%mm5, 40(%2)\n"
22249+ " movq 48(%1), %%mm6\n"
22250+ " movntq %%mm6, 48(%2)\n"
22251+ " movq 56(%1), %%mm7\n"
22252+ " movntq %%mm7, 56(%2)\n"
22253 ".section .fixup, \"ax\"\n"
22254- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22255+ "3:\n"
22256+
22257+#ifdef CONFIG_PAX_KERNEXEC
22258+ " movl %%cr0, %0\n"
22259+ " movl %0, %%eax\n"
22260+ " andl $0xFFFEFFFF, %%eax\n"
22261+ " movl %%eax, %%cr0\n"
22262+#endif
22263+
22264+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22265+
22266+#ifdef CONFIG_PAX_KERNEXEC
22267+ " movl %0, %%cr0\n"
22268+#endif
22269+
22270 " jmp 2b\n"
22271 ".previous\n"
22272- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22273+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22274
22275 from += 64;
22276 to += 64;
22277@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22278 static void fast_copy_page(void *to, void *from)
22279 {
22280 int i;
22281+ unsigned long cr0;
22282
22283 kernel_fpu_begin();
22284
22285 __asm__ __volatile__ (
22286- "1: prefetch (%0)\n"
22287- " prefetch 64(%0)\n"
22288- " prefetch 128(%0)\n"
22289- " prefetch 192(%0)\n"
22290- " prefetch 256(%0)\n"
22291+ "1: prefetch (%1)\n"
22292+ " prefetch 64(%1)\n"
22293+ " prefetch 128(%1)\n"
22294+ " prefetch 192(%1)\n"
22295+ " prefetch 256(%1)\n"
22296 "2: \n"
22297 ".section .fixup, \"ax\"\n"
22298- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22299+ "3: \n"
22300+
22301+#ifdef CONFIG_PAX_KERNEXEC
22302+ " movl %%cr0, %0\n"
22303+ " movl %0, %%eax\n"
22304+ " andl $0xFFFEFFFF, %%eax\n"
22305+ " movl %%eax, %%cr0\n"
22306+#endif
22307+
22308+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22309+
22310+#ifdef CONFIG_PAX_KERNEXEC
22311+ " movl %0, %%cr0\n"
22312+#endif
22313+
22314 " jmp 2b\n"
22315 ".previous\n"
22316- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22317+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22318
22319 for (i = 0; i < 4096/64; i++) {
22320 __asm__ __volatile__ (
22321- "1: prefetch 320(%0)\n"
22322- "2: movq (%0), %%mm0\n"
22323- " movq 8(%0), %%mm1\n"
22324- " movq 16(%0), %%mm2\n"
22325- " movq 24(%0), %%mm3\n"
22326- " movq %%mm0, (%1)\n"
22327- " movq %%mm1, 8(%1)\n"
22328- " movq %%mm2, 16(%1)\n"
22329- " movq %%mm3, 24(%1)\n"
22330- " movq 32(%0), %%mm0\n"
22331- " movq 40(%0), %%mm1\n"
22332- " movq 48(%0), %%mm2\n"
22333- " movq 56(%0), %%mm3\n"
22334- " movq %%mm0, 32(%1)\n"
22335- " movq %%mm1, 40(%1)\n"
22336- " movq %%mm2, 48(%1)\n"
22337- " movq %%mm3, 56(%1)\n"
22338+ "1: prefetch 320(%1)\n"
22339+ "2: movq (%1), %%mm0\n"
22340+ " movq 8(%1), %%mm1\n"
22341+ " movq 16(%1), %%mm2\n"
22342+ " movq 24(%1), %%mm3\n"
22343+ " movq %%mm0, (%2)\n"
22344+ " movq %%mm1, 8(%2)\n"
22345+ " movq %%mm2, 16(%2)\n"
22346+ " movq %%mm3, 24(%2)\n"
22347+ " movq 32(%1), %%mm0\n"
22348+ " movq 40(%1), %%mm1\n"
22349+ " movq 48(%1), %%mm2\n"
22350+ " movq 56(%1), %%mm3\n"
22351+ " movq %%mm0, 32(%2)\n"
22352+ " movq %%mm1, 40(%2)\n"
22353+ " movq %%mm2, 48(%2)\n"
22354+ " movq %%mm3, 56(%2)\n"
22355 ".section .fixup, \"ax\"\n"
22356- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22357+ "3:\n"
22358+
22359+#ifdef CONFIG_PAX_KERNEXEC
22360+ " movl %%cr0, %0\n"
22361+ " movl %0, %%eax\n"
22362+ " andl $0xFFFEFFFF, %%eax\n"
22363+ " movl %%eax, %%cr0\n"
22364+#endif
22365+
22366+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22367+
22368+#ifdef CONFIG_PAX_KERNEXEC
22369+ " movl %0, %%cr0\n"
22370+#endif
22371+
22372 " jmp 2b\n"
22373 ".previous\n"
22374 _ASM_EXTABLE(1b, 3b)
22375- : : "r" (from), "r" (to) : "memory");
22376+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22377
22378 from += 64;
22379 to += 64;
22380diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22381index 69fa106..adda88b 100644
22382--- a/arch/x86/lib/msr-reg.S
22383+++ b/arch/x86/lib/msr-reg.S
22384@@ -3,6 +3,7 @@
22385 #include <asm/dwarf2.h>
22386 #include <asm/asm.h>
22387 #include <asm/msr.h>
22388+#include <asm/alternative-asm.h>
22389
22390 #ifdef CONFIG_X86_64
22391 /*
22392@@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
22393 CFI_STARTPROC
22394 pushq_cfi %rbx
22395 pushq_cfi %rbp
22396- movq %rdi, %r10 /* Save pointer */
22397+ movq %rdi, %r9 /* Save pointer */
22398 xorl %r11d, %r11d /* Return value */
22399 movl (%rdi), %eax
22400 movl 4(%rdi), %ecx
22401@@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
22402 movl 28(%rdi), %edi
22403 CFI_REMEMBER_STATE
22404 1: \op
22405-2: movl %eax, (%r10)
22406+2: movl %eax, (%r9)
22407 movl %r11d, %eax /* Return value */
22408- movl %ecx, 4(%r10)
22409- movl %edx, 8(%r10)
22410- movl %ebx, 12(%r10)
22411- movl %ebp, 20(%r10)
22412- movl %esi, 24(%r10)
22413- movl %edi, 28(%r10)
22414+ movl %ecx, 4(%r9)
22415+ movl %edx, 8(%r9)
22416+ movl %ebx, 12(%r9)
22417+ movl %ebp, 20(%r9)
22418+ movl %esi, 24(%r9)
22419+ movl %edi, 28(%r9)
22420 popq_cfi %rbp
22421 popq_cfi %rbx
22422+ pax_force_retaddr
22423 ret
22424 3:
22425 CFI_RESTORE_STATE
22426diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22427index 7f951c8..ebd573a 100644
22428--- a/arch/x86/lib/putuser.S
22429+++ b/arch/x86/lib/putuser.S
22430@@ -15,7 +15,9 @@
22431 #include <asm/thread_info.h>
22432 #include <asm/errno.h>
22433 #include <asm/asm.h>
22434-
22435+#include <asm/segment.h>
22436+#include <asm/pgtable.h>
22437+#include <asm/alternative-asm.h>
22438
22439 /*
22440 * __put_user_X
22441@@ -29,52 +31,119 @@
22442 * as they get called from within inline assembly.
22443 */
22444
22445-#define ENTER CFI_STARTPROC ; \
22446- GET_THREAD_INFO(%_ASM_BX)
22447-#define EXIT ret ; \
22448+#define ENTER CFI_STARTPROC
22449+#define EXIT pax_force_retaddr; ret ; \
22450 CFI_ENDPROC
22451
22452+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22453+#define _DEST %_ASM_CX,%_ASM_BX
22454+#else
22455+#define _DEST %_ASM_CX
22456+#endif
22457+
22458+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22459+#define __copyuser_seg gs;
22460+#else
22461+#define __copyuser_seg
22462+#endif
22463+
22464 .text
22465 ENTRY(__put_user_1)
22466 ENTER
22467+
22468+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22469+ GET_THREAD_INFO(%_ASM_BX)
22470 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22471 jae bad_put_user
22472-1: movb %al,(%_ASM_CX)
22473+
22474+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22475+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22476+ cmp %_ASM_BX,%_ASM_CX
22477+ jb 1234f
22478+ xor %ebx,%ebx
22479+1234:
22480+#endif
22481+
22482+#endif
22483+
22484+1: __copyuser_seg movb %al,(_DEST)
22485 xor %eax,%eax
22486 EXIT
22487 ENDPROC(__put_user_1)
22488
22489 ENTRY(__put_user_2)
22490 ENTER
22491+
22492+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22493+ GET_THREAD_INFO(%_ASM_BX)
22494 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22495 sub $1,%_ASM_BX
22496 cmp %_ASM_BX,%_ASM_CX
22497 jae bad_put_user
22498-2: movw %ax,(%_ASM_CX)
22499+
22500+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22501+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22502+ cmp %_ASM_BX,%_ASM_CX
22503+ jb 1234f
22504+ xor %ebx,%ebx
22505+1234:
22506+#endif
22507+
22508+#endif
22509+
22510+2: __copyuser_seg movw %ax,(_DEST)
22511 xor %eax,%eax
22512 EXIT
22513 ENDPROC(__put_user_2)
22514
22515 ENTRY(__put_user_4)
22516 ENTER
22517+
22518+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22519+ GET_THREAD_INFO(%_ASM_BX)
22520 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22521 sub $3,%_ASM_BX
22522 cmp %_ASM_BX,%_ASM_CX
22523 jae bad_put_user
22524-3: movl %eax,(%_ASM_CX)
22525+
22526+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22527+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22528+ cmp %_ASM_BX,%_ASM_CX
22529+ jb 1234f
22530+ xor %ebx,%ebx
22531+1234:
22532+#endif
22533+
22534+#endif
22535+
22536+3: __copyuser_seg movl %eax,(_DEST)
22537 xor %eax,%eax
22538 EXIT
22539 ENDPROC(__put_user_4)
22540
22541 ENTRY(__put_user_8)
22542 ENTER
22543+
22544+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22545+ GET_THREAD_INFO(%_ASM_BX)
22546 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22547 sub $7,%_ASM_BX
22548 cmp %_ASM_BX,%_ASM_CX
22549 jae bad_put_user
22550-4: mov %_ASM_AX,(%_ASM_CX)
22551+
22552+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22553+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22554+ cmp %_ASM_BX,%_ASM_CX
22555+ jb 1234f
22556+ xor %ebx,%ebx
22557+1234:
22558+#endif
22559+
22560+#endif
22561+
22562+4: __copyuser_seg mov %_ASM_AX,(_DEST)
22563 #ifdef CONFIG_X86_32
22564-5: movl %edx,4(%_ASM_CX)
22565+5: __copyuser_seg movl %edx,4(_DEST)
22566 #endif
22567 xor %eax,%eax
22568 EXIT
22569diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22570index 1cad221..de671ee 100644
22571--- a/arch/x86/lib/rwlock.S
22572+++ b/arch/x86/lib/rwlock.S
22573@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22574 FRAME
22575 0: LOCK_PREFIX
22576 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22577+
22578+#ifdef CONFIG_PAX_REFCOUNT
22579+ jno 1234f
22580+ LOCK_PREFIX
22581+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22582+ int $4
22583+1234:
22584+ _ASM_EXTABLE(1234b, 1234b)
22585+#endif
22586+
22587 1: rep; nop
22588 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22589 jne 1b
22590 LOCK_PREFIX
22591 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22592+
22593+#ifdef CONFIG_PAX_REFCOUNT
22594+ jno 1234f
22595+ LOCK_PREFIX
22596+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22597+ int $4
22598+1234:
22599+ _ASM_EXTABLE(1234b, 1234b)
22600+#endif
22601+
22602 jnz 0b
22603 ENDFRAME
22604+ pax_force_retaddr
22605 ret
22606 CFI_ENDPROC
22607 END(__write_lock_failed)
22608@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22609 FRAME
22610 0: LOCK_PREFIX
22611 READ_LOCK_SIZE(inc) (%__lock_ptr)
22612+
22613+#ifdef CONFIG_PAX_REFCOUNT
22614+ jno 1234f
22615+ LOCK_PREFIX
22616+ READ_LOCK_SIZE(dec) (%__lock_ptr)
22617+ int $4
22618+1234:
22619+ _ASM_EXTABLE(1234b, 1234b)
22620+#endif
22621+
22622 1: rep; nop
22623 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22624 js 1b
22625 LOCK_PREFIX
22626 READ_LOCK_SIZE(dec) (%__lock_ptr)
22627+
22628+#ifdef CONFIG_PAX_REFCOUNT
22629+ jno 1234f
22630+ LOCK_PREFIX
22631+ READ_LOCK_SIZE(inc) (%__lock_ptr)
22632+ int $4
22633+1234:
22634+ _ASM_EXTABLE(1234b, 1234b)
22635+#endif
22636+
22637 js 0b
22638 ENDFRAME
22639+ pax_force_retaddr
22640 ret
22641 CFI_ENDPROC
22642 END(__read_lock_failed)
22643diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22644index 5dff5f0..cadebf4 100644
22645--- a/arch/x86/lib/rwsem.S
22646+++ b/arch/x86/lib/rwsem.S
22647@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22648 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22649 CFI_RESTORE __ASM_REG(dx)
22650 restore_common_regs
22651+ pax_force_retaddr
22652 ret
22653 CFI_ENDPROC
22654 ENDPROC(call_rwsem_down_read_failed)
22655@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22656 movq %rax,%rdi
22657 call rwsem_down_write_failed
22658 restore_common_regs
22659+ pax_force_retaddr
22660 ret
22661 CFI_ENDPROC
22662 ENDPROC(call_rwsem_down_write_failed)
22663@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22664 movq %rax,%rdi
22665 call rwsem_wake
22666 restore_common_regs
22667-1: ret
22668+1: pax_force_retaddr
22669+ ret
22670 CFI_ENDPROC
22671 ENDPROC(call_rwsem_wake)
22672
22673@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22674 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22675 CFI_RESTORE __ASM_REG(dx)
22676 restore_common_regs
22677+ pax_force_retaddr
22678 ret
22679 CFI_ENDPROC
22680 ENDPROC(call_rwsem_downgrade_wake)
22681diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22682index a63efd6..ccecad8 100644
22683--- a/arch/x86/lib/thunk_64.S
22684+++ b/arch/x86/lib/thunk_64.S
22685@@ -8,6 +8,7 @@
22686 #include <linux/linkage.h>
22687 #include <asm/dwarf2.h>
22688 #include <asm/calling.h>
22689+#include <asm/alternative-asm.h>
22690
22691 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22692 .macro THUNK name, func, put_ret_addr_in_rdi=0
22693@@ -41,5 +42,6 @@
22694 SAVE_ARGS
22695 restore:
22696 RESTORE_ARGS
22697+ pax_force_retaddr
22698 ret
22699 CFI_ENDPROC
22700diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22701index 1781b2f..90368dd 100644
22702--- a/arch/x86/lib/usercopy_32.c
22703+++ b/arch/x86/lib/usercopy_32.c
22704@@ -42,10 +42,12 @@ do { \
22705 int __d0; \
22706 might_fault(); \
22707 __asm__ __volatile__( \
22708+ __COPYUSER_SET_ES \
22709 "0: rep; stosl\n" \
22710 " movl %2,%0\n" \
22711 "1: rep; stosb\n" \
22712 "2:\n" \
22713+ __COPYUSER_RESTORE_ES \
22714 ".section .fixup,\"ax\"\n" \
22715 "3: lea 0(%2,%0,4),%0\n" \
22716 " jmp 2b\n" \
22717@@ -97,7 +99,7 @@ EXPORT_SYMBOL(__clear_user);
22718
22719 #ifdef CONFIG_X86_INTEL_USERCOPY
22720 static unsigned long
22721-__copy_user_intel(void __user *to, const void *from, unsigned long size)
22722+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22723 {
22724 int d0, d1;
22725 __asm__ __volatile__(
22726@@ -109,36 +111,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22727 " .align 2,0x90\n"
22728 "3: movl 0(%4), %%eax\n"
22729 "4: movl 4(%4), %%edx\n"
22730- "5: movl %%eax, 0(%3)\n"
22731- "6: movl %%edx, 4(%3)\n"
22732+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22733+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22734 "7: movl 8(%4), %%eax\n"
22735 "8: movl 12(%4),%%edx\n"
22736- "9: movl %%eax, 8(%3)\n"
22737- "10: movl %%edx, 12(%3)\n"
22738+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22739+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22740 "11: movl 16(%4), %%eax\n"
22741 "12: movl 20(%4), %%edx\n"
22742- "13: movl %%eax, 16(%3)\n"
22743- "14: movl %%edx, 20(%3)\n"
22744+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22745+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22746 "15: movl 24(%4), %%eax\n"
22747 "16: movl 28(%4), %%edx\n"
22748- "17: movl %%eax, 24(%3)\n"
22749- "18: movl %%edx, 28(%3)\n"
22750+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22751+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22752 "19: movl 32(%4), %%eax\n"
22753 "20: movl 36(%4), %%edx\n"
22754- "21: movl %%eax, 32(%3)\n"
22755- "22: movl %%edx, 36(%3)\n"
22756+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22757+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22758 "23: movl 40(%4), %%eax\n"
22759 "24: movl 44(%4), %%edx\n"
22760- "25: movl %%eax, 40(%3)\n"
22761- "26: movl %%edx, 44(%3)\n"
22762+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22763+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22764 "27: movl 48(%4), %%eax\n"
22765 "28: movl 52(%4), %%edx\n"
22766- "29: movl %%eax, 48(%3)\n"
22767- "30: movl %%edx, 52(%3)\n"
22768+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22769+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22770 "31: movl 56(%4), %%eax\n"
22771 "32: movl 60(%4), %%edx\n"
22772- "33: movl %%eax, 56(%3)\n"
22773- "34: movl %%edx, 60(%3)\n"
22774+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22775+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22776 " addl $-64, %0\n"
22777 " addl $64, %4\n"
22778 " addl $64, %3\n"
22779@@ -148,10 +150,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22780 " shrl $2, %0\n"
22781 " andl $3, %%eax\n"
22782 " cld\n"
22783+ __COPYUSER_SET_ES
22784 "99: rep; movsl\n"
22785 "36: movl %%eax, %0\n"
22786 "37: rep; movsb\n"
22787 "100:\n"
22788+ __COPYUSER_RESTORE_ES
22789 ".section .fixup,\"ax\"\n"
22790 "101: lea 0(%%eax,%0,4),%0\n"
22791 " jmp 100b\n"
22792@@ -201,46 +205,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22793 }
22794
22795 static unsigned long
22796+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22797+{
22798+ int d0, d1;
22799+ __asm__ __volatile__(
22800+ " .align 2,0x90\n"
22801+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22802+ " cmpl $67, %0\n"
22803+ " jbe 3f\n"
22804+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
22805+ " .align 2,0x90\n"
22806+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
22807+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
22808+ "5: movl %%eax, 0(%3)\n"
22809+ "6: movl %%edx, 4(%3)\n"
22810+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
22811+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
22812+ "9: movl %%eax, 8(%3)\n"
22813+ "10: movl %%edx, 12(%3)\n"
22814+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
22815+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
22816+ "13: movl %%eax, 16(%3)\n"
22817+ "14: movl %%edx, 20(%3)\n"
22818+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
22819+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
22820+ "17: movl %%eax, 24(%3)\n"
22821+ "18: movl %%edx, 28(%3)\n"
22822+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
22823+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
22824+ "21: movl %%eax, 32(%3)\n"
22825+ "22: movl %%edx, 36(%3)\n"
22826+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
22827+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
22828+ "25: movl %%eax, 40(%3)\n"
22829+ "26: movl %%edx, 44(%3)\n"
22830+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
22831+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
22832+ "29: movl %%eax, 48(%3)\n"
22833+ "30: movl %%edx, 52(%3)\n"
22834+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
22835+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
22836+ "33: movl %%eax, 56(%3)\n"
22837+ "34: movl %%edx, 60(%3)\n"
22838+ " addl $-64, %0\n"
22839+ " addl $64, %4\n"
22840+ " addl $64, %3\n"
22841+ " cmpl $63, %0\n"
22842+ " ja 1b\n"
22843+ "35: movl %0, %%eax\n"
22844+ " shrl $2, %0\n"
22845+ " andl $3, %%eax\n"
22846+ " cld\n"
22847+ "99: rep; "__copyuser_seg" movsl\n"
22848+ "36: movl %%eax, %0\n"
22849+ "37: rep; "__copyuser_seg" movsb\n"
22850+ "100:\n"
22851+ ".section .fixup,\"ax\"\n"
22852+ "101: lea 0(%%eax,%0,4),%0\n"
22853+ " jmp 100b\n"
22854+ ".previous\n"
22855+ _ASM_EXTABLE(1b,100b)
22856+ _ASM_EXTABLE(2b,100b)
22857+ _ASM_EXTABLE(3b,100b)
22858+ _ASM_EXTABLE(4b,100b)
22859+ _ASM_EXTABLE(5b,100b)
22860+ _ASM_EXTABLE(6b,100b)
22861+ _ASM_EXTABLE(7b,100b)
22862+ _ASM_EXTABLE(8b,100b)
22863+ _ASM_EXTABLE(9b,100b)
22864+ _ASM_EXTABLE(10b,100b)
22865+ _ASM_EXTABLE(11b,100b)
22866+ _ASM_EXTABLE(12b,100b)
22867+ _ASM_EXTABLE(13b,100b)
22868+ _ASM_EXTABLE(14b,100b)
22869+ _ASM_EXTABLE(15b,100b)
22870+ _ASM_EXTABLE(16b,100b)
22871+ _ASM_EXTABLE(17b,100b)
22872+ _ASM_EXTABLE(18b,100b)
22873+ _ASM_EXTABLE(19b,100b)
22874+ _ASM_EXTABLE(20b,100b)
22875+ _ASM_EXTABLE(21b,100b)
22876+ _ASM_EXTABLE(22b,100b)
22877+ _ASM_EXTABLE(23b,100b)
22878+ _ASM_EXTABLE(24b,100b)
22879+ _ASM_EXTABLE(25b,100b)
22880+ _ASM_EXTABLE(26b,100b)
22881+ _ASM_EXTABLE(27b,100b)
22882+ _ASM_EXTABLE(28b,100b)
22883+ _ASM_EXTABLE(29b,100b)
22884+ _ASM_EXTABLE(30b,100b)
22885+ _ASM_EXTABLE(31b,100b)
22886+ _ASM_EXTABLE(32b,100b)
22887+ _ASM_EXTABLE(33b,100b)
22888+ _ASM_EXTABLE(34b,100b)
22889+ _ASM_EXTABLE(35b,100b)
22890+ _ASM_EXTABLE(36b,100b)
22891+ _ASM_EXTABLE(37b,100b)
22892+ _ASM_EXTABLE(99b,101b)
22893+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
22894+ : "1"(to), "2"(from), "0"(size)
22895+ : "eax", "edx", "memory");
22896+ return size;
22897+}
22898+
22899+static unsigned long __size_overflow(3)
22900 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22901 {
22902 int d0, d1;
22903 __asm__ __volatile__(
22904 " .align 2,0x90\n"
22905- "0: movl 32(%4), %%eax\n"
22906+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22907 " cmpl $67, %0\n"
22908 " jbe 2f\n"
22909- "1: movl 64(%4), %%eax\n"
22910+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22911 " .align 2,0x90\n"
22912- "2: movl 0(%4), %%eax\n"
22913- "21: movl 4(%4), %%edx\n"
22914+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22915+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22916 " movl %%eax, 0(%3)\n"
22917 " movl %%edx, 4(%3)\n"
22918- "3: movl 8(%4), %%eax\n"
22919- "31: movl 12(%4),%%edx\n"
22920+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22921+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22922 " movl %%eax, 8(%3)\n"
22923 " movl %%edx, 12(%3)\n"
22924- "4: movl 16(%4), %%eax\n"
22925- "41: movl 20(%4), %%edx\n"
22926+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22927+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22928 " movl %%eax, 16(%3)\n"
22929 " movl %%edx, 20(%3)\n"
22930- "10: movl 24(%4), %%eax\n"
22931- "51: movl 28(%4), %%edx\n"
22932+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22933+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22934 " movl %%eax, 24(%3)\n"
22935 " movl %%edx, 28(%3)\n"
22936- "11: movl 32(%4), %%eax\n"
22937- "61: movl 36(%4), %%edx\n"
22938+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22939+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22940 " movl %%eax, 32(%3)\n"
22941 " movl %%edx, 36(%3)\n"
22942- "12: movl 40(%4), %%eax\n"
22943- "71: movl 44(%4), %%edx\n"
22944+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22945+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22946 " movl %%eax, 40(%3)\n"
22947 " movl %%edx, 44(%3)\n"
22948- "13: movl 48(%4), %%eax\n"
22949- "81: movl 52(%4), %%edx\n"
22950+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22951+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22952 " movl %%eax, 48(%3)\n"
22953 " movl %%edx, 52(%3)\n"
22954- "14: movl 56(%4), %%eax\n"
22955- "91: movl 60(%4), %%edx\n"
22956+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22957+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22958 " movl %%eax, 56(%3)\n"
22959 " movl %%edx, 60(%3)\n"
22960 " addl $-64, %0\n"
22961@@ -252,9 +360,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22962 " shrl $2, %0\n"
22963 " andl $3, %%eax\n"
22964 " cld\n"
22965- "6: rep; movsl\n"
22966+ "6: rep; "__copyuser_seg" movsl\n"
22967 " movl %%eax,%0\n"
22968- "7: rep; movsb\n"
22969+ "7: rep; "__copyuser_seg" movsb\n"
22970 "8:\n"
22971 ".section .fixup,\"ax\"\n"
22972 "9: lea 0(%%eax,%0,4),%0\n"
22973@@ -297,48 +405,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22974 * hyoshiok@miraclelinux.com
22975 */
22976
22977-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
22978+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
22979 const void __user *from, unsigned long size)
22980 {
22981 int d0, d1;
22982
22983 __asm__ __volatile__(
22984 " .align 2,0x90\n"
22985- "0: movl 32(%4), %%eax\n"
22986+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22987 " cmpl $67, %0\n"
22988 " jbe 2f\n"
22989- "1: movl 64(%4), %%eax\n"
22990+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22991 " .align 2,0x90\n"
22992- "2: movl 0(%4), %%eax\n"
22993- "21: movl 4(%4), %%edx\n"
22994+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22995+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22996 " movnti %%eax, 0(%3)\n"
22997 " movnti %%edx, 4(%3)\n"
22998- "3: movl 8(%4), %%eax\n"
22999- "31: movl 12(%4),%%edx\n"
23000+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23001+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23002 " movnti %%eax, 8(%3)\n"
23003 " movnti %%edx, 12(%3)\n"
23004- "4: movl 16(%4), %%eax\n"
23005- "41: movl 20(%4), %%edx\n"
23006+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23007+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23008 " movnti %%eax, 16(%3)\n"
23009 " movnti %%edx, 20(%3)\n"
23010- "10: movl 24(%4), %%eax\n"
23011- "51: movl 28(%4), %%edx\n"
23012+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23013+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23014 " movnti %%eax, 24(%3)\n"
23015 " movnti %%edx, 28(%3)\n"
23016- "11: movl 32(%4), %%eax\n"
23017- "61: movl 36(%4), %%edx\n"
23018+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23019+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23020 " movnti %%eax, 32(%3)\n"
23021 " movnti %%edx, 36(%3)\n"
23022- "12: movl 40(%4), %%eax\n"
23023- "71: movl 44(%4), %%edx\n"
23024+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23025+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23026 " movnti %%eax, 40(%3)\n"
23027 " movnti %%edx, 44(%3)\n"
23028- "13: movl 48(%4), %%eax\n"
23029- "81: movl 52(%4), %%edx\n"
23030+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23031+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23032 " movnti %%eax, 48(%3)\n"
23033 " movnti %%edx, 52(%3)\n"
23034- "14: movl 56(%4), %%eax\n"
23035- "91: movl 60(%4), %%edx\n"
23036+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23037+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23038 " movnti %%eax, 56(%3)\n"
23039 " movnti %%edx, 60(%3)\n"
23040 " addl $-64, %0\n"
23041@@ -351,9 +459,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23042 " shrl $2, %0\n"
23043 " andl $3, %%eax\n"
23044 " cld\n"
23045- "6: rep; movsl\n"
23046+ "6: rep; "__copyuser_seg" movsl\n"
23047 " movl %%eax,%0\n"
23048- "7: rep; movsb\n"
23049+ "7: rep; "__copyuser_seg" movsb\n"
23050 "8:\n"
23051 ".section .fixup,\"ax\"\n"
23052 "9: lea 0(%%eax,%0,4),%0\n"
23053@@ -391,48 +499,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23054 return size;
23055 }
23056
23057-static unsigned long __copy_user_intel_nocache(void *to,
23058+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
23059 const void __user *from, unsigned long size)
23060 {
23061 int d0, d1;
23062
23063 __asm__ __volatile__(
23064 " .align 2,0x90\n"
23065- "0: movl 32(%4), %%eax\n"
23066+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23067 " cmpl $67, %0\n"
23068 " jbe 2f\n"
23069- "1: movl 64(%4), %%eax\n"
23070+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23071 " .align 2,0x90\n"
23072- "2: movl 0(%4), %%eax\n"
23073- "21: movl 4(%4), %%edx\n"
23074+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23075+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23076 " movnti %%eax, 0(%3)\n"
23077 " movnti %%edx, 4(%3)\n"
23078- "3: movl 8(%4), %%eax\n"
23079- "31: movl 12(%4),%%edx\n"
23080+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23081+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23082 " movnti %%eax, 8(%3)\n"
23083 " movnti %%edx, 12(%3)\n"
23084- "4: movl 16(%4), %%eax\n"
23085- "41: movl 20(%4), %%edx\n"
23086+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23087+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23088 " movnti %%eax, 16(%3)\n"
23089 " movnti %%edx, 20(%3)\n"
23090- "10: movl 24(%4), %%eax\n"
23091- "51: movl 28(%4), %%edx\n"
23092+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23093+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23094 " movnti %%eax, 24(%3)\n"
23095 " movnti %%edx, 28(%3)\n"
23096- "11: movl 32(%4), %%eax\n"
23097- "61: movl 36(%4), %%edx\n"
23098+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23099+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23100 " movnti %%eax, 32(%3)\n"
23101 " movnti %%edx, 36(%3)\n"
23102- "12: movl 40(%4), %%eax\n"
23103- "71: movl 44(%4), %%edx\n"
23104+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23105+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23106 " movnti %%eax, 40(%3)\n"
23107 " movnti %%edx, 44(%3)\n"
23108- "13: movl 48(%4), %%eax\n"
23109- "81: movl 52(%4), %%edx\n"
23110+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23111+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23112 " movnti %%eax, 48(%3)\n"
23113 " movnti %%edx, 52(%3)\n"
23114- "14: movl 56(%4), %%eax\n"
23115- "91: movl 60(%4), %%edx\n"
23116+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23117+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23118 " movnti %%eax, 56(%3)\n"
23119 " movnti %%edx, 60(%3)\n"
23120 " addl $-64, %0\n"
23121@@ -445,9 +553,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23122 " shrl $2, %0\n"
23123 " andl $3, %%eax\n"
23124 " cld\n"
23125- "6: rep; movsl\n"
23126+ "6: rep; "__copyuser_seg" movsl\n"
23127 " movl %%eax,%0\n"
23128- "7: rep; movsb\n"
23129+ "7: rep; "__copyuser_seg" movsb\n"
23130 "8:\n"
23131 ".section .fixup,\"ax\"\n"
23132 "9: lea 0(%%eax,%0,4),%0\n"
23133@@ -487,32 +595,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23134 */
23135 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23136 unsigned long size);
23137-unsigned long __copy_user_intel(void __user *to, const void *from,
23138+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23139+ unsigned long size);
23140+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23141 unsigned long size);
23142 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23143 const void __user *from, unsigned long size);
23144 #endif /* CONFIG_X86_INTEL_USERCOPY */
23145
23146 /* Generic arbitrary sized copy. */
23147-#define __copy_user(to, from, size) \
23148+#define __copy_user(to, from, size, prefix, set, restore) \
23149 do { \
23150 int __d0, __d1, __d2; \
23151 __asm__ __volatile__( \
23152+ set \
23153 " cmp $7,%0\n" \
23154 " jbe 1f\n" \
23155 " movl %1,%0\n" \
23156 " negl %0\n" \
23157 " andl $7,%0\n" \
23158 " subl %0,%3\n" \
23159- "4: rep; movsb\n" \
23160+ "4: rep; "prefix"movsb\n" \
23161 " movl %3,%0\n" \
23162 " shrl $2,%0\n" \
23163 " andl $3,%3\n" \
23164 " .align 2,0x90\n" \
23165- "0: rep; movsl\n" \
23166+ "0: rep; "prefix"movsl\n" \
23167 " movl %3,%0\n" \
23168- "1: rep; movsb\n" \
23169+ "1: rep; "prefix"movsb\n" \
23170 "2:\n" \
23171+ restore \
23172 ".section .fixup,\"ax\"\n" \
23173 "5: addl %3,%0\n" \
23174 " jmp 2b\n" \
23175@@ -537,14 +649,14 @@ do { \
23176 " negl %0\n" \
23177 " andl $7,%0\n" \
23178 " subl %0,%3\n" \
23179- "4: rep; movsb\n" \
23180+ "4: rep; "__copyuser_seg"movsb\n" \
23181 " movl %3,%0\n" \
23182 " shrl $2,%0\n" \
23183 " andl $3,%3\n" \
23184 " .align 2,0x90\n" \
23185- "0: rep; movsl\n" \
23186+ "0: rep; "__copyuser_seg"movsl\n" \
23187 " movl %3,%0\n" \
23188- "1: rep; movsb\n" \
23189+ "1: rep; "__copyuser_seg"movsb\n" \
23190 "2:\n" \
23191 ".section .fixup,\"ax\"\n" \
23192 "5: addl %3,%0\n" \
23193@@ -627,9 +739,9 @@ survive:
23194 }
23195 #endif
23196 if (movsl_is_ok(to, from, n))
23197- __copy_user(to, from, n);
23198+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23199 else
23200- n = __copy_user_intel(to, from, n);
23201+ n = __generic_copy_to_user_intel(to, from, n);
23202 return n;
23203 }
23204 EXPORT_SYMBOL(__copy_to_user_ll);
23205@@ -649,10 +761,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23206 unsigned long n)
23207 {
23208 if (movsl_is_ok(to, from, n))
23209- __copy_user(to, from, n);
23210+ __copy_user(to, from, n, __copyuser_seg, "", "");
23211 else
23212- n = __copy_user_intel((void __user *)to,
23213- (const void *)from, n);
23214+ n = __generic_copy_from_user_intel(to, from, n);
23215 return n;
23216 }
23217 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23218@@ -679,65 +790,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23219 if (n > 64 && cpu_has_xmm2)
23220 n = __copy_user_intel_nocache(to, from, n);
23221 else
23222- __copy_user(to, from, n);
23223+ __copy_user(to, from, n, __copyuser_seg, "", "");
23224 #else
23225- __copy_user(to, from, n);
23226+ __copy_user(to, from, n, __copyuser_seg, "", "");
23227 #endif
23228 return n;
23229 }
23230 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23231
23232-/**
23233- * copy_to_user: - Copy a block of data into user space.
23234- * @to: Destination address, in user space.
23235- * @from: Source address, in kernel space.
23236- * @n: Number of bytes to copy.
23237- *
23238- * Context: User context only. This function may sleep.
23239- *
23240- * Copy data from kernel space to user space.
23241- *
23242- * Returns number of bytes that could not be copied.
23243- * On success, this will be zero.
23244- */
23245-unsigned long
23246-copy_to_user(void __user *to, const void *from, unsigned long n)
23247-{
23248- if (access_ok(VERIFY_WRITE, to, n))
23249- n = __copy_to_user(to, from, n);
23250- return n;
23251-}
23252-EXPORT_SYMBOL(copy_to_user);
23253-
23254-/**
23255- * copy_from_user: - Copy a block of data from user space.
23256- * @to: Destination address, in kernel space.
23257- * @from: Source address, in user space.
23258- * @n: Number of bytes to copy.
23259- *
23260- * Context: User context only. This function may sleep.
23261- *
23262- * Copy data from user space to kernel space.
23263- *
23264- * Returns number of bytes that could not be copied.
23265- * On success, this will be zero.
23266- *
23267- * If some data could not be copied, this function will pad the copied
23268- * data to the requested size using zero bytes.
23269- */
23270-unsigned long
23271-_copy_from_user(void *to, const void __user *from, unsigned long n)
23272-{
23273- if (access_ok(VERIFY_READ, from, n))
23274- n = __copy_from_user(to, from, n);
23275- else
23276- memset(to, 0, n);
23277- return n;
23278-}
23279-EXPORT_SYMBOL(_copy_from_user);
23280-
23281 void copy_from_user_overflow(void)
23282 {
23283 WARN(1, "Buffer overflow detected!\n");
23284 }
23285 EXPORT_SYMBOL(copy_from_user_overflow);
23286+
23287+void copy_to_user_overflow(void)
23288+{
23289+ WARN(1, "Buffer overflow detected!\n");
23290+}
23291+EXPORT_SYMBOL(copy_to_user_overflow);
23292+
23293+#ifdef CONFIG_PAX_MEMORY_UDEREF
23294+void __set_fs(mm_segment_t x)
23295+{
23296+ switch (x.seg) {
23297+ case 0:
23298+ loadsegment(gs, 0);
23299+ break;
23300+ case TASK_SIZE_MAX:
23301+ loadsegment(gs, __USER_DS);
23302+ break;
23303+ case -1UL:
23304+ loadsegment(gs, __KERNEL_DS);
23305+ break;
23306+ default:
23307+ BUG();
23308+ }
23309+ return;
23310+}
23311+EXPORT_SYMBOL(__set_fs);
23312+
23313+void set_fs(mm_segment_t x)
23314+{
23315+ current_thread_info()->addr_limit = x;
23316+ __set_fs(x);
23317+}
23318+EXPORT_SYMBOL(set_fs);
23319+#endif
23320diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23321index e5b130b..6690d31 100644
23322--- a/arch/x86/lib/usercopy_64.c
23323+++ b/arch/x86/lib/usercopy_64.c
23324@@ -16,6 +16,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23325 {
23326 long __d0;
23327 might_fault();
23328+
23329+#ifdef CONFIG_PAX_MEMORY_UDEREF
23330+ if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23331+ addr += PAX_USER_SHADOW_BASE;
23332+#endif
23333+
23334 /* no memory constraint because it doesn't change any memory gcc knows
23335 about */
23336 asm volatile(
23337@@ -52,12 +58,20 @@ unsigned long clear_user(void __user *to, unsigned long n)
23338 }
23339 EXPORT_SYMBOL(clear_user);
23340
23341-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23342+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23343 {
23344- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23345- return copy_user_generic((__force void *)to, (__force void *)from, len);
23346- }
23347- return len;
23348+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23349+
23350+#ifdef CONFIG_PAX_MEMORY_UDEREF
23351+ if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23352+ to += PAX_USER_SHADOW_BASE;
23353+ if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23354+ from += PAX_USER_SHADOW_BASE;
23355+#endif
23356+
23357+ return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23358+ }
23359+ return len;
23360 }
23361 EXPORT_SYMBOL(copy_in_user);
23362
23363@@ -67,7 +81,7 @@ EXPORT_SYMBOL(copy_in_user);
23364 * it is not necessary to optimize tail handling.
23365 */
23366 unsigned long
23367-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23368+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23369 {
23370 char c;
23371 unsigned zero_len;
23372@@ -84,3 +98,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23373 break;
23374 return len;
23375 }
23376+
23377+void copy_from_user_overflow(void)
23378+{
23379+ WARN(1, "Buffer overflow detected!\n");
23380+}
23381+EXPORT_SYMBOL(copy_from_user_overflow);
23382+
23383+void copy_to_user_overflow(void)
23384+{
23385+ WARN(1, "Buffer overflow detected!\n");
23386+}
23387+EXPORT_SYMBOL(copy_to_user_overflow);
23388diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23389index 903ec1e..833f340 100644
23390--- a/arch/x86/mm/extable.c
23391+++ b/arch/x86/mm/extable.c
23392@@ -6,12 +6,25 @@
23393 static inline unsigned long
23394 ex_insn_addr(const struct exception_table_entry *x)
23395 {
23396- return (unsigned long)&x->insn + x->insn;
23397+//printk(KERN_ERR "fixup %p insn:%x fixup:%x\n", x, x->insn, x->fixup);
23398+ unsigned long reloc = 0;
23399+
23400+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
23401+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23402+#endif
23403+
23404+ return (unsigned long)&x->insn + x->insn + reloc;
23405 }
23406 static inline unsigned long
23407 ex_fixup_addr(const struct exception_table_entry *x)
23408 {
23409- return (unsigned long)&x->fixup + x->fixup;
23410+ unsigned long reloc = 0;
23411+
23412+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
23413+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23414+#endif
23415+
23416+ return (unsigned long)&x->fixup + x->fixup + reloc;
23417 }
23418
23419 int fixup_exception(struct pt_regs *regs)
23420@@ -20,7 +33,7 @@ int fixup_exception(struct pt_regs *regs)
23421 unsigned long new_ip;
23422
23423 #ifdef CONFIG_PNPBIOS
23424- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23425+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23426 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23427 extern u32 pnp_bios_is_utter_crap;
23428 pnp_bios_is_utter_crap = 1;
23429@@ -34,6 +47,7 @@ int fixup_exception(struct pt_regs *regs)
23430 #endif
23431
23432 fixup = search_exception_tables(regs->ip);
23433+//printk(KERN_ERR "fixup %p %lx\n", fixup, regs->ip);
23434 if (fixup) {
23435 new_ip = ex_fixup_addr(fixup);
23436
23437diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23438index 76dcd9d..e9dffde 100644
23439--- a/arch/x86/mm/fault.c
23440+++ b/arch/x86/mm/fault.c
23441@@ -13,11 +13,18 @@
23442 #include <linux/perf_event.h> /* perf_sw_event */
23443 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23444 #include <linux/prefetch.h> /* prefetchw */
23445+#include <linux/unistd.h>
23446+#include <linux/compiler.h>
23447
23448 #include <asm/traps.h> /* dotraplinkage, ... */
23449 #include <asm/pgalloc.h> /* pgd_*(), ... */
23450 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23451 #include <asm/fixmap.h> /* VSYSCALL_START */
23452+#include <asm/tlbflush.h>
23453+
23454+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23455+#include <asm/stacktrace.h>
23456+#endif
23457
23458 /*
23459 * Page fault error code bits:
23460@@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23461 int ret = 0;
23462
23463 /* kprobe_running() needs smp_processor_id() */
23464- if (kprobes_built_in() && !user_mode_vm(regs)) {
23465+ if (kprobes_built_in() && !user_mode(regs)) {
23466 preempt_disable();
23467 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23468 ret = 1;
23469@@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23470 return !instr_lo || (instr_lo>>1) == 1;
23471 case 0x00:
23472 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23473- if (probe_kernel_address(instr, opcode))
23474+ if (user_mode(regs)) {
23475+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23476+ return 0;
23477+ } else if (probe_kernel_address(instr, opcode))
23478 return 0;
23479
23480 *prefetch = (instr_lo == 0xF) &&
23481@@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23482 while (instr < max_instr) {
23483 unsigned char opcode;
23484
23485- if (probe_kernel_address(instr, opcode))
23486+ if (user_mode(regs)) {
23487+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23488+ break;
23489+ } else if (probe_kernel_address(instr, opcode))
23490 break;
23491
23492 instr++;
23493@@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23494 force_sig_info(si_signo, &info, tsk);
23495 }
23496
23497+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23498+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23499+#endif
23500+
23501+#ifdef CONFIG_PAX_EMUTRAMP
23502+static int pax_handle_fetch_fault(struct pt_regs *regs);
23503+#endif
23504+
23505+#ifdef CONFIG_PAX_PAGEEXEC
23506+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23507+{
23508+ pgd_t *pgd;
23509+ pud_t *pud;
23510+ pmd_t *pmd;
23511+
23512+ pgd = pgd_offset(mm, address);
23513+ if (!pgd_present(*pgd))
23514+ return NULL;
23515+ pud = pud_offset(pgd, address);
23516+ if (!pud_present(*pud))
23517+ return NULL;
23518+ pmd = pmd_offset(pud, address);
23519+ if (!pmd_present(*pmd))
23520+ return NULL;
23521+ return pmd;
23522+}
23523+#endif
23524+
23525 DEFINE_SPINLOCK(pgd_lock);
23526 LIST_HEAD(pgd_list);
23527
23528@@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23529 for (address = VMALLOC_START & PMD_MASK;
23530 address >= TASK_SIZE && address < FIXADDR_TOP;
23531 address += PMD_SIZE) {
23532+
23533+#ifdef CONFIG_PAX_PER_CPU_PGD
23534+ unsigned long cpu;
23535+#else
23536 struct page *page;
23537+#endif
23538
23539 spin_lock(&pgd_lock);
23540+
23541+#ifdef CONFIG_PAX_PER_CPU_PGD
23542+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23543+ pgd_t *pgd = get_cpu_pgd(cpu);
23544+ pmd_t *ret;
23545+#else
23546 list_for_each_entry(page, &pgd_list, lru) {
23547+ pgd_t *pgd = page_address(page);
23548 spinlock_t *pgt_lock;
23549 pmd_t *ret;
23550
23551@@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23552 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23553
23554 spin_lock(pgt_lock);
23555- ret = vmalloc_sync_one(page_address(page), address);
23556+#endif
23557+
23558+ ret = vmalloc_sync_one(pgd, address);
23559+
23560+#ifndef CONFIG_PAX_PER_CPU_PGD
23561 spin_unlock(pgt_lock);
23562+#endif
23563
23564 if (!ret)
23565 break;
23566@@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23567 * an interrupt in the middle of a task switch..
23568 */
23569 pgd_paddr = read_cr3();
23570+
23571+#ifdef CONFIG_PAX_PER_CPU_PGD
23572+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23573+#endif
23574+
23575 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23576 if (!pmd_k)
23577 return -1;
23578@@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23579 * happen within a race in page table update. In the later
23580 * case just flush:
23581 */
23582+
23583+#ifdef CONFIG_PAX_PER_CPU_PGD
23584+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23585+ pgd = pgd_offset_cpu(smp_processor_id(), address);
23586+#else
23587 pgd = pgd_offset(current->active_mm, address);
23588+#endif
23589+
23590 pgd_ref = pgd_offset_k(address);
23591 if (pgd_none(*pgd_ref))
23592 return -1;
23593@@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23594 static int is_errata100(struct pt_regs *regs, unsigned long address)
23595 {
23596 #ifdef CONFIG_X86_64
23597- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23598+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23599 return 1;
23600 #endif
23601 return 0;
23602@@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23603 }
23604
23605 static const char nx_warning[] = KERN_CRIT
23606-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23607+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23608
23609 static void
23610 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23611@@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23612 if (!oops_may_print())
23613 return;
23614
23615- if (error_code & PF_INSTR) {
23616+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23617 unsigned int level;
23618
23619 pte_t *pte = lookup_address(address, &level);
23620
23621 if (pte && pte_present(*pte) && !pte_exec(*pte))
23622- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
23623+ printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
23624 }
23625
23626+#ifdef CONFIG_PAX_KERNEXEC
23627+ if (init_mm.start_code <= address && address < init_mm.end_code) {
23628+ if (current->signal->curr_ip)
23629+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23630+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23631+ else
23632+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23633+ current->comm, task_pid_nr(current), current_uid(), current_euid());
23634+ }
23635+#endif
23636+
23637 printk(KERN_ALERT "BUG: unable to handle kernel ");
23638 if (address < PAGE_SIZE)
23639 printk(KERN_CONT "NULL pointer dereference");
23640@@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23641 }
23642 #endif
23643
23644+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23645+ if (pax_is_fetch_fault(regs, error_code, address)) {
23646+
23647+#ifdef CONFIG_PAX_EMUTRAMP
23648+ switch (pax_handle_fetch_fault(regs)) {
23649+ case 2:
23650+ return;
23651+ }
23652+#endif
23653+
23654+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23655+ do_group_exit(SIGKILL);
23656+ }
23657+#endif
23658+
23659 if (unlikely(show_unhandled_signals))
23660 show_signal_msg(regs, error_code, address, tsk);
23661
23662@@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23663 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23664 printk(KERN_ERR
23665 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23666- tsk->comm, tsk->pid, address);
23667+ tsk->comm, task_pid_nr(tsk), address);
23668 code = BUS_MCEERR_AR;
23669 }
23670 #endif
23671@@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23672 return 1;
23673 }
23674
23675+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23676+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23677+{
23678+ pte_t *pte;
23679+ pmd_t *pmd;
23680+ spinlock_t *ptl;
23681+ unsigned char pte_mask;
23682+
23683+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23684+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
23685+ return 0;
23686+
23687+ /* PaX: it's our fault, let's handle it if we can */
23688+
23689+ /* PaX: take a look at read faults before acquiring any locks */
23690+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23691+ /* instruction fetch attempt from a protected page in user mode */
23692+ up_read(&mm->mmap_sem);
23693+
23694+#ifdef CONFIG_PAX_EMUTRAMP
23695+ switch (pax_handle_fetch_fault(regs)) {
23696+ case 2:
23697+ return 1;
23698+ }
23699+#endif
23700+
23701+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23702+ do_group_exit(SIGKILL);
23703+ }
23704+
23705+ pmd = pax_get_pmd(mm, address);
23706+ if (unlikely(!pmd))
23707+ return 0;
23708+
23709+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23710+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23711+ pte_unmap_unlock(pte, ptl);
23712+ return 0;
23713+ }
23714+
23715+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23716+ /* write attempt to a protected page in user mode */
23717+ pte_unmap_unlock(pte, ptl);
23718+ return 0;
23719+ }
23720+
23721+#ifdef CONFIG_SMP
23722+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23723+#else
23724+ if (likely(address > get_limit(regs->cs)))
23725+#endif
23726+ {
23727+ set_pte(pte, pte_mkread(*pte));
23728+ __flush_tlb_one(address);
23729+ pte_unmap_unlock(pte, ptl);
23730+ up_read(&mm->mmap_sem);
23731+ return 1;
23732+ }
23733+
23734+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23735+
23736+ /*
23737+ * PaX: fill DTLB with user rights and retry
23738+ */
23739+ __asm__ __volatile__ (
23740+ "orb %2,(%1)\n"
23741+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23742+/*
23743+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23744+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23745+ * page fault when examined during a TLB load attempt. this is true not only
23746+ * for PTEs holding a non-present entry but also present entries that will
23747+ * raise a page fault (such as those set up by PaX, or the copy-on-write
23748+ * mechanism). in effect it means that we do *not* need to flush the TLBs
23749+ * for our target pages since their PTEs are simply not in the TLBs at all.
23750+
23751+ * the best thing in omitting it is that we gain around 15-20% speed in the
23752+ * fast path of the page fault handler and can get rid of tracing since we
23753+ * can no longer flush unintended entries.
23754+ */
23755+ "invlpg (%0)\n"
23756+#endif
23757+ __copyuser_seg"testb $0,(%0)\n"
23758+ "xorb %3,(%1)\n"
23759+ :
23760+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23761+ : "memory", "cc");
23762+ pte_unmap_unlock(pte, ptl);
23763+ up_read(&mm->mmap_sem);
23764+ return 1;
23765+}
23766+#endif
23767+
23768 /*
23769 * Handle a spurious fault caused by a stale TLB entry.
23770 *
23771@@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23772 static inline int
23773 access_error(unsigned long error_code, struct vm_area_struct *vma)
23774 {
23775+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23776+ return 1;
23777+
23778 if (error_code & PF_WRITE) {
23779 /* write, present and write, not present: */
23780 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23781@@ -1005,18 +1197,33 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23782 {
23783 struct vm_area_struct *vma;
23784 struct task_struct *tsk;
23785- unsigned long address;
23786 struct mm_struct *mm;
23787 int fault;
23788 int write = error_code & PF_WRITE;
23789 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23790 (write ? FAULT_FLAG_WRITE : 0);
23791
23792- tsk = current;
23793- mm = tsk->mm;
23794-
23795 /* Get the faulting address: */
23796- address = read_cr2();
23797+ unsigned long address = read_cr2();
23798+
23799+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23800+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23801+ if (!search_exception_tables(regs->ip)) {
23802+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23803+ bad_area_nosemaphore(regs, error_code, address);
23804+ return;
23805+ }
23806+ if (address < PAX_USER_SHADOW_BASE) {
23807+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23808+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
23809+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
23810+ } else
23811+ address -= PAX_USER_SHADOW_BASE;
23812+ }
23813+#endif
23814+
23815+ tsk = current;
23816+ mm = tsk->mm;
23817
23818 /*
23819 * Detect and handle instructions that would cause a page fault for
23820@@ -1077,7 +1284,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23821 * User-mode registers count as a user access even for any
23822 * potential system fault or CPU buglet:
23823 */
23824- if (user_mode_vm(regs)) {
23825+ if (user_mode(regs)) {
23826 local_irq_enable();
23827 error_code |= PF_USER;
23828 } else {
23829@@ -1132,6 +1339,11 @@ retry:
23830 might_sleep();
23831 }
23832
23833+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23834+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
23835+ return;
23836+#endif
23837+
23838 vma = find_vma(mm, address);
23839 if (unlikely(!vma)) {
23840 bad_area(regs, error_code, address);
23841@@ -1143,18 +1355,24 @@ retry:
23842 bad_area(regs, error_code, address);
23843 return;
23844 }
23845- if (error_code & PF_USER) {
23846- /*
23847- * Accessing the stack below %sp is always a bug.
23848- * The large cushion allows instructions like enter
23849- * and pusha to work. ("enter $65535, $31" pushes
23850- * 32 pointers and then decrements %sp by 65535.)
23851- */
23852- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
23853- bad_area(regs, error_code, address);
23854- return;
23855- }
23856+ /*
23857+ * Accessing the stack below %sp is always a bug.
23858+ * The large cushion allows instructions like enter
23859+ * and pusha to work. ("enter $65535, $31" pushes
23860+ * 32 pointers and then decrements %sp by 65535.)
23861+ */
23862+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
23863+ bad_area(regs, error_code, address);
23864+ return;
23865 }
23866+
23867+#ifdef CONFIG_PAX_SEGMEXEC
23868+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
23869+ bad_area(regs, error_code, address);
23870+ return;
23871+ }
23872+#endif
23873+
23874 if (unlikely(expand_stack(vma, address))) {
23875 bad_area(regs, error_code, address);
23876 return;
23877@@ -1209,3 +1427,292 @@ good_area:
23878
23879 up_read(&mm->mmap_sem);
23880 }
23881+
23882+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23883+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
23884+{
23885+ struct mm_struct *mm = current->mm;
23886+ unsigned long ip = regs->ip;
23887+
23888+ if (v8086_mode(regs))
23889+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
23890+
23891+#ifdef CONFIG_PAX_PAGEEXEC
23892+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
23893+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
23894+ return true;
23895+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
23896+ return true;
23897+ return false;
23898+ }
23899+#endif
23900+
23901+#ifdef CONFIG_PAX_SEGMEXEC
23902+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
23903+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
23904+ return true;
23905+ return false;
23906+ }
23907+#endif
23908+
23909+ return false;
23910+}
23911+#endif
23912+
23913+#ifdef CONFIG_PAX_EMUTRAMP
23914+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
23915+{
23916+ int err;
23917+
23918+ do { /* PaX: libffi trampoline emulation */
23919+ unsigned char mov, jmp;
23920+ unsigned int addr1, addr2;
23921+
23922+#ifdef CONFIG_X86_64
23923+ if ((regs->ip + 9) >> 32)
23924+ break;
23925+#endif
23926+
23927+ err = get_user(mov, (unsigned char __user *)regs->ip);
23928+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23929+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23930+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23931+
23932+ if (err)
23933+ break;
23934+
23935+ if (mov == 0xB8 && jmp == 0xE9) {
23936+ regs->ax = addr1;
23937+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
23938+ return 2;
23939+ }
23940+ } while (0);
23941+
23942+ do { /* PaX: gcc trampoline emulation #1 */
23943+ unsigned char mov1, mov2;
23944+ unsigned short jmp;
23945+ unsigned int addr1, addr2;
23946+
23947+#ifdef CONFIG_X86_64
23948+ if ((regs->ip + 11) >> 32)
23949+ break;
23950+#endif
23951+
23952+ err = get_user(mov1, (unsigned char __user *)regs->ip);
23953+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23954+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
23955+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23956+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
23957+
23958+ if (err)
23959+ break;
23960+
23961+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
23962+ regs->cx = addr1;
23963+ regs->ax = addr2;
23964+ regs->ip = addr2;
23965+ return 2;
23966+ }
23967+ } while (0);
23968+
23969+ do { /* PaX: gcc trampoline emulation #2 */
23970+ unsigned char mov, jmp;
23971+ unsigned int addr1, addr2;
23972+
23973+#ifdef CONFIG_X86_64
23974+ if ((regs->ip + 9) >> 32)
23975+ break;
23976+#endif
23977+
23978+ err = get_user(mov, (unsigned char __user *)regs->ip);
23979+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23980+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23981+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23982+
23983+ if (err)
23984+ break;
23985+
23986+ if (mov == 0xB9 && jmp == 0xE9) {
23987+ regs->cx = addr1;
23988+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
23989+ return 2;
23990+ }
23991+ } while (0);
23992+
23993+ return 1; /* PaX in action */
23994+}
23995+
23996+#ifdef CONFIG_X86_64
23997+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
23998+{
23999+ int err;
24000+
24001+ do { /* PaX: libffi trampoline emulation */
24002+ unsigned short mov1, mov2, jmp1;
24003+ unsigned char stcclc, jmp2;
24004+ unsigned long addr1, addr2;
24005+
24006+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24007+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24008+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24009+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24010+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24011+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24012+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24013+
24014+ if (err)
24015+ break;
24016+
24017+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24018+ regs->r11 = addr1;
24019+ regs->r10 = addr2;
24020+ if (stcclc == 0xF8)
24021+ regs->flags &= ~X86_EFLAGS_CF;
24022+ else
24023+ regs->flags |= X86_EFLAGS_CF;
24024+ regs->ip = addr1;
24025+ return 2;
24026+ }
24027+ } while (0);
24028+
24029+ do { /* PaX: gcc trampoline emulation #1 */
24030+ unsigned short mov1, mov2, jmp1;
24031+ unsigned char jmp2;
24032+ unsigned int addr1;
24033+ unsigned long addr2;
24034+
24035+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24036+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24037+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24038+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24039+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24040+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24041+
24042+ if (err)
24043+ break;
24044+
24045+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24046+ regs->r11 = addr1;
24047+ regs->r10 = addr2;
24048+ regs->ip = addr1;
24049+ return 2;
24050+ }
24051+ } while (0);
24052+
24053+ do { /* PaX: gcc trampoline emulation #2 */
24054+ unsigned short mov1, mov2, jmp1;
24055+ unsigned char jmp2;
24056+ unsigned long addr1, addr2;
24057+
24058+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24059+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24060+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24061+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24062+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24063+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24064+
24065+ if (err)
24066+ break;
24067+
24068+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24069+ regs->r11 = addr1;
24070+ regs->r10 = addr2;
24071+ regs->ip = addr1;
24072+ return 2;
24073+ }
24074+ } while (0);
24075+
24076+ return 1; /* PaX in action */
24077+}
24078+#endif
24079+
24080+/*
24081+ * PaX: decide what to do with offenders (regs->ip = fault address)
24082+ *
24083+ * returns 1 when task should be killed
24084+ * 2 when gcc trampoline was detected
24085+ */
24086+static int pax_handle_fetch_fault(struct pt_regs *regs)
24087+{
24088+ if (v8086_mode(regs))
24089+ return 1;
24090+
24091+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24092+ return 1;
24093+
24094+#ifdef CONFIG_X86_32
24095+ return pax_handle_fetch_fault_32(regs);
24096+#else
24097+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24098+ return pax_handle_fetch_fault_32(regs);
24099+ else
24100+ return pax_handle_fetch_fault_64(regs);
24101+#endif
24102+}
24103+#endif
24104+
24105+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24106+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24107+{
24108+ long i;
24109+
24110+ printk(KERN_ERR "PAX: bytes at PC: ");
24111+ for (i = 0; i < 20; i++) {
24112+ unsigned char c;
24113+ if (get_user(c, (unsigned char __force_user *)pc+i))
24114+ printk(KERN_CONT "?? ");
24115+ else
24116+ printk(KERN_CONT "%02x ", c);
24117+ }
24118+ printk("\n");
24119+
24120+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24121+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
24122+ unsigned long c;
24123+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
24124+#ifdef CONFIG_X86_32
24125+ printk(KERN_CONT "???????? ");
24126+#else
24127+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24128+ printk(KERN_CONT "???????? ???????? ");
24129+ else
24130+ printk(KERN_CONT "???????????????? ");
24131+#endif
24132+ } else {
24133+#ifdef CONFIG_X86_64
24134+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24135+ printk(KERN_CONT "%08x ", (unsigned int)c);
24136+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24137+ } else
24138+#endif
24139+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24140+ }
24141+ }
24142+ printk("\n");
24143+}
24144+#endif
24145+
24146+/**
24147+ * probe_kernel_write(): safely attempt to write to a location
24148+ * @dst: address to write to
24149+ * @src: pointer to the data that shall be written
24150+ * @size: size of the data chunk
24151+ *
24152+ * Safely write to address @dst from the buffer at @src. If a kernel fault
24153+ * happens, handle that and return -EFAULT.
24154+ */
24155+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24156+{
24157+ long ret;
24158+ mm_segment_t old_fs = get_fs();
24159+
24160+ set_fs(KERNEL_DS);
24161+ pagefault_disable();
24162+ pax_open_kernel();
24163+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24164+ pax_close_kernel();
24165+ pagefault_enable();
24166+ set_fs(old_fs);
24167+
24168+ return ret ? -EFAULT : 0;
24169+}
24170diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24171index dd74e46..7d26398 100644
24172--- a/arch/x86/mm/gup.c
24173+++ b/arch/x86/mm/gup.c
24174@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24175 addr = start;
24176 len = (unsigned long) nr_pages << PAGE_SHIFT;
24177 end = start + len;
24178- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24179+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24180 (void __user *)start, len)))
24181 return 0;
24182
24183diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24184index 6f31ee5..8ee4164 100644
24185--- a/arch/x86/mm/highmem_32.c
24186+++ b/arch/x86/mm/highmem_32.c
24187@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24188 idx = type + KM_TYPE_NR*smp_processor_id();
24189 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24190 BUG_ON(!pte_none(*(kmap_pte-idx)));
24191+
24192+ pax_open_kernel();
24193 set_pte(kmap_pte-idx, mk_pte(page, prot));
24194+ pax_close_kernel();
24195+
24196 arch_flush_lazy_mmu_mode();
24197
24198 return (void *)vaddr;
24199diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24200index f6679a7..8f795a3 100644
24201--- a/arch/x86/mm/hugetlbpage.c
24202+++ b/arch/x86/mm/hugetlbpage.c
24203@@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24204 struct hstate *h = hstate_file(file);
24205 struct mm_struct *mm = current->mm;
24206 struct vm_area_struct *vma;
24207- unsigned long start_addr;
24208+ unsigned long start_addr, pax_task_size = TASK_SIZE;
24209+
24210+#ifdef CONFIG_PAX_SEGMEXEC
24211+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24212+ pax_task_size = SEGMEXEC_TASK_SIZE;
24213+#endif
24214+
24215+ pax_task_size -= PAGE_SIZE;
24216
24217 if (len > mm->cached_hole_size) {
24218- start_addr = mm->free_area_cache;
24219+ start_addr = mm->free_area_cache;
24220 } else {
24221- start_addr = TASK_UNMAPPED_BASE;
24222- mm->cached_hole_size = 0;
24223+ start_addr = mm->mmap_base;
24224+ mm->cached_hole_size = 0;
24225 }
24226
24227 full_search:
24228@@ -280,26 +287,27 @@ full_search:
24229
24230 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24231 /* At this point: (!vma || addr < vma->vm_end). */
24232- if (TASK_SIZE - len < addr) {
24233+ if (pax_task_size - len < addr) {
24234 /*
24235 * Start a new search - just in case we missed
24236 * some holes.
24237 */
24238- if (start_addr != TASK_UNMAPPED_BASE) {
24239- start_addr = TASK_UNMAPPED_BASE;
24240+ if (start_addr != mm->mmap_base) {
24241+ start_addr = mm->mmap_base;
24242 mm->cached_hole_size = 0;
24243 goto full_search;
24244 }
24245 return -ENOMEM;
24246 }
24247- if (!vma || addr + len <= vma->vm_start) {
24248- mm->free_area_cache = addr + len;
24249- return addr;
24250- }
24251+ if (check_heap_stack_gap(vma, addr, len))
24252+ break;
24253 if (addr + mm->cached_hole_size < vma->vm_start)
24254 mm->cached_hole_size = vma->vm_start - addr;
24255 addr = ALIGN(vma->vm_end, huge_page_size(h));
24256 }
24257+
24258+ mm->free_area_cache = addr + len;
24259+ return addr;
24260 }
24261
24262 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24263@@ -310,9 +318,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24264 struct mm_struct *mm = current->mm;
24265 struct vm_area_struct *vma;
24266 unsigned long base = mm->mmap_base;
24267- unsigned long addr = addr0;
24268+ unsigned long addr;
24269 unsigned long largest_hole = mm->cached_hole_size;
24270- unsigned long start_addr;
24271
24272 /* don't allow allocations above current base */
24273 if (mm->free_area_cache > base)
24274@@ -322,16 +329,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24275 largest_hole = 0;
24276 mm->free_area_cache = base;
24277 }
24278-try_again:
24279- start_addr = mm->free_area_cache;
24280
24281 /* make sure it can fit in the remaining address space */
24282 if (mm->free_area_cache < len)
24283 goto fail;
24284
24285 /* either no address requested or can't fit in requested address hole */
24286- addr = (mm->free_area_cache - len) & huge_page_mask(h);
24287+ addr = mm->free_area_cache - len;
24288 do {
24289+ addr &= huge_page_mask(h);
24290 /*
24291 * Lookup failure means no vma is above this address,
24292 * i.e. return with success:
24293@@ -340,10 +346,10 @@ try_again:
24294 if (!vma)
24295 return addr;
24296
24297- if (addr + len <= vma->vm_start) {
24298+ if (check_heap_stack_gap(vma, addr, len)) {
24299 /* remember the address as a hint for next time */
24300- mm->cached_hole_size = largest_hole;
24301- return (mm->free_area_cache = addr);
24302+ mm->cached_hole_size = largest_hole;
24303+ return (mm->free_area_cache = addr);
24304 } else if (mm->free_area_cache == vma->vm_end) {
24305 /* pull free_area_cache down to the first hole */
24306 mm->free_area_cache = vma->vm_start;
24307@@ -352,29 +358,34 @@ try_again:
24308
24309 /* remember the largest hole we saw so far */
24310 if (addr + largest_hole < vma->vm_start)
24311- largest_hole = vma->vm_start - addr;
24312+ largest_hole = vma->vm_start - addr;
24313
24314 /* try just below the current vma->vm_start */
24315- addr = (vma->vm_start - len) & huge_page_mask(h);
24316- } while (len <= vma->vm_start);
24317+ addr = skip_heap_stack_gap(vma, len);
24318+ } while (!IS_ERR_VALUE(addr));
24319
24320 fail:
24321 /*
24322- * if hint left us with no space for the requested
24323- * mapping then try again:
24324- */
24325- if (start_addr != base) {
24326- mm->free_area_cache = base;
24327- largest_hole = 0;
24328- goto try_again;
24329- }
24330- /*
24331 * A failed mmap() very likely causes application failure,
24332 * so fall back to the bottom-up function here. This scenario
24333 * can happen with large stack limits and large mmap()
24334 * allocations.
24335 */
24336- mm->free_area_cache = TASK_UNMAPPED_BASE;
24337+
24338+#ifdef CONFIG_PAX_SEGMEXEC
24339+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24340+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24341+ else
24342+#endif
24343+
24344+ mm->mmap_base = TASK_UNMAPPED_BASE;
24345+
24346+#ifdef CONFIG_PAX_RANDMMAP
24347+ if (mm->pax_flags & MF_PAX_RANDMMAP)
24348+ mm->mmap_base += mm->delta_mmap;
24349+#endif
24350+
24351+ mm->free_area_cache = mm->mmap_base;
24352 mm->cached_hole_size = ~0UL;
24353 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24354 len, pgoff, flags);
24355@@ -382,6 +393,7 @@ fail:
24356 /*
24357 * Restore the topdown base:
24358 */
24359+ mm->mmap_base = base;
24360 mm->free_area_cache = base;
24361 mm->cached_hole_size = ~0UL;
24362
24363@@ -395,10 +407,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24364 struct hstate *h = hstate_file(file);
24365 struct mm_struct *mm = current->mm;
24366 struct vm_area_struct *vma;
24367+ unsigned long pax_task_size = TASK_SIZE;
24368
24369 if (len & ~huge_page_mask(h))
24370 return -EINVAL;
24371- if (len > TASK_SIZE)
24372+
24373+#ifdef CONFIG_PAX_SEGMEXEC
24374+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24375+ pax_task_size = SEGMEXEC_TASK_SIZE;
24376+#endif
24377+
24378+ pax_task_size -= PAGE_SIZE;
24379+
24380+ if (len > pax_task_size)
24381 return -ENOMEM;
24382
24383 if (flags & MAP_FIXED) {
24384@@ -410,8 +431,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24385 if (addr) {
24386 addr = ALIGN(addr, huge_page_size(h));
24387 vma = find_vma(mm, addr);
24388- if (TASK_SIZE - len >= addr &&
24389- (!vma || addr + len <= vma->vm_start))
24390+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24391 return addr;
24392 }
24393 if (mm->get_unmapped_area == arch_get_unmapped_area)
24394diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24395index bc4e9d8..ca4c14b 100644
24396--- a/arch/x86/mm/init.c
24397+++ b/arch/x86/mm/init.c
24398@@ -16,6 +16,8 @@
24399 #include <asm/tlb.h>
24400 #include <asm/proto.h>
24401 #include <asm/dma.h> /* for MAX_DMA_PFN */
24402+#include <asm/desc.h>
24403+#include <asm/bios_ebda.h>
24404
24405 unsigned long __initdata pgt_buf_start;
24406 unsigned long __meminitdata pgt_buf_end;
24407@@ -38,7 +40,7 @@ struct map_range {
24408 static void __init find_early_table_space(struct map_range *mr, unsigned long end,
24409 int use_pse, int use_gbpages)
24410 {
24411- unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
24412+ unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
24413 phys_addr_t base;
24414
24415 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
24416@@ -317,10 +319,37 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24417 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24418 * mmio resources as well as potential bios/acpi data regions.
24419 */
24420+
24421+#ifdef CONFIG_GRKERNSEC_KMEM
24422+static unsigned int ebda_start __read_only;
24423+static unsigned int ebda_end __read_only;
24424+#endif
24425+
24426 int devmem_is_allowed(unsigned long pagenr)
24427 {
24428+#ifdef CONFIG_GRKERNSEC_KMEM
24429+ /* allow BDA */
24430+ if (!pagenr)
24431+ return 1;
24432+ /* allow EBDA */
24433+ if (pagenr >= ebda_start && pagenr < ebda_end)
24434+ return 1;
24435+#else
24436+ if (!pagenr)
24437+ return 1;
24438+#ifdef CONFIG_VM86
24439+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24440+ return 1;
24441+#endif
24442+#endif
24443+
24444+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24445+ return 1;
24446+#ifdef CONFIG_GRKERNSEC_KMEM
24447+ /* throw out everything else below 1MB */
24448 if (pagenr <= 256)
24449- return 1;
24450+ return 0;
24451+#endif
24452 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24453 return 0;
24454 if (!page_is_ram(pagenr))
24455@@ -377,8 +406,116 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24456 #endif
24457 }
24458
24459+#ifdef CONFIG_GRKERNSEC_KMEM
24460+static inline void gr_init_ebda(void)
24461+{
24462+ unsigned int ebda_addr;
24463+ unsigned int ebda_size = 0;
24464+
24465+ ebda_addr = get_bios_ebda();
24466+ if (ebda_addr) {
24467+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24468+ ebda_size <<= 10;
24469+ }
24470+ if (ebda_addr && ebda_size) {
24471+ ebda_start = ebda_addr >> PAGE_SHIFT;
24472+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24473+ } else {
24474+ ebda_start = 0x9f000 >> PAGE_SHIFT;
24475+ ebda_end = 0xa0000 >> PAGE_SHIFT;
24476+ }
24477+}
24478+#else
24479+static inline void gr_init_ebda(void) { }
24480+#endif
24481+
24482 void free_initmem(void)
24483 {
24484+#ifdef CONFIG_PAX_KERNEXEC
24485+#ifdef CONFIG_X86_32
24486+ /* PaX: limit KERNEL_CS to actual size */
24487+ unsigned long addr, limit;
24488+ struct desc_struct d;
24489+ int cpu;
24490+#else
24491+ pgd_t *pgd;
24492+ pud_t *pud;
24493+ pmd_t *pmd;
24494+ unsigned long addr, end;
24495+#endif
24496+#endif
24497+
24498+ gr_init_ebda();
24499+
24500+#ifdef CONFIG_PAX_KERNEXEC
24501+#ifdef CONFIG_X86_32
24502+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24503+ limit = (limit - 1UL) >> PAGE_SHIFT;
24504+
24505+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24506+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24507+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24508+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24509+ }
24510+
24511+ /* PaX: make KERNEL_CS read-only */
24512+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24513+ if (!paravirt_enabled())
24514+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24515+/*
24516+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24517+ pgd = pgd_offset_k(addr);
24518+ pud = pud_offset(pgd, addr);
24519+ pmd = pmd_offset(pud, addr);
24520+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24521+ }
24522+*/
24523+#ifdef CONFIG_X86_PAE
24524+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24525+/*
24526+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24527+ pgd = pgd_offset_k(addr);
24528+ pud = pud_offset(pgd, addr);
24529+ pmd = pmd_offset(pud, addr);
24530+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24531+ }
24532+*/
24533+#endif
24534+
24535+#ifdef CONFIG_MODULES
24536+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24537+#endif
24538+
24539+#else
24540+ /* PaX: make kernel code/rodata read-only, rest non-executable */
24541+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24542+ pgd = pgd_offset_k(addr);
24543+ pud = pud_offset(pgd, addr);
24544+ pmd = pmd_offset(pud, addr);
24545+ if (!pmd_present(*pmd))
24546+ continue;
24547+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24548+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24549+ else
24550+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24551+ }
24552+
24553+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24554+ end = addr + KERNEL_IMAGE_SIZE;
24555+ for (; addr < end; addr += PMD_SIZE) {
24556+ pgd = pgd_offset_k(addr);
24557+ pud = pud_offset(pgd, addr);
24558+ pmd = pmd_offset(pud, addr);
24559+ if (!pmd_present(*pmd))
24560+ continue;
24561+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24562+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24563+ }
24564+#endif
24565+
24566+ flush_tlb_all();
24567+#endif
24568+
24569 free_init_pages("unused kernel memory",
24570 (unsigned long)(&__init_begin),
24571 (unsigned long)(&__init_end));
24572diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24573index 575d86f..4987469 100644
24574--- a/arch/x86/mm/init_32.c
24575+++ b/arch/x86/mm/init_32.c
24576@@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24577 }
24578
24579 /*
24580- * Creates a middle page table and puts a pointer to it in the
24581- * given global directory entry. This only returns the gd entry
24582- * in non-PAE compilation mode, since the middle layer is folded.
24583- */
24584-static pmd_t * __init one_md_table_init(pgd_t *pgd)
24585-{
24586- pud_t *pud;
24587- pmd_t *pmd_table;
24588-
24589-#ifdef CONFIG_X86_PAE
24590- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24591- if (after_bootmem)
24592- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24593- else
24594- pmd_table = (pmd_t *)alloc_low_page();
24595- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24596- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24597- pud = pud_offset(pgd, 0);
24598- BUG_ON(pmd_table != pmd_offset(pud, 0));
24599-
24600- return pmd_table;
24601- }
24602-#endif
24603- pud = pud_offset(pgd, 0);
24604- pmd_table = pmd_offset(pud, 0);
24605-
24606- return pmd_table;
24607-}
24608-
24609-/*
24610 * Create a page table and place a pointer to it in a middle page
24611 * directory entry:
24612 */
24613@@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24614 page_table = (pte_t *)alloc_low_page();
24615
24616 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24617+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24618+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24619+#else
24620 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24621+#endif
24622 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24623 }
24624
24625 return pte_offset_kernel(pmd, 0);
24626 }
24627
24628+static pmd_t * __init one_md_table_init(pgd_t *pgd)
24629+{
24630+ pud_t *pud;
24631+ pmd_t *pmd_table;
24632+
24633+ pud = pud_offset(pgd, 0);
24634+ pmd_table = pmd_offset(pud, 0);
24635+
24636+ return pmd_table;
24637+}
24638+
24639 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24640 {
24641 int pgd_idx = pgd_index(vaddr);
24642@@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24643 int pgd_idx, pmd_idx;
24644 unsigned long vaddr;
24645 pgd_t *pgd;
24646+ pud_t *pud;
24647 pmd_t *pmd;
24648 pte_t *pte = NULL;
24649
24650@@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24651 pgd = pgd_base + pgd_idx;
24652
24653 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24654- pmd = one_md_table_init(pgd);
24655- pmd = pmd + pmd_index(vaddr);
24656+ pud = pud_offset(pgd, vaddr);
24657+ pmd = pmd_offset(pud, vaddr);
24658+
24659+#ifdef CONFIG_X86_PAE
24660+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24661+#endif
24662+
24663 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24664 pmd++, pmd_idx++) {
24665 pte = page_table_kmap_check(one_page_table_init(pmd),
24666@@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24667 }
24668 }
24669
24670-static inline int is_kernel_text(unsigned long addr)
24671+static inline int is_kernel_text(unsigned long start, unsigned long end)
24672 {
24673- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24674- return 1;
24675- return 0;
24676+ if ((start > ktla_ktva((unsigned long)_etext) ||
24677+ end <= ktla_ktva((unsigned long)_stext)) &&
24678+ (start > ktla_ktva((unsigned long)_einittext) ||
24679+ end <= ktla_ktva((unsigned long)_sinittext)) &&
24680+
24681+#ifdef CONFIG_ACPI_SLEEP
24682+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24683+#endif
24684+
24685+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24686+ return 0;
24687+ return 1;
24688 }
24689
24690 /*
24691@@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24692 unsigned long last_map_addr = end;
24693 unsigned long start_pfn, end_pfn;
24694 pgd_t *pgd_base = swapper_pg_dir;
24695- int pgd_idx, pmd_idx, pte_ofs;
24696+ unsigned int pgd_idx, pmd_idx, pte_ofs;
24697 unsigned long pfn;
24698 pgd_t *pgd;
24699+ pud_t *pud;
24700 pmd_t *pmd;
24701 pte_t *pte;
24702 unsigned pages_2m, pages_4k;
24703@@ -280,8 +281,13 @@ repeat:
24704 pfn = start_pfn;
24705 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24706 pgd = pgd_base + pgd_idx;
24707- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24708- pmd = one_md_table_init(pgd);
24709+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24710+ pud = pud_offset(pgd, 0);
24711+ pmd = pmd_offset(pud, 0);
24712+
24713+#ifdef CONFIG_X86_PAE
24714+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24715+#endif
24716
24717 if (pfn >= end_pfn)
24718 continue;
24719@@ -293,14 +299,13 @@ repeat:
24720 #endif
24721 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24722 pmd++, pmd_idx++) {
24723- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24724+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24725
24726 /*
24727 * Map with big pages if possible, otherwise
24728 * create normal page tables:
24729 */
24730 if (use_pse) {
24731- unsigned int addr2;
24732 pgprot_t prot = PAGE_KERNEL_LARGE;
24733 /*
24734 * first pass will use the same initial
24735@@ -310,11 +315,7 @@ repeat:
24736 __pgprot(PTE_IDENT_ATTR |
24737 _PAGE_PSE);
24738
24739- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24740- PAGE_OFFSET + PAGE_SIZE-1;
24741-
24742- if (is_kernel_text(addr) ||
24743- is_kernel_text(addr2))
24744+ if (is_kernel_text(address, address + PMD_SIZE))
24745 prot = PAGE_KERNEL_LARGE_EXEC;
24746
24747 pages_2m++;
24748@@ -331,7 +332,7 @@ repeat:
24749 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24750 pte += pte_ofs;
24751 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24752- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24753+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24754 pgprot_t prot = PAGE_KERNEL;
24755 /*
24756 * first pass will use the same initial
24757@@ -339,7 +340,7 @@ repeat:
24758 */
24759 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24760
24761- if (is_kernel_text(addr))
24762+ if (is_kernel_text(address, address + PAGE_SIZE))
24763 prot = PAGE_KERNEL_EXEC;
24764
24765 pages_4k++;
24766@@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24767
24768 pud = pud_offset(pgd, va);
24769 pmd = pmd_offset(pud, va);
24770- if (!pmd_present(*pmd))
24771+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
24772 break;
24773
24774 pte = pte_offset_kernel(pmd, va);
24775@@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
24776
24777 static void __init pagetable_init(void)
24778 {
24779- pgd_t *pgd_base = swapper_pg_dir;
24780-
24781- permanent_kmaps_init(pgd_base);
24782+ permanent_kmaps_init(swapper_pg_dir);
24783 }
24784
24785-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24786+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24787 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24788
24789 /* user-defined highmem size */
24790@@ -734,6 +733,12 @@ void __init mem_init(void)
24791
24792 pci_iommu_alloc();
24793
24794+#ifdef CONFIG_PAX_PER_CPU_PGD
24795+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24796+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24797+ KERNEL_PGD_PTRS);
24798+#endif
24799+
24800 #ifdef CONFIG_FLATMEM
24801 BUG_ON(!mem_map);
24802 #endif
24803@@ -760,7 +765,7 @@ void __init mem_init(void)
24804 reservedpages++;
24805
24806 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24807- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
24808+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
24809 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
24810
24811 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
24812@@ -801,10 +806,10 @@ void __init mem_init(void)
24813 ((unsigned long)&__init_end -
24814 (unsigned long)&__init_begin) >> 10,
24815
24816- (unsigned long)&_etext, (unsigned long)&_edata,
24817- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
24818+ (unsigned long)&_sdata, (unsigned long)&_edata,
24819+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
24820
24821- (unsigned long)&_text, (unsigned long)&_etext,
24822+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
24823 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
24824
24825 /*
24826@@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
24827 if (!kernel_set_to_readonly)
24828 return;
24829
24830+ start = ktla_ktva(start);
24831 pr_debug("Set kernel text: %lx - %lx for read write\n",
24832 start, start+size);
24833
24834@@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
24835 if (!kernel_set_to_readonly)
24836 return;
24837
24838+ start = ktla_ktva(start);
24839 pr_debug("Set kernel text: %lx - %lx for read only\n",
24840 start, start+size);
24841
24842@@ -924,6 +931,7 @@ void mark_rodata_ro(void)
24843 unsigned long start = PFN_ALIGN(_text);
24844 unsigned long size = PFN_ALIGN(_etext) - start;
24845
24846+ start = ktla_ktva(start);
24847 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
24848 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
24849 size >> 10);
24850diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
24851index 2b6b4a3..c17210d 100644
24852--- a/arch/x86/mm/init_64.c
24853+++ b/arch/x86/mm/init_64.c
24854@@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
24855 * around without checking the pgd every time.
24856 */
24857
24858-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
24859+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
24860 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24861
24862 int force_personality32;
24863@@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24864
24865 for (address = start; address <= end; address += PGDIR_SIZE) {
24866 const pgd_t *pgd_ref = pgd_offset_k(address);
24867+
24868+#ifdef CONFIG_PAX_PER_CPU_PGD
24869+ unsigned long cpu;
24870+#else
24871 struct page *page;
24872+#endif
24873
24874 if (pgd_none(*pgd_ref))
24875 continue;
24876
24877 spin_lock(&pgd_lock);
24878+
24879+#ifdef CONFIG_PAX_PER_CPU_PGD
24880+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
24881+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
24882+#else
24883 list_for_each_entry(page, &pgd_list, lru) {
24884 pgd_t *pgd;
24885 spinlock_t *pgt_lock;
24886@@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24887 /* the pgt_lock only for Xen */
24888 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
24889 spin_lock(pgt_lock);
24890+#endif
24891
24892 if (pgd_none(*pgd))
24893 set_pgd(pgd, *pgd_ref);
24894@@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24895 BUG_ON(pgd_page_vaddr(*pgd)
24896 != pgd_page_vaddr(*pgd_ref));
24897
24898+#ifndef CONFIG_PAX_PER_CPU_PGD
24899 spin_unlock(pgt_lock);
24900+#endif
24901+
24902 }
24903 spin_unlock(&pgd_lock);
24904 }
24905@@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
24906 {
24907 if (pgd_none(*pgd)) {
24908 pud_t *pud = (pud_t *)spp_getpage();
24909- pgd_populate(&init_mm, pgd, pud);
24910+ pgd_populate_kernel(&init_mm, pgd, pud);
24911 if (pud != pud_offset(pgd, 0))
24912 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
24913 pud, pud_offset(pgd, 0));
24914@@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
24915 {
24916 if (pud_none(*pud)) {
24917 pmd_t *pmd = (pmd_t *) spp_getpage();
24918- pud_populate(&init_mm, pud, pmd);
24919+ pud_populate_kernel(&init_mm, pud, pmd);
24920 if (pmd != pmd_offset(pud, 0))
24921 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
24922 pmd, pmd_offset(pud, 0));
24923@@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
24924 pmd = fill_pmd(pud, vaddr);
24925 pte = fill_pte(pmd, vaddr);
24926
24927+ pax_open_kernel();
24928 set_pte(pte, new_pte);
24929+ pax_close_kernel();
24930
24931 /*
24932 * It's enough to flush this one mapping.
24933@@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
24934 pgd = pgd_offset_k((unsigned long)__va(phys));
24935 if (pgd_none(*pgd)) {
24936 pud = (pud_t *) spp_getpage();
24937- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
24938- _PAGE_USER));
24939+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
24940 }
24941 pud = pud_offset(pgd, (unsigned long)__va(phys));
24942 if (pud_none(*pud)) {
24943 pmd = (pmd_t *) spp_getpage();
24944- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
24945- _PAGE_USER));
24946+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
24947 }
24948 pmd = pmd_offset(pud, phys);
24949 BUG_ON(!pmd_none(*pmd));
24950@@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
24951 if (pfn >= pgt_buf_top)
24952 panic("alloc_low_page: ran out of memory");
24953
24954- adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24955+ adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24956 clear_page(adr);
24957 *phys = pfn * PAGE_SIZE;
24958 return adr;
24959@@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
24960
24961 phys = __pa(virt);
24962 left = phys & (PAGE_SIZE - 1);
24963- adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24964+ adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24965 adr = (void *)(((unsigned long)adr) | left);
24966
24967 return adr;
24968@@ -548,7 +562,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
24969 unmap_low_page(pmd);
24970
24971 spin_lock(&init_mm.page_table_lock);
24972- pud_populate(&init_mm, pud, __va(pmd_phys));
24973+ pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
24974 spin_unlock(&init_mm.page_table_lock);
24975 }
24976 __flush_tlb_all();
24977@@ -594,7 +608,7 @@ kernel_physical_mapping_init(unsigned long start,
24978 unmap_low_page(pud);
24979
24980 spin_lock(&init_mm.page_table_lock);
24981- pgd_populate(&init_mm, pgd, __va(pud_phys));
24982+ pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
24983 spin_unlock(&init_mm.page_table_lock);
24984 pgd_changed = true;
24985 }
24986@@ -686,6 +700,12 @@ void __init mem_init(void)
24987
24988 pci_iommu_alloc();
24989
24990+#ifdef CONFIG_PAX_PER_CPU_PGD
24991+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24992+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24993+ KERNEL_PGD_PTRS);
24994+#endif
24995+
24996 /* clear_bss() already clear the empty_zero_page */
24997
24998 reservedpages = 0;
24999@@ -846,8 +866,8 @@ int kern_addr_valid(unsigned long addr)
25000 static struct vm_area_struct gate_vma = {
25001 .vm_start = VSYSCALL_START,
25002 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25003- .vm_page_prot = PAGE_READONLY_EXEC,
25004- .vm_flags = VM_READ | VM_EXEC
25005+ .vm_page_prot = PAGE_READONLY,
25006+ .vm_flags = VM_READ
25007 };
25008
25009 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25010@@ -881,7 +901,7 @@ int in_gate_area_no_mm(unsigned long addr)
25011
25012 const char *arch_vma_name(struct vm_area_struct *vma)
25013 {
25014- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25015+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25016 return "[vdso]";
25017 if (vma == &gate_vma)
25018 return "[vsyscall]";
25019diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25020index 7b179b4..6bd1777 100644
25021--- a/arch/x86/mm/iomap_32.c
25022+++ b/arch/x86/mm/iomap_32.c
25023@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25024 type = kmap_atomic_idx_push();
25025 idx = type + KM_TYPE_NR * smp_processor_id();
25026 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25027+
25028+ pax_open_kernel();
25029 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25030+ pax_close_kernel();
25031+
25032 arch_flush_lazy_mmu_mode();
25033
25034 return (void *)vaddr;
25035diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25036index 78fe3f1..8293b6f 100644
25037--- a/arch/x86/mm/ioremap.c
25038+++ b/arch/x86/mm/ioremap.c
25039@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25040 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25041 int is_ram = page_is_ram(pfn);
25042
25043- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25044+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25045 return NULL;
25046 WARN_ON_ONCE(is_ram);
25047 }
25048@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25049
25050 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25051 if (page_is_ram(start >> PAGE_SHIFT))
25052+#ifdef CONFIG_HIGHMEM
25053+ if ((start >> PAGE_SHIFT) < max_low_pfn)
25054+#endif
25055 return __va(phys);
25056
25057 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25058@@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25059 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25060
25061 static __initdata int after_paging_init;
25062-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25063+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25064
25065 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25066 {
25067@@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25068 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25069
25070 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25071- memset(bm_pte, 0, sizeof(bm_pte));
25072- pmd_populate_kernel(&init_mm, pmd, bm_pte);
25073+ pmd_populate_user(&init_mm, pmd, bm_pte);
25074
25075 /*
25076 * The boot-ioremap range spans multiple pmds, for which
25077diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25078index d87dd6d..bf3fa66 100644
25079--- a/arch/x86/mm/kmemcheck/kmemcheck.c
25080+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25081@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25082 * memory (e.g. tracked pages)? For now, we need this to avoid
25083 * invoking kmemcheck for PnP BIOS calls.
25084 */
25085- if (regs->flags & X86_VM_MASK)
25086+ if (v8086_mode(regs))
25087 return false;
25088- if (regs->cs != __KERNEL_CS)
25089+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25090 return false;
25091
25092 pte = kmemcheck_pte_lookup(address);
25093diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25094index 845df68..1d8d29f 100644
25095--- a/arch/x86/mm/mmap.c
25096+++ b/arch/x86/mm/mmap.c
25097@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25098 * Leave an at least ~128 MB hole with possible stack randomization.
25099 */
25100 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25101-#define MAX_GAP (TASK_SIZE/6*5)
25102+#define MAX_GAP (pax_task_size/6*5)
25103
25104 static int mmap_is_legacy(void)
25105 {
25106@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25107 return rnd << PAGE_SHIFT;
25108 }
25109
25110-static unsigned long mmap_base(void)
25111+static unsigned long mmap_base(struct mm_struct *mm)
25112 {
25113 unsigned long gap = rlimit(RLIMIT_STACK);
25114+ unsigned long pax_task_size = TASK_SIZE;
25115+
25116+#ifdef CONFIG_PAX_SEGMEXEC
25117+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25118+ pax_task_size = SEGMEXEC_TASK_SIZE;
25119+#endif
25120
25121 if (gap < MIN_GAP)
25122 gap = MIN_GAP;
25123 else if (gap > MAX_GAP)
25124 gap = MAX_GAP;
25125
25126- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25127+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25128 }
25129
25130 /*
25131 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25132 * does, but not when emulating X86_32
25133 */
25134-static unsigned long mmap_legacy_base(void)
25135+static unsigned long mmap_legacy_base(struct mm_struct *mm)
25136 {
25137- if (mmap_is_ia32())
25138+ if (mmap_is_ia32()) {
25139+
25140+#ifdef CONFIG_PAX_SEGMEXEC
25141+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25142+ return SEGMEXEC_TASK_UNMAPPED_BASE;
25143+ else
25144+#endif
25145+
25146 return TASK_UNMAPPED_BASE;
25147- else
25148+ } else
25149 return TASK_UNMAPPED_BASE + mmap_rnd();
25150 }
25151
25152@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25153 void arch_pick_mmap_layout(struct mm_struct *mm)
25154 {
25155 if (mmap_is_legacy()) {
25156- mm->mmap_base = mmap_legacy_base();
25157+ mm->mmap_base = mmap_legacy_base(mm);
25158+
25159+#ifdef CONFIG_PAX_RANDMMAP
25160+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25161+ mm->mmap_base += mm->delta_mmap;
25162+#endif
25163+
25164 mm->get_unmapped_area = arch_get_unmapped_area;
25165 mm->unmap_area = arch_unmap_area;
25166 } else {
25167- mm->mmap_base = mmap_base();
25168+ mm->mmap_base = mmap_base(mm);
25169+
25170+#ifdef CONFIG_PAX_RANDMMAP
25171+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25172+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25173+#endif
25174+
25175 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25176 mm->unmap_area = arch_unmap_area_topdown;
25177 }
25178diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25179index dc0b727..dc9d71a 100644
25180--- a/arch/x86/mm/mmio-mod.c
25181+++ b/arch/x86/mm/mmio-mod.c
25182@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25183 break;
25184 default:
25185 {
25186- unsigned char *ip = (unsigned char *)instptr;
25187+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25188 my_trace->opcode = MMIO_UNKNOWN_OP;
25189 my_trace->width = 0;
25190 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25191@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25192 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25193 void __iomem *addr)
25194 {
25195- static atomic_t next_id;
25196+ static atomic_unchecked_t next_id;
25197 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25198 /* These are page-unaligned. */
25199 struct mmiotrace_map map = {
25200@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25201 .private = trace
25202 },
25203 .phys = offset,
25204- .id = atomic_inc_return(&next_id)
25205+ .id = atomic_inc_return_unchecked(&next_id)
25206 };
25207 map.map_id = trace->id;
25208
25209diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25210index b008656..773eac2 100644
25211--- a/arch/x86/mm/pageattr-test.c
25212+++ b/arch/x86/mm/pageattr-test.c
25213@@ -36,7 +36,7 @@ enum {
25214
25215 static int pte_testbit(pte_t pte)
25216 {
25217- return pte_flags(pte) & _PAGE_UNUSED1;
25218+ return pte_flags(pte) & _PAGE_CPA_TEST;
25219 }
25220
25221 struct split_state {
25222diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25223index a718e0d..45efc32 100644
25224--- a/arch/x86/mm/pageattr.c
25225+++ b/arch/x86/mm/pageattr.c
25226@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25227 */
25228 #ifdef CONFIG_PCI_BIOS
25229 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25230- pgprot_val(forbidden) |= _PAGE_NX;
25231+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25232 #endif
25233
25234 /*
25235@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25236 * Does not cover __inittext since that is gone later on. On
25237 * 64bit we do not enforce !NX on the low mapping
25238 */
25239- if (within(address, (unsigned long)_text, (unsigned long)_etext))
25240- pgprot_val(forbidden) |= _PAGE_NX;
25241+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25242+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25243
25244+#ifdef CONFIG_DEBUG_RODATA
25245 /*
25246 * The .rodata section needs to be read-only. Using the pfn
25247 * catches all aliases.
25248@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25249 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25250 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25251 pgprot_val(forbidden) |= _PAGE_RW;
25252+#endif
25253
25254 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25255 /*
25256@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25257 }
25258 #endif
25259
25260+#ifdef CONFIG_PAX_KERNEXEC
25261+ if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25262+ pgprot_val(forbidden) |= _PAGE_RW;
25263+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25264+ }
25265+#endif
25266+
25267 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25268
25269 return prot;
25270@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25271 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25272 {
25273 /* change init_mm */
25274+ pax_open_kernel();
25275 set_pte_atomic(kpte, pte);
25276+
25277 #ifdef CONFIG_X86_32
25278 if (!SHARED_KERNEL_PMD) {
25279+
25280+#ifdef CONFIG_PAX_PER_CPU_PGD
25281+ unsigned long cpu;
25282+#else
25283 struct page *page;
25284+#endif
25285
25286+#ifdef CONFIG_PAX_PER_CPU_PGD
25287+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25288+ pgd_t *pgd = get_cpu_pgd(cpu);
25289+#else
25290 list_for_each_entry(page, &pgd_list, lru) {
25291- pgd_t *pgd;
25292+ pgd_t *pgd = (pgd_t *)page_address(page);
25293+#endif
25294+
25295 pud_t *pud;
25296 pmd_t *pmd;
25297
25298- pgd = (pgd_t *)page_address(page) + pgd_index(address);
25299+ pgd += pgd_index(address);
25300 pud = pud_offset(pgd, address);
25301 pmd = pmd_offset(pud, address);
25302 set_pte_atomic((pte_t *)pmd, pte);
25303 }
25304 }
25305 #endif
25306+ pax_close_kernel();
25307 }
25308
25309 static int
25310diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25311index 3d68ef6..7f69136 100644
25312--- a/arch/x86/mm/pat.c
25313+++ b/arch/x86/mm/pat.c
25314@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
25315
25316 if (!entry) {
25317 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
25318- current->comm, current->pid, start, end - 1);
25319+ current->comm, task_pid_nr(current), start, end - 1);
25320 return -EINVAL;
25321 }
25322
25323@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25324
25325 while (cursor < to) {
25326 if (!devmem_is_allowed(pfn)) {
25327- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
25328- current->comm, from, to - 1);
25329+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
25330+ current->comm, from, to - 1, cursor);
25331 return 0;
25332 }
25333 cursor += PAGE_SIZE;
25334@@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25335 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
25336 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
25337 "for [mem %#010Lx-%#010Lx]\n",
25338- current->comm, current->pid,
25339+ current->comm, task_pid_nr(current),
25340 cattr_name(flags),
25341 base, (unsigned long long)(base + size-1));
25342 return -EINVAL;
25343@@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25344 flags = lookup_memtype(paddr);
25345 if (want_flags != flags) {
25346 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
25347- current->comm, current->pid,
25348+ current->comm, task_pid_nr(current),
25349 cattr_name(want_flags),
25350 (unsigned long long)paddr,
25351 (unsigned long long)(paddr + size - 1),
25352@@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25353 free_memtype(paddr, paddr + size);
25354 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25355 " for [mem %#010Lx-%#010Lx], got %s\n",
25356- current->comm, current->pid,
25357+ current->comm, task_pid_nr(current),
25358 cattr_name(want_flags),
25359 (unsigned long long)paddr,
25360 (unsigned long long)(paddr + size - 1),
25361diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25362index 9f0614d..92ae64a 100644
25363--- a/arch/x86/mm/pf_in.c
25364+++ b/arch/x86/mm/pf_in.c
25365@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25366 int i;
25367 enum reason_type rv = OTHERS;
25368
25369- p = (unsigned char *)ins_addr;
25370+ p = (unsigned char *)ktla_ktva(ins_addr);
25371 p += skip_prefix(p, &prf);
25372 p += get_opcode(p, &opcode);
25373
25374@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25375 struct prefix_bits prf;
25376 int i;
25377
25378- p = (unsigned char *)ins_addr;
25379+ p = (unsigned char *)ktla_ktva(ins_addr);
25380 p += skip_prefix(p, &prf);
25381 p += get_opcode(p, &opcode);
25382
25383@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25384 struct prefix_bits prf;
25385 int i;
25386
25387- p = (unsigned char *)ins_addr;
25388+ p = (unsigned char *)ktla_ktva(ins_addr);
25389 p += skip_prefix(p, &prf);
25390 p += get_opcode(p, &opcode);
25391
25392@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25393 struct prefix_bits prf;
25394 int i;
25395
25396- p = (unsigned char *)ins_addr;
25397+ p = (unsigned char *)ktla_ktva(ins_addr);
25398 p += skip_prefix(p, &prf);
25399 p += get_opcode(p, &opcode);
25400 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25401@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25402 struct prefix_bits prf;
25403 int i;
25404
25405- p = (unsigned char *)ins_addr;
25406+ p = (unsigned char *)ktla_ktva(ins_addr);
25407 p += skip_prefix(p, &prf);
25408 p += get_opcode(p, &opcode);
25409 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25410diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25411index 8573b83..4f3ed7e 100644
25412--- a/arch/x86/mm/pgtable.c
25413+++ b/arch/x86/mm/pgtable.c
25414@@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25415 list_del(&page->lru);
25416 }
25417
25418-#define UNSHARED_PTRS_PER_PGD \
25419- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25420+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25421+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25422
25423+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25424+{
25425+ unsigned int count = USER_PGD_PTRS;
25426
25427+ while (count--)
25428+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25429+}
25430+#endif
25431+
25432+#ifdef CONFIG_PAX_PER_CPU_PGD
25433+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25434+{
25435+ unsigned int count = USER_PGD_PTRS;
25436+
25437+ while (count--) {
25438+ pgd_t pgd;
25439+
25440+#ifdef CONFIG_X86_64
25441+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25442+#else
25443+ pgd = *src++;
25444+#endif
25445+
25446+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25447+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25448+#endif
25449+
25450+ *dst++ = pgd;
25451+ }
25452+
25453+}
25454+#endif
25455+
25456+#ifdef CONFIG_X86_64
25457+#define pxd_t pud_t
25458+#define pyd_t pgd_t
25459+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25460+#define pxd_free(mm, pud) pud_free((mm), (pud))
25461+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25462+#define pyd_offset(mm, address) pgd_offset((mm), (address))
25463+#define PYD_SIZE PGDIR_SIZE
25464+#else
25465+#define pxd_t pmd_t
25466+#define pyd_t pud_t
25467+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25468+#define pxd_free(mm, pud) pmd_free((mm), (pud))
25469+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25470+#define pyd_offset(mm, address) pud_offset((mm), (address))
25471+#define PYD_SIZE PUD_SIZE
25472+#endif
25473+
25474+#ifdef CONFIG_PAX_PER_CPU_PGD
25475+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25476+static inline void pgd_dtor(pgd_t *pgd) {}
25477+#else
25478 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25479 {
25480 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25481@@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25482 pgd_list_del(pgd);
25483 spin_unlock(&pgd_lock);
25484 }
25485+#endif
25486
25487 /*
25488 * List of all pgd's needed for non-PAE so it can invalidate entries
25489@@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25490 * -- wli
25491 */
25492
25493-#ifdef CONFIG_X86_PAE
25494+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25495 /*
25496 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25497 * updating the top-level pagetable entries to guarantee the
25498@@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25499 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25500 * and initialize the kernel pmds here.
25501 */
25502-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25503+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25504
25505 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25506 {
25507@@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25508 */
25509 flush_tlb_mm(mm);
25510 }
25511+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25512+#define PREALLOCATED_PXDS USER_PGD_PTRS
25513 #else /* !CONFIG_X86_PAE */
25514
25515 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25516-#define PREALLOCATED_PMDS 0
25517+#define PREALLOCATED_PXDS 0
25518
25519 #endif /* CONFIG_X86_PAE */
25520
25521-static void free_pmds(pmd_t *pmds[])
25522+static void free_pxds(pxd_t *pxds[])
25523 {
25524 int i;
25525
25526- for(i = 0; i < PREALLOCATED_PMDS; i++)
25527- if (pmds[i])
25528- free_page((unsigned long)pmds[i]);
25529+ for(i = 0; i < PREALLOCATED_PXDS; i++)
25530+ if (pxds[i])
25531+ free_page((unsigned long)pxds[i]);
25532 }
25533
25534-static int preallocate_pmds(pmd_t *pmds[])
25535+static int preallocate_pxds(pxd_t *pxds[])
25536 {
25537 int i;
25538 bool failed = false;
25539
25540- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25541- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25542- if (pmd == NULL)
25543+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25544+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25545+ if (pxd == NULL)
25546 failed = true;
25547- pmds[i] = pmd;
25548+ pxds[i] = pxd;
25549 }
25550
25551 if (failed) {
25552- free_pmds(pmds);
25553+ free_pxds(pxds);
25554 return -ENOMEM;
25555 }
25556
25557@@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25558 * preallocate which never got a corresponding vma will need to be
25559 * freed manually.
25560 */
25561-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25562+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25563 {
25564 int i;
25565
25566- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25567+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25568 pgd_t pgd = pgdp[i];
25569
25570 if (pgd_val(pgd) != 0) {
25571- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25572+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25573
25574- pgdp[i] = native_make_pgd(0);
25575+ set_pgd(pgdp + i, native_make_pgd(0));
25576
25577- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25578- pmd_free(mm, pmd);
25579+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25580+ pxd_free(mm, pxd);
25581 }
25582 }
25583 }
25584
25585-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25586+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25587 {
25588- pud_t *pud;
25589+ pyd_t *pyd;
25590 unsigned long addr;
25591 int i;
25592
25593- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25594+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25595 return;
25596
25597- pud = pud_offset(pgd, 0);
25598+#ifdef CONFIG_X86_64
25599+ pyd = pyd_offset(mm, 0L);
25600+#else
25601+ pyd = pyd_offset(pgd, 0L);
25602+#endif
25603
25604- for (addr = i = 0; i < PREALLOCATED_PMDS;
25605- i++, pud++, addr += PUD_SIZE) {
25606- pmd_t *pmd = pmds[i];
25607+ for (addr = i = 0; i < PREALLOCATED_PXDS;
25608+ i++, pyd++, addr += PYD_SIZE) {
25609+ pxd_t *pxd = pxds[i];
25610
25611 if (i >= KERNEL_PGD_BOUNDARY)
25612- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25613- sizeof(pmd_t) * PTRS_PER_PMD);
25614+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25615+ sizeof(pxd_t) * PTRS_PER_PMD);
25616
25617- pud_populate(mm, pud, pmd);
25618+ pyd_populate(mm, pyd, pxd);
25619 }
25620 }
25621
25622 pgd_t *pgd_alloc(struct mm_struct *mm)
25623 {
25624 pgd_t *pgd;
25625- pmd_t *pmds[PREALLOCATED_PMDS];
25626+ pxd_t *pxds[PREALLOCATED_PXDS];
25627
25628 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25629
25630@@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25631
25632 mm->pgd = pgd;
25633
25634- if (preallocate_pmds(pmds) != 0)
25635+ if (preallocate_pxds(pxds) != 0)
25636 goto out_free_pgd;
25637
25638 if (paravirt_pgd_alloc(mm) != 0)
25639- goto out_free_pmds;
25640+ goto out_free_pxds;
25641
25642 /*
25643 * Make sure that pre-populating the pmds is atomic with
25644@@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25645 spin_lock(&pgd_lock);
25646
25647 pgd_ctor(mm, pgd);
25648- pgd_prepopulate_pmd(mm, pgd, pmds);
25649+ pgd_prepopulate_pxd(mm, pgd, pxds);
25650
25651 spin_unlock(&pgd_lock);
25652
25653 return pgd;
25654
25655-out_free_pmds:
25656- free_pmds(pmds);
25657+out_free_pxds:
25658+ free_pxds(pxds);
25659 out_free_pgd:
25660 free_page((unsigned long)pgd);
25661 out:
25662@@ -295,7 +356,7 @@ out:
25663
25664 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25665 {
25666- pgd_mop_up_pmds(mm, pgd);
25667+ pgd_mop_up_pxds(mm, pgd);
25668 pgd_dtor(pgd);
25669 paravirt_pgd_free(mm, pgd);
25670 free_page((unsigned long)pgd);
25671diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25672index a69bcb8..19068ab 100644
25673--- a/arch/x86/mm/pgtable_32.c
25674+++ b/arch/x86/mm/pgtable_32.c
25675@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25676 return;
25677 }
25678 pte = pte_offset_kernel(pmd, vaddr);
25679+
25680+ pax_open_kernel();
25681 if (pte_val(pteval))
25682 set_pte_at(&init_mm, vaddr, pte, pteval);
25683 else
25684 pte_clear(&init_mm, vaddr, pte);
25685+ pax_close_kernel();
25686
25687 /*
25688 * It's enough to flush this one mapping.
25689diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25690index 410531d..0f16030 100644
25691--- a/arch/x86/mm/setup_nx.c
25692+++ b/arch/x86/mm/setup_nx.c
25693@@ -5,8 +5,10 @@
25694 #include <asm/pgtable.h>
25695 #include <asm/proto.h>
25696
25697+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25698 static int disable_nx __cpuinitdata;
25699
25700+#ifndef CONFIG_PAX_PAGEEXEC
25701 /*
25702 * noexec = on|off
25703 *
25704@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25705 return 0;
25706 }
25707 early_param("noexec", noexec_setup);
25708+#endif
25709+
25710+#endif
25711
25712 void __cpuinit x86_configure_nx(void)
25713 {
25714+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25715 if (cpu_has_nx && !disable_nx)
25716 __supported_pte_mask |= _PAGE_NX;
25717 else
25718+#endif
25719 __supported_pte_mask &= ~_PAGE_NX;
25720 }
25721
25722diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25723index 5e57e11..64874249 100644
25724--- a/arch/x86/mm/tlb.c
25725+++ b/arch/x86/mm/tlb.c
25726@@ -66,7 +66,11 @@ void leave_mm(int cpu)
25727 BUG();
25728 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
25729 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
25730+
25731+#ifndef CONFIG_PAX_PER_CPU_PGD
25732 load_cr3(swapper_pg_dir);
25733+#endif
25734+
25735 }
25736 }
25737 EXPORT_SYMBOL_GPL(leave_mm);
25738diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25739index 877b9a1..a8ecf42 100644
25740--- a/arch/x86/net/bpf_jit.S
25741+++ b/arch/x86/net/bpf_jit.S
25742@@ -9,6 +9,7 @@
25743 */
25744 #include <linux/linkage.h>
25745 #include <asm/dwarf2.h>
25746+#include <asm/alternative-asm.h>
25747
25748 /*
25749 * Calling convention :
25750@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
25751 jle bpf_slow_path_word
25752 mov (SKBDATA,%rsi),%eax
25753 bswap %eax /* ntohl() */
25754+ pax_force_retaddr
25755 ret
25756
25757 sk_load_half:
25758@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
25759 jle bpf_slow_path_half
25760 movzwl (SKBDATA,%rsi),%eax
25761 rol $8,%ax # ntohs()
25762+ pax_force_retaddr
25763 ret
25764
25765 sk_load_byte:
25766@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
25767 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25768 jle bpf_slow_path_byte
25769 movzbl (SKBDATA,%rsi),%eax
25770+ pax_force_retaddr
25771 ret
25772
25773 /**
25774@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
25775 movzbl (SKBDATA,%rsi),%ebx
25776 and $15,%bl
25777 shl $2,%bl
25778+ pax_force_retaddr
25779 ret
25780
25781 /* rsi contains offset and can be scratched */
25782@@ -109,6 +114,7 @@ bpf_slow_path_word:
25783 js bpf_error
25784 mov -12(%rbp),%eax
25785 bswap %eax
25786+ pax_force_retaddr
25787 ret
25788
25789 bpf_slow_path_half:
25790@@ -117,12 +123,14 @@ bpf_slow_path_half:
25791 mov -12(%rbp),%ax
25792 rol $8,%ax
25793 movzwl %ax,%eax
25794+ pax_force_retaddr
25795 ret
25796
25797 bpf_slow_path_byte:
25798 bpf_slow_path_common(1)
25799 js bpf_error
25800 movzbl -12(%rbp),%eax
25801+ pax_force_retaddr
25802 ret
25803
25804 bpf_slow_path_byte_msh:
25805@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
25806 and $15,%al
25807 shl $2,%al
25808 xchg %eax,%ebx
25809+ pax_force_retaddr
25810 ret
25811
25812 #define sk_negative_common(SIZE) \
25813@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
25814 sk_negative_common(4)
25815 mov (%rax), %eax
25816 bswap %eax
25817+ pax_force_retaddr
25818 ret
25819
25820 bpf_slow_path_half_neg:
25821@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
25822 mov (%rax),%ax
25823 rol $8,%ax
25824 movzwl %ax,%eax
25825+ pax_force_retaddr
25826 ret
25827
25828 bpf_slow_path_byte_neg:
25829@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
25830 .globl sk_load_byte_negative_offset
25831 sk_negative_common(1)
25832 movzbl (%rax), %eax
25833+ pax_force_retaddr
25834 ret
25835
25836 bpf_slow_path_byte_msh_neg:
25837@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
25838 and $15,%al
25839 shl $2,%al
25840 xchg %eax,%ebx
25841+ pax_force_retaddr
25842 ret
25843
25844 bpf_error:
25845@@ -197,4 +210,5 @@ bpf_error:
25846 xor %eax,%eax
25847 mov -8(%rbp),%rbx
25848 leaveq
25849+ pax_force_retaddr
25850 ret
25851diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
25852index 0597f95..a12c36e 100644
25853--- a/arch/x86/net/bpf_jit_comp.c
25854+++ b/arch/x86/net/bpf_jit_comp.c
25855@@ -120,6 +120,11 @@ static inline void bpf_flush_icache(void *start, void *end)
25856 set_fs(old_fs);
25857 }
25858
25859+struct bpf_jit_work {
25860+ struct work_struct work;
25861+ void *image;
25862+};
25863+
25864 #define CHOOSE_LOAD_FUNC(K, func) \
25865 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
25866
25867@@ -146,6 +151,10 @@ void bpf_jit_compile(struct sk_filter *fp)
25868 if (addrs == NULL)
25869 return;
25870
25871+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
25872+ if (!fp->work)
25873+ goto out;
25874+
25875 /* Before first pass, make a rough estimation of addrs[]
25876 * each bpf instruction is translated to less than 64 bytes
25877 */
25878@@ -589,17 +598,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25879 break;
25880 default:
25881 /* hmm, too complex filter, give up with jit compiler */
25882- goto out;
25883+ goto error;
25884 }
25885 ilen = prog - temp;
25886 if (image) {
25887 if (unlikely(proglen + ilen > oldproglen)) {
25888 pr_err("bpb_jit_compile fatal error\n");
25889- kfree(addrs);
25890- module_free(NULL, image);
25891- return;
25892+ module_free_exec(NULL, image);
25893+ goto error;
25894 }
25895+ pax_open_kernel();
25896 memcpy(image + proglen, temp, ilen);
25897+ pax_close_kernel();
25898 }
25899 proglen += ilen;
25900 addrs[i] = proglen;
25901@@ -620,11 +630,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25902 break;
25903 }
25904 if (proglen == oldproglen) {
25905- image = module_alloc(max_t(unsigned int,
25906- proglen,
25907- sizeof(struct work_struct)));
25908+ image = module_alloc_exec(proglen);
25909 if (!image)
25910- goto out;
25911+ goto error;
25912 }
25913 oldproglen = proglen;
25914 }
25915@@ -640,7 +648,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25916 bpf_flush_icache(image, image + proglen);
25917
25918 fp->bpf_func = (void *)image;
25919- }
25920+ } else
25921+error:
25922+ kfree(fp->work);
25923+
25924 out:
25925 kfree(addrs);
25926 return;
25927@@ -648,18 +659,20 @@ out:
25928
25929 static void jit_free_defer(struct work_struct *arg)
25930 {
25931- module_free(NULL, arg);
25932+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
25933+ kfree(arg);
25934 }
25935
25936 /* run from softirq, we must use a work_struct to call
25937- * module_free() from process context
25938+ * module_free_exec() from process context
25939 */
25940 void bpf_jit_free(struct sk_filter *fp)
25941 {
25942 if (fp->bpf_func != sk_run_filter) {
25943- struct work_struct *work = (struct work_struct *)fp->bpf_func;
25944+ struct work_struct *work = &fp->work->work;
25945
25946 INIT_WORK(work, jit_free_defer);
25947+ fp->work->image = fp->bpf_func;
25948 schedule_work(work);
25949 }
25950 }
25951diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
25952index d6aa6e8..266395a 100644
25953--- a/arch/x86/oprofile/backtrace.c
25954+++ b/arch/x86/oprofile/backtrace.c
25955@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
25956 struct stack_frame_ia32 *fp;
25957 unsigned long bytes;
25958
25959- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25960+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25961 if (bytes != sizeof(bufhead))
25962 return NULL;
25963
25964- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
25965+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
25966
25967 oprofile_add_trace(bufhead[0].return_address);
25968
25969@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
25970 struct stack_frame bufhead[2];
25971 unsigned long bytes;
25972
25973- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25974+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25975 if (bytes != sizeof(bufhead))
25976 return NULL;
25977
25978@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
25979 {
25980 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
25981
25982- if (!user_mode_vm(regs)) {
25983+ if (!user_mode(regs)) {
25984 unsigned long stack = kernel_stack_pointer(regs);
25985 if (depth)
25986 dump_trace(NULL, regs, (unsigned long *)stack, 0,
25987diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
25988index 140942f..8a5cc55 100644
25989--- a/arch/x86/pci/mrst.c
25990+++ b/arch/x86/pci/mrst.c
25991@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
25992 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
25993 pci_mmcfg_late_init();
25994 pcibios_enable_irq = mrst_pci_irq_enable;
25995- pci_root_ops = pci_mrst_ops;
25996+ pax_open_kernel();
25997+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
25998+ pax_close_kernel();
25999 pci_soc_mode = 1;
26000 /* Continue with standard init */
26001 return 1;
26002diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26003index da8fe05..7ee6704 100644
26004--- a/arch/x86/pci/pcbios.c
26005+++ b/arch/x86/pci/pcbios.c
26006@@ -79,50 +79,93 @@ union bios32 {
26007 static struct {
26008 unsigned long address;
26009 unsigned short segment;
26010-} bios32_indirect = { 0, __KERNEL_CS };
26011+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26012
26013 /*
26014 * Returns the entry point for the given service, NULL on error
26015 */
26016
26017-static unsigned long bios32_service(unsigned long service)
26018+static unsigned long __devinit bios32_service(unsigned long service)
26019 {
26020 unsigned char return_code; /* %al */
26021 unsigned long address; /* %ebx */
26022 unsigned long length; /* %ecx */
26023 unsigned long entry; /* %edx */
26024 unsigned long flags;
26025+ struct desc_struct d, *gdt;
26026
26027 local_irq_save(flags);
26028- __asm__("lcall *(%%edi); cld"
26029+
26030+ gdt = get_cpu_gdt_table(smp_processor_id());
26031+
26032+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26033+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26034+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26035+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26036+
26037+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26038 : "=a" (return_code),
26039 "=b" (address),
26040 "=c" (length),
26041 "=d" (entry)
26042 : "0" (service),
26043 "1" (0),
26044- "D" (&bios32_indirect));
26045+ "D" (&bios32_indirect),
26046+ "r"(__PCIBIOS_DS)
26047+ : "memory");
26048+
26049+ pax_open_kernel();
26050+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26051+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26052+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26053+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26054+ pax_close_kernel();
26055+
26056 local_irq_restore(flags);
26057
26058 switch (return_code) {
26059- case 0:
26060- return address + entry;
26061- case 0x80: /* Not present */
26062- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26063- return 0;
26064- default: /* Shouldn't happen */
26065- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26066- service, return_code);
26067+ case 0: {
26068+ int cpu;
26069+ unsigned char flags;
26070+
26071+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26072+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26073+ printk(KERN_WARNING "bios32_service: not valid\n");
26074 return 0;
26075+ }
26076+ address = address + PAGE_OFFSET;
26077+ length += 16UL; /* some BIOSs underreport this... */
26078+ flags = 4;
26079+ if (length >= 64*1024*1024) {
26080+ length >>= PAGE_SHIFT;
26081+ flags |= 8;
26082+ }
26083+
26084+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26085+ gdt = get_cpu_gdt_table(cpu);
26086+ pack_descriptor(&d, address, length, 0x9b, flags);
26087+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26088+ pack_descriptor(&d, address, length, 0x93, flags);
26089+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26090+ }
26091+ return entry;
26092+ }
26093+ case 0x80: /* Not present */
26094+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26095+ return 0;
26096+ default: /* Shouldn't happen */
26097+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26098+ service, return_code);
26099+ return 0;
26100 }
26101 }
26102
26103 static struct {
26104 unsigned long address;
26105 unsigned short segment;
26106-} pci_indirect = { 0, __KERNEL_CS };
26107+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26108
26109-static int pci_bios_present;
26110+static int pci_bios_present __read_only;
26111
26112 static int __devinit check_pcibios(void)
26113 {
26114@@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26115 unsigned long flags, pcibios_entry;
26116
26117 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26118- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26119+ pci_indirect.address = pcibios_entry;
26120
26121 local_irq_save(flags);
26122- __asm__(
26123- "lcall *(%%edi); cld\n\t"
26124+ __asm__("movw %w6, %%ds\n\t"
26125+ "lcall *%%ss:(%%edi); cld\n\t"
26126+ "push %%ss\n\t"
26127+ "pop %%ds\n\t"
26128 "jc 1f\n\t"
26129 "xor %%ah, %%ah\n"
26130 "1:"
26131@@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26132 "=b" (ebx),
26133 "=c" (ecx)
26134 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26135- "D" (&pci_indirect)
26136+ "D" (&pci_indirect),
26137+ "r" (__PCIBIOS_DS)
26138 : "memory");
26139 local_irq_restore(flags);
26140
26141@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26142
26143 switch (len) {
26144 case 1:
26145- __asm__("lcall *(%%esi); cld\n\t"
26146+ __asm__("movw %w6, %%ds\n\t"
26147+ "lcall *%%ss:(%%esi); cld\n\t"
26148+ "push %%ss\n\t"
26149+ "pop %%ds\n\t"
26150 "jc 1f\n\t"
26151 "xor %%ah, %%ah\n"
26152 "1:"
26153@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26154 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26155 "b" (bx),
26156 "D" ((long)reg),
26157- "S" (&pci_indirect));
26158+ "S" (&pci_indirect),
26159+ "r" (__PCIBIOS_DS));
26160 /*
26161 * Zero-extend the result beyond 8 bits, do not trust the
26162 * BIOS having done it:
26163@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26164 *value &= 0xff;
26165 break;
26166 case 2:
26167- __asm__("lcall *(%%esi); cld\n\t"
26168+ __asm__("movw %w6, %%ds\n\t"
26169+ "lcall *%%ss:(%%esi); cld\n\t"
26170+ "push %%ss\n\t"
26171+ "pop %%ds\n\t"
26172 "jc 1f\n\t"
26173 "xor %%ah, %%ah\n"
26174 "1:"
26175@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26176 : "1" (PCIBIOS_READ_CONFIG_WORD),
26177 "b" (bx),
26178 "D" ((long)reg),
26179- "S" (&pci_indirect));
26180+ "S" (&pci_indirect),
26181+ "r" (__PCIBIOS_DS));
26182 /*
26183 * Zero-extend the result beyond 16 bits, do not trust the
26184 * BIOS having done it:
26185@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26186 *value &= 0xffff;
26187 break;
26188 case 4:
26189- __asm__("lcall *(%%esi); cld\n\t"
26190+ __asm__("movw %w6, %%ds\n\t"
26191+ "lcall *%%ss:(%%esi); cld\n\t"
26192+ "push %%ss\n\t"
26193+ "pop %%ds\n\t"
26194 "jc 1f\n\t"
26195 "xor %%ah, %%ah\n"
26196 "1:"
26197@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26198 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26199 "b" (bx),
26200 "D" ((long)reg),
26201- "S" (&pci_indirect));
26202+ "S" (&pci_indirect),
26203+ "r" (__PCIBIOS_DS));
26204 break;
26205 }
26206
26207@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26208
26209 switch (len) {
26210 case 1:
26211- __asm__("lcall *(%%esi); cld\n\t"
26212+ __asm__("movw %w6, %%ds\n\t"
26213+ "lcall *%%ss:(%%esi); cld\n\t"
26214+ "push %%ss\n\t"
26215+ "pop %%ds\n\t"
26216 "jc 1f\n\t"
26217 "xor %%ah, %%ah\n"
26218 "1:"
26219@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26220 "c" (value),
26221 "b" (bx),
26222 "D" ((long)reg),
26223- "S" (&pci_indirect));
26224+ "S" (&pci_indirect),
26225+ "r" (__PCIBIOS_DS));
26226 break;
26227 case 2:
26228- __asm__("lcall *(%%esi); cld\n\t"
26229+ __asm__("movw %w6, %%ds\n\t"
26230+ "lcall *%%ss:(%%esi); cld\n\t"
26231+ "push %%ss\n\t"
26232+ "pop %%ds\n\t"
26233 "jc 1f\n\t"
26234 "xor %%ah, %%ah\n"
26235 "1:"
26236@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26237 "c" (value),
26238 "b" (bx),
26239 "D" ((long)reg),
26240- "S" (&pci_indirect));
26241+ "S" (&pci_indirect),
26242+ "r" (__PCIBIOS_DS));
26243 break;
26244 case 4:
26245- __asm__("lcall *(%%esi); cld\n\t"
26246+ __asm__("movw %w6, %%ds\n\t"
26247+ "lcall *%%ss:(%%esi); cld\n\t"
26248+ "push %%ss\n\t"
26249+ "pop %%ds\n\t"
26250 "jc 1f\n\t"
26251 "xor %%ah, %%ah\n"
26252 "1:"
26253@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26254 "c" (value),
26255 "b" (bx),
26256 "D" ((long)reg),
26257- "S" (&pci_indirect));
26258+ "S" (&pci_indirect),
26259+ "r" (__PCIBIOS_DS));
26260 break;
26261 }
26262
26263@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26264
26265 DBG("PCI: Fetching IRQ routing table... ");
26266 __asm__("push %%es\n\t"
26267+ "movw %w8, %%ds\n\t"
26268 "push %%ds\n\t"
26269 "pop %%es\n\t"
26270- "lcall *(%%esi); cld\n\t"
26271+ "lcall *%%ss:(%%esi); cld\n\t"
26272 "pop %%es\n\t"
26273+ "push %%ss\n\t"
26274+ "pop %%ds\n"
26275 "jc 1f\n\t"
26276 "xor %%ah, %%ah\n"
26277 "1:"
26278@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26279 "1" (0),
26280 "D" ((long) &opt),
26281 "S" (&pci_indirect),
26282- "m" (opt)
26283+ "m" (opt),
26284+ "r" (__PCIBIOS_DS)
26285 : "memory");
26286 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26287 if (ret & 0xff00)
26288@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26289 {
26290 int ret;
26291
26292- __asm__("lcall *(%%esi); cld\n\t"
26293+ __asm__("movw %w5, %%ds\n\t"
26294+ "lcall *%%ss:(%%esi); cld\n\t"
26295+ "push %%ss\n\t"
26296+ "pop %%ds\n"
26297 "jc 1f\n\t"
26298 "xor %%ah, %%ah\n"
26299 "1:"
26300@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26301 : "0" (PCIBIOS_SET_PCI_HW_INT),
26302 "b" ((dev->bus->number << 8) | dev->devfn),
26303 "c" ((irq << 8) | (pin + 10)),
26304- "S" (&pci_indirect));
26305+ "S" (&pci_indirect),
26306+ "r" (__PCIBIOS_DS));
26307 return !(ret & 0xff00);
26308 }
26309 EXPORT_SYMBOL(pcibios_set_irq_routing);
26310diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26311index 40e4469..1ab536e 100644
26312--- a/arch/x86/platform/efi/efi_32.c
26313+++ b/arch/x86/platform/efi/efi_32.c
26314@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26315 {
26316 struct desc_ptr gdt_descr;
26317
26318+#ifdef CONFIG_PAX_KERNEXEC
26319+ struct desc_struct d;
26320+#endif
26321+
26322 local_irq_save(efi_rt_eflags);
26323
26324 load_cr3(initial_page_table);
26325 __flush_tlb_all();
26326
26327+#ifdef CONFIG_PAX_KERNEXEC
26328+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26329+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26330+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26331+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26332+#endif
26333+
26334 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26335 gdt_descr.size = GDT_SIZE - 1;
26336 load_gdt(&gdt_descr);
26337@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26338 {
26339 struct desc_ptr gdt_descr;
26340
26341+#ifdef CONFIG_PAX_KERNEXEC
26342+ struct desc_struct d;
26343+
26344+ memset(&d, 0, sizeof d);
26345+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26346+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26347+#endif
26348+
26349 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26350 gdt_descr.size = GDT_SIZE - 1;
26351 load_gdt(&gdt_descr);
26352diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26353index fbe66e6..eae5e38 100644
26354--- a/arch/x86/platform/efi/efi_stub_32.S
26355+++ b/arch/x86/platform/efi/efi_stub_32.S
26356@@ -6,7 +6,9 @@
26357 */
26358
26359 #include <linux/linkage.h>
26360+#include <linux/init.h>
26361 #include <asm/page_types.h>
26362+#include <asm/segment.h>
26363
26364 /*
26365 * efi_call_phys(void *, ...) is a function with variable parameters.
26366@@ -20,7 +22,7 @@
26367 * service functions will comply with gcc calling convention, too.
26368 */
26369
26370-.text
26371+__INIT
26372 ENTRY(efi_call_phys)
26373 /*
26374 * 0. The function can only be called in Linux kernel. So CS has been
26375@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
26376 * The mapping of lower virtual memory has been created in prelog and
26377 * epilog.
26378 */
26379- movl $1f, %edx
26380- subl $__PAGE_OFFSET, %edx
26381- jmp *%edx
26382+#ifdef CONFIG_PAX_KERNEXEC
26383+ movl $(__KERNEXEC_EFI_DS), %edx
26384+ mov %edx, %ds
26385+ mov %edx, %es
26386+ mov %edx, %ss
26387+ addl $2f,(1f)
26388+ ljmp *(1f)
26389+
26390+__INITDATA
26391+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
26392+.previous
26393+
26394+2:
26395+ subl $2b,(1b)
26396+#else
26397+ jmp 1f-__PAGE_OFFSET
26398 1:
26399+#endif
26400
26401 /*
26402 * 2. Now on the top of stack is the return
26403@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
26404 * parameter 2, ..., param n. To make things easy, we save the return
26405 * address of efi_call_phys in a global variable.
26406 */
26407- popl %edx
26408- movl %edx, saved_return_addr
26409- /* get the function pointer into ECX*/
26410- popl %ecx
26411- movl %ecx, efi_rt_function_ptr
26412- movl $2f, %edx
26413- subl $__PAGE_OFFSET, %edx
26414- pushl %edx
26415+ popl (saved_return_addr)
26416+ popl (efi_rt_function_ptr)
26417
26418 /*
26419 * 3. Clear PG bit in %CR0.
26420@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
26421 /*
26422 * 5. Call the physical function.
26423 */
26424- jmp *%ecx
26425+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
26426
26427-2:
26428 /*
26429 * 6. After EFI runtime service returns, control will return to
26430 * following instruction. We'd better readjust stack pointer first.
26431@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
26432 movl %cr0, %edx
26433 orl $0x80000000, %edx
26434 movl %edx, %cr0
26435- jmp 1f
26436-1:
26437+
26438 /*
26439 * 8. Now restore the virtual mode from flat mode by
26440 * adding EIP with PAGE_OFFSET.
26441 */
26442- movl $1f, %edx
26443- jmp *%edx
26444+#ifdef CONFIG_PAX_KERNEXEC
26445+ movl $(__KERNEL_DS), %edx
26446+ mov %edx, %ds
26447+ mov %edx, %es
26448+ mov %edx, %ss
26449+ ljmp $(__KERNEL_CS),$1f
26450+#else
26451+ jmp 1f+__PAGE_OFFSET
26452+#endif
26453 1:
26454
26455 /*
26456 * 9. Balance the stack. And because EAX contain the return value,
26457 * we'd better not clobber it.
26458 */
26459- leal efi_rt_function_ptr, %edx
26460- movl (%edx), %ecx
26461- pushl %ecx
26462+ pushl (efi_rt_function_ptr)
26463
26464 /*
26465- * 10. Push the saved return address onto the stack and return.
26466+ * 10. Return to the saved return address.
26467 */
26468- leal saved_return_addr, %edx
26469- movl (%edx), %ecx
26470- pushl %ecx
26471- ret
26472+ jmpl *(saved_return_addr)
26473 ENDPROC(efi_call_phys)
26474 .previous
26475
26476-.data
26477+__INITDATA
26478 saved_return_addr:
26479 .long 0
26480 efi_rt_function_ptr:
26481diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26482index 4c07cca..2c8427d 100644
26483--- a/arch/x86/platform/efi/efi_stub_64.S
26484+++ b/arch/x86/platform/efi/efi_stub_64.S
26485@@ -7,6 +7,7 @@
26486 */
26487
26488 #include <linux/linkage.h>
26489+#include <asm/alternative-asm.h>
26490
26491 #define SAVE_XMM \
26492 mov %rsp, %rax; \
26493@@ -40,6 +41,7 @@ ENTRY(efi_call0)
26494 call *%rdi
26495 addq $32, %rsp
26496 RESTORE_XMM
26497+ pax_force_retaddr 0, 1
26498 ret
26499 ENDPROC(efi_call0)
26500
26501@@ -50,6 +52,7 @@ ENTRY(efi_call1)
26502 call *%rdi
26503 addq $32, %rsp
26504 RESTORE_XMM
26505+ pax_force_retaddr 0, 1
26506 ret
26507 ENDPROC(efi_call1)
26508
26509@@ -60,6 +63,7 @@ ENTRY(efi_call2)
26510 call *%rdi
26511 addq $32, %rsp
26512 RESTORE_XMM
26513+ pax_force_retaddr 0, 1
26514 ret
26515 ENDPROC(efi_call2)
26516
26517@@ -71,6 +75,7 @@ ENTRY(efi_call3)
26518 call *%rdi
26519 addq $32, %rsp
26520 RESTORE_XMM
26521+ pax_force_retaddr 0, 1
26522 ret
26523 ENDPROC(efi_call3)
26524
26525@@ -83,6 +88,7 @@ ENTRY(efi_call4)
26526 call *%rdi
26527 addq $32, %rsp
26528 RESTORE_XMM
26529+ pax_force_retaddr 0, 1
26530 ret
26531 ENDPROC(efi_call4)
26532
26533@@ -96,6 +102,7 @@ ENTRY(efi_call5)
26534 call *%rdi
26535 addq $48, %rsp
26536 RESTORE_XMM
26537+ pax_force_retaddr 0, 1
26538 ret
26539 ENDPROC(efi_call5)
26540
26541@@ -112,5 +119,6 @@ ENTRY(efi_call6)
26542 call *%rdi
26543 addq $48, %rsp
26544 RESTORE_XMM
26545+ pax_force_retaddr 0, 1
26546 ret
26547 ENDPROC(efi_call6)
26548diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26549index fd41a92..9c33628 100644
26550--- a/arch/x86/platform/mrst/mrst.c
26551+++ b/arch/x86/platform/mrst/mrst.c
26552@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26553 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26554 int sfi_mrtc_num;
26555
26556-static void mrst_power_off(void)
26557+static __noreturn void mrst_power_off(void)
26558 {
26559+ BUG();
26560 }
26561
26562-static void mrst_reboot(void)
26563+static __noreturn void mrst_reboot(void)
26564 {
26565 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26566+ BUG();
26567 }
26568
26569 /* parse all the mtimer info to a static mtimer array */
26570diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26571index 218cdb1..fd55c08 100644
26572--- a/arch/x86/power/cpu.c
26573+++ b/arch/x86/power/cpu.c
26574@@ -132,7 +132,7 @@ static void do_fpu_end(void)
26575 static void fix_processor_context(void)
26576 {
26577 int cpu = smp_processor_id();
26578- struct tss_struct *t = &per_cpu(init_tss, cpu);
26579+ struct tss_struct *t = init_tss + cpu;
26580
26581 set_tss_desc(cpu, t); /*
26582 * This just modifies memory; should not be
26583@@ -142,7 +142,9 @@ static void fix_processor_context(void)
26584 */
26585
26586 #ifdef CONFIG_X86_64
26587+ pax_open_kernel();
26588 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26589+ pax_close_kernel();
26590
26591 syscall_init(); /* This sets MSR_*STAR and related */
26592 #endif
26593diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
26594index cbca565..35ce1d7 100644
26595--- a/arch/x86/realmode/init.c
26596+++ b/arch/x86/realmode/init.c
26597@@ -62,7 +62,13 @@ void __init setup_real_mode(void)
26598 __va(real_mode_header->trampoline_header);
26599
26600 #ifdef CONFIG_X86_32
26601- trampoline_header->start = __pa(startup_32_smp);
26602+ trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
26603+
26604+#ifdef CONFIG_PAX_KERNEXEC
26605+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
26606+#endif
26607+
26608+ trampoline_header->boot_cs = __BOOT_CS;
26609 trampoline_header->gdt_limit = __BOOT_DS + 7;
26610 trampoline_header->gdt_base = __pa(boot_gdt);
26611 #else
26612diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
26613index 5b84a2d..a004393 100644
26614--- a/arch/x86/realmode/rm/Makefile
26615+++ b/arch/x86/realmode/rm/Makefile
26616@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
26617 $(call cc-option, -fno-unit-at-a-time)) \
26618 $(call cc-option, -fno-stack-protector) \
26619 $(call cc-option, -mpreferred-stack-boundary=2)
26620+ifdef CONSTIFY_PLUGIN
26621+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
26622+endif
26623 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
26624 GCOV_PROFILE := n
26625diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
26626index c1b2791..f9e31c7 100644
26627--- a/arch/x86/realmode/rm/trampoline_32.S
26628+++ b/arch/x86/realmode/rm/trampoline_32.S
26629@@ -25,6 +25,12 @@
26630 #include <asm/page_types.h>
26631 #include "realmode.h"
26632
26633+#ifdef CONFIG_PAX_KERNEXEC
26634+#define ta(X) (X)
26635+#else
26636+#define ta(X) (pa_ ## X)
26637+#endif
26638+
26639 .text
26640 .code16
26641
26642@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
26643
26644 cli # We should be safe anyway
26645
26646- movl tr_start, %eax # where we need to go
26647-
26648 movl $0xA5A5A5A5, trampoline_status
26649 # write marker for master knows we're running
26650
26651@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
26652 movw $1, %dx # protected mode (PE) bit
26653 lmsw %dx # into protected mode
26654
26655- ljmpl $__BOOT_CS, $pa_startup_32
26656+ ljmpl *(trampoline_header)
26657
26658 .section ".text32","ax"
26659 .code32
26660@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
26661 .balign 8
26662 GLOBAL(trampoline_header)
26663 tr_start: .space 4
26664- tr_gdt_pad: .space 2
26665+ tr_boot_cs: .space 2
26666 tr_gdt: .space 6
26667 END(trampoline_header)
26668
26669diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
26670index bb360dc..3e5945f 100644
26671--- a/arch/x86/realmode/rm/trampoline_64.S
26672+++ b/arch/x86/realmode/rm/trampoline_64.S
26673@@ -107,7 +107,7 @@ ENTRY(startup_32)
26674 wrmsr
26675
26676 # Enable paging and in turn activate Long Mode
26677- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
26678+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
26679 movl %eax, %cr0
26680
26681 /*
26682diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
26683index 5a1847d..deccb30 100644
26684--- a/arch/x86/tools/relocs.c
26685+++ b/arch/x86/tools/relocs.c
26686@@ -12,10 +12,13 @@
26687 #include <regex.h>
26688 #include <tools/le_byteshift.h>
26689
26690+#include "../../../include/generated/autoconf.h"
26691+
26692 static void die(char *fmt, ...);
26693
26694 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
26695 static Elf32_Ehdr ehdr;
26696+static Elf32_Phdr *phdr;
26697 static unsigned long reloc_count, reloc_idx;
26698 static unsigned long *relocs;
26699 static unsigned long reloc16_count, reloc16_idx;
26700@@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
26701 }
26702 }
26703
26704+static void read_phdrs(FILE *fp)
26705+{
26706+ unsigned int i;
26707+
26708+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
26709+ if (!phdr) {
26710+ die("Unable to allocate %d program headers\n",
26711+ ehdr.e_phnum);
26712+ }
26713+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
26714+ die("Seek to %d failed: %s\n",
26715+ ehdr.e_phoff, strerror(errno));
26716+ }
26717+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
26718+ die("Cannot read ELF program headers: %s\n",
26719+ strerror(errno));
26720+ }
26721+ for(i = 0; i < ehdr.e_phnum; i++) {
26722+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
26723+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
26724+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
26725+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
26726+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
26727+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
26728+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
26729+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
26730+ }
26731+
26732+}
26733+
26734 static void read_shdrs(FILE *fp)
26735 {
26736- int i;
26737+ unsigned int i;
26738 Elf32_Shdr shdr;
26739
26740 secs = calloc(ehdr.e_shnum, sizeof(struct section));
26741@@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
26742
26743 static void read_strtabs(FILE *fp)
26744 {
26745- int i;
26746+ unsigned int i;
26747 for (i = 0; i < ehdr.e_shnum; i++) {
26748 struct section *sec = &secs[i];
26749 if (sec->shdr.sh_type != SHT_STRTAB) {
26750@@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
26751
26752 static void read_symtabs(FILE *fp)
26753 {
26754- int i,j;
26755+ unsigned int i,j;
26756 for (i = 0; i < ehdr.e_shnum; i++) {
26757 struct section *sec = &secs[i];
26758 if (sec->shdr.sh_type != SHT_SYMTAB) {
26759@@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
26760 }
26761
26762
26763-static void read_relocs(FILE *fp)
26764+static void read_relocs(FILE *fp, int use_real_mode)
26765 {
26766- int i,j;
26767+ unsigned int i,j;
26768+ uint32_t base;
26769+
26770 for (i = 0; i < ehdr.e_shnum; i++) {
26771 struct section *sec = &secs[i];
26772 if (sec->shdr.sh_type != SHT_REL) {
26773@@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
26774 die("Cannot read symbol table: %s\n",
26775 strerror(errno));
26776 }
26777+ base = 0;
26778+
26779+#ifdef CONFIG_X86_32
26780+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
26781+ if (phdr[j].p_type != PT_LOAD )
26782+ continue;
26783+ 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)
26784+ continue;
26785+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
26786+ break;
26787+ }
26788+#endif
26789+
26790 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
26791 Elf32_Rel *rel = &sec->reltab[j];
26792- rel->r_offset = elf32_to_cpu(rel->r_offset);
26793+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
26794 rel->r_info = elf32_to_cpu(rel->r_info);
26795 }
26796 }
26797@@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
26798
26799 static void print_absolute_symbols(void)
26800 {
26801- int i;
26802+ unsigned int i;
26803 printf("Absolute symbols\n");
26804 printf(" Num: Value Size Type Bind Visibility Name\n");
26805 for (i = 0; i < ehdr.e_shnum; i++) {
26806 struct section *sec = &secs[i];
26807 char *sym_strtab;
26808- int j;
26809+ unsigned int j;
26810
26811 if (sec->shdr.sh_type != SHT_SYMTAB) {
26812 continue;
26813@@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
26814
26815 static void print_absolute_relocs(void)
26816 {
26817- int i, printed = 0;
26818+ unsigned int i, printed = 0;
26819
26820 for (i = 0; i < ehdr.e_shnum; i++) {
26821 struct section *sec = &secs[i];
26822 struct section *sec_applies, *sec_symtab;
26823 char *sym_strtab;
26824 Elf32_Sym *sh_symtab;
26825- int j;
26826+ unsigned int j;
26827 if (sec->shdr.sh_type != SHT_REL) {
26828 continue;
26829 }
26830@@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
26831 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26832 int use_real_mode)
26833 {
26834- int i;
26835+ unsigned int i;
26836 /* Walk through the relocations */
26837 for (i = 0; i < ehdr.e_shnum; i++) {
26838 char *sym_strtab;
26839 Elf32_Sym *sh_symtab;
26840 struct section *sec_applies, *sec_symtab;
26841- int j;
26842+ unsigned int j;
26843 struct section *sec = &secs[i];
26844
26845 if (sec->shdr.sh_type != SHT_REL) {
26846@@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26847 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
26848 r_type = ELF32_R_TYPE(rel->r_info);
26849
26850+ if (!use_real_mode) {
26851+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
26852+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
26853+ continue;
26854+
26855+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
26856+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
26857+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
26858+ continue;
26859+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
26860+ continue;
26861+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
26862+ continue;
26863+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
26864+ continue;
26865+#endif
26866+ }
26867+
26868 shn_abs = sym->st_shndx == SHN_ABS;
26869
26870 switch (r_type) {
26871@@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
26872
26873 static void emit_relocs(int as_text, int use_real_mode)
26874 {
26875- int i;
26876+ unsigned int i;
26877 /* Count how many relocations I have and allocate space for them. */
26878 reloc_count = 0;
26879 walk_relocs(count_reloc, use_real_mode);
26880@@ -808,10 +874,11 @@ int main(int argc, char **argv)
26881 fname, strerror(errno));
26882 }
26883 read_ehdr(fp);
26884+ read_phdrs(fp);
26885 read_shdrs(fp);
26886 read_strtabs(fp);
26887 read_symtabs(fp);
26888- read_relocs(fp);
26889+ read_relocs(fp, use_real_mode);
26890 if (show_absolute_syms) {
26891 print_absolute_symbols();
26892 return 0;
26893diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
26894index fd14be1..e3c79c0 100644
26895--- a/arch/x86/vdso/Makefile
26896+++ b/arch/x86/vdso/Makefile
26897@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
26898 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
26899 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
26900
26901-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26902+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26903 GCOV_PROFILE := n
26904
26905 #
26906diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
26907index 66e6d93..587f435 100644
26908--- a/arch/x86/vdso/vdso32-setup.c
26909+++ b/arch/x86/vdso/vdso32-setup.c
26910@@ -25,6 +25,7 @@
26911 #include <asm/tlbflush.h>
26912 #include <asm/vdso.h>
26913 #include <asm/proto.h>
26914+#include <asm/mman.h>
26915
26916 enum {
26917 VDSO_DISABLED = 0,
26918@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
26919 void enable_sep_cpu(void)
26920 {
26921 int cpu = get_cpu();
26922- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26923+ struct tss_struct *tss = init_tss + cpu;
26924
26925 if (!boot_cpu_has(X86_FEATURE_SEP)) {
26926 put_cpu();
26927@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
26928 gate_vma.vm_start = FIXADDR_USER_START;
26929 gate_vma.vm_end = FIXADDR_USER_END;
26930 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
26931- gate_vma.vm_page_prot = __P101;
26932+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
26933
26934 return 0;
26935 }
26936@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26937 if (compat)
26938 addr = VDSO_HIGH_BASE;
26939 else {
26940- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
26941+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
26942 if (IS_ERR_VALUE(addr)) {
26943 ret = addr;
26944 goto up_fail;
26945 }
26946 }
26947
26948- current->mm->context.vdso = (void *)addr;
26949+ current->mm->context.vdso = addr;
26950
26951 if (compat_uses_vma || !compat) {
26952 /*
26953@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26954 }
26955
26956 current_thread_info()->sysenter_return =
26957- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26958+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26959
26960 up_fail:
26961 if (ret)
26962- current->mm->context.vdso = NULL;
26963+ current->mm->context.vdso = 0;
26964
26965 up_write(&mm->mmap_sem);
26966
26967@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
26968
26969 const char *arch_vma_name(struct vm_area_struct *vma)
26970 {
26971- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26972+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26973 return "[vdso]";
26974+
26975+#ifdef CONFIG_PAX_SEGMEXEC
26976+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
26977+ return "[vdso]";
26978+#endif
26979+
26980 return NULL;
26981 }
26982
26983@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
26984 * Check to see if the corresponding task was created in compat vdso
26985 * mode.
26986 */
26987- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
26988+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
26989 return &gate_vma;
26990 return NULL;
26991 }
26992diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
26993index 00aaf04..4a26505 100644
26994--- a/arch/x86/vdso/vma.c
26995+++ b/arch/x86/vdso/vma.c
26996@@ -16,8 +16,6 @@
26997 #include <asm/vdso.h>
26998 #include <asm/page.h>
26999
27000-unsigned int __read_mostly vdso_enabled = 1;
27001-
27002 extern char vdso_start[], vdso_end[];
27003 extern unsigned short vdso_sync_cpuid;
27004
27005@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27006 * unaligned here as a result of stack start randomization.
27007 */
27008 addr = PAGE_ALIGN(addr);
27009- addr = align_addr(addr, NULL, ALIGN_VDSO);
27010
27011 return addr;
27012 }
27013@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
27014 unsigned size)
27015 {
27016 struct mm_struct *mm = current->mm;
27017- unsigned long addr;
27018+ unsigned long addr = 0;
27019 int ret;
27020
27021- if (!vdso_enabled)
27022- return 0;
27023-
27024 down_write(&mm->mmap_sem);
27025+
27026+#ifdef CONFIG_PAX_RANDMMAP
27027+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27028+#endif
27029+
27030 addr = vdso_addr(mm->start_stack, size);
27031+ addr = align_addr(addr, NULL, ALIGN_VDSO);
27032 addr = get_unmapped_area(NULL, addr, size, 0, 0);
27033 if (IS_ERR_VALUE(addr)) {
27034 ret = addr;
27035 goto up_fail;
27036 }
27037
27038- current->mm->context.vdso = (void *)addr;
27039+ mm->context.vdso = addr;
27040
27041 ret = install_special_mapping(mm, addr, size,
27042 VM_READ|VM_EXEC|
27043 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
27044 pages);
27045- if (ret) {
27046- current->mm->context.vdso = NULL;
27047- goto up_fail;
27048- }
27049+ if (ret)
27050+ mm->context.vdso = 0;
27051
27052 up_fail:
27053 up_write(&mm->mmap_sem);
27054@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27055 vdsox32_size);
27056 }
27057 #endif
27058-
27059-static __init int vdso_setup(char *s)
27060-{
27061- vdso_enabled = simple_strtoul(s, NULL, 0);
27062- return 0;
27063-}
27064-__setup("vdso=", vdso_setup);
27065diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27066index ff962d4..2bb5e83 100644
27067--- a/arch/x86/xen/enlighten.c
27068+++ b/arch/x86/xen/enlighten.c
27069@@ -97,8 +97,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27070
27071 struct shared_info xen_dummy_shared_info;
27072
27073-void *xen_initial_gdt;
27074-
27075 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27076 __read_mostly int xen_have_vector_callback;
27077 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27078@@ -1175,30 +1173,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27079 #endif
27080 };
27081
27082-static void xen_reboot(int reason)
27083+static __noreturn void xen_reboot(int reason)
27084 {
27085 struct sched_shutdown r = { .reason = reason };
27086
27087- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27088- BUG();
27089+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27090+ BUG();
27091 }
27092
27093-static void xen_restart(char *msg)
27094+static __noreturn void xen_restart(char *msg)
27095 {
27096 xen_reboot(SHUTDOWN_reboot);
27097 }
27098
27099-static void xen_emergency_restart(void)
27100+static __noreturn void xen_emergency_restart(void)
27101 {
27102 xen_reboot(SHUTDOWN_reboot);
27103 }
27104
27105-static void xen_machine_halt(void)
27106+static __noreturn void xen_machine_halt(void)
27107 {
27108 xen_reboot(SHUTDOWN_poweroff);
27109 }
27110
27111-static void xen_machine_power_off(void)
27112+static __noreturn void xen_machine_power_off(void)
27113 {
27114 if (pm_power_off)
27115 pm_power_off();
27116@@ -1301,7 +1299,17 @@ asmlinkage void __init xen_start_kernel(void)
27117 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27118
27119 /* Work out if we support NX */
27120- x86_configure_nx();
27121+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27122+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27123+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27124+ unsigned l, h;
27125+
27126+ __supported_pte_mask |= _PAGE_NX;
27127+ rdmsr(MSR_EFER, l, h);
27128+ l |= EFER_NX;
27129+ wrmsr(MSR_EFER, l, h);
27130+ }
27131+#endif
27132
27133 xen_setup_features();
27134
27135@@ -1332,13 +1340,6 @@ asmlinkage void __init xen_start_kernel(void)
27136
27137 machine_ops = xen_machine_ops;
27138
27139- /*
27140- * The only reliable way to retain the initial address of the
27141- * percpu gdt_page is to remember it here, so we can go and
27142- * mark it RW later, when the initial percpu area is freed.
27143- */
27144- xen_initial_gdt = &per_cpu(gdt_page, 0);
27145-
27146 xen_smp_init();
27147
27148 #ifdef CONFIG_ACPI_NUMA
27149diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27150index 3a73785..0d30df2 100644
27151--- a/arch/x86/xen/mmu.c
27152+++ b/arch/x86/xen/mmu.c
27153@@ -1738,6 +1738,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27154 convert_pfn_mfn(init_level4_pgt);
27155 convert_pfn_mfn(level3_ident_pgt);
27156 convert_pfn_mfn(level3_kernel_pgt);
27157+ convert_pfn_mfn(level3_vmalloc_start_pgt);
27158+ convert_pfn_mfn(level3_vmalloc_end_pgt);
27159+ convert_pfn_mfn(level3_vmemmap_pgt);
27160
27161 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27162 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27163@@ -1756,7 +1759,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27164 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27165 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27166 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27167+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27168+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27169+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27170 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27171+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27172 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27173 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27174
27175@@ -1940,6 +1947,7 @@ static void __init xen_post_allocator_init(void)
27176 pv_mmu_ops.set_pud = xen_set_pud;
27177 #if PAGETABLE_LEVELS == 4
27178 pv_mmu_ops.set_pgd = xen_set_pgd;
27179+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27180 #endif
27181
27182 /* This will work as long as patching hasn't happened yet
27183@@ -2021,6 +2029,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27184 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27185 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27186 .set_pgd = xen_set_pgd_hyper,
27187+ .set_pgd_batched = xen_set_pgd_hyper,
27188
27189 .alloc_pud = xen_alloc_pmd_init,
27190 .release_pud = xen_release_pmd_init,
27191diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27192index afb250d..627075f 100644
27193--- a/arch/x86/xen/smp.c
27194+++ b/arch/x86/xen/smp.c
27195@@ -231,11 +231,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27196 {
27197 BUG_ON(smp_processor_id() != 0);
27198 native_smp_prepare_boot_cpu();
27199-
27200- /* We've switched to the "real" per-cpu gdt, so make sure the
27201- old memory can be recycled */
27202- make_lowmem_page_readwrite(xen_initial_gdt);
27203-
27204 xen_filter_cpu_maps();
27205 xen_setup_vcpu_info_placement();
27206 }
27207@@ -302,12 +297,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27208 gdt = get_cpu_gdt_table(cpu);
27209
27210 ctxt->flags = VGCF_IN_KERNEL;
27211- ctxt->user_regs.ds = __USER_DS;
27212- ctxt->user_regs.es = __USER_DS;
27213+ ctxt->user_regs.ds = __KERNEL_DS;
27214+ ctxt->user_regs.es = __KERNEL_DS;
27215 ctxt->user_regs.ss = __KERNEL_DS;
27216 #ifdef CONFIG_X86_32
27217 ctxt->user_regs.fs = __KERNEL_PERCPU;
27218- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27219+ savesegment(gs, ctxt->user_regs.gs);
27220 #else
27221 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27222 #endif
27223@@ -357,13 +352,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
27224 int rc;
27225
27226 per_cpu(current_task, cpu) = idle;
27227+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
27228 #ifdef CONFIG_X86_32
27229 irq_ctx_init(cpu);
27230 #else
27231 clear_tsk_thread_flag(idle, TIF_FORK);
27232- per_cpu(kernel_stack, cpu) =
27233- (unsigned long)task_stack_page(idle) -
27234- KERNEL_STACK_OFFSET + THREAD_SIZE;
27235+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27236 #endif
27237 xen_setup_runstate_info(cpu);
27238 xen_setup_timer(cpu);
27239diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27240index f9643fc..602e8af 100644
27241--- a/arch/x86/xen/xen-asm_32.S
27242+++ b/arch/x86/xen/xen-asm_32.S
27243@@ -84,14 +84,14 @@ ENTRY(xen_iret)
27244 ESP_OFFSET=4 # bytes pushed onto stack
27245
27246 /*
27247- * Store vcpu_info pointer for easy access. Do it this way to
27248- * avoid having to reload %fs
27249+ * Store vcpu_info pointer for easy access.
27250 */
27251 #ifdef CONFIG_SMP
27252- GET_THREAD_INFO(%eax)
27253- movl TI_cpu(%eax), %eax
27254- movl __per_cpu_offset(,%eax,4), %eax
27255- mov xen_vcpu(%eax), %eax
27256+ push %fs
27257+ mov $(__KERNEL_PERCPU), %eax
27258+ mov %eax, %fs
27259+ mov PER_CPU_VAR(xen_vcpu), %eax
27260+ pop %fs
27261 #else
27262 movl xen_vcpu, %eax
27263 #endif
27264diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27265index aaa7291..3f77960 100644
27266--- a/arch/x86/xen/xen-head.S
27267+++ b/arch/x86/xen/xen-head.S
27268@@ -19,6 +19,17 @@ ENTRY(startup_xen)
27269 #ifdef CONFIG_X86_32
27270 mov %esi,xen_start_info
27271 mov $init_thread_union+THREAD_SIZE,%esp
27272+#ifdef CONFIG_SMP
27273+ movl $cpu_gdt_table,%edi
27274+ movl $__per_cpu_load,%eax
27275+ movw %ax,__KERNEL_PERCPU + 2(%edi)
27276+ rorl $16,%eax
27277+ movb %al,__KERNEL_PERCPU + 4(%edi)
27278+ movb %ah,__KERNEL_PERCPU + 7(%edi)
27279+ movl $__per_cpu_end - 1,%eax
27280+ subl $__per_cpu_start,%eax
27281+ movw %ax,__KERNEL_PERCPU + 0(%edi)
27282+#endif
27283 #else
27284 mov %rsi,xen_start_info
27285 mov $init_thread_union+THREAD_SIZE,%rsp
27286diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27287index 202d4c1..99b072a 100644
27288--- a/arch/x86/xen/xen-ops.h
27289+++ b/arch/x86/xen/xen-ops.h
27290@@ -10,8 +10,6 @@
27291 extern const char xen_hypervisor_callback[];
27292 extern const char xen_failsafe_callback[];
27293
27294-extern void *xen_initial_gdt;
27295-
27296 struct trap_info;
27297 void xen_copy_trap_info(struct trap_info *traps);
27298
27299diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27300index 525bd3d..ef888b1 100644
27301--- a/arch/xtensa/variants/dc232b/include/variant/core.h
27302+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27303@@ -119,9 +119,9 @@
27304 ----------------------------------------------------------------------*/
27305
27306 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27307-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27308 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27309 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27310+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27311
27312 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27313 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27314diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27315index 2f33760..835e50a 100644
27316--- a/arch/xtensa/variants/fsf/include/variant/core.h
27317+++ b/arch/xtensa/variants/fsf/include/variant/core.h
27318@@ -11,6 +11,7 @@
27319 #ifndef _XTENSA_CORE_H
27320 #define _XTENSA_CORE_H
27321
27322+#include <linux/const.h>
27323
27324 /****************************************************************************
27325 Parameters Useful for Any Code, USER or PRIVILEGED
27326@@ -112,9 +113,9 @@
27327 ----------------------------------------------------------------------*/
27328
27329 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27330-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27331 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27332 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27333+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27334
27335 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27336 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27337diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27338index af00795..2bb8105 100644
27339--- a/arch/xtensa/variants/s6000/include/variant/core.h
27340+++ b/arch/xtensa/variants/s6000/include/variant/core.h
27341@@ -11,6 +11,7 @@
27342 #ifndef _XTENSA_CORE_CONFIGURATION_H
27343 #define _XTENSA_CORE_CONFIGURATION_H
27344
27345+#include <linux/const.h>
27346
27347 /****************************************************************************
27348 Parameters Useful for Any Code, USER or PRIVILEGED
27349@@ -118,9 +119,9 @@
27350 ----------------------------------------------------------------------*/
27351
27352 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27353-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27354 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27355 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27356+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27357
27358 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27359 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27360diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27361index 58916af..9cb880b 100644
27362--- a/block/blk-iopoll.c
27363+++ b/block/blk-iopoll.c
27364@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27365 }
27366 EXPORT_SYMBOL(blk_iopoll_complete);
27367
27368-static void blk_iopoll_softirq(struct softirq_action *h)
27369+static void blk_iopoll_softirq(void)
27370 {
27371 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27372 int rearm = 0, budget = blk_iopoll_budget;
27373diff --git a/block/blk-map.c b/block/blk-map.c
27374index 623e1cd..ca1e109 100644
27375--- a/block/blk-map.c
27376+++ b/block/blk-map.c
27377@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27378 if (!len || !kbuf)
27379 return -EINVAL;
27380
27381- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27382+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27383 if (do_copy)
27384 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27385 else
27386diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27387index 467c8de..4bddc6d 100644
27388--- a/block/blk-softirq.c
27389+++ b/block/blk-softirq.c
27390@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27391 * Softirq action handler - move entries to local list and loop over them
27392 * while passing them to the queue registered handler.
27393 */
27394-static void blk_done_softirq(struct softirq_action *h)
27395+static void blk_done_softirq(void)
27396 {
27397 struct list_head *cpu_list, local_list;
27398
27399diff --git a/block/bsg.c b/block/bsg.c
27400index ff64ae3..593560c 100644
27401--- a/block/bsg.c
27402+++ b/block/bsg.c
27403@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27404 struct sg_io_v4 *hdr, struct bsg_device *bd,
27405 fmode_t has_write_perm)
27406 {
27407+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27408+ unsigned char *cmdptr;
27409+
27410 if (hdr->request_len > BLK_MAX_CDB) {
27411 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27412 if (!rq->cmd)
27413 return -ENOMEM;
27414- }
27415+ cmdptr = rq->cmd;
27416+ } else
27417+ cmdptr = tmpcmd;
27418
27419- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27420+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27421 hdr->request_len))
27422 return -EFAULT;
27423
27424+ if (cmdptr != rq->cmd)
27425+ memcpy(rq->cmd, cmdptr, hdr->request_len);
27426+
27427 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27428 if (blk_verify_command(rq->cmd, has_write_perm))
27429 return -EPERM;
27430diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27431index 7c668c8..db3521c 100644
27432--- a/block/compat_ioctl.c
27433+++ b/block/compat_ioctl.c
27434@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27435 err |= __get_user(f->spec1, &uf->spec1);
27436 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27437 err |= __get_user(name, &uf->name);
27438- f->name = compat_ptr(name);
27439+ f->name = (void __force_kernel *)compat_ptr(name);
27440 if (err) {
27441 err = -EFAULT;
27442 goto out;
27443diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27444index 6296b40..417c00f 100644
27445--- a/block/partitions/efi.c
27446+++ b/block/partitions/efi.c
27447@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27448 if (!gpt)
27449 return NULL;
27450
27451+ if (!le32_to_cpu(gpt->num_partition_entries))
27452+ return NULL;
27453+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27454+ if (!pte)
27455+ return NULL;
27456+
27457 count = le32_to_cpu(gpt->num_partition_entries) *
27458 le32_to_cpu(gpt->sizeof_partition_entry);
27459- if (!count)
27460- return NULL;
27461- pte = kzalloc(count, GFP_KERNEL);
27462- if (!pte)
27463- return NULL;
27464-
27465 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27466 (u8 *) pte,
27467 count) < count) {
27468diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27469index 9a87daa..fb17486 100644
27470--- a/block/scsi_ioctl.c
27471+++ b/block/scsi_ioctl.c
27472@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27473 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27474 struct sg_io_hdr *hdr, fmode_t mode)
27475 {
27476- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27477+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27478+ unsigned char *cmdptr;
27479+
27480+ if (rq->cmd != rq->__cmd)
27481+ cmdptr = rq->cmd;
27482+ else
27483+ cmdptr = tmpcmd;
27484+
27485+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27486 return -EFAULT;
27487+
27488+ if (cmdptr != rq->cmd)
27489+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27490+
27491 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27492 return -EPERM;
27493
27494@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27495 int err;
27496 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27497 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27498+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27499+ unsigned char *cmdptr;
27500
27501 if (!sic)
27502 return -EINVAL;
27503@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27504 */
27505 err = -EFAULT;
27506 rq->cmd_len = cmdlen;
27507- if (copy_from_user(rq->cmd, sic->data, cmdlen))
27508+
27509+ if (rq->cmd != rq->__cmd)
27510+ cmdptr = rq->cmd;
27511+ else
27512+ cmdptr = tmpcmd;
27513+
27514+ if (copy_from_user(cmdptr, sic->data, cmdlen))
27515 goto error;
27516
27517+ if (rq->cmd != cmdptr)
27518+ memcpy(rq->cmd, cmdptr, cmdlen);
27519+
27520 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27521 goto error;
27522
27523diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27524index 671d4d6..5f24030 100644
27525--- a/crypto/cryptd.c
27526+++ b/crypto/cryptd.c
27527@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27528
27529 struct cryptd_blkcipher_request_ctx {
27530 crypto_completion_t complete;
27531-};
27532+} __no_const;
27533
27534 struct cryptd_hash_ctx {
27535 struct crypto_shash *child;
27536@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27537
27538 struct cryptd_aead_request_ctx {
27539 crypto_completion_t complete;
27540-};
27541+} __no_const;
27542
27543 static void cryptd_queue_worker(struct work_struct *work);
27544
27545diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27546index e6defd8..c26a225 100644
27547--- a/drivers/acpi/apei/cper.c
27548+++ b/drivers/acpi/apei/cper.c
27549@@ -38,12 +38,12 @@
27550 */
27551 u64 cper_next_record_id(void)
27552 {
27553- static atomic64_t seq;
27554+ static atomic64_unchecked_t seq;
27555
27556- if (!atomic64_read(&seq))
27557- atomic64_set(&seq, ((u64)get_seconds()) << 32);
27558+ if (!atomic64_read_unchecked(&seq))
27559+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27560
27561- return atomic64_inc_return(&seq);
27562+ return atomic64_inc_return_unchecked(&seq);
27563 }
27564 EXPORT_SYMBOL_GPL(cper_next_record_id);
27565
27566diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27567index 7586544..636a2f0 100644
27568--- a/drivers/acpi/ec_sys.c
27569+++ b/drivers/acpi/ec_sys.c
27570@@ -12,6 +12,7 @@
27571 #include <linux/acpi.h>
27572 #include <linux/debugfs.h>
27573 #include <linux/module.h>
27574+#include <linux/uaccess.h>
27575 #include "internal.h"
27576
27577 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27578@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27579 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27580 */
27581 unsigned int size = EC_SPACE_SIZE;
27582- u8 *data = (u8 *) buf;
27583+ u8 data;
27584 loff_t init_off = *off;
27585 int err = 0;
27586
27587@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27588 size = count;
27589
27590 while (size) {
27591- err = ec_read(*off, &data[*off - init_off]);
27592+ err = ec_read(*off, &data);
27593 if (err)
27594 return err;
27595+ if (put_user(data, &buf[*off - init_off]))
27596+ return -EFAULT;
27597 *off += 1;
27598 size--;
27599 }
27600@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27601
27602 unsigned int size = count;
27603 loff_t init_off = *off;
27604- u8 *data = (u8 *) buf;
27605 int err = 0;
27606
27607 if (*off >= EC_SPACE_SIZE)
27608@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27609 }
27610
27611 while (size) {
27612- u8 byte_write = data[*off - init_off];
27613+ u8 byte_write;
27614+ if (get_user(byte_write, &buf[*off - init_off]))
27615+ return -EFAULT;
27616 err = ec_write(*off, byte_write);
27617 if (err)
27618 return err;
27619diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27620index 251c7b62..000462d 100644
27621--- a/drivers/acpi/proc.c
27622+++ b/drivers/acpi/proc.c
27623@@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27624 size_t count, loff_t * ppos)
27625 {
27626 struct list_head *node, *next;
27627- char strbuf[5];
27628- char str[5] = "";
27629- unsigned int len = count;
27630+ char strbuf[5] = {0};
27631
27632- if (len > 4)
27633- len = 4;
27634- if (len < 0)
27635+ if (count > 4)
27636+ count = 4;
27637+ if (copy_from_user(strbuf, buffer, count))
27638 return -EFAULT;
27639-
27640- if (copy_from_user(strbuf, buffer, len))
27641- return -EFAULT;
27642- strbuf[len] = '\0';
27643- sscanf(strbuf, "%s", str);
27644+ strbuf[count] = '\0';
27645
27646 mutex_lock(&acpi_device_lock);
27647 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27648@@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27649 if (!dev->wakeup.flags.valid)
27650 continue;
27651
27652- if (!strncmp(dev->pnp.bus_id, str, 4)) {
27653+ if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27654 if (device_can_wakeup(&dev->dev)) {
27655 bool enable = !device_may_wakeup(&dev->dev);
27656 device_set_wakeup_enable(&dev->dev, enable);
27657diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27658index bbac51e..4c094f9 100644
27659--- a/drivers/acpi/processor_driver.c
27660+++ b/drivers/acpi/processor_driver.c
27661@@ -556,7 +556,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27662 return 0;
27663 #endif
27664
27665- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27666+ BUG_ON(pr->id >= nr_cpu_ids);
27667
27668 /*
27669 * Buggy BIOS check
27670diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27671index cece3a4..0845256 100644
27672--- a/drivers/ata/libata-core.c
27673+++ b/drivers/ata/libata-core.c
27674@@ -4743,7 +4743,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27675 struct ata_port *ap;
27676 unsigned int tag;
27677
27678- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27679+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27680 ap = qc->ap;
27681
27682 qc->flags = 0;
27683@@ -4759,7 +4759,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27684 struct ata_port *ap;
27685 struct ata_link *link;
27686
27687- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27688+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27689 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27690 ap = qc->ap;
27691 link = qc->dev->link;
27692@@ -5823,6 +5823,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27693 return;
27694
27695 spin_lock(&lock);
27696+ pax_open_kernel();
27697
27698 for (cur = ops->inherits; cur; cur = cur->inherits) {
27699 void **inherit = (void **)cur;
27700@@ -5836,8 +5837,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27701 if (IS_ERR(*pp))
27702 *pp = NULL;
27703
27704- ops->inherits = NULL;
27705+ *(struct ata_port_operations **)&ops->inherits = NULL;
27706
27707+ pax_close_kernel();
27708 spin_unlock(&lock);
27709 }
27710
27711diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27712index ac6a5be..c7176b1 100644
27713--- a/drivers/ata/pata_arasan_cf.c
27714+++ b/drivers/ata/pata_arasan_cf.c
27715@@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27716 /* Handle platform specific quirks */
27717 if (pdata->quirk) {
27718 if (pdata->quirk & CF_BROKEN_PIO) {
27719- ap->ops->set_piomode = NULL;
27720+ pax_open_kernel();
27721+ *(void **)&ap->ops->set_piomode = NULL;
27722+ pax_close_kernel();
27723 ap->pio_mask = 0;
27724 }
27725 if (pdata->quirk & CF_BROKEN_MWDMA)
27726diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27727index f9b983a..887b9d8 100644
27728--- a/drivers/atm/adummy.c
27729+++ b/drivers/atm/adummy.c
27730@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27731 vcc->pop(vcc, skb);
27732 else
27733 dev_kfree_skb_any(skb);
27734- atomic_inc(&vcc->stats->tx);
27735+ atomic_inc_unchecked(&vcc->stats->tx);
27736
27737 return 0;
27738 }
27739diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27740index 89b30f3..7964211 100644
27741--- a/drivers/atm/ambassador.c
27742+++ b/drivers/atm/ambassador.c
27743@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27744 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27745
27746 // VC layer stats
27747- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27748+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27749
27750 // free the descriptor
27751 kfree (tx_descr);
27752@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27753 dump_skb ("<<<", vc, skb);
27754
27755 // VC layer stats
27756- atomic_inc(&atm_vcc->stats->rx);
27757+ atomic_inc_unchecked(&atm_vcc->stats->rx);
27758 __net_timestamp(skb);
27759 // end of our responsibility
27760 atm_vcc->push (atm_vcc, skb);
27761@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27762 } else {
27763 PRINTK (KERN_INFO, "dropped over-size frame");
27764 // should we count this?
27765- atomic_inc(&atm_vcc->stats->rx_drop);
27766+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27767 }
27768
27769 } else {
27770@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
27771 }
27772
27773 if (check_area (skb->data, skb->len)) {
27774- atomic_inc(&atm_vcc->stats->tx_err);
27775+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
27776 return -ENOMEM; // ?
27777 }
27778
27779diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
27780index b22d71c..d6e1049 100644
27781--- a/drivers/atm/atmtcp.c
27782+++ b/drivers/atm/atmtcp.c
27783@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27784 if (vcc->pop) vcc->pop(vcc,skb);
27785 else dev_kfree_skb(skb);
27786 if (dev_data) return 0;
27787- atomic_inc(&vcc->stats->tx_err);
27788+ atomic_inc_unchecked(&vcc->stats->tx_err);
27789 return -ENOLINK;
27790 }
27791 size = skb->len+sizeof(struct atmtcp_hdr);
27792@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27793 if (!new_skb) {
27794 if (vcc->pop) vcc->pop(vcc,skb);
27795 else dev_kfree_skb(skb);
27796- atomic_inc(&vcc->stats->tx_err);
27797+ atomic_inc_unchecked(&vcc->stats->tx_err);
27798 return -ENOBUFS;
27799 }
27800 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
27801@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27802 if (vcc->pop) vcc->pop(vcc,skb);
27803 else dev_kfree_skb(skb);
27804 out_vcc->push(out_vcc,new_skb);
27805- atomic_inc(&vcc->stats->tx);
27806- atomic_inc(&out_vcc->stats->rx);
27807+ atomic_inc_unchecked(&vcc->stats->tx);
27808+ atomic_inc_unchecked(&out_vcc->stats->rx);
27809 return 0;
27810 }
27811
27812@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27813 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
27814 read_unlock(&vcc_sklist_lock);
27815 if (!out_vcc) {
27816- atomic_inc(&vcc->stats->tx_err);
27817+ atomic_inc_unchecked(&vcc->stats->tx_err);
27818 goto done;
27819 }
27820 skb_pull(skb,sizeof(struct atmtcp_hdr));
27821@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27822 __net_timestamp(new_skb);
27823 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
27824 out_vcc->push(out_vcc,new_skb);
27825- atomic_inc(&vcc->stats->tx);
27826- atomic_inc(&out_vcc->stats->rx);
27827+ atomic_inc_unchecked(&vcc->stats->tx);
27828+ atomic_inc_unchecked(&out_vcc->stats->rx);
27829 done:
27830 if (vcc->pop) vcc->pop(vcc,skb);
27831 else dev_kfree_skb(skb);
27832diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
27833index 2059ee4..faf51c7 100644
27834--- a/drivers/atm/eni.c
27835+++ b/drivers/atm/eni.c
27836@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
27837 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
27838 vcc->dev->number);
27839 length = 0;
27840- atomic_inc(&vcc->stats->rx_err);
27841+ atomic_inc_unchecked(&vcc->stats->rx_err);
27842 }
27843 else {
27844 length = ATM_CELL_SIZE-1; /* no HEC */
27845@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27846 size);
27847 }
27848 eff = length = 0;
27849- atomic_inc(&vcc->stats->rx_err);
27850+ atomic_inc_unchecked(&vcc->stats->rx_err);
27851 }
27852 else {
27853 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
27854@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27855 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
27856 vcc->dev->number,vcc->vci,length,size << 2,descr);
27857 length = eff = 0;
27858- atomic_inc(&vcc->stats->rx_err);
27859+ atomic_inc_unchecked(&vcc->stats->rx_err);
27860 }
27861 }
27862 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
27863@@ -767,7 +767,7 @@ rx_dequeued++;
27864 vcc->push(vcc,skb);
27865 pushed++;
27866 }
27867- atomic_inc(&vcc->stats->rx);
27868+ atomic_inc_unchecked(&vcc->stats->rx);
27869 }
27870 wake_up(&eni_dev->rx_wait);
27871 }
27872@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
27873 PCI_DMA_TODEVICE);
27874 if (vcc->pop) vcc->pop(vcc,skb);
27875 else dev_kfree_skb_irq(skb);
27876- atomic_inc(&vcc->stats->tx);
27877+ atomic_inc_unchecked(&vcc->stats->tx);
27878 wake_up(&eni_dev->tx_wait);
27879 dma_complete++;
27880 }
27881@@ -1567,7 +1567,7 @@ tx_complete++;
27882 /*--------------------------------- entries ---------------------------------*/
27883
27884
27885-static const char *media_name[] __devinitdata = {
27886+static const char *media_name[] __devinitconst = {
27887 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
27888 "UTP", "05?", "06?", "07?", /* 4- 7 */
27889 "TAXI","09?", "10?", "11?", /* 8-11 */
27890diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
27891index 86fed1b..6dc4721 100644
27892--- a/drivers/atm/firestream.c
27893+++ b/drivers/atm/firestream.c
27894@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
27895 }
27896 }
27897
27898- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27899+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27900
27901 fs_dprintk (FS_DEBUG_TXMEM, "i");
27902 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
27903@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27904 #endif
27905 skb_put (skb, qe->p1 & 0xffff);
27906 ATM_SKB(skb)->vcc = atm_vcc;
27907- atomic_inc(&atm_vcc->stats->rx);
27908+ atomic_inc_unchecked(&atm_vcc->stats->rx);
27909 __net_timestamp(skb);
27910 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
27911 atm_vcc->push (atm_vcc, skb);
27912@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27913 kfree (pe);
27914 }
27915 if (atm_vcc)
27916- atomic_inc(&atm_vcc->stats->rx_drop);
27917+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27918 break;
27919 case 0x1f: /* Reassembly abort: no buffers. */
27920 /* Silently increment error counter. */
27921 if (atm_vcc)
27922- atomic_inc(&atm_vcc->stats->rx_drop);
27923+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27924 break;
27925 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
27926 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
27927diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
27928index 361f5ae..7fc552d 100644
27929--- a/drivers/atm/fore200e.c
27930+++ b/drivers/atm/fore200e.c
27931@@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
27932 #endif
27933 /* check error condition */
27934 if (*entry->status & STATUS_ERROR)
27935- atomic_inc(&vcc->stats->tx_err);
27936+ atomic_inc_unchecked(&vcc->stats->tx_err);
27937 else
27938- atomic_inc(&vcc->stats->tx);
27939+ atomic_inc_unchecked(&vcc->stats->tx);
27940 }
27941 }
27942
27943@@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27944 if (skb == NULL) {
27945 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
27946
27947- atomic_inc(&vcc->stats->rx_drop);
27948+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27949 return -ENOMEM;
27950 }
27951
27952@@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27953
27954 dev_kfree_skb_any(skb);
27955
27956- atomic_inc(&vcc->stats->rx_drop);
27957+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27958 return -ENOMEM;
27959 }
27960
27961 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27962
27963 vcc->push(vcc, skb);
27964- atomic_inc(&vcc->stats->rx);
27965+ atomic_inc_unchecked(&vcc->stats->rx);
27966
27967 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27968
27969@@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
27970 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
27971 fore200e->atm_dev->number,
27972 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
27973- atomic_inc(&vcc->stats->rx_err);
27974+ atomic_inc_unchecked(&vcc->stats->rx_err);
27975 }
27976 }
27977
27978@@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
27979 goto retry_here;
27980 }
27981
27982- atomic_inc(&vcc->stats->tx_err);
27983+ atomic_inc_unchecked(&vcc->stats->tx_err);
27984
27985 fore200e->tx_sat++;
27986 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
27987diff --git a/drivers/atm/he.c b/drivers/atm/he.c
27988index b182c2f..1c6fa8a 100644
27989--- a/drivers/atm/he.c
27990+++ b/drivers/atm/he.c
27991@@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27992
27993 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
27994 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
27995- atomic_inc(&vcc->stats->rx_drop);
27996+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27997 goto return_host_buffers;
27998 }
27999
28000@@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28001 RBRQ_LEN_ERR(he_dev->rbrq_head)
28002 ? "LEN_ERR" : "",
28003 vcc->vpi, vcc->vci);
28004- atomic_inc(&vcc->stats->rx_err);
28005+ atomic_inc_unchecked(&vcc->stats->rx_err);
28006 goto return_host_buffers;
28007 }
28008
28009@@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28010 vcc->push(vcc, skb);
28011 spin_lock(&he_dev->global_lock);
28012
28013- atomic_inc(&vcc->stats->rx);
28014+ atomic_inc_unchecked(&vcc->stats->rx);
28015
28016 return_host_buffers:
28017 ++pdus_assembled;
28018@@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
28019 tpd->vcc->pop(tpd->vcc, tpd->skb);
28020 else
28021 dev_kfree_skb_any(tpd->skb);
28022- atomic_inc(&tpd->vcc->stats->tx_err);
28023+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
28024 }
28025 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
28026 return;
28027@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28028 vcc->pop(vcc, skb);
28029 else
28030 dev_kfree_skb_any(skb);
28031- atomic_inc(&vcc->stats->tx_err);
28032+ atomic_inc_unchecked(&vcc->stats->tx_err);
28033 return -EINVAL;
28034 }
28035
28036@@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28037 vcc->pop(vcc, skb);
28038 else
28039 dev_kfree_skb_any(skb);
28040- atomic_inc(&vcc->stats->tx_err);
28041+ atomic_inc_unchecked(&vcc->stats->tx_err);
28042 return -EINVAL;
28043 }
28044 #endif
28045@@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28046 vcc->pop(vcc, skb);
28047 else
28048 dev_kfree_skb_any(skb);
28049- atomic_inc(&vcc->stats->tx_err);
28050+ atomic_inc_unchecked(&vcc->stats->tx_err);
28051 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28052 return -ENOMEM;
28053 }
28054@@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28055 vcc->pop(vcc, skb);
28056 else
28057 dev_kfree_skb_any(skb);
28058- atomic_inc(&vcc->stats->tx_err);
28059+ atomic_inc_unchecked(&vcc->stats->tx_err);
28060 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28061 return -ENOMEM;
28062 }
28063@@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28064 __enqueue_tpd(he_dev, tpd, cid);
28065 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28066
28067- atomic_inc(&vcc->stats->tx);
28068+ atomic_inc_unchecked(&vcc->stats->tx);
28069
28070 return 0;
28071 }
28072diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28073index 7d01c2a..4e3ac01 100644
28074--- a/drivers/atm/horizon.c
28075+++ b/drivers/atm/horizon.c
28076@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28077 {
28078 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28079 // VC layer stats
28080- atomic_inc(&vcc->stats->rx);
28081+ atomic_inc_unchecked(&vcc->stats->rx);
28082 __net_timestamp(skb);
28083 // end of our responsibility
28084 vcc->push (vcc, skb);
28085@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28086 dev->tx_iovec = NULL;
28087
28088 // VC layer stats
28089- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28090+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28091
28092 // free the skb
28093 hrz_kfree_skb (skb);
28094diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28095index 8974bd2..b856f85 100644
28096--- a/drivers/atm/idt77252.c
28097+++ b/drivers/atm/idt77252.c
28098@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28099 else
28100 dev_kfree_skb(skb);
28101
28102- atomic_inc(&vcc->stats->tx);
28103+ atomic_inc_unchecked(&vcc->stats->tx);
28104 }
28105
28106 atomic_dec(&scq->used);
28107@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28108 if ((sb = dev_alloc_skb(64)) == NULL) {
28109 printk("%s: Can't allocate buffers for aal0.\n",
28110 card->name);
28111- atomic_add(i, &vcc->stats->rx_drop);
28112+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
28113 break;
28114 }
28115 if (!atm_charge(vcc, sb->truesize)) {
28116 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28117 card->name);
28118- atomic_add(i - 1, &vcc->stats->rx_drop);
28119+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28120 dev_kfree_skb(sb);
28121 break;
28122 }
28123@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28124 ATM_SKB(sb)->vcc = vcc;
28125 __net_timestamp(sb);
28126 vcc->push(vcc, sb);
28127- atomic_inc(&vcc->stats->rx);
28128+ atomic_inc_unchecked(&vcc->stats->rx);
28129
28130 cell += ATM_CELL_PAYLOAD;
28131 }
28132@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28133 "(CDC: %08x)\n",
28134 card->name, len, rpp->len, readl(SAR_REG_CDC));
28135 recycle_rx_pool_skb(card, rpp);
28136- atomic_inc(&vcc->stats->rx_err);
28137+ atomic_inc_unchecked(&vcc->stats->rx_err);
28138 return;
28139 }
28140 if (stat & SAR_RSQE_CRC) {
28141 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28142 recycle_rx_pool_skb(card, rpp);
28143- atomic_inc(&vcc->stats->rx_err);
28144+ atomic_inc_unchecked(&vcc->stats->rx_err);
28145 return;
28146 }
28147 if (skb_queue_len(&rpp->queue) > 1) {
28148@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28149 RXPRINTK("%s: Can't alloc RX skb.\n",
28150 card->name);
28151 recycle_rx_pool_skb(card, rpp);
28152- atomic_inc(&vcc->stats->rx_err);
28153+ atomic_inc_unchecked(&vcc->stats->rx_err);
28154 return;
28155 }
28156 if (!atm_charge(vcc, skb->truesize)) {
28157@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28158 __net_timestamp(skb);
28159
28160 vcc->push(vcc, skb);
28161- atomic_inc(&vcc->stats->rx);
28162+ atomic_inc_unchecked(&vcc->stats->rx);
28163
28164 return;
28165 }
28166@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28167 __net_timestamp(skb);
28168
28169 vcc->push(vcc, skb);
28170- atomic_inc(&vcc->stats->rx);
28171+ atomic_inc_unchecked(&vcc->stats->rx);
28172
28173 if (skb->truesize > SAR_FB_SIZE_3)
28174 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28175@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28176 if (vcc->qos.aal != ATM_AAL0) {
28177 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28178 card->name, vpi, vci);
28179- atomic_inc(&vcc->stats->rx_drop);
28180+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28181 goto drop;
28182 }
28183
28184 if ((sb = dev_alloc_skb(64)) == NULL) {
28185 printk("%s: Can't allocate buffers for AAL0.\n",
28186 card->name);
28187- atomic_inc(&vcc->stats->rx_err);
28188+ atomic_inc_unchecked(&vcc->stats->rx_err);
28189 goto drop;
28190 }
28191
28192@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28193 ATM_SKB(sb)->vcc = vcc;
28194 __net_timestamp(sb);
28195 vcc->push(vcc, sb);
28196- atomic_inc(&vcc->stats->rx);
28197+ atomic_inc_unchecked(&vcc->stats->rx);
28198
28199 drop:
28200 skb_pull(queue, 64);
28201@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28202
28203 if (vc == NULL) {
28204 printk("%s: NULL connection in send().\n", card->name);
28205- atomic_inc(&vcc->stats->tx_err);
28206+ atomic_inc_unchecked(&vcc->stats->tx_err);
28207 dev_kfree_skb(skb);
28208 return -EINVAL;
28209 }
28210 if (!test_bit(VCF_TX, &vc->flags)) {
28211 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28212- atomic_inc(&vcc->stats->tx_err);
28213+ atomic_inc_unchecked(&vcc->stats->tx_err);
28214 dev_kfree_skb(skb);
28215 return -EINVAL;
28216 }
28217@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28218 break;
28219 default:
28220 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28221- atomic_inc(&vcc->stats->tx_err);
28222+ atomic_inc_unchecked(&vcc->stats->tx_err);
28223 dev_kfree_skb(skb);
28224 return -EINVAL;
28225 }
28226
28227 if (skb_shinfo(skb)->nr_frags != 0) {
28228 printk("%s: No scatter-gather yet.\n", card->name);
28229- atomic_inc(&vcc->stats->tx_err);
28230+ atomic_inc_unchecked(&vcc->stats->tx_err);
28231 dev_kfree_skb(skb);
28232 return -EINVAL;
28233 }
28234@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28235
28236 err = queue_skb(card, vc, skb, oam);
28237 if (err) {
28238- atomic_inc(&vcc->stats->tx_err);
28239+ atomic_inc_unchecked(&vcc->stats->tx_err);
28240 dev_kfree_skb(skb);
28241 return err;
28242 }
28243@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28244 skb = dev_alloc_skb(64);
28245 if (!skb) {
28246 printk("%s: Out of memory in send_oam().\n", card->name);
28247- atomic_inc(&vcc->stats->tx_err);
28248+ atomic_inc_unchecked(&vcc->stats->tx_err);
28249 return -ENOMEM;
28250 }
28251 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28252diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28253index d438601..8b98495 100644
28254--- a/drivers/atm/iphase.c
28255+++ b/drivers/atm/iphase.c
28256@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28257 status = (u_short) (buf_desc_ptr->desc_mode);
28258 if (status & (RX_CER | RX_PTE | RX_OFL))
28259 {
28260- atomic_inc(&vcc->stats->rx_err);
28261+ atomic_inc_unchecked(&vcc->stats->rx_err);
28262 IF_ERR(printk("IA: bad packet, dropping it");)
28263 if (status & RX_CER) {
28264 IF_ERR(printk(" cause: packet CRC error\n");)
28265@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28266 len = dma_addr - buf_addr;
28267 if (len > iadev->rx_buf_sz) {
28268 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28269- atomic_inc(&vcc->stats->rx_err);
28270+ atomic_inc_unchecked(&vcc->stats->rx_err);
28271 goto out_free_desc;
28272 }
28273
28274@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28275 ia_vcc = INPH_IA_VCC(vcc);
28276 if (ia_vcc == NULL)
28277 {
28278- atomic_inc(&vcc->stats->rx_err);
28279+ atomic_inc_unchecked(&vcc->stats->rx_err);
28280 atm_return(vcc, skb->truesize);
28281 dev_kfree_skb_any(skb);
28282 goto INCR_DLE;
28283@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28284 if ((length > iadev->rx_buf_sz) || (length >
28285 (skb->len - sizeof(struct cpcs_trailer))))
28286 {
28287- atomic_inc(&vcc->stats->rx_err);
28288+ atomic_inc_unchecked(&vcc->stats->rx_err);
28289 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28290 length, skb->len);)
28291 atm_return(vcc, skb->truesize);
28292@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28293
28294 IF_RX(printk("rx_dle_intr: skb push");)
28295 vcc->push(vcc,skb);
28296- atomic_inc(&vcc->stats->rx);
28297+ atomic_inc_unchecked(&vcc->stats->rx);
28298 iadev->rx_pkt_cnt++;
28299 }
28300 INCR_DLE:
28301@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28302 {
28303 struct k_sonet_stats *stats;
28304 stats = &PRIV(_ia_dev[board])->sonet_stats;
28305- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28306- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28307- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28308- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28309- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28310- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28311- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28312- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28313- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28314+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28315+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28316+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28317+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28318+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28319+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28320+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28321+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28322+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28323 }
28324 ia_cmds.status = 0;
28325 break;
28326@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28327 if ((desc == 0) || (desc > iadev->num_tx_desc))
28328 {
28329 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28330- atomic_inc(&vcc->stats->tx);
28331+ atomic_inc_unchecked(&vcc->stats->tx);
28332 if (vcc->pop)
28333 vcc->pop(vcc, skb);
28334 else
28335@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28336 ATM_DESC(skb) = vcc->vci;
28337 skb_queue_tail(&iadev->tx_dma_q, skb);
28338
28339- atomic_inc(&vcc->stats->tx);
28340+ atomic_inc_unchecked(&vcc->stats->tx);
28341 iadev->tx_pkt_cnt++;
28342 /* Increment transaction counter */
28343 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28344
28345 #if 0
28346 /* add flow control logic */
28347- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28348+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28349 if (iavcc->vc_desc_cnt > 10) {
28350 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28351 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28352diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28353index 68c7588..7036683 100644
28354--- a/drivers/atm/lanai.c
28355+++ b/drivers/atm/lanai.c
28356@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28357 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28358 lanai_endtx(lanai, lvcc);
28359 lanai_free_skb(lvcc->tx.atmvcc, skb);
28360- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28361+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28362 }
28363
28364 /* Try to fill the buffer - don't call unless there is backlog */
28365@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28366 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28367 __net_timestamp(skb);
28368 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28369- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28370+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28371 out:
28372 lvcc->rx.buf.ptr = end;
28373 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28374@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28375 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28376 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28377 lanai->stats.service_rxnotaal5++;
28378- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28379+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28380 return 0;
28381 }
28382 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28383@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28384 int bytes;
28385 read_unlock(&vcc_sklist_lock);
28386 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28387- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28388+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28389 lvcc->stats.x.aal5.service_trash++;
28390 bytes = (SERVICE_GET_END(s) * 16) -
28391 (((unsigned long) lvcc->rx.buf.ptr) -
28392@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28393 }
28394 if (s & SERVICE_STREAM) {
28395 read_unlock(&vcc_sklist_lock);
28396- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28397+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28398 lvcc->stats.x.aal5.service_stream++;
28399 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28400 "PDU on VCI %d!\n", lanai->number, vci);
28401@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28402 return 0;
28403 }
28404 DPRINTK("got rx crc error on vci %d\n", vci);
28405- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28406+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28407 lvcc->stats.x.aal5.service_rxcrc++;
28408 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28409 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28410diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28411index 1c70c45..300718d 100644
28412--- a/drivers/atm/nicstar.c
28413+++ b/drivers/atm/nicstar.c
28414@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28415 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28416 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28417 card->index);
28418- atomic_inc(&vcc->stats->tx_err);
28419+ atomic_inc_unchecked(&vcc->stats->tx_err);
28420 dev_kfree_skb_any(skb);
28421 return -EINVAL;
28422 }
28423@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28424 if (!vc->tx) {
28425 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28426 card->index);
28427- atomic_inc(&vcc->stats->tx_err);
28428+ atomic_inc_unchecked(&vcc->stats->tx_err);
28429 dev_kfree_skb_any(skb);
28430 return -EINVAL;
28431 }
28432@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28433 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28434 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28435 card->index);
28436- atomic_inc(&vcc->stats->tx_err);
28437+ atomic_inc_unchecked(&vcc->stats->tx_err);
28438 dev_kfree_skb_any(skb);
28439 return -EINVAL;
28440 }
28441
28442 if (skb_shinfo(skb)->nr_frags != 0) {
28443 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28444- atomic_inc(&vcc->stats->tx_err);
28445+ atomic_inc_unchecked(&vcc->stats->tx_err);
28446 dev_kfree_skb_any(skb);
28447 return -EINVAL;
28448 }
28449@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28450 }
28451
28452 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28453- atomic_inc(&vcc->stats->tx_err);
28454+ atomic_inc_unchecked(&vcc->stats->tx_err);
28455 dev_kfree_skb_any(skb);
28456 return -EIO;
28457 }
28458- atomic_inc(&vcc->stats->tx);
28459+ atomic_inc_unchecked(&vcc->stats->tx);
28460
28461 return 0;
28462 }
28463@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28464 printk
28465 ("nicstar%d: Can't allocate buffers for aal0.\n",
28466 card->index);
28467- atomic_add(i, &vcc->stats->rx_drop);
28468+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
28469 break;
28470 }
28471 if (!atm_charge(vcc, sb->truesize)) {
28472 RXPRINTK
28473 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28474 card->index);
28475- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28476+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28477 dev_kfree_skb_any(sb);
28478 break;
28479 }
28480@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28481 ATM_SKB(sb)->vcc = vcc;
28482 __net_timestamp(sb);
28483 vcc->push(vcc, sb);
28484- atomic_inc(&vcc->stats->rx);
28485+ atomic_inc_unchecked(&vcc->stats->rx);
28486 cell += ATM_CELL_PAYLOAD;
28487 }
28488
28489@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28490 if (iovb == NULL) {
28491 printk("nicstar%d: Out of iovec buffers.\n",
28492 card->index);
28493- atomic_inc(&vcc->stats->rx_drop);
28494+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28495 recycle_rx_buf(card, skb);
28496 return;
28497 }
28498@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28499 small or large buffer itself. */
28500 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28501 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28502- atomic_inc(&vcc->stats->rx_err);
28503+ atomic_inc_unchecked(&vcc->stats->rx_err);
28504 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28505 NS_MAX_IOVECS);
28506 NS_PRV_IOVCNT(iovb) = 0;
28507@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28508 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28509 card->index);
28510 which_list(card, skb);
28511- atomic_inc(&vcc->stats->rx_err);
28512+ atomic_inc_unchecked(&vcc->stats->rx_err);
28513 recycle_rx_buf(card, skb);
28514 vc->rx_iov = NULL;
28515 recycle_iov_buf(card, iovb);
28516@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28517 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28518 card->index);
28519 which_list(card, skb);
28520- atomic_inc(&vcc->stats->rx_err);
28521+ atomic_inc_unchecked(&vcc->stats->rx_err);
28522 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28523 NS_PRV_IOVCNT(iovb));
28524 vc->rx_iov = NULL;
28525@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28526 printk(" - PDU size mismatch.\n");
28527 else
28528 printk(".\n");
28529- atomic_inc(&vcc->stats->rx_err);
28530+ atomic_inc_unchecked(&vcc->stats->rx_err);
28531 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28532 NS_PRV_IOVCNT(iovb));
28533 vc->rx_iov = NULL;
28534@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28535 /* skb points to a small buffer */
28536 if (!atm_charge(vcc, skb->truesize)) {
28537 push_rxbufs(card, skb);
28538- atomic_inc(&vcc->stats->rx_drop);
28539+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28540 } else {
28541 skb_put(skb, len);
28542 dequeue_sm_buf(card, skb);
28543@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28544 ATM_SKB(skb)->vcc = vcc;
28545 __net_timestamp(skb);
28546 vcc->push(vcc, skb);
28547- atomic_inc(&vcc->stats->rx);
28548+ atomic_inc_unchecked(&vcc->stats->rx);
28549 }
28550 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28551 struct sk_buff *sb;
28552@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28553 if (len <= NS_SMBUFSIZE) {
28554 if (!atm_charge(vcc, sb->truesize)) {
28555 push_rxbufs(card, sb);
28556- atomic_inc(&vcc->stats->rx_drop);
28557+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28558 } else {
28559 skb_put(sb, len);
28560 dequeue_sm_buf(card, sb);
28561@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28562 ATM_SKB(sb)->vcc = vcc;
28563 __net_timestamp(sb);
28564 vcc->push(vcc, sb);
28565- atomic_inc(&vcc->stats->rx);
28566+ atomic_inc_unchecked(&vcc->stats->rx);
28567 }
28568
28569 push_rxbufs(card, skb);
28570@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28571
28572 if (!atm_charge(vcc, skb->truesize)) {
28573 push_rxbufs(card, skb);
28574- atomic_inc(&vcc->stats->rx_drop);
28575+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28576 } else {
28577 dequeue_lg_buf(card, skb);
28578 #ifdef NS_USE_DESTRUCTORS
28579@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28580 ATM_SKB(skb)->vcc = vcc;
28581 __net_timestamp(skb);
28582 vcc->push(vcc, skb);
28583- atomic_inc(&vcc->stats->rx);
28584+ atomic_inc_unchecked(&vcc->stats->rx);
28585 }
28586
28587 push_rxbufs(card, sb);
28588@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28589 printk
28590 ("nicstar%d: Out of huge buffers.\n",
28591 card->index);
28592- atomic_inc(&vcc->stats->rx_drop);
28593+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28594 recycle_iovec_rx_bufs(card,
28595 (struct iovec *)
28596 iovb->data,
28597@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28598 card->hbpool.count++;
28599 } else
28600 dev_kfree_skb_any(hb);
28601- atomic_inc(&vcc->stats->rx_drop);
28602+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28603 } else {
28604 /* Copy the small buffer to the huge buffer */
28605 sb = (struct sk_buff *)iov->iov_base;
28606@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28607 #endif /* NS_USE_DESTRUCTORS */
28608 __net_timestamp(hb);
28609 vcc->push(vcc, hb);
28610- atomic_inc(&vcc->stats->rx);
28611+ atomic_inc_unchecked(&vcc->stats->rx);
28612 }
28613 }
28614
28615diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28616index 9851093..adb2b1e 100644
28617--- a/drivers/atm/solos-pci.c
28618+++ b/drivers/atm/solos-pci.c
28619@@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28620 }
28621 atm_charge(vcc, skb->truesize);
28622 vcc->push(vcc, skb);
28623- atomic_inc(&vcc->stats->rx);
28624+ atomic_inc_unchecked(&vcc->stats->rx);
28625 break;
28626
28627 case PKT_STATUS:
28628@@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28629 vcc = SKB_CB(oldskb)->vcc;
28630
28631 if (vcc) {
28632- atomic_inc(&vcc->stats->tx);
28633+ atomic_inc_unchecked(&vcc->stats->tx);
28634 solos_pop(vcc, oldskb);
28635 } else
28636 dev_kfree_skb_irq(oldskb);
28637diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28638index 0215934..ce9f5b1 100644
28639--- a/drivers/atm/suni.c
28640+++ b/drivers/atm/suni.c
28641@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28642
28643
28644 #define ADD_LIMITED(s,v) \
28645- atomic_add((v),&stats->s); \
28646- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28647+ atomic_add_unchecked((v),&stats->s); \
28648+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28649
28650
28651 static void suni_hz(unsigned long from_timer)
28652diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28653index 5120a96..e2572bd 100644
28654--- a/drivers/atm/uPD98402.c
28655+++ b/drivers/atm/uPD98402.c
28656@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28657 struct sonet_stats tmp;
28658 int error = 0;
28659
28660- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28661+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28662 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28663 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28664 if (zero && !error) {
28665@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28666
28667
28668 #define ADD_LIMITED(s,v) \
28669- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28670- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28671- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28672+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28673+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28674+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28675
28676
28677 static void stat_event(struct atm_dev *dev)
28678@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28679 if (reason & uPD98402_INT_PFM) stat_event(dev);
28680 if (reason & uPD98402_INT_PCO) {
28681 (void) GET(PCOCR); /* clear interrupt cause */
28682- atomic_add(GET(HECCT),
28683+ atomic_add_unchecked(GET(HECCT),
28684 &PRIV(dev)->sonet_stats.uncorr_hcs);
28685 }
28686 if ((reason & uPD98402_INT_RFO) &&
28687@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28688 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28689 uPD98402_INT_LOS),PIMR); /* enable them */
28690 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28691- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28692- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28693- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28694+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28695+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28696+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28697 return 0;
28698 }
28699
28700diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28701index abe4e20..83c4727 100644
28702--- a/drivers/atm/zatm.c
28703+++ b/drivers/atm/zatm.c
28704@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28705 }
28706 if (!size) {
28707 dev_kfree_skb_irq(skb);
28708- if (vcc) atomic_inc(&vcc->stats->rx_err);
28709+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28710 continue;
28711 }
28712 if (!atm_charge(vcc,skb->truesize)) {
28713@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28714 skb->len = size;
28715 ATM_SKB(skb)->vcc = vcc;
28716 vcc->push(vcc,skb);
28717- atomic_inc(&vcc->stats->rx);
28718+ atomic_inc_unchecked(&vcc->stats->rx);
28719 }
28720 zout(pos & 0xffff,MTA(mbx));
28721 #if 0 /* probably a stupid idea */
28722@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28723 skb_queue_head(&zatm_vcc->backlog,skb);
28724 break;
28725 }
28726- atomic_inc(&vcc->stats->tx);
28727+ atomic_inc_unchecked(&vcc->stats->tx);
28728 wake_up(&zatm_vcc->tx_wait);
28729 }
28730
28731diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28732index 765c3a2..771ace6 100644
28733--- a/drivers/base/devtmpfs.c
28734+++ b/drivers/base/devtmpfs.c
28735@@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
28736 if (!thread)
28737 return 0;
28738
28739- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28740+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28741 if (err)
28742 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28743 else
28744diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28745index cbb463b..babe2cf 100644
28746--- a/drivers/base/power/wakeup.c
28747+++ b/drivers/base/power/wakeup.c
28748@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
28749 * They need to be modified together atomically, so it's better to use one
28750 * atomic variable to hold them both.
28751 */
28752-static atomic_t combined_event_count = ATOMIC_INIT(0);
28753+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
28754
28755 #define IN_PROGRESS_BITS (sizeof(int) * 4)
28756 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
28757
28758 static void split_counters(unsigned int *cnt, unsigned int *inpr)
28759 {
28760- unsigned int comb = atomic_read(&combined_event_count);
28761+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
28762
28763 *cnt = (comb >> IN_PROGRESS_BITS);
28764 *inpr = comb & MAX_IN_PROGRESS;
28765@@ -385,7 +385,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
28766 ws->start_prevent_time = ws->last_time;
28767
28768 /* Increment the counter of events in progress. */
28769- cec = atomic_inc_return(&combined_event_count);
28770+ cec = atomic_inc_return_unchecked(&combined_event_count);
28771
28772 trace_wakeup_source_activate(ws->name, cec);
28773 }
28774@@ -511,7 +511,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
28775 * Increment the counter of registered wakeup events and decrement the
28776 * couter of wakeup events in progress simultaneously.
28777 */
28778- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
28779+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
28780 trace_wakeup_source_deactivate(ws->name, cec);
28781
28782 split_counters(&cnt, &inpr);
28783diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
28784index b0f553b..77b928b 100644
28785--- a/drivers/block/cciss.c
28786+++ b/drivers/block/cciss.c
28787@@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
28788 int err;
28789 u32 cp;
28790
28791+ memset(&arg64, 0, sizeof(arg64));
28792+
28793 err = 0;
28794 err |=
28795 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
28796@@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
28797 while (!list_empty(&h->reqQ)) {
28798 c = list_entry(h->reqQ.next, CommandList_struct, list);
28799 /* can't do anything if fifo is full */
28800- if ((h->access.fifo_full(h))) {
28801+ if ((h->access->fifo_full(h))) {
28802 dev_warn(&h->pdev->dev, "fifo full\n");
28803 break;
28804 }
28805@@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
28806 h->Qdepth--;
28807
28808 /* Tell the controller execute command */
28809- h->access.submit_command(h, c);
28810+ h->access->submit_command(h, c);
28811
28812 /* Put job onto the completed Q */
28813 addQ(&h->cmpQ, c);
28814@@ -3443,17 +3445,17 @@ startio:
28815
28816 static inline unsigned long get_next_completion(ctlr_info_t *h)
28817 {
28818- return h->access.command_completed(h);
28819+ return h->access->command_completed(h);
28820 }
28821
28822 static inline int interrupt_pending(ctlr_info_t *h)
28823 {
28824- return h->access.intr_pending(h);
28825+ return h->access->intr_pending(h);
28826 }
28827
28828 static inline long interrupt_not_for_us(ctlr_info_t *h)
28829 {
28830- return ((h->access.intr_pending(h) == 0) ||
28831+ return ((h->access->intr_pending(h) == 0) ||
28832 (h->interrupts_enabled == 0));
28833 }
28834
28835@@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
28836 u32 a;
28837
28838 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
28839- return h->access.command_completed(h);
28840+ return h->access->command_completed(h);
28841
28842 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
28843 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
28844@@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
28845 trans_support & CFGTBL_Trans_use_short_tags);
28846
28847 /* Change the access methods to the performant access methods */
28848- h->access = SA5_performant_access;
28849+ h->access = &SA5_performant_access;
28850 h->transMethod = CFGTBL_Trans_Performant;
28851
28852 return;
28853@@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
28854 if (prod_index < 0)
28855 return -ENODEV;
28856 h->product_name = products[prod_index].product_name;
28857- h->access = *(products[prod_index].access);
28858+ h->access = products[prod_index].access;
28859
28860 if (cciss_board_disabled(h)) {
28861 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
28862@@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
28863 }
28864
28865 /* make sure the board interrupts are off */
28866- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28867+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28868 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
28869 if (rc)
28870 goto clean2;
28871@@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
28872 * fake ones to scoop up any residual completions.
28873 */
28874 spin_lock_irqsave(&h->lock, flags);
28875- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28876+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28877 spin_unlock_irqrestore(&h->lock, flags);
28878 free_irq(h->intr[h->intr_mode], h);
28879 rc = cciss_request_irq(h, cciss_msix_discard_completions,
28880@@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
28881 dev_info(&h->pdev->dev, "Board READY.\n");
28882 dev_info(&h->pdev->dev,
28883 "Waiting for stale completions to drain.\n");
28884- h->access.set_intr_mask(h, CCISS_INTR_ON);
28885+ h->access->set_intr_mask(h, CCISS_INTR_ON);
28886 msleep(10000);
28887- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28888+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28889
28890 rc = controller_reset_failed(h->cfgtable);
28891 if (rc)
28892@@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
28893 cciss_scsi_setup(h);
28894
28895 /* Turn the interrupts on so we can service requests */
28896- h->access.set_intr_mask(h, CCISS_INTR_ON);
28897+ h->access->set_intr_mask(h, CCISS_INTR_ON);
28898
28899 /* Get the firmware version */
28900 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
28901@@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
28902 kfree(flush_buf);
28903 if (return_code != IO_OK)
28904 dev_warn(&h->pdev->dev, "Error flushing cache\n");
28905- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28906+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28907 free_irq(h->intr[h->intr_mode], h);
28908 }
28909
28910diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
28911index 7fda30e..eb5dfe0 100644
28912--- a/drivers/block/cciss.h
28913+++ b/drivers/block/cciss.h
28914@@ -101,7 +101,7 @@ struct ctlr_info
28915 /* information about each logical volume */
28916 drive_info_struct *drv[CISS_MAX_LUN];
28917
28918- struct access_method access;
28919+ struct access_method *access;
28920
28921 /* queue and queue Info */
28922 struct list_head reqQ;
28923diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
28924index 9125bbe..eede5c8 100644
28925--- a/drivers/block/cpqarray.c
28926+++ b/drivers/block/cpqarray.c
28927@@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28928 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
28929 goto Enomem4;
28930 }
28931- hba[i]->access.set_intr_mask(hba[i], 0);
28932+ hba[i]->access->set_intr_mask(hba[i], 0);
28933 if (request_irq(hba[i]->intr, do_ida_intr,
28934 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
28935 {
28936@@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28937 add_timer(&hba[i]->timer);
28938
28939 /* Enable IRQ now that spinlock and rate limit timer are set up */
28940- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28941+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28942
28943 for(j=0; j<NWD; j++) {
28944 struct gendisk *disk = ida_gendisk[i][j];
28945@@ -694,7 +694,7 @@ DBGINFO(
28946 for(i=0; i<NR_PRODUCTS; i++) {
28947 if (board_id == products[i].board_id) {
28948 c->product_name = products[i].product_name;
28949- c->access = *(products[i].access);
28950+ c->access = products[i].access;
28951 break;
28952 }
28953 }
28954@@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
28955 hba[ctlr]->intr = intr;
28956 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
28957 hba[ctlr]->product_name = products[j].product_name;
28958- hba[ctlr]->access = *(products[j].access);
28959+ hba[ctlr]->access = products[j].access;
28960 hba[ctlr]->ctlr = ctlr;
28961 hba[ctlr]->board_id = board_id;
28962 hba[ctlr]->pci_dev = NULL; /* not PCI */
28963@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
28964
28965 while((c = h->reqQ) != NULL) {
28966 /* Can't do anything if we're busy */
28967- if (h->access.fifo_full(h) == 0)
28968+ if (h->access->fifo_full(h) == 0)
28969 return;
28970
28971 /* Get the first entry from the request Q */
28972@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
28973 h->Qdepth--;
28974
28975 /* Tell the controller to do our bidding */
28976- h->access.submit_command(h, c);
28977+ h->access->submit_command(h, c);
28978
28979 /* Get onto the completion Q */
28980 addQ(&h->cmpQ, c);
28981@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28982 unsigned long flags;
28983 __u32 a,a1;
28984
28985- istat = h->access.intr_pending(h);
28986+ istat = h->access->intr_pending(h);
28987 /* Is this interrupt for us? */
28988 if (istat == 0)
28989 return IRQ_NONE;
28990@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28991 */
28992 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
28993 if (istat & FIFO_NOT_EMPTY) {
28994- while((a = h->access.command_completed(h))) {
28995+ while((a = h->access->command_completed(h))) {
28996 a1 = a; a &= ~3;
28997 if ((c = h->cmpQ) == NULL)
28998 {
28999@@ -1449,11 +1449,11 @@ static int sendcmd(
29000 /*
29001 * Disable interrupt
29002 */
29003- info_p->access.set_intr_mask(info_p, 0);
29004+ info_p->access->set_intr_mask(info_p, 0);
29005 /* Make sure there is room in the command FIFO */
29006 /* Actually it should be completely empty at this time. */
29007 for (i = 200000; i > 0; i--) {
29008- temp = info_p->access.fifo_full(info_p);
29009+ temp = info_p->access->fifo_full(info_p);
29010 if (temp != 0) {
29011 break;
29012 }
29013@@ -1466,7 +1466,7 @@ DBG(
29014 /*
29015 * Send the cmd
29016 */
29017- info_p->access.submit_command(info_p, c);
29018+ info_p->access->submit_command(info_p, c);
29019 complete = pollcomplete(ctlr);
29020
29021 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29022@@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29023 * we check the new geometry. Then turn interrupts back on when
29024 * we're done.
29025 */
29026- host->access.set_intr_mask(host, 0);
29027+ host->access->set_intr_mask(host, 0);
29028 getgeometry(ctlr);
29029- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29030+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29031
29032 for(i=0; i<NWD; i++) {
29033 struct gendisk *disk = ida_gendisk[ctlr][i];
29034@@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29035 /* Wait (up to 2 seconds) for a command to complete */
29036
29037 for (i = 200000; i > 0; i--) {
29038- done = hba[ctlr]->access.command_completed(hba[ctlr]);
29039+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
29040 if (done == 0) {
29041 udelay(10); /* a short fixed delay */
29042 } else
29043diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29044index be73e9d..7fbf140 100644
29045--- a/drivers/block/cpqarray.h
29046+++ b/drivers/block/cpqarray.h
29047@@ -99,7 +99,7 @@ struct ctlr_info {
29048 drv_info_t drv[NWD];
29049 struct proc_dir_entry *proc;
29050
29051- struct access_method access;
29052+ struct access_method *access;
29053
29054 cmdlist_t *reqQ;
29055 cmdlist_t *cmpQ;
29056diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29057index 02f013a..afeba24 100644
29058--- a/drivers/block/drbd/drbd_int.h
29059+++ b/drivers/block/drbd/drbd_int.h
29060@@ -735,7 +735,7 @@ struct drbd_request;
29061 struct drbd_epoch {
29062 struct list_head list;
29063 unsigned int barrier_nr;
29064- atomic_t epoch_size; /* increased on every request added. */
29065+ atomic_unchecked_t epoch_size; /* increased on every request added. */
29066 atomic_t active; /* increased on every req. added, and dec on every finished. */
29067 unsigned long flags;
29068 };
29069@@ -1110,7 +1110,7 @@ struct drbd_conf {
29070 void *int_dig_in;
29071 void *int_dig_vv;
29072 wait_queue_head_t seq_wait;
29073- atomic_t packet_seq;
29074+ atomic_unchecked_t packet_seq;
29075 unsigned int peer_seq;
29076 spinlock_t peer_seq_lock;
29077 unsigned int minor;
29078@@ -1651,30 +1651,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29079
29080 static inline void drbd_tcp_cork(struct socket *sock)
29081 {
29082- int __user val = 1;
29083+ int val = 1;
29084 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29085- (char __user *)&val, sizeof(val));
29086+ (char __force_user *)&val, sizeof(val));
29087 }
29088
29089 static inline void drbd_tcp_uncork(struct socket *sock)
29090 {
29091- int __user val = 0;
29092+ int val = 0;
29093 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29094- (char __user *)&val, sizeof(val));
29095+ (char __force_user *)&val, sizeof(val));
29096 }
29097
29098 static inline void drbd_tcp_nodelay(struct socket *sock)
29099 {
29100- int __user val = 1;
29101+ int val = 1;
29102 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29103- (char __user *)&val, sizeof(val));
29104+ (char __force_user *)&val, sizeof(val));
29105 }
29106
29107 static inline void drbd_tcp_quickack(struct socket *sock)
29108 {
29109- int __user val = 2;
29110+ int val = 2;
29111 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29112- (char __user *)&val, sizeof(val));
29113+ (char __force_user *)&val, sizeof(val));
29114 }
29115
29116 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29117diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29118index 920ede2..cb827ba 100644
29119--- a/drivers/block/drbd/drbd_main.c
29120+++ b/drivers/block/drbd/drbd_main.c
29121@@ -2555,7 +2555,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29122 p.sector = sector;
29123 p.block_id = block_id;
29124 p.blksize = blksize;
29125- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29126+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29127
29128 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29129 return false;
29130@@ -2853,7 +2853,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29131
29132 p.sector = cpu_to_be64(req->sector);
29133 p.block_id = (unsigned long)req;
29134- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29135+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29136
29137 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29138
29139@@ -3138,7 +3138,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29140 atomic_set(&mdev->unacked_cnt, 0);
29141 atomic_set(&mdev->local_cnt, 0);
29142 atomic_set(&mdev->net_cnt, 0);
29143- atomic_set(&mdev->packet_seq, 0);
29144+ atomic_set_unchecked(&mdev->packet_seq, 0);
29145 atomic_set(&mdev->pp_in_use, 0);
29146 atomic_set(&mdev->pp_in_use_by_net, 0);
29147 atomic_set(&mdev->rs_sect_in, 0);
29148@@ -3220,8 +3220,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29149 mdev->receiver.t_state);
29150
29151 /* no need to lock it, I'm the only thread alive */
29152- if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29153- dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29154+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29155+ dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29156 mdev->al_writ_cnt =
29157 mdev->bm_writ_cnt =
29158 mdev->read_cnt =
29159diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29160index 6d4de6a..7b7ad4b 100644
29161--- a/drivers/block/drbd/drbd_nl.c
29162+++ b/drivers/block/drbd/drbd_nl.c
29163@@ -2387,7 +2387,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29164 module_put(THIS_MODULE);
29165 }
29166
29167-static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29168+static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29169
29170 static unsigned short *
29171 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29172@@ -2458,7 +2458,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29173 cn_reply->id.idx = CN_IDX_DRBD;
29174 cn_reply->id.val = CN_VAL_DRBD;
29175
29176- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29177+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29178 cn_reply->ack = 0; /* not used here. */
29179 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29180 (int)((char *)tl - (char *)reply->tag_list);
29181@@ -2490,7 +2490,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29182 cn_reply->id.idx = CN_IDX_DRBD;
29183 cn_reply->id.val = CN_VAL_DRBD;
29184
29185- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29186+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29187 cn_reply->ack = 0; /* not used here. */
29188 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29189 (int)((char *)tl - (char *)reply->tag_list);
29190@@ -2568,7 +2568,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29191 cn_reply->id.idx = CN_IDX_DRBD;
29192 cn_reply->id.val = CN_VAL_DRBD;
29193
29194- cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29195+ cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29196 cn_reply->ack = 0; // not used here.
29197 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29198 (int)((char*)tl - (char*)reply->tag_list);
29199@@ -2607,7 +2607,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29200 cn_reply->id.idx = CN_IDX_DRBD;
29201 cn_reply->id.val = CN_VAL_DRBD;
29202
29203- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29204+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29205 cn_reply->ack = 0; /* not used here. */
29206 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29207 (int)((char *)tl - (char *)reply->tag_list);
29208diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29209index ea4836e..272d72a 100644
29210--- a/drivers/block/drbd/drbd_receiver.c
29211+++ b/drivers/block/drbd/drbd_receiver.c
29212@@ -893,7 +893,7 @@ retry:
29213 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29214 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29215
29216- atomic_set(&mdev->packet_seq, 0);
29217+ atomic_set_unchecked(&mdev->packet_seq, 0);
29218 mdev->peer_seq = 0;
29219
29220 if (drbd_send_protocol(mdev) == -1)
29221@@ -994,7 +994,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29222 do {
29223 next_epoch = NULL;
29224
29225- epoch_size = atomic_read(&epoch->epoch_size);
29226+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29227
29228 switch (ev & ~EV_CLEANUP) {
29229 case EV_PUT:
29230@@ -1030,7 +1030,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29231 rv = FE_DESTROYED;
29232 } else {
29233 epoch->flags = 0;
29234- atomic_set(&epoch->epoch_size, 0);
29235+ atomic_set_unchecked(&epoch->epoch_size, 0);
29236 /* atomic_set(&epoch->active, 0); is already zero */
29237 if (rv == FE_STILL_LIVE)
29238 rv = FE_RECYCLED;
29239@@ -1205,14 +1205,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29240 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29241 drbd_flush(mdev);
29242
29243- if (atomic_read(&mdev->current_epoch->epoch_size)) {
29244+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29245 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29246 if (epoch)
29247 break;
29248 }
29249
29250 epoch = mdev->current_epoch;
29251- wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29252+ wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29253
29254 D_ASSERT(atomic_read(&epoch->active) == 0);
29255 D_ASSERT(epoch->flags == 0);
29256@@ -1224,11 +1224,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29257 }
29258
29259 epoch->flags = 0;
29260- atomic_set(&epoch->epoch_size, 0);
29261+ atomic_set_unchecked(&epoch->epoch_size, 0);
29262 atomic_set(&epoch->active, 0);
29263
29264 spin_lock(&mdev->epoch_lock);
29265- if (atomic_read(&mdev->current_epoch->epoch_size)) {
29266+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29267 list_add(&epoch->list, &mdev->current_epoch->list);
29268 mdev->current_epoch = epoch;
29269 mdev->epochs++;
29270@@ -1695,7 +1695,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29271 spin_unlock(&mdev->peer_seq_lock);
29272
29273 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29274- atomic_inc(&mdev->current_epoch->epoch_size);
29275+ atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29276 return drbd_drain_block(mdev, data_size);
29277 }
29278
29279@@ -1721,7 +1721,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29280
29281 spin_lock(&mdev->epoch_lock);
29282 e->epoch = mdev->current_epoch;
29283- atomic_inc(&e->epoch->epoch_size);
29284+ atomic_inc_unchecked(&e->epoch->epoch_size);
29285 atomic_inc(&e->epoch->active);
29286 spin_unlock(&mdev->epoch_lock);
29287
29288@@ -3936,7 +3936,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29289 D_ASSERT(list_empty(&mdev->done_ee));
29290
29291 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29292- atomic_set(&mdev->current_epoch->epoch_size, 0);
29293+ atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29294 D_ASSERT(list_empty(&mdev->current_epoch->list));
29295 }
29296
29297diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29298index 3bba655..6151b66 100644
29299--- a/drivers/block/loop.c
29300+++ b/drivers/block/loop.c
29301@@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29302 mm_segment_t old_fs = get_fs();
29303
29304 set_fs(get_ds());
29305- bw = file->f_op->write(file, buf, len, &pos);
29306+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29307 set_fs(old_fs);
29308 if (likely(bw == len))
29309 return 0;
29310diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29311index ea6f632..eafb192 100644
29312--- a/drivers/char/Kconfig
29313+++ b/drivers/char/Kconfig
29314@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29315
29316 config DEVKMEM
29317 bool "/dev/kmem virtual device support"
29318- default y
29319+ default n
29320+ depends on !GRKERNSEC_KMEM
29321 help
29322 Say Y here if you want to support the /dev/kmem device. The
29323 /dev/kmem device is rarely used, but can be used for certain
29324@@ -581,6 +582,7 @@ config DEVPORT
29325 bool
29326 depends on !M68K
29327 depends on ISA || PCI
29328+ depends on !GRKERNSEC_KMEM
29329 default y
29330
29331 source "drivers/s390/char/Kconfig"
29332diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29333index 2e04433..22afc64 100644
29334--- a/drivers/char/agp/frontend.c
29335+++ b/drivers/char/agp/frontend.c
29336@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29337 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29338 return -EFAULT;
29339
29340- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29341+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29342 return -EFAULT;
29343
29344 client = agp_find_client_by_pid(reserve.pid);
29345diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29346index 21cb980..f15107c 100644
29347--- a/drivers/char/genrtc.c
29348+++ b/drivers/char/genrtc.c
29349@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29350 switch (cmd) {
29351
29352 case RTC_PLL_GET:
29353+ memset(&pll, 0, sizeof(pll));
29354 if (get_rtc_pll(&pll))
29355 return -EINVAL;
29356 else
29357diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29358index dfd7876..c0b0885 100644
29359--- a/drivers/char/hpet.c
29360+++ b/drivers/char/hpet.c
29361@@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29362 }
29363
29364 static int
29365-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29366+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29367 struct hpet_info *info)
29368 {
29369 struct hpet_timer __iomem *timer;
29370diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29371index 2c29942..604c5ba 100644
29372--- a/drivers/char/ipmi/ipmi_msghandler.c
29373+++ b/drivers/char/ipmi/ipmi_msghandler.c
29374@@ -420,7 +420,7 @@ struct ipmi_smi {
29375 struct proc_dir_entry *proc_dir;
29376 char proc_dir_name[10];
29377
29378- atomic_t stats[IPMI_NUM_STATS];
29379+ atomic_unchecked_t stats[IPMI_NUM_STATS];
29380
29381 /*
29382 * run_to_completion duplicate of smb_info, smi_info
29383@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29384
29385
29386 #define ipmi_inc_stat(intf, stat) \
29387- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29388+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29389 #define ipmi_get_stat(intf, stat) \
29390- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29391+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29392
29393 static int is_lan_addr(struct ipmi_addr *addr)
29394 {
29395@@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29396 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29397 init_waitqueue_head(&intf->waitq);
29398 for (i = 0; i < IPMI_NUM_STATS; i++)
29399- atomic_set(&intf->stats[i], 0);
29400+ atomic_set_unchecked(&intf->stats[i], 0);
29401
29402 intf->proc_dir = NULL;
29403
29404diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29405index 1e638ff..a869ef5 100644
29406--- a/drivers/char/ipmi/ipmi_si_intf.c
29407+++ b/drivers/char/ipmi/ipmi_si_intf.c
29408@@ -275,7 +275,7 @@ struct smi_info {
29409 unsigned char slave_addr;
29410
29411 /* Counters and things for the proc filesystem. */
29412- atomic_t stats[SI_NUM_STATS];
29413+ atomic_unchecked_t stats[SI_NUM_STATS];
29414
29415 struct task_struct *thread;
29416
29417@@ -284,9 +284,9 @@ struct smi_info {
29418 };
29419
29420 #define smi_inc_stat(smi, stat) \
29421- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29422+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29423 #define smi_get_stat(smi, stat) \
29424- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29425+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29426
29427 #define SI_MAX_PARMS 4
29428
29429@@ -3209,7 +3209,7 @@ static int try_smi_init(struct smi_info *new_smi)
29430 atomic_set(&new_smi->req_events, 0);
29431 new_smi->run_to_completion = 0;
29432 for (i = 0; i < SI_NUM_STATS; i++)
29433- atomic_set(&new_smi->stats[i], 0);
29434+ atomic_set_unchecked(&new_smi->stats[i], 0);
29435
29436 new_smi->interrupt_disabled = 1;
29437 atomic_set(&new_smi->stop_operation, 0);
29438diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29439index 47ff7e4..0c7d340 100644
29440--- a/drivers/char/mbcs.c
29441+++ b/drivers/char/mbcs.c
29442@@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
29443 return 0;
29444 }
29445
29446-static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29447+static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29448 {
29449 .part_num = MBCS_PART_NUM,
29450 .mfg_num = MBCS_MFG_NUM,
29451diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29452index 67c3371..ba8429d 100644
29453--- a/drivers/char/mem.c
29454+++ b/drivers/char/mem.c
29455@@ -18,6 +18,7 @@
29456 #include <linux/raw.h>
29457 #include <linux/tty.h>
29458 #include <linux/capability.h>
29459+#include <linux/security.h>
29460 #include <linux/ptrace.h>
29461 #include <linux/device.h>
29462 #include <linux/highmem.h>
29463@@ -35,6 +36,10 @@
29464 # include <linux/efi.h>
29465 #endif
29466
29467+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29468+extern const struct file_operations grsec_fops;
29469+#endif
29470+
29471 static inline unsigned long size_inside_page(unsigned long start,
29472 unsigned long size)
29473 {
29474@@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29475
29476 while (cursor < to) {
29477 if (!devmem_is_allowed(pfn)) {
29478+#ifdef CONFIG_GRKERNSEC_KMEM
29479+ gr_handle_mem_readwrite(from, to);
29480+#else
29481 printk(KERN_INFO
29482 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29483 current->comm, from, to);
29484+#endif
29485 return 0;
29486 }
29487 cursor += PAGE_SIZE;
29488@@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29489 }
29490 return 1;
29491 }
29492+#elif defined(CONFIG_GRKERNSEC_KMEM)
29493+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29494+{
29495+ return 0;
29496+}
29497 #else
29498 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29499 {
29500@@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29501
29502 while (count > 0) {
29503 unsigned long remaining;
29504+ char *temp;
29505
29506 sz = size_inside_page(p, count);
29507
29508@@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29509 if (!ptr)
29510 return -EFAULT;
29511
29512- remaining = copy_to_user(buf, ptr, sz);
29513+#ifdef CONFIG_PAX_USERCOPY
29514+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29515+ if (!temp) {
29516+ unxlate_dev_mem_ptr(p, ptr);
29517+ return -ENOMEM;
29518+ }
29519+ memcpy(temp, ptr, sz);
29520+#else
29521+ temp = ptr;
29522+#endif
29523+
29524+ remaining = copy_to_user(buf, temp, sz);
29525+
29526+#ifdef CONFIG_PAX_USERCOPY
29527+ kfree(temp);
29528+#endif
29529+
29530 unxlate_dev_mem_ptr(p, ptr);
29531 if (remaining)
29532 return -EFAULT;
29533@@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29534 size_t count, loff_t *ppos)
29535 {
29536 unsigned long p = *ppos;
29537- ssize_t low_count, read, sz;
29538+ ssize_t low_count, read, sz, err = 0;
29539 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29540- int err = 0;
29541
29542 read = 0;
29543 if (p < (unsigned long) high_memory) {
29544@@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29545 }
29546 #endif
29547 while (low_count > 0) {
29548+ char *temp;
29549+
29550 sz = size_inside_page(p, low_count);
29551
29552 /*
29553@@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29554 */
29555 kbuf = xlate_dev_kmem_ptr((char *)p);
29556
29557- if (copy_to_user(buf, kbuf, sz))
29558+#ifdef CONFIG_PAX_USERCOPY
29559+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29560+ if (!temp)
29561+ return -ENOMEM;
29562+ memcpy(temp, kbuf, sz);
29563+#else
29564+ temp = kbuf;
29565+#endif
29566+
29567+ err = copy_to_user(buf, temp, sz);
29568+
29569+#ifdef CONFIG_PAX_USERCOPY
29570+ kfree(temp);
29571+#endif
29572+
29573+ if (err)
29574 return -EFAULT;
29575 buf += sz;
29576 p += sz;
29577@@ -831,6 +878,9 @@ static const struct memdev {
29578 #ifdef CONFIG_CRASH_DUMP
29579 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29580 #endif
29581+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29582+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29583+#endif
29584 };
29585
29586 static int memory_open(struct inode *inode, struct file *filp)
29587diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29588index 9df78e2..01ba9ae 100644
29589--- a/drivers/char/nvram.c
29590+++ b/drivers/char/nvram.c
29591@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29592
29593 spin_unlock_irq(&rtc_lock);
29594
29595- if (copy_to_user(buf, contents, tmp - contents))
29596+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29597 return -EFAULT;
29598
29599 *ppos = i;
29600diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
29601index 0a484b4..f48ccd1 100644
29602--- a/drivers/char/pcmcia/synclink_cs.c
29603+++ b/drivers/char/pcmcia/synclink_cs.c
29604@@ -2340,9 +2340,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29605
29606 if (debug_level >= DEBUG_LEVEL_INFO)
29607 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
29608- __FILE__,__LINE__, info->device_name, port->count);
29609+ __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
29610
29611- WARN_ON(!port->count);
29612+ WARN_ON(!atomic_read(&port->count));
29613
29614 if (tty_port_close_start(port, tty, filp) == 0)
29615 goto cleanup;
29616@@ -2360,7 +2360,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29617 cleanup:
29618 if (debug_level >= DEBUG_LEVEL_INFO)
29619 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
29620- tty->driver->name, port->count);
29621+ tty->driver->name, atomic_read(&port->count));
29622 }
29623
29624 /* Wait until the transmitter is empty.
29625@@ -2502,7 +2502,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29626
29627 if (debug_level >= DEBUG_LEVEL_INFO)
29628 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
29629- __FILE__,__LINE__,tty->driver->name, port->count);
29630+ __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
29631
29632 /* If port is closing, signal caller to try again */
29633 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
29634@@ -2522,11 +2522,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29635 goto cleanup;
29636 }
29637 spin_lock(&port->lock);
29638- port->count++;
29639+ atomic_inc(&port->count);
29640 spin_unlock(&port->lock);
29641 spin_unlock_irqrestore(&info->netlock, flags);
29642
29643- if (port->count == 1) {
29644+ if (atomic_read(&port->count) == 1) {
29645 /* 1st open on this device, init hardware */
29646 retval = startup(info, tty);
29647 if (retval < 0)
29648@@ -3891,7 +3891,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
29649 unsigned short new_crctype;
29650
29651 /* return error if TTY interface open */
29652- if (info->port.count)
29653+ if (atomic_read(&info->port.count))
29654 return -EBUSY;
29655
29656 switch (encoding)
29657@@ -3994,7 +3994,7 @@ static int hdlcdev_open(struct net_device *dev)
29658
29659 /* arbitrate between network and tty opens */
29660 spin_lock_irqsave(&info->netlock, flags);
29661- if (info->port.count != 0 || info->netcount != 0) {
29662+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
29663 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
29664 spin_unlock_irqrestore(&info->netlock, flags);
29665 return -EBUSY;
29666@@ -4083,7 +4083,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
29667 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
29668
29669 /* return error if TTY interface open */
29670- if (info->port.count)
29671+ if (atomic_read(&info->port.count))
29672 return -EBUSY;
29673
29674 if (cmd != SIOCWANDEV)
29675diff --git a/drivers/char/random.c b/drivers/char/random.c
29676index d98b2a6..f0ceb97 100644
29677--- a/drivers/char/random.c
29678+++ b/drivers/char/random.c
29679@@ -272,8 +272,13 @@
29680 /*
29681 * Configuration information
29682 */
29683+#ifdef CONFIG_GRKERNSEC_RANDNET
29684+#define INPUT_POOL_WORDS 512
29685+#define OUTPUT_POOL_WORDS 128
29686+#else
29687 #define INPUT_POOL_WORDS 128
29688 #define OUTPUT_POOL_WORDS 32
29689+#endif
29690 #define SEC_XFER_SIZE 512
29691 #define EXTRACT_SIZE 10
29692
29693@@ -313,10 +318,17 @@ static struct poolinfo {
29694 int poolwords;
29695 int tap1, tap2, tap3, tap4, tap5;
29696 } poolinfo_table[] = {
29697+#ifdef CONFIG_GRKERNSEC_RANDNET
29698+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29699+ { 512, 411, 308, 208, 104, 1 },
29700+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29701+ { 128, 103, 76, 51, 25, 1 },
29702+#else
29703 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29704 { 128, 103, 76, 51, 25, 1 },
29705 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29706 { 32, 26, 20, 14, 7, 1 },
29707+#endif
29708 #if 0
29709 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29710 { 2048, 1638, 1231, 819, 411, 1 },
29711@@ -527,8 +539,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
29712 input_rotate += i ? 7 : 14;
29713 }
29714
29715- ACCESS_ONCE(r->input_rotate) = input_rotate;
29716- ACCESS_ONCE(r->add_ptr) = i;
29717+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
29718+ ACCESS_ONCE_RW(r->add_ptr) = i;
29719 smp_wmb();
29720
29721 if (out)
29722@@ -799,6 +811,17 @@ void add_disk_randomness(struct gendisk *disk)
29723 }
29724 #endif
29725
29726+#ifdef CONFIG_PAX_LATENT_ENTROPY
29727+u64 latent_entropy;
29728+
29729+__init void transfer_latent_entropy(void)
29730+{
29731+ mix_pool_bytes(&input_pool, &latent_entropy, sizeof(latent_entropy), NULL);
29732+ mix_pool_bytes(&nonblocking_pool, &latent_entropy, sizeof(latent_entropy), NULL);
29733+// printk(KERN_INFO "PAX: transferring latent entropy: %16llx\n", latent_entropy);
29734+}
29735+#endif
29736+
29737 /*********************************************************************
29738 *
29739 * Entropy extraction routines
29740@@ -1008,7 +1031,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29741
29742 extract_buf(r, tmp);
29743 i = min_t(int, nbytes, EXTRACT_SIZE);
29744- if (copy_to_user(buf, tmp, i)) {
29745+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29746 ret = -EFAULT;
29747 break;
29748 }
29749@@ -1342,7 +1365,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29750 #include <linux/sysctl.h>
29751
29752 static int min_read_thresh = 8, min_write_thresh;
29753-static int max_read_thresh = INPUT_POOL_WORDS * 32;
29754+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29755 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29756 static char sysctl_bootid[16];
29757
29758diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
29759index 45713f0..8286d21 100644
29760--- a/drivers/char/sonypi.c
29761+++ b/drivers/char/sonypi.c
29762@@ -54,6 +54,7 @@
29763
29764 #include <asm/uaccess.h>
29765 #include <asm/io.h>
29766+#include <asm/local.h>
29767
29768 #include <linux/sonypi.h>
29769
29770@@ -490,7 +491,7 @@ static struct sonypi_device {
29771 spinlock_t fifo_lock;
29772 wait_queue_head_t fifo_proc_list;
29773 struct fasync_struct *fifo_async;
29774- int open_count;
29775+ local_t open_count;
29776 int model;
29777 struct input_dev *input_jog_dev;
29778 struct input_dev *input_key_dev;
29779@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
29780 static int sonypi_misc_release(struct inode *inode, struct file *file)
29781 {
29782 mutex_lock(&sonypi_device.lock);
29783- sonypi_device.open_count--;
29784+ local_dec(&sonypi_device.open_count);
29785 mutex_unlock(&sonypi_device.lock);
29786 return 0;
29787 }
29788@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
29789 {
29790 mutex_lock(&sonypi_device.lock);
29791 /* Flush input queue on first open */
29792- if (!sonypi_device.open_count)
29793+ if (!local_read(&sonypi_device.open_count))
29794 kfifo_reset(&sonypi_device.fifo);
29795- sonypi_device.open_count++;
29796+ local_inc(&sonypi_device.open_count);
29797 mutex_unlock(&sonypi_device.lock);
29798
29799 return 0;
29800diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
29801index 08427ab..1ab10b7 100644
29802--- a/drivers/char/tpm/tpm.c
29803+++ b/drivers/char/tpm/tpm.c
29804@@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
29805 chip->vendor.req_complete_val)
29806 goto out_recv;
29807
29808- if ((status == chip->vendor.req_canceled)) {
29809+ if (status == chip->vendor.req_canceled) {
29810 dev_err(chip->dev, "Operation Canceled\n");
29811 rc = -ECANCELED;
29812 goto out;
29813diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
29814index 0636520..169c1d0 100644
29815--- a/drivers/char/tpm/tpm_bios.c
29816+++ b/drivers/char/tpm/tpm_bios.c
29817@@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
29818 event = addr;
29819
29820 if ((event->event_type == 0 && event->event_size == 0) ||
29821- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
29822+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
29823 return NULL;
29824
29825 return addr;
29826@@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
29827 return NULL;
29828
29829 if ((event->event_type == 0 && event->event_size == 0) ||
29830- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
29831+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
29832 return NULL;
29833
29834 (*pos)++;
29835@@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
29836 int i;
29837
29838 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
29839- seq_putc(m, data[i]);
29840+ if (!seq_putc(m, data[i]))
29841+ return -EFAULT;
29842
29843 return 0;
29844 }
29845@@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
29846 log->bios_event_log_end = log->bios_event_log + len;
29847
29848 virt = acpi_os_map_memory(start, len);
29849+ if (!virt) {
29850+ kfree(log->bios_event_log);
29851+ log->bios_event_log = NULL;
29852+ return -EFAULT;
29853+ }
29854
29855- memcpy(log->bios_event_log, virt, len);
29856+ memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
29857
29858 acpi_os_unmap_memory(virt, len);
29859 return 0;
29860diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
29861index cdf2f54..e55c197 100644
29862--- a/drivers/char/virtio_console.c
29863+++ b/drivers/char/virtio_console.c
29864@@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
29865 if (to_user) {
29866 ssize_t ret;
29867
29868- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
29869+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
29870 if (ret)
29871 return -EFAULT;
29872 } else {
29873@@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
29874 if (!port_has_data(port) && !port->host_connected)
29875 return 0;
29876
29877- return fill_readbuf(port, ubuf, count, true);
29878+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
29879 }
29880
29881 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
29882diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
29883index 97f5064..202b6e6 100644
29884--- a/drivers/edac/edac_pci_sysfs.c
29885+++ b/drivers/edac/edac_pci_sysfs.c
29886@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
29887 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
29888 static int edac_pci_poll_msec = 1000; /* one second workq period */
29889
29890-static atomic_t pci_parity_count = ATOMIC_INIT(0);
29891-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
29892+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
29893+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
29894
29895 static struct kobject *edac_pci_top_main_kobj;
29896 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
29897@@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29898 edac_printk(KERN_CRIT, EDAC_PCI,
29899 "Signaled System Error on %s\n",
29900 pci_name(dev));
29901- atomic_inc(&pci_nonparity_count);
29902+ atomic_inc_unchecked(&pci_nonparity_count);
29903 }
29904
29905 if (status & (PCI_STATUS_PARITY)) {
29906@@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29907 "Master Data Parity Error on %s\n",
29908 pci_name(dev));
29909
29910- atomic_inc(&pci_parity_count);
29911+ atomic_inc_unchecked(&pci_parity_count);
29912 }
29913
29914 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29915@@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29916 "Detected Parity Error on %s\n",
29917 pci_name(dev));
29918
29919- atomic_inc(&pci_parity_count);
29920+ atomic_inc_unchecked(&pci_parity_count);
29921 }
29922 }
29923
29924@@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29925 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
29926 "Signaled System Error on %s\n",
29927 pci_name(dev));
29928- atomic_inc(&pci_nonparity_count);
29929+ atomic_inc_unchecked(&pci_nonparity_count);
29930 }
29931
29932 if (status & (PCI_STATUS_PARITY)) {
29933@@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29934 "Master Data Parity Error on "
29935 "%s\n", pci_name(dev));
29936
29937- atomic_inc(&pci_parity_count);
29938+ atomic_inc_unchecked(&pci_parity_count);
29939 }
29940
29941 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29942@@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29943 "Detected Parity Error on %s\n",
29944 pci_name(dev));
29945
29946- atomic_inc(&pci_parity_count);
29947+ atomic_inc_unchecked(&pci_parity_count);
29948 }
29949 }
29950 }
29951@@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
29952 if (!check_pci_errors)
29953 return;
29954
29955- before_count = atomic_read(&pci_parity_count);
29956+ before_count = atomic_read_unchecked(&pci_parity_count);
29957
29958 /* scan all PCI devices looking for a Parity Error on devices and
29959 * bridges.
29960@@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
29961 /* Only if operator has selected panic on PCI Error */
29962 if (edac_pci_get_panic_on_pe()) {
29963 /* If the count is different 'after' from 'before' */
29964- if (before_count != atomic_read(&pci_parity_count))
29965+ if (before_count != atomic_read_unchecked(&pci_parity_count))
29966 panic("EDAC: PCI Parity Error");
29967 }
29968 }
29969diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
29970index 8c87a5e..a19cbd7 100644
29971--- a/drivers/edac/mce_amd.h
29972+++ b/drivers/edac/mce_amd.h
29973@@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
29974 struct amd_decoder_ops {
29975 bool (*dc_mce)(u16, u8);
29976 bool (*ic_mce)(u16, u8);
29977-};
29978+} __no_const;
29979
29980 void amd_report_gart_errors(bool);
29981 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
29982diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
29983index 57ea7f4..789e3c3 100644
29984--- a/drivers/firewire/core-card.c
29985+++ b/drivers/firewire/core-card.c
29986@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
29987
29988 void fw_core_remove_card(struct fw_card *card)
29989 {
29990- struct fw_card_driver dummy_driver = dummy_driver_template;
29991+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
29992
29993 card->driver->update_phy_reg(card, 4,
29994 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
29995diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
29996index 2783f69..9f4b0cc 100644
29997--- a/drivers/firewire/core-cdev.c
29998+++ b/drivers/firewire/core-cdev.c
29999@@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
30000 int ret;
30001
30002 if ((request->channels == 0 && request->bandwidth == 0) ||
30003- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
30004- request->bandwidth < 0)
30005+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
30006 return -EINVAL;
30007
30008 r = kmalloc(sizeof(*r), GFP_KERNEL);
30009diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
30010index 780708d..ad60a66 100644
30011--- a/drivers/firewire/core-transaction.c
30012+++ b/drivers/firewire/core-transaction.c
30013@@ -37,6 +37,7 @@
30014 #include <linux/timer.h>
30015 #include <linux/types.h>
30016 #include <linux/workqueue.h>
30017+#include <linux/sched.h>
30018
30019 #include <asm/byteorder.h>
30020
30021diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
30022index 515a42c..5ecf3ba 100644
30023--- a/drivers/firewire/core.h
30024+++ b/drivers/firewire/core.h
30025@@ -111,6 +111,7 @@ struct fw_card_driver {
30026
30027 int (*stop_iso)(struct fw_iso_context *ctx);
30028 };
30029+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
30030
30031 void fw_card_initialize(struct fw_card *card,
30032 const struct fw_card_driver *driver, struct device *device);
30033diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
30034index b298158..7ed8432 100644
30035--- a/drivers/firmware/dmi_scan.c
30036+++ b/drivers/firmware/dmi_scan.c
30037@@ -452,11 +452,6 @@ void __init dmi_scan_machine(void)
30038 }
30039 }
30040 else {
30041- /*
30042- * no iounmap() for that ioremap(); it would be a no-op, but
30043- * it's so early in setup that sucker gets confused into doing
30044- * what it shouldn't if we actually call it.
30045- */
30046 p = dmi_ioremap(0xF0000, 0x10000);
30047 if (p == NULL)
30048 goto error;
30049@@ -726,7 +721,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30050 if (buf == NULL)
30051 return -1;
30052
30053- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30054+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30055
30056 iounmap(buf);
30057 return 0;
30058diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30059index 82d5c20..44a7177 100644
30060--- a/drivers/gpio/gpio-vr41xx.c
30061+++ b/drivers/gpio/gpio-vr41xx.c
30062@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30063 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30064 maskl, pendl, maskh, pendh);
30065
30066- atomic_inc(&irq_err_count);
30067+ atomic_inc_unchecked(&irq_err_count);
30068
30069 return -EINVAL;
30070 }
30071diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30072index 3252e70..b5314ace 100644
30073--- a/drivers/gpu/drm/drm_crtc_helper.c
30074+++ b/drivers/gpu/drm/drm_crtc_helper.c
30075@@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30076 struct drm_crtc *tmp;
30077 int crtc_mask = 1;
30078
30079- WARN(!crtc, "checking null crtc?\n");
30080+ BUG_ON(!crtc);
30081
30082 dev = crtc->dev;
30083
30084diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30085index 8a9d079..606cdd5 100644
30086--- a/drivers/gpu/drm/drm_drv.c
30087+++ b/drivers/gpu/drm/drm_drv.c
30088@@ -318,7 +318,7 @@ module_exit(drm_core_exit);
30089 /**
30090 * Copy and IOCTL return string to user space
30091 */
30092-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30093+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30094 {
30095 int len;
30096
30097@@ -401,7 +401,7 @@ long drm_ioctl(struct file *filp,
30098 return -ENODEV;
30099
30100 atomic_inc(&dev->ioctl_count);
30101- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30102+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30103 ++file_priv->ioctl_count;
30104
30105 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30106diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30107index 123de28..43a0897 100644
30108--- a/drivers/gpu/drm/drm_fops.c
30109+++ b/drivers/gpu/drm/drm_fops.c
30110@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30111 }
30112
30113 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30114- atomic_set(&dev->counts[i], 0);
30115+ atomic_set_unchecked(&dev->counts[i], 0);
30116
30117 dev->sigdata.lock = NULL;
30118
30119@@ -138,8 +138,8 @@ int drm_open(struct inode *inode, struct file *filp)
30120
30121 retcode = drm_open_helper(inode, filp, dev);
30122 if (!retcode) {
30123- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30124- if (!dev->open_count++)
30125+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30126+ if (local_inc_return(&dev->open_count) == 1)
30127 retcode = drm_setup(dev);
30128 }
30129 if (!retcode) {
30130@@ -482,7 +482,7 @@ int drm_release(struct inode *inode, struct file *filp)
30131
30132 mutex_lock(&drm_global_mutex);
30133
30134- DRM_DEBUG("open_count = %d\n", dev->open_count);
30135+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30136
30137 if (dev->driver->preclose)
30138 dev->driver->preclose(dev, file_priv);
30139@@ -491,10 +491,10 @@ int drm_release(struct inode *inode, struct file *filp)
30140 * Begin inline drm_release
30141 */
30142
30143- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30144+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30145 task_pid_nr(current),
30146 (long)old_encode_dev(file_priv->minor->device),
30147- dev->open_count);
30148+ local_read(&dev->open_count));
30149
30150 /* Release any auth tokens that might point to this file_priv,
30151 (do that under the drm_global_mutex) */
30152@@ -584,8 +584,8 @@ int drm_release(struct inode *inode, struct file *filp)
30153 * End inline drm_release
30154 */
30155
30156- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30157- if (!--dev->open_count) {
30158+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30159+ if (local_dec_and_test(&dev->open_count)) {
30160 if (atomic_read(&dev->ioctl_count)) {
30161 DRM_ERROR("Device busy: %d\n",
30162 atomic_read(&dev->ioctl_count));
30163diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30164index c87dc96..326055d 100644
30165--- a/drivers/gpu/drm/drm_global.c
30166+++ b/drivers/gpu/drm/drm_global.c
30167@@ -36,7 +36,7 @@
30168 struct drm_global_item {
30169 struct mutex mutex;
30170 void *object;
30171- int refcount;
30172+ atomic_t refcount;
30173 };
30174
30175 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30176@@ -49,7 +49,7 @@ void drm_global_init(void)
30177 struct drm_global_item *item = &glob[i];
30178 mutex_init(&item->mutex);
30179 item->object = NULL;
30180- item->refcount = 0;
30181+ atomic_set(&item->refcount, 0);
30182 }
30183 }
30184
30185@@ -59,7 +59,7 @@ void drm_global_release(void)
30186 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30187 struct drm_global_item *item = &glob[i];
30188 BUG_ON(item->object != NULL);
30189- BUG_ON(item->refcount != 0);
30190+ BUG_ON(atomic_read(&item->refcount) != 0);
30191 }
30192 }
30193
30194@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30195 void *object;
30196
30197 mutex_lock(&item->mutex);
30198- if (item->refcount == 0) {
30199+ if (atomic_read(&item->refcount) == 0) {
30200 item->object = kzalloc(ref->size, GFP_KERNEL);
30201 if (unlikely(item->object == NULL)) {
30202 ret = -ENOMEM;
30203@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30204 goto out_err;
30205
30206 }
30207- ++item->refcount;
30208+ atomic_inc(&item->refcount);
30209 ref->object = item->object;
30210 object = item->object;
30211 mutex_unlock(&item->mutex);
30212@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30213 struct drm_global_item *item = &glob[ref->global_type];
30214
30215 mutex_lock(&item->mutex);
30216- BUG_ON(item->refcount == 0);
30217+ BUG_ON(atomic_read(&item->refcount) == 0);
30218 BUG_ON(ref->object != item->object);
30219- if (--item->refcount == 0) {
30220+ if (atomic_dec_and_test(&item->refcount)) {
30221 ref->release(ref);
30222 item->object = NULL;
30223 }
30224diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30225index ab1162d..42587b2 100644
30226--- a/drivers/gpu/drm/drm_info.c
30227+++ b/drivers/gpu/drm/drm_info.c
30228@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30229 struct drm_local_map *map;
30230 struct drm_map_list *r_list;
30231
30232- /* Hardcoded from _DRM_FRAME_BUFFER,
30233- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30234- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30235- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30236+ static const char * const types[] = {
30237+ [_DRM_FRAME_BUFFER] = "FB",
30238+ [_DRM_REGISTERS] = "REG",
30239+ [_DRM_SHM] = "SHM",
30240+ [_DRM_AGP] = "AGP",
30241+ [_DRM_SCATTER_GATHER] = "SG",
30242+ [_DRM_CONSISTENT] = "PCI",
30243+ [_DRM_GEM] = "GEM" };
30244 const char *type;
30245 int i;
30246
30247@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30248 map = r_list->map;
30249 if (!map)
30250 continue;
30251- if (map->type < 0 || map->type > 5)
30252+ if (map->type >= ARRAY_SIZE(types))
30253 type = "??";
30254 else
30255 type = types[map->type];
30256@@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30257 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30258 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30259 vma->vm_flags & VM_IO ? 'i' : '-',
30260+#ifdef CONFIG_GRKERNSEC_HIDESYM
30261+ 0);
30262+#else
30263 vma->vm_pgoff);
30264+#endif
30265
30266 #if defined(__i386__)
30267 pgprot = pgprot_val(vma->vm_page_prot);
30268diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30269index 637fcc3..e890b33 100644
30270--- a/drivers/gpu/drm/drm_ioc32.c
30271+++ b/drivers/gpu/drm/drm_ioc32.c
30272@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30273 request = compat_alloc_user_space(nbytes);
30274 if (!access_ok(VERIFY_WRITE, request, nbytes))
30275 return -EFAULT;
30276- list = (struct drm_buf_desc *) (request + 1);
30277+ list = (struct drm_buf_desc __user *) (request + 1);
30278
30279 if (__put_user(count, &request->count)
30280 || __put_user(list, &request->list))
30281@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30282 request = compat_alloc_user_space(nbytes);
30283 if (!access_ok(VERIFY_WRITE, request, nbytes))
30284 return -EFAULT;
30285- list = (struct drm_buf_pub *) (request + 1);
30286+ list = (struct drm_buf_pub __user *) (request + 1);
30287
30288 if (__put_user(count, &request->count)
30289 || __put_user(list, &request->list))
30290diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30291index 64a62c6..ceab35e 100644
30292--- a/drivers/gpu/drm/drm_ioctl.c
30293+++ b/drivers/gpu/drm/drm_ioctl.c
30294@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30295 stats->data[i].value =
30296 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30297 else
30298- stats->data[i].value = atomic_read(&dev->counts[i]);
30299+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30300 stats->data[i].type = dev->types[i];
30301 }
30302
30303diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30304index 5211520..c744d85 100644
30305--- a/drivers/gpu/drm/drm_lock.c
30306+++ b/drivers/gpu/drm/drm_lock.c
30307@@ -90,7 +90,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30308 if (drm_lock_take(&master->lock, lock->context)) {
30309 master->lock.file_priv = file_priv;
30310 master->lock.lock_time = jiffies;
30311- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30312+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30313 break; /* Got lock */
30314 }
30315
30316@@ -161,7 +161,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30317 return -EINVAL;
30318 }
30319
30320- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30321+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30322
30323 if (drm_lock_free(&master->lock, lock->context)) {
30324 /* FIXME: Should really bail out here. */
30325diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30326index 21bcd4a..8e074e0 100644
30327--- a/drivers/gpu/drm/drm_stub.c
30328+++ b/drivers/gpu/drm/drm_stub.c
30329@@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
30330
30331 drm_device_set_unplugged(dev);
30332
30333- if (dev->open_count == 0) {
30334+ if (local_read(&dev->open_count) == 0) {
30335 drm_put_dev(dev);
30336 }
30337 mutex_unlock(&drm_global_mutex);
30338diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30339index fa94391..ed26ec8 100644
30340--- a/drivers/gpu/drm/i810/i810_dma.c
30341+++ b/drivers/gpu/drm/i810/i810_dma.c
30342@@ -943,8 +943,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30343 dma->buflist[vertex->idx],
30344 vertex->discard, vertex->used);
30345
30346- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30347- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30348+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30349+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30350 sarea_priv->last_enqueue = dev_priv->counter - 1;
30351 sarea_priv->last_dispatch = (int)hw_status[5];
30352
30353@@ -1104,8 +1104,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30354 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30355 mc->last_render);
30356
30357- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30358- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30359+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30360+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30361 sarea_priv->last_enqueue = dev_priv->counter - 1;
30362 sarea_priv->last_dispatch = (int)hw_status[5];
30363
30364diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30365index c9339f4..f5e1b9d 100644
30366--- a/drivers/gpu/drm/i810/i810_drv.h
30367+++ b/drivers/gpu/drm/i810/i810_drv.h
30368@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30369 int page_flipping;
30370
30371 wait_queue_head_t irq_queue;
30372- atomic_t irq_received;
30373- atomic_t irq_emitted;
30374+ atomic_unchecked_t irq_received;
30375+ atomic_unchecked_t irq_emitted;
30376
30377 int front_offset;
30378 } drm_i810_private_t;
30379diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30380index 5363e9c..59360d1 100644
30381--- a/drivers/gpu/drm/i915/i915_debugfs.c
30382+++ b/drivers/gpu/drm/i915/i915_debugfs.c
30383@@ -518,7 +518,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30384 I915_READ(GTIMR));
30385 }
30386 seq_printf(m, "Interrupts received: %d\n",
30387- atomic_read(&dev_priv->irq_received));
30388+ atomic_read_unchecked(&dev_priv->irq_received));
30389 for (i = 0; i < I915_NUM_RINGS; i++) {
30390 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30391 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30392diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30393index 36822b9..b725e1b 100644
30394--- a/drivers/gpu/drm/i915/i915_dma.c
30395+++ b/drivers/gpu/drm/i915/i915_dma.c
30396@@ -1266,7 +1266,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30397 bool can_switch;
30398
30399 spin_lock(&dev->count_lock);
30400- can_switch = (dev->open_count == 0);
30401+ can_switch = (local_read(&dev->open_count) == 0);
30402 spin_unlock(&dev->count_lock);
30403 return can_switch;
30404 }
30405diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30406index b0b676a..d107105 100644
30407--- a/drivers/gpu/drm/i915/i915_drv.h
30408+++ b/drivers/gpu/drm/i915/i915_drv.h
30409@@ -268,7 +268,7 @@ struct drm_i915_display_funcs {
30410 /* render clock increase/decrease */
30411 /* display clock increase/decrease */
30412 /* pll clock increase/decrease */
30413-};
30414+} __no_const;
30415
30416 struct intel_device_info {
30417 u8 gen;
30418@@ -386,7 +386,7 @@ typedef struct drm_i915_private {
30419 int current_page;
30420 int page_flipping;
30421
30422- atomic_t irq_received;
30423+ atomic_unchecked_t irq_received;
30424
30425 /* protects the irq masks */
30426 spinlock_t irq_lock;
30427@@ -985,7 +985,7 @@ struct drm_i915_gem_object {
30428 * will be page flipped away on the next vblank. When it
30429 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30430 */
30431- atomic_t pending_flip;
30432+ atomic_unchecked_t pending_flip;
30433 };
30434
30435 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30436@@ -1434,7 +1434,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
30437 struct drm_i915_private *dev_priv, unsigned port);
30438 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30439 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30440-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30441+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30442 {
30443 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30444 }
30445diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30446index 974a9f1..b3ebd45 100644
30447--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30448+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30449@@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30450 i915_gem_clflush_object(obj);
30451
30452 if (obj->base.pending_write_domain)
30453- cd->flips |= atomic_read(&obj->pending_flip);
30454+ cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30455
30456 /* The actual obj->write_domain will be updated with
30457 * pending_write_domain after we emit the accumulated flush for all
30458@@ -916,9 +916,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30459
30460 static int
30461 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30462- int count)
30463+ unsigned int count)
30464 {
30465- int i;
30466+ unsigned int i;
30467
30468 for (i = 0; i < count; i++) {
30469 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30470diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30471index ed3224c..6618589 100644
30472--- a/drivers/gpu/drm/i915/i915_irq.c
30473+++ b/drivers/gpu/drm/i915/i915_irq.c
30474@@ -433,7 +433,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
30475 int vblank = 0;
30476 bool blc_event;
30477
30478- atomic_inc(&dev_priv->irq_received);
30479+ atomic_inc_unchecked(&dev_priv->irq_received);
30480
30481 vblank_status = PIPE_START_VBLANK_INTERRUPT_STATUS |
30482 PIPE_VBLANK_INTERRUPT_STATUS;
30483@@ -586,7 +586,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30484 irqreturn_t ret = IRQ_NONE;
30485 int i;
30486
30487- atomic_inc(&dev_priv->irq_received);
30488+ atomic_inc_unchecked(&dev_priv->irq_received);
30489
30490 /* disable master interrupt before clearing iir */
30491 de_ier = I915_READ(DEIER);
30492@@ -661,7 +661,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30493 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30494 u32 hotplug_mask;
30495
30496- atomic_inc(&dev_priv->irq_received);
30497+ atomic_inc_unchecked(&dev_priv->irq_received);
30498
30499 /* disable master interrupt before clearing iir */
30500 de_ier = I915_READ(DEIER);
30501@@ -1646,7 +1646,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30502 {
30503 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30504
30505- atomic_set(&dev_priv->irq_received, 0);
30506+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30507
30508
30509 I915_WRITE(HWSTAM, 0xeffe);
30510@@ -1673,7 +1673,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
30511 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30512 int pipe;
30513
30514- atomic_set(&dev_priv->irq_received, 0);
30515+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30516
30517 /* VLV magic */
30518 I915_WRITE(VLV_IMR, 0);
30519@@ -1969,7 +1969,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
30520 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30521 int pipe;
30522
30523- atomic_set(&dev_priv->irq_received, 0);
30524+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30525
30526 for_each_pipe(pipe)
30527 I915_WRITE(PIPESTAT(pipe), 0);
30528@@ -2020,7 +2020,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
30529 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
30530 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
30531
30532- atomic_inc(&dev_priv->irq_received);
30533+ atomic_inc_unchecked(&dev_priv->irq_received);
30534
30535 iir = I915_READ16(IIR);
30536 if (iir == 0)
30537@@ -2105,7 +2105,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
30538 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30539 int pipe;
30540
30541- atomic_set(&dev_priv->irq_received, 0);
30542+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30543
30544 if (I915_HAS_HOTPLUG(dev)) {
30545 I915_WRITE(PORT_HOTPLUG_EN, 0);
30546@@ -2200,7 +2200,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
30547 };
30548 int pipe, ret = IRQ_NONE;
30549
30550- atomic_inc(&dev_priv->irq_received);
30551+ atomic_inc_unchecked(&dev_priv->irq_received);
30552
30553 iir = I915_READ(IIR);
30554 do {
30555@@ -2326,7 +2326,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
30556 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30557 int pipe;
30558
30559- atomic_set(&dev_priv->irq_received, 0);
30560+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30561
30562 if (I915_HAS_HOTPLUG(dev)) {
30563 I915_WRITE(PORT_HOTPLUG_EN, 0);
30564@@ -2436,7 +2436,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
30565 int irq_received;
30566 int ret = IRQ_NONE, pipe;
30567
30568- atomic_inc(&dev_priv->irq_received);
30569+ atomic_inc_unchecked(&dev_priv->irq_received);
30570
30571 iir = I915_READ(IIR);
30572
30573diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30574index a8538ac..4868a05 100644
30575--- a/drivers/gpu/drm/i915/intel_display.c
30576+++ b/drivers/gpu/drm/i915/intel_display.c
30577@@ -2000,7 +2000,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
30578
30579 wait_event(dev_priv->pending_flip_queue,
30580 atomic_read(&dev_priv->mm.wedged) ||
30581- atomic_read(&obj->pending_flip) == 0);
30582+ atomic_read_unchecked(&obj->pending_flip) == 0);
30583
30584 /* Big Hammer, we also need to ensure that any pending
30585 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30586@@ -5925,9 +5925,8 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30587
30588 obj = work->old_fb_obj;
30589
30590- atomic_clear_mask(1 << intel_crtc->plane,
30591- &obj->pending_flip.counter);
30592- if (atomic_read(&obj->pending_flip) == 0)
30593+ atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
30594+ if (atomic_read_unchecked(&obj->pending_flip) == 0)
30595 wake_up(&dev_priv->pending_flip_queue);
30596
30597 schedule_work(&work->work);
30598@@ -6264,7 +6263,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30599 /* Block clients from rendering to the new back buffer until
30600 * the flip occurs and the object is no longer visible.
30601 */
30602- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30603+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30604
30605 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30606 if (ret)
30607@@ -6279,7 +6278,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30608 return 0;
30609
30610 cleanup_pending:
30611- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30612+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30613 drm_gem_object_unreference(&work->old_fb_obj->base);
30614 drm_gem_object_unreference(&obj->base);
30615 mutex_unlock(&dev->struct_mutex);
30616diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30617index 54558a0..2d97005 100644
30618--- a/drivers/gpu/drm/mga/mga_drv.h
30619+++ b/drivers/gpu/drm/mga/mga_drv.h
30620@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30621 u32 clear_cmd;
30622 u32 maccess;
30623
30624- atomic_t vbl_received; /**< Number of vblanks received. */
30625+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30626 wait_queue_head_t fence_queue;
30627- atomic_t last_fence_retired;
30628+ atomic_unchecked_t last_fence_retired;
30629 u32 next_fence_to_post;
30630
30631 unsigned int fb_cpp;
30632diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30633index 2581202..f230a8d9 100644
30634--- a/drivers/gpu/drm/mga/mga_irq.c
30635+++ b/drivers/gpu/drm/mga/mga_irq.c
30636@@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30637 if (crtc != 0)
30638 return 0;
30639
30640- return atomic_read(&dev_priv->vbl_received);
30641+ return atomic_read_unchecked(&dev_priv->vbl_received);
30642 }
30643
30644
30645@@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30646 /* VBLANK interrupt */
30647 if (status & MGA_VLINEPEN) {
30648 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30649- atomic_inc(&dev_priv->vbl_received);
30650+ atomic_inc_unchecked(&dev_priv->vbl_received);
30651 drm_handle_vblank(dev, 0);
30652 handled = 1;
30653 }
30654@@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30655 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30656 MGA_WRITE(MGA_PRIMEND, prim_end);
30657
30658- atomic_inc(&dev_priv->last_fence_retired);
30659+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
30660 DRM_WAKEUP(&dev_priv->fence_queue);
30661 handled = 1;
30662 }
30663@@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30664 * using fences.
30665 */
30666 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30667- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30668+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30669 - *sequence) <= (1 << 23)));
30670
30671 *sequence = cur_fence;
30672diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30673index 2f11e16..191267e 100644
30674--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30675+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30676@@ -5340,7 +5340,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30677 struct bit_table {
30678 const char id;
30679 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30680-};
30681+} __no_const;
30682
30683 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30684
30685diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30686index b863a3a..c55e0dc 100644
30687--- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30688+++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30689@@ -302,7 +302,7 @@ struct nouveau_exec_engine {
30690 u32 handle, u16 class);
30691 void (*set_tile_region)(struct drm_device *dev, int i);
30692 void (*tlb_flush)(struct drm_device *, int engine);
30693-};
30694+} __no_const;
30695
30696 struct nouveau_instmem_engine {
30697 void *priv;
30698@@ -324,13 +324,13 @@ struct nouveau_instmem_engine {
30699 struct nouveau_mc_engine {
30700 int (*init)(struct drm_device *dev);
30701 void (*takedown)(struct drm_device *dev);
30702-};
30703+} __no_const;
30704
30705 struct nouveau_timer_engine {
30706 int (*init)(struct drm_device *dev);
30707 void (*takedown)(struct drm_device *dev);
30708 uint64_t (*read)(struct drm_device *dev);
30709-};
30710+} __no_const;
30711
30712 struct nouveau_fb_engine {
30713 int num_tiles;
30714@@ -547,7 +547,7 @@ struct nouveau_vram_engine {
30715 void (*put)(struct drm_device *, struct nouveau_mem **);
30716
30717 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30718-};
30719+} __no_const;
30720
30721 struct nouveau_engine {
30722 struct nouveau_instmem_engine instmem;
30723@@ -693,7 +693,7 @@ struct drm_nouveau_private {
30724 struct drm_global_reference mem_global_ref;
30725 struct ttm_bo_global_ref bo_global_ref;
30726 struct ttm_bo_device bdev;
30727- atomic_t validate_sequence;
30728+ atomic_unchecked_t validate_sequence;
30729 int (*move)(struct nouveau_channel *,
30730 struct ttm_buffer_object *,
30731 struct ttm_mem_reg *, struct ttm_mem_reg *);
30732diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30733index 30f5423..abca136 100644
30734--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30735+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30736@@ -319,7 +319,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30737 int trycnt = 0;
30738 int ret, i;
30739
30740- sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30741+ sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30742 retry:
30743 if (++trycnt > 100000) {
30744 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30745diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30746index 19706f0..f257368 100644
30747--- a/drivers/gpu/drm/nouveau/nouveau_state.c
30748+++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30749@@ -490,7 +490,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30750 bool can_switch;
30751
30752 spin_lock(&dev->count_lock);
30753- can_switch = (dev->open_count == 0);
30754+ can_switch = (local_read(&dev->open_count) == 0);
30755 spin_unlock(&dev->count_lock);
30756 return can_switch;
30757 }
30758diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
30759index a9514ea..369d511 100644
30760--- a/drivers/gpu/drm/nouveau/nv50_sor.c
30761+++ b/drivers/gpu/drm/nouveau/nv50_sor.c
30762@@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
30763 }
30764
30765 if (nv_encoder->dcb->type == OUTPUT_DP) {
30766- struct dp_train_func func = {
30767+ static struct dp_train_func func = {
30768 .link_set = nv50_sor_dp_link_set,
30769 .train_set = nv50_sor_dp_train_set,
30770 .train_adj = nv50_sor_dp_train_adj
30771diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
30772index c486d3c..3a7d6f4 100644
30773--- a/drivers/gpu/drm/nouveau/nvd0_display.c
30774+++ b/drivers/gpu/drm/nouveau/nvd0_display.c
30775@@ -1366,7 +1366,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
30776 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
30777
30778 if (nv_encoder->dcb->type == OUTPUT_DP) {
30779- struct dp_train_func func = {
30780+ static struct dp_train_func func = {
30781 .link_set = nvd0_sor_dp_link_set,
30782 .train_set = nvd0_sor_dp_train_set,
30783 .train_adj = nvd0_sor_dp_train_adj
30784diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
30785index bcac90b..53bfc76 100644
30786--- a/drivers/gpu/drm/r128/r128_cce.c
30787+++ b/drivers/gpu/drm/r128/r128_cce.c
30788@@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
30789
30790 /* GH: Simple idle check.
30791 */
30792- atomic_set(&dev_priv->idle_count, 0);
30793+ atomic_set_unchecked(&dev_priv->idle_count, 0);
30794
30795 /* We don't support anything other than bus-mastering ring mode,
30796 * but the ring can be in either AGP or PCI space for the ring
30797diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
30798index 930c71b..499aded 100644
30799--- a/drivers/gpu/drm/r128/r128_drv.h
30800+++ b/drivers/gpu/drm/r128/r128_drv.h
30801@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
30802 int is_pci;
30803 unsigned long cce_buffers_offset;
30804
30805- atomic_t idle_count;
30806+ atomic_unchecked_t idle_count;
30807
30808 int page_flipping;
30809 int current_page;
30810 u32 crtc_offset;
30811 u32 crtc_offset_cntl;
30812
30813- atomic_t vbl_received;
30814+ atomic_unchecked_t vbl_received;
30815
30816 u32 color_fmt;
30817 unsigned int front_offset;
30818diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
30819index 429d5a0..7e899ed 100644
30820--- a/drivers/gpu/drm/r128/r128_irq.c
30821+++ b/drivers/gpu/drm/r128/r128_irq.c
30822@@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
30823 if (crtc != 0)
30824 return 0;
30825
30826- return atomic_read(&dev_priv->vbl_received);
30827+ return atomic_read_unchecked(&dev_priv->vbl_received);
30828 }
30829
30830 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30831@@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30832 /* VBLANK interrupt */
30833 if (status & R128_CRTC_VBLANK_INT) {
30834 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
30835- atomic_inc(&dev_priv->vbl_received);
30836+ atomic_inc_unchecked(&dev_priv->vbl_received);
30837 drm_handle_vblank(dev, 0);
30838 return IRQ_HANDLED;
30839 }
30840diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
30841index a9e33ce..09edd4b 100644
30842--- a/drivers/gpu/drm/r128/r128_state.c
30843+++ b/drivers/gpu/drm/r128/r128_state.c
30844@@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
30845
30846 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
30847 {
30848- if (atomic_read(&dev_priv->idle_count) == 0)
30849+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
30850 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
30851 else
30852- atomic_set(&dev_priv->idle_count, 0);
30853+ atomic_set_unchecked(&dev_priv->idle_count, 0);
30854 }
30855
30856 #endif
30857diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
30858index 5a82b6b..9e69c73 100644
30859--- a/drivers/gpu/drm/radeon/mkregtable.c
30860+++ b/drivers/gpu/drm/radeon/mkregtable.c
30861@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
30862 regex_t mask_rex;
30863 regmatch_t match[4];
30864 char buf[1024];
30865- size_t end;
30866+ long end;
30867 int len;
30868 int done = 0;
30869 int r;
30870 unsigned o;
30871 struct offset *offset;
30872 char last_reg_s[10];
30873- int last_reg;
30874+ unsigned long last_reg;
30875
30876 if (regcomp
30877 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
30878diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
30879index fefcca5..20a5b90 100644
30880--- a/drivers/gpu/drm/radeon/radeon.h
30881+++ b/drivers/gpu/drm/radeon/radeon.h
30882@@ -743,7 +743,7 @@ struct r600_blit_cp_primitives {
30883 int x2, int y2);
30884 void (*draw_auto)(struct radeon_device *rdev);
30885 void (*set_default_state)(struct radeon_device *rdev);
30886-};
30887+} __no_const;
30888
30889 struct r600_blit {
30890 struct radeon_bo *shader_obj;
30891@@ -1244,7 +1244,7 @@ struct radeon_asic {
30892 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
30893 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
30894 } pflip;
30895-};
30896+} __no_const;
30897
30898 /*
30899 * Asic structures
30900diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
30901index 066c98b..96ab858 100644
30902--- a/drivers/gpu/drm/radeon/radeon_device.c
30903+++ b/drivers/gpu/drm/radeon/radeon_device.c
30904@@ -692,7 +692,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
30905 bool can_switch;
30906
30907 spin_lock(&dev->count_lock);
30908- can_switch = (dev->open_count == 0);
30909+ can_switch = (local_read(&dev->open_count) == 0);
30910 spin_unlock(&dev->count_lock);
30911 return can_switch;
30912 }
30913diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
30914index a1b59ca..86f2d44 100644
30915--- a/drivers/gpu/drm/radeon/radeon_drv.h
30916+++ b/drivers/gpu/drm/radeon/radeon_drv.h
30917@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
30918
30919 /* SW interrupt */
30920 wait_queue_head_t swi_queue;
30921- atomic_t swi_emitted;
30922+ atomic_unchecked_t swi_emitted;
30923 int vblank_crtc;
30924 uint32_t irq_enable_reg;
30925 uint32_t r500_disp_irq_reg;
30926diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
30927index 48b7cea..342236f 100644
30928--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
30929+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
30930@@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
30931 request = compat_alloc_user_space(sizeof(*request));
30932 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
30933 || __put_user(req32.param, &request->param)
30934- || __put_user((void __user *)(unsigned long)req32.value,
30935+ || __put_user((unsigned long)req32.value,
30936 &request->value))
30937 return -EFAULT;
30938
30939diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
30940index 00da384..32f972d 100644
30941--- a/drivers/gpu/drm/radeon/radeon_irq.c
30942+++ b/drivers/gpu/drm/radeon/radeon_irq.c
30943@@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
30944 unsigned int ret;
30945 RING_LOCALS;
30946
30947- atomic_inc(&dev_priv->swi_emitted);
30948- ret = atomic_read(&dev_priv->swi_emitted);
30949+ atomic_inc_unchecked(&dev_priv->swi_emitted);
30950+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
30951
30952 BEGIN_RING(4);
30953 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
30954@@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
30955 drm_radeon_private_t *dev_priv =
30956 (drm_radeon_private_t *) dev->dev_private;
30957
30958- atomic_set(&dev_priv->swi_emitted, 0);
30959+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
30960 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
30961
30962 dev->max_vblank_count = 0x001fffff;
30963diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
30964index e8422ae..d22d4a8 100644
30965--- a/drivers/gpu/drm/radeon/radeon_state.c
30966+++ b/drivers/gpu/drm/radeon/radeon_state.c
30967@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
30968 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
30969 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
30970
30971- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30972+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30973 sarea_priv->nbox * sizeof(depth_boxes[0])))
30974 return -EFAULT;
30975
30976@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
30977 {
30978 drm_radeon_private_t *dev_priv = dev->dev_private;
30979 drm_radeon_getparam_t *param = data;
30980- int value;
30981+ int value = 0;
30982
30983 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
30984
30985diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
30986index c94a225..5795d34 100644
30987--- a/drivers/gpu/drm/radeon/radeon_ttm.c
30988+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
30989@@ -852,8 +852,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
30990 }
30991 if (unlikely(ttm_vm_ops == NULL)) {
30992 ttm_vm_ops = vma->vm_ops;
30993- radeon_ttm_vm_ops = *ttm_vm_ops;
30994- radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30995+ pax_open_kernel();
30996+ memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
30997+ *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
30998+ pax_close_kernel();
30999 }
31000 vma->vm_ops = &radeon_ttm_vm_ops;
31001 return 0;
31002diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31003index 159b6a4..fa82487 100644
31004--- a/drivers/gpu/drm/radeon/rs690.c
31005+++ b/drivers/gpu/drm/radeon/rs690.c
31006@@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31007 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31008 rdev->pm.sideport_bandwidth.full)
31009 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31010- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31011+ read_delay_latency.full = dfixed_const(800 * 1000);
31012 read_delay_latency.full = dfixed_div(read_delay_latency,
31013 rdev->pm.igp_sideport_mclk);
31014+ a.full = dfixed_const(370);
31015+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31016 } else {
31017 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31018 rdev->pm.k8_bandwidth.full)
31019diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31020index ebc6fac..a8313ed 100644
31021--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31022+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31023@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
31024 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31025 struct shrink_control *sc)
31026 {
31027- static atomic_t start_pool = ATOMIC_INIT(0);
31028+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31029 unsigned i;
31030- unsigned pool_offset = atomic_add_return(1, &start_pool);
31031+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31032 struct ttm_page_pool *pool;
31033 int shrink_pages = sc->nr_to_scan;
31034
31035diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31036index 88edacc..1e5412b 100644
31037--- a/drivers/gpu/drm/via/via_drv.h
31038+++ b/drivers/gpu/drm/via/via_drv.h
31039@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31040 typedef uint32_t maskarray_t[5];
31041
31042 typedef struct drm_via_irq {
31043- atomic_t irq_received;
31044+ atomic_unchecked_t irq_received;
31045 uint32_t pending_mask;
31046 uint32_t enable_mask;
31047 wait_queue_head_t irq_queue;
31048@@ -75,7 +75,7 @@ typedef struct drm_via_private {
31049 struct timeval last_vblank;
31050 int last_vblank_valid;
31051 unsigned usec_per_vblank;
31052- atomic_t vbl_received;
31053+ atomic_unchecked_t vbl_received;
31054 drm_via_state_t hc_state;
31055 char pci_buf[VIA_PCI_BUF_SIZE];
31056 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31057diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31058index d391f48..10c8ca3 100644
31059--- a/drivers/gpu/drm/via/via_irq.c
31060+++ b/drivers/gpu/drm/via/via_irq.c
31061@@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31062 if (crtc != 0)
31063 return 0;
31064
31065- return atomic_read(&dev_priv->vbl_received);
31066+ return atomic_read_unchecked(&dev_priv->vbl_received);
31067 }
31068
31069 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31070@@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31071
31072 status = VIA_READ(VIA_REG_INTERRUPT);
31073 if (status & VIA_IRQ_VBLANK_PENDING) {
31074- atomic_inc(&dev_priv->vbl_received);
31075- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31076+ atomic_inc_unchecked(&dev_priv->vbl_received);
31077+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31078 do_gettimeofday(&cur_vblank);
31079 if (dev_priv->last_vblank_valid) {
31080 dev_priv->usec_per_vblank =
31081@@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31082 dev_priv->last_vblank = cur_vblank;
31083 dev_priv->last_vblank_valid = 1;
31084 }
31085- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31086+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31087 DRM_DEBUG("US per vblank is: %u\n",
31088 dev_priv->usec_per_vblank);
31089 }
31090@@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31091
31092 for (i = 0; i < dev_priv->num_irqs; ++i) {
31093 if (status & cur_irq->pending_mask) {
31094- atomic_inc(&cur_irq->irq_received);
31095+ atomic_inc_unchecked(&cur_irq->irq_received);
31096 DRM_WAKEUP(&cur_irq->irq_queue);
31097 handled = 1;
31098 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31099@@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31100 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31101 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31102 masks[irq][4]));
31103- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31104+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31105 } else {
31106 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31107 (((cur_irq_sequence =
31108- atomic_read(&cur_irq->irq_received)) -
31109+ atomic_read_unchecked(&cur_irq->irq_received)) -
31110 *sequence) <= (1 << 23)));
31111 }
31112 *sequence = cur_irq_sequence;
31113@@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31114 }
31115
31116 for (i = 0; i < dev_priv->num_irqs; ++i) {
31117- atomic_set(&cur_irq->irq_received, 0);
31118+ atomic_set_unchecked(&cur_irq->irq_received, 0);
31119 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31120 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31121 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31122@@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31123 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31124 case VIA_IRQ_RELATIVE:
31125 irqwait->request.sequence +=
31126- atomic_read(&cur_irq->irq_received);
31127+ atomic_read_unchecked(&cur_irq->irq_received);
31128 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31129 case VIA_IRQ_ABSOLUTE:
31130 break;
31131diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31132index d0f2c07..9ebd9c3 100644
31133--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31134+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31135@@ -263,7 +263,7 @@ struct vmw_private {
31136 * Fencing and IRQs.
31137 */
31138
31139- atomic_t marker_seq;
31140+ atomic_unchecked_t marker_seq;
31141 wait_queue_head_t fence_queue;
31142 wait_queue_head_t fifo_queue;
31143 int fence_queue_waiters; /* Protected by hw_mutex */
31144diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31145index a0c2f12..68ae6cb 100644
31146--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31147+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31148@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31149 (unsigned int) min,
31150 (unsigned int) fifo->capabilities);
31151
31152- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31153+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31154 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31155 vmw_marker_queue_init(&fifo->marker_queue);
31156 return vmw_fifo_send_fence(dev_priv, &dummy);
31157@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31158 if (reserveable)
31159 iowrite32(bytes, fifo_mem +
31160 SVGA_FIFO_RESERVED);
31161- return fifo_mem + (next_cmd >> 2);
31162+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31163 } else {
31164 need_bounce = true;
31165 }
31166@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31167
31168 fm = vmw_fifo_reserve(dev_priv, bytes);
31169 if (unlikely(fm == NULL)) {
31170- *seqno = atomic_read(&dev_priv->marker_seq);
31171+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31172 ret = -ENOMEM;
31173 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31174 false, 3*HZ);
31175@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31176 }
31177
31178 do {
31179- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31180+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31181 } while (*seqno == 0);
31182
31183 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31184diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31185index cabc95f..14b3d77 100644
31186--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31187+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31188@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31189 * emitted. Then the fence is stale and signaled.
31190 */
31191
31192- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31193+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31194 > VMW_FENCE_WRAP);
31195
31196 return ret;
31197@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31198
31199 if (fifo_idle)
31200 down_read(&fifo_state->rwsem);
31201- signal_seq = atomic_read(&dev_priv->marker_seq);
31202+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31203 ret = 0;
31204
31205 for (;;) {
31206diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31207index 8a8725c..afed796 100644
31208--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31209+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31210@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31211 while (!vmw_lag_lt(queue, us)) {
31212 spin_lock(&queue->lock);
31213 if (list_empty(&queue->head))
31214- seqno = atomic_read(&dev_priv->marker_seq);
31215+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31216 else {
31217 marker = list_first_entry(&queue->head,
31218 struct vmw_marker, head);
31219diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31220index 1f6957c..b579481 100644
31221--- a/drivers/hid/hid-core.c
31222+++ b/drivers/hid/hid-core.c
31223@@ -2153,7 +2153,7 @@ static bool hid_ignore(struct hid_device *hdev)
31224
31225 int hid_add_device(struct hid_device *hdev)
31226 {
31227- static atomic_t id = ATOMIC_INIT(0);
31228+ static atomic_unchecked_t id = ATOMIC_INIT(0);
31229 int ret;
31230
31231 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31232@@ -2188,7 +2188,7 @@ int hid_add_device(struct hid_device *hdev)
31233 /* XXX hack, any other cleaner solution after the driver core
31234 * is converted to allow more than 20 bytes as the device name? */
31235 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31236- hdev->vendor, hdev->product, atomic_inc_return(&id));
31237+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31238
31239 hid_debug_register(hdev, dev_name(&hdev->dev));
31240 ret = device_add(&hdev->dev);
31241diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31242index eec3291..8ed706b 100644
31243--- a/drivers/hid/hid-wiimote-debug.c
31244+++ b/drivers/hid/hid-wiimote-debug.c
31245@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31246 else if (size == 0)
31247 return -EIO;
31248
31249- if (copy_to_user(u, buf, size))
31250+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
31251 return -EFAULT;
31252
31253 *off += size;
31254diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31255index 14599e2..711c965 100644
31256--- a/drivers/hid/usbhid/hiddev.c
31257+++ b/drivers/hid/usbhid/hiddev.c
31258@@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31259 break;
31260
31261 case HIDIOCAPPLICATION:
31262- if (arg < 0 || arg >= hid->maxapplication)
31263+ if (arg >= hid->maxapplication)
31264 break;
31265
31266 for (i = 0; i < hid->maxcollection; i++)
31267diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31268index 4065374..10ed7dc 100644
31269--- a/drivers/hv/channel.c
31270+++ b/drivers/hv/channel.c
31271@@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31272 int ret = 0;
31273 int t;
31274
31275- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31276- atomic_inc(&vmbus_connection.next_gpadl_handle);
31277+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31278+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31279
31280 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31281 if (ret)
31282diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31283index 86f8885..ab9cb2b 100644
31284--- a/drivers/hv/hv.c
31285+++ b/drivers/hv/hv.c
31286@@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31287 u64 output_address = (output) ? virt_to_phys(output) : 0;
31288 u32 output_address_hi = output_address >> 32;
31289 u32 output_address_lo = output_address & 0xFFFFFFFF;
31290- void *hypercall_page = hv_context.hypercall_page;
31291+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31292
31293 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31294 "=a"(hv_status_lo) : "d" (control_hi),
31295diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31296index b9426a6..677ce34 100644
31297--- a/drivers/hv/hyperv_vmbus.h
31298+++ b/drivers/hv/hyperv_vmbus.h
31299@@ -555,7 +555,7 @@ enum vmbus_connect_state {
31300 struct vmbus_connection {
31301 enum vmbus_connect_state conn_state;
31302
31303- atomic_t next_gpadl_handle;
31304+ atomic_unchecked_t next_gpadl_handle;
31305
31306 /*
31307 * Represents channel interrupts. Each bit position represents a
31308diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31309index a220e57..428f54d 100644
31310--- a/drivers/hv/vmbus_drv.c
31311+++ b/drivers/hv/vmbus_drv.c
31312@@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31313 {
31314 int ret = 0;
31315
31316- static atomic_t device_num = ATOMIC_INIT(0);
31317+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31318
31319 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31320- atomic_inc_return(&device_num));
31321+ atomic_inc_return_unchecked(&device_num));
31322
31323 child_device_obj->device.bus = &hv_bus;
31324 child_device_obj->device.parent = &hv_acpi_dev->dev;
31325diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
31326index 34ad5a2..e2b0ae8 100644
31327--- a/drivers/hwmon/acpi_power_meter.c
31328+++ b/drivers/hwmon/acpi_power_meter.c
31329@@ -308,8 +308,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
31330 return res;
31331
31332 temp /= 1000;
31333- if (temp < 0)
31334- return -EINVAL;
31335
31336 mutex_lock(&resource->lock);
31337 resource->trip[attr->index - 7] = temp;
31338diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31339index 8b011d0..3de24a1 100644
31340--- a/drivers/hwmon/sht15.c
31341+++ b/drivers/hwmon/sht15.c
31342@@ -166,7 +166,7 @@ struct sht15_data {
31343 int supply_uV;
31344 bool supply_uV_valid;
31345 struct work_struct update_supply_work;
31346- atomic_t interrupt_handled;
31347+ atomic_unchecked_t interrupt_handled;
31348 };
31349
31350 /**
31351@@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31352 return ret;
31353
31354 gpio_direction_input(data->pdata->gpio_data);
31355- atomic_set(&data->interrupt_handled, 0);
31356+ atomic_set_unchecked(&data->interrupt_handled, 0);
31357
31358 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31359 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31360 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31361 /* Only relevant if the interrupt hasn't occurred. */
31362- if (!atomic_read(&data->interrupt_handled))
31363+ if (!atomic_read_unchecked(&data->interrupt_handled))
31364 schedule_work(&data->read_work);
31365 }
31366 ret = wait_event_timeout(data->wait_queue,
31367@@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31368
31369 /* First disable the interrupt */
31370 disable_irq_nosync(irq);
31371- atomic_inc(&data->interrupt_handled);
31372+ atomic_inc_unchecked(&data->interrupt_handled);
31373 /* Then schedule a reading work struct */
31374 if (data->state != SHT15_READING_NOTHING)
31375 schedule_work(&data->read_work);
31376@@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31377 * If not, then start the interrupt again - care here as could
31378 * have gone low in meantime so verify it hasn't!
31379 */
31380- atomic_set(&data->interrupt_handled, 0);
31381+ atomic_set_unchecked(&data->interrupt_handled, 0);
31382 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31383 /* If still not occurred or another handler was scheduled */
31384 if (gpio_get_value(data->pdata->gpio_data)
31385- || atomic_read(&data->interrupt_handled))
31386+ || atomic_read_unchecked(&data->interrupt_handled))
31387 return;
31388 }
31389
31390diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31391index 378fcb5..5e91fa8 100644
31392--- a/drivers/i2c/busses/i2c-amd756-s4882.c
31393+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31394@@ -43,7 +43,7 @@
31395 extern struct i2c_adapter amd756_smbus;
31396
31397 static struct i2c_adapter *s4882_adapter;
31398-static struct i2c_algorithm *s4882_algo;
31399+static i2c_algorithm_no_const *s4882_algo;
31400
31401 /* Wrapper access functions for multiplexed SMBus */
31402 static DEFINE_MUTEX(amd756_lock);
31403diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31404index 29015eb..af2d8e9 100644
31405--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31406+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31407@@ -41,7 +41,7 @@
31408 extern struct i2c_adapter *nforce2_smbus;
31409
31410 static struct i2c_adapter *s4985_adapter;
31411-static struct i2c_algorithm *s4985_algo;
31412+static i2c_algorithm_no_const *s4985_algo;
31413
31414 /* Wrapper access functions for multiplexed SMBus */
31415 static DEFINE_MUTEX(nforce2_lock);
31416diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31417index 1038c38..eb92f51 100644
31418--- a/drivers/i2c/i2c-mux.c
31419+++ b/drivers/i2c/i2c-mux.c
31420@@ -30,7 +30,7 @@
31421 /* multiplexer per channel data */
31422 struct i2c_mux_priv {
31423 struct i2c_adapter adap;
31424- struct i2c_algorithm algo;
31425+ i2c_algorithm_no_const algo;
31426
31427 struct i2c_adapter *parent;
31428 void *mux_priv; /* the mux chip/device */
31429diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31430index 57d00ca..0145194 100644
31431--- a/drivers/ide/aec62xx.c
31432+++ b/drivers/ide/aec62xx.c
31433@@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31434 .cable_detect = atp86x_cable_detect,
31435 };
31436
31437-static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31438+static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31439 { /* 0: AEC6210 */
31440 .name = DRV_NAME,
31441 .init_chipset = init_chipset_aec62xx,
31442diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31443index 2c8016a..911a27c 100644
31444--- a/drivers/ide/alim15x3.c
31445+++ b/drivers/ide/alim15x3.c
31446@@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31447 .dma_sff_read_status = ide_dma_sff_read_status,
31448 };
31449
31450-static const struct ide_port_info ali15x3_chipset __devinitdata = {
31451+static const struct ide_port_info ali15x3_chipset __devinitconst = {
31452 .name = DRV_NAME,
31453 .init_chipset = init_chipset_ali15x3,
31454 .init_hwif = init_hwif_ali15x3,
31455diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31456index 3747b25..56fc995 100644
31457--- a/drivers/ide/amd74xx.c
31458+++ b/drivers/ide/amd74xx.c
31459@@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31460 .udma_mask = udma, \
31461 }
31462
31463-static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31464+static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31465 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31466 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31467 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31468diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31469index 15f0ead..cb43480 100644
31470--- a/drivers/ide/atiixp.c
31471+++ b/drivers/ide/atiixp.c
31472@@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31473 .cable_detect = atiixp_cable_detect,
31474 };
31475
31476-static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31477+static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31478 { /* 0: IXP200/300/400/700 */
31479 .name = DRV_NAME,
31480 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31481diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31482index 5f80312..d1fc438 100644
31483--- a/drivers/ide/cmd64x.c
31484+++ b/drivers/ide/cmd64x.c
31485@@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31486 .dma_sff_read_status = ide_dma_sff_read_status,
31487 };
31488
31489-static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31490+static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31491 { /* 0: CMD643 */
31492 .name = DRV_NAME,
31493 .init_chipset = init_chipset_cmd64x,
31494diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31495index 2c1e5f7..1444762 100644
31496--- a/drivers/ide/cs5520.c
31497+++ b/drivers/ide/cs5520.c
31498@@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31499 .set_dma_mode = cs5520_set_dma_mode,
31500 };
31501
31502-static const struct ide_port_info cyrix_chipset __devinitdata = {
31503+static const struct ide_port_info cyrix_chipset __devinitconst = {
31504 .name = DRV_NAME,
31505 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31506 .port_ops = &cs5520_port_ops,
31507diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31508index 4dc4eb9..49b40ad 100644
31509--- a/drivers/ide/cs5530.c
31510+++ b/drivers/ide/cs5530.c
31511@@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31512 .udma_filter = cs5530_udma_filter,
31513 };
31514
31515-static const struct ide_port_info cs5530_chipset __devinitdata = {
31516+static const struct ide_port_info cs5530_chipset __devinitconst = {
31517 .name = DRV_NAME,
31518 .init_chipset = init_chipset_cs5530,
31519 .init_hwif = init_hwif_cs5530,
31520diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31521index 5059faf..18d4c85 100644
31522--- a/drivers/ide/cs5535.c
31523+++ b/drivers/ide/cs5535.c
31524@@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31525 .cable_detect = cs5535_cable_detect,
31526 };
31527
31528-static const struct ide_port_info cs5535_chipset __devinitdata = {
31529+static const struct ide_port_info cs5535_chipset __devinitconst = {
31530 .name = DRV_NAME,
31531 .port_ops = &cs5535_port_ops,
31532 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31533diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31534index 847553f..3ffb49d 100644
31535--- a/drivers/ide/cy82c693.c
31536+++ b/drivers/ide/cy82c693.c
31537@@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31538 .set_dma_mode = cy82c693_set_dma_mode,
31539 };
31540
31541-static const struct ide_port_info cy82c693_chipset __devinitdata = {
31542+static const struct ide_port_info cy82c693_chipset __devinitconst = {
31543 .name = DRV_NAME,
31544 .init_iops = init_iops_cy82c693,
31545 .port_ops = &cy82c693_port_ops,
31546diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31547index 58c51cd..4aec3b8 100644
31548--- a/drivers/ide/hpt366.c
31549+++ b/drivers/ide/hpt366.c
31550@@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31551 }
31552 };
31553
31554-static const struct hpt_info hpt36x __devinitdata = {
31555+static const struct hpt_info hpt36x __devinitconst = {
31556 .chip_name = "HPT36x",
31557 .chip_type = HPT36x,
31558 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31559@@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31560 .timings = &hpt36x_timings
31561 };
31562
31563-static const struct hpt_info hpt370 __devinitdata = {
31564+static const struct hpt_info hpt370 __devinitconst = {
31565 .chip_name = "HPT370",
31566 .chip_type = HPT370,
31567 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31568@@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31569 .timings = &hpt37x_timings
31570 };
31571
31572-static const struct hpt_info hpt370a __devinitdata = {
31573+static const struct hpt_info hpt370a __devinitconst = {
31574 .chip_name = "HPT370A",
31575 .chip_type = HPT370A,
31576 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31577@@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31578 .timings = &hpt37x_timings
31579 };
31580
31581-static const struct hpt_info hpt374 __devinitdata = {
31582+static const struct hpt_info hpt374 __devinitconst = {
31583 .chip_name = "HPT374",
31584 .chip_type = HPT374,
31585 .udma_mask = ATA_UDMA5,
31586@@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31587 .timings = &hpt37x_timings
31588 };
31589
31590-static const struct hpt_info hpt372 __devinitdata = {
31591+static const struct hpt_info hpt372 __devinitconst = {
31592 .chip_name = "HPT372",
31593 .chip_type = HPT372,
31594 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31595@@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31596 .timings = &hpt37x_timings
31597 };
31598
31599-static const struct hpt_info hpt372a __devinitdata = {
31600+static const struct hpt_info hpt372a __devinitconst = {
31601 .chip_name = "HPT372A",
31602 .chip_type = HPT372A,
31603 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31604@@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31605 .timings = &hpt37x_timings
31606 };
31607
31608-static const struct hpt_info hpt302 __devinitdata = {
31609+static const struct hpt_info hpt302 __devinitconst = {
31610 .chip_name = "HPT302",
31611 .chip_type = HPT302,
31612 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31613@@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31614 .timings = &hpt37x_timings
31615 };
31616
31617-static const struct hpt_info hpt371 __devinitdata = {
31618+static const struct hpt_info hpt371 __devinitconst = {
31619 .chip_name = "HPT371",
31620 .chip_type = HPT371,
31621 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31622@@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31623 .timings = &hpt37x_timings
31624 };
31625
31626-static const struct hpt_info hpt372n __devinitdata = {
31627+static const struct hpt_info hpt372n __devinitconst = {
31628 .chip_name = "HPT372N",
31629 .chip_type = HPT372N,
31630 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31631@@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31632 .timings = &hpt37x_timings
31633 };
31634
31635-static const struct hpt_info hpt302n __devinitdata = {
31636+static const struct hpt_info hpt302n __devinitconst = {
31637 .chip_name = "HPT302N",
31638 .chip_type = HPT302N,
31639 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31640@@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31641 .timings = &hpt37x_timings
31642 };
31643
31644-static const struct hpt_info hpt371n __devinitdata = {
31645+static const struct hpt_info hpt371n __devinitconst = {
31646 .chip_name = "HPT371N",
31647 .chip_type = HPT371N,
31648 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31649@@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31650 .dma_sff_read_status = ide_dma_sff_read_status,
31651 };
31652
31653-static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31654+static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31655 { /* 0: HPT36x */
31656 .name = DRV_NAME,
31657 .init_chipset = init_chipset_hpt366,
31658diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31659index 8126824..55a2798 100644
31660--- a/drivers/ide/ide-cd.c
31661+++ b/drivers/ide/ide-cd.c
31662@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31663 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31664 if ((unsigned long)buf & alignment
31665 || blk_rq_bytes(rq) & q->dma_pad_mask
31666- || object_is_on_stack(buf))
31667+ || object_starts_on_stack(buf))
31668 drive->dma = 0;
31669 }
31670 }
31671diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31672index 7f56b73..dab5b67 100644
31673--- a/drivers/ide/ide-pci-generic.c
31674+++ b/drivers/ide/ide-pci-generic.c
31675@@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31676 .udma_mask = ATA_UDMA6, \
31677 }
31678
31679-static const struct ide_port_info generic_chipsets[] __devinitdata = {
31680+static const struct ide_port_info generic_chipsets[] __devinitconst = {
31681 /* 0: Unknown */
31682 DECLARE_GENERIC_PCI_DEV(0),
31683
31684diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31685index 560e66d..d5dd180 100644
31686--- a/drivers/ide/it8172.c
31687+++ b/drivers/ide/it8172.c
31688@@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31689 .set_dma_mode = it8172_set_dma_mode,
31690 };
31691
31692-static const struct ide_port_info it8172_port_info __devinitdata = {
31693+static const struct ide_port_info it8172_port_info __devinitconst = {
31694 .name = DRV_NAME,
31695 .port_ops = &it8172_port_ops,
31696 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31697diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31698index 46816ba..1847aeb 100644
31699--- a/drivers/ide/it8213.c
31700+++ b/drivers/ide/it8213.c
31701@@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31702 .cable_detect = it8213_cable_detect,
31703 };
31704
31705-static const struct ide_port_info it8213_chipset __devinitdata = {
31706+static const struct ide_port_info it8213_chipset __devinitconst = {
31707 .name = DRV_NAME,
31708 .enablebits = { {0x41, 0x80, 0x80} },
31709 .port_ops = &it8213_port_ops,
31710diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31711index 2e3169f..c5611db 100644
31712--- a/drivers/ide/it821x.c
31713+++ b/drivers/ide/it821x.c
31714@@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31715 .cable_detect = it821x_cable_detect,
31716 };
31717
31718-static const struct ide_port_info it821x_chipset __devinitdata = {
31719+static const struct ide_port_info it821x_chipset __devinitconst = {
31720 .name = DRV_NAME,
31721 .init_chipset = init_chipset_it821x,
31722 .init_hwif = init_hwif_it821x,
31723diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31724index 74c2c4a..efddd7d 100644
31725--- a/drivers/ide/jmicron.c
31726+++ b/drivers/ide/jmicron.c
31727@@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31728 .cable_detect = jmicron_cable_detect,
31729 };
31730
31731-static const struct ide_port_info jmicron_chipset __devinitdata = {
31732+static const struct ide_port_info jmicron_chipset __devinitconst = {
31733 .name = DRV_NAME,
31734 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31735 .port_ops = &jmicron_port_ops,
31736diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31737index 95327a2..73f78d8 100644
31738--- a/drivers/ide/ns87415.c
31739+++ b/drivers/ide/ns87415.c
31740@@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31741 .dma_sff_read_status = superio_dma_sff_read_status,
31742 };
31743
31744-static const struct ide_port_info ns87415_chipset __devinitdata = {
31745+static const struct ide_port_info ns87415_chipset __devinitconst = {
31746 .name = DRV_NAME,
31747 .init_hwif = init_hwif_ns87415,
31748 .tp_ops = &ns87415_tp_ops,
31749diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31750index 1a53a4c..39edc66 100644
31751--- a/drivers/ide/opti621.c
31752+++ b/drivers/ide/opti621.c
31753@@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31754 .set_pio_mode = opti621_set_pio_mode,
31755 };
31756
31757-static const struct ide_port_info opti621_chipset __devinitdata = {
31758+static const struct ide_port_info opti621_chipset __devinitconst = {
31759 .name = DRV_NAME,
31760 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31761 .port_ops = &opti621_port_ops,
31762diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31763index 9546fe2..2e5ceb6 100644
31764--- a/drivers/ide/pdc202xx_new.c
31765+++ b/drivers/ide/pdc202xx_new.c
31766@@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
31767 .udma_mask = udma, \
31768 }
31769
31770-static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
31771+static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
31772 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
31773 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
31774 };
31775diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
31776index 3a35ec6..5634510 100644
31777--- a/drivers/ide/pdc202xx_old.c
31778+++ b/drivers/ide/pdc202xx_old.c
31779@@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
31780 .max_sectors = sectors, \
31781 }
31782
31783-static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
31784+static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
31785 { /* 0: PDC20246 */
31786 .name = DRV_NAME,
31787 .init_chipset = init_chipset_pdc202xx,
31788diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
31789index 1892e81..fe0fd60 100644
31790--- a/drivers/ide/piix.c
31791+++ b/drivers/ide/piix.c
31792@@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
31793 .udma_mask = udma, \
31794 }
31795
31796-static const struct ide_port_info piix_pci_info[] __devinitdata = {
31797+static const struct ide_port_info piix_pci_info[] __devinitconst = {
31798 /* 0: MPIIX */
31799 { /*
31800 * MPIIX actually has only a single IDE channel mapped to
31801diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
31802index a6414a8..c04173e 100644
31803--- a/drivers/ide/rz1000.c
31804+++ b/drivers/ide/rz1000.c
31805@@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
31806 }
31807 }
31808
31809-static const struct ide_port_info rz1000_chipset __devinitdata = {
31810+static const struct ide_port_info rz1000_chipset __devinitconst = {
31811 .name = DRV_NAME,
31812 .host_flags = IDE_HFLAG_NO_DMA,
31813 };
31814diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
31815index 356b9b5..d4758eb 100644
31816--- a/drivers/ide/sc1200.c
31817+++ b/drivers/ide/sc1200.c
31818@@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
31819 .dma_sff_read_status = ide_dma_sff_read_status,
31820 };
31821
31822-static const struct ide_port_info sc1200_chipset __devinitdata = {
31823+static const struct ide_port_info sc1200_chipset __devinitconst = {
31824 .name = DRV_NAME,
31825 .port_ops = &sc1200_port_ops,
31826 .dma_ops = &sc1200_dma_ops,
31827diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
31828index b7f5b0c..9701038 100644
31829--- a/drivers/ide/scc_pata.c
31830+++ b/drivers/ide/scc_pata.c
31831@@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
31832 .dma_sff_read_status = scc_dma_sff_read_status,
31833 };
31834
31835-static const struct ide_port_info scc_chipset __devinitdata = {
31836+static const struct ide_port_info scc_chipset __devinitconst = {
31837 .name = "sccIDE",
31838 .init_iops = init_iops_scc,
31839 .init_dma = scc_init_dma,
31840diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
31841index 35fb8da..24d72ef 100644
31842--- a/drivers/ide/serverworks.c
31843+++ b/drivers/ide/serverworks.c
31844@@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
31845 .cable_detect = svwks_cable_detect,
31846 };
31847
31848-static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
31849+static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
31850 { /* 0: OSB4 */
31851 .name = DRV_NAME,
31852 .init_chipset = init_chipset_svwks,
31853diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
31854index ddeda44..46f7e30 100644
31855--- a/drivers/ide/siimage.c
31856+++ b/drivers/ide/siimage.c
31857@@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
31858 .udma_mask = ATA_UDMA6, \
31859 }
31860
31861-static const struct ide_port_info siimage_chipsets[] __devinitdata = {
31862+static const struct ide_port_info siimage_chipsets[] __devinitconst = {
31863 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
31864 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
31865 };
31866diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
31867index 4a00225..09e61b4 100644
31868--- a/drivers/ide/sis5513.c
31869+++ b/drivers/ide/sis5513.c
31870@@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
31871 .cable_detect = sis_cable_detect,
31872 };
31873
31874-static const struct ide_port_info sis5513_chipset __devinitdata = {
31875+static const struct ide_port_info sis5513_chipset __devinitconst = {
31876 .name = DRV_NAME,
31877 .init_chipset = init_chipset_sis5513,
31878 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
31879diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
31880index f21dc2a..d051cd2 100644
31881--- a/drivers/ide/sl82c105.c
31882+++ b/drivers/ide/sl82c105.c
31883@@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
31884 .dma_sff_read_status = ide_dma_sff_read_status,
31885 };
31886
31887-static const struct ide_port_info sl82c105_chipset __devinitdata = {
31888+static const struct ide_port_info sl82c105_chipset __devinitconst = {
31889 .name = DRV_NAME,
31890 .init_chipset = init_chipset_sl82c105,
31891 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
31892diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
31893index 864ffe0..863a5e9 100644
31894--- a/drivers/ide/slc90e66.c
31895+++ b/drivers/ide/slc90e66.c
31896@@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
31897 .cable_detect = slc90e66_cable_detect,
31898 };
31899
31900-static const struct ide_port_info slc90e66_chipset __devinitdata = {
31901+static const struct ide_port_info slc90e66_chipset __devinitconst = {
31902 .name = DRV_NAME,
31903 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
31904 .port_ops = &slc90e66_port_ops,
31905diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
31906index 4799d5c..1794678 100644
31907--- a/drivers/ide/tc86c001.c
31908+++ b/drivers/ide/tc86c001.c
31909@@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
31910 .dma_sff_read_status = ide_dma_sff_read_status,
31911 };
31912
31913-static const struct ide_port_info tc86c001_chipset __devinitdata = {
31914+static const struct ide_port_info tc86c001_chipset __devinitconst = {
31915 .name = DRV_NAME,
31916 .init_hwif = init_hwif_tc86c001,
31917 .port_ops = &tc86c001_port_ops,
31918diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
31919index 281c914..55ce1b8 100644
31920--- a/drivers/ide/triflex.c
31921+++ b/drivers/ide/triflex.c
31922@@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
31923 .set_dma_mode = triflex_set_mode,
31924 };
31925
31926-static const struct ide_port_info triflex_device __devinitdata = {
31927+static const struct ide_port_info triflex_device __devinitconst = {
31928 .name = DRV_NAME,
31929 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
31930 .port_ops = &triflex_port_ops,
31931diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
31932index 4b42ca0..e494a98 100644
31933--- a/drivers/ide/trm290.c
31934+++ b/drivers/ide/trm290.c
31935@@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
31936 .dma_check = trm290_dma_check,
31937 };
31938
31939-static const struct ide_port_info trm290_chipset __devinitdata = {
31940+static const struct ide_port_info trm290_chipset __devinitconst = {
31941 .name = DRV_NAME,
31942 .init_hwif = init_hwif_trm290,
31943 .tp_ops = &trm290_tp_ops,
31944diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
31945index f46f49c..eb77678 100644
31946--- a/drivers/ide/via82cxxx.c
31947+++ b/drivers/ide/via82cxxx.c
31948@@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
31949 .cable_detect = via82cxxx_cable_detect,
31950 };
31951
31952-static const struct ide_port_info via82cxxx_chipset __devinitdata = {
31953+static const struct ide_port_info via82cxxx_chipset __devinitconst = {
31954 .name = DRV_NAME,
31955 .init_chipset = init_chipset_via82cxxx,
31956 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
31957diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
31958index 73d4531..c90cd2d 100644
31959--- a/drivers/ieee802154/fakehard.c
31960+++ b/drivers/ieee802154/fakehard.c
31961@@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
31962 phy->transmit_power = 0xbf;
31963
31964 dev->netdev_ops = &fake_ops;
31965- dev->ml_priv = &fake_mlme;
31966+ dev->ml_priv = (void *)&fake_mlme;
31967
31968 priv = netdev_priv(dev);
31969 priv->phy = phy;
31970diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
31971index c889aae..6cf5aa7 100644
31972--- a/drivers/infiniband/core/cm.c
31973+++ b/drivers/infiniband/core/cm.c
31974@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
31975
31976 struct cm_counter_group {
31977 struct kobject obj;
31978- atomic_long_t counter[CM_ATTR_COUNT];
31979+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
31980 };
31981
31982 struct cm_counter_attribute {
31983@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
31984 struct ib_mad_send_buf *msg = NULL;
31985 int ret;
31986
31987- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31988+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31989 counter[CM_REQ_COUNTER]);
31990
31991 /* Quick state check to discard duplicate REQs. */
31992@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
31993 if (!cm_id_priv)
31994 return;
31995
31996- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
31997+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
31998 counter[CM_REP_COUNTER]);
31999 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
32000 if (ret)
32001@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32002 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32003 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32004 spin_unlock_irq(&cm_id_priv->lock);
32005- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32006+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32007 counter[CM_RTU_COUNTER]);
32008 goto out;
32009 }
32010@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32011 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32012 dreq_msg->local_comm_id);
32013 if (!cm_id_priv) {
32014- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32015+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32016 counter[CM_DREQ_COUNTER]);
32017 cm_issue_drep(work->port, work->mad_recv_wc);
32018 return -EINVAL;
32019@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32020 case IB_CM_MRA_REP_RCVD:
32021 break;
32022 case IB_CM_TIMEWAIT:
32023- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32024+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32025 counter[CM_DREQ_COUNTER]);
32026 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32027 goto unlock;
32028@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32029 cm_free_msg(msg);
32030 goto deref;
32031 case IB_CM_DREQ_RCVD:
32032- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32033+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32034 counter[CM_DREQ_COUNTER]);
32035 goto unlock;
32036 default:
32037@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32038 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32039 cm_id_priv->msg, timeout)) {
32040 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32041- atomic_long_inc(&work->port->
32042+ atomic_long_inc_unchecked(&work->port->
32043 counter_group[CM_RECV_DUPLICATES].
32044 counter[CM_MRA_COUNTER]);
32045 goto out;
32046@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32047 break;
32048 case IB_CM_MRA_REQ_RCVD:
32049 case IB_CM_MRA_REP_RCVD:
32050- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32051+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32052 counter[CM_MRA_COUNTER]);
32053 /* fall through */
32054 default:
32055@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32056 case IB_CM_LAP_IDLE:
32057 break;
32058 case IB_CM_MRA_LAP_SENT:
32059- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32060+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32061 counter[CM_LAP_COUNTER]);
32062 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32063 goto unlock;
32064@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32065 cm_free_msg(msg);
32066 goto deref;
32067 case IB_CM_LAP_RCVD:
32068- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32069+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32070 counter[CM_LAP_COUNTER]);
32071 goto unlock;
32072 default:
32073@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32074 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32075 if (cur_cm_id_priv) {
32076 spin_unlock_irq(&cm.lock);
32077- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32078+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32079 counter[CM_SIDR_REQ_COUNTER]);
32080 goto out; /* Duplicate message. */
32081 }
32082@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32083 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32084 msg->retries = 1;
32085
32086- atomic_long_add(1 + msg->retries,
32087+ atomic_long_add_unchecked(1 + msg->retries,
32088 &port->counter_group[CM_XMIT].counter[attr_index]);
32089 if (msg->retries)
32090- atomic_long_add(msg->retries,
32091+ atomic_long_add_unchecked(msg->retries,
32092 &port->counter_group[CM_XMIT_RETRIES].
32093 counter[attr_index]);
32094
32095@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32096 }
32097
32098 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32099- atomic_long_inc(&port->counter_group[CM_RECV].
32100+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32101 counter[attr_id - CM_ATTR_ID_OFFSET]);
32102
32103 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32104@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32105 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32106
32107 return sprintf(buf, "%ld\n",
32108- atomic_long_read(&group->counter[cm_attr->index]));
32109+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32110 }
32111
32112 static const struct sysfs_ops cm_counter_ops = {
32113diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32114index 176c8f9..2627b62 100644
32115--- a/drivers/infiniband/core/fmr_pool.c
32116+++ b/drivers/infiniband/core/fmr_pool.c
32117@@ -98,8 +98,8 @@ struct ib_fmr_pool {
32118
32119 struct task_struct *thread;
32120
32121- atomic_t req_ser;
32122- atomic_t flush_ser;
32123+ atomic_unchecked_t req_ser;
32124+ atomic_unchecked_t flush_ser;
32125
32126 wait_queue_head_t force_wait;
32127 };
32128@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32129 struct ib_fmr_pool *pool = pool_ptr;
32130
32131 do {
32132- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32133+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32134 ib_fmr_batch_release(pool);
32135
32136- atomic_inc(&pool->flush_ser);
32137+ atomic_inc_unchecked(&pool->flush_ser);
32138 wake_up_interruptible(&pool->force_wait);
32139
32140 if (pool->flush_function)
32141@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32142 }
32143
32144 set_current_state(TASK_INTERRUPTIBLE);
32145- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32146+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32147 !kthread_should_stop())
32148 schedule();
32149 __set_current_state(TASK_RUNNING);
32150@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32151 pool->dirty_watermark = params->dirty_watermark;
32152 pool->dirty_len = 0;
32153 spin_lock_init(&pool->pool_lock);
32154- atomic_set(&pool->req_ser, 0);
32155- atomic_set(&pool->flush_ser, 0);
32156+ atomic_set_unchecked(&pool->req_ser, 0);
32157+ atomic_set_unchecked(&pool->flush_ser, 0);
32158 init_waitqueue_head(&pool->force_wait);
32159
32160 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32161@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32162 }
32163 spin_unlock_irq(&pool->pool_lock);
32164
32165- serial = atomic_inc_return(&pool->req_ser);
32166+ serial = atomic_inc_return_unchecked(&pool->req_ser);
32167 wake_up_process(pool->thread);
32168
32169 if (wait_event_interruptible(pool->force_wait,
32170- atomic_read(&pool->flush_ser) - serial >= 0))
32171+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32172 return -EINTR;
32173
32174 return 0;
32175@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32176 } else {
32177 list_add_tail(&fmr->list, &pool->dirty_list);
32178 if (++pool->dirty_len >= pool->dirty_watermark) {
32179- atomic_inc(&pool->req_ser);
32180+ atomic_inc_unchecked(&pool->req_ser);
32181 wake_up_process(pool->thread);
32182 }
32183 }
32184diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32185index 57e07c6..56d09d4 100644
32186--- a/drivers/infiniband/hw/cxgb4/mem.c
32187+++ b/drivers/infiniband/hw/cxgb4/mem.c
32188@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32189 int err;
32190 struct fw_ri_tpte tpt;
32191 u32 stag_idx;
32192- static atomic_t key;
32193+ static atomic_unchecked_t key;
32194
32195 if (c4iw_fatal_error(rdev))
32196 return -EIO;
32197@@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32198 if (rdev->stats.stag.cur > rdev->stats.stag.max)
32199 rdev->stats.stag.max = rdev->stats.stag.cur;
32200 mutex_unlock(&rdev->stats.lock);
32201- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32202+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32203 }
32204 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32205 __func__, stag_state, type, pdid, stag_idx);
32206diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32207index 79b3dbc..96e5fcc 100644
32208--- a/drivers/infiniband/hw/ipath/ipath_rc.c
32209+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32210@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32211 struct ib_atomic_eth *ateth;
32212 struct ipath_ack_entry *e;
32213 u64 vaddr;
32214- atomic64_t *maddr;
32215+ atomic64_unchecked_t *maddr;
32216 u64 sdata;
32217 u32 rkey;
32218 u8 next;
32219@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32220 IB_ACCESS_REMOTE_ATOMIC)))
32221 goto nack_acc_unlck;
32222 /* Perform atomic OP and save result. */
32223- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32224+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32225 sdata = be64_to_cpu(ateth->swap_data);
32226 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32227 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32228- (u64) atomic64_add_return(sdata, maddr) - sdata :
32229+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32230 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32231 be64_to_cpu(ateth->compare_data),
32232 sdata);
32233diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32234index 1f95bba..9530f87 100644
32235--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32236+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32237@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32238 unsigned long flags;
32239 struct ib_wc wc;
32240 u64 sdata;
32241- atomic64_t *maddr;
32242+ atomic64_unchecked_t *maddr;
32243 enum ib_wc_status send_status;
32244
32245 /*
32246@@ -382,11 +382,11 @@ again:
32247 IB_ACCESS_REMOTE_ATOMIC)))
32248 goto acc_err;
32249 /* Perform atomic OP and save result. */
32250- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32251+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32252 sdata = wqe->wr.wr.atomic.compare_add;
32253 *(u64 *) sqp->s_sge.sge.vaddr =
32254 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32255- (u64) atomic64_add_return(sdata, maddr) - sdata :
32256+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32257 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32258 sdata, wqe->wr.wr.atomic.swap);
32259 goto send_comp;
32260diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32261index 7140199..da60063 100644
32262--- a/drivers/infiniband/hw/nes/nes.c
32263+++ b/drivers/infiniband/hw/nes/nes.c
32264@@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32265 LIST_HEAD(nes_adapter_list);
32266 static LIST_HEAD(nes_dev_list);
32267
32268-atomic_t qps_destroyed;
32269+atomic_unchecked_t qps_destroyed;
32270
32271 static unsigned int ee_flsh_adapter;
32272 static unsigned int sysfs_nonidx_addr;
32273@@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32274 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32275 struct nes_adapter *nesadapter = nesdev->nesadapter;
32276
32277- atomic_inc(&qps_destroyed);
32278+ atomic_inc_unchecked(&qps_destroyed);
32279
32280 /* Free the control structures */
32281
32282diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32283index c438e46..ca30356 100644
32284--- a/drivers/infiniband/hw/nes/nes.h
32285+++ b/drivers/infiniband/hw/nes/nes.h
32286@@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32287 extern unsigned int wqm_quanta;
32288 extern struct list_head nes_adapter_list;
32289
32290-extern atomic_t cm_connects;
32291-extern atomic_t cm_accepts;
32292-extern atomic_t cm_disconnects;
32293-extern atomic_t cm_closes;
32294-extern atomic_t cm_connecteds;
32295-extern atomic_t cm_connect_reqs;
32296-extern atomic_t cm_rejects;
32297-extern atomic_t mod_qp_timouts;
32298-extern atomic_t qps_created;
32299-extern atomic_t qps_destroyed;
32300-extern atomic_t sw_qps_destroyed;
32301+extern atomic_unchecked_t cm_connects;
32302+extern atomic_unchecked_t cm_accepts;
32303+extern atomic_unchecked_t cm_disconnects;
32304+extern atomic_unchecked_t cm_closes;
32305+extern atomic_unchecked_t cm_connecteds;
32306+extern atomic_unchecked_t cm_connect_reqs;
32307+extern atomic_unchecked_t cm_rejects;
32308+extern atomic_unchecked_t mod_qp_timouts;
32309+extern atomic_unchecked_t qps_created;
32310+extern atomic_unchecked_t qps_destroyed;
32311+extern atomic_unchecked_t sw_qps_destroyed;
32312 extern u32 mh_detected;
32313 extern u32 mh_pauses_sent;
32314 extern u32 cm_packets_sent;
32315@@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32316 extern u32 cm_packets_received;
32317 extern u32 cm_packets_dropped;
32318 extern u32 cm_packets_retrans;
32319-extern atomic_t cm_listens_created;
32320-extern atomic_t cm_listens_destroyed;
32321+extern atomic_unchecked_t cm_listens_created;
32322+extern atomic_unchecked_t cm_listens_destroyed;
32323 extern u32 cm_backlog_drops;
32324-extern atomic_t cm_loopbacks;
32325-extern atomic_t cm_nodes_created;
32326-extern atomic_t cm_nodes_destroyed;
32327-extern atomic_t cm_accel_dropped_pkts;
32328-extern atomic_t cm_resets_recvd;
32329-extern atomic_t pau_qps_created;
32330-extern atomic_t pau_qps_destroyed;
32331+extern atomic_unchecked_t cm_loopbacks;
32332+extern atomic_unchecked_t cm_nodes_created;
32333+extern atomic_unchecked_t cm_nodes_destroyed;
32334+extern atomic_unchecked_t cm_accel_dropped_pkts;
32335+extern atomic_unchecked_t cm_resets_recvd;
32336+extern atomic_unchecked_t pau_qps_created;
32337+extern atomic_unchecked_t pau_qps_destroyed;
32338
32339 extern u32 int_mod_timer_init;
32340 extern u32 int_mod_cq_depth_256;
32341diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32342index 020e95c..fbb3450 100644
32343--- a/drivers/infiniband/hw/nes/nes_cm.c
32344+++ b/drivers/infiniband/hw/nes/nes_cm.c
32345@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32346 u32 cm_packets_retrans;
32347 u32 cm_packets_created;
32348 u32 cm_packets_received;
32349-atomic_t cm_listens_created;
32350-atomic_t cm_listens_destroyed;
32351+atomic_unchecked_t cm_listens_created;
32352+atomic_unchecked_t cm_listens_destroyed;
32353 u32 cm_backlog_drops;
32354-atomic_t cm_loopbacks;
32355-atomic_t cm_nodes_created;
32356-atomic_t cm_nodes_destroyed;
32357-atomic_t cm_accel_dropped_pkts;
32358-atomic_t cm_resets_recvd;
32359+atomic_unchecked_t cm_loopbacks;
32360+atomic_unchecked_t cm_nodes_created;
32361+atomic_unchecked_t cm_nodes_destroyed;
32362+atomic_unchecked_t cm_accel_dropped_pkts;
32363+atomic_unchecked_t cm_resets_recvd;
32364
32365 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32366 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32367@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32368
32369 static struct nes_cm_core *g_cm_core;
32370
32371-atomic_t cm_connects;
32372-atomic_t cm_accepts;
32373-atomic_t cm_disconnects;
32374-atomic_t cm_closes;
32375-atomic_t cm_connecteds;
32376-atomic_t cm_connect_reqs;
32377-atomic_t cm_rejects;
32378+atomic_unchecked_t cm_connects;
32379+atomic_unchecked_t cm_accepts;
32380+atomic_unchecked_t cm_disconnects;
32381+atomic_unchecked_t cm_closes;
32382+atomic_unchecked_t cm_connecteds;
32383+atomic_unchecked_t cm_connect_reqs;
32384+atomic_unchecked_t cm_rejects;
32385
32386 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32387 {
32388@@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32389 kfree(listener);
32390 listener = NULL;
32391 ret = 0;
32392- atomic_inc(&cm_listens_destroyed);
32393+ atomic_inc_unchecked(&cm_listens_destroyed);
32394 } else {
32395 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32396 }
32397@@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32398 cm_node->rem_mac);
32399
32400 add_hte_node(cm_core, cm_node);
32401- atomic_inc(&cm_nodes_created);
32402+ atomic_inc_unchecked(&cm_nodes_created);
32403
32404 return cm_node;
32405 }
32406@@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32407 }
32408
32409 atomic_dec(&cm_core->node_cnt);
32410- atomic_inc(&cm_nodes_destroyed);
32411+ atomic_inc_unchecked(&cm_nodes_destroyed);
32412 nesqp = cm_node->nesqp;
32413 if (nesqp) {
32414 nesqp->cm_node = NULL;
32415@@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32416
32417 static void drop_packet(struct sk_buff *skb)
32418 {
32419- atomic_inc(&cm_accel_dropped_pkts);
32420+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
32421 dev_kfree_skb_any(skb);
32422 }
32423
32424@@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32425 {
32426
32427 int reset = 0; /* whether to send reset in case of err.. */
32428- atomic_inc(&cm_resets_recvd);
32429+ atomic_inc_unchecked(&cm_resets_recvd);
32430 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32431 " refcnt=%d\n", cm_node, cm_node->state,
32432 atomic_read(&cm_node->ref_count));
32433@@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32434 rem_ref_cm_node(cm_node->cm_core, cm_node);
32435 return NULL;
32436 }
32437- atomic_inc(&cm_loopbacks);
32438+ atomic_inc_unchecked(&cm_loopbacks);
32439 loopbackremotenode->loopbackpartner = cm_node;
32440 loopbackremotenode->tcp_cntxt.rcv_wscale =
32441 NES_CM_DEFAULT_RCV_WND_SCALE;
32442@@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32443 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32444 else {
32445 rem_ref_cm_node(cm_core, cm_node);
32446- atomic_inc(&cm_accel_dropped_pkts);
32447+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
32448 dev_kfree_skb_any(skb);
32449 }
32450 break;
32451@@ -2891,7 +2891,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32452
32453 if ((cm_id) && (cm_id->event_handler)) {
32454 if (issue_disconn) {
32455- atomic_inc(&cm_disconnects);
32456+ atomic_inc_unchecked(&cm_disconnects);
32457 cm_event.event = IW_CM_EVENT_DISCONNECT;
32458 cm_event.status = disconn_status;
32459 cm_event.local_addr = cm_id->local_addr;
32460@@ -2913,7 +2913,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32461 }
32462
32463 if (issue_close) {
32464- atomic_inc(&cm_closes);
32465+ atomic_inc_unchecked(&cm_closes);
32466 nes_disconnect(nesqp, 1);
32467
32468 cm_id->provider_data = nesqp;
32469@@ -3049,7 +3049,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32470
32471 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32472 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32473- atomic_inc(&cm_accepts);
32474+ atomic_inc_unchecked(&cm_accepts);
32475
32476 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32477 netdev_refcnt_read(nesvnic->netdev));
32478@@ -3251,7 +3251,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32479 struct nes_cm_core *cm_core;
32480 u8 *start_buff;
32481
32482- atomic_inc(&cm_rejects);
32483+ atomic_inc_unchecked(&cm_rejects);
32484 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32485 loopback = cm_node->loopbackpartner;
32486 cm_core = cm_node->cm_core;
32487@@ -3311,7 +3311,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32488 ntohl(cm_id->local_addr.sin_addr.s_addr),
32489 ntohs(cm_id->local_addr.sin_port));
32490
32491- atomic_inc(&cm_connects);
32492+ atomic_inc_unchecked(&cm_connects);
32493 nesqp->active_conn = 1;
32494
32495 /* cache the cm_id in the qp */
32496@@ -3421,7 +3421,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32497 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32498 return err;
32499 }
32500- atomic_inc(&cm_listens_created);
32501+ atomic_inc_unchecked(&cm_listens_created);
32502 }
32503
32504 cm_id->add_ref(cm_id);
32505@@ -3522,7 +3522,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32506
32507 if (nesqp->destroyed)
32508 return;
32509- atomic_inc(&cm_connecteds);
32510+ atomic_inc_unchecked(&cm_connecteds);
32511 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32512 " local port 0x%04X. jiffies = %lu.\n",
32513 nesqp->hwqp.qp_id,
32514@@ -3709,7 +3709,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32515
32516 cm_id->add_ref(cm_id);
32517 ret = cm_id->event_handler(cm_id, &cm_event);
32518- atomic_inc(&cm_closes);
32519+ atomic_inc_unchecked(&cm_closes);
32520 cm_event.event = IW_CM_EVENT_CLOSE;
32521 cm_event.status = 0;
32522 cm_event.provider_data = cm_id->provider_data;
32523@@ -3745,7 +3745,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32524 return;
32525 cm_id = cm_node->cm_id;
32526
32527- atomic_inc(&cm_connect_reqs);
32528+ atomic_inc_unchecked(&cm_connect_reqs);
32529 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32530 cm_node, cm_id, jiffies);
32531
32532@@ -3785,7 +3785,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32533 return;
32534 cm_id = cm_node->cm_id;
32535
32536- atomic_inc(&cm_connect_reqs);
32537+ atomic_inc_unchecked(&cm_connect_reqs);
32538 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32539 cm_node, cm_id, jiffies);
32540
32541diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32542index 3ba7be3..c81f6ff 100644
32543--- a/drivers/infiniband/hw/nes/nes_mgt.c
32544+++ b/drivers/infiniband/hw/nes/nes_mgt.c
32545@@ -40,8 +40,8 @@
32546 #include "nes.h"
32547 #include "nes_mgt.h"
32548
32549-atomic_t pau_qps_created;
32550-atomic_t pau_qps_destroyed;
32551+atomic_unchecked_t pau_qps_created;
32552+atomic_unchecked_t pau_qps_destroyed;
32553
32554 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32555 {
32556@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32557 {
32558 struct sk_buff *skb;
32559 unsigned long flags;
32560- atomic_inc(&pau_qps_destroyed);
32561+ atomic_inc_unchecked(&pau_qps_destroyed);
32562
32563 /* Free packets that have not yet been forwarded */
32564 /* Lock is acquired by skb_dequeue when removing the skb */
32565@@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32566 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32567 skb_queue_head_init(&nesqp->pau_list);
32568 spin_lock_init(&nesqp->pau_lock);
32569- atomic_inc(&pau_qps_created);
32570+ atomic_inc_unchecked(&pau_qps_created);
32571 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32572 }
32573
32574diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32575index f3a3ecf..57d311d 100644
32576--- a/drivers/infiniband/hw/nes/nes_nic.c
32577+++ b/drivers/infiniband/hw/nes/nes_nic.c
32578@@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32579 target_stat_values[++index] = mh_detected;
32580 target_stat_values[++index] = mh_pauses_sent;
32581 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32582- target_stat_values[++index] = atomic_read(&cm_connects);
32583- target_stat_values[++index] = atomic_read(&cm_accepts);
32584- target_stat_values[++index] = atomic_read(&cm_disconnects);
32585- target_stat_values[++index] = atomic_read(&cm_connecteds);
32586- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32587- target_stat_values[++index] = atomic_read(&cm_rejects);
32588- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32589- target_stat_values[++index] = atomic_read(&qps_created);
32590- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32591- target_stat_values[++index] = atomic_read(&qps_destroyed);
32592- target_stat_values[++index] = atomic_read(&cm_closes);
32593+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32594+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32595+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32596+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32597+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32598+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32599+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32600+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32601+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32602+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32603+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32604 target_stat_values[++index] = cm_packets_sent;
32605 target_stat_values[++index] = cm_packets_bounced;
32606 target_stat_values[++index] = cm_packets_created;
32607 target_stat_values[++index] = cm_packets_received;
32608 target_stat_values[++index] = cm_packets_dropped;
32609 target_stat_values[++index] = cm_packets_retrans;
32610- target_stat_values[++index] = atomic_read(&cm_listens_created);
32611- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32612+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32613+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32614 target_stat_values[++index] = cm_backlog_drops;
32615- target_stat_values[++index] = atomic_read(&cm_loopbacks);
32616- target_stat_values[++index] = atomic_read(&cm_nodes_created);
32617- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32618- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32619- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32620+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32621+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32622+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32623+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32624+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32625 target_stat_values[++index] = nesadapter->free_4kpbl;
32626 target_stat_values[++index] = nesadapter->free_256pbl;
32627 target_stat_values[++index] = int_mod_timer_init;
32628 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32629 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32630 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32631- target_stat_values[++index] = atomic_read(&pau_qps_created);
32632- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32633+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32634+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32635 }
32636
32637 /**
32638diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32639index 8b8812d..a5e1133 100644
32640--- a/drivers/infiniband/hw/nes/nes_verbs.c
32641+++ b/drivers/infiniband/hw/nes/nes_verbs.c
32642@@ -46,9 +46,9 @@
32643
32644 #include <rdma/ib_umem.h>
32645
32646-atomic_t mod_qp_timouts;
32647-atomic_t qps_created;
32648-atomic_t sw_qps_destroyed;
32649+atomic_unchecked_t mod_qp_timouts;
32650+atomic_unchecked_t qps_created;
32651+atomic_unchecked_t sw_qps_destroyed;
32652
32653 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32654
32655@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32656 if (init_attr->create_flags)
32657 return ERR_PTR(-EINVAL);
32658
32659- atomic_inc(&qps_created);
32660+ atomic_inc_unchecked(&qps_created);
32661 switch (init_attr->qp_type) {
32662 case IB_QPT_RC:
32663 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32664@@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32665 struct iw_cm_event cm_event;
32666 int ret = 0;
32667
32668- atomic_inc(&sw_qps_destroyed);
32669+ atomic_inc_unchecked(&sw_qps_destroyed);
32670 nesqp->destroyed = 1;
32671
32672 /* Blow away the connection if it exists. */
32673diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32674index 7e62f41..4c2b8e2 100644
32675--- a/drivers/infiniband/hw/qib/qib.h
32676+++ b/drivers/infiniband/hw/qib/qib.h
32677@@ -51,6 +51,7 @@
32678 #include <linux/completion.h>
32679 #include <linux/kref.h>
32680 #include <linux/sched.h>
32681+#include <linux/slab.h>
32682
32683 #include "qib_common.h"
32684 #include "qib_verbs.h"
32685diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32686index da739d9..da1c7f4 100644
32687--- a/drivers/input/gameport/gameport.c
32688+++ b/drivers/input/gameport/gameport.c
32689@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32690 */
32691 static void gameport_init_port(struct gameport *gameport)
32692 {
32693- static atomic_t gameport_no = ATOMIC_INIT(0);
32694+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32695
32696 __module_get(THIS_MODULE);
32697
32698 mutex_init(&gameport->drv_mutex);
32699 device_initialize(&gameport->dev);
32700 dev_set_name(&gameport->dev, "gameport%lu",
32701- (unsigned long)atomic_inc_return(&gameport_no) - 1);
32702+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32703 gameport->dev.bus = &gameport_bus;
32704 gameport->dev.release = gameport_release_port;
32705 if (gameport->parent)
32706diff --git a/drivers/input/input.c b/drivers/input/input.c
32707index 8921c61..f5cd63d 100644
32708--- a/drivers/input/input.c
32709+++ b/drivers/input/input.c
32710@@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32711 */
32712 int input_register_device(struct input_dev *dev)
32713 {
32714- static atomic_t input_no = ATOMIC_INIT(0);
32715+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32716 struct input_handler *handler;
32717 const char *path;
32718 int error;
32719@@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32720 dev->setkeycode = input_default_setkeycode;
32721
32722 dev_set_name(&dev->dev, "input%ld",
32723- (unsigned long) atomic_inc_return(&input_no) - 1);
32724+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32725
32726 error = device_add(&dev->dev);
32727 if (error)
32728diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32729index 04c69af..5f92d00 100644
32730--- a/drivers/input/joystick/sidewinder.c
32731+++ b/drivers/input/joystick/sidewinder.c
32732@@ -30,6 +30,7 @@
32733 #include <linux/kernel.h>
32734 #include <linux/module.h>
32735 #include <linux/slab.h>
32736+#include <linux/sched.h>
32737 #include <linux/init.h>
32738 #include <linux/input.h>
32739 #include <linux/gameport.h>
32740diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32741index 83811e4..0822b90 100644
32742--- a/drivers/input/joystick/xpad.c
32743+++ b/drivers/input/joystick/xpad.c
32744@@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32745
32746 static int xpad_led_probe(struct usb_xpad *xpad)
32747 {
32748- static atomic_t led_seq = ATOMIC_INIT(0);
32749+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32750 long led_no;
32751 struct xpad_led *led;
32752 struct led_classdev *led_cdev;
32753@@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32754 if (!led)
32755 return -ENOMEM;
32756
32757- led_no = (long)atomic_inc_return(&led_seq) - 1;
32758+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32759
32760 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32761 led->xpad = xpad;
32762diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32763index 0110b5a..d3ad144 100644
32764--- a/drivers/input/mousedev.c
32765+++ b/drivers/input/mousedev.c
32766@@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32767
32768 spin_unlock_irq(&client->packet_lock);
32769
32770- if (copy_to_user(buffer, data, count))
32771+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
32772 return -EFAULT;
32773
32774 return count;
32775diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
32776index d0f7533..fb8215b 100644
32777--- a/drivers/input/serio/serio.c
32778+++ b/drivers/input/serio/serio.c
32779@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
32780 */
32781 static void serio_init_port(struct serio *serio)
32782 {
32783- static atomic_t serio_no = ATOMIC_INIT(0);
32784+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
32785
32786 __module_get(THIS_MODULE);
32787
32788@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
32789 mutex_init(&serio->drv_mutex);
32790 device_initialize(&serio->dev);
32791 dev_set_name(&serio->dev, "serio%ld",
32792- (long)atomic_inc_return(&serio_no) - 1);
32793+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
32794 serio->dev.bus = &serio_bus;
32795 serio->dev.release = serio_release_port;
32796 serio->dev.groups = serio_device_attr_groups;
32797diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
32798index 38c4bd8..58965d9 100644
32799--- a/drivers/isdn/capi/capi.c
32800+++ b/drivers/isdn/capi/capi.c
32801@@ -83,8 +83,8 @@ struct capiminor {
32802
32803 struct capi20_appl *ap;
32804 u32 ncci;
32805- atomic_t datahandle;
32806- atomic_t msgid;
32807+ atomic_unchecked_t datahandle;
32808+ atomic_unchecked_t msgid;
32809
32810 struct tty_port port;
32811 int ttyinstop;
32812@@ -392,7 +392,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
32813 capimsg_setu16(s, 2, mp->ap->applid);
32814 capimsg_setu8 (s, 4, CAPI_DATA_B3);
32815 capimsg_setu8 (s, 5, CAPI_RESP);
32816- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
32817+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
32818 capimsg_setu32(s, 8, mp->ncci);
32819 capimsg_setu16(s, 12, datahandle);
32820 }
32821@@ -513,14 +513,14 @@ static void handle_minor_send(struct capiminor *mp)
32822 mp->outbytes -= len;
32823 spin_unlock_bh(&mp->outlock);
32824
32825- datahandle = atomic_inc_return(&mp->datahandle);
32826+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
32827 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
32828 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32829 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32830 capimsg_setu16(skb->data, 2, mp->ap->applid);
32831 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
32832 capimsg_setu8 (skb->data, 5, CAPI_REQ);
32833- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
32834+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
32835 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
32836 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
32837 capimsg_setu16(skb->data, 16, len); /* Data length */
32838diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
32839index a6d9fd2..afdb8a3 100644
32840--- a/drivers/isdn/gigaset/interface.c
32841+++ b/drivers/isdn/gigaset/interface.c
32842@@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
32843 }
32844 tty->driver_data = cs;
32845
32846- ++cs->port.count;
32847+ atomic_inc(&cs->port.count);
32848
32849- if (cs->port.count == 1) {
32850+ if (atomic_read(&cs->port.count) == 1) {
32851 tty_port_tty_set(&cs->port, tty);
32852 tty->low_latency = 1;
32853 }
32854@@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
32855
32856 if (!cs->connected)
32857 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32858- else if (!cs->port.count)
32859+ else if (!atomic_read(&cs->port.count))
32860 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32861- else if (!--cs->port.count)
32862+ else if (!atomic_dec_return(&cs->port.count))
32863 tty_port_tty_set(&cs->port, NULL);
32864
32865 mutex_unlock(&cs->mutex);
32866diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
32867index 821f7ac..28d4030 100644
32868--- a/drivers/isdn/hardware/avm/b1.c
32869+++ b/drivers/isdn/hardware/avm/b1.c
32870@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
32871 }
32872 if (left) {
32873 if (t4file->user) {
32874- if (copy_from_user(buf, dp, left))
32875+ if (left > sizeof buf || copy_from_user(buf, dp, left))
32876 return -EFAULT;
32877 } else {
32878 memcpy(buf, dp, left);
32879@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
32880 }
32881 if (left) {
32882 if (config->user) {
32883- if (copy_from_user(buf, dp, left))
32884+ if (left > sizeof buf || copy_from_user(buf, dp, left))
32885 return -EFAULT;
32886 } else {
32887 memcpy(buf, dp, left);
32888diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
32889index dd6b53a..19d9ee6 100644
32890--- a/drivers/isdn/hardware/eicon/divasync.h
32891+++ b/drivers/isdn/hardware/eicon/divasync.h
32892@@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
32893 } diva_didd_add_adapter_t;
32894 typedef struct _diva_didd_remove_adapter {
32895 IDI_CALL p_request;
32896-} diva_didd_remove_adapter_t;
32897+} __no_const diva_didd_remove_adapter_t;
32898 typedef struct _diva_didd_read_adapter_array {
32899 void *buffer;
32900 dword length;
32901diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
32902index d303e65..28bcb7b 100644
32903--- a/drivers/isdn/hardware/eicon/xdi_adapter.h
32904+++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
32905@@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
32906 typedef struct _diva_os_idi_adapter_interface {
32907 diva_init_card_proc_t cleanup_adapter_proc;
32908 diva_cmd_card_proc_t cmd_proc;
32909-} diva_os_idi_adapter_interface_t;
32910+} __no_const diva_os_idi_adapter_interface_t;
32911
32912 typedef struct _diva_os_xdi_adapter {
32913 struct list_head link;
32914diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
32915index 7bc5067..fd36232 100644
32916--- a/drivers/isdn/i4l/isdn_tty.c
32917+++ b/drivers/isdn/i4l/isdn_tty.c
32918@@ -1505,9 +1505,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
32919 port = &info->port;
32920 #ifdef ISDN_DEBUG_MODEM_OPEN
32921 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
32922- port->count);
32923+ atomic_read(&port->count))
32924 #endif
32925- port->count++;
32926+ atomic_inc(&port->count);
32927 tty->driver_data = info;
32928 port->tty = tty;
32929 tty->port = port;
32930@@ -1553,7 +1553,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
32931 #endif
32932 return;
32933 }
32934- if ((tty->count == 1) && (port->count != 1)) {
32935+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
32936 /*
32937 * Uh, oh. tty->count is 1, which means that the tty
32938 * structure will be freed. Info->count should always
32939@@ -1562,15 +1562,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
32940 * serial port won't be shutdown.
32941 */
32942 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
32943- "info->count is %d\n", port->count);
32944- port->count = 1;
32945+ "info->count is %d\n", atomic_read(&port->count));
32946+ atomic_set(&port->count, 1);
32947 }
32948- if (--port->count < 0) {
32949+ if (atomic_dec_return(&port->count) < 0) {
32950 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
32951- info->line, port->count);
32952- port->count = 0;
32953+ info->line, atomic_read(&port->count));
32954+ atomic_set(&port->count, 0);
32955 }
32956- if (port->count) {
32957+ if (atomic_read(&port->count)) {
32958 #ifdef ISDN_DEBUG_MODEM_OPEN
32959 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
32960 #endif
32961@@ -1624,7 +1624,7 @@ isdn_tty_hangup(struct tty_struct *tty)
32962 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
32963 return;
32964 isdn_tty_shutdown(info);
32965- port->count = 0;
32966+ atomic_set(&port->count, 0);
32967 port->flags &= ~ASYNC_NORMAL_ACTIVE;
32968 port->tty = NULL;
32969 wake_up_interruptible(&port->open_wait);
32970@@ -1964,7 +1964,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
32971 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
32972 modem_info *info = &dev->mdm.info[i];
32973
32974- if (info->port.count == 0)
32975+ if (atomic_read(&info->port.count) == 0)
32976 continue;
32977 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
32978 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
32979diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
32980index e74df7c..03a03ba 100644
32981--- a/drivers/isdn/icn/icn.c
32982+++ b/drivers/isdn/icn/icn.c
32983@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
32984 if (count > len)
32985 count = len;
32986 if (user) {
32987- if (copy_from_user(msg, buf, count))
32988+ if (count > sizeof msg || copy_from_user(msg, buf, count))
32989 return -EFAULT;
32990 } else
32991 memcpy(msg, buf, count);
32992diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
32993index b5fdcb7..5b6c59f 100644
32994--- a/drivers/lguest/core.c
32995+++ b/drivers/lguest/core.c
32996@@ -92,9 +92,17 @@ static __init int map_switcher(void)
32997 * it's worked so far. The end address needs +1 because __get_vm_area
32998 * allocates an extra guard page, so we need space for that.
32999 */
33000+
33001+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
33002+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33003+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
33004+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33005+#else
33006 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33007 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
33008 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33009+#endif
33010+
33011 if (!switcher_vma) {
33012 err = -ENOMEM;
33013 printk("lguest: could not map switcher pages high\n");
33014@@ -119,7 +127,7 @@ static __init int map_switcher(void)
33015 * Now the Switcher is mapped at the right address, we can't fail!
33016 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
33017 */
33018- memcpy(switcher_vma->addr, start_switcher_text,
33019+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
33020 end_switcher_text - start_switcher_text);
33021
33022 printk(KERN_INFO "lguest: mapped switcher at %p\n",
33023diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
33024index 39809035..ce25c5e 100644
33025--- a/drivers/lguest/x86/core.c
33026+++ b/drivers/lguest/x86/core.c
33027@@ -59,7 +59,7 @@ static struct {
33028 /* Offset from where switcher.S was compiled to where we've copied it */
33029 static unsigned long switcher_offset(void)
33030 {
33031- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
33032+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
33033 }
33034
33035 /* This cpu's struct lguest_pages. */
33036@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
33037 * These copies are pretty cheap, so we do them unconditionally: */
33038 /* Save the current Host top-level page directory.
33039 */
33040+
33041+#ifdef CONFIG_PAX_PER_CPU_PGD
33042+ pages->state.host_cr3 = read_cr3();
33043+#else
33044 pages->state.host_cr3 = __pa(current->mm->pgd);
33045+#endif
33046+
33047 /*
33048 * Set up the Guest's page tables to see this CPU's pages (and no
33049 * other CPU's pages).
33050@@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
33051 * compiled-in switcher code and the high-mapped copy we just made.
33052 */
33053 for (i = 0; i < IDT_ENTRIES; i++)
33054- default_idt_entries[i] += switcher_offset();
33055+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33056
33057 /*
33058 * Set up the Switcher's per-cpu areas.
33059@@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
33060 * it will be undisturbed when we switch. To change %cs and jump we
33061 * need this structure to feed to Intel's "lcall" instruction.
33062 */
33063- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33064+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33065 lguest_entry.segment = LGUEST_CS;
33066
33067 /*
33068diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33069index 40634b0..4f5855e 100644
33070--- a/drivers/lguest/x86/switcher_32.S
33071+++ b/drivers/lguest/x86/switcher_32.S
33072@@ -87,6 +87,7 @@
33073 #include <asm/page.h>
33074 #include <asm/segment.h>
33075 #include <asm/lguest.h>
33076+#include <asm/processor-flags.h>
33077
33078 // We mark the start of the code to copy
33079 // It's placed in .text tho it's never run here
33080@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33081 // Changes type when we load it: damn Intel!
33082 // For after we switch over our page tables
33083 // That entry will be read-only: we'd crash.
33084+
33085+#ifdef CONFIG_PAX_KERNEXEC
33086+ mov %cr0, %edx
33087+ xor $X86_CR0_WP, %edx
33088+ mov %edx, %cr0
33089+#endif
33090+
33091 movl $(GDT_ENTRY_TSS*8), %edx
33092 ltr %dx
33093
33094@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33095 // Let's clear it again for our return.
33096 // The GDT descriptor of the Host
33097 // Points to the table after two "size" bytes
33098- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33099+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33100 // Clear "used" from type field (byte 5, bit 2)
33101- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33102+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33103+
33104+#ifdef CONFIG_PAX_KERNEXEC
33105+ mov %cr0, %eax
33106+ xor $X86_CR0_WP, %eax
33107+ mov %eax, %cr0
33108+#endif
33109
33110 // Once our page table's switched, the Guest is live!
33111 // The Host fades as we run this final step.
33112@@ -295,13 +309,12 @@ deliver_to_host:
33113 // I consulted gcc, and it gave
33114 // These instructions, which I gladly credit:
33115 leal (%edx,%ebx,8), %eax
33116- movzwl (%eax),%edx
33117- movl 4(%eax), %eax
33118- xorw %ax, %ax
33119- orl %eax, %edx
33120+ movl 4(%eax), %edx
33121+ movw (%eax), %dx
33122 // Now the address of the handler's in %edx
33123 // We call it now: its "iret" drops us home.
33124- jmp *%edx
33125+ ljmp $__KERNEL_CS, $1f
33126+1: jmp *%edx
33127
33128 // Every interrupt can come to us here
33129 // But we must truly tell each apart.
33130diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33131index 20e5c2c..9e849a9 100644
33132--- a/drivers/macintosh/macio_asic.c
33133+++ b/drivers/macintosh/macio_asic.c
33134@@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33135 * MacIO is matched against any Apple ID, it's probe() function
33136 * will then decide wether it applies or not
33137 */
33138-static const struct pci_device_id __devinitdata pci_ids [] = { {
33139+static const struct pci_device_id __devinitconst pci_ids [] = { {
33140 .vendor = PCI_VENDOR_ID_APPLE,
33141 .device = PCI_ANY_ID,
33142 .subvendor = PCI_ANY_ID,
33143diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33144index 15dbe03..743fc65 100644
33145--- a/drivers/md/bitmap.c
33146+++ b/drivers/md/bitmap.c
33147@@ -1786,7 +1786,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33148 chunk_kb ? "KB" : "B");
33149 if (bitmap->storage.file) {
33150 seq_printf(seq, ", file: ");
33151- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
33152+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
33153 }
33154
33155 seq_printf(seq, "\n");
33156diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33157index a1a3e6d..1918bfc 100644
33158--- a/drivers/md/dm-ioctl.c
33159+++ b/drivers/md/dm-ioctl.c
33160@@ -1590,7 +1590,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33161 cmd == DM_LIST_VERSIONS_CMD)
33162 return 0;
33163
33164- if ((cmd == DM_DEV_CREATE_CMD)) {
33165+ if (cmd == DM_DEV_CREATE_CMD) {
33166 if (!*param->name) {
33167 DMWARN("name not supplied when creating device");
33168 return -EINVAL;
33169diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33170index b58b7a3..8018b19 100644
33171--- a/drivers/md/dm-raid1.c
33172+++ b/drivers/md/dm-raid1.c
33173@@ -40,7 +40,7 @@ enum dm_raid1_error {
33174
33175 struct mirror {
33176 struct mirror_set *ms;
33177- atomic_t error_count;
33178+ atomic_unchecked_t error_count;
33179 unsigned long error_type;
33180 struct dm_dev *dev;
33181 sector_t offset;
33182@@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33183 struct mirror *m;
33184
33185 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33186- if (!atomic_read(&m->error_count))
33187+ if (!atomic_read_unchecked(&m->error_count))
33188 return m;
33189
33190 return NULL;
33191@@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33192 * simple way to tell if a device has encountered
33193 * errors.
33194 */
33195- atomic_inc(&m->error_count);
33196+ atomic_inc_unchecked(&m->error_count);
33197
33198 if (test_and_set_bit(error_type, &m->error_type))
33199 return;
33200@@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33201 struct mirror *m = get_default_mirror(ms);
33202
33203 do {
33204- if (likely(!atomic_read(&m->error_count)))
33205+ if (likely(!atomic_read_unchecked(&m->error_count)))
33206 return m;
33207
33208 if (m-- == ms->mirror)
33209@@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33210 {
33211 struct mirror *default_mirror = get_default_mirror(m->ms);
33212
33213- return !atomic_read(&default_mirror->error_count);
33214+ return !atomic_read_unchecked(&default_mirror->error_count);
33215 }
33216
33217 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33218@@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33219 */
33220 if (likely(region_in_sync(ms, region, 1)))
33221 m = choose_mirror(ms, bio->bi_sector);
33222- else if (m && atomic_read(&m->error_count))
33223+ else if (m && atomic_read_unchecked(&m->error_count))
33224 m = NULL;
33225
33226 if (likely(m))
33227@@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33228 }
33229
33230 ms->mirror[mirror].ms = ms;
33231- atomic_set(&(ms->mirror[mirror].error_count), 0);
33232+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33233 ms->mirror[mirror].error_type = 0;
33234 ms->mirror[mirror].offset = offset;
33235
33236@@ -1352,7 +1352,7 @@ static void mirror_resume(struct dm_target *ti)
33237 */
33238 static char device_status_char(struct mirror *m)
33239 {
33240- if (!atomic_read(&(m->error_count)))
33241+ if (!atomic_read_unchecked(&(m->error_count)))
33242 return 'A';
33243
33244 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33245diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33246index 35c94ff..20d4c17 100644
33247--- a/drivers/md/dm-stripe.c
33248+++ b/drivers/md/dm-stripe.c
33249@@ -20,7 +20,7 @@ struct stripe {
33250 struct dm_dev *dev;
33251 sector_t physical_start;
33252
33253- atomic_t error_count;
33254+ atomic_unchecked_t error_count;
33255 };
33256
33257 struct stripe_c {
33258@@ -193,7 +193,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33259 kfree(sc);
33260 return r;
33261 }
33262- atomic_set(&(sc->stripe[i].error_count), 0);
33263+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33264 }
33265
33266 ti->private = sc;
33267@@ -315,7 +315,7 @@ static int stripe_status(struct dm_target *ti,
33268 DMEMIT("%d ", sc->stripes);
33269 for (i = 0; i < sc->stripes; i++) {
33270 DMEMIT("%s ", sc->stripe[i].dev->name);
33271- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33272+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33273 'D' : 'A';
33274 }
33275 buffer[i] = '\0';
33276@@ -362,8 +362,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33277 */
33278 for (i = 0; i < sc->stripes; i++)
33279 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33280- atomic_inc(&(sc->stripe[i].error_count));
33281- if (atomic_read(&(sc->stripe[i].error_count)) <
33282+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
33283+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33284 DM_IO_ERROR_THRESHOLD)
33285 schedule_work(&sc->trigger_event);
33286 }
33287diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33288index 2e227fb..44ead1f 100644
33289--- a/drivers/md/dm-table.c
33290+++ b/drivers/md/dm-table.c
33291@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33292 if (!dev_size)
33293 return 0;
33294
33295- if ((start >= dev_size) || (start + len > dev_size)) {
33296+ if ((start >= dev_size) || (len > dev_size - start)) {
33297 DMWARN("%s: %s too small for target: "
33298 "start=%llu, len=%llu, dev_size=%llu",
33299 dm_device_name(ti->table->md), bdevname(bdev, b),
33300diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33301index 3e2907f..c28851a 100644
33302--- a/drivers/md/dm-thin-metadata.c
33303+++ b/drivers/md/dm-thin-metadata.c
33304@@ -432,7 +432,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33305
33306 pmd->info.tm = tm;
33307 pmd->info.levels = 2;
33308- pmd->info.value_type.context = pmd->data_sm;
33309+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33310 pmd->info.value_type.size = sizeof(__le64);
33311 pmd->info.value_type.inc = data_block_inc;
33312 pmd->info.value_type.dec = data_block_dec;
33313@@ -451,7 +451,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33314
33315 pmd->bl_info.tm = tm;
33316 pmd->bl_info.levels = 1;
33317- pmd->bl_info.value_type.context = pmd->data_sm;
33318+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33319 pmd->bl_info.value_type.size = sizeof(__le64);
33320 pmd->bl_info.value_type.inc = data_block_inc;
33321 pmd->bl_info.value_type.dec = data_block_dec;
33322diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33323index e24143c..ce2f21a1 100644
33324--- a/drivers/md/dm.c
33325+++ b/drivers/md/dm.c
33326@@ -176,9 +176,9 @@ struct mapped_device {
33327 /*
33328 * Event handling.
33329 */
33330- atomic_t event_nr;
33331+ atomic_unchecked_t event_nr;
33332 wait_queue_head_t eventq;
33333- atomic_t uevent_seq;
33334+ atomic_unchecked_t uevent_seq;
33335 struct list_head uevent_list;
33336 spinlock_t uevent_lock; /* Protect access to uevent_list */
33337
33338@@ -1845,8 +1845,8 @@ static struct mapped_device *alloc_dev(int minor)
33339 rwlock_init(&md->map_lock);
33340 atomic_set(&md->holders, 1);
33341 atomic_set(&md->open_count, 0);
33342- atomic_set(&md->event_nr, 0);
33343- atomic_set(&md->uevent_seq, 0);
33344+ atomic_set_unchecked(&md->event_nr, 0);
33345+ atomic_set_unchecked(&md->uevent_seq, 0);
33346 INIT_LIST_HEAD(&md->uevent_list);
33347 spin_lock_init(&md->uevent_lock);
33348
33349@@ -1980,7 +1980,7 @@ static void event_callback(void *context)
33350
33351 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33352
33353- atomic_inc(&md->event_nr);
33354+ atomic_inc_unchecked(&md->event_nr);
33355 wake_up(&md->eventq);
33356 }
33357
33358@@ -2622,18 +2622,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33359
33360 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33361 {
33362- return atomic_add_return(1, &md->uevent_seq);
33363+ return atomic_add_return_unchecked(1, &md->uevent_seq);
33364 }
33365
33366 uint32_t dm_get_event_nr(struct mapped_device *md)
33367 {
33368- return atomic_read(&md->event_nr);
33369+ return atomic_read_unchecked(&md->event_nr);
33370 }
33371
33372 int dm_wait_event(struct mapped_device *md, int event_nr)
33373 {
33374 return wait_event_interruptible(md->eventq,
33375- (event_nr != atomic_read(&md->event_nr)));
33376+ (event_nr != atomic_read_unchecked(&md->event_nr)));
33377 }
33378
33379 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33380diff --git a/drivers/md/md.c b/drivers/md/md.c
33381index d5ab449..7e9ed7b 100644
33382--- a/drivers/md/md.c
33383+++ b/drivers/md/md.c
33384@@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33385 * start build, activate spare
33386 */
33387 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33388-static atomic_t md_event_count;
33389+static atomic_unchecked_t md_event_count;
33390 void md_new_event(struct mddev *mddev)
33391 {
33392- atomic_inc(&md_event_count);
33393+ atomic_inc_unchecked(&md_event_count);
33394 wake_up(&md_event_waiters);
33395 }
33396 EXPORT_SYMBOL_GPL(md_new_event);
33397@@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33398 */
33399 static void md_new_event_inintr(struct mddev *mddev)
33400 {
33401- atomic_inc(&md_event_count);
33402+ atomic_inc_unchecked(&md_event_count);
33403 wake_up(&md_event_waiters);
33404 }
33405
33406@@ -1565,7 +1565,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33407 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
33408 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
33409 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
33410- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33411+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33412
33413 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33414 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33415@@ -1809,7 +1809,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33416 else
33417 sb->resync_offset = cpu_to_le64(0);
33418
33419- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33420+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33421
33422 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33423 sb->size = cpu_to_le64(mddev->dev_sectors);
33424@@ -2803,7 +2803,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33425 static ssize_t
33426 errors_show(struct md_rdev *rdev, char *page)
33427 {
33428- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33429+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33430 }
33431
33432 static ssize_t
33433@@ -2812,7 +2812,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33434 char *e;
33435 unsigned long n = simple_strtoul(buf, &e, 10);
33436 if (*buf && (*e == 0 || *e == '\n')) {
33437- atomic_set(&rdev->corrected_errors, n);
33438+ atomic_set_unchecked(&rdev->corrected_errors, n);
33439 return len;
33440 }
33441 return -EINVAL;
33442@@ -3259,8 +3259,8 @@ int md_rdev_init(struct md_rdev *rdev)
33443 rdev->sb_loaded = 0;
33444 rdev->bb_page = NULL;
33445 atomic_set(&rdev->nr_pending, 0);
33446- atomic_set(&rdev->read_errors, 0);
33447- atomic_set(&rdev->corrected_errors, 0);
33448+ atomic_set_unchecked(&rdev->read_errors, 0);
33449+ atomic_set_unchecked(&rdev->corrected_errors, 0);
33450
33451 INIT_LIST_HEAD(&rdev->same_set);
33452 init_waitqueue_head(&rdev->blocked_wait);
33453@@ -6997,7 +6997,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33454
33455 spin_unlock(&pers_lock);
33456 seq_printf(seq, "\n");
33457- seq->poll_event = atomic_read(&md_event_count);
33458+ seq->poll_event = atomic_read_unchecked(&md_event_count);
33459 return 0;
33460 }
33461 if (v == (void*)2) {
33462@@ -7100,7 +7100,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33463 return error;
33464
33465 seq = file->private_data;
33466- seq->poll_event = atomic_read(&md_event_count);
33467+ seq->poll_event = atomic_read_unchecked(&md_event_count);
33468 return error;
33469 }
33470
33471@@ -7114,7 +7114,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33472 /* always allow read */
33473 mask = POLLIN | POLLRDNORM;
33474
33475- if (seq->poll_event != atomic_read(&md_event_count))
33476+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33477 mask |= POLLERR | POLLPRI;
33478 return mask;
33479 }
33480@@ -7158,7 +7158,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33481 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33482 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33483 (int)part_stat_read(&disk->part0, sectors[1]) -
33484- atomic_read(&disk->sync_io);
33485+ atomic_read_unchecked(&disk->sync_io);
33486 /* sync IO will cause sync_io to increase before the disk_stats
33487 * as sync_io is counted when a request starts, and
33488 * disk_stats is counted when it completes.
33489diff --git a/drivers/md/md.h b/drivers/md/md.h
33490index 7b4a3c3..994ad4f 100644
33491--- a/drivers/md/md.h
33492+++ b/drivers/md/md.h
33493@@ -94,13 +94,13 @@ struct md_rdev {
33494 * only maintained for arrays that
33495 * support hot removal
33496 */
33497- atomic_t read_errors; /* number of consecutive read errors that
33498+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
33499 * we have tried to ignore.
33500 */
33501 struct timespec last_read_error; /* monotonic time since our
33502 * last read error
33503 */
33504- atomic_t corrected_errors; /* number of corrected read errors,
33505+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33506 * for reporting to userspace and storing
33507 * in superblock.
33508 */
33509@@ -435,7 +435,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33510
33511 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33512 {
33513- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33514+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33515 }
33516
33517 struct md_personality
33518diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
33519index fc90c11..c8cd9a9 100644
33520--- a/drivers/md/persistent-data/dm-space-map-checker.c
33521+++ b/drivers/md/persistent-data/dm-space-map-checker.c
33522@@ -167,7 +167,7 @@ static int ca_commit(struct count_array *old, struct count_array *new)
33523 /*----------------------------------------------------------------*/
33524
33525 struct sm_checker {
33526- struct dm_space_map sm;
33527+ dm_space_map_no_const sm;
33528
33529 struct count_array old_counts;
33530 struct count_array counts;
33531diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33532index 3d0ed53..35dc592 100644
33533--- a/drivers/md/persistent-data/dm-space-map-disk.c
33534+++ b/drivers/md/persistent-data/dm-space-map-disk.c
33535@@ -23,7 +23,7 @@
33536 * Space map interface.
33537 */
33538 struct sm_disk {
33539- struct dm_space_map sm;
33540+ dm_space_map_no_const sm;
33541
33542 struct ll_disk ll;
33543 struct ll_disk old_ll;
33544diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33545index e89ae5e..062e4c2 100644
33546--- a/drivers/md/persistent-data/dm-space-map-metadata.c
33547+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33548@@ -43,7 +43,7 @@ struct block_op {
33549 };
33550
33551 struct sm_metadata {
33552- struct dm_space_map sm;
33553+ dm_space_map_no_const sm;
33554
33555 struct ll_disk ll;
33556 struct ll_disk old_ll;
33557diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33558index 1cbfc6b..56e1dbb 100644
33559--- a/drivers/md/persistent-data/dm-space-map.h
33560+++ b/drivers/md/persistent-data/dm-space-map.h
33561@@ -60,6 +60,7 @@ struct dm_space_map {
33562 int (*root_size)(struct dm_space_map *sm, size_t *result);
33563 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33564 };
33565+typedef struct dm_space_map __no_const dm_space_map_no_const;
33566
33567 /*----------------------------------------------------------------*/
33568
33569diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33570index 53aec45..250851c 100644
33571--- a/drivers/md/raid1.c
33572+++ b/drivers/md/raid1.c
33573@@ -1685,7 +1685,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33574 if (r1_sync_page_io(rdev, sect, s,
33575 bio->bi_io_vec[idx].bv_page,
33576 READ) != 0)
33577- atomic_add(s, &rdev->corrected_errors);
33578+ atomic_add_unchecked(s, &rdev->corrected_errors);
33579 }
33580 sectors -= s;
33581 sect += s;
33582@@ -1907,7 +1907,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33583 test_bit(In_sync, &rdev->flags)) {
33584 if (r1_sync_page_io(rdev, sect, s,
33585 conf->tmppage, READ)) {
33586- atomic_add(s, &rdev->corrected_errors);
33587+ atomic_add_unchecked(s, &rdev->corrected_errors);
33588 printk(KERN_INFO
33589 "md/raid1:%s: read error corrected "
33590 "(%d sectors at %llu on %s)\n",
33591diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33592index 8da6282..8ec7103 100644
33593--- a/drivers/md/raid10.c
33594+++ b/drivers/md/raid10.c
33595@@ -1784,7 +1784,7 @@ static void end_sync_read(struct bio *bio, int error)
33596 /* The write handler will notice the lack of
33597 * R10BIO_Uptodate and record any errors etc
33598 */
33599- atomic_add(r10_bio->sectors,
33600+ atomic_add_unchecked(r10_bio->sectors,
33601 &conf->mirrors[d].rdev->corrected_errors);
33602
33603 /* for reconstruct, we always reschedule after a read.
33604@@ -2133,7 +2133,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33605 {
33606 struct timespec cur_time_mon;
33607 unsigned long hours_since_last;
33608- unsigned int read_errors = atomic_read(&rdev->read_errors);
33609+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33610
33611 ktime_get_ts(&cur_time_mon);
33612
33613@@ -2155,9 +2155,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33614 * overflowing the shift of read_errors by hours_since_last.
33615 */
33616 if (hours_since_last >= 8 * sizeof(read_errors))
33617- atomic_set(&rdev->read_errors, 0);
33618+ atomic_set_unchecked(&rdev->read_errors, 0);
33619 else
33620- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33621+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33622 }
33623
33624 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33625@@ -2211,8 +2211,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33626 return;
33627
33628 check_decay_read_errors(mddev, rdev);
33629- atomic_inc(&rdev->read_errors);
33630- if (atomic_read(&rdev->read_errors) > max_read_errors) {
33631+ atomic_inc_unchecked(&rdev->read_errors);
33632+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33633 char b[BDEVNAME_SIZE];
33634 bdevname(rdev->bdev, b);
33635
33636@@ -2220,7 +2220,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33637 "md/raid10:%s: %s: Raid device exceeded "
33638 "read_error threshold [cur %d:max %d]\n",
33639 mdname(mddev), b,
33640- atomic_read(&rdev->read_errors), max_read_errors);
33641+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33642 printk(KERN_NOTICE
33643 "md/raid10:%s: %s: Failing raid device\n",
33644 mdname(mddev), b);
33645@@ -2375,7 +2375,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33646 sect +
33647 choose_data_offset(r10_bio, rdev)),
33648 bdevname(rdev->bdev, b));
33649- atomic_add(s, &rdev->corrected_errors);
33650+ atomic_add_unchecked(s, &rdev->corrected_errors);
33651 }
33652
33653 rdev_dec_pending(rdev, mddev);
33654diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33655index 04348d7..62a4b9b 100644
33656--- a/drivers/md/raid5.c
33657+++ b/drivers/md/raid5.c
33658@@ -1736,19 +1736,19 @@ static void raid5_end_read_request(struct bio * bi, int error)
33659 mdname(conf->mddev), STRIPE_SECTORS,
33660 (unsigned long long)s,
33661 bdevname(rdev->bdev, b));
33662- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33663+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33664 clear_bit(R5_ReadError, &sh->dev[i].flags);
33665 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33666 }
33667- if (atomic_read(&rdev->read_errors))
33668- atomic_set(&rdev->read_errors, 0);
33669+ if (atomic_read_unchecked(&rdev->read_errors))
33670+ atomic_set_unchecked(&rdev->read_errors, 0);
33671 } else {
33672 const char *bdn = bdevname(rdev->bdev, b);
33673 int retry = 0;
33674 int set_bad = 0;
33675
33676 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33677- atomic_inc(&rdev->read_errors);
33678+ atomic_inc_unchecked(&rdev->read_errors);
33679 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33680 printk_ratelimited(
33681 KERN_WARNING
33682@@ -1776,7 +1776,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33683 mdname(conf->mddev),
33684 (unsigned long long)s,
33685 bdn);
33686- } else if (atomic_read(&rdev->read_errors)
33687+ } else if (atomic_read_unchecked(&rdev->read_errors)
33688 > conf->max_nr_stripes)
33689 printk(KERN_WARNING
33690 "md/raid:%s: Too many read errors, failing device %s.\n",
33691diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33692index 131b938..8572ed1 100644
33693--- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33694+++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33695@@ -1678,7 +1678,7 @@ static struct ddb_info ddb_v6 = {
33696 .subvendor = _subvend, .subdevice = _subdev, \
33697 .driver_data = (unsigned long)&_driverdata }
33698
33699-static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33700+static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33701 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33702 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33703 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33704diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33705index fa7188a..04a045e 100644
33706--- a/drivers/media/dvb/dvb-core/dvb_demux.h
33707+++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33708@@ -73,7 +73,7 @@ struct dvb_demux_feed {
33709 union {
33710 dmx_ts_cb ts;
33711 dmx_section_cb sec;
33712- } cb;
33713+ } __no_const cb;
33714
33715 struct dvb_demux *demux;
33716 void *priv;
33717diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33718index 39eab73..60033e7 100644
33719--- a/drivers/media/dvb/dvb-core/dvbdev.c
33720+++ b/drivers/media/dvb/dvb-core/dvbdev.c
33721@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33722 const struct dvb_device *template, void *priv, int type)
33723 {
33724 struct dvb_device *dvbdev;
33725- struct file_operations *dvbdevfops;
33726+ file_operations_no_const *dvbdevfops;
33727 struct device *clsdev;
33728 int minor;
33729 int id;
33730diff --git a/drivers/media/dvb/dvb-usb/az6007.c b/drivers/media/dvb/dvb-usb/az6007.c
33731index 4008b9c..ce714f5 100644
33732--- a/drivers/media/dvb/dvb-usb/az6007.c
33733+++ b/drivers/media/dvb/dvb-usb/az6007.c
33734@@ -590,7 +590,7 @@ static int az6007_read_mac_addr(struct dvb_usb_device *d, u8 mac[6])
33735 int ret;
33736
33737 ret = az6007_read(d, AZ6007_READ_DATA, 6, 0, st->data, 6);
33738- memcpy(mac, st->data, sizeof(mac));
33739+ memcpy(mac, st->data, 6);
33740
33741 if (ret > 0)
33742 deb_info("%s: mac is %02x:%02x:%02x:%02x:%02x:%02x\n",
33743diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33744index 3940bb0..fb3952a 100644
33745--- a/drivers/media/dvb/dvb-usb/cxusb.c
33746+++ b/drivers/media/dvb/dvb-usb/cxusb.c
33747@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33748
33749 struct dib0700_adapter_state {
33750 int (*set_param_save) (struct dvb_frontend *);
33751-};
33752+} __no_const;
33753
33754 static int dib7070_set_param_override(struct dvb_frontend *fe)
33755 {
33756diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33757index 9382895..ac8093c 100644
33758--- a/drivers/media/dvb/dvb-usb/dw2102.c
33759+++ b/drivers/media/dvb/dvb-usb/dw2102.c
33760@@ -95,7 +95,7 @@ struct su3000_state {
33761
33762 struct s6x0_state {
33763 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33764-};
33765+} __no_const;
33766
33767 /* debug */
33768 static int dvb_usb_dw2102_debug;
33769diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33770index 404f63a..4796533 100644
33771--- a/drivers/media/dvb/frontends/dib3000.h
33772+++ b/drivers/media/dvb/frontends/dib3000.h
33773@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33774 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33775 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33776 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33777-};
33778+} __no_const;
33779
33780 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33781 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33782diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33783index 7539a5d..06531a6 100644
33784--- a/drivers/media/dvb/ngene/ngene-cards.c
33785+++ b/drivers/media/dvb/ngene/ngene-cards.c
33786@@ -478,7 +478,7 @@ static struct ngene_info ngene_info_m780 = {
33787
33788 /****************************************************************************/
33789
33790-static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33791+static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
33792 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
33793 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
33794 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
33795diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
33796index 16a089f..1661b11 100644
33797--- a/drivers/media/radio/radio-cadet.c
33798+++ b/drivers/media/radio/radio-cadet.c
33799@@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33800 unsigned char readbuf[RDS_BUFFER];
33801 int i = 0;
33802
33803+ if (count > RDS_BUFFER)
33804+ return -EFAULT;
33805 mutex_lock(&dev->lock);
33806 if (dev->rdsstat == 0) {
33807 dev->rdsstat = 1;
33808@@ -347,7 +349,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33809 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
33810 mutex_unlock(&dev->lock);
33811
33812- if (copy_to_user(data, readbuf, i))
33813+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
33814 return -EFAULT;
33815 return i;
33816 }
33817diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
33818index 9cde353..8c6a1c3 100644
33819--- a/drivers/media/video/au0828/au0828.h
33820+++ b/drivers/media/video/au0828/au0828.h
33821@@ -191,7 +191,7 @@ struct au0828_dev {
33822
33823 /* I2C */
33824 struct i2c_adapter i2c_adap;
33825- struct i2c_algorithm i2c_algo;
33826+ i2c_algorithm_no_const i2c_algo;
33827 struct i2c_client i2c_client;
33828 u32 i2c_rc;
33829
33830diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
33831index 04bf662..e0ac026 100644
33832--- a/drivers/media/video/cx88/cx88-alsa.c
33833+++ b/drivers/media/video/cx88/cx88-alsa.c
33834@@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
33835 * Only boards with eeprom and byte 1 at eeprom=1 have it
33836 */
33837
33838-static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
33839+static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
33840 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33841 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33842 {0, }
33843diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
33844index 88cf9d9..bbc4b2c 100644
33845--- a/drivers/media/video/omap/omap_vout.c
33846+++ b/drivers/media/video/omap/omap_vout.c
33847@@ -64,7 +64,6 @@ enum omap_vout_channels {
33848 OMAP_VIDEO2,
33849 };
33850
33851-static struct videobuf_queue_ops video_vbq_ops;
33852 /* Variables configurable through module params*/
33853 static u32 video1_numbuffers = 3;
33854 static u32 video2_numbuffers = 3;
33855@@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
33856 {
33857 struct videobuf_queue *q;
33858 struct omap_vout_device *vout = NULL;
33859+ static struct videobuf_queue_ops video_vbq_ops = {
33860+ .buf_setup = omap_vout_buffer_setup,
33861+ .buf_prepare = omap_vout_buffer_prepare,
33862+ .buf_release = omap_vout_buffer_release,
33863+ .buf_queue = omap_vout_buffer_queue,
33864+ };
33865
33866 vout = video_drvdata(file);
33867 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
33868@@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
33869 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
33870
33871 q = &vout->vbq;
33872- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
33873- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
33874- video_vbq_ops.buf_release = omap_vout_buffer_release;
33875- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
33876 spin_lock_init(&vout->vbq_lock);
33877
33878 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
33879diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33880index 036952f..80d356d 100644
33881--- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33882+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33883@@ -196,7 +196,7 @@ struct pvr2_hdw {
33884
33885 /* I2C stuff */
33886 struct i2c_adapter i2c_adap;
33887- struct i2c_algorithm i2c_algo;
33888+ i2c_algorithm_no_const i2c_algo;
33889 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
33890 int i2c_cx25840_hack_state;
33891 int i2c_linked;
33892diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
33893index 02194c0..091733b 100644
33894--- a/drivers/media/video/timblogiw.c
33895+++ b/drivers/media/video/timblogiw.c
33896@@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
33897
33898 /* Platform device functions */
33899
33900-static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33901+static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
33902 .vidioc_querycap = timblogiw_querycap,
33903 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
33904 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
33905@@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33906 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
33907 };
33908
33909-static __devinitconst struct v4l2_file_operations timblogiw_fops = {
33910+static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
33911 .owner = THIS_MODULE,
33912 .open = timblogiw_open,
33913 .release = timblogiw_close,
33914diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
33915index d99db56..a16b959 100644
33916--- a/drivers/message/fusion/mptbase.c
33917+++ b/drivers/message/fusion/mptbase.c
33918@@ -6751,8 +6751,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
33919 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
33920 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
33921
33922+#ifdef CONFIG_GRKERNSEC_HIDESYM
33923+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
33924+#else
33925 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33926 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
33927+#endif
33928+
33929 /*
33930 * Rounding UP to nearest 4-kB boundary here...
33931 */
33932diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
33933index 551262e..7551198 100644
33934--- a/drivers/message/fusion/mptsas.c
33935+++ b/drivers/message/fusion/mptsas.c
33936@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
33937 return 0;
33938 }
33939
33940+static inline void
33941+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33942+{
33943+ if (phy_info->port_details) {
33944+ phy_info->port_details->rphy = rphy;
33945+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33946+ ioc->name, rphy));
33947+ }
33948+
33949+ if (rphy) {
33950+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33951+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33952+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33953+ ioc->name, rphy, rphy->dev.release));
33954+ }
33955+}
33956+
33957 /* no mutex */
33958 static void
33959 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
33960@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
33961 return NULL;
33962 }
33963
33964-static inline void
33965-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33966-{
33967- if (phy_info->port_details) {
33968- phy_info->port_details->rphy = rphy;
33969- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33970- ioc->name, rphy));
33971- }
33972-
33973- if (rphy) {
33974- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33975- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33976- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33977- ioc->name, rphy, rphy->dev.release));
33978- }
33979-}
33980-
33981 static inline struct sas_port *
33982 mptsas_get_port(struct mptsas_phyinfo *phy_info)
33983 {
33984diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
33985index 0c3ced7..1fe34ec 100644
33986--- a/drivers/message/fusion/mptscsih.c
33987+++ b/drivers/message/fusion/mptscsih.c
33988@@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
33989
33990 h = shost_priv(SChost);
33991
33992- if (h) {
33993- if (h->info_kbuf == NULL)
33994- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
33995- return h->info_kbuf;
33996- h->info_kbuf[0] = '\0';
33997+ if (!h)
33998+ return NULL;
33999
34000- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34001- h->info_kbuf[size-1] = '\0';
34002- }
34003+ if (h->info_kbuf == NULL)
34004+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34005+ return h->info_kbuf;
34006+ h->info_kbuf[0] = '\0';
34007+
34008+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34009+ h->info_kbuf[size-1] = '\0';
34010
34011 return h->info_kbuf;
34012 }
34013diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34014index 506c36f..b137580 100644
34015--- a/drivers/message/i2o/i2o_proc.c
34016+++ b/drivers/message/i2o/i2o_proc.c
34017@@ -255,13 +255,6 @@ static char *scsi_devices[] = {
34018 "Array Controller Device"
34019 };
34020
34021-static char *chtostr(u8 * chars, int n)
34022-{
34023- char tmp[256];
34024- tmp[0] = 0;
34025- return strncat(tmp, (char *)chars, n);
34026-}
34027-
34028 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34029 char *group)
34030 {
34031@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34032
34033 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34034 seq_printf(seq, "%-#8x", ddm_table.module_id);
34035- seq_printf(seq, "%-29s",
34036- chtostr(ddm_table.module_name_version, 28));
34037+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34038 seq_printf(seq, "%9d ", ddm_table.data_size);
34039 seq_printf(seq, "%8d", ddm_table.code_size);
34040
34041@@ -927,8 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34042
34043 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34044 seq_printf(seq, "%-#8x", dst->module_id);
34045- seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
34046- seq_printf(seq, "%-9s", chtostr(dst->date, 8));
34047+ seq_printf(seq, "%-.28s", dst->module_name_version);
34048+ seq_printf(seq, "%-.8s", dst->date);
34049 seq_printf(seq, "%8d ", dst->module_size);
34050 seq_printf(seq, "%8d ", dst->mpb_size);
34051 seq_printf(seq, "0x%04x", dst->module_flags);
34052@@ -1259,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34053 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34054 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34055 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34056- seq_printf(seq, "Vendor info : %s\n",
34057- chtostr((u8 *) (work32 + 2), 16));
34058- seq_printf(seq, "Product info : %s\n",
34059- chtostr((u8 *) (work32 + 6), 16));
34060- seq_printf(seq, "Description : %s\n",
34061- chtostr((u8 *) (work32 + 10), 16));
34062- seq_printf(seq, "Product rev. : %s\n",
34063- chtostr((u8 *) (work32 + 14), 8));
34064+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34065+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34066+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34067+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34068
34069 seq_printf(seq, "Serial number : ");
34070 print_serial_number(seq, (u8 *) (work32 + 16),
34071@@ -1311,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34072 }
34073
34074 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34075- seq_printf(seq, "Module name : %s\n",
34076- chtostr(result.module_name, 24));
34077- seq_printf(seq, "Module revision : %s\n",
34078- chtostr(result.module_rev, 8));
34079+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
34080+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34081
34082 seq_printf(seq, "Serial number : ");
34083 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34084@@ -1345,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34085 return 0;
34086 }
34087
34088- seq_printf(seq, "Device name : %s\n",
34089- chtostr(result.device_name, 64));
34090- seq_printf(seq, "Service name : %s\n",
34091- chtostr(result.service_name, 64));
34092- seq_printf(seq, "Physical name : %s\n",
34093- chtostr(result.physical_location, 64));
34094- seq_printf(seq, "Instance number : %s\n",
34095- chtostr(result.instance_number, 4));
34096+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
34097+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
34098+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34099+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34100
34101 return 0;
34102 }
34103diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34104index a8c08f3..155fe3d 100644
34105--- a/drivers/message/i2o/iop.c
34106+++ b/drivers/message/i2o/iop.c
34107@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34108
34109 spin_lock_irqsave(&c->context_list_lock, flags);
34110
34111- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34112- atomic_inc(&c->context_list_counter);
34113+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34114+ atomic_inc_unchecked(&c->context_list_counter);
34115
34116- entry->context = atomic_read(&c->context_list_counter);
34117+ entry->context = atomic_read_unchecked(&c->context_list_counter);
34118
34119 list_add(&entry->list, &c->context_list);
34120
34121@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34122
34123 #if BITS_PER_LONG == 64
34124 spin_lock_init(&c->context_list_lock);
34125- atomic_set(&c->context_list_counter, 0);
34126+ atomic_set_unchecked(&c->context_list_counter, 0);
34127 INIT_LIST_HEAD(&c->context_list);
34128 #endif
34129
34130diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34131index 7ce65f4..e66e9bc 100644
34132--- a/drivers/mfd/abx500-core.c
34133+++ b/drivers/mfd/abx500-core.c
34134@@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34135
34136 struct abx500_device_entry {
34137 struct list_head list;
34138- struct abx500_ops ops;
34139+ abx500_ops_no_const ops;
34140 struct device *dev;
34141 };
34142
34143diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34144index 2ea9998..51dabee 100644
34145--- a/drivers/mfd/janz-cmodio.c
34146+++ b/drivers/mfd/janz-cmodio.c
34147@@ -13,6 +13,7 @@
34148
34149 #include <linux/kernel.h>
34150 #include <linux/module.h>
34151+#include <linux/slab.h>
34152 #include <linux/init.h>
34153 #include <linux/pci.h>
34154 #include <linux/interrupt.h>
34155diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34156index a981e2a..5ca0c8b 100644
34157--- a/drivers/misc/lis3lv02d/lis3lv02d.c
34158+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34159@@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34160 * the lid is closed. This leads to interrupts as soon as a little move
34161 * is done.
34162 */
34163- atomic_inc(&lis3->count);
34164+ atomic_inc_unchecked(&lis3->count);
34165
34166 wake_up_interruptible(&lis3->misc_wait);
34167 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34168@@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34169 if (lis3->pm_dev)
34170 pm_runtime_get_sync(lis3->pm_dev);
34171
34172- atomic_set(&lis3->count, 0);
34173+ atomic_set_unchecked(&lis3->count, 0);
34174 return 0;
34175 }
34176
34177@@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34178 add_wait_queue(&lis3->misc_wait, &wait);
34179 while (true) {
34180 set_current_state(TASK_INTERRUPTIBLE);
34181- data = atomic_xchg(&lis3->count, 0);
34182+ data = atomic_xchg_unchecked(&lis3->count, 0);
34183 if (data)
34184 break;
34185
34186@@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34187 struct lis3lv02d, miscdev);
34188
34189 poll_wait(file, &lis3->misc_wait, wait);
34190- if (atomic_read(&lis3->count))
34191+ if (atomic_read_unchecked(&lis3->count))
34192 return POLLIN | POLLRDNORM;
34193 return 0;
34194 }
34195diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34196index 2b1482a..5d33616 100644
34197--- a/drivers/misc/lis3lv02d/lis3lv02d.h
34198+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34199@@ -266,7 +266,7 @@ struct lis3lv02d {
34200 struct input_polled_dev *idev; /* input device */
34201 struct platform_device *pdev; /* platform device */
34202 struct regulator_bulk_data regulators[2];
34203- atomic_t count; /* interrupt count after last read */
34204+ atomic_unchecked_t count; /* interrupt count after last read */
34205 union axis_conversion ac; /* hw -> logical axis */
34206 int mapped_btns[3];
34207
34208diff --git a/drivers/misc/lkdtm.c b/drivers/misc/lkdtm.c
34209index 28adefe..08aad69 100644
34210--- a/drivers/misc/lkdtm.c
34211+++ b/drivers/misc/lkdtm.c
34212@@ -477,6 +477,8 @@ static ssize_t lkdtm_debugfs_read(struct file *f, char __user *user_buf,
34213 int i, n, out;
34214
34215 buf = (char *)__get_free_page(GFP_KERNEL);
34216+ if (buf == NULL)
34217+ return -ENOMEM;
34218
34219 n = snprintf(buf, PAGE_SIZE, "Available crash types:\n");
34220 for (i = 0; i < ARRAY_SIZE(cp_type); i++)
34221diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34222index 2f30bad..c4c13d0 100644
34223--- a/drivers/misc/sgi-gru/gruhandles.c
34224+++ b/drivers/misc/sgi-gru/gruhandles.c
34225@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34226 unsigned long nsec;
34227
34228 nsec = CLKS2NSEC(clks);
34229- atomic_long_inc(&mcs_op_statistics[op].count);
34230- atomic_long_add(nsec, &mcs_op_statistics[op].total);
34231+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34232+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34233 if (mcs_op_statistics[op].max < nsec)
34234 mcs_op_statistics[op].max = nsec;
34235 }
34236diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34237index 950dbe9..eeef0f8 100644
34238--- a/drivers/misc/sgi-gru/gruprocfs.c
34239+++ b/drivers/misc/sgi-gru/gruprocfs.c
34240@@ -32,9 +32,9 @@
34241
34242 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34243
34244-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34245+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34246 {
34247- unsigned long val = atomic_long_read(v);
34248+ unsigned long val = atomic_long_read_unchecked(v);
34249
34250 seq_printf(s, "%16lu %s\n", val, id);
34251 }
34252@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34253
34254 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34255 for (op = 0; op < mcsop_last; op++) {
34256- count = atomic_long_read(&mcs_op_statistics[op].count);
34257- total = atomic_long_read(&mcs_op_statistics[op].total);
34258+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34259+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34260 max = mcs_op_statistics[op].max;
34261 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34262 count ? total / count : 0, max);
34263diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34264index 5c3ce24..4915ccb 100644
34265--- a/drivers/misc/sgi-gru/grutables.h
34266+++ b/drivers/misc/sgi-gru/grutables.h
34267@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34268 * GRU statistics.
34269 */
34270 struct gru_stats_s {
34271- atomic_long_t vdata_alloc;
34272- atomic_long_t vdata_free;
34273- atomic_long_t gts_alloc;
34274- atomic_long_t gts_free;
34275- atomic_long_t gms_alloc;
34276- atomic_long_t gms_free;
34277- atomic_long_t gts_double_allocate;
34278- atomic_long_t assign_context;
34279- atomic_long_t assign_context_failed;
34280- atomic_long_t free_context;
34281- atomic_long_t load_user_context;
34282- atomic_long_t load_kernel_context;
34283- atomic_long_t lock_kernel_context;
34284- atomic_long_t unlock_kernel_context;
34285- atomic_long_t steal_user_context;
34286- atomic_long_t steal_kernel_context;
34287- atomic_long_t steal_context_failed;
34288- atomic_long_t nopfn;
34289- atomic_long_t asid_new;
34290- atomic_long_t asid_next;
34291- atomic_long_t asid_wrap;
34292- atomic_long_t asid_reuse;
34293- atomic_long_t intr;
34294- atomic_long_t intr_cbr;
34295- atomic_long_t intr_tfh;
34296- atomic_long_t intr_spurious;
34297- atomic_long_t intr_mm_lock_failed;
34298- atomic_long_t call_os;
34299- atomic_long_t call_os_wait_queue;
34300- atomic_long_t user_flush_tlb;
34301- atomic_long_t user_unload_context;
34302- atomic_long_t user_exception;
34303- atomic_long_t set_context_option;
34304- atomic_long_t check_context_retarget_intr;
34305- atomic_long_t check_context_unload;
34306- atomic_long_t tlb_dropin;
34307- atomic_long_t tlb_preload_page;
34308- atomic_long_t tlb_dropin_fail_no_asid;
34309- atomic_long_t tlb_dropin_fail_upm;
34310- atomic_long_t tlb_dropin_fail_invalid;
34311- atomic_long_t tlb_dropin_fail_range_active;
34312- atomic_long_t tlb_dropin_fail_idle;
34313- atomic_long_t tlb_dropin_fail_fmm;
34314- atomic_long_t tlb_dropin_fail_no_exception;
34315- atomic_long_t tfh_stale_on_fault;
34316- atomic_long_t mmu_invalidate_range;
34317- atomic_long_t mmu_invalidate_page;
34318- atomic_long_t flush_tlb;
34319- atomic_long_t flush_tlb_gru;
34320- atomic_long_t flush_tlb_gru_tgh;
34321- atomic_long_t flush_tlb_gru_zero_asid;
34322+ atomic_long_unchecked_t vdata_alloc;
34323+ atomic_long_unchecked_t vdata_free;
34324+ atomic_long_unchecked_t gts_alloc;
34325+ atomic_long_unchecked_t gts_free;
34326+ atomic_long_unchecked_t gms_alloc;
34327+ atomic_long_unchecked_t gms_free;
34328+ atomic_long_unchecked_t gts_double_allocate;
34329+ atomic_long_unchecked_t assign_context;
34330+ atomic_long_unchecked_t assign_context_failed;
34331+ atomic_long_unchecked_t free_context;
34332+ atomic_long_unchecked_t load_user_context;
34333+ atomic_long_unchecked_t load_kernel_context;
34334+ atomic_long_unchecked_t lock_kernel_context;
34335+ atomic_long_unchecked_t unlock_kernel_context;
34336+ atomic_long_unchecked_t steal_user_context;
34337+ atomic_long_unchecked_t steal_kernel_context;
34338+ atomic_long_unchecked_t steal_context_failed;
34339+ atomic_long_unchecked_t nopfn;
34340+ atomic_long_unchecked_t asid_new;
34341+ atomic_long_unchecked_t asid_next;
34342+ atomic_long_unchecked_t asid_wrap;
34343+ atomic_long_unchecked_t asid_reuse;
34344+ atomic_long_unchecked_t intr;
34345+ atomic_long_unchecked_t intr_cbr;
34346+ atomic_long_unchecked_t intr_tfh;
34347+ atomic_long_unchecked_t intr_spurious;
34348+ atomic_long_unchecked_t intr_mm_lock_failed;
34349+ atomic_long_unchecked_t call_os;
34350+ atomic_long_unchecked_t call_os_wait_queue;
34351+ atomic_long_unchecked_t user_flush_tlb;
34352+ atomic_long_unchecked_t user_unload_context;
34353+ atomic_long_unchecked_t user_exception;
34354+ atomic_long_unchecked_t set_context_option;
34355+ atomic_long_unchecked_t check_context_retarget_intr;
34356+ atomic_long_unchecked_t check_context_unload;
34357+ atomic_long_unchecked_t tlb_dropin;
34358+ atomic_long_unchecked_t tlb_preload_page;
34359+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34360+ atomic_long_unchecked_t tlb_dropin_fail_upm;
34361+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
34362+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
34363+ atomic_long_unchecked_t tlb_dropin_fail_idle;
34364+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
34365+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34366+ atomic_long_unchecked_t tfh_stale_on_fault;
34367+ atomic_long_unchecked_t mmu_invalidate_range;
34368+ atomic_long_unchecked_t mmu_invalidate_page;
34369+ atomic_long_unchecked_t flush_tlb;
34370+ atomic_long_unchecked_t flush_tlb_gru;
34371+ atomic_long_unchecked_t flush_tlb_gru_tgh;
34372+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34373
34374- atomic_long_t copy_gpa;
34375- atomic_long_t read_gpa;
34376+ atomic_long_unchecked_t copy_gpa;
34377+ atomic_long_unchecked_t read_gpa;
34378
34379- atomic_long_t mesq_receive;
34380- atomic_long_t mesq_receive_none;
34381- atomic_long_t mesq_send;
34382- atomic_long_t mesq_send_failed;
34383- atomic_long_t mesq_noop;
34384- atomic_long_t mesq_send_unexpected_error;
34385- atomic_long_t mesq_send_lb_overflow;
34386- atomic_long_t mesq_send_qlimit_reached;
34387- atomic_long_t mesq_send_amo_nacked;
34388- atomic_long_t mesq_send_put_nacked;
34389- atomic_long_t mesq_page_overflow;
34390- atomic_long_t mesq_qf_locked;
34391- atomic_long_t mesq_qf_noop_not_full;
34392- atomic_long_t mesq_qf_switch_head_failed;
34393- atomic_long_t mesq_qf_unexpected_error;
34394- atomic_long_t mesq_noop_unexpected_error;
34395- atomic_long_t mesq_noop_lb_overflow;
34396- atomic_long_t mesq_noop_qlimit_reached;
34397- atomic_long_t mesq_noop_amo_nacked;
34398- atomic_long_t mesq_noop_put_nacked;
34399- atomic_long_t mesq_noop_page_overflow;
34400+ atomic_long_unchecked_t mesq_receive;
34401+ atomic_long_unchecked_t mesq_receive_none;
34402+ atomic_long_unchecked_t mesq_send;
34403+ atomic_long_unchecked_t mesq_send_failed;
34404+ atomic_long_unchecked_t mesq_noop;
34405+ atomic_long_unchecked_t mesq_send_unexpected_error;
34406+ atomic_long_unchecked_t mesq_send_lb_overflow;
34407+ atomic_long_unchecked_t mesq_send_qlimit_reached;
34408+ atomic_long_unchecked_t mesq_send_amo_nacked;
34409+ atomic_long_unchecked_t mesq_send_put_nacked;
34410+ atomic_long_unchecked_t mesq_page_overflow;
34411+ atomic_long_unchecked_t mesq_qf_locked;
34412+ atomic_long_unchecked_t mesq_qf_noop_not_full;
34413+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
34414+ atomic_long_unchecked_t mesq_qf_unexpected_error;
34415+ atomic_long_unchecked_t mesq_noop_unexpected_error;
34416+ atomic_long_unchecked_t mesq_noop_lb_overflow;
34417+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
34418+ atomic_long_unchecked_t mesq_noop_amo_nacked;
34419+ atomic_long_unchecked_t mesq_noop_put_nacked;
34420+ atomic_long_unchecked_t mesq_noop_page_overflow;
34421
34422 };
34423
34424@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34425 tghop_invalidate, mcsop_last};
34426
34427 struct mcs_op_statistic {
34428- atomic_long_t count;
34429- atomic_long_t total;
34430+ atomic_long_unchecked_t count;
34431+ atomic_long_unchecked_t total;
34432 unsigned long max;
34433 };
34434
34435@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34436
34437 #define STAT(id) do { \
34438 if (gru_options & OPT_STATS) \
34439- atomic_long_inc(&gru_stats.id); \
34440+ atomic_long_inc_unchecked(&gru_stats.id); \
34441 } while (0)
34442
34443 #ifdef CONFIG_SGI_GRU_DEBUG
34444diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34445index c862cd4..0d176fe 100644
34446--- a/drivers/misc/sgi-xp/xp.h
34447+++ b/drivers/misc/sgi-xp/xp.h
34448@@ -288,7 +288,7 @@ struct xpc_interface {
34449 xpc_notify_func, void *);
34450 void (*received) (short, int, void *);
34451 enum xp_retval (*partid_to_nasids) (short, void *);
34452-};
34453+} __no_const;
34454
34455 extern struct xpc_interface xpc_interface;
34456
34457diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34458index b94d5f7..7f494c5 100644
34459--- a/drivers/misc/sgi-xp/xpc.h
34460+++ b/drivers/misc/sgi-xp/xpc.h
34461@@ -835,6 +835,7 @@ struct xpc_arch_operations {
34462 void (*received_payload) (struct xpc_channel *, void *);
34463 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34464 };
34465+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34466
34467 /* struct xpc_partition act_state values (for XPC HB) */
34468
34469@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34470 /* found in xpc_main.c */
34471 extern struct device *xpc_part;
34472 extern struct device *xpc_chan;
34473-extern struct xpc_arch_operations xpc_arch_ops;
34474+extern xpc_arch_operations_no_const xpc_arch_ops;
34475 extern int xpc_disengage_timelimit;
34476 extern int xpc_disengage_timedout;
34477 extern int xpc_activate_IRQ_rcvd;
34478diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34479index 8d082b4..aa749ae 100644
34480--- a/drivers/misc/sgi-xp/xpc_main.c
34481+++ b/drivers/misc/sgi-xp/xpc_main.c
34482@@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34483 .notifier_call = xpc_system_die,
34484 };
34485
34486-struct xpc_arch_operations xpc_arch_ops;
34487+xpc_arch_operations_no_const xpc_arch_ops;
34488
34489 /*
34490 * Timer function to enforce the timelimit on the partition disengage.
34491diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c
34492index 2b62232..acfaeeb 100644
34493--- a/drivers/misc/ti-st/st_core.c
34494+++ b/drivers/misc/ti-st/st_core.c
34495@@ -349,6 +349,11 @@ void st_int_recv(void *disc_data,
34496 st_gdata->rx_skb = alloc_skb(
34497 st_gdata->list[type]->max_frame_size,
34498 GFP_ATOMIC);
34499+ if (st_gdata->rx_skb == NULL) {
34500+ pr_err("out of memory: dropping\n");
34501+ goto done;
34502+ }
34503+
34504 skb_reserve(st_gdata->rx_skb,
34505 st_gdata->list[type]->reserve);
34506 /* next 2 required for BT only */
34507diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34508index 504da71..9722d43 100644
34509--- a/drivers/mmc/host/sdhci-pci.c
34510+++ b/drivers/mmc/host/sdhci-pci.c
34511@@ -653,7 +653,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34512 .probe = via_probe,
34513 };
34514
34515-static const struct pci_device_id pci_ids[] __devinitdata = {
34516+static const struct pci_device_id pci_ids[] __devinitconst = {
34517 {
34518 .vendor = PCI_VENDOR_ID_RICOH,
34519 .device = PCI_DEVICE_ID_RICOH_R5C822,
34520diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34521index a4eb8b5..8c0628f 100644
34522--- a/drivers/mtd/devices/doc2000.c
34523+++ b/drivers/mtd/devices/doc2000.c
34524@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34525
34526 /* The ECC will not be calculated correctly if less than 512 is written */
34527 /* DBB-
34528- if (len != 0x200 && eccbuf)
34529+ if (len != 0x200)
34530 printk(KERN_WARNING
34531 "ECC needs a full sector write (adr: %lx size %lx)\n",
34532 (long) to, (long) len);
34533diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34534index 0650aaf..7718762 100644
34535--- a/drivers/mtd/nand/denali.c
34536+++ b/drivers/mtd/nand/denali.c
34537@@ -26,6 +26,7 @@
34538 #include <linux/pci.h>
34539 #include <linux/mtd/mtd.h>
34540 #include <linux/module.h>
34541+#include <linux/slab.h>
34542
34543 #include "denali.h"
34544
34545diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34546index 51b9d6a..52af9a7 100644
34547--- a/drivers/mtd/nftlmount.c
34548+++ b/drivers/mtd/nftlmount.c
34549@@ -24,6 +24,7 @@
34550 #include <asm/errno.h>
34551 #include <linux/delay.h>
34552 #include <linux/slab.h>
34553+#include <linux/sched.h>
34554 #include <linux/mtd/mtd.h>
34555 #include <linux/mtd/nand.h>
34556 #include <linux/mtd/nftl.h>
34557diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34558index 6762dc4..9956862 100644
34559--- a/drivers/net/ethernet/atheros/atlx/atl2.c
34560+++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34561@@ -2859,7 +2859,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34562 */
34563
34564 #define ATL2_PARAM(X, desc) \
34565- static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34566+ static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34567 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34568 MODULE_PARM_DESC(X, desc);
34569 #else
34570diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34571index efd80bd..21fcff0 100644
34572--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34573+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34574@@ -487,7 +487,7 @@ struct bnx2x_rx_mode_obj {
34575
34576 int (*wait_comp)(struct bnx2x *bp,
34577 struct bnx2x_rx_mode_ramrod_params *p);
34578-};
34579+} __no_const;
34580
34581 /********************** Set multicast group ***********************************/
34582
34583diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34584index 93865f8..5448741 100644
34585--- a/drivers/net/ethernet/broadcom/tg3.h
34586+++ b/drivers/net/ethernet/broadcom/tg3.h
34587@@ -140,6 +140,7 @@
34588 #define CHIPREV_ID_5750_A0 0x4000
34589 #define CHIPREV_ID_5750_A1 0x4001
34590 #define CHIPREV_ID_5750_A3 0x4003
34591+#define CHIPREV_ID_5750_C1 0x4201
34592 #define CHIPREV_ID_5750_C2 0x4202
34593 #define CHIPREV_ID_5752_A0_HW 0x5000
34594 #define CHIPREV_ID_5752_A0 0x6000
34595diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34596index c4e8643..0979484 100644
34597--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34598+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34599@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34600 */
34601 struct l2t_skb_cb {
34602 arp_failure_handler_func arp_failure_handler;
34603-};
34604+} __no_const;
34605
34606 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34607
34608diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34609index d3cd489..0fd52dd 100644
34610--- a/drivers/net/ethernet/dec/tulip/de4x5.c
34611+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34612@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34613 for (i=0; i<ETH_ALEN; i++) {
34614 tmp.addr[i] = dev->dev_addr[i];
34615 }
34616- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34617+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34618 break;
34619
34620 case DE4X5_SET_HWADDR: /* Set the hardware address */
34621@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34622 spin_lock_irqsave(&lp->lock, flags);
34623 memcpy(&statbuf, &lp->pktStats, ioc->len);
34624 spin_unlock_irqrestore(&lp->lock, flags);
34625- if (copy_to_user(ioc->data, &statbuf, ioc->len))
34626+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34627 return -EFAULT;
34628 break;
34629 }
34630diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34631index ed7d1dc..d426748 100644
34632--- a/drivers/net/ethernet/dec/tulip/eeprom.c
34633+++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34634@@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34635 {NULL}};
34636
34637
34638-static const char *block_name[] __devinitdata = {
34639+static const char *block_name[] __devinitconst = {
34640 "21140 non-MII",
34641 "21140 MII PHY",
34642 "21142 Serial PHY",
34643diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
34644index 75d45f8..3d9c55b 100644
34645--- a/drivers/net/ethernet/dec/tulip/uli526x.c
34646+++ b/drivers/net/ethernet/dec/tulip/uli526x.c
34647@@ -129,7 +129,7 @@ struct uli526x_board_info {
34648 struct uli_phy_ops {
34649 void (*write)(struct uli526x_board_info *, u8, u8, u16);
34650 u16 (*read)(struct uli526x_board_info *, u8, u8);
34651- } phy;
34652+ } __no_const phy;
34653 struct net_device *next_dev; /* next device */
34654 struct pci_dev *pdev; /* PCI device */
34655 spinlock_t lock;
34656diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34657index 4d1ffca..7c1ec4d 100644
34658--- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34659+++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34660@@ -236,7 +236,7 @@ struct pci_id_info {
34661 int drv_flags; /* Driver use, intended as capability flags. */
34662 };
34663
34664-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34665+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34666 { /* Sometime a Level-One switch card. */
34667 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34668 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34669diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34670index d7bb52a..3b83588 100644
34671--- a/drivers/net/ethernet/dlink/sundance.c
34672+++ b/drivers/net/ethernet/dlink/sundance.c
34673@@ -218,7 +218,7 @@ enum {
34674 struct pci_id_info {
34675 const char *name;
34676 };
34677-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34678+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34679 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34680 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34681 {"D-Link DFE-580TX 4 port Server Adapter"},
34682diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34683index bd5cf7e..c165651 100644
34684--- a/drivers/net/ethernet/emulex/benet/be_main.c
34685+++ b/drivers/net/ethernet/emulex/benet/be_main.c
34686@@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34687
34688 if (wrapped)
34689 newacc += 65536;
34690- ACCESS_ONCE(*acc) = newacc;
34691+ ACCESS_ONCE_RW(*acc) = newacc;
34692 }
34693
34694 void be_parse_stats(struct be_adapter *adapter)
34695diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34696index 16b0704..d2c07d7 100644
34697--- a/drivers/net/ethernet/faraday/ftgmac100.c
34698+++ b/drivers/net/ethernet/faraday/ftgmac100.c
34699@@ -31,6 +31,8 @@
34700 #include <linux/netdevice.h>
34701 #include <linux/phy.h>
34702 #include <linux/platform_device.h>
34703+#include <linux/interrupt.h>
34704+#include <linux/irqreturn.h>
34705 #include <net/ip.h>
34706
34707 #include "ftgmac100.h"
34708diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34709index 829b109..4ae5f6a 100644
34710--- a/drivers/net/ethernet/faraday/ftmac100.c
34711+++ b/drivers/net/ethernet/faraday/ftmac100.c
34712@@ -31,6 +31,8 @@
34713 #include <linux/module.h>
34714 #include <linux/netdevice.h>
34715 #include <linux/platform_device.h>
34716+#include <linux/interrupt.h>
34717+#include <linux/irqreturn.h>
34718
34719 #include "ftmac100.h"
34720
34721diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34722index 9d71c9c..0e4a0ac 100644
34723--- a/drivers/net/ethernet/fealnx.c
34724+++ b/drivers/net/ethernet/fealnx.c
34725@@ -150,7 +150,7 @@ struct chip_info {
34726 int flags;
34727 };
34728
34729-static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
34730+static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
34731 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34732 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
34733 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34734diff --git a/drivers/net/ethernet/intel/e1000e/e1000.h b/drivers/net/ethernet/intel/e1000e/e1000.h
34735index 6e6fffb..588f361 100644
34736--- a/drivers/net/ethernet/intel/e1000e/e1000.h
34737+++ b/drivers/net/ethernet/intel/e1000e/e1000.h
34738@@ -181,7 +181,7 @@ struct e1000_info;
34739 #define E1000_TXDCTL_DMA_BURST_ENABLE \
34740 (E1000_TXDCTL_GRAN | /* set descriptor granularity */ \
34741 E1000_TXDCTL_COUNT_DESC | \
34742- (5 << 16) | /* wthresh must be +1 more than desired */\
34743+ (1 << 16) | /* wthresh must be +1 more than desired */\
34744 (1 << 8) | /* hthresh */ \
34745 0x1f) /* pthresh */
34746
34747diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34748index ed5b409..ec37828 100644
34749--- a/drivers/net/ethernet/intel/e1000e/hw.h
34750+++ b/drivers/net/ethernet/intel/e1000e/hw.h
34751@@ -797,6 +797,7 @@ struct e1000_mac_operations {
34752 void (*rar_set)(struct e1000_hw *, u8 *, u32);
34753 s32 (*read_mac_addr)(struct e1000_hw *);
34754 };
34755+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34756
34757 /*
34758 * When to use various PHY register access functions:
34759@@ -837,6 +838,7 @@ struct e1000_phy_operations {
34760 void (*power_up)(struct e1000_hw *);
34761 void (*power_down)(struct e1000_hw *);
34762 };
34763+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34764
34765 /* Function pointers for the NVM. */
34766 struct e1000_nvm_operations {
34767@@ -849,9 +851,10 @@ struct e1000_nvm_operations {
34768 s32 (*validate)(struct e1000_hw *);
34769 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34770 };
34771+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34772
34773 struct e1000_mac_info {
34774- struct e1000_mac_operations ops;
34775+ e1000_mac_operations_no_const ops;
34776 u8 addr[ETH_ALEN];
34777 u8 perm_addr[ETH_ALEN];
34778
34779@@ -892,7 +895,7 @@ struct e1000_mac_info {
34780 };
34781
34782 struct e1000_phy_info {
34783- struct e1000_phy_operations ops;
34784+ e1000_phy_operations_no_const ops;
34785
34786 enum e1000_phy_type type;
34787
34788@@ -926,7 +929,7 @@ struct e1000_phy_info {
34789 };
34790
34791 struct e1000_nvm_info {
34792- struct e1000_nvm_operations ops;
34793+ e1000_nvm_operations_no_const ops;
34794
34795 enum e1000_nvm_type type;
34796 enum e1000_nvm_override override;
34797diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
34798index c2a51dc..c2bd262 100644
34799--- a/drivers/net/ethernet/intel/igb/e1000_hw.h
34800+++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
34801@@ -327,6 +327,7 @@ struct e1000_mac_operations {
34802 void (*release_swfw_sync)(struct e1000_hw *, u16);
34803
34804 };
34805+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34806
34807 struct e1000_phy_operations {
34808 s32 (*acquire)(struct e1000_hw *);
34809@@ -343,6 +344,7 @@ struct e1000_phy_operations {
34810 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
34811 s32 (*write_reg)(struct e1000_hw *, u32, u16);
34812 };
34813+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34814
34815 struct e1000_nvm_operations {
34816 s32 (*acquire)(struct e1000_hw *);
34817@@ -353,6 +355,7 @@ struct e1000_nvm_operations {
34818 s32 (*validate)(struct e1000_hw *);
34819 s32 (*valid_led_default)(struct e1000_hw *, u16 *);
34820 };
34821+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34822
34823 struct e1000_info {
34824 s32 (*get_invariants)(struct e1000_hw *);
34825@@ -364,7 +367,7 @@ struct e1000_info {
34826 extern const struct e1000_info e1000_82575_info;
34827
34828 struct e1000_mac_info {
34829- struct e1000_mac_operations ops;
34830+ e1000_mac_operations_no_const ops;
34831
34832 u8 addr[6];
34833 u8 perm_addr[6];
34834@@ -402,7 +405,7 @@ struct e1000_mac_info {
34835 };
34836
34837 struct e1000_phy_info {
34838- struct e1000_phy_operations ops;
34839+ e1000_phy_operations_no_const ops;
34840
34841 enum e1000_phy_type type;
34842
34843@@ -437,7 +440,7 @@ struct e1000_phy_info {
34844 };
34845
34846 struct e1000_nvm_info {
34847- struct e1000_nvm_operations ops;
34848+ e1000_nvm_operations_no_const ops;
34849 enum e1000_nvm_type type;
34850 enum e1000_nvm_override override;
34851
34852@@ -482,6 +485,7 @@ struct e1000_mbx_operations {
34853 s32 (*check_for_ack)(struct e1000_hw *, u16);
34854 s32 (*check_for_rst)(struct e1000_hw *, u16);
34855 };
34856+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34857
34858 struct e1000_mbx_stats {
34859 u32 msgs_tx;
34860@@ -493,7 +497,7 @@ struct e1000_mbx_stats {
34861 };
34862
34863 struct e1000_mbx_info {
34864- struct e1000_mbx_operations ops;
34865+ e1000_mbx_operations_no_const ops;
34866 struct e1000_mbx_stats stats;
34867 u32 timeout;
34868 u32 usec_delay;
34869diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
34870index 57db3c6..aa825fc 100644
34871--- a/drivers/net/ethernet/intel/igbvf/vf.h
34872+++ b/drivers/net/ethernet/intel/igbvf/vf.h
34873@@ -189,9 +189,10 @@ struct e1000_mac_operations {
34874 s32 (*read_mac_addr)(struct e1000_hw *);
34875 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
34876 };
34877+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34878
34879 struct e1000_mac_info {
34880- struct e1000_mac_operations ops;
34881+ e1000_mac_operations_no_const ops;
34882 u8 addr[6];
34883 u8 perm_addr[6];
34884
34885@@ -213,6 +214,7 @@ struct e1000_mbx_operations {
34886 s32 (*check_for_ack)(struct e1000_hw *);
34887 s32 (*check_for_rst)(struct e1000_hw *);
34888 };
34889+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34890
34891 struct e1000_mbx_stats {
34892 u32 msgs_tx;
34893@@ -224,7 +226,7 @@ struct e1000_mbx_stats {
34894 };
34895
34896 struct e1000_mbx_info {
34897- struct e1000_mbx_operations ops;
34898+ e1000_mbx_operations_no_const ops;
34899 struct e1000_mbx_stats stats;
34900 u32 timeout;
34901 u32 usec_delay;
34902diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34903index dcebd12..c1fe8be 100644
34904--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34905+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34906@@ -805,7 +805,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
34907 /* store the new cycle speed */
34908 adapter->cycle_speed = cycle_speed;
34909
34910- ACCESS_ONCE(adapter->base_incval) = incval;
34911+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
34912 smp_mb();
34913
34914 /* grab the ptp lock */
34915diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34916index 204848d..d8aeaec 100644
34917--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34918+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34919@@ -2791,6 +2791,7 @@ struct ixgbe_eeprom_operations {
34920 s32 (*update_checksum)(struct ixgbe_hw *);
34921 u16 (*calc_checksum)(struct ixgbe_hw *);
34922 };
34923+typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
34924
34925 struct ixgbe_mac_operations {
34926 s32 (*init_hw)(struct ixgbe_hw *);
34927@@ -2856,6 +2857,7 @@ struct ixgbe_mac_operations {
34928 s32 (*get_thermal_sensor_data)(struct ixgbe_hw *);
34929 s32 (*init_thermal_sensor_thresh)(struct ixgbe_hw *hw);
34930 };
34931+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34932
34933 struct ixgbe_phy_operations {
34934 s32 (*identify)(struct ixgbe_hw *);
34935@@ -2875,9 +2877,10 @@ struct ixgbe_phy_operations {
34936 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
34937 s32 (*check_overtemp)(struct ixgbe_hw *);
34938 };
34939+typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
34940
34941 struct ixgbe_eeprom_info {
34942- struct ixgbe_eeprom_operations ops;
34943+ ixgbe_eeprom_operations_no_const ops;
34944 enum ixgbe_eeprom_type type;
34945 u32 semaphore_delay;
34946 u16 word_size;
34947@@ -2887,7 +2890,7 @@ struct ixgbe_eeprom_info {
34948
34949 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
34950 struct ixgbe_mac_info {
34951- struct ixgbe_mac_operations ops;
34952+ ixgbe_mac_operations_no_const ops;
34953 enum ixgbe_mac_type type;
34954 u8 addr[ETH_ALEN];
34955 u8 perm_addr[ETH_ALEN];
34956@@ -2916,7 +2919,7 @@ struct ixgbe_mac_info {
34957 };
34958
34959 struct ixgbe_phy_info {
34960- struct ixgbe_phy_operations ops;
34961+ ixgbe_phy_operations_no_const ops;
34962 struct mdio_if_info mdio;
34963 enum ixgbe_phy_type type;
34964 u32 id;
34965@@ -2944,6 +2947,7 @@ struct ixgbe_mbx_operations {
34966 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
34967 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
34968 };
34969+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34970
34971 struct ixgbe_mbx_stats {
34972 u32 msgs_tx;
34973@@ -2955,7 +2959,7 @@ struct ixgbe_mbx_stats {
34974 };
34975
34976 struct ixgbe_mbx_info {
34977- struct ixgbe_mbx_operations ops;
34978+ ixgbe_mbx_operations_no_const ops;
34979 struct ixgbe_mbx_stats stats;
34980 u32 timeout;
34981 u32 usec_delay;
34982diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
34983index 25c951d..cc7cf33 100644
34984--- a/drivers/net/ethernet/intel/ixgbevf/vf.h
34985+++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
34986@@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
34987 s32 (*clear_vfta)(struct ixgbe_hw *);
34988 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
34989 };
34990+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34991
34992 enum ixgbe_mac_type {
34993 ixgbe_mac_unknown = 0,
34994@@ -79,7 +80,7 @@ enum ixgbe_mac_type {
34995 };
34996
34997 struct ixgbe_mac_info {
34998- struct ixgbe_mac_operations ops;
34999+ ixgbe_mac_operations_no_const ops;
35000 u8 addr[6];
35001 u8 perm_addr[6];
35002
35003@@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35004 s32 (*check_for_ack)(struct ixgbe_hw *);
35005 s32 (*check_for_rst)(struct ixgbe_hw *);
35006 };
35007+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35008
35009 struct ixgbe_mbx_stats {
35010 u32 msgs_tx;
35011@@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35012 };
35013
35014 struct ixgbe_mbx_info {
35015- struct ixgbe_mbx_operations ops;
35016+ ixgbe_mbx_operations_no_const ops;
35017 struct ixgbe_mbx_stats stats;
35018 u32 timeout;
35019 u32 udelay;
35020diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
35021index a0313de..e83a572 100644
35022--- a/drivers/net/ethernet/mellanox/mlx4/main.c
35023+++ b/drivers/net/ethernet/mellanox/mlx4/main.c
35024@@ -41,6 +41,7 @@
35025 #include <linux/slab.h>
35026 #include <linux/io-mapping.h>
35027 #include <linux/delay.h>
35028+#include <linux/sched.h>
35029
35030 #include <linux/mlx4/device.h>
35031 #include <linux/mlx4/doorbell.h>
35032diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35033index 5046a64..71ca936 100644
35034--- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35035+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35036@@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35037 void (*link_down)(struct __vxge_hw_device *devh);
35038 void (*crit_err)(struct __vxge_hw_device *devh,
35039 enum vxge_hw_event type, u64 ext_data);
35040-};
35041+} __no_const;
35042
35043 /*
35044 * struct __vxge_hw_blockpool_entry - Block private data structure
35045diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35046index 4a518a3..936b334 100644
35047--- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35048+++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35049@@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35050 struct vxge_hw_mempool_dma *dma_object,
35051 u32 index,
35052 u32 is_last);
35053-};
35054+} __no_const;
35055
35056 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35057 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35058diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35059index eb81da4..1592b62 100644
35060--- a/drivers/net/ethernet/realtek/r8169.c
35061+++ b/drivers/net/ethernet/realtek/r8169.c
35062@@ -723,22 +723,22 @@ struct rtl8169_private {
35063 struct mdio_ops {
35064 void (*write)(void __iomem *, int, int);
35065 int (*read)(void __iomem *, int);
35066- } mdio_ops;
35067+ } __no_const mdio_ops;
35068
35069 struct pll_power_ops {
35070 void (*down)(struct rtl8169_private *);
35071 void (*up)(struct rtl8169_private *);
35072- } pll_power_ops;
35073+ } __no_const pll_power_ops;
35074
35075 struct jumbo_ops {
35076 void (*enable)(struct rtl8169_private *);
35077 void (*disable)(struct rtl8169_private *);
35078- } jumbo_ops;
35079+ } __no_const jumbo_ops;
35080
35081 struct csi_ops {
35082 void (*write)(void __iomem *, int, int);
35083 u32 (*read)(void __iomem *, int);
35084- } csi_ops;
35085+ } __no_const csi_ops;
35086
35087 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35088 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35089diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35090index 4613591..d816601 100644
35091--- a/drivers/net/ethernet/sis/sis190.c
35092+++ b/drivers/net/ethernet/sis/sis190.c
35093@@ -1618,7 +1618,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35094 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35095 struct net_device *dev)
35096 {
35097- static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35098+ static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35099 struct sis190_private *tp = netdev_priv(dev);
35100 struct pci_dev *isa_bridge;
35101 u8 reg, tmp8;
35102diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35103index c07cfe9..81cbf7e 100644
35104--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35105+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35106@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35107
35108 writel(value, ioaddr + MMC_CNTRL);
35109
35110- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35111- MMC_CNTRL, value);
35112+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35113+// MMC_CNTRL, value);
35114 }
35115
35116 /* To mask all all interrupts.*/
35117diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35118index 2857ab0..9a1f9b0 100644
35119--- a/drivers/net/hyperv/hyperv_net.h
35120+++ b/drivers/net/hyperv/hyperv_net.h
35121@@ -99,7 +99,7 @@ struct rndis_device {
35122
35123 enum rndis_device_state state;
35124 bool link_state;
35125- atomic_t new_req_id;
35126+ atomic_unchecked_t new_req_id;
35127
35128 spinlock_t request_lock;
35129 struct list_head req_list;
35130diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35131index 981ebb1..b34959b 100644
35132--- a/drivers/net/hyperv/rndis_filter.c
35133+++ b/drivers/net/hyperv/rndis_filter.c
35134@@ -97,7 +97,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35135 * template
35136 */
35137 set = &rndis_msg->msg.set_req;
35138- set->req_id = atomic_inc_return(&dev->new_req_id);
35139+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35140
35141 /* Add to the request list */
35142 spin_lock_irqsave(&dev->request_lock, flags);
35143@@ -648,7 +648,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35144
35145 /* Setup the rndis set */
35146 halt = &request->request_msg.msg.halt_req;
35147- halt->req_id = atomic_inc_return(&dev->new_req_id);
35148+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35149
35150 /* Ignore return since this msg is optional. */
35151 rndis_filter_send_request(dev, request);
35152diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35153index 5c05572..389610b 100644
35154--- a/drivers/net/ppp/ppp_generic.c
35155+++ b/drivers/net/ppp/ppp_generic.c
35156@@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35157 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35158 struct ppp_stats stats;
35159 struct ppp_comp_stats cstats;
35160- char *vers;
35161
35162 switch (cmd) {
35163 case SIOCGPPPSTATS:
35164@@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35165 break;
35166
35167 case SIOCGPPPVER:
35168- vers = PPP_VERSION;
35169- if (copy_to_user(addr, vers, strlen(vers) + 1))
35170+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35171 break;
35172 err = 0;
35173 break;
35174diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35175index 62f30b4..ff99dfd 100644
35176--- a/drivers/net/usb/hso.c
35177+++ b/drivers/net/usb/hso.c
35178@@ -71,7 +71,7 @@
35179 #include <asm/byteorder.h>
35180 #include <linux/serial_core.h>
35181 #include <linux/serial.h>
35182-
35183+#include <asm/local.h>
35184
35185 #define MOD_AUTHOR "Option Wireless"
35186 #define MOD_DESCRIPTION "USB High Speed Option driver"
35187@@ -1182,7 +1182,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35188 struct urb *urb;
35189
35190 urb = serial->rx_urb[0];
35191- if (serial->port.count > 0) {
35192+ if (atomic_read(&serial->port.count) > 0) {
35193 count = put_rxbuf_data(urb, serial);
35194 if (count == -1)
35195 return;
35196@@ -1218,7 +1218,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35197 DUMP1(urb->transfer_buffer, urb->actual_length);
35198
35199 /* Anyone listening? */
35200- if (serial->port.count == 0)
35201+ if (atomic_read(&serial->port.count) == 0)
35202 return;
35203
35204 if (status == 0) {
35205@@ -1300,8 +1300,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35206 tty_port_tty_set(&serial->port, tty);
35207
35208 /* check for port already opened, if not set the termios */
35209- serial->port.count++;
35210- if (serial->port.count == 1) {
35211+ if (atomic_inc_return(&serial->port.count) == 1) {
35212 serial->rx_state = RX_IDLE;
35213 /* Force default termio settings */
35214 _hso_serial_set_termios(tty, NULL);
35215@@ -1313,7 +1312,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35216 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35217 if (result) {
35218 hso_stop_serial_device(serial->parent);
35219- serial->port.count--;
35220+ atomic_dec(&serial->port.count);
35221 kref_put(&serial->parent->ref, hso_serial_ref_free);
35222 }
35223 } else {
35224@@ -1350,10 +1349,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35225
35226 /* reset the rts and dtr */
35227 /* do the actual close */
35228- serial->port.count--;
35229+ atomic_dec(&serial->port.count);
35230
35231- if (serial->port.count <= 0) {
35232- serial->port.count = 0;
35233+ if (atomic_read(&serial->port.count) <= 0) {
35234+ atomic_set(&serial->port.count, 0);
35235 tty_port_tty_set(&serial->port, NULL);
35236 if (!usb_gone)
35237 hso_stop_serial_device(serial->parent);
35238@@ -1429,7 +1428,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35239
35240 /* the actual setup */
35241 spin_lock_irqsave(&serial->serial_lock, flags);
35242- if (serial->port.count)
35243+ if (atomic_read(&serial->port.count))
35244 _hso_serial_set_termios(tty, old);
35245 else
35246 tty->termios = old;
35247@@ -1888,7 +1887,7 @@ static void intr_callback(struct urb *urb)
35248 D1("Pending read interrupt on port %d\n", i);
35249 spin_lock(&serial->serial_lock);
35250 if (serial->rx_state == RX_IDLE &&
35251- serial->port.count > 0) {
35252+ atomic_read(&serial->port.count) > 0) {
35253 /* Setup and send a ctrl req read on
35254 * port i */
35255 if (!serial->rx_urb_filled[0]) {
35256@@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
35257 /* Start all serial ports */
35258 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35259 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35260- if (dev2ser(serial_table[i])->port.count) {
35261+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
35262 result =
35263 hso_start_serial_device(serial_table[i], GFP_NOIO);
35264 hso_kick_transmit(dev2ser(serial_table[i]));
35265diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35266index 420d69b..74f90a2 100644
35267--- a/drivers/net/wireless/ath/ath.h
35268+++ b/drivers/net/wireless/ath/ath.h
35269@@ -119,6 +119,7 @@ struct ath_ops {
35270 void (*write_flush) (void *);
35271 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35272 };
35273+typedef struct ath_ops __no_const ath_ops_no_const;
35274
35275 struct ath_common;
35276 struct ath_bus_ops;
35277diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35278index 8d78253..bebbb68 100644
35279--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35280+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35281@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35282 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35283 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35284
35285- ACCESS_ONCE(ads->ds_link) = i->link;
35286- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35287+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
35288+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35289
35290 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35291 ctl6 = SM(i->keytype, AR_EncrType);
35292@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35293
35294 if ((i->is_first || i->is_last) &&
35295 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35296- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35297+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35298 | set11nTries(i->rates, 1)
35299 | set11nTries(i->rates, 2)
35300 | set11nTries(i->rates, 3)
35301 | (i->dur_update ? AR_DurUpdateEna : 0)
35302 | SM(0, AR_BurstDur);
35303
35304- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35305+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35306 | set11nRate(i->rates, 1)
35307 | set11nRate(i->rates, 2)
35308 | set11nRate(i->rates, 3);
35309 } else {
35310- ACCESS_ONCE(ads->ds_ctl2) = 0;
35311- ACCESS_ONCE(ads->ds_ctl3) = 0;
35312+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35313+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35314 }
35315
35316 if (!i->is_first) {
35317- ACCESS_ONCE(ads->ds_ctl0) = 0;
35318- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35319- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35320+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35321+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35322+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35323 return;
35324 }
35325
35326@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35327 break;
35328 }
35329
35330- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35331+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35332 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35333 | SM(i->txpower, AR_XmitPower)
35334 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35335@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35336 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35337 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35338
35339- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35340- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35341+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35342+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35343
35344 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35345 return;
35346
35347- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35348+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35349 | set11nPktDurRTSCTS(i->rates, 1);
35350
35351- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35352+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35353 | set11nPktDurRTSCTS(i->rates, 3);
35354
35355- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35356+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35357 | set11nRateFlags(i->rates, 1)
35358 | set11nRateFlags(i->rates, 2)
35359 | set11nRateFlags(i->rates, 3)
35360diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35361index d9e0824..1a874e7 100644
35362--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35363+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35364@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35365 (i->qcu << AR_TxQcuNum_S) | desc_len;
35366
35367 checksum += val;
35368- ACCESS_ONCE(ads->info) = val;
35369+ ACCESS_ONCE_RW(ads->info) = val;
35370
35371 checksum += i->link;
35372- ACCESS_ONCE(ads->link) = i->link;
35373+ ACCESS_ONCE_RW(ads->link) = i->link;
35374
35375 checksum += i->buf_addr[0];
35376- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35377+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35378 checksum += i->buf_addr[1];
35379- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35380+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35381 checksum += i->buf_addr[2];
35382- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35383+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35384 checksum += i->buf_addr[3];
35385- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35386+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35387
35388 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35389- ACCESS_ONCE(ads->ctl3) = val;
35390+ ACCESS_ONCE_RW(ads->ctl3) = val;
35391 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35392- ACCESS_ONCE(ads->ctl5) = val;
35393+ ACCESS_ONCE_RW(ads->ctl5) = val;
35394 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35395- ACCESS_ONCE(ads->ctl7) = val;
35396+ ACCESS_ONCE_RW(ads->ctl7) = val;
35397 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35398- ACCESS_ONCE(ads->ctl9) = val;
35399+ ACCESS_ONCE_RW(ads->ctl9) = val;
35400
35401 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35402- ACCESS_ONCE(ads->ctl10) = checksum;
35403+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
35404
35405 if (i->is_first || i->is_last) {
35406- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35407+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35408 | set11nTries(i->rates, 1)
35409 | set11nTries(i->rates, 2)
35410 | set11nTries(i->rates, 3)
35411 | (i->dur_update ? AR_DurUpdateEna : 0)
35412 | SM(0, AR_BurstDur);
35413
35414- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35415+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35416 | set11nRate(i->rates, 1)
35417 | set11nRate(i->rates, 2)
35418 | set11nRate(i->rates, 3);
35419 } else {
35420- ACCESS_ONCE(ads->ctl13) = 0;
35421- ACCESS_ONCE(ads->ctl14) = 0;
35422+ ACCESS_ONCE_RW(ads->ctl13) = 0;
35423+ ACCESS_ONCE_RW(ads->ctl14) = 0;
35424 }
35425
35426 ads->ctl20 = 0;
35427@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35428
35429 ctl17 = SM(i->keytype, AR_EncrType);
35430 if (!i->is_first) {
35431- ACCESS_ONCE(ads->ctl11) = 0;
35432- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35433- ACCESS_ONCE(ads->ctl15) = 0;
35434- ACCESS_ONCE(ads->ctl16) = 0;
35435- ACCESS_ONCE(ads->ctl17) = ctl17;
35436- ACCESS_ONCE(ads->ctl18) = 0;
35437- ACCESS_ONCE(ads->ctl19) = 0;
35438+ ACCESS_ONCE_RW(ads->ctl11) = 0;
35439+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35440+ ACCESS_ONCE_RW(ads->ctl15) = 0;
35441+ ACCESS_ONCE_RW(ads->ctl16) = 0;
35442+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35443+ ACCESS_ONCE_RW(ads->ctl18) = 0;
35444+ ACCESS_ONCE_RW(ads->ctl19) = 0;
35445 return;
35446 }
35447
35448- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35449+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35450 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35451 | SM(i->txpower, AR_XmitPower)
35452 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35453@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35454 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35455 ctl12 |= SM(val, AR_PAPRDChainMask);
35456
35457- ACCESS_ONCE(ads->ctl12) = ctl12;
35458- ACCESS_ONCE(ads->ctl17) = ctl17;
35459+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35460+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35461
35462- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35463+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35464 | set11nPktDurRTSCTS(i->rates, 1);
35465
35466- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35467+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35468 | set11nPktDurRTSCTS(i->rates, 3);
35469
35470- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35471+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35472 | set11nRateFlags(i->rates, 1)
35473 | set11nRateFlags(i->rates, 2)
35474 | set11nRateFlags(i->rates, 3)
35475 | SM(i->rtscts_rate, AR_RTSCTSRate);
35476
35477- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35478+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35479 }
35480
35481 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35482diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35483index 02f5007..bd0bd8f 100644
35484--- a/drivers/net/wireless/ath/ath9k/hw.h
35485+++ b/drivers/net/wireless/ath/ath9k/hw.h
35486@@ -610,7 +610,7 @@ struct ath_hw_private_ops {
35487
35488 /* ANI */
35489 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35490-};
35491+} __no_const;
35492
35493 /**
35494 * struct ath_hw_ops - callbacks used by hardware code and driver code
35495@@ -640,7 +640,7 @@ struct ath_hw_ops {
35496 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35497 struct ath_hw_antcomb_conf *antconf);
35498
35499-};
35500+} __no_const;
35501
35502 struct ath_nf_limits {
35503 s16 max;
35504@@ -660,7 +660,7 @@ enum ath_cal_list {
35505 #define AH_FASTCC 0x4
35506
35507 struct ath_hw {
35508- struct ath_ops reg_ops;
35509+ ath_ops_no_const reg_ops;
35510
35511 struct ieee80211_hw *hw;
35512 struct ath_common common;
35513diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35514index af00e2c..ab04d34 100644
35515--- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35516+++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35517@@ -545,7 +545,7 @@ struct phy_func_ptr {
35518 void (*carrsuppr)(struct brcms_phy *);
35519 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35520 void (*detach)(struct brcms_phy *);
35521-};
35522+} __no_const;
35523
35524 struct brcms_phy {
35525 struct brcms_phy_pub pubpi_ro;
35526diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35527index faec404..a5277f1 100644
35528--- a/drivers/net/wireless/iwlegacy/3945-mac.c
35529+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35530@@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35531 */
35532 if (il3945_mod_params.disable_hw_scan) {
35533 D_INFO("Disabling hw_scan\n");
35534- il3945_mac_ops.hw_scan = NULL;
35535+ pax_open_kernel();
35536+ *(void **)&il3945_mac_ops.hw_scan = NULL;
35537+ pax_close_kernel();
35538 }
35539
35540 D_INFO("*** LOAD DRIVER ***\n");
35541diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35542index a0b7cfd..20b49f7 100644
35543--- a/drivers/net/wireless/mac80211_hwsim.c
35544+++ b/drivers/net/wireless/mac80211_hwsim.c
35545@@ -1752,9 +1752,11 @@ static int __init init_mac80211_hwsim(void)
35546 return -EINVAL;
35547
35548 if (fake_hw_scan) {
35549- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35550- mac80211_hwsim_ops.sw_scan_start = NULL;
35551- mac80211_hwsim_ops.sw_scan_complete = NULL;
35552+ pax_open_kernel();
35553+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35554+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35555+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35556+ pax_close_kernel();
35557 }
35558
35559 spin_lock_init(&hwsim_radio_lock);
35560diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35561index bd3b0bf..f9db92a 100644
35562--- a/drivers/net/wireless/mwifiex/main.h
35563+++ b/drivers/net/wireless/mwifiex/main.h
35564@@ -567,7 +567,7 @@ struct mwifiex_if_ops {
35565 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35566 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
35567 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
35568-};
35569+} __no_const;
35570
35571 struct mwifiex_adapter {
35572 u8 iface_type;
35573diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35574index dfcd02a..a42a59d 100644
35575--- a/drivers/net/wireless/rndis_wlan.c
35576+++ b/drivers/net/wireless/rndis_wlan.c
35577@@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35578
35579 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35580
35581- if (rts_threshold < 0 || rts_threshold > 2347)
35582+ if (rts_threshold > 2347)
35583 rts_threshold = 2347;
35584
35585 tmp = cpu_to_le32(rts_threshold);
35586diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
35587index 8f75402..eed109d 100644
35588--- a/drivers/net/wireless/rt2x00/rt2x00.h
35589+++ b/drivers/net/wireless/rt2x00/rt2x00.h
35590@@ -396,7 +396,7 @@ struct rt2x00_intf {
35591 * for hardware which doesn't support hardware
35592 * sequence counting.
35593 */
35594- atomic_t seqno;
35595+ atomic_unchecked_t seqno;
35596 };
35597
35598 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
35599diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
35600index 2fd8301..9767e8c 100644
35601--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
35602+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
35603@@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
35604 * sequence counter given by mac80211.
35605 */
35606 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
35607- seqno = atomic_add_return(0x10, &intf->seqno);
35608+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
35609 else
35610- seqno = atomic_read(&intf->seqno);
35611+ seqno = atomic_read_unchecked(&intf->seqno);
35612
35613 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
35614 hdr->seq_ctrl |= cpu_to_le16(seqno);
35615diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
35616index 9d8f581..0f6589e 100644
35617--- a/drivers/net/wireless/ti/wl1251/wl1251.h
35618+++ b/drivers/net/wireless/ti/wl1251/wl1251.h
35619@@ -266,7 +266,7 @@ struct wl1251_if_operations {
35620 void (*reset)(struct wl1251 *wl);
35621 void (*enable_irq)(struct wl1251 *wl);
35622 void (*disable_irq)(struct wl1251 *wl);
35623-};
35624+} __no_const;
35625
35626 struct wl1251 {
35627 struct ieee80211_hw *hw;
35628diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
35629index 0b3f0b5..62f68bd 100644
35630--- a/drivers/net/wireless/ti/wlcore/wlcore.h
35631+++ b/drivers/net/wireless/ti/wlcore/wlcore.h
35632@@ -61,7 +61,7 @@ struct wlcore_ops {
35633 struct wl12xx_vif *wlvif);
35634 s8 (*get_pg_ver)(struct wl1271 *wl);
35635 void (*get_mac)(struct wl1271 *wl);
35636-};
35637+} __no_const;
35638
35639 enum wlcore_partitions {
35640 PART_DOWN,
35641diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
35642index f34b5b2..b5abb9f 100644
35643--- a/drivers/oprofile/buffer_sync.c
35644+++ b/drivers/oprofile/buffer_sync.c
35645@@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
35646 if (cookie == NO_COOKIE)
35647 offset = pc;
35648 if (cookie == INVALID_COOKIE) {
35649- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35650+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35651 offset = pc;
35652 }
35653 if (cookie != last_cookie) {
35654@@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
35655 /* add userspace sample */
35656
35657 if (!mm) {
35658- atomic_inc(&oprofile_stats.sample_lost_no_mm);
35659+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
35660 return 0;
35661 }
35662
35663 cookie = lookup_dcookie(mm, s->eip, &offset);
35664
35665 if (cookie == INVALID_COOKIE) {
35666- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35667+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35668 return 0;
35669 }
35670
35671@@ -563,7 +563,7 @@ void sync_buffer(int cpu)
35672 /* ignore backtraces if failed to add a sample */
35673 if (state == sb_bt_start) {
35674 state = sb_bt_ignore;
35675- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
35676+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
35677 }
35678 }
35679 release_mm(mm);
35680diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
35681index c0cc4e7..44d4e54 100644
35682--- a/drivers/oprofile/event_buffer.c
35683+++ b/drivers/oprofile/event_buffer.c
35684@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
35685 }
35686
35687 if (buffer_pos == buffer_size) {
35688- atomic_inc(&oprofile_stats.event_lost_overflow);
35689+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
35690 return;
35691 }
35692
35693diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
35694index ed2c3ec..deda85a 100644
35695--- a/drivers/oprofile/oprof.c
35696+++ b/drivers/oprofile/oprof.c
35697@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
35698 if (oprofile_ops.switch_events())
35699 return;
35700
35701- atomic_inc(&oprofile_stats.multiplex_counter);
35702+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
35703 start_switch_worker();
35704 }
35705
35706diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
35707index 917d28e..d62d981 100644
35708--- a/drivers/oprofile/oprofile_stats.c
35709+++ b/drivers/oprofile/oprofile_stats.c
35710@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
35711 cpu_buf->sample_invalid_eip = 0;
35712 }
35713
35714- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
35715- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
35716- atomic_set(&oprofile_stats.event_lost_overflow, 0);
35717- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
35718- atomic_set(&oprofile_stats.multiplex_counter, 0);
35719+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
35720+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
35721+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
35722+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
35723+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
35724 }
35725
35726
35727diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
35728index 38b6fc0..b5cbfce 100644
35729--- a/drivers/oprofile/oprofile_stats.h
35730+++ b/drivers/oprofile/oprofile_stats.h
35731@@ -13,11 +13,11 @@
35732 #include <linux/atomic.h>
35733
35734 struct oprofile_stat_struct {
35735- atomic_t sample_lost_no_mm;
35736- atomic_t sample_lost_no_mapping;
35737- atomic_t bt_lost_no_mapping;
35738- atomic_t event_lost_overflow;
35739- atomic_t multiplex_counter;
35740+ atomic_unchecked_t sample_lost_no_mm;
35741+ atomic_unchecked_t sample_lost_no_mapping;
35742+ atomic_unchecked_t bt_lost_no_mapping;
35743+ atomic_unchecked_t event_lost_overflow;
35744+ atomic_unchecked_t multiplex_counter;
35745 };
35746
35747 extern struct oprofile_stat_struct oprofile_stats;
35748diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
35749index 849357c..b83c1e0 100644
35750--- a/drivers/oprofile/oprofilefs.c
35751+++ b/drivers/oprofile/oprofilefs.c
35752@@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
35753
35754
35755 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
35756- char const *name, atomic_t *val)
35757+ char const *name, atomic_unchecked_t *val)
35758 {
35759 return __oprofilefs_create_file(sb, root, name,
35760 &atomic_ro_fops, 0444, val);
35761diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
35762index 3f56bc0..707d642 100644
35763--- a/drivers/parport/procfs.c
35764+++ b/drivers/parport/procfs.c
35765@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
35766
35767 *ppos += len;
35768
35769- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
35770+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
35771 }
35772
35773 #ifdef CONFIG_PARPORT_1284
35774@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
35775
35776 *ppos += len;
35777
35778- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
35779+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
35780 }
35781 #endif /* IEEE1284.3 support. */
35782
35783diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
35784index 9fff878..ad0ad53 100644
35785--- a/drivers/pci/hotplug/cpci_hotplug.h
35786+++ b/drivers/pci/hotplug/cpci_hotplug.h
35787@@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
35788 int (*hardware_test) (struct slot* slot, u32 value);
35789 u8 (*get_power) (struct slot* slot);
35790 int (*set_power) (struct slot* slot, int value);
35791-};
35792+} __no_const;
35793
35794 struct cpci_hp_controller {
35795 unsigned int irq;
35796diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
35797index 76ba8a1..20ca857 100644
35798--- a/drivers/pci/hotplug/cpqphp_nvram.c
35799+++ b/drivers/pci/hotplug/cpqphp_nvram.c
35800@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
35801
35802 void compaq_nvram_init (void __iomem *rom_start)
35803 {
35804+
35805+#ifndef CONFIG_PAX_KERNEXEC
35806 if (rom_start) {
35807 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
35808 }
35809+#endif
35810+
35811 dbg("int15 entry = %p\n", compaq_int15_entry_point);
35812
35813 /* initialize our int15 lock */
35814diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
35815index b500840..d7159d3 100644
35816--- a/drivers/pci/pcie/aspm.c
35817+++ b/drivers/pci/pcie/aspm.c
35818@@ -27,9 +27,9 @@
35819 #define MODULE_PARAM_PREFIX "pcie_aspm."
35820
35821 /* Note: those are not register definitions */
35822-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
35823-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
35824-#define ASPM_STATE_L1 (4) /* L1 state */
35825+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
35826+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
35827+#define ASPM_STATE_L1 (4U) /* L1 state */
35828 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
35829 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
35830
35831diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
35832index 658ac97..05e1b90 100644
35833--- a/drivers/pci/probe.c
35834+++ b/drivers/pci/probe.c
35835@@ -137,7 +137,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
35836 u16 orig_cmd;
35837 struct pci_bus_region region;
35838
35839- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
35840+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
35841
35842 if (!dev->mmio_always_on) {
35843 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
35844diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
35845index 27911b5..5b6db88 100644
35846--- a/drivers/pci/proc.c
35847+++ b/drivers/pci/proc.c
35848@@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
35849 static int __init pci_proc_init(void)
35850 {
35851 struct pci_dev *dev = NULL;
35852+
35853+#ifdef CONFIG_GRKERNSEC_PROC_ADD
35854+#ifdef CONFIG_GRKERNSEC_PROC_USER
35855+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
35856+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
35857+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
35858+#endif
35859+#else
35860 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
35861+#endif
35862 proc_create("devices", 0, proc_bus_pci_dir,
35863 &proc_bus_pci_dev_operations);
35864 proc_initialized = 1;
35865diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
35866index 8b5610d..a4c22bb 100644
35867--- a/drivers/platform/x86/thinkpad_acpi.c
35868+++ b/drivers/platform/x86/thinkpad_acpi.c
35869@@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
35870 return 0;
35871 }
35872
35873-void static hotkey_mask_warn_incomplete_mask(void)
35874+static void hotkey_mask_warn_incomplete_mask(void)
35875 {
35876 /* log only what the user can fix... */
35877 const u32 wantedmask = hotkey_driver_mask &
35878@@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
35879 }
35880 }
35881
35882-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35883- struct tp_nvram_state *newn,
35884- const u32 event_mask)
35885-{
35886-
35887 #define TPACPI_COMPARE_KEY(__scancode, __member) \
35888 do { \
35889 if ((event_mask & (1 << __scancode)) && \
35890@@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35891 tpacpi_hotkey_send_key(__scancode); \
35892 } while (0)
35893
35894- void issue_volchange(const unsigned int oldvol,
35895- const unsigned int newvol)
35896- {
35897- unsigned int i = oldvol;
35898+static void issue_volchange(const unsigned int oldvol,
35899+ const unsigned int newvol,
35900+ const u32 event_mask)
35901+{
35902+ unsigned int i = oldvol;
35903
35904- while (i > newvol) {
35905- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35906- i--;
35907- }
35908- while (i < newvol) {
35909- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35910- i++;
35911- }
35912+ while (i > newvol) {
35913+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35914+ i--;
35915 }
35916+ while (i < newvol) {
35917+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35918+ i++;
35919+ }
35920+}
35921
35922- void issue_brightnesschange(const unsigned int oldbrt,
35923- const unsigned int newbrt)
35924- {
35925- unsigned int i = oldbrt;
35926+static void issue_brightnesschange(const unsigned int oldbrt,
35927+ const unsigned int newbrt,
35928+ const u32 event_mask)
35929+{
35930+ unsigned int i = oldbrt;
35931
35932- while (i > newbrt) {
35933- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35934- i--;
35935- }
35936- while (i < newbrt) {
35937- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35938- i++;
35939- }
35940+ while (i > newbrt) {
35941+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35942+ i--;
35943+ }
35944+ while (i < newbrt) {
35945+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35946+ i++;
35947 }
35948+}
35949
35950+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35951+ struct tp_nvram_state *newn,
35952+ const u32 event_mask)
35953+{
35954 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
35955 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
35956 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
35957@@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35958 oldn->volume_level != newn->volume_level) {
35959 /* recently muted, or repeated mute keypress, or
35960 * multiple presses ending in mute */
35961- issue_volchange(oldn->volume_level, newn->volume_level);
35962+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35963 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
35964 }
35965 } else {
35966@@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35967 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35968 }
35969 if (oldn->volume_level != newn->volume_level) {
35970- issue_volchange(oldn->volume_level, newn->volume_level);
35971+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35972 } else if (oldn->volume_toggle != newn->volume_toggle) {
35973 /* repeated vol up/down keypress at end of scale ? */
35974 if (newn->volume_level == 0)
35975@@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35976 /* handle brightness */
35977 if (oldn->brightness_level != newn->brightness_level) {
35978 issue_brightnesschange(oldn->brightness_level,
35979- newn->brightness_level);
35980+ newn->brightness_level,
35981+ event_mask);
35982 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
35983 /* repeated key presses that didn't change state */
35984 if (newn->brightness_level == 0)
35985@@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35986 && !tp_features.bright_unkfw)
35987 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35988 }
35989+}
35990
35991 #undef TPACPI_COMPARE_KEY
35992 #undef TPACPI_MAY_SEND_KEY
35993-}
35994
35995 /*
35996 * Polling driver
35997diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
35998index 769d265..a3a05ca 100644
35999--- a/drivers/pnp/pnpbios/bioscalls.c
36000+++ b/drivers/pnp/pnpbios/bioscalls.c
36001@@ -58,7 +58,7 @@ do { \
36002 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36003 } while(0)
36004
36005-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36006+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36007 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36008
36009 /*
36010@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36011
36012 cpu = get_cpu();
36013 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36014+
36015+ pax_open_kernel();
36016 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36017+ pax_close_kernel();
36018
36019 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36020 spin_lock_irqsave(&pnp_bios_lock, flags);
36021@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36022 :"memory");
36023 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36024
36025+ pax_open_kernel();
36026 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36027+ pax_close_kernel();
36028+
36029 put_cpu();
36030
36031 /* If we get here and this is set then the PnP BIOS faulted on us. */
36032@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36033 return status;
36034 }
36035
36036-void pnpbios_calls_init(union pnp_bios_install_struct *header)
36037+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36038 {
36039 int i;
36040
36041@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36042 pnp_bios_callpoint.offset = header->fields.pm16offset;
36043 pnp_bios_callpoint.segment = PNP_CS16;
36044
36045+ pax_open_kernel();
36046+
36047 for_each_possible_cpu(i) {
36048 struct desc_struct *gdt = get_cpu_gdt_table(i);
36049 if (!gdt)
36050@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36051 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36052 (unsigned long)__va(header->fields.pm16dseg));
36053 }
36054+
36055+ pax_close_kernel();
36056 }
36057diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36058index b0ecacb..7c9da2e 100644
36059--- a/drivers/pnp/resource.c
36060+++ b/drivers/pnp/resource.c
36061@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36062 return 1;
36063
36064 /* check if the resource is valid */
36065- if (*irq < 0 || *irq > 15)
36066+ if (*irq > 15)
36067 return 0;
36068
36069 /* check if the resource is reserved */
36070@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36071 return 1;
36072
36073 /* check if the resource is valid */
36074- if (*dma < 0 || *dma == 4 || *dma > 7)
36075+ if (*dma == 4 || *dma > 7)
36076 return 0;
36077
36078 /* check if the resource is reserved */
36079diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36080index f5d6d37..739f6a9 100644
36081--- a/drivers/power/bq27x00_battery.c
36082+++ b/drivers/power/bq27x00_battery.c
36083@@ -72,7 +72,7 @@
36084 struct bq27x00_device_info;
36085 struct bq27x00_access_methods {
36086 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36087-};
36088+} __no_const;
36089
36090 enum bq27x00_chip { BQ27000, BQ27500 };
36091
36092diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36093index 8d53174..04c65de 100644
36094--- a/drivers/regulator/max8660.c
36095+++ b/drivers/regulator/max8660.c
36096@@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36097 max8660->shadow_regs[MAX8660_OVER1] = 5;
36098 } else {
36099 /* Otherwise devices can be toggled via software */
36100- max8660_dcdc_ops.enable = max8660_dcdc_enable;
36101- max8660_dcdc_ops.disable = max8660_dcdc_disable;
36102+ pax_open_kernel();
36103+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36104+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36105+ pax_close_kernel();
36106 }
36107
36108 /*
36109diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36110index 970a233..ee1f241 100644
36111--- a/drivers/regulator/mc13892-regulator.c
36112+++ b/drivers/regulator/mc13892-regulator.c
36113@@ -566,10 +566,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36114 }
36115 mc13xxx_unlock(mc13892);
36116
36117- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36118+ pax_open_kernel();
36119+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36120 = mc13892_vcam_set_mode;
36121- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36122+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36123 = mc13892_vcam_get_mode;
36124+ pax_close_kernel();
36125
36126 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36127 ARRAY_SIZE(mc13892_regulators));
36128diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36129index cace6d3..f623fda 100644
36130--- a/drivers/rtc/rtc-dev.c
36131+++ b/drivers/rtc/rtc-dev.c
36132@@ -14,6 +14,7 @@
36133 #include <linux/module.h>
36134 #include <linux/rtc.h>
36135 #include <linux/sched.h>
36136+#include <linux/grsecurity.h>
36137 #include "rtc-core.h"
36138
36139 static dev_t rtc_devt;
36140@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36141 if (copy_from_user(&tm, uarg, sizeof(tm)))
36142 return -EFAULT;
36143
36144+ gr_log_timechange();
36145+
36146 return rtc_set_time(rtc, &tm);
36147
36148 case RTC_PIE_ON:
36149diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36150index 3fcf627..f334910 100644
36151--- a/drivers/scsi/aacraid/aacraid.h
36152+++ b/drivers/scsi/aacraid/aacraid.h
36153@@ -492,7 +492,7 @@ struct adapter_ops
36154 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36155 /* Administrative operations */
36156 int (*adapter_comm)(struct aac_dev * dev, int comm);
36157-};
36158+} __no_const;
36159
36160 /*
36161 * Define which interrupt handler needs to be installed
36162diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36163index 0d279c44..3d25a97 100644
36164--- a/drivers/scsi/aacraid/linit.c
36165+++ b/drivers/scsi/aacraid/linit.c
36166@@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36167 #elif defined(__devinitconst)
36168 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36169 #else
36170-static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36171+static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36172 #endif
36173 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36174 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36175diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36176index ff80552..1c4120c 100644
36177--- a/drivers/scsi/aic94xx/aic94xx_init.c
36178+++ b/drivers/scsi/aic94xx/aic94xx_init.c
36179@@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36180 .lldd_ata_set_dmamode = asd_set_dmamode,
36181 };
36182
36183-static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36184+static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36185 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36186 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36187 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36188diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36189index 4ad7e36..d004679 100644
36190--- a/drivers/scsi/bfa/bfa.h
36191+++ b/drivers/scsi/bfa/bfa.h
36192@@ -196,7 +196,7 @@ struct bfa_hwif_s {
36193 u32 *end);
36194 int cpe_vec_q0;
36195 int rme_vec_q0;
36196-};
36197+} __no_const;
36198 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36199
36200 struct bfa_faa_cbfn_s {
36201diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36202index f0f80e2..8ec946b 100644
36203--- a/drivers/scsi/bfa/bfa_fcpim.c
36204+++ b/drivers/scsi/bfa/bfa_fcpim.c
36205@@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36206
36207 bfa_iotag_attach(fcp);
36208
36209- fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36210+ fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36211 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36212 (fcp->num_itns * sizeof(struct bfa_itn_s));
36213 memset(fcp->itn_arr, 0,
36214@@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36215 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36216 {
36217 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36218- struct bfa_itn_s *itn;
36219+ bfa_itn_s_no_const *itn;
36220
36221 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36222 itn->isr = isr;
36223diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36224index 36f26da..38a34a8 100644
36225--- a/drivers/scsi/bfa/bfa_fcpim.h
36226+++ b/drivers/scsi/bfa/bfa_fcpim.h
36227@@ -37,6 +37,7 @@ struct bfa_iotag_s {
36228 struct bfa_itn_s {
36229 bfa_isr_func_t isr;
36230 };
36231+typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36232
36233 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36234 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36235@@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36236 struct list_head iotag_tio_free_q; /* free IO resources */
36237 struct list_head iotag_unused_q; /* unused IO resources*/
36238 struct bfa_iotag_s *iotag_arr;
36239- struct bfa_itn_s *itn_arr;
36240+ bfa_itn_s_no_const *itn_arr;
36241 int num_ioim_reqs;
36242 int num_fwtio_reqs;
36243 int num_itns;
36244diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36245index 1a99d4b..e85d64b 100644
36246--- a/drivers/scsi/bfa/bfa_ioc.h
36247+++ b/drivers/scsi/bfa/bfa_ioc.h
36248@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36249 bfa_ioc_disable_cbfn_t disable_cbfn;
36250 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36251 bfa_ioc_reset_cbfn_t reset_cbfn;
36252-};
36253+} __no_const;
36254
36255 /*
36256 * IOC event notification mechanism.
36257@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36258 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36259 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36260 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36261-};
36262+} __no_const;
36263
36264 /*
36265 * Queue element to wait for room in request queue. FIFO order is
36266diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36267index b48c24f..dac0fbc 100644
36268--- a/drivers/scsi/hosts.c
36269+++ b/drivers/scsi/hosts.c
36270@@ -42,7 +42,7 @@
36271 #include "scsi_logging.h"
36272
36273
36274-static atomic_t scsi_host_next_hn; /* host_no for next new host */
36275+static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
36276
36277
36278 static void scsi_host_cls_release(struct device *dev)
36279@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36280 * subtract one because we increment first then return, but we need to
36281 * know what the next host number was before increment
36282 */
36283- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36284+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36285 shost->dma_channel = 0xff;
36286
36287 /* These three are default values which can be overridden */
36288diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36289index 796482b..d08435c 100644
36290--- a/drivers/scsi/hpsa.c
36291+++ b/drivers/scsi/hpsa.c
36292@@ -536,7 +536,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
36293 unsigned long flags;
36294
36295 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36296- return h->access.command_completed(h, q);
36297+ return h->access->command_completed(h, q);
36298
36299 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
36300 a = rq->head[rq->current_entry];
36301@@ -3354,7 +3354,7 @@ static void start_io(struct ctlr_info *h)
36302 while (!list_empty(&h->reqQ)) {
36303 c = list_entry(h->reqQ.next, struct CommandList, list);
36304 /* can't do anything if fifo is full */
36305- if ((h->access.fifo_full(h))) {
36306+ if ((h->access->fifo_full(h))) {
36307 dev_warn(&h->pdev->dev, "fifo full\n");
36308 break;
36309 }
36310@@ -3376,7 +3376,7 @@ static void start_io(struct ctlr_info *h)
36311
36312 /* Tell the controller execute command */
36313 spin_unlock_irqrestore(&h->lock, flags);
36314- h->access.submit_command(h, c);
36315+ h->access->submit_command(h, c);
36316 spin_lock_irqsave(&h->lock, flags);
36317 }
36318 spin_unlock_irqrestore(&h->lock, flags);
36319@@ -3384,17 +3384,17 @@ static void start_io(struct ctlr_info *h)
36320
36321 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
36322 {
36323- return h->access.command_completed(h, q);
36324+ return h->access->command_completed(h, q);
36325 }
36326
36327 static inline bool interrupt_pending(struct ctlr_info *h)
36328 {
36329- return h->access.intr_pending(h);
36330+ return h->access->intr_pending(h);
36331 }
36332
36333 static inline long interrupt_not_for_us(struct ctlr_info *h)
36334 {
36335- return (h->access.intr_pending(h) == 0) ||
36336+ return (h->access->intr_pending(h) == 0) ||
36337 (h->interrupts_enabled == 0);
36338 }
36339
36340@@ -4298,7 +4298,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36341 if (prod_index < 0)
36342 return -ENODEV;
36343 h->product_name = products[prod_index].product_name;
36344- h->access = *(products[prod_index].access);
36345+ h->access = products[prod_index].access;
36346
36347 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
36348 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
36349@@ -4580,7 +4580,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36350
36351 assert_spin_locked(&lockup_detector_lock);
36352 remove_ctlr_from_lockup_detector_list(h);
36353- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36354+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36355 spin_lock_irqsave(&h->lock, flags);
36356 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36357 spin_unlock_irqrestore(&h->lock, flags);
36358@@ -4758,7 +4758,7 @@ reinit_after_soft_reset:
36359 }
36360
36361 /* make sure the board interrupts are off */
36362- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36363+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36364
36365 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36366 goto clean2;
36367@@ -4792,7 +4792,7 @@ reinit_after_soft_reset:
36368 * fake ones to scoop up any residual completions.
36369 */
36370 spin_lock_irqsave(&h->lock, flags);
36371- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36372+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36373 spin_unlock_irqrestore(&h->lock, flags);
36374 free_irqs(h);
36375 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36376@@ -4811,9 +4811,9 @@ reinit_after_soft_reset:
36377 dev_info(&h->pdev->dev, "Board READY.\n");
36378 dev_info(&h->pdev->dev,
36379 "Waiting for stale completions to drain.\n");
36380- h->access.set_intr_mask(h, HPSA_INTR_ON);
36381+ h->access->set_intr_mask(h, HPSA_INTR_ON);
36382 msleep(10000);
36383- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36384+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36385
36386 rc = controller_reset_failed(h->cfgtable);
36387 if (rc)
36388@@ -4834,7 +4834,7 @@ reinit_after_soft_reset:
36389 }
36390
36391 /* Turn the interrupts on so we can service requests */
36392- h->access.set_intr_mask(h, HPSA_INTR_ON);
36393+ h->access->set_intr_mask(h, HPSA_INTR_ON);
36394
36395 hpsa_hba_inquiry(h);
36396 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36397@@ -4886,7 +4886,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36398 * To write all data in the battery backed cache to disks
36399 */
36400 hpsa_flush_cache(h);
36401- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36402+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36403 hpsa_free_irqs_and_disable_msix(h);
36404 }
36405
36406@@ -5055,7 +5055,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36407 return;
36408 }
36409 /* Change the access methods to the performant access methods */
36410- h->access = SA5_performant_access;
36411+ h->access = &SA5_performant_access;
36412 h->transMethod = CFGTBL_Trans_Performant;
36413 }
36414
36415diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36416index 9816479..c5d4e97 100644
36417--- a/drivers/scsi/hpsa.h
36418+++ b/drivers/scsi/hpsa.h
36419@@ -79,7 +79,7 @@ struct ctlr_info {
36420 unsigned int msix_vector;
36421 unsigned int msi_vector;
36422 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36423- struct access_method access;
36424+ struct access_method *access;
36425
36426 /* queue and queue Info */
36427 struct list_head reqQ;
36428diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36429index f2df059..a3a9930 100644
36430--- a/drivers/scsi/ips.h
36431+++ b/drivers/scsi/ips.h
36432@@ -1027,7 +1027,7 @@ typedef struct {
36433 int (*intr)(struct ips_ha *);
36434 void (*enableint)(struct ips_ha *);
36435 uint32_t (*statupd)(struct ips_ha *);
36436-} ips_hw_func_t;
36437+} __no_const ips_hw_func_t;
36438
36439 typedef struct ips_ha {
36440 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36441diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36442index aceffad..c35c08d 100644
36443--- a/drivers/scsi/libfc/fc_exch.c
36444+++ b/drivers/scsi/libfc/fc_exch.c
36445@@ -105,12 +105,12 @@ struct fc_exch_mgr {
36446 * all together if not used XXX
36447 */
36448 struct {
36449- atomic_t no_free_exch;
36450- atomic_t no_free_exch_xid;
36451- atomic_t xid_not_found;
36452- atomic_t xid_busy;
36453- atomic_t seq_not_found;
36454- atomic_t non_bls_resp;
36455+ atomic_unchecked_t no_free_exch;
36456+ atomic_unchecked_t no_free_exch_xid;
36457+ atomic_unchecked_t xid_not_found;
36458+ atomic_unchecked_t xid_busy;
36459+ atomic_unchecked_t seq_not_found;
36460+ atomic_unchecked_t non_bls_resp;
36461 } stats;
36462 };
36463
36464@@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36465 /* allocate memory for exchange */
36466 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36467 if (!ep) {
36468- atomic_inc(&mp->stats.no_free_exch);
36469+ atomic_inc_unchecked(&mp->stats.no_free_exch);
36470 goto out;
36471 }
36472 memset(ep, 0, sizeof(*ep));
36473@@ -780,7 +780,7 @@ out:
36474 return ep;
36475 err:
36476 spin_unlock_bh(&pool->lock);
36477- atomic_inc(&mp->stats.no_free_exch_xid);
36478+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36479 mempool_free(ep, mp->ep_pool);
36480 return NULL;
36481 }
36482@@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36483 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36484 ep = fc_exch_find(mp, xid);
36485 if (!ep) {
36486- atomic_inc(&mp->stats.xid_not_found);
36487+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36488 reject = FC_RJT_OX_ID;
36489 goto out;
36490 }
36491@@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36492 ep = fc_exch_find(mp, xid);
36493 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36494 if (ep) {
36495- atomic_inc(&mp->stats.xid_busy);
36496+ atomic_inc_unchecked(&mp->stats.xid_busy);
36497 reject = FC_RJT_RX_ID;
36498 goto rel;
36499 }
36500@@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36501 }
36502 xid = ep->xid; /* get our XID */
36503 } else if (!ep) {
36504- atomic_inc(&mp->stats.xid_not_found);
36505+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36506 reject = FC_RJT_RX_ID; /* XID not found */
36507 goto out;
36508 }
36509@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36510 } else {
36511 sp = &ep->seq;
36512 if (sp->id != fh->fh_seq_id) {
36513- atomic_inc(&mp->stats.seq_not_found);
36514+ atomic_inc_unchecked(&mp->stats.seq_not_found);
36515 if (f_ctl & FC_FC_END_SEQ) {
36516 /*
36517 * Update sequence_id based on incoming last
36518@@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36519
36520 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36521 if (!ep) {
36522- atomic_inc(&mp->stats.xid_not_found);
36523+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36524 goto out;
36525 }
36526 if (ep->esb_stat & ESB_ST_COMPLETE) {
36527- atomic_inc(&mp->stats.xid_not_found);
36528+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36529 goto rel;
36530 }
36531 if (ep->rxid == FC_XID_UNKNOWN)
36532 ep->rxid = ntohs(fh->fh_rx_id);
36533 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36534- atomic_inc(&mp->stats.xid_not_found);
36535+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36536 goto rel;
36537 }
36538 if (ep->did != ntoh24(fh->fh_s_id) &&
36539 ep->did != FC_FID_FLOGI) {
36540- atomic_inc(&mp->stats.xid_not_found);
36541+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36542 goto rel;
36543 }
36544 sof = fr_sof(fp);
36545@@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36546 sp->ssb_stat |= SSB_ST_RESP;
36547 sp->id = fh->fh_seq_id;
36548 } else if (sp->id != fh->fh_seq_id) {
36549- atomic_inc(&mp->stats.seq_not_found);
36550+ atomic_inc_unchecked(&mp->stats.seq_not_found);
36551 goto rel;
36552 }
36553
36554@@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36555 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36556
36557 if (!sp)
36558- atomic_inc(&mp->stats.xid_not_found);
36559+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36560 else
36561- atomic_inc(&mp->stats.non_bls_resp);
36562+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
36563
36564 fc_frame_free(fp);
36565 }
36566diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36567index d109cc3..09f4e7d 100644
36568--- a/drivers/scsi/libsas/sas_ata.c
36569+++ b/drivers/scsi/libsas/sas_ata.c
36570@@ -529,7 +529,7 @@ static struct ata_port_operations sas_sata_ops = {
36571 .postreset = ata_std_postreset,
36572 .error_handler = ata_std_error_handler,
36573 .post_internal_cmd = sas_ata_post_internal,
36574- .qc_defer = ata_std_qc_defer,
36575+ .qc_defer = ata_std_qc_defer,
36576 .qc_prep = ata_noop_qc_prep,
36577 .qc_issue = sas_ata_qc_issue,
36578 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36579diff --git a/drivers/scsi/lpfc/Makefile b/drivers/scsi/lpfc/Makefile
36580index fe5d396..e93d526 100644
36581--- a/drivers/scsi/lpfc/Makefile
36582+++ b/drivers/scsi/lpfc/Makefile
36583@@ -22,7 +22,7 @@
36584 ccflags-$(GCOV) := -fprofile-arcs -ftest-coverage
36585 ccflags-$(GCOV) += -O0
36586
36587-ccflags-y += -Werror
36588+#ccflags-y += -Werror
36589
36590 obj-$(CONFIG_SCSI_LPFC) := lpfc.o
36591
36592diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36593index e5da6da..c888d48 100644
36594--- a/drivers/scsi/lpfc/lpfc.h
36595+++ b/drivers/scsi/lpfc/lpfc.h
36596@@ -416,7 +416,7 @@ struct lpfc_vport {
36597 struct dentry *debug_nodelist;
36598 struct dentry *vport_debugfs_root;
36599 struct lpfc_debugfs_trc *disc_trc;
36600- atomic_t disc_trc_cnt;
36601+ atomic_unchecked_t disc_trc_cnt;
36602 #endif
36603 uint8_t stat_data_enabled;
36604 uint8_t stat_data_blocked;
36605@@ -830,8 +830,8 @@ struct lpfc_hba {
36606 struct timer_list fabric_block_timer;
36607 unsigned long bit_flags;
36608 #define FABRIC_COMANDS_BLOCKED 0
36609- atomic_t num_rsrc_err;
36610- atomic_t num_cmd_success;
36611+ atomic_unchecked_t num_rsrc_err;
36612+ atomic_unchecked_t num_cmd_success;
36613 unsigned long last_rsrc_error_time;
36614 unsigned long last_ramp_down_time;
36615 unsigned long last_ramp_up_time;
36616@@ -867,7 +867,7 @@ struct lpfc_hba {
36617
36618 struct dentry *debug_slow_ring_trc;
36619 struct lpfc_debugfs_trc *slow_ring_trc;
36620- atomic_t slow_ring_trc_cnt;
36621+ atomic_unchecked_t slow_ring_trc_cnt;
36622 /* iDiag debugfs sub-directory */
36623 struct dentry *idiag_root;
36624 struct dentry *idiag_pci_cfg;
36625diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
36626index 3217d63..c417981 100644
36627--- a/drivers/scsi/lpfc/lpfc_debugfs.c
36628+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
36629@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
36630
36631 #include <linux/debugfs.h>
36632
36633-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36634+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36635 static unsigned long lpfc_debugfs_start_time = 0L;
36636
36637 /* iDiag */
36638@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
36639 lpfc_debugfs_enable = 0;
36640
36641 len = 0;
36642- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
36643+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
36644 (lpfc_debugfs_max_disc_trc - 1);
36645 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
36646 dtp = vport->disc_trc + i;
36647@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
36648 lpfc_debugfs_enable = 0;
36649
36650 len = 0;
36651- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
36652+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
36653 (lpfc_debugfs_max_slow_ring_trc - 1);
36654 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
36655 dtp = phba->slow_ring_trc + i;
36656@@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
36657 !vport || !vport->disc_trc)
36658 return;
36659
36660- index = atomic_inc_return(&vport->disc_trc_cnt) &
36661+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
36662 (lpfc_debugfs_max_disc_trc - 1);
36663 dtp = vport->disc_trc + index;
36664 dtp->fmt = fmt;
36665 dtp->data1 = data1;
36666 dtp->data2 = data2;
36667 dtp->data3 = data3;
36668- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36669+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36670 dtp->jif = jiffies;
36671 #endif
36672 return;
36673@@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
36674 !phba || !phba->slow_ring_trc)
36675 return;
36676
36677- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
36678+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
36679 (lpfc_debugfs_max_slow_ring_trc - 1);
36680 dtp = phba->slow_ring_trc + index;
36681 dtp->fmt = fmt;
36682 dtp->data1 = data1;
36683 dtp->data2 = data2;
36684 dtp->data3 = data3;
36685- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36686+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36687 dtp->jif = jiffies;
36688 #endif
36689 return;
36690@@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36691 "slow_ring buffer\n");
36692 goto debug_failed;
36693 }
36694- atomic_set(&phba->slow_ring_trc_cnt, 0);
36695+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
36696 memset(phba->slow_ring_trc, 0,
36697 (sizeof(struct lpfc_debugfs_trc) *
36698 lpfc_debugfs_max_slow_ring_trc));
36699@@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36700 "buffer\n");
36701 goto debug_failed;
36702 }
36703- atomic_set(&vport->disc_trc_cnt, 0);
36704+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
36705
36706 snprintf(name, sizeof(name), "discovery_trace");
36707 vport->debug_disc_trc =
36708diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
36709index 411ed48..967f553 100644
36710--- a/drivers/scsi/lpfc/lpfc_init.c
36711+++ b/drivers/scsi/lpfc/lpfc_init.c
36712@@ -10341,8 +10341,10 @@ lpfc_init(void)
36713 "misc_register returned with status %d", error);
36714
36715 if (lpfc_enable_npiv) {
36716- lpfc_transport_functions.vport_create = lpfc_vport_create;
36717- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36718+ pax_open_kernel();
36719+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
36720+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36721+ pax_close_kernel();
36722 }
36723 lpfc_transport_template =
36724 fc_attach_transport(&lpfc_transport_functions);
36725diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
36726index 66e0906..1620281 100644
36727--- a/drivers/scsi/lpfc/lpfc_scsi.c
36728+++ b/drivers/scsi/lpfc/lpfc_scsi.c
36729@@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
36730 uint32_t evt_posted;
36731
36732 spin_lock_irqsave(&phba->hbalock, flags);
36733- atomic_inc(&phba->num_rsrc_err);
36734+ atomic_inc_unchecked(&phba->num_rsrc_err);
36735 phba->last_rsrc_error_time = jiffies;
36736
36737 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
36738@@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
36739 unsigned long flags;
36740 struct lpfc_hba *phba = vport->phba;
36741 uint32_t evt_posted;
36742- atomic_inc(&phba->num_cmd_success);
36743+ atomic_inc_unchecked(&phba->num_cmd_success);
36744
36745 if (vport->cfg_lun_queue_depth <= queue_depth)
36746 return;
36747@@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36748 unsigned long num_rsrc_err, num_cmd_success;
36749 int i;
36750
36751- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
36752- num_cmd_success = atomic_read(&phba->num_cmd_success);
36753+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
36754+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
36755
36756 /*
36757 * The error and success command counters are global per
36758@@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36759 }
36760 }
36761 lpfc_destroy_vport_work_array(phba, vports);
36762- atomic_set(&phba->num_rsrc_err, 0);
36763- atomic_set(&phba->num_cmd_success, 0);
36764+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
36765+ atomic_set_unchecked(&phba->num_cmd_success, 0);
36766 }
36767
36768 /**
36769@@ -460,8 +460,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
36770 }
36771 }
36772 lpfc_destroy_vport_work_array(phba, vports);
36773- atomic_set(&phba->num_rsrc_err, 0);
36774- atomic_set(&phba->num_cmd_success, 0);
36775+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
36776+ atomic_set_unchecked(&phba->num_cmd_success, 0);
36777 }
36778
36779 /**
36780diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
36781index ea8a0b4..812a124 100644
36782--- a/drivers/scsi/pmcraid.c
36783+++ b/drivers/scsi/pmcraid.c
36784@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
36785 res->scsi_dev = scsi_dev;
36786 scsi_dev->hostdata = res;
36787 res->change_detected = 0;
36788- atomic_set(&res->read_failures, 0);
36789- atomic_set(&res->write_failures, 0);
36790+ atomic_set_unchecked(&res->read_failures, 0);
36791+ atomic_set_unchecked(&res->write_failures, 0);
36792 rc = 0;
36793 }
36794 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
36795@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
36796
36797 /* If this was a SCSI read/write command keep count of errors */
36798 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
36799- atomic_inc(&res->read_failures);
36800+ atomic_inc_unchecked(&res->read_failures);
36801 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
36802- atomic_inc(&res->write_failures);
36803+ atomic_inc_unchecked(&res->write_failures);
36804
36805 if (!RES_IS_GSCSI(res->cfg_entry) &&
36806 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
36807@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
36808 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36809 * hrrq_id assigned here in queuecommand
36810 */
36811- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36812+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36813 pinstance->num_hrrq;
36814 cmd->cmd_done = pmcraid_io_done;
36815
36816@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
36817 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36818 * hrrq_id assigned here in queuecommand
36819 */
36820- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36821+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36822 pinstance->num_hrrq;
36823
36824 if (request_size) {
36825@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
36826
36827 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
36828 /* add resources only after host is added into system */
36829- if (!atomic_read(&pinstance->expose_resources))
36830+ if (!atomic_read_unchecked(&pinstance->expose_resources))
36831 return;
36832
36833 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
36834@@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
36835 init_waitqueue_head(&pinstance->reset_wait_q);
36836
36837 atomic_set(&pinstance->outstanding_cmds, 0);
36838- atomic_set(&pinstance->last_message_id, 0);
36839- atomic_set(&pinstance->expose_resources, 0);
36840+ atomic_set_unchecked(&pinstance->last_message_id, 0);
36841+ atomic_set_unchecked(&pinstance->expose_resources, 0);
36842
36843 INIT_LIST_HEAD(&pinstance->free_res_q);
36844 INIT_LIST_HEAD(&pinstance->used_res_q);
36845@@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
36846 /* Schedule worker thread to handle CCN and take care of adding and
36847 * removing devices to OS
36848 */
36849- atomic_set(&pinstance->expose_resources, 1);
36850+ atomic_set_unchecked(&pinstance->expose_resources, 1);
36851 schedule_work(&pinstance->worker_q);
36852 return rc;
36853
36854diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
36855index e1d150f..6c6df44 100644
36856--- a/drivers/scsi/pmcraid.h
36857+++ b/drivers/scsi/pmcraid.h
36858@@ -748,7 +748,7 @@ struct pmcraid_instance {
36859 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
36860
36861 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
36862- atomic_t last_message_id;
36863+ atomic_unchecked_t last_message_id;
36864
36865 /* configuration table */
36866 struct pmcraid_config_table *cfg_table;
36867@@ -777,7 +777,7 @@ struct pmcraid_instance {
36868 atomic_t outstanding_cmds;
36869
36870 /* should add/delete resources to mid-layer now ?*/
36871- atomic_t expose_resources;
36872+ atomic_unchecked_t expose_resources;
36873
36874
36875
36876@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
36877 struct pmcraid_config_table_entry_ext cfg_entry_ext;
36878 };
36879 struct scsi_device *scsi_dev; /* Link scsi_device structure */
36880- atomic_t read_failures; /* count of failed READ commands */
36881- atomic_t write_failures; /* count of failed WRITE commands */
36882+ atomic_unchecked_t read_failures; /* count of failed READ commands */
36883+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
36884
36885 /* To indicate add/delete/modify during CCN */
36886 u8 change_detected;
36887diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
36888index 5ab9530..2dd80f7 100644
36889--- a/drivers/scsi/qla2xxx/qla_attr.c
36890+++ b/drivers/scsi/qla2xxx/qla_attr.c
36891@@ -1855,7 +1855,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
36892 return 0;
36893 }
36894
36895-struct fc_function_template qla2xxx_transport_functions = {
36896+fc_function_template_no_const qla2xxx_transport_functions = {
36897
36898 .show_host_node_name = 1,
36899 .show_host_port_name = 1,
36900@@ -1902,7 +1902,7 @@ struct fc_function_template qla2xxx_transport_functions = {
36901 .bsg_timeout = qla24xx_bsg_timeout,
36902 };
36903
36904-struct fc_function_template qla2xxx_transport_vport_functions = {
36905+fc_function_template_no_const qla2xxx_transport_vport_functions = {
36906
36907 .show_host_node_name = 1,
36908 .show_host_port_name = 1,
36909diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
36910index 39007f5..7fafc64 100644
36911--- a/drivers/scsi/qla2xxx/qla_def.h
36912+++ b/drivers/scsi/qla2xxx/qla_def.h
36913@@ -2284,7 +2284,7 @@ struct isp_operations {
36914 int (*start_scsi) (srb_t *);
36915 int (*abort_isp) (struct scsi_qla_host *);
36916 int (*iospace_config)(struct qla_hw_data*);
36917-};
36918+} __no_const;
36919
36920 /* MSI-X Support *************************************************************/
36921
36922diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
36923index 9eacd2d..d79629c 100644
36924--- a/drivers/scsi/qla2xxx/qla_gbl.h
36925+++ b/drivers/scsi/qla2xxx/qla_gbl.h
36926@@ -484,8 +484,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
36927 struct device_attribute;
36928 extern struct device_attribute *qla2x00_host_attrs[];
36929 struct fc_function_template;
36930-extern struct fc_function_template qla2xxx_transport_functions;
36931-extern struct fc_function_template qla2xxx_transport_vport_functions;
36932+extern fc_function_template_no_const qla2xxx_transport_functions;
36933+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
36934 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
36935 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
36936 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
36937diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
36938index 96a5616..eeb185a 100644
36939--- a/drivers/scsi/qla4xxx/ql4_def.h
36940+++ b/drivers/scsi/qla4xxx/ql4_def.h
36941@@ -268,7 +268,7 @@ struct ddb_entry {
36942 * (4000 only) */
36943 atomic_t relogin_timer; /* Max Time to wait for
36944 * relogin to complete */
36945- atomic_t relogin_retry_count; /* Num of times relogin has been
36946+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
36947 * retried */
36948 uint32_t default_time2wait; /* Default Min time between
36949 * relogins (+aens) */
36950diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
36951index cd15678..f7e6846 100644
36952--- a/drivers/scsi/qla4xxx/ql4_os.c
36953+++ b/drivers/scsi/qla4xxx/ql4_os.c
36954@@ -2615,12 +2615,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
36955 */
36956 if (!iscsi_is_session_online(cls_sess)) {
36957 /* Reset retry relogin timer */
36958- atomic_inc(&ddb_entry->relogin_retry_count);
36959+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
36960 DEBUG2(ql4_printk(KERN_INFO, ha,
36961 "%s: index[%d] relogin timed out-retrying"
36962 " relogin (%d), retry (%d)\n", __func__,
36963 ddb_entry->fw_ddb_index,
36964- atomic_read(&ddb_entry->relogin_retry_count),
36965+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
36966 ddb_entry->default_time2wait + 4));
36967 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
36968 atomic_set(&ddb_entry->retry_relogin_timer,
36969@@ -4517,7 +4517,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
36970
36971 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
36972 atomic_set(&ddb_entry->relogin_timer, 0);
36973- atomic_set(&ddb_entry->relogin_retry_count, 0);
36974+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
36975 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
36976 ddb_entry->default_relogin_timeout =
36977 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
36978diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
36979index bbbc9c9..ce22f77 100644
36980--- a/drivers/scsi/scsi.c
36981+++ b/drivers/scsi/scsi.c
36982@@ -659,7 +659,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
36983 unsigned long timeout;
36984 int rtn = 0;
36985
36986- atomic_inc(&cmd->device->iorequest_cnt);
36987+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
36988
36989 /* check if the device is still usable */
36990 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
36991diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
36992index 495db80..fb37d59 100644
36993--- a/drivers/scsi/scsi_lib.c
36994+++ b/drivers/scsi/scsi_lib.c
36995@@ -1422,7 +1422,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
36996 shost = sdev->host;
36997 scsi_init_cmd_errh(cmd);
36998 cmd->result = DID_NO_CONNECT << 16;
36999- atomic_inc(&cmd->device->iorequest_cnt);
37000+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37001
37002 /*
37003 * SCSI request completion path will do scsi_device_unbusy(),
37004@@ -1448,9 +1448,9 @@ static void scsi_softirq_done(struct request *rq)
37005
37006 INIT_LIST_HEAD(&cmd->eh_entry);
37007
37008- atomic_inc(&cmd->device->iodone_cnt);
37009+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
37010 if (cmd->result)
37011- atomic_inc(&cmd->device->ioerr_cnt);
37012+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37013
37014 disposition = scsi_decide_disposition(cmd);
37015 if (disposition != SUCCESS &&
37016diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37017index bb7c482..7551a95 100644
37018--- a/drivers/scsi/scsi_sysfs.c
37019+++ b/drivers/scsi/scsi_sysfs.c
37020@@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37021 char *buf) \
37022 { \
37023 struct scsi_device *sdev = to_scsi_device(dev); \
37024- unsigned long long count = atomic_read(&sdev->field); \
37025+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
37026 return snprintf(buf, 20, "0x%llx\n", count); \
37027 } \
37028 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37029diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37030index 84a1fdf..693b0d6 100644
37031--- a/drivers/scsi/scsi_tgt_lib.c
37032+++ b/drivers/scsi/scsi_tgt_lib.c
37033@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37034 int err;
37035
37036 dprintk("%lx %u\n", uaddr, len);
37037- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37038+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37039 if (err) {
37040 /*
37041 * TODO: need to fixup sg_tablesize, max_segment_size,
37042diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37043index 5797604..289a5b5 100644
37044--- a/drivers/scsi/scsi_transport_fc.c
37045+++ b/drivers/scsi/scsi_transport_fc.c
37046@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37047 * Netlink Infrastructure
37048 */
37049
37050-static atomic_t fc_event_seq;
37051+static atomic_unchecked_t fc_event_seq;
37052
37053 /**
37054 * fc_get_event_number - Obtain the next sequential FC event number
37055@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
37056 u32
37057 fc_get_event_number(void)
37058 {
37059- return atomic_add_return(1, &fc_event_seq);
37060+ return atomic_add_return_unchecked(1, &fc_event_seq);
37061 }
37062 EXPORT_SYMBOL(fc_get_event_number);
37063
37064@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
37065 {
37066 int error;
37067
37068- atomic_set(&fc_event_seq, 0);
37069+ atomic_set_unchecked(&fc_event_seq, 0);
37070
37071 error = transport_class_register(&fc_host_class);
37072 if (error)
37073@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37074 char *cp;
37075
37076 *val = simple_strtoul(buf, &cp, 0);
37077- if ((*cp && (*cp != '\n')) || (*val < 0))
37078+ if (*cp && (*cp != '\n'))
37079 return -EINVAL;
37080 /*
37081 * Check for overflow; dev_loss_tmo is u32
37082diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37083index 1cf640e..78e9014 100644
37084--- a/drivers/scsi/scsi_transport_iscsi.c
37085+++ b/drivers/scsi/scsi_transport_iscsi.c
37086@@ -79,7 +79,7 @@ struct iscsi_internal {
37087 struct transport_container session_cont;
37088 };
37089
37090-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37091+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37092 static struct workqueue_struct *iscsi_eh_timer_workq;
37093
37094 static DEFINE_IDA(iscsi_sess_ida);
37095@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37096 int err;
37097
37098 ihost = shost->shost_data;
37099- session->sid = atomic_add_return(1, &iscsi_session_nr);
37100+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37101
37102 if (target_id == ISCSI_MAX_TARGET) {
37103 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37104@@ -2940,7 +2940,7 @@ static __init int iscsi_transport_init(void)
37105 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37106 ISCSI_TRANSPORT_VERSION);
37107
37108- atomic_set(&iscsi_session_nr, 0);
37109+ atomic_set_unchecked(&iscsi_session_nr, 0);
37110
37111 err = class_register(&iscsi_transport_class);
37112 if (err)
37113diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37114index 21a045e..ec89e03 100644
37115--- a/drivers/scsi/scsi_transport_srp.c
37116+++ b/drivers/scsi/scsi_transport_srp.c
37117@@ -33,7 +33,7 @@
37118 #include "scsi_transport_srp_internal.h"
37119
37120 struct srp_host_attrs {
37121- atomic_t next_port_id;
37122+ atomic_unchecked_t next_port_id;
37123 };
37124 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37125
37126@@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37127 struct Scsi_Host *shost = dev_to_shost(dev);
37128 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37129
37130- atomic_set(&srp_host->next_port_id, 0);
37131+ atomic_set_unchecked(&srp_host->next_port_id, 0);
37132 return 0;
37133 }
37134
37135@@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37136 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37137 rport->roles = ids->roles;
37138
37139- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37140+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37141 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37142
37143 transport_setup_device(&rport->dev);
37144diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37145index 9c5c5f2..8414557 100644
37146--- a/drivers/scsi/sg.c
37147+++ b/drivers/scsi/sg.c
37148@@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37149 sdp->disk->disk_name,
37150 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37151 NULL,
37152- (char *)arg);
37153+ (char __user *)arg);
37154 case BLKTRACESTART:
37155 return blk_trace_startstop(sdp->device->request_queue, 1);
37156 case BLKTRACESTOP:
37157diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37158index 1041cb8..4a946fa 100644
37159--- a/drivers/spi/spi.c
37160+++ b/drivers/spi/spi.c
37161@@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
37162 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37163
37164 /* portable code must never pass more than 32 bytes */
37165-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37166+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37167
37168 static u8 *buf;
37169
37170diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37171index 34afc16..ffe44dd 100644
37172--- a/drivers/staging/octeon/ethernet-rx.c
37173+++ b/drivers/staging/octeon/ethernet-rx.c
37174@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37175 /* Increment RX stats for virtual ports */
37176 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37177 #ifdef CONFIG_64BIT
37178- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37179- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37180+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37181+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37182 #else
37183- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37184- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37185+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37186+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37187 #endif
37188 }
37189 netif_receive_skb(skb);
37190@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37191 dev->name);
37192 */
37193 #ifdef CONFIG_64BIT
37194- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37195+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37196 #else
37197- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37198+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37199 #endif
37200 dev_kfree_skb_irq(skb);
37201 }
37202diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37203index 18f7a79..cc3bc24 100644
37204--- a/drivers/staging/octeon/ethernet.c
37205+++ b/drivers/staging/octeon/ethernet.c
37206@@ -259,11 +259,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37207 * since the RX tasklet also increments it.
37208 */
37209 #ifdef CONFIG_64BIT
37210- atomic64_add(rx_status.dropped_packets,
37211- (atomic64_t *)&priv->stats.rx_dropped);
37212+ atomic64_add_unchecked(rx_status.dropped_packets,
37213+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37214 #else
37215- atomic_add(rx_status.dropped_packets,
37216- (atomic_t *)&priv->stats.rx_dropped);
37217+ atomic_add_unchecked(rx_status.dropped_packets,
37218+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
37219 #endif
37220 }
37221
37222diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37223index dc23395..cf7e9b1 100644
37224--- a/drivers/staging/rtl8712/rtl871x_io.h
37225+++ b/drivers/staging/rtl8712/rtl871x_io.h
37226@@ -108,7 +108,7 @@ struct _io_ops {
37227 u8 *pmem);
37228 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37229 u8 *pmem);
37230-};
37231+} __no_const;
37232
37233 struct io_req {
37234 struct list_head list;
37235diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37236index c7b5e8b..783d6cb 100644
37237--- a/drivers/staging/sbe-2t3e3/netdev.c
37238+++ b/drivers/staging/sbe-2t3e3/netdev.c
37239@@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37240 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37241
37242 if (rlen)
37243- if (copy_to_user(data, &resp, rlen))
37244+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37245 return -EFAULT;
37246
37247 return 0;
37248diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c
37249index 42cdafe..2769103 100644
37250--- a/drivers/staging/speakup/speakup_soft.c
37251+++ b/drivers/staging/speakup/speakup_soft.c
37252@@ -241,11 +241,11 @@ static ssize_t softsynth_read(struct file *fp, char *buf, size_t count,
37253 break;
37254 } else if (!initialized) {
37255 if (*init) {
37256- ch = *init;
37257 init++;
37258 } else {
37259 initialized = 1;
37260 }
37261+ ch = *init;
37262 } else {
37263 ch = synth_buffer_getc();
37264 }
37265diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37266index 5d89c0f..9261317 100644
37267--- a/drivers/staging/usbip/usbip_common.h
37268+++ b/drivers/staging/usbip/usbip_common.h
37269@@ -289,7 +289,7 @@ struct usbip_device {
37270 void (*shutdown)(struct usbip_device *);
37271 void (*reset)(struct usbip_device *);
37272 void (*unusable)(struct usbip_device *);
37273- } eh_ops;
37274+ } __no_const eh_ops;
37275 };
37276
37277 #define kthread_get_run(threadfn, data, namefmt, ...) \
37278diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37279index 88b3298..3783eee 100644
37280--- a/drivers/staging/usbip/vhci.h
37281+++ b/drivers/staging/usbip/vhci.h
37282@@ -88,7 +88,7 @@ struct vhci_hcd {
37283 unsigned resuming:1;
37284 unsigned long re_timeout;
37285
37286- atomic_t seqnum;
37287+ atomic_unchecked_t seqnum;
37288
37289 /*
37290 * NOTE:
37291diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37292index f708cba..2de6d72 100644
37293--- a/drivers/staging/usbip/vhci_hcd.c
37294+++ b/drivers/staging/usbip/vhci_hcd.c
37295@@ -488,7 +488,7 @@ static void vhci_tx_urb(struct urb *urb)
37296 return;
37297 }
37298
37299- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37300+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37301 if (priv->seqnum == 0xffff)
37302 dev_info(&urb->dev->dev, "seqnum max\n");
37303
37304@@ -740,7 +740,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37305 return -ENOMEM;
37306 }
37307
37308- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37309+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37310 if (unlink->seqnum == 0xffff)
37311 pr_info("seqnum max\n");
37312
37313@@ -928,7 +928,7 @@ static int vhci_start(struct usb_hcd *hcd)
37314 vdev->rhport = rhport;
37315 }
37316
37317- atomic_set(&vhci->seqnum, 0);
37318+ atomic_set_unchecked(&vhci->seqnum, 0);
37319 spin_lock_init(&vhci->lock);
37320
37321 hcd->power_budget = 0; /* no limit */
37322diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37323index f0eaf04..5a82e06 100644
37324--- a/drivers/staging/usbip/vhci_rx.c
37325+++ b/drivers/staging/usbip/vhci_rx.c
37326@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37327 if (!urb) {
37328 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37329 pr_info("max seqnum %d\n",
37330- atomic_read(&the_controller->seqnum));
37331+ atomic_read_unchecked(&the_controller->seqnum));
37332 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37333 return;
37334 }
37335diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37336index 7735027..30eed13 100644
37337--- a/drivers/staging/vt6655/hostap.c
37338+++ b/drivers/staging/vt6655/hostap.c
37339@@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
37340 *
37341 */
37342
37343+static net_device_ops_no_const apdev_netdev_ops;
37344+
37345 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37346 {
37347 PSDevice apdev_priv;
37348 struct net_device *dev = pDevice->dev;
37349 int ret;
37350- const struct net_device_ops apdev_netdev_ops = {
37351- .ndo_start_xmit = pDevice->tx_80211,
37352- };
37353
37354 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37355
37356@@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37357 *apdev_priv = *pDevice;
37358 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37359
37360+ /* only half broken now */
37361+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37362 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37363
37364 pDevice->apdev->type = ARPHRD_IEEE80211;
37365diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37366index 51b5adf..098e320 100644
37367--- a/drivers/staging/vt6656/hostap.c
37368+++ b/drivers/staging/vt6656/hostap.c
37369@@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
37370 *
37371 */
37372
37373+static net_device_ops_no_const apdev_netdev_ops;
37374+
37375 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37376 {
37377 PSDevice apdev_priv;
37378 struct net_device *dev = pDevice->dev;
37379 int ret;
37380- const struct net_device_ops apdev_netdev_ops = {
37381- .ndo_start_xmit = pDevice->tx_80211,
37382- };
37383
37384 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37385
37386@@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37387 *apdev_priv = *pDevice;
37388 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37389
37390+ /* only half broken now */
37391+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37392 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37393
37394 pDevice->apdev->type = ARPHRD_IEEE80211;
37395diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37396index 7843dfd..3db105f 100644
37397--- a/drivers/staging/wlan-ng/hfa384x_usb.c
37398+++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37399@@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37400
37401 struct usbctlx_completor {
37402 int (*complete) (struct usbctlx_completor *);
37403-};
37404+} __no_const;
37405
37406 static int
37407 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37408diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37409index 1ca66ea..76f1343 100644
37410--- a/drivers/staging/zcache/tmem.c
37411+++ b/drivers/staging/zcache/tmem.c
37412@@ -39,7 +39,7 @@
37413 * A tmem host implementation must use this function to register callbacks
37414 * for memory allocation.
37415 */
37416-static struct tmem_hostops tmem_hostops;
37417+static tmem_hostops_no_const tmem_hostops;
37418
37419 static void tmem_objnode_tree_init(void);
37420
37421@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37422 * A tmem host implementation must use this function to register
37423 * callbacks for a page-accessible memory (PAM) implementation
37424 */
37425-static struct tmem_pamops tmem_pamops;
37426+static tmem_pamops_no_const tmem_pamops;
37427
37428 void tmem_register_pamops(struct tmem_pamops *m)
37429 {
37430diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37431index 0d4aa82..f7832d4 100644
37432--- a/drivers/staging/zcache/tmem.h
37433+++ b/drivers/staging/zcache/tmem.h
37434@@ -180,6 +180,7 @@ struct tmem_pamops {
37435 void (*new_obj)(struct tmem_obj *);
37436 int (*replace_in_obj)(void *, struct tmem_obj *);
37437 };
37438+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37439 extern void tmem_register_pamops(struct tmem_pamops *m);
37440
37441 /* memory allocation methods provided by the host implementation */
37442@@ -189,6 +190,7 @@ struct tmem_hostops {
37443 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37444 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37445 };
37446+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37447 extern void tmem_register_hostops(struct tmem_hostops *m);
37448
37449 /* core tmem accessor functions */
37450diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37451index c6c385f..b23c65d 100644
37452--- a/drivers/target/target_core_transport.c
37453+++ b/drivers/target/target_core_transport.c
37454@@ -1233,7 +1233,7 @@ struct se_device *transport_add_device_to_core_hba(
37455 spin_lock_init(&dev->se_port_lock);
37456 spin_lock_init(&dev->se_tmr_lock);
37457 spin_lock_init(&dev->qf_cmd_lock);
37458- atomic_set(&dev->dev_ordered_id, 0);
37459+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
37460
37461 se_dev_set_default_attribs(dev, dev_limits);
37462
37463@@ -1402,7 +1402,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37464 * Used to determine when ORDERED commands should go from
37465 * Dormant to Active status.
37466 */
37467- cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37468+ cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37469 smp_mb__after_atomic_inc();
37470 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37471 cmd->se_ordered_id, cmd->sam_task_attr,
37472diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
37473index e61cabd..7617d26 100644
37474--- a/drivers/tty/cyclades.c
37475+++ b/drivers/tty/cyclades.c
37476@@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
37477 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
37478 info->port.count);
37479 #endif
37480- info->port.count++;
37481+ atomic_inc(&info->port.count);
37482 #ifdef CY_DEBUG_COUNT
37483 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
37484- current->pid, info->port.count);
37485+ current->pid, atomic_read(&info->port.count));
37486 #endif
37487
37488 /*
37489@@ -3987,7 +3987,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
37490 for (j = 0; j < cy_card[i].nports; j++) {
37491 info = &cy_card[i].ports[j];
37492
37493- if (info->port.count) {
37494+ if (atomic_read(&info->port.count)) {
37495 /* XXX is the ldisc num worth this? */
37496 struct tty_struct *tty;
37497 struct tty_ldisc *ld;
37498diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
37499index 2d691eb..be02ebd 100644
37500--- a/drivers/tty/hvc/hvc_console.c
37501+++ b/drivers/tty/hvc/hvc_console.c
37502@@ -315,7 +315,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
37503
37504 spin_lock_irqsave(&hp->port.lock, flags);
37505 /* Check and then increment for fast path open. */
37506- if (hp->port.count++ > 0) {
37507+ if (atomic_inc_return(&hp->port.count) > 1) {
37508 spin_unlock_irqrestore(&hp->port.lock, flags);
37509 hvc_kick();
37510 return 0;
37511@@ -366,7 +366,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37512
37513 spin_lock_irqsave(&hp->port.lock, flags);
37514
37515- if (--hp->port.count == 0) {
37516+ if (atomic_dec_return(&hp->port.count) == 0) {
37517 spin_unlock_irqrestore(&hp->port.lock, flags);
37518 /* We are done with the tty pointer now. */
37519 tty_port_tty_set(&hp->port, NULL);
37520@@ -384,9 +384,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37521 */
37522 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
37523 } else {
37524- if (hp->port.count < 0)
37525+ if (atomic_read(&hp->port.count) < 0)
37526 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
37527- hp->vtermno, hp->port.count);
37528+ hp->vtermno, atomic_read(&hp->port.count));
37529 spin_unlock_irqrestore(&hp->port.lock, flags);
37530 }
37531
37532@@ -412,13 +412,13 @@ static void hvc_hangup(struct tty_struct *tty)
37533 * open->hangup case this can be called after the final close so prevent
37534 * that from happening for now.
37535 */
37536- if (hp->port.count <= 0) {
37537+ if (atomic_read(&hp->port.count) <= 0) {
37538 spin_unlock_irqrestore(&hp->port.lock, flags);
37539 return;
37540 }
37541
37542- temp_open_count = hp->port.count;
37543- hp->port.count = 0;
37544+ temp_open_count = atomic_read(&hp->port.count);
37545+ atomic_set(&hp->port.count, 0);
37546 spin_unlock_irqrestore(&hp->port.lock, flags);
37547 tty_port_tty_set(&hp->port, NULL);
37548
37549@@ -471,7 +471,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
37550 return -EPIPE;
37551
37552 /* FIXME what's this (unprotected) check for? */
37553- if (hp->port.count <= 0)
37554+ if (atomic_read(&hp->port.count) <= 0)
37555 return -EIO;
37556
37557 spin_lock_irqsave(&hp->lock, flags);
37558diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37559index d56788c..12d8f85 100644
37560--- a/drivers/tty/hvc/hvcs.c
37561+++ b/drivers/tty/hvc/hvcs.c
37562@@ -83,6 +83,7 @@
37563 #include <asm/hvcserver.h>
37564 #include <asm/uaccess.h>
37565 #include <asm/vio.h>
37566+#include <asm/local.h>
37567
37568 /*
37569 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37570@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37571
37572 spin_lock_irqsave(&hvcsd->lock, flags);
37573
37574- if (hvcsd->port.count > 0) {
37575+ if (atomic_read(&hvcsd->port.count) > 0) {
37576 spin_unlock_irqrestore(&hvcsd->lock, flags);
37577 printk(KERN_INFO "HVCS: vterm state unchanged. "
37578 "The hvcs device node is still in use.\n");
37579@@ -1134,7 +1135,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37580 if ((retval = hvcs_partner_connect(hvcsd)))
37581 goto error_release;
37582
37583- hvcsd->port.count = 1;
37584+ atomic_set(&hvcsd->port.count, 1);
37585 hvcsd->port.tty = tty;
37586 tty->driver_data = hvcsd;
37587
37588@@ -1168,7 +1169,7 @@ fast_open:
37589
37590 spin_lock_irqsave(&hvcsd->lock, flags);
37591 tty_port_get(&hvcsd->port);
37592- hvcsd->port.count++;
37593+ atomic_inc(&hvcsd->port.count);
37594 hvcsd->todo_mask |= HVCS_SCHED_READ;
37595 spin_unlock_irqrestore(&hvcsd->lock, flags);
37596
37597@@ -1212,7 +1213,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37598 hvcsd = tty->driver_data;
37599
37600 spin_lock_irqsave(&hvcsd->lock, flags);
37601- if (--hvcsd->port.count == 0) {
37602+ if (atomic_dec_and_test(&hvcsd->port.count)) {
37603
37604 vio_disable_interrupts(hvcsd->vdev);
37605
37606@@ -1238,10 +1239,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37607 free_irq(irq, hvcsd);
37608 tty_port_put(&hvcsd->port);
37609 return;
37610- } else if (hvcsd->port.count < 0) {
37611+ } else if (atomic_read(&hvcsd->port.count) < 0) {
37612 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
37613 " is missmanaged.\n",
37614- hvcsd->vdev->unit_address, hvcsd->port.count);
37615+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
37616 }
37617
37618 spin_unlock_irqrestore(&hvcsd->lock, flags);
37619@@ -1257,7 +1258,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37620
37621 spin_lock_irqsave(&hvcsd->lock, flags);
37622 /* Preserve this so that we know how many kref refs to put */
37623- temp_open_count = hvcsd->port.count;
37624+ temp_open_count = atomic_read(&hvcsd->port.count);
37625
37626 /*
37627 * Don't kref put inside the spinlock because the destruction
37628@@ -1272,7 +1273,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37629 tty->driver_data = NULL;
37630 hvcsd->port.tty = NULL;
37631
37632- hvcsd->port.count = 0;
37633+ atomic_set(&hvcsd->port.count, 0);
37634
37635 /* This will drop any buffered data on the floor which is OK in a hangup
37636 * scenario. */
37637@@ -1343,7 +1344,7 @@ static int hvcs_write(struct tty_struct *tty,
37638 * the middle of a write operation? This is a crummy place to do this
37639 * but we want to keep it all in the spinlock.
37640 */
37641- if (hvcsd->port.count <= 0) {
37642+ if (atomic_read(&hvcsd->port.count) <= 0) {
37643 spin_unlock_irqrestore(&hvcsd->lock, flags);
37644 return -ENODEV;
37645 }
37646@@ -1417,7 +1418,7 @@ static int hvcs_write_room(struct tty_struct *tty)
37647 {
37648 struct hvcs_struct *hvcsd = tty->driver_data;
37649
37650- if (!hvcsd || hvcsd->port.count <= 0)
37651+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
37652 return 0;
37653
37654 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
37655diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
37656index f8b5fa0..4ba9f89 100644
37657--- a/drivers/tty/ipwireless/tty.c
37658+++ b/drivers/tty/ipwireless/tty.c
37659@@ -29,6 +29,7 @@
37660 #include <linux/tty_driver.h>
37661 #include <linux/tty_flip.h>
37662 #include <linux/uaccess.h>
37663+#include <asm/local.h>
37664
37665 #include "tty.h"
37666 #include "network.h"
37667@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37668 mutex_unlock(&tty->ipw_tty_mutex);
37669 return -ENODEV;
37670 }
37671- if (tty->port.count == 0)
37672+ if (atomic_read(&tty->port.count) == 0)
37673 tty->tx_bytes_queued = 0;
37674
37675- tty->port.count++;
37676+ atomic_inc(&tty->port.count);
37677
37678 tty->port.tty = linux_tty;
37679 linux_tty->driver_data = tty;
37680@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37681
37682 static void do_ipw_close(struct ipw_tty *tty)
37683 {
37684- tty->port.count--;
37685-
37686- if (tty->port.count == 0) {
37687+ if (atomic_dec_return(&tty->port.count) == 0) {
37688 struct tty_struct *linux_tty = tty->port.tty;
37689
37690 if (linux_tty != NULL) {
37691@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
37692 return;
37693
37694 mutex_lock(&tty->ipw_tty_mutex);
37695- if (tty->port.count == 0) {
37696+ if (atomic_read(&tty->port.count) == 0) {
37697 mutex_unlock(&tty->ipw_tty_mutex);
37698 return;
37699 }
37700@@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
37701 return;
37702 }
37703
37704- if (!tty->port.count) {
37705+ if (!atomic_read(&tty->port.count)) {
37706 mutex_unlock(&tty->ipw_tty_mutex);
37707 return;
37708 }
37709@@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
37710 return -ENODEV;
37711
37712 mutex_lock(&tty->ipw_tty_mutex);
37713- if (!tty->port.count) {
37714+ if (!atomic_read(&tty->port.count)) {
37715 mutex_unlock(&tty->ipw_tty_mutex);
37716 return -EINVAL;
37717 }
37718@@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
37719 if (!tty)
37720 return -ENODEV;
37721
37722- if (!tty->port.count)
37723+ if (!atomic_read(&tty->port.count))
37724 return -EINVAL;
37725
37726 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
37727@@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
37728 if (!tty)
37729 return 0;
37730
37731- if (!tty->port.count)
37732+ if (!atomic_read(&tty->port.count))
37733 return 0;
37734
37735 return tty->tx_bytes_queued;
37736@@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
37737 if (!tty)
37738 return -ENODEV;
37739
37740- if (!tty->port.count)
37741+ if (!atomic_read(&tty->port.count))
37742 return -EINVAL;
37743
37744 return get_control_lines(tty);
37745@@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
37746 if (!tty)
37747 return -ENODEV;
37748
37749- if (!tty->port.count)
37750+ if (!atomic_read(&tty->port.count))
37751 return -EINVAL;
37752
37753 return set_control_lines(tty, set, clear);
37754@@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
37755 if (!tty)
37756 return -ENODEV;
37757
37758- if (!tty->port.count)
37759+ if (!atomic_read(&tty->port.count))
37760 return -EINVAL;
37761
37762 /* FIXME: Exactly how is the tty object locked here .. */
37763@@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
37764 * are gone */
37765 mutex_lock(&ttyj->ipw_tty_mutex);
37766 }
37767- while (ttyj->port.count)
37768+ while (atomic_read(&ttyj->port.count))
37769 do_ipw_close(ttyj);
37770 ipwireless_disassociate_network_ttys(network,
37771 ttyj->channel_idx);
37772diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
37773index 324467d..504cc25 100644
37774--- a/drivers/tty/moxa.c
37775+++ b/drivers/tty/moxa.c
37776@@ -1172,7 +1172,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
37777 }
37778
37779 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
37780- ch->port.count++;
37781+ atomic_inc(&ch->port.count);
37782 tty->driver_data = ch;
37783 tty_port_tty_set(&ch->port, tty);
37784 mutex_lock(&ch->port.mutex);
37785diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
37786index c43b683..4dab83e 100644
37787--- a/drivers/tty/n_gsm.c
37788+++ b/drivers/tty/n_gsm.c
37789@@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
37790 kref_init(&dlci->ref);
37791 mutex_init(&dlci->mutex);
37792 dlci->fifo = &dlci->_fifo;
37793- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
37794+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
37795 kfree(dlci);
37796 return NULL;
37797 }
37798@@ -2895,7 +2895,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
37799 if (dlci == NULL)
37800 return -ENOMEM;
37801 port = &dlci->port;
37802- port->count++;
37803+ atomic_inc(&port->count);
37804 tty->driver_data = dlci;
37805 dlci_get(dlci);
37806 dlci_get(dlci->gsm->dlci[0]);
37807diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
37808index ee1c268..0e97caf 100644
37809--- a/drivers/tty/n_tty.c
37810+++ b/drivers/tty/n_tty.c
37811@@ -2123,6 +2123,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
37812 {
37813 *ops = tty_ldisc_N_TTY;
37814 ops->owner = NULL;
37815- ops->refcount = ops->flags = 0;
37816+ atomic_set(&ops->refcount, 0);
37817+ ops->flags = 0;
37818 }
37819 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
37820diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
37821index 5505ffc..7affff9 100644
37822--- a/drivers/tty/pty.c
37823+++ b/drivers/tty/pty.c
37824@@ -718,8 +718,10 @@ static void __init unix98_pty_init(void)
37825 panic("Couldn't register Unix98 pts driver");
37826
37827 /* Now create the /dev/ptmx special device */
37828+ pax_open_kernel();
37829 tty_default_fops(&ptmx_fops);
37830- ptmx_fops.open = ptmx_open;
37831+ *(void **)&ptmx_fops.open = ptmx_open;
37832+ pax_close_kernel();
37833
37834 cdev_init(&ptmx_cdev, &ptmx_fops);
37835 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
37836diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
37837index 777d5f9..56d67ca 100644
37838--- a/drivers/tty/rocket.c
37839+++ b/drivers/tty/rocket.c
37840@@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
37841 tty->driver_data = info;
37842 tty_port_tty_set(port, tty);
37843
37844- if (port->count++ == 0) {
37845+ if (atomic_inc_return(&port->count) == 1) {
37846 atomic_inc(&rp_num_ports_open);
37847
37848 #ifdef ROCKET_DEBUG_OPEN
37849@@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
37850 #endif
37851 }
37852 #ifdef ROCKET_DEBUG_OPEN
37853- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
37854+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
37855 #endif
37856
37857 /*
37858@@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
37859 spin_unlock_irqrestore(&info->port.lock, flags);
37860 return;
37861 }
37862- if (info->port.count)
37863+ if (atomic_read(&info->port.count))
37864 atomic_dec(&rp_num_ports_open);
37865 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
37866 spin_unlock_irqrestore(&info->port.lock, flags);
37867diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
37868index 2b42a01..32a2ed3 100644
37869--- a/drivers/tty/serial/kgdboc.c
37870+++ b/drivers/tty/serial/kgdboc.c
37871@@ -24,8 +24,9 @@
37872 #define MAX_CONFIG_LEN 40
37873
37874 static struct kgdb_io kgdboc_io_ops;
37875+static struct kgdb_io kgdboc_io_ops_console;
37876
37877-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
37878+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
37879 static int configured = -1;
37880
37881 static char config[MAX_CONFIG_LEN];
37882@@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
37883 kgdboc_unregister_kbd();
37884 if (configured == 1)
37885 kgdb_unregister_io_module(&kgdboc_io_ops);
37886+ else if (configured == 2)
37887+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
37888 }
37889
37890 static int configure_kgdboc(void)
37891@@ -157,13 +160,13 @@ static int configure_kgdboc(void)
37892 int err;
37893 char *cptr = config;
37894 struct console *cons;
37895+ int is_console = 0;
37896
37897 err = kgdboc_option_setup(config);
37898 if (err || !strlen(config) || isspace(config[0]))
37899 goto noconfig;
37900
37901 err = -ENODEV;
37902- kgdboc_io_ops.is_console = 0;
37903 kgdb_tty_driver = NULL;
37904
37905 kgdboc_use_kms = 0;
37906@@ -184,7 +187,7 @@ static int configure_kgdboc(void)
37907 int idx;
37908 if (cons->device && cons->device(cons, &idx) == p &&
37909 idx == tty_line) {
37910- kgdboc_io_ops.is_console = 1;
37911+ is_console = 1;
37912 break;
37913 }
37914 cons = cons->next;
37915@@ -194,12 +197,16 @@ static int configure_kgdboc(void)
37916 kgdb_tty_line = tty_line;
37917
37918 do_register:
37919- err = kgdb_register_io_module(&kgdboc_io_ops);
37920+ if (is_console) {
37921+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
37922+ configured = 2;
37923+ } else {
37924+ err = kgdb_register_io_module(&kgdboc_io_ops);
37925+ configured = 1;
37926+ }
37927 if (err)
37928 goto noconfig;
37929
37930- configured = 1;
37931-
37932 return 0;
37933
37934 noconfig:
37935@@ -213,7 +220,7 @@ noconfig:
37936 static int __init init_kgdboc(void)
37937 {
37938 /* Already configured? */
37939- if (configured == 1)
37940+ if (configured >= 1)
37941 return 0;
37942
37943 return configure_kgdboc();
37944@@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
37945 if (config[len - 1] == '\n')
37946 config[len - 1] = '\0';
37947
37948- if (configured == 1)
37949+ if (configured >= 1)
37950 cleanup_kgdboc();
37951
37952 /* Go and configure with the new params. */
37953@@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
37954 .post_exception = kgdboc_post_exp_handler,
37955 };
37956
37957+static struct kgdb_io kgdboc_io_ops_console = {
37958+ .name = "kgdboc",
37959+ .read_char = kgdboc_get_char,
37960+ .write_char = kgdboc_put_char,
37961+ .pre_exception = kgdboc_pre_exp_handler,
37962+ .post_exception = kgdboc_post_exp_handler,
37963+ .is_console = 1
37964+};
37965+
37966 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
37967 /* This is only available if kgdboc is a built in for early debugging */
37968 static int __init kgdboc_early_init(char *opt)
37969diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
37970index 246b823..9e0db76 100644
37971--- a/drivers/tty/serial/serial_core.c
37972+++ b/drivers/tty/serial/serial_core.c
37973@@ -1392,7 +1392,7 @@ static void uart_hangup(struct tty_struct *tty)
37974 uart_flush_buffer(tty);
37975 uart_shutdown(tty, state);
37976 spin_lock_irqsave(&port->lock, flags);
37977- port->count = 0;
37978+ atomic_set(&port->count, 0);
37979 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
37980 spin_unlock_irqrestore(&port->lock, flags);
37981 tty_port_tty_set(port, NULL);
37982@@ -1488,7 +1488,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
37983 goto end;
37984 }
37985
37986- port->count++;
37987+ atomic_inc(&port->count);
37988 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
37989 retval = -ENXIO;
37990 goto err_dec_count;
37991@@ -1515,7 +1515,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
37992 /*
37993 * Make sure the device is in D0 state.
37994 */
37995- if (port->count == 1)
37996+ if (atomic_read(&port->count) == 1)
37997 uart_change_pm(state, 0);
37998
37999 /*
38000@@ -1533,7 +1533,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38001 end:
38002 return retval;
38003 err_dec_count:
38004- port->count--;
38005+ atomic_inc(&port->count);
38006 mutex_unlock(&port->mutex);
38007 goto end;
38008 }
38009diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
38010index 593d40a..bdc61f3 100644
38011--- a/drivers/tty/synclink.c
38012+++ b/drivers/tty/synclink.c
38013@@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38014
38015 if (debug_level >= DEBUG_LEVEL_INFO)
38016 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
38017- __FILE__,__LINE__, info->device_name, info->port.count);
38018+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38019
38020 if (tty_port_close_start(&info->port, tty, filp) == 0)
38021 goto cleanup;
38022@@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38023 cleanup:
38024 if (debug_level >= DEBUG_LEVEL_INFO)
38025 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
38026- tty->driver->name, info->port.count);
38027+ tty->driver->name, atomic_read(&info->port.count));
38028
38029 } /* end of mgsl_close() */
38030
38031@@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
38032
38033 mgsl_flush_buffer(tty);
38034 shutdown(info);
38035-
38036- info->port.count = 0;
38037+
38038+ atomic_set(&info->port.count, 0);
38039 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38040 info->port.tty = NULL;
38041
38042@@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38043
38044 if (debug_level >= DEBUG_LEVEL_INFO)
38045 printk("%s(%d):block_til_ready before block on %s count=%d\n",
38046- __FILE__,__LINE__, tty->driver->name, port->count );
38047+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38048
38049 spin_lock_irqsave(&info->irq_spinlock, flags);
38050 if (!tty_hung_up_p(filp)) {
38051 extra_count = true;
38052- port->count--;
38053+ atomic_dec(&port->count);
38054 }
38055 spin_unlock_irqrestore(&info->irq_spinlock, flags);
38056 port->blocked_open++;
38057@@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38058
38059 if (debug_level >= DEBUG_LEVEL_INFO)
38060 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
38061- __FILE__,__LINE__, tty->driver->name, port->count );
38062+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38063
38064 tty_unlock();
38065 schedule();
38066@@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38067
38068 /* FIXME: Racy on hangup during close wait */
38069 if (extra_count)
38070- port->count++;
38071+ atomic_inc(&port->count);
38072 port->blocked_open--;
38073
38074 if (debug_level >= DEBUG_LEVEL_INFO)
38075 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
38076- __FILE__,__LINE__, tty->driver->name, port->count );
38077+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38078
38079 if (!retval)
38080 port->flags |= ASYNC_NORMAL_ACTIVE;
38081@@ -3398,7 +3398,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38082
38083 if (debug_level >= DEBUG_LEVEL_INFO)
38084 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
38085- __FILE__,__LINE__,tty->driver->name, info->port.count);
38086+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38087
38088 /* If port is closing, signal caller to try again */
38089 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38090@@ -3417,10 +3417,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38091 spin_unlock_irqrestore(&info->netlock, flags);
38092 goto cleanup;
38093 }
38094- info->port.count++;
38095+ atomic_inc(&info->port.count);
38096 spin_unlock_irqrestore(&info->netlock, flags);
38097
38098- if (info->port.count == 1) {
38099+ if (atomic_read(&info->port.count) == 1) {
38100 /* 1st open on this device, init hardware */
38101 retval = startup(info);
38102 if (retval < 0)
38103@@ -3444,8 +3444,8 @@ cleanup:
38104 if (retval) {
38105 if (tty->count == 1)
38106 info->port.tty = NULL; /* tty layer will release tty struct */
38107- if(info->port.count)
38108- info->port.count--;
38109+ if (atomic_read(&info->port.count))
38110+ atomic_dec(&info->port.count);
38111 }
38112
38113 return retval;
38114@@ -7653,7 +7653,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38115 unsigned short new_crctype;
38116
38117 /* return error if TTY interface open */
38118- if (info->port.count)
38119+ if (atomic_read(&info->port.count))
38120 return -EBUSY;
38121
38122 switch (encoding)
38123@@ -7748,7 +7748,7 @@ static int hdlcdev_open(struct net_device *dev)
38124
38125 /* arbitrate between network and tty opens */
38126 spin_lock_irqsave(&info->netlock, flags);
38127- if (info->port.count != 0 || info->netcount != 0) {
38128+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38129 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38130 spin_unlock_irqrestore(&info->netlock, flags);
38131 return -EBUSY;
38132@@ -7834,7 +7834,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38133 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38134
38135 /* return error if TTY interface open */
38136- if (info->port.count)
38137+ if (atomic_read(&info->port.count))
38138 return -EBUSY;
38139
38140 if (cmd != SIOCWANDEV)
38141diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
38142index aa1debf..9297a16 100644
38143--- a/drivers/tty/synclink_gt.c
38144+++ b/drivers/tty/synclink_gt.c
38145@@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38146 tty->driver_data = info;
38147 info->port.tty = tty;
38148
38149- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
38150+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
38151
38152 /* If port is closing, signal caller to try again */
38153 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38154@@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38155 mutex_unlock(&info->port.mutex);
38156 goto cleanup;
38157 }
38158- info->port.count++;
38159+ atomic_inc(&info->port.count);
38160 spin_unlock_irqrestore(&info->netlock, flags);
38161
38162- if (info->port.count == 1) {
38163+ if (atomic_read(&info->port.count) == 1) {
38164 /* 1st open on this device, init hardware */
38165 retval = startup(info);
38166 if (retval < 0) {
38167@@ -716,8 +716,8 @@ cleanup:
38168 if (retval) {
38169 if (tty->count == 1)
38170 info->port.tty = NULL; /* tty layer will release tty struct */
38171- if(info->port.count)
38172- info->port.count--;
38173+ if(atomic_read(&info->port.count))
38174+ atomic_dec(&info->port.count);
38175 }
38176
38177 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
38178@@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38179
38180 if (sanity_check(info, tty->name, "close"))
38181 return;
38182- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
38183+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
38184
38185 if (tty_port_close_start(&info->port, tty, filp) == 0)
38186 goto cleanup;
38187@@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38188 tty_port_close_end(&info->port, tty);
38189 info->port.tty = NULL;
38190 cleanup:
38191- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
38192+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
38193 }
38194
38195 static void hangup(struct tty_struct *tty)
38196@@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
38197 shutdown(info);
38198
38199 spin_lock_irqsave(&info->port.lock, flags);
38200- info->port.count = 0;
38201+ atomic_set(&info->port.count, 0);
38202 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38203 info->port.tty = NULL;
38204 spin_unlock_irqrestore(&info->port.lock, flags);
38205@@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38206 unsigned short new_crctype;
38207
38208 /* return error if TTY interface open */
38209- if (info->port.count)
38210+ if (atomic_read(&info->port.count))
38211 return -EBUSY;
38212
38213 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
38214@@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
38215
38216 /* arbitrate between network and tty opens */
38217 spin_lock_irqsave(&info->netlock, flags);
38218- if (info->port.count != 0 || info->netcount != 0) {
38219+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38220 DBGINFO(("%s hdlc_open busy\n", dev->name));
38221 spin_unlock_irqrestore(&info->netlock, flags);
38222 return -EBUSY;
38223@@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38224 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
38225
38226 /* return error if TTY interface open */
38227- if (info->port.count)
38228+ if (atomic_read(&info->port.count))
38229 return -EBUSY;
38230
38231 if (cmd != SIOCWANDEV)
38232@@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
38233 if (port == NULL)
38234 continue;
38235 spin_lock(&port->lock);
38236- if ((port->port.count || port->netcount) &&
38237+ if ((atomic_read(&port->port.count) || port->netcount) &&
38238 port->pending_bh && !port->bh_running &&
38239 !port->bh_requested) {
38240 DBGISR(("%s bh queued\n", port->device_name));
38241@@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38242 spin_lock_irqsave(&info->lock, flags);
38243 if (!tty_hung_up_p(filp)) {
38244 extra_count = true;
38245- port->count--;
38246+ atomic_dec(&port->count);
38247 }
38248 spin_unlock_irqrestore(&info->lock, flags);
38249 port->blocked_open++;
38250@@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38251 remove_wait_queue(&port->open_wait, &wait);
38252
38253 if (extra_count)
38254- port->count++;
38255+ atomic_inc(&port->count);
38256 port->blocked_open--;
38257
38258 if (!retval)
38259diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
38260index a3dddc1..8905ab2 100644
38261--- a/drivers/tty/synclinkmp.c
38262+++ b/drivers/tty/synclinkmp.c
38263@@ -742,7 +742,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38264
38265 if (debug_level >= DEBUG_LEVEL_INFO)
38266 printk("%s(%d):%s open(), old ref count = %d\n",
38267- __FILE__,__LINE__,tty->driver->name, info->port.count);
38268+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38269
38270 /* If port is closing, signal caller to try again */
38271 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38272@@ -761,10 +761,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38273 spin_unlock_irqrestore(&info->netlock, flags);
38274 goto cleanup;
38275 }
38276- info->port.count++;
38277+ atomic_inc(&info->port.count);
38278 spin_unlock_irqrestore(&info->netlock, flags);
38279
38280- if (info->port.count == 1) {
38281+ if (atomic_read(&info->port.count) == 1) {
38282 /* 1st open on this device, init hardware */
38283 retval = startup(info);
38284 if (retval < 0)
38285@@ -788,8 +788,8 @@ cleanup:
38286 if (retval) {
38287 if (tty->count == 1)
38288 info->port.tty = NULL; /* tty layer will release tty struct */
38289- if(info->port.count)
38290- info->port.count--;
38291+ if(atomic_read(&info->port.count))
38292+ atomic_dec(&info->port.count);
38293 }
38294
38295 return retval;
38296@@ -807,7 +807,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38297
38298 if (debug_level >= DEBUG_LEVEL_INFO)
38299 printk("%s(%d):%s close() entry, count=%d\n",
38300- __FILE__,__LINE__, info->device_name, info->port.count);
38301+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38302
38303 if (tty_port_close_start(&info->port, tty, filp) == 0)
38304 goto cleanup;
38305@@ -826,7 +826,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38306 cleanup:
38307 if (debug_level >= DEBUG_LEVEL_INFO)
38308 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
38309- tty->driver->name, info->port.count);
38310+ tty->driver->name, atomic_read(&info->port.count));
38311 }
38312
38313 /* Called by tty_hangup() when a hangup is signaled.
38314@@ -849,7 +849,7 @@ static void hangup(struct tty_struct *tty)
38315 shutdown(info);
38316
38317 spin_lock_irqsave(&info->port.lock, flags);
38318- info->port.count = 0;
38319+ atomic_set(&info->port.count, 0);
38320 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38321 info->port.tty = NULL;
38322 spin_unlock_irqrestore(&info->port.lock, flags);
38323@@ -1557,7 +1557,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38324 unsigned short new_crctype;
38325
38326 /* return error if TTY interface open */
38327- if (info->port.count)
38328+ if (atomic_read(&info->port.count))
38329 return -EBUSY;
38330
38331 switch (encoding)
38332@@ -1652,7 +1652,7 @@ static int hdlcdev_open(struct net_device *dev)
38333
38334 /* arbitrate between network and tty opens */
38335 spin_lock_irqsave(&info->netlock, flags);
38336- if (info->port.count != 0 || info->netcount != 0) {
38337+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38338 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38339 spin_unlock_irqrestore(&info->netlock, flags);
38340 return -EBUSY;
38341@@ -1738,7 +1738,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38342 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38343
38344 /* return error if TTY interface open */
38345- if (info->port.count)
38346+ if (atomic_read(&info->port.count))
38347 return -EBUSY;
38348
38349 if (cmd != SIOCWANDEV)
38350@@ -2623,7 +2623,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
38351 * do not request bottom half processing if the
38352 * device is not open in a normal mode.
38353 */
38354- if ( port && (port->port.count || port->netcount) &&
38355+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
38356 port->pending_bh && !port->bh_running &&
38357 !port->bh_requested ) {
38358 if ( debug_level >= DEBUG_LEVEL_ISR )
38359@@ -3321,12 +3321,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38360
38361 if (debug_level >= DEBUG_LEVEL_INFO)
38362 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
38363- __FILE__,__LINE__, tty->driver->name, port->count );
38364+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38365
38366 spin_lock_irqsave(&info->lock, flags);
38367 if (!tty_hung_up_p(filp)) {
38368 extra_count = true;
38369- port->count--;
38370+ atomic_dec(&port->count);
38371 }
38372 spin_unlock_irqrestore(&info->lock, flags);
38373 port->blocked_open++;
38374@@ -3355,7 +3355,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38375
38376 if (debug_level >= DEBUG_LEVEL_INFO)
38377 printk("%s(%d):%s block_til_ready() count=%d\n",
38378- __FILE__,__LINE__, tty->driver->name, port->count );
38379+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38380
38381 tty_unlock();
38382 schedule();
38383@@ -3366,12 +3366,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38384 remove_wait_queue(&port->open_wait, &wait);
38385
38386 if (extra_count)
38387- port->count++;
38388+ atomic_inc(&port->count);
38389 port->blocked_open--;
38390
38391 if (debug_level >= DEBUG_LEVEL_INFO)
38392 printk("%s(%d):%s block_til_ready() after, count=%d\n",
38393- __FILE__,__LINE__, tty->driver->name, port->count );
38394+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38395
38396 if (!retval)
38397 port->flags |= ASYNC_NORMAL_ACTIVE;
38398diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38399index 05728894..b9d44c6 100644
38400--- a/drivers/tty/sysrq.c
38401+++ b/drivers/tty/sysrq.c
38402@@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38403 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38404 size_t count, loff_t *ppos)
38405 {
38406- if (count) {
38407+ if (count && capable(CAP_SYS_ADMIN)) {
38408 char c;
38409
38410 if (get_user(c, buf))
38411diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38412index b425c79..08a3f06 100644
38413--- a/drivers/tty/tty_io.c
38414+++ b/drivers/tty/tty_io.c
38415@@ -3283,7 +3283,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38416
38417 void tty_default_fops(struct file_operations *fops)
38418 {
38419- *fops = tty_fops;
38420+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38421 }
38422
38423 /*
38424diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38425index 9911eb6..5abe0e1 100644
38426--- a/drivers/tty/tty_ldisc.c
38427+++ b/drivers/tty/tty_ldisc.c
38428@@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38429 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38430 struct tty_ldisc_ops *ldo = ld->ops;
38431
38432- ldo->refcount--;
38433+ atomic_dec(&ldo->refcount);
38434 module_put(ldo->owner);
38435 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38436
38437@@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38438 spin_lock_irqsave(&tty_ldisc_lock, flags);
38439 tty_ldiscs[disc] = new_ldisc;
38440 new_ldisc->num = disc;
38441- new_ldisc->refcount = 0;
38442+ atomic_set(&new_ldisc->refcount, 0);
38443 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38444
38445 return ret;
38446@@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
38447 return -EINVAL;
38448
38449 spin_lock_irqsave(&tty_ldisc_lock, flags);
38450- if (tty_ldiscs[disc]->refcount)
38451+ if (atomic_read(&tty_ldiscs[disc]->refcount))
38452 ret = -EBUSY;
38453 else
38454 tty_ldiscs[disc] = NULL;
38455@@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38456 if (ldops) {
38457 ret = ERR_PTR(-EAGAIN);
38458 if (try_module_get(ldops->owner)) {
38459- ldops->refcount++;
38460+ atomic_inc(&ldops->refcount);
38461 ret = ldops;
38462 }
38463 }
38464@@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38465 unsigned long flags;
38466
38467 spin_lock_irqsave(&tty_ldisc_lock, flags);
38468- ldops->refcount--;
38469+ atomic_dec(&ldops->refcount);
38470 module_put(ldops->owner);
38471 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38472 }
38473diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
38474index bf6e238..d401c04 100644
38475--- a/drivers/tty/tty_port.c
38476+++ b/drivers/tty/tty_port.c
38477@@ -138,7 +138,7 @@ void tty_port_hangup(struct tty_port *port)
38478 unsigned long flags;
38479
38480 spin_lock_irqsave(&port->lock, flags);
38481- port->count = 0;
38482+ atomic_set(&port->count, 0);
38483 port->flags &= ~ASYNC_NORMAL_ACTIVE;
38484 if (port->tty) {
38485 set_bit(TTY_IO_ERROR, &port->tty->flags);
38486@@ -264,7 +264,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38487 /* The port lock protects the port counts */
38488 spin_lock_irqsave(&port->lock, flags);
38489 if (!tty_hung_up_p(filp))
38490- port->count--;
38491+ atomic_dec(&port->count);
38492 port->blocked_open++;
38493 spin_unlock_irqrestore(&port->lock, flags);
38494
38495@@ -306,7 +306,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38496 we must not mess that up further */
38497 spin_lock_irqsave(&port->lock, flags);
38498 if (!tty_hung_up_p(filp))
38499- port->count++;
38500+ atomic_inc(&port->count);
38501 port->blocked_open--;
38502 if (retval == 0)
38503 port->flags |= ASYNC_NORMAL_ACTIVE;
38504@@ -326,19 +326,19 @@ int tty_port_close_start(struct tty_port *port,
38505 return 0;
38506 }
38507
38508- if (tty->count == 1 && port->count != 1) {
38509+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
38510 printk(KERN_WARNING
38511 "tty_port_close_start: tty->count = 1 port count = %d.\n",
38512- port->count);
38513- port->count = 1;
38514+ atomic_read(&port->count));
38515+ atomic_set(&port->count, 1);
38516 }
38517- if (--port->count < 0) {
38518+ if (atomic_dec_return(&port->count) < 0) {
38519 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
38520- port->count);
38521- port->count = 0;
38522+ atomic_read(&port->count));
38523+ atomic_set(&port->count, 0);
38524 }
38525
38526- if (port->count) {
38527+ if (atomic_read(&port->count)) {
38528 spin_unlock_irqrestore(&port->lock, flags);
38529 if (port->ops->drop)
38530 port->ops->drop(port);
38531@@ -418,7 +418,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
38532 {
38533 spin_lock_irq(&port->lock);
38534 if (!tty_hung_up_p(filp))
38535- ++port->count;
38536+ atomic_inc(&port->count);
38537 spin_unlock_irq(&port->lock);
38538 tty_port_tty_set(port, tty);
38539
38540diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
38541index 48cc6f2..85584dd 100644
38542--- a/drivers/tty/vt/keyboard.c
38543+++ b/drivers/tty/vt/keyboard.c
38544@@ -659,6 +659,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
38545 kbd->kbdmode == VC_OFF) &&
38546 value != KVAL(K_SAK))
38547 return; /* SAK is allowed even in raw mode */
38548+
38549+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
38550+ {
38551+ void *func = fn_handler[value];
38552+ if (func == fn_show_state || func == fn_show_ptregs ||
38553+ func == fn_show_mem)
38554+ return;
38555+ }
38556+#endif
38557+
38558 fn_handler[value](vc);
38559 }
38560
38561@@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38562 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
38563 return -EFAULT;
38564
38565- if (!capable(CAP_SYS_TTY_CONFIG))
38566- perm = 0;
38567-
38568 switch (cmd) {
38569 case KDGKBENT:
38570 /* Ensure another thread doesn't free it under us */
38571@@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38572 spin_unlock_irqrestore(&kbd_event_lock, flags);
38573 return put_user(val, &user_kbe->kb_value);
38574 case KDSKBENT:
38575+ if (!capable(CAP_SYS_TTY_CONFIG))
38576+ perm = 0;
38577+
38578 if (!perm)
38579 return -EPERM;
38580 if (!i && v == K_NOSUCHMAP) {
38581@@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38582 int i, j, k;
38583 int ret;
38584
38585- if (!capable(CAP_SYS_TTY_CONFIG))
38586- perm = 0;
38587-
38588 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
38589 if (!kbs) {
38590 ret = -ENOMEM;
38591@@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38592 kfree(kbs);
38593 return ((p && *p) ? -EOVERFLOW : 0);
38594 case KDSKBSENT:
38595+ if (!capable(CAP_SYS_TTY_CONFIG))
38596+ perm = 0;
38597+
38598 if (!perm) {
38599 ret = -EPERM;
38600 goto reterr;
38601diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
38602index a783d53..cb30d94 100644
38603--- a/drivers/uio/uio.c
38604+++ b/drivers/uio/uio.c
38605@@ -25,6 +25,7 @@
38606 #include <linux/kobject.h>
38607 #include <linux/cdev.h>
38608 #include <linux/uio_driver.h>
38609+#include <asm/local.h>
38610
38611 #define UIO_MAX_DEVICES (1U << MINORBITS)
38612
38613@@ -32,10 +33,10 @@ struct uio_device {
38614 struct module *owner;
38615 struct device *dev;
38616 int minor;
38617- atomic_t event;
38618+ atomic_unchecked_t event;
38619 struct fasync_struct *async_queue;
38620 wait_queue_head_t wait;
38621- int vma_count;
38622+ local_t vma_count;
38623 struct uio_info *info;
38624 struct kobject *map_dir;
38625 struct kobject *portio_dir;
38626@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
38627 struct device_attribute *attr, char *buf)
38628 {
38629 struct uio_device *idev = dev_get_drvdata(dev);
38630- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
38631+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
38632 }
38633
38634 static struct device_attribute uio_class_attributes[] = {
38635@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
38636 {
38637 struct uio_device *idev = info->uio_dev;
38638
38639- atomic_inc(&idev->event);
38640+ atomic_inc_unchecked(&idev->event);
38641 wake_up_interruptible(&idev->wait);
38642 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
38643 }
38644@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
38645 }
38646
38647 listener->dev = idev;
38648- listener->event_count = atomic_read(&idev->event);
38649+ listener->event_count = atomic_read_unchecked(&idev->event);
38650 filep->private_data = listener;
38651
38652 if (idev->info->open) {
38653@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
38654 return -EIO;
38655
38656 poll_wait(filep, &idev->wait, wait);
38657- if (listener->event_count != atomic_read(&idev->event))
38658+ if (listener->event_count != atomic_read_unchecked(&idev->event))
38659 return POLLIN | POLLRDNORM;
38660 return 0;
38661 }
38662@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
38663 do {
38664 set_current_state(TASK_INTERRUPTIBLE);
38665
38666- event_count = atomic_read(&idev->event);
38667+ event_count = atomic_read_unchecked(&idev->event);
38668 if (event_count != listener->event_count) {
38669 if (copy_to_user(buf, &event_count, count))
38670 retval = -EFAULT;
38671@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
38672 static void uio_vma_open(struct vm_area_struct *vma)
38673 {
38674 struct uio_device *idev = vma->vm_private_data;
38675- idev->vma_count++;
38676+ local_inc(&idev->vma_count);
38677 }
38678
38679 static void uio_vma_close(struct vm_area_struct *vma)
38680 {
38681 struct uio_device *idev = vma->vm_private_data;
38682- idev->vma_count--;
38683+ local_dec(&idev->vma_count);
38684 }
38685
38686 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38687@@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
38688 idev->owner = owner;
38689 idev->info = info;
38690 init_waitqueue_head(&idev->wait);
38691- atomic_set(&idev->event, 0);
38692+ atomic_set_unchecked(&idev->event, 0);
38693
38694 ret = uio_get_minor(idev);
38695 if (ret)
38696diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
38697index b7eb86a..36d28af 100644
38698--- a/drivers/usb/atm/cxacru.c
38699+++ b/drivers/usb/atm/cxacru.c
38700@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
38701 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
38702 if (ret < 2)
38703 return -EINVAL;
38704- if (index < 0 || index > 0x7f)
38705+ if (index > 0x7f)
38706 return -EINVAL;
38707 pos += tmp;
38708
38709diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
38710index ee62b35..b663594 100644
38711--- a/drivers/usb/atm/usbatm.c
38712+++ b/drivers/usb/atm/usbatm.c
38713@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38714 if (printk_ratelimit())
38715 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
38716 __func__, vpi, vci);
38717- atomic_inc(&vcc->stats->rx_err);
38718+ atomic_inc_unchecked(&vcc->stats->rx_err);
38719 return;
38720 }
38721
38722@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38723 if (length > ATM_MAX_AAL5_PDU) {
38724 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
38725 __func__, length, vcc);
38726- atomic_inc(&vcc->stats->rx_err);
38727+ atomic_inc_unchecked(&vcc->stats->rx_err);
38728 goto out;
38729 }
38730
38731@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38732 if (sarb->len < pdu_length) {
38733 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
38734 __func__, pdu_length, sarb->len, vcc);
38735- atomic_inc(&vcc->stats->rx_err);
38736+ atomic_inc_unchecked(&vcc->stats->rx_err);
38737 goto out;
38738 }
38739
38740 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
38741 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
38742 __func__, vcc);
38743- atomic_inc(&vcc->stats->rx_err);
38744+ atomic_inc_unchecked(&vcc->stats->rx_err);
38745 goto out;
38746 }
38747
38748@@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38749 if (printk_ratelimit())
38750 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
38751 __func__, length);
38752- atomic_inc(&vcc->stats->rx_drop);
38753+ atomic_inc_unchecked(&vcc->stats->rx_drop);
38754 goto out;
38755 }
38756
38757@@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38758
38759 vcc->push(vcc, skb);
38760
38761- atomic_inc(&vcc->stats->rx);
38762+ atomic_inc_unchecked(&vcc->stats->rx);
38763 out:
38764 skb_trim(sarb, 0);
38765 }
38766@@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
38767 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
38768
38769 usbatm_pop(vcc, skb);
38770- atomic_inc(&vcc->stats->tx);
38771+ atomic_inc_unchecked(&vcc->stats->tx);
38772
38773 skb = skb_dequeue(&instance->sndqueue);
38774 }
38775@@ -770,11 +770,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
38776 if (!left--)
38777 return sprintf(page,
38778 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
38779- atomic_read(&atm_dev->stats.aal5.tx),
38780- atomic_read(&atm_dev->stats.aal5.tx_err),
38781- atomic_read(&atm_dev->stats.aal5.rx),
38782- atomic_read(&atm_dev->stats.aal5.rx_err),
38783- atomic_read(&atm_dev->stats.aal5.rx_drop));
38784+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
38785+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
38786+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
38787+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
38788+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
38789
38790 if (!left--) {
38791 if (instance->disconnected)
38792diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
38793index d956965..4179a77 100644
38794--- a/drivers/usb/core/devices.c
38795+++ b/drivers/usb/core/devices.c
38796@@ -126,7 +126,7 @@ static const char format_endpt[] =
38797 * time it gets called.
38798 */
38799 static struct device_connect_event {
38800- atomic_t count;
38801+ atomic_unchecked_t count;
38802 wait_queue_head_t wait;
38803 } device_event = {
38804 .count = ATOMIC_INIT(1),
38805@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
38806
38807 void usbfs_conn_disc_event(void)
38808 {
38809- atomic_add(2, &device_event.count);
38810+ atomic_add_unchecked(2, &device_event.count);
38811 wake_up(&device_event.wait);
38812 }
38813
38814@@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
38815
38816 poll_wait(file, &device_event.wait, wait);
38817
38818- event_count = atomic_read(&device_event.count);
38819+ event_count = atomic_read_unchecked(&device_event.count);
38820 if (file->f_version != event_count) {
38821 file->f_version = event_count;
38822 return POLLIN | POLLRDNORM;
38823diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
38824index 347bb05..63e1b73 100644
38825--- a/drivers/usb/early/ehci-dbgp.c
38826+++ b/drivers/usb/early/ehci-dbgp.c
38827@@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
38828
38829 #ifdef CONFIG_KGDB
38830 static struct kgdb_io kgdbdbgp_io_ops;
38831-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
38832+static struct kgdb_io kgdbdbgp_io_ops_console;
38833+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
38834 #else
38835 #define dbgp_kgdb_mode (0)
38836 #endif
38837@@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
38838 .write_char = kgdbdbgp_write_char,
38839 };
38840
38841+static struct kgdb_io kgdbdbgp_io_ops_console = {
38842+ .name = "kgdbdbgp",
38843+ .read_char = kgdbdbgp_read_char,
38844+ .write_char = kgdbdbgp_write_char,
38845+ .is_console = 1
38846+};
38847+
38848 static int kgdbdbgp_wait_time;
38849
38850 static int __init kgdbdbgp_parse_config(char *str)
38851@@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
38852 ptr++;
38853 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
38854 }
38855- kgdb_register_io_module(&kgdbdbgp_io_ops);
38856- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
38857+ if (early_dbgp_console.index != -1)
38858+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
38859+ else
38860+ kgdb_register_io_module(&kgdbdbgp_io_ops);
38861
38862 return 0;
38863 }
38864diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
38865index 5b3f5ff..6e00893 100644
38866--- a/drivers/usb/gadget/u_serial.c
38867+++ b/drivers/usb/gadget/u_serial.c
38868@@ -731,9 +731,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
38869 spin_lock_irq(&port->port_lock);
38870
38871 /* already open? Great. */
38872- if (port->port.count) {
38873+ if (atomic_read(&port->port.count)) {
38874 status = 0;
38875- port->port.count++;
38876+ atomic_inc(&port->port.count);
38877
38878 /* currently opening/closing? wait ... */
38879 } else if (port->openclose) {
38880@@ -792,7 +792,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
38881 tty->driver_data = port;
38882 port->port.tty = tty;
38883
38884- port->port.count = 1;
38885+ atomic_set(&port->port.count, 1);
38886 port->openclose = false;
38887
38888 /* if connected, start the I/O stream */
38889@@ -834,11 +834,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
38890
38891 spin_lock_irq(&port->port_lock);
38892
38893- if (port->port.count != 1) {
38894- if (port->port.count == 0)
38895+ if (atomic_read(&port->port.count) != 1) {
38896+ if (atomic_read(&port->port.count) == 0)
38897 WARN_ON(1);
38898 else
38899- --port->port.count;
38900+ atomic_dec(&port->port.count);
38901 goto exit;
38902 }
38903
38904@@ -848,7 +848,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
38905 * and sleep if necessary
38906 */
38907 port->openclose = true;
38908- port->port.count = 0;
38909+ atomic_set(&port->port.count, 0);
38910
38911 gser = port->port_usb;
38912 if (gser && gser->disconnect)
38913@@ -1152,7 +1152,7 @@ static int gs_closed(struct gs_port *port)
38914 int cond;
38915
38916 spin_lock_irq(&port->port_lock);
38917- cond = (port->port.count == 0) && !port->openclose;
38918+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
38919 spin_unlock_irq(&port->port_lock);
38920 return cond;
38921 }
38922@@ -1265,7 +1265,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
38923 /* if it's already open, start I/O ... and notify the serial
38924 * protocol about open/close status (connect/disconnect).
38925 */
38926- if (port->port.count) {
38927+ if (atomic_read(&port->port.count)) {
38928 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
38929 gs_start_io(port);
38930 if (gser->connect)
38931@@ -1312,7 +1312,7 @@ void gserial_disconnect(struct gserial *gser)
38932
38933 port->port_usb = NULL;
38934 gser->ioport = NULL;
38935- if (port->port.count > 0 || port->openclose) {
38936+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
38937 wake_up_interruptible(&port->drain_wait);
38938 if (port->port.tty)
38939 tty_hangup(port->port.tty);
38940@@ -1328,7 +1328,7 @@ void gserial_disconnect(struct gserial *gser)
38941
38942 /* finally, free any unused/unusable I/O buffers */
38943 spin_lock_irqsave(&port->port_lock, flags);
38944- if (port->port.count == 0 && !port->openclose)
38945+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
38946 gs_buf_free(&port->port_write_buf);
38947 gs_free_requests(gser->out, &port->read_pool, NULL);
38948 gs_free_requests(gser->out, &port->read_queue, NULL);
38949diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
38950index b9cca6d..75c75df 100644
38951--- a/drivers/usb/serial/console.c
38952+++ b/drivers/usb/serial/console.c
38953@@ -127,7 +127,7 @@ static int usb_console_setup(struct console *co, char *options)
38954
38955 info->port = port;
38956
38957- ++port->port.count;
38958+ atomic_inc(&port->port.count);
38959 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
38960 if (serial->type->set_termios) {
38961 /*
38962@@ -177,7 +177,7 @@ static int usb_console_setup(struct console *co, char *options)
38963 }
38964 /* Now that any required fake tty operations are completed restore
38965 * the tty port count */
38966- --port->port.count;
38967+ atomic_dec(&port->port.count);
38968 /* The console is special in terms of closing the device so
38969 * indicate this port is now acting as a system console. */
38970 port->port.console = 1;
38971@@ -190,7 +190,7 @@ static int usb_console_setup(struct console *co, char *options)
38972 free_tty:
38973 kfree(tty);
38974 reset_open_count:
38975- port->port.count = 0;
38976+ atomic_set(&port->port.count, 0);
38977 usb_autopm_put_interface(serial->interface);
38978 error_get_interface:
38979 usb_serial_put(serial);
38980diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
38981index d6bea3e..60b250e 100644
38982--- a/drivers/usb/wusbcore/wa-hc.h
38983+++ b/drivers/usb/wusbcore/wa-hc.h
38984@@ -192,7 +192,7 @@ struct wahc {
38985 struct list_head xfer_delayed_list;
38986 spinlock_t xfer_list_lock;
38987 struct work_struct xfer_work;
38988- atomic_t xfer_id_count;
38989+ atomic_unchecked_t xfer_id_count;
38990 };
38991
38992
38993@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
38994 INIT_LIST_HEAD(&wa->xfer_delayed_list);
38995 spin_lock_init(&wa->xfer_list_lock);
38996 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
38997- atomic_set(&wa->xfer_id_count, 1);
38998+ atomic_set_unchecked(&wa->xfer_id_count, 1);
38999 }
39000
39001 /**
39002diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
39003index 57c01ab..8a05959 100644
39004--- a/drivers/usb/wusbcore/wa-xfer.c
39005+++ b/drivers/usb/wusbcore/wa-xfer.c
39006@@ -296,7 +296,7 @@ out:
39007 */
39008 static void wa_xfer_id_init(struct wa_xfer *xfer)
39009 {
39010- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
39011+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
39012 }
39013
39014 /*
39015diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
39016index 112156f..eb81154 100644
39017--- a/drivers/vhost/vhost.c
39018+++ b/drivers/vhost/vhost.c
39019@@ -635,7 +635,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
39020 return 0;
39021 }
39022
39023-static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
39024+static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
39025 {
39026 struct file *eventfp, *filep = NULL,
39027 *pollstart = NULL, *pollstop = NULL;
39028diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
39029index b0b2ac3..89a4399 100644
39030--- a/drivers/video/aty/aty128fb.c
39031+++ b/drivers/video/aty/aty128fb.c
39032@@ -148,7 +148,7 @@ enum {
39033 };
39034
39035 /* Must match above enum */
39036-static const char *r128_family[] __devinitdata = {
39037+static const char *r128_family[] __devinitconst = {
39038 "AGP",
39039 "PCI",
39040 "PRO AGP",
39041diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
39042index 5c3960d..15cf8fc 100644
39043--- a/drivers/video/fbcmap.c
39044+++ b/drivers/video/fbcmap.c
39045@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
39046 rc = -ENODEV;
39047 goto out;
39048 }
39049- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
39050- !info->fbops->fb_setcmap)) {
39051+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
39052 rc = -EINVAL;
39053 goto out1;
39054 }
39055diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
39056index 0dff12a..2ef47b3 100644
39057--- a/drivers/video/fbmem.c
39058+++ b/drivers/video/fbmem.c
39059@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39060 image->dx += image->width + 8;
39061 }
39062 } else if (rotate == FB_ROTATE_UD) {
39063- for (x = 0; x < num && image->dx >= 0; x++) {
39064+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
39065 info->fbops->fb_imageblit(info, image);
39066 image->dx -= image->width + 8;
39067 }
39068@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39069 image->dy += image->height + 8;
39070 }
39071 } else if (rotate == FB_ROTATE_CCW) {
39072- for (x = 0; x < num && image->dy >= 0; x++) {
39073+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39074 info->fbops->fb_imageblit(info, image);
39075 image->dy -= image->height + 8;
39076 }
39077@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
39078 return -EFAULT;
39079 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39080 return -EINVAL;
39081- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39082+ if (con2fb.framebuffer >= FB_MAX)
39083 return -EINVAL;
39084 if (!registered_fb[con2fb.framebuffer])
39085 request_module("fb%d", con2fb.framebuffer);
39086diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
39087index 5a5d092..265c5ed 100644
39088--- a/drivers/video/geode/gx1fb_core.c
39089+++ b/drivers/video/geode/gx1fb_core.c
39090@@ -29,7 +29,7 @@ static int crt_option = 1;
39091 static char panel_option[32] = "";
39092
39093 /* Modes relevant to the GX1 (taken from modedb.c) */
39094-static const struct fb_videomode __devinitdata gx1_modedb[] = {
39095+static const struct fb_videomode __devinitconst gx1_modedb[] = {
39096 /* 640x480-60 VESA */
39097 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
39098 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
39099diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
39100index 0fad23f..0e9afa4 100644
39101--- a/drivers/video/gxt4500.c
39102+++ b/drivers/video/gxt4500.c
39103@@ -156,7 +156,7 @@ struct gxt4500_par {
39104 static char *mode_option;
39105
39106 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
39107-static const struct fb_videomode defaultmode __devinitdata = {
39108+static const struct fb_videomode defaultmode __devinitconst = {
39109 .refresh = 60,
39110 .xres = 1280,
39111 .yres = 1024,
39112@@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
39113 return 0;
39114 }
39115
39116-static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
39117+static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
39118 .id = "IBM GXT4500P",
39119 .type = FB_TYPE_PACKED_PIXELS,
39120 .visual = FB_VISUAL_PSEUDOCOLOR,
39121diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39122index 7672d2e..b56437f 100644
39123--- a/drivers/video/i810/i810_accel.c
39124+++ b/drivers/video/i810/i810_accel.c
39125@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39126 }
39127 }
39128 printk("ringbuffer lockup!!!\n");
39129+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39130 i810_report_error(mmio);
39131 par->dev_flags |= LOCKUP;
39132 info->pixmap.scan_align = 1;
39133diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
39134index b83f361..2b05a91 100644
39135--- a/drivers/video/i810/i810_main.c
39136+++ b/drivers/video/i810/i810_main.c
39137@@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
39138 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
39139
39140 /* PCI */
39141-static const char *i810_pci_list[] __devinitdata = {
39142+static const char *i810_pci_list[] __devinitconst = {
39143 "Intel(R) 810 Framebuffer Device" ,
39144 "Intel(R) 810-DC100 Framebuffer Device" ,
39145 "Intel(R) 810E Framebuffer Device" ,
39146diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
39147index de36693..3c63fc2 100644
39148--- a/drivers/video/jz4740_fb.c
39149+++ b/drivers/video/jz4740_fb.c
39150@@ -136,7 +136,7 @@ struct jzfb {
39151 uint32_t pseudo_palette[16];
39152 };
39153
39154-static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
39155+static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
39156 .id = "JZ4740 FB",
39157 .type = FB_TYPE_PACKED_PIXELS,
39158 .visual = FB_VISUAL_TRUECOLOR,
39159diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39160index 3c14e43..eafa544 100644
39161--- a/drivers/video/logo/logo_linux_clut224.ppm
39162+++ b/drivers/video/logo/logo_linux_clut224.ppm
39163@@ -1,1604 +1,1123 @@
39164 P3
39165-# Standard 224-color Linux logo
39166 80 80
39167 255
39168- 0 0 0 0 0 0 0 0 0 0 0 0
39169- 0 0 0 0 0 0 0 0 0 0 0 0
39170- 0 0 0 0 0 0 0 0 0 0 0 0
39171- 0 0 0 0 0 0 0 0 0 0 0 0
39172- 0 0 0 0 0 0 0 0 0 0 0 0
39173- 0 0 0 0 0 0 0 0 0 0 0 0
39174- 0 0 0 0 0 0 0 0 0 0 0 0
39175- 0 0 0 0 0 0 0 0 0 0 0 0
39176- 0 0 0 0 0 0 0 0 0 0 0 0
39177- 6 6 6 6 6 6 10 10 10 10 10 10
39178- 10 10 10 6 6 6 6 6 6 6 6 6
39179- 0 0 0 0 0 0 0 0 0 0 0 0
39180- 0 0 0 0 0 0 0 0 0 0 0 0
39181- 0 0 0 0 0 0 0 0 0 0 0 0
39182- 0 0 0 0 0 0 0 0 0 0 0 0
39183- 0 0 0 0 0 0 0 0 0 0 0 0
39184- 0 0 0 0 0 0 0 0 0 0 0 0
39185- 0 0 0 0 0 0 0 0 0 0 0 0
39186- 0 0 0 0 0 0 0 0 0 0 0 0
39187- 0 0 0 0 0 0 0 0 0 0 0 0
39188- 0 0 0 0 0 0 0 0 0 0 0 0
39189- 0 0 0 0 0 0 0 0 0 0 0 0
39190- 0 0 0 0 0 0 0 0 0 0 0 0
39191- 0 0 0 0 0 0 0 0 0 0 0 0
39192- 0 0 0 0 0 0 0 0 0 0 0 0
39193- 0 0 0 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 6 6 6 10 10 10 14 14 14
39197- 22 22 22 26 26 26 30 30 30 34 34 34
39198- 30 30 30 30 30 30 26 26 26 18 18 18
39199- 14 14 14 10 10 10 6 6 6 0 0 0
39200- 0 0 0 0 0 0 0 0 0 0 0 0
39201- 0 0 0 0 0 0 0 0 0 0 0 0
39202- 0 0 0 0 0 0 0 0 0 0 0 0
39203- 0 0 0 0 0 0 0 0 0 0 0 0
39204- 0 0 0 0 0 0 0 0 0 0 0 0
39205- 0 0 0 0 0 0 0 0 0 0 0 0
39206- 0 0 0 0 0 0 0 0 0 0 0 0
39207- 0 0 0 0 0 0 0 0 0 0 0 0
39208- 0 0 0 0 0 0 0 0 0 0 0 0
39209- 0 0 0 0 0 1 0 0 1 0 0 0
39210- 0 0 0 0 0 0 0 0 0 0 0 0
39211- 0 0 0 0 0 0 0 0 0 0 0 0
39212- 0 0 0 0 0 0 0 0 0 0 0 0
39213- 0 0 0 0 0 0 0 0 0 0 0 0
39214- 0 0 0 0 0 0 0 0 0 0 0 0
39215- 0 0 0 0 0 0 0 0 0 0 0 0
39216- 6 6 6 14 14 14 26 26 26 42 42 42
39217- 54 54 54 66 66 66 78 78 78 78 78 78
39218- 78 78 78 74 74 74 66 66 66 54 54 54
39219- 42 42 42 26 26 26 18 18 18 10 10 10
39220- 6 6 6 0 0 0 0 0 0 0 0 0
39221- 0 0 0 0 0 0 0 0 0 0 0 0
39222- 0 0 0 0 0 0 0 0 0 0 0 0
39223- 0 0 0 0 0 0 0 0 0 0 0 0
39224- 0 0 0 0 0 0 0 0 0 0 0 0
39225- 0 0 0 0 0 0 0 0 0 0 0 0
39226- 0 0 0 0 0 0 0 0 0 0 0 0
39227- 0 0 0 0 0 0 0 0 0 0 0 0
39228- 0 0 0 0 0 0 0 0 0 0 0 0
39229- 0 0 1 0 0 0 0 0 0 0 0 0
39230- 0 0 0 0 0 0 0 0 0 0 0 0
39231- 0 0 0 0 0 0 0 0 0 0 0 0
39232- 0 0 0 0 0 0 0 0 0 0 0 0
39233- 0 0 0 0 0 0 0 0 0 0 0 0
39234- 0 0 0 0 0 0 0 0 0 0 0 0
39235- 0 0 0 0 0 0 0 0 0 10 10 10
39236- 22 22 22 42 42 42 66 66 66 86 86 86
39237- 66 66 66 38 38 38 38 38 38 22 22 22
39238- 26 26 26 34 34 34 54 54 54 66 66 66
39239- 86 86 86 70 70 70 46 46 46 26 26 26
39240- 14 14 14 6 6 6 0 0 0 0 0 0
39241- 0 0 0 0 0 0 0 0 0 0 0 0
39242- 0 0 0 0 0 0 0 0 0 0 0 0
39243- 0 0 0 0 0 0 0 0 0 0 0 0
39244- 0 0 0 0 0 0 0 0 0 0 0 0
39245- 0 0 0 0 0 0 0 0 0 0 0 0
39246- 0 0 0 0 0 0 0 0 0 0 0 0
39247- 0 0 0 0 0 0 0 0 0 0 0 0
39248- 0 0 0 0 0 0 0 0 0 0 0 0
39249- 0 0 1 0 0 1 0 0 1 0 0 0
39250- 0 0 0 0 0 0 0 0 0 0 0 0
39251- 0 0 0 0 0 0 0 0 0 0 0 0
39252- 0 0 0 0 0 0 0 0 0 0 0 0
39253- 0 0 0 0 0 0 0 0 0 0 0 0
39254- 0 0 0 0 0 0 0 0 0 0 0 0
39255- 0 0 0 0 0 0 10 10 10 26 26 26
39256- 50 50 50 82 82 82 58 58 58 6 6 6
39257- 2 2 6 2 2 6 2 2 6 2 2 6
39258- 2 2 6 2 2 6 2 2 6 2 2 6
39259- 6 6 6 54 54 54 86 86 86 66 66 66
39260- 38 38 38 18 18 18 6 6 6 0 0 0
39261- 0 0 0 0 0 0 0 0 0 0 0 0
39262- 0 0 0 0 0 0 0 0 0 0 0 0
39263- 0 0 0 0 0 0 0 0 0 0 0 0
39264- 0 0 0 0 0 0 0 0 0 0 0 0
39265- 0 0 0 0 0 0 0 0 0 0 0 0
39266- 0 0 0 0 0 0 0 0 0 0 0 0
39267- 0 0 0 0 0 0 0 0 0 0 0 0
39268- 0 0 0 0 0 0 0 0 0 0 0 0
39269- 0 0 0 0 0 0 0 0 0 0 0 0
39270- 0 0 0 0 0 0 0 0 0 0 0 0
39271- 0 0 0 0 0 0 0 0 0 0 0 0
39272- 0 0 0 0 0 0 0 0 0 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 6 6 6 22 22 22 50 50 50
39276- 78 78 78 34 34 34 2 2 6 2 2 6
39277- 2 2 6 2 2 6 2 2 6 2 2 6
39278- 2 2 6 2 2 6 2 2 6 2 2 6
39279- 2 2 6 2 2 6 6 6 6 70 70 70
39280- 78 78 78 46 46 46 22 22 22 6 6 6
39281- 0 0 0 0 0 0 0 0 0 0 0 0
39282- 0 0 0 0 0 0 0 0 0 0 0 0
39283- 0 0 0 0 0 0 0 0 0 0 0 0
39284- 0 0 0 0 0 0 0 0 0 0 0 0
39285- 0 0 0 0 0 0 0 0 0 0 0 0
39286- 0 0 0 0 0 0 0 0 0 0 0 0
39287- 0 0 0 0 0 0 0 0 0 0 0 0
39288- 0 0 0 0 0 0 0 0 0 0 0 0
39289- 0 0 1 0 0 1 0 0 1 0 0 0
39290- 0 0 0 0 0 0 0 0 0 0 0 0
39291- 0 0 0 0 0 0 0 0 0 0 0 0
39292- 0 0 0 0 0 0 0 0 0 0 0 0
39293- 0 0 0 0 0 0 0 0 0 0 0 0
39294- 0 0 0 0 0 0 0 0 0 0 0 0
39295- 6 6 6 18 18 18 42 42 42 82 82 82
39296- 26 26 26 2 2 6 2 2 6 2 2 6
39297- 2 2 6 2 2 6 2 2 6 2 2 6
39298- 2 2 6 2 2 6 2 2 6 14 14 14
39299- 46 46 46 34 34 34 6 6 6 2 2 6
39300- 42 42 42 78 78 78 42 42 42 18 18 18
39301- 6 6 6 0 0 0 0 0 0 0 0 0
39302- 0 0 0 0 0 0 0 0 0 0 0 0
39303- 0 0 0 0 0 0 0 0 0 0 0 0
39304- 0 0 0 0 0 0 0 0 0 0 0 0
39305- 0 0 0 0 0 0 0 0 0 0 0 0
39306- 0 0 0 0 0 0 0 0 0 0 0 0
39307- 0 0 0 0 0 0 0 0 0 0 0 0
39308- 0 0 0 0 0 0 0 0 0 0 0 0
39309- 0 0 1 0 0 0 0 0 1 0 0 0
39310- 0 0 0 0 0 0 0 0 0 0 0 0
39311- 0 0 0 0 0 0 0 0 0 0 0 0
39312- 0 0 0 0 0 0 0 0 0 0 0 0
39313- 0 0 0 0 0 0 0 0 0 0 0 0
39314- 0 0 0 0 0 0 0 0 0 0 0 0
39315- 10 10 10 30 30 30 66 66 66 58 58 58
39316- 2 2 6 2 2 6 2 2 6 2 2 6
39317- 2 2 6 2 2 6 2 2 6 2 2 6
39318- 2 2 6 2 2 6 2 2 6 26 26 26
39319- 86 86 86 101 101 101 46 46 46 10 10 10
39320- 2 2 6 58 58 58 70 70 70 34 34 34
39321- 10 10 10 0 0 0 0 0 0 0 0 0
39322- 0 0 0 0 0 0 0 0 0 0 0 0
39323- 0 0 0 0 0 0 0 0 0 0 0 0
39324- 0 0 0 0 0 0 0 0 0 0 0 0
39325- 0 0 0 0 0 0 0 0 0 0 0 0
39326- 0 0 0 0 0 0 0 0 0 0 0 0
39327- 0 0 0 0 0 0 0 0 0 0 0 0
39328- 0 0 0 0 0 0 0 0 0 0 0 0
39329- 0 0 1 0 0 1 0 0 1 0 0 0
39330- 0 0 0 0 0 0 0 0 0 0 0 0
39331- 0 0 0 0 0 0 0 0 0 0 0 0
39332- 0 0 0 0 0 0 0 0 0 0 0 0
39333- 0 0 0 0 0 0 0 0 0 0 0 0
39334- 0 0 0 0 0 0 0 0 0 0 0 0
39335- 14 14 14 42 42 42 86 86 86 10 10 10
39336- 2 2 6 2 2 6 2 2 6 2 2 6
39337- 2 2 6 2 2 6 2 2 6 2 2 6
39338- 2 2 6 2 2 6 2 2 6 30 30 30
39339- 94 94 94 94 94 94 58 58 58 26 26 26
39340- 2 2 6 6 6 6 78 78 78 54 54 54
39341- 22 22 22 6 6 6 0 0 0 0 0 0
39342- 0 0 0 0 0 0 0 0 0 0 0 0
39343- 0 0 0 0 0 0 0 0 0 0 0 0
39344- 0 0 0 0 0 0 0 0 0 0 0 0
39345- 0 0 0 0 0 0 0 0 0 0 0 0
39346- 0 0 0 0 0 0 0 0 0 0 0 0
39347- 0 0 0 0 0 0 0 0 0 0 0 0
39348- 0 0 0 0 0 0 0 0 0 0 0 0
39349- 0 0 0 0 0 0 0 0 0 0 0 0
39350- 0 0 0 0 0 0 0 0 0 0 0 0
39351- 0 0 0 0 0 0 0 0 0 0 0 0
39352- 0 0 0 0 0 0 0 0 0 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 6 6 6
39355- 22 22 22 62 62 62 62 62 62 2 2 6
39356- 2 2 6 2 2 6 2 2 6 2 2 6
39357- 2 2 6 2 2 6 2 2 6 2 2 6
39358- 2 2 6 2 2 6 2 2 6 26 26 26
39359- 54 54 54 38 38 38 18 18 18 10 10 10
39360- 2 2 6 2 2 6 34 34 34 82 82 82
39361- 38 38 38 14 14 14 0 0 0 0 0 0
39362- 0 0 0 0 0 0 0 0 0 0 0 0
39363- 0 0 0 0 0 0 0 0 0 0 0 0
39364- 0 0 0 0 0 0 0 0 0 0 0 0
39365- 0 0 0 0 0 0 0 0 0 0 0 0
39366- 0 0 0 0 0 0 0 0 0 0 0 0
39367- 0 0 0 0 0 0 0 0 0 0 0 0
39368- 0 0 0 0 0 0 0 0 0 0 0 0
39369- 0 0 0 0 0 1 0 0 1 0 0 0
39370- 0 0 0 0 0 0 0 0 0 0 0 0
39371- 0 0 0 0 0 0 0 0 0 0 0 0
39372- 0 0 0 0 0 0 0 0 0 0 0 0
39373- 0 0 0 0 0 0 0 0 0 0 0 0
39374- 0 0 0 0 0 0 0 0 0 6 6 6
39375- 30 30 30 78 78 78 30 30 30 2 2 6
39376- 2 2 6 2 2 6 2 2 6 2 2 6
39377- 2 2 6 2 2 6 2 2 6 2 2 6
39378- 2 2 6 2 2 6 2 2 6 10 10 10
39379- 10 10 10 2 2 6 2 2 6 2 2 6
39380- 2 2 6 2 2 6 2 2 6 78 78 78
39381- 50 50 50 18 18 18 6 6 6 0 0 0
39382- 0 0 0 0 0 0 0 0 0 0 0 0
39383- 0 0 0 0 0 0 0 0 0 0 0 0
39384- 0 0 0 0 0 0 0 0 0 0 0 0
39385- 0 0 0 0 0 0 0 0 0 0 0 0
39386- 0 0 0 0 0 0 0 0 0 0 0 0
39387- 0 0 0 0 0 0 0 0 0 0 0 0
39388- 0 0 0 0 0 0 0 0 0 0 0 0
39389- 0 0 1 0 0 0 0 0 0 0 0 0
39390- 0 0 0 0 0 0 0 0 0 0 0 0
39391- 0 0 0 0 0 0 0 0 0 0 0 0
39392- 0 0 0 0 0 0 0 0 0 0 0 0
39393- 0 0 0 0 0 0 0 0 0 0 0 0
39394- 0 0 0 0 0 0 0 0 0 10 10 10
39395- 38 38 38 86 86 86 14 14 14 2 2 6
39396- 2 2 6 2 2 6 2 2 6 2 2 6
39397- 2 2 6 2 2 6 2 2 6 2 2 6
39398- 2 2 6 2 2 6 2 2 6 2 2 6
39399- 2 2 6 2 2 6 2 2 6 2 2 6
39400- 2 2 6 2 2 6 2 2 6 54 54 54
39401- 66 66 66 26 26 26 6 6 6 0 0 0
39402- 0 0 0 0 0 0 0 0 0 0 0 0
39403- 0 0 0 0 0 0 0 0 0 0 0 0
39404- 0 0 0 0 0 0 0 0 0 0 0 0
39405- 0 0 0 0 0 0 0 0 0 0 0 0
39406- 0 0 0 0 0 0 0 0 0 0 0 0
39407- 0 0 0 0 0 0 0 0 0 0 0 0
39408- 0 0 0 0 0 0 0 0 0 0 0 0
39409- 0 0 0 0 0 1 0 0 1 0 0 0
39410- 0 0 0 0 0 0 0 0 0 0 0 0
39411- 0 0 0 0 0 0 0 0 0 0 0 0
39412- 0 0 0 0 0 0 0 0 0 0 0 0
39413- 0 0 0 0 0 0 0 0 0 0 0 0
39414- 0 0 0 0 0 0 0 0 0 14 14 14
39415- 42 42 42 82 82 82 2 2 6 2 2 6
39416- 2 2 6 6 6 6 10 10 10 2 2 6
39417- 2 2 6 2 2 6 2 2 6 2 2 6
39418- 2 2 6 2 2 6 2 2 6 6 6 6
39419- 14 14 14 10 10 10 2 2 6 2 2 6
39420- 2 2 6 2 2 6 2 2 6 18 18 18
39421- 82 82 82 34 34 34 10 10 10 0 0 0
39422- 0 0 0 0 0 0 0 0 0 0 0 0
39423- 0 0 0 0 0 0 0 0 0 0 0 0
39424- 0 0 0 0 0 0 0 0 0 0 0 0
39425- 0 0 0 0 0 0 0 0 0 0 0 0
39426- 0 0 0 0 0 0 0 0 0 0 0 0
39427- 0 0 0 0 0 0 0 0 0 0 0 0
39428- 0 0 0 0 0 0 0 0 0 0 0 0
39429- 0 0 1 0 0 0 0 0 0 0 0 0
39430- 0 0 0 0 0 0 0 0 0 0 0 0
39431- 0 0 0 0 0 0 0 0 0 0 0 0
39432- 0 0 0 0 0 0 0 0 0 0 0 0
39433- 0 0 0 0 0 0 0 0 0 0 0 0
39434- 0 0 0 0 0 0 0 0 0 14 14 14
39435- 46 46 46 86 86 86 2 2 6 2 2 6
39436- 6 6 6 6 6 6 22 22 22 34 34 34
39437- 6 6 6 2 2 6 2 2 6 2 2 6
39438- 2 2 6 2 2 6 18 18 18 34 34 34
39439- 10 10 10 50 50 50 22 22 22 2 2 6
39440- 2 2 6 2 2 6 2 2 6 10 10 10
39441- 86 86 86 42 42 42 14 14 14 0 0 0
39442- 0 0 0 0 0 0 0 0 0 0 0 0
39443- 0 0 0 0 0 0 0 0 0 0 0 0
39444- 0 0 0 0 0 0 0 0 0 0 0 0
39445- 0 0 0 0 0 0 0 0 0 0 0 0
39446- 0 0 0 0 0 0 0 0 0 0 0 0
39447- 0 0 0 0 0 0 0 0 0 0 0 0
39448- 0 0 0 0 0 0 0 0 0 0 0 0
39449- 0 0 1 0 0 1 0 0 1 0 0 0
39450- 0 0 0 0 0 0 0 0 0 0 0 0
39451- 0 0 0 0 0 0 0 0 0 0 0 0
39452- 0 0 0 0 0 0 0 0 0 0 0 0
39453- 0 0 0 0 0 0 0 0 0 0 0 0
39454- 0 0 0 0 0 0 0 0 0 14 14 14
39455- 46 46 46 86 86 86 2 2 6 2 2 6
39456- 38 38 38 116 116 116 94 94 94 22 22 22
39457- 22 22 22 2 2 6 2 2 6 2 2 6
39458- 14 14 14 86 86 86 138 138 138 162 162 162
39459-154 154 154 38 38 38 26 26 26 6 6 6
39460- 2 2 6 2 2 6 2 2 6 2 2 6
39461- 86 86 86 46 46 46 14 14 14 0 0 0
39462- 0 0 0 0 0 0 0 0 0 0 0 0
39463- 0 0 0 0 0 0 0 0 0 0 0 0
39464- 0 0 0 0 0 0 0 0 0 0 0 0
39465- 0 0 0 0 0 0 0 0 0 0 0 0
39466- 0 0 0 0 0 0 0 0 0 0 0 0
39467- 0 0 0 0 0 0 0 0 0 0 0 0
39468- 0 0 0 0 0 0 0 0 0 0 0 0
39469- 0 0 0 0 0 0 0 0 0 0 0 0
39470- 0 0 0 0 0 0 0 0 0 0 0 0
39471- 0 0 0 0 0 0 0 0 0 0 0 0
39472- 0 0 0 0 0 0 0 0 0 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 14 14 14
39475- 46 46 46 86 86 86 2 2 6 14 14 14
39476-134 134 134 198 198 198 195 195 195 116 116 116
39477- 10 10 10 2 2 6 2 2 6 6 6 6
39478-101 98 89 187 187 187 210 210 210 218 218 218
39479-214 214 214 134 134 134 14 14 14 6 6 6
39480- 2 2 6 2 2 6 2 2 6 2 2 6
39481- 86 86 86 50 50 50 18 18 18 6 6 6
39482- 0 0 0 0 0 0 0 0 0 0 0 0
39483- 0 0 0 0 0 0 0 0 0 0 0 0
39484- 0 0 0 0 0 0 0 0 0 0 0 0
39485- 0 0 0 0 0 0 0 0 0 0 0 0
39486- 0 0 0 0 0 0 0 0 0 0 0 0
39487- 0 0 0 0 0 0 0 0 0 0 0 0
39488- 0 0 0 0 0 0 0 0 1 0 0 0
39489- 0 0 1 0 0 1 0 0 1 0 0 0
39490- 0 0 0 0 0 0 0 0 0 0 0 0
39491- 0 0 0 0 0 0 0 0 0 0 0 0
39492- 0 0 0 0 0 0 0 0 0 0 0 0
39493- 0 0 0 0 0 0 0 0 0 0 0 0
39494- 0 0 0 0 0 0 0 0 0 14 14 14
39495- 46 46 46 86 86 86 2 2 6 54 54 54
39496-218 218 218 195 195 195 226 226 226 246 246 246
39497- 58 58 58 2 2 6 2 2 6 30 30 30
39498-210 210 210 253 253 253 174 174 174 123 123 123
39499-221 221 221 234 234 234 74 74 74 2 2 6
39500- 2 2 6 2 2 6 2 2 6 2 2 6
39501- 70 70 70 58 58 58 22 22 22 6 6 6
39502- 0 0 0 0 0 0 0 0 0 0 0 0
39503- 0 0 0 0 0 0 0 0 0 0 0 0
39504- 0 0 0 0 0 0 0 0 0 0 0 0
39505- 0 0 0 0 0 0 0 0 0 0 0 0
39506- 0 0 0 0 0 0 0 0 0 0 0 0
39507- 0 0 0 0 0 0 0 0 0 0 0 0
39508- 0 0 0 0 0 0 0 0 0 0 0 0
39509- 0 0 0 0 0 0 0 0 0 0 0 0
39510- 0 0 0 0 0 0 0 0 0 0 0 0
39511- 0 0 0 0 0 0 0 0 0 0 0 0
39512- 0 0 0 0 0 0 0 0 0 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 14 14 14
39515- 46 46 46 82 82 82 2 2 6 106 106 106
39516-170 170 170 26 26 26 86 86 86 226 226 226
39517-123 123 123 10 10 10 14 14 14 46 46 46
39518-231 231 231 190 190 190 6 6 6 70 70 70
39519- 90 90 90 238 238 238 158 158 158 2 2 6
39520- 2 2 6 2 2 6 2 2 6 2 2 6
39521- 70 70 70 58 58 58 22 22 22 6 6 6
39522- 0 0 0 0 0 0 0 0 0 0 0 0
39523- 0 0 0 0 0 0 0 0 0 0 0 0
39524- 0 0 0 0 0 0 0 0 0 0 0 0
39525- 0 0 0 0 0 0 0 0 0 0 0 0
39526- 0 0 0 0 0 0 0 0 0 0 0 0
39527- 0 0 0 0 0 0 0 0 0 0 0 0
39528- 0 0 0 0 0 0 0 0 1 0 0 0
39529- 0 0 1 0 0 1 0 0 1 0 0 0
39530- 0 0 0 0 0 0 0 0 0 0 0 0
39531- 0 0 0 0 0 0 0 0 0 0 0 0
39532- 0 0 0 0 0 0 0 0 0 0 0 0
39533- 0 0 0 0 0 0 0 0 0 0 0 0
39534- 0 0 0 0 0 0 0 0 0 14 14 14
39535- 42 42 42 86 86 86 6 6 6 116 116 116
39536-106 106 106 6 6 6 70 70 70 149 149 149
39537-128 128 128 18 18 18 38 38 38 54 54 54
39538-221 221 221 106 106 106 2 2 6 14 14 14
39539- 46 46 46 190 190 190 198 198 198 2 2 6
39540- 2 2 6 2 2 6 2 2 6 2 2 6
39541- 74 74 74 62 62 62 22 22 22 6 6 6
39542- 0 0 0 0 0 0 0 0 0 0 0 0
39543- 0 0 0 0 0 0 0 0 0 0 0 0
39544- 0 0 0 0 0 0 0 0 0 0 0 0
39545- 0 0 0 0 0 0 0 0 0 0 0 0
39546- 0 0 0 0 0 0 0 0 0 0 0 0
39547- 0 0 0 0 0 0 0 0 0 0 0 0
39548- 0 0 0 0 0 0 0 0 1 0 0 0
39549- 0 0 1 0 0 0 0 0 1 0 0 0
39550- 0 0 0 0 0 0 0 0 0 0 0 0
39551- 0 0 0 0 0 0 0 0 0 0 0 0
39552- 0 0 0 0 0 0 0 0 0 0 0 0
39553- 0 0 0 0 0 0 0 0 0 0 0 0
39554- 0 0 0 0 0 0 0 0 0 14 14 14
39555- 42 42 42 94 94 94 14 14 14 101 101 101
39556-128 128 128 2 2 6 18 18 18 116 116 116
39557-118 98 46 121 92 8 121 92 8 98 78 10
39558-162 162 162 106 106 106 2 2 6 2 2 6
39559- 2 2 6 195 195 195 195 195 195 6 6 6
39560- 2 2 6 2 2 6 2 2 6 2 2 6
39561- 74 74 74 62 62 62 22 22 22 6 6 6
39562- 0 0 0 0 0 0 0 0 0 0 0 0
39563- 0 0 0 0 0 0 0 0 0 0 0 0
39564- 0 0 0 0 0 0 0 0 0 0 0 0
39565- 0 0 0 0 0 0 0 0 0 0 0 0
39566- 0 0 0 0 0 0 0 0 0 0 0 0
39567- 0 0 0 0 0 0 0 0 0 0 0 0
39568- 0 0 0 0 0 0 0 0 1 0 0 1
39569- 0 0 1 0 0 0 0 0 1 0 0 0
39570- 0 0 0 0 0 0 0 0 0 0 0 0
39571- 0 0 0 0 0 0 0 0 0 0 0 0
39572- 0 0 0 0 0 0 0 0 0 0 0 0
39573- 0 0 0 0 0 0 0 0 0 0 0 0
39574- 0 0 0 0 0 0 0 0 0 10 10 10
39575- 38 38 38 90 90 90 14 14 14 58 58 58
39576-210 210 210 26 26 26 54 38 6 154 114 10
39577-226 170 11 236 186 11 225 175 15 184 144 12
39578-215 174 15 175 146 61 37 26 9 2 2 6
39579- 70 70 70 246 246 246 138 138 138 2 2 6
39580- 2 2 6 2 2 6 2 2 6 2 2 6
39581- 70 70 70 66 66 66 26 26 26 6 6 6
39582- 0 0 0 0 0 0 0 0 0 0 0 0
39583- 0 0 0 0 0 0 0 0 0 0 0 0
39584- 0 0 0 0 0 0 0 0 0 0 0 0
39585- 0 0 0 0 0 0 0 0 0 0 0 0
39586- 0 0 0 0 0 0 0 0 0 0 0 0
39587- 0 0 0 0 0 0 0 0 0 0 0 0
39588- 0 0 0 0 0 0 0 0 0 0 0 0
39589- 0 0 0 0 0 0 0 0 0 0 0 0
39590- 0 0 0 0 0 0 0 0 0 0 0 0
39591- 0 0 0 0 0 0 0 0 0 0 0 0
39592- 0 0 0 0 0 0 0 0 0 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 10 10 10
39595- 38 38 38 86 86 86 14 14 14 10 10 10
39596-195 195 195 188 164 115 192 133 9 225 175 15
39597-239 182 13 234 190 10 232 195 16 232 200 30
39598-245 207 45 241 208 19 232 195 16 184 144 12
39599-218 194 134 211 206 186 42 42 42 2 2 6
39600- 2 2 6 2 2 6 2 2 6 2 2 6
39601- 50 50 50 74 74 74 30 30 30 6 6 6
39602- 0 0 0 0 0 0 0 0 0 0 0 0
39603- 0 0 0 0 0 0 0 0 0 0 0 0
39604- 0 0 0 0 0 0 0 0 0 0 0 0
39605- 0 0 0 0 0 0 0 0 0 0 0 0
39606- 0 0 0 0 0 0 0 0 0 0 0 0
39607- 0 0 0 0 0 0 0 0 0 0 0 0
39608- 0 0 0 0 0 0 0 0 0 0 0 0
39609- 0 0 0 0 0 0 0 0 0 0 0 0
39610- 0 0 0 0 0 0 0 0 0 0 0 0
39611- 0 0 0 0 0 0 0 0 0 0 0 0
39612- 0 0 0 0 0 0 0 0 0 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 10 10 10
39615- 34 34 34 86 86 86 14 14 14 2 2 6
39616-121 87 25 192 133 9 219 162 10 239 182 13
39617-236 186 11 232 195 16 241 208 19 244 214 54
39618-246 218 60 246 218 38 246 215 20 241 208 19
39619-241 208 19 226 184 13 121 87 25 2 2 6
39620- 2 2 6 2 2 6 2 2 6 2 2 6
39621- 50 50 50 82 82 82 34 34 34 10 10 10
39622- 0 0 0 0 0 0 0 0 0 0 0 0
39623- 0 0 0 0 0 0 0 0 0 0 0 0
39624- 0 0 0 0 0 0 0 0 0 0 0 0
39625- 0 0 0 0 0 0 0 0 0 0 0 0
39626- 0 0 0 0 0 0 0 0 0 0 0 0
39627- 0 0 0 0 0 0 0 0 0 0 0 0
39628- 0 0 0 0 0 0 0 0 0 0 0 0
39629- 0 0 0 0 0 0 0 0 0 0 0 0
39630- 0 0 0 0 0 0 0 0 0 0 0 0
39631- 0 0 0 0 0 0 0 0 0 0 0 0
39632- 0 0 0 0 0 0 0 0 0 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 10 10 10
39635- 34 34 34 82 82 82 30 30 30 61 42 6
39636-180 123 7 206 145 10 230 174 11 239 182 13
39637-234 190 10 238 202 15 241 208 19 246 218 74
39638-246 218 38 246 215 20 246 215 20 246 215 20
39639-226 184 13 215 174 15 184 144 12 6 6 6
39640- 2 2 6 2 2 6 2 2 6 2 2 6
39641- 26 26 26 94 94 94 42 42 42 14 14 14
39642- 0 0 0 0 0 0 0 0 0 0 0 0
39643- 0 0 0 0 0 0 0 0 0 0 0 0
39644- 0 0 0 0 0 0 0 0 0 0 0 0
39645- 0 0 0 0 0 0 0 0 0 0 0 0
39646- 0 0 0 0 0 0 0 0 0 0 0 0
39647- 0 0 0 0 0 0 0 0 0 0 0 0
39648- 0 0 0 0 0 0 0 0 0 0 0 0
39649- 0 0 0 0 0 0 0 0 0 0 0 0
39650- 0 0 0 0 0 0 0 0 0 0 0 0
39651- 0 0 0 0 0 0 0 0 0 0 0 0
39652- 0 0 0 0 0 0 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 10 10 10
39655- 30 30 30 78 78 78 50 50 50 104 69 6
39656-192 133 9 216 158 10 236 178 12 236 186 11
39657-232 195 16 241 208 19 244 214 54 245 215 43
39658-246 215 20 246 215 20 241 208 19 198 155 10
39659-200 144 11 216 158 10 156 118 10 2 2 6
39660- 2 2 6 2 2 6 2 2 6 2 2 6
39661- 6 6 6 90 90 90 54 54 54 18 18 18
39662- 6 6 6 0 0 0 0 0 0 0 0 0
39663- 0 0 0 0 0 0 0 0 0 0 0 0
39664- 0 0 0 0 0 0 0 0 0 0 0 0
39665- 0 0 0 0 0 0 0 0 0 0 0 0
39666- 0 0 0 0 0 0 0 0 0 0 0 0
39667- 0 0 0 0 0 0 0 0 0 0 0 0
39668- 0 0 0 0 0 0 0 0 0 0 0 0
39669- 0 0 0 0 0 0 0 0 0 0 0 0
39670- 0 0 0 0 0 0 0 0 0 0 0 0
39671- 0 0 0 0 0 0 0 0 0 0 0 0
39672- 0 0 0 0 0 0 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 10 10 10
39675- 30 30 30 78 78 78 46 46 46 22 22 22
39676-137 92 6 210 162 10 239 182 13 238 190 10
39677-238 202 15 241 208 19 246 215 20 246 215 20
39678-241 208 19 203 166 17 185 133 11 210 150 10
39679-216 158 10 210 150 10 102 78 10 2 2 6
39680- 6 6 6 54 54 54 14 14 14 2 2 6
39681- 2 2 6 62 62 62 74 74 74 30 30 30
39682- 10 10 10 0 0 0 0 0 0 0 0 0
39683- 0 0 0 0 0 0 0 0 0 0 0 0
39684- 0 0 0 0 0 0 0 0 0 0 0 0
39685- 0 0 0 0 0 0 0 0 0 0 0 0
39686- 0 0 0 0 0 0 0 0 0 0 0 0
39687- 0 0 0 0 0 0 0 0 0 0 0 0
39688- 0 0 0 0 0 0 0 0 0 0 0 0
39689- 0 0 0 0 0 0 0 0 0 0 0 0
39690- 0 0 0 0 0 0 0 0 0 0 0 0
39691- 0 0 0 0 0 0 0 0 0 0 0 0
39692- 0 0 0 0 0 0 0 0 0 0 0 0
39693- 0 0 0 0 0 0 0 0 0 0 0 0
39694- 0 0 0 0 0 0 0 0 0 10 10 10
39695- 34 34 34 78 78 78 50 50 50 6 6 6
39696- 94 70 30 139 102 15 190 146 13 226 184 13
39697-232 200 30 232 195 16 215 174 15 190 146 13
39698-168 122 10 192 133 9 210 150 10 213 154 11
39699-202 150 34 182 157 106 101 98 89 2 2 6
39700- 2 2 6 78 78 78 116 116 116 58 58 58
39701- 2 2 6 22 22 22 90 90 90 46 46 46
39702- 18 18 18 6 6 6 0 0 0 0 0 0
39703- 0 0 0 0 0 0 0 0 0 0 0 0
39704- 0 0 0 0 0 0 0 0 0 0 0 0
39705- 0 0 0 0 0 0 0 0 0 0 0 0
39706- 0 0 0 0 0 0 0 0 0 0 0 0
39707- 0 0 0 0 0 0 0 0 0 0 0 0
39708- 0 0 0 0 0 0 0 0 0 0 0 0
39709- 0 0 0 0 0 0 0 0 0 0 0 0
39710- 0 0 0 0 0 0 0 0 0 0 0 0
39711- 0 0 0 0 0 0 0 0 0 0 0 0
39712- 0 0 0 0 0 0 0 0 0 0 0 0
39713- 0 0 0 0 0 0 0 0 0 0 0 0
39714- 0 0 0 0 0 0 0 0 0 10 10 10
39715- 38 38 38 86 86 86 50 50 50 6 6 6
39716-128 128 128 174 154 114 156 107 11 168 122 10
39717-198 155 10 184 144 12 197 138 11 200 144 11
39718-206 145 10 206 145 10 197 138 11 188 164 115
39719-195 195 195 198 198 198 174 174 174 14 14 14
39720- 2 2 6 22 22 22 116 116 116 116 116 116
39721- 22 22 22 2 2 6 74 74 74 70 70 70
39722- 30 30 30 10 10 10 0 0 0 0 0 0
39723- 0 0 0 0 0 0 0 0 0 0 0 0
39724- 0 0 0 0 0 0 0 0 0 0 0 0
39725- 0 0 0 0 0 0 0 0 0 0 0 0
39726- 0 0 0 0 0 0 0 0 0 0 0 0
39727- 0 0 0 0 0 0 0 0 0 0 0 0
39728- 0 0 0 0 0 0 0 0 0 0 0 0
39729- 0 0 0 0 0 0 0 0 0 0 0 0
39730- 0 0 0 0 0 0 0 0 0 0 0 0
39731- 0 0 0 0 0 0 0 0 0 0 0 0
39732- 0 0 0 0 0 0 0 0 0 0 0 0
39733- 0 0 0 0 0 0 0 0 0 0 0 0
39734- 0 0 0 0 0 0 6 6 6 18 18 18
39735- 50 50 50 101 101 101 26 26 26 10 10 10
39736-138 138 138 190 190 190 174 154 114 156 107 11
39737-197 138 11 200 144 11 197 138 11 192 133 9
39738-180 123 7 190 142 34 190 178 144 187 187 187
39739-202 202 202 221 221 221 214 214 214 66 66 66
39740- 2 2 6 2 2 6 50 50 50 62 62 62
39741- 6 6 6 2 2 6 10 10 10 90 90 90
39742- 50 50 50 18 18 18 6 6 6 0 0 0
39743- 0 0 0 0 0 0 0 0 0 0 0 0
39744- 0 0 0 0 0 0 0 0 0 0 0 0
39745- 0 0 0 0 0 0 0 0 0 0 0 0
39746- 0 0 0 0 0 0 0 0 0 0 0 0
39747- 0 0 0 0 0 0 0 0 0 0 0 0
39748- 0 0 0 0 0 0 0 0 0 0 0 0
39749- 0 0 0 0 0 0 0 0 0 0 0 0
39750- 0 0 0 0 0 0 0 0 0 0 0 0
39751- 0 0 0 0 0 0 0 0 0 0 0 0
39752- 0 0 0 0 0 0 0 0 0 0 0 0
39753- 0 0 0 0 0 0 0 0 0 0 0 0
39754- 0 0 0 0 0 0 10 10 10 34 34 34
39755- 74 74 74 74 74 74 2 2 6 6 6 6
39756-144 144 144 198 198 198 190 190 190 178 166 146
39757-154 121 60 156 107 11 156 107 11 168 124 44
39758-174 154 114 187 187 187 190 190 190 210 210 210
39759-246 246 246 253 253 253 253 253 253 182 182 182
39760- 6 6 6 2 2 6 2 2 6 2 2 6
39761- 2 2 6 2 2 6 2 2 6 62 62 62
39762- 74 74 74 34 34 34 14 14 14 0 0 0
39763- 0 0 0 0 0 0 0 0 0 0 0 0
39764- 0 0 0 0 0 0 0 0 0 0 0 0
39765- 0 0 0 0 0 0 0 0 0 0 0 0
39766- 0 0 0 0 0 0 0 0 0 0 0 0
39767- 0 0 0 0 0 0 0 0 0 0 0 0
39768- 0 0 0 0 0 0 0 0 0 0 0 0
39769- 0 0 0 0 0 0 0 0 0 0 0 0
39770- 0 0 0 0 0 0 0 0 0 0 0 0
39771- 0 0 0 0 0 0 0 0 0 0 0 0
39772- 0 0 0 0 0 0 0 0 0 0 0 0
39773- 0 0 0 0 0 0 0 0 0 0 0 0
39774- 0 0 0 10 10 10 22 22 22 54 54 54
39775- 94 94 94 18 18 18 2 2 6 46 46 46
39776-234 234 234 221 221 221 190 190 190 190 190 190
39777-190 190 190 187 187 187 187 187 187 190 190 190
39778-190 190 190 195 195 195 214 214 214 242 242 242
39779-253 253 253 253 253 253 253 253 253 253 253 253
39780- 82 82 82 2 2 6 2 2 6 2 2 6
39781- 2 2 6 2 2 6 2 2 6 14 14 14
39782- 86 86 86 54 54 54 22 22 22 6 6 6
39783- 0 0 0 0 0 0 0 0 0 0 0 0
39784- 0 0 0 0 0 0 0 0 0 0 0 0
39785- 0 0 0 0 0 0 0 0 0 0 0 0
39786- 0 0 0 0 0 0 0 0 0 0 0 0
39787- 0 0 0 0 0 0 0 0 0 0 0 0
39788- 0 0 0 0 0 0 0 0 0 0 0 0
39789- 0 0 0 0 0 0 0 0 0 0 0 0
39790- 0 0 0 0 0 0 0 0 0 0 0 0
39791- 0 0 0 0 0 0 0 0 0 0 0 0
39792- 0 0 0 0 0 0 0 0 0 0 0 0
39793- 0 0 0 0 0 0 0 0 0 0 0 0
39794- 6 6 6 18 18 18 46 46 46 90 90 90
39795- 46 46 46 18 18 18 6 6 6 182 182 182
39796-253 253 253 246 246 246 206 206 206 190 190 190
39797-190 190 190 190 190 190 190 190 190 190 190 190
39798-206 206 206 231 231 231 250 250 250 253 253 253
39799-253 253 253 253 253 253 253 253 253 253 253 253
39800-202 202 202 14 14 14 2 2 6 2 2 6
39801- 2 2 6 2 2 6 2 2 6 2 2 6
39802- 42 42 42 86 86 86 42 42 42 18 18 18
39803- 6 6 6 0 0 0 0 0 0 0 0 0
39804- 0 0 0 0 0 0 0 0 0 0 0 0
39805- 0 0 0 0 0 0 0 0 0 0 0 0
39806- 0 0 0 0 0 0 0 0 0 0 0 0
39807- 0 0 0 0 0 0 0 0 0 0 0 0
39808- 0 0 0 0 0 0 0 0 0 0 0 0
39809- 0 0 0 0 0 0 0 0 0 0 0 0
39810- 0 0 0 0 0 0 0 0 0 0 0 0
39811- 0 0 0 0 0 0 0 0 0 0 0 0
39812- 0 0 0 0 0 0 0 0 0 0 0 0
39813- 0 0 0 0 0 0 0 0 0 6 6 6
39814- 14 14 14 38 38 38 74 74 74 66 66 66
39815- 2 2 6 6 6 6 90 90 90 250 250 250
39816-253 253 253 253 253 253 238 238 238 198 198 198
39817-190 190 190 190 190 190 195 195 195 221 221 221
39818-246 246 246 253 253 253 253 253 253 253 253 253
39819-253 253 253 253 253 253 253 253 253 253 253 253
39820-253 253 253 82 82 82 2 2 6 2 2 6
39821- 2 2 6 2 2 6 2 2 6 2 2 6
39822- 2 2 6 78 78 78 70 70 70 34 34 34
39823- 14 14 14 6 6 6 0 0 0 0 0 0
39824- 0 0 0 0 0 0 0 0 0 0 0 0
39825- 0 0 0 0 0 0 0 0 0 0 0 0
39826- 0 0 0 0 0 0 0 0 0 0 0 0
39827- 0 0 0 0 0 0 0 0 0 0 0 0
39828- 0 0 0 0 0 0 0 0 0 0 0 0
39829- 0 0 0 0 0 0 0 0 0 0 0 0
39830- 0 0 0 0 0 0 0 0 0 0 0 0
39831- 0 0 0 0 0 0 0 0 0 0 0 0
39832- 0 0 0 0 0 0 0 0 0 0 0 0
39833- 0 0 0 0 0 0 0 0 0 14 14 14
39834- 34 34 34 66 66 66 78 78 78 6 6 6
39835- 2 2 6 18 18 18 218 218 218 253 253 253
39836-253 253 253 253 253 253 253 253 253 246 246 246
39837-226 226 226 231 231 231 246 246 246 253 253 253
39838-253 253 253 253 253 253 253 253 253 253 253 253
39839-253 253 253 253 253 253 253 253 253 253 253 253
39840-253 253 253 178 178 178 2 2 6 2 2 6
39841- 2 2 6 2 2 6 2 2 6 2 2 6
39842- 2 2 6 18 18 18 90 90 90 62 62 62
39843- 30 30 30 10 10 10 0 0 0 0 0 0
39844- 0 0 0 0 0 0 0 0 0 0 0 0
39845- 0 0 0 0 0 0 0 0 0 0 0 0
39846- 0 0 0 0 0 0 0 0 0 0 0 0
39847- 0 0 0 0 0 0 0 0 0 0 0 0
39848- 0 0 0 0 0 0 0 0 0 0 0 0
39849- 0 0 0 0 0 0 0 0 0 0 0 0
39850- 0 0 0 0 0 0 0 0 0 0 0 0
39851- 0 0 0 0 0 0 0 0 0 0 0 0
39852- 0 0 0 0 0 0 0 0 0 0 0 0
39853- 0 0 0 0 0 0 10 10 10 26 26 26
39854- 58 58 58 90 90 90 18 18 18 2 2 6
39855- 2 2 6 110 110 110 253 253 253 253 253 253
39856-253 253 253 253 253 253 253 253 253 253 253 253
39857-250 250 250 253 253 253 253 253 253 253 253 253
39858-253 253 253 253 253 253 253 253 253 253 253 253
39859-253 253 253 253 253 253 253 253 253 253 253 253
39860-253 253 253 231 231 231 18 18 18 2 2 6
39861- 2 2 6 2 2 6 2 2 6 2 2 6
39862- 2 2 6 2 2 6 18 18 18 94 94 94
39863- 54 54 54 26 26 26 10 10 10 0 0 0
39864- 0 0 0 0 0 0 0 0 0 0 0 0
39865- 0 0 0 0 0 0 0 0 0 0 0 0
39866- 0 0 0 0 0 0 0 0 0 0 0 0
39867- 0 0 0 0 0 0 0 0 0 0 0 0
39868- 0 0 0 0 0 0 0 0 0 0 0 0
39869- 0 0 0 0 0 0 0 0 0 0 0 0
39870- 0 0 0 0 0 0 0 0 0 0 0 0
39871- 0 0 0 0 0 0 0 0 0 0 0 0
39872- 0 0 0 0 0 0 0 0 0 0 0 0
39873- 0 0 0 6 6 6 22 22 22 50 50 50
39874- 90 90 90 26 26 26 2 2 6 2 2 6
39875- 14 14 14 195 195 195 250 250 250 253 253 253
39876-253 253 253 253 253 253 253 253 253 253 253 253
39877-253 253 253 253 253 253 253 253 253 253 253 253
39878-253 253 253 253 253 253 253 253 253 253 253 253
39879-253 253 253 253 253 253 253 253 253 253 253 253
39880-250 250 250 242 242 242 54 54 54 2 2 6
39881- 2 2 6 2 2 6 2 2 6 2 2 6
39882- 2 2 6 2 2 6 2 2 6 38 38 38
39883- 86 86 86 50 50 50 22 22 22 6 6 6
39884- 0 0 0 0 0 0 0 0 0 0 0 0
39885- 0 0 0 0 0 0 0 0 0 0 0 0
39886- 0 0 0 0 0 0 0 0 0 0 0 0
39887- 0 0 0 0 0 0 0 0 0 0 0 0
39888- 0 0 0 0 0 0 0 0 0 0 0 0
39889- 0 0 0 0 0 0 0 0 0 0 0 0
39890- 0 0 0 0 0 0 0 0 0 0 0 0
39891- 0 0 0 0 0 0 0 0 0 0 0 0
39892- 0 0 0 0 0 0 0 0 0 0 0 0
39893- 6 6 6 14 14 14 38 38 38 82 82 82
39894- 34 34 34 2 2 6 2 2 6 2 2 6
39895- 42 42 42 195 195 195 246 246 246 253 253 253
39896-253 253 253 253 253 253 253 253 253 250 250 250
39897-242 242 242 242 242 242 250 250 250 253 253 253
39898-253 253 253 253 253 253 253 253 253 253 253 253
39899-253 253 253 250 250 250 246 246 246 238 238 238
39900-226 226 226 231 231 231 101 101 101 6 6 6
39901- 2 2 6 2 2 6 2 2 6 2 2 6
39902- 2 2 6 2 2 6 2 2 6 2 2 6
39903- 38 38 38 82 82 82 42 42 42 14 14 14
39904- 6 6 6 0 0 0 0 0 0 0 0 0
39905- 0 0 0 0 0 0 0 0 0 0 0 0
39906- 0 0 0 0 0 0 0 0 0 0 0 0
39907- 0 0 0 0 0 0 0 0 0 0 0 0
39908- 0 0 0 0 0 0 0 0 0 0 0 0
39909- 0 0 0 0 0 0 0 0 0 0 0 0
39910- 0 0 0 0 0 0 0 0 0 0 0 0
39911- 0 0 0 0 0 0 0 0 0 0 0 0
39912- 0 0 0 0 0 0 0 0 0 0 0 0
39913- 10 10 10 26 26 26 62 62 62 66 66 66
39914- 2 2 6 2 2 6 2 2 6 6 6 6
39915- 70 70 70 170 170 170 206 206 206 234 234 234
39916-246 246 246 250 250 250 250 250 250 238 238 238
39917-226 226 226 231 231 231 238 238 238 250 250 250
39918-250 250 250 250 250 250 246 246 246 231 231 231
39919-214 214 214 206 206 206 202 202 202 202 202 202
39920-198 198 198 202 202 202 182 182 182 18 18 18
39921- 2 2 6 2 2 6 2 2 6 2 2 6
39922- 2 2 6 2 2 6 2 2 6 2 2 6
39923- 2 2 6 62 62 62 66 66 66 30 30 30
39924- 10 10 10 0 0 0 0 0 0 0 0 0
39925- 0 0 0 0 0 0 0 0 0 0 0 0
39926- 0 0 0 0 0 0 0 0 0 0 0 0
39927- 0 0 0 0 0 0 0 0 0 0 0 0
39928- 0 0 0 0 0 0 0 0 0 0 0 0
39929- 0 0 0 0 0 0 0 0 0 0 0 0
39930- 0 0 0 0 0 0 0 0 0 0 0 0
39931- 0 0 0 0 0 0 0 0 0 0 0 0
39932- 0 0 0 0 0 0 0 0 0 0 0 0
39933- 14 14 14 42 42 42 82 82 82 18 18 18
39934- 2 2 6 2 2 6 2 2 6 10 10 10
39935- 94 94 94 182 182 182 218 218 218 242 242 242
39936-250 250 250 253 253 253 253 253 253 250 250 250
39937-234 234 234 253 253 253 253 253 253 253 253 253
39938-253 253 253 253 253 253 253 253 253 246 246 246
39939-238 238 238 226 226 226 210 210 210 202 202 202
39940-195 195 195 195 195 195 210 210 210 158 158 158
39941- 6 6 6 14 14 14 50 50 50 14 14 14
39942- 2 2 6 2 2 6 2 2 6 2 2 6
39943- 2 2 6 6 6 6 86 86 86 46 46 46
39944- 18 18 18 6 6 6 0 0 0 0 0 0
39945- 0 0 0 0 0 0 0 0 0 0 0 0
39946- 0 0 0 0 0 0 0 0 0 0 0 0
39947- 0 0 0 0 0 0 0 0 0 0 0 0
39948- 0 0 0 0 0 0 0 0 0 0 0 0
39949- 0 0 0 0 0 0 0 0 0 0 0 0
39950- 0 0 0 0 0 0 0 0 0 0 0 0
39951- 0 0 0 0 0 0 0 0 0 0 0 0
39952- 0 0 0 0 0 0 0 0 0 6 6 6
39953- 22 22 22 54 54 54 70 70 70 2 2 6
39954- 2 2 6 10 10 10 2 2 6 22 22 22
39955-166 166 166 231 231 231 250 250 250 253 253 253
39956-253 253 253 253 253 253 253 253 253 250 250 250
39957-242 242 242 253 253 253 253 253 253 253 253 253
39958-253 253 253 253 253 253 253 253 253 253 253 253
39959-253 253 253 253 253 253 253 253 253 246 246 246
39960-231 231 231 206 206 206 198 198 198 226 226 226
39961- 94 94 94 2 2 6 6 6 6 38 38 38
39962- 30 30 30 2 2 6 2 2 6 2 2 6
39963- 2 2 6 2 2 6 62 62 62 66 66 66
39964- 26 26 26 10 10 10 0 0 0 0 0 0
39965- 0 0 0 0 0 0 0 0 0 0 0 0
39966- 0 0 0 0 0 0 0 0 0 0 0 0
39967- 0 0 0 0 0 0 0 0 0 0 0 0
39968- 0 0 0 0 0 0 0 0 0 0 0 0
39969- 0 0 0 0 0 0 0 0 0 0 0 0
39970- 0 0 0 0 0 0 0 0 0 0 0 0
39971- 0 0 0 0 0 0 0 0 0 0 0 0
39972- 0 0 0 0 0 0 0 0 0 10 10 10
39973- 30 30 30 74 74 74 50 50 50 2 2 6
39974- 26 26 26 26 26 26 2 2 6 106 106 106
39975-238 238 238 253 253 253 253 253 253 253 253 253
39976-253 253 253 253 253 253 253 253 253 253 253 253
39977-253 253 253 253 253 253 253 253 253 253 253 253
39978-253 253 253 253 253 253 253 253 253 253 253 253
39979-253 253 253 253 253 253 253 253 253 253 253 253
39980-253 253 253 246 246 246 218 218 218 202 202 202
39981-210 210 210 14 14 14 2 2 6 2 2 6
39982- 30 30 30 22 22 22 2 2 6 2 2 6
39983- 2 2 6 2 2 6 18 18 18 86 86 86
39984- 42 42 42 14 14 14 0 0 0 0 0 0
39985- 0 0 0 0 0 0 0 0 0 0 0 0
39986- 0 0 0 0 0 0 0 0 0 0 0 0
39987- 0 0 0 0 0 0 0 0 0 0 0 0
39988- 0 0 0 0 0 0 0 0 0 0 0 0
39989- 0 0 0 0 0 0 0 0 0 0 0 0
39990- 0 0 0 0 0 0 0 0 0 0 0 0
39991- 0 0 0 0 0 0 0 0 0 0 0 0
39992- 0 0 0 0 0 0 0 0 0 14 14 14
39993- 42 42 42 90 90 90 22 22 22 2 2 6
39994- 42 42 42 2 2 6 18 18 18 218 218 218
39995-253 253 253 253 253 253 253 253 253 253 253 253
39996-253 253 253 253 253 253 253 253 253 253 253 253
39997-253 253 253 253 253 253 253 253 253 253 253 253
39998-253 253 253 253 253 253 253 253 253 253 253 253
39999-253 253 253 253 253 253 253 253 253 253 253 253
40000-253 253 253 253 253 253 250 250 250 221 221 221
40001-218 218 218 101 101 101 2 2 6 14 14 14
40002- 18 18 18 38 38 38 10 10 10 2 2 6
40003- 2 2 6 2 2 6 2 2 6 78 78 78
40004- 58 58 58 22 22 22 6 6 6 0 0 0
40005- 0 0 0 0 0 0 0 0 0 0 0 0
40006- 0 0 0 0 0 0 0 0 0 0 0 0
40007- 0 0 0 0 0 0 0 0 0 0 0 0
40008- 0 0 0 0 0 0 0 0 0 0 0 0
40009- 0 0 0 0 0 0 0 0 0 0 0 0
40010- 0 0 0 0 0 0 0 0 0 0 0 0
40011- 0 0 0 0 0 0 0 0 0 0 0 0
40012- 0 0 0 0 0 0 6 6 6 18 18 18
40013- 54 54 54 82 82 82 2 2 6 26 26 26
40014- 22 22 22 2 2 6 123 123 123 253 253 253
40015-253 253 253 253 253 253 253 253 253 253 253 253
40016-253 253 253 253 253 253 253 253 253 253 253 253
40017-253 253 253 253 253 253 253 253 253 253 253 253
40018-253 253 253 253 253 253 253 253 253 253 253 253
40019-253 253 253 253 253 253 253 253 253 253 253 253
40020-253 253 253 253 253 253 253 253 253 250 250 250
40021-238 238 238 198 198 198 6 6 6 38 38 38
40022- 58 58 58 26 26 26 38 38 38 2 2 6
40023- 2 2 6 2 2 6 2 2 6 46 46 46
40024- 78 78 78 30 30 30 10 10 10 0 0 0
40025- 0 0 0 0 0 0 0 0 0 0 0 0
40026- 0 0 0 0 0 0 0 0 0 0 0 0
40027- 0 0 0 0 0 0 0 0 0 0 0 0
40028- 0 0 0 0 0 0 0 0 0 0 0 0
40029- 0 0 0 0 0 0 0 0 0 0 0 0
40030- 0 0 0 0 0 0 0 0 0 0 0 0
40031- 0 0 0 0 0 0 0 0 0 0 0 0
40032- 0 0 0 0 0 0 10 10 10 30 30 30
40033- 74 74 74 58 58 58 2 2 6 42 42 42
40034- 2 2 6 22 22 22 231 231 231 253 253 253
40035-253 253 253 253 253 253 253 253 253 253 253 253
40036-253 253 253 253 253 253 253 253 253 250 250 250
40037-253 253 253 253 253 253 253 253 253 253 253 253
40038-253 253 253 253 253 253 253 253 253 253 253 253
40039-253 253 253 253 253 253 253 253 253 253 253 253
40040-253 253 253 253 253 253 253 253 253 253 253 253
40041-253 253 253 246 246 246 46 46 46 38 38 38
40042- 42 42 42 14 14 14 38 38 38 14 14 14
40043- 2 2 6 2 2 6 2 2 6 6 6 6
40044- 86 86 86 46 46 46 14 14 14 0 0 0
40045- 0 0 0 0 0 0 0 0 0 0 0 0
40046- 0 0 0 0 0 0 0 0 0 0 0 0
40047- 0 0 0 0 0 0 0 0 0 0 0 0
40048- 0 0 0 0 0 0 0 0 0 0 0 0
40049- 0 0 0 0 0 0 0 0 0 0 0 0
40050- 0 0 0 0 0 0 0 0 0 0 0 0
40051- 0 0 0 0 0 0 0 0 0 0 0 0
40052- 0 0 0 6 6 6 14 14 14 42 42 42
40053- 90 90 90 18 18 18 18 18 18 26 26 26
40054- 2 2 6 116 116 116 253 253 253 253 253 253
40055-253 253 253 253 253 253 253 253 253 253 253 253
40056-253 253 253 253 253 253 250 250 250 238 238 238
40057-253 253 253 253 253 253 253 253 253 253 253 253
40058-253 253 253 253 253 253 253 253 253 253 253 253
40059-253 253 253 253 253 253 253 253 253 253 253 253
40060-253 253 253 253 253 253 253 253 253 253 253 253
40061-253 253 253 253 253 253 94 94 94 6 6 6
40062- 2 2 6 2 2 6 10 10 10 34 34 34
40063- 2 2 6 2 2 6 2 2 6 2 2 6
40064- 74 74 74 58 58 58 22 22 22 6 6 6
40065- 0 0 0 0 0 0 0 0 0 0 0 0
40066- 0 0 0 0 0 0 0 0 0 0 0 0
40067- 0 0 0 0 0 0 0 0 0 0 0 0
40068- 0 0 0 0 0 0 0 0 0 0 0 0
40069- 0 0 0 0 0 0 0 0 0 0 0 0
40070- 0 0 0 0 0 0 0 0 0 0 0 0
40071- 0 0 0 0 0 0 0 0 0 0 0 0
40072- 0 0 0 10 10 10 26 26 26 66 66 66
40073- 82 82 82 2 2 6 38 38 38 6 6 6
40074- 14 14 14 210 210 210 253 253 253 253 253 253
40075-253 253 253 253 253 253 253 253 253 253 253 253
40076-253 253 253 253 253 253 246 246 246 242 242 242
40077-253 253 253 253 253 253 253 253 253 253 253 253
40078-253 253 253 253 253 253 253 253 253 253 253 253
40079-253 253 253 253 253 253 253 253 253 253 253 253
40080-253 253 253 253 253 253 253 253 253 253 253 253
40081-253 253 253 253 253 253 144 144 144 2 2 6
40082- 2 2 6 2 2 6 2 2 6 46 46 46
40083- 2 2 6 2 2 6 2 2 6 2 2 6
40084- 42 42 42 74 74 74 30 30 30 10 10 10
40085- 0 0 0 0 0 0 0 0 0 0 0 0
40086- 0 0 0 0 0 0 0 0 0 0 0 0
40087- 0 0 0 0 0 0 0 0 0 0 0 0
40088- 0 0 0 0 0 0 0 0 0 0 0 0
40089- 0 0 0 0 0 0 0 0 0 0 0 0
40090- 0 0 0 0 0 0 0 0 0 0 0 0
40091- 0 0 0 0 0 0 0 0 0 0 0 0
40092- 6 6 6 14 14 14 42 42 42 90 90 90
40093- 26 26 26 6 6 6 42 42 42 2 2 6
40094- 74 74 74 250 250 250 253 253 253 253 253 253
40095-253 253 253 253 253 253 253 253 253 253 253 253
40096-253 253 253 253 253 253 242 242 242 242 242 242
40097-253 253 253 253 253 253 253 253 253 253 253 253
40098-253 253 253 253 253 253 253 253 253 253 253 253
40099-253 253 253 253 253 253 253 253 253 253 253 253
40100-253 253 253 253 253 253 253 253 253 253 253 253
40101-253 253 253 253 253 253 182 182 182 2 2 6
40102- 2 2 6 2 2 6 2 2 6 46 46 46
40103- 2 2 6 2 2 6 2 2 6 2 2 6
40104- 10 10 10 86 86 86 38 38 38 10 10 10
40105- 0 0 0 0 0 0 0 0 0 0 0 0
40106- 0 0 0 0 0 0 0 0 0 0 0 0
40107- 0 0 0 0 0 0 0 0 0 0 0 0
40108- 0 0 0 0 0 0 0 0 0 0 0 0
40109- 0 0 0 0 0 0 0 0 0 0 0 0
40110- 0 0 0 0 0 0 0 0 0 0 0 0
40111- 0 0 0 0 0 0 0 0 0 0 0 0
40112- 10 10 10 26 26 26 66 66 66 82 82 82
40113- 2 2 6 22 22 22 18 18 18 2 2 6
40114-149 149 149 253 253 253 253 253 253 253 253 253
40115-253 253 253 253 253 253 253 253 253 253 253 253
40116-253 253 253 253 253 253 234 234 234 242 242 242
40117-253 253 253 253 253 253 253 253 253 253 253 253
40118-253 253 253 253 253 253 253 253 253 253 253 253
40119-253 253 253 253 253 253 253 253 253 253 253 253
40120-253 253 253 253 253 253 253 253 253 253 253 253
40121-253 253 253 253 253 253 206 206 206 2 2 6
40122- 2 2 6 2 2 6 2 2 6 38 38 38
40123- 2 2 6 2 2 6 2 2 6 2 2 6
40124- 6 6 6 86 86 86 46 46 46 14 14 14
40125- 0 0 0 0 0 0 0 0 0 0 0 0
40126- 0 0 0 0 0 0 0 0 0 0 0 0
40127- 0 0 0 0 0 0 0 0 0 0 0 0
40128- 0 0 0 0 0 0 0 0 0 0 0 0
40129- 0 0 0 0 0 0 0 0 0 0 0 0
40130- 0 0 0 0 0 0 0 0 0 0 0 0
40131- 0 0 0 0 0 0 0 0 0 6 6 6
40132- 18 18 18 46 46 46 86 86 86 18 18 18
40133- 2 2 6 34 34 34 10 10 10 6 6 6
40134-210 210 210 253 253 253 253 253 253 253 253 253
40135-253 253 253 253 253 253 253 253 253 253 253 253
40136-253 253 253 253 253 253 234 234 234 242 242 242
40137-253 253 253 253 253 253 253 253 253 253 253 253
40138-253 253 253 253 253 253 253 253 253 253 253 253
40139-253 253 253 253 253 253 253 253 253 253 253 253
40140-253 253 253 253 253 253 253 253 253 253 253 253
40141-253 253 253 253 253 253 221 221 221 6 6 6
40142- 2 2 6 2 2 6 6 6 6 30 30 30
40143- 2 2 6 2 2 6 2 2 6 2 2 6
40144- 2 2 6 82 82 82 54 54 54 18 18 18
40145- 6 6 6 0 0 0 0 0 0 0 0 0
40146- 0 0 0 0 0 0 0 0 0 0 0 0
40147- 0 0 0 0 0 0 0 0 0 0 0 0
40148- 0 0 0 0 0 0 0 0 0 0 0 0
40149- 0 0 0 0 0 0 0 0 0 0 0 0
40150- 0 0 0 0 0 0 0 0 0 0 0 0
40151- 0 0 0 0 0 0 0 0 0 10 10 10
40152- 26 26 26 66 66 66 62 62 62 2 2 6
40153- 2 2 6 38 38 38 10 10 10 26 26 26
40154-238 238 238 253 253 253 253 253 253 253 253 253
40155-253 253 253 253 253 253 253 253 253 253 253 253
40156-253 253 253 253 253 253 231 231 231 238 238 238
40157-253 253 253 253 253 253 253 253 253 253 253 253
40158-253 253 253 253 253 253 253 253 253 253 253 253
40159-253 253 253 253 253 253 253 253 253 253 253 253
40160-253 253 253 253 253 253 253 253 253 253 253 253
40161-253 253 253 253 253 253 231 231 231 6 6 6
40162- 2 2 6 2 2 6 10 10 10 30 30 30
40163- 2 2 6 2 2 6 2 2 6 2 2 6
40164- 2 2 6 66 66 66 58 58 58 22 22 22
40165- 6 6 6 0 0 0 0 0 0 0 0 0
40166- 0 0 0 0 0 0 0 0 0 0 0 0
40167- 0 0 0 0 0 0 0 0 0 0 0 0
40168- 0 0 0 0 0 0 0 0 0 0 0 0
40169- 0 0 0 0 0 0 0 0 0 0 0 0
40170- 0 0 0 0 0 0 0 0 0 0 0 0
40171- 0 0 0 0 0 0 0 0 0 10 10 10
40172- 38 38 38 78 78 78 6 6 6 2 2 6
40173- 2 2 6 46 46 46 14 14 14 42 42 42
40174-246 246 246 253 253 253 253 253 253 253 253 253
40175-253 253 253 253 253 253 253 253 253 253 253 253
40176-253 253 253 253 253 253 231 231 231 242 242 242
40177-253 253 253 253 253 253 253 253 253 253 253 253
40178-253 253 253 253 253 253 253 253 253 253 253 253
40179-253 253 253 253 253 253 253 253 253 253 253 253
40180-253 253 253 253 253 253 253 253 253 253 253 253
40181-253 253 253 253 253 253 234 234 234 10 10 10
40182- 2 2 6 2 2 6 22 22 22 14 14 14
40183- 2 2 6 2 2 6 2 2 6 2 2 6
40184- 2 2 6 66 66 66 62 62 62 22 22 22
40185- 6 6 6 0 0 0 0 0 0 0 0 0
40186- 0 0 0 0 0 0 0 0 0 0 0 0
40187- 0 0 0 0 0 0 0 0 0 0 0 0
40188- 0 0 0 0 0 0 0 0 0 0 0 0
40189- 0 0 0 0 0 0 0 0 0 0 0 0
40190- 0 0 0 0 0 0 0 0 0 0 0 0
40191- 0 0 0 0 0 0 6 6 6 18 18 18
40192- 50 50 50 74 74 74 2 2 6 2 2 6
40193- 14 14 14 70 70 70 34 34 34 62 62 62
40194-250 250 250 253 253 253 253 253 253 253 253 253
40195-253 253 253 253 253 253 253 253 253 253 253 253
40196-253 253 253 253 253 253 231 231 231 246 246 246
40197-253 253 253 253 253 253 253 253 253 253 253 253
40198-253 253 253 253 253 253 253 253 253 253 253 253
40199-253 253 253 253 253 253 253 253 253 253 253 253
40200-253 253 253 253 253 253 253 253 253 253 253 253
40201-253 253 253 253 253 253 234 234 234 14 14 14
40202- 2 2 6 2 2 6 30 30 30 2 2 6
40203- 2 2 6 2 2 6 2 2 6 2 2 6
40204- 2 2 6 66 66 66 62 62 62 22 22 22
40205- 6 6 6 0 0 0 0 0 0 0 0 0
40206- 0 0 0 0 0 0 0 0 0 0 0 0
40207- 0 0 0 0 0 0 0 0 0 0 0 0
40208- 0 0 0 0 0 0 0 0 0 0 0 0
40209- 0 0 0 0 0 0 0 0 0 0 0 0
40210- 0 0 0 0 0 0 0 0 0 0 0 0
40211- 0 0 0 0 0 0 6 6 6 18 18 18
40212- 54 54 54 62 62 62 2 2 6 2 2 6
40213- 2 2 6 30 30 30 46 46 46 70 70 70
40214-250 250 250 253 253 253 253 253 253 253 253 253
40215-253 253 253 253 253 253 253 253 253 253 253 253
40216-253 253 253 253 253 253 231 231 231 246 246 246
40217-253 253 253 253 253 253 253 253 253 253 253 253
40218-253 253 253 253 253 253 253 253 253 253 253 253
40219-253 253 253 253 253 253 253 253 253 253 253 253
40220-253 253 253 253 253 253 253 253 253 253 253 253
40221-253 253 253 253 253 253 226 226 226 10 10 10
40222- 2 2 6 6 6 6 30 30 30 2 2 6
40223- 2 2 6 2 2 6 2 2 6 2 2 6
40224- 2 2 6 66 66 66 58 58 58 22 22 22
40225- 6 6 6 0 0 0 0 0 0 0 0 0
40226- 0 0 0 0 0 0 0 0 0 0 0 0
40227- 0 0 0 0 0 0 0 0 0 0 0 0
40228- 0 0 0 0 0 0 0 0 0 0 0 0
40229- 0 0 0 0 0 0 0 0 0 0 0 0
40230- 0 0 0 0 0 0 0 0 0 0 0 0
40231- 0 0 0 0 0 0 6 6 6 22 22 22
40232- 58 58 58 62 62 62 2 2 6 2 2 6
40233- 2 2 6 2 2 6 30 30 30 78 78 78
40234-250 250 250 253 253 253 253 253 253 253 253 253
40235-253 253 253 253 253 253 253 253 253 253 253 253
40236-253 253 253 253 253 253 231 231 231 246 246 246
40237-253 253 253 253 253 253 253 253 253 253 253 253
40238-253 253 253 253 253 253 253 253 253 253 253 253
40239-253 253 253 253 253 253 253 253 253 253 253 253
40240-253 253 253 253 253 253 253 253 253 253 253 253
40241-253 253 253 253 253 253 206 206 206 2 2 6
40242- 22 22 22 34 34 34 18 14 6 22 22 22
40243- 26 26 26 18 18 18 6 6 6 2 2 6
40244- 2 2 6 82 82 82 54 54 54 18 18 18
40245- 6 6 6 0 0 0 0 0 0 0 0 0
40246- 0 0 0 0 0 0 0 0 0 0 0 0
40247- 0 0 0 0 0 0 0 0 0 0 0 0
40248- 0 0 0 0 0 0 0 0 0 0 0 0
40249- 0 0 0 0 0 0 0 0 0 0 0 0
40250- 0 0 0 0 0 0 0 0 0 0 0 0
40251- 0 0 0 0 0 0 6 6 6 26 26 26
40252- 62 62 62 106 106 106 74 54 14 185 133 11
40253-210 162 10 121 92 8 6 6 6 62 62 62
40254-238 238 238 253 253 253 253 253 253 253 253 253
40255-253 253 253 253 253 253 253 253 253 253 253 253
40256-253 253 253 253 253 253 231 231 231 246 246 246
40257-253 253 253 253 253 253 253 253 253 253 253 253
40258-253 253 253 253 253 253 253 253 253 253 253 253
40259-253 253 253 253 253 253 253 253 253 253 253 253
40260-253 253 253 253 253 253 253 253 253 253 253 253
40261-253 253 253 253 253 253 158 158 158 18 18 18
40262- 14 14 14 2 2 6 2 2 6 2 2 6
40263- 6 6 6 18 18 18 66 66 66 38 38 38
40264- 6 6 6 94 94 94 50 50 50 18 18 18
40265- 6 6 6 0 0 0 0 0 0 0 0 0
40266- 0 0 0 0 0 0 0 0 0 0 0 0
40267- 0 0 0 0 0 0 0 0 0 0 0 0
40268- 0 0 0 0 0 0 0 0 0 0 0 0
40269- 0 0 0 0 0 0 0 0 0 0 0 0
40270- 0 0 0 0 0 0 0 0 0 6 6 6
40271- 10 10 10 10 10 10 18 18 18 38 38 38
40272- 78 78 78 142 134 106 216 158 10 242 186 14
40273-246 190 14 246 190 14 156 118 10 10 10 10
40274- 90 90 90 238 238 238 253 253 253 253 253 253
40275-253 253 253 253 253 253 253 253 253 253 253 253
40276-253 253 253 253 253 253 231 231 231 250 250 250
40277-253 253 253 253 253 253 253 253 253 253 253 253
40278-253 253 253 253 253 253 253 253 253 253 253 253
40279-253 253 253 253 253 253 253 253 253 253 253 253
40280-253 253 253 253 253 253 253 253 253 246 230 190
40281-238 204 91 238 204 91 181 142 44 37 26 9
40282- 2 2 6 2 2 6 2 2 6 2 2 6
40283- 2 2 6 2 2 6 38 38 38 46 46 46
40284- 26 26 26 106 106 106 54 54 54 18 18 18
40285- 6 6 6 0 0 0 0 0 0 0 0 0
40286- 0 0 0 0 0 0 0 0 0 0 0 0
40287- 0 0 0 0 0 0 0 0 0 0 0 0
40288- 0 0 0 0 0 0 0 0 0 0 0 0
40289- 0 0 0 0 0 0 0 0 0 0 0 0
40290- 0 0 0 6 6 6 14 14 14 22 22 22
40291- 30 30 30 38 38 38 50 50 50 70 70 70
40292-106 106 106 190 142 34 226 170 11 242 186 14
40293-246 190 14 246 190 14 246 190 14 154 114 10
40294- 6 6 6 74 74 74 226 226 226 253 253 253
40295-253 253 253 253 253 253 253 253 253 253 253 253
40296-253 253 253 253 253 253 231 231 231 250 250 250
40297-253 253 253 253 253 253 253 253 253 253 253 253
40298-253 253 253 253 253 253 253 253 253 253 253 253
40299-253 253 253 253 253 253 253 253 253 253 253 253
40300-253 253 253 253 253 253 253 253 253 228 184 62
40301-241 196 14 241 208 19 232 195 16 38 30 10
40302- 2 2 6 2 2 6 2 2 6 2 2 6
40303- 2 2 6 6 6 6 30 30 30 26 26 26
40304-203 166 17 154 142 90 66 66 66 26 26 26
40305- 6 6 6 0 0 0 0 0 0 0 0 0
40306- 0 0 0 0 0 0 0 0 0 0 0 0
40307- 0 0 0 0 0 0 0 0 0 0 0 0
40308- 0 0 0 0 0 0 0 0 0 0 0 0
40309- 0 0 0 0 0 0 0 0 0 0 0 0
40310- 6 6 6 18 18 18 38 38 38 58 58 58
40311- 78 78 78 86 86 86 101 101 101 123 123 123
40312-175 146 61 210 150 10 234 174 13 246 186 14
40313-246 190 14 246 190 14 246 190 14 238 190 10
40314-102 78 10 2 2 6 46 46 46 198 198 198
40315-253 253 253 253 253 253 253 253 253 253 253 253
40316-253 253 253 253 253 253 234 234 234 242 242 242
40317-253 253 253 253 253 253 253 253 253 253 253 253
40318-253 253 253 253 253 253 253 253 253 253 253 253
40319-253 253 253 253 253 253 253 253 253 253 253 253
40320-253 253 253 253 253 253 253 253 253 224 178 62
40321-242 186 14 241 196 14 210 166 10 22 18 6
40322- 2 2 6 2 2 6 2 2 6 2 2 6
40323- 2 2 6 2 2 6 6 6 6 121 92 8
40324-238 202 15 232 195 16 82 82 82 34 34 34
40325- 10 10 10 0 0 0 0 0 0 0 0 0
40326- 0 0 0 0 0 0 0 0 0 0 0 0
40327- 0 0 0 0 0 0 0 0 0 0 0 0
40328- 0 0 0 0 0 0 0 0 0 0 0 0
40329- 0 0 0 0 0 0 0 0 0 0 0 0
40330- 14 14 14 38 38 38 70 70 70 154 122 46
40331-190 142 34 200 144 11 197 138 11 197 138 11
40332-213 154 11 226 170 11 242 186 14 246 190 14
40333-246 190 14 246 190 14 246 190 14 246 190 14
40334-225 175 15 46 32 6 2 2 6 22 22 22
40335-158 158 158 250 250 250 253 253 253 253 253 253
40336-253 253 253 253 253 253 253 253 253 253 253 253
40337-253 253 253 253 253 253 253 253 253 253 253 253
40338-253 253 253 253 253 253 253 253 253 253 253 253
40339-253 253 253 253 253 253 253 253 253 253 253 253
40340-253 253 253 250 250 250 242 242 242 224 178 62
40341-239 182 13 236 186 11 213 154 11 46 32 6
40342- 2 2 6 2 2 6 2 2 6 2 2 6
40343- 2 2 6 2 2 6 61 42 6 225 175 15
40344-238 190 10 236 186 11 112 100 78 42 42 42
40345- 14 14 14 0 0 0 0 0 0 0 0 0
40346- 0 0 0 0 0 0 0 0 0 0 0 0
40347- 0 0 0 0 0 0 0 0 0 0 0 0
40348- 0 0 0 0 0 0 0 0 0 0 0 0
40349- 0 0 0 0 0 0 0 0 0 6 6 6
40350- 22 22 22 54 54 54 154 122 46 213 154 11
40351-226 170 11 230 174 11 226 170 11 226 170 11
40352-236 178 12 242 186 14 246 190 14 246 190 14
40353-246 190 14 246 190 14 246 190 14 246 190 14
40354-241 196 14 184 144 12 10 10 10 2 2 6
40355- 6 6 6 116 116 116 242 242 242 253 253 253
40356-253 253 253 253 253 253 253 253 253 253 253 253
40357-253 253 253 253 253 253 253 253 253 253 253 253
40358-253 253 253 253 253 253 253 253 253 253 253 253
40359-253 253 253 253 253 253 253 253 253 253 253 253
40360-253 253 253 231 231 231 198 198 198 214 170 54
40361-236 178 12 236 178 12 210 150 10 137 92 6
40362- 18 14 6 2 2 6 2 2 6 2 2 6
40363- 6 6 6 70 47 6 200 144 11 236 178 12
40364-239 182 13 239 182 13 124 112 88 58 58 58
40365- 22 22 22 6 6 6 0 0 0 0 0 0
40366- 0 0 0 0 0 0 0 0 0 0 0 0
40367- 0 0 0 0 0 0 0 0 0 0 0 0
40368- 0 0 0 0 0 0 0 0 0 0 0 0
40369- 0 0 0 0 0 0 0 0 0 10 10 10
40370- 30 30 30 70 70 70 180 133 36 226 170 11
40371-239 182 13 242 186 14 242 186 14 246 186 14
40372-246 190 14 246 190 14 246 190 14 246 190 14
40373-246 190 14 246 190 14 246 190 14 246 190 14
40374-246 190 14 232 195 16 98 70 6 2 2 6
40375- 2 2 6 2 2 6 66 66 66 221 221 221
40376-253 253 253 253 253 253 253 253 253 253 253 253
40377-253 253 253 253 253 253 253 253 253 253 253 253
40378-253 253 253 253 253 253 253 253 253 253 253 253
40379-253 253 253 253 253 253 253 253 253 253 253 253
40380-253 253 253 206 206 206 198 198 198 214 166 58
40381-230 174 11 230 174 11 216 158 10 192 133 9
40382-163 110 8 116 81 8 102 78 10 116 81 8
40383-167 114 7 197 138 11 226 170 11 239 182 13
40384-242 186 14 242 186 14 162 146 94 78 78 78
40385- 34 34 34 14 14 14 6 6 6 0 0 0
40386- 0 0 0 0 0 0 0 0 0 0 0 0
40387- 0 0 0 0 0 0 0 0 0 0 0 0
40388- 0 0 0 0 0 0 0 0 0 0 0 0
40389- 0 0 0 0 0 0 0 0 0 6 6 6
40390- 30 30 30 78 78 78 190 142 34 226 170 11
40391-239 182 13 246 190 14 246 190 14 246 190 14
40392-246 190 14 246 190 14 246 190 14 246 190 14
40393-246 190 14 246 190 14 246 190 14 246 190 14
40394-246 190 14 241 196 14 203 166 17 22 18 6
40395- 2 2 6 2 2 6 2 2 6 38 38 38
40396-218 218 218 253 253 253 253 253 253 253 253 253
40397-253 253 253 253 253 253 253 253 253 253 253 253
40398-253 253 253 253 253 253 253 253 253 253 253 253
40399-253 253 253 253 253 253 253 253 253 253 253 253
40400-250 250 250 206 206 206 198 198 198 202 162 69
40401-226 170 11 236 178 12 224 166 10 210 150 10
40402-200 144 11 197 138 11 192 133 9 197 138 11
40403-210 150 10 226 170 11 242 186 14 246 190 14
40404-246 190 14 246 186 14 225 175 15 124 112 88
40405- 62 62 62 30 30 30 14 14 14 6 6 6
40406- 0 0 0 0 0 0 0 0 0 0 0 0
40407- 0 0 0 0 0 0 0 0 0 0 0 0
40408- 0 0 0 0 0 0 0 0 0 0 0 0
40409- 0 0 0 0 0 0 0 0 0 10 10 10
40410- 30 30 30 78 78 78 174 135 50 224 166 10
40411-239 182 13 246 190 14 246 190 14 246 190 14
40412-246 190 14 246 190 14 246 190 14 246 190 14
40413-246 190 14 246 190 14 246 190 14 246 190 14
40414-246 190 14 246 190 14 241 196 14 139 102 15
40415- 2 2 6 2 2 6 2 2 6 2 2 6
40416- 78 78 78 250 250 250 253 253 253 253 253 253
40417-253 253 253 253 253 253 253 253 253 253 253 253
40418-253 253 253 253 253 253 253 253 253 253 253 253
40419-253 253 253 253 253 253 253 253 253 253 253 253
40420-250 250 250 214 214 214 198 198 198 190 150 46
40421-219 162 10 236 178 12 234 174 13 224 166 10
40422-216 158 10 213 154 11 213 154 11 216 158 10
40423-226 170 11 239 182 13 246 190 14 246 190 14
40424-246 190 14 246 190 14 242 186 14 206 162 42
40425-101 101 101 58 58 58 30 30 30 14 14 14
40426- 6 6 6 0 0 0 0 0 0 0 0 0
40427- 0 0 0 0 0 0 0 0 0 0 0 0
40428- 0 0 0 0 0 0 0 0 0 0 0 0
40429- 0 0 0 0 0 0 0 0 0 10 10 10
40430- 30 30 30 74 74 74 174 135 50 216 158 10
40431-236 178 12 246 190 14 246 190 14 246 190 14
40432-246 190 14 246 190 14 246 190 14 246 190 14
40433-246 190 14 246 190 14 246 190 14 246 190 14
40434-246 190 14 246 190 14 241 196 14 226 184 13
40435- 61 42 6 2 2 6 2 2 6 2 2 6
40436- 22 22 22 238 238 238 253 253 253 253 253 253
40437-253 253 253 253 253 253 253 253 253 253 253 253
40438-253 253 253 253 253 253 253 253 253 253 253 253
40439-253 253 253 253 253 253 253 253 253 253 253 253
40440-253 253 253 226 226 226 187 187 187 180 133 36
40441-216 158 10 236 178 12 239 182 13 236 178 12
40442-230 174 11 226 170 11 226 170 11 230 174 11
40443-236 178 12 242 186 14 246 190 14 246 190 14
40444-246 190 14 246 190 14 246 186 14 239 182 13
40445-206 162 42 106 106 106 66 66 66 34 34 34
40446- 14 14 14 6 6 6 0 0 0 0 0 0
40447- 0 0 0 0 0 0 0 0 0 0 0 0
40448- 0 0 0 0 0 0 0 0 0 0 0 0
40449- 0 0 0 0 0 0 0 0 0 6 6 6
40450- 26 26 26 70 70 70 163 133 67 213 154 11
40451-236 178 12 246 190 14 246 190 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 241 196 14
40455-190 146 13 18 14 6 2 2 6 2 2 6
40456- 46 46 46 246 246 246 253 253 253 253 253 253
40457-253 253 253 253 253 253 253 253 253 253 253 253
40458-253 253 253 253 253 253 253 253 253 253 253 253
40459-253 253 253 253 253 253 253 253 253 253 253 253
40460-253 253 253 221 221 221 86 86 86 156 107 11
40461-216 158 10 236 178 12 242 186 14 246 186 14
40462-242 186 14 239 182 13 239 182 13 242 186 14
40463-242 186 14 246 186 14 246 190 14 246 190 14
40464-246 190 14 246 190 14 246 190 14 246 190 14
40465-242 186 14 225 175 15 142 122 72 66 66 66
40466- 30 30 30 10 10 10 0 0 0 0 0 0
40467- 0 0 0 0 0 0 0 0 0 0 0 0
40468- 0 0 0 0 0 0 0 0 0 0 0 0
40469- 0 0 0 0 0 0 0 0 0 6 6 6
40470- 26 26 26 70 70 70 163 133 67 210 150 10
40471-236 178 12 246 190 14 246 190 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-232 195 16 121 92 8 34 34 34 106 106 106
40476-221 221 221 253 253 253 253 253 253 253 253 253
40477-253 253 253 253 253 253 253 253 253 253 253 253
40478-253 253 253 253 253 253 253 253 253 253 253 253
40479-253 253 253 253 253 253 253 253 253 253 253 253
40480-242 242 242 82 82 82 18 14 6 163 110 8
40481-216 158 10 236 178 12 242 186 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-246 190 14 246 190 14 242 186 14 163 133 67
40486- 46 46 46 18 18 18 6 6 6 0 0 0
40487- 0 0 0 0 0 0 0 0 0 0 0 0
40488- 0 0 0 0 0 0 0 0 0 0 0 0
40489- 0 0 0 0 0 0 0 0 0 10 10 10
40490- 30 30 30 78 78 78 163 133 67 210 150 10
40491-236 178 12 246 186 14 246 190 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 246 190 14
40495-241 196 14 215 174 15 190 178 144 253 253 253
40496-253 253 253 253 253 253 253 253 253 253 253 253
40497-253 253 253 253 253 253 253 253 253 253 253 253
40498-253 253 253 253 253 253 253 253 253 253 253 253
40499-253 253 253 253 253 253 253 253 253 218 218 218
40500- 58 58 58 2 2 6 22 18 6 167 114 7
40501-216 158 10 236 178 12 246 186 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 190 14 246 186 14 242 186 14 190 150 46
40506- 54 54 54 22 22 22 6 6 6 0 0 0
40507- 0 0 0 0 0 0 0 0 0 0 0 0
40508- 0 0 0 0 0 0 0 0 0 0 0 0
40509- 0 0 0 0 0 0 0 0 0 14 14 14
40510- 38 38 38 86 86 86 180 133 36 213 154 11
40511-236 178 12 246 186 14 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 246 190 14 246 190 14 246 190 14
40515-246 190 14 232 195 16 190 146 13 214 214 214
40516-253 253 253 253 253 253 253 253 253 253 253 253
40517-253 253 253 253 253 253 253 253 253 253 253 253
40518-253 253 253 253 253 253 253 253 253 253 253 253
40519-253 253 253 250 250 250 170 170 170 26 26 26
40520- 2 2 6 2 2 6 37 26 9 163 110 8
40521-219 162 10 239 182 13 246 186 14 246 190 14
40522-246 190 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 186 14 236 178 12 224 166 10 142 122 72
40526- 46 46 46 18 18 18 6 6 6 0 0 0
40527- 0 0 0 0 0 0 0 0 0 0 0 0
40528- 0 0 0 0 0 0 0 0 0 0 0 0
40529- 0 0 0 0 0 0 6 6 6 18 18 18
40530- 50 50 50 109 106 95 192 133 9 224 166 10
40531-242 186 14 246 190 14 246 190 14 246 190 14
40532-246 190 14 246 190 14 246 190 14 246 190 14
40533-246 190 14 246 190 14 246 190 14 246 190 14
40534-246 190 14 246 190 14 246 190 14 246 190 14
40535-242 186 14 226 184 13 210 162 10 142 110 46
40536-226 226 226 253 253 253 253 253 253 253 253 253
40537-253 253 253 253 253 253 253 253 253 253 253 253
40538-253 253 253 253 253 253 253 253 253 253 253 253
40539-198 198 198 66 66 66 2 2 6 2 2 6
40540- 2 2 6 2 2 6 50 34 6 156 107 11
40541-219 162 10 239 182 13 246 186 14 246 190 14
40542-246 190 14 246 190 14 246 190 14 246 190 14
40543-246 190 14 246 190 14 246 190 14 246 190 14
40544-246 190 14 246 190 14 246 190 14 242 186 14
40545-234 174 13 213 154 11 154 122 46 66 66 66
40546- 30 30 30 10 10 10 0 0 0 0 0 0
40547- 0 0 0 0 0 0 0 0 0 0 0 0
40548- 0 0 0 0 0 0 0 0 0 0 0 0
40549- 0 0 0 0 0 0 6 6 6 22 22 22
40550- 58 58 58 154 121 60 206 145 10 234 174 13
40551-242 186 14 246 186 14 246 190 14 246 190 14
40552-246 190 14 246 190 14 246 190 14 246 190 14
40553-246 190 14 246 190 14 246 190 14 246 190 14
40554-246 190 14 246 190 14 246 190 14 246 190 14
40555-246 186 14 236 178 12 210 162 10 163 110 8
40556- 61 42 6 138 138 138 218 218 218 250 250 250
40557-253 253 253 253 253 253 253 253 253 250 250 250
40558-242 242 242 210 210 210 144 144 144 66 66 66
40559- 6 6 6 2 2 6 2 2 6 2 2 6
40560- 2 2 6 2 2 6 61 42 6 163 110 8
40561-216 158 10 236 178 12 246 190 14 246 190 14
40562-246 190 14 246 190 14 246 190 14 246 190 14
40563-246 190 14 246 190 14 246 190 14 246 190 14
40564-246 190 14 239 182 13 230 174 11 216 158 10
40565-190 142 34 124 112 88 70 70 70 38 38 38
40566- 18 18 18 6 6 6 0 0 0 0 0 0
40567- 0 0 0 0 0 0 0 0 0 0 0 0
40568- 0 0 0 0 0 0 0 0 0 0 0 0
40569- 0 0 0 0 0 0 6 6 6 22 22 22
40570- 62 62 62 168 124 44 206 145 10 224 166 10
40571-236 178 12 239 182 13 242 186 14 242 186 14
40572-246 186 14 246 190 14 246 190 14 246 190 14
40573-246 190 14 246 190 14 246 190 14 246 190 14
40574-246 190 14 246 190 14 246 190 14 246 190 14
40575-246 190 14 236 178 12 216 158 10 175 118 6
40576- 80 54 7 2 2 6 6 6 6 30 30 30
40577- 54 54 54 62 62 62 50 50 50 38 38 38
40578- 14 14 14 2 2 6 2 2 6 2 2 6
40579- 2 2 6 2 2 6 2 2 6 2 2 6
40580- 2 2 6 6 6 6 80 54 7 167 114 7
40581-213 154 11 236 178 12 246 190 14 246 190 14
40582-246 190 14 246 190 14 246 190 14 246 190 14
40583-246 190 14 242 186 14 239 182 13 239 182 13
40584-230 174 11 210 150 10 174 135 50 124 112 88
40585- 82 82 82 54 54 54 34 34 34 18 18 18
40586- 6 6 6 0 0 0 0 0 0 0 0 0
40587- 0 0 0 0 0 0 0 0 0 0 0 0
40588- 0 0 0 0 0 0 0 0 0 0 0 0
40589- 0 0 0 0 0 0 6 6 6 18 18 18
40590- 50 50 50 158 118 36 192 133 9 200 144 11
40591-216 158 10 219 162 10 224 166 10 226 170 11
40592-230 174 11 236 178 12 239 182 13 239 182 13
40593-242 186 14 246 186 14 246 190 14 246 190 14
40594-246 190 14 246 190 14 246 190 14 246 190 14
40595-246 186 14 230 174 11 210 150 10 163 110 8
40596-104 69 6 10 10 10 2 2 6 2 2 6
40597- 2 2 6 2 2 6 2 2 6 2 2 6
40598- 2 2 6 2 2 6 2 2 6 2 2 6
40599- 2 2 6 2 2 6 2 2 6 2 2 6
40600- 2 2 6 6 6 6 91 60 6 167 114 7
40601-206 145 10 230 174 11 242 186 14 246 190 14
40602-246 190 14 246 190 14 246 186 14 242 186 14
40603-239 182 13 230 174 11 224 166 10 213 154 11
40604-180 133 36 124 112 88 86 86 86 58 58 58
40605- 38 38 38 22 22 22 10 10 10 6 6 6
40606- 0 0 0 0 0 0 0 0 0 0 0 0
40607- 0 0 0 0 0 0 0 0 0 0 0 0
40608- 0 0 0 0 0 0 0 0 0 0 0 0
40609- 0 0 0 0 0 0 0 0 0 14 14 14
40610- 34 34 34 70 70 70 138 110 50 158 118 36
40611-167 114 7 180 123 7 192 133 9 197 138 11
40612-200 144 11 206 145 10 213 154 11 219 162 10
40613-224 166 10 230 174 11 239 182 13 242 186 14
40614-246 186 14 246 186 14 246 186 14 246 186 14
40615-239 182 13 216 158 10 185 133 11 152 99 6
40616-104 69 6 18 14 6 2 2 6 2 2 6
40617- 2 2 6 2 2 6 2 2 6 2 2 6
40618- 2 2 6 2 2 6 2 2 6 2 2 6
40619- 2 2 6 2 2 6 2 2 6 2 2 6
40620- 2 2 6 6 6 6 80 54 7 152 99 6
40621-192 133 9 219 162 10 236 178 12 239 182 13
40622-246 186 14 242 186 14 239 182 13 236 178 12
40623-224 166 10 206 145 10 192 133 9 154 121 60
40624- 94 94 94 62 62 62 42 42 42 22 22 22
40625- 14 14 14 6 6 6 0 0 0 0 0 0
40626- 0 0 0 0 0 0 0 0 0 0 0 0
40627- 0 0 0 0 0 0 0 0 0 0 0 0
40628- 0 0 0 0 0 0 0 0 0 0 0 0
40629- 0 0 0 0 0 0 0 0 0 6 6 6
40630- 18 18 18 34 34 34 58 58 58 78 78 78
40631-101 98 89 124 112 88 142 110 46 156 107 11
40632-163 110 8 167 114 7 175 118 6 180 123 7
40633-185 133 11 197 138 11 210 150 10 219 162 10
40634-226 170 11 236 178 12 236 178 12 234 174 13
40635-219 162 10 197 138 11 163 110 8 130 83 6
40636- 91 60 6 10 10 10 2 2 6 2 2 6
40637- 18 18 18 38 38 38 38 38 38 38 38 38
40638- 38 38 38 38 38 38 38 38 38 38 38 38
40639- 38 38 38 38 38 38 26 26 26 2 2 6
40640- 2 2 6 6 6 6 70 47 6 137 92 6
40641-175 118 6 200 144 11 219 162 10 230 174 11
40642-234 174 13 230 174 11 219 162 10 210 150 10
40643-192 133 9 163 110 8 124 112 88 82 82 82
40644- 50 50 50 30 30 30 14 14 14 6 6 6
40645- 0 0 0 0 0 0 0 0 0 0 0 0
40646- 0 0 0 0 0 0 0 0 0 0 0 0
40647- 0 0 0 0 0 0 0 0 0 0 0 0
40648- 0 0 0 0 0 0 0 0 0 0 0 0
40649- 0 0 0 0 0 0 0 0 0 0 0 0
40650- 6 6 6 14 14 14 22 22 22 34 34 34
40651- 42 42 42 58 58 58 74 74 74 86 86 86
40652-101 98 89 122 102 70 130 98 46 121 87 25
40653-137 92 6 152 99 6 163 110 8 180 123 7
40654-185 133 11 197 138 11 206 145 10 200 144 11
40655-180 123 7 156 107 11 130 83 6 104 69 6
40656- 50 34 6 54 54 54 110 110 110 101 98 89
40657- 86 86 86 82 82 82 78 78 78 78 78 78
40658- 78 78 78 78 78 78 78 78 78 78 78 78
40659- 78 78 78 82 82 82 86 86 86 94 94 94
40660-106 106 106 101 101 101 86 66 34 124 80 6
40661-156 107 11 180 123 7 192 133 9 200 144 11
40662-206 145 10 200 144 11 192 133 9 175 118 6
40663-139 102 15 109 106 95 70 70 70 42 42 42
40664- 22 22 22 10 10 10 0 0 0 0 0 0
40665- 0 0 0 0 0 0 0 0 0 0 0 0
40666- 0 0 0 0 0 0 0 0 0 0 0 0
40667- 0 0 0 0 0 0 0 0 0 0 0 0
40668- 0 0 0 0 0 0 0 0 0 0 0 0
40669- 0 0 0 0 0 0 0 0 0 0 0 0
40670- 0 0 0 0 0 0 6 6 6 10 10 10
40671- 14 14 14 22 22 22 30 30 30 38 38 38
40672- 50 50 50 62 62 62 74 74 74 90 90 90
40673-101 98 89 112 100 78 121 87 25 124 80 6
40674-137 92 6 152 99 6 152 99 6 152 99 6
40675-138 86 6 124 80 6 98 70 6 86 66 30
40676-101 98 89 82 82 82 58 58 58 46 46 46
40677- 38 38 38 34 34 34 34 34 34 34 34 34
40678- 34 34 34 34 34 34 34 34 34 34 34 34
40679- 34 34 34 34 34 34 38 38 38 42 42 42
40680- 54 54 54 82 82 82 94 86 76 91 60 6
40681-134 86 6 156 107 11 167 114 7 175 118 6
40682-175 118 6 167 114 7 152 99 6 121 87 25
40683-101 98 89 62 62 62 34 34 34 18 18 18
40684- 6 6 6 0 0 0 0 0 0 0 0 0
40685- 0 0 0 0 0 0 0 0 0 0 0 0
40686- 0 0 0 0 0 0 0 0 0 0 0 0
40687- 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0
40691- 0 0 0 6 6 6 6 6 6 10 10 10
40692- 18 18 18 22 22 22 30 30 30 42 42 42
40693- 50 50 50 66 66 66 86 86 86 101 98 89
40694-106 86 58 98 70 6 104 69 6 104 69 6
40695-104 69 6 91 60 6 82 62 34 90 90 90
40696- 62 62 62 38 38 38 22 22 22 14 14 14
40697- 10 10 10 10 10 10 10 10 10 10 10 10
40698- 10 10 10 10 10 10 6 6 6 10 10 10
40699- 10 10 10 10 10 10 10 10 10 14 14 14
40700- 22 22 22 42 42 42 70 70 70 89 81 66
40701- 80 54 7 104 69 6 124 80 6 137 92 6
40702-134 86 6 116 81 8 100 82 52 86 86 86
40703- 58 58 58 30 30 30 14 14 14 6 6 6
40704- 0 0 0 0 0 0 0 0 0 0 0 0
40705- 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0
40711- 0 0 0 0 0 0 0 0 0 0 0 0
40712- 0 0 0 6 6 6 10 10 10 14 14 14
40713- 18 18 18 26 26 26 38 38 38 54 54 54
40714- 70 70 70 86 86 86 94 86 76 89 81 66
40715- 89 81 66 86 86 86 74 74 74 50 50 50
40716- 30 30 30 14 14 14 6 6 6 0 0 0
40717- 0 0 0 0 0 0 0 0 0 0 0 0
40718- 0 0 0 0 0 0 0 0 0 0 0 0
40719- 0 0 0 0 0 0 0 0 0 0 0 0
40720- 6 6 6 18 18 18 34 34 34 58 58 58
40721- 82 82 82 89 81 66 89 81 66 89 81 66
40722- 94 86 66 94 86 76 74 74 74 50 50 50
40723- 26 26 26 14 14 14 6 6 6 0 0 0
40724- 0 0 0 0 0 0 0 0 0 0 0 0
40725- 0 0 0 0 0 0 0 0 0 0 0 0
40726- 0 0 0 0 0 0 0 0 0 0 0 0
40727- 0 0 0 0 0 0 0 0 0 0 0 0
40728- 0 0 0 0 0 0 0 0 0 0 0 0
40729- 0 0 0 0 0 0 0 0 0 0 0 0
40730- 0 0 0 0 0 0 0 0 0 0 0 0
40731- 0 0 0 0 0 0 0 0 0 0 0 0
40732- 0 0 0 0 0 0 0 0 0 0 0 0
40733- 6 6 6 6 6 6 14 14 14 18 18 18
40734- 30 30 30 38 38 38 46 46 46 54 54 54
40735- 50 50 50 42 42 42 30 30 30 18 18 18
40736- 10 10 10 0 0 0 0 0 0 0 0 0
40737- 0 0 0 0 0 0 0 0 0 0 0 0
40738- 0 0 0 0 0 0 0 0 0 0 0 0
40739- 0 0 0 0 0 0 0 0 0 0 0 0
40740- 0 0 0 6 6 6 14 14 14 26 26 26
40741- 38 38 38 50 50 50 58 58 58 58 58 58
40742- 54 54 54 42 42 42 30 30 30 18 18 18
40743- 10 10 10 0 0 0 0 0 0 0 0 0
40744- 0 0 0 0 0 0 0 0 0 0 0 0
40745- 0 0 0 0 0 0 0 0 0 0 0 0
40746- 0 0 0 0 0 0 0 0 0 0 0 0
40747- 0 0 0 0 0 0 0 0 0 0 0 0
40748- 0 0 0 0 0 0 0 0 0 0 0 0
40749- 0 0 0 0 0 0 0 0 0 0 0 0
40750- 0 0 0 0 0 0 0 0 0 0 0 0
40751- 0 0 0 0 0 0 0 0 0 0 0 0
40752- 0 0 0 0 0 0 0 0 0 0 0 0
40753- 0 0 0 0 0 0 0 0 0 6 6 6
40754- 6 6 6 10 10 10 14 14 14 18 18 18
40755- 18 18 18 14 14 14 10 10 10 6 6 6
40756- 0 0 0 0 0 0 0 0 0 0 0 0
40757- 0 0 0 0 0 0 0 0 0 0 0 0
40758- 0 0 0 0 0 0 0 0 0 0 0 0
40759- 0 0 0 0 0 0 0 0 0 0 0 0
40760- 0 0 0 0 0 0 0 0 0 6 6 6
40761- 14 14 14 18 18 18 22 22 22 22 22 22
40762- 18 18 18 14 14 14 10 10 10 6 6 6
40763- 0 0 0 0 0 0 0 0 0 0 0 0
40764- 0 0 0 0 0 0 0 0 0 0 0 0
40765- 0 0 0 0 0 0 0 0 0 0 0 0
40766- 0 0 0 0 0 0 0 0 0 0 0 0
40767- 0 0 0 0 0 0 0 0 0 0 0 0
40768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40772+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40774+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40775+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40780+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40781+4 4 4 4 4 4
40782+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 4 4 4 4 4 4 4 4 4 4 4 4
40788+4 4 4 4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
40807+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40808+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40809+4 4 4 4 4 4
40810+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 4 4 4 4 4 4
40812+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40813+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40814+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40815+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
40821+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40822+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40823+4 4 4 4 4 4
40824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40825+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40826+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40827+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40828+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40829+4 4 4 4 4 4 4 4 4 4 4 4 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+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40835+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40836+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40837+4 4 4 4 4 4
40838+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 4 4 4 4 4 4 4 4 4 4 4 4
40840+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40841+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40842+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40843+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
40848+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40849+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40850+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40851+4 4 4 4 4 4
40852+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40853+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40854+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40855+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40856+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
40857+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
40862+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40863+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
40864+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40865+4 4 4 4 4 4
40866+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40867+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40868+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40869+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40870+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
40871+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
40872+5 5 5 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 4 4 4
40875+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
40876+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
40877+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
40878+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40879+4 4 4 4 4 4
40880+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40881+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40882+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40883+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40884+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
40885+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
40886+0 0 0 3 3 3 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 4 4 4 4 4 4
40889+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
40890+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
40891+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
40892+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
40893+4 4 4 4 4 4
40894+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40895+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40896+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40897+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
40898+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
40899+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
40900+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 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 4 4 4 5 5 5 5 5 5
40903+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
40904+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
40905+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
40906+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
40907+4 4 4 4 4 4
40908+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40909+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40910+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40911+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
40912+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
40913+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
40914+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
40915+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40916+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
40917+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
40918+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
40919+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
40920+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
40921+4 4 4 4 4 4
40922+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40923+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40924+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40925+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
40926+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
40927+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
40928+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
40929+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
40930+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
40931+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
40932+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
40933+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
40934+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
40935+4 4 4 4 4 4
40936+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40937+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40938+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
40939+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
40940+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
40941+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
40942+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
40943+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
40944+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
40945+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
40946+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
40947+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
40948+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
40949+4 4 4 4 4 4
40950+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40951+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40952+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
40953+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
40954+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
40955+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
40956+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
40957+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
40958+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
40959+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
40960+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
40961+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
40962+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
40963+4 4 4 4 4 4
40964+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40965+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40966+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
40967+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
40968+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
40969+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
40970+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
40971+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
40972+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
40973+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
40974+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
40975+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
40976+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40977+4 4 4 4 4 4
40978+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40979+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40980+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
40981+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
40982+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
40983+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
40984+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
40985+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
40986+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
40987+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
40988+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
40989+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
40990+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
40991+4 4 4 4 4 4
40992+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40993+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
40994+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
40995+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
40996+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
40997+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
40998+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
40999+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
41000+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
41001+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
41002+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
41003+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
41004+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
41005+4 4 4 4 4 4
41006+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41007+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
41008+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
41009+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
41010+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41011+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
41012+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
41013+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
41014+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
41015+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
41016+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
41017+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
41018+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
41019+0 0 0 4 4 4
41020+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41021+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
41022+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
41023+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
41024+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
41025+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
41026+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
41027+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
41028+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
41029+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
41030+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
41031+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
41032+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
41033+2 0 0 0 0 0
41034+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
41035+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
41036+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
41037+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
41038+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
41039+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
41040+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
41041+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
41042+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
41043+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
41044+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
41045+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
41046+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
41047+37 38 37 0 0 0
41048+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41049+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
41050+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
41051+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
41052+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
41053+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
41054+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
41055+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
41056+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
41057+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
41058+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
41059+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
41060+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
41061+85 115 134 4 0 0
41062+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
41063+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
41064+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
41065+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
41066+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
41067+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
41068+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
41069+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
41070+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
41071+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
41072+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
41073+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
41074+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
41075+60 73 81 4 0 0
41076+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
41077+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
41078+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
41079+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
41080+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
41081+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41082+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41083+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41084+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41085+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41086+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41087+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41088+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41089+16 19 21 4 0 0
41090+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41091+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41092+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41093+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41094+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41095+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41096+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41097+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41098+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41099+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41100+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41101+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41102+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41103+4 0 0 4 3 3
41104+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41105+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41106+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41107+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41108+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41109+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41110+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41111+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41112+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41113+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41114+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41115+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41116+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41117+3 2 2 4 4 4
41118+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41119+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41120+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41121+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41122+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41123+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41124+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41125+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41126+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41127+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41128+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41129+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41130+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41131+4 4 4 4 4 4
41132+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41133+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41134+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41135+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41136+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41137+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41138+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41139+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41140+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41141+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41142+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41143+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41144+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41145+4 4 4 4 4 4
41146+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41147+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41148+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41149+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41150+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41151+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41152+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41153+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41154+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41155+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41156+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41157+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41158+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41159+5 5 5 5 5 5
41160+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41161+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41162+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41163+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41164+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41165+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41166+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41167+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41168+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41169+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41170+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41171+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41172+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41173+5 5 5 4 4 4
41174+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41175+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41176+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41177+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41178+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41179+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41180+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41181+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41182+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41183+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41184+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41185+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41186+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41187+4 4 4 4 4 4
41188+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41189+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41190+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41191+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41192+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41193+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41194+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41195+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41196+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41197+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41198+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41199+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
41200+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41201+4 4 4 4 4 4
41202+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
41203+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41204+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41205+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41206+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41207+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41208+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41209+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41210+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41211+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41212+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
41213+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41214+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41215+4 4 4 4 4 4
41216+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41217+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41218+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41219+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41220+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41221+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41222+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41223+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41224+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41225+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41226+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
41227+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41228+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41229+4 4 4 4 4 4
41230+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41231+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41232+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41233+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41234+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41235+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41236+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41237+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41238+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41239+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41240+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41241+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41242+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41243+4 4 4 4 4 4
41244+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41245+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
41246+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
41247+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
41248+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41249+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
41250+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
41251+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
41252+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
41253+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
41254+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
41255+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41256+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41257+4 4 4 4 4 4
41258+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
41259+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
41260+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
41261+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
41262+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41263+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
41264+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
41265+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
41266+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
41267+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
41268+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
41269+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41270+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41271+4 4 4 4 4 4
41272+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
41273+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
41274+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
41275+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41276+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
41277+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
41278+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
41279+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
41280+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
41281+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
41282+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41283+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41284+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41285+4 4 4 4 4 4
41286+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
41287+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
41288+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
41289+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41290+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41291+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
41292+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
41293+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
41294+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
41295+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
41296+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41297+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41298+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41299+4 4 4 4 4 4
41300+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
41301+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
41302+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41303+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41304+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41305+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
41306+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
41307+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
41308+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
41309+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
41310+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41311+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41312+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41313+4 4 4 4 4 4
41314+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41315+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41316+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41317+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41318+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41319+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41320+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41321+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41322+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41323+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41324+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41325+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41326+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41327+4 4 4 4 4 4
41328+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41329+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41330+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41331+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41332+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41333+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41334+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41335+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41336+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41337+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41338+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41339+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41340+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41341+4 4 4 4 4 4
41342+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41343+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41344+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41345+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41346+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41347+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41348+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41349+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41350+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41351+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41352+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41353+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41354+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41355+4 4 4 4 4 4
41356+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41357+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41358+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41359+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41360+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41361+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41362+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41363+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41364+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41365+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41366+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41367+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41368+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41369+4 4 4 4 4 4
41370+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41371+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41372+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41373+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41374+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41375+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41376+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41377+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41378+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41379+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41380+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41381+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41382+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41383+4 4 4 4 4 4
41384+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41385+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41386+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41387+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41388+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41389+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41390+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41391+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41392+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41393+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41394+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41395+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41396+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41397+4 4 4 4 4 4
41398+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41399+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41400+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41401+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41402+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41403+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41404+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41405+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41406+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41407+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41408+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41409+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41410+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41411+4 4 4 4 4 4
41412+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41413+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41414+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41415+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41416+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41417+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41418+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41419+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41420+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41421+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41422+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41423+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41424+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41425+4 4 4 4 4 4
41426+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41427+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41428+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41429+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41430+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41431+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41432+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41433+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41434+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41435+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41436+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41437+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41438+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41439+4 4 4 4 4 4
41440+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41441+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41442+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41443+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41444+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41445+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41446+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41447+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41448+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41449+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41450+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41451+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41452+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41453+4 4 4 4 4 4
41454+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41455+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41456+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41457+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41458+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41459+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41460+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41461+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41462+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41463+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41464+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41465+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41466+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41467+4 4 4 4 4 4
41468+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41469+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41470+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41471+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41472+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41473+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41474+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41475+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41476+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41477+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41478+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41479+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41480+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41481+4 4 4 4 4 4
41482+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41483+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41484+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41485+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41486+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41487+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41488+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41489+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41490+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41491+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41492+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41493+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41494+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41495+4 4 4 4 4 4
41496+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
41497+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
41498+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
41499+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
41500+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41501+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
41502+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
41503+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
41504+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
41505+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41506+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41507+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41508+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41509+4 4 4 4 4 4
41510+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41511+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
41512+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
41513+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
41514+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
41515+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
41516+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
41517+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
41518+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
41519+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41520+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41521+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41522+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41523+4 4 4 4 4 4
41524+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
41525+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
41526+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
41527+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
41528+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
41529+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
41530+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
41531+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
41532+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
41533+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
41534+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41535+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41536+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41537+4 4 4 4 4 4
41538+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
41539+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41540+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
41541+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
41542+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
41543+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
41544+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
41545+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
41546+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
41547+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
41548+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41549+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41550+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41551+4 4 4 4 4 4
41552+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
41553+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41554+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
41555+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
41556+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
41557+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
41558+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41559+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
41560+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
41561+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
41562+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41563+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41564+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41565+4 4 4 4 4 4
41566+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
41567+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
41568+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
41569+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
41570+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
41571+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
41572+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
41573+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
41574+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
41575+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
41576+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41577+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41578+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41579+4 4 4 4 4 4
41580+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
41581+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
41582+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41583+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
41584+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
41585+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
41586+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
41587+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
41588+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
41589+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
41590+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41591+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41592+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41593+4 4 4 4 4 4
41594+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41595+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
41596+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
41597+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
41598+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
41599+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
41600+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
41601+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
41602+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
41603+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41604+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41605+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41606+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41607+4 4 4 4 4 4
41608+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
41609+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
41610+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
41611+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
41612+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
41613+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
41614+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
41615+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
41616+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
41617+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41618+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41619+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41620+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41621+4 4 4 4 4 4
41622+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
41623+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
41624+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
41625+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
41626+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
41627+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
41628+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
41629+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
41630+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41631+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41632+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41633+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41634+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41635+4 4 4 4 4 4
41636+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
41637+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41638+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
41639+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41640+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
41641+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
41642+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
41643+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
41644+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
41645+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41646+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41647+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41648+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41649+4 4 4 4 4 4
41650+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
41651+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
41652+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
41653+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
41654+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
41655+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
41656+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
41657+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
41658+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
41659+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41660+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41661+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41662+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41663+4 4 4 4 4 4
41664+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41665+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
41666+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
41667+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
41668+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
41669+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
41670+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
41671+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
41672+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41676+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41677+4 4 4 4 4 4
41678+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
41679+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
41680+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41681+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
41682+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
41683+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
41684+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
41685+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
41686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41688+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41690+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41691+4 4 4 4 4 4
41692+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41693+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
41694+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
41695+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
41696+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
41697+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
41698+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
41699+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41702+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41704+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41705+4 4 4 4 4 4
41706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41707+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
41708+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41709+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
41710+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
41711+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
41712+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
41713+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
41714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41715+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41716+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41719+4 4 4 4 4 4
41720+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41721+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
41722+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
41723+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
41724+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
41725+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
41726+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
41727+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
41728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41730+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41733+4 4 4 4 4 4
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 5 5 5 5 5 5 5 5 5
41736+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
41737+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41738+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
41739+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
41740+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
41741+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41743+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41744+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41747+4 4 4 4 4 4
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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41751+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
41752+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
41753+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
41754+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
41755+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41757+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41758+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41761+4 4 4 4 4 4
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 5 5 5
41765+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41766+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
41767+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
41768+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
41769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41772+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41774+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41775+4 4 4 4 4 4
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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41780+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41781+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
41782+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
41783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41786+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41787+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41788+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41789+4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5 6 6 6
41794+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41795+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41796+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
41797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41798+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41799+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41800+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41801+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41802+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41803+4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5
41808+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
41809+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
41810+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4
41815+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
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 5 5 5
41822+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
41823+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41824+6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4
41829+4 4 4 4 4 4 4 4 4 4 4 4 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
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 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
41837+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
41838+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41839+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41840+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41841+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41842+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41843+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41844+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41845+4 4 4 4 4 4
41846+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41848+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41849+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41850+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
41851+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
41852+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41853+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41854+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41855+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41856+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41857+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41858+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41859+4 4 4 4 4 4
41860+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41862+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41863+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41864+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
41865+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
41866+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41867+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41868+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41869+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41870+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41871+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41872+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41873+4 4 4 4 4 4
41874+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41875+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41876+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41877+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41878+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41879+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
41880+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41881+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41882+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41883+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41884+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41885+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41886+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41887+4 4 4 4 4 4
41888diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
41889index 8af6414..658c030 100644
41890--- a/drivers/video/udlfb.c
41891+++ b/drivers/video/udlfb.c
41892@@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
41893 dlfb_urb_completion(urb);
41894
41895 error:
41896- atomic_add(bytes_sent, &dev->bytes_sent);
41897- atomic_add(bytes_identical, &dev->bytes_identical);
41898- atomic_add(width*height*2, &dev->bytes_rendered);
41899+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41900+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41901+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
41902 end_cycles = get_cycles();
41903- atomic_add(((unsigned int) ((end_cycles - start_cycles)
41904+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41905 >> 10)), /* Kcycles */
41906 &dev->cpu_kcycles_used);
41907
41908@@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
41909 dlfb_urb_completion(urb);
41910
41911 error:
41912- atomic_add(bytes_sent, &dev->bytes_sent);
41913- atomic_add(bytes_identical, &dev->bytes_identical);
41914- atomic_add(bytes_rendered, &dev->bytes_rendered);
41915+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41916+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41917+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
41918 end_cycles = get_cycles();
41919- atomic_add(((unsigned int) ((end_cycles - start_cycles)
41920+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41921 >> 10)), /* Kcycles */
41922 &dev->cpu_kcycles_used);
41923 }
41924@@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
41925 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41926 struct dlfb_data *dev = fb_info->par;
41927 return snprintf(buf, PAGE_SIZE, "%u\n",
41928- atomic_read(&dev->bytes_rendered));
41929+ atomic_read_unchecked(&dev->bytes_rendered));
41930 }
41931
41932 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41933@@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41934 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41935 struct dlfb_data *dev = fb_info->par;
41936 return snprintf(buf, PAGE_SIZE, "%u\n",
41937- atomic_read(&dev->bytes_identical));
41938+ atomic_read_unchecked(&dev->bytes_identical));
41939 }
41940
41941 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41942@@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41943 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41944 struct dlfb_data *dev = fb_info->par;
41945 return snprintf(buf, PAGE_SIZE, "%u\n",
41946- atomic_read(&dev->bytes_sent));
41947+ atomic_read_unchecked(&dev->bytes_sent));
41948 }
41949
41950 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41951@@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41952 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41953 struct dlfb_data *dev = fb_info->par;
41954 return snprintf(buf, PAGE_SIZE, "%u\n",
41955- atomic_read(&dev->cpu_kcycles_used));
41956+ atomic_read_unchecked(&dev->cpu_kcycles_used));
41957 }
41958
41959 static ssize_t edid_show(
41960@@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
41961 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41962 struct dlfb_data *dev = fb_info->par;
41963
41964- atomic_set(&dev->bytes_rendered, 0);
41965- atomic_set(&dev->bytes_identical, 0);
41966- atomic_set(&dev->bytes_sent, 0);
41967- atomic_set(&dev->cpu_kcycles_used, 0);
41968+ atomic_set_unchecked(&dev->bytes_rendered, 0);
41969+ atomic_set_unchecked(&dev->bytes_identical, 0);
41970+ atomic_set_unchecked(&dev->bytes_sent, 0);
41971+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
41972
41973 return count;
41974 }
41975diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
41976index b0e2a42..e2df3ad 100644
41977--- a/drivers/video/uvesafb.c
41978+++ b/drivers/video/uvesafb.c
41979@@ -19,6 +19,7 @@
41980 #include <linux/io.h>
41981 #include <linux/mutex.h>
41982 #include <linux/slab.h>
41983+#include <linux/moduleloader.h>
41984 #include <video/edid.h>
41985 #include <video/uvesafb.h>
41986 #ifdef CONFIG_X86
41987@@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
41988 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
41989 par->pmi_setpal = par->ypan = 0;
41990 } else {
41991+
41992+#ifdef CONFIG_PAX_KERNEXEC
41993+#ifdef CONFIG_MODULES
41994+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
41995+#endif
41996+ if (!par->pmi_code) {
41997+ par->pmi_setpal = par->ypan = 0;
41998+ return 0;
41999+ }
42000+#endif
42001+
42002 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
42003 + task->t.regs.edi);
42004+
42005+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42006+ pax_open_kernel();
42007+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
42008+ pax_close_kernel();
42009+
42010+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
42011+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
42012+#else
42013 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
42014 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
42015+#endif
42016+
42017 printk(KERN_INFO "uvesafb: protected mode interface info at "
42018 "%04x:%04x\n",
42019 (u16)task->t.regs.es, (u16)task->t.regs.edi);
42020@@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
42021 par->ypan = ypan;
42022
42023 if (par->pmi_setpal || par->ypan) {
42024+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
42025 if (__supported_pte_mask & _PAGE_NX) {
42026 par->pmi_setpal = par->ypan = 0;
42027 printk(KERN_WARNING "uvesafb: NX protection is actively."
42028 "We have better not to use the PMI.\n");
42029- } else {
42030+ } else
42031+#endif
42032 uvesafb_vbe_getpmi(task, par);
42033- }
42034 }
42035 #else
42036 /* The protected mode interface is not available on non-x86. */
42037@@ -1836,6 +1860,11 @@ out:
42038 if (par->vbe_modes)
42039 kfree(par->vbe_modes);
42040
42041+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42042+ if (par->pmi_code)
42043+ module_free_exec(NULL, par->pmi_code);
42044+#endif
42045+
42046 framebuffer_release(info);
42047 return err;
42048 }
42049@@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
42050 kfree(par->vbe_state_orig);
42051 if (par->vbe_state_saved)
42052 kfree(par->vbe_state_saved);
42053+
42054+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42055+ if (par->pmi_code)
42056+ module_free_exec(NULL, par->pmi_code);
42057+#endif
42058+
42059 }
42060
42061 framebuffer_release(info);
42062diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
42063index 501b340..86bd4cf 100644
42064--- a/drivers/video/vesafb.c
42065+++ b/drivers/video/vesafb.c
42066@@ -9,6 +9,7 @@
42067 */
42068
42069 #include <linux/module.h>
42070+#include <linux/moduleloader.h>
42071 #include <linux/kernel.h>
42072 #include <linux/errno.h>
42073 #include <linux/string.h>
42074@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
42075 static int vram_total __initdata; /* Set total amount of memory */
42076 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
42077 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
42078-static void (*pmi_start)(void) __read_mostly;
42079-static void (*pmi_pal) (void) __read_mostly;
42080+static void (*pmi_start)(void) __read_only;
42081+static void (*pmi_pal) (void) __read_only;
42082 static int depth __read_mostly;
42083 static int vga_compat __read_mostly;
42084 /* --------------------------------------------------------------------- */
42085@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
42086 unsigned int size_vmode;
42087 unsigned int size_remap;
42088 unsigned int size_total;
42089+ void *pmi_code = NULL;
42090
42091 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42092 return -ENODEV;
42093@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
42094 size_remap = size_total;
42095 vesafb_fix.smem_len = size_remap;
42096
42097-#ifndef __i386__
42098- screen_info.vesapm_seg = 0;
42099-#endif
42100-
42101 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42102 printk(KERN_WARNING
42103 "vesafb: cannot reserve video memory at 0x%lx\n",
42104@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42105 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42106 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42107
42108+#ifdef __i386__
42109+
42110+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42111+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
42112+ if (!pmi_code)
42113+#elif !defined(CONFIG_PAX_KERNEXEC)
42114+ if (0)
42115+#endif
42116+
42117+#endif
42118+ screen_info.vesapm_seg = 0;
42119+
42120 if (screen_info.vesapm_seg) {
42121- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42122- screen_info.vesapm_seg,screen_info.vesapm_off);
42123+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42124+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42125 }
42126
42127 if (screen_info.vesapm_seg < 0xc000)
42128@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42129
42130 if (ypan || pmi_setpal) {
42131 unsigned short *pmi_base;
42132+
42133 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42134- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42135- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42136+
42137+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42138+ pax_open_kernel();
42139+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42140+#else
42141+ pmi_code = pmi_base;
42142+#endif
42143+
42144+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42145+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42146+
42147+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42148+ pmi_start = ktva_ktla(pmi_start);
42149+ pmi_pal = ktva_ktla(pmi_pal);
42150+ pax_close_kernel();
42151+#endif
42152+
42153 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42154 if (pmi_base[3]) {
42155 printk(KERN_INFO "vesafb: pmi: ports = ");
42156@@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42157 info->node, info->fix.id);
42158 return 0;
42159 err:
42160+
42161+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42162+ module_free_exec(NULL, pmi_code);
42163+#endif
42164+
42165 if (info->screen_base)
42166 iounmap(info->screen_base);
42167 framebuffer_release(info);
42168diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42169index 88714ae..16c2e11 100644
42170--- a/drivers/video/via/via_clock.h
42171+++ b/drivers/video/via/via_clock.h
42172@@ -56,7 +56,7 @@ struct via_clock {
42173
42174 void (*set_engine_pll_state)(u8 state);
42175 void (*set_engine_pll)(struct via_pll_config config);
42176-};
42177+} __no_const;
42178
42179
42180 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42181diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
42182index e56c934..fc22f4b 100644
42183--- a/drivers/xen/xen-pciback/conf_space.h
42184+++ b/drivers/xen/xen-pciback/conf_space.h
42185@@ -44,15 +44,15 @@ struct config_field {
42186 struct {
42187 conf_dword_write write;
42188 conf_dword_read read;
42189- } dw;
42190+ } __no_const dw;
42191 struct {
42192 conf_word_write write;
42193 conf_word_read read;
42194- } w;
42195+ } __no_const w;
42196 struct {
42197 conf_byte_write write;
42198 conf_byte_read read;
42199- } b;
42200+ } __no_const b;
42201 } u;
42202 struct list_head list;
42203 };
42204diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
42205index 57ccb75..f6d05f8 100644
42206--- a/fs/9p/vfs_inode.c
42207+++ b/fs/9p/vfs_inode.c
42208@@ -1303,7 +1303,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42209 void
42210 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42211 {
42212- char *s = nd_get_link(nd);
42213+ const char *s = nd_get_link(nd);
42214
42215 p9_debug(P9_DEBUG_VFS, " %s %s\n",
42216 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
42217diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
42218index 0225742..1cd4732 100644
42219--- a/fs/Kconfig.binfmt
42220+++ b/fs/Kconfig.binfmt
42221@@ -89,7 +89,7 @@ config HAVE_AOUT
42222
42223 config BINFMT_AOUT
42224 tristate "Kernel support for a.out and ECOFF binaries"
42225- depends on HAVE_AOUT
42226+ depends on HAVE_AOUT && BROKEN
42227 ---help---
42228 A.out (Assembler.OUTput) is a set of formats for libraries and
42229 executables used in the earliest versions of UNIX. Linux used
42230diff --git a/fs/aio.c b/fs/aio.c
42231index 55c4c76..11aee6f 100644
42232--- a/fs/aio.c
42233+++ b/fs/aio.c
42234@@ -118,7 +118,7 @@ static int aio_setup_ring(struct kioctx *ctx)
42235 size += sizeof(struct io_event) * nr_events;
42236 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
42237
42238- if (nr_pages < 0)
42239+ if (nr_pages <= 0)
42240 return -EINVAL;
42241
42242 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
42243@@ -1440,18 +1440,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
42244 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42245 {
42246 ssize_t ret;
42247+ struct iovec iovstack;
42248
42249 #ifdef CONFIG_COMPAT
42250 if (compat)
42251 ret = compat_rw_copy_check_uvector(type,
42252 (struct compat_iovec __user *)kiocb->ki_buf,
42253- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42254+ kiocb->ki_nbytes, 1, &iovstack,
42255 &kiocb->ki_iovec);
42256 else
42257 #endif
42258 ret = rw_copy_check_uvector(type,
42259 (struct iovec __user *)kiocb->ki_buf,
42260- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42261+ kiocb->ki_nbytes, 1, &iovstack,
42262 &kiocb->ki_iovec);
42263 if (ret < 0)
42264 goto out;
42265@@ -1460,6 +1461,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42266 if (ret < 0)
42267 goto out;
42268
42269+ if (kiocb->ki_iovec == &iovstack) {
42270+ kiocb->ki_inline_vec = iovstack;
42271+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
42272+ }
42273 kiocb->ki_nr_segs = kiocb->ki_nbytes;
42274 kiocb->ki_cur_seg = 0;
42275 /* ki_nbytes/left now reflect bytes instead of segs */
42276diff --git a/fs/attr.c b/fs/attr.c
42277index 0da9095..1386693 100644
42278--- a/fs/attr.c
42279+++ b/fs/attr.c
42280@@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
42281 unsigned long limit;
42282
42283 limit = rlimit(RLIMIT_FSIZE);
42284+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
42285 if (limit != RLIM_INFINITY && offset > limit)
42286 goto out_sig;
42287 if (offset > inode->i_sb->s_maxbytes)
42288diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
42289index da8876d..9f3e6d8 100644
42290--- a/fs/autofs4/waitq.c
42291+++ b/fs/autofs4/waitq.c
42292@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
42293 {
42294 unsigned long sigpipe, flags;
42295 mm_segment_t fs;
42296- const char *data = (const char *)addr;
42297+ const char __user *data = (const char __force_user *)addr;
42298 ssize_t wr = 0;
42299
42300 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
42301diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
42302index e18da23..affc30e 100644
42303--- a/fs/befs/linuxvfs.c
42304+++ b/fs/befs/linuxvfs.c
42305@@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42306 {
42307 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
42308 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
42309- char *link = nd_get_link(nd);
42310+ const char *link = nd_get_link(nd);
42311 if (!IS_ERR(link))
42312 kfree(link);
42313 }
42314diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
42315index d146e18..12d1bd1 100644
42316--- a/fs/binfmt_aout.c
42317+++ b/fs/binfmt_aout.c
42318@@ -16,6 +16,7 @@
42319 #include <linux/string.h>
42320 #include <linux/fs.h>
42321 #include <linux/file.h>
42322+#include <linux/security.h>
42323 #include <linux/stat.h>
42324 #include <linux/fcntl.h>
42325 #include <linux/ptrace.h>
42326@@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42327 #endif
42328 # define START_STACK(u) ((void __user *)u.start_stack)
42329
42330+ memset(&dump, 0, sizeof(dump));
42331+
42332 fs = get_fs();
42333 set_fs(KERNEL_DS);
42334 has_dumped = 1;
42335@@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42336
42337 /* If the size of the dump file exceeds the rlimit, then see what would happen
42338 if we wrote the stack, but not the data area. */
42339+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42340 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42341 dump.u_dsize = 0;
42342
42343 /* Make sure we have enough room to write the stack and data areas. */
42344+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42345 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42346 dump.u_ssize = 0;
42347
42348@@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42349 rlim = rlimit(RLIMIT_DATA);
42350 if (rlim >= RLIM_INFINITY)
42351 rlim = ~0;
42352+
42353+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42354 if (ex.a_data + ex.a_bss > rlim)
42355 return -ENOMEM;
42356
42357@@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42358
42359 install_exec_creds(bprm);
42360
42361+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42362+ current->mm->pax_flags = 0UL;
42363+#endif
42364+
42365+#ifdef CONFIG_PAX_PAGEEXEC
42366+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42367+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42368+
42369+#ifdef CONFIG_PAX_EMUTRAMP
42370+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42371+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42372+#endif
42373+
42374+#ifdef CONFIG_PAX_MPROTECT
42375+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42376+ current->mm->pax_flags |= MF_PAX_MPROTECT;
42377+#endif
42378+
42379+ }
42380+#endif
42381+
42382 if (N_MAGIC(ex) == OMAGIC) {
42383 unsigned long text_addr, map_size;
42384 loff_t pos;
42385@@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42386 }
42387
42388 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42389- PROT_READ | PROT_WRITE | PROT_EXEC,
42390+ PROT_READ | PROT_WRITE,
42391 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42392 fd_offset + ex.a_text);
42393 if (error != N_DATADDR(ex)) {
42394diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42395index 1b52956..271266e 100644
42396--- a/fs/binfmt_elf.c
42397+++ b/fs/binfmt_elf.c
42398@@ -32,6 +32,7 @@
42399 #include <linux/elf.h>
42400 #include <linux/utsname.h>
42401 #include <linux/coredump.h>
42402+#include <linux/xattr.h>
42403 #include <asm/uaccess.h>
42404 #include <asm/param.h>
42405 #include <asm/page.h>
42406@@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42407 #define elf_core_dump NULL
42408 #endif
42409
42410+#ifdef CONFIG_PAX_MPROTECT
42411+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42412+#endif
42413+
42414 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42415 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42416 #else
42417@@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
42418 .load_binary = load_elf_binary,
42419 .load_shlib = load_elf_library,
42420 .core_dump = elf_core_dump,
42421+
42422+#ifdef CONFIG_PAX_MPROTECT
42423+ .handle_mprotect= elf_handle_mprotect,
42424+#endif
42425+
42426 .min_coredump = ELF_EXEC_PAGESIZE,
42427 };
42428
42429@@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
42430
42431 static int set_brk(unsigned long start, unsigned long end)
42432 {
42433+ unsigned long e = end;
42434+
42435 start = ELF_PAGEALIGN(start);
42436 end = ELF_PAGEALIGN(end);
42437 if (end > start) {
42438@@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
42439 if (BAD_ADDR(addr))
42440 return addr;
42441 }
42442- current->mm->start_brk = current->mm->brk = end;
42443+ current->mm->start_brk = current->mm->brk = e;
42444 return 0;
42445 }
42446
42447@@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42448 elf_addr_t __user *u_rand_bytes;
42449 const char *k_platform = ELF_PLATFORM;
42450 const char *k_base_platform = ELF_BASE_PLATFORM;
42451- unsigned char k_rand_bytes[16];
42452+ u32 k_rand_bytes[4];
42453 int items;
42454 elf_addr_t *elf_info;
42455 int ei_index = 0;
42456 const struct cred *cred = current_cred();
42457 struct vm_area_struct *vma;
42458+ unsigned long saved_auxv[AT_VECTOR_SIZE];
42459
42460 /*
42461 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42462@@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42463 * Generate 16 random bytes for userspace PRNG seeding.
42464 */
42465 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42466- u_rand_bytes = (elf_addr_t __user *)
42467- STACK_ALLOC(p, sizeof(k_rand_bytes));
42468+ srandom32(k_rand_bytes[0] ^ random32());
42469+ srandom32(k_rand_bytes[1] ^ random32());
42470+ srandom32(k_rand_bytes[2] ^ random32());
42471+ srandom32(k_rand_bytes[3] ^ random32());
42472+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
42473+ u_rand_bytes = (elf_addr_t __user *) p;
42474 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
42475 return -EFAULT;
42476
42477@@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42478 return -EFAULT;
42479 current->mm->env_end = p;
42480
42481+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
42482+
42483 /* Put the elf_info on the stack in the right place. */
42484 sp = (elf_addr_t __user *)envp + 1;
42485- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
42486+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
42487 return -EFAULT;
42488 return 0;
42489 }
42490@@ -378,10 +397,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42491 {
42492 struct elf_phdr *elf_phdata;
42493 struct elf_phdr *eppnt;
42494- unsigned long load_addr = 0;
42495+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
42496 int load_addr_set = 0;
42497 unsigned long last_bss = 0, elf_bss = 0;
42498- unsigned long error = ~0UL;
42499+ unsigned long error = -EINVAL;
42500 unsigned long total_size;
42501 int retval, i, size;
42502
42503@@ -427,6 +446,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42504 goto out_close;
42505 }
42506
42507+#ifdef CONFIG_PAX_SEGMEXEC
42508+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
42509+ pax_task_size = SEGMEXEC_TASK_SIZE;
42510+#endif
42511+
42512 eppnt = elf_phdata;
42513 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
42514 if (eppnt->p_type == PT_LOAD) {
42515@@ -470,8 +494,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42516 k = load_addr + eppnt->p_vaddr;
42517 if (BAD_ADDR(k) ||
42518 eppnt->p_filesz > eppnt->p_memsz ||
42519- eppnt->p_memsz > TASK_SIZE ||
42520- TASK_SIZE - eppnt->p_memsz < k) {
42521+ eppnt->p_memsz > pax_task_size ||
42522+ pax_task_size - eppnt->p_memsz < k) {
42523 error = -ENOMEM;
42524 goto out_close;
42525 }
42526@@ -523,6 +547,311 @@ out:
42527 return error;
42528 }
42529
42530+#ifdef CONFIG_PAX_PT_PAX_FLAGS
42531+#ifdef CONFIG_PAX_SOFTMODE
42532+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
42533+{
42534+ unsigned long pax_flags = 0UL;
42535+
42536+#ifdef CONFIG_PAX_PAGEEXEC
42537+ if (elf_phdata->p_flags & PF_PAGEEXEC)
42538+ pax_flags |= MF_PAX_PAGEEXEC;
42539+#endif
42540+
42541+#ifdef CONFIG_PAX_SEGMEXEC
42542+ if (elf_phdata->p_flags & PF_SEGMEXEC)
42543+ pax_flags |= MF_PAX_SEGMEXEC;
42544+#endif
42545+
42546+#ifdef CONFIG_PAX_EMUTRAMP
42547+ if (elf_phdata->p_flags & PF_EMUTRAMP)
42548+ pax_flags |= MF_PAX_EMUTRAMP;
42549+#endif
42550+
42551+#ifdef CONFIG_PAX_MPROTECT
42552+ if (elf_phdata->p_flags & PF_MPROTECT)
42553+ pax_flags |= MF_PAX_MPROTECT;
42554+#endif
42555+
42556+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42557+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
42558+ pax_flags |= MF_PAX_RANDMMAP;
42559+#endif
42560+
42561+ return pax_flags;
42562+}
42563+#endif
42564+
42565+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
42566+{
42567+ unsigned long pax_flags = 0UL;
42568+
42569+#ifdef CONFIG_PAX_PAGEEXEC
42570+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
42571+ pax_flags |= MF_PAX_PAGEEXEC;
42572+#endif
42573+
42574+#ifdef CONFIG_PAX_SEGMEXEC
42575+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
42576+ pax_flags |= MF_PAX_SEGMEXEC;
42577+#endif
42578+
42579+#ifdef CONFIG_PAX_EMUTRAMP
42580+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
42581+ pax_flags |= MF_PAX_EMUTRAMP;
42582+#endif
42583+
42584+#ifdef CONFIG_PAX_MPROTECT
42585+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
42586+ pax_flags |= MF_PAX_MPROTECT;
42587+#endif
42588+
42589+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42590+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
42591+ pax_flags |= MF_PAX_RANDMMAP;
42592+#endif
42593+
42594+ return pax_flags;
42595+}
42596+#endif
42597+
42598+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42599+#ifdef CONFIG_PAX_SOFTMODE
42600+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
42601+{
42602+ unsigned long pax_flags = 0UL;
42603+
42604+#ifdef CONFIG_PAX_PAGEEXEC
42605+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
42606+ pax_flags |= MF_PAX_PAGEEXEC;
42607+#endif
42608+
42609+#ifdef CONFIG_PAX_SEGMEXEC
42610+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
42611+ pax_flags |= MF_PAX_SEGMEXEC;
42612+#endif
42613+
42614+#ifdef CONFIG_PAX_EMUTRAMP
42615+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
42616+ pax_flags |= MF_PAX_EMUTRAMP;
42617+#endif
42618+
42619+#ifdef CONFIG_PAX_MPROTECT
42620+ if (pax_flags_softmode & MF_PAX_MPROTECT)
42621+ pax_flags |= MF_PAX_MPROTECT;
42622+#endif
42623+
42624+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42625+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
42626+ pax_flags |= MF_PAX_RANDMMAP;
42627+#endif
42628+
42629+ return pax_flags;
42630+}
42631+#endif
42632+
42633+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
42634+{
42635+ unsigned long pax_flags = 0UL;
42636+
42637+#ifdef CONFIG_PAX_PAGEEXEC
42638+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
42639+ pax_flags |= MF_PAX_PAGEEXEC;
42640+#endif
42641+
42642+#ifdef CONFIG_PAX_SEGMEXEC
42643+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
42644+ pax_flags |= MF_PAX_SEGMEXEC;
42645+#endif
42646+
42647+#ifdef CONFIG_PAX_EMUTRAMP
42648+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
42649+ pax_flags |= MF_PAX_EMUTRAMP;
42650+#endif
42651+
42652+#ifdef CONFIG_PAX_MPROTECT
42653+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
42654+ pax_flags |= MF_PAX_MPROTECT;
42655+#endif
42656+
42657+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42658+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
42659+ pax_flags |= MF_PAX_RANDMMAP;
42660+#endif
42661+
42662+ return pax_flags;
42663+}
42664+#endif
42665+
42666+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42667+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
42668+{
42669+ unsigned long pax_flags = 0UL;
42670+
42671+#ifdef CONFIG_PAX_EI_PAX
42672+
42673+#ifdef CONFIG_PAX_PAGEEXEC
42674+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
42675+ pax_flags |= MF_PAX_PAGEEXEC;
42676+#endif
42677+
42678+#ifdef CONFIG_PAX_SEGMEXEC
42679+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
42680+ pax_flags |= MF_PAX_SEGMEXEC;
42681+#endif
42682+
42683+#ifdef CONFIG_PAX_EMUTRAMP
42684+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
42685+ pax_flags |= MF_PAX_EMUTRAMP;
42686+#endif
42687+
42688+#ifdef CONFIG_PAX_MPROTECT
42689+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
42690+ pax_flags |= MF_PAX_MPROTECT;
42691+#endif
42692+
42693+#ifdef CONFIG_PAX_ASLR
42694+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
42695+ pax_flags |= MF_PAX_RANDMMAP;
42696+#endif
42697+
42698+#else
42699+
42700+#ifdef CONFIG_PAX_PAGEEXEC
42701+ pax_flags |= MF_PAX_PAGEEXEC;
42702+#endif
42703+
42704+#ifdef CONFIG_PAX_SEGMEXEC
42705+ pax_flags |= MF_PAX_SEGMEXEC;
42706+#endif
42707+
42708+#ifdef CONFIG_PAX_MPROTECT
42709+ pax_flags |= MF_PAX_MPROTECT;
42710+#endif
42711+
42712+#ifdef CONFIG_PAX_RANDMMAP
42713+ if (randomize_va_space)
42714+ pax_flags |= MF_PAX_RANDMMAP;
42715+#endif
42716+
42717+#endif
42718+
42719+ return pax_flags;
42720+}
42721+
42722+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
42723+{
42724+
42725+#ifdef CONFIG_PAX_PT_PAX_FLAGS
42726+ unsigned long i;
42727+
42728+ for (i = 0UL; i < elf_ex->e_phnum; i++)
42729+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
42730+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
42731+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
42732+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
42733+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
42734+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
42735+ return ~0UL;
42736+
42737+#ifdef CONFIG_PAX_SOFTMODE
42738+ if (pax_softmode)
42739+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
42740+ else
42741+#endif
42742+
42743+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
42744+ break;
42745+ }
42746+#endif
42747+
42748+ return ~0UL;
42749+}
42750+
42751+static unsigned long pax_parse_xattr_pax(struct file * const file)
42752+{
42753+
42754+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42755+ ssize_t xattr_size, i;
42756+ unsigned char xattr_value[5];
42757+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
42758+
42759+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
42760+ if (xattr_size <= 0)
42761+ return ~0UL;
42762+
42763+ for (i = 0; i < xattr_size; i++)
42764+ switch (xattr_value[i]) {
42765+ default:
42766+ return ~0UL;
42767+
42768+#define parse_flag(option1, option2, flag) \
42769+ case option1: \
42770+ pax_flags_hardmode |= MF_PAX_##flag; \
42771+ break; \
42772+ case option2: \
42773+ pax_flags_softmode |= MF_PAX_##flag; \
42774+ break;
42775+
42776+ parse_flag('p', 'P', PAGEEXEC);
42777+ parse_flag('e', 'E', EMUTRAMP);
42778+ parse_flag('m', 'M', MPROTECT);
42779+ parse_flag('r', 'R', RANDMMAP);
42780+ parse_flag('s', 'S', SEGMEXEC);
42781+
42782+#undef parse_flag
42783+ }
42784+
42785+ if (pax_flags_hardmode & pax_flags_softmode)
42786+ return ~0UL;
42787+
42788+#ifdef CONFIG_PAX_SOFTMODE
42789+ if (pax_softmode)
42790+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
42791+ else
42792+#endif
42793+
42794+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
42795+#else
42796+ return ~0UL;
42797+#endif
42798+
42799+}
42800+
42801+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
42802+{
42803+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
42804+
42805+ pax_flags = pax_parse_ei_pax(elf_ex);
42806+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
42807+ xattr_pax_flags = pax_parse_xattr_pax(file);
42808+
42809+ if (pt_pax_flags == ~0UL)
42810+ pt_pax_flags = xattr_pax_flags;
42811+ else if (xattr_pax_flags == ~0UL)
42812+ xattr_pax_flags = pt_pax_flags;
42813+ if (pt_pax_flags != xattr_pax_flags)
42814+ return -EINVAL;
42815+ if (pt_pax_flags != ~0UL)
42816+ pax_flags = pt_pax_flags;
42817+
42818+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42819+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42820+ if ((__supported_pte_mask & _PAGE_NX))
42821+ pax_flags &= ~MF_PAX_SEGMEXEC;
42822+ else
42823+ pax_flags &= ~MF_PAX_PAGEEXEC;
42824+ }
42825+#endif
42826+
42827+ if (0 > pax_check_flags(&pax_flags))
42828+ return -EINVAL;
42829+
42830+ current->mm->pax_flags = pax_flags;
42831+ return 0;
42832+}
42833+#endif
42834+
42835 /*
42836 * These are the functions used to load ELF style executables and shared
42837 * libraries. There is no binary dependent code anywhere else.
42838@@ -539,6 +868,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
42839 {
42840 unsigned int random_variable = 0;
42841
42842+#ifdef CONFIG_PAX_RANDUSTACK
42843+ if (randomize_va_space)
42844+ return stack_top - current->mm->delta_stack;
42845+#endif
42846+
42847 if ((current->flags & PF_RANDOMIZE) &&
42848 !(current->personality & ADDR_NO_RANDOMIZE)) {
42849 random_variable = get_random_int() & STACK_RND_MASK;
42850@@ -557,7 +891,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42851 unsigned long load_addr = 0, load_bias = 0;
42852 int load_addr_set = 0;
42853 char * elf_interpreter = NULL;
42854- unsigned long error;
42855+ unsigned long error = 0;
42856 struct elf_phdr *elf_ppnt, *elf_phdata;
42857 unsigned long elf_bss, elf_brk;
42858 int retval, i;
42859@@ -567,11 +901,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42860 unsigned long start_code, end_code, start_data, end_data;
42861 unsigned long reloc_func_desc __maybe_unused = 0;
42862 int executable_stack = EXSTACK_DEFAULT;
42863- unsigned long def_flags = 0;
42864 struct {
42865 struct elfhdr elf_ex;
42866 struct elfhdr interp_elf_ex;
42867 } *loc;
42868+ unsigned long pax_task_size = TASK_SIZE;
42869
42870 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
42871 if (!loc) {
42872@@ -707,11 +1041,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42873 goto out_free_dentry;
42874
42875 /* OK, This is the point of no return */
42876- current->mm->def_flags = def_flags;
42877+
42878+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42879+ current->mm->pax_flags = 0UL;
42880+#endif
42881+
42882+#ifdef CONFIG_PAX_DLRESOLVE
42883+ current->mm->call_dl_resolve = 0UL;
42884+#endif
42885+
42886+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
42887+ current->mm->call_syscall = 0UL;
42888+#endif
42889+
42890+#ifdef CONFIG_PAX_ASLR
42891+ current->mm->delta_mmap = 0UL;
42892+ current->mm->delta_stack = 0UL;
42893+#endif
42894+
42895+ current->mm->def_flags = 0;
42896+
42897+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42898+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
42899+ send_sig(SIGKILL, current, 0);
42900+ goto out_free_dentry;
42901+ }
42902+#endif
42903+
42904+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
42905+ pax_set_initial_flags(bprm);
42906+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
42907+ if (pax_set_initial_flags_func)
42908+ (pax_set_initial_flags_func)(bprm);
42909+#endif
42910+
42911+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
42912+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
42913+ current->mm->context.user_cs_limit = PAGE_SIZE;
42914+ current->mm->def_flags |= VM_PAGEEXEC;
42915+ }
42916+#endif
42917+
42918+#ifdef CONFIG_PAX_SEGMEXEC
42919+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
42920+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
42921+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
42922+ pax_task_size = SEGMEXEC_TASK_SIZE;
42923+ current->mm->def_flags |= VM_NOHUGEPAGE;
42924+ }
42925+#endif
42926+
42927+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
42928+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42929+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
42930+ put_cpu();
42931+ }
42932+#endif
42933
42934 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
42935 may depend on the personality. */
42936 SET_PERSONALITY(loc->elf_ex);
42937+
42938+#ifdef CONFIG_PAX_ASLR
42939+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42940+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
42941+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
42942+ }
42943+#endif
42944+
42945+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
42946+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42947+ executable_stack = EXSTACK_DISABLE_X;
42948+ current->personality &= ~READ_IMPLIES_EXEC;
42949+ } else
42950+#endif
42951+
42952 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
42953 current->personality |= READ_IMPLIES_EXEC;
42954
42955@@ -802,6 +1206,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42956 #else
42957 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
42958 #endif
42959+
42960+#ifdef CONFIG_PAX_RANDMMAP
42961+ /* PaX: randomize base address at the default exe base if requested */
42962+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
42963+#ifdef CONFIG_SPARC64
42964+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
42965+#else
42966+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
42967+#endif
42968+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
42969+ elf_flags |= MAP_FIXED;
42970+ }
42971+#endif
42972+
42973 }
42974
42975 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
42976@@ -834,9 +1252,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42977 * allowed task size. Note that p_filesz must always be
42978 * <= p_memsz so it is only necessary to check p_memsz.
42979 */
42980- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42981- elf_ppnt->p_memsz > TASK_SIZE ||
42982- TASK_SIZE - elf_ppnt->p_memsz < k) {
42983+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42984+ elf_ppnt->p_memsz > pax_task_size ||
42985+ pax_task_size - elf_ppnt->p_memsz < k) {
42986 /* set_brk can never work. Avoid overflows. */
42987 send_sig(SIGKILL, current, 0);
42988 retval = -EINVAL;
42989@@ -875,11 +1293,41 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42990 goto out_free_dentry;
42991 }
42992 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
42993- send_sig(SIGSEGV, current, 0);
42994- retval = -EFAULT; /* Nobody gets to see this, but.. */
42995- goto out_free_dentry;
42996+ /*
42997+ * This bss-zeroing can fail if the ELF
42998+ * file specifies odd protections. So
42999+ * we don't check the return value
43000+ */
43001 }
43002
43003+#ifdef CONFIG_PAX_RANDMMAP
43004+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43005+ unsigned long start, size;
43006+
43007+ start = ELF_PAGEALIGN(elf_brk);
43008+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
43009+ down_read(&current->mm->mmap_sem);
43010+ retval = -ENOMEM;
43011+ if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
43012+ unsigned long prot = PROT_NONE;
43013+
43014+ up_read(&current->mm->mmap_sem);
43015+ current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
43016+// if (current->personality & ADDR_NO_RANDOMIZE)
43017+// prot = PROT_READ;
43018+ start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
43019+ retval = IS_ERR_VALUE(start) ? start : 0;
43020+ } else
43021+ up_read(&current->mm->mmap_sem);
43022+ if (retval == 0)
43023+ retval = set_brk(start + size, start + size + PAGE_SIZE);
43024+ if (retval < 0) {
43025+ send_sig(SIGKILL, current, 0);
43026+ goto out_free_dentry;
43027+ }
43028+ }
43029+#endif
43030+
43031 if (elf_interpreter) {
43032 unsigned long uninitialized_var(interp_map_addr);
43033
43034@@ -1107,7 +1555,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
43035 * Decide what to dump of a segment, part, all or none.
43036 */
43037 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43038- unsigned long mm_flags)
43039+ unsigned long mm_flags, long signr)
43040 {
43041 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43042
43043@@ -1144,7 +1592,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
43044 if (vma->vm_file == NULL)
43045 return 0;
43046
43047- if (FILTER(MAPPED_PRIVATE))
43048+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43049 goto whole;
43050
43051 /*
43052@@ -1366,9 +1814,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
43053 {
43054 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
43055 int i = 0;
43056- do
43057+ do {
43058 i += 2;
43059- while (auxv[i - 2] != AT_NULL);
43060+ } while (auxv[i - 2] != AT_NULL);
43061 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43062 }
43063
43064@@ -1890,14 +2338,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
43065 }
43066
43067 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43068- unsigned long mm_flags)
43069+ struct coredump_params *cprm)
43070 {
43071 struct vm_area_struct *vma;
43072 size_t size = 0;
43073
43074 for (vma = first_vma(current, gate_vma); vma != NULL;
43075 vma = next_vma(vma, gate_vma))
43076- size += vma_dump_size(vma, mm_flags);
43077+ size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43078 return size;
43079 }
43080
43081@@ -1991,7 +2439,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43082
43083 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43084
43085- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43086+ offset += elf_core_vma_data_size(gate_vma, cprm);
43087 offset += elf_core_extra_data_size();
43088 e_shoff = offset;
43089
43090@@ -2005,10 +2453,12 @@ static int elf_core_dump(struct coredump_params *cprm)
43091 offset = dataoff;
43092
43093 size += sizeof(*elf);
43094+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43095 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43096 goto end_coredump;
43097
43098 size += sizeof(*phdr4note);
43099+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43100 if (size > cprm->limit
43101 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43102 goto end_coredump;
43103@@ -2022,7 +2472,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43104 phdr.p_offset = offset;
43105 phdr.p_vaddr = vma->vm_start;
43106 phdr.p_paddr = 0;
43107- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43108+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43109 phdr.p_memsz = vma->vm_end - vma->vm_start;
43110 offset += phdr.p_filesz;
43111 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43112@@ -2033,6 +2483,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43113 phdr.p_align = ELF_EXEC_PAGESIZE;
43114
43115 size += sizeof(phdr);
43116+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43117 if (size > cprm->limit
43118 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
43119 goto end_coredump;
43120@@ -2057,7 +2508,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43121 unsigned long addr;
43122 unsigned long end;
43123
43124- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
43125+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43126
43127 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43128 struct page *page;
43129@@ -2066,6 +2517,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43130 page = get_dump_page(addr);
43131 if (page) {
43132 void *kaddr = kmap(page);
43133+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43134 stop = ((size += PAGE_SIZE) > cprm->limit) ||
43135 !dump_write(cprm->file, kaddr,
43136 PAGE_SIZE);
43137@@ -2083,6 +2535,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43138
43139 if (e_phnum == PN_XNUM) {
43140 size += sizeof(*shdr4extnum);
43141+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43142 if (size > cprm->limit
43143 || !dump_write(cprm->file, shdr4extnum,
43144 sizeof(*shdr4extnum)))
43145@@ -2103,6 +2556,97 @@ out:
43146
43147 #endif /* CONFIG_ELF_CORE */
43148
43149+#ifdef CONFIG_PAX_MPROTECT
43150+/* PaX: non-PIC ELF libraries need relocations on their executable segments
43151+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43152+ * we'll remove VM_MAYWRITE for good on RELRO segments.
43153+ *
43154+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43155+ * basis because we want to allow the common case and not the special ones.
43156+ */
43157+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43158+{
43159+ struct elfhdr elf_h;
43160+ struct elf_phdr elf_p;
43161+ unsigned long i;
43162+ unsigned long oldflags;
43163+ bool is_textrel_rw, is_textrel_rx, is_relro;
43164+
43165+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
43166+ return;
43167+
43168+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
43169+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
43170+
43171+#ifdef CONFIG_PAX_ELFRELOCS
43172+ /* possible TEXTREL */
43173+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
43174+ 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);
43175+#else
43176+ is_textrel_rw = false;
43177+ is_textrel_rx = false;
43178+#endif
43179+
43180+ /* possible RELRO */
43181+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
43182+
43183+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
43184+ return;
43185+
43186+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
43187+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
43188+
43189+#ifdef CONFIG_PAX_ETEXECRELOCS
43190+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43191+#else
43192+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
43193+#endif
43194+
43195+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43196+ !elf_check_arch(&elf_h) ||
43197+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
43198+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
43199+ return;
43200+
43201+ for (i = 0UL; i < elf_h.e_phnum; i++) {
43202+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
43203+ return;
43204+ switch (elf_p.p_type) {
43205+ case PT_DYNAMIC:
43206+ if (!is_textrel_rw && !is_textrel_rx)
43207+ continue;
43208+ i = 0UL;
43209+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
43210+ elf_dyn dyn;
43211+
43212+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
43213+ return;
43214+ if (dyn.d_tag == DT_NULL)
43215+ return;
43216+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
43217+ gr_log_textrel(vma);
43218+ if (is_textrel_rw)
43219+ vma->vm_flags |= VM_MAYWRITE;
43220+ else
43221+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
43222+ vma->vm_flags &= ~VM_MAYWRITE;
43223+ return;
43224+ }
43225+ i++;
43226+ }
43227+ return;
43228+
43229+ case PT_GNU_RELRO:
43230+ if (!is_relro)
43231+ continue;
43232+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
43233+ vma->vm_flags &= ~VM_MAYWRITE;
43234+ return;
43235+ }
43236+ }
43237+}
43238+#endif
43239+
43240 static int __init init_elf_binfmt(void)
43241 {
43242 register_binfmt(&elf_format);
43243diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
43244index 178cb70..8972997 100644
43245--- a/fs/binfmt_flat.c
43246+++ b/fs/binfmt_flat.c
43247@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
43248 realdatastart = (unsigned long) -ENOMEM;
43249 printk("Unable to allocate RAM for process data, errno %d\n",
43250 (int)-realdatastart);
43251+ down_write(&current->mm->mmap_sem);
43252 vm_munmap(textpos, text_len);
43253+ up_write(&current->mm->mmap_sem);
43254 ret = realdatastart;
43255 goto err;
43256 }
43257@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43258 }
43259 if (IS_ERR_VALUE(result)) {
43260 printk("Unable to read data+bss, errno %d\n", (int)-result);
43261+ down_write(&current->mm->mmap_sem);
43262 vm_munmap(textpos, text_len);
43263 vm_munmap(realdatastart, len);
43264+ up_write(&current->mm->mmap_sem);
43265 ret = result;
43266 goto err;
43267 }
43268@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43269 }
43270 if (IS_ERR_VALUE(result)) {
43271 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
43272+ down_write(&current->mm->mmap_sem);
43273 vm_munmap(textpos, text_len + data_len + extra +
43274 MAX_SHARED_LIBS * sizeof(unsigned long));
43275+ up_write(&current->mm->mmap_sem);
43276 ret = result;
43277 goto err;
43278 }
43279diff --git a/fs/bio.c b/fs/bio.c
43280index 73922ab..16642dd 100644
43281--- a/fs/bio.c
43282+++ b/fs/bio.c
43283@@ -841,7 +841,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
43284 /*
43285 * Overflow, abort
43286 */
43287- if (end < start)
43288+ if (end < start || end - start > INT_MAX - nr_pages)
43289 return ERR_PTR(-EINVAL);
43290
43291 nr_pages += end - start;
43292@@ -975,7 +975,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
43293 /*
43294 * Overflow, abort
43295 */
43296- if (end < start)
43297+ if (end < start || end - start > INT_MAX - nr_pages)
43298 return ERR_PTR(-EINVAL);
43299
43300 nr_pages += end - start;
43301@@ -1237,7 +1237,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43302 const int read = bio_data_dir(bio) == READ;
43303 struct bio_map_data *bmd = bio->bi_private;
43304 int i;
43305- char *p = bmd->sgvecs[0].iov_base;
43306+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43307
43308 __bio_for_each_segment(bvec, bio, i, 0) {
43309 char *addr = page_address(bvec->bv_page);
43310diff --git a/fs/block_dev.c b/fs/block_dev.c
43311index c2bbe1f..9dfbc23 100644
43312--- a/fs/block_dev.c
43313+++ b/fs/block_dev.c
43314@@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43315 else if (bdev->bd_contains == bdev)
43316 return true; /* is a whole device which isn't held */
43317
43318- else if (whole->bd_holder == bd_may_claim)
43319+ else if (whole->bd_holder == (void *)bd_may_claim)
43320 return true; /* is a partition of a device that is being partitioned */
43321 else if (whole->bd_holder != NULL)
43322 return false; /* is a partition of a held device */
43323diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
43324index da6e936..1598dd0 100644
43325--- a/fs/btrfs/check-integrity.c
43326+++ b/fs/btrfs/check-integrity.c
43327@@ -155,7 +155,7 @@ struct btrfsic_block {
43328 union {
43329 bio_end_io_t *bio;
43330 bh_end_io_t *bh;
43331- } orig_bio_bh_end_io;
43332+ } __no_const orig_bio_bh_end_io;
43333 int submit_bio_bh_rw;
43334 u64 flush_gen; /* only valid if !never_written */
43335 };
43336diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
43337index 8206b39..06d5654 100644
43338--- a/fs/btrfs/ctree.c
43339+++ b/fs/btrfs/ctree.c
43340@@ -973,9 +973,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
43341 free_extent_buffer(buf);
43342 add_root_to_dirty_list(root);
43343 } else {
43344- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43345- parent_start = parent->start;
43346- else
43347+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43348+ if (parent)
43349+ parent_start = parent->start;
43350+ else
43351+ parent_start = 0;
43352+ } else
43353 parent_start = 0;
43354
43355 WARN_ON(trans->transid != btrfs_header_generation(parent));
43356diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43357index a7d1921..a32dba2 100644
43358--- a/fs/btrfs/inode.c
43359+++ b/fs/btrfs/inode.c
43360@@ -7111,7 +7111,7 @@ fail:
43361 return -ENOMEM;
43362 }
43363
43364-static int btrfs_getattr(struct vfsmount *mnt,
43365+int btrfs_getattr(struct vfsmount *mnt,
43366 struct dentry *dentry, struct kstat *stat)
43367 {
43368 struct inode *inode = dentry->d_inode;
43369@@ -7125,6 +7125,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43370 return 0;
43371 }
43372
43373+EXPORT_SYMBOL(btrfs_getattr);
43374+
43375+dev_t get_btrfs_dev_from_inode(struct inode *inode)
43376+{
43377+ return BTRFS_I(inode)->root->anon_dev;
43378+}
43379+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43380+
43381 /*
43382 * If a file is moved, it will inherit the cow and compression flags of the new
43383 * directory.
43384diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43385index 0e92e57..8b560de 100644
43386--- a/fs/btrfs/ioctl.c
43387+++ b/fs/btrfs/ioctl.c
43388@@ -2902,9 +2902,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43389 for (i = 0; i < num_types; i++) {
43390 struct btrfs_space_info *tmp;
43391
43392+ /* Don't copy in more than we allocated */
43393 if (!slot_count)
43394 break;
43395
43396+ slot_count--;
43397+
43398 info = NULL;
43399 rcu_read_lock();
43400 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43401@@ -2926,10 +2929,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43402 memcpy(dest, &space, sizeof(space));
43403 dest++;
43404 space_args.total_spaces++;
43405- slot_count--;
43406 }
43407- if (!slot_count)
43408- break;
43409 }
43410 up_read(&info->groups_sem);
43411 }
43412diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43413index 646ee21..f020f87 100644
43414--- a/fs/btrfs/relocation.c
43415+++ b/fs/btrfs/relocation.c
43416@@ -1268,7 +1268,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43417 }
43418 spin_unlock(&rc->reloc_root_tree.lock);
43419
43420- BUG_ON((struct btrfs_root *)node->data != root);
43421+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
43422
43423 if (!del) {
43424 spin_lock(&rc->reloc_root_tree.lock);
43425diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43426index 622f469..e8d2d55 100644
43427--- a/fs/cachefiles/bind.c
43428+++ b/fs/cachefiles/bind.c
43429@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43430 args);
43431
43432 /* start by checking things over */
43433- ASSERT(cache->fstop_percent >= 0 &&
43434- cache->fstop_percent < cache->fcull_percent &&
43435+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
43436 cache->fcull_percent < cache->frun_percent &&
43437 cache->frun_percent < 100);
43438
43439- ASSERT(cache->bstop_percent >= 0 &&
43440- cache->bstop_percent < cache->bcull_percent &&
43441+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
43442 cache->bcull_percent < cache->brun_percent &&
43443 cache->brun_percent < 100);
43444
43445diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
43446index 0a1467b..6a53245 100644
43447--- a/fs/cachefiles/daemon.c
43448+++ b/fs/cachefiles/daemon.c
43449@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
43450 if (n > buflen)
43451 return -EMSGSIZE;
43452
43453- if (copy_to_user(_buffer, buffer, n) != 0)
43454+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
43455 return -EFAULT;
43456
43457 return n;
43458@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
43459 if (test_bit(CACHEFILES_DEAD, &cache->flags))
43460 return -EIO;
43461
43462- if (datalen < 0 || datalen > PAGE_SIZE - 1)
43463+ if (datalen > PAGE_SIZE - 1)
43464 return -EOPNOTSUPP;
43465
43466 /* drag the command string into the kernel so we can parse it */
43467@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
43468 if (args[0] != '%' || args[1] != '\0')
43469 return -EINVAL;
43470
43471- if (fstop < 0 || fstop >= cache->fcull_percent)
43472+ if (fstop >= cache->fcull_percent)
43473 return cachefiles_daemon_range_error(cache, args);
43474
43475 cache->fstop_percent = fstop;
43476@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
43477 if (args[0] != '%' || args[1] != '\0')
43478 return -EINVAL;
43479
43480- if (bstop < 0 || bstop >= cache->bcull_percent)
43481+ if (bstop >= cache->bcull_percent)
43482 return cachefiles_daemon_range_error(cache, args);
43483
43484 cache->bstop_percent = bstop;
43485diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
43486index bd6bc1b..b627b53 100644
43487--- a/fs/cachefiles/internal.h
43488+++ b/fs/cachefiles/internal.h
43489@@ -57,7 +57,7 @@ struct cachefiles_cache {
43490 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
43491 struct rb_root active_nodes; /* active nodes (can't be culled) */
43492 rwlock_t active_lock; /* lock for active_nodes */
43493- atomic_t gravecounter; /* graveyard uniquifier */
43494+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
43495 unsigned frun_percent; /* when to stop culling (% files) */
43496 unsigned fcull_percent; /* when to start culling (% files) */
43497 unsigned fstop_percent; /* when to stop allocating (% files) */
43498@@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
43499 * proc.c
43500 */
43501 #ifdef CONFIG_CACHEFILES_HISTOGRAM
43502-extern atomic_t cachefiles_lookup_histogram[HZ];
43503-extern atomic_t cachefiles_mkdir_histogram[HZ];
43504-extern atomic_t cachefiles_create_histogram[HZ];
43505+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43506+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43507+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
43508
43509 extern int __init cachefiles_proc_init(void);
43510 extern void cachefiles_proc_cleanup(void);
43511 static inline
43512-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
43513+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
43514 {
43515 unsigned long jif = jiffies - start_jif;
43516 if (jif >= HZ)
43517 jif = HZ - 1;
43518- atomic_inc(&histogram[jif]);
43519+ atomic_inc_unchecked(&histogram[jif]);
43520 }
43521
43522 #else
43523diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
43524index 7f0771d..87d4f36 100644
43525--- a/fs/cachefiles/namei.c
43526+++ b/fs/cachefiles/namei.c
43527@@ -318,7 +318,7 @@ try_again:
43528 /* first step is to make up a grave dentry in the graveyard */
43529 sprintf(nbuffer, "%08x%08x",
43530 (uint32_t) get_seconds(),
43531- (uint32_t) atomic_inc_return(&cache->gravecounter));
43532+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
43533
43534 /* do the multiway lock magic */
43535 trap = lock_rename(cache->graveyard, dir);
43536diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
43537index eccd339..4c1d995 100644
43538--- a/fs/cachefiles/proc.c
43539+++ b/fs/cachefiles/proc.c
43540@@ -14,9 +14,9 @@
43541 #include <linux/seq_file.h>
43542 #include "internal.h"
43543
43544-atomic_t cachefiles_lookup_histogram[HZ];
43545-atomic_t cachefiles_mkdir_histogram[HZ];
43546-atomic_t cachefiles_create_histogram[HZ];
43547+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43548+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43549+atomic_unchecked_t cachefiles_create_histogram[HZ];
43550
43551 /*
43552 * display the latency histogram
43553@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
43554 return 0;
43555 default:
43556 index = (unsigned long) v - 3;
43557- x = atomic_read(&cachefiles_lookup_histogram[index]);
43558- y = atomic_read(&cachefiles_mkdir_histogram[index]);
43559- z = atomic_read(&cachefiles_create_histogram[index]);
43560+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
43561+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
43562+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
43563 if (x == 0 && y == 0 && z == 0)
43564 return 0;
43565
43566diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
43567index 0e3c092..818480e 100644
43568--- a/fs/cachefiles/rdwr.c
43569+++ b/fs/cachefiles/rdwr.c
43570@@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
43571 old_fs = get_fs();
43572 set_fs(KERNEL_DS);
43573 ret = file->f_op->write(
43574- file, (const void __user *) data, len, &pos);
43575+ file, (const void __force_user *) data, len, &pos);
43576 set_fs(old_fs);
43577 kunmap(page);
43578 if (ret != len)
43579diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
43580index 3e8094b..cb3ff3d 100644
43581--- a/fs/ceph/dir.c
43582+++ b/fs/ceph/dir.c
43583@@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
43584 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
43585 struct ceph_mds_client *mdsc = fsc->mdsc;
43586 unsigned frag = fpos_frag(filp->f_pos);
43587- int off = fpos_off(filp->f_pos);
43588+ unsigned int off = fpos_off(filp->f_pos);
43589 int err;
43590 u32 ftype;
43591 struct ceph_mds_reply_info_parsed *rinfo;
43592@@ -598,7 +598,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
43593 if (nd &&
43594 (nd->flags & LOOKUP_OPEN) &&
43595 !(nd->intent.open.flags & O_CREAT)) {
43596- int mode = nd->intent.open.create_mode & ~current->fs->umask;
43597+ int mode = nd->intent.open.create_mode & ~current_umask();
43598 return ceph_lookup_open(dir, dentry, nd, mode, 1);
43599 }
43600
43601diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
43602index e814052..28dcdf7 100644
43603--- a/fs/cifs/cifs_debug.c
43604+++ b/fs/cifs/cifs_debug.c
43605@@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43606
43607 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
43608 #ifdef CONFIG_CIFS_STATS2
43609- atomic_set(&totBufAllocCount, 0);
43610- atomic_set(&totSmBufAllocCount, 0);
43611+ atomic_set_unchecked(&totBufAllocCount, 0);
43612+ atomic_set_unchecked(&totSmBufAllocCount, 0);
43613 #endif /* CONFIG_CIFS_STATS2 */
43614 spin_lock(&cifs_tcp_ses_lock);
43615 list_for_each(tmp1, &cifs_tcp_ses_list) {
43616@@ -281,25 +281,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43617 tcon = list_entry(tmp3,
43618 struct cifs_tcon,
43619 tcon_list);
43620- atomic_set(&tcon->num_smbs_sent, 0);
43621- atomic_set(&tcon->num_writes, 0);
43622- atomic_set(&tcon->num_reads, 0);
43623- atomic_set(&tcon->num_oplock_brks, 0);
43624- atomic_set(&tcon->num_opens, 0);
43625- atomic_set(&tcon->num_posixopens, 0);
43626- atomic_set(&tcon->num_posixmkdirs, 0);
43627- atomic_set(&tcon->num_closes, 0);
43628- atomic_set(&tcon->num_deletes, 0);
43629- atomic_set(&tcon->num_mkdirs, 0);
43630- atomic_set(&tcon->num_rmdirs, 0);
43631- atomic_set(&tcon->num_renames, 0);
43632- atomic_set(&tcon->num_t2renames, 0);
43633- atomic_set(&tcon->num_ffirst, 0);
43634- atomic_set(&tcon->num_fnext, 0);
43635- atomic_set(&tcon->num_fclose, 0);
43636- atomic_set(&tcon->num_hardlinks, 0);
43637- atomic_set(&tcon->num_symlinks, 0);
43638- atomic_set(&tcon->num_locks, 0);
43639+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
43640+ atomic_set_unchecked(&tcon->num_writes, 0);
43641+ atomic_set_unchecked(&tcon->num_reads, 0);
43642+ atomic_set_unchecked(&tcon->num_oplock_brks, 0);
43643+ atomic_set_unchecked(&tcon->num_opens, 0);
43644+ atomic_set_unchecked(&tcon->num_posixopens, 0);
43645+ atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
43646+ atomic_set_unchecked(&tcon->num_closes, 0);
43647+ atomic_set_unchecked(&tcon->num_deletes, 0);
43648+ atomic_set_unchecked(&tcon->num_mkdirs, 0);
43649+ atomic_set_unchecked(&tcon->num_rmdirs, 0);
43650+ atomic_set_unchecked(&tcon->num_renames, 0);
43651+ atomic_set_unchecked(&tcon->num_t2renames, 0);
43652+ atomic_set_unchecked(&tcon->num_ffirst, 0);
43653+ atomic_set_unchecked(&tcon->num_fnext, 0);
43654+ atomic_set_unchecked(&tcon->num_fclose, 0);
43655+ atomic_set_unchecked(&tcon->num_hardlinks, 0);
43656+ atomic_set_unchecked(&tcon->num_symlinks, 0);
43657+ atomic_set_unchecked(&tcon->num_locks, 0);
43658 }
43659 }
43660 }
43661@@ -329,8 +329,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43662 smBufAllocCount.counter, cifs_min_small);
43663 #ifdef CONFIG_CIFS_STATS2
43664 seq_printf(m, "Total Large %d Small %d Allocations\n",
43665- atomic_read(&totBufAllocCount),
43666- atomic_read(&totSmBufAllocCount));
43667+ atomic_read_unchecked(&totBufAllocCount),
43668+ atomic_read_unchecked(&totSmBufAllocCount));
43669 #endif /* CONFIG_CIFS_STATS2 */
43670
43671 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
43672@@ -359,41 +359,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43673 if (tcon->need_reconnect)
43674 seq_puts(m, "\tDISCONNECTED ");
43675 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
43676- atomic_read(&tcon->num_smbs_sent),
43677- atomic_read(&tcon->num_oplock_brks));
43678+ atomic_read_unchecked(&tcon->num_smbs_sent),
43679+ atomic_read_unchecked(&tcon->num_oplock_brks));
43680 seq_printf(m, "\nReads: %d Bytes: %lld",
43681- atomic_read(&tcon->num_reads),
43682+ atomic_read_unchecked(&tcon->num_reads),
43683 (long long)(tcon->bytes_read));
43684 seq_printf(m, "\nWrites: %d Bytes: %lld",
43685- atomic_read(&tcon->num_writes),
43686+ atomic_read_unchecked(&tcon->num_writes),
43687 (long long)(tcon->bytes_written));
43688 seq_printf(m, "\nFlushes: %d",
43689- atomic_read(&tcon->num_flushes));
43690+ atomic_read_unchecked(&tcon->num_flushes));
43691 seq_printf(m, "\nLocks: %d HardLinks: %d "
43692 "Symlinks: %d",
43693- atomic_read(&tcon->num_locks),
43694- atomic_read(&tcon->num_hardlinks),
43695- atomic_read(&tcon->num_symlinks));
43696+ atomic_read_unchecked(&tcon->num_locks),
43697+ atomic_read_unchecked(&tcon->num_hardlinks),
43698+ atomic_read_unchecked(&tcon->num_symlinks));
43699 seq_printf(m, "\nOpens: %d Closes: %d "
43700 "Deletes: %d",
43701- atomic_read(&tcon->num_opens),
43702- atomic_read(&tcon->num_closes),
43703- atomic_read(&tcon->num_deletes));
43704+ atomic_read_unchecked(&tcon->num_opens),
43705+ atomic_read_unchecked(&tcon->num_closes),
43706+ atomic_read_unchecked(&tcon->num_deletes));
43707 seq_printf(m, "\nPosix Opens: %d "
43708 "Posix Mkdirs: %d",
43709- atomic_read(&tcon->num_posixopens),
43710- atomic_read(&tcon->num_posixmkdirs));
43711+ atomic_read_unchecked(&tcon->num_posixopens),
43712+ atomic_read_unchecked(&tcon->num_posixmkdirs));
43713 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
43714- atomic_read(&tcon->num_mkdirs),
43715- atomic_read(&tcon->num_rmdirs));
43716+ atomic_read_unchecked(&tcon->num_mkdirs),
43717+ atomic_read_unchecked(&tcon->num_rmdirs));
43718 seq_printf(m, "\nRenames: %d T2 Renames %d",
43719- atomic_read(&tcon->num_renames),
43720- atomic_read(&tcon->num_t2renames));
43721+ atomic_read_unchecked(&tcon->num_renames),
43722+ atomic_read_unchecked(&tcon->num_t2renames));
43723 seq_printf(m, "\nFindFirst: %d FNext %d "
43724 "FClose %d",
43725- atomic_read(&tcon->num_ffirst),
43726- atomic_read(&tcon->num_fnext),
43727- atomic_read(&tcon->num_fclose));
43728+ atomic_read_unchecked(&tcon->num_ffirst),
43729+ atomic_read_unchecked(&tcon->num_fnext),
43730+ atomic_read_unchecked(&tcon->num_fclose));
43731 }
43732 }
43733 }
43734diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
43735index 8b6e344..303a662 100644
43736--- a/fs/cifs/cifsfs.c
43737+++ b/fs/cifs/cifsfs.c
43738@@ -994,7 +994,7 @@ cifs_init_request_bufs(void)
43739 cifs_req_cachep = kmem_cache_create("cifs_request",
43740 CIFSMaxBufSize +
43741 MAX_CIFS_HDR_SIZE, 0,
43742- SLAB_HWCACHE_ALIGN, NULL);
43743+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
43744 if (cifs_req_cachep == NULL)
43745 return -ENOMEM;
43746
43747@@ -1021,7 +1021,7 @@ cifs_init_request_bufs(void)
43748 efficient to alloc 1 per page off the slab compared to 17K (5page)
43749 alloc of large cifs buffers even when page debugging is on */
43750 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
43751- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
43752+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
43753 NULL);
43754 if (cifs_sm_req_cachep == NULL) {
43755 mempool_destroy(cifs_req_poolp);
43756@@ -1106,8 +1106,8 @@ init_cifs(void)
43757 atomic_set(&bufAllocCount, 0);
43758 atomic_set(&smBufAllocCount, 0);
43759 #ifdef CONFIG_CIFS_STATS2
43760- atomic_set(&totBufAllocCount, 0);
43761- atomic_set(&totSmBufAllocCount, 0);
43762+ atomic_set_unchecked(&totBufAllocCount, 0);
43763+ atomic_set_unchecked(&totSmBufAllocCount, 0);
43764 #endif /* CONFIG_CIFS_STATS2 */
43765
43766 atomic_set(&midCount, 0);
43767diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
43768index d86ba9f..e80049d 100644
43769--- a/fs/cifs/cifsglob.h
43770+++ b/fs/cifs/cifsglob.h
43771@@ -491,28 +491,28 @@ struct cifs_tcon {
43772 __u16 Flags; /* optional support bits */
43773 enum statusEnum tidStatus;
43774 #ifdef CONFIG_CIFS_STATS
43775- atomic_t num_smbs_sent;
43776- atomic_t num_writes;
43777- atomic_t num_reads;
43778- atomic_t num_flushes;
43779- atomic_t num_oplock_brks;
43780- atomic_t num_opens;
43781- atomic_t num_closes;
43782- atomic_t num_deletes;
43783- atomic_t num_mkdirs;
43784- atomic_t num_posixopens;
43785- atomic_t num_posixmkdirs;
43786- atomic_t num_rmdirs;
43787- atomic_t num_renames;
43788- atomic_t num_t2renames;
43789- atomic_t num_ffirst;
43790- atomic_t num_fnext;
43791- atomic_t num_fclose;
43792- atomic_t num_hardlinks;
43793- atomic_t num_symlinks;
43794- atomic_t num_locks;
43795- atomic_t num_acl_get;
43796- atomic_t num_acl_set;
43797+ atomic_unchecked_t num_smbs_sent;
43798+ atomic_unchecked_t num_writes;
43799+ atomic_unchecked_t num_reads;
43800+ atomic_unchecked_t num_flushes;
43801+ atomic_unchecked_t num_oplock_brks;
43802+ atomic_unchecked_t num_opens;
43803+ atomic_unchecked_t num_closes;
43804+ atomic_unchecked_t num_deletes;
43805+ atomic_unchecked_t num_mkdirs;
43806+ atomic_unchecked_t num_posixopens;
43807+ atomic_unchecked_t num_posixmkdirs;
43808+ atomic_unchecked_t num_rmdirs;
43809+ atomic_unchecked_t num_renames;
43810+ atomic_unchecked_t num_t2renames;
43811+ atomic_unchecked_t num_ffirst;
43812+ atomic_unchecked_t num_fnext;
43813+ atomic_unchecked_t num_fclose;
43814+ atomic_unchecked_t num_hardlinks;
43815+ atomic_unchecked_t num_symlinks;
43816+ atomic_unchecked_t num_locks;
43817+ atomic_unchecked_t num_acl_get;
43818+ atomic_unchecked_t num_acl_set;
43819 #ifdef CONFIG_CIFS_STATS2
43820 unsigned long long time_writes;
43821 unsigned long long time_reads;
43822@@ -735,7 +735,7 @@ convert_delimiter(char *path, char delim)
43823 }
43824
43825 #ifdef CONFIG_CIFS_STATS
43826-#define cifs_stats_inc atomic_inc
43827+#define cifs_stats_inc atomic_inc_unchecked
43828
43829 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
43830 unsigned int bytes)
43831@@ -1093,8 +1093,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
43832 /* Various Debug counters */
43833 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
43834 #ifdef CONFIG_CIFS_STATS2
43835-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
43836-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
43837+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
43838+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
43839 #endif
43840 GLOBAL_EXTERN atomic_t smBufAllocCount;
43841 GLOBAL_EXTERN atomic_t midCount;
43842diff --git a/fs/cifs/link.c b/fs/cifs/link.c
43843index 6b0e064..94e6c3c 100644
43844--- a/fs/cifs/link.c
43845+++ b/fs/cifs/link.c
43846@@ -600,7 +600,7 @@ symlink_exit:
43847
43848 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
43849 {
43850- char *p = nd_get_link(nd);
43851+ const char *p = nd_get_link(nd);
43852 if (!IS_ERR(p))
43853 kfree(p);
43854 }
43855diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
43856index 557506a..2fd3816 100644
43857--- a/fs/cifs/misc.c
43858+++ b/fs/cifs/misc.c
43859@@ -156,7 +156,7 @@ cifs_buf_get(void)
43860 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
43861 atomic_inc(&bufAllocCount);
43862 #ifdef CONFIG_CIFS_STATS2
43863- atomic_inc(&totBufAllocCount);
43864+ atomic_inc_unchecked(&totBufAllocCount);
43865 #endif /* CONFIG_CIFS_STATS2 */
43866 }
43867
43868@@ -191,7 +191,7 @@ cifs_small_buf_get(void)
43869 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
43870 atomic_inc(&smBufAllocCount);
43871 #ifdef CONFIG_CIFS_STATS2
43872- atomic_inc(&totSmBufAllocCount);
43873+ atomic_inc_unchecked(&totSmBufAllocCount);
43874 #endif /* CONFIG_CIFS_STATS2 */
43875
43876 }
43877diff --git a/fs/coda/cache.c b/fs/coda/cache.c
43878index 6901578..d402eb5 100644
43879--- a/fs/coda/cache.c
43880+++ b/fs/coda/cache.c
43881@@ -24,7 +24,7 @@
43882 #include "coda_linux.h"
43883 #include "coda_cache.h"
43884
43885-static atomic_t permission_epoch = ATOMIC_INIT(0);
43886+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
43887
43888 /* replace or extend an acl cache hit */
43889 void coda_cache_enter(struct inode *inode, int mask)
43890@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
43891 struct coda_inode_info *cii = ITOC(inode);
43892
43893 spin_lock(&cii->c_lock);
43894- cii->c_cached_epoch = atomic_read(&permission_epoch);
43895+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
43896 if (cii->c_uid != current_fsuid()) {
43897 cii->c_uid = current_fsuid();
43898 cii->c_cached_perm = mask;
43899@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
43900 {
43901 struct coda_inode_info *cii = ITOC(inode);
43902 spin_lock(&cii->c_lock);
43903- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
43904+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
43905 spin_unlock(&cii->c_lock);
43906 }
43907
43908 /* remove all acl caches */
43909 void coda_cache_clear_all(struct super_block *sb)
43910 {
43911- atomic_inc(&permission_epoch);
43912+ atomic_inc_unchecked(&permission_epoch);
43913 }
43914
43915
43916@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
43917 spin_lock(&cii->c_lock);
43918 hit = (mask & cii->c_cached_perm) == mask &&
43919 cii->c_uid == current_fsuid() &&
43920- cii->c_cached_epoch == atomic_read(&permission_epoch);
43921+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
43922 spin_unlock(&cii->c_lock);
43923
43924 return hit;
43925diff --git a/fs/compat.c b/fs/compat.c
43926index 6161255..9f28287 100644
43927--- a/fs/compat.c
43928+++ b/fs/compat.c
43929@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
43930
43931 set_fs(KERNEL_DS);
43932 /* The __user pointer cast is valid because of the set_fs() */
43933- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
43934+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
43935 set_fs(oldfs);
43936 /* truncating is ok because it's a user address */
43937 if (!ret)
43938@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
43939 goto out;
43940
43941 ret = -EINVAL;
43942- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
43943+ if (nr_segs > UIO_MAXIOV)
43944 goto out;
43945 if (nr_segs > fast_segs) {
43946 ret = -ENOMEM;
43947@@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
43948
43949 struct compat_readdir_callback {
43950 struct compat_old_linux_dirent __user *dirent;
43951+ struct file * file;
43952 int result;
43953 };
43954
43955@@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
43956 buf->result = -EOVERFLOW;
43957 return -EOVERFLOW;
43958 }
43959+
43960+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43961+ return 0;
43962+
43963 buf->result++;
43964 dirent = buf->dirent;
43965 if (!access_ok(VERIFY_WRITE, dirent,
43966@@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
43967
43968 buf.result = 0;
43969 buf.dirent = dirent;
43970+ buf.file = file;
43971
43972 error = vfs_readdir(file, compat_fillonedir, &buf);
43973 if (buf.result)
43974@@ -899,6 +905,7 @@ struct compat_linux_dirent {
43975 struct compat_getdents_callback {
43976 struct compat_linux_dirent __user *current_dir;
43977 struct compat_linux_dirent __user *previous;
43978+ struct file * file;
43979 int count;
43980 int error;
43981 };
43982@@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
43983 buf->error = -EOVERFLOW;
43984 return -EOVERFLOW;
43985 }
43986+
43987+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43988+ return 0;
43989+
43990 dirent = buf->previous;
43991 if (dirent) {
43992 if (__put_user(offset, &dirent->d_off))
43993@@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
43994 buf.previous = NULL;
43995 buf.count = count;
43996 buf.error = 0;
43997+ buf.file = file;
43998
43999 error = vfs_readdir(file, compat_filldir, &buf);
44000 if (error >= 0)
44001@@ -986,6 +998,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44002 struct compat_getdents_callback64 {
44003 struct linux_dirent64 __user *current_dir;
44004 struct linux_dirent64 __user *previous;
44005+ struct file * file;
44006 int count;
44007 int error;
44008 };
44009@@ -1002,6 +1015,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
44010 buf->error = -EINVAL; /* only used if we fail.. */
44011 if (reclen > buf->count)
44012 return -EINVAL;
44013+
44014+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44015+ return 0;
44016+
44017 dirent = buf->previous;
44018
44019 if (dirent) {
44020@@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
44021 buf.previous = NULL;
44022 buf.count = count;
44023 buf.error = 0;
44024+ buf.file = file;
44025
44026 error = vfs_readdir(file, compat_filldir64, &buf);
44027 if (error >= 0)
44028 error = buf.error;
44029 lastdirent = buf.previous;
44030 if (lastdirent) {
44031- typeof(lastdirent->d_off) d_off = file->f_pos;
44032+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
44033 if (__put_user_unaligned(d_off, &lastdirent->d_off))
44034 error = -EFAULT;
44035 else
44036@@ -1155,11 +1173,14 @@ compat_sys_readv(unsigned long fd, const struct compat_iovec __user *vec,
44037 struct file *file;
44038 int fput_needed;
44039 ssize_t ret;
44040+ loff_t pos;
44041
44042 file = fget_light(fd, &fput_needed);
44043 if (!file)
44044 return -EBADF;
44045- ret = compat_readv(file, vec, vlen, &file->f_pos);
44046+ pos = file->f_pos;
44047+ ret = compat_readv(file, vec, vlen, &pos);
44048+ file->f_pos = pos;
44049 fput_light(file, fput_needed);
44050 return ret;
44051 }
44052@@ -1221,11 +1242,14 @@ compat_sys_writev(unsigned long fd, const struct compat_iovec __user *vec,
44053 struct file *file;
44054 int fput_needed;
44055 ssize_t ret;
44056+ loff_t pos;
44057
44058 file = fget_light(fd, &fput_needed);
44059 if (!file)
44060 return -EBADF;
44061- ret = compat_writev(file, vec, vlen, &file->f_pos);
44062+ pos = file->f_pos;
44063+ ret = compat_writev(file, vec, vlen, &pos);
44064+ file->f_pos = pos;
44065 fput_light(file, fput_needed);
44066 return ret;
44067 }
44068diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
44069index 112e45a..b59845b 100644
44070--- a/fs/compat_binfmt_elf.c
44071+++ b/fs/compat_binfmt_elf.c
44072@@ -30,11 +30,13 @@
44073 #undef elf_phdr
44074 #undef elf_shdr
44075 #undef elf_note
44076+#undef elf_dyn
44077 #undef elf_addr_t
44078 #define elfhdr elf32_hdr
44079 #define elf_phdr elf32_phdr
44080 #define elf_shdr elf32_shdr
44081 #define elf_note elf32_note
44082+#define elf_dyn Elf32_Dyn
44083 #define elf_addr_t Elf32_Addr
44084
44085 /*
44086diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
44087index debdfe0..75d31d4 100644
44088--- a/fs/compat_ioctl.c
44089+++ b/fs/compat_ioctl.c
44090@@ -210,6 +210,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
44091
44092 err = get_user(palp, &up->palette);
44093 err |= get_user(length, &up->length);
44094+ if (err)
44095+ return -EFAULT;
44096
44097 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
44098 err = put_user(compat_ptr(palp), &up_native->palette);
44099@@ -621,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
44100 return -EFAULT;
44101 if (__get_user(udata, &ss32->iomem_base))
44102 return -EFAULT;
44103- ss.iomem_base = compat_ptr(udata);
44104+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
44105 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
44106 __get_user(ss.port_high, &ss32->port_high))
44107 return -EFAULT;
44108@@ -796,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
44109 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
44110 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
44111 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
44112- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44113+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44114 return -EFAULT;
44115
44116 return ioctl_preallocate(file, p);
44117@@ -1610,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
44118 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
44119 {
44120 unsigned int a, b;
44121- a = *(unsigned int *)p;
44122- b = *(unsigned int *)q;
44123+ a = *(const unsigned int *)p;
44124+ b = *(const unsigned int *)q;
44125 if (a > b)
44126 return 1;
44127 if (a < b)
44128diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
44129index 7e6c52d..94bc756 100644
44130--- a/fs/configfs/dir.c
44131+++ b/fs/configfs/dir.c
44132@@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44133 }
44134 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
44135 struct configfs_dirent *next;
44136- const char * name;
44137+ const unsigned char * name;
44138+ char d_name[sizeof(next->s_dentry->d_iname)];
44139 int len;
44140 struct inode *inode = NULL;
44141
44142@@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44143 continue;
44144
44145 name = configfs_get_name(next);
44146- len = strlen(name);
44147+ if (next->s_dentry && name == next->s_dentry->d_iname) {
44148+ len = next->s_dentry->d_name.len;
44149+ memcpy(d_name, name, len);
44150+ name = d_name;
44151+ } else
44152+ len = strlen(name);
44153
44154 /*
44155 * We'll have a dentry and an inode for
44156diff --git a/fs/dcache.c b/fs/dcache.c
44157index 4046904..5e31505 100644
44158--- a/fs/dcache.c
44159+++ b/fs/dcache.c
44160@@ -3154,7 +3154,7 @@ void __init vfs_caches_init(unsigned long mempages)
44161 mempages -= reserve;
44162
44163 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
44164- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
44165+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
44166
44167 dcache_init();
44168 inode_init();
44169diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
44170index b80bc84..0d46d1a 100644
44171--- a/fs/debugfs/inode.c
44172+++ b/fs/debugfs/inode.c
44173@@ -408,7 +408,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
44174 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
44175 {
44176 return debugfs_create_file(name,
44177+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
44178+ S_IFDIR | S_IRWXU,
44179+#else
44180 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
44181+#endif
44182 parent, NULL, NULL);
44183 }
44184 EXPORT_SYMBOL_GPL(debugfs_create_dir);
44185diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
44186index a07441a..046fc0d 100644
44187--- a/fs/ecryptfs/inode.c
44188+++ b/fs/ecryptfs/inode.c
44189@@ -671,7 +671,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
44190 old_fs = get_fs();
44191 set_fs(get_ds());
44192 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
44193- (char __user *)lower_buf,
44194+ (char __force_user *)lower_buf,
44195 PATH_MAX);
44196 set_fs(old_fs);
44197 if (rc < 0)
44198@@ -703,7 +703,7 @@ out:
44199 static void
44200 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
44201 {
44202- char *buf = nd_get_link(nd);
44203+ const char *buf = nd_get_link(nd);
44204 if (!IS_ERR(buf)) {
44205 /* Free the char* */
44206 kfree(buf);
44207diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
44208index c0038f6..47ab347 100644
44209--- a/fs/ecryptfs/miscdev.c
44210+++ b/fs/ecryptfs/miscdev.c
44211@@ -355,7 +355,7 @@ check_list:
44212 goto out_unlock_msg_ctx;
44213 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
44214 if (msg_ctx->msg) {
44215- if (copy_to_user(&buf[i], packet_length, packet_length_size))
44216+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
44217 goto out_unlock_msg_ctx;
44218 i += packet_length_size;
44219 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
44220diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
44221index b2a34a1..162fa69 100644
44222--- a/fs/ecryptfs/read_write.c
44223+++ b/fs/ecryptfs/read_write.c
44224@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
44225 return -EIO;
44226 fs_save = get_fs();
44227 set_fs(get_ds());
44228- rc = vfs_write(lower_file, data, size, &offset);
44229+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
44230 set_fs(fs_save);
44231 mark_inode_dirty_sync(ecryptfs_inode);
44232 return rc;
44233@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
44234 return -EIO;
44235 fs_save = get_fs();
44236 set_fs(get_ds());
44237- rc = vfs_read(lower_file, data, size, &offset);
44238+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
44239 set_fs(fs_save);
44240 return rc;
44241 }
44242diff --git a/fs/exec.c b/fs/exec.c
44243index e95aeed..a943469 100644
44244--- a/fs/exec.c
44245+++ b/fs/exec.c
44246@@ -55,6 +55,15 @@
44247 #include <linux/pipe_fs_i.h>
44248 #include <linux/oom.h>
44249 #include <linux/compat.h>
44250+#include <linux/random.h>
44251+#include <linux/seq_file.h>
44252+
44253+#ifdef CONFIG_PAX_REFCOUNT
44254+#include <linux/kallsyms.h>
44255+#include <linux/kdebug.h>
44256+#endif
44257+
44258+#include <trace/events/fs.h>
44259
44260 #include <asm/uaccess.h>
44261 #include <asm/mmu_context.h>
44262@@ -66,6 +75,18 @@
44263
44264 #include <trace/events/sched.h>
44265
44266+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
44267+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
44268+{
44269+ 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");
44270+}
44271+#endif
44272+
44273+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
44274+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
44275+EXPORT_SYMBOL(pax_set_initial_flags_func);
44276+#endif
44277+
44278 int core_uses_pid;
44279 char core_pattern[CORENAME_MAX_SIZE] = "core";
44280 unsigned int core_pipe_limit;
44281@@ -75,7 +96,7 @@ struct core_name {
44282 char *corename;
44283 int used, size;
44284 };
44285-static atomic_t call_count = ATOMIC_INIT(1);
44286+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
44287
44288 /* The maximal length of core_pattern is also specified in sysctl.c */
44289
44290@@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44291 int write)
44292 {
44293 struct page *page;
44294- int ret;
44295
44296-#ifdef CONFIG_STACK_GROWSUP
44297- if (write) {
44298- ret = expand_downwards(bprm->vma, pos);
44299- if (ret < 0)
44300- return NULL;
44301- }
44302-#endif
44303- ret = get_user_pages(current, bprm->mm, pos,
44304- 1, write, 1, &page, NULL);
44305- if (ret <= 0)
44306+ if (0 > expand_downwards(bprm->vma, pos))
44307+ return NULL;
44308+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
44309 return NULL;
44310
44311 if (write) {
44312@@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44313 if (size <= ARG_MAX)
44314 return page;
44315
44316+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44317+ // only allow 512KB for argv+env on suid/sgid binaries
44318+ // to prevent easy ASLR exhaustion
44319+ if (((bprm->cred->euid != current_euid()) ||
44320+ (bprm->cred->egid != current_egid())) &&
44321+ (size > (512 * 1024))) {
44322+ put_page(page);
44323+ return NULL;
44324+ }
44325+#endif
44326+
44327 /*
44328 * Limit to 1/4-th the stack size for the argv+env strings.
44329 * This ensures that:
44330@@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44331 vma->vm_end = STACK_TOP_MAX;
44332 vma->vm_start = vma->vm_end - PAGE_SIZE;
44333 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
44334+
44335+#ifdef CONFIG_PAX_SEGMEXEC
44336+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
44337+#endif
44338+
44339 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
44340 INIT_LIST_HEAD(&vma->anon_vma_chain);
44341
44342@@ -287,6 +316,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44343 mm->stack_vm = mm->total_vm = 1;
44344 up_write(&mm->mmap_sem);
44345 bprm->p = vma->vm_end - sizeof(void *);
44346+
44347+#ifdef CONFIG_PAX_RANDUSTACK
44348+ if (randomize_va_space)
44349+ bprm->p ^= random32() & ~PAGE_MASK;
44350+#endif
44351+
44352 return 0;
44353 err:
44354 up_write(&mm->mmap_sem);
44355@@ -395,19 +430,7 @@ err:
44356 return err;
44357 }
44358
44359-struct user_arg_ptr {
44360-#ifdef CONFIG_COMPAT
44361- bool is_compat;
44362-#endif
44363- union {
44364- const char __user *const __user *native;
44365-#ifdef CONFIG_COMPAT
44366- compat_uptr_t __user *compat;
44367-#endif
44368- } ptr;
44369-};
44370-
44371-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44372+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44373 {
44374 const char __user *native;
44375
44376@@ -416,14 +439,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44377 compat_uptr_t compat;
44378
44379 if (get_user(compat, argv.ptr.compat + nr))
44380- return ERR_PTR(-EFAULT);
44381+ return (const char __force_user *)ERR_PTR(-EFAULT);
44382
44383 return compat_ptr(compat);
44384 }
44385 #endif
44386
44387 if (get_user(native, argv.ptr.native + nr))
44388- return ERR_PTR(-EFAULT);
44389+ return (const char __force_user *)ERR_PTR(-EFAULT);
44390
44391 return native;
44392 }
44393@@ -442,7 +465,7 @@ static int count(struct user_arg_ptr argv, int max)
44394 if (!p)
44395 break;
44396
44397- if (IS_ERR(p))
44398+ if (IS_ERR((const char __force_kernel *)p))
44399 return -EFAULT;
44400
44401 if (i++ >= max)
44402@@ -476,7 +499,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
44403
44404 ret = -EFAULT;
44405 str = get_user_arg_ptr(argv, argc);
44406- if (IS_ERR(str))
44407+ if (IS_ERR((const char __force_kernel *)str))
44408 goto out;
44409
44410 len = strnlen_user(str, MAX_ARG_STRLEN);
44411@@ -558,7 +581,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
44412 int r;
44413 mm_segment_t oldfs = get_fs();
44414 struct user_arg_ptr argv = {
44415- .ptr.native = (const char __user *const __user *)__argv,
44416+ .ptr.native = (const char __force_user *const __force_user *)__argv,
44417 };
44418
44419 set_fs(KERNEL_DS);
44420@@ -593,7 +616,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44421 unsigned long new_end = old_end - shift;
44422 struct mmu_gather tlb;
44423
44424- BUG_ON(new_start > new_end);
44425+ if (new_start >= new_end || new_start < mmap_min_addr)
44426+ return -ENOMEM;
44427
44428 /*
44429 * ensure there are no vmas between where we want to go
44430@@ -602,6 +626,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44431 if (vma != find_vma(mm, new_start))
44432 return -EFAULT;
44433
44434+#ifdef CONFIG_PAX_SEGMEXEC
44435+ BUG_ON(pax_find_mirror_vma(vma));
44436+#endif
44437+
44438 /*
44439 * cover the whole range: [new_start, old_end)
44440 */
44441@@ -682,10 +710,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44442 stack_top = arch_align_stack(stack_top);
44443 stack_top = PAGE_ALIGN(stack_top);
44444
44445- if (unlikely(stack_top < mmap_min_addr) ||
44446- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
44447- return -ENOMEM;
44448-
44449 stack_shift = vma->vm_end - stack_top;
44450
44451 bprm->p -= stack_shift;
44452@@ -697,8 +721,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
44453 bprm->exec -= stack_shift;
44454
44455 down_write(&mm->mmap_sem);
44456+
44457+ /* Move stack pages down in memory. */
44458+ if (stack_shift) {
44459+ ret = shift_arg_pages(vma, stack_shift);
44460+ if (ret)
44461+ goto out_unlock;
44462+ }
44463+
44464 vm_flags = VM_STACK_FLAGS;
44465
44466+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44467+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44468+ vm_flags &= ~VM_EXEC;
44469+
44470+#ifdef CONFIG_PAX_MPROTECT
44471+ if (mm->pax_flags & MF_PAX_MPROTECT)
44472+ vm_flags &= ~VM_MAYEXEC;
44473+#endif
44474+
44475+ }
44476+#endif
44477+
44478 /*
44479 * Adjust stack execute permissions; explicitly enable for
44480 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
44481@@ -717,13 +761,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44482 goto out_unlock;
44483 BUG_ON(prev != vma);
44484
44485- /* Move stack pages down in memory. */
44486- if (stack_shift) {
44487- ret = shift_arg_pages(vma, stack_shift);
44488- if (ret)
44489- goto out_unlock;
44490- }
44491-
44492 /* mprotect_fixup is overkill to remove the temporary stack flags */
44493 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
44494
44495@@ -781,6 +818,8 @@ struct file *open_exec(const char *name)
44496
44497 fsnotify_open(file);
44498
44499+ trace_open_exec(name);
44500+
44501 err = deny_write_access(file);
44502 if (err)
44503 goto exit;
44504@@ -804,7 +843,7 @@ int kernel_read(struct file *file, loff_t offset,
44505 old_fs = get_fs();
44506 set_fs(get_ds());
44507 /* The cast to a user pointer is valid due to the set_fs() */
44508- result = vfs_read(file, (void __user *)addr, count, &pos);
44509+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
44510 set_fs(old_fs);
44511 return result;
44512 }
44513@@ -1257,7 +1296,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
44514 }
44515 rcu_read_unlock();
44516
44517- if (p->fs->users > n_fs) {
44518+ if (atomic_read(&p->fs->users) > n_fs) {
44519 bprm->unsafe |= LSM_UNSAFE_SHARE;
44520 } else {
44521 res = -EAGAIN;
44522@@ -1460,6 +1499,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
44523
44524 EXPORT_SYMBOL(search_binary_handler);
44525
44526+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44527+static DEFINE_PER_CPU(u64, exec_counter);
44528+static int __init init_exec_counters(void)
44529+{
44530+ unsigned int cpu;
44531+
44532+ for_each_possible_cpu(cpu) {
44533+ per_cpu(exec_counter, cpu) = (u64)cpu;
44534+ }
44535+
44536+ return 0;
44537+}
44538+early_initcall(init_exec_counters);
44539+static inline void increment_exec_counter(void)
44540+{
44541+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
44542+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
44543+}
44544+#else
44545+static inline void increment_exec_counter(void) {}
44546+#endif
44547+
44548 /*
44549 * sys_execve() executes a new program.
44550 */
44551@@ -1468,6 +1529,11 @@ static int do_execve_common(const char *filename,
44552 struct user_arg_ptr envp,
44553 struct pt_regs *regs)
44554 {
44555+#ifdef CONFIG_GRKERNSEC
44556+ struct file *old_exec_file;
44557+ struct acl_subject_label *old_acl;
44558+ struct rlimit old_rlim[RLIM_NLIMITS];
44559+#endif
44560 struct linux_binprm *bprm;
44561 struct file *file;
44562 struct files_struct *displaced;
44563@@ -1475,6 +1541,8 @@ static int do_execve_common(const char *filename,
44564 int retval;
44565 const struct cred *cred = current_cred();
44566
44567+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
44568+
44569 /*
44570 * We move the actual failure in case of RLIMIT_NPROC excess from
44571 * set*uid() to execve() because too many poorly written programs
44572@@ -1515,12 +1583,27 @@ static int do_execve_common(const char *filename,
44573 if (IS_ERR(file))
44574 goto out_unmark;
44575
44576+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
44577+ retval = -EPERM;
44578+ goto out_file;
44579+ }
44580+
44581 sched_exec();
44582
44583 bprm->file = file;
44584 bprm->filename = filename;
44585 bprm->interp = filename;
44586
44587+ if (gr_process_user_ban()) {
44588+ retval = -EPERM;
44589+ goto out_file;
44590+ }
44591+
44592+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
44593+ retval = -EACCES;
44594+ goto out_file;
44595+ }
44596+
44597 retval = bprm_mm_init(bprm);
44598 if (retval)
44599 goto out_file;
44600@@ -1537,24 +1620,65 @@ static int do_execve_common(const char *filename,
44601 if (retval < 0)
44602 goto out;
44603
44604+#ifdef CONFIG_GRKERNSEC
44605+ old_acl = current->acl;
44606+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
44607+ old_exec_file = current->exec_file;
44608+ get_file(file);
44609+ current->exec_file = file;
44610+#endif
44611+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44612+ /* limit suid stack to 8MB
44613+ we saved the old limits above and will restore them if this exec fails
44614+ */
44615+ if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
44616+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
44617+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
44618+#endif
44619+
44620+ if (!gr_tpe_allow(file)) {
44621+ retval = -EACCES;
44622+ goto out_fail;
44623+ }
44624+
44625+ if (gr_check_crash_exec(file)) {
44626+ retval = -EACCES;
44627+ goto out_fail;
44628+ }
44629+
44630+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
44631+ bprm->unsafe);
44632+ if (retval < 0)
44633+ goto out_fail;
44634+
44635 retval = copy_strings_kernel(1, &bprm->filename, bprm);
44636 if (retval < 0)
44637- goto out;
44638+ goto out_fail;
44639
44640 bprm->exec = bprm->p;
44641 retval = copy_strings(bprm->envc, envp, bprm);
44642 if (retval < 0)
44643- goto out;
44644+ goto out_fail;
44645
44646 retval = copy_strings(bprm->argc, argv, bprm);
44647 if (retval < 0)
44648- goto out;
44649+ goto out_fail;
44650+
44651+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
44652+
44653+ gr_handle_exec_args(bprm, argv);
44654
44655 retval = search_binary_handler(bprm,regs);
44656 if (retval < 0)
44657- goto out;
44658+ goto out_fail;
44659+#ifdef CONFIG_GRKERNSEC
44660+ if (old_exec_file)
44661+ fput(old_exec_file);
44662+#endif
44663
44664 /* execve succeeded */
44665+
44666+ increment_exec_counter();
44667 current->fs->in_exec = 0;
44668 current->in_execve = 0;
44669 acct_update_integrals(current);
44670@@ -1563,6 +1687,14 @@ static int do_execve_common(const char *filename,
44671 put_files_struct(displaced);
44672 return retval;
44673
44674+out_fail:
44675+#ifdef CONFIG_GRKERNSEC
44676+ current->acl = old_acl;
44677+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
44678+ fput(current->exec_file);
44679+ current->exec_file = old_exec_file;
44680+#endif
44681+
44682 out:
44683 if (bprm->mm) {
44684 acct_arg_size(bprm, 0);
44685@@ -1636,7 +1768,7 @@ static int expand_corename(struct core_name *cn)
44686 {
44687 char *old_corename = cn->corename;
44688
44689- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
44690+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
44691 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
44692
44693 if (!cn->corename) {
44694@@ -1733,7 +1865,7 @@ static int format_corename(struct core_name *cn, long signr)
44695 int pid_in_pattern = 0;
44696 int err = 0;
44697
44698- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
44699+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
44700 cn->corename = kmalloc(cn->size, GFP_KERNEL);
44701 cn->used = 0;
44702
44703@@ -1830,6 +1962,250 @@ out:
44704 return ispipe;
44705 }
44706
44707+int pax_check_flags(unsigned long *flags)
44708+{
44709+ int retval = 0;
44710+
44711+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
44712+ if (*flags & MF_PAX_SEGMEXEC)
44713+ {
44714+ *flags &= ~MF_PAX_SEGMEXEC;
44715+ retval = -EINVAL;
44716+ }
44717+#endif
44718+
44719+ if ((*flags & MF_PAX_PAGEEXEC)
44720+
44721+#ifdef CONFIG_PAX_PAGEEXEC
44722+ && (*flags & MF_PAX_SEGMEXEC)
44723+#endif
44724+
44725+ )
44726+ {
44727+ *flags &= ~MF_PAX_PAGEEXEC;
44728+ retval = -EINVAL;
44729+ }
44730+
44731+ if ((*flags & MF_PAX_MPROTECT)
44732+
44733+#ifdef CONFIG_PAX_MPROTECT
44734+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44735+#endif
44736+
44737+ )
44738+ {
44739+ *flags &= ~MF_PAX_MPROTECT;
44740+ retval = -EINVAL;
44741+ }
44742+
44743+ if ((*flags & MF_PAX_EMUTRAMP)
44744+
44745+#ifdef CONFIG_PAX_EMUTRAMP
44746+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44747+#endif
44748+
44749+ )
44750+ {
44751+ *flags &= ~MF_PAX_EMUTRAMP;
44752+ retval = -EINVAL;
44753+ }
44754+
44755+ return retval;
44756+}
44757+
44758+EXPORT_SYMBOL(pax_check_flags);
44759+
44760+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44761+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
44762+{
44763+ struct task_struct *tsk = current;
44764+ struct mm_struct *mm = current->mm;
44765+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
44766+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
44767+ char *path_exec = NULL;
44768+ char *path_fault = NULL;
44769+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
44770+
44771+ if (buffer_exec && buffer_fault) {
44772+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
44773+
44774+ down_read(&mm->mmap_sem);
44775+ vma = mm->mmap;
44776+ while (vma && (!vma_exec || !vma_fault)) {
44777+ if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
44778+ vma_exec = vma;
44779+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
44780+ vma_fault = vma;
44781+ vma = vma->vm_next;
44782+ }
44783+ if (vma_exec) {
44784+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
44785+ if (IS_ERR(path_exec))
44786+ path_exec = "<path too long>";
44787+ else {
44788+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
44789+ if (path_exec) {
44790+ *path_exec = 0;
44791+ path_exec = buffer_exec;
44792+ } else
44793+ path_exec = "<path too long>";
44794+ }
44795+ }
44796+ if (vma_fault) {
44797+ start = vma_fault->vm_start;
44798+ end = vma_fault->vm_end;
44799+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
44800+ if (vma_fault->vm_file) {
44801+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
44802+ if (IS_ERR(path_fault))
44803+ path_fault = "<path too long>";
44804+ else {
44805+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
44806+ if (path_fault) {
44807+ *path_fault = 0;
44808+ path_fault = buffer_fault;
44809+ } else
44810+ path_fault = "<path too long>";
44811+ }
44812+ } else
44813+ path_fault = "<anonymous mapping>";
44814+ }
44815+ up_read(&mm->mmap_sem);
44816+ }
44817+ if (tsk->signal->curr_ip)
44818+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
44819+ else
44820+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
44821+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
44822+ "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
44823+ task_uid(tsk), task_euid(tsk), pc, sp);
44824+ free_page((unsigned long)buffer_exec);
44825+ free_page((unsigned long)buffer_fault);
44826+ pax_report_insns(regs, pc, sp);
44827+ do_coredump(SIGKILL, SIGKILL, regs);
44828+}
44829+#endif
44830+
44831+#ifdef CONFIG_PAX_REFCOUNT
44832+void pax_report_refcount_overflow(struct pt_regs *regs)
44833+{
44834+ if (current->signal->curr_ip)
44835+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44836+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
44837+ else
44838+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44839+ current->comm, task_pid_nr(current), current_uid(), current_euid());
44840+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
44841+ show_regs(regs);
44842+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
44843+}
44844+#endif
44845+
44846+#ifdef CONFIG_PAX_USERCOPY
44847+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
44848+static noinline int check_stack_object(const void *obj, unsigned long len)
44849+{
44850+ const void * const stack = task_stack_page(current);
44851+ const void * const stackend = stack + THREAD_SIZE;
44852+
44853+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44854+ const void *frame = NULL;
44855+ const void *oldframe;
44856+#endif
44857+
44858+ if (obj + len < obj)
44859+ return -1;
44860+
44861+ if (obj + len <= stack || stackend <= obj)
44862+ return 0;
44863+
44864+ if (obj < stack || stackend < obj + len)
44865+ return -1;
44866+
44867+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44868+ oldframe = __builtin_frame_address(1);
44869+ if (oldframe)
44870+ frame = __builtin_frame_address(2);
44871+ /*
44872+ low ----------------------------------------------> high
44873+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
44874+ ^----------------^
44875+ allow copies only within here
44876+ */
44877+ while (stack <= frame && frame < stackend) {
44878+ /* if obj + len extends past the last frame, this
44879+ check won't pass and the next frame will be 0,
44880+ causing us to bail out and correctly report
44881+ the copy as invalid
44882+ */
44883+ if (obj + len <= frame)
44884+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
44885+ oldframe = frame;
44886+ frame = *(const void * const *)frame;
44887+ }
44888+ return -1;
44889+#else
44890+ return 1;
44891+#endif
44892+}
44893+
44894+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
44895+{
44896+ if (current->signal->curr_ip)
44897+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44898+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44899+ else
44900+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44901+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44902+ dump_stack();
44903+ gr_handle_kernel_exploit();
44904+ do_group_exit(SIGKILL);
44905+}
44906+#endif
44907+
44908+void check_object_size(const void *ptr, unsigned long n, bool to)
44909+{
44910+
44911+#ifdef CONFIG_PAX_USERCOPY
44912+ const char *type;
44913+
44914+ if (!n)
44915+ return;
44916+
44917+ type = check_heap_object(ptr, n, to);
44918+ if (!type) {
44919+ if (check_stack_object(ptr, n) != -1)
44920+ return;
44921+ type = "<process stack>";
44922+ }
44923+
44924+ pax_report_usercopy(ptr, n, to, type);
44925+#endif
44926+
44927+}
44928+EXPORT_SYMBOL(check_object_size);
44929+
44930+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
44931+void pax_track_stack(void)
44932+{
44933+ unsigned long sp = (unsigned long)&sp;
44934+ if (sp < current_thread_info()->lowest_stack &&
44935+ sp > (unsigned long)task_stack_page(current))
44936+ current_thread_info()->lowest_stack = sp;
44937+}
44938+EXPORT_SYMBOL(pax_track_stack);
44939+#endif
44940+
44941+#ifdef CONFIG_PAX_SIZE_OVERFLOW
44942+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
44943+{
44944+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
44945+ dump_stack();
44946+ do_group_exit(SIGKILL);
44947+}
44948+EXPORT_SYMBOL(report_size_overflow);
44949+#endif
44950+
44951 static int zap_process(struct task_struct *start, int exit_code)
44952 {
44953 struct task_struct *t;
44954@@ -2002,17 +2378,17 @@ static void coredump_finish(struct mm_struct *mm)
44955 void set_dumpable(struct mm_struct *mm, int value)
44956 {
44957 switch (value) {
44958- case 0:
44959+ case SUID_DUMPABLE_DISABLED:
44960 clear_bit(MMF_DUMPABLE, &mm->flags);
44961 smp_wmb();
44962 clear_bit(MMF_DUMP_SECURELY, &mm->flags);
44963 break;
44964- case 1:
44965+ case SUID_DUMPABLE_ENABLED:
44966 set_bit(MMF_DUMPABLE, &mm->flags);
44967 smp_wmb();
44968 clear_bit(MMF_DUMP_SECURELY, &mm->flags);
44969 break;
44970- case 2:
44971+ case SUID_DUMPABLE_SAFE:
44972 set_bit(MMF_DUMP_SECURELY, &mm->flags);
44973 smp_wmb();
44974 set_bit(MMF_DUMPABLE, &mm->flags);
44975@@ -2025,7 +2401,7 @@ static int __get_dumpable(unsigned long mm_flags)
44976 int ret;
44977
44978 ret = mm_flags & MMF_DUMPABLE_MASK;
44979- return (ret >= 2) ? 2 : ret;
44980+ return (ret > SUID_DUMPABLE_ENABLED) ? SUID_DUMPABLE_SAFE : ret;
44981 }
44982
44983 int get_dumpable(struct mm_struct *mm)
44984@@ -2040,17 +2416,17 @@ static void wait_for_dump_helpers(struct file *file)
44985 pipe = file->f_path.dentry->d_inode->i_pipe;
44986
44987 pipe_lock(pipe);
44988- pipe->readers++;
44989- pipe->writers--;
44990+ atomic_inc(&pipe->readers);
44991+ atomic_dec(&pipe->writers);
44992
44993- while ((pipe->readers > 1) && (!signal_pending(current))) {
44994+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
44995 wake_up_interruptible_sync(&pipe->wait);
44996 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
44997 pipe_wait(pipe);
44998 }
44999
45000- pipe->readers--;
45001- pipe->writers++;
45002+ atomic_dec(&pipe->readers);
45003+ atomic_inc(&pipe->writers);
45004 pipe_unlock(pipe);
45005
45006 }
45007@@ -2111,7 +2487,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45008 int retval = 0;
45009 int flag = 0;
45010 int ispipe;
45011- static atomic_t core_dump_count = ATOMIC_INIT(0);
45012+ bool need_nonrelative = false;
45013+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
45014 struct coredump_params cprm = {
45015 .signr = signr,
45016 .regs = regs,
45017@@ -2126,6 +2503,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45018
45019 audit_core_dumps(signr);
45020
45021+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
45022+ gr_handle_brute_attach(current, cprm.mm_flags);
45023+
45024 binfmt = mm->binfmt;
45025 if (!binfmt || !binfmt->core_dump)
45026 goto fail;
45027@@ -2136,14 +2516,16 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45028 if (!cred)
45029 goto fail;
45030 /*
45031- * We cannot trust fsuid as being the "true" uid of the
45032- * process nor do we know its entire history. We only know it
45033- * was tainted so we dump it as root in mode 2.
45034+ * We cannot trust fsuid as being the "true" uid of the process
45035+ * nor do we know its entire history. We only know it was tainted
45036+ * so we dump it as root in mode 2, and only into a controlled
45037+ * environment (pipe handler or fully qualified path).
45038 */
45039- if (__get_dumpable(cprm.mm_flags) == 2) {
45040+ if (__get_dumpable(cprm.mm_flags) == SUID_DUMPABLE_SAFE) {
45041 /* Setuid core dump mode */
45042 flag = O_EXCL; /* Stop rewrite attacks */
45043 cred->fsuid = GLOBAL_ROOT_UID; /* Dump root private */
45044+ need_nonrelative = true;
45045 }
45046
45047 retval = coredump_wait(exit_code, &core_state);
45048@@ -2193,7 +2575,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45049 }
45050 cprm.limit = RLIM_INFINITY;
45051
45052- dump_count = atomic_inc_return(&core_dump_count);
45053+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
45054 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
45055 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
45056 task_tgid_vnr(current), current->comm);
45057@@ -2220,9 +2602,19 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45058 } else {
45059 struct inode *inode;
45060
45061+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
45062+
45063 if (cprm.limit < binfmt->min_coredump)
45064 goto fail_unlock;
45065
45066+ if (need_nonrelative && cn.corename[0] != '/') {
45067+ printk(KERN_WARNING "Pid %d(%s) can only dump core "\
45068+ "to fully qualified path!\n",
45069+ task_tgid_vnr(current), current->comm);
45070+ printk(KERN_WARNING "Skipping core dump\n");
45071+ goto fail_unlock;
45072+ }
45073+
45074 cprm.file = filp_open(cn.corename,
45075 O_CREAT | 2 | O_NOFOLLOW | O_LARGEFILE | flag,
45076 0600);
45077@@ -2263,7 +2655,7 @@ close_fail:
45078 filp_close(cprm.file, NULL);
45079 fail_dropcount:
45080 if (ispipe)
45081- atomic_dec(&core_dump_count);
45082+ atomic_dec_unchecked(&core_dump_count);
45083 fail_unlock:
45084 kfree(cn.corename);
45085 fail_corename:
45086@@ -2282,7 +2674,7 @@ fail:
45087 */
45088 int dump_write(struct file *file, const void *addr, int nr)
45089 {
45090- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
45091+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
45092 }
45093 EXPORT_SYMBOL(dump_write);
45094
45095diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
45096index 1c36139..cf6b350 100644
45097--- a/fs/ext2/balloc.c
45098+++ b/fs/ext2/balloc.c
45099@@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
45100
45101 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45102 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45103- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45104+ if (free_blocks < root_blocks + 1 &&
45105 !uid_eq(sbi->s_resuid, current_fsuid()) &&
45106 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45107- !in_group_p (sbi->s_resgid))) {
45108+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45109 return 0;
45110 }
45111 return 1;
45112diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
45113index 25cd608..9ed5294 100644
45114--- a/fs/ext3/balloc.c
45115+++ b/fs/ext3/balloc.c
45116@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
45117
45118 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45119 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45120- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45121+ if (free_blocks < root_blocks + 1 &&
45122 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
45123 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45124- !in_group_p (sbi->s_resgid))) {
45125+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45126 return 0;
45127 }
45128 return 1;
45129diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
45130index d23b31c..0585239 100644
45131--- a/fs/ext4/balloc.c
45132+++ b/fs/ext4/balloc.c
45133@@ -488,8 +488,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
45134 /* Hm, nope. Are (enough) root reserved clusters available? */
45135 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
45136 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
45137- capable(CAP_SYS_RESOURCE) ||
45138- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
45139+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
45140+ capable_nolog(CAP_SYS_RESOURCE)) {
45141
45142 if (free_clusters >= (nclusters + dirty_clusters))
45143 return 1;
45144diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
45145index 01434f2..bd995b4 100644
45146--- a/fs/ext4/ext4.h
45147+++ b/fs/ext4/ext4.h
45148@@ -1246,19 +1246,19 @@ struct ext4_sb_info {
45149 unsigned long s_mb_last_start;
45150
45151 /* stats for buddy allocator */
45152- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45153- atomic_t s_bal_success; /* we found long enough chunks */
45154- atomic_t s_bal_allocated; /* in blocks */
45155- atomic_t s_bal_ex_scanned; /* total extents scanned */
45156- atomic_t s_bal_goals; /* goal hits */
45157- atomic_t s_bal_breaks; /* too long searches */
45158- atomic_t s_bal_2orders; /* 2^order hits */
45159+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45160+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45161+ atomic_unchecked_t s_bal_allocated; /* in blocks */
45162+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45163+ atomic_unchecked_t s_bal_goals; /* goal hits */
45164+ atomic_unchecked_t s_bal_breaks; /* too long searches */
45165+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45166 spinlock_t s_bal_lock;
45167 unsigned long s_mb_buddies_generated;
45168 unsigned long long s_mb_generation_time;
45169- atomic_t s_mb_lost_chunks;
45170- atomic_t s_mb_preallocated;
45171- atomic_t s_mb_discarded;
45172+ atomic_unchecked_t s_mb_lost_chunks;
45173+ atomic_unchecked_t s_mb_preallocated;
45174+ atomic_unchecked_t s_mb_discarded;
45175 atomic_t s_lock_busy;
45176
45177 /* locality groups */
45178diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
45179index 58a75fe..9752106 100644
45180--- a/fs/ext4/extents.c
45181+++ b/fs/ext4/extents.c
45182@@ -2663,6 +2663,7 @@ cont:
45183 }
45184 path[0].p_depth = depth;
45185 path[0].p_hdr = ext_inode_hdr(inode);
45186+ i = 0;
45187
45188 if (ext4_ext_check(inode, path[0].p_hdr, depth)) {
45189 err = -EIO;
45190diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
45191index 1cd6994..5799d45 100644
45192--- a/fs/ext4/mballoc.c
45193+++ b/fs/ext4/mballoc.c
45194@@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
45195 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45196
45197 if (EXT4_SB(sb)->s_mb_stats)
45198- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45199+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45200
45201 break;
45202 }
45203@@ -2041,7 +2041,7 @@ repeat:
45204 ac->ac_status = AC_STATUS_CONTINUE;
45205 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45206 cr = 3;
45207- atomic_inc(&sbi->s_mb_lost_chunks);
45208+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45209 goto repeat;
45210 }
45211 }
45212@@ -2545,25 +2545,25 @@ int ext4_mb_release(struct super_block *sb)
45213 if (sbi->s_mb_stats) {
45214 ext4_msg(sb, KERN_INFO,
45215 "mballoc: %u blocks %u reqs (%u success)",
45216- atomic_read(&sbi->s_bal_allocated),
45217- atomic_read(&sbi->s_bal_reqs),
45218- atomic_read(&sbi->s_bal_success));
45219+ atomic_read_unchecked(&sbi->s_bal_allocated),
45220+ atomic_read_unchecked(&sbi->s_bal_reqs),
45221+ atomic_read_unchecked(&sbi->s_bal_success));
45222 ext4_msg(sb, KERN_INFO,
45223 "mballoc: %u extents scanned, %u goal hits, "
45224 "%u 2^N hits, %u breaks, %u lost",
45225- atomic_read(&sbi->s_bal_ex_scanned),
45226- atomic_read(&sbi->s_bal_goals),
45227- atomic_read(&sbi->s_bal_2orders),
45228- atomic_read(&sbi->s_bal_breaks),
45229- atomic_read(&sbi->s_mb_lost_chunks));
45230+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45231+ atomic_read_unchecked(&sbi->s_bal_goals),
45232+ atomic_read_unchecked(&sbi->s_bal_2orders),
45233+ atomic_read_unchecked(&sbi->s_bal_breaks),
45234+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45235 ext4_msg(sb, KERN_INFO,
45236 "mballoc: %lu generated and it took %Lu",
45237 sbi->s_mb_buddies_generated,
45238 sbi->s_mb_generation_time);
45239 ext4_msg(sb, KERN_INFO,
45240 "mballoc: %u preallocated, %u discarded",
45241- atomic_read(&sbi->s_mb_preallocated),
45242- atomic_read(&sbi->s_mb_discarded));
45243+ atomic_read_unchecked(&sbi->s_mb_preallocated),
45244+ atomic_read_unchecked(&sbi->s_mb_discarded));
45245 }
45246
45247 free_percpu(sbi->s_locality_groups);
45248@@ -3047,16 +3047,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
45249 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45250
45251 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45252- atomic_inc(&sbi->s_bal_reqs);
45253- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45254+ atomic_inc_unchecked(&sbi->s_bal_reqs);
45255+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45256 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
45257- atomic_inc(&sbi->s_bal_success);
45258- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45259+ atomic_inc_unchecked(&sbi->s_bal_success);
45260+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45261 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45262 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45263- atomic_inc(&sbi->s_bal_goals);
45264+ atomic_inc_unchecked(&sbi->s_bal_goals);
45265 if (ac->ac_found > sbi->s_mb_max_to_scan)
45266- atomic_inc(&sbi->s_bal_breaks);
45267+ atomic_inc_unchecked(&sbi->s_bal_breaks);
45268 }
45269
45270 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45271@@ -3456,7 +3456,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
45272 trace_ext4_mb_new_inode_pa(ac, pa);
45273
45274 ext4_mb_use_inode_pa(ac, pa);
45275- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
45276+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
45277
45278 ei = EXT4_I(ac->ac_inode);
45279 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45280@@ -3516,7 +3516,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
45281 trace_ext4_mb_new_group_pa(ac, pa);
45282
45283 ext4_mb_use_group_pa(ac, pa);
45284- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45285+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45286
45287 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45288 lg = ac->ac_lg;
45289@@ -3605,7 +3605,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
45290 * from the bitmap and continue.
45291 */
45292 }
45293- atomic_add(free, &sbi->s_mb_discarded);
45294+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
45295
45296 return err;
45297 }
45298@@ -3623,7 +3623,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
45299 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
45300 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
45301 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
45302- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45303+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45304 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
45305
45306 return 0;
45307diff --git a/fs/fcntl.c b/fs/fcntl.c
45308index 81b70e6..d9ae6cf 100644
45309--- a/fs/fcntl.c
45310+++ b/fs/fcntl.c
45311@@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
45312 if (err)
45313 return err;
45314
45315+ if (gr_handle_chroot_fowner(pid, type))
45316+ return -ENOENT;
45317+ if (gr_check_protected_task_fowner(pid, type))
45318+ return -EACCES;
45319+
45320 f_modown(filp, pid, type, force);
45321 return 0;
45322 }
45323@@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
45324
45325 static int f_setown_ex(struct file *filp, unsigned long arg)
45326 {
45327- struct f_owner_ex * __user owner_p = (void * __user)arg;
45328+ struct f_owner_ex __user *owner_p = (void __user *)arg;
45329 struct f_owner_ex owner;
45330 struct pid *pid;
45331 int type;
45332@@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
45333
45334 static int f_getown_ex(struct file *filp, unsigned long arg)
45335 {
45336- struct f_owner_ex * __user owner_p = (void * __user)arg;
45337+ struct f_owner_ex __user *owner_p = (void __user *)arg;
45338 struct f_owner_ex owner;
45339 int ret = 0;
45340
45341@@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
45342 switch (cmd) {
45343 case F_DUPFD:
45344 case F_DUPFD_CLOEXEC:
45345+ gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
45346 if (arg >= rlimit(RLIMIT_NOFILE))
45347 break;
45348 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
45349diff --git a/fs/fifo.c b/fs/fifo.c
45350index cf6f434..3d7942c 100644
45351--- a/fs/fifo.c
45352+++ b/fs/fifo.c
45353@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
45354 */
45355 filp->f_op = &read_pipefifo_fops;
45356 pipe->r_counter++;
45357- if (pipe->readers++ == 0)
45358+ if (atomic_inc_return(&pipe->readers) == 1)
45359 wake_up_partner(inode);
45360
45361- if (!pipe->writers) {
45362+ if (!atomic_read(&pipe->writers)) {
45363 if ((filp->f_flags & O_NONBLOCK)) {
45364 /* suppress POLLHUP until we have
45365 * seen a writer */
45366@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
45367 * errno=ENXIO when there is no process reading the FIFO.
45368 */
45369 ret = -ENXIO;
45370- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
45371+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
45372 goto err;
45373
45374 filp->f_op = &write_pipefifo_fops;
45375 pipe->w_counter++;
45376- if (!pipe->writers++)
45377+ if (atomic_inc_return(&pipe->writers) == 1)
45378 wake_up_partner(inode);
45379
45380- if (!pipe->readers) {
45381+ if (!atomic_read(&pipe->readers)) {
45382 if (wait_for_partner(inode, &pipe->r_counter))
45383 goto err_wr;
45384 }
45385@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
45386 */
45387 filp->f_op = &rdwr_pipefifo_fops;
45388
45389- pipe->readers++;
45390- pipe->writers++;
45391+ atomic_inc(&pipe->readers);
45392+ atomic_inc(&pipe->writers);
45393 pipe->r_counter++;
45394 pipe->w_counter++;
45395- if (pipe->readers == 1 || pipe->writers == 1)
45396+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
45397 wake_up_partner(inode);
45398 break;
45399
45400@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
45401 return 0;
45402
45403 err_rd:
45404- if (!--pipe->readers)
45405+ if (atomic_dec_and_test(&pipe->readers))
45406 wake_up_interruptible(&pipe->wait);
45407 ret = -ERESTARTSYS;
45408 goto err;
45409
45410 err_wr:
45411- if (!--pipe->writers)
45412+ if (atomic_dec_and_test(&pipe->writers))
45413 wake_up_interruptible(&pipe->wait);
45414 ret = -ERESTARTSYS;
45415 goto err;
45416
45417 err:
45418- if (!pipe->readers && !pipe->writers)
45419+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
45420 free_pipe_info(inode);
45421
45422 err_nocleanup:
45423diff --git a/fs/file.c b/fs/file.c
45424index ba3f605..fade102 100644
45425--- a/fs/file.c
45426+++ b/fs/file.c
45427@@ -15,6 +15,7 @@
45428 #include <linux/slab.h>
45429 #include <linux/vmalloc.h>
45430 #include <linux/file.h>
45431+#include <linux/security.h>
45432 #include <linux/fdtable.h>
45433 #include <linux/bitops.h>
45434 #include <linux/interrupt.h>
45435@@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
45436 * N.B. For clone tasks sharing a files structure, this test
45437 * will limit the total number of files that can be opened.
45438 */
45439+ gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
45440 if (nr >= rlimit(RLIMIT_NOFILE))
45441 return -EMFILE;
45442
45443diff --git a/fs/filesystems.c b/fs/filesystems.c
45444index 96f2428..f5eeb8e 100644
45445--- a/fs/filesystems.c
45446+++ b/fs/filesystems.c
45447@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
45448 int len = dot ? dot - name : strlen(name);
45449
45450 fs = __get_fs_type(name, len);
45451+
45452+#ifdef CONFIG_GRKERNSEC_MODHARDEN
45453+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
45454+#else
45455 if (!fs && (request_module("%.*s", len, name) == 0))
45456+#endif
45457 fs = __get_fs_type(name, len);
45458
45459 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
45460diff --git a/fs/fs_struct.c b/fs/fs_struct.c
45461index e159e68..e7d2a6f 100644
45462--- a/fs/fs_struct.c
45463+++ b/fs/fs_struct.c
45464@@ -4,6 +4,7 @@
45465 #include <linux/path.h>
45466 #include <linux/slab.h>
45467 #include <linux/fs_struct.h>
45468+#include <linux/grsecurity.h>
45469 #include "internal.h"
45470
45471 static inline void path_get_longterm(struct path *path)
45472@@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
45473 write_seqcount_begin(&fs->seq);
45474 old_root = fs->root;
45475 fs->root = *path;
45476+ gr_set_chroot_entries(current, path);
45477 write_seqcount_end(&fs->seq);
45478 spin_unlock(&fs->lock);
45479 if (old_root.dentry)
45480@@ -65,6 +67,17 @@ static inline int replace_path(struct path *p, const struct path *old, const str
45481 return 1;
45482 }
45483
45484+static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
45485+{
45486+ if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
45487+ return 0;
45488+ *p = *new;
45489+
45490+ gr_set_chroot_entries(task, new);
45491+
45492+ return 1;
45493+}
45494+
45495 void chroot_fs_refs(struct path *old_root, struct path *new_root)
45496 {
45497 struct task_struct *g, *p;
45498@@ -79,7 +92,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
45499 int hits = 0;
45500 spin_lock(&fs->lock);
45501 write_seqcount_begin(&fs->seq);
45502- hits += replace_path(&fs->root, old_root, new_root);
45503+ hits += replace_root_path(p, &fs->root, old_root, new_root);
45504 hits += replace_path(&fs->pwd, old_root, new_root);
45505 write_seqcount_end(&fs->seq);
45506 while (hits--) {
45507@@ -111,7 +124,8 @@ void exit_fs(struct task_struct *tsk)
45508 task_lock(tsk);
45509 spin_lock(&fs->lock);
45510 tsk->fs = NULL;
45511- kill = !--fs->users;
45512+ gr_clear_chroot_entries(tsk);
45513+ kill = !atomic_dec_return(&fs->users);
45514 spin_unlock(&fs->lock);
45515 task_unlock(tsk);
45516 if (kill)
45517@@ -124,7 +138,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45518 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
45519 /* We don't need to lock fs - think why ;-) */
45520 if (fs) {
45521- fs->users = 1;
45522+ atomic_set(&fs->users, 1);
45523 fs->in_exec = 0;
45524 spin_lock_init(&fs->lock);
45525 seqcount_init(&fs->seq);
45526@@ -133,6 +147,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45527 spin_lock(&old->lock);
45528 fs->root = old->root;
45529 path_get_longterm(&fs->root);
45530+ /* instead of calling gr_set_chroot_entries here,
45531+ we call it from every caller of this function
45532+ */
45533 fs->pwd = old->pwd;
45534 path_get_longterm(&fs->pwd);
45535 spin_unlock(&old->lock);
45536@@ -151,8 +168,9 @@ int unshare_fs_struct(void)
45537
45538 task_lock(current);
45539 spin_lock(&fs->lock);
45540- kill = !--fs->users;
45541+ kill = !atomic_dec_return(&fs->users);
45542 current->fs = new_fs;
45543+ gr_set_chroot_entries(current, &new_fs->root);
45544 spin_unlock(&fs->lock);
45545 task_unlock(current);
45546
45547@@ -165,13 +183,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
45548
45549 int current_umask(void)
45550 {
45551- return current->fs->umask;
45552+ return current->fs->umask | gr_acl_umask();
45553 }
45554 EXPORT_SYMBOL(current_umask);
45555
45556 /* to be mentioned only in INIT_TASK */
45557 struct fs_struct init_fs = {
45558- .users = 1,
45559+ .users = ATOMIC_INIT(1),
45560 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
45561 .seq = SEQCNT_ZERO,
45562 .umask = 0022,
45563@@ -187,12 +205,13 @@ void daemonize_fs_struct(void)
45564 task_lock(current);
45565
45566 spin_lock(&init_fs.lock);
45567- init_fs.users++;
45568+ atomic_inc(&init_fs.users);
45569 spin_unlock(&init_fs.lock);
45570
45571 spin_lock(&fs->lock);
45572 current->fs = &init_fs;
45573- kill = !--fs->users;
45574+ gr_set_chroot_entries(current, &current->fs->root);
45575+ kill = !atomic_dec_return(&fs->users);
45576 spin_unlock(&fs->lock);
45577
45578 task_unlock(current);
45579diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
45580index 9905350..02eaec4 100644
45581--- a/fs/fscache/cookie.c
45582+++ b/fs/fscache/cookie.c
45583@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
45584 parent ? (char *) parent->def->name : "<no-parent>",
45585 def->name, netfs_data);
45586
45587- fscache_stat(&fscache_n_acquires);
45588+ fscache_stat_unchecked(&fscache_n_acquires);
45589
45590 /* if there's no parent cookie, then we don't create one here either */
45591 if (!parent) {
45592- fscache_stat(&fscache_n_acquires_null);
45593+ fscache_stat_unchecked(&fscache_n_acquires_null);
45594 _leave(" [no parent]");
45595 return NULL;
45596 }
45597@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
45598 /* allocate and initialise a cookie */
45599 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
45600 if (!cookie) {
45601- fscache_stat(&fscache_n_acquires_oom);
45602+ fscache_stat_unchecked(&fscache_n_acquires_oom);
45603 _leave(" [ENOMEM]");
45604 return NULL;
45605 }
45606@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45607
45608 switch (cookie->def->type) {
45609 case FSCACHE_COOKIE_TYPE_INDEX:
45610- fscache_stat(&fscache_n_cookie_index);
45611+ fscache_stat_unchecked(&fscache_n_cookie_index);
45612 break;
45613 case FSCACHE_COOKIE_TYPE_DATAFILE:
45614- fscache_stat(&fscache_n_cookie_data);
45615+ fscache_stat_unchecked(&fscache_n_cookie_data);
45616 break;
45617 default:
45618- fscache_stat(&fscache_n_cookie_special);
45619+ fscache_stat_unchecked(&fscache_n_cookie_special);
45620 break;
45621 }
45622
45623@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45624 if (fscache_acquire_non_index_cookie(cookie) < 0) {
45625 atomic_dec(&parent->n_children);
45626 __fscache_cookie_put(cookie);
45627- fscache_stat(&fscache_n_acquires_nobufs);
45628+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
45629 _leave(" = NULL");
45630 return NULL;
45631 }
45632 }
45633
45634- fscache_stat(&fscache_n_acquires_ok);
45635+ fscache_stat_unchecked(&fscache_n_acquires_ok);
45636 _leave(" = %p", cookie);
45637 return cookie;
45638 }
45639@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
45640 cache = fscache_select_cache_for_object(cookie->parent);
45641 if (!cache) {
45642 up_read(&fscache_addremove_sem);
45643- fscache_stat(&fscache_n_acquires_no_cache);
45644+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
45645 _leave(" = -ENOMEDIUM [no cache]");
45646 return -ENOMEDIUM;
45647 }
45648@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
45649 object = cache->ops->alloc_object(cache, cookie);
45650 fscache_stat_d(&fscache_n_cop_alloc_object);
45651 if (IS_ERR(object)) {
45652- fscache_stat(&fscache_n_object_no_alloc);
45653+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
45654 ret = PTR_ERR(object);
45655 goto error;
45656 }
45657
45658- fscache_stat(&fscache_n_object_alloc);
45659+ fscache_stat_unchecked(&fscache_n_object_alloc);
45660
45661 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
45662
45663@@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
45664 struct fscache_object *object;
45665 struct hlist_node *_p;
45666
45667- fscache_stat(&fscache_n_updates);
45668+ fscache_stat_unchecked(&fscache_n_updates);
45669
45670 if (!cookie) {
45671- fscache_stat(&fscache_n_updates_null);
45672+ fscache_stat_unchecked(&fscache_n_updates_null);
45673 _leave(" [no cookie]");
45674 return;
45675 }
45676@@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45677 struct fscache_object *object;
45678 unsigned long event;
45679
45680- fscache_stat(&fscache_n_relinquishes);
45681+ fscache_stat_unchecked(&fscache_n_relinquishes);
45682 if (retire)
45683- fscache_stat(&fscache_n_relinquishes_retire);
45684+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
45685
45686 if (!cookie) {
45687- fscache_stat(&fscache_n_relinquishes_null);
45688+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
45689 _leave(" [no cookie]");
45690 return;
45691 }
45692@@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45693
45694 /* wait for the cookie to finish being instantiated (or to fail) */
45695 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
45696- fscache_stat(&fscache_n_relinquishes_waitcrt);
45697+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
45698 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
45699 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
45700 }
45701diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
45702index f6aad48..88dcf26 100644
45703--- a/fs/fscache/internal.h
45704+++ b/fs/fscache/internal.h
45705@@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
45706 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
45707 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
45708
45709-extern atomic_t fscache_n_op_pend;
45710-extern atomic_t fscache_n_op_run;
45711-extern atomic_t fscache_n_op_enqueue;
45712-extern atomic_t fscache_n_op_deferred_release;
45713-extern atomic_t fscache_n_op_release;
45714-extern atomic_t fscache_n_op_gc;
45715-extern atomic_t fscache_n_op_cancelled;
45716-extern atomic_t fscache_n_op_rejected;
45717+extern atomic_unchecked_t fscache_n_op_pend;
45718+extern atomic_unchecked_t fscache_n_op_run;
45719+extern atomic_unchecked_t fscache_n_op_enqueue;
45720+extern atomic_unchecked_t fscache_n_op_deferred_release;
45721+extern atomic_unchecked_t fscache_n_op_release;
45722+extern atomic_unchecked_t fscache_n_op_gc;
45723+extern atomic_unchecked_t fscache_n_op_cancelled;
45724+extern atomic_unchecked_t fscache_n_op_rejected;
45725
45726-extern atomic_t fscache_n_attr_changed;
45727-extern atomic_t fscache_n_attr_changed_ok;
45728-extern atomic_t fscache_n_attr_changed_nobufs;
45729-extern atomic_t fscache_n_attr_changed_nomem;
45730-extern atomic_t fscache_n_attr_changed_calls;
45731+extern atomic_unchecked_t fscache_n_attr_changed;
45732+extern atomic_unchecked_t fscache_n_attr_changed_ok;
45733+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
45734+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
45735+extern atomic_unchecked_t fscache_n_attr_changed_calls;
45736
45737-extern atomic_t fscache_n_allocs;
45738-extern atomic_t fscache_n_allocs_ok;
45739-extern atomic_t fscache_n_allocs_wait;
45740-extern atomic_t fscache_n_allocs_nobufs;
45741-extern atomic_t fscache_n_allocs_intr;
45742-extern atomic_t fscache_n_allocs_object_dead;
45743-extern atomic_t fscache_n_alloc_ops;
45744-extern atomic_t fscache_n_alloc_op_waits;
45745+extern atomic_unchecked_t fscache_n_allocs;
45746+extern atomic_unchecked_t fscache_n_allocs_ok;
45747+extern atomic_unchecked_t fscache_n_allocs_wait;
45748+extern atomic_unchecked_t fscache_n_allocs_nobufs;
45749+extern atomic_unchecked_t fscache_n_allocs_intr;
45750+extern atomic_unchecked_t fscache_n_allocs_object_dead;
45751+extern atomic_unchecked_t fscache_n_alloc_ops;
45752+extern atomic_unchecked_t fscache_n_alloc_op_waits;
45753
45754-extern atomic_t fscache_n_retrievals;
45755-extern atomic_t fscache_n_retrievals_ok;
45756-extern atomic_t fscache_n_retrievals_wait;
45757-extern atomic_t fscache_n_retrievals_nodata;
45758-extern atomic_t fscache_n_retrievals_nobufs;
45759-extern atomic_t fscache_n_retrievals_intr;
45760-extern atomic_t fscache_n_retrievals_nomem;
45761-extern atomic_t fscache_n_retrievals_object_dead;
45762-extern atomic_t fscache_n_retrieval_ops;
45763-extern atomic_t fscache_n_retrieval_op_waits;
45764+extern atomic_unchecked_t fscache_n_retrievals;
45765+extern atomic_unchecked_t fscache_n_retrievals_ok;
45766+extern atomic_unchecked_t fscache_n_retrievals_wait;
45767+extern atomic_unchecked_t fscache_n_retrievals_nodata;
45768+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
45769+extern atomic_unchecked_t fscache_n_retrievals_intr;
45770+extern atomic_unchecked_t fscache_n_retrievals_nomem;
45771+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
45772+extern atomic_unchecked_t fscache_n_retrieval_ops;
45773+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
45774
45775-extern atomic_t fscache_n_stores;
45776-extern atomic_t fscache_n_stores_ok;
45777-extern atomic_t fscache_n_stores_again;
45778-extern atomic_t fscache_n_stores_nobufs;
45779-extern atomic_t fscache_n_stores_oom;
45780-extern atomic_t fscache_n_store_ops;
45781-extern atomic_t fscache_n_store_calls;
45782-extern atomic_t fscache_n_store_pages;
45783-extern atomic_t fscache_n_store_radix_deletes;
45784-extern atomic_t fscache_n_store_pages_over_limit;
45785+extern atomic_unchecked_t fscache_n_stores;
45786+extern atomic_unchecked_t fscache_n_stores_ok;
45787+extern atomic_unchecked_t fscache_n_stores_again;
45788+extern atomic_unchecked_t fscache_n_stores_nobufs;
45789+extern atomic_unchecked_t fscache_n_stores_oom;
45790+extern atomic_unchecked_t fscache_n_store_ops;
45791+extern atomic_unchecked_t fscache_n_store_calls;
45792+extern atomic_unchecked_t fscache_n_store_pages;
45793+extern atomic_unchecked_t fscache_n_store_radix_deletes;
45794+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
45795
45796-extern atomic_t fscache_n_store_vmscan_not_storing;
45797-extern atomic_t fscache_n_store_vmscan_gone;
45798-extern atomic_t fscache_n_store_vmscan_busy;
45799-extern atomic_t fscache_n_store_vmscan_cancelled;
45800+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45801+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
45802+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
45803+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45804
45805-extern atomic_t fscache_n_marks;
45806-extern atomic_t fscache_n_uncaches;
45807+extern atomic_unchecked_t fscache_n_marks;
45808+extern atomic_unchecked_t fscache_n_uncaches;
45809
45810-extern atomic_t fscache_n_acquires;
45811-extern atomic_t fscache_n_acquires_null;
45812-extern atomic_t fscache_n_acquires_no_cache;
45813-extern atomic_t fscache_n_acquires_ok;
45814-extern atomic_t fscache_n_acquires_nobufs;
45815-extern atomic_t fscache_n_acquires_oom;
45816+extern atomic_unchecked_t fscache_n_acquires;
45817+extern atomic_unchecked_t fscache_n_acquires_null;
45818+extern atomic_unchecked_t fscache_n_acquires_no_cache;
45819+extern atomic_unchecked_t fscache_n_acquires_ok;
45820+extern atomic_unchecked_t fscache_n_acquires_nobufs;
45821+extern atomic_unchecked_t fscache_n_acquires_oom;
45822
45823-extern atomic_t fscache_n_updates;
45824-extern atomic_t fscache_n_updates_null;
45825-extern atomic_t fscache_n_updates_run;
45826+extern atomic_unchecked_t fscache_n_updates;
45827+extern atomic_unchecked_t fscache_n_updates_null;
45828+extern atomic_unchecked_t fscache_n_updates_run;
45829
45830-extern atomic_t fscache_n_relinquishes;
45831-extern atomic_t fscache_n_relinquishes_null;
45832-extern atomic_t fscache_n_relinquishes_waitcrt;
45833-extern atomic_t fscache_n_relinquishes_retire;
45834+extern atomic_unchecked_t fscache_n_relinquishes;
45835+extern atomic_unchecked_t fscache_n_relinquishes_null;
45836+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
45837+extern atomic_unchecked_t fscache_n_relinquishes_retire;
45838
45839-extern atomic_t fscache_n_cookie_index;
45840-extern atomic_t fscache_n_cookie_data;
45841-extern atomic_t fscache_n_cookie_special;
45842+extern atomic_unchecked_t fscache_n_cookie_index;
45843+extern atomic_unchecked_t fscache_n_cookie_data;
45844+extern atomic_unchecked_t fscache_n_cookie_special;
45845
45846-extern atomic_t fscache_n_object_alloc;
45847-extern atomic_t fscache_n_object_no_alloc;
45848-extern atomic_t fscache_n_object_lookups;
45849-extern atomic_t fscache_n_object_lookups_negative;
45850-extern atomic_t fscache_n_object_lookups_positive;
45851-extern atomic_t fscache_n_object_lookups_timed_out;
45852-extern atomic_t fscache_n_object_created;
45853-extern atomic_t fscache_n_object_avail;
45854-extern atomic_t fscache_n_object_dead;
45855+extern atomic_unchecked_t fscache_n_object_alloc;
45856+extern atomic_unchecked_t fscache_n_object_no_alloc;
45857+extern atomic_unchecked_t fscache_n_object_lookups;
45858+extern atomic_unchecked_t fscache_n_object_lookups_negative;
45859+extern atomic_unchecked_t fscache_n_object_lookups_positive;
45860+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
45861+extern atomic_unchecked_t fscache_n_object_created;
45862+extern atomic_unchecked_t fscache_n_object_avail;
45863+extern atomic_unchecked_t fscache_n_object_dead;
45864
45865-extern atomic_t fscache_n_checkaux_none;
45866-extern atomic_t fscache_n_checkaux_okay;
45867-extern atomic_t fscache_n_checkaux_update;
45868-extern atomic_t fscache_n_checkaux_obsolete;
45869+extern atomic_unchecked_t fscache_n_checkaux_none;
45870+extern atomic_unchecked_t fscache_n_checkaux_okay;
45871+extern atomic_unchecked_t fscache_n_checkaux_update;
45872+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
45873
45874 extern atomic_t fscache_n_cop_alloc_object;
45875 extern atomic_t fscache_n_cop_lookup_object;
45876@@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
45877 atomic_inc(stat);
45878 }
45879
45880+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
45881+{
45882+ atomic_inc_unchecked(stat);
45883+}
45884+
45885 static inline void fscache_stat_d(atomic_t *stat)
45886 {
45887 atomic_dec(stat);
45888@@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
45889
45890 #define __fscache_stat(stat) (NULL)
45891 #define fscache_stat(stat) do {} while (0)
45892+#define fscache_stat_unchecked(stat) do {} while (0)
45893 #define fscache_stat_d(stat) do {} while (0)
45894 #endif
45895
45896diff --git a/fs/fscache/object.c b/fs/fscache/object.c
45897index b6b897c..0ffff9c 100644
45898--- a/fs/fscache/object.c
45899+++ b/fs/fscache/object.c
45900@@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45901 /* update the object metadata on disk */
45902 case FSCACHE_OBJECT_UPDATING:
45903 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
45904- fscache_stat(&fscache_n_updates_run);
45905+ fscache_stat_unchecked(&fscache_n_updates_run);
45906 fscache_stat(&fscache_n_cop_update_object);
45907 object->cache->ops->update_object(object);
45908 fscache_stat_d(&fscache_n_cop_update_object);
45909@@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45910 spin_lock(&object->lock);
45911 object->state = FSCACHE_OBJECT_DEAD;
45912 spin_unlock(&object->lock);
45913- fscache_stat(&fscache_n_object_dead);
45914+ fscache_stat_unchecked(&fscache_n_object_dead);
45915 goto terminal_transit;
45916
45917 /* handle the parent cache of this object being withdrawn from
45918@@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45919 spin_lock(&object->lock);
45920 object->state = FSCACHE_OBJECT_DEAD;
45921 spin_unlock(&object->lock);
45922- fscache_stat(&fscache_n_object_dead);
45923+ fscache_stat_unchecked(&fscache_n_object_dead);
45924 goto terminal_transit;
45925
45926 /* complain about the object being woken up once it is
45927@@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45928 parent->cookie->def->name, cookie->def->name,
45929 object->cache->tag->name);
45930
45931- fscache_stat(&fscache_n_object_lookups);
45932+ fscache_stat_unchecked(&fscache_n_object_lookups);
45933 fscache_stat(&fscache_n_cop_lookup_object);
45934 ret = object->cache->ops->lookup_object(object);
45935 fscache_stat_d(&fscache_n_cop_lookup_object);
45936@@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45937 if (ret == -ETIMEDOUT) {
45938 /* probably stuck behind another object, so move this one to
45939 * the back of the queue */
45940- fscache_stat(&fscache_n_object_lookups_timed_out);
45941+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
45942 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45943 }
45944
45945@@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
45946
45947 spin_lock(&object->lock);
45948 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45949- fscache_stat(&fscache_n_object_lookups_negative);
45950+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
45951
45952 /* transit here to allow write requests to begin stacking up
45953 * and read requests to begin returning ENODATA */
45954@@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
45955 * result, in which case there may be data available */
45956 spin_lock(&object->lock);
45957 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45958- fscache_stat(&fscache_n_object_lookups_positive);
45959+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
45960
45961 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
45962
45963@@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
45964 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45965 } else {
45966 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
45967- fscache_stat(&fscache_n_object_created);
45968+ fscache_stat_unchecked(&fscache_n_object_created);
45969
45970 object->state = FSCACHE_OBJECT_AVAILABLE;
45971 spin_unlock(&object->lock);
45972@@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
45973 fscache_enqueue_dependents(object);
45974
45975 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
45976- fscache_stat(&fscache_n_object_avail);
45977+ fscache_stat_unchecked(&fscache_n_object_avail);
45978
45979 _leave("");
45980 }
45981@@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45982 enum fscache_checkaux result;
45983
45984 if (!object->cookie->def->check_aux) {
45985- fscache_stat(&fscache_n_checkaux_none);
45986+ fscache_stat_unchecked(&fscache_n_checkaux_none);
45987 return FSCACHE_CHECKAUX_OKAY;
45988 }
45989
45990@@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45991 switch (result) {
45992 /* entry okay as is */
45993 case FSCACHE_CHECKAUX_OKAY:
45994- fscache_stat(&fscache_n_checkaux_okay);
45995+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
45996 break;
45997
45998 /* entry requires update */
45999 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
46000- fscache_stat(&fscache_n_checkaux_update);
46001+ fscache_stat_unchecked(&fscache_n_checkaux_update);
46002 break;
46003
46004 /* entry requires deletion */
46005 case FSCACHE_CHECKAUX_OBSOLETE:
46006- fscache_stat(&fscache_n_checkaux_obsolete);
46007+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
46008 break;
46009
46010 default:
46011diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
46012index 30afdfa..2256596 100644
46013--- a/fs/fscache/operation.c
46014+++ b/fs/fscache/operation.c
46015@@ -17,7 +17,7 @@
46016 #include <linux/slab.h>
46017 #include "internal.h"
46018
46019-atomic_t fscache_op_debug_id;
46020+atomic_unchecked_t fscache_op_debug_id;
46021 EXPORT_SYMBOL(fscache_op_debug_id);
46022
46023 /**
46024@@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
46025 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
46026 ASSERTCMP(atomic_read(&op->usage), >, 0);
46027
46028- fscache_stat(&fscache_n_op_enqueue);
46029+ fscache_stat_unchecked(&fscache_n_op_enqueue);
46030 switch (op->flags & FSCACHE_OP_TYPE) {
46031 case FSCACHE_OP_ASYNC:
46032 _debug("queue async");
46033@@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
46034 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
46035 if (op->processor)
46036 fscache_enqueue_operation(op);
46037- fscache_stat(&fscache_n_op_run);
46038+ fscache_stat_unchecked(&fscache_n_op_run);
46039 }
46040
46041 /*
46042@@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46043 if (object->n_ops > 1) {
46044 atomic_inc(&op->usage);
46045 list_add_tail(&op->pend_link, &object->pending_ops);
46046- fscache_stat(&fscache_n_op_pend);
46047+ fscache_stat_unchecked(&fscache_n_op_pend);
46048 } else if (!list_empty(&object->pending_ops)) {
46049 atomic_inc(&op->usage);
46050 list_add_tail(&op->pend_link, &object->pending_ops);
46051- fscache_stat(&fscache_n_op_pend);
46052+ fscache_stat_unchecked(&fscache_n_op_pend);
46053 fscache_start_operations(object);
46054 } else {
46055 ASSERTCMP(object->n_in_progress, ==, 0);
46056@@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46057 object->n_exclusive++; /* reads and writes must wait */
46058 atomic_inc(&op->usage);
46059 list_add_tail(&op->pend_link, &object->pending_ops);
46060- fscache_stat(&fscache_n_op_pend);
46061+ fscache_stat_unchecked(&fscache_n_op_pend);
46062 ret = 0;
46063 } else {
46064 /* not allowed to submit ops in any other state */
46065@@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
46066 if (object->n_exclusive > 0) {
46067 atomic_inc(&op->usage);
46068 list_add_tail(&op->pend_link, &object->pending_ops);
46069- fscache_stat(&fscache_n_op_pend);
46070+ fscache_stat_unchecked(&fscache_n_op_pend);
46071 } else if (!list_empty(&object->pending_ops)) {
46072 atomic_inc(&op->usage);
46073 list_add_tail(&op->pend_link, &object->pending_ops);
46074- fscache_stat(&fscache_n_op_pend);
46075+ fscache_stat_unchecked(&fscache_n_op_pend);
46076 fscache_start_operations(object);
46077 } else {
46078 ASSERTCMP(object->n_exclusive, ==, 0);
46079@@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
46080 object->n_ops++;
46081 atomic_inc(&op->usage);
46082 list_add_tail(&op->pend_link, &object->pending_ops);
46083- fscache_stat(&fscache_n_op_pend);
46084+ fscache_stat_unchecked(&fscache_n_op_pend);
46085 ret = 0;
46086 } else if (object->state == FSCACHE_OBJECT_DYING ||
46087 object->state == FSCACHE_OBJECT_LC_DYING ||
46088 object->state == FSCACHE_OBJECT_WITHDRAWING) {
46089- fscache_stat(&fscache_n_op_rejected);
46090+ fscache_stat_unchecked(&fscache_n_op_rejected);
46091 ret = -ENOBUFS;
46092 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
46093 fscache_report_unexpected_submission(object, op, ostate);
46094@@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
46095
46096 ret = -EBUSY;
46097 if (!list_empty(&op->pend_link)) {
46098- fscache_stat(&fscache_n_op_cancelled);
46099+ fscache_stat_unchecked(&fscache_n_op_cancelled);
46100 list_del_init(&op->pend_link);
46101 object->n_ops--;
46102 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
46103@@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
46104 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
46105 BUG();
46106
46107- fscache_stat(&fscache_n_op_release);
46108+ fscache_stat_unchecked(&fscache_n_op_release);
46109
46110 if (op->release) {
46111 op->release(op);
46112@@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
46113 * lock, and defer it otherwise */
46114 if (!spin_trylock(&object->lock)) {
46115 _debug("defer put");
46116- fscache_stat(&fscache_n_op_deferred_release);
46117+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
46118
46119 cache = object->cache;
46120 spin_lock(&cache->op_gc_list_lock);
46121@@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
46122
46123 _debug("GC DEFERRED REL OBJ%x OP%x",
46124 object->debug_id, op->debug_id);
46125- fscache_stat(&fscache_n_op_gc);
46126+ fscache_stat_unchecked(&fscache_n_op_gc);
46127
46128 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46129
46130diff --git a/fs/fscache/page.c b/fs/fscache/page.c
46131index 3f7a59b..cf196cc 100644
46132--- a/fs/fscache/page.c
46133+++ b/fs/fscache/page.c
46134@@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46135 val = radix_tree_lookup(&cookie->stores, page->index);
46136 if (!val) {
46137 rcu_read_unlock();
46138- fscache_stat(&fscache_n_store_vmscan_not_storing);
46139+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46140 __fscache_uncache_page(cookie, page);
46141 return true;
46142 }
46143@@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46144 spin_unlock(&cookie->stores_lock);
46145
46146 if (xpage) {
46147- fscache_stat(&fscache_n_store_vmscan_cancelled);
46148- fscache_stat(&fscache_n_store_radix_deletes);
46149+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46150+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46151 ASSERTCMP(xpage, ==, page);
46152 } else {
46153- fscache_stat(&fscache_n_store_vmscan_gone);
46154+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46155 }
46156
46157 wake_up_bit(&cookie->flags, 0);
46158@@ -107,7 +107,7 @@ page_busy:
46159 /* we might want to wait here, but that could deadlock the allocator as
46160 * the work threads writing to the cache may all end up sleeping
46161 * on memory allocation */
46162- fscache_stat(&fscache_n_store_vmscan_busy);
46163+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46164 return false;
46165 }
46166 EXPORT_SYMBOL(__fscache_maybe_release_page);
46167@@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
46168 FSCACHE_COOKIE_STORING_TAG);
46169 if (!radix_tree_tag_get(&cookie->stores, page->index,
46170 FSCACHE_COOKIE_PENDING_TAG)) {
46171- fscache_stat(&fscache_n_store_radix_deletes);
46172+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46173 xpage = radix_tree_delete(&cookie->stores, page->index);
46174 }
46175 spin_unlock(&cookie->stores_lock);
46176@@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
46177
46178 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46179
46180- fscache_stat(&fscache_n_attr_changed_calls);
46181+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46182
46183 if (fscache_object_is_active(object)) {
46184 fscache_stat(&fscache_n_cop_attr_changed);
46185@@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46186
46187 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46188
46189- fscache_stat(&fscache_n_attr_changed);
46190+ fscache_stat_unchecked(&fscache_n_attr_changed);
46191
46192 op = kzalloc(sizeof(*op), GFP_KERNEL);
46193 if (!op) {
46194- fscache_stat(&fscache_n_attr_changed_nomem);
46195+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46196 _leave(" = -ENOMEM");
46197 return -ENOMEM;
46198 }
46199@@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46200 if (fscache_submit_exclusive_op(object, op) < 0)
46201 goto nobufs;
46202 spin_unlock(&cookie->lock);
46203- fscache_stat(&fscache_n_attr_changed_ok);
46204+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46205 fscache_put_operation(op);
46206 _leave(" = 0");
46207 return 0;
46208@@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46209 nobufs:
46210 spin_unlock(&cookie->lock);
46211 kfree(op);
46212- fscache_stat(&fscache_n_attr_changed_nobufs);
46213+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46214 _leave(" = %d", -ENOBUFS);
46215 return -ENOBUFS;
46216 }
46217@@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
46218 /* allocate a retrieval operation and attempt to submit it */
46219 op = kzalloc(sizeof(*op), GFP_NOIO);
46220 if (!op) {
46221- fscache_stat(&fscache_n_retrievals_nomem);
46222+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46223 return NULL;
46224 }
46225
46226@@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46227 return 0;
46228 }
46229
46230- fscache_stat(&fscache_n_retrievals_wait);
46231+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
46232
46233 jif = jiffies;
46234 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46235 fscache_wait_bit_interruptible,
46236 TASK_INTERRUPTIBLE) != 0) {
46237- fscache_stat(&fscache_n_retrievals_intr);
46238+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
46239 _leave(" = -ERESTARTSYS");
46240 return -ERESTARTSYS;
46241 }
46242@@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46243 */
46244 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46245 struct fscache_retrieval *op,
46246- atomic_t *stat_op_waits,
46247- atomic_t *stat_object_dead)
46248+ atomic_unchecked_t *stat_op_waits,
46249+ atomic_unchecked_t *stat_object_dead)
46250 {
46251 int ret;
46252
46253@@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46254 goto check_if_dead;
46255
46256 _debug(">>> WT");
46257- fscache_stat(stat_op_waits);
46258+ fscache_stat_unchecked(stat_op_waits);
46259 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46260 fscache_wait_bit_interruptible,
46261 TASK_INTERRUPTIBLE) < 0) {
46262@@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46263
46264 check_if_dead:
46265 if (unlikely(fscache_object_is_dead(object))) {
46266- fscache_stat(stat_object_dead);
46267+ fscache_stat_unchecked(stat_object_dead);
46268 return -ENOBUFS;
46269 }
46270 return 0;
46271@@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46272
46273 _enter("%p,%p,,,", cookie, page);
46274
46275- fscache_stat(&fscache_n_retrievals);
46276+ fscache_stat_unchecked(&fscache_n_retrievals);
46277
46278 if (hlist_empty(&cookie->backing_objects))
46279 goto nobufs;
46280@@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46281 goto nobufs_unlock;
46282 spin_unlock(&cookie->lock);
46283
46284- fscache_stat(&fscache_n_retrieval_ops);
46285+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
46286
46287 /* pin the netfs read context in case we need to do the actual netfs
46288 * read because we've encountered a cache read failure */
46289@@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46290
46291 error:
46292 if (ret == -ENOMEM)
46293- fscache_stat(&fscache_n_retrievals_nomem);
46294+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46295 else if (ret == -ERESTARTSYS)
46296- fscache_stat(&fscache_n_retrievals_intr);
46297+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
46298 else if (ret == -ENODATA)
46299- fscache_stat(&fscache_n_retrievals_nodata);
46300+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46301 else if (ret < 0)
46302- fscache_stat(&fscache_n_retrievals_nobufs);
46303+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46304 else
46305- fscache_stat(&fscache_n_retrievals_ok);
46306+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
46307
46308 fscache_put_retrieval(op);
46309 _leave(" = %d", ret);
46310@@ -429,7 +429,7 @@ nobufs_unlock:
46311 spin_unlock(&cookie->lock);
46312 kfree(op);
46313 nobufs:
46314- fscache_stat(&fscache_n_retrievals_nobufs);
46315+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46316 _leave(" = -ENOBUFS");
46317 return -ENOBUFS;
46318 }
46319@@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46320
46321 _enter("%p,,%d,,,", cookie, *nr_pages);
46322
46323- fscache_stat(&fscache_n_retrievals);
46324+ fscache_stat_unchecked(&fscache_n_retrievals);
46325
46326 if (hlist_empty(&cookie->backing_objects))
46327 goto nobufs;
46328@@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46329 goto nobufs_unlock;
46330 spin_unlock(&cookie->lock);
46331
46332- fscache_stat(&fscache_n_retrieval_ops);
46333+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
46334
46335 /* pin the netfs read context in case we need to do the actual netfs
46336 * read because we've encountered a cache read failure */
46337@@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46338
46339 error:
46340 if (ret == -ENOMEM)
46341- fscache_stat(&fscache_n_retrievals_nomem);
46342+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46343 else if (ret == -ERESTARTSYS)
46344- fscache_stat(&fscache_n_retrievals_intr);
46345+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
46346 else if (ret == -ENODATA)
46347- fscache_stat(&fscache_n_retrievals_nodata);
46348+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46349 else if (ret < 0)
46350- fscache_stat(&fscache_n_retrievals_nobufs);
46351+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46352 else
46353- fscache_stat(&fscache_n_retrievals_ok);
46354+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
46355
46356 fscache_put_retrieval(op);
46357 _leave(" = %d", ret);
46358@@ -545,7 +545,7 @@ nobufs_unlock:
46359 spin_unlock(&cookie->lock);
46360 kfree(op);
46361 nobufs:
46362- fscache_stat(&fscache_n_retrievals_nobufs);
46363+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46364 _leave(" = -ENOBUFS");
46365 return -ENOBUFS;
46366 }
46367@@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46368
46369 _enter("%p,%p,,,", cookie, page);
46370
46371- fscache_stat(&fscache_n_allocs);
46372+ fscache_stat_unchecked(&fscache_n_allocs);
46373
46374 if (hlist_empty(&cookie->backing_objects))
46375 goto nobufs;
46376@@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46377 goto nobufs_unlock;
46378 spin_unlock(&cookie->lock);
46379
46380- fscache_stat(&fscache_n_alloc_ops);
46381+ fscache_stat_unchecked(&fscache_n_alloc_ops);
46382
46383 ret = fscache_wait_for_retrieval_activation(
46384 object, op,
46385@@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46386
46387 error:
46388 if (ret == -ERESTARTSYS)
46389- fscache_stat(&fscache_n_allocs_intr);
46390+ fscache_stat_unchecked(&fscache_n_allocs_intr);
46391 else if (ret < 0)
46392- fscache_stat(&fscache_n_allocs_nobufs);
46393+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46394 else
46395- fscache_stat(&fscache_n_allocs_ok);
46396+ fscache_stat_unchecked(&fscache_n_allocs_ok);
46397
46398 fscache_put_retrieval(op);
46399 _leave(" = %d", ret);
46400@@ -625,7 +625,7 @@ nobufs_unlock:
46401 spin_unlock(&cookie->lock);
46402 kfree(op);
46403 nobufs:
46404- fscache_stat(&fscache_n_allocs_nobufs);
46405+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46406 _leave(" = -ENOBUFS");
46407 return -ENOBUFS;
46408 }
46409@@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46410
46411 spin_lock(&cookie->stores_lock);
46412
46413- fscache_stat(&fscache_n_store_calls);
46414+ fscache_stat_unchecked(&fscache_n_store_calls);
46415
46416 /* find a page to store */
46417 page = NULL;
46418@@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46419 page = results[0];
46420 _debug("gang %d [%lx]", n, page->index);
46421 if (page->index > op->store_limit) {
46422- fscache_stat(&fscache_n_store_pages_over_limit);
46423+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
46424 goto superseded;
46425 }
46426
46427@@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46428 spin_unlock(&cookie->stores_lock);
46429 spin_unlock(&object->lock);
46430
46431- fscache_stat(&fscache_n_store_pages);
46432+ fscache_stat_unchecked(&fscache_n_store_pages);
46433 fscache_stat(&fscache_n_cop_write_page);
46434 ret = object->cache->ops->write_page(op, page);
46435 fscache_stat_d(&fscache_n_cop_write_page);
46436@@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46437 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46438 ASSERT(PageFsCache(page));
46439
46440- fscache_stat(&fscache_n_stores);
46441+ fscache_stat_unchecked(&fscache_n_stores);
46442
46443 op = kzalloc(sizeof(*op), GFP_NOIO);
46444 if (!op)
46445@@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46446 spin_unlock(&cookie->stores_lock);
46447 spin_unlock(&object->lock);
46448
46449- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
46450+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
46451 op->store_limit = object->store_limit;
46452
46453 if (fscache_submit_op(object, &op->op) < 0)
46454@@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46455
46456 spin_unlock(&cookie->lock);
46457 radix_tree_preload_end();
46458- fscache_stat(&fscache_n_store_ops);
46459- fscache_stat(&fscache_n_stores_ok);
46460+ fscache_stat_unchecked(&fscache_n_store_ops);
46461+ fscache_stat_unchecked(&fscache_n_stores_ok);
46462
46463 /* the work queue now carries its own ref on the object */
46464 fscache_put_operation(&op->op);
46465@@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46466 return 0;
46467
46468 already_queued:
46469- fscache_stat(&fscache_n_stores_again);
46470+ fscache_stat_unchecked(&fscache_n_stores_again);
46471 already_pending:
46472 spin_unlock(&cookie->stores_lock);
46473 spin_unlock(&object->lock);
46474 spin_unlock(&cookie->lock);
46475 radix_tree_preload_end();
46476 kfree(op);
46477- fscache_stat(&fscache_n_stores_ok);
46478+ fscache_stat_unchecked(&fscache_n_stores_ok);
46479 _leave(" = 0");
46480 return 0;
46481
46482@@ -851,14 +851,14 @@ nobufs:
46483 spin_unlock(&cookie->lock);
46484 radix_tree_preload_end();
46485 kfree(op);
46486- fscache_stat(&fscache_n_stores_nobufs);
46487+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
46488 _leave(" = -ENOBUFS");
46489 return -ENOBUFS;
46490
46491 nomem_free:
46492 kfree(op);
46493 nomem:
46494- fscache_stat(&fscache_n_stores_oom);
46495+ fscache_stat_unchecked(&fscache_n_stores_oom);
46496 _leave(" = -ENOMEM");
46497 return -ENOMEM;
46498 }
46499@@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
46500 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46501 ASSERTCMP(page, !=, NULL);
46502
46503- fscache_stat(&fscache_n_uncaches);
46504+ fscache_stat_unchecked(&fscache_n_uncaches);
46505
46506 /* cache withdrawal may beat us to it */
46507 if (!PageFsCache(page))
46508@@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
46509 unsigned long loop;
46510
46511 #ifdef CONFIG_FSCACHE_STATS
46512- atomic_add(pagevec->nr, &fscache_n_marks);
46513+ atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
46514 #endif
46515
46516 for (loop = 0; loop < pagevec->nr; loop++) {
46517diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
46518index 4765190..2a067f2 100644
46519--- a/fs/fscache/stats.c
46520+++ b/fs/fscache/stats.c
46521@@ -18,95 +18,95 @@
46522 /*
46523 * operation counters
46524 */
46525-atomic_t fscache_n_op_pend;
46526-atomic_t fscache_n_op_run;
46527-atomic_t fscache_n_op_enqueue;
46528-atomic_t fscache_n_op_requeue;
46529-atomic_t fscache_n_op_deferred_release;
46530-atomic_t fscache_n_op_release;
46531-atomic_t fscache_n_op_gc;
46532-atomic_t fscache_n_op_cancelled;
46533-atomic_t fscache_n_op_rejected;
46534+atomic_unchecked_t fscache_n_op_pend;
46535+atomic_unchecked_t fscache_n_op_run;
46536+atomic_unchecked_t fscache_n_op_enqueue;
46537+atomic_unchecked_t fscache_n_op_requeue;
46538+atomic_unchecked_t fscache_n_op_deferred_release;
46539+atomic_unchecked_t fscache_n_op_release;
46540+atomic_unchecked_t fscache_n_op_gc;
46541+atomic_unchecked_t fscache_n_op_cancelled;
46542+atomic_unchecked_t fscache_n_op_rejected;
46543
46544-atomic_t fscache_n_attr_changed;
46545-atomic_t fscache_n_attr_changed_ok;
46546-atomic_t fscache_n_attr_changed_nobufs;
46547-atomic_t fscache_n_attr_changed_nomem;
46548-atomic_t fscache_n_attr_changed_calls;
46549+atomic_unchecked_t fscache_n_attr_changed;
46550+atomic_unchecked_t fscache_n_attr_changed_ok;
46551+atomic_unchecked_t fscache_n_attr_changed_nobufs;
46552+atomic_unchecked_t fscache_n_attr_changed_nomem;
46553+atomic_unchecked_t fscache_n_attr_changed_calls;
46554
46555-atomic_t fscache_n_allocs;
46556-atomic_t fscache_n_allocs_ok;
46557-atomic_t fscache_n_allocs_wait;
46558-atomic_t fscache_n_allocs_nobufs;
46559-atomic_t fscache_n_allocs_intr;
46560-atomic_t fscache_n_allocs_object_dead;
46561-atomic_t fscache_n_alloc_ops;
46562-atomic_t fscache_n_alloc_op_waits;
46563+atomic_unchecked_t fscache_n_allocs;
46564+atomic_unchecked_t fscache_n_allocs_ok;
46565+atomic_unchecked_t fscache_n_allocs_wait;
46566+atomic_unchecked_t fscache_n_allocs_nobufs;
46567+atomic_unchecked_t fscache_n_allocs_intr;
46568+atomic_unchecked_t fscache_n_allocs_object_dead;
46569+atomic_unchecked_t fscache_n_alloc_ops;
46570+atomic_unchecked_t fscache_n_alloc_op_waits;
46571
46572-atomic_t fscache_n_retrievals;
46573-atomic_t fscache_n_retrievals_ok;
46574-atomic_t fscache_n_retrievals_wait;
46575-atomic_t fscache_n_retrievals_nodata;
46576-atomic_t fscache_n_retrievals_nobufs;
46577-atomic_t fscache_n_retrievals_intr;
46578-atomic_t fscache_n_retrievals_nomem;
46579-atomic_t fscache_n_retrievals_object_dead;
46580-atomic_t fscache_n_retrieval_ops;
46581-atomic_t fscache_n_retrieval_op_waits;
46582+atomic_unchecked_t fscache_n_retrievals;
46583+atomic_unchecked_t fscache_n_retrievals_ok;
46584+atomic_unchecked_t fscache_n_retrievals_wait;
46585+atomic_unchecked_t fscache_n_retrievals_nodata;
46586+atomic_unchecked_t fscache_n_retrievals_nobufs;
46587+atomic_unchecked_t fscache_n_retrievals_intr;
46588+atomic_unchecked_t fscache_n_retrievals_nomem;
46589+atomic_unchecked_t fscache_n_retrievals_object_dead;
46590+atomic_unchecked_t fscache_n_retrieval_ops;
46591+atomic_unchecked_t fscache_n_retrieval_op_waits;
46592
46593-atomic_t fscache_n_stores;
46594-atomic_t fscache_n_stores_ok;
46595-atomic_t fscache_n_stores_again;
46596-atomic_t fscache_n_stores_nobufs;
46597-atomic_t fscache_n_stores_oom;
46598-atomic_t fscache_n_store_ops;
46599-atomic_t fscache_n_store_calls;
46600-atomic_t fscache_n_store_pages;
46601-atomic_t fscache_n_store_radix_deletes;
46602-atomic_t fscache_n_store_pages_over_limit;
46603+atomic_unchecked_t fscache_n_stores;
46604+atomic_unchecked_t fscache_n_stores_ok;
46605+atomic_unchecked_t fscache_n_stores_again;
46606+atomic_unchecked_t fscache_n_stores_nobufs;
46607+atomic_unchecked_t fscache_n_stores_oom;
46608+atomic_unchecked_t fscache_n_store_ops;
46609+atomic_unchecked_t fscache_n_store_calls;
46610+atomic_unchecked_t fscache_n_store_pages;
46611+atomic_unchecked_t fscache_n_store_radix_deletes;
46612+atomic_unchecked_t fscache_n_store_pages_over_limit;
46613
46614-atomic_t fscache_n_store_vmscan_not_storing;
46615-atomic_t fscache_n_store_vmscan_gone;
46616-atomic_t fscache_n_store_vmscan_busy;
46617-atomic_t fscache_n_store_vmscan_cancelled;
46618+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46619+atomic_unchecked_t fscache_n_store_vmscan_gone;
46620+atomic_unchecked_t fscache_n_store_vmscan_busy;
46621+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46622
46623-atomic_t fscache_n_marks;
46624-atomic_t fscache_n_uncaches;
46625+atomic_unchecked_t fscache_n_marks;
46626+atomic_unchecked_t fscache_n_uncaches;
46627
46628-atomic_t fscache_n_acquires;
46629-atomic_t fscache_n_acquires_null;
46630-atomic_t fscache_n_acquires_no_cache;
46631-atomic_t fscache_n_acquires_ok;
46632-atomic_t fscache_n_acquires_nobufs;
46633-atomic_t fscache_n_acquires_oom;
46634+atomic_unchecked_t fscache_n_acquires;
46635+atomic_unchecked_t fscache_n_acquires_null;
46636+atomic_unchecked_t fscache_n_acquires_no_cache;
46637+atomic_unchecked_t fscache_n_acquires_ok;
46638+atomic_unchecked_t fscache_n_acquires_nobufs;
46639+atomic_unchecked_t fscache_n_acquires_oom;
46640
46641-atomic_t fscache_n_updates;
46642-atomic_t fscache_n_updates_null;
46643-atomic_t fscache_n_updates_run;
46644+atomic_unchecked_t fscache_n_updates;
46645+atomic_unchecked_t fscache_n_updates_null;
46646+atomic_unchecked_t fscache_n_updates_run;
46647
46648-atomic_t fscache_n_relinquishes;
46649-atomic_t fscache_n_relinquishes_null;
46650-atomic_t fscache_n_relinquishes_waitcrt;
46651-atomic_t fscache_n_relinquishes_retire;
46652+atomic_unchecked_t fscache_n_relinquishes;
46653+atomic_unchecked_t fscache_n_relinquishes_null;
46654+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46655+atomic_unchecked_t fscache_n_relinquishes_retire;
46656
46657-atomic_t fscache_n_cookie_index;
46658-atomic_t fscache_n_cookie_data;
46659-atomic_t fscache_n_cookie_special;
46660+atomic_unchecked_t fscache_n_cookie_index;
46661+atomic_unchecked_t fscache_n_cookie_data;
46662+atomic_unchecked_t fscache_n_cookie_special;
46663
46664-atomic_t fscache_n_object_alloc;
46665-atomic_t fscache_n_object_no_alloc;
46666-atomic_t fscache_n_object_lookups;
46667-atomic_t fscache_n_object_lookups_negative;
46668-atomic_t fscache_n_object_lookups_positive;
46669-atomic_t fscache_n_object_lookups_timed_out;
46670-atomic_t fscache_n_object_created;
46671-atomic_t fscache_n_object_avail;
46672-atomic_t fscache_n_object_dead;
46673+atomic_unchecked_t fscache_n_object_alloc;
46674+atomic_unchecked_t fscache_n_object_no_alloc;
46675+atomic_unchecked_t fscache_n_object_lookups;
46676+atomic_unchecked_t fscache_n_object_lookups_negative;
46677+atomic_unchecked_t fscache_n_object_lookups_positive;
46678+atomic_unchecked_t fscache_n_object_lookups_timed_out;
46679+atomic_unchecked_t fscache_n_object_created;
46680+atomic_unchecked_t fscache_n_object_avail;
46681+atomic_unchecked_t fscache_n_object_dead;
46682
46683-atomic_t fscache_n_checkaux_none;
46684-atomic_t fscache_n_checkaux_okay;
46685-atomic_t fscache_n_checkaux_update;
46686-atomic_t fscache_n_checkaux_obsolete;
46687+atomic_unchecked_t fscache_n_checkaux_none;
46688+atomic_unchecked_t fscache_n_checkaux_okay;
46689+atomic_unchecked_t fscache_n_checkaux_update;
46690+atomic_unchecked_t fscache_n_checkaux_obsolete;
46691
46692 atomic_t fscache_n_cop_alloc_object;
46693 atomic_t fscache_n_cop_lookup_object;
46694@@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
46695 seq_puts(m, "FS-Cache statistics\n");
46696
46697 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
46698- atomic_read(&fscache_n_cookie_index),
46699- atomic_read(&fscache_n_cookie_data),
46700- atomic_read(&fscache_n_cookie_special));
46701+ atomic_read_unchecked(&fscache_n_cookie_index),
46702+ atomic_read_unchecked(&fscache_n_cookie_data),
46703+ atomic_read_unchecked(&fscache_n_cookie_special));
46704
46705 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
46706- atomic_read(&fscache_n_object_alloc),
46707- atomic_read(&fscache_n_object_no_alloc),
46708- atomic_read(&fscache_n_object_avail),
46709- atomic_read(&fscache_n_object_dead));
46710+ atomic_read_unchecked(&fscache_n_object_alloc),
46711+ atomic_read_unchecked(&fscache_n_object_no_alloc),
46712+ atomic_read_unchecked(&fscache_n_object_avail),
46713+ atomic_read_unchecked(&fscache_n_object_dead));
46714 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
46715- atomic_read(&fscache_n_checkaux_none),
46716- atomic_read(&fscache_n_checkaux_okay),
46717- atomic_read(&fscache_n_checkaux_update),
46718- atomic_read(&fscache_n_checkaux_obsolete));
46719+ atomic_read_unchecked(&fscache_n_checkaux_none),
46720+ atomic_read_unchecked(&fscache_n_checkaux_okay),
46721+ atomic_read_unchecked(&fscache_n_checkaux_update),
46722+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
46723
46724 seq_printf(m, "Pages : mrk=%u unc=%u\n",
46725- atomic_read(&fscache_n_marks),
46726- atomic_read(&fscache_n_uncaches));
46727+ atomic_read_unchecked(&fscache_n_marks),
46728+ atomic_read_unchecked(&fscache_n_uncaches));
46729
46730 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
46731 " oom=%u\n",
46732- atomic_read(&fscache_n_acquires),
46733- atomic_read(&fscache_n_acquires_null),
46734- atomic_read(&fscache_n_acquires_no_cache),
46735- atomic_read(&fscache_n_acquires_ok),
46736- atomic_read(&fscache_n_acquires_nobufs),
46737- atomic_read(&fscache_n_acquires_oom));
46738+ atomic_read_unchecked(&fscache_n_acquires),
46739+ atomic_read_unchecked(&fscache_n_acquires_null),
46740+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
46741+ atomic_read_unchecked(&fscache_n_acquires_ok),
46742+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
46743+ atomic_read_unchecked(&fscache_n_acquires_oom));
46744
46745 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
46746- atomic_read(&fscache_n_object_lookups),
46747- atomic_read(&fscache_n_object_lookups_negative),
46748- atomic_read(&fscache_n_object_lookups_positive),
46749- atomic_read(&fscache_n_object_created),
46750- atomic_read(&fscache_n_object_lookups_timed_out));
46751+ atomic_read_unchecked(&fscache_n_object_lookups),
46752+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
46753+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
46754+ atomic_read_unchecked(&fscache_n_object_created),
46755+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
46756
46757 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
46758- atomic_read(&fscache_n_updates),
46759- atomic_read(&fscache_n_updates_null),
46760- atomic_read(&fscache_n_updates_run));
46761+ atomic_read_unchecked(&fscache_n_updates),
46762+ atomic_read_unchecked(&fscache_n_updates_null),
46763+ atomic_read_unchecked(&fscache_n_updates_run));
46764
46765 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
46766- atomic_read(&fscache_n_relinquishes),
46767- atomic_read(&fscache_n_relinquishes_null),
46768- atomic_read(&fscache_n_relinquishes_waitcrt),
46769- atomic_read(&fscache_n_relinquishes_retire));
46770+ atomic_read_unchecked(&fscache_n_relinquishes),
46771+ atomic_read_unchecked(&fscache_n_relinquishes_null),
46772+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
46773+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
46774
46775 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
46776- atomic_read(&fscache_n_attr_changed),
46777- atomic_read(&fscache_n_attr_changed_ok),
46778- atomic_read(&fscache_n_attr_changed_nobufs),
46779- atomic_read(&fscache_n_attr_changed_nomem),
46780- atomic_read(&fscache_n_attr_changed_calls));
46781+ atomic_read_unchecked(&fscache_n_attr_changed),
46782+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
46783+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
46784+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
46785+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
46786
46787 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
46788- atomic_read(&fscache_n_allocs),
46789- atomic_read(&fscache_n_allocs_ok),
46790- atomic_read(&fscache_n_allocs_wait),
46791- atomic_read(&fscache_n_allocs_nobufs),
46792- atomic_read(&fscache_n_allocs_intr));
46793+ atomic_read_unchecked(&fscache_n_allocs),
46794+ atomic_read_unchecked(&fscache_n_allocs_ok),
46795+ atomic_read_unchecked(&fscache_n_allocs_wait),
46796+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
46797+ atomic_read_unchecked(&fscache_n_allocs_intr));
46798 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
46799- atomic_read(&fscache_n_alloc_ops),
46800- atomic_read(&fscache_n_alloc_op_waits),
46801- atomic_read(&fscache_n_allocs_object_dead));
46802+ atomic_read_unchecked(&fscache_n_alloc_ops),
46803+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
46804+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
46805
46806 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
46807 " int=%u oom=%u\n",
46808- atomic_read(&fscache_n_retrievals),
46809- atomic_read(&fscache_n_retrievals_ok),
46810- atomic_read(&fscache_n_retrievals_wait),
46811- atomic_read(&fscache_n_retrievals_nodata),
46812- atomic_read(&fscache_n_retrievals_nobufs),
46813- atomic_read(&fscache_n_retrievals_intr),
46814- atomic_read(&fscache_n_retrievals_nomem));
46815+ atomic_read_unchecked(&fscache_n_retrievals),
46816+ atomic_read_unchecked(&fscache_n_retrievals_ok),
46817+ atomic_read_unchecked(&fscache_n_retrievals_wait),
46818+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
46819+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
46820+ atomic_read_unchecked(&fscache_n_retrievals_intr),
46821+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
46822 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
46823- atomic_read(&fscache_n_retrieval_ops),
46824- atomic_read(&fscache_n_retrieval_op_waits),
46825- atomic_read(&fscache_n_retrievals_object_dead));
46826+ atomic_read_unchecked(&fscache_n_retrieval_ops),
46827+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
46828+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
46829
46830 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
46831- atomic_read(&fscache_n_stores),
46832- atomic_read(&fscache_n_stores_ok),
46833- atomic_read(&fscache_n_stores_again),
46834- atomic_read(&fscache_n_stores_nobufs),
46835- atomic_read(&fscache_n_stores_oom));
46836+ atomic_read_unchecked(&fscache_n_stores),
46837+ atomic_read_unchecked(&fscache_n_stores_ok),
46838+ atomic_read_unchecked(&fscache_n_stores_again),
46839+ atomic_read_unchecked(&fscache_n_stores_nobufs),
46840+ atomic_read_unchecked(&fscache_n_stores_oom));
46841 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
46842- atomic_read(&fscache_n_store_ops),
46843- atomic_read(&fscache_n_store_calls),
46844- atomic_read(&fscache_n_store_pages),
46845- atomic_read(&fscache_n_store_radix_deletes),
46846- atomic_read(&fscache_n_store_pages_over_limit));
46847+ atomic_read_unchecked(&fscache_n_store_ops),
46848+ atomic_read_unchecked(&fscache_n_store_calls),
46849+ atomic_read_unchecked(&fscache_n_store_pages),
46850+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
46851+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
46852
46853 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
46854- atomic_read(&fscache_n_store_vmscan_not_storing),
46855- atomic_read(&fscache_n_store_vmscan_gone),
46856- atomic_read(&fscache_n_store_vmscan_busy),
46857- atomic_read(&fscache_n_store_vmscan_cancelled));
46858+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
46859+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
46860+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
46861+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
46862
46863 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
46864- atomic_read(&fscache_n_op_pend),
46865- atomic_read(&fscache_n_op_run),
46866- atomic_read(&fscache_n_op_enqueue),
46867- atomic_read(&fscache_n_op_cancelled),
46868- atomic_read(&fscache_n_op_rejected));
46869+ atomic_read_unchecked(&fscache_n_op_pend),
46870+ atomic_read_unchecked(&fscache_n_op_run),
46871+ atomic_read_unchecked(&fscache_n_op_enqueue),
46872+ atomic_read_unchecked(&fscache_n_op_cancelled),
46873+ atomic_read_unchecked(&fscache_n_op_rejected));
46874 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
46875- atomic_read(&fscache_n_op_deferred_release),
46876- atomic_read(&fscache_n_op_release),
46877- atomic_read(&fscache_n_op_gc));
46878+ atomic_read_unchecked(&fscache_n_op_deferred_release),
46879+ atomic_read_unchecked(&fscache_n_op_release),
46880+ atomic_read_unchecked(&fscache_n_op_gc));
46881
46882 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
46883 atomic_read(&fscache_n_cop_alloc_object),
46884diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
46885index 3426521..3b75162 100644
46886--- a/fs/fuse/cuse.c
46887+++ b/fs/fuse/cuse.c
46888@@ -587,10 +587,12 @@ static int __init cuse_init(void)
46889 INIT_LIST_HEAD(&cuse_conntbl[i]);
46890
46891 /* inherit and extend fuse_dev_operations */
46892- cuse_channel_fops = fuse_dev_operations;
46893- cuse_channel_fops.owner = THIS_MODULE;
46894- cuse_channel_fops.open = cuse_channel_open;
46895- cuse_channel_fops.release = cuse_channel_release;
46896+ pax_open_kernel();
46897+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
46898+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
46899+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
46900+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
46901+ pax_close_kernel();
46902
46903 cuse_class = class_create(THIS_MODULE, "cuse");
46904 if (IS_ERR(cuse_class))
46905diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
46906index 7df2b5e..5804aa7 100644
46907--- a/fs/fuse/dev.c
46908+++ b/fs/fuse/dev.c
46909@@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
46910 ret = 0;
46911 pipe_lock(pipe);
46912
46913- if (!pipe->readers) {
46914+ if (!atomic_read(&pipe->readers)) {
46915 send_sig(SIGPIPE, current, 0);
46916 if (!ret)
46917 ret = -EPIPE;
46918diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
46919index 334e0b1..fc571e8 100644
46920--- a/fs/fuse/dir.c
46921+++ b/fs/fuse/dir.c
46922@@ -1189,7 +1189,7 @@ static char *read_link(struct dentry *dentry)
46923 return link;
46924 }
46925
46926-static void free_link(char *link)
46927+static void free_link(const char *link)
46928 {
46929 if (!IS_ERR(link))
46930 free_page((unsigned long) link);
46931diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
46932index a9ba244..d9df391 100644
46933--- a/fs/gfs2/inode.c
46934+++ b/fs/gfs2/inode.c
46935@@ -1496,7 +1496,7 @@ out:
46936
46937 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46938 {
46939- char *s = nd_get_link(nd);
46940+ const char *s = nd_get_link(nd);
46941 if (!IS_ERR(s))
46942 kfree(s);
46943 }
46944diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
46945index cc9281b..58996fb 100644
46946--- a/fs/hugetlbfs/inode.c
46947+++ b/fs/hugetlbfs/inode.c
46948@@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
46949 .kill_sb = kill_litter_super,
46950 };
46951
46952-static struct vfsmount *hugetlbfs_vfsmount;
46953+struct vfsmount *hugetlbfs_vfsmount;
46954
46955 static int can_do_hugetlb_shm(void)
46956 {
46957diff --git a/fs/inode.c b/fs/inode.c
46958index c99163b..a11ad40 100644
46959--- a/fs/inode.c
46960+++ b/fs/inode.c
46961@@ -867,8 +867,8 @@ unsigned int get_next_ino(void)
46962
46963 #ifdef CONFIG_SMP
46964 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
46965- static atomic_t shared_last_ino;
46966- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
46967+ static atomic_unchecked_t shared_last_ino;
46968+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
46969
46970 res = next - LAST_INO_BATCH;
46971 }
46972diff --git a/fs/isofs/export.c b/fs/isofs/export.c
46973index aa4356d..1d38044 100644
46974--- a/fs/isofs/export.c
46975+++ b/fs/isofs/export.c
46976@@ -134,6 +134,7 @@ isofs_export_encode_fh(struct inode *inode,
46977 len = 3;
46978 fh32[0] = ei->i_iget5_block;
46979 fh16[2] = (__u16)ei->i_iget5_offset; /* fh16 [sic] */
46980+ fh16[3] = 0; /* avoid leaking uninitialized data */
46981 fh32[2] = inode->i_generation;
46982 if (parent) {
46983 struct iso_inode_info *eparent;
46984diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
46985index 4a6cf28..d3a29d3 100644
46986--- a/fs/jffs2/erase.c
46987+++ b/fs/jffs2/erase.c
46988@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
46989 struct jffs2_unknown_node marker = {
46990 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
46991 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46992- .totlen = cpu_to_je32(c->cleanmarker_size)
46993+ .totlen = cpu_to_je32(c->cleanmarker_size),
46994+ .hdr_crc = cpu_to_je32(0)
46995 };
46996
46997 jffs2_prealloc_raw_node_refs(c, jeb, 1);
46998diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
46999index 6f4529d..bf12806 100644
47000--- a/fs/jffs2/wbuf.c
47001+++ b/fs/jffs2/wbuf.c
47002@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
47003 {
47004 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
47005 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47006- .totlen = constant_cpu_to_je32(8)
47007+ .totlen = constant_cpu_to_je32(8),
47008+ .hdr_crc = constant_cpu_to_je32(0)
47009 };
47010
47011 /*
47012diff --git a/fs/jfs/super.c b/fs/jfs/super.c
47013index 4a82950..bcaa0cb 100644
47014--- a/fs/jfs/super.c
47015+++ b/fs/jfs/super.c
47016@@ -801,7 +801,7 @@ static int __init init_jfs_fs(void)
47017
47018 jfs_inode_cachep =
47019 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
47020- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
47021+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
47022 init_once);
47023 if (jfs_inode_cachep == NULL)
47024 return -ENOMEM;
47025diff --git a/fs/libfs.c b/fs/libfs.c
47026index f86ec27..4734776 100644
47027--- a/fs/libfs.c
47028+++ b/fs/libfs.c
47029@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47030
47031 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
47032 struct dentry *next;
47033+ char d_name[sizeof(next->d_iname)];
47034+ const unsigned char *name;
47035+
47036 next = list_entry(p, struct dentry, d_u.d_child);
47037 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
47038 if (!simple_positive(next)) {
47039@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47040
47041 spin_unlock(&next->d_lock);
47042 spin_unlock(&dentry->d_lock);
47043- if (filldir(dirent, next->d_name.name,
47044+ name = next->d_name.name;
47045+ if (name == next->d_iname) {
47046+ memcpy(d_name, name, next->d_name.len);
47047+ name = d_name;
47048+ }
47049+ if (filldir(dirent, name,
47050 next->d_name.len, filp->f_pos,
47051 next->d_inode->i_ino,
47052 dt_type(next->d_inode)) < 0)
47053diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
47054index 8392cb8..80d6193 100644
47055--- a/fs/lockd/clntproc.c
47056+++ b/fs/lockd/clntproc.c
47057@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
47058 /*
47059 * Cookie counter for NLM requests
47060 */
47061-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
47062+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
47063
47064 void nlmclnt_next_cookie(struct nlm_cookie *c)
47065 {
47066- u32 cookie = atomic_inc_return(&nlm_cookie);
47067+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
47068
47069 memcpy(c->data, &cookie, 4);
47070 c->len=4;
47071diff --git a/fs/locks.c b/fs/locks.c
47072index 82c3533..34e929c 100644
47073--- a/fs/locks.c
47074+++ b/fs/locks.c
47075@@ -2076,16 +2076,16 @@ void locks_remove_flock(struct file *filp)
47076 return;
47077
47078 if (filp->f_op && filp->f_op->flock) {
47079- struct file_lock fl = {
47080+ struct file_lock flock = {
47081 .fl_pid = current->tgid,
47082 .fl_file = filp,
47083 .fl_flags = FL_FLOCK,
47084 .fl_type = F_UNLCK,
47085 .fl_end = OFFSET_MAX,
47086 };
47087- filp->f_op->flock(filp, F_SETLKW, &fl);
47088- if (fl.fl_ops && fl.fl_ops->fl_release_private)
47089- fl.fl_ops->fl_release_private(&fl);
47090+ filp->f_op->flock(filp, F_SETLKW, &flock);
47091+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
47092+ flock.fl_ops->fl_release_private(&flock);
47093 }
47094
47095 lock_flocks();
47096diff --git a/fs/namei.c b/fs/namei.c
47097index 7d69419..10c6af6 100644
47098--- a/fs/namei.c
47099+++ b/fs/namei.c
47100@@ -265,16 +265,32 @@ int generic_permission(struct inode *inode, int mask)
47101 if (ret != -EACCES)
47102 return ret;
47103
47104+#ifdef CONFIG_GRKERNSEC
47105+ /* we'll block if we have to log due to a denied capability use */
47106+ if (mask & MAY_NOT_BLOCK)
47107+ return -ECHILD;
47108+#endif
47109+
47110 if (S_ISDIR(inode->i_mode)) {
47111 /* DACs are overridable for directories */
47112- if (inode_capable(inode, CAP_DAC_OVERRIDE))
47113- return 0;
47114 if (!(mask & MAY_WRITE))
47115- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47116+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47117+ inode_capable(inode, CAP_DAC_READ_SEARCH))
47118 return 0;
47119+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
47120+ return 0;
47121 return -EACCES;
47122 }
47123 /*
47124+ * Searching includes executable on directories, else just read.
47125+ */
47126+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47127+ if (mask == MAY_READ)
47128+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47129+ inode_capable(inode, CAP_DAC_READ_SEARCH))
47130+ return 0;
47131+
47132+ /*
47133 * Read/write DACs are always overridable.
47134 * Executable DACs are overridable when there is
47135 * at least one exec bit set.
47136@@ -283,14 +299,6 @@ int generic_permission(struct inode *inode, int mask)
47137 if (inode_capable(inode, CAP_DAC_OVERRIDE))
47138 return 0;
47139
47140- /*
47141- * Searching includes executable on directories, else just read.
47142- */
47143- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47144- if (mask == MAY_READ)
47145- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47146- return 0;
47147-
47148 return -EACCES;
47149 }
47150
47151@@ -639,11 +647,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47152 return error;
47153 }
47154
47155+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
47156+ dentry->d_inode, dentry, nd->path.mnt)) {
47157+ error = -EACCES;
47158+ *p = ERR_PTR(error); /* no ->put_link(), please */
47159+ path_put(&nd->path);
47160+ return error;
47161+ }
47162+
47163 nd->last_type = LAST_BIND;
47164 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
47165 error = PTR_ERR(*p);
47166 if (!IS_ERR(*p)) {
47167- char *s = nd_get_link(nd);
47168+ const char *s = nd_get_link(nd);
47169 error = 0;
47170 if (s)
47171 error = __vfs_follow_link(nd, s);
47172@@ -1386,6 +1402,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
47173 if (!res)
47174 res = walk_component(nd, path, &nd->last,
47175 nd->last_type, LOOKUP_FOLLOW);
47176+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
47177+ res = -EACCES;
47178 put_link(nd, &link, cookie);
47179 } while (res > 0);
47180
47181@@ -1779,6 +1797,8 @@ static int path_lookupat(int dfd, const char *name,
47182 err = follow_link(&link, nd, &cookie);
47183 if (!err)
47184 err = lookup_last(nd, &path);
47185+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
47186+ err = -EACCES;
47187 put_link(nd, &link, cookie);
47188 }
47189 }
47190@@ -1786,6 +1806,21 @@ static int path_lookupat(int dfd, const char *name,
47191 if (!err)
47192 err = complete_walk(nd);
47193
47194+ if (!(nd->flags & LOOKUP_PARENT)) {
47195+#ifdef CONFIG_GRKERNSEC
47196+ if (flags & LOOKUP_RCU) {
47197+ if (!err)
47198+ path_put(&nd->path);
47199+ err = -ECHILD;
47200+ } else
47201+#endif
47202+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47203+ if (!err)
47204+ path_put(&nd->path);
47205+ err = -ENOENT;
47206+ }
47207+ }
47208+
47209 if (!err && nd->flags & LOOKUP_DIRECTORY) {
47210 if (!nd->inode->i_op->lookup) {
47211 path_put(&nd->path);
47212@@ -1813,6 +1848,15 @@ static int do_path_lookup(int dfd, const char *name,
47213 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
47214
47215 if (likely(!retval)) {
47216+ if (*name != '/' && nd->path.dentry && nd->inode) {
47217+#ifdef CONFIG_GRKERNSEC
47218+ if (flags & LOOKUP_RCU)
47219+ return -ECHILD;
47220+#endif
47221+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
47222+ return -ENOENT;
47223+ }
47224+
47225 if (unlikely(!audit_dummy_context())) {
47226 if (nd->path.dentry && nd->inode)
47227 audit_inode(name, nd->path.dentry);
47228@@ -2155,6 +2199,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
47229 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
47230 return -EPERM;
47231
47232+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
47233+ return -EPERM;
47234+ if (gr_handle_rawio(inode))
47235+ return -EPERM;
47236+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
47237+ return -EACCES;
47238+
47239 return 0;
47240 }
47241
47242@@ -2190,7 +2241,7 @@ static inline int open_to_namei_flags(int flag)
47243 /*
47244 * Handle the last step of open()
47245 */
47246-static struct file *do_last(struct nameidata *nd, struct path *path,
47247+static struct file *do_last(struct nameidata *nd, struct path *path, struct path *link,
47248 const struct open_flags *op, const char *pathname)
47249 {
47250 struct dentry *dir = nd->path.dentry;
47251@@ -2220,16 +2271,44 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47252 error = complete_walk(nd);
47253 if (error)
47254 return ERR_PTR(error);
47255+#ifdef CONFIG_GRKERNSEC
47256+ if (nd->flags & LOOKUP_RCU) {
47257+ error = -ECHILD;
47258+ goto exit;
47259+ }
47260+#endif
47261+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47262+ error = -ENOENT;
47263+ goto exit;
47264+ }
47265 audit_inode(pathname, nd->path.dentry);
47266 if (open_flag & O_CREAT) {
47267 error = -EISDIR;
47268 goto exit;
47269 }
47270+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
47271+ error = -EACCES;
47272+ goto exit;
47273+ }
47274 goto ok;
47275 case LAST_BIND:
47276 error = complete_walk(nd);
47277 if (error)
47278 return ERR_PTR(error);
47279+#ifdef CONFIG_GRKERNSEC
47280+ if (nd->flags & LOOKUP_RCU) {
47281+ error = -ECHILD;
47282+ goto exit;
47283+ }
47284+#endif
47285+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
47286+ error = -ENOENT;
47287+ goto exit;
47288+ }
47289+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
47290+ error = -EACCES;
47291+ goto exit;
47292+ }
47293 audit_inode(pathname, dir);
47294 goto ok;
47295 }
47296@@ -2285,6 +2364,12 @@ retry_lookup:
47297 /* Negative dentry, just create the file */
47298 if (!dentry->d_inode) {
47299 umode_t mode = op->mode;
47300+
47301+ if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
47302+ error = -EACCES;
47303+ goto exit_mutex_unlock;
47304+ }
47305+
47306 if (!IS_POSIXACL(dir->d_inode))
47307 mode &= ~current_umask();
47308 /*
47309@@ -2308,6 +2393,8 @@ retry_lookup:
47310 error = vfs_create(dir->d_inode, dentry, mode, nd);
47311 if (error)
47312 goto exit_mutex_unlock;
47313+ else
47314+ gr_handle_create(path->dentry, path->mnt);
47315 mutex_unlock(&dir->d_inode->i_mutex);
47316 dput(nd->path.dentry);
47317 nd->path.dentry = dentry;
47318@@ -2317,6 +2404,23 @@ retry_lookup:
47319 /*
47320 * It already exists.
47321 */
47322+
47323+ if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
47324+ error = -ENOENT;
47325+ goto exit_mutex_unlock;
47326+ }
47327+ if (link && gr_handle_symlink_owner(link, dentry->d_inode)) {
47328+ error = -EACCES;
47329+ goto exit_mutex_unlock;
47330+ }
47331+
47332+ /* only check if O_CREAT is specified, all other checks need to go
47333+ into may_open */
47334+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
47335+ error = -EACCES;
47336+ goto exit_mutex_unlock;
47337+ }
47338+
47339 mutex_unlock(&dir->d_inode->i_mutex);
47340 audit_inode(pathname, path->dentry);
47341
47342@@ -2349,6 +2453,11 @@ finish_lookup:
47343 }
47344 }
47345 BUG_ON(inode != path->dentry->d_inode);
47346+ /* if we're resolving a symlink to another symlink */
47347+ if (link && gr_handle_symlink_owner(link, inode)) {
47348+ error = -EACCES;
47349+ goto exit;
47350+ }
47351 return NULL;
47352 }
47353
47354@@ -2358,7 +2467,6 @@ finish_lookup:
47355 save_parent.dentry = nd->path.dentry;
47356 save_parent.mnt = mntget(path->mnt);
47357 nd->path.dentry = path->dentry;
47358-
47359 }
47360 nd->inode = inode;
47361 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
47362@@ -2367,6 +2475,21 @@ finish_lookup:
47363 path_put(&save_parent);
47364 return ERR_PTR(error);
47365 }
47366+#ifdef CONFIG_GRKERNSEC
47367+ if (nd->flags & LOOKUP_RCU) {
47368+ error = -ECHILD;
47369+ goto exit;
47370+ }
47371+#endif
47372+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47373+ error = -ENOENT;
47374+ goto exit;
47375+ }
47376+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
47377+ error = -EACCES;
47378+ goto exit;
47379+ }
47380+
47381 error = -EISDIR;
47382 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
47383 goto exit;
47384@@ -2461,7 +2584,7 @@ static struct file *path_openat(int dfd, const char *pathname,
47385 if (unlikely(error))
47386 goto out_filp;
47387
47388- filp = do_last(nd, &path, op, pathname);
47389+ filp = do_last(nd, &path, NULL, op, pathname);
47390 while (unlikely(!filp)) { /* trailing symlink */
47391 struct path link = path;
47392 void *cookie;
47393@@ -2476,8 +2599,9 @@ static struct file *path_openat(int dfd, const char *pathname,
47394 error = follow_link(&link, nd, &cookie);
47395 if (unlikely(error))
47396 filp = ERR_PTR(error);
47397- else
47398- filp = do_last(nd, &path, op, pathname);
47399+ else {
47400+ filp = do_last(nd, &path, &link, op, pathname);
47401+ }
47402 put_link(nd, &link, cookie);
47403 }
47404 out:
47405@@ -2577,6 +2701,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
47406 *path = nd.path;
47407 return dentry;
47408 eexist:
47409+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
47410+ dput(dentry);
47411+ dentry = ERR_PTR(-ENOENT);
47412+ goto fail;
47413+ }
47414 dput(dentry);
47415 dentry = ERR_PTR(-EEXIST);
47416 fail:
47417@@ -2599,6 +2728,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
47418 }
47419 EXPORT_SYMBOL(user_path_create);
47420
47421+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
47422+{
47423+ char *tmp = getname(pathname);
47424+ struct dentry *res;
47425+ if (IS_ERR(tmp))
47426+ return ERR_CAST(tmp);
47427+ res = kern_path_create(dfd, tmp, path, is_dir);
47428+ if (IS_ERR(res))
47429+ putname(tmp);
47430+ else
47431+ *to = tmp;
47432+ return res;
47433+}
47434+
47435 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
47436 {
47437 int error = may_create(dir, dentry);
47438@@ -2665,6 +2808,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47439 error = mnt_want_write(path.mnt);
47440 if (error)
47441 goto out_dput;
47442+
47443+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
47444+ error = -EPERM;
47445+ goto out_drop_write;
47446+ }
47447+
47448+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
47449+ error = -EACCES;
47450+ goto out_drop_write;
47451+ }
47452+
47453 error = security_path_mknod(&path, dentry, mode, dev);
47454 if (error)
47455 goto out_drop_write;
47456@@ -2682,6 +2836,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47457 }
47458 out_drop_write:
47459 mnt_drop_write(path.mnt);
47460+
47461+ if (!error)
47462+ gr_handle_create(dentry, path.mnt);
47463 out_dput:
47464 dput(dentry);
47465 mutex_unlock(&path.dentry->d_inode->i_mutex);
47466@@ -2735,12 +2892,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
47467 error = mnt_want_write(path.mnt);
47468 if (error)
47469 goto out_dput;
47470+
47471+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
47472+ error = -EACCES;
47473+ goto out_drop_write;
47474+ }
47475+
47476 error = security_path_mkdir(&path, dentry, mode);
47477 if (error)
47478 goto out_drop_write;
47479 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
47480 out_drop_write:
47481 mnt_drop_write(path.mnt);
47482+
47483+ if (!error)
47484+ gr_handle_create(dentry, path.mnt);
47485 out_dput:
47486 dput(dentry);
47487 mutex_unlock(&path.dentry->d_inode->i_mutex);
47488@@ -2820,6 +2986,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47489 char * name;
47490 struct dentry *dentry;
47491 struct nameidata nd;
47492+ ino_t saved_ino = 0;
47493+ dev_t saved_dev = 0;
47494
47495 error = user_path_parent(dfd, pathname, &nd, &name);
47496 if (error)
47497@@ -2848,6 +3016,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
47498 error = -ENOENT;
47499 goto exit3;
47500 }
47501+
47502+ saved_ino = dentry->d_inode->i_ino;
47503+ saved_dev = gr_get_dev_from_dentry(dentry);
47504+
47505+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
47506+ error = -EACCES;
47507+ goto exit3;
47508+ }
47509+
47510 error = mnt_want_write(nd.path.mnt);
47511 if (error)
47512 goto exit3;
47513@@ -2855,6 +3032,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47514 if (error)
47515 goto exit4;
47516 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
47517+ if (!error && (saved_dev || saved_ino))
47518+ gr_handle_delete(saved_ino, saved_dev);
47519 exit4:
47520 mnt_drop_write(nd.path.mnt);
47521 exit3:
47522@@ -2917,6 +3096,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47523 struct dentry *dentry;
47524 struct nameidata nd;
47525 struct inode *inode = NULL;
47526+ ino_t saved_ino = 0;
47527+ dev_t saved_dev = 0;
47528
47529 error = user_path_parent(dfd, pathname, &nd, &name);
47530 if (error)
47531@@ -2939,6 +3120,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47532 if (!inode)
47533 goto slashes;
47534 ihold(inode);
47535+
47536+ if (inode->i_nlink <= 1) {
47537+ saved_ino = inode->i_ino;
47538+ saved_dev = gr_get_dev_from_dentry(dentry);
47539+ }
47540+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
47541+ error = -EACCES;
47542+ goto exit2;
47543+ }
47544+
47545 error = mnt_want_write(nd.path.mnt);
47546 if (error)
47547 goto exit2;
47548@@ -2946,6 +3137,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47549 if (error)
47550 goto exit3;
47551 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
47552+ if (!error && (saved_ino || saved_dev))
47553+ gr_handle_delete(saved_ino, saved_dev);
47554 exit3:
47555 mnt_drop_write(nd.path.mnt);
47556 exit2:
47557@@ -3021,10 +3214,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
47558 error = mnt_want_write(path.mnt);
47559 if (error)
47560 goto out_dput;
47561+
47562+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
47563+ error = -EACCES;
47564+ goto out_drop_write;
47565+ }
47566+
47567 error = security_path_symlink(&path, dentry, from);
47568 if (error)
47569 goto out_drop_write;
47570 error = vfs_symlink(path.dentry->d_inode, dentry, from);
47571+ if (!error)
47572+ gr_handle_create(dentry, path.mnt);
47573 out_drop_write:
47574 mnt_drop_write(path.mnt);
47575 out_dput:
47576@@ -3099,6 +3300,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47577 {
47578 struct dentry *new_dentry;
47579 struct path old_path, new_path;
47580+ char *to = NULL;
47581 int how = 0;
47582 int error;
47583
47584@@ -3122,7 +3324,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47585 if (error)
47586 return error;
47587
47588- new_dentry = user_path_create(newdfd, newname, &new_path, 0);
47589+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
47590 error = PTR_ERR(new_dentry);
47591 if (IS_ERR(new_dentry))
47592 goto out;
47593@@ -3133,13 +3335,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47594 error = mnt_want_write(new_path.mnt);
47595 if (error)
47596 goto out_dput;
47597+
47598+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
47599+ old_path.dentry->d_inode,
47600+ old_path.dentry->d_inode->i_mode, to)) {
47601+ error = -EACCES;
47602+ goto out_drop_write;
47603+ }
47604+
47605+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
47606+ old_path.dentry, old_path.mnt, to)) {
47607+ error = -EACCES;
47608+ goto out_drop_write;
47609+ }
47610+
47611 error = security_path_link(old_path.dentry, &new_path, new_dentry);
47612 if (error)
47613 goto out_drop_write;
47614 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
47615+ if (!error)
47616+ gr_handle_create(new_dentry, new_path.mnt);
47617 out_drop_write:
47618 mnt_drop_write(new_path.mnt);
47619 out_dput:
47620+ putname(to);
47621 dput(new_dentry);
47622 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
47623 path_put(&new_path);
47624@@ -3373,6 +3592,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47625 if (new_dentry == trap)
47626 goto exit5;
47627
47628+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
47629+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
47630+ to);
47631+ if (error)
47632+ goto exit5;
47633+
47634 error = mnt_want_write(oldnd.path.mnt);
47635 if (error)
47636 goto exit5;
47637@@ -3382,6 +3607,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47638 goto exit6;
47639 error = vfs_rename(old_dir->d_inode, old_dentry,
47640 new_dir->d_inode, new_dentry);
47641+ if (!error)
47642+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
47643+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
47644 exit6:
47645 mnt_drop_write(oldnd.path.mnt);
47646 exit5:
47647@@ -3407,6 +3635,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
47648
47649 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
47650 {
47651+ char tmpbuf[64];
47652+ const char *newlink;
47653 int len;
47654
47655 len = PTR_ERR(link);
47656@@ -3416,7 +3646,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
47657 len = strlen(link);
47658 if (len > (unsigned) buflen)
47659 len = buflen;
47660- if (copy_to_user(buffer, link, len))
47661+
47662+ if (len < sizeof(tmpbuf)) {
47663+ memcpy(tmpbuf, link, len);
47664+ newlink = tmpbuf;
47665+ } else
47666+ newlink = link;
47667+
47668+ if (copy_to_user(buffer, newlink, len))
47669 len = -EFAULT;
47670 out:
47671 return len;
47672diff --git a/fs/namespace.c b/fs/namespace.c
47673index 1e4a5fe..a5ce747 100644
47674--- a/fs/namespace.c
47675+++ b/fs/namespace.c
47676@@ -1157,6 +1157,9 @@ static int do_umount(struct mount *mnt, int flags)
47677 if (!(sb->s_flags & MS_RDONLY))
47678 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
47679 up_write(&sb->s_umount);
47680+
47681+ gr_log_remount(mnt->mnt_devname, retval);
47682+
47683 return retval;
47684 }
47685
47686@@ -1176,6 +1179,9 @@ static int do_umount(struct mount *mnt, int flags)
47687 br_write_unlock(&vfsmount_lock);
47688 up_write(&namespace_sem);
47689 release_mounts(&umount_list);
47690+
47691+ gr_log_unmount(mnt->mnt_devname, retval);
47692+
47693 return retval;
47694 }
47695
47696@@ -2177,6 +2183,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47697 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
47698 MS_STRICTATIME);
47699
47700+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
47701+ retval = -EPERM;
47702+ goto dput_out;
47703+ }
47704+
47705+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
47706+ retval = -EPERM;
47707+ goto dput_out;
47708+ }
47709+
47710 if (flags & MS_REMOUNT)
47711 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
47712 data_page);
47713@@ -2191,6 +2207,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47714 dev_name, data_page);
47715 dput_out:
47716 path_put(&path);
47717+
47718+ gr_log_mount(dev_name, dir_name, retval);
47719+
47720 return retval;
47721 }
47722
47723@@ -2472,6 +2491,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
47724 if (error)
47725 goto out2;
47726
47727+ if (gr_handle_chroot_pivot()) {
47728+ error = -EPERM;
47729+ goto out2;
47730+ }
47731+
47732 get_fs_root(current->fs, &root);
47733 error = lock_mount(&old);
47734 if (error)
47735diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
47736index f729698..2bac081 100644
47737--- a/fs/nfs/inode.c
47738+++ b/fs/nfs/inode.c
47739@@ -152,7 +152,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
47740 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
47741 nfsi->attrtimeo_timestamp = jiffies;
47742
47743- memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
47744+ memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
47745 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
47746 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
47747 else
47748@@ -1008,16 +1008,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
47749 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
47750 }
47751
47752-static atomic_long_t nfs_attr_generation_counter;
47753+static atomic_long_unchecked_t nfs_attr_generation_counter;
47754
47755 static unsigned long nfs_read_attr_generation_counter(void)
47756 {
47757- return atomic_long_read(&nfs_attr_generation_counter);
47758+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
47759 }
47760
47761 unsigned long nfs_inc_attr_generation_counter(void)
47762 {
47763- return atomic_long_inc_return(&nfs_attr_generation_counter);
47764+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
47765 }
47766
47767 void nfs_fattr_init(struct nfs_fattr *fattr)
47768diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
47769index c8bd9c3..4f83416 100644
47770--- a/fs/nfsd/vfs.c
47771+++ b/fs/nfsd/vfs.c
47772@@ -933,7 +933,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47773 } else {
47774 oldfs = get_fs();
47775 set_fs(KERNEL_DS);
47776- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
47777+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
47778 set_fs(oldfs);
47779 }
47780
47781@@ -1037,7 +1037,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47782
47783 /* Write the data. */
47784 oldfs = get_fs(); set_fs(KERNEL_DS);
47785- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
47786+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
47787 set_fs(oldfs);
47788 if (host_err < 0)
47789 goto out_nfserr;
47790@@ -1573,7 +1573,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
47791 */
47792
47793 oldfs = get_fs(); set_fs(KERNEL_DS);
47794- host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
47795+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
47796 set_fs(oldfs);
47797
47798 if (host_err < 0)
47799diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
47800index 3568c8a..e0240d8 100644
47801--- a/fs/notify/fanotify/fanotify_user.c
47802+++ b/fs/notify/fanotify/fanotify_user.c
47803@@ -278,7 +278,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
47804 goto out_close_fd;
47805
47806 ret = -EFAULT;
47807- if (copy_to_user(buf, &fanotify_event_metadata,
47808+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
47809+ copy_to_user(buf, &fanotify_event_metadata,
47810 fanotify_event_metadata.event_len))
47811 goto out_kill_access_response;
47812
47813diff --git a/fs/notify/notification.c b/fs/notify/notification.c
47814index c887b13..0fdf472 100644
47815--- a/fs/notify/notification.c
47816+++ b/fs/notify/notification.c
47817@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
47818 * get set to 0 so it will never get 'freed'
47819 */
47820 static struct fsnotify_event *q_overflow_event;
47821-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47822+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47823
47824 /**
47825 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
47826@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47827 */
47828 u32 fsnotify_get_cookie(void)
47829 {
47830- return atomic_inc_return(&fsnotify_sync_cookie);
47831+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
47832 }
47833 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
47834
47835diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
47836index 99e3610..02c1068 100644
47837--- a/fs/ntfs/dir.c
47838+++ b/fs/ntfs/dir.c
47839@@ -1329,7 +1329,7 @@ find_next_index_buffer:
47840 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
47841 ~(s64)(ndir->itype.index.block_size - 1)));
47842 /* Bounds checks. */
47843- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47844+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47845 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
47846 "inode 0x%lx or driver bug.", vdir->i_ino);
47847 goto err_out;
47848diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
47849index 7389d2d..dfd5dbe 100644
47850--- a/fs/ntfs/file.c
47851+++ b/fs/ntfs/file.c
47852@@ -2231,6 +2231,6 @@ const struct inode_operations ntfs_file_inode_ops = {
47853 #endif /* NTFS_RW */
47854 };
47855
47856-const struct file_operations ntfs_empty_file_ops = {};
47857+const struct file_operations ntfs_empty_file_ops __read_only;
47858
47859-const struct inode_operations ntfs_empty_inode_ops = {};
47860+const struct inode_operations ntfs_empty_inode_ops __read_only;
47861diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
47862index 210c352..a174f83 100644
47863--- a/fs/ocfs2/localalloc.c
47864+++ b/fs/ocfs2/localalloc.c
47865@@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
47866 goto bail;
47867 }
47868
47869- atomic_inc(&osb->alloc_stats.moves);
47870+ atomic_inc_unchecked(&osb->alloc_stats.moves);
47871
47872 bail:
47873 if (handle)
47874diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
47875index d355e6e..578d905 100644
47876--- a/fs/ocfs2/ocfs2.h
47877+++ b/fs/ocfs2/ocfs2.h
47878@@ -235,11 +235,11 @@ enum ocfs2_vol_state
47879
47880 struct ocfs2_alloc_stats
47881 {
47882- atomic_t moves;
47883- atomic_t local_data;
47884- atomic_t bitmap_data;
47885- atomic_t bg_allocs;
47886- atomic_t bg_extends;
47887+ atomic_unchecked_t moves;
47888+ atomic_unchecked_t local_data;
47889+ atomic_unchecked_t bitmap_data;
47890+ atomic_unchecked_t bg_allocs;
47891+ atomic_unchecked_t bg_extends;
47892 };
47893
47894 enum ocfs2_local_alloc_state
47895diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
47896index f169da4..9112253 100644
47897--- a/fs/ocfs2/suballoc.c
47898+++ b/fs/ocfs2/suballoc.c
47899@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
47900 mlog_errno(status);
47901 goto bail;
47902 }
47903- atomic_inc(&osb->alloc_stats.bg_extends);
47904+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
47905
47906 /* You should never ask for this much metadata */
47907 BUG_ON(bits_wanted >
47908@@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
47909 mlog_errno(status);
47910 goto bail;
47911 }
47912- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47913+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47914
47915 *suballoc_loc = res.sr_bg_blkno;
47916 *suballoc_bit_start = res.sr_bit_offset;
47917@@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
47918 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
47919 res->sr_bits);
47920
47921- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47922+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47923
47924 BUG_ON(res->sr_bits != 1);
47925
47926@@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
47927 mlog_errno(status);
47928 goto bail;
47929 }
47930- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47931+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47932
47933 BUG_ON(res.sr_bits != 1);
47934
47935@@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47936 cluster_start,
47937 num_clusters);
47938 if (!status)
47939- atomic_inc(&osb->alloc_stats.local_data);
47940+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
47941 } else {
47942 if (min_clusters > (osb->bitmap_cpg - 1)) {
47943 /* The only paths asking for contiguousness
47944@@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47945 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
47946 res.sr_bg_blkno,
47947 res.sr_bit_offset);
47948- atomic_inc(&osb->alloc_stats.bitmap_data);
47949+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
47950 *num_clusters = res.sr_bits;
47951 }
47952 }
47953diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
47954index 68f4541..89cfe6a 100644
47955--- a/fs/ocfs2/super.c
47956+++ b/fs/ocfs2/super.c
47957@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
47958 "%10s => GlobalAllocs: %d LocalAllocs: %d "
47959 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
47960 "Stats",
47961- atomic_read(&osb->alloc_stats.bitmap_data),
47962- atomic_read(&osb->alloc_stats.local_data),
47963- atomic_read(&osb->alloc_stats.bg_allocs),
47964- atomic_read(&osb->alloc_stats.moves),
47965- atomic_read(&osb->alloc_stats.bg_extends));
47966+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
47967+ atomic_read_unchecked(&osb->alloc_stats.local_data),
47968+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
47969+ atomic_read_unchecked(&osb->alloc_stats.moves),
47970+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
47971
47972 out += snprintf(buf + out, len - out,
47973 "%10s => State: %u Descriptor: %llu Size: %u bits "
47974@@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
47975 spin_lock_init(&osb->osb_xattr_lock);
47976 ocfs2_init_steal_slots(osb);
47977
47978- atomic_set(&osb->alloc_stats.moves, 0);
47979- atomic_set(&osb->alloc_stats.local_data, 0);
47980- atomic_set(&osb->alloc_stats.bitmap_data, 0);
47981- atomic_set(&osb->alloc_stats.bg_allocs, 0);
47982- atomic_set(&osb->alloc_stats.bg_extends, 0);
47983+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
47984+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
47985+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
47986+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
47987+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
47988
47989 /* Copy the blockcheck stats from the superblock probe */
47990 osb->osb_ecc_stats = *stats;
47991diff --git a/fs/open.c b/fs/open.c
47992index 1540632..79d7242 100644
47993--- a/fs/open.c
47994+++ b/fs/open.c
47995@@ -31,6 +31,8 @@
47996 #include <linux/ima.h>
47997 #include <linux/dnotify.h>
47998
47999+#define CREATE_TRACE_POINTS
48000+#include <trace/events/fs.h>
48001 #include "internal.h"
48002
48003 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
48004@@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
48005 error = locks_verify_truncate(inode, NULL, length);
48006 if (!error)
48007 error = security_path_truncate(&path);
48008+
48009+ if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
48010+ error = -EACCES;
48011+
48012 if (!error)
48013 error = do_truncate(path.dentry, length, 0, NULL);
48014
48015@@ -359,6 +365,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
48016 if (__mnt_is_readonly(path.mnt))
48017 res = -EROFS;
48018
48019+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
48020+ res = -EACCES;
48021+
48022 out_path_release:
48023 path_put(&path);
48024 out:
48025@@ -385,6 +394,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
48026 if (error)
48027 goto dput_and_out;
48028
48029+ gr_log_chdir(path.dentry, path.mnt);
48030+
48031 set_fs_pwd(current->fs, &path);
48032
48033 dput_and_out:
48034@@ -411,6 +422,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
48035 goto out_putf;
48036
48037 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
48038+
48039+ if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
48040+ error = -EPERM;
48041+
48042+ if (!error)
48043+ gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
48044+
48045 if (!error)
48046 set_fs_pwd(current->fs, &file->f_path);
48047 out_putf:
48048@@ -439,7 +457,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
48049 if (error)
48050 goto dput_and_out;
48051
48052+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
48053+ goto dput_and_out;
48054+
48055 set_fs_root(current->fs, &path);
48056+
48057+ gr_handle_chroot_chdir(&path);
48058+
48059 error = 0;
48060 dput_and_out:
48061 path_put(&path);
48062@@ -457,6 +481,16 @@ static int chmod_common(struct path *path, umode_t mode)
48063 if (error)
48064 return error;
48065 mutex_lock(&inode->i_mutex);
48066+
48067+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
48068+ error = -EACCES;
48069+ goto out_unlock;
48070+ }
48071+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
48072+ error = -EACCES;
48073+ goto out_unlock;
48074+ }
48075+
48076 error = security_path_chmod(path, mode);
48077 if (error)
48078 goto out_unlock;
48079@@ -512,6 +546,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
48080 uid = make_kuid(current_user_ns(), user);
48081 gid = make_kgid(current_user_ns(), group);
48082
48083+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
48084+ return -EACCES;
48085+
48086 newattrs.ia_valid = ATTR_CTIME;
48087 if (user != (uid_t) -1) {
48088 if (!uid_valid(uid))
48089@@ -1035,6 +1072,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
48090 } else {
48091 fsnotify_open(f);
48092 fd_install(fd, f);
48093+ trace_do_sys_open(tmp, flags, mode);
48094 }
48095 }
48096 putname(tmp);
48097diff --git a/fs/pipe.c b/fs/pipe.c
48098index 49c1065..13b9e12 100644
48099--- a/fs/pipe.c
48100+++ b/fs/pipe.c
48101@@ -438,9 +438,9 @@ redo:
48102 }
48103 if (bufs) /* More to do? */
48104 continue;
48105- if (!pipe->writers)
48106+ if (!atomic_read(&pipe->writers))
48107 break;
48108- if (!pipe->waiting_writers) {
48109+ if (!atomic_read(&pipe->waiting_writers)) {
48110 /* syscall merging: Usually we must not sleep
48111 * if O_NONBLOCK is set, or if we got some data.
48112 * But if a writer sleeps in kernel space, then
48113@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
48114 mutex_lock(&inode->i_mutex);
48115 pipe = inode->i_pipe;
48116
48117- if (!pipe->readers) {
48118+ if (!atomic_read(&pipe->readers)) {
48119 send_sig(SIGPIPE, current, 0);
48120 ret = -EPIPE;
48121 goto out;
48122@@ -553,7 +553,7 @@ redo1:
48123 for (;;) {
48124 int bufs;
48125
48126- if (!pipe->readers) {
48127+ if (!atomic_read(&pipe->readers)) {
48128 send_sig(SIGPIPE, current, 0);
48129 if (!ret)
48130 ret = -EPIPE;
48131@@ -644,9 +644,9 @@ redo2:
48132 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
48133 do_wakeup = 0;
48134 }
48135- pipe->waiting_writers++;
48136+ atomic_inc(&pipe->waiting_writers);
48137 pipe_wait(pipe);
48138- pipe->waiting_writers--;
48139+ atomic_dec(&pipe->waiting_writers);
48140 }
48141 out:
48142 mutex_unlock(&inode->i_mutex);
48143@@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48144 mask = 0;
48145 if (filp->f_mode & FMODE_READ) {
48146 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
48147- if (!pipe->writers && filp->f_version != pipe->w_counter)
48148+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
48149 mask |= POLLHUP;
48150 }
48151
48152@@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48153 * Most Unices do not set POLLERR for FIFOs but on Linux they
48154 * behave exactly like pipes for poll().
48155 */
48156- if (!pipe->readers)
48157+ if (!atomic_read(&pipe->readers))
48158 mask |= POLLERR;
48159 }
48160
48161@@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
48162
48163 mutex_lock(&inode->i_mutex);
48164 pipe = inode->i_pipe;
48165- pipe->readers -= decr;
48166- pipe->writers -= decw;
48167+ atomic_sub(decr, &pipe->readers);
48168+ atomic_sub(decw, &pipe->writers);
48169
48170- if (!pipe->readers && !pipe->writers) {
48171+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
48172 free_pipe_info(inode);
48173 } else {
48174 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
48175@@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
48176
48177 if (inode->i_pipe) {
48178 ret = 0;
48179- inode->i_pipe->readers++;
48180+ atomic_inc(&inode->i_pipe->readers);
48181 }
48182
48183 mutex_unlock(&inode->i_mutex);
48184@@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
48185
48186 if (inode->i_pipe) {
48187 ret = 0;
48188- inode->i_pipe->writers++;
48189+ atomic_inc(&inode->i_pipe->writers);
48190 }
48191
48192 mutex_unlock(&inode->i_mutex);
48193@@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
48194 if (inode->i_pipe) {
48195 ret = 0;
48196 if (filp->f_mode & FMODE_READ)
48197- inode->i_pipe->readers++;
48198+ atomic_inc(&inode->i_pipe->readers);
48199 if (filp->f_mode & FMODE_WRITE)
48200- inode->i_pipe->writers++;
48201+ atomic_inc(&inode->i_pipe->writers);
48202 }
48203
48204 mutex_unlock(&inode->i_mutex);
48205@@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
48206 inode->i_pipe = NULL;
48207 }
48208
48209-static struct vfsmount *pipe_mnt __read_mostly;
48210+struct vfsmount *pipe_mnt __read_mostly;
48211
48212 /*
48213 * pipefs_dname() is called from d_path().
48214@@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
48215 goto fail_iput;
48216 inode->i_pipe = pipe;
48217
48218- pipe->readers = pipe->writers = 1;
48219+ atomic_set(&pipe->readers, 1);
48220+ atomic_set(&pipe->writers, 1);
48221 inode->i_fop = &rdwr_pipefifo_fops;
48222
48223 /*
48224diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
48225index 15af622..0e9f4467 100644
48226--- a/fs/proc/Kconfig
48227+++ b/fs/proc/Kconfig
48228@@ -30,12 +30,12 @@ config PROC_FS
48229
48230 config PROC_KCORE
48231 bool "/proc/kcore support" if !ARM
48232- depends on PROC_FS && MMU
48233+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
48234
48235 config PROC_VMCORE
48236 bool "/proc/vmcore support"
48237- depends on PROC_FS && CRASH_DUMP
48238- default y
48239+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
48240+ default n
48241 help
48242 Exports the dump image of crashed kernel in ELF format.
48243
48244@@ -59,8 +59,8 @@ config PROC_SYSCTL
48245 limited in memory.
48246
48247 config PROC_PAGE_MONITOR
48248- default y
48249- depends on PROC_FS && MMU
48250+ default n
48251+ depends on PROC_FS && MMU && !GRKERNSEC
48252 bool "Enable /proc page monitoring" if EXPERT
48253 help
48254 Various /proc files exist to monitor process memory utilization:
48255diff --git a/fs/proc/array.c b/fs/proc/array.c
48256index c1c207c..5179411 100644
48257--- a/fs/proc/array.c
48258+++ b/fs/proc/array.c
48259@@ -60,6 +60,7 @@
48260 #include <linux/tty.h>
48261 #include <linux/string.h>
48262 #include <linux/mman.h>
48263+#include <linux/grsecurity.h>
48264 #include <linux/proc_fs.h>
48265 #include <linux/ioport.h>
48266 #include <linux/uaccess.h>
48267@@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
48268 seq_putc(m, '\n');
48269 }
48270
48271+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48272+static inline void task_pax(struct seq_file *m, struct task_struct *p)
48273+{
48274+ if (p->mm)
48275+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
48276+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
48277+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
48278+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
48279+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
48280+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
48281+ else
48282+ seq_printf(m, "PaX:\t-----\n");
48283+}
48284+#endif
48285+
48286 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48287 struct pid *pid, struct task_struct *task)
48288 {
48289@@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48290 task_cpus_allowed(m, task);
48291 cpuset_task_status_allowed(m, task);
48292 task_context_switch_counts(m, task);
48293+
48294+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48295+ task_pax(m, task);
48296+#endif
48297+
48298+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
48299+ task_grsec_rbac(m, task);
48300+#endif
48301+
48302 return 0;
48303 }
48304
48305+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48306+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48307+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
48308+ _mm->pax_flags & MF_PAX_SEGMEXEC))
48309+#endif
48310+
48311 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48312 struct pid *pid, struct task_struct *task, int whole)
48313 {
48314@@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48315 char tcomm[sizeof(task->comm)];
48316 unsigned long flags;
48317
48318+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48319+ if (current->exec_id != m->exec_id) {
48320+ gr_log_badprocpid("stat");
48321+ return 0;
48322+ }
48323+#endif
48324+
48325 state = *get_task_state(task);
48326 vsize = eip = esp = 0;
48327 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48328@@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48329 gtime = task->gtime;
48330 }
48331
48332+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48333+ if (PAX_RAND_FLAGS(mm)) {
48334+ eip = 0;
48335+ esp = 0;
48336+ wchan = 0;
48337+ }
48338+#endif
48339+#ifdef CONFIG_GRKERNSEC_HIDESYM
48340+ wchan = 0;
48341+ eip =0;
48342+ esp =0;
48343+#endif
48344+
48345 /* scale priority and nice values from timeslices to -20..20 */
48346 /* to make it look like a "normal" Unix priority/nice value */
48347 priority = task_prio(task);
48348@@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48349 seq_put_decimal_ull(m, ' ', vsize);
48350 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
48351 seq_put_decimal_ull(m, ' ', rsslim);
48352+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48353+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
48354+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
48355+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
48356+#else
48357 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
48358 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
48359 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
48360+#endif
48361 seq_put_decimal_ull(m, ' ', esp);
48362 seq_put_decimal_ull(m, ' ', eip);
48363 /* The signal information here is obsolete.
48364@@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48365 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
48366 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
48367
48368- if (mm && permitted) {
48369+ if (mm && permitted
48370+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48371+ && !PAX_RAND_FLAGS(mm)
48372+#endif
48373+ ) {
48374 seq_put_decimal_ull(m, ' ', mm->start_data);
48375 seq_put_decimal_ull(m, ' ', mm->end_data);
48376 seq_put_decimal_ull(m, ' ', mm->start_brk);
48377@@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48378 struct pid *pid, struct task_struct *task)
48379 {
48380 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
48381- struct mm_struct *mm = get_task_mm(task);
48382+ struct mm_struct *mm;
48383
48384+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48385+ if (current->exec_id != m->exec_id) {
48386+ gr_log_badprocpid("statm");
48387+ return 0;
48388+ }
48389+#endif
48390+ mm = get_task_mm(task);
48391 if (mm) {
48392 size = task_statm(mm, &shared, &text, &data, &resident);
48393 mmput(mm);
48394@@ -580,6 +648,21 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48395 return 0;
48396 }
48397
48398+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48399+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
48400+{
48401+ u32 curr_ip = 0;
48402+ unsigned long flags;
48403+
48404+ if (lock_task_sighand(task, &flags)) {
48405+ curr_ip = task->signal->curr_ip;
48406+ unlock_task_sighand(task, &flags);
48407+ }
48408+
48409+ return sprintf(buffer, "%pI4\n", &curr_ip);
48410+}
48411+#endif
48412+
48413 #ifdef CONFIG_CHECKPOINT_RESTORE
48414 static struct pid *
48415 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
48416diff --git a/fs/proc/base.c b/fs/proc/base.c
48417index 437195f..cd2210d 100644
48418--- a/fs/proc/base.c
48419+++ b/fs/proc/base.c
48420@@ -110,6 +110,14 @@ struct pid_entry {
48421 union proc_op op;
48422 };
48423
48424+struct getdents_callback {
48425+ struct linux_dirent __user * current_dir;
48426+ struct linux_dirent __user * previous;
48427+ struct file * file;
48428+ int count;
48429+ int error;
48430+};
48431+
48432 #define NOD(NAME, MODE, IOP, FOP, OP) { \
48433 .name = (NAME), \
48434 .len = sizeof(NAME) - 1, \
48435@@ -209,6 +217,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
48436 if (!mm->arg_end)
48437 goto out_mm; /* Shh! No looking before we're done */
48438
48439+ if (gr_acl_handle_procpidmem(task))
48440+ goto out_mm;
48441+
48442 len = mm->arg_end - mm->arg_start;
48443
48444 if (len > PAGE_SIZE)
48445@@ -236,12 +247,28 @@ out:
48446 return res;
48447 }
48448
48449+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48450+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48451+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
48452+ _mm->pax_flags & MF_PAX_SEGMEXEC))
48453+#endif
48454+
48455 static int proc_pid_auxv(struct task_struct *task, char *buffer)
48456 {
48457 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
48458 int res = PTR_ERR(mm);
48459 if (mm && !IS_ERR(mm)) {
48460 unsigned int nwords = 0;
48461+
48462+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48463+ /* allow if we're currently ptracing this task */
48464+ if (PAX_RAND_FLAGS(mm) &&
48465+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
48466+ mmput(mm);
48467+ return 0;
48468+ }
48469+#endif
48470+
48471 do {
48472 nwords += 2;
48473 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
48474@@ -255,7 +282,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
48475 }
48476
48477
48478-#ifdef CONFIG_KALLSYMS
48479+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48480 /*
48481 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
48482 * Returns the resolved symbol. If that fails, simply return the address.
48483@@ -294,7 +321,7 @@ static void unlock_trace(struct task_struct *task)
48484 mutex_unlock(&task->signal->cred_guard_mutex);
48485 }
48486
48487-#ifdef CONFIG_STACKTRACE
48488+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48489
48490 #define MAX_STACK_TRACE_DEPTH 64
48491
48492@@ -486,7 +513,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
48493 return count;
48494 }
48495
48496-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48497+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48498 static int proc_pid_syscall(struct task_struct *task, char *buffer)
48499 {
48500 long nr;
48501@@ -515,7 +542,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
48502 /************************************************************************/
48503
48504 /* permission checks */
48505-static int proc_fd_access_allowed(struct inode *inode)
48506+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
48507 {
48508 struct task_struct *task;
48509 int allowed = 0;
48510@@ -525,7 +552,10 @@ static int proc_fd_access_allowed(struct inode *inode)
48511 */
48512 task = get_proc_task(inode);
48513 if (task) {
48514- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48515+ if (log)
48516+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48517+ else
48518+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48519 put_task_struct(task);
48520 }
48521 return allowed;
48522@@ -563,10 +593,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
48523 struct task_struct *task,
48524 int hide_pid_min)
48525 {
48526+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48527+ return false;
48528+
48529+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48530+ rcu_read_lock();
48531+ {
48532+ const struct cred *tmpcred = current_cred();
48533+ const struct cred *cred = __task_cred(task);
48534+
48535+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
48536+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48537+ || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
48538+#endif
48539+ ) {
48540+ rcu_read_unlock();
48541+ return true;
48542+ }
48543+ }
48544+ rcu_read_unlock();
48545+
48546+ if (!pid->hide_pid)
48547+ return false;
48548+#endif
48549+
48550 if (pid->hide_pid < hide_pid_min)
48551 return true;
48552 if (in_group_p(pid->pid_gid))
48553 return true;
48554+
48555 return ptrace_may_access(task, PTRACE_MODE_READ);
48556 }
48557
48558@@ -584,7 +639,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
48559 put_task_struct(task);
48560
48561 if (!has_perms) {
48562+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48563+ {
48564+#else
48565 if (pid->hide_pid == 2) {
48566+#endif
48567 /*
48568 * Let's make getdents(), stat(), and open()
48569 * consistent with each other. If a process
48570@@ -682,6 +741,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
48571 if (!task)
48572 return -ESRCH;
48573
48574+ if (gr_acl_handle_procpidmem(task)) {
48575+ put_task_struct(task);
48576+ return -EPERM;
48577+ }
48578+
48579 mm = mm_access(task, mode);
48580 put_task_struct(task);
48581
48582@@ -695,16 +759,24 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
48583 mmput(mm);
48584 }
48585
48586- /* OK to pass negative loff_t, we can catch out-of-range */
48587- file->f_mode |= FMODE_UNSIGNED_OFFSET;
48588 file->private_data = mm;
48589
48590+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48591+ file->f_version = current->exec_id;
48592+#endif
48593+
48594 return 0;
48595 }
48596
48597 static int mem_open(struct inode *inode, struct file *file)
48598 {
48599- return __mem_open(inode, file, PTRACE_MODE_ATTACH);
48600+ int ret;
48601+ ret = __mem_open(inode, file, PTRACE_MODE_ATTACH);
48602+
48603+ /* OK to pass negative loff_t, we can catch out-of-range */
48604+ file->f_mode |= FMODE_UNSIGNED_OFFSET;
48605+
48606+ return ret;
48607 }
48608
48609 static ssize_t mem_rw(struct file *file, char __user *buf,
48610@@ -715,6 +787,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
48611 ssize_t copied;
48612 char *page;
48613
48614+#ifdef CONFIG_GRKERNSEC
48615+ if (write)
48616+ return -EPERM;
48617+#endif
48618+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48619+ if (file->f_version != current->exec_id) {
48620+ gr_log_badprocpid("mem");
48621+ return 0;
48622+ }
48623+#endif
48624+
48625 if (!mm)
48626 return 0;
48627
48628@@ -819,6 +902,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
48629 if (!mm)
48630 return 0;
48631
48632+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48633+ if (file->f_version != current->exec_id) {
48634+ gr_log_badprocpid("environ");
48635+ return 0;
48636+ }
48637+#endif
48638+
48639 page = (char *)__get_free_page(GFP_TEMPORARY);
48640 if (!page)
48641 return -ENOMEM;
48642@@ -827,15 +917,17 @@ static ssize_t environ_read(struct file *file, char __user *buf,
48643 if (!atomic_inc_not_zero(&mm->mm_users))
48644 goto free;
48645 while (count > 0) {
48646- int this_len, retval, max_len;
48647+ size_t this_len, max_len;
48648+ int retval;
48649+
48650+ if (src >= (mm->env_end - mm->env_start))
48651+ break;
48652
48653 this_len = mm->env_end - (mm->env_start + src);
48654
48655- if (this_len <= 0)
48656- break;
48657
48658- max_len = (count > PAGE_SIZE) ? PAGE_SIZE : count;
48659- this_len = (this_len > max_len) ? max_len : this_len;
48660+ max_len = min_t(size_t, PAGE_SIZE, count);
48661+ this_len = min(max_len, this_len);
48662
48663 retval = access_remote_vm(mm, (mm->env_start + src),
48664 page, this_len, 0);
48665@@ -1433,7 +1525,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
48666 path_put(&nd->path);
48667
48668 /* Are we allowed to snoop on the tasks file descriptors? */
48669- if (!proc_fd_access_allowed(inode))
48670+ if (!proc_fd_access_allowed(inode, 0))
48671 goto out;
48672
48673 error = PROC_I(inode)->op.proc_get_link(dentry, &nd->path);
48674@@ -1472,8 +1564,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
48675 struct path path;
48676
48677 /* Are we allowed to snoop on the tasks file descriptors? */
48678- if (!proc_fd_access_allowed(inode))
48679- goto out;
48680+ /* logging this is needed for learning on chromium to work properly,
48681+ but we don't want to flood the logs from 'ps' which does a readlink
48682+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
48683+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
48684+ */
48685+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
48686+ if (!proc_fd_access_allowed(inode,0))
48687+ goto out;
48688+ } else {
48689+ if (!proc_fd_access_allowed(inode,1))
48690+ goto out;
48691+ }
48692
48693 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
48694 if (error)
48695@@ -1538,7 +1640,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
48696 rcu_read_lock();
48697 cred = __task_cred(task);
48698 inode->i_uid = cred->euid;
48699+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48700+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48701+#else
48702 inode->i_gid = cred->egid;
48703+#endif
48704 rcu_read_unlock();
48705 }
48706 security_task_to_inode(task, inode);
48707@@ -1574,10 +1680,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
48708 return -ENOENT;
48709 }
48710 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48711+#ifdef CONFIG_GRKERNSEC_PROC_USER
48712+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48713+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48714+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48715+#endif
48716 task_dumpable(task)) {
48717 cred = __task_cred(task);
48718 stat->uid = cred->euid;
48719+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48720+ stat->gid = CONFIG_GRKERNSEC_PROC_GID;
48721+#else
48722 stat->gid = cred->egid;
48723+#endif
48724 }
48725 }
48726 rcu_read_unlock();
48727@@ -1615,11 +1730,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
48728
48729 if (task) {
48730 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48731+#ifdef CONFIG_GRKERNSEC_PROC_USER
48732+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48733+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48734+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48735+#endif
48736 task_dumpable(task)) {
48737 rcu_read_lock();
48738 cred = __task_cred(task);
48739 inode->i_uid = cred->euid;
48740+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48741+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48742+#else
48743 inode->i_gid = cred->egid;
48744+#endif
48745 rcu_read_unlock();
48746 } else {
48747 inode->i_uid = GLOBAL_ROOT_UID;
48748@@ -1737,7 +1861,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
48749 int fd = proc_fd(inode);
48750
48751 if (task) {
48752- files = get_files_struct(task);
48753+ if (!gr_acl_handle_procpidmem(task))
48754+ files = get_files_struct(task);
48755 put_task_struct(task);
48756 }
48757 if (files) {
48758@@ -2336,11 +2461,21 @@ static const struct file_operations proc_map_files_operations = {
48759 */
48760 static int proc_fd_permission(struct inode *inode, int mask)
48761 {
48762+ struct task_struct *task;
48763 int rv = generic_permission(inode, mask);
48764- if (rv == 0)
48765- return 0;
48766+
48767 if (task_pid(current) == proc_pid(inode))
48768 rv = 0;
48769+
48770+ task = get_proc_task(inode);
48771+ if (task == NULL)
48772+ return rv;
48773+
48774+ if (gr_acl_handle_procpidmem(task))
48775+ rv = -EACCES;
48776+
48777+ put_task_struct(task);
48778+
48779 return rv;
48780 }
48781
48782@@ -2450,6 +2585,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
48783 if (!task)
48784 goto out_no_task;
48785
48786+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48787+ goto out;
48788+
48789 /*
48790 * Yes, it does not scale. And it should not. Don't add
48791 * new entries into /proc/<tgid>/ without very good reasons.
48792@@ -2494,6 +2632,9 @@ static int proc_pident_readdir(struct file *filp,
48793 if (!task)
48794 goto out_no_task;
48795
48796+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48797+ goto out;
48798+
48799 ret = 0;
48800 i = filp->f_pos;
48801 switch (i) {
48802@@ -2764,7 +2905,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
48803 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
48804 void *cookie)
48805 {
48806- char *s = nd_get_link(nd);
48807+ const char *s = nd_get_link(nd);
48808 if (!IS_ERR(s))
48809 __putname(s);
48810 }
48811@@ -3033,7 +3174,7 @@ static const struct pid_entry tgid_base_stuff[] = {
48812 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
48813 #endif
48814 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48815-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48816+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48817 INF("syscall", S_IRUGO, proc_pid_syscall),
48818 #endif
48819 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48820@@ -3058,10 +3199,10 @@ static const struct pid_entry tgid_base_stuff[] = {
48821 #ifdef CONFIG_SECURITY
48822 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48823 #endif
48824-#ifdef CONFIG_KALLSYMS
48825+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48826 INF("wchan", S_IRUGO, proc_pid_wchan),
48827 #endif
48828-#ifdef CONFIG_STACKTRACE
48829+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48830 ONE("stack", S_IRUGO, proc_pid_stack),
48831 #endif
48832 #ifdef CONFIG_SCHEDSTATS
48833@@ -3095,6 +3236,9 @@ static const struct pid_entry tgid_base_stuff[] = {
48834 #ifdef CONFIG_HARDWALL
48835 INF("hardwall", S_IRUGO, proc_pid_hardwall),
48836 #endif
48837+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48838+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
48839+#endif
48840 #ifdef CONFIG_USER_NS
48841 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
48842 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
48843@@ -3225,7 +3369,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
48844 if (!inode)
48845 goto out;
48846
48847+#ifdef CONFIG_GRKERNSEC_PROC_USER
48848+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
48849+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48850+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48851+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
48852+#else
48853 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
48854+#endif
48855 inode->i_op = &proc_tgid_base_inode_operations;
48856 inode->i_fop = &proc_tgid_base_operations;
48857 inode->i_flags|=S_IMMUTABLE;
48858@@ -3267,7 +3418,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
48859 if (!task)
48860 goto out;
48861
48862+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48863+ goto out_put_task;
48864+
48865 result = proc_pid_instantiate(dir, dentry, task, NULL);
48866+out_put_task:
48867 put_task_struct(task);
48868 out:
48869 return result;
48870@@ -3330,6 +3485,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
48871 static int fake_filldir(void *buf, const char *name, int namelen,
48872 loff_t offset, u64 ino, unsigned d_type)
48873 {
48874+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
48875+ __buf->error = -EINVAL;
48876 return 0;
48877 }
48878
48879@@ -3396,7 +3553,7 @@ static const struct pid_entry tid_base_stuff[] = {
48880 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
48881 #endif
48882 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48883-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48884+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48885 INF("syscall", S_IRUGO, proc_pid_syscall),
48886 #endif
48887 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48888@@ -3423,10 +3580,10 @@ static const struct pid_entry tid_base_stuff[] = {
48889 #ifdef CONFIG_SECURITY
48890 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48891 #endif
48892-#ifdef CONFIG_KALLSYMS
48893+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48894 INF("wchan", S_IRUGO, proc_pid_wchan),
48895 #endif
48896-#ifdef CONFIG_STACKTRACE
48897+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48898 ONE("stack", S_IRUGO, proc_pid_stack),
48899 #endif
48900 #ifdef CONFIG_SCHEDSTATS
48901diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
48902index 82676e3..5f8518a 100644
48903--- a/fs/proc/cmdline.c
48904+++ b/fs/proc/cmdline.c
48905@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
48906
48907 static int __init proc_cmdline_init(void)
48908 {
48909+#ifdef CONFIG_GRKERNSEC_PROC_ADD
48910+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
48911+#else
48912 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
48913+#endif
48914 return 0;
48915 }
48916 module_init(proc_cmdline_init);
48917diff --git a/fs/proc/devices.c b/fs/proc/devices.c
48918index b143471..bb105e5 100644
48919--- a/fs/proc/devices.c
48920+++ b/fs/proc/devices.c
48921@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
48922
48923 static int __init proc_devices_init(void)
48924 {
48925+#ifdef CONFIG_GRKERNSEC_PROC_ADD
48926+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
48927+#else
48928 proc_create("devices", 0, NULL, &proc_devinfo_operations);
48929+#endif
48930 return 0;
48931 }
48932 module_init(proc_devices_init);
48933diff --git a/fs/proc/inode.c b/fs/proc/inode.c
48934index 7ac817b..abab1a5 100644
48935--- a/fs/proc/inode.c
48936+++ b/fs/proc/inode.c
48937@@ -21,11 +21,17 @@
48938 #include <linux/seq_file.h>
48939 #include <linux/slab.h>
48940 #include <linux/mount.h>
48941+#include <linux/grsecurity.h>
48942
48943 #include <asm/uaccess.h>
48944
48945 #include "internal.h"
48946
48947+#ifdef CONFIG_PROC_SYSCTL
48948+extern const struct inode_operations proc_sys_inode_operations;
48949+extern const struct inode_operations proc_sys_dir_operations;
48950+#endif
48951+
48952 static void proc_evict_inode(struct inode *inode)
48953 {
48954 struct proc_dir_entry *de;
48955@@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
48956 ns_ops = PROC_I(inode)->ns_ops;
48957 if (ns_ops && ns_ops->put)
48958 ns_ops->put(PROC_I(inode)->ns);
48959+
48960+#ifdef CONFIG_PROC_SYSCTL
48961+ if (inode->i_op == &proc_sys_inode_operations ||
48962+ inode->i_op == &proc_sys_dir_operations)
48963+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
48964+#endif
48965+
48966 }
48967
48968 static struct kmem_cache * proc_inode_cachep;
48969@@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
48970 if (de->mode) {
48971 inode->i_mode = de->mode;
48972 inode->i_uid = de->uid;
48973+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48974+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48975+#else
48976 inode->i_gid = de->gid;
48977+#endif
48978 }
48979 if (de->size)
48980 inode->i_size = de->size;
48981diff --git a/fs/proc/internal.h b/fs/proc/internal.h
48982index eca4aca..19166b2 100644
48983--- a/fs/proc/internal.h
48984+++ b/fs/proc/internal.h
48985@@ -52,6 +52,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48986 struct pid *pid, struct task_struct *task);
48987 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48988 struct pid *pid, struct task_struct *task);
48989+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48990+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
48991+#endif
48992 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
48993
48994 extern const struct file_operations proc_tid_children_operations;
48995diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
48996index 86c67ee..cdca321 100644
48997--- a/fs/proc/kcore.c
48998+++ b/fs/proc/kcore.c
48999@@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49000 * the addresses in the elf_phdr on our list.
49001 */
49002 start = kc_offset_to_vaddr(*fpos - elf_buflen);
49003- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
49004+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
49005+ if (tsz > buflen)
49006 tsz = buflen;
49007-
49008+
49009 while (buflen) {
49010 struct kcore_list *m;
49011
49012@@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49013 kfree(elf_buf);
49014 } else {
49015 if (kern_addr_valid(start)) {
49016- unsigned long n;
49017+ char *elf_buf;
49018+ mm_segment_t oldfs;
49019
49020- n = copy_to_user(buffer, (char *)start, tsz);
49021- /*
49022- * We cannot distinguish between fault on source
49023- * and fault on destination. When this happens
49024- * we clear too and hope it will trigger the
49025- * EFAULT again.
49026- */
49027- if (n) {
49028- if (clear_user(buffer + tsz - n,
49029- n))
49030+ elf_buf = kmalloc(tsz, GFP_KERNEL);
49031+ if (!elf_buf)
49032+ return -ENOMEM;
49033+ oldfs = get_fs();
49034+ set_fs(KERNEL_DS);
49035+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
49036+ set_fs(oldfs);
49037+ if (copy_to_user(buffer, elf_buf, tsz)) {
49038+ kfree(elf_buf);
49039 return -EFAULT;
49040+ }
49041 }
49042+ set_fs(oldfs);
49043+ kfree(elf_buf);
49044 } else {
49045 if (clear_user(buffer, tsz))
49046 return -EFAULT;
49047@@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49048
49049 static int open_kcore(struct inode *inode, struct file *filp)
49050 {
49051+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
49052+ return -EPERM;
49053+#endif
49054 if (!capable(CAP_SYS_RAWIO))
49055 return -EPERM;
49056 if (kcore_need_update)
49057diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
49058index 80e4645..53e5fcf 100644
49059--- a/fs/proc/meminfo.c
49060+++ b/fs/proc/meminfo.c
49061@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
49062 vmi.used >> 10,
49063 vmi.largest_chunk >> 10
49064 #ifdef CONFIG_MEMORY_FAILURE
49065- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
49066+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
49067 #endif
49068 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
49069 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
49070diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
49071index b1822dd..df622cb 100644
49072--- a/fs/proc/nommu.c
49073+++ b/fs/proc/nommu.c
49074@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
49075 if (len < 1)
49076 len = 1;
49077 seq_printf(m, "%*c", len, ' ');
49078- seq_path(m, &file->f_path, "");
49079+ seq_path(m, &file->f_path, "\n\\");
49080 }
49081
49082 seq_putc(m, '\n');
49083diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
49084index 06e1cc1..177cd98 100644
49085--- a/fs/proc/proc_net.c
49086+++ b/fs/proc/proc_net.c
49087@@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
49088 struct task_struct *task;
49089 struct nsproxy *ns;
49090 struct net *net = NULL;
49091+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49092+ const struct cred *cred = current_cred();
49093+#endif
49094+
49095+#ifdef CONFIG_GRKERNSEC_PROC_USER
49096+ if (cred->fsuid)
49097+ return net;
49098+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49099+ if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
49100+ return net;
49101+#endif
49102
49103 rcu_read_lock();
49104 task = pid_task(proc_pid(dir), PIDTYPE_PID);
49105diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
49106index 3476bca..cb6d86a 100644
49107--- a/fs/proc/proc_sysctl.c
49108+++ b/fs/proc/proc_sysctl.c
49109@@ -12,11 +12,15 @@
49110 #include <linux/module.h>
49111 #include "internal.h"
49112
49113+extern int gr_handle_chroot_sysctl(const int op);
49114+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
49115+ const int op);
49116+
49117 static const struct dentry_operations proc_sys_dentry_operations;
49118 static const struct file_operations proc_sys_file_operations;
49119-static const struct inode_operations proc_sys_inode_operations;
49120+const struct inode_operations proc_sys_inode_operations;
49121 static const struct file_operations proc_sys_dir_file_operations;
49122-static const struct inode_operations proc_sys_dir_operations;
49123+const struct inode_operations proc_sys_dir_operations;
49124
49125 void proc_sys_poll_notify(struct ctl_table_poll *poll)
49126 {
49127@@ -470,8 +474,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
49128
49129 err = NULL;
49130 d_set_d_op(dentry, &proc_sys_dentry_operations);
49131+
49132+ gr_handle_proc_create(dentry, inode);
49133+
49134 d_add(dentry, inode);
49135
49136+ if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt))
49137+ err = ERR_PTR(-ENOENT);
49138+
49139 out:
49140 sysctl_head_finish(head);
49141 return err;
49142@@ -483,18 +493,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49143 struct inode *inode = filp->f_path.dentry->d_inode;
49144 struct ctl_table_header *head = grab_header(inode);
49145 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
49146+ int op = write ? MAY_WRITE : MAY_READ;
49147 ssize_t error;
49148 size_t res;
49149
49150 if (IS_ERR(head))
49151 return PTR_ERR(head);
49152
49153+
49154 /*
49155 * At this point we know that the sysctl was not unregistered
49156 * and won't be until we finish.
49157 */
49158 error = -EPERM;
49159- if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
49160+ if (sysctl_perm(head->root, table, op))
49161 goto out;
49162
49163 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
49164@@ -502,6 +514,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49165 if (!table->proc_handler)
49166 goto out;
49167
49168+#ifdef CONFIG_GRKERNSEC
49169+ error = -EPERM;
49170+ if (gr_handle_chroot_sysctl(op))
49171+ goto out;
49172+ dget(filp->f_path.dentry);
49173+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
49174+ dput(filp->f_path.dentry);
49175+ goto out;
49176+ }
49177+ dput(filp->f_path.dentry);
49178+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
49179+ goto out;
49180+ if (write && !capable(CAP_SYS_ADMIN))
49181+ goto out;
49182+#endif
49183+
49184 /* careful: calling conventions are nasty here */
49185 res = count;
49186 error = table->proc_handler(table, write, buf, &res, ppos);
49187@@ -599,6 +627,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
49188 return -ENOMEM;
49189 } else {
49190 d_set_d_op(child, &proc_sys_dentry_operations);
49191+
49192+ gr_handle_proc_create(child, inode);
49193+
49194 d_add(child, inode);
49195 }
49196 } else {
49197@@ -642,6 +673,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
49198 if ((*pos)++ < file->f_pos)
49199 return 0;
49200
49201+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
49202+ return 0;
49203+
49204 if (unlikely(S_ISLNK(table->mode)))
49205 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
49206 else
49207@@ -759,6 +793,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
49208 if (IS_ERR(head))
49209 return PTR_ERR(head);
49210
49211+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
49212+ return -ENOENT;
49213+
49214 generic_fillattr(inode, stat);
49215 if (table)
49216 stat->mode = (stat->mode & S_IFMT) | table->mode;
49217@@ -781,13 +818,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
49218 .llseek = generic_file_llseek,
49219 };
49220
49221-static const struct inode_operations proc_sys_inode_operations = {
49222+const struct inode_operations proc_sys_inode_operations = {
49223 .permission = proc_sys_permission,
49224 .setattr = proc_sys_setattr,
49225 .getattr = proc_sys_getattr,
49226 };
49227
49228-static const struct inode_operations proc_sys_dir_operations = {
49229+const struct inode_operations proc_sys_dir_operations = {
49230 .lookup = proc_sys_lookup,
49231 .permission = proc_sys_permission,
49232 .setattr = proc_sys_setattr,
49233diff --git a/fs/proc/root.c b/fs/proc/root.c
49234index 7c30fce..b3d3aa2 100644
49235--- a/fs/proc/root.c
49236+++ b/fs/proc/root.c
49237@@ -188,7 +188,15 @@ void __init proc_root_init(void)
49238 #ifdef CONFIG_PROC_DEVICETREE
49239 proc_device_tree_init();
49240 #endif
49241+#ifdef CONFIG_GRKERNSEC_PROC_ADD
49242+#ifdef CONFIG_GRKERNSEC_PROC_USER
49243+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
49244+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49245+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
49246+#endif
49247+#else
49248 proc_mkdir("bus", NULL);
49249+#endif
49250 proc_sys_init();
49251 }
49252
49253diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
49254index 4540b8f..1b9772f 100644
49255--- a/fs/proc/task_mmu.c
49256+++ b/fs/proc/task_mmu.c
49257@@ -11,12 +11,19 @@
49258 #include <linux/rmap.h>
49259 #include <linux/swap.h>
49260 #include <linux/swapops.h>
49261+#include <linux/grsecurity.h>
49262
49263 #include <asm/elf.h>
49264 #include <asm/uaccess.h>
49265 #include <asm/tlbflush.h>
49266 #include "internal.h"
49267
49268+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49269+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49270+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
49271+ _mm->pax_flags & MF_PAX_SEGMEXEC))
49272+#endif
49273+
49274 void task_mem(struct seq_file *m, struct mm_struct *mm)
49275 {
49276 unsigned long data, text, lib, swap;
49277@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49278 "VmExe:\t%8lu kB\n"
49279 "VmLib:\t%8lu kB\n"
49280 "VmPTE:\t%8lu kB\n"
49281- "VmSwap:\t%8lu kB\n",
49282- hiwater_vm << (PAGE_SHIFT-10),
49283+ "VmSwap:\t%8lu kB\n"
49284+
49285+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49286+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
49287+#endif
49288+
49289+ ,hiwater_vm << (PAGE_SHIFT-10),
49290 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
49291 mm->locked_vm << (PAGE_SHIFT-10),
49292 mm->pinned_vm << (PAGE_SHIFT-10),
49293@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49294 data << (PAGE_SHIFT-10),
49295 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
49296 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
49297- swap << (PAGE_SHIFT-10));
49298+ swap << (PAGE_SHIFT-10)
49299+
49300+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49301+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49302+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
49303+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
49304+#else
49305+ , mm->context.user_cs_base
49306+ , mm->context.user_cs_limit
49307+#endif
49308+#endif
49309+
49310+ );
49311 }
49312
49313 unsigned long task_vsize(struct mm_struct *mm)
49314@@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49315 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
49316 }
49317
49318- /* We don't show the stack guard page in /proc/maps */
49319+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49320+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
49321+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
49322+#else
49323 start = vma->vm_start;
49324- if (stack_guard_page_start(vma, start))
49325- start += PAGE_SIZE;
49326 end = vma->vm_end;
49327- if (stack_guard_page_end(vma, end))
49328- end -= PAGE_SIZE;
49329+#endif
49330
49331 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
49332 start,
49333@@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49334 flags & VM_WRITE ? 'w' : '-',
49335 flags & VM_EXEC ? 'x' : '-',
49336 flags & VM_MAYSHARE ? 's' : 'p',
49337+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49338+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
49339+#else
49340 pgoff,
49341+#endif
49342 MAJOR(dev), MINOR(dev), ino, &len);
49343
49344 /*
49345@@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49346 */
49347 if (file) {
49348 pad_len_spaces(m, len);
49349- seq_path(m, &file->f_path, "\n");
49350+ seq_path(m, &file->f_path, "\n\\");
49351 goto done;
49352 }
49353
49354@@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49355 * Thread stack in /proc/PID/task/TID/maps or
49356 * the main process stack.
49357 */
49358- if (!is_pid || (vma->vm_start <= mm->start_stack &&
49359- vma->vm_end >= mm->start_stack)) {
49360+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
49361+ (vma->vm_start <= mm->start_stack &&
49362+ vma->vm_end >= mm->start_stack)) {
49363 name = "[stack]";
49364 } else {
49365 /* Thread stack in /proc/PID/maps */
49366@@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
49367 struct proc_maps_private *priv = m->private;
49368 struct task_struct *task = priv->task;
49369
49370+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49371+ if (current->exec_id != m->exec_id) {
49372+ gr_log_badprocpid("maps");
49373+ return 0;
49374+ }
49375+#endif
49376+
49377 show_map_vma(m, vma, is_pid);
49378
49379 if (m->count < m->size) /* vma is copied successfully */
49380@@ -492,12 +528,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49381 .private = &mss,
49382 };
49383
49384+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49385+ if (current->exec_id != m->exec_id) {
49386+ gr_log_badprocpid("smaps");
49387+ return 0;
49388+ }
49389+#endif
49390 memset(&mss, 0, sizeof mss);
49391- mss.vma = vma;
49392- /* mmap_sem is held in m_start */
49393- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49394- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49395-
49396+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49397+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
49398+#endif
49399+ mss.vma = vma;
49400+ /* mmap_sem is held in m_start */
49401+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49402+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49403+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49404+ }
49405+#endif
49406 show_map_vma(m, vma, is_pid);
49407
49408 seq_printf(m,
49409@@ -515,7 +562,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49410 "KernelPageSize: %8lu kB\n"
49411 "MMUPageSize: %8lu kB\n"
49412 "Locked: %8lu kB\n",
49413+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49414+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
49415+#else
49416 (vma->vm_end - vma->vm_start) >> 10,
49417+#endif
49418 mss.resident >> 10,
49419 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
49420 mss.shared_clean >> 10,
49421@@ -1164,6 +1215,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49422 int n;
49423 char buffer[50];
49424
49425+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49426+ if (current->exec_id != m->exec_id) {
49427+ gr_log_badprocpid("numa_maps");
49428+ return 0;
49429+ }
49430+#endif
49431+
49432 if (!mm)
49433 return 0;
49434
49435@@ -1181,11 +1239,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49436 mpol_to_str(buffer, sizeof(buffer), pol, 0);
49437 mpol_cond_put(pol);
49438
49439+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49440+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
49441+#else
49442 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
49443+#endif
49444
49445 if (file) {
49446 seq_printf(m, " file=");
49447- seq_path(m, &file->f_path, "\n\t= ");
49448+ seq_path(m, &file->f_path, "\n\t\\= ");
49449 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
49450 seq_printf(m, " heap");
49451 } else {
49452diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
49453index 1ccfa53..0848f95 100644
49454--- a/fs/proc/task_nommu.c
49455+++ b/fs/proc/task_nommu.c
49456@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49457 else
49458 bytes += kobjsize(mm);
49459
49460- if (current->fs && current->fs->users > 1)
49461+ if (current->fs && atomic_read(&current->fs->users) > 1)
49462 sbytes += kobjsize(current->fs);
49463 else
49464 bytes += kobjsize(current->fs);
49465@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
49466
49467 if (file) {
49468 pad_len_spaces(m, len);
49469- seq_path(m, &file->f_path, "");
49470+ seq_path(m, &file->f_path, "\n\\");
49471 } else if (mm) {
49472 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
49473
49474diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
49475index d67908b..d13f6a6 100644
49476--- a/fs/quota/netlink.c
49477+++ b/fs/quota/netlink.c
49478@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
49479 void quota_send_warning(short type, unsigned int id, dev_t dev,
49480 const char warntype)
49481 {
49482- static atomic_t seq;
49483+ static atomic_unchecked_t seq;
49484 struct sk_buff *skb;
49485 void *msg_head;
49486 int ret;
49487@@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
49488 "VFS: Not enough memory to send quota warning.\n");
49489 return;
49490 }
49491- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
49492+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
49493 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
49494 if (!msg_head) {
49495 printk(KERN_ERR
49496diff --git a/fs/readdir.c b/fs/readdir.c
49497index 39e3370..20d446d 100644
49498--- a/fs/readdir.c
49499+++ b/fs/readdir.c
49500@@ -17,6 +17,7 @@
49501 #include <linux/security.h>
49502 #include <linux/syscalls.h>
49503 #include <linux/unistd.h>
49504+#include <linux/namei.h>
49505
49506 #include <asm/uaccess.h>
49507
49508@@ -67,6 +68,7 @@ struct old_linux_dirent {
49509
49510 struct readdir_callback {
49511 struct old_linux_dirent __user * dirent;
49512+ struct file * file;
49513 int result;
49514 };
49515
49516@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
49517 buf->result = -EOVERFLOW;
49518 return -EOVERFLOW;
49519 }
49520+
49521+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49522+ return 0;
49523+
49524 buf->result++;
49525 dirent = buf->dirent;
49526 if (!access_ok(VERIFY_WRITE, dirent,
49527@@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
49528
49529 buf.result = 0;
49530 buf.dirent = dirent;
49531+ buf.file = file;
49532
49533 error = vfs_readdir(file, fillonedir, &buf);
49534 if (buf.result)
49535@@ -141,6 +148,7 @@ struct linux_dirent {
49536 struct getdents_callback {
49537 struct linux_dirent __user * current_dir;
49538 struct linux_dirent __user * previous;
49539+ struct file * file;
49540 int count;
49541 int error;
49542 };
49543@@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
49544 buf->error = -EOVERFLOW;
49545 return -EOVERFLOW;
49546 }
49547+
49548+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49549+ return 0;
49550+
49551 dirent = buf->previous;
49552 if (dirent) {
49553 if (__put_user(offset, &dirent->d_off))
49554@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49555 buf.previous = NULL;
49556 buf.count = count;
49557 buf.error = 0;
49558+ buf.file = file;
49559
49560 error = vfs_readdir(file, filldir, &buf);
49561 if (error >= 0)
49562@@ -226,6 +239,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49563 struct getdents_callback64 {
49564 struct linux_dirent64 __user * current_dir;
49565 struct linux_dirent64 __user * previous;
49566+ struct file *file;
49567 int count;
49568 int error;
49569 };
49570@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
49571 buf->error = -EINVAL; /* only used if we fail.. */
49572 if (reclen > buf->count)
49573 return -EINVAL;
49574+
49575+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49576+ return 0;
49577+
49578 dirent = buf->previous;
49579 if (dirent) {
49580 if (__put_user(offset, &dirent->d_off))
49581@@ -287,6 +305,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49582
49583 buf.current_dir = dirent;
49584 buf.previous = NULL;
49585+ buf.file = file;
49586 buf.count = count;
49587 buf.error = 0;
49588
49589@@ -295,7 +314,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49590 error = buf.error;
49591 lastdirent = buf.previous;
49592 if (lastdirent) {
49593- typeof(lastdirent->d_off) d_off = file->f_pos;
49594+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
49595 if (__put_user(d_off, &lastdirent->d_off))
49596 error = -EFAULT;
49597 else
49598diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
49599index 2b7882b..1c5ef48 100644
49600--- a/fs/reiserfs/do_balan.c
49601+++ b/fs/reiserfs/do_balan.c
49602@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
49603 return;
49604 }
49605
49606- atomic_inc(&(fs_generation(tb->tb_sb)));
49607+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
49608 do_balance_starts(tb);
49609
49610 /* balance leaf returns 0 except if combining L R and S into
49611diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
49612index 2c1ade6..8c59d8d 100644
49613--- a/fs/reiserfs/procfs.c
49614+++ b/fs/reiserfs/procfs.c
49615@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
49616 "SMALL_TAILS " : "NO_TAILS ",
49617 replay_only(sb) ? "REPLAY_ONLY " : "",
49618 convert_reiserfs(sb) ? "CONV " : "",
49619- atomic_read(&r->s_generation_counter),
49620+ atomic_read_unchecked(&r->s_generation_counter),
49621 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
49622 SF(s_do_balance), SF(s_unneeded_left_neighbor),
49623 SF(s_good_search_by_key_reada), SF(s_bmaps),
49624diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
49625index 33215f5..c5d427a 100644
49626--- a/fs/reiserfs/reiserfs.h
49627+++ b/fs/reiserfs/reiserfs.h
49628@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
49629 /* Comment? -Hans */
49630 wait_queue_head_t s_wait;
49631 /* To be obsoleted soon by per buffer seals.. -Hans */
49632- atomic_t s_generation_counter; // increased by one every time the
49633+ atomic_unchecked_t s_generation_counter; // increased by one every time the
49634 // tree gets re-balanced
49635 unsigned long s_properties; /* File system properties. Currently holds
49636 on-disk FS format */
49637@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
49638 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
49639
49640 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
49641-#define get_generation(s) atomic_read (&fs_generation(s))
49642+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
49643 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
49644 #define __fs_changed(gen,s) (gen != get_generation (s))
49645 #define fs_changed(gen,s) \
49646diff --git a/fs/select.c b/fs/select.c
49647index db14c78..3aae1bd 100644
49648--- a/fs/select.c
49649+++ b/fs/select.c
49650@@ -20,6 +20,7 @@
49651 #include <linux/export.h>
49652 #include <linux/slab.h>
49653 #include <linux/poll.h>
49654+#include <linux/security.h>
49655 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
49656 #include <linux/file.h>
49657 #include <linux/fdtable.h>
49658@@ -831,6 +832,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
49659 struct poll_list *walk = head;
49660 unsigned long todo = nfds;
49661
49662+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
49663 if (nfds > rlimit(RLIMIT_NOFILE))
49664 return -EINVAL;
49665
49666diff --git a/fs/seq_file.c b/fs/seq_file.c
49667index 0cbd049..64e705c 100644
49668--- a/fs/seq_file.c
49669+++ b/fs/seq_file.c
49670@@ -9,6 +9,7 @@
49671 #include <linux/export.h>
49672 #include <linux/seq_file.h>
49673 #include <linux/slab.h>
49674+#include <linux/sched.h>
49675
49676 #include <asm/uaccess.h>
49677 #include <asm/page.h>
49678@@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
49679 memset(p, 0, sizeof(*p));
49680 mutex_init(&p->lock);
49681 p->op = op;
49682+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49683+ p->exec_id = current->exec_id;
49684+#endif
49685
49686 /*
49687 * Wrappers around seq_open(e.g. swaps_open) need to be
49688@@ -92,7 +96,7 @@ static int traverse(struct seq_file *m, loff_t offset)
49689 return 0;
49690 }
49691 if (!m->buf) {
49692- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
49693+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
49694 if (!m->buf)
49695 return -ENOMEM;
49696 }
49697@@ -132,7 +136,7 @@ static int traverse(struct seq_file *m, loff_t offset)
49698 Eoverflow:
49699 m->op->stop(m, p);
49700 kfree(m->buf);
49701- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
49702+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
49703 return !m->buf ? -ENOMEM : -EAGAIN;
49704 }
49705
49706@@ -187,7 +191,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
49707
49708 /* grab buffer if we didn't have one */
49709 if (!m->buf) {
49710- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
49711+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
49712 if (!m->buf)
49713 goto Enomem;
49714 }
49715@@ -228,7 +232,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
49716 goto Fill;
49717 m->op->stop(m, p);
49718 kfree(m->buf);
49719- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
49720+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
49721 if (!m->buf)
49722 goto Enomem;
49723 m->count = 0;
49724@@ -567,7 +571,7 @@ static void single_stop(struct seq_file *p, void *v)
49725 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
49726 void *data)
49727 {
49728- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
49729+ seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
49730 int res = -ENOMEM;
49731
49732 if (op) {
49733diff --git a/fs/splice.c b/fs/splice.c
49734index 7bf08fa..eb35c2f 100644
49735--- a/fs/splice.c
49736+++ b/fs/splice.c
49737@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49738 pipe_lock(pipe);
49739
49740 for (;;) {
49741- if (!pipe->readers) {
49742+ if (!atomic_read(&pipe->readers)) {
49743 send_sig(SIGPIPE, current, 0);
49744 if (!ret)
49745 ret = -EPIPE;
49746@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49747 do_wakeup = 0;
49748 }
49749
49750- pipe->waiting_writers++;
49751+ atomic_inc(&pipe->waiting_writers);
49752 pipe_wait(pipe);
49753- pipe->waiting_writers--;
49754+ atomic_dec(&pipe->waiting_writers);
49755 }
49756
49757 pipe_unlock(pipe);
49758@@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
49759 old_fs = get_fs();
49760 set_fs(get_ds());
49761 /* The cast to a user pointer is valid due to the set_fs() */
49762- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
49763+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
49764 set_fs(old_fs);
49765
49766 return res;
49767@@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
49768 old_fs = get_fs();
49769 set_fs(get_ds());
49770 /* The cast to a user pointer is valid due to the set_fs() */
49771- res = vfs_write(file, (const char __user *)buf, count, &pos);
49772+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
49773 set_fs(old_fs);
49774
49775 return res;
49776@@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
49777 goto err;
49778
49779 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
49780- vec[i].iov_base = (void __user *) page_address(page);
49781+ vec[i].iov_base = (void __force_user *) page_address(page);
49782 vec[i].iov_len = this_len;
49783 spd.pages[i] = page;
49784 spd.nr_pages++;
49785@@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
49786 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
49787 {
49788 while (!pipe->nrbufs) {
49789- if (!pipe->writers)
49790+ if (!atomic_read(&pipe->writers))
49791 return 0;
49792
49793- if (!pipe->waiting_writers && sd->num_spliced)
49794+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
49795 return 0;
49796
49797 if (sd->flags & SPLICE_F_NONBLOCK)
49798@@ -1187,7 +1187,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
49799 * out of the pipe right after the splice_to_pipe(). So set
49800 * PIPE_READERS appropriately.
49801 */
49802- pipe->readers = 1;
49803+ atomic_set(&pipe->readers, 1);
49804
49805 current->splice_pipe = pipe;
49806 }
49807@@ -1740,9 +1740,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49808 ret = -ERESTARTSYS;
49809 break;
49810 }
49811- if (!pipe->writers)
49812+ if (!atomic_read(&pipe->writers))
49813 break;
49814- if (!pipe->waiting_writers) {
49815+ if (!atomic_read(&pipe->waiting_writers)) {
49816 if (flags & SPLICE_F_NONBLOCK) {
49817 ret = -EAGAIN;
49818 break;
49819@@ -1774,7 +1774,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49820 pipe_lock(pipe);
49821
49822 while (pipe->nrbufs >= pipe->buffers) {
49823- if (!pipe->readers) {
49824+ if (!atomic_read(&pipe->readers)) {
49825 send_sig(SIGPIPE, current, 0);
49826 ret = -EPIPE;
49827 break;
49828@@ -1787,9 +1787,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49829 ret = -ERESTARTSYS;
49830 break;
49831 }
49832- pipe->waiting_writers++;
49833+ atomic_inc(&pipe->waiting_writers);
49834 pipe_wait(pipe);
49835- pipe->waiting_writers--;
49836+ atomic_dec(&pipe->waiting_writers);
49837 }
49838
49839 pipe_unlock(pipe);
49840@@ -1825,14 +1825,14 @@ retry:
49841 pipe_double_lock(ipipe, opipe);
49842
49843 do {
49844- if (!opipe->readers) {
49845+ if (!atomic_read(&opipe->readers)) {
49846 send_sig(SIGPIPE, current, 0);
49847 if (!ret)
49848 ret = -EPIPE;
49849 break;
49850 }
49851
49852- if (!ipipe->nrbufs && !ipipe->writers)
49853+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
49854 break;
49855
49856 /*
49857@@ -1929,7 +1929,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49858 pipe_double_lock(ipipe, opipe);
49859
49860 do {
49861- if (!opipe->readers) {
49862+ if (!atomic_read(&opipe->readers)) {
49863 send_sig(SIGPIPE, current, 0);
49864 if (!ret)
49865 ret = -EPIPE;
49866@@ -1974,7 +1974,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49867 * return EAGAIN if we have the potential of some data in the
49868 * future, otherwise just return 0
49869 */
49870- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
49871+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
49872 ret = -EAGAIN;
49873
49874 pipe_unlock(ipipe);
49875diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
49876index e6bb9b2..d8e3951 100644
49877--- a/fs/sysfs/dir.c
49878+++ b/fs/sysfs/dir.c
49879@@ -678,6 +678,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
49880 struct sysfs_dirent *sd;
49881 int rc;
49882
49883+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
49884+ const char *parent_name = parent_sd->s_name;
49885+
49886+ mode = S_IFDIR | S_IRWXU;
49887+
49888+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
49889+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
49890+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
49891+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
49892+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
49893+#endif
49894+
49895 /* allocate */
49896 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
49897 if (!sd)
49898diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
49899index 00012e3..8392349 100644
49900--- a/fs/sysfs/file.c
49901+++ b/fs/sysfs/file.c
49902@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
49903
49904 struct sysfs_open_dirent {
49905 atomic_t refcnt;
49906- atomic_t event;
49907+ atomic_unchecked_t event;
49908 wait_queue_head_t poll;
49909 struct list_head buffers; /* goes through sysfs_buffer.list */
49910 };
49911@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
49912 if (!sysfs_get_active(attr_sd))
49913 return -ENODEV;
49914
49915- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
49916+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
49917 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
49918
49919 sysfs_put_active(attr_sd);
49920@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
49921 return -ENOMEM;
49922
49923 atomic_set(&new_od->refcnt, 0);
49924- atomic_set(&new_od->event, 1);
49925+ atomic_set_unchecked(&new_od->event, 1);
49926 init_waitqueue_head(&new_od->poll);
49927 INIT_LIST_HEAD(&new_od->buffers);
49928 goto retry;
49929@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
49930
49931 sysfs_put_active(attr_sd);
49932
49933- if (buffer->event != atomic_read(&od->event))
49934+ if (buffer->event != atomic_read_unchecked(&od->event))
49935 goto trigger;
49936
49937 return DEFAULT_POLLMASK;
49938@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
49939
49940 od = sd->s_attr.open;
49941 if (od) {
49942- atomic_inc(&od->event);
49943+ atomic_inc_unchecked(&od->event);
49944 wake_up_interruptible(&od->poll);
49945 }
49946
49947diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
49948index a7ac78f..02158e1 100644
49949--- a/fs/sysfs/symlink.c
49950+++ b/fs/sysfs/symlink.c
49951@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
49952
49953 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
49954 {
49955- char *page = nd_get_link(nd);
49956+ const char *page = nd_get_link(nd);
49957 if (!IS_ERR(page))
49958 free_page((unsigned long)page);
49959 }
49960diff --git a/fs/udf/misc.c b/fs/udf/misc.c
49961index c175b4d..8f36a16 100644
49962--- a/fs/udf/misc.c
49963+++ b/fs/udf/misc.c
49964@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
49965
49966 u8 udf_tag_checksum(const struct tag *t)
49967 {
49968- u8 *data = (u8 *)t;
49969+ const u8 *data = (const u8 *)t;
49970 u8 checksum = 0;
49971 int i;
49972 for (i = 0; i < sizeof(struct tag); ++i)
49973diff --git a/fs/udf/namei.c b/fs/udf/namei.c
49974index 1802417..c31deb3 100644
49975--- a/fs/udf/namei.c
49976+++ b/fs/udf/namei.c
49977@@ -1279,6 +1279,7 @@ static int udf_encode_fh(struct inode *inode, __u32 *fh, int *lenp,
49978 *lenp = 3;
49979 fid->udf.block = location.logicalBlockNum;
49980 fid->udf.partref = location.partitionReferenceNum;
49981+ fid->udf.parent_partref = 0;
49982 fid->udf.generation = inode->i_generation;
49983
49984 if (parent) {
49985diff --git a/fs/utimes.c b/fs/utimes.c
49986index fa4dbe4..e12d1b9 100644
49987--- a/fs/utimes.c
49988+++ b/fs/utimes.c
49989@@ -1,6 +1,7 @@
49990 #include <linux/compiler.h>
49991 #include <linux/file.h>
49992 #include <linux/fs.h>
49993+#include <linux/security.h>
49994 #include <linux/linkage.h>
49995 #include <linux/mount.h>
49996 #include <linux/namei.h>
49997@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
49998 goto mnt_drop_write_and_out;
49999 }
50000 }
50001+
50002+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
50003+ error = -EACCES;
50004+ goto mnt_drop_write_and_out;
50005+ }
50006+
50007 mutex_lock(&inode->i_mutex);
50008 error = notify_change(path->dentry, &newattrs);
50009 mutex_unlock(&inode->i_mutex);
50010diff --git a/fs/xattr.c b/fs/xattr.c
50011index 1d7ac37..23cb9ec 100644
50012--- a/fs/xattr.c
50013+++ b/fs/xattr.c
50014@@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
50015 * Extended attribute SET operations
50016 */
50017 static long
50018-setxattr(struct dentry *d, const char __user *name, const void __user *value,
50019+setxattr(struct path *path, const char __user *name, const void __user *value,
50020 size_t size, int flags)
50021 {
50022 int error;
50023@@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
50024 }
50025 }
50026
50027- error = vfs_setxattr(d, kname, kvalue, size, flags);
50028+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
50029+ error = -EACCES;
50030+ goto out;
50031+ }
50032+
50033+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
50034 out:
50035 if (vvalue)
50036 vfree(vvalue);
50037@@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
50038 return error;
50039 error = mnt_want_write(path.mnt);
50040 if (!error) {
50041- error = setxattr(path.dentry, name, value, size, flags);
50042+ error = setxattr(&path, name, value, size, flags);
50043 mnt_drop_write(path.mnt);
50044 }
50045 path_put(&path);
50046@@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
50047 return error;
50048 error = mnt_want_write(path.mnt);
50049 if (!error) {
50050- error = setxattr(path.dentry, name, value, size, flags);
50051+ error = setxattr(&path, name, value, size, flags);
50052 mnt_drop_write(path.mnt);
50053 }
50054 path_put(&path);
50055@@ -401,17 +406,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
50056 {
50057 int fput_needed;
50058 struct file *f;
50059- struct dentry *dentry;
50060 int error = -EBADF;
50061
50062 f = fget_light(fd, &fput_needed);
50063 if (!f)
50064 return error;
50065- dentry = f->f_path.dentry;
50066- audit_inode(NULL, dentry);
50067+ audit_inode(NULL, f->f_path.dentry);
50068 error = mnt_want_write_file(f);
50069 if (!error) {
50070- error = setxattr(dentry, name, value, size, flags);
50071+ error = setxattr(&f->f_path, name, value, size, flags);
50072 mnt_drop_write_file(f);
50073 }
50074 fput_light(f, fput_needed);
50075diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
50076index 69d06b0..c0996e5 100644
50077--- a/fs/xattr_acl.c
50078+++ b/fs/xattr_acl.c
50079@@ -17,8 +17,8 @@
50080 struct posix_acl *
50081 posix_acl_from_xattr(const void *value, size_t size)
50082 {
50083- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
50084- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
50085+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
50086+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
50087 int count;
50088 struct posix_acl *acl;
50089 struct posix_acl_entry *acl_e;
50090diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
50091index 58b815e..595ddee 100644
50092--- a/fs/xfs/xfs_bmap.c
50093+++ b/fs/xfs/xfs_bmap.c
50094@@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
50095 int nmap,
50096 int ret_nmap);
50097 #else
50098-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
50099+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
50100 #endif /* DEBUG */
50101
50102 STATIC int
50103diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
50104index 19bf0c5..9f26b02 100644
50105--- a/fs/xfs/xfs_dir2_sf.c
50106+++ b/fs/xfs/xfs_dir2_sf.c
50107@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
50108 }
50109
50110 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
50111- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50112+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
50113+ char name[sfep->namelen];
50114+ memcpy(name, sfep->name, sfep->namelen);
50115+ if (filldir(dirent, name, sfep->namelen,
50116+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
50117+ *offset = off & 0x7fffffff;
50118+ return 0;
50119+ }
50120+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50121 off & 0x7fffffff, ino, DT_UNKNOWN)) {
50122 *offset = off & 0x7fffffff;
50123 return 0;
50124diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
50125index 3a05a41..320bec6 100644
50126--- a/fs/xfs/xfs_ioctl.c
50127+++ b/fs/xfs/xfs_ioctl.c
50128@@ -126,7 +126,7 @@ xfs_find_handle(
50129 }
50130
50131 error = -EFAULT;
50132- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
50133+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
50134 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
50135 goto out_put;
50136
50137diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
50138index 1a25fd8..e935581 100644
50139--- a/fs/xfs/xfs_iops.c
50140+++ b/fs/xfs/xfs_iops.c
50141@@ -394,7 +394,7 @@ xfs_vn_put_link(
50142 struct nameidata *nd,
50143 void *p)
50144 {
50145- char *s = nd_get_link(nd);
50146+ const char *s = nd_get_link(nd);
50147
50148 if (!IS_ERR(s))
50149 kfree(s);
50150diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
50151new file mode 100644
50152index 0000000..4d533f1
50153--- /dev/null
50154+++ b/grsecurity/Kconfig
50155@@ -0,0 +1,941 @@
50156+#
50157+# grecurity configuration
50158+#
50159+menu "Memory Protections"
50160+depends on GRKERNSEC
50161+
50162+config GRKERNSEC_KMEM
50163+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
50164+ default y if GRKERNSEC_CONFIG_AUTO
50165+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
50166+ help
50167+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
50168+ be written to or read from to modify or leak the contents of the running
50169+ kernel. /dev/port will also not be allowed to be opened. If you have module
50170+ support disabled, enabling this will close up four ways that are
50171+ currently used to insert malicious code into the running kernel.
50172+ Even with all these features enabled, we still highly recommend that
50173+ you use the RBAC system, as it is still possible for an attacker to
50174+ modify the running kernel through privileged I/O granted by ioperm/iopl.
50175+ If you are not using XFree86, you may be able to stop this additional
50176+ case by enabling the 'Disable privileged I/O' option. Though nothing
50177+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
50178+ but only to video memory, which is the only writing we allow in this
50179+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
50180+ not be allowed to mprotect it with PROT_WRITE later.
50181+ It is highly recommended that you say Y here if you meet all the
50182+ conditions above.
50183+
50184+config GRKERNSEC_VM86
50185+ bool "Restrict VM86 mode"
50186+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50187+ depends on X86_32
50188+
50189+ help
50190+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
50191+ make use of a special execution mode on 32bit x86 processors called
50192+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
50193+ video cards and will still work with this option enabled. The purpose
50194+ of the option is to prevent exploitation of emulation errors in
50195+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
50196+ Nearly all users should be able to enable this option.
50197+
50198+config GRKERNSEC_IO
50199+ bool "Disable privileged I/O"
50200+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50201+ depends on X86
50202+ select RTC_CLASS
50203+ select RTC_INTF_DEV
50204+ select RTC_DRV_CMOS
50205+
50206+ help
50207+ If you say Y here, all ioperm and iopl calls will return an error.
50208+ Ioperm and iopl can be used to modify the running kernel.
50209+ Unfortunately, some programs need this access to operate properly,
50210+ the most notable of which are XFree86 and hwclock. hwclock can be
50211+ remedied by having RTC support in the kernel, so real-time
50212+ clock support is enabled if this option is enabled, to ensure
50213+ that hwclock operates correctly. XFree86 still will not
50214+ operate correctly with this option enabled, so DO NOT CHOOSE Y
50215+ IF YOU USE XFree86. If you use XFree86 and you still want to
50216+ protect your kernel against modification, use the RBAC system.
50217+
50218+config GRKERNSEC_PROC_MEMMAP
50219+ bool "Harden ASLR against information leaks and entropy reduction"
50220+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
50221+ depends on PAX_NOEXEC || PAX_ASLR
50222+ help
50223+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
50224+ give no information about the addresses of its mappings if
50225+ PaX features that rely on random addresses are enabled on the task.
50226+ In addition to sanitizing this information and disabling other
50227+ dangerous sources of information, this option causes reads of sensitive
50228+ /proc/<pid> entries where the file descriptor was opened in a different
50229+ task than the one performing the read. Such attempts are logged.
50230+ This option also limits argv/env strings for suid/sgid binaries
50231+ to 512KB to prevent a complete exhaustion of the stack entropy provided
50232+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
50233+ binaries to prevent alternative mmap layouts from being abused.
50234+
50235+ If you use PaX it is essential that you say Y here as it closes up
50236+ several holes that make full ASLR useless locally.
50237+
50238+config GRKERNSEC_BRUTE
50239+ bool "Deter exploit bruteforcing"
50240+ default y if GRKERNSEC_CONFIG_AUTO
50241+ help
50242+ If you say Y here, attempts to bruteforce exploits against forking
50243+ daemons such as apache or sshd, as well as against suid/sgid binaries
50244+ will be deterred. When a child of a forking daemon is killed by PaX
50245+ or crashes due to an illegal instruction or other suspicious signal,
50246+ the parent process will be delayed 30 seconds upon every subsequent
50247+ fork until the administrator is able to assess the situation and
50248+ restart the daemon.
50249+ In the suid/sgid case, the attempt is logged, the user has all their
50250+ processes terminated, and they are prevented from executing any further
50251+ processes for 15 minutes.
50252+ It is recommended that you also enable signal logging in the auditing
50253+ section so that logs are generated when a process triggers a suspicious
50254+ signal.
50255+ If the sysctl option is enabled, a sysctl option with name
50256+ "deter_bruteforce" is created.
50257+
50258+
50259+config GRKERNSEC_MODHARDEN
50260+ bool "Harden module auto-loading"
50261+ default y if GRKERNSEC_CONFIG_AUTO
50262+ depends on MODULES
50263+ help
50264+ If you say Y here, module auto-loading in response to use of some
50265+ feature implemented by an unloaded module will be restricted to
50266+ root users. Enabling this option helps defend against attacks
50267+ by unprivileged users who abuse the auto-loading behavior to
50268+ cause a vulnerable module to load that is then exploited.
50269+
50270+ If this option prevents a legitimate use of auto-loading for a
50271+ non-root user, the administrator can execute modprobe manually
50272+ with the exact name of the module mentioned in the alert log.
50273+ Alternatively, the administrator can add the module to the list
50274+ of modules loaded at boot by modifying init scripts.
50275+
50276+ Modification of init scripts will most likely be needed on
50277+ Ubuntu servers with encrypted home directory support enabled,
50278+ as the first non-root user logging in will cause the ecb(aes),
50279+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
50280+
50281+config GRKERNSEC_HIDESYM
50282+ bool "Hide kernel symbols"
50283+ default y if GRKERNSEC_CONFIG_AUTO
50284+ select PAX_USERCOPY_SLABS
50285+ help
50286+ If you say Y here, getting information on loaded modules, and
50287+ displaying all kernel symbols through a syscall will be restricted
50288+ to users with CAP_SYS_MODULE. For software compatibility reasons,
50289+ /proc/kallsyms will be restricted to the root user. The RBAC
50290+ system can hide that entry even from root.
50291+
50292+ This option also prevents leaking of kernel addresses through
50293+ several /proc entries.
50294+
50295+ Note that this option is only effective provided the following
50296+ conditions are met:
50297+ 1) The kernel using grsecurity is not precompiled by some distribution
50298+ 2) You have also enabled GRKERNSEC_DMESG
50299+ 3) You are using the RBAC system and hiding other files such as your
50300+ kernel image and System.map. Alternatively, enabling this option
50301+ causes the permissions on /boot, /lib/modules, and the kernel
50302+ source directory to change at compile time to prevent
50303+ reading by non-root users.
50304+ If the above conditions are met, this option will aid in providing a
50305+ useful protection against local kernel exploitation of overflows
50306+ and arbitrary read/write vulnerabilities.
50307+
50308+config GRKERNSEC_KERN_LOCKOUT
50309+ bool "Active kernel exploit response"
50310+ default y if GRKERNSEC_CONFIG_AUTO
50311+ depends on X86 || ARM || PPC || SPARC
50312+ help
50313+ If you say Y here, when a PaX alert is triggered due to suspicious
50314+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
50315+ or an OOPS occurs due to bad memory accesses, instead of just
50316+ terminating the offending process (and potentially allowing
50317+ a subsequent exploit from the same user), we will take one of two
50318+ actions:
50319+ If the user was root, we will panic the system
50320+ If the user was non-root, we will log the attempt, terminate
50321+ all processes owned by the user, then prevent them from creating
50322+ any new processes until the system is restarted
50323+ This deters repeated kernel exploitation/bruteforcing attempts
50324+ and is useful for later forensics.
50325+
50326+endmenu
50327+menu "Role Based Access Control Options"
50328+depends on GRKERNSEC
50329+
50330+config GRKERNSEC_RBAC_DEBUG
50331+ bool
50332+
50333+config GRKERNSEC_NO_RBAC
50334+ bool "Disable RBAC system"
50335+ help
50336+ If you say Y here, the /dev/grsec device will be removed from the kernel,
50337+ preventing the RBAC system from being enabled. You should only say Y
50338+ here if you have no intention of using the RBAC system, so as to prevent
50339+ an attacker with root access from misusing the RBAC system to hide files
50340+ and processes when loadable module support and /dev/[k]mem have been
50341+ locked down.
50342+
50343+config GRKERNSEC_ACL_HIDEKERN
50344+ bool "Hide kernel processes"
50345+ help
50346+ If you say Y here, all kernel threads will be hidden to all
50347+ processes but those whose subject has the "view hidden processes"
50348+ flag.
50349+
50350+config GRKERNSEC_ACL_MAXTRIES
50351+ int "Maximum tries before password lockout"
50352+ default 3
50353+ help
50354+ This option enforces the maximum number of times a user can attempt
50355+ to authorize themselves with the grsecurity RBAC system before being
50356+ denied the ability to attempt authorization again for a specified time.
50357+ The lower the number, the harder it will be to brute-force a password.
50358+
50359+config GRKERNSEC_ACL_TIMEOUT
50360+ int "Time to wait after max password tries, in seconds"
50361+ default 30
50362+ help
50363+ This option specifies the time the user must wait after attempting to
50364+ authorize to the RBAC system with the maximum number of invalid
50365+ passwords. The higher the number, the harder it will be to brute-force
50366+ a password.
50367+
50368+endmenu
50369+menu "Filesystem Protections"
50370+depends on GRKERNSEC
50371+
50372+config GRKERNSEC_PROC
50373+ bool "Proc restrictions"
50374+ default y if GRKERNSEC_CONFIG_AUTO
50375+ help
50376+ If you say Y here, the permissions of the /proc filesystem
50377+ will be altered to enhance system security and privacy. You MUST
50378+ choose either a user only restriction or a user and group restriction.
50379+ Depending upon the option you choose, you can either restrict users to
50380+ see only the processes they themselves run, or choose a group that can
50381+ view all processes and files normally restricted to root if you choose
50382+ the "restrict to user only" option. NOTE: If you're running identd or
50383+ ntpd as a non-root user, you will have to run it as the group you
50384+ specify here.
50385+
50386+config GRKERNSEC_PROC_USER
50387+ bool "Restrict /proc to user only"
50388+ depends on GRKERNSEC_PROC
50389+ help
50390+ If you say Y here, non-root users will only be able to view their own
50391+ processes, and restricts them from viewing network-related information,
50392+ and viewing kernel symbol and module information.
50393+
50394+config GRKERNSEC_PROC_USERGROUP
50395+ bool "Allow special group"
50396+ default y if GRKERNSEC_CONFIG_AUTO
50397+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
50398+ help
50399+ If you say Y here, you will be able to select a group that will be
50400+ able to view all processes and network-related information. If you've
50401+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
50402+ remain hidden. This option is useful if you want to run identd as
50403+ a non-root user.
50404+
50405+config GRKERNSEC_PROC_GID
50406+ int "GID for special group"
50407+ depends on GRKERNSEC_PROC_USERGROUP
50408+ default 1001
50409+
50410+config GRKERNSEC_PROC_ADD
50411+ bool "Additional restrictions"
50412+ default y if GRKERNSEC_CONFIG_AUTO
50413+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
50414+ help
50415+ If you say Y here, additional restrictions will be placed on
50416+ /proc that keep normal users from viewing device information and
50417+ slabinfo information that could be useful for exploits.
50418+
50419+config GRKERNSEC_LINK
50420+ bool "Linking restrictions"
50421+ default y if GRKERNSEC_CONFIG_AUTO
50422+ help
50423+ If you say Y here, /tmp race exploits will be prevented, since users
50424+ will no longer be able to follow symlinks owned by other users in
50425+ world-writable +t directories (e.g. /tmp), unless the owner of the
50426+ symlink is the owner of the directory. users will also not be
50427+ able to hardlink to files they do not own. If the sysctl option is
50428+ enabled, a sysctl option with name "linking_restrictions" is created.
50429+
50430+config GRKERNSEC_SYMLINKOWN
50431+ bool "Kernel-enforced SymlinksIfOwnerMatch"
50432+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
50433+ help
50434+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
50435+ that prevents it from being used as a security feature. As Apache
50436+ verifies the symlink by performing a stat() against the target of
50437+ the symlink before it is followed, an attacker can setup a symlink
50438+ to point to a same-owned file, then replace the symlink with one
50439+ that targets another user's file just after Apache "validates" the
50440+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
50441+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
50442+ will be in place for the group you specify. If the sysctl option
50443+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
50444+ created.
50445+
50446+config GRKERNSEC_SYMLINKOWN_GID
50447+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
50448+ depends on GRKERNSEC_SYMLINKOWN
50449+ default 1006
50450+ help
50451+ Setting this GID determines what group kernel-enforced
50452+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
50453+ is enabled, a sysctl option with name "symlinkown_gid" is created.
50454+
50455+config GRKERNSEC_FIFO
50456+ bool "FIFO restrictions"
50457+ default y if GRKERNSEC_CONFIG_AUTO
50458+ help
50459+ If you say Y here, users will not be able to write to FIFOs they don't
50460+ own in world-writable +t directories (e.g. /tmp), unless the owner of
50461+ the FIFO is the same owner of the directory it's held in. If the sysctl
50462+ option is enabled, a sysctl option with name "fifo_restrictions" is
50463+ created.
50464+
50465+config GRKERNSEC_SYSFS_RESTRICT
50466+ bool "Sysfs/debugfs restriction"
50467+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50468+ depends on SYSFS
50469+ help
50470+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
50471+ any filesystem normally mounted under it (e.g. debugfs) will be
50472+ mostly accessible only by root. These filesystems generally provide access
50473+ to hardware and debug information that isn't appropriate for unprivileged
50474+ users of the system. Sysfs and debugfs have also become a large source
50475+ of new vulnerabilities, ranging from infoleaks to local compromise.
50476+ There has been very little oversight with an eye toward security involved
50477+ in adding new exporters of information to these filesystems, so their
50478+ use is discouraged.
50479+ For reasons of compatibility, a few directories have been whitelisted
50480+ for access by non-root users:
50481+ /sys/fs/selinux
50482+ /sys/fs/fuse
50483+ /sys/devices/system/cpu
50484+
50485+config GRKERNSEC_ROFS
50486+ bool "Runtime read-only mount protection"
50487+ help
50488+ If you say Y here, a sysctl option with name "romount_protect" will
50489+ be created. By setting this option to 1 at runtime, filesystems
50490+ will be protected in the following ways:
50491+ * No new writable mounts will be allowed
50492+ * Existing read-only mounts won't be able to be remounted read/write
50493+ * Write operations will be denied on all block devices
50494+ This option acts independently of grsec_lock: once it is set to 1,
50495+ it cannot be turned off. Therefore, please be mindful of the resulting
50496+ behavior if this option is enabled in an init script on a read-only
50497+ filesystem. This feature is mainly intended for secure embedded systems.
50498+
50499+config GRKERNSEC_CHROOT
50500+ bool "Chroot jail restrictions"
50501+ default y if GRKERNSEC_CONFIG_AUTO
50502+ help
50503+ If you say Y here, you will be able to choose several options that will
50504+ make breaking out of a chrooted jail much more difficult. If you
50505+ encounter no software incompatibilities with the following options, it
50506+ is recommended that you enable each one.
50507+
50508+config GRKERNSEC_CHROOT_MOUNT
50509+ bool "Deny mounts"
50510+ default y if GRKERNSEC_CONFIG_AUTO
50511+ depends on GRKERNSEC_CHROOT
50512+ help
50513+ If you say Y here, processes inside a chroot will not be able to
50514+ mount or remount filesystems. If the sysctl option is enabled, a
50515+ sysctl option with name "chroot_deny_mount" is created.
50516+
50517+config GRKERNSEC_CHROOT_DOUBLE
50518+ bool "Deny double-chroots"
50519+ default y if GRKERNSEC_CONFIG_AUTO
50520+ depends on GRKERNSEC_CHROOT
50521+ help
50522+ If you say Y here, processes inside a chroot will not be able to chroot
50523+ again outside the chroot. This is a widely used method of breaking
50524+ out of a chroot jail and should not be allowed. If the sysctl
50525+ option is enabled, a sysctl option with name
50526+ "chroot_deny_chroot" is created.
50527+
50528+config GRKERNSEC_CHROOT_PIVOT
50529+ bool "Deny pivot_root in chroot"
50530+ default y if GRKERNSEC_CONFIG_AUTO
50531+ depends on GRKERNSEC_CHROOT
50532+ help
50533+ If you say Y here, processes inside a chroot will not be able to use
50534+ a function called pivot_root() that was introduced in Linux 2.3.41. It
50535+ works similar to chroot in that it changes the root filesystem. This
50536+ function could be misused in a chrooted process to attempt to break out
50537+ of the chroot, and therefore should not be allowed. If the sysctl
50538+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
50539+ created.
50540+
50541+config GRKERNSEC_CHROOT_CHDIR
50542+ bool "Enforce chdir(\"/\") on all chroots"
50543+ default y if GRKERNSEC_CONFIG_AUTO
50544+ depends on GRKERNSEC_CHROOT
50545+ help
50546+ If you say Y here, the current working directory of all newly-chrooted
50547+ applications will be set to the the root directory of the chroot.
50548+ The man page on chroot(2) states:
50549+ Note that this call does not change the current working
50550+ directory, so that `.' can be outside the tree rooted at
50551+ `/'. In particular, the super-user can escape from a
50552+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
50553+
50554+ It is recommended that you say Y here, since it's not known to break
50555+ any software. If the sysctl option is enabled, a sysctl option with
50556+ name "chroot_enforce_chdir" is created.
50557+
50558+config GRKERNSEC_CHROOT_CHMOD
50559+ bool "Deny (f)chmod +s"
50560+ default y if GRKERNSEC_CONFIG_AUTO
50561+ depends on GRKERNSEC_CHROOT
50562+ help
50563+ If you say Y here, processes inside a chroot will not be able to chmod
50564+ or fchmod files to make them have suid or sgid bits. This protects
50565+ against another published method of breaking a chroot. If the sysctl
50566+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
50567+ created.
50568+
50569+config GRKERNSEC_CHROOT_FCHDIR
50570+ bool "Deny fchdir out of chroot"
50571+ default y if GRKERNSEC_CONFIG_AUTO
50572+ depends on GRKERNSEC_CHROOT
50573+ help
50574+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
50575+ to a file descriptor of the chrooting process that points to a directory
50576+ outside the filesystem will be stopped. If the sysctl option
50577+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
50578+
50579+config GRKERNSEC_CHROOT_MKNOD
50580+ bool "Deny mknod"
50581+ default y if GRKERNSEC_CONFIG_AUTO
50582+ depends on GRKERNSEC_CHROOT
50583+ help
50584+ If you say Y here, processes inside a chroot will not be allowed to
50585+ mknod. The problem with using mknod inside a chroot is that it
50586+ would allow an attacker to create a device entry that is the same
50587+ as one on the physical root of your system, which could range from
50588+ anything from the console device to a device for your harddrive (which
50589+ they could then use to wipe the drive or steal data). It is recommended
50590+ that you say Y here, unless you run into software incompatibilities.
50591+ If the sysctl option is enabled, a sysctl option with name
50592+ "chroot_deny_mknod" is created.
50593+
50594+config GRKERNSEC_CHROOT_SHMAT
50595+ bool "Deny shmat() out of chroot"
50596+ default y if GRKERNSEC_CONFIG_AUTO
50597+ depends on GRKERNSEC_CHROOT
50598+ help
50599+ If you say Y here, processes inside a chroot will not be able to attach
50600+ to shared memory segments that were created outside of the chroot jail.
50601+ It is recommended that you say Y here. If the sysctl option is enabled,
50602+ a sysctl option with name "chroot_deny_shmat" is created.
50603+
50604+config GRKERNSEC_CHROOT_UNIX
50605+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
50606+ default y if GRKERNSEC_CONFIG_AUTO
50607+ depends on GRKERNSEC_CHROOT
50608+ help
50609+ If you say Y here, processes inside a chroot will not be able to
50610+ connect to abstract (meaning not belonging to a filesystem) Unix
50611+ domain sockets that were bound outside of a chroot. It is recommended
50612+ that you say Y here. If the sysctl option is enabled, a sysctl option
50613+ with name "chroot_deny_unix" is created.
50614+
50615+config GRKERNSEC_CHROOT_FINDTASK
50616+ bool "Protect outside processes"
50617+ default y if GRKERNSEC_CONFIG_AUTO
50618+ depends on GRKERNSEC_CHROOT
50619+ help
50620+ If you say Y here, processes inside a chroot will not be able to
50621+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
50622+ getsid, or view any process outside of the chroot. If the sysctl
50623+ option is enabled, a sysctl option with name "chroot_findtask" is
50624+ created.
50625+
50626+config GRKERNSEC_CHROOT_NICE
50627+ bool "Restrict priority changes"
50628+ default y if GRKERNSEC_CONFIG_AUTO
50629+ depends on GRKERNSEC_CHROOT
50630+ help
50631+ If you say Y here, processes inside a chroot will not be able to raise
50632+ the priority of processes in the chroot, or alter the priority of
50633+ processes outside the chroot. This provides more security than simply
50634+ removing CAP_SYS_NICE from the process' capability set. If the
50635+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
50636+ is created.
50637+
50638+config GRKERNSEC_CHROOT_SYSCTL
50639+ bool "Deny sysctl writes"
50640+ default y if GRKERNSEC_CONFIG_AUTO
50641+ depends on GRKERNSEC_CHROOT
50642+ help
50643+ If you say Y here, an attacker in a chroot will not be able to
50644+ write to sysctl entries, either by sysctl(2) or through a /proc
50645+ interface. It is strongly recommended that you say Y here. If the
50646+ sysctl option is enabled, a sysctl option with name
50647+ "chroot_deny_sysctl" is created.
50648+
50649+config GRKERNSEC_CHROOT_CAPS
50650+ bool "Capability restrictions"
50651+ default y if GRKERNSEC_CONFIG_AUTO
50652+ depends on GRKERNSEC_CHROOT
50653+ help
50654+ If you say Y here, the capabilities on all processes within a
50655+ chroot jail will be lowered to stop module insertion, raw i/o,
50656+ system and net admin tasks, rebooting the system, modifying immutable
50657+ files, modifying IPC owned by another, and changing the system time.
50658+ This is left an option because it can break some apps. Disable this
50659+ if your chrooted apps are having problems performing those kinds of
50660+ tasks. If the sysctl option is enabled, a sysctl option with
50661+ name "chroot_caps" is created.
50662+
50663+endmenu
50664+menu "Kernel Auditing"
50665+depends on GRKERNSEC
50666+
50667+config GRKERNSEC_AUDIT_GROUP
50668+ bool "Single group for auditing"
50669+ help
50670+ If you say Y here, the exec, chdir, and (un)mount logging features
50671+ will only operate on a group you specify. This option is recommended
50672+ if you only want to watch certain users instead of having a large
50673+ amount of logs from the entire system. If the sysctl option is enabled,
50674+ a sysctl option with name "audit_group" is created.
50675+
50676+config GRKERNSEC_AUDIT_GID
50677+ int "GID for auditing"
50678+ depends on GRKERNSEC_AUDIT_GROUP
50679+ default 1007
50680+
50681+config GRKERNSEC_EXECLOG
50682+ bool "Exec logging"
50683+ help
50684+ If you say Y here, all execve() calls will be logged (since the
50685+ other exec*() calls are frontends to execve(), all execution
50686+ will be logged). Useful for shell-servers that like to keep track
50687+ of their users. If the sysctl option is enabled, a sysctl option with
50688+ name "exec_logging" is created.
50689+ WARNING: This option when enabled will produce a LOT of logs, especially
50690+ on an active system.
50691+
50692+config GRKERNSEC_RESLOG
50693+ bool "Resource logging"
50694+ default y if GRKERNSEC_CONFIG_AUTO
50695+ help
50696+ If you say Y here, all attempts to overstep resource limits will
50697+ be logged with the resource name, the requested size, and the current
50698+ limit. It is highly recommended that you say Y here. If the sysctl
50699+ option is enabled, a sysctl option with name "resource_logging" is
50700+ created. If the RBAC system is enabled, the sysctl value is ignored.
50701+
50702+config GRKERNSEC_CHROOT_EXECLOG
50703+ bool "Log execs within chroot"
50704+ help
50705+ If you say Y here, all executions inside a chroot jail will be logged
50706+ to syslog. This can cause a large amount of logs if certain
50707+ applications (eg. djb's daemontools) are installed on the system, and
50708+ is therefore left as an option. If the sysctl option is enabled, a
50709+ sysctl option with name "chroot_execlog" is created.
50710+
50711+config GRKERNSEC_AUDIT_PTRACE
50712+ bool "Ptrace logging"
50713+ help
50714+ If you say Y here, all attempts to attach to a process via ptrace
50715+ will be logged. If the sysctl option is enabled, a sysctl option
50716+ with name "audit_ptrace" is created.
50717+
50718+config GRKERNSEC_AUDIT_CHDIR
50719+ bool "Chdir logging"
50720+ help
50721+ If you say Y here, all chdir() calls will be logged. If the sysctl
50722+ option is enabled, a sysctl option with name "audit_chdir" is created.
50723+
50724+config GRKERNSEC_AUDIT_MOUNT
50725+ bool "(Un)Mount logging"
50726+ help
50727+ If you say Y here, all mounts and unmounts will be logged. If the
50728+ sysctl option is enabled, a sysctl option with name "audit_mount" is
50729+ created.
50730+
50731+config GRKERNSEC_SIGNAL
50732+ bool "Signal logging"
50733+ default y if GRKERNSEC_CONFIG_AUTO
50734+ help
50735+ If you say Y here, certain important signals will be logged, such as
50736+ SIGSEGV, which will as a result inform you of when a error in a program
50737+ occurred, which in some cases could mean a possible exploit attempt.
50738+ If the sysctl option is enabled, a sysctl option with name
50739+ "signal_logging" is created.
50740+
50741+config GRKERNSEC_FORKFAIL
50742+ bool "Fork failure logging"
50743+ help
50744+ If you say Y here, all failed fork() attempts will be logged.
50745+ This could suggest a fork bomb, or someone attempting to overstep
50746+ their process limit. If the sysctl option is enabled, a sysctl option
50747+ with name "forkfail_logging" is created.
50748+
50749+config GRKERNSEC_TIME
50750+ bool "Time change logging"
50751+ default y if GRKERNSEC_CONFIG_AUTO
50752+ help
50753+ If you say Y here, any changes of the system clock will be logged.
50754+ If the sysctl option is enabled, a sysctl option with name
50755+ "timechange_logging" is created.
50756+
50757+config GRKERNSEC_PROC_IPADDR
50758+ bool "/proc/<pid>/ipaddr support"
50759+ default y if GRKERNSEC_CONFIG_AUTO
50760+ help
50761+ If you say Y here, a new entry will be added to each /proc/<pid>
50762+ directory that contains the IP address of the person using the task.
50763+ The IP is carried across local TCP and AF_UNIX stream sockets.
50764+ This information can be useful for IDS/IPSes to perform remote response
50765+ to a local attack. The entry is readable by only the owner of the
50766+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
50767+ the RBAC system), and thus does not create privacy concerns.
50768+
50769+config GRKERNSEC_RWXMAP_LOG
50770+ bool 'Denied RWX mmap/mprotect logging'
50771+ default y if GRKERNSEC_CONFIG_AUTO
50772+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
50773+ help
50774+ If you say Y here, calls to mmap() and mprotect() with explicit
50775+ usage of PROT_WRITE and PROT_EXEC together will be logged when
50776+ denied by the PAX_MPROTECT feature. If the sysctl option is
50777+ enabled, a sysctl option with name "rwxmap_logging" is created.
50778+
50779+config GRKERNSEC_AUDIT_TEXTREL
50780+ bool 'ELF text relocations logging (READ HELP)'
50781+ depends on PAX_MPROTECT
50782+ help
50783+ If you say Y here, text relocations will be logged with the filename
50784+ of the offending library or binary. The purpose of the feature is
50785+ to help Linux distribution developers get rid of libraries and
50786+ binaries that need text relocations which hinder the future progress
50787+ of PaX. Only Linux distribution developers should say Y here, and
50788+ never on a production machine, as this option creates an information
50789+ leak that could aid an attacker in defeating the randomization of
50790+ a single memory region. If the sysctl option is enabled, a sysctl
50791+ option with name "audit_textrel" is created.
50792+
50793+endmenu
50794+
50795+menu "Executable Protections"
50796+depends on GRKERNSEC
50797+
50798+config GRKERNSEC_DMESG
50799+ bool "Dmesg(8) restriction"
50800+ default y if GRKERNSEC_CONFIG_AUTO
50801+ help
50802+ If you say Y here, non-root users will not be able to use dmesg(8)
50803+ to view up to the last 4kb of messages in the kernel's log buffer.
50804+ The kernel's log buffer often contains kernel addresses and other
50805+ identifying information useful to an attacker in fingerprinting a
50806+ system for a targeted exploit.
50807+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
50808+ created.
50809+
50810+config GRKERNSEC_HARDEN_PTRACE
50811+ bool "Deter ptrace-based process snooping"
50812+ default y if GRKERNSEC_CONFIG_AUTO
50813+ help
50814+ If you say Y here, TTY sniffers and other malicious monitoring
50815+ programs implemented through ptrace will be defeated. If you
50816+ have been using the RBAC system, this option has already been
50817+ enabled for several years for all users, with the ability to make
50818+ fine-grained exceptions.
50819+
50820+ This option only affects the ability of non-root users to ptrace
50821+ processes that are not a descendent of the ptracing process.
50822+ This means that strace ./binary and gdb ./binary will still work,
50823+ but attaching to arbitrary processes will not. If the sysctl
50824+ option is enabled, a sysctl option with name "harden_ptrace" is
50825+ created.
50826+
50827+config GRKERNSEC_PTRACE_READEXEC
50828+ bool "Require read access to ptrace sensitive binaries"
50829+ default y if GRKERNSEC_CONFIG_AUTO
50830+ help
50831+ If you say Y here, unprivileged users will not be able to ptrace unreadable
50832+ binaries. This option is useful in environments that
50833+ remove the read bits (e.g. file mode 4711) from suid binaries to
50834+ prevent infoleaking of their contents. This option adds
50835+ consistency to the use of that file mode, as the binary could normally
50836+ be read out when run without privileges while ptracing.
50837+
50838+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
50839+ is created.
50840+
50841+config GRKERNSEC_SETXID
50842+ bool "Enforce consistent multithreaded privileges"
50843+ default y if GRKERNSEC_CONFIG_AUTO
50844+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
50845+ help
50846+ If you say Y here, a change from a root uid to a non-root uid
50847+ in a multithreaded application will cause the resulting uids,
50848+ gids, supplementary groups, and capabilities in that thread
50849+ to be propagated to the other threads of the process. In most
50850+ cases this is unnecessary, as glibc will emulate this behavior
50851+ on behalf of the application. Other libcs do not act in the
50852+ same way, allowing the other threads of the process to continue
50853+ running with root privileges. If the sysctl option is enabled,
50854+ a sysctl option with name "consistent_setxid" is created.
50855+
50856+config GRKERNSEC_TPE
50857+ bool "Trusted Path Execution (TPE)"
50858+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
50859+ help
50860+ If you say Y here, you will be able to choose a gid to add to the
50861+ supplementary groups of users you want to mark as "untrusted."
50862+ These users will not be able to execute any files that are not in
50863+ root-owned directories writable only by root. If the sysctl option
50864+ is enabled, a sysctl option with name "tpe" is created.
50865+
50866+config GRKERNSEC_TPE_ALL
50867+ bool "Partially restrict all non-root users"
50868+ depends on GRKERNSEC_TPE
50869+ help
50870+ If you say Y here, all non-root users will be covered under
50871+ a weaker TPE restriction. This is separate from, and in addition to,
50872+ the main TPE options that you have selected elsewhere. Thus, if a
50873+ "trusted" GID is chosen, this restriction applies to even that GID.
50874+ Under this restriction, all non-root users will only be allowed to
50875+ execute files in directories they own that are not group or
50876+ world-writable, or in directories owned by root and writable only by
50877+ root. If the sysctl option is enabled, a sysctl option with name
50878+ "tpe_restrict_all" is created.
50879+
50880+config GRKERNSEC_TPE_INVERT
50881+ bool "Invert GID option"
50882+ depends on GRKERNSEC_TPE
50883+ help
50884+ If you say Y here, the group you specify in the TPE configuration will
50885+ decide what group TPE restrictions will be *disabled* for. This
50886+ option is useful if you want TPE restrictions to be applied to most
50887+ users on the system. If the sysctl option is enabled, a sysctl option
50888+ with name "tpe_invert" is created. Unlike other sysctl options, this
50889+ entry will default to on for backward-compatibility.
50890+
50891+config GRKERNSEC_TPE_GID
50892+ int "GID for untrusted users"
50893+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
50894+ default 1005
50895+ help
50896+ Setting this GID determines what group TPE restrictions will be
50897+ *enabled* for. If the sysctl option is enabled, a sysctl option
50898+ with name "tpe_gid" is created.
50899+
50900+config GRKERNSEC_TPE_GID
50901+ int "GID for trusted users"
50902+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
50903+ default 1005
50904+ help
50905+ Setting this GID determines what group TPE restrictions will be
50906+ *disabled* for. If the sysctl option is enabled, a sysctl option
50907+ with name "tpe_gid" is created.
50908+
50909+endmenu
50910+menu "Network Protections"
50911+depends on GRKERNSEC
50912+
50913+config GRKERNSEC_RANDNET
50914+ bool "Larger entropy pools"
50915+ default y if GRKERNSEC_CONFIG_AUTO
50916+ help
50917+ If you say Y here, the entropy pools used for many features of Linux
50918+ and grsecurity will be doubled in size. Since several grsecurity
50919+ features use additional randomness, it is recommended that you say Y
50920+ here. Saying Y here has a similar effect as modifying
50921+ /proc/sys/kernel/random/poolsize.
50922+
50923+config GRKERNSEC_BLACKHOLE
50924+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
50925+ default y if GRKERNSEC_CONFIG_AUTO
50926+ depends on NET
50927+ help
50928+ If you say Y here, neither TCP resets nor ICMP
50929+ destination-unreachable packets will be sent in response to packets
50930+ sent to ports for which no associated listening process exists.
50931+ This feature supports both IPV4 and IPV6 and exempts the
50932+ loopback interface from blackholing. Enabling this feature
50933+ makes a host more resilient to DoS attacks and reduces network
50934+ visibility against scanners.
50935+
50936+ The blackhole feature as-implemented is equivalent to the FreeBSD
50937+ blackhole feature, as it prevents RST responses to all packets, not
50938+ just SYNs. Under most application behavior this causes no
50939+ problems, but applications (like haproxy) may not close certain
50940+ connections in a way that cleanly terminates them on the remote
50941+ end, leaving the remote host in LAST_ACK state. Because of this
50942+ side-effect and to prevent intentional LAST_ACK DoSes, this
50943+ feature also adds automatic mitigation against such attacks.
50944+ The mitigation drastically reduces the amount of time a socket
50945+ can spend in LAST_ACK state. If you're using haproxy and not
50946+ all servers it connects to have this option enabled, consider
50947+ disabling this feature on the haproxy host.
50948+
50949+ If the sysctl option is enabled, two sysctl options with names
50950+ "ip_blackhole" and "lastack_retries" will be created.
50951+ While "ip_blackhole" takes the standard zero/non-zero on/off
50952+ toggle, "lastack_retries" uses the same kinds of values as
50953+ "tcp_retries1" and "tcp_retries2". The default value of 4
50954+ prevents a socket from lasting more than 45 seconds in LAST_ACK
50955+ state.
50956+
50957+config GRKERNSEC_SOCKET
50958+ bool "Socket restrictions"
50959+ depends on NET
50960+ help
50961+ If you say Y here, you will be able to choose from several options.
50962+ If you assign a GID on your system and add it to the supplementary
50963+ groups of users you want to restrict socket access to, this patch
50964+ will perform up to three things, based on the option(s) you choose.
50965+
50966+config GRKERNSEC_SOCKET_ALL
50967+ bool "Deny any sockets to group"
50968+ depends on GRKERNSEC_SOCKET
50969+ help
50970+ If you say Y here, you will be able to choose a GID of whose users will
50971+ be unable to connect to other hosts from your machine or run server
50972+ applications from your machine. If the sysctl option is enabled, a
50973+ sysctl option with name "socket_all" is created.
50974+
50975+config GRKERNSEC_SOCKET_ALL_GID
50976+ int "GID to deny all sockets for"
50977+ depends on GRKERNSEC_SOCKET_ALL
50978+ default 1004
50979+ help
50980+ Here you can choose the GID to disable socket access for. Remember to
50981+ add the users you want socket access disabled for to the GID
50982+ specified here. If the sysctl option is enabled, a sysctl option
50983+ with name "socket_all_gid" is created.
50984+
50985+config GRKERNSEC_SOCKET_CLIENT
50986+ bool "Deny client sockets to group"
50987+ depends on GRKERNSEC_SOCKET
50988+ help
50989+ If you say Y here, you will be able to choose a GID of whose users will
50990+ be unable to connect to other hosts from your machine, but will be
50991+ able to run servers. If this option is enabled, all users in the group
50992+ you specify will have to use passive mode when initiating ftp transfers
50993+ from the shell on your machine. If the sysctl option is enabled, a
50994+ sysctl option with name "socket_client" is created.
50995+
50996+config GRKERNSEC_SOCKET_CLIENT_GID
50997+ int "GID to deny client sockets for"
50998+ depends on GRKERNSEC_SOCKET_CLIENT
50999+ default 1003
51000+ help
51001+ Here you can choose the GID to disable client socket access for.
51002+ Remember to add the users you want client socket access disabled for to
51003+ the GID specified here. If the sysctl option is enabled, a sysctl
51004+ option with name "socket_client_gid" is created.
51005+
51006+config GRKERNSEC_SOCKET_SERVER
51007+ bool "Deny server sockets to group"
51008+ depends on GRKERNSEC_SOCKET
51009+ help
51010+ If you say Y here, you will be able to choose a GID of whose users will
51011+ be unable to run server applications from your machine. If the sysctl
51012+ option is enabled, a sysctl option with name "socket_server" is created.
51013+
51014+config GRKERNSEC_SOCKET_SERVER_GID
51015+ int "GID to deny server sockets for"
51016+ depends on GRKERNSEC_SOCKET_SERVER
51017+ default 1002
51018+ help
51019+ Here you can choose the GID to disable server socket access for.
51020+ Remember to add the users you want server socket access disabled for to
51021+ the GID specified here. If the sysctl option is enabled, a sysctl
51022+ option with name "socket_server_gid" is created.
51023+
51024+endmenu
51025+menu "Sysctl Support"
51026+depends on GRKERNSEC && SYSCTL
51027+
51028+config GRKERNSEC_SYSCTL
51029+ bool "Sysctl support"
51030+ default y if GRKERNSEC_CONFIG_AUTO
51031+ help
51032+ If you say Y here, you will be able to change the options that
51033+ grsecurity runs with at bootup, without having to recompile your
51034+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
51035+ to enable (1) or disable (0) various features. All the sysctl entries
51036+ are mutable until the "grsec_lock" entry is set to a non-zero value.
51037+ All features enabled in the kernel configuration are disabled at boot
51038+ if you do not say Y to the "Turn on features by default" option.
51039+ All options should be set at startup, and the grsec_lock entry should
51040+ be set to a non-zero value after all the options are set.
51041+ *THIS IS EXTREMELY IMPORTANT*
51042+
51043+config GRKERNSEC_SYSCTL_DISTRO
51044+ bool "Extra sysctl support for distro makers (READ HELP)"
51045+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
51046+ help
51047+ If you say Y here, additional sysctl options will be created
51048+ for features that affect processes running as root. Therefore,
51049+ it is critical when using this option that the grsec_lock entry be
51050+ enabled after boot. Only distros with prebuilt kernel packages
51051+ with this option enabled that can ensure grsec_lock is enabled
51052+ after boot should use this option.
51053+ *Failure to set grsec_lock after boot makes all grsec features
51054+ this option covers useless*
51055+
51056+ Currently this option creates the following sysctl entries:
51057+ "Disable Privileged I/O": "disable_priv_io"
51058+
51059+config GRKERNSEC_SYSCTL_ON
51060+ bool "Turn on features by default"
51061+ default y if GRKERNSEC_CONFIG_AUTO
51062+ depends on GRKERNSEC_SYSCTL
51063+ help
51064+ If you say Y here, instead of having all features enabled in the
51065+ kernel configuration disabled at boot time, the features will be
51066+ enabled at boot time. It is recommended you say Y here unless
51067+ there is some reason you would want all sysctl-tunable features to
51068+ be disabled by default. As mentioned elsewhere, it is important
51069+ to enable the grsec_lock entry once you have finished modifying
51070+ the sysctl entries.
51071+
51072+endmenu
51073+menu "Logging Options"
51074+depends on GRKERNSEC
51075+
51076+config GRKERNSEC_FLOODTIME
51077+ int "Seconds in between log messages (minimum)"
51078+ default 10
51079+ help
51080+ This option allows you to enforce the number of seconds between
51081+ grsecurity log messages. The default should be suitable for most
51082+ people, however, if you choose to change it, choose a value small enough
51083+ to allow informative logs to be produced, but large enough to
51084+ prevent flooding.
51085+
51086+config GRKERNSEC_FLOODBURST
51087+ int "Number of messages in a burst (maximum)"
51088+ default 6
51089+ help
51090+ This option allows you to choose the maximum number of messages allowed
51091+ within the flood time interval you chose in a separate option. The
51092+ default should be suitable for most people, however if you find that
51093+ many of your logs are being interpreted as flooding, you may want to
51094+ raise this value.
51095+
51096+endmenu
51097diff --git a/grsecurity/Makefile b/grsecurity/Makefile
51098new file mode 100644
51099index 0000000..1b9afa9
51100--- /dev/null
51101+++ b/grsecurity/Makefile
51102@@ -0,0 +1,38 @@
51103+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
51104+# during 2001-2009 it has been completely redesigned by Brad Spengler
51105+# into an RBAC system
51106+#
51107+# All code in this directory and various hooks inserted throughout the kernel
51108+# are copyright Brad Spengler - Open Source Security, Inc., and released
51109+# under the GPL v2 or higher
51110+
51111+KBUILD_CFLAGS += -Werror
51112+
51113+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
51114+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
51115+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
51116+
51117+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
51118+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
51119+ gracl_learn.o grsec_log.o
51120+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
51121+
51122+ifdef CONFIG_NET
51123+obj-y += grsec_sock.o
51124+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
51125+endif
51126+
51127+ifndef CONFIG_GRKERNSEC
51128+obj-y += grsec_disabled.o
51129+endif
51130+
51131+ifdef CONFIG_GRKERNSEC_HIDESYM
51132+extra-y := grsec_hidesym.o
51133+$(obj)/grsec_hidesym.o:
51134+ @-chmod -f 500 /boot
51135+ @-chmod -f 500 /lib/modules
51136+ @-chmod -f 500 /lib64/modules
51137+ @-chmod -f 500 /lib32/modules
51138+ @-chmod -f 700 .
51139+ @echo ' grsec: protected kernel image paths'
51140+endif
51141diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
51142new file mode 100644
51143index 0000000..1561617
51144--- /dev/null
51145+++ b/grsecurity/gracl.c
51146@@ -0,0 +1,4017 @@
51147+#include <linux/kernel.h>
51148+#include <linux/module.h>
51149+#include <linux/sched.h>
51150+#include <linux/mm.h>
51151+#include <linux/file.h>
51152+#include <linux/fs.h>
51153+#include <linux/namei.h>
51154+#include <linux/mount.h>
51155+#include <linux/tty.h>
51156+#include <linux/proc_fs.h>
51157+#include <linux/lglock.h>
51158+#include <linux/slab.h>
51159+#include <linux/vmalloc.h>
51160+#include <linux/types.h>
51161+#include <linux/sysctl.h>
51162+#include <linux/netdevice.h>
51163+#include <linux/ptrace.h>
51164+#include <linux/gracl.h>
51165+#include <linux/gralloc.h>
51166+#include <linux/security.h>
51167+#include <linux/grinternal.h>
51168+#include <linux/pid_namespace.h>
51169+#include <linux/stop_machine.h>
51170+#include <linux/fdtable.h>
51171+#include <linux/percpu.h>
51172+#include <linux/lglock.h>
51173+#include "../fs/mount.h"
51174+
51175+#include <asm/uaccess.h>
51176+#include <asm/errno.h>
51177+#include <asm/mman.h>
51178+
51179+extern struct lglock vfsmount_lock;
51180+
51181+static struct acl_role_db acl_role_set;
51182+static struct name_db name_set;
51183+static struct inodev_db inodev_set;
51184+
51185+/* for keeping track of userspace pointers used for subjects, so we
51186+ can share references in the kernel as well
51187+*/
51188+
51189+static struct path real_root;
51190+
51191+static struct acl_subj_map_db subj_map_set;
51192+
51193+static struct acl_role_label *default_role;
51194+
51195+static struct acl_role_label *role_list;
51196+
51197+static u16 acl_sp_role_value;
51198+
51199+extern char *gr_shared_page[4];
51200+static DEFINE_MUTEX(gr_dev_mutex);
51201+DEFINE_RWLOCK(gr_inode_lock);
51202+
51203+struct gr_arg *gr_usermode;
51204+
51205+static unsigned int gr_status __read_only = GR_STATUS_INIT;
51206+
51207+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51208+extern void gr_clear_learn_entries(void);
51209+
51210+#ifdef CONFIG_GRKERNSEC_RESLOG
51211+extern void gr_log_resource(const struct task_struct *task,
51212+ const int res, const unsigned long wanted, const int gt);
51213+#endif
51214+
51215+unsigned char *gr_system_salt;
51216+unsigned char *gr_system_sum;
51217+
51218+static struct sprole_pw **acl_special_roles = NULL;
51219+static __u16 num_sprole_pws = 0;
51220+
51221+static struct acl_role_label *kernel_role = NULL;
51222+
51223+static unsigned int gr_auth_attempts = 0;
51224+static unsigned long gr_auth_expires = 0UL;
51225+
51226+#ifdef CONFIG_NET
51227+extern struct vfsmount *sock_mnt;
51228+#endif
51229+
51230+extern struct vfsmount *pipe_mnt;
51231+extern struct vfsmount *shm_mnt;
51232+#ifdef CONFIG_HUGETLBFS
51233+extern struct vfsmount *hugetlbfs_vfsmount;
51234+#endif
51235+
51236+static struct acl_object_label *fakefs_obj_rw;
51237+static struct acl_object_label *fakefs_obj_rwx;
51238+
51239+extern int gr_init_uidset(void);
51240+extern void gr_free_uidset(void);
51241+extern void gr_remove_uid(uid_t uid);
51242+extern int gr_find_uid(uid_t uid);
51243+
51244+__inline__ int
51245+gr_acl_is_enabled(void)
51246+{
51247+ return (gr_status & GR_READY);
51248+}
51249+
51250+#ifdef CONFIG_BTRFS_FS
51251+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51252+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51253+#endif
51254+
51255+static inline dev_t __get_dev(const struct dentry *dentry)
51256+{
51257+#ifdef CONFIG_BTRFS_FS
51258+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51259+ return get_btrfs_dev_from_inode(dentry->d_inode);
51260+ else
51261+#endif
51262+ return dentry->d_inode->i_sb->s_dev;
51263+}
51264+
51265+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51266+{
51267+ return __get_dev(dentry);
51268+}
51269+
51270+static char gr_task_roletype_to_char(struct task_struct *task)
51271+{
51272+ switch (task->role->roletype &
51273+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51274+ GR_ROLE_SPECIAL)) {
51275+ case GR_ROLE_DEFAULT:
51276+ return 'D';
51277+ case GR_ROLE_USER:
51278+ return 'U';
51279+ case GR_ROLE_GROUP:
51280+ return 'G';
51281+ case GR_ROLE_SPECIAL:
51282+ return 'S';
51283+ }
51284+
51285+ return 'X';
51286+}
51287+
51288+char gr_roletype_to_char(void)
51289+{
51290+ return gr_task_roletype_to_char(current);
51291+}
51292+
51293+__inline__ int
51294+gr_acl_tpe_check(void)
51295+{
51296+ if (unlikely(!(gr_status & GR_READY)))
51297+ return 0;
51298+ if (current->role->roletype & GR_ROLE_TPE)
51299+ return 1;
51300+ else
51301+ return 0;
51302+}
51303+
51304+int
51305+gr_handle_rawio(const struct inode *inode)
51306+{
51307+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51308+ if (inode && S_ISBLK(inode->i_mode) &&
51309+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51310+ !capable(CAP_SYS_RAWIO))
51311+ return 1;
51312+#endif
51313+ return 0;
51314+}
51315+
51316+static int
51317+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51318+{
51319+ if (likely(lena != lenb))
51320+ return 0;
51321+
51322+ return !memcmp(a, b, lena);
51323+}
51324+
51325+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51326+{
51327+ *buflen -= namelen;
51328+ if (*buflen < 0)
51329+ return -ENAMETOOLONG;
51330+ *buffer -= namelen;
51331+ memcpy(*buffer, str, namelen);
51332+ return 0;
51333+}
51334+
51335+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51336+{
51337+ return prepend(buffer, buflen, name->name, name->len);
51338+}
51339+
51340+static int prepend_path(const struct path *path, struct path *root,
51341+ char **buffer, int *buflen)
51342+{
51343+ struct dentry *dentry = path->dentry;
51344+ struct vfsmount *vfsmnt = path->mnt;
51345+ struct mount *mnt = real_mount(vfsmnt);
51346+ bool slash = false;
51347+ int error = 0;
51348+
51349+ while (dentry != root->dentry || vfsmnt != root->mnt) {
51350+ struct dentry * parent;
51351+
51352+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51353+ /* Global root? */
51354+ if (!mnt_has_parent(mnt)) {
51355+ goto out;
51356+ }
51357+ dentry = mnt->mnt_mountpoint;
51358+ mnt = mnt->mnt_parent;
51359+ vfsmnt = &mnt->mnt;
51360+ continue;
51361+ }
51362+ parent = dentry->d_parent;
51363+ prefetch(parent);
51364+ spin_lock(&dentry->d_lock);
51365+ error = prepend_name(buffer, buflen, &dentry->d_name);
51366+ spin_unlock(&dentry->d_lock);
51367+ if (!error)
51368+ error = prepend(buffer, buflen, "/", 1);
51369+ if (error)
51370+ break;
51371+
51372+ slash = true;
51373+ dentry = parent;
51374+ }
51375+
51376+out:
51377+ if (!error && !slash)
51378+ error = prepend(buffer, buflen, "/", 1);
51379+
51380+ return error;
51381+}
51382+
51383+/* this must be called with vfsmount_lock and rename_lock held */
51384+
51385+static char *__our_d_path(const struct path *path, struct path *root,
51386+ char *buf, int buflen)
51387+{
51388+ char *res = buf + buflen;
51389+ int error;
51390+
51391+ prepend(&res, &buflen, "\0", 1);
51392+ error = prepend_path(path, root, &res, &buflen);
51393+ if (error)
51394+ return ERR_PTR(error);
51395+
51396+ return res;
51397+}
51398+
51399+static char *
51400+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
51401+{
51402+ char *retval;
51403+
51404+ retval = __our_d_path(path, root, buf, buflen);
51405+ if (unlikely(IS_ERR(retval)))
51406+ retval = strcpy(buf, "<path too long>");
51407+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
51408+ retval[1] = '\0';
51409+
51410+ return retval;
51411+}
51412+
51413+static char *
51414+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51415+ char *buf, int buflen)
51416+{
51417+ struct path path;
51418+ char *res;
51419+
51420+ path.dentry = (struct dentry *)dentry;
51421+ path.mnt = (struct vfsmount *)vfsmnt;
51422+
51423+ /* we can use real_root.dentry, real_root.mnt, because this is only called
51424+ by the RBAC system */
51425+ res = gen_full_path(&path, &real_root, buf, buflen);
51426+
51427+ return res;
51428+}
51429+
51430+static char *
51431+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51432+ char *buf, int buflen)
51433+{
51434+ char *res;
51435+ struct path path;
51436+ struct path root;
51437+ struct task_struct *reaper = init_pid_ns.child_reaper;
51438+
51439+ path.dentry = (struct dentry *)dentry;
51440+ path.mnt = (struct vfsmount *)vfsmnt;
51441+
51442+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
51443+ get_fs_root(reaper->fs, &root);
51444+
51445+ write_seqlock(&rename_lock);
51446+ br_read_lock(&vfsmount_lock);
51447+ res = gen_full_path(&path, &root, buf, buflen);
51448+ br_read_unlock(&vfsmount_lock);
51449+ write_sequnlock(&rename_lock);
51450+
51451+ path_put(&root);
51452+ return res;
51453+}
51454+
51455+static char *
51456+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51457+{
51458+ char *ret;
51459+ write_seqlock(&rename_lock);
51460+ br_read_lock(&vfsmount_lock);
51461+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51462+ PAGE_SIZE);
51463+ br_read_unlock(&vfsmount_lock);
51464+ write_sequnlock(&rename_lock);
51465+ return ret;
51466+}
51467+
51468+static char *
51469+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51470+{
51471+ char *ret;
51472+ char *buf;
51473+ int buflen;
51474+
51475+ write_seqlock(&rename_lock);
51476+ br_read_lock(&vfsmount_lock);
51477+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
51478+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
51479+ buflen = (int)(ret - buf);
51480+ if (buflen >= 5)
51481+ prepend(&ret, &buflen, "/proc", 5);
51482+ else
51483+ ret = strcpy(buf, "<path too long>");
51484+ br_read_unlock(&vfsmount_lock);
51485+ write_sequnlock(&rename_lock);
51486+ return ret;
51487+}
51488+
51489+char *
51490+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
51491+{
51492+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51493+ PAGE_SIZE);
51494+}
51495+
51496+char *
51497+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
51498+{
51499+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
51500+ PAGE_SIZE);
51501+}
51502+
51503+char *
51504+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
51505+{
51506+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
51507+ PAGE_SIZE);
51508+}
51509+
51510+char *
51511+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
51512+{
51513+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
51514+ PAGE_SIZE);
51515+}
51516+
51517+char *
51518+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
51519+{
51520+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
51521+ PAGE_SIZE);
51522+}
51523+
51524+__inline__ __u32
51525+to_gr_audit(const __u32 reqmode)
51526+{
51527+ /* masks off auditable permission flags, then shifts them to create
51528+ auditing flags, and adds the special case of append auditing if
51529+ we're requesting write */
51530+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
51531+}
51532+
51533+struct acl_subject_label *
51534+lookup_subject_map(const struct acl_subject_label *userp)
51535+{
51536+ unsigned int index = shash(userp, subj_map_set.s_size);
51537+ struct subject_map *match;
51538+
51539+ match = subj_map_set.s_hash[index];
51540+
51541+ while (match && match->user != userp)
51542+ match = match->next;
51543+
51544+ if (match != NULL)
51545+ return match->kernel;
51546+ else
51547+ return NULL;
51548+}
51549+
51550+static void
51551+insert_subj_map_entry(struct subject_map *subjmap)
51552+{
51553+ unsigned int index = shash(subjmap->user, subj_map_set.s_size);
51554+ struct subject_map **curr;
51555+
51556+ subjmap->prev = NULL;
51557+
51558+ curr = &subj_map_set.s_hash[index];
51559+ if (*curr != NULL)
51560+ (*curr)->prev = subjmap;
51561+
51562+ subjmap->next = *curr;
51563+ *curr = subjmap;
51564+
51565+ return;
51566+}
51567+
51568+static struct acl_role_label *
51569+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
51570+ const gid_t gid)
51571+{
51572+ unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
51573+ struct acl_role_label *match;
51574+ struct role_allowed_ip *ipp;
51575+ unsigned int x;
51576+ u32 curr_ip = task->signal->curr_ip;
51577+
51578+ task->signal->saved_ip = curr_ip;
51579+
51580+ match = acl_role_set.r_hash[index];
51581+
51582+ while (match) {
51583+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
51584+ for (x = 0; x < match->domain_child_num; x++) {
51585+ if (match->domain_children[x] == uid)
51586+ goto found;
51587+ }
51588+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
51589+ break;
51590+ match = match->next;
51591+ }
51592+found:
51593+ if (match == NULL) {
51594+ try_group:
51595+ index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
51596+ match = acl_role_set.r_hash[index];
51597+
51598+ while (match) {
51599+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
51600+ for (x = 0; x < match->domain_child_num; x++) {
51601+ if (match->domain_children[x] == gid)
51602+ goto found2;
51603+ }
51604+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
51605+ break;
51606+ match = match->next;
51607+ }
51608+found2:
51609+ if (match == NULL)
51610+ match = default_role;
51611+ if (match->allowed_ips == NULL)
51612+ return match;
51613+ else {
51614+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51615+ if (likely
51616+ ((ntohl(curr_ip) & ipp->netmask) ==
51617+ (ntohl(ipp->addr) & ipp->netmask)))
51618+ return match;
51619+ }
51620+ match = default_role;
51621+ }
51622+ } else if (match->allowed_ips == NULL) {
51623+ return match;
51624+ } else {
51625+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51626+ if (likely
51627+ ((ntohl(curr_ip) & ipp->netmask) ==
51628+ (ntohl(ipp->addr) & ipp->netmask)))
51629+ return match;
51630+ }
51631+ goto try_group;
51632+ }
51633+
51634+ return match;
51635+}
51636+
51637+struct acl_subject_label *
51638+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
51639+ const struct acl_role_label *role)
51640+{
51641+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
51642+ struct acl_subject_label *match;
51643+
51644+ match = role->subj_hash[index];
51645+
51646+ while (match && (match->inode != ino || match->device != dev ||
51647+ (match->mode & GR_DELETED))) {
51648+ match = match->next;
51649+ }
51650+
51651+ if (match && !(match->mode & GR_DELETED))
51652+ return match;
51653+ else
51654+ return NULL;
51655+}
51656+
51657+struct acl_subject_label *
51658+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
51659+ const struct acl_role_label *role)
51660+{
51661+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
51662+ struct acl_subject_label *match;
51663+
51664+ match = role->subj_hash[index];
51665+
51666+ while (match && (match->inode != ino || match->device != dev ||
51667+ !(match->mode & GR_DELETED))) {
51668+ match = match->next;
51669+ }
51670+
51671+ if (match && (match->mode & GR_DELETED))
51672+ return match;
51673+ else
51674+ return NULL;
51675+}
51676+
51677+static struct acl_object_label *
51678+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
51679+ const struct acl_subject_label *subj)
51680+{
51681+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51682+ struct acl_object_label *match;
51683+
51684+ match = subj->obj_hash[index];
51685+
51686+ while (match && (match->inode != ino || match->device != dev ||
51687+ (match->mode & GR_DELETED))) {
51688+ match = match->next;
51689+ }
51690+
51691+ if (match && !(match->mode & GR_DELETED))
51692+ return match;
51693+ else
51694+ return NULL;
51695+}
51696+
51697+static struct acl_object_label *
51698+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
51699+ const struct acl_subject_label *subj)
51700+{
51701+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51702+ struct acl_object_label *match;
51703+
51704+ match = subj->obj_hash[index];
51705+
51706+ while (match && (match->inode != ino || match->device != dev ||
51707+ !(match->mode & GR_DELETED))) {
51708+ match = match->next;
51709+ }
51710+
51711+ if (match && (match->mode & GR_DELETED))
51712+ return match;
51713+
51714+ match = subj->obj_hash[index];
51715+
51716+ while (match && (match->inode != ino || match->device != dev ||
51717+ (match->mode & GR_DELETED))) {
51718+ match = match->next;
51719+ }
51720+
51721+ if (match && !(match->mode & GR_DELETED))
51722+ return match;
51723+ else
51724+ return NULL;
51725+}
51726+
51727+static struct name_entry *
51728+lookup_name_entry(const char *name)
51729+{
51730+ unsigned int len = strlen(name);
51731+ unsigned int key = full_name_hash(name, len);
51732+ unsigned int index = key % name_set.n_size;
51733+ struct name_entry *match;
51734+
51735+ match = name_set.n_hash[index];
51736+
51737+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
51738+ match = match->next;
51739+
51740+ return match;
51741+}
51742+
51743+static struct name_entry *
51744+lookup_name_entry_create(const char *name)
51745+{
51746+ unsigned int len = strlen(name);
51747+ unsigned int key = full_name_hash(name, len);
51748+ unsigned int index = key % name_set.n_size;
51749+ struct name_entry *match;
51750+
51751+ match = name_set.n_hash[index];
51752+
51753+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51754+ !match->deleted))
51755+ match = match->next;
51756+
51757+ if (match && match->deleted)
51758+ return match;
51759+
51760+ match = name_set.n_hash[index];
51761+
51762+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51763+ match->deleted))
51764+ match = match->next;
51765+
51766+ if (match && !match->deleted)
51767+ return match;
51768+ else
51769+ return NULL;
51770+}
51771+
51772+static struct inodev_entry *
51773+lookup_inodev_entry(const ino_t ino, const dev_t dev)
51774+{
51775+ unsigned int index = fhash(ino, dev, inodev_set.i_size);
51776+ struct inodev_entry *match;
51777+
51778+ match = inodev_set.i_hash[index];
51779+
51780+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
51781+ match = match->next;
51782+
51783+ return match;
51784+}
51785+
51786+static void
51787+insert_inodev_entry(struct inodev_entry *entry)
51788+{
51789+ unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
51790+ inodev_set.i_size);
51791+ struct inodev_entry **curr;
51792+
51793+ entry->prev = NULL;
51794+
51795+ curr = &inodev_set.i_hash[index];
51796+ if (*curr != NULL)
51797+ (*curr)->prev = entry;
51798+
51799+ entry->next = *curr;
51800+ *curr = entry;
51801+
51802+ return;
51803+}
51804+
51805+static void
51806+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
51807+{
51808+ unsigned int index =
51809+ rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
51810+ struct acl_role_label **curr;
51811+ struct acl_role_label *tmp, *tmp2;
51812+
51813+ curr = &acl_role_set.r_hash[index];
51814+
51815+ /* simple case, slot is empty, just set it to our role */
51816+ if (*curr == NULL) {
51817+ *curr = role;
51818+ } else {
51819+ /* example:
51820+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
51821+ 2 -> 3
51822+ */
51823+ /* first check to see if we can already be reached via this slot */
51824+ tmp = *curr;
51825+ while (tmp && tmp != role)
51826+ tmp = tmp->next;
51827+ if (tmp == role) {
51828+ /* we don't need to add ourselves to this slot's chain */
51829+ return;
51830+ }
51831+ /* we need to add ourselves to this chain, two cases */
51832+ if (role->next == NULL) {
51833+ /* simple case, append the current chain to our role */
51834+ role->next = *curr;
51835+ *curr = role;
51836+ } else {
51837+ /* 1 -> 2 -> 3 -> 4
51838+ 2 -> 3 -> 4
51839+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
51840+ */
51841+ /* trickier case: walk our role's chain until we find
51842+ the role for the start of the current slot's chain */
51843+ tmp = role;
51844+ tmp2 = *curr;
51845+ while (tmp->next && tmp->next != tmp2)
51846+ tmp = tmp->next;
51847+ if (tmp->next == tmp2) {
51848+ /* from example above, we found 3, so just
51849+ replace this slot's chain with ours */
51850+ *curr = role;
51851+ } else {
51852+ /* we didn't find a subset of our role's chain
51853+ in the current slot's chain, so append their
51854+ chain to ours, and set us as the first role in
51855+ the slot's chain
51856+
51857+ we could fold this case with the case above,
51858+ but making it explicit for clarity
51859+ */
51860+ tmp->next = tmp2;
51861+ *curr = role;
51862+ }
51863+ }
51864+ }
51865+
51866+ return;
51867+}
51868+
51869+static void
51870+insert_acl_role_label(struct acl_role_label *role)
51871+{
51872+ int i;
51873+
51874+ if (role_list == NULL) {
51875+ role_list = role;
51876+ role->prev = NULL;
51877+ } else {
51878+ role->prev = role_list;
51879+ role_list = role;
51880+ }
51881+
51882+ /* used for hash chains */
51883+ role->next = NULL;
51884+
51885+ if (role->roletype & GR_ROLE_DOMAIN) {
51886+ for (i = 0; i < role->domain_child_num; i++)
51887+ __insert_acl_role_label(role, role->domain_children[i]);
51888+ } else
51889+ __insert_acl_role_label(role, role->uidgid);
51890+}
51891+
51892+static int
51893+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
51894+{
51895+ struct name_entry **curr, *nentry;
51896+ struct inodev_entry *ientry;
51897+ unsigned int len = strlen(name);
51898+ unsigned int key = full_name_hash(name, len);
51899+ unsigned int index = key % name_set.n_size;
51900+
51901+ curr = &name_set.n_hash[index];
51902+
51903+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
51904+ curr = &((*curr)->next);
51905+
51906+ if (*curr != NULL)
51907+ return 1;
51908+
51909+ nentry = acl_alloc(sizeof (struct name_entry));
51910+ if (nentry == NULL)
51911+ return 0;
51912+ ientry = acl_alloc(sizeof (struct inodev_entry));
51913+ if (ientry == NULL)
51914+ return 0;
51915+ ientry->nentry = nentry;
51916+
51917+ nentry->key = key;
51918+ nentry->name = name;
51919+ nentry->inode = inode;
51920+ nentry->device = device;
51921+ nentry->len = len;
51922+ nentry->deleted = deleted;
51923+
51924+ nentry->prev = NULL;
51925+ curr = &name_set.n_hash[index];
51926+ if (*curr != NULL)
51927+ (*curr)->prev = nentry;
51928+ nentry->next = *curr;
51929+ *curr = nentry;
51930+
51931+ /* insert us into the table searchable by inode/dev */
51932+ insert_inodev_entry(ientry);
51933+
51934+ return 1;
51935+}
51936+
51937+static void
51938+insert_acl_obj_label(struct acl_object_label *obj,
51939+ struct acl_subject_label *subj)
51940+{
51941+ unsigned int index =
51942+ fhash(obj->inode, obj->device, subj->obj_hash_size);
51943+ struct acl_object_label **curr;
51944+
51945+
51946+ obj->prev = NULL;
51947+
51948+ curr = &subj->obj_hash[index];
51949+ if (*curr != NULL)
51950+ (*curr)->prev = obj;
51951+
51952+ obj->next = *curr;
51953+ *curr = obj;
51954+
51955+ return;
51956+}
51957+
51958+static void
51959+insert_acl_subj_label(struct acl_subject_label *obj,
51960+ struct acl_role_label *role)
51961+{
51962+ unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
51963+ struct acl_subject_label **curr;
51964+
51965+ obj->prev = NULL;
51966+
51967+ curr = &role->subj_hash[index];
51968+ if (*curr != NULL)
51969+ (*curr)->prev = obj;
51970+
51971+ obj->next = *curr;
51972+ *curr = obj;
51973+
51974+ return;
51975+}
51976+
51977+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
51978+
51979+static void *
51980+create_table(__u32 * len, int elementsize)
51981+{
51982+ unsigned int table_sizes[] = {
51983+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
51984+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
51985+ 4194301, 8388593, 16777213, 33554393, 67108859
51986+ };
51987+ void *newtable = NULL;
51988+ unsigned int pwr = 0;
51989+
51990+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
51991+ table_sizes[pwr] <= *len)
51992+ pwr++;
51993+
51994+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
51995+ return newtable;
51996+
51997+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
51998+ newtable =
51999+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
52000+ else
52001+ newtable = vmalloc(table_sizes[pwr] * elementsize);
52002+
52003+ *len = table_sizes[pwr];
52004+
52005+ return newtable;
52006+}
52007+
52008+static int
52009+init_variables(const struct gr_arg *arg)
52010+{
52011+ struct task_struct *reaper = init_pid_ns.child_reaper;
52012+ unsigned int stacksize;
52013+
52014+ subj_map_set.s_size = arg->role_db.num_subjects;
52015+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
52016+ name_set.n_size = arg->role_db.num_objects;
52017+ inodev_set.i_size = arg->role_db.num_objects;
52018+
52019+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
52020+ !name_set.n_size || !inodev_set.i_size)
52021+ return 1;
52022+
52023+ if (!gr_init_uidset())
52024+ return 1;
52025+
52026+ /* set up the stack that holds allocation info */
52027+
52028+ stacksize = arg->role_db.num_pointers + 5;
52029+
52030+ if (!acl_alloc_stack_init(stacksize))
52031+ return 1;
52032+
52033+ /* grab reference for the real root dentry and vfsmount */
52034+ get_fs_root(reaper->fs, &real_root);
52035+
52036+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52037+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
52038+#endif
52039+
52040+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
52041+ if (fakefs_obj_rw == NULL)
52042+ return 1;
52043+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
52044+
52045+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
52046+ if (fakefs_obj_rwx == NULL)
52047+ return 1;
52048+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
52049+
52050+ subj_map_set.s_hash =
52051+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
52052+ acl_role_set.r_hash =
52053+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
52054+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
52055+ inodev_set.i_hash =
52056+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
52057+
52058+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
52059+ !name_set.n_hash || !inodev_set.i_hash)
52060+ return 1;
52061+
52062+ memset(subj_map_set.s_hash, 0,
52063+ sizeof(struct subject_map *) * subj_map_set.s_size);
52064+ memset(acl_role_set.r_hash, 0,
52065+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
52066+ memset(name_set.n_hash, 0,
52067+ sizeof (struct name_entry *) * name_set.n_size);
52068+ memset(inodev_set.i_hash, 0,
52069+ sizeof (struct inodev_entry *) * inodev_set.i_size);
52070+
52071+ return 0;
52072+}
52073+
52074+/* free information not needed after startup
52075+ currently contains user->kernel pointer mappings for subjects
52076+*/
52077+
52078+static void
52079+free_init_variables(void)
52080+{
52081+ __u32 i;
52082+
52083+ if (subj_map_set.s_hash) {
52084+ for (i = 0; i < subj_map_set.s_size; i++) {
52085+ if (subj_map_set.s_hash[i]) {
52086+ kfree(subj_map_set.s_hash[i]);
52087+ subj_map_set.s_hash[i] = NULL;
52088+ }
52089+ }
52090+
52091+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
52092+ PAGE_SIZE)
52093+ kfree(subj_map_set.s_hash);
52094+ else
52095+ vfree(subj_map_set.s_hash);
52096+ }
52097+
52098+ return;
52099+}
52100+
52101+static void
52102+free_variables(void)
52103+{
52104+ struct acl_subject_label *s;
52105+ struct acl_role_label *r;
52106+ struct task_struct *task, *task2;
52107+ unsigned int x;
52108+
52109+ gr_clear_learn_entries();
52110+
52111+ read_lock(&tasklist_lock);
52112+ do_each_thread(task2, task) {
52113+ task->acl_sp_role = 0;
52114+ task->acl_role_id = 0;
52115+ task->acl = NULL;
52116+ task->role = NULL;
52117+ } while_each_thread(task2, task);
52118+ read_unlock(&tasklist_lock);
52119+
52120+ /* release the reference to the real root dentry and vfsmount */
52121+ path_put(&real_root);
52122+ memset(&real_root, 0, sizeof(real_root));
52123+
52124+ /* free all object hash tables */
52125+
52126+ FOR_EACH_ROLE_START(r)
52127+ if (r->subj_hash == NULL)
52128+ goto next_role;
52129+ FOR_EACH_SUBJECT_START(r, s, x)
52130+ if (s->obj_hash == NULL)
52131+ break;
52132+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52133+ kfree(s->obj_hash);
52134+ else
52135+ vfree(s->obj_hash);
52136+ FOR_EACH_SUBJECT_END(s, x)
52137+ FOR_EACH_NESTED_SUBJECT_START(r, s)
52138+ if (s->obj_hash == NULL)
52139+ break;
52140+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52141+ kfree(s->obj_hash);
52142+ else
52143+ vfree(s->obj_hash);
52144+ FOR_EACH_NESTED_SUBJECT_END(s)
52145+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
52146+ kfree(r->subj_hash);
52147+ else
52148+ vfree(r->subj_hash);
52149+ r->subj_hash = NULL;
52150+next_role:
52151+ FOR_EACH_ROLE_END(r)
52152+
52153+ acl_free_all();
52154+
52155+ if (acl_role_set.r_hash) {
52156+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
52157+ PAGE_SIZE)
52158+ kfree(acl_role_set.r_hash);
52159+ else
52160+ vfree(acl_role_set.r_hash);
52161+ }
52162+ if (name_set.n_hash) {
52163+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
52164+ PAGE_SIZE)
52165+ kfree(name_set.n_hash);
52166+ else
52167+ vfree(name_set.n_hash);
52168+ }
52169+
52170+ if (inodev_set.i_hash) {
52171+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
52172+ PAGE_SIZE)
52173+ kfree(inodev_set.i_hash);
52174+ else
52175+ vfree(inodev_set.i_hash);
52176+ }
52177+
52178+ gr_free_uidset();
52179+
52180+ memset(&name_set, 0, sizeof (struct name_db));
52181+ memset(&inodev_set, 0, sizeof (struct inodev_db));
52182+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52183+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52184+
52185+ default_role = NULL;
52186+ kernel_role = NULL;
52187+ role_list = NULL;
52188+
52189+ return;
52190+}
52191+
52192+static __u32
52193+count_user_objs(struct acl_object_label *userp)
52194+{
52195+ struct acl_object_label o_tmp;
52196+ __u32 num = 0;
52197+
52198+ while (userp) {
52199+ if (copy_from_user(&o_tmp, userp,
52200+ sizeof (struct acl_object_label)))
52201+ break;
52202+
52203+ userp = o_tmp.prev;
52204+ num++;
52205+ }
52206+
52207+ return num;
52208+}
52209+
52210+static struct acl_subject_label *
52211+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
52212+
52213+static int
52214+copy_user_glob(struct acl_object_label *obj)
52215+{
52216+ struct acl_object_label *g_tmp, **guser;
52217+ unsigned int len;
52218+ char *tmp;
52219+
52220+ if (obj->globbed == NULL)
52221+ return 0;
52222+
52223+ guser = &obj->globbed;
52224+ while (*guser) {
52225+ g_tmp = (struct acl_object_label *)
52226+ acl_alloc(sizeof (struct acl_object_label));
52227+ if (g_tmp == NULL)
52228+ return -ENOMEM;
52229+
52230+ if (copy_from_user(g_tmp, *guser,
52231+ sizeof (struct acl_object_label)))
52232+ return -EFAULT;
52233+
52234+ len = strnlen_user(g_tmp->filename, PATH_MAX);
52235+
52236+ if (!len || len >= PATH_MAX)
52237+ return -EINVAL;
52238+
52239+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52240+ return -ENOMEM;
52241+
52242+ if (copy_from_user(tmp, g_tmp->filename, len))
52243+ return -EFAULT;
52244+ tmp[len-1] = '\0';
52245+ g_tmp->filename = tmp;
52246+
52247+ *guser = g_tmp;
52248+ guser = &(g_tmp->next);
52249+ }
52250+
52251+ return 0;
52252+}
52253+
52254+static int
52255+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52256+ struct acl_role_label *role)
52257+{
52258+ struct acl_object_label *o_tmp;
52259+ unsigned int len;
52260+ int ret;
52261+ char *tmp;
52262+
52263+ while (userp) {
52264+ if ((o_tmp = (struct acl_object_label *)
52265+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
52266+ return -ENOMEM;
52267+
52268+ if (copy_from_user(o_tmp, userp,
52269+ sizeof (struct acl_object_label)))
52270+ return -EFAULT;
52271+
52272+ userp = o_tmp->prev;
52273+
52274+ len = strnlen_user(o_tmp->filename, PATH_MAX);
52275+
52276+ if (!len || len >= PATH_MAX)
52277+ return -EINVAL;
52278+
52279+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52280+ return -ENOMEM;
52281+
52282+ if (copy_from_user(tmp, o_tmp->filename, len))
52283+ return -EFAULT;
52284+ tmp[len-1] = '\0';
52285+ o_tmp->filename = tmp;
52286+
52287+ insert_acl_obj_label(o_tmp, subj);
52288+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52289+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52290+ return -ENOMEM;
52291+
52292+ ret = copy_user_glob(o_tmp);
52293+ if (ret)
52294+ return ret;
52295+
52296+ if (o_tmp->nested) {
52297+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
52298+ if (IS_ERR(o_tmp->nested))
52299+ return PTR_ERR(o_tmp->nested);
52300+
52301+ /* insert into nested subject list */
52302+ o_tmp->nested->next = role->hash->first;
52303+ role->hash->first = o_tmp->nested;
52304+ }
52305+ }
52306+
52307+ return 0;
52308+}
52309+
52310+static __u32
52311+count_user_subjs(struct acl_subject_label *userp)
52312+{
52313+ struct acl_subject_label s_tmp;
52314+ __u32 num = 0;
52315+
52316+ while (userp) {
52317+ if (copy_from_user(&s_tmp, userp,
52318+ sizeof (struct acl_subject_label)))
52319+ break;
52320+
52321+ userp = s_tmp.prev;
52322+ /* do not count nested subjects against this count, since
52323+ they are not included in the hash table, but are
52324+ attached to objects. We have already counted
52325+ the subjects in userspace for the allocation
52326+ stack
52327+ */
52328+ if (!(s_tmp.mode & GR_NESTED))
52329+ num++;
52330+ }
52331+
52332+ return num;
52333+}
52334+
52335+static int
52336+copy_user_allowedips(struct acl_role_label *rolep)
52337+{
52338+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52339+
52340+ ruserip = rolep->allowed_ips;
52341+
52342+ while (ruserip) {
52343+ rlast = rtmp;
52344+
52345+ if ((rtmp = (struct role_allowed_ip *)
52346+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52347+ return -ENOMEM;
52348+
52349+ if (copy_from_user(rtmp, ruserip,
52350+ sizeof (struct role_allowed_ip)))
52351+ return -EFAULT;
52352+
52353+ ruserip = rtmp->prev;
52354+
52355+ if (!rlast) {
52356+ rtmp->prev = NULL;
52357+ rolep->allowed_ips = rtmp;
52358+ } else {
52359+ rlast->next = rtmp;
52360+ rtmp->prev = rlast;
52361+ }
52362+
52363+ if (!ruserip)
52364+ rtmp->next = NULL;
52365+ }
52366+
52367+ return 0;
52368+}
52369+
52370+static int
52371+copy_user_transitions(struct acl_role_label *rolep)
52372+{
52373+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
52374+
52375+ unsigned int len;
52376+ char *tmp;
52377+
52378+ rusertp = rolep->transitions;
52379+
52380+ while (rusertp) {
52381+ rlast = rtmp;
52382+
52383+ if ((rtmp = (struct role_transition *)
52384+ acl_alloc(sizeof (struct role_transition))) == NULL)
52385+ return -ENOMEM;
52386+
52387+ if (copy_from_user(rtmp, rusertp,
52388+ sizeof (struct role_transition)))
52389+ return -EFAULT;
52390+
52391+ rusertp = rtmp->prev;
52392+
52393+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52394+
52395+ if (!len || len >= GR_SPROLE_LEN)
52396+ return -EINVAL;
52397+
52398+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52399+ return -ENOMEM;
52400+
52401+ if (copy_from_user(tmp, rtmp->rolename, len))
52402+ return -EFAULT;
52403+ tmp[len-1] = '\0';
52404+ rtmp->rolename = tmp;
52405+
52406+ if (!rlast) {
52407+ rtmp->prev = NULL;
52408+ rolep->transitions = rtmp;
52409+ } else {
52410+ rlast->next = rtmp;
52411+ rtmp->prev = rlast;
52412+ }
52413+
52414+ if (!rusertp)
52415+ rtmp->next = NULL;
52416+ }
52417+
52418+ return 0;
52419+}
52420+
52421+static struct acl_subject_label *
52422+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
52423+{
52424+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
52425+ unsigned int len;
52426+ char *tmp;
52427+ __u32 num_objs;
52428+ struct acl_ip_label **i_tmp, *i_utmp2;
52429+ struct gr_hash_struct ghash;
52430+ struct subject_map *subjmap;
52431+ unsigned int i_num;
52432+ int err;
52433+
52434+ s_tmp = lookup_subject_map(userp);
52435+
52436+ /* we've already copied this subject into the kernel, just return
52437+ the reference to it, and don't copy it over again
52438+ */
52439+ if (s_tmp)
52440+ return(s_tmp);
52441+
52442+ if ((s_tmp = (struct acl_subject_label *)
52443+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
52444+ return ERR_PTR(-ENOMEM);
52445+
52446+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
52447+ if (subjmap == NULL)
52448+ return ERR_PTR(-ENOMEM);
52449+
52450+ subjmap->user = userp;
52451+ subjmap->kernel = s_tmp;
52452+ insert_subj_map_entry(subjmap);
52453+
52454+ if (copy_from_user(s_tmp, userp,
52455+ sizeof (struct acl_subject_label)))
52456+ return ERR_PTR(-EFAULT);
52457+
52458+ len = strnlen_user(s_tmp->filename, PATH_MAX);
52459+
52460+ if (!len || len >= PATH_MAX)
52461+ return ERR_PTR(-EINVAL);
52462+
52463+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52464+ return ERR_PTR(-ENOMEM);
52465+
52466+ if (copy_from_user(tmp, s_tmp->filename, len))
52467+ return ERR_PTR(-EFAULT);
52468+ tmp[len-1] = '\0';
52469+ s_tmp->filename = tmp;
52470+
52471+ if (!strcmp(s_tmp->filename, "/"))
52472+ role->root_label = s_tmp;
52473+
52474+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
52475+ return ERR_PTR(-EFAULT);
52476+
52477+ /* copy user and group transition tables */
52478+
52479+ if (s_tmp->user_trans_num) {
52480+ uid_t *uidlist;
52481+
52482+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
52483+ if (uidlist == NULL)
52484+ return ERR_PTR(-ENOMEM);
52485+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
52486+ return ERR_PTR(-EFAULT);
52487+
52488+ s_tmp->user_transitions = uidlist;
52489+ }
52490+
52491+ if (s_tmp->group_trans_num) {
52492+ gid_t *gidlist;
52493+
52494+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
52495+ if (gidlist == NULL)
52496+ return ERR_PTR(-ENOMEM);
52497+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
52498+ return ERR_PTR(-EFAULT);
52499+
52500+ s_tmp->group_transitions = gidlist;
52501+ }
52502+
52503+ /* set up object hash table */
52504+ num_objs = count_user_objs(ghash.first);
52505+
52506+ s_tmp->obj_hash_size = num_objs;
52507+ s_tmp->obj_hash =
52508+ (struct acl_object_label **)
52509+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
52510+
52511+ if (!s_tmp->obj_hash)
52512+ return ERR_PTR(-ENOMEM);
52513+
52514+ memset(s_tmp->obj_hash, 0,
52515+ s_tmp->obj_hash_size *
52516+ sizeof (struct acl_object_label *));
52517+
52518+ /* add in objects */
52519+ err = copy_user_objs(ghash.first, s_tmp, role);
52520+
52521+ if (err)
52522+ return ERR_PTR(err);
52523+
52524+ /* set pointer for parent subject */
52525+ if (s_tmp->parent_subject) {
52526+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
52527+
52528+ if (IS_ERR(s_tmp2))
52529+ return s_tmp2;
52530+
52531+ s_tmp->parent_subject = s_tmp2;
52532+ }
52533+
52534+ /* add in ip acls */
52535+
52536+ if (!s_tmp->ip_num) {
52537+ s_tmp->ips = NULL;
52538+ goto insert;
52539+ }
52540+
52541+ i_tmp =
52542+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
52543+ sizeof (struct acl_ip_label *));
52544+
52545+ if (!i_tmp)
52546+ return ERR_PTR(-ENOMEM);
52547+
52548+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
52549+ *(i_tmp + i_num) =
52550+ (struct acl_ip_label *)
52551+ acl_alloc(sizeof (struct acl_ip_label));
52552+ if (!*(i_tmp + i_num))
52553+ return ERR_PTR(-ENOMEM);
52554+
52555+ if (copy_from_user
52556+ (&i_utmp2, s_tmp->ips + i_num,
52557+ sizeof (struct acl_ip_label *)))
52558+ return ERR_PTR(-EFAULT);
52559+
52560+ if (copy_from_user
52561+ (*(i_tmp + i_num), i_utmp2,
52562+ sizeof (struct acl_ip_label)))
52563+ return ERR_PTR(-EFAULT);
52564+
52565+ if ((*(i_tmp + i_num))->iface == NULL)
52566+ continue;
52567+
52568+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
52569+ if (!len || len >= IFNAMSIZ)
52570+ return ERR_PTR(-EINVAL);
52571+ tmp = acl_alloc(len);
52572+ if (tmp == NULL)
52573+ return ERR_PTR(-ENOMEM);
52574+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
52575+ return ERR_PTR(-EFAULT);
52576+ (*(i_tmp + i_num))->iface = tmp;
52577+ }
52578+
52579+ s_tmp->ips = i_tmp;
52580+
52581+insert:
52582+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
52583+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
52584+ return ERR_PTR(-ENOMEM);
52585+
52586+ return s_tmp;
52587+}
52588+
52589+static int
52590+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
52591+{
52592+ struct acl_subject_label s_pre;
52593+ struct acl_subject_label * ret;
52594+ int err;
52595+
52596+ while (userp) {
52597+ if (copy_from_user(&s_pre, userp,
52598+ sizeof (struct acl_subject_label)))
52599+ return -EFAULT;
52600+
52601+ /* do not add nested subjects here, add
52602+ while parsing objects
52603+ */
52604+
52605+ if (s_pre.mode & GR_NESTED) {
52606+ userp = s_pre.prev;
52607+ continue;
52608+ }
52609+
52610+ ret = do_copy_user_subj(userp, role);
52611+
52612+ err = PTR_ERR(ret);
52613+ if (IS_ERR(ret))
52614+ return err;
52615+
52616+ insert_acl_subj_label(ret, role);
52617+
52618+ userp = s_pre.prev;
52619+ }
52620+
52621+ return 0;
52622+}
52623+
52624+static int
52625+copy_user_acl(struct gr_arg *arg)
52626+{
52627+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
52628+ struct sprole_pw *sptmp;
52629+ struct gr_hash_struct *ghash;
52630+ uid_t *domainlist;
52631+ unsigned int r_num;
52632+ unsigned int len;
52633+ char *tmp;
52634+ int err = 0;
52635+ __u16 i;
52636+ __u32 num_subjs;
52637+
52638+ /* we need a default and kernel role */
52639+ if (arg->role_db.num_roles < 2)
52640+ return -EINVAL;
52641+
52642+ /* copy special role authentication info from userspace */
52643+
52644+ num_sprole_pws = arg->num_sprole_pws;
52645+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
52646+
52647+ if (!acl_special_roles && num_sprole_pws)
52648+ return -ENOMEM;
52649+
52650+ for (i = 0; i < num_sprole_pws; i++) {
52651+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
52652+ if (!sptmp)
52653+ return -ENOMEM;
52654+ if (copy_from_user(sptmp, arg->sprole_pws + i,
52655+ sizeof (struct sprole_pw)))
52656+ return -EFAULT;
52657+
52658+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
52659+
52660+ if (!len || len >= GR_SPROLE_LEN)
52661+ return -EINVAL;
52662+
52663+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52664+ return -ENOMEM;
52665+
52666+ if (copy_from_user(tmp, sptmp->rolename, len))
52667+ return -EFAULT;
52668+
52669+ tmp[len-1] = '\0';
52670+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52671+ printk(KERN_ALERT "Copying special role %s\n", tmp);
52672+#endif
52673+ sptmp->rolename = tmp;
52674+ acl_special_roles[i] = sptmp;
52675+ }
52676+
52677+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
52678+
52679+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
52680+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
52681+
52682+ if (!r_tmp)
52683+ return -ENOMEM;
52684+
52685+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
52686+ sizeof (struct acl_role_label *)))
52687+ return -EFAULT;
52688+
52689+ if (copy_from_user(r_tmp, r_utmp2,
52690+ sizeof (struct acl_role_label)))
52691+ return -EFAULT;
52692+
52693+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
52694+
52695+ if (!len || len >= PATH_MAX)
52696+ return -EINVAL;
52697+
52698+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52699+ return -ENOMEM;
52700+
52701+ if (copy_from_user(tmp, r_tmp->rolename, len))
52702+ return -EFAULT;
52703+
52704+ tmp[len-1] = '\0';
52705+ r_tmp->rolename = tmp;
52706+
52707+ if (!strcmp(r_tmp->rolename, "default")
52708+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
52709+ default_role = r_tmp;
52710+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
52711+ kernel_role = r_tmp;
52712+ }
52713+
52714+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
52715+ return -ENOMEM;
52716+
52717+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
52718+ return -EFAULT;
52719+
52720+ r_tmp->hash = ghash;
52721+
52722+ num_subjs = count_user_subjs(r_tmp->hash->first);
52723+
52724+ r_tmp->subj_hash_size = num_subjs;
52725+ r_tmp->subj_hash =
52726+ (struct acl_subject_label **)
52727+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
52728+
52729+ if (!r_tmp->subj_hash)
52730+ return -ENOMEM;
52731+
52732+ err = copy_user_allowedips(r_tmp);
52733+ if (err)
52734+ return err;
52735+
52736+ /* copy domain info */
52737+ if (r_tmp->domain_children != NULL) {
52738+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
52739+ if (domainlist == NULL)
52740+ return -ENOMEM;
52741+
52742+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
52743+ return -EFAULT;
52744+
52745+ r_tmp->domain_children = domainlist;
52746+ }
52747+
52748+ err = copy_user_transitions(r_tmp);
52749+ if (err)
52750+ return err;
52751+
52752+ memset(r_tmp->subj_hash, 0,
52753+ r_tmp->subj_hash_size *
52754+ sizeof (struct acl_subject_label *));
52755+
52756+ err = copy_user_subjs(r_tmp->hash->first, r_tmp);
52757+
52758+ if (err)
52759+ return err;
52760+
52761+ /* set nested subject list to null */
52762+ r_tmp->hash->first = NULL;
52763+
52764+ insert_acl_role_label(r_tmp);
52765+ }
52766+
52767+ if (default_role == NULL || kernel_role == NULL)
52768+ return -EINVAL;
52769+
52770+ return err;
52771+}
52772+
52773+static int
52774+gracl_init(struct gr_arg *args)
52775+{
52776+ int error = 0;
52777+
52778+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
52779+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
52780+
52781+ if (init_variables(args)) {
52782+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
52783+ error = -ENOMEM;
52784+ free_variables();
52785+ goto out;
52786+ }
52787+
52788+ error = copy_user_acl(args);
52789+ free_init_variables();
52790+ if (error) {
52791+ free_variables();
52792+ goto out;
52793+ }
52794+
52795+ if ((error = gr_set_acls(0))) {
52796+ free_variables();
52797+ goto out;
52798+ }
52799+
52800+ pax_open_kernel();
52801+ gr_status |= GR_READY;
52802+ pax_close_kernel();
52803+
52804+ out:
52805+ return error;
52806+}
52807+
52808+/* derived from glibc fnmatch() 0: match, 1: no match*/
52809+
52810+static int
52811+glob_match(const char *p, const char *n)
52812+{
52813+ char c;
52814+
52815+ while ((c = *p++) != '\0') {
52816+ switch (c) {
52817+ case '?':
52818+ if (*n == '\0')
52819+ return 1;
52820+ else if (*n == '/')
52821+ return 1;
52822+ break;
52823+ case '\\':
52824+ if (*n != c)
52825+ return 1;
52826+ break;
52827+ case '*':
52828+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
52829+ if (*n == '/')
52830+ return 1;
52831+ else if (c == '?') {
52832+ if (*n == '\0')
52833+ return 1;
52834+ else
52835+ ++n;
52836+ }
52837+ }
52838+ if (c == '\0') {
52839+ return 0;
52840+ } else {
52841+ const char *endp;
52842+
52843+ if ((endp = strchr(n, '/')) == NULL)
52844+ endp = n + strlen(n);
52845+
52846+ if (c == '[') {
52847+ for (--p; n < endp; ++n)
52848+ if (!glob_match(p, n))
52849+ return 0;
52850+ } else if (c == '/') {
52851+ while (*n != '\0' && *n != '/')
52852+ ++n;
52853+ if (*n == '/' && !glob_match(p, n + 1))
52854+ return 0;
52855+ } else {
52856+ for (--p; n < endp; ++n)
52857+ if (*n == c && !glob_match(p, n))
52858+ return 0;
52859+ }
52860+
52861+ return 1;
52862+ }
52863+ case '[':
52864+ {
52865+ int not;
52866+ char cold;
52867+
52868+ if (*n == '\0' || *n == '/')
52869+ return 1;
52870+
52871+ not = (*p == '!' || *p == '^');
52872+ if (not)
52873+ ++p;
52874+
52875+ c = *p++;
52876+ for (;;) {
52877+ unsigned char fn = (unsigned char)*n;
52878+
52879+ if (c == '\0')
52880+ return 1;
52881+ else {
52882+ if (c == fn)
52883+ goto matched;
52884+ cold = c;
52885+ c = *p++;
52886+
52887+ if (c == '-' && *p != ']') {
52888+ unsigned char cend = *p++;
52889+
52890+ if (cend == '\0')
52891+ return 1;
52892+
52893+ if (cold <= fn && fn <= cend)
52894+ goto matched;
52895+
52896+ c = *p++;
52897+ }
52898+ }
52899+
52900+ if (c == ']')
52901+ break;
52902+ }
52903+ if (!not)
52904+ return 1;
52905+ break;
52906+ matched:
52907+ while (c != ']') {
52908+ if (c == '\0')
52909+ return 1;
52910+
52911+ c = *p++;
52912+ }
52913+ if (not)
52914+ return 1;
52915+ }
52916+ break;
52917+ default:
52918+ if (c != *n)
52919+ return 1;
52920+ }
52921+
52922+ ++n;
52923+ }
52924+
52925+ if (*n == '\0')
52926+ return 0;
52927+
52928+ if (*n == '/')
52929+ return 0;
52930+
52931+ return 1;
52932+}
52933+
52934+static struct acl_object_label *
52935+chk_glob_label(struct acl_object_label *globbed,
52936+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
52937+{
52938+ struct acl_object_label *tmp;
52939+
52940+ if (*path == NULL)
52941+ *path = gr_to_filename_nolock(dentry, mnt);
52942+
52943+ tmp = globbed;
52944+
52945+ while (tmp) {
52946+ if (!glob_match(tmp->filename, *path))
52947+ return tmp;
52948+ tmp = tmp->next;
52949+ }
52950+
52951+ return NULL;
52952+}
52953+
52954+static struct acl_object_label *
52955+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52956+ const ino_t curr_ino, const dev_t curr_dev,
52957+ const struct acl_subject_label *subj, char **path, const int checkglob)
52958+{
52959+ struct acl_subject_label *tmpsubj;
52960+ struct acl_object_label *retval;
52961+ struct acl_object_label *retval2;
52962+
52963+ tmpsubj = (struct acl_subject_label *) subj;
52964+ read_lock(&gr_inode_lock);
52965+ do {
52966+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
52967+ if (retval) {
52968+ if (checkglob && retval->globbed) {
52969+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
52970+ if (retval2)
52971+ retval = retval2;
52972+ }
52973+ break;
52974+ }
52975+ } while ((tmpsubj = tmpsubj->parent_subject));
52976+ read_unlock(&gr_inode_lock);
52977+
52978+ return retval;
52979+}
52980+
52981+static __inline__ struct acl_object_label *
52982+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52983+ struct dentry *curr_dentry,
52984+ const struct acl_subject_label *subj, char **path, const int checkglob)
52985+{
52986+ int newglob = checkglob;
52987+ ino_t inode;
52988+ dev_t device;
52989+
52990+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
52991+ as we don't want a / * rule to match instead of the / object
52992+ don't do this for create lookups that call this function though, since they're looking up
52993+ on the parent and thus need globbing checks on all paths
52994+ */
52995+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
52996+ newglob = GR_NO_GLOB;
52997+
52998+ spin_lock(&curr_dentry->d_lock);
52999+ inode = curr_dentry->d_inode->i_ino;
53000+ device = __get_dev(curr_dentry);
53001+ spin_unlock(&curr_dentry->d_lock);
53002+
53003+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
53004+}
53005+
53006+static struct acl_object_label *
53007+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53008+ const struct acl_subject_label *subj, char *path, const int checkglob)
53009+{
53010+ struct dentry *dentry = (struct dentry *) l_dentry;
53011+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53012+ struct mount *real_mnt = real_mount(mnt);
53013+ struct acl_object_label *retval;
53014+ struct dentry *parent;
53015+
53016+ write_seqlock(&rename_lock);
53017+ br_read_lock(&vfsmount_lock);
53018+
53019+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
53020+#ifdef CONFIG_NET
53021+ mnt == sock_mnt ||
53022+#endif
53023+#ifdef CONFIG_HUGETLBFS
53024+ (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
53025+#endif
53026+ /* ignore Eric Biederman */
53027+ IS_PRIVATE(l_dentry->d_inode))) {
53028+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
53029+ goto out;
53030+ }
53031+
53032+ for (;;) {
53033+ if (dentry == real_root.dentry && mnt == real_root.mnt)
53034+ break;
53035+
53036+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53037+ if (!mnt_has_parent(real_mnt))
53038+ break;
53039+
53040+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53041+ if (retval != NULL)
53042+ goto out;
53043+
53044+ dentry = real_mnt->mnt_mountpoint;
53045+ real_mnt = real_mnt->mnt_parent;
53046+ mnt = &real_mnt->mnt;
53047+ continue;
53048+ }
53049+
53050+ parent = dentry->d_parent;
53051+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53052+ if (retval != NULL)
53053+ goto out;
53054+
53055+ dentry = parent;
53056+ }
53057+
53058+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53059+
53060+ /* real_root is pinned so we don't have to hold a reference */
53061+ if (retval == NULL)
53062+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
53063+out:
53064+ br_read_unlock(&vfsmount_lock);
53065+ write_sequnlock(&rename_lock);
53066+
53067+ BUG_ON(retval == NULL);
53068+
53069+ return retval;
53070+}
53071+
53072+static __inline__ struct acl_object_label *
53073+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53074+ const struct acl_subject_label *subj)
53075+{
53076+ char *path = NULL;
53077+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
53078+}
53079+
53080+static __inline__ struct acl_object_label *
53081+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53082+ const struct acl_subject_label *subj)
53083+{
53084+ char *path = NULL;
53085+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
53086+}
53087+
53088+static __inline__ struct acl_object_label *
53089+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53090+ const struct acl_subject_label *subj, char *path)
53091+{
53092+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
53093+}
53094+
53095+static struct acl_subject_label *
53096+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53097+ const struct acl_role_label *role)
53098+{
53099+ struct dentry *dentry = (struct dentry *) l_dentry;
53100+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53101+ struct mount *real_mnt = real_mount(mnt);
53102+ struct acl_subject_label *retval;
53103+ struct dentry *parent;
53104+
53105+ write_seqlock(&rename_lock);
53106+ br_read_lock(&vfsmount_lock);
53107+
53108+ for (;;) {
53109+ if (dentry == real_root.dentry && mnt == real_root.mnt)
53110+ break;
53111+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53112+ if (!mnt_has_parent(real_mnt))
53113+ break;
53114+
53115+ spin_lock(&dentry->d_lock);
53116+ read_lock(&gr_inode_lock);
53117+ retval =
53118+ lookup_acl_subj_label(dentry->d_inode->i_ino,
53119+ __get_dev(dentry), role);
53120+ read_unlock(&gr_inode_lock);
53121+ spin_unlock(&dentry->d_lock);
53122+ if (retval != NULL)
53123+ goto out;
53124+
53125+ dentry = real_mnt->mnt_mountpoint;
53126+ real_mnt = real_mnt->mnt_parent;
53127+ mnt = &real_mnt->mnt;
53128+ continue;
53129+ }
53130+
53131+ spin_lock(&dentry->d_lock);
53132+ read_lock(&gr_inode_lock);
53133+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53134+ __get_dev(dentry), role);
53135+ read_unlock(&gr_inode_lock);
53136+ parent = dentry->d_parent;
53137+ spin_unlock(&dentry->d_lock);
53138+
53139+ if (retval != NULL)
53140+ goto out;
53141+
53142+ dentry = parent;
53143+ }
53144+
53145+ spin_lock(&dentry->d_lock);
53146+ read_lock(&gr_inode_lock);
53147+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53148+ __get_dev(dentry), role);
53149+ read_unlock(&gr_inode_lock);
53150+ spin_unlock(&dentry->d_lock);
53151+
53152+ if (unlikely(retval == NULL)) {
53153+ /* real_root is pinned, we don't need to hold a reference */
53154+ read_lock(&gr_inode_lock);
53155+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
53156+ __get_dev(real_root.dentry), role);
53157+ read_unlock(&gr_inode_lock);
53158+ }
53159+out:
53160+ br_read_unlock(&vfsmount_lock);
53161+ write_sequnlock(&rename_lock);
53162+
53163+ BUG_ON(retval == NULL);
53164+
53165+ return retval;
53166+}
53167+
53168+static void
53169+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
53170+{
53171+ struct task_struct *task = current;
53172+ const struct cred *cred = current_cred();
53173+
53174+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53175+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53176+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53177+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53178+
53179+ return;
53180+}
53181+
53182+static void
53183+gr_log_learn_id_change(const char type, const unsigned int real,
53184+ const unsigned int effective, const unsigned int fs)
53185+{
53186+ struct task_struct *task = current;
53187+ const struct cred *cred = current_cred();
53188+
53189+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53190+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53191+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53192+ type, real, effective, fs, &task->signal->saved_ip);
53193+
53194+ return;
53195+}
53196+
53197+__u32
53198+gr_search_file(const struct dentry * dentry, const __u32 mode,
53199+ const struct vfsmount * mnt)
53200+{
53201+ __u32 retval = mode;
53202+ struct acl_subject_label *curracl;
53203+ struct acl_object_label *currobj;
53204+
53205+ if (unlikely(!(gr_status & GR_READY)))
53206+ return (mode & ~GR_AUDITS);
53207+
53208+ curracl = current->acl;
53209+
53210+ currobj = chk_obj_label(dentry, mnt, curracl);
53211+ retval = currobj->mode & mode;
53212+
53213+ /* if we're opening a specified transfer file for writing
53214+ (e.g. /dev/initctl), then transfer our role to init
53215+ */
53216+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53217+ current->role->roletype & GR_ROLE_PERSIST)) {
53218+ struct task_struct *task = init_pid_ns.child_reaper;
53219+
53220+ if (task->role != current->role) {
53221+ task->acl_sp_role = 0;
53222+ task->acl_role_id = current->acl_role_id;
53223+ task->role = current->role;
53224+ rcu_read_lock();
53225+ read_lock(&grsec_exec_file_lock);
53226+ gr_apply_subject_to_task(task);
53227+ read_unlock(&grsec_exec_file_lock);
53228+ rcu_read_unlock();
53229+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53230+ }
53231+ }
53232+
53233+ if (unlikely
53234+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53235+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53236+ __u32 new_mode = mode;
53237+
53238+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53239+
53240+ retval = new_mode;
53241+
53242+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53243+ new_mode |= GR_INHERIT;
53244+
53245+ if (!(mode & GR_NOLEARN))
53246+ gr_log_learn(dentry, mnt, new_mode);
53247+ }
53248+
53249+ return retval;
53250+}
53251+
53252+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
53253+ const struct dentry *parent,
53254+ const struct vfsmount *mnt)
53255+{
53256+ struct name_entry *match;
53257+ struct acl_object_label *matchpo;
53258+ struct acl_subject_label *curracl;
53259+ char *path;
53260+
53261+ if (unlikely(!(gr_status & GR_READY)))
53262+ return NULL;
53263+
53264+ preempt_disable();
53265+ path = gr_to_filename_rbac(new_dentry, mnt);
53266+ match = lookup_name_entry_create(path);
53267+
53268+ curracl = current->acl;
53269+
53270+ if (match) {
53271+ read_lock(&gr_inode_lock);
53272+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53273+ read_unlock(&gr_inode_lock);
53274+
53275+ if (matchpo) {
53276+ preempt_enable();
53277+ return matchpo;
53278+ }
53279+ }
53280+
53281+ // lookup parent
53282+
53283+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53284+
53285+ preempt_enable();
53286+ return matchpo;
53287+}
53288+
53289+__u32
53290+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53291+ const struct vfsmount * mnt, const __u32 mode)
53292+{
53293+ struct acl_object_label *matchpo;
53294+ __u32 retval;
53295+
53296+ if (unlikely(!(gr_status & GR_READY)))
53297+ return (mode & ~GR_AUDITS);
53298+
53299+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
53300+
53301+ retval = matchpo->mode & mode;
53302+
53303+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53304+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53305+ __u32 new_mode = mode;
53306+
53307+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53308+
53309+ gr_log_learn(new_dentry, mnt, new_mode);
53310+ return new_mode;
53311+ }
53312+
53313+ return retval;
53314+}
53315+
53316+__u32
53317+gr_check_link(const struct dentry * new_dentry,
53318+ const struct dentry * parent_dentry,
53319+ const struct vfsmount * parent_mnt,
53320+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53321+{
53322+ struct acl_object_label *obj;
53323+ __u32 oldmode, newmode;
53324+ __u32 needmode;
53325+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
53326+ GR_DELETE | GR_INHERIT;
53327+
53328+ if (unlikely(!(gr_status & GR_READY)))
53329+ return (GR_CREATE | GR_LINK);
53330+
53331+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53332+ oldmode = obj->mode;
53333+
53334+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
53335+ newmode = obj->mode;
53336+
53337+ needmode = newmode & checkmodes;
53338+
53339+ // old name for hardlink must have at least the permissions of the new name
53340+ if ((oldmode & needmode) != needmode)
53341+ goto bad;
53342+
53343+ // if old name had restrictions/auditing, make sure the new name does as well
53344+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53345+
53346+ // don't allow hardlinking of suid/sgid/fcapped files without permission
53347+ if (is_privileged_binary(old_dentry))
53348+ needmode |= GR_SETID;
53349+
53350+ if ((newmode & needmode) != needmode)
53351+ goto bad;
53352+
53353+ // enforce minimum permissions
53354+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53355+ return newmode;
53356+bad:
53357+ needmode = oldmode;
53358+ if (is_privileged_binary(old_dentry))
53359+ needmode |= GR_SETID;
53360+
53361+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53362+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
53363+ return (GR_CREATE | GR_LINK);
53364+ } else if (newmode & GR_SUPPRESS)
53365+ return GR_SUPPRESS;
53366+ else
53367+ return 0;
53368+}
53369+
53370+int
53371+gr_check_hidden_task(const struct task_struct *task)
53372+{
53373+ if (unlikely(!(gr_status & GR_READY)))
53374+ return 0;
53375+
53376+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53377+ return 1;
53378+
53379+ return 0;
53380+}
53381+
53382+int
53383+gr_check_protected_task(const struct task_struct *task)
53384+{
53385+ if (unlikely(!(gr_status & GR_READY) || !task))
53386+ return 0;
53387+
53388+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53389+ task->acl != current->acl)
53390+ return 1;
53391+
53392+ return 0;
53393+}
53394+
53395+int
53396+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53397+{
53398+ struct task_struct *p;
53399+ int ret = 0;
53400+
53401+ if (unlikely(!(gr_status & GR_READY) || !pid))
53402+ return ret;
53403+
53404+ read_lock(&tasklist_lock);
53405+ do_each_pid_task(pid, type, p) {
53406+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53407+ p->acl != current->acl) {
53408+ ret = 1;
53409+ goto out;
53410+ }
53411+ } while_each_pid_task(pid, type, p);
53412+out:
53413+ read_unlock(&tasklist_lock);
53414+
53415+ return ret;
53416+}
53417+
53418+void
53419+gr_copy_label(struct task_struct *tsk)
53420+{
53421+ tsk->signal->used_accept = 0;
53422+ tsk->acl_sp_role = 0;
53423+ tsk->acl_role_id = current->acl_role_id;
53424+ tsk->acl = current->acl;
53425+ tsk->role = current->role;
53426+ tsk->signal->curr_ip = current->signal->curr_ip;
53427+ tsk->signal->saved_ip = current->signal->saved_ip;
53428+ if (current->exec_file)
53429+ get_file(current->exec_file);
53430+ tsk->exec_file = current->exec_file;
53431+ tsk->is_writable = current->is_writable;
53432+ if (unlikely(current->signal->used_accept)) {
53433+ current->signal->curr_ip = 0;
53434+ current->signal->saved_ip = 0;
53435+ }
53436+
53437+ return;
53438+}
53439+
53440+static void
53441+gr_set_proc_res(struct task_struct *task)
53442+{
53443+ struct acl_subject_label *proc;
53444+ unsigned short i;
53445+
53446+ proc = task->acl;
53447+
53448+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
53449+ return;
53450+
53451+ for (i = 0; i < RLIM_NLIMITS; i++) {
53452+ if (!(proc->resmask & (1 << i)))
53453+ continue;
53454+
53455+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
53456+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
53457+ }
53458+
53459+ return;
53460+}
53461+
53462+extern int __gr_process_user_ban(struct user_struct *user);
53463+
53464+int
53465+gr_check_user_change(int real, int effective, int fs)
53466+{
53467+ unsigned int i;
53468+ __u16 num;
53469+ uid_t *uidlist;
53470+ int curuid;
53471+ int realok = 0;
53472+ int effectiveok = 0;
53473+ int fsok = 0;
53474+
53475+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
53476+ struct user_struct *user;
53477+
53478+ if (real == -1)
53479+ goto skipit;
53480+
53481+ user = find_user(real);
53482+ if (user == NULL)
53483+ goto skipit;
53484+
53485+ if (__gr_process_user_ban(user)) {
53486+ /* for find_user */
53487+ free_uid(user);
53488+ return 1;
53489+ }
53490+
53491+ /* for find_user */
53492+ free_uid(user);
53493+
53494+skipit:
53495+#endif
53496+
53497+ if (unlikely(!(gr_status & GR_READY)))
53498+ return 0;
53499+
53500+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53501+ gr_log_learn_id_change('u', real, effective, fs);
53502+
53503+ num = current->acl->user_trans_num;
53504+ uidlist = current->acl->user_transitions;
53505+
53506+ if (uidlist == NULL)
53507+ return 0;
53508+
53509+ if (real == -1)
53510+ realok = 1;
53511+ if (effective == -1)
53512+ effectiveok = 1;
53513+ if (fs == -1)
53514+ fsok = 1;
53515+
53516+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
53517+ for (i = 0; i < num; i++) {
53518+ curuid = (int)uidlist[i];
53519+ if (real == curuid)
53520+ realok = 1;
53521+ if (effective == curuid)
53522+ effectiveok = 1;
53523+ if (fs == curuid)
53524+ fsok = 1;
53525+ }
53526+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
53527+ for (i = 0; i < num; i++) {
53528+ curuid = (int)uidlist[i];
53529+ if (real == curuid)
53530+ break;
53531+ if (effective == curuid)
53532+ break;
53533+ if (fs == curuid)
53534+ break;
53535+ }
53536+ /* not in deny list */
53537+ if (i == num) {
53538+ realok = 1;
53539+ effectiveok = 1;
53540+ fsok = 1;
53541+ }
53542+ }
53543+
53544+ if (realok && effectiveok && fsok)
53545+ return 0;
53546+ else {
53547+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53548+ return 1;
53549+ }
53550+}
53551+
53552+int
53553+gr_check_group_change(int real, int effective, int fs)
53554+{
53555+ unsigned int i;
53556+ __u16 num;
53557+ gid_t *gidlist;
53558+ int curgid;
53559+ int realok = 0;
53560+ int effectiveok = 0;
53561+ int fsok = 0;
53562+
53563+ if (unlikely(!(gr_status & GR_READY)))
53564+ return 0;
53565+
53566+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53567+ gr_log_learn_id_change('g', real, effective, fs);
53568+
53569+ num = current->acl->group_trans_num;
53570+ gidlist = current->acl->group_transitions;
53571+
53572+ if (gidlist == NULL)
53573+ return 0;
53574+
53575+ if (real == -1)
53576+ realok = 1;
53577+ if (effective == -1)
53578+ effectiveok = 1;
53579+ if (fs == -1)
53580+ fsok = 1;
53581+
53582+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
53583+ for (i = 0; i < num; i++) {
53584+ curgid = (int)gidlist[i];
53585+ if (real == curgid)
53586+ realok = 1;
53587+ if (effective == curgid)
53588+ effectiveok = 1;
53589+ if (fs == curgid)
53590+ fsok = 1;
53591+ }
53592+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
53593+ for (i = 0; i < num; i++) {
53594+ curgid = (int)gidlist[i];
53595+ if (real == curgid)
53596+ break;
53597+ if (effective == curgid)
53598+ break;
53599+ if (fs == curgid)
53600+ break;
53601+ }
53602+ /* not in deny list */
53603+ if (i == num) {
53604+ realok = 1;
53605+ effectiveok = 1;
53606+ fsok = 1;
53607+ }
53608+ }
53609+
53610+ if (realok && effectiveok && fsok)
53611+ return 0;
53612+ else {
53613+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53614+ return 1;
53615+ }
53616+}
53617+
53618+extern int gr_acl_is_capable(const int cap);
53619+
53620+void
53621+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
53622+{
53623+ struct acl_role_label *role = task->role;
53624+ struct acl_subject_label *subj = NULL;
53625+ struct acl_object_label *obj;
53626+ struct file *filp;
53627+
53628+ if (unlikely(!(gr_status & GR_READY)))
53629+ return;
53630+
53631+ filp = task->exec_file;
53632+
53633+ /* kernel process, we'll give them the kernel role */
53634+ if (unlikely(!filp)) {
53635+ task->role = kernel_role;
53636+ task->acl = kernel_role->root_label;
53637+ return;
53638+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
53639+ role = lookup_acl_role_label(task, uid, gid);
53640+
53641+ /* don't change the role if we're not a privileged process */
53642+ if (role && task->role != role &&
53643+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
53644+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
53645+ return;
53646+
53647+ /* perform subject lookup in possibly new role
53648+ we can use this result below in the case where role == task->role
53649+ */
53650+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
53651+
53652+ /* if we changed uid/gid, but result in the same role
53653+ and are using inheritance, don't lose the inherited subject
53654+ if current subject is other than what normal lookup
53655+ would result in, we arrived via inheritance, don't
53656+ lose subject
53657+ */
53658+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
53659+ (subj == task->acl)))
53660+ task->acl = subj;
53661+
53662+ task->role = role;
53663+
53664+ task->is_writable = 0;
53665+
53666+ /* ignore additional mmap checks for processes that are writable
53667+ by the default ACL */
53668+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53669+ if (unlikely(obj->mode & GR_WRITE))
53670+ task->is_writable = 1;
53671+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53672+ if (unlikely(obj->mode & GR_WRITE))
53673+ task->is_writable = 1;
53674+
53675+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53676+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53677+#endif
53678+
53679+ gr_set_proc_res(task);
53680+
53681+ return;
53682+}
53683+
53684+int
53685+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
53686+ const int unsafe_flags)
53687+{
53688+ struct task_struct *task = current;
53689+ struct acl_subject_label *newacl;
53690+ struct acl_object_label *obj;
53691+ __u32 retmode;
53692+
53693+ if (unlikely(!(gr_status & GR_READY)))
53694+ return 0;
53695+
53696+ newacl = chk_subj_label(dentry, mnt, task->role);
53697+
53698+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
53699+ did an exec
53700+ */
53701+ rcu_read_lock();
53702+ read_lock(&tasklist_lock);
53703+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
53704+ (task->parent->acl->mode & GR_POVERRIDE))) {
53705+ read_unlock(&tasklist_lock);
53706+ rcu_read_unlock();
53707+ goto skip_check;
53708+ }
53709+ read_unlock(&tasklist_lock);
53710+ rcu_read_unlock();
53711+
53712+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
53713+ !(task->role->roletype & GR_ROLE_GOD) &&
53714+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
53715+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53716+ if (unsafe_flags & LSM_UNSAFE_SHARE)
53717+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
53718+ else
53719+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
53720+ return -EACCES;
53721+ }
53722+
53723+skip_check:
53724+
53725+ obj = chk_obj_label(dentry, mnt, task->acl);
53726+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
53727+
53728+ if (!(task->acl->mode & GR_INHERITLEARN) &&
53729+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
53730+ if (obj->nested)
53731+ task->acl = obj->nested;
53732+ else
53733+ task->acl = newacl;
53734+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
53735+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
53736+
53737+ task->is_writable = 0;
53738+
53739+ /* ignore additional mmap checks for processes that are writable
53740+ by the default ACL */
53741+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
53742+ if (unlikely(obj->mode & GR_WRITE))
53743+ task->is_writable = 1;
53744+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
53745+ if (unlikely(obj->mode & GR_WRITE))
53746+ task->is_writable = 1;
53747+
53748+ gr_set_proc_res(task);
53749+
53750+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53751+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53752+#endif
53753+ return 0;
53754+}
53755+
53756+/* always called with valid inodev ptr */
53757+static void
53758+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
53759+{
53760+ struct acl_object_label *matchpo;
53761+ struct acl_subject_label *matchps;
53762+ struct acl_subject_label *subj;
53763+ struct acl_role_label *role;
53764+ unsigned int x;
53765+
53766+ FOR_EACH_ROLE_START(role)
53767+ FOR_EACH_SUBJECT_START(role, subj, x)
53768+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
53769+ matchpo->mode |= GR_DELETED;
53770+ FOR_EACH_SUBJECT_END(subj,x)
53771+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
53772+ if (subj->inode == ino && subj->device == dev)
53773+ subj->mode |= GR_DELETED;
53774+ FOR_EACH_NESTED_SUBJECT_END(subj)
53775+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
53776+ matchps->mode |= GR_DELETED;
53777+ FOR_EACH_ROLE_END(role)
53778+
53779+ inodev->nentry->deleted = 1;
53780+
53781+ return;
53782+}
53783+
53784+void
53785+gr_handle_delete(const ino_t ino, const dev_t dev)
53786+{
53787+ struct inodev_entry *inodev;
53788+
53789+ if (unlikely(!(gr_status & GR_READY)))
53790+ return;
53791+
53792+ write_lock(&gr_inode_lock);
53793+ inodev = lookup_inodev_entry(ino, dev);
53794+ if (inodev != NULL)
53795+ do_handle_delete(inodev, ino, dev);
53796+ write_unlock(&gr_inode_lock);
53797+
53798+ return;
53799+}
53800+
53801+static void
53802+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
53803+ const ino_t newinode, const dev_t newdevice,
53804+ struct acl_subject_label *subj)
53805+{
53806+ unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
53807+ struct acl_object_label *match;
53808+
53809+ match = subj->obj_hash[index];
53810+
53811+ while (match && (match->inode != oldinode ||
53812+ match->device != olddevice ||
53813+ !(match->mode & GR_DELETED)))
53814+ match = match->next;
53815+
53816+ if (match && (match->inode == oldinode)
53817+ && (match->device == olddevice)
53818+ && (match->mode & GR_DELETED)) {
53819+ if (match->prev == NULL) {
53820+ subj->obj_hash[index] = match->next;
53821+ if (match->next != NULL)
53822+ match->next->prev = NULL;
53823+ } else {
53824+ match->prev->next = match->next;
53825+ if (match->next != NULL)
53826+ match->next->prev = match->prev;
53827+ }
53828+ match->prev = NULL;
53829+ match->next = NULL;
53830+ match->inode = newinode;
53831+ match->device = newdevice;
53832+ match->mode &= ~GR_DELETED;
53833+
53834+ insert_acl_obj_label(match, subj);
53835+ }
53836+
53837+ return;
53838+}
53839+
53840+static void
53841+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
53842+ const ino_t newinode, const dev_t newdevice,
53843+ struct acl_role_label *role)
53844+{
53845+ unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
53846+ struct acl_subject_label *match;
53847+
53848+ match = role->subj_hash[index];
53849+
53850+ while (match && (match->inode != oldinode ||
53851+ match->device != olddevice ||
53852+ !(match->mode & GR_DELETED)))
53853+ match = match->next;
53854+
53855+ if (match && (match->inode == oldinode)
53856+ && (match->device == olddevice)
53857+ && (match->mode & GR_DELETED)) {
53858+ if (match->prev == NULL) {
53859+ role->subj_hash[index] = match->next;
53860+ if (match->next != NULL)
53861+ match->next->prev = NULL;
53862+ } else {
53863+ match->prev->next = match->next;
53864+ if (match->next != NULL)
53865+ match->next->prev = match->prev;
53866+ }
53867+ match->prev = NULL;
53868+ match->next = NULL;
53869+ match->inode = newinode;
53870+ match->device = newdevice;
53871+ match->mode &= ~GR_DELETED;
53872+
53873+ insert_acl_subj_label(match, role);
53874+ }
53875+
53876+ return;
53877+}
53878+
53879+static void
53880+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
53881+ const ino_t newinode, const dev_t newdevice)
53882+{
53883+ unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
53884+ struct inodev_entry *match;
53885+
53886+ match = inodev_set.i_hash[index];
53887+
53888+ while (match && (match->nentry->inode != oldinode ||
53889+ match->nentry->device != olddevice || !match->nentry->deleted))
53890+ match = match->next;
53891+
53892+ if (match && (match->nentry->inode == oldinode)
53893+ && (match->nentry->device == olddevice) &&
53894+ match->nentry->deleted) {
53895+ if (match->prev == NULL) {
53896+ inodev_set.i_hash[index] = match->next;
53897+ if (match->next != NULL)
53898+ match->next->prev = NULL;
53899+ } else {
53900+ match->prev->next = match->next;
53901+ if (match->next != NULL)
53902+ match->next->prev = match->prev;
53903+ }
53904+ match->prev = NULL;
53905+ match->next = NULL;
53906+ match->nentry->inode = newinode;
53907+ match->nentry->device = newdevice;
53908+ match->nentry->deleted = 0;
53909+
53910+ insert_inodev_entry(match);
53911+ }
53912+
53913+ return;
53914+}
53915+
53916+static void
53917+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
53918+{
53919+ struct acl_subject_label *subj;
53920+ struct acl_role_label *role;
53921+ unsigned int x;
53922+
53923+ FOR_EACH_ROLE_START(role)
53924+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
53925+
53926+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
53927+ if ((subj->inode == ino) && (subj->device == dev)) {
53928+ subj->inode = ino;
53929+ subj->device = dev;
53930+ }
53931+ FOR_EACH_NESTED_SUBJECT_END(subj)
53932+ FOR_EACH_SUBJECT_START(role, subj, x)
53933+ update_acl_obj_label(matchn->inode, matchn->device,
53934+ ino, dev, subj);
53935+ FOR_EACH_SUBJECT_END(subj,x)
53936+ FOR_EACH_ROLE_END(role)
53937+
53938+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
53939+
53940+ return;
53941+}
53942+
53943+static void
53944+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
53945+ const struct vfsmount *mnt)
53946+{
53947+ ino_t ino = dentry->d_inode->i_ino;
53948+ dev_t dev = __get_dev(dentry);
53949+
53950+ __do_handle_create(matchn, ino, dev);
53951+
53952+ return;
53953+}
53954+
53955+void
53956+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
53957+{
53958+ struct name_entry *matchn;
53959+
53960+ if (unlikely(!(gr_status & GR_READY)))
53961+ return;
53962+
53963+ preempt_disable();
53964+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
53965+
53966+ if (unlikely((unsigned long)matchn)) {
53967+ write_lock(&gr_inode_lock);
53968+ do_handle_create(matchn, dentry, mnt);
53969+ write_unlock(&gr_inode_lock);
53970+ }
53971+ preempt_enable();
53972+
53973+ return;
53974+}
53975+
53976+void
53977+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
53978+{
53979+ struct name_entry *matchn;
53980+
53981+ if (unlikely(!(gr_status & GR_READY)))
53982+ return;
53983+
53984+ preempt_disable();
53985+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
53986+
53987+ if (unlikely((unsigned long)matchn)) {
53988+ write_lock(&gr_inode_lock);
53989+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
53990+ write_unlock(&gr_inode_lock);
53991+ }
53992+ preempt_enable();
53993+
53994+ return;
53995+}
53996+
53997+void
53998+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
53999+ struct dentry *old_dentry,
54000+ struct dentry *new_dentry,
54001+ struct vfsmount *mnt, const __u8 replace)
54002+{
54003+ struct name_entry *matchn;
54004+ struct inodev_entry *inodev;
54005+ struct inode *inode = new_dentry->d_inode;
54006+ ino_t old_ino = old_dentry->d_inode->i_ino;
54007+ dev_t old_dev = __get_dev(old_dentry);
54008+
54009+ /* vfs_rename swaps the name and parent link for old_dentry and
54010+ new_dentry
54011+ at this point, old_dentry has the new name, parent link, and inode
54012+ for the renamed file
54013+ if a file is being replaced by a rename, new_dentry has the inode
54014+ and name for the replaced file
54015+ */
54016+
54017+ if (unlikely(!(gr_status & GR_READY)))
54018+ return;
54019+
54020+ preempt_disable();
54021+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
54022+
54023+ /* we wouldn't have to check d_inode if it weren't for
54024+ NFS silly-renaming
54025+ */
54026+
54027+ write_lock(&gr_inode_lock);
54028+ if (unlikely(replace && inode)) {
54029+ ino_t new_ino = inode->i_ino;
54030+ dev_t new_dev = __get_dev(new_dentry);
54031+
54032+ inodev = lookup_inodev_entry(new_ino, new_dev);
54033+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
54034+ do_handle_delete(inodev, new_ino, new_dev);
54035+ }
54036+
54037+ inodev = lookup_inodev_entry(old_ino, old_dev);
54038+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
54039+ do_handle_delete(inodev, old_ino, old_dev);
54040+
54041+ if (unlikely((unsigned long)matchn))
54042+ do_handle_create(matchn, old_dentry, mnt);
54043+
54044+ write_unlock(&gr_inode_lock);
54045+ preempt_enable();
54046+
54047+ return;
54048+}
54049+
54050+static int
54051+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
54052+ unsigned char **sum)
54053+{
54054+ struct acl_role_label *r;
54055+ struct role_allowed_ip *ipp;
54056+ struct role_transition *trans;
54057+ unsigned int i;
54058+ int found = 0;
54059+ u32 curr_ip = current->signal->curr_ip;
54060+
54061+ current->signal->saved_ip = curr_ip;
54062+
54063+ /* check transition table */
54064+
54065+ for (trans = current->role->transitions; trans; trans = trans->next) {
54066+ if (!strcmp(rolename, trans->rolename)) {
54067+ found = 1;
54068+ break;
54069+ }
54070+ }
54071+
54072+ if (!found)
54073+ return 0;
54074+
54075+ /* handle special roles that do not require authentication
54076+ and check ip */
54077+
54078+ FOR_EACH_ROLE_START(r)
54079+ if (!strcmp(rolename, r->rolename) &&
54080+ (r->roletype & GR_ROLE_SPECIAL)) {
54081+ found = 0;
54082+ if (r->allowed_ips != NULL) {
54083+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
54084+ if ((ntohl(curr_ip) & ipp->netmask) ==
54085+ (ntohl(ipp->addr) & ipp->netmask))
54086+ found = 1;
54087+ }
54088+ } else
54089+ found = 2;
54090+ if (!found)
54091+ return 0;
54092+
54093+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
54094+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
54095+ *salt = NULL;
54096+ *sum = NULL;
54097+ return 1;
54098+ }
54099+ }
54100+ FOR_EACH_ROLE_END(r)
54101+
54102+ for (i = 0; i < num_sprole_pws; i++) {
54103+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
54104+ *salt = acl_special_roles[i]->salt;
54105+ *sum = acl_special_roles[i]->sum;
54106+ return 1;
54107+ }
54108+ }
54109+
54110+ return 0;
54111+}
54112+
54113+static void
54114+assign_special_role(char *rolename)
54115+{
54116+ struct acl_object_label *obj;
54117+ struct acl_role_label *r;
54118+ struct acl_role_label *assigned = NULL;
54119+ struct task_struct *tsk;
54120+ struct file *filp;
54121+
54122+ FOR_EACH_ROLE_START(r)
54123+ if (!strcmp(rolename, r->rolename) &&
54124+ (r->roletype & GR_ROLE_SPECIAL)) {
54125+ assigned = r;
54126+ break;
54127+ }
54128+ FOR_EACH_ROLE_END(r)
54129+
54130+ if (!assigned)
54131+ return;
54132+
54133+ read_lock(&tasklist_lock);
54134+ read_lock(&grsec_exec_file_lock);
54135+
54136+ tsk = current->real_parent;
54137+ if (tsk == NULL)
54138+ goto out_unlock;
54139+
54140+ filp = tsk->exec_file;
54141+ if (filp == NULL)
54142+ goto out_unlock;
54143+
54144+ tsk->is_writable = 0;
54145+
54146+ tsk->acl_sp_role = 1;
54147+ tsk->acl_role_id = ++acl_sp_role_value;
54148+ tsk->role = assigned;
54149+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
54150+
54151+ /* ignore additional mmap checks for processes that are writable
54152+ by the default ACL */
54153+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54154+ if (unlikely(obj->mode & GR_WRITE))
54155+ tsk->is_writable = 1;
54156+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
54157+ if (unlikely(obj->mode & GR_WRITE))
54158+ tsk->is_writable = 1;
54159+
54160+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54161+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
54162+#endif
54163+
54164+out_unlock:
54165+ read_unlock(&grsec_exec_file_lock);
54166+ read_unlock(&tasklist_lock);
54167+ return;
54168+}
54169+
54170+int gr_check_secure_terminal(struct task_struct *task)
54171+{
54172+ struct task_struct *p, *p2, *p3;
54173+ struct files_struct *files;
54174+ struct fdtable *fdt;
54175+ struct file *our_file = NULL, *file;
54176+ int i;
54177+
54178+ if (task->signal->tty == NULL)
54179+ return 1;
54180+
54181+ files = get_files_struct(task);
54182+ if (files != NULL) {
54183+ rcu_read_lock();
54184+ fdt = files_fdtable(files);
54185+ for (i=0; i < fdt->max_fds; i++) {
54186+ file = fcheck_files(files, i);
54187+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54188+ get_file(file);
54189+ our_file = file;
54190+ }
54191+ }
54192+ rcu_read_unlock();
54193+ put_files_struct(files);
54194+ }
54195+
54196+ if (our_file == NULL)
54197+ return 1;
54198+
54199+ read_lock(&tasklist_lock);
54200+ do_each_thread(p2, p) {
54201+ files = get_files_struct(p);
54202+ if (files == NULL ||
54203+ (p->signal && p->signal->tty == task->signal->tty)) {
54204+ if (files != NULL)
54205+ put_files_struct(files);
54206+ continue;
54207+ }
54208+ rcu_read_lock();
54209+ fdt = files_fdtable(files);
54210+ for (i=0; i < fdt->max_fds; i++) {
54211+ file = fcheck_files(files, i);
54212+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54213+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54214+ p3 = task;
54215+ while (p3->pid > 0) {
54216+ if (p3 == p)
54217+ break;
54218+ p3 = p3->real_parent;
54219+ }
54220+ if (p3 == p)
54221+ break;
54222+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54223+ gr_handle_alertkill(p);
54224+ rcu_read_unlock();
54225+ put_files_struct(files);
54226+ read_unlock(&tasklist_lock);
54227+ fput(our_file);
54228+ return 0;
54229+ }
54230+ }
54231+ rcu_read_unlock();
54232+ put_files_struct(files);
54233+ } while_each_thread(p2, p);
54234+ read_unlock(&tasklist_lock);
54235+
54236+ fput(our_file);
54237+ return 1;
54238+}
54239+
54240+static int gr_rbac_disable(void *unused)
54241+{
54242+ pax_open_kernel();
54243+ gr_status &= ~GR_READY;
54244+ pax_close_kernel();
54245+
54246+ return 0;
54247+}
54248+
54249+ssize_t
54250+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54251+{
54252+ struct gr_arg_wrapper uwrap;
54253+ unsigned char *sprole_salt = NULL;
54254+ unsigned char *sprole_sum = NULL;
54255+ int error = sizeof (struct gr_arg_wrapper);
54256+ int error2 = 0;
54257+
54258+ mutex_lock(&gr_dev_mutex);
54259+
54260+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54261+ error = -EPERM;
54262+ goto out;
54263+ }
54264+
54265+ if (count != sizeof (struct gr_arg_wrapper)) {
54266+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54267+ error = -EINVAL;
54268+ goto out;
54269+ }
54270+
54271+
54272+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54273+ gr_auth_expires = 0;
54274+ gr_auth_attempts = 0;
54275+ }
54276+
54277+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54278+ error = -EFAULT;
54279+ goto out;
54280+ }
54281+
54282+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54283+ error = -EINVAL;
54284+ goto out;
54285+ }
54286+
54287+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54288+ error = -EFAULT;
54289+ goto out;
54290+ }
54291+
54292+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54293+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54294+ time_after(gr_auth_expires, get_seconds())) {
54295+ error = -EBUSY;
54296+ goto out;
54297+ }
54298+
54299+ /* if non-root trying to do anything other than use a special role,
54300+ do not attempt authentication, do not count towards authentication
54301+ locking
54302+ */
54303+
54304+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54305+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54306+ !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
54307+ error = -EPERM;
54308+ goto out;
54309+ }
54310+
54311+ /* ensure pw and special role name are null terminated */
54312+
54313+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54314+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54315+
54316+ /* Okay.
54317+ * We have our enough of the argument structure..(we have yet
54318+ * to copy_from_user the tables themselves) . Copy the tables
54319+ * only if we need them, i.e. for loading operations. */
54320+
54321+ switch (gr_usermode->mode) {
54322+ case GR_STATUS:
54323+ if (gr_status & GR_READY) {
54324+ error = 1;
54325+ if (!gr_check_secure_terminal(current))
54326+ error = 3;
54327+ } else
54328+ error = 2;
54329+ goto out;
54330+ case GR_SHUTDOWN:
54331+ if ((gr_status & GR_READY)
54332+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54333+ stop_machine(gr_rbac_disable, NULL, NULL);
54334+ free_variables();
54335+ memset(gr_usermode, 0, sizeof (struct gr_arg));
54336+ memset(gr_system_salt, 0, GR_SALT_LEN);
54337+ memset(gr_system_sum, 0, GR_SHA_LEN);
54338+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54339+ } else if (gr_status & GR_READY) {
54340+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54341+ error = -EPERM;
54342+ } else {
54343+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54344+ error = -EAGAIN;
54345+ }
54346+ break;
54347+ case GR_ENABLE:
54348+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54349+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54350+ else {
54351+ if (gr_status & GR_READY)
54352+ error = -EAGAIN;
54353+ else
54354+ error = error2;
54355+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54356+ }
54357+ break;
54358+ case GR_RELOAD:
54359+ if (!(gr_status & GR_READY)) {
54360+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54361+ error = -EAGAIN;
54362+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54363+ stop_machine(gr_rbac_disable, NULL, NULL);
54364+ free_variables();
54365+ error2 = gracl_init(gr_usermode);
54366+ if (!error2)
54367+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54368+ else {
54369+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54370+ error = error2;
54371+ }
54372+ } else {
54373+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54374+ error = -EPERM;
54375+ }
54376+ break;
54377+ case GR_SEGVMOD:
54378+ if (unlikely(!(gr_status & GR_READY))) {
54379+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54380+ error = -EAGAIN;
54381+ break;
54382+ }
54383+
54384+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54385+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54386+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
54387+ struct acl_subject_label *segvacl;
54388+ segvacl =
54389+ lookup_acl_subj_label(gr_usermode->segv_inode,
54390+ gr_usermode->segv_device,
54391+ current->role);
54392+ if (segvacl) {
54393+ segvacl->crashes = 0;
54394+ segvacl->expires = 0;
54395+ }
54396+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
54397+ gr_remove_uid(gr_usermode->segv_uid);
54398+ }
54399+ } else {
54400+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
54401+ error = -EPERM;
54402+ }
54403+ break;
54404+ case GR_SPROLE:
54405+ case GR_SPROLEPAM:
54406+ if (unlikely(!(gr_status & GR_READY))) {
54407+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
54408+ error = -EAGAIN;
54409+ break;
54410+ }
54411+
54412+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
54413+ current->role->expires = 0;
54414+ current->role->auth_attempts = 0;
54415+ }
54416+
54417+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54418+ time_after(current->role->expires, get_seconds())) {
54419+ error = -EBUSY;
54420+ goto out;
54421+ }
54422+
54423+ if (lookup_special_role_auth
54424+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
54425+ && ((!sprole_salt && !sprole_sum)
54426+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
54427+ char *p = "";
54428+ assign_special_role(gr_usermode->sp_role);
54429+ read_lock(&tasklist_lock);
54430+ if (current->real_parent)
54431+ p = current->real_parent->role->rolename;
54432+ read_unlock(&tasklist_lock);
54433+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
54434+ p, acl_sp_role_value);
54435+ } else {
54436+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
54437+ error = -EPERM;
54438+ if(!(current->role->auth_attempts++))
54439+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54440+
54441+ goto out;
54442+ }
54443+ break;
54444+ case GR_UNSPROLE:
54445+ if (unlikely(!(gr_status & GR_READY))) {
54446+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
54447+ error = -EAGAIN;
54448+ break;
54449+ }
54450+
54451+ if (current->role->roletype & GR_ROLE_SPECIAL) {
54452+ char *p = "";
54453+ int i = 0;
54454+
54455+ read_lock(&tasklist_lock);
54456+ if (current->real_parent) {
54457+ p = current->real_parent->role->rolename;
54458+ i = current->real_parent->acl_role_id;
54459+ }
54460+ read_unlock(&tasklist_lock);
54461+
54462+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
54463+ gr_set_acls(1);
54464+ } else {
54465+ error = -EPERM;
54466+ goto out;
54467+ }
54468+ break;
54469+ default:
54470+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
54471+ error = -EINVAL;
54472+ break;
54473+ }
54474+
54475+ if (error != -EPERM)
54476+ goto out;
54477+
54478+ if(!(gr_auth_attempts++))
54479+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54480+
54481+ out:
54482+ mutex_unlock(&gr_dev_mutex);
54483+ return error;
54484+}
54485+
54486+/* must be called with
54487+ rcu_read_lock();
54488+ read_lock(&tasklist_lock);
54489+ read_lock(&grsec_exec_file_lock);
54490+*/
54491+int gr_apply_subject_to_task(struct task_struct *task)
54492+{
54493+ struct acl_object_label *obj;
54494+ char *tmpname;
54495+ struct acl_subject_label *tmpsubj;
54496+ struct file *filp;
54497+ struct name_entry *nmatch;
54498+
54499+ filp = task->exec_file;
54500+ if (filp == NULL)
54501+ return 0;
54502+
54503+ /* the following is to apply the correct subject
54504+ on binaries running when the RBAC system
54505+ is enabled, when the binaries have been
54506+ replaced or deleted since their execution
54507+ -----
54508+ when the RBAC system starts, the inode/dev
54509+ from exec_file will be one the RBAC system
54510+ is unaware of. It only knows the inode/dev
54511+ of the present file on disk, or the absence
54512+ of it.
54513+ */
54514+ preempt_disable();
54515+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
54516+
54517+ nmatch = lookup_name_entry(tmpname);
54518+ preempt_enable();
54519+ tmpsubj = NULL;
54520+ if (nmatch) {
54521+ if (nmatch->deleted)
54522+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
54523+ else
54524+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
54525+ if (tmpsubj != NULL)
54526+ task->acl = tmpsubj;
54527+ }
54528+ if (tmpsubj == NULL)
54529+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
54530+ task->role);
54531+ if (task->acl) {
54532+ task->is_writable = 0;
54533+ /* ignore additional mmap checks for processes that are writable
54534+ by the default ACL */
54535+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54536+ if (unlikely(obj->mode & GR_WRITE))
54537+ task->is_writable = 1;
54538+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54539+ if (unlikely(obj->mode & GR_WRITE))
54540+ task->is_writable = 1;
54541+
54542+ gr_set_proc_res(task);
54543+
54544+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54545+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54546+#endif
54547+ } else {
54548+ return 1;
54549+ }
54550+
54551+ return 0;
54552+}
54553+
54554+int
54555+gr_set_acls(const int type)
54556+{
54557+ struct task_struct *task, *task2;
54558+ struct acl_role_label *role = current->role;
54559+ __u16 acl_role_id = current->acl_role_id;
54560+ const struct cred *cred;
54561+ int ret;
54562+
54563+ rcu_read_lock();
54564+ read_lock(&tasklist_lock);
54565+ read_lock(&grsec_exec_file_lock);
54566+ do_each_thread(task2, task) {
54567+ /* check to see if we're called from the exit handler,
54568+ if so, only replace ACLs that have inherited the admin
54569+ ACL */
54570+
54571+ if (type && (task->role != role ||
54572+ task->acl_role_id != acl_role_id))
54573+ continue;
54574+
54575+ task->acl_role_id = 0;
54576+ task->acl_sp_role = 0;
54577+
54578+ if (task->exec_file) {
54579+ cred = __task_cred(task);
54580+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
54581+ ret = gr_apply_subject_to_task(task);
54582+ if (ret) {
54583+ read_unlock(&grsec_exec_file_lock);
54584+ read_unlock(&tasklist_lock);
54585+ rcu_read_unlock();
54586+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
54587+ return ret;
54588+ }
54589+ } else {
54590+ // it's a kernel process
54591+ task->role = kernel_role;
54592+ task->acl = kernel_role->root_label;
54593+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
54594+ task->acl->mode &= ~GR_PROCFIND;
54595+#endif
54596+ }
54597+ } while_each_thread(task2, task);
54598+ read_unlock(&grsec_exec_file_lock);
54599+ read_unlock(&tasklist_lock);
54600+ rcu_read_unlock();
54601+
54602+ return 0;
54603+}
54604+
54605+void
54606+gr_learn_resource(const struct task_struct *task,
54607+ const int res, const unsigned long wanted, const int gt)
54608+{
54609+ struct acl_subject_label *acl;
54610+ const struct cred *cred;
54611+
54612+ if (unlikely((gr_status & GR_READY) &&
54613+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
54614+ goto skip_reslog;
54615+
54616+#ifdef CONFIG_GRKERNSEC_RESLOG
54617+ gr_log_resource(task, res, wanted, gt);
54618+#endif
54619+ skip_reslog:
54620+
54621+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
54622+ return;
54623+
54624+ acl = task->acl;
54625+
54626+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
54627+ !(acl->resmask & (1 << (unsigned short) res))))
54628+ return;
54629+
54630+ if (wanted >= acl->res[res].rlim_cur) {
54631+ unsigned long res_add;
54632+
54633+ res_add = wanted;
54634+ switch (res) {
54635+ case RLIMIT_CPU:
54636+ res_add += GR_RLIM_CPU_BUMP;
54637+ break;
54638+ case RLIMIT_FSIZE:
54639+ res_add += GR_RLIM_FSIZE_BUMP;
54640+ break;
54641+ case RLIMIT_DATA:
54642+ res_add += GR_RLIM_DATA_BUMP;
54643+ break;
54644+ case RLIMIT_STACK:
54645+ res_add += GR_RLIM_STACK_BUMP;
54646+ break;
54647+ case RLIMIT_CORE:
54648+ res_add += GR_RLIM_CORE_BUMP;
54649+ break;
54650+ case RLIMIT_RSS:
54651+ res_add += GR_RLIM_RSS_BUMP;
54652+ break;
54653+ case RLIMIT_NPROC:
54654+ res_add += GR_RLIM_NPROC_BUMP;
54655+ break;
54656+ case RLIMIT_NOFILE:
54657+ res_add += GR_RLIM_NOFILE_BUMP;
54658+ break;
54659+ case RLIMIT_MEMLOCK:
54660+ res_add += GR_RLIM_MEMLOCK_BUMP;
54661+ break;
54662+ case RLIMIT_AS:
54663+ res_add += GR_RLIM_AS_BUMP;
54664+ break;
54665+ case RLIMIT_LOCKS:
54666+ res_add += GR_RLIM_LOCKS_BUMP;
54667+ break;
54668+ case RLIMIT_SIGPENDING:
54669+ res_add += GR_RLIM_SIGPENDING_BUMP;
54670+ break;
54671+ case RLIMIT_MSGQUEUE:
54672+ res_add += GR_RLIM_MSGQUEUE_BUMP;
54673+ break;
54674+ case RLIMIT_NICE:
54675+ res_add += GR_RLIM_NICE_BUMP;
54676+ break;
54677+ case RLIMIT_RTPRIO:
54678+ res_add += GR_RLIM_RTPRIO_BUMP;
54679+ break;
54680+ case RLIMIT_RTTIME:
54681+ res_add += GR_RLIM_RTTIME_BUMP;
54682+ break;
54683+ }
54684+
54685+ acl->res[res].rlim_cur = res_add;
54686+
54687+ if (wanted > acl->res[res].rlim_max)
54688+ acl->res[res].rlim_max = res_add;
54689+
54690+ /* only log the subject filename, since resource logging is supported for
54691+ single-subject learning only */
54692+ rcu_read_lock();
54693+ cred = __task_cred(task);
54694+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54695+ task->role->roletype, cred->uid, cred->gid, acl->filename,
54696+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
54697+ "", (unsigned long) res, &task->signal->saved_ip);
54698+ rcu_read_unlock();
54699+ }
54700+
54701+ return;
54702+}
54703+
54704+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
54705+void
54706+pax_set_initial_flags(struct linux_binprm *bprm)
54707+{
54708+ struct task_struct *task = current;
54709+ struct acl_subject_label *proc;
54710+ unsigned long flags;
54711+
54712+ if (unlikely(!(gr_status & GR_READY)))
54713+ return;
54714+
54715+ flags = pax_get_flags(task);
54716+
54717+ proc = task->acl;
54718+
54719+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
54720+ flags &= ~MF_PAX_PAGEEXEC;
54721+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
54722+ flags &= ~MF_PAX_SEGMEXEC;
54723+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
54724+ flags &= ~MF_PAX_RANDMMAP;
54725+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
54726+ flags &= ~MF_PAX_EMUTRAMP;
54727+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
54728+ flags &= ~MF_PAX_MPROTECT;
54729+
54730+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
54731+ flags |= MF_PAX_PAGEEXEC;
54732+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
54733+ flags |= MF_PAX_SEGMEXEC;
54734+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
54735+ flags |= MF_PAX_RANDMMAP;
54736+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
54737+ flags |= MF_PAX_EMUTRAMP;
54738+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
54739+ flags |= MF_PAX_MPROTECT;
54740+
54741+ pax_set_flags(task, flags);
54742+
54743+ return;
54744+}
54745+#endif
54746+
54747+int
54748+gr_handle_proc_ptrace(struct task_struct *task)
54749+{
54750+ struct file *filp;
54751+ struct task_struct *tmp = task;
54752+ struct task_struct *curtemp = current;
54753+ __u32 retmode;
54754+
54755+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54756+ if (unlikely(!(gr_status & GR_READY)))
54757+ return 0;
54758+#endif
54759+
54760+ read_lock(&tasklist_lock);
54761+ read_lock(&grsec_exec_file_lock);
54762+ filp = task->exec_file;
54763+
54764+ while (tmp->pid > 0) {
54765+ if (tmp == curtemp)
54766+ break;
54767+ tmp = tmp->real_parent;
54768+ }
54769+
54770+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
54771+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
54772+ read_unlock(&grsec_exec_file_lock);
54773+ read_unlock(&tasklist_lock);
54774+ return 1;
54775+ }
54776+
54777+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54778+ if (!(gr_status & GR_READY)) {
54779+ read_unlock(&grsec_exec_file_lock);
54780+ read_unlock(&tasklist_lock);
54781+ return 0;
54782+ }
54783+#endif
54784+
54785+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
54786+ read_unlock(&grsec_exec_file_lock);
54787+ read_unlock(&tasklist_lock);
54788+
54789+ if (retmode & GR_NOPTRACE)
54790+ return 1;
54791+
54792+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
54793+ && (current->acl != task->acl || (current->acl != current->role->root_label
54794+ && current->pid != task->pid)))
54795+ return 1;
54796+
54797+ return 0;
54798+}
54799+
54800+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
54801+{
54802+ if (unlikely(!(gr_status & GR_READY)))
54803+ return;
54804+
54805+ if (!(current->role->roletype & GR_ROLE_GOD))
54806+ return;
54807+
54808+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
54809+ p->role->rolename, gr_task_roletype_to_char(p),
54810+ p->acl->filename);
54811+}
54812+
54813+int
54814+gr_handle_ptrace(struct task_struct *task, const long request)
54815+{
54816+ struct task_struct *tmp = task;
54817+ struct task_struct *curtemp = current;
54818+ __u32 retmode;
54819+
54820+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54821+ if (unlikely(!(gr_status & GR_READY)))
54822+ return 0;
54823+#endif
54824+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
54825+ read_lock(&tasklist_lock);
54826+ while (tmp->pid > 0) {
54827+ if (tmp == curtemp)
54828+ break;
54829+ tmp = tmp->real_parent;
54830+ }
54831+
54832+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
54833+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
54834+ read_unlock(&tasklist_lock);
54835+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54836+ return 1;
54837+ }
54838+ read_unlock(&tasklist_lock);
54839+ }
54840+
54841+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54842+ if (!(gr_status & GR_READY))
54843+ return 0;
54844+#endif
54845+
54846+ read_lock(&grsec_exec_file_lock);
54847+ if (unlikely(!task->exec_file)) {
54848+ read_unlock(&grsec_exec_file_lock);
54849+ return 0;
54850+ }
54851+
54852+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
54853+ read_unlock(&grsec_exec_file_lock);
54854+
54855+ if (retmode & GR_NOPTRACE) {
54856+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54857+ return 1;
54858+ }
54859+
54860+ if (retmode & GR_PTRACERD) {
54861+ switch (request) {
54862+ case PTRACE_SEIZE:
54863+ case PTRACE_POKETEXT:
54864+ case PTRACE_POKEDATA:
54865+ case PTRACE_POKEUSR:
54866+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
54867+ case PTRACE_SETREGS:
54868+ case PTRACE_SETFPREGS:
54869+#endif
54870+#ifdef CONFIG_X86
54871+ case PTRACE_SETFPXREGS:
54872+#endif
54873+#ifdef CONFIG_ALTIVEC
54874+ case PTRACE_SETVRREGS:
54875+#endif
54876+ return 1;
54877+ default:
54878+ return 0;
54879+ }
54880+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
54881+ !(current->role->roletype & GR_ROLE_GOD) &&
54882+ (current->acl != task->acl)) {
54883+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54884+ return 1;
54885+ }
54886+
54887+ return 0;
54888+}
54889+
54890+static int is_writable_mmap(const struct file *filp)
54891+{
54892+ struct task_struct *task = current;
54893+ struct acl_object_label *obj, *obj2;
54894+
54895+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
54896+ !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))) {
54897+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54898+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
54899+ task->role->root_label);
54900+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
54901+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
54902+ return 1;
54903+ }
54904+ }
54905+ return 0;
54906+}
54907+
54908+int
54909+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
54910+{
54911+ __u32 mode;
54912+
54913+ if (unlikely(!file || !(prot & PROT_EXEC)))
54914+ return 1;
54915+
54916+ if (is_writable_mmap(file))
54917+ return 0;
54918+
54919+ mode =
54920+ gr_search_file(file->f_path.dentry,
54921+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54922+ file->f_path.mnt);
54923+
54924+ if (!gr_tpe_allow(file))
54925+ return 0;
54926+
54927+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54928+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54929+ return 0;
54930+ } else if (unlikely(!(mode & GR_EXEC))) {
54931+ return 0;
54932+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54933+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54934+ return 1;
54935+ }
54936+
54937+ return 1;
54938+}
54939+
54940+int
54941+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
54942+{
54943+ __u32 mode;
54944+
54945+ if (unlikely(!file || !(prot & PROT_EXEC)))
54946+ return 1;
54947+
54948+ if (is_writable_mmap(file))
54949+ return 0;
54950+
54951+ mode =
54952+ gr_search_file(file->f_path.dentry,
54953+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54954+ file->f_path.mnt);
54955+
54956+ if (!gr_tpe_allow(file))
54957+ return 0;
54958+
54959+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54960+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54961+ return 0;
54962+ } else if (unlikely(!(mode & GR_EXEC))) {
54963+ return 0;
54964+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54965+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54966+ return 1;
54967+ }
54968+
54969+ return 1;
54970+}
54971+
54972+void
54973+gr_acl_handle_psacct(struct task_struct *task, const long code)
54974+{
54975+ unsigned long runtime;
54976+ unsigned long cputime;
54977+ unsigned int wday, cday;
54978+ __u8 whr, chr;
54979+ __u8 wmin, cmin;
54980+ __u8 wsec, csec;
54981+ struct timespec timeval;
54982+
54983+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
54984+ !(task->acl->mode & GR_PROCACCT)))
54985+ return;
54986+
54987+ do_posix_clock_monotonic_gettime(&timeval);
54988+ runtime = timeval.tv_sec - task->start_time.tv_sec;
54989+ wday = runtime / (3600 * 24);
54990+ runtime -= wday * (3600 * 24);
54991+ whr = runtime / 3600;
54992+ runtime -= whr * 3600;
54993+ wmin = runtime / 60;
54994+ runtime -= wmin * 60;
54995+ wsec = runtime;
54996+
54997+ cputime = (task->utime + task->stime) / HZ;
54998+ cday = cputime / (3600 * 24);
54999+ cputime -= cday * (3600 * 24);
55000+ chr = cputime / 3600;
55001+ cputime -= chr * 3600;
55002+ cmin = cputime / 60;
55003+ cputime -= cmin * 60;
55004+ csec = cputime;
55005+
55006+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
55007+
55008+ return;
55009+}
55010+
55011+void gr_set_kernel_label(struct task_struct *task)
55012+{
55013+ if (gr_status & GR_READY) {
55014+ task->role = kernel_role;
55015+ task->acl = kernel_role->root_label;
55016+ }
55017+ return;
55018+}
55019+
55020+#ifdef CONFIG_TASKSTATS
55021+int gr_is_taskstats_denied(int pid)
55022+{
55023+ struct task_struct *task;
55024+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55025+ const struct cred *cred;
55026+#endif
55027+ int ret = 0;
55028+
55029+ /* restrict taskstats viewing to un-chrooted root users
55030+ who have the 'view' subject flag if the RBAC system is enabled
55031+ */
55032+
55033+ rcu_read_lock();
55034+ read_lock(&tasklist_lock);
55035+ task = find_task_by_vpid(pid);
55036+ if (task) {
55037+#ifdef CONFIG_GRKERNSEC_CHROOT
55038+ if (proc_is_chrooted(task))
55039+ ret = -EACCES;
55040+#endif
55041+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55042+ cred = __task_cred(task);
55043+#ifdef CONFIG_GRKERNSEC_PROC_USER
55044+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
55045+ ret = -EACCES;
55046+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55047+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
55048+ ret = -EACCES;
55049+#endif
55050+#endif
55051+ if (gr_status & GR_READY) {
55052+ if (!(task->acl->mode & GR_VIEW))
55053+ ret = -EACCES;
55054+ }
55055+ } else
55056+ ret = -ENOENT;
55057+
55058+ read_unlock(&tasklist_lock);
55059+ rcu_read_unlock();
55060+
55061+ return ret;
55062+}
55063+#endif
55064+
55065+/* AUXV entries are filled via a descendant of search_binary_handler
55066+ after we've already applied the subject for the target
55067+*/
55068+int gr_acl_enable_at_secure(void)
55069+{
55070+ if (unlikely(!(gr_status & GR_READY)))
55071+ return 0;
55072+
55073+ if (current->acl->mode & GR_ATSECURE)
55074+ return 1;
55075+
55076+ return 0;
55077+}
55078+
55079+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
55080+{
55081+ struct task_struct *task = current;
55082+ struct dentry *dentry = file->f_path.dentry;
55083+ struct vfsmount *mnt = file->f_path.mnt;
55084+ struct acl_object_label *obj, *tmp;
55085+ struct acl_subject_label *subj;
55086+ unsigned int bufsize;
55087+ int is_not_root;
55088+ char *path;
55089+ dev_t dev = __get_dev(dentry);
55090+
55091+ if (unlikely(!(gr_status & GR_READY)))
55092+ return 1;
55093+
55094+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55095+ return 1;
55096+
55097+ /* ignore Eric Biederman */
55098+ if (IS_PRIVATE(dentry->d_inode))
55099+ return 1;
55100+
55101+ subj = task->acl;
55102+ read_lock(&gr_inode_lock);
55103+ do {
55104+ obj = lookup_acl_obj_label(ino, dev, subj);
55105+ if (obj != NULL) {
55106+ read_unlock(&gr_inode_lock);
55107+ return (obj->mode & GR_FIND) ? 1 : 0;
55108+ }
55109+ } while ((subj = subj->parent_subject));
55110+ read_unlock(&gr_inode_lock);
55111+
55112+ /* this is purely an optimization since we're looking for an object
55113+ for the directory we're doing a readdir on
55114+ if it's possible for any globbed object to match the entry we're
55115+ filling into the directory, then the object we find here will be
55116+ an anchor point with attached globbed objects
55117+ */
55118+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
55119+ if (obj->globbed == NULL)
55120+ return (obj->mode & GR_FIND) ? 1 : 0;
55121+
55122+ is_not_root = ((obj->filename[0] == '/') &&
55123+ (obj->filename[1] == '\0')) ? 0 : 1;
55124+ bufsize = PAGE_SIZE - namelen - is_not_root;
55125+
55126+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
55127+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
55128+ return 1;
55129+
55130+ preempt_disable();
55131+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55132+ bufsize);
55133+
55134+ bufsize = strlen(path);
55135+
55136+ /* if base is "/", don't append an additional slash */
55137+ if (is_not_root)
55138+ *(path + bufsize) = '/';
55139+ memcpy(path + bufsize + is_not_root, name, namelen);
55140+ *(path + bufsize + namelen + is_not_root) = '\0';
55141+
55142+ tmp = obj->globbed;
55143+ while (tmp) {
55144+ if (!glob_match(tmp->filename, path)) {
55145+ preempt_enable();
55146+ return (tmp->mode & GR_FIND) ? 1 : 0;
55147+ }
55148+ tmp = tmp->next;
55149+ }
55150+ preempt_enable();
55151+ return (obj->mode & GR_FIND) ? 1 : 0;
55152+}
55153+
55154+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55155+EXPORT_SYMBOL(gr_acl_is_enabled);
55156+#endif
55157+EXPORT_SYMBOL(gr_learn_resource);
55158+EXPORT_SYMBOL(gr_set_kernel_label);
55159+#ifdef CONFIG_SECURITY
55160+EXPORT_SYMBOL(gr_check_user_change);
55161+EXPORT_SYMBOL(gr_check_group_change);
55162+#endif
55163+
55164diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
55165new file mode 100644
55166index 0000000..34fefda
55167--- /dev/null
55168+++ b/grsecurity/gracl_alloc.c
55169@@ -0,0 +1,105 @@
55170+#include <linux/kernel.h>
55171+#include <linux/mm.h>
55172+#include <linux/slab.h>
55173+#include <linux/vmalloc.h>
55174+#include <linux/gracl.h>
55175+#include <linux/grsecurity.h>
55176+
55177+static unsigned long alloc_stack_next = 1;
55178+static unsigned long alloc_stack_size = 1;
55179+static void **alloc_stack;
55180+
55181+static __inline__ int
55182+alloc_pop(void)
55183+{
55184+ if (alloc_stack_next == 1)
55185+ return 0;
55186+
55187+ kfree(alloc_stack[alloc_stack_next - 2]);
55188+
55189+ alloc_stack_next--;
55190+
55191+ return 1;
55192+}
55193+
55194+static __inline__ int
55195+alloc_push(void *buf)
55196+{
55197+ if (alloc_stack_next >= alloc_stack_size)
55198+ return 1;
55199+
55200+ alloc_stack[alloc_stack_next - 1] = buf;
55201+
55202+ alloc_stack_next++;
55203+
55204+ return 0;
55205+}
55206+
55207+void *
55208+acl_alloc(unsigned long len)
55209+{
55210+ void *ret = NULL;
55211+
55212+ if (!len || len > PAGE_SIZE)
55213+ goto out;
55214+
55215+ ret = kmalloc(len, GFP_KERNEL);
55216+
55217+ if (ret) {
55218+ if (alloc_push(ret)) {
55219+ kfree(ret);
55220+ ret = NULL;
55221+ }
55222+ }
55223+
55224+out:
55225+ return ret;
55226+}
55227+
55228+void *
55229+acl_alloc_num(unsigned long num, unsigned long len)
55230+{
55231+ if (!len || (num > (PAGE_SIZE / len)))
55232+ return NULL;
55233+
55234+ return acl_alloc(num * len);
55235+}
55236+
55237+void
55238+acl_free_all(void)
55239+{
55240+ if (gr_acl_is_enabled() || !alloc_stack)
55241+ return;
55242+
55243+ while (alloc_pop()) ;
55244+
55245+ if (alloc_stack) {
55246+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
55247+ kfree(alloc_stack);
55248+ else
55249+ vfree(alloc_stack);
55250+ }
55251+
55252+ alloc_stack = NULL;
55253+ alloc_stack_size = 1;
55254+ alloc_stack_next = 1;
55255+
55256+ return;
55257+}
55258+
55259+int
55260+acl_alloc_stack_init(unsigned long size)
55261+{
55262+ if ((size * sizeof (void *)) <= PAGE_SIZE)
55263+ alloc_stack =
55264+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
55265+ else
55266+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
55267+
55268+ alloc_stack_size = size;
55269+
55270+ if (!alloc_stack)
55271+ return 0;
55272+ else
55273+ return 1;
55274+}
55275diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
55276new file mode 100644
55277index 0000000..6d21049
55278--- /dev/null
55279+++ b/grsecurity/gracl_cap.c
55280@@ -0,0 +1,110 @@
55281+#include <linux/kernel.h>
55282+#include <linux/module.h>
55283+#include <linux/sched.h>
55284+#include <linux/gracl.h>
55285+#include <linux/grsecurity.h>
55286+#include <linux/grinternal.h>
55287+
55288+extern const char *captab_log[];
55289+extern int captab_log_entries;
55290+
55291+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
55292+{
55293+ struct acl_subject_label *curracl;
55294+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55295+ kernel_cap_t cap_audit = __cap_empty_set;
55296+
55297+ if (!gr_acl_is_enabled())
55298+ return 1;
55299+
55300+ curracl = task->acl;
55301+
55302+ cap_drop = curracl->cap_lower;
55303+ cap_mask = curracl->cap_mask;
55304+ cap_audit = curracl->cap_invert_audit;
55305+
55306+ while ((curracl = curracl->parent_subject)) {
55307+ /* if the cap isn't specified in the current computed mask but is specified in the
55308+ current level subject, and is lowered in the current level subject, then add
55309+ it to the set of dropped capabilities
55310+ otherwise, add the current level subject's mask to the current computed mask
55311+ */
55312+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55313+ cap_raise(cap_mask, cap);
55314+ if (cap_raised(curracl->cap_lower, cap))
55315+ cap_raise(cap_drop, cap);
55316+ if (cap_raised(curracl->cap_invert_audit, cap))
55317+ cap_raise(cap_audit, cap);
55318+ }
55319+ }
55320+
55321+ if (!cap_raised(cap_drop, cap)) {
55322+ if (cap_raised(cap_audit, cap))
55323+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55324+ return 1;
55325+ }
55326+
55327+ curracl = task->acl;
55328+
55329+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55330+ && cap_raised(cred->cap_effective, cap)) {
55331+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55332+ task->role->roletype, cred->uid,
55333+ cred->gid, task->exec_file ?
55334+ gr_to_filename(task->exec_file->f_path.dentry,
55335+ task->exec_file->f_path.mnt) : curracl->filename,
55336+ curracl->filename, 0UL,
55337+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55338+ return 1;
55339+ }
55340+
55341+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55342+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55343+
55344+ return 0;
55345+}
55346+
55347+int
55348+gr_acl_is_capable(const int cap)
55349+{
55350+ return gr_task_acl_is_capable(current, current_cred(), cap);
55351+}
55352+
55353+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
55354+{
55355+ struct acl_subject_label *curracl;
55356+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55357+
55358+ if (!gr_acl_is_enabled())
55359+ return 1;
55360+
55361+ curracl = task->acl;
55362+
55363+ cap_drop = curracl->cap_lower;
55364+ cap_mask = curracl->cap_mask;
55365+
55366+ while ((curracl = curracl->parent_subject)) {
55367+ /* if the cap isn't specified in the current computed mask but is specified in the
55368+ current level subject, and is lowered in the current level subject, then add
55369+ it to the set of dropped capabilities
55370+ otherwise, add the current level subject's mask to the current computed mask
55371+ */
55372+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55373+ cap_raise(cap_mask, cap);
55374+ if (cap_raised(curracl->cap_lower, cap))
55375+ cap_raise(cap_drop, cap);
55376+ }
55377+ }
55378+
55379+ if (!cap_raised(cap_drop, cap))
55380+ return 1;
55381+
55382+ return 0;
55383+}
55384+
55385+int
55386+gr_acl_is_capable_nolog(const int cap)
55387+{
55388+ return gr_task_acl_is_capable_nolog(current, cap);
55389+}
55390+
55391diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
55392new file mode 100644
55393index 0000000..d28e241
55394--- /dev/null
55395+++ b/grsecurity/gracl_fs.c
55396@@ -0,0 +1,437 @@
55397+#include <linux/kernel.h>
55398+#include <linux/sched.h>
55399+#include <linux/types.h>
55400+#include <linux/fs.h>
55401+#include <linux/file.h>
55402+#include <linux/stat.h>
55403+#include <linux/grsecurity.h>
55404+#include <linux/grinternal.h>
55405+#include <linux/gracl.h>
55406+
55407+umode_t
55408+gr_acl_umask(void)
55409+{
55410+ if (unlikely(!gr_acl_is_enabled()))
55411+ return 0;
55412+
55413+ return current->role->umask;
55414+}
55415+
55416+__u32
55417+gr_acl_handle_hidden_file(const struct dentry * dentry,
55418+ const struct vfsmount * mnt)
55419+{
55420+ __u32 mode;
55421+
55422+ if (unlikely(!dentry->d_inode))
55423+ return GR_FIND;
55424+
55425+ mode =
55426+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55427+
55428+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55429+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55430+ return mode;
55431+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55432+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55433+ return 0;
55434+ } else if (unlikely(!(mode & GR_FIND)))
55435+ return 0;
55436+
55437+ return GR_FIND;
55438+}
55439+
55440+__u32
55441+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55442+ int acc_mode)
55443+{
55444+ __u32 reqmode = GR_FIND;
55445+ __u32 mode;
55446+
55447+ if (unlikely(!dentry->d_inode))
55448+ return reqmode;
55449+
55450+ if (acc_mode & MAY_APPEND)
55451+ reqmode |= GR_APPEND;
55452+ else if (acc_mode & MAY_WRITE)
55453+ reqmode |= GR_WRITE;
55454+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
55455+ reqmode |= GR_READ;
55456+
55457+ mode =
55458+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55459+ mnt);
55460+
55461+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55462+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55463+ reqmode & GR_READ ? " reading" : "",
55464+ reqmode & GR_WRITE ? " writing" : reqmode &
55465+ GR_APPEND ? " appending" : "");
55466+ return reqmode;
55467+ } else
55468+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55469+ {
55470+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55471+ reqmode & GR_READ ? " reading" : "",
55472+ reqmode & GR_WRITE ? " writing" : reqmode &
55473+ GR_APPEND ? " appending" : "");
55474+ return 0;
55475+ } else if (unlikely((mode & reqmode) != reqmode))
55476+ return 0;
55477+
55478+ return reqmode;
55479+}
55480+
55481+__u32
55482+gr_acl_handle_creat(const struct dentry * dentry,
55483+ const struct dentry * p_dentry,
55484+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
55485+ const int imode)
55486+{
55487+ __u32 reqmode = GR_WRITE | GR_CREATE;
55488+ __u32 mode;
55489+
55490+ if (acc_mode & MAY_APPEND)
55491+ reqmode |= GR_APPEND;
55492+ // if a directory was required or the directory already exists, then
55493+ // don't count this open as a read
55494+ if ((acc_mode & MAY_READ) &&
55495+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
55496+ reqmode |= GR_READ;
55497+ if ((open_flags & O_CREAT) &&
55498+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
55499+ reqmode |= GR_SETID;
55500+
55501+ mode =
55502+ gr_check_create(dentry, p_dentry, p_mnt,
55503+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55504+
55505+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55506+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55507+ reqmode & GR_READ ? " reading" : "",
55508+ reqmode & GR_WRITE ? " writing" : reqmode &
55509+ GR_APPEND ? " appending" : "");
55510+ return reqmode;
55511+ } else
55512+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55513+ {
55514+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55515+ reqmode & GR_READ ? " reading" : "",
55516+ reqmode & GR_WRITE ? " writing" : reqmode &
55517+ GR_APPEND ? " appending" : "");
55518+ return 0;
55519+ } else if (unlikely((mode & reqmode) != reqmode))
55520+ return 0;
55521+
55522+ return reqmode;
55523+}
55524+
55525+__u32
55526+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
55527+ const int fmode)
55528+{
55529+ __u32 mode, reqmode = GR_FIND;
55530+
55531+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
55532+ reqmode |= GR_EXEC;
55533+ if (fmode & S_IWOTH)
55534+ reqmode |= GR_WRITE;
55535+ if (fmode & S_IROTH)
55536+ reqmode |= GR_READ;
55537+
55538+ mode =
55539+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55540+ mnt);
55541+
55542+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55543+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55544+ reqmode & GR_READ ? " reading" : "",
55545+ reqmode & GR_WRITE ? " writing" : "",
55546+ reqmode & GR_EXEC ? " executing" : "");
55547+ return reqmode;
55548+ } else
55549+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55550+ {
55551+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55552+ reqmode & GR_READ ? " reading" : "",
55553+ reqmode & GR_WRITE ? " writing" : "",
55554+ reqmode & GR_EXEC ? " executing" : "");
55555+ return 0;
55556+ } else if (unlikely((mode & reqmode) != reqmode))
55557+ return 0;
55558+
55559+ return reqmode;
55560+}
55561+
55562+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55563+{
55564+ __u32 mode;
55565+
55566+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55567+
55568+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55569+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55570+ return mode;
55571+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55572+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55573+ return 0;
55574+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
55575+ return 0;
55576+
55577+ return (reqmode);
55578+}
55579+
55580+__u32
55581+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
55582+{
55583+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
55584+}
55585+
55586+__u32
55587+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
55588+{
55589+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
55590+}
55591+
55592+__u32
55593+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
55594+{
55595+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
55596+}
55597+
55598+__u32
55599+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
55600+{
55601+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
55602+}
55603+
55604+__u32
55605+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
55606+ umode_t *modeptr)
55607+{
55608+ umode_t mode;
55609+
55610+ *modeptr &= ~gr_acl_umask();
55611+ mode = *modeptr;
55612+
55613+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
55614+ return 1;
55615+
55616+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
55617+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
55618+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55619+ GR_CHMOD_ACL_MSG);
55620+ } else {
55621+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
55622+ }
55623+}
55624+
55625+__u32
55626+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
55627+{
55628+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
55629+}
55630+
55631+__u32
55632+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
55633+{
55634+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
55635+}
55636+
55637+__u32
55638+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
55639+{
55640+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
55641+}
55642+
55643+__u32
55644+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
55645+{
55646+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
55647+ GR_UNIXCONNECT_ACL_MSG);
55648+}
55649+
55650+/* hardlinks require at minimum create and link permission,
55651+ any additional privilege required is based on the
55652+ privilege of the file being linked to
55653+*/
55654+__u32
55655+gr_acl_handle_link(const struct dentry * new_dentry,
55656+ const struct dentry * parent_dentry,
55657+ const struct vfsmount * parent_mnt,
55658+ const struct dentry * old_dentry,
55659+ const struct vfsmount * old_mnt, const char *to)
55660+{
55661+ __u32 mode;
55662+ __u32 needmode = GR_CREATE | GR_LINK;
55663+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
55664+
55665+ mode =
55666+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
55667+ old_mnt);
55668+
55669+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
55670+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55671+ return mode;
55672+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55673+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55674+ return 0;
55675+ } else if (unlikely((mode & needmode) != needmode))
55676+ return 0;
55677+
55678+ return 1;
55679+}
55680+
55681+__u32
55682+gr_acl_handle_symlink(const struct dentry * new_dentry,
55683+ const struct dentry * parent_dentry,
55684+ const struct vfsmount * parent_mnt, const char *from)
55685+{
55686+ __u32 needmode = GR_WRITE | GR_CREATE;
55687+ __u32 mode;
55688+
55689+ mode =
55690+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
55691+ GR_CREATE | GR_AUDIT_CREATE |
55692+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
55693+
55694+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
55695+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55696+ return mode;
55697+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55698+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55699+ return 0;
55700+ } else if (unlikely((mode & needmode) != needmode))
55701+ return 0;
55702+
55703+ return (GR_WRITE | GR_CREATE);
55704+}
55705+
55706+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)
55707+{
55708+ __u32 mode;
55709+
55710+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55711+
55712+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55713+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
55714+ return mode;
55715+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55716+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
55717+ return 0;
55718+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
55719+ return 0;
55720+
55721+ return (reqmode);
55722+}
55723+
55724+__u32
55725+gr_acl_handle_mknod(const struct dentry * new_dentry,
55726+ const struct dentry * parent_dentry,
55727+ const struct vfsmount * parent_mnt,
55728+ const int mode)
55729+{
55730+ __u32 reqmode = GR_WRITE | GR_CREATE;
55731+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
55732+ reqmode |= GR_SETID;
55733+
55734+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55735+ reqmode, GR_MKNOD_ACL_MSG);
55736+}
55737+
55738+__u32
55739+gr_acl_handle_mkdir(const struct dentry *new_dentry,
55740+ const struct dentry *parent_dentry,
55741+ const struct vfsmount *parent_mnt)
55742+{
55743+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55744+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
55745+}
55746+
55747+#define RENAME_CHECK_SUCCESS(old, new) \
55748+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
55749+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
55750+
55751+int
55752+gr_acl_handle_rename(struct dentry *new_dentry,
55753+ struct dentry *parent_dentry,
55754+ const struct vfsmount *parent_mnt,
55755+ struct dentry *old_dentry,
55756+ struct inode *old_parent_inode,
55757+ struct vfsmount *old_mnt, const char *newname)
55758+{
55759+ __u32 comp1, comp2;
55760+ int error = 0;
55761+
55762+ if (unlikely(!gr_acl_is_enabled()))
55763+ return 0;
55764+
55765+ if (!new_dentry->d_inode) {
55766+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
55767+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
55768+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
55769+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
55770+ GR_DELETE | GR_AUDIT_DELETE |
55771+ GR_AUDIT_READ | GR_AUDIT_WRITE |
55772+ GR_SUPPRESS, old_mnt);
55773+ } else {
55774+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
55775+ GR_CREATE | GR_DELETE |
55776+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
55777+ GR_AUDIT_READ | GR_AUDIT_WRITE |
55778+ GR_SUPPRESS, parent_mnt);
55779+ comp2 =
55780+ gr_search_file(old_dentry,
55781+ GR_READ | GR_WRITE | GR_AUDIT_READ |
55782+ GR_DELETE | GR_AUDIT_DELETE |
55783+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
55784+ }
55785+
55786+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
55787+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
55788+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55789+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
55790+ && !(comp2 & GR_SUPPRESS)) {
55791+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55792+ error = -EACCES;
55793+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
55794+ error = -EACCES;
55795+
55796+ return error;
55797+}
55798+
55799+void
55800+gr_acl_handle_exit(void)
55801+{
55802+ u16 id;
55803+ char *rolename;
55804+ struct file *exec_file;
55805+
55806+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
55807+ !(current->role->roletype & GR_ROLE_PERSIST))) {
55808+ id = current->acl_role_id;
55809+ rolename = current->role->rolename;
55810+ gr_set_acls(1);
55811+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
55812+ }
55813+
55814+ write_lock(&grsec_exec_file_lock);
55815+ exec_file = current->exec_file;
55816+ current->exec_file = NULL;
55817+ write_unlock(&grsec_exec_file_lock);
55818+
55819+ if (exec_file)
55820+ fput(exec_file);
55821+}
55822+
55823+int
55824+gr_acl_handle_procpidmem(const struct task_struct *task)
55825+{
55826+ if (unlikely(!gr_acl_is_enabled()))
55827+ return 0;
55828+
55829+ if (task != current && task->acl->mode & GR_PROTPROCFD)
55830+ return -EACCES;
55831+
55832+ return 0;
55833+}
55834diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
55835new file mode 100644
55836index 0000000..58800a7
55837--- /dev/null
55838+++ b/grsecurity/gracl_ip.c
55839@@ -0,0 +1,384 @@
55840+#include <linux/kernel.h>
55841+#include <asm/uaccess.h>
55842+#include <asm/errno.h>
55843+#include <net/sock.h>
55844+#include <linux/file.h>
55845+#include <linux/fs.h>
55846+#include <linux/net.h>
55847+#include <linux/in.h>
55848+#include <linux/skbuff.h>
55849+#include <linux/ip.h>
55850+#include <linux/udp.h>
55851+#include <linux/types.h>
55852+#include <linux/sched.h>
55853+#include <linux/netdevice.h>
55854+#include <linux/inetdevice.h>
55855+#include <linux/gracl.h>
55856+#include <linux/grsecurity.h>
55857+#include <linux/grinternal.h>
55858+
55859+#define GR_BIND 0x01
55860+#define GR_CONNECT 0x02
55861+#define GR_INVERT 0x04
55862+#define GR_BINDOVERRIDE 0x08
55863+#define GR_CONNECTOVERRIDE 0x10
55864+#define GR_SOCK_FAMILY 0x20
55865+
55866+static const char * gr_protocols[IPPROTO_MAX] = {
55867+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
55868+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
55869+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
55870+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
55871+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
55872+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
55873+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
55874+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
55875+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
55876+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
55877+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
55878+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
55879+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
55880+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
55881+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
55882+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
55883+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
55884+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
55885+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
55886+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
55887+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
55888+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
55889+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
55890+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
55891+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
55892+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
55893+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
55894+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
55895+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
55896+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
55897+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
55898+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
55899+ };
55900+
55901+static const char * gr_socktypes[SOCK_MAX] = {
55902+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
55903+ "unknown:7", "unknown:8", "unknown:9", "packet"
55904+ };
55905+
55906+static const char * gr_sockfamilies[AF_MAX+1] = {
55907+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
55908+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
55909+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
55910+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
55911+ };
55912+
55913+const char *
55914+gr_proto_to_name(unsigned char proto)
55915+{
55916+ return gr_protocols[proto];
55917+}
55918+
55919+const char *
55920+gr_socktype_to_name(unsigned char type)
55921+{
55922+ return gr_socktypes[type];
55923+}
55924+
55925+const char *
55926+gr_sockfamily_to_name(unsigned char family)
55927+{
55928+ return gr_sockfamilies[family];
55929+}
55930+
55931+int
55932+gr_search_socket(const int domain, const int type, const int protocol)
55933+{
55934+ struct acl_subject_label *curr;
55935+ const struct cred *cred = current_cred();
55936+
55937+ if (unlikely(!gr_acl_is_enabled()))
55938+ goto exit;
55939+
55940+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
55941+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
55942+ goto exit; // let the kernel handle it
55943+
55944+ curr = current->acl;
55945+
55946+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
55947+ /* the family is allowed, if this is PF_INET allow it only if
55948+ the extra sock type/protocol checks pass */
55949+ if (domain == PF_INET)
55950+ goto inet_check;
55951+ goto exit;
55952+ } else {
55953+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55954+ __u32 fakeip = 0;
55955+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55956+ current->role->roletype, cred->uid,
55957+ cred->gid, current->exec_file ?
55958+ gr_to_filename(current->exec_file->f_path.dentry,
55959+ current->exec_file->f_path.mnt) :
55960+ curr->filename, curr->filename,
55961+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
55962+ &current->signal->saved_ip);
55963+ goto exit;
55964+ }
55965+ goto exit_fail;
55966+ }
55967+
55968+inet_check:
55969+ /* the rest of this checking is for IPv4 only */
55970+ if (!curr->ips)
55971+ goto exit;
55972+
55973+ if ((curr->ip_type & (1 << type)) &&
55974+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
55975+ goto exit;
55976+
55977+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55978+ /* we don't place acls on raw sockets , and sometimes
55979+ dgram/ip sockets are opened for ioctl and not
55980+ bind/connect, so we'll fake a bind learn log */
55981+ if (type == SOCK_RAW || type == SOCK_PACKET) {
55982+ __u32 fakeip = 0;
55983+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55984+ current->role->roletype, cred->uid,
55985+ cred->gid, current->exec_file ?
55986+ gr_to_filename(current->exec_file->f_path.dentry,
55987+ current->exec_file->f_path.mnt) :
55988+ curr->filename, curr->filename,
55989+ &fakeip, 0, type,
55990+ protocol, GR_CONNECT, &current->signal->saved_ip);
55991+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
55992+ __u32 fakeip = 0;
55993+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55994+ current->role->roletype, cred->uid,
55995+ cred->gid, current->exec_file ?
55996+ gr_to_filename(current->exec_file->f_path.dentry,
55997+ current->exec_file->f_path.mnt) :
55998+ curr->filename, curr->filename,
55999+ &fakeip, 0, type,
56000+ protocol, GR_BIND, &current->signal->saved_ip);
56001+ }
56002+ /* we'll log when they use connect or bind */
56003+ goto exit;
56004+ }
56005+
56006+exit_fail:
56007+ if (domain == PF_INET)
56008+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
56009+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
56010+ else
56011+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
56012+ gr_socktype_to_name(type), protocol);
56013+
56014+ return 0;
56015+exit:
56016+ return 1;
56017+}
56018+
56019+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)
56020+{
56021+ if ((ip->mode & mode) &&
56022+ (ip_port >= ip->low) &&
56023+ (ip_port <= ip->high) &&
56024+ ((ntohl(ip_addr) & our_netmask) ==
56025+ (ntohl(our_addr) & our_netmask))
56026+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
56027+ && (ip->type & (1 << type))) {
56028+ if (ip->mode & GR_INVERT)
56029+ return 2; // specifically denied
56030+ else
56031+ return 1; // allowed
56032+ }
56033+
56034+ return 0; // not specifically allowed, may continue parsing
56035+}
56036+
56037+static int
56038+gr_search_connectbind(const int full_mode, struct sock *sk,
56039+ struct sockaddr_in *addr, const int type)
56040+{
56041+ char iface[IFNAMSIZ] = {0};
56042+ struct acl_subject_label *curr;
56043+ struct acl_ip_label *ip;
56044+ struct inet_sock *isk;
56045+ struct net_device *dev;
56046+ struct in_device *idev;
56047+ unsigned long i;
56048+ int ret;
56049+ int mode = full_mode & (GR_BIND | GR_CONNECT);
56050+ __u32 ip_addr = 0;
56051+ __u32 our_addr;
56052+ __u32 our_netmask;
56053+ char *p;
56054+ __u16 ip_port = 0;
56055+ const struct cred *cred = current_cred();
56056+
56057+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
56058+ return 0;
56059+
56060+ curr = current->acl;
56061+ isk = inet_sk(sk);
56062+
56063+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
56064+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
56065+ addr->sin_addr.s_addr = curr->inaddr_any_override;
56066+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
56067+ struct sockaddr_in saddr;
56068+ int err;
56069+
56070+ saddr.sin_family = AF_INET;
56071+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
56072+ saddr.sin_port = isk->inet_sport;
56073+
56074+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56075+ if (err)
56076+ return err;
56077+
56078+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56079+ if (err)
56080+ return err;
56081+ }
56082+
56083+ if (!curr->ips)
56084+ return 0;
56085+
56086+ ip_addr = addr->sin_addr.s_addr;
56087+ ip_port = ntohs(addr->sin_port);
56088+
56089+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56090+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56091+ current->role->roletype, cred->uid,
56092+ cred->gid, current->exec_file ?
56093+ gr_to_filename(current->exec_file->f_path.dentry,
56094+ current->exec_file->f_path.mnt) :
56095+ curr->filename, curr->filename,
56096+ &ip_addr, ip_port, type,
56097+ sk->sk_protocol, mode, &current->signal->saved_ip);
56098+ return 0;
56099+ }
56100+
56101+ for (i = 0; i < curr->ip_num; i++) {
56102+ ip = *(curr->ips + i);
56103+ if (ip->iface != NULL) {
56104+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
56105+ p = strchr(iface, ':');
56106+ if (p != NULL)
56107+ *p = '\0';
56108+ dev = dev_get_by_name(sock_net(sk), iface);
56109+ if (dev == NULL)
56110+ continue;
56111+ idev = in_dev_get(dev);
56112+ if (idev == NULL) {
56113+ dev_put(dev);
56114+ continue;
56115+ }
56116+ rcu_read_lock();
56117+ for_ifa(idev) {
56118+ if (!strcmp(ip->iface, ifa->ifa_label)) {
56119+ our_addr = ifa->ifa_address;
56120+ our_netmask = 0xffffffff;
56121+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56122+ if (ret == 1) {
56123+ rcu_read_unlock();
56124+ in_dev_put(idev);
56125+ dev_put(dev);
56126+ return 0;
56127+ } else if (ret == 2) {
56128+ rcu_read_unlock();
56129+ in_dev_put(idev);
56130+ dev_put(dev);
56131+ goto denied;
56132+ }
56133+ }
56134+ } endfor_ifa(idev);
56135+ rcu_read_unlock();
56136+ in_dev_put(idev);
56137+ dev_put(dev);
56138+ } else {
56139+ our_addr = ip->addr;
56140+ our_netmask = ip->netmask;
56141+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56142+ if (ret == 1)
56143+ return 0;
56144+ else if (ret == 2)
56145+ goto denied;
56146+ }
56147+ }
56148+
56149+denied:
56150+ if (mode == GR_BIND)
56151+ 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));
56152+ else if (mode == GR_CONNECT)
56153+ 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));
56154+
56155+ return -EACCES;
56156+}
56157+
56158+int
56159+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56160+{
56161+ /* always allow disconnection of dgram sockets with connect */
56162+ if (addr->sin_family == AF_UNSPEC)
56163+ return 0;
56164+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56165+}
56166+
56167+int
56168+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56169+{
56170+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56171+}
56172+
56173+int gr_search_listen(struct socket *sock)
56174+{
56175+ struct sock *sk = sock->sk;
56176+ struct sockaddr_in addr;
56177+
56178+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56179+ addr.sin_port = inet_sk(sk)->inet_sport;
56180+
56181+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56182+}
56183+
56184+int gr_search_accept(struct socket *sock)
56185+{
56186+ struct sock *sk = sock->sk;
56187+ struct sockaddr_in addr;
56188+
56189+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56190+ addr.sin_port = inet_sk(sk)->inet_sport;
56191+
56192+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56193+}
56194+
56195+int
56196+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56197+{
56198+ if (addr)
56199+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56200+ else {
56201+ struct sockaddr_in sin;
56202+ const struct inet_sock *inet = inet_sk(sk);
56203+
56204+ sin.sin_addr.s_addr = inet->inet_daddr;
56205+ sin.sin_port = inet->inet_dport;
56206+
56207+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56208+ }
56209+}
56210+
56211+int
56212+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56213+{
56214+ struct sockaddr_in sin;
56215+
56216+ if (unlikely(skb->len < sizeof (struct udphdr)))
56217+ return 0; // skip this packet
56218+
56219+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56220+ sin.sin_port = udp_hdr(skb)->source;
56221+
56222+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56223+}
56224diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
56225new file mode 100644
56226index 0000000..25f54ef
56227--- /dev/null
56228+++ b/grsecurity/gracl_learn.c
56229@@ -0,0 +1,207 @@
56230+#include <linux/kernel.h>
56231+#include <linux/mm.h>
56232+#include <linux/sched.h>
56233+#include <linux/poll.h>
56234+#include <linux/string.h>
56235+#include <linux/file.h>
56236+#include <linux/types.h>
56237+#include <linux/vmalloc.h>
56238+#include <linux/grinternal.h>
56239+
56240+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56241+ size_t count, loff_t *ppos);
56242+extern int gr_acl_is_enabled(void);
56243+
56244+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56245+static int gr_learn_attached;
56246+
56247+/* use a 512k buffer */
56248+#define LEARN_BUFFER_SIZE (512 * 1024)
56249+
56250+static DEFINE_SPINLOCK(gr_learn_lock);
56251+static DEFINE_MUTEX(gr_learn_user_mutex);
56252+
56253+/* we need to maintain two buffers, so that the kernel context of grlearn
56254+ uses a semaphore around the userspace copying, and the other kernel contexts
56255+ use a spinlock when copying into the buffer, since they cannot sleep
56256+*/
56257+static char *learn_buffer;
56258+static char *learn_buffer_user;
56259+static int learn_buffer_len;
56260+static int learn_buffer_user_len;
56261+
56262+static ssize_t
56263+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56264+{
56265+ DECLARE_WAITQUEUE(wait, current);
56266+ ssize_t retval = 0;
56267+
56268+ add_wait_queue(&learn_wait, &wait);
56269+ set_current_state(TASK_INTERRUPTIBLE);
56270+ do {
56271+ mutex_lock(&gr_learn_user_mutex);
56272+ spin_lock(&gr_learn_lock);
56273+ if (learn_buffer_len)
56274+ break;
56275+ spin_unlock(&gr_learn_lock);
56276+ mutex_unlock(&gr_learn_user_mutex);
56277+ if (file->f_flags & O_NONBLOCK) {
56278+ retval = -EAGAIN;
56279+ goto out;
56280+ }
56281+ if (signal_pending(current)) {
56282+ retval = -ERESTARTSYS;
56283+ goto out;
56284+ }
56285+
56286+ schedule();
56287+ } while (1);
56288+
56289+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56290+ learn_buffer_user_len = learn_buffer_len;
56291+ retval = learn_buffer_len;
56292+ learn_buffer_len = 0;
56293+
56294+ spin_unlock(&gr_learn_lock);
56295+
56296+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56297+ retval = -EFAULT;
56298+
56299+ mutex_unlock(&gr_learn_user_mutex);
56300+out:
56301+ set_current_state(TASK_RUNNING);
56302+ remove_wait_queue(&learn_wait, &wait);
56303+ return retval;
56304+}
56305+
56306+static unsigned int
56307+poll_learn(struct file * file, poll_table * wait)
56308+{
56309+ poll_wait(file, &learn_wait, wait);
56310+
56311+ if (learn_buffer_len)
56312+ return (POLLIN | POLLRDNORM);
56313+
56314+ return 0;
56315+}
56316+
56317+void
56318+gr_clear_learn_entries(void)
56319+{
56320+ char *tmp;
56321+
56322+ mutex_lock(&gr_learn_user_mutex);
56323+ spin_lock(&gr_learn_lock);
56324+ tmp = learn_buffer;
56325+ learn_buffer = NULL;
56326+ spin_unlock(&gr_learn_lock);
56327+ if (tmp)
56328+ vfree(tmp);
56329+ if (learn_buffer_user != NULL) {
56330+ vfree(learn_buffer_user);
56331+ learn_buffer_user = NULL;
56332+ }
56333+ learn_buffer_len = 0;
56334+ mutex_unlock(&gr_learn_user_mutex);
56335+
56336+ return;
56337+}
56338+
56339+void
56340+gr_add_learn_entry(const char *fmt, ...)
56341+{
56342+ va_list args;
56343+ unsigned int len;
56344+
56345+ if (!gr_learn_attached)
56346+ return;
56347+
56348+ spin_lock(&gr_learn_lock);
56349+
56350+ /* leave a gap at the end so we know when it's "full" but don't have to
56351+ compute the exact length of the string we're trying to append
56352+ */
56353+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56354+ spin_unlock(&gr_learn_lock);
56355+ wake_up_interruptible(&learn_wait);
56356+ return;
56357+ }
56358+ if (learn_buffer == NULL) {
56359+ spin_unlock(&gr_learn_lock);
56360+ return;
56361+ }
56362+
56363+ va_start(args, fmt);
56364+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56365+ va_end(args);
56366+
56367+ learn_buffer_len += len + 1;
56368+
56369+ spin_unlock(&gr_learn_lock);
56370+ wake_up_interruptible(&learn_wait);
56371+
56372+ return;
56373+}
56374+
56375+static int
56376+open_learn(struct inode *inode, struct file *file)
56377+{
56378+ if (file->f_mode & FMODE_READ && gr_learn_attached)
56379+ return -EBUSY;
56380+ if (file->f_mode & FMODE_READ) {
56381+ int retval = 0;
56382+ mutex_lock(&gr_learn_user_mutex);
56383+ if (learn_buffer == NULL)
56384+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56385+ if (learn_buffer_user == NULL)
56386+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56387+ if (learn_buffer == NULL) {
56388+ retval = -ENOMEM;
56389+ goto out_error;
56390+ }
56391+ if (learn_buffer_user == NULL) {
56392+ retval = -ENOMEM;
56393+ goto out_error;
56394+ }
56395+ learn_buffer_len = 0;
56396+ learn_buffer_user_len = 0;
56397+ gr_learn_attached = 1;
56398+out_error:
56399+ mutex_unlock(&gr_learn_user_mutex);
56400+ return retval;
56401+ }
56402+ return 0;
56403+}
56404+
56405+static int
56406+close_learn(struct inode *inode, struct file *file)
56407+{
56408+ if (file->f_mode & FMODE_READ) {
56409+ char *tmp = NULL;
56410+ mutex_lock(&gr_learn_user_mutex);
56411+ spin_lock(&gr_learn_lock);
56412+ tmp = learn_buffer;
56413+ learn_buffer = NULL;
56414+ spin_unlock(&gr_learn_lock);
56415+ if (tmp)
56416+ vfree(tmp);
56417+ if (learn_buffer_user != NULL) {
56418+ vfree(learn_buffer_user);
56419+ learn_buffer_user = NULL;
56420+ }
56421+ learn_buffer_len = 0;
56422+ learn_buffer_user_len = 0;
56423+ gr_learn_attached = 0;
56424+ mutex_unlock(&gr_learn_user_mutex);
56425+ }
56426+
56427+ return 0;
56428+}
56429+
56430+const struct file_operations grsec_fops = {
56431+ .read = read_learn,
56432+ .write = write_grsec_handler,
56433+ .open = open_learn,
56434+ .release = close_learn,
56435+ .poll = poll_learn,
56436+};
56437diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
56438new file mode 100644
56439index 0000000..39645c9
56440--- /dev/null
56441+++ b/grsecurity/gracl_res.c
56442@@ -0,0 +1,68 @@
56443+#include <linux/kernel.h>
56444+#include <linux/sched.h>
56445+#include <linux/gracl.h>
56446+#include <linux/grinternal.h>
56447+
56448+static const char *restab_log[] = {
56449+ [RLIMIT_CPU] = "RLIMIT_CPU",
56450+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56451+ [RLIMIT_DATA] = "RLIMIT_DATA",
56452+ [RLIMIT_STACK] = "RLIMIT_STACK",
56453+ [RLIMIT_CORE] = "RLIMIT_CORE",
56454+ [RLIMIT_RSS] = "RLIMIT_RSS",
56455+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
56456+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56457+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56458+ [RLIMIT_AS] = "RLIMIT_AS",
56459+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56460+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56461+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56462+ [RLIMIT_NICE] = "RLIMIT_NICE",
56463+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56464+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56465+ [GR_CRASH_RES] = "RLIMIT_CRASH"
56466+};
56467+
56468+void
56469+gr_log_resource(const struct task_struct *task,
56470+ const int res, const unsigned long wanted, const int gt)
56471+{
56472+ const struct cred *cred;
56473+ unsigned long rlim;
56474+
56475+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
56476+ return;
56477+
56478+ // not yet supported resource
56479+ if (unlikely(!restab_log[res]))
56480+ return;
56481+
56482+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56483+ rlim = task_rlimit_max(task, res);
56484+ else
56485+ rlim = task_rlimit(task, res);
56486+
56487+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
56488+ return;
56489+
56490+ rcu_read_lock();
56491+ cred = __task_cred(task);
56492+
56493+ if (res == RLIMIT_NPROC &&
56494+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
56495+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
56496+ goto out_rcu_unlock;
56497+ else if (res == RLIMIT_MEMLOCK &&
56498+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
56499+ goto out_rcu_unlock;
56500+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
56501+ goto out_rcu_unlock;
56502+ rcu_read_unlock();
56503+
56504+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
56505+
56506+ return;
56507+out_rcu_unlock:
56508+ rcu_read_unlock();
56509+ return;
56510+}
56511diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
56512new file mode 100644
56513index 0000000..25197e9
56514--- /dev/null
56515+++ b/grsecurity/gracl_segv.c
56516@@ -0,0 +1,299 @@
56517+#include <linux/kernel.h>
56518+#include <linux/mm.h>
56519+#include <asm/uaccess.h>
56520+#include <asm/errno.h>
56521+#include <asm/mman.h>
56522+#include <net/sock.h>
56523+#include <linux/file.h>
56524+#include <linux/fs.h>
56525+#include <linux/net.h>
56526+#include <linux/in.h>
56527+#include <linux/slab.h>
56528+#include <linux/types.h>
56529+#include <linux/sched.h>
56530+#include <linux/timer.h>
56531+#include <linux/gracl.h>
56532+#include <linux/grsecurity.h>
56533+#include <linux/grinternal.h>
56534+
56535+static struct crash_uid *uid_set;
56536+static unsigned short uid_used;
56537+static DEFINE_SPINLOCK(gr_uid_lock);
56538+extern rwlock_t gr_inode_lock;
56539+extern struct acl_subject_label *
56540+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
56541+ struct acl_role_label *role);
56542+
56543+#ifdef CONFIG_BTRFS_FS
56544+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56545+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56546+#endif
56547+
56548+static inline dev_t __get_dev(const struct dentry *dentry)
56549+{
56550+#ifdef CONFIG_BTRFS_FS
56551+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56552+ return get_btrfs_dev_from_inode(dentry->d_inode);
56553+ else
56554+#endif
56555+ return dentry->d_inode->i_sb->s_dev;
56556+}
56557+
56558+int
56559+gr_init_uidset(void)
56560+{
56561+ uid_set =
56562+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56563+ uid_used = 0;
56564+
56565+ return uid_set ? 1 : 0;
56566+}
56567+
56568+void
56569+gr_free_uidset(void)
56570+{
56571+ if (uid_set)
56572+ kfree(uid_set);
56573+
56574+ return;
56575+}
56576+
56577+int
56578+gr_find_uid(const uid_t uid)
56579+{
56580+ struct crash_uid *tmp = uid_set;
56581+ uid_t buid;
56582+ int low = 0, high = uid_used - 1, mid;
56583+
56584+ while (high >= low) {
56585+ mid = (low + high) >> 1;
56586+ buid = tmp[mid].uid;
56587+ if (buid == uid)
56588+ return mid;
56589+ if (buid > uid)
56590+ high = mid - 1;
56591+ if (buid < uid)
56592+ low = mid + 1;
56593+ }
56594+
56595+ return -1;
56596+}
56597+
56598+static __inline__ void
56599+gr_insertsort(void)
56600+{
56601+ unsigned short i, j;
56602+ struct crash_uid index;
56603+
56604+ for (i = 1; i < uid_used; i++) {
56605+ index = uid_set[i];
56606+ j = i;
56607+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
56608+ uid_set[j] = uid_set[j - 1];
56609+ j--;
56610+ }
56611+ uid_set[j] = index;
56612+ }
56613+
56614+ return;
56615+}
56616+
56617+static __inline__ void
56618+gr_insert_uid(const uid_t uid, const unsigned long expires)
56619+{
56620+ int loc;
56621+
56622+ if (uid_used == GR_UIDTABLE_MAX)
56623+ return;
56624+
56625+ loc = gr_find_uid(uid);
56626+
56627+ if (loc >= 0) {
56628+ uid_set[loc].expires = expires;
56629+ return;
56630+ }
56631+
56632+ uid_set[uid_used].uid = uid;
56633+ uid_set[uid_used].expires = expires;
56634+ uid_used++;
56635+
56636+ gr_insertsort();
56637+
56638+ return;
56639+}
56640+
56641+void
56642+gr_remove_uid(const unsigned short loc)
56643+{
56644+ unsigned short i;
56645+
56646+ for (i = loc + 1; i < uid_used; i++)
56647+ uid_set[i - 1] = uid_set[i];
56648+
56649+ uid_used--;
56650+
56651+ return;
56652+}
56653+
56654+int
56655+gr_check_crash_uid(const uid_t uid)
56656+{
56657+ int loc;
56658+ int ret = 0;
56659+
56660+ if (unlikely(!gr_acl_is_enabled()))
56661+ return 0;
56662+
56663+ spin_lock(&gr_uid_lock);
56664+ loc = gr_find_uid(uid);
56665+
56666+ if (loc < 0)
56667+ goto out_unlock;
56668+
56669+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
56670+ gr_remove_uid(loc);
56671+ else
56672+ ret = 1;
56673+
56674+out_unlock:
56675+ spin_unlock(&gr_uid_lock);
56676+ return ret;
56677+}
56678+
56679+static __inline__ int
56680+proc_is_setxid(const struct cred *cred)
56681+{
56682+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
56683+ !uid_eq(cred->uid, cred->fsuid))
56684+ return 1;
56685+ if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
56686+ !uid_eq(cred->gid, cred->fsgid))
56687+ return 1;
56688+
56689+ return 0;
56690+}
56691+
56692+extern int gr_fake_force_sig(int sig, struct task_struct *t);
56693+
56694+void
56695+gr_handle_crash(struct task_struct *task, const int sig)
56696+{
56697+ struct acl_subject_label *curr;
56698+ struct task_struct *tsk, *tsk2;
56699+ const struct cred *cred;
56700+ const struct cred *cred2;
56701+
56702+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
56703+ return;
56704+
56705+ if (unlikely(!gr_acl_is_enabled()))
56706+ return;
56707+
56708+ curr = task->acl;
56709+
56710+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
56711+ return;
56712+
56713+ if (time_before_eq(curr->expires, get_seconds())) {
56714+ curr->expires = 0;
56715+ curr->crashes = 0;
56716+ }
56717+
56718+ curr->crashes++;
56719+
56720+ if (!curr->expires)
56721+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
56722+
56723+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56724+ time_after(curr->expires, get_seconds())) {
56725+ rcu_read_lock();
56726+ cred = __task_cred(task);
56727+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
56728+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56729+ spin_lock(&gr_uid_lock);
56730+ gr_insert_uid(cred->uid, curr->expires);
56731+ spin_unlock(&gr_uid_lock);
56732+ curr->expires = 0;
56733+ curr->crashes = 0;
56734+ read_lock(&tasklist_lock);
56735+ do_each_thread(tsk2, tsk) {
56736+ cred2 = __task_cred(tsk);
56737+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
56738+ gr_fake_force_sig(SIGKILL, tsk);
56739+ } while_each_thread(tsk2, tsk);
56740+ read_unlock(&tasklist_lock);
56741+ } else {
56742+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56743+ read_lock(&tasklist_lock);
56744+ read_lock(&grsec_exec_file_lock);
56745+ do_each_thread(tsk2, tsk) {
56746+ if (likely(tsk != task)) {
56747+ // if this thread has the same subject as the one that triggered
56748+ // RES_CRASH and it's the same binary, kill it
56749+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
56750+ gr_fake_force_sig(SIGKILL, tsk);
56751+ }
56752+ } while_each_thread(tsk2, tsk);
56753+ read_unlock(&grsec_exec_file_lock);
56754+ read_unlock(&tasklist_lock);
56755+ }
56756+ rcu_read_unlock();
56757+ }
56758+
56759+ return;
56760+}
56761+
56762+int
56763+gr_check_crash_exec(const struct file *filp)
56764+{
56765+ struct acl_subject_label *curr;
56766+
56767+ if (unlikely(!gr_acl_is_enabled()))
56768+ return 0;
56769+
56770+ read_lock(&gr_inode_lock);
56771+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
56772+ __get_dev(filp->f_path.dentry),
56773+ current->role);
56774+ read_unlock(&gr_inode_lock);
56775+
56776+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
56777+ (!curr->crashes && !curr->expires))
56778+ return 0;
56779+
56780+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56781+ time_after(curr->expires, get_seconds()))
56782+ return 1;
56783+ else if (time_before_eq(curr->expires, get_seconds())) {
56784+ curr->crashes = 0;
56785+ curr->expires = 0;
56786+ }
56787+
56788+ return 0;
56789+}
56790+
56791+void
56792+gr_handle_alertkill(struct task_struct *task)
56793+{
56794+ struct acl_subject_label *curracl;
56795+ __u32 curr_ip;
56796+ struct task_struct *p, *p2;
56797+
56798+ if (unlikely(!gr_acl_is_enabled()))
56799+ return;
56800+
56801+ curracl = task->acl;
56802+ curr_ip = task->signal->curr_ip;
56803+
56804+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
56805+ read_lock(&tasklist_lock);
56806+ do_each_thread(p2, p) {
56807+ if (p->signal->curr_ip == curr_ip)
56808+ gr_fake_force_sig(SIGKILL, p);
56809+ } while_each_thread(p2, p);
56810+ read_unlock(&tasklist_lock);
56811+ } else if (curracl->mode & GR_KILLPROC)
56812+ gr_fake_force_sig(SIGKILL, task);
56813+
56814+ return;
56815+}
56816diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
56817new file mode 100644
56818index 0000000..9d83a69
56819--- /dev/null
56820+++ b/grsecurity/gracl_shm.c
56821@@ -0,0 +1,40 @@
56822+#include <linux/kernel.h>
56823+#include <linux/mm.h>
56824+#include <linux/sched.h>
56825+#include <linux/file.h>
56826+#include <linux/ipc.h>
56827+#include <linux/gracl.h>
56828+#include <linux/grsecurity.h>
56829+#include <linux/grinternal.h>
56830+
56831+int
56832+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56833+ const time_t shm_createtime, const uid_t cuid, const int shmid)
56834+{
56835+ struct task_struct *task;
56836+
56837+ if (!gr_acl_is_enabled())
56838+ return 1;
56839+
56840+ rcu_read_lock();
56841+ read_lock(&tasklist_lock);
56842+
56843+ task = find_task_by_vpid(shm_cprid);
56844+
56845+ if (unlikely(!task))
56846+ task = find_task_by_vpid(shm_lapid);
56847+
56848+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
56849+ (task->pid == shm_lapid)) &&
56850+ (task->acl->mode & GR_PROTSHM) &&
56851+ (task->acl != current->acl))) {
56852+ read_unlock(&tasklist_lock);
56853+ rcu_read_unlock();
56854+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
56855+ return 0;
56856+ }
56857+ read_unlock(&tasklist_lock);
56858+ rcu_read_unlock();
56859+
56860+ return 1;
56861+}
56862diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
56863new file mode 100644
56864index 0000000..bc0be01
56865--- /dev/null
56866+++ b/grsecurity/grsec_chdir.c
56867@@ -0,0 +1,19 @@
56868+#include <linux/kernel.h>
56869+#include <linux/sched.h>
56870+#include <linux/fs.h>
56871+#include <linux/file.h>
56872+#include <linux/grsecurity.h>
56873+#include <linux/grinternal.h>
56874+
56875+void
56876+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
56877+{
56878+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
56879+ if ((grsec_enable_chdir && grsec_enable_group &&
56880+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
56881+ !grsec_enable_group)) {
56882+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
56883+ }
56884+#endif
56885+ return;
56886+}
56887diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
56888new file mode 100644
56889index 0000000..9807ee2
56890--- /dev/null
56891+++ b/grsecurity/grsec_chroot.c
56892@@ -0,0 +1,368 @@
56893+#include <linux/kernel.h>
56894+#include <linux/module.h>
56895+#include <linux/sched.h>
56896+#include <linux/file.h>
56897+#include <linux/fs.h>
56898+#include <linux/mount.h>
56899+#include <linux/types.h>
56900+#include "../fs/mount.h"
56901+#include <linux/grsecurity.h>
56902+#include <linux/grinternal.h>
56903+
56904+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
56905+{
56906+#ifdef CONFIG_GRKERNSEC
56907+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
56908+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
56909+ task->gr_is_chrooted = 1;
56910+ else
56911+ task->gr_is_chrooted = 0;
56912+
56913+ task->gr_chroot_dentry = path->dentry;
56914+#endif
56915+ return;
56916+}
56917+
56918+void gr_clear_chroot_entries(struct task_struct *task)
56919+{
56920+#ifdef CONFIG_GRKERNSEC
56921+ task->gr_is_chrooted = 0;
56922+ task->gr_chroot_dentry = NULL;
56923+#endif
56924+ return;
56925+}
56926+
56927+int
56928+gr_handle_chroot_unix(const pid_t pid)
56929+{
56930+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
56931+ struct task_struct *p;
56932+
56933+ if (unlikely(!grsec_enable_chroot_unix))
56934+ return 1;
56935+
56936+ if (likely(!proc_is_chrooted(current)))
56937+ return 1;
56938+
56939+ rcu_read_lock();
56940+ read_lock(&tasklist_lock);
56941+ p = find_task_by_vpid_unrestricted(pid);
56942+ if (unlikely(p && !have_same_root(current, p))) {
56943+ read_unlock(&tasklist_lock);
56944+ rcu_read_unlock();
56945+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
56946+ return 0;
56947+ }
56948+ read_unlock(&tasklist_lock);
56949+ rcu_read_unlock();
56950+#endif
56951+ return 1;
56952+}
56953+
56954+int
56955+gr_handle_chroot_nice(void)
56956+{
56957+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56958+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
56959+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
56960+ return -EPERM;
56961+ }
56962+#endif
56963+ return 0;
56964+}
56965+
56966+int
56967+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
56968+{
56969+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56970+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
56971+ && proc_is_chrooted(current)) {
56972+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
56973+ return -EACCES;
56974+ }
56975+#endif
56976+ return 0;
56977+}
56978+
56979+int
56980+gr_handle_chroot_rawio(const struct inode *inode)
56981+{
56982+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56983+ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
56984+ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
56985+ return 1;
56986+#endif
56987+ return 0;
56988+}
56989+
56990+int
56991+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
56992+{
56993+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56994+ struct task_struct *p;
56995+ int ret = 0;
56996+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
56997+ return ret;
56998+
56999+ read_lock(&tasklist_lock);
57000+ do_each_pid_task(pid, type, p) {
57001+ if (!have_same_root(current, p)) {
57002+ ret = 1;
57003+ goto out;
57004+ }
57005+ } while_each_pid_task(pid, type, p);
57006+out:
57007+ read_unlock(&tasklist_lock);
57008+ return ret;
57009+#endif
57010+ return 0;
57011+}
57012+
57013+int
57014+gr_pid_is_chrooted(struct task_struct *p)
57015+{
57016+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57017+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
57018+ return 0;
57019+
57020+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
57021+ !have_same_root(current, p)) {
57022+ return 1;
57023+ }
57024+#endif
57025+ return 0;
57026+}
57027+
57028+EXPORT_SYMBOL(gr_pid_is_chrooted);
57029+
57030+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
57031+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
57032+{
57033+ struct path path, currentroot;
57034+ int ret = 0;
57035+
57036+ path.dentry = (struct dentry *)u_dentry;
57037+ path.mnt = (struct vfsmount *)u_mnt;
57038+ get_fs_root(current->fs, &currentroot);
57039+ if (path_is_under(&path, &currentroot))
57040+ ret = 1;
57041+ path_put(&currentroot);
57042+
57043+ return ret;
57044+}
57045+#endif
57046+
57047+int
57048+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
57049+{
57050+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57051+ if (!grsec_enable_chroot_fchdir)
57052+ return 1;
57053+
57054+ if (!proc_is_chrooted(current))
57055+ return 1;
57056+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
57057+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
57058+ return 0;
57059+ }
57060+#endif
57061+ return 1;
57062+}
57063+
57064+int
57065+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57066+ const time_t shm_createtime)
57067+{
57068+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57069+ struct task_struct *p;
57070+ time_t starttime;
57071+
57072+ if (unlikely(!grsec_enable_chroot_shmat))
57073+ return 1;
57074+
57075+ if (likely(!proc_is_chrooted(current)))
57076+ return 1;
57077+
57078+ rcu_read_lock();
57079+ read_lock(&tasklist_lock);
57080+
57081+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
57082+ starttime = p->start_time.tv_sec;
57083+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
57084+ if (have_same_root(current, p)) {
57085+ goto allow;
57086+ } else {
57087+ read_unlock(&tasklist_lock);
57088+ rcu_read_unlock();
57089+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57090+ return 0;
57091+ }
57092+ }
57093+ /* creator exited, pid reuse, fall through to next check */
57094+ }
57095+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
57096+ if (unlikely(!have_same_root(current, p))) {
57097+ read_unlock(&tasklist_lock);
57098+ rcu_read_unlock();
57099+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57100+ return 0;
57101+ }
57102+ }
57103+
57104+allow:
57105+ read_unlock(&tasklist_lock);
57106+ rcu_read_unlock();
57107+#endif
57108+ return 1;
57109+}
57110+
57111+void
57112+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
57113+{
57114+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57115+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
57116+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
57117+#endif
57118+ return;
57119+}
57120+
57121+int
57122+gr_handle_chroot_mknod(const struct dentry *dentry,
57123+ const struct vfsmount *mnt, const int mode)
57124+{
57125+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57126+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
57127+ proc_is_chrooted(current)) {
57128+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57129+ return -EPERM;
57130+ }
57131+#endif
57132+ return 0;
57133+}
57134+
57135+int
57136+gr_handle_chroot_mount(const struct dentry *dentry,
57137+ const struct vfsmount *mnt, const char *dev_name)
57138+{
57139+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57140+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57141+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
57142+ return -EPERM;
57143+ }
57144+#endif
57145+ return 0;
57146+}
57147+
57148+int
57149+gr_handle_chroot_pivot(void)
57150+{
57151+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57152+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57153+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57154+ return -EPERM;
57155+ }
57156+#endif
57157+ return 0;
57158+}
57159+
57160+int
57161+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57162+{
57163+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57164+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57165+ !gr_is_outside_chroot(dentry, mnt)) {
57166+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57167+ return -EPERM;
57168+ }
57169+#endif
57170+ return 0;
57171+}
57172+
57173+extern const char *captab_log[];
57174+extern int captab_log_entries;
57175+
57176+int
57177+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57178+{
57179+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57180+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57181+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57182+ if (cap_raised(chroot_caps, cap)) {
57183+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
57184+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
57185+ }
57186+ return 0;
57187+ }
57188+ }
57189+#endif
57190+ return 1;
57191+}
57192+
57193+int
57194+gr_chroot_is_capable(const int cap)
57195+{
57196+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57197+ return gr_task_chroot_is_capable(current, current_cred(), cap);
57198+#endif
57199+ return 1;
57200+}
57201+
57202+int
57203+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
57204+{
57205+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57206+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57207+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57208+ if (cap_raised(chroot_caps, cap)) {
57209+ return 0;
57210+ }
57211+ }
57212+#endif
57213+ return 1;
57214+}
57215+
57216+int
57217+gr_chroot_is_capable_nolog(const int cap)
57218+{
57219+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57220+ return gr_task_chroot_is_capable_nolog(current, cap);
57221+#endif
57222+ return 1;
57223+}
57224+
57225+int
57226+gr_handle_chroot_sysctl(const int op)
57227+{
57228+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57229+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57230+ proc_is_chrooted(current))
57231+ return -EACCES;
57232+#endif
57233+ return 0;
57234+}
57235+
57236+void
57237+gr_handle_chroot_chdir(struct path *path)
57238+{
57239+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57240+ if (grsec_enable_chroot_chdir)
57241+ set_fs_pwd(current->fs, path);
57242+#endif
57243+ return;
57244+}
57245+
57246+int
57247+gr_handle_chroot_chmod(const struct dentry *dentry,
57248+ const struct vfsmount *mnt, const int mode)
57249+{
57250+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57251+ /* allow chmod +s on directories, but not files */
57252+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57253+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57254+ proc_is_chrooted(current)) {
57255+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57256+ return -EPERM;
57257+ }
57258+#endif
57259+ return 0;
57260+}
57261diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
57262new file mode 100644
57263index 0000000..213ad8b
57264--- /dev/null
57265+++ b/grsecurity/grsec_disabled.c
57266@@ -0,0 +1,437 @@
57267+#include <linux/kernel.h>
57268+#include <linux/module.h>
57269+#include <linux/sched.h>
57270+#include <linux/file.h>
57271+#include <linux/fs.h>
57272+#include <linux/kdev_t.h>
57273+#include <linux/net.h>
57274+#include <linux/in.h>
57275+#include <linux/ip.h>
57276+#include <linux/skbuff.h>
57277+#include <linux/sysctl.h>
57278+
57279+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57280+void
57281+pax_set_initial_flags(struct linux_binprm *bprm)
57282+{
57283+ return;
57284+}
57285+#endif
57286+
57287+#ifdef CONFIG_SYSCTL
57288+__u32
57289+gr_handle_sysctl(const struct ctl_table * table, const int op)
57290+{
57291+ return 0;
57292+}
57293+#endif
57294+
57295+#ifdef CONFIG_TASKSTATS
57296+int gr_is_taskstats_denied(int pid)
57297+{
57298+ return 0;
57299+}
57300+#endif
57301+
57302+int
57303+gr_acl_is_enabled(void)
57304+{
57305+ return 0;
57306+}
57307+
57308+void
57309+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57310+{
57311+ return;
57312+}
57313+
57314+int
57315+gr_handle_rawio(const struct inode *inode)
57316+{
57317+ return 0;
57318+}
57319+
57320+void
57321+gr_acl_handle_psacct(struct task_struct *task, const long code)
57322+{
57323+ return;
57324+}
57325+
57326+int
57327+gr_handle_ptrace(struct task_struct *task, const long request)
57328+{
57329+ return 0;
57330+}
57331+
57332+int
57333+gr_handle_proc_ptrace(struct task_struct *task)
57334+{
57335+ return 0;
57336+}
57337+
57338+void
57339+gr_learn_resource(const struct task_struct *task,
57340+ const int res, const unsigned long wanted, const int gt)
57341+{
57342+ return;
57343+}
57344+
57345+int
57346+gr_set_acls(const int type)
57347+{
57348+ return 0;
57349+}
57350+
57351+int
57352+gr_check_hidden_task(const struct task_struct *tsk)
57353+{
57354+ return 0;
57355+}
57356+
57357+int
57358+gr_check_protected_task(const struct task_struct *task)
57359+{
57360+ return 0;
57361+}
57362+
57363+int
57364+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57365+{
57366+ return 0;
57367+}
57368+
57369+void
57370+gr_copy_label(struct task_struct *tsk)
57371+{
57372+ return;
57373+}
57374+
57375+void
57376+gr_set_pax_flags(struct task_struct *task)
57377+{
57378+ return;
57379+}
57380+
57381+int
57382+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57383+ const int unsafe_share)
57384+{
57385+ return 0;
57386+}
57387+
57388+void
57389+gr_handle_delete(const ino_t ino, const dev_t dev)
57390+{
57391+ return;
57392+}
57393+
57394+void
57395+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57396+{
57397+ return;
57398+}
57399+
57400+void
57401+gr_handle_crash(struct task_struct *task, const int sig)
57402+{
57403+ return;
57404+}
57405+
57406+int
57407+gr_check_crash_exec(const struct file *filp)
57408+{
57409+ return 0;
57410+}
57411+
57412+int
57413+gr_check_crash_uid(const uid_t uid)
57414+{
57415+ return 0;
57416+}
57417+
57418+void
57419+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57420+ struct dentry *old_dentry,
57421+ struct dentry *new_dentry,
57422+ struct vfsmount *mnt, const __u8 replace)
57423+{
57424+ return;
57425+}
57426+
57427+int
57428+gr_search_socket(const int family, const int type, const int protocol)
57429+{
57430+ return 1;
57431+}
57432+
57433+int
57434+gr_search_connectbind(const int mode, const struct socket *sock,
57435+ const struct sockaddr_in *addr)
57436+{
57437+ return 0;
57438+}
57439+
57440+void
57441+gr_handle_alertkill(struct task_struct *task)
57442+{
57443+ return;
57444+}
57445+
57446+__u32
57447+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57448+{
57449+ return 1;
57450+}
57451+
57452+__u32
57453+gr_acl_handle_hidden_file(const struct dentry * dentry,
57454+ const struct vfsmount * mnt)
57455+{
57456+ return 1;
57457+}
57458+
57459+__u32
57460+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57461+ int acc_mode)
57462+{
57463+ return 1;
57464+}
57465+
57466+__u32
57467+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57468+{
57469+ return 1;
57470+}
57471+
57472+__u32
57473+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57474+{
57475+ return 1;
57476+}
57477+
57478+int
57479+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57480+ unsigned int *vm_flags)
57481+{
57482+ return 1;
57483+}
57484+
57485+__u32
57486+gr_acl_handle_truncate(const struct dentry * dentry,
57487+ const struct vfsmount * mnt)
57488+{
57489+ return 1;
57490+}
57491+
57492+__u32
57493+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
57494+{
57495+ return 1;
57496+}
57497+
57498+__u32
57499+gr_acl_handle_access(const struct dentry * dentry,
57500+ const struct vfsmount * mnt, const int fmode)
57501+{
57502+ return 1;
57503+}
57504+
57505+__u32
57506+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
57507+ umode_t *mode)
57508+{
57509+ return 1;
57510+}
57511+
57512+__u32
57513+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
57514+{
57515+ return 1;
57516+}
57517+
57518+__u32
57519+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
57520+{
57521+ return 1;
57522+}
57523+
57524+void
57525+grsecurity_init(void)
57526+{
57527+ return;
57528+}
57529+
57530+umode_t gr_acl_umask(void)
57531+{
57532+ return 0;
57533+}
57534+
57535+__u32
57536+gr_acl_handle_mknod(const struct dentry * new_dentry,
57537+ const struct dentry * parent_dentry,
57538+ const struct vfsmount * parent_mnt,
57539+ const int mode)
57540+{
57541+ return 1;
57542+}
57543+
57544+__u32
57545+gr_acl_handle_mkdir(const struct dentry * new_dentry,
57546+ const struct dentry * parent_dentry,
57547+ const struct vfsmount * parent_mnt)
57548+{
57549+ return 1;
57550+}
57551+
57552+__u32
57553+gr_acl_handle_symlink(const struct dentry * new_dentry,
57554+ const struct dentry * parent_dentry,
57555+ const struct vfsmount * parent_mnt, const char *from)
57556+{
57557+ return 1;
57558+}
57559+
57560+__u32
57561+gr_acl_handle_link(const struct dentry * new_dentry,
57562+ const struct dentry * parent_dentry,
57563+ const struct vfsmount * parent_mnt,
57564+ const struct dentry * old_dentry,
57565+ const struct vfsmount * old_mnt, const char *to)
57566+{
57567+ return 1;
57568+}
57569+
57570+int
57571+gr_acl_handle_rename(const struct dentry *new_dentry,
57572+ const struct dentry *parent_dentry,
57573+ const struct vfsmount *parent_mnt,
57574+ const struct dentry *old_dentry,
57575+ const struct inode *old_parent_inode,
57576+ const struct vfsmount *old_mnt, const char *newname)
57577+{
57578+ return 0;
57579+}
57580+
57581+int
57582+gr_acl_handle_filldir(const struct file *file, const char *name,
57583+ const int namelen, const ino_t ino)
57584+{
57585+ return 1;
57586+}
57587+
57588+int
57589+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57590+ const time_t shm_createtime, const uid_t cuid, const int shmid)
57591+{
57592+ return 1;
57593+}
57594+
57595+int
57596+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
57597+{
57598+ return 0;
57599+}
57600+
57601+int
57602+gr_search_accept(const struct socket *sock)
57603+{
57604+ return 0;
57605+}
57606+
57607+int
57608+gr_search_listen(const struct socket *sock)
57609+{
57610+ return 0;
57611+}
57612+
57613+int
57614+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
57615+{
57616+ return 0;
57617+}
57618+
57619+__u32
57620+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
57621+{
57622+ return 1;
57623+}
57624+
57625+__u32
57626+gr_acl_handle_creat(const struct dentry * dentry,
57627+ const struct dentry * p_dentry,
57628+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
57629+ const int imode)
57630+{
57631+ return 1;
57632+}
57633+
57634+void
57635+gr_acl_handle_exit(void)
57636+{
57637+ return;
57638+}
57639+
57640+int
57641+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57642+{
57643+ return 1;
57644+}
57645+
57646+void
57647+gr_set_role_label(const uid_t uid, const gid_t gid)
57648+{
57649+ return;
57650+}
57651+
57652+int
57653+gr_acl_handle_procpidmem(const struct task_struct *task)
57654+{
57655+ return 0;
57656+}
57657+
57658+int
57659+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
57660+{
57661+ return 0;
57662+}
57663+
57664+int
57665+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
57666+{
57667+ return 0;
57668+}
57669+
57670+void
57671+gr_set_kernel_label(struct task_struct *task)
57672+{
57673+ return;
57674+}
57675+
57676+int
57677+gr_check_user_change(int real, int effective, int fs)
57678+{
57679+ return 0;
57680+}
57681+
57682+int
57683+gr_check_group_change(int real, int effective, int fs)
57684+{
57685+ return 0;
57686+}
57687+
57688+int gr_acl_enable_at_secure(void)
57689+{
57690+ return 0;
57691+}
57692+
57693+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57694+{
57695+ return dentry->d_inode->i_sb->s_dev;
57696+}
57697+
57698+EXPORT_SYMBOL(gr_learn_resource);
57699+EXPORT_SYMBOL(gr_set_kernel_label);
57700+#ifdef CONFIG_SECURITY
57701+EXPORT_SYMBOL(gr_check_user_change);
57702+EXPORT_SYMBOL(gr_check_group_change);
57703+#endif
57704diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
57705new file mode 100644
57706index 0000000..abfa971
57707--- /dev/null
57708+++ b/grsecurity/grsec_exec.c
57709@@ -0,0 +1,174 @@
57710+#include <linux/kernel.h>
57711+#include <linux/sched.h>
57712+#include <linux/file.h>
57713+#include <linux/binfmts.h>
57714+#include <linux/fs.h>
57715+#include <linux/types.h>
57716+#include <linux/grdefs.h>
57717+#include <linux/grsecurity.h>
57718+#include <linux/grinternal.h>
57719+#include <linux/capability.h>
57720+#include <linux/module.h>
57721+
57722+#include <asm/uaccess.h>
57723+
57724+#ifdef CONFIG_GRKERNSEC_EXECLOG
57725+static char gr_exec_arg_buf[132];
57726+static DEFINE_MUTEX(gr_exec_arg_mutex);
57727+#endif
57728+
57729+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
57730+
57731+void
57732+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
57733+{
57734+#ifdef CONFIG_GRKERNSEC_EXECLOG
57735+ char *grarg = gr_exec_arg_buf;
57736+ unsigned int i, x, execlen = 0;
57737+ char c;
57738+
57739+ if (!((grsec_enable_execlog && grsec_enable_group &&
57740+ in_group_p(grsec_audit_gid))
57741+ || (grsec_enable_execlog && !grsec_enable_group)))
57742+ return;
57743+
57744+ mutex_lock(&gr_exec_arg_mutex);
57745+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
57746+
57747+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
57748+ const char __user *p;
57749+ unsigned int len;
57750+
57751+ p = get_user_arg_ptr(argv, i);
57752+ if (IS_ERR(p))
57753+ goto log;
57754+
57755+ len = strnlen_user(p, 128 - execlen);
57756+ if (len > 128 - execlen)
57757+ len = 128 - execlen;
57758+ else if (len > 0)
57759+ len--;
57760+ if (copy_from_user(grarg + execlen, p, len))
57761+ goto log;
57762+
57763+ /* rewrite unprintable characters */
57764+ for (x = 0; x < len; x++) {
57765+ c = *(grarg + execlen + x);
57766+ if (c < 32 || c > 126)
57767+ *(grarg + execlen + x) = ' ';
57768+ }
57769+
57770+ execlen += len;
57771+ *(grarg + execlen) = ' ';
57772+ *(grarg + execlen + 1) = '\0';
57773+ execlen++;
57774+ }
57775+
57776+ log:
57777+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
57778+ bprm->file->f_path.mnt, grarg);
57779+ mutex_unlock(&gr_exec_arg_mutex);
57780+#endif
57781+ return;
57782+}
57783+
57784+#ifdef CONFIG_GRKERNSEC
57785+extern int gr_acl_is_capable(const int cap);
57786+extern int gr_acl_is_capable_nolog(const int cap);
57787+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57788+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
57789+extern int gr_chroot_is_capable(const int cap);
57790+extern int gr_chroot_is_capable_nolog(const int cap);
57791+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57792+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
57793+#endif
57794+
57795+const char *captab_log[] = {
57796+ "CAP_CHOWN",
57797+ "CAP_DAC_OVERRIDE",
57798+ "CAP_DAC_READ_SEARCH",
57799+ "CAP_FOWNER",
57800+ "CAP_FSETID",
57801+ "CAP_KILL",
57802+ "CAP_SETGID",
57803+ "CAP_SETUID",
57804+ "CAP_SETPCAP",
57805+ "CAP_LINUX_IMMUTABLE",
57806+ "CAP_NET_BIND_SERVICE",
57807+ "CAP_NET_BROADCAST",
57808+ "CAP_NET_ADMIN",
57809+ "CAP_NET_RAW",
57810+ "CAP_IPC_LOCK",
57811+ "CAP_IPC_OWNER",
57812+ "CAP_SYS_MODULE",
57813+ "CAP_SYS_RAWIO",
57814+ "CAP_SYS_CHROOT",
57815+ "CAP_SYS_PTRACE",
57816+ "CAP_SYS_PACCT",
57817+ "CAP_SYS_ADMIN",
57818+ "CAP_SYS_BOOT",
57819+ "CAP_SYS_NICE",
57820+ "CAP_SYS_RESOURCE",
57821+ "CAP_SYS_TIME",
57822+ "CAP_SYS_TTY_CONFIG",
57823+ "CAP_MKNOD",
57824+ "CAP_LEASE",
57825+ "CAP_AUDIT_WRITE",
57826+ "CAP_AUDIT_CONTROL",
57827+ "CAP_SETFCAP",
57828+ "CAP_MAC_OVERRIDE",
57829+ "CAP_MAC_ADMIN",
57830+ "CAP_SYSLOG",
57831+ "CAP_WAKE_ALARM"
57832+};
57833+
57834+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
57835+
57836+int gr_is_capable(const int cap)
57837+{
57838+#ifdef CONFIG_GRKERNSEC
57839+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
57840+ return 1;
57841+ return 0;
57842+#else
57843+ return 1;
57844+#endif
57845+}
57846+
57847+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57848+{
57849+#ifdef CONFIG_GRKERNSEC
57850+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
57851+ return 1;
57852+ return 0;
57853+#else
57854+ return 1;
57855+#endif
57856+}
57857+
57858+int gr_is_capable_nolog(const int cap)
57859+{
57860+#ifdef CONFIG_GRKERNSEC
57861+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
57862+ return 1;
57863+ return 0;
57864+#else
57865+ return 1;
57866+#endif
57867+}
57868+
57869+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
57870+{
57871+#ifdef CONFIG_GRKERNSEC
57872+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
57873+ return 1;
57874+ return 0;
57875+#else
57876+ return 1;
57877+#endif
57878+}
57879+
57880+EXPORT_SYMBOL(gr_is_capable);
57881+EXPORT_SYMBOL(gr_is_capable_nolog);
57882+EXPORT_SYMBOL(gr_task_is_capable);
57883+EXPORT_SYMBOL(gr_task_is_capable_nolog);
57884diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
57885new file mode 100644
57886index 0000000..d3ee748
57887--- /dev/null
57888+++ b/grsecurity/grsec_fifo.c
57889@@ -0,0 +1,24 @@
57890+#include <linux/kernel.h>
57891+#include <linux/sched.h>
57892+#include <linux/fs.h>
57893+#include <linux/file.h>
57894+#include <linux/grinternal.h>
57895+
57896+int
57897+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
57898+ const struct dentry *dir, const int flag, const int acc_mode)
57899+{
57900+#ifdef CONFIG_GRKERNSEC_FIFO
57901+ const struct cred *cred = current_cred();
57902+
57903+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
57904+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
57905+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
57906+ (cred->fsuid != dentry->d_inode->i_uid)) {
57907+ if (!inode_permission(dentry->d_inode, acc_mode))
57908+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
57909+ return -EACCES;
57910+ }
57911+#endif
57912+ return 0;
57913+}
57914diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
57915new file mode 100644
57916index 0000000..8ca18bf
57917--- /dev/null
57918+++ b/grsecurity/grsec_fork.c
57919@@ -0,0 +1,23 @@
57920+#include <linux/kernel.h>
57921+#include <linux/sched.h>
57922+#include <linux/grsecurity.h>
57923+#include <linux/grinternal.h>
57924+#include <linux/errno.h>
57925+
57926+void
57927+gr_log_forkfail(const int retval)
57928+{
57929+#ifdef CONFIG_GRKERNSEC_FORKFAIL
57930+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
57931+ switch (retval) {
57932+ case -EAGAIN:
57933+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
57934+ break;
57935+ case -ENOMEM:
57936+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
57937+ break;
57938+ }
57939+ }
57940+#endif
57941+ return;
57942+}
57943diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
57944new file mode 100644
57945index 0000000..05a6015
57946--- /dev/null
57947+++ b/grsecurity/grsec_init.c
57948@@ -0,0 +1,283 @@
57949+#include <linux/kernel.h>
57950+#include <linux/sched.h>
57951+#include <linux/mm.h>
57952+#include <linux/gracl.h>
57953+#include <linux/slab.h>
57954+#include <linux/vmalloc.h>
57955+#include <linux/percpu.h>
57956+#include <linux/module.h>
57957+
57958+int grsec_enable_ptrace_readexec;
57959+int grsec_enable_setxid;
57960+int grsec_enable_symlinkown;
57961+int grsec_symlinkown_gid;
57962+int grsec_enable_brute;
57963+int grsec_enable_link;
57964+int grsec_enable_dmesg;
57965+int grsec_enable_harden_ptrace;
57966+int grsec_enable_fifo;
57967+int grsec_enable_execlog;
57968+int grsec_enable_signal;
57969+int grsec_enable_forkfail;
57970+int grsec_enable_audit_ptrace;
57971+int grsec_enable_time;
57972+int grsec_enable_audit_textrel;
57973+int grsec_enable_group;
57974+int grsec_audit_gid;
57975+int grsec_enable_chdir;
57976+int grsec_enable_mount;
57977+int grsec_enable_rofs;
57978+int grsec_enable_chroot_findtask;
57979+int grsec_enable_chroot_mount;
57980+int grsec_enable_chroot_shmat;
57981+int grsec_enable_chroot_fchdir;
57982+int grsec_enable_chroot_double;
57983+int grsec_enable_chroot_pivot;
57984+int grsec_enable_chroot_chdir;
57985+int grsec_enable_chroot_chmod;
57986+int grsec_enable_chroot_mknod;
57987+int grsec_enable_chroot_nice;
57988+int grsec_enable_chroot_execlog;
57989+int grsec_enable_chroot_caps;
57990+int grsec_enable_chroot_sysctl;
57991+int grsec_enable_chroot_unix;
57992+int grsec_enable_tpe;
57993+int grsec_tpe_gid;
57994+int grsec_enable_blackhole;
57995+#ifdef CONFIG_IPV6_MODULE
57996+EXPORT_SYMBOL(grsec_enable_blackhole);
57997+#endif
57998+int grsec_lastack_retries;
57999+int grsec_enable_tpe_all;
58000+int grsec_enable_tpe_invert;
58001+int grsec_enable_socket_all;
58002+int grsec_socket_all_gid;
58003+int grsec_enable_socket_client;
58004+int grsec_socket_client_gid;
58005+int grsec_enable_socket_server;
58006+int grsec_socket_server_gid;
58007+int grsec_resource_logging;
58008+int grsec_disable_privio;
58009+int grsec_enable_log_rwxmaps;
58010+int grsec_lock;
58011+
58012+DEFINE_SPINLOCK(grsec_alert_lock);
58013+unsigned long grsec_alert_wtime = 0;
58014+unsigned long grsec_alert_fyet = 0;
58015+
58016+DEFINE_SPINLOCK(grsec_audit_lock);
58017+
58018+DEFINE_RWLOCK(grsec_exec_file_lock);
58019+
58020+char *gr_shared_page[4];
58021+
58022+char *gr_alert_log_fmt;
58023+char *gr_audit_log_fmt;
58024+char *gr_alert_log_buf;
58025+char *gr_audit_log_buf;
58026+
58027+extern struct gr_arg *gr_usermode;
58028+extern unsigned char *gr_system_salt;
58029+extern unsigned char *gr_system_sum;
58030+
58031+void __init
58032+grsecurity_init(void)
58033+{
58034+ int j;
58035+ /* create the per-cpu shared pages */
58036+
58037+#ifdef CONFIG_X86
58038+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
58039+#endif
58040+
58041+ for (j = 0; j < 4; j++) {
58042+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
58043+ if (gr_shared_page[j] == NULL) {
58044+ panic("Unable to allocate grsecurity shared page");
58045+ return;
58046+ }
58047+ }
58048+
58049+ /* allocate log buffers */
58050+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
58051+ if (!gr_alert_log_fmt) {
58052+ panic("Unable to allocate grsecurity alert log format buffer");
58053+ return;
58054+ }
58055+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
58056+ if (!gr_audit_log_fmt) {
58057+ panic("Unable to allocate grsecurity audit log format buffer");
58058+ return;
58059+ }
58060+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58061+ if (!gr_alert_log_buf) {
58062+ panic("Unable to allocate grsecurity alert log buffer");
58063+ return;
58064+ }
58065+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58066+ if (!gr_audit_log_buf) {
58067+ panic("Unable to allocate grsecurity audit log buffer");
58068+ return;
58069+ }
58070+
58071+ /* allocate memory for authentication structure */
58072+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
58073+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
58074+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
58075+
58076+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
58077+ panic("Unable to allocate grsecurity authentication structure");
58078+ return;
58079+ }
58080+
58081+
58082+#ifdef CONFIG_GRKERNSEC_IO
58083+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
58084+ grsec_disable_privio = 1;
58085+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58086+ grsec_disable_privio = 1;
58087+#else
58088+ grsec_disable_privio = 0;
58089+#endif
58090+#endif
58091+
58092+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58093+ /* for backward compatibility, tpe_invert always defaults to on if
58094+ enabled in the kernel
58095+ */
58096+ grsec_enable_tpe_invert = 1;
58097+#endif
58098+
58099+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58100+#ifndef CONFIG_GRKERNSEC_SYSCTL
58101+ grsec_lock = 1;
58102+#endif
58103+
58104+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58105+ grsec_enable_audit_textrel = 1;
58106+#endif
58107+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58108+ grsec_enable_log_rwxmaps = 1;
58109+#endif
58110+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58111+ grsec_enable_group = 1;
58112+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
58113+#endif
58114+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58115+ grsec_enable_ptrace_readexec = 1;
58116+#endif
58117+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58118+ grsec_enable_chdir = 1;
58119+#endif
58120+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58121+ grsec_enable_harden_ptrace = 1;
58122+#endif
58123+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58124+ grsec_enable_mount = 1;
58125+#endif
58126+#ifdef CONFIG_GRKERNSEC_LINK
58127+ grsec_enable_link = 1;
58128+#endif
58129+#ifdef CONFIG_GRKERNSEC_BRUTE
58130+ grsec_enable_brute = 1;
58131+#endif
58132+#ifdef CONFIG_GRKERNSEC_DMESG
58133+ grsec_enable_dmesg = 1;
58134+#endif
58135+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58136+ grsec_enable_blackhole = 1;
58137+ grsec_lastack_retries = 4;
58138+#endif
58139+#ifdef CONFIG_GRKERNSEC_FIFO
58140+ grsec_enable_fifo = 1;
58141+#endif
58142+#ifdef CONFIG_GRKERNSEC_EXECLOG
58143+ grsec_enable_execlog = 1;
58144+#endif
58145+#ifdef CONFIG_GRKERNSEC_SETXID
58146+ grsec_enable_setxid = 1;
58147+#endif
58148+#ifdef CONFIG_GRKERNSEC_SIGNAL
58149+ grsec_enable_signal = 1;
58150+#endif
58151+#ifdef CONFIG_GRKERNSEC_FORKFAIL
58152+ grsec_enable_forkfail = 1;
58153+#endif
58154+#ifdef CONFIG_GRKERNSEC_TIME
58155+ grsec_enable_time = 1;
58156+#endif
58157+#ifdef CONFIG_GRKERNSEC_RESLOG
58158+ grsec_resource_logging = 1;
58159+#endif
58160+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58161+ grsec_enable_chroot_findtask = 1;
58162+#endif
58163+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58164+ grsec_enable_chroot_unix = 1;
58165+#endif
58166+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58167+ grsec_enable_chroot_mount = 1;
58168+#endif
58169+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58170+ grsec_enable_chroot_fchdir = 1;
58171+#endif
58172+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58173+ grsec_enable_chroot_shmat = 1;
58174+#endif
58175+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58176+ grsec_enable_audit_ptrace = 1;
58177+#endif
58178+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58179+ grsec_enable_chroot_double = 1;
58180+#endif
58181+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58182+ grsec_enable_chroot_pivot = 1;
58183+#endif
58184+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58185+ grsec_enable_chroot_chdir = 1;
58186+#endif
58187+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58188+ grsec_enable_chroot_chmod = 1;
58189+#endif
58190+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58191+ grsec_enable_chroot_mknod = 1;
58192+#endif
58193+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58194+ grsec_enable_chroot_nice = 1;
58195+#endif
58196+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58197+ grsec_enable_chroot_execlog = 1;
58198+#endif
58199+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58200+ grsec_enable_chroot_caps = 1;
58201+#endif
58202+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58203+ grsec_enable_chroot_sysctl = 1;
58204+#endif
58205+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58206+ grsec_enable_symlinkown = 1;
58207+ grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
58208+#endif
58209+#ifdef CONFIG_GRKERNSEC_TPE
58210+ grsec_enable_tpe = 1;
58211+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58212+#ifdef CONFIG_GRKERNSEC_TPE_ALL
58213+ grsec_enable_tpe_all = 1;
58214+#endif
58215+#endif
58216+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58217+ grsec_enable_socket_all = 1;
58218+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58219+#endif
58220+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58221+ grsec_enable_socket_client = 1;
58222+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58223+#endif
58224+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58225+ grsec_enable_socket_server = 1;
58226+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58227+#endif
58228+#endif
58229+
58230+ return;
58231+}
58232diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
58233new file mode 100644
58234index 0000000..589481f
58235--- /dev/null
58236+++ b/grsecurity/grsec_link.c
58237@@ -0,0 +1,58 @@
58238+#include <linux/kernel.h>
58239+#include <linux/sched.h>
58240+#include <linux/fs.h>
58241+#include <linux/file.h>
58242+#include <linux/grinternal.h>
58243+
58244+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
58245+{
58246+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58247+ const struct inode *link_inode = link->dentry->d_inode;
58248+
58249+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
58250+ /* ignore root-owned links, e.g. /proc/self */
58251+ !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
58252+ !uid_eq(link_inode->i_uid, target->i_uid)) {
58253+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
58254+ return 1;
58255+ }
58256+#endif
58257+ return 0;
58258+}
58259+
58260+int
58261+gr_handle_follow_link(const struct inode *parent,
58262+ const struct inode *inode,
58263+ const struct dentry *dentry, const struct vfsmount *mnt)
58264+{
58265+#ifdef CONFIG_GRKERNSEC_LINK
58266+ const struct cred *cred = current_cred();
58267+
58268+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58269+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
58270+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
58271+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58272+ return -EACCES;
58273+ }
58274+#endif
58275+ return 0;
58276+}
58277+
58278+int
58279+gr_handle_hardlink(const struct dentry *dentry,
58280+ const struct vfsmount *mnt,
58281+ struct inode *inode, const int mode, const char *to)
58282+{
58283+#ifdef CONFIG_GRKERNSEC_LINK
58284+ const struct cred *cred = current_cred();
58285+
58286+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
58287+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
58288+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58289+ !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
58290+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
58291+ return -EPERM;
58292+ }
58293+#endif
58294+ return 0;
58295+}
58296diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
58297new file mode 100644
58298index 0000000..a45d2e9
58299--- /dev/null
58300+++ b/grsecurity/grsec_log.c
58301@@ -0,0 +1,322 @@
58302+#include <linux/kernel.h>
58303+#include <linux/sched.h>
58304+#include <linux/file.h>
58305+#include <linux/tty.h>
58306+#include <linux/fs.h>
58307+#include <linux/grinternal.h>
58308+
58309+#ifdef CONFIG_TREE_PREEMPT_RCU
58310+#define DISABLE_PREEMPT() preempt_disable()
58311+#define ENABLE_PREEMPT() preempt_enable()
58312+#else
58313+#define DISABLE_PREEMPT()
58314+#define ENABLE_PREEMPT()
58315+#endif
58316+
58317+#define BEGIN_LOCKS(x) \
58318+ DISABLE_PREEMPT(); \
58319+ rcu_read_lock(); \
58320+ read_lock(&tasklist_lock); \
58321+ read_lock(&grsec_exec_file_lock); \
58322+ if (x != GR_DO_AUDIT) \
58323+ spin_lock(&grsec_alert_lock); \
58324+ else \
58325+ spin_lock(&grsec_audit_lock)
58326+
58327+#define END_LOCKS(x) \
58328+ if (x != GR_DO_AUDIT) \
58329+ spin_unlock(&grsec_alert_lock); \
58330+ else \
58331+ spin_unlock(&grsec_audit_lock); \
58332+ read_unlock(&grsec_exec_file_lock); \
58333+ read_unlock(&tasklist_lock); \
58334+ rcu_read_unlock(); \
58335+ ENABLE_PREEMPT(); \
58336+ if (x == GR_DONT_AUDIT) \
58337+ gr_handle_alertkill(current)
58338+
58339+enum {
58340+ FLOODING,
58341+ NO_FLOODING
58342+};
58343+
58344+extern char *gr_alert_log_fmt;
58345+extern char *gr_audit_log_fmt;
58346+extern char *gr_alert_log_buf;
58347+extern char *gr_audit_log_buf;
58348+
58349+static int gr_log_start(int audit)
58350+{
58351+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58352+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58353+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58354+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
58355+ unsigned long curr_secs = get_seconds();
58356+
58357+ if (audit == GR_DO_AUDIT)
58358+ goto set_fmt;
58359+
58360+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
58361+ grsec_alert_wtime = curr_secs;
58362+ grsec_alert_fyet = 0;
58363+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
58364+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58365+ grsec_alert_fyet++;
58366+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58367+ grsec_alert_wtime = curr_secs;
58368+ grsec_alert_fyet++;
58369+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58370+ return FLOODING;
58371+ }
58372+ else return FLOODING;
58373+
58374+set_fmt:
58375+#endif
58376+ memset(buf, 0, PAGE_SIZE);
58377+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
58378+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58379+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58380+ } else if (current->signal->curr_ip) {
58381+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58382+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58383+ } else if (gr_acl_is_enabled()) {
58384+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58385+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58386+ } else {
58387+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
58388+ strcpy(buf, fmt);
58389+ }
58390+
58391+ return NO_FLOODING;
58392+}
58393+
58394+static void gr_log_middle(int audit, const char *msg, va_list ap)
58395+ __attribute__ ((format (printf, 2, 0)));
58396+
58397+static void gr_log_middle(int audit, const char *msg, va_list ap)
58398+{
58399+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58400+ unsigned int len = strlen(buf);
58401+
58402+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58403+
58404+ return;
58405+}
58406+
58407+static void gr_log_middle_varargs(int audit, const char *msg, ...)
58408+ __attribute__ ((format (printf, 2, 3)));
58409+
58410+static void gr_log_middle_varargs(int audit, const char *msg, ...)
58411+{
58412+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58413+ unsigned int len = strlen(buf);
58414+ va_list ap;
58415+
58416+ va_start(ap, msg);
58417+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58418+ va_end(ap);
58419+
58420+ return;
58421+}
58422+
58423+static void gr_log_end(int audit, int append_default)
58424+{
58425+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58426+
58427+ if (append_default) {
58428+ unsigned int len = strlen(buf);
58429+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58430+ }
58431+
58432+ printk("%s\n", buf);
58433+
58434+ return;
58435+}
58436+
58437+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58438+{
58439+ int logtype;
58440+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58441+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58442+ void *voidptr = NULL;
58443+ int num1 = 0, num2 = 0;
58444+ unsigned long ulong1 = 0, ulong2 = 0;
58445+ struct dentry *dentry = NULL;
58446+ struct vfsmount *mnt = NULL;
58447+ struct file *file = NULL;
58448+ struct task_struct *task = NULL;
58449+ const struct cred *cred, *pcred;
58450+ va_list ap;
58451+
58452+ BEGIN_LOCKS(audit);
58453+ logtype = gr_log_start(audit);
58454+ if (logtype == FLOODING) {
58455+ END_LOCKS(audit);
58456+ return;
58457+ }
58458+ va_start(ap, argtypes);
58459+ switch (argtypes) {
58460+ case GR_TTYSNIFF:
58461+ task = va_arg(ap, struct task_struct *);
58462+ 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);
58463+ break;
58464+ case GR_SYSCTL_HIDDEN:
58465+ str1 = va_arg(ap, char *);
58466+ gr_log_middle_varargs(audit, msg, result, str1);
58467+ break;
58468+ case GR_RBAC:
58469+ dentry = va_arg(ap, struct dentry *);
58470+ mnt = va_arg(ap, struct vfsmount *);
58471+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58472+ break;
58473+ case GR_RBAC_STR:
58474+ dentry = va_arg(ap, struct dentry *);
58475+ mnt = va_arg(ap, struct vfsmount *);
58476+ str1 = va_arg(ap, char *);
58477+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58478+ break;
58479+ case GR_STR_RBAC:
58480+ str1 = va_arg(ap, char *);
58481+ dentry = va_arg(ap, struct dentry *);
58482+ mnt = va_arg(ap, struct vfsmount *);
58483+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
58484+ break;
58485+ case GR_RBAC_MODE2:
58486+ dentry = va_arg(ap, struct dentry *);
58487+ mnt = va_arg(ap, struct vfsmount *);
58488+ str1 = va_arg(ap, char *);
58489+ str2 = va_arg(ap, char *);
58490+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
58491+ break;
58492+ case GR_RBAC_MODE3:
58493+ dentry = va_arg(ap, struct dentry *);
58494+ mnt = va_arg(ap, struct vfsmount *);
58495+ str1 = va_arg(ap, char *);
58496+ str2 = va_arg(ap, char *);
58497+ str3 = va_arg(ap, char *);
58498+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
58499+ break;
58500+ case GR_FILENAME:
58501+ dentry = va_arg(ap, struct dentry *);
58502+ mnt = va_arg(ap, struct vfsmount *);
58503+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
58504+ break;
58505+ case GR_STR_FILENAME:
58506+ str1 = va_arg(ap, char *);
58507+ dentry = va_arg(ap, struct dentry *);
58508+ mnt = va_arg(ap, struct vfsmount *);
58509+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
58510+ break;
58511+ case GR_FILENAME_STR:
58512+ dentry = va_arg(ap, struct dentry *);
58513+ mnt = va_arg(ap, struct vfsmount *);
58514+ str1 = va_arg(ap, char *);
58515+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
58516+ break;
58517+ case GR_FILENAME_TWO_INT:
58518+ dentry = va_arg(ap, struct dentry *);
58519+ mnt = va_arg(ap, struct vfsmount *);
58520+ num1 = va_arg(ap, int);
58521+ num2 = va_arg(ap, int);
58522+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
58523+ break;
58524+ case GR_FILENAME_TWO_INT_STR:
58525+ dentry = va_arg(ap, struct dentry *);
58526+ mnt = va_arg(ap, struct vfsmount *);
58527+ num1 = va_arg(ap, int);
58528+ num2 = va_arg(ap, int);
58529+ str1 = va_arg(ap, char *);
58530+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
58531+ break;
58532+ case GR_TEXTREL:
58533+ file = va_arg(ap, struct file *);
58534+ ulong1 = va_arg(ap, unsigned long);
58535+ ulong2 = va_arg(ap, unsigned long);
58536+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
58537+ break;
58538+ case GR_PTRACE:
58539+ task = va_arg(ap, struct task_struct *);
58540+ 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);
58541+ break;
58542+ case GR_RESOURCE:
58543+ task = va_arg(ap, struct task_struct *);
58544+ cred = __task_cred(task);
58545+ pcred = __task_cred(task->real_parent);
58546+ ulong1 = va_arg(ap, unsigned long);
58547+ str1 = va_arg(ap, char *);
58548+ ulong2 = va_arg(ap, unsigned long);
58549+ 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);
58550+ break;
58551+ case GR_CAP:
58552+ task = va_arg(ap, struct task_struct *);
58553+ cred = __task_cred(task);
58554+ pcred = __task_cred(task->real_parent);
58555+ str1 = va_arg(ap, char *);
58556+ 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);
58557+ break;
58558+ case GR_SIG:
58559+ str1 = va_arg(ap, char *);
58560+ voidptr = va_arg(ap, void *);
58561+ gr_log_middle_varargs(audit, msg, str1, voidptr);
58562+ break;
58563+ case GR_SIG2:
58564+ task = va_arg(ap, struct task_struct *);
58565+ cred = __task_cred(task);
58566+ pcred = __task_cred(task->real_parent);
58567+ num1 = va_arg(ap, int);
58568+ 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);
58569+ break;
58570+ case GR_CRASH1:
58571+ task = va_arg(ap, struct task_struct *);
58572+ cred = __task_cred(task);
58573+ pcred = __task_cred(task->real_parent);
58574+ ulong1 = va_arg(ap, unsigned long);
58575+ 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);
58576+ break;
58577+ case GR_CRASH2:
58578+ task = va_arg(ap, struct task_struct *);
58579+ cred = __task_cred(task);
58580+ pcred = __task_cred(task->real_parent);
58581+ ulong1 = va_arg(ap, unsigned long);
58582+ 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);
58583+ break;
58584+ case GR_RWXMAP:
58585+ file = va_arg(ap, struct file *);
58586+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
58587+ break;
58588+ case GR_PSACCT:
58589+ {
58590+ unsigned int wday, cday;
58591+ __u8 whr, chr;
58592+ __u8 wmin, cmin;
58593+ __u8 wsec, csec;
58594+ char cur_tty[64] = { 0 };
58595+ char parent_tty[64] = { 0 };
58596+
58597+ task = va_arg(ap, struct task_struct *);
58598+ wday = va_arg(ap, unsigned int);
58599+ cday = va_arg(ap, unsigned int);
58600+ whr = va_arg(ap, int);
58601+ chr = va_arg(ap, int);
58602+ wmin = va_arg(ap, int);
58603+ cmin = va_arg(ap, int);
58604+ wsec = va_arg(ap, int);
58605+ csec = va_arg(ap, int);
58606+ ulong1 = va_arg(ap, unsigned long);
58607+ cred = __task_cred(task);
58608+ pcred = __task_cred(task->real_parent);
58609+
58610+ 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);
58611+ }
58612+ break;
58613+ default:
58614+ gr_log_middle(audit, msg, ap);
58615+ }
58616+ va_end(ap);
58617+ // these don't need DEFAULTSECARGS printed on the end
58618+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
58619+ gr_log_end(audit, 0);
58620+ else
58621+ gr_log_end(audit, 1);
58622+ END_LOCKS(audit);
58623+}
58624diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
58625new file mode 100644
58626index 0000000..f536303
58627--- /dev/null
58628+++ b/grsecurity/grsec_mem.c
58629@@ -0,0 +1,40 @@
58630+#include <linux/kernel.h>
58631+#include <linux/sched.h>
58632+#include <linux/mm.h>
58633+#include <linux/mman.h>
58634+#include <linux/grinternal.h>
58635+
58636+void
58637+gr_handle_ioperm(void)
58638+{
58639+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
58640+ return;
58641+}
58642+
58643+void
58644+gr_handle_iopl(void)
58645+{
58646+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
58647+ return;
58648+}
58649+
58650+void
58651+gr_handle_mem_readwrite(u64 from, u64 to)
58652+{
58653+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
58654+ return;
58655+}
58656+
58657+void
58658+gr_handle_vm86(void)
58659+{
58660+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
58661+ return;
58662+}
58663+
58664+void
58665+gr_log_badprocpid(const char *entry)
58666+{
58667+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
58668+ return;
58669+}
58670diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
58671new file mode 100644
58672index 0000000..2131422
58673--- /dev/null
58674+++ b/grsecurity/grsec_mount.c
58675@@ -0,0 +1,62 @@
58676+#include <linux/kernel.h>
58677+#include <linux/sched.h>
58678+#include <linux/mount.h>
58679+#include <linux/grsecurity.h>
58680+#include <linux/grinternal.h>
58681+
58682+void
58683+gr_log_remount(const char *devname, const int retval)
58684+{
58685+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58686+ if (grsec_enable_mount && (retval >= 0))
58687+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
58688+#endif
58689+ return;
58690+}
58691+
58692+void
58693+gr_log_unmount(const char *devname, const int retval)
58694+{
58695+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58696+ if (grsec_enable_mount && (retval >= 0))
58697+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
58698+#endif
58699+ return;
58700+}
58701+
58702+void
58703+gr_log_mount(const char *from, const char *to, const int retval)
58704+{
58705+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58706+ if (grsec_enable_mount && (retval >= 0))
58707+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
58708+#endif
58709+ return;
58710+}
58711+
58712+int
58713+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
58714+{
58715+#ifdef CONFIG_GRKERNSEC_ROFS
58716+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
58717+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
58718+ return -EPERM;
58719+ } else
58720+ return 0;
58721+#endif
58722+ return 0;
58723+}
58724+
58725+int
58726+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
58727+{
58728+#ifdef CONFIG_GRKERNSEC_ROFS
58729+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
58730+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
58731+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
58732+ return -EPERM;
58733+ } else
58734+ return 0;
58735+#endif
58736+ return 0;
58737+}
58738diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
58739new file mode 100644
58740index 0000000..a3b12a0
58741--- /dev/null
58742+++ b/grsecurity/grsec_pax.c
58743@@ -0,0 +1,36 @@
58744+#include <linux/kernel.h>
58745+#include <linux/sched.h>
58746+#include <linux/mm.h>
58747+#include <linux/file.h>
58748+#include <linux/grinternal.h>
58749+#include <linux/grsecurity.h>
58750+
58751+void
58752+gr_log_textrel(struct vm_area_struct * vma)
58753+{
58754+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58755+ if (grsec_enable_audit_textrel)
58756+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
58757+#endif
58758+ return;
58759+}
58760+
58761+void
58762+gr_log_rwxmmap(struct file *file)
58763+{
58764+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58765+ if (grsec_enable_log_rwxmaps)
58766+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
58767+#endif
58768+ return;
58769+}
58770+
58771+void
58772+gr_log_rwxmprotect(struct file *file)
58773+{
58774+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58775+ if (grsec_enable_log_rwxmaps)
58776+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
58777+#endif
58778+ return;
58779+}
58780diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
58781new file mode 100644
58782index 0000000..f7f29aa
58783--- /dev/null
58784+++ b/grsecurity/grsec_ptrace.c
58785@@ -0,0 +1,30 @@
58786+#include <linux/kernel.h>
58787+#include <linux/sched.h>
58788+#include <linux/grinternal.h>
58789+#include <linux/security.h>
58790+
58791+void
58792+gr_audit_ptrace(struct task_struct *task)
58793+{
58794+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58795+ if (grsec_enable_audit_ptrace)
58796+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
58797+#endif
58798+ return;
58799+}
58800+
58801+int
58802+gr_ptrace_readexec(struct file *file, int unsafe_flags)
58803+{
58804+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58805+ const struct dentry *dentry = file->f_path.dentry;
58806+ const struct vfsmount *mnt = file->f_path.mnt;
58807+
58808+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
58809+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
58810+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
58811+ return -EACCES;
58812+ }
58813+#endif
58814+ return 0;
58815+}
58816diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
58817new file mode 100644
58818index 0000000..b4ac94c
58819--- /dev/null
58820+++ b/grsecurity/grsec_sig.c
58821@@ -0,0 +1,209 @@
58822+#include <linux/kernel.h>
58823+#include <linux/sched.h>
58824+#include <linux/delay.h>
58825+#include <linux/grsecurity.h>
58826+#include <linux/grinternal.h>
58827+#include <linux/hardirq.h>
58828+
58829+char *signames[] = {
58830+ [SIGSEGV] = "Segmentation fault",
58831+ [SIGILL] = "Illegal instruction",
58832+ [SIGABRT] = "Abort",
58833+ [SIGBUS] = "Invalid alignment/Bus error"
58834+};
58835+
58836+void
58837+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
58838+{
58839+#ifdef CONFIG_GRKERNSEC_SIGNAL
58840+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
58841+ (sig == SIGABRT) || (sig == SIGBUS))) {
58842+ if (t->pid == current->pid) {
58843+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
58844+ } else {
58845+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
58846+ }
58847+ }
58848+#endif
58849+ return;
58850+}
58851+
58852+int
58853+gr_handle_signal(const struct task_struct *p, const int sig)
58854+{
58855+#ifdef CONFIG_GRKERNSEC
58856+ /* ignore the 0 signal for protected task checks */
58857+ if (current->pid > 1 && sig && gr_check_protected_task(p)) {
58858+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
58859+ return -EPERM;
58860+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
58861+ return -EPERM;
58862+ }
58863+#endif
58864+ return 0;
58865+}
58866+
58867+#ifdef CONFIG_GRKERNSEC
58868+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
58869+
58870+int gr_fake_force_sig(int sig, struct task_struct *t)
58871+{
58872+ unsigned long int flags;
58873+ int ret, blocked, ignored;
58874+ struct k_sigaction *action;
58875+
58876+ spin_lock_irqsave(&t->sighand->siglock, flags);
58877+ action = &t->sighand->action[sig-1];
58878+ ignored = action->sa.sa_handler == SIG_IGN;
58879+ blocked = sigismember(&t->blocked, sig);
58880+ if (blocked || ignored) {
58881+ action->sa.sa_handler = SIG_DFL;
58882+ if (blocked) {
58883+ sigdelset(&t->blocked, sig);
58884+ recalc_sigpending_and_wake(t);
58885+ }
58886+ }
58887+ if (action->sa.sa_handler == SIG_DFL)
58888+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
58889+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
58890+
58891+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
58892+
58893+ return ret;
58894+}
58895+#endif
58896+
58897+#ifdef CONFIG_GRKERNSEC_BRUTE
58898+#define GR_USER_BAN_TIME (15 * 60)
58899+
58900+static int __get_dumpable(unsigned long mm_flags)
58901+{
58902+ int ret;
58903+
58904+ ret = mm_flags & MMF_DUMPABLE_MASK;
58905+ return (ret >= 2) ? 2 : ret;
58906+}
58907+#endif
58908+
58909+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
58910+{
58911+#ifdef CONFIG_GRKERNSEC_BRUTE
58912+ kuid_t uid = GLOBAL_ROOT_UID;
58913+
58914+ if (!grsec_enable_brute)
58915+ return;
58916+
58917+ rcu_read_lock();
58918+ read_lock(&tasklist_lock);
58919+ read_lock(&grsec_exec_file_lock);
58920+ if (p->real_parent && p->real_parent->exec_file == p->exec_file)
58921+ p->real_parent->brute = 1;
58922+ else {
58923+ const struct cred *cred = __task_cred(p), *cred2;
58924+ struct task_struct *tsk, *tsk2;
58925+
58926+ if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
58927+ struct user_struct *user;
58928+
58929+ uid = cred->uid;
58930+
58931+ /* this is put upon execution past expiration */
58932+ user = find_user(uid);
58933+ if (user == NULL)
58934+ goto unlock;
58935+ user->banned = 1;
58936+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
58937+ if (user->ban_expires == ~0UL)
58938+ user->ban_expires--;
58939+
58940+ do_each_thread(tsk2, tsk) {
58941+ cred2 = __task_cred(tsk);
58942+ if (tsk != p && uid_eq(cred2->uid, uid))
58943+ gr_fake_force_sig(SIGKILL, tsk);
58944+ } while_each_thread(tsk2, tsk);
58945+ }
58946+ }
58947+unlock:
58948+ read_unlock(&grsec_exec_file_lock);
58949+ read_unlock(&tasklist_lock);
58950+ rcu_read_unlock();
58951+
58952+ if (!uid_eq(uid, GLOBAL_ROOT_UID))
58953+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
58954+ from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
58955+
58956+#endif
58957+ return;
58958+}
58959+
58960+void gr_handle_brute_check(void)
58961+{
58962+#ifdef CONFIG_GRKERNSEC_BRUTE
58963+ if (current->brute)
58964+ msleep(30 * 1000);
58965+#endif
58966+ return;
58967+}
58968+
58969+void gr_handle_kernel_exploit(void)
58970+{
58971+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
58972+ const struct cred *cred;
58973+ struct task_struct *tsk, *tsk2;
58974+ struct user_struct *user;
58975+ kuid_t uid;
58976+
58977+ if (in_irq() || in_serving_softirq() || in_nmi())
58978+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
58979+
58980+ uid = current_uid();
58981+
58982+ if (uid_eq(uid, GLOBAL_ROOT_UID))
58983+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
58984+ else {
58985+ /* kill all the processes of this user, hold a reference
58986+ to their creds struct, and prevent them from creating
58987+ another process until system reset
58988+ */
58989+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
58990+ from_kuid_munged(&init_user_ns, uid));
58991+ /* we intentionally leak this ref */
58992+ user = get_uid(current->cred->user);
58993+ if (user) {
58994+ user->banned = 1;
58995+ user->ban_expires = ~0UL;
58996+ }
58997+
58998+ read_lock(&tasklist_lock);
58999+ do_each_thread(tsk2, tsk) {
59000+ cred = __task_cred(tsk);
59001+ if (uid_eq(cred->uid, uid))
59002+ gr_fake_force_sig(SIGKILL, tsk);
59003+ } while_each_thread(tsk2, tsk);
59004+ read_unlock(&tasklist_lock);
59005+ }
59006+#endif
59007+}
59008+
59009+int __gr_process_user_ban(struct user_struct *user)
59010+{
59011+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59012+ if (unlikely(user->banned)) {
59013+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
59014+ user->banned = 0;
59015+ user->ban_expires = 0;
59016+ free_uid(user);
59017+ } else
59018+ return -EPERM;
59019+ }
59020+#endif
59021+ return 0;
59022+}
59023+
59024+int gr_process_user_ban(void)
59025+{
59026+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59027+ return __gr_process_user_ban(current->cred->user);
59028+#endif
59029+ return 0;
59030+}
59031diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
59032new file mode 100644
59033index 0000000..4030d57
59034--- /dev/null
59035+++ b/grsecurity/grsec_sock.c
59036@@ -0,0 +1,244 @@
59037+#include <linux/kernel.h>
59038+#include <linux/module.h>
59039+#include <linux/sched.h>
59040+#include <linux/file.h>
59041+#include <linux/net.h>
59042+#include <linux/in.h>
59043+#include <linux/ip.h>
59044+#include <net/sock.h>
59045+#include <net/inet_sock.h>
59046+#include <linux/grsecurity.h>
59047+#include <linux/grinternal.h>
59048+#include <linux/gracl.h>
59049+
59050+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
59051+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
59052+
59053+EXPORT_SYMBOL(gr_search_udp_recvmsg);
59054+EXPORT_SYMBOL(gr_search_udp_sendmsg);
59055+
59056+#ifdef CONFIG_UNIX_MODULE
59057+EXPORT_SYMBOL(gr_acl_handle_unix);
59058+EXPORT_SYMBOL(gr_acl_handle_mknod);
59059+EXPORT_SYMBOL(gr_handle_chroot_unix);
59060+EXPORT_SYMBOL(gr_handle_create);
59061+#endif
59062+
59063+#ifdef CONFIG_GRKERNSEC
59064+#define gr_conn_table_size 32749
59065+struct conn_table_entry {
59066+ struct conn_table_entry *next;
59067+ struct signal_struct *sig;
59068+};
59069+
59070+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
59071+DEFINE_SPINLOCK(gr_conn_table_lock);
59072+
59073+extern const char * gr_socktype_to_name(unsigned char type);
59074+extern const char * gr_proto_to_name(unsigned char proto);
59075+extern const char * gr_sockfamily_to_name(unsigned char family);
59076+
59077+static __inline__ int
59078+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
59079+{
59080+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
59081+}
59082+
59083+static __inline__ int
59084+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
59085+ __u16 sport, __u16 dport)
59086+{
59087+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
59088+ sig->gr_sport == sport && sig->gr_dport == dport))
59089+ return 1;
59090+ else
59091+ return 0;
59092+}
59093+
59094+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
59095+{
59096+ struct conn_table_entry **match;
59097+ unsigned int index;
59098+
59099+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59100+ sig->gr_sport, sig->gr_dport,
59101+ gr_conn_table_size);
59102+
59103+ newent->sig = sig;
59104+
59105+ match = &gr_conn_table[index];
59106+ newent->next = *match;
59107+ *match = newent;
59108+
59109+ return;
59110+}
59111+
59112+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
59113+{
59114+ struct conn_table_entry *match, *last = NULL;
59115+ unsigned int index;
59116+
59117+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59118+ sig->gr_sport, sig->gr_dport,
59119+ gr_conn_table_size);
59120+
59121+ match = gr_conn_table[index];
59122+ while (match && !conn_match(match->sig,
59123+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
59124+ sig->gr_dport)) {
59125+ last = match;
59126+ match = match->next;
59127+ }
59128+
59129+ if (match) {
59130+ if (last)
59131+ last->next = match->next;
59132+ else
59133+ gr_conn_table[index] = NULL;
59134+ kfree(match);
59135+ }
59136+
59137+ return;
59138+}
59139+
59140+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
59141+ __u16 sport, __u16 dport)
59142+{
59143+ struct conn_table_entry *match;
59144+ unsigned int index;
59145+
59146+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
59147+
59148+ match = gr_conn_table[index];
59149+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
59150+ match = match->next;
59151+
59152+ if (match)
59153+ return match->sig;
59154+ else
59155+ return NULL;
59156+}
59157+
59158+#endif
59159+
59160+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59161+{
59162+#ifdef CONFIG_GRKERNSEC
59163+ struct signal_struct *sig = task->signal;
59164+ struct conn_table_entry *newent;
59165+
59166+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59167+ if (newent == NULL)
59168+ return;
59169+ /* no bh lock needed since we are called with bh disabled */
59170+ spin_lock(&gr_conn_table_lock);
59171+ gr_del_task_from_ip_table_nolock(sig);
59172+ sig->gr_saddr = inet->inet_rcv_saddr;
59173+ sig->gr_daddr = inet->inet_daddr;
59174+ sig->gr_sport = inet->inet_sport;
59175+ sig->gr_dport = inet->inet_dport;
59176+ gr_add_to_task_ip_table_nolock(sig, newent);
59177+ spin_unlock(&gr_conn_table_lock);
59178+#endif
59179+ return;
59180+}
59181+
59182+void gr_del_task_from_ip_table(struct task_struct *task)
59183+{
59184+#ifdef CONFIG_GRKERNSEC
59185+ spin_lock_bh(&gr_conn_table_lock);
59186+ gr_del_task_from_ip_table_nolock(task->signal);
59187+ spin_unlock_bh(&gr_conn_table_lock);
59188+#endif
59189+ return;
59190+}
59191+
59192+void
59193+gr_attach_curr_ip(const struct sock *sk)
59194+{
59195+#ifdef CONFIG_GRKERNSEC
59196+ struct signal_struct *p, *set;
59197+ const struct inet_sock *inet = inet_sk(sk);
59198+
59199+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59200+ return;
59201+
59202+ set = current->signal;
59203+
59204+ spin_lock_bh(&gr_conn_table_lock);
59205+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59206+ inet->inet_dport, inet->inet_sport);
59207+ if (unlikely(p != NULL)) {
59208+ set->curr_ip = p->curr_ip;
59209+ set->used_accept = 1;
59210+ gr_del_task_from_ip_table_nolock(p);
59211+ spin_unlock_bh(&gr_conn_table_lock);
59212+ return;
59213+ }
59214+ spin_unlock_bh(&gr_conn_table_lock);
59215+
59216+ set->curr_ip = inet->inet_daddr;
59217+ set->used_accept = 1;
59218+#endif
59219+ return;
59220+}
59221+
59222+int
59223+gr_handle_sock_all(const int family, const int type, const int protocol)
59224+{
59225+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59226+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59227+ (family != AF_UNIX)) {
59228+ if (family == AF_INET)
59229+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59230+ else
59231+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59232+ return -EACCES;
59233+ }
59234+#endif
59235+ return 0;
59236+}
59237+
59238+int
59239+gr_handle_sock_server(const struct sockaddr *sck)
59240+{
59241+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59242+ if (grsec_enable_socket_server &&
59243+ in_group_p(grsec_socket_server_gid) &&
59244+ sck && (sck->sa_family != AF_UNIX) &&
59245+ (sck->sa_family != AF_LOCAL)) {
59246+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59247+ return -EACCES;
59248+ }
59249+#endif
59250+ return 0;
59251+}
59252+
59253+int
59254+gr_handle_sock_server_other(const struct sock *sck)
59255+{
59256+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59257+ if (grsec_enable_socket_server &&
59258+ in_group_p(grsec_socket_server_gid) &&
59259+ sck && (sck->sk_family != AF_UNIX) &&
59260+ (sck->sk_family != AF_LOCAL)) {
59261+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59262+ return -EACCES;
59263+ }
59264+#endif
59265+ return 0;
59266+}
59267+
59268+int
59269+gr_handle_sock_client(const struct sockaddr *sck)
59270+{
59271+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59272+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59273+ sck && (sck->sa_family != AF_UNIX) &&
59274+ (sck->sa_family != AF_LOCAL)) {
59275+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59276+ return -EACCES;
59277+ }
59278+#endif
59279+ return 0;
59280+}
59281diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
59282new file mode 100644
59283index 0000000..f55ef0f
59284--- /dev/null
59285+++ b/grsecurity/grsec_sysctl.c
59286@@ -0,0 +1,469 @@
59287+#include <linux/kernel.h>
59288+#include <linux/sched.h>
59289+#include <linux/sysctl.h>
59290+#include <linux/grsecurity.h>
59291+#include <linux/grinternal.h>
59292+
59293+int
59294+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59295+{
59296+#ifdef CONFIG_GRKERNSEC_SYSCTL
59297+ if (dirname == NULL || name == NULL)
59298+ return 0;
59299+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59300+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59301+ return -EACCES;
59302+ }
59303+#endif
59304+ return 0;
59305+}
59306+
59307+#ifdef CONFIG_GRKERNSEC_ROFS
59308+static int __maybe_unused one = 1;
59309+#endif
59310+
59311+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59312+struct ctl_table grsecurity_table[] = {
59313+#ifdef CONFIG_GRKERNSEC_SYSCTL
59314+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59315+#ifdef CONFIG_GRKERNSEC_IO
59316+ {
59317+ .procname = "disable_priv_io",
59318+ .data = &grsec_disable_privio,
59319+ .maxlen = sizeof(int),
59320+ .mode = 0600,
59321+ .proc_handler = &proc_dointvec,
59322+ },
59323+#endif
59324+#endif
59325+#ifdef CONFIG_GRKERNSEC_LINK
59326+ {
59327+ .procname = "linking_restrictions",
59328+ .data = &grsec_enable_link,
59329+ .maxlen = sizeof(int),
59330+ .mode = 0600,
59331+ .proc_handler = &proc_dointvec,
59332+ },
59333+#endif
59334+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59335+ {
59336+ .procname = "enforce_symlinksifowner",
59337+ .data = &grsec_enable_symlinkown,
59338+ .maxlen = sizeof(int),
59339+ .mode = 0600,
59340+ .proc_handler = &proc_dointvec,
59341+ },
59342+ {
59343+ .procname = "symlinkown_gid",
59344+ .data = &grsec_symlinkown_gid,
59345+ .maxlen = sizeof(int),
59346+ .mode = 0600,
59347+ .proc_handler = &proc_dointvec,
59348+ },
59349+#endif
59350+#ifdef CONFIG_GRKERNSEC_BRUTE
59351+ {
59352+ .procname = "deter_bruteforce",
59353+ .data = &grsec_enable_brute,
59354+ .maxlen = sizeof(int),
59355+ .mode = 0600,
59356+ .proc_handler = &proc_dointvec,
59357+ },
59358+#endif
59359+#ifdef CONFIG_GRKERNSEC_FIFO
59360+ {
59361+ .procname = "fifo_restrictions",
59362+ .data = &grsec_enable_fifo,
59363+ .maxlen = sizeof(int),
59364+ .mode = 0600,
59365+ .proc_handler = &proc_dointvec,
59366+ },
59367+#endif
59368+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59369+ {
59370+ .procname = "ptrace_readexec",
59371+ .data = &grsec_enable_ptrace_readexec,
59372+ .maxlen = sizeof(int),
59373+ .mode = 0600,
59374+ .proc_handler = &proc_dointvec,
59375+ },
59376+#endif
59377+#ifdef CONFIG_GRKERNSEC_SETXID
59378+ {
59379+ .procname = "consistent_setxid",
59380+ .data = &grsec_enable_setxid,
59381+ .maxlen = sizeof(int),
59382+ .mode = 0600,
59383+ .proc_handler = &proc_dointvec,
59384+ },
59385+#endif
59386+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59387+ {
59388+ .procname = "ip_blackhole",
59389+ .data = &grsec_enable_blackhole,
59390+ .maxlen = sizeof(int),
59391+ .mode = 0600,
59392+ .proc_handler = &proc_dointvec,
59393+ },
59394+ {
59395+ .procname = "lastack_retries",
59396+ .data = &grsec_lastack_retries,
59397+ .maxlen = sizeof(int),
59398+ .mode = 0600,
59399+ .proc_handler = &proc_dointvec,
59400+ },
59401+#endif
59402+#ifdef CONFIG_GRKERNSEC_EXECLOG
59403+ {
59404+ .procname = "exec_logging",
59405+ .data = &grsec_enable_execlog,
59406+ .maxlen = sizeof(int),
59407+ .mode = 0600,
59408+ .proc_handler = &proc_dointvec,
59409+ },
59410+#endif
59411+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59412+ {
59413+ .procname = "rwxmap_logging",
59414+ .data = &grsec_enable_log_rwxmaps,
59415+ .maxlen = sizeof(int),
59416+ .mode = 0600,
59417+ .proc_handler = &proc_dointvec,
59418+ },
59419+#endif
59420+#ifdef CONFIG_GRKERNSEC_SIGNAL
59421+ {
59422+ .procname = "signal_logging",
59423+ .data = &grsec_enable_signal,
59424+ .maxlen = sizeof(int),
59425+ .mode = 0600,
59426+ .proc_handler = &proc_dointvec,
59427+ },
59428+#endif
59429+#ifdef CONFIG_GRKERNSEC_FORKFAIL
59430+ {
59431+ .procname = "forkfail_logging",
59432+ .data = &grsec_enable_forkfail,
59433+ .maxlen = sizeof(int),
59434+ .mode = 0600,
59435+ .proc_handler = &proc_dointvec,
59436+ },
59437+#endif
59438+#ifdef CONFIG_GRKERNSEC_TIME
59439+ {
59440+ .procname = "timechange_logging",
59441+ .data = &grsec_enable_time,
59442+ .maxlen = sizeof(int),
59443+ .mode = 0600,
59444+ .proc_handler = &proc_dointvec,
59445+ },
59446+#endif
59447+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59448+ {
59449+ .procname = "chroot_deny_shmat",
59450+ .data = &grsec_enable_chroot_shmat,
59451+ .maxlen = sizeof(int),
59452+ .mode = 0600,
59453+ .proc_handler = &proc_dointvec,
59454+ },
59455+#endif
59456+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59457+ {
59458+ .procname = "chroot_deny_unix",
59459+ .data = &grsec_enable_chroot_unix,
59460+ .maxlen = sizeof(int),
59461+ .mode = 0600,
59462+ .proc_handler = &proc_dointvec,
59463+ },
59464+#endif
59465+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59466+ {
59467+ .procname = "chroot_deny_mount",
59468+ .data = &grsec_enable_chroot_mount,
59469+ .maxlen = sizeof(int),
59470+ .mode = 0600,
59471+ .proc_handler = &proc_dointvec,
59472+ },
59473+#endif
59474+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59475+ {
59476+ .procname = "chroot_deny_fchdir",
59477+ .data = &grsec_enable_chroot_fchdir,
59478+ .maxlen = sizeof(int),
59479+ .mode = 0600,
59480+ .proc_handler = &proc_dointvec,
59481+ },
59482+#endif
59483+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59484+ {
59485+ .procname = "chroot_deny_chroot",
59486+ .data = &grsec_enable_chroot_double,
59487+ .maxlen = sizeof(int),
59488+ .mode = 0600,
59489+ .proc_handler = &proc_dointvec,
59490+ },
59491+#endif
59492+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59493+ {
59494+ .procname = "chroot_deny_pivot",
59495+ .data = &grsec_enable_chroot_pivot,
59496+ .maxlen = sizeof(int),
59497+ .mode = 0600,
59498+ .proc_handler = &proc_dointvec,
59499+ },
59500+#endif
59501+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59502+ {
59503+ .procname = "chroot_enforce_chdir",
59504+ .data = &grsec_enable_chroot_chdir,
59505+ .maxlen = sizeof(int),
59506+ .mode = 0600,
59507+ .proc_handler = &proc_dointvec,
59508+ },
59509+#endif
59510+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59511+ {
59512+ .procname = "chroot_deny_chmod",
59513+ .data = &grsec_enable_chroot_chmod,
59514+ .maxlen = sizeof(int),
59515+ .mode = 0600,
59516+ .proc_handler = &proc_dointvec,
59517+ },
59518+#endif
59519+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59520+ {
59521+ .procname = "chroot_deny_mknod",
59522+ .data = &grsec_enable_chroot_mknod,
59523+ .maxlen = sizeof(int),
59524+ .mode = 0600,
59525+ .proc_handler = &proc_dointvec,
59526+ },
59527+#endif
59528+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59529+ {
59530+ .procname = "chroot_restrict_nice",
59531+ .data = &grsec_enable_chroot_nice,
59532+ .maxlen = sizeof(int),
59533+ .mode = 0600,
59534+ .proc_handler = &proc_dointvec,
59535+ },
59536+#endif
59537+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59538+ {
59539+ .procname = "chroot_execlog",
59540+ .data = &grsec_enable_chroot_execlog,
59541+ .maxlen = sizeof(int),
59542+ .mode = 0600,
59543+ .proc_handler = &proc_dointvec,
59544+ },
59545+#endif
59546+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59547+ {
59548+ .procname = "chroot_caps",
59549+ .data = &grsec_enable_chroot_caps,
59550+ .maxlen = sizeof(int),
59551+ .mode = 0600,
59552+ .proc_handler = &proc_dointvec,
59553+ },
59554+#endif
59555+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59556+ {
59557+ .procname = "chroot_deny_sysctl",
59558+ .data = &grsec_enable_chroot_sysctl,
59559+ .maxlen = sizeof(int),
59560+ .mode = 0600,
59561+ .proc_handler = &proc_dointvec,
59562+ },
59563+#endif
59564+#ifdef CONFIG_GRKERNSEC_TPE
59565+ {
59566+ .procname = "tpe",
59567+ .data = &grsec_enable_tpe,
59568+ .maxlen = sizeof(int),
59569+ .mode = 0600,
59570+ .proc_handler = &proc_dointvec,
59571+ },
59572+ {
59573+ .procname = "tpe_gid",
59574+ .data = &grsec_tpe_gid,
59575+ .maxlen = sizeof(int),
59576+ .mode = 0600,
59577+ .proc_handler = &proc_dointvec,
59578+ },
59579+#endif
59580+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59581+ {
59582+ .procname = "tpe_invert",
59583+ .data = &grsec_enable_tpe_invert,
59584+ .maxlen = sizeof(int),
59585+ .mode = 0600,
59586+ .proc_handler = &proc_dointvec,
59587+ },
59588+#endif
59589+#ifdef CONFIG_GRKERNSEC_TPE_ALL
59590+ {
59591+ .procname = "tpe_restrict_all",
59592+ .data = &grsec_enable_tpe_all,
59593+ .maxlen = sizeof(int),
59594+ .mode = 0600,
59595+ .proc_handler = &proc_dointvec,
59596+ },
59597+#endif
59598+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59599+ {
59600+ .procname = "socket_all",
59601+ .data = &grsec_enable_socket_all,
59602+ .maxlen = sizeof(int),
59603+ .mode = 0600,
59604+ .proc_handler = &proc_dointvec,
59605+ },
59606+ {
59607+ .procname = "socket_all_gid",
59608+ .data = &grsec_socket_all_gid,
59609+ .maxlen = sizeof(int),
59610+ .mode = 0600,
59611+ .proc_handler = &proc_dointvec,
59612+ },
59613+#endif
59614+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59615+ {
59616+ .procname = "socket_client",
59617+ .data = &grsec_enable_socket_client,
59618+ .maxlen = sizeof(int),
59619+ .mode = 0600,
59620+ .proc_handler = &proc_dointvec,
59621+ },
59622+ {
59623+ .procname = "socket_client_gid",
59624+ .data = &grsec_socket_client_gid,
59625+ .maxlen = sizeof(int),
59626+ .mode = 0600,
59627+ .proc_handler = &proc_dointvec,
59628+ },
59629+#endif
59630+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59631+ {
59632+ .procname = "socket_server",
59633+ .data = &grsec_enable_socket_server,
59634+ .maxlen = sizeof(int),
59635+ .mode = 0600,
59636+ .proc_handler = &proc_dointvec,
59637+ },
59638+ {
59639+ .procname = "socket_server_gid",
59640+ .data = &grsec_socket_server_gid,
59641+ .maxlen = sizeof(int),
59642+ .mode = 0600,
59643+ .proc_handler = &proc_dointvec,
59644+ },
59645+#endif
59646+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
59647+ {
59648+ .procname = "audit_group",
59649+ .data = &grsec_enable_group,
59650+ .maxlen = sizeof(int),
59651+ .mode = 0600,
59652+ .proc_handler = &proc_dointvec,
59653+ },
59654+ {
59655+ .procname = "audit_gid",
59656+ .data = &grsec_audit_gid,
59657+ .maxlen = sizeof(int),
59658+ .mode = 0600,
59659+ .proc_handler = &proc_dointvec,
59660+ },
59661+#endif
59662+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59663+ {
59664+ .procname = "audit_chdir",
59665+ .data = &grsec_enable_chdir,
59666+ .maxlen = sizeof(int),
59667+ .mode = 0600,
59668+ .proc_handler = &proc_dointvec,
59669+ },
59670+#endif
59671+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59672+ {
59673+ .procname = "audit_mount",
59674+ .data = &grsec_enable_mount,
59675+ .maxlen = sizeof(int),
59676+ .mode = 0600,
59677+ .proc_handler = &proc_dointvec,
59678+ },
59679+#endif
59680+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59681+ {
59682+ .procname = "audit_textrel",
59683+ .data = &grsec_enable_audit_textrel,
59684+ .maxlen = sizeof(int),
59685+ .mode = 0600,
59686+ .proc_handler = &proc_dointvec,
59687+ },
59688+#endif
59689+#ifdef CONFIG_GRKERNSEC_DMESG
59690+ {
59691+ .procname = "dmesg",
59692+ .data = &grsec_enable_dmesg,
59693+ .maxlen = sizeof(int),
59694+ .mode = 0600,
59695+ .proc_handler = &proc_dointvec,
59696+ },
59697+#endif
59698+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59699+ {
59700+ .procname = "chroot_findtask",
59701+ .data = &grsec_enable_chroot_findtask,
59702+ .maxlen = sizeof(int),
59703+ .mode = 0600,
59704+ .proc_handler = &proc_dointvec,
59705+ },
59706+#endif
59707+#ifdef CONFIG_GRKERNSEC_RESLOG
59708+ {
59709+ .procname = "resource_logging",
59710+ .data = &grsec_resource_logging,
59711+ .maxlen = sizeof(int),
59712+ .mode = 0600,
59713+ .proc_handler = &proc_dointvec,
59714+ },
59715+#endif
59716+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59717+ {
59718+ .procname = "audit_ptrace",
59719+ .data = &grsec_enable_audit_ptrace,
59720+ .maxlen = sizeof(int),
59721+ .mode = 0600,
59722+ .proc_handler = &proc_dointvec,
59723+ },
59724+#endif
59725+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59726+ {
59727+ .procname = "harden_ptrace",
59728+ .data = &grsec_enable_harden_ptrace,
59729+ .maxlen = sizeof(int),
59730+ .mode = 0600,
59731+ .proc_handler = &proc_dointvec,
59732+ },
59733+#endif
59734+ {
59735+ .procname = "grsec_lock",
59736+ .data = &grsec_lock,
59737+ .maxlen = sizeof(int),
59738+ .mode = 0600,
59739+ .proc_handler = &proc_dointvec,
59740+ },
59741+#endif
59742+#ifdef CONFIG_GRKERNSEC_ROFS
59743+ {
59744+ .procname = "romount_protect",
59745+ .data = &grsec_enable_rofs,
59746+ .maxlen = sizeof(int),
59747+ .mode = 0600,
59748+ .proc_handler = &proc_dointvec_minmax,
59749+ .extra1 = &one,
59750+ .extra2 = &one,
59751+ },
59752+#endif
59753+ { }
59754+};
59755+#endif
59756diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
59757new file mode 100644
59758index 0000000..0dc13c3
59759--- /dev/null
59760+++ b/grsecurity/grsec_time.c
59761@@ -0,0 +1,16 @@
59762+#include <linux/kernel.h>
59763+#include <linux/sched.h>
59764+#include <linux/grinternal.h>
59765+#include <linux/module.h>
59766+
59767+void
59768+gr_log_timechange(void)
59769+{
59770+#ifdef CONFIG_GRKERNSEC_TIME
59771+ if (grsec_enable_time)
59772+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
59773+#endif
59774+ return;
59775+}
59776+
59777+EXPORT_SYMBOL(gr_log_timechange);
59778diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
59779new file mode 100644
59780index 0000000..07e0dc0
59781--- /dev/null
59782+++ b/grsecurity/grsec_tpe.c
59783@@ -0,0 +1,73 @@
59784+#include <linux/kernel.h>
59785+#include <linux/sched.h>
59786+#include <linux/file.h>
59787+#include <linux/fs.h>
59788+#include <linux/grinternal.h>
59789+
59790+extern int gr_acl_tpe_check(void);
59791+
59792+int
59793+gr_tpe_allow(const struct file *file)
59794+{
59795+#ifdef CONFIG_GRKERNSEC
59796+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
59797+ const struct cred *cred = current_cred();
59798+ char *msg = NULL;
59799+ char *msg2 = NULL;
59800+
59801+ // never restrict root
59802+ if (!cred->uid)
59803+ return 1;
59804+
59805+ if (grsec_enable_tpe) {
59806+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59807+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
59808+ msg = "not being in trusted group";
59809+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
59810+ msg = "being in untrusted group";
59811+#else
59812+ if (in_group_p(grsec_tpe_gid))
59813+ msg = "being in untrusted group";
59814+#endif
59815+ }
59816+ if (!msg && gr_acl_tpe_check())
59817+ msg = "being in untrusted role";
59818+
59819+ // not in any affected group/role
59820+ if (!msg)
59821+ goto next_check;
59822+
59823+ if (inode->i_uid)
59824+ msg2 = "file in non-root-owned directory";
59825+ else if (inode->i_mode & S_IWOTH)
59826+ msg2 = "file in world-writable directory";
59827+ else if (inode->i_mode & S_IWGRP)
59828+ msg2 = "file in group-writable directory";
59829+
59830+ if (msg && msg2) {
59831+ char fullmsg[70] = {0};
59832+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
59833+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
59834+ return 0;
59835+ }
59836+ msg = NULL;
59837+next_check:
59838+#ifdef CONFIG_GRKERNSEC_TPE_ALL
59839+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
59840+ return 1;
59841+
59842+ if (inode->i_uid && (inode->i_uid != cred->uid))
59843+ msg = "directory not owned by user";
59844+ else if (inode->i_mode & S_IWOTH)
59845+ msg = "file in world-writable directory";
59846+ else if (inode->i_mode & S_IWGRP)
59847+ msg = "file in group-writable directory";
59848+
59849+ if (msg) {
59850+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
59851+ return 0;
59852+ }
59853+#endif
59854+#endif
59855+ return 1;
59856+}
59857diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
59858new file mode 100644
59859index 0000000..9f7b1ac
59860--- /dev/null
59861+++ b/grsecurity/grsum.c
59862@@ -0,0 +1,61 @@
59863+#include <linux/err.h>
59864+#include <linux/kernel.h>
59865+#include <linux/sched.h>
59866+#include <linux/mm.h>
59867+#include <linux/scatterlist.h>
59868+#include <linux/crypto.h>
59869+#include <linux/gracl.h>
59870+
59871+
59872+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
59873+#error "crypto and sha256 must be built into the kernel"
59874+#endif
59875+
59876+int
59877+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
59878+{
59879+ char *p;
59880+ struct crypto_hash *tfm;
59881+ struct hash_desc desc;
59882+ struct scatterlist sg;
59883+ unsigned char temp_sum[GR_SHA_LEN];
59884+ volatile int retval = 0;
59885+ volatile int dummy = 0;
59886+ unsigned int i;
59887+
59888+ sg_init_table(&sg, 1);
59889+
59890+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
59891+ if (IS_ERR(tfm)) {
59892+ /* should never happen, since sha256 should be built in */
59893+ return 1;
59894+ }
59895+
59896+ desc.tfm = tfm;
59897+ desc.flags = 0;
59898+
59899+ crypto_hash_init(&desc);
59900+
59901+ p = salt;
59902+ sg_set_buf(&sg, p, GR_SALT_LEN);
59903+ crypto_hash_update(&desc, &sg, sg.length);
59904+
59905+ p = entry->pw;
59906+ sg_set_buf(&sg, p, strlen(p));
59907+
59908+ crypto_hash_update(&desc, &sg, sg.length);
59909+
59910+ crypto_hash_final(&desc, temp_sum);
59911+
59912+ memset(entry->pw, 0, GR_PW_LEN);
59913+
59914+ for (i = 0; i < GR_SHA_LEN; i++)
59915+ if (sum[i] != temp_sum[i])
59916+ retval = 1;
59917+ else
59918+ dummy = 1; // waste a cycle
59919+
59920+ crypto_free_hash(tfm);
59921+
59922+ return retval;
59923+}
59924diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
59925index 9e6e1c6..d47b906 100644
59926--- a/include/acpi/acpi_bus.h
59927+++ b/include/acpi/acpi_bus.h
59928@@ -138,7 +138,7 @@ struct acpi_device_ops {
59929 acpi_op_bind bind;
59930 acpi_op_unbind unbind;
59931 acpi_op_notify notify;
59932-};
59933+} __no_const;
59934
59935 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
59936
59937diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
59938index b7babf0..3ba8aee 100644
59939--- a/include/asm-generic/atomic-long.h
59940+++ b/include/asm-generic/atomic-long.h
59941@@ -22,6 +22,12 @@
59942
59943 typedef atomic64_t atomic_long_t;
59944
59945+#ifdef CONFIG_PAX_REFCOUNT
59946+typedef atomic64_unchecked_t atomic_long_unchecked_t;
59947+#else
59948+typedef atomic64_t atomic_long_unchecked_t;
59949+#endif
59950+
59951 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
59952
59953 static inline long atomic_long_read(atomic_long_t *l)
59954@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59955 return (long)atomic64_read(v);
59956 }
59957
59958+#ifdef CONFIG_PAX_REFCOUNT
59959+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59960+{
59961+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59962+
59963+ return (long)atomic64_read_unchecked(v);
59964+}
59965+#endif
59966+
59967 static inline void atomic_long_set(atomic_long_t *l, long i)
59968 {
59969 atomic64_t *v = (atomic64_t *)l;
59970@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59971 atomic64_set(v, i);
59972 }
59973
59974+#ifdef CONFIG_PAX_REFCOUNT
59975+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59976+{
59977+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59978+
59979+ atomic64_set_unchecked(v, i);
59980+}
59981+#endif
59982+
59983 static inline void atomic_long_inc(atomic_long_t *l)
59984 {
59985 atomic64_t *v = (atomic64_t *)l;
59986@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59987 atomic64_inc(v);
59988 }
59989
59990+#ifdef CONFIG_PAX_REFCOUNT
59991+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59992+{
59993+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59994+
59995+ atomic64_inc_unchecked(v);
59996+}
59997+#endif
59998+
59999 static inline void atomic_long_dec(atomic_long_t *l)
60000 {
60001 atomic64_t *v = (atomic64_t *)l;
60002@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60003 atomic64_dec(v);
60004 }
60005
60006+#ifdef CONFIG_PAX_REFCOUNT
60007+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60008+{
60009+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60010+
60011+ atomic64_dec_unchecked(v);
60012+}
60013+#endif
60014+
60015 static inline void atomic_long_add(long i, atomic_long_t *l)
60016 {
60017 atomic64_t *v = (atomic64_t *)l;
60018@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60019 atomic64_add(i, v);
60020 }
60021
60022+#ifdef CONFIG_PAX_REFCOUNT
60023+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60024+{
60025+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60026+
60027+ atomic64_add_unchecked(i, v);
60028+}
60029+#endif
60030+
60031 static inline void atomic_long_sub(long i, atomic_long_t *l)
60032 {
60033 atomic64_t *v = (atomic64_t *)l;
60034@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60035 atomic64_sub(i, v);
60036 }
60037
60038+#ifdef CONFIG_PAX_REFCOUNT
60039+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60040+{
60041+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60042+
60043+ atomic64_sub_unchecked(i, v);
60044+}
60045+#endif
60046+
60047 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60048 {
60049 atomic64_t *v = (atomic64_t *)l;
60050@@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60051 return (long)atomic64_inc_return(v);
60052 }
60053
60054+#ifdef CONFIG_PAX_REFCOUNT
60055+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60056+{
60057+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60058+
60059+ return (long)atomic64_inc_return_unchecked(v);
60060+}
60061+#endif
60062+
60063 static inline long atomic_long_dec_return(atomic_long_t *l)
60064 {
60065 atomic64_t *v = (atomic64_t *)l;
60066@@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60067
60068 typedef atomic_t atomic_long_t;
60069
60070+#ifdef CONFIG_PAX_REFCOUNT
60071+typedef atomic_unchecked_t atomic_long_unchecked_t;
60072+#else
60073+typedef atomic_t atomic_long_unchecked_t;
60074+#endif
60075+
60076 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
60077 static inline long atomic_long_read(atomic_long_t *l)
60078 {
60079@@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60080 return (long)atomic_read(v);
60081 }
60082
60083+#ifdef CONFIG_PAX_REFCOUNT
60084+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60085+{
60086+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60087+
60088+ return (long)atomic_read_unchecked(v);
60089+}
60090+#endif
60091+
60092 static inline void atomic_long_set(atomic_long_t *l, long i)
60093 {
60094 atomic_t *v = (atomic_t *)l;
60095@@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60096 atomic_set(v, i);
60097 }
60098
60099+#ifdef CONFIG_PAX_REFCOUNT
60100+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60101+{
60102+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60103+
60104+ atomic_set_unchecked(v, i);
60105+}
60106+#endif
60107+
60108 static inline void atomic_long_inc(atomic_long_t *l)
60109 {
60110 atomic_t *v = (atomic_t *)l;
60111@@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60112 atomic_inc(v);
60113 }
60114
60115+#ifdef CONFIG_PAX_REFCOUNT
60116+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60117+{
60118+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60119+
60120+ atomic_inc_unchecked(v);
60121+}
60122+#endif
60123+
60124 static inline void atomic_long_dec(atomic_long_t *l)
60125 {
60126 atomic_t *v = (atomic_t *)l;
60127@@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60128 atomic_dec(v);
60129 }
60130
60131+#ifdef CONFIG_PAX_REFCOUNT
60132+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60133+{
60134+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60135+
60136+ atomic_dec_unchecked(v);
60137+}
60138+#endif
60139+
60140 static inline void atomic_long_add(long i, atomic_long_t *l)
60141 {
60142 atomic_t *v = (atomic_t *)l;
60143@@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60144 atomic_add(i, v);
60145 }
60146
60147+#ifdef CONFIG_PAX_REFCOUNT
60148+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60149+{
60150+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60151+
60152+ atomic_add_unchecked(i, v);
60153+}
60154+#endif
60155+
60156 static inline void atomic_long_sub(long i, atomic_long_t *l)
60157 {
60158 atomic_t *v = (atomic_t *)l;
60159@@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60160 atomic_sub(i, v);
60161 }
60162
60163+#ifdef CONFIG_PAX_REFCOUNT
60164+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60165+{
60166+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60167+
60168+ atomic_sub_unchecked(i, v);
60169+}
60170+#endif
60171+
60172 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60173 {
60174 atomic_t *v = (atomic_t *)l;
60175@@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60176 return (long)atomic_inc_return(v);
60177 }
60178
60179+#ifdef CONFIG_PAX_REFCOUNT
60180+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60181+{
60182+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60183+
60184+ return (long)atomic_inc_return_unchecked(v);
60185+}
60186+#endif
60187+
60188 static inline long atomic_long_dec_return(atomic_long_t *l)
60189 {
60190 atomic_t *v = (atomic_t *)l;
60191@@ -255,4 +393,55 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60192
60193 #endif /* BITS_PER_LONG == 64 */
60194
60195+#ifdef CONFIG_PAX_REFCOUNT
60196+static inline void pax_refcount_needs_these_functions(void)
60197+{
60198+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
60199+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
60200+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
60201+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
60202+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
60203+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
60204+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
60205+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
60206+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
60207+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
60208+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
60209+#ifdef CONFIG_X86
60210+ atomic_clear_mask_unchecked(0, NULL);
60211+ atomic_set_mask_unchecked(0, NULL);
60212+#endif
60213+
60214+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
60215+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
60216+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
60217+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
60218+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
60219+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
60220+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
60221+}
60222+#else
60223+#define atomic_read_unchecked(v) atomic_read(v)
60224+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
60225+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
60226+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
60227+#define atomic_inc_unchecked(v) atomic_inc(v)
60228+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
60229+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
60230+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
60231+#define atomic_dec_unchecked(v) atomic_dec(v)
60232+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
60233+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
60234+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
60235+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
60236+
60237+#define atomic_long_read_unchecked(v) atomic_long_read(v)
60238+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
60239+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
60240+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
60241+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
60242+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
60243+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
60244+#endif
60245+
60246 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
60247diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
60248index 1ced641..c896ee8 100644
60249--- a/include/asm-generic/atomic.h
60250+++ b/include/asm-generic/atomic.h
60251@@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
60252 * Atomically clears the bits set in @mask from @v
60253 */
60254 #ifndef atomic_clear_mask
60255-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
60256+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
60257 {
60258 unsigned long flags;
60259
60260diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
60261index b18ce4f..2ee2843 100644
60262--- a/include/asm-generic/atomic64.h
60263+++ b/include/asm-generic/atomic64.h
60264@@ -16,6 +16,8 @@ typedef struct {
60265 long long counter;
60266 } atomic64_t;
60267
60268+typedef atomic64_t atomic64_unchecked_t;
60269+
60270 #define ATOMIC64_INIT(i) { (i) }
60271
60272 extern long long atomic64_read(const atomic64_t *v);
60273@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
60274 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
60275 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
60276
60277+#define atomic64_read_unchecked(v) atomic64_read(v)
60278+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
60279+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
60280+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
60281+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
60282+#define atomic64_inc_unchecked(v) atomic64_inc(v)
60283+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
60284+#define atomic64_dec_unchecked(v) atomic64_dec(v)
60285+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
60286+
60287 #endif /* _ASM_GENERIC_ATOMIC64_H */
60288diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
60289index 1bfcfe5..e04c5c9 100644
60290--- a/include/asm-generic/cache.h
60291+++ b/include/asm-generic/cache.h
60292@@ -6,7 +6,7 @@
60293 * cache lines need to provide their own cache.h.
60294 */
60295
60296-#define L1_CACHE_SHIFT 5
60297-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
60298+#define L1_CACHE_SHIFT 5UL
60299+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
60300
60301 #endif /* __ASM_GENERIC_CACHE_H */
60302diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
60303index 0d68a1e..b74a761 100644
60304--- a/include/asm-generic/emergency-restart.h
60305+++ b/include/asm-generic/emergency-restart.h
60306@@ -1,7 +1,7 @@
60307 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
60308 #define _ASM_GENERIC_EMERGENCY_RESTART_H
60309
60310-static inline void machine_emergency_restart(void)
60311+static inline __noreturn void machine_emergency_restart(void)
60312 {
60313 machine_restart(NULL);
60314 }
60315diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
60316index 0232ccb..13d9165 100644
60317--- a/include/asm-generic/kmap_types.h
60318+++ b/include/asm-generic/kmap_types.h
60319@@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
60320 KMAP_D(17) KM_NMI,
60321 KMAP_D(18) KM_NMI_PTE,
60322 KMAP_D(19) KM_KDB,
60323+KMAP_D(20) KM_CLEARPAGE,
60324 /*
60325 * Remember to update debug_kmap_atomic() when adding new kmap types!
60326 */
60327-KMAP_D(20) KM_TYPE_NR
60328+KMAP_D(21) KM_TYPE_NR
60329 };
60330
60331 #undef KMAP_D
60332diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
60333index 9ceb03b..2efbcbd 100644
60334--- a/include/asm-generic/local.h
60335+++ b/include/asm-generic/local.h
60336@@ -39,6 +39,7 @@ typedef struct
60337 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
60338 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
60339 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
60340+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
60341
60342 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
60343 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
60344diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
60345index 725612b..9cc513a 100644
60346--- a/include/asm-generic/pgtable-nopmd.h
60347+++ b/include/asm-generic/pgtable-nopmd.h
60348@@ -1,14 +1,19 @@
60349 #ifndef _PGTABLE_NOPMD_H
60350 #define _PGTABLE_NOPMD_H
60351
60352-#ifndef __ASSEMBLY__
60353-
60354 #include <asm-generic/pgtable-nopud.h>
60355
60356-struct mm_struct;
60357-
60358 #define __PAGETABLE_PMD_FOLDED
60359
60360+#define PMD_SHIFT PUD_SHIFT
60361+#define PTRS_PER_PMD 1
60362+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
60363+#define PMD_MASK (~(PMD_SIZE-1))
60364+
60365+#ifndef __ASSEMBLY__
60366+
60367+struct mm_struct;
60368+
60369 /*
60370 * Having the pmd type consist of a pud gets the size right, and allows
60371 * us to conceptually access the pud entry that this pmd is folded into
60372@@ -16,11 +21,6 @@ struct mm_struct;
60373 */
60374 typedef struct { pud_t pud; } pmd_t;
60375
60376-#define PMD_SHIFT PUD_SHIFT
60377-#define PTRS_PER_PMD 1
60378-#define PMD_SIZE (1UL << PMD_SHIFT)
60379-#define PMD_MASK (~(PMD_SIZE-1))
60380-
60381 /*
60382 * The "pud_xxx()" functions here are trivial for a folded two-level
60383 * setup: the pmd is never bad, and a pmd always exists (as it's folded
60384diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
60385index 810431d..0ec4804f 100644
60386--- a/include/asm-generic/pgtable-nopud.h
60387+++ b/include/asm-generic/pgtable-nopud.h
60388@@ -1,10 +1,15 @@
60389 #ifndef _PGTABLE_NOPUD_H
60390 #define _PGTABLE_NOPUD_H
60391
60392-#ifndef __ASSEMBLY__
60393-
60394 #define __PAGETABLE_PUD_FOLDED
60395
60396+#define PUD_SHIFT PGDIR_SHIFT
60397+#define PTRS_PER_PUD 1
60398+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
60399+#define PUD_MASK (~(PUD_SIZE-1))
60400+
60401+#ifndef __ASSEMBLY__
60402+
60403 /*
60404 * Having the pud type consist of a pgd gets the size right, and allows
60405 * us to conceptually access the pgd entry that this pud is folded into
60406@@ -12,11 +17,6 @@
60407 */
60408 typedef struct { pgd_t pgd; } pud_t;
60409
60410-#define PUD_SHIFT PGDIR_SHIFT
60411-#define PTRS_PER_PUD 1
60412-#define PUD_SIZE (1UL << PUD_SHIFT)
60413-#define PUD_MASK (~(PUD_SIZE-1))
60414-
60415 /*
60416 * The "pgd_xxx()" functions here are trivial for a folded two-level
60417 * setup: the pud is never bad, and a pud always exists (as it's folded
60418@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
60419 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
60420
60421 #define pgd_populate(mm, pgd, pud) do { } while (0)
60422+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
60423 /*
60424 * (puds are folded into pgds so this doesn't get actually called,
60425 * but the define is needed for a generic inline function.)
60426diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
60427index ff4947b..f48183f 100644
60428--- a/include/asm-generic/pgtable.h
60429+++ b/include/asm-generic/pgtable.h
60430@@ -530,6 +530,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
60431 #endif
60432 }
60433
60434+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
60435+static inline unsigned long pax_open_kernel(void) { return 0; }
60436+#endif
60437+
60438+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
60439+static inline unsigned long pax_close_kernel(void) { return 0; }
60440+#endif
60441+
60442 #endif /* CONFIG_MMU */
60443
60444 #endif /* !__ASSEMBLY__ */
60445diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
60446index 4e2e1cc..12c266b 100644
60447--- a/include/asm-generic/vmlinux.lds.h
60448+++ b/include/asm-generic/vmlinux.lds.h
60449@@ -218,6 +218,7 @@
60450 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
60451 VMLINUX_SYMBOL(__start_rodata) = .; \
60452 *(.rodata) *(.rodata.*) \
60453+ *(.data..read_only) \
60454 *(__vermagic) /* Kernel version magic */ \
60455 . = ALIGN(8); \
60456 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
60457@@ -716,17 +717,18 @@
60458 * section in the linker script will go there too. @phdr should have
60459 * a leading colon.
60460 *
60461- * Note that this macros defines __per_cpu_load as an absolute symbol.
60462+ * Note that this macros defines per_cpu_load as an absolute symbol.
60463 * If there is no need to put the percpu section at a predetermined
60464 * address, use PERCPU_SECTION.
60465 */
60466 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
60467- VMLINUX_SYMBOL(__per_cpu_load) = .; \
60468- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
60469+ per_cpu_load = .; \
60470+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
60471 - LOAD_OFFSET) { \
60472+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
60473 PERCPU_INPUT(cacheline) \
60474 } phdr \
60475- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
60476+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
60477
60478 /**
60479 * PERCPU_SECTION - define output section for percpu area, simple version
60480diff --git a/include/drm/drmP.h b/include/drm/drmP.h
60481index 31ad880..4e79884 100644
60482--- a/include/drm/drmP.h
60483+++ b/include/drm/drmP.h
60484@@ -72,6 +72,7 @@
60485 #include <linux/workqueue.h>
60486 #include <linux/poll.h>
60487 #include <asm/pgalloc.h>
60488+#include <asm/local.h>
60489 #include "drm.h"
60490
60491 #include <linux/idr.h>
60492@@ -1074,7 +1075,7 @@ struct drm_device {
60493
60494 /** \name Usage Counters */
60495 /*@{ */
60496- int open_count; /**< Outstanding files open */
60497+ local_t open_count; /**< Outstanding files open */
60498 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
60499 atomic_t vma_count; /**< Outstanding vma areas open */
60500 int buf_use; /**< Buffers in use -- cannot alloc */
60501@@ -1085,7 +1086,7 @@ struct drm_device {
60502 /*@{ */
60503 unsigned long counters;
60504 enum drm_stat_type types[15];
60505- atomic_t counts[15];
60506+ atomic_unchecked_t counts[15];
60507 /*@} */
60508
60509 struct list_head filelist;
60510diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
60511index 7988e55..ec974c9 100644
60512--- a/include/drm/drm_crtc_helper.h
60513+++ b/include/drm/drm_crtc_helper.h
60514@@ -81,7 +81,7 @@ struct drm_crtc_helper_funcs {
60515
60516 /* disable crtc when not in use - more explicit than dpms off */
60517 void (*disable)(struct drm_crtc *crtc);
60518-};
60519+} __no_const;
60520
60521 /**
60522 * drm_encoder_helper_funcs - helper operations for encoders
60523@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
60524 struct drm_connector *connector);
60525 /* disable encoder when not in use - more explicit than dpms off */
60526 void (*disable)(struct drm_encoder *encoder);
60527-};
60528+} __no_const;
60529
60530 /**
60531 * drm_connector_helper_funcs - helper operations for connectors
60532diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
60533index d6d1da4..fdd1ac5 100644
60534--- a/include/drm/ttm/ttm_memory.h
60535+++ b/include/drm/ttm/ttm_memory.h
60536@@ -48,7 +48,7 @@
60537
60538 struct ttm_mem_shrink {
60539 int (*do_shrink) (struct ttm_mem_shrink *);
60540-};
60541+} __no_const;
60542
60543 /**
60544 * struct ttm_mem_global - Global memory accounting structure.
60545diff --git a/include/linux/a.out.h b/include/linux/a.out.h
60546index e86dfca..40cc55f 100644
60547--- a/include/linux/a.out.h
60548+++ b/include/linux/a.out.h
60549@@ -39,6 +39,14 @@ enum machine_type {
60550 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
60551 };
60552
60553+/* Constants for the N_FLAGS field */
60554+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60555+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
60556+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
60557+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
60558+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60559+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60560+
60561 #if !defined (N_MAGIC)
60562 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
60563 #endif
60564diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
60565index 06fd4bb..1caec0d 100644
60566--- a/include/linux/atmdev.h
60567+++ b/include/linux/atmdev.h
60568@@ -237,7 +237,7 @@ struct compat_atm_iobuf {
60569 #endif
60570
60571 struct k_atm_aal_stats {
60572-#define __HANDLE_ITEM(i) atomic_t i
60573+#define __HANDLE_ITEM(i) atomic_unchecked_t i
60574 __AAL_STAT_ITEMS
60575 #undef __HANDLE_ITEM
60576 };
60577diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
60578index 366422b..1fa7f84 100644
60579--- a/include/linux/binfmts.h
60580+++ b/include/linux/binfmts.h
60581@@ -89,6 +89,7 @@ struct linux_binfmt {
60582 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
60583 int (*load_shlib)(struct file *);
60584 int (*core_dump)(struct coredump_params *cprm);
60585+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
60586 unsigned long min_coredump; /* minimal dump size */
60587 };
60588
60589diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
60590index 07954b0..cb2ae71 100644
60591--- a/include/linux/blkdev.h
60592+++ b/include/linux/blkdev.h
60593@@ -1393,7 +1393,7 @@ struct block_device_operations {
60594 /* this callback is with swap_lock and sometimes page table lock held */
60595 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
60596 struct module *owner;
60597-};
60598+} __do_const;
60599
60600 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
60601 unsigned long);
60602diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
60603index 4d1a074..88f929a 100644
60604--- a/include/linux/blktrace_api.h
60605+++ b/include/linux/blktrace_api.h
60606@@ -162,7 +162,7 @@ struct blk_trace {
60607 struct dentry *dir;
60608 struct dentry *dropped_file;
60609 struct dentry *msg_file;
60610- atomic_t dropped;
60611+ atomic_unchecked_t dropped;
60612 };
60613
60614 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
60615diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
60616index 83195fb..0b0f77d 100644
60617--- a/include/linux/byteorder/little_endian.h
60618+++ b/include/linux/byteorder/little_endian.h
60619@@ -42,51 +42,51 @@
60620
60621 static inline __le64 __cpu_to_le64p(const __u64 *p)
60622 {
60623- return (__force __le64)*p;
60624+ return (__force const __le64)*p;
60625 }
60626 static inline __u64 __le64_to_cpup(const __le64 *p)
60627 {
60628- return (__force __u64)*p;
60629+ return (__force const __u64)*p;
60630 }
60631 static inline __le32 __cpu_to_le32p(const __u32 *p)
60632 {
60633- return (__force __le32)*p;
60634+ return (__force const __le32)*p;
60635 }
60636 static inline __u32 __le32_to_cpup(const __le32 *p)
60637 {
60638- return (__force __u32)*p;
60639+ return (__force const __u32)*p;
60640 }
60641 static inline __le16 __cpu_to_le16p(const __u16 *p)
60642 {
60643- return (__force __le16)*p;
60644+ return (__force const __le16)*p;
60645 }
60646 static inline __u16 __le16_to_cpup(const __le16 *p)
60647 {
60648- return (__force __u16)*p;
60649+ return (__force const __u16)*p;
60650 }
60651 static inline __be64 __cpu_to_be64p(const __u64 *p)
60652 {
60653- return (__force __be64)__swab64p(p);
60654+ return (__force const __be64)__swab64p(p);
60655 }
60656 static inline __u64 __be64_to_cpup(const __be64 *p)
60657 {
60658- return __swab64p((__u64 *)p);
60659+ return __swab64p((const __u64 *)p);
60660 }
60661 static inline __be32 __cpu_to_be32p(const __u32 *p)
60662 {
60663- return (__force __be32)__swab32p(p);
60664+ return (__force const __be32)__swab32p(p);
60665 }
60666 static inline __u32 __be32_to_cpup(const __be32 *p)
60667 {
60668- return __swab32p((__u32 *)p);
60669+ return __swab32p((const __u32 *)p);
60670 }
60671 static inline __be16 __cpu_to_be16p(const __u16 *p)
60672 {
60673- return (__force __be16)__swab16p(p);
60674+ return (__force const __be16)__swab16p(p);
60675 }
60676 static inline __u16 __be16_to_cpup(const __be16 *p)
60677 {
60678- return __swab16p((__u16 *)p);
60679+ return __swab16p((const __u16 *)p);
60680 }
60681 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
60682 #define __le64_to_cpus(x) do { (void)(x); } while (0)
60683diff --git a/include/linux/cache.h b/include/linux/cache.h
60684index 4c57065..4307975 100644
60685--- a/include/linux/cache.h
60686+++ b/include/linux/cache.h
60687@@ -16,6 +16,10 @@
60688 #define __read_mostly
60689 #endif
60690
60691+#ifndef __read_only
60692+#define __read_only __read_mostly
60693+#endif
60694+
60695 #ifndef ____cacheline_aligned
60696 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
60697 #endif
60698diff --git a/include/linux/capability.h b/include/linux/capability.h
60699index d10b7ed..0288b79 100644
60700--- a/include/linux/capability.h
60701+++ b/include/linux/capability.h
60702@@ -553,10 +553,15 @@ extern bool capable(int cap);
60703 extern bool ns_capable(struct user_namespace *ns, int cap);
60704 extern bool nsown_capable(int cap);
60705 extern bool inode_capable(const struct inode *inode, int cap);
60706+extern bool capable_nolog(int cap);
60707+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
60708+extern bool inode_capable_nolog(const struct inode *inode, int cap);
60709
60710 /* audit system wants to get cap info from files as well */
60711 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
60712
60713+extern int is_privileged_binary(const struct dentry *dentry);
60714+
60715 #endif /* __KERNEL__ */
60716
60717 #endif /* !_LINUX_CAPABILITY_H */
60718diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
60719index 42e55de..1cd0e66 100644
60720--- a/include/linux/cleancache.h
60721+++ b/include/linux/cleancache.h
60722@@ -31,7 +31,7 @@ struct cleancache_ops {
60723 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
60724 void (*invalidate_inode)(int, struct cleancache_filekey);
60725 void (*invalidate_fs)(int);
60726-};
60727+} __no_const;
60728
60729 extern struct cleancache_ops
60730 cleancache_register_ops(struct cleancache_ops *ops);
60731diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
60732index 4a0b483..f1f70ba 100644
60733--- a/include/linux/clk-provider.h
60734+++ b/include/linux/clk-provider.h
60735@@ -110,6 +110,7 @@ struct clk_ops {
60736 unsigned long);
60737 void (*init)(struct clk_hw *hw);
60738 };
60739+typedef struct clk_ops __no_const clk_ops_no_const;
60740
60741 /**
60742 * struct clk_init_data - holds init data that's common to all clocks and is
60743diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
60744index 2f40791..9c9e13c 100644
60745--- a/include/linux/compiler-gcc4.h
60746+++ b/include/linux/compiler-gcc4.h
60747@@ -32,6 +32,20 @@
60748 #define __linktime_error(message) __attribute__((__error__(message)))
60749
60750 #if __GNUC_MINOR__ >= 5
60751+
60752+#ifdef CONSTIFY_PLUGIN
60753+#define __no_const __attribute__((no_const))
60754+#define __do_const __attribute__((do_const))
60755+#endif
60756+
60757+#ifdef SIZE_OVERFLOW_PLUGIN
60758+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
60759+#endif
60760+
60761+#ifdef LATENT_ENTROPY_PLUGIN
60762+#define __latent_entropy __attribute__((latent_entropy))
60763+#endif
60764+
60765 /*
60766 * Mark a position in code as unreachable. This can be used to
60767 * suppress control flow warnings after asm blocks that transfer
60768@@ -47,6 +61,11 @@
60769 #define __noclone __attribute__((__noclone__))
60770
60771 #endif
60772+
60773+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
60774+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
60775+#define __bos0(ptr) __bos((ptr), 0)
60776+#define __bos1(ptr) __bos((ptr), 1)
60777 #endif
60778
60779 #if __GNUC_MINOR__ > 0
60780diff --git a/include/linux/compiler.h b/include/linux/compiler.h
60781index 923d093..1fef491 100644
60782--- a/include/linux/compiler.h
60783+++ b/include/linux/compiler.h
60784@@ -5,31 +5,62 @@
60785
60786 #ifdef __CHECKER__
60787 # define __user __attribute__((noderef, address_space(1)))
60788+# define __force_user __force __user
60789 # define __kernel __attribute__((address_space(0)))
60790+# define __force_kernel __force __kernel
60791 # define __safe __attribute__((safe))
60792 # define __force __attribute__((force))
60793 # define __nocast __attribute__((nocast))
60794 # define __iomem __attribute__((noderef, address_space(2)))
60795+# define __force_iomem __force __iomem
60796 # define __acquires(x) __attribute__((context(x,0,1)))
60797 # define __releases(x) __attribute__((context(x,1,0)))
60798 # define __acquire(x) __context__(x,1)
60799 # define __release(x) __context__(x,-1)
60800 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
60801 # define __percpu __attribute__((noderef, address_space(3)))
60802+# define __force_percpu __force __percpu
60803 #ifdef CONFIG_SPARSE_RCU_POINTER
60804 # define __rcu __attribute__((noderef, address_space(4)))
60805+# define __force_rcu __force __rcu
60806 #else
60807 # define __rcu
60808+# define __force_rcu
60809 #endif
60810 extern void __chk_user_ptr(const volatile void __user *);
60811 extern void __chk_io_ptr(const volatile void __iomem *);
60812+#elif defined(CHECKER_PLUGIN)
60813+//# define __user
60814+//# define __force_user
60815+//# define __kernel
60816+//# define __force_kernel
60817+# define __safe
60818+# define __force
60819+# define __nocast
60820+# define __iomem
60821+# define __force_iomem
60822+# define __chk_user_ptr(x) (void)0
60823+# define __chk_io_ptr(x) (void)0
60824+# define __builtin_warning(x, y...) (1)
60825+# define __acquires(x)
60826+# define __releases(x)
60827+# define __acquire(x) (void)0
60828+# define __release(x) (void)0
60829+# define __cond_lock(x,c) (c)
60830+# define __percpu
60831+# define __force_percpu
60832+# define __rcu
60833+# define __force_rcu
60834 #else
60835 # define __user
60836+# define __force_user
60837 # define __kernel
60838+# define __force_kernel
60839 # define __safe
60840 # define __force
60841 # define __nocast
60842 # define __iomem
60843+# define __force_iomem
60844 # define __chk_user_ptr(x) (void)0
60845 # define __chk_io_ptr(x) (void)0
60846 # define __builtin_warning(x, y...) (1)
60847@@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
60848 # define __release(x) (void)0
60849 # define __cond_lock(x,c) (c)
60850 # define __percpu
60851+# define __force_percpu
60852 # define __rcu
60853+# define __force_rcu
60854 #endif
60855
60856 #ifdef __KERNEL__
60857@@ -264,6 +297,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60858 # define __attribute_const__ /* unimplemented */
60859 #endif
60860
60861+#ifndef __no_const
60862+# define __no_const
60863+#endif
60864+
60865+#ifndef __do_const
60866+# define __do_const
60867+#endif
60868+
60869+#ifndef __size_overflow
60870+# define __size_overflow(...)
60871+#endif
60872+
60873+#ifndef __latent_entropy
60874+# define __latent_entropy
60875+#endif
60876+
60877 /*
60878 * Tell gcc if a function is cold. The compiler will assume any path
60879 * directly leading to the call is unlikely.
60880@@ -273,6 +322,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60881 #define __cold
60882 #endif
60883
60884+#ifndef __alloc_size
60885+#define __alloc_size(...)
60886+#endif
60887+
60888+#ifndef __bos
60889+#define __bos(ptr, arg)
60890+#endif
60891+
60892+#ifndef __bos0
60893+#define __bos0(ptr)
60894+#endif
60895+
60896+#ifndef __bos1
60897+#define __bos1(ptr)
60898+#endif
60899+
60900 /* Simple shorthand for a section definition */
60901 #ifndef __section
60902 # define __section(S) __attribute__ ((__section__(#S)))
60903@@ -308,6 +373,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60904 * use is to mediate communication between process-level code and irq/NMI
60905 * handlers, all running on the same CPU.
60906 */
60907-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
60908+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
60909+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
60910
60911 #endif /* __LINUX_COMPILER_H */
60912diff --git a/include/linux/cred.h b/include/linux/cred.h
60913index ebbed2c..908cc2c 100644
60914--- a/include/linux/cred.h
60915+++ b/include/linux/cred.h
60916@@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
60917 static inline void validate_process_creds(void)
60918 {
60919 }
60920+static inline void validate_task_creds(struct task_struct *task)
60921+{
60922+}
60923 #endif
60924
60925 /**
60926diff --git a/include/linux/crypto.h b/include/linux/crypto.h
60927index b92eadf..b4ecdc1 100644
60928--- a/include/linux/crypto.h
60929+++ b/include/linux/crypto.h
60930@@ -373,7 +373,7 @@ struct cipher_tfm {
60931 const u8 *key, unsigned int keylen);
60932 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60933 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60934-};
60935+} __no_const;
60936
60937 struct hash_tfm {
60938 int (*init)(struct hash_desc *desc);
60939@@ -394,13 +394,13 @@ struct compress_tfm {
60940 int (*cot_decompress)(struct crypto_tfm *tfm,
60941 const u8 *src, unsigned int slen,
60942 u8 *dst, unsigned int *dlen);
60943-};
60944+} __no_const;
60945
60946 struct rng_tfm {
60947 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
60948 unsigned int dlen);
60949 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
60950-};
60951+} __no_const;
60952
60953 #define crt_ablkcipher crt_u.ablkcipher
60954 #define crt_aead crt_u.aead
60955diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
60956index 7925bf0..d5143d2 100644
60957--- a/include/linux/decompress/mm.h
60958+++ b/include/linux/decompress/mm.h
60959@@ -77,7 +77,7 @@ static void free(void *where)
60960 * warnings when not needed (indeed large_malloc / large_free are not
60961 * needed by inflate */
60962
60963-#define malloc(a) kmalloc(a, GFP_KERNEL)
60964+#define malloc(a) kmalloc((a), GFP_KERNEL)
60965 #define free(a) kfree(a)
60966
60967 #define large_malloc(a) vmalloc(a)
60968diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
60969index dfc099e..e583e66 100644
60970--- a/include/linux/dma-mapping.h
60971+++ b/include/linux/dma-mapping.h
60972@@ -51,7 +51,7 @@ struct dma_map_ops {
60973 u64 (*get_required_mask)(struct device *dev);
60974 #endif
60975 int is_phys;
60976-};
60977+} __do_const;
60978
60979 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
60980
60981diff --git a/include/linux/efi.h b/include/linux/efi.h
60982index ec45ccd..9923c32 100644
60983--- a/include/linux/efi.h
60984+++ b/include/linux/efi.h
60985@@ -635,7 +635,7 @@ struct efivar_operations {
60986 efi_get_variable_t *get_variable;
60987 efi_get_next_variable_t *get_next_variable;
60988 efi_set_variable_t *set_variable;
60989-};
60990+} __no_const;
60991
60992 struct efivars {
60993 /*
60994diff --git a/include/linux/elf.h b/include/linux/elf.h
60995index 999b4f5..57753b4 100644
60996--- a/include/linux/elf.h
60997+++ b/include/linux/elf.h
60998@@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
60999 #define PT_GNU_EH_FRAME 0x6474e550
61000
61001 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
61002+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
61003+
61004+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
61005+
61006+/* Constants for the e_flags field */
61007+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61008+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
61009+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
61010+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
61011+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61012+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61013
61014 /*
61015 * Extended Numbering
61016@@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
61017 #define DT_DEBUG 21
61018 #define DT_TEXTREL 22
61019 #define DT_JMPREL 23
61020+#define DT_FLAGS 30
61021+ #define DF_TEXTREL 0x00000004
61022 #define DT_ENCODING 32
61023 #define OLD_DT_LOOS 0x60000000
61024 #define DT_LOOS 0x6000000d
61025@@ -243,6 +256,19 @@ typedef struct elf64_hdr {
61026 #define PF_W 0x2
61027 #define PF_X 0x1
61028
61029+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
61030+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
61031+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
61032+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
61033+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
61034+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
61035+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
61036+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
61037+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
61038+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
61039+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
61040+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
61041+
61042 typedef struct elf32_phdr{
61043 Elf32_Word p_type;
61044 Elf32_Off p_offset;
61045@@ -335,6 +361,8 @@ typedef struct elf64_shdr {
61046 #define EI_OSABI 7
61047 #define EI_PAD 8
61048
61049+#define EI_PAX 14
61050+
61051 #define ELFMAG0 0x7f /* EI_MAG */
61052 #define ELFMAG1 'E'
61053 #define ELFMAG2 'L'
61054@@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
61055 #define elf_note elf32_note
61056 #define elf_addr_t Elf32_Off
61057 #define Elf_Half Elf32_Half
61058+#define elf_dyn Elf32_Dyn
61059
61060 #else
61061
61062@@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
61063 #define elf_note elf64_note
61064 #define elf_addr_t Elf64_Off
61065 #define Elf_Half Elf64_Half
61066+#define elf_dyn Elf64_Dyn
61067
61068 #endif
61069
61070diff --git a/include/linux/filter.h b/include/linux/filter.h
61071index 82b0135..917914d 100644
61072--- a/include/linux/filter.h
61073+++ b/include/linux/filter.h
61074@@ -146,6 +146,7 @@ struct compat_sock_fprog {
61075
61076 struct sk_buff;
61077 struct sock;
61078+struct bpf_jit_work;
61079
61080 struct sk_filter
61081 {
61082@@ -153,6 +154,9 @@ struct sk_filter
61083 unsigned int len; /* Number of filter blocks */
61084 unsigned int (*bpf_func)(const struct sk_buff *skb,
61085 const struct sock_filter *filter);
61086+#ifdef CONFIG_BPF_JIT
61087+ struct bpf_jit_work *work;
61088+#endif
61089 struct rcu_head rcu;
61090 struct sock_filter insns[0];
61091 };
61092diff --git a/include/linux/firewire.h b/include/linux/firewire.h
61093index 7edcf10..714d5e8 100644
61094--- a/include/linux/firewire.h
61095+++ b/include/linux/firewire.h
61096@@ -430,7 +430,7 @@ struct fw_iso_context {
61097 union {
61098 fw_iso_callback_t sc;
61099 fw_iso_mc_callback_t mc;
61100- } callback;
61101+ } __no_const callback;
61102 void *callback_data;
61103 };
61104
61105diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
61106index 0e4e2ee..4ff4312 100644
61107--- a/include/linux/frontswap.h
61108+++ b/include/linux/frontswap.h
61109@@ -11,7 +11,7 @@ struct frontswap_ops {
61110 int (*load)(unsigned, pgoff_t, struct page *);
61111 void (*invalidate_page)(unsigned, pgoff_t);
61112 void (*invalidate_area)(unsigned);
61113-};
61114+} __no_const;
61115
61116 extern bool frontswap_enabled;
61117 extern struct frontswap_ops
61118diff --git a/include/linux/fs.h b/include/linux/fs.h
61119index 17fd887..8eebca0 100644
61120--- a/include/linux/fs.h
61121+++ b/include/linux/fs.h
61122@@ -1663,7 +1663,8 @@ struct file_operations {
61123 int (*setlease)(struct file *, long, struct file_lock **);
61124 long (*fallocate)(struct file *file, int mode, loff_t offset,
61125 loff_t len);
61126-};
61127+} __do_const;
61128+typedef struct file_operations __no_const file_operations_no_const;
61129
61130 struct inode_operations {
61131 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
61132diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
61133index 003dc0f..3c4ea97 100644
61134--- a/include/linux/fs_struct.h
61135+++ b/include/linux/fs_struct.h
61136@@ -6,7 +6,7 @@
61137 #include <linux/seqlock.h>
61138
61139 struct fs_struct {
61140- int users;
61141+ atomic_t users;
61142 spinlock_t lock;
61143 seqcount_t seq;
61144 int umask;
61145diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
61146index ce31408..b1ad003 100644
61147--- a/include/linux/fscache-cache.h
61148+++ b/include/linux/fscache-cache.h
61149@@ -102,7 +102,7 @@ struct fscache_operation {
61150 fscache_operation_release_t release;
61151 };
61152
61153-extern atomic_t fscache_op_debug_id;
61154+extern atomic_unchecked_t fscache_op_debug_id;
61155 extern void fscache_op_work_func(struct work_struct *work);
61156
61157 extern void fscache_enqueue_operation(struct fscache_operation *);
61158@@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
61159 {
61160 INIT_WORK(&op->work, fscache_op_work_func);
61161 atomic_set(&op->usage, 1);
61162- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
61163+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61164 op->processor = processor;
61165 op->release = release;
61166 INIT_LIST_HEAD(&op->pend_link);
61167diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
61168index a6dfe69..569586df 100644
61169--- a/include/linux/fsnotify.h
61170+++ b/include/linux/fsnotify.h
61171@@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
61172 */
61173 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
61174 {
61175- return kstrdup(name, GFP_KERNEL);
61176+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
61177 }
61178
61179 /*
61180diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
61181index 63d966d..cdcb717 100644
61182--- a/include/linux/fsnotify_backend.h
61183+++ b/include/linux/fsnotify_backend.h
61184@@ -105,6 +105,7 @@ struct fsnotify_ops {
61185 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
61186 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
61187 };
61188+typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
61189
61190 /*
61191 * A group is a "thing" that wants to receive notification about filesystem
61192diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
61193index 176a939..1462211 100644
61194--- a/include/linux/ftrace_event.h
61195+++ b/include/linux/ftrace_event.h
61196@@ -97,7 +97,7 @@ struct trace_event_functions {
61197 trace_print_func raw;
61198 trace_print_func hex;
61199 trace_print_func binary;
61200-};
61201+} __no_const;
61202
61203 struct trace_event {
61204 struct hlist_node node;
61205@@ -263,7 +263,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
61206 extern int trace_add_event_call(struct ftrace_event_call *call);
61207 extern void trace_remove_event_call(struct ftrace_event_call *call);
61208
61209-#define is_signed_type(type) (((type)(-1)) < 0)
61210+#define is_signed_type(type) (((type)(-1)) < (type)1)
61211
61212 int trace_set_clr_event(const char *system, const char *event, int set);
61213
61214diff --git a/include/linux/genhd.h b/include/linux/genhd.h
61215index 017a7fb..33a8507 100644
61216--- a/include/linux/genhd.h
61217+++ b/include/linux/genhd.h
61218@@ -185,7 +185,7 @@ struct gendisk {
61219 struct kobject *slave_dir;
61220
61221 struct timer_rand_state *random;
61222- atomic_t sync_io; /* RAID */
61223+ atomic_unchecked_t sync_io; /* RAID */
61224 struct disk_events *ev;
61225 #ifdef CONFIG_BLK_DEV_INTEGRITY
61226 struct blk_integrity *integrity;
61227diff --git a/include/linux/gfp.h b/include/linux/gfp.h
61228index 1e49be4..b8a9305 100644
61229--- a/include/linux/gfp.h
61230+++ b/include/linux/gfp.h
61231@@ -38,6 +38,12 @@ struct vm_area_struct;
61232 #define ___GFP_OTHER_NODE 0x800000u
61233 #define ___GFP_WRITE 0x1000000u
61234
61235+#ifdef CONFIG_PAX_USERCOPY_SLABS
61236+#define ___GFP_USERCOPY 0x2000000u
61237+#else
61238+#define ___GFP_USERCOPY 0
61239+#endif
61240+
61241 /*
61242 * GFP bitmasks..
61243 *
61244@@ -87,6 +93,7 @@ struct vm_area_struct;
61245 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
61246 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
61247 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
61248+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
61249
61250 /*
61251 * This may seem redundant, but it's a way of annotating false positives vs.
61252@@ -94,7 +101,7 @@ struct vm_area_struct;
61253 */
61254 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
61255
61256-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
61257+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
61258 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
61259
61260 /* This equals 0, but use constants in case they ever change */
61261@@ -148,6 +155,8 @@ struct vm_area_struct;
61262 /* 4GB DMA on some platforms */
61263 #define GFP_DMA32 __GFP_DMA32
61264
61265+#define GFP_USERCOPY __GFP_USERCOPY
61266+
61267 /* Convert GFP flags to their corresponding migrate type */
61268 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
61269 {
61270diff --git a/include/linux/gracl.h b/include/linux/gracl.h
61271new file mode 100644
61272index 0000000..c938b1f
61273--- /dev/null
61274+++ b/include/linux/gracl.h
61275@@ -0,0 +1,319 @@
61276+#ifndef GR_ACL_H
61277+#define GR_ACL_H
61278+
61279+#include <linux/grdefs.h>
61280+#include <linux/resource.h>
61281+#include <linux/capability.h>
61282+#include <linux/dcache.h>
61283+#include <asm/resource.h>
61284+
61285+/* Major status information */
61286+
61287+#define GR_VERSION "grsecurity 2.9.1"
61288+#define GRSECURITY_VERSION 0x2901
61289+
61290+enum {
61291+ GR_SHUTDOWN = 0,
61292+ GR_ENABLE = 1,
61293+ GR_SPROLE = 2,
61294+ GR_RELOAD = 3,
61295+ GR_SEGVMOD = 4,
61296+ GR_STATUS = 5,
61297+ GR_UNSPROLE = 6,
61298+ GR_PASSSET = 7,
61299+ GR_SPROLEPAM = 8,
61300+};
61301+
61302+/* Password setup definitions
61303+ * kernel/grhash.c */
61304+enum {
61305+ GR_PW_LEN = 128,
61306+ GR_SALT_LEN = 16,
61307+ GR_SHA_LEN = 32,
61308+};
61309+
61310+enum {
61311+ GR_SPROLE_LEN = 64,
61312+};
61313+
61314+enum {
61315+ GR_NO_GLOB = 0,
61316+ GR_REG_GLOB,
61317+ GR_CREATE_GLOB
61318+};
61319+
61320+#define GR_NLIMITS 32
61321+
61322+/* Begin Data Structures */
61323+
61324+struct sprole_pw {
61325+ unsigned char *rolename;
61326+ unsigned char salt[GR_SALT_LEN];
61327+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
61328+};
61329+
61330+struct name_entry {
61331+ __u32 key;
61332+ ino_t inode;
61333+ dev_t device;
61334+ char *name;
61335+ __u16 len;
61336+ __u8 deleted;
61337+ struct name_entry *prev;
61338+ struct name_entry *next;
61339+};
61340+
61341+struct inodev_entry {
61342+ struct name_entry *nentry;
61343+ struct inodev_entry *prev;
61344+ struct inodev_entry *next;
61345+};
61346+
61347+struct acl_role_db {
61348+ struct acl_role_label **r_hash;
61349+ __u32 r_size;
61350+};
61351+
61352+struct inodev_db {
61353+ struct inodev_entry **i_hash;
61354+ __u32 i_size;
61355+};
61356+
61357+struct name_db {
61358+ struct name_entry **n_hash;
61359+ __u32 n_size;
61360+};
61361+
61362+struct crash_uid {
61363+ uid_t uid;
61364+ unsigned long expires;
61365+};
61366+
61367+struct gr_hash_struct {
61368+ void **table;
61369+ void **nametable;
61370+ void *first;
61371+ __u32 table_size;
61372+ __u32 used_size;
61373+ int type;
61374+};
61375+
61376+/* Userspace Grsecurity ACL data structures */
61377+
61378+struct acl_subject_label {
61379+ char *filename;
61380+ ino_t inode;
61381+ dev_t device;
61382+ __u32 mode;
61383+ kernel_cap_t cap_mask;
61384+ kernel_cap_t cap_lower;
61385+ kernel_cap_t cap_invert_audit;
61386+
61387+ struct rlimit res[GR_NLIMITS];
61388+ __u32 resmask;
61389+
61390+ __u8 user_trans_type;
61391+ __u8 group_trans_type;
61392+ uid_t *user_transitions;
61393+ gid_t *group_transitions;
61394+ __u16 user_trans_num;
61395+ __u16 group_trans_num;
61396+
61397+ __u32 sock_families[2];
61398+ __u32 ip_proto[8];
61399+ __u32 ip_type;
61400+ struct acl_ip_label **ips;
61401+ __u32 ip_num;
61402+ __u32 inaddr_any_override;
61403+
61404+ __u32 crashes;
61405+ unsigned long expires;
61406+
61407+ struct acl_subject_label *parent_subject;
61408+ struct gr_hash_struct *hash;
61409+ struct acl_subject_label *prev;
61410+ struct acl_subject_label *next;
61411+
61412+ struct acl_object_label **obj_hash;
61413+ __u32 obj_hash_size;
61414+ __u16 pax_flags;
61415+};
61416+
61417+struct role_allowed_ip {
61418+ __u32 addr;
61419+ __u32 netmask;
61420+
61421+ struct role_allowed_ip *prev;
61422+ struct role_allowed_ip *next;
61423+};
61424+
61425+struct role_transition {
61426+ char *rolename;
61427+
61428+ struct role_transition *prev;
61429+ struct role_transition *next;
61430+};
61431+
61432+struct acl_role_label {
61433+ char *rolename;
61434+ uid_t uidgid;
61435+ __u16 roletype;
61436+
61437+ __u16 auth_attempts;
61438+ unsigned long expires;
61439+
61440+ struct acl_subject_label *root_label;
61441+ struct gr_hash_struct *hash;
61442+
61443+ struct acl_role_label *prev;
61444+ struct acl_role_label *next;
61445+
61446+ struct role_transition *transitions;
61447+ struct role_allowed_ip *allowed_ips;
61448+ uid_t *domain_children;
61449+ __u16 domain_child_num;
61450+
61451+ umode_t umask;
61452+
61453+ struct acl_subject_label **subj_hash;
61454+ __u32 subj_hash_size;
61455+};
61456+
61457+struct user_acl_role_db {
61458+ struct acl_role_label **r_table;
61459+ __u32 num_pointers; /* Number of allocations to track */
61460+ __u32 num_roles; /* Number of roles */
61461+ __u32 num_domain_children; /* Number of domain children */
61462+ __u32 num_subjects; /* Number of subjects */
61463+ __u32 num_objects; /* Number of objects */
61464+};
61465+
61466+struct acl_object_label {
61467+ char *filename;
61468+ ino_t inode;
61469+ dev_t device;
61470+ __u32 mode;
61471+
61472+ struct acl_subject_label *nested;
61473+ struct acl_object_label *globbed;
61474+
61475+ /* next two structures not used */
61476+
61477+ struct acl_object_label *prev;
61478+ struct acl_object_label *next;
61479+};
61480+
61481+struct acl_ip_label {
61482+ char *iface;
61483+ __u32 addr;
61484+ __u32 netmask;
61485+ __u16 low, high;
61486+ __u8 mode;
61487+ __u32 type;
61488+ __u32 proto[8];
61489+
61490+ /* next two structures not used */
61491+
61492+ struct acl_ip_label *prev;
61493+ struct acl_ip_label *next;
61494+};
61495+
61496+struct gr_arg {
61497+ struct user_acl_role_db role_db;
61498+ unsigned char pw[GR_PW_LEN];
61499+ unsigned char salt[GR_SALT_LEN];
61500+ unsigned char sum[GR_SHA_LEN];
61501+ unsigned char sp_role[GR_SPROLE_LEN];
61502+ struct sprole_pw *sprole_pws;
61503+ dev_t segv_device;
61504+ ino_t segv_inode;
61505+ uid_t segv_uid;
61506+ __u16 num_sprole_pws;
61507+ __u16 mode;
61508+};
61509+
61510+struct gr_arg_wrapper {
61511+ struct gr_arg *arg;
61512+ __u32 version;
61513+ __u32 size;
61514+};
61515+
61516+struct subject_map {
61517+ struct acl_subject_label *user;
61518+ struct acl_subject_label *kernel;
61519+ struct subject_map *prev;
61520+ struct subject_map *next;
61521+};
61522+
61523+struct acl_subj_map_db {
61524+ struct subject_map **s_hash;
61525+ __u32 s_size;
61526+};
61527+
61528+/* End Data Structures Section */
61529+
61530+/* Hash functions generated by empirical testing by Brad Spengler
61531+ Makes good use of the low bits of the inode. Generally 0-1 times
61532+ in loop for successful match. 0-3 for unsuccessful match.
61533+ Shift/add algorithm with modulus of table size and an XOR*/
61534+
61535+static __inline__ unsigned int
61536+rhash(const uid_t uid, const __u16 type, const unsigned int sz)
61537+{
61538+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
61539+}
61540+
61541+ static __inline__ unsigned int
61542+shash(const struct acl_subject_label *userp, const unsigned int sz)
61543+{
61544+ return ((const unsigned long)userp % sz);
61545+}
61546+
61547+static __inline__ unsigned int
61548+fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
61549+{
61550+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
61551+}
61552+
61553+static __inline__ unsigned int
61554+nhash(const char *name, const __u16 len, const unsigned int sz)
61555+{
61556+ return full_name_hash((const unsigned char *)name, len) % sz;
61557+}
61558+
61559+#define FOR_EACH_ROLE_START(role) \
61560+ role = role_list; \
61561+ while (role) {
61562+
61563+#define FOR_EACH_ROLE_END(role) \
61564+ role = role->prev; \
61565+ }
61566+
61567+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
61568+ subj = NULL; \
61569+ iter = 0; \
61570+ while (iter < role->subj_hash_size) { \
61571+ if (subj == NULL) \
61572+ subj = role->subj_hash[iter]; \
61573+ if (subj == NULL) { \
61574+ iter++; \
61575+ continue; \
61576+ }
61577+
61578+#define FOR_EACH_SUBJECT_END(subj,iter) \
61579+ subj = subj->next; \
61580+ if (subj == NULL) \
61581+ iter++; \
61582+ }
61583+
61584+
61585+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
61586+ subj = role->hash->first; \
61587+ while (subj != NULL) {
61588+
61589+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
61590+ subj = subj->next; \
61591+ }
61592+
61593+#endif
61594+
61595diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
61596new file mode 100644
61597index 0000000..323ecf2
61598--- /dev/null
61599+++ b/include/linux/gralloc.h
61600@@ -0,0 +1,9 @@
61601+#ifndef __GRALLOC_H
61602+#define __GRALLOC_H
61603+
61604+void acl_free_all(void);
61605+int acl_alloc_stack_init(unsigned long size);
61606+void *acl_alloc(unsigned long len);
61607+void *acl_alloc_num(unsigned long num, unsigned long len);
61608+
61609+#endif
61610diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
61611new file mode 100644
61612index 0000000..b30e9bc
61613--- /dev/null
61614+++ b/include/linux/grdefs.h
61615@@ -0,0 +1,140 @@
61616+#ifndef GRDEFS_H
61617+#define GRDEFS_H
61618+
61619+/* Begin grsecurity status declarations */
61620+
61621+enum {
61622+ GR_READY = 0x01,
61623+ GR_STATUS_INIT = 0x00 // disabled state
61624+};
61625+
61626+/* Begin ACL declarations */
61627+
61628+/* Role flags */
61629+
61630+enum {
61631+ GR_ROLE_USER = 0x0001,
61632+ GR_ROLE_GROUP = 0x0002,
61633+ GR_ROLE_DEFAULT = 0x0004,
61634+ GR_ROLE_SPECIAL = 0x0008,
61635+ GR_ROLE_AUTH = 0x0010,
61636+ GR_ROLE_NOPW = 0x0020,
61637+ GR_ROLE_GOD = 0x0040,
61638+ GR_ROLE_LEARN = 0x0080,
61639+ GR_ROLE_TPE = 0x0100,
61640+ GR_ROLE_DOMAIN = 0x0200,
61641+ GR_ROLE_PAM = 0x0400,
61642+ GR_ROLE_PERSIST = 0x0800
61643+};
61644+
61645+/* ACL Subject and Object mode flags */
61646+enum {
61647+ GR_DELETED = 0x80000000
61648+};
61649+
61650+/* ACL Object-only mode flags */
61651+enum {
61652+ GR_READ = 0x00000001,
61653+ GR_APPEND = 0x00000002,
61654+ GR_WRITE = 0x00000004,
61655+ GR_EXEC = 0x00000008,
61656+ GR_FIND = 0x00000010,
61657+ GR_INHERIT = 0x00000020,
61658+ GR_SETID = 0x00000040,
61659+ GR_CREATE = 0x00000080,
61660+ GR_DELETE = 0x00000100,
61661+ GR_LINK = 0x00000200,
61662+ GR_AUDIT_READ = 0x00000400,
61663+ GR_AUDIT_APPEND = 0x00000800,
61664+ GR_AUDIT_WRITE = 0x00001000,
61665+ GR_AUDIT_EXEC = 0x00002000,
61666+ GR_AUDIT_FIND = 0x00004000,
61667+ GR_AUDIT_INHERIT= 0x00008000,
61668+ GR_AUDIT_SETID = 0x00010000,
61669+ GR_AUDIT_CREATE = 0x00020000,
61670+ GR_AUDIT_DELETE = 0x00040000,
61671+ GR_AUDIT_LINK = 0x00080000,
61672+ GR_PTRACERD = 0x00100000,
61673+ GR_NOPTRACE = 0x00200000,
61674+ GR_SUPPRESS = 0x00400000,
61675+ GR_NOLEARN = 0x00800000,
61676+ GR_INIT_TRANSFER= 0x01000000
61677+};
61678+
61679+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
61680+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
61681+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
61682+
61683+/* ACL subject-only mode flags */
61684+enum {
61685+ GR_KILL = 0x00000001,
61686+ GR_VIEW = 0x00000002,
61687+ GR_PROTECTED = 0x00000004,
61688+ GR_LEARN = 0x00000008,
61689+ GR_OVERRIDE = 0x00000010,
61690+ /* just a placeholder, this mode is only used in userspace */
61691+ GR_DUMMY = 0x00000020,
61692+ GR_PROTSHM = 0x00000040,
61693+ GR_KILLPROC = 0x00000080,
61694+ GR_KILLIPPROC = 0x00000100,
61695+ /* just a placeholder, this mode is only used in userspace */
61696+ GR_NOTROJAN = 0x00000200,
61697+ GR_PROTPROCFD = 0x00000400,
61698+ GR_PROCACCT = 0x00000800,
61699+ GR_RELAXPTRACE = 0x00001000,
61700+ GR_NESTED = 0x00002000,
61701+ GR_INHERITLEARN = 0x00004000,
61702+ GR_PROCFIND = 0x00008000,
61703+ GR_POVERRIDE = 0x00010000,
61704+ GR_KERNELAUTH = 0x00020000,
61705+ GR_ATSECURE = 0x00040000,
61706+ GR_SHMEXEC = 0x00080000
61707+};
61708+
61709+enum {
61710+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
61711+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
61712+ GR_PAX_ENABLE_MPROTECT = 0x0004,
61713+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
61714+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
61715+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
61716+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
61717+ GR_PAX_DISABLE_MPROTECT = 0x0400,
61718+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
61719+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
61720+};
61721+
61722+enum {
61723+ GR_ID_USER = 0x01,
61724+ GR_ID_GROUP = 0x02,
61725+};
61726+
61727+enum {
61728+ GR_ID_ALLOW = 0x01,
61729+ GR_ID_DENY = 0x02,
61730+};
61731+
61732+#define GR_CRASH_RES 31
61733+#define GR_UIDTABLE_MAX 500
61734+
61735+/* begin resource learning section */
61736+enum {
61737+ GR_RLIM_CPU_BUMP = 60,
61738+ GR_RLIM_FSIZE_BUMP = 50000,
61739+ GR_RLIM_DATA_BUMP = 10000,
61740+ GR_RLIM_STACK_BUMP = 1000,
61741+ GR_RLIM_CORE_BUMP = 10000,
61742+ GR_RLIM_RSS_BUMP = 500000,
61743+ GR_RLIM_NPROC_BUMP = 1,
61744+ GR_RLIM_NOFILE_BUMP = 5,
61745+ GR_RLIM_MEMLOCK_BUMP = 50000,
61746+ GR_RLIM_AS_BUMP = 500000,
61747+ GR_RLIM_LOCKS_BUMP = 2,
61748+ GR_RLIM_SIGPENDING_BUMP = 5,
61749+ GR_RLIM_MSGQUEUE_BUMP = 10000,
61750+ GR_RLIM_NICE_BUMP = 1,
61751+ GR_RLIM_RTPRIO_BUMP = 1,
61752+ GR_RLIM_RTTIME_BUMP = 1000000
61753+};
61754+
61755+#endif
61756diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
61757new file mode 100644
61758index 0000000..c9292f7
61759--- /dev/null
61760+++ b/include/linux/grinternal.h
61761@@ -0,0 +1,223 @@
61762+#ifndef __GRINTERNAL_H
61763+#define __GRINTERNAL_H
61764+
61765+#ifdef CONFIG_GRKERNSEC
61766+
61767+#include <linux/fs.h>
61768+#include <linux/mnt_namespace.h>
61769+#include <linux/nsproxy.h>
61770+#include <linux/gracl.h>
61771+#include <linux/grdefs.h>
61772+#include <linux/grmsg.h>
61773+
61774+void gr_add_learn_entry(const char *fmt, ...)
61775+ __attribute__ ((format (printf, 1, 2)));
61776+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
61777+ const struct vfsmount *mnt);
61778+__u32 gr_check_create(const struct dentry *new_dentry,
61779+ const struct dentry *parent,
61780+ const struct vfsmount *mnt, const __u32 mode);
61781+int gr_check_protected_task(const struct task_struct *task);
61782+__u32 to_gr_audit(const __u32 reqmode);
61783+int gr_set_acls(const int type);
61784+int gr_apply_subject_to_task(struct task_struct *task);
61785+int gr_acl_is_enabled(void);
61786+char gr_roletype_to_char(void);
61787+
61788+void gr_handle_alertkill(struct task_struct *task);
61789+char *gr_to_filename(const struct dentry *dentry,
61790+ const struct vfsmount *mnt);
61791+char *gr_to_filename1(const struct dentry *dentry,
61792+ const struct vfsmount *mnt);
61793+char *gr_to_filename2(const struct dentry *dentry,
61794+ const struct vfsmount *mnt);
61795+char *gr_to_filename3(const struct dentry *dentry,
61796+ const struct vfsmount *mnt);
61797+
61798+extern int grsec_enable_ptrace_readexec;
61799+extern int grsec_enable_harden_ptrace;
61800+extern int grsec_enable_link;
61801+extern int grsec_enable_fifo;
61802+extern int grsec_enable_execve;
61803+extern int grsec_enable_shm;
61804+extern int grsec_enable_execlog;
61805+extern int grsec_enable_signal;
61806+extern int grsec_enable_audit_ptrace;
61807+extern int grsec_enable_forkfail;
61808+extern int grsec_enable_time;
61809+extern int grsec_enable_rofs;
61810+extern int grsec_enable_chroot_shmat;
61811+extern int grsec_enable_chroot_mount;
61812+extern int grsec_enable_chroot_double;
61813+extern int grsec_enable_chroot_pivot;
61814+extern int grsec_enable_chroot_chdir;
61815+extern int grsec_enable_chroot_chmod;
61816+extern int grsec_enable_chroot_mknod;
61817+extern int grsec_enable_chroot_fchdir;
61818+extern int grsec_enable_chroot_nice;
61819+extern int grsec_enable_chroot_execlog;
61820+extern int grsec_enable_chroot_caps;
61821+extern int grsec_enable_chroot_sysctl;
61822+extern int grsec_enable_chroot_unix;
61823+extern int grsec_enable_symlinkown;
61824+extern int grsec_symlinkown_gid;
61825+extern int grsec_enable_tpe;
61826+extern int grsec_tpe_gid;
61827+extern int grsec_enable_tpe_all;
61828+extern int grsec_enable_tpe_invert;
61829+extern int grsec_enable_socket_all;
61830+extern int grsec_socket_all_gid;
61831+extern int grsec_enable_socket_client;
61832+extern int grsec_socket_client_gid;
61833+extern int grsec_enable_socket_server;
61834+extern int grsec_socket_server_gid;
61835+extern int grsec_audit_gid;
61836+extern int grsec_enable_group;
61837+extern int grsec_enable_audit_textrel;
61838+extern int grsec_enable_log_rwxmaps;
61839+extern int grsec_enable_mount;
61840+extern int grsec_enable_chdir;
61841+extern int grsec_resource_logging;
61842+extern int grsec_enable_blackhole;
61843+extern int grsec_lastack_retries;
61844+extern int grsec_enable_brute;
61845+extern int grsec_lock;
61846+
61847+extern spinlock_t grsec_alert_lock;
61848+extern unsigned long grsec_alert_wtime;
61849+extern unsigned long grsec_alert_fyet;
61850+
61851+extern spinlock_t grsec_audit_lock;
61852+
61853+extern rwlock_t grsec_exec_file_lock;
61854+
61855+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
61856+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
61857+ (tsk)->exec_file->f_vfsmnt) : "/")
61858+
61859+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
61860+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
61861+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61862+
61863+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
61864+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
61865+ (tsk)->exec_file->f_vfsmnt) : "/")
61866+
61867+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
61868+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
61869+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61870+
61871+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
61872+
61873+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
61874+
61875+#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
61876+ (task)->pid, (cred)->uid, \
61877+ (cred)->euid, (cred)->gid, (cred)->egid, \
61878+ gr_parent_task_fullpath(task), \
61879+ (task)->real_parent->comm, (task)->real_parent->pid, \
61880+ (pcred)->uid, (pcred)->euid, \
61881+ (pcred)->gid, (pcred)->egid
61882+
61883+#define GR_CHROOT_CAPS {{ \
61884+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
61885+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
61886+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
61887+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
61888+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
61889+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
61890+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
61891+
61892+#define security_learn(normal_msg,args...) \
61893+({ \
61894+ read_lock(&grsec_exec_file_lock); \
61895+ gr_add_learn_entry(normal_msg "\n", ## args); \
61896+ read_unlock(&grsec_exec_file_lock); \
61897+})
61898+
61899+enum {
61900+ GR_DO_AUDIT,
61901+ GR_DONT_AUDIT,
61902+ /* used for non-audit messages that we shouldn't kill the task on */
61903+ GR_DONT_AUDIT_GOOD
61904+};
61905+
61906+enum {
61907+ GR_TTYSNIFF,
61908+ GR_RBAC,
61909+ GR_RBAC_STR,
61910+ GR_STR_RBAC,
61911+ GR_RBAC_MODE2,
61912+ GR_RBAC_MODE3,
61913+ GR_FILENAME,
61914+ GR_SYSCTL_HIDDEN,
61915+ GR_NOARGS,
61916+ GR_ONE_INT,
61917+ GR_ONE_INT_TWO_STR,
61918+ GR_ONE_STR,
61919+ GR_STR_INT,
61920+ GR_TWO_STR_INT,
61921+ GR_TWO_INT,
61922+ GR_TWO_U64,
61923+ GR_THREE_INT,
61924+ GR_FIVE_INT_TWO_STR,
61925+ GR_TWO_STR,
61926+ GR_THREE_STR,
61927+ GR_FOUR_STR,
61928+ GR_STR_FILENAME,
61929+ GR_FILENAME_STR,
61930+ GR_FILENAME_TWO_INT,
61931+ GR_FILENAME_TWO_INT_STR,
61932+ GR_TEXTREL,
61933+ GR_PTRACE,
61934+ GR_RESOURCE,
61935+ GR_CAP,
61936+ GR_SIG,
61937+ GR_SIG2,
61938+ GR_CRASH1,
61939+ GR_CRASH2,
61940+ GR_PSACCT,
61941+ GR_RWXMAP
61942+};
61943+
61944+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
61945+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
61946+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
61947+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
61948+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
61949+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
61950+#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)
61951+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
61952+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
61953+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
61954+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
61955+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
61956+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
61957+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
61958+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
61959+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
61960+#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)
61961+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
61962+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
61963+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
61964+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
61965+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
61966+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
61967+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
61968+#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)
61969+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
61970+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
61971+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
61972+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
61973+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
61974+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
61975+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
61976+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
61977+#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)
61978+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
61979+
61980+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
61981+
61982+#endif
61983+
61984+#endif
61985diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
61986new file mode 100644
61987index 0000000..54f4e85
61988--- /dev/null
61989+++ b/include/linux/grmsg.h
61990@@ -0,0 +1,110 @@
61991+#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"
61992+#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"
61993+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
61994+#define GR_STOPMOD_MSG "denied modification of module state by "
61995+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
61996+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
61997+#define GR_IOPERM_MSG "denied use of ioperm() by "
61998+#define GR_IOPL_MSG "denied use of iopl() by "
61999+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
62000+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
62001+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
62002+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
62003+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
62004+#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"
62005+#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"
62006+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
62007+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
62008+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
62009+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
62010+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
62011+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
62012+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
62013+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
62014+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
62015+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
62016+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
62017+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
62018+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
62019+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
62020+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
62021+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
62022+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
62023+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
62024+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
62025+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
62026+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
62027+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
62028+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
62029+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
62030+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
62031+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
62032+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
62033+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
62034+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
62035+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
62036+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
62037+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
62038+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
62039+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
62040+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
62041+#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"
62042+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
62043+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
62044+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
62045+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
62046+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
62047+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
62048+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
62049+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
62050+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
62051+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
62052+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
62053+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
62054+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
62055+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
62056+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
62057+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
62058+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
62059+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
62060+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
62061+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
62062+#define GR_FAILFORK_MSG "failed fork with errno %s by "
62063+#define GR_NICE_CHROOT_MSG "denied priority change by "
62064+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
62065+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
62066+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
62067+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
62068+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
62069+#define GR_TIME_MSG "time set by "
62070+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
62071+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
62072+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
62073+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
62074+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
62075+#define GR_BIND_MSG "denied bind() by "
62076+#define GR_CONNECT_MSG "denied connect() by "
62077+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
62078+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
62079+#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"
62080+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
62081+#define GR_CAP_ACL_MSG "use of %s denied for "
62082+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
62083+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
62084+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
62085+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
62086+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
62087+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
62088+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
62089+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
62090+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
62091+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
62092+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
62093+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
62094+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
62095+#define GR_VM86_MSG "denied use of vm86 by "
62096+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
62097+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
62098+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
62099+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
62100+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
62101diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
62102new file mode 100644
62103index 0000000..38bfb04
62104--- /dev/null
62105+++ b/include/linux/grsecurity.h
62106@@ -0,0 +1,233 @@
62107+#ifndef GR_SECURITY_H
62108+#define GR_SECURITY_H
62109+#include <linux/fs.h>
62110+#include <linux/fs_struct.h>
62111+#include <linux/binfmts.h>
62112+#include <linux/gracl.h>
62113+
62114+/* notify of brain-dead configs */
62115+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62116+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
62117+#endif
62118+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
62119+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
62120+#endif
62121+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
62122+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
62123+#endif
62124+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
62125+#error "CONFIG_PAX enabled, but no PaX options are enabled."
62126+#endif
62127+
62128+#include <linux/compat.h>
62129+
62130+struct user_arg_ptr {
62131+#ifdef CONFIG_COMPAT
62132+ bool is_compat;
62133+#endif
62134+ union {
62135+ const char __user *const __user *native;
62136+#ifdef CONFIG_COMPAT
62137+ compat_uptr_t __user *compat;
62138+#endif
62139+ } ptr;
62140+};
62141+
62142+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
62143+void gr_handle_brute_check(void);
62144+void gr_handle_kernel_exploit(void);
62145+int gr_process_user_ban(void);
62146+
62147+char gr_roletype_to_char(void);
62148+
62149+int gr_acl_enable_at_secure(void);
62150+
62151+int gr_check_user_change(int real, int effective, int fs);
62152+int gr_check_group_change(int real, int effective, int fs);
62153+
62154+void gr_del_task_from_ip_table(struct task_struct *p);
62155+
62156+int gr_pid_is_chrooted(struct task_struct *p);
62157+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
62158+int gr_handle_chroot_nice(void);
62159+int gr_handle_chroot_sysctl(const int op);
62160+int gr_handle_chroot_setpriority(struct task_struct *p,
62161+ const int niceval);
62162+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
62163+int gr_handle_chroot_chroot(const struct dentry *dentry,
62164+ const struct vfsmount *mnt);
62165+void gr_handle_chroot_chdir(struct path *path);
62166+int gr_handle_chroot_chmod(const struct dentry *dentry,
62167+ const struct vfsmount *mnt, const int mode);
62168+int gr_handle_chroot_mknod(const struct dentry *dentry,
62169+ const struct vfsmount *mnt, const int mode);
62170+int gr_handle_chroot_mount(const struct dentry *dentry,
62171+ const struct vfsmount *mnt,
62172+ const char *dev_name);
62173+int gr_handle_chroot_pivot(void);
62174+int gr_handle_chroot_unix(const pid_t pid);
62175+
62176+int gr_handle_rawio(const struct inode *inode);
62177+
62178+void gr_handle_ioperm(void);
62179+void gr_handle_iopl(void);
62180+
62181+umode_t gr_acl_umask(void);
62182+
62183+int gr_tpe_allow(const struct file *file);
62184+
62185+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
62186+void gr_clear_chroot_entries(struct task_struct *task);
62187+
62188+void gr_log_forkfail(const int retval);
62189+void gr_log_timechange(void);
62190+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
62191+void gr_log_chdir(const struct dentry *dentry,
62192+ const struct vfsmount *mnt);
62193+void gr_log_chroot_exec(const struct dentry *dentry,
62194+ const struct vfsmount *mnt);
62195+void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
62196+void gr_log_remount(const char *devname, const int retval);
62197+void gr_log_unmount(const char *devname, const int retval);
62198+void gr_log_mount(const char *from, const char *to, const int retval);
62199+void gr_log_textrel(struct vm_area_struct *vma);
62200+void gr_log_rwxmmap(struct file *file);
62201+void gr_log_rwxmprotect(struct file *file);
62202+
62203+int gr_handle_follow_link(const struct inode *parent,
62204+ const struct inode *inode,
62205+ const struct dentry *dentry,
62206+ const struct vfsmount *mnt);
62207+int gr_handle_fifo(const struct dentry *dentry,
62208+ const struct vfsmount *mnt,
62209+ const struct dentry *dir, const int flag,
62210+ const int acc_mode);
62211+int gr_handle_hardlink(const struct dentry *dentry,
62212+ const struct vfsmount *mnt,
62213+ struct inode *inode,
62214+ const int mode, const char *to);
62215+
62216+int gr_is_capable(const int cap);
62217+int gr_is_capable_nolog(const int cap);
62218+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
62219+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
62220+
62221+void gr_learn_resource(const struct task_struct *task, const int limit,
62222+ const unsigned long wanted, const int gt);
62223+void gr_copy_label(struct task_struct *tsk);
62224+void gr_handle_crash(struct task_struct *task, const int sig);
62225+int gr_handle_signal(const struct task_struct *p, const int sig);
62226+int gr_check_crash_uid(const uid_t uid);
62227+int gr_check_protected_task(const struct task_struct *task);
62228+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
62229+int gr_acl_handle_mmap(const struct file *file,
62230+ const unsigned long prot);
62231+int gr_acl_handle_mprotect(const struct file *file,
62232+ const unsigned long prot);
62233+int gr_check_hidden_task(const struct task_struct *tsk);
62234+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
62235+ const struct vfsmount *mnt);
62236+__u32 gr_acl_handle_utime(const struct dentry *dentry,
62237+ const struct vfsmount *mnt);
62238+__u32 gr_acl_handle_access(const struct dentry *dentry,
62239+ const struct vfsmount *mnt, const int fmode);
62240+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
62241+ const struct vfsmount *mnt, umode_t *mode);
62242+__u32 gr_acl_handle_chown(const struct dentry *dentry,
62243+ const struct vfsmount *mnt);
62244+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
62245+ const struct vfsmount *mnt);
62246+int gr_handle_ptrace(struct task_struct *task, const long request);
62247+int gr_handle_proc_ptrace(struct task_struct *task);
62248+__u32 gr_acl_handle_execve(const struct dentry *dentry,
62249+ const struct vfsmount *mnt);
62250+int gr_check_crash_exec(const struct file *filp);
62251+int gr_acl_is_enabled(void);
62252+void gr_set_kernel_label(struct task_struct *task);
62253+void gr_set_role_label(struct task_struct *task, const uid_t uid,
62254+ const gid_t gid);
62255+int gr_set_proc_label(const struct dentry *dentry,
62256+ const struct vfsmount *mnt,
62257+ const int unsafe_flags);
62258+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
62259+ const struct vfsmount *mnt);
62260+__u32 gr_acl_handle_open(const struct dentry *dentry,
62261+ const struct vfsmount *mnt, int acc_mode);
62262+__u32 gr_acl_handle_creat(const struct dentry *dentry,
62263+ const struct dentry *p_dentry,
62264+ const struct vfsmount *p_mnt,
62265+ int open_flags, int acc_mode, const int imode);
62266+void gr_handle_create(const struct dentry *dentry,
62267+ const struct vfsmount *mnt);
62268+void gr_handle_proc_create(const struct dentry *dentry,
62269+ const struct inode *inode);
62270+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
62271+ const struct dentry *parent_dentry,
62272+ const struct vfsmount *parent_mnt,
62273+ const int mode);
62274+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
62275+ const struct dentry *parent_dentry,
62276+ const struct vfsmount *parent_mnt);
62277+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
62278+ const struct vfsmount *mnt);
62279+void gr_handle_delete(const ino_t ino, const dev_t dev);
62280+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
62281+ const struct vfsmount *mnt);
62282+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
62283+ const struct dentry *parent_dentry,
62284+ const struct vfsmount *parent_mnt,
62285+ const char *from);
62286+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
62287+ const struct dentry *parent_dentry,
62288+ const struct vfsmount *parent_mnt,
62289+ const struct dentry *old_dentry,
62290+ const struct vfsmount *old_mnt, const char *to);
62291+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
62292+int gr_acl_handle_rename(struct dentry *new_dentry,
62293+ struct dentry *parent_dentry,
62294+ const struct vfsmount *parent_mnt,
62295+ struct dentry *old_dentry,
62296+ struct inode *old_parent_inode,
62297+ struct vfsmount *old_mnt, const char *newname);
62298+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
62299+ struct dentry *old_dentry,
62300+ struct dentry *new_dentry,
62301+ struct vfsmount *mnt, const __u8 replace);
62302+__u32 gr_check_link(const struct dentry *new_dentry,
62303+ const struct dentry *parent_dentry,
62304+ const struct vfsmount *parent_mnt,
62305+ const struct dentry *old_dentry,
62306+ const struct vfsmount *old_mnt);
62307+int gr_acl_handle_filldir(const struct file *file, const char *name,
62308+ const unsigned int namelen, const ino_t ino);
62309+
62310+__u32 gr_acl_handle_unix(const struct dentry *dentry,
62311+ const struct vfsmount *mnt);
62312+void gr_acl_handle_exit(void);
62313+void gr_acl_handle_psacct(struct task_struct *task, const long code);
62314+int gr_acl_handle_procpidmem(const struct task_struct *task);
62315+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
62316+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
62317+void gr_audit_ptrace(struct task_struct *task);
62318+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
62319+
62320+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
62321+
62322+#ifdef CONFIG_GRKERNSEC
62323+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
62324+void gr_handle_vm86(void);
62325+void gr_handle_mem_readwrite(u64 from, u64 to);
62326+
62327+void gr_log_badprocpid(const char *entry);
62328+
62329+extern int grsec_enable_dmesg;
62330+extern int grsec_disable_privio;
62331+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62332+extern int grsec_enable_chroot_findtask;
62333+#endif
62334+#ifdef CONFIG_GRKERNSEC_SETXID
62335+extern int grsec_enable_setxid;
62336+#endif
62337+#endif
62338+
62339+#endif
62340diff --git a/include/linux/grsock.h b/include/linux/grsock.h
62341new file mode 100644
62342index 0000000..e7ffaaf
62343--- /dev/null
62344+++ b/include/linux/grsock.h
62345@@ -0,0 +1,19 @@
62346+#ifndef __GRSOCK_H
62347+#define __GRSOCK_H
62348+
62349+extern void gr_attach_curr_ip(const struct sock *sk);
62350+extern int gr_handle_sock_all(const int family, const int type,
62351+ const int protocol);
62352+extern int gr_handle_sock_server(const struct sockaddr *sck);
62353+extern int gr_handle_sock_server_other(const struct sock *sck);
62354+extern int gr_handle_sock_client(const struct sockaddr *sck);
62355+extern int gr_search_connect(struct socket * sock,
62356+ struct sockaddr_in * addr);
62357+extern int gr_search_bind(struct socket * sock,
62358+ struct sockaddr_in * addr);
62359+extern int gr_search_listen(struct socket * sock);
62360+extern int gr_search_accept(struct socket * sock);
62361+extern int gr_search_socket(const int domain, const int type,
62362+ const int protocol);
62363+
62364+#endif
62365diff --git a/include/linux/hid.h b/include/linux/hid.h
62366index 449fa38..b37c8cc 100644
62367--- a/include/linux/hid.h
62368+++ b/include/linux/hid.h
62369@@ -704,7 +704,7 @@ struct hid_ll_driver {
62370 unsigned int code, int value);
62371
62372 int (*parse)(struct hid_device *hdev);
62373-};
62374+} __no_const;
62375
62376 #define PM_HINT_FULLON 1<<5
62377 #define PM_HINT_NORMAL 1<<1
62378diff --git a/include/linux/highmem.h b/include/linux/highmem.h
62379index d3999b4..1304cb4 100644
62380--- a/include/linux/highmem.h
62381+++ b/include/linux/highmem.h
62382@@ -221,6 +221,18 @@ static inline void clear_highpage(struct page *page)
62383 kunmap_atomic(kaddr);
62384 }
62385
62386+static inline void sanitize_highpage(struct page *page)
62387+{
62388+ void *kaddr;
62389+ unsigned long flags;
62390+
62391+ local_irq_save(flags);
62392+ kaddr = kmap_atomic(page);
62393+ clear_page(kaddr);
62394+ kunmap_atomic(kaddr);
62395+ local_irq_restore(flags);
62396+}
62397+
62398 static inline void zero_user_segments(struct page *page,
62399 unsigned start1, unsigned end1,
62400 unsigned start2, unsigned end2)
62401diff --git a/include/linux/i2c.h b/include/linux/i2c.h
62402index ddfa041..a44cfff 100644
62403--- a/include/linux/i2c.h
62404+++ b/include/linux/i2c.h
62405@@ -366,6 +366,7 @@ struct i2c_algorithm {
62406 /* To determine what the adapter supports */
62407 u32 (*functionality) (struct i2c_adapter *);
62408 };
62409+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
62410
62411 /*
62412 * i2c_adapter is the structure used to identify a physical i2c bus along
62413diff --git a/include/linux/i2o.h b/include/linux/i2o.h
62414index d23c3c2..eb63c81 100644
62415--- a/include/linux/i2o.h
62416+++ b/include/linux/i2o.h
62417@@ -565,7 +565,7 @@ struct i2o_controller {
62418 struct i2o_device *exec; /* Executive */
62419 #if BITS_PER_LONG == 64
62420 spinlock_t context_list_lock; /* lock for context_list */
62421- atomic_t context_list_counter; /* needed for unique contexts */
62422+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
62423 struct list_head context_list; /* list of context id's
62424 and pointers */
62425 #endif
62426diff --git a/include/linux/if_team.h b/include/linux/if_team.h
62427index 8185f57..7b2d222 100644
62428--- a/include/linux/if_team.h
62429+++ b/include/linux/if_team.h
62430@@ -74,6 +74,7 @@ struct team_mode_ops {
62431 void (*port_leave)(struct team *team, struct team_port *port);
62432 void (*port_change_mac)(struct team *team, struct team_port *port);
62433 };
62434+typedef struct team_mode_ops __no_const team_mode_ops_no_const;
62435
62436 enum team_option_type {
62437 TEAM_OPTION_TYPE_U32,
62438@@ -136,7 +137,7 @@ struct team {
62439 struct list_head option_inst_list; /* list of option instances */
62440
62441 const struct team_mode *mode;
62442- struct team_mode_ops ops;
62443+ team_mode_ops_no_const ops;
62444 long mode_priv[TEAM_MODE_PRIV_LONGS];
62445 };
62446
62447diff --git a/include/linux/init.h b/include/linux/init.h
62448index 6b95109..7616d09 100644
62449--- a/include/linux/init.h
62450+++ b/include/linux/init.h
62451@@ -39,9 +39,15 @@
62452 * Also note, that this data cannot be "const".
62453 */
62454
62455+#ifdef MODULE
62456+#define add_latent_entropy
62457+#else
62458+#define add_latent_entropy __latent_entropy
62459+#endif
62460+
62461 /* These are for everybody (although not all archs will actually
62462 discard it in modules) */
62463-#define __init __section(.init.text) __cold notrace
62464+#define __init __section(.init.text) __cold notrace add_latent_entropy
62465 #define __initdata __section(.init.data)
62466 #define __initconst __section(.init.rodata)
62467 #define __exitdata __section(.exit.data)
62468@@ -83,7 +89,7 @@
62469 #define __exit __section(.exit.text) __exitused __cold notrace
62470
62471 /* Used for HOTPLUG */
62472-#define __devinit __section(.devinit.text) __cold notrace
62473+#define __devinit __section(.devinit.text) __cold notrace add_latent_entropy
62474 #define __devinitdata __section(.devinit.data)
62475 #define __devinitconst __section(.devinit.rodata)
62476 #define __devexit __section(.devexit.text) __exitused __cold notrace
62477@@ -91,7 +97,7 @@
62478 #define __devexitconst __section(.devexit.rodata)
62479
62480 /* Used for HOTPLUG_CPU */
62481-#define __cpuinit __section(.cpuinit.text) __cold notrace
62482+#define __cpuinit __section(.cpuinit.text) __cold notrace add_latent_entropy
62483 #define __cpuinitdata __section(.cpuinit.data)
62484 #define __cpuinitconst __section(.cpuinit.rodata)
62485 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
62486@@ -99,7 +105,7 @@
62487 #define __cpuexitconst __section(.cpuexit.rodata)
62488
62489 /* Used for MEMORY_HOTPLUG */
62490-#define __meminit __section(.meminit.text) __cold notrace
62491+#define __meminit __section(.meminit.text) __cold notrace add_latent_entropy
62492 #define __meminitdata __section(.meminit.data)
62493 #define __meminitconst __section(.meminit.rodata)
62494 #define __memexit __section(.memexit.text) __exitused __cold notrace
62495diff --git a/include/linux/init_task.h b/include/linux/init_task.h
62496index 9e65eff..b131e8b 100644
62497--- a/include/linux/init_task.h
62498+++ b/include/linux/init_task.h
62499@@ -134,6 +134,12 @@ extern struct cred init_cred;
62500
62501 #define INIT_TASK_COMM "swapper"
62502
62503+#ifdef CONFIG_X86
62504+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
62505+#else
62506+#define INIT_TASK_THREAD_INFO
62507+#endif
62508+
62509 /*
62510 * INIT_TASK is used to set up the first task table, touch at
62511 * your own risk!. Base=0, limit=0x1fffff (=2MB)
62512@@ -172,6 +178,7 @@ extern struct cred init_cred;
62513 RCU_INIT_POINTER(.cred, &init_cred), \
62514 .comm = INIT_TASK_COMM, \
62515 .thread = INIT_THREAD, \
62516+ INIT_TASK_THREAD_INFO \
62517 .fs = &init_fs, \
62518 .files = &init_files, \
62519 .signal = &init_signals, \
62520diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
62521index e6ca56d..8583707 100644
62522--- a/include/linux/intel-iommu.h
62523+++ b/include/linux/intel-iommu.h
62524@@ -296,7 +296,7 @@ struct iommu_flush {
62525 u8 fm, u64 type);
62526 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
62527 unsigned int size_order, u64 type);
62528-};
62529+} __no_const;
62530
62531 enum {
62532 SR_DMAR_FECTL_REG,
62533diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
62534index e68a8e5..811b9af 100644
62535--- a/include/linux/interrupt.h
62536+++ b/include/linux/interrupt.h
62537@@ -435,7 +435,7 @@ enum
62538 /* map softirq index to softirq name. update 'softirq_to_name' in
62539 * kernel/softirq.c when adding a new softirq.
62540 */
62541-extern char *softirq_to_name[NR_SOFTIRQS];
62542+extern const char * const softirq_to_name[NR_SOFTIRQS];
62543
62544 /* softirq mask and active fields moved to irq_cpustat_t in
62545 * asm/hardirq.h to get better cache usage. KAO
62546@@ -443,12 +443,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
62547
62548 struct softirq_action
62549 {
62550- void (*action)(struct softirq_action *);
62551+ void (*action)(void);
62552 };
62553
62554 asmlinkage void do_softirq(void);
62555 asmlinkage void __do_softirq(void);
62556-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
62557+extern void open_softirq(int nr, void (*action)(void));
62558 extern void softirq_init(void);
62559 extern void __raise_softirq_irqoff(unsigned int nr);
62560
62561diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
62562index 6883e19..06992b1 100644
62563--- a/include/linux/kallsyms.h
62564+++ b/include/linux/kallsyms.h
62565@@ -15,7 +15,8 @@
62566
62567 struct module;
62568
62569-#ifdef CONFIG_KALLSYMS
62570+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
62571+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62572 /* Lookup the address for a symbol. Returns 0 if not found. */
62573 unsigned long kallsyms_lookup_name(const char *name);
62574
62575@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
62576 /* Stupid that this does nothing, but I didn't create this mess. */
62577 #define __print_symbol(fmt, addr)
62578 #endif /*CONFIG_KALLSYMS*/
62579+#else /* when included by kallsyms.c, vsnprintf.c, or
62580+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
62581+extern void __print_symbol(const char *fmt, unsigned long address);
62582+extern int sprint_backtrace(char *buffer, unsigned long address);
62583+extern int sprint_symbol(char *buffer, unsigned long address);
62584+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
62585+const char *kallsyms_lookup(unsigned long addr,
62586+ unsigned long *symbolsize,
62587+ unsigned long *offset,
62588+ char **modname, char *namebuf);
62589+#endif
62590
62591 /* This macro allows us to keep printk typechecking */
62592 static __printf(1, 2)
62593diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
62594index c4d2fc1..5df9c19 100644
62595--- a/include/linux/kgdb.h
62596+++ b/include/linux/kgdb.h
62597@@ -53,7 +53,7 @@ extern int kgdb_connected;
62598 extern int kgdb_io_module_registered;
62599
62600 extern atomic_t kgdb_setting_breakpoint;
62601-extern atomic_t kgdb_cpu_doing_single_step;
62602+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
62603
62604 extern struct task_struct *kgdb_usethread;
62605 extern struct task_struct *kgdb_contthread;
62606@@ -252,7 +252,7 @@ struct kgdb_arch {
62607 void (*disable_hw_break)(struct pt_regs *regs);
62608 void (*remove_all_hw_break)(void);
62609 void (*correct_hw_break)(void);
62610-};
62611+} __do_const;
62612
62613 /**
62614 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
62615@@ -277,7 +277,7 @@ struct kgdb_io {
62616 void (*pre_exception) (void);
62617 void (*post_exception) (void);
62618 int is_console;
62619-};
62620+} __do_const;
62621
62622 extern struct kgdb_arch arch_kgdb_ops;
62623
62624diff --git a/include/linux/kmod.h b/include/linux/kmod.h
62625index 5398d58..5883a34 100644
62626--- a/include/linux/kmod.h
62627+++ b/include/linux/kmod.h
62628@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
62629 * usually useless though. */
62630 extern __printf(2, 3)
62631 int __request_module(bool wait, const char *name, ...);
62632+extern __printf(3, 4)
62633+int ___request_module(bool wait, char *param_name, const char *name, ...);
62634 #define request_module(mod...) __request_module(true, mod)
62635 #define request_module_nowait(mod...) __request_module(false, mod)
62636 #define try_then_request_module(x, mod...) \
62637diff --git a/include/linux/kref.h b/include/linux/kref.h
62638index 9c07dce..a92fa71 100644
62639--- a/include/linux/kref.h
62640+++ b/include/linux/kref.h
62641@@ -63,7 +63,7 @@ static inline void kref_get(struct kref *kref)
62642 static inline int kref_sub(struct kref *kref, unsigned int count,
62643 void (*release)(struct kref *kref))
62644 {
62645- WARN_ON(release == NULL);
62646+ BUG_ON(release == NULL);
62647
62648 if (atomic_sub_and_test((int) count, &kref->refcount)) {
62649 release(kref);
62650diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
62651index 96c158a..1864db5 100644
62652--- a/include/linux/kvm_host.h
62653+++ b/include/linux/kvm_host.h
62654@@ -345,7 +345,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
62655 void vcpu_load(struct kvm_vcpu *vcpu);
62656 void vcpu_put(struct kvm_vcpu *vcpu);
62657
62658-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62659+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62660 struct module *module);
62661 void kvm_exit(void);
62662
62663@@ -511,7 +511,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
62664 struct kvm_guest_debug *dbg);
62665 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
62666
62667-int kvm_arch_init(void *opaque);
62668+int kvm_arch_init(const void *opaque);
62669 void kvm_arch_exit(void);
62670
62671 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
62672diff --git a/include/linux/libata.h b/include/linux/libata.h
62673index 6e887c7..4539601 100644
62674--- a/include/linux/libata.h
62675+++ b/include/linux/libata.h
62676@@ -910,7 +910,7 @@ struct ata_port_operations {
62677 * fields must be pointers.
62678 */
62679 const struct ata_port_operations *inherits;
62680-};
62681+} __do_const;
62682
62683 struct ata_port_info {
62684 unsigned long flags;
62685diff --git a/include/linux/memory.h b/include/linux/memory.h
62686index 1ac7f6e..a5794d0 100644
62687--- a/include/linux/memory.h
62688+++ b/include/linux/memory.h
62689@@ -143,7 +143,7 @@ struct memory_accessor {
62690 size_t count);
62691 ssize_t (*write)(struct memory_accessor *, const char *buf,
62692 off_t offset, size_t count);
62693-};
62694+} __no_const;
62695
62696 /*
62697 * Kernel text modification mutex, used for code patching. Users of this lock
62698diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
62699index 1318ca6..7521340 100644
62700--- a/include/linux/mfd/abx500.h
62701+++ b/include/linux/mfd/abx500.h
62702@@ -452,6 +452,7 @@ struct abx500_ops {
62703 int (*event_registers_startup_state_get) (struct device *, u8 *);
62704 int (*startup_irq_enabled) (struct device *, unsigned int);
62705 };
62706+typedef struct abx500_ops __no_const abx500_ops_no_const;
62707
62708 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
62709 void abx500_remove_ops(struct device *dev);
62710diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
62711index 9b07725..3d55001 100644
62712--- a/include/linux/mfd/abx500/ux500_chargalg.h
62713+++ b/include/linux/mfd/abx500/ux500_chargalg.h
62714@@ -19,7 +19,7 @@ struct ux500_charger_ops {
62715 int (*enable) (struct ux500_charger *, int, int, int);
62716 int (*kick_wd) (struct ux500_charger *);
62717 int (*update_curr) (struct ux500_charger *, int);
62718-};
62719+} __no_const;
62720
62721 /**
62722 * struct ux500_charger - power supply ux500 charger sub class
62723diff --git a/include/linux/mm.h b/include/linux/mm.h
62724index f9f279c..198da78 100644
62725--- a/include/linux/mm.h
62726+++ b/include/linux/mm.h
62727@@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
62728
62729 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
62730 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
62731+
62732+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
62733+#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
62734+#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
62735+#else
62736 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
62737+#endif
62738+
62739 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
62740 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
62741
62742@@ -1009,34 +1016,6 @@ int set_page_dirty(struct page *page);
62743 int set_page_dirty_lock(struct page *page);
62744 int clear_page_dirty_for_io(struct page *page);
62745
62746-/* Is the vma a continuation of the stack vma above it? */
62747-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
62748-{
62749- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
62750-}
62751-
62752-static inline int stack_guard_page_start(struct vm_area_struct *vma,
62753- unsigned long addr)
62754-{
62755- return (vma->vm_flags & VM_GROWSDOWN) &&
62756- (vma->vm_start == addr) &&
62757- !vma_growsdown(vma->vm_prev, addr);
62758-}
62759-
62760-/* Is the vma a continuation of the stack vma below it? */
62761-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
62762-{
62763- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
62764-}
62765-
62766-static inline int stack_guard_page_end(struct vm_area_struct *vma,
62767- unsigned long addr)
62768-{
62769- return (vma->vm_flags & VM_GROWSUP) &&
62770- (vma->vm_end == addr) &&
62771- !vma_growsup(vma->vm_next, addr);
62772-}
62773-
62774 extern pid_t
62775 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
62776
62777@@ -1135,6 +1114,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
62778 }
62779 #endif
62780
62781+#ifdef CONFIG_MMU
62782+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
62783+#else
62784+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
62785+{
62786+ return __pgprot(0);
62787+}
62788+#endif
62789+
62790 int vma_wants_writenotify(struct vm_area_struct *vma);
62791
62792 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
62793@@ -1153,8 +1141,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
62794 {
62795 return 0;
62796 }
62797+
62798+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
62799+ unsigned long address)
62800+{
62801+ return 0;
62802+}
62803 #else
62804 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
62805+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
62806 #endif
62807
62808 #ifdef __PAGETABLE_PMD_FOLDED
62809@@ -1163,8 +1158,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
62810 {
62811 return 0;
62812 }
62813+
62814+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
62815+ unsigned long address)
62816+{
62817+ return 0;
62818+}
62819 #else
62820 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
62821+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
62822 #endif
62823
62824 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
62825@@ -1182,11 +1184,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
62826 NULL: pud_offset(pgd, address);
62827 }
62828
62829+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
62830+{
62831+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
62832+ NULL: pud_offset(pgd, address);
62833+}
62834+
62835 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
62836 {
62837 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
62838 NULL: pmd_offset(pud, address);
62839 }
62840+
62841+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
62842+{
62843+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
62844+ NULL: pmd_offset(pud, address);
62845+}
62846 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
62847
62848 #if USE_SPLIT_PTLOCKS
62849@@ -1396,6 +1410,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
62850 unsigned long, unsigned long,
62851 unsigned long, unsigned long);
62852 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
62853+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
62854
62855 /* These take the mm semaphore themselves */
62856 extern unsigned long vm_brk(unsigned long, unsigned long);
62857@@ -1458,6 +1473,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
62858 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
62859 struct vm_area_struct **pprev);
62860
62861+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
62862+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
62863+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
62864+
62865 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
62866 NULL if none. Assume start_addr < end_addr. */
62867 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
62868@@ -1486,15 +1505,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
62869 return vma;
62870 }
62871
62872-#ifdef CONFIG_MMU
62873-pgprot_t vm_get_page_prot(unsigned long vm_flags);
62874-#else
62875-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
62876-{
62877- return __pgprot(0);
62878-}
62879-#endif
62880-
62881 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
62882 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
62883 unsigned long pfn, unsigned long size, pgprot_t);
62884@@ -1599,7 +1609,7 @@ extern int unpoison_memory(unsigned long pfn);
62885 extern int sysctl_memory_failure_early_kill;
62886 extern int sysctl_memory_failure_recovery;
62887 extern void shake_page(struct page *p, int access);
62888-extern atomic_long_t mce_bad_pages;
62889+extern atomic_long_unchecked_t mce_bad_pages;
62890 extern int soft_offline_page(struct page *page, int flags);
62891
62892 extern void dump_page(struct page *page);
62893@@ -1630,5 +1640,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
62894 static inline bool page_is_guard(struct page *page) { return false; }
62895 #endif /* CONFIG_DEBUG_PAGEALLOC */
62896
62897+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
62898+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
62899+#else
62900+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
62901+#endif
62902+
62903 #endif /* __KERNEL__ */
62904 #endif /* _LINUX_MM_H */
62905diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
62906index 704a626..bb0705a 100644
62907--- a/include/linux/mm_types.h
62908+++ b/include/linux/mm_types.h
62909@@ -263,6 +263,8 @@ struct vm_area_struct {
62910 #ifdef CONFIG_NUMA
62911 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
62912 #endif
62913+
62914+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
62915 };
62916
62917 struct core_thread {
62918@@ -337,7 +339,7 @@ struct mm_struct {
62919 unsigned long def_flags;
62920 unsigned long nr_ptes; /* Page table pages */
62921 unsigned long start_code, end_code, start_data, end_data;
62922- unsigned long start_brk, brk, start_stack;
62923+ unsigned long brk_gap, start_brk, brk, start_stack;
62924 unsigned long arg_start, arg_end, env_start, env_end;
62925
62926 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
62927@@ -389,6 +391,24 @@ struct mm_struct {
62928 struct cpumask cpumask_allocation;
62929 #endif
62930 struct uprobes_state uprobes_state;
62931+
62932+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62933+ unsigned long pax_flags;
62934+#endif
62935+
62936+#ifdef CONFIG_PAX_DLRESOLVE
62937+ unsigned long call_dl_resolve;
62938+#endif
62939+
62940+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
62941+ unsigned long call_syscall;
62942+#endif
62943+
62944+#ifdef CONFIG_PAX_ASLR
62945+ unsigned long delta_mmap; /* randomized offset */
62946+ unsigned long delta_stack; /* randomized offset */
62947+#endif
62948+
62949 };
62950
62951 static inline void mm_init_cpumask(struct mm_struct *mm)
62952diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
62953index 1d1b1e1..2a13c78 100644
62954--- a/include/linux/mmu_notifier.h
62955+++ b/include/linux/mmu_notifier.h
62956@@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
62957 */
62958 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
62959 ({ \
62960- pte_t __pte; \
62961+ pte_t ___pte; \
62962 struct vm_area_struct *___vma = __vma; \
62963 unsigned long ___address = __address; \
62964- __pte = ptep_clear_flush(___vma, ___address, __ptep); \
62965+ ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
62966 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
62967- __pte; \
62968+ ___pte; \
62969 })
62970
62971 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
62972diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
62973index 68c569f..5f43753 100644
62974--- a/include/linux/mmzone.h
62975+++ b/include/linux/mmzone.h
62976@@ -411,7 +411,7 @@ struct zone {
62977 unsigned long flags; /* zone flags, see below */
62978
62979 /* Zone statistics */
62980- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62981+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62982
62983 /*
62984 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
62985diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
62986index 5db9382..50e801d 100644
62987--- a/include/linux/mod_devicetable.h
62988+++ b/include/linux/mod_devicetable.h
62989@@ -12,7 +12,7 @@
62990 typedef unsigned long kernel_ulong_t;
62991 #endif
62992
62993-#define PCI_ANY_ID (~0)
62994+#define PCI_ANY_ID ((__u16)~0)
62995
62996 struct pci_device_id {
62997 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
62998@@ -131,7 +131,7 @@ struct usb_device_id {
62999 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
63000 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
63001
63002-#define HID_ANY_ID (~0)
63003+#define HID_ANY_ID (~0U)
63004 #define HID_BUS_ANY 0xffff
63005 #define HID_GROUP_ANY 0x0000
63006
63007diff --git a/include/linux/module.h b/include/linux/module.h
63008index fbcafe2..e5d9587 100644
63009--- a/include/linux/module.h
63010+++ b/include/linux/module.h
63011@@ -17,6 +17,7 @@
63012 #include <linux/moduleparam.h>
63013 #include <linux/tracepoint.h>
63014 #include <linux/export.h>
63015+#include <linux/fs.h>
63016
63017 #include <linux/percpu.h>
63018 #include <asm/module.h>
63019@@ -273,19 +274,16 @@ struct module
63020 int (*init)(void);
63021
63022 /* If this is non-NULL, vfree after init() returns */
63023- void *module_init;
63024+ void *module_init_rx, *module_init_rw;
63025
63026 /* Here is the actual code + data, vfree'd on unload. */
63027- void *module_core;
63028+ void *module_core_rx, *module_core_rw;
63029
63030 /* Here are the sizes of the init and core sections */
63031- unsigned int init_size, core_size;
63032+ unsigned int init_size_rw, core_size_rw;
63033
63034 /* The size of the executable code in each section. */
63035- unsigned int init_text_size, core_text_size;
63036-
63037- /* Size of RO sections of the module (text+rodata) */
63038- unsigned int init_ro_size, core_ro_size;
63039+ unsigned int init_size_rx, core_size_rx;
63040
63041 /* Arch-specific module values */
63042 struct mod_arch_specific arch;
63043@@ -341,6 +339,10 @@ struct module
63044 #ifdef CONFIG_EVENT_TRACING
63045 struct ftrace_event_call **trace_events;
63046 unsigned int num_trace_events;
63047+ struct file_operations trace_id;
63048+ struct file_operations trace_enable;
63049+ struct file_operations trace_format;
63050+ struct file_operations trace_filter;
63051 #endif
63052 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
63053 unsigned int num_ftrace_callsites;
63054@@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
63055 bool is_module_percpu_address(unsigned long addr);
63056 bool is_module_text_address(unsigned long addr);
63057
63058+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
63059+{
63060+
63061+#ifdef CONFIG_PAX_KERNEXEC
63062+ if (ktla_ktva(addr) >= (unsigned long)start &&
63063+ ktla_ktva(addr) < (unsigned long)start + size)
63064+ return 1;
63065+#endif
63066+
63067+ return ((void *)addr >= start && (void *)addr < start + size);
63068+}
63069+
63070+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
63071+{
63072+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
63073+}
63074+
63075+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
63076+{
63077+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
63078+}
63079+
63080+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
63081+{
63082+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
63083+}
63084+
63085+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
63086+{
63087+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
63088+}
63089+
63090 static inline int within_module_core(unsigned long addr, struct module *mod)
63091 {
63092- return (unsigned long)mod->module_core <= addr &&
63093- addr < (unsigned long)mod->module_core + mod->core_size;
63094+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
63095 }
63096
63097 static inline int within_module_init(unsigned long addr, struct module *mod)
63098 {
63099- return (unsigned long)mod->module_init <= addr &&
63100- addr < (unsigned long)mod->module_init + mod->init_size;
63101+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
63102 }
63103
63104 /* Search for module by name: must hold module_mutex. */
63105diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
63106index b2be02e..72d2f78 100644
63107--- a/include/linux/moduleloader.h
63108+++ b/include/linux/moduleloader.h
63109@@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
63110
63111 /* Allocator used for allocating struct module, core sections and init
63112 sections. Returns NULL on failure. */
63113-void *module_alloc(unsigned long size);
63114+void *module_alloc(unsigned long size) __size_overflow(1);
63115+
63116+#ifdef CONFIG_PAX_KERNEXEC
63117+void *module_alloc_exec(unsigned long size) __size_overflow(1);
63118+#else
63119+#define module_alloc_exec(x) module_alloc(x)
63120+#endif
63121
63122 /* Free memory returned from module_alloc. */
63123 void module_free(struct module *mod, void *module_region);
63124
63125+#ifdef CONFIG_PAX_KERNEXEC
63126+void module_free_exec(struct module *mod, void *module_region);
63127+#else
63128+#define module_free_exec(x, y) module_free((x), (y))
63129+#endif
63130+
63131 /* Apply the given relocation to the (simplified) ELF. Return -error
63132 or 0. */
63133 int apply_relocate(Elf_Shdr *sechdrs,
63134diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
63135index d6a5806..7c13347 100644
63136--- a/include/linux/moduleparam.h
63137+++ b/include/linux/moduleparam.h
63138@@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
63139 * @len is usually just sizeof(string).
63140 */
63141 #define module_param_string(name, string, len, perm) \
63142- static const struct kparam_string __param_string_##name \
63143+ static const struct kparam_string __param_string_##name __used \
63144 = { len, string }; \
63145 __module_param_call(MODULE_PARAM_PREFIX, name, \
63146 &param_ops_string, \
63147@@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
63148 */
63149 #define module_param_array_named(name, array, type, nump, perm) \
63150 param_check_##type(name, &(array)[0]); \
63151- static const struct kparam_array __param_arr_##name \
63152+ static const struct kparam_array __param_arr_##name __used \
63153 = { .max = ARRAY_SIZE(array), .num = nump, \
63154 .ops = &param_ops_##type, \
63155 .elemsize = sizeof(array[0]), .elem = array }; \
63156diff --git a/include/linux/namei.h b/include/linux/namei.h
63157index ffc0213..2c1f2cb 100644
63158--- a/include/linux/namei.h
63159+++ b/include/linux/namei.h
63160@@ -24,7 +24,7 @@ struct nameidata {
63161 unsigned seq;
63162 int last_type;
63163 unsigned depth;
63164- char *saved_names[MAX_NESTED_LINKS + 1];
63165+ const char *saved_names[MAX_NESTED_LINKS + 1];
63166
63167 /* Intent data */
63168 union {
63169@@ -94,12 +94,12 @@ extern int follow_up(struct path *);
63170 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
63171 extern void unlock_rename(struct dentry *, struct dentry *);
63172
63173-static inline void nd_set_link(struct nameidata *nd, char *path)
63174+static inline void nd_set_link(struct nameidata *nd, const char *path)
63175 {
63176 nd->saved_names[nd->depth] = path;
63177 }
63178
63179-static inline char *nd_get_link(struct nameidata *nd)
63180+static inline const char *nd_get_link(const struct nameidata *nd)
63181 {
63182 return nd->saved_names[nd->depth];
63183 }
63184diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
63185index d94cb14..e64c951 100644
63186--- a/include/linux/netdevice.h
63187+++ b/include/linux/netdevice.h
63188@@ -1026,6 +1026,7 @@ struct net_device_ops {
63189 struct net_device *dev,
63190 int idx);
63191 };
63192+typedef struct net_device_ops __no_const net_device_ops_no_const;
63193
63194 /*
63195 * The DEVICE structure.
63196@@ -1087,7 +1088,7 @@ struct net_device {
63197 int iflink;
63198
63199 struct net_device_stats stats;
63200- atomic_long_t rx_dropped; /* dropped packets by core network
63201+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
63202 * Do not use this in drivers.
63203 */
63204
63205diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
63206new file mode 100644
63207index 0000000..33f4af8
63208--- /dev/null
63209+++ b/include/linux/netfilter/xt_gradm.h
63210@@ -0,0 +1,9 @@
63211+#ifndef _LINUX_NETFILTER_XT_GRADM_H
63212+#define _LINUX_NETFILTER_XT_GRADM_H 1
63213+
63214+struct xt_gradm_mtinfo {
63215+ __u16 flags;
63216+ __u16 invflags;
63217+};
63218+
63219+#endif
63220diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
63221index c65a18a..0c05f3a 100644
63222--- a/include/linux/of_pdt.h
63223+++ b/include/linux/of_pdt.h
63224@@ -32,7 +32,7 @@ struct of_pdt_ops {
63225
63226 /* return 0 on success; fill in 'len' with number of bytes in path */
63227 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
63228-};
63229+} __no_const;
63230
63231 extern void *prom_early_alloc(unsigned long size);
63232
63233diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
63234index a4c5624..79d6d88 100644
63235--- a/include/linux/oprofile.h
63236+++ b/include/linux/oprofile.h
63237@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
63238 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
63239 char const * name, ulong * val);
63240
63241-/** Create a file for read-only access to an atomic_t. */
63242+/** Create a file for read-only access to an atomic_unchecked_t. */
63243 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
63244- char const * name, atomic_t * val);
63245+ char const * name, atomic_unchecked_t * val);
63246
63247 /** create a directory */
63248 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
63249diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
63250index 45db49f..386788e 100644
63251--- a/include/linux/perf_event.h
63252+++ b/include/linux/perf_event.h
63253@@ -879,8 +879,8 @@ struct perf_event {
63254
63255 enum perf_event_active_state state;
63256 unsigned int attach_state;
63257- local64_t count;
63258- atomic64_t child_count;
63259+ local64_t count; /* PaX: fix it one day */
63260+ atomic64_unchecked_t child_count;
63261
63262 /*
63263 * These are the total time in nanoseconds that the event
63264@@ -931,8 +931,8 @@ struct perf_event {
63265 * These accumulate total time (in nanoseconds) that children
63266 * events have been enabled and running, respectively.
63267 */
63268- atomic64_t child_total_time_enabled;
63269- atomic64_t child_total_time_running;
63270+ atomic64_unchecked_t child_total_time_enabled;
63271+ atomic64_unchecked_t child_total_time_running;
63272
63273 /*
63274 * Protect attach/detach and child_list:
63275diff --git a/include/linux/personality.h b/include/linux/personality.h
63276index 8fc7dd1a..c19d89e 100644
63277--- a/include/linux/personality.h
63278+++ b/include/linux/personality.h
63279@@ -44,6 +44,7 @@ enum {
63280 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
63281 ADDR_NO_RANDOMIZE | \
63282 ADDR_COMPAT_LAYOUT | \
63283+ ADDR_LIMIT_3GB | \
63284 MMAP_PAGE_ZERO)
63285
63286 /*
63287diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
63288index e1ac1ce..0675fed 100644
63289--- a/include/linux/pipe_fs_i.h
63290+++ b/include/linux/pipe_fs_i.h
63291@@ -45,9 +45,9 @@ struct pipe_buffer {
63292 struct pipe_inode_info {
63293 wait_queue_head_t wait;
63294 unsigned int nrbufs, curbuf, buffers;
63295- unsigned int readers;
63296- unsigned int writers;
63297- unsigned int waiting_writers;
63298+ atomic_t readers;
63299+ atomic_t writers;
63300+ atomic_t waiting_writers;
63301 unsigned int r_counter;
63302 unsigned int w_counter;
63303 struct page *tmp_page;
63304diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
63305index f271860..6b3bec5 100644
63306--- a/include/linux/pm_runtime.h
63307+++ b/include/linux/pm_runtime.h
63308@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
63309
63310 static inline void pm_runtime_mark_last_busy(struct device *dev)
63311 {
63312- ACCESS_ONCE(dev->power.last_busy) = jiffies;
63313+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
63314 }
63315
63316 #else /* !CONFIG_PM_RUNTIME */
63317diff --git a/include/linux/poison.h b/include/linux/poison.h
63318index 2110a81..13a11bb 100644
63319--- a/include/linux/poison.h
63320+++ b/include/linux/poison.h
63321@@ -19,8 +19,8 @@
63322 * under normal circumstances, used to verify that nobody uses
63323 * non-initialized list entries.
63324 */
63325-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
63326-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
63327+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
63328+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
63329
63330 /********** include/linux/timer.h **********/
63331 /*
63332diff --git a/include/linux/preempt.h b/include/linux/preempt.h
63333index 5a710b9..0b0dab9 100644
63334--- a/include/linux/preempt.h
63335+++ b/include/linux/preempt.h
63336@@ -126,7 +126,7 @@ struct preempt_ops {
63337 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
63338 void (*sched_out)(struct preempt_notifier *notifier,
63339 struct task_struct *next);
63340-};
63341+} __no_const;
63342
63343 /**
63344 * preempt_notifier - key for installing preemption notifiers
63345diff --git a/include/linux/printk.h b/include/linux/printk.h
63346index 1bec2f7..b66e833 100644
63347--- a/include/linux/printk.h
63348+++ b/include/linux/printk.h
63349@@ -94,6 +94,8 @@ void early_printk(const char *fmt, ...);
63350 extern int printk_needs_cpu(int cpu);
63351 extern void printk_tick(void);
63352
63353+extern int kptr_restrict;
63354+
63355 #ifdef CONFIG_PRINTK
63356 asmlinkage __printf(5, 0)
63357 int vprintk_emit(int facility, int level,
63358@@ -128,7 +130,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
63359
63360 extern int printk_delay_msec;
63361 extern int dmesg_restrict;
63362-extern int kptr_restrict;
63363
63364 void log_buf_kexec_setup(void);
63365 void __init setup_log_buf(int early);
63366diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
63367index 3fd2e87..d93a721 100644
63368--- a/include/linux/proc_fs.h
63369+++ b/include/linux/proc_fs.h
63370@@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
63371 return proc_create_data(name, mode, parent, proc_fops, NULL);
63372 }
63373
63374+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
63375+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
63376+{
63377+#ifdef CONFIG_GRKERNSEC_PROC_USER
63378+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
63379+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63380+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
63381+#else
63382+ return proc_create_data(name, mode, parent, proc_fops, NULL);
63383+#endif
63384+}
63385+
63386 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
63387 umode_t mode, struct proc_dir_entry *base,
63388 read_proc_t *read_proc, void * data)
63389@@ -258,7 +270,7 @@ union proc_op {
63390 int (*proc_show)(struct seq_file *m,
63391 struct pid_namespace *ns, struct pid *pid,
63392 struct task_struct *task);
63393-};
63394+} __no_const;
63395
63396 struct ctl_table_header;
63397 struct ctl_table;
63398diff --git a/include/linux/random.h b/include/linux/random.h
63399index ac621ce..c1215f3 100644
63400--- a/include/linux/random.h
63401+++ b/include/linux/random.h
63402@@ -53,6 +53,10 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
63403 unsigned int value);
63404 extern void add_interrupt_randomness(int irq, int irq_flags);
63405
63406+#ifdef CONFIG_PAX_LATENT_ENTROPY
63407+extern void transfer_latent_entropy(void);
63408+#endif
63409+
63410 extern void get_random_bytes(void *buf, int nbytes);
63411 extern void get_random_bytes_arch(void *buf, int nbytes);
63412 void generate_random_uuid(unsigned char uuid_out[16]);
63413@@ -69,12 +73,17 @@ void srandom32(u32 seed);
63414
63415 u32 prandom32(struct rnd_state *);
63416
63417+static inline unsigned long pax_get_random_long(void)
63418+{
63419+ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
63420+}
63421+
63422 /*
63423 * Handle minimum values for seeds
63424 */
63425 static inline u32 __seed(u32 x, u32 m)
63426 {
63427- return (x < m) ? x + m : x;
63428+ return (x <= m) ? x + m + 1 : x;
63429 }
63430
63431 /**
63432diff --git a/include/linux/reboot.h b/include/linux/reboot.h
63433index e0879a7..a12f962 100644
63434--- a/include/linux/reboot.h
63435+++ b/include/linux/reboot.h
63436@@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
63437 * Architecture-specific implementations of sys_reboot commands.
63438 */
63439
63440-extern void machine_restart(char *cmd);
63441-extern void machine_halt(void);
63442-extern void machine_power_off(void);
63443+extern void machine_restart(char *cmd) __noreturn;
63444+extern void machine_halt(void) __noreturn;
63445+extern void machine_power_off(void) __noreturn;
63446
63447 extern void machine_shutdown(void);
63448 struct pt_regs;
63449@@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
63450 */
63451
63452 extern void kernel_restart_prepare(char *cmd);
63453-extern void kernel_restart(char *cmd);
63454-extern void kernel_halt(void);
63455-extern void kernel_power_off(void);
63456+extern void kernel_restart(char *cmd) __noreturn;
63457+extern void kernel_halt(void) __noreturn;
63458+extern void kernel_power_off(void) __noreturn;
63459
63460 extern int C_A_D; /* for sysctl */
63461 void ctrl_alt_del(void);
63462@@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
63463 * Emergency restart, callable from an interrupt handler.
63464 */
63465
63466-extern void emergency_restart(void);
63467+extern void emergency_restart(void) __noreturn;
63468 #include <asm/emergency-restart.h>
63469
63470 #endif
63471diff --git a/include/linux/relay.h b/include/linux/relay.h
63472index 91cacc3..b55ff74 100644
63473--- a/include/linux/relay.h
63474+++ b/include/linux/relay.h
63475@@ -160,7 +160,7 @@ struct rchan_callbacks
63476 * The callback should return 0 if successful, negative if not.
63477 */
63478 int (*remove_buf_file)(struct dentry *dentry);
63479-};
63480+} __no_const;
63481
63482 /*
63483 * CONFIG_RELAY kernel API, kernel/relay.c
63484diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
63485index 6fdf027..ff72610 100644
63486--- a/include/linux/rfkill.h
63487+++ b/include/linux/rfkill.h
63488@@ -147,6 +147,7 @@ struct rfkill_ops {
63489 void (*query)(struct rfkill *rfkill, void *data);
63490 int (*set_block)(void *data, bool blocked);
63491 };
63492+typedef struct rfkill_ops __no_const rfkill_ops_no_const;
63493
63494 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
63495 /**
63496diff --git a/include/linux/rio.h b/include/linux/rio.h
63497index a90ebad..fd87b5d 100644
63498--- a/include/linux/rio.h
63499+++ b/include/linux/rio.h
63500@@ -321,7 +321,7 @@ struct rio_ops {
63501 int mbox, void *buffer, size_t len);
63502 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
63503 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
63504-};
63505+} __no_const;
63506
63507 #define RIO_RESOURCE_MEM 0x00000100
63508 #define RIO_RESOURCE_DOORBELL 0x00000200
63509diff --git a/include/linux/rmap.h b/include/linux/rmap.h
63510index 3fce545..b4fed6e 100644
63511--- a/include/linux/rmap.h
63512+++ b/include/linux/rmap.h
63513@@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
63514 void anon_vma_init(void); /* create anon_vma_cachep */
63515 int anon_vma_prepare(struct vm_area_struct *);
63516 void unlink_anon_vmas(struct vm_area_struct *);
63517-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
63518+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
63519 void anon_vma_moveto_tail(struct vm_area_struct *);
63520-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
63521+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
63522
63523 static inline void anon_vma_merge(struct vm_area_struct *vma,
63524 struct vm_area_struct *next)
63525diff --git a/include/linux/sched.h b/include/linux/sched.h
63526index 4a1f493..5812aeb 100644
63527--- a/include/linux/sched.h
63528+++ b/include/linux/sched.h
63529@@ -101,6 +101,7 @@ struct bio_list;
63530 struct fs_struct;
63531 struct perf_event_context;
63532 struct blk_plug;
63533+struct linux_binprm;
63534
63535 /*
63536 * List of flags we want to share for kernel threads,
63537@@ -384,10 +385,13 @@ struct user_namespace;
63538 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
63539
63540 extern int sysctl_max_map_count;
63541+extern unsigned long sysctl_heap_stack_gap;
63542
63543 #include <linux/aio.h>
63544
63545 #ifdef CONFIG_MMU
63546+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
63547+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
63548 extern void arch_pick_mmap_layout(struct mm_struct *mm);
63549 extern unsigned long
63550 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
63551@@ -406,6 +410,11 @@ static inline void arch_pick_mmap_layout(struct mm_struct *mm) {}
63552 extern void set_dumpable(struct mm_struct *mm, int value);
63553 extern int get_dumpable(struct mm_struct *mm);
63554
63555+/* get/set_dumpable() values */
63556+#define SUID_DUMPABLE_DISABLED 0
63557+#define SUID_DUMPABLE_ENABLED 1
63558+#define SUID_DUMPABLE_SAFE 2
63559+
63560 /* mm flags */
63561 /* dumpable bits */
63562 #define MMF_DUMPABLE 0 /* core dump is permitted */
63563@@ -646,6 +655,17 @@ struct signal_struct {
63564 #ifdef CONFIG_TASKSTATS
63565 struct taskstats *stats;
63566 #endif
63567+
63568+#ifdef CONFIG_GRKERNSEC
63569+ u32 curr_ip;
63570+ u32 saved_ip;
63571+ u32 gr_saddr;
63572+ u32 gr_daddr;
63573+ u16 gr_sport;
63574+ u16 gr_dport;
63575+ u8 used_accept:1;
63576+#endif
63577+
63578 #ifdef CONFIG_AUDIT
63579 unsigned audit_tty;
63580 struct tty_audit_buf *tty_audit_buf;
63581@@ -729,6 +749,11 @@ struct user_struct {
63582 struct key *session_keyring; /* UID's default session keyring */
63583 #endif
63584
63585+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
63586+ unsigned int banned;
63587+ unsigned long ban_expires;
63588+#endif
63589+
63590 /* Hash table maintenance information */
63591 struct hlist_node uidhash_node;
63592 kuid_t uid;
63593@@ -1348,8 +1373,8 @@ struct task_struct {
63594 struct list_head thread_group;
63595
63596 struct completion *vfork_done; /* for vfork() */
63597- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
63598- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63599+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
63600+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63601
63602 cputime_t utime, stime, utimescaled, stimescaled;
63603 cputime_t gtime;
63604@@ -1365,11 +1390,6 @@ struct task_struct {
63605 struct task_cputime cputime_expires;
63606 struct list_head cpu_timers[3];
63607
63608-/* process credentials */
63609- const struct cred __rcu *real_cred; /* objective and real subjective task
63610- * credentials (COW) */
63611- const struct cred __rcu *cred; /* effective (overridable) subjective task
63612- * credentials (COW) */
63613 char comm[TASK_COMM_LEN]; /* executable name excluding path
63614 - access with [gs]et_task_comm (which lock
63615 it with task_lock())
63616@@ -1386,8 +1406,16 @@ struct task_struct {
63617 #endif
63618 /* CPU-specific state of this task */
63619 struct thread_struct thread;
63620+/* thread_info moved to task_struct */
63621+#ifdef CONFIG_X86
63622+ struct thread_info tinfo;
63623+#endif
63624 /* filesystem information */
63625 struct fs_struct *fs;
63626+
63627+ const struct cred __rcu *cred; /* effective (overridable) subjective task
63628+ * credentials (COW) */
63629+
63630 /* open file information */
63631 struct files_struct *files;
63632 /* namespaces */
63633@@ -1431,6 +1459,11 @@ struct task_struct {
63634 struct rt_mutex_waiter *pi_blocked_on;
63635 #endif
63636
63637+/* process credentials */
63638+ const struct cred __rcu *real_cred; /* objective and real subjective task
63639+ * credentials (COW) */
63640+ struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63641+
63642 #ifdef CONFIG_DEBUG_MUTEXES
63643 /* mutex deadlock detection */
63644 struct mutex_waiter *blocked_on;
63645@@ -1547,6 +1580,27 @@ struct task_struct {
63646 unsigned long default_timer_slack_ns;
63647
63648 struct list_head *scm_work_list;
63649+
63650+#ifdef CONFIG_GRKERNSEC
63651+ /* grsecurity */
63652+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63653+ u64 exec_id;
63654+#endif
63655+#ifdef CONFIG_GRKERNSEC_SETXID
63656+ const struct cred *delayed_cred;
63657+#endif
63658+ struct dentry *gr_chroot_dentry;
63659+ struct acl_subject_label *acl;
63660+ struct acl_role_label *role;
63661+ struct file *exec_file;
63662+ u16 acl_role_id;
63663+ /* is this the task that authenticated to the special role */
63664+ u8 acl_sp_role;
63665+ u8 is_writable;
63666+ u8 brute;
63667+ u8 gr_is_chrooted;
63668+#endif
63669+
63670 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
63671 /* Index of current stored address in ret_stack */
63672 int curr_ret_stack;
63673@@ -1585,6 +1639,51 @@ struct task_struct {
63674 #endif
63675 };
63676
63677+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
63678+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
63679+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
63680+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
63681+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
63682+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
63683+
63684+#ifdef CONFIG_PAX_SOFTMODE
63685+extern int pax_softmode;
63686+#endif
63687+
63688+extern int pax_check_flags(unsigned long *);
63689+
63690+/* if tsk != current then task_lock must be held on it */
63691+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63692+static inline unsigned long pax_get_flags(struct task_struct *tsk)
63693+{
63694+ if (likely(tsk->mm))
63695+ return tsk->mm->pax_flags;
63696+ else
63697+ return 0UL;
63698+}
63699+
63700+/* if tsk != current then task_lock must be held on it */
63701+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
63702+{
63703+ if (likely(tsk->mm)) {
63704+ tsk->mm->pax_flags = flags;
63705+ return 0;
63706+ }
63707+ return -EINVAL;
63708+}
63709+#endif
63710+
63711+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
63712+extern void pax_set_initial_flags(struct linux_binprm *bprm);
63713+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
63714+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
63715+#endif
63716+
63717+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
63718+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
63719+extern void pax_report_refcount_overflow(struct pt_regs *regs);
63720+extern void check_object_size(const void *ptr, unsigned long n, bool to);
63721+
63722 /* Future-safe accessor for struct task_struct's cpus_allowed. */
63723 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
63724
63725@@ -2112,7 +2211,9 @@ void yield(void);
63726 extern struct exec_domain default_exec_domain;
63727
63728 union thread_union {
63729+#ifndef CONFIG_X86
63730 struct thread_info thread_info;
63731+#endif
63732 unsigned long stack[THREAD_SIZE/sizeof(long)];
63733 };
63734
63735@@ -2145,6 +2246,7 @@ extern struct pid_namespace init_pid_ns;
63736 */
63737
63738 extern struct task_struct *find_task_by_vpid(pid_t nr);
63739+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
63740 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
63741 struct pid_namespace *ns);
63742
63743@@ -2301,7 +2403,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
63744 extern void exit_itimers(struct signal_struct *);
63745 extern void flush_itimer_signals(void);
63746
63747-extern void do_group_exit(int);
63748+extern __noreturn void do_group_exit(int);
63749
63750 extern void daemonize(const char *, ...);
63751 extern int allow_signal(int);
63752@@ -2502,9 +2604,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
63753
63754 #endif
63755
63756-static inline int object_is_on_stack(void *obj)
63757+static inline int object_starts_on_stack(void *obj)
63758 {
63759- void *stack = task_stack_page(current);
63760+ const void *stack = task_stack_page(current);
63761
63762 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
63763 }
63764diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
63765index 899fbb4..1cb4138 100644
63766--- a/include/linux/screen_info.h
63767+++ b/include/linux/screen_info.h
63768@@ -43,7 +43,8 @@ struct screen_info {
63769 __u16 pages; /* 0x32 */
63770 __u16 vesa_attributes; /* 0x34 */
63771 __u32 capabilities; /* 0x36 */
63772- __u8 _reserved[6]; /* 0x3a */
63773+ __u16 vesapm_size; /* 0x3a */
63774+ __u8 _reserved[4]; /* 0x3c */
63775 } __attribute__((packed));
63776
63777 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
63778diff --git a/include/linux/security.h b/include/linux/security.h
63779index 3dea6a9..81fd81f 100644
63780--- a/include/linux/security.h
63781+++ b/include/linux/security.h
63782@@ -26,6 +26,7 @@
63783 #include <linux/capability.h>
63784 #include <linux/slab.h>
63785 #include <linux/err.h>
63786+#include <linux/grsecurity.h>
63787
63788 struct linux_binprm;
63789 struct cred;
63790diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
63791index fc61854..d7c490b 100644
63792--- a/include/linux/seq_file.h
63793+++ b/include/linux/seq_file.h
63794@@ -25,6 +25,9 @@ struct seq_file {
63795 struct mutex lock;
63796 const struct seq_operations *op;
63797 int poll_event;
63798+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63799+ u64 exec_id;
63800+#endif
63801 void *private;
63802 };
63803
63804@@ -34,6 +37,7 @@ struct seq_operations {
63805 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
63806 int (*show) (struct seq_file *m, void *v);
63807 };
63808+typedef struct seq_operations __no_const seq_operations_no_const;
63809
63810 #define SEQ_SKIP 1
63811
63812diff --git a/include/linux/shm.h b/include/linux/shm.h
63813index 92808b8..c28cac4 100644
63814--- a/include/linux/shm.h
63815+++ b/include/linux/shm.h
63816@@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
63817
63818 /* The task created the shm object. NULL if the task is dead. */
63819 struct task_struct *shm_creator;
63820+#ifdef CONFIG_GRKERNSEC
63821+ time_t shm_createtime;
63822+ pid_t shm_lapid;
63823+#endif
63824 };
63825
63826 /* shm_mode upper byte flags */
63827diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
63828index 642cb73..7ff7f9f 100644
63829--- a/include/linux/skbuff.h
63830+++ b/include/linux/skbuff.h
63831@@ -680,7 +680,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
63832 */
63833 static inline int skb_queue_empty(const struct sk_buff_head *list)
63834 {
63835- return list->next == (struct sk_buff *)list;
63836+ return list->next == (const struct sk_buff *)list;
63837 }
63838
63839 /**
63840@@ -693,7 +693,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
63841 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63842 const struct sk_buff *skb)
63843 {
63844- return skb->next == (struct sk_buff *)list;
63845+ return skb->next == (const struct sk_buff *)list;
63846 }
63847
63848 /**
63849@@ -706,7 +706,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63850 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
63851 const struct sk_buff *skb)
63852 {
63853- return skb->prev == (struct sk_buff *)list;
63854+ return skb->prev == (const struct sk_buff *)list;
63855 }
63856
63857 /**
63858@@ -1605,7 +1605,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
63859 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
63860 */
63861 #ifndef NET_SKB_PAD
63862-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
63863+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
63864 #endif
63865
63866 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
63867diff --git a/include/linux/slab.h b/include/linux/slab.h
63868index 67d5d94..bbd740b 100644
63869--- a/include/linux/slab.h
63870+++ b/include/linux/slab.h
63871@@ -11,12 +11,20 @@
63872
63873 #include <linux/gfp.h>
63874 #include <linux/types.h>
63875+#include <linux/err.h>
63876
63877 /*
63878 * Flags to pass to kmem_cache_create().
63879 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
63880 */
63881 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
63882+
63883+#ifdef CONFIG_PAX_USERCOPY_SLABS
63884+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
63885+#else
63886+#define SLAB_USERCOPY 0x00000000UL
63887+#endif
63888+
63889 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
63890 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
63891 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
63892@@ -87,10 +95,13 @@
63893 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
63894 * Both make kfree a no-op.
63895 */
63896-#define ZERO_SIZE_PTR ((void *)16)
63897+#define ZERO_SIZE_PTR \
63898+({ \
63899+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
63900+ (void *)(-MAX_ERRNO-1L); \
63901+})
63902
63903-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
63904- (unsigned long)ZERO_SIZE_PTR)
63905+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
63906
63907 /*
63908 * struct kmem_cache related prototypes
63909@@ -161,6 +172,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
63910 void kfree(const void *);
63911 void kzfree(const void *);
63912 size_t ksize(const void *);
63913+const char *check_heap_object(const void *ptr, unsigned long n, bool to);
63914+bool is_usercopy_object(const void *ptr);
63915
63916 /*
63917 * Allocator specific definitions. These are mainly used to establish optimized
63918@@ -298,7 +311,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
63919 */
63920 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63921 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63922-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63923+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
63924 #define kmalloc_track_caller(size, flags) \
63925 __kmalloc_track_caller(size, flags, _RET_IP_)
63926 #else
63927@@ -317,7 +330,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63928 */
63929 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63930 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63931-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
63932+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
63933 #define kmalloc_node_track_caller(size, flags, node) \
63934 __kmalloc_node_track_caller(size, flags, node, \
63935 _RET_IP_)
63936diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
63937index fbd1117..0a3d314 100644
63938--- a/include/linux/slab_def.h
63939+++ b/include/linux/slab_def.h
63940@@ -66,10 +66,10 @@ struct kmem_cache {
63941 unsigned long node_allocs;
63942 unsigned long node_frees;
63943 unsigned long node_overflow;
63944- atomic_t allochit;
63945- atomic_t allocmiss;
63946- atomic_t freehit;
63947- atomic_t freemiss;
63948+ atomic_unchecked_t allochit;
63949+ atomic_unchecked_t allocmiss;
63950+ atomic_unchecked_t freehit;
63951+ atomic_unchecked_t freemiss;
63952
63953 /*
63954 * If debugging is enabled, then the allocator can add additional
63955@@ -103,11 +103,16 @@ struct cache_sizes {
63956 #ifdef CONFIG_ZONE_DMA
63957 struct kmem_cache *cs_dmacachep;
63958 #endif
63959+
63960+#ifdef CONFIG_PAX_USERCOPY_SLABS
63961+ struct kmem_cache *cs_usercopycachep;
63962+#endif
63963+
63964 };
63965 extern struct cache_sizes malloc_sizes[];
63966
63967 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63968-void *__kmalloc(size_t size, gfp_t flags);
63969+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63970
63971 #ifdef CONFIG_TRACING
63972 extern void *kmem_cache_alloc_trace(size_t size,
63973@@ -150,6 +155,13 @@ found:
63974 cachep = malloc_sizes[i].cs_dmacachep;
63975 else
63976 #endif
63977+
63978+#ifdef CONFIG_PAX_USERCOPY_SLABS
63979+ if (flags & GFP_USERCOPY)
63980+ cachep = malloc_sizes[i].cs_usercopycachep;
63981+ else
63982+#endif
63983+
63984 cachep = malloc_sizes[i].cs_cachep;
63985
63986 ret = kmem_cache_alloc_trace(size, cachep, flags);
63987@@ -160,7 +172,7 @@ found:
63988 }
63989
63990 #ifdef CONFIG_NUMA
63991-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
63992+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63993 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
63994
63995 #ifdef CONFIG_TRACING
63996@@ -203,6 +215,13 @@ found:
63997 cachep = malloc_sizes[i].cs_dmacachep;
63998 else
63999 #endif
64000+
64001+#ifdef CONFIG_PAX_USERCOPY_SLABS
64002+ if (flags & GFP_USERCOPY)
64003+ cachep = malloc_sizes[i].cs_usercopycachep;
64004+ else
64005+#endif
64006+
64007 cachep = malloc_sizes[i].cs_cachep;
64008
64009 return kmem_cache_alloc_node_trace(size, cachep, flags, node);
64010diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
64011index 0ec00b3..22b4715 100644
64012--- a/include/linux/slob_def.h
64013+++ b/include/linux/slob_def.h
64014@@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
64015 return kmem_cache_alloc_node(cachep, flags, -1);
64016 }
64017
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
64021 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
64022 {
64023@@ -29,7 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64024 return __kmalloc_node(size, flags, -1);
64025 }
64026
64027-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
64028+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
64029 {
64030 return kmalloc(size, flags);
64031 }
64032diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
64033index c2f8c8b..d992a41 100644
64034--- a/include/linux/slub_def.h
64035+++ b/include/linux/slub_def.h
64036@@ -92,7 +92,7 @@ struct kmem_cache {
64037 struct kmem_cache_order_objects max;
64038 struct kmem_cache_order_objects min;
64039 gfp_t allocflags; /* gfp flags to use on each alloc */
64040- int refcount; /* Refcount for slab cache destroy */
64041+ atomic_t refcount; /* Refcount for slab cache destroy */
64042 void (*ctor)(void *);
64043 int inuse; /* Offset to metadata */
64044 int align; /* Alignment */
64045@@ -153,7 +153,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
64046 * Sorry that the following has to be that ugly but some versions of GCC
64047 * have trouble with constant propagation and loops.
64048 */
64049-static __always_inline int kmalloc_index(size_t size)
64050+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
64051 {
64052 if (!size)
64053 return 0;
64054@@ -218,7 +218,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
64055 }
64056
64057 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64058-void *__kmalloc(size_t size, gfp_t flags);
64059+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
64060
64061 static __always_inline void *
64062 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
64063@@ -259,7 +259,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
64064 }
64065 #endif
64066
64067-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
64068+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
64069 {
64070 unsigned int order = get_order(size);
64071 return kmalloc_order_trace(size, flags, order);
64072@@ -284,7 +284,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64073 }
64074
64075 #ifdef CONFIG_NUMA
64076-void *__kmalloc_node(size_t size, gfp_t flags, int node);
64077+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64078 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64079
64080 #ifdef CONFIG_TRACING
64081diff --git a/include/linux/sonet.h b/include/linux/sonet.h
64082index de8832d..0147b46 100644
64083--- a/include/linux/sonet.h
64084+++ b/include/linux/sonet.h
64085@@ -61,7 +61,7 @@ struct sonet_stats {
64086 #include <linux/atomic.h>
64087
64088 struct k_sonet_stats {
64089-#define __HANDLE_ITEM(i) atomic_t i
64090+#define __HANDLE_ITEM(i) atomic_unchecked_t i
64091 __SONET_ITEMS
64092 #undef __HANDLE_ITEM
64093 };
64094diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
64095index 523547e..2cb7140 100644
64096--- a/include/linux/sunrpc/clnt.h
64097+++ b/include/linux/sunrpc/clnt.h
64098@@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
64099 {
64100 switch (sap->sa_family) {
64101 case AF_INET:
64102- return ntohs(((struct sockaddr_in *)sap)->sin_port);
64103+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
64104 case AF_INET6:
64105- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
64106+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
64107 }
64108 return 0;
64109 }
64110@@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
64111 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
64112 const struct sockaddr *src)
64113 {
64114- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
64115+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
64116 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
64117
64118 dsin->sin_family = ssin->sin_family;
64119@@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
64120 if (sa->sa_family != AF_INET6)
64121 return 0;
64122
64123- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
64124+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
64125 }
64126
64127 #endif /* __KERNEL__ */
64128diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
64129index dc0c3cc..8503fb6 100644
64130--- a/include/linux/sunrpc/sched.h
64131+++ b/include/linux/sunrpc/sched.h
64132@@ -106,6 +106,7 @@ struct rpc_call_ops {
64133 void (*rpc_count_stats)(struct rpc_task *, void *);
64134 void (*rpc_release)(void *);
64135 };
64136+typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
64137
64138 struct rpc_task_setup {
64139 struct rpc_task *task;
64140diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
64141index 0b8e3e6..33e0a01 100644
64142--- a/include/linux/sunrpc/svc_rdma.h
64143+++ b/include/linux/sunrpc/svc_rdma.h
64144@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
64145 extern unsigned int svcrdma_max_requests;
64146 extern unsigned int svcrdma_max_req_size;
64147
64148-extern atomic_t rdma_stat_recv;
64149-extern atomic_t rdma_stat_read;
64150-extern atomic_t rdma_stat_write;
64151-extern atomic_t rdma_stat_sq_starve;
64152-extern atomic_t rdma_stat_rq_starve;
64153-extern atomic_t rdma_stat_rq_poll;
64154-extern atomic_t rdma_stat_rq_prod;
64155-extern atomic_t rdma_stat_sq_poll;
64156-extern atomic_t rdma_stat_sq_prod;
64157+extern atomic_unchecked_t rdma_stat_recv;
64158+extern atomic_unchecked_t rdma_stat_read;
64159+extern atomic_unchecked_t rdma_stat_write;
64160+extern atomic_unchecked_t rdma_stat_sq_starve;
64161+extern atomic_unchecked_t rdma_stat_rq_starve;
64162+extern atomic_unchecked_t rdma_stat_rq_poll;
64163+extern atomic_unchecked_t rdma_stat_rq_prod;
64164+extern atomic_unchecked_t rdma_stat_sq_poll;
64165+extern atomic_unchecked_t rdma_stat_sq_prod;
64166
64167 #define RPCRDMA_VERSION 1
64168
64169diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
64170index c34b4c8..a65b67d 100644
64171--- a/include/linux/sysctl.h
64172+++ b/include/linux/sysctl.h
64173@@ -155,7 +155,11 @@ enum
64174 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
64175 };
64176
64177-
64178+#ifdef CONFIG_PAX_SOFTMODE
64179+enum {
64180+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
64181+};
64182+#endif
64183
64184 /* CTL_VM names: */
64185 enum
64186@@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
64187
64188 extern int proc_dostring(struct ctl_table *, int,
64189 void __user *, size_t *, loff_t *);
64190+extern int proc_dostring_modpriv(struct ctl_table *, int,
64191+ void __user *, size_t *, loff_t *);
64192 extern int proc_dointvec(struct ctl_table *, int,
64193 void __user *, size_t *, loff_t *);
64194 extern int proc_dointvec_minmax(struct ctl_table *, int,
64195diff --git a/include/linux/tty.h b/include/linux/tty.h
64196index 9f47ab5..73da944 100644
64197--- a/include/linux/tty.h
64198+++ b/include/linux/tty.h
64199@@ -225,7 +225,7 @@ struct tty_port {
64200 const struct tty_port_operations *ops; /* Port operations */
64201 spinlock_t lock; /* Lock protecting tty field */
64202 int blocked_open; /* Waiting to open */
64203- int count; /* Usage count */
64204+ atomic_t count; /* Usage count */
64205 wait_queue_head_t open_wait; /* Open waiters */
64206 wait_queue_head_t close_wait; /* Close waiters */
64207 wait_queue_head_t delta_msr_wait; /* Modem status change */
64208@@ -525,7 +525,7 @@ extern int tty_port_open(struct tty_port *port,
64209 struct tty_struct *tty, struct file *filp);
64210 static inline int tty_port_users(struct tty_port *port)
64211 {
64212- return port->count + port->blocked_open;
64213+ return atomic_read(&port->count) + port->blocked_open;
64214 }
64215
64216 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
64217diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
64218index fb79dd8d..07d4773 100644
64219--- a/include/linux/tty_ldisc.h
64220+++ b/include/linux/tty_ldisc.h
64221@@ -149,7 +149,7 @@ struct tty_ldisc_ops {
64222
64223 struct module *owner;
64224
64225- int refcount;
64226+ atomic_t refcount;
64227 };
64228
64229 struct tty_ldisc {
64230diff --git a/include/linux/types.h b/include/linux/types.h
64231index 9c1bd53..c2370f6 100644
64232--- a/include/linux/types.h
64233+++ b/include/linux/types.h
64234@@ -220,10 +220,26 @@ typedef struct {
64235 int counter;
64236 } atomic_t;
64237
64238+#ifdef CONFIG_PAX_REFCOUNT
64239+typedef struct {
64240+ int counter;
64241+} atomic_unchecked_t;
64242+#else
64243+typedef atomic_t atomic_unchecked_t;
64244+#endif
64245+
64246 #ifdef CONFIG_64BIT
64247 typedef struct {
64248 long counter;
64249 } atomic64_t;
64250+
64251+#ifdef CONFIG_PAX_REFCOUNT
64252+typedef struct {
64253+ long counter;
64254+} atomic64_unchecked_t;
64255+#else
64256+typedef atomic64_t atomic64_unchecked_t;
64257+#endif
64258 #endif
64259
64260 struct list_head {
64261diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
64262index 5ca0951..ab496a5 100644
64263--- a/include/linux/uaccess.h
64264+++ b/include/linux/uaccess.h
64265@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
64266 long ret; \
64267 mm_segment_t old_fs = get_fs(); \
64268 \
64269- set_fs(KERNEL_DS); \
64270 pagefault_disable(); \
64271- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
64272- pagefault_enable(); \
64273+ set_fs(KERNEL_DS); \
64274+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
64275 set_fs(old_fs); \
64276+ pagefault_enable(); \
64277 ret; \
64278 })
64279
64280diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
64281index 99c1b4d..bb94261 100644
64282--- a/include/linux/unaligned/access_ok.h
64283+++ b/include/linux/unaligned/access_ok.h
64284@@ -6,32 +6,32 @@
64285
64286 static inline u16 get_unaligned_le16(const void *p)
64287 {
64288- return le16_to_cpup((__le16 *)p);
64289+ return le16_to_cpup((const __le16 *)p);
64290 }
64291
64292 static inline u32 get_unaligned_le32(const void *p)
64293 {
64294- return le32_to_cpup((__le32 *)p);
64295+ return le32_to_cpup((const __le32 *)p);
64296 }
64297
64298 static inline u64 get_unaligned_le64(const void *p)
64299 {
64300- return le64_to_cpup((__le64 *)p);
64301+ return le64_to_cpup((const __le64 *)p);
64302 }
64303
64304 static inline u16 get_unaligned_be16(const void *p)
64305 {
64306- return be16_to_cpup((__be16 *)p);
64307+ return be16_to_cpup((const __be16 *)p);
64308 }
64309
64310 static inline u32 get_unaligned_be32(const void *p)
64311 {
64312- return be32_to_cpup((__be32 *)p);
64313+ return be32_to_cpup((const __be32 *)p);
64314 }
64315
64316 static inline u64 get_unaligned_be64(const void *p)
64317 {
64318- return be64_to_cpup((__be64 *)p);
64319+ return be64_to_cpup((const __be64 *)p);
64320 }
64321
64322 static inline void put_unaligned_le16(u16 val, void *p)
64323diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
64324index 547e59c..db6ad19 100644
64325--- a/include/linux/usb/renesas_usbhs.h
64326+++ b/include/linux/usb/renesas_usbhs.h
64327@@ -39,7 +39,7 @@ enum {
64328 */
64329 struct renesas_usbhs_driver_callback {
64330 int (*notify_hotplug)(struct platform_device *pdev);
64331-};
64332+} __no_const;
64333
64334 /*
64335 * callback functions for platform
64336@@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
64337 * VBUS control is needed for Host
64338 */
64339 int (*set_vbus)(struct platform_device *pdev, int enable);
64340-};
64341+} __no_const;
64342
64343 /*
64344 * parameters for renesas usbhs
64345diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
64346index 6f8fbcf..8259001 100644
64347--- a/include/linux/vermagic.h
64348+++ b/include/linux/vermagic.h
64349@@ -25,9 +25,35 @@
64350 #define MODULE_ARCH_VERMAGIC ""
64351 #endif
64352
64353+#ifdef CONFIG_PAX_REFCOUNT
64354+#define MODULE_PAX_REFCOUNT "REFCOUNT "
64355+#else
64356+#define MODULE_PAX_REFCOUNT ""
64357+#endif
64358+
64359+#ifdef CONSTIFY_PLUGIN
64360+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
64361+#else
64362+#define MODULE_CONSTIFY_PLUGIN ""
64363+#endif
64364+
64365+#ifdef STACKLEAK_PLUGIN
64366+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
64367+#else
64368+#define MODULE_STACKLEAK_PLUGIN ""
64369+#endif
64370+
64371+#ifdef CONFIG_GRKERNSEC
64372+#define MODULE_GRSEC "GRSEC "
64373+#else
64374+#define MODULE_GRSEC ""
64375+#endif
64376+
64377 #define VERMAGIC_STRING \
64378 UTS_RELEASE " " \
64379 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
64380 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
64381- MODULE_ARCH_VERMAGIC
64382+ MODULE_ARCH_VERMAGIC \
64383+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
64384+ MODULE_GRSEC
64385
64386diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
64387index dcdfc2b..ec79ab5 100644
64388--- a/include/linux/vmalloc.h
64389+++ b/include/linux/vmalloc.h
64390@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
64391 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
64392 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
64393 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
64394+
64395+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
64396+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
64397+#endif
64398+
64399 /* bits [20..32] reserved for arch specific ioremap internals */
64400
64401 /*
64402@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
64403 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
64404 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
64405 unsigned long start, unsigned long end, gfp_t gfp_mask,
64406- pgprot_t prot, int node, void *caller);
64407+ pgprot_t prot, int node, void *caller) __size_overflow(1);
64408 extern void vfree(const void *addr);
64409
64410 extern void *vmap(struct page **pages, unsigned int count,
64411@@ -123,8 +128,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
64412 extern void free_vm_area(struct vm_struct *area);
64413
64414 /* for /dev/kmem */
64415-extern long vread(char *buf, char *addr, unsigned long count);
64416-extern long vwrite(char *buf, char *addr, unsigned long count);
64417+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
64418+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
64419
64420 /*
64421 * Internals. Dont't use..
64422diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
64423index 65efb92..137adbb 100644
64424--- a/include/linux/vmstat.h
64425+++ b/include/linux/vmstat.h
64426@@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
64427 /*
64428 * Zone based page accounting with per cpu differentials.
64429 */
64430-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64431+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64432
64433 static inline void zone_page_state_add(long x, struct zone *zone,
64434 enum zone_stat_item item)
64435 {
64436- atomic_long_add(x, &zone->vm_stat[item]);
64437- atomic_long_add(x, &vm_stat[item]);
64438+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
64439+ atomic_long_add_unchecked(x, &vm_stat[item]);
64440 }
64441
64442 static inline unsigned long global_page_state(enum zone_stat_item item)
64443 {
64444- long x = atomic_long_read(&vm_stat[item]);
64445+ long x = atomic_long_read_unchecked(&vm_stat[item]);
64446 #ifdef CONFIG_SMP
64447 if (x < 0)
64448 x = 0;
64449@@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
64450 static inline unsigned long zone_page_state(struct zone *zone,
64451 enum zone_stat_item item)
64452 {
64453- long x = atomic_long_read(&zone->vm_stat[item]);
64454+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64455 #ifdef CONFIG_SMP
64456 if (x < 0)
64457 x = 0;
64458@@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
64459 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
64460 enum zone_stat_item item)
64461 {
64462- long x = atomic_long_read(&zone->vm_stat[item]);
64463+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64464
64465 #ifdef CONFIG_SMP
64466 int cpu;
64467@@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
64468
64469 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
64470 {
64471- atomic_long_inc(&zone->vm_stat[item]);
64472- atomic_long_inc(&vm_stat[item]);
64473+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
64474+ atomic_long_inc_unchecked(&vm_stat[item]);
64475 }
64476
64477 static inline void __inc_zone_page_state(struct page *page,
64478@@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
64479
64480 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
64481 {
64482- atomic_long_dec(&zone->vm_stat[item]);
64483- atomic_long_dec(&vm_stat[item]);
64484+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
64485+ atomic_long_dec_unchecked(&vm_stat[item]);
64486 }
64487
64488 static inline void __dec_zone_page_state(struct page *page,
64489diff --git a/include/linux/xattr.h b/include/linux/xattr.h
64490index e5d1220..ef6e406 100644
64491--- a/include/linux/xattr.h
64492+++ b/include/linux/xattr.h
64493@@ -57,6 +57,11 @@
64494 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
64495 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
64496
64497+/* User namespace */
64498+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
64499+#define XATTR_PAX_FLAGS_SUFFIX "flags"
64500+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
64501+
64502 #ifdef __KERNEL__
64503
64504 #include <linux/types.h>
64505diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
64506index 944ecdf..a3994fc 100644
64507--- a/include/media/saa7146_vv.h
64508+++ b/include/media/saa7146_vv.h
64509@@ -161,8 +161,8 @@ struct saa7146_ext_vv
64510 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
64511
64512 /* the extension can override this */
64513- struct v4l2_ioctl_ops vid_ops;
64514- struct v4l2_ioctl_ops vbi_ops;
64515+ v4l2_ioctl_ops_no_const vid_ops;
64516+ v4l2_ioctl_ops_no_const vbi_ops;
64517 /* pointer to the saa7146 core ops */
64518 const struct v4l2_ioctl_ops *core_ops;
64519
64520diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
64521index a056e6e..31023a5 100644
64522--- a/include/media/v4l2-dev.h
64523+++ b/include/media/v4l2-dev.h
64524@@ -73,7 +73,8 @@ struct v4l2_file_operations {
64525 int (*mmap) (struct file *, struct vm_area_struct *);
64526 int (*open) (struct file *);
64527 int (*release) (struct file *);
64528-};
64529+} __do_const;
64530+typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
64531
64532 /*
64533 * Newer version of video_device, handled by videodev2.c
64534diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
64535index d8b76f7..7d5aa18 100644
64536--- a/include/media/v4l2-ioctl.h
64537+++ b/include/media/v4l2-ioctl.h
64538@@ -287,7 +287,7 @@ struct v4l2_ioctl_ops {
64539 long (*vidioc_default) (struct file *file, void *fh,
64540 bool valid_prio, int cmd, void *arg);
64541 };
64542-
64543+typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
64544
64545 /* v4l debugging and diagnostics */
64546
64547diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
64548index 439dadc..1c67e3f 100644
64549--- a/include/net/caif/caif_hsi.h
64550+++ b/include/net/caif/caif_hsi.h
64551@@ -98,7 +98,7 @@ struct cfhsi_drv {
64552 void (*rx_done_cb) (struct cfhsi_drv *drv);
64553 void (*wake_up_cb) (struct cfhsi_drv *drv);
64554 void (*wake_down_cb) (struct cfhsi_drv *drv);
64555-};
64556+} __no_const;
64557
64558 /* Structure implemented by HSI device. */
64559 struct cfhsi_dev {
64560diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
64561index 9e5425b..8136ffc 100644
64562--- a/include/net/caif/cfctrl.h
64563+++ b/include/net/caif/cfctrl.h
64564@@ -52,7 +52,7 @@ struct cfctrl_rsp {
64565 void (*radioset_rsp)(void);
64566 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
64567 struct cflayer *client_layer);
64568-};
64569+} __no_const;
64570
64571 /* Link Setup Parameters for CAIF-Links. */
64572 struct cfctrl_link_param {
64573@@ -101,8 +101,8 @@ struct cfctrl_request_info {
64574 struct cfctrl {
64575 struct cfsrvl serv;
64576 struct cfctrl_rsp res;
64577- atomic_t req_seq_no;
64578- atomic_t rsp_seq_no;
64579+ atomic_unchecked_t req_seq_no;
64580+ atomic_unchecked_t rsp_seq_no;
64581 struct list_head list;
64582 /* Protects from simultaneous access to first_req list */
64583 spinlock_t info_list_lock;
64584diff --git a/include/net/flow.h b/include/net/flow.h
64585index 6c469db..7743b8e 100644
64586--- a/include/net/flow.h
64587+++ b/include/net/flow.h
64588@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
64589
64590 extern void flow_cache_flush(void);
64591 extern void flow_cache_flush_deferred(void);
64592-extern atomic_t flow_cache_genid;
64593+extern atomic_unchecked_t flow_cache_genid;
64594
64595 #endif
64596diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
64597index 2040bff..f4c0733 100644
64598--- a/include/net/inetpeer.h
64599+++ b/include/net/inetpeer.h
64600@@ -51,8 +51,8 @@ struct inet_peer {
64601 */
64602 union {
64603 struct {
64604- atomic_t rid; /* Frag reception counter */
64605- atomic_t ip_id_count; /* IP ID for the next packet */
64606+ atomic_unchecked_t rid; /* Frag reception counter */
64607+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
64608 __u32 tcp_ts;
64609 __u32 tcp_ts_stamp;
64610 };
64611@@ -118,11 +118,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
64612 more++;
64613 inet_peer_refcheck(p);
64614 do {
64615- old = atomic_read(&p->ip_id_count);
64616+ old = atomic_read_unchecked(&p->ip_id_count);
64617 new = old + more;
64618 if (!new)
64619 new = 1;
64620- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
64621+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
64622 return new;
64623 }
64624
64625diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
64626index 78df0866..00e5c9b 100644
64627--- a/include/net/ip_fib.h
64628+++ b/include/net/ip_fib.h
64629@@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
64630
64631 #define FIB_RES_SADDR(net, res) \
64632 ((FIB_RES_NH(res).nh_saddr_genid == \
64633- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
64634+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
64635 FIB_RES_NH(res).nh_saddr : \
64636 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
64637 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
64638diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
64639index 95374d1..2300e36 100644
64640--- a/include/net/ip_vs.h
64641+++ b/include/net/ip_vs.h
64642@@ -510,7 +510,7 @@ struct ip_vs_conn {
64643 struct ip_vs_conn *control; /* Master control connection */
64644 atomic_t n_control; /* Number of controlled ones */
64645 struct ip_vs_dest *dest; /* real server */
64646- atomic_t in_pkts; /* incoming packet counter */
64647+ atomic_unchecked_t in_pkts; /* incoming packet counter */
64648
64649 /* packet transmitter for different forwarding methods. If it
64650 mangles the packet, it must return NF_DROP or better NF_STOLEN,
64651@@ -648,7 +648,7 @@ struct ip_vs_dest {
64652 __be16 port; /* port number of the server */
64653 union nf_inet_addr addr; /* IP address of the server */
64654 volatile unsigned int flags; /* dest status flags */
64655- atomic_t conn_flags; /* flags to copy to conn */
64656+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
64657 atomic_t weight; /* server weight */
64658
64659 atomic_t refcnt; /* reference counter */
64660diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
64661index 69b610a..fe3962c 100644
64662--- a/include/net/irda/ircomm_core.h
64663+++ b/include/net/irda/ircomm_core.h
64664@@ -51,7 +51,7 @@ typedef struct {
64665 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
64666 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
64667 struct ircomm_info *);
64668-} call_t;
64669+} __no_const call_t;
64670
64671 struct ircomm_cb {
64672 irda_queue_t queue;
64673diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
64674index 59ba38bc..d515662 100644
64675--- a/include/net/irda/ircomm_tty.h
64676+++ b/include/net/irda/ircomm_tty.h
64677@@ -35,6 +35,7 @@
64678 #include <linux/termios.h>
64679 #include <linux/timer.h>
64680 #include <linux/tty.h> /* struct tty_struct */
64681+#include <asm/local.h>
64682
64683 #include <net/irda/irias_object.h>
64684 #include <net/irda/ircomm_core.h>
64685@@ -105,8 +106,8 @@ struct ircomm_tty_cb {
64686 unsigned short close_delay;
64687 unsigned short closing_wait; /* time to wait before closing */
64688
64689- int open_count;
64690- int blocked_open; /* # of blocked opens */
64691+ local_t open_count;
64692+ local_t blocked_open; /* # of blocked opens */
64693
64694 /* Protect concurent access to :
64695 * o self->open_count
64696diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
64697index cc7c197..9f2da2a 100644
64698--- a/include/net/iucv/af_iucv.h
64699+++ b/include/net/iucv/af_iucv.h
64700@@ -141,7 +141,7 @@ struct iucv_sock {
64701 struct iucv_sock_list {
64702 struct hlist_head head;
64703 rwlock_t lock;
64704- atomic_t autobind_name;
64705+ atomic_unchecked_t autobind_name;
64706 };
64707
64708 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
64709diff --git a/include/net/neighbour.h b/include/net/neighbour.h
64710index 6cdfeed..55a0256 100644
64711--- a/include/net/neighbour.h
64712+++ b/include/net/neighbour.h
64713@@ -123,7 +123,7 @@ struct neigh_ops {
64714 void (*error_report)(struct neighbour *, struct sk_buff *);
64715 int (*output)(struct neighbour *, struct sk_buff *);
64716 int (*connected_output)(struct neighbour *, struct sk_buff *);
64717-};
64718+} __do_const;
64719
64720 struct pneigh_entry {
64721 struct pneigh_entry *next;
64722diff --git a/include/net/netlink.h b/include/net/netlink.h
64723index 785f37a..c81dc0c 100644
64724--- a/include/net/netlink.h
64725+++ b/include/net/netlink.h
64726@@ -520,7 +520,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
64727 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
64728 {
64729 if (mark)
64730- skb_trim(skb, (unsigned char *) mark - skb->data);
64731+ skb_trim(skb, (const unsigned char *) mark - skb->data);
64732 }
64733
64734 /**
64735diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
64736index bbd023a..97c6d0d 100644
64737--- a/include/net/netns/ipv4.h
64738+++ b/include/net/netns/ipv4.h
64739@@ -57,8 +57,8 @@ struct netns_ipv4 {
64740 unsigned int sysctl_ping_group_range[2];
64741 long sysctl_tcp_mem[3];
64742
64743- atomic_t rt_genid;
64744- atomic_t dev_addr_genid;
64745+ atomic_unchecked_t rt_genid;
64746+ atomic_unchecked_t dev_addr_genid;
64747
64748 #ifdef CONFIG_IP_MROUTE
64749 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
64750diff --git a/include/net/scm.h b/include/net/scm.h
64751index d456f4c..0c0017c 100644
64752--- a/include/net/scm.h
64753+++ b/include/net/scm.h
64754@@ -71,9 +71,11 @@ static __inline__ void scm_destroy(struct scm_cookie *scm)
64755 }
64756
64757 static __inline__ int scm_send(struct socket *sock, struct msghdr *msg,
64758- struct scm_cookie *scm)
64759+ struct scm_cookie *scm, bool forcecreds)
64760 {
64761 memset(scm, 0, sizeof(*scm));
64762+ if (forcecreds)
64763+ scm_set_cred(scm, task_tgid(current), current_cred());
64764 unix_get_peersec_dgram(sock, scm);
64765 if (msg->msg_controllen <= 0)
64766 return 0;
64767diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
64768index a2ef814..31a8e3f 100644
64769--- a/include/net/sctp/sctp.h
64770+++ b/include/net/sctp/sctp.h
64771@@ -318,9 +318,9 @@ do { \
64772
64773 #else /* SCTP_DEBUG */
64774
64775-#define SCTP_DEBUG_PRINTK(whatever...)
64776-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
64777-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
64778+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
64779+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
64780+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
64781 #define SCTP_ENABLE_DEBUG
64782 #define SCTP_DISABLE_DEBUG
64783 #define SCTP_ASSERT(expr, str, func)
64784diff --git a/include/net/sock.h b/include/net/sock.h
64785index 4a45216..7af2578 100644
64786--- a/include/net/sock.h
64787+++ b/include/net/sock.h
64788@@ -303,7 +303,7 @@ struct sock {
64789 #ifdef CONFIG_RPS
64790 __u32 sk_rxhash;
64791 #endif
64792- atomic_t sk_drops;
64793+ atomic_unchecked_t sk_drops;
64794 int sk_rcvbuf;
64795
64796 struct sk_filter __rcu *sk_filter;
64797@@ -1726,7 +1726,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
64798 }
64799
64800 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
64801- char __user *from, char *to,
64802+ char __user *from, unsigned char *to,
64803 int copy, int offset)
64804 {
64805 if (skb->ip_summed == CHECKSUM_NONE) {
64806diff --git a/include/net/tcp.h b/include/net/tcp.h
64807index e79aa48..9929421 100644
64808--- a/include/net/tcp.h
64809+++ b/include/net/tcp.h
64810@@ -1459,7 +1459,7 @@ struct tcp_seq_afinfo {
64811 char *name;
64812 sa_family_t family;
64813 const struct file_operations *seq_fops;
64814- struct seq_operations seq_ops;
64815+ seq_operations_no_const seq_ops;
64816 };
64817
64818 struct tcp_iter_state {
64819diff --git a/include/net/udp.h b/include/net/udp.h
64820index 065f379..b661b40 100644
64821--- a/include/net/udp.h
64822+++ b/include/net/udp.h
64823@@ -244,7 +244,7 @@ struct udp_seq_afinfo {
64824 sa_family_t family;
64825 struct udp_table *udp_table;
64826 const struct file_operations *seq_fops;
64827- struct seq_operations seq_ops;
64828+ seq_operations_no_const seq_ops;
64829 };
64830
64831 struct udp_iter_state {
64832diff --git a/include/net/xfrm.h b/include/net/xfrm.h
64833index e0a55df..5890bca07 100644
64834--- a/include/net/xfrm.h
64835+++ b/include/net/xfrm.h
64836@@ -505,7 +505,7 @@ struct xfrm_policy {
64837 struct timer_list timer;
64838
64839 struct flow_cache_object flo;
64840- atomic_t genid;
64841+ atomic_unchecked_t genid;
64842 u32 priority;
64843 u32 index;
64844 struct xfrm_mark mark;
64845diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
64846index 1a046b1..ee0bef0 100644
64847--- a/include/rdma/iw_cm.h
64848+++ b/include/rdma/iw_cm.h
64849@@ -122,7 +122,7 @@ struct iw_cm_verbs {
64850 int backlog);
64851
64852 int (*destroy_listen)(struct iw_cm_id *cm_id);
64853-};
64854+} __no_const;
64855
64856 /**
64857 * iw_create_cm_id - Create an IW CM identifier.
64858diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
64859index 8f9dfba..610ab6c 100644
64860--- a/include/scsi/libfc.h
64861+++ b/include/scsi/libfc.h
64862@@ -756,6 +756,7 @@ struct libfc_function_template {
64863 */
64864 void (*disc_stop_final) (struct fc_lport *);
64865 };
64866+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
64867
64868 /**
64869 * struct fc_disc - Discovery context
64870@@ -861,7 +862,7 @@ struct fc_lport {
64871 struct fc_vport *vport;
64872
64873 /* Operational Information */
64874- struct libfc_function_template tt;
64875+ libfc_function_template_no_const tt;
64876 u8 link_up;
64877 u8 qfull;
64878 enum fc_lport_state state;
64879diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
64880index ba96988..ecf2eb9 100644
64881--- a/include/scsi/scsi_device.h
64882+++ b/include/scsi/scsi_device.h
64883@@ -163,9 +163,9 @@ struct scsi_device {
64884 unsigned int max_device_blocked; /* what device_blocked counts down from */
64885 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
64886
64887- atomic_t iorequest_cnt;
64888- atomic_t iodone_cnt;
64889- atomic_t ioerr_cnt;
64890+ atomic_unchecked_t iorequest_cnt;
64891+ atomic_unchecked_t iodone_cnt;
64892+ atomic_unchecked_t ioerr_cnt;
64893
64894 struct device sdev_gendev,
64895 sdev_dev;
64896diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
64897index 719faf1..07b6728 100644
64898--- a/include/scsi/scsi_transport_fc.h
64899+++ b/include/scsi/scsi_transport_fc.h
64900@@ -739,7 +739,8 @@ struct fc_function_template {
64901 unsigned long show_host_system_hostname:1;
64902
64903 unsigned long disable_target_scan:1;
64904-};
64905+} __do_const;
64906+typedef struct fc_function_template __no_const fc_function_template_no_const;
64907
64908
64909 /**
64910diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
64911index 030b87c..98a6954 100644
64912--- a/include/sound/ak4xxx-adda.h
64913+++ b/include/sound/ak4xxx-adda.h
64914@@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
64915 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
64916 unsigned char val);
64917 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
64918-};
64919+} __no_const;
64920
64921 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
64922
64923diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
64924index 8c05e47..2b5df97 100644
64925--- a/include/sound/hwdep.h
64926+++ b/include/sound/hwdep.h
64927@@ -49,7 +49,7 @@ struct snd_hwdep_ops {
64928 struct snd_hwdep_dsp_status *status);
64929 int (*dsp_load)(struct snd_hwdep *hw,
64930 struct snd_hwdep_dsp_image *image);
64931-};
64932+} __no_const;
64933
64934 struct snd_hwdep {
64935 struct snd_card *card;
64936diff --git a/include/sound/info.h b/include/sound/info.h
64937index 9ca1a49..aba1728 100644
64938--- a/include/sound/info.h
64939+++ b/include/sound/info.h
64940@@ -44,7 +44,7 @@ struct snd_info_entry_text {
64941 struct snd_info_buffer *buffer);
64942 void (*write)(struct snd_info_entry *entry,
64943 struct snd_info_buffer *buffer);
64944-};
64945+} __no_const;
64946
64947 struct snd_info_entry_ops {
64948 int (*open)(struct snd_info_entry *entry,
64949diff --git a/include/sound/pcm.h b/include/sound/pcm.h
64950index 0d11128..814178e 100644
64951--- a/include/sound/pcm.h
64952+++ b/include/sound/pcm.h
64953@@ -81,6 +81,7 @@ struct snd_pcm_ops {
64954 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
64955 int (*ack)(struct snd_pcm_substream *substream);
64956 };
64957+typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
64958
64959 /*
64960 *
64961diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
64962index af1b49e..a5d55a5 100644
64963--- a/include/sound/sb16_csp.h
64964+++ b/include/sound/sb16_csp.h
64965@@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
64966 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
64967 int (*csp_stop) (struct snd_sb_csp * p);
64968 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
64969-};
64970+} __no_const;
64971
64972 /*
64973 * CSP private data
64974diff --git a/include/sound/soc.h b/include/sound/soc.h
64975index c703871..f7fbbbd 100644
64976--- a/include/sound/soc.h
64977+++ b/include/sound/soc.h
64978@@ -757,7 +757,7 @@ struct snd_soc_platform_driver {
64979 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
64980 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
64981 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
64982-};
64983+} __do_const;
64984
64985 struct snd_soc_platform {
64986 const char *name;
64987@@ -949,7 +949,7 @@ struct snd_soc_pcm_runtime {
64988 struct snd_soc_dai_link *dai_link;
64989 struct mutex pcm_mutex;
64990 enum snd_soc_pcm_subclass pcm_subclass;
64991- struct snd_pcm_ops ops;
64992+ snd_pcm_ops_no_const ops;
64993
64994 unsigned int dev_registered:1;
64995
64996diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
64997index 0c3c2fb..d9d9990 100644
64998--- a/include/sound/tea575x-tuner.h
64999+++ b/include/sound/tea575x-tuner.h
65000@@ -44,7 +44,7 @@ struct snd_tea575x_ops {
65001
65002 struct snd_tea575x {
65003 struct v4l2_device *v4l2_dev;
65004- struct v4l2_file_operations fops;
65005+ v4l2_file_operations_no_const fops;
65006 struct video_device vd; /* video device */
65007 int radio_nr; /* radio_nr */
65008 bool tea5759; /* 5759 chip is present */
65009diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
65010index 4119966..1a4671c 100644
65011--- a/include/sound/ymfpci.h
65012+++ b/include/sound/ymfpci.h
65013@@ -358,7 +358,7 @@ struct snd_ymfpci {
65014 spinlock_t reg_lock;
65015 spinlock_t voice_lock;
65016 wait_queue_head_t interrupt_sleep;
65017- atomic_t interrupt_sleep_count;
65018+ atomic_unchecked_t interrupt_sleep_count;
65019 struct snd_info_entry *proc_entry;
65020 const struct firmware *dsp_microcode;
65021 const struct firmware *controller_microcode;
65022diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
65023index 362e0d9..36b9a83 100644
65024--- a/include/target/target_core_base.h
65025+++ b/include/target/target_core_base.h
65026@@ -441,7 +441,7 @@ struct t10_reservation_ops {
65027 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
65028 int (*t10_pr_register)(struct se_cmd *);
65029 int (*t10_pr_clear)(struct se_cmd *);
65030-};
65031+} __no_const;
65032
65033 struct t10_reservation {
65034 /* Reservation effects all target ports */
65035@@ -780,7 +780,7 @@ struct se_device {
65036 spinlock_t stats_lock;
65037 /* Active commands on this virtual SE device */
65038 atomic_t simple_cmds;
65039- atomic_t dev_ordered_id;
65040+ atomic_unchecked_t dev_ordered_id;
65041 atomic_t execute_tasks;
65042 atomic_t dev_ordered_sync;
65043 atomic_t dev_qf_count;
65044diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
65045new file mode 100644
65046index 0000000..2efe49d
65047--- /dev/null
65048+++ b/include/trace/events/fs.h
65049@@ -0,0 +1,53 @@
65050+#undef TRACE_SYSTEM
65051+#define TRACE_SYSTEM fs
65052+
65053+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
65054+#define _TRACE_FS_H
65055+
65056+#include <linux/fs.h>
65057+#include <linux/tracepoint.h>
65058+
65059+TRACE_EVENT(do_sys_open,
65060+
65061+ TP_PROTO(char *filename, int flags, int mode),
65062+
65063+ TP_ARGS(filename, flags, mode),
65064+
65065+ TP_STRUCT__entry(
65066+ __string( filename, filename )
65067+ __field( int, flags )
65068+ __field( int, mode )
65069+ ),
65070+
65071+ TP_fast_assign(
65072+ __assign_str(filename, filename);
65073+ __entry->flags = flags;
65074+ __entry->mode = mode;
65075+ ),
65076+
65077+ TP_printk("\"%s\" %x %o",
65078+ __get_str(filename), __entry->flags, __entry->mode)
65079+);
65080+
65081+TRACE_EVENT(open_exec,
65082+
65083+ TP_PROTO(const char *filename),
65084+
65085+ TP_ARGS(filename),
65086+
65087+ TP_STRUCT__entry(
65088+ __string( filename, filename )
65089+ ),
65090+
65091+ TP_fast_assign(
65092+ __assign_str(filename, filename);
65093+ ),
65094+
65095+ TP_printk("\"%s\"",
65096+ __get_str(filename))
65097+);
65098+
65099+#endif /* _TRACE_FS_H */
65100+
65101+/* This part must be outside protection */
65102+#include <trace/define_trace.h>
65103diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
65104index 1c09820..7f5ec79 100644
65105--- a/include/trace/events/irq.h
65106+++ b/include/trace/events/irq.h
65107@@ -36,7 +36,7 @@ struct softirq_action;
65108 */
65109 TRACE_EVENT(irq_handler_entry,
65110
65111- TP_PROTO(int irq, struct irqaction *action),
65112+ TP_PROTO(int irq, const struct irqaction *action),
65113
65114 TP_ARGS(irq, action),
65115
65116@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
65117 */
65118 TRACE_EVENT(irq_handler_exit,
65119
65120- TP_PROTO(int irq, struct irqaction *action, int ret),
65121+ TP_PROTO(int irq, const struct irqaction *action, int ret),
65122
65123 TP_ARGS(irq, action, ret),
65124
65125diff --git a/include/video/udlfb.h b/include/video/udlfb.h
65126index f9466fa..f4e2b81 100644
65127--- a/include/video/udlfb.h
65128+++ b/include/video/udlfb.h
65129@@ -53,10 +53,10 @@ struct dlfb_data {
65130 u32 pseudo_palette[256];
65131 int blank_mode; /*one of FB_BLANK_ */
65132 /* blit-only rendering path metrics, exposed through sysfs */
65133- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65134- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
65135- atomic_t bytes_sent; /* to usb, after compression including overhead */
65136- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
65137+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65138+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
65139+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
65140+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
65141 };
65142
65143 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
65144diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
65145index 0993a22..32ba2fe 100644
65146--- a/include/video/uvesafb.h
65147+++ b/include/video/uvesafb.h
65148@@ -177,6 +177,7 @@ struct uvesafb_par {
65149 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
65150 u8 pmi_setpal; /* PMI for palette changes */
65151 u16 *pmi_base; /* protected mode interface location */
65152+ u8 *pmi_code; /* protected mode code location */
65153 void *pmi_start;
65154 void *pmi_pal;
65155 u8 *vbe_state_orig; /*
65156diff --git a/init/Kconfig b/init/Kconfig
65157index d07dcf9..fa47d0e 100644
65158--- a/init/Kconfig
65159+++ b/init/Kconfig
65160@@ -835,6 +835,7 @@ endif # CGROUPS
65161
65162 config CHECKPOINT_RESTORE
65163 bool "Checkpoint/restore support" if EXPERT
65164+ depends on !GRKERNSEC
65165 default n
65166 help
65167 Enables additional kernel features in a sake of checkpoint/restore.
65168@@ -1014,6 +1015,7 @@ config UIDGID_CONVERTED
65169 # Security modules
65170 depends on SECURITY_TOMOYO = n
65171 depends on SECURITY_APPARMOR = n
65172+ depends on GRKERNSEC = n
65173
65174 config UIDGID_STRICT_TYPE_CHECKS
65175 bool "Require conversions between uid/gids and their internal representation"
65176@@ -1401,7 +1403,7 @@ config SLUB_DEBUG
65177
65178 config COMPAT_BRK
65179 bool "Disable heap randomization"
65180- default y
65181+ default n
65182 help
65183 Randomizing heap placement makes heap exploits harder, but it
65184 also breaks ancient binaries (including anything libc5 based).
65185@@ -1584,7 +1586,7 @@ config INIT_ALL_POSSIBLE
65186 config STOP_MACHINE
65187 bool
65188 default y
65189- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
65190+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
65191 help
65192 Need stop_machine() primitive.
65193
65194diff --git a/init/Makefile b/init/Makefile
65195index 7bc47ee..6da2dc7 100644
65196--- a/init/Makefile
65197+++ b/init/Makefile
65198@@ -2,6 +2,9 @@
65199 # Makefile for the linux kernel.
65200 #
65201
65202+ccflags-y := $(GCC_PLUGINS_CFLAGS)
65203+asflags-y := $(GCC_PLUGINS_AFLAGS)
65204+
65205 obj-y := main.o version.o mounts.o
65206 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
65207 obj-y += noinitramfs.o
65208diff --git a/init/do_mounts.c b/init/do_mounts.c
65209index d3f0aee..c9322f5 100644
65210--- a/init/do_mounts.c
65211+++ b/init/do_mounts.c
65212@@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
65213 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
65214 {
65215 struct super_block *s;
65216- int err = sys_mount(name, "/root", fs, flags, data);
65217+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
65218 if (err)
65219 return err;
65220
65221- sys_chdir("/root");
65222+ sys_chdir((const char __force_user *)"/root");
65223 s = current->fs->pwd.dentry->d_sb;
65224 ROOT_DEV = s->s_dev;
65225 printk(KERN_INFO
65226@@ -460,18 +460,18 @@ void __init change_floppy(char *fmt, ...)
65227 va_start(args, fmt);
65228 vsprintf(buf, fmt, args);
65229 va_end(args);
65230- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
65231+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
65232 if (fd >= 0) {
65233 sys_ioctl(fd, FDEJECT, 0);
65234 sys_close(fd);
65235 }
65236 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
65237- fd = sys_open("/dev/console", O_RDWR, 0);
65238+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
65239 if (fd >= 0) {
65240 sys_ioctl(fd, TCGETS, (long)&termios);
65241 termios.c_lflag &= ~ICANON;
65242 sys_ioctl(fd, TCSETSF, (long)&termios);
65243- sys_read(fd, &c, 1);
65244+ sys_read(fd, (char __user *)&c, 1);
65245 termios.c_lflag |= ICANON;
65246 sys_ioctl(fd, TCSETSF, (long)&termios);
65247 sys_close(fd);
65248@@ -565,6 +565,6 @@ void __init prepare_namespace(void)
65249 mount_root();
65250 out:
65251 devtmpfs_mount("dev");
65252- sys_mount(".", "/", NULL, MS_MOVE, NULL);
65253- sys_chroot(".");
65254+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65255+ sys_chroot((const char __force_user *)".");
65256 }
65257diff --git a/init/do_mounts.h b/init/do_mounts.h
65258index f5b978a..69dbfe8 100644
65259--- a/init/do_mounts.h
65260+++ b/init/do_mounts.h
65261@@ -15,15 +15,15 @@ extern int root_mountflags;
65262
65263 static inline int create_dev(char *name, dev_t dev)
65264 {
65265- sys_unlink(name);
65266- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
65267+ sys_unlink((char __force_user *)name);
65268+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
65269 }
65270
65271 #if BITS_PER_LONG == 32
65272 static inline u32 bstat(char *name)
65273 {
65274 struct stat64 stat;
65275- if (sys_stat64(name, &stat) != 0)
65276+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
65277 return 0;
65278 if (!S_ISBLK(stat.st_mode))
65279 return 0;
65280@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
65281 static inline u32 bstat(char *name)
65282 {
65283 struct stat stat;
65284- if (sys_newstat(name, &stat) != 0)
65285+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
65286 return 0;
65287 if (!S_ISBLK(stat.st_mode))
65288 return 0;
65289diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
65290index 135959a2..28a3f43 100644
65291--- a/init/do_mounts_initrd.c
65292+++ b/init/do_mounts_initrd.c
65293@@ -53,13 +53,13 @@ static void __init handle_initrd(void)
65294 create_dev("/dev/root.old", Root_RAM0);
65295 /* mount initrd on rootfs' /root */
65296 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
65297- sys_mkdir("/old", 0700);
65298- root_fd = sys_open("/", 0, 0);
65299- old_fd = sys_open("/old", 0, 0);
65300+ sys_mkdir((const char __force_user *)"/old", 0700);
65301+ root_fd = sys_open((const char __force_user *)"/", 0, 0);
65302+ old_fd = sys_open((const char __force_user *)"/old", 0, 0);
65303 /* move initrd over / and chdir/chroot in initrd root */
65304- sys_chdir("/root");
65305- sys_mount(".", "/", NULL, MS_MOVE, NULL);
65306- sys_chroot(".");
65307+ sys_chdir((const char __force_user *)"/root");
65308+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65309+ sys_chroot((const char __force_user *)".");
65310
65311 /*
65312 * In case that a resume from disk is carried out by linuxrc or one of
65313@@ -76,15 +76,15 @@ static void __init handle_initrd(void)
65314
65315 /* move initrd to rootfs' /old */
65316 sys_fchdir(old_fd);
65317- sys_mount("/", ".", NULL, MS_MOVE, NULL);
65318+ sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
65319 /* switch root and cwd back to / of rootfs */
65320 sys_fchdir(root_fd);
65321- sys_chroot(".");
65322+ sys_chroot((const char __force_user *)".");
65323 sys_close(old_fd);
65324 sys_close(root_fd);
65325
65326 if (new_decode_dev(real_root_dev) == Root_RAM0) {
65327- sys_chdir("/old");
65328+ sys_chdir((const char __force_user *)"/old");
65329 return;
65330 }
65331
65332@@ -92,17 +92,17 @@ static void __init handle_initrd(void)
65333 mount_root();
65334
65335 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
65336- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
65337+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
65338 if (!error)
65339 printk("okay\n");
65340 else {
65341- int fd = sys_open("/dev/root.old", O_RDWR, 0);
65342+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
65343 if (error == -ENOENT)
65344 printk("/initrd does not exist. Ignored.\n");
65345 else
65346 printk("failed\n");
65347 printk(KERN_NOTICE "Unmounting old root\n");
65348- sys_umount("/old", MNT_DETACH);
65349+ sys_umount((char __force_user *)"/old", MNT_DETACH);
65350 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
65351 if (fd < 0) {
65352 error = fd;
65353@@ -125,11 +125,11 @@ int __init initrd_load(void)
65354 * mounted in the normal path.
65355 */
65356 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
65357- sys_unlink("/initrd.image");
65358+ sys_unlink((const char __force_user *)"/initrd.image");
65359 handle_initrd();
65360 return 1;
65361 }
65362 }
65363- sys_unlink("/initrd.image");
65364+ sys_unlink((const char __force_user *)"/initrd.image");
65365 return 0;
65366 }
65367diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
65368index 8cb6db5..d729f50 100644
65369--- a/init/do_mounts_md.c
65370+++ b/init/do_mounts_md.c
65371@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
65372 partitioned ? "_d" : "", minor,
65373 md_setup_args[ent].device_names);
65374
65375- fd = sys_open(name, 0, 0);
65376+ fd = sys_open((char __force_user *)name, 0, 0);
65377 if (fd < 0) {
65378 printk(KERN_ERR "md: open failed - cannot start "
65379 "array %s\n", name);
65380@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
65381 * array without it
65382 */
65383 sys_close(fd);
65384- fd = sys_open(name, 0, 0);
65385+ fd = sys_open((char __force_user *)name, 0, 0);
65386 sys_ioctl(fd, BLKRRPART, 0);
65387 }
65388 sys_close(fd);
65389@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
65390
65391 wait_for_device_probe();
65392
65393- fd = sys_open("/dev/md0", 0, 0);
65394+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
65395 if (fd >= 0) {
65396 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
65397 sys_close(fd);
65398diff --git a/init/init_task.c b/init/init_task.c
65399index 8b2f399..f0797c9 100644
65400--- a/init/init_task.c
65401+++ b/init/init_task.c
65402@@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
65403 * Initial thread structure. Alignment of this is handled by a special
65404 * linker map entry.
65405 */
65406+#ifdef CONFIG_X86
65407+union thread_union init_thread_union __init_task_data;
65408+#else
65409 union thread_union init_thread_union __init_task_data =
65410 { INIT_THREAD_INFO(init_task) };
65411+#endif
65412diff --git a/init/initramfs.c b/init/initramfs.c
65413index 84c6bf1..8899338 100644
65414--- a/init/initramfs.c
65415+++ b/init/initramfs.c
65416@@ -84,7 +84,7 @@ static void __init free_hash(void)
65417 }
65418 }
65419
65420-static long __init do_utime(char *filename, time_t mtime)
65421+static long __init do_utime(char __force_user *filename, time_t mtime)
65422 {
65423 struct timespec t[2];
65424
65425@@ -119,7 +119,7 @@ static void __init dir_utime(void)
65426 struct dir_entry *de, *tmp;
65427 list_for_each_entry_safe(de, tmp, &dir_list, list) {
65428 list_del(&de->list);
65429- do_utime(de->name, de->mtime);
65430+ do_utime((char __force_user *)de->name, de->mtime);
65431 kfree(de->name);
65432 kfree(de);
65433 }
65434@@ -281,7 +281,7 @@ static int __init maybe_link(void)
65435 if (nlink >= 2) {
65436 char *old = find_link(major, minor, ino, mode, collected);
65437 if (old)
65438- return (sys_link(old, collected) < 0) ? -1 : 1;
65439+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
65440 }
65441 return 0;
65442 }
65443@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
65444 {
65445 struct stat st;
65446
65447- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
65448+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
65449 if (S_ISDIR(st.st_mode))
65450- sys_rmdir(path);
65451+ sys_rmdir((char __force_user *)path);
65452 else
65453- sys_unlink(path);
65454+ sys_unlink((char __force_user *)path);
65455 }
65456 }
65457
65458@@ -315,7 +315,7 @@ static int __init do_name(void)
65459 int openflags = O_WRONLY|O_CREAT;
65460 if (ml != 1)
65461 openflags |= O_TRUNC;
65462- wfd = sys_open(collected, openflags, mode);
65463+ wfd = sys_open((char __force_user *)collected, openflags, mode);
65464
65465 if (wfd >= 0) {
65466 sys_fchown(wfd, uid, gid);
65467@@ -327,17 +327,17 @@ static int __init do_name(void)
65468 }
65469 }
65470 } else if (S_ISDIR(mode)) {
65471- sys_mkdir(collected, mode);
65472- sys_chown(collected, uid, gid);
65473- sys_chmod(collected, mode);
65474+ sys_mkdir((char __force_user *)collected, mode);
65475+ sys_chown((char __force_user *)collected, uid, gid);
65476+ sys_chmod((char __force_user *)collected, mode);
65477 dir_add(collected, mtime);
65478 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
65479 S_ISFIFO(mode) || S_ISSOCK(mode)) {
65480 if (maybe_link() == 0) {
65481- sys_mknod(collected, mode, rdev);
65482- sys_chown(collected, uid, gid);
65483- sys_chmod(collected, mode);
65484- do_utime(collected, mtime);
65485+ sys_mknod((char __force_user *)collected, mode, rdev);
65486+ sys_chown((char __force_user *)collected, uid, gid);
65487+ sys_chmod((char __force_user *)collected, mode);
65488+ do_utime((char __force_user *)collected, mtime);
65489 }
65490 }
65491 return 0;
65492@@ -346,15 +346,15 @@ static int __init do_name(void)
65493 static int __init do_copy(void)
65494 {
65495 if (count >= body_len) {
65496- sys_write(wfd, victim, body_len);
65497+ sys_write(wfd, (char __force_user *)victim, body_len);
65498 sys_close(wfd);
65499- do_utime(vcollected, mtime);
65500+ do_utime((char __force_user *)vcollected, mtime);
65501 kfree(vcollected);
65502 eat(body_len);
65503 state = SkipIt;
65504 return 0;
65505 } else {
65506- sys_write(wfd, victim, count);
65507+ sys_write(wfd, (char __force_user *)victim, count);
65508 body_len -= count;
65509 eat(count);
65510 return 1;
65511@@ -365,9 +365,9 @@ static int __init do_symlink(void)
65512 {
65513 collected[N_ALIGN(name_len) + body_len] = '\0';
65514 clean_path(collected, 0);
65515- sys_symlink(collected + N_ALIGN(name_len), collected);
65516- sys_lchown(collected, uid, gid);
65517- do_utime(collected, mtime);
65518+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
65519+ sys_lchown((char __force_user *)collected, uid, gid);
65520+ do_utime((char __force_user *)collected, mtime);
65521 state = SkipIt;
65522 next_state = Reset;
65523 return 0;
65524diff --git a/init/main.c b/init/main.c
65525index b5cc0a7..5605c91 100644
65526--- a/init/main.c
65527+++ b/init/main.c
65528@@ -95,6 +95,8 @@ static inline void mark_rodata_ro(void) { }
65529 extern void tc_init(void);
65530 #endif
65531
65532+extern void grsecurity_init(void);
65533+
65534 /*
65535 * Debug helper: via this flag we know that we are in 'early bootup code'
65536 * where only the boot processor is running with IRQ disabled. This means
65537@@ -148,6 +150,49 @@ static int __init set_reset_devices(char *str)
65538
65539 __setup("reset_devices", set_reset_devices);
65540
65541+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
65542+extern char pax_enter_kernel_user[];
65543+extern char pax_exit_kernel_user[];
65544+extern pgdval_t clone_pgd_mask;
65545+#endif
65546+
65547+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
65548+static int __init setup_pax_nouderef(char *str)
65549+{
65550+#ifdef CONFIG_X86_32
65551+ unsigned int cpu;
65552+ struct desc_struct *gdt;
65553+
65554+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
65555+ gdt = get_cpu_gdt_table(cpu);
65556+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
65557+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
65558+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
65559+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
65560+ }
65561+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
65562+#else
65563+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
65564+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
65565+ clone_pgd_mask = ~(pgdval_t)0UL;
65566+#endif
65567+
65568+ return 0;
65569+}
65570+early_param("pax_nouderef", setup_pax_nouderef);
65571+#endif
65572+
65573+#ifdef CONFIG_PAX_SOFTMODE
65574+int pax_softmode;
65575+
65576+static int __init setup_pax_softmode(char *str)
65577+{
65578+ get_option(&str, &pax_softmode);
65579+ return 1;
65580+}
65581+__setup("pax_softmode=", setup_pax_softmode);
65582+#endif
65583+
65584 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
65585 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
65586 static const char *panic_later, *panic_param;
65587@@ -674,6 +719,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
65588 {
65589 int count = preempt_count();
65590 int ret;
65591+ const char *msg1 = "", *msg2 = "";
65592
65593 if (initcall_debug)
65594 ret = do_one_initcall_debug(fn);
65595@@ -686,15 +732,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
65596 sprintf(msgbuf, "error code %d ", ret);
65597
65598 if (preempt_count() != count) {
65599- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
65600+ msg1 = " preemption imbalance";
65601 preempt_count() = count;
65602 }
65603 if (irqs_disabled()) {
65604- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
65605+ msg2 = " disabled interrupts";
65606 local_irq_enable();
65607 }
65608- if (msgbuf[0]) {
65609- printk("initcall %pF returned with %s\n", fn, msgbuf);
65610+ if (msgbuf[0] || *msg1 || *msg2) {
65611+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
65612 }
65613
65614 return ret;
65615@@ -747,8 +793,14 @@ static void __init do_initcall_level(int level)
65616 level, level,
65617 &repair_env_string);
65618
65619- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
65620+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
65621 do_one_initcall(*fn);
65622+
65623+#ifdef CONFIG_PAX_LATENT_ENTROPY
65624+ transfer_latent_entropy();
65625+#endif
65626+
65627+ }
65628 }
65629
65630 static void __init do_initcalls(void)
65631@@ -782,8 +834,14 @@ static void __init do_pre_smp_initcalls(void)
65632 {
65633 initcall_t *fn;
65634
65635- for (fn = __initcall_start; fn < __initcall0_start; fn++)
65636+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
65637 do_one_initcall(*fn);
65638+
65639+#ifdef CONFIG_PAX_LATENT_ENTROPY
65640+ transfer_latent_entropy();
65641+#endif
65642+
65643+ }
65644 }
65645
65646 static void run_init_process(const char *init_filename)
65647@@ -865,7 +923,7 @@ static int __init kernel_init(void * unused)
65648 do_basic_setup();
65649
65650 /* Open the /dev/console on the rootfs, this should never fail */
65651- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
65652+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
65653 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
65654
65655 (void) sys_dup(0);
65656@@ -878,11 +936,13 @@ static int __init kernel_init(void * unused)
65657 if (!ramdisk_execute_command)
65658 ramdisk_execute_command = "/init";
65659
65660- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
65661+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
65662 ramdisk_execute_command = NULL;
65663 prepare_namespace();
65664 }
65665
65666+ grsecurity_init();
65667+
65668 /*
65669 * Ok, we have completed the initial bootup, and
65670 * we're essentially up and running. Get rid of the
65671diff --git a/ipc/mqueue.c b/ipc/mqueue.c
65672index 8ce5769..4666884 100644
65673--- a/ipc/mqueue.c
65674+++ b/ipc/mqueue.c
65675@@ -279,6 +279,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
65676 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
65677 info->attr.mq_msgsize);
65678
65679+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
65680 spin_lock(&mq_lock);
65681 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
65682 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
65683diff --git a/ipc/msg.c b/ipc/msg.c
65684index 7385de2..a8180e08 100644
65685--- a/ipc/msg.c
65686+++ b/ipc/msg.c
65687@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
65688 return security_msg_queue_associate(msq, msgflg);
65689 }
65690
65691+static struct ipc_ops msg_ops = {
65692+ .getnew = newque,
65693+ .associate = msg_security,
65694+ .more_checks = NULL
65695+};
65696+
65697 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
65698 {
65699 struct ipc_namespace *ns;
65700- struct ipc_ops msg_ops;
65701 struct ipc_params msg_params;
65702
65703 ns = current->nsproxy->ipc_ns;
65704
65705- msg_ops.getnew = newque;
65706- msg_ops.associate = msg_security;
65707- msg_ops.more_checks = NULL;
65708-
65709 msg_params.key = key;
65710 msg_params.flg = msgflg;
65711
65712diff --git a/ipc/sem.c b/ipc/sem.c
65713index 5215a81..cfc0cac 100644
65714--- a/ipc/sem.c
65715+++ b/ipc/sem.c
65716@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
65717 return 0;
65718 }
65719
65720+static struct ipc_ops sem_ops = {
65721+ .getnew = newary,
65722+ .associate = sem_security,
65723+ .more_checks = sem_more_checks
65724+};
65725+
65726 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65727 {
65728 struct ipc_namespace *ns;
65729- struct ipc_ops sem_ops;
65730 struct ipc_params sem_params;
65731
65732 ns = current->nsproxy->ipc_ns;
65733@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65734 if (nsems < 0 || nsems > ns->sc_semmsl)
65735 return -EINVAL;
65736
65737- sem_ops.getnew = newary;
65738- sem_ops.associate = sem_security;
65739- sem_ops.more_checks = sem_more_checks;
65740-
65741 sem_params.key = key;
65742 sem_params.flg = semflg;
65743 sem_params.u.nsems = nsems;
65744diff --git a/ipc/shm.c b/ipc/shm.c
65745index 41c1285..cf6404c 100644
65746--- a/ipc/shm.c
65747+++ b/ipc/shm.c
65748@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
65749 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
65750 #endif
65751
65752+#ifdef CONFIG_GRKERNSEC
65753+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65754+ const time_t shm_createtime, const uid_t cuid,
65755+ const int shmid);
65756+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65757+ const time_t shm_createtime);
65758+#endif
65759+
65760 void shm_init_ns(struct ipc_namespace *ns)
65761 {
65762 ns->shm_ctlmax = SHMMAX;
65763@@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
65764 shp->shm_lprid = 0;
65765 shp->shm_atim = shp->shm_dtim = 0;
65766 shp->shm_ctim = get_seconds();
65767+#ifdef CONFIG_GRKERNSEC
65768+ {
65769+ struct timespec timeval;
65770+ do_posix_clock_monotonic_gettime(&timeval);
65771+
65772+ shp->shm_createtime = timeval.tv_sec;
65773+ }
65774+#endif
65775 shp->shm_segsz = size;
65776 shp->shm_nattch = 0;
65777 shp->shm_file = file;
65778@@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
65779 return 0;
65780 }
65781
65782+static struct ipc_ops shm_ops = {
65783+ .getnew = newseg,
65784+ .associate = shm_security,
65785+ .more_checks = shm_more_checks
65786+};
65787+
65788 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
65789 {
65790 struct ipc_namespace *ns;
65791- struct ipc_ops shm_ops;
65792 struct ipc_params shm_params;
65793
65794 ns = current->nsproxy->ipc_ns;
65795
65796- shm_ops.getnew = newseg;
65797- shm_ops.associate = shm_security;
65798- shm_ops.more_checks = shm_more_checks;
65799-
65800 shm_params.key = key;
65801 shm_params.flg = shmflg;
65802 shm_params.u.size = size;
65803@@ -1000,6 +1017,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65804 f_mode = FMODE_READ | FMODE_WRITE;
65805 }
65806 if (shmflg & SHM_EXEC) {
65807+
65808+#ifdef CONFIG_PAX_MPROTECT
65809+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
65810+ goto out;
65811+#endif
65812+
65813 prot |= PROT_EXEC;
65814 acc_mode |= S_IXUGO;
65815 }
65816@@ -1023,9 +1046,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65817 if (err)
65818 goto out_unlock;
65819
65820+#ifdef CONFIG_GRKERNSEC
65821+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
65822+ shp->shm_perm.cuid, shmid) ||
65823+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
65824+ err = -EACCES;
65825+ goto out_unlock;
65826+ }
65827+#endif
65828+
65829 path = shp->shm_file->f_path;
65830 path_get(&path);
65831 shp->shm_nattch++;
65832+#ifdef CONFIG_GRKERNSEC
65833+ shp->shm_lapid = current->pid;
65834+#endif
65835 size = i_size_read(path.dentry->d_inode);
65836 shm_unlock(shp);
65837
65838diff --git a/kernel/acct.c b/kernel/acct.c
65839index 02e6167..54824f7 100644
65840--- a/kernel/acct.c
65841+++ b/kernel/acct.c
65842@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
65843 */
65844 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
65845 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
65846- file->f_op->write(file, (char *)&ac,
65847+ file->f_op->write(file, (char __force_user *)&ac,
65848 sizeof(acct_t), &file->f_pos);
65849 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
65850 set_fs(fs);
65851diff --git a/kernel/audit.c b/kernel/audit.c
65852index 1c7f2c6..9ba5359 100644
65853--- a/kernel/audit.c
65854+++ b/kernel/audit.c
65855@@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
65856 3) suppressed due to audit_rate_limit
65857 4) suppressed due to audit_backlog_limit
65858 */
65859-static atomic_t audit_lost = ATOMIC_INIT(0);
65860+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
65861
65862 /* The netlink socket. */
65863 static struct sock *audit_sock;
65864@@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
65865 unsigned long now;
65866 int print;
65867
65868- atomic_inc(&audit_lost);
65869+ atomic_inc_unchecked(&audit_lost);
65870
65871 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
65872
65873@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
65874 printk(KERN_WARNING
65875 "audit: audit_lost=%d audit_rate_limit=%d "
65876 "audit_backlog_limit=%d\n",
65877- atomic_read(&audit_lost),
65878+ atomic_read_unchecked(&audit_lost),
65879 audit_rate_limit,
65880 audit_backlog_limit);
65881 audit_panic(message);
65882@@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
65883 status_set.pid = audit_pid;
65884 status_set.rate_limit = audit_rate_limit;
65885 status_set.backlog_limit = audit_backlog_limit;
65886- status_set.lost = atomic_read(&audit_lost);
65887+ status_set.lost = atomic_read_unchecked(&audit_lost);
65888 status_set.backlog = skb_queue_len(&audit_skb_queue);
65889 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
65890 &status_set, sizeof(status_set));
65891diff --git a/kernel/auditsc.c b/kernel/auditsc.c
65892index 4b96415..d8c16ee 100644
65893--- a/kernel/auditsc.c
65894+++ b/kernel/auditsc.c
65895@@ -2289,7 +2289,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
65896 }
65897
65898 /* global counter which is incremented every time something logs in */
65899-static atomic_t session_id = ATOMIC_INIT(0);
65900+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
65901
65902 /**
65903 * audit_set_loginuid - set current task's audit_context loginuid
65904@@ -2313,7 +2313,7 @@ int audit_set_loginuid(uid_t loginuid)
65905 return -EPERM;
65906 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
65907
65908- sessionid = atomic_inc_return(&session_id);
65909+ sessionid = atomic_inc_return_unchecked(&session_id);
65910 if (context && context->in_syscall) {
65911 struct audit_buffer *ab;
65912
65913diff --git a/kernel/capability.c b/kernel/capability.c
65914index 493d972..ea17248 100644
65915--- a/kernel/capability.c
65916+++ b/kernel/capability.c
65917@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
65918 * before modification is attempted and the application
65919 * fails.
65920 */
65921+ if (tocopy > ARRAY_SIZE(kdata))
65922+ return -EFAULT;
65923+
65924 if (copy_to_user(dataptr, kdata, tocopy
65925 * sizeof(struct __user_cap_data_struct))) {
65926 return -EFAULT;
65927@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
65928 int ret;
65929
65930 rcu_read_lock();
65931- ret = security_capable(__task_cred(t), ns, cap);
65932+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
65933+ gr_task_is_capable(t, __task_cred(t), cap);
65934 rcu_read_unlock();
65935
65936- return (ret == 0);
65937+ return ret;
65938 }
65939
65940 /**
65941@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
65942 int ret;
65943
65944 rcu_read_lock();
65945- ret = security_capable_noaudit(__task_cred(t), ns, cap);
65946+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
65947 rcu_read_unlock();
65948
65949- return (ret == 0);
65950+ return ret;
65951 }
65952
65953 /**
65954@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
65955 BUG();
65956 }
65957
65958- if (security_capable(current_cred(), ns, cap) == 0) {
65959+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
65960 current->flags |= PF_SUPERPRIV;
65961 return true;
65962 }
65963@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
65964 }
65965 EXPORT_SYMBOL(ns_capable);
65966
65967+bool ns_capable_nolog(struct user_namespace *ns, int cap)
65968+{
65969+ if (unlikely(!cap_valid(cap))) {
65970+ printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
65971+ BUG();
65972+ }
65973+
65974+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
65975+ current->flags |= PF_SUPERPRIV;
65976+ return true;
65977+ }
65978+ return false;
65979+}
65980+EXPORT_SYMBOL(ns_capable_nolog);
65981+
65982 /**
65983 * capable - Determine if the current task has a superior capability in effect
65984 * @cap: The capability to be tested for
65985@@ -408,6 +427,12 @@ bool capable(int cap)
65986 }
65987 EXPORT_SYMBOL(capable);
65988
65989+bool capable_nolog(int cap)
65990+{
65991+ return ns_capable_nolog(&init_user_ns, cap);
65992+}
65993+EXPORT_SYMBOL(capable_nolog);
65994+
65995 /**
65996 * nsown_capable - Check superior capability to one's own user_ns
65997 * @cap: The capability in question
65998@@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
65999
66000 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66001 }
66002+
66003+bool inode_capable_nolog(const struct inode *inode, int cap)
66004+{
66005+ struct user_namespace *ns = current_user_ns();
66006+
66007+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66008+}
66009diff --git a/kernel/compat.c b/kernel/compat.c
66010index c28a306..b4d0cf3 100644
66011--- a/kernel/compat.c
66012+++ b/kernel/compat.c
66013@@ -13,6 +13,7 @@
66014
66015 #include <linux/linkage.h>
66016 #include <linux/compat.h>
66017+#include <linux/module.h>
66018 #include <linux/errno.h>
66019 #include <linux/time.h>
66020 #include <linux/signal.h>
66021@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
66022 mm_segment_t oldfs;
66023 long ret;
66024
66025- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
66026+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
66027 oldfs = get_fs();
66028 set_fs(KERNEL_DS);
66029 ret = hrtimer_nanosleep_restart(restart);
66030@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
66031 oldfs = get_fs();
66032 set_fs(KERNEL_DS);
66033 ret = hrtimer_nanosleep(&tu,
66034- rmtp ? (struct timespec __user *)&rmt : NULL,
66035+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
66036 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
66037 set_fs(oldfs);
66038
66039@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
66040 mm_segment_t old_fs = get_fs();
66041
66042 set_fs(KERNEL_DS);
66043- ret = sys_sigpending((old_sigset_t __user *) &s);
66044+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
66045 set_fs(old_fs);
66046 if (ret == 0)
66047 ret = put_user(s, set);
66048@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
66049 mm_segment_t old_fs = get_fs();
66050
66051 set_fs(KERNEL_DS);
66052- ret = sys_old_getrlimit(resource, &r);
66053+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
66054 set_fs(old_fs);
66055
66056 if (!ret) {
66057@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
66058 mm_segment_t old_fs = get_fs();
66059
66060 set_fs(KERNEL_DS);
66061- ret = sys_getrusage(who, (struct rusage __user *) &r);
66062+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
66063 set_fs(old_fs);
66064
66065 if (ret)
66066@@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
66067 set_fs (KERNEL_DS);
66068 ret = sys_wait4(pid,
66069 (stat_addr ?
66070- (unsigned int __user *) &status : NULL),
66071- options, (struct rusage __user *) &r);
66072+ (unsigned int __force_user *) &status : NULL),
66073+ options, (struct rusage __force_user *) &r);
66074 set_fs (old_fs);
66075
66076 if (ret > 0) {
66077@@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
66078 memset(&info, 0, sizeof(info));
66079
66080 set_fs(KERNEL_DS);
66081- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
66082- uru ? (struct rusage __user *)&ru : NULL);
66083+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
66084+ uru ? (struct rusage __force_user *)&ru : NULL);
66085 set_fs(old_fs);
66086
66087 if ((ret < 0) || (info.si_signo == 0))
66088@@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
66089 oldfs = get_fs();
66090 set_fs(KERNEL_DS);
66091 err = sys_timer_settime(timer_id, flags,
66092- (struct itimerspec __user *) &newts,
66093- (struct itimerspec __user *) &oldts);
66094+ (struct itimerspec __force_user *) &newts,
66095+ (struct itimerspec __force_user *) &oldts);
66096 set_fs(oldfs);
66097 if (!err && old && put_compat_itimerspec(old, &oldts))
66098 return -EFAULT;
66099@@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
66100 oldfs = get_fs();
66101 set_fs(KERNEL_DS);
66102 err = sys_timer_gettime(timer_id,
66103- (struct itimerspec __user *) &ts);
66104+ (struct itimerspec __force_user *) &ts);
66105 set_fs(oldfs);
66106 if (!err && put_compat_itimerspec(setting, &ts))
66107 return -EFAULT;
66108@@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
66109 oldfs = get_fs();
66110 set_fs(KERNEL_DS);
66111 err = sys_clock_settime(which_clock,
66112- (struct timespec __user *) &ts);
66113+ (struct timespec __force_user *) &ts);
66114 set_fs(oldfs);
66115 return err;
66116 }
66117@@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
66118 oldfs = get_fs();
66119 set_fs(KERNEL_DS);
66120 err = sys_clock_gettime(which_clock,
66121- (struct timespec __user *) &ts);
66122+ (struct timespec __force_user *) &ts);
66123 set_fs(oldfs);
66124 if (!err && put_compat_timespec(&ts, tp))
66125 return -EFAULT;
66126@@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
66127
66128 oldfs = get_fs();
66129 set_fs(KERNEL_DS);
66130- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
66131+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
66132 set_fs(oldfs);
66133
66134 err = compat_put_timex(utp, &txc);
66135@@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
66136 oldfs = get_fs();
66137 set_fs(KERNEL_DS);
66138 err = sys_clock_getres(which_clock,
66139- (struct timespec __user *) &ts);
66140+ (struct timespec __force_user *) &ts);
66141 set_fs(oldfs);
66142 if (!err && tp && put_compat_timespec(&ts, tp))
66143 return -EFAULT;
66144@@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
66145 long err;
66146 mm_segment_t oldfs;
66147 struct timespec tu;
66148- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
66149+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
66150
66151- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
66152+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
66153 oldfs = get_fs();
66154 set_fs(KERNEL_DS);
66155 err = clock_nanosleep_restart(restart);
66156@@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
66157 oldfs = get_fs();
66158 set_fs(KERNEL_DS);
66159 err = sys_clock_nanosleep(which_clock, flags,
66160- (struct timespec __user *) &in,
66161- (struct timespec __user *) &out);
66162+ (struct timespec __force_user *) &in,
66163+ (struct timespec __force_user *) &out);
66164 set_fs(oldfs);
66165
66166 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
66167diff --git a/kernel/configs.c b/kernel/configs.c
66168index 42e8fa0..9e7406b 100644
66169--- a/kernel/configs.c
66170+++ b/kernel/configs.c
66171@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
66172 struct proc_dir_entry *entry;
66173
66174 /* create the current config file */
66175+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66176+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
66177+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
66178+ &ikconfig_file_ops);
66179+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66180+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
66181+ &ikconfig_file_ops);
66182+#endif
66183+#else
66184 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
66185 &ikconfig_file_ops);
66186+#endif
66187+
66188 if (!entry)
66189 return -ENOMEM;
66190
66191diff --git a/kernel/cred.c b/kernel/cred.c
66192index de728ac..e3c267c 100644
66193--- a/kernel/cred.c
66194+++ b/kernel/cred.c
66195@@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
66196 validate_creds(cred);
66197 alter_cred_subscribers(cred, -1);
66198 put_cred(cred);
66199+
66200+#ifdef CONFIG_GRKERNSEC_SETXID
66201+ cred = (struct cred *) tsk->delayed_cred;
66202+ if (cred != NULL) {
66203+ tsk->delayed_cred = NULL;
66204+ validate_creds(cred);
66205+ alter_cred_subscribers(cred, -1);
66206+ put_cred(cred);
66207+ }
66208+#endif
66209 }
66210
66211 /**
66212@@ -469,7 +479,7 @@ error_put:
66213 * Always returns 0 thus allowing this function to be tail-called at the end
66214 * of, say, sys_setgid().
66215 */
66216-int commit_creds(struct cred *new)
66217+static int __commit_creds(struct cred *new)
66218 {
66219 struct task_struct *task = current;
66220 const struct cred *old = task->real_cred;
66221@@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
66222
66223 get_cred(new); /* we will require a ref for the subj creds too */
66224
66225+ gr_set_role_label(task, new->uid, new->gid);
66226+
66227 /* dumpability changes */
66228 if (!uid_eq(old->euid, new->euid) ||
66229 !gid_eq(old->egid, new->egid) ||
66230@@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
66231 put_cred(old);
66232 return 0;
66233 }
66234+#ifdef CONFIG_GRKERNSEC_SETXID
66235+extern int set_user(struct cred *new);
66236+
66237+void gr_delayed_cred_worker(void)
66238+{
66239+ const struct cred *new = current->delayed_cred;
66240+ struct cred *ncred;
66241+
66242+ current->delayed_cred = NULL;
66243+
66244+ if (current_uid() && new != NULL) {
66245+ // from doing get_cred on it when queueing this
66246+ put_cred(new);
66247+ return;
66248+ } else if (new == NULL)
66249+ return;
66250+
66251+ ncred = prepare_creds();
66252+ if (!ncred)
66253+ goto die;
66254+ // uids
66255+ ncred->uid = new->uid;
66256+ ncred->euid = new->euid;
66257+ ncred->suid = new->suid;
66258+ ncred->fsuid = new->fsuid;
66259+ // gids
66260+ ncred->gid = new->gid;
66261+ ncred->egid = new->egid;
66262+ ncred->sgid = new->sgid;
66263+ ncred->fsgid = new->fsgid;
66264+ // groups
66265+ if (set_groups(ncred, new->group_info) < 0) {
66266+ abort_creds(ncred);
66267+ goto die;
66268+ }
66269+ // caps
66270+ ncred->securebits = new->securebits;
66271+ ncred->cap_inheritable = new->cap_inheritable;
66272+ ncred->cap_permitted = new->cap_permitted;
66273+ ncred->cap_effective = new->cap_effective;
66274+ ncred->cap_bset = new->cap_bset;
66275+
66276+ if (set_user(ncred)) {
66277+ abort_creds(ncred);
66278+ goto die;
66279+ }
66280+
66281+ // from doing get_cred on it when queueing this
66282+ put_cred(new);
66283+
66284+ __commit_creds(ncred);
66285+ return;
66286+die:
66287+ // from doing get_cred on it when queueing this
66288+ put_cred(new);
66289+ do_group_exit(SIGKILL);
66290+}
66291+#endif
66292+
66293+int commit_creds(struct cred *new)
66294+{
66295+#ifdef CONFIG_GRKERNSEC_SETXID
66296+ int ret;
66297+ int schedule_it = 0;
66298+ struct task_struct *t;
66299+
66300+ /* we won't get called with tasklist_lock held for writing
66301+ and interrupts disabled as the cred struct in that case is
66302+ init_cred
66303+ */
66304+ if (grsec_enable_setxid && !current_is_single_threaded() &&
66305+ !current_uid() && new->uid) {
66306+ schedule_it = 1;
66307+ }
66308+ ret = __commit_creds(new);
66309+ if (schedule_it) {
66310+ rcu_read_lock();
66311+ read_lock(&tasklist_lock);
66312+ for (t = next_thread(current); t != current;
66313+ t = next_thread(t)) {
66314+ if (t->delayed_cred == NULL) {
66315+ t->delayed_cred = get_cred(new);
66316+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
66317+ set_tsk_need_resched(t);
66318+ }
66319+ }
66320+ read_unlock(&tasklist_lock);
66321+ rcu_read_unlock();
66322+ }
66323+ return ret;
66324+#else
66325+ return __commit_creds(new);
66326+#endif
66327+}
66328+
66329 EXPORT_SYMBOL(commit_creds);
66330
66331 /**
66332diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
66333index 0557f24..1a00d9a 100644
66334--- a/kernel/debug/debug_core.c
66335+++ b/kernel/debug/debug_core.c
66336@@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
66337 */
66338 static atomic_t masters_in_kgdb;
66339 static atomic_t slaves_in_kgdb;
66340-static atomic_t kgdb_break_tasklet_var;
66341+static atomic_unchecked_t kgdb_break_tasklet_var;
66342 atomic_t kgdb_setting_breakpoint;
66343
66344 struct task_struct *kgdb_usethread;
66345@@ -132,7 +132,7 @@ int kgdb_single_step;
66346 static pid_t kgdb_sstep_pid;
66347
66348 /* to keep track of the CPU which is doing the single stepping*/
66349-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66350+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66351
66352 /*
66353 * If you are debugging a problem where roundup (the collection of
66354@@ -540,7 +540,7 @@ return_normal:
66355 * kernel will only try for the value of sstep_tries before
66356 * giving up and continuing on.
66357 */
66358- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
66359+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
66360 (kgdb_info[cpu].task &&
66361 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
66362 atomic_set(&kgdb_active, -1);
66363@@ -634,8 +634,8 @@ cpu_master_loop:
66364 }
66365
66366 kgdb_restore:
66367- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
66368- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
66369+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
66370+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
66371 if (kgdb_info[sstep_cpu].task)
66372 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
66373 else
66374@@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
66375 static void kgdb_tasklet_bpt(unsigned long ing)
66376 {
66377 kgdb_breakpoint();
66378- atomic_set(&kgdb_break_tasklet_var, 0);
66379+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
66380 }
66381
66382 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
66383
66384 void kgdb_schedule_breakpoint(void)
66385 {
66386- if (atomic_read(&kgdb_break_tasklet_var) ||
66387+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
66388 atomic_read(&kgdb_active) != -1 ||
66389 atomic_read(&kgdb_setting_breakpoint))
66390 return;
66391- atomic_inc(&kgdb_break_tasklet_var);
66392+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
66393 tasklet_schedule(&kgdb_tasklet_breakpoint);
66394 }
66395 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
66396diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
66397index 1f91413..362a0a1 100644
66398--- a/kernel/debug/kdb/kdb_main.c
66399+++ b/kernel/debug/kdb/kdb_main.c
66400@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
66401 list_for_each_entry(mod, kdb_modules, list) {
66402
66403 kdb_printf("%-20s%8u 0x%p ", mod->name,
66404- mod->core_size, (void *)mod);
66405+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
66406 #ifdef CONFIG_MODULE_UNLOAD
66407 kdb_printf("%4ld ", module_refcount(mod));
66408 #endif
66409@@ -1994,7 +1994,7 @@ static int kdb_lsmod(int argc, const char **argv)
66410 kdb_printf(" (Loading)");
66411 else
66412 kdb_printf(" (Live)");
66413- kdb_printf(" 0x%p", mod->module_core);
66414+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
66415
66416 #ifdef CONFIG_MODULE_UNLOAD
66417 {
66418diff --git a/kernel/events/core.c b/kernel/events/core.c
66419index d7d71d6..f54b76f 100644
66420--- a/kernel/events/core.c
66421+++ b/kernel/events/core.c
66422@@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
66423 return 0;
66424 }
66425
66426-static atomic64_t perf_event_id;
66427+static atomic64_unchecked_t perf_event_id;
66428
66429 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
66430 enum event_type_t event_type);
66431@@ -2663,7 +2663,7 @@ static void __perf_event_read(void *info)
66432
66433 static inline u64 perf_event_count(struct perf_event *event)
66434 {
66435- return local64_read(&event->count) + atomic64_read(&event->child_count);
66436+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
66437 }
66438
66439 static u64 perf_event_read(struct perf_event *event)
66440@@ -2987,9 +2987,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
66441 mutex_lock(&event->child_mutex);
66442 total += perf_event_read(event);
66443 *enabled += event->total_time_enabled +
66444- atomic64_read(&event->child_total_time_enabled);
66445+ atomic64_read_unchecked(&event->child_total_time_enabled);
66446 *running += event->total_time_running +
66447- atomic64_read(&event->child_total_time_running);
66448+ atomic64_read_unchecked(&event->child_total_time_running);
66449
66450 list_for_each_entry(child, &event->child_list, child_list) {
66451 total += perf_event_read(child);
66452@@ -3396,10 +3396,10 @@ void perf_event_update_userpage(struct perf_event *event)
66453 userpg->offset -= local64_read(&event->hw.prev_count);
66454
66455 userpg->time_enabled = enabled +
66456- atomic64_read(&event->child_total_time_enabled);
66457+ atomic64_read_unchecked(&event->child_total_time_enabled);
66458
66459 userpg->time_running = running +
66460- atomic64_read(&event->child_total_time_running);
66461+ atomic64_read_unchecked(&event->child_total_time_running);
66462
66463 arch_perf_update_userpage(userpg, now);
66464
66465@@ -3832,11 +3832,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
66466 values[n++] = perf_event_count(event);
66467 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
66468 values[n++] = enabled +
66469- atomic64_read(&event->child_total_time_enabled);
66470+ atomic64_read_unchecked(&event->child_total_time_enabled);
66471 }
66472 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
66473 values[n++] = running +
66474- atomic64_read(&event->child_total_time_running);
66475+ atomic64_read_unchecked(&event->child_total_time_running);
66476 }
66477 if (read_format & PERF_FORMAT_ID)
66478 values[n++] = primary_event_id(event);
66479@@ -4514,12 +4514,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
66480 * need to add enough zero bytes after the string to handle
66481 * the 64bit alignment we do later.
66482 */
66483- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
66484+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
66485 if (!buf) {
66486 name = strncpy(tmp, "//enomem", sizeof(tmp));
66487 goto got_name;
66488 }
66489- name = d_path(&file->f_path, buf, PATH_MAX);
66490+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
66491 if (IS_ERR(name)) {
66492 name = strncpy(tmp, "//toolong", sizeof(tmp));
66493 goto got_name;
66494@@ -5931,7 +5931,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
66495 event->parent = parent_event;
66496
66497 event->ns = get_pid_ns(current->nsproxy->pid_ns);
66498- event->id = atomic64_inc_return(&perf_event_id);
66499+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
66500
66501 event->state = PERF_EVENT_STATE_INACTIVE;
66502
66503@@ -6493,10 +6493,10 @@ static void sync_child_event(struct perf_event *child_event,
66504 /*
66505 * Add back the child's count to the parent's count:
66506 */
66507- atomic64_add(child_val, &parent_event->child_count);
66508- atomic64_add(child_event->total_time_enabled,
66509+ atomic64_add_unchecked(child_val, &parent_event->child_count);
66510+ atomic64_add_unchecked(child_event->total_time_enabled,
66511 &parent_event->child_total_time_enabled);
66512- atomic64_add(child_event->total_time_running,
66513+ atomic64_add_unchecked(child_event->total_time_running,
66514 &parent_event->child_total_time_running);
66515
66516 /*
66517diff --git a/kernel/exit.c b/kernel/exit.c
66518index 46ce8da..c648f3a 100644
66519--- a/kernel/exit.c
66520+++ b/kernel/exit.c
66521@@ -59,6 +59,10 @@
66522 #include <asm/pgtable.h>
66523 #include <asm/mmu_context.h>
66524
66525+#ifdef CONFIG_GRKERNSEC
66526+extern rwlock_t grsec_exec_file_lock;
66527+#endif
66528+
66529 static void exit_mm(struct task_struct * tsk);
66530
66531 static void __unhash_process(struct task_struct *p, bool group_dead)
66532@@ -182,6 +186,10 @@ void release_task(struct task_struct * p)
66533 struct task_struct *leader;
66534 int zap_leader;
66535 repeat:
66536+#ifdef CONFIG_NET
66537+ gr_del_task_from_ip_table(p);
66538+#endif
66539+
66540 /* don't need to get the RCU readlock here - the process is dead and
66541 * can't be modifying its own credentials. But shut RCU-lockdep up */
66542 rcu_read_lock();
66543@@ -394,7 +402,7 @@ int allow_signal(int sig)
66544 * know it'll be handled, so that they don't get converted to
66545 * SIGKILL or just silently dropped.
66546 */
66547- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
66548+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
66549 recalc_sigpending();
66550 spin_unlock_irq(&current->sighand->siglock);
66551 return 0;
66552@@ -430,6 +438,17 @@ void daemonize(const char *name, ...)
66553 vsnprintf(current->comm, sizeof(current->comm), name, args);
66554 va_end(args);
66555
66556+#ifdef CONFIG_GRKERNSEC
66557+ write_lock(&grsec_exec_file_lock);
66558+ if (current->exec_file) {
66559+ fput(current->exec_file);
66560+ current->exec_file = NULL;
66561+ }
66562+ write_unlock(&grsec_exec_file_lock);
66563+#endif
66564+
66565+ gr_set_kernel_label(current);
66566+
66567 /*
66568 * If we were started as result of loading a module, close all of the
66569 * user space pages. We don't need them, and if we didn't close them
66570@@ -907,6 +926,8 @@ void do_exit(long code)
66571 struct task_struct *tsk = current;
66572 int group_dead;
66573
66574+ set_fs(USER_DS);
66575+
66576 profile_task_exit(tsk);
66577
66578 WARN_ON(blk_needs_flush_plug(tsk));
66579@@ -923,7 +944,6 @@ void do_exit(long code)
66580 * mm_release()->clear_child_tid() from writing to a user-controlled
66581 * kernel address.
66582 */
66583- set_fs(USER_DS);
66584
66585 ptrace_event(PTRACE_EVENT_EXIT, code);
66586
66587@@ -985,6 +1005,9 @@ void do_exit(long code)
66588 tsk->exit_code = code;
66589 taskstats_exit(tsk, group_dead);
66590
66591+ gr_acl_handle_psacct(tsk, code);
66592+ gr_acl_handle_exit();
66593+
66594 exit_mm(tsk);
66595
66596 if (group_dead)
66597@@ -1101,7 +1124,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
66598 * Take down every thread in the group. This is called by fatal signals
66599 * as well as by sys_exit_group (below).
66600 */
66601-void
66602+__noreturn void
66603 do_group_exit(int exit_code)
66604 {
66605 struct signal_struct *sig = current->signal;
66606diff --git a/kernel/fork.c b/kernel/fork.c
66607index f00e319..c212fbc 100644
66608--- a/kernel/fork.c
66609+++ b/kernel/fork.c
66610@@ -321,7 +321,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
66611 *stackend = STACK_END_MAGIC; /* for overflow detection */
66612
66613 #ifdef CONFIG_CC_STACKPROTECTOR
66614- tsk->stack_canary = get_random_int();
66615+ tsk->stack_canary = pax_get_random_long();
66616 #endif
66617
66618 /*
66619@@ -345,13 +345,78 @@ out:
66620 }
66621
66622 #ifdef CONFIG_MMU
66623+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
66624+{
66625+ struct vm_area_struct *tmp;
66626+ unsigned long charge;
66627+ struct mempolicy *pol;
66628+ struct file *file;
66629+
66630+ charge = 0;
66631+ if (mpnt->vm_flags & VM_ACCOUNT) {
66632+ unsigned long len;
66633+ len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66634+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
66635+ goto fail_nomem;
66636+ charge = len;
66637+ }
66638+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66639+ if (!tmp)
66640+ goto fail_nomem;
66641+ *tmp = *mpnt;
66642+ tmp->vm_mm = mm;
66643+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
66644+ pol = mpol_dup(vma_policy(mpnt));
66645+ if (IS_ERR(pol))
66646+ goto fail_nomem_policy;
66647+ vma_set_policy(tmp, pol);
66648+ if (anon_vma_fork(tmp, mpnt))
66649+ goto fail_nomem_anon_vma_fork;
66650+ tmp->vm_flags &= ~VM_LOCKED;
66651+ tmp->vm_next = tmp->vm_prev = NULL;
66652+ tmp->vm_mirror = NULL;
66653+ file = tmp->vm_file;
66654+ if (file) {
66655+ struct inode *inode = file->f_path.dentry->d_inode;
66656+ struct address_space *mapping = file->f_mapping;
66657+
66658+ get_file(file);
66659+ if (tmp->vm_flags & VM_DENYWRITE)
66660+ atomic_dec(&inode->i_writecount);
66661+ mutex_lock(&mapping->i_mmap_mutex);
66662+ if (tmp->vm_flags & VM_SHARED)
66663+ mapping->i_mmap_writable++;
66664+ flush_dcache_mmap_lock(mapping);
66665+ /* insert tmp into the share list, just after mpnt */
66666+ vma_prio_tree_add(tmp, mpnt);
66667+ flush_dcache_mmap_unlock(mapping);
66668+ mutex_unlock(&mapping->i_mmap_mutex);
66669+ }
66670+
66671+ /*
66672+ * Clear hugetlb-related page reserves for children. This only
66673+ * affects MAP_PRIVATE mappings. Faults generated by the child
66674+ * are not guaranteed to succeed, even if read-only
66675+ */
66676+ if (is_vm_hugetlb_page(tmp))
66677+ reset_vma_resv_huge_pages(tmp);
66678+
66679+ return tmp;
66680+
66681+fail_nomem_anon_vma_fork:
66682+ mpol_put(pol);
66683+fail_nomem_policy:
66684+ kmem_cache_free(vm_area_cachep, tmp);
66685+fail_nomem:
66686+ vm_unacct_memory(charge);
66687+ return NULL;
66688+}
66689+
66690 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66691 {
66692 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
66693 struct rb_node **rb_link, *rb_parent;
66694 int retval;
66695- unsigned long charge;
66696- struct mempolicy *pol;
66697
66698 down_write(&oldmm->mmap_sem);
66699 flush_cache_dup_mm(oldmm);
66700@@ -363,8 +428,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66701 mm->locked_vm = 0;
66702 mm->mmap = NULL;
66703 mm->mmap_cache = NULL;
66704- mm->free_area_cache = oldmm->mmap_base;
66705- mm->cached_hole_size = ~0UL;
66706+ mm->free_area_cache = oldmm->free_area_cache;
66707+ mm->cached_hole_size = oldmm->cached_hole_size;
66708 mm->map_count = 0;
66709 cpumask_clear(mm_cpumask(mm));
66710 mm->mm_rb = RB_ROOT;
66711@@ -380,8 +445,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66712
66713 prev = NULL;
66714 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
66715- struct file *file;
66716-
66717 if (mpnt->vm_flags & VM_DONTCOPY) {
66718 long pages = vma_pages(mpnt);
66719 mm->total_vm -= pages;
66720@@ -389,54 +452,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66721 -pages);
66722 continue;
66723 }
66724- charge = 0;
66725- if (mpnt->vm_flags & VM_ACCOUNT) {
66726- unsigned long len;
66727- len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66728- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
66729- goto fail_nomem;
66730- charge = len;
66731+ tmp = dup_vma(mm, oldmm, mpnt);
66732+ if (!tmp) {
66733+ retval = -ENOMEM;
66734+ goto out;
66735 }
66736- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66737- if (!tmp)
66738- goto fail_nomem;
66739- *tmp = *mpnt;
66740- INIT_LIST_HEAD(&tmp->anon_vma_chain);
66741- pol = mpol_dup(vma_policy(mpnt));
66742- retval = PTR_ERR(pol);
66743- if (IS_ERR(pol))
66744- goto fail_nomem_policy;
66745- vma_set_policy(tmp, pol);
66746- tmp->vm_mm = mm;
66747- if (anon_vma_fork(tmp, mpnt))
66748- goto fail_nomem_anon_vma_fork;
66749- tmp->vm_flags &= ~VM_LOCKED;
66750- tmp->vm_next = tmp->vm_prev = NULL;
66751- file = tmp->vm_file;
66752- if (file) {
66753- struct inode *inode = file->f_path.dentry->d_inode;
66754- struct address_space *mapping = file->f_mapping;
66755-
66756- get_file(file);
66757- if (tmp->vm_flags & VM_DENYWRITE)
66758- atomic_dec(&inode->i_writecount);
66759- mutex_lock(&mapping->i_mmap_mutex);
66760- if (tmp->vm_flags & VM_SHARED)
66761- mapping->i_mmap_writable++;
66762- flush_dcache_mmap_lock(mapping);
66763- /* insert tmp into the share list, just after mpnt */
66764- vma_prio_tree_add(tmp, mpnt);
66765- flush_dcache_mmap_unlock(mapping);
66766- mutex_unlock(&mapping->i_mmap_mutex);
66767- }
66768-
66769- /*
66770- * Clear hugetlb-related page reserves for children. This only
66771- * affects MAP_PRIVATE mappings. Faults generated by the child
66772- * are not guaranteed to succeed, even if read-only
66773- */
66774- if (is_vm_hugetlb_page(tmp))
66775- reset_vma_resv_huge_pages(tmp);
66776
66777 /*
66778 * Link in the new vma and copy the page table entries.
66779@@ -459,9 +479,34 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66780 if (retval)
66781 goto out;
66782
66783- if (file && uprobe_mmap(tmp))
66784+ if (tmp->vm_file && uprobe_mmap(tmp))
66785 goto out;
66786 }
66787+
66788+#ifdef CONFIG_PAX_SEGMEXEC
66789+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
66790+ struct vm_area_struct *mpnt_m;
66791+
66792+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
66793+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
66794+
66795+ if (!mpnt->vm_mirror)
66796+ continue;
66797+
66798+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
66799+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
66800+ mpnt->vm_mirror = mpnt_m;
66801+ } else {
66802+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
66803+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
66804+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
66805+ mpnt->vm_mirror->vm_mirror = mpnt;
66806+ }
66807+ }
66808+ BUG_ON(mpnt_m);
66809+ }
66810+#endif
66811+
66812 /* a new mm has just been created */
66813 arch_dup_mmap(oldmm, mm);
66814 retval = 0;
66815@@ -470,14 +515,6 @@ out:
66816 flush_tlb_mm(oldmm);
66817 up_write(&oldmm->mmap_sem);
66818 return retval;
66819-fail_nomem_anon_vma_fork:
66820- mpol_put(pol);
66821-fail_nomem_policy:
66822- kmem_cache_free(vm_area_cachep, tmp);
66823-fail_nomem:
66824- retval = -ENOMEM;
66825- vm_unacct_memory(charge);
66826- goto out;
66827 }
66828
66829 static inline int mm_alloc_pgd(struct mm_struct *mm)
66830@@ -714,8 +751,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
66831 return ERR_PTR(err);
66832
66833 mm = get_task_mm(task);
66834- if (mm && mm != current->mm &&
66835- !ptrace_may_access(task, mode)) {
66836+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
66837+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
66838 mmput(mm);
66839 mm = ERR_PTR(-EACCES);
66840 }
66841@@ -936,13 +973,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
66842 spin_unlock(&fs->lock);
66843 return -EAGAIN;
66844 }
66845- fs->users++;
66846+ atomic_inc(&fs->users);
66847 spin_unlock(&fs->lock);
66848 return 0;
66849 }
66850 tsk->fs = copy_fs_struct(fs);
66851 if (!tsk->fs)
66852 return -ENOMEM;
66853+ gr_set_chroot_entries(tsk, &tsk->fs->root);
66854 return 0;
66855 }
66856
66857@@ -1209,6 +1247,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66858 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
66859 #endif
66860 retval = -EAGAIN;
66861+
66862+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
66863+
66864 if (atomic_read(&p->real_cred->user->processes) >=
66865 task_rlimit(p, RLIMIT_NPROC)) {
66866 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
66867@@ -1431,6 +1472,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66868 /* Need tasklist lock for parent etc handling! */
66869 write_lock_irq(&tasklist_lock);
66870
66871+ /* synchronizes with gr_set_acls() */
66872+ gr_copy_label(p);
66873+
66874 /* CLONE_PARENT re-uses the old parent */
66875 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
66876 p->real_parent = current->real_parent;
66877@@ -1541,6 +1585,8 @@ bad_fork_cleanup_count:
66878 bad_fork_free:
66879 free_task(p);
66880 fork_out:
66881+ gr_log_forkfail(retval);
66882+
66883 return ERR_PTR(retval);
66884 }
66885
66886@@ -1641,6 +1687,8 @@ long do_fork(unsigned long clone_flags,
66887 if (clone_flags & CLONE_PARENT_SETTID)
66888 put_user(nr, parent_tidptr);
66889
66890+ gr_handle_brute_check();
66891+
66892 if (clone_flags & CLONE_VFORK) {
66893 p->vfork_done = &vfork;
66894 init_completion(&vfork);
66895@@ -1739,7 +1787,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
66896 return 0;
66897
66898 /* don't need lock here; in the worst case we'll do useless copy */
66899- if (fs->users == 1)
66900+ if (atomic_read(&fs->users) == 1)
66901 return 0;
66902
66903 *new_fsp = copy_fs_struct(fs);
66904@@ -1828,7 +1876,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
66905 fs = current->fs;
66906 spin_lock(&fs->lock);
66907 current->fs = new_fs;
66908- if (--fs->users)
66909+ gr_set_chroot_entries(current, &current->fs->root);
66910+ if (atomic_dec_return(&fs->users))
66911 new_fs = NULL;
66912 else
66913 new_fs = fs;
66914diff --git a/kernel/futex.c b/kernel/futex.c
66915index 3717e7b..473c750 100644
66916--- a/kernel/futex.c
66917+++ b/kernel/futex.c
66918@@ -54,6 +54,7 @@
66919 #include <linux/mount.h>
66920 #include <linux/pagemap.h>
66921 #include <linux/syscalls.h>
66922+#include <linux/ptrace.h>
66923 #include <linux/signal.h>
66924 #include <linux/export.h>
66925 #include <linux/magic.h>
66926@@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
66927 struct page *page, *page_head;
66928 int err, ro = 0;
66929
66930+#ifdef CONFIG_PAX_SEGMEXEC
66931+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
66932+ return -EFAULT;
66933+#endif
66934+
66935 /*
66936 * The futex address must be "naturally" aligned.
66937 */
66938@@ -2714,6 +2720,7 @@ static int __init futex_init(void)
66939 {
66940 u32 curval;
66941 int i;
66942+ mm_segment_t oldfs;
66943
66944 /*
66945 * This will fail and we want it. Some arch implementations do
66946@@ -2725,8 +2732,11 @@ static int __init futex_init(void)
66947 * implementation, the non-functional ones will return
66948 * -ENOSYS.
66949 */
66950+ oldfs = get_fs();
66951+ set_fs(USER_DS);
66952 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
66953 futex_cmpxchg_enabled = 1;
66954+ set_fs(oldfs);
66955
66956 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
66957 plist_head_init(&futex_queues[i].chain);
66958diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
66959index 9b22d03..6295b62 100644
66960--- a/kernel/gcov/base.c
66961+++ b/kernel/gcov/base.c
66962@@ -102,11 +102,6 @@ void gcov_enable_events(void)
66963 }
66964
66965 #ifdef CONFIG_MODULES
66966-static inline int within(void *addr, void *start, unsigned long size)
66967-{
66968- return ((addr >= start) && (addr < start + size));
66969-}
66970-
66971 /* Update list and generate events when modules are unloaded. */
66972 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66973 void *data)
66974@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66975 prev = NULL;
66976 /* Remove entries located in module from linked list. */
66977 for (info = gcov_info_head; info; info = info->next) {
66978- if (within(info, mod->module_core, mod->core_size)) {
66979+ if (within_module_core_rw((unsigned long)info, mod)) {
66980 if (prev)
66981 prev->next = info->next;
66982 else
66983diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
66984index 6db7a5e..25b6648 100644
66985--- a/kernel/hrtimer.c
66986+++ b/kernel/hrtimer.c
66987@@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
66988 local_irq_restore(flags);
66989 }
66990
66991-static void run_hrtimer_softirq(struct softirq_action *h)
66992+static void run_hrtimer_softirq(void)
66993 {
66994 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
66995
66996diff --git a/kernel/jump_label.c b/kernel/jump_label.c
66997index 4304919..408c4c0 100644
66998--- a/kernel/jump_label.c
66999+++ b/kernel/jump_label.c
67000@@ -13,6 +13,7 @@
67001 #include <linux/sort.h>
67002 #include <linux/err.h>
67003 #include <linux/static_key.h>
67004+#include <linux/mm.h>
67005
67006 #ifdef HAVE_JUMP_LABEL
67007
67008@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
67009
67010 size = (((unsigned long)stop - (unsigned long)start)
67011 / sizeof(struct jump_entry));
67012+ pax_open_kernel();
67013 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
67014+ pax_close_kernel();
67015 }
67016
67017 static void jump_label_update(struct static_key *key, int enable);
67018@@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
67019 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
67020 struct jump_entry *iter;
67021
67022+ pax_open_kernel();
67023 for (iter = iter_start; iter < iter_stop; iter++) {
67024 if (within_module_init(iter->code, mod))
67025 iter->code = 0;
67026 }
67027+ pax_close_kernel();
67028 }
67029
67030 static int
67031diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
67032index 2169fee..45c017a 100644
67033--- a/kernel/kallsyms.c
67034+++ b/kernel/kallsyms.c
67035@@ -11,6 +11,9 @@
67036 * Changed the compression method from stem compression to "table lookup"
67037 * compression (see scripts/kallsyms.c for a more complete description)
67038 */
67039+#ifdef CONFIG_GRKERNSEC_HIDESYM
67040+#define __INCLUDED_BY_HIDESYM 1
67041+#endif
67042 #include <linux/kallsyms.h>
67043 #include <linux/module.h>
67044 #include <linux/init.h>
67045@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
67046
67047 static inline int is_kernel_inittext(unsigned long addr)
67048 {
67049+ if (system_state != SYSTEM_BOOTING)
67050+ return 0;
67051+
67052 if (addr >= (unsigned long)_sinittext
67053 && addr <= (unsigned long)_einittext)
67054 return 1;
67055 return 0;
67056 }
67057
67058+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67059+#ifdef CONFIG_MODULES
67060+static inline int is_module_text(unsigned long addr)
67061+{
67062+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
67063+ return 1;
67064+
67065+ addr = ktla_ktva(addr);
67066+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
67067+}
67068+#else
67069+static inline int is_module_text(unsigned long addr)
67070+{
67071+ return 0;
67072+}
67073+#endif
67074+#endif
67075+
67076 static inline int is_kernel_text(unsigned long addr)
67077 {
67078 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
67079@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
67080
67081 static inline int is_kernel(unsigned long addr)
67082 {
67083+
67084+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67085+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
67086+ return 1;
67087+
67088+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
67089+#else
67090 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
67091+#endif
67092+
67093 return 1;
67094 return in_gate_area_no_mm(addr);
67095 }
67096
67097 static int is_ksym_addr(unsigned long addr)
67098 {
67099+
67100+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67101+ if (is_module_text(addr))
67102+ return 0;
67103+#endif
67104+
67105 if (all_var)
67106 return is_kernel(addr);
67107
67108@@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
67109
67110 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
67111 {
67112- iter->name[0] = '\0';
67113 iter->nameoff = get_symbol_offset(new_pos);
67114 iter->pos = new_pos;
67115 }
67116@@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
67117 {
67118 struct kallsym_iter *iter = m->private;
67119
67120+#ifdef CONFIG_GRKERNSEC_HIDESYM
67121+ if (current_uid())
67122+ return 0;
67123+#endif
67124+
67125 /* Some debugging symbols have no name. Ignore them. */
67126 if (!iter->name[0])
67127 return 0;
67128@@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
67129 */
67130 type = iter->exported ? toupper(iter->type) :
67131 tolower(iter->type);
67132+
67133 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
67134 type, iter->name, iter->module_name);
67135 } else
67136@@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
67137 struct kallsym_iter *iter;
67138 int ret;
67139
67140- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
67141+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
67142 if (!iter)
67143 return -ENOMEM;
67144 reset_iter(iter, 0);
67145diff --git a/kernel/kexec.c b/kernel/kexec.c
67146index 4e2e472..cd0c7ae 100644
67147--- a/kernel/kexec.c
67148+++ b/kernel/kexec.c
67149@@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
67150 unsigned long flags)
67151 {
67152 struct compat_kexec_segment in;
67153- struct kexec_segment out, __user *ksegments;
67154+ struct kexec_segment out;
67155+ struct kexec_segment __user *ksegments;
67156 unsigned long i, result;
67157
67158 /* Don't allow clients that don't understand the native
67159diff --git a/kernel/kmod.c b/kernel/kmod.c
67160index ff2c7cb..085d7af 100644
67161--- a/kernel/kmod.c
67162+++ b/kernel/kmod.c
67163@@ -66,7 +66,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
67164 kfree(info->argv);
67165 }
67166
67167-static int call_modprobe(char *module_name, int wait)
67168+static int call_modprobe(char *module_name, char *module_param, int wait)
67169 {
67170 static char *envp[] = {
67171 "HOME=/",
67172@@ -75,7 +75,7 @@ static int call_modprobe(char *module_name, int wait)
67173 NULL
67174 };
67175
67176- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
67177+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
67178 if (!argv)
67179 goto out;
67180
67181@@ -87,7 +87,8 @@ static int call_modprobe(char *module_name, int wait)
67182 argv[1] = "-q";
67183 argv[2] = "--";
67184 argv[3] = module_name; /* check free_modprobe_argv() */
67185- argv[4] = NULL;
67186+ argv[4] = module_param;
67187+ argv[5] = NULL;
67188
67189 return call_usermodehelper_fns(modprobe_path, argv, envp,
67190 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
67191@@ -112,9 +113,8 @@ out:
67192 * If module auto-loading support is disabled then this function
67193 * becomes a no-operation.
67194 */
67195-int __request_module(bool wait, const char *fmt, ...)
67196+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
67197 {
67198- va_list args;
67199 char module_name[MODULE_NAME_LEN];
67200 unsigned int max_modprobes;
67201 int ret;
67202@@ -122,9 +122,7 @@ int __request_module(bool wait, const char *fmt, ...)
67203 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
67204 static int kmod_loop_msg;
67205
67206- va_start(args, fmt);
67207- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
67208- va_end(args);
67209+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
67210 if (ret >= MODULE_NAME_LEN)
67211 return -ENAMETOOLONG;
67212
67213@@ -132,6 +130,20 @@ int __request_module(bool wait, const char *fmt, ...)
67214 if (ret)
67215 return ret;
67216
67217+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67218+ if (!current_uid()) {
67219+ /* hack to workaround consolekit/udisks stupidity */
67220+ read_lock(&tasklist_lock);
67221+ if (!strcmp(current->comm, "mount") &&
67222+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
67223+ read_unlock(&tasklist_lock);
67224+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
67225+ return -EPERM;
67226+ }
67227+ read_unlock(&tasklist_lock);
67228+ }
67229+#endif
67230+
67231 /* If modprobe needs a service that is in a module, we get a recursive
67232 * loop. Limit the number of running kmod threads to max_threads/2 or
67233 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
67234@@ -160,11 +172,52 @@ int __request_module(bool wait, const char *fmt, ...)
67235
67236 trace_module_request(module_name, wait, _RET_IP_);
67237
67238- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67239+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67240
67241 atomic_dec(&kmod_concurrent);
67242 return ret;
67243 }
67244+
67245+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
67246+{
67247+ va_list args;
67248+ int ret;
67249+
67250+ va_start(args, fmt);
67251+ ret = ____request_module(wait, module_param, fmt, args);
67252+ va_end(args);
67253+
67254+ return ret;
67255+}
67256+
67257+int __request_module(bool wait, const char *fmt, ...)
67258+{
67259+ va_list args;
67260+ int ret;
67261+
67262+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67263+ if (current_uid()) {
67264+ char module_param[MODULE_NAME_LEN];
67265+
67266+ memset(module_param, 0, sizeof(module_param));
67267+
67268+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
67269+
67270+ va_start(args, fmt);
67271+ ret = ____request_module(wait, module_param, fmt, args);
67272+ va_end(args);
67273+
67274+ return ret;
67275+ }
67276+#endif
67277+
67278+ va_start(args, fmt);
67279+ ret = ____request_module(wait, NULL, fmt, args);
67280+ va_end(args);
67281+
67282+ return ret;
67283+}
67284+
67285 EXPORT_SYMBOL(__request_module);
67286 #endif /* CONFIG_MODULES */
67287
67288@@ -266,7 +319,7 @@ static int wait_for_helper(void *data)
67289 *
67290 * Thus the __user pointer cast is valid here.
67291 */
67292- sys_wait4(pid, (int __user *)&ret, 0, NULL);
67293+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
67294
67295 /*
67296 * If ret is 0, either ____call_usermodehelper failed and the
67297diff --git a/kernel/kprobes.c b/kernel/kprobes.c
67298index c62b854..cb67968 100644
67299--- a/kernel/kprobes.c
67300+++ b/kernel/kprobes.c
67301@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
67302 * kernel image and loaded module images reside. This is required
67303 * so x86_64 can correctly handle the %rip-relative fixups.
67304 */
67305- kip->insns = module_alloc(PAGE_SIZE);
67306+ kip->insns = module_alloc_exec(PAGE_SIZE);
67307 if (!kip->insns) {
67308 kfree(kip);
67309 return NULL;
67310@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
67311 */
67312 if (!list_is_singular(&kip->list)) {
67313 list_del(&kip->list);
67314- module_free(NULL, kip->insns);
67315+ module_free_exec(NULL, kip->insns);
67316 kfree(kip);
67317 }
67318 return 1;
67319@@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
67320 {
67321 int i, err = 0;
67322 unsigned long offset = 0, size = 0;
67323- char *modname, namebuf[128];
67324+ char *modname, namebuf[KSYM_NAME_LEN];
67325 const char *symbol_name;
67326 void *addr;
67327 struct kprobe_blackpoint *kb;
67328@@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
67329 const char *sym = NULL;
67330 unsigned int i = *(loff_t *) v;
67331 unsigned long offset = 0;
67332- char *modname, namebuf[128];
67333+ char *modname, namebuf[KSYM_NAME_LEN];
67334
67335 head = &kprobe_table[i];
67336 preempt_disable();
67337diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
67338index 4e316e1..5501eef 100644
67339--- a/kernel/ksysfs.c
67340+++ b/kernel/ksysfs.c
67341@@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
67342 {
67343 if (count+1 > UEVENT_HELPER_PATH_LEN)
67344 return -ENOENT;
67345+ if (!capable(CAP_SYS_ADMIN))
67346+ return -EPERM;
67347 memcpy(uevent_helper, buf, count);
67348 uevent_helper[count] = '\0';
67349 if (count && uevent_helper[count-1] == '\n')
67350diff --git a/kernel/lockdep.c b/kernel/lockdep.c
67351index ea9ee45..67ebc8f 100644
67352--- a/kernel/lockdep.c
67353+++ b/kernel/lockdep.c
67354@@ -590,6 +590,10 @@ static int static_obj(void *obj)
67355 end = (unsigned long) &_end,
67356 addr = (unsigned long) obj;
67357
67358+#ifdef CONFIG_PAX_KERNEXEC
67359+ start = ktla_ktva(start);
67360+#endif
67361+
67362 /*
67363 * static variable?
67364 */
67365@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
67366 if (!static_obj(lock->key)) {
67367 debug_locks_off();
67368 printk("INFO: trying to register non-static key.\n");
67369+ printk("lock:%pS key:%pS.\n", lock, lock->key);
67370 printk("the code is fine but needs lockdep annotation.\n");
67371 printk("turning off the locking correctness validator.\n");
67372 dump_stack();
67373@@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
67374 if (!class)
67375 return 0;
67376 }
67377- atomic_inc((atomic_t *)&class->ops);
67378+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
67379 if (very_verbose(class)) {
67380 printk("\nacquire class [%p] %s", class->key, class->name);
67381 if (class->name_version > 1)
67382diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
67383index 91c32a0..b2c71c5 100644
67384--- a/kernel/lockdep_proc.c
67385+++ b/kernel/lockdep_proc.c
67386@@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
67387
67388 static void print_name(struct seq_file *m, struct lock_class *class)
67389 {
67390- char str[128];
67391+ char str[KSYM_NAME_LEN];
67392 const char *name = class->name;
67393
67394 if (!name) {
67395diff --git a/kernel/module.c b/kernel/module.c
67396index 4edbd9c..165e780 100644
67397--- a/kernel/module.c
67398+++ b/kernel/module.c
67399@@ -58,6 +58,7 @@
67400 #include <linux/jump_label.h>
67401 #include <linux/pfn.h>
67402 #include <linux/bsearch.h>
67403+#include <linux/grsecurity.h>
67404
67405 #define CREATE_TRACE_POINTS
67406 #include <trace/events/module.h>
67407@@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
67408
67409 /* Bounds of module allocation, for speeding __module_address.
67410 * Protected by module_mutex. */
67411-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
67412+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
67413+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
67414
67415 int register_module_notifier(struct notifier_block * nb)
67416 {
67417@@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
67418 return true;
67419
67420 list_for_each_entry_rcu(mod, &modules, list) {
67421- struct symsearch arr[] = {
67422+ struct symsearch modarr[] = {
67423 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
67424 NOT_GPL_ONLY, false },
67425 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
67426@@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
67427 #endif
67428 };
67429
67430- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
67431+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
67432 return true;
67433 }
67434 return false;
67435@@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
67436 static int percpu_modalloc(struct module *mod,
67437 unsigned long size, unsigned long align)
67438 {
67439- if (align > PAGE_SIZE) {
67440+ if (align-1 >= PAGE_SIZE) {
67441 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
67442 mod->name, align, PAGE_SIZE);
67443 align = PAGE_SIZE;
67444@@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
67445 static ssize_t show_coresize(struct module_attribute *mattr,
67446 struct module_kobject *mk, char *buffer)
67447 {
67448- return sprintf(buffer, "%u\n", mk->mod->core_size);
67449+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
67450 }
67451
67452 static struct module_attribute modinfo_coresize =
67453@@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
67454 static ssize_t show_initsize(struct module_attribute *mattr,
67455 struct module_kobject *mk, char *buffer)
67456 {
67457- return sprintf(buffer, "%u\n", mk->mod->init_size);
67458+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
67459 }
67460
67461 static struct module_attribute modinfo_initsize =
67462@@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
67463 */
67464 #ifdef CONFIG_SYSFS
67465
67466-#ifdef CONFIG_KALLSYMS
67467+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67468 static inline bool sect_empty(const Elf_Shdr *sect)
67469 {
67470 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
67471@@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
67472
67473 static void unset_module_core_ro_nx(struct module *mod)
67474 {
67475- set_page_attributes(mod->module_core + mod->core_text_size,
67476- mod->module_core + mod->core_size,
67477+ set_page_attributes(mod->module_core_rw,
67478+ mod->module_core_rw + mod->core_size_rw,
67479 set_memory_x);
67480- set_page_attributes(mod->module_core,
67481- mod->module_core + mod->core_ro_size,
67482+ set_page_attributes(mod->module_core_rx,
67483+ mod->module_core_rx + mod->core_size_rx,
67484 set_memory_rw);
67485 }
67486
67487 static void unset_module_init_ro_nx(struct module *mod)
67488 {
67489- set_page_attributes(mod->module_init + mod->init_text_size,
67490- mod->module_init + mod->init_size,
67491+ set_page_attributes(mod->module_init_rw,
67492+ mod->module_init_rw + mod->init_size_rw,
67493 set_memory_x);
67494- set_page_attributes(mod->module_init,
67495- mod->module_init + mod->init_ro_size,
67496+ set_page_attributes(mod->module_init_rx,
67497+ mod->module_init_rx + mod->init_size_rx,
67498 set_memory_rw);
67499 }
67500
67501@@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
67502
67503 mutex_lock(&module_mutex);
67504 list_for_each_entry_rcu(mod, &modules, list) {
67505- if ((mod->module_core) && (mod->core_text_size)) {
67506- set_page_attributes(mod->module_core,
67507- mod->module_core + mod->core_text_size,
67508+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
67509+ set_page_attributes(mod->module_core_rx,
67510+ mod->module_core_rx + mod->core_size_rx,
67511 set_memory_rw);
67512 }
67513- if ((mod->module_init) && (mod->init_text_size)) {
67514- set_page_attributes(mod->module_init,
67515- mod->module_init + mod->init_text_size,
67516+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
67517+ set_page_attributes(mod->module_init_rx,
67518+ mod->module_init_rx + mod->init_size_rx,
67519 set_memory_rw);
67520 }
67521 }
67522@@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
67523
67524 mutex_lock(&module_mutex);
67525 list_for_each_entry_rcu(mod, &modules, list) {
67526- if ((mod->module_core) && (mod->core_text_size)) {
67527- set_page_attributes(mod->module_core,
67528- mod->module_core + mod->core_text_size,
67529+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
67530+ set_page_attributes(mod->module_core_rx,
67531+ mod->module_core_rx + mod->core_size_rx,
67532 set_memory_ro);
67533 }
67534- if ((mod->module_init) && (mod->init_text_size)) {
67535- set_page_attributes(mod->module_init,
67536- mod->module_init + mod->init_text_size,
67537+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
67538+ set_page_attributes(mod->module_init_rx,
67539+ mod->module_init_rx + mod->init_size_rx,
67540 set_memory_ro);
67541 }
67542 }
67543@@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
67544
67545 /* This may be NULL, but that's OK */
67546 unset_module_init_ro_nx(mod);
67547- module_free(mod, mod->module_init);
67548+ module_free(mod, mod->module_init_rw);
67549+ module_free_exec(mod, mod->module_init_rx);
67550 kfree(mod->args);
67551 percpu_modfree(mod);
67552
67553 /* Free lock-classes: */
67554- lockdep_free_key_range(mod->module_core, mod->core_size);
67555+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
67556+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
67557
67558 /* Finally, free the core (containing the module structure) */
67559 unset_module_core_ro_nx(mod);
67560- module_free(mod, mod->module_core);
67561+ module_free_exec(mod, mod->module_core_rx);
67562+ module_free(mod, mod->module_core_rw);
67563
67564 #ifdef CONFIG_MPU
67565 update_protections(current->mm);
67566@@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67567 int ret = 0;
67568 const struct kernel_symbol *ksym;
67569
67570+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67571+ int is_fs_load = 0;
67572+ int register_filesystem_found = 0;
67573+ char *p;
67574+
67575+ p = strstr(mod->args, "grsec_modharden_fs");
67576+ if (p) {
67577+ char *endptr = p + strlen("grsec_modharden_fs");
67578+ /* copy \0 as well */
67579+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
67580+ is_fs_load = 1;
67581+ }
67582+#endif
67583+
67584 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
67585 const char *name = info->strtab + sym[i].st_name;
67586
67587+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67588+ /* it's a real shame this will never get ripped and copied
67589+ upstream! ;(
67590+ */
67591+ if (is_fs_load && !strcmp(name, "register_filesystem"))
67592+ register_filesystem_found = 1;
67593+#endif
67594+
67595 switch (sym[i].st_shndx) {
67596 case SHN_COMMON:
67597 /* We compiled with -fno-common. These are not
67598@@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67599 ksym = resolve_symbol_wait(mod, info, name);
67600 /* Ok if resolved. */
67601 if (ksym && !IS_ERR(ksym)) {
67602+ pax_open_kernel();
67603 sym[i].st_value = ksym->value;
67604+ pax_close_kernel();
67605 break;
67606 }
67607
67608@@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67609 secbase = (unsigned long)mod_percpu(mod);
67610 else
67611 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
67612+ pax_open_kernel();
67613 sym[i].st_value += secbase;
67614+ pax_close_kernel();
67615 break;
67616 }
67617 }
67618
67619+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67620+ if (is_fs_load && !register_filesystem_found) {
67621+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
67622+ ret = -EPERM;
67623+ }
67624+#endif
67625+
67626 return ret;
67627 }
67628
67629@@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
67630 || s->sh_entsize != ~0UL
67631 || strstarts(sname, ".init"))
67632 continue;
67633- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
67634+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67635+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
67636+ else
67637+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
67638 pr_debug("\t%s\n", sname);
67639 }
67640- switch (m) {
67641- case 0: /* executable */
67642- mod->core_size = debug_align(mod->core_size);
67643- mod->core_text_size = mod->core_size;
67644- break;
67645- case 1: /* RO: text and ro-data */
67646- mod->core_size = debug_align(mod->core_size);
67647- mod->core_ro_size = mod->core_size;
67648- break;
67649- case 3: /* whole core */
67650- mod->core_size = debug_align(mod->core_size);
67651- break;
67652- }
67653 }
67654
67655 pr_debug("Init section allocation order:\n");
67656@@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
67657 || s->sh_entsize != ~0UL
67658 || !strstarts(sname, ".init"))
67659 continue;
67660- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
67661- | INIT_OFFSET_MASK);
67662+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67663+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
67664+ else
67665+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
67666+ s->sh_entsize |= INIT_OFFSET_MASK;
67667 pr_debug("\t%s\n", sname);
67668 }
67669- switch (m) {
67670- case 0: /* executable */
67671- mod->init_size = debug_align(mod->init_size);
67672- mod->init_text_size = mod->init_size;
67673- break;
67674- case 1: /* RO: text and ro-data */
67675- mod->init_size = debug_align(mod->init_size);
67676- mod->init_ro_size = mod->init_size;
67677- break;
67678- case 3: /* whole init */
67679- mod->init_size = debug_align(mod->init_size);
67680- break;
67681- }
67682 }
67683 }
67684
67685@@ -2266,7 +2284,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67686
67687 /* Put symbol section at end of init part of module. */
67688 symsect->sh_flags |= SHF_ALLOC;
67689- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
67690+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
67691 info->index.sym) | INIT_OFFSET_MASK;
67692 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
67693
67694@@ -2281,13 +2299,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67695 }
67696
67697 /* Append room for core symbols at end of core part. */
67698- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
67699- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
67700- mod->core_size += strtab_size;
67701+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
67702+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
67703+ mod->core_size_rx += strtab_size;
67704
67705 /* Put string table section at end of init part of module. */
67706 strsect->sh_flags |= SHF_ALLOC;
67707- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
67708+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
67709 info->index.str) | INIT_OFFSET_MASK;
67710 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
67711 }
67712@@ -2305,12 +2323,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67713 /* Make sure we get permanent strtab: don't use info->strtab. */
67714 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
67715
67716+ pax_open_kernel();
67717+
67718 /* Set types up while we still have access to sections. */
67719 for (i = 0; i < mod->num_symtab; i++)
67720 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
67721
67722- mod->core_symtab = dst = mod->module_core + info->symoffs;
67723- mod->core_strtab = s = mod->module_core + info->stroffs;
67724+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
67725+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
67726 src = mod->symtab;
67727 *dst = *src;
67728 *s++ = 0;
67729@@ -2323,6 +2343,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67730 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
67731 }
67732 mod->core_num_syms = ndst;
67733+
67734+ pax_close_kernel();
67735 }
67736 #else
67737 static inline void layout_symtab(struct module *mod, struct load_info *info)
67738@@ -2356,17 +2378,33 @@ void * __weak module_alloc(unsigned long size)
67739 return size == 0 ? NULL : vmalloc_exec(size);
67740 }
67741
67742-static void *module_alloc_update_bounds(unsigned long size)
67743+static void *module_alloc_update_bounds_rw(unsigned long size)
67744 {
67745 void *ret = module_alloc(size);
67746
67747 if (ret) {
67748 mutex_lock(&module_mutex);
67749 /* Update module bounds. */
67750- if ((unsigned long)ret < module_addr_min)
67751- module_addr_min = (unsigned long)ret;
67752- if ((unsigned long)ret + size > module_addr_max)
67753- module_addr_max = (unsigned long)ret + size;
67754+ if ((unsigned long)ret < module_addr_min_rw)
67755+ module_addr_min_rw = (unsigned long)ret;
67756+ if ((unsigned long)ret + size > module_addr_max_rw)
67757+ module_addr_max_rw = (unsigned long)ret + size;
67758+ mutex_unlock(&module_mutex);
67759+ }
67760+ return ret;
67761+}
67762+
67763+static void *module_alloc_update_bounds_rx(unsigned long size)
67764+{
67765+ void *ret = module_alloc_exec(size);
67766+
67767+ if (ret) {
67768+ mutex_lock(&module_mutex);
67769+ /* Update module bounds. */
67770+ if ((unsigned long)ret < module_addr_min_rx)
67771+ module_addr_min_rx = (unsigned long)ret;
67772+ if ((unsigned long)ret + size > module_addr_max_rx)
67773+ module_addr_max_rx = (unsigned long)ret + size;
67774 mutex_unlock(&module_mutex);
67775 }
67776 return ret;
67777@@ -2544,8 +2582,14 @@ static struct module *setup_load_info(struct load_info *info)
67778 static int check_modinfo(struct module *mod, struct load_info *info)
67779 {
67780 const char *modmagic = get_modinfo(info, "vermagic");
67781+ const char *license = get_modinfo(info, "license");
67782 int err;
67783
67784+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
67785+ if (!license || !license_is_gpl_compatible(license))
67786+ return -ENOEXEC;
67787+#endif
67788+
67789 /* This is allowed: modprobe --force will invalidate it. */
67790 if (!modmagic) {
67791 err = try_to_force_load(mod, "bad vermagic");
67792@@ -2568,7 +2612,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
67793 }
67794
67795 /* Set up license info based on the info section */
67796- set_license(mod, get_modinfo(info, "license"));
67797+ set_license(mod, license);
67798
67799 return 0;
67800 }
67801@@ -2662,7 +2706,7 @@ static int move_module(struct module *mod, struct load_info *info)
67802 void *ptr;
67803
67804 /* Do the allocs. */
67805- ptr = module_alloc_update_bounds(mod->core_size);
67806+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
67807 /*
67808 * The pointer to this block is stored in the module structure
67809 * which is inside the block. Just mark it as not being a
67810@@ -2672,23 +2716,50 @@ static int move_module(struct module *mod, struct load_info *info)
67811 if (!ptr)
67812 return -ENOMEM;
67813
67814- memset(ptr, 0, mod->core_size);
67815- mod->module_core = ptr;
67816+ memset(ptr, 0, mod->core_size_rw);
67817+ mod->module_core_rw = ptr;
67818
67819- ptr = module_alloc_update_bounds(mod->init_size);
67820+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
67821 /*
67822 * The pointer to this block is stored in the module structure
67823 * which is inside the block. This block doesn't need to be
67824 * scanned as it contains data and code that will be freed
67825 * after the module is initialized.
67826 */
67827- kmemleak_ignore(ptr);
67828- if (!ptr && mod->init_size) {
67829- module_free(mod, mod->module_core);
67830+ kmemleak_not_leak(ptr);
67831+ if (!ptr && mod->init_size_rw) {
67832+ module_free(mod, mod->module_core_rw);
67833 return -ENOMEM;
67834 }
67835- memset(ptr, 0, mod->init_size);
67836- mod->module_init = ptr;
67837+ memset(ptr, 0, mod->init_size_rw);
67838+ mod->module_init_rw = ptr;
67839+
67840+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
67841+ kmemleak_not_leak(ptr);
67842+ if (!ptr) {
67843+ module_free(mod, mod->module_init_rw);
67844+ module_free(mod, mod->module_core_rw);
67845+ return -ENOMEM;
67846+ }
67847+
67848+ pax_open_kernel();
67849+ memset(ptr, 0, mod->core_size_rx);
67850+ pax_close_kernel();
67851+ mod->module_core_rx = ptr;
67852+
67853+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
67854+ kmemleak_not_leak(ptr);
67855+ if (!ptr && mod->init_size_rx) {
67856+ module_free_exec(mod, mod->module_core_rx);
67857+ module_free(mod, mod->module_init_rw);
67858+ module_free(mod, mod->module_core_rw);
67859+ return -ENOMEM;
67860+ }
67861+
67862+ pax_open_kernel();
67863+ memset(ptr, 0, mod->init_size_rx);
67864+ pax_close_kernel();
67865+ mod->module_init_rx = ptr;
67866
67867 /* Transfer each section which specifies SHF_ALLOC */
67868 pr_debug("final section addresses:\n");
67869@@ -2699,16 +2770,45 @@ static int move_module(struct module *mod, struct load_info *info)
67870 if (!(shdr->sh_flags & SHF_ALLOC))
67871 continue;
67872
67873- if (shdr->sh_entsize & INIT_OFFSET_MASK)
67874- dest = mod->module_init
67875- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67876- else
67877- dest = mod->module_core + shdr->sh_entsize;
67878+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
67879+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67880+ dest = mod->module_init_rw
67881+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67882+ else
67883+ dest = mod->module_init_rx
67884+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67885+ } else {
67886+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67887+ dest = mod->module_core_rw + shdr->sh_entsize;
67888+ else
67889+ dest = mod->module_core_rx + shdr->sh_entsize;
67890+ }
67891+
67892+ if (shdr->sh_type != SHT_NOBITS) {
67893+
67894+#ifdef CONFIG_PAX_KERNEXEC
67895+#ifdef CONFIG_X86_64
67896+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
67897+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
67898+#endif
67899+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
67900+ pax_open_kernel();
67901+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67902+ pax_close_kernel();
67903+ } else
67904+#endif
67905
67906- if (shdr->sh_type != SHT_NOBITS)
67907 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67908+ }
67909 /* Update sh_addr to point to copy in image. */
67910- shdr->sh_addr = (unsigned long)dest;
67911+
67912+#ifdef CONFIG_PAX_KERNEXEC
67913+ if (shdr->sh_flags & SHF_EXECINSTR)
67914+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
67915+ else
67916+#endif
67917+
67918+ shdr->sh_addr = (unsigned long)dest;
67919 pr_debug("\t0x%lx %s\n",
67920 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
67921 }
67922@@ -2759,12 +2859,12 @@ static void flush_module_icache(const struct module *mod)
67923 * Do it before processing of module parameters, so the module
67924 * can provide parameter accessor functions of its own.
67925 */
67926- if (mod->module_init)
67927- flush_icache_range((unsigned long)mod->module_init,
67928- (unsigned long)mod->module_init
67929- + mod->init_size);
67930- flush_icache_range((unsigned long)mod->module_core,
67931- (unsigned long)mod->module_core + mod->core_size);
67932+ if (mod->module_init_rx)
67933+ flush_icache_range((unsigned long)mod->module_init_rx,
67934+ (unsigned long)mod->module_init_rx
67935+ + mod->init_size_rx);
67936+ flush_icache_range((unsigned long)mod->module_core_rx,
67937+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
67938
67939 set_fs(old_fs);
67940 }
67941@@ -2834,8 +2934,10 @@ out:
67942 static void module_deallocate(struct module *mod, struct load_info *info)
67943 {
67944 percpu_modfree(mod);
67945- module_free(mod, mod->module_init);
67946- module_free(mod, mod->module_core);
67947+ module_free_exec(mod, mod->module_init_rx);
67948+ module_free_exec(mod, mod->module_core_rx);
67949+ module_free(mod, mod->module_init_rw);
67950+ module_free(mod, mod->module_core_rw);
67951 }
67952
67953 int __weak module_finalize(const Elf_Ehdr *hdr,
67954@@ -2848,7 +2950,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
67955 static int post_relocation(struct module *mod, const struct load_info *info)
67956 {
67957 /* Sort exception table now relocations are done. */
67958+ pax_open_kernel();
67959 sort_extable(mod->extable, mod->extable + mod->num_exentries);
67960+ pax_close_kernel();
67961
67962 /* Copy relocated percpu area over. */
67963 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
67964@@ -2899,9 +3003,38 @@ static struct module *load_module(void __user *umod,
67965 if (err)
67966 goto free_unload;
67967
67968+ /* Now copy in args */
67969+ mod->args = strndup_user(uargs, ~0UL >> 1);
67970+ if (IS_ERR(mod->args)) {
67971+ err = PTR_ERR(mod->args);
67972+ goto free_unload;
67973+ }
67974+
67975 /* Set up MODINFO_ATTR fields */
67976 setup_modinfo(mod, &info);
67977
67978+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67979+ {
67980+ char *p, *p2;
67981+
67982+ if (strstr(mod->args, "grsec_modharden_netdev")) {
67983+ 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);
67984+ err = -EPERM;
67985+ goto free_modinfo;
67986+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
67987+ p += strlen("grsec_modharden_normal");
67988+ p2 = strstr(p, "_");
67989+ if (p2) {
67990+ *p2 = '\0';
67991+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
67992+ *p2 = '_';
67993+ }
67994+ err = -EPERM;
67995+ goto free_modinfo;
67996+ }
67997+ }
67998+#endif
67999+
68000 /* Fix up syms, so that st_value is a pointer to location. */
68001 err = simplify_symbols(mod, &info);
68002 if (err < 0)
68003@@ -2917,13 +3050,6 @@ static struct module *load_module(void __user *umod,
68004
68005 flush_module_icache(mod);
68006
68007- /* Now copy in args */
68008- mod->args = strndup_user(uargs, ~0UL >> 1);
68009- if (IS_ERR(mod->args)) {
68010- err = PTR_ERR(mod->args);
68011- goto free_arch_cleanup;
68012- }
68013-
68014 /* Mark state as coming so strong_try_module_get() ignores us. */
68015 mod->state = MODULE_STATE_COMING;
68016
68017@@ -2981,11 +3107,10 @@ static struct module *load_module(void __user *umod,
68018 unlock:
68019 mutex_unlock(&module_mutex);
68020 synchronize_sched();
68021- kfree(mod->args);
68022- free_arch_cleanup:
68023 module_arch_cleanup(mod);
68024 free_modinfo:
68025 free_modinfo(mod);
68026+ kfree(mod->args);
68027 free_unload:
68028 module_unload_free(mod);
68029 free_module:
68030@@ -3026,16 +3151,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68031 MODULE_STATE_COMING, mod);
68032
68033 /* Set RO and NX regions for core */
68034- set_section_ro_nx(mod->module_core,
68035- mod->core_text_size,
68036- mod->core_ro_size,
68037- mod->core_size);
68038+ set_section_ro_nx(mod->module_core_rx,
68039+ mod->core_size_rx,
68040+ mod->core_size_rx,
68041+ mod->core_size_rx);
68042
68043 /* Set RO and NX regions for init */
68044- set_section_ro_nx(mod->module_init,
68045- mod->init_text_size,
68046- mod->init_ro_size,
68047- mod->init_size);
68048+ set_section_ro_nx(mod->module_init_rx,
68049+ mod->init_size_rx,
68050+ mod->init_size_rx,
68051+ mod->init_size_rx);
68052
68053 do_mod_ctors(mod);
68054 /* Start the module */
68055@@ -3081,11 +3206,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68056 mod->strtab = mod->core_strtab;
68057 #endif
68058 unset_module_init_ro_nx(mod);
68059- module_free(mod, mod->module_init);
68060- mod->module_init = NULL;
68061- mod->init_size = 0;
68062- mod->init_ro_size = 0;
68063- mod->init_text_size = 0;
68064+ module_free(mod, mod->module_init_rw);
68065+ module_free_exec(mod, mod->module_init_rx);
68066+ mod->module_init_rw = NULL;
68067+ mod->module_init_rx = NULL;
68068+ mod->init_size_rw = 0;
68069+ mod->init_size_rx = 0;
68070 mutex_unlock(&module_mutex);
68071
68072 return 0;
68073@@ -3116,10 +3242,16 @@ static const char *get_ksymbol(struct module *mod,
68074 unsigned long nextval;
68075
68076 /* At worse, next value is at end of module */
68077- if (within_module_init(addr, mod))
68078- nextval = (unsigned long)mod->module_init+mod->init_text_size;
68079+ if (within_module_init_rx(addr, mod))
68080+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
68081+ else if (within_module_init_rw(addr, mod))
68082+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
68083+ else if (within_module_core_rx(addr, mod))
68084+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
68085+ else if (within_module_core_rw(addr, mod))
68086+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
68087 else
68088- nextval = (unsigned long)mod->module_core+mod->core_text_size;
68089+ return NULL;
68090
68091 /* Scan for closest preceding symbol, and next symbol. (ELF
68092 starts real symbols at 1). */
68093@@ -3354,7 +3486,7 @@ static int m_show(struct seq_file *m, void *p)
68094 char buf[8];
68095
68096 seq_printf(m, "%s %u",
68097- mod->name, mod->init_size + mod->core_size);
68098+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
68099 print_unload_info(m, mod);
68100
68101 /* Informative for users. */
68102@@ -3363,7 +3495,7 @@ static int m_show(struct seq_file *m, void *p)
68103 mod->state == MODULE_STATE_COMING ? "Loading":
68104 "Live");
68105 /* Used by oprofile and other similar tools. */
68106- seq_printf(m, " 0x%pK", mod->module_core);
68107+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
68108
68109 /* Taints info */
68110 if (mod->taints)
68111@@ -3399,7 +3531,17 @@ static const struct file_operations proc_modules_operations = {
68112
68113 static int __init proc_modules_init(void)
68114 {
68115+#ifndef CONFIG_GRKERNSEC_HIDESYM
68116+#ifdef CONFIG_GRKERNSEC_PROC_USER
68117+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68118+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68119+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
68120+#else
68121 proc_create("modules", 0, NULL, &proc_modules_operations);
68122+#endif
68123+#else
68124+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68125+#endif
68126 return 0;
68127 }
68128 module_init(proc_modules_init);
68129@@ -3458,12 +3600,12 @@ struct module *__module_address(unsigned long addr)
68130 {
68131 struct module *mod;
68132
68133- if (addr < module_addr_min || addr > module_addr_max)
68134+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
68135+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
68136 return NULL;
68137
68138 list_for_each_entry_rcu(mod, &modules, list)
68139- if (within_module_core(addr, mod)
68140- || within_module_init(addr, mod))
68141+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
68142 return mod;
68143 return NULL;
68144 }
68145@@ -3497,11 +3639,20 @@ bool is_module_text_address(unsigned long addr)
68146 */
68147 struct module *__module_text_address(unsigned long addr)
68148 {
68149- struct module *mod = __module_address(addr);
68150+ struct module *mod;
68151+
68152+#ifdef CONFIG_X86_32
68153+ addr = ktla_ktva(addr);
68154+#endif
68155+
68156+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
68157+ return NULL;
68158+
68159+ mod = __module_address(addr);
68160+
68161 if (mod) {
68162 /* Make sure it's within the text section. */
68163- if (!within(addr, mod->module_init, mod->init_text_size)
68164- && !within(addr, mod->module_core, mod->core_text_size))
68165+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
68166 mod = NULL;
68167 }
68168 return mod;
68169diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
68170index 7e3443f..b2a1e6b 100644
68171--- a/kernel/mutex-debug.c
68172+++ b/kernel/mutex-debug.c
68173@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
68174 }
68175
68176 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68177- struct thread_info *ti)
68178+ struct task_struct *task)
68179 {
68180 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
68181
68182 /* Mark the current thread as blocked on the lock: */
68183- ti->task->blocked_on = waiter;
68184+ task->blocked_on = waiter;
68185 }
68186
68187 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68188- struct thread_info *ti)
68189+ struct task_struct *task)
68190 {
68191 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
68192- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
68193- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
68194- ti->task->blocked_on = NULL;
68195+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
68196+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
68197+ task->blocked_on = NULL;
68198
68199 list_del_init(&waiter->list);
68200 waiter->task = NULL;
68201diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
68202index 0799fd3..d06ae3b 100644
68203--- a/kernel/mutex-debug.h
68204+++ b/kernel/mutex-debug.h
68205@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
68206 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
68207 extern void debug_mutex_add_waiter(struct mutex *lock,
68208 struct mutex_waiter *waiter,
68209- struct thread_info *ti);
68210+ struct task_struct *task);
68211 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68212- struct thread_info *ti);
68213+ struct task_struct *task);
68214 extern void debug_mutex_unlock(struct mutex *lock);
68215 extern void debug_mutex_init(struct mutex *lock, const char *name,
68216 struct lock_class_key *key);
68217diff --git a/kernel/mutex.c b/kernel/mutex.c
68218index a307cc9..27fd2e9 100644
68219--- a/kernel/mutex.c
68220+++ b/kernel/mutex.c
68221@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68222 spin_lock_mutex(&lock->wait_lock, flags);
68223
68224 debug_mutex_lock_common(lock, &waiter);
68225- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
68226+ debug_mutex_add_waiter(lock, &waiter, task);
68227
68228 /* add waiting tasks to the end of the waitqueue (FIFO): */
68229 list_add_tail(&waiter.list, &lock->wait_list);
68230@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68231 * TASK_UNINTERRUPTIBLE case.)
68232 */
68233 if (unlikely(signal_pending_state(state, task))) {
68234- mutex_remove_waiter(lock, &waiter,
68235- task_thread_info(task));
68236+ mutex_remove_waiter(lock, &waiter, task);
68237 mutex_release(&lock->dep_map, 1, ip);
68238 spin_unlock_mutex(&lock->wait_lock, flags);
68239
68240@@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68241 done:
68242 lock_acquired(&lock->dep_map, ip);
68243 /* got the lock - rejoice! */
68244- mutex_remove_waiter(lock, &waiter, current_thread_info());
68245+ mutex_remove_waiter(lock, &waiter, task);
68246 mutex_set_owner(lock);
68247
68248 /* set it to 0 if there are no waiters left: */
68249diff --git a/kernel/panic.c b/kernel/panic.c
68250index d2a5f4e..5edc1d9 100644
68251--- a/kernel/panic.c
68252+++ b/kernel/panic.c
68253@@ -75,6 +75,14 @@ void panic(const char *fmt, ...)
68254 int state = 0;
68255
68256 /*
68257+ * Disable local interrupts. This will prevent panic_smp_self_stop
68258+ * from deadlocking the first cpu that invokes the panic, since
68259+ * there is nothing to prevent an interrupt handler (that runs
68260+ * after the panic_lock is acquired) from invoking panic again.
68261+ */
68262+ local_irq_disable();
68263+
68264+ /*
68265 * It's possible to come here directly from a panic-assertion and
68266 * not have preempt disabled. Some functions called from here want
68267 * preempt to be disabled. No point enabling it later though...
68268@@ -402,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
68269 const char *board;
68270
68271 printk(KERN_WARNING "------------[ cut here ]------------\n");
68272- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
68273+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
68274 board = dmi_get_system_info(DMI_PRODUCT_NAME);
68275 if (board)
68276 printk(KERN_WARNING "Hardware name: %s\n", board);
68277@@ -457,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
68278 */
68279 void __stack_chk_fail(void)
68280 {
68281- panic("stack-protector: Kernel stack is corrupted in: %p\n",
68282+ dump_stack();
68283+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
68284 __builtin_return_address(0));
68285 }
68286 EXPORT_SYMBOL(__stack_chk_fail);
68287diff --git a/kernel/pid.c b/kernel/pid.c
68288index e86b291a..e8b0fb5 100644
68289--- a/kernel/pid.c
68290+++ b/kernel/pid.c
68291@@ -33,6 +33,7 @@
68292 #include <linux/rculist.h>
68293 #include <linux/bootmem.h>
68294 #include <linux/hash.h>
68295+#include <linux/security.h>
68296 #include <linux/pid_namespace.h>
68297 #include <linux/init_task.h>
68298 #include <linux/syscalls.h>
68299@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
68300
68301 int pid_max = PID_MAX_DEFAULT;
68302
68303-#define RESERVED_PIDS 300
68304+#define RESERVED_PIDS 500
68305
68306 int pid_max_min = RESERVED_PIDS + 1;
68307 int pid_max_max = PID_MAX_LIMIT;
68308@@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
68309 */
68310 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
68311 {
68312+ struct task_struct *task;
68313+
68314 rcu_lockdep_assert(rcu_read_lock_held(),
68315 "find_task_by_pid_ns() needs rcu_read_lock()"
68316 " protection");
68317- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68318+
68319+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68320+
68321+ if (gr_pid_is_chrooted(task))
68322+ return NULL;
68323+
68324+ return task;
68325 }
68326
68327 struct task_struct *find_task_by_vpid(pid_t vnr)
68328@@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
68329 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
68330 }
68331
68332+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
68333+{
68334+ rcu_lockdep_assert(rcu_read_lock_held(),
68335+ "find_task_by_pid_ns() needs rcu_read_lock()"
68336+ " protection");
68337+ return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
68338+}
68339+
68340 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
68341 {
68342 struct pid *pid;
68343diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
68344index 125cb67..a4d1c30 100644
68345--- a/kernel/posix-cpu-timers.c
68346+++ b/kernel/posix-cpu-timers.c
68347@@ -6,6 +6,7 @@
68348 #include <linux/posix-timers.h>
68349 #include <linux/errno.h>
68350 #include <linux/math64.h>
68351+#include <linux/security.h>
68352 #include <asm/uaccess.h>
68353 #include <linux/kernel_stat.h>
68354 #include <trace/events/timer.h>
68355@@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
68356
68357 static __init int init_posix_cpu_timers(void)
68358 {
68359- struct k_clock process = {
68360+ static struct k_clock process = {
68361 .clock_getres = process_cpu_clock_getres,
68362 .clock_get = process_cpu_clock_get,
68363 .timer_create = process_cpu_timer_create,
68364 .nsleep = process_cpu_nsleep,
68365 .nsleep_restart = process_cpu_nsleep_restart,
68366 };
68367- struct k_clock thread = {
68368+ static struct k_clock thread = {
68369 .clock_getres = thread_cpu_clock_getres,
68370 .clock_get = thread_cpu_clock_get,
68371 .timer_create = thread_cpu_timer_create,
68372diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
68373index 69185ae..cc2847a 100644
68374--- a/kernel/posix-timers.c
68375+++ b/kernel/posix-timers.c
68376@@ -43,6 +43,7 @@
68377 #include <linux/idr.h>
68378 #include <linux/posix-clock.h>
68379 #include <linux/posix-timers.h>
68380+#include <linux/grsecurity.h>
68381 #include <linux/syscalls.h>
68382 #include <linux/wait.h>
68383 #include <linux/workqueue.h>
68384@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
68385 * which we beg off on and pass to do_sys_settimeofday().
68386 */
68387
68388-static struct k_clock posix_clocks[MAX_CLOCKS];
68389+static struct k_clock *posix_clocks[MAX_CLOCKS];
68390
68391 /*
68392 * These ones are defined below.
68393@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
68394 */
68395 static __init int init_posix_timers(void)
68396 {
68397- struct k_clock clock_realtime = {
68398+ static struct k_clock clock_realtime = {
68399 .clock_getres = hrtimer_get_res,
68400 .clock_get = posix_clock_realtime_get,
68401 .clock_set = posix_clock_realtime_set,
68402@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
68403 .timer_get = common_timer_get,
68404 .timer_del = common_timer_del,
68405 };
68406- struct k_clock clock_monotonic = {
68407+ static struct k_clock clock_monotonic = {
68408 .clock_getres = hrtimer_get_res,
68409 .clock_get = posix_ktime_get_ts,
68410 .nsleep = common_nsleep,
68411@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
68412 .timer_get = common_timer_get,
68413 .timer_del = common_timer_del,
68414 };
68415- struct k_clock clock_monotonic_raw = {
68416+ static struct k_clock clock_monotonic_raw = {
68417 .clock_getres = hrtimer_get_res,
68418 .clock_get = posix_get_monotonic_raw,
68419 };
68420- struct k_clock clock_realtime_coarse = {
68421+ static struct k_clock clock_realtime_coarse = {
68422 .clock_getres = posix_get_coarse_res,
68423 .clock_get = posix_get_realtime_coarse,
68424 };
68425- struct k_clock clock_monotonic_coarse = {
68426+ static struct k_clock clock_monotonic_coarse = {
68427 .clock_getres = posix_get_coarse_res,
68428 .clock_get = posix_get_monotonic_coarse,
68429 };
68430- struct k_clock clock_boottime = {
68431+ static struct k_clock clock_boottime = {
68432 .clock_getres = hrtimer_get_res,
68433 .clock_get = posix_get_boottime,
68434 .nsleep = common_nsleep,
68435@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
68436 return;
68437 }
68438
68439- posix_clocks[clock_id] = *new_clock;
68440+ posix_clocks[clock_id] = new_clock;
68441 }
68442 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
68443
68444@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
68445 return (id & CLOCKFD_MASK) == CLOCKFD ?
68446 &clock_posix_dynamic : &clock_posix_cpu;
68447
68448- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
68449+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
68450 return NULL;
68451- return &posix_clocks[id];
68452+ return posix_clocks[id];
68453 }
68454
68455 static int common_timer_create(struct k_itimer *new_timer)
68456@@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
68457 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
68458 return -EFAULT;
68459
68460+ /* only the CLOCK_REALTIME clock can be set, all other clocks
68461+ have their clock_set fptr set to a nosettime dummy function
68462+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
68463+ call common_clock_set, which calls do_sys_settimeofday, which
68464+ we hook
68465+ */
68466+
68467 return kc->clock_set(which_clock, &new_tp);
68468 }
68469
68470diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
68471index d523593..68197a4 100644
68472--- a/kernel/power/poweroff.c
68473+++ b/kernel/power/poweroff.c
68474@@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
68475 .enable_mask = SYSRQ_ENABLE_BOOT,
68476 };
68477
68478-static int pm_sysrq_init(void)
68479+static int __init pm_sysrq_init(void)
68480 {
68481 register_sysrq_key('o', &sysrq_poweroff_op);
68482 return 0;
68483diff --git a/kernel/power/process.c b/kernel/power/process.c
68484index 19db29f..33b52b6 100644
68485--- a/kernel/power/process.c
68486+++ b/kernel/power/process.c
68487@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
68488 u64 elapsed_csecs64;
68489 unsigned int elapsed_csecs;
68490 bool wakeup = false;
68491+ bool timedout = false;
68492
68493 do_gettimeofday(&start);
68494
68495@@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
68496
68497 while (true) {
68498 todo = 0;
68499+ if (time_after(jiffies, end_time))
68500+ timedout = true;
68501 read_lock(&tasklist_lock);
68502 do_each_thread(g, p) {
68503 if (p == current || !freeze_task(p))
68504@@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
68505 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
68506 * transition can't race with task state testing here.
68507 */
68508- if (!task_is_stopped_or_traced(p) &&
68509- !freezer_should_skip(p))
68510+ if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
68511 todo++;
68512+ if (timedout) {
68513+ printk(KERN_ERR "Task refusing to freeze:\n");
68514+ sched_show_task(p);
68515+ }
68516+ }
68517 } while_each_thread(g, p);
68518 read_unlock(&tasklist_lock);
68519
68520@@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
68521 todo += wq_busy;
68522 }
68523
68524- if (!todo || time_after(jiffies, end_time))
68525+ if (!todo || timedout)
68526 break;
68527
68528 if (pm_wakeup_pending()) {
68529diff --git a/kernel/printk.c b/kernel/printk.c
68530index 146827f..a501fec 100644
68531--- a/kernel/printk.c
68532+++ b/kernel/printk.c
68533@@ -782,6 +782,11 @@ static int check_syslog_permissions(int type, bool from_file)
68534 if (from_file && type != SYSLOG_ACTION_OPEN)
68535 return 0;
68536
68537+#ifdef CONFIG_GRKERNSEC_DMESG
68538+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
68539+ return -EPERM;
68540+#endif
68541+
68542 if (syslog_action_restricted(type)) {
68543 if (capable(CAP_SYSLOG))
68544 return 0;
68545diff --git a/kernel/profile.c b/kernel/profile.c
68546index 76b8e77..a2930e8 100644
68547--- a/kernel/profile.c
68548+++ b/kernel/profile.c
68549@@ -39,7 +39,7 @@ struct profile_hit {
68550 /* Oprofile timer tick hook */
68551 static int (*timer_hook)(struct pt_regs *) __read_mostly;
68552
68553-static atomic_t *prof_buffer;
68554+static atomic_unchecked_t *prof_buffer;
68555 static unsigned long prof_len, prof_shift;
68556
68557 int prof_on __read_mostly;
68558@@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
68559 hits[i].pc = 0;
68560 continue;
68561 }
68562- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
68563+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
68564 hits[i].hits = hits[i].pc = 0;
68565 }
68566 }
68567@@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
68568 * Add the current hit(s) and flush the write-queue out
68569 * to the global buffer:
68570 */
68571- atomic_add(nr_hits, &prof_buffer[pc]);
68572+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
68573 for (i = 0; i < NR_PROFILE_HIT; ++i) {
68574- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
68575+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
68576 hits[i].pc = hits[i].hits = 0;
68577 }
68578 out:
68579@@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
68580 {
68581 unsigned long pc;
68582 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
68583- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68584+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68585 }
68586 #endif /* !CONFIG_SMP */
68587
68588@@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
68589 return -EFAULT;
68590 buf++; p++; count--; read++;
68591 }
68592- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
68593+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
68594 if (copy_to_user(buf, (void *)pnt, count))
68595 return -EFAULT;
68596 read += count;
68597@@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
68598 }
68599 #endif
68600 profile_discard_flip_buffers();
68601- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
68602+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
68603 return count;
68604 }
68605
68606diff --git a/kernel/ptrace.c b/kernel/ptrace.c
68607index a232bb5..2a65ef9 100644
68608--- a/kernel/ptrace.c
68609+++ b/kernel/ptrace.c
68610@@ -279,7 +279,7 @@ static int ptrace_attach(struct task_struct *task, long request,
68611
68612 if (seize)
68613 flags |= PT_SEIZED;
68614- if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
68615+ if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
68616 flags |= PT_PTRACE_CAP;
68617 task->ptrace = flags;
68618
68619@@ -486,7 +486,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
68620 break;
68621 return -EIO;
68622 }
68623- if (copy_to_user(dst, buf, retval))
68624+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
68625 return -EFAULT;
68626 copied += retval;
68627 src += retval;
68628@@ -671,7 +671,7 @@ int ptrace_request(struct task_struct *child, long request,
68629 bool seized = child->ptrace & PT_SEIZED;
68630 int ret = -EIO;
68631 siginfo_t siginfo, *si;
68632- void __user *datavp = (void __user *) data;
68633+ void __user *datavp = (__force void __user *) data;
68634 unsigned long __user *datalp = datavp;
68635 unsigned long flags;
68636
68637@@ -873,14 +873,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
68638 goto out;
68639 }
68640
68641+ if (gr_handle_ptrace(child, request)) {
68642+ ret = -EPERM;
68643+ goto out_put_task_struct;
68644+ }
68645+
68646 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68647 ret = ptrace_attach(child, request, addr, data);
68648 /*
68649 * Some architectures need to do book-keeping after
68650 * a ptrace attach.
68651 */
68652- if (!ret)
68653+ if (!ret) {
68654 arch_ptrace_attach(child);
68655+ gr_audit_ptrace(child);
68656+ }
68657 goto out_put_task_struct;
68658 }
68659
68660@@ -906,7 +913,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
68661 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
68662 if (copied != sizeof(tmp))
68663 return -EIO;
68664- return put_user(tmp, (unsigned long __user *)data);
68665+ return put_user(tmp, (__force unsigned long __user *)data);
68666 }
68667
68668 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
68669@@ -1016,14 +1023,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
68670 goto out;
68671 }
68672
68673+ if (gr_handle_ptrace(child, request)) {
68674+ ret = -EPERM;
68675+ goto out_put_task_struct;
68676+ }
68677+
68678 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68679 ret = ptrace_attach(child, request, addr, data);
68680 /*
68681 * Some architectures need to do book-keeping after
68682 * a ptrace attach.
68683 */
68684- if (!ret)
68685+ if (!ret) {
68686 arch_ptrace_attach(child);
68687+ gr_audit_ptrace(child);
68688+ }
68689 goto out_put_task_struct;
68690 }
68691
68692diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
68693index 37a5444..eec170a 100644
68694--- a/kernel/rcutiny.c
68695+++ b/kernel/rcutiny.c
68696@@ -46,7 +46,7 @@
68697 struct rcu_ctrlblk;
68698 static void invoke_rcu_callbacks(void);
68699 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
68700-static void rcu_process_callbacks(struct softirq_action *unused);
68701+static void rcu_process_callbacks(void);
68702 static void __call_rcu(struct rcu_head *head,
68703 void (*func)(struct rcu_head *rcu),
68704 struct rcu_ctrlblk *rcp);
68705@@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
68706 rcu_is_callbacks_kthread()));
68707 }
68708
68709-static void rcu_process_callbacks(struct softirq_action *unused)
68710+static void rcu_process_callbacks(void)
68711 {
68712 __rcu_process_callbacks(&rcu_sched_ctrlblk);
68713 __rcu_process_callbacks(&rcu_bh_ctrlblk);
68714diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
68715index fc31a2d..be2ec04 100644
68716--- a/kernel/rcutiny_plugin.h
68717+++ b/kernel/rcutiny_plugin.h
68718@@ -939,7 +939,7 @@ static int rcu_kthread(void *arg)
68719 have_rcu_kthread_work = morework;
68720 local_irq_restore(flags);
68721 if (work)
68722- rcu_process_callbacks(NULL);
68723+ rcu_process_callbacks();
68724 schedule_timeout_interruptible(1); /* Leave CPU for others. */
68725 }
68726
68727diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
68728index e66b34a..4b8b626 100644
68729--- a/kernel/rcutorture.c
68730+++ b/kernel/rcutorture.c
68731@@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
68732 { 0 };
68733 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
68734 { 0 };
68735-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68736-static atomic_t n_rcu_torture_alloc;
68737-static atomic_t n_rcu_torture_alloc_fail;
68738-static atomic_t n_rcu_torture_free;
68739-static atomic_t n_rcu_torture_mberror;
68740-static atomic_t n_rcu_torture_error;
68741+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68742+static atomic_unchecked_t n_rcu_torture_alloc;
68743+static atomic_unchecked_t n_rcu_torture_alloc_fail;
68744+static atomic_unchecked_t n_rcu_torture_free;
68745+static atomic_unchecked_t n_rcu_torture_mberror;
68746+static atomic_unchecked_t n_rcu_torture_error;
68747 static long n_rcu_torture_barrier_error;
68748 static long n_rcu_torture_boost_ktrerror;
68749 static long n_rcu_torture_boost_rterror;
68750@@ -265,11 +265,11 @@ rcu_torture_alloc(void)
68751
68752 spin_lock_bh(&rcu_torture_lock);
68753 if (list_empty(&rcu_torture_freelist)) {
68754- atomic_inc(&n_rcu_torture_alloc_fail);
68755+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
68756 spin_unlock_bh(&rcu_torture_lock);
68757 return NULL;
68758 }
68759- atomic_inc(&n_rcu_torture_alloc);
68760+ atomic_inc_unchecked(&n_rcu_torture_alloc);
68761 p = rcu_torture_freelist.next;
68762 list_del_init(p);
68763 spin_unlock_bh(&rcu_torture_lock);
68764@@ -282,7 +282,7 @@ rcu_torture_alloc(void)
68765 static void
68766 rcu_torture_free(struct rcu_torture *p)
68767 {
68768- atomic_inc(&n_rcu_torture_free);
68769+ atomic_inc_unchecked(&n_rcu_torture_free);
68770 spin_lock_bh(&rcu_torture_lock);
68771 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
68772 spin_unlock_bh(&rcu_torture_lock);
68773@@ -403,7 +403,7 @@ rcu_torture_cb(struct rcu_head *p)
68774 i = rp->rtort_pipe_count;
68775 if (i > RCU_TORTURE_PIPE_LEN)
68776 i = RCU_TORTURE_PIPE_LEN;
68777- atomic_inc(&rcu_torture_wcount[i]);
68778+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
68779 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68780 rp->rtort_mbtest = 0;
68781 rcu_torture_free(rp);
68782@@ -451,7 +451,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
68783 i = rp->rtort_pipe_count;
68784 if (i > RCU_TORTURE_PIPE_LEN)
68785 i = RCU_TORTURE_PIPE_LEN;
68786- atomic_inc(&rcu_torture_wcount[i]);
68787+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
68788 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68789 rp->rtort_mbtest = 0;
68790 list_del(&rp->rtort_free);
68791@@ -983,7 +983,7 @@ rcu_torture_writer(void *arg)
68792 i = old_rp->rtort_pipe_count;
68793 if (i > RCU_TORTURE_PIPE_LEN)
68794 i = RCU_TORTURE_PIPE_LEN;
68795- atomic_inc(&rcu_torture_wcount[i]);
68796+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
68797 old_rp->rtort_pipe_count++;
68798 cur_ops->deferred_free(old_rp);
68799 }
68800@@ -1064,7 +1064,7 @@ static void rcu_torture_timer(unsigned long unused)
68801 }
68802 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
68803 if (p->rtort_mbtest == 0)
68804- atomic_inc(&n_rcu_torture_mberror);
68805+ atomic_inc_unchecked(&n_rcu_torture_mberror);
68806 spin_lock(&rand_lock);
68807 cur_ops->read_delay(&rand);
68808 n_rcu_torture_timers++;
68809@@ -1128,7 +1128,7 @@ rcu_torture_reader(void *arg)
68810 }
68811 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
68812 if (p->rtort_mbtest == 0)
68813- atomic_inc(&n_rcu_torture_mberror);
68814+ atomic_inc_unchecked(&n_rcu_torture_mberror);
68815 cur_ops->read_delay(&rand);
68816 preempt_disable();
68817 pipe_count = p->rtort_pipe_count;
68818@@ -1191,10 +1191,10 @@ rcu_torture_printk(char *page)
68819 rcu_torture_current,
68820 rcu_torture_current_version,
68821 list_empty(&rcu_torture_freelist),
68822- atomic_read(&n_rcu_torture_alloc),
68823- atomic_read(&n_rcu_torture_alloc_fail),
68824- atomic_read(&n_rcu_torture_free),
68825- atomic_read(&n_rcu_torture_mberror),
68826+ atomic_read_unchecked(&n_rcu_torture_alloc),
68827+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
68828+ atomic_read_unchecked(&n_rcu_torture_free),
68829+ atomic_read_unchecked(&n_rcu_torture_mberror),
68830 n_rcu_torture_boost_ktrerror,
68831 n_rcu_torture_boost_rterror,
68832 n_rcu_torture_boost_failure,
68833@@ -1208,14 +1208,14 @@ rcu_torture_printk(char *page)
68834 n_barrier_attempts,
68835 n_rcu_torture_barrier_error);
68836 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
68837- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
68838+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
68839 n_rcu_torture_barrier_error != 0 ||
68840 n_rcu_torture_boost_ktrerror != 0 ||
68841 n_rcu_torture_boost_rterror != 0 ||
68842 n_rcu_torture_boost_failure != 0 ||
68843 i > 1) {
68844 cnt += sprintf(&page[cnt], "!!! ");
68845- atomic_inc(&n_rcu_torture_error);
68846+ atomic_inc_unchecked(&n_rcu_torture_error);
68847 WARN_ON_ONCE(1);
68848 }
68849 cnt += sprintf(&page[cnt], "Reader Pipe: ");
68850@@ -1229,7 +1229,7 @@ rcu_torture_printk(char *page)
68851 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
68852 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68853 cnt += sprintf(&page[cnt], " %d",
68854- atomic_read(&rcu_torture_wcount[i]));
68855+ atomic_read_unchecked(&rcu_torture_wcount[i]));
68856 }
68857 cnt += sprintf(&page[cnt], "\n");
68858 if (cur_ops->stats)
68859@@ -1888,7 +1888,7 @@ rcu_torture_cleanup(void)
68860
68861 if (cur_ops->cleanup)
68862 cur_ops->cleanup();
68863- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
68864+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
68865 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
68866 else if (n_online_successes != n_online_attempts ||
68867 n_offline_successes != n_offline_attempts)
68868@@ -1958,18 +1958,18 @@ rcu_torture_init(void)
68869
68870 rcu_torture_current = NULL;
68871 rcu_torture_current_version = 0;
68872- atomic_set(&n_rcu_torture_alloc, 0);
68873- atomic_set(&n_rcu_torture_alloc_fail, 0);
68874- atomic_set(&n_rcu_torture_free, 0);
68875- atomic_set(&n_rcu_torture_mberror, 0);
68876- atomic_set(&n_rcu_torture_error, 0);
68877+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
68878+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
68879+ atomic_set_unchecked(&n_rcu_torture_free, 0);
68880+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
68881+ atomic_set_unchecked(&n_rcu_torture_error, 0);
68882 n_rcu_torture_barrier_error = 0;
68883 n_rcu_torture_boost_ktrerror = 0;
68884 n_rcu_torture_boost_rterror = 0;
68885 n_rcu_torture_boost_failure = 0;
68886 n_rcu_torture_boosts = 0;
68887 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
68888- atomic_set(&rcu_torture_wcount[i], 0);
68889+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
68890 for_each_possible_cpu(cpu) {
68891 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68892 per_cpu(rcu_torture_count, cpu)[i] = 0;
68893diff --git a/kernel/rcutree.c b/kernel/rcutree.c
68894index 4b97bba..b92c9d2 100644
68895--- a/kernel/rcutree.c
68896+++ b/kernel/rcutree.c
68897@@ -366,9 +366,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
68898 rcu_prepare_for_idle(smp_processor_id());
68899 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68900 smp_mb__before_atomic_inc(); /* See above. */
68901- atomic_inc(&rdtp->dynticks);
68902+ atomic_inc_unchecked(&rdtp->dynticks);
68903 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
68904- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68905+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68906
68907 /*
68908 * The idle task is not permitted to enter the idle loop while
68909@@ -457,10 +457,10 @@ void rcu_irq_exit(void)
68910 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
68911 {
68912 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
68913- atomic_inc(&rdtp->dynticks);
68914+ atomic_inc_unchecked(&rdtp->dynticks);
68915 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68916 smp_mb__after_atomic_inc(); /* See above. */
68917- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68918+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68919 rcu_cleanup_after_idle(smp_processor_id());
68920 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
68921 if (!is_idle_task(current)) {
68922@@ -554,14 +554,14 @@ void rcu_nmi_enter(void)
68923 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
68924
68925 if (rdtp->dynticks_nmi_nesting == 0 &&
68926- (atomic_read(&rdtp->dynticks) & 0x1))
68927+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
68928 return;
68929 rdtp->dynticks_nmi_nesting++;
68930 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
68931- atomic_inc(&rdtp->dynticks);
68932+ atomic_inc_unchecked(&rdtp->dynticks);
68933 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68934 smp_mb__after_atomic_inc(); /* See above. */
68935- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68936+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68937 }
68938
68939 /**
68940@@ -580,9 +580,9 @@ void rcu_nmi_exit(void)
68941 return;
68942 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68943 smp_mb__before_atomic_inc(); /* See above. */
68944- atomic_inc(&rdtp->dynticks);
68945+ atomic_inc_unchecked(&rdtp->dynticks);
68946 smp_mb__after_atomic_inc(); /* Force delay to next write. */
68947- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68948+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68949 }
68950
68951 #ifdef CONFIG_PROVE_RCU
68952@@ -598,7 +598,7 @@ int rcu_is_cpu_idle(void)
68953 int ret;
68954
68955 preempt_disable();
68956- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
68957+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
68958 preempt_enable();
68959 return ret;
68960 }
68961@@ -668,7 +668,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
68962 */
68963 static int dyntick_save_progress_counter(struct rcu_data *rdp)
68964 {
68965- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
68966+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68967 return (rdp->dynticks_snap & 0x1) == 0;
68968 }
68969
68970@@ -683,7 +683,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
68971 unsigned int curr;
68972 unsigned int snap;
68973
68974- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
68975+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68976 snap = (unsigned int)rdp->dynticks_snap;
68977
68978 /*
68979@@ -713,10 +713,10 @@ static int jiffies_till_stall_check(void)
68980 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
68981 */
68982 if (till_stall_check < 3) {
68983- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
68984+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
68985 till_stall_check = 3;
68986 } else if (till_stall_check > 300) {
68987- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
68988+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
68989 till_stall_check = 300;
68990 }
68991 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
68992@@ -1824,7 +1824,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
68993 /*
68994 * Do RCU core processing for the current CPU.
68995 */
68996-static void rcu_process_callbacks(struct softirq_action *unused)
68997+static void rcu_process_callbacks(void)
68998 {
68999 trace_rcu_utilization("Start RCU core");
69000 __rcu_process_callbacks(&rcu_sched_state,
69001@@ -2042,8 +2042,8 @@ void synchronize_rcu_bh(void)
69002 }
69003 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
69004
69005-static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
69006-static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
69007+static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
69008+static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
69009
69010 static int synchronize_sched_expedited_cpu_stop(void *data)
69011 {
69012@@ -2104,7 +2104,7 @@ void synchronize_sched_expedited(void)
69013 int firstsnap, s, snap, trycount = 0;
69014
69015 /* Note that atomic_inc_return() implies full memory barrier. */
69016- firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
69017+ firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
69018 get_online_cpus();
69019 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
69020
69021@@ -2126,7 +2126,7 @@ void synchronize_sched_expedited(void)
69022 }
69023
69024 /* Check to see if someone else did our work for us. */
69025- s = atomic_read(&sync_sched_expedited_done);
69026+ s = atomic_read_unchecked(&sync_sched_expedited_done);
69027 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
69028 smp_mb(); /* ensure test happens before caller kfree */
69029 return;
69030@@ -2141,7 +2141,7 @@ void synchronize_sched_expedited(void)
69031 * grace period works for us.
69032 */
69033 get_online_cpus();
69034- snap = atomic_read(&sync_sched_expedited_started);
69035+ snap = atomic_read_unchecked(&sync_sched_expedited_started);
69036 smp_mb(); /* ensure read is before try_stop_cpus(). */
69037 }
69038
69039@@ -2152,12 +2152,12 @@ void synchronize_sched_expedited(void)
69040 * than we did beat us to the punch.
69041 */
69042 do {
69043- s = atomic_read(&sync_sched_expedited_done);
69044+ s = atomic_read_unchecked(&sync_sched_expedited_done);
69045 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
69046 smp_mb(); /* ensure test happens before caller kfree */
69047 break;
69048 }
69049- } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
69050+ } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
69051
69052 put_online_cpus();
69053 }
69054@@ -2421,7 +2421,7 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
69055 rdp->qlen = 0;
69056 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
69057 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
69058- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
69059+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
69060 rdp->cpu = cpu;
69061 rdp->rsp = rsp;
69062 raw_spin_unlock_irqrestore(&rnp->lock, flags);
69063@@ -2449,8 +2449,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
69064 rdp->n_force_qs_snap = rsp->n_force_qs;
69065 rdp->blimit = blimit;
69066 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
69067- atomic_set(&rdp->dynticks->dynticks,
69068- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
69069+ atomic_set_unchecked(&rdp->dynticks->dynticks,
69070+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
69071 rcu_prepare_for_idle_init(cpu);
69072 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
69073
69074diff --git a/kernel/rcutree.h b/kernel/rcutree.h
69075index 19b61ac..5c60a94 100644
69076--- a/kernel/rcutree.h
69077+++ b/kernel/rcutree.h
69078@@ -83,7 +83,7 @@ struct rcu_dynticks {
69079 long long dynticks_nesting; /* Track irq/process nesting level. */
69080 /* Process level is worth LLONG_MAX/2. */
69081 int dynticks_nmi_nesting; /* Track NMI nesting level. */
69082- atomic_t dynticks; /* Even value for idle, else odd. */
69083+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
69084 #ifdef CONFIG_RCU_FAST_NO_HZ
69085 int dyntick_drain; /* Prepare-for-idle state variable. */
69086 unsigned long dyntick_holdoff;
69087diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
69088index 3e48994..d94f03a 100644
69089--- a/kernel/rcutree_plugin.h
69090+++ b/kernel/rcutree_plugin.h
69091@@ -909,7 +909,7 @@ void synchronize_rcu_expedited(void)
69092
69093 /* Clean up and exit. */
69094 smp_mb(); /* ensure expedited GP seen before counter increment. */
69095- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
69096+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
69097 unlock_mb_ret:
69098 mutex_unlock(&sync_rcu_preempt_exp_mutex);
69099 mb_ret:
69100diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
69101index d4bc16d..c234a5c 100644
69102--- a/kernel/rcutree_trace.c
69103+++ b/kernel/rcutree_trace.c
69104@@ -68,7 +68,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
69105 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69106 rdp->qs_pending);
69107 seq_printf(m, " dt=%d/%llx/%d df=%lu",
69108- atomic_read(&rdp->dynticks->dynticks),
69109+ atomic_read_unchecked(&rdp->dynticks->dynticks),
69110 rdp->dynticks->dynticks_nesting,
69111 rdp->dynticks->dynticks_nmi_nesting,
69112 rdp->dynticks_fqs);
69113@@ -140,7 +140,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
69114 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69115 rdp->qs_pending);
69116 seq_printf(m, ",%d,%llx,%d,%lu",
69117- atomic_read(&rdp->dynticks->dynticks),
69118+ atomic_read_unchecked(&rdp->dynticks->dynticks),
69119 rdp->dynticks->dynticks_nesting,
69120 rdp->dynticks->dynticks_nmi_nesting,
69121 rdp->dynticks_fqs);
69122diff --git a/kernel/resource.c b/kernel/resource.c
69123index e1d2b8e..24820bb 100644
69124--- a/kernel/resource.c
69125+++ b/kernel/resource.c
69126@@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
69127
69128 static int __init ioresources_init(void)
69129 {
69130+#ifdef CONFIG_GRKERNSEC_PROC_ADD
69131+#ifdef CONFIG_GRKERNSEC_PROC_USER
69132+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
69133+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
69134+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69135+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
69136+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
69137+#endif
69138+#else
69139 proc_create("ioports", 0, NULL, &proc_ioports_operations);
69140 proc_create("iomem", 0, NULL, &proc_iomem_operations);
69141+#endif
69142 return 0;
69143 }
69144 __initcall(ioresources_init);
69145diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
69146index 98ec494..4241d6d 100644
69147--- a/kernel/rtmutex-tester.c
69148+++ b/kernel/rtmutex-tester.c
69149@@ -20,7 +20,7 @@
69150 #define MAX_RT_TEST_MUTEXES 8
69151
69152 static spinlock_t rttest_lock;
69153-static atomic_t rttest_event;
69154+static atomic_unchecked_t rttest_event;
69155
69156 struct test_thread_data {
69157 int opcode;
69158@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69159
69160 case RTTEST_LOCKCONT:
69161 td->mutexes[td->opdata] = 1;
69162- td->event = atomic_add_return(1, &rttest_event);
69163+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69164 return 0;
69165
69166 case RTTEST_RESET:
69167@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69168 return 0;
69169
69170 case RTTEST_RESETEVENT:
69171- atomic_set(&rttest_event, 0);
69172+ atomic_set_unchecked(&rttest_event, 0);
69173 return 0;
69174
69175 default:
69176@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69177 return ret;
69178
69179 td->mutexes[id] = 1;
69180- td->event = atomic_add_return(1, &rttest_event);
69181+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69182 rt_mutex_lock(&mutexes[id]);
69183- td->event = atomic_add_return(1, &rttest_event);
69184+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69185 td->mutexes[id] = 4;
69186 return 0;
69187
69188@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69189 return ret;
69190
69191 td->mutexes[id] = 1;
69192- td->event = atomic_add_return(1, &rttest_event);
69193+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69194 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
69195- td->event = atomic_add_return(1, &rttest_event);
69196+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69197 td->mutexes[id] = ret ? 0 : 4;
69198 return ret ? -EINTR : 0;
69199
69200@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69201 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
69202 return ret;
69203
69204- td->event = atomic_add_return(1, &rttest_event);
69205+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69206 rt_mutex_unlock(&mutexes[id]);
69207- td->event = atomic_add_return(1, &rttest_event);
69208+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69209 td->mutexes[id] = 0;
69210 return 0;
69211
69212@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69213 break;
69214
69215 td->mutexes[dat] = 2;
69216- td->event = atomic_add_return(1, &rttest_event);
69217+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69218 break;
69219
69220 default:
69221@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69222 return;
69223
69224 td->mutexes[dat] = 3;
69225- td->event = atomic_add_return(1, &rttest_event);
69226+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69227 break;
69228
69229 case RTTEST_LOCKNOWAIT:
69230@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69231 return;
69232
69233 td->mutexes[dat] = 1;
69234- td->event = atomic_add_return(1, &rttest_event);
69235+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69236 return;
69237
69238 default:
69239diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
69240index 0984a21..939f183 100644
69241--- a/kernel/sched/auto_group.c
69242+++ b/kernel/sched/auto_group.c
69243@@ -11,7 +11,7 @@
69244
69245 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
69246 static struct autogroup autogroup_default;
69247-static atomic_t autogroup_seq_nr;
69248+static atomic_unchecked_t autogroup_seq_nr;
69249
69250 void __init autogroup_init(struct task_struct *init_task)
69251 {
69252@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
69253
69254 kref_init(&ag->kref);
69255 init_rwsem(&ag->lock);
69256- ag->id = atomic_inc_return(&autogroup_seq_nr);
69257+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
69258 ag->tg = tg;
69259 #ifdef CONFIG_RT_GROUP_SCHED
69260 /*
69261diff --git a/kernel/sched/core.c b/kernel/sched/core.c
69262index 468bdd4..b941572 100644
69263--- a/kernel/sched/core.c
69264+++ b/kernel/sched/core.c
69265@@ -4097,6 +4097,8 @@ int can_nice(const struct task_struct *p, const int nice)
69266 /* convert nice value [19,-20] to rlimit style value [1,40] */
69267 int nice_rlim = 20 - nice;
69268
69269+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
69270+
69271 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
69272 capable(CAP_SYS_NICE));
69273 }
69274@@ -4130,7 +4132,8 @@ SYSCALL_DEFINE1(nice, int, increment)
69275 if (nice > 19)
69276 nice = 19;
69277
69278- if (increment < 0 && !can_nice(current, nice))
69279+ if (increment < 0 && (!can_nice(current, nice) ||
69280+ gr_handle_chroot_nice()))
69281 return -EPERM;
69282
69283 retval = security_task_setnice(current, nice);
69284@@ -4284,6 +4287,7 @@ recheck:
69285 unsigned long rlim_rtprio =
69286 task_rlimit(p, RLIMIT_RTPRIO);
69287
69288+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
69289 /* can't set/change the rt policy */
69290 if (policy != p->policy && !rlim_rtprio)
69291 return -EPERM;
69292diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
69293index c099cc6..06aec4f 100644
69294--- a/kernel/sched/fair.c
69295+++ b/kernel/sched/fair.c
69296@@ -4846,7 +4846,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
69297 * run_rebalance_domains is triggered when needed from the scheduler tick.
69298 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
69299 */
69300-static void run_rebalance_domains(struct softirq_action *h)
69301+static void run_rebalance_domains(void)
69302 {
69303 int this_cpu = smp_processor_id();
69304 struct rq *this_rq = cpu_rq(this_cpu);
69305diff --git a/kernel/signal.c b/kernel/signal.c
69306index 6771027..763e51e 100644
69307--- a/kernel/signal.c
69308+++ b/kernel/signal.c
69309@@ -48,12 +48,12 @@ static struct kmem_cache *sigqueue_cachep;
69310
69311 int print_fatal_signals __read_mostly;
69312
69313-static void __user *sig_handler(struct task_struct *t, int sig)
69314+static __sighandler_t sig_handler(struct task_struct *t, int sig)
69315 {
69316 return t->sighand->action[sig - 1].sa.sa_handler;
69317 }
69318
69319-static int sig_handler_ignored(void __user *handler, int sig)
69320+static int sig_handler_ignored(__sighandler_t handler, int sig)
69321 {
69322 /* Is it explicitly or implicitly ignored? */
69323 return handler == SIG_IGN ||
69324@@ -62,7 +62,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
69325
69326 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
69327 {
69328- void __user *handler;
69329+ __sighandler_t handler;
69330
69331 handler = sig_handler(t, sig);
69332
69333@@ -366,6 +366,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
69334 atomic_inc(&user->sigpending);
69335 rcu_read_unlock();
69336
69337+ if (!override_rlimit)
69338+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
69339+
69340 if (override_rlimit ||
69341 atomic_read(&user->sigpending) <=
69342 task_rlimit(t, RLIMIT_SIGPENDING)) {
69343@@ -490,7 +493,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
69344
69345 int unhandled_signal(struct task_struct *tsk, int sig)
69346 {
69347- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
69348+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
69349 if (is_global_init(tsk))
69350 return 1;
69351 if (handler != SIG_IGN && handler != SIG_DFL)
69352@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
69353 }
69354 }
69355
69356+ /* allow glibc communication via tgkill to other threads in our
69357+ thread group */
69358+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
69359+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
69360+ && gr_handle_signal(t, sig))
69361+ return -EPERM;
69362+
69363 return security_task_kill(t, info, sig, 0);
69364 }
69365
69366@@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69367 return send_signal(sig, info, p, 1);
69368 }
69369
69370-static int
69371+int
69372 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69373 {
69374 return send_signal(sig, info, t, 0);
69375@@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69376 unsigned long int flags;
69377 int ret, blocked, ignored;
69378 struct k_sigaction *action;
69379+ int is_unhandled = 0;
69380
69381 spin_lock_irqsave(&t->sighand->siglock, flags);
69382 action = &t->sighand->action[sig-1];
69383@@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69384 }
69385 if (action->sa.sa_handler == SIG_DFL)
69386 t->signal->flags &= ~SIGNAL_UNKILLABLE;
69387+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
69388+ is_unhandled = 1;
69389 ret = specific_send_sig_info(sig, info, t);
69390 spin_unlock_irqrestore(&t->sighand->siglock, flags);
69391
69392+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
69393+ normal operation */
69394+ if (is_unhandled) {
69395+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
69396+ gr_handle_crash(t, sig);
69397+ }
69398+
69399 return ret;
69400 }
69401
69402@@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69403 ret = check_kill_permission(sig, info, p);
69404 rcu_read_unlock();
69405
69406- if (!ret && sig)
69407+ if (!ret && sig) {
69408 ret = do_send_sig_info(sig, info, p, true);
69409+ if (!ret)
69410+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
69411+ }
69412
69413 return ret;
69414 }
69415@@ -2858,7 +2881,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
69416 int error = -ESRCH;
69417
69418 rcu_read_lock();
69419- p = find_task_by_vpid(pid);
69420+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69421+ /* allow glibc communication via tgkill to other threads in our
69422+ thread group */
69423+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
69424+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
69425+ p = find_task_by_vpid_unrestricted(pid);
69426+ else
69427+#endif
69428+ p = find_task_by_vpid(pid);
69429 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
69430 error = check_kill_permission(sig, info, p);
69431 /*
69432diff --git a/kernel/smp.c b/kernel/smp.c
69433index d0ae5b2..b87c5a8 100644
69434--- a/kernel/smp.c
69435+++ b/kernel/smp.c
69436@@ -582,22 +582,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
69437 }
69438 EXPORT_SYMBOL(smp_call_function);
69439
69440-void ipi_call_lock(void)
69441+void ipi_call_lock(void) __acquires(call_function.lock)
69442 {
69443 raw_spin_lock(&call_function.lock);
69444 }
69445
69446-void ipi_call_unlock(void)
69447+void ipi_call_unlock(void) __releases(call_function.lock)
69448 {
69449 raw_spin_unlock(&call_function.lock);
69450 }
69451
69452-void ipi_call_lock_irq(void)
69453+void ipi_call_lock_irq(void) __acquires(call_function.lock)
69454 {
69455 raw_spin_lock_irq(&call_function.lock);
69456 }
69457
69458-void ipi_call_unlock_irq(void)
69459+void ipi_call_unlock_irq(void) __releases(call_function.lock)
69460 {
69461 raw_spin_unlock_irq(&call_function.lock);
69462 }
69463diff --git a/kernel/softirq.c b/kernel/softirq.c
69464index 671f959..91c51cb 100644
69465--- a/kernel/softirq.c
69466+++ b/kernel/softirq.c
69467@@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
69468
69469 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
69470
69471-char *softirq_to_name[NR_SOFTIRQS] = {
69472+const char * const softirq_to_name[NR_SOFTIRQS] = {
69473 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
69474 "TASKLET", "SCHED", "HRTIMER", "RCU"
69475 };
69476@@ -235,7 +235,7 @@ restart:
69477 kstat_incr_softirqs_this_cpu(vec_nr);
69478
69479 trace_softirq_entry(vec_nr);
69480- h->action(h);
69481+ h->action();
69482 trace_softirq_exit(vec_nr);
69483 if (unlikely(prev_count != preempt_count())) {
69484 printk(KERN_ERR "huh, entered softirq %u %s %p"
69485@@ -381,9 +381,11 @@ void __raise_softirq_irqoff(unsigned int nr)
69486 or_softirq_pending(1UL << nr);
69487 }
69488
69489-void open_softirq(int nr, void (*action)(struct softirq_action *))
69490+void open_softirq(int nr, void (*action)(void))
69491 {
69492- softirq_vec[nr].action = action;
69493+ pax_open_kernel();
69494+ *(void **)&softirq_vec[nr].action = action;
69495+ pax_close_kernel();
69496 }
69497
69498 /*
69499@@ -437,7 +439,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
69500
69501 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
69502
69503-static void tasklet_action(struct softirq_action *a)
69504+static void tasklet_action(void)
69505 {
69506 struct tasklet_struct *list;
69507
69508@@ -472,7 +474,7 @@ static void tasklet_action(struct softirq_action *a)
69509 }
69510 }
69511
69512-static void tasklet_hi_action(struct softirq_action *a)
69513+static void tasklet_hi_action(void)
69514 {
69515 struct tasklet_struct *list;
69516
69517diff --git a/kernel/srcu.c b/kernel/srcu.c
69518index 2095be3..9a5b89d 100644
69519--- a/kernel/srcu.c
69520+++ b/kernel/srcu.c
69521@@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
69522 preempt_disable();
69523 idx = rcu_dereference_index_check(sp->completed,
69524 rcu_read_lock_sched_held()) & 0x1;
69525- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
69526+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
69527 smp_mb(); /* B */ /* Avoid leaking the critical section. */
69528- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
69529+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
69530 preempt_enable();
69531 return idx;
69532 }
69533@@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
69534 {
69535 preempt_disable();
69536 smp_mb(); /* C */ /* Avoid leaking the critical section. */
69537- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
69538+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
69539 preempt_enable();
69540 }
69541 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
69542diff --git a/kernel/sys.c b/kernel/sys.c
69543index 2d39a84..f778b49 100644
69544--- a/kernel/sys.c
69545+++ b/kernel/sys.c
69546@@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
69547 error = -EACCES;
69548 goto out;
69549 }
69550+
69551+ if (gr_handle_chroot_setpriority(p, niceval)) {
69552+ error = -EACCES;
69553+ goto out;
69554+ }
69555+
69556 no_nice = security_task_setnice(p, niceval);
69557 if (no_nice) {
69558 error = no_nice;
69559@@ -594,6 +600,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
69560 goto error;
69561 }
69562
69563+ if (gr_check_group_change(new->gid, new->egid, -1))
69564+ goto error;
69565+
69566 if (rgid != (gid_t) -1 ||
69567 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
69568 new->sgid = new->egid;
69569@@ -629,6 +638,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
69570 old = current_cred();
69571
69572 retval = -EPERM;
69573+
69574+ if (gr_check_group_change(kgid, kgid, kgid))
69575+ goto error;
69576+
69577 if (nsown_capable(CAP_SETGID))
69578 new->gid = new->egid = new->sgid = new->fsgid = kgid;
69579 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
69580@@ -646,7 +659,7 @@ error:
69581 /*
69582 * change the user struct in a credentials set to match the new UID
69583 */
69584-static int set_user(struct cred *new)
69585+int set_user(struct cred *new)
69586 {
69587 struct user_struct *new_user;
69588
69589@@ -726,6 +739,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
69590 goto error;
69591 }
69592
69593+ if (gr_check_user_change(new->uid, new->euid, -1))
69594+ goto error;
69595+
69596 if (!uid_eq(new->uid, old->uid)) {
69597 retval = set_user(new);
69598 if (retval < 0)
69599@@ -776,6 +792,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
69600 old = current_cred();
69601
69602 retval = -EPERM;
69603+
69604+ if (gr_check_crash_uid(kuid))
69605+ goto error;
69606+ if (gr_check_user_change(kuid, kuid, kuid))
69607+ goto error;
69608+
69609 if (nsown_capable(CAP_SETUID)) {
69610 new->suid = new->uid = kuid;
69611 if (!uid_eq(kuid, old->uid)) {
69612@@ -845,6 +867,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
69613 goto error;
69614 }
69615
69616+ if (gr_check_user_change(kruid, keuid, -1))
69617+ goto error;
69618+
69619 if (ruid != (uid_t) -1) {
69620 new->uid = kruid;
69621 if (!uid_eq(kruid, old->uid)) {
69622@@ -927,6 +952,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
69623 goto error;
69624 }
69625
69626+ if (gr_check_group_change(krgid, kegid, -1))
69627+ goto error;
69628+
69629 if (rgid != (gid_t) -1)
69630 new->gid = krgid;
69631 if (egid != (gid_t) -1)
69632@@ -980,6 +1008,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69633 if (!uid_valid(kuid))
69634 return old_fsuid;
69635
69636+ if (gr_check_user_change(-1, -1, kuid))
69637+ goto error;
69638+
69639 new = prepare_creds();
69640 if (!new)
69641 return old_fsuid;
69642@@ -994,6 +1025,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69643 }
69644 }
69645
69646+error:
69647 abort_creds(new);
69648 return old_fsuid;
69649
69650@@ -1026,12 +1058,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
69651 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
69652 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
69653 nsown_capable(CAP_SETGID)) {
69654+ if (gr_check_group_change(-1, -1, kgid))
69655+ goto error;
69656+
69657 if (!gid_eq(kgid, old->fsgid)) {
69658 new->fsgid = kgid;
69659 goto change_okay;
69660 }
69661 }
69662
69663+error:
69664 abort_creds(new);
69665 return old_fsgid;
69666
69667@@ -1283,7 +1319,10 @@ static int override_release(char __user *release, int len)
69668 }
69669 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
69670 snprintf(buf, len, "2.6.%u%s", v, rest);
69671- ret = copy_to_user(release, buf, len);
69672+ if (len > sizeof(buf))
69673+ ret = -EFAULT;
69674+ else
69675+ ret = copy_to_user(release, buf, len);
69676 }
69677 return ret;
69678 }
69679@@ -1337,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
69680 return -EFAULT;
69681
69682 down_read(&uts_sem);
69683- error = __copy_to_user(&name->sysname, &utsname()->sysname,
69684+ error = __copy_to_user(name->sysname, &utsname()->sysname,
69685 __OLD_UTS_LEN);
69686 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
69687- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
69688+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
69689 __OLD_UTS_LEN);
69690 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
69691- error |= __copy_to_user(&name->release, &utsname()->release,
69692+ error |= __copy_to_user(name->release, &utsname()->release,
69693 __OLD_UTS_LEN);
69694 error |= __put_user(0, name->release + __OLD_UTS_LEN);
69695- error |= __copy_to_user(&name->version, &utsname()->version,
69696+ error |= __copy_to_user(name->version, &utsname()->version,
69697 __OLD_UTS_LEN);
69698 error |= __put_user(0, name->version + __OLD_UTS_LEN);
69699- error |= __copy_to_user(&name->machine, &utsname()->machine,
69700+ error |= __copy_to_user(name->machine, &utsname()->machine,
69701 __OLD_UTS_LEN);
69702 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
69703 up_read(&uts_sem);
69704@@ -2024,7 +2063,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
69705 error = get_dumpable(me->mm);
69706 break;
69707 case PR_SET_DUMPABLE:
69708- if (arg2 < 0 || arg2 > 1) {
69709+ if (arg2 > 1) {
69710 error = -EINVAL;
69711 break;
69712 }
69713diff --git a/kernel/sysctl.c b/kernel/sysctl.c
69714index 4ab1187..33f4f2b 100644
69715--- a/kernel/sysctl.c
69716+++ b/kernel/sysctl.c
69717@@ -91,7 +91,6 @@
69718
69719
69720 #if defined(CONFIG_SYSCTL)
69721-
69722 /* External variables not in a header file. */
69723 extern int sysctl_overcommit_memory;
69724 extern int sysctl_overcommit_ratio;
69725@@ -169,10 +168,13 @@ static int proc_taint(struct ctl_table *table, int write,
69726 void __user *buffer, size_t *lenp, loff_t *ppos);
69727 #endif
69728
69729-#ifdef CONFIG_PRINTK
69730 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69731 void __user *buffer, size_t *lenp, loff_t *ppos);
69732-#endif
69733+
69734+static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
69735+ void __user *buffer, size_t *lenp, loff_t *ppos);
69736+static int proc_dostring_coredump(struct ctl_table *table, int write,
69737+ void __user *buffer, size_t *lenp, loff_t *ppos);
69738
69739 #ifdef CONFIG_MAGIC_SYSRQ
69740 /* Note: sysrq code uses it's own private copy */
69741@@ -196,6 +198,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
69742
69743 #endif
69744
69745+extern struct ctl_table grsecurity_table[];
69746+
69747 static struct ctl_table kern_table[];
69748 static struct ctl_table vm_table[];
69749 static struct ctl_table fs_table[];
69750@@ -210,6 +214,20 @@ extern struct ctl_table epoll_table[];
69751 int sysctl_legacy_va_layout;
69752 #endif
69753
69754+#ifdef CONFIG_PAX_SOFTMODE
69755+static ctl_table pax_table[] = {
69756+ {
69757+ .procname = "softmode",
69758+ .data = &pax_softmode,
69759+ .maxlen = sizeof(unsigned int),
69760+ .mode = 0600,
69761+ .proc_handler = &proc_dointvec,
69762+ },
69763+
69764+ { }
69765+};
69766+#endif
69767+
69768 /* The default sysctl tables: */
69769
69770 static struct ctl_table sysctl_base_table[] = {
69771@@ -256,6 +274,22 @@ static int max_extfrag_threshold = 1000;
69772 #endif
69773
69774 static struct ctl_table kern_table[] = {
69775+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
69776+ {
69777+ .procname = "grsecurity",
69778+ .mode = 0500,
69779+ .child = grsecurity_table,
69780+ },
69781+#endif
69782+
69783+#ifdef CONFIG_PAX_SOFTMODE
69784+ {
69785+ .procname = "pax",
69786+ .mode = 0500,
69787+ .child = pax_table,
69788+ },
69789+#endif
69790+
69791 {
69792 .procname = "sched_child_runs_first",
69793 .data = &sysctl_sched_child_runs_first,
69794@@ -410,7 +444,7 @@ static struct ctl_table kern_table[] = {
69795 .data = core_pattern,
69796 .maxlen = CORENAME_MAX_SIZE,
69797 .mode = 0644,
69798- .proc_handler = proc_dostring,
69799+ .proc_handler = proc_dostring_coredump,
69800 },
69801 {
69802 .procname = "core_pipe_limit",
69803@@ -540,7 +574,7 @@ static struct ctl_table kern_table[] = {
69804 .data = &modprobe_path,
69805 .maxlen = KMOD_PATH_LEN,
69806 .mode = 0644,
69807- .proc_handler = proc_dostring,
69808+ .proc_handler = proc_dostring_modpriv,
69809 },
69810 {
69811 .procname = "modules_disabled",
69812@@ -707,16 +741,20 @@ static struct ctl_table kern_table[] = {
69813 .extra1 = &zero,
69814 .extra2 = &one,
69815 },
69816+#endif
69817 {
69818 .procname = "kptr_restrict",
69819 .data = &kptr_restrict,
69820 .maxlen = sizeof(int),
69821 .mode = 0644,
69822 .proc_handler = proc_dointvec_minmax_sysadmin,
69823+#ifdef CONFIG_GRKERNSEC_HIDESYM
69824+ .extra1 = &two,
69825+#else
69826 .extra1 = &zero,
69827+#endif
69828 .extra2 = &two,
69829 },
69830-#endif
69831 {
69832 .procname = "ngroups_max",
69833 .data = &ngroups_max,
69834@@ -1215,6 +1253,13 @@ static struct ctl_table vm_table[] = {
69835 .proc_handler = proc_dointvec_minmax,
69836 .extra1 = &zero,
69837 },
69838+ {
69839+ .procname = "heap_stack_gap",
69840+ .data = &sysctl_heap_stack_gap,
69841+ .maxlen = sizeof(sysctl_heap_stack_gap),
69842+ .mode = 0644,
69843+ .proc_handler = proc_doulongvec_minmax,
69844+ },
69845 #else
69846 {
69847 .procname = "nr_trim_pages",
69848@@ -1498,7 +1543,7 @@ static struct ctl_table fs_table[] = {
69849 .data = &suid_dumpable,
69850 .maxlen = sizeof(int),
69851 .mode = 0644,
69852- .proc_handler = proc_dointvec_minmax,
69853+ .proc_handler = proc_dointvec_minmax_coredump,
69854 .extra1 = &zero,
69855 .extra2 = &two,
69856 },
69857@@ -1645,6 +1690,16 @@ int proc_dostring(struct ctl_table *table, int write,
69858 buffer, lenp, ppos);
69859 }
69860
69861+int proc_dostring_modpriv(struct ctl_table *table, int write,
69862+ void __user *buffer, size_t *lenp, loff_t *ppos)
69863+{
69864+ if (write && !capable(CAP_SYS_MODULE))
69865+ return -EPERM;
69866+
69867+ return _proc_do_string(table->data, table->maxlen, write,
69868+ buffer, lenp, ppos);
69869+}
69870+
69871 static size_t proc_skip_spaces(char **buf)
69872 {
69873 size_t ret;
69874@@ -1750,6 +1805,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
69875 len = strlen(tmp);
69876 if (len > *size)
69877 len = *size;
69878+ if (len > sizeof(tmp))
69879+ len = sizeof(tmp);
69880 if (copy_to_user(*buf, tmp, len))
69881 return -EFAULT;
69882 *size -= len;
69883@@ -1942,7 +1999,6 @@ static int proc_taint(struct ctl_table *table, int write,
69884 return err;
69885 }
69886
69887-#ifdef CONFIG_PRINTK
69888 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69889 void __user *buffer, size_t *lenp, loff_t *ppos)
69890 {
69891@@ -1951,7 +2007,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69892
69893 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
69894 }
69895-#endif
69896
69897 struct do_proc_dointvec_minmax_conv_param {
69898 int *min;
69899@@ -2009,6 +2064,34 @@ int proc_dointvec_minmax(struct ctl_table *table, int write,
69900 do_proc_dointvec_minmax_conv, &param);
69901 }
69902
69903+static void validate_coredump_safety(void)
69904+{
69905+ if (suid_dumpable == SUID_DUMPABLE_SAFE &&
69906+ core_pattern[0] != '/' && core_pattern[0] != '|') {
69907+ printk(KERN_WARNING "Unsafe core_pattern used with "\
69908+ "suid_dumpable=2. Pipe handler or fully qualified "\
69909+ "core dump path required.\n");
69910+ }
69911+}
69912+
69913+static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
69914+ void __user *buffer, size_t *lenp, loff_t *ppos)
69915+{
69916+ int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
69917+ if (!error)
69918+ validate_coredump_safety();
69919+ return error;
69920+}
69921+
69922+static int proc_dostring_coredump(struct ctl_table *table, int write,
69923+ void __user *buffer, size_t *lenp, loff_t *ppos)
69924+{
69925+ int error = proc_dostring(table, write, buffer, lenp, ppos);
69926+ if (!error)
69927+ validate_coredump_safety();
69928+ return error;
69929+}
69930+
69931 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
69932 void __user *buffer,
69933 size_t *lenp, loff_t *ppos,
69934@@ -2066,8 +2149,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
69935 *i = val;
69936 } else {
69937 val = convdiv * (*i) / convmul;
69938- if (!first)
69939+ if (!first) {
69940 err = proc_put_char(&buffer, &left, '\t');
69941+ if (err)
69942+ break;
69943+ }
69944 err = proc_put_long(&buffer, &left, val, false);
69945 if (err)
69946 break;
69947@@ -2459,6 +2545,12 @@ int proc_dostring(struct ctl_table *table, int write,
69948 return -ENOSYS;
69949 }
69950
69951+int proc_dostring_modpriv(struct ctl_table *table, int write,
69952+ void __user *buffer, size_t *lenp, loff_t *ppos)
69953+{
69954+ return -ENOSYS;
69955+}
69956+
69957 int proc_dointvec(struct ctl_table *table, int write,
69958 void __user *buffer, size_t *lenp, loff_t *ppos)
69959 {
69960@@ -2515,5 +2607,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
69961 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
69962 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
69963 EXPORT_SYMBOL(proc_dostring);
69964+EXPORT_SYMBOL(proc_dostring_modpriv);
69965 EXPORT_SYMBOL(proc_doulongvec_minmax);
69966 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
69967diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
69968index a650694..aaeeb20 100644
69969--- a/kernel/sysctl_binary.c
69970+++ b/kernel/sysctl_binary.c
69971@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
69972 int i;
69973
69974 set_fs(KERNEL_DS);
69975- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69976+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69977 set_fs(old_fs);
69978 if (result < 0)
69979 goto out_kfree;
69980@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
69981 }
69982
69983 set_fs(KERNEL_DS);
69984- result = vfs_write(file, buffer, str - buffer, &pos);
69985+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69986 set_fs(old_fs);
69987 if (result < 0)
69988 goto out_kfree;
69989@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
69990 int i;
69991
69992 set_fs(KERNEL_DS);
69993- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69994+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69995 set_fs(old_fs);
69996 if (result < 0)
69997 goto out_kfree;
69998@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
69999 }
70000
70001 set_fs(KERNEL_DS);
70002- result = vfs_write(file, buffer, str - buffer, &pos);
70003+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70004 set_fs(old_fs);
70005 if (result < 0)
70006 goto out_kfree;
70007@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
70008 int i;
70009
70010 set_fs(KERNEL_DS);
70011- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70012+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70013 set_fs(old_fs);
70014 if (result < 0)
70015 goto out;
70016@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70017 __le16 dnaddr;
70018
70019 set_fs(KERNEL_DS);
70020- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70021+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70022 set_fs(old_fs);
70023 if (result < 0)
70024 goto out;
70025@@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70026 le16_to_cpu(dnaddr) & 0x3ff);
70027
70028 set_fs(KERNEL_DS);
70029- result = vfs_write(file, buf, len, &pos);
70030+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
70031 set_fs(old_fs);
70032 if (result < 0)
70033 goto out;
70034diff --git a/kernel/taskstats.c b/kernel/taskstats.c
70035index e660464..c8b9e67 100644
70036--- a/kernel/taskstats.c
70037+++ b/kernel/taskstats.c
70038@@ -27,9 +27,12 @@
70039 #include <linux/cgroup.h>
70040 #include <linux/fs.h>
70041 #include <linux/file.h>
70042+#include <linux/grsecurity.h>
70043 #include <net/genetlink.h>
70044 #include <linux/atomic.h>
70045
70046+extern int gr_is_taskstats_denied(int pid);
70047+
70048 /*
70049 * Maximum length of a cpumask that can be specified in
70050 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
70051@@ -556,6 +559,9 @@ err:
70052
70053 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
70054 {
70055+ if (gr_is_taskstats_denied(current->pid))
70056+ return -EACCES;
70057+
70058 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
70059 return cmd_attr_register_cpumask(info);
70060 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
70061diff --git a/kernel/time.c b/kernel/time.c
70062index ba744cf..267b7c5 100644
70063--- a/kernel/time.c
70064+++ b/kernel/time.c
70065@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
70066 return error;
70067
70068 if (tz) {
70069+ /* we log in do_settimeofday called below, so don't log twice
70070+ */
70071+ if (!tv)
70072+ gr_log_timechange();
70073+
70074 sys_tz = *tz;
70075 update_vsyscall_tz();
70076 if (firsttime) {
70077diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
70078index aa27d39..34d221c 100644
70079--- a/kernel/time/alarmtimer.c
70080+++ b/kernel/time/alarmtimer.c
70081@@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
70082 struct platform_device *pdev;
70083 int error = 0;
70084 int i;
70085- struct k_clock alarm_clock = {
70086+ static struct k_clock alarm_clock = {
70087 .clock_getres = alarm_clock_getres,
70088 .clock_get = alarm_clock_get,
70089 .timer_create = alarm_timer_create,
70090diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
70091index f113755..ec24223 100644
70092--- a/kernel/time/tick-broadcast.c
70093+++ b/kernel/time/tick-broadcast.c
70094@@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
70095 * then clear the broadcast bit.
70096 */
70097 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
70098- int cpu = smp_processor_id();
70099+ cpu = smp_processor_id();
70100
70101 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
70102 tick_broadcast_clear_oneshot(cpu);
70103diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
70104index 3447cfa..291806b 100644
70105--- a/kernel/time/timekeeping.c
70106+++ b/kernel/time/timekeeping.c
70107@@ -14,6 +14,7 @@
70108 #include <linux/init.h>
70109 #include <linux/mm.h>
70110 #include <linux/sched.h>
70111+#include <linux/grsecurity.h>
70112 #include <linux/syscore_ops.h>
70113 #include <linux/clocksource.h>
70114 #include <linux/jiffies.h>
70115@@ -387,6 +388,8 @@ int do_settimeofday(const struct timespec *tv)
70116 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
70117 return -EINVAL;
70118
70119+ gr_log_timechange();
70120+
70121 write_seqlock_irqsave(&timekeeper.lock, flags);
70122
70123 timekeeping_forward_now();
70124diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
70125index 3258455..f35227d 100644
70126--- a/kernel/time/timer_list.c
70127+++ b/kernel/time/timer_list.c
70128@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
70129
70130 static void print_name_offset(struct seq_file *m, void *sym)
70131 {
70132+#ifdef CONFIG_GRKERNSEC_HIDESYM
70133+ SEQ_printf(m, "<%p>", NULL);
70134+#else
70135 char symname[KSYM_NAME_LEN];
70136
70137 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
70138 SEQ_printf(m, "<%pK>", sym);
70139 else
70140 SEQ_printf(m, "%s", symname);
70141+#endif
70142 }
70143
70144 static void
70145@@ -112,7 +116,11 @@ next_one:
70146 static void
70147 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
70148 {
70149+#ifdef CONFIG_GRKERNSEC_HIDESYM
70150+ SEQ_printf(m, " .base: %p\n", NULL);
70151+#else
70152 SEQ_printf(m, " .base: %pK\n", base);
70153+#endif
70154 SEQ_printf(m, " .index: %d\n",
70155 base->index);
70156 SEQ_printf(m, " .resolution: %Lu nsecs\n",
70157@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
70158 {
70159 struct proc_dir_entry *pe;
70160
70161+#ifdef CONFIG_GRKERNSEC_PROC_ADD
70162+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
70163+#else
70164 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
70165+#endif
70166 if (!pe)
70167 return -ENOMEM;
70168 return 0;
70169diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
70170index 0b537f2..9e71eca 100644
70171--- a/kernel/time/timer_stats.c
70172+++ b/kernel/time/timer_stats.c
70173@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
70174 static unsigned long nr_entries;
70175 static struct entry entries[MAX_ENTRIES];
70176
70177-static atomic_t overflow_count;
70178+static atomic_unchecked_t overflow_count;
70179
70180 /*
70181 * The entries are in a hash-table, for fast lookup:
70182@@ -140,7 +140,7 @@ static void reset_entries(void)
70183 nr_entries = 0;
70184 memset(entries, 0, sizeof(entries));
70185 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
70186- atomic_set(&overflow_count, 0);
70187+ atomic_set_unchecked(&overflow_count, 0);
70188 }
70189
70190 static struct entry *alloc_entry(void)
70191@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70192 if (likely(entry))
70193 entry->count++;
70194 else
70195- atomic_inc(&overflow_count);
70196+ atomic_inc_unchecked(&overflow_count);
70197
70198 out_unlock:
70199 raw_spin_unlock_irqrestore(lock, flags);
70200@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70201
70202 static void print_name_offset(struct seq_file *m, unsigned long addr)
70203 {
70204+#ifdef CONFIG_GRKERNSEC_HIDESYM
70205+ seq_printf(m, "<%p>", NULL);
70206+#else
70207 char symname[KSYM_NAME_LEN];
70208
70209 if (lookup_symbol_name(addr, symname) < 0)
70210 seq_printf(m, "<%p>", (void *)addr);
70211 else
70212 seq_printf(m, "%s", symname);
70213+#endif
70214 }
70215
70216 static int tstats_show(struct seq_file *m, void *v)
70217@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
70218
70219 seq_puts(m, "Timer Stats Version: v0.2\n");
70220 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
70221- if (atomic_read(&overflow_count))
70222+ if (atomic_read_unchecked(&overflow_count))
70223 seq_printf(m, "Overflow: %d entries\n",
70224- atomic_read(&overflow_count));
70225+ atomic_read_unchecked(&overflow_count));
70226
70227 for (i = 0; i < nr_entries; i++) {
70228 entry = entries + i;
70229@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
70230 {
70231 struct proc_dir_entry *pe;
70232
70233+#ifdef CONFIG_GRKERNSEC_PROC_ADD
70234+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
70235+#else
70236 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
70237+#endif
70238 if (!pe)
70239 return -ENOMEM;
70240 return 0;
70241diff --git a/kernel/timer.c b/kernel/timer.c
70242index 6ec7e7e..cbc448b 100644
70243--- a/kernel/timer.c
70244+++ b/kernel/timer.c
70245@@ -1362,7 +1362,7 @@ void update_process_times(int user_tick)
70246 /*
70247 * This function runs timers and the timer-tq in bottom half context.
70248 */
70249-static void run_timer_softirq(struct softirq_action *h)
70250+static void run_timer_softirq(void)
70251 {
70252 struct tvec_base *base = __this_cpu_read(tvec_bases);
70253
70254diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
70255index c0bd030..62a1927 100644
70256--- a/kernel/trace/blktrace.c
70257+++ b/kernel/trace/blktrace.c
70258@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
70259 struct blk_trace *bt = filp->private_data;
70260 char buf[16];
70261
70262- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
70263+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
70264
70265 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
70266 }
70267@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
70268 return 1;
70269
70270 bt = buf->chan->private_data;
70271- atomic_inc(&bt->dropped);
70272+ atomic_inc_unchecked(&bt->dropped);
70273 return 0;
70274 }
70275
70276@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
70277
70278 bt->dir = dir;
70279 bt->dev = dev;
70280- atomic_set(&bt->dropped, 0);
70281+ atomic_set_unchecked(&bt->dropped, 0);
70282
70283 ret = -EIO;
70284 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
70285diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
70286index a008663..30d7429 100644
70287--- a/kernel/trace/ftrace.c
70288+++ b/kernel/trace/ftrace.c
70289@@ -1785,12 +1785,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
70290 if (unlikely(ftrace_disabled))
70291 return 0;
70292
70293+ ret = ftrace_arch_code_modify_prepare();
70294+ FTRACE_WARN_ON(ret);
70295+ if (ret)
70296+ return 0;
70297+
70298 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
70299+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
70300 if (ret) {
70301 ftrace_bug(ret, ip);
70302- return 0;
70303 }
70304- return 1;
70305+ return ret ? 0 : 1;
70306 }
70307
70308 /*
70309@@ -2885,7 +2890,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
70310
70311 int
70312 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
70313- void *data)
70314+ void *data)
70315 {
70316 struct ftrace_func_probe *entry;
70317 struct ftrace_page *pg;
70318@@ -3697,8 +3702,10 @@ static int ftrace_process_locs(struct module *mod,
70319 if (!count)
70320 return 0;
70321
70322+ pax_open_kernel();
70323 sort(start, count, sizeof(*start),
70324 ftrace_cmp_ips, ftrace_swap_ips);
70325+ pax_close_kernel();
70326
70327 start_pg = ftrace_allocate_pages(count);
70328 if (!start_pg)
70329diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
70330index a7fa070..403bc8d 100644
70331--- a/kernel/trace/trace.c
70332+++ b/kernel/trace/trace.c
70333@@ -4421,10 +4421,9 @@ static const struct file_operations tracing_dyn_info_fops = {
70334 };
70335 #endif
70336
70337-static struct dentry *d_tracer;
70338-
70339 struct dentry *tracing_init_dentry(void)
70340 {
70341+ static struct dentry *d_tracer;
70342 static int once;
70343
70344 if (d_tracer)
70345@@ -4444,10 +4443,9 @@ struct dentry *tracing_init_dentry(void)
70346 return d_tracer;
70347 }
70348
70349-static struct dentry *d_percpu;
70350-
70351 struct dentry *tracing_dentry_percpu(void)
70352 {
70353+ static struct dentry *d_percpu;
70354 static int once;
70355 struct dentry *d_tracer;
70356
70357diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
70358index 29111da..d190fe2 100644
70359--- a/kernel/trace/trace_events.c
70360+++ b/kernel/trace/trace_events.c
70361@@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
70362 struct ftrace_module_file_ops {
70363 struct list_head list;
70364 struct module *mod;
70365- struct file_operations id;
70366- struct file_operations enable;
70367- struct file_operations format;
70368- struct file_operations filter;
70369 };
70370
70371 static struct ftrace_module_file_ops *
70372@@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
70373
70374 file_ops->mod = mod;
70375
70376- file_ops->id = ftrace_event_id_fops;
70377- file_ops->id.owner = mod;
70378-
70379- file_ops->enable = ftrace_enable_fops;
70380- file_ops->enable.owner = mod;
70381-
70382- file_ops->filter = ftrace_event_filter_fops;
70383- file_ops->filter.owner = mod;
70384-
70385- file_ops->format = ftrace_event_format_fops;
70386- file_ops->format.owner = mod;
70387+ pax_open_kernel();
70388+ *(void **)&mod->trace_id.owner = mod;
70389+ *(void **)&mod->trace_enable.owner = mod;
70390+ *(void **)&mod->trace_filter.owner = mod;
70391+ *(void **)&mod->trace_format.owner = mod;
70392+ pax_close_kernel();
70393
70394 list_add(&file_ops->list, &ftrace_module_file_list);
70395
70396@@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
70397
70398 for_each_event(call, start, end) {
70399 __trace_add_event_call(*call, mod,
70400- &file_ops->id, &file_ops->enable,
70401- &file_ops->filter, &file_ops->format);
70402+ &mod->trace_id, &mod->trace_enable,
70403+ &mod->trace_filter, &mod->trace_format);
70404 }
70405 }
70406
70407diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
70408index fd3c8aa..5f324a6 100644
70409--- a/kernel/trace/trace_mmiotrace.c
70410+++ b/kernel/trace/trace_mmiotrace.c
70411@@ -24,7 +24,7 @@ struct header_iter {
70412 static struct trace_array *mmio_trace_array;
70413 static bool overrun_detected;
70414 static unsigned long prev_overruns;
70415-static atomic_t dropped_count;
70416+static atomic_unchecked_t dropped_count;
70417
70418 static void mmio_reset_data(struct trace_array *tr)
70419 {
70420@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
70421
70422 static unsigned long count_overruns(struct trace_iterator *iter)
70423 {
70424- unsigned long cnt = atomic_xchg(&dropped_count, 0);
70425+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
70426 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
70427
70428 if (over > prev_overruns)
70429@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
70430 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
70431 sizeof(*entry), 0, pc);
70432 if (!event) {
70433- atomic_inc(&dropped_count);
70434+ atomic_inc_unchecked(&dropped_count);
70435 return;
70436 }
70437 entry = ring_buffer_event_data(event);
70438@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
70439 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
70440 sizeof(*entry), 0, pc);
70441 if (!event) {
70442- atomic_inc(&dropped_count);
70443+ atomic_inc_unchecked(&dropped_count);
70444 return;
70445 }
70446 entry = ring_buffer_event_data(event);
70447diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
70448index df611a0..10d8b32 100644
70449--- a/kernel/trace/trace_output.c
70450+++ b/kernel/trace/trace_output.c
70451@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
70452
70453 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
70454 if (!IS_ERR(p)) {
70455- p = mangle_path(s->buffer + s->len, p, "\n");
70456+ p = mangle_path(s->buffer + s->len, p, "\n\\");
70457 if (p) {
70458 s->len = p - s->buffer;
70459 return 1;
70460diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
70461index d4545f4..a9010a1 100644
70462--- a/kernel/trace/trace_stack.c
70463+++ b/kernel/trace/trace_stack.c
70464@@ -53,7 +53,7 @@ static inline void check_stack(void)
70465 return;
70466
70467 /* we do not handle interrupt stacks yet */
70468- if (!object_is_on_stack(&this_size))
70469+ if (!object_starts_on_stack(&this_size))
70470 return;
70471
70472 local_irq_save(flags);
70473diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
70474index ff5bdee..3eaeba6 100644
70475--- a/lib/Kconfig.debug
70476+++ b/lib/Kconfig.debug
70477@@ -1165,6 +1165,7 @@ config LATENCYTOP
70478 depends on DEBUG_KERNEL
70479 depends on STACKTRACE_SUPPORT
70480 depends on PROC_FS
70481+ depends on !GRKERNSEC_HIDESYM
70482 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
70483 select KALLSYMS
70484 select KALLSYMS_ALL
70485diff --git a/lib/bitmap.c b/lib/bitmap.c
70486index 06fdfa1..97c5c7d 100644
70487--- a/lib/bitmap.c
70488+++ b/lib/bitmap.c
70489@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
70490 {
70491 int c, old_c, totaldigits, ndigits, nchunks, nbits;
70492 u32 chunk;
70493- const char __user __force *ubuf = (const char __user __force *)buf;
70494+ const char __user *ubuf = (const char __force_user *)buf;
70495
70496 bitmap_zero(maskp, nmaskbits);
70497
70498@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
70499 {
70500 if (!access_ok(VERIFY_READ, ubuf, ulen))
70501 return -EFAULT;
70502- return __bitmap_parse((const char __force *)ubuf,
70503+ return __bitmap_parse((const char __force_kernel *)ubuf,
70504 ulen, 1, maskp, nmaskbits);
70505
70506 }
70507@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
70508 {
70509 unsigned a, b;
70510 int c, old_c, totaldigits;
70511- const char __user __force *ubuf = (const char __user __force *)buf;
70512+ const char __user *ubuf = (const char __force_user *)buf;
70513 int exp_digit, in_range;
70514
70515 totaldigits = c = 0;
70516@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
70517 {
70518 if (!access_ok(VERIFY_READ, ubuf, ulen))
70519 return -EFAULT;
70520- return __bitmap_parselist((const char __force *)ubuf,
70521+ return __bitmap_parselist((const char __force_kernel *)ubuf,
70522 ulen, 1, maskp, nmaskbits);
70523 }
70524 EXPORT_SYMBOL(bitmap_parselist_user);
70525diff --git a/lib/bug.c b/lib/bug.c
70526index a28c141..2bd3d95 100644
70527--- a/lib/bug.c
70528+++ b/lib/bug.c
70529@@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
70530 return BUG_TRAP_TYPE_NONE;
70531
70532 bug = find_bug(bugaddr);
70533+ if (!bug)
70534+ return BUG_TRAP_TYPE_NONE;
70535
70536 file = NULL;
70537 line = 0;
70538diff --git a/lib/debugobjects.c b/lib/debugobjects.c
70539index d11808c..dc2d6f8 100644
70540--- a/lib/debugobjects.c
70541+++ b/lib/debugobjects.c
70542@@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
70543 if (limit > 4)
70544 return;
70545
70546- is_on_stack = object_is_on_stack(addr);
70547+ is_on_stack = object_starts_on_stack(addr);
70548 if (is_on_stack == onstack)
70549 return;
70550
70551diff --git a/lib/devres.c b/lib/devres.c
70552index 80b9c76..9e32279 100644
70553--- a/lib/devres.c
70554+++ b/lib/devres.c
70555@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
70556 void devm_iounmap(struct device *dev, void __iomem *addr)
70557 {
70558 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
70559- (void *)addr));
70560+ (void __force *)addr));
70561 iounmap(addr);
70562 }
70563 EXPORT_SYMBOL(devm_iounmap);
70564@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
70565 {
70566 ioport_unmap(addr);
70567 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
70568- devm_ioport_map_match, (void *)addr));
70569+ devm_ioport_map_match, (void __force *)addr));
70570 }
70571 EXPORT_SYMBOL(devm_ioport_unmap);
70572
70573diff --git a/lib/dma-debug.c b/lib/dma-debug.c
70574index 66ce414..6f0a0dd 100644
70575--- a/lib/dma-debug.c
70576+++ b/lib/dma-debug.c
70577@@ -924,7 +924,7 @@ out:
70578
70579 static void check_for_stack(struct device *dev, void *addr)
70580 {
70581- if (object_is_on_stack(addr))
70582+ if (object_starts_on_stack(addr))
70583 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
70584 "stack [addr=%p]\n", addr);
70585 }
70586diff --git a/lib/inflate.c b/lib/inflate.c
70587index 013a761..c28f3fc 100644
70588--- a/lib/inflate.c
70589+++ b/lib/inflate.c
70590@@ -269,7 +269,7 @@ static void free(void *where)
70591 malloc_ptr = free_mem_ptr;
70592 }
70593 #else
70594-#define malloc(a) kmalloc(a, GFP_KERNEL)
70595+#define malloc(a) kmalloc((a), GFP_KERNEL)
70596 #define free(a) kfree(a)
70597 #endif
70598
70599diff --git a/lib/ioremap.c b/lib/ioremap.c
70600index 0c9216c..863bd89 100644
70601--- a/lib/ioremap.c
70602+++ b/lib/ioremap.c
70603@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
70604 unsigned long next;
70605
70606 phys_addr -= addr;
70607- pmd = pmd_alloc(&init_mm, pud, addr);
70608+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
70609 if (!pmd)
70610 return -ENOMEM;
70611 do {
70612@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
70613 unsigned long next;
70614
70615 phys_addr -= addr;
70616- pud = pud_alloc(&init_mm, pgd, addr);
70617+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
70618 if (!pud)
70619 return -ENOMEM;
70620 do {
70621diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
70622index bd2bea9..6b3c95e 100644
70623--- a/lib/is_single_threaded.c
70624+++ b/lib/is_single_threaded.c
70625@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
70626 struct task_struct *p, *t;
70627 bool ret;
70628
70629+ if (!mm)
70630+ return true;
70631+
70632 if (atomic_read(&task->signal->live) != 1)
70633 return false;
70634
70635diff --git a/lib/radix-tree.c b/lib/radix-tree.c
70636index e796429..6e38f9f 100644
70637--- a/lib/radix-tree.c
70638+++ b/lib/radix-tree.c
70639@@ -92,7 +92,7 @@ struct radix_tree_preload {
70640 int nr;
70641 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
70642 };
70643-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
70644+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
70645
70646 static inline void *ptr_to_indirect(void *ptr)
70647 {
70648diff --git a/lib/vsprintf.c b/lib/vsprintf.c
70649index 598a73e..5c5aeb5 100644
70650--- a/lib/vsprintf.c
70651+++ b/lib/vsprintf.c
70652@@ -16,6 +16,9 @@
70653 * - scnprintf and vscnprintf
70654 */
70655
70656+#ifdef CONFIG_GRKERNSEC_HIDESYM
70657+#define __INCLUDED_BY_HIDESYM 1
70658+#endif
70659 #include <stdarg.h>
70660 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
70661 #include <linux/types.h>
70662@@ -536,7 +539,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
70663 char sym[KSYM_SYMBOL_LEN];
70664 if (ext == 'B')
70665 sprint_backtrace(sym, value);
70666- else if (ext != 'f' && ext != 's')
70667+ else if (ext != 'f' && ext != 's' && ext != 'a')
70668 sprint_symbol(sym, value);
70669 else
70670 sprint_symbol_no_offset(sym, value);
70671@@ -912,7 +915,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
70672 return number(buf, end, *(const netdev_features_t *)addr, spec);
70673 }
70674
70675+#ifdef CONFIG_GRKERNSEC_HIDESYM
70676+int kptr_restrict __read_mostly = 2;
70677+#else
70678 int kptr_restrict __read_mostly;
70679+#endif
70680
70681 /*
70682 * Show a '%p' thing. A kernel extension is that the '%p' is followed
70683@@ -926,6 +933,8 @@ int kptr_restrict __read_mostly;
70684 * - 'S' For symbolic direct pointers with offset
70685 * - 's' For symbolic direct pointers without offset
70686 * - 'B' For backtraced symbolic direct pointers with offset
70687+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
70688+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
70689 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
70690 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
70691 * - 'M' For a 6-byte MAC address, it prints the address in the
70692@@ -973,12 +982,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70693
70694 if (!ptr && *fmt != 'K') {
70695 /*
70696- * Print (null) with the same width as a pointer so it makes
70697+ * Print (nil) with the same width as a pointer so it makes
70698 * tabular output look nice.
70699 */
70700 if (spec.field_width == -1)
70701 spec.field_width = default_width;
70702- return string(buf, end, "(null)", spec);
70703+ return string(buf, end, "(nil)", spec);
70704 }
70705
70706 switch (*fmt) {
70707@@ -988,6 +997,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70708 /* Fallthrough */
70709 case 'S':
70710 case 's':
70711+#ifdef CONFIG_GRKERNSEC_HIDESYM
70712+ break;
70713+#else
70714+ return symbol_string(buf, end, ptr, spec, *fmt);
70715+#endif
70716+ case 'A':
70717+ case 'a':
70718 case 'B':
70719 return symbol_string(buf, end, ptr, spec, *fmt);
70720 case 'R':
70721@@ -1025,6 +1041,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70722 va_end(va);
70723 return buf;
70724 }
70725+ case 'P':
70726+ break;
70727 case 'K':
70728 /*
70729 * %pK cannot be used in IRQ context because its test
70730@@ -1048,6 +1066,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70731 }
70732 break;
70733 }
70734+
70735+#ifdef CONFIG_GRKERNSEC_HIDESYM
70736+ /* 'P' = approved pointers to copy to userland,
70737+ as in the /proc/kallsyms case, as we make it display nothing
70738+ for non-root users, and the real contents for root users
70739+ Also ignore 'K' pointers, since we force their NULLing for non-root users
70740+ above
70741+ */
70742+ if (ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
70743+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
70744+ dump_stack();
70745+ ptr = NULL;
70746+ }
70747+#endif
70748+
70749 spec.flags |= SMALL;
70750 if (spec.field_width == -1) {
70751 spec.field_width = default_width;
70752@@ -1759,11 +1792,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70753 typeof(type) value; \
70754 if (sizeof(type) == 8) { \
70755 args = PTR_ALIGN(args, sizeof(u32)); \
70756- *(u32 *)&value = *(u32 *)args; \
70757- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
70758+ *(u32 *)&value = *(const u32 *)args; \
70759+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
70760 } else { \
70761 args = PTR_ALIGN(args, sizeof(type)); \
70762- value = *(typeof(type) *)args; \
70763+ value = *(const typeof(type) *)args; \
70764 } \
70765 args += sizeof(type); \
70766 value; \
70767@@ -1826,7 +1859,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70768 case FORMAT_TYPE_STR: {
70769 const char *str_arg = args;
70770 args += strlen(str_arg) + 1;
70771- str = string(str, end, (char *)str_arg, spec);
70772+ str = string(str, end, str_arg, spec);
70773 break;
70774 }
70775
70776diff --git a/localversion-grsec b/localversion-grsec
70777new file mode 100644
70778index 0000000..7cd6065
70779--- /dev/null
70780+++ b/localversion-grsec
70781@@ -0,0 +1 @@
70782+-grsec
70783diff --git a/mm/Kconfig b/mm/Kconfig
70784index 82fed4e..979e814 100644
70785--- a/mm/Kconfig
70786+++ b/mm/Kconfig
70787@@ -247,10 +247,10 @@ config KSM
70788 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
70789
70790 config DEFAULT_MMAP_MIN_ADDR
70791- int "Low address space to protect from user allocation"
70792+ int "Low address space to protect from user allocation"
70793 depends on MMU
70794- default 4096
70795- help
70796+ default 65536
70797+ help
70798 This is the portion of low virtual memory which should be protected
70799 from userspace allocation. Keeping a user from writing to low pages
70800 can help reduce the impact of kernel NULL pointer bugs.
70801@@ -280,7 +280,7 @@ config MEMORY_FAILURE
70802
70803 config HWPOISON_INJECT
70804 tristate "HWPoison pages injector"
70805- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
70806+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
70807 select PROC_PAGE_MONITOR
70808
70809 config NOMMU_INITIAL_TRIM_EXCESS
70810diff --git a/mm/filemap.c b/mm/filemap.c
70811index a4a5260..6151dc5 100644
70812--- a/mm/filemap.c
70813+++ b/mm/filemap.c
70814@@ -1723,7 +1723,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
70815 struct address_space *mapping = file->f_mapping;
70816
70817 if (!mapping->a_ops->readpage)
70818- return -ENOEXEC;
70819+ return -ENODEV;
70820 file_accessed(file);
70821 vma->vm_ops = &generic_file_vm_ops;
70822 vma->vm_flags |= VM_CAN_NONLINEAR;
70823@@ -2064,6 +2064,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
70824 *pos = i_size_read(inode);
70825
70826 if (limit != RLIM_INFINITY) {
70827+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
70828 if (*pos >= limit) {
70829 send_sig(SIGXFSZ, current, 0);
70830 return -EFBIG;
70831diff --git a/mm/fremap.c b/mm/fremap.c
70832index 9ed4fd4..c42648d 100644
70833--- a/mm/fremap.c
70834+++ b/mm/fremap.c
70835@@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
70836 retry:
70837 vma = find_vma(mm, start);
70838
70839+#ifdef CONFIG_PAX_SEGMEXEC
70840+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
70841+ goto out;
70842+#endif
70843+
70844 /*
70845 * Make sure the vma is shared, that it supports prefaulting,
70846 * and that the remapped range is valid and fully within
70847diff --git a/mm/highmem.c b/mm/highmem.c
70848index 57d82c6..e9e0552 100644
70849--- a/mm/highmem.c
70850+++ b/mm/highmem.c
70851@@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
70852 * So no dangers, even with speculative execution.
70853 */
70854 page = pte_page(pkmap_page_table[i]);
70855+ pax_open_kernel();
70856 pte_clear(&init_mm, (unsigned long)page_address(page),
70857 &pkmap_page_table[i]);
70858-
70859+ pax_close_kernel();
70860 set_page_address(page, NULL);
70861 need_flush = 1;
70862 }
70863@@ -186,9 +187,11 @@ start:
70864 }
70865 }
70866 vaddr = PKMAP_ADDR(last_pkmap_nr);
70867+
70868+ pax_open_kernel();
70869 set_pte_at(&init_mm, vaddr,
70870 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
70871-
70872+ pax_close_kernel();
70873 pkmap_count[last_pkmap_nr] = 1;
70874 set_page_address(page, (void *)vaddr);
70875
70876diff --git a/mm/huge_memory.c b/mm/huge_memory.c
70877index 57c4b93..24b8f59 100644
70878--- a/mm/huge_memory.c
70879+++ b/mm/huge_memory.c
70880@@ -735,7 +735,7 @@ out:
70881 * run pte_offset_map on the pmd, if an huge pmd could
70882 * materialize from under us from a different thread.
70883 */
70884- if (unlikely(__pte_alloc(mm, vma, pmd, address)))
70885+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
70886 return VM_FAULT_OOM;
70887 /* if an huge pmd materialized from under us just retry later */
70888 if (unlikely(pmd_trans_huge(*pmd)))
70889diff --git a/mm/hugetlb.c b/mm/hugetlb.c
70890index 19558df..f7743b3 100644
70891--- a/mm/hugetlb.c
70892+++ b/mm/hugetlb.c
70893@@ -2463,6 +2463,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
70894 return 1;
70895 }
70896
70897+#ifdef CONFIG_PAX_SEGMEXEC
70898+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
70899+{
70900+ struct mm_struct *mm = vma->vm_mm;
70901+ struct vm_area_struct *vma_m;
70902+ unsigned long address_m;
70903+ pte_t *ptep_m;
70904+
70905+ vma_m = pax_find_mirror_vma(vma);
70906+ if (!vma_m)
70907+ return;
70908+
70909+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70910+ address_m = address + SEGMEXEC_TASK_SIZE;
70911+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
70912+ get_page(page_m);
70913+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
70914+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
70915+}
70916+#endif
70917+
70918 /*
70919 * Hugetlb_cow() should be called with page lock of the original hugepage held.
70920 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
70921@@ -2575,6 +2596,11 @@ retry_avoidcopy:
70922 make_huge_pte(vma, new_page, 1));
70923 page_remove_rmap(old_page);
70924 hugepage_add_new_anon_rmap(new_page, vma, address);
70925+
70926+#ifdef CONFIG_PAX_SEGMEXEC
70927+ pax_mirror_huge_pte(vma, address, new_page);
70928+#endif
70929+
70930 /* Make the old page be freed below */
70931 new_page = old_page;
70932 mmu_notifier_invalidate_range_end(mm,
70933@@ -2729,6 +2755,10 @@ retry:
70934 && (vma->vm_flags & VM_SHARED)));
70935 set_huge_pte_at(mm, address, ptep, new_pte);
70936
70937+#ifdef CONFIG_PAX_SEGMEXEC
70938+ pax_mirror_huge_pte(vma, address, page);
70939+#endif
70940+
70941 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
70942 /* Optimization, do the COW without a second fault */
70943 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
70944@@ -2758,6 +2788,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70945 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
70946 struct hstate *h = hstate_vma(vma);
70947
70948+#ifdef CONFIG_PAX_SEGMEXEC
70949+ struct vm_area_struct *vma_m;
70950+#endif
70951+
70952 address &= huge_page_mask(h);
70953
70954 ptep = huge_pte_offset(mm, address);
70955@@ -2771,6 +2805,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70956 VM_FAULT_SET_HINDEX(h - hstates);
70957 }
70958
70959+#ifdef CONFIG_PAX_SEGMEXEC
70960+ vma_m = pax_find_mirror_vma(vma);
70961+ if (vma_m) {
70962+ unsigned long address_m;
70963+
70964+ if (vma->vm_start > vma_m->vm_start) {
70965+ address_m = address;
70966+ address -= SEGMEXEC_TASK_SIZE;
70967+ vma = vma_m;
70968+ h = hstate_vma(vma);
70969+ } else
70970+ address_m = address + SEGMEXEC_TASK_SIZE;
70971+
70972+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
70973+ return VM_FAULT_OOM;
70974+ address_m &= HPAGE_MASK;
70975+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
70976+ }
70977+#endif
70978+
70979 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
70980 if (!ptep)
70981 return VM_FAULT_OOM;
70982diff --git a/mm/internal.h b/mm/internal.h
70983index 8052379..47029d1 100644
70984--- a/mm/internal.h
70985+++ b/mm/internal.h
70986@@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
70987 * in mm/page_alloc.c
70988 */
70989 extern void __free_pages_bootmem(struct page *page, unsigned int order);
70990+extern void free_compound_page(struct page *page);
70991 extern void prep_compound_page(struct page *page, unsigned long order);
70992 #ifdef CONFIG_MEMORY_FAILURE
70993 extern bool is_free_buddy_page(struct page *page);
70994diff --git a/mm/kmemleak.c b/mm/kmemleak.c
70995index 45eb621..6ccd8ea 100644
70996--- a/mm/kmemleak.c
70997+++ b/mm/kmemleak.c
70998@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
70999
71000 for (i = 0; i < object->trace_len; i++) {
71001 void *ptr = (void *)object->trace[i];
71002- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
71003+ seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
71004 }
71005 }
71006
71007diff --git a/mm/maccess.c b/mm/maccess.c
71008index d53adf9..03a24bf 100644
71009--- a/mm/maccess.c
71010+++ b/mm/maccess.c
71011@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
71012 set_fs(KERNEL_DS);
71013 pagefault_disable();
71014 ret = __copy_from_user_inatomic(dst,
71015- (__force const void __user *)src, size);
71016+ (const void __force_user *)src, size);
71017 pagefault_enable();
71018 set_fs(old_fs);
71019
71020@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
71021
71022 set_fs(KERNEL_DS);
71023 pagefault_disable();
71024- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
71025+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
71026 pagefault_enable();
71027 set_fs(old_fs);
71028
71029diff --git a/mm/madvise.c b/mm/madvise.c
71030index 14d260f..b2a80fd 100644
71031--- a/mm/madvise.c
71032+++ b/mm/madvise.c
71033@@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
71034 pgoff_t pgoff;
71035 unsigned long new_flags = vma->vm_flags;
71036
71037+#ifdef CONFIG_PAX_SEGMEXEC
71038+ struct vm_area_struct *vma_m;
71039+#endif
71040+
71041 switch (behavior) {
71042 case MADV_NORMAL:
71043 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
71044@@ -119,6 +123,13 @@ success:
71045 /*
71046 * vm_flags is protected by the mmap_sem held in write mode.
71047 */
71048+
71049+#ifdef CONFIG_PAX_SEGMEXEC
71050+ vma_m = pax_find_mirror_vma(vma);
71051+ if (vma_m)
71052+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
71053+#endif
71054+
71055 vma->vm_flags = new_flags;
71056
71057 out:
71058@@ -177,6 +188,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71059 struct vm_area_struct ** prev,
71060 unsigned long start, unsigned long end)
71061 {
71062+
71063+#ifdef CONFIG_PAX_SEGMEXEC
71064+ struct vm_area_struct *vma_m;
71065+#endif
71066+
71067 *prev = vma;
71068 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
71069 return -EINVAL;
71070@@ -189,6 +205,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71071 zap_page_range(vma, start, end - start, &details);
71072 } else
71073 zap_page_range(vma, start, end - start, NULL);
71074+
71075+#ifdef CONFIG_PAX_SEGMEXEC
71076+ vma_m = pax_find_mirror_vma(vma);
71077+ if (vma_m) {
71078+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
71079+ struct zap_details details = {
71080+ .nonlinear_vma = vma_m,
71081+ .last_index = ULONG_MAX,
71082+ };
71083+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
71084+ } else
71085+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
71086+ }
71087+#endif
71088+
71089 return 0;
71090 }
71091
71092@@ -393,6 +424,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
71093 if (end < start)
71094 goto out;
71095
71096+#ifdef CONFIG_PAX_SEGMEXEC
71097+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
71098+ if (end > SEGMEXEC_TASK_SIZE)
71099+ goto out;
71100+ } else
71101+#endif
71102+
71103+ if (end > TASK_SIZE)
71104+ goto out;
71105+
71106 error = 0;
71107 if (end == start)
71108 goto out;
71109diff --git a/mm/memory-failure.c b/mm/memory-failure.c
71110index 6de0d61..da836cf 100644
71111--- a/mm/memory-failure.c
71112+++ b/mm/memory-failure.c
71113@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
71114
71115 int sysctl_memory_failure_recovery __read_mostly = 1;
71116
71117-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71118+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71119
71120 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
71121
71122@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
71123 pfn, t->comm, t->pid);
71124 si.si_signo = SIGBUS;
71125 si.si_errno = 0;
71126- si.si_addr = (void *)addr;
71127+ si.si_addr = (void __user *)addr;
71128 #ifdef __ARCH_SI_TRAPNO
71129 si.si_trapno = trapno;
71130 #endif
71131@@ -1038,7 +1038,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71132 }
71133
71134 nr_pages = 1 << compound_trans_order(hpage);
71135- atomic_long_add(nr_pages, &mce_bad_pages);
71136+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
71137
71138 /*
71139 * We need/can do nothing about count=0 pages.
71140@@ -1068,7 +1068,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71141 if (!PageHWPoison(hpage)
71142 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
71143 || (p != hpage && TestSetPageHWPoison(hpage))) {
71144- atomic_long_sub(nr_pages, &mce_bad_pages);
71145+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71146 return 0;
71147 }
71148 set_page_hwpoison_huge_page(hpage);
71149@@ -1126,7 +1126,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71150 }
71151 if (hwpoison_filter(p)) {
71152 if (TestClearPageHWPoison(p))
71153- atomic_long_sub(nr_pages, &mce_bad_pages);
71154+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71155 unlock_page(hpage);
71156 put_page(hpage);
71157 return 0;
71158@@ -1321,7 +1321,7 @@ int unpoison_memory(unsigned long pfn)
71159 return 0;
71160 }
71161 if (TestClearPageHWPoison(p))
71162- atomic_long_sub(nr_pages, &mce_bad_pages);
71163+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71164 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
71165 return 0;
71166 }
71167@@ -1335,7 +1335,7 @@ int unpoison_memory(unsigned long pfn)
71168 */
71169 if (TestClearPageHWPoison(page)) {
71170 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
71171- atomic_long_sub(nr_pages, &mce_bad_pages);
71172+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71173 freeit = 1;
71174 if (PageHuge(page))
71175 clear_page_hwpoison_huge_page(page);
71176@@ -1448,7 +1448,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
71177 }
71178 done:
71179 if (!PageHWPoison(hpage))
71180- atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
71181+ atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
71182 set_page_hwpoison_huge_page(hpage);
71183 dequeue_hwpoisoned_huge_page(hpage);
71184 /* keep elevated page count for bad page */
71185@@ -1579,7 +1579,7 @@ int soft_offline_page(struct page *page, int flags)
71186 return ret;
71187
71188 done:
71189- atomic_long_add(1, &mce_bad_pages);
71190+ atomic_long_add_unchecked(1, &mce_bad_pages);
71191 SetPageHWPoison(page);
71192 /* keep elevated page count for bad page */
71193 return ret;
71194diff --git a/mm/memory.c b/mm/memory.c
71195index 2466d12..08be4f6 100644
71196--- a/mm/memory.c
71197+++ b/mm/memory.c
71198@@ -434,8 +434,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71199 return;
71200
71201 pmd = pmd_offset(pud, start);
71202+
71203+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
71204 pud_clear(pud);
71205 pmd_free_tlb(tlb, pmd, start);
71206+#endif
71207+
71208 }
71209
71210 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71211@@ -466,9 +470,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71212 if (end - 1 > ceiling - 1)
71213 return;
71214
71215+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
71216 pud = pud_offset(pgd, start);
71217 pgd_clear(pgd);
71218 pud_free_tlb(tlb, pud, start);
71219+#endif
71220+
71221 }
71222
71223 /*
71224@@ -1602,12 +1609,6 @@ no_page_table:
71225 return page;
71226 }
71227
71228-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
71229-{
71230- return stack_guard_page_start(vma, addr) ||
71231- stack_guard_page_end(vma, addr+PAGE_SIZE);
71232-}
71233-
71234 /**
71235 * __get_user_pages() - pin user pages in memory
71236 * @tsk: task_struct of target task
71237@@ -1680,10 +1681,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71238 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
71239 i = 0;
71240
71241- do {
71242+ while (nr_pages) {
71243 struct vm_area_struct *vma;
71244
71245- vma = find_extend_vma(mm, start);
71246+ vma = find_vma(mm, start);
71247 if (!vma && in_gate_area(mm, start)) {
71248 unsigned long pg = start & PAGE_MASK;
71249 pgd_t *pgd;
71250@@ -1731,7 +1732,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71251 goto next_page;
71252 }
71253
71254- if (!vma ||
71255+ if (!vma || start < vma->vm_start ||
71256 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
71257 !(vm_flags & vma->vm_flags))
71258 return i ? : -EFAULT;
71259@@ -1758,11 +1759,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71260 int ret;
71261 unsigned int fault_flags = 0;
71262
71263- /* For mlock, just skip the stack guard page. */
71264- if (foll_flags & FOLL_MLOCK) {
71265- if (stack_guard_page(vma, start))
71266- goto next_page;
71267- }
71268 if (foll_flags & FOLL_WRITE)
71269 fault_flags |= FAULT_FLAG_WRITE;
71270 if (nonblocking)
71271@@ -1836,7 +1832,7 @@ next_page:
71272 start += PAGE_SIZE;
71273 nr_pages--;
71274 } while (nr_pages && start < vma->vm_end);
71275- } while (nr_pages);
71276+ }
71277 return i;
71278 }
71279 EXPORT_SYMBOL(__get_user_pages);
71280@@ -2043,6 +2039,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
71281 page_add_file_rmap(page);
71282 set_pte_at(mm, addr, pte, mk_pte(page, prot));
71283
71284+#ifdef CONFIG_PAX_SEGMEXEC
71285+ pax_mirror_file_pte(vma, addr, page, ptl);
71286+#endif
71287+
71288 retval = 0;
71289 pte_unmap_unlock(pte, ptl);
71290 return retval;
71291@@ -2077,10 +2077,22 @@ out:
71292 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
71293 struct page *page)
71294 {
71295+
71296+#ifdef CONFIG_PAX_SEGMEXEC
71297+ struct vm_area_struct *vma_m;
71298+#endif
71299+
71300 if (addr < vma->vm_start || addr >= vma->vm_end)
71301 return -EFAULT;
71302 if (!page_count(page))
71303 return -EINVAL;
71304+
71305+#ifdef CONFIG_PAX_SEGMEXEC
71306+ vma_m = pax_find_mirror_vma(vma);
71307+ if (vma_m)
71308+ vma_m->vm_flags |= VM_INSERTPAGE;
71309+#endif
71310+
71311 vma->vm_flags |= VM_INSERTPAGE;
71312 return insert_page(vma, addr, page, vma->vm_page_prot);
71313 }
71314@@ -2166,6 +2178,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
71315 unsigned long pfn)
71316 {
71317 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
71318+ BUG_ON(vma->vm_mirror);
71319
71320 if (addr < vma->vm_start || addr >= vma->vm_end)
71321 return -EFAULT;
71322@@ -2373,7 +2386,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
71323
71324 BUG_ON(pud_huge(*pud));
71325
71326- pmd = pmd_alloc(mm, pud, addr);
71327+ pmd = (mm == &init_mm) ?
71328+ pmd_alloc_kernel(mm, pud, addr) :
71329+ pmd_alloc(mm, pud, addr);
71330 if (!pmd)
71331 return -ENOMEM;
71332 do {
71333@@ -2393,7 +2408,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
71334 unsigned long next;
71335 int err;
71336
71337- pud = pud_alloc(mm, pgd, addr);
71338+ pud = (mm == &init_mm) ?
71339+ pud_alloc_kernel(mm, pgd, addr) :
71340+ pud_alloc(mm, pgd, addr);
71341 if (!pud)
71342 return -ENOMEM;
71343 do {
71344@@ -2481,6 +2498,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
71345 copy_user_highpage(dst, src, va, vma);
71346 }
71347
71348+#ifdef CONFIG_PAX_SEGMEXEC
71349+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
71350+{
71351+ struct mm_struct *mm = vma->vm_mm;
71352+ spinlock_t *ptl;
71353+ pte_t *pte, entry;
71354+
71355+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
71356+ entry = *pte;
71357+ if (!pte_present(entry)) {
71358+ if (!pte_none(entry)) {
71359+ BUG_ON(pte_file(entry));
71360+ free_swap_and_cache(pte_to_swp_entry(entry));
71361+ pte_clear_not_present_full(mm, address, pte, 0);
71362+ }
71363+ } else {
71364+ struct page *page;
71365+
71366+ flush_cache_page(vma, address, pte_pfn(entry));
71367+ entry = ptep_clear_flush(vma, address, pte);
71368+ BUG_ON(pte_dirty(entry));
71369+ page = vm_normal_page(vma, address, entry);
71370+ if (page) {
71371+ update_hiwater_rss(mm);
71372+ if (PageAnon(page))
71373+ dec_mm_counter_fast(mm, MM_ANONPAGES);
71374+ else
71375+ dec_mm_counter_fast(mm, MM_FILEPAGES);
71376+ page_remove_rmap(page);
71377+ page_cache_release(page);
71378+ }
71379+ }
71380+ pte_unmap_unlock(pte, ptl);
71381+}
71382+
71383+/* PaX: if vma is mirrored, synchronize the mirror's PTE
71384+ *
71385+ * the ptl of the lower mapped page is held on entry and is not released on exit
71386+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
71387+ */
71388+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71389+{
71390+ struct mm_struct *mm = vma->vm_mm;
71391+ unsigned long address_m;
71392+ spinlock_t *ptl_m;
71393+ struct vm_area_struct *vma_m;
71394+ pmd_t *pmd_m;
71395+ pte_t *pte_m, entry_m;
71396+
71397+ BUG_ON(!page_m || !PageAnon(page_m));
71398+
71399+ vma_m = pax_find_mirror_vma(vma);
71400+ if (!vma_m)
71401+ return;
71402+
71403+ BUG_ON(!PageLocked(page_m));
71404+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71405+ address_m = address + SEGMEXEC_TASK_SIZE;
71406+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71407+ pte_m = pte_offset_map(pmd_m, address_m);
71408+ ptl_m = pte_lockptr(mm, pmd_m);
71409+ if (ptl != ptl_m) {
71410+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71411+ if (!pte_none(*pte_m))
71412+ goto out;
71413+ }
71414+
71415+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71416+ page_cache_get(page_m);
71417+ page_add_anon_rmap(page_m, vma_m, address_m);
71418+ inc_mm_counter_fast(mm, MM_ANONPAGES);
71419+ set_pte_at(mm, address_m, pte_m, entry_m);
71420+ update_mmu_cache(vma_m, address_m, entry_m);
71421+out:
71422+ if (ptl != ptl_m)
71423+ spin_unlock(ptl_m);
71424+ pte_unmap(pte_m);
71425+ unlock_page(page_m);
71426+}
71427+
71428+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71429+{
71430+ struct mm_struct *mm = vma->vm_mm;
71431+ unsigned long address_m;
71432+ spinlock_t *ptl_m;
71433+ struct vm_area_struct *vma_m;
71434+ pmd_t *pmd_m;
71435+ pte_t *pte_m, entry_m;
71436+
71437+ BUG_ON(!page_m || PageAnon(page_m));
71438+
71439+ vma_m = pax_find_mirror_vma(vma);
71440+ if (!vma_m)
71441+ return;
71442+
71443+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71444+ address_m = address + SEGMEXEC_TASK_SIZE;
71445+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71446+ pte_m = pte_offset_map(pmd_m, address_m);
71447+ ptl_m = pte_lockptr(mm, pmd_m);
71448+ if (ptl != ptl_m) {
71449+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71450+ if (!pte_none(*pte_m))
71451+ goto out;
71452+ }
71453+
71454+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71455+ page_cache_get(page_m);
71456+ page_add_file_rmap(page_m);
71457+ inc_mm_counter_fast(mm, MM_FILEPAGES);
71458+ set_pte_at(mm, address_m, pte_m, entry_m);
71459+ update_mmu_cache(vma_m, address_m, entry_m);
71460+out:
71461+ if (ptl != ptl_m)
71462+ spin_unlock(ptl_m);
71463+ pte_unmap(pte_m);
71464+}
71465+
71466+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
71467+{
71468+ struct mm_struct *mm = vma->vm_mm;
71469+ unsigned long address_m;
71470+ spinlock_t *ptl_m;
71471+ struct vm_area_struct *vma_m;
71472+ pmd_t *pmd_m;
71473+ pte_t *pte_m, entry_m;
71474+
71475+ vma_m = pax_find_mirror_vma(vma);
71476+ if (!vma_m)
71477+ return;
71478+
71479+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71480+ address_m = address + SEGMEXEC_TASK_SIZE;
71481+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71482+ pte_m = pte_offset_map(pmd_m, address_m);
71483+ ptl_m = pte_lockptr(mm, pmd_m);
71484+ if (ptl != ptl_m) {
71485+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71486+ if (!pte_none(*pte_m))
71487+ goto out;
71488+ }
71489+
71490+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
71491+ set_pte_at(mm, address_m, pte_m, entry_m);
71492+out:
71493+ if (ptl != ptl_m)
71494+ spin_unlock(ptl_m);
71495+ pte_unmap(pte_m);
71496+}
71497+
71498+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
71499+{
71500+ struct page *page_m;
71501+ pte_t entry;
71502+
71503+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
71504+ goto out;
71505+
71506+ entry = *pte;
71507+ page_m = vm_normal_page(vma, address, entry);
71508+ if (!page_m)
71509+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
71510+ else if (PageAnon(page_m)) {
71511+ if (pax_find_mirror_vma(vma)) {
71512+ pte_unmap_unlock(pte, ptl);
71513+ lock_page(page_m);
71514+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
71515+ if (pte_same(entry, *pte))
71516+ pax_mirror_anon_pte(vma, address, page_m, ptl);
71517+ else
71518+ unlock_page(page_m);
71519+ }
71520+ } else
71521+ pax_mirror_file_pte(vma, address, page_m, ptl);
71522+
71523+out:
71524+ pte_unmap_unlock(pte, ptl);
71525+}
71526+#endif
71527+
71528 /*
71529 * This routine handles present pages, when users try to write
71530 * to a shared page. It is done by copying the page to a new address
71531@@ -2692,6 +2889,12 @@ gotten:
71532 */
71533 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71534 if (likely(pte_same(*page_table, orig_pte))) {
71535+
71536+#ifdef CONFIG_PAX_SEGMEXEC
71537+ if (pax_find_mirror_vma(vma))
71538+ BUG_ON(!trylock_page(new_page));
71539+#endif
71540+
71541 if (old_page) {
71542 if (!PageAnon(old_page)) {
71543 dec_mm_counter_fast(mm, MM_FILEPAGES);
71544@@ -2743,6 +2946,10 @@ gotten:
71545 page_remove_rmap(old_page);
71546 }
71547
71548+#ifdef CONFIG_PAX_SEGMEXEC
71549+ pax_mirror_anon_pte(vma, address, new_page, ptl);
71550+#endif
71551+
71552 /* Free the old page.. */
71553 new_page = old_page;
71554 ret |= VM_FAULT_WRITE;
71555@@ -3022,6 +3229,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
71556 swap_free(entry);
71557 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
71558 try_to_free_swap(page);
71559+
71560+#ifdef CONFIG_PAX_SEGMEXEC
71561+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
71562+#endif
71563+
71564 unlock_page(page);
71565 if (swapcache) {
71566 /*
71567@@ -3045,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
71568
71569 /* No need to invalidate - it was non-present before */
71570 update_mmu_cache(vma, address, page_table);
71571+
71572+#ifdef CONFIG_PAX_SEGMEXEC
71573+ pax_mirror_anon_pte(vma, address, page, ptl);
71574+#endif
71575+
71576 unlock:
71577 pte_unmap_unlock(page_table, ptl);
71578 out:
71579@@ -3064,40 +3281,6 @@ out_release:
71580 }
71581
71582 /*
71583- * This is like a special single-page "expand_{down|up}wards()",
71584- * except we must first make sure that 'address{-|+}PAGE_SIZE'
71585- * doesn't hit another vma.
71586- */
71587-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
71588-{
71589- address &= PAGE_MASK;
71590- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
71591- struct vm_area_struct *prev = vma->vm_prev;
71592-
71593- /*
71594- * Is there a mapping abutting this one below?
71595- *
71596- * That's only ok if it's the same stack mapping
71597- * that has gotten split..
71598- */
71599- if (prev && prev->vm_end == address)
71600- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
71601-
71602- expand_downwards(vma, address - PAGE_SIZE);
71603- }
71604- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
71605- struct vm_area_struct *next = vma->vm_next;
71606-
71607- /* As VM_GROWSDOWN but s/below/above/ */
71608- if (next && next->vm_start == address + PAGE_SIZE)
71609- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
71610-
71611- expand_upwards(vma, address + PAGE_SIZE);
71612- }
71613- return 0;
71614-}
71615-
71616-/*
71617 * We enter with non-exclusive mmap_sem (to exclude vma changes,
71618 * but allow concurrent faults), and pte mapped but not yet locked.
71619 * We return with mmap_sem still held, but pte unmapped and unlocked.
71620@@ -3106,27 +3289,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71621 unsigned long address, pte_t *page_table, pmd_t *pmd,
71622 unsigned int flags)
71623 {
71624- struct page *page;
71625+ struct page *page = NULL;
71626 spinlock_t *ptl;
71627 pte_t entry;
71628
71629- pte_unmap(page_table);
71630-
71631- /* Check if we need to add a guard page to the stack */
71632- if (check_stack_guard_page(vma, address) < 0)
71633- return VM_FAULT_SIGBUS;
71634-
71635- /* Use the zero-page for reads */
71636 if (!(flags & FAULT_FLAG_WRITE)) {
71637 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
71638 vma->vm_page_prot));
71639- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71640+ ptl = pte_lockptr(mm, pmd);
71641+ spin_lock(ptl);
71642 if (!pte_none(*page_table))
71643 goto unlock;
71644 goto setpte;
71645 }
71646
71647 /* Allocate our own private page. */
71648+ pte_unmap(page_table);
71649+
71650 if (unlikely(anon_vma_prepare(vma)))
71651 goto oom;
71652 page = alloc_zeroed_user_highpage_movable(vma, address);
71653@@ -3145,6 +3324,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71654 if (!pte_none(*page_table))
71655 goto release;
71656
71657+#ifdef CONFIG_PAX_SEGMEXEC
71658+ if (pax_find_mirror_vma(vma))
71659+ BUG_ON(!trylock_page(page));
71660+#endif
71661+
71662 inc_mm_counter_fast(mm, MM_ANONPAGES);
71663 page_add_new_anon_rmap(page, vma, address);
71664 setpte:
71665@@ -3152,6 +3336,12 @@ setpte:
71666
71667 /* No need to invalidate - it was non-present before */
71668 update_mmu_cache(vma, address, page_table);
71669+
71670+#ifdef CONFIG_PAX_SEGMEXEC
71671+ if (page)
71672+ pax_mirror_anon_pte(vma, address, page, ptl);
71673+#endif
71674+
71675 unlock:
71676 pte_unmap_unlock(page_table, ptl);
71677 return 0;
71678@@ -3295,6 +3485,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71679 */
71680 /* Only go through if we didn't race with anybody else... */
71681 if (likely(pte_same(*page_table, orig_pte))) {
71682+
71683+#ifdef CONFIG_PAX_SEGMEXEC
71684+ if (anon && pax_find_mirror_vma(vma))
71685+ BUG_ON(!trylock_page(page));
71686+#endif
71687+
71688 flush_icache_page(vma, page);
71689 entry = mk_pte(page, vma->vm_page_prot);
71690 if (flags & FAULT_FLAG_WRITE)
71691@@ -3314,6 +3510,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71692
71693 /* no need to invalidate: a not-present page won't be cached */
71694 update_mmu_cache(vma, address, page_table);
71695+
71696+#ifdef CONFIG_PAX_SEGMEXEC
71697+ if (anon)
71698+ pax_mirror_anon_pte(vma, address, page, ptl);
71699+ else
71700+ pax_mirror_file_pte(vma, address, page, ptl);
71701+#endif
71702+
71703 } else {
71704 if (cow_page)
71705 mem_cgroup_uncharge_page(cow_page);
71706@@ -3467,6 +3671,12 @@ int handle_pte_fault(struct mm_struct *mm,
71707 if (flags & FAULT_FLAG_WRITE)
71708 flush_tlb_fix_spurious_fault(vma, address);
71709 }
71710+
71711+#ifdef CONFIG_PAX_SEGMEXEC
71712+ pax_mirror_pte(vma, address, pte, pmd, ptl);
71713+ return 0;
71714+#endif
71715+
71716 unlock:
71717 pte_unmap_unlock(pte, ptl);
71718 return 0;
71719@@ -3483,6 +3693,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71720 pmd_t *pmd;
71721 pte_t *pte;
71722
71723+#ifdef CONFIG_PAX_SEGMEXEC
71724+ struct vm_area_struct *vma_m;
71725+#endif
71726+
71727 __set_current_state(TASK_RUNNING);
71728
71729 count_vm_event(PGFAULT);
71730@@ -3494,6 +3708,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71731 if (unlikely(is_vm_hugetlb_page(vma)))
71732 return hugetlb_fault(mm, vma, address, flags);
71733
71734+#ifdef CONFIG_PAX_SEGMEXEC
71735+ vma_m = pax_find_mirror_vma(vma);
71736+ if (vma_m) {
71737+ unsigned long address_m;
71738+ pgd_t *pgd_m;
71739+ pud_t *pud_m;
71740+ pmd_t *pmd_m;
71741+
71742+ if (vma->vm_start > vma_m->vm_start) {
71743+ address_m = address;
71744+ address -= SEGMEXEC_TASK_SIZE;
71745+ vma = vma_m;
71746+ } else
71747+ address_m = address + SEGMEXEC_TASK_SIZE;
71748+
71749+ pgd_m = pgd_offset(mm, address_m);
71750+ pud_m = pud_alloc(mm, pgd_m, address_m);
71751+ if (!pud_m)
71752+ return VM_FAULT_OOM;
71753+ pmd_m = pmd_alloc(mm, pud_m, address_m);
71754+ if (!pmd_m)
71755+ return VM_FAULT_OOM;
71756+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
71757+ return VM_FAULT_OOM;
71758+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
71759+ }
71760+#endif
71761+
71762 retry:
71763 pgd = pgd_offset(mm, address);
71764 pud = pud_alloc(mm, pgd, address);
71765@@ -3535,7 +3777,7 @@ retry:
71766 * run pte_offset_map on the pmd, if an huge pmd could
71767 * materialize from under us from a different thread.
71768 */
71769- if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
71770+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71771 return VM_FAULT_OOM;
71772 /* if an huge pmd materialized from under us just retry later */
71773 if (unlikely(pmd_trans_huge(*pmd)))
71774@@ -3572,6 +3814,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
71775 spin_unlock(&mm->page_table_lock);
71776 return 0;
71777 }
71778+
71779+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
71780+{
71781+ pud_t *new = pud_alloc_one(mm, address);
71782+ if (!new)
71783+ return -ENOMEM;
71784+
71785+ smp_wmb(); /* See comment in __pte_alloc */
71786+
71787+ spin_lock(&mm->page_table_lock);
71788+ if (pgd_present(*pgd)) /* Another has populated it */
71789+ pud_free(mm, new);
71790+ else
71791+ pgd_populate_kernel(mm, pgd, new);
71792+ spin_unlock(&mm->page_table_lock);
71793+ return 0;
71794+}
71795 #endif /* __PAGETABLE_PUD_FOLDED */
71796
71797 #ifndef __PAGETABLE_PMD_FOLDED
71798@@ -3602,6 +3861,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
71799 spin_unlock(&mm->page_table_lock);
71800 return 0;
71801 }
71802+
71803+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
71804+{
71805+ pmd_t *new = pmd_alloc_one(mm, address);
71806+ if (!new)
71807+ return -ENOMEM;
71808+
71809+ smp_wmb(); /* See comment in __pte_alloc */
71810+
71811+ spin_lock(&mm->page_table_lock);
71812+#ifndef __ARCH_HAS_4LEVEL_HACK
71813+ if (pud_present(*pud)) /* Another has populated it */
71814+ pmd_free(mm, new);
71815+ else
71816+ pud_populate_kernel(mm, pud, new);
71817+#else
71818+ if (pgd_present(*pud)) /* Another has populated it */
71819+ pmd_free(mm, new);
71820+ else
71821+ pgd_populate_kernel(mm, pud, new);
71822+#endif /* __ARCH_HAS_4LEVEL_HACK */
71823+ spin_unlock(&mm->page_table_lock);
71824+ return 0;
71825+}
71826 #endif /* __PAGETABLE_PMD_FOLDED */
71827
71828 int make_pages_present(unsigned long addr, unsigned long end)
71829@@ -3639,7 +3922,7 @@ static int __init gate_vma_init(void)
71830 gate_vma.vm_start = FIXADDR_USER_START;
71831 gate_vma.vm_end = FIXADDR_USER_END;
71832 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
71833- gate_vma.vm_page_prot = __P101;
71834+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
71835
71836 return 0;
71837 }
71838diff --git a/mm/mempolicy.c b/mm/mempolicy.c
71839index 1d771e4..f9a6808 100644
71840--- a/mm/mempolicy.c
71841+++ b/mm/mempolicy.c
71842@@ -619,6 +619,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71843 unsigned long vmstart;
71844 unsigned long vmend;
71845
71846+#ifdef CONFIG_PAX_SEGMEXEC
71847+ struct vm_area_struct *vma_m;
71848+#endif
71849+
71850 vma = find_vma(mm, start);
71851 if (!vma || vma->vm_start > start)
71852 return -EFAULT;
71853@@ -672,6 +676,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71854 if (err)
71855 goto out;
71856 }
71857+
71858+#ifdef CONFIG_PAX_SEGMEXEC
71859+ vma_m = pax_find_mirror_vma(vma);
71860+ if (vma_m && vma_m->vm_ops && vma_m->vm_ops->set_policy) {
71861+ err = vma_m->vm_ops->set_policy(vma_m, new_pol);
71862+ if (err)
71863+ goto out;
71864+ }
71865+#endif
71866+
71867 }
71868
71869 out:
71870@@ -1125,6 +1139,17 @@ static long do_mbind(unsigned long start, unsigned long len,
71871
71872 if (end < start)
71873 return -EINVAL;
71874+
71875+#ifdef CONFIG_PAX_SEGMEXEC
71876+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
71877+ if (end > SEGMEXEC_TASK_SIZE)
71878+ return -EINVAL;
71879+ } else
71880+#endif
71881+
71882+ if (end > TASK_SIZE)
71883+ return -EINVAL;
71884+
71885 if (end == start)
71886 return 0;
71887
71888@@ -1348,8 +1373,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71889 */
71890 tcred = __task_cred(task);
71891 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
71892- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
71893- !capable(CAP_SYS_NICE)) {
71894+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
71895 rcu_read_unlock();
71896 err = -EPERM;
71897 goto out_put;
71898@@ -1380,6 +1404,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71899 goto out;
71900 }
71901
71902+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71903+ if (mm != current->mm &&
71904+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
71905+ mmput(mm);
71906+ err = -EPERM;
71907+ goto out;
71908+ }
71909+#endif
71910+
71911 err = do_migrate_pages(mm, old, new,
71912 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
71913
71914diff --git a/mm/mlock.c b/mm/mlock.c
71915index ef726e8..cd7f1ec 100644
71916--- a/mm/mlock.c
71917+++ b/mm/mlock.c
71918@@ -13,6 +13,7 @@
71919 #include <linux/pagemap.h>
71920 #include <linux/mempolicy.h>
71921 #include <linux/syscalls.h>
71922+#include <linux/security.h>
71923 #include <linux/sched.h>
71924 #include <linux/export.h>
71925 #include <linux/rmap.h>
71926@@ -376,7 +377,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
71927 {
71928 unsigned long nstart, end, tmp;
71929 struct vm_area_struct * vma, * prev;
71930- int error;
71931+ int error = 0;
71932
71933 VM_BUG_ON(start & ~PAGE_MASK);
71934 VM_BUG_ON(len != PAGE_ALIGN(len));
71935@@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
71936 return -EINVAL;
71937 if (end == start)
71938 return 0;
71939+ if (end > TASK_SIZE)
71940+ return -EINVAL;
71941+
71942 vma = find_vma(current->mm, start);
71943 if (!vma || vma->vm_start > start)
71944 return -ENOMEM;
71945@@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
71946 for (nstart = start ; ; ) {
71947 vm_flags_t newflags;
71948
71949+#ifdef CONFIG_PAX_SEGMEXEC
71950+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71951+ break;
71952+#endif
71953+
71954 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
71955
71956 newflags = vma->vm_flags | VM_LOCKED;
71957@@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
71958 lock_limit >>= PAGE_SHIFT;
71959
71960 /* check against resource limits */
71961+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
71962 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
71963 error = do_mlock(start, len, 1);
71964 up_write(&current->mm->mmap_sem);
71965@@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
71966 static int do_mlockall(int flags)
71967 {
71968 struct vm_area_struct * vma, * prev = NULL;
71969- unsigned int def_flags = 0;
71970
71971 if (flags & MCL_FUTURE)
71972- def_flags = VM_LOCKED;
71973- current->mm->def_flags = def_flags;
71974+ current->mm->def_flags |= VM_LOCKED;
71975+ else
71976+ current->mm->def_flags &= ~VM_LOCKED;
71977 if (flags == MCL_FUTURE)
71978 goto out;
71979
71980 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
71981 vm_flags_t newflags;
71982
71983+#ifdef CONFIG_PAX_SEGMEXEC
71984+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71985+ break;
71986+#endif
71987+
71988+ BUG_ON(vma->vm_end > TASK_SIZE);
71989 newflags = vma->vm_flags | VM_LOCKED;
71990 if (!(flags & MCL_CURRENT))
71991 newflags &= ~VM_LOCKED;
71992@@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
71993 lock_limit >>= PAGE_SHIFT;
71994
71995 ret = -ENOMEM;
71996+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
71997 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
71998 capable(CAP_IPC_LOCK))
71999 ret = do_mlockall(flags);
72000diff --git a/mm/mmap.c b/mm/mmap.c
72001index 3edfcdf..4a27ae9 100644
72002--- a/mm/mmap.c
72003+++ b/mm/mmap.c
72004@@ -47,6 +47,16 @@
72005 #define arch_rebalance_pgtables(addr, len) (addr)
72006 #endif
72007
72008+static inline void verify_mm_writelocked(struct mm_struct *mm)
72009+{
72010+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
72011+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72012+ up_read(&mm->mmap_sem);
72013+ BUG();
72014+ }
72015+#endif
72016+}
72017+
72018 static void unmap_region(struct mm_struct *mm,
72019 struct vm_area_struct *vma, struct vm_area_struct *prev,
72020 unsigned long start, unsigned long end);
72021@@ -72,22 +82,32 @@ static void unmap_region(struct mm_struct *mm,
72022 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
72023 *
72024 */
72025-pgprot_t protection_map[16] = {
72026+pgprot_t protection_map[16] __read_only = {
72027 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
72028 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
72029 };
72030
72031-pgprot_t vm_get_page_prot(unsigned long vm_flags)
72032+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
72033 {
72034- return __pgprot(pgprot_val(protection_map[vm_flags &
72035+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
72036 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
72037 pgprot_val(arch_vm_get_page_prot(vm_flags)));
72038+
72039+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72040+ if (!(__supported_pte_mask & _PAGE_NX) &&
72041+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
72042+ (vm_flags & (VM_READ | VM_WRITE)))
72043+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
72044+#endif
72045+
72046+ return prot;
72047 }
72048 EXPORT_SYMBOL(vm_get_page_prot);
72049
72050 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
72051 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
72052 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
72053+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
72054 /*
72055 * Make sure vm_committed_as in one cacheline and not cacheline shared with
72056 * other variables. It can be updated by several CPUs frequently.
72057@@ -229,6 +249,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
72058 struct vm_area_struct *next = vma->vm_next;
72059
72060 might_sleep();
72061+ BUG_ON(vma->vm_mirror);
72062 if (vma->vm_ops && vma->vm_ops->close)
72063 vma->vm_ops->close(vma);
72064 if (vma->vm_file) {
72065@@ -275,6 +296,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
72066 * not page aligned -Ram Gupta
72067 */
72068 rlim = rlimit(RLIMIT_DATA);
72069+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
72070 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
72071 (mm->end_data - mm->start_data) > rlim)
72072 goto out;
72073@@ -708,6 +730,12 @@ static int
72074 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
72075 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72076 {
72077+
72078+#ifdef CONFIG_PAX_SEGMEXEC
72079+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
72080+ return 0;
72081+#endif
72082+
72083 if (is_mergeable_vma(vma, file, vm_flags) &&
72084 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72085 if (vma->vm_pgoff == vm_pgoff)
72086@@ -727,6 +755,12 @@ static int
72087 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72088 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72089 {
72090+
72091+#ifdef CONFIG_PAX_SEGMEXEC
72092+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
72093+ return 0;
72094+#endif
72095+
72096 if (is_mergeable_vma(vma, file, vm_flags) &&
72097 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72098 pgoff_t vm_pglen;
72099@@ -769,13 +803,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72100 struct vm_area_struct *vma_merge(struct mm_struct *mm,
72101 struct vm_area_struct *prev, unsigned long addr,
72102 unsigned long end, unsigned long vm_flags,
72103- struct anon_vma *anon_vma, struct file *file,
72104+ struct anon_vma *anon_vma, struct file *file,
72105 pgoff_t pgoff, struct mempolicy *policy)
72106 {
72107 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
72108 struct vm_area_struct *area, *next;
72109 int err;
72110
72111+#ifdef CONFIG_PAX_SEGMEXEC
72112+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
72113+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
72114+
72115+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
72116+#endif
72117+
72118 /*
72119 * We later require that vma->vm_flags == vm_flags,
72120 * so this tests vma->vm_flags & VM_SPECIAL, too.
72121@@ -791,6 +832,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72122 if (next && next->vm_end == end) /* cases 6, 7, 8 */
72123 next = next->vm_next;
72124
72125+#ifdef CONFIG_PAX_SEGMEXEC
72126+ if (prev)
72127+ prev_m = pax_find_mirror_vma(prev);
72128+ if (area)
72129+ area_m = pax_find_mirror_vma(area);
72130+ if (next)
72131+ next_m = pax_find_mirror_vma(next);
72132+#endif
72133+
72134 /*
72135 * Can it merge with the predecessor?
72136 */
72137@@ -810,9 +860,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72138 /* cases 1, 6 */
72139 err = vma_adjust(prev, prev->vm_start,
72140 next->vm_end, prev->vm_pgoff, NULL);
72141- } else /* cases 2, 5, 7 */
72142+
72143+#ifdef CONFIG_PAX_SEGMEXEC
72144+ if (!err && prev_m)
72145+ err = vma_adjust(prev_m, prev_m->vm_start,
72146+ next_m->vm_end, prev_m->vm_pgoff, NULL);
72147+#endif
72148+
72149+ } else { /* cases 2, 5, 7 */
72150 err = vma_adjust(prev, prev->vm_start,
72151 end, prev->vm_pgoff, NULL);
72152+
72153+#ifdef CONFIG_PAX_SEGMEXEC
72154+ if (!err && prev_m)
72155+ err = vma_adjust(prev_m, prev_m->vm_start,
72156+ end_m, prev_m->vm_pgoff, NULL);
72157+#endif
72158+
72159+ }
72160 if (err)
72161 return NULL;
72162 khugepaged_enter_vma_merge(prev);
72163@@ -826,12 +891,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72164 mpol_equal(policy, vma_policy(next)) &&
72165 can_vma_merge_before(next, vm_flags,
72166 anon_vma, file, pgoff+pglen)) {
72167- if (prev && addr < prev->vm_end) /* case 4 */
72168+ if (prev && addr < prev->vm_end) { /* case 4 */
72169 err = vma_adjust(prev, prev->vm_start,
72170 addr, prev->vm_pgoff, NULL);
72171- else /* cases 3, 8 */
72172+
72173+#ifdef CONFIG_PAX_SEGMEXEC
72174+ if (!err && prev_m)
72175+ err = vma_adjust(prev_m, prev_m->vm_start,
72176+ addr_m, prev_m->vm_pgoff, NULL);
72177+#endif
72178+
72179+ } else { /* cases 3, 8 */
72180 err = vma_adjust(area, addr, next->vm_end,
72181 next->vm_pgoff - pglen, NULL);
72182+
72183+#ifdef CONFIG_PAX_SEGMEXEC
72184+ if (!err && area_m)
72185+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
72186+ next_m->vm_pgoff - pglen, NULL);
72187+#endif
72188+
72189+ }
72190 if (err)
72191 return NULL;
72192 khugepaged_enter_vma_merge(area);
72193@@ -940,14 +1020,11 @@ none:
72194 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
72195 struct file *file, long pages)
72196 {
72197- const unsigned long stack_flags
72198- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
72199-
72200 if (file) {
72201 mm->shared_vm += pages;
72202 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
72203 mm->exec_vm += pages;
72204- } else if (flags & stack_flags)
72205+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
72206 mm->stack_vm += pages;
72207 if (flags & (VM_RESERVED|VM_IO))
72208 mm->reserved_vm += pages;
72209@@ -985,7 +1062,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72210 * (the exception is when the underlying filesystem is noexec
72211 * mounted, in which case we dont add PROT_EXEC.)
72212 */
72213- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72214+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72215 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
72216 prot |= PROT_EXEC;
72217
72218@@ -1011,7 +1088,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72219 /* Obtain the address to map to. we verify (or select) it and ensure
72220 * that it represents a valid section of the address space.
72221 */
72222- addr = get_unmapped_area(file, addr, len, pgoff, flags);
72223+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
72224 if (addr & ~PAGE_MASK)
72225 return addr;
72226
72227@@ -1022,6 +1099,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72228 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
72229 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
72230
72231+#ifdef CONFIG_PAX_MPROTECT
72232+ if (mm->pax_flags & MF_PAX_MPROTECT) {
72233+#ifndef CONFIG_PAX_MPROTECT_COMPAT
72234+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
72235+ gr_log_rwxmmap(file);
72236+
72237+#ifdef CONFIG_PAX_EMUPLT
72238+ vm_flags &= ~VM_EXEC;
72239+#else
72240+ return -EPERM;
72241+#endif
72242+
72243+ }
72244+
72245+ if (!(vm_flags & VM_EXEC))
72246+ vm_flags &= ~VM_MAYEXEC;
72247+#else
72248+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72249+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72250+#endif
72251+ else
72252+ vm_flags &= ~VM_MAYWRITE;
72253+ }
72254+#endif
72255+
72256+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72257+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
72258+ vm_flags &= ~VM_PAGEEXEC;
72259+#endif
72260+
72261 if (flags & MAP_LOCKED)
72262 if (!can_do_mlock())
72263 return -EPERM;
72264@@ -1033,6 +1140,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72265 locked += mm->locked_vm;
72266 lock_limit = rlimit(RLIMIT_MEMLOCK);
72267 lock_limit >>= PAGE_SHIFT;
72268+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72269 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
72270 return -EAGAIN;
72271 }
72272@@ -1099,6 +1207,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72273 }
72274 }
72275
72276+ if (!gr_acl_handle_mmap(file, prot))
72277+ return -EACCES;
72278+
72279 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
72280 }
72281
72282@@ -1175,7 +1286,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
72283 vm_flags_t vm_flags = vma->vm_flags;
72284
72285 /* If it was private or non-writable, the write bit is already clear */
72286- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
72287+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
72288 return 0;
72289
72290 /* The backer wishes to know when pages are first written to? */
72291@@ -1224,14 +1335,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
72292 unsigned long charged = 0;
72293 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
72294
72295+#ifdef CONFIG_PAX_SEGMEXEC
72296+ struct vm_area_struct *vma_m = NULL;
72297+#endif
72298+
72299+ /*
72300+ * mm->mmap_sem is required to protect against another thread
72301+ * changing the mappings in case we sleep.
72302+ */
72303+ verify_mm_writelocked(mm);
72304+
72305 /* Clear old maps */
72306 error = -ENOMEM;
72307-munmap_back:
72308 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72309 if (vma && vma->vm_start < addr + len) {
72310 if (do_munmap(mm, addr, len))
72311 return -ENOMEM;
72312- goto munmap_back;
72313+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72314+ BUG_ON(vma && vma->vm_start < addr + len);
72315 }
72316
72317 /* Check against address space limit. */
72318@@ -1280,6 +1401,16 @@ munmap_back:
72319 goto unacct_error;
72320 }
72321
72322+#ifdef CONFIG_PAX_SEGMEXEC
72323+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
72324+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72325+ if (!vma_m) {
72326+ error = -ENOMEM;
72327+ goto free_vma;
72328+ }
72329+ }
72330+#endif
72331+
72332 vma->vm_mm = mm;
72333 vma->vm_start = addr;
72334 vma->vm_end = addr + len;
72335@@ -1304,6 +1435,19 @@ munmap_back:
72336 error = file->f_op->mmap(file, vma);
72337 if (error)
72338 goto unmap_and_free_vma;
72339+
72340+#ifdef CONFIG_PAX_SEGMEXEC
72341+ if (vma_m && (vm_flags & VM_EXECUTABLE))
72342+ added_exe_file_vma(mm);
72343+#endif
72344+
72345+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72346+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
72347+ vma->vm_flags |= VM_PAGEEXEC;
72348+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72349+ }
72350+#endif
72351+
72352 if (vm_flags & VM_EXECUTABLE)
72353 added_exe_file_vma(mm);
72354
72355@@ -1341,6 +1485,11 @@ munmap_back:
72356 vma_link(mm, vma, prev, rb_link, rb_parent);
72357 file = vma->vm_file;
72358
72359+#ifdef CONFIG_PAX_SEGMEXEC
72360+ if (vma_m)
72361+ BUG_ON(pax_mirror_vma(vma_m, vma));
72362+#endif
72363+
72364 /* Once vma denies write, undo our temporary denial count */
72365 if (correct_wcount)
72366 atomic_inc(&inode->i_writecount);
72367@@ -1349,6 +1498,7 @@ out:
72368
72369 mm->total_vm += len >> PAGE_SHIFT;
72370 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
72371+ track_exec_limit(mm, addr, addr + len, vm_flags);
72372 if (vm_flags & VM_LOCKED) {
72373 if (!mlock_vma_pages_range(vma, addr, addr + len))
72374 mm->locked_vm += (len >> PAGE_SHIFT);
72375@@ -1371,6 +1521,12 @@ unmap_and_free_vma:
72376 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
72377 charged = 0;
72378 free_vma:
72379+
72380+#ifdef CONFIG_PAX_SEGMEXEC
72381+ if (vma_m)
72382+ kmem_cache_free(vm_area_cachep, vma_m);
72383+#endif
72384+
72385 kmem_cache_free(vm_area_cachep, vma);
72386 unacct_error:
72387 if (charged)
72388@@ -1378,6 +1534,44 @@ unacct_error:
72389 return error;
72390 }
72391
72392+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
72393+{
72394+ if (!vma) {
72395+#ifdef CONFIG_STACK_GROWSUP
72396+ if (addr > sysctl_heap_stack_gap)
72397+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
72398+ else
72399+ vma = find_vma(current->mm, 0);
72400+ if (vma && (vma->vm_flags & VM_GROWSUP))
72401+ return false;
72402+#endif
72403+ return true;
72404+ }
72405+
72406+ if (addr + len > vma->vm_start)
72407+ return false;
72408+
72409+ if (vma->vm_flags & VM_GROWSDOWN)
72410+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
72411+#ifdef CONFIG_STACK_GROWSUP
72412+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
72413+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
72414+#endif
72415+
72416+ return true;
72417+}
72418+
72419+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
72420+{
72421+ if (vma->vm_start < len)
72422+ return -ENOMEM;
72423+ if (!(vma->vm_flags & VM_GROWSDOWN))
72424+ return vma->vm_start - len;
72425+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
72426+ return vma->vm_start - len - sysctl_heap_stack_gap;
72427+ return -ENOMEM;
72428+}
72429+
72430 /* Get an address range which is currently unmapped.
72431 * For shmat() with addr=0.
72432 *
72433@@ -1404,18 +1598,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
72434 if (flags & MAP_FIXED)
72435 return addr;
72436
72437+#ifdef CONFIG_PAX_RANDMMAP
72438+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
72439+#endif
72440+
72441 if (addr) {
72442 addr = PAGE_ALIGN(addr);
72443- vma = find_vma(mm, addr);
72444- if (TASK_SIZE - len >= addr &&
72445- (!vma || addr + len <= vma->vm_start))
72446- return addr;
72447+ if (TASK_SIZE - len >= addr) {
72448+ vma = find_vma(mm, addr);
72449+ if (check_heap_stack_gap(vma, addr, len))
72450+ return addr;
72451+ }
72452 }
72453 if (len > mm->cached_hole_size) {
72454- start_addr = addr = mm->free_area_cache;
72455+ start_addr = addr = mm->free_area_cache;
72456 } else {
72457- start_addr = addr = TASK_UNMAPPED_BASE;
72458- mm->cached_hole_size = 0;
72459+ start_addr = addr = mm->mmap_base;
72460+ mm->cached_hole_size = 0;
72461 }
72462
72463 full_search:
72464@@ -1426,34 +1625,40 @@ full_search:
72465 * Start a new search - just in case we missed
72466 * some holes.
72467 */
72468- if (start_addr != TASK_UNMAPPED_BASE) {
72469- addr = TASK_UNMAPPED_BASE;
72470- start_addr = addr;
72471+ if (start_addr != mm->mmap_base) {
72472+ start_addr = addr = mm->mmap_base;
72473 mm->cached_hole_size = 0;
72474 goto full_search;
72475 }
72476 return -ENOMEM;
72477 }
72478- if (!vma || addr + len <= vma->vm_start) {
72479- /*
72480- * Remember the place where we stopped the search:
72481- */
72482- mm->free_area_cache = addr + len;
72483- return addr;
72484- }
72485+ if (check_heap_stack_gap(vma, addr, len))
72486+ break;
72487 if (addr + mm->cached_hole_size < vma->vm_start)
72488 mm->cached_hole_size = vma->vm_start - addr;
72489 addr = vma->vm_end;
72490 }
72491+
72492+ /*
72493+ * Remember the place where we stopped the search:
72494+ */
72495+ mm->free_area_cache = addr + len;
72496+ return addr;
72497 }
72498 #endif
72499
72500 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
72501 {
72502+
72503+#ifdef CONFIG_PAX_SEGMEXEC
72504+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72505+ return;
72506+#endif
72507+
72508 /*
72509 * Is this a new hole at the lowest possible address?
72510 */
72511- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
72512+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
72513 mm->free_area_cache = addr;
72514 }
72515
72516@@ -1469,7 +1674,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72517 {
72518 struct vm_area_struct *vma;
72519 struct mm_struct *mm = current->mm;
72520- unsigned long addr = addr0, start_addr;
72521+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
72522
72523 /* requested length too big for entire address space */
72524 if (len > TASK_SIZE)
72525@@ -1478,13 +1683,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72526 if (flags & MAP_FIXED)
72527 return addr;
72528
72529+#ifdef CONFIG_PAX_RANDMMAP
72530+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
72531+#endif
72532+
72533 /* requesting a specific address */
72534 if (addr) {
72535 addr = PAGE_ALIGN(addr);
72536- vma = find_vma(mm, addr);
72537- if (TASK_SIZE - len >= addr &&
72538- (!vma || addr + len <= vma->vm_start))
72539- return addr;
72540+ if (TASK_SIZE - len >= addr) {
72541+ vma = find_vma(mm, addr);
72542+ if (check_heap_stack_gap(vma, addr, len))
72543+ return addr;
72544+ }
72545 }
72546
72547 /* check if free_area_cache is useful for us */
72548@@ -1508,7 +1718,7 @@ try_again:
72549 * return with success:
72550 */
72551 vma = find_vma(mm, addr);
72552- if (!vma || addr+len <= vma->vm_start)
72553+ if (check_heap_stack_gap(vma, addr, len))
72554 /* remember the address as a hint for next time */
72555 return (mm->free_area_cache = addr);
72556
72557@@ -1517,8 +1727,8 @@ try_again:
72558 mm->cached_hole_size = vma->vm_start - addr;
72559
72560 /* try just below the current vma->vm_start */
72561- addr = vma->vm_start-len;
72562- } while (len < vma->vm_start);
72563+ addr = skip_heap_stack_gap(vma, len);
72564+ } while (!IS_ERR_VALUE(addr));
72565
72566 fail:
72567 /*
72568@@ -1541,13 +1751,21 @@ fail:
72569 * can happen with large stack limits and large mmap()
72570 * allocations.
72571 */
72572+ mm->mmap_base = TASK_UNMAPPED_BASE;
72573+
72574+#ifdef CONFIG_PAX_RANDMMAP
72575+ if (mm->pax_flags & MF_PAX_RANDMMAP)
72576+ mm->mmap_base += mm->delta_mmap;
72577+#endif
72578+
72579+ mm->free_area_cache = mm->mmap_base;
72580 mm->cached_hole_size = ~0UL;
72581- mm->free_area_cache = TASK_UNMAPPED_BASE;
72582 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
72583 /*
72584 * Restore the topdown base:
72585 */
72586- mm->free_area_cache = mm->mmap_base;
72587+ mm->mmap_base = base;
72588+ mm->free_area_cache = base;
72589 mm->cached_hole_size = ~0UL;
72590
72591 return addr;
72592@@ -1556,6 +1774,12 @@ fail:
72593
72594 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72595 {
72596+
72597+#ifdef CONFIG_PAX_SEGMEXEC
72598+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72599+ return;
72600+#endif
72601+
72602 /*
72603 * Is this a new hole at the highest possible address?
72604 */
72605@@ -1563,8 +1787,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72606 mm->free_area_cache = addr;
72607
72608 /* dont allow allocations above current base */
72609- if (mm->free_area_cache > mm->mmap_base)
72610+ if (mm->free_area_cache > mm->mmap_base) {
72611 mm->free_area_cache = mm->mmap_base;
72612+ mm->cached_hole_size = ~0UL;
72613+ }
72614 }
72615
72616 unsigned long
72617@@ -1663,6 +1889,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
72618 return vma;
72619 }
72620
72621+#ifdef CONFIG_PAX_SEGMEXEC
72622+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
72623+{
72624+ struct vm_area_struct *vma_m;
72625+
72626+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
72627+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
72628+ BUG_ON(vma->vm_mirror);
72629+ return NULL;
72630+ }
72631+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
72632+ vma_m = vma->vm_mirror;
72633+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
72634+ BUG_ON(vma->vm_file != vma_m->vm_file);
72635+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
72636+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
72637+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
72638+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
72639+ return vma_m;
72640+}
72641+#endif
72642+
72643 /*
72644 * Verify that the stack growth is acceptable and
72645 * update accounting. This is shared with both the
72646@@ -1679,6 +1927,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72647 return -ENOMEM;
72648
72649 /* Stack limit test */
72650+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
72651 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
72652 return -ENOMEM;
72653
72654@@ -1689,6 +1938,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72655 locked = mm->locked_vm + grow;
72656 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
72657 limit >>= PAGE_SHIFT;
72658+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72659 if (locked > limit && !capable(CAP_IPC_LOCK))
72660 return -ENOMEM;
72661 }
72662@@ -1719,37 +1969,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72663 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
72664 * vma is the last one with address > vma->vm_end. Have to extend vma.
72665 */
72666+#ifndef CONFIG_IA64
72667+static
72668+#endif
72669 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72670 {
72671 int error;
72672+ bool locknext;
72673
72674 if (!(vma->vm_flags & VM_GROWSUP))
72675 return -EFAULT;
72676
72677+ /* Also guard against wrapping around to address 0. */
72678+ if (address < PAGE_ALIGN(address+1))
72679+ address = PAGE_ALIGN(address+1);
72680+ else
72681+ return -ENOMEM;
72682+
72683 /*
72684 * We must make sure the anon_vma is allocated
72685 * so that the anon_vma locking is not a noop.
72686 */
72687 if (unlikely(anon_vma_prepare(vma)))
72688 return -ENOMEM;
72689+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
72690+ if (locknext && anon_vma_prepare(vma->vm_next))
72691+ return -ENOMEM;
72692 vma_lock_anon_vma(vma);
72693+ if (locknext)
72694+ vma_lock_anon_vma(vma->vm_next);
72695
72696 /*
72697 * vma->vm_start/vm_end cannot change under us because the caller
72698 * is required to hold the mmap_sem in read mode. We need the
72699- * anon_vma lock to serialize against concurrent expand_stacks.
72700- * Also guard against wrapping around to address 0.
72701+ * anon_vma locks to serialize against concurrent expand_stacks
72702+ * and expand_upwards.
72703 */
72704- if (address < PAGE_ALIGN(address+4))
72705- address = PAGE_ALIGN(address+4);
72706- else {
72707- vma_unlock_anon_vma(vma);
72708- return -ENOMEM;
72709- }
72710 error = 0;
72711
72712 /* Somebody else might have raced and expanded it already */
72713- if (address > vma->vm_end) {
72714+ 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)
72715+ error = -ENOMEM;
72716+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
72717 unsigned long size, grow;
72718
72719 size = address - vma->vm_start;
72720@@ -1764,6 +2025,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72721 }
72722 }
72723 }
72724+ if (locknext)
72725+ vma_unlock_anon_vma(vma->vm_next);
72726 vma_unlock_anon_vma(vma);
72727 khugepaged_enter_vma_merge(vma);
72728 return error;
72729@@ -1777,6 +2040,8 @@ int expand_downwards(struct vm_area_struct *vma,
72730 unsigned long address)
72731 {
72732 int error;
72733+ bool lockprev = false;
72734+ struct vm_area_struct *prev;
72735
72736 /*
72737 * We must make sure the anon_vma is allocated
72738@@ -1790,6 +2055,15 @@ int expand_downwards(struct vm_area_struct *vma,
72739 if (error)
72740 return error;
72741
72742+ prev = vma->vm_prev;
72743+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
72744+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
72745+#endif
72746+ if (lockprev && anon_vma_prepare(prev))
72747+ return -ENOMEM;
72748+ if (lockprev)
72749+ vma_lock_anon_vma(prev);
72750+
72751 vma_lock_anon_vma(vma);
72752
72753 /*
72754@@ -1799,9 +2073,17 @@ int expand_downwards(struct vm_area_struct *vma,
72755 */
72756
72757 /* Somebody else might have raced and expanded it already */
72758- if (address < vma->vm_start) {
72759+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
72760+ error = -ENOMEM;
72761+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
72762 unsigned long size, grow;
72763
72764+#ifdef CONFIG_PAX_SEGMEXEC
72765+ struct vm_area_struct *vma_m;
72766+
72767+ vma_m = pax_find_mirror_vma(vma);
72768+#endif
72769+
72770 size = vma->vm_end - address;
72771 grow = (vma->vm_start - address) >> PAGE_SHIFT;
72772
72773@@ -1811,11 +2093,22 @@ int expand_downwards(struct vm_area_struct *vma,
72774 if (!error) {
72775 vma->vm_start = address;
72776 vma->vm_pgoff -= grow;
72777+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
72778+
72779+#ifdef CONFIG_PAX_SEGMEXEC
72780+ if (vma_m) {
72781+ vma_m->vm_start -= grow << PAGE_SHIFT;
72782+ vma_m->vm_pgoff -= grow;
72783+ }
72784+#endif
72785+
72786 perf_event_mmap(vma);
72787 }
72788 }
72789 }
72790 vma_unlock_anon_vma(vma);
72791+ if (lockprev)
72792+ vma_unlock_anon_vma(prev);
72793 khugepaged_enter_vma_merge(vma);
72794 return error;
72795 }
72796@@ -1887,6 +2180,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
72797 do {
72798 long nrpages = vma_pages(vma);
72799
72800+#ifdef CONFIG_PAX_SEGMEXEC
72801+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
72802+ vma = remove_vma(vma);
72803+ continue;
72804+ }
72805+#endif
72806+
72807 if (vma->vm_flags & VM_ACCOUNT)
72808 nr_accounted += nrpages;
72809 mm->total_vm -= nrpages;
72810@@ -1933,6 +2233,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
72811 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
72812 vma->vm_prev = NULL;
72813 do {
72814+
72815+#ifdef CONFIG_PAX_SEGMEXEC
72816+ if (vma->vm_mirror) {
72817+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
72818+ vma->vm_mirror->vm_mirror = NULL;
72819+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
72820+ vma->vm_mirror = NULL;
72821+ }
72822+#endif
72823+
72824 rb_erase(&vma->vm_rb, &mm->mm_rb);
72825 mm->map_count--;
72826 tail_vma = vma;
72827@@ -1961,14 +2271,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72828 struct vm_area_struct *new;
72829 int err = -ENOMEM;
72830
72831+#ifdef CONFIG_PAX_SEGMEXEC
72832+ struct vm_area_struct *vma_m, *new_m = NULL;
72833+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
72834+#endif
72835+
72836 if (is_vm_hugetlb_page(vma) && (addr &
72837 ~(huge_page_mask(hstate_vma(vma)))))
72838 return -EINVAL;
72839
72840+#ifdef CONFIG_PAX_SEGMEXEC
72841+ vma_m = pax_find_mirror_vma(vma);
72842+#endif
72843+
72844 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72845 if (!new)
72846 goto out_err;
72847
72848+#ifdef CONFIG_PAX_SEGMEXEC
72849+ if (vma_m) {
72850+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72851+ if (!new_m) {
72852+ kmem_cache_free(vm_area_cachep, new);
72853+ goto out_err;
72854+ }
72855+ }
72856+#endif
72857+
72858 /* most fields are the same, copy all, and then fixup */
72859 *new = *vma;
72860
72861@@ -1981,6 +2310,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72862 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
72863 }
72864
72865+#ifdef CONFIG_PAX_SEGMEXEC
72866+ if (vma_m) {
72867+ *new_m = *vma_m;
72868+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
72869+ new_m->vm_mirror = new;
72870+ new->vm_mirror = new_m;
72871+
72872+ if (new_below)
72873+ new_m->vm_end = addr_m;
72874+ else {
72875+ new_m->vm_start = addr_m;
72876+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
72877+ }
72878+ }
72879+#endif
72880+
72881 pol = mpol_dup(vma_policy(vma));
72882 if (IS_ERR(pol)) {
72883 err = PTR_ERR(pol);
72884@@ -2006,6 +2351,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72885 else
72886 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
72887
72888+#ifdef CONFIG_PAX_SEGMEXEC
72889+ if (!err && vma_m) {
72890+ if (anon_vma_clone(new_m, vma_m))
72891+ goto out_free_mpol;
72892+
72893+ mpol_get(pol);
72894+ vma_set_policy(new_m, pol);
72895+
72896+ if (new_m->vm_file) {
72897+ get_file(new_m->vm_file);
72898+ if (vma_m->vm_flags & VM_EXECUTABLE)
72899+ added_exe_file_vma(mm);
72900+ }
72901+
72902+ if (new_m->vm_ops && new_m->vm_ops->open)
72903+ new_m->vm_ops->open(new_m);
72904+
72905+ if (new_below)
72906+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
72907+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
72908+ else
72909+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
72910+
72911+ if (err) {
72912+ if (new_m->vm_ops && new_m->vm_ops->close)
72913+ new_m->vm_ops->close(new_m);
72914+ if (new_m->vm_file) {
72915+ if (vma_m->vm_flags & VM_EXECUTABLE)
72916+ removed_exe_file_vma(mm);
72917+ fput(new_m->vm_file);
72918+ }
72919+ mpol_put(pol);
72920+ }
72921+ }
72922+#endif
72923+
72924 /* Success. */
72925 if (!err)
72926 return 0;
72927@@ -2018,10 +2399,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72928 removed_exe_file_vma(mm);
72929 fput(new->vm_file);
72930 }
72931- unlink_anon_vmas(new);
72932 out_free_mpol:
72933 mpol_put(pol);
72934 out_free_vma:
72935+
72936+#ifdef CONFIG_PAX_SEGMEXEC
72937+ if (new_m) {
72938+ unlink_anon_vmas(new_m);
72939+ kmem_cache_free(vm_area_cachep, new_m);
72940+ }
72941+#endif
72942+
72943+ unlink_anon_vmas(new);
72944 kmem_cache_free(vm_area_cachep, new);
72945 out_err:
72946 return err;
72947@@ -2034,6 +2423,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72948 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72949 unsigned long addr, int new_below)
72950 {
72951+
72952+#ifdef CONFIG_PAX_SEGMEXEC
72953+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72954+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
72955+ if (mm->map_count >= sysctl_max_map_count-1)
72956+ return -ENOMEM;
72957+ } else
72958+#endif
72959+
72960 if (mm->map_count >= sysctl_max_map_count)
72961 return -ENOMEM;
72962
72963@@ -2045,11 +2443,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72964 * work. This now handles partial unmappings.
72965 * Jeremy Fitzhardinge <jeremy@goop.org>
72966 */
72967+#ifdef CONFIG_PAX_SEGMEXEC
72968 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72969 {
72970+ int ret = __do_munmap(mm, start, len);
72971+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
72972+ return ret;
72973+
72974+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
72975+}
72976+
72977+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72978+#else
72979+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72980+#endif
72981+{
72982 unsigned long end;
72983 struct vm_area_struct *vma, *prev, *last;
72984
72985+ /*
72986+ * mm->mmap_sem is required to protect against another thread
72987+ * changing the mappings in case we sleep.
72988+ */
72989+ verify_mm_writelocked(mm);
72990+
72991 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
72992 return -EINVAL;
72993
72994@@ -2124,6 +2541,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72995 /* Fix up all other VM information */
72996 remove_vma_list(mm, vma);
72997
72998+ track_exec_limit(mm, start, end, 0UL);
72999+
73000 return 0;
73001 }
73002
73003@@ -2132,6 +2551,13 @@ int vm_munmap(unsigned long start, size_t len)
73004 int ret;
73005 struct mm_struct *mm = current->mm;
73006
73007+
73008+#ifdef CONFIG_PAX_SEGMEXEC
73009+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
73010+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
73011+ return -EINVAL;
73012+#endif
73013+
73014 down_write(&mm->mmap_sem);
73015 ret = do_munmap(mm, start, len);
73016 up_write(&mm->mmap_sem);
73017@@ -2145,16 +2571,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
73018 return vm_munmap(addr, len);
73019 }
73020
73021-static inline void verify_mm_writelocked(struct mm_struct *mm)
73022-{
73023-#ifdef CONFIG_DEBUG_VM
73024- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
73025- WARN_ON(1);
73026- up_read(&mm->mmap_sem);
73027- }
73028-#endif
73029-}
73030-
73031 /*
73032 * this is really a simplified "do_mmap". it only handles
73033 * anonymous maps. eventually we may be able to do some
73034@@ -2168,6 +2584,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73035 struct rb_node ** rb_link, * rb_parent;
73036 pgoff_t pgoff = addr >> PAGE_SHIFT;
73037 int error;
73038+ unsigned long charged;
73039
73040 len = PAGE_ALIGN(len);
73041 if (!len)
73042@@ -2175,16 +2592,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73043
73044 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
73045
73046+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
73047+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
73048+ flags &= ~VM_EXEC;
73049+
73050+#ifdef CONFIG_PAX_MPROTECT
73051+ if (mm->pax_flags & MF_PAX_MPROTECT)
73052+ flags &= ~VM_MAYEXEC;
73053+#endif
73054+
73055+ }
73056+#endif
73057+
73058 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
73059 if (error & ~PAGE_MASK)
73060 return error;
73061
73062+ charged = len >> PAGE_SHIFT;
73063+
73064 /*
73065 * mlock MCL_FUTURE?
73066 */
73067 if (mm->def_flags & VM_LOCKED) {
73068 unsigned long locked, lock_limit;
73069- locked = len >> PAGE_SHIFT;
73070+ locked = charged;
73071 locked += mm->locked_vm;
73072 lock_limit = rlimit(RLIMIT_MEMLOCK);
73073 lock_limit >>= PAGE_SHIFT;
73074@@ -2201,22 +2632,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73075 /*
73076 * Clear old maps. this also does some error checking for us
73077 */
73078- munmap_back:
73079 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73080 if (vma && vma->vm_start < addr + len) {
73081 if (do_munmap(mm, addr, len))
73082 return -ENOMEM;
73083- goto munmap_back;
73084- }
73085+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73086+ BUG_ON(vma && vma->vm_start < addr + len);
73087+ }
73088
73089 /* Check against address space limits *after* clearing old maps... */
73090- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
73091+ if (!may_expand_vm(mm, charged))
73092 return -ENOMEM;
73093
73094 if (mm->map_count > sysctl_max_map_count)
73095 return -ENOMEM;
73096
73097- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
73098+ if (security_vm_enough_memory_mm(mm, charged))
73099 return -ENOMEM;
73100
73101 /* Can we just expand an old private anonymous mapping? */
73102@@ -2230,7 +2661,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73103 */
73104 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73105 if (!vma) {
73106- vm_unacct_memory(len >> PAGE_SHIFT);
73107+ vm_unacct_memory(charged);
73108 return -ENOMEM;
73109 }
73110
73111@@ -2244,11 +2675,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73112 vma_link(mm, vma, prev, rb_link, rb_parent);
73113 out:
73114 perf_event_mmap(vma);
73115- mm->total_vm += len >> PAGE_SHIFT;
73116+ mm->total_vm += charged;
73117 if (flags & VM_LOCKED) {
73118 if (!mlock_vma_pages_range(vma, addr, addr + len))
73119- mm->locked_vm += (len >> PAGE_SHIFT);
73120+ mm->locked_vm += charged;
73121 }
73122+ track_exec_limit(mm, addr, addr + len, flags);
73123 return addr;
73124 }
73125
73126@@ -2306,6 +2738,7 @@ void exit_mmap(struct mm_struct *mm)
73127 while (vma) {
73128 if (vma->vm_flags & VM_ACCOUNT)
73129 nr_accounted += vma_pages(vma);
73130+ vma->vm_mirror = NULL;
73131 vma = remove_vma(vma);
73132 }
73133 vm_unacct_memory(nr_accounted);
73134@@ -2322,6 +2755,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73135 struct vm_area_struct * __vma, * prev;
73136 struct rb_node ** rb_link, * rb_parent;
73137
73138+#ifdef CONFIG_PAX_SEGMEXEC
73139+ struct vm_area_struct *vma_m = NULL;
73140+#endif
73141+
73142+ if (security_mmap_addr(vma->vm_start))
73143+ return -EPERM;
73144+
73145 /*
73146 * The vm_pgoff of a purely anonymous vma should be irrelevant
73147 * until its first write fault, when page's anon_vma and index
73148@@ -2348,7 +2788,21 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73149 if (vma->vm_file && uprobe_mmap(vma))
73150 return -EINVAL;
73151
73152+#ifdef CONFIG_PAX_SEGMEXEC
73153+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
73154+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73155+ if (!vma_m)
73156+ return -ENOMEM;
73157+ }
73158+#endif
73159+
73160 vma_link(mm, vma, prev, rb_link, rb_parent);
73161+
73162+#ifdef CONFIG_PAX_SEGMEXEC
73163+ if (vma_m)
73164+ BUG_ON(pax_mirror_vma(vma_m, vma));
73165+#endif
73166+
73167 return 0;
73168 }
73169
73170@@ -2367,6 +2821,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73171 struct mempolicy *pol;
73172 bool faulted_in_anon_vma = true;
73173
73174+ BUG_ON(vma->vm_mirror);
73175+
73176 /*
73177 * If anonymous vma has not yet been faulted, update new pgoff
73178 * to match new location, to increase its chance of merging.
73179@@ -2438,6 +2894,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73180 return NULL;
73181 }
73182
73183+#ifdef CONFIG_PAX_SEGMEXEC
73184+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
73185+{
73186+ struct vm_area_struct *prev_m;
73187+ struct rb_node **rb_link_m, *rb_parent_m;
73188+ struct mempolicy *pol_m;
73189+
73190+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
73191+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
73192+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
73193+ *vma_m = *vma;
73194+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
73195+ if (anon_vma_clone(vma_m, vma))
73196+ return -ENOMEM;
73197+ pol_m = vma_policy(vma_m);
73198+ mpol_get(pol_m);
73199+ vma_set_policy(vma_m, pol_m);
73200+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
73201+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
73202+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
73203+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
73204+ if (vma_m->vm_file)
73205+ get_file(vma_m->vm_file);
73206+ if (vma_m->vm_ops && vma_m->vm_ops->open)
73207+ vma_m->vm_ops->open(vma_m);
73208+ find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
73209+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
73210+ vma_m->vm_mirror = vma;
73211+ vma->vm_mirror = vma_m;
73212+ return 0;
73213+}
73214+#endif
73215+
73216 /*
73217 * Return true if the calling process may expand its vm space by the passed
73218 * number of pages
73219@@ -2449,6 +2938,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
73220
73221 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
73222
73223+#ifdef CONFIG_PAX_RANDMMAP
73224+ if (mm->pax_flags & MF_PAX_RANDMMAP)
73225+ cur -= mm->brk_gap;
73226+#endif
73227+
73228+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
73229 if (cur + npages > lim)
73230 return 0;
73231 return 1;
73232@@ -2519,6 +3014,22 @@ int install_special_mapping(struct mm_struct *mm,
73233 vma->vm_start = addr;
73234 vma->vm_end = addr + len;
73235
73236+#ifdef CONFIG_PAX_MPROTECT
73237+ if (mm->pax_flags & MF_PAX_MPROTECT) {
73238+#ifndef CONFIG_PAX_MPROTECT_COMPAT
73239+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
73240+ return -EPERM;
73241+ if (!(vm_flags & VM_EXEC))
73242+ vm_flags &= ~VM_MAYEXEC;
73243+#else
73244+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73245+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73246+#endif
73247+ else
73248+ vm_flags &= ~VM_MAYWRITE;
73249+ }
73250+#endif
73251+
73252 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
73253 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73254
73255diff --git a/mm/mprotect.c b/mm/mprotect.c
73256index a409926..8b32e6d 100644
73257--- a/mm/mprotect.c
73258+++ b/mm/mprotect.c
73259@@ -23,10 +23,17 @@
73260 #include <linux/mmu_notifier.h>
73261 #include <linux/migrate.h>
73262 #include <linux/perf_event.h>
73263+
73264+#ifdef CONFIG_PAX_MPROTECT
73265+#include <linux/elf.h>
73266+#include <linux/binfmts.h>
73267+#endif
73268+
73269 #include <asm/uaccess.h>
73270 #include <asm/pgtable.h>
73271 #include <asm/cacheflush.h>
73272 #include <asm/tlbflush.h>
73273+#include <asm/mmu_context.h>
73274
73275 #ifndef pgprot_modify
73276 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
73277@@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
73278 flush_tlb_range(vma, start, end);
73279 }
73280
73281+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73282+/* called while holding the mmap semaphor for writing except stack expansion */
73283+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
73284+{
73285+ unsigned long oldlimit, newlimit = 0UL;
73286+
73287+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
73288+ return;
73289+
73290+ spin_lock(&mm->page_table_lock);
73291+ oldlimit = mm->context.user_cs_limit;
73292+ if ((prot & VM_EXEC) && oldlimit < end)
73293+ /* USER_CS limit moved up */
73294+ newlimit = end;
73295+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
73296+ /* USER_CS limit moved down */
73297+ newlimit = start;
73298+
73299+ if (newlimit) {
73300+ mm->context.user_cs_limit = newlimit;
73301+
73302+#ifdef CONFIG_SMP
73303+ wmb();
73304+ cpus_clear(mm->context.cpu_user_cs_mask);
73305+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
73306+#endif
73307+
73308+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
73309+ }
73310+ spin_unlock(&mm->page_table_lock);
73311+ if (newlimit == end) {
73312+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
73313+
73314+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
73315+ if (is_vm_hugetlb_page(vma))
73316+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
73317+ else
73318+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
73319+ }
73320+}
73321+#endif
73322+
73323 int
73324 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73325 unsigned long start, unsigned long end, unsigned long newflags)
73326@@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73327 int error;
73328 int dirty_accountable = 0;
73329
73330+#ifdef CONFIG_PAX_SEGMEXEC
73331+ struct vm_area_struct *vma_m = NULL;
73332+ unsigned long start_m, end_m;
73333+
73334+ start_m = start + SEGMEXEC_TASK_SIZE;
73335+ end_m = end + SEGMEXEC_TASK_SIZE;
73336+#endif
73337+
73338 if (newflags == oldflags) {
73339 *pprev = vma;
73340 return 0;
73341 }
73342
73343+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
73344+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
73345+
73346+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
73347+ return -ENOMEM;
73348+
73349+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
73350+ return -ENOMEM;
73351+ }
73352+
73353 /*
73354 * If we make a private mapping writable we increase our commit;
73355 * but (without finer accounting) cannot reduce our commit if we
73356@@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73357 }
73358 }
73359
73360+#ifdef CONFIG_PAX_SEGMEXEC
73361+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
73362+ if (start != vma->vm_start) {
73363+ error = split_vma(mm, vma, start, 1);
73364+ if (error)
73365+ goto fail;
73366+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
73367+ *pprev = (*pprev)->vm_next;
73368+ }
73369+
73370+ if (end != vma->vm_end) {
73371+ error = split_vma(mm, vma, end, 0);
73372+ if (error)
73373+ goto fail;
73374+ }
73375+
73376+ if (pax_find_mirror_vma(vma)) {
73377+ error = __do_munmap(mm, start_m, end_m - start_m);
73378+ if (error)
73379+ goto fail;
73380+ } else {
73381+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73382+ if (!vma_m) {
73383+ error = -ENOMEM;
73384+ goto fail;
73385+ }
73386+ vma->vm_flags = newflags;
73387+ error = pax_mirror_vma(vma_m, vma);
73388+ if (error) {
73389+ vma->vm_flags = oldflags;
73390+ goto fail;
73391+ }
73392+ }
73393+ }
73394+#endif
73395+
73396 /*
73397 * First try to merge with previous and/or next vma.
73398 */
73399@@ -204,9 +307,21 @@ success:
73400 * vm_flags and vm_page_prot are protected by the mmap_sem
73401 * held in write mode.
73402 */
73403+
73404+#ifdef CONFIG_PAX_SEGMEXEC
73405+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
73406+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
73407+#endif
73408+
73409 vma->vm_flags = newflags;
73410+
73411+#ifdef CONFIG_PAX_MPROTECT
73412+ if (mm->binfmt && mm->binfmt->handle_mprotect)
73413+ mm->binfmt->handle_mprotect(vma, newflags);
73414+#endif
73415+
73416 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
73417- vm_get_page_prot(newflags));
73418+ vm_get_page_prot(vma->vm_flags));
73419
73420 if (vma_wants_writenotify(vma)) {
73421 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
73422@@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73423 end = start + len;
73424 if (end <= start)
73425 return -ENOMEM;
73426+
73427+#ifdef CONFIG_PAX_SEGMEXEC
73428+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
73429+ if (end > SEGMEXEC_TASK_SIZE)
73430+ return -EINVAL;
73431+ } else
73432+#endif
73433+
73434+ if (end > TASK_SIZE)
73435+ return -EINVAL;
73436+
73437 if (!arch_validate_prot(prot))
73438 return -EINVAL;
73439
73440@@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73441 /*
73442 * Does the application expect PROT_READ to imply PROT_EXEC:
73443 */
73444- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
73445+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
73446 prot |= PROT_EXEC;
73447
73448 vm_flags = calc_vm_prot_bits(prot);
73449@@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73450 if (start > vma->vm_start)
73451 prev = vma;
73452
73453+#ifdef CONFIG_PAX_MPROTECT
73454+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
73455+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
73456+#endif
73457+
73458 for (nstart = start ; ; ) {
73459 unsigned long newflags;
73460
73461@@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73462
73463 /* newflags >> 4 shift VM_MAY% in place of VM_% */
73464 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
73465+ if (prot & (PROT_WRITE | PROT_EXEC))
73466+ gr_log_rwxmprotect(vma->vm_file);
73467+
73468+ error = -EACCES;
73469+ goto out;
73470+ }
73471+
73472+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
73473 error = -EACCES;
73474 goto out;
73475 }
73476@@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73477 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
73478 if (error)
73479 goto out;
73480+
73481+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
73482+
73483 nstart = tmp;
73484
73485 if (nstart < prev->vm_end)
73486diff --git a/mm/mremap.c b/mm/mremap.c
73487index 21fed20..6822658 100644
73488--- a/mm/mremap.c
73489+++ b/mm/mremap.c
73490@@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
73491 continue;
73492 pte = ptep_get_and_clear(mm, old_addr, old_pte);
73493 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
73494+
73495+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73496+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
73497+ pte = pte_exprotect(pte);
73498+#endif
73499+
73500 set_pte_at(mm, new_addr, new_pte, pte);
73501 }
73502
73503@@ -299,6 +305,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
73504 if (is_vm_hugetlb_page(vma))
73505 goto Einval;
73506
73507+#ifdef CONFIG_PAX_SEGMEXEC
73508+ if (pax_find_mirror_vma(vma))
73509+ goto Einval;
73510+#endif
73511+
73512 /* We can't remap across vm area boundaries */
73513 if (old_len > vma->vm_end - addr)
73514 goto Efault;
73515@@ -355,20 +366,25 @@ static unsigned long mremap_to(unsigned long addr,
73516 unsigned long ret = -EINVAL;
73517 unsigned long charged = 0;
73518 unsigned long map_flags;
73519+ unsigned long pax_task_size = TASK_SIZE;
73520
73521 if (new_addr & ~PAGE_MASK)
73522 goto out;
73523
73524- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
73525+#ifdef CONFIG_PAX_SEGMEXEC
73526+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
73527+ pax_task_size = SEGMEXEC_TASK_SIZE;
73528+#endif
73529+
73530+ pax_task_size -= PAGE_SIZE;
73531+
73532+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
73533 goto out;
73534
73535 /* Check if the location we're moving into overlaps the
73536 * old location at all, and fail if it does.
73537 */
73538- if ((new_addr <= addr) && (new_addr+new_len) > addr)
73539- goto out;
73540-
73541- if ((addr <= new_addr) && (addr+old_len) > new_addr)
73542+ if (addr + old_len > new_addr && new_addr + new_len > addr)
73543 goto out;
73544
73545 ret = do_munmap(mm, new_addr, new_len);
73546@@ -436,6 +452,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73547 struct vm_area_struct *vma;
73548 unsigned long ret = -EINVAL;
73549 unsigned long charged = 0;
73550+ unsigned long pax_task_size = TASK_SIZE;
73551
73552 down_write(&current->mm->mmap_sem);
73553
73554@@ -456,6 +473,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73555 if (!new_len)
73556 goto out;
73557
73558+#ifdef CONFIG_PAX_SEGMEXEC
73559+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
73560+ pax_task_size = SEGMEXEC_TASK_SIZE;
73561+#endif
73562+
73563+ pax_task_size -= PAGE_SIZE;
73564+
73565+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
73566+ old_len > pax_task_size || addr > pax_task_size-old_len)
73567+ goto out;
73568+
73569 if (flags & MREMAP_FIXED) {
73570 if (flags & MREMAP_MAYMOVE)
73571 ret = mremap_to(addr, old_len, new_addr, new_len);
73572@@ -505,6 +533,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73573 addr + new_len);
73574 }
73575 ret = addr;
73576+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
73577 goto out;
73578 }
73579 }
73580@@ -528,7 +557,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73581 goto out;
73582 }
73583
73584+ map_flags = vma->vm_flags;
73585 ret = move_vma(vma, addr, old_len, new_len, new_addr);
73586+ if (!(ret & ~PAGE_MASK)) {
73587+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
73588+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
73589+ }
73590 }
73591 out:
73592 if (ret & ~PAGE_MASK)
73593diff --git a/mm/nommu.c b/mm/nommu.c
73594index d4b0c10..ed421b5 100644
73595--- a/mm/nommu.c
73596+++ b/mm/nommu.c
73597@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
73598 int sysctl_overcommit_ratio = 50; /* default is 50% */
73599 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
73600 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
73601-int heap_stack_gap = 0;
73602
73603 atomic_long_t mmap_pages_allocated;
73604
73605@@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
73606 EXPORT_SYMBOL(find_vma);
73607
73608 /*
73609- * find a VMA
73610- * - we don't extend stack VMAs under NOMMU conditions
73611- */
73612-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
73613-{
73614- return find_vma(mm, addr);
73615-}
73616-
73617-/*
73618 * expand a stack to a given address
73619 * - not supported under NOMMU conditions
73620 */
73621@@ -1551,6 +1541,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73622
73623 /* most fields are the same, copy all, and then fixup */
73624 *new = *vma;
73625+ INIT_LIST_HEAD(&new->anon_vma_chain);
73626 *region = *vma->vm_region;
73627 new->vm_region = region;
73628
73629diff --git a/mm/page_alloc.c b/mm/page_alloc.c
73630index 201b508..1fb51ca 100644
73631--- a/mm/page_alloc.c
73632+++ b/mm/page_alloc.c
73633@@ -336,7 +336,7 @@ out:
73634 * This usage means that zero-order pages may not be compound.
73635 */
73636
73637-static void free_compound_page(struct page *page)
73638+void free_compound_page(struct page *page)
73639 {
73640 __free_pages_ok(page, compound_order(page));
73641 }
73642@@ -693,6 +693,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73643 int i;
73644 int bad = 0;
73645
73646+#ifdef CONFIG_PAX_MEMORY_SANITIZE
73647+ unsigned long index = 1UL << order;
73648+#endif
73649+
73650 trace_mm_page_free(page, order);
73651 kmemcheck_free_shadow(page, order);
73652
73653@@ -708,6 +712,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73654 debug_check_no_obj_freed(page_address(page),
73655 PAGE_SIZE << order);
73656 }
73657+
73658+#ifdef CONFIG_PAX_MEMORY_SANITIZE
73659+ for (; index; --index)
73660+ sanitize_highpage(page + index - 1);
73661+#endif
73662+
73663 arch_free_page(page, order);
73664 kernel_map_pages(page, 1 << order, 0);
73665
73666@@ -849,8 +859,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
73667 arch_alloc_page(page, order);
73668 kernel_map_pages(page, 1 << order, 1);
73669
73670+#ifndef CONFIG_PAX_MEMORY_SANITIZE
73671 if (gfp_flags & __GFP_ZERO)
73672 prep_zero_page(page, order, gfp_flags);
73673+#endif
73674
73675 if (order && (gfp_flags & __GFP_COMP))
73676 prep_compound_page(page, order);
73677@@ -3579,7 +3591,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
73678 unsigned long pfn;
73679
73680 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
73681+#ifdef CONFIG_X86_32
73682+ /* boot failures in VMware 8 on 32bit vanilla since
73683+ this change */
73684+ if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
73685+#else
73686 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
73687+#endif
73688 return 1;
73689 }
73690 return 0;
73691diff --git a/mm/percpu.c b/mm/percpu.c
73692index bb4be74..a43ea85 100644
73693--- a/mm/percpu.c
73694+++ b/mm/percpu.c
73695@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
73696 static unsigned int pcpu_high_unit_cpu __read_mostly;
73697
73698 /* the address of the first chunk which starts with the kernel static area */
73699-void *pcpu_base_addr __read_mostly;
73700+void *pcpu_base_addr __read_only;
73701 EXPORT_SYMBOL_GPL(pcpu_base_addr);
73702
73703 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
73704diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
73705index 926b466..b23df53 100644
73706--- a/mm/process_vm_access.c
73707+++ b/mm/process_vm_access.c
73708@@ -13,6 +13,7 @@
73709 #include <linux/uio.h>
73710 #include <linux/sched.h>
73711 #include <linux/highmem.h>
73712+#include <linux/security.h>
73713 #include <linux/ptrace.h>
73714 #include <linux/slab.h>
73715 #include <linux/syscalls.h>
73716@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73717 size_t iov_l_curr_offset = 0;
73718 ssize_t iov_len;
73719
73720+ return -ENOSYS; // PaX: until properly audited
73721+
73722 /*
73723 * Work out how many pages of struct pages we're going to need
73724 * when eventually calling get_user_pages
73725 */
73726 for (i = 0; i < riovcnt; i++) {
73727 iov_len = rvec[i].iov_len;
73728- if (iov_len > 0) {
73729- nr_pages_iov = ((unsigned long)rvec[i].iov_base
73730- + iov_len)
73731- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
73732- / PAGE_SIZE + 1;
73733- nr_pages = max(nr_pages, nr_pages_iov);
73734- }
73735+ if (iov_len <= 0)
73736+ continue;
73737+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
73738+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
73739+ nr_pages = max(nr_pages, nr_pages_iov);
73740 }
73741
73742 if (nr_pages == 0)
73743@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73744 goto free_proc_pages;
73745 }
73746
73747+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
73748+ rc = -EPERM;
73749+ goto put_task_struct;
73750+ }
73751+
73752 mm = mm_access(task, PTRACE_MODE_ATTACH);
73753 if (!mm || IS_ERR(mm)) {
73754 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
73755diff --git a/mm/rmap.c b/mm/rmap.c
73756index 0f3b7cd..c5652b6 100644
73757--- a/mm/rmap.c
73758+++ b/mm/rmap.c
73759@@ -167,6 +167,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73760 struct anon_vma *anon_vma = vma->anon_vma;
73761 struct anon_vma_chain *avc;
73762
73763+#ifdef CONFIG_PAX_SEGMEXEC
73764+ struct anon_vma_chain *avc_m = NULL;
73765+#endif
73766+
73767 might_sleep();
73768 if (unlikely(!anon_vma)) {
73769 struct mm_struct *mm = vma->vm_mm;
73770@@ -176,6 +180,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73771 if (!avc)
73772 goto out_enomem;
73773
73774+#ifdef CONFIG_PAX_SEGMEXEC
73775+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
73776+ if (!avc_m)
73777+ goto out_enomem_free_avc;
73778+#endif
73779+
73780 anon_vma = find_mergeable_anon_vma(vma);
73781 allocated = NULL;
73782 if (!anon_vma) {
73783@@ -189,6 +199,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73784 /* page_table_lock to protect against threads */
73785 spin_lock(&mm->page_table_lock);
73786 if (likely(!vma->anon_vma)) {
73787+
73788+#ifdef CONFIG_PAX_SEGMEXEC
73789+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
73790+
73791+ if (vma_m) {
73792+ BUG_ON(vma_m->anon_vma);
73793+ vma_m->anon_vma = anon_vma;
73794+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
73795+ avc_m = NULL;
73796+ }
73797+#endif
73798+
73799 vma->anon_vma = anon_vma;
73800 anon_vma_chain_link(vma, avc, anon_vma);
73801 allocated = NULL;
73802@@ -199,12 +221,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73803
73804 if (unlikely(allocated))
73805 put_anon_vma(allocated);
73806+
73807+#ifdef CONFIG_PAX_SEGMEXEC
73808+ if (unlikely(avc_m))
73809+ anon_vma_chain_free(avc_m);
73810+#endif
73811+
73812 if (unlikely(avc))
73813 anon_vma_chain_free(avc);
73814 }
73815 return 0;
73816
73817 out_enomem_free_avc:
73818+
73819+#ifdef CONFIG_PAX_SEGMEXEC
73820+ if (avc_m)
73821+ anon_vma_chain_free(avc_m);
73822+#endif
73823+
73824 anon_vma_chain_free(avc);
73825 out_enomem:
73826 return -ENOMEM;
73827@@ -240,7 +274,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
73828 * Attach the anon_vmas from src to dst.
73829 * Returns 0 on success, -ENOMEM on failure.
73830 */
73831-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
73832+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
73833 {
73834 struct anon_vma_chain *avc, *pavc;
73835 struct anon_vma *root = NULL;
73836@@ -318,7 +352,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
73837 * the corresponding VMA in the parent process is attached to.
73838 * Returns 0 on success, non-zero on failure.
73839 */
73840-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
73841+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
73842 {
73843 struct anon_vma_chain *avc;
73844 struct anon_vma *anon_vma;
73845diff --git a/mm/shmem.c b/mm/shmem.c
73846index bd10636..5c16d49 100644
73847--- a/mm/shmem.c
73848+++ b/mm/shmem.c
73849@@ -31,7 +31,7 @@
73850 #include <linux/export.h>
73851 #include <linux/swap.h>
73852
73853-static struct vfsmount *shm_mnt;
73854+struct vfsmount *shm_mnt;
73855
73856 #ifdef CONFIG_SHMEM
73857 /*
73858@@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
73859 #define BOGO_DIRENT_SIZE 20
73860
73861 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
73862-#define SHORT_SYMLINK_LEN 128
73863+#define SHORT_SYMLINK_LEN 64
73864
73865 struct shmem_xattr {
73866 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
73867@@ -2590,8 +2590,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
73868 int err = -ENOMEM;
73869
73870 /* Round up to L1_CACHE_BYTES to resist false sharing */
73871- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
73872- L1_CACHE_BYTES), GFP_KERNEL);
73873+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
73874 if (!sbinfo)
73875 return -ENOMEM;
73876
73877diff --git a/mm/slab.c b/mm/slab.c
73878index e901a36..ca479fc 100644
73879--- a/mm/slab.c
73880+++ b/mm/slab.c
73881@@ -153,7 +153,7 @@
73882
73883 /* Legal flag mask for kmem_cache_create(). */
73884 #if DEBUG
73885-# define CREATE_MASK (SLAB_RED_ZONE | \
73886+# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
73887 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
73888 SLAB_CACHE_DMA | \
73889 SLAB_STORE_USER | \
73890@@ -161,7 +161,7 @@
73891 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73892 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
73893 #else
73894-# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
73895+# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
73896 SLAB_CACHE_DMA | \
73897 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
73898 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73899@@ -290,7 +290,7 @@ struct kmem_list3 {
73900 * Need this for bootstrapping a per node allocator.
73901 */
73902 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
73903-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
73904+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
73905 #define CACHE_CACHE 0
73906 #define SIZE_AC MAX_NUMNODES
73907 #define SIZE_L3 (2 * MAX_NUMNODES)
73908@@ -391,10 +391,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
73909 if ((x)->max_freeable < i) \
73910 (x)->max_freeable = i; \
73911 } while (0)
73912-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
73913-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
73914-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
73915-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
73916+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
73917+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
73918+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
73919+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
73920 #else
73921 #define STATS_INC_ACTIVE(x) do { } while (0)
73922 #define STATS_DEC_ACTIVE(x) do { } while (0)
73923@@ -542,7 +542,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
73924 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
73925 */
73926 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
73927- const struct slab *slab, void *obj)
73928+ const struct slab *slab, const void *obj)
73929 {
73930 u32 offset = (obj - slab->s_mem);
73931 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
73932@@ -563,12 +563,13 @@ EXPORT_SYMBOL(malloc_sizes);
73933 struct cache_names {
73934 char *name;
73935 char *name_dma;
73936+ char *name_usercopy;
73937 };
73938
73939 static struct cache_names __initdata cache_names[] = {
73940-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
73941+#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
73942 #include <linux/kmalloc_sizes.h>
73943- {NULL,}
73944+ {NULL}
73945 #undef CACHE
73946 };
73947
73948@@ -756,6 +757,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
73949 if (unlikely(gfpflags & GFP_DMA))
73950 return csizep->cs_dmacachep;
73951 #endif
73952+
73953+#ifdef CONFIG_PAX_USERCOPY_SLABS
73954+ if (unlikely(gfpflags & GFP_USERCOPY))
73955+ return csizep->cs_usercopycachep;
73956+#endif
73957+
73958 return csizep->cs_cachep;
73959 }
73960
73961@@ -1588,7 +1595,7 @@ void __init kmem_cache_init(void)
73962 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
73963 sizes[INDEX_AC].cs_size,
73964 ARCH_KMALLOC_MINALIGN,
73965- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73966+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73967 NULL);
73968
73969 if (INDEX_AC != INDEX_L3) {
73970@@ -1596,7 +1603,7 @@ void __init kmem_cache_init(void)
73971 kmem_cache_create(names[INDEX_L3].name,
73972 sizes[INDEX_L3].cs_size,
73973 ARCH_KMALLOC_MINALIGN,
73974- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73975+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73976 NULL);
73977 }
73978
73979@@ -1614,7 +1621,7 @@ void __init kmem_cache_init(void)
73980 sizes->cs_cachep = kmem_cache_create(names->name,
73981 sizes->cs_size,
73982 ARCH_KMALLOC_MINALIGN,
73983- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73984+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73985 NULL);
73986 }
73987 #ifdef CONFIG_ZONE_DMA
73988@@ -1626,6 +1633,16 @@ void __init kmem_cache_init(void)
73989 SLAB_PANIC,
73990 NULL);
73991 #endif
73992+
73993+#ifdef CONFIG_PAX_USERCOPY_SLABS
73994+ sizes->cs_usercopycachep = kmem_cache_create(
73995+ names->name_usercopy,
73996+ sizes->cs_size,
73997+ ARCH_KMALLOC_MINALIGN,
73998+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73999+ NULL);
74000+#endif
74001+
74002 sizes++;
74003 names++;
74004 }
74005@@ -4390,10 +4407,10 @@ static int s_show(struct seq_file *m, void *p)
74006 }
74007 /* cpu stats */
74008 {
74009- unsigned long allochit = atomic_read(&cachep->allochit);
74010- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
74011- unsigned long freehit = atomic_read(&cachep->freehit);
74012- unsigned long freemiss = atomic_read(&cachep->freemiss);
74013+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
74014+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
74015+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
74016+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
74017
74018 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
74019 allochit, allocmiss, freehit, freemiss);
74020@@ -4652,13 +4669,68 @@ static int __init slab_proc_init(void)
74021 {
74022 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
74023 #ifdef CONFIG_DEBUG_SLAB_LEAK
74024- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
74025+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
74026 #endif
74027 return 0;
74028 }
74029 module_init(slab_proc_init);
74030 #endif
74031
74032+bool is_usercopy_object(const void *ptr)
74033+{
74034+ struct page *page;
74035+ struct kmem_cache *cachep;
74036+
74037+ if (ZERO_OR_NULL_PTR(ptr))
74038+ return false;
74039+
74040+ if (!virt_addr_valid(ptr))
74041+ return false;
74042+
74043+ page = virt_to_head_page(ptr);
74044+
74045+ if (!PageSlab(page))
74046+ return false;
74047+
74048+ cachep = page_get_cache(page);
74049+ return cachep->flags & SLAB_USERCOPY;
74050+}
74051+
74052+#ifdef CONFIG_PAX_USERCOPY
74053+const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74054+{
74055+ struct page *page;
74056+ struct kmem_cache *cachep;
74057+ struct slab *slabp;
74058+ unsigned int objnr;
74059+ unsigned long offset;
74060+
74061+ if (ZERO_OR_NULL_PTR(ptr))
74062+ return "<null>";
74063+
74064+ if (!virt_addr_valid(ptr))
74065+ return NULL;
74066+
74067+ page = virt_to_head_page(ptr);
74068+
74069+ if (!PageSlab(page))
74070+ return NULL;
74071+
74072+ cachep = page_get_cache(page);
74073+ if (!(cachep->flags & SLAB_USERCOPY))
74074+ return cachep->name;
74075+
74076+ slabp = page_get_slab(page);
74077+ objnr = obj_to_index(cachep, slabp, ptr);
74078+ BUG_ON(objnr >= cachep->num);
74079+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
74080+ if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
74081+ return NULL;
74082+
74083+ return cachep->name;
74084+}
74085+#endif
74086+
74087 /**
74088 * ksize - get the actual amount of memory allocated for a given object
74089 * @objp: Pointer to the object
74090diff --git a/mm/slob.c b/mm/slob.c
74091index 8105be4..3c15e57 100644
74092--- a/mm/slob.c
74093+++ b/mm/slob.c
74094@@ -29,7 +29,7 @@
74095 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
74096 * alloc_pages() directly, allocating compound pages so the page order
74097 * does not have to be separately tracked, and also stores the exact
74098- * allocation size in page->private so that it can be used to accurately
74099+ * allocation size in slob_page->size so that it can be used to accurately
74100 * provide ksize(). These objects are detected in kfree() because slob_page()
74101 * is false for them.
74102 *
74103@@ -58,6 +58,7 @@
74104 */
74105
74106 #include <linux/kernel.h>
74107+#include <linux/sched.h>
74108 #include <linux/slab.h>
74109 #include <linux/mm.h>
74110 #include <linux/swap.h> /* struct reclaim_state */
74111@@ -102,7 +103,8 @@ struct slob_page {
74112 unsigned long flags; /* mandatory */
74113 atomic_t _count; /* mandatory */
74114 slobidx_t units; /* free units left in page */
74115- unsigned long pad[2];
74116+ unsigned long pad[1];
74117+ unsigned long size; /* size when >=PAGE_SIZE */
74118 slob_t *free; /* first free slob_t in page */
74119 struct list_head list; /* linked list of free pages */
74120 };
74121@@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
74122 */
74123 static inline int is_slob_page(struct slob_page *sp)
74124 {
74125- return PageSlab((struct page *)sp);
74126+ return PageSlab((struct page *)sp) && !sp->size;
74127 }
74128
74129 static inline void set_slob_page(struct slob_page *sp)
74130@@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
74131
74132 static inline struct slob_page *slob_page(const void *addr)
74133 {
74134- return (struct slob_page *)virt_to_page(addr);
74135+ return (struct slob_page *)virt_to_head_page(addr);
74136 }
74137
74138 /*
74139@@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
74140 /*
74141 * Return the size of a slob block.
74142 */
74143-static slobidx_t slob_units(slob_t *s)
74144+static slobidx_t slob_units(const slob_t *s)
74145 {
74146 if (s->units > 0)
74147 return s->units;
74148@@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
74149 /*
74150 * Return the next free slob block pointer after this one.
74151 */
74152-static slob_t *slob_next(slob_t *s)
74153+static slob_t *slob_next(const slob_t *s)
74154 {
74155 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
74156 slobidx_t next;
74157@@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
74158 /*
74159 * Returns true if s is the last free block in its page.
74160 */
74161-static int slob_last(slob_t *s)
74162+static int slob_last(const slob_t *s)
74163 {
74164 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
74165 }
74166@@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
74167 if (!page)
74168 return NULL;
74169
74170+ set_slob_page(page);
74171 return page_address(page);
74172 }
74173
74174@@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
74175 if (!b)
74176 return NULL;
74177 sp = slob_page(b);
74178- set_slob_page(sp);
74179
74180 spin_lock_irqsave(&slob_lock, flags);
74181 sp->units = SLOB_UNITS(PAGE_SIZE);
74182 sp->free = b;
74183+ sp->size = 0;
74184 INIT_LIST_HEAD(&sp->list);
74185 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
74186 set_slob_page_free(sp, slob_list);
74187@@ -476,10 +479,9 @@ out:
74188 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
74189 */
74190
74191-void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74192+static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
74193 {
74194- unsigned int *m;
74195- int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74196+ slob_t *m;
74197 void *ret;
74198
74199 gfp &= gfp_allowed_mask;
74200@@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74201
74202 if (!m)
74203 return NULL;
74204- *m = size;
74205+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
74206+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
74207+ m[0].units = size;
74208+ m[1].units = align;
74209 ret = (void *)m + align;
74210
74211 trace_kmalloc_node(_RET_IP_, ret,
74212@@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74213 gfp |= __GFP_COMP;
74214 ret = slob_new_pages(gfp, order, node);
74215 if (ret) {
74216- struct page *page;
74217- page = virt_to_page(ret);
74218- page->private = size;
74219+ struct slob_page *sp;
74220+ sp = slob_page(ret);
74221+ sp->size = size;
74222 }
74223
74224 trace_kmalloc_node(_RET_IP_, ret,
74225 size, PAGE_SIZE << order, gfp, node);
74226 }
74227
74228- kmemleak_alloc(ret, size, 1, gfp);
74229+ return ret;
74230+}
74231+
74232+void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74233+{
74234+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74235+ void *ret = __kmalloc_node_align(size, gfp, node, align);
74236+
74237+ if (!ZERO_OR_NULL_PTR(ret))
74238+ kmemleak_alloc(ret, size, 1, gfp);
74239 return ret;
74240 }
74241 EXPORT_SYMBOL(__kmalloc_node);
74242@@ -533,13 +547,83 @@ void kfree(const void *block)
74243 sp = slob_page(block);
74244 if (is_slob_page(sp)) {
74245 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74246- unsigned int *m = (unsigned int *)(block - align);
74247- slob_free(m, *m + align);
74248- } else
74249+ slob_t *m = (slob_t *)(block - align);
74250+ slob_free(m, m[0].units + align);
74251+ } else {
74252+ clear_slob_page(sp);
74253+ free_slob_page(sp);
74254+ sp->size = 0;
74255 put_page(&sp->page);
74256+ }
74257 }
74258 EXPORT_SYMBOL(kfree);
74259
74260+bool is_usercopy_object(const void *ptr)
74261+{
74262+ return false;
74263+}
74264+
74265+#ifdef CONFIG_PAX_USERCOPY
74266+const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74267+{
74268+ struct slob_page *sp;
74269+ const slob_t *free;
74270+ const void *base;
74271+ unsigned long flags;
74272+
74273+ if (ZERO_OR_NULL_PTR(ptr))
74274+ return "<null>";
74275+
74276+ if (!virt_addr_valid(ptr))
74277+ return NULL;
74278+
74279+ sp = slob_page(ptr);
74280+ if (!PageSlab((struct page *)sp))
74281+ return NULL;
74282+
74283+ if (sp->size) {
74284+ base = page_address(&sp->page);
74285+ if (base <= ptr && n <= sp->size - (ptr - base))
74286+ return NULL;
74287+ return "<slob>";
74288+ }
74289+
74290+ /* some tricky double walking to find the chunk */
74291+ spin_lock_irqsave(&slob_lock, flags);
74292+ base = (void *)((unsigned long)ptr & PAGE_MASK);
74293+ free = sp->free;
74294+
74295+ while (!slob_last(free) && (void *)free <= ptr) {
74296+ base = free + slob_units(free);
74297+ free = slob_next(free);
74298+ }
74299+
74300+ while (base < (void *)free) {
74301+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
74302+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
74303+ int offset;
74304+
74305+ if (ptr < base + align)
74306+ break;
74307+
74308+ offset = ptr - base - align;
74309+ if (offset >= m) {
74310+ base += size;
74311+ continue;
74312+ }
74313+
74314+ if (n > m - offset)
74315+ break;
74316+
74317+ spin_unlock_irqrestore(&slob_lock, flags);
74318+ return NULL;
74319+ }
74320+
74321+ spin_unlock_irqrestore(&slob_lock, flags);
74322+ return "<slob>";
74323+}
74324+#endif
74325+
74326 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
74327 size_t ksize(const void *block)
74328 {
74329@@ -552,10 +636,10 @@ size_t ksize(const void *block)
74330 sp = slob_page(block);
74331 if (is_slob_page(sp)) {
74332 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74333- unsigned int *m = (unsigned int *)(block - align);
74334- return SLOB_UNITS(*m) * SLOB_UNIT;
74335+ slob_t *m = (slob_t *)(block - align);
74336+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
74337 } else
74338- return sp->page.private;
74339+ return sp->size;
74340 }
74341 EXPORT_SYMBOL(ksize);
74342
74343@@ -571,8 +655,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74344 {
74345 struct kmem_cache *c;
74346
74347+#ifdef CONFIG_PAX_USERCOPY_SLABS
74348+ c = __kmalloc_node_align(sizeof(struct kmem_cache),
74349+ GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
74350+#else
74351 c = slob_alloc(sizeof(struct kmem_cache),
74352 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
74353+#endif
74354
74355 if (c) {
74356 c->name = name;
74357@@ -614,17 +703,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
74358
74359 lockdep_trace_alloc(flags);
74360
74361+#ifdef CONFIG_PAX_USERCOPY_SLABS
74362+ b = __kmalloc_node_align(c->size, flags, node, c->align);
74363+#else
74364 if (c->size < PAGE_SIZE) {
74365 b = slob_alloc(c->size, flags, c->align, node);
74366 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74367 SLOB_UNITS(c->size) * SLOB_UNIT,
74368 flags, node);
74369 } else {
74370+ struct slob_page *sp;
74371+
74372 b = slob_new_pages(flags, get_order(c->size), node);
74373+ sp = slob_page(b);
74374+ sp->size = c->size;
74375 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74376 PAGE_SIZE << get_order(c->size),
74377 flags, node);
74378 }
74379+#endif
74380
74381 if (c->ctor)
74382 c->ctor(b);
74383@@ -636,10 +733,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
74384
74385 static void __kmem_cache_free(void *b, int size)
74386 {
74387- if (size < PAGE_SIZE)
74388+ struct slob_page *sp = slob_page(b);
74389+
74390+ if (is_slob_page(sp))
74391 slob_free(b, size);
74392- else
74393+ else {
74394+ clear_slob_page(sp);
74395+ free_slob_page(sp);
74396+ sp->size = 0;
74397 slob_free_pages(b, get_order(size));
74398+ }
74399 }
74400
74401 static void kmem_rcu_free(struct rcu_head *head)
74402@@ -652,17 +755,31 @@ static void kmem_rcu_free(struct rcu_head *head)
74403
74404 void kmem_cache_free(struct kmem_cache *c, void *b)
74405 {
74406+ int size = c->size;
74407+
74408+#ifdef CONFIG_PAX_USERCOPY_SLABS
74409+ if (size + c->align < PAGE_SIZE) {
74410+ size += c->align;
74411+ b -= c->align;
74412+ }
74413+#endif
74414+
74415 kmemleak_free_recursive(b, c->flags);
74416 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
74417 struct slob_rcu *slob_rcu;
74418- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
74419- slob_rcu->size = c->size;
74420+ slob_rcu = b + (size - sizeof(struct slob_rcu));
74421+ slob_rcu->size = size;
74422 call_rcu(&slob_rcu->head, kmem_rcu_free);
74423 } else {
74424- __kmem_cache_free(b, c->size);
74425+ __kmem_cache_free(b, size);
74426 }
74427
74428+#ifdef CONFIG_PAX_USERCOPY_SLABS
74429+ trace_kfree(_RET_IP_, b);
74430+#else
74431 trace_kmem_cache_free(_RET_IP_, b);
74432+#endif
74433+
74434 }
74435 EXPORT_SYMBOL(kmem_cache_free);
74436
74437diff --git a/mm/slub.c b/mm/slub.c
74438index 8c691fa..ff23a85 100644
74439--- a/mm/slub.c
74440+++ b/mm/slub.c
74441@@ -209,7 +209,7 @@ struct track {
74442
74443 enum track_item { TRACK_ALLOC, TRACK_FREE };
74444
74445-#ifdef CONFIG_SYSFS
74446+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74447 static int sysfs_slab_add(struct kmem_cache *);
74448 static int sysfs_slab_alias(struct kmem_cache *, const char *);
74449 static void sysfs_slab_remove(struct kmem_cache *);
74450@@ -538,7 +538,7 @@ static void print_track(const char *s, struct track *t)
74451 if (!t->addr)
74452 return;
74453
74454- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
74455+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
74456 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
74457 #ifdef CONFIG_STACKTRACE
74458 {
74459@@ -2603,6 +2603,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
74460
74461 page = virt_to_head_page(x);
74462
74463+ BUG_ON(!PageSlab(page));
74464+
74465 slab_free(s, page, x, _RET_IP_);
74466
74467 trace_kmem_cache_free(_RET_IP_, x);
74468@@ -2636,7 +2638,7 @@ static int slub_min_objects;
74469 * Merge control. If this is set then no merging of slab caches will occur.
74470 * (Could be removed. This was introduced to pacify the merge skeptics.)
74471 */
74472-static int slub_nomerge;
74473+static int slub_nomerge = 1;
74474
74475 /*
74476 * Calculate the order of allocation given an slab object size.
74477@@ -3089,7 +3091,7 @@ static int kmem_cache_open(struct kmem_cache *s,
74478 else
74479 s->cpu_partial = 30;
74480
74481- s->refcount = 1;
74482+ atomic_set(&s->refcount, 1);
74483 #ifdef CONFIG_NUMA
74484 s->remote_node_defrag_ratio = 1000;
74485 #endif
74486@@ -3193,8 +3195,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
74487 void kmem_cache_destroy(struct kmem_cache *s)
74488 {
74489 down_write(&slub_lock);
74490- s->refcount--;
74491- if (!s->refcount) {
74492+ if (atomic_dec_and_test(&s->refcount)) {
74493 list_del(&s->list);
74494 up_write(&slub_lock);
74495 if (kmem_cache_close(s)) {
74496@@ -3223,6 +3224,10 @@ static struct kmem_cache *kmem_cache;
74497 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
74498 #endif
74499
74500+#ifdef CONFIG_PAX_USERCOPY_SLABS
74501+static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
74502+#endif
74503+
74504 static int __init setup_slub_min_order(char *str)
74505 {
74506 get_option(&str, &slub_min_order);
74507@@ -3337,6 +3342,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
74508 return kmalloc_dma_caches[index];
74509
74510 #endif
74511+
74512+#ifdef CONFIG_PAX_USERCOPY_SLABS
74513+ if (flags & SLAB_USERCOPY)
74514+ return kmalloc_usercopy_caches[index];
74515+
74516+#endif
74517+
74518 return kmalloc_caches[index];
74519 }
74520
74521@@ -3405,6 +3417,56 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
74522 EXPORT_SYMBOL(__kmalloc_node);
74523 #endif
74524
74525+bool is_usercopy_object(const void *ptr)
74526+{
74527+ struct page *page;
74528+ struct kmem_cache *s;
74529+
74530+ if (ZERO_OR_NULL_PTR(ptr))
74531+ return false;
74532+
74533+ if (!virt_addr_valid(ptr))
74534+ return false;
74535+
74536+ page = virt_to_head_page(ptr);
74537+
74538+ if (!PageSlab(page))
74539+ return false;
74540+
74541+ s = page->slab;
74542+ return s->flags & SLAB_USERCOPY;
74543+}
74544+
74545+#ifdef CONFIG_PAX_USERCOPY
74546+const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74547+{
74548+ struct page *page;
74549+ struct kmem_cache *s;
74550+ unsigned long offset;
74551+
74552+ if (ZERO_OR_NULL_PTR(ptr))
74553+ return "<null>";
74554+
74555+ if (!virt_addr_valid(ptr))
74556+ return NULL;
74557+
74558+ page = virt_to_head_page(ptr);
74559+
74560+ if (!PageSlab(page))
74561+ return NULL;
74562+
74563+ s = page->slab;
74564+ if (!(s->flags & SLAB_USERCOPY))
74565+ return s->name;
74566+
74567+ offset = (ptr - page_address(page)) % s->size;
74568+ if (offset <= s->objsize && n <= s->objsize - offset)
74569+ return NULL;
74570+
74571+ return s->name;
74572+}
74573+#endif
74574+
74575 size_t ksize(const void *object)
74576 {
74577 struct page *page;
74578@@ -3679,7 +3741,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
74579 int node;
74580
74581 list_add(&s->list, &slab_caches);
74582- s->refcount = -1;
74583+ atomic_set(&s->refcount, -1);
74584
74585 for_each_node_state(node, N_NORMAL_MEMORY) {
74586 struct kmem_cache_node *n = get_node(s, node);
74587@@ -3799,17 +3861,17 @@ void __init kmem_cache_init(void)
74588
74589 /* Caches that are not of the two-to-the-power-of size */
74590 if (KMALLOC_MIN_SIZE <= 32) {
74591- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
74592+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
74593 caches++;
74594 }
74595
74596 if (KMALLOC_MIN_SIZE <= 64) {
74597- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
74598+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
74599 caches++;
74600 }
74601
74602 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
74603- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
74604+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
74605 caches++;
74606 }
74607
74608@@ -3851,6 +3913,22 @@ void __init kmem_cache_init(void)
74609 }
74610 }
74611 #endif
74612+
74613+#ifdef CONFIG_PAX_USERCOPY_SLABS
74614+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
74615+ struct kmem_cache *s = kmalloc_caches[i];
74616+
74617+ if (s && s->size) {
74618+ char *name = kasprintf(GFP_NOWAIT,
74619+ "usercopy-kmalloc-%d", s->objsize);
74620+
74621+ BUG_ON(!name);
74622+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
74623+ s->objsize, SLAB_USERCOPY);
74624+ }
74625+ }
74626+#endif
74627+
74628 printk(KERN_INFO
74629 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
74630 " CPUs=%d, Nodes=%d\n",
74631@@ -3877,7 +3955,7 @@ static int slab_unmergeable(struct kmem_cache *s)
74632 /*
74633 * We may have set a slab to be unmergeable during bootstrap.
74634 */
74635- if (s->refcount < 0)
74636+ if (atomic_read(&s->refcount) < 0)
74637 return 1;
74638
74639 return 0;
74640@@ -3936,7 +4014,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74641 down_write(&slub_lock);
74642 s = find_mergeable(size, align, flags, name, ctor);
74643 if (s) {
74644- s->refcount++;
74645+ atomic_inc(&s->refcount);
74646 /*
74647 * Adjust the object sizes so that we clear
74648 * the complete object on kzalloc.
74649@@ -3945,7 +4023,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74650 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
74651
74652 if (sysfs_slab_alias(s, name)) {
74653- s->refcount--;
74654+ atomic_dec(&s->refcount);
74655 goto err;
74656 }
74657 up_write(&slub_lock);
74658@@ -4074,7 +4152,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
74659 }
74660 #endif
74661
74662-#ifdef CONFIG_SYSFS
74663+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74664 static int count_inuse(struct page *page)
74665 {
74666 return page->inuse;
74667@@ -4461,12 +4539,12 @@ static void resiliency_test(void)
74668 validate_slab_cache(kmalloc_caches[9]);
74669 }
74670 #else
74671-#ifdef CONFIG_SYSFS
74672+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74673 static void resiliency_test(void) {};
74674 #endif
74675 #endif
74676
74677-#ifdef CONFIG_SYSFS
74678+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74679 enum slab_stat_type {
74680 SL_ALL, /* All slabs */
74681 SL_PARTIAL, /* Only partially allocated slabs */
74682@@ -4709,7 +4787,7 @@ SLAB_ATTR_RO(ctor);
74683
74684 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
74685 {
74686- return sprintf(buf, "%d\n", s->refcount - 1);
74687+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
74688 }
74689 SLAB_ATTR_RO(aliases);
74690
74691@@ -5280,6 +5358,7 @@ static char *create_unique_id(struct kmem_cache *s)
74692 return name;
74693 }
74694
74695+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74696 static int sysfs_slab_add(struct kmem_cache *s)
74697 {
74698 int err;
74699@@ -5342,6 +5421,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
74700 kobject_del(&s->kobj);
74701 kobject_put(&s->kobj);
74702 }
74703+#endif
74704
74705 /*
74706 * Need to buffer aliases during bootup until sysfs becomes
74707@@ -5355,6 +5435,7 @@ struct saved_alias {
74708
74709 static struct saved_alias *alias_list;
74710
74711+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74712 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74713 {
74714 struct saved_alias *al;
74715@@ -5377,6 +5458,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74716 alias_list = al;
74717 return 0;
74718 }
74719+#endif
74720
74721 static int __init slab_sysfs_init(void)
74722 {
74723diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
74724index 1b7e22a..3fcd4f3 100644
74725--- a/mm/sparse-vmemmap.c
74726+++ b/mm/sparse-vmemmap.c
74727@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
74728 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
74729 if (!p)
74730 return NULL;
74731- pud_populate(&init_mm, pud, p);
74732+ pud_populate_kernel(&init_mm, pud, p);
74733 }
74734 return pud;
74735 }
74736@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
74737 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
74738 if (!p)
74739 return NULL;
74740- pgd_populate(&init_mm, pgd, p);
74741+ pgd_populate_kernel(&init_mm, pgd, p);
74742 }
74743 return pgd;
74744 }
74745diff --git a/mm/swap.c b/mm/swap.c
74746index 4e7e2ec..0c57830 100644
74747--- a/mm/swap.c
74748+++ b/mm/swap.c
74749@@ -30,6 +30,7 @@
74750 #include <linux/backing-dev.h>
74751 #include <linux/memcontrol.h>
74752 #include <linux/gfp.h>
74753+#include <linux/hugetlb.h>
74754
74755 #include "internal.h"
74756
74757@@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
74758
74759 __page_cache_release(page);
74760 dtor = get_compound_page_dtor(page);
74761+ if (!PageHuge(page))
74762+ BUG_ON(dtor != free_compound_page);
74763 (*dtor)(page);
74764 }
74765
74766diff --git a/mm/swapfile.c b/mm/swapfile.c
74767index 71373d0..11fa7d9 100644
74768--- a/mm/swapfile.c
74769+++ b/mm/swapfile.c
74770@@ -63,7 +63,7 @@ static DEFINE_MUTEX(swapon_mutex);
74771
74772 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
74773 /* Activity counter to indicate that a swapon or swapoff has occurred */
74774-static atomic_t proc_poll_event = ATOMIC_INIT(0);
74775+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
74776
74777 static inline unsigned char swap_count(unsigned char ent)
74778 {
74779@@ -1663,7 +1663,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
74780 }
74781 filp_close(swap_file, NULL);
74782 err = 0;
74783- atomic_inc(&proc_poll_event);
74784+ atomic_inc_unchecked(&proc_poll_event);
74785 wake_up_interruptible(&proc_poll_wait);
74786
74787 out_dput:
74788@@ -1679,8 +1679,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
74789
74790 poll_wait(file, &proc_poll_wait, wait);
74791
74792- if (seq->poll_event != atomic_read(&proc_poll_event)) {
74793- seq->poll_event = atomic_read(&proc_poll_event);
74794+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
74795+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74796 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
74797 }
74798
74799@@ -1778,7 +1778,7 @@ static int swaps_open(struct inode *inode, struct file *file)
74800 return ret;
74801
74802 seq = file->private_data;
74803- seq->poll_event = atomic_read(&proc_poll_event);
74804+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74805 return 0;
74806 }
74807
74808@@ -2120,7 +2120,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
74809 (frontswap_map) ? "FS" : "");
74810
74811 mutex_unlock(&swapon_mutex);
74812- atomic_inc(&proc_poll_event);
74813+ atomic_inc_unchecked(&proc_poll_event);
74814 wake_up_interruptible(&proc_poll_wait);
74815
74816 if (S_ISREG(inode->i_mode))
74817diff --git a/mm/util.c b/mm/util.c
74818index 8c7265a..c96d884 100644
74819--- a/mm/util.c
74820+++ b/mm/util.c
74821@@ -285,6 +285,12 @@ done:
74822 void arch_pick_mmap_layout(struct mm_struct *mm)
74823 {
74824 mm->mmap_base = TASK_UNMAPPED_BASE;
74825+
74826+#ifdef CONFIG_PAX_RANDMMAP
74827+ if (mm->pax_flags & MF_PAX_RANDMMAP)
74828+ mm->mmap_base += mm->delta_mmap;
74829+#endif
74830+
74831 mm->get_unmapped_area = arch_get_unmapped_area;
74832 mm->unmap_area = arch_unmap_area;
74833 }
74834diff --git a/mm/vmalloc.c b/mm/vmalloc.c
74835index 2aad499..4006a74 100644
74836--- a/mm/vmalloc.c
74837+++ b/mm/vmalloc.c
74838@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
74839
74840 pte = pte_offset_kernel(pmd, addr);
74841 do {
74842- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74843- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74844+
74845+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74846+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
74847+ BUG_ON(!pte_exec(*pte));
74848+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
74849+ continue;
74850+ }
74851+#endif
74852+
74853+ {
74854+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74855+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74856+ }
74857 } while (pte++, addr += PAGE_SIZE, addr != end);
74858 }
74859
74860@@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74861 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
74862 {
74863 pte_t *pte;
74864+ int ret = -ENOMEM;
74865
74866 /*
74867 * nr is a running index into the array which helps higher level
74868@@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74869 pte = pte_alloc_kernel(pmd, addr);
74870 if (!pte)
74871 return -ENOMEM;
74872+
74873+ pax_open_kernel();
74874 do {
74875 struct page *page = pages[*nr];
74876
74877- if (WARN_ON(!pte_none(*pte)))
74878- return -EBUSY;
74879- if (WARN_ON(!page))
74880- return -ENOMEM;
74881+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74882+ if (pgprot_val(prot) & _PAGE_NX)
74883+#endif
74884+
74885+ if (WARN_ON(!pte_none(*pte))) {
74886+ ret = -EBUSY;
74887+ goto out;
74888+ }
74889+ if (WARN_ON(!page)) {
74890+ ret = -ENOMEM;
74891+ goto out;
74892+ }
74893 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
74894 (*nr)++;
74895 } while (pte++, addr += PAGE_SIZE, addr != end);
74896- return 0;
74897+ ret = 0;
74898+out:
74899+ pax_close_kernel();
74900+ return ret;
74901 }
74902
74903 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
74904@@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
74905 pmd_t *pmd;
74906 unsigned long next;
74907
74908- pmd = pmd_alloc(&init_mm, pud, addr);
74909+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
74910 if (!pmd)
74911 return -ENOMEM;
74912 do {
74913@@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
74914 pud_t *pud;
74915 unsigned long next;
74916
74917- pud = pud_alloc(&init_mm, pgd, addr);
74918+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
74919 if (!pud)
74920 return -ENOMEM;
74921 do {
74922@@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
74923 * and fall back on vmalloc() if that fails. Others
74924 * just put it in the vmalloc space.
74925 */
74926-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
74927+#ifdef CONFIG_MODULES
74928+#ifdef MODULES_VADDR
74929 unsigned long addr = (unsigned long)x;
74930 if (addr >= MODULES_VADDR && addr < MODULES_END)
74931 return 1;
74932 #endif
74933+
74934+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74935+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
74936+ return 1;
74937+#endif
74938+
74939+#endif
74940+
74941 return is_vmalloc_addr(x);
74942 }
74943
74944@@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
74945
74946 if (!pgd_none(*pgd)) {
74947 pud_t *pud = pud_offset(pgd, addr);
74948+#ifdef CONFIG_X86
74949+ if (!pud_large(*pud))
74950+#endif
74951 if (!pud_none(*pud)) {
74952 pmd_t *pmd = pmd_offset(pud, addr);
74953+#ifdef CONFIG_X86
74954+ if (!pmd_large(*pmd))
74955+#endif
74956 if (!pmd_none(*pmd)) {
74957 pte_t *ptep, pte;
74958
74959@@ -329,7 +369,7 @@ static void purge_vmap_area_lazy(void);
74960 * Allocate a region of KVA of the specified size and alignment, within the
74961 * vstart and vend.
74962 */
74963-static struct vmap_area *alloc_vmap_area(unsigned long size,
74964+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
74965 unsigned long align,
74966 unsigned long vstart, unsigned long vend,
74967 int node, gfp_t gfp_mask)
74968@@ -1320,6 +1360,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
74969 struct vm_struct *area;
74970
74971 BUG_ON(in_interrupt());
74972+
74973+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74974+ if (flags & VM_KERNEXEC) {
74975+ if (start != VMALLOC_START || end != VMALLOC_END)
74976+ return NULL;
74977+ start = (unsigned long)MODULES_EXEC_VADDR;
74978+ end = (unsigned long)MODULES_EXEC_END;
74979+ }
74980+#endif
74981+
74982 if (flags & VM_IOREMAP) {
74983 int bit = fls(size);
74984
74985@@ -1552,6 +1602,11 @@ void *vmap(struct page **pages, unsigned int count,
74986 if (count > totalram_pages)
74987 return NULL;
74988
74989+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74990+ if (!(pgprot_val(prot) & _PAGE_NX))
74991+ flags |= VM_KERNEXEC;
74992+#endif
74993+
74994 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
74995 __builtin_return_address(0));
74996 if (!area)
74997@@ -1653,6 +1708,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
74998 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
74999 goto fail;
75000
75001+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75002+ if (!(pgprot_val(prot) & _PAGE_NX))
75003+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
75004+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
75005+ else
75006+#endif
75007+
75008 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
75009 start, end, node, gfp_mask, caller);
75010 if (!area)
75011@@ -1826,10 +1888,9 @@ EXPORT_SYMBOL(vzalloc_node);
75012 * For tight control over page level allocator and protection flags
75013 * use __vmalloc() instead.
75014 */
75015-
75016 void *vmalloc_exec(unsigned long size)
75017 {
75018- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
75019+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
75020 -1, __builtin_return_address(0));
75021 }
75022
75023@@ -2124,6 +2185,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
75024 unsigned long uaddr = vma->vm_start;
75025 unsigned long usize = vma->vm_end - vma->vm_start;
75026
75027+ BUG_ON(vma->vm_mirror);
75028+
75029 if ((PAGE_SIZE-1) & (unsigned long)addr)
75030 return -EINVAL;
75031
75032diff --git a/mm/vmstat.c b/mm/vmstat.c
75033index 1bbbbd9..ff35669 100644
75034--- a/mm/vmstat.c
75035+++ b/mm/vmstat.c
75036@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
75037 *
75038 * vm_stat contains the global counters
75039 */
75040-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75041+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75042 EXPORT_SYMBOL(vm_stat);
75043
75044 #ifdef CONFIG_SMP
75045@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
75046 v = p->vm_stat_diff[i];
75047 p->vm_stat_diff[i] = 0;
75048 local_irq_restore(flags);
75049- atomic_long_add(v, &zone->vm_stat[i]);
75050+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
75051 global_diff[i] += v;
75052 #ifdef CONFIG_NUMA
75053 /* 3 seconds idle till flush */
75054@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
75055
75056 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
75057 if (global_diff[i])
75058- atomic_long_add(global_diff[i], &vm_stat[i]);
75059+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
75060 }
75061
75062 #endif
75063@@ -1211,10 +1211,20 @@ static int __init setup_vmstat(void)
75064 start_cpu_timer(cpu);
75065 #endif
75066 #ifdef CONFIG_PROC_FS
75067- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
75068- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
75069- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
75070- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
75071+ {
75072+ mode_t gr_mode = S_IRUGO;
75073+#ifdef CONFIG_GRKERNSEC_PROC_ADD
75074+ gr_mode = S_IRUSR;
75075+#endif
75076+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
75077+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
75078+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
75079+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
75080+#else
75081+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
75082+#endif
75083+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
75084+ }
75085 #endif
75086 return 0;
75087 }
75088diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
75089index 9096bcb..43ed7bb 100644
75090--- a/net/8021q/vlan.c
75091+++ b/net/8021q/vlan.c
75092@@ -557,8 +557,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
75093 err = -EPERM;
75094 if (!capable(CAP_NET_ADMIN))
75095 break;
75096- if ((args.u.name_type >= 0) &&
75097- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
75098+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
75099 struct vlan_net *vn;
75100
75101 vn = net_generic(net, vlan_net_id);
75102diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
75103index 6449bae..8c1f454 100644
75104--- a/net/9p/trans_fd.c
75105+++ b/net/9p/trans_fd.c
75106@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
75107 oldfs = get_fs();
75108 set_fs(get_ds());
75109 /* The cast to a user pointer is valid due to the set_fs() */
75110- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
75111+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
75112 set_fs(oldfs);
75113
75114 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
75115diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
75116index 876fbe8..8bbea9f 100644
75117--- a/net/atm/atm_misc.c
75118+++ b/net/atm/atm_misc.c
75119@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
75120 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
75121 return 1;
75122 atm_return(vcc, truesize);
75123- atomic_inc(&vcc->stats->rx_drop);
75124+ atomic_inc_unchecked(&vcc->stats->rx_drop);
75125 return 0;
75126 }
75127 EXPORT_SYMBOL(atm_charge);
75128@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
75129 }
75130 }
75131 atm_return(vcc, guess);
75132- atomic_inc(&vcc->stats->rx_drop);
75133+ atomic_inc_unchecked(&vcc->stats->rx_drop);
75134 return NULL;
75135 }
75136 EXPORT_SYMBOL(atm_alloc_charge);
75137@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
75138
75139 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75140 {
75141-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75142+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75143 __SONET_ITEMS
75144 #undef __HANDLE_ITEM
75145 }
75146@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
75147
75148 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75149 {
75150-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75151+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
75152 __SONET_ITEMS
75153 #undef __HANDLE_ITEM
75154 }
75155diff --git a/net/atm/common.c b/net/atm/common.c
75156index b4b44db..0c0ad93 100644
75157--- a/net/atm/common.c
75158+++ b/net/atm/common.c
75159@@ -812,6 +812,7 @@ int vcc_getsockopt(struct socket *sock, int level, int optname,
75160
75161 if (!vcc->dev || !test_bit(ATM_VF_ADDR, &vcc->flags))
75162 return -ENOTCONN;
75163+ memset(&pvc, 0, sizeof(pvc));
75164 pvc.sap_family = AF_ATMPVC;
75165 pvc.sap_addr.itf = vcc->dev->number;
75166 pvc.sap_addr.vpi = vcc->vpi;
75167diff --git a/net/atm/lec.h b/net/atm/lec.h
75168index a86aff9..3a0d6f6 100644
75169--- a/net/atm/lec.h
75170+++ b/net/atm/lec.h
75171@@ -48,7 +48,7 @@ struct lane2_ops {
75172 const u8 *tlvs, u32 sizeoftlvs);
75173 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
75174 const u8 *tlvs, u32 sizeoftlvs);
75175-};
75176+} __no_const;
75177
75178 /*
75179 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
75180diff --git a/net/atm/mpc.h b/net/atm/mpc.h
75181index 0919a88..a23d54e 100644
75182--- a/net/atm/mpc.h
75183+++ b/net/atm/mpc.h
75184@@ -33,7 +33,7 @@ struct mpoa_client {
75185 struct mpc_parameters parameters; /* parameters for this client */
75186
75187 const struct net_device_ops *old_ops;
75188- struct net_device_ops new_ops;
75189+ net_device_ops_no_const new_ops;
75190 };
75191
75192
75193diff --git a/net/atm/proc.c b/net/atm/proc.c
75194index 0d020de..011c7bb 100644
75195--- a/net/atm/proc.c
75196+++ b/net/atm/proc.c
75197@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
75198 const struct k_atm_aal_stats *stats)
75199 {
75200 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
75201- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
75202- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
75203- atomic_read(&stats->rx_drop));
75204+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
75205+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
75206+ atomic_read_unchecked(&stats->rx_drop));
75207 }
75208
75209 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
75210diff --git a/net/atm/pvc.c b/net/atm/pvc.c
75211index 3a73491..ae03240 100644
75212--- a/net/atm/pvc.c
75213+++ b/net/atm/pvc.c
75214@@ -95,6 +95,7 @@ static int pvc_getname(struct socket *sock, struct sockaddr *sockaddr,
75215 return -ENOTCONN;
75216 *sockaddr_len = sizeof(struct sockaddr_atmpvc);
75217 addr = (struct sockaddr_atmpvc *)sockaddr;
75218+ memset(addr, 0, sizeof(*addr));
75219 addr->sap_family = AF_ATMPVC;
75220 addr->sap_addr.itf = vcc->dev->number;
75221 addr->sap_addr.vpi = vcc->vpi;
75222diff --git a/net/atm/resources.c b/net/atm/resources.c
75223index 23f45ce..c748f1a 100644
75224--- a/net/atm/resources.c
75225+++ b/net/atm/resources.c
75226@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
75227 static void copy_aal_stats(struct k_atm_aal_stats *from,
75228 struct atm_aal_stats *to)
75229 {
75230-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75231+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75232 __AAL_STAT_ITEMS
75233 #undef __HANDLE_ITEM
75234 }
75235@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
75236 static void subtract_aal_stats(struct k_atm_aal_stats *from,
75237 struct atm_aal_stats *to)
75238 {
75239-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75240+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
75241 __AAL_STAT_ITEMS
75242 #undef __HANDLE_ITEM
75243 }
75244diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
75245index dc53798..dc66333 100644
75246--- a/net/batman-adv/bat_iv_ogm.c
75247+++ b/net/batman-adv/bat_iv_ogm.c
75248@@ -63,7 +63,7 @@ static int bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
75249
75250 /* randomize initial seqno to avoid collision */
75251 get_random_bytes(&random_seqno, sizeof(random_seqno));
75252- atomic_set(&hard_iface->seqno, random_seqno);
75253+ atomic_set_unchecked(&hard_iface->seqno, random_seqno);
75254
75255 hard_iface->packet_len = BATMAN_OGM_HLEN;
75256 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
75257@@ -572,7 +572,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
75258
75259 /* change sequence number to network order */
75260 batman_ogm_packet->seqno =
75261- htonl((uint32_t)atomic_read(&hard_iface->seqno));
75262+ htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
75263
75264 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
75265 batman_ogm_packet->tt_crc = htons((uint16_t)
75266@@ -592,7 +592,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
75267 else
75268 batman_ogm_packet->gw_flags = NO_FLAGS;
75269
75270- atomic_inc(&hard_iface->seqno);
75271+ atomic_inc_unchecked(&hard_iface->seqno);
75272
75273 slide_own_bcast_window(hard_iface);
75274 bat_iv_ogm_queue_add(bat_priv, hard_iface->packet_buff,
75275@@ -956,7 +956,7 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
75276 return;
75277
75278 /* could be changed by schedule_own_packet() */
75279- if_incoming_seqno = atomic_read(&if_incoming->seqno);
75280+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
75281
75282 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
75283
75284diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
75285index dc334fa..766a01a 100644
75286--- a/net/batman-adv/hard-interface.c
75287+++ b/net/batman-adv/hard-interface.c
75288@@ -321,7 +321,7 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
75289 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
75290 dev_add_pack(&hard_iface->batman_adv_ptype);
75291
75292- atomic_set(&hard_iface->frag_seqno, 1);
75293+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
75294 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
75295 hard_iface->net_dev->name);
75296
75297@@ -444,7 +444,7 @@ static struct hard_iface *hardif_add_interface(struct net_device *net_dev)
75298 * This can't be called via a bat_priv callback because
75299 * we have no bat_priv yet.
75300 */
75301- atomic_set(&hard_iface->seqno, 1);
75302+ atomic_set_unchecked(&hard_iface->seqno, 1);
75303 hard_iface->packet_buff = NULL;
75304
75305 return hard_iface;
75306diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
75307index a0ec0e4..7beb587 100644
75308--- a/net/batman-adv/soft-interface.c
75309+++ b/net/batman-adv/soft-interface.c
75310@@ -214,7 +214,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
75311
75312 /* set broadcast sequence number */
75313 bcast_packet->seqno =
75314- htonl(atomic_inc_return(&bat_priv->bcast_seqno));
75315+ htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
75316
75317 add_bcast_packet_to_list(bat_priv, skb, 1);
75318
75319@@ -390,7 +390,7 @@ struct net_device *softif_create(const char *name)
75320 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
75321
75322 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
75323- atomic_set(&bat_priv->bcast_seqno, 1);
75324+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
75325 atomic_set(&bat_priv->ttvn, 0);
75326 atomic_set(&bat_priv->tt_local_changes, 0);
75327 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
75328diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
75329index 61308e8..2e142b2 100644
75330--- a/net/batman-adv/types.h
75331+++ b/net/batman-adv/types.h
75332@@ -38,8 +38,8 @@ struct hard_iface {
75333 int16_t if_num;
75334 char if_status;
75335 struct net_device *net_dev;
75336- atomic_t seqno;
75337- atomic_t frag_seqno;
75338+ atomic_unchecked_t seqno;
75339+ atomic_unchecked_t frag_seqno;
75340 unsigned char *packet_buff;
75341 int packet_len;
75342 struct kobject *hardif_obj;
75343@@ -163,7 +163,7 @@ struct bat_priv {
75344 atomic_t orig_interval; /* uint */
75345 atomic_t hop_penalty; /* uint */
75346 atomic_t log_level; /* uint */
75347- atomic_t bcast_seqno;
75348+ atomic_unchecked_t bcast_seqno;
75349 atomic_t bcast_queue_left;
75350 atomic_t batman_queue_left;
75351 atomic_t ttvn; /* translation table version number */
75352diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
75353index 74175c2..32f8901 100644
75354--- a/net/batman-adv/unicast.c
75355+++ b/net/batman-adv/unicast.c
75356@@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
75357 frag1->flags = UNI_FRAG_HEAD | large_tail;
75358 frag2->flags = large_tail;
75359
75360- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
75361+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
75362 frag1->seqno = htons(seqno - 1);
75363 frag2->seqno = htons(seqno);
75364
75365diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
75366index 5914623..bedc768 100644
75367--- a/net/bluetooth/hci_sock.c
75368+++ b/net/bluetooth/hci_sock.c
75369@@ -706,6 +706,7 @@ static int hci_sock_getname(struct socket *sock, struct sockaddr *addr, int *add
75370 *addr_len = sizeof(*haddr);
75371 haddr->hci_family = AF_BLUETOOTH;
75372 haddr->hci_dev = hdev->id;
75373+ haddr->hci_channel= 0;
75374
75375 release_sock(sk);
75376 return 0;
75377@@ -1016,6 +1017,7 @@ static int hci_sock_getsockopt(struct socket *sock, int level, int optname, char
75378 {
75379 struct hci_filter *f = &hci_pi(sk)->filter;
75380
75381+ memset(&uf, 0, sizeof(uf));
75382 uf.type_mask = f->type_mask;
75383 uf.opcode = f->opcode;
75384 uf.event_mask[0] = *((u32 *) f->event_mask + 0);
75385diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
75386index 4554e80..b778671 100644
75387--- a/net/bluetooth/l2cap_core.c
75388+++ b/net/bluetooth/l2cap_core.c
75389@@ -2798,8 +2798,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
75390 break;
75391
75392 case L2CAP_CONF_RFC:
75393- if (olen == sizeof(rfc))
75394- memcpy(&rfc, (void *)val, olen);
75395+ if (olen != sizeof(rfc))
75396+ break;
75397+
75398+ memcpy(&rfc, (void *)val, olen);
75399
75400 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
75401 rfc.mode != chan->mode)
75402diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
75403index 3bb1611..fcf656b 100644
75404--- a/net/bluetooth/l2cap_sock.c
75405+++ b/net/bluetooth/l2cap_sock.c
75406@@ -246,6 +246,7 @@ static int l2cap_sock_getname(struct socket *sock, struct sockaddr *addr, int *l
75407
75408 BT_DBG("sock %p, sk %p", sock, sk);
75409
75410+ memset(la, 0, sizeof(struct sockaddr_l2));
75411 addr->sa_family = AF_BLUETOOTH;
75412 *len = sizeof(struct sockaddr_l2);
75413
75414diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
75415index e8707de..2df6956 100644
75416--- a/net/bluetooth/rfcomm/sock.c
75417+++ b/net/bluetooth/rfcomm/sock.c
75418@@ -547,6 +547,7 @@ static int rfcomm_sock_getname(struct socket *sock, struct sockaddr *addr, int *
75419
75420 BT_DBG("sock %p, sk %p", sock, sk);
75421
75422+ memset(sa, 0, sizeof(*sa));
75423 sa->rc_family = AF_BLUETOOTH;
75424 sa->rc_channel = rfcomm_pi(sk)->channel;
75425 if (peer)
75426@@ -841,6 +842,7 @@ static int rfcomm_sock_getsockopt(struct socket *sock, int level, int optname, c
75427 }
75428
75429 sec.level = rfcomm_pi(sk)->sec_level;
75430+ sec.key_size = 0;
75431
75432 len = min_t(unsigned int, len, sizeof(sec));
75433 if (copy_to_user(optval, (char *) &sec, len))
75434diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
75435index d1820ff..4f8c8f6 100644
75436--- a/net/bluetooth/rfcomm/tty.c
75437+++ b/net/bluetooth/rfcomm/tty.c
75438@@ -314,7 +314,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
75439 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
75440
75441 spin_lock_irqsave(&dev->port.lock, flags);
75442- if (dev->port.count > 0) {
75443+ if (atomic_read(&dev->port.count) > 0) {
75444 spin_unlock_irqrestore(&dev->port.lock, flags);
75445 return;
75446 }
75447@@ -461,7 +461,7 @@ static int rfcomm_get_dev_list(void __user *arg)
75448
75449 size = sizeof(*dl) + dev_num * sizeof(*di);
75450
75451- dl = kmalloc(size, GFP_KERNEL);
75452+ dl = kzalloc(size, GFP_KERNEL);
75453 if (!dl)
75454 return -ENOMEM;
75455
75456@@ -669,10 +669,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
75457 return -ENODEV;
75458
75459 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
75460- dev->channel, dev->port.count);
75461+ dev->channel, atomic_read(&dev->port.count));
75462
75463 spin_lock_irqsave(&dev->port.lock, flags);
75464- if (++dev->port.count > 1) {
75465+ if (atomic_inc_return(&dev->port.count) > 1) {
75466 spin_unlock_irqrestore(&dev->port.lock, flags);
75467 return 0;
75468 }
75469@@ -737,10 +737,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
75470 return;
75471
75472 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
75473- dev->port.count);
75474+ atomic_read(&dev->port.count));
75475
75476 spin_lock_irqsave(&dev->port.lock, flags);
75477- if (!--dev->port.count) {
75478+ if (!atomic_dec_return(&dev->port.count)) {
75479 spin_unlock_irqrestore(&dev->port.lock, flags);
75480 if (dev->tty_dev->parent)
75481 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
75482diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
75483index 5fe2ff3..10968b5 100644
75484--- a/net/bridge/netfilter/ebtables.c
75485+++ b/net/bridge/netfilter/ebtables.c
75486@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
75487 tmp.valid_hooks = t->table->valid_hooks;
75488 }
75489 mutex_unlock(&ebt_mutex);
75490- if (copy_to_user(user, &tmp, *len) != 0){
75491+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
75492 BUGPRINT("c2u Didn't work\n");
75493 ret = -EFAULT;
75494 break;
75495diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
75496index 047cd0e..461fd28 100644
75497--- a/net/caif/cfctrl.c
75498+++ b/net/caif/cfctrl.c
75499@@ -10,6 +10,7 @@
75500 #include <linux/spinlock.h>
75501 #include <linux/slab.h>
75502 #include <linux/pkt_sched.h>
75503+#include <linux/sched.h>
75504 #include <net/caif/caif_layer.h>
75505 #include <net/caif/cfpkt.h>
75506 #include <net/caif/cfctrl.h>
75507@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
75508 memset(&dev_info, 0, sizeof(dev_info));
75509 dev_info.id = 0xff;
75510 cfsrvl_init(&this->serv, 0, &dev_info, false);
75511- atomic_set(&this->req_seq_no, 1);
75512- atomic_set(&this->rsp_seq_no, 1);
75513+ atomic_set_unchecked(&this->req_seq_no, 1);
75514+ atomic_set_unchecked(&this->rsp_seq_no, 1);
75515 this->serv.layer.receive = cfctrl_recv;
75516 sprintf(this->serv.layer.name, "ctrl");
75517 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
75518@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
75519 struct cfctrl_request_info *req)
75520 {
75521 spin_lock_bh(&ctrl->info_list_lock);
75522- atomic_inc(&ctrl->req_seq_no);
75523- req->sequence_no = atomic_read(&ctrl->req_seq_no);
75524+ atomic_inc_unchecked(&ctrl->req_seq_no);
75525+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
75526 list_add_tail(&req->list, &ctrl->list);
75527 spin_unlock_bh(&ctrl->info_list_lock);
75528 }
75529@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
75530 if (p != first)
75531 pr_warn("Requests are not received in order\n");
75532
75533- atomic_set(&ctrl->rsp_seq_no,
75534+ atomic_set_unchecked(&ctrl->rsp_seq_no,
75535 p->sequence_no);
75536 list_del(&p->list);
75537 goto out;
75538diff --git a/net/caif/chnl_net.c b/net/caif/chnl_net.c
75539index 69771c0..e597733 100644
75540--- a/net/caif/chnl_net.c
75541+++ b/net/caif/chnl_net.c
75542@@ -94,6 +94,10 @@ static int chnl_recv_cb(struct cflayer *layr, struct cfpkt *pkt)
75543
75544 /* check the version of IP */
75545 ip_version = skb_header_pointer(skb, 0, 1, &buf);
75546+ if (!ip_version) {
75547+ kfree_skb(skb);
75548+ return -EINVAL;
75549+ }
75550
75551 switch (*ip_version >> 4) {
75552 case 4:
75553diff --git a/net/can/gw.c b/net/can/gw.c
75554index b41acf2..3affb3a 100644
75555--- a/net/can/gw.c
75556+++ b/net/can/gw.c
75557@@ -96,7 +96,7 @@ struct cf_mod {
75558 struct {
75559 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
75560 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
75561- } csumfunc;
75562+ } __no_const csumfunc;
75563 };
75564
75565
75566diff --git a/net/compat.c b/net/compat.c
75567index 74ed1d7..62f7ea6 100644
75568--- a/net/compat.c
75569+++ b/net/compat.c
75570@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
75571 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
75572 __get_user(kmsg->msg_flags, &umsg->msg_flags))
75573 return -EFAULT;
75574- kmsg->msg_name = compat_ptr(tmp1);
75575- kmsg->msg_iov = compat_ptr(tmp2);
75576- kmsg->msg_control = compat_ptr(tmp3);
75577+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
75578+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
75579+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
75580 return 0;
75581 }
75582
75583@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75584
75585 if (kern_msg->msg_namelen) {
75586 if (mode == VERIFY_READ) {
75587- int err = move_addr_to_kernel(kern_msg->msg_name,
75588+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
75589 kern_msg->msg_namelen,
75590 kern_address);
75591 if (err < 0)
75592@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75593 kern_msg->msg_name = NULL;
75594
75595 tot_len = iov_from_user_compat_to_kern(kern_iov,
75596- (struct compat_iovec __user *)kern_msg->msg_iov,
75597+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
75598 kern_msg->msg_iovlen);
75599 if (tot_len >= 0)
75600 kern_msg->msg_iov = kern_iov;
75601@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75602
75603 #define CMSG_COMPAT_FIRSTHDR(msg) \
75604 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
75605- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
75606+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
75607 (struct compat_cmsghdr __user *)NULL)
75608
75609 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
75610 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
75611 (ucmlen) <= (unsigned long) \
75612 ((mhdr)->msg_controllen - \
75613- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
75614+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
75615
75616 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
75617 struct compat_cmsghdr __user *cmsg, int cmsg_len)
75618 {
75619 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
75620- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
75621+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
75622 msg->msg_controllen)
75623 return NULL;
75624 return (struct compat_cmsghdr __user *)ptr;
75625@@ -219,7 +219,7 @@ Efault:
75626
75627 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
75628 {
75629- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
75630+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
75631 struct compat_cmsghdr cmhdr;
75632 struct compat_timeval ctv;
75633 struct compat_timespec cts[3];
75634@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
75635
75636 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
75637 {
75638- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
75639+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
75640 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
75641 int fdnum = scm->fp->count;
75642 struct file **fp = scm->fp->fp;
75643@@ -364,7 +364,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
75644 return -EFAULT;
75645 old_fs = get_fs();
75646 set_fs(KERNEL_DS);
75647- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
75648+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
75649 set_fs(old_fs);
75650
75651 return err;
75652@@ -425,7 +425,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
75653 len = sizeof(ktime);
75654 old_fs = get_fs();
75655 set_fs(KERNEL_DS);
75656- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
75657+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
75658 set_fs(old_fs);
75659
75660 if (!err) {
75661@@ -568,7 +568,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75662 case MCAST_JOIN_GROUP:
75663 case MCAST_LEAVE_GROUP:
75664 {
75665- struct compat_group_req __user *gr32 = (void *)optval;
75666+ struct compat_group_req __user *gr32 = (void __user *)optval;
75667 struct group_req __user *kgr =
75668 compat_alloc_user_space(sizeof(struct group_req));
75669 u32 interface;
75670@@ -589,7 +589,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75671 case MCAST_BLOCK_SOURCE:
75672 case MCAST_UNBLOCK_SOURCE:
75673 {
75674- struct compat_group_source_req __user *gsr32 = (void *)optval;
75675+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
75676 struct group_source_req __user *kgsr = compat_alloc_user_space(
75677 sizeof(struct group_source_req));
75678 u32 interface;
75679@@ -610,7 +610,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75680 }
75681 case MCAST_MSFILTER:
75682 {
75683- struct compat_group_filter __user *gf32 = (void *)optval;
75684+ struct compat_group_filter __user *gf32 = (void __user *)optval;
75685 struct group_filter __user *kgf;
75686 u32 interface, fmode, numsrc;
75687
75688@@ -648,7 +648,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
75689 char __user *optval, int __user *optlen,
75690 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
75691 {
75692- struct compat_group_filter __user *gf32 = (void *)optval;
75693+ struct compat_group_filter __user *gf32 = (void __user *)optval;
75694 struct group_filter __user *kgf;
75695 int __user *koptlen;
75696 u32 interface, fmode, numsrc;
75697diff --git a/net/core/datagram.c b/net/core/datagram.c
75698index ae6acf6..d5c8f66 100644
75699--- a/net/core/datagram.c
75700+++ b/net/core/datagram.c
75701@@ -290,7 +290,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
75702 }
75703
75704 kfree_skb(skb);
75705- atomic_inc(&sk->sk_drops);
75706+ atomic_inc_unchecked(&sk->sk_drops);
75707 sk_mem_reclaim_partial(sk);
75708
75709 return err;
75710diff --git a/net/core/dev.c b/net/core/dev.c
75711index a000840..566cee1 100644
75712--- a/net/core/dev.c
75713+++ b/net/core/dev.c
75714@@ -1135,9 +1135,13 @@ void dev_load(struct net *net, const char *name)
75715 if (no_module && capable(CAP_NET_ADMIN))
75716 no_module = request_module("netdev-%s", name);
75717 if (no_module && capable(CAP_SYS_MODULE)) {
75718+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75719+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
75720+#else
75721 if (!request_module("%s", name))
75722 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
75723 name);
75724+#endif
75725 }
75726 }
75727 EXPORT_SYMBOL(dev_load);
75728@@ -1602,7 +1606,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75729 {
75730 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
75731 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
75732- atomic_long_inc(&dev->rx_dropped);
75733+ atomic_long_inc_unchecked(&dev->rx_dropped);
75734 kfree_skb(skb);
75735 return NET_RX_DROP;
75736 }
75737@@ -1612,7 +1616,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75738 nf_reset(skb);
75739
75740 if (unlikely(!is_skb_forwardable(dev, skb))) {
75741- atomic_long_inc(&dev->rx_dropped);
75742+ atomic_long_inc_unchecked(&dev->rx_dropped);
75743 kfree_skb(skb);
75744 return NET_RX_DROP;
75745 }
75746@@ -2041,7 +2045,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
75747
75748 struct dev_gso_cb {
75749 void (*destructor)(struct sk_buff *skb);
75750-};
75751+} __no_const;
75752
75753 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
75754
75755@@ -2876,7 +2880,7 @@ enqueue:
75756
75757 local_irq_restore(flags);
75758
75759- atomic_long_inc(&skb->dev->rx_dropped);
75760+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75761 kfree_skb(skb);
75762 return NET_RX_DROP;
75763 }
75764@@ -2948,7 +2952,7 @@ int netif_rx_ni(struct sk_buff *skb)
75765 }
75766 EXPORT_SYMBOL(netif_rx_ni);
75767
75768-static void net_tx_action(struct softirq_action *h)
75769+static void net_tx_action(void)
75770 {
75771 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75772
75773@@ -3235,7 +3239,7 @@ ncls:
75774 if (pt_prev) {
75775 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
75776 } else {
75777- atomic_long_inc(&skb->dev->rx_dropped);
75778+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75779 kfree_skb(skb);
75780 /* Jamal, now you will not able to escape explaining
75781 * me how you were going to use this. :-)
75782@@ -3800,7 +3804,7 @@ void netif_napi_del(struct napi_struct *napi)
75783 }
75784 EXPORT_SYMBOL(netif_napi_del);
75785
75786-static void net_rx_action(struct softirq_action *h)
75787+static void net_rx_action(void)
75788 {
75789 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75790 unsigned long time_limit = jiffies + 2;
75791@@ -4270,8 +4274,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
75792 else
75793 seq_printf(seq, "%04x", ntohs(pt->type));
75794
75795+#ifdef CONFIG_GRKERNSEC_HIDESYM
75796+ seq_printf(seq, " %-8s %p\n",
75797+ pt->dev ? pt->dev->name : "", NULL);
75798+#else
75799 seq_printf(seq, " %-8s %pF\n",
75800 pt->dev ? pt->dev->name : "", pt->func);
75801+#endif
75802 }
75803
75804 return 0;
75805@@ -5823,7 +5832,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
75806 } else {
75807 netdev_stats_to_stats64(storage, &dev->stats);
75808 }
75809- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
75810+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
75811 return storage;
75812 }
75813 EXPORT_SYMBOL(dev_get_stats);
75814diff --git a/net/core/flow.c b/net/core/flow.c
75815index e318c7e..168b1d0 100644
75816--- a/net/core/flow.c
75817+++ b/net/core/flow.c
75818@@ -61,7 +61,7 @@ struct flow_cache {
75819 struct timer_list rnd_timer;
75820 };
75821
75822-atomic_t flow_cache_genid = ATOMIC_INIT(0);
75823+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
75824 EXPORT_SYMBOL(flow_cache_genid);
75825 static struct flow_cache flow_cache_global;
75826 static struct kmem_cache *flow_cachep __read_mostly;
75827@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
75828
75829 static int flow_entry_valid(struct flow_cache_entry *fle)
75830 {
75831- if (atomic_read(&flow_cache_genid) != fle->genid)
75832+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
75833 return 0;
75834 if (fle->object && !fle->object->ops->check(fle->object))
75835 return 0;
75836@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
75837 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
75838 fcp->hash_count++;
75839 }
75840- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
75841+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
75842 flo = fle->object;
75843 if (!flo)
75844 goto ret_object;
75845@@ -280,7 +280,7 @@ nocache:
75846 }
75847 flo = resolver(net, key, family, dir, flo, ctx);
75848 if (fle) {
75849- fle->genid = atomic_read(&flow_cache_genid);
75850+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
75851 if (!IS_ERR(flo))
75852 fle->object = flo;
75853 else
75854diff --git a/net/core/iovec.c b/net/core/iovec.c
75855index 7e7aeb0..2a998cb 100644
75856--- a/net/core/iovec.c
75857+++ b/net/core/iovec.c
75858@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
75859 if (m->msg_namelen) {
75860 if (mode == VERIFY_READ) {
75861 void __user *namep;
75862- namep = (void __user __force *) m->msg_name;
75863+ namep = (void __force_user *) m->msg_name;
75864 err = move_addr_to_kernel(namep, m->msg_namelen,
75865 address);
75866 if (err < 0)
75867@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
75868 }
75869
75870 size = m->msg_iovlen * sizeof(struct iovec);
75871- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
75872+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
75873 return -EFAULT;
75874
75875 m->msg_iov = iov;
75876diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
75877index 6c50ac0..6b4c038 100644
75878--- a/net/core/rtnetlink.c
75879+++ b/net/core/rtnetlink.c
75880@@ -58,7 +58,7 @@ struct rtnl_link {
75881 rtnl_doit_func doit;
75882 rtnl_dumpit_func dumpit;
75883 rtnl_calcit_func calcit;
75884-};
75885+} __no_const;
75886
75887 static DEFINE_MUTEX(rtnl_mutex);
75888
75889diff --git a/net/core/scm.c b/net/core/scm.c
75890index 611c5ef..88f6d6d 100644
75891--- a/net/core/scm.c
75892+++ b/net/core/scm.c
75893@@ -219,7 +219,7 @@ EXPORT_SYMBOL(__scm_send);
75894 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75895 {
75896 struct cmsghdr __user *cm
75897- = (__force struct cmsghdr __user *)msg->msg_control;
75898+ = (struct cmsghdr __force_user *)msg->msg_control;
75899 struct cmsghdr cmhdr;
75900 int cmlen = CMSG_LEN(len);
75901 int err;
75902@@ -242,7 +242,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75903 err = -EFAULT;
75904 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
75905 goto out;
75906- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
75907+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
75908 goto out;
75909 cmlen = CMSG_SPACE(len);
75910 if (msg->msg_controllen < cmlen)
75911@@ -258,7 +258,7 @@ EXPORT_SYMBOL(put_cmsg);
75912 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75913 {
75914 struct cmsghdr __user *cm
75915- = (__force struct cmsghdr __user*)msg->msg_control;
75916+ = (struct cmsghdr __force_user *)msg->msg_control;
75917
75918 int fdmax = 0;
75919 int fdnum = scm->fp->count;
75920@@ -278,7 +278,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75921 if (fdnum < fdmax)
75922 fdmax = fdnum;
75923
75924- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
75925+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
75926 i++, cmfptr++)
75927 {
75928 int new_fd;
75929diff --git a/net/core/sock.c b/net/core/sock.c
75930index 9e5b71f..66dec30 100644
75931--- a/net/core/sock.c
75932+++ b/net/core/sock.c
75933@@ -344,7 +344,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75934 struct sk_buff_head *list = &sk->sk_receive_queue;
75935
75936 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
75937- atomic_inc(&sk->sk_drops);
75938+ atomic_inc_unchecked(&sk->sk_drops);
75939 trace_sock_rcvqueue_full(sk, skb);
75940 return -ENOMEM;
75941 }
75942@@ -354,7 +354,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75943 return err;
75944
75945 if (!sk_rmem_schedule(sk, skb->truesize)) {
75946- atomic_inc(&sk->sk_drops);
75947+ atomic_inc_unchecked(&sk->sk_drops);
75948 return -ENOBUFS;
75949 }
75950
75951@@ -374,7 +374,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75952 skb_dst_force(skb);
75953
75954 spin_lock_irqsave(&list->lock, flags);
75955- skb->dropcount = atomic_read(&sk->sk_drops);
75956+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
75957 __skb_queue_tail(list, skb);
75958 spin_unlock_irqrestore(&list->lock, flags);
75959
75960@@ -394,7 +394,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75961 skb->dev = NULL;
75962
75963 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
75964- atomic_inc(&sk->sk_drops);
75965+ atomic_inc_unchecked(&sk->sk_drops);
75966 goto discard_and_relse;
75967 }
75968 if (nested)
75969@@ -412,7 +412,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75970 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
75971 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
75972 bh_unlock_sock(sk);
75973- atomic_inc(&sk->sk_drops);
75974+ atomic_inc_unchecked(&sk->sk_drops);
75975 goto discard_and_relse;
75976 }
75977
75978@@ -976,7 +976,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75979 if (len > sizeof(peercred))
75980 len = sizeof(peercred);
75981 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
75982- if (copy_to_user(optval, &peercred, len))
75983+ if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
75984 return -EFAULT;
75985 goto lenout;
75986 }
75987@@ -989,7 +989,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75988 return -ENOTCONN;
75989 if (lv < len)
75990 return -EINVAL;
75991- if (copy_to_user(optval, address, len))
75992+ if (len > sizeof(address) || copy_to_user(optval, address, len))
75993 return -EFAULT;
75994 goto lenout;
75995 }
75996@@ -1035,7 +1035,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75997
75998 if (len > lv)
75999 len = lv;
76000- if (copy_to_user(optval, &v, len))
76001+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
76002 return -EFAULT;
76003 lenout:
76004 if (put_user(len, optlen))
76005@@ -2124,7 +2124,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
76006 */
76007 smp_wmb();
76008 atomic_set(&sk->sk_refcnt, 1);
76009- atomic_set(&sk->sk_drops, 0);
76010+ atomic_set_unchecked(&sk->sk_drops, 0);
76011 }
76012 EXPORT_SYMBOL(sock_init_data);
76013
76014diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
76015index 5fd1467..8b70900 100644
76016--- a/net/core/sock_diag.c
76017+++ b/net/core/sock_diag.c
76018@@ -16,20 +16,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
76019
76020 int sock_diag_check_cookie(void *sk, __u32 *cookie)
76021 {
76022+#ifndef CONFIG_GRKERNSEC_HIDESYM
76023 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
76024 cookie[1] != INET_DIAG_NOCOOKIE) &&
76025 ((u32)(unsigned long)sk != cookie[0] ||
76026 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
76027 return -ESTALE;
76028 else
76029+#endif
76030 return 0;
76031 }
76032 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
76033
76034 void sock_diag_save_cookie(void *sk, __u32 *cookie)
76035 {
76036+#ifdef CONFIG_GRKERNSEC_HIDESYM
76037+ cookie[0] = 0;
76038+ cookie[1] = 0;
76039+#else
76040 cookie[0] = (u32)(unsigned long)sk;
76041 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
76042+#endif
76043 }
76044 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
76045
76046diff --git a/net/dccp/ccid.h b/net/dccp/ccid.h
76047index 75c3582..fb85d37 100644
76048--- a/net/dccp/ccid.h
76049+++ b/net/dccp/ccid.h
76050@@ -246,7 +246,7 @@ static inline int ccid_hc_rx_getsockopt(struct ccid *ccid, struct sock *sk,
76051 u32 __user *optval, int __user *optlen)
76052 {
76053 int rc = -ENOPROTOOPT;
76054- if (ccid->ccid_ops->ccid_hc_rx_getsockopt != NULL)
76055+ if (ccid != NULL && ccid->ccid_ops->ccid_hc_rx_getsockopt != NULL)
76056 rc = ccid->ccid_ops->ccid_hc_rx_getsockopt(sk, optname, len,
76057 optval, optlen);
76058 return rc;
76059@@ -257,7 +257,7 @@ static inline int ccid_hc_tx_getsockopt(struct ccid *ccid, struct sock *sk,
76060 u32 __user *optval, int __user *optlen)
76061 {
76062 int rc = -ENOPROTOOPT;
76063- if (ccid->ccid_ops->ccid_hc_tx_getsockopt != NULL)
76064+ if (ccid != NULL && ccid->ccid_ops->ccid_hc_tx_getsockopt != NULL)
76065 rc = ccid->ccid_ops->ccid_hc_tx_getsockopt(sk, optname, len,
76066 optval, optlen);
76067 return rc;
76068diff --git a/net/dccp/ccids/ccid3.c b/net/dccp/ccids/ccid3.c
76069index 8c67bed..ce0d140 100644
76070--- a/net/dccp/ccids/ccid3.c
76071+++ b/net/dccp/ccids/ccid3.c
76072@@ -531,6 +531,7 @@ static int ccid3_hc_tx_getsockopt(struct sock *sk, const int optname, int len,
76073 case DCCP_SOCKOPT_CCID_TX_INFO:
76074 if (len < sizeof(tfrc))
76075 return -EINVAL;
76076+ memset(&tfrc, 0, sizeof(tfrc));
76077 tfrc.tfrctx_x = hc->tx_x;
76078 tfrc.tfrctx_x_recv = hc->tx_x_recv;
76079 tfrc.tfrctx_x_calc = hc->tx_x_calc;
76080diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
76081index a55eecc..dd8428c 100644
76082--- a/net/decnet/sysctl_net_decnet.c
76083+++ b/net/decnet/sysctl_net_decnet.c
76084@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
76085
76086 if (len > *lenp) len = *lenp;
76087
76088- if (copy_to_user(buffer, addr, len))
76089+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
76090 return -EFAULT;
76091
76092 *lenp = len;
76093@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
76094
76095 if (len > *lenp) len = *lenp;
76096
76097- if (copy_to_user(buffer, devname, len))
76098+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
76099 return -EFAULT;
76100
76101 *lenp = len;
76102diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
76103index 3854411..2201a94 100644
76104--- a/net/ipv4/fib_frontend.c
76105+++ b/net/ipv4/fib_frontend.c
76106@@ -969,12 +969,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
76107 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76108 fib_sync_up(dev);
76109 #endif
76110- atomic_inc(&net->ipv4.dev_addr_genid);
76111+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76112 rt_cache_flush(dev_net(dev), -1);
76113 break;
76114 case NETDEV_DOWN:
76115 fib_del_ifaddr(ifa, NULL);
76116- atomic_inc(&net->ipv4.dev_addr_genid);
76117+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76118 if (ifa->ifa_dev->ifa_list == NULL) {
76119 /* Last address was deleted from this interface.
76120 * Disable IP.
76121@@ -1010,7 +1010,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
76122 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76123 fib_sync_up(dev);
76124 #endif
76125- atomic_inc(&net->ipv4.dev_addr_genid);
76126+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76127 rt_cache_flush(dev_net(dev), -1);
76128 break;
76129 case NETDEV_DOWN:
76130diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
76131index e5b7182..570a90e 100644
76132--- a/net/ipv4/fib_semantics.c
76133+++ b/net/ipv4/fib_semantics.c
76134@@ -698,7 +698,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
76135 nh->nh_saddr = inet_select_addr(nh->nh_dev,
76136 nh->nh_gw,
76137 nh->nh_parent->fib_scope);
76138- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
76139+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
76140
76141 return nh->nh_saddr;
76142 }
76143diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
76144index 7880af9..70f92a3 100644
76145--- a/net/ipv4/inet_hashtables.c
76146+++ b/net/ipv4/inet_hashtables.c
76147@@ -18,12 +18,15 @@
76148 #include <linux/sched.h>
76149 #include <linux/slab.h>
76150 #include <linux/wait.h>
76151+#include <linux/security.h>
76152
76153 #include <net/inet_connection_sock.h>
76154 #include <net/inet_hashtables.h>
76155 #include <net/secure_seq.h>
76156 #include <net/ip.h>
76157
76158+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
76159+
76160 /*
76161 * Allocate and initialize a new local port bind bucket.
76162 * The bindhash mutex for snum's hash chain must be held here.
76163@@ -530,6 +533,8 @@ ok:
76164 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
76165 spin_unlock(&head->lock);
76166
76167+ gr_update_task_in_ip_table(current, inet_sk(sk));
76168+
76169 if (tw) {
76170 inet_twsk_deschedule(tw, death_row);
76171 while (twrefcnt) {
76172diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
76173index dfba343..c827d50 100644
76174--- a/net/ipv4/inetpeer.c
76175+++ b/net/ipv4/inetpeer.c
76176@@ -487,8 +487,8 @@ relookup:
76177 if (p) {
76178 p->daddr = *daddr;
76179 atomic_set(&p->refcnt, 1);
76180- atomic_set(&p->rid, 0);
76181- atomic_set(&p->ip_id_count,
76182+ atomic_set_unchecked(&p->rid, 0);
76183+ atomic_set_unchecked(&p->ip_id_count,
76184 (daddr->family == AF_INET) ?
76185 secure_ip_id(daddr->addr.a4) :
76186 secure_ipv6_id(daddr->addr.a6));
76187diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
76188index 9dbd3dd..0c59fb2 100644
76189--- a/net/ipv4/ip_fragment.c
76190+++ b/net/ipv4/ip_fragment.c
76191@@ -318,7 +318,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
76192 return 0;
76193
76194 start = qp->rid;
76195- end = atomic_inc_return(&peer->rid);
76196+ end = atomic_inc_return_unchecked(&peer->rid);
76197 qp->rid = end;
76198
76199 rc = qp->q.fragments && (end - start) > max;
76200diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
76201index 0d11f23..2bb3f64 100644
76202--- a/net/ipv4/ip_sockglue.c
76203+++ b/net/ipv4/ip_sockglue.c
76204@@ -1142,7 +1142,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
76205 len = min_t(unsigned int, len, opt->optlen);
76206 if (put_user(len, optlen))
76207 return -EFAULT;
76208- if (copy_to_user(optval, opt->__data, len))
76209+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
76210+ copy_to_user(optval, opt->__data, len))
76211 return -EFAULT;
76212 return 0;
76213 }
76214@@ -1273,7 +1274,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
76215 if (sk->sk_type != SOCK_STREAM)
76216 return -ENOPROTOOPT;
76217
76218- msg.msg_control = optval;
76219+ msg.msg_control = (void __force_kernel *)optval;
76220 msg.msg_controllen = len;
76221 msg.msg_flags = flags;
76222
76223diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
76224index 67e8a6b..386764d 100644
76225--- a/net/ipv4/ipconfig.c
76226+++ b/net/ipv4/ipconfig.c
76227@@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
76228
76229 mm_segment_t oldfs = get_fs();
76230 set_fs(get_ds());
76231- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
76232+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
76233 set_fs(oldfs);
76234 return res;
76235 }
76236@@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
76237
76238 mm_segment_t oldfs = get_fs();
76239 set_fs(get_ds());
76240- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
76241+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
76242 set_fs(oldfs);
76243 return res;
76244 }
76245@@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
76246
76247 mm_segment_t oldfs = get_fs();
76248 set_fs(get_ds());
76249- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
76250+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
76251 set_fs(oldfs);
76252 return res;
76253 }
76254diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
76255index 2c00e8b..45b3bdd 100644
76256--- a/net/ipv4/ping.c
76257+++ b/net/ipv4/ping.c
76258@@ -845,7 +845,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
76259 sk_rmem_alloc_get(sp),
76260 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76261 atomic_read(&sp->sk_refcnt), sp,
76262- atomic_read(&sp->sk_drops), len);
76263+ atomic_read_unchecked(&sp->sk_drops), len);
76264 }
76265
76266 static int ping_seq_show(struct seq_file *seq, void *v)
76267diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
76268index 4032b81..625143c 100644
76269--- a/net/ipv4/raw.c
76270+++ b/net/ipv4/raw.c
76271@@ -304,7 +304,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
76272 int raw_rcv(struct sock *sk, struct sk_buff *skb)
76273 {
76274 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
76275- atomic_inc(&sk->sk_drops);
76276+ atomic_inc_unchecked(&sk->sk_drops);
76277 kfree_skb(skb);
76278 return NET_RX_DROP;
76279 }
76280@@ -740,16 +740,20 @@ static int raw_init(struct sock *sk)
76281
76282 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
76283 {
76284+ struct icmp_filter filter;
76285+
76286 if (optlen > sizeof(struct icmp_filter))
76287 optlen = sizeof(struct icmp_filter);
76288- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
76289+ if (copy_from_user(&filter, optval, optlen))
76290 return -EFAULT;
76291+ raw_sk(sk)->filter = filter;
76292 return 0;
76293 }
76294
76295 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
76296 {
76297 int len, ret = -EFAULT;
76298+ struct icmp_filter filter;
76299
76300 if (get_user(len, optlen))
76301 goto out;
76302@@ -759,8 +763,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
76303 if (len > sizeof(struct icmp_filter))
76304 len = sizeof(struct icmp_filter);
76305 ret = -EFAULT;
76306- if (put_user(len, optlen) ||
76307- copy_to_user(optval, &raw_sk(sk)->filter, len))
76308+ filter = raw_sk(sk)->filter;
76309+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
76310 goto out;
76311 ret = 0;
76312 out: return ret;
76313@@ -988,7 +992,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76314 sk_wmem_alloc_get(sp),
76315 sk_rmem_alloc_get(sp),
76316 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76317- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76318+ atomic_read(&sp->sk_refcnt),
76319+#ifdef CONFIG_GRKERNSEC_HIDESYM
76320+ NULL,
76321+#else
76322+ sp,
76323+#endif
76324+ atomic_read_unchecked(&sp->sk_drops));
76325 }
76326
76327 static int raw_seq_show(struct seq_file *seq, void *v)
76328diff --git a/net/ipv4/route.c b/net/ipv4/route.c
76329index 98b30d0..cfa3cf7 100644
76330--- a/net/ipv4/route.c
76331+++ b/net/ipv4/route.c
76332@@ -313,7 +313,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
76333
76334 static inline int rt_genid(struct net *net)
76335 {
76336- return atomic_read(&net->ipv4.rt_genid);
76337+ return atomic_read_unchecked(&net->ipv4.rt_genid);
76338 }
76339
76340 #ifdef CONFIG_PROC_FS
76341@@ -937,7 +937,7 @@ static void rt_cache_invalidate(struct net *net)
76342 unsigned char shuffle;
76343
76344 get_random_bytes(&shuffle, sizeof(shuffle));
76345- atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
76346+ atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
76347 inetpeer_invalidate_tree(AF_INET);
76348 }
76349
76350@@ -3011,7 +3011,7 @@ static int rt_fill_info(struct net *net,
76351 error = rt->dst.error;
76352 if (peer) {
76353 inet_peer_refcheck(rt->peer);
76354- id = atomic_read(&peer->ip_id_count) & 0xffff;
76355+ id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
76356 if (peer->tcp_ts_stamp) {
76357 ts = peer->tcp_ts;
76358 tsage = get_seconds() - peer->tcp_ts_stamp;
76359diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
76360index c8d28c4..e40f75a 100644
76361--- a/net/ipv4/tcp_ipv4.c
76362+++ b/net/ipv4/tcp_ipv4.c
76363@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
76364 EXPORT_SYMBOL(sysctl_tcp_low_latency);
76365
76366
76367+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76368+extern int grsec_enable_blackhole;
76369+#endif
76370+
76371 #ifdef CONFIG_TCP_MD5SIG
76372 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
76373 __be32 daddr, __be32 saddr, const struct tcphdr *th);
76374@@ -1656,6 +1660,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
76375 return 0;
76376
76377 reset:
76378+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76379+ if (!grsec_enable_blackhole)
76380+#endif
76381 tcp_v4_send_reset(rsk, skb);
76382 discard:
76383 kfree_skb(skb);
76384@@ -1718,12 +1725,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
76385 TCP_SKB_CB(skb)->sacked = 0;
76386
76387 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76388- if (!sk)
76389+ if (!sk) {
76390+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76391+ ret = 1;
76392+#endif
76393 goto no_tcp_socket;
76394-
76395+ }
76396 process:
76397- if (sk->sk_state == TCP_TIME_WAIT)
76398+ if (sk->sk_state == TCP_TIME_WAIT) {
76399+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76400+ ret = 2;
76401+#endif
76402 goto do_time_wait;
76403+ }
76404
76405 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
76406 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76407@@ -1774,6 +1788,10 @@ no_tcp_socket:
76408 bad_packet:
76409 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76410 } else {
76411+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76412+ if (!grsec_enable_blackhole || (ret == 1 &&
76413+ (skb->dev->flags & IFF_LOOPBACK)))
76414+#endif
76415 tcp_v4_send_reset(NULL, skb);
76416 }
76417
76418@@ -2386,7 +2404,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
76419 0, /* non standard timer */
76420 0, /* open_requests have no inode */
76421 atomic_read(&sk->sk_refcnt),
76422+#ifdef CONFIG_GRKERNSEC_HIDESYM
76423+ NULL,
76424+#else
76425 req,
76426+#endif
76427 len);
76428 }
76429
76430@@ -2436,7 +2458,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
76431 sock_i_uid(sk),
76432 icsk->icsk_probes_out,
76433 sock_i_ino(sk),
76434- atomic_read(&sk->sk_refcnt), sk,
76435+ atomic_read(&sk->sk_refcnt),
76436+#ifdef CONFIG_GRKERNSEC_HIDESYM
76437+ NULL,
76438+#else
76439+ sk,
76440+#endif
76441 jiffies_to_clock_t(icsk->icsk_rto),
76442 jiffies_to_clock_t(icsk->icsk_ack.ato),
76443 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
76444@@ -2464,7 +2491,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
76445 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
76446 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
76447 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76448- atomic_read(&tw->tw_refcnt), tw, len);
76449+ atomic_read(&tw->tw_refcnt),
76450+#ifdef CONFIG_GRKERNSEC_HIDESYM
76451+ NULL,
76452+#else
76453+ tw,
76454+#endif
76455+ len);
76456 }
76457
76458 #define TMPSZ 150
76459diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
76460index b85d9fe..4b0eed9 100644
76461--- a/net/ipv4/tcp_minisocks.c
76462+++ b/net/ipv4/tcp_minisocks.c
76463@@ -27,6 +27,10 @@
76464 #include <net/inet_common.h>
76465 #include <net/xfrm.h>
76466
76467+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76468+extern int grsec_enable_blackhole;
76469+#endif
76470+
76471 int sysctl_tcp_syncookies __read_mostly = 1;
76472 EXPORT_SYMBOL(sysctl_tcp_syncookies);
76473
76474@@ -754,6 +758,10 @@ listen_overflow:
76475
76476 embryonic_reset:
76477 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
76478+
76479+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76480+ if (!grsec_enable_blackhole)
76481+#endif
76482 if (!(flg & TCP_FLAG_RST))
76483 req->rsk_ops->send_reset(sk, skb);
76484
76485diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
76486index 4526fe6..1a34e43 100644
76487--- a/net/ipv4/tcp_probe.c
76488+++ b/net/ipv4/tcp_probe.c
76489@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
76490 if (cnt + width >= len)
76491 break;
76492
76493- if (copy_to_user(buf + cnt, tbuf, width))
76494+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
76495 return -EFAULT;
76496 cnt += width;
76497 }
76498diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
76499index e911e6c..d0a9356 100644
76500--- a/net/ipv4/tcp_timer.c
76501+++ b/net/ipv4/tcp_timer.c
76502@@ -22,6 +22,10 @@
76503 #include <linux/gfp.h>
76504 #include <net/tcp.h>
76505
76506+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76507+extern int grsec_lastack_retries;
76508+#endif
76509+
76510 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
76511 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
76512 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
76513@@ -196,6 +200,13 @@ static int tcp_write_timeout(struct sock *sk)
76514 }
76515 }
76516
76517+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76518+ if ((sk->sk_state == TCP_LAST_ACK) &&
76519+ (grsec_lastack_retries > 0) &&
76520+ (grsec_lastack_retries < retry_until))
76521+ retry_until = grsec_lastack_retries;
76522+#endif
76523+
76524 if (retransmits_timed_out(sk, retry_until,
76525 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
76526 /* Has it gone just too far? */
76527diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
76528index eaca736..60488ae 100644
76529--- a/net/ipv4/udp.c
76530+++ b/net/ipv4/udp.c
76531@@ -87,6 +87,7 @@
76532 #include <linux/types.h>
76533 #include <linux/fcntl.h>
76534 #include <linux/module.h>
76535+#include <linux/security.h>
76536 #include <linux/socket.h>
76537 #include <linux/sockios.h>
76538 #include <linux/igmp.h>
76539@@ -110,6 +111,10 @@
76540 #include <linux/static_key.h>
76541 #include "udp_impl.h"
76542
76543+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76544+extern int grsec_enable_blackhole;
76545+#endif
76546+
76547 struct udp_table udp_table __read_mostly;
76548 EXPORT_SYMBOL(udp_table);
76549
76550@@ -568,6 +573,9 @@ found:
76551 return s;
76552 }
76553
76554+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
76555+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
76556+
76557 /*
76558 * This routine is called by the ICMP module when it gets some
76559 * sort of error condition. If err < 0 then the socket should
76560@@ -859,9 +867,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
76561 dport = usin->sin_port;
76562 if (dport == 0)
76563 return -EINVAL;
76564+
76565+ err = gr_search_udp_sendmsg(sk, usin);
76566+ if (err)
76567+ return err;
76568 } else {
76569 if (sk->sk_state != TCP_ESTABLISHED)
76570 return -EDESTADDRREQ;
76571+
76572+ err = gr_search_udp_sendmsg(sk, NULL);
76573+ if (err)
76574+ return err;
76575+
76576 daddr = inet->inet_daddr;
76577 dport = inet->inet_dport;
76578 /* Open fast path for connected socket.
76579@@ -1103,7 +1120,7 @@ static unsigned int first_packet_length(struct sock *sk)
76580 udp_lib_checksum_complete(skb)) {
76581 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76582 IS_UDPLITE(sk));
76583- atomic_inc(&sk->sk_drops);
76584+ atomic_inc_unchecked(&sk->sk_drops);
76585 __skb_unlink(skb, rcvq);
76586 __skb_queue_tail(&list_kill, skb);
76587 }
76588@@ -1189,6 +1206,10 @@ try_again:
76589 if (!skb)
76590 goto out;
76591
76592+ err = gr_search_udp_recvmsg(sk, skb);
76593+ if (err)
76594+ goto out_free;
76595+
76596 ulen = skb->len - sizeof(struct udphdr);
76597 copied = len;
76598 if (copied > ulen)
76599@@ -1498,7 +1519,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76600
76601 drop:
76602 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76603- atomic_inc(&sk->sk_drops);
76604+ atomic_inc_unchecked(&sk->sk_drops);
76605 kfree_skb(skb);
76606 return -1;
76607 }
76608@@ -1517,7 +1538,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76609 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
76610
76611 if (!skb1) {
76612- atomic_inc(&sk->sk_drops);
76613+ atomic_inc_unchecked(&sk->sk_drops);
76614 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
76615 IS_UDPLITE(sk));
76616 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76617@@ -1686,6 +1707,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76618 goto csum_error;
76619
76620 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
76621+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76622+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76623+#endif
76624 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
76625
76626 /*
76627@@ -2104,8 +2128,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
76628 sk_wmem_alloc_get(sp),
76629 sk_rmem_alloc_get(sp),
76630 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76631- atomic_read(&sp->sk_refcnt), sp,
76632- atomic_read(&sp->sk_drops), len);
76633+ atomic_read(&sp->sk_refcnt),
76634+#ifdef CONFIG_GRKERNSEC_HIDESYM
76635+ NULL,
76636+#else
76637+ sp,
76638+#endif
76639+ atomic_read_unchecked(&sp->sk_drops), len);
76640 }
76641
76642 int udp4_seq_show(struct seq_file *seq, void *v)
76643diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
76644index 8f6411c..5767579 100644
76645--- a/net/ipv6/addrconf.c
76646+++ b/net/ipv6/addrconf.c
76647@@ -2145,7 +2145,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
76648 p.iph.ihl = 5;
76649 p.iph.protocol = IPPROTO_IPV6;
76650 p.iph.ttl = 64;
76651- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
76652+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
76653
76654 if (ops->ndo_do_ioctl) {
76655 mm_segment_t oldfs = get_fs();
76656diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
76657index e6cee52..cf47476 100644
76658--- a/net/ipv6/inet6_connection_sock.c
76659+++ b/net/ipv6/inet6_connection_sock.c
76660@@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
76661 #ifdef CONFIG_XFRM
76662 {
76663 struct rt6_info *rt = (struct rt6_info *)dst;
76664- rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
76665+ rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
76666 }
76667 #endif
76668 }
76669@@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
76670 #ifdef CONFIG_XFRM
76671 if (dst) {
76672 struct rt6_info *rt = (struct rt6_info *)dst;
76673- if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
76674+ if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
76675 __sk_dst_reset(sk);
76676 dst = NULL;
76677 }
76678diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
76679index ba6d13d..6899122 100644
76680--- a/net/ipv6/ipv6_sockglue.c
76681+++ b/net/ipv6/ipv6_sockglue.c
76682@@ -989,7 +989,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
76683 if (sk->sk_type != SOCK_STREAM)
76684 return -ENOPROTOOPT;
76685
76686- msg.msg_control = optval;
76687+ msg.msg_control = (void __force_kernel *)optval;
76688 msg.msg_controllen = len;
76689 msg.msg_flags = flags;
76690
76691diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
76692index 93d6983..8e54c4d 100644
76693--- a/net/ipv6/raw.c
76694+++ b/net/ipv6/raw.c
76695@@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
76696 {
76697 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
76698 skb_checksum_complete(skb)) {
76699- atomic_inc(&sk->sk_drops);
76700+ atomic_inc_unchecked(&sk->sk_drops);
76701 kfree_skb(skb);
76702 return NET_RX_DROP;
76703 }
76704@@ -405,7 +405,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76705 struct raw6_sock *rp = raw6_sk(sk);
76706
76707 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
76708- atomic_inc(&sk->sk_drops);
76709+ atomic_inc_unchecked(&sk->sk_drops);
76710 kfree_skb(skb);
76711 return NET_RX_DROP;
76712 }
76713@@ -429,7 +429,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76714
76715 if (inet->hdrincl) {
76716 if (skb_checksum_complete(skb)) {
76717- atomic_inc(&sk->sk_drops);
76718+ atomic_inc_unchecked(&sk->sk_drops);
76719 kfree_skb(skb);
76720 return NET_RX_DROP;
76721 }
76722@@ -602,7 +602,7 @@ out:
76723 return err;
76724 }
76725
76726-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
76727+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
76728 struct flowi6 *fl6, struct dst_entry **dstp,
76729 unsigned int flags)
76730 {
76731@@ -914,12 +914,15 @@ do_confirm:
76732 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
76733 char __user *optval, int optlen)
76734 {
76735+ struct icmp6_filter filter;
76736+
76737 switch (optname) {
76738 case ICMPV6_FILTER:
76739 if (optlen > sizeof(struct icmp6_filter))
76740 optlen = sizeof(struct icmp6_filter);
76741- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
76742+ if (copy_from_user(&filter, optval, optlen))
76743 return -EFAULT;
76744+ raw6_sk(sk)->filter = filter;
76745 return 0;
76746 default:
76747 return -ENOPROTOOPT;
76748@@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76749 char __user *optval, int __user *optlen)
76750 {
76751 int len;
76752+ struct icmp6_filter filter;
76753
76754 switch (optname) {
76755 case ICMPV6_FILTER:
76756@@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76757 len = sizeof(struct icmp6_filter);
76758 if (put_user(len, optlen))
76759 return -EFAULT;
76760- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
76761+ filter = raw6_sk(sk)->filter;
76762+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
76763 return -EFAULT;
76764 return 0;
76765 default:
76766@@ -1250,7 +1255,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76767 0, 0L, 0,
76768 sock_i_uid(sp), 0,
76769 sock_i_ino(sp),
76770- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76771+ atomic_read(&sp->sk_refcnt),
76772+#ifdef CONFIG_GRKERNSEC_HIDESYM
76773+ NULL,
76774+#else
76775+ sp,
76776+#endif
76777+ atomic_read_unchecked(&sp->sk_drops));
76778 }
76779
76780 static int raw6_seq_show(struct seq_file *seq, void *v)
76781diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
76782index 9df64a5..39875da 100644
76783--- a/net/ipv6/tcp_ipv6.c
76784+++ b/net/ipv6/tcp_ipv6.c
76785@@ -94,6 +94,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
76786 }
76787 #endif
76788
76789+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76790+extern int grsec_enable_blackhole;
76791+#endif
76792+
76793 static void tcp_v6_hash(struct sock *sk)
76794 {
76795 if (sk->sk_state != TCP_CLOSE) {
76796@@ -1544,6 +1548,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
76797 return 0;
76798
76799 reset:
76800+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76801+ if (!grsec_enable_blackhole)
76802+#endif
76803 tcp_v6_send_reset(sk, skb);
76804 discard:
76805 if (opt_skb)
76806@@ -1625,12 +1632,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
76807 TCP_SKB_CB(skb)->sacked = 0;
76808
76809 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76810- if (!sk)
76811+ if (!sk) {
76812+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76813+ ret = 1;
76814+#endif
76815 goto no_tcp_socket;
76816+ }
76817
76818 process:
76819- if (sk->sk_state == TCP_TIME_WAIT)
76820+ if (sk->sk_state == TCP_TIME_WAIT) {
76821+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76822+ ret = 2;
76823+#endif
76824 goto do_time_wait;
76825+ }
76826
76827 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
76828 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76829@@ -1679,6 +1694,10 @@ no_tcp_socket:
76830 bad_packet:
76831 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76832 } else {
76833+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76834+ if (!grsec_enable_blackhole || (ret == 1 &&
76835+ (skb->dev->flags & IFF_LOOPBACK)))
76836+#endif
76837 tcp_v6_send_reset(NULL, skb);
76838 }
76839
76840@@ -1885,7 +1904,13 @@ static void get_openreq6(struct seq_file *seq,
76841 uid,
76842 0, /* non standard timer */
76843 0, /* open_requests have no inode */
76844- 0, req);
76845+ 0,
76846+#ifdef CONFIG_GRKERNSEC_HIDESYM
76847+ NULL
76848+#else
76849+ req
76850+#endif
76851+ );
76852 }
76853
76854 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76855@@ -1935,7 +1960,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76856 sock_i_uid(sp),
76857 icsk->icsk_probes_out,
76858 sock_i_ino(sp),
76859- atomic_read(&sp->sk_refcnt), sp,
76860+ atomic_read(&sp->sk_refcnt),
76861+#ifdef CONFIG_GRKERNSEC_HIDESYM
76862+ NULL,
76863+#else
76864+ sp,
76865+#endif
76866 jiffies_to_clock_t(icsk->icsk_rto),
76867 jiffies_to_clock_t(icsk->icsk_ack.ato),
76868 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
76869@@ -1970,7 +2000,13 @@ static void get_timewait6_sock(struct seq_file *seq,
76870 dest->s6_addr32[2], dest->s6_addr32[3], destp,
76871 tw->tw_substate, 0, 0,
76872 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76873- atomic_read(&tw->tw_refcnt), tw);
76874+ atomic_read(&tw->tw_refcnt),
76875+#ifdef CONFIG_GRKERNSEC_HIDESYM
76876+ NULL
76877+#else
76878+ tw
76879+#endif
76880+ );
76881 }
76882
76883 static int tcp6_seq_show(struct seq_file *seq, void *v)
76884diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
76885index f05099f..ea613f0 100644
76886--- a/net/ipv6/udp.c
76887+++ b/net/ipv6/udp.c
76888@@ -50,6 +50,10 @@
76889 #include <linux/seq_file.h>
76890 #include "udp_impl.h"
76891
76892+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76893+extern int grsec_enable_blackhole;
76894+#endif
76895+
76896 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
76897 {
76898 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
76899@@ -615,7 +619,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76900 return rc;
76901 drop:
76902 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76903- atomic_inc(&sk->sk_drops);
76904+ atomic_inc_unchecked(&sk->sk_drops);
76905 kfree_skb(skb);
76906 return -1;
76907 }
76908@@ -673,7 +677,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76909 if (likely(skb1 == NULL))
76910 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
76911 if (!skb1) {
76912- atomic_inc(&sk->sk_drops);
76913+ atomic_inc_unchecked(&sk->sk_drops);
76914 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
76915 IS_UDPLITE(sk));
76916 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76917@@ -844,6 +848,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76918 goto discard;
76919
76920 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
76921+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76922+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76923+#endif
76924 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
76925
76926 kfree_skb(skb);
76927@@ -1453,8 +1460,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
76928 0, 0L, 0,
76929 sock_i_uid(sp), 0,
76930 sock_i_ino(sp),
76931- atomic_read(&sp->sk_refcnt), sp,
76932- atomic_read(&sp->sk_drops));
76933+ atomic_read(&sp->sk_refcnt),
76934+#ifdef CONFIG_GRKERNSEC_HIDESYM
76935+ NULL,
76936+#else
76937+ sp,
76938+#endif
76939+ atomic_read_unchecked(&sp->sk_drops));
76940 }
76941
76942 int udp6_seq_show(struct seq_file *seq, void *v)
76943diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
76944index 6b9d5a0..4dffaf1 100644
76945--- a/net/irda/ircomm/ircomm_tty.c
76946+++ b/net/irda/ircomm/ircomm_tty.c
76947@@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76948 add_wait_queue(&self->open_wait, &wait);
76949
76950 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
76951- __FILE__,__LINE__, tty->driver->name, self->open_count );
76952+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76953
76954 /* As far as I can see, we protect open_count - Jean II */
76955 spin_lock_irqsave(&self->spinlock, flags);
76956 if (!tty_hung_up_p(filp)) {
76957 extra_count = 1;
76958- self->open_count--;
76959+ local_dec(&self->open_count);
76960 }
76961 spin_unlock_irqrestore(&self->spinlock, flags);
76962- self->blocked_open++;
76963+ local_inc(&self->blocked_open);
76964
76965 while (1) {
76966 if (tty->termios->c_cflag & CBAUD) {
76967@@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76968 }
76969
76970 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
76971- __FILE__,__LINE__, tty->driver->name, self->open_count );
76972+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76973
76974 schedule();
76975 }
76976@@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76977 if (extra_count) {
76978 /* ++ is not atomic, so this should be protected - Jean II */
76979 spin_lock_irqsave(&self->spinlock, flags);
76980- self->open_count++;
76981+ local_inc(&self->open_count);
76982 spin_unlock_irqrestore(&self->spinlock, flags);
76983 }
76984- self->blocked_open--;
76985+ local_dec(&self->blocked_open);
76986
76987 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
76988- __FILE__,__LINE__, tty->driver->name, self->open_count);
76989+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
76990
76991 if (!retval)
76992 self->flags |= ASYNC_NORMAL_ACTIVE;
76993@@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
76994 }
76995 /* ++ is not atomic, so this should be protected - Jean II */
76996 spin_lock_irqsave(&self->spinlock, flags);
76997- self->open_count++;
76998+ local_inc(&self->open_count);
76999
77000 tty->driver_data = self;
77001 self->tty = tty;
77002 spin_unlock_irqrestore(&self->spinlock, flags);
77003
77004 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
77005- self->line, self->open_count);
77006+ self->line, local_read(&self->open_count));
77007
77008 /* Not really used by us, but lets do it anyway */
77009 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
77010@@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77011 return;
77012 }
77013
77014- if ((tty->count == 1) && (self->open_count != 1)) {
77015+ if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
77016 /*
77017 * Uh, oh. tty->count is 1, which means that the tty
77018 * structure will be freed. state->count should always
77019@@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77020 */
77021 IRDA_DEBUG(0, "%s(), bad serial port count; "
77022 "tty->count is 1, state->count is %d\n", __func__ ,
77023- self->open_count);
77024- self->open_count = 1;
77025+ local_read(&self->open_count));
77026+ local_set(&self->open_count, 1);
77027 }
77028
77029- if (--self->open_count < 0) {
77030+ if (local_dec_return(&self->open_count) < 0) {
77031 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
77032- __func__, self->line, self->open_count);
77033- self->open_count = 0;
77034+ __func__, self->line, local_read(&self->open_count));
77035+ local_set(&self->open_count, 0);
77036 }
77037- if (self->open_count) {
77038+ if (local_read(&self->open_count)) {
77039 spin_unlock_irqrestore(&self->spinlock, flags);
77040
77041 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
77042@@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77043 tty->closing = 0;
77044 self->tty = NULL;
77045
77046- if (self->blocked_open) {
77047+ if (local_read(&self->blocked_open)) {
77048 if (self->close_delay)
77049 schedule_timeout_interruptible(self->close_delay);
77050 wake_up_interruptible(&self->open_wait);
77051@@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
77052 spin_lock_irqsave(&self->spinlock, flags);
77053 self->flags &= ~ASYNC_NORMAL_ACTIVE;
77054 self->tty = NULL;
77055- self->open_count = 0;
77056+ local_set(&self->open_count, 0);
77057 spin_unlock_irqrestore(&self->spinlock, flags);
77058
77059 wake_up_interruptible(&self->open_wait);
77060@@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
77061 seq_putc(m, '\n');
77062
77063 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
77064- seq_printf(m, "Open count: %d\n", self->open_count);
77065+ seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
77066 seq_printf(m, "Max data size: %d\n", self->max_data_size);
77067 seq_printf(m, "Max header size: %d\n", self->max_header_size);
77068
77069diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
77070index cd6f7a9..e63fe89 100644
77071--- a/net/iucv/af_iucv.c
77072+++ b/net/iucv/af_iucv.c
77073@@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
77074
77075 write_lock_bh(&iucv_sk_list.lock);
77076
77077- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
77078+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77079 while (__iucv_get_sock_by_name(name)) {
77080 sprintf(name, "%08x",
77081- atomic_inc_return(&iucv_sk_list.autobind_name));
77082+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77083 }
77084
77085 write_unlock_bh(&iucv_sk_list.lock);
77086diff --git a/net/key/af_key.c b/net/key/af_key.c
77087index 34e4185..8823368 100644
77088--- a/net/key/af_key.c
77089+++ b/net/key/af_key.c
77090@@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
77091 static u32 get_acqseq(void)
77092 {
77093 u32 res;
77094- static atomic_t acqseq;
77095+ static atomic_unchecked_t acqseq;
77096
77097 do {
77098- res = atomic_inc_return(&acqseq);
77099+ res = atomic_inc_return_unchecked(&acqseq);
77100 } while (!res);
77101 return res;
77102 }
77103diff --git a/net/l2tp/l2tp_ip6.c b/net/l2tp/l2tp_ip6.c
77104index 35e1e4b..9275471 100644
77105--- a/net/l2tp/l2tp_ip6.c
77106+++ b/net/l2tp/l2tp_ip6.c
77107@@ -410,6 +410,7 @@ static int l2tp_ip6_getname(struct socket *sock, struct sockaddr *uaddr,
77108 lsa->l2tp_family = AF_INET6;
77109 lsa->l2tp_flowinfo = 0;
77110 lsa->l2tp_scope_id = 0;
77111+ lsa->l2tp_unused = 0;
77112 if (peer) {
77113 if (!lsk->peer_conn_id)
77114 return -ENOTCONN;
77115diff --git a/net/llc/af_llc.c b/net/llc/af_llc.c
77116index fe5453c..a13c3e23 100644
77117--- a/net/llc/af_llc.c
77118+++ b/net/llc/af_llc.c
77119@@ -969,14 +969,13 @@ static int llc_ui_getname(struct socket *sock, struct sockaddr *uaddr,
77120 struct sockaddr_llc sllc;
77121 struct sock *sk = sock->sk;
77122 struct llc_sock *llc = llc_sk(sk);
77123- int rc = 0;
77124+ int rc = -EBADF;
77125
77126 memset(&sllc, 0, sizeof(sllc));
77127 lock_sock(sk);
77128 if (sock_flag(sk, SOCK_ZAPPED))
77129 goto out;
77130 *uaddrlen = sizeof(sllc);
77131- memset(uaddr, 0, *uaddrlen);
77132 if (peer) {
77133 rc = -ENOTCONN;
77134 if (sk->sk_state != TCP_ESTABLISHED)
77135diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
77136index 3f3cd50..d2cf249 100644
77137--- a/net/mac80211/ieee80211_i.h
77138+++ b/net/mac80211/ieee80211_i.h
77139@@ -28,6 +28,7 @@
77140 #include <net/ieee80211_radiotap.h>
77141 #include <net/cfg80211.h>
77142 #include <net/mac80211.h>
77143+#include <asm/local.h>
77144 #include "key.h"
77145 #include "sta_info.h"
77146
77147@@ -863,7 +864,7 @@ struct ieee80211_local {
77148 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
77149 spinlock_t queue_stop_reason_lock;
77150
77151- int open_count;
77152+ local_t open_count;
77153 int monitors, cooked_mntrs;
77154 /* number of interfaces with corresponding FIF_ flags */
77155 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
77156diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
77157index 8664111..1d6a065 100644
77158--- a/net/mac80211/iface.c
77159+++ b/net/mac80211/iface.c
77160@@ -328,7 +328,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77161 break;
77162 }
77163
77164- if (local->open_count == 0) {
77165+ if (local_read(&local->open_count) == 0) {
77166 res = drv_start(local);
77167 if (res)
77168 goto err_del_bss;
77169@@ -371,7 +371,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77170 break;
77171 }
77172
77173- if (local->monitors == 0 && local->open_count == 0) {
77174+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
77175 res = ieee80211_add_virtual_monitor(local);
77176 if (res)
77177 goto err_stop;
77178@@ -468,7 +468,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77179 mutex_unlock(&local->mtx);
77180
77181 if (coming_up)
77182- local->open_count++;
77183+ local_inc(&local->open_count);
77184
77185 if (hw_reconf_flags)
77186 ieee80211_hw_config(local, hw_reconf_flags);
77187@@ -481,7 +481,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77188 err_del_interface:
77189 drv_remove_interface(local, sdata);
77190 err_stop:
77191- if (!local->open_count)
77192+ if (!local_read(&local->open_count))
77193 drv_stop(local);
77194 err_del_bss:
77195 sdata->bss = NULL;
77196@@ -613,7 +613,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77197 }
77198
77199 if (going_down)
77200- local->open_count--;
77201+ local_dec(&local->open_count);
77202
77203 switch (sdata->vif.type) {
77204 case NL80211_IFTYPE_AP_VLAN:
77205@@ -685,7 +685,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77206
77207 ieee80211_recalc_ps(local, -1);
77208
77209- if (local->open_count == 0) {
77210+ if (local_read(&local->open_count) == 0) {
77211 if (local->ops->napi_poll)
77212 napi_disable(&local->napi);
77213 ieee80211_clear_tx_pending(local);
77214@@ -717,7 +717,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77215 }
77216 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
77217
77218- if (local->monitors == local->open_count && local->monitors > 0)
77219+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
77220 ieee80211_add_virtual_monitor(local);
77221 }
77222
77223diff --git a/net/mac80211/main.c b/net/mac80211/main.c
77224index f5548e9..474a15f 100644
77225--- a/net/mac80211/main.c
77226+++ b/net/mac80211/main.c
77227@@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
77228 local->hw.conf.power_level = power;
77229 }
77230
77231- if (changed && local->open_count) {
77232+ if (changed && local_read(&local->open_count)) {
77233 ret = drv_config(local, changed);
77234 /*
77235 * Goal:
77236diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
77237index af1c4e2..24dbbe3 100644
77238--- a/net/mac80211/pm.c
77239+++ b/net/mac80211/pm.c
77240@@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77241 struct ieee80211_sub_if_data *sdata;
77242 struct sta_info *sta;
77243
77244- if (!local->open_count)
77245+ if (!local_read(&local->open_count))
77246 goto suspend;
77247
77248 ieee80211_scan_cancel(local);
77249@@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77250 cancel_work_sync(&local->dynamic_ps_enable_work);
77251 del_timer_sync(&local->dynamic_ps_timer);
77252
77253- local->wowlan = wowlan && local->open_count;
77254+ local->wowlan = wowlan && local_read(&local->open_count);
77255 if (local->wowlan) {
77256 int err = drv_suspend(local, wowlan);
77257 if (err < 0) {
77258@@ -132,7 +132,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77259 drv_remove_interface(local, sdata);
77260
77261 /* stop hardware - this must stop RX */
77262- if (local->open_count)
77263+ if (local_read(&local->open_count))
77264 ieee80211_stop_device(local);
77265
77266 suspend:
77267diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
77268index 3313c11..bec9f17 100644
77269--- a/net/mac80211/rate.c
77270+++ b/net/mac80211/rate.c
77271@@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
77272
77273 ASSERT_RTNL();
77274
77275- if (local->open_count)
77276+ if (local_read(&local->open_count))
77277 return -EBUSY;
77278
77279 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
77280diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
77281index c97a065..ff61928 100644
77282--- a/net/mac80211/rc80211_pid_debugfs.c
77283+++ b/net/mac80211/rc80211_pid_debugfs.c
77284@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
77285
77286 spin_unlock_irqrestore(&events->lock, status);
77287
77288- if (copy_to_user(buf, pb, p))
77289+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
77290 return -EFAULT;
77291
77292 return p;
77293diff --git a/net/mac80211/util.c b/net/mac80211/util.c
77294index f564b5e..22fee47 100644
77295--- a/net/mac80211/util.c
77296+++ b/net/mac80211/util.c
77297@@ -1224,7 +1224,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
77298 }
77299 #endif
77300 /* everything else happens only if HW was up & running */
77301- if (!local->open_count)
77302+ if (!local_read(&local->open_count))
77303 goto wake_up;
77304
77305 /*
77306diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
77307index 209c1ed..39484dc 100644
77308--- a/net/netfilter/Kconfig
77309+++ b/net/netfilter/Kconfig
77310@@ -851,6 +851,16 @@ config NETFILTER_XT_MATCH_ESP
77311
77312 To compile it as a module, choose M here. If unsure, say N.
77313
77314+config NETFILTER_XT_MATCH_GRADM
77315+ tristate '"gradm" match support'
77316+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
77317+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
77318+ ---help---
77319+ The gradm match allows to match on grsecurity RBAC being enabled.
77320+ It is useful when iptables rules are applied early on bootup to
77321+ prevent connections to the machine (except from a trusted host)
77322+ while the RBAC system is disabled.
77323+
77324 config NETFILTER_XT_MATCH_HASHLIMIT
77325 tristate '"hashlimit" match support'
77326 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
77327diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
77328index 4e7960c..89e48d4 100644
77329--- a/net/netfilter/Makefile
77330+++ b/net/netfilter/Makefile
77331@@ -87,6 +87,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
77332 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
77333 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
77334 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
77335+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
77336 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
77337 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
77338 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
77339diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
77340index 1548df9..98ad9b4 100644
77341--- a/net/netfilter/ipvs/ip_vs_conn.c
77342+++ b/net/netfilter/ipvs/ip_vs_conn.c
77343@@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
77344 /* Increase the refcnt counter of the dest */
77345 atomic_inc(&dest->refcnt);
77346
77347- conn_flags = atomic_read(&dest->conn_flags);
77348+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
77349 if (cp->protocol != IPPROTO_UDP)
77350 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
77351 flags = cp->flags;
77352@@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
77353 atomic_set(&cp->refcnt, 1);
77354
77355 atomic_set(&cp->n_control, 0);
77356- atomic_set(&cp->in_pkts, 0);
77357+ atomic_set_unchecked(&cp->in_pkts, 0);
77358
77359 atomic_inc(&ipvs->conn_count);
77360 if (flags & IP_VS_CONN_F_NO_CPORT)
77361@@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
77362
77363 /* Don't drop the entry if its number of incoming packets is not
77364 located in [0, 8] */
77365- i = atomic_read(&cp->in_pkts);
77366+ i = atomic_read_unchecked(&cp->in_pkts);
77367 if (i > 8 || i < 0) return 0;
77368
77369 if (!todrop_rate[i]) return 0;
77370diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
77371index a54b018c..07e0120 100644
77372--- a/net/netfilter/ipvs/ip_vs_core.c
77373+++ b/net/netfilter/ipvs/ip_vs_core.c
77374@@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
77375 ret = cp->packet_xmit(skb, cp, pd->pp);
77376 /* do not touch skb anymore */
77377
77378- atomic_inc(&cp->in_pkts);
77379+ atomic_inc_unchecked(&cp->in_pkts);
77380 ip_vs_conn_put(cp);
77381 return ret;
77382 }
77383@@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
77384 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
77385 pkts = sysctl_sync_threshold(ipvs);
77386 else
77387- pkts = atomic_add_return(1, &cp->in_pkts);
77388+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77389
77390 if (ipvs->sync_state & IP_VS_STATE_MASTER)
77391 ip_vs_sync_conn(net, cp, pkts);
77392diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
77393index 84444dd..f91c066 100644
77394--- a/net/netfilter/ipvs/ip_vs_ctl.c
77395+++ b/net/netfilter/ipvs/ip_vs_ctl.c
77396@@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
77397 ip_vs_rs_hash(ipvs, dest);
77398 write_unlock_bh(&ipvs->rs_lock);
77399 }
77400- atomic_set(&dest->conn_flags, conn_flags);
77401+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
77402
77403 /* bind the service */
77404 if (!dest->svc) {
77405@@ -2074,7 +2074,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
77406 " %-7s %-6d %-10d %-10d\n",
77407 &dest->addr.in6,
77408 ntohs(dest->port),
77409- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77410+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77411 atomic_read(&dest->weight),
77412 atomic_read(&dest->activeconns),
77413 atomic_read(&dest->inactconns));
77414@@ -2085,7 +2085,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
77415 "%-7s %-6d %-10d %-10d\n",
77416 ntohl(dest->addr.ip),
77417 ntohs(dest->port),
77418- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77419+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77420 atomic_read(&dest->weight),
77421 atomic_read(&dest->activeconns),
77422 atomic_read(&dest->inactconns));
77423@@ -2555,7 +2555,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
77424
77425 entry.addr = dest->addr.ip;
77426 entry.port = dest->port;
77427- entry.conn_flags = atomic_read(&dest->conn_flags);
77428+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
77429 entry.weight = atomic_read(&dest->weight);
77430 entry.u_threshold = dest->u_threshold;
77431 entry.l_threshold = dest->l_threshold;
77432@@ -2759,6 +2759,7 @@ do_ip_vs_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77433 {
77434 struct ip_vs_timeout_user t;
77435
77436+ memset(&t, 0, sizeof(t));
77437 __ip_vs_get_timeouts(net, &t);
77438 if (copy_to_user(user, &t, sizeof(t)) != 0)
77439 ret = -EFAULT;
77440@@ -3089,7 +3090,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
77441 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
77442 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
77443 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
77444- (atomic_read(&dest->conn_flags) &
77445+ (atomic_read_unchecked(&dest->conn_flags) &
77446 IP_VS_CONN_F_FWD_MASK)) ||
77447 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
77448 atomic_read(&dest->weight)) ||
77449diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
77450index effa10c..9058928 100644
77451--- a/net/netfilter/ipvs/ip_vs_sync.c
77452+++ b/net/netfilter/ipvs/ip_vs_sync.c
77453@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
77454 cp = cp->control;
77455 if (cp) {
77456 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
77457- pkts = atomic_add_return(1, &cp->in_pkts);
77458+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77459 else
77460 pkts = sysctl_sync_threshold(ipvs);
77461 ip_vs_sync_conn(net, cp->control, pkts);
77462@@ -758,7 +758,7 @@ control:
77463 if (!cp)
77464 return;
77465 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
77466- pkts = atomic_add_return(1, &cp->in_pkts);
77467+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77468 else
77469 pkts = sysctl_sync_threshold(ipvs);
77470 goto sloop;
77471@@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
77472
77473 if (opt)
77474 memcpy(&cp->in_seq, opt, sizeof(*opt));
77475- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77476+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77477 cp->state = state;
77478 cp->old_state = cp->state;
77479 /*
77480diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
77481index 7fd66de..e6fb361 100644
77482--- a/net/netfilter/ipvs/ip_vs_xmit.c
77483+++ b/net/netfilter/ipvs/ip_vs_xmit.c
77484@@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
77485 else
77486 rc = NF_ACCEPT;
77487 /* do not touch skb anymore */
77488- atomic_inc(&cp->in_pkts);
77489+ atomic_inc_unchecked(&cp->in_pkts);
77490 goto out;
77491 }
77492
77493@@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
77494 else
77495 rc = NF_ACCEPT;
77496 /* do not touch skb anymore */
77497- atomic_inc(&cp->in_pkts);
77498+ atomic_inc_unchecked(&cp->in_pkts);
77499 goto out;
77500 }
77501
77502diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
77503index ac3af97..c134c21 100644
77504--- a/net/netfilter/nf_conntrack_core.c
77505+++ b/net/netfilter/nf_conntrack_core.c
77506@@ -1530,6 +1530,10 @@ err_proto:
77507 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
77508 #define DYING_NULLS_VAL ((1<<30)+1)
77509
77510+#ifdef CONFIG_GRKERNSEC_HIDESYM
77511+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
77512+#endif
77513+
77514 static int nf_conntrack_init_net(struct net *net)
77515 {
77516 int ret;
77517@@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
77518 goto err_stat;
77519 }
77520
77521+#ifdef CONFIG_GRKERNSEC_HIDESYM
77522+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
77523+#else
77524 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
77525+#endif
77526 if (!net->ct.slabname) {
77527 ret = -ENOMEM;
77528 goto err_slabname;
77529diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
77530index 3c3cfc0..7a6ea1a 100644
77531--- a/net/netfilter/nfnetlink_log.c
77532+++ b/net/netfilter/nfnetlink_log.c
77533@@ -70,7 +70,7 @@ struct nfulnl_instance {
77534 };
77535
77536 static DEFINE_SPINLOCK(instances_lock);
77537-static atomic_t global_seq;
77538+static atomic_unchecked_t global_seq;
77539
77540 #define INSTANCE_BUCKETS 16
77541 static struct hlist_head instance_table[INSTANCE_BUCKETS];
77542@@ -517,7 +517,7 @@ __build_packet_message(struct nfulnl_instance *inst,
77543 /* global sequence number */
77544 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
77545 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
77546- htonl(atomic_inc_return(&global_seq))))
77547+ htonl(atomic_inc_return_unchecked(&global_seq))))
77548 goto nla_put_failure;
77549
77550 if (data_len) {
77551diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
77552new file mode 100644
77553index 0000000..6905327
77554--- /dev/null
77555+++ b/net/netfilter/xt_gradm.c
77556@@ -0,0 +1,51 @@
77557+/*
77558+ * gradm match for netfilter
77559