]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.5.3-201208302015.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.5.3-201208302015.patch
CommitLineData
1c3d44ff
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 c901aae..0f96503 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/syscalls.c b/arch/powerpc/kernel/syscalls.c
4378index f2496f2..4e3cc47 100644
4379--- a/arch/powerpc/kernel/syscalls.c
4380+++ b/arch/powerpc/kernel/syscalls.c
4381@@ -107,11 +107,11 @@ long ppc64_personality(unsigned long personality)
4382 long ret;
4383
4384 if (personality(current->personality) == PER_LINUX32
4385- && personality == PER_LINUX)
4386- personality = PER_LINUX32;
4387+ && personality(personality) == PER_LINUX)
4388+ personality = (personality & ~PER_MASK) | PER_LINUX32;
4389 ret = sys_personality(personality);
4390- if (ret == PER_LINUX32)
4391- ret = PER_LINUX;
4392+ if (personality(ret) == PER_LINUX32)
4393+ ret = (ret & ~PER_MASK) | PER_LINUX;
4394 return ret;
4395 }
4396 #endif
4397diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
4398index 1589723..cefe690 100644
4399--- a/arch/powerpc/kernel/traps.c
4400+++ b/arch/powerpc/kernel/traps.c
4401@@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
4402 return flags;
4403 }
4404
4405+extern void gr_handle_kernel_exploit(void);
4406+
4407 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4408 int signr)
4409 {
4410@@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4411 panic("Fatal exception in interrupt");
4412 if (panic_on_oops)
4413 panic("Fatal exception");
4414+
4415+ gr_handle_kernel_exploit();
4416+
4417 do_exit(signr);
4418 }
4419
4420diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
4421index 9eb5b9b..e45498a 100644
4422--- a/arch/powerpc/kernel/vdso.c
4423+++ b/arch/powerpc/kernel/vdso.c
4424@@ -34,6 +34,7 @@
4425 #include <asm/firmware.h>
4426 #include <asm/vdso.h>
4427 #include <asm/vdso_datapage.h>
4428+#include <asm/mman.h>
4429
4430 #include "setup.h"
4431
4432@@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4433 vdso_base = VDSO32_MBASE;
4434 #endif
4435
4436- current->mm->context.vdso_base = 0;
4437+ current->mm->context.vdso_base = ~0UL;
4438
4439 /* vDSO has a problem and was disabled, just don't "enable" it for the
4440 * process
4441@@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4442 vdso_base = get_unmapped_area(NULL, vdso_base,
4443 (vdso_pages << PAGE_SHIFT) +
4444 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4445- 0, 0);
4446+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
4447 if (IS_ERR_VALUE(vdso_base)) {
4448 rc = vdso_base;
4449 goto fail_mmapsem;
4450diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4451index 5eea6f3..5d10396 100644
4452--- a/arch/powerpc/lib/usercopy_64.c
4453+++ b/arch/powerpc/lib/usercopy_64.c
4454@@ -9,22 +9,6 @@
4455 #include <linux/module.h>
4456 #include <asm/uaccess.h>
4457
4458-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4459-{
4460- if (likely(access_ok(VERIFY_READ, from, n)))
4461- n = __copy_from_user(to, from, n);
4462- else
4463- memset(to, 0, n);
4464- return n;
4465-}
4466-
4467-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4468-{
4469- if (likely(access_ok(VERIFY_WRITE, to, n)))
4470- n = __copy_to_user(to, from, n);
4471- return n;
4472-}
4473-
4474 unsigned long copy_in_user(void __user *to, const void __user *from,
4475 unsigned long n)
4476 {
4477@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4478 return n;
4479 }
4480
4481-EXPORT_SYMBOL(copy_from_user);
4482-EXPORT_SYMBOL(copy_to_user);
4483 EXPORT_SYMBOL(copy_in_user);
4484
4485diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4486index 08ffcf5..a0ab912 100644
4487--- a/arch/powerpc/mm/fault.c
4488+++ b/arch/powerpc/mm/fault.c
4489@@ -32,6 +32,10 @@
4490 #include <linux/perf_event.h>
4491 #include <linux/magic.h>
4492 #include <linux/ratelimit.h>
4493+#include <linux/slab.h>
4494+#include <linux/pagemap.h>
4495+#include <linux/compiler.h>
4496+#include <linux/unistd.h>
4497
4498 #include <asm/firmware.h>
4499 #include <asm/page.h>
4500@@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4501 }
4502 #endif
4503
4504+#ifdef CONFIG_PAX_PAGEEXEC
4505+/*
4506+ * PaX: decide what to do with offenders (regs->nip = fault address)
4507+ *
4508+ * returns 1 when task should be killed
4509+ */
4510+static int pax_handle_fetch_fault(struct pt_regs *regs)
4511+{
4512+ return 1;
4513+}
4514+
4515+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4516+{
4517+ unsigned long i;
4518+
4519+ printk(KERN_ERR "PAX: bytes at PC: ");
4520+ for (i = 0; i < 5; i++) {
4521+ unsigned int c;
4522+ if (get_user(c, (unsigned int __user *)pc+i))
4523+ printk(KERN_CONT "???????? ");
4524+ else
4525+ printk(KERN_CONT "%08x ", c);
4526+ }
4527+ printk("\n");
4528+}
4529+#endif
4530+
4531 /*
4532 * Check whether the instruction at regs->nip is a store using
4533 * an update addressing form which will update r1.
4534@@ -215,7 +246,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4535 * indicate errors in DSISR but can validly be set in SRR1.
4536 */
4537 if (trap == 0x400)
4538- error_code &= 0x48200000;
4539+ error_code &= 0x58200000;
4540 else
4541 is_write = error_code & DSISR_ISSTORE;
4542 #else
4543@@ -366,7 +397,7 @@ good_area:
4544 * "undefined". Of those that can be set, this is the only
4545 * one which seems bad.
4546 */
4547- if (error_code & 0x10000000)
4548+ if (error_code & DSISR_GUARDED)
4549 /* Guarded storage error. */
4550 goto bad_area;
4551 #endif /* CONFIG_8xx */
4552@@ -381,7 +412,7 @@ good_area:
4553 * processors use the same I/D cache coherency mechanism
4554 * as embedded.
4555 */
4556- if (error_code & DSISR_PROTFAULT)
4557+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4558 goto bad_area;
4559 #endif /* CONFIG_PPC_STD_MMU */
4560
4561@@ -463,6 +494,23 @@ bad_area:
4562 bad_area_nosemaphore:
4563 /* User mode accesses cause a SIGSEGV */
4564 if (user_mode(regs)) {
4565+
4566+#ifdef CONFIG_PAX_PAGEEXEC
4567+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4568+#ifdef CONFIG_PPC_STD_MMU
4569+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4570+#else
4571+ if (is_exec && regs->nip == address) {
4572+#endif
4573+ switch (pax_handle_fetch_fault(regs)) {
4574+ }
4575+
4576+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4577+ do_group_exit(SIGKILL);
4578+ }
4579+ }
4580+#endif
4581+
4582 _exception(SIGSEGV, regs, code, address);
4583 return 0;
4584 }
4585diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4586index 67a42ed..1c7210c 100644
4587--- a/arch/powerpc/mm/mmap_64.c
4588+++ b/arch/powerpc/mm/mmap_64.c
4589@@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4590 */
4591 if (mmap_is_legacy()) {
4592 mm->mmap_base = TASK_UNMAPPED_BASE;
4593+
4594+#ifdef CONFIG_PAX_RANDMMAP
4595+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4596+ mm->mmap_base += mm->delta_mmap;
4597+#endif
4598+
4599 mm->get_unmapped_area = arch_get_unmapped_area;
4600 mm->unmap_area = arch_unmap_area;
4601 } else {
4602 mm->mmap_base = mmap_base();
4603+
4604+#ifdef CONFIG_PAX_RANDMMAP
4605+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4606+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4607+#endif
4608+
4609 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4610 mm->unmap_area = arch_unmap_area_topdown;
4611 }
4612diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4613index 73709f7..6b90313 100644
4614--- a/arch/powerpc/mm/slice.c
4615+++ b/arch/powerpc/mm/slice.c
4616@@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4617 if ((mm->task_size - len) < addr)
4618 return 0;
4619 vma = find_vma(mm, addr);
4620- return (!vma || (addr + len) <= vma->vm_start);
4621+ return check_heap_stack_gap(vma, addr, len);
4622 }
4623
4624 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4625@@ -256,7 +256,7 @@ full_search:
4626 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4627 continue;
4628 }
4629- if (!vma || addr + len <= vma->vm_start) {
4630+ if (check_heap_stack_gap(vma, addr, len)) {
4631 /*
4632 * Remember the place where we stopped the search:
4633 */
4634@@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4635 }
4636 }
4637
4638- addr = mm->mmap_base;
4639- while (addr > len) {
4640+ if (mm->mmap_base < len)
4641+ addr = -ENOMEM;
4642+ else
4643+ addr = mm->mmap_base - len;
4644+
4645+ while (!IS_ERR_VALUE(addr)) {
4646 /* Go down by chunk size */
4647- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4648+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
4649
4650 /* Check for hit with different page size */
4651 mask = slice_range_to_mask(addr, len);
4652@@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4653 * return with success:
4654 */
4655 vma = find_vma(mm, addr);
4656- if (!vma || (addr + len) <= vma->vm_start) {
4657+ if (check_heap_stack_gap(vma, addr, len)) {
4658 /* remember the address as a hint for next time */
4659 if (use_cache)
4660 mm->free_area_cache = addr;
4661@@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4662 mm->cached_hole_size = vma->vm_start - addr;
4663
4664 /* try just below the current vma->vm_start */
4665- addr = vma->vm_start;
4666+ addr = skip_heap_stack_gap(vma, len);
4667 }
4668
4669 /*
4670@@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4671 if (fixed && addr > (mm->task_size - len))
4672 return -EINVAL;
4673
4674+#ifdef CONFIG_PAX_RANDMMAP
4675+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4676+ addr = 0;
4677+#endif
4678+
4679 /* If hint, make sure it matches our alignment restrictions */
4680 if (!fixed && addr) {
4681 addr = _ALIGN_UP(addr, 1ul << pshift);
4682diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4683index 748347b..81bc6c7 100644
4684--- a/arch/s390/include/asm/atomic.h
4685+++ b/arch/s390/include/asm/atomic.h
4686@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4687 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4688 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4689
4690+#define atomic64_read_unchecked(v) atomic64_read(v)
4691+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4692+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4693+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4694+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4695+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4696+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4697+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4698+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4699+
4700 #define smp_mb__before_atomic_dec() smp_mb()
4701 #define smp_mb__after_atomic_dec() smp_mb()
4702 #define smp_mb__before_atomic_inc() smp_mb()
4703diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4704index 2a30d5a..5e5586f 100644
4705--- a/arch/s390/include/asm/cache.h
4706+++ b/arch/s390/include/asm/cache.h
4707@@ -11,8 +11,10 @@
4708 #ifndef __ARCH_S390_CACHE_H
4709 #define __ARCH_S390_CACHE_H
4710
4711-#define L1_CACHE_BYTES 256
4712+#include <linux/const.h>
4713+
4714 #define L1_CACHE_SHIFT 8
4715+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4716 #define NET_SKB_PAD 32
4717
4718 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4719diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4720index 06151e6..c08cb52 100644
4721--- a/arch/s390/include/asm/elf.h
4722+++ b/arch/s390/include/asm/elf.h
4723@@ -161,8 +161,14 @@ extern unsigned int vdso_enabled;
4724 the loader. We need to make sure that it is out of the way of the program
4725 that it will "exec", and that there is sufficient room for the brk. */
4726
4727-extern unsigned long randomize_et_dyn(unsigned long base);
4728-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4729+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4730+
4731+#ifdef CONFIG_PAX_ASLR
4732+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4733+
4734+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4735+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4736+#endif
4737
4738 /* This yields a mask that user programs can use to figure out what
4739 instruction set this CPU supports. */
4740@@ -210,7 +216,4 @@ struct linux_binprm;
4741 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4742 int arch_setup_additional_pages(struct linux_binprm *, int);
4743
4744-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4745-#define arch_randomize_brk arch_randomize_brk
4746-
4747 #endif
4748diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
4749index c4a93d6..4d2a9b4 100644
4750--- a/arch/s390/include/asm/exec.h
4751+++ b/arch/s390/include/asm/exec.h
4752@@ -7,6 +7,6 @@
4753 #ifndef __ASM_EXEC_H
4754 #define __ASM_EXEC_H
4755
4756-extern unsigned long arch_align_stack(unsigned long sp);
4757+#define arch_align_stack(x) ((x) & ~0xfUL)
4758
4759 #endif /* __ASM_EXEC_H */
4760diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4761index 1f3a79b..44d7f9c 100644
4762--- a/arch/s390/include/asm/uaccess.h
4763+++ b/arch/s390/include/asm/uaccess.h
4764@@ -241,6 +241,10 @@ static inline unsigned long __must_check
4765 copy_to_user(void __user *to, const void *from, unsigned long n)
4766 {
4767 might_fault();
4768+
4769+ if ((long)n < 0)
4770+ return n;
4771+
4772 if (access_ok(VERIFY_WRITE, to, n))
4773 n = __copy_to_user(to, from, n);
4774 return n;
4775@@ -266,6 +270,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4776 static inline unsigned long __must_check
4777 __copy_from_user(void *to, const void __user *from, unsigned long n)
4778 {
4779+ if ((long)n < 0)
4780+ return n;
4781+
4782 if (__builtin_constant_p(n) && (n <= 256))
4783 return uaccess.copy_from_user_small(n, from, to);
4784 else
4785@@ -297,10 +304,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
4786 static inline unsigned long __must_check
4787 copy_from_user(void *to, const void __user *from, unsigned long n)
4788 {
4789- unsigned int sz = __compiletime_object_size(to);
4790+ size_t sz = __compiletime_object_size(to);
4791
4792 might_fault();
4793- if (unlikely(sz != -1 && sz < n)) {
4794+
4795+ if ((long)n < 0)
4796+ return n;
4797+
4798+ if (unlikely(sz != (size_t)-1 && sz < n)) {
4799 copy_from_user_overflow();
4800 return n;
4801 }
4802diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4803index dfcb343..eda788a 100644
4804--- a/arch/s390/kernel/module.c
4805+++ b/arch/s390/kernel/module.c
4806@@ -161,11 +161,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4807
4808 /* Increase core size by size of got & plt and set start
4809 offsets for got and plt. */
4810- me->core_size = ALIGN(me->core_size, 4);
4811- me->arch.got_offset = me->core_size;
4812- me->core_size += me->arch.got_size;
4813- me->arch.plt_offset = me->core_size;
4814- me->core_size += me->arch.plt_size;
4815+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
4816+ me->arch.got_offset = me->core_size_rw;
4817+ me->core_size_rw += me->arch.got_size;
4818+ me->arch.plt_offset = me->core_size_rx;
4819+ me->core_size_rx += me->arch.plt_size;
4820 return 0;
4821 }
4822
4823@@ -242,7 +242,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4824 if (info->got_initialized == 0) {
4825 Elf_Addr *gotent;
4826
4827- gotent = me->module_core + me->arch.got_offset +
4828+ gotent = me->module_core_rw + me->arch.got_offset +
4829 info->got_offset;
4830 *gotent = val;
4831 info->got_initialized = 1;
4832@@ -266,7 +266,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4833 else if (r_type == R_390_GOTENT ||
4834 r_type == R_390_GOTPLTENT)
4835 *(unsigned int *) loc =
4836- (val + (Elf_Addr) me->module_core - loc) >> 1;
4837+ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4838 else if (r_type == R_390_GOT64 ||
4839 r_type == R_390_GOTPLT64)
4840 *(unsigned long *) loc = val;
4841@@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4842 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4843 if (info->plt_initialized == 0) {
4844 unsigned int *ip;
4845- ip = me->module_core + me->arch.plt_offset +
4846+ ip = me->module_core_rx + me->arch.plt_offset +
4847 info->plt_offset;
4848 #ifndef CONFIG_64BIT
4849 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4850@@ -305,7 +305,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4851 val - loc + 0xffffUL < 0x1ffffeUL) ||
4852 (r_type == R_390_PLT32DBL &&
4853 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4854- val = (Elf_Addr) me->module_core +
4855+ val = (Elf_Addr) me->module_core_rx +
4856 me->arch.plt_offset +
4857 info->plt_offset;
4858 val += rela->r_addend - loc;
4859@@ -327,7 +327,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4860 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4861 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4862 val = val + rela->r_addend -
4863- ((Elf_Addr) me->module_core + me->arch.got_offset);
4864+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4865 if (r_type == R_390_GOTOFF16)
4866 *(unsigned short *) loc = val;
4867 else if (r_type == R_390_GOTOFF32)
4868@@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4869 break;
4870 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4871 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4872- val = (Elf_Addr) me->module_core + me->arch.got_offset +
4873+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4874 rela->r_addend - loc;
4875 if (r_type == R_390_GOTPC)
4876 *(unsigned int *) loc = val;
4877diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4878index 60055ce..ee4b252 100644
4879--- a/arch/s390/kernel/process.c
4880+++ b/arch/s390/kernel/process.c
4881@@ -316,39 +316,3 @@ unsigned long get_wchan(struct task_struct *p)
4882 }
4883 return 0;
4884 }
4885-
4886-unsigned long arch_align_stack(unsigned long sp)
4887-{
4888- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4889- sp -= get_random_int() & ~PAGE_MASK;
4890- return sp & ~0xf;
4891-}
4892-
4893-static inline unsigned long brk_rnd(void)
4894-{
4895- /* 8MB for 32bit, 1GB for 64bit */
4896- if (is_32bit_task())
4897- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4898- else
4899- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4900-}
4901-
4902-unsigned long arch_randomize_brk(struct mm_struct *mm)
4903-{
4904- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4905-
4906- if (ret < mm->brk)
4907- return mm->brk;
4908- return ret;
4909-}
4910-
4911-unsigned long randomize_et_dyn(unsigned long base)
4912-{
4913- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4914-
4915- if (!(current->flags & PF_RANDOMIZE))
4916- return base;
4917- if (ret < base)
4918- return base;
4919- return ret;
4920-}
4921diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4922index a64fe53..5c66963 100644
4923--- a/arch/s390/mm/mmap.c
4924+++ b/arch/s390/mm/mmap.c
4925@@ -92,10 +92,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4926 */
4927 if (mmap_is_legacy()) {
4928 mm->mmap_base = TASK_UNMAPPED_BASE;
4929+
4930+#ifdef CONFIG_PAX_RANDMMAP
4931+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4932+ mm->mmap_base += mm->delta_mmap;
4933+#endif
4934+
4935 mm->get_unmapped_area = arch_get_unmapped_area;
4936 mm->unmap_area = arch_unmap_area;
4937 } else {
4938 mm->mmap_base = mmap_base();
4939+
4940+#ifdef CONFIG_PAX_RANDMMAP
4941+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4942+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4943+#endif
4944+
4945 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4946 mm->unmap_area = arch_unmap_area_topdown;
4947 }
4948@@ -174,10 +186,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4949 */
4950 if (mmap_is_legacy()) {
4951 mm->mmap_base = TASK_UNMAPPED_BASE;
4952+
4953+#ifdef CONFIG_PAX_RANDMMAP
4954+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4955+ mm->mmap_base += mm->delta_mmap;
4956+#endif
4957+
4958 mm->get_unmapped_area = s390_get_unmapped_area;
4959 mm->unmap_area = arch_unmap_area;
4960 } else {
4961 mm->mmap_base = mmap_base();
4962+
4963+#ifdef CONFIG_PAX_RANDMMAP
4964+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4965+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4966+#endif
4967+
4968 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4969 mm->unmap_area = arch_unmap_area_topdown;
4970 }
4971diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4972index ae3d59f..f65f075 100644
4973--- a/arch/score/include/asm/cache.h
4974+++ b/arch/score/include/asm/cache.h
4975@@ -1,7 +1,9 @@
4976 #ifndef _ASM_SCORE_CACHE_H
4977 #define _ASM_SCORE_CACHE_H
4978
4979+#include <linux/const.h>
4980+
4981 #define L1_CACHE_SHIFT 4
4982-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4983+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4984
4985 #endif /* _ASM_SCORE_CACHE_H */
4986diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
4987index f9f3cd5..58ff438 100644
4988--- a/arch/score/include/asm/exec.h
4989+++ b/arch/score/include/asm/exec.h
4990@@ -1,6 +1,6 @@
4991 #ifndef _ASM_SCORE_EXEC_H
4992 #define _ASM_SCORE_EXEC_H
4993
4994-extern unsigned long arch_align_stack(unsigned long sp);
4995+#define arch_align_stack(x) (x)
4996
4997 #endif /* _ASM_SCORE_EXEC_H */
4998diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4999index 2707023..1c2a3b7 100644
5000--- a/arch/score/kernel/process.c
5001+++ b/arch/score/kernel/process.c
5002@@ -159,8 +159,3 @@ unsigned long get_wchan(struct task_struct *task)
5003
5004 return task_pt_regs(task)->cp0_epc;
5005 }
5006-
5007-unsigned long arch_align_stack(unsigned long sp)
5008-{
5009- return sp;
5010-}
5011diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
5012index ef9e555..331bd29 100644
5013--- a/arch/sh/include/asm/cache.h
5014+++ b/arch/sh/include/asm/cache.h
5015@@ -9,10 +9,11 @@
5016 #define __ASM_SH_CACHE_H
5017 #ifdef __KERNEL__
5018
5019+#include <linux/const.h>
5020 #include <linux/init.h>
5021 #include <cpu/cache.h>
5022
5023-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5024+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5025
5026 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5027
5028diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
5029index afeb710..d1d1289 100644
5030--- a/arch/sh/mm/mmap.c
5031+++ b/arch/sh/mm/mmap.c
5032@@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5033 addr = PAGE_ALIGN(addr);
5034
5035 vma = find_vma(mm, addr);
5036- if (TASK_SIZE - len >= addr &&
5037- (!vma || addr + len <= vma->vm_start))
5038+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5039 return addr;
5040 }
5041
5042@@ -106,7 +105,7 @@ full_search:
5043 }
5044 return -ENOMEM;
5045 }
5046- if (likely(!vma || addr + len <= vma->vm_start)) {
5047+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5048 /*
5049 * Remember the place where we stopped the search:
5050 */
5051@@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5052 addr = PAGE_ALIGN(addr);
5053
5054 vma = find_vma(mm, addr);
5055- if (TASK_SIZE - len >= addr &&
5056- (!vma || addr + len <= vma->vm_start))
5057+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5058 return addr;
5059 }
5060
5061@@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5062 /* make sure it can fit in the remaining address space */
5063 if (likely(addr > len)) {
5064 vma = find_vma(mm, addr-len);
5065- if (!vma || addr <= vma->vm_start) {
5066+ if (check_heap_stack_gap(vma, addr - len, len)) {
5067 /* remember the address as a hint for next time */
5068 return (mm->free_area_cache = addr-len);
5069 }
5070@@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5071 if (unlikely(mm->mmap_base < len))
5072 goto bottomup;
5073
5074- addr = mm->mmap_base-len;
5075- if (do_colour_align)
5076- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5077+ addr = mm->mmap_base - len;
5078
5079 do {
5080+ if (do_colour_align)
5081+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5082 /*
5083 * Lookup failure means no vma is above this address,
5084 * else if new region fits below vma->vm_start,
5085 * return with success:
5086 */
5087 vma = find_vma(mm, addr);
5088- if (likely(!vma || addr+len <= vma->vm_start)) {
5089+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5090 /* remember the address as a hint for next time */
5091 return (mm->free_area_cache = addr);
5092 }
5093@@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5094 mm->cached_hole_size = vma->vm_start - addr;
5095
5096 /* try just below the current vma->vm_start */
5097- addr = vma->vm_start-len;
5098- if (do_colour_align)
5099- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5100- } while (likely(len < vma->vm_start));
5101+ addr = skip_heap_stack_gap(vma, len);
5102+ } while (!IS_ERR_VALUE(addr));
5103
5104 bottomup:
5105 /*
5106diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5107index ce35a1c..2e7b8f9 100644
5108--- a/arch/sparc/include/asm/atomic_64.h
5109+++ b/arch/sparc/include/asm/atomic_64.h
5110@@ -14,18 +14,40 @@
5111 #define ATOMIC64_INIT(i) { (i) }
5112
5113 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5114+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5115+{
5116+ return v->counter;
5117+}
5118 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5119+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5120+{
5121+ return v->counter;
5122+}
5123
5124 #define atomic_set(v, i) (((v)->counter) = i)
5125+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5126+{
5127+ v->counter = i;
5128+}
5129 #define atomic64_set(v, i) (((v)->counter) = i)
5130+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5131+{
5132+ v->counter = i;
5133+}
5134
5135 extern void atomic_add(int, atomic_t *);
5136+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5137 extern void atomic64_add(long, atomic64_t *);
5138+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5139 extern void atomic_sub(int, atomic_t *);
5140+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5141 extern void atomic64_sub(long, atomic64_t *);
5142+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5143
5144 extern int atomic_add_ret(int, atomic_t *);
5145+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5146 extern long atomic64_add_ret(long, atomic64_t *);
5147+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5148 extern int atomic_sub_ret(int, atomic_t *);
5149 extern long atomic64_sub_ret(long, atomic64_t *);
5150
5151@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5152 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5153
5154 #define atomic_inc_return(v) atomic_add_ret(1, v)
5155+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5156+{
5157+ return atomic_add_ret_unchecked(1, v);
5158+}
5159 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5160+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5161+{
5162+ return atomic64_add_ret_unchecked(1, v);
5163+}
5164
5165 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5166 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5167
5168 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5169+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5170+{
5171+ return atomic_add_ret_unchecked(i, v);
5172+}
5173 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5174+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5175+{
5176+ return atomic64_add_ret_unchecked(i, v);
5177+}
5178
5179 /*
5180 * atomic_inc_and_test - increment and test
5181@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5182 * other cases.
5183 */
5184 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5185+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5186+{
5187+ return atomic_inc_return_unchecked(v) == 0;
5188+}
5189 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5190
5191 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5192@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5193 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5194
5195 #define atomic_inc(v) atomic_add(1, v)
5196+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5197+{
5198+ atomic_add_unchecked(1, v);
5199+}
5200 #define atomic64_inc(v) atomic64_add(1, v)
5201+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5202+{
5203+ atomic64_add_unchecked(1, v);
5204+}
5205
5206 #define atomic_dec(v) atomic_sub(1, v)
5207+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5208+{
5209+ atomic_sub_unchecked(1, v);
5210+}
5211 #define atomic64_dec(v) atomic64_sub(1, v)
5212+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5213+{
5214+ atomic64_sub_unchecked(1, v);
5215+}
5216
5217 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5218 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5219
5220 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5221+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
5222+{
5223+ return cmpxchg(&v->counter, old, new);
5224+}
5225 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5226+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5227+{
5228+ return xchg(&v->counter, new);
5229+}
5230
5231 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5232 {
5233- int c, old;
5234+ int c, old, new;
5235 c = atomic_read(v);
5236 for (;;) {
5237- if (unlikely(c == (u)))
5238+ if (unlikely(c == u))
5239 break;
5240- old = atomic_cmpxchg((v), c, c + (a));
5241+
5242+ asm volatile("addcc %2, %0, %0\n"
5243+
5244+#ifdef CONFIG_PAX_REFCOUNT
5245+ "tvs %%icc, 6\n"
5246+#endif
5247+
5248+ : "=r" (new)
5249+ : "0" (c), "ir" (a)
5250+ : "cc");
5251+
5252+ old = atomic_cmpxchg(v, c, new);
5253 if (likely(old == c))
5254 break;
5255 c = old;
5256@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5257 #define atomic64_cmpxchg(v, o, n) \
5258 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
5259 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
5260+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
5261+{
5262+ return xchg(&v->counter, new);
5263+}
5264
5265 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5266 {
5267- long c, old;
5268+ long c, old, new;
5269 c = atomic64_read(v);
5270 for (;;) {
5271- if (unlikely(c == (u)))
5272+ if (unlikely(c == u))
5273 break;
5274- old = atomic64_cmpxchg((v), c, c + (a));
5275+
5276+ asm volatile("addcc %2, %0, %0\n"
5277+
5278+#ifdef CONFIG_PAX_REFCOUNT
5279+ "tvs %%xcc, 6\n"
5280+#endif
5281+
5282+ : "=r" (new)
5283+ : "0" (c), "ir" (a)
5284+ : "cc");
5285+
5286+ old = atomic64_cmpxchg(v, c, new);
5287 if (likely(old == c))
5288 break;
5289 c = old;
5290 }
5291- return c != (u);
5292+ return c != u;
5293 }
5294
5295 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5296diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
5297index 5bb6991..5c2132e 100644
5298--- a/arch/sparc/include/asm/cache.h
5299+++ b/arch/sparc/include/asm/cache.h
5300@@ -7,10 +7,12 @@
5301 #ifndef _SPARC_CACHE_H
5302 #define _SPARC_CACHE_H
5303
5304+#include <linux/const.h>
5305+
5306 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5307
5308 #define L1_CACHE_SHIFT 5
5309-#define L1_CACHE_BYTES 32
5310+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5311
5312 #ifdef CONFIG_SPARC32
5313 #define SMP_CACHE_BYTES_SHIFT 5
5314diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
5315index 2d4d755..81b6662 100644
5316--- a/arch/sparc/include/asm/elf_32.h
5317+++ b/arch/sparc/include/asm/elf_32.h
5318@@ -114,6 +114,13 @@ typedef struct {
5319
5320 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5321
5322+#ifdef CONFIG_PAX_ASLR
5323+#define PAX_ELF_ET_DYN_BASE 0x10000UL
5324+
5325+#define PAX_DELTA_MMAP_LEN 16
5326+#define PAX_DELTA_STACK_LEN 16
5327+#endif
5328+
5329 /* This yields a mask that user programs can use to figure out what
5330 instruction set this cpu supports. This can NOT be done in userspace
5331 on Sparc. */
5332diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
5333index 7df8b7f..4946269 100644
5334--- a/arch/sparc/include/asm/elf_64.h
5335+++ b/arch/sparc/include/asm/elf_64.h
5336@@ -180,6 +180,13 @@ typedef struct {
5337 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5338 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5339
5340+#ifdef CONFIG_PAX_ASLR
5341+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5342+
5343+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5344+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5345+#endif
5346+
5347 extern unsigned long sparc64_elf_hwcap;
5348 #define ELF_HWCAP sparc64_elf_hwcap
5349
5350diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
5351index e5b169b46..e90b4fa 100644
5352--- a/arch/sparc/include/asm/pgalloc_32.h
5353+++ b/arch/sparc/include/asm/pgalloc_32.h
5354@@ -46,6 +46,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
5355 }
5356
5357 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
5358+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
5359
5360 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
5361 unsigned long address)
5362diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
5363index 40b2d7a..22a665b 100644
5364--- a/arch/sparc/include/asm/pgalloc_64.h
5365+++ b/arch/sparc/include/asm/pgalloc_64.h
5366@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
5367 }
5368
5369 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
5370+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
5371
5372 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5373 {
5374diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
5375index cbbbed5..0983069 100644
5376--- a/arch/sparc/include/asm/pgtable_32.h
5377+++ b/arch/sparc/include/asm/pgtable_32.h
5378@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
5379 #define PAGE_SHARED SRMMU_PAGE_SHARED
5380 #define PAGE_COPY SRMMU_PAGE_COPY
5381 #define PAGE_READONLY SRMMU_PAGE_RDONLY
5382+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
5383+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
5384+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
5385 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
5386
5387 /* Top-level page directory */
5388@@ -61,18 +64,18 @@ extern unsigned long ptr_in_current_pgd;
5389
5390 /* xwr */
5391 #define __P000 PAGE_NONE
5392-#define __P001 PAGE_READONLY
5393-#define __P010 PAGE_COPY
5394-#define __P011 PAGE_COPY
5395+#define __P001 PAGE_READONLY_NOEXEC
5396+#define __P010 PAGE_COPY_NOEXEC
5397+#define __P011 PAGE_COPY_NOEXEC
5398 #define __P100 PAGE_READONLY
5399 #define __P101 PAGE_READONLY
5400 #define __P110 PAGE_COPY
5401 #define __P111 PAGE_COPY
5402
5403 #define __S000 PAGE_NONE
5404-#define __S001 PAGE_READONLY
5405-#define __S010 PAGE_SHARED
5406-#define __S011 PAGE_SHARED
5407+#define __S001 PAGE_READONLY_NOEXEC
5408+#define __S010 PAGE_SHARE_NOEXEC
5409+#define __S011 PAGE_SHARE_NOEXEC
5410 #define __S100 PAGE_READONLY
5411 #define __S101 PAGE_READONLY
5412 #define __S110 PAGE_SHARED
5413diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
5414index 79da178..c2eede8 100644
5415--- a/arch/sparc/include/asm/pgtsrmmu.h
5416+++ b/arch/sparc/include/asm/pgtsrmmu.h
5417@@ -115,6 +115,11 @@
5418 SRMMU_EXEC | SRMMU_REF)
5419 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5420 SRMMU_EXEC | SRMMU_REF)
5421+
5422+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5423+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5424+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5425+
5426 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5427 SRMMU_DIRTY | SRMMU_REF)
5428
5429diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
5430index 9689176..63c18ea 100644
5431--- a/arch/sparc/include/asm/spinlock_64.h
5432+++ b/arch/sparc/include/asm/spinlock_64.h
5433@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
5434
5435 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5436
5437-static void inline arch_read_lock(arch_rwlock_t *lock)
5438+static inline void arch_read_lock(arch_rwlock_t *lock)
5439 {
5440 unsigned long tmp1, tmp2;
5441
5442 __asm__ __volatile__ (
5443 "1: ldsw [%2], %0\n"
5444 " brlz,pn %0, 2f\n"
5445-"4: add %0, 1, %1\n"
5446+"4: addcc %0, 1, %1\n"
5447+
5448+#ifdef CONFIG_PAX_REFCOUNT
5449+" tvs %%icc, 6\n"
5450+#endif
5451+
5452 " cas [%2], %0, %1\n"
5453 " cmp %0, %1\n"
5454 " bne,pn %%icc, 1b\n"
5455@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5456 " .previous"
5457 : "=&r" (tmp1), "=&r" (tmp2)
5458 : "r" (lock)
5459- : "memory");
5460+ : "memory", "cc");
5461 }
5462
5463-static int inline arch_read_trylock(arch_rwlock_t *lock)
5464+static inline int arch_read_trylock(arch_rwlock_t *lock)
5465 {
5466 int tmp1, tmp2;
5467
5468@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5469 "1: ldsw [%2], %0\n"
5470 " brlz,a,pn %0, 2f\n"
5471 " mov 0, %0\n"
5472-" add %0, 1, %1\n"
5473+" addcc %0, 1, %1\n"
5474+
5475+#ifdef CONFIG_PAX_REFCOUNT
5476+" tvs %%icc, 6\n"
5477+#endif
5478+
5479 " cas [%2], %0, %1\n"
5480 " cmp %0, %1\n"
5481 " bne,pn %%icc, 1b\n"
5482@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5483 return tmp1;
5484 }
5485
5486-static void inline arch_read_unlock(arch_rwlock_t *lock)
5487+static inline void arch_read_unlock(arch_rwlock_t *lock)
5488 {
5489 unsigned long tmp1, tmp2;
5490
5491 __asm__ __volatile__(
5492 "1: lduw [%2], %0\n"
5493-" sub %0, 1, %1\n"
5494+" subcc %0, 1, %1\n"
5495+
5496+#ifdef CONFIG_PAX_REFCOUNT
5497+" tvs %%icc, 6\n"
5498+#endif
5499+
5500 " cas [%2], %0, %1\n"
5501 " cmp %0, %1\n"
5502 " bne,pn %%xcc, 1b\n"
5503@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5504 : "memory");
5505 }
5506
5507-static void inline arch_write_lock(arch_rwlock_t *lock)
5508+static inline void arch_write_lock(arch_rwlock_t *lock)
5509 {
5510 unsigned long mask, tmp1, tmp2;
5511
5512@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5513 : "memory");
5514 }
5515
5516-static void inline arch_write_unlock(arch_rwlock_t *lock)
5517+static inline void arch_write_unlock(arch_rwlock_t *lock)
5518 {
5519 __asm__ __volatile__(
5520 " stw %%g0, [%0]"
5521@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5522 : "memory");
5523 }
5524
5525-static int inline arch_write_trylock(arch_rwlock_t *lock)
5526+static inline int arch_write_trylock(arch_rwlock_t *lock)
5527 {
5528 unsigned long mask, tmp1, tmp2, result;
5529
5530diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5531index e6cd224..3a71793 100644
5532--- a/arch/sparc/include/asm/thread_info_32.h
5533+++ b/arch/sparc/include/asm/thread_info_32.h
5534@@ -49,6 +49,8 @@ struct thread_info {
5535 unsigned long w_saved;
5536
5537 struct restart_block restart_block;
5538+
5539+ unsigned long lowest_stack;
5540 };
5541
5542 /*
5543diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5544index cfa8c38..13f30d3 100644
5545--- a/arch/sparc/include/asm/thread_info_64.h
5546+++ b/arch/sparc/include/asm/thread_info_64.h
5547@@ -63,6 +63,8 @@ struct thread_info {
5548 struct pt_regs *kern_una_regs;
5549 unsigned int kern_una_insn;
5550
5551+ unsigned long lowest_stack;
5552+
5553 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5554 };
5555
5556@@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
5557 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
5558 /* flag bit 6 is available */
5559 #define TIF_32BIT 7 /* 32-bit binary */
5560-/* flag bit 8 is available */
5561+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
5562 #define TIF_SECCOMP 9 /* secure computing */
5563 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
5564 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
5565+
5566 /* NOTE: Thread flags >= 12 should be ones we have no interest
5567 * in using in assembly, else we can't use the mask as
5568 * an immediate value in instructions such as andcc.
5569@@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
5570 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
5571 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5572 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
5573+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5574
5575 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
5576 _TIF_DO_NOTIFY_RESUME_MASK | \
5577 _TIF_NEED_RESCHED)
5578 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
5579
5580+#define _TIF_WORK_SYSCALL \
5581+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
5582+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
5583+
5584+
5585 /*
5586 * Thread-synchronous status.
5587 *
5588diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5589index 0167d26..9acd8ed 100644
5590--- a/arch/sparc/include/asm/uaccess.h
5591+++ b/arch/sparc/include/asm/uaccess.h
5592@@ -1,5 +1,13 @@
5593 #ifndef ___ASM_SPARC_UACCESS_H
5594 #define ___ASM_SPARC_UACCESS_H
5595+
5596+#ifdef __KERNEL__
5597+#ifndef __ASSEMBLY__
5598+#include <linux/types.h>
5599+extern void check_object_size(const void *ptr, unsigned long n, bool to);
5600+#endif
5601+#endif
5602+
5603 #if defined(__sparc__) && defined(__arch64__)
5604 #include <asm/uaccess_64.h>
5605 #else
5606diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5607index 53a28dd..50c38c3 100644
5608--- a/arch/sparc/include/asm/uaccess_32.h
5609+++ b/arch/sparc/include/asm/uaccess_32.h
5610@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5611
5612 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5613 {
5614- if (n && __access_ok((unsigned long) to, n))
5615+ if ((long)n < 0)
5616+ return n;
5617+
5618+ if (n && __access_ok((unsigned long) to, n)) {
5619+ if (!__builtin_constant_p(n))
5620+ check_object_size(from, n, true);
5621 return __copy_user(to, (__force void __user *) from, n);
5622- else
5623+ } else
5624 return n;
5625 }
5626
5627 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5628 {
5629+ if ((long)n < 0)
5630+ return n;
5631+
5632+ if (!__builtin_constant_p(n))
5633+ check_object_size(from, n, true);
5634+
5635 return __copy_user(to, (__force void __user *) from, n);
5636 }
5637
5638 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5639 {
5640- if (n && __access_ok((unsigned long) from, n))
5641+ if ((long)n < 0)
5642+ return n;
5643+
5644+ if (n && __access_ok((unsigned long) from, n)) {
5645+ if (!__builtin_constant_p(n))
5646+ check_object_size(to, n, false);
5647 return __copy_user((__force void __user *) to, from, n);
5648- else
5649+ } else
5650 return n;
5651 }
5652
5653 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5654 {
5655+ if ((long)n < 0)
5656+ return n;
5657+
5658 return __copy_user((__force void __user *) to, from, n);
5659 }
5660
5661diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5662index 7c831d8..d440ca7 100644
5663--- a/arch/sparc/include/asm/uaccess_64.h
5664+++ b/arch/sparc/include/asm/uaccess_64.h
5665@@ -10,6 +10,7 @@
5666 #include <linux/compiler.h>
5667 #include <linux/string.h>
5668 #include <linux/thread_info.h>
5669+#include <linux/kernel.h>
5670 #include <asm/asi.h>
5671 #include <asm/spitfire.h>
5672 #include <asm-generic/uaccess-unaligned.h>
5673@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5674 static inline unsigned long __must_check
5675 copy_from_user(void *to, const void __user *from, unsigned long size)
5676 {
5677- unsigned long ret = ___copy_from_user(to, from, size);
5678+ unsigned long ret;
5679
5680+ if ((long)size < 0 || size > INT_MAX)
5681+ return size;
5682+
5683+ if (!__builtin_constant_p(size))
5684+ check_object_size(to, size, false);
5685+
5686+ ret = ___copy_from_user(to, from, size);
5687 if (unlikely(ret))
5688 ret = copy_from_user_fixup(to, from, size);
5689
5690@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5691 static inline unsigned long __must_check
5692 copy_to_user(void __user *to, const void *from, unsigned long size)
5693 {
5694- unsigned long ret = ___copy_to_user(to, from, size);
5695+ unsigned long ret;
5696
5697+ if ((long)size < 0 || size > INT_MAX)
5698+ return size;
5699+
5700+ if (!__builtin_constant_p(size))
5701+ check_object_size(from, size, true);
5702+
5703+ ret = ___copy_to_user(to, from, size);
5704 if (unlikely(ret))
5705 ret = copy_to_user_fixup(to, from, size);
5706 return ret;
5707diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5708index 6cf591b..b49e65a 100644
5709--- a/arch/sparc/kernel/Makefile
5710+++ b/arch/sparc/kernel/Makefile
5711@@ -3,7 +3,7 @@
5712 #
5713
5714 asflags-y := -ansi
5715-ccflags-y := -Werror
5716+#ccflags-y := -Werror
5717
5718 extra-y := head_$(BITS).o
5719
5720diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5721index cb36e82..1c1462f 100644
5722--- a/arch/sparc/kernel/process_32.c
5723+++ b/arch/sparc/kernel/process_32.c
5724@@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
5725
5726 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5727 r->psr, r->pc, r->npc, r->y, print_tainted());
5728- printk("PC: <%pS>\n", (void *) r->pc);
5729+ printk("PC: <%pA>\n", (void *) r->pc);
5730 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5731 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5732 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5733 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5734 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5735 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5736- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5737+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5738
5739 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5740 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5741@@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5742 rw = (struct reg_window32 *) fp;
5743 pc = rw->ins[7];
5744 printk("[%08lx : ", pc);
5745- printk("%pS ] ", (void *) pc);
5746+ printk("%pA ] ", (void *) pc);
5747 fp = rw->ins[6];
5748 } while (++count < 16);
5749 printk("\n");
5750diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5751index aff0c72..9067b39 100644
5752--- a/arch/sparc/kernel/process_64.c
5753+++ b/arch/sparc/kernel/process_64.c
5754@@ -179,14 +179,14 @@ static void show_regwindow(struct pt_regs *regs)
5755 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5756 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5757 if (regs->tstate & TSTATE_PRIV)
5758- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5759+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5760 }
5761
5762 void show_regs(struct pt_regs *regs)
5763 {
5764 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5765 regs->tpc, regs->tnpc, regs->y, print_tainted());
5766- printk("TPC: <%pS>\n", (void *) regs->tpc);
5767+ printk("TPC: <%pA>\n", (void *) regs->tpc);
5768 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5769 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5770 regs->u_regs[3]);
5771@@ -199,7 +199,7 @@ void show_regs(struct pt_regs *regs)
5772 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5773 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5774 regs->u_regs[15]);
5775- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5776+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5777 show_regwindow(regs);
5778 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5779 }
5780@@ -284,7 +284,7 @@ void arch_trigger_all_cpu_backtrace(void)
5781 ((tp && tp->task) ? tp->task->pid : -1));
5782
5783 if (gp->tstate & TSTATE_PRIV) {
5784- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5785+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5786 (void *) gp->tpc,
5787 (void *) gp->o7,
5788 (void *) gp->i7,
5789diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
5790index 484daba..0674139 100644
5791--- a/arch/sparc/kernel/ptrace_64.c
5792+++ b/arch/sparc/kernel/ptrace_64.c
5793@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
5794 return ret;
5795 }
5796
5797+#ifdef CONFIG_GRKERNSEC_SETXID
5798+extern void gr_delayed_cred_worker(void);
5799+#endif
5800+
5801 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5802 {
5803 int ret = 0;
5804@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5805 /* do the secure computing check first */
5806 secure_computing_strict(regs->u_regs[UREG_G1]);
5807
5808+#ifdef CONFIG_GRKERNSEC_SETXID
5809+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5810+ gr_delayed_cred_worker();
5811+#endif
5812+
5813 if (test_thread_flag(TIF_SYSCALL_TRACE))
5814 ret = tracehook_report_syscall_entry(regs);
5815
5816@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5817
5818 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
5819 {
5820+#ifdef CONFIG_GRKERNSEC_SETXID
5821+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5822+ gr_delayed_cred_worker();
5823+#endif
5824+
5825 audit_syscall_exit(regs);
5826
5827 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5828diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5829index 0c9b31b..7cb7aee 100644
5830--- a/arch/sparc/kernel/sys_sparc_32.c
5831+++ b/arch/sparc/kernel/sys_sparc_32.c
5832@@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5833 if (len > TASK_SIZE - PAGE_SIZE)
5834 return -ENOMEM;
5835 if (!addr)
5836- addr = TASK_UNMAPPED_BASE;
5837+ addr = current->mm->mmap_base;
5838
5839 if (flags & MAP_SHARED)
5840 addr = COLOUR_ALIGN(addr);
5841@@ -65,7 +65,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5842 /* At this point: (!vmm || addr < vmm->vm_end). */
5843 if (TASK_SIZE - PAGE_SIZE - len < addr)
5844 return -ENOMEM;
5845- if (!vmm || addr + len <= vmm->vm_start)
5846+ if (check_heap_stack_gap(vmm, addr, len))
5847 return addr;
5848 addr = vmm->vm_end;
5849 if (flags & MAP_SHARED)
5850diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5851index 275f74f..81bf5b8 100644
5852--- a/arch/sparc/kernel/sys_sparc_64.c
5853+++ b/arch/sparc/kernel/sys_sparc_64.c
5854@@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5855 /* We do not accept a shared mapping if it would violate
5856 * cache aliasing constraints.
5857 */
5858- if ((flags & MAP_SHARED) &&
5859+ if ((filp || (flags & MAP_SHARED)) &&
5860 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5861 return -EINVAL;
5862 return addr;
5863@@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5864 if (filp || (flags & MAP_SHARED))
5865 do_color_align = 1;
5866
5867+#ifdef CONFIG_PAX_RANDMMAP
5868+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5869+#endif
5870+
5871 if (addr) {
5872 if (do_color_align)
5873 addr = COLOUR_ALIGN(addr, pgoff);
5874@@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5875 addr = PAGE_ALIGN(addr);
5876
5877 vma = find_vma(mm, addr);
5878- if (task_size - len >= addr &&
5879- (!vma || addr + len <= vma->vm_start))
5880+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5881 return addr;
5882 }
5883
5884 if (len > mm->cached_hole_size) {
5885- start_addr = addr = mm->free_area_cache;
5886+ start_addr = addr = mm->free_area_cache;
5887 } else {
5888- start_addr = addr = TASK_UNMAPPED_BASE;
5889+ start_addr = addr = mm->mmap_base;
5890 mm->cached_hole_size = 0;
5891 }
5892
5893@@ -174,14 +177,14 @@ full_search:
5894 vma = find_vma(mm, VA_EXCLUDE_END);
5895 }
5896 if (unlikely(task_size < addr)) {
5897- if (start_addr != TASK_UNMAPPED_BASE) {
5898- start_addr = addr = TASK_UNMAPPED_BASE;
5899+ if (start_addr != mm->mmap_base) {
5900+ start_addr = addr = mm->mmap_base;
5901 mm->cached_hole_size = 0;
5902 goto full_search;
5903 }
5904 return -ENOMEM;
5905 }
5906- if (likely(!vma || addr + len <= vma->vm_start)) {
5907+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5908 /*
5909 * Remember the place where we stopped the search:
5910 */
5911@@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5912 /* We do not accept a shared mapping if it would violate
5913 * cache aliasing constraints.
5914 */
5915- if ((flags & MAP_SHARED) &&
5916+ if ((filp || (flags & MAP_SHARED)) &&
5917 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5918 return -EINVAL;
5919 return addr;
5920@@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5921 addr = PAGE_ALIGN(addr);
5922
5923 vma = find_vma(mm, addr);
5924- if (task_size - len >= addr &&
5925- (!vma || addr + len <= vma->vm_start))
5926+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5927 return addr;
5928 }
5929
5930@@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5931 /* make sure it can fit in the remaining address space */
5932 if (likely(addr > len)) {
5933 vma = find_vma(mm, addr-len);
5934- if (!vma || addr <= vma->vm_start) {
5935+ if (check_heap_stack_gap(vma, addr - len, len)) {
5936 /* remember the address as a hint for next time */
5937 return (mm->free_area_cache = addr-len);
5938 }
5939@@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5940 if (unlikely(mm->mmap_base < len))
5941 goto bottomup;
5942
5943- addr = mm->mmap_base-len;
5944- if (do_color_align)
5945- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5946+ addr = mm->mmap_base - len;
5947
5948 do {
5949+ if (do_color_align)
5950+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5951 /*
5952 * Lookup failure means no vma is above this address,
5953 * else if new region fits below vma->vm_start,
5954 * return with success:
5955 */
5956 vma = find_vma(mm, addr);
5957- if (likely(!vma || addr+len <= vma->vm_start)) {
5958+ if (likely(check_heap_stack_gap(vma, addr, len))) {
5959 /* remember the address as a hint for next time */
5960 return (mm->free_area_cache = addr);
5961 }
5962@@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5963 mm->cached_hole_size = vma->vm_start - addr;
5964
5965 /* try just below the current vma->vm_start */
5966- addr = vma->vm_start-len;
5967- if (do_color_align)
5968- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5969- } while (likely(len < vma->vm_start));
5970+ addr = skip_heap_stack_gap(vma, len);
5971+ } while (!IS_ERR_VALUE(addr));
5972
5973 bottomup:
5974 /*
5975@@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5976 gap == RLIM_INFINITY ||
5977 sysctl_legacy_va_layout) {
5978 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5979+
5980+#ifdef CONFIG_PAX_RANDMMAP
5981+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5982+ mm->mmap_base += mm->delta_mmap;
5983+#endif
5984+
5985 mm->get_unmapped_area = arch_get_unmapped_area;
5986 mm->unmap_area = arch_unmap_area;
5987 } else {
5988@@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5989 gap = (task_size / 6 * 5);
5990
5991 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5992+
5993+#ifdef CONFIG_PAX_RANDMMAP
5994+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5995+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5996+#endif
5997+
5998 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5999 mm->unmap_area = arch_unmap_area_topdown;
6000 }
6001diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
6002index 1d7e274..b39c527 100644
6003--- a/arch/sparc/kernel/syscalls.S
6004+++ b/arch/sparc/kernel/syscalls.S
6005@@ -62,7 +62,7 @@ sys32_rt_sigreturn:
6006 #endif
6007 .align 32
6008 1: ldx [%g6 + TI_FLAGS], %l5
6009- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6010+ andcc %l5, _TIF_WORK_SYSCALL, %g0
6011 be,pt %icc, rtrap
6012 nop
6013 call syscall_trace_leave
6014@@ -179,7 +179,7 @@ linux_sparc_syscall32:
6015
6016 srl %i5, 0, %o5 ! IEU1
6017 srl %i2, 0, %o2 ! IEU0 Group
6018- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6019+ andcc %l0, _TIF_WORK_SYSCALL, %g0
6020 bne,pn %icc, linux_syscall_trace32 ! CTI
6021 mov %i0, %l5 ! IEU1
6022 call %l7 ! CTI Group brk forced
6023@@ -202,7 +202,7 @@ linux_sparc_syscall:
6024
6025 mov %i3, %o3 ! IEU1
6026 mov %i4, %o4 ! IEU0 Group
6027- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6028+ andcc %l0, _TIF_WORK_SYSCALL, %g0
6029 bne,pn %icc, linux_syscall_trace ! CTI Group
6030 mov %i0, %l5 ! IEU0
6031 2: call %l7 ! CTI Group brk forced
6032@@ -226,7 +226,7 @@ ret_sys_call:
6033
6034 cmp %o0, -ERESTART_RESTARTBLOCK
6035 bgeu,pn %xcc, 1f
6036- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6037+ andcc %l0, _TIF_WORK_SYSCALL, %l6
6038 80:
6039 /* System call success, clear Carry condition code. */
6040 andn %g3, %g2, %g3
6041@@ -241,7 +241,7 @@ ret_sys_call:
6042 /* System call failure, set Carry condition code.
6043 * Also, get abs(errno) to return to the process.
6044 */
6045- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6046+ andcc %l0, _TIF_WORK_SYSCALL, %l6
6047 sub %g0, %o0, %o0
6048 or %g3, %g2, %g3
6049 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
6050diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6051index a5785ea..405c5f7 100644
6052--- a/arch/sparc/kernel/traps_32.c
6053+++ b/arch/sparc/kernel/traps_32.c
6054@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
6055 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6056 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6057
6058+extern void gr_handle_kernel_exploit(void);
6059+
6060 void die_if_kernel(char *str, struct pt_regs *regs)
6061 {
6062 static int die_counter;
6063@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6064 count++ < 30 &&
6065 (((unsigned long) rw) >= PAGE_OFFSET) &&
6066 !(((unsigned long) rw) & 0x7)) {
6067- printk("Caller[%08lx]: %pS\n", rw->ins[7],
6068+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
6069 (void *) rw->ins[7]);
6070 rw = (struct reg_window32 *)rw->ins[6];
6071 }
6072 }
6073 printk("Instruction DUMP:");
6074 instruction_dump ((unsigned long *) regs->pc);
6075- if(regs->psr & PSR_PS)
6076+ if(regs->psr & PSR_PS) {
6077+ gr_handle_kernel_exploit();
6078 do_exit(SIGKILL);
6079+ }
6080 do_exit(SIGSEGV);
6081 }
6082
6083diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6084index 3b05e66..6ea2917 100644
6085--- a/arch/sparc/kernel/traps_64.c
6086+++ b/arch/sparc/kernel/traps_64.c
6087@@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6088 i + 1,
6089 p->trapstack[i].tstate, p->trapstack[i].tpc,
6090 p->trapstack[i].tnpc, p->trapstack[i].tt);
6091- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6092+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6093 }
6094 }
6095
6096@@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6097
6098 lvl -= 0x100;
6099 if (regs->tstate & TSTATE_PRIV) {
6100+
6101+#ifdef CONFIG_PAX_REFCOUNT
6102+ if (lvl == 6)
6103+ pax_report_refcount_overflow(regs);
6104+#endif
6105+
6106 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6107 die_if_kernel(buffer, regs);
6108 }
6109@@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6110 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6111 {
6112 char buffer[32];
6113-
6114+
6115 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6116 0, lvl, SIGTRAP) == NOTIFY_STOP)
6117 return;
6118
6119+#ifdef CONFIG_PAX_REFCOUNT
6120+ if (lvl == 6)
6121+ pax_report_refcount_overflow(regs);
6122+#endif
6123+
6124 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6125
6126 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6127@@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6128 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6129 printk("%s" "ERROR(%d): ",
6130 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6131- printk("TPC<%pS>\n", (void *) regs->tpc);
6132+ printk("TPC<%pA>\n", (void *) regs->tpc);
6133 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6134 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6135 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6136@@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6137 smp_processor_id(),
6138 (type & 0x1) ? 'I' : 'D',
6139 regs->tpc);
6140- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6141+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6142 panic("Irrecoverable Cheetah+ parity error.");
6143 }
6144
6145@@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6146 smp_processor_id(),
6147 (type & 0x1) ? 'I' : 'D',
6148 regs->tpc);
6149- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6150+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6151 }
6152
6153 struct sun4v_error_entry {
6154@@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6155
6156 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6157 regs->tpc, tl);
6158- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6159+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6160 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6161- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6162+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6163 (void *) regs->u_regs[UREG_I7]);
6164 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6165 "pte[%lx] error[%lx]\n",
6166@@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6167
6168 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6169 regs->tpc, tl);
6170- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6171+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6172 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6173- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6174+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6175 (void *) regs->u_regs[UREG_I7]);
6176 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6177 "pte[%lx] error[%lx]\n",
6178@@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6179 fp = (unsigned long)sf->fp + STACK_BIAS;
6180 }
6181
6182- printk(" [%016lx] %pS\n", pc, (void *) pc);
6183+ printk(" [%016lx] %pA\n", pc, (void *) pc);
6184 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6185 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6186 int index = tsk->curr_ret_stack;
6187 if (tsk->ret_stack && index >= graph) {
6188 pc = tsk->ret_stack[index - graph].ret;
6189- printk(" [%016lx] %pS\n", pc, (void *) pc);
6190+ printk(" [%016lx] %pA\n", pc, (void *) pc);
6191 graph++;
6192 }
6193 }
6194@@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6195 return (struct reg_window *) (fp + STACK_BIAS);
6196 }
6197
6198+extern void gr_handle_kernel_exploit(void);
6199+
6200 void die_if_kernel(char *str, struct pt_regs *regs)
6201 {
6202 static int die_counter;
6203@@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6204 while (rw &&
6205 count++ < 30 &&
6206 kstack_valid(tp, (unsigned long) rw)) {
6207- printk("Caller[%016lx]: %pS\n", rw->ins[7],
6208+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
6209 (void *) rw->ins[7]);
6210
6211 rw = kernel_stack_up(rw);
6212@@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6213 }
6214 user_instruction_dump ((unsigned int __user *) regs->tpc);
6215 }
6216- if (regs->tstate & TSTATE_PRIV)
6217+ if (regs->tstate & TSTATE_PRIV) {
6218+ gr_handle_kernel_exploit();
6219 do_exit(SIGKILL);
6220+ }
6221 do_exit(SIGSEGV);
6222 }
6223 EXPORT_SYMBOL(die_if_kernel);
6224diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6225index f81d038..e7a4680 100644
6226--- a/arch/sparc/kernel/unaligned_64.c
6227+++ b/arch/sparc/kernel/unaligned_64.c
6228@@ -278,7 +278,7 @@ static void log_unaligned(struct pt_regs *regs)
6229 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6230
6231 if (__ratelimit(&ratelimit)) {
6232- printk("Kernel unaligned access at TPC[%lx] %pS\n",
6233+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
6234 regs->tpc, (void *) regs->tpc);
6235 }
6236 }
6237diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6238index dff4096..bd9a388 100644
6239--- a/arch/sparc/lib/Makefile
6240+++ b/arch/sparc/lib/Makefile
6241@@ -2,7 +2,7 @@
6242 #
6243
6244 asflags-y := -ansi -DST_DIV0=0x02
6245-ccflags-y := -Werror
6246+#ccflags-y := -Werror
6247
6248 lib-$(CONFIG_SPARC32) += ashrdi3.o
6249 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6250diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6251index 4d502da..527c48d 100644
6252--- a/arch/sparc/lib/atomic_64.S
6253+++ b/arch/sparc/lib/atomic_64.S
6254@@ -17,7 +17,12 @@
6255 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6256 BACKOFF_SETUP(%o2)
6257 1: lduw [%o1], %g1
6258- add %g1, %o0, %g7
6259+ addcc %g1, %o0, %g7
6260+
6261+#ifdef CONFIG_PAX_REFCOUNT
6262+ tvs %icc, 6
6263+#endif
6264+
6265 cas [%o1], %g1, %g7
6266 cmp %g1, %g7
6267 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6268@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6269 2: BACKOFF_SPIN(%o2, %o3, 1b)
6270 ENDPROC(atomic_add)
6271
6272+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6273+ BACKOFF_SETUP(%o2)
6274+1: lduw [%o1], %g1
6275+ add %g1, %o0, %g7
6276+ cas [%o1], %g1, %g7
6277+ cmp %g1, %g7
6278+ bne,pn %icc, 2f
6279+ nop
6280+ retl
6281+ nop
6282+2: BACKOFF_SPIN(%o2, %o3, 1b)
6283+ENDPROC(atomic_add_unchecked)
6284+
6285 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6286 BACKOFF_SETUP(%o2)
6287 1: lduw [%o1], %g1
6288- sub %g1, %o0, %g7
6289+ subcc %g1, %o0, %g7
6290+
6291+#ifdef CONFIG_PAX_REFCOUNT
6292+ tvs %icc, 6
6293+#endif
6294+
6295 cas [%o1], %g1, %g7
6296 cmp %g1, %g7
6297 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6298@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6299 2: BACKOFF_SPIN(%o2, %o3, 1b)
6300 ENDPROC(atomic_sub)
6301
6302+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6303+ BACKOFF_SETUP(%o2)
6304+1: lduw [%o1], %g1
6305+ sub %g1, %o0, %g7
6306+ cas [%o1], %g1, %g7
6307+ cmp %g1, %g7
6308+ bne,pn %icc, 2f
6309+ nop
6310+ retl
6311+ nop
6312+2: BACKOFF_SPIN(%o2, %o3, 1b)
6313+ENDPROC(atomic_sub_unchecked)
6314+
6315 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6316 BACKOFF_SETUP(%o2)
6317 1: lduw [%o1], %g1
6318- add %g1, %o0, %g7
6319+ addcc %g1, %o0, %g7
6320+
6321+#ifdef CONFIG_PAX_REFCOUNT
6322+ tvs %icc, 6
6323+#endif
6324+
6325 cas [%o1], %g1, %g7
6326 cmp %g1, %g7
6327 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6328@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6329 2: BACKOFF_SPIN(%o2, %o3, 1b)
6330 ENDPROC(atomic_add_ret)
6331
6332+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6333+ BACKOFF_SETUP(%o2)
6334+1: lduw [%o1], %g1
6335+ addcc %g1, %o0, %g7
6336+ cas [%o1], %g1, %g7
6337+ cmp %g1, %g7
6338+ bne,pn %icc, 2f
6339+ add %g7, %o0, %g7
6340+ sra %g7, 0, %o0
6341+ retl
6342+ nop
6343+2: BACKOFF_SPIN(%o2, %o3, 1b)
6344+ENDPROC(atomic_add_ret_unchecked)
6345+
6346 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6347 BACKOFF_SETUP(%o2)
6348 1: lduw [%o1], %g1
6349- sub %g1, %o0, %g7
6350+ subcc %g1, %o0, %g7
6351+
6352+#ifdef CONFIG_PAX_REFCOUNT
6353+ tvs %icc, 6
6354+#endif
6355+
6356 cas [%o1], %g1, %g7
6357 cmp %g1, %g7
6358 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6359@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
6360 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6361 BACKOFF_SETUP(%o2)
6362 1: ldx [%o1], %g1
6363- add %g1, %o0, %g7
6364+ addcc %g1, %o0, %g7
6365+
6366+#ifdef CONFIG_PAX_REFCOUNT
6367+ tvs %xcc, 6
6368+#endif
6369+
6370 casx [%o1], %g1, %g7
6371 cmp %g1, %g7
6372 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6373@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6374 2: BACKOFF_SPIN(%o2, %o3, 1b)
6375 ENDPROC(atomic64_add)
6376
6377+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6378+ BACKOFF_SETUP(%o2)
6379+1: ldx [%o1], %g1
6380+ addcc %g1, %o0, %g7
6381+ casx [%o1], %g1, %g7
6382+ cmp %g1, %g7
6383+ bne,pn %xcc, 2f
6384+ nop
6385+ retl
6386+ nop
6387+2: BACKOFF_SPIN(%o2, %o3, 1b)
6388+ENDPROC(atomic64_add_unchecked)
6389+
6390 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6391 BACKOFF_SETUP(%o2)
6392 1: ldx [%o1], %g1
6393- sub %g1, %o0, %g7
6394+ subcc %g1, %o0, %g7
6395+
6396+#ifdef CONFIG_PAX_REFCOUNT
6397+ tvs %xcc, 6
6398+#endif
6399+
6400 casx [%o1], %g1, %g7
6401 cmp %g1, %g7
6402 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6403@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6404 2: BACKOFF_SPIN(%o2, %o3, 1b)
6405 ENDPROC(atomic64_sub)
6406
6407+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6408+ BACKOFF_SETUP(%o2)
6409+1: ldx [%o1], %g1
6410+ subcc %g1, %o0, %g7
6411+ casx [%o1], %g1, %g7
6412+ cmp %g1, %g7
6413+ bne,pn %xcc, 2f
6414+ nop
6415+ retl
6416+ nop
6417+2: BACKOFF_SPIN(%o2, %o3, 1b)
6418+ENDPROC(atomic64_sub_unchecked)
6419+
6420 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6421 BACKOFF_SETUP(%o2)
6422 1: ldx [%o1], %g1
6423- add %g1, %o0, %g7
6424+ addcc %g1, %o0, %g7
6425+
6426+#ifdef CONFIG_PAX_REFCOUNT
6427+ tvs %xcc, 6
6428+#endif
6429+
6430 casx [%o1], %g1, %g7
6431 cmp %g1, %g7
6432 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6433@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6434 2: BACKOFF_SPIN(%o2, %o3, 1b)
6435 ENDPROC(atomic64_add_ret)
6436
6437+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6438+ BACKOFF_SETUP(%o2)
6439+1: ldx [%o1], %g1
6440+ addcc %g1, %o0, %g7
6441+ casx [%o1], %g1, %g7
6442+ cmp %g1, %g7
6443+ bne,pn %xcc, 2f
6444+ add %g7, %o0, %g7
6445+ mov %g7, %o0
6446+ retl
6447+ nop
6448+2: BACKOFF_SPIN(%o2, %o3, 1b)
6449+ENDPROC(atomic64_add_ret_unchecked)
6450+
6451 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6452 BACKOFF_SETUP(%o2)
6453 1: ldx [%o1], %g1
6454- sub %g1, %o0, %g7
6455+ subcc %g1, %o0, %g7
6456+
6457+#ifdef CONFIG_PAX_REFCOUNT
6458+ tvs %xcc, 6
6459+#endif
6460+
6461 casx [%o1], %g1, %g7
6462 cmp %g1, %g7
6463 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6464diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6465index 3b31218..345c609 100644
6466--- a/arch/sparc/lib/ksyms.c
6467+++ b/arch/sparc/lib/ksyms.c
6468@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
6469
6470 /* Atomic counter implementation. */
6471 EXPORT_SYMBOL(atomic_add);
6472+EXPORT_SYMBOL(atomic_add_unchecked);
6473 EXPORT_SYMBOL(atomic_add_ret);
6474+EXPORT_SYMBOL(atomic_add_ret_unchecked);
6475 EXPORT_SYMBOL(atomic_sub);
6476+EXPORT_SYMBOL(atomic_sub_unchecked);
6477 EXPORT_SYMBOL(atomic_sub_ret);
6478 EXPORT_SYMBOL(atomic64_add);
6479+EXPORT_SYMBOL(atomic64_add_unchecked);
6480 EXPORT_SYMBOL(atomic64_add_ret);
6481+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6482 EXPORT_SYMBOL(atomic64_sub);
6483+EXPORT_SYMBOL(atomic64_sub_unchecked);
6484 EXPORT_SYMBOL(atomic64_sub_ret);
6485
6486 /* Atomic bit operations. */
6487diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6488index 30c3ecc..736f015 100644
6489--- a/arch/sparc/mm/Makefile
6490+++ b/arch/sparc/mm/Makefile
6491@@ -2,7 +2,7 @@
6492 #
6493
6494 asflags-y := -ansi
6495-ccflags-y := -Werror
6496+#ccflags-y := -Werror
6497
6498 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6499 obj-y += fault_$(BITS).o
6500diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6501index f46cf6b..cc0666bae 100644
6502--- a/arch/sparc/mm/fault_32.c
6503+++ b/arch/sparc/mm/fault_32.c
6504@@ -21,6 +21,9 @@
6505 #include <linux/perf_event.h>
6506 #include <linux/interrupt.h>
6507 #include <linux/kdebug.h>
6508+#include <linux/slab.h>
6509+#include <linux/pagemap.h>
6510+#include <linux/compiler.h>
6511
6512 #include <asm/page.h>
6513 #include <asm/pgtable.h>
6514@@ -177,6 +180,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6515 return safe_compute_effective_address(regs, insn);
6516 }
6517
6518+#ifdef CONFIG_PAX_PAGEEXEC
6519+#ifdef CONFIG_PAX_DLRESOLVE
6520+static void pax_emuplt_close(struct vm_area_struct *vma)
6521+{
6522+ vma->vm_mm->call_dl_resolve = 0UL;
6523+}
6524+
6525+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6526+{
6527+ unsigned int *kaddr;
6528+
6529+ vmf->page = alloc_page(GFP_HIGHUSER);
6530+ if (!vmf->page)
6531+ return VM_FAULT_OOM;
6532+
6533+ kaddr = kmap(vmf->page);
6534+ memset(kaddr, 0, PAGE_SIZE);
6535+ kaddr[0] = 0x9DE3BFA8U; /* save */
6536+ flush_dcache_page(vmf->page);
6537+ kunmap(vmf->page);
6538+ return VM_FAULT_MAJOR;
6539+}
6540+
6541+static const struct vm_operations_struct pax_vm_ops = {
6542+ .close = pax_emuplt_close,
6543+ .fault = pax_emuplt_fault
6544+};
6545+
6546+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6547+{
6548+ int ret;
6549+
6550+ INIT_LIST_HEAD(&vma->anon_vma_chain);
6551+ vma->vm_mm = current->mm;
6552+ vma->vm_start = addr;
6553+ vma->vm_end = addr + PAGE_SIZE;
6554+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6555+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6556+ vma->vm_ops = &pax_vm_ops;
6557+
6558+ ret = insert_vm_struct(current->mm, vma);
6559+ if (ret)
6560+ return ret;
6561+
6562+ ++current->mm->total_vm;
6563+ return 0;
6564+}
6565+#endif
6566+
6567+/*
6568+ * PaX: decide what to do with offenders (regs->pc = fault address)
6569+ *
6570+ * returns 1 when task should be killed
6571+ * 2 when patched PLT trampoline was detected
6572+ * 3 when unpatched PLT trampoline was detected
6573+ */
6574+static int pax_handle_fetch_fault(struct pt_regs *regs)
6575+{
6576+
6577+#ifdef CONFIG_PAX_EMUPLT
6578+ int err;
6579+
6580+ do { /* PaX: patched PLT emulation #1 */
6581+ unsigned int sethi1, sethi2, jmpl;
6582+
6583+ err = get_user(sethi1, (unsigned int *)regs->pc);
6584+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6585+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6586+
6587+ if (err)
6588+ break;
6589+
6590+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6591+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
6592+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
6593+ {
6594+ unsigned int addr;
6595+
6596+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6597+ addr = regs->u_regs[UREG_G1];
6598+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6599+ regs->pc = addr;
6600+ regs->npc = addr+4;
6601+ return 2;
6602+ }
6603+ } while (0);
6604+
6605+ do { /* PaX: patched PLT emulation #2 */
6606+ unsigned int ba;
6607+
6608+ err = get_user(ba, (unsigned int *)regs->pc);
6609+
6610+ if (err)
6611+ break;
6612+
6613+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6614+ unsigned int addr;
6615+
6616+ if ((ba & 0xFFC00000U) == 0x30800000U)
6617+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6618+ else
6619+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6620+ regs->pc = addr;
6621+ regs->npc = addr+4;
6622+ return 2;
6623+ }
6624+ } while (0);
6625+
6626+ do { /* PaX: patched PLT emulation #3 */
6627+ unsigned int sethi, bajmpl, nop;
6628+
6629+ err = get_user(sethi, (unsigned int *)regs->pc);
6630+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
6631+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
6632+
6633+ if (err)
6634+ break;
6635+
6636+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6637+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6638+ nop == 0x01000000U)
6639+ {
6640+ unsigned int addr;
6641+
6642+ addr = (sethi & 0x003FFFFFU) << 10;
6643+ regs->u_regs[UREG_G1] = addr;
6644+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6645+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6646+ else
6647+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6648+ regs->pc = addr;
6649+ regs->npc = addr+4;
6650+ return 2;
6651+ }
6652+ } while (0);
6653+
6654+ do { /* PaX: unpatched PLT emulation step 1 */
6655+ unsigned int sethi, ba, nop;
6656+
6657+ err = get_user(sethi, (unsigned int *)regs->pc);
6658+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
6659+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
6660+
6661+ if (err)
6662+ break;
6663+
6664+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6665+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6666+ nop == 0x01000000U)
6667+ {
6668+ unsigned int addr, save, call;
6669+
6670+ if ((ba & 0xFFC00000U) == 0x30800000U)
6671+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6672+ else
6673+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6674+
6675+ err = get_user(save, (unsigned int *)addr);
6676+ err |= get_user(call, (unsigned int *)(addr+4));
6677+ err |= get_user(nop, (unsigned int *)(addr+8));
6678+ if (err)
6679+ break;
6680+
6681+#ifdef CONFIG_PAX_DLRESOLVE
6682+ if (save == 0x9DE3BFA8U &&
6683+ (call & 0xC0000000U) == 0x40000000U &&
6684+ nop == 0x01000000U)
6685+ {
6686+ struct vm_area_struct *vma;
6687+ unsigned long call_dl_resolve;
6688+
6689+ down_read(&current->mm->mmap_sem);
6690+ call_dl_resolve = current->mm->call_dl_resolve;
6691+ up_read(&current->mm->mmap_sem);
6692+ if (likely(call_dl_resolve))
6693+ goto emulate;
6694+
6695+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6696+
6697+ down_write(&current->mm->mmap_sem);
6698+ if (current->mm->call_dl_resolve) {
6699+ call_dl_resolve = current->mm->call_dl_resolve;
6700+ up_write(&current->mm->mmap_sem);
6701+ if (vma)
6702+ kmem_cache_free(vm_area_cachep, vma);
6703+ goto emulate;
6704+ }
6705+
6706+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6707+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6708+ up_write(&current->mm->mmap_sem);
6709+ if (vma)
6710+ kmem_cache_free(vm_area_cachep, vma);
6711+ return 1;
6712+ }
6713+
6714+ if (pax_insert_vma(vma, call_dl_resolve)) {
6715+ up_write(&current->mm->mmap_sem);
6716+ kmem_cache_free(vm_area_cachep, vma);
6717+ return 1;
6718+ }
6719+
6720+ current->mm->call_dl_resolve = call_dl_resolve;
6721+ up_write(&current->mm->mmap_sem);
6722+
6723+emulate:
6724+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6725+ regs->pc = call_dl_resolve;
6726+ regs->npc = addr+4;
6727+ return 3;
6728+ }
6729+#endif
6730+
6731+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6732+ if ((save & 0xFFC00000U) == 0x05000000U &&
6733+ (call & 0xFFFFE000U) == 0x85C0A000U &&
6734+ nop == 0x01000000U)
6735+ {
6736+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6737+ regs->u_regs[UREG_G2] = addr + 4;
6738+ addr = (save & 0x003FFFFFU) << 10;
6739+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6740+ regs->pc = addr;
6741+ regs->npc = addr+4;
6742+ return 3;
6743+ }
6744+ }
6745+ } while (0);
6746+
6747+ do { /* PaX: unpatched PLT emulation step 2 */
6748+ unsigned int save, call, nop;
6749+
6750+ err = get_user(save, (unsigned int *)(regs->pc-4));
6751+ err |= get_user(call, (unsigned int *)regs->pc);
6752+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
6753+ if (err)
6754+ break;
6755+
6756+ if (save == 0x9DE3BFA8U &&
6757+ (call & 0xC0000000U) == 0x40000000U &&
6758+ nop == 0x01000000U)
6759+ {
6760+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6761+
6762+ regs->u_regs[UREG_RETPC] = regs->pc;
6763+ regs->pc = dl_resolve;
6764+ regs->npc = dl_resolve+4;
6765+ return 3;
6766+ }
6767+ } while (0);
6768+#endif
6769+
6770+ return 1;
6771+}
6772+
6773+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6774+{
6775+ unsigned long i;
6776+
6777+ printk(KERN_ERR "PAX: bytes at PC: ");
6778+ for (i = 0; i < 8; i++) {
6779+ unsigned int c;
6780+ if (get_user(c, (unsigned int *)pc+i))
6781+ printk(KERN_CONT "???????? ");
6782+ else
6783+ printk(KERN_CONT "%08x ", c);
6784+ }
6785+ printk("\n");
6786+}
6787+#endif
6788+
6789 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6790 int text_fault)
6791 {
6792@@ -248,6 +522,24 @@ good_area:
6793 if (!(vma->vm_flags & VM_WRITE))
6794 goto bad_area;
6795 } else {
6796+
6797+#ifdef CONFIG_PAX_PAGEEXEC
6798+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6799+ up_read(&mm->mmap_sem);
6800+ switch (pax_handle_fetch_fault(regs)) {
6801+
6802+#ifdef CONFIG_PAX_EMUPLT
6803+ case 2:
6804+ case 3:
6805+ return;
6806+#endif
6807+
6808+ }
6809+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6810+ do_group_exit(SIGKILL);
6811+ }
6812+#endif
6813+
6814 /* Allow reads even for write-only mappings */
6815 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
6816 goto bad_area;
6817diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6818index 1fe0429..8dd5dd5 100644
6819--- a/arch/sparc/mm/fault_64.c
6820+++ b/arch/sparc/mm/fault_64.c
6821@@ -21,6 +21,9 @@
6822 #include <linux/kprobes.h>
6823 #include <linux/kdebug.h>
6824 #include <linux/percpu.h>
6825+#include <linux/slab.h>
6826+#include <linux/pagemap.h>
6827+#include <linux/compiler.h>
6828
6829 #include <asm/page.h>
6830 #include <asm/pgtable.h>
6831@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6832 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6833 regs->tpc);
6834 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6835- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6836+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6837 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6838 dump_stack();
6839 unhandled_fault(regs->tpc, current, regs);
6840@@ -272,6 +275,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6841 show_regs(regs);
6842 }
6843
6844+#ifdef CONFIG_PAX_PAGEEXEC
6845+#ifdef CONFIG_PAX_DLRESOLVE
6846+static void pax_emuplt_close(struct vm_area_struct *vma)
6847+{
6848+ vma->vm_mm->call_dl_resolve = 0UL;
6849+}
6850+
6851+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6852+{
6853+ unsigned int *kaddr;
6854+
6855+ vmf->page = alloc_page(GFP_HIGHUSER);
6856+ if (!vmf->page)
6857+ return VM_FAULT_OOM;
6858+
6859+ kaddr = kmap(vmf->page);
6860+ memset(kaddr, 0, PAGE_SIZE);
6861+ kaddr[0] = 0x9DE3BFA8U; /* save */
6862+ flush_dcache_page(vmf->page);
6863+ kunmap(vmf->page);
6864+ return VM_FAULT_MAJOR;
6865+}
6866+
6867+static const struct vm_operations_struct pax_vm_ops = {
6868+ .close = pax_emuplt_close,
6869+ .fault = pax_emuplt_fault
6870+};
6871+
6872+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6873+{
6874+ int ret;
6875+
6876+ INIT_LIST_HEAD(&vma->anon_vma_chain);
6877+ vma->vm_mm = current->mm;
6878+ vma->vm_start = addr;
6879+ vma->vm_end = addr + PAGE_SIZE;
6880+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6881+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6882+ vma->vm_ops = &pax_vm_ops;
6883+
6884+ ret = insert_vm_struct(current->mm, vma);
6885+ if (ret)
6886+ return ret;
6887+
6888+ ++current->mm->total_vm;
6889+ return 0;
6890+}
6891+#endif
6892+
6893+/*
6894+ * PaX: decide what to do with offenders (regs->tpc = fault address)
6895+ *
6896+ * returns 1 when task should be killed
6897+ * 2 when patched PLT trampoline was detected
6898+ * 3 when unpatched PLT trampoline was detected
6899+ */
6900+static int pax_handle_fetch_fault(struct pt_regs *regs)
6901+{
6902+
6903+#ifdef CONFIG_PAX_EMUPLT
6904+ int err;
6905+
6906+ do { /* PaX: patched PLT emulation #1 */
6907+ unsigned int sethi1, sethi2, jmpl;
6908+
6909+ err = get_user(sethi1, (unsigned int *)regs->tpc);
6910+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6911+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6912+
6913+ if (err)
6914+ break;
6915+
6916+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6917+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
6918+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
6919+ {
6920+ unsigned long addr;
6921+
6922+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6923+ addr = regs->u_regs[UREG_G1];
6924+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6925+
6926+ if (test_thread_flag(TIF_32BIT))
6927+ addr &= 0xFFFFFFFFUL;
6928+
6929+ regs->tpc = addr;
6930+ regs->tnpc = addr+4;
6931+ return 2;
6932+ }
6933+ } while (0);
6934+
6935+ do { /* PaX: patched PLT emulation #2 */
6936+ unsigned int ba;
6937+
6938+ err = get_user(ba, (unsigned int *)regs->tpc);
6939+
6940+ if (err)
6941+ break;
6942+
6943+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6944+ unsigned long addr;
6945+
6946+ if ((ba & 0xFFC00000U) == 0x30800000U)
6947+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6948+ else
6949+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6950+
6951+ if (test_thread_flag(TIF_32BIT))
6952+ addr &= 0xFFFFFFFFUL;
6953+
6954+ regs->tpc = addr;
6955+ regs->tnpc = addr+4;
6956+ return 2;
6957+ }
6958+ } while (0);
6959+
6960+ do { /* PaX: patched PLT emulation #3 */
6961+ unsigned int sethi, bajmpl, nop;
6962+
6963+ err = get_user(sethi, (unsigned int *)regs->tpc);
6964+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
6965+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6966+
6967+ if (err)
6968+ break;
6969+
6970+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
6971+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6972+ nop == 0x01000000U)
6973+ {
6974+ unsigned long addr;
6975+
6976+ addr = (sethi & 0x003FFFFFU) << 10;
6977+ regs->u_regs[UREG_G1] = addr;
6978+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6979+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6980+ else
6981+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6982+
6983+ if (test_thread_flag(TIF_32BIT))
6984+ addr &= 0xFFFFFFFFUL;
6985+
6986+ regs->tpc = addr;
6987+ regs->tnpc = addr+4;
6988+ return 2;
6989+ }
6990+ } while (0);
6991+
6992+ do { /* PaX: patched PLT emulation #4 */
6993+ unsigned int sethi, mov1, call, mov2;
6994+
6995+ err = get_user(sethi, (unsigned int *)regs->tpc);
6996+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6997+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
6998+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6999+
7000+ if (err)
7001+ break;
7002+
7003+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7004+ mov1 == 0x8210000FU &&
7005+ (call & 0xC0000000U) == 0x40000000U &&
7006+ mov2 == 0x9E100001U)
7007+ {
7008+ unsigned long addr;
7009+
7010+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
7011+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7012+
7013+ if (test_thread_flag(TIF_32BIT))
7014+ addr &= 0xFFFFFFFFUL;
7015+
7016+ regs->tpc = addr;
7017+ regs->tnpc = addr+4;
7018+ return 2;
7019+ }
7020+ } while (0);
7021+
7022+ do { /* PaX: patched PLT emulation #5 */
7023+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
7024+
7025+ err = get_user(sethi, (unsigned int *)regs->tpc);
7026+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7027+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7028+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
7029+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
7030+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
7031+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
7032+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
7033+
7034+ if (err)
7035+ break;
7036+
7037+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7038+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
7039+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7040+ (or1 & 0xFFFFE000U) == 0x82106000U &&
7041+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
7042+ sllx == 0x83287020U &&
7043+ jmpl == 0x81C04005U &&
7044+ nop == 0x01000000U)
7045+ {
7046+ unsigned long addr;
7047+
7048+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7049+ regs->u_regs[UREG_G1] <<= 32;
7050+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7051+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7052+ regs->tpc = addr;
7053+ regs->tnpc = addr+4;
7054+ return 2;
7055+ }
7056+ } while (0);
7057+
7058+ do { /* PaX: patched PLT emulation #6 */
7059+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7060+
7061+ err = get_user(sethi, (unsigned int *)regs->tpc);
7062+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7063+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7064+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7065+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
7066+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7067+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7068+
7069+ if (err)
7070+ break;
7071+
7072+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7073+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
7074+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7075+ sllx == 0x83287020U &&
7076+ (or & 0xFFFFE000U) == 0x8A116000U &&
7077+ jmpl == 0x81C04005U &&
7078+ nop == 0x01000000U)
7079+ {
7080+ unsigned long addr;
7081+
7082+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7083+ regs->u_regs[UREG_G1] <<= 32;
7084+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7085+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7086+ regs->tpc = addr;
7087+ regs->tnpc = addr+4;
7088+ return 2;
7089+ }
7090+ } while (0);
7091+
7092+ do { /* PaX: unpatched PLT emulation step 1 */
7093+ unsigned int sethi, ba, nop;
7094+
7095+ err = get_user(sethi, (unsigned int *)regs->tpc);
7096+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7097+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7098+
7099+ if (err)
7100+ break;
7101+
7102+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7103+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7104+ nop == 0x01000000U)
7105+ {
7106+ unsigned long addr;
7107+ unsigned int save, call;
7108+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7109+
7110+ if ((ba & 0xFFC00000U) == 0x30800000U)
7111+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7112+ else
7113+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7114+
7115+ if (test_thread_flag(TIF_32BIT))
7116+ addr &= 0xFFFFFFFFUL;
7117+
7118+ err = get_user(save, (unsigned int *)addr);
7119+ err |= get_user(call, (unsigned int *)(addr+4));
7120+ err |= get_user(nop, (unsigned int *)(addr+8));
7121+ if (err)
7122+ break;
7123+
7124+#ifdef CONFIG_PAX_DLRESOLVE
7125+ if (save == 0x9DE3BFA8U &&
7126+ (call & 0xC0000000U) == 0x40000000U &&
7127+ nop == 0x01000000U)
7128+ {
7129+ struct vm_area_struct *vma;
7130+ unsigned long call_dl_resolve;
7131+
7132+ down_read(&current->mm->mmap_sem);
7133+ call_dl_resolve = current->mm->call_dl_resolve;
7134+ up_read(&current->mm->mmap_sem);
7135+ if (likely(call_dl_resolve))
7136+ goto emulate;
7137+
7138+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7139+
7140+ down_write(&current->mm->mmap_sem);
7141+ if (current->mm->call_dl_resolve) {
7142+ call_dl_resolve = current->mm->call_dl_resolve;
7143+ up_write(&current->mm->mmap_sem);
7144+ if (vma)
7145+ kmem_cache_free(vm_area_cachep, vma);
7146+ goto emulate;
7147+ }
7148+
7149+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7150+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7151+ up_write(&current->mm->mmap_sem);
7152+ if (vma)
7153+ kmem_cache_free(vm_area_cachep, vma);
7154+ return 1;
7155+ }
7156+
7157+ if (pax_insert_vma(vma, call_dl_resolve)) {
7158+ up_write(&current->mm->mmap_sem);
7159+ kmem_cache_free(vm_area_cachep, vma);
7160+ return 1;
7161+ }
7162+
7163+ current->mm->call_dl_resolve = call_dl_resolve;
7164+ up_write(&current->mm->mmap_sem);
7165+
7166+emulate:
7167+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7168+ regs->tpc = call_dl_resolve;
7169+ regs->tnpc = addr+4;
7170+ return 3;
7171+ }
7172+#endif
7173+
7174+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7175+ if ((save & 0xFFC00000U) == 0x05000000U &&
7176+ (call & 0xFFFFE000U) == 0x85C0A000U &&
7177+ nop == 0x01000000U)
7178+ {
7179+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7180+ regs->u_regs[UREG_G2] = addr + 4;
7181+ addr = (save & 0x003FFFFFU) << 10;
7182+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7183+
7184+ if (test_thread_flag(TIF_32BIT))
7185+ addr &= 0xFFFFFFFFUL;
7186+
7187+ regs->tpc = addr;
7188+ regs->tnpc = addr+4;
7189+ return 3;
7190+ }
7191+
7192+ /* PaX: 64-bit PLT stub */
7193+ err = get_user(sethi1, (unsigned int *)addr);
7194+ err |= get_user(sethi2, (unsigned int *)(addr+4));
7195+ err |= get_user(or1, (unsigned int *)(addr+8));
7196+ err |= get_user(or2, (unsigned int *)(addr+12));
7197+ err |= get_user(sllx, (unsigned int *)(addr+16));
7198+ err |= get_user(add, (unsigned int *)(addr+20));
7199+ err |= get_user(jmpl, (unsigned int *)(addr+24));
7200+ err |= get_user(nop, (unsigned int *)(addr+28));
7201+ if (err)
7202+ break;
7203+
7204+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7205+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7206+ (or1 & 0xFFFFE000U) == 0x88112000U &&
7207+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
7208+ sllx == 0x89293020U &&
7209+ add == 0x8A010005U &&
7210+ jmpl == 0x89C14000U &&
7211+ nop == 0x01000000U)
7212+ {
7213+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7214+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7215+ regs->u_regs[UREG_G4] <<= 32;
7216+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7217+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7218+ regs->u_regs[UREG_G4] = addr + 24;
7219+ addr = regs->u_regs[UREG_G5];
7220+ regs->tpc = addr;
7221+ regs->tnpc = addr+4;
7222+ return 3;
7223+ }
7224+ }
7225+ } while (0);
7226+
7227+#ifdef CONFIG_PAX_DLRESOLVE
7228+ do { /* PaX: unpatched PLT emulation step 2 */
7229+ unsigned int save, call, nop;
7230+
7231+ err = get_user(save, (unsigned int *)(regs->tpc-4));
7232+ err |= get_user(call, (unsigned int *)regs->tpc);
7233+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7234+ if (err)
7235+ break;
7236+
7237+ if (save == 0x9DE3BFA8U &&
7238+ (call & 0xC0000000U) == 0x40000000U &&
7239+ nop == 0x01000000U)
7240+ {
7241+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7242+
7243+ if (test_thread_flag(TIF_32BIT))
7244+ dl_resolve &= 0xFFFFFFFFUL;
7245+
7246+ regs->u_regs[UREG_RETPC] = regs->tpc;
7247+ regs->tpc = dl_resolve;
7248+ regs->tnpc = dl_resolve+4;
7249+ return 3;
7250+ }
7251+ } while (0);
7252+#endif
7253+
7254+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7255+ unsigned int sethi, ba, nop;
7256+
7257+ err = get_user(sethi, (unsigned int *)regs->tpc);
7258+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7259+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7260+
7261+ if (err)
7262+ break;
7263+
7264+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7265+ (ba & 0xFFF00000U) == 0x30600000U &&
7266+ nop == 0x01000000U)
7267+ {
7268+ unsigned long addr;
7269+
7270+ addr = (sethi & 0x003FFFFFU) << 10;
7271+ regs->u_regs[UREG_G1] = addr;
7272+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7273+
7274+ if (test_thread_flag(TIF_32BIT))
7275+ addr &= 0xFFFFFFFFUL;
7276+
7277+ regs->tpc = addr;
7278+ regs->tnpc = addr+4;
7279+ return 2;
7280+ }
7281+ } while (0);
7282+
7283+#endif
7284+
7285+ return 1;
7286+}
7287+
7288+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7289+{
7290+ unsigned long i;
7291+
7292+ printk(KERN_ERR "PAX: bytes at PC: ");
7293+ for (i = 0; i < 8; i++) {
7294+ unsigned int c;
7295+ if (get_user(c, (unsigned int *)pc+i))
7296+ printk(KERN_CONT "???????? ");
7297+ else
7298+ printk(KERN_CONT "%08x ", c);
7299+ }
7300+ printk("\n");
7301+}
7302+#endif
7303+
7304 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7305 {
7306 struct mm_struct *mm = current->mm;
7307@@ -343,6 +806,29 @@ retry:
7308 if (!vma)
7309 goto bad_area;
7310
7311+#ifdef CONFIG_PAX_PAGEEXEC
7312+ /* PaX: detect ITLB misses on non-exec pages */
7313+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7314+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7315+ {
7316+ if (address != regs->tpc)
7317+ goto good_area;
7318+
7319+ up_read(&mm->mmap_sem);
7320+ switch (pax_handle_fetch_fault(regs)) {
7321+
7322+#ifdef CONFIG_PAX_EMUPLT
7323+ case 2:
7324+ case 3:
7325+ return;
7326+#endif
7327+
7328+ }
7329+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7330+ do_group_exit(SIGKILL);
7331+ }
7332+#endif
7333+
7334 /* Pure DTLB misses do not tell us whether the fault causing
7335 * load/store/atomic was a write or not, it only says that there
7336 * was no match. So in such a case we (carefully) read the
7337diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7338index 07e1453..0a7d9e9 100644
7339--- a/arch/sparc/mm/hugetlbpage.c
7340+++ b/arch/sparc/mm/hugetlbpage.c
7341@@ -67,7 +67,7 @@ full_search:
7342 }
7343 return -ENOMEM;
7344 }
7345- if (likely(!vma || addr + len <= vma->vm_start)) {
7346+ if (likely(check_heap_stack_gap(vma, addr, len))) {
7347 /*
7348 * Remember the place where we stopped the search:
7349 */
7350@@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7351 /* make sure it can fit in the remaining address space */
7352 if (likely(addr > len)) {
7353 vma = find_vma(mm, addr-len);
7354- if (!vma || addr <= vma->vm_start) {
7355+ if (check_heap_stack_gap(vma, addr - len, len)) {
7356 /* remember the address as a hint for next time */
7357 return (mm->free_area_cache = addr-len);
7358 }
7359@@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7360 if (unlikely(mm->mmap_base < len))
7361 goto bottomup;
7362
7363- addr = (mm->mmap_base-len) & HPAGE_MASK;
7364+ addr = mm->mmap_base - len;
7365
7366 do {
7367+ addr &= HPAGE_MASK;
7368 /*
7369 * Lookup failure means no vma is above this address,
7370 * else if new region fits below vma->vm_start,
7371 * return with success:
7372 */
7373 vma = find_vma(mm, addr);
7374- if (likely(!vma || addr+len <= vma->vm_start)) {
7375+ if (likely(check_heap_stack_gap(vma, addr, len))) {
7376 /* remember the address as a hint for next time */
7377 return (mm->free_area_cache = addr);
7378 }
7379@@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7380 mm->cached_hole_size = vma->vm_start - addr;
7381
7382 /* try just below the current vma->vm_start */
7383- addr = (vma->vm_start-len) & HPAGE_MASK;
7384- } while (likely(len < vma->vm_start));
7385+ addr = skip_heap_stack_gap(vma, len);
7386+ } while (!IS_ERR_VALUE(addr));
7387
7388 bottomup:
7389 /*
7390@@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7391 if (addr) {
7392 addr = ALIGN(addr, HPAGE_SIZE);
7393 vma = find_vma(mm, addr);
7394- if (task_size - len >= addr &&
7395- (!vma || addr + len <= vma->vm_start))
7396+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7397 return addr;
7398 }
7399 if (mm->get_unmapped_area == arch_get_unmapped_area)
7400diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7401index f4500c6..889656c 100644
7402--- a/arch/tile/include/asm/atomic_64.h
7403+++ b/arch/tile/include/asm/atomic_64.h
7404@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7405
7406 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7407
7408+#define atomic64_read_unchecked(v) atomic64_read(v)
7409+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7410+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7411+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7412+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7413+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7414+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7415+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7416+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7417+
7418 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7419 #define smp_mb__before_atomic_dec() smp_mb()
7420 #define smp_mb__after_atomic_dec() smp_mb()
7421diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7422index 392e533..536b092 100644
7423--- a/arch/tile/include/asm/cache.h
7424+++ b/arch/tile/include/asm/cache.h
7425@@ -15,11 +15,12 @@
7426 #ifndef _ASM_TILE_CACHE_H
7427 #define _ASM_TILE_CACHE_H
7428
7429+#include <linux/const.h>
7430 #include <arch/chip.h>
7431
7432 /* bytes per L1 data cache line */
7433 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7434-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7435+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7436
7437 /* bytes per L2 cache line */
7438 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7439diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
7440index 9ab078a..d6635c2 100644
7441--- a/arch/tile/include/asm/uaccess.h
7442+++ b/arch/tile/include/asm/uaccess.h
7443@@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
7444 const void __user *from,
7445 unsigned long n)
7446 {
7447- int sz = __compiletime_object_size(to);
7448+ size_t sz = __compiletime_object_size(to);
7449
7450- if (likely(sz == -1 || sz >= n))
7451+ if (likely(sz == (size_t)-1 || sz >= n))
7452 n = _copy_from_user(to, from, n);
7453 else
7454 copy_from_user_overflow();
7455diff --git a/arch/um/Makefile b/arch/um/Makefile
7456index 0970910..13adb57a 100644
7457--- a/arch/um/Makefile
7458+++ b/arch/um/Makefile
7459@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7460 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7461 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7462
7463+ifdef CONSTIFY_PLUGIN
7464+USER_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7465+endif
7466+
7467 #This will adjust *FLAGS accordingly to the platform.
7468 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7469
7470diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7471index 19e1bdd..3665b77 100644
7472--- a/arch/um/include/asm/cache.h
7473+++ b/arch/um/include/asm/cache.h
7474@@ -1,6 +1,7 @@
7475 #ifndef __UM_CACHE_H
7476 #define __UM_CACHE_H
7477
7478+#include <linux/const.h>
7479
7480 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7481 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7482@@ -12,6 +13,6 @@
7483 # define L1_CACHE_SHIFT 5
7484 #endif
7485
7486-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7487+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7488
7489 #endif
7490diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7491index 6c03acd..a5e0215 100644
7492--- a/arch/um/include/asm/kmap_types.h
7493+++ b/arch/um/include/asm/kmap_types.h
7494@@ -23,6 +23,7 @@ enum km_type {
7495 KM_IRQ1,
7496 KM_SOFTIRQ0,
7497 KM_SOFTIRQ1,
7498+ KM_CLEARPAGE,
7499 KM_TYPE_NR
7500 };
7501
7502diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7503index 7cfc3ce..cbd1a58 100644
7504--- a/arch/um/include/asm/page.h
7505+++ b/arch/um/include/asm/page.h
7506@@ -14,6 +14,9 @@
7507 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7508 #define PAGE_MASK (~(PAGE_SIZE-1))
7509
7510+#define ktla_ktva(addr) (addr)
7511+#define ktva_ktla(addr) (addr)
7512+
7513 #ifndef __ASSEMBLY__
7514
7515 struct page;
7516diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7517index 0032f92..cd151e0 100644
7518--- a/arch/um/include/asm/pgtable-3level.h
7519+++ b/arch/um/include/asm/pgtable-3level.h
7520@@ -58,6 +58,7 @@
7521 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7522 #define pud_populate(mm, pud, pmd) \
7523 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7524+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7525
7526 #ifdef CONFIG_64BIT
7527 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7528diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7529index ccb9a9d..cc425bb 100644
7530--- a/arch/um/kernel/process.c
7531+++ b/arch/um/kernel/process.c
7532@@ -407,22 +407,6 @@ int singlestepping(void * t)
7533 return 2;
7534 }
7535
7536-/*
7537- * Only x86 and x86_64 have an arch_align_stack().
7538- * All other arches have "#define arch_align_stack(x) (x)"
7539- * in their asm/system.h
7540- * As this is included in UML from asm-um/system-generic.h,
7541- * we can use it to behave as the subarch does.
7542- */
7543-#ifndef arch_align_stack
7544-unsigned long arch_align_stack(unsigned long sp)
7545-{
7546- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7547- sp -= get_random_int() % 8192;
7548- return sp & ~0xf;
7549-}
7550-#endif
7551-
7552 unsigned long get_wchan(struct task_struct *p)
7553 {
7554 unsigned long stack_page, sp, ip;
7555diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7556index ad8f795..2c7eec6 100644
7557--- a/arch/unicore32/include/asm/cache.h
7558+++ b/arch/unicore32/include/asm/cache.h
7559@@ -12,8 +12,10 @@
7560 #ifndef __UNICORE_CACHE_H__
7561 #define __UNICORE_CACHE_H__
7562
7563-#define L1_CACHE_SHIFT (5)
7564-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7565+#include <linux/const.h>
7566+
7567+#define L1_CACHE_SHIFT 5
7568+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7569
7570 /*
7571 * Memory returned by kmalloc() may be used for DMA, so we must make
7572diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7573index c70684f..698fa4b 100644
7574--- a/arch/x86/Kconfig
7575+++ b/arch/x86/Kconfig
7576@@ -218,7 +218,7 @@ config X86_HT
7577
7578 config X86_32_LAZY_GS
7579 def_bool y
7580- depends on X86_32 && !CC_STACKPROTECTOR
7581+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7582
7583 config ARCH_HWEIGHT_CFLAGS
7584 string
7585@@ -1047,7 +1047,7 @@ choice
7586
7587 config NOHIGHMEM
7588 bool "off"
7589- depends on !X86_NUMAQ
7590+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7591 ---help---
7592 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7593 However, the address space of 32-bit x86 processors is only 4
7594@@ -1084,7 +1084,7 @@ config NOHIGHMEM
7595
7596 config HIGHMEM4G
7597 bool "4GB"
7598- depends on !X86_NUMAQ
7599+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7600 ---help---
7601 Select this if you have a 32-bit processor and between 1 and 4
7602 gigabytes of physical RAM.
7603@@ -1138,7 +1138,7 @@ config PAGE_OFFSET
7604 hex
7605 default 0xB0000000 if VMSPLIT_3G_OPT
7606 default 0x80000000 if VMSPLIT_2G
7607- default 0x78000000 if VMSPLIT_2G_OPT
7608+ default 0x70000000 if VMSPLIT_2G_OPT
7609 default 0x40000000 if VMSPLIT_1G
7610 default 0xC0000000
7611 depends on X86_32
7612@@ -1526,6 +1526,7 @@ config SECCOMP
7613
7614 config CC_STACKPROTECTOR
7615 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
7616+ depends on X86_64 || !PAX_MEMORY_UDEREF
7617 ---help---
7618 This option turns on the -fstack-protector GCC feature. This
7619 feature puts, at the beginning of functions, a canary value on
7620@@ -1583,6 +1584,7 @@ config KEXEC_JUMP
7621 config PHYSICAL_START
7622 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7623 default "0x1000000"
7624+ range 0x400000 0x40000000
7625 ---help---
7626 This gives the physical address where the kernel is loaded.
7627
7628@@ -1646,6 +1648,7 @@ config X86_NEED_RELOCS
7629 config PHYSICAL_ALIGN
7630 hex "Alignment value to which kernel should be aligned" if X86_32
7631 default "0x1000000"
7632+ range 0x400000 0x1000000 if PAX_KERNEXEC
7633 range 0x2000 0x1000000
7634 ---help---
7635 This value puts the alignment restrictions on physical address
7636@@ -1677,9 +1680,10 @@ config HOTPLUG_CPU
7637 Say N if you want to disable CPU hotplug.
7638
7639 config COMPAT_VDSO
7640- def_bool y
7641+ def_bool n
7642 prompt "Compat VDSO support"
7643 depends on X86_32 || IA32_EMULATION
7644+ depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7645 ---help---
7646 Map the 32-bit VDSO to the predictable old-style address too.
7647
7648diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7649index 706e12e..62e4feb 100644
7650--- a/arch/x86/Kconfig.cpu
7651+++ b/arch/x86/Kconfig.cpu
7652@@ -334,7 +334,7 @@ config X86_PPRO_FENCE
7653
7654 config X86_F00F_BUG
7655 def_bool y
7656- depends on M586MMX || M586TSC || M586 || M486 || M386
7657+ depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7658
7659 config X86_INVD_BUG
7660 def_bool y
7661@@ -358,7 +358,7 @@ config X86_POPAD_OK
7662
7663 config X86_ALIGNMENT_16
7664 def_bool y
7665- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7666+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7667
7668 config X86_INTEL_USERCOPY
7669 def_bool y
7670@@ -404,7 +404,7 @@ config X86_CMPXCHG64
7671 # generates cmov.
7672 config X86_CMOV
7673 def_bool y
7674- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7675+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7676
7677 config X86_MINIMUM_CPU_FAMILY
7678 int
7679diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7680index e46c214..ab62fd1 100644
7681--- a/arch/x86/Kconfig.debug
7682+++ b/arch/x86/Kconfig.debug
7683@@ -84,7 +84,7 @@ config X86_PTDUMP
7684 config DEBUG_RODATA
7685 bool "Write protect kernel read-only data structures"
7686 default y
7687- depends on DEBUG_KERNEL
7688+ depends on DEBUG_KERNEL && BROKEN
7689 ---help---
7690 Mark the kernel read-only data as write-protected in the pagetables,
7691 in order to catch accidental (and incorrect) writes to such const
7692@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7693
7694 config DEBUG_SET_MODULE_RONX
7695 bool "Set loadable kernel module data as NX and text as RO"
7696- depends on MODULES
7697+ depends on MODULES && BROKEN
7698 ---help---
7699 This option helps catch unintended modifications to loadable
7700 kernel module's text and read-only data. It also prevents execution
7701@@ -275,7 +275,7 @@ config OPTIMIZE_INLINING
7702
7703 config DEBUG_STRICT_USER_COPY_CHECKS
7704 bool "Strict copy size checks"
7705- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
7706+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
7707 ---help---
7708 Enabling this option turns a certain set of sanity checks for user
7709 copy operations into compile time failures.
7710diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7711index 1f25214..39422b3 100644
7712--- a/arch/x86/Makefile
7713+++ b/arch/x86/Makefile
7714@@ -46,6 +46,7 @@ else
7715 UTS_MACHINE := x86_64
7716 CHECKFLAGS += -D__x86_64__ -m64
7717
7718+ biarch := $(call cc-option,-m64)
7719 KBUILD_AFLAGS += -m64
7720 KBUILD_CFLAGS += -m64
7721
7722@@ -222,3 +223,12 @@ define archhelp
7723 echo ' FDARGS="..." arguments for the booted kernel'
7724 echo ' FDINITRD=file initrd for the booted kernel'
7725 endef
7726+
7727+define OLD_LD
7728+
7729+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7730+*** Please upgrade your binutils to 2.18 or newer
7731+endef
7732+
7733+archprepare:
7734+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7735diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7736index 5a747dd..ff7b12c 100644
7737--- a/arch/x86/boot/Makefile
7738+++ b/arch/x86/boot/Makefile
7739@@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7740 $(call cc-option, -fno-stack-protector) \
7741 $(call cc-option, -mpreferred-stack-boundary=2)
7742 KBUILD_CFLAGS += $(call cc-option, -m32)
7743+ifdef CONSTIFY_PLUGIN
7744+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7745+endif
7746 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7747 GCOV_PROFILE := n
7748
7749diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7750index 878e4b9..20537ab 100644
7751--- a/arch/x86/boot/bitops.h
7752+++ b/arch/x86/boot/bitops.h
7753@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7754 u8 v;
7755 const u32 *p = (const u32 *)addr;
7756
7757- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7758+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7759 return v;
7760 }
7761
7762@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7763
7764 static inline void set_bit(int nr, void *addr)
7765 {
7766- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7767+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7768 }
7769
7770 #endif /* BOOT_BITOPS_H */
7771diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7772index 18997e5..83d9c67 100644
7773--- a/arch/x86/boot/boot.h
7774+++ b/arch/x86/boot/boot.h
7775@@ -85,7 +85,7 @@ static inline void io_delay(void)
7776 static inline u16 ds(void)
7777 {
7778 u16 seg;
7779- asm("movw %%ds,%0" : "=rm" (seg));
7780+ asm volatile("movw %%ds,%0" : "=rm" (seg));
7781 return seg;
7782 }
7783
7784@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7785 static inline int memcmp(const void *s1, const void *s2, size_t len)
7786 {
7787 u8 diff;
7788- asm("repe; cmpsb; setnz %0"
7789+ asm volatile("repe; cmpsb; setnz %0"
7790 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7791 return diff;
7792 }
7793diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7794index e398bb5..3a382ca 100644
7795--- a/arch/x86/boot/compressed/Makefile
7796+++ b/arch/x86/boot/compressed/Makefile
7797@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7798 KBUILD_CFLAGS += $(cflags-y)
7799 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7800 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7801+ifdef CONSTIFY_PLUGIN
7802+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7803+endif
7804
7805 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7806 GCOV_PROFILE := n
7807diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7808index 4e85f5f..39fa641 100644
7809--- a/arch/x86/boot/compressed/eboot.c
7810+++ b/arch/x86/boot/compressed/eboot.c
7811@@ -142,7 +142,6 @@ again:
7812 *addr = max_addr;
7813 }
7814
7815-free_pool:
7816 efi_call_phys1(sys_table->boottime->free_pool, map);
7817
7818 fail:
7819@@ -206,7 +205,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7820 if (i == map_size / desc_size)
7821 status = EFI_NOT_FOUND;
7822
7823-free_pool:
7824 efi_call_phys1(sys_table->boottime->free_pool, map);
7825 fail:
7826 return status;
7827diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7828index c85e3ac..6f5aa80 100644
7829--- a/arch/x86/boot/compressed/head_32.S
7830+++ b/arch/x86/boot/compressed/head_32.S
7831@@ -106,7 +106,7 @@ preferred_addr:
7832 notl %eax
7833 andl %eax, %ebx
7834 #else
7835- movl $LOAD_PHYSICAL_ADDR, %ebx
7836+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7837 #endif
7838
7839 /* Target address to relocate to for decompression */
7840@@ -192,7 +192,7 @@ relocated:
7841 * and where it was actually loaded.
7842 */
7843 movl %ebp, %ebx
7844- subl $LOAD_PHYSICAL_ADDR, %ebx
7845+ subl $____LOAD_PHYSICAL_ADDR, %ebx
7846 jz 2f /* Nothing to be done if loaded at compiled addr. */
7847 /*
7848 * Process relocations.
7849@@ -200,8 +200,7 @@ relocated:
7850
7851 1: subl $4, %edi
7852 movl (%edi), %ecx
7853- testl %ecx, %ecx
7854- jz 2f
7855+ jecxz 2f
7856 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7857 jmp 1b
7858 2:
7859diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7860index 87e03a1..0d94c76 100644
7861--- a/arch/x86/boot/compressed/head_64.S
7862+++ b/arch/x86/boot/compressed/head_64.S
7863@@ -91,7 +91,7 @@ ENTRY(startup_32)
7864 notl %eax
7865 andl %eax, %ebx
7866 #else
7867- movl $LOAD_PHYSICAL_ADDR, %ebx
7868+ movl $____LOAD_PHYSICAL_ADDR, %ebx
7869 #endif
7870
7871 /* Target address to relocate to for decompression */
7872@@ -263,7 +263,7 @@ preferred_addr:
7873 notq %rax
7874 andq %rax, %rbp
7875 #else
7876- movq $LOAD_PHYSICAL_ADDR, %rbp
7877+ movq $____LOAD_PHYSICAL_ADDR, %rbp
7878 #endif
7879
7880 /* Target address to relocate to for decompression */
7881diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7882index 7116dcb..d9ae1d7 100644
7883--- a/arch/x86/boot/compressed/misc.c
7884+++ b/arch/x86/boot/compressed/misc.c
7885@@ -310,7 +310,7 @@ static void parse_elf(void *output)
7886 case PT_LOAD:
7887 #ifdef CONFIG_RELOCATABLE
7888 dest = output;
7889- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7890+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7891 #else
7892 dest = (void *)(phdr->p_paddr);
7893 #endif
7894@@ -365,7 +365,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7895 error("Destination address too large");
7896 #endif
7897 #ifndef CONFIG_RELOCATABLE
7898- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7899+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7900 error("Wrong destination address");
7901 #endif
7902
7903diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7904index 4d3ff03..e4972ff 100644
7905--- a/arch/x86/boot/cpucheck.c
7906+++ b/arch/x86/boot/cpucheck.c
7907@@ -74,7 +74,7 @@ static int has_fpu(void)
7908 u16 fcw = -1, fsw = -1;
7909 u32 cr0;
7910
7911- asm("movl %%cr0,%0" : "=r" (cr0));
7912+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
7913 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7914 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7915 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7916@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7917 {
7918 u32 f0, f1;
7919
7920- asm("pushfl ; "
7921+ asm volatile("pushfl ; "
7922 "pushfl ; "
7923 "popl %0 ; "
7924 "movl %0,%1 ; "
7925@@ -115,7 +115,7 @@ static void get_flags(void)
7926 set_bit(X86_FEATURE_FPU, cpu.flags);
7927
7928 if (has_eflag(X86_EFLAGS_ID)) {
7929- asm("cpuid"
7930+ asm volatile("cpuid"
7931 : "=a" (max_intel_level),
7932 "=b" (cpu_vendor[0]),
7933 "=d" (cpu_vendor[1]),
7934@@ -124,7 +124,7 @@ static void get_flags(void)
7935
7936 if (max_intel_level >= 0x00000001 &&
7937 max_intel_level <= 0x0000ffff) {
7938- asm("cpuid"
7939+ asm volatile("cpuid"
7940 : "=a" (tfms),
7941 "=c" (cpu.flags[4]),
7942 "=d" (cpu.flags[0])
7943@@ -136,7 +136,7 @@ static void get_flags(void)
7944 cpu.model += ((tfms >> 16) & 0xf) << 4;
7945 }
7946
7947- asm("cpuid"
7948+ asm volatile("cpuid"
7949 : "=a" (max_amd_level)
7950 : "a" (0x80000000)
7951 : "ebx", "ecx", "edx");
7952@@ -144,7 +144,7 @@ static void get_flags(void)
7953 if (max_amd_level >= 0x80000001 &&
7954 max_amd_level <= 0x8000ffff) {
7955 u32 eax = 0x80000001;
7956- asm("cpuid"
7957+ asm volatile("cpuid"
7958 : "+a" (eax),
7959 "=c" (cpu.flags[6]),
7960 "=d" (cpu.flags[1])
7961@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7962 u32 ecx = MSR_K7_HWCR;
7963 u32 eax, edx;
7964
7965- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7966+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7967 eax &= ~(1 << 15);
7968- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7969+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7970
7971 get_flags(); /* Make sure it really did something */
7972 err = check_flags();
7973@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7974 u32 ecx = MSR_VIA_FCR;
7975 u32 eax, edx;
7976
7977- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7978+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7979 eax |= (1<<1)|(1<<7);
7980- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7981+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7982
7983 set_bit(X86_FEATURE_CX8, cpu.flags);
7984 err = check_flags();
7985@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7986 u32 eax, edx;
7987 u32 level = 1;
7988
7989- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7990- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7991- asm("cpuid"
7992+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7993+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7994+ asm volatile("cpuid"
7995 : "+a" (level), "=d" (cpu.flags[0])
7996 : : "ecx", "ebx");
7997- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7998+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7999
8000 err = check_flags();
8001 }
8002diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
8003index efe5acf..22a3784 100644
8004--- a/arch/x86/boot/header.S
8005+++ b/arch/x86/boot/header.S
8006@@ -391,10 +391,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
8007 # single linked list of
8008 # struct setup_data
8009
8010-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
8011+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
8012
8013 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
8014+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
8015+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
8016+#else
8017 #define VO_INIT_SIZE (VO__end - VO__text)
8018+#endif
8019 #if ZO_INIT_SIZE > VO_INIT_SIZE
8020 #define INIT_SIZE ZO_INIT_SIZE
8021 #else
8022diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
8023index db75d07..8e6d0af 100644
8024--- a/arch/x86/boot/memory.c
8025+++ b/arch/x86/boot/memory.c
8026@@ -19,7 +19,7 @@
8027
8028 static int detect_memory_e820(void)
8029 {
8030- int count = 0;
8031+ unsigned int count = 0;
8032 struct biosregs ireg, oreg;
8033 struct e820entry *desc = boot_params.e820_map;
8034 static struct e820entry buf; /* static so it is zeroed */
8035diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
8036index 11e8c6e..fdbb1ed 100644
8037--- a/arch/x86/boot/video-vesa.c
8038+++ b/arch/x86/boot/video-vesa.c
8039@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
8040
8041 boot_params.screen_info.vesapm_seg = oreg.es;
8042 boot_params.screen_info.vesapm_off = oreg.di;
8043+ boot_params.screen_info.vesapm_size = oreg.cx;
8044 }
8045
8046 /*
8047diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
8048index 43eda28..5ab5fdb 100644
8049--- a/arch/x86/boot/video.c
8050+++ b/arch/x86/boot/video.c
8051@@ -96,7 +96,7 @@ static void store_mode_params(void)
8052 static unsigned int get_entry(void)
8053 {
8054 char entry_buf[4];
8055- int i, len = 0;
8056+ unsigned int i, len = 0;
8057 int key;
8058 unsigned int v;
8059
8060diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8061index 5b577d5..3c1fed4 100644
8062--- a/arch/x86/crypto/aes-x86_64-asm_64.S
8063+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8064@@ -8,6 +8,8 @@
8065 * including this sentence is retained in full.
8066 */
8067
8068+#include <asm/alternative-asm.h>
8069+
8070 .extern crypto_ft_tab
8071 .extern crypto_it_tab
8072 .extern crypto_fl_tab
8073@@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8074 je B192; \
8075 leaq 32(r9),r9;
8076
8077+#define ret pax_force_retaddr 0, 1; ret
8078+
8079 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8080 movq r1,r2; \
8081 movq r3,r4; \
8082diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8083index 3470624..201259d 100644
8084--- a/arch/x86/crypto/aesni-intel_asm.S
8085+++ b/arch/x86/crypto/aesni-intel_asm.S
8086@@ -31,6 +31,7 @@
8087
8088 #include <linux/linkage.h>
8089 #include <asm/inst.h>
8090+#include <asm/alternative-asm.h>
8091
8092 #ifdef __x86_64__
8093 .data
8094@@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8095 pop %r14
8096 pop %r13
8097 pop %r12
8098+ pax_force_retaddr 0, 1
8099 ret
8100+ENDPROC(aesni_gcm_dec)
8101
8102
8103 /*****************************************************************************
8104@@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8105 pop %r14
8106 pop %r13
8107 pop %r12
8108+ pax_force_retaddr 0, 1
8109 ret
8110+ENDPROC(aesni_gcm_enc)
8111
8112 #endif
8113
8114@@ -1714,6 +1719,7 @@ _key_expansion_256a:
8115 pxor %xmm1, %xmm0
8116 movaps %xmm0, (TKEYP)
8117 add $0x10, TKEYP
8118+ pax_force_retaddr_bts
8119 ret
8120
8121 .align 4
8122@@ -1738,6 +1744,7 @@ _key_expansion_192a:
8123 shufps $0b01001110, %xmm2, %xmm1
8124 movaps %xmm1, 0x10(TKEYP)
8125 add $0x20, TKEYP
8126+ pax_force_retaddr_bts
8127 ret
8128
8129 .align 4
8130@@ -1757,6 +1764,7 @@ _key_expansion_192b:
8131
8132 movaps %xmm0, (TKEYP)
8133 add $0x10, TKEYP
8134+ pax_force_retaddr_bts
8135 ret
8136
8137 .align 4
8138@@ -1769,6 +1777,7 @@ _key_expansion_256b:
8139 pxor %xmm1, %xmm2
8140 movaps %xmm2, (TKEYP)
8141 add $0x10, TKEYP
8142+ pax_force_retaddr_bts
8143 ret
8144
8145 /*
8146@@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8147 #ifndef __x86_64__
8148 popl KEYP
8149 #endif
8150+ pax_force_retaddr 0, 1
8151 ret
8152+ENDPROC(aesni_set_key)
8153
8154 /*
8155 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8156@@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8157 popl KLEN
8158 popl KEYP
8159 #endif
8160+ pax_force_retaddr 0, 1
8161 ret
8162+ENDPROC(aesni_enc)
8163
8164 /*
8165 * _aesni_enc1: internal ABI
8166@@ -1959,6 +1972,7 @@ _aesni_enc1:
8167 AESENC KEY STATE
8168 movaps 0x70(TKEYP), KEY
8169 AESENCLAST KEY STATE
8170+ pax_force_retaddr_bts
8171 ret
8172
8173 /*
8174@@ -2067,6 +2081,7 @@ _aesni_enc4:
8175 AESENCLAST KEY STATE2
8176 AESENCLAST KEY STATE3
8177 AESENCLAST KEY STATE4
8178+ pax_force_retaddr_bts
8179 ret
8180
8181 /*
8182@@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8183 popl KLEN
8184 popl KEYP
8185 #endif
8186+ pax_force_retaddr 0, 1
8187 ret
8188+ENDPROC(aesni_dec)
8189
8190 /*
8191 * _aesni_dec1: internal ABI
8192@@ -2146,6 +2163,7 @@ _aesni_dec1:
8193 AESDEC KEY STATE
8194 movaps 0x70(TKEYP), KEY
8195 AESDECLAST KEY STATE
8196+ pax_force_retaddr_bts
8197 ret
8198
8199 /*
8200@@ -2254,6 +2272,7 @@ _aesni_dec4:
8201 AESDECLAST KEY STATE2
8202 AESDECLAST KEY STATE3
8203 AESDECLAST KEY STATE4
8204+ pax_force_retaddr_bts
8205 ret
8206
8207 /*
8208@@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8209 popl KEYP
8210 popl LEN
8211 #endif
8212+ pax_force_retaddr 0, 1
8213 ret
8214+ENDPROC(aesni_ecb_enc)
8215
8216 /*
8217 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8218@@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8219 popl KEYP
8220 popl LEN
8221 #endif
8222+ pax_force_retaddr 0, 1
8223 ret
8224+ENDPROC(aesni_ecb_dec)
8225
8226 /*
8227 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8228@@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8229 popl LEN
8230 popl IVP
8231 #endif
8232+ pax_force_retaddr 0, 1
8233 ret
8234+ENDPROC(aesni_cbc_enc)
8235
8236 /*
8237 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8238@@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
8239 popl LEN
8240 popl IVP
8241 #endif
8242+ pax_force_retaddr 0, 1
8243 ret
8244+ENDPROC(aesni_cbc_dec)
8245
8246 #ifdef __x86_64__
8247 .align 16
8248@@ -2526,6 +2553,7 @@ _aesni_inc_init:
8249 mov $1, TCTR_LOW
8250 MOVQ_R64_XMM TCTR_LOW INC
8251 MOVQ_R64_XMM CTR TCTR_LOW
8252+ pax_force_retaddr_bts
8253 ret
8254
8255 /*
8256@@ -2554,6 +2582,7 @@ _aesni_inc:
8257 .Linc_low:
8258 movaps CTR, IV
8259 PSHUFB_XMM BSWAP_MASK IV
8260+ pax_force_retaddr_bts
8261 ret
8262
8263 /*
8264@@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
8265 .Lctr_enc_ret:
8266 movups IV, (IVP)
8267 .Lctr_enc_just_ret:
8268+ pax_force_retaddr 0, 1
8269 ret
8270+ENDPROC(aesni_ctr_enc)
8271 #endif
8272diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8273index 391d245..67f35c2 100644
8274--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8275+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8276@@ -20,6 +20,8 @@
8277 *
8278 */
8279
8280+#include <asm/alternative-asm.h>
8281+
8282 .file "blowfish-x86_64-asm.S"
8283 .text
8284
8285@@ -151,9 +153,11 @@ __blowfish_enc_blk:
8286 jnz __enc_xor;
8287
8288 write_block();
8289+ pax_force_retaddr 0, 1
8290 ret;
8291 __enc_xor:
8292 xor_block();
8293+ pax_force_retaddr 0, 1
8294 ret;
8295
8296 .align 8
8297@@ -188,6 +192,7 @@ blowfish_dec_blk:
8298
8299 movq %r11, %rbp;
8300
8301+ pax_force_retaddr 0, 1
8302 ret;
8303
8304 /**********************************************************************
8305@@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8306
8307 popq %rbx;
8308 popq %rbp;
8309+ pax_force_retaddr 0, 1
8310 ret;
8311
8312 __enc_xor4:
8313@@ -349,6 +355,7 @@ __enc_xor4:
8314
8315 popq %rbx;
8316 popq %rbp;
8317+ pax_force_retaddr 0, 1
8318 ret;
8319
8320 .align 8
8321@@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8322 popq %rbx;
8323 popq %rbp;
8324
8325+ pax_force_retaddr 0, 1
8326 ret;
8327
8328diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
8329index 0b33743..7a56206 100644
8330--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
8331+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
8332@@ -20,6 +20,8 @@
8333 *
8334 */
8335
8336+#include <asm/alternative-asm.h>
8337+
8338 .file "camellia-x86_64-asm_64.S"
8339 .text
8340
8341@@ -229,12 +231,14 @@ __enc_done:
8342 enc_outunpack(mov, RT1);
8343
8344 movq RRBP, %rbp;
8345+ pax_force_retaddr 0, 1
8346 ret;
8347
8348 __enc_xor:
8349 enc_outunpack(xor, RT1);
8350
8351 movq RRBP, %rbp;
8352+ pax_force_retaddr 0, 1
8353 ret;
8354
8355 .global camellia_dec_blk;
8356@@ -275,6 +279,7 @@ __dec_rounds16:
8357 dec_outunpack();
8358
8359 movq RRBP, %rbp;
8360+ pax_force_retaddr 0, 1
8361 ret;
8362
8363 /**********************************************************************
8364@@ -468,6 +473,7 @@ __enc2_done:
8365
8366 movq RRBP, %rbp;
8367 popq %rbx;
8368+ pax_force_retaddr 0, 1
8369 ret;
8370
8371 __enc2_xor:
8372@@ -475,6 +481,7 @@ __enc2_xor:
8373
8374 movq RRBP, %rbp;
8375 popq %rbx;
8376+ pax_force_retaddr 0, 1
8377 ret;
8378
8379 .global camellia_dec_blk_2way;
8380@@ -517,4 +524,5 @@ __dec2_rounds16:
8381
8382 movq RRBP, %rbp;
8383 movq RXOR, %rbx;
8384+ pax_force_retaddr 0, 1
8385 ret;
8386diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8387index 6214a9b..1f4fc9a 100644
8388--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8389+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8390@@ -1,3 +1,5 @@
8391+#include <asm/alternative-asm.h>
8392+
8393 # enter ECRYPT_encrypt_bytes
8394 .text
8395 .p2align 5
8396@@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8397 add %r11,%rsp
8398 mov %rdi,%rax
8399 mov %rsi,%rdx
8400+ pax_force_retaddr 0, 1
8401 ret
8402 # bytesatleast65:
8403 ._bytesatleast65:
8404@@ -891,6 +894,7 @@ ECRYPT_keysetup:
8405 add %r11,%rsp
8406 mov %rdi,%rax
8407 mov %rsi,%rdx
8408+ pax_force_retaddr
8409 ret
8410 # enter ECRYPT_ivsetup
8411 .text
8412@@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8413 add %r11,%rsp
8414 mov %rdi,%rax
8415 mov %rsi,%rdx
8416+ pax_force_retaddr
8417 ret
8418diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8419index 3ee1ff0..cbc568b 100644
8420--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8421+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8422@@ -24,6 +24,8 @@
8423 *
8424 */
8425
8426+#include <asm/alternative-asm.h>
8427+
8428 .file "serpent-sse2-x86_64-asm_64.S"
8429 .text
8430
8431@@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
8432 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8433 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8434
8435+ pax_force_retaddr
8436 ret;
8437
8438 __enc_xor8:
8439 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8440 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8441
8442+ pax_force_retaddr
8443 ret;
8444
8445 .align 8
8446@@ -755,4 +759,5 @@ serpent_dec_blk_8way:
8447 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8448 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8449
8450+ pax_force_retaddr
8451 ret;
8452diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8453index b2c2f57..8470cab 100644
8454--- a/arch/x86/crypto/sha1_ssse3_asm.S
8455+++ b/arch/x86/crypto/sha1_ssse3_asm.S
8456@@ -28,6 +28,8 @@
8457 * (at your option) any later version.
8458 */
8459
8460+#include <asm/alternative-asm.h>
8461+
8462 #define CTX %rdi // arg1
8463 #define BUF %rsi // arg2
8464 #define CNT %rdx // arg3
8465@@ -104,6 +106,7 @@
8466 pop %r12
8467 pop %rbp
8468 pop %rbx
8469+ pax_force_retaddr 0, 1
8470 ret
8471
8472 .size \name, .-\name
8473diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8474index 5b012a2..36d5364 100644
8475--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8476+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8477@@ -20,6 +20,8 @@
8478 *
8479 */
8480
8481+#include <asm/alternative-asm.h>
8482+
8483 .file "twofish-x86_64-asm-3way.S"
8484 .text
8485
8486@@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8487 popq %r13;
8488 popq %r14;
8489 popq %r15;
8490+ pax_force_retaddr 0, 1
8491 ret;
8492
8493 __enc_xor3:
8494@@ -271,6 +274,7 @@ __enc_xor3:
8495 popq %r13;
8496 popq %r14;
8497 popq %r15;
8498+ pax_force_retaddr 0, 1
8499 ret;
8500
8501 .global twofish_dec_blk_3way
8502@@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8503 popq %r13;
8504 popq %r14;
8505 popq %r15;
8506+ pax_force_retaddr 0, 1
8507 ret;
8508
8509diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8510index 7bcf3fc..f53832f 100644
8511--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8512+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8513@@ -21,6 +21,7 @@
8514 .text
8515
8516 #include <asm/asm-offsets.h>
8517+#include <asm/alternative-asm.h>
8518
8519 #define a_offset 0
8520 #define b_offset 4
8521@@ -268,6 +269,7 @@ twofish_enc_blk:
8522
8523 popq R1
8524 movq $1,%rax
8525+ pax_force_retaddr 0, 1
8526 ret
8527
8528 twofish_dec_blk:
8529@@ -319,4 +321,5 @@ twofish_dec_blk:
8530
8531 popq R1
8532 movq $1,%rax
8533+ pax_force_retaddr 0, 1
8534 ret
8535diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8536index 07b3a68..bd2a388 100644
8537--- a/arch/x86/ia32/ia32_aout.c
8538+++ b/arch/x86/ia32/ia32_aout.c
8539@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8540 unsigned long dump_start, dump_size;
8541 struct user32 dump;
8542
8543+ memset(&dump, 0, sizeof(dump));
8544+
8545 fs = get_fs();
8546 set_fs(KERNEL_DS);
8547 has_dumped = 1;
8548diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8549index 673ac9b..7a8c5df 100644
8550--- a/arch/x86/ia32/ia32_signal.c
8551+++ b/arch/x86/ia32/ia32_signal.c
8552@@ -162,7 +162,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8553 }
8554 seg = get_fs();
8555 set_fs(KERNEL_DS);
8556- ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8557+ ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8558 set_fs(seg);
8559 if (ret >= 0 && uoss_ptr) {
8560 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8561@@ -361,7 +361,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8562 */
8563 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8564 size_t frame_size,
8565- void **fpstate)
8566+ void __user **fpstate)
8567 {
8568 unsigned long sp;
8569
8570@@ -382,7 +382,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8571
8572 if (used_math()) {
8573 sp = sp - sig_xstate_ia32_size;
8574- *fpstate = (struct _fpstate_ia32 *) sp;
8575+ *fpstate = (struct _fpstate_ia32 __user *) sp;
8576 if (save_i387_xstate_ia32(*fpstate) < 0)
8577 return (void __user *) -1L;
8578 }
8579@@ -390,7 +390,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8580 sp -= frame_size;
8581 /* Align the stack pointer according to the i386 ABI,
8582 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8583- sp = ((sp + 4) & -16ul) - 4;
8584+ sp = ((sp - 12) & -16ul) - 4;
8585 return (void __user *) sp;
8586 }
8587
8588@@ -448,7 +448,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8589 * These are actually not used anymore, but left because some
8590 * gdb versions depend on them as a marker.
8591 */
8592- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8593+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8594 } put_user_catch(err);
8595
8596 if (err)
8597@@ -490,7 +490,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8598 0xb8,
8599 __NR_ia32_rt_sigreturn,
8600 0x80cd,
8601- 0,
8602+ 0
8603 };
8604
8605 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8606@@ -520,16 +520,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8607
8608 if (ka->sa.sa_flags & SA_RESTORER)
8609 restorer = ka->sa.sa_restorer;
8610+ else if (current->mm->context.vdso)
8611+ /* Return stub is in 32bit vsyscall page */
8612+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8613 else
8614- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8615- rt_sigreturn);
8616+ restorer = &frame->retcode;
8617 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8618
8619 /*
8620 * Not actually used anymore, but left because some gdb
8621 * versions need it.
8622 */
8623- put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8624+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8625 } put_user_catch(err);
8626
8627 if (err)
8628diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8629index 20e5f7b..f33c779 100644
8630--- a/arch/x86/ia32/ia32entry.S
8631+++ b/arch/x86/ia32/ia32entry.S
8632@@ -14,8 +14,10 @@
8633 #include <asm/segment.h>
8634 #include <asm/irqflags.h>
8635 #include <asm/asm.h>
8636+#include <asm/pgtable.h>
8637 #include <linux/linkage.h>
8638 #include <linux/err.h>
8639+#include <asm/alternative-asm.h>
8640
8641 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8642 #include <linux/elf-em.h>
8643@@ -95,6 +97,32 @@ ENTRY(native_irq_enable_sysexit)
8644 ENDPROC(native_irq_enable_sysexit)
8645 #endif
8646
8647+ .macro pax_enter_kernel_user
8648+ pax_set_fptr_mask
8649+#ifdef CONFIG_PAX_MEMORY_UDEREF
8650+ call pax_enter_kernel_user
8651+#endif
8652+ .endm
8653+
8654+ .macro pax_exit_kernel_user
8655+#ifdef CONFIG_PAX_MEMORY_UDEREF
8656+ call pax_exit_kernel_user
8657+#endif
8658+#ifdef CONFIG_PAX_RANDKSTACK
8659+ pushq %rax
8660+ pushq %r11
8661+ call pax_randomize_kstack
8662+ popq %r11
8663+ popq %rax
8664+#endif
8665+ .endm
8666+
8667+.macro pax_erase_kstack
8668+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8669+ call pax_erase_kstack
8670+#endif
8671+.endm
8672+
8673 /*
8674 * 32bit SYSENTER instruction entry.
8675 *
8676@@ -121,12 +149,6 @@ ENTRY(ia32_sysenter_target)
8677 CFI_REGISTER rsp,rbp
8678 SWAPGS_UNSAFE_STACK
8679 movq PER_CPU_VAR(kernel_stack), %rsp
8680- addq $(KERNEL_STACK_OFFSET),%rsp
8681- /*
8682- * No need to follow this irqs on/off section: the syscall
8683- * disabled irqs, here we enable it straight after entry:
8684- */
8685- ENABLE_INTERRUPTS(CLBR_NONE)
8686 movl %ebp,%ebp /* zero extension */
8687 pushq_cfi $__USER32_DS
8688 /*CFI_REL_OFFSET ss,0*/
8689@@ -134,22 +156,42 @@ ENTRY(ia32_sysenter_target)
8690 CFI_REL_OFFSET rsp,0
8691 pushfq_cfi
8692 /*CFI_REL_OFFSET rflags,0*/
8693- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8694- CFI_REGISTER rip,r10
8695+ orl $X86_EFLAGS_IF,(%rsp)
8696+ GET_THREAD_INFO(%r11)
8697+ movl TI_sysenter_return(%r11), %r11d
8698+ CFI_REGISTER rip,r11
8699 pushq_cfi $__USER32_CS
8700 /*CFI_REL_OFFSET cs,0*/
8701 movl %eax, %eax
8702- pushq_cfi %r10
8703+ pushq_cfi %r11
8704 CFI_REL_OFFSET rip,0
8705 pushq_cfi %rax
8706 cld
8707 SAVE_ARGS 0,1,0
8708+ pax_enter_kernel_user
8709+
8710+#ifdef CONFIG_PAX_RANDKSTACK
8711+ pax_erase_kstack
8712+#endif
8713+
8714+ /*
8715+ * No need to follow this irqs on/off section: the syscall
8716+ * disabled irqs, here we enable it straight after entry:
8717+ */
8718+ ENABLE_INTERRUPTS(CLBR_NONE)
8719 /* no need to do an access_ok check here because rbp has been
8720 32bit zero extended */
8721+
8722+#ifdef CONFIG_PAX_MEMORY_UDEREF
8723+ mov $PAX_USER_SHADOW_BASE,%r11
8724+ add %r11,%rbp
8725+#endif
8726+
8727 1: movl (%rbp),%ebp
8728 _ASM_EXTABLE(1b,ia32_badarg)
8729- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8730- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8731+ GET_THREAD_INFO(%r11)
8732+ orl $TS_COMPAT,TI_status(%r11)
8733+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8734 CFI_REMEMBER_STATE
8735 jnz sysenter_tracesys
8736 cmpq $(IA32_NR_syscalls-1),%rax
8737@@ -159,12 +201,15 @@ sysenter_do_call:
8738 sysenter_dispatch:
8739 call *ia32_sys_call_table(,%rax,8)
8740 movq %rax,RAX-ARGOFFSET(%rsp)
8741+ GET_THREAD_INFO(%r11)
8742 DISABLE_INTERRUPTS(CLBR_NONE)
8743 TRACE_IRQS_OFF
8744- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8745+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8746 jnz sysexit_audit
8747 sysexit_from_sys_call:
8748- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8749+ pax_exit_kernel_user
8750+ pax_erase_kstack
8751+ andl $~TS_COMPAT,TI_status(%r11)
8752 /* clear IF, that popfq doesn't enable interrupts early */
8753 andl $~0x200,EFLAGS-R11(%rsp)
8754 movl RIP-R11(%rsp),%edx /* User %eip */
8755@@ -190,6 +235,9 @@ sysexit_from_sys_call:
8756 movl %eax,%esi /* 2nd arg: syscall number */
8757 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8758 call __audit_syscall_entry
8759+
8760+ pax_erase_kstack
8761+
8762 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8763 cmpq $(IA32_NR_syscalls-1),%rax
8764 ja ia32_badsys
8765@@ -201,7 +249,7 @@ sysexit_from_sys_call:
8766 .endm
8767
8768 .macro auditsys_exit exit
8769- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8770+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8771 jnz ia32_ret_from_sys_call
8772 TRACE_IRQS_ON
8773 sti
8774@@ -212,11 +260,12 @@ sysexit_from_sys_call:
8775 1: setbe %al /* 1 if error, 0 if not */
8776 movzbl %al,%edi /* zero-extend that into %edi */
8777 call __audit_syscall_exit
8778+ GET_THREAD_INFO(%r11)
8779 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8780 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8781 cli
8782 TRACE_IRQS_OFF
8783- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8784+ testl %edi,TI_flags(%r11)
8785 jz \exit
8786 CLEAR_RREGS -ARGOFFSET
8787 jmp int_with_check
8788@@ -234,7 +283,7 @@ sysexit_audit:
8789
8790 sysenter_tracesys:
8791 #ifdef CONFIG_AUDITSYSCALL
8792- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8793+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8794 jz sysenter_auditsys
8795 #endif
8796 SAVE_REST
8797@@ -246,6 +295,9 @@ sysenter_tracesys:
8798 RESTORE_REST
8799 cmpq $(IA32_NR_syscalls-1),%rax
8800 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
8801+
8802+ pax_erase_kstack
8803+
8804 jmp sysenter_do_call
8805 CFI_ENDPROC
8806 ENDPROC(ia32_sysenter_target)
8807@@ -273,19 +325,25 @@ ENDPROC(ia32_sysenter_target)
8808 ENTRY(ia32_cstar_target)
8809 CFI_STARTPROC32 simple
8810 CFI_SIGNAL_FRAME
8811- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8812+ CFI_DEF_CFA rsp,0
8813 CFI_REGISTER rip,rcx
8814 /*CFI_REGISTER rflags,r11*/
8815 SWAPGS_UNSAFE_STACK
8816 movl %esp,%r8d
8817 CFI_REGISTER rsp,r8
8818 movq PER_CPU_VAR(kernel_stack),%rsp
8819+ SAVE_ARGS 8*6,0,0
8820+ pax_enter_kernel_user
8821+
8822+#ifdef CONFIG_PAX_RANDKSTACK
8823+ pax_erase_kstack
8824+#endif
8825+
8826 /*
8827 * No need to follow this irqs on/off section: the syscall
8828 * disabled irqs and here we enable it straight after entry:
8829 */
8830 ENABLE_INTERRUPTS(CLBR_NONE)
8831- SAVE_ARGS 8,0,0
8832 movl %eax,%eax /* zero extension */
8833 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8834 movq %rcx,RIP-ARGOFFSET(%rsp)
8835@@ -301,10 +359,17 @@ ENTRY(ia32_cstar_target)
8836 /* no need to do an access_ok check here because r8 has been
8837 32bit zero extended */
8838 /* hardware stack frame is complete now */
8839+
8840+#ifdef CONFIG_PAX_MEMORY_UDEREF
8841+ mov $PAX_USER_SHADOW_BASE,%r11
8842+ add %r11,%r8
8843+#endif
8844+
8845 1: movl (%r8),%r9d
8846 _ASM_EXTABLE(1b,ia32_badarg)
8847- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8848- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8849+ GET_THREAD_INFO(%r11)
8850+ orl $TS_COMPAT,TI_status(%r11)
8851+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8852 CFI_REMEMBER_STATE
8853 jnz cstar_tracesys
8854 cmpq $IA32_NR_syscalls-1,%rax
8855@@ -314,12 +379,15 @@ cstar_do_call:
8856 cstar_dispatch:
8857 call *ia32_sys_call_table(,%rax,8)
8858 movq %rax,RAX-ARGOFFSET(%rsp)
8859+ GET_THREAD_INFO(%r11)
8860 DISABLE_INTERRUPTS(CLBR_NONE)
8861 TRACE_IRQS_OFF
8862- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8863+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8864 jnz sysretl_audit
8865 sysretl_from_sys_call:
8866- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8867+ pax_exit_kernel_user
8868+ pax_erase_kstack
8869+ andl $~TS_COMPAT,TI_status(%r11)
8870 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8871 movl RIP-ARGOFFSET(%rsp),%ecx
8872 CFI_REGISTER rip,rcx
8873@@ -347,7 +415,7 @@ sysretl_audit:
8874
8875 cstar_tracesys:
8876 #ifdef CONFIG_AUDITSYSCALL
8877- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8878+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8879 jz cstar_auditsys
8880 #endif
8881 xchgl %r9d,%ebp
8882@@ -361,6 +429,9 @@ cstar_tracesys:
8883 xchgl %ebp,%r9d
8884 cmpq $(IA32_NR_syscalls-1),%rax
8885 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
8886+
8887+ pax_erase_kstack
8888+
8889 jmp cstar_do_call
8890 END(ia32_cstar_target)
8891
8892@@ -401,19 +472,26 @@ ENTRY(ia32_syscall)
8893 CFI_REL_OFFSET rip,RIP-RIP
8894 PARAVIRT_ADJUST_EXCEPTION_FRAME
8895 SWAPGS
8896- /*
8897- * No need to follow this irqs on/off section: the syscall
8898- * disabled irqs and here we enable it straight after entry:
8899- */
8900- ENABLE_INTERRUPTS(CLBR_NONE)
8901 movl %eax,%eax
8902 pushq_cfi %rax
8903 cld
8904 /* note the registers are not zero extended to the sf.
8905 this could be a problem. */
8906 SAVE_ARGS 0,1,0
8907- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8908- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8909+ pax_enter_kernel_user
8910+
8911+#ifdef CONFIG_PAX_RANDKSTACK
8912+ pax_erase_kstack
8913+#endif
8914+
8915+ /*
8916+ * No need to follow this irqs on/off section: the syscall
8917+ * disabled irqs and here we enable it straight after entry:
8918+ */
8919+ ENABLE_INTERRUPTS(CLBR_NONE)
8920+ GET_THREAD_INFO(%r11)
8921+ orl $TS_COMPAT,TI_status(%r11)
8922+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8923 jnz ia32_tracesys
8924 cmpq $(IA32_NR_syscalls-1),%rax
8925 ja ia32_badsys
8926@@ -436,6 +514,9 @@ ia32_tracesys:
8927 RESTORE_REST
8928 cmpq $(IA32_NR_syscalls-1),%rax
8929 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
8930+
8931+ pax_erase_kstack
8932+
8933 jmp ia32_do_call
8934 END(ia32_syscall)
8935
8936diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8937index 4540bec..714d913 100644
8938--- a/arch/x86/ia32/sys_ia32.c
8939+++ b/arch/x86/ia32/sys_ia32.c
8940@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8941 */
8942 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8943 {
8944- typeof(ubuf->st_uid) uid = 0;
8945- typeof(ubuf->st_gid) gid = 0;
8946+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
8947+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
8948 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
8949 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
8950 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8951@@ -287,7 +287,7 @@ asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 __user *act,
8952 return ret;
8953 }
8954
8955-asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
8956+asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
8957 int options)
8958 {
8959 return compat_sys_wait4(pid, stat_addr, options, NULL);
8960@@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8961 mm_segment_t old_fs = get_fs();
8962
8963 set_fs(KERNEL_DS);
8964- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
8965+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
8966 set_fs(old_fs);
8967 if (put_compat_timespec(&t, interval))
8968 return -EFAULT;
8969@@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
8970 mm_segment_t old_fs = get_fs();
8971
8972 set_fs(KERNEL_DS);
8973- ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
8974+ ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
8975 set_fs(old_fs);
8976 if (!ret) {
8977 switch (_NSIG_WORDS) {
8978@@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
8979 if (copy_siginfo_from_user32(&info, uinfo))
8980 return -EFAULT;
8981 set_fs(KERNEL_DS);
8982- ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
8983+ ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
8984 set_fs(old_fs);
8985 return ret;
8986 }
8987@@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
8988 return -EFAULT;
8989
8990 set_fs(KERNEL_DS);
8991- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
8992+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
8993 count);
8994 set_fs(old_fs);
8995
8996diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
8997index 952bd01..7692c6f 100644
8998--- a/arch/x86/include/asm/alternative-asm.h
8999+++ b/arch/x86/include/asm/alternative-asm.h
9000@@ -15,6 +15,45 @@
9001 .endm
9002 #endif
9003
9004+#ifdef KERNEXEC_PLUGIN
9005+ .macro pax_force_retaddr_bts rip=0
9006+ btsq $63,\rip(%rsp)
9007+ .endm
9008+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9009+ .macro pax_force_retaddr rip=0, reload=0
9010+ btsq $63,\rip(%rsp)
9011+ .endm
9012+ .macro pax_force_fptr ptr
9013+ btsq $63,\ptr
9014+ .endm
9015+ .macro pax_set_fptr_mask
9016+ .endm
9017+#endif
9018+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
9019+ .macro pax_force_retaddr rip=0, reload=0
9020+ .if \reload
9021+ pax_set_fptr_mask
9022+ .endif
9023+ orq %r10,\rip(%rsp)
9024+ .endm
9025+ .macro pax_force_fptr ptr
9026+ orq %r10,\ptr
9027+ .endm
9028+ .macro pax_set_fptr_mask
9029+ movabs $0x8000000000000000,%r10
9030+ .endm
9031+#endif
9032+#else
9033+ .macro pax_force_retaddr rip=0, reload=0
9034+ .endm
9035+ .macro pax_force_fptr ptr
9036+ .endm
9037+ .macro pax_force_retaddr_bts rip=0
9038+ .endm
9039+ .macro pax_set_fptr_mask
9040+ .endm
9041+#endif
9042+
9043 .macro altinstruction_entry orig alt feature orig_len alt_len
9044 .long \orig - .
9045 .long \alt - .
9046diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9047index 49331be..9706065 100644
9048--- a/arch/x86/include/asm/alternative.h
9049+++ b/arch/x86/include/asm/alternative.h
9050@@ -89,7 +89,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9051 ".section .discard,\"aw\",@progbits\n" \
9052 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
9053 ".previous\n" \
9054- ".section .altinstr_replacement, \"ax\"\n" \
9055+ ".section .altinstr_replacement, \"a\"\n" \
9056 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
9057 ".previous"
9058
9059diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9060index eaff479..3025a63 100644
9061--- a/arch/x86/include/asm/apic.h
9062+++ b/arch/x86/include/asm/apic.h
9063@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9064
9065 #ifdef CONFIG_X86_LOCAL_APIC
9066
9067-extern unsigned int apic_verbosity;
9068+extern int apic_verbosity;
9069 extern int local_apic_timer_c2_ok;
9070
9071 extern int disable_apic;
9072diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9073index 20370c6..a2eb9b0 100644
9074--- a/arch/x86/include/asm/apm.h
9075+++ b/arch/x86/include/asm/apm.h
9076@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9077 __asm__ __volatile__(APM_DO_ZERO_SEGS
9078 "pushl %%edi\n\t"
9079 "pushl %%ebp\n\t"
9080- "lcall *%%cs:apm_bios_entry\n\t"
9081+ "lcall *%%ss:apm_bios_entry\n\t"
9082 "setc %%al\n\t"
9083 "popl %%ebp\n\t"
9084 "popl %%edi\n\t"
9085@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9086 __asm__ __volatile__(APM_DO_ZERO_SEGS
9087 "pushl %%edi\n\t"
9088 "pushl %%ebp\n\t"
9089- "lcall *%%cs:apm_bios_entry\n\t"
9090+ "lcall *%%ss:apm_bios_entry\n\t"
9091 "setc %%bl\n\t"
9092 "popl %%ebp\n\t"
9093 "popl %%edi\n\t"
9094diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9095index 58cb6d4..a4b806c 100644
9096--- a/arch/x86/include/asm/atomic.h
9097+++ b/arch/x86/include/asm/atomic.h
9098@@ -22,7 +22,18 @@
9099 */
9100 static inline int atomic_read(const atomic_t *v)
9101 {
9102- return (*(volatile int *)&(v)->counter);
9103+ return (*(volatile const int *)&(v)->counter);
9104+}
9105+
9106+/**
9107+ * atomic_read_unchecked - read atomic variable
9108+ * @v: pointer of type atomic_unchecked_t
9109+ *
9110+ * Atomically reads the value of @v.
9111+ */
9112+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9113+{
9114+ return (*(volatile const int *)&(v)->counter);
9115 }
9116
9117 /**
9118@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9119 }
9120
9121 /**
9122+ * atomic_set_unchecked - set atomic variable
9123+ * @v: pointer of type atomic_unchecked_t
9124+ * @i: required value
9125+ *
9126+ * Atomically sets the value of @v to @i.
9127+ */
9128+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9129+{
9130+ v->counter = i;
9131+}
9132+
9133+/**
9134 * atomic_add - add integer to atomic variable
9135 * @i: integer value to add
9136 * @v: pointer of type atomic_t
9137@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9138 */
9139 static inline void atomic_add(int i, atomic_t *v)
9140 {
9141- asm volatile(LOCK_PREFIX "addl %1,%0"
9142+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
9143+
9144+#ifdef CONFIG_PAX_REFCOUNT
9145+ "jno 0f\n"
9146+ LOCK_PREFIX "subl %1,%0\n"
9147+ "int $4\n0:\n"
9148+ _ASM_EXTABLE(0b, 0b)
9149+#endif
9150+
9151+ : "+m" (v->counter)
9152+ : "ir" (i));
9153+}
9154+
9155+/**
9156+ * atomic_add_unchecked - add integer to atomic variable
9157+ * @i: integer value to add
9158+ * @v: pointer of type atomic_unchecked_t
9159+ *
9160+ * Atomically adds @i to @v.
9161+ */
9162+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9163+{
9164+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
9165 : "+m" (v->counter)
9166 : "ir" (i));
9167 }
9168@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9169 */
9170 static inline void atomic_sub(int i, atomic_t *v)
9171 {
9172- asm volatile(LOCK_PREFIX "subl %1,%0"
9173+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
9174+
9175+#ifdef CONFIG_PAX_REFCOUNT
9176+ "jno 0f\n"
9177+ LOCK_PREFIX "addl %1,%0\n"
9178+ "int $4\n0:\n"
9179+ _ASM_EXTABLE(0b, 0b)
9180+#endif
9181+
9182+ : "+m" (v->counter)
9183+ : "ir" (i));
9184+}
9185+
9186+/**
9187+ * atomic_sub_unchecked - subtract integer from atomic variable
9188+ * @i: integer value to subtract
9189+ * @v: pointer of type atomic_unchecked_t
9190+ *
9191+ * Atomically subtracts @i from @v.
9192+ */
9193+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9194+{
9195+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
9196 : "+m" (v->counter)
9197 : "ir" (i));
9198 }
9199@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9200 {
9201 unsigned char c;
9202
9203- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9204+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
9205+
9206+#ifdef CONFIG_PAX_REFCOUNT
9207+ "jno 0f\n"
9208+ LOCK_PREFIX "addl %2,%0\n"
9209+ "int $4\n0:\n"
9210+ _ASM_EXTABLE(0b, 0b)
9211+#endif
9212+
9213+ "sete %1\n"
9214 : "+m" (v->counter), "=qm" (c)
9215 : "ir" (i) : "memory");
9216 return c;
9217@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9218 */
9219 static inline void atomic_inc(atomic_t *v)
9220 {
9221- asm volatile(LOCK_PREFIX "incl %0"
9222+ asm volatile(LOCK_PREFIX "incl %0\n"
9223+
9224+#ifdef CONFIG_PAX_REFCOUNT
9225+ "jno 0f\n"
9226+ LOCK_PREFIX "decl %0\n"
9227+ "int $4\n0:\n"
9228+ _ASM_EXTABLE(0b, 0b)
9229+#endif
9230+
9231+ : "+m" (v->counter));
9232+}
9233+
9234+/**
9235+ * atomic_inc_unchecked - increment atomic variable
9236+ * @v: pointer of type atomic_unchecked_t
9237+ *
9238+ * Atomically increments @v by 1.
9239+ */
9240+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9241+{
9242+ asm volatile(LOCK_PREFIX "incl %0\n"
9243 : "+m" (v->counter));
9244 }
9245
9246@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9247 */
9248 static inline void atomic_dec(atomic_t *v)
9249 {
9250- asm volatile(LOCK_PREFIX "decl %0"
9251+ asm volatile(LOCK_PREFIX "decl %0\n"
9252+
9253+#ifdef CONFIG_PAX_REFCOUNT
9254+ "jno 0f\n"
9255+ LOCK_PREFIX "incl %0\n"
9256+ "int $4\n0:\n"
9257+ _ASM_EXTABLE(0b, 0b)
9258+#endif
9259+
9260+ : "+m" (v->counter));
9261+}
9262+
9263+/**
9264+ * atomic_dec_unchecked - decrement atomic variable
9265+ * @v: pointer of type atomic_unchecked_t
9266+ *
9267+ * Atomically decrements @v by 1.
9268+ */
9269+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9270+{
9271+ asm volatile(LOCK_PREFIX "decl %0\n"
9272 : "+m" (v->counter));
9273 }
9274
9275@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9276 {
9277 unsigned char c;
9278
9279- asm volatile(LOCK_PREFIX "decl %0; sete %1"
9280+ asm volatile(LOCK_PREFIX "decl %0\n"
9281+
9282+#ifdef CONFIG_PAX_REFCOUNT
9283+ "jno 0f\n"
9284+ LOCK_PREFIX "incl %0\n"
9285+ "int $4\n0:\n"
9286+ _ASM_EXTABLE(0b, 0b)
9287+#endif
9288+
9289+ "sete %1\n"
9290 : "+m" (v->counter), "=qm" (c)
9291 : : "memory");
9292 return c != 0;
9293@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9294 {
9295 unsigned char c;
9296
9297- asm volatile(LOCK_PREFIX "incl %0; sete %1"
9298+ asm volatile(LOCK_PREFIX "incl %0\n"
9299+
9300+#ifdef CONFIG_PAX_REFCOUNT
9301+ "jno 0f\n"
9302+ LOCK_PREFIX "decl %0\n"
9303+ "int $4\n0:\n"
9304+ _ASM_EXTABLE(0b, 0b)
9305+#endif
9306+
9307+ "sete %1\n"
9308+ : "+m" (v->counter), "=qm" (c)
9309+ : : "memory");
9310+ return c != 0;
9311+}
9312+
9313+/**
9314+ * atomic_inc_and_test_unchecked - increment and test
9315+ * @v: pointer of type atomic_unchecked_t
9316+ *
9317+ * Atomically increments @v by 1
9318+ * and returns true if the result is zero, or false for all
9319+ * other cases.
9320+ */
9321+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9322+{
9323+ unsigned char c;
9324+
9325+ asm volatile(LOCK_PREFIX "incl %0\n"
9326+ "sete %1\n"
9327 : "+m" (v->counter), "=qm" (c)
9328 : : "memory");
9329 return c != 0;
9330@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9331 {
9332 unsigned char c;
9333
9334- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9335+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
9336+
9337+#ifdef CONFIG_PAX_REFCOUNT
9338+ "jno 0f\n"
9339+ LOCK_PREFIX "subl %2,%0\n"
9340+ "int $4\n0:\n"
9341+ _ASM_EXTABLE(0b, 0b)
9342+#endif
9343+
9344+ "sets %1\n"
9345 : "+m" (v->counter), "=qm" (c)
9346 : "ir" (i) : "memory");
9347 return c;
9348@@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9349 goto no_xadd;
9350 #endif
9351 /* Modern 486+ processor */
9352- return i + xadd(&v->counter, i);
9353+ return i + xadd_check_overflow(&v->counter, i);
9354
9355 #ifdef CONFIG_M386
9356 no_xadd: /* Legacy 386 processor */
9357@@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9358 }
9359
9360 /**
9361+ * atomic_add_return_unchecked - add integer and return
9362+ * @i: integer value to add
9363+ * @v: pointer of type atomic_unchecked_t
9364+ *
9365+ * Atomically adds @i to @v and returns @i + @v
9366+ */
9367+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9368+{
9369+#ifdef CONFIG_M386
9370+ int __i;
9371+ unsigned long flags;
9372+ if (unlikely(boot_cpu_data.x86 <= 3))
9373+ goto no_xadd;
9374+#endif
9375+ /* Modern 486+ processor */
9376+ return i + xadd(&v->counter, i);
9377+
9378+#ifdef CONFIG_M386
9379+no_xadd: /* Legacy 386 processor */
9380+ raw_local_irq_save(flags);
9381+ __i = atomic_read_unchecked(v);
9382+ atomic_set_unchecked(v, i + __i);
9383+ raw_local_irq_restore(flags);
9384+ return i + __i;
9385+#endif
9386+}
9387+
9388+/**
9389 * atomic_sub_return - subtract integer and return
9390 * @v: pointer of type atomic_t
9391 * @i: integer value to subtract
9392@@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9393 }
9394
9395 #define atomic_inc_return(v) (atomic_add_return(1, v))
9396+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9397+{
9398+ return atomic_add_return_unchecked(1, v);
9399+}
9400 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9401
9402 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9403@@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9404 return cmpxchg(&v->counter, old, new);
9405 }
9406
9407+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9408+{
9409+ return cmpxchg(&v->counter, old, new);
9410+}
9411+
9412 static inline int atomic_xchg(atomic_t *v, int new)
9413 {
9414 return xchg(&v->counter, new);
9415 }
9416
9417+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9418+{
9419+ return xchg(&v->counter, new);
9420+}
9421+
9422 /**
9423 * __atomic_add_unless - add unless the number is already a given value
9424 * @v: pointer of type atomic_t
9425@@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9426 */
9427 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9428 {
9429- int c, old;
9430+ int c, old, new;
9431 c = atomic_read(v);
9432 for (;;) {
9433- if (unlikely(c == (u)))
9434+ if (unlikely(c == u))
9435 break;
9436- old = atomic_cmpxchg((v), c, c + (a));
9437+
9438+ asm volatile("addl %2,%0\n"
9439+
9440+#ifdef CONFIG_PAX_REFCOUNT
9441+ "jno 0f\n"
9442+ "subl %2,%0\n"
9443+ "int $4\n0:\n"
9444+ _ASM_EXTABLE(0b, 0b)
9445+#endif
9446+
9447+ : "=r" (new)
9448+ : "0" (c), "ir" (a));
9449+
9450+ old = atomic_cmpxchg(v, c, new);
9451 if (likely(old == c))
9452 break;
9453 c = old;
9454@@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9455 return c;
9456 }
9457
9458+/**
9459+ * atomic_inc_not_zero_hint - increment if not null
9460+ * @v: pointer of type atomic_t
9461+ * @hint: probable value of the atomic before the increment
9462+ *
9463+ * This version of atomic_inc_not_zero() gives a hint of probable
9464+ * value of the atomic. This helps processor to not read the memory
9465+ * before doing the atomic read/modify/write cycle, lowering
9466+ * number of bus transactions on some arches.
9467+ *
9468+ * Returns: 0 if increment was not done, 1 otherwise.
9469+ */
9470+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9471+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9472+{
9473+ int val, c = hint, new;
9474+
9475+ /* sanity test, should be removed by compiler if hint is a constant */
9476+ if (!hint)
9477+ return __atomic_add_unless(v, 1, 0);
9478+
9479+ do {
9480+ asm volatile("incl %0\n"
9481+
9482+#ifdef CONFIG_PAX_REFCOUNT
9483+ "jno 0f\n"
9484+ "decl %0\n"
9485+ "int $4\n0:\n"
9486+ _ASM_EXTABLE(0b, 0b)
9487+#endif
9488+
9489+ : "=r" (new)
9490+ : "0" (c));
9491+
9492+ val = atomic_cmpxchg(v, c, new);
9493+ if (val == c)
9494+ return 1;
9495+ c = val;
9496+ } while (c);
9497+
9498+ return 0;
9499+}
9500
9501 /*
9502 * atomic_dec_if_positive - decrement by 1 if old value positive
9503@@ -293,14 +552,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
9504 #endif
9505
9506 /* These are x86-specific, used by some header files */
9507-#define atomic_clear_mask(mask, addr) \
9508- asm volatile(LOCK_PREFIX "andl %0,%1" \
9509- : : "r" (~(mask)), "m" (*(addr)) : "memory")
9510+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
9511+{
9512+ asm volatile(LOCK_PREFIX "andl %1,%0"
9513+ : "+m" (v->counter)
9514+ : "r" (~(mask))
9515+ : "memory");
9516+}
9517
9518-#define atomic_set_mask(mask, addr) \
9519- asm volatile(LOCK_PREFIX "orl %0,%1" \
9520- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
9521- : "memory")
9522+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9523+{
9524+ asm volatile(LOCK_PREFIX "andl %1,%0"
9525+ : "+m" (v->counter)
9526+ : "r" (~(mask))
9527+ : "memory");
9528+}
9529+
9530+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
9531+{
9532+ asm volatile(LOCK_PREFIX "orl %1,%0"
9533+ : "+m" (v->counter)
9534+ : "r" (mask)
9535+ : "memory");
9536+}
9537+
9538+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9539+{
9540+ asm volatile(LOCK_PREFIX "orl %1,%0"
9541+ : "+m" (v->counter)
9542+ : "r" (mask)
9543+ : "memory");
9544+}
9545
9546 /* Atomic operations are already serializing on x86 */
9547 #define smp_mb__before_atomic_dec() barrier()
9548diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9549index b154de7..aadebd8 100644
9550--- a/arch/x86/include/asm/atomic64_32.h
9551+++ b/arch/x86/include/asm/atomic64_32.h
9552@@ -12,6 +12,14 @@ typedef struct {
9553 u64 __aligned(8) counter;
9554 } atomic64_t;
9555
9556+#ifdef CONFIG_PAX_REFCOUNT
9557+typedef struct {
9558+ u64 __aligned(8) counter;
9559+} atomic64_unchecked_t;
9560+#else
9561+typedef atomic64_t atomic64_unchecked_t;
9562+#endif
9563+
9564 #define ATOMIC64_INIT(val) { (val) }
9565
9566 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
9567@@ -37,21 +45,31 @@ typedef struct {
9568 ATOMIC64_DECL_ONE(sym##_386)
9569
9570 ATOMIC64_DECL_ONE(add_386);
9571+ATOMIC64_DECL_ONE(add_unchecked_386);
9572 ATOMIC64_DECL_ONE(sub_386);
9573+ATOMIC64_DECL_ONE(sub_unchecked_386);
9574 ATOMIC64_DECL_ONE(inc_386);
9575+ATOMIC64_DECL_ONE(inc_unchecked_386);
9576 ATOMIC64_DECL_ONE(dec_386);
9577+ATOMIC64_DECL_ONE(dec_unchecked_386);
9578 #endif
9579
9580 #define alternative_atomic64(f, out, in...) \
9581 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
9582
9583 ATOMIC64_DECL(read);
9584+ATOMIC64_DECL(read_unchecked);
9585 ATOMIC64_DECL(set);
9586+ATOMIC64_DECL(set_unchecked);
9587 ATOMIC64_DECL(xchg);
9588 ATOMIC64_DECL(add_return);
9589+ATOMIC64_DECL(add_return_unchecked);
9590 ATOMIC64_DECL(sub_return);
9591+ATOMIC64_DECL(sub_return_unchecked);
9592 ATOMIC64_DECL(inc_return);
9593+ATOMIC64_DECL(inc_return_unchecked);
9594 ATOMIC64_DECL(dec_return);
9595+ATOMIC64_DECL(dec_return_unchecked);
9596 ATOMIC64_DECL(dec_if_positive);
9597 ATOMIC64_DECL(inc_not_zero);
9598 ATOMIC64_DECL(add_unless);
9599@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9600 }
9601
9602 /**
9603+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9604+ * @p: pointer to type atomic64_unchecked_t
9605+ * @o: expected value
9606+ * @n: new value
9607+ *
9608+ * Atomically sets @v to @n if it was equal to @o and returns
9609+ * the old value.
9610+ */
9611+
9612+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9613+{
9614+ return cmpxchg64(&v->counter, o, n);
9615+}
9616+
9617+/**
9618 * atomic64_xchg - xchg atomic64 variable
9619 * @v: pointer to type atomic64_t
9620 * @n: value to assign
9621@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9622 }
9623
9624 /**
9625+ * atomic64_set_unchecked - set atomic64 variable
9626+ * @v: pointer to type atomic64_unchecked_t
9627+ * @n: value to assign
9628+ *
9629+ * Atomically sets the value of @v to @n.
9630+ */
9631+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9632+{
9633+ unsigned high = (unsigned)(i >> 32);
9634+ unsigned low = (unsigned)i;
9635+ alternative_atomic64(set, /* no output */,
9636+ "S" (v), "b" (low), "c" (high)
9637+ : "eax", "edx", "memory");
9638+}
9639+
9640+/**
9641 * atomic64_read - read atomic64 variable
9642 * @v: pointer to type atomic64_t
9643 *
9644@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
9645 }
9646
9647 /**
9648+ * atomic64_read_unchecked - read atomic64 variable
9649+ * @v: pointer to type atomic64_unchecked_t
9650+ *
9651+ * Atomically reads the value of @v and returns it.
9652+ */
9653+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9654+{
9655+ long long r;
9656+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
9657+ return r;
9658+ }
9659+
9660+/**
9661 * atomic64_add_return - add and return
9662 * @i: integer value to add
9663 * @v: pointer to type atomic64_t
9664@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9665 return i;
9666 }
9667
9668+/**
9669+ * atomic64_add_return_unchecked - add and return
9670+ * @i: integer value to add
9671+ * @v: pointer to type atomic64_unchecked_t
9672+ *
9673+ * Atomically adds @i to @v and returns @i + *@v
9674+ */
9675+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9676+{
9677+ alternative_atomic64(add_return_unchecked,
9678+ ASM_OUTPUT2("+A" (i), "+c" (v)),
9679+ ASM_NO_INPUT_CLOBBER("memory"));
9680+ return i;
9681+}
9682+
9683 /*
9684 * Other variants with different arithmetic operators:
9685 */
9686@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9687 return a;
9688 }
9689
9690+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9691+{
9692+ long long a;
9693+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
9694+ "S" (v) : "memory", "ecx");
9695+ return a;
9696+}
9697+
9698 static inline long long atomic64_dec_return(atomic64_t *v)
9699 {
9700 long long a;
9701@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9702 }
9703
9704 /**
9705+ * atomic64_add_unchecked - add integer to atomic64 variable
9706+ * @i: integer value to add
9707+ * @v: pointer to type atomic64_unchecked_t
9708+ *
9709+ * Atomically adds @i to @v.
9710+ */
9711+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9712+{
9713+ __alternative_atomic64(add_unchecked, add_return_unchecked,
9714+ ASM_OUTPUT2("+A" (i), "+c" (v)),
9715+ ASM_NO_INPUT_CLOBBER("memory"));
9716+ return i;
9717+}
9718+
9719+/**
9720 * atomic64_sub - subtract the atomic64 variable
9721 * @i: integer value to subtract
9722 * @v: pointer to type atomic64_t
9723diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9724index 0e1cbfc..5623683 100644
9725--- a/arch/x86/include/asm/atomic64_64.h
9726+++ b/arch/x86/include/asm/atomic64_64.h
9727@@ -18,7 +18,19 @@
9728 */
9729 static inline long atomic64_read(const atomic64_t *v)
9730 {
9731- return (*(volatile long *)&(v)->counter);
9732+ return (*(volatile const long *)&(v)->counter);
9733+}
9734+
9735+/**
9736+ * atomic64_read_unchecked - read atomic64 variable
9737+ * @v: pointer of type atomic64_unchecked_t
9738+ *
9739+ * Atomically reads the value of @v.
9740+ * Doesn't imply a read memory barrier.
9741+ */
9742+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9743+{
9744+ return (*(volatile const long *)&(v)->counter);
9745 }
9746
9747 /**
9748@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9749 }
9750
9751 /**
9752+ * atomic64_set_unchecked - set atomic64 variable
9753+ * @v: pointer to type atomic64_unchecked_t
9754+ * @i: required value
9755+ *
9756+ * Atomically sets the value of @v to @i.
9757+ */
9758+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9759+{
9760+ v->counter = i;
9761+}
9762+
9763+/**
9764 * atomic64_add - add integer to atomic64 variable
9765 * @i: integer value to add
9766 * @v: pointer to type atomic64_t
9767@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9768 */
9769 static inline void atomic64_add(long i, atomic64_t *v)
9770 {
9771+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
9772+
9773+#ifdef CONFIG_PAX_REFCOUNT
9774+ "jno 0f\n"
9775+ LOCK_PREFIX "subq %1,%0\n"
9776+ "int $4\n0:\n"
9777+ _ASM_EXTABLE(0b, 0b)
9778+#endif
9779+
9780+ : "=m" (v->counter)
9781+ : "er" (i), "m" (v->counter));
9782+}
9783+
9784+/**
9785+ * atomic64_add_unchecked - add integer to atomic64 variable
9786+ * @i: integer value to add
9787+ * @v: pointer to type atomic64_unchecked_t
9788+ *
9789+ * Atomically adds @i to @v.
9790+ */
9791+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9792+{
9793 asm volatile(LOCK_PREFIX "addq %1,%0"
9794 : "=m" (v->counter)
9795 : "er" (i), "m" (v->counter));
9796@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9797 */
9798 static inline void atomic64_sub(long i, atomic64_t *v)
9799 {
9800- asm volatile(LOCK_PREFIX "subq %1,%0"
9801+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
9802+
9803+#ifdef CONFIG_PAX_REFCOUNT
9804+ "jno 0f\n"
9805+ LOCK_PREFIX "addq %1,%0\n"
9806+ "int $4\n0:\n"
9807+ _ASM_EXTABLE(0b, 0b)
9808+#endif
9809+
9810+ : "=m" (v->counter)
9811+ : "er" (i), "m" (v->counter));
9812+}
9813+
9814+/**
9815+ * atomic64_sub_unchecked - subtract the atomic64 variable
9816+ * @i: integer value to subtract
9817+ * @v: pointer to type atomic64_unchecked_t
9818+ *
9819+ * Atomically subtracts @i from @v.
9820+ */
9821+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9822+{
9823+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
9824 : "=m" (v->counter)
9825 : "er" (i), "m" (v->counter));
9826 }
9827@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9828 {
9829 unsigned char c;
9830
9831- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9832+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
9833+
9834+#ifdef CONFIG_PAX_REFCOUNT
9835+ "jno 0f\n"
9836+ LOCK_PREFIX "addq %2,%0\n"
9837+ "int $4\n0:\n"
9838+ _ASM_EXTABLE(0b, 0b)
9839+#endif
9840+
9841+ "sete %1\n"
9842 : "=m" (v->counter), "=qm" (c)
9843 : "er" (i), "m" (v->counter) : "memory");
9844 return c;
9845@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9846 */
9847 static inline void atomic64_inc(atomic64_t *v)
9848 {
9849+ asm volatile(LOCK_PREFIX "incq %0\n"
9850+
9851+#ifdef CONFIG_PAX_REFCOUNT
9852+ "jno 0f\n"
9853+ LOCK_PREFIX "decq %0\n"
9854+ "int $4\n0:\n"
9855+ _ASM_EXTABLE(0b, 0b)
9856+#endif
9857+
9858+ : "=m" (v->counter)
9859+ : "m" (v->counter));
9860+}
9861+
9862+/**
9863+ * atomic64_inc_unchecked - increment atomic64 variable
9864+ * @v: pointer to type atomic64_unchecked_t
9865+ *
9866+ * Atomically increments @v by 1.
9867+ */
9868+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9869+{
9870 asm volatile(LOCK_PREFIX "incq %0"
9871 : "=m" (v->counter)
9872 : "m" (v->counter));
9873@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9874 */
9875 static inline void atomic64_dec(atomic64_t *v)
9876 {
9877- asm volatile(LOCK_PREFIX "decq %0"
9878+ asm volatile(LOCK_PREFIX "decq %0\n"
9879+
9880+#ifdef CONFIG_PAX_REFCOUNT
9881+ "jno 0f\n"
9882+ LOCK_PREFIX "incq %0\n"
9883+ "int $4\n0:\n"
9884+ _ASM_EXTABLE(0b, 0b)
9885+#endif
9886+
9887+ : "=m" (v->counter)
9888+ : "m" (v->counter));
9889+}
9890+
9891+/**
9892+ * atomic64_dec_unchecked - decrement atomic64 variable
9893+ * @v: pointer to type atomic64_t
9894+ *
9895+ * Atomically decrements @v by 1.
9896+ */
9897+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9898+{
9899+ asm volatile(LOCK_PREFIX "decq %0\n"
9900 : "=m" (v->counter)
9901 : "m" (v->counter));
9902 }
9903@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9904 {
9905 unsigned char c;
9906
9907- asm volatile(LOCK_PREFIX "decq %0; sete %1"
9908+ asm volatile(LOCK_PREFIX "decq %0\n"
9909+
9910+#ifdef CONFIG_PAX_REFCOUNT
9911+ "jno 0f\n"
9912+ LOCK_PREFIX "incq %0\n"
9913+ "int $4\n0:\n"
9914+ _ASM_EXTABLE(0b, 0b)
9915+#endif
9916+
9917+ "sete %1\n"
9918 : "=m" (v->counter), "=qm" (c)
9919 : "m" (v->counter) : "memory");
9920 return c != 0;
9921@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9922 {
9923 unsigned char c;
9924
9925- asm volatile(LOCK_PREFIX "incq %0; sete %1"
9926+ asm volatile(LOCK_PREFIX "incq %0\n"
9927+
9928+#ifdef CONFIG_PAX_REFCOUNT
9929+ "jno 0f\n"
9930+ LOCK_PREFIX "decq %0\n"
9931+ "int $4\n0:\n"
9932+ _ASM_EXTABLE(0b, 0b)
9933+#endif
9934+
9935+ "sete %1\n"
9936 : "=m" (v->counter), "=qm" (c)
9937 : "m" (v->counter) : "memory");
9938 return c != 0;
9939@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9940 {
9941 unsigned char c;
9942
9943- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9944+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
9945+
9946+#ifdef CONFIG_PAX_REFCOUNT
9947+ "jno 0f\n"
9948+ LOCK_PREFIX "subq %2,%0\n"
9949+ "int $4\n0:\n"
9950+ _ASM_EXTABLE(0b, 0b)
9951+#endif
9952+
9953+ "sets %1\n"
9954 : "=m" (v->counter), "=qm" (c)
9955 : "er" (i), "m" (v->counter) : "memory");
9956 return c;
9957@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9958 */
9959 static inline long atomic64_add_return(long i, atomic64_t *v)
9960 {
9961+ return i + xadd_check_overflow(&v->counter, i);
9962+}
9963+
9964+/**
9965+ * atomic64_add_return_unchecked - add and return
9966+ * @i: integer value to add
9967+ * @v: pointer to type atomic64_unchecked_t
9968+ *
9969+ * Atomically adds @i to @v and returns @i + @v
9970+ */
9971+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9972+{
9973 return i + xadd(&v->counter, i);
9974 }
9975
9976@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
9977 }
9978
9979 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
9980+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9981+{
9982+ return atomic64_add_return_unchecked(1, v);
9983+}
9984 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
9985
9986 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9987@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9988 return cmpxchg(&v->counter, old, new);
9989 }
9990
9991+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
9992+{
9993+ return cmpxchg(&v->counter, old, new);
9994+}
9995+
9996 static inline long atomic64_xchg(atomic64_t *v, long new)
9997 {
9998 return xchg(&v->counter, new);
9999@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
10000 */
10001 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
10002 {
10003- long c, old;
10004+ long c, old, new;
10005 c = atomic64_read(v);
10006 for (;;) {
10007- if (unlikely(c == (u)))
10008+ if (unlikely(c == u))
10009 break;
10010- old = atomic64_cmpxchg((v), c, c + (a));
10011+
10012+ asm volatile("add %2,%0\n"
10013+
10014+#ifdef CONFIG_PAX_REFCOUNT
10015+ "jno 0f\n"
10016+ "sub %2,%0\n"
10017+ "int $4\n0:\n"
10018+ _ASM_EXTABLE(0b, 0b)
10019+#endif
10020+
10021+ : "=r" (new)
10022+ : "0" (c), "ir" (a));
10023+
10024+ old = atomic64_cmpxchg(v, c, new);
10025 if (likely(old == c))
10026 break;
10027 c = old;
10028 }
10029- return c != (u);
10030+ return c != u;
10031 }
10032
10033 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10034diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10035index a6983b2..63f48a2 100644
10036--- a/arch/x86/include/asm/bitops.h
10037+++ b/arch/x86/include/asm/bitops.h
10038@@ -40,7 +40,7 @@
10039 * a mask operation on a byte.
10040 */
10041 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10042-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10043+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10044 #define CONST_MASK(nr) (1 << ((nr) & 7))
10045
10046 /**
10047diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10048index b13fe63..0dab13a 100644
10049--- a/arch/x86/include/asm/boot.h
10050+++ b/arch/x86/include/asm/boot.h
10051@@ -11,10 +11,15 @@
10052 #include <asm/pgtable_types.h>
10053
10054 /* Physical address where kernel should be loaded. */
10055-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10056+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10057 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10058 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10059
10060+#ifndef __ASSEMBLY__
10061+extern unsigned char __LOAD_PHYSICAL_ADDR[];
10062+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10063+#endif
10064+
10065 /* Minimum kernel alignment, as a power of two */
10066 #ifdef CONFIG_X86_64
10067 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10068diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10069index 48f99f1..d78ebf9 100644
10070--- a/arch/x86/include/asm/cache.h
10071+++ b/arch/x86/include/asm/cache.h
10072@@ -5,12 +5,13 @@
10073
10074 /* L1 cache line size */
10075 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10076-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10077+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10078
10079 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10080+#define __read_only __attribute__((__section__(".data..read_only")))
10081
10082 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10083-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10084+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10085
10086 #ifdef CONFIG_X86_VSMP
10087 #ifdef CONFIG_SMP
10088diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10089index 9863ee3..4a1f8e1 100644
10090--- a/arch/x86/include/asm/cacheflush.h
10091+++ b/arch/x86/include/asm/cacheflush.h
10092@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10093 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10094
10095 if (pg_flags == _PGMT_DEFAULT)
10096- return -1;
10097+ return ~0UL;
10098 else if (pg_flags == _PGMT_WC)
10099 return _PAGE_CACHE_WC;
10100 else if (pg_flags == _PGMT_UC_MINUS)
10101diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10102index 46fc474..b02b0f9 100644
10103--- a/arch/x86/include/asm/checksum_32.h
10104+++ b/arch/x86/include/asm/checksum_32.h
10105@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10106 int len, __wsum sum,
10107 int *src_err_ptr, int *dst_err_ptr);
10108
10109+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10110+ int len, __wsum sum,
10111+ int *src_err_ptr, int *dst_err_ptr);
10112+
10113+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10114+ int len, __wsum sum,
10115+ int *src_err_ptr, int *dst_err_ptr);
10116+
10117 /*
10118 * Note: when you get a NULL pointer exception here this means someone
10119 * passed in an incorrect kernel address to one of these functions.
10120@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10121 int *err_ptr)
10122 {
10123 might_sleep();
10124- return csum_partial_copy_generic((__force void *)src, dst,
10125+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
10126 len, sum, err_ptr, NULL);
10127 }
10128
10129@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10130 {
10131 might_sleep();
10132 if (access_ok(VERIFY_WRITE, dst, len))
10133- return csum_partial_copy_generic(src, (__force void *)dst,
10134+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10135 len, sum, NULL, err_ptr);
10136
10137 if (len)
10138diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10139index 99480e5..d81165b 100644
10140--- a/arch/x86/include/asm/cmpxchg.h
10141+++ b/arch/x86/include/asm/cmpxchg.h
10142@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10143 __compiletime_error("Bad argument size for cmpxchg");
10144 extern void __xadd_wrong_size(void)
10145 __compiletime_error("Bad argument size for xadd");
10146+extern void __xadd_check_overflow_wrong_size(void)
10147+ __compiletime_error("Bad argument size for xadd_check_overflow");
10148 extern void __add_wrong_size(void)
10149 __compiletime_error("Bad argument size for add");
10150+extern void __add_check_overflow_wrong_size(void)
10151+ __compiletime_error("Bad argument size for add_check_overflow");
10152
10153 /*
10154 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10155@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10156 __ret; \
10157 })
10158
10159+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10160+ ({ \
10161+ __typeof__ (*(ptr)) __ret = (arg); \
10162+ switch (sizeof(*(ptr))) { \
10163+ case __X86_CASE_L: \
10164+ asm volatile (lock #op "l %0, %1\n" \
10165+ "jno 0f\n" \
10166+ "mov %0,%1\n" \
10167+ "int $4\n0:\n" \
10168+ _ASM_EXTABLE(0b, 0b) \
10169+ : "+r" (__ret), "+m" (*(ptr)) \
10170+ : : "memory", "cc"); \
10171+ break; \
10172+ case __X86_CASE_Q: \
10173+ asm volatile (lock #op "q %q0, %1\n" \
10174+ "jno 0f\n" \
10175+ "mov %0,%1\n" \
10176+ "int $4\n0:\n" \
10177+ _ASM_EXTABLE(0b, 0b) \
10178+ : "+r" (__ret), "+m" (*(ptr)) \
10179+ : : "memory", "cc"); \
10180+ break; \
10181+ default: \
10182+ __ ## op ## _check_overflow_wrong_size(); \
10183+ } \
10184+ __ret; \
10185+ })
10186+
10187 /*
10188 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10189 * Since this is generally used to protect other memory information, we
10190@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10191 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10192 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10193
10194+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10195+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10196+
10197 #define __add(ptr, inc, lock) \
10198 ({ \
10199 __typeof__ (*(ptr)) __ret = (inc); \
10200diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10201index f91e80f..7f9bd27 100644
10202--- a/arch/x86/include/asm/cpufeature.h
10203+++ b/arch/x86/include/asm/cpufeature.h
10204@@ -371,7 +371,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10205 ".section .discard,\"aw\",@progbits\n"
10206 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10207 ".previous\n"
10208- ".section .altinstr_replacement,\"ax\"\n"
10209+ ".section .altinstr_replacement,\"a\"\n"
10210 "3: movb $1,%0\n"
10211 "4:\n"
10212 ".previous\n"
10213diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10214index 8bf1c06..f723dfd 100644
10215--- a/arch/x86/include/asm/desc.h
10216+++ b/arch/x86/include/asm/desc.h
10217@@ -4,6 +4,7 @@
10218 #include <asm/desc_defs.h>
10219 #include <asm/ldt.h>
10220 #include <asm/mmu.h>
10221+#include <asm/pgtable.h>
10222
10223 #include <linux/smp.h>
10224 #include <linux/percpu.h>
10225@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10226
10227 desc->type = (info->read_exec_only ^ 1) << 1;
10228 desc->type |= info->contents << 2;
10229+ desc->type |= info->seg_not_present ^ 1;
10230
10231 desc->s = 1;
10232 desc->dpl = 0x3;
10233@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10234 }
10235
10236 extern struct desc_ptr idt_descr;
10237-extern gate_desc idt_table[];
10238 extern struct desc_ptr nmi_idt_descr;
10239-extern gate_desc nmi_idt_table[];
10240-
10241-struct gdt_page {
10242- struct desc_struct gdt[GDT_ENTRIES];
10243-} __attribute__((aligned(PAGE_SIZE)));
10244-
10245-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10246+extern gate_desc idt_table[256];
10247+extern gate_desc nmi_idt_table[256];
10248
10249+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10250 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10251 {
10252- return per_cpu(gdt_page, cpu).gdt;
10253+ return cpu_gdt_table[cpu];
10254 }
10255
10256 #ifdef CONFIG_X86_64
10257@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10258 unsigned long base, unsigned dpl, unsigned flags,
10259 unsigned short seg)
10260 {
10261- gate->a = (seg << 16) | (base & 0xffff);
10262- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10263+ gate->gate.offset_low = base;
10264+ gate->gate.seg = seg;
10265+ gate->gate.reserved = 0;
10266+ gate->gate.type = type;
10267+ gate->gate.s = 0;
10268+ gate->gate.dpl = dpl;
10269+ gate->gate.p = 1;
10270+ gate->gate.offset_high = base >> 16;
10271 }
10272
10273 #endif
10274@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10275
10276 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10277 {
10278+ pax_open_kernel();
10279 memcpy(&idt[entry], gate, sizeof(*gate));
10280+ pax_close_kernel();
10281 }
10282
10283 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10284 {
10285+ pax_open_kernel();
10286 memcpy(&ldt[entry], desc, 8);
10287+ pax_close_kernel();
10288 }
10289
10290 static inline void
10291@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10292 default: size = sizeof(*gdt); break;
10293 }
10294
10295+ pax_open_kernel();
10296 memcpy(&gdt[entry], desc, size);
10297+ pax_close_kernel();
10298 }
10299
10300 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10301@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10302
10303 static inline void native_load_tr_desc(void)
10304 {
10305+ pax_open_kernel();
10306 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10307+ pax_close_kernel();
10308 }
10309
10310 static inline void native_load_gdt(const struct desc_ptr *dtr)
10311@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10312 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10313 unsigned int i;
10314
10315+ pax_open_kernel();
10316 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10317 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10318+ pax_close_kernel();
10319 }
10320
10321 #define _LDT_empty(info) \
10322@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10323 }
10324
10325 #ifdef CONFIG_X86_64
10326-static inline void set_nmi_gate(int gate, void *addr)
10327+static inline void set_nmi_gate(int gate, const void *addr)
10328 {
10329 gate_desc s;
10330
10331@@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10332 }
10333 #endif
10334
10335-static inline void _set_gate(int gate, unsigned type, void *addr,
10336+static inline void _set_gate(int gate, unsigned type, const void *addr,
10337 unsigned dpl, unsigned ist, unsigned seg)
10338 {
10339 gate_desc s;
10340@@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10341 * Pentium F0 0F bugfix can have resulted in the mapped
10342 * IDT being write-protected.
10343 */
10344-static inline void set_intr_gate(unsigned int n, void *addr)
10345+static inline void set_intr_gate(unsigned int n, const void *addr)
10346 {
10347 BUG_ON((unsigned)n > 0xFF);
10348 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10349@@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10350 /*
10351 * This routine sets up an interrupt gate at directory privilege level 3.
10352 */
10353-static inline void set_system_intr_gate(unsigned int n, void *addr)
10354+static inline void set_system_intr_gate(unsigned int n, const void *addr)
10355 {
10356 BUG_ON((unsigned)n > 0xFF);
10357 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10358 }
10359
10360-static inline void set_system_trap_gate(unsigned int n, void *addr)
10361+static inline void set_system_trap_gate(unsigned int n, const void *addr)
10362 {
10363 BUG_ON((unsigned)n > 0xFF);
10364 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10365 }
10366
10367-static inline void set_trap_gate(unsigned int n, void *addr)
10368+static inline void set_trap_gate(unsigned int n, const void *addr)
10369 {
10370 BUG_ON((unsigned)n > 0xFF);
10371 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10372@@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10373 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10374 {
10375 BUG_ON((unsigned)n > 0xFF);
10376- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10377+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10378 }
10379
10380-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10381+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10382 {
10383 BUG_ON((unsigned)n > 0xFF);
10384 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10385 }
10386
10387-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10388+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10389 {
10390 BUG_ON((unsigned)n > 0xFF);
10391 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10392 }
10393
10394+#ifdef CONFIG_X86_32
10395+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10396+{
10397+ struct desc_struct d;
10398+
10399+ if (likely(limit))
10400+ limit = (limit - 1UL) >> PAGE_SHIFT;
10401+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
10402+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10403+}
10404+#endif
10405+
10406 #endif /* _ASM_X86_DESC_H */
10407diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10408index 278441f..b95a174 100644
10409--- a/arch/x86/include/asm/desc_defs.h
10410+++ b/arch/x86/include/asm/desc_defs.h
10411@@ -31,6 +31,12 @@ struct desc_struct {
10412 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10413 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10414 };
10415+ struct {
10416+ u16 offset_low;
10417+ u16 seg;
10418+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10419+ unsigned offset_high: 16;
10420+ } gate;
10421 };
10422 } __attribute__((packed));
10423
10424diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10425index 3778256..c5d4fce 100644
10426--- a/arch/x86/include/asm/e820.h
10427+++ b/arch/x86/include/asm/e820.h
10428@@ -69,7 +69,7 @@ struct e820map {
10429 #define ISA_START_ADDRESS 0xa0000
10430 #define ISA_END_ADDRESS 0x100000
10431
10432-#define BIOS_BEGIN 0x000a0000
10433+#define BIOS_BEGIN 0x000c0000
10434 #define BIOS_END 0x00100000
10435
10436 #define BIOS_ROM_BASE 0xffe00000
10437diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10438index 5939f44..f8845f6 100644
10439--- a/arch/x86/include/asm/elf.h
10440+++ b/arch/x86/include/asm/elf.h
10441@@ -243,7 +243,25 @@ extern int force_personality32;
10442 the loader. We need to make sure that it is out of the way of the program
10443 that it will "exec", and that there is sufficient room for the brk. */
10444
10445+#ifdef CONFIG_PAX_SEGMEXEC
10446+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10447+#else
10448 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10449+#endif
10450+
10451+#ifdef CONFIG_PAX_ASLR
10452+#ifdef CONFIG_X86_32
10453+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10454+
10455+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10456+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10457+#else
10458+#define PAX_ELF_ET_DYN_BASE 0x400000UL
10459+
10460+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10461+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10462+#endif
10463+#endif
10464
10465 /* This yields a mask that user programs can use to figure out what
10466 instruction set this CPU supports. This could be done in user space,
10467@@ -296,16 +314,12 @@ do { \
10468
10469 #define ARCH_DLINFO \
10470 do { \
10471- if (vdso_enabled) \
10472- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10473- (unsigned long)current->mm->context.vdso); \
10474+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10475 } while (0)
10476
10477 #define ARCH_DLINFO_X32 \
10478 do { \
10479- if (vdso_enabled) \
10480- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10481- (unsigned long)current->mm->context.vdso); \
10482+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10483 } while (0)
10484
10485 #define AT_SYSINFO 32
10486@@ -320,7 +334,7 @@ else \
10487
10488 #endif /* !CONFIG_X86_32 */
10489
10490-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10491+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10492
10493 #define VDSO_ENTRY \
10494 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10495@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
10496 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10497 #define compat_arch_setup_additional_pages syscall32_setup_pages
10498
10499-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10500-#define arch_randomize_brk arch_randomize_brk
10501-
10502 /*
10503 * True on X86_32 or when emulating IA32 on X86_64
10504 */
10505diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10506index cc70c1c..d96d011 100644
10507--- a/arch/x86/include/asm/emergency-restart.h
10508+++ b/arch/x86/include/asm/emergency-restart.h
10509@@ -15,6 +15,6 @@ enum reboot_type {
10510
10511 extern enum reboot_type reboot_type;
10512
10513-extern void machine_emergency_restart(void);
10514+extern void machine_emergency_restart(void) __noreturn;
10515
10516 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10517diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
10518index 75f4c6d..ee3eb8f 100644
10519--- a/arch/x86/include/asm/fpu-internal.h
10520+++ b/arch/x86/include/asm/fpu-internal.h
10521@@ -86,6 +86,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10522 {
10523 int err;
10524
10525+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10526+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10527+ fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10528+#endif
10529+
10530 /* See comment in fxsave() below. */
10531 #ifdef CONFIG_AS_FXSAVEQ
10532 asm volatile("1: fxrstorq %[fx]\n\t"
10533@@ -115,6 +120,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10534 {
10535 int err;
10536
10537+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10538+ if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10539+ fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10540+#endif
10541+
10542 /*
10543 * Clear the bytes not touched by the fxsave and reserved
10544 * for the SW usage.
10545@@ -271,7 +281,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10546 "emms\n\t" /* clear stack tags */
10547 "fildl %P[addr]", /* set F?P to defined value */
10548 X86_FEATURE_FXSAVE_LEAK,
10549- [addr] "m" (tsk->thread.fpu.has_fpu));
10550+ [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10551
10552 return fpu_restore_checking(&tsk->thread.fpu);
10553 }
10554diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10555index 71ecbcb..bac10b7 100644
10556--- a/arch/x86/include/asm/futex.h
10557+++ b/arch/x86/include/asm/futex.h
10558@@ -11,16 +11,18 @@
10559 #include <asm/processor.h>
10560
10561 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10562+ typecheck(u32 __user *, uaddr); \
10563 asm volatile("1:\t" insn "\n" \
10564 "2:\t.section .fixup,\"ax\"\n" \
10565 "3:\tmov\t%3, %1\n" \
10566 "\tjmp\t2b\n" \
10567 "\t.previous\n" \
10568 _ASM_EXTABLE(1b, 3b) \
10569- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10570+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10571 : "i" (-EFAULT), "0" (oparg), "1" (0))
10572
10573 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10574+ typecheck(u32 __user *, uaddr); \
10575 asm volatile("1:\tmovl %2, %0\n" \
10576 "\tmovl\t%0, %3\n" \
10577 "\t" insn "\n" \
10578@@ -33,7 +35,7 @@
10579 _ASM_EXTABLE(1b, 4b) \
10580 _ASM_EXTABLE(2b, 4b) \
10581 : "=&a" (oldval), "=&r" (ret), \
10582- "+m" (*uaddr), "=&r" (tem) \
10583+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10584 : "r" (oparg), "i" (-EFAULT), "1" (0))
10585
10586 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10587@@ -60,10 +62,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10588
10589 switch (op) {
10590 case FUTEX_OP_SET:
10591- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10592+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10593 break;
10594 case FUTEX_OP_ADD:
10595- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10596+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10597 uaddr, oparg);
10598 break;
10599 case FUTEX_OP_OR:
10600@@ -122,13 +124,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10601 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10602 return -EFAULT;
10603
10604- asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10605+ asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10606 "2:\t.section .fixup, \"ax\"\n"
10607 "3:\tmov %3, %0\n"
10608 "\tjmp 2b\n"
10609 "\t.previous\n"
10610 _ASM_EXTABLE(1b, 3b)
10611- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10612+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10613 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10614 : "memory"
10615 );
10616diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10617index eb92a6e..b98b2f4 100644
10618--- a/arch/x86/include/asm/hw_irq.h
10619+++ b/arch/x86/include/asm/hw_irq.h
10620@@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10621 extern void enable_IO_APIC(void);
10622
10623 /* Statistics */
10624-extern atomic_t irq_err_count;
10625-extern atomic_t irq_mis_count;
10626+extern atomic_unchecked_t irq_err_count;
10627+extern atomic_unchecked_t irq_mis_count;
10628
10629 /* EISA */
10630 extern void eisa_set_level_irq(unsigned int irq);
10631diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10632index d8e8eef..99f81ae 100644
10633--- a/arch/x86/include/asm/io.h
10634+++ b/arch/x86/include/asm/io.h
10635@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10636
10637 #include <linux/vmalloc.h>
10638
10639+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10640+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10641+{
10642+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10643+}
10644+
10645+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10646+{
10647+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10648+}
10649+
10650 /*
10651 * Convert a virtual cached pointer to an uncached pointer
10652 */
10653diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10654index bba3cf8..06bc8da 100644
10655--- a/arch/x86/include/asm/irqflags.h
10656+++ b/arch/x86/include/asm/irqflags.h
10657@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10658 sti; \
10659 sysexit
10660
10661+#define GET_CR0_INTO_RDI mov %cr0, %rdi
10662+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10663+#define GET_CR3_INTO_RDI mov %cr3, %rdi
10664+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10665+
10666 #else
10667 #define INTERRUPT_RETURN iret
10668 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10669diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10670index 5478825..839e88c 100644
10671--- a/arch/x86/include/asm/kprobes.h
10672+++ b/arch/x86/include/asm/kprobes.h
10673@@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10674 #define RELATIVEJUMP_SIZE 5
10675 #define RELATIVECALL_OPCODE 0xe8
10676 #define RELATIVE_ADDR_SIZE 4
10677-#define MAX_STACK_SIZE 64
10678-#define MIN_STACK_SIZE(ADDR) \
10679- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10680- THREAD_SIZE - (unsigned long)(ADDR))) \
10681- ? (MAX_STACK_SIZE) \
10682- : (((unsigned long)current_thread_info()) + \
10683- THREAD_SIZE - (unsigned long)(ADDR)))
10684+#define MAX_STACK_SIZE 64UL
10685+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10686
10687 #define flush_insn_slot(p) do { } while (0)
10688
10689diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10690index db7c1f2..92f130a 100644
10691--- a/arch/x86/include/asm/kvm_host.h
10692+++ b/arch/x86/include/asm/kvm_host.h
10693@@ -680,7 +680,7 @@ struct kvm_x86_ops {
10694 int (*check_intercept)(struct kvm_vcpu *vcpu,
10695 struct x86_instruction_info *info,
10696 enum x86_intercept_stage stage);
10697-};
10698+} __do_const;
10699
10700 struct kvm_arch_async_pf {
10701 u32 token;
10702diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10703index c8bed0d..e5721fa 100644
10704--- a/arch/x86/include/asm/local.h
10705+++ b/arch/x86/include/asm/local.h
10706@@ -17,26 +17,58 @@ typedef struct {
10707
10708 static inline void local_inc(local_t *l)
10709 {
10710- asm volatile(_ASM_INC "%0"
10711+ asm volatile(_ASM_INC "%0\n"
10712+
10713+#ifdef CONFIG_PAX_REFCOUNT
10714+ "jno 0f\n"
10715+ _ASM_DEC "%0\n"
10716+ "int $4\n0:\n"
10717+ _ASM_EXTABLE(0b, 0b)
10718+#endif
10719+
10720 : "+m" (l->a.counter));
10721 }
10722
10723 static inline void local_dec(local_t *l)
10724 {
10725- asm volatile(_ASM_DEC "%0"
10726+ asm volatile(_ASM_DEC "%0\n"
10727+
10728+#ifdef CONFIG_PAX_REFCOUNT
10729+ "jno 0f\n"
10730+ _ASM_INC "%0\n"
10731+ "int $4\n0:\n"
10732+ _ASM_EXTABLE(0b, 0b)
10733+#endif
10734+
10735 : "+m" (l->a.counter));
10736 }
10737
10738 static inline void local_add(long i, local_t *l)
10739 {
10740- asm volatile(_ASM_ADD "%1,%0"
10741+ asm volatile(_ASM_ADD "%1,%0\n"
10742+
10743+#ifdef CONFIG_PAX_REFCOUNT
10744+ "jno 0f\n"
10745+ _ASM_SUB "%1,%0\n"
10746+ "int $4\n0:\n"
10747+ _ASM_EXTABLE(0b, 0b)
10748+#endif
10749+
10750 : "+m" (l->a.counter)
10751 : "ir" (i));
10752 }
10753
10754 static inline void local_sub(long i, local_t *l)
10755 {
10756- asm volatile(_ASM_SUB "%1,%0"
10757+ asm volatile(_ASM_SUB "%1,%0\n"
10758+
10759+#ifdef CONFIG_PAX_REFCOUNT
10760+ "jno 0f\n"
10761+ _ASM_ADD "%1,%0\n"
10762+ "int $4\n0:\n"
10763+ _ASM_EXTABLE(0b, 0b)
10764+#endif
10765+
10766 : "+m" (l->a.counter)
10767 : "ir" (i));
10768 }
10769@@ -54,7 +86,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10770 {
10771 unsigned char c;
10772
10773- asm volatile(_ASM_SUB "%2,%0; sete %1"
10774+ asm volatile(_ASM_SUB "%2,%0\n"
10775+
10776+#ifdef CONFIG_PAX_REFCOUNT
10777+ "jno 0f\n"
10778+ _ASM_ADD "%2,%0\n"
10779+ "int $4\n0:\n"
10780+ _ASM_EXTABLE(0b, 0b)
10781+#endif
10782+
10783+ "sete %1\n"
10784 : "+m" (l->a.counter), "=qm" (c)
10785 : "ir" (i) : "memory");
10786 return c;
10787@@ -72,7 +113,16 @@ static inline int local_dec_and_test(local_t *l)
10788 {
10789 unsigned char c;
10790
10791- asm volatile(_ASM_DEC "%0; sete %1"
10792+ asm volatile(_ASM_DEC "%0\n"
10793+
10794+#ifdef CONFIG_PAX_REFCOUNT
10795+ "jno 0f\n"
10796+ _ASM_INC "%0\n"
10797+ "int $4\n0:\n"
10798+ _ASM_EXTABLE(0b, 0b)
10799+#endif
10800+
10801+ "sete %1\n"
10802 : "+m" (l->a.counter), "=qm" (c)
10803 : : "memory");
10804 return c != 0;
10805@@ -90,7 +140,16 @@ static inline int local_inc_and_test(local_t *l)
10806 {
10807 unsigned char c;
10808
10809- asm volatile(_ASM_INC "%0; sete %1"
10810+ asm volatile(_ASM_INC "%0\n"
10811+
10812+#ifdef CONFIG_PAX_REFCOUNT
10813+ "jno 0f\n"
10814+ _ASM_DEC "%0\n"
10815+ "int $4\n0:\n"
10816+ _ASM_EXTABLE(0b, 0b)
10817+#endif
10818+
10819+ "sete %1\n"
10820 : "+m" (l->a.counter), "=qm" (c)
10821 : : "memory");
10822 return c != 0;
10823@@ -109,7 +168,16 @@ static inline int local_add_negative(long i, local_t *l)
10824 {
10825 unsigned char c;
10826
10827- asm volatile(_ASM_ADD "%2,%0; sets %1"
10828+ asm volatile(_ASM_ADD "%2,%0\n"
10829+
10830+#ifdef CONFIG_PAX_REFCOUNT
10831+ "jno 0f\n"
10832+ _ASM_SUB "%2,%0\n"
10833+ "int $4\n0:\n"
10834+ _ASM_EXTABLE(0b, 0b)
10835+#endif
10836+
10837+ "sets %1\n"
10838 : "+m" (l->a.counter), "=qm" (c)
10839 : "ir" (i) : "memory");
10840 return c;
10841@@ -132,7 +200,15 @@ static inline long local_add_return(long i, local_t *l)
10842 #endif
10843 /* Modern 486+ processor */
10844 __i = i;
10845- asm volatile(_ASM_XADD "%0, %1;"
10846+ asm volatile(_ASM_XADD "%0, %1\n"
10847+
10848+#ifdef CONFIG_PAX_REFCOUNT
10849+ "jno 0f\n"
10850+ _ASM_MOV "%0,%1\n"
10851+ "int $4\n0:\n"
10852+ _ASM_EXTABLE(0b, 0b)
10853+#endif
10854+
10855 : "+r" (i), "+m" (l->a.counter)
10856 : : "memory");
10857 return i + __i;
10858diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10859index 593e51d..fa69c9a 100644
10860--- a/arch/x86/include/asm/mman.h
10861+++ b/arch/x86/include/asm/mman.h
10862@@ -5,4 +5,14 @@
10863
10864 #include <asm-generic/mman.h>
10865
10866+#ifdef __KERNEL__
10867+#ifndef __ASSEMBLY__
10868+#ifdef CONFIG_X86_32
10869+#define arch_mmap_check i386_mmap_check
10870+int i386_mmap_check(unsigned long addr, unsigned long len,
10871+ unsigned long flags);
10872+#endif
10873+#endif
10874+#endif
10875+
10876 #endif /* _ASM_X86_MMAN_H */
10877diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10878index 5f55e69..e20bfb1 100644
10879--- a/arch/x86/include/asm/mmu.h
10880+++ b/arch/x86/include/asm/mmu.h
10881@@ -9,7 +9,7 @@
10882 * we put the segment information here.
10883 */
10884 typedef struct {
10885- void *ldt;
10886+ struct desc_struct *ldt;
10887 int size;
10888
10889 #ifdef CONFIG_X86_64
10890@@ -18,7 +18,19 @@ typedef struct {
10891 #endif
10892
10893 struct mutex lock;
10894- void *vdso;
10895+ unsigned long vdso;
10896+
10897+#ifdef CONFIG_X86_32
10898+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10899+ unsigned long user_cs_base;
10900+ unsigned long user_cs_limit;
10901+
10902+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10903+ cpumask_t cpu_user_cs_mask;
10904+#endif
10905+
10906+#endif
10907+#endif
10908 } mm_context_t;
10909
10910 #ifdef CONFIG_SMP
10911diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10912index cdbf367..adb37ac 100644
10913--- a/arch/x86/include/asm/mmu_context.h
10914+++ b/arch/x86/include/asm/mmu_context.h
10915@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10916
10917 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10918 {
10919+
10920+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10921+ unsigned int i;
10922+ pgd_t *pgd;
10923+
10924+ pax_open_kernel();
10925+ pgd = get_cpu_pgd(smp_processor_id());
10926+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10927+ set_pgd_batched(pgd+i, native_make_pgd(0));
10928+ pax_close_kernel();
10929+#endif
10930+
10931 #ifdef CONFIG_SMP
10932 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10933 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10934@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10935 struct task_struct *tsk)
10936 {
10937 unsigned cpu = smp_processor_id();
10938+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10939+ int tlbstate = TLBSTATE_OK;
10940+#endif
10941
10942 if (likely(prev != next)) {
10943 #ifdef CONFIG_SMP
10944+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10945+ tlbstate = this_cpu_read(cpu_tlbstate.state);
10946+#endif
10947 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10948 this_cpu_write(cpu_tlbstate.active_mm, next);
10949 #endif
10950 cpumask_set_cpu(cpu, mm_cpumask(next));
10951
10952 /* Re-load page tables */
10953+#ifdef CONFIG_PAX_PER_CPU_PGD
10954+ pax_open_kernel();
10955+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
10956+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
10957+ pax_close_kernel();
10958+ load_cr3(get_cpu_pgd(cpu));
10959+#else
10960 load_cr3(next->pgd);
10961+#endif
10962
10963 /* stop flush ipis for the previous mm */
10964 cpumask_clear_cpu(cpu, mm_cpumask(prev));
10965@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10966 */
10967 if (unlikely(prev->context.ldt != next->context.ldt))
10968 load_LDT_nolock(&next->context);
10969- }
10970+
10971+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10972+ if (!(__supported_pte_mask & _PAGE_NX)) {
10973+ smp_mb__before_clear_bit();
10974+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
10975+ smp_mb__after_clear_bit();
10976+ cpu_set(cpu, next->context.cpu_user_cs_mask);
10977+ }
10978+#endif
10979+
10980+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10981+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
10982+ prev->context.user_cs_limit != next->context.user_cs_limit))
10983+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10984 #ifdef CONFIG_SMP
10985+ else if (unlikely(tlbstate != TLBSTATE_OK))
10986+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10987+#endif
10988+#endif
10989+
10990+ }
10991 else {
10992+
10993+#ifdef CONFIG_PAX_PER_CPU_PGD
10994+ pax_open_kernel();
10995+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
10996+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
10997+ pax_close_kernel();
10998+ load_cr3(get_cpu_pgd(cpu));
10999+#endif
11000+
11001+#ifdef CONFIG_SMP
11002 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11003 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
11004
11005@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11006 * tlb flush IPI delivery. We must reload CR3
11007 * to make sure to use no freed page tables.
11008 */
11009+
11010+#ifndef CONFIG_PAX_PER_CPU_PGD
11011 load_cr3(next->pgd);
11012+#endif
11013+
11014 load_LDT_nolock(&next->context);
11015+
11016+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
11017+ if (!(__supported_pte_mask & _PAGE_NX))
11018+ cpu_set(cpu, next->context.cpu_user_cs_mask);
11019+#endif
11020+
11021+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11022+#ifdef CONFIG_PAX_PAGEEXEC
11023+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
11024+#endif
11025+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11026+#endif
11027+
11028 }
11029+#endif
11030 }
11031-#endif
11032 }
11033
11034 #define activate_mm(prev, next) \
11035diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
11036index 9eae775..c914fea 100644
11037--- a/arch/x86/include/asm/module.h
11038+++ b/arch/x86/include/asm/module.h
11039@@ -5,6 +5,7 @@
11040
11041 #ifdef CONFIG_X86_64
11042 /* X86_64 does not define MODULE_PROC_FAMILY */
11043+#define MODULE_PROC_FAMILY ""
11044 #elif defined CONFIG_M386
11045 #define MODULE_PROC_FAMILY "386 "
11046 #elif defined CONFIG_M486
11047@@ -59,8 +60,20 @@
11048 #error unknown processor family
11049 #endif
11050
11051-#ifdef CONFIG_X86_32
11052-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11053+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11054+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11055+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11056+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11057+#else
11058+#define MODULE_PAX_KERNEXEC ""
11059 #endif
11060
11061+#ifdef CONFIG_PAX_MEMORY_UDEREF
11062+#define MODULE_PAX_UDEREF "UDEREF "
11063+#else
11064+#define MODULE_PAX_UDEREF ""
11065+#endif
11066+
11067+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11068+
11069 #endif /* _ASM_X86_MODULE_H */
11070diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11071index 320f7bb..e89f8f8 100644
11072--- a/arch/x86/include/asm/page_64_types.h
11073+++ b/arch/x86/include/asm/page_64_types.h
11074@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11075
11076 /* duplicated to the one in bootmem.h */
11077 extern unsigned long max_pfn;
11078-extern unsigned long phys_base;
11079+extern const unsigned long phys_base;
11080
11081 extern unsigned long __phys_addr(unsigned long);
11082 #define __phys_reloc_hide(x) (x)
11083diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11084index 6cbbabf..11b3aed 100644
11085--- a/arch/x86/include/asm/paravirt.h
11086+++ b/arch/x86/include/asm/paravirt.h
11087@@ -668,6 +668,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11088 val);
11089 }
11090
11091+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11092+{
11093+ pgdval_t val = native_pgd_val(pgd);
11094+
11095+ if (sizeof(pgdval_t) > sizeof(long))
11096+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11097+ val, (u64)val >> 32);
11098+ else
11099+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11100+ val);
11101+}
11102+
11103 static inline void pgd_clear(pgd_t *pgdp)
11104 {
11105 set_pgd(pgdp, __pgd(0));
11106@@ -749,6 +761,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11107 pv_mmu_ops.set_fixmap(idx, phys, flags);
11108 }
11109
11110+#ifdef CONFIG_PAX_KERNEXEC
11111+static inline unsigned long pax_open_kernel(void)
11112+{
11113+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11114+}
11115+
11116+static inline unsigned long pax_close_kernel(void)
11117+{
11118+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11119+}
11120+#else
11121+static inline unsigned long pax_open_kernel(void) { return 0; }
11122+static inline unsigned long pax_close_kernel(void) { return 0; }
11123+#endif
11124+
11125 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11126
11127 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11128@@ -965,7 +992,7 @@ extern void default_banner(void);
11129
11130 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11131 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11132-#define PARA_INDIRECT(addr) *%cs:addr
11133+#define PARA_INDIRECT(addr) *%ss:addr
11134 #endif
11135
11136 #define INTERRUPT_RETURN \
11137@@ -1040,6 +1067,21 @@ extern void default_banner(void);
11138 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11139 CLBR_NONE, \
11140 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11141+
11142+#define GET_CR0_INTO_RDI \
11143+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11144+ mov %rax,%rdi
11145+
11146+#define SET_RDI_INTO_CR0 \
11147+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11148+
11149+#define GET_CR3_INTO_RDI \
11150+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11151+ mov %rax,%rdi
11152+
11153+#define SET_RDI_INTO_CR3 \
11154+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11155+
11156 #endif /* CONFIG_X86_32 */
11157
11158 #endif /* __ASSEMBLY__ */
11159diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11160index 8e8b9a4..f07d725 100644
11161--- a/arch/x86/include/asm/paravirt_types.h
11162+++ b/arch/x86/include/asm/paravirt_types.h
11163@@ -84,20 +84,20 @@ struct pv_init_ops {
11164 */
11165 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11166 unsigned long addr, unsigned len);
11167-};
11168+} __no_const;
11169
11170
11171 struct pv_lazy_ops {
11172 /* Set deferred update mode, used for batching operations. */
11173 void (*enter)(void);
11174 void (*leave)(void);
11175-};
11176+} __no_const;
11177
11178 struct pv_time_ops {
11179 unsigned long long (*sched_clock)(void);
11180 unsigned long long (*steal_clock)(int cpu);
11181 unsigned long (*get_tsc_khz)(void);
11182-};
11183+} __no_const;
11184
11185 struct pv_cpu_ops {
11186 /* hooks for various privileged instructions */
11187@@ -193,7 +193,7 @@ struct pv_cpu_ops {
11188
11189 void (*start_context_switch)(struct task_struct *prev);
11190 void (*end_context_switch)(struct task_struct *next);
11191-};
11192+} __no_const;
11193
11194 struct pv_irq_ops {
11195 /*
11196@@ -224,7 +224,7 @@ struct pv_apic_ops {
11197 unsigned long start_eip,
11198 unsigned long start_esp);
11199 #endif
11200-};
11201+} __no_const;
11202
11203 struct pv_mmu_ops {
11204 unsigned long (*read_cr2)(void);
11205@@ -313,6 +313,7 @@ struct pv_mmu_ops {
11206 struct paravirt_callee_save make_pud;
11207
11208 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11209+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11210 #endif /* PAGETABLE_LEVELS == 4 */
11211 #endif /* PAGETABLE_LEVELS >= 3 */
11212
11213@@ -324,6 +325,12 @@ struct pv_mmu_ops {
11214 an mfn. We can tell which is which from the index. */
11215 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11216 phys_addr_t phys, pgprot_t flags);
11217+
11218+#ifdef CONFIG_PAX_KERNEXEC
11219+ unsigned long (*pax_open_kernel)(void);
11220+ unsigned long (*pax_close_kernel)(void);
11221+#endif
11222+
11223 };
11224
11225 struct arch_spinlock;
11226@@ -334,7 +341,7 @@ struct pv_lock_ops {
11227 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11228 int (*spin_trylock)(struct arch_spinlock *lock);
11229 void (*spin_unlock)(struct arch_spinlock *lock);
11230-};
11231+} __no_const;
11232
11233 /* This contains all the paravirt structures: we get a convenient
11234 * number for each function using the offset which we use to indicate
11235diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11236index b4389a4..7024269 100644
11237--- a/arch/x86/include/asm/pgalloc.h
11238+++ b/arch/x86/include/asm/pgalloc.h
11239@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11240 pmd_t *pmd, pte_t *pte)
11241 {
11242 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11243+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11244+}
11245+
11246+static inline void pmd_populate_user(struct mm_struct *mm,
11247+ pmd_t *pmd, pte_t *pte)
11248+{
11249+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11250 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11251 }
11252
11253@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11254
11255 #ifdef CONFIG_X86_PAE
11256 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11257+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11258+{
11259+ pud_populate(mm, pudp, pmd);
11260+}
11261 #else /* !CONFIG_X86_PAE */
11262 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11263 {
11264 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11265 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11266 }
11267+
11268+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11269+{
11270+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11271+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11272+}
11273 #endif /* CONFIG_X86_PAE */
11274
11275 #if PAGETABLE_LEVELS > 3
11276@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11277 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11278 }
11279
11280+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11281+{
11282+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11283+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11284+}
11285+
11286 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11287 {
11288 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11289diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11290index 98391db..8f6984e 100644
11291--- a/arch/x86/include/asm/pgtable-2level.h
11292+++ b/arch/x86/include/asm/pgtable-2level.h
11293@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11294
11295 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11296 {
11297+ pax_open_kernel();
11298 *pmdp = pmd;
11299+ pax_close_kernel();
11300 }
11301
11302 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11303diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11304index cb00ccc..17e9054 100644
11305--- a/arch/x86/include/asm/pgtable-3level.h
11306+++ b/arch/x86/include/asm/pgtable-3level.h
11307@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11308
11309 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11310 {
11311+ pax_open_kernel();
11312 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11313+ pax_close_kernel();
11314 }
11315
11316 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11317 {
11318+ pax_open_kernel();
11319 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11320+ pax_close_kernel();
11321 }
11322
11323 /*
11324diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11325index 49afb3f..91a8c63 100644
11326--- a/arch/x86/include/asm/pgtable.h
11327+++ b/arch/x86/include/asm/pgtable.h
11328@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11329
11330 #ifndef __PAGETABLE_PUD_FOLDED
11331 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11332+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11333 #define pgd_clear(pgd) native_pgd_clear(pgd)
11334 #endif
11335
11336@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11337
11338 #define arch_end_context_switch(prev) do {} while(0)
11339
11340+#define pax_open_kernel() native_pax_open_kernel()
11341+#define pax_close_kernel() native_pax_close_kernel()
11342 #endif /* CONFIG_PARAVIRT */
11343
11344+#define __HAVE_ARCH_PAX_OPEN_KERNEL
11345+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11346+
11347+#ifdef CONFIG_PAX_KERNEXEC
11348+static inline unsigned long native_pax_open_kernel(void)
11349+{
11350+ unsigned long cr0;
11351+
11352+ preempt_disable();
11353+ barrier();
11354+ cr0 = read_cr0() ^ X86_CR0_WP;
11355+ BUG_ON(unlikely(cr0 & X86_CR0_WP));
11356+ write_cr0(cr0);
11357+ return cr0 ^ X86_CR0_WP;
11358+}
11359+
11360+static inline unsigned long native_pax_close_kernel(void)
11361+{
11362+ unsigned long cr0;
11363+
11364+ cr0 = read_cr0() ^ X86_CR0_WP;
11365+ BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11366+ write_cr0(cr0);
11367+ barrier();
11368+ preempt_enable_no_resched();
11369+ return cr0 ^ X86_CR0_WP;
11370+}
11371+#else
11372+static inline unsigned long native_pax_open_kernel(void) { return 0; }
11373+static inline unsigned long native_pax_close_kernel(void) { return 0; }
11374+#endif
11375+
11376 /*
11377 * The following only work if pte_present() is true.
11378 * Undefined behaviour if not..
11379 */
11380+static inline int pte_user(pte_t pte)
11381+{
11382+ return pte_val(pte) & _PAGE_USER;
11383+}
11384+
11385 static inline int pte_dirty(pte_t pte)
11386 {
11387 return pte_flags(pte) & _PAGE_DIRTY;
11388@@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11389 return pte_clear_flags(pte, _PAGE_RW);
11390 }
11391
11392+static inline pte_t pte_mkread(pte_t pte)
11393+{
11394+ return __pte(pte_val(pte) | _PAGE_USER);
11395+}
11396+
11397 static inline pte_t pte_mkexec(pte_t pte)
11398 {
11399- return pte_clear_flags(pte, _PAGE_NX);
11400+#ifdef CONFIG_X86_PAE
11401+ if (__supported_pte_mask & _PAGE_NX)
11402+ return pte_clear_flags(pte, _PAGE_NX);
11403+ else
11404+#endif
11405+ return pte_set_flags(pte, _PAGE_USER);
11406+}
11407+
11408+static inline pte_t pte_exprotect(pte_t pte)
11409+{
11410+#ifdef CONFIG_X86_PAE
11411+ if (__supported_pte_mask & _PAGE_NX)
11412+ return pte_set_flags(pte, _PAGE_NX);
11413+ else
11414+#endif
11415+ return pte_clear_flags(pte, _PAGE_USER);
11416 }
11417
11418 static inline pte_t pte_mkdirty(pte_t pte)
11419@@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11420 #endif
11421
11422 #ifndef __ASSEMBLY__
11423+
11424+#ifdef CONFIG_PAX_PER_CPU_PGD
11425+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11426+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11427+{
11428+ return cpu_pgd[cpu];
11429+}
11430+#endif
11431+
11432 #include <linux/mm_types.h>
11433
11434 static inline int pte_none(pte_t pte)
11435@@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11436
11437 static inline int pgd_bad(pgd_t pgd)
11438 {
11439- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11440+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11441 }
11442
11443 static inline int pgd_none(pgd_t pgd)
11444@@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
11445 * pgd_offset() returns a (pgd_t *)
11446 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11447 */
11448-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11449+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11450+
11451+#ifdef CONFIG_PAX_PER_CPU_PGD
11452+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11453+#endif
11454+
11455 /*
11456 * a shortcut which implies the use of the kernel's pgd, instead
11457 * of a process's
11458@@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
11459 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11460 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11461
11462+#ifdef CONFIG_X86_32
11463+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11464+#else
11465+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11466+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11467+
11468+#ifdef CONFIG_PAX_MEMORY_UDEREF
11469+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11470+#else
11471+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11472+#endif
11473+
11474+#endif
11475+
11476 #ifndef __ASSEMBLY__
11477
11478 extern int direct_gbpages;
11479@@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11480 * dst and src can be on the same page, but the range must not overlap,
11481 * and must not cross a page boundary.
11482 */
11483-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11484+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11485 {
11486- memcpy(dst, src, count * sizeof(pgd_t));
11487+ pax_open_kernel();
11488+ while (count--)
11489+ *dst++ = *src++;
11490+ pax_close_kernel();
11491 }
11492
11493+#ifdef CONFIG_PAX_PER_CPU_PGD
11494+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11495+#endif
11496+
11497+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11498+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11499+#else
11500+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11501+#endif
11502
11503 #include <asm-generic/pgtable.h>
11504 #endif /* __ASSEMBLY__ */
11505diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11506index 0c92113..34a77c6 100644
11507--- a/arch/x86/include/asm/pgtable_32.h
11508+++ b/arch/x86/include/asm/pgtable_32.h
11509@@ -25,9 +25,6 @@
11510 struct mm_struct;
11511 struct vm_area_struct;
11512
11513-extern pgd_t swapper_pg_dir[1024];
11514-extern pgd_t initial_page_table[1024];
11515-
11516 static inline void pgtable_cache_init(void) { }
11517 static inline void check_pgt_cache(void) { }
11518 void paging_init(void);
11519@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11520 # include <asm/pgtable-2level.h>
11521 #endif
11522
11523+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11524+extern pgd_t initial_page_table[PTRS_PER_PGD];
11525+#ifdef CONFIG_X86_PAE
11526+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11527+#endif
11528+
11529 #if defined(CONFIG_HIGHPTE)
11530 #define pte_offset_map(dir, address) \
11531 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11532@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11533 /* Clear a kernel PTE and flush it from the TLB */
11534 #define kpte_clear_flush(ptep, vaddr) \
11535 do { \
11536+ pax_open_kernel(); \
11537 pte_clear(&init_mm, (vaddr), (ptep)); \
11538+ pax_close_kernel(); \
11539 __flush_tlb_one((vaddr)); \
11540 } while (0)
11541
11542@@ -74,6 +79,9 @@ do { \
11543
11544 #endif /* !__ASSEMBLY__ */
11545
11546+#define HAVE_ARCH_UNMAPPED_AREA
11547+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11548+
11549 /*
11550 * kern_addr_valid() is (1) for FLATMEM and (0) for
11551 * SPARSEMEM and DISCONTIGMEM
11552diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11553index ed5903b..c7fe163 100644
11554--- a/arch/x86/include/asm/pgtable_32_types.h
11555+++ b/arch/x86/include/asm/pgtable_32_types.h
11556@@ -8,7 +8,7 @@
11557 */
11558 #ifdef CONFIG_X86_PAE
11559 # include <asm/pgtable-3level_types.h>
11560-# define PMD_SIZE (1UL << PMD_SHIFT)
11561+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11562 # define PMD_MASK (~(PMD_SIZE - 1))
11563 #else
11564 # include <asm/pgtable-2level_types.h>
11565@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11566 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11567 #endif
11568
11569+#ifdef CONFIG_PAX_KERNEXEC
11570+#ifndef __ASSEMBLY__
11571+extern unsigned char MODULES_EXEC_VADDR[];
11572+extern unsigned char MODULES_EXEC_END[];
11573+#endif
11574+#include <asm/boot.h>
11575+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11576+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11577+#else
11578+#define ktla_ktva(addr) (addr)
11579+#define ktva_ktla(addr) (addr)
11580+#endif
11581+
11582 #define MODULES_VADDR VMALLOC_START
11583 #define MODULES_END VMALLOC_END
11584 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11585diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11586index 975f709..9f779c9 100644
11587--- a/arch/x86/include/asm/pgtable_64.h
11588+++ b/arch/x86/include/asm/pgtable_64.h
11589@@ -16,10 +16,14 @@
11590
11591 extern pud_t level3_kernel_pgt[512];
11592 extern pud_t level3_ident_pgt[512];
11593+extern pud_t level3_vmalloc_start_pgt[512];
11594+extern pud_t level3_vmalloc_end_pgt[512];
11595+extern pud_t level3_vmemmap_pgt[512];
11596+extern pud_t level2_vmemmap_pgt[512];
11597 extern pmd_t level2_kernel_pgt[512];
11598 extern pmd_t level2_fixmap_pgt[512];
11599-extern pmd_t level2_ident_pgt[512];
11600-extern pgd_t init_level4_pgt[];
11601+extern pmd_t level2_ident_pgt[512*2];
11602+extern pgd_t init_level4_pgt[512];
11603
11604 #define swapper_pg_dir init_level4_pgt
11605
11606@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11607
11608 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11609 {
11610+ pax_open_kernel();
11611 *pmdp = pmd;
11612+ pax_close_kernel();
11613 }
11614
11615 static inline void native_pmd_clear(pmd_t *pmd)
11616@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11617
11618 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11619 {
11620+ pax_open_kernel();
11621 *pudp = pud;
11622+ pax_close_kernel();
11623 }
11624
11625 static inline void native_pud_clear(pud_t *pud)
11626@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11627
11628 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11629 {
11630+ pax_open_kernel();
11631+ *pgdp = pgd;
11632+ pax_close_kernel();
11633+}
11634+
11635+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11636+{
11637 *pgdp = pgd;
11638 }
11639
11640diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11641index 766ea16..5b96cb3 100644
11642--- a/arch/x86/include/asm/pgtable_64_types.h
11643+++ b/arch/x86/include/asm/pgtable_64_types.h
11644@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11645 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11646 #define MODULES_END _AC(0xffffffffff000000, UL)
11647 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11648+#define MODULES_EXEC_VADDR MODULES_VADDR
11649+#define MODULES_EXEC_END MODULES_END
11650+
11651+#define ktla_ktva(addr) (addr)
11652+#define ktva_ktla(addr) (addr)
11653
11654 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11655diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11656index 013286a..8b42f4f 100644
11657--- a/arch/x86/include/asm/pgtable_types.h
11658+++ b/arch/x86/include/asm/pgtable_types.h
11659@@ -16,13 +16,12 @@
11660 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11661 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11662 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11663-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11664+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11665 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11666 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11667 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11668-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11669-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11670-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11671+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11672+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11673 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11674
11675 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11676@@ -40,7 +39,6 @@
11677 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11678 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11679 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11680-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11681 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11682 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11683 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11684@@ -57,8 +55,10 @@
11685
11686 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11687 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11688-#else
11689+#elif defined(CONFIG_KMEMCHECK)
11690 #define _PAGE_NX (_AT(pteval_t, 0))
11691+#else
11692+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11693 #endif
11694
11695 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11696@@ -96,6 +96,9 @@
11697 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11698 _PAGE_ACCESSED)
11699
11700+#define PAGE_READONLY_NOEXEC PAGE_READONLY
11701+#define PAGE_SHARED_NOEXEC PAGE_SHARED
11702+
11703 #define __PAGE_KERNEL_EXEC \
11704 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11705 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11706@@ -106,7 +109,7 @@
11707 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11708 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11709 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11710-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11711+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11712 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11713 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11714 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11715@@ -168,8 +171,8 @@
11716 * bits are combined, this will alow user to access the high address mapped
11717 * VDSO in the presence of CONFIG_COMPAT_VDSO
11718 */
11719-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11720-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11721+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11722+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11723 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11724 #endif
11725
11726@@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11727 {
11728 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11729 }
11730+#endif
11731
11732+#if PAGETABLE_LEVELS == 3
11733+#include <asm-generic/pgtable-nopud.h>
11734+#endif
11735+
11736+#if PAGETABLE_LEVELS == 2
11737+#include <asm-generic/pgtable-nopmd.h>
11738+#endif
11739+
11740+#ifndef __ASSEMBLY__
11741 #if PAGETABLE_LEVELS > 3
11742 typedef struct { pudval_t pud; } pud_t;
11743
11744@@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11745 return pud.pud;
11746 }
11747 #else
11748-#include <asm-generic/pgtable-nopud.h>
11749-
11750 static inline pudval_t native_pud_val(pud_t pud)
11751 {
11752 return native_pgd_val(pud.pgd);
11753@@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11754 return pmd.pmd;
11755 }
11756 #else
11757-#include <asm-generic/pgtable-nopmd.h>
11758-
11759 static inline pmdval_t native_pmd_val(pmd_t pmd)
11760 {
11761 return native_pgd_val(pmd.pud.pgd);
11762@@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11763
11764 extern pteval_t __supported_pte_mask;
11765 extern void set_nx(void);
11766-extern int nx_enabled;
11767
11768 #define pgprot_writecombine pgprot_writecombine
11769 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11770diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11771index 39bc577..538233f 100644
11772--- a/arch/x86/include/asm/processor.h
11773+++ b/arch/x86/include/asm/processor.h
11774@@ -276,7 +276,7 @@ struct tss_struct {
11775
11776 } ____cacheline_aligned;
11777
11778-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11779+extern struct tss_struct init_tss[NR_CPUS];
11780
11781 /*
11782 * Save the original ist values for checking stack pointers during debugging
11783@@ -809,11 +809,18 @@ static inline void spin_lock_prefetch(const void *x)
11784 */
11785 #define TASK_SIZE PAGE_OFFSET
11786 #define TASK_SIZE_MAX TASK_SIZE
11787+
11788+#ifdef CONFIG_PAX_SEGMEXEC
11789+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11790+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11791+#else
11792 #define STACK_TOP TASK_SIZE
11793-#define STACK_TOP_MAX STACK_TOP
11794+#endif
11795+
11796+#define STACK_TOP_MAX TASK_SIZE
11797
11798 #define INIT_THREAD { \
11799- .sp0 = sizeof(init_stack) + (long)&init_stack, \
11800+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11801 .vm86_info = NULL, \
11802 .sysenter_cs = __KERNEL_CS, \
11803 .io_bitmap_ptr = NULL, \
11804@@ -827,7 +834,7 @@ static inline void spin_lock_prefetch(const void *x)
11805 */
11806 #define INIT_TSS { \
11807 .x86_tss = { \
11808- .sp0 = sizeof(init_stack) + (long)&init_stack, \
11809+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11810 .ss0 = __KERNEL_DS, \
11811 .ss1 = __KERNEL_CS, \
11812 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11813@@ -838,11 +845,7 @@ static inline void spin_lock_prefetch(const void *x)
11814 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11815
11816 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11817-#define KSTK_TOP(info) \
11818-({ \
11819- unsigned long *__ptr = (unsigned long *)(info); \
11820- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11821-})
11822+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11823
11824 /*
11825 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11826@@ -857,7 +860,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11827 #define task_pt_regs(task) \
11828 ({ \
11829 struct pt_regs *__regs__; \
11830- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11831+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11832 __regs__ - 1; \
11833 })
11834
11835@@ -867,13 +870,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11836 /*
11837 * User space process size. 47bits minus one guard page.
11838 */
11839-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11840+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11841
11842 /* This decides where the kernel will search for a free chunk of vm
11843 * space during mmap's.
11844 */
11845 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11846- 0xc0000000 : 0xFFFFe000)
11847+ 0xc0000000 : 0xFFFFf000)
11848
11849 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
11850 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11851@@ -884,11 +887,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11852 #define STACK_TOP_MAX TASK_SIZE_MAX
11853
11854 #define INIT_THREAD { \
11855- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11856+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11857 }
11858
11859 #define INIT_TSS { \
11860- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11861+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11862 }
11863
11864 /*
11865@@ -916,6 +919,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11866 */
11867 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11868
11869+#ifdef CONFIG_PAX_SEGMEXEC
11870+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11871+#endif
11872+
11873 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11874
11875 /* Get/set a process' ability to use the timestamp counter instruction */
11876@@ -976,12 +983,12 @@ extern bool cpu_has_amd_erratum(const int *);
11877 #define cpu_has_amd_erratum(x) (false)
11878 #endif /* CONFIG_CPU_SUP_AMD */
11879
11880-extern unsigned long arch_align_stack(unsigned long sp);
11881+#define arch_align_stack(x) ((x) & ~0xfUL)
11882 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11883
11884 void default_idle(void);
11885 bool set_pm_idle_to_default(void);
11886
11887-void stop_this_cpu(void *dummy);
11888+void stop_this_cpu(void *dummy) __noreturn;
11889
11890 #endif /* _ASM_X86_PROCESSOR_H */
11891diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11892index dcfde52..dbfea06 100644
11893--- a/arch/x86/include/asm/ptrace.h
11894+++ b/arch/x86/include/asm/ptrace.h
11895@@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11896 }
11897
11898 /*
11899- * user_mode_vm(regs) determines whether a register set came from user mode.
11900+ * user_mode(regs) determines whether a register set came from user mode.
11901 * This is true if V8086 mode was enabled OR if the register set was from
11902 * protected mode with RPL-3 CS value. This tricky test checks that with
11903 * one comparison. Many places in the kernel can bypass this full check
11904- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11905+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11906+ * be used.
11907 */
11908-static inline int user_mode(struct pt_regs *regs)
11909+static inline int user_mode_novm(struct pt_regs *regs)
11910 {
11911 #ifdef CONFIG_X86_32
11912 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11913 #else
11914- return !!(regs->cs & 3);
11915+ return !!(regs->cs & SEGMENT_RPL_MASK);
11916 #endif
11917 }
11918
11919-static inline int user_mode_vm(struct pt_regs *regs)
11920+static inline int user_mode(struct pt_regs *regs)
11921 {
11922 #ifdef CONFIG_X86_32
11923 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11924 USER_RPL;
11925 #else
11926- return user_mode(regs);
11927+ return user_mode_novm(regs);
11928 #endif
11929 }
11930
11931@@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
11932 #ifdef CONFIG_X86_64
11933 static inline bool user_64bit_mode(struct pt_regs *regs)
11934 {
11935+ unsigned long cs = regs->cs & 0xffff;
11936 #ifndef CONFIG_PARAVIRT
11937 /*
11938 * On non-paravirt systems, this is the only long mode CPL 3
11939 * selector. We do not allow long mode selectors in the LDT.
11940 */
11941- return regs->cs == __USER_CS;
11942+ return cs == __USER_CS;
11943 #else
11944 /* Headers are too twisted for this to go in paravirt.h. */
11945- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
11946+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
11947 #endif
11948 }
11949 #endif
11950diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
11951index fce3f4a..3f69f2a 100644
11952--- a/arch/x86/include/asm/realmode.h
11953+++ b/arch/x86/include/asm/realmode.h
11954@@ -30,7 +30,7 @@ struct real_mode_header {
11955 struct trampoline_header {
11956 #ifdef CONFIG_X86_32
11957 u32 start;
11958- u16 gdt_pad;
11959+ u16 boot_cs;
11960 u16 gdt_limit;
11961 u32 gdt_base;
11962 #else
11963diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
11964index 92f29706..a79cbbb 100644
11965--- a/arch/x86/include/asm/reboot.h
11966+++ b/arch/x86/include/asm/reboot.h
11967@@ -6,19 +6,19 @@
11968 struct pt_regs;
11969
11970 struct machine_ops {
11971- void (*restart)(char *cmd);
11972- void (*halt)(void);
11973- void (*power_off)(void);
11974+ void (* __noreturn restart)(char *cmd);
11975+ void (* __noreturn halt)(void);
11976+ void (* __noreturn power_off)(void);
11977 void (*shutdown)(void);
11978 void (*crash_shutdown)(struct pt_regs *);
11979- void (*emergency_restart)(void);
11980-};
11981+ void (* __noreturn emergency_restart)(void);
11982+} __no_const;
11983
11984 extern struct machine_ops machine_ops;
11985
11986 void native_machine_crash_shutdown(struct pt_regs *regs);
11987 void native_machine_shutdown(void);
11988-void machine_real_restart(unsigned int type);
11989+void machine_real_restart(unsigned int type) __noreturn;
11990 /* These must match dispatch_table in reboot_32.S */
11991 #define MRR_BIOS 0
11992 #define MRR_APM 1
11993diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
11994index 2dbe4a7..ce1db00 100644
11995--- a/arch/x86/include/asm/rwsem.h
11996+++ b/arch/x86/include/asm/rwsem.h
11997@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
11998 {
11999 asm volatile("# beginning down_read\n\t"
12000 LOCK_PREFIX _ASM_INC "(%1)\n\t"
12001+
12002+#ifdef CONFIG_PAX_REFCOUNT
12003+ "jno 0f\n"
12004+ LOCK_PREFIX _ASM_DEC "(%1)\n"
12005+ "int $4\n0:\n"
12006+ _ASM_EXTABLE(0b, 0b)
12007+#endif
12008+
12009 /* adds 0x00000001 */
12010 " jns 1f\n"
12011 " call call_rwsem_down_read_failed\n"
12012@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
12013 "1:\n\t"
12014 " mov %1,%2\n\t"
12015 " add %3,%2\n\t"
12016+
12017+#ifdef CONFIG_PAX_REFCOUNT
12018+ "jno 0f\n"
12019+ "sub %3,%2\n"
12020+ "int $4\n0:\n"
12021+ _ASM_EXTABLE(0b, 0b)
12022+#endif
12023+
12024 " jle 2f\n\t"
12025 LOCK_PREFIX " cmpxchg %2,%0\n\t"
12026 " jnz 1b\n\t"
12027@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
12028 long tmp;
12029 asm volatile("# beginning down_write\n\t"
12030 LOCK_PREFIX " xadd %1,(%2)\n\t"
12031+
12032+#ifdef CONFIG_PAX_REFCOUNT
12033+ "jno 0f\n"
12034+ "mov %1,(%2)\n"
12035+ "int $4\n0:\n"
12036+ _ASM_EXTABLE(0b, 0b)
12037+#endif
12038+
12039 /* adds 0xffff0001, returns the old value */
12040 " test %1,%1\n\t"
12041 /* was the count 0 before? */
12042@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12043 long tmp;
12044 asm volatile("# beginning __up_read\n\t"
12045 LOCK_PREFIX " xadd %1,(%2)\n\t"
12046+
12047+#ifdef CONFIG_PAX_REFCOUNT
12048+ "jno 0f\n"
12049+ "mov %1,(%2)\n"
12050+ "int $4\n0:\n"
12051+ _ASM_EXTABLE(0b, 0b)
12052+#endif
12053+
12054 /* subtracts 1, returns the old value */
12055 " jns 1f\n\t"
12056 " call call_rwsem_wake\n" /* expects old value in %edx */
12057@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12058 long tmp;
12059 asm volatile("# beginning __up_write\n\t"
12060 LOCK_PREFIX " xadd %1,(%2)\n\t"
12061+
12062+#ifdef CONFIG_PAX_REFCOUNT
12063+ "jno 0f\n"
12064+ "mov %1,(%2)\n"
12065+ "int $4\n0:\n"
12066+ _ASM_EXTABLE(0b, 0b)
12067+#endif
12068+
12069 /* subtracts 0xffff0001, returns the old value */
12070 " jns 1f\n\t"
12071 " call call_rwsem_wake\n" /* expects old value in %edx */
12072@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12073 {
12074 asm volatile("# beginning __downgrade_write\n\t"
12075 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12076+
12077+#ifdef CONFIG_PAX_REFCOUNT
12078+ "jno 0f\n"
12079+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12080+ "int $4\n0:\n"
12081+ _ASM_EXTABLE(0b, 0b)
12082+#endif
12083+
12084 /*
12085 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12086 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12087@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12088 */
12089 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12090 {
12091- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12092+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12093+
12094+#ifdef CONFIG_PAX_REFCOUNT
12095+ "jno 0f\n"
12096+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
12097+ "int $4\n0:\n"
12098+ _ASM_EXTABLE(0b, 0b)
12099+#endif
12100+
12101 : "+m" (sem->count)
12102 : "er" (delta));
12103 }
12104@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12105 */
12106 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12107 {
12108- return delta + xadd(&sem->count, delta);
12109+ return delta + xadd_check_overflow(&sem->count, delta);
12110 }
12111
12112 #endif /* __KERNEL__ */
12113diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12114index c48a950..c6d7468 100644
12115--- a/arch/x86/include/asm/segment.h
12116+++ b/arch/x86/include/asm/segment.h
12117@@ -64,10 +64,15 @@
12118 * 26 - ESPFIX small SS
12119 * 27 - per-cpu [ offset to per-cpu data area ]
12120 * 28 - stack_canary-20 [ for stack protector ]
12121- * 29 - unused
12122- * 30 - unused
12123+ * 29 - PCI BIOS CS
12124+ * 30 - PCI BIOS DS
12125 * 31 - TSS for double fault handler
12126 */
12127+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12128+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12129+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12130+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12131+
12132 #define GDT_ENTRY_TLS_MIN 6
12133 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12134
12135@@ -79,6 +84,8 @@
12136
12137 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12138
12139+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12140+
12141 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12142
12143 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12144@@ -104,6 +111,12 @@
12145 #define __KERNEL_STACK_CANARY 0
12146 #endif
12147
12148+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12149+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12150+
12151+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12152+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12153+
12154 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12155
12156 /*
12157@@ -141,7 +154,7 @@
12158 */
12159
12160 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12161-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12162+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12163
12164
12165 #else
12166@@ -165,6 +178,8 @@
12167 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12168 #define __USER32_DS __USER_DS
12169
12170+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12171+
12172 #define GDT_ENTRY_TSS 8 /* needs two entries */
12173 #define GDT_ENTRY_LDT 10 /* needs two entries */
12174 #define GDT_ENTRY_TLS_MIN 12
12175@@ -185,6 +200,7 @@
12176 #endif
12177
12178 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12179+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12180 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12181 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12182 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12183@@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
12184 {
12185 unsigned long __limit;
12186 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12187- return __limit + 1;
12188+ return __limit;
12189 }
12190
12191 #endif /* !__ASSEMBLY__ */
12192diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12193index f483945..64a7851 100644
12194--- a/arch/x86/include/asm/smp.h
12195+++ b/arch/x86/include/asm/smp.h
12196@@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
12197 /* cpus sharing the last level cache: */
12198 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
12199 DECLARE_PER_CPU(u16, cpu_llc_id);
12200-DECLARE_PER_CPU(int, cpu_number);
12201+DECLARE_PER_CPU(unsigned int, cpu_number);
12202
12203 static inline struct cpumask *cpu_sibling_mask(int cpu)
12204 {
12205@@ -79,7 +79,7 @@ struct smp_ops {
12206
12207 void (*send_call_func_ipi)(const struct cpumask *mask);
12208 void (*send_call_func_single_ipi)(int cpu);
12209-};
12210+} __no_const;
12211
12212 /* Globals due to paravirt */
12213 extern void set_cpu_sibling_map(int cpu);
12214@@ -195,14 +195,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12215 extern int safe_smp_processor_id(void);
12216
12217 #elif defined(CONFIG_X86_64_SMP)
12218-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12219-
12220-#define stack_smp_processor_id() \
12221-({ \
12222- struct thread_info *ti; \
12223- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12224- ti->cpu; \
12225-})
12226+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12227+#define stack_smp_processor_id() raw_smp_processor_id()
12228 #define safe_smp_processor_id() smp_processor_id()
12229
12230 #endif
12231diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12232index b315a33..8849ab0 100644
12233--- a/arch/x86/include/asm/spinlock.h
12234+++ b/arch/x86/include/asm/spinlock.h
12235@@ -173,6 +173,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12236 static inline void arch_read_lock(arch_rwlock_t *rw)
12237 {
12238 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12239+
12240+#ifdef CONFIG_PAX_REFCOUNT
12241+ "jno 0f\n"
12242+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12243+ "int $4\n0:\n"
12244+ _ASM_EXTABLE(0b, 0b)
12245+#endif
12246+
12247 "jns 1f\n"
12248 "call __read_lock_failed\n\t"
12249 "1:\n"
12250@@ -182,6 +190,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12251 static inline void arch_write_lock(arch_rwlock_t *rw)
12252 {
12253 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12254+
12255+#ifdef CONFIG_PAX_REFCOUNT
12256+ "jno 0f\n"
12257+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12258+ "int $4\n0:\n"
12259+ _ASM_EXTABLE(0b, 0b)
12260+#endif
12261+
12262 "jz 1f\n"
12263 "call __write_lock_failed\n\t"
12264 "1:\n"
12265@@ -211,13 +227,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12266
12267 static inline void arch_read_unlock(arch_rwlock_t *rw)
12268 {
12269- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12270+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12271+
12272+#ifdef CONFIG_PAX_REFCOUNT
12273+ "jno 0f\n"
12274+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12275+ "int $4\n0:\n"
12276+ _ASM_EXTABLE(0b, 0b)
12277+#endif
12278+
12279 :"+m" (rw->lock) : : "memory");
12280 }
12281
12282 static inline void arch_write_unlock(arch_rwlock_t *rw)
12283 {
12284- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12285+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12286+
12287+#ifdef CONFIG_PAX_REFCOUNT
12288+ "jno 0f\n"
12289+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12290+ "int $4\n0:\n"
12291+ _ASM_EXTABLE(0b, 0b)
12292+#endif
12293+
12294 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12295 }
12296
12297diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12298index 6a99859..03cb807 100644
12299--- a/arch/x86/include/asm/stackprotector.h
12300+++ b/arch/x86/include/asm/stackprotector.h
12301@@ -47,7 +47,7 @@
12302 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12303 */
12304 #define GDT_STACK_CANARY_INIT \
12305- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12306+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12307
12308 /*
12309 * Initialize the stackprotector canary value.
12310@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
12311
12312 static inline void load_stack_canary_segment(void)
12313 {
12314-#ifdef CONFIG_X86_32
12315+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12316 asm volatile ("mov %0, %%gs" : : "r" (0));
12317 #endif
12318 }
12319diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12320index 70bbe39..4ae2bd4 100644
12321--- a/arch/x86/include/asm/stacktrace.h
12322+++ b/arch/x86/include/asm/stacktrace.h
12323@@ -11,28 +11,20 @@
12324
12325 extern int kstack_depth_to_print;
12326
12327-struct thread_info;
12328+struct task_struct;
12329 struct stacktrace_ops;
12330
12331-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12332- unsigned long *stack,
12333- unsigned long bp,
12334- const struct stacktrace_ops *ops,
12335- void *data,
12336- unsigned long *end,
12337- int *graph);
12338+typedef unsigned long walk_stack_t(struct task_struct *task,
12339+ void *stack_start,
12340+ unsigned long *stack,
12341+ unsigned long bp,
12342+ const struct stacktrace_ops *ops,
12343+ void *data,
12344+ unsigned long *end,
12345+ int *graph);
12346
12347-extern unsigned long
12348-print_context_stack(struct thread_info *tinfo,
12349- unsigned long *stack, unsigned long bp,
12350- const struct stacktrace_ops *ops, void *data,
12351- unsigned long *end, int *graph);
12352-
12353-extern unsigned long
12354-print_context_stack_bp(struct thread_info *tinfo,
12355- unsigned long *stack, unsigned long bp,
12356- const struct stacktrace_ops *ops, void *data,
12357- unsigned long *end, int *graph);
12358+extern walk_stack_t print_context_stack;
12359+extern walk_stack_t print_context_stack_bp;
12360
12361 /* Generic stack tracer with callbacks */
12362
12363@@ -40,7 +32,7 @@ struct stacktrace_ops {
12364 void (*address)(void *data, unsigned long address, int reliable);
12365 /* On negative return stop dumping */
12366 int (*stack)(void *data, char *name);
12367- walk_stack_t walk_stack;
12368+ walk_stack_t *walk_stack;
12369 };
12370
12371 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12372diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
12373index 4ec45b3..a4f0a8a 100644
12374--- a/arch/x86/include/asm/switch_to.h
12375+++ b/arch/x86/include/asm/switch_to.h
12376@@ -108,7 +108,7 @@ do { \
12377 "call __switch_to\n\t" \
12378 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12379 __switch_canary \
12380- "movq %P[thread_info](%%rsi),%%r8\n\t" \
12381+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12382 "movq %%rax,%%rdi\n\t" \
12383 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12384 "jnz ret_from_fork\n\t" \
12385@@ -119,7 +119,7 @@ do { \
12386 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12387 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12388 [_tif_fork] "i" (_TIF_FORK), \
12389- [thread_info] "i" (offsetof(struct task_struct, stack)), \
12390+ [thread_info] "m" (current_tinfo), \
12391 [current_task] "m" (current_task) \
12392 __switch_canary_iparam \
12393 : "memory", "cc" __EXTRA_CLOBBER)
12394diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12395index 3fda9db4..4ca1c61 100644
12396--- a/arch/x86/include/asm/sys_ia32.h
12397+++ b/arch/x86/include/asm/sys_ia32.h
12398@@ -40,7 +40,7 @@ asmlinkage long sys32_sigaction(int, struct old_sigaction32 __user *,
12399 struct old_sigaction32 __user *);
12400 asmlinkage long sys32_alarm(unsigned int);
12401
12402-asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12403+asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12404 asmlinkage long sys32_sysfs(int, u32, u32);
12405
12406 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12407diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12408index 89f794f..1422765 100644
12409--- a/arch/x86/include/asm/thread_info.h
12410+++ b/arch/x86/include/asm/thread_info.h
12411@@ -10,6 +10,7 @@
12412 #include <linux/compiler.h>
12413 #include <asm/page.h>
12414 #include <asm/types.h>
12415+#include <asm/percpu.h>
12416
12417 /*
12418 * low level task data that entry.S needs immediate access to
12419@@ -24,7 +25,6 @@ struct exec_domain;
12420 #include <linux/atomic.h>
12421
12422 struct thread_info {
12423- struct task_struct *task; /* main task structure */
12424 struct exec_domain *exec_domain; /* execution domain */
12425 __u32 flags; /* low level flags */
12426 __u32 status; /* thread synchronous flags */
12427@@ -34,19 +34,13 @@ struct thread_info {
12428 mm_segment_t addr_limit;
12429 struct restart_block restart_block;
12430 void __user *sysenter_return;
12431-#ifdef CONFIG_X86_32
12432- unsigned long previous_esp; /* ESP of the previous stack in
12433- case of nested (IRQ) stacks
12434- */
12435- __u8 supervisor_stack[0];
12436-#endif
12437+ unsigned long lowest_stack;
12438 unsigned int sig_on_uaccess_error:1;
12439 unsigned int uaccess_err:1; /* uaccess failed */
12440 };
12441
12442-#define INIT_THREAD_INFO(tsk) \
12443+#define INIT_THREAD_INFO \
12444 { \
12445- .task = &tsk, \
12446 .exec_domain = &default_exec_domain, \
12447 .flags = 0, \
12448 .cpu = 0, \
12449@@ -57,7 +51,7 @@ struct thread_info {
12450 }, \
12451 }
12452
12453-#define init_thread_info (init_thread_union.thread_info)
12454+#define init_thread_info (init_thread_union.stack)
12455 #define init_stack (init_thread_union.stack)
12456
12457 #else /* !__ASSEMBLY__ */
12458@@ -98,6 +92,7 @@ struct thread_info {
12459 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12460 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
12461 #define TIF_X32 30 /* 32-bit native x86-64 binary */
12462+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
12463
12464 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12465 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12466@@ -122,16 +117,18 @@ struct thread_info {
12467 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12468 #define _TIF_ADDR32 (1 << TIF_ADDR32)
12469 #define _TIF_X32 (1 << TIF_X32)
12470+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12471
12472 /* work to do in syscall_trace_enter() */
12473 #define _TIF_WORK_SYSCALL_ENTRY \
12474 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12475- _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12476+ _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
12477+ _TIF_GRSEC_SETXID)
12478
12479 /* work to do in syscall_trace_leave() */
12480 #define _TIF_WORK_SYSCALL_EXIT \
12481 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12482- _TIF_SYSCALL_TRACEPOINT)
12483+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12484
12485 /* work to do on interrupt/exception return */
12486 #define _TIF_WORK_MASK \
12487@@ -141,7 +138,8 @@ struct thread_info {
12488
12489 /* work to do on any return to user space */
12490 #define _TIF_ALLWORK_MASK \
12491- ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12492+ ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12493+ _TIF_GRSEC_SETXID)
12494
12495 /* Only used for 64 bit */
12496 #define _TIF_DO_NOTIFY_MASK \
12497@@ -157,45 +155,40 @@ struct thread_info {
12498
12499 #define PREEMPT_ACTIVE 0x10000000
12500
12501-#ifdef CONFIG_X86_32
12502-
12503-#define STACK_WARN (THREAD_SIZE/8)
12504-/*
12505- * macros/functions for gaining access to the thread information structure
12506- *
12507- * preempt_count needs to be 1 initially, until the scheduler is functional.
12508- */
12509-#ifndef __ASSEMBLY__
12510-
12511-
12512-/* how to get the current stack pointer from C */
12513-register unsigned long current_stack_pointer asm("esp") __used;
12514-
12515-/* how to get the thread information struct from C */
12516-static inline struct thread_info *current_thread_info(void)
12517-{
12518- return (struct thread_info *)
12519- (current_stack_pointer & ~(THREAD_SIZE - 1));
12520-}
12521-
12522-#else /* !__ASSEMBLY__ */
12523-
12524+#ifdef __ASSEMBLY__
12525 /* how to get the thread information struct from ASM */
12526 #define GET_THREAD_INFO(reg) \
12527- movl $-THREAD_SIZE, reg; \
12528- andl %esp, reg
12529+ mov PER_CPU_VAR(current_tinfo), reg
12530
12531 /* use this one if reg already contains %esp */
12532-#define GET_THREAD_INFO_WITH_ESP(reg) \
12533- andl $-THREAD_SIZE, reg
12534+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12535+#else
12536+/* how to get the thread information struct from C */
12537+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12538+
12539+static __always_inline struct thread_info *current_thread_info(void)
12540+{
12541+ return this_cpu_read_stable(current_tinfo);
12542+}
12543+#endif
12544+
12545+#ifdef CONFIG_X86_32
12546+
12547+#define STACK_WARN (THREAD_SIZE/8)
12548+/*
12549+ * macros/functions for gaining access to the thread information structure
12550+ *
12551+ * preempt_count needs to be 1 initially, until the scheduler is functional.
12552+ */
12553+#ifndef __ASSEMBLY__
12554+
12555+/* how to get the current stack pointer from C */
12556+register unsigned long current_stack_pointer asm("esp") __used;
12557
12558 #endif
12559
12560 #else /* X86_32 */
12561
12562-#include <asm/percpu.h>
12563-#define KERNEL_STACK_OFFSET (5*8)
12564-
12565 /*
12566 * macros/functions for gaining access to the thread information structure
12567 * preempt_count needs to be 1 initially, until the scheduler is functional.
12568@@ -203,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
12569 #ifndef __ASSEMBLY__
12570 DECLARE_PER_CPU(unsigned long, kernel_stack);
12571
12572-static inline struct thread_info *current_thread_info(void)
12573-{
12574- struct thread_info *ti;
12575- ti = (void *)(this_cpu_read_stable(kernel_stack) +
12576- KERNEL_STACK_OFFSET - THREAD_SIZE);
12577- return ti;
12578-}
12579-
12580-#else /* !__ASSEMBLY__ */
12581-
12582-/* how to get the thread information struct from ASM */
12583-#define GET_THREAD_INFO(reg) \
12584- movq PER_CPU_VAR(kernel_stack),reg ; \
12585- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12586-
12587-/*
12588- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12589- * a certain register (to be used in assembler memory operands).
12590- */
12591-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12592-
12593+/* how to get the current stack pointer from C */
12594+register unsigned long current_stack_pointer asm("rsp") __used;
12595 #endif
12596
12597 #endif /* !X86_32 */
12598@@ -284,5 +258,12 @@ static inline bool is_ia32_task(void)
12599 extern void arch_task_cache_init(void);
12600 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12601 extern void arch_release_task_struct(struct task_struct *tsk);
12602+
12603+#define __HAVE_THREAD_FUNCTIONS
12604+#define task_thread_info(task) (&(task)->tinfo)
12605+#define task_stack_page(task) ((task)->stack)
12606+#define setup_thread_stack(p, org) do {} while (0)
12607+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12608+
12609 #endif
12610 #endif /* _ASM_X86_THREAD_INFO_H */
12611diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12612index e1f3a17..1ab364d 100644
12613--- a/arch/x86/include/asm/uaccess.h
12614+++ b/arch/x86/include/asm/uaccess.h
12615@@ -7,12 +7,15 @@
12616 #include <linux/compiler.h>
12617 #include <linux/thread_info.h>
12618 #include <linux/string.h>
12619+#include <linux/sched.h>
12620 #include <asm/asm.h>
12621 #include <asm/page.h>
12622
12623 #define VERIFY_READ 0
12624 #define VERIFY_WRITE 1
12625
12626+extern void check_object_size(const void *ptr, unsigned long n, bool to);
12627+
12628 /*
12629 * The fs value determines whether argument validity checking should be
12630 * performed or not. If get_fs() == USER_DS, checking is performed, with
12631@@ -28,7 +31,12 @@
12632
12633 #define get_ds() (KERNEL_DS)
12634 #define get_fs() (current_thread_info()->addr_limit)
12635+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12636+void __set_fs(mm_segment_t x);
12637+void set_fs(mm_segment_t x);
12638+#else
12639 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12640+#endif
12641
12642 #define segment_eq(a, b) ((a).seg == (b).seg)
12643
12644@@ -76,8 +84,33 @@
12645 * checks that the pointer is in the user space range - after calling
12646 * this function, memory access functions may still return -EFAULT.
12647 */
12648-#define access_ok(type, addr, size) \
12649- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12650+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12651+#define access_ok(type, addr, size) \
12652+({ \
12653+ long __size = size; \
12654+ unsigned long __addr = (unsigned long)addr; \
12655+ unsigned long __addr_ao = __addr & PAGE_MASK; \
12656+ unsigned long __end_ao = __addr + __size - 1; \
12657+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
12658+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12659+ while(__addr_ao <= __end_ao) { \
12660+ char __c_ao; \
12661+ __addr_ao += PAGE_SIZE; \
12662+ if (__size > PAGE_SIZE) \
12663+ cond_resched(); \
12664+ if (__get_user(__c_ao, (char __user *)__addr)) \
12665+ break; \
12666+ if (type != VERIFY_WRITE) { \
12667+ __addr = __addr_ao; \
12668+ continue; \
12669+ } \
12670+ if (__put_user(__c_ao, (char __user *)__addr)) \
12671+ break; \
12672+ __addr = __addr_ao; \
12673+ } \
12674+ } \
12675+ __ret_ao; \
12676+})
12677
12678 /*
12679 * The exception table consists of pairs of addresses relative to the
12680@@ -188,12 +221,20 @@ extern int __get_user_bad(void);
12681 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12682 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12683
12684-
12685+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12686+#define __copyuser_seg "gs;"
12687+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12688+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12689+#else
12690+#define __copyuser_seg
12691+#define __COPYUSER_SET_ES
12692+#define __COPYUSER_RESTORE_ES
12693+#endif
12694
12695 #ifdef CONFIG_X86_32
12696 #define __put_user_asm_u64(x, addr, err, errret) \
12697- asm volatile("1: movl %%eax,0(%2)\n" \
12698- "2: movl %%edx,4(%2)\n" \
12699+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12700+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12701 "3:\n" \
12702 ".section .fixup,\"ax\"\n" \
12703 "4: movl %3,%0\n" \
12704@@ -205,8 +246,8 @@ extern int __get_user_bad(void);
12705 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12706
12707 #define __put_user_asm_ex_u64(x, addr) \
12708- asm volatile("1: movl %%eax,0(%1)\n" \
12709- "2: movl %%edx,4(%1)\n" \
12710+ asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12711+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12712 "3:\n" \
12713 _ASM_EXTABLE_EX(1b, 2b) \
12714 _ASM_EXTABLE_EX(2b, 3b) \
12715@@ -258,7 +299,7 @@ extern void __put_user_8(void);
12716 __typeof__(*(ptr)) __pu_val; \
12717 __chk_user_ptr(ptr); \
12718 might_fault(); \
12719- __pu_val = x; \
12720+ __pu_val = (x); \
12721 switch (sizeof(*(ptr))) { \
12722 case 1: \
12723 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12724@@ -379,7 +420,7 @@ do { \
12725 } while (0)
12726
12727 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12728- asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12729+ asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12730 "2:\n" \
12731 ".section .fixup,\"ax\"\n" \
12732 "3: mov %3,%0\n" \
12733@@ -387,7 +428,7 @@ do { \
12734 " jmp 2b\n" \
12735 ".previous\n" \
12736 _ASM_EXTABLE(1b, 3b) \
12737- : "=r" (err), ltype(x) \
12738+ : "=r" (err), ltype (x) \
12739 : "m" (__m(addr)), "i" (errret), "0" (err))
12740
12741 #define __get_user_size_ex(x, ptr, size) \
12742@@ -412,7 +453,7 @@ do { \
12743 } while (0)
12744
12745 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12746- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12747+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12748 "2:\n" \
12749 _ASM_EXTABLE_EX(1b, 2b) \
12750 : ltype(x) : "m" (__m(addr)))
12751@@ -429,13 +470,24 @@ do { \
12752 int __gu_err; \
12753 unsigned long __gu_val; \
12754 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12755- (x) = (__force __typeof__(*(ptr)))__gu_val; \
12756+ (x) = (__typeof__(*(ptr)))__gu_val; \
12757 __gu_err; \
12758 })
12759
12760 /* FIXME: this hack is definitely wrong -AK */
12761 struct __large_struct { unsigned long buf[100]; };
12762-#define __m(x) (*(struct __large_struct __user *)(x))
12763+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12764+#define ____m(x) \
12765+({ \
12766+ unsigned long ____x = (unsigned long)(x); \
12767+ if (____x < PAX_USER_SHADOW_BASE) \
12768+ ____x += PAX_USER_SHADOW_BASE; \
12769+ (void __user *)____x; \
12770+})
12771+#else
12772+#define ____m(x) (x)
12773+#endif
12774+#define __m(x) (*(struct __large_struct __user *)____m(x))
12775
12776 /*
12777 * Tell gcc we read from memory instead of writing: this is because
12778@@ -443,7 +495,7 @@ struct __large_struct { unsigned long buf[100]; };
12779 * aliasing issues.
12780 */
12781 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12782- asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12783+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12784 "2:\n" \
12785 ".section .fixup,\"ax\"\n" \
12786 "3: mov %3,%0\n" \
12787@@ -451,10 +503,10 @@ struct __large_struct { unsigned long buf[100]; };
12788 ".previous\n" \
12789 _ASM_EXTABLE(1b, 3b) \
12790 : "=r"(err) \
12791- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12792+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12793
12794 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12795- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12796+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12797 "2:\n" \
12798 _ASM_EXTABLE_EX(1b, 2b) \
12799 : : ltype(x), "m" (__m(addr)))
12800@@ -493,8 +545,12 @@ struct __large_struct { unsigned long buf[100]; };
12801 * On error, the variable @x is set to zero.
12802 */
12803
12804+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12805+#define __get_user(x, ptr) get_user((x), (ptr))
12806+#else
12807 #define __get_user(x, ptr) \
12808 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12809+#endif
12810
12811 /**
12812 * __put_user: - Write a simple value into user space, with less checking.
12813@@ -516,8 +572,12 @@ struct __large_struct { unsigned long buf[100]; };
12814 * Returns zero on success, or -EFAULT on error.
12815 */
12816
12817+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12818+#define __put_user(x, ptr) put_user((x), (ptr))
12819+#else
12820 #define __put_user(x, ptr) \
12821 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12822+#endif
12823
12824 #define __get_user_unaligned __get_user
12825 #define __put_user_unaligned __put_user
12826@@ -535,7 +595,7 @@ struct __large_struct { unsigned long buf[100]; };
12827 #define get_user_ex(x, ptr) do { \
12828 unsigned long __gue_val; \
12829 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12830- (x) = (__force __typeof__(*(ptr)))__gue_val; \
12831+ (x) = (__typeof__(*(ptr)))__gue_val; \
12832 } while (0)
12833
12834 #ifdef CONFIG_X86_WP_WORKS_OK
12835diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12836index 576e39b..ccd0a39 100644
12837--- a/arch/x86/include/asm/uaccess_32.h
12838+++ b/arch/x86/include/asm/uaccess_32.h
12839@@ -11,15 +11,15 @@
12840 #include <asm/page.h>
12841
12842 unsigned long __must_check __copy_to_user_ll
12843- (void __user *to, const void *from, unsigned long n);
12844+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12845 unsigned long __must_check __copy_from_user_ll
12846- (void *to, const void __user *from, unsigned long n);
12847+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12848 unsigned long __must_check __copy_from_user_ll_nozero
12849- (void *to, const void __user *from, unsigned long n);
12850+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12851 unsigned long __must_check __copy_from_user_ll_nocache
12852- (void *to, const void __user *from, unsigned long n);
12853+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12854 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12855- (void *to, const void __user *from, unsigned long n);
12856+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12857
12858 /**
12859 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12860@@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12861 static __always_inline unsigned long __must_check
12862 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12863 {
12864+ if ((long)n < 0)
12865+ return n;
12866+
12867 if (__builtin_constant_p(n)) {
12868 unsigned long ret;
12869
12870@@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12871 return ret;
12872 }
12873 }
12874+ if (!__builtin_constant_p(n))
12875+ check_object_size(from, n, true);
12876 return __copy_to_user_ll(to, from, n);
12877 }
12878
12879@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
12880 __copy_to_user(void __user *to, const void *from, unsigned long n)
12881 {
12882 might_fault();
12883+
12884 return __copy_to_user_inatomic(to, from, n);
12885 }
12886
12887 static __always_inline unsigned long
12888 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12889 {
12890+ if ((long)n < 0)
12891+ return n;
12892+
12893 /* Avoid zeroing the tail if the copy fails..
12894 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12895 * but as the zeroing behaviour is only significant when n is not
12896@@ -137,6 +146,10 @@ static __always_inline unsigned long
12897 __copy_from_user(void *to, 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@@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12908 return ret;
12909 }
12910 }
12911+ if (!__builtin_constant_p(n))
12912+ check_object_size(to, n, false);
12913 return __copy_from_user_ll(to, from, n);
12914 }
12915
12916@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12917 const void __user *from, unsigned long n)
12918 {
12919 might_fault();
12920+
12921+ if ((long)n < 0)
12922+ return n;
12923+
12924 if (__builtin_constant_p(n)) {
12925 unsigned long ret;
12926
12927@@ -181,15 +200,19 @@ static __always_inline unsigned long
12928 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
12929 unsigned long n)
12930 {
12931- return __copy_from_user_ll_nocache_nozero(to, from, n);
12932+ if ((long)n < 0)
12933+ return n;
12934+
12935+ return __copy_from_user_ll_nocache_nozero(to, from, n);
12936 }
12937
12938-unsigned long __must_check copy_to_user(void __user *to,
12939- const void *from, unsigned long n);
12940-unsigned long __must_check _copy_from_user(void *to,
12941- const void __user *from,
12942- unsigned long n);
12943-
12944+extern void copy_to_user_overflow(void)
12945+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12946+ __compiletime_error("copy_to_user() buffer size is not provably correct")
12947+#else
12948+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
12949+#endif
12950+;
12951
12952 extern void copy_from_user_overflow(void)
12953 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12954@@ -199,21 +222,65 @@ extern void copy_from_user_overflow(void)
12955 #endif
12956 ;
12957
12958-static inline unsigned long __must_check copy_from_user(void *to,
12959- const void __user *from,
12960- unsigned long n)
12961+/**
12962+ * copy_to_user: - Copy a block of data into user space.
12963+ * @to: Destination address, in user space.
12964+ * @from: Source address, in kernel space.
12965+ * @n: Number of bytes to copy.
12966+ *
12967+ * Context: User context only. This function may sleep.
12968+ *
12969+ * Copy data from kernel space to user space.
12970+ *
12971+ * Returns number of bytes that could not be copied.
12972+ * On success, this will be zero.
12973+ */
12974+static inline unsigned long __must_check
12975+copy_to_user(void __user *to, const void *from, unsigned long n)
12976 {
12977- int sz = __compiletime_object_size(to);
12978+ size_t sz = __compiletime_object_size(from);
12979
12980- if (likely(sz == -1 || sz >= n))
12981- n = _copy_from_user(to, from, n);
12982- else
12983+ if (unlikely(sz != (size_t)-1 && sz < n))
12984+ copy_to_user_overflow();
12985+ else if (access_ok(VERIFY_WRITE, to, n))
12986+ n = __copy_to_user(to, from, n);
12987+ return n;
12988+}
12989+
12990+/**
12991+ * copy_from_user: - Copy a block of data from user space.
12992+ * @to: Destination address, in kernel space.
12993+ * @from: Source address, in user space.
12994+ * @n: Number of bytes to copy.
12995+ *
12996+ * Context: User context only. This function may sleep.
12997+ *
12998+ * Copy data from user space to kernel space.
12999+ *
13000+ * Returns number of bytes that could not be copied.
13001+ * On success, this will be zero.
13002+ *
13003+ * If some data could not be copied, this function will pad the copied
13004+ * data to the requested size using zero bytes.
13005+ */
13006+static inline unsigned long __must_check
13007+copy_from_user(void *to, const void __user *from, unsigned long n)
13008+{
13009+ size_t sz = __compiletime_object_size(to);
13010+
13011+ if (unlikely(sz != (size_t)-1 && sz < n))
13012 copy_from_user_overflow();
13013-
13014+ else if (access_ok(VERIFY_READ, from, n))
13015+ n = __copy_from_user(to, from, n);
13016+ else if ((long)n > 0) {
13017+ if (!__builtin_constant_p(n))
13018+ check_object_size(to, n, false);
13019+ memset(to, 0, n);
13020+ }
13021 return n;
13022 }
13023
13024-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
13025-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
13026+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13027+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13028
13029 #endif /* _ASM_X86_UACCESS_32_H */
13030diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
13031index 8e796fb..72fd934 100644
13032--- a/arch/x86/include/asm/uaccess_64.h
13033+++ b/arch/x86/include/asm/uaccess_64.h
13034@@ -10,6 +10,9 @@
13035 #include <asm/alternative.h>
13036 #include <asm/cpufeature.h>
13037 #include <asm/page.h>
13038+#include <asm/pgtable.h>
13039+
13040+#define set_fs(x) (current_thread_info()->addr_limit = (x))
13041
13042 /*
13043 * Copy To/From Userspace
13044@@ -17,12 +20,14 @@
13045
13046 /* Handles exceptions in both to and from, but doesn't do access_ok */
13047 __must_check unsigned long
13048-copy_user_generic_string(void *to, const void *from, unsigned len);
13049+copy_user_generic_string(void *to, const void *from, unsigned long len) __size_overflow(3);
13050 __must_check unsigned long
13051-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13052+copy_user_generic_unrolled(void *to, const void *from, unsigned long len) __size_overflow(3);
13053
13054 static __always_inline __must_check unsigned long
13055-copy_user_generic(void *to, const void *from, unsigned len)
13056+copy_user_generic(void *to, const void *from, unsigned long len) __size_overflow(3);
13057+static __always_inline __must_check unsigned long
13058+copy_user_generic(void *to, const void *from, unsigned long len)
13059 {
13060 unsigned ret;
13061
13062@@ -32,142 +37,238 @@ copy_user_generic(void *to, const void *from, unsigned len)
13063 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13064 "=d" (len)),
13065 "1" (to), "2" (from), "3" (len)
13066- : "memory", "rcx", "r8", "r9", "r10", "r11");
13067+ : "memory", "rcx", "r8", "r9", "r11");
13068 return ret;
13069 }
13070
13071+static __always_inline __must_check unsigned long
13072+__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13073+static __always_inline __must_check unsigned long
13074+__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13075 __must_check unsigned long
13076-_copy_to_user(void __user *to, const void *from, unsigned len);
13077-__must_check unsigned long
13078-_copy_from_user(void *to, const void __user *from, unsigned len);
13079-__must_check unsigned long
13080-copy_in_user(void __user *to, const void __user *from, unsigned len);
13081+copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13082+
13083+extern void copy_to_user_overflow(void)
13084+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13085+ __compiletime_error("copy_to_user() buffer size is not provably correct")
13086+#else
13087+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
13088+#endif
13089+;
13090+
13091+extern void copy_from_user_overflow(void)
13092+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13093+ __compiletime_error("copy_from_user() buffer size is not provably correct")
13094+#else
13095+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
13096+#endif
13097+;
13098
13099 static inline unsigned long __must_check copy_from_user(void *to,
13100 const void __user *from,
13101 unsigned long n)
13102 {
13103- int sz = __compiletime_object_size(to);
13104-
13105 might_fault();
13106- if (likely(sz == -1 || sz >= n))
13107- n = _copy_from_user(to, from, n);
13108-#ifdef CONFIG_DEBUG_VM
13109- else
13110- WARN(1, "Buffer overflow detected!\n");
13111-#endif
13112+
13113+ if (access_ok(VERIFY_READ, from, n))
13114+ n = __copy_from_user(to, from, n);
13115+ else if (n < INT_MAX) {
13116+ if (!__builtin_constant_p(n))
13117+ check_object_size(to, n, false);
13118+ memset(to, 0, n);
13119+ }
13120 return n;
13121 }
13122
13123 static __always_inline __must_check
13124-int copy_to_user(void __user *dst, const void *src, unsigned size)
13125+int copy_to_user(void __user *dst, const void *src, unsigned long size)
13126 {
13127 might_fault();
13128
13129- return _copy_to_user(dst, src, size);
13130+ if (access_ok(VERIFY_WRITE, dst, size))
13131+ size = __copy_to_user(dst, src, size);
13132+ return size;
13133 }
13134
13135 static __always_inline __must_check
13136-int __copy_from_user(void *dst, const void __user *src, unsigned size)
13137+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13138 {
13139- int ret = 0;
13140+ size_t sz = __compiletime_object_size(dst);
13141+ unsigned ret = 0;
13142
13143 might_fault();
13144- if (!__builtin_constant_p(size))
13145- return copy_user_generic(dst, (__force void *)src, size);
13146+
13147+ if (size > INT_MAX)
13148+ return size;
13149+
13150+#ifdef CONFIG_PAX_MEMORY_UDEREF
13151+ if (!__access_ok(VERIFY_READ, src, size))
13152+ return size;
13153+#endif
13154+
13155+ if (unlikely(sz != (size_t)-1 && sz < size)) {
13156+ copy_from_user_overflow();
13157+ return size;
13158+ }
13159+
13160+ if (!__builtin_constant_p(size)) {
13161+ check_object_size(dst, size, false);
13162+
13163+#ifdef CONFIG_PAX_MEMORY_UDEREF
13164+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13165+ src += PAX_USER_SHADOW_BASE;
13166+#endif
13167+
13168+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13169+ }
13170 switch (size) {
13171- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13172+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13173 ret, "b", "b", "=q", 1);
13174 return ret;
13175- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13176+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13177 ret, "w", "w", "=r", 2);
13178 return ret;
13179- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13180+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13181 ret, "l", "k", "=r", 4);
13182 return ret;
13183- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13184+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13185 ret, "q", "", "=r", 8);
13186 return ret;
13187 case 10:
13188- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13189+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13190 ret, "q", "", "=r", 10);
13191 if (unlikely(ret))
13192 return ret;
13193 __get_user_asm(*(u16 *)(8 + (char *)dst),
13194- (u16 __user *)(8 + (char __user *)src),
13195+ (const u16 __user *)(8 + (const char __user *)src),
13196 ret, "w", "w", "=r", 2);
13197 return ret;
13198 case 16:
13199- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13200+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13201 ret, "q", "", "=r", 16);
13202 if (unlikely(ret))
13203 return ret;
13204 __get_user_asm(*(u64 *)(8 + (char *)dst),
13205- (u64 __user *)(8 + (char __user *)src),
13206+ (const u64 __user *)(8 + (const char __user *)src),
13207 ret, "q", "", "=r", 8);
13208 return ret;
13209 default:
13210- return copy_user_generic(dst, (__force void *)src, size);
13211+
13212+#ifdef CONFIG_PAX_MEMORY_UDEREF
13213+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13214+ src += PAX_USER_SHADOW_BASE;
13215+#endif
13216+
13217+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13218 }
13219 }
13220
13221 static __always_inline __must_check
13222-int __copy_to_user(void __user *dst, const void *src, unsigned size)
13223+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13224 {
13225- int ret = 0;
13226+ size_t sz = __compiletime_object_size(src);
13227+ unsigned ret = 0;
13228
13229 might_fault();
13230- if (!__builtin_constant_p(size))
13231- return copy_user_generic((__force void *)dst, src, size);
13232+
13233+ if (size > INT_MAX)
13234+ return size;
13235+
13236+#ifdef CONFIG_PAX_MEMORY_UDEREF
13237+ if (!__access_ok(VERIFY_WRITE, dst, size))
13238+ return size;
13239+#endif
13240+
13241+ if (unlikely(sz != (size_t)-1 && sz < size)) {
13242+ copy_to_user_overflow();
13243+ return size;
13244+ }
13245+
13246+ if (!__builtin_constant_p(size)) {
13247+ check_object_size(src, size, true);
13248+
13249+#ifdef CONFIG_PAX_MEMORY_UDEREF
13250+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13251+ dst += PAX_USER_SHADOW_BASE;
13252+#endif
13253+
13254+ return copy_user_generic((__force_kernel void *)dst, src, size);
13255+ }
13256 switch (size) {
13257- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13258+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13259 ret, "b", "b", "iq", 1);
13260 return ret;
13261- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13262+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13263 ret, "w", "w", "ir", 2);
13264 return ret;
13265- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13266+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13267 ret, "l", "k", "ir", 4);
13268 return ret;
13269- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13270+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13271 ret, "q", "", "er", 8);
13272 return ret;
13273 case 10:
13274- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13275+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13276 ret, "q", "", "er", 10);
13277 if (unlikely(ret))
13278 return ret;
13279 asm("":::"memory");
13280- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13281+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13282 ret, "w", "w", "ir", 2);
13283 return ret;
13284 case 16:
13285- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13286+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13287 ret, "q", "", "er", 16);
13288 if (unlikely(ret))
13289 return ret;
13290 asm("":::"memory");
13291- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13292+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13293 ret, "q", "", "er", 8);
13294 return ret;
13295 default:
13296- return copy_user_generic((__force void *)dst, src, size);
13297+
13298+#ifdef CONFIG_PAX_MEMORY_UDEREF
13299+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13300+ dst += PAX_USER_SHADOW_BASE;
13301+#endif
13302+
13303+ return copy_user_generic((__force_kernel void *)dst, src, size);
13304 }
13305 }
13306
13307 static __always_inline __must_check
13308-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13309+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13310 {
13311- int ret = 0;
13312+ unsigned ret = 0;
13313
13314 might_fault();
13315- if (!__builtin_constant_p(size))
13316- return copy_user_generic((__force void *)dst,
13317- (__force void *)src, size);
13318+
13319+ if (size > INT_MAX)
13320+ return size;
13321+
13322+#ifdef CONFIG_PAX_MEMORY_UDEREF
13323+ if (!__access_ok(VERIFY_READ, src, size))
13324+ return size;
13325+ if (!__access_ok(VERIFY_WRITE, dst, size))
13326+ return size;
13327+#endif
13328+
13329+ if (!__builtin_constant_p(size)) {
13330+
13331+#ifdef CONFIG_PAX_MEMORY_UDEREF
13332+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13333+ src += PAX_USER_SHADOW_BASE;
13334+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13335+ dst += PAX_USER_SHADOW_BASE;
13336+#endif
13337+
13338+ return copy_user_generic((__force_kernel void *)dst,
13339+ (__force_kernel const void *)src, size);
13340+ }
13341 switch (size) {
13342 case 1: {
13343 u8 tmp;
13344- __get_user_asm(tmp, (u8 __user *)src,
13345+ __get_user_asm(tmp, (const u8 __user *)src,
13346 ret, "b", "b", "=q", 1);
13347 if (likely(!ret))
13348 __put_user_asm(tmp, (u8 __user *)dst,
13349@@ -176,7 +277,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13350 }
13351 case 2: {
13352 u16 tmp;
13353- __get_user_asm(tmp, (u16 __user *)src,
13354+ __get_user_asm(tmp, (const u16 __user *)src,
13355 ret, "w", "w", "=r", 2);
13356 if (likely(!ret))
13357 __put_user_asm(tmp, (u16 __user *)dst,
13358@@ -186,7 +287,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13359
13360 case 4: {
13361 u32 tmp;
13362- __get_user_asm(tmp, (u32 __user *)src,
13363+ __get_user_asm(tmp, (const u32 __user *)src,
13364 ret, "l", "k", "=r", 4);
13365 if (likely(!ret))
13366 __put_user_asm(tmp, (u32 __user *)dst,
13367@@ -195,7 +296,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13368 }
13369 case 8: {
13370 u64 tmp;
13371- __get_user_asm(tmp, (u64 __user *)src,
13372+ __get_user_asm(tmp, (const u64 __user *)src,
13373 ret, "q", "", "=r", 8);
13374 if (likely(!ret))
13375 __put_user_asm(tmp, (u64 __user *)dst,
13376@@ -203,44 +304,89 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13377 return ret;
13378 }
13379 default:
13380- return copy_user_generic((__force void *)dst,
13381- (__force void *)src, size);
13382+
13383+#ifdef CONFIG_PAX_MEMORY_UDEREF
13384+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13385+ src += PAX_USER_SHADOW_BASE;
13386+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13387+ dst += PAX_USER_SHADOW_BASE;
13388+#endif
13389+
13390+ return copy_user_generic((__force_kernel void *)dst,
13391+ (__force_kernel const void *)src, size);
13392 }
13393 }
13394
13395-__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13396-__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13397+__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13398+__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13399
13400 static __must_check __always_inline int
13401-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13402+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13403 {
13404- return copy_user_generic(dst, (__force const void *)src, size);
13405+ if (size > INT_MAX)
13406+ return size;
13407+
13408+#ifdef CONFIG_PAX_MEMORY_UDEREF
13409+ if (!__access_ok(VERIFY_READ, src, size))
13410+ return size;
13411+
13412+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13413+ src += PAX_USER_SHADOW_BASE;
13414+#endif
13415+
13416+ return copy_user_generic(dst, (__force_kernel const void *)src, size);
13417 }
13418
13419-static __must_check __always_inline int
13420-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13421+static __must_check __always_inline unsigned long
13422+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13423 {
13424- return copy_user_generic((__force void *)dst, src, size);
13425+ if (size > INT_MAX)
13426+ return size;
13427+
13428+#ifdef CONFIG_PAX_MEMORY_UDEREF
13429+ if (!__access_ok(VERIFY_WRITE, dst, size))
13430+ return size;
13431+
13432+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13433+ dst += PAX_USER_SHADOW_BASE;
13434+#endif
13435+
13436+ return copy_user_generic((__force_kernel void *)dst, src, size);
13437 }
13438
13439-extern long __copy_user_nocache(void *dst, const void __user *src,
13440- unsigned size, int zerorest);
13441+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13442+ unsigned long size, int zerorest) __size_overflow(3);
13443
13444-static inline int
13445-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13446+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13447 {
13448 might_sleep();
13449+
13450+ if (size > INT_MAX)
13451+ return size;
13452+
13453+#ifdef CONFIG_PAX_MEMORY_UDEREF
13454+ if (!__access_ok(VERIFY_READ, src, size))
13455+ return size;
13456+#endif
13457+
13458 return __copy_user_nocache(dst, src, size, 1);
13459 }
13460
13461-static inline int
13462-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13463- unsigned size)
13464+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13465+ unsigned long size)
13466 {
13467+ if (size > INT_MAX)
13468+ return size;
13469+
13470+#ifdef CONFIG_PAX_MEMORY_UDEREF
13471+ if (!__access_ok(VERIFY_READ, src, size))
13472+ return size;
13473+#endif
13474+
13475 return __copy_user_nocache(dst, src, size, 0);
13476 }
13477
13478-unsigned long
13479-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13480+extern unsigned long
13481+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13482
13483 #endif /* _ASM_X86_UACCESS_64_H */
13484diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13485index bb05228..d763d5b 100644
13486--- a/arch/x86/include/asm/vdso.h
13487+++ b/arch/x86/include/asm/vdso.h
13488@@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13489 #define VDSO32_SYMBOL(base, name) \
13490 ({ \
13491 extern const char VDSO32_##name[]; \
13492- (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13493+ (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13494 })
13495 #endif
13496
13497diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
13498index 5b238981..77fdd78 100644
13499--- a/arch/x86/include/asm/word-at-a-time.h
13500+++ b/arch/x86/include/asm/word-at-a-time.h
13501@@ -11,7 +11,7 @@
13502 * and shift, for example.
13503 */
13504 struct word_at_a_time {
13505- const unsigned long one_bits, high_bits;
13506+ unsigned long one_bits, high_bits;
13507 };
13508
13509 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
13510diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13511index c090af1..7e7bf16 100644
13512--- a/arch/x86/include/asm/x86_init.h
13513+++ b/arch/x86/include/asm/x86_init.h
13514@@ -29,7 +29,7 @@ struct x86_init_mpparse {
13515 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13516 void (*find_smp_config)(void);
13517 void (*get_smp_config)(unsigned int early);
13518-};
13519+} __no_const;
13520
13521 /**
13522 * struct x86_init_resources - platform specific resource related ops
13523@@ -43,7 +43,7 @@ struct x86_init_resources {
13524 void (*probe_roms)(void);
13525 void (*reserve_resources)(void);
13526 char *(*memory_setup)(void);
13527-};
13528+} __no_const;
13529
13530 /**
13531 * struct x86_init_irqs - platform specific interrupt setup
13532@@ -56,7 +56,7 @@ struct x86_init_irqs {
13533 void (*pre_vector_init)(void);
13534 void (*intr_init)(void);
13535 void (*trap_init)(void);
13536-};
13537+} __no_const;
13538
13539 /**
13540 * struct x86_init_oem - oem platform specific customizing functions
13541@@ -66,7 +66,7 @@ struct x86_init_irqs {
13542 struct x86_init_oem {
13543 void (*arch_setup)(void);
13544 void (*banner)(void);
13545-};
13546+} __no_const;
13547
13548 /**
13549 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13550@@ -77,7 +77,7 @@ struct x86_init_oem {
13551 */
13552 struct x86_init_mapping {
13553 void (*pagetable_reserve)(u64 start, u64 end);
13554-};
13555+} __no_const;
13556
13557 /**
13558 * struct x86_init_paging - platform specific paging functions
13559@@ -87,7 +87,7 @@ struct x86_init_mapping {
13560 struct x86_init_paging {
13561 void (*pagetable_setup_start)(pgd_t *base);
13562 void (*pagetable_setup_done)(pgd_t *base);
13563-};
13564+} __no_const;
13565
13566 /**
13567 * struct x86_init_timers - platform specific timer setup
13568@@ -102,7 +102,7 @@ struct x86_init_timers {
13569 void (*tsc_pre_init)(void);
13570 void (*timer_init)(void);
13571 void (*wallclock_init)(void);
13572-};
13573+} __no_const;
13574
13575 /**
13576 * struct x86_init_iommu - platform specific iommu setup
13577@@ -110,7 +110,7 @@ struct x86_init_timers {
13578 */
13579 struct x86_init_iommu {
13580 int (*iommu_init)(void);
13581-};
13582+} __no_const;
13583
13584 /**
13585 * struct x86_init_pci - platform specific pci init functions
13586@@ -124,7 +124,7 @@ struct x86_init_pci {
13587 int (*init)(void);
13588 void (*init_irq)(void);
13589 void (*fixup_irqs)(void);
13590-};
13591+} __no_const;
13592
13593 /**
13594 * struct x86_init_ops - functions for platform specific setup
13595@@ -140,7 +140,7 @@ struct x86_init_ops {
13596 struct x86_init_timers timers;
13597 struct x86_init_iommu iommu;
13598 struct x86_init_pci pci;
13599-};
13600+} __no_const;
13601
13602 /**
13603 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13604@@ -151,7 +151,7 @@ struct x86_cpuinit_ops {
13605 void (*setup_percpu_clockev)(void);
13606 void (*early_percpu_clock_init)(void);
13607 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13608-};
13609+} __no_const;
13610
13611 /**
13612 * struct x86_platform_ops - platform specific runtime functions
13613@@ -177,7 +177,7 @@ struct x86_platform_ops {
13614 int (*i8042_detect)(void);
13615 void (*save_sched_clock_state)(void);
13616 void (*restore_sched_clock_state)(void);
13617-};
13618+} __no_const;
13619
13620 struct pci_dev;
13621
13622@@ -186,14 +186,14 @@ struct x86_msi_ops {
13623 void (*teardown_msi_irq)(unsigned int irq);
13624 void (*teardown_msi_irqs)(struct pci_dev *dev);
13625 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13626-};
13627+} __no_const;
13628
13629 struct x86_io_apic_ops {
13630 void (*init) (void);
13631 unsigned int (*read) (unsigned int apic, unsigned int reg);
13632 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
13633 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
13634-};
13635+} __no_const;
13636
13637 extern struct x86_init_ops x86_init;
13638 extern struct x86_cpuinit_ops x86_cpuinit;
13639diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13640index 8a1b6f9..a29c4e4 100644
13641--- a/arch/x86/include/asm/xsave.h
13642+++ b/arch/x86/include/asm/xsave.h
13643@@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13644 {
13645 int err;
13646
13647+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13648+ if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13649+ buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13650+#endif
13651+
13652 /*
13653 * Clear the xsave header first, so that reserved fields are
13654 * initialized to zero.
13655@@ -93,10 +98,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13656 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13657 {
13658 int err;
13659- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13660+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13661 u32 lmask = mask;
13662 u32 hmask = mask >> 32;
13663
13664+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13665+ if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13666+ xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13667+#endif
13668+
13669 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13670 "2:\n"
13671 ".section .fixup,\"ax\"\n"
13672diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13673index 95bf99de..de9235c 100644
13674--- a/arch/x86/kernel/acpi/sleep.c
13675+++ b/arch/x86/kernel/acpi/sleep.c
13676@@ -73,8 +73,12 @@ int acpi_suspend_lowlevel(void)
13677 #else /* CONFIG_64BIT */
13678 #ifdef CONFIG_SMP
13679 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13680+
13681+ pax_open_kernel();
13682 early_gdt_descr.address =
13683 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13684+ pax_close_kernel();
13685+
13686 initial_gs = per_cpu_offset(smp_processor_id());
13687 #endif
13688 initial_code = (unsigned long)wakeup_long64;
13689diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13690index 7261083..5c12053 100644
13691--- a/arch/x86/kernel/acpi/wakeup_32.S
13692+++ b/arch/x86/kernel/acpi/wakeup_32.S
13693@@ -30,13 +30,11 @@ wakeup_pmode_return:
13694 # and restore the stack ... but you need gdt for this to work
13695 movl saved_context_esp, %esp
13696
13697- movl %cs:saved_magic, %eax
13698- cmpl $0x12345678, %eax
13699+ cmpl $0x12345678, saved_magic
13700 jne bogus_magic
13701
13702 # jump to place where we left off
13703- movl saved_eip, %eax
13704- jmp *%eax
13705+ jmp *(saved_eip)
13706
13707 bogus_magic:
13708 jmp bogus_magic
13709diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13710index 73ef56c..0238021 100644
13711--- a/arch/x86/kernel/alternative.c
13712+++ b/arch/x86/kernel/alternative.c
13713@@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13714 */
13715 for (a = start; a < end; a++) {
13716 instr = (u8 *)&a->instr_offset + a->instr_offset;
13717+
13718+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13719+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13720+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13721+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13722+#endif
13723+
13724 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13725 BUG_ON(a->replacementlen > a->instrlen);
13726 BUG_ON(a->instrlen > sizeof(insnbuf));
13727@@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13728 for (poff = start; poff < end; poff++) {
13729 u8 *ptr = (u8 *)poff + *poff;
13730
13731+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13732+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13733+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13734+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13735+#endif
13736+
13737 if (!*poff || ptr < text || ptr >= text_end)
13738 continue;
13739 /* turn DS segment override prefix into lock prefix */
13740- if (*ptr == 0x3e)
13741+ if (*ktla_ktva(ptr) == 0x3e)
13742 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13743 };
13744 mutex_unlock(&text_mutex);
13745@@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13746 for (poff = start; poff < end; poff++) {
13747 u8 *ptr = (u8 *)poff + *poff;
13748
13749+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13750+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13751+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13752+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13753+#endif
13754+
13755 if (!*poff || ptr < text || ptr >= text_end)
13756 continue;
13757 /* turn lock prefix into DS segment override prefix */
13758- if (*ptr == 0xf0)
13759+ if (*ktla_ktva(ptr) == 0xf0)
13760 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13761 };
13762 mutex_unlock(&text_mutex);
13763@@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13764
13765 BUG_ON(p->len > MAX_PATCH_LEN);
13766 /* prep the buffer with the original instructions */
13767- memcpy(insnbuf, p->instr, p->len);
13768+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13769 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13770 (unsigned long)p->instr, p->len);
13771
13772@@ -568,7 +587,7 @@ void __init alternative_instructions(void)
13773 if (smp_alt_once)
13774 free_init_pages("SMP alternatives",
13775 (unsigned long)__smp_locks,
13776- (unsigned long)__smp_locks_end);
13777+ PAGE_ALIGN((unsigned long)__smp_locks_end));
13778
13779 restart_nmi();
13780 }
13781@@ -585,13 +604,17 @@ void __init alternative_instructions(void)
13782 * instructions. And on the local CPU you need to be protected again NMI or MCE
13783 * handlers seeing an inconsistent instruction while you patch.
13784 */
13785-void *__init_or_module text_poke_early(void *addr, const void *opcode,
13786+void *__kprobes text_poke_early(void *addr, const void *opcode,
13787 size_t len)
13788 {
13789 unsigned long flags;
13790 local_irq_save(flags);
13791- memcpy(addr, opcode, len);
13792+
13793+ pax_open_kernel();
13794+ memcpy(ktla_ktva(addr), opcode, len);
13795 sync_core();
13796+ pax_close_kernel();
13797+
13798 local_irq_restore(flags);
13799 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13800 that causes hangs on some VIA CPUs. */
13801@@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13802 */
13803 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13804 {
13805- unsigned long flags;
13806- char *vaddr;
13807+ unsigned char *vaddr = ktla_ktva(addr);
13808 struct page *pages[2];
13809- int i;
13810+ size_t i;
13811
13812 if (!core_kernel_text((unsigned long)addr)) {
13813- pages[0] = vmalloc_to_page(addr);
13814- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13815+ pages[0] = vmalloc_to_page(vaddr);
13816+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13817 } else {
13818- pages[0] = virt_to_page(addr);
13819+ pages[0] = virt_to_page(vaddr);
13820 WARN_ON(!PageReserved(pages[0]));
13821- pages[1] = virt_to_page(addr + PAGE_SIZE);
13822+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13823 }
13824 BUG_ON(!pages[0]);
13825- local_irq_save(flags);
13826- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13827- if (pages[1])
13828- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13829- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13830- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13831- clear_fixmap(FIX_TEXT_POKE0);
13832- if (pages[1])
13833- clear_fixmap(FIX_TEXT_POKE1);
13834- local_flush_tlb();
13835- sync_core();
13836- /* Could also do a CLFLUSH here to speed up CPU recovery; but
13837- that causes hangs on some VIA CPUs. */
13838+ text_poke_early(addr, opcode, len);
13839 for (i = 0; i < len; i++)
13840- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13841- local_irq_restore(flags);
13842+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13843 return addr;
13844 }
13845
13846diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13847index 39a222e..85a7767 100644
13848--- a/arch/x86/kernel/apic/apic.c
13849+++ b/arch/x86/kernel/apic/apic.c
13850@@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
13851 /*
13852 * Debug level, exported for io_apic.c
13853 */
13854-unsigned int apic_verbosity;
13855+int apic_verbosity;
13856
13857 int pic_mode;
13858
13859@@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13860 apic_write(APIC_ESR, 0);
13861 v1 = apic_read(APIC_ESR);
13862 ack_APIC_irq();
13863- atomic_inc(&irq_err_count);
13864+ atomic_inc_unchecked(&irq_err_count);
13865
13866 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13867 smp_processor_id(), v0 , v1);
13868diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13869index 5f0ff59..f9e01bc 100644
13870--- a/arch/x86/kernel/apic/io_apic.c
13871+++ b/arch/x86/kernel/apic/io_apic.c
13872@@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13873 }
13874 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13875
13876-void lock_vector_lock(void)
13877+void lock_vector_lock(void) __acquires(vector_lock)
13878 {
13879 /* Used to the online set of cpus does not change
13880 * during assign_irq_vector.
13881@@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
13882 raw_spin_lock(&vector_lock);
13883 }
13884
13885-void unlock_vector_lock(void)
13886+void unlock_vector_lock(void) __releases(vector_lock)
13887 {
13888 raw_spin_unlock(&vector_lock);
13889 }
13890@@ -2369,7 +2369,7 @@ static void ack_apic_edge(struct irq_data *data)
13891 ack_APIC_irq();
13892 }
13893
13894-atomic_t irq_mis_count;
13895+atomic_unchecked_t irq_mis_count;
13896
13897 #ifdef CONFIG_GENERIC_PENDING_IRQ
13898 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
13899@@ -2510,7 +2510,7 @@ static void ack_apic_level(struct irq_data *data)
13900 * at the cpu.
13901 */
13902 if (!(v & (1 << (i & 0x1f)))) {
13903- atomic_inc(&irq_mis_count);
13904+ atomic_inc_unchecked(&irq_mis_count);
13905
13906 eoi_ioapic_irq(irq, cfg);
13907 }
13908diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13909index 07b0c0d..1df6f42 100644
13910--- a/arch/x86/kernel/apm_32.c
13911+++ b/arch/x86/kernel/apm_32.c
13912@@ -410,7 +410,7 @@ static DEFINE_MUTEX(apm_mutex);
13913 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13914 * even though they are called in protected mode.
13915 */
13916-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
13917+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
13918 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
13919
13920 static const char driver_version[] = "1.16ac"; /* no spaces */
13921@@ -588,7 +588,10 @@ static long __apm_bios_call(void *_call)
13922 BUG_ON(cpu != 0);
13923 gdt = get_cpu_gdt_table(cpu);
13924 save_desc_40 = gdt[0x40 / 8];
13925+
13926+ pax_open_kernel();
13927 gdt[0x40 / 8] = bad_bios_desc;
13928+ pax_close_kernel();
13929
13930 apm_irq_save(flags);
13931 APM_DO_SAVE_SEGS;
13932@@ -597,7 +600,11 @@ static long __apm_bios_call(void *_call)
13933 &call->esi);
13934 APM_DO_RESTORE_SEGS;
13935 apm_irq_restore(flags);
13936+
13937+ pax_open_kernel();
13938 gdt[0x40 / 8] = save_desc_40;
13939+ pax_close_kernel();
13940+
13941 put_cpu();
13942
13943 return call->eax & 0xff;
13944@@ -664,7 +671,10 @@ static long __apm_bios_call_simple(void *_call)
13945 BUG_ON(cpu != 0);
13946 gdt = get_cpu_gdt_table(cpu);
13947 save_desc_40 = gdt[0x40 / 8];
13948+
13949+ pax_open_kernel();
13950 gdt[0x40 / 8] = bad_bios_desc;
13951+ pax_close_kernel();
13952
13953 apm_irq_save(flags);
13954 APM_DO_SAVE_SEGS;
13955@@ -672,7 +682,11 @@ static long __apm_bios_call_simple(void *_call)
13956 &call->eax);
13957 APM_DO_RESTORE_SEGS;
13958 apm_irq_restore(flags);
13959+
13960+ pax_open_kernel();
13961 gdt[0x40 / 8] = save_desc_40;
13962+ pax_close_kernel();
13963+
13964 put_cpu();
13965 return error;
13966 }
13967@@ -2345,12 +2359,15 @@ static int __init apm_init(void)
13968 * code to that CPU.
13969 */
13970 gdt = get_cpu_gdt_table(0);
13971+
13972+ pax_open_kernel();
13973 set_desc_base(&gdt[APM_CS >> 3],
13974 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
13975 set_desc_base(&gdt[APM_CS_16 >> 3],
13976 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
13977 set_desc_base(&gdt[APM_DS >> 3],
13978 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
13979+ pax_close_kernel();
13980
13981 proc_create("apm", 0, NULL, &apm_file_ops);
13982
13983diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
13984index 68de2dc..1f3c720 100644
13985--- a/arch/x86/kernel/asm-offsets.c
13986+++ b/arch/x86/kernel/asm-offsets.c
13987@@ -33,6 +33,8 @@ void common(void) {
13988 OFFSET(TI_status, thread_info, status);
13989 OFFSET(TI_addr_limit, thread_info, addr_limit);
13990 OFFSET(TI_preempt_count, thread_info, preempt_count);
13991+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
13992+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
13993
13994 BLANK();
13995 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
13996@@ -53,8 +55,26 @@ void common(void) {
13997 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
13998 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
13999 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
14000+
14001+#ifdef CONFIG_PAX_KERNEXEC
14002+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
14003 #endif
14004
14005+#ifdef CONFIG_PAX_MEMORY_UDEREF
14006+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
14007+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
14008+#ifdef CONFIG_X86_64
14009+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
14010+#endif
14011+#endif
14012+
14013+#endif
14014+
14015+ BLANK();
14016+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
14017+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
14018+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
14019+
14020 #ifdef CONFIG_XEN
14021 BLANK();
14022 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
14023diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
14024index 1b4754f..fbb4227 100644
14025--- a/arch/x86/kernel/asm-offsets_64.c
14026+++ b/arch/x86/kernel/asm-offsets_64.c
14027@@ -76,6 +76,7 @@ int main(void)
14028 BLANK();
14029 #undef ENTRY
14030
14031+ DEFINE(TSS_size, sizeof(struct tss_struct));
14032 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
14033 BLANK();
14034
14035diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14036index 6ab6aa2..8f71507 100644
14037--- a/arch/x86/kernel/cpu/Makefile
14038+++ b/arch/x86/kernel/cpu/Makefile
14039@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14040 CFLAGS_REMOVE_perf_event.o = -pg
14041 endif
14042
14043-# Make sure load_percpu_segment has no stackprotector
14044-nostackp := $(call cc-option, -fno-stack-protector)
14045-CFLAGS_common.o := $(nostackp)
14046-
14047 obj-y := intel_cacheinfo.o scattered.o topology.o
14048 obj-y += proc.o capflags.o powerflags.o common.o
14049 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
14050diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14051index 146bb62..ac9c74a 100644
14052--- a/arch/x86/kernel/cpu/amd.c
14053+++ b/arch/x86/kernel/cpu/amd.c
14054@@ -691,7 +691,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14055 unsigned int size)
14056 {
14057 /* AMD errata T13 (order #21922) */
14058- if ((c->x86 == 6)) {
14059+ if (c->x86 == 6) {
14060 /* Duron Rev A0 */
14061 if (c->x86_model == 3 && c->x86_mask == 0)
14062 size = 64;
14063diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14064index 6b9333b..4c3083a 100644
14065--- a/arch/x86/kernel/cpu/common.c
14066+++ b/arch/x86/kernel/cpu/common.c
14067@@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14068
14069 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14070
14071-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14072-#ifdef CONFIG_X86_64
14073- /*
14074- * We need valid kernel segments for data and code in long mode too
14075- * IRET will check the segment types kkeil 2000/10/28
14076- * Also sysret mandates a special GDT layout
14077- *
14078- * TLS descriptors are currently at a different place compared to i386.
14079- * Hopefully nobody expects them at a fixed place (Wine?)
14080- */
14081- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14082- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14083- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14084- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14085- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14086- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14087-#else
14088- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14089- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14090- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14091- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14092- /*
14093- * Segments used for calling PnP BIOS have byte granularity.
14094- * They code segments and data segments have fixed 64k limits,
14095- * the transfer segment sizes are set at run time.
14096- */
14097- /* 32-bit code */
14098- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14099- /* 16-bit code */
14100- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14101- /* 16-bit data */
14102- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14103- /* 16-bit data */
14104- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14105- /* 16-bit data */
14106- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14107- /*
14108- * The APM segments have byte granularity and their bases
14109- * are set at run time. All have 64k limits.
14110- */
14111- /* 32-bit code */
14112- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14113- /* 16-bit code */
14114- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14115- /* data */
14116- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14117-
14118- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14119- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14120- GDT_STACK_CANARY_INIT
14121-#endif
14122-} };
14123-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14124-
14125 static int __init x86_xsave_setup(char *s)
14126 {
14127 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14128@@ -374,7 +320,7 @@ void switch_to_new_gdt(int cpu)
14129 {
14130 struct desc_ptr gdt_descr;
14131
14132- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14133+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14134 gdt_descr.size = GDT_SIZE - 1;
14135 load_gdt(&gdt_descr);
14136 /* Reload the per-cpu base */
14137@@ -841,6 +787,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14138 /* Filter out anything that depends on CPUID levels we don't have */
14139 filter_cpuid_features(c, true);
14140
14141+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14142+ setup_clear_cpu_cap(X86_FEATURE_SEP);
14143+#endif
14144+
14145 /* If the model name is still unset, do table lookup. */
14146 if (!c->x86_model_id[0]) {
14147 const char *p;
14148@@ -1021,10 +971,12 @@ static __init int setup_disablecpuid(char *arg)
14149 }
14150 __setup("clearcpuid=", setup_disablecpuid);
14151
14152+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14153+EXPORT_PER_CPU_SYMBOL(current_tinfo);
14154+
14155 #ifdef CONFIG_X86_64
14156 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14157-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14158- (unsigned long) nmi_idt_table };
14159+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14160
14161 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14162 irq_stack_union) __aligned(PAGE_SIZE);
14163@@ -1038,7 +990,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14164 EXPORT_PER_CPU_SYMBOL(current_task);
14165
14166 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14167- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14168+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14169 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14170
14171 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14172@@ -1132,7 +1084,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14173 {
14174 memset(regs, 0, sizeof(struct pt_regs));
14175 regs->fs = __KERNEL_PERCPU;
14176- regs->gs = __KERNEL_STACK_CANARY;
14177+ savesegment(gs, regs->gs);
14178
14179 return regs;
14180 }
14181@@ -1187,7 +1139,7 @@ void __cpuinit cpu_init(void)
14182 int i;
14183
14184 cpu = stack_smp_processor_id();
14185- t = &per_cpu(init_tss, cpu);
14186+ t = init_tss + cpu;
14187 oist = &per_cpu(orig_ist, cpu);
14188
14189 #ifdef CONFIG_NUMA
14190@@ -1213,7 +1165,7 @@ void __cpuinit cpu_init(void)
14191 switch_to_new_gdt(cpu);
14192 loadsegment(fs, 0);
14193
14194- load_idt((const struct desc_ptr *)&idt_descr);
14195+ load_idt(&idt_descr);
14196
14197 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14198 syscall_init();
14199@@ -1222,7 +1174,6 @@ void __cpuinit cpu_init(void)
14200 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14201 barrier();
14202
14203- x86_configure_nx();
14204 if (cpu != 0)
14205 enable_x2apic();
14206
14207@@ -1278,7 +1229,7 @@ void __cpuinit cpu_init(void)
14208 {
14209 int cpu = smp_processor_id();
14210 struct task_struct *curr = current;
14211- struct tss_struct *t = &per_cpu(init_tss, cpu);
14212+ struct tss_struct *t = init_tss + cpu;
14213 struct thread_struct *thread = &curr->thread;
14214
14215 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14216diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14217index 3e6ff6c..54b4992 100644
14218--- a/arch/x86/kernel/cpu/intel.c
14219+++ b/arch/x86/kernel/cpu/intel.c
14220@@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14221 * Update the IDT descriptor and reload the IDT so that
14222 * it uses the read-only mapped virtual address.
14223 */
14224- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14225+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14226 load_idt(&idt_descr);
14227 }
14228 #endif
14229diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14230index c46ed49..5dc0a53 100644
14231--- a/arch/x86/kernel/cpu/mcheck/mce.c
14232+++ b/arch/x86/kernel/cpu/mcheck/mce.c
14233@@ -42,6 +42,7 @@
14234 #include <asm/processor.h>
14235 #include <asm/mce.h>
14236 #include <asm/msr.h>
14237+#include <asm/local.h>
14238
14239 #include "mce-internal.h"
14240
14241@@ -250,7 +251,7 @@ static void print_mce(struct mce *m)
14242 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14243 m->cs, m->ip);
14244
14245- if (m->cs == __KERNEL_CS)
14246+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14247 print_symbol("{%s}", m->ip);
14248 pr_cont("\n");
14249 }
14250@@ -283,10 +284,10 @@ static void print_mce(struct mce *m)
14251
14252 #define PANIC_TIMEOUT 5 /* 5 seconds */
14253
14254-static atomic_t mce_paniced;
14255+static atomic_unchecked_t mce_paniced;
14256
14257 static int fake_panic;
14258-static atomic_t mce_fake_paniced;
14259+static atomic_unchecked_t mce_fake_paniced;
14260
14261 /* Panic in progress. Enable interrupts and wait for final IPI */
14262 static void wait_for_panic(void)
14263@@ -310,7 +311,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14264 /*
14265 * Make sure only one CPU runs in machine check panic
14266 */
14267- if (atomic_inc_return(&mce_paniced) > 1)
14268+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14269 wait_for_panic();
14270 barrier();
14271
14272@@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14273 console_verbose();
14274 } else {
14275 /* Don't log too much for fake panic */
14276- if (atomic_inc_return(&mce_fake_paniced) > 1)
14277+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14278 return;
14279 }
14280 /* First print corrected ones that are still unlogged */
14281@@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
14282 * might have been modified by someone else.
14283 */
14284 rmb();
14285- if (atomic_read(&mce_paniced))
14286+ if (atomic_read_unchecked(&mce_paniced))
14287 wait_for_panic();
14288 if (!monarch_timeout)
14289 goto out;
14290@@ -1581,7 +1582,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14291 }
14292
14293 /* Call the installed machine check handler for this CPU setup. */
14294-void (*machine_check_vector)(struct pt_regs *, long error_code) =
14295+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14296 unexpected_machine_check;
14297
14298 /*
14299@@ -1604,7 +1605,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14300 return;
14301 }
14302
14303+ pax_open_kernel();
14304 machine_check_vector = do_machine_check;
14305+ pax_close_kernel();
14306
14307 __mcheck_cpu_init_generic();
14308 __mcheck_cpu_init_vendor(c);
14309@@ -1618,7 +1621,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14310 */
14311
14312 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14313-static int mce_chrdev_open_count; /* #times opened */
14314+static local_t mce_chrdev_open_count; /* #times opened */
14315 static int mce_chrdev_open_exclu; /* already open exclusive? */
14316
14317 static int mce_chrdev_open(struct inode *inode, struct file *file)
14318@@ -1626,7 +1629,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14319 spin_lock(&mce_chrdev_state_lock);
14320
14321 if (mce_chrdev_open_exclu ||
14322- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14323+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14324 spin_unlock(&mce_chrdev_state_lock);
14325
14326 return -EBUSY;
14327@@ -1634,7 +1637,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14328
14329 if (file->f_flags & O_EXCL)
14330 mce_chrdev_open_exclu = 1;
14331- mce_chrdev_open_count++;
14332+ local_inc(&mce_chrdev_open_count);
14333
14334 spin_unlock(&mce_chrdev_state_lock);
14335
14336@@ -1645,7 +1648,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14337 {
14338 spin_lock(&mce_chrdev_state_lock);
14339
14340- mce_chrdev_open_count--;
14341+ local_dec(&mce_chrdev_open_count);
14342 mce_chrdev_open_exclu = 0;
14343
14344 spin_unlock(&mce_chrdev_state_lock);
14345@@ -2370,7 +2373,7 @@ struct dentry *mce_get_debugfs_dir(void)
14346 static void mce_reset(void)
14347 {
14348 cpu_missing = 0;
14349- atomic_set(&mce_fake_paniced, 0);
14350+ atomic_set_unchecked(&mce_fake_paniced, 0);
14351 atomic_set(&mce_executing, 0);
14352 atomic_set(&mce_callin, 0);
14353 atomic_set(&global_nwo, 0);
14354diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14355index 2d5454c..51987eb 100644
14356--- a/arch/x86/kernel/cpu/mcheck/p5.c
14357+++ b/arch/x86/kernel/cpu/mcheck/p5.c
14358@@ -11,6 +11,7 @@
14359 #include <asm/processor.h>
14360 #include <asm/mce.h>
14361 #include <asm/msr.h>
14362+#include <asm/pgtable.h>
14363
14364 /* By default disabled */
14365 int mce_p5_enabled __read_mostly;
14366@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14367 if (!cpu_has(c, X86_FEATURE_MCE))
14368 return;
14369
14370+ pax_open_kernel();
14371 machine_check_vector = pentium_machine_check;
14372+ pax_close_kernel();
14373 /* Make sure the vector pointer is visible before we enable MCEs: */
14374 wmb();
14375
14376diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14377index 2d7998f..17c9de1 100644
14378--- a/arch/x86/kernel/cpu/mcheck/winchip.c
14379+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14380@@ -10,6 +10,7 @@
14381 #include <asm/processor.h>
14382 #include <asm/mce.h>
14383 #include <asm/msr.h>
14384+#include <asm/pgtable.h>
14385
14386 /* Machine check handler for WinChip C6: */
14387 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14388@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14389 {
14390 u32 lo, hi;
14391
14392+ pax_open_kernel();
14393 machine_check_vector = winchip_machine_check;
14394+ pax_close_kernel();
14395 /* Make sure the vector pointer is visible before we enable MCEs: */
14396 wmb();
14397
14398diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14399index 6b96110..0da73eb 100644
14400--- a/arch/x86/kernel/cpu/mtrr/main.c
14401+++ b/arch/x86/kernel/cpu/mtrr/main.c
14402@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14403 u64 size_or_mask, size_and_mask;
14404 static bool mtrr_aps_delayed_init;
14405
14406-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14407+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14408
14409 const struct mtrr_ops *mtrr_if;
14410
14411diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14412index df5e41f..816c719 100644
14413--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14414+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14415@@ -25,7 +25,7 @@ struct mtrr_ops {
14416 int (*validate_add_page)(unsigned long base, unsigned long size,
14417 unsigned int type);
14418 int (*have_wrcomb)(void);
14419-};
14420+} __do_const;
14421
14422 extern int generic_get_free_region(unsigned long base, unsigned long size,
14423 int replace_reg);
14424diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14425index c4706cf..264b0f7 100644
14426--- a/arch/x86/kernel/cpu/perf_event.c
14427+++ b/arch/x86/kernel/cpu/perf_event.c
14428@@ -1837,7 +1837,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14429 break;
14430
14431 perf_callchain_store(entry, frame.return_address);
14432- fp = frame.next_frame;
14433+ fp = (const void __force_user *)frame.next_frame;
14434 }
14435 }
14436
14437diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14438index 13ad899..f642b9a 100644
14439--- a/arch/x86/kernel/crash.c
14440+++ b/arch/x86/kernel/crash.c
14441@@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14442 {
14443 #ifdef CONFIG_X86_32
14444 struct pt_regs fixed_regs;
14445-#endif
14446
14447-#ifdef CONFIG_X86_32
14448- if (!user_mode_vm(regs)) {
14449+ if (!user_mode(regs)) {
14450 crash_fixup_ss_esp(&fixed_regs, regs);
14451 regs = &fixed_regs;
14452 }
14453diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14454index 37250fe..bf2ec74 100644
14455--- a/arch/x86/kernel/doublefault_32.c
14456+++ b/arch/x86/kernel/doublefault_32.c
14457@@ -11,7 +11,7 @@
14458
14459 #define DOUBLEFAULT_STACKSIZE (1024)
14460 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14461-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14462+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14463
14464 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14465
14466@@ -21,7 +21,7 @@ static void doublefault_fn(void)
14467 unsigned long gdt, tss;
14468
14469 store_gdt(&gdt_desc);
14470- gdt = gdt_desc.address;
14471+ gdt = (unsigned long)gdt_desc.address;
14472
14473 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14474
14475@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14476 /* 0x2 bit is always set */
14477 .flags = X86_EFLAGS_SF | 0x2,
14478 .sp = STACK_START,
14479- .es = __USER_DS,
14480+ .es = __KERNEL_DS,
14481 .cs = __KERNEL_CS,
14482 .ss = __KERNEL_DS,
14483- .ds = __USER_DS,
14484+ .ds = __KERNEL_DS,
14485 .fs = __KERNEL_PERCPU,
14486
14487 .__cr3 = __pa_nodebug(swapper_pg_dir),
14488diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14489index 571246d..81f335c 100644
14490--- a/arch/x86/kernel/dumpstack.c
14491+++ b/arch/x86/kernel/dumpstack.c
14492@@ -2,6 +2,9 @@
14493 * Copyright (C) 1991, 1992 Linus Torvalds
14494 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14495 */
14496+#ifdef CONFIG_GRKERNSEC_HIDESYM
14497+#define __INCLUDED_BY_HIDESYM 1
14498+#endif
14499 #include <linux/kallsyms.h>
14500 #include <linux/kprobes.h>
14501 #include <linux/uaccess.h>
14502@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
14503 static void
14504 print_ftrace_graph_addr(unsigned long addr, void *data,
14505 const struct stacktrace_ops *ops,
14506- struct thread_info *tinfo, int *graph)
14507+ struct task_struct *task, int *graph)
14508 {
14509- struct task_struct *task;
14510 unsigned long ret_addr;
14511 int index;
14512
14513 if (addr != (unsigned long)return_to_handler)
14514 return;
14515
14516- task = tinfo->task;
14517 index = task->curr_ret_stack;
14518
14519 if (!task->ret_stack || index < *graph)
14520@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14521 static inline void
14522 print_ftrace_graph_addr(unsigned long addr, void *data,
14523 const struct stacktrace_ops *ops,
14524- struct thread_info *tinfo, int *graph)
14525+ struct task_struct *task, int *graph)
14526 { }
14527 #endif
14528
14529@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14530 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14531 */
14532
14533-static inline int valid_stack_ptr(struct thread_info *tinfo,
14534- void *p, unsigned int size, void *end)
14535+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14536 {
14537- void *t = tinfo;
14538 if (end) {
14539 if (p < end && p >= (end-THREAD_SIZE))
14540 return 1;
14541@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14542 }
14543
14544 unsigned long
14545-print_context_stack(struct thread_info *tinfo,
14546+print_context_stack(struct task_struct *task, void *stack_start,
14547 unsigned long *stack, unsigned long bp,
14548 const struct stacktrace_ops *ops, void *data,
14549 unsigned long *end, int *graph)
14550 {
14551 struct stack_frame *frame = (struct stack_frame *)bp;
14552
14553- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14554+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14555 unsigned long addr;
14556
14557 addr = *stack;
14558@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
14559 } else {
14560 ops->address(data, addr, 0);
14561 }
14562- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14563+ print_ftrace_graph_addr(addr, data, ops, task, graph);
14564 }
14565 stack++;
14566 }
14567@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
14568 EXPORT_SYMBOL_GPL(print_context_stack);
14569
14570 unsigned long
14571-print_context_stack_bp(struct thread_info *tinfo,
14572+print_context_stack_bp(struct task_struct *task, void *stack_start,
14573 unsigned long *stack, unsigned long bp,
14574 const struct stacktrace_ops *ops, void *data,
14575 unsigned long *end, int *graph)
14576@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14577 struct stack_frame *frame = (struct stack_frame *)bp;
14578 unsigned long *ret_addr = &frame->return_address;
14579
14580- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14581+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14582 unsigned long addr = *ret_addr;
14583
14584 if (!__kernel_text_address(addr))
14585@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14586 ops->address(data, addr, 1);
14587 frame = frame->next_frame;
14588 ret_addr = &frame->return_address;
14589- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14590+ print_ftrace_graph_addr(addr, data, ops, task, graph);
14591 }
14592
14593 return (unsigned long)frame;
14594@@ -189,7 +188,7 @@ void dump_stack(void)
14595
14596 bp = stack_frame(current, NULL);
14597 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14598- current->pid, current->comm, print_tainted(),
14599+ task_pid_nr(current), current->comm, print_tainted(),
14600 init_utsname()->release,
14601 (int)strcspn(init_utsname()->version, " "),
14602 init_utsname()->version);
14603@@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
14604 }
14605 EXPORT_SYMBOL_GPL(oops_begin);
14606
14607+extern void gr_handle_kernel_exploit(void);
14608+
14609 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14610 {
14611 if (regs && kexec_should_crash(current))
14612@@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14613 panic("Fatal exception in interrupt");
14614 if (panic_on_oops)
14615 panic("Fatal exception");
14616- do_exit(signr);
14617+
14618+ gr_handle_kernel_exploit();
14619+
14620+ do_group_exit(signr);
14621 }
14622
14623 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14624@@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14625
14626 show_regs(regs);
14627 #ifdef CONFIG_X86_32
14628- if (user_mode_vm(regs)) {
14629+ if (user_mode(regs)) {
14630 sp = regs->sp;
14631 ss = regs->ss & 0xffff;
14632 } else {
14633@@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14634 unsigned long flags = oops_begin();
14635 int sig = SIGSEGV;
14636
14637- if (!user_mode_vm(regs))
14638+ if (!user_mode(regs))
14639 report_bug(regs->ip, regs);
14640
14641 if (__die(str, regs, err))
14642diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14643index e0b1d78..a8ade5e 100644
14644--- a/arch/x86/kernel/dumpstack_32.c
14645+++ b/arch/x86/kernel/dumpstack_32.c
14646@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14647 bp = stack_frame(task, regs);
14648
14649 for (;;) {
14650- struct thread_info *context;
14651+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14652
14653- context = (struct thread_info *)
14654- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14655- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14656+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14657
14658- stack = (unsigned long *)context->previous_esp;
14659- if (!stack)
14660+ if (stack_start == task_stack_page(task))
14661 break;
14662+ stack = *(unsigned long **)stack_start;
14663 if (ops->stack(data, "IRQ") < 0)
14664 break;
14665 touch_nmi_watchdog();
14666@@ -87,7 +85,7 @@ void show_regs(struct pt_regs *regs)
14667 int i;
14668
14669 print_modules();
14670- __show_regs(regs, !user_mode_vm(regs));
14671+ __show_regs(regs, !user_mode(regs));
14672
14673 printk(KERN_EMERG "Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
14674 TASK_COMM_LEN, current->comm, task_pid_nr(current),
14675@@ -96,21 +94,22 @@ void show_regs(struct pt_regs *regs)
14676 * When in-kernel, we also print out the stack and code at the
14677 * time of the fault..
14678 */
14679- if (!user_mode_vm(regs)) {
14680+ if (!user_mode(regs)) {
14681 unsigned int code_prologue = code_bytes * 43 / 64;
14682 unsigned int code_len = code_bytes;
14683 unsigned char c;
14684 u8 *ip;
14685+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14686
14687 printk(KERN_EMERG "Stack:\n");
14688 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14689
14690 printk(KERN_EMERG "Code: ");
14691
14692- ip = (u8 *)regs->ip - code_prologue;
14693+ ip = (u8 *)regs->ip - code_prologue + cs_base;
14694 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14695 /* try starting at IP */
14696- ip = (u8 *)regs->ip;
14697+ ip = (u8 *)regs->ip + cs_base;
14698 code_len = code_len - code_prologue + 1;
14699 }
14700 for (i = 0; i < code_len; i++, ip++) {
14701@@ -119,7 +118,7 @@ void show_regs(struct pt_regs *regs)
14702 printk(KERN_CONT " Bad EIP value.");
14703 break;
14704 }
14705- if (ip == (u8 *)regs->ip)
14706+ if (ip == (u8 *)regs->ip + cs_base)
14707 printk(KERN_CONT "<%02x> ", c);
14708 else
14709 printk(KERN_CONT "%02x ", c);
14710@@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
14711 {
14712 unsigned short ud2;
14713
14714+ ip = ktla_ktva(ip);
14715 if (ip < PAGE_OFFSET)
14716 return 0;
14717 if (probe_kernel_address((unsigned short *)ip, ud2))
14718@@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
14719
14720 return ud2 == 0x0b0f;
14721 }
14722+
14723+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14724+void pax_check_alloca(unsigned long size)
14725+{
14726+ unsigned long sp = (unsigned long)&sp, stack_left;
14727+
14728+ /* all kernel stacks are of the same size */
14729+ stack_left = sp & (THREAD_SIZE - 1);
14730+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14731+}
14732+EXPORT_SYMBOL(pax_check_alloca);
14733+#endif
14734diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14735index 791b761..2ab6e33 100644
14736--- a/arch/x86/kernel/dumpstack_64.c
14737+++ b/arch/x86/kernel/dumpstack_64.c
14738@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14739 unsigned long *irq_stack_end =
14740 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14741 unsigned used = 0;
14742- struct thread_info *tinfo;
14743 int graph = 0;
14744 unsigned long dummy;
14745+ void *stack_start;
14746
14747 if (!task)
14748 task = current;
14749@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14750 * current stack address. If the stacks consist of nested
14751 * exceptions
14752 */
14753- tinfo = task_thread_info(task);
14754 for (;;) {
14755 char *id;
14756 unsigned long *estack_end;
14757+
14758 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14759 &used, &id);
14760
14761@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14762 if (ops->stack(data, id) < 0)
14763 break;
14764
14765- bp = ops->walk_stack(tinfo, stack, bp, ops,
14766+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14767 data, estack_end, &graph);
14768 ops->stack(data, "<EOE>");
14769 /*
14770@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14771 * second-to-last pointer (index -2 to end) in the
14772 * exception stack:
14773 */
14774+ if ((u16)estack_end[-1] != __KERNEL_DS)
14775+ goto out;
14776 stack = (unsigned long *) estack_end[-2];
14777 continue;
14778 }
14779@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14780 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14781 if (ops->stack(data, "IRQ") < 0)
14782 break;
14783- bp = ops->walk_stack(tinfo, stack, bp,
14784+ bp = ops->walk_stack(task, irq_stack, stack, bp,
14785 ops, data, irq_stack_end, &graph);
14786 /*
14787 * We link to the next stack (which would be
14788@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14789 /*
14790 * This handles the process stack:
14791 */
14792- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14793+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14794+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14795+out:
14796 put_cpu();
14797 }
14798 EXPORT_SYMBOL(dump_trace);
14799@@ -305,3 +309,50 @@ int is_valid_bugaddr(unsigned long ip)
14800
14801 return ud2 == 0x0b0f;
14802 }
14803+
14804+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14805+void pax_check_alloca(unsigned long size)
14806+{
14807+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14808+ unsigned cpu, used;
14809+ char *id;
14810+
14811+ /* check the process stack first */
14812+ stack_start = (unsigned long)task_stack_page(current);
14813+ stack_end = stack_start + THREAD_SIZE;
14814+ if (likely(stack_start <= sp && sp < stack_end)) {
14815+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
14816+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14817+ return;
14818+ }
14819+
14820+ cpu = get_cpu();
14821+
14822+ /* check the irq stacks */
14823+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14824+ stack_start = stack_end - IRQ_STACK_SIZE;
14825+ if (stack_start <= sp && sp < stack_end) {
14826+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14827+ put_cpu();
14828+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14829+ return;
14830+ }
14831+
14832+ /* check the exception stacks */
14833+ used = 0;
14834+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14835+ stack_start = stack_end - EXCEPTION_STKSZ;
14836+ if (stack_end && stack_start <= sp && sp < stack_end) {
14837+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14838+ put_cpu();
14839+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
14840+ return;
14841+ }
14842+
14843+ put_cpu();
14844+
14845+ /* unknown stack */
14846+ BUG();
14847+}
14848+EXPORT_SYMBOL(pax_check_alloca);
14849+#endif
14850diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14851index 9b9f18b..9fcaa04 100644
14852--- a/arch/x86/kernel/early_printk.c
14853+++ b/arch/x86/kernel/early_printk.c
14854@@ -7,6 +7,7 @@
14855 #include <linux/pci_regs.h>
14856 #include <linux/pci_ids.h>
14857 #include <linux/errno.h>
14858+#include <linux/sched.h>
14859 #include <asm/io.h>
14860 #include <asm/processor.h>
14861 #include <asm/fcntl.h>
14862diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14863index 623f288..8bdd78a 100644
14864--- a/arch/x86/kernel/entry_32.S
14865+++ b/arch/x86/kernel/entry_32.S
14866@@ -176,13 +176,153 @@
14867 /*CFI_REL_OFFSET gs, PT_GS*/
14868 .endm
14869 .macro SET_KERNEL_GS reg
14870+
14871+#ifdef CONFIG_CC_STACKPROTECTOR
14872 movl $(__KERNEL_STACK_CANARY), \reg
14873+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14874+ movl $(__USER_DS), \reg
14875+#else
14876+ xorl \reg, \reg
14877+#endif
14878+
14879 movl \reg, %gs
14880 .endm
14881
14882 #endif /* CONFIG_X86_32_LAZY_GS */
14883
14884-.macro SAVE_ALL
14885+.macro pax_enter_kernel
14886+#ifdef CONFIG_PAX_KERNEXEC
14887+ call pax_enter_kernel
14888+#endif
14889+.endm
14890+
14891+.macro pax_exit_kernel
14892+#ifdef CONFIG_PAX_KERNEXEC
14893+ call pax_exit_kernel
14894+#endif
14895+.endm
14896+
14897+#ifdef CONFIG_PAX_KERNEXEC
14898+ENTRY(pax_enter_kernel)
14899+#ifdef CONFIG_PARAVIRT
14900+ pushl %eax
14901+ pushl %ecx
14902+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
14903+ mov %eax, %esi
14904+#else
14905+ mov %cr0, %esi
14906+#endif
14907+ bts $16, %esi
14908+ jnc 1f
14909+ mov %cs, %esi
14910+ cmp $__KERNEL_CS, %esi
14911+ jz 3f
14912+ ljmp $__KERNEL_CS, $3f
14913+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
14914+2:
14915+#ifdef CONFIG_PARAVIRT
14916+ mov %esi, %eax
14917+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14918+#else
14919+ mov %esi, %cr0
14920+#endif
14921+3:
14922+#ifdef CONFIG_PARAVIRT
14923+ popl %ecx
14924+ popl %eax
14925+#endif
14926+ ret
14927+ENDPROC(pax_enter_kernel)
14928+
14929+ENTRY(pax_exit_kernel)
14930+#ifdef CONFIG_PARAVIRT
14931+ pushl %eax
14932+ pushl %ecx
14933+#endif
14934+ mov %cs, %esi
14935+ cmp $__KERNEXEC_KERNEL_CS, %esi
14936+ jnz 2f
14937+#ifdef CONFIG_PARAVIRT
14938+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
14939+ mov %eax, %esi
14940+#else
14941+ mov %cr0, %esi
14942+#endif
14943+ btr $16, %esi
14944+ ljmp $__KERNEL_CS, $1f
14945+1:
14946+#ifdef CONFIG_PARAVIRT
14947+ mov %esi, %eax
14948+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
14949+#else
14950+ mov %esi, %cr0
14951+#endif
14952+2:
14953+#ifdef CONFIG_PARAVIRT
14954+ popl %ecx
14955+ popl %eax
14956+#endif
14957+ ret
14958+ENDPROC(pax_exit_kernel)
14959+#endif
14960+
14961+.macro pax_erase_kstack
14962+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14963+ call pax_erase_kstack
14964+#endif
14965+.endm
14966+
14967+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14968+/*
14969+ * ebp: thread_info
14970+ */
14971+ENTRY(pax_erase_kstack)
14972+ pushl %edi
14973+ pushl %ecx
14974+ pushl %eax
14975+
14976+ mov TI_lowest_stack(%ebp), %edi
14977+ mov $-0xBEEF, %eax
14978+ std
14979+
14980+1: mov %edi, %ecx
14981+ and $THREAD_SIZE_asm - 1, %ecx
14982+ shr $2, %ecx
14983+ repne scasl
14984+ jecxz 2f
14985+
14986+ cmp $2*16, %ecx
14987+ jc 2f
14988+
14989+ mov $2*16, %ecx
14990+ repe scasl
14991+ jecxz 2f
14992+ jne 1b
14993+
14994+2: cld
14995+ mov %esp, %ecx
14996+ sub %edi, %ecx
14997+
14998+ cmp $THREAD_SIZE_asm, %ecx
14999+ jb 3f
15000+ ud2
15001+3:
15002+
15003+ shr $2, %ecx
15004+ rep stosl
15005+
15006+ mov TI_task_thread_sp0(%ebp), %edi
15007+ sub $128, %edi
15008+ mov %edi, TI_lowest_stack(%ebp)
15009+
15010+ popl %eax
15011+ popl %ecx
15012+ popl %edi
15013+ ret
15014+ENDPROC(pax_erase_kstack)
15015+#endif
15016+
15017+.macro __SAVE_ALL _DS
15018 cld
15019 PUSH_GS
15020 pushl_cfi %fs
15021@@ -205,7 +345,7 @@
15022 CFI_REL_OFFSET ecx, 0
15023 pushl_cfi %ebx
15024 CFI_REL_OFFSET ebx, 0
15025- movl $(__USER_DS), %edx
15026+ movl $\_DS, %edx
15027 movl %edx, %ds
15028 movl %edx, %es
15029 movl $(__KERNEL_PERCPU), %edx
15030@@ -213,6 +353,15 @@
15031 SET_KERNEL_GS %edx
15032 .endm
15033
15034+.macro SAVE_ALL
15035+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
15036+ __SAVE_ALL __KERNEL_DS
15037+ pax_enter_kernel
15038+#else
15039+ __SAVE_ALL __USER_DS
15040+#endif
15041+.endm
15042+
15043 .macro RESTORE_INT_REGS
15044 popl_cfi %ebx
15045 CFI_RESTORE ebx
15046@@ -296,7 +445,7 @@ ENTRY(ret_from_fork)
15047 popfl_cfi
15048 jmp syscall_exit
15049 CFI_ENDPROC
15050-END(ret_from_fork)
15051+ENDPROC(ret_from_fork)
15052
15053 /*
15054 * Interrupt exit functions should be protected against kprobes
15055@@ -329,7 +478,15 @@ ret_from_intr:
15056 andl $SEGMENT_RPL_MASK, %eax
15057 #endif
15058 cmpl $USER_RPL, %eax
15059+
15060+#ifdef CONFIG_PAX_KERNEXEC
15061+ jae resume_userspace
15062+
15063+ pax_exit_kernel
15064+ jmp resume_kernel
15065+#else
15066 jb resume_kernel # not returning to v8086 or userspace
15067+#endif
15068
15069 ENTRY(resume_userspace)
15070 LOCKDEP_SYS_EXIT
15071@@ -341,8 +498,8 @@ ENTRY(resume_userspace)
15072 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15073 # int/exception return?
15074 jne work_pending
15075- jmp restore_all
15076-END(ret_from_exception)
15077+ jmp restore_all_pax
15078+ENDPROC(ret_from_exception)
15079
15080 #ifdef CONFIG_PREEMPT
15081 ENTRY(resume_kernel)
15082@@ -357,7 +514,7 @@ need_resched:
15083 jz restore_all
15084 call preempt_schedule_irq
15085 jmp need_resched
15086-END(resume_kernel)
15087+ENDPROC(resume_kernel)
15088 #endif
15089 CFI_ENDPROC
15090 /*
15091@@ -391,28 +548,43 @@ sysenter_past_esp:
15092 /*CFI_REL_OFFSET cs, 0*/
15093 /*
15094 * Push current_thread_info()->sysenter_return to the stack.
15095- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15096- * pushed above; +8 corresponds to copy_thread's esp0 setting.
15097 */
15098- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15099+ pushl_cfi $0
15100 CFI_REL_OFFSET eip, 0
15101
15102 pushl_cfi %eax
15103 SAVE_ALL
15104+ GET_THREAD_INFO(%ebp)
15105+ movl TI_sysenter_return(%ebp),%ebp
15106+ movl %ebp,PT_EIP(%esp)
15107 ENABLE_INTERRUPTS(CLBR_NONE)
15108
15109 /*
15110 * Load the potential sixth argument from user stack.
15111 * Careful about security.
15112 */
15113+ movl PT_OLDESP(%esp),%ebp
15114+
15115+#ifdef CONFIG_PAX_MEMORY_UDEREF
15116+ mov PT_OLDSS(%esp),%ds
15117+1: movl %ds:(%ebp),%ebp
15118+ push %ss
15119+ pop %ds
15120+#else
15121 cmpl $__PAGE_OFFSET-3,%ebp
15122 jae syscall_fault
15123 1: movl (%ebp),%ebp
15124+#endif
15125+
15126 movl %ebp,PT_EBP(%esp)
15127 _ASM_EXTABLE(1b,syscall_fault)
15128
15129 GET_THREAD_INFO(%ebp)
15130
15131+#ifdef CONFIG_PAX_RANDKSTACK
15132+ pax_erase_kstack
15133+#endif
15134+
15135 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15136 jnz sysenter_audit
15137 sysenter_do_call:
15138@@ -427,12 +599,24 @@ sysenter_do_call:
15139 testl $_TIF_ALLWORK_MASK, %ecx
15140 jne sysexit_audit
15141 sysenter_exit:
15142+
15143+#ifdef CONFIG_PAX_RANDKSTACK
15144+ pushl_cfi %eax
15145+ movl %esp, %eax
15146+ call pax_randomize_kstack
15147+ popl_cfi %eax
15148+#endif
15149+
15150+ pax_erase_kstack
15151+
15152 /* if something modifies registers it must also disable sysexit */
15153 movl PT_EIP(%esp), %edx
15154 movl PT_OLDESP(%esp), %ecx
15155 xorl %ebp,%ebp
15156 TRACE_IRQS_ON
15157 1: mov PT_FS(%esp), %fs
15158+2: mov PT_DS(%esp), %ds
15159+3: mov PT_ES(%esp), %es
15160 PTGS_TO_GS
15161 ENABLE_INTERRUPTS_SYSEXIT
15162
15163@@ -449,6 +633,9 @@ sysenter_audit:
15164 movl %eax,%edx /* 2nd arg: syscall number */
15165 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15166 call __audit_syscall_entry
15167+
15168+ pax_erase_kstack
15169+
15170 pushl_cfi %ebx
15171 movl PT_EAX(%esp),%eax /* reload syscall number */
15172 jmp sysenter_do_call
15173@@ -474,10 +661,16 @@ sysexit_audit:
15174
15175 CFI_ENDPROC
15176 .pushsection .fixup,"ax"
15177-2: movl $0,PT_FS(%esp)
15178+4: movl $0,PT_FS(%esp)
15179+ jmp 1b
15180+5: movl $0,PT_DS(%esp)
15181+ jmp 1b
15182+6: movl $0,PT_ES(%esp)
15183 jmp 1b
15184 .popsection
15185- _ASM_EXTABLE(1b,2b)
15186+ _ASM_EXTABLE(1b,4b)
15187+ _ASM_EXTABLE(2b,5b)
15188+ _ASM_EXTABLE(3b,6b)
15189 PTGS_TO_GS_EX
15190 ENDPROC(ia32_sysenter_target)
15191
15192@@ -491,6 +684,11 @@ ENTRY(system_call)
15193 pushl_cfi %eax # save orig_eax
15194 SAVE_ALL
15195 GET_THREAD_INFO(%ebp)
15196+
15197+#ifdef CONFIG_PAX_RANDKSTACK
15198+ pax_erase_kstack
15199+#endif
15200+
15201 # system call tracing in operation / emulation
15202 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15203 jnz syscall_trace_entry
15204@@ -509,6 +707,15 @@ syscall_exit:
15205 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15206 jne syscall_exit_work
15207
15208+restore_all_pax:
15209+
15210+#ifdef CONFIG_PAX_RANDKSTACK
15211+ movl %esp, %eax
15212+ call pax_randomize_kstack
15213+#endif
15214+
15215+ pax_erase_kstack
15216+
15217 restore_all:
15218 TRACE_IRQS_IRET
15219 restore_all_notrace:
15220@@ -565,14 +772,34 @@ ldt_ss:
15221 * compensating for the offset by changing to the ESPFIX segment with
15222 * a base address that matches for the difference.
15223 */
15224-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15225+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15226 mov %esp, %edx /* load kernel esp */
15227 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15228 mov %dx, %ax /* eax: new kernel esp */
15229 sub %eax, %edx /* offset (low word is 0) */
15230+#ifdef CONFIG_SMP
15231+ movl PER_CPU_VAR(cpu_number), %ebx
15232+ shll $PAGE_SHIFT_asm, %ebx
15233+ addl $cpu_gdt_table, %ebx
15234+#else
15235+ movl $cpu_gdt_table, %ebx
15236+#endif
15237 shr $16, %edx
15238- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15239- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15240+
15241+#ifdef CONFIG_PAX_KERNEXEC
15242+ mov %cr0, %esi
15243+ btr $16, %esi
15244+ mov %esi, %cr0
15245+#endif
15246+
15247+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15248+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15249+
15250+#ifdef CONFIG_PAX_KERNEXEC
15251+ bts $16, %esi
15252+ mov %esi, %cr0
15253+#endif
15254+
15255 pushl_cfi $__ESPFIX_SS
15256 pushl_cfi %eax /* new kernel esp */
15257 /* Disable interrupts, but do not irqtrace this section: we
15258@@ -601,35 +828,23 @@ work_resched:
15259 movl TI_flags(%ebp), %ecx
15260 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15261 # than syscall tracing?
15262- jz restore_all
15263+ jz restore_all_pax
15264 testb $_TIF_NEED_RESCHED, %cl
15265 jnz work_resched
15266
15267 work_notifysig: # deal with pending signals and
15268 # notify-resume requests
15269+ movl %esp, %eax
15270 #ifdef CONFIG_VM86
15271 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15272- movl %esp, %eax
15273- jne work_notifysig_v86 # returning to kernel-space or
15274+ jz 1f # returning to kernel-space or
15275 # vm86-space
15276- TRACE_IRQS_ON
15277- ENABLE_INTERRUPTS(CLBR_NONE)
15278- movb PT_CS(%esp), %bl
15279- andb $SEGMENT_RPL_MASK, %bl
15280- cmpb $USER_RPL, %bl
15281- jb resume_kernel
15282- xorl %edx, %edx
15283- call do_notify_resume
15284- jmp resume_userspace
15285
15286- ALIGN
15287-work_notifysig_v86:
15288 pushl_cfi %ecx # save ti_flags for do_notify_resume
15289 call save_v86_state # %eax contains pt_regs pointer
15290 popl_cfi %ecx
15291 movl %eax, %esp
15292-#else
15293- movl %esp, %eax
15294+1:
15295 #endif
15296 TRACE_IRQS_ON
15297 ENABLE_INTERRUPTS(CLBR_NONE)
15298@@ -640,7 +855,7 @@ work_notifysig_v86:
15299 xorl %edx, %edx
15300 call do_notify_resume
15301 jmp resume_userspace
15302-END(work_pending)
15303+ENDPROC(work_pending)
15304
15305 # perform syscall exit tracing
15306 ALIGN
15307@@ -648,11 +863,14 @@ syscall_trace_entry:
15308 movl $-ENOSYS,PT_EAX(%esp)
15309 movl %esp, %eax
15310 call syscall_trace_enter
15311+
15312+ pax_erase_kstack
15313+
15314 /* What it returned is what we'll actually use. */
15315 cmpl $(NR_syscalls), %eax
15316 jnae syscall_call
15317 jmp syscall_exit
15318-END(syscall_trace_entry)
15319+ENDPROC(syscall_trace_entry)
15320
15321 # perform syscall exit tracing
15322 ALIGN
15323@@ -665,20 +883,24 @@ syscall_exit_work:
15324 movl %esp, %eax
15325 call syscall_trace_leave
15326 jmp resume_userspace
15327-END(syscall_exit_work)
15328+ENDPROC(syscall_exit_work)
15329 CFI_ENDPROC
15330
15331 RING0_INT_FRAME # can't unwind into user space anyway
15332 syscall_fault:
15333+#ifdef CONFIG_PAX_MEMORY_UDEREF
15334+ push %ss
15335+ pop %ds
15336+#endif
15337 GET_THREAD_INFO(%ebp)
15338 movl $-EFAULT,PT_EAX(%esp)
15339 jmp resume_userspace
15340-END(syscall_fault)
15341+ENDPROC(syscall_fault)
15342
15343 syscall_badsys:
15344 movl $-ENOSYS,PT_EAX(%esp)
15345 jmp resume_userspace
15346-END(syscall_badsys)
15347+ENDPROC(syscall_badsys)
15348 CFI_ENDPROC
15349 /*
15350 * End of kprobes section
15351@@ -750,6 +972,36 @@ ENTRY(ptregs_clone)
15352 CFI_ENDPROC
15353 ENDPROC(ptregs_clone)
15354
15355+ ALIGN;
15356+ENTRY(kernel_execve)
15357+ CFI_STARTPROC
15358+ pushl_cfi %ebp
15359+ sub $PT_OLDSS+4,%esp
15360+ pushl_cfi %edi
15361+ pushl_cfi %ecx
15362+ pushl_cfi %eax
15363+ lea 3*4(%esp),%edi
15364+ mov $PT_OLDSS/4+1,%ecx
15365+ xorl %eax,%eax
15366+ rep stosl
15367+ popl_cfi %eax
15368+ popl_cfi %ecx
15369+ popl_cfi %edi
15370+ movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15371+ pushl_cfi %esp
15372+ call sys_execve
15373+ add $4,%esp
15374+ CFI_ADJUST_CFA_OFFSET -4
15375+ GET_THREAD_INFO(%ebp)
15376+ test %eax,%eax
15377+ jz syscall_exit
15378+ add $PT_OLDSS+4,%esp
15379+ CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15380+ popl_cfi %ebp
15381+ ret
15382+ CFI_ENDPROC
15383+ENDPROC(kernel_execve)
15384+
15385 .macro FIXUP_ESPFIX_STACK
15386 /*
15387 * Switch back for ESPFIX stack to the normal zerobased stack
15388@@ -759,8 +1011,15 @@ ENDPROC(ptregs_clone)
15389 * normal stack and adjusts ESP with the matching offset.
15390 */
15391 /* fixup the stack */
15392- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15393- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15394+#ifdef CONFIG_SMP
15395+ movl PER_CPU_VAR(cpu_number), %ebx
15396+ shll $PAGE_SHIFT_asm, %ebx
15397+ addl $cpu_gdt_table, %ebx
15398+#else
15399+ movl $cpu_gdt_table, %ebx
15400+#endif
15401+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15402+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15403 shl $16, %eax
15404 addl %esp, %eax /* the adjusted stack pointer */
15405 pushl_cfi $__KERNEL_DS
15406@@ -813,7 +1072,7 @@ vector=vector+1
15407 .endr
15408 2: jmp common_interrupt
15409 .endr
15410-END(irq_entries_start)
15411+ENDPROC(irq_entries_start)
15412
15413 .previous
15414 END(interrupt)
15415@@ -861,7 +1120,7 @@ ENTRY(coprocessor_error)
15416 pushl_cfi $do_coprocessor_error
15417 jmp error_code
15418 CFI_ENDPROC
15419-END(coprocessor_error)
15420+ENDPROC(coprocessor_error)
15421
15422 ENTRY(simd_coprocessor_error)
15423 RING0_INT_FRAME
15424@@ -882,7 +1141,7 @@ ENTRY(simd_coprocessor_error)
15425 #endif
15426 jmp error_code
15427 CFI_ENDPROC
15428-END(simd_coprocessor_error)
15429+ENDPROC(simd_coprocessor_error)
15430
15431 ENTRY(device_not_available)
15432 RING0_INT_FRAME
15433@@ -890,18 +1149,18 @@ ENTRY(device_not_available)
15434 pushl_cfi $do_device_not_available
15435 jmp error_code
15436 CFI_ENDPROC
15437-END(device_not_available)
15438+ENDPROC(device_not_available)
15439
15440 #ifdef CONFIG_PARAVIRT
15441 ENTRY(native_iret)
15442 iret
15443 _ASM_EXTABLE(native_iret, iret_exc)
15444-END(native_iret)
15445+ENDPROC(native_iret)
15446
15447 ENTRY(native_irq_enable_sysexit)
15448 sti
15449 sysexit
15450-END(native_irq_enable_sysexit)
15451+ENDPROC(native_irq_enable_sysexit)
15452 #endif
15453
15454 ENTRY(overflow)
15455@@ -910,7 +1169,7 @@ ENTRY(overflow)
15456 pushl_cfi $do_overflow
15457 jmp error_code
15458 CFI_ENDPROC
15459-END(overflow)
15460+ENDPROC(overflow)
15461
15462 ENTRY(bounds)
15463 RING0_INT_FRAME
15464@@ -918,7 +1177,7 @@ ENTRY(bounds)
15465 pushl_cfi $do_bounds
15466 jmp error_code
15467 CFI_ENDPROC
15468-END(bounds)
15469+ENDPROC(bounds)
15470
15471 ENTRY(invalid_op)
15472 RING0_INT_FRAME
15473@@ -926,7 +1185,7 @@ ENTRY(invalid_op)
15474 pushl_cfi $do_invalid_op
15475 jmp error_code
15476 CFI_ENDPROC
15477-END(invalid_op)
15478+ENDPROC(invalid_op)
15479
15480 ENTRY(coprocessor_segment_overrun)
15481 RING0_INT_FRAME
15482@@ -934,35 +1193,35 @@ ENTRY(coprocessor_segment_overrun)
15483 pushl_cfi $do_coprocessor_segment_overrun
15484 jmp error_code
15485 CFI_ENDPROC
15486-END(coprocessor_segment_overrun)
15487+ENDPROC(coprocessor_segment_overrun)
15488
15489 ENTRY(invalid_TSS)
15490 RING0_EC_FRAME
15491 pushl_cfi $do_invalid_TSS
15492 jmp error_code
15493 CFI_ENDPROC
15494-END(invalid_TSS)
15495+ENDPROC(invalid_TSS)
15496
15497 ENTRY(segment_not_present)
15498 RING0_EC_FRAME
15499 pushl_cfi $do_segment_not_present
15500 jmp error_code
15501 CFI_ENDPROC
15502-END(segment_not_present)
15503+ENDPROC(segment_not_present)
15504
15505 ENTRY(stack_segment)
15506 RING0_EC_FRAME
15507 pushl_cfi $do_stack_segment
15508 jmp error_code
15509 CFI_ENDPROC
15510-END(stack_segment)
15511+ENDPROC(stack_segment)
15512
15513 ENTRY(alignment_check)
15514 RING0_EC_FRAME
15515 pushl_cfi $do_alignment_check
15516 jmp error_code
15517 CFI_ENDPROC
15518-END(alignment_check)
15519+ENDPROC(alignment_check)
15520
15521 ENTRY(divide_error)
15522 RING0_INT_FRAME
15523@@ -970,7 +1229,7 @@ ENTRY(divide_error)
15524 pushl_cfi $do_divide_error
15525 jmp error_code
15526 CFI_ENDPROC
15527-END(divide_error)
15528+ENDPROC(divide_error)
15529
15530 #ifdef CONFIG_X86_MCE
15531 ENTRY(machine_check)
15532@@ -979,7 +1238,7 @@ ENTRY(machine_check)
15533 pushl_cfi machine_check_vector
15534 jmp error_code
15535 CFI_ENDPROC
15536-END(machine_check)
15537+ENDPROC(machine_check)
15538 #endif
15539
15540 ENTRY(spurious_interrupt_bug)
15541@@ -988,7 +1247,7 @@ ENTRY(spurious_interrupt_bug)
15542 pushl_cfi $do_spurious_interrupt_bug
15543 jmp error_code
15544 CFI_ENDPROC
15545-END(spurious_interrupt_bug)
15546+ENDPROC(spurious_interrupt_bug)
15547 /*
15548 * End of kprobes section
15549 */
15550@@ -1100,7 +1359,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15551
15552 ENTRY(mcount)
15553 ret
15554-END(mcount)
15555+ENDPROC(mcount)
15556
15557 ENTRY(ftrace_caller)
15558 cmpl $0, function_trace_stop
15559@@ -1129,7 +1388,7 @@ ftrace_graph_call:
15560 .globl ftrace_stub
15561 ftrace_stub:
15562 ret
15563-END(ftrace_caller)
15564+ENDPROC(ftrace_caller)
15565
15566 #else /* ! CONFIG_DYNAMIC_FTRACE */
15567
15568@@ -1165,7 +1424,7 @@ trace:
15569 popl %ecx
15570 popl %eax
15571 jmp ftrace_stub
15572-END(mcount)
15573+ENDPROC(mcount)
15574 #endif /* CONFIG_DYNAMIC_FTRACE */
15575 #endif /* CONFIG_FUNCTION_TRACER */
15576
15577@@ -1186,7 +1445,7 @@ ENTRY(ftrace_graph_caller)
15578 popl %ecx
15579 popl %eax
15580 ret
15581-END(ftrace_graph_caller)
15582+ENDPROC(ftrace_graph_caller)
15583
15584 .globl return_to_handler
15585 return_to_handler:
15586@@ -1241,15 +1500,18 @@ error_code:
15587 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15588 REG_TO_PTGS %ecx
15589 SET_KERNEL_GS %ecx
15590- movl $(__USER_DS), %ecx
15591+ movl $(__KERNEL_DS), %ecx
15592 movl %ecx, %ds
15593 movl %ecx, %es
15594+
15595+ pax_enter_kernel
15596+
15597 TRACE_IRQS_OFF
15598 movl %esp,%eax # pt_regs pointer
15599 call *%edi
15600 jmp ret_from_exception
15601 CFI_ENDPROC
15602-END(page_fault)
15603+ENDPROC(page_fault)
15604
15605 /*
15606 * Debug traps and NMI can happen at the one SYSENTER instruction
15607@@ -1291,7 +1553,7 @@ debug_stack_correct:
15608 call do_debug
15609 jmp ret_from_exception
15610 CFI_ENDPROC
15611-END(debug)
15612+ENDPROC(debug)
15613
15614 /*
15615 * NMI is doubly nasty. It can happen _while_ we're handling
15616@@ -1328,6 +1590,9 @@ nmi_stack_correct:
15617 xorl %edx,%edx # zero error code
15618 movl %esp,%eax # pt_regs pointer
15619 call do_nmi
15620+
15621+ pax_exit_kernel
15622+
15623 jmp restore_all_notrace
15624 CFI_ENDPROC
15625
15626@@ -1364,12 +1629,15 @@ nmi_espfix_stack:
15627 FIXUP_ESPFIX_STACK # %eax == %esp
15628 xorl %edx,%edx # zero error code
15629 call do_nmi
15630+
15631+ pax_exit_kernel
15632+
15633 RESTORE_REGS
15634 lss 12+4(%esp), %esp # back to espfix stack
15635 CFI_ADJUST_CFA_OFFSET -24
15636 jmp irq_return
15637 CFI_ENDPROC
15638-END(nmi)
15639+ENDPROC(nmi)
15640
15641 ENTRY(int3)
15642 RING0_INT_FRAME
15643@@ -1381,14 +1649,14 @@ ENTRY(int3)
15644 call do_int3
15645 jmp ret_from_exception
15646 CFI_ENDPROC
15647-END(int3)
15648+ENDPROC(int3)
15649
15650 ENTRY(general_protection)
15651 RING0_EC_FRAME
15652 pushl_cfi $do_general_protection
15653 jmp error_code
15654 CFI_ENDPROC
15655-END(general_protection)
15656+ENDPROC(general_protection)
15657
15658 #ifdef CONFIG_KVM_GUEST
15659 ENTRY(async_page_fault)
15660@@ -1396,7 +1664,7 @@ ENTRY(async_page_fault)
15661 pushl_cfi $do_async_page_fault
15662 jmp error_code
15663 CFI_ENDPROC
15664-END(async_page_fault)
15665+ENDPROC(async_page_fault)
15666 #endif
15667
15668 /*
15669diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15670index 7d65133..c888d5f 100644
15671--- a/arch/x86/kernel/entry_64.S
15672+++ b/arch/x86/kernel/entry_64.S
15673@@ -57,6 +57,8 @@
15674 #include <asm/percpu.h>
15675 #include <asm/asm.h>
15676 #include <linux/err.h>
15677+#include <asm/pgtable.h>
15678+#include <asm/alternative-asm.h>
15679
15680 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15681 #include <linux/elf-em.h>
15682@@ -70,8 +72,9 @@
15683 #ifdef CONFIG_FUNCTION_TRACER
15684 #ifdef CONFIG_DYNAMIC_FTRACE
15685 ENTRY(mcount)
15686+ pax_force_retaddr
15687 retq
15688-END(mcount)
15689+ENDPROC(mcount)
15690
15691 ENTRY(ftrace_caller)
15692 cmpl $0, function_trace_stop
15693@@ -94,8 +97,9 @@ GLOBAL(ftrace_graph_call)
15694 #endif
15695
15696 GLOBAL(ftrace_stub)
15697+ pax_force_retaddr
15698 retq
15699-END(ftrace_caller)
15700+ENDPROC(ftrace_caller)
15701
15702 #else /* ! CONFIG_DYNAMIC_FTRACE */
15703 ENTRY(mcount)
15704@@ -114,6 +118,7 @@ ENTRY(mcount)
15705 #endif
15706
15707 GLOBAL(ftrace_stub)
15708+ pax_force_retaddr
15709 retq
15710
15711 trace:
15712@@ -123,12 +128,13 @@ trace:
15713 movq 8(%rbp), %rsi
15714 subq $MCOUNT_INSN_SIZE, %rdi
15715
15716+ pax_force_fptr ftrace_trace_function
15717 call *ftrace_trace_function
15718
15719 MCOUNT_RESTORE_FRAME
15720
15721 jmp ftrace_stub
15722-END(mcount)
15723+ENDPROC(mcount)
15724 #endif /* CONFIG_DYNAMIC_FTRACE */
15725 #endif /* CONFIG_FUNCTION_TRACER */
15726
15727@@ -148,8 +154,9 @@ ENTRY(ftrace_graph_caller)
15728
15729 MCOUNT_RESTORE_FRAME
15730
15731+ pax_force_retaddr
15732 retq
15733-END(ftrace_graph_caller)
15734+ENDPROC(ftrace_graph_caller)
15735
15736 GLOBAL(return_to_handler)
15737 subq $24, %rsp
15738@@ -165,6 +172,7 @@ GLOBAL(return_to_handler)
15739 movq 8(%rsp), %rdx
15740 movq (%rsp), %rax
15741 addq $24, %rsp
15742+ pax_force_fptr %rdi
15743 jmp *%rdi
15744 #endif
15745
15746@@ -180,6 +188,280 @@ ENTRY(native_usergs_sysret64)
15747 ENDPROC(native_usergs_sysret64)
15748 #endif /* CONFIG_PARAVIRT */
15749
15750+ .macro ljmpq sel, off
15751+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15752+ .byte 0x48; ljmp *1234f(%rip)
15753+ .pushsection .rodata
15754+ .align 16
15755+ 1234: .quad \off; .word \sel
15756+ .popsection
15757+#else
15758+ pushq $\sel
15759+ pushq $\off
15760+ lretq
15761+#endif
15762+ .endm
15763+
15764+ .macro pax_enter_kernel
15765+ pax_set_fptr_mask
15766+#ifdef CONFIG_PAX_KERNEXEC
15767+ call pax_enter_kernel
15768+#endif
15769+ .endm
15770+
15771+ .macro pax_exit_kernel
15772+#ifdef CONFIG_PAX_KERNEXEC
15773+ call pax_exit_kernel
15774+#endif
15775+ .endm
15776+
15777+#ifdef CONFIG_PAX_KERNEXEC
15778+ENTRY(pax_enter_kernel)
15779+ pushq %rdi
15780+
15781+#ifdef CONFIG_PARAVIRT
15782+ PV_SAVE_REGS(CLBR_RDI)
15783+#endif
15784+
15785+ GET_CR0_INTO_RDI
15786+ bts $16,%rdi
15787+ jnc 3f
15788+ mov %cs,%edi
15789+ cmp $__KERNEL_CS,%edi
15790+ jnz 2f
15791+1:
15792+
15793+#ifdef CONFIG_PARAVIRT
15794+ PV_RESTORE_REGS(CLBR_RDI)
15795+#endif
15796+
15797+ popq %rdi
15798+ pax_force_retaddr
15799+ retq
15800+
15801+2: ljmpq __KERNEL_CS,1f
15802+3: ljmpq __KERNEXEC_KERNEL_CS,4f
15803+4: SET_RDI_INTO_CR0
15804+ jmp 1b
15805+ENDPROC(pax_enter_kernel)
15806+
15807+ENTRY(pax_exit_kernel)
15808+ pushq %rdi
15809+
15810+#ifdef CONFIG_PARAVIRT
15811+ PV_SAVE_REGS(CLBR_RDI)
15812+#endif
15813+
15814+ mov %cs,%rdi
15815+ cmp $__KERNEXEC_KERNEL_CS,%edi
15816+ jz 2f
15817+1:
15818+
15819+#ifdef CONFIG_PARAVIRT
15820+ PV_RESTORE_REGS(CLBR_RDI);
15821+#endif
15822+
15823+ popq %rdi
15824+ pax_force_retaddr
15825+ retq
15826+
15827+2: GET_CR0_INTO_RDI
15828+ btr $16,%rdi
15829+ ljmpq __KERNEL_CS,3f
15830+3: SET_RDI_INTO_CR0
15831+ jmp 1b
15832+#ifdef CONFIG_PARAVIRT
15833+ PV_RESTORE_REGS(CLBR_RDI);
15834+#endif
15835+
15836+ popq %rdi
15837+ pax_force_retaddr
15838+ retq
15839+ENDPROC(pax_exit_kernel)
15840+#endif
15841+
15842+ .macro pax_enter_kernel_user
15843+ pax_set_fptr_mask
15844+#ifdef CONFIG_PAX_MEMORY_UDEREF
15845+ call pax_enter_kernel_user
15846+#endif
15847+ .endm
15848+
15849+ .macro pax_exit_kernel_user
15850+#ifdef CONFIG_PAX_MEMORY_UDEREF
15851+ call pax_exit_kernel_user
15852+#endif
15853+#ifdef CONFIG_PAX_RANDKSTACK
15854+ pushq %rax
15855+ call pax_randomize_kstack
15856+ popq %rax
15857+#endif
15858+ .endm
15859+
15860+#ifdef CONFIG_PAX_MEMORY_UDEREF
15861+ENTRY(pax_enter_kernel_user)
15862+ pushq %rdi
15863+ pushq %rbx
15864+
15865+#ifdef CONFIG_PARAVIRT
15866+ PV_SAVE_REGS(CLBR_RDI)
15867+#endif
15868+
15869+ GET_CR3_INTO_RDI
15870+ mov %rdi,%rbx
15871+ add $__START_KERNEL_map,%rbx
15872+ sub phys_base(%rip),%rbx
15873+
15874+#ifdef CONFIG_PARAVIRT
15875+ pushq %rdi
15876+ cmpl $0, pv_info+PARAVIRT_enabled
15877+ jz 1f
15878+ i = 0
15879+ .rept USER_PGD_PTRS
15880+ mov i*8(%rbx),%rsi
15881+ mov $0,%sil
15882+ lea i*8(%rbx),%rdi
15883+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15884+ i = i + 1
15885+ .endr
15886+ jmp 2f
15887+1:
15888+#endif
15889+
15890+ i = 0
15891+ .rept USER_PGD_PTRS
15892+ movb $0,i*8(%rbx)
15893+ i = i + 1
15894+ .endr
15895+
15896+#ifdef CONFIG_PARAVIRT
15897+2: popq %rdi
15898+#endif
15899+ SET_RDI_INTO_CR3
15900+
15901+#ifdef CONFIG_PAX_KERNEXEC
15902+ GET_CR0_INTO_RDI
15903+ bts $16,%rdi
15904+ SET_RDI_INTO_CR0
15905+#endif
15906+
15907+#ifdef CONFIG_PARAVIRT
15908+ PV_RESTORE_REGS(CLBR_RDI)
15909+#endif
15910+
15911+ popq %rbx
15912+ popq %rdi
15913+ pax_force_retaddr
15914+ retq
15915+ENDPROC(pax_enter_kernel_user)
15916+
15917+ENTRY(pax_exit_kernel_user)
15918+ push %rdi
15919+
15920+#ifdef CONFIG_PARAVIRT
15921+ pushq %rbx
15922+ PV_SAVE_REGS(CLBR_RDI)
15923+#endif
15924+
15925+#ifdef CONFIG_PAX_KERNEXEC
15926+ GET_CR0_INTO_RDI
15927+ btr $16,%rdi
15928+ SET_RDI_INTO_CR0
15929+#endif
15930+
15931+ GET_CR3_INTO_RDI
15932+ add $__START_KERNEL_map,%rdi
15933+ sub phys_base(%rip),%rdi
15934+
15935+#ifdef CONFIG_PARAVIRT
15936+ cmpl $0, pv_info+PARAVIRT_enabled
15937+ jz 1f
15938+ mov %rdi,%rbx
15939+ i = 0
15940+ .rept USER_PGD_PTRS
15941+ mov i*8(%rbx),%rsi
15942+ mov $0x67,%sil
15943+ lea i*8(%rbx),%rdi
15944+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15945+ i = i + 1
15946+ .endr
15947+ jmp 2f
15948+1:
15949+#endif
15950+
15951+ i = 0
15952+ .rept USER_PGD_PTRS
15953+ movb $0x67,i*8(%rdi)
15954+ i = i + 1
15955+ .endr
15956+
15957+#ifdef CONFIG_PARAVIRT
15958+2: PV_RESTORE_REGS(CLBR_RDI)
15959+ popq %rbx
15960+#endif
15961+
15962+ popq %rdi
15963+ pax_force_retaddr
15964+ retq
15965+ENDPROC(pax_exit_kernel_user)
15966+#endif
15967+
15968+.macro pax_erase_kstack
15969+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15970+ call pax_erase_kstack
15971+#endif
15972+.endm
15973+
15974+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15975+ENTRY(pax_erase_kstack)
15976+ pushq %rdi
15977+ pushq %rcx
15978+ pushq %rax
15979+ pushq %r11
15980+
15981+ GET_THREAD_INFO(%r11)
15982+ mov TI_lowest_stack(%r11), %rdi
15983+ mov $-0xBEEF, %rax
15984+ std
15985+
15986+1: mov %edi, %ecx
15987+ and $THREAD_SIZE_asm - 1, %ecx
15988+ shr $3, %ecx
15989+ repne scasq
15990+ jecxz 2f
15991+
15992+ cmp $2*8, %ecx
15993+ jc 2f
15994+
15995+ mov $2*8, %ecx
15996+ repe scasq
15997+ jecxz 2f
15998+ jne 1b
15999+
16000+2: cld
16001+ mov %esp, %ecx
16002+ sub %edi, %ecx
16003+
16004+ cmp $THREAD_SIZE_asm, %rcx
16005+ jb 3f
16006+ ud2
16007+3:
16008+
16009+ shr $3, %ecx
16010+ rep stosq
16011+
16012+ mov TI_task_thread_sp0(%r11), %rdi
16013+ sub $256, %rdi
16014+ mov %rdi, TI_lowest_stack(%r11)
16015+
16016+ popq %r11
16017+ popq %rax
16018+ popq %rcx
16019+ popq %rdi
16020+ pax_force_retaddr
16021+ ret
16022+ENDPROC(pax_erase_kstack)
16023+#endif
16024
16025 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
16026 #ifdef CONFIG_TRACE_IRQFLAGS
16027@@ -271,8 +553,8 @@ ENDPROC(native_usergs_sysret64)
16028 .endm
16029
16030 .macro UNFAKE_STACK_FRAME
16031- addq $8*6, %rsp
16032- CFI_ADJUST_CFA_OFFSET -(6*8)
16033+ addq $8*6 + ARG_SKIP, %rsp
16034+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
16035 .endm
16036
16037 /*
16038@@ -359,7 +641,7 @@ ENDPROC(native_usergs_sysret64)
16039 movq %rsp, %rsi
16040
16041 leaq -RBP(%rsp),%rdi /* arg1 for handler */
16042- testl $3, CS-RBP(%rsi)
16043+ testb $3, CS-RBP(%rsi)
16044 je 1f
16045 SWAPGS
16046 /*
16047@@ -394,9 +676,10 @@ ENTRY(save_rest)
16048 movq_cfi r15, R15+16
16049 movq %r11, 8(%rsp) /* return address */
16050 FIXUP_TOP_OF_STACK %r11, 16
16051+ pax_force_retaddr
16052 ret
16053 CFI_ENDPROC
16054-END(save_rest)
16055+ENDPROC(save_rest)
16056
16057 /* save complete stack frame */
16058 .pushsection .kprobes.text, "ax"
16059@@ -425,9 +708,10 @@ ENTRY(save_paranoid)
16060 js 1f /* negative -> in kernel */
16061 SWAPGS
16062 xorl %ebx,%ebx
16063-1: ret
16064+1: pax_force_retaddr_bts
16065+ ret
16066 CFI_ENDPROC
16067-END(save_paranoid)
16068+ENDPROC(save_paranoid)
16069 .popsection
16070
16071 /*
16072@@ -449,7 +733,7 @@ ENTRY(ret_from_fork)
16073
16074 RESTORE_REST
16075
16076- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16077+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16078 jz retint_restore_args
16079
16080 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16081@@ -459,7 +743,7 @@ ENTRY(ret_from_fork)
16082 jmp ret_from_sys_call # go to the SYSRET fastpath
16083
16084 CFI_ENDPROC
16085-END(ret_from_fork)
16086+ENDPROC(ret_from_fork)
16087
16088 /*
16089 * System call entry. Up to 6 arguments in registers are supported.
16090@@ -495,7 +779,7 @@ END(ret_from_fork)
16091 ENTRY(system_call)
16092 CFI_STARTPROC simple
16093 CFI_SIGNAL_FRAME
16094- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16095+ CFI_DEF_CFA rsp,0
16096 CFI_REGISTER rip,rcx
16097 /*CFI_REGISTER rflags,r11*/
16098 SWAPGS_UNSAFE_STACK
16099@@ -508,16 +792,23 @@ GLOBAL(system_call_after_swapgs)
16100
16101 movq %rsp,PER_CPU_VAR(old_rsp)
16102 movq PER_CPU_VAR(kernel_stack),%rsp
16103+ SAVE_ARGS 8*6,0
16104+ pax_enter_kernel_user
16105+
16106+#ifdef CONFIG_PAX_RANDKSTACK
16107+ pax_erase_kstack
16108+#endif
16109+
16110 /*
16111 * No need to follow this irqs off/on section - it's straight
16112 * and short:
16113 */
16114 ENABLE_INTERRUPTS(CLBR_NONE)
16115- SAVE_ARGS 8,0
16116 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16117 movq %rcx,RIP-ARGOFFSET(%rsp)
16118 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16119- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16120+ GET_THREAD_INFO(%rcx)
16121+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16122 jnz tracesys
16123 system_call_fastpath:
16124 #if __SYSCALL_MASK == ~0
16125@@ -527,7 +818,7 @@ system_call_fastpath:
16126 cmpl $__NR_syscall_max,%eax
16127 #endif
16128 ja badsys
16129- movq %r10,%rcx
16130+ movq R10-ARGOFFSET(%rsp),%rcx
16131 call *sys_call_table(,%rax,8) # XXX: rip relative
16132 movq %rax,RAX-ARGOFFSET(%rsp)
16133 /*
16134@@ -541,10 +832,13 @@ sysret_check:
16135 LOCKDEP_SYS_EXIT
16136 DISABLE_INTERRUPTS(CLBR_NONE)
16137 TRACE_IRQS_OFF
16138- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16139+ GET_THREAD_INFO(%rcx)
16140+ movl TI_flags(%rcx),%edx
16141 andl %edi,%edx
16142 jnz sysret_careful
16143 CFI_REMEMBER_STATE
16144+ pax_exit_kernel_user
16145+ pax_erase_kstack
16146 /*
16147 * sysretq will re-enable interrupts:
16148 */
16149@@ -596,14 +890,18 @@ badsys:
16150 * jump back to the normal fast path.
16151 */
16152 auditsys:
16153- movq %r10,%r9 /* 6th arg: 4th syscall arg */
16154+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16155 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16156 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16157 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16158 movq %rax,%rsi /* 2nd arg: syscall number */
16159 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16160 call __audit_syscall_entry
16161+
16162+ pax_erase_kstack
16163+
16164 LOAD_ARGS 0 /* reload call-clobbered registers */
16165+ pax_set_fptr_mask
16166 jmp system_call_fastpath
16167
16168 /*
16169@@ -624,7 +922,7 @@ sysret_audit:
16170 /* Do syscall tracing */
16171 tracesys:
16172 #ifdef CONFIG_AUDITSYSCALL
16173- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16174+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16175 jz auditsys
16176 #endif
16177 SAVE_REST
16178@@ -632,12 +930,16 @@ tracesys:
16179 FIXUP_TOP_OF_STACK %rdi
16180 movq %rsp,%rdi
16181 call syscall_trace_enter
16182+
16183+ pax_erase_kstack
16184+
16185 /*
16186 * Reload arg registers from stack in case ptrace changed them.
16187 * We don't reload %rax because syscall_trace_enter() returned
16188 * the value it wants us to use in the table lookup.
16189 */
16190 LOAD_ARGS ARGOFFSET, 1
16191+ pax_set_fptr_mask
16192 RESTORE_REST
16193 #if __SYSCALL_MASK == ~0
16194 cmpq $__NR_syscall_max,%rax
16195@@ -646,7 +948,7 @@ tracesys:
16196 cmpl $__NR_syscall_max,%eax
16197 #endif
16198 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16199- movq %r10,%rcx /* fixup for C */
16200+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16201 call *sys_call_table(,%rax,8)
16202 movq %rax,RAX-ARGOFFSET(%rsp)
16203 /* Use IRET because user could have changed frame */
16204@@ -667,7 +969,9 @@ GLOBAL(int_with_check)
16205 andl %edi,%edx
16206 jnz int_careful
16207 andl $~TS_COMPAT,TI_status(%rcx)
16208- jmp retint_swapgs
16209+ pax_exit_kernel_user
16210+ pax_erase_kstack
16211+ jmp retint_swapgs_pax
16212
16213 /* Either reschedule or signal or syscall exit tracking needed. */
16214 /* First do a reschedule test. */
16215@@ -713,7 +1017,7 @@ int_restore_rest:
16216 TRACE_IRQS_OFF
16217 jmp int_with_check
16218 CFI_ENDPROC
16219-END(system_call)
16220+ENDPROC(system_call)
16221
16222 /*
16223 * Certain special system calls that need to save a complete full stack frame.
16224@@ -729,7 +1033,7 @@ ENTRY(\label)
16225 call \func
16226 jmp ptregscall_common
16227 CFI_ENDPROC
16228-END(\label)
16229+ENDPROC(\label)
16230 .endm
16231
16232 PTREGSCALL stub_clone, sys_clone, %r8
16233@@ -747,9 +1051,10 @@ ENTRY(ptregscall_common)
16234 movq_cfi_restore R12+8, r12
16235 movq_cfi_restore RBP+8, rbp
16236 movq_cfi_restore RBX+8, rbx
16237+ pax_force_retaddr
16238 ret $REST_SKIP /* pop extended registers */
16239 CFI_ENDPROC
16240-END(ptregscall_common)
16241+ENDPROC(ptregscall_common)
16242
16243 ENTRY(stub_execve)
16244 CFI_STARTPROC
16245@@ -764,7 +1069,7 @@ ENTRY(stub_execve)
16246 RESTORE_REST
16247 jmp int_ret_from_sys_call
16248 CFI_ENDPROC
16249-END(stub_execve)
16250+ENDPROC(stub_execve)
16251
16252 /*
16253 * sigreturn is special because it needs to restore all registers on return.
16254@@ -782,7 +1087,7 @@ ENTRY(stub_rt_sigreturn)
16255 RESTORE_REST
16256 jmp int_ret_from_sys_call
16257 CFI_ENDPROC
16258-END(stub_rt_sigreturn)
16259+ENDPROC(stub_rt_sigreturn)
16260
16261 #ifdef CONFIG_X86_X32_ABI
16262 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16263@@ -851,7 +1156,7 @@ vector=vector+1
16264 2: jmp common_interrupt
16265 .endr
16266 CFI_ENDPROC
16267-END(irq_entries_start)
16268+ENDPROC(irq_entries_start)
16269
16270 .previous
16271 END(interrupt)
16272@@ -871,6 +1176,16 @@ END(interrupt)
16273 subq $ORIG_RAX-RBP, %rsp
16274 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16275 SAVE_ARGS_IRQ
16276+#ifdef CONFIG_PAX_MEMORY_UDEREF
16277+ testb $3, CS(%rdi)
16278+ jnz 1f
16279+ pax_enter_kernel
16280+ jmp 2f
16281+1: pax_enter_kernel_user
16282+2:
16283+#else
16284+ pax_enter_kernel
16285+#endif
16286 call \func
16287 .endm
16288
16289@@ -902,7 +1217,7 @@ ret_from_intr:
16290
16291 exit_intr:
16292 GET_THREAD_INFO(%rcx)
16293- testl $3,CS-ARGOFFSET(%rsp)
16294+ testb $3,CS-ARGOFFSET(%rsp)
16295 je retint_kernel
16296
16297 /* Interrupt came from user space */
16298@@ -924,12 +1239,16 @@ retint_swapgs: /* return to user-space */
16299 * The iretq could re-enable interrupts:
16300 */
16301 DISABLE_INTERRUPTS(CLBR_ANY)
16302+ pax_exit_kernel_user
16303+retint_swapgs_pax:
16304 TRACE_IRQS_IRETQ
16305 SWAPGS
16306 jmp restore_args
16307
16308 retint_restore_args: /* return to kernel space */
16309 DISABLE_INTERRUPTS(CLBR_ANY)
16310+ pax_exit_kernel
16311+ pax_force_retaddr RIP-ARGOFFSET
16312 /*
16313 * The iretq could re-enable interrupts:
16314 */
16315@@ -1012,7 +1331,7 @@ ENTRY(retint_kernel)
16316 #endif
16317
16318 CFI_ENDPROC
16319-END(common_interrupt)
16320+ENDPROC(common_interrupt)
16321 /*
16322 * End of kprobes section
16323 */
16324@@ -1029,7 +1348,7 @@ ENTRY(\sym)
16325 interrupt \do_sym
16326 jmp ret_from_intr
16327 CFI_ENDPROC
16328-END(\sym)
16329+ENDPROC(\sym)
16330 .endm
16331
16332 #ifdef CONFIG_SMP
16333@@ -1102,12 +1421,22 @@ ENTRY(\sym)
16334 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16335 call error_entry
16336 DEFAULT_FRAME 0
16337+#ifdef CONFIG_PAX_MEMORY_UDEREF
16338+ testb $3, CS(%rsp)
16339+ jnz 1f
16340+ pax_enter_kernel
16341+ jmp 2f
16342+1: pax_enter_kernel_user
16343+2:
16344+#else
16345+ pax_enter_kernel
16346+#endif
16347 movq %rsp,%rdi /* pt_regs pointer */
16348 xorl %esi,%esi /* no error code */
16349 call \do_sym
16350 jmp error_exit /* %ebx: no swapgs flag */
16351 CFI_ENDPROC
16352-END(\sym)
16353+ENDPROC(\sym)
16354 .endm
16355
16356 .macro paranoidzeroentry sym do_sym
16357@@ -1119,15 +1448,25 @@ ENTRY(\sym)
16358 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16359 call save_paranoid
16360 TRACE_IRQS_OFF
16361+#ifdef CONFIG_PAX_MEMORY_UDEREF
16362+ testb $3, CS(%rsp)
16363+ jnz 1f
16364+ pax_enter_kernel
16365+ jmp 2f
16366+1: pax_enter_kernel_user
16367+2:
16368+#else
16369+ pax_enter_kernel
16370+#endif
16371 movq %rsp,%rdi /* pt_regs pointer */
16372 xorl %esi,%esi /* no error code */
16373 call \do_sym
16374 jmp paranoid_exit /* %ebx: no swapgs flag */
16375 CFI_ENDPROC
16376-END(\sym)
16377+ENDPROC(\sym)
16378 .endm
16379
16380-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16381+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16382 .macro paranoidzeroentry_ist sym do_sym ist
16383 ENTRY(\sym)
16384 INTR_FRAME
16385@@ -1137,14 +1476,30 @@ ENTRY(\sym)
16386 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16387 call save_paranoid
16388 TRACE_IRQS_OFF_DEBUG
16389+#ifdef CONFIG_PAX_MEMORY_UDEREF
16390+ testb $3, CS(%rsp)
16391+ jnz 1f
16392+ pax_enter_kernel
16393+ jmp 2f
16394+1: pax_enter_kernel_user
16395+2:
16396+#else
16397+ pax_enter_kernel
16398+#endif
16399 movq %rsp,%rdi /* pt_regs pointer */
16400 xorl %esi,%esi /* no error code */
16401+#ifdef CONFIG_SMP
16402+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16403+ lea init_tss(%r12), %r12
16404+#else
16405+ lea init_tss(%rip), %r12
16406+#endif
16407 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16408 call \do_sym
16409 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16410 jmp paranoid_exit /* %ebx: no swapgs flag */
16411 CFI_ENDPROC
16412-END(\sym)
16413+ENDPROC(\sym)
16414 .endm
16415
16416 .macro errorentry sym do_sym
16417@@ -1155,13 +1510,23 @@ ENTRY(\sym)
16418 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16419 call error_entry
16420 DEFAULT_FRAME 0
16421+#ifdef CONFIG_PAX_MEMORY_UDEREF
16422+ testb $3, CS(%rsp)
16423+ jnz 1f
16424+ pax_enter_kernel
16425+ jmp 2f
16426+1: pax_enter_kernel_user
16427+2:
16428+#else
16429+ pax_enter_kernel
16430+#endif
16431 movq %rsp,%rdi /* pt_regs pointer */
16432 movq ORIG_RAX(%rsp),%rsi /* get error code */
16433 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16434 call \do_sym
16435 jmp error_exit /* %ebx: no swapgs flag */
16436 CFI_ENDPROC
16437-END(\sym)
16438+ENDPROC(\sym)
16439 .endm
16440
16441 /* error code is on the stack already */
16442@@ -1174,13 +1539,23 @@ ENTRY(\sym)
16443 call save_paranoid
16444 DEFAULT_FRAME 0
16445 TRACE_IRQS_OFF
16446+#ifdef CONFIG_PAX_MEMORY_UDEREF
16447+ testb $3, CS(%rsp)
16448+ jnz 1f
16449+ pax_enter_kernel
16450+ jmp 2f
16451+1: pax_enter_kernel_user
16452+2:
16453+#else
16454+ pax_enter_kernel
16455+#endif
16456 movq %rsp,%rdi /* pt_regs pointer */
16457 movq ORIG_RAX(%rsp),%rsi /* get error code */
16458 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16459 call \do_sym
16460 jmp paranoid_exit /* %ebx: no swapgs flag */
16461 CFI_ENDPROC
16462-END(\sym)
16463+ENDPROC(\sym)
16464 .endm
16465
16466 zeroentry divide_error do_divide_error
16467@@ -1210,9 +1585,10 @@ gs_change:
16468 2: mfence /* workaround */
16469 SWAPGS
16470 popfq_cfi
16471+ pax_force_retaddr
16472 ret
16473 CFI_ENDPROC
16474-END(native_load_gs_index)
16475+ENDPROC(native_load_gs_index)
16476
16477 _ASM_EXTABLE(gs_change,bad_gs)
16478 .section .fixup,"ax"
16479@@ -1231,13 +1607,14 @@ ENTRY(kernel_thread_helper)
16480 * Here we are in the child and the registers are set as they were
16481 * at kernel_thread() invocation in the parent.
16482 */
16483+ pax_force_fptr %rsi
16484 call *%rsi
16485 # exit
16486 mov %eax, %edi
16487 call do_exit
16488 ud2 # padding for call trace
16489 CFI_ENDPROC
16490-END(kernel_thread_helper)
16491+ENDPROC(kernel_thread_helper)
16492
16493 /*
16494 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16495@@ -1264,11 +1641,11 @@ ENTRY(kernel_execve)
16496 RESTORE_REST
16497 testq %rax,%rax
16498 je int_ret_from_sys_call
16499- RESTORE_ARGS
16500 UNFAKE_STACK_FRAME
16501+ pax_force_retaddr
16502 ret
16503 CFI_ENDPROC
16504-END(kernel_execve)
16505+ENDPROC(kernel_execve)
16506
16507 /* Call softirq on interrupt stack. Interrupts are off. */
16508 ENTRY(call_softirq)
16509@@ -1286,9 +1663,10 @@ ENTRY(call_softirq)
16510 CFI_DEF_CFA_REGISTER rsp
16511 CFI_ADJUST_CFA_OFFSET -8
16512 decl PER_CPU_VAR(irq_count)
16513+ pax_force_retaddr
16514 ret
16515 CFI_ENDPROC
16516-END(call_softirq)
16517+ENDPROC(call_softirq)
16518
16519 #ifdef CONFIG_XEN
16520 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16521@@ -1326,7 +1704,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16522 decl PER_CPU_VAR(irq_count)
16523 jmp error_exit
16524 CFI_ENDPROC
16525-END(xen_do_hypervisor_callback)
16526+ENDPROC(xen_do_hypervisor_callback)
16527
16528 /*
16529 * Hypervisor uses this for application faults while it executes.
16530@@ -1385,7 +1763,7 @@ ENTRY(xen_failsafe_callback)
16531 SAVE_ALL
16532 jmp error_exit
16533 CFI_ENDPROC
16534-END(xen_failsafe_callback)
16535+ENDPROC(xen_failsafe_callback)
16536
16537 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16538 xen_hvm_callback_vector xen_evtchn_do_upcall
16539@@ -1434,16 +1812,31 @@ ENTRY(paranoid_exit)
16540 TRACE_IRQS_OFF_DEBUG
16541 testl %ebx,%ebx /* swapgs needed? */
16542 jnz paranoid_restore
16543- testl $3,CS(%rsp)
16544+ testb $3,CS(%rsp)
16545 jnz paranoid_userspace
16546+#ifdef CONFIG_PAX_MEMORY_UDEREF
16547+ pax_exit_kernel
16548+ TRACE_IRQS_IRETQ 0
16549+ SWAPGS_UNSAFE_STACK
16550+ RESTORE_ALL 8
16551+ pax_force_retaddr_bts
16552+ jmp irq_return
16553+#endif
16554 paranoid_swapgs:
16555+#ifdef CONFIG_PAX_MEMORY_UDEREF
16556+ pax_exit_kernel_user
16557+#else
16558+ pax_exit_kernel
16559+#endif
16560 TRACE_IRQS_IRETQ 0
16561 SWAPGS_UNSAFE_STACK
16562 RESTORE_ALL 8
16563 jmp irq_return
16564 paranoid_restore:
16565+ pax_exit_kernel
16566 TRACE_IRQS_IRETQ_DEBUG 0
16567 RESTORE_ALL 8
16568+ pax_force_retaddr_bts
16569 jmp irq_return
16570 paranoid_userspace:
16571 GET_THREAD_INFO(%rcx)
16572@@ -1472,7 +1865,7 @@ paranoid_schedule:
16573 TRACE_IRQS_OFF
16574 jmp paranoid_userspace
16575 CFI_ENDPROC
16576-END(paranoid_exit)
16577+ENDPROC(paranoid_exit)
16578
16579 /*
16580 * Exception entry point. This expects an error code/orig_rax on the stack.
16581@@ -1499,12 +1892,13 @@ ENTRY(error_entry)
16582 movq_cfi r14, R14+8
16583 movq_cfi r15, R15+8
16584 xorl %ebx,%ebx
16585- testl $3,CS+8(%rsp)
16586+ testb $3,CS+8(%rsp)
16587 je error_kernelspace
16588 error_swapgs:
16589 SWAPGS
16590 error_sti:
16591 TRACE_IRQS_OFF
16592+ pax_force_retaddr_bts
16593 ret
16594
16595 /*
16596@@ -1531,7 +1925,7 @@ bstep_iret:
16597 movq %rcx,RIP+8(%rsp)
16598 jmp error_swapgs
16599 CFI_ENDPROC
16600-END(error_entry)
16601+ENDPROC(error_entry)
16602
16603
16604 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16605@@ -1551,7 +1945,7 @@ ENTRY(error_exit)
16606 jnz retint_careful
16607 jmp retint_swapgs
16608 CFI_ENDPROC
16609-END(error_exit)
16610+ENDPROC(error_exit)
16611
16612 /*
16613 * Test if a given stack is an NMI stack or not.
16614@@ -1609,9 +2003,11 @@ ENTRY(nmi)
16615 * If %cs was not the kernel segment, then the NMI triggered in user
16616 * space, which means it is definitely not nested.
16617 */
16618+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16619+ je 1f
16620 cmpl $__KERNEL_CS, 16(%rsp)
16621 jne first_nmi
16622-
16623+1:
16624 /*
16625 * Check the special variable on the stack to see if NMIs are
16626 * executing.
16627@@ -1758,6 +2154,16 @@ end_repeat_nmi:
16628 */
16629 call save_paranoid
16630 DEFAULT_FRAME 0
16631+#ifdef CONFIG_PAX_MEMORY_UDEREF
16632+ testb $3, CS(%rsp)
16633+ jnz 1f
16634+ pax_enter_kernel
16635+ jmp 2f
16636+1: pax_enter_kernel_user
16637+2:
16638+#else
16639+ pax_enter_kernel
16640+#endif
16641 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16642 movq %rsp,%rdi
16643 movq $-1,%rsi
16644@@ -1765,21 +2171,32 @@ end_repeat_nmi:
16645 testl %ebx,%ebx /* swapgs needed? */
16646 jnz nmi_restore
16647 nmi_swapgs:
16648+#ifdef CONFIG_PAX_MEMORY_UDEREF
16649+ pax_exit_kernel_user
16650+#else
16651+ pax_exit_kernel
16652+#endif
16653 SWAPGS_UNSAFE_STACK
16654+ RESTORE_ALL 8
16655+ /* Clear the NMI executing stack variable */
16656+ movq $0, 10*8(%rsp)
16657+ jmp irq_return
16658 nmi_restore:
16659+ pax_exit_kernel
16660 RESTORE_ALL 8
16661+ pax_force_retaddr_bts
16662 /* Clear the NMI executing stack variable */
16663 movq $0, 10*8(%rsp)
16664 jmp irq_return
16665 CFI_ENDPROC
16666-END(nmi)
16667+ENDPROC(nmi)
16668
16669 ENTRY(ignore_sysret)
16670 CFI_STARTPROC
16671 mov $-ENOSYS,%eax
16672 sysret
16673 CFI_ENDPROC
16674-END(ignore_sysret)
16675+ENDPROC(ignore_sysret)
16676
16677 /*
16678 * End of kprobes section
16679diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16680index c3a7cb4..3ad00dc 100644
16681--- a/arch/x86/kernel/ftrace.c
16682+++ b/arch/x86/kernel/ftrace.c
16683@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
16684 {
16685 unsigned char replaced[MCOUNT_INSN_SIZE];
16686
16687+ ip = ktla_ktva(ip);
16688+
16689 /*
16690 * Note: Due to modules and __init, code can
16691 * disappear and change, we need to protect against faulting
16692@@ -212,7 +214,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16693 unsigned char old[MCOUNT_INSN_SIZE], *new;
16694 int ret;
16695
16696- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16697+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16698 new = ftrace_call_replace(ip, (unsigned long)func);
16699
16700 /* See comment above by declaration of modifying_ftrace_code */
16701@@ -605,6 +607,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16702 {
16703 unsigned char code[MCOUNT_INSN_SIZE];
16704
16705+ ip = ktla_ktva(ip);
16706+
16707 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16708 return -EFAULT;
16709
16710diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16711index c18f59d..9c0c9f6 100644
16712--- a/arch/x86/kernel/head32.c
16713+++ b/arch/x86/kernel/head32.c
16714@@ -18,6 +18,7 @@
16715 #include <asm/io_apic.h>
16716 #include <asm/bios_ebda.h>
16717 #include <asm/tlbflush.h>
16718+#include <asm/boot.h>
16719
16720 static void __init i386_default_early_setup(void)
16721 {
16722@@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
16723
16724 void __init i386_start_kernel(void)
16725 {
16726- memblock_reserve(__pa_symbol(&_text),
16727- __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16728+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16729
16730 #ifdef CONFIG_BLK_DEV_INITRD
16731 /* Reserve INITRD */
16732diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16733index d42ab17..cb1b997 100644
16734--- a/arch/x86/kernel/head_32.S
16735+++ b/arch/x86/kernel/head_32.S
16736@@ -26,6 +26,12 @@
16737 /* Physical address */
16738 #define pa(X) ((X) - __PAGE_OFFSET)
16739
16740+#ifdef CONFIG_PAX_KERNEXEC
16741+#define ta(X) (X)
16742+#else
16743+#define ta(X) ((X) - __PAGE_OFFSET)
16744+#endif
16745+
16746 /*
16747 * References to members of the new_cpu_data structure.
16748 */
16749@@ -55,11 +61,7 @@
16750 * and small than max_low_pfn, otherwise will waste some page table entries
16751 */
16752
16753-#if PTRS_PER_PMD > 1
16754-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16755-#else
16756-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16757-#endif
16758+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16759
16760 /* Number of possible pages in the lowmem region */
16761 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16762@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16763 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16764
16765 /*
16766+ * Real beginning of normal "text" segment
16767+ */
16768+ENTRY(stext)
16769+ENTRY(_stext)
16770+
16771+/*
16772 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16773 * %esi points to the real-mode code as a 32-bit pointer.
16774 * CS and DS must be 4 GB flat segments, but we don't depend on
16775@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16776 * can.
16777 */
16778 __HEAD
16779+
16780+#ifdef CONFIG_PAX_KERNEXEC
16781+ jmp startup_32
16782+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16783+.fill PAGE_SIZE-5,1,0xcc
16784+#endif
16785+
16786 ENTRY(startup_32)
16787 movl pa(stack_start),%ecx
16788
16789@@ -106,6 +121,57 @@ ENTRY(startup_32)
16790 2:
16791 leal -__PAGE_OFFSET(%ecx),%esp
16792
16793+#ifdef CONFIG_SMP
16794+ movl $pa(cpu_gdt_table),%edi
16795+ movl $__per_cpu_load,%eax
16796+ movw %ax,__KERNEL_PERCPU + 2(%edi)
16797+ rorl $16,%eax
16798+ movb %al,__KERNEL_PERCPU + 4(%edi)
16799+ movb %ah,__KERNEL_PERCPU + 7(%edi)
16800+ movl $__per_cpu_end - 1,%eax
16801+ subl $__per_cpu_start,%eax
16802+ movw %ax,__KERNEL_PERCPU + 0(%edi)
16803+#endif
16804+
16805+#ifdef CONFIG_PAX_MEMORY_UDEREF
16806+ movl $NR_CPUS,%ecx
16807+ movl $pa(cpu_gdt_table),%edi
16808+1:
16809+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16810+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16811+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16812+ addl $PAGE_SIZE_asm,%edi
16813+ loop 1b
16814+#endif
16815+
16816+#ifdef CONFIG_PAX_KERNEXEC
16817+ movl $pa(boot_gdt),%edi
16818+ movl $__LOAD_PHYSICAL_ADDR,%eax
16819+ movw %ax,__BOOT_CS + 2(%edi)
16820+ rorl $16,%eax
16821+ movb %al,__BOOT_CS + 4(%edi)
16822+ movb %ah,__BOOT_CS + 7(%edi)
16823+ rorl $16,%eax
16824+
16825+ ljmp $(__BOOT_CS),$1f
16826+1:
16827+
16828+ movl $NR_CPUS,%ecx
16829+ movl $pa(cpu_gdt_table),%edi
16830+ addl $__PAGE_OFFSET,%eax
16831+1:
16832+ movw %ax,__KERNEL_CS + 2(%edi)
16833+ movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16834+ rorl $16,%eax
16835+ movb %al,__KERNEL_CS + 4(%edi)
16836+ movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16837+ movb %ah,__KERNEL_CS + 7(%edi)
16838+ movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16839+ rorl $16,%eax
16840+ addl $PAGE_SIZE_asm,%edi
16841+ loop 1b
16842+#endif
16843+
16844 /*
16845 * Clear BSS first so that there are no surprises...
16846 */
16847@@ -196,8 +262,11 @@ ENTRY(startup_32)
16848 movl %eax, pa(max_pfn_mapped)
16849
16850 /* Do early initialization of the fixmap area */
16851- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16852- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16853+#ifdef CONFIG_COMPAT_VDSO
16854+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16855+#else
16856+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16857+#endif
16858 #else /* Not PAE */
16859
16860 page_pde_offset = (__PAGE_OFFSET >> 20);
16861@@ -227,8 +296,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16862 movl %eax, pa(max_pfn_mapped)
16863
16864 /* Do early initialization of the fixmap area */
16865- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16866- movl %eax,pa(initial_page_table+0xffc)
16867+#ifdef CONFIG_COMPAT_VDSO
16868+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16869+#else
16870+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16871+#endif
16872 #endif
16873
16874 #ifdef CONFIG_PARAVIRT
16875@@ -242,9 +314,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16876 cmpl $num_subarch_entries, %eax
16877 jae bad_subarch
16878
16879- movl pa(subarch_entries)(,%eax,4), %eax
16880- subl $__PAGE_OFFSET, %eax
16881- jmp *%eax
16882+ jmp *pa(subarch_entries)(,%eax,4)
16883
16884 bad_subarch:
16885 WEAK(lguest_entry)
16886@@ -256,10 +326,10 @@ WEAK(xen_entry)
16887 __INITDATA
16888
16889 subarch_entries:
16890- .long default_entry /* normal x86/PC */
16891- .long lguest_entry /* lguest hypervisor */
16892- .long xen_entry /* Xen hypervisor */
16893- .long default_entry /* Moorestown MID */
16894+ .long ta(default_entry) /* normal x86/PC */
16895+ .long ta(lguest_entry) /* lguest hypervisor */
16896+ .long ta(xen_entry) /* Xen hypervisor */
16897+ .long ta(default_entry) /* Moorestown MID */
16898 num_subarch_entries = (. - subarch_entries) / 4
16899 .previous
16900 #else
16901@@ -310,6 +380,7 @@ default_entry:
16902 orl %edx,%eax
16903 movl %eax,%cr4
16904
16905+#ifdef CONFIG_X86_PAE
16906 testb $X86_CR4_PAE, %al # check if PAE is enabled
16907 jz 6f
16908
16909@@ -338,6 +409,9 @@ default_entry:
16910 /* Make changes effective */
16911 wrmsr
16912
16913+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
16914+#endif
16915+
16916 6:
16917
16918 /*
16919@@ -436,14 +510,20 @@ is386: movl $2,%ecx # set MP
16920 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
16921 movl %eax,%ss # after changing gdt.
16922
16923- movl $(__USER_DS),%eax # DS/ES contains default USER segment
16924+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
16925 movl %eax,%ds
16926 movl %eax,%es
16927
16928 movl $(__KERNEL_PERCPU), %eax
16929 movl %eax,%fs # set this cpu's percpu
16930
16931+#ifdef CONFIG_CC_STACKPROTECTOR
16932 movl $(__KERNEL_STACK_CANARY),%eax
16933+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
16934+ movl $(__USER_DS),%eax
16935+#else
16936+ xorl %eax,%eax
16937+#endif
16938 movl %eax,%gs
16939
16940 xorl %eax,%eax # Clear LDT
16941@@ -520,8 +600,11 @@ setup_once:
16942 * relocation. Manually set base address in stack canary
16943 * segment descriptor.
16944 */
16945- movl $gdt_page,%eax
16946+ movl $cpu_gdt_table,%eax
16947 movl $stack_canary,%ecx
16948+#ifdef CONFIG_SMP
16949+ addl $__per_cpu_load,%ecx
16950+#endif
16951 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
16952 shrl $16, %ecx
16953 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
16954@@ -552,7 +635,7 @@ ENDPROC(early_idt_handlers)
16955 /* This is global to keep gas from relaxing the jumps */
16956 ENTRY(early_idt_handler)
16957 cld
16958- cmpl $2,%ss:early_recursion_flag
16959+ cmpl $1,%ss:early_recursion_flag
16960 je hlt_loop
16961 incl %ss:early_recursion_flag
16962
16963@@ -590,8 +673,8 @@ ENTRY(early_idt_handler)
16964 pushl (20+6*4)(%esp) /* trapno */
16965 pushl $fault_msg
16966 call printk
16967-#endif
16968 call dump_stack
16969+#endif
16970 hlt_loop:
16971 hlt
16972 jmp hlt_loop
16973@@ -610,8 +693,11 @@ ENDPROC(early_idt_handler)
16974 /* This is the default interrupt "handler" :-) */
16975 ALIGN
16976 ignore_int:
16977- cld
16978 #ifdef CONFIG_PRINTK
16979+ cmpl $2,%ss:early_recursion_flag
16980+ je hlt_loop
16981+ incl %ss:early_recursion_flag
16982+ cld
16983 pushl %eax
16984 pushl %ecx
16985 pushl %edx
16986@@ -620,9 +706,6 @@ ignore_int:
16987 movl $(__KERNEL_DS),%eax
16988 movl %eax,%ds
16989 movl %eax,%es
16990- cmpl $2,early_recursion_flag
16991- je hlt_loop
16992- incl early_recursion_flag
16993 pushl 16(%esp)
16994 pushl 24(%esp)
16995 pushl 32(%esp)
16996@@ -656,29 +739,43 @@ ENTRY(setup_once_ref)
16997 /*
16998 * BSS section
16999 */
17000-__PAGE_ALIGNED_BSS
17001- .align PAGE_SIZE
17002 #ifdef CONFIG_X86_PAE
17003+.section .initial_pg_pmd,"a",@progbits
17004 initial_pg_pmd:
17005 .fill 1024*KPMDS,4,0
17006 #else
17007+.section .initial_page_table,"a",@progbits
17008 ENTRY(initial_page_table)
17009 .fill 1024,4,0
17010 #endif
17011+.section .initial_pg_fixmap,"a",@progbits
17012 initial_pg_fixmap:
17013 .fill 1024,4,0
17014+.section .empty_zero_page,"a",@progbits
17015 ENTRY(empty_zero_page)
17016 .fill 4096,1,0
17017+.section .swapper_pg_dir,"a",@progbits
17018 ENTRY(swapper_pg_dir)
17019+#ifdef CONFIG_X86_PAE
17020+ .fill 4,8,0
17021+#else
17022 .fill 1024,4,0
17023+#endif
17024+
17025+/*
17026+ * The IDT has to be page-aligned to simplify the Pentium
17027+ * F0 0F bug workaround.. We have a special link segment
17028+ * for this.
17029+ */
17030+.section .idt,"a",@progbits
17031+ENTRY(idt_table)
17032+ .fill 256,8,0
17033
17034 /*
17035 * This starts the data section.
17036 */
17037 #ifdef CONFIG_X86_PAE
17038-__PAGE_ALIGNED_DATA
17039- /* Page-aligned for the benefit of paravirt? */
17040- .align PAGE_SIZE
17041+.section .initial_page_table,"a",@progbits
17042 ENTRY(initial_page_table)
17043 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17044 # if KPMDS == 3
17045@@ -697,12 +794,20 @@ ENTRY(initial_page_table)
17046 # error "Kernel PMDs should be 1, 2 or 3"
17047 # endif
17048 .align PAGE_SIZE /* needs to be page-sized too */
17049+
17050+#ifdef CONFIG_PAX_PER_CPU_PGD
17051+ENTRY(cpu_pgd)
17052+ .rept NR_CPUS
17053+ .fill 4,8,0
17054+ .endr
17055+#endif
17056+
17057 #endif
17058
17059 .data
17060 .balign 4
17061 ENTRY(stack_start)
17062- .long init_thread_union+THREAD_SIZE
17063+ .long init_thread_union+THREAD_SIZE-8
17064
17065 __INITRODATA
17066 int_msg:
17067@@ -730,7 +835,7 @@ fault_msg:
17068 * segment size, and 32-bit linear address value:
17069 */
17070
17071- .data
17072+.section .rodata,"a",@progbits
17073 .globl boot_gdt_descr
17074 .globl idt_descr
17075
17076@@ -739,7 +844,7 @@ fault_msg:
17077 .word 0 # 32 bit align gdt_desc.address
17078 boot_gdt_descr:
17079 .word __BOOT_DS+7
17080- .long boot_gdt - __PAGE_OFFSET
17081+ .long pa(boot_gdt)
17082
17083 .word 0 # 32-bit align idt_desc.address
17084 idt_descr:
17085@@ -750,7 +855,7 @@ idt_descr:
17086 .word 0 # 32 bit align gdt_desc.address
17087 ENTRY(early_gdt_descr)
17088 .word GDT_ENTRIES*8-1
17089- .long gdt_page /* Overwritten for secondary CPUs */
17090+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
17091
17092 /*
17093 * The boot_gdt must mirror the equivalent in setup.S and is
17094@@ -759,5 +864,65 @@ ENTRY(early_gdt_descr)
17095 .align L1_CACHE_BYTES
17096 ENTRY(boot_gdt)
17097 .fill GDT_ENTRY_BOOT_CS,8,0
17098- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17099- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17100+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17101+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17102+
17103+ .align PAGE_SIZE_asm
17104+ENTRY(cpu_gdt_table)
17105+ .rept NR_CPUS
17106+ .quad 0x0000000000000000 /* NULL descriptor */
17107+ .quad 0x0000000000000000 /* 0x0b reserved */
17108+ .quad 0x0000000000000000 /* 0x13 reserved */
17109+ .quad 0x0000000000000000 /* 0x1b reserved */
17110+
17111+#ifdef CONFIG_PAX_KERNEXEC
17112+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17113+#else
17114+ .quad 0x0000000000000000 /* 0x20 unused */
17115+#endif
17116+
17117+ .quad 0x0000000000000000 /* 0x28 unused */
17118+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17119+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17120+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17121+ .quad 0x0000000000000000 /* 0x4b reserved */
17122+ .quad 0x0000000000000000 /* 0x53 reserved */
17123+ .quad 0x0000000000000000 /* 0x5b reserved */
17124+
17125+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17126+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17127+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17128+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17129+
17130+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17131+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17132+
17133+ /*
17134+ * Segments used for calling PnP BIOS have byte granularity.
17135+ * The code segments and data segments have fixed 64k limits,
17136+ * the transfer segment sizes are set at run time.
17137+ */
17138+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
17139+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
17140+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
17141+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
17142+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
17143+
17144+ /*
17145+ * The APM segments have byte granularity and their bases
17146+ * are set at run time. All have 64k limits.
17147+ */
17148+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17149+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17150+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
17151+
17152+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17153+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17154+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17155+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17156+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17157+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17158+
17159+ /* Be sure this is zeroed to avoid false validations in Xen */
17160+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17161+ .endr
17162diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17163index 94bf9cc..400455a 100644
17164--- a/arch/x86/kernel/head_64.S
17165+++ b/arch/x86/kernel/head_64.S
17166@@ -20,6 +20,8 @@
17167 #include <asm/processor-flags.h>
17168 #include <asm/percpu.h>
17169 #include <asm/nops.h>
17170+#include <asm/cpufeature.h>
17171+#include <asm/alternative-asm.h>
17172
17173 #ifdef CONFIG_PARAVIRT
17174 #include <asm/asm-offsets.h>
17175@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17176 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17177 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17178 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17179+L4_VMALLOC_START = pgd_index(VMALLOC_START)
17180+L3_VMALLOC_START = pud_index(VMALLOC_START)
17181+L4_VMALLOC_END = pgd_index(VMALLOC_END)
17182+L3_VMALLOC_END = pud_index(VMALLOC_END)
17183+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17184+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17185
17186 .text
17187 __HEAD
17188@@ -88,35 +96,23 @@ startup_64:
17189 */
17190 addq %rbp, init_level4_pgt + 0(%rip)
17191 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17192+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17193+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17194+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17195 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17196
17197 addq %rbp, level3_ident_pgt + 0(%rip)
17198+#ifndef CONFIG_XEN
17199+ addq %rbp, level3_ident_pgt + 8(%rip)
17200+#endif
17201
17202- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17203- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17204+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17205+
17206+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17207+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17208
17209 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17210-
17211- /* Add an Identity mapping if I am above 1G */
17212- leaq _text(%rip), %rdi
17213- andq $PMD_PAGE_MASK, %rdi
17214-
17215- movq %rdi, %rax
17216- shrq $PUD_SHIFT, %rax
17217- andq $(PTRS_PER_PUD - 1), %rax
17218- jz ident_complete
17219-
17220- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17221- leaq level3_ident_pgt(%rip), %rbx
17222- movq %rdx, 0(%rbx, %rax, 8)
17223-
17224- movq %rdi, %rax
17225- shrq $PMD_SHIFT, %rax
17226- andq $(PTRS_PER_PMD - 1), %rax
17227- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17228- leaq level2_spare_pgt(%rip), %rbx
17229- movq %rdx, 0(%rbx, %rax, 8)
17230-ident_complete:
17231+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17232
17233 /*
17234 * Fixup the kernel text+data virtual addresses. Note that
17235@@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
17236 * after the boot processor executes this code.
17237 */
17238
17239- /* Enable PAE mode and PGE */
17240- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17241+ /* Enable PAE mode and PSE/PGE */
17242+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17243 movq %rax, %cr4
17244
17245 /* Setup early boot stage 4 level pagetables. */
17246@@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
17247 movl $MSR_EFER, %ecx
17248 rdmsr
17249 btsl $_EFER_SCE, %eax /* Enable System Call */
17250- btl $20,%edi /* No Execute supported? */
17251+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17252 jnc 1f
17253 btsl $_EFER_NX, %eax
17254+ leaq init_level4_pgt(%rip), %rdi
17255+#ifndef CONFIG_EFI
17256+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17257+#endif
17258+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17259+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17260+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17261+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17262 1: wrmsr /* Make changes effective */
17263
17264 /* Setup cr0 */
17265@@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
17266 * jump. In addition we need to ensure %cs is set so we make this
17267 * a far return.
17268 */
17269+ pax_set_fptr_mask
17270 movq initial_code(%rip),%rax
17271 pushq $0 # fake return address to stop unwinder
17272 pushq $__KERNEL_CS # set correct cs
17273@@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
17274 bad_address:
17275 jmp bad_address
17276
17277- .section ".init.text","ax"
17278+ __INIT
17279 .globl early_idt_handlers
17280 early_idt_handlers:
17281 # 104(%rsp) %rflags
17282@@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
17283 addq $16,%rsp # drop vector number and error code
17284 decl early_recursion_flag(%rip)
17285 INTERRUPT_RETURN
17286+ .previous
17287
17288+ __INITDATA
17289 .balign 4
17290 early_recursion_flag:
17291 .long 0
17292+ .previous
17293
17294+ .section .rodata,"a",@progbits
17295 #ifdef CONFIG_EARLY_PRINTK
17296 early_idt_msg:
17297 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17298@@ -360,6 +369,7 @@ early_idt_ripmsg:
17299 #endif /* CONFIG_EARLY_PRINTK */
17300 .previous
17301
17302+ .section .rodata,"a",@progbits
17303 #define NEXT_PAGE(name) \
17304 .balign PAGE_SIZE; \
17305 ENTRY(name)
17306@@ -372,7 +382,6 @@ ENTRY(name)
17307 i = i + 1 ; \
17308 .endr
17309
17310- .data
17311 /*
17312 * This default setting generates an ident mapping at address 0x100000
17313 * and a mapping for the kernel that precisely maps virtual address
17314@@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
17315 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17316 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17317 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17318+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
17319+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17320+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
17321+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17322+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17323+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17324 .org init_level4_pgt + L4_START_KERNEL*8, 0
17325 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17326 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17327
17328+#ifdef CONFIG_PAX_PER_CPU_PGD
17329+NEXT_PAGE(cpu_pgd)
17330+ .rept NR_CPUS
17331+ .fill 512,8,0
17332+ .endr
17333+#endif
17334+
17335 NEXT_PAGE(level3_ident_pgt)
17336 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17337+#ifdef CONFIG_XEN
17338 .fill 511,8,0
17339+#else
17340+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17341+ .fill 510,8,0
17342+#endif
17343+
17344+NEXT_PAGE(level3_vmalloc_start_pgt)
17345+ .fill 512,8,0
17346+
17347+NEXT_PAGE(level3_vmalloc_end_pgt)
17348+ .fill 512,8,0
17349+
17350+NEXT_PAGE(level3_vmemmap_pgt)
17351+ .fill L3_VMEMMAP_START,8,0
17352+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17353
17354 NEXT_PAGE(level3_kernel_pgt)
17355 .fill L3_START_KERNEL,8,0
17356@@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
17357 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17358 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17359
17360+NEXT_PAGE(level2_vmemmap_pgt)
17361+ .fill 512,8,0
17362+
17363 NEXT_PAGE(level2_fixmap_pgt)
17364- .fill 506,8,0
17365- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17366- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17367- .fill 5,8,0
17368+ .fill 507,8,0
17369+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17370+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17371+ .fill 4,8,0
17372
17373-NEXT_PAGE(level1_fixmap_pgt)
17374+NEXT_PAGE(level1_vsyscall_pgt)
17375 .fill 512,8,0
17376
17377-NEXT_PAGE(level2_ident_pgt)
17378- /* Since I easily can, map the first 1G.
17379+ /* Since I easily can, map the first 2G.
17380 * Don't set NX because code runs from these pages.
17381 */
17382- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17383+NEXT_PAGE(level2_ident_pgt)
17384+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17385
17386 NEXT_PAGE(level2_kernel_pgt)
17387 /*
17388@@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
17389 * If you want to increase this then increase MODULES_VADDR
17390 * too.)
17391 */
17392- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17393- KERNEL_IMAGE_SIZE/PMD_SIZE)
17394-
17395-NEXT_PAGE(level2_spare_pgt)
17396- .fill 512, 8, 0
17397+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17398
17399 #undef PMDS
17400 #undef NEXT_PAGE
17401
17402- .data
17403+ .align PAGE_SIZE
17404+ENTRY(cpu_gdt_table)
17405+ .rept NR_CPUS
17406+ .quad 0x0000000000000000 /* NULL descriptor */
17407+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17408+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
17409+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
17410+ .quad 0x00cffb000000ffff /* __USER32_CS */
17411+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17412+ .quad 0x00affb000000ffff /* __USER_CS */
17413+
17414+#ifdef CONFIG_PAX_KERNEXEC
17415+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17416+#else
17417+ .quad 0x0 /* unused */
17418+#endif
17419+
17420+ .quad 0,0 /* TSS */
17421+ .quad 0,0 /* LDT */
17422+ .quad 0,0,0 /* three TLS descriptors */
17423+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
17424+ /* asm/segment.h:GDT_ENTRIES must match this */
17425+
17426+ /* zero the remaining page */
17427+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17428+ .endr
17429+
17430 .align 16
17431 .globl early_gdt_descr
17432 early_gdt_descr:
17433 .word GDT_ENTRIES*8-1
17434 early_gdt_descr_base:
17435- .quad INIT_PER_CPU_VAR(gdt_page)
17436+ .quad cpu_gdt_table
17437
17438 ENTRY(phys_base)
17439 /* This must match the first entry in level2_kernel_pgt */
17440 .quad 0x0000000000000000
17441
17442 #include "../../x86/xen/xen-head.S"
17443-
17444- .section .bss, "aw", @nobits
17445+
17446+ .section .rodata,"a",@progbits
17447 .align L1_CACHE_BYTES
17448 ENTRY(idt_table)
17449- .skip IDT_ENTRIES * 16
17450+ .fill 512,8,0
17451
17452 .align L1_CACHE_BYTES
17453 ENTRY(nmi_idt_table)
17454- .skip IDT_ENTRIES * 16
17455+ .fill 512,8,0
17456
17457 __PAGE_ALIGNED_BSS
17458 .align PAGE_SIZE
17459diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17460index 9c3bd4a..e1d9b35 100644
17461--- a/arch/x86/kernel/i386_ksyms_32.c
17462+++ b/arch/x86/kernel/i386_ksyms_32.c
17463@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17464 EXPORT_SYMBOL(cmpxchg8b_emu);
17465 #endif
17466
17467+EXPORT_SYMBOL_GPL(cpu_gdt_table);
17468+
17469 /* Networking helper routines. */
17470 EXPORT_SYMBOL(csum_partial_copy_generic);
17471+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17472+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17473
17474 EXPORT_SYMBOL(__get_user_1);
17475 EXPORT_SYMBOL(__get_user_2);
17476@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17477
17478 EXPORT_SYMBOL(csum_partial);
17479 EXPORT_SYMBOL(empty_zero_page);
17480+
17481+#ifdef CONFIG_PAX_KERNEXEC
17482+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17483+#endif
17484diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17485index f250431..54097e7 100644
17486--- a/arch/x86/kernel/i387.c
17487+++ b/arch/x86/kernel/i387.c
17488@@ -59,7 +59,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17489 static inline bool interrupted_user_mode(void)
17490 {
17491 struct pt_regs *regs = get_irq_regs();
17492- return regs && user_mode_vm(regs);
17493+ return regs && user_mode(regs);
17494 }
17495
17496 /*
17497diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17498index 36d1853..bf25736 100644
17499--- a/arch/x86/kernel/i8259.c
17500+++ b/arch/x86/kernel/i8259.c
17501@@ -209,7 +209,7 @@ spurious_8259A_irq:
17502 "spurious 8259A interrupt: IRQ%d.\n", irq);
17503 spurious_irq_mask |= irqmask;
17504 }
17505- atomic_inc(&irq_err_count);
17506+ atomic_inc_unchecked(&irq_err_count);
17507 /*
17508 * Theoretically we do not have to handle this IRQ,
17509 * but in Linux this does not cause problems and is
17510diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17511index 8c96897..be66bfa 100644
17512--- a/arch/x86/kernel/ioport.c
17513+++ b/arch/x86/kernel/ioport.c
17514@@ -6,6 +6,7 @@
17515 #include <linux/sched.h>
17516 #include <linux/kernel.h>
17517 #include <linux/capability.h>
17518+#include <linux/security.h>
17519 #include <linux/errno.h>
17520 #include <linux/types.h>
17521 #include <linux/ioport.h>
17522@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17523
17524 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17525 return -EINVAL;
17526+#ifdef CONFIG_GRKERNSEC_IO
17527+ if (turn_on && grsec_disable_privio) {
17528+ gr_handle_ioperm();
17529+ return -EPERM;
17530+ }
17531+#endif
17532 if (turn_on && !capable(CAP_SYS_RAWIO))
17533 return -EPERM;
17534
17535@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17536 * because the ->io_bitmap_max value must match the bitmap
17537 * contents:
17538 */
17539- tss = &per_cpu(init_tss, get_cpu());
17540+ tss = init_tss + get_cpu();
17541
17542 if (turn_on)
17543 bitmap_clear(t->io_bitmap_ptr, from, num);
17544@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17545 return -EINVAL;
17546 /* Trying to gain more privileges? */
17547 if (level > old) {
17548+#ifdef CONFIG_GRKERNSEC_IO
17549+ if (grsec_disable_privio) {
17550+ gr_handle_iopl();
17551+ return -EPERM;
17552+ }
17553+#endif
17554 if (!capable(CAP_SYS_RAWIO))
17555 return -EPERM;
17556 }
17557diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17558index 3dafc60..aa8e9c4 100644
17559--- a/arch/x86/kernel/irq.c
17560+++ b/arch/x86/kernel/irq.c
17561@@ -18,7 +18,7 @@
17562 #include <asm/mce.h>
17563 #include <asm/hw_irq.h>
17564
17565-atomic_t irq_err_count;
17566+atomic_unchecked_t irq_err_count;
17567
17568 /* Function pointer for generic interrupt vector handling */
17569 void (*x86_platform_ipi_callback)(void) = NULL;
17570@@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17571 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17572 seq_printf(p, " Machine check polls\n");
17573 #endif
17574- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17575+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17576 #if defined(CONFIG_X86_IO_APIC)
17577- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17578+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17579 #endif
17580 return 0;
17581 }
17582@@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17583
17584 u64 arch_irq_stat(void)
17585 {
17586- u64 sum = atomic_read(&irq_err_count);
17587+ u64 sum = atomic_read_unchecked(&irq_err_count);
17588
17589 #ifdef CONFIG_X86_IO_APIC
17590- sum += atomic_read(&irq_mis_count);
17591+ sum += atomic_read_unchecked(&irq_mis_count);
17592 #endif
17593 return sum;
17594 }
17595diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17596index 344faf8..355f60d 100644
17597--- a/arch/x86/kernel/irq_32.c
17598+++ b/arch/x86/kernel/irq_32.c
17599@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17600 __asm__ __volatile__("andl %%esp,%0" :
17601 "=r" (sp) : "0" (THREAD_SIZE - 1));
17602
17603- return sp < (sizeof(struct thread_info) + STACK_WARN);
17604+ return sp < STACK_WARN;
17605 }
17606
17607 static void print_stack_overflow(void)
17608@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17609 * per-CPU IRQ handling contexts (thread information and stack)
17610 */
17611 union irq_ctx {
17612- struct thread_info tinfo;
17613- u32 stack[THREAD_SIZE/sizeof(u32)];
17614+ unsigned long previous_esp;
17615+ u32 stack[THREAD_SIZE/sizeof(u32)];
17616 } __attribute__((aligned(THREAD_SIZE)));
17617
17618 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17619@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17620 static inline int
17621 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17622 {
17623- union irq_ctx *curctx, *irqctx;
17624+ union irq_ctx *irqctx;
17625 u32 *isp, arg1, arg2;
17626
17627- curctx = (union irq_ctx *) current_thread_info();
17628 irqctx = __this_cpu_read(hardirq_ctx);
17629
17630 /*
17631@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17632 * handler) we can't do that and just have to keep using the
17633 * current stack (which is the irq stack already after all)
17634 */
17635- if (unlikely(curctx == irqctx))
17636+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17637 return 0;
17638
17639 /* build the stack frame on the IRQ stack */
17640- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17641- irqctx->tinfo.task = curctx->tinfo.task;
17642- irqctx->tinfo.previous_esp = current_stack_pointer;
17643+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17644+ irqctx->previous_esp = current_stack_pointer;
17645
17646- /* Copy the preempt_count so that the [soft]irq checks work. */
17647- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17648+#ifdef CONFIG_PAX_MEMORY_UDEREF
17649+ __set_fs(MAKE_MM_SEG(0));
17650+#endif
17651
17652 if (unlikely(overflow))
17653 call_on_stack(print_stack_overflow, isp);
17654@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17655 : "0" (irq), "1" (desc), "2" (isp),
17656 "D" (desc->handle_irq)
17657 : "memory", "cc", "ecx");
17658+
17659+#ifdef CONFIG_PAX_MEMORY_UDEREF
17660+ __set_fs(current_thread_info()->addr_limit);
17661+#endif
17662+
17663 return 1;
17664 }
17665
17666@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17667 */
17668 void __cpuinit irq_ctx_init(int cpu)
17669 {
17670- union irq_ctx *irqctx;
17671-
17672 if (per_cpu(hardirq_ctx, cpu))
17673 return;
17674
17675- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17676- THREADINFO_GFP,
17677- THREAD_SIZE_ORDER));
17678- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17679- irqctx->tinfo.cpu = cpu;
17680- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17681- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17682-
17683- per_cpu(hardirq_ctx, cpu) = irqctx;
17684-
17685- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17686- THREADINFO_GFP,
17687- THREAD_SIZE_ORDER));
17688- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17689- irqctx->tinfo.cpu = cpu;
17690- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17691-
17692- per_cpu(softirq_ctx, cpu) = irqctx;
17693+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17694+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17695+
17696+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17697+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17698
17699 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17700 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17701@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
17702 asmlinkage void do_softirq(void)
17703 {
17704 unsigned long flags;
17705- struct thread_info *curctx;
17706 union irq_ctx *irqctx;
17707 u32 *isp;
17708
17709@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
17710 local_irq_save(flags);
17711
17712 if (local_softirq_pending()) {
17713- curctx = current_thread_info();
17714 irqctx = __this_cpu_read(softirq_ctx);
17715- irqctx->tinfo.task = curctx->task;
17716- irqctx->tinfo.previous_esp = current_stack_pointer;
17717+ irqctx->previous_esp = current_stack_pointer;
17718
17719 /* build the stack frame on the softirq stack */
17720- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17721+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17722+
17723+#ifdef CONFIG_PAX_MEMORY_UDEREF
17724+ __set_fs(MAKE_MM_SEG(0));
17725+#endif
17726
17727 call_on_stack(__do_softirq, isp);
17728+
17729+#ifdef CONFIG_PAX_MEMORY_UDEREF
17730+ __set_fs(current_thread_info()->addr_limit);
17731+#endif
17732+
17733 /*
17734 * Shouldn't happen, we returned above if in_interrupt():
17735 */
17736@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17737 if (unlikely(!desc))
17738 return false;
17739
17740- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17741+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17742 if (unlikely(overflow))
17743 print_stack_overflow();
17744 desc->handle_irq(irq, desc);
17745diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17746index d04d3ec..ea4b374 100644
17747--- a/arch/x86/kernel/irq_64.c
17748+++ b/arch/x86/kernel/irq_64.c
17749@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17750 u64 estack_top, estack_bottom;
17751 u64 curbase = (u64)task_stack_page(current);
17752
17753- if (user_mode_vm(regs))
17754+ if (user_mode(regs))
17755 return;
17756
17757 if (regs->sp >= curbase + sizeof(struct thread_info) +
17758diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17759index 1d5d31e..72731d4 100644
17760--- a/arch/x86/kernel/kdebugfs.c
17761+++ b/arch/x86/kernel/kdebugfs.c
17762@@ -27,7 +27,7 @@ struct setup_data_node {
17763 u32 len;
17764 };
17765
17766-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17767+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
17768 size_t count, loff_t *ppos)
17769 {
17770 struct setup_data_node *node = file->private_data;
17771diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17772index 3f61904..873cea9 100644
17773--- a/arch/x86/kernel/kgdb.c
17774+++ b/arch/x86/kernel/kgdb.c
17775@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17776 #ifdef CONFIG_X86_32
17777 switch (regno) {
17778 case GDB_SS:
17779- if (!user_mode_vm(regs))
17780+ if (!user_mode(regs))
17781 *(unsigned long *)mem = __KERNEL_DS;
17782 break;
17783 case GDB_SP:
17784- if (!user_mode_vm(regs))
17785+ if (!user_mode(regs))
17786 *(unsigned long *)mem = kernel_stack_pointer(regs);
17787 break;
17788 case GDB_GS:
17789@@ -476,12 +476,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17790 case 'k':
17791 /* clear the trace bit */
17792 linux_regs->flags &= ~X86_EFLAGS_TF;
17793- atomic_set(&kgdb_cpu_doing_single_step, -1);
17794+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17795
17796 /* set the trace bit if we're stepping */
17797 if (remcomInBuffer[0] == 's') {
17798 linux_regs->flags |= X86_EFLAGS_TF;
17799- atomic_set(&kgdb_cpu_doing_single_step,
17800+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17801 raw_smp_processor_id());
17802 }
17803
17804@@ -546,7 +546,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17805
17806 switch (cmd) {
17807 case DIE_DEBUG:
17808- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17809+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17810 if (user_mode(regs))
17811 return single_step_cont(regs, args);
17812 break;
17813diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
17814index c5e410e..da6aaf9 100644
17815--- a/arch/x86/kernel/kprobes-opt.c
17816+++ b/arch/x86/kernel/kprobes-opt.c
17817@@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17818 * Verify if the address gap is in 2GB range, because this uses
17819 * a relative jump.
17820 */
17821- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17822+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17823 if (abs(rel) > 0x7fffffff)
17824 return -ERANGE;
17825
17826@@ -359,11 +359,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17827 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17828
17829 /* Set probe function call */
17830- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17831+ synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17832
17833 /* Set returning jmp instruction at the tail of out-of-line buffer */
17834 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17835- (u8 *)op->kp.addr + op->optinsn.size);
17836+ (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17837
17838 flush_icache_range((unsigned long) buf,
17839 (unsigned long) buf + TMPL_END_IDX +
17840@@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17841 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17842
17843 /* Backup instructions which will be replaced by jump address */
17844- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17845+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17846 RELATIVE_ADDR_SIZE);
17847
17848 insn_buf[0] = RELATIVEJUMP_OPCODE;
17849diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17850index e2f751e..dffa2a0 100644
17851--- a/arch/x86/kernel/kprobes.c
17852+++ b/arch/x86/kernel/kprobes.c
17853@@ -120,8 +120,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17854 } __attribute__((packed)) *insn;
17855
17856 insn = (struct __arch_relative_insn *)from;
17857+
17858+ pax_open_kernel();
17859 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17860 insn->op = op;
17861+ pax_close_kernel();
17862 }
17863
17864 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17865@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
17866 kprobe_opcode_t opcode;
17867 kprobe_opcode_t *orig_opcodes = opcodes;
17868
17869- if (search_exception_tables((unsigned long)opcodes))
17870+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17871 return 0; /* Page fault may occur on this address. */
17872
17873 retry:
17874@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17875 /* Another subsystem puts a breakpoint, failed to recover */
17876 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
17877 return 0;
17878+ pax_open_kernel();
17879 memcpy(dest, insn.kaddr, insn.length);
17880+ pax_close_kernel();
17881
17882 #ifdef CONFIG_X86_64
17883 if (insn_rip_relative(&insn)) {
17884@@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17885 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
17886 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
17887 disp = (u8 *) dest + insn_offset_displacement(&insn);
17888+ pax_open_kernel();
17889 *(s32 *) disp = (s32) newdisp;
17890+ pax_close_kernel();
17891 }
17892 #endif
17893 return insn.length;
17894@@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17895 * nor set current_kprobe, because it doesn't use single
17896 * stepping.
17897 */
17898- regs->ip = (unsigned long)p->ainsn.insn;
17899+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17900 preempt_enable_no_resched();
17901 return;
17902 }
17903@@ -504,7 +511,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17904 if (p->opcode == BREAKPOINT_INSTRUCTION)
17905 regs->ip = (unsigned long)p->addr;
17906 else
17907- regs->ip = (unsigned long)p->ainsn.insn;
17908+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17909 }
17910
17911 /*
17912@@ -583,7 +590,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
17913 setup_singlestep(p, regs, kcb, 0);
17914 return 1;
17915 }
17916- } else if (*addr != BREAKPOINT_INSTRUCTION) {
17917+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
17918 /*
17919 * The breakpoint instruction was removed right
17920 * after we hit it. Another cpu has removed
17921@@ -628,6 +635,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
17922 " movq %rax, 152(%rsp)\n"
17923 RESTORE_REGS_STRING
17924 " popfq\n"
17925+#ifdef KERNEXEC_PLUGIN
17926+ " btsq $63,(%rsp)\n"
17927+#endif
17928 #else
17929 " pushf\n"
17930 SAVE_REGS_STRING
17931@@ -765,7 +775,7 @@ static void __kprobes
17932 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
17933 {
17934 unsigned long *tos = stack_addr(regs);
17935- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
17936+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
17937 unsigned long orig_ip = (unsigned long)p->addr;
17938 kprobe_opcode_t *insn = p->ainsn.insn;
17939
17940@@ -947,7 +957,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
17941 struct die_args *args = data;
17942 int ret = NOTIFY_DONE;
17943
17944- if (args->regs && user_mode_vm(args->regs))
17945+ if (args->regs && user_mode(args->regs))
17946 return ret;
17947
17948 switch (val) {
17949diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
17950index ebc9873..1b9724b 100644
17951--- a/arch/x86/kernel/ldt.c
17952+++ b/arch/x86/kernel/ldt.c
17953@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
17954 if (reload) {
17955 #ifdef CONFIG_SMP
17956 preempt_disable();
17957- load_LDT(pc);
17958+ load_LDT_nolock(pc);
17959 if (!cpumask_equal(mm_cpumask(current->mm),
17960 cpumask_of(smp_processor_id())))
17961 smp_call_function(flush_ldt, current->mm, 1);
17962 preempt_enable();
17963 #else
17964- load_LDT(pc);
17965+ load_LDT_nolock(pc);
17966 #endif
17967 }
17968 if (oldsize) {
17969@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
17970 return err;
17971
17972 for (i = 0; i < old->size; i++)
17973- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
17974+ write_ldt_entry(new->ldt, i, old->ldt + i);
17975 return 0;
17976 }
17977
17978@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
17979 retval = copy_ldt(&mm->context, &old_mm->context);
17980 mutex_unlock(&old_mm->context.lock);
17981 }
17982+
17983+ if (tsk == current) {
17984+ mm->context.vdso = 0;
17985+
17986+#ifdef CONFIG_X86_32
17987+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17988+ mm->context.user_cs_base = 0UL;
17989+ mm->context.user_cs_limit = ~0UL;
17990+
17991+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17992+ cpus_clear(mm->context.cpu_user_cs_mask);
17993+#endif
17994+
17995+#endif
17996+#endif
17997+
17998+ }
17999+
18000 return retval;
18001 }
18002
18003@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18004 }
18005 }
18006
18007+#ifdef CONFIG_PAX_SEGMEXEC
18008+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18009+ error = -EINVAL;
18010+ goto out_unlock;
18011+ }
18012+#endif
18013+
18014 fill_ldt(&ldt, &ldt_info);
18015 if (oldmode)
18016 ldt.avl = 0;
18017diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18018index 5b19e4d..6476a76 100644
18019--- a/arch/x86/kernel/machine_kexec_32.c
18020+++ b/arch/x86/kernel/machine_kexec_32.c
18021@@ -26,7 +26,7 @@
18022 #include <asm/cacheflush.h>
18023 #include <asm/debugreg.h>
18024
18025-static void set_idt(void *newidt, __u16 limit)
18026+static void set_idt(struct desc_struct *newidt, __u16 limit)
18027 {
18028 struct desc_ptr curidt;
18029
18030@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
18031 }
18032
18033
18034-static void set_gdt(void *newgdt, __u16 limit)
18035+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18036 {
18037 struct desc_ptr curgdt;
18038
18039@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
18040 }
18041
18042 control_page = page_address(image->control_code_page);
18043- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18044+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18045
18046 relocate_kernel_ptr = control_page;
18047 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18048diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18049index 0327e2b..e43737b 100644
18050--- a/arch/x86/kernel/microcode_intel.c
18051+++ b/arch/x86/kernel/microcode_intel.c
18052@@ -430,13 +430,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
18053
18054 static int get_ucode_user(void *to, const void *from, size_t n)
18055 {
18056- return copy_from_user(to, from, n);
18057+ return copy_from_user(to, (const void __force_user *)from, n);
18058 }
18059
18060 static enum ucode_state
18061 request_microcode_user(int cpu, const void __user *buf, size_t size)
18062 {
18063- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18064+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18065 }
18066
18067 static void microcode_fini_cpu(int cpu)
18068diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18069index f21fd94..61565cd 100644
18070--- a/arch/x86/kernel/module.c
18071+++ b/arch/x86/kernel/module.c
18072@@ -35,15 +35,60 @@
18073 #define DEBUGP(fmt...)
18074 #endif
18075
18076-void *module_alloc(unsigned long size)
18077+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18078 {
18079- if (PAGE_ALIGN(size) > MODULES_LEN)
18080+ if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18081 return NULL;
18082 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18083- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18084+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18085 -1, __builtin_return_address(0));
18086 }
18087
18088+void *module_alloc(unsigned long size)
18089+{
18090+
18091+#ifdef CONFIG_PAX_KERNEXEC
18092+ return __module_alloc(size, PAGE_KERNEL);
18093+#else
18094+ return __module_alloc(size, PAGE_KERNEL_EXEC);
18095+#endif
18096+
18097+}
18098+
18099+#ifdef CONFIG_PAX_KERNEXEC
18100+#ifdef CONFIG_X86_32
18101+void *module_alloc_exec(unsigned long size)
18102+{
18103+ struct vm_struct *area;
18104+
18105+ if (size == 0)
18106+ return NULL;
18107+
18108+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18109+ return area ? area->addr : NULL;
18110+}
18111+EXPORT_SYMBOL(module_alloc_exec);
18112+
18113+void module_free_exec(struct module *mod, void *module_region)
18114+{
18115+ vunmap(module_region);
18116+}
18117+EXPORT_SYMBOL(module_free_exec);
18118+#else
18119+void module_free_exec(struct module *mod, void *module_region)
18120+{
18121+ module_free(mod, module_region);
18122+}
18123+EXPORT_SYMBOL(module_free_exec);
18124+
18125+void *module_alloc_exec(unsigned long size)
18126+{
18127+ return __module_alloc(size, PAGE_KERNEL_RX);
18128+}
18129+EXPORT_SYMBOL(module_alloc_exec);
18130+#endif
18131+#endif
18132+
18133 #ifdef CONFIG_X86_32
18134 int apply_relocate(Elf32_Shdr *sechdrs,
18135 const char *strtab,
18136@@ -54,14 +99,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18137 unsigned int i;
18138 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18139 Elf32_Sym *sym;
18140- uint32_t *location;
18141+ uint32_t *plocation, location;
18142
18143 DEBUGP("Applying relocate section %u to %u\n", relsec,
18144 sechdrs[relsec].sh_info);
18145 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18146 /* This is where to make the change */
18147- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18148- + rel[i].r_offset;
18149+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18150+ location = (uint32_t)plocation;
18151+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18152+ plocation = ktla_ktva((void *)plocation);
18153 /* This is the symbol it is referring to. Note that all
18154 undefined symbols have been resolved. */
18155 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18156@@ -70,11 +117,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18157 switch (ELF32_R_TYPE(rel[i].r_info)) {
18158 case R_386_32:
18159 /* We add the value into the location given */
18160- *location += sym->st_value;
18161+ pax_open_kernel();
18162+ *plocation += sym->st_value;
18163+ pax_close_kernel();
18164 break;
18165 case R_386_PC32:
18166 /* Add the value, subtract its postition */
18167- *location += sym->st_value - (uint32_t)location;
18168+ pax_open_kernel();
18169+ *plocation += sym->st_value - location;
18170+ pax_close_kernel();
18171 break;
18172 default:
18173 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
18174@@ -119,21 +170,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18175 case R_X86_64_NONE:
18176 break;
18177 case R_X86_64_64:
18178+ pax_open_kernel();
18179 *(u64 *)loc = val;
18180+ pax_close_kernel();
18181 break;
18182 case R_X86_64_32:
18183+ pax_open_kernel();
18184 *(u32 *)loc = val;
18185+ pax_close_kernel();
18186 if (val != *(u32 *)loc)
18187 goto overflow;
18188 break;
18189 case R_X86_64_32S:
18190+ pax_open_kernel();
18191 *(s32 *)loc = val;
18192+ pax_close_kernel();
18193 if ((s64)val != *(s32 *)loc)
18194 goto overflow;
18195 break;
18196 case R_X86_64_PC32:
18197 val -= (u64)loc;
18198+ pax_open_kernel();
18199 *(u32 *)loc = val;
18200+ pax_close_kernel();
18201+
18202 #if 0
18203 if ((s64)val != *(s32 *)loc)
18204 goto overflow;
18205diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18206index a0b2f84..875ab81 100644
18207--- a/arch/x86/kernel/nmi.c
18208+++ b/arch/x86/kernel/nmi.c
18209@@ -460,6 +460,17 @@ static inline void nmi_nesting_postprocess(void)
18210 dotraplinkage notrace __kprobes void
18211 do_nmi(struct pt_regs *regs, long error_code)
18212 {
18213+
18214+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18215+ if (!user_mode(regs)) {
18216+ unsigned long cs = regs->cs & 0xFFFF;
18217+ unsigned long ip = ktva_ktla(regs->ip);
18218+
18219+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18220+ regs->ip = ip;
18221+ }
18222+#endif
18223+
18224 nmi_nesting_preprocess(regs);
18225
18226 nmi_enter();
18227diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18228index 676b8c7..870ba04 100644
18229--- a/arch/x86/kernel/paravirt-spinlocks.c
18230+++ b/arch/x86/kernel/paravirt-spinlocks.c
18231@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18232 arch_spin_lock(lock);
18233 }
18234
18235-struct pv_lock_ops pv_lock_ops = {
18236+struct pv_lock_ops pv_lock_ops __read_only = {
18237 #ifdef CONFIG_SMP
18238 .spin_is_locked = __ticket_spin_is_locked,
18239 .spin_is_contended = __ticket_spin_is_contended,
18240diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18241index 9ce8859..b49bf51 100644
18242--- a/arch/x86/kernel/paravirt.c
18243+++ b/arch/x86/kernel/paravirt.c
18244@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18245 {
18246 return x;
18247 }
18248+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18249+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18250+#endif
18251
18252 void __init default_banner(void)
18253 {
18254@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18255 if (opfunc == NULL)
18256 /* If there's no function, patch it with a ud2a (BUG) */
18257 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18258- else if (opfunc == _paravirt_nop)
18259+ else if (opfunc == (void *)_paravirt_nop)
18260 /* If the operation is a nop, then nop the callsite */
18261 ret = paravirt_patch_nop();
18262
18263 /* identity functions just return their single argument */
18264- else if (opfunc == _paravirt_ident_32)
18265+ else if (opfunc == (void *)_paravirt_ident_32)
18266 ret = paravirt_patch_ident_32(insnbuf, len);
18267- else if (opfunc == _paravirt_ident_64)
18268+ else if (opfunc == (void *)_paravirt_ident_64)
18269 ret = paravirt_patch_ident_64(insnbuf, len);
18270+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18271+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18272+ ret = paravirt_patch_ident_64(insnbuf, len);
18273+#endif
18274
18275 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18276 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18277@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18278 if (insn_len > len || start == NULL)
18279 insn_len = len;
18280 else
18281- memcpy(insnbuf, start, insn_len);
18282+ memcpy(insnbuf, ktla_ktva(start), insn_len);
18283
18284 return insn_len;
18285 }
18286@@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18287 preempt_enable();
18288 }
18289
18290-struct pv_info pv_info = {
18291+struct pv_info pv_info __read_only = {
18292 .name = "bare hardware",
18293 .paravirt_enabled = 0,
18294 .kernel_rpl = 0,
18295@@ -315,16 +322,16 @@ struct pv_info pv_info = {
18296 #endif
18297 };
18298
18299-struct pv_init_ops pv_init_ops = {
18300+struct pv_init_ops pv_init_ops __read_only = {
18301 .patch = native_patch,
18302 };
18303
18304-struct pv_time_ops pv_time_ops = {
18305+struct pv_time_ops pv_time_ops __read_only = {
18306 .sched_clock = native_sched_clock,
18307 .steal_clock = native_steal_clock,
18308 };
18309
18310-struct pv_irq_ops pv_irq_ops = {
18311+struct pv_irq_ops pv_irq_ops __read_only = {
18312 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18313 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18314 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18315@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18316 #endif
18317 };
18318
18319-struct pv_cpu_ops pv_cpu_ops = {
18320+struct pv_cpu_ops pv_cpu_ops __read_only = {
18321 .cpuid = native_cpuid,
18322 .get_debugreg = native_get_debugreg,
18323 .set_debugreg = native_set_debugreg,
18324@@ -397,21 +404,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18325 .end_context_switch = paravirt_nop,
18326 };
18327
18328-struct pv_apic_ops pv_apic_ops = {
18329+struct pv_apic_ops pv_apic_ops __read_only = {
18330 #ifdef CONFIG_X86_LOCAL_APIC
18331 .startup_ipi_hook = paravirt_nop,
18332 #endif
18333 };
18334
18335-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18336+#ifdef CONFIG_X86_32
18337+#ifdef CONFIG_X86_PAE
18338+/* 64-bit pagetable entries */
18339+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18340+#else
18341 /* 32-bit pagetable entries */
18342 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18343+#endif
18344 #else
18345 /* 64-bit pagetable entries */
18346 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18347 #endif
18348
18349-struct pv_mmu_ops pv_mmu_ops = {
18350+struct pv_mmu_ops pv_mmu_ops __read_only = {
18351
18352 .read_cr2 = native_read_cr2,
18353 .write_cr2 = native_write_cr2,
18354@@ -461,6 +473,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18355 .make_pud = PTE_IDENT,
18356
18357 .set_pgd = native_set_pgd,
18358+ .set_pgd_batched = native_set_pgd_batched,
18359 #endif
18360 #endif /* PAGETABLE_LEVELS >= 3 */
18361
18362@@ -480,6 +493,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18363 },
18364
18365 .set_fixmap = native_set_fixmap,
18366+
18367+#ifdef CONFIG_PAX_KERNEXEC
18368+ .pax_open_kernel = native_pax_open_kernel,
18369+ .pax_close_kernel = native_pax_close_kernel,
18370+#endif
18371+
18372 };
18373
18374 EXPORT_SYMBOL_GPL(pv_time_ops);
18375diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18376index 35ccf75..7a15747 100644
18377--- a/arch/x86/kernel/pci-iommu_table.c
18378+++ b/arch/x86/kernel/pci-iommu_table.c
18379@@ -2,7 +2,7 @@
18380 #include <asm/iommu_table.h>
18381 #include <linux/string.h>
18382 #include <linux/kallsyms.h>
18383-
18384+#include <linux/sched.h>
18385
18386 #define DEBUG 1
18387
18388diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18389index 735279e..5008677 100644
18390--- a/arch/x86/kernel/process.c
18391+++ b/arch/x86/kernel/process.c
18392@@ -34,7 +34,8 @@
18393 * section. Since TSS's are completely CPU-local, we want them
18394 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
18395 */
18396-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
18397+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
18398+EXPORT_SYMBOL(init_tss);
18399
18400 #ifdef CONFIG_X86_64
18401 static DEFINE_PER_CPU(unsigned char, is_idle);
18402@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
18403 task_xstate_cachep =
18404 kmem_cache_create("task_xstate", xstate_size,
18405 __alignof__(union thread_xstate),
18406- SLAB_PANIC | SLAB_NOTRACK, NULL);
18407+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18408 }
18409
18410 static inline void drop_fpu(struct task_struct *tsk)
18411@@ -115,7 +116,7 @@ void exit_thread(void)
18412 unsigned long *bp = t->io_bitmap_ptr;
18413
18414 if (bp) {
18415- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18416+ struct tss_struct *tss = init_tss + get_cpu();
18417
18418 t->io_bitmap_ptr = NULL;
18419 clear_thread_flag(TIF_IO_BITMAP);
18420@@ -147,7 +148,7 @@ void show_regs_common(void)
18421
18422 printk(KERN_CONT "\n");
18423 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
18424- current->pid, current->comm, print_tainted(),
18425+ task_pid_nr(current), current->comm, print_tainted(),
18426 init_utsname()->release,
18427 (int)strcspn(init_utsname()->version, " "),
18428 init_utsname()->version);
18429@@ -161,6 +162,9 @@ void flush_thread(void)
18430 {
18431 struct task_struct *tsk = current;
18432
18433+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18434+ loadsegment(gs, 0);
18435+#endif
18436 flush_ptrace_hw_breakpoint(tsk);
18437 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18438 drop_fpu(tsk);
18439@@ -318,10 +322,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18440 regs.di = (unsigned long) arg;
18441
18442 #ifdef CONFIG_X86_32
18443- regs.ds = __USER_DS;
18444- regs.es = __USER_DS;
18445+ regs.ds = __KERNEL_DS;
18446+ regs.es = __KERNEL_DS;
18447 regs.fs = __KERNEL_PERCPU;
18448- regs.gs = __KERNEL_STACK_CANARY;
18449+ savesegment(gs, regs.gs);
18450 #else
18451 regs.ss = __KERNEL_DS;
18452 #endif
18453@@ -407,7 +411,7 @@ static void __exit_idle(void)
18454 void exit_idle(void)
18455 {
18456 /* idle loop has pid 0 */
18457- if (current->pid)
18458+ if (task_pid_nr(current))
18459 return;
18460 __exit_idle();
18461 }
18462@@ -516,7 +520,7 @@ bool set_pm_idle_to_default(void)
18463
18464 return ret;
18465 }
18466-void stop_this_cpu(void *dummy)
18467+__noreturn void stop_this_cpu(void *dummy)
18468 {
18469 local_irq_disable();
18470 /*
18471@@ -746,16 +750,37 @@ static int __init idle_setup(char *str)
18472 }
18473 early_param("idle", idle_setup);
18474
18475-unsigned long arch_align_stack(unsigned long sp)
18476+#ifdef CONFIG_PAX_RANDKSTACK
18477+void pax_randomize_kstack(struct pt_regs *regs)
18478 {
18479- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18480- sp -= get_random_int() % 8192;
18481- return sp & ~0xf;
18482-}
18483+ struct thread_struct *thread = &current->thread;
18484+ unsigned long time;
18485
18486-unsigned long arch_randomize_brk(struct mm_struct *mm)
18487-{
18488- unsigned long range_end = mm->brk + 0x02000000;
18489- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18490-}
18491+ if (!randomize_va_space)
18492+ return;
18493+
18494+ if (v8086_mode(regs))
18495+ return;
18496
18497+ rdtscl(time);
18498+
18499+ /* P4 seems to return a 0 LSB, ignore it */
18500+#ifdef CONFIG_MPENTIUM4
18501+ time &= 0x3EUL;
18502+ time <<= 2;
18503+#elif defined(CONFIG_X86_64)
18504+ time &= 0xFUL;
18505+ time <<= 4;
18506+#else
18507+ time &= 0x1FUL;
18508+ time <<= 3;
18509+#endif
18510+
18511+ thread->sp0 ^= time;
18512+ load_sp0(init_tss + smp_processor_id(), thread);
18513+
18514+#ifdef CONFIG_X86_64
18515+ this_cpu_write(kernel_stack, thread->sp0);
18516+#endif
18517+}
18518+#endif
18519diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18520index 516fa18..80bd9e6 100644
18521--- a/arch/x86/kernel/process_32.c
18522+++ b/arch/x86/kernel/process_32.c
18523@@ -64,6 +64,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18524 unsigned long thread_saved_pc(struct task_struct *tsk)
18525 {
18526 return ((unsigned long *)tsk->thread.sp)[3];
18527+//XXX return tsk->thread.eip;
18528 }
18529
18530 void __show_regs(struct pt_regs *regs, int all)
18531@@ -73,15 +74,14 @@ void __show_regs(struct pt_regs *regs, int all)
18532 unsigned long sp;
18533 unsigned short ss, gs;
18534
18535- if (user_mode_vm(regs)) {
18536+ if (user_mode(regs)) {
18537 sp = regs->sp;
18538 ss = regs->ss & 0xffff;
18539- gs = get_user_gs(regs);
18540 } else {
18541 sp = kernel_stack_pointer(regs);
18542 savesegment(ss, ss);
18543- savesegment(gs, gs);
18544 }
18545+ gs = get_user_gs(regs);
18546
18547 show_regs_common();
18548
18549@@ -134,13 +134,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18550 struct task_struct *tsk;
18551 int err;
18552
18553- childregs = task_pt_regs(p);
18554+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18555 *childregs = *regs;
18556 childregs->ax = 0;
18557 childregs->sp = sp;
18558
18559 p->thread.sp = (unsigned long) childregs;
18560 p->thread.sp0 = (unsigned long) (childregs+1);
18561+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18562
18563 p->thread.ip = (unsigned long) ret_from_fork;
18564
18565@@ -231,7 +232,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18566 struct thread_struct *prev = &prev_p->thread,
18567 *next = &next_p->thread;
18568 int cpu = smp_processor_id();
18569- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18570+ struct tss_struct *tss = init_tss + cpu;
18571 fpu_switch_t fpu;
18572
18573 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18574@@ -255,6 +256,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18575 */
18576 lazy_save_gs(prev->gs);
18577
18578+#ifdef CONFIG_PAX_MEMORY_UDEREF
18579+ __set_fs(task_thread_info(next_p)->addr_limit);
18580+#endif
18581+
18582 /*
18583 * Load the per-thread Thread-Local Storage descriptor.
18584 */
18585@@ -285,6 +290,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18586 */
18587 arch_end_context_switch(next_p);
18588
18589+ this_cpu_write(current_task, next_p);
18590+ this_cpu_write(current_tinfo, &next_p->tinfo);
18591+
18592 /*
18593 * Restore %gs if needed (which is common)
18594 */
18595@@ -293,8 +301,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18596
18597 switch_fpu_finish(next_p, fpu);
18598
18599- this_cpu_write(current_task, next_p);
18600-
18601 return prev_p;
18602 }
18603
18604@@ -324,4 +330,3 @@ unsigned long get_wchan(struct task_struct *p)
18605 } while (count++ < 16);
18606 return 0;
18607 }
18608-
18609diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18610index 61cdf7f..797f06a 100644
18611--- a/arch/x86/kernel/process_64.c
18612+++ b/arch/x86/kernel/process_64.c
18613@@ -153,8 +153,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18614 struct pt_regs *childregs;
18615 struct task_struct *me = current;
18616
18617- childregs = ((struct pt_regs *)
18618- (THREAD_SIZE + task_stack_page(p))) - 1;
18619+ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18620 *childregs = *regs;
18621
18622 childregs->ax = 0;
18623@@ -166,6 +165,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18624 p->thread.sp = (unsigned long) childregs;
18625 p->thread.sp0 = (unsigned long) (childregs+1);
18626 p->thread.usersp = me->thread.usersp;
18627+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18628
18629 set_tsk_thread_flag(p, TIF_FORK);
18630
18631@@ -271,7 +271,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18632 struct thread_struct *prev = &prev_p->thread;
18633 struct thread_struct *next = &next_p->thread;
18634 int cpu = smp_processor_id();
18635- struct tss_struct *tss = &per_cpu(init_tss, cpu);
18636+ struct tss_struct *tss = init_tss + cpu;
18637 unsigned fsindex, gsindex;
18638 fpu_switch_t fpu;
18639
18640@@ -353,10 +353,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18641 prev->usersp = this_cpu_read(old_rsp);
18642 this_cpu_write(old_rsp, next->usersp);
18643 this_cpu_write(current_task, next_p);
18644+ this_cpu_write(current_tinfo, &next_p->tinfo);
18645
18646- this_cpu_write(kernel_stack,
18647- (unsigned long)task_stack_page(next_p) +
18648- THREAD_SIZE - KERNEL_STACK_OFFSET);
18649+ this_cpu_write(kernel_stack, next->sp0);
18650
18651 /*
18652 * Now maybe reload the debug registers and handle I/O bitmaps
18653@@ -425,12 +424,11 @@ unsigned long get_wchan(struct task_struct *p)
18654 if (!p || p == current || p->state == TASK_RUNNING)
18655 return 0;
18656 stack = (unsigned long)task_stack_page(p);
18657- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18658+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18659 return 0;
18660 fp = *(u64 *)(p->thread.sp);
18661 do {
18662- if (fp < (unsigned long)stack ||
18663- fp >= (unsigned long)stack+THREAD_SIZE)
18664+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18665 return 0;
18666 ip = *(u64 *)(fp+8);
18667 if (!in_sched_functions(ip))
18668diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18669index c4c6a5c..905f440 100644
18670--- a/arch/x86/kernel/ptrace.c
18671+++ b/arch/x86/kernel/ptrace.c
18672@@ -824,7 +824,7 @@ long arch_ptrace(struct task_struct *child, long request,
18673 unsigned long addr, unsigned long data)
18674 {
18675 int ret;
18676- unsigned long __user *datap = (unsigned long __user *)data;
18677+ unsigned long __user *datap = (__force unsigned long __user *)data;
18678
18679 switch (request) {
18680 /* read the word at location addr in the USER area. */
18681@@ -909,14 +909,14 @@ long arch_ptrace(struct task_struct *child, long request,
18682 if ((int) addr < 0)
18683 return -EIO;
18684 ret = do_get_thread_area(child, addr,
18685- (struct user_desc __user *)data);
18686+ (__force struct user_desc __user *) data);
18687 break;
18688
18689 case PTRACE_SET_THREAD_AREA:
18690 if ((int) addr < 0)
18691 return -EIO;
18692 ret = do_set_thread_area(child, addr,
18693- (struct user_desc __user *)data, 0);
18694+ (__force struct user_desc __user *) data, 0);
18695 break;
18696 #endif
18697
18698@@ -1426,7 +1426,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18699 memset(info, 0, sizeof(*info));
18700 info->si_signo = SIGTRAP;
18701 info->si_code = si_code;
18702- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18703+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18704 }
18705
18706 void user_single_step_siginfo(struct task_struct *tsk,
18707@@ -1455,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18708 # define IS_IA32 0
18709 #endif
18710
18711+#ifdef CONFIG_GRKERNSEC_SETXID
18712+extern void gr_delayed_cred_worker(void);
18713+#endif
18714+
18715 /*
18716 * We must return the syscall number to actually look up in the table.
18717 * This can be -1L to skip running any syscall at all.
18718@@ -1463,6 +1467,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18719 {
18720 long ret = 0;
18721
18722+#ifdef CONFIG_GRKERNSEC_SETXID
18723+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18724+ gr_delayed_cred_worker();
18725+#endif
18726+
18727 /*
18728 * If we stepped into a sysenter/syscall insn, it trapped in
18729 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18730@@ -1511,6 +1520,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18731 {
18732 bool step;
18733
18734+#ifdef CONFIG_GRKERNSEC_SETXID
18735+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18736+ gr_delayed_cred_worker();
18737+#endif
18738+
18739 audit_syscall_exit(regs);
18740
18741 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18742diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18743index 42eb330..139955c 100644
18744--- a/arch/x86/kernel/pvclock.c
18745+++ b/arch/x86/kernel/pvclock.c
18746@@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18747 return pv_tsc_khz;
18748 }
18749
18750-static atomic64_t last_value = ATOMIC64_INIT(0);
18751+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18752
18753 void pvclock_resume(void)
18754 {
18755- atomic64_set(&last_value, 0);
18756+ atomic64_set_unchecked(&last_value, 0);
18757 }
18758
18759 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18760@@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18761 * updating at the same time, and one of them could be slightly behind,
18762 * making the assumption that last_value always go forward fail to hold.
18763 */
18764- last = atomic64_read(&last_value);
18765+ last = atomic64_read_unchecked(&last_value);
18766 do {
18767 if (ret < last)
18768 return last;
18769- last = atomic64_cmpxchg(&last_value, last, ret);
18770+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18771 } while (unlikely(last != ret));
18772
18773 return ret;
18774diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18775index 5de92f1..2732385 100644
18776--- a/arch/x86/kernel/reboot.c
18777+++ b/arch/x86/kernel/reboot.c
18778@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
18779 EXPORT_SYMBOL(pm_power_off);
18780
18781 static const struct desc_ptr no_idt = {};
18782-static int reboot_mode;
18783+static unsigned short reboot_mode;
18784 enum reboot_type reboot_type = BOOT_ACPI;
18785 int reboot_force;
18786
18787@@ -157,11 +157,15 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
18788 return 0;
18789 }
18790
18791-void machine_real_restart(unsigned int type)
18792+__noreturn void machine_real_restart(unsigned int type)
18793 {
18794- void (*restart_lowmem)(unsigned int) = (void (*)(unsigned int))
18795+ void (* restart_lowmem)(unsigned int) = (void (*)(unsigned int))
18796 real_mode_header->machine_real_restart_asm;
18797
18798+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18799+ struct desc_struct *gdt;
18800+#endif
18801+
18802 local_irq_disable();
18803
18804 /*
18805@@ -189,10 +193,36 @@ void machine_real_restart(unsigned int type)
18806 * boot)". This seems like a fairly standard thing that gets set by
18807 * REBOOT.COM programs, and the previous reset routine did this
18808 * too. */
18809- *((unsigned short *)0x472) = reboot_mode;
18810+ *(unsigned short *)(__va(0x472)) = reboot_mode;
18811
18812 /* Jump to the identity-mapped low memory code */
18813+
18814+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18815+ gdt = get_cpu_gdt_table(smp_processor_id());
18816+ pax_open_kernel();
18817+#ifdef CONFIG_PAX_MEMORY_UDEREF
18818+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18819+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18820+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
18821+#endif
18822+#ifdef CONFIG_PAX_KERNEXEC
18823+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18824+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18825+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18826+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18827+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18828+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18829+#endif
18830+ pax_close_kernel();
18831+#endif
18832+
18833+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18834+ asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
18835+ unreachable();
18836+#else
18837 restart_lowmem(type);
18838+#endif
18839+
18840 }
18841 #ifdef CONFIG_APM_MODULE
18842 EXPORT_SYMBOL(machine_real_restart);
18843@@ -543,7 +573,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18844 * try to force a triple fault and then cycle between hitting the keyboard
18845 * controller and doing that
18846 */
18847-static void native_machine_emergency_restart(void)
18848+__noreturn static void native_machine_emergency_restart(void)
18849 {
18850 int i;
18851 int attempt = 0;
18852@@ -670,13 +700,13 @@ void native_machine_shutdown(void)
18853 #endif
18854 }
18855
18856-static void __machine_emergency_restart(int emergency)
18857+static __noreturn void __machine_emergency_restart(int emergency)
18858 {
18859 reboot_emergency = emergency;
18860 machine_ops.emergency_restart();
18861 }
18862
18863-static void native_machine_restart(char *__unused)
18864+static __noreturn void native_machine_restart(char *__unused)
18865 {
18866 printk("machine restart\n");
18867
18868@@ -685,7 +715,7 @@ static void native_machine_restart(char *__unused)
18869 __machine_emergency_restart(0);
18870 }
18871
18872-static void native_machine_halt(void)
18873+static __noreturn void native_machine_halt(void)
18874 {
18875 /* Stop other cpus and apics */
18876 machine_shutdown();
18877@@ -695,7 +725,7 @@ static void native_machine_halt(void)
18878 stop_this_cpu(NULL);
18879 }
18880
18881-static void native_machine_power_off(void)
18882+__noreturn static void native_machine_power_off(void)
18883 {
18884 if (pm_power_off) {
18885 if (!reboot_force)
18886@@ -704,6 +734,7 @@ static void native_machine_power_off(void)
18887 }
18888 /* A fallback in case there is no PM info available */
18889 tboot_shutdown(TB_SHUTDOWN_HALT);
18890+ unreachable();
18891 }
18892
18893 struct machine_ops machine_ops = {
18894diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
18895index 7a6f3b3..bed145d7 100644
18896--- a/arch/x86/kernel/relocate_kernel_64.S
18897+++ b/arch/x86/kernel/relocate_kernel_64.S
18898@@ -11,6 +11,7 @@
18899 #include <asm/kexec.h>
18900 #include <asm/processor-flags.h>
18901 #include <asm/pgtable_types.h>
18902+#include <asm/alternative-asm.h>
18903
18904 /*
18905 * Must be relocatable PIC code callable as a C function
18906@@ -160,13 +161,14 @@ identity_mapped:
18907 xorq %rbp, %rbp
18908 xorq %r8, %r8
18909 xorq %r9, %r9
18910- xorq %r10, %r9
18911+ xorq %r10, %r10
18912 xorq %r11, %r11
18913 xorq %r12, %r12
18914 xorq %r13, %r13
18915 xorq %r14, %r14
18916 xorq %r15, %r15
18917
18918+ pax_force_retaddr 0, 1
18919 ret
18920
18921 1:
18922diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
18923index 16be6dc..4686132 100644
18924--- a/arch/x86/kernel/setup.c
18925+++ b/arch/x86/kernel/setup.c
18926@@ -440,7 +440,7 @@ static void __init parse_setup_data(void)
18927
18928 switch (data->type) {
18929 case SETUP_E820_EXT:
18930- parse_e820_ext(data);
18931+ parse_e820_ext((struct setup_data __force_kernel *)data);
18932 break;
18933 case SETUP_DTB:
18934 add_dtb(pa_data);
18935@@ -632,7 +632,7 @@ static void __init trim_bios_range(void)
18936 * area (640->1Mb) as ram even though it is not.
18937 * take them out.
18938 */
18939- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
18940+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
18941 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
18942 }
18943
18944@@ -755,14 +755,14 @@ void __init setup_arch(char **cmdline_p)
18945
18946 if (!boot_params.hdr.root_flags)
18947 root_mountflags &= ~MS_RDONLY;
18948- init_mm.start_code = (unsigned long) _text;
18949- init_mm.end_code = (unsigned long) _etext;
18950+ init_mm.start_code = ktla_ktva((unsigned long) _text);
18951+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
18952 init_mm.end_data = (unsigned long) _edata;
18953 init_mm.brk = _brk_end;
18954
18955- code_resource.start = virt_to_phys(_text);
18956- code_resource.end = virt_to_phys(_etext)-1;
18957- data_resource.start = virt_to_phys(_etext);
18958+ code_resource.start = virt_to_phys(ktla_ktva(_text));
18959+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
18960+ data_resource.start = virt_to_phys(_sdata);
18961 data_resource.end = virt_to_phys(_edata)-1;
18962 bss_resource.start = virt_to_phys(&__bss_start);
18963 bss_resource.end = virt_to_phys(&__bss_stop)-1;
18964diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
18965index 5a98aa2..2f9288d 100644
18966--- a/arch/x86/kernel/setup_percpu.c
18967+++ b/arch/x86/kernel/setup_percpu.c
18968@@ -21,19 +21,17 @@
18969 #include <asm/cpu.h>
18970 #include <asm/stackprotector.h>
18971
18972-DEFINE_PER_CPU(int, cpu_number);
18973+#ifdef CONFIG_SMP
18974+DEFINE_PER_CPU(unsigned int, cpu_number);
18975 EXPORT_PER_CPU_SYMBOL(cpu_number);
18976+#endif
18977
18978-#ifdef CONFIG_X86_64
18979 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
18980-#else
18981-#define BOOT_PERCPU_OFFSET 0
18982-#endif
18983
18984 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
18985 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
18986
18987-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
18988+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
18989 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
18990 };
18991 EXPORT_SYMBOL(__per_cpu_offset);
18992@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
18993 {
18994 #ifdef CONFIG_X86_32
18995 struct desc_struct gdt;
18996+ unsigned long base = per_cpu_offset(cpu);
18997
18998- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
18999- 0x2 | DESCTYPE_S, 0x8);
19000- gdt.s = 1;
19001+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19002+ 0x83 | DESCTYPE_S, 0xC);
19003 write_gdt_entry(get_cpu_gdt_table(cpu),
19004 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19005 #endif
19006@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
19007 /* alrighty, percpu areas up and running */
19008 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19009 for_each_possible_cpu(cpu) {
19010+#ifdef CONFIG_CC_STACKPROTECTOR
19011+#ifdef CONFIG_X86_32
19012+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
19013+#endif
19014+#endif
19015 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19016 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19017 per_cpu(cpu_number, cpu) = cpu;
19018@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
19019 */
19020 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
19021 #endif
19022+#ifdef CONFIG_CC_STACKPROTECTOR
19023+#ifdef CONFIG_X86_32
19024+ if (!cpu)
19025+ per_cpu(stack_canary.canary, cpu) = canary;
19026+#endif
19027+#endif
19028 /*
19029 * Up to this point, the boot CPU has been using .init.data
19030 * area. Reload any changed state for the boot CPU.
19031diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19032index 21af737..fb45e22 100644
19033--- a/arch/x86/kernel/signal.c
19034+++ b/arch/x86/kernel/signal.c
19035@@ -191,7 +191,7 @@ static unsigned long align_sigframe(unsigned long sp)
19036 * Align the stack pointer according to the i386 ABI,
19037 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19038 */
19039- sp = ((sp + 4) & -16ul) - 4;
19040+ sp = ((sp - 12) & -16ul) - 4;
19041 #else /* !CONFIG_X86_32 */
19042 sp = round_down(sp, 16) - 8;
19043 #endif
19044@@ -242,11 +242,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
19045 * Return an always-bogus address instead so we will die with SIGSEGV.
19046 */
19047 if (onsigstack && !likely(on_sig_stack(sp)))
19048- return (void __user *)-1L;
19049+ return (__force void __user *)-1L;
19050
19051 /* save i387 state */
19052 if (used_math() && save_i387_xstate(*fpstate) < 0)
19053- return (void __user *)-1L;
19054+ return (__force void __user *)-1L;
19055
19056 return (void __user *)sp;
19057 }
19058@@ -301,9 +301,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19059 }
19060
19061 if (current->mm->context.vdso)
19062- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19063+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19064 else
19065- restorer = &frame->retcode;
19066+ restorer = (void __user *)&frame->retcode;
19067 if (ka->sa.sa_flags & SA_RESTORER)
19068 restorer = ka->sa.sa_restorer;
19069
19070@@ -317,7 +317,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19071 * reasons and because gdb uses it as a signature to notice
19072 * signal handler stack frames.
19073 */
19074- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19075+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19076
19077 if (err)
19078 return -EFAULT;
19079@@ -371,7 +371,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19080 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19081
19082 /* Set up to return from userspace. */
19083- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19084+ if (current->mm->context.vdso)
19085+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19086+ else
19087+ restorer = (void __user *)&frame->retcode;
19088 if (ka->sa.sa_flags & SA_RESTORER)
19089 restorer = ka->sa.sa_restorer;
19090 put_user_ex(restorer, &frame->pretcode);
19091@@ -383,7 +386,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19092 * reasons and because gdb uses it as a signature to notice
19093 * signal handler stack frames.
19094 */
19095- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19096+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19097 } put_user_catch(err);
19098
19099 if (err)
19100diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19101index 7bd8a08..2659b5b 100644
19102--- a/arch/x86/kernel/smpboot.c
19103+++ b/arch/x86/kernel/smpboot.c
19104@@ -679,6 +679,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19105 idle->thread.sp = (unsigned long) (((struct pt_regs *)
19106 (THREAD_SIZE + task_stack_page(idle))) - 1);
19107 per_cpu(current_task, cpu) = idle;
19108+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
19109
19110 #ifdef CONFIG_X86_32
19111 /* Stack for startup_32 can be just as for start_secondary onwards */
19112@@ -686,11 +687,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19113 #else
19114 clear_tsk_thread_flag(idle, TIF_FORK);
19115 initial_gs = per_cpu_offset(cpu);
19116- per_cpu(kernel_stack, cpu) =
19117- (unsigned long)task_stack_page(idle) -
19118- KERNEL_STACK_OFFSET + THREAD_SIZE;
19119+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
19120 #endif
19121+
19122+ pax_open_kernel();
19123 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19124+ pax_close_kernel();
19125+
19126 initial_code = (unsigned long)start_secondary;
19127 stack_start = idle->thread.sp;
19128
19129@@ -826,6 +829,12 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
19130
19131 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19132
19133+#ifdef CONFIG_PAX_PER_CPU_PGD
19134+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19135+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19136+ KERNEL_PGD_PTRS);
19137+#endif
19138+
19139 err = do_boot_cpu(apicid, cpu, tidle);
19140 if (err) {
19141 pr_debug("do_boot_cpu failed %d\n", err);
19142diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19143index c346d11..d43b163 100644
19144--- a/arch/x86/kernel/step.c
19145+++ b/arch/x86/kernel/step.c
19146@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19147 struct desc_struct *desc;
19148 unsigned long base;
19149
19150- seg &= ~7UL;
19151+ seg >>= 3;
19152
19153 mutex_lock(&child->mm->context.lock);
19154- if (unlikely((seg >> 3) >= child->mm->context.size))
19155+ if (unlikely(seg >= child->mm->context.size))
19156 addr = -1L; /* bogus selector, access would fault */
19157 else {
19158 desc = child->mm->context.ldt + seg;
19159@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19160 addr += base;
19161 }
19162 mutex_unlock(&child->mm->context.lock);
19163- }
19164+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19165+ addr = ktla_ktva(addr);
19166
19167 return addr;
19168 }
19169@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19170 unsigned char opcode[15];
19171 unsigned long addr = convert_ip_to_linear(child, regs);
19172
19173+ if (addr == -EINVAL)
19174+ return 0;
19175+
19176 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19177 for (i = 0; i < copied; i++) {
19178 switch (opcode[i]) {
19179diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19180index 0b0cb5f..db6b9ed 100644
19181--- a/arch/x86/kernel/sys_i386_32.c
19182+++ b/arch/x86/kernel/sys_i386_32.c
19183@@ -24,17 +24,224 @@
19184
19185 #include <asm/syscalls.h>
19186
19187-/*
19188- * Do a system call from kernel instead of calling sys_execve so we
19189- * end up with proper pt_regs.
19190- */
19191-int kernel_execve(const char *filename,
19192- const char *const argv[],
19193- const char *const envp[])
19194+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19195 {
19196- long __res;
19197- asm volatile ("int $0x80"
19198- : "=a" (__res)
19199- : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19200- return __res;
19201+ unsigned long pax_task_size = TASK_SIZE;
19202+
19203+#ifdef CONFIG_PAX_SEGMEXEC
19204+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19205+ pax_task_size = SEGMEXEC_TASK_SIZE;
19206+#endif
19207+
19208+ if (len > pax_task_size || addr > pax_task_size - len)
19209+ return -EINVAL;
19210+
19211+ return 0;
19212+}
19213+
19214+unsigned long
19215+arch_get_unmapped_area(struct file *filp, unsigned long addr,
19216+ unsigned long len, unsigned long pgoff, unsigned long flags)
19217+{
19218+ struct mm_struct *mm = current->mm;
19219+ struct vm_area_struct *vma;
19220+ unsigned long start_addr, pax_task_size = TASK_SIZE;
19221+
19222+#ifdef CONFIG_PAX_SEGMEXEC
19223+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19224+ pax_task_size = SEGMEXEC_TASK_SIZE;
19225+#endif
19226+
19227+ pax_task_size -= PAGE_SIZE;
19228+
19229+ if (len > pax_task_size)
19230+ return -ENOMEM;
19231+
19232+ if (flags & MAP_FIXED)
19233+ return addr;
19234+
19235+#ifdef CONFIG_PAX_RANDMMAP
19236+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19237+#endif
19238+
19239+ if (addr) {
19240+ addr = PAGE_ALIGN(addr);
19241+ if (pax_task_size - len >= addr) {
19242+ vma = find_vma(mm, addr);
19243+ if (check_heap_stack_gap(vma, addr, len))
19244+ return addr;
19245+ }
19246+ }
19247+ if (len > mm->cached_hole_size) {
19248+ start_addr = addr = mm->free_area_cache;
19249+ } else {
19250+ start_addr = addr = mm->mmap_base;
19251+ mm->cached_hole_size = 0;
19252+ }
19253+
19254+#ifdef CONFIG_PAX_PAGEEXEC
19255+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19256+ start_addr = 0x00110000UL;
19257+
19258+#ifdef CONFIG_PAX_RANDMMAP
19259+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19260+ start_addr += mm->delta_mmap & 0x03FFF000UL;
19261+#endif
19262+
19263+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19264+ start_addr = addr = mm->mmap_base;
19265+ else
19266+ addr = start_addr;
19267+ }
19268+#endif
19269+
19270+full_search:
19271+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19272+ /* At this point: (!vma || addr < vma->vm_end). */
19273+ if (pax_task_size - len < addr) {
19274+ /*
19275+ * Start a new search - just in case we missed
19276+ * some holes.
19277+ */
19278+ if (start_addr != mm->mmap_base) {
19279+ start_addr = addr = mm->mmap_base;
19280+ mm->cached_hole_size = 0;
19281+ goto full_search;
19282+ }
19283+ return -ENOMEM;
19284+ }
19285+ if (check_heap_stack_gap(vma, addr, len))
19286+ break;
19287+ if (addr + mm->cached_hole_size < vma->vm_start)
19288+ mm->cached_hole_size = vma->vm_start - addr;
19289+ addr = vma->vm_end;
19290+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
19291+ start_addr = addr = mm->mmap_base;
19292+ mm->cached_hole_size = 0;
19293+ goto full_search;
19294+ }
19295+ }
19296+
19297+ /*
19298+ * Remember the place where we stopped the search:
19299+ */
19300+ mm->free_area_cache = addr + len;
19301+ return addr;
19302+}
19303+
19304+unsigned long
19305+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19306+ const unsigned long len, const unsigned long pgoff,
19307+ const unsigned long flags)
19308+{
19309+ struct vm_area_struct *vma;
19310+ struct mm_struct *mm = current->mm;
19311+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19312+
19313+#ifdef CONFIG_PAX_SEGMEXEC
19314+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19315+ pax_task_size = SEGMEXEC_TASK_SIZE;
19316+#endif
19317+
19318+ pax_task_size -= PAGE_SIZE;
19319+
19320+ /* requested length too big for entire address space */
19321+ if (len > pax_task_size)
19322+ return -ENOMEM;
19323+
19324+ if (flags & MAP_FIXED)
19325+ return addr;
19326+
19327+#ifdef CONFIG_PAX_PAGEEXEC
19328+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19329+ goto bottomup;
19330+#endif
19331+
19332+#ifdef CONFIG_PAX_RANDMMAP
19333+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19334+#endif
19335+
19336+ /* requesting a specific address */
19337+ if (addr) {
19338+ addr = PAGE_ALIGN(addr);
19339+ if (pax_task_size - len >= addr) {
19340+ vma = find_vma(mm, addr);
19341+ if (check_heap_stack_gap(vma, addr, len))
19342+ return addr;
19343+ }
19344+ }
19345+
19346+ /* check if free_area_cache is useful for us */
19347+ if (len <= mm->cached_hole_size) {
19348+ mm->cached_hole_size = 0;
19349+ mm->free_area_cache = mm->mmap_base;
19350+ }
19351+
19352+ /* either no address requested or can't fit in requested address hole */
19353+ addr = mm->free_area_cache;
19354+
19355+ /* make sure it can fit in the remaining address space */
19356+ if (addr > len) {
19357+ vma = find_vma(mm, addr-len);
19358+ if (check_heap_stack_gap(vma, addr - len, len))
19359+ /* remember the address as a hint for next time */
19360+ return (mm->free_area_cache = addr-len);
19361+ }
19362+
19363+ if (mm->mmap_base < len)
19364+ goto bottomup;
19365+
19366+ addr = mm->mmap_base-len;
19367+
19368+ do {
19369+ /*
19370+ * Lookup failure means no vma is above this address,
19371+ * else if new region fits below vma->vm_start,
19372+ * return with success:
19373+ */
19374+ vma = find_vma(mm, addr);
19375+ if (check_heap_stack_gap(vma, addr, len))
19376+ /* remember the address as a hint for next time */
19377+ return (mm->free_area_cache = addr);
19378+
19379+ /* remember the largest hole we saw so far */
19380+ if (addr + mm->cached_hole_size < vma->vm_start)
19381+ mm->cached_hole_size = vma->vm_start - addr;
19382+
19383+ /* try just below the current vma->vm_start */
19384+ addr = skip_heap_stack_gap(vma, len);
19385+ } while (!IS_ERR_VALUE(addr));
19386+
19387+bottomup:
19388+ /*
19389+ * A failed mmap() very likely causes application failure,
19390+ * so fall back to the bottom-up function here. This scenario
19391+ * can happen with large stack limits and large mmap()
19392+ * allocations.
19393+ */
19394+
19395+#ifdef CONFIG_PAX_SEGMEXEC
19396+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
19397+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19398+ else
19399+#endif
19400+
19401+ mm->mmap_base = TASK_UNMAPPED_BASE;
19402+
19403+#ifdef CONFIG_PAX_RANDMMAP
19404+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19405+ mm->mmap_base += mm->delta_mmap;
19406+#endif
19407+
19408+ mm->free_area_cache = mm->mmap_base;
19409+ mm->cached_hole_size = ~0UL;
19410+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19411+ /*
19412+ * Restore the topdown base:
19413+ */
19414+ mm->mmap_base = base;
19415+ mm->free_area_cache = base;
19416+ mm->cached_hole_size = ~0UL;
19417+
19418+ return addr;
19419 }
19420diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19421index b4d3c39..82bb73b 100644
19422--- a/arch/x86/kernel/sys_x86_64.c
19423+++ b/arch/x86/kernel/sys_x86_64.c
19424@@ -95,8 +95,8 @@ out:
19425 return error;
19426 }
19427
19428-static void find_start_end(unsigned long flags, unsigned long *begin,
19429- unsigned long *end)
19430+static void find_start_end(struct mm_struct *mm, unsigned long flags,
19431+ unsigned long *begin, unsigned long *end)
19432 {
19433 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19434 unsigned long new_begin;
19435@@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19436 *begin = new_begin;
19437 }
19438 } else {
19439- *begin = TASK_UNMAPPED_BASE;
19440+ *begin = mm->mmap_base;
19441 *end = TASK_SIZE;
19442 }
19443 }
19444@@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19445 if (flags & MAP_FIXED)
19446 return addr;
19447
19448- find_start_end(flags, &begin, &end);
19449+ find_start_end(mm, flags, &begin, &end);
19450
19451 if (len > end)
19452 return -ENOMEM;
19453
19454+#ifdef CONFIG_PAX_RANDMMAP
19455+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19456+#endif
19457+
19458 if (addr) {
19459 addr = PAGE_ALIGN(addr);
19460 vma = find_vma(mm, addr);
19461- if (end - len >= addr &&
19462- (!vma || addr + len <= vma->vm_start))
19463+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19464 return addr;
19465 }
19466 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19467@@ -172,7 +175,7 @@ full_search:
19468 }
19469 return -ENOMEM;
19470 }
19471- if (!vma || addr + len <= vma->vm_start) {
19472+ if (check_heap_stack_gap(vma, addr, len)) {
19473 /*
19474 * Remember the place where we stopped the search:
19475 */
19476@@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19477 {
19478 struct vm_area_struct *vma;
19479 struct mm_struct *mm = current->mm;
19480- unsigned long addr = addr0, start_addr;
19481+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19482
19483 /* requested length too big for entire address space */
19484 if (len > TASK_SIZE)
19485@@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19486 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19487 goto bottomup;
19488
19489+#ifdef CONFIG_PAX_RANDMMAP
19490+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19491+#endif
19492+
19493 /* requesting a specific address */
19494 if (addr) {
19495 addr = PAGE_ALIGN(addr);
19496- vma = find_vma(mm, addr);
19497- if (TASK_SIZE - len >= addr &&
19498- (!vma || addr + len <= vma->vm_start))
19499- return addr;
19500+ if (TASK_SIZE - len >= addr) {
19501+ vma = find_vma(mm, addr);
19502+ if (check_heap_stack_gap(vma, addr, len))
19503+ return addr;
19504+ }
19505 }
19506
19507 /* check if free_area_cache is useful for us */
19508@@ -240,7 +248,7 @@ try_again:
19509 * return with success:
19510 */
19511 vma = find_vma(mm, addr);
19512- if (!vma || addr+len <= vma->vm_start)
19513+ if (check_heap_stack_gap(vma, addr, len))
19514 /* remember the address as a hint for next time */
19515 return mm->free_area_cache = addr;
19516
19517@@ -249,8 +257,8 @@ try_again:
19518 mm->cached_hole_size = vma->vm_start - addr;
19519
19520 /* try just below the current vma->vm_start */
19521- addr = vma->vm_start-len;
19522- } while (len < vma->vm_start);
19523+ addr = skip_heap_stack_gap(vma, len);
19524+ } while (!IS_ERR_VALUE(addr));
19525
19526 fail:
19527 /*
19528@@ -270,13 +278,21 @@ bottomup:
19529 * can happen with large stack limits and large mmap()
19530 * allocations.
19531 */
19532+ mm->mmap_base = TASK_UNMAPPED_BASE;
19533+
19534+#ifdef CONFIG_PAX_RANDMMAP
19535+ if (mm->pax_flags & MF_PAX_RANDMMAP)
19536+ mm->mmap_base += mm->delta_mmap;
19537+#endif
19538+
19539+ mm->free_area_cache = mm->mmap_base;
19540 mm->cached_hole_size = ~0UL;
19541- mm->free_area_cache = TASK_UNMAPPED_BASE;
19542 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19543 /*
19544 * Restore the topdown base:
19545 */
19546- mm->free_area_cache = mm->mmap_base;
19547+ mm->mmap_base = base;
19548+ mm->free_area_cache = base;
19549 mm->cached_hole_size = ~0UL;
19550
19551 return addr;
19552diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19553index f84fe00..93fe08f 100644
19554--- a/arch/x86/kernel/tboot.c
19555+++ b/arch/x86/kernel/tboot.c
19556@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
19557
19558 void tboot_shutdown(u32 shutdown_type)
19559 {
19560- void (*shutdown)(void);
19561+ void (* __noreturn shutdown)(void);
19562
19563 if (!tboot_enabled())
19564 return;
19565@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
19566
19567 switch_to_tboot_pt();
19568
19569- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19570+ shutdown = (void *)tboot->shutdown_entry;
19571 shutdown();
19572
19573 /* should not reach here */
19574@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19575 return 0;
19576 }
19577
19578-static atomic_t ap_wfs_count;
19579+static atomic_unchecked_t ap_wfs_count;
19580
19581 static int tboot_wait_for_aps(int num_aps)
19582 {
19583@@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19584 {
19585 switch (action) {
19586 case CPU_DYING:
19587- atomic_inc(&ap_wfs_count);
19588+ atomic_inc_unchecked(&ap_wfs_count);
19589 if (num_online_cpus() == 1)
19590- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19591+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19592 return NOTIFY_BAD;
19593 break;
19594 }
19595@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
19596
19597 tboot_create_trampoline();
19598
19599- atomic_set(&ap_wfs_count, 0);
19600+ atomic_set_unchecked(&ap_wfs_count, 0);
19601 register_hotcpu_notifier(&tboot_cpu_notifier);
19602
19603 acpi_os_set_prepare_sleep(&tboot_sleep);
19604diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19605index 24d3c91..d06b473 100644
19606--- a/arch/x86/kernel/time.c
19607+++ b/arch/x86/kernel/time.c
19608@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19609 {
19610 unsigned long pc = instruction_pointer(regs);
19611
19612- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19613+ if (!user_mode(regs) && in_lock_functions(pc)) {
19614 #ifdef CONFIG_FRAME_POINTER
19615- return *(unsigned long *)(regs->bp + sizeof(long));
19616+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19617 #else
19618 unsigned long *sp =
19619 (unsigned long *)kernel_stack_pointer(regs);
19620@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19621 * or above a saved flags. Eflags has bits 22-31 zero,
19622 * kernel addresses don't.
19623 */
19624+
19625+#ifdef CONFIG_PAX_KERNEXEC
19626+ return ktla_ktva(sp[0]);
19627+#else
19628 if (sp[0] >> 22)
19629 return sp[0];
19630 if (sp[1] >> 22)
19631 return sp[1];
19632 #endif
19633+
19634+#endif
19635 }
19636 return pc;
19637 }
19638diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19639index 9d9d2f9..ed344e4 100644
19640--- a/arch/x86/kernel/tls.c
19641+++ b/arch/x86/kernel/tls.c
19642@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19643 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19644 return -EINVAL;
19645
19646+#ifdef CONFIG_PAX_SEGMEXEC
19647+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19648+ return -EINVAL;
19649+#endif
19650+
19651 set_tls_desc(p, idx, &info, 1);
19652
19653 return 0;
19654diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19655index 05b31d9..501d3ba 100644
19656--- a/arch/x86/kernel/traps.c
19657+++ b/arch/x86/kernel/traps.c
19658@@ -67,12 +67,6 @@ asmlinkage int system_call(void);
19659
19660 /* Do we ignore FPU interrupts ? */
19661 char ignore_fpu_irq;
19662-
19663-/*
19664- * The IDT has to be page-aligned to simplify the Pentium
19665- * F0 0F bug workaround.
19666- */
19667-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19668 #endif
19669
19670 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19671@@ -105,13 +99,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19672 }
19673
19674 static void __kprobes
19675-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19676+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19677 long error_code, siginfo_t *info)
19678 {
19679 struct task_struct *tsk = current;
19680
19681 #ifdef CONFIG_X86_32
19682- if (regs->flags & X86_VM_MASK) {
19683+ if (v8086_mode(regs)) {
19684 /*
19685 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19686 * On nmi (interrupt 2), do_trap should not be called.
19687@@ -122,7 +116,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19688 }
19689 #endif
19690
19691- if (!user_mode(regs))
19692+ if (!user_mode_novm(regs))
19693 goto kernel_trap;
19694
19695 #ifdef CONFIG_X86_32
19696@@ -145,7 +139,7 @@ trap_signal:
19697 printk_ratelimit()) {
19698 printk(KERN_INFO
19699 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19700- tsk->comm, tsk->pid, str,
19701+ tsk->comm, task_pid_nr(tsk), str,
19702 regs->ip, regs->sp, error_code);
19703 print_vma_addr(" in ", regs->ip);
19704 printk("\n");
19705@@ -162,8 +156,20 @@ kernel_trap:
19706 if (!fixup_exception(regs)) {
19707 tsk->thread.error_code = error_code;
19708 tsk->thread.trap_nr = trapnr;
19709+
19710+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19711+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19712+ str = "PAX: suspicious stack segment fault";
19713+#endif
19714+
19715 die(str, regs, error_code);
19716 }
19717+
19718+#ifdef CONFIG_PAX_REFCOUNT
19719+ if (trapnr == 4)
19720+ pax_report_refcount_overflow(regs);
19721+#endif
19722+
19723 return;
19724
19725 #ifdef CONFIG_X86_32
19726@@ -256,14 +262,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19727 conditional_sti(regs);
19728
19729 #ifdef CONFIG_X86_32
19730- if (regs->flags & X86_VM_MASK)
19731+ if (v8086_mode(regs))
19732 goto gp_in_vm86;
19733 #endif
19734
19735 tsk = current;
19736- if (!user_mode(regs))
19737+ if (!user_mode_novm(regs))
19738 goto gp_in_kernel;
19739
19740+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19741+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19742+ struct mm_struct *mm = tsk->mm;
19743+ unsigned long limit;
19744+
19745+ down_write(&mm->mmap_sem);
19746+ limit = mm->context.user_cs_limit;
19747+ if (limit < TASK_SIZE) {
19748+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19749+ up_write(&mm->mmap_sem);
19750+ return;
19751+ }
19752+ up_write(&mm->mmap_sem);
19753+ }
19754+#endif
19755+
19756 tsk->thread.error_code = error_code;
19757 tsk->thread.trap_nr = X86_TRAP_GP;
19758
19759@@ -296,6 +318,13 @@ gp_in_kernel:
19760 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
19761 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
19762 return;
19763+
19764+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19765+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19766+ die("PAX: suspicious general protection fault", regs, error_code);
19767+ else
19768+#endif
19769+
19770 die("general protection fault", regs, error_code);
19771 }
19772
19773@@ -431,7 +460,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19774 /* It's safe to allow irq's after DR6 has been saved */
19775 preempt_conditional_sti(regs);
19776
19777- if (regs->flags & X86_VM_MASK) {
19778+ if (v8086_mode(regs)) {
19779 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
19780 X86_TRAP_DB);
19781 preempt_conditional_cli(regs);
19782@@ -446,7 +475,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19783 * We already checked v86 mode above, so we can check for kernel mode
19784 * by just checking the CPL of CS.
19785 */
19786- if ((dr6 & DR_STEP) && !user_mode(regs)) {
19787+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19788 tsk->thread.debugreg6 &= ~DR_STEP;
19789 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19790 regs->flags &= ~X86_EFLAGS_TF;
19791@@ -477,7 +506,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19792 return;
19793 conditional_sti(regs);
19794
19795- if (!user_mode_vm(regs))
19796+ if (!user_mode(regs))
19797 {
19798 if (!fixup_exception(regs)) {
19799 task->thread.error_code = error_code;
19800diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
19801index dc4e910..c9dedab 100644
19802--- a/arch/x86/kernel/uprobes.c
19803+++ b/arch/x86/kernel/uprobes.c
19804@@ -606,7 +606,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
19805 int ret = NOTIFY_DONE;
19806
19807 /* We are only interested in userspace traps */
19808- if (regs && !user_mode_vm(regs))
19809+ if (regs && !user_mode(regs))
19810 return NOTIFY_DONE;
19811
19812 switch (val) {
19813diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19814index b9242ba..50c5edd 100644
19815--- a/arch/x86/kernel/verify_cpu.S
19816+++ b/arch/x86/kernel/verify_cpu.S
19817@@ -20,6 +20,7 @@
19818 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19819 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19820 * arch/x86/kernel/head_32.S: processor startup
19821+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19822 *
19823 * verify_cpu, returns the status of longmode and SSE in register %eax.
19824 * 0: Success 1: Failure
19825diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19826index 255f58a..5e91150 100644
19827--- a/arch/x86/kernel/vm86_32.c
19828+++ b/arch/x86/kernel/vm86_32.c
19829@@ -41,6 +41,7 @@
19830 #include <linux/ptrace.h>
19831 #include <linux/audit.h>
19832 #include <linux/stddef.h>
19833+#include <linux/grsecurity.h>
19834
19835 #include <asm/uaccess.h>
19836 #include <asm/io.h>
19837@@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19838 do_exit(SIGSEGV);
19839 }
19840
19841- tss = &per_cpu(init_tss, get_cpu());
19842+ tss = init_tss + get_cpu();
19843 current->thread.sp0 = current->thread.saved_sp0;
19844 current->thread.sysenter_cs = __KERNEL_CS;
19845 load_sp0(tss, &current->thread);
19846@@ -210,6 +211,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19847 struct task_struct *tsk;
19848 int tmp, ret = -EPERM;
19849
19850+#ifdef CONFIG_GRKERNSEC_VM86
19851+ if (!capable(CAP_SYS_RAWIO)) {
19852+ gr_handle_vm86();
19853+ goto out;
19854+ }
19855+#endif
19856+
19857 tsk = current;
19858 if (tsk->thread.saved_sp0)
19859 goto out;
19860@@ -240,6 +248,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19861 int tmp, ret;
19862 struct vm86plus_struct __user *v86;
19863
19864+#ifdef CONFIG_GRKERNSEC_VM86
19865+ if (!capable(CAP_SYS_RAWIO)) {
19866+ gr_handle_vm86();
19867+ ret = -EPERM;
19868+ goto out;
19869+ }
19870+#endif
19871+
19872 tsk = current;
19873 switch (cmd) {
19874 case VM86_REQUEST_IRQ:
19875@@ -326,7 +342,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
19876 tsk->thread.saved_fs = info->regs32->fs;
19877 tsk->thread.saved_gs = get_user_gs(info->regs32);
19878
19879- tss = &per_cpu(init_tss, get_cpu());
19880+ tss = init_tss + get_cpu();
19881 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
19882 if (cpu_has_sep)
19883 tsk->thread.sysenter_cs = 0;
19884@@ -533,7 +549,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
19885 goto cannot_handle;
19886 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
19887 goto cannot_handle;
19888- intr_ptr = (unsigned long __user *) (i << 2);
19889+ intr_ptr = (__force unsigned long __user *) (i << 2);
19890 if (get_user(segoffs, intr_ptr))
19891 goto cannot_handle;
19892 if ((segoffs >> 16) == BIOSSEG)
19893diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
19894index 22a1530..8fbaaad 100644
19895--- a/arch/x86/kernel/vmlinux.lds.S
19896+++ b/arch/x86/kernel/vmlinux.lds.S
19897@@ -26,6 +26,13 @@
19898 #include <asm/page_types.h>
19899 #include <asm/cache.h>
19900 #include <asm/boot.h>
19901+#include <asm/segment.h>
19902+
19903+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19904+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
19905+#else
19906+#define __KERNEL_TEXT_OFFSET 0
19907+#endif
19908
19909 #undef i386 /* in case the preprocessor is a 32bit one */
19910
19911@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
19912
19913 PHDRS {
19914 text PT_LOAD FLAGS(5); /* R_E */
19915+#ifdef CONFIG_X86_32
19916+ module PT_LOAD FLAGS(5); /* R_E */
19917+#endif
19918+#ifdef CONFIG_XEN
19919+ rodata PT_LOAD FLAGS(5); /* R_E */
19920+#else
19921+ rodata PT_LOAD FLAGS(4); /* R__ */
19922+#endif
19923 data PT_LOAD FLAGS(6); /* RW_ */
19924-#ifdef CONFIG_X86_64
19925+ init.begin PT_LOAD FLAGS(6); /* RW_ */
19926 #ifdef CONFIG_SMP
19927 percpu PT_LOAD FLAGS(6); /* RW_ */
19928 #endif
19929+ text.init PT_LOAD FLAGS(5); /* R_E */
19930+ text.exit PT_LOAD FLAGS(5); /* R_E */
19931 init PT_LOAD FLAGS(7); /* RWE */
19932-#endif
19933 note PT_NOTE FLAGS(0); /* ___ */
19934 }
19935
19936 SECTIONS
19937 {
19938 #ifdef CONFIG_X86_32
19939- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
19940- phys_startup_32 = startup_32 - LOAD_OFFSET;
19941+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
19942 #else
19943- . = __START_KERNEL;
19944- phys_startup_64 = startup_64 - LOAD_OFFSET;
19945+ . = __START_KERNEL;
19946 #endif
19947
19948 /* Text and read-only data */
19949- .text : AT(ADDR(.text) - LOAD_OFFSET) {
19950- _text = .;
19951+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19952 /* bootstrapping code */
19953+#ifdef CONFIG_X86_32
19954+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19955+#else
19956+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19957+#endif
19958+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19959+ _text = .;
19960 HEAD_TEXT
19961 #ifdef CONFIG_X86_32
19962 . = ALIGN(PAGE_SIZE);
19963@@ -108,13 +128,48 @@ SECTIONS
19964 IRQENTRY_TEXT
19965 *(.fixup)
19966 *(.gnu.warning)
19967- /* End of text section */
19968- _etext = .;
19969 } :text = 0x9090
19970
19971- NOTES :text :note
19972+ . += __KERNEL_TEXT_OFFSET;
19973
19974- EXCEPTION_TABLE(16) :text = 0x9090
19975+#ifdef CONFIG_X86_32
19976+ . = ALIGN(PAGE_SIZE);
19977+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
19978+
19979+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
19980+ MODULES_EXEC_VADDR = .;
19981+ BYTE(0)
19982+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
19983+ . = ALIGN(HPAGE_SIZE) - 1;
19984+ MODULES_EXEC_END = .;
19985+#endif
19986+
19987+ } :module
19988+#endif
19989+
19990+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
19991+ /* End of text section */
19992+ BYTE(0)
19993+ _etext = . - __KERNEL_TEXT_OFFSET;
19994+ }
19995+
19996+#ifdef CONFIG_X86_32
19997+ . = ALIGN(PAGE_SIZE);
19998+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
19999+ *(.idt)
20000+ . = ALIGN(PAGE_SIZE);
20001+ *(.empty_zero_page)
20002+ *(.initial_pg_fixmap)
20003+ *(.initial_pg_pmd)
20004+ *(.initial_page_table)
20005+ *(.swapper_pg_dir)
20006+ } :rodata
20007+#endif
20008+
20009+ . = ALIGN(PAGE_SIZE);
20010+ NOTES :rodata :note
20011+
20012+ EXCEPTION_TABLE(16) :rodata
20013
20014 #if defined(CONFIG_DEBUG_RODATA)
20015 /* .text should occupy whole number of pages */
20016@@ -126,16 +181,20 @@ SECTIONS
20017
20018 /* Data */
20019 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20020+
20021+#ifdef CONFIG_PAX_KERNEXEC
20022+ . = ALIGN(HPAGE_SIZE);
20023+#else
20024+ . = ALIGN(PAGE_SIZE);
20025+#endif
20026+
20027 /* Start of data section */
20028 _sdata = .;
20029
20030 /* init_task */
20031 INIT_TASK_DATA(THREAD_SIZE)
20032
20033-#ifdef CONFIG_X86_32
20034- /* 32 bit has nosave before _edata */
20035 NOSAVE_DATA
20036-#endif
20037
20038 PAGE_ALIGNED_DATA(PAGE_SIZE)
20039
20040@@ -176,12 +235,19 @@ SECTIONS
20041 #endif /* CONFIG_X86_64 */
20042
20043 /* Init code and data - will be freed after init */
20044- . = ALIGN(PAGE_SIZE);
20045 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20046+ BYTE(0)
20047+
20048+#ifdef CONFIG_PAX_KERNEXEC
20049+ . = ALIGN(HPAGE_SIZE);
20050+#else
20051+ . = ALIGN(PAGE_SIZE);
20052+#endif
20053+
20054 __init_begin = .; /* paired with __init_end */
20055- }
20056+ } :init.begin
20057
20058-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20059+#ifdef CONFIG_SMP
20060 /*
20061 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20062 * output PHDR, so the next output section - .init.text - should
20063@@ -190,12 +256,27 @@ SECTIONS
20064 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20065 #endif
20066
20067- INIT_TEXT_SECTION(PAGE_SIZE)
20068-#ifdef CONFIG_X86_64
20069- :init
20070-#endif
20071+ . = ALIGN(PAGE_SIZE);
20072+ init_begin = .;
20073+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20074+ VMLINUX_SYMBOL(_sinittext) = .;
20075+ INIT_TEXT
20076+ VMLINUX_SYMBOL(_einittext) = .;
20077+ . = ALIGN(PAGE_SIZE);
20078+ } :text.init
20079
20080- INIT_DATA_SECTION(16)
20081+ /*
20082+ * .exit.text is discard at runtime, not link time, to deal with
20083+ * references from .altinstructions and .eh_frame
20084+ */
20085+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20086+ EXIT_TEXT
20087+ . = ALIGN(16);
20088+ } :text.exit
20089+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20090+
20091+ . = ALIGN(PAGE_SIZE);
20092+ INIT_DATA_SECTION(16) :init
20093
20094 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
20095 __x86_cpu_dev_start = .;
20096@@ -257,19 +338,12 @@ SECTIONS
20097 }
20098
20099 . = ALIGN(8);
20100- /*
20101- * .exit.text is discard at runtime, not link time, to deal with
20102- * references from .altinstructions and .eh_frame
20103- */
20104- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20105- EXIT_TEXT
20106- }
20107
20108 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20109 EXIT_DATA
20110 }
20111
20112-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20113+#ifndef CONFIG_SMP
20114 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20115 #endif
20116
20117@@ -288,16 +362,10 @@ SECTIONS
20118 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20119 __smp_locks = .;
20120 *(.smp_locks)
20121- . = ALIGN(PAGE_SIZE);
20122 __smp_locks_end = .;
20123+ . = ALIGN(PAGE_SIZE);
20124 }
20125
20126-#ifdef CONFIG_X86_64
20127- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20128- NOSAVE_DATA
20129- }
20130-#endif
20131-
20132 /* BSS */
20133 . = ALIGN(PAGE_SIZE);
20134 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20135@@ -313,6 +381,7 @@ SECTIONS
20136 __brk_base = .;
20137 . += 64 * 1024; /* 64k alignment slop space */
20138 *(.brk_reservation) /* areas brk users have reserved */
20139+ . = ALIGN(HPAGE_SIZE);
20140 __brk_limit = .;
20141 }
20142
20143@@ -339,13 +408,12 @@ SECTIONS
20144 * for the boot processor.
20145 */
20146 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20147-INIT_PER_CPU(gdt_page);
20148 INIT_PER_CPU(irq_stack_union);
20149
20150 /*
20151 * Build-time check on the image size:
20152 */
20153-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20154+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20155 "kernel image bigger than KERNEL_IMAGE_SIZE");
20156
20157 #ifdef CONFIG_SMP
20158diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20159index 5db36ca..2938af9 100644
20160--- a/arch/x86/kernel/vsyscall_64.c
20161+++ b/arch/x86/kernel/vsyscall_64.c
20162@@ -54,15 +54,13 @@
20163 DEFINE_VVAR(int, vgetcpu_mode);
20164 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20165
20166-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20167+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20168
20169 static int __init vsyscall_setup(char *str)
20170 {
20171 if (str) {
20172 if (!strcmp("emulate", str))
20173 vsyscall_mode = EMULATE;
20174- else if (!strcmp("native", str))
20175- vsyscall_mode = NATIVE;
20176 else if (!strcmp("none", str))
20177 vsyscall_mode = NONE;
20178 else
20179@@ -309,8 +307,7 @@ done:
20180 return true;
20181
20182 sigsegv:
20183- force_sig(SIGSEGV, current);
20184- return true;
20185+ do_group_exit(SIGKILL);
20186 }
20187
20188 /*
20189@@ -363,10 +360,7 @@ void __init map_vsyscall(void)
20190 extern char __vvar_page;
20191 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20192
20193- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20194- vsyscall_mode == NATIVE
20195- ? PAGE_KERNEL_VSYSCALL
20196- : PAGE_KERNEL_VVAR);
20197+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20198 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20199 (unsigned long)VSYSCALL_START);
20200
20201diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20202index 9796c2f..f686fbf 100644
20203--- a/arch/x86/kernel/x8664_ksyms_64.c
20204+++ b/arch/x86/kernel/x8664_ksyms_64.c
20205@@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
20206 EXPORT_SYMBOL(copy_user_generic_string);
20207 EXPORT_SYMBOL(copy_user_generic_unrolled);
20208 EXPORT_SYMBOL(__copy_user_nocache);
20209-EXPORT_SYMBOL(_copy_from_user);
20210-EXPORT_SYMBOL(_copy_to_user);
20211
20212 EXPORT_SYMBOL(copy_page);
20213 EXPORT_SYMBOL(clear_page);
20214diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20215index bd18149..2ea0183 100644
20216--- a/arch/x86/kernel/xsave.c
20217+++ b/arch/x86/kernel/xsave.c
20218@@ -129,7 +129,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20219 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20220 return -EINVAL;
20221
20222- err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20223+ err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20224 fx_sw_user->extended_size -
20225 FP_XSTATE_MAGIC2_SIZE));
20226 if (err)
20227@@ -265,7 +265,7 @@ fx_only:
20228 * the other extended state.
20229 */
20230 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20231- return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20232+ return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20233 }
20234
20235 /*
20236@@ -294,7 +294,7 @@ int restore_i387_xstate(void __user *buf)
20237 if (use_xsave())
20238 err = restore_user_xstate(buf);
20239 else
20240- err = fxrstor_checking((__force struct i387_fxsave_struct *)
20241+ err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20242 buf);
20243 if (unlikely(err)) {
20244 /*
20245diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20246index 7df1c6d..9ea7c79 100644
20247--- a/arch/x86/kvm/cpuid.c
20248+++ b/arch/x86/kvm/cpuid.c
20249@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20250 struct kvm_cpuid2 *cpuid,
20251 struct kvm_cpuid_entry2 __user *entries)
20252 {
20253- int r;
20254+ int r, i;
20255
20256 r = -E2BIG;
20257 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20258 goto out;
20259 r = -EFAULT;
20260- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20261- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20262+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20263 goto out;
20264+ for (i = 0; i < cpuid->nent; ++i) {
20265+ struct kvm_cpuid_entry2 cpuid_entry;
20266+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20267+ goto out;
20268+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
20269+ }
20270 vcpu->arch.cpuid_nent = cpuid->nent;
20271 kvm_apic_set_version(vcpu);
20272 kvm_x86_ops->cpuid_update(vcpu);
20273@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20274 struct kvm_cpuid2 *cpuid,
20275 struct kvm_cpuid_entry2 __user *entries)
20276 {
20277- int r;
20278+ int r, i;
20279
20280 r = -E2BIG;
20281 if (cpuid->nent < vcpu->arch.cpuid_nent)
20282 goto out;
20283 r = -EFAULT;
20284- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20285- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20286+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20287 goto out;
20288+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20289+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20290+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20291+ goto out;
20292+ }
20293 return 0;
20294
20295 out:
20296diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20297index 4837375..2cc9722 100644
20298--- a/arch/x86/kvm/emulate.c
20299+++ b/arch/x86/kvm/emulate.c
20300@@ -256,6 +256,7 @@ struct gprefix {
20301
20302 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20303 do { \
20304+ unsigned long _tmp; \
20305 __asm__ __volatile__ ( \
20306 _PRE_EFLAGS("0", "4", "2") \
20307 _op _suffix " %"_x"3,%1; " \
20308@@ -270,8 +271,6 @@ struct gprefix {
20309 /* Raw emulation: instruction has two explicit operands. */
20310 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20311 do { \
20312- unsigned long _tmp; \
20313- \
20314 switch ((ctxt)->dst.bytes) { \
20315 case 2: \
20316 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20317@@ -287,7 +286,6 @@ struct gprefix {
20318
20319 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20320 do { \
20321- unsigned long _tmp; \
20322 switch ((ctxt)->dst.bytes) { \
20323 case 1: \
20324 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20325diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20326index 93c1574..d6097dc 100644
20327--- a/arch/x86/kvm/lapic.c
20328+++ b/arch/x86/kvm/lapic.c
20329@@ -54,7 +54,7 @@
20330 #define APIC_BUS_CYCLE_NS 1
20331
20332 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20333-#define apic_debug(fmt, arg...)
20334+#define apic_debug(fmt, arg...) do {} while (0)
20335
20336 #define APIC_LVT_NUM 6
20337 /* 14 is the version for Xeon and Pentium 8.4.8*/
20338diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20339index 34f9709..8eca2d5 100644
20340--- a/arch/x86/kvm/paging_tmpl.h
20341+++ b/arch/x86/kvm/paging_tmpl.h
20342@@ -197,7 +197,7 @@ retry_walk:
20343 if (unlikely(kvm_is_error_hva(host_addr)))
20344 goto error;
20345
20346- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20347+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20348 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20349 goto error;
20350
20351diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20352index f75af40..285b18f 100644
20353--- a/arch/x86/kvm/svm.c
20354+++ b/arch/x86/kvm/svm.c
20355@@ -3516,7 +3516,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20356 int cpu = raw_smp_processor_id();
20357
20358 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20359+
20360+ pax_open_kernel();
20361 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20362+ pax_close_kernel();
20363+
20364 load_TR_desc();
20365 }
20366
20367@@ -3894,6 +3898,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20368 #endif
20369 #endif
20370
20371+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20372+ __set_fs(current_thread_info()->addr_limit);
20373+#endif
20374+
20375 reload_tss(vcpu);
20376
20377 local_irq_disable();
20378diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20379index 86c8704..e8ee2ac 100644
20380--- a/arch/x86/kvm/vmx.c
20381+++ b/arch/x86/kvm/vmx.c
20382@@ -1317,7 +1317,11 @@ static void reload_tss(void)
20383 struct desc_struct *descs;
20384
20385 descs = (void *)gdt->address;
20386+
20387+ pax_open_kernel();
20388 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20389+ pax_close_kernel();
20390+
20391 load_TR_desc();
20392 }
20393
20394@@ -2650,8 +2654,11 @@ static __init int hardware_setup(void)
20395 if (!cpu_has_vmx_flexpriority())
20396 flexpriority_enabled = 0;
20397
20398- if (!cpu_has_vmx_tpr_shadow())
20399- kvm_x86_ops->update_cr8_intercept = NULL;
20400+ if (!cpu_has_vmx_tpr_shadow()) {
20401+ pax_open_kernel();
20402+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20403+ pax_close_kernel();
20404+ }
20405
20406 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20407 kvm_disable_largepages();
20408@@ -3719,7 +3726,7 @@ static void vmx_set_constant_host_state(void)
20409 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20410
20411 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20412- vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20413+ vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20414
20415 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20416 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20417@@ -6257,6 +6264,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20418 "jmp .Lkvm_vmx_return \n\t"
20419 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20420 ".Lkvm_vmx_return: "
20421+
20422+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20423+ "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20424+ ".Lkvm_vmx_return2: "
20425+#endif
20426+
20427 /* Save guest registers, load host registers, keep flags */
20428 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20429 "pop %0 \n\t"
20430@@ -6305,6 +6318,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20431 #endif
20432 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20433 [wordsize]"i"(sizeof(ulong))
20434+
20435+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20436+ ,[cs]"i"(__KERNEL_CS)
20437+#endif
20438+
20439 : "cc", "memory"
20440 , R"ax", R"bx", R"di", R"si"
20441 #ifdef CONFIG_X86_64
20442@@ -6312,7 +6330,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20443 #endif
20444 );
20445
20446-#ifndef CONFIG_X86_64
20447+#ifdef CONFIG_X86_32
20448 /*
20449 * The sysexit path does not restore ds/es, so we must set them to
20450 * a reasonable value ourselves.
20451@@ -6321,8 +6339,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20452 * may be executed in interrupt context, which saves and restore segments
20453 * around it, nullifying its effect.
20454 */
20455- loadsegment(ds, __USER_DS);
20456- loadsegment(es, __USER_DS);
20457+ loadsegment(ds, __KERNEL_DS);
20458+ loadsegment(es, __KERNEL_DS);
20459+ loadsegment(ss, __KERNEL_DS);
20460+
20461+#ifdef CONFIG_PAX_KERNEXEC
20462+ loadsegment(fs, __KERNEL_PERCPU);
20463+#endif
20464+
20465+#ifdef CONFIG_PAX_MEMORY_UDEREF
20466+ __set_fs(current_thread_info()->addr_limit);
20467+#endif
20468+
20469 #endif
20470
20471 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
20472diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20473index 14c290d..0dae6e5 100644
20474--- a/arch/x86/kvm/x86.c
20475+++ b/arch/x86/kvm/x86.c
20476@@ -1361,8 +1361,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20477 {
20478 struct kvm *kvm = vcpu->kvm;
20479 int lm = is_long_mode(vcpu);
20480- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20481- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20482+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20483+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20484 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20485 : kvm->arch.xen_hvm_config.blob_size_32;
20486 u32 page_num = data & ~PAGE_MASK;
20487@@ -2218,6 +2218,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20488 if (n < msr_list.nmsrs)
20489 goto out;
20490 r = -EFAULT;
20491+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20492+ goto out;
20493 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20494 num_msrs_to_save * sizeof(u32)))
20495 goto out;
20496@@ -2343,7 +2345,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20497 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20498 struct kvm_interrupt *irq)
20499 {
20500- if (irq->irq < 0 || irq->irq >= 256)
20501+ if (irq->irq >= 256)
20502 return -EINVAL;
20503 if (irqchip_in_kernel(vcpu->kvm))
20504 return -ENXIO;
20505@@ -4880,7 +4882,7 @@ static void kvm_set_mmio_spte_mask(void)
20506 kvm_mmu_set_mmio_spte_mask(mask);
20507 }
20508
20509-int kvm_arch_init(void *opaque)
20510+int kvm_arch_init(const void *opaque)
20511 {
20512 int r;
20513 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20514diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20515index 642d880..44e0f3f 100644
20516--- a/arch/x86/lguest/boot.c
20517+++ b/arch/x86/lguest/boot.c
20518@@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20519 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20520 * Launcher to reboot us.
20521 */
20522-static void lguest_restart(char *reason)
20523+static __noreturn void lguest_restart(char *reason)
20524 {
20525 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20526+ BUG();
20527 }
20528
20529 /*G:050
20530diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20531index 00933d5..3a64af9 100644
20532--- a/arch/x86/lib/atomic64_386_32.S
20533+++ b/arch/x86/lib/atomic64_386_32.S
20534@@ -48,6 +48,10 @@ BEGIN(read)
20535 movl (v), %eax
20536 movl 4(v), %edx
20537 RET_ENDP
20538+BEGIN(read_unchecked)
20539+ movl (v), %eax
20540+ movl 4(v), %edx
20541+RET_ENDP
20542 #undef v
20543
20544 #define v %esi
20545@@ -55,6 +59,10 @@ BEGIN(set)
20546 movl %ebx, (v)
20547 movl %ecx, 4(v)
20548 RET_ENDP
20549+BEGIN(set_unchecked)
20550+ movl %ebx, (v)
20551+ movl %ecx, 4(v)
20552+RET_ENDP
20553 #undef v
20554
20555 #define v %esi
20556@@ -70,6 +78,20 @@ RET_ENDP
20557 BEGIN(add)
20558 addl %eax, (v)
20559 adcl %edx, 4(v)
20560+
20561+#ifdef CONFIG_PAX_REFCOUNT
20562+ jno 0f
20563+ subl %eax, (v)
20564+ sbbl %edx, 4(v)
20565+ int $4
20566+0:
20567+ _ASM_EXTABLE(0b, 0b)
20568+#endif
20569+
20570+RET_ENDP
20571+BEGIN(add_unchecked)
20572+ addl %eax, (v)
20573+ adcl %edx, 4(v)
20574 RET_ENDP
20575 #undef v
20576
20577@@ -77,6 +99,24 @@ RET_ENDP
20578 BEGIN(add_return)
20579 addl (v), %eax
20580 adcl 4(v), %edx
20581+
20582+#ifdef CONFIG_PAX_REFCOUNT
20583+ into
20584+1234:
20585+ _ASM_EXTABLE(1234b, 2f)
20586+#endif
20587+
20588+ movl %eax, (v)
20589+ movl %edx, 4(v)
20590+
20591+#ifdef CONFIG_PAX_REFCOUNT
20592+2:
20593+#endif
20594+
20595+RET_ENDP
20596+BEGIN(add_return_unchecked)
20597+ addl (v), %eax
20598+ adcl 4(v), %edx
20599 movl %eax, (v)
20600 movl %edx, 4(v)
20601 RET_ENDP
20602@@ -86,6 +126,20 @@ RET_ENDP
20603 BEGIN(sub)
20604 subl %eax, (v)
20605 sbbl %edx, 4(v)
20606+
20607+#ifdef CONFIG_PAX_REFCOUNT
20608+ jno 0f
20609+ addl %eax, (v)
20610+ adcl %edx, 4(v)
20611+ int $4
20612+0:
20613+ _ASM_EXTABLE(0b, 0b)
20614+#endif
20615+
20616+RET_ENDP
20617+BEGIN(sub_unchecked)
20618+ subl %eax, (v)
20619+ sbbl %edx, 4(v)
20620 RET_ENDP
20621 #undef v
20622
20623@@ -96,6 +150,27 @@ BEGIN(sub_return)
20624 sbbl $0, %edx
20625 addl (v), %eax
20626 adcl 4(v), %edx
20627+
20628+#ifdef CONFIG_PAX_REFCOUNT
20629+ into
20630+1234:
20631+ _ASM_EXTABLE(1234b, 2f)
20632+#endif
20633+
20634+ movl %eax, (v)
20635+ movl %edx, 4(v)
20636+
20637+#ifdef CONFIG_PAX_REFCOUNT
20638+2:
20639+#endif
20640+
20641+RET_ENDP
20642+BEGIN(sub_return_unchecked)
20643+ negl %edx
20644+ negl %eax
20645+ sbbl $0, %edx
20646+ addl (v), %eax
20647+ adcl 4(v), %edx
20648 movl %eax, (v)
20649 movl %edx, 4(v)
20650 RET_ENDP
20651@@ -105,6 +180,20 @@ RET_ENDP
20652 BEGIN(inc)
20653 addl $1, (v)
20654 adcl $0, 4(v)
20655+
20656+#ifdef CONFIG_PAX_REFCOUNT
20657+ jno 0f
20658+ subl $1, (v)
20659+ sbbl $0, 4(v)
20660+ int $4
20661+0:
20662+ _ASM_EXTABLE(0b, 0b)
20663+#endif
20664+
20665+RET_ENDP
20666+BEGIN(inc_unchecked)
20667+ addl $1, (v)
20668+ adcl $0, 4(v)
20669 RET_ENDP
20670 #undef v
20671
20672@@ -114,6 +203,26 @@ BEGIN(inc_return)
20673 movl 4(v), %edx
20674 addl $1, %eax
20675 adcl $0, %edx
20676+
20677+#ifdef CONFIG_PAX_REFCOUNT
20678+ into
20679+1234:
20680+ _ASM_EXTABLE(1234b, 2f)
20681+#endif
20682+
20683+ movl %eax, (v)
20684+ movl %edx, 4(v)
20685+
20686+#ifdef CONFIG_PAX_REFCOUNT
20687+2:
20688+#endif
20689+
20690+RET_ENDP
20691+BEGIN(inc_return_unchecked)
20692+ movl (v), %eax
20693+ movl 4(v), %edx
20694+ addl $1, %eax
20695+ adcl $0, %edx
20696 movl %eax, (v)
20697 movl %edx, 4(v)
20698 RET_ENDP
20699@@ -123,6 +232,20 @@ RET_ENDP
20700 BEGIN(dec)
20701 subl $1, (v)
20702 sbbl $0, 4(v)
20703+
20704+#ifdef CONFIG_PAX_REFCOUNT
20705+ jno 0f
20706+ addl $1, (v)
20707+ adcl $0, 4(v)
20708+ int $4
20709+0:
20710+ _ASM_EXTABLE(0b, 0b)
20711+#endif
20712+
20713+RET_ENDP
20714+BEGIN(dec_unchecked)
20715+ subl $1, (v)
20716+ sbbl $0, 4(v)
20717 RET_ENDP
20718 #undef v
20719
20720@@ -132,6 +255,26 @@ BEGIN(dec_return)
20721 movl 4(v), %edx
20722 subl $1, %eax
20723 sbbl $0, %edx
20724+
20725+#ifdef CONFIG_PAX_REFCOUNT
20726+ into
20727+1234:
20728+ _ASM_EXTABLE(1234b, 2f)
20729+#endif
20730+
20731+ movl %eax, (v)
20732+ movl %edx, 4(v)
20733+
20734+#ifdef CONFIG_PAX_REFCOUNT
20735+2:
20736+#endif
20737+
20738+RET_ENDP
20739+BEGIN(dec_return_unchecked)
20740+ movl (v), %eax
20741+ movl 4(v), %edx
20742+ subl $1, %eax
20743+ sbbl $0, %edx
20744 movl %eax, (v)
20745 movl %edx, 4(v)
20746 RET_ENDP
20747@@ -143,6 +286,13 @@ BEGIN(add_unless)
20748 adcl %edx, %edi
20749 addl (v), %eax
20750 adcl 4(v), %edx
20751+
20752+#ifdef CONFIG_PAX_REFCOUNT
20753+ into
20754+1234:
20755+ _ASM_EXTABLE(1234b, 2f)
20756+#endif
20757+
20758 cmpl %eax, %ecx
20759 je 3f
20760 1:
20761@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20762 1:
20763 addl $1, %eax
20764 adcl $0, %edx
20765+
20766+#ifdef CONFIG_PAX_REFCOUNT
20767+ into
20768+1234:
20769+ _ASM_EXTABLE(1234b, 2f)
20770+#endif
20771+
20772 movl %eax, (v)
20773 movl %edx, 4(v)
20774 movl $1, %eax
20775@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20776 movl 4(v), %edx
20777 subl $1, %eax
20778 sbbl $0, %edx
20779+
20780+#ifdef CONFIG_PAX_REFCOUNT
20781+ into
20782+1234:
20783+ _ASM_EXTABLE(1234b, 1f)
20784+#endif
20785+
20786 js 1f
20787 movl %eax, (v)
20788 movl %edx, 4(v)
20789diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20790index f5cc9eb..51fa319 100644
20791--- a/arch/x86/lib/atomic64_cx8_32.S
20792+++ b/arch/x86/lib/atomic64_cx8_32.S
20793@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20794 CFI_STARTPROC
20795
20796 read64 %ecx
20797+ pax_force_retaddr
20798 ret
20799 CFI_ENDPROC
20800 ENDPROC(atomic64_read_cx8)
20801
20802+ENTRY(atomic64_read_unchecked_cx8)
20803+ CFI_STARTPROC
20804+
20805+ read64 %ecx
20806+ pax_force_retaddr
20807+ ret
20808+ CFI_ENDPROC
20809+ENDPROC(atomic64_read_unchecked_cx8)
20810+
20811 ENTRY(atomic64_set_cx8)
20812 CFI_STARTPROC
20813
20814@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20815 cmpxchg8b (%esi)
20816 jne 1b
20817
20818+ pax_force_retaddr
20819 ret
20820 CFI_ENDPROC
20821 ENDPROC(atomic64_set_cx8)
20822
20823+ENTRY(atomic64_set_unchecked_cx8)
20824+ CFI_STARTPROC
20825+
20826+1:
20827+/* we don't need LOCK_PREFIX since aligned 64-bit writes
20828+ * are atomic on 586 and newer */
20829+ cmpxchg8b (%esi)
20830+ jne 1b
20831+
20832+ pax_force_retaddr
20833+ ret
20834+ CFI_ENDPROC
20835+ENDPROC(atomic64_set_unchecked_cx8)
20836+
20837 ENTRY(atomic64_xchg_cx8)
20838 CFI_STARTPROC
20839
20840@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
20841 cmpxchg8b (%esi)
20842 jne 1b
20843
20844+ pax_force_retaddr
20845 ret
20846 CFI_ENDPROC
20847 ENDPROC(atomic64_xchg_cx8)
20848
20849-.macro addsub_return func ins insc
20850-ENTRY(atomic64_\func\()_return_cx8)
20851+.macro addsub_return func ins insc unchecked=""
20852+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20853 CFI_STARTPROC
20854 SAVE ebp
20855 SAVE ebx
20856@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
20857 movl %edx, %ecx
20858 \ins\()l %esi, %ebx
20859 \insc\()l %edi, %ecx
20860+
20861+.ifb \unchecked
20862+#ifdef CONFIG_PAX_REFCOUNT
20863+ into
20864+2:
20865+ _ASM_EXTABLE(2b, 3f)
20866+#endif
20867+.endif
20868+
20869 LOCK_PREFIX
20870 cmpxchg8b (%ebp)
20871 jne 1b
20872-
20873-10:
20874 movl %ebx, %eax
20875 movl %ecx, %edx
20876+
20877+.ifb \unchecked
20878+#ifdef CONFIG_PAX_REFCOUNT
20879+3:
20880+#endif
20881+.endif
20882+
20883 RESTORE edi
20884 RESTORE esi
20885 RESTORE ebx
20886 RESTORE ebp
20887+ pax_force_retaddr
20888 ret
20889 CFI_ENDPROC
20890-ENDPROC(atomic64_\func\()_return_cx8)
20891+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20892 .endm
20893
20894 addsub_return add add adc
20895 addsub_return sub sub sbb
20896+addsub_return add add adc _unchecked
20897+addsub_return sub sub sbb _unchecked
20898
20899-.macro incdec_return func ins insc
20900-ENTRY(atomic64_\func\()_return_cx8)
20901+.macro incdec_return func ins insc unchecked=""
20902+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20903 CFI_STARTPROC
20904 SAVE ebx
20905
20906@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
20907 movl %edx, %ecx
20908 \ins\()l $1, %ebx
20909 \insc\()l $0, %ecx
20910+
20911+.ifb \unchecked
20912+#ifdef CONFIG_PAX_REFCOUNT
20913+ into
20914+2:
20915+ _ASM_EXTABLE(2b, 3f)
20916+#endif
20917+.endif
20918+
20919 LOCK_PREFIX
20920 cmpxchg8b (%esi)
20921 jne 1b
20922
20923-10:
20924 movl %ebx, %eax
20925 movl %ecx, %edx
20926+
20927+.ifb \unchecked
20928+#ifdef CONFIG_PAX_REFCOUNT
20929+3:
20930+#endif
20931+.endif
20932+
20933 RESTORE ebx
20934+ pax_force_retaddr
20935 ret
20936 CFI_ENDPROC
20937-ENDPROC(atomic64_\func\()_return_cx8)
20938+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20939 .endm
20940
20941 incdec_return inc add adc
20942 incdec_return dec sub sbb
20943+incdec_return inc add adc _unchecked
20944+incdec_return dec sub sbb _unchecked
20945
20946 ENTRY(atomic64_dec_if_positive_cx8)
20947 CFI_STARTPROC
20948@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
20949 movl %edx, %ecx
20950 subl $1, %ebx
20951 sbb $0, %ecx
20952+
20953+#ifdef CONFIG_PAX_REFCOUNT
20954+ into
20955+1234:
20956+ _ASM_EXTABLE(1234b, 2f)
20957+#endif
20958+
20959 js 2f
20960 LOCK_PREFIX
20961 cmpxchg8b (%esi)
20962@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
20963 movl %ebx, %eax
20964 movl %ecx, %edx
20965 RESTORE ebx
20966+ pax_force_retaddr
20967 ret
20968 CFI_ENDPROC
20969 ENDPROC(atomic64_dec_if_positive_cx8)
20970@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
20971 movl %edx, %ecx
20972 addl %ebp, %ebx
20973 adcl %edi, %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@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
20985 CFI_ADJUST_CFA_OFFSET -8
20986 RESTORE ebx
20987 RESTORE ebp
20988+ pax_force_retaddr
20989 ret
20990 4:
20991 cmpl %edx, 4(%esp)
20992@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
20993 xorl %ecx, %ecx
20994 addl $1, %ebx
20995 adcl %edx, %ecx
20996+
20997+#ifdef CONFIG_PAX_REFCOUNT
20998+ into
20999+1234:
21000+ _ASM_EXTABLE(1234b, 3f)
21001+#endif
21002+
21003 LOCK_PREFIX
21004 cmpxchg8b (%esi)
21005 jne 1b
21006@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21007 movl $1, %eax
21008 3:
21009 RESTORE ebx
21010+ pax_force_retaddr
21011 ret
21012 CFI_ENDPROC
21013 ENDPROC(atomic64_inc_not_zero_cx8)
21014diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21015index 2af5df3..62b1a5a 100644
21016--- a/arch/x86/lib/checksum_32.S
21017+++ b/arch/x86/lib/checksum_32.S
21018@@ -29,7 +29,8 @@
21019 #include <asm/dwarf2.h>
21020 #include <asm/errno.h>
21021 #include <asm/asm.h>
21022-
21023+#include <asm/segment.h>
21024+
21025 /*
21026 * computes a partial checksum, e.g. for TCP/UDP fragments
21027 */
21028@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21029
21030 #define ARGBASE 16
21031 #define FP 12
21032-
21033-ENTRY(csum_partial_copy_generic)
21034+
21035+ENTRY(csum_partial_copy_generic_to_user)
21036 CFI_STARTPROC
21037+
21038+#ifdef CONFIG_PAX_MEMORY_UDEREF
21039+ pushl_cfi %gs
21040+ popl_cfi %es
21041+ jmp csum_partial_copy_generic
21042+#endif
21043+
21044+ENTRY(csum_partial_copy_generic_from_user)
21045+
21046+#ifdef CONFIG_PAX_MEMORY_UDEREF
21047+ pushl_cfi %gs
21048+ popl_cfi %ds
21049+#endif
21050+
21051+ENTRY(csum_partial_copy_generic)
21052 subl $4,%esp
21053 CFI_ADJUST_CFA_OFFSET 4
21054 pushl_cfi %edi
21055@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
21056 jmp 4f
21057 SRC(1: movw (%esi), %bx )
21058 addl $2, %esi
21059-DST( movw %bx, (%edi) )
21060+DST( movw %bx, %es:(%edi) )
21061 addl $2, %edi
21062 addw %bx, %ax
21063 adcl $0, %eax
21064@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
21065 SRC(1: movl (%esi), %ebx )
21066 SRC( movl 4(%esi), %edx )
21067 adcl %ebx, %eax
21068-DST( movl %ebx, (%edi) )
21069+DST( movl %ebx, %es:(%edi) )
21070 adcl %edx, %eax
21071-DST( movl %edx, 4(%edi) )
21072+DST( movl %edx, %es:4(%edi) )
21073
21074 SRC( movl 8(%esi), %ebx )
21075 SRC( movl 12(%esi), %edx )
21076 adcl %ebx, %eax
21077-DST( movl %ebx, 8(%edi) )
21078+DST( movl %ebx, %es:8(%edi) )
21079 adcl %edx, %eax
21080-DST( movl %edx, 12(%edi) )
21081+DST( movl %edx, %es:12(%edi) )
21082
21083 SRC( movl 16(%esi), %ebx )
21084 SRC( movl 20(%esi), %edx )
21085 adcl %ebx, %eax
21086-DST( movl %ebx, 16(%edi) )
21087+DST( movl %ebx, %es:16(%edi) )
21088 adcl %edx, %eax
21089-DST( movl %edx, 20(%edi) )
21090+DST( movl %edx, %es:20(%edi) )
21091
21092 SRC( movl 24(%esi), %ebx )
21093 SRC( movl 28(%esi), %edx )
21094 adcl %ebx, %eax
21095-DST( movl %ebx, 24(%edi) )
21096+DST( movl %ebx, %es:24(%edi) )
21097 adcl %edx, %eax
21098-DST( movl %edx, 28(%edi) )
21099+DST( movl %edx, %es:28(%edi) )
21100
21101 lea 32(%esi), %esi
21102 lea 32(%edi), %edi
21103@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
21104 shrl $2, %edx # This clears CF
21105 SRC(3: movl (%esi), %ebx )
21106 adcl %ebx, %eax
21107-DST( movl %ebx, (%edi) )
21108+DST( movl %ebx, %es:(%edi) )
21109 lea 4(%esi), %esi
21110 lea 4(%edi), %edi
21111 dec %edx
21112@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
21113 jb 5f
21114 SRC( movw (%esi), %cx )
21115 leal 2(%esi), %esi
21116-DST( movw %cx, (%edi) )
21117+DST( movw %cx, %es:(%edi) )
21118 leal 2(%edi), %edi
21119 je 6f
21120 shll $16,%ecx
21121 SRC(5: movb (%esi), %cl )
21122-DST( movb %cl, (%edi) )
21123+DST( movb %cl, %es:(%edi) )
21124 6: addl %ecx, %eax
21125 adcl $0, %eax
21126 7:
21127@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
21128
21129 6001:
21130 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21131- movl $-EFAULT, (%ebx)
21132+ movl $-EFAULT, %ss:(%ebx)
21133
21134 # zero the complete destination - computing the rest
21135 # is too much work
21136@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
21137
21138 6002:
21139 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21140- movl $-EFAULT,(%ebx)
21141+ movl $-EFAULT,%ss:(%ebx)
21142 jmp 5000b
21143
21144 .previous
21145
21146+ pushl_cfi %ss
21147+ popl_cfi %ds
21148+ pushl_cfi %ss
21149+ popl_cfi %es
21150 popl_cfi %ebx
21151 CFI_RESTORE ebx
21152 popl_cfi %esi
21153@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
21154 popl_cfi %ecx # equivalent to addl $4,%esp
21155 ret
21156 CFI_ENDPROC
21157-ENDPROC(csum_partial_copy_generic)
21158+ENDPROC(csum_partial_copy_generic_to_user)
21159
21160 #else
21161
21162 /* Version for PentiumII/PPro */
21163
21164 #define ROUND1(x) \
21165+ nop; nop; nop; \
21166 SRC(movl x(%esi), %ebx ) ; \
21167 addl %ebx, %eax ; \
21168- DST(movl %ebx, x(%edi) ) ;
21169+ DST(movl %ebx, %es:x(%edi)) ;
21170
21171 #define ROUND(x) \
21172+ nop; nop; nop; \
21173 SRC(movl x(%esi), %ebx ) ; \
21174 adcl %ebx, %eax ; \
21175- DST(movl %ebx, x(%edi) ) ;
21176+ DST(movl %ebx, %es:x(%edi)) ;
21177
21178 #define ARGBASE 12
21179-
21180-ENTRY(csum_partial_copy_generic)
21181+
21182+ENTRY(csum_partial_copy_generic_to_user)
21183 CFI_STARTPROC
21184+
21185+#ifdef CONFIG_PAX_MEMORY_UDEREF
21186+ pushl_cfi %gs
21187+ popl_cfi %es
21188+ jmp csum_partial_copy_generic
21189+#endif
21190+
21191+ENTRY(csum_partial_copy_generic_from_user)
21192+
21193+#ifdef CONFIG_PAX_MEMORY_UDEREF
21194+ pushl_cfi %gs
21195+ popl_cfi %ds
21196+#endif
21197+
21198+ENTRY(csum_partial_copy_generic)
21199 pushl_cfi %ebx
21200 CFI_REL_OFFSET ebx, 0
21201 pushl_cfi %edi
21202@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
21203 subl %ebx, %edi
21204 lea -1(%esi),%edx
21205 andl $-32,%edx
21206- lea 3f(%ebx,%ebx), %ebx
21207+ lea 3f(%ebx,%ebx,2), %ebx
21208 testl %esi, %esi
21209 jmp *%ebx
21210 1: addl $64,%esi
21211@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
21212 jb 5f
21213 SRC( movw (%esi), %dx )
21214 leal 2(%esi), %esi
21215-DST( movw %dx, (%edi) )
21216+DST( movw %dx, %es:(%edi) )
21217 leal 2(%edi), %edi
21218 je 6f
21219 shll $16,%edx
21220 5:
21221 SRC( movb (%esi), %dl )
21222-DST( movb %dl, (%edi) )
21223+DST( movb %dl, %es:(%edi) )
21224 6: addl %edx, %eax
21225 adcl $0, %eax
21226 7:
21227 .section .fixup, "ax"
21228 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21229- movl $-EFAULT, (%ebx)
21230+ movl $-EFAULT, %ss:(%ebx)
21231 # zero the complete destination (computing the rest is too much work)
21232 movl ARGBASE+8(%esp),%edi # dst
21233 movl ARGBASE+12(%esp),%ecx # len
21234@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
21235 rep; stosb
21236 jmp 7b
21237 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21238- movl $-EFAULT, (%ebx)
21239+ movl $-EFAULT, %ss:(%ebx)
21240 jmp 7b
21241 .previous
21242
21243+#ifdef CONFIG_PAX_MEMORY_UDEREF
21244+ pushl_cfi %ss
21245+ popl_cfi %ds
21246+ pushl_cfi %ss
21247+ popl_cfi %es
21248+#endif
21249+
21250 popl_cfi %esi
21251 CFI_RESTORE esi
21252 popl_cfi %edi
21253@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
21254 CFI_RESTORE ebx
21255 ret
21256 CFI_ENDPROC
21257-ENDPROC(csum_partial_copy_generic)
21258+ENDPROC(csum_partial_copy_generic_to_user)
21259
21260 #undef ROUND
21261 #undef ROUND1
21262diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21263index f2145cf..cea889d 100644
21264--- a/arch/x86/lib/clear_page_64.S
21265+++ b/arch/x86/lib/clear_page_64.S
21266@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21267 movl $4096/8,%ecx
21268 xorl %eax,%eax
21269 rep stosq
21270+ pax_force_retaddr
21271 ret
21272 CFI_ENDPROC
21273 ENDPROC(clear_page_c)
21274@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21275 movl $4096,%ecx
21276 xorl %eax,%eax
21277 rep stosb
21278+ pax_force_retaddr
21279 ret
21280 CFI_ENDPROC
21281 ENDPROC(clear_page_c_e)
21282@@ -43,6 +45,7 @@ ENTRY(clear_page)
21283 leaq 64(%rdi),%rdi
21284 jnz .Lloop
21285 nop
21286+ pax_force_retaddr
21287 ret
21288 CFI_ENDPROC
21289 .Lclear_page_end:
21290@@ -58,7 +61,7 @@ ENDPROC(clear_page)
21291
21292 #include <asm/cpufeature.h>
21293
21294- .section .altinstr_replacement,"ax"
21295+ .section .altinstr_replacement,"a"
21296 1: .byte 0xeb /* jmp <disp8> */
21297 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21298 2: .byte 0xeb /* jmp <disp8> */
21299diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21300index 1e572c5..2a162cd 100644
21301--- a/arch/x86/lib/cmpxchg16b_emu.S
21302+++ b/arch/x86/lib/cmpxchg16b_emu.S
21303@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21304
21305 popf
21306 mov $1, %al
21307+ pax_force_retaddr
21308 ret
21309
21310 not_same:
21311 popf
21312 xor %al,%al
21313+ pax_force_retaddr
21314 ret
21315
21316 CFI_ENDPROC
21317diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21318index 6b34d04..dccb07f 100644
21319--- a/arch/x86/lib/copy_page_64.S
21320+++ b/arch/x86/lib/copy_page_64.S
21321@@ -9,6 +9,7 @@ copy_page_c:
21322 CFI_STARTPROC
21323 movl $4096/8,%ecx
21324 rep movsq
21325+ pax_force_retaddr
21326 ret
21327 CFI_ENDPROC
21328 ENDPROC(copy_page_c)
21329@@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21330
21331 ENTRY(copy_page)
21332 CFI_STARTPROC
21333- subq $2*8,%rsp
21334- CFI_ADJUST_CFA_OFFSET 2*8
21335+ subq $3*8,%rsp
21336+ CFI_ADJUST_CFA_OFFSET 3*8
21337 movq %rbx,(%rsp)
21338 CFI_REL_OFFSET rbx, 0
21339 movq %r12,1*8(%rsp)
21340 CFI_REL_OFFSET r12, 1*8
21341+ movq %r13,2*8(%rsp)
21342+ CFI_REL_OFFSET r13, 2*8
21343
21344 movl $(4096/64)-5,%ecx
21345 .p2align 4
21346@@ -37,7 +40,7 @@ ENTRY(copy_page)
21347 movq 16 (%rsi), %rdx
21348 movq 24 (%rsi), %r8
21349 movq 32 (%rsi), %r9
21350- movq 40 (%rsi), %r10
21351+ movq 40 (%rsi), %r13
21352 movq 48 (%rsi), %r11
21353 movq 56 (%rsi), %r12
21354
21355@@ -48,7 +51,7 @@ ENTRY(copy_page)
21356 movq %rdx, 16 (%rdi)
21357 movq %r8, 24 (%rdi)
21358 movq %r9, 32 (%rdi)
21359- movq %r10, 40 (%rdi)
21360+ movq %r13, 40 (%rdi)
21361 movq %r11, 48 (%rdi)
21362 movq %r12, 56 (%rdi)
21363
21364@@ -67,7 +70,7 @@ ENTRY(copy_page)
21365 movq 16 (%rsi), %rdx
21366 movq 24 (%rsi), %r8
21367 movq 32 (%rsi), %r9
21368- movq 40 (%rsi), %r10
21369+ movq 40 (%rsi), %r13
21370 movq 48 (%rsi), %r11
21371 movq 56 (%rsi), %r12
21372
21373@@ -76,7 +79,7 @@ ENTRY(copy_page)
21374 movq %rdx, 16 (%rdi)
21375 movq %r8, 24 (%rdi)
21376 movq %r9, 32 (%rdi)
21377- movq %r10, 40 (%rdi)
21378+ movq %r13, 40 (%rdi)
21379 movq %r11, 48 (%rdi)
21380 movq %r12, 56 (%rdi)
21381
21382@@ -89,8 +92,11 @@ ENTRY(copy_page)
21383 CFI_RESTORE rbx
21384 movq 1*8(%rsp),%r12
21385 CFI_RESTORE r12
21386- addq $2*8,%rsp
21387- CFI_ADJUST_CFA_OFFSET -2*8
21388+ movq 2*8(%rsp),%r13
21389+ CFI_RESTORE r13
21390+ addq $3*8,%rsp
21391+ CFI_ADJUST_CFA_OFFSET -3*8
21392+ pax_force_retaddr
21393 ret
21394 .Lcopy_page_end:
21395 CFI_ENDPROC
21396@@ -101,7 +107,7 @@ ENDPROC(copy_page)
21397
21398 #include <asm/cpufeature.h>
21399
21400- .section .altinstr_replacement,"ax"
21401+ .section .altinstr_replacement,"a"
21402 1: .byte 0xeb /* jmp <disp8> */
21403 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21404 2:
21405diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21406index 5b2995f..78e7644 100644
21407--- a/arch/x86/lib/copy_user_64.S
21408+++ b/arch/x86/lib/copy_user_64.S
21409@@ -17,6 +17,7 @@
21410 #include <asm/cpufeature.h>
21411 #include <asm/alternative-asm.h>
21412 #include <asm/asm.h>
21413+#include <asm/pgtable.h>
21414
21415 /*
21416 * By placing feature2 after feature1 in altinstructions section, we logically
21417@@ -30,7 +31,7 @@
21418 .byte 0xe9 /* 32bit jump */
21419 .long \orig-1f /* by default jump to orig */
21420 1:
21421- .section .altinstr_replacement,"ax"
21422+ .section .altinstr_replacement,"a"
21423 2: .byte 0xe9 /* near jump with 32bit immediate */
21424 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21425 3: .byte 0xe9 /* near jump with 32bit immediate */
21426@@ -69,47 +70,20 @@
21427 #endif
21428 .endm
21429
21430-/* Standard copy_to_user with segment limit checking */
21431-ENTRY(_copy_to_user)
21432- CFI_STARTPROC
21433- GET_THREAD_INFO(%rax)
21434- movq %rdi,%rcx
21435- addq %rdx,%rcx
21436- jc bad_to_user
21437- cmpq TI_addr_limit(%rax),%rcx
21438- ja bad_to_user
21439- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21440- copy_user_generic_unrolled,copy_user_generic_string, \
21441- copy_user_enhanced_fast_string
21442- CFI_ENDPROC
21443-ENDPROC(_copy_to_user)
21444-
21445-/* Standard copy_from_user with segment limit checking */
21446-ENTRY(_copy_from_user)
21447- CFI_STARTPROC
21448- GET_THREAD_INFO(%rax)
21449- movq %rsi,%rcx
21450- addq %rdx,%rcx
21451- jc bad_from_user
21452- cmpq TI_addr_limit(%rax),%rcx
21453- ja bad_from_user
21454- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21455- copy_user_generic_unrolled,copy_user_generic_string, \
21456- copy_user_enhanced_fast_string
21457- CFI_ENDPROC
21458-ENDPROC(_copy_from_user)
21459-
21460 .section .fixup,"ax"
21461 /* must zero dest */
21462 ENTRY(bad_from_user)
21463 bad_from_user:
21464 CFI_STARTPROC
21465+ testl %edx,%edx
21466+ js bad_to_user
21467 movl %edx,%ecx
21468 xorl %eax,%eax
21469 rep
21470 stosb
21471 bad_to_user:
21472 movl %edx,%eax
21473+ pax_force_retaddr
21474 ret
21475 CFI_ENDPROC
21476 ENDPROC(bad_from_user)
21477@@ -139,19 +113,19 @@ ENTRY(copy_user_generic_unrolled)
21478 jz 17f
21479 1: movq (%rsi),%r8
21480 2: movq 1*8(%rsi),%r9
21481-3: movq 2*8(%rsi),%r10
21482+3: movq 2*8(%rsi),%rax
21483 4: movq 3*8(%rsi),%r11
21484 5: movq %r8,(%rdi)
21485 6: movq %r9,1*8(%rdi)
21486-7: movq %r10,2*8(%rdi)
21487+7: movq %rax,2*8(%rdi)
21488 8: movq %r11,3*8(%rdi)
21489 9: movq 4*8(%rsi),%r8
21490 10: movq 5*8(%rsi),%r9
21491-11: movq 6*8(%rsi),%r10
21492+11: movq 6*8(%rsi),%rax
21493 12: movq 7*8(%rsi),%r11
21494 13: movq %r8,4*8(%rdi)
21495 14: movq %r9,5*8(%rdi)
21496-15: movq %r10,6*8(%rdi)
21497+15: movq %rax,6*8(%rdi)
21498 16: movq %r11,7*8(%rdi)
21499 leaq 64(%rsi),%rsi
21500 leaq 64(%rdi),%rdi
21501@@ -177,6 +151,7 @@ ENTRY(copy_user_generic_unrolled)
21502 decl %ecx
21503 jnz 21b
21504 23: xor %eax,%eax
21505+ pax_force_retaddr
21506 ret
21507
21508 .section .fixup,"ax"
21509@@ -246,6 +221,7 @@ ENTRY(copy_user_generic_string)
21510 3: rep
21511 movsb
21512 4: xorl %eax,%eax
21513+ pax_force_retaddr
21514 ret
21515
21516 .section .fixup,"ax"
21517@@ -279,6 +255,7 @@ ENTRY(copy_user_enhanced_fast_string)
21518 1: rep
21519 movsb
21520 2: xorl %eax,%eax
21521+ pax_force_retaddr
21522 ret
21523
21524 .section .fixup,"ax"
21525diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21526index cacddc7..09d49e4 100644
21527--- a/arch/x86/lib/copy_user_nocache_64.S
21528+++ b/arch/x86/lib/copy_user_nocache_64.S
21529@@ -8,6 +8,7 @@
21530
21531 #include <linux/linkage.h>
21532 #include <asm/dwarf2.h>
21533+#include <asm/alternative-asm.h>
21534
21535 #define FIX_ALIGNMENT 1
21536
21537@@ -15,6 +16,7 @@
21538 #include <asm/asm-offsets.h>
21539 #include <asm/thread_info.h>
21540 #include <asm/asm.h>
21541+#include <asm/pgtable.h>
21542
21543 .macro ALIGN_DESTINATION
21544 #ifdef FIX_ALIGNMENT
21545@@ -48,6 +50,15 @@
21546 */
21547 ENTRY(__copy_user_nocache)
21548 CFI_STARTPROC
21549+
21550+#ifdef CONFIG_PAX_MEMORY_UDEREF
21551+ mov $PAX_USER_SHADOW_BASE,%rcx
21552+ cmp %rcx,%rsi
21553+ jae 1f
21554+ add %rcx,%rsi
21555+1:
21556+#endif
21557+
21558 cmpl $8,%edx
21559 jb 20f /* less then 8 bytes, go to byte copy loop */
21560 ALIGN_DESTINATION
21561@@ -57,19 +68,19 @@ ENTRY(__copy_user_nocache)
21562 jz 17f
21563 1: movq (%rsi),%r8
21564 2: movq 1*8(%rsi),%r9
21565-3: movq 2*8(%rsi),%r10
21566+3: movq 2*8(%rsi),%rax
21567 4: movq 3*8(%rsi),%r11
21568 5: movnti %r8,(%rdi)
21569 6: movnti %r9,1*8(%rdi)
21570-7: movnti %r10,2*8(%rdi)
21571+7: movnti %rax,2*8(%rdi)
21572 8: movnti %r11,3*8(%rdi)
21573 9: movq 4*8(%rsi),%r8
21574 10: movq 5*8(%rsi),%r9
21575-11: movq 6*8(%rsi),%r10
21576+11: movq 6*8(%rsi),%rax
21577 12: movq 7*8(%rsi),%r11
21578 13: movnti %r8,4*8(%rdi)
21579 14: movnti %r9,5*8(%rdi)
21580-15: movnti %r10,6*8(%rdi)
21581+15: movnti %rax,6*8(%rdi)
21582 16: movnti %r11,7*8(%rdi)
21583 leaq 64(%rsi),%rsi
21584 leaq 64(%rdi),%rdi
21585@@ -96,6 +107,7 @@ ENTRY(__copy_user_nocache)
21586 jnz 21b
21587 23: xorl %eax,%eax
21588 sfence
21589+ pax_force_retaddr
21590 ret
21591
21592 .section .fixup,"ax"
21593diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21594index 2419d5f..953ee51 100644
21595--- a/arch/x86/lib/csum-copy_64.S
21596+++ b/arch/x86/lib/csum-copy_64.S
21597@@ -9,6 +9,7 @@
21598 #include <asm/dwarf2.h>
21599 #include <asm/errno.h>
21600 #include <asm/asm.h>
21601+#include <asm/alternative-asm.h>
21602
21603 /*
21604 * Checksum copy with exception handling.
21605@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
21606 CFI_RESTORE rbp
21607 addq $7*8, %rsp
21608 CFI_ADJUST_CFA_OFFSET -7*8
21609+ pax_force_retaddr 0, 1
21610 ret
21611 CFI_RESTORE_STATE
21612
21613diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21614index 25b7ae8..3b52ccd 100644
21615--- a/arch/x86/lib/csum-wrappers_64.c
21616+++ b/arch/x86/lib/csum-wrappers_64.c
21617@@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21618 len -= 2;
21619 }
21620 }
21621- isum = csum_partial_copy_generic((__force const void *)src,
21622+
21623+#ifdef CONFIG_PAX_MEMORY_UDEREF
21624+ if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21625+ src += PAX_USER_SHADOW_BASE;
21626+#endif
21627+
21628+ isum = csum_partial_copy_generic((const void __force_kernel *)src,
21629 dst, len, isum, errp, NULL);
21630 if (unlikely(*errp))
21631 goto out_err;
21632@@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21633 }
21634
21635 *errp = 0;
21636- return csum_partial_copy_generic(src, (void __force *)dst,
21637+
21638+#ifdef CONFIG_PAX_MEMORY_UDEREF
21639+ if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21640+ dst += PAX_USER_SHADOW_BASE;
21641+#endif
21642+
21643+ return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21644 len, isum, NULL, errp);
21645 }
21646 EXPORT_SYMBOL(csum_partial_copy_to_user);
21647diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21648index b33b1fb..219f389 100644
21649--- a/arch/x86/lib/getuser.S
21650+++ b/arch/x86/lib/getuser.S
21651@@ -33,15 +33,38 @@
21652 #include <asm/asm-offsets.h>
21653 #include <asm/thread_info.h>
21654 #include <asm/asm.h>
21655+#include <asm/segment.h>
21656+#include <asm/pgtable.h>
21657+#include <asm/alternative-asm.h>
21658+
21659+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21660+#define __copyuser_seg gs;
21661+#else
21662+#define __copyuser_seg
21663+#endif
21664
21665 .text
21666 ENTRY(__get_user_1)
21667 CFI_STARTPROC
21668+
21669+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21670 GET_THREAD_INFO(%_ASM_DX)
21671 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21672 jae bad_get_user
21673-1: movzb (%_ASM_AX),%edx
21674+
21675+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21676+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21677+ cmp %_ASM_DX,%_ASM_AX
21678+ jae 1234f
21679+ add %_ASM_DX,%_ASM_AX
21680+1234:
21681+#endif
21682+
21683+#endif
21684+
21685+1: __copyuser_seg movzb (%_ASM_AX),%edx
21686 xor %eax,%eax
21687+ pax_force_retaddr
21688 ret
21689 CFI_ENDPROC
21690 ENDPROC(__get_user_1)
21691@@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21692 ENTRY(__get_user_2)
21693 CFI_STARTPROC
21694 add $1,%_ASM_AX
21695+
21696+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21697 jc bad_get_user
21698 GET_THREAD_INFO(%_ASM_DX)
21699 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21700 jae bad_get_user
21701-2: movzwl -1(%_ASM_AX),%edx
21702+
21703+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21704+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21705+ cmp %_ASM_DX,%_ASM_AX
21706+ jae 1234f
21707+ add %_ASM_DX,%_ASM_AX
21708+1234:
21709+#endif
21710+
21711+#endif
21712+
21713+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21714 xor %eax,%eax
21715+ pax_force_retaddr
21716 ret
21717 CFI_ENDPROC
21718 ENDPROC(__get_user_2)
21719@@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21720 ENTRY(__get_user_4)
21721 CFI_STARTPROC
21722 add $3,%_ASM_AX
21723+
21724+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21725 jc bad_get_user
21726 GET_THREAD_INFO(%_ASM_DX)
21727 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21728 jae bad_get_user
21729-3: mov -3(%_ASM_AX),%edx
21730+
21731+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21732+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21733+ cmp %_ASM_DX,%_ASM_AX
21734+ jae 1234f
21735+ add %_ASM_DX,%_ASM_AX
21736+1234:
21737+#endif
21738+
21739+#endif
21740+
21741+3: __copyuser_seg mov -3(%_ASM_AX),%edx
21742 xor %eax,%eax
21743+ pax_force_retaddr
21744 ret
21745 CFI_ENDPROC
21746 ENDPROC(__get_user_4)
21747@@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21748 GET_THREAD_INFO(%_ASM_DX)
21749 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21750 jae bad_get_user
21751+
21752+#ifdef CONFIG_PAX_MEMORY_UDEREF
21753+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21754+ cmp %_ASM_DX,%_ASM_AX
21755+ jae 1234f
21756+ add %_ASM_DX,%_ASM_AX
21757+1234:
21758+#endif
21759+
21760 4: movq -7(%_ASM_AX),%_ASM_DX
21761 xor %eax,%eax
21762+ pax_force_retaddr
21763 ret
21764 CFI_ENDPROC
21765 ENDPROC(__get_user_8)
21766@@ -91,6 +152,7 @@ bad_get_user:
21767 CFI_STARTPROC
21768 xor %edx,%edx
21769 mov $(-EFAULT),%_ASM_AX
21770+ pax_force_retaddr
21771 ret
21772 CFI_ENDPROC
21773 END(bad_get_user)
21774diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21775index b1e6c4b..21ae8fc 100644
21776--- a/arch/x86/lib/insn.c
21777+++ b/arch/x86/lib/insn.c
21778@@ -21,6 +21,11 @@
21779 #include <linux/string.h>
21780 #include <asm/inat.h>
21781 #include <asm/insn.h>
21782+#ifdef __KERNEL__
21783+#include <asm/pgtable_types.h>
21784+#else
21785+#define ktla_ktva(addr) addr
21786+#endif
21787
21788 /* Verify next sizeof(t) bytes can be on the same instruction */
21789 #define validate_next(t, insn, n) \
21790@@ -49,8 +54,8 @@
21791 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21792 {
21793 memset(insn, 0, sizeof(*insn));
21794- insn->kaddr = kaddr;
21795- insn->next_byte = kaddr;
21796+ insn->kaddr = ktla_ktva(kaddr);
21797+ insn->next_byte = ktla_ktva(kaddr);
21798 insn->x86_64 = x86_64 ? 1 : 0;
21799 insn->opnd_bytes = 4;
21800 if (x86_64)
21801diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21802index 05a95e7..326f2fa 100644
21803--- a/arch/x86/lib/iomap_copy_64.S
21804+++ b/arch/x86/lib/iomap_copy_64.S
21805@@ -17,6 +17,7 @@
21806
21807 #include <linux/linkage.h>
21808 #include <asm/dwarf2.h>
21809+#include <asm/alternative-asm.h>
21810
21811 /*
21812 * override generic version in lib/iomap_copy.c
21813@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21814 CFI_STARTPROC
21815 movl %edx,%ecx
21816 rep movsd
21817+ pax_force_retaddr
21818 ret
21819 CFI_ENDPROC
21820 ENDPROC(__iowrite32_copy)
21821diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21822index 1c273be..da9cc0e 100644
21823--- a/arch/x86/lib/memcpy_64.S
21824+++ b/arch/x86/lib/memcpy_64.S
21825@@ -33,6 +33,7 @@
21826 rep movsq
21827 movl %edx, %ecx
21828 rep movsb
21829+ pax_force_retaddr
21830 ret
21831 .Lmemcpy_e:
21832 .previous
21833@@ -49,6 +50,7 @@
21834 movq %rdi, %rax
21835 movq %rdx, %rcx
21836 rep movsb
21837+ pax_force_retaddr
21838 ret
21839 .Lmemcpy_e_e:
21840 .previous
21841@@ -76,13 +78,13 @@ ENTRY(memcpy)
21842 */
21843 movq 0*8(%rsi), %r8
21844 movq 1*8(%rsi), %r9
21845- movq 2*8(%rsi), %r10
21846+ movq 2*8(%rsi), %rcx
21847 movq 3*8(%rsi), %r11
21848 leaq 4*8(%rsi), %rsi
21849
21850 movq %r8, 0*8(%rdi)
21851 movq %r9, 1*8(%rdi)
21852- movq %r10, 2*8(%rdi)
21853+ movq %rcx, 2*8(%rdi)
21854 movq %r11, 3*8(%rdi)
21855 leaq 4*8(%rdi), %rdi
21856 jae .Lcopy_forward_loop
21857@@ -105,12 +107,12 @@ ENTRY(memcpy)
21858 subq $0x20, %rdx
21859 movq -1*8(%rsi), %r8
21860 movq -2*8(%rsi), %r9
21861- movq -3*8(%rsi), %r10
21862+ movq -3*8(%rsi), %rcx
21863 movq -4*8(%rsi), %r11
21864 leaq -4*8(%rsi), %rsi
21865 movq %r8, -1*8(%rdi)
21866 movq %r9, -2*8(%rdi)
21867- movq %r10, -3*8(%rdi)
21868+ movq %rcx, -3*8(%rdi)
21869 movq %r11, -4*8(%rdi)
21870 leaq -4*8(%rdi), %rdi
21871 jae .Lcopy_backward_loop
21872@@ -130,12 +132,13 @@ ENTRY(memcpy)
21873 */
21874 movq 0*8(%rsi), %r8
21875 movq 1*8(%rsi), %r9
21876- movq -2*8(%rsi, %rdx), %r10
21877+ movq -2*8(%rsi, %rdx), %rcx
21878 movq -1*8(%rsi, %rdx), %r11
21879 movq %r8, 0*8(%rdi)
21880 movq %r9, 1*8(%rdi)
21881- movq %r10, -2*8(%rdi, %rdx)
21882+ movq %rcx, -2*8(%rdi, %rdx)
21883 movq %r11, -1*8(%rdi, %rdx)
21884+ pax_force_retaddr
21885 retq
21886 .p2align 4
21887 .Lless_16bytes:
21888@@ -148,6 +151,7 @@ ENTRY(memcpy)
21889 movq -1*8(%rsi, %rdx), %r9
21890 movq %r8, 0*8(%rdi)
21891 movq %r9, -1*8(%rdi, %rdx)
21892+ pax_force_retaddr
21893 retq
21894 .p2align 4
21895 .Lless_8bytes:
21896@@ -161,6 +165,7 @@ ENTRY(memcpy)
21897 movl -4(%rsi, %rdx), %r8d
21898 movl %ecx, (%rdi)
21899 movl %r8d, -4(%rdi, %rdx)
21900+ pax_force_retaddr
21901 retq
21902 .p2align 4
21903 .Lless_3bytes:
21904@@ -179,6 +184,7 @@ ENTRY(memcpy)
21905 movb %cl, (%rdi)
21906
21907 .Lend:
21908+ pax_force_retaddr
21909 retq
21910 CFI_ENDPROC
21911 ENDPROC(memcpy)
21912diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
21913index ee16461..c39c199 100644
21914--- a/arch/x86/lib/memmove_64.S
21915+++ b/arch/x86/lib/memmove_64.S
21916@@ -61,13 +61,13 @@ ENTRY(memmove)
21917 5:
21918 sub $0x20, %rdx
21919 movq 0*8(%rsi), %r11
21920- movq 1*8(%rsi), %r10
21921+ movq 1*8(%rsi), %rcx
21922 movq 2*8(%rsi), %r9
21923 movq 3*8(%rsi), %r8
21924 leaq 4*8(%rsi), %rsi
21925
21926 movq %r11, 0*8(%rdi)
21927- movq %r10, 1*8(%rdi)
21928+ movq %rcx, 1*8(%rdi)
21929 movq %r9, 2*8(%rdi)
21930 movq %r8, 3*8(%rdi)
21931 leaq 4*8(%rdi), %rdi
21932@@ -81,10 +81,10 @@ ENTRY(memmove)
21933 4:
21934 movq %rdx, %rcx
21935 movq -8(%rsi, %rdx), %r11
21936- lea -8(%rdi, %rdx), %r10
21937+ lea -8(%rdi, %rdx), %r9
21938 shrq $3, %rcx
21939 rep movsq
21940- movq %r11, (%r10)
21941+ movq %r11, (%r9)
21942 jmp 13f
21943 .Lmemmove_end_forward:
21944
21945@@ -95,14 +95,14 @@ ENTRY(memmove)
21946 7:
21947 movq %rdx, %rcx
21948 movq (%rsi), %r11
21949- movq %rdi, %r10
21950+ movq %rdi, %r9
21951 leaq -8(%rsi, %rdx), %rsi
21952 leaq -8(%rdi, %rdx), %rdi
21953 shrq $3, %rcx
21954 std
21955 rep movsq
21956 cld
21957- movq %r11, (%r10)
21958+ movq %r11, (%r9)
21959 jmp 13f
21960
21961 /*
21962@@ -127,13 +127,13 @@ ENTRY(memmove)
21963 8:
21964 subq $0x20, %rdx
21965 movq -1*8(%rsi), %r11
21966- movq -2*8(%rsi), %r10
21967+ movq -2*8(%rsi), %rcx
21968 movq -3*8(%rsi), %r9
21969 movq -4*8(%rsi), %r8
21970 leaq -4*8(%rsi), %rsi
21971
21972 movq %r11, -1*8(%rdi)
21973- movq %r10, -2*8(%rdi)
21974+ movq %rcx, -2*8(%rdi)
21975 movq %r9, -3*8(%rdi)
21976 movq %r8, -4*8(%rdi)
21977 leaq -4*8(%rdi), %rdi
21978@@ -151,11 +151,11 @@ ENTRY(memmove)
21979 * Move data from 16 bytes to 31 bytes.
21980 */
21981 movq 0*8(%rsi), %r11
21982- movq 1*8(%rsi), %r10
21983+ movq 1*8(%rsi), %rcx
21984 movq -2*8(%rsi, %rdx), %r9
21985 movq -1*8(%rsi, %rdx), %r8
21986 movq %r11, 0*8(%rdi)
21987- movq %r10, 1*8(%rdi)
21988+ movq %rcx, 1*8(%rdi)
21989 movq %r9, -2*8(%rdi, %rdx)
21990 movq %r8, -1*8(%rdi, %rdx)
21991 jmp 13f
21992@@ -167,9 +167,9 @@ ENTRY(memmove)
21993 * Move data from 8 bytes to 15 bytes.
21994 */
21995 movq 0*8(%rsi), %r11
21996- movq -1*8(%rsi, %rdx), %r10
21997+ movq -1*8(%rsi, %rdx), %r9
21998 movq %r11, 0*8(%rdi)
21999- movq %r10, -1*8(%rdi, %rdx)
22000+ movq %r9, -1*8(%rdi, %rdx)
22001 jmp 13f
22002 10:
22003 cmpq $4, %rdx
22004@@ -178,9 +178,9 @@ ENTRY(memmove)
22005 * Move data from 4 bytes to 7 bytes.
22006 */
22007 movl (%rsi), %r11d
22008- movl -4(%rsi, %rdx), %r10d
22009+ movl -4(%rsi, %rdx), %r9d
22010 movl %r11d, (%rdi)
22011- movl %r10d, -4(%rdi, %rdx)
22012+ movl %r9d, -4(%rdi, %rdx)
22013 jmp 13f
22014 11:
22015 cmp $2, %rdx
22016@@ -189,9 +189,9 @@ ENTRY(memmove)
22017 * Move data from 2 bytes to 3 bytes.
22018 */
22019 movw (%rsi), %r11w
22020- movw -2(%rsi, %rdx), %r10w
22021+ movw -2(%rsi, %rdx), %r9w
22022 movw %r11w, (%rdi)
22023- movw %r10w, -2(%rdi, %rdx)
22024+ movw %r9w, -2(%rdi, %rdx)
22025 jmp 13f
22026 12:
22027 cmp $1, %rdx
22028@@ -202,6 +202,7 @@ ENTRY(memmove)
22029 movb (%rsi), %r11b
22030 movb %r11b, (%rdi)
22031 13:
22032+ pax_force_retaddr
22033 retq
22034 CFI_ENDPROC
22035
22036@@ -210,6 +211,7 @@ ENTRY(memmove)
22037 /* Forward moving data. */
22038 movq %rdx, %rcx
22039 rep movsb
22040+ pax_force_retaddr
22041 retq
22042 .Lmemmove_end_forward_efs:
22043 .previous
22044diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22045index 2dcb380..963660a 100644
22046--- a/arch/x86/lib/memset_64.S
22047+++ b/arch/x86/lib/memset_64.S
22048@@ -30,6 +30,7 @@
22049 movl %edx,%ecx
22050 rep stosb
22051 movq %r9,%rax
22052+ pax_force_retaddr
22053 ret
22054 .Lmemset_e:
22055 .previous
22056@@ -52,6 +53,7 @@
22057 movq %rdx,%rcx
22058 rep stosb
22059 movq %r9,%rax
22060+ pax_force_retaddr
22061 ret
22062 .Lmemset_e_e:
22063 .previous
22064@@ -59,7 +61,7 @@
22065 ENTRY(memset)
22066 ENTRY(__memset)
22067 CFI_STARTPROC
22068- movq %rdi,%r10
22069+ movq %rdi,%r11
22070
22071 /* expand byte value */
22072 movzbl %sil,%ecx
22073@@ -117,7 +119,8 @@ ENTRY(__memset)
22074 jnz .Lloop_1
22075
22076 .Lende:
22077- movq %r10,%rax
22078+ movq %r11,%rax
22079+ pax_force_retaddr
22080 ret
22081
22082 CFI_RESTORE_STATE
22083diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22084index c9f2d9b..e7fd2c0 100644
22085--- a/arch/x86/lib/mmx_32.c
22086+++ b/arch/x86/lib/mmx_32.c
22087@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22088 {
22089 void *p;
22090 int i;
22091+ unsigned long cr0;
22092
22093 if (unlikely(in_interrupt()))
22094 return __memcpy(to, from, len);
22095@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22096 kernel_fpu_begin();
22097
22098 __asm__ __volatile__ (
22099- "1: prefetch (%0)\n" /* This set is 28 bytes */
22100- " prefetch 64(%0)\n"
22101- " prefetch 128(%0)\n"
22102- " prefetch 192(%0)\n"
22103- " prefetch 256(%0)\n"
22104+ "1: prefetch (%1)\n" /* This set is 28 bytes */
22105+ " prefetch 64(%1)\n"
22106+ " prefetch 128(%1)\n"
22107+ " prefetch 192(%1)\n"
22108+ " prefetch 256(%1)\n"
22109 "2: \n"
22110 ".section .fixup, \"ax\"\n"
22111- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22112+ "3: \n"
22113+
22114+#ifdef CONFIG_PAX_KERNEXEC
22115+ " movl %%cr0, %0\n"
22116+ " movl %0, %%eax\n"
22117+ " andl $0xFFFEFFFF, %%eax\n"
22118+ " movl %%eax, %%cr0\n"
22119+#endif
22120+
22121+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22122+
22123+#ifdef CONFIG_PAX_KERNEXEC
22124+ " movl %0, %%cr0\n"
22125+#endif
22126+
22127 " jmp 2b\n"
22128 ".previous\n"
22129 _ASM_EXTABLE(1b, 3b)
22130- : : "r" (from));
22131+ : "=&r" (cr0) : "r" (from) : "ax");
22132
22133 for ( ; i > 5; i--) {
22134 __asm__ __volatile__ (
22135- "1: prefetch 320(%0)\n"
22136- "2: movq (%0), %%mm0\n"
22137- " movq 8(%0), %%mm1\n"
22138- " movq 16(%0), %%mm2\n"
22139- " movq 24(%0), %%mm3\n"
22140- " movq %%mm0, (%1)\n"
22141- " movq %%mm1, 8(%1)\n"
22142- " movq %%mm2, 16(%1)\n"
22143- " movq %%mm3, 24(%1)\n"
22144- " movq 32(%0), %%mm0\n"
22145- " movq 40(%0), %%mm1\n"
22146- " movq 48(%0), %%mm2\n"
22147- " movq 56(%0), %%mm3\n"
22148- " movq %%mm0, 32(%1)\n"
22149- " movq %%mm1, 40(%1)\n"
22150- " movq %%mm2, 48(%1)\n"
22151- " movq %%mm3, 56(%1)\n"
22152+ "1: prefetch 320(%1)\n"
22153+ "2: movq (%1), %%mm0\n"
22154+ " movq 8(%1), %%mm1\n"
22155+ " movq 16(%1), %%mm2\n"
22156+ " movq 24(%1), %%mm3\n"
22157+ " movq %%mm0, (%2)\n"
22158+ " movq %%mm1, 8(%2)\n"
22159+ " movq %%mm2, 16(%2)\n"
22160+ " movq %%mm3, 24(%2)\n"
22161+ " movq 32(%1), %%mm0\n"
22162+ " movq 40(%1), %%mm1\n"
22163+ " movq 48(%1), %%mm2\n"
22164+ " movq 56(%1), %%mm3\n"
22165+ " movq %%mm0, 32(%2)\n"
22166+ " movq %%mm1, 40(%2)\n"
22167+ " movq %%mm2, 48(%2)\n"
22168+ " movq %%mm3, 56(%2)\n"
22169 ".section .fixup, \"ax\"\n"
22170- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22171+ "3:\n"
22172+
22173+#ifdef CONFIG_PAX_KERNEXEC
22174+ " movl %%cr0, %0\n"
22175+ " movl %0, %%eax\n"
22176+ " andl $0xFFFEFFFF, %%eax\n"
22177+ " movl %%eax, %%cr0\n"
22178+#endif
22179+
22180+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22181+
22182+#ifdef CONFIG_PAX_KERNEXEC
22183+ " movl %0, %%cr0\n"
22184+#endif
22185+
22186 " jmp 2b\n"
22187 ".previous\n"
22188 _ASM_EXTABLE(1b, 3b)
22189- : : "r" (from), "r" (to) : "memory");
22190+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22191
22192 from += 64;
22193 to += 64;
22194@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22195 static void fast_copy_page(void *to, void *from)
22196 {
22197 int i;
22198+ unsigned long cr0;
22199
22200 kernel_fpu_begin();
22201
22202@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22203 * but that is for later. -AV
22204 */
22205 __asm__ __volatile__(
22206- "1: prefetch (%0)\n"
22207- " prefetch 64(%0)\n"
22208- " prefetch 128(%0)\n"
22209- " prefetch 192(%0)\n"
22210- " prefetch 256(%0)\n"
22211+ "1: prefetch (%1)\n"
22212+ " prefetch 64(%1)\n"
22213+ " prefetch 128(%1)\n"
22214+ " prefetch 192(%1)\n"
22215+ " prefetch 256(%1)\n"
22216 "2: \n"
22217 ".section .fixup, \"ax\"\n"
22218- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22219+ "3: \n"
22220+
22221+#ifdef CONFIG_PAX_KERNEXEC
22222+ " movl %%cr0, %0\n"
22223+ " movl %0, %%eax\n"
22224+ " andl $0xFFFEFFFF, %%eax\n"
22225+ " movl %%eax, %%cr0\n"
22226+#endif
22227+
22228+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22229+
22230+#ifdef CONFIG_PAX_KERNEXEC
22231+ " movl %0, %%cr0\n"
22232+#endif
22233+
22234 " jmp 2b\n"
22235 ".previous\n"
22236- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22237+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22238
22239 for (i = 0; i < (4096-320)/64; i++) {
22240 __asm__ __volatile__ (
22241- "1: prefetch 320(%0)\n"
22242- "2: movq (%0), %%mm0\n"
22243- " movntq %%mm0, (%1)\n"
22244- " movq 8(%0), %%mm1\n"
22245- " movntq %%mm1, 8(%1)\n"
22246- " movq 16(%0), %%mm2\n"
22247- " movntq %%mm2, 16(%1)\n"
22248- " movq 24(%0), %%mm3\n"
22249- " movntq %%mm3, 24(%1)\n"
22250- " movq 32(%0), %%mm4\n"
22251- " movntq %%mm4, 32(%1)\n"
22252- " movq 40(%0), %%mm5\n"
22253- " movntq %%mm5, 40(%1)\n"
22254- " movq 48(%0), %%mm6\n"
22255- " movntq %%mm6, 48(%1)\n"
22256- " movq 56(%0), %%mm7\n"
22257- " movntq %%mm7, 56(%1)\n"
22258+ "1: prefetch 320(%1)\n"
22259+ "2: movq (%1), %%mm0\n"
22260+ " movntq %%mm0, (%2)\n"
22261+ " movq 8(%1), %%mm1\n"
22262+ " movntq %%mm1, 8(%2)\n"
22263+ " movq 16(%1), %%mm2\n"
22264+ " movntq %%mm2, 16(%2)\n"
22265+ " movq 24(%1), %%mm3\n"
22266+ " movntq %%mm3, 24(%2)\n"
22267+ " movq 32(%1), %%mm4\n"
22268+ " movntq %%mm4, 32(%2)\n"
22269+ " movq 40(%1), %%mm5\n"
22270+ " movntq %%mm5, 40(%2)\n"
22271+ " movq 48(%1), %%mm6\n"
22272+ " movntq %%mm6, 48(%2)\n"
22273+ " movq 56(%1), %%mm7\n"
22274+ " movntq %%mm7, 56(%2)\n"
22275 ".section .fixup, \"ax\"\n"
22276- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22277+ "3:\n"
22278+
22279+#ifdef CONFIG_PAX_KERNEXEC
22280+ " movl %%cr0, %0\n"
22281+ " movl %0, %%eax\n"
22282+ " andl $0xFFFEFFFF, %%eax\n"
22283+ " movl %%eax, %%cr0\n"
22284+#endif
22285+
22286+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22287+
22288+#ifdef CONFIG_PAX_KERNEXEC
22289+ " movl %0, %%cr0\n"
22290+#endif
22291+
22292 " jmp 2b\n"
22293 ".previous\n"
22294- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22295+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22296
22297 from += 64;
22298 to += 64;
22299@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22300 static void fast_copy_page(void *to, void *from)
22301 {
22302 int i;
22303+ unsigned long cr0;
22304
22305 kernel_fpu_begin();
22306
22307 __asm__ __volatile__ (
22308- "1: prefetch (%0)\n"
22309- " prefetch 64(%0)\n"
22310- " prefetch 128(%0)\n"
22311- " prefetch 192(%0)\n"
22312- " prefetch 256(%0)\n"
22313+ "1: prefetch (%1)\n"
22314+ " prefetch 64(%1)\n"
22315+ " prefetch 128(%1)\n"
22316+ " prefetch 192(%1)\n"
22317+ " prefetch 256(%1)\n"
22318 "2: \n"
22319 ".section .fixup, \"ax\"\n"
22320- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22321+ "3: \n"
22322+
22323+#ifdef CONFIG_PAX_KERNEXEC
22324+ " movl %%cr0, %0\n"
22325+ " movl %0, %%eax\n"
22326+ " andl $0xFFFEFFFF, %%eax\n"
22327+ " movl %%eax, %%cr0\n"
22328+#endif
22329+
22330+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22331+
22332+#ifdef CONFIG_PAX_KERNEXEC
22333+ " movl %0, %%cr0\n"
22334+#endif
22335+
22336 " jmp 2b\n"
22337 ".previous\n"
22338- _ASM_EXTABLE(1b, 3b) : : "r" (from));
22339+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22340
22341 for (i = 0; i < 4096/64; i++) {
22342 __asm__ __volatile__ (
22343- "1: prefetch 320(%0)\n"
22344- "2: movq (%0), %%mm0\n"
22345- " movq 8(%0), %%mm1\n"
22346- " movq 16(%0), %%mm2\n"
22347- " movq 24(%0), %%mm3\n"
22348- " movq %%mm0, (%1)\n"
22349- " movq %%mm1, 8(%1)\n"
22350- " movq %%mm2, 16(%1)\n"
22351- " movq %%mm3, 24(%1)\n"
22352- " movq 32(%0), %%mm0\n"
22353- " movq 40(%0), %%mm1\n"
22354- " movq 48(%0), %%mm2\n"
22355- " movq 56(%0), %%mm3\n"
22356- " movq %%mm0, 32(%1)\n"
22357- " movq %%mm1, 40(%1)\n"
22358- " movq %%mm2, 48(%1)\n"
22359- " movq %%mm3, 56(%1)\n"
22360+ "1: prefetch 320(%1)\n"
22361+ "2: movq (%1), %%mm0\n"
22362+ " movq 8(%1), %%mm1\n"
22363+ " movq 16(%1), %%mm2\n"
22364+ " movq 24(%1), %%mm3\n"
22365+ " movq %%mm0, (%2)\n"
22366+ " movq %%mm1, 8(%2)\n"
22367+ " movq %%mm2, 16(%2)\n"
22368+ " movq %%mm3, 24(%2)\n"
22369+ " movq 32(%1), %%mm0\n"
22370+ " movq 40(%1), %%mm1\n"
22371+ " movq 48(%1), %%mm2\n"
22372+ " movq 56(%1), %%mm3\n"
22373+ " movq %%mm0, 32(%2)\n"
22374+ " movq %%mm1, 40(%2)\n"
22375+ " movq %%mm2, 48(%2)\n"
22376+ " movq %%mm3, 56(%2)\n"
22377 ".section .fixup, \"ax\"\n"
22378- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22379+ "3:\n"
22380+
22381+#ifdef CONFIG_PAX_KERNEXEC
22382+ " movl %%cr0, %0\n"
22383+ " movl %0, %%eax\n"
22384+ " andl $0xFFFEFFFF, %%eax\n"
22385+ " movl %%eax, %%cr0\n"
22386+#endif
22387+
22388+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22389+
22390+#ifdef CONFIG_PAX_KERNEXEC
22391+ " movl %0, %%cr0\n"
22392+#endif
22393+
22394 " jmp 2b\n"
22395 ".previous\n"
22396 _ASM_EXTABLE(1b, 3b)
22397- : : "r" (from), "r" (to) : "memory");
22398+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22399
22400 from += 64;
22401 to += 64;
22402diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22403index 69fa106..adda88b 100644
22404--- a/arch/x86/lib/msr-reg.S
22405+++ b/arch/x86/lib/msr-reg.S
22406@@ -3,6 +3,7 @@
22407 #include <asm/dwarf2.h>
22408 #include <asm/asm.h>
22409 #include <asm/msr.h>
22410+#include <asm/alternative-asm.h>
22411
22412 #ifdef CONFIG_X86_64
22413 /*
22414@@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
22415 CFI_STARTPROC
22416 pushq_cfi %rbx
22417 pushq_cfi %rbp
22418- movq %rdi, %r10 /* Save pointer */
22419+ movq %rdi, %r9 /* Save pointer */
22420 xorl %r11d, %r11d /* Return value */
22421 movl (%rdi), %eax
22422 movl 4(%rdi), %ecx
22423@@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
22424 movl 28(%rdi), %edi
22425 CFI_REMEMBER_STATE
22426 1: \op
22427-2: movl %eax, (%r10)
22428+2: movl %eax, (%r9)
22429 movl %r11d, %eax /* Return value */
22430- movl %ecx, 4(%r10)
22431- movl %edx, 8(%r10)
22432- movl %ebx, 12(%r10)
22433- movl %ebp, 20(%r10)
22434- movl %esi, 24(%r10)
22435- movl %edi, 28(%r10)
22436+ movl %ecx, 4(%r9)
22437+ movl %edx, 8(%r9)
22438+ movl %ebx, 12(%r9)
22439+ movl %ebp, 20(%r9)
22440+ movl %esi, 24(%r9)
22441+ movl %edi, 28(%r9)
22442 popq_cfi %rbp
22443 popq_cfi %rbx
22444+ pax_force_retaddr
22445 ret
22446 3:
22447 CFI_RESTORE_STATE
22448diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22449index 7f951c8..ebd573a 100644
22450--- a/arch/x86/lib/putuser.S
22451+++ b/arch/x86/lib/putuser.S
22452@@ -15,7 +15,9 @@
22453 #include <asm/thread_info.h>
22454 #include <asm/errno.h>
22455 #include <asm/asm.h>
22456-
22457+#include <asm/segment.h>
22458+#include <asm/pgtable.h>
22459+#include <asm/alternative-asm.h>
22460
22461 /*
22462 * __put_user_X
22463@@ -29,52 +31,119 @@
22464 * as they get called from within inline assembly.
22465 */
22466
22467-#define ENTER CFI_STARTPROC ; \
22468- GET_THREAD_INFO(%_ASM_BX)
22469-#define EXIT ret ; \
22470+#define ENTER CFI_STARTPROC
22471+#define EXIT pax_force_retaddr; ret ; \
22472 CFI_ENDPROC
22473
22474+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22475+#define _DEST %_ASM_CX,%_ASM_BX
22476+#else
22477+#define _DEST %_ASM_CX
22478+#endif
22479+
22480+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22481+#define __copyuser_seg gs;
22482+#else
22483+#define __copyuser_seg
22484+#endif
22485+
22486 .text
22487 ENTRY(__put_user_1)
22488 ENTER
22489+
22490+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22491+ GET_THREAD_INFO(%_ASM_BX)
22492 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22493 jae bad_put_user
22494-1: movb %al,(%_ASM_CX)
22495+
22496+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22497+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22498+ cmp %_ASM_BX,%_ASM_CX
22499+ jb 1234f
22500+ xor %ebx,%ebx
22501+1234:
22502+#endif
22503+
22504+#endif
22505+
22506+1: __copyuser_seg movb %al,(_DEST)
22507 xor %eax,%eax
22508 EXIT
22509 ENDPROC(__put_user_1)
22510
22511 ENTRY(__put_user_2)
22512 ENTER
22513+
22514+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22515+ GET_THREAD_INFO(%_ASM_BX)
22516 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22517 sub $1,%_ASM_BX
22518 cmp %_ASM_BX,%_ASM_CX
22519 jae bad_put_user
22520-2: movw %ax,(%_ASM_CX)
22521+
22522+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22523+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22524+ cmp %_ASM_BX,%_ASM_CX
22525+ jb 1234f
22526+ xor %ebx,%ebx
22527+1234:
22528+#endif
22529+
22530+#endif
22531+
22532+2: __copyuser_seg movw %ax,(_DEST)
22533 xor %eax,%eax
22534 EXIT
22535 ENDPROC(__put_user_2)
22536
22537 ENTRY(__put_user_4)
22538 ENTER
22539+
22540+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22541+ GET_THREAD_INFO(%_ASM_BX)
22542 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22543 sub $3,%_ASM_BX
22544 cmp %_ASM_BX,%_ASM_CX
22545 jae bad_put_user
22546-3: movl %eax,(%_ASM_CX)
22547+
22548+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22549+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22550+ cmp %_ASM_BX,%_ASM_CX
22551+ jb 1234f
22552+ xor %ebx,%ebx
22553+1234:
22554+#endif
22555+
22556+#endif
22557+
22558+3: __copyuser_seg movl %eax,(_DEST)
22559 xor %eax,%eax
22560 EXIT
22561 ENDPROC(__put_user_4)
22562
22563 ENTRY(__put_user_8)
22564 ENTER
22565+
22566+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22567+ GET_THREAD_INFO(%_ASM_BX)
22568 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22569 sub $7,%_ASM_BX
22570 cmp %_ASM_BX,%_ASM_CX
22571 jae bad_put_user
22572-4: mov %_ASM_AX,(%_ASM_CX)
22573+
22574+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22575+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22576+ cmp %_ASM_BX,%_ASM_CX
22577+ jb 1234f
22578+ xor %ebx,%ebx
22579+1234:
22580+#endif
22581+
22582+#endif
22583+
22584+4: __copyuser_seg mov %_ASM_AX,(_DEST)
22585 #ifdef CONFIG_X86_32
22586-5: movl %edx,4(%_ASM_CX)
22587+5: __copyuser_seg movl %edx,4(_DEST)
22588 #endif
22589 xor %eax,%eax
22590 EXIT
22591diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22592index 1cad221..de671ee 100644
22593--- a/arch/x86/lib/rwlock.S
22594+++ b/arch/x86/lib/rwlock.S
22595@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22596 FRAME
22597 0: LOCK_PREFIX
22598 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22599+
22600+#ifdef CONFIG_PAX_REFCOUNT
22601+ jno 1234f
22602+ LOCK_PREFIX
22603+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22604+ int $4
22605+1234:
22606+ _ASM_EXTABLE(1234b, 1234b)
22607+#endif
22608+
22609 1: rep; nop
22610 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22611 jne 1b
22612 LOCK_PREFIX
22613 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22614+
22615+#ifdef CONFIG_PAX_REFCOUNT
22616+ jno 1234f
22617+ LOCK_PREFIX
22618+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22619+ int $4
22620+1234:
22621+ _ASM_EXTABLE(1234b, 1234b)
22622+#endif
22623+
22624 jnz 0b
22625 ENDFRAME
22626+ pax_force_retaddr
22627 ret
22628 CFI_ENDPROC
22629 END(__write_lock_failed)
22630@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22631 FRAME
22632 0: LOCK_PREFIX
22633 READ_LOCK_SIZE(inc) (%__lock_ptr)
22634+
22635+#ifdef CONFIG_PAX_REFCOUNT
22636+ jno 1234f
22637+ LOCK_PREFIX
22638+ READ_LOCK_SIZE(dec) (%__lock_ptr)
22639+ int $4
22640+1234:
22641+ _ASM_EXTABLE(1234b, 1234b)
22642+#endif
22643+
22644 1: rep; nop
22645 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22646 js 1b
22647 LOCK_PREFIX
22648 READ_LOCK_SIZE(dec) (%__lock_ptr)
22649+
22650+#ifdef CONFIG_PAX_REFCOUNT
22651+ jno 1234f
22652+ LOCK_PREFIX
22653+ READ_LOCK_SIZE(inc) (%__lock_ptr)
22654+ int $4
22655+1234:
22656+ _ASM_EXTABLE(1234b, 1234b)
22657+#endif
22658+
22659 js 0b
22660 ENDFRAME
22661+ pax_force_retaddr
22662 ret
22663 CFI_ENDPROC
22664 END(__read_lock_failed)
22665diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22666index 5dff5f0..cadebf4 100644
22667--- a/arch/x86/lib/rwsem.S
22668+++ b/arch/x86/lib/rwsem.S
22669@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22670 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22671 CFI_RESTORE __ASM_REG(dx)
22672 restore_common_regs
22673+ pax_force_retaddr
22674 ret
22675 CFI_ENDPROC
22676 ENDPROC(call_rwsem_down_read_failed)
22677@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22678 movq %rax,%rdi
22679 call rwsem_down_write_failed
22680 restore_common_regs
22681+ pax_force_retaddr
22682 ret
22683 CFI_ENDPROC
22684 ENDPROC(call_rwsem_down_write_failed)
22685@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22686 movq %rax,%rdi
22687 call rwsem_wake
22688 restore_common_regs
22689-1: ret
22690+1: pax_force_retaddr
22691+ ret
22692 CFI_ENDPROC
22693 ENDPROC(call_rwsem_wake)
22694
22695@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22696 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22697 CFI_RESTORE __ASM_REG(dx)
22698 restore_common_regs
22699+ pax_force_retaddr
22700 ret
22701 CFI_ENDPROC
22702 ENDPROC(call_rwsem_downgrade_wake)
22703diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22704index a63efd6..ccecad8 100644
22705--- a/arch/x86/lib/thunk_64.S
22706+++ b/arch/x86/lib/thunk_64.S
22707@@ -8,6 +8,7 @@
22708 #include <linux/linkage.h>
22709 #include <asm/dwarf2.h>
22710 #include <asm/calling.h>
22711+#include <asm/alternative-asm.h>
22712
22713 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22714 .macro THUNK name, func, put_ret_addr_in_rdi=0
22715@@ -41,5 +42,6 @@
22716 SAVE_ARGS
22717 restore:
22718 RESTORE_ARGS
22719+ pax_force_retaddr
22720 ret
22721 CFI_ENDPROC
22722diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22723index 1781b2f..90368dd 100644
22724--- a/arch/x86/lib/usercopy_32.c
22725+++ b/arch/x86/lib/usercopy_32.c
22726@@ -42,10 +42,12 @@ do { \
22727 int __d0; \
22728 might_fault(); \
22729 __asm__ __volatile__( \
22730+ __COPYUSER_SET_ES \
22731 "0: rep; stosl\n" \
22732 " movl %2,%0\n" \
22733 "1: rep; stosb\n" \
22734 "2:\n" \
22735+ __COPYUSER_RESTORE_ES \
22736 ".section .fixup,\"ax\"\n" \
22737 "3: lea 0(%2,%0,4),%0\n" \
22738 " jmp 2b\n" \
22739@@ -97,7 +99,7 @@ EXPORT_SYMBOL(__clear_user);
22740
22741 #ifdef CONFIG_X86_INTEL_USERCOPY
22742 static unsigned long
22743-__copy_user_intel(void __user *to, const void *from, unsigned long size)
22744+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22745 {
22746 int d0, d1;
22747 __asm__ __volatile__(
22748@@ -109,36 +111,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22749 " .align 2,0x90\n"
22750 "3: movl 0(%4), %%eax\n"
22751 "4: movl 4(%4), %%edx\n"
22752- "5: movl %%eax, 0(%3)\n"
22753- "6: movl %%edx, 4(%3)\n"
22754+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22755+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22756 "7: movl 8(%4), %%eax\n"
22757 "8: movl 12(%4),%%edx\n"
22758- "9: movl %%eax, 8(%3)\n"
22759- "10: movl %%edx, 12(%3)\n"
22760+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22761+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22762 "11: movl 16(%4), %%eax\n"
22763 "12: movl 20(%4), %%edx\n"
22764- "13: movl %%eax, 16(%3)\n"
22765- "14: movl %%edx, 20(%3)\n"
22766+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22767+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22768 "15: movl 24(%4), %%eax\n"
22769 "16: movl 28(%4), %%edx\n"
22770- "17: movl %%eax, 24(%3)\n"
22771- "18: movl %%edx, 28(%3)\n"
22772+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22773+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22774 "19: movl 32(%4), %%eax\n"
22775 "20: movl 36(%4), %%edx\n"
22776- "21: movl %%eax, 32(%3)\n"
22777- "22: movl %%edx, 36(%3)\n"
22778+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22779+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22780 "23: movl 40(%4), %%eax\n"
22781 "24: movl 44(%4), %%edx\n"
22782- "25: movl %%eax, 40(%3)\n"
22783- "26: movl %%edx, 44(%3)\n"
22784+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22785+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22786 "27: movl 48(%4), %%eax\n"
22787 "28: movl 52(%4), %%edx\n"
22788- "29: movl %%eax, 48(%3)\n"
22789- "30: movl %%edx, 52(%3)\n"
22790+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22791+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22792 "31: movl 56(%4), %%eax\n"
22793 "32: movl 60(%4), %%edx\n"
22794- "33: movl %%eax, 56(%3)\n"
22795- "34: movl %%edx, 60(%3)\n"
22796+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22797+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22798 " addl $-64, %0\n"
22799 " addl $64, %4\n"
22800 " addl $64, %3\n"
22801@@ -148,10 +150,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22802 " shrl $2, %0\n"
22803 " andl $3, %%eax\n"
22804 " cld\n"
22805+ __COPYUSER_SET_ES
22806 "99: rep; movsl\n"
22807 "36: movl %%eax, %0\n"
22808 "37: rep; movsb\n"
22809 "100:\n"
22810+ __COPYUSER_RESTORE_ES
22811 ".section .fixup,\"ax\"\n"
22812 "101: lea 0(%%eax,%0,4),%0\n"
22813 " jmp 100b\n"
22814@@ -201,46 +205,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22815 }
22816
22817 static unsigned long
22818+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22819+{
22820+ int d0, d1;
22821+ __asm__ __volatile__(
22822+ " .align 2,0x90\n"
22823+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22824+ " cmpl $67, %0\n"
22825+ " jbe 3f\n"
22826+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
22827+ " .align 2,0x90\n"
22828+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
22829+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
22830+ "5: movl %%eax, 0(%3)\n"
22831+ "6: movl %%edx, 4(%3)\n"
22832+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
22833+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
22834+ "9: movl %%eax, 8(%3)\n"
22835+ "10: movl %%edx, 12(%3)\n"
22836+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
22837+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
22838+ "13: movl %%eax, 16(%3)\n"
22839+ "14: movl %%edx, 20(%3)\n"
22840+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
22841+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
22842+ "17: movl %%eax, 24(%3)\n"
22843+ "18: movl %%edx, 28(%3)\n"
22844+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
22845+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
22846+ "21: movl %%eax, 32(%3)\n"
22847+ "22: movl %%edx, 36(%3)\n"
22848+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
22849+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
22850+ "25: movl %%eax, 40(%3)\n"
22851+ "26: movl %%edx, 44(%3)\n"
22852+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
22853+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
22854+ "29: movl %%eax, 48(%3)\n"
22855+ "30: movl %%edx, 52(%3)\n"
22856+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
22857+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
22858+ "33: movl %%eax, 56(%3)\n"
22859+ "34: movl %%edx, 60(%3)\n"
22860+ " addl $-64, %0\n"
22861+ " addl $64, %4\n"
22862+ " addl $64, %3\n"
22863+ " cmpl $63, %0\n"
22864+ " ja 1b\n"
22865+ "35: movl %0, %%eax\n"
22866+ " shrl $2, %0\n"
22867+ " andl $3, %%eax\n"
22868+ " cld\n"
22869+ "99: rep; "__copyuser_seg" movsl\n"
22870+ "36: movl %%eax, %0\n"
22871+ "37: rep; "__copyuser_seg" movsb\n"
22872+ "100:\n"
22873+ ".section .fixup,\"ax\"\n"
22874+ "101: lea 0(%%eax,%0,4),%0\n"
22875+ " jmp 100b\n"
22876+ ".previous\n"
22877+ _ASM_EXTABLE(1b,100b)
22878+ _ASM_EXTABLE(2b,100b)
22879+ _ASM_EXTABLE(3b,100b)
22880+ _ASM_EXTABLE(4b,100b)
22881+ _ASM_EXTABLE(5b,100b)
22882+ _ASM_EXTABLE(6b,100b)
22883+ _ASM_EXTABLE(7b,100b)
22884+ _ASM_EXTABLE(8b,100b)
22885+ _ASM_EXTABLE(9b,100b)
22886+ _ASM_EXTABLE(10b,100b)
22887+ _ASM_EXTABLE(11b,100b)
22888+ _ASM_EXTABLE(12b,100b)
22889+ _ASM_EXTABLE(13b,100b)
22890+ _ASM_EXTABLE(14b,100b)
22891+ _ASM_EXTABLE(15b,100b)
22892+ _ASM_EXTABLE(16b,100b)
22893+ _ASM_EXTABLE(17b,100b)
22894+ _ASM_EXTABLE(18b,100b)
22895+ _ASM_EXTABLE(19b,100b)
22896+ _ASM_EXTABLE(20b,100b)
22897+ _ASM_EXTABLE(21b,100b)
22898+ _ASM_EXTABLE(22b,100b)
22899+ _ASM_EXTABLE(23b,100b)
22900+ _ASM_EXTABLE(24b,100b)
22901+ _ASM_EXTABLE(25b,100b)
22902+ _ASM_EXTABLE(26b,100b)
22903+ _ASM_EXTABLE(27b,100b)
22904+ _ASM_EXTABLE(28b,100b)
22905+ _ASM_EXTABLE(29b,100b)
22906+ _ASM_EXTABLE(30b,100b)
22907+ _ASM_EXTABLE(31b,100b)
22908+ _ASM_EXTABLE(32b,100b)
22909+ _ASM_EXTABLE(33b,100b)
22910+ _ASM_EXTABLE(34b,100b)
22911+ _ASM_EXTABLE(35b,100b)
22912+ _ASM_EXTABLE(36b,100b)
22913+ _ASM_EXTABLE(37b,100b)
22914+ _ASM_EXTABLE(99b,101b)
22915+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
22916+ : "1"(to), "2"(from), "0"(size)
22917+ : "eax", "edx", "memory");
22918+ return size;
22919+}
22920+
22921+static unsigned long __size_overflow(3)
22922 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22923 {
22924 int d0, d1;
22925 __asm__ __volatile__(
22926 " .align 2,0x90\n"
22927- "0: movl 32(%4), %%eax\n"
22928+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
22929 " cmpl $67, %0\n"
22930 " jbe 2f\n"
22931- "1: movl 64(%4), %%eax\n"
22932+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
22933 " .align 2,0x90\n"
22934- "2: movl 0(%4), %%eax\n"
22935- "21: movl 4(%4), %%edx\n"
22936+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
22937+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
22938 " movl %%eax, 0(%3)\n"
22939 " movl %%edx, 4(%3)\n"
22940- "3: movl 8(%4), %%eax\n"
22941- "31: movl 12(%4),%%edx\n"
22942+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
22943+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
22944 " movl %%eax, 8(%3)\n"
22945 " movl %%edx, 12(%3)\n"
22946- "4: movl 16(%4), %%eax\n"
22947- "41: movl 20(%4), %%edx\n"
22948+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
22949+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
22950 " movl %%eax, 16(%3)\n"
22951 " movl %%edx, 20(%3)\n"
22952- "10: movl 24(%4), %%eax\n"
22953- "51: movl 28(%4), %%edx\n"
22954+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
22955+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
22956 " movl %%eax, 24(%3)\n"
22957 " movl %%edx, 28(%3)\n"
22958- "11: movl 32(%4), %%eax\n"
22959- "61: movl 36(%4), %%edx\n"
22960+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
22961+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
22962 " movl %%eax, 32(%3)\n"
22963 " movl %%edx, 36(%3)\n"
22964- "12: movl 40(%4), %%eax\n"
22965- "71: movl 44(%4), %%edx\n"
22966+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
22967+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
22968 " movl %%eax, 40(%3)\n"
22969 " movl %%edx, 44(%3)\n"
22970- "13: movl 48(%4), %%eax\n"
22971- "81: movl 52(%4), %%edx\n"
22972+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
22973+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
22974 " movl %%eax, 48(%3)\n"
22975 " movl %%edx, 52(%3)\n"
22976- "14: movl 56(%4), %%eax\n"
22977- "91: movl 60(%4), %%edx\n"
22978+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
22979+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
22980 " movl %%eax, 56(%3)\n"
22981 " movl %%edx, 60(%3)\n"
22982 " addl $-64, %0\n"
22983@@ -252,9 +360,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22984 " shrl $2, %0\n"
22985 " andl $3, %%eax\n"
22986 " cld\n"
22987- "6: rep; movsl\n"
22988+ "6: rep; "__copyuser_seg" movsl\n"
22989 " movl %%eax,%0\n"
22990- "7: rep; movsb\n"
22991+ "7: rep; "__copyuser_seg" movsb\n"
22992 "8:\n"
22993 ".section .fixup,\"ax\"\n"
22994 "9: lea 0(%%eax,%0,4),%0\n"
22995@@ -297,48 +405,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
22996 * hyoshiok@miraclelinux.com
22997 */
22998
22999-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23000+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
23001 const void __user *from, unsigned long size)
23002 {
23003 int d0, d1;
23004
23005 __asm__ __volatile__(
23006 " .align 2,0x90\n"
23007- "0: movl 32(%4), %%eax\n"
23008+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23009 " cmpl $67, %0\n"
23010 " jbe 2f\n"
23011- "1: movl 64(%4), %%eax\n"
23012+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23013 " .align 2,0x90\n"
23014- "2: movl 0(%4), %%eax\n"
23015- "21: movl 4(%4), %%edx\n"
23016+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23017+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23018 " movnti %%eax, 0(%3)\n"
23019 " movnti %%edx, 4(%3)\n"
23020- "3: movl 8(%4), %%eax\n"
23021- "31: movl 12(%4),%%edx\n"
23022+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23023+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23024 " movnti %%eax, 8(%3)\n"
23025 " movnti %%edx, 12(%3)\n"
23026- "4: movl 16(%4), %%eax\n"
23027- "41: movl 20(%4), %%edx\n"
23028+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23029+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23030 " movnti %%eax, 16(%3)\n"
23031 " movnti %%edx, 20(%3)\n"
23032- "10: movl 24(%4), %%eax\n"
23033- "51: movl 28(%4), %%edx\n"
23034+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23035+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23036 " movnti %%eax, 24(%3)\n"
23037 " movnti %%edx, 28(%3)\n"
23038- "11: movl 32(%4), %%eax\n"
23039- "61: movl 36(%4), %%edx\n"
23040+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23041+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23042 " movnti %%eax, 32(%3)\n"
23043 " movnti %%edx, 36(%3)\n"
23044- "12: movl 40(%4), %%eax\n"
23045- "71: movl 44(%4), %%edx\n"
23046+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23047+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23048 " movnti %%eax, 40(%3)\n"
23049 " movnti %%edx, 44(%3)\n"
23050- "13: movl 48(%4), %%eax\n"
23051- "81: movl 52(%4), %%edx\n"
23052+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23053+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23054 " movnti %%eax, 48(%3)\n"
23055 " movnti %%edx, 52(%3)\n"
23056- "14: movl 56(%4), %%eax\n"
23057- "91: movl 60(%4), %%edx\n"
23058+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23059+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23060 " movnti %%eax, 56(%3)\n"
23061 " movnti %%edx, 60(%3)\n"
23062 " addl $-64, %0\n"
23063@@ -351,9 +459,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23064 " shrl $2, %0\n"
23065 " andl $3, %%eax\n"
23066 " cld\n"
23067- "6: rep; movsl\n"
23068+ "6: rep; "__copyuser_seg" movsl\n"
23069 " movl %%eax,%0\n"
23070- "7: rep; movsb\n"
23071+ "7: rep; "__copyuser_seg" movsb\n"
23072 "8:\n"
23073 ".section .fixup,\"ax\"\n"
23074 "9: lea 0(%%eax,%0,4),%0\n"
23075@@ -391,48 +499,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23076 return size;
23077 }
23078
23079-static unsigned long __copy_user_intel_nocache(void *to,
23080+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
23081 const void __user *from, unsigned long size)
23082 {
23083 int d0, d1;
23084
23085 __asm__ __volatile__(
23086 " .align 2,0x90\n"
23087- "0: movl 32(%4), %%eax\n"
23088+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23089 " cmpl $67, %0\n"
23090 " jbe 2f\n"
23091- "1: movl 64(%4), %%eax\n"
23092+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23093 " .align 2,0x90\n"
23094- "2: movl 0(%4), %%eax\n"
23095- "21: movl 4(%4), %%edx\n"
23096+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23097+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23098 " movnti %%eax, 0(%3)\n"
23099 " movnti %%edx, 4(%3)\n"
23100- "3: movl 8(%4), %%eax\n"
23101- "31: movl 12(%4),%%edx\n"
23102+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23103+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23104 " movnti %%eax, 8(%3)\n"
23105 " movnti %%edx, 12(%3)\n"
23106- "4: movl 16(%4), %%eax\n"
23107- "41: movl 20(%4), %%edx\n"
23108+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23109+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23110 " movnti %%eax, 16(%3)\n"
23111 " movnti %%edx, 20(%3)\n"
23112- "10: movl 24(%4), %%eax\n"
23113- "51: movl 28(%4), %%edx\n"
23114+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23115+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23116 " movnti %%eax, 24(%3)\n"
23117 " movnti %%edx, 28(%3)\n"
23118- "11: movl 32(%4), %%eax\n"
23119- "61: movl 36(%4), %%edx\n"
23120+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23121+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23122 " movnti %%eax, 32(%3)\n"
23123 " movnti %%edx, 36(%3)\n"
23124- "12: movl 40(%4), %%eax\n"
23125- "71: movl 44(%4), %%edx\n"
23126+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23127+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23128 " movnti %%eax, 40(%3)\n"
23129 " movnti %%edx, 44(%3)\n"
23130- "13: movl 48(%4), %%eax\n"
23131- "81: movl 52(%4), %%edx\n"
23132+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23133+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23134 " movnti %%eax, 48(%3)\n"
23135 " movnti %%edx, 52(%3)\n"
23136- "14: movl 56(%4), %%eax\n"
23137- "91: movl 60(%4), %%edx\n"
23138+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23139+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23140 " movnti %%eax, 56(%3)\n"
23141 " movnti %%edx, 60(%3)\n"
23142 " addl $-64, %0\n"
23143@@ -445,9 +553,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23144 " shrl $2, %0\n"
23145 " andl $3, %%eax\n"
23146 " cld\n"
23147- "6: rep; movsl\n"
23148+ "6: rep; "__copyuser_seg" movsl\n"
23149 " movl %%eax,%0\n"
23150- "7: rep; movsb\n"
23151+ "7: rep; "__copyuser_seg" movsb\n"
23152 "8:\n"
23153 ".section .fixup,\"ax\"\n"
23154 "9: lea 0(%%eax,%0,4),%0\n"
23155@@ -487,32 +595,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23156 */
23157 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23158 unsigned long size);
23159-unsigned long __copy_user_intel(void __user *to, const void *from,
23160+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23161+ unsigned long size);
23162+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23163 unsigned long size);
23164 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23165 const void __user *from, unsigned long size);
23166 #endif /* CONFIG_X86_INTEL_USERCOPY */
23167
23168 /* Generic arbitrary sized copy. */
23169-#define __copy_user(to, from, size) \
23170+#define __copy_user(to, from, size, prefix, set, restore) \
23171 do { \
23172 int __d0, __d1, __d2; \
23173 __asm__ __volatile__( \
23174+ set \
23175 " cmp $7,%0\n" \
23176 " jbe 1f\n" \
23177 " movl %1,%0\n" \
23178 " negl %0\n" \
23179 " andl $7,%0\n" \
23180 " subl %0,%3\n" \
23181- "4: rep; movsb\n" \
23182+ "4: rep; "prefix"movsb\n" \
23183 " movl %3,%0\n" \
23184 " shrl $2,%0\n" \
23185 " andl $3,%3\n" \
23186 " .align 2,0x90\n" \
23187- "0: rep; movsl\n" \
23188+ "0: rep; "prefix"movsl\n" \
23189 " movl %3,%0\n" \
23190- "1: rep; movsb\n" \
23191+ "1: rep; "prefix"movsb\n" \
23192 "2:\n" \
23193+ restore \
23194 ".section .fixup,\"ax\"\n" \
23195 "5: addl %3,%0\n" \
23196 " jmp 2b\n" \
23197@@ -537,14 +649,14 @@ do { \
23198 " negl %0\n" \
23199 " andl $7,%0\n" \
23200 " subl %0,%3\n" \
23201- "4: rep; movsb\n" \
23202+ "4: rep; "__copyuser_seg"movsb\n" \
23203 " movl %3,%0\n" \
23204 " shrl $2,%0\n" \
23205 " andl $3,%3\n" \
23206 " .align 2,0x90\n" \
23207- "0: rep; movsl\n" \
23208+ "0: rep; "__copyuser_seg"movsl\n" \
23209 " movl %3,%0\n" \
23210- "1: rep; movsb\n" \
23211+ "1: rep; "__copyuser_seg"movsb\n" \
23212 "2:\n" \
23213 ".section .fixup,\"ax\"\n" \
23214 "5: addl %3,%0\n" \
23215@@ -627,9 +739,9 @@ survive:
23216 }
23217 #endif
23218 if (movsl_is_ok(to, from, n))
23219- __copy_user(to, from, n);
23220+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23221 else
23222- n = __copy_user_intel(to, from, n);
23223+ n = __generic_copy_to_user_intel(to, from, n);
23224 return n;
23225 }
23226 EXPORT_SYMBOL(__copy_to_user_ll);
23227@@ -649,10 +761,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23228 unsigned long n)
23229 {
23230 if (movsl_is_ok(to, from, n))
23231- __copy_user(to, from, n);
23232+ __copy_user(to, from, n, __copyuser_seg, "", "");
23233 else
23234- n = __copy_user_intel((void __user *)to,
23235- (const void *)from, n);
23236+ n = __generic_copy_from_user_intel(to, from, n);
23237 return n;
23238 }
23239 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23240@@ -679,65 +790,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23241 if (n > 64 && cpu_has_xmm2)
23242 n = __copy_user_intel_nocache(to, from, n);
23243 else
23244- __copy_user(to, from, n);
23245+ __copy_user(to, from, n, __copyuser_seg, "", "");
23246 #else
23247- __copy_user(to, from, n);
23248+ __copy_user(to, from, n, __copyuser_seg, "", "");
23249 #endif
23250 return n;
23251 }
23252 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23253
23254-/**
23255- * copy_to_user: - Copy a block of data into user space.
23256- * @to: Destination address, in user space.
23257- * @from: Source address, in kernel space.
23258- * @n: Number of bytes to copy.
23259- *
23260- * Context: User context only. This function may sleep.
23261- *
23262- * Copy data from kernel space to user space.
23263- *
23264- * Returns number of bytes that could not be copied.
23265- * On success, this will be zero.
23266- */
23267-unsigned long
23268-copy_to_user(void __user *to, const void *from, unsigned long n)
23269-{
23270- if (access_ok(VERIFY_WRITE, to, n))
23271- n = __copy_to_user(to, from, n);
23272- return n;
23273-}
23274-EXPORT_SYMBOL(copy_to_user);
23275-
23276-/**
23277- * copy_from_user: - Copy a block of data from user space.
23278- * @to: Destination address, in kernel space.
23279- * @from: Source address, in user space.
23280- * @n: Number of bytes to copy.
23281- *
23282- * Context: User context only. This function may sleep.
23283- *
23284- * Copy data from user space to kernel space.
23285- *
23286- * Returns number of bytes that could not be copied.
23287- * On success, this will be zero.
23288- *
23289- * If some data could not be copied, this function will pad the copied
23290- * data to the requested size using zero bytes.
23291- */
23292-unsigned long
23293-_copy_from_user(void *to, const void __user *from, unsigned long n)
23294-{
23295- if (access_ok(VERIFY_READ, from, n))
23296- n = __copy_from_user(to, from, n);
23297- else
23298- memset(to, 0, n);
23299- return n;
23300-}
23301-EXPORT_SYMBOL(_copy_from_user);
23302-
23303 void copy_from_user_overflow(void)
23304 {
23305 WARN(1, "Buffer overflow detected!\n");
23306 }
23307 EXPORT_SYMBOL(copy_from_user_overflow);
23308+
23309+void copy_to_user_overflow(void)
23310+{
23311+ WARN(1, "Buffer overflow detected!\n");
23312+}
23313+EXPORT_SYMBOL(copy_to_user_overflow);
23314+
23315+#ifdef CONFIG_PAX_MEMORY_UDEREF
23316+void __set_fs(mm_segment_t x)
23317+{
23318+ switch (x.seg) {
23319+ case 0:
23320+ loadsegment(gs, 0);
23321+ break;
23322+ case TASK_SIZE_MAX:
23323+ loadsegment(gs, __USER_DS);
23324+ break;
23325+ case -1UL:
23326+ loadsegment(gs, __KERNEL_DS);
23327+ break;
23328+ default:
23329+ BUG();
23330+ }
23331+ return;
23332+}
23333+EXPORT_SYMBOL(__set_fs);
23334+
23335+void set_fs(mm_segment_t x)
23336+{
23337+ current_thread_info()->addr_limit = x;
23338+ __set_fs(x);
23339+}
23340+EXPORT_SYMBOL(set_fs);
23341+#endif
23342diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23343index e5b130b..6690d31 100644
23344--- a/arch/x86/lib/usercopy_64.c
23345+++ b/arch/x86/lib/usercopy_64.c
23346@@ -16,6 +16,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23347 {
23348 long __d0;
23349 might_fault();
23350+
23351+#ifdef CONFIG_PAX_MEMORY_UDEREF
23352+ if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23353+ addr += PAX_USER_SHADOW_BASE;
23354+#endif
23355+
23356 /* no memory constraint because it doesn't change any memory gcc knows
23357 about */
23358 asm volatile(
23359@@ -52,12 +58,20 @@ unsigned long clear_user(void __user *to, unsigned long n)
23360 }
23361 EXPORT_SYMBOL(clear_user);
23362
23363-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23364+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23365 {
23366- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23367- return copy_user_generic((__force void *)to, (__force void *)from, len);
23368- }
23369- return len;
23370+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23371+
23372+#ifdef CONFIG_PAX_MEMORY_UDEREF
23373+ if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23374+ to += PAX_USER_SHADOW_BASE;
23375+ if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23376+ from += PAX_USER_SHADOW_BASE;
23377+#endif
23378+
23379+ return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23380+ }
23381+ return len;
23382 }
23383 EXPORT_SYMBOL(copy_in_user);
23384
23385@@ -67,7 +81,7 @@ EXPORT_SYMBOL(copy_in_user);
23386 * it is not necessary to optimize tail handling.
23387 */
23388 unsigned long
23389-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23390+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23391 {
23392 char c;
23393 unsigned zero_len;
23394@@ -84,3 +98,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23395 break;
23396 return len;
23397 }
23398+
23399+void copy_from_user_overflow(void)
23400+{
23401+ WARN(1, "Buffer overflow detected!\n");
23402+}
23403+EXPORT_SYMBOL(copy_from_user_overflow);
23404+
23405+void copy_to_user_overflow(void)
23406+{
23407+ WARN(1, "Buffer overflow detected!\n");
23408+}
23409+EXPORT_SYMBOL(copy_to_user_overflow);
23410diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23411index 903ec1e..af8e064 100644
23412--- a/arch/x86/mm/extable.c
23413+++ b/arch/x86/mm/extable.c
23414@@ -6,12 +6,24 @@
23415 static inline unsigned long
23416 ex_insn_addr(const struct exception_table_entry *x)
23417 {
23418- return (unsigned long)&x->insn + x->insn;
23419+ unsigned long reloc = 0;
23420+
23421+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
23422+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23423+#endif
23424+
23425+ return (unsigned long)&x->insn + x->insn + reloc;
23426 }
23427 static inline unsigned long
23428 ex_fixup_addr(const struct exception_table_entry *x)
23429 {
23430- return (unsigned long)&x->fixup + x->fixup;
23431+ unsigned long reloc = 0;
23432+
23433+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
23434+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23435+#endif
23436+
23437+ return (unsigned long)&x->fixup + x->fixup + reloc;
23438 }
23439
23440 int fixup_exception(struct pt_regs *regs)
23441@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
23442 unsigned long new_ip;
23443
23444 #ifdef CONFIG_PNPBIOS
23445- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23446+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23447 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23448 extern u32 pnp_bios_is_utter_crap;
23449 pnp_bios_is_utter_crap = 1;
23450diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23451index 76dcd9d..e9dffde 100644
23452--- a/arch/x86/mm/fault.c
23453+++ b/arch/x86/mm/fault.c
23454@@ -13,11 +13,18 @@
23455 #include <linux/perf_event.h> /* perf_sw_event */
23456 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23457 #include <linux/prefetch.h> /* prefetchw */
23458+#include <linux/unistd.h>
23459+#include <linux/compiler.h>
23460
23461 #include <asm/traps.h> /* dotraplinkage, ... */
23462 #include <asm/pgalloc.h> /* pgd_*(), ... */
23463 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23464 #include <asm/fixmap.h> /* VSYSCALL_START */
23465+#include <asm/tlbflush.h>
23466+
23467+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23468+#include <asm/stacktrace.h>
23469+#endif
23470
23471 /*
23472 * Page fault error code bits:
23473@@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23474 int ret = 0;
23475
23476 /* kprobe_running() needs smp_processor_id() */
23477- if (kprobes_built_in() && !user_mode_vm(regs)) {
23478+ if (kprobes_built_in() && !user_mode(regs)) {
23479 preempt_disable();
23480 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23481 ret = 1;
23482@@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23483 return !instr_lo || (instr_lo>>1) == 1;
23484 case 0x00:
23485 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23486- if (probe_kernel_address(instr, opcode))
23487+ if (user_mode(regs)) {
23488+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23489+ return 0;
23490+ } else if (probe_kernel_address(instr, opcode))
23491 return 0;
23492
23493 *prefetch = (instr_lo == 0xF) &&
23494@@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23495 while (instr < max_instr) {
23496 unsigned char opcode;
23497
23498- if (probe_kernel_address(instr, opcode))
23499+ if (user_mode(regs)) {
23500+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23501+ break;
23502+ } else if (probe_kernel_address(instr, opcode))
23503 break;
23504
23505 instr++;
23506@@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23507 force_sig_info(si_signo, &info, tsk);
23508 }
23509
23510+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23511+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23512+#endif
23513+
23514+#ifdef CONFIG_PAX_EMUTRAMP
23515+static int pax_handle_fetch_fault(struct pt_regs *regs);
23516+#endif
23517+
23518+#ifdef CONFIG_PAX_PAGEEXEC
23519+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23520+{
23521+ pgd_t *pgd;
23522+ pud_t *pud;
23523+ pmd_t *pmd;
23524+
23525+ pgd = pgd_offset(mm, address);
23526+ if (!pgd_present(*pgd))
23527+ return NULL;
23528+ pud = pud_offset(pgd, address);
23529+ if (!pud_present(*pud))
23530+ return NULL;
23531+ pmd = pmd_offset(pud, address);
23532+ if (!pmd_present(*pmd))
23533+ return NULL;
23534+ return pmd;
23535+}
23536+#endif
23537+
23538 DEFINE_SPINLOCK(pgd_lock);
23539 LIST_HEAD(pgd_list);
23540
23541@@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23542 for (address = VMALLOC_START & PMD_MASK;
23543 address >= TASK_SIZE && address < FIXADDR_TOP;
23544 address += PMD_SIZE) {
23545+
23546+#ifdef CONFIG_PAX_PER_CPU_PGD
23547+ unsigned long cpu;
23548+#else
23549 struct page *page;
23550+#endif
23551
23552 spin_lock(&pgd_lock);
23553+
23554+#ifdef CONFIG_PAX_PER_CPU_PGD
23555+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23556+ pgd_t *pgd = get_cpu_pgd(cpu);
23557+ pmd_t *ret;
23558+#else
23559 list_for_each_entry(page, &pgd_list, lru) {
23560+ pgd_t *pgd = page_address(page);
23561 spinlock_t *pgt_lock;
23562 pmd_t *ret;
23563
23564@@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23565 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23566
23567 spin_lock(pgt_lock);
23568- ret = vmalloc_sync_one(page_address(page), address);
23569+#endif
23570+
23571+ ret = vmalloc_sync_one(pgd, address);
23572+
23573+#ifndef CONFIG_PAX_PER_CPU_PGD
23574 spin_unlock(pgt_lock);
23575+#endif
23576
23577 if (!ret)
23578 break;
23579@@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23580 * an interrupt in the middle of a task switch..
23581 */
23582 pgd_paddr = read_cr3();
23583+
23584+#ifdef CONFIG_PAX_PER_CPU_PGD
23585+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23586+#endif
23587+
23588 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23589 if (!pmd_k)
23590 return -1;
23591@@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23592 * happen within a race in page table update. In the later
23593 * case just flush:
23594 */
23595+
23596+#ifdef CONFIG_PAX_PER_CPU_PGD
23597+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23598+ pgd = pgd_offset_cpu(smp_processor_id(), address);
23599+#else
23600 pgd = pgd_offset(current->active_mm, address);
23601+#endif
23602+
23603 pgd_ref = pgd_offset_k(address);
23604 if (pgd_none(*pgd_ref))
23605 return -1;
23606@@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23607 static int is_errata100(struct pt_regs *regs, unsigned long address)
23608 {
23609 #ifdef CONFIG_X86_64
23610- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23611+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23612 return 1;
23613 #endif
23614 return 0;
23615@@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23616 }
23617
23618 static const char nx_warning[] = KERN_CRIT
23619-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23620+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23621
23622 static void
23623 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23624@@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23625 if (!oops_may_print())
23626 return;
23627
23628- if (error_code & PF_INSTR) {
23629+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23630 unsigned int level;
23631
23632 pte_t *pte = lookup_address(address, &level);
23633
23634 if (pte && pte_present(*pte) && !pte_exec(*pte))
23635- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
23636+ printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
23637 }
23638
23639+#ifdef CONFIG_PAX_KERNEXEC
23640+ if (init_mm.start_code <= address && address < init_mm.end_code) {
23641+ if (current->signal->curr_ip)
23642+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23643+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23644+ else
23645+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23646+ current->comm, task_pid_nr(current), current_uid(), current_euid());
23647+ }
23648+#endif
23649+
23650 printk(KERN_ALERT "BUG: unable to handle kernel ");
23651 if (address < PAGE_SIZE)
23652 printk(KERN_CONT "NULL pointer dereference");
23653@@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23654 }
23655 #endif
23656
23657+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23658+ if (pax_is_fetch_fault(regs, error_code, address)) {
23659+
23660+#ifdef CONFIG_PAX_EMUTRAMP
23661+ switch (pax_handle_fetch_fault(regs)) {
23662+ case 2:
23663+ return;
23664+ }
23665+#endif
23666+
23667+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23668+ do_group_exit(SIGKILL);
23669+ }
23670+#endif
23671+
23672 if (unlikely(show_unhandled_signals))
23673 show_signal_msg(regs, error_code, address, tsk);
23674
23675@@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23676 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23677 printk(KERN_ERR
23678 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23679- tsk->comm, tsk->pid, address);
23680+ tsk->comm, task_pid_nr(tsk), address);
23681 code = BUS_MCEERR_AR;
23682 }
23683 #endif
23684@@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23685 return 1;
23686 }
23687
23688+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23689+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23690+{
23691+ pte_t *pte;
23692+ pmd_t *pmd;
23693+ spinlock_t *ptl;
23694+ unsigned char pte_mask;
23695+
23696+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23697+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
23698+ return 0;
23699+
23700+ /* PaX: it's our fault, let's handle it if we can */
23701+
23702+ /* PaX: take a look at read faults before acquiring any locks */
23703+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23704+ /* instruction fetch attempt from a protected page in user mode */
23705+ up_read(&mm->mmap_sem);
23706+
23707+#ifdef CONFIG_PAX_EMUTRAMP
23708+ switch (pax_handle_fetch_fault(regs)) {
23709+ case 2:
23710+ return 1;
23711+ }
23712+#endif
23713+
23714+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23715+ do_group_exit(SIGKILL);
23716+ }
23717+
23718+ pmd = pax_get_pmd(mm, address);
23719+ if (unlikely(!pmd))
23720+ return 0;
23721+
23722+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23723+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23724+ pte_unmap_unlock(pte, ptl);
23725+ return 0;
23726+ }
23727+
23728+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23729+ /* write attempt to a protected page in user mode */
23730+ pte_unmap_unlock(pte, ptl);
23731+ return 0;
23732+ }
23733+
23734+#ifdef CONFIG_SMP
23735+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23736+#else
23737+ if (likely(address > get_limit(regs->cs)))
23738+#endif
23739+ {
23740+ set_pte(pte, pte_mkread(*pte));
23741+ __flush_tlb_one(address);
23742+ pte_unmap_unlock(pte, ptl);
23743+ up_read(&mm->mmap_sem);
23744+ return 1;
23745+ }
23746+
23747+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23748+
23749+ /*
23750+ * PaX: fill DTLB with user rights and retry
23751+ */
23752+ __asm__ __volatile__ (
23753+ "orb %2,(%1)\n"
23754+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23755+/*
23756+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23757+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23758+ * page fault when examined during a TLB load attempt. this is true not only
23759+ * for PTEs holding a non-present entry but also present entries that will
23760+ * raise a page fault (such as those set up by PaX, or the copy-on-write
23761+ * mechanism). in effect it means that we do *not* need to flush the TLBs
23762+ * for our target pages since their PTEs are simply not in the TLBs at all.
23763+
23764+ * the best thing in omitting it is that we gain around 15-20% speed in the
23765+ * fast path of the page fault handler and can get rid of tracing since we
23766+ * can no longer flush unintended entries.
23767+ */
23768+ "invlpg (%0)\n"
23769+#endif
23770+ __copyuser_seg"testb $0,(%0)\n"
23771+ "xorb %3,(%1)\n"
23772+ :
23773+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23774+ : "memory", "cc");
23775+ pte_unmap_unlock(pte, ptl);
23776+ up_read(&mm->mmap_sem);
23777+ return 1;
23778+}
23779+#endif
23780+
23781 /*
23782 * Handle a spurious fault caused by a stale TLB entry.
23783 *
23784@@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23785 static inline int
23786 access_error(unsigned long error_code, struct vm_area_struct *vma)
23787 {
23788+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23789+ return 1;
23790+
23791 if (error_code & PF_WRITE) {
23792 /* write, present and write, not present: */
23793 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23794@@ -1005,18 +1197,33 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23795 {
23796 struct vm_area_struct *vma;
23797 struct task_struct *tsk;
23798- unsigned long address;
23799 struct mm_struct *mm;
23800 int fault;
23801 int write = error_code & PF_WRITE;
23802 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23803 (write ? FAULT_FLAG_WRITE : 0);
23804
23805- tsk = current;
23806- mm = tsk->mm;
23807-
23808 /* Get the faulting address: */
23809- address = read_cr2();
23810+ unsigned long address = read_cr2();
23811+
23812+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23813+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23814+ if (!search_exception_tables(regs->ip)) {
23815+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23816+ bad_area_nosemaphore(regs, error_code, address);
23817+ return;
23818+ }
23819+ if (address < PAX_USER_SHADOW_BASE) {
23820+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23821+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
23822+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
23823+ } else
23824+ address -= PAX_USER_SHADOW_BASE;
23825+ }
23826+#endif
23827+
23828+ tsk = current;
23829+ mm = tsk->mm;
23830
23831 /*
23832 * Detect and handle instructions that would cause a page fault for
23833@@ -1077,7 +1284,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23834 * User-mode registers count as a user access even for any
23835 * potential system fault or CPU buglet:
23836 */
23837- if (user_mode_vm(regs)) {
23838+ if (user_mode(regs)) {
23839 local_irq_enable();
23840 error_code |= PF_USER;
23841 } else {
23842@@ -1132,6 +1339,11 @@ retry:
23843 might_sleep();
23844 }
23845
23846+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23847+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
23848+ return;
23849+#endif
23850+
23851 vma = find_vma(mm, address);
23852 if (unlikely(!vma)) {
23853 bad_area(regs, error_code, address);
23854@@ -1143,18 +1355,24 @@ retry:
23855 bad_area(regs, error_code, address);
23856 return;
23857 }
23858- if (error_code & PF_USER) {
23859- /*
23860- * Accessing the stack below %sp is always a bug.
23861- * The large cushion allows instructions like enter
23862- * and pusha to work. ("enter $65535, $31" pushes
23863- * 32 pointers and then decrements %sp by 65535.)
23864- */
23865- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
23866- bad_area(regs, error_code, address);
23867- return;
23868- }
23869+ /*
23870+ * Accessing the stack below %sp is always a bug.
23871+ * The large cushion allows instructions like enter
23872+ * and pusha to work. ("enter $65535, $31" pushes
23873+ * 32 pointers and then decrements %sp by 65535.)
23874+ */
23875+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
23876+ bad_area(regs, error_code, address);
23877+ return;
23878 }
23879+
23880+#ifdef CONFIG_PAX_SEGMEXEC
23881+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
23882+ bad_area(regs, error_code, address);
23883+ return;
23884+ }
23885+#endif
23886+
23887 if (unlikely(expand_stack(vma, address))) {
23888 bad_area(regs, error_code, address);
23889 return;
23890@@ -1209,3 +1427,292 @@ good_area:
23891
23892 up_read(&mm->mmap_sem);
23893 }
23894+
23895+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23896+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
23897+{
23898+ struct mm_struct *mm = current->mm;
23899+ unsigned long ip = regs->ip;
23900+
23901+ if (v8086_mode(regs))
23902+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
23903+
23904+#ifdef CONFIG_PAX_PAGEEXEC
23905+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
23906+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
23907+ return true;
23908+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
23909+ return true;
23910+ return false;
23911+ }
23912+#endif
23913+
23914+#ifdef CONFIG_PAX_SEGMEXEC
23915+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
23916+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
23917+ return true;
23918+ return false;
23919+ }
23920+#endif
23921+
23922+ return false;
23923+}
23924+#endif
23925+
23926+#ifdef CONFIG_PAX_EMUTRAMP
23927+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
23928+{
23929+ int err;
23930+
23931+ do { /* PaX: libffi trampoline emulation */
23932+ unsigned char mov, jmp;
23933+ unsigned int addr1, addr2;
23934+
23935+#ifdef CONFIG_X86_64
23936+ if ((regs->ip + 9) >> 32)
23937+ break;
23938+#endif
23939+
23940+ err = get_user(mov, (unsigned char __user *)regs->ip);
23941+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23942+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23943+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23944+
23945+ if (err)
23946+ break;
23947+
23948+ if (mov == 0xB8 && jmp == 0xE9) {
23949+ regs->ax = addr1;
23950+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
23951+ return 2;
23952+ }
23953+ } while (0);
23954+
23955+ do { /* PaX: gcc trampoline emulation #1 */
23956+ unsigned char mov1, mov2;
23957+ unsigned short jmp;
23958+ unsigned int addr1, addr2;
23959+
23960+#ifdef CONFIG_X86_64
23961+ if ((regs->ip + 11) >> 32)
23962+ break;
23963+#endif
23964+
23965+ err = get_user(mov1, (unsigned char __user *)regs->ip);
23966+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23967+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
23968+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23969+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
23970+
23971+ if (err)
23972+ break;
23973+
23974+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
23975+ regs->cx = addr1;
23976+ regs->ax = addr2;
23977+ regs->ip = addr2;
23978+ return 2;
23979+ }
23980+ } while (0);
23981+
23982+ do { /* PaX: gcc trampoline emulation #2 */
23983+ unsigned char mov, jmp;
23984+ unsigned int addr1, addr2;
23985+
23986+#ifdef CONFIG_X86_64
23987+ if ((regs->ip + 9) >> 32)
23988+ break;
23989+#endif
23990+
23991+ err = get_user(mov, (unsigned char __user *)regs->ip);
23992+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
23993+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
23994+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
23995+
23996+ if (err)
23997+ break;
23998+
23999+ if (mov == 0xB9 && jmp == 0xE9) {
24000+ regs->cx = addr1;
24001+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24002+ return 2;
24003+ }
24004+ } while (0);
24005+
24006+ return 1; /* PaX in action */
24007+}
24008+
24009+#ifdef CONFIG_X86_64
24010+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24011+{
24012+ int err;
24013+
24014+ do { /* PaX: libffi trampoline emulation */
24015+ unsigned short mov1, mov2, jmp1;
24016+ unsigned char stcclc, jmp2;
24017+ unsigned long addr1, addr2;
24018+
24019+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24020+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24021+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24022+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24023+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24024+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24025+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24026+
24027+ if (err)
24028+ break;
24029+
24030+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24031+ regs->r11 = addr1;
24032+ regs->r10 = addr2;
24033+ if (stcclc == 0xF8)
24034+ regs->flags &= ~X86_EFLAGS_CF;
24035+ else
24036+ regs->flags |= X86_EFLAGS_CF;
24037+ regs->ip = addr1;
24038+ return 2;
24039+ }
24040+ } while (0);
24041+
24042+ do { /* PaX: gcc trampoline emulation #1 */
24043+ unsigned short mov1, mov2, jmp1;
24044+ unsigned char jmp2;
24045+ unsigned int addr1;
24046+ unsigned long addr2;
24047+
24048+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24049+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24050+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24051+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24052+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24053+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24054+
24055+ if (err)
24056+ break;
24057+
24058+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24059+ regs->r11 = addr1;
24060+ regs->r10 = addr2;
24061+ regs->ip = addr1;
24062+ return 2;
24063+ }
24064+ } while (0);
24065+
24066+ do { /* PaX: gcc trampoline emulation #2 */
24067+ unsigned short mov1, mov2, jmp1;
24068+ unsigned char jmp2;
24069+ unsigned long addr1, addr2;
24070+
24071+ err = get_user(mov1, (unsigned short __user *)regs->ip);
24072+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24073+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24074+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24075+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24076+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24077+
24078+ if (err)
24079+ break;
24080+
24081+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24082+ regs->r11 = addr1;
24083+ regs->r10 = addr2;
24084+ regs->ip = addr1;
24085+ return 2;
24086+ }
24087+ } while (0);
24088+
24089+ return 1; /* PaX in action */
24090+}
24091+#endif
24092+
24093+/*
24094+ * PaX: decide what to do with offenders (regs->ip = fault address)
24095+ *
24096+ * returns 1 when task should be killed
24097+ * 2 when gcc trampoline was detected
24098+ */
24099+static int pax_handle_fetch_fault(struct pt_regs *regs)
24100+{
24101+ if (v8086_mode(regs))
24102+ return 1;
24103+
24104+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24105+ return 1;
24106+
24107+#ifdef CONFIG_X86_32
24108+ return pax_handle_fetch_fault_32(regs);
24109+#else
24110+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24111+ return pax_handle_fetch_fault_32(regs);
24112+ else
24113+ return pax_handle_fetch_fault_64(regs);
24114+#endif
24115+}
24116+#endif
24117+
24118+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24119+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24120+{
24121+ long i;
24122+
24123+ printk(KERN_ERR "PAX: bytes at PC: ");
24124+ for (i = 0; i < 20; i++) {
24125+ unsigned char c;
24126+ if (get_user(c, (unsigned char __force_user *)pc+i))
24127+ printk(KERN_CONT "?? ");
24128+ else
24129+ printk(KERN_CONT "%02x ", c);
24130+ }
24131+ printk("\n");
24132+
24133+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24134+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
24135+ unsigned long c;
24136+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
24137+#ifdef CONFIG_X86_32
24138+ printk(KERN_CONT "???????? ");
24139+#else
24140+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24141+ printk(KERN_CONT "???????? ???????? ");
24142+ else
24143+ printk(KERN_CONT "???????????????? ");
24144+#endif
24145+ } else {
24146+#ifdef CONFIG_X86_64
24147+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24148+ printk(KERN_CONT "%08x ", (unsigned int)c);
24149+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24150+ } else
24151+#endif
24152+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24153+ }
24154+ }
24155+ printk("\n");
24156+}
24157+#endif
24158+
24159+/**
24160+ * probe_kernel_write(): safely attempt to write to a location
24161+ * @dst: address to write to
24162+ * @src: pointer to the data that shall be written
24163+ * @size: size of the data chunk
24164+ *
24165+ * Safely write to address @dst from the buffer at @src. If a kernel fault
24166+ * happens, handle that and return -EFAULT.
24167+ */
24168+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24169+{
24170+ long ret;
24171+ mm_segment_t old_fs = get_fs();
24172+
24173+ set_fs(KERNEL_DS);
24174+ pagefault_disable();
24175+ pax_open_kernel();
24176+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24177+ pax_close_kernel();
24178+ pagefault_enable();
24179+ set_fs(old_fs);
24180+
24181+ return ret ? -EFAULT : 0;
24182+}
24183diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24184index dd74e46..7d26398 100644
24185--- a/arch/x86/mm/gup.c
24186+++ b/arch/x86/mm/gup.c
24187@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24188 addr = start;
24189 len = (unsigned long) nr_pages << PAGE_SHIFT;
24190 end = start + len;
24191- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24192+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24193 (void __user *)start, len)))
24194 return 0;
24195
24196diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24197index 6f31ee5..8ee4164 100644
24198--- a/arch/x86/mm/highmem_32.c
24199+++ b/arch/x86/mm/highmem_32.c
24200@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24201 idx = type + KM_TYPE_NR*smp_processor_id();
24202 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24203 BUG_ON(!pte_none(*(kmap_pte-idx)));
24204+
24205+ pax_open_kernel();
24206 set_pte(kmap_pte-idx, mk_pte(page, prot));
24207+ pax_close_kernel();
24208+
24209 arch_flush_lazy_mmu_mode();
24210
24211 return (void *)vaddr;
24212diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24213index f6679a7..8f795a3 100644
24214--- a/arch/x86/mm/hugetlbpage.c
24215+++ b/arch/x86/mm/hugetlbpage.c
24216@@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24217 struct hstate *h = hstate_file(file);
24218 struct mm_struct *mm = current->mm;
24219 struct vm_area_struct *vma;
24220- unsigned long start_addr;
24221+ unsigned long start_addr, pax_task_size = TASK_SIZE;
24222+
24223+#ifdef CONFIG_PAX_SEGMEXEC
24224+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24225+ pax_task_size = SEGMEXEC_TASK_SIZE;
24226+#endif
24227+
24228+ pax_task_size -= PAGE_SIZE;
24229
24230 if (len > mm->cached_hole_size) {
24231- start_addr = mm->free_area_cache;
24232+ start_addr = mm->free_area_cache;
24233 } else {
24234- start_addr = TASK_UNMAPPED_BASE;
24235- mm->cached_hole_size = 0;
24236+ start_addr = mm->mmap_base;
24237+ mm->cached_hole_size = 0;
24238 }
24239
24240 full_search:
24241@@ -280,26 +287,27 @@ full_search:
24242
24243 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24244 /* At this point: (!vma || addr < vma->vm_end). */
24245- if (TASK_SIZE - len < addr) {
24246+ if (pax_task_size - len < addr) {
24247 /*
24248 * Start a new search - just in case we missed
24249 * some holes.
24250 */
24251- if (start_addr != TASK_UNMAPPED_BASE) {
24252- start_addr = TASK_UNMAPPED_BASE;
24253+ if (start_addr != mm->mmap_base) {
24254+ start_addr = mm->mmap_base;
24255 mm->cached_hole_size = 0;
24256 goto full_search;
24257 }
24258 return -ENOMEM;
24259 }
24260- if (!vma || addr + len <= vma->vm_start) {
24261- mm->free_area_cache = addr + len;
24262- return addr;
24263- }
24264+ if (check_heap_stack_gap(vma, addr, len))
24265+ break;
24266 if (addr + mm->cached_hole_size < vma->vm_start)
24267 mm->cached_hole_size = vma->vm_start - addr;
24268 addr = ALIGN(vma->vm_end, huge_page_size(h));
24269 }
24270+
24271+ mm->free_area_cache = addr + len;
24272+ return addr;
24273 }
24274
24275 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24276@@ -310,9 +318,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24277 struct mm_struct *mm = current->mm;
24278 struct vm_area_struct *vma;
24279 unsigned long base = mm->mmap_base;
24280- unsigned long addr = addr0;
24281+ unsigned long addr;
24282 unsigned long largest_hole = mm->cached_hole_size;
24283- unsigned long start_addr;
24284
24285 /* don't allow allocations above current base */
24286 if (mm->free_area_cache > base)
24287@@ -322,16 +329,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24288 largest_hole = 0;
24289 mm->free_area_cache = base;
24290 }
24291-try_again:
24292- start_addr = mm->free_area_cache;
24293
24294 /* make sure it can fit in the remaining address space */
24295 if (mm->free_area_cache < len)
24296 goto fail;
24297
24298 /* either no address requested or can't fit in requested address hole */
24299- addr = (mm->free_area_cache - len) & huge_page_mask(h);
24300+ addr = mm->free_area_cache - len;
24301 do {
24302+ addr &= huge_page_mask(h);
24303 /*
24304 * Lookup failure means no vma is above this address,
24305 * i.e. return with success:
24306@@ -340,10 +346,10 @@ try_again:
24307 if (!vma)
24308 return addr;
24309
24310- if (addr + len <= vma->vm_start) {
24311+ if (check_heap_stack_gap(vma, addr, len)) {
24312 /* remember the address as a hint for next time */
24313- mm->cached_hole_size = largest_hole;
24314- return (mm->free_area_cache = addr);
24315+ mm->cached_hole_size = largest_hole;
24316+ return (mm->free_area_cache = addr);
24317 } else if (mm->free_area_cache == vma->vm_end) {
24318 /* pull free_area_cache down to the first hole */
24319 mm->free_area_cache = vma->vm_start;
24320@@ -352,29 +358,34 @@ try_again:
24321
24322 /* remember the largest hole we saw so far */
24323 if (addr + largest_hole < vma->vm_start)
24324- largest_hole = vma->vm_start - addr;
24325+ largest_hole = vma->vm_start - addr;
24326
24327 /* try just below the current vma->vm_start */
24328- addr = (vma->vm_start - len) & huge_page_mask(h);
24329- } while (len <= vma->vm_start);
24330+ addr = skip_heap_stack_gap(vma, len);
24331+ } while (!IS_ERR_VALUE(addr));
24332
24333 fail:
24334 /*
24335- * if hint left us with no space for the requested
24336- * mapping then try again:
24337- */
24338- if (start_addr != base) {
24339- mm->free_area_cache = base;
24340- largest_hole = 0;
24341- goto try_again;
24342- }
24343- /*
24344 * A failed mmap() very likely causes application failure,
24345 * so fall back to the bottom-up function here. This scenario
24346 * can happen with large stack limits and large mmap()
24347 * allocations.
24348 */
24349- mm->free_area_cache = TASK_UNMAPPED_BASE;
24350+
24351+#ifdef CONFIG_PAX_SEGMEXEC
24352+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24353+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24354+ else
24355+#endif
24356+
24357+ mm->mmap_base = TASK_UNMAPPED_BASE;
24358+
24359+#ifdef CONFIG_PAX_RANDMMAP
24360+ if (mm->pax_flags & MF_PAX_RANDMMAP)
24361+ mm->mmap_base += mm->delta_mmap;
24362+#endif
24363+
24364+ mm->free_area_cache = mm->mmap_base;
24365 mm->cached_hole_size = ~0UL;
24366 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24367 len, pgoff, flags);
24368@@ -382,6 +393,7 @@ fail:
24369 /*
24370 * Restore the topdown base:
24371 */
24372+ mm->mmap_base = base;
24373 mm->free_area_cache = base;
24374 mm->cached_hole_size = ~0UL;
24375
24376@@ -395,10 +407,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24377 struct hstate *h = hstate_file(file);
24378 struct mm_struct *mm = current->mm;
24379 struct vm_area_struct *vma;
24380+ unsigned long pax_task_size = TASK_SIZE;
24381
24382 if (len & ~huge_page_mask(h))
24383 return -EINVAL;
24384- if (len > TASK_SIZE)
24385+
24386+#ifdef CONFIG_PAX_SEGMEXEC
24387+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
24388+ pax_task_size = SEGMEXEC_TASK_SIZE;
24389+#endif
24390+
24391+ pax_task_size -= PAGE_SIZE;
24392+
24393+ if (len > pax_task_size)
24394 return -ENOMEM;
24395
24396 if (flags & MAP_FIXED) {
24397@@ -410,8 +431,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24398 if (addr) {
24399 addr = ALIGN(addr, huge_page_size(h));
24400 vma = find_vma(mm, addr);
24401- if (TASK_SIZE - len >= addr &&
24402- (!vma || addr + len <= vma->vm_start))
24403+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24404 return addr;
24405 }
24406 if (mm->get_unmapped_area == arch_get_unmapped_area)
24407diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24408index bc4e9d8..ca4c14b 100644
24409--- a/arch/x86/mm/init.c
24410+++ b/arch/x86/mm/init.c
24411@@ -16,6 +16,8 @@
24412 #include <asm/tlb.h>
24413 #include <asm/proto.h>
24414 #include <asm/dma.h> /* for MAX_DMA_PFN */
24415+#include <asm/desc.h>
24416+#include <asm/bios_ebda.h>
24417
24418 unsigned long __initdata pgt_buf_start;
24419 unsigned long __meminitdata pgt_buf_end;
24420@@ -38,7 +40,7 @@ struct map_range {
24421 static void __init find_early_table_space(struct map_range *mr, unsigned long end,
24422 int use_pse, int use_gbpages)
24423 {
24424- unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
24425+ unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
24426 phys_addr_t base;
24427
24428 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
24429@@ -317,10 +319,37 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24430 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24431 * mmio resources as well as potential bios/acpi data regions.
24432 */
24433+
24434+#ifdef CONFIG_GRKERNSEC_KMEM
24435+static unsigned int ebda_start __read_only;
24436+static unsigned int ebda_end __read_only;
24437+#endif
24438+
24439 int devmem_is_allowed(unsigned long pagenr)
24440 {
24441+#ifdef CONFIG_GRKERNSEC_KMEM
24442+ /* allow BDA */
24443+ if (!pagenr)
24444+ return 1;
24445+ /* allow EBDA */
24446+ if (pagenr >= ebda_start && pagenr < ebda_end)
24447+ return 1;
24448+#else
24449+ if (!pagenr)
24450+ return 1;
24451+#ifdef CONFIG_VM86
24452+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24453+ return 1;
24454+#endif
24455+#endif
24456+
24457+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24458+ return 1;
24459+#ifdef CONFIG_GRKERNSEC_KMEM
24460+ /* throw out everything else below 1MB */
24461 if (pagenr <= 256)
24462- return 1;
24463+ return 0;
24464+#endif
24465 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24466 return 0;
24467 if (!page_is_ram(pagenr))
24468@@ -377,8 +406,116 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24469 #endif
24470 }
24471
24472+#ifdef CONFIG_GRKERNSEC_KMEM
24473+static inline void gr_init_ebda(void)
24474+{
24475+ unsigned int ebda_addr;
24476+ unsigned int ebda_size = 0;
24477+
24478+ ebda_addr = get_bios_ebda();
24479+ if (ebda_addr) {
24480+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24481+ ebda_size <<= 10;
24482+ }
24483+ if (ebda_addr && ebda_size) {
24484+ ebda_start = ebda_addr >> PAGE_SHIFT;
24485+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24486+ } else {
24487+ ebda_start = 0x9f000 >> PAGE_SHIFT;
24488+ ebda_end = 0xa0000 >> PAGE_SHIFT;
24489+ }
24490+}
24491+#else
24492+static inline void gr_init_ebda(void) { }
24493+#endif
24494+
24495 void free_initmem(void)
24496 {
24497+#ifdef CONFIG_PAX_KERNEXEC
24498+#ifdef CONFIG_X86_32
24499+ /* PaX: limit KERNEL_CS to actual size */
24500+ unsigned long addr, limit;
24501+ struct desc_struct d;
24502+ int cpu;
24503+#else
24504+ pgd_t *pgd;
24505+ pud_t *pud;
24506+ pmd_t *pmd;
24507+ unsigned long addr, end;
24508+#endif
24509+#endif
24510+
24511+ gr_init_ebda();
24512+
24513+#ifdef CONFIG_PAX_KERNEXEC
24514+#ifdef CONFIG_X86_32
24515+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24516+ limit = (limit - 1UL) >> PAGE_SHIFT;
24517+
24518+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24519+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24520+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24521+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24522+ }
24523+
24524+ /* PaX: make KERNEL_CS read-only */
24525+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24526+ if (!paravirt_enabled())
24527+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24528+/*
24529+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24530+ pgd = pgd_offset_k(addr);
24531+ pud = pud_offset(pgd, addr);
24532+ pmd = pmd_offset(pud, addr);
24533+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24534+ }
24535+*/
24536+#ifdef CONFIG_X86_PAE
24537+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24538+/*
24539+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24540+ pgd = pgd_offset_k(addr);
24541+ pud = pud_offset(pgd, addr);
24542+ pmd = pmd_offset(pud, addr);
24543+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24544+ }
24545+*/
24546+#endif
24547+
24548+#ifdef CONFIG_MODULES
24549+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24550+#endif
24551+
24552+#else
24553+ /* PaX: make kernel code/rodata read-only, rest non-executable */
24554+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24555+ pgd = pgd_offset_k(addr);
24556+ pud = pud_offset(pgd, addr);
24557+ pmd = pmd_offset(pud, addr);
24558+ if (!pmd_present(*pmd))
24559+ continue;
24560+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24561+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24562+ else
24563+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24564+ }
24565+
24566+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24567+ end = addr + KERNEL_IMAGE_SIZE;
24568+ for (; addr < end; addr += PMD_SIZE) {
24569+ pgd = pgd_offset_k(addr);
24570+ pud = pud_offset(pgd, addr);
24571+ pmd = pmd_offset(pud, addr);
24572+ if (!pmd_present(*pmd))
24573+ continue;
24574+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24575+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24576+ }
24577+#endif
24578+
24579+ flush_tlb_all();
24580+#endif
24581+
24582 free_init_pages("unused kernel memory",
24583 (unsigned long)(&__init_begin),
24584 (unsigned long)(&__init_end));
24585diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24586index 575d86f..4987469 100644
24587--- a/arch/x86/mm/init_32.c
24588+++ b/arch/x86/mm/init_32.c
24589@@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24590 }
24591
24592 /*
24593- * Creates a middle page table and puts a pointer to it in the
24594- * given global directory entry. This only returns the gd entry
24595- * in non-PAE compilation mode, since the middle layer is folded.
24596- */
24597-static pmd_t * __init one_md_table_init(pgd_t *pgd)
24598-{
24599- pud_t *pud;
24600- pmd_t *pmd_table;
24601-
24602-#ifdef CONFIG_X86_PAE
24603- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24604- if (after_bootmem)
24605- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24606- else
24607- pmd_table = (pmd_t *)alloc_low_page();
24608- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24609- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24610- pud = pud_offset(pgd, 0);
24611- BUG_ON(pmd_table != pmd_offset(pud, 0));
24612-
24613- return pmd_table;
24614- }
24615-#endif
24616- pud = pud_offset(pgd, 0);
24617- pmd_table = pmd_offset(pud, 0);
24618-
24619- return pmd_table;
24620-}
24621-
24622-/*
24623 * Create a page table and place a pointer to it in a middle page
24624 * directory entry:
24625 */
24626@@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24627 page_table = (pte_t *)alloc_low_page();
24628
24629 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24630+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24631+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24632+#else
24633 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24634+#endif
24635 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24636 }
24637
24638 return pte_offset_kernel(pmd, 0);
24639 }
24640
24641+static pmd_t * __init one_md_table_init(pgd_t *pgd)
24642+{
24643+ pud_t *pud;
24644+ pmd_t *pmd_table;
24645+
24646+ pud = pud_offset(pgd, 0);
24647+ pmd_table = pmd_offset(pud, 0);
24648+
24649+ return pmd_table;
24650+}
24651+
24652 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24653 {
24654 int pgd_idx = pgd_index(vaddr);
24655@@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24656 int pgd_idx, pmd_idx;
24657 unsigned long vaddr;
24658 pgd_t *pgd;
24659+ pud_t *pud;
24660 pmd_t *pmd;
24661 pte_t *pte = NULL;
24662
24663@@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24664 pgd = pgd_base + pgd_idx;
24665
24666 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24667- pmd = one_md_table_init(pgd);
24668- pmd = pmd + pmd_index(vaddr);
24669+ pud = pud_offset(pgd, vaddr);
24670+ pmd = pmd_offset(pud, vaddr);
24671+
24672+#ifdef CONFIG_X86_PAE
24673+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24674+#endif
24675+
24676 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24677 pmd++, pmd_idx++) {
24678 pte = page_table_kmap_check(one_page_table_init(pmd),
24679@@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24680 }
24681 }
24682
24683-static inline int is_kernel_text(unsigned long addr)
24684+static inline int is_kernel_text(unsigned long start, unsigned long end)
24685 {
24686- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24687- return 1;
24688- return 0;
24689+ if ((start > ktla_ktva((unsigned long)_etext) ||
24690+ end <= ktla_ktva((unsigned long)_stext)) &&
24691+ (start > ktla_ktva((unsigned long)_einittext) ||
24692+ end <= ktla_ktva((unsigned long)_sinittext)) &&
24693+
24694+#ifdef CONFIG_ACPI_SLEEP
24695+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24696+#endif
24697+
24698+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24699+ return 0;
24700+ return 1;
24701 }
24702
24703 /*
24704@@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24705 unsigned long last_map_addr = end;
24706 unsigned long start_pfn, end_pfn;
24707 pgd_t *pgd_base = swapper_pg_dir;
24708- int pgd_idx, pmd_idx, pte_ofs;
24709+ unsigned int pgd_idx, pmd_idx, pte_ofs;
24710 unsigned long pfn;
24711 pgd_t *pgd;
24712+ pud_t *pud;
24713 pmd_t *pmd;
24714 pte_t *pte;
24715 unsigned pages_2m, pages_4k;
24716@@ -280,8 +281,13 @@ repeat:
24717 pfn = start_pfn;
24718 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24719 pgd = pgd_base + pgd_idx;
24720- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24721- pmd = one_md_table_init(pgd);
24722+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24723+ pud = pud_offset(pgd, 0);
24724+ pmd = pmd_offset(pud, 0);
24725+
24726+#ifdef CONFIG_X86_PAE
24727+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24728+#endif
24729
24730 if (pfn >= end_pfn)
24731 continue;
24732@@ -293,14 +299,13 @@ repeat:
24733 #endif
24734 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24735 pmd++, pmd_idx++) {
24736- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24737+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24738
24739 /*
24740 * Map with big pages if possible, otherwise
24741 * create normal page tables:
24742 */
24743 if (use_pse) {
24744- unsigned int addr2;
24745 pgprot_t prot = PAGE_KERNEL_LARGE;
24746 /*
24747 * first pass will use the same initial
24748@@ -310,11 +315,7 @@ repeat:
24749 __pgprot(PTE_IDENT_ATTR |
24750 _PAGE_PSE);
24751
24752- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24753- PAGE_OFFSET + PAGE_SIZE-1;
24754-
24755- if (is_kernel_text(addr) ||
24756- is_kernel_text(addr2))
24757+ if (is_kernel_text(address, address + PMD_SIZE))
24758 prot = PAGE_KERNEL_LARGE_EXEC;
24759
24760 pages_2m++;
24761@@ -331,7 +332,7 @@ repeat:
24762 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24763 pte += pte_ofs;
24764 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24765- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24766+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24767 pgprot_t prot = PAGE_KERNEL;
24768 /*
24769 * first pass will use the same initial
24770@@ -339,7 +340,7 @@ repeat:
24771 */
24772 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24773
24774- if (is_kernel_text(addr))
24775+ if (is_kernel_text(address, address + PAGE_SIZE))
24776 prot = PAGE_KERNEL_EXEC;
24777
24778 pages_4k++;
24779@@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24780
24781 pud = pud_offset(pgd, va);
24782 pmd = pmd_offset(pud, va);
24783- if (!pmd_present(*pmd))
24784+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
24785 break;
24786
24787 pte = pte_offset_kernel(pmd, va);
24788@@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
24789
24790 static void __init pagetable_init(void)
24791 {
24792- pgd_t *pgd_base = swapper_pg_dir;
24793-
24794- permanent_kmaps_init(pgd_base);
24795+ permanent_kmaps_init(swapper_pg_dir);
24796 }
24797
24798-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24799+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24800 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24801
24802 /* user-defined highmem size */
24803@@ -734,6 +733,12 @@ void __init mem_init(void)
24804
24805 pci_iommu_alloc();
24806
24807+#ifdef CONFIG_PAX_PER_CPU_PGD
24808+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24809+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24810+ KERNEL_PGD_PTRS);
24811+#endif
24812+
24813 #ifdef CONFIG_FLATMEM
24814 BUG_ON(!mem_map);
24815 #endif
24816@@ -760,7 +765,7 @@ void __init mem_init(void)
24817 reservedpages++;
24818
24819 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24820- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
24821+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
24822 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
24823
24824 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
24825@@ -801,10 +806,10 @@ void __init mem_init(void)
24826 ((unsigned long)&__init_end -
24827 (unsigned long)&__init_begin) >> 10,
24828
24829- (unsigned long)&_etext, (unsigned long)&_edata,
24830- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
24831+ (unsigned long)&_sdata, (unsigned long)&_edata,
24832+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
24833
24834- (unsigned long)&_text, (unsigned long)&_etext,
24835+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
24836 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
24837
24838 /*
24839@@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
24840 if (!kernel_set_to_readonly)
24841 return;
24842
24843+ start = ktla_ktva(start);
24844 pr_debug("Set kernel text: %lx - %lx for read write\n",
24845 start, start+size);
24846
24847@@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
24848 if (!kernel_set_to_readonly)
24849 return;
24850
24851+ start = ktla_ktva(start);
24852 pr_debug("Set kernel text: %lx - %lx for read only\n",
24853 start, start+size);
24854
24855@@ -924,6 +931,7 @@ void mark_rodata_ro(void)
24856 unsigned long start = PFN_ALIGN(_text);
24857 unsigned long size = PFN_ALIGN(_etext) - start;
24858
24859+ start = ktla_ktva(start);
24860 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
24861 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
24862 size >> 10);
24863diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
24864index 2b6b4a3..c17210d 100644
24865--- a/arch/x86/mm/init_64.c
24866+++ b/arch/x86/mm/init_64.c
24867@@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
24868 * around without checking the pgd every time.
24869 */
24870
24871-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
24872+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
24873 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24874
24875 int force_personality32;
24876@@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24877
24878 for (address = start; address <= end; address += PGDIR_SIZE) {
24879 const pgd_t *pgd_ref = pgd_offset_k(address);
24880+
24881+#ifdef CONFIG_PAX_PER_CPU_PGD
24882+ unsigned long cpu;
24883+#else
24884 struct page *page;
24885+#endif
24886
24887 if (pgd_none(*pgd_ref))
24888 continue;
24889
24890 spin_lock(&pgd_lock);
24891+
24892+#ifdef CONFIG_PAX_PER_CPU_PGD
24893+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
24894+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
24895+#else
24896 list_for_each_entry(page, &pgd_list, lru) {
24897 pgd_t *pgd;
24898 spinlock_t *pgt_lock;
24899@@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24900 /* the pgt_lock only for Xen */
24901 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
24902 spin_lock(pgt_lock);
24903+#endif
24904
24905 if (pgd_none(*pgd))
24906 set_pgd(pgd, *pgd_ref);
24907@@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24908 BUG_ON(pgd_page_vaddr(*pgd)
24909 != pgd_page_vaddr(*pgd_ref));
24910
24911+#ifndef CONFIG_PAX_PER_CPU_PGD
24912 spin_unlock(pgt_lock);
24913+#endif
24914+
24915 }
24916 spin_unlock(&pgd_lock);
24917 }
24918@@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
24919 {
24920 if (pgd_none(*pgd)) {
24921 pud_t *pud = (pud_t *)spp_getpage();
24922- pgd_populate(&init_mm, pgd, pud);
24923+ pgd_populate_kernel(&init_mm, pgd, pud);
24924 if (pud != pud_offset(pgd, 0))
24925 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
24926 pud, pud_offset(pgd, 0));
24927@@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
24928 {
24929 if (pud_none(*pud)) {
24930 pmd_t *pmd = (pmd_t *) spp_getpage();
24931- pud_populate(&init_mm, pud, pmd);
24932+ pud_populate_kernel(&init_mm, pud, pmd);
24933 if (pmd != pmd_offset(pud, 0))
24934 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
24935 pmd, pmd_offset(pud, 0));
24936@@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
24937 pmd = fill_pmd(pud, vaddr);
24938 pte = fill_pte(pmd, vaddr);
24939
24940+ pax_open_kernel();
24941 set_pte(pte, new_pte);
24942+ pax_close_kernel();
24943
24944 /*
24945 * It's enough to flush this one mapping.
24946@@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
24947 pgd = pgd_offset_k((unsigned long)__va(phys));
24948 if (pgd_none(*pgd)) {
24949 pud = (pud_t *) spp_getpage();
24950- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
24951- _PAGE_USER));
24952+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
24953 }
24954 pud = pud_offset(pgd, (unsigned long)__va(phys));
24955 if (pud_none(*pud)) {
24956 pmd = (pmd_t *) spp_getpage();
24957- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
24958- _PAGE_USER));
24959+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
24960 }
24961 pmd = pmd_offset(pud, phys);
24962 BUG_ON(!pmd_none(*pmd));
24963@@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
24964 if (pfn >= pgt_buf_top)
24965 panic("alloc_low_page: ran out of memory");
24966
24967- adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24968+ adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
24969 clear_page(adr);
24970 *phys = pfn * PAGE_SIZE;
24971 return adr;
24972@@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
24973
24974 phys = __pa(virt);
24975 left = phys & (PAGE_SIZE - 1);
24976- adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24977+ adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
24978 adr = (void *)(((unsigned long)adr) | left);
24979
24980 return adr;
24981@@ -548,7 +562,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
24982 unmap_low_page(pmd);
24983
24984 spin_lock(&init_mm.page_table_lock);
24985- pud_populate(&init_mm, pud, __va(pmd_phys));
24986+ pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
24987 spin_unlock(&init_mm.page_table_lock);
24988 }
24989 __flush_tlb_all();
24990@@ -594,7 +608,7 @@ kernel_physical_mapping_init(unsigned long start,
24991 unmap_low_page(pud);
24992
24993 spin_lock(&init_mm.page_table_lock);
24994- pgd_populate(&init_mm, pgd, __va(pud_phys));
24995+ pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
24996 spin_unlock(&init_mm.page_table_lock);
24997 pgd_changed = true;
24998 }
24999@@ -686,6 +700,12 @@ void __init mem_init(void)
25000
25001 pci_iommu_alloc();
25002
25003+#ifdef CONFIG_PAX_PER_CPU_PGD
25004+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25005+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25006+ KERNEL_PGD_PTRS);
25007+#endif
25008+
25009 /* clear_bss() already clear the empty_zero_page */
25010
25011 reservedpages = 0;
25012@@ -846,8 +866,8 @@ int kern_addr_valid(unsigned long addr)
25013 static struct vm_area_struct gate_vma = {
25014 .vm_start = VSYSCALL_START,
25015 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25016- .vm_page_prot = PAGE_READONLY_EXEC,
25017- .vm_flags = VM_READ | VM_EXEC
25018+ .vm_page_prot = PAGE_READONLY,
25019+ .vm_flags = VM_READ
25020 };
25021
25022 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25023@@ -881,7 +901,7 @@ int in_gate_area_no_mm(unsigned long addr)
25024
25025 const char *arch_vma_name(struct vm_area_struct *vma)
25026 {
25027- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25028+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25029 return "[vdso]";
25030 if (vma == &gate_vma)
25031 return "[vsyscall]";
25032diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25033index 7b179b4..6bd1777 100644
25034--- a/arch/x86/mm/iomap_32.c
25035+++ b/arch/x86/mm/iomap_32.c
25036@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25037 type = kmap_atomic_idx_push();
25038 idx = type + KM_TYPE_NR * smp_processor_id();
25039 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25040+
25041+ pax_open_kernel();
25042 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25043+ pax_close_kernel();
25044+
25045 arch_flush_lazy_mmu_mode();
25046
25047 return (void *)vaddr;
25048diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25049index 78fe3f1..8293b6f 100644
25050--- a/arch/x86/mm/ioremap.c
25051+++ b/arch/x86/mm/ioremap.c
25052@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25053 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25054 int is_ram = page_is_ram(pfn);
25055
25056- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25057+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25058 return NULL;
25059 WARN_ON_ONCE(is_ram);
25060 }
25061@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25062
25063 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25064 if (page_is_ram(start >> PAGE_SHIFT))
25065+#ifdef CONFIG_HIGHMEM
25066+ if ((start >> PAGE_SHIFT) < max_low_pfn)
25067+#endif
25068 return __va(phys);
25069
25070 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25071@@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25072 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25073
25074 static __initdata int after_paging_init;
25075-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25076+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25077
25078 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25079 {
25080@@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25081 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25082
25083 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25084- memset(bm_pte, 0, sizeof(bm_pte));
25085- pmd_populate_kernel(&init_mm, pmd, bm_pte);
25086+ pmd_populate_user(&init_mm, pmd, bm_pte);
25087
25088 /*
25089 * The boot-ioremap range spans multiple pmds, for which
25090diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25091index d87dd6d..bf3fa66 100644
25092--- a/arch/x86/mm/kmemcheck/kmemcheck.c
25093+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25094@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25095 * memory (e.g. tracked pages)? For now, we need this to avoid
25096 * invoking kmemcheck for PnP BIOS calls.
25097 */
25098- if (regs->flags & X86_VM_MASK)
25099+ if (v8086_mode(regs))
25100 return false;
25101- if (regs->cs != __KERNEL_CS)
25102+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25103 return false;
25104
25105 pte = kmemcheck_pte_lookup(address);
25106diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25107index 845df68..1d8d29f 100644
25108--- a/arch/x86/mm/mmap.c
25109+++ b/arch/x86/mm/mmap.c
25110@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25111 * Leave an at least ~128 MB hole with possible stack randomization.
25112 */
25113 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25114-#define MAX_GAP (TASK_SIZE/6*5)
25115+#define MAX_GAP (pax_task_size/6*5)
25116
25117 static int mmap_is_legacy(void)
25118 {
25119@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25120 return rnd << PAGE_SHIFT;
25121 }
25122
25123-static unsigned long mmap_base(void)
25124+static unsigned long mmap_base(struct mm_struct *mm)
25125 {
25126 unsigned long gap = rlimit(RLIMIT_STACK);
25127+ unsigned long pax_task_size = TASK_SIZE;
25128+
25129+#ifdef CONFIG_PAX_SEGMEXEC
25130+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25131+ pax_task_size = SEGMEXEC_TASK_SIZE;
25132+#endif
25133
25134 if (gap < MIN_GAP)
25135 gap = MIN_GAP;
25136 else if (gap > MAX_GAP)
25137 gap = MAX_GAP;
25138
25139- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25140+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25141 }
25142
25143 /*
25144 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25145 * does, but not when emulating X86_32
25146 */
25147-static unsigned long mmap_legacy_base(void)
25148+static unsigned long mmap_legacy_base(struct mm_struct *mm)
25149 {
25150- if (mmap_is_ia32())
25151+ if (mmap_is_ia32()) {
25152+
25153+#ifdef CONFIG_PAX_SEGMEXEC
25154+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25155+ return SEGMEXEC_TASK_UNMAPPED_BASE;
25156+ else
25157+#endif
25158+
25159 return TASK_UNMAPPED_BASE;
25160- else
25161+ } else
25162 return TASK_UNMAPPED_BASE + mmap_rnd();
25163 }
25164
25165@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25166 void arch_pick_mmap_layout(struct mm_struct *mm)
25167 {
25168 if (mmap_is_legacy()) {
25169- mm->mmap_base = mmap_legacy_base();
25170+ mm->mmap_base = mmap_legacy_base(mm);
25171+
25172+#ifdef CONFIG_PAX_RANDMMAP
25173+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25174+ mm->mmap_base += mm->delta_mmap;
25175+#endif
25176+
25177 mm->get_unmapped_area = arch_get_unmapped_area;
25178 mm->unmap_area = arch_unmap_area;
25179 } else {
25180- mm->mmap_base = mmap_base();
25181+ mm->mmap_base = mmap_base(mm);
25182+
25183+#ifdef CONFIG_PAX_RANDMMAP
25184+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25185+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25186+#endif
25187+
25188 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25189 mm->unmap_area = arch_unmap_area_topdown;
25190 }
25191diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25192index dc0b727..dc9d71a 100644
25193--- a/arch/x86/mm/mmio-mod.c
25194+++ b/arch/x86/mm/mmio-mod.c
25195@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25196 break;
25197 default:
25198 {
25199- unsigned char *ip = (unsigned char *)instptr;
25200+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25201 my_trace->opcode = MMIO_UNKNOWN_OP;
25202 my_trace->width = 0;
25203 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25204@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25205 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25206 void __iomem *addr)
25207 {
25208- static atomic_t next_id;
25209+ static atomic_unchecked_t next_id;
25210 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25211 /* These are page-unaligned. */
25212 struct mmiotrace_map map = {
25213@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25214 .private = trace
25215 },
25216 .phys = offset,
25217- .id = atomic_inc_return(&next_id)
25218+ .id = atomic_inc_return_unchecked(&next_id)
25219 };
25220 map.map_id = trace->id;
25221
25222diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25223index b008656..773eac2 100644
25224--- a/arch/x86/mm/pageattr-test.c
25225+++ b/arch/x86/mm/pageattr-test.c
25226@@ -36,7 +36,7 @@ enum {
25227
25228 static int pte_testbit(pte_t pte)
25229 {
25230- return pte_flags(pte) & _PAGE_UNUSED1;
25231+ return pte_flags(pte) & _PAGE_CPA_TEST;
25232 }
25233
25234 struct split_state {
25235diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25236index a718e0d..45efc32 100644
25237--- a/arch/x86/mm/pageattr.c
25238+++ b/arch/x86/mm/pageattr.c
25239@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25240 */
25241 #ifdef CONFIG_PCI_BIOS
25242 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25243- pgprot_val(forbidden) |= _PAGE_NX;
25244+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25245 #endif
25246
25247 /*
25248@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25249 * Does not cover __inittext since that is gone later on. On
25250 * 64bit we do not enforce !NX on the low mapping
25251 */
25252- if (within(address, (unsigned long)_text, (unsigned long)_etext))
25253- pgprot_val(forbidden) |= _PAGE_NX;
25254+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25255+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25256
25257+#ifdef CONFIG_DEBUG_RODATA
25258 /*
25259 * The .rodata section needs to be read-only. Using the pfn
25260 * catches all aliases.
25261@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25262 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25263 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25264 pgprot_val(forbidden) |= _PAGE_RW;
25265+#endif
25266
25267 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25268 /*
25269@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25270 }
25271 #endif
25272
25273+#ifdef CONFIG_PAX_KERNEXEC
25274+ if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25275+ pgprot_val(forbidden) |= _PAGE_RW;
25276+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25277+ }
25278+#endif
25279+
25280 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25281
25282 return prot;
25283@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25284 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25285 {
25286 /* change init_mm */
25287+ pax_open_kernel();
25288 set_pte_atomic(kpte, pte);
25289+
25290 #ifdef CONFIG_X86_32
25291 if (!SHARED_KERNEL_PMD) {
25292+
25293+#ifdef CONFIG_PAX_PER_CPU_PGD
25294+ unsigned long cpu;
25295+#else
25296 struct page *page;
25297+#endif
25298
25299+#ifdef CONFIG_PAX_PER_CPU_PGD
25300+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25301+ pgd_t *pgd = get_cpu_pgd(cpu);
25302+#else
25303 list_for_each_entry(page, &pgd_list, lru) {
25304- pgd_t *pgd;
25305+ pgd_t *pgd = (pgd_t *)page_address(page);
25306+#endif
25307+
25308 pud_t *pud;
25309 pmd_t *pmd;
25310
25311- pgd = (pgd_t *)page_address(page) + pgd_index(address);
25312+ pgd += pgd_index(address);
25313 pud = pud_offset(pgd, address);
25314 pmd = pmd_offset(pud, address);
25315 set_pte_atomic((pte_t *)pmd, pte);
25316 }
25317 }
25318 #endif
25319+ pax_close_kernel();
25320 }
25321
25322 static int
25323diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25324index 3d68ef6..7f69136 100644
25325--- a/arch/x86/mm/pat.c
25326+++ b/arch/x86/mm/pat.c
25327@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
25328
25329 if (!entry) {
25330 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
25331- current->comm, current->pid, start, end - 1);
25332+ current->comm, task_pid_nr(current), start, end - 1);
25333 return -EINVAL;
25334 }
25335
25336@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25337
25338 while (cursor < to) {
25339 if (!devmem_is_allowed(pfn)) {
25340- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
25341- current->comm, from, to - 1);
25342+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
25343+ current->comm, from, to - 1, cursor);
25344 return 0;
25345 }
25346 cursor += PAGE_SIZE;
25347@@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25348 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
25349 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
25350 "for [mem %#010Lx-%#010Lx]\n",
25351- current->comm, current->pid,
25352+ current->comm, task_pid_nr(current),
25353 cattr_name(flags),
25354 base, (unsigned long long)(base + size-1));
25355 return -EINVAL;
25356@@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25357 flags = lookup_memtype(paddr);
25358 if (want_flags != flags) {
25359 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
25360- current->comm, current->pid,
25361+ current->comm, task_pid_nr(current),
25362 cattr_name(want_flags),
25363 (unsigned long long)paddr,
25364 (unsigned long long)(paddr + size - 1),
25365@@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25366 free_memtype(paddr, paddr + size);
25367 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25368 " for [mem %#010Lx-%#010Lx], got %s\n",
25369- current->comm, current->pid,
25370+ current->comm, task_pid_nr(current),
25371 cattr_name(want_flags),
25372 (unsigned long long)paddr,
25373 (unsigned long long)(paddr + size - 1),
25374diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25375index 9f0614d..92ae64a 100644
25376--- a/arch/x86/mm/pf_in.c
25377+++ b/arch/x86/mm/pf_in.c
25378@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25379 int i;
25380 enum reason_type rv = OTHERS;
25381
25382- p = (unsigned char *)ins_addr;
25383+ p = (unsigned char *)ktla_ktva(ins_addr);
25384 p += skip_prefix(p, &prf);
25385 p += get_opcode(p, &opcode);
25386
25387@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25388 struct prefix_bits prf;
25389 int i;
25390
25391- p = (unsigned char *)ins_addr;
25392+ p = (unsigned char *)ktla_ktva(ins_addr);
25393 p += skip_prefix(p, &prf);
25394 p += get_opcode(p, &opcode);
25395
25396@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25397 struct prefix_bits prf;
25398 int i;
25399
25400- p = (unsigned char *)ins_addr;
25401+ p = (unsigned char *)ktla_ktva(ins_addr);
25402 p += skip_prefix(p, &prf);
25403 p += get_opcode(p, &opcode);
25404
25405@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25406 struct prefix_bits prf;
25407 int i;
25408
25409- p = (unsigned char *)ins_addr;
25410+ p = (unsigned char *)ktla_ktva(ins_addr);
25411 p += skip_prefix(p, &prf);
25412 p += get_opcode(p, &opcode);
25413 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25414@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25415 struct prefix_bits prf;
25416 int i;
25417
25418- p = (unsigned char *)ins_addr;
25419+ p = (unsigned char *)ktla_ktva(ins_addr);
25420 p += skip_prefix(p, &prf);
25421 p += get_opcode(p, &opcode);
25422 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25423diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25424index 8573b83..4f3ed7e 100644
25425--- a/arch/x86/mm/pgtable.c
25426+++ b/arch/x86/mm/pgtable.c
25427@@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25428 list_del(&page->lru);
25429 }
25430
25431-#define UNSHARED_PTRS_PER_PGD \
25432- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25433+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25434+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25435
25436+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25437+{
25438+ unsigned int count = USER_PGD_PTRS;
25439
25440+ while (count--)
25441+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25442+}
25443+#endif
25444+
25445+#ifdef CONFIG_PAX_PER_CPU_PGD
25446+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25447+{
25448+ unsigned int count = USER_PGD_PTRS;
25449+
25450+ while (count--) {
25451+ pgd_t pgd;
25452+
25453+#ifdef CONFIG_X86_64
25454+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25455+#else
25456+ pgd = *src++;
25457+#endif
25458+
25459+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25460+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25461+#endif
25462+
25463+ *dst++ = pgd;
25464+ }
25465+
25466+}
25467+#endif
25468+
25469+#ifdef CONFIG_X86_64
25470+#define pxd_t pud_t
25471+#define pyd_t pgd_t
25472+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25473+#define pxd_free(mm, pud) pud_free((mm), (pud))
25474+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25475+#define pyd_offset(mm, address) pgd_offset((mm), (address))
25476+#define PYD_SIZE PGDIR_SIZE
25477+#else
25478+#define pxd_t pmd_t
25479+#define pyd_t pud_t
25480+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25481+#define pxd_free(mm, pud) pmd_free((mm), (pud))
25482+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25483+#define pyd_offset(mm, address) pud_offset((mm), (address))
25484+#define PYD_SIZE PUD_SIZE
25485+#endif
25486+
25487+#ifdef CONFIG_PAX_PER_CPU_PGD
25488+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25489+static inline void pgd_dtor(pgd_t *pgd) {}
25490+#else
25491 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25492 {
25493 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25494@@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25495 pgd_list_del(pgd);
25496 spin_unlock(&pgd_lock);
25497 }
25498+#endif
25499
25500 /*
25501 * List of all pgd's needed for non-PAE so it can invalidate entries
25502@@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25503 * -- wli
25504 */
25505
25506-#ifdef CONFIG_X86_PAE
25507+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25508 /*
25509 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25510 * updating the top-level pagetable entries to guarantee the
25511@@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25512 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25513 * and initialize the kernel pmds here.
25514 */
25515-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25516+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25517
25518 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25519 {
25520@@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25521 */
25522 flush_tlb_mm(mm);
25523 }
25524+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25525+#define PREALLOCATED_PXDS USER_PGD_PTRS
25526 #else /* !CONFIG_X86_PAE */
25527
25528 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25529-#define PREALLOCATED_PMDS 0
25530+#define PREALLOCATED_PXDS 0
25531
25532 #endif /* CONFIG_X86_PAE */
25533
25534-static void free_pmds(pmd_t *pmds[])
25535+static void free_pxds(pxd_t *pxds[])
25536 {
25537 int i;
25538
25539- for(i = 0; i < PREALLOCATED_PMDS; i++)
25540- if (pmds[i])
25541- free_page((unsigned long)pmds[i]);
25542+ for(i = 0; i < PREALLOCATED_PXDS; i++)
25543+ if (pxds[i])
25544+ free_page((unsigned long)pxds[i]);
25545 }
25546
25547-static int preallocate_pmds(pmd_t *pmds[])
25548+static int preallocate_pxds(pxd_t *pxds[])
25549 {
25550 int i;
25551 bool failed = false;
25552
25553- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25554- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25555- if (pmd == NULL)
25556+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25557+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25558+ if (pxd == NULL)
25559 failed = true;
25560- pmds[i] = pmd;
25561+ pxds[i] = pxd;
25562 }
25563
25564 if (failed) {
25565- free_pmds(pmds);
25566+ free_pxds(pxds);
25567 return -ENOMEM;
25568 }
25569
25570@@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25571 * preallocate which never got a corresponding vma will need to be
25572 * freed manually.
25573 */
25574-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25575+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25576 {
25577 int i;
25578
25579- for(i = 0; i < PREALLOCATED_PMDS; i++) {
25580+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
25581 pgd_t pgd = pgdp[i];
25582
25583 if (pgd_val(pgd) != 0) {
25584- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25585+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25586
25587- pgdp[i] = native_make_pgd(0);
25588+ set_pgd(pgdp + i, native_make_pgd(0));
25589
25590- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25591- pmd_free(mm, pmd);
25592+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25593+ pxd_free(mm, pxd);
25594 }
25595 }
25596 }
25597
25598-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25599+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25600 {
25601- pud_t *pud;
25602+ pyd_t *pyd;
25603 unsigned long addr;
25604 int i;
25605
25606- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25607+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25608 return;
25609
25610- pud = pud_offset(pgd, 0);
25611+#ifdef CONFIG_X86_64
25612+ pyd = pyd_offset(mm, 0L);
25613+#else
25614+ pyd = pyd_offset(pgd, 0L);
25615+#endif
25616
25617- for (addr = i = 0; i < PREALLOCATED_PMDS;
25618- i++, pud++, addr += PUD_SIZE) {
25619- pmd_t *pmd = pmds[i];
25620+ for (addr = i = 0; i < PREALLOCATED_PXDS;
25621+ i++, pyd++, addr += PYD_SIZE) {
25622+ pxd_t *pxd = pxds[i];
25623
25624 if (i >= KERNEL_PGD_BOUNDARY)
25625- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25626- sizeof(pmd_t) * PTRS_PER_PMD);
25627+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25628+ sizeof(pxd_t) * PTRS_PER_PMD);
25629
25630- pud_populate(mm, pud, pmd);
25631+ pyd_populate(mm, pyd, pxd);
25632 }
25633 }
25634
25635 pgd_t *pgd_alloc(struct mm_struct *mm)
25636 {
25637 pgd_t *pgd;
25638- pmd_t *pmds[PREALLOCATED_PMDS];
25639+ pxd_t *pxds[PREALLOCATED_PXDS];
25640
25641 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25642
25643@@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25644
25645 mm->pgd = pgd;
25646
25647- if (preallocate_pmds(pmds) != 0)
25648+ if (preallocate_pxds(pxds) != 0)
25649 goto out_free_pgd;
25650
25651 if (paravirt_pgd_alloc(mm) != 0)
25652- goto out_free_pmds;
25653+ goto out_free_pxds;
25654
25655 /*
25656 * Make sure that pre-populating the pmds is atomic with
25657@@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25658 spin_lock(&pgd_lock);
25659
25660 pgd_ctor(mm, pgd);
25661- pgd_prepopulate_pmd(mm, pgd, pmds);
25662+ pgd_prepopulate_pxd(mm, pgd, pxds);
25663
25664 spin_unlock(&pgd_lock);
25665
25666 return pgd;
25667
25668-out_free_pmds:
25669- free_pmds(pmds);
25670+out_free_pxds:
25671+ free_pxds(pxds);
25672 out_free_pgd:
25673 free_page((unsigned long)pgd);
25674 out:
25675@@ -295,7 +356,7 @@ out:
25676
25677 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25678 {
25679- pgd_mop_up_pmds(mm, pgd);
25680+ pgd_mop_up_pxds(mm, pgd);
25681 pgd_dtor(pgd);
25682 paravirt_pgd_free(mm, pgd);
25683 free_page((unsigned long)pgd);
25684diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25685index a69bcb8..19068ab 100644
25686--- a/arch/x86/mm/pgtable_32.c
25687+++ b/arch/x86/mm/pgtable_32.c
25688@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25689 return;
25690 }
25691 pte = pte_offset_kernel(pmd, vaddr);
25692+
25693+ pax_open_kernel();
25694 if (pte_val(pteval))
25695 set_pte_at(&init_mm, vaddr, pte, pteval);
25696 else
25697 pte_clear(&init_mm, vaddr, pte);
25698+ pax_close_kernel();
25699
25700 /*
25701 * It's enough to flush this one mapping.
25702diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25703index 410531d..0f16030 100644
25704--- a/arch/x86/mm/setup_nx.c
25705+++ b/arch/x86/mm/setup_nx.c
25706@@ -5,8 +5,10 @@
25707 #include <asm/pgtable.h>
25708 #include <asm/proto.h>
25709
25710+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25711 static int disable_nx __cpuinitdata;
25712
25713+#ifndef CONFIG_PAX_PAGEEXEC
25714 /*
25715 * noexec = on|off
25716 *
25717@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25718 return 0;
25719 }
25720 early_param("noexec", noexec_setup);
25721+#endif
25722+
25723+#endif
25724
25725 void __cpuinit x86_configure_nx(void)
25726 {
25727+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25728 if (cpu_has_nx && !disable_nx)
25729 __supported_pte_mask |= _PAGE_NX;
25730 else
25731+#endif
25732 __supported_pte_mask &= ~_PAGE_NX;
25733 }
25734
25735diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25736index 5e57e11..64874249 100644
25737--- a/arch/x86/mm/tlb.c
25738+++ b/arch/x86/mm/tlb.c
25739@@ -66,7 +66,11 @@ void leave_mm(int cpu)
25740 BUG();
25741 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
25742 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
25743+
25744+#ifndef CONFIG_PAX_PER_CPU_PGD
25745 load_cr3(swapper_pg_dir);
25746+#endif
25747+
25748 }
25749 }
25750 EXPORT_SYMBOL_GPL(leave_mm);
25751diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25752index 877b9a1..a8ecf42 100644
25753--- a/arch/x86/net/bpf_jit.S
25754+++ b/arch/x86/net/bpf_jit.S
25755@@ -9,6 +9,7 @@
25756 */
25757 #include <linux/linkage.h>
25758 #include <asm/dwarf2.h>
25759+#include <asm/alternative-asm.h>
25760
25761 /*
25762 * Calling convention :
25763@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
25764 jle bpf_slow_path_word
25765 mov (SKBDATA,%rsi),%eax
25766 bswap %eax /* ntohl() */
25767+ pax_force_retaddr
25768 ret
25769
25770 sk_load_half:
25771@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
25772 jle bpf_slow_path_half
25773 movzwl (SKBDATA,%rsi),%eax
25774 rol $8,%ax # ntohs()
25775+ pax_force_retaddr
25776 ret
25777
25778 sk_load_byte:
25779@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
25780 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25781 jle bpf_slow_path_byte
25782 movzbl (SKBDATA,%rsi),%eax
25783+ pax_force_retaddr
25784 ret
25785
25786 /**
25787@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
25788 movzbl (SKBDATA,%rsi),%ebx
25789 and $15,%bl
25790 shl $2,%bl
25791+ pax_force_retaddr
25792 ret
25793
25794 /* rsi contains offset and can be scratched */
25795@@ -109,6 +114,7 @@ bpf_slow_path_word:
25796 js bpf_error
25797 mov -12(%rbp),%eax
25798 bswap %eax
25799+ pax_force_retaddr
25800 ret
25801
25802 bpf_slow_path_half:
25803@@ -117,12 +123,14 @@ bpf_slow_path_half:
25804 mov -12(%rbp),%ax
25805 rol $8,%ax
25806 movzwl %ax,%eax
25807+ pax_force_retaddr
25808 ret
25809
25810 bpf_slow_path_byte:
25811 bpf_slow_path_common(1)
25812 js bpf_error
25813 movzbl -12(%rbp),%eax
25814+ pax_force_retaddr
25815 ret
25816
25817 bpf_slow_path_byte_msh:
25818@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
25819 and $15,%al
25820 shl $2,%al
25821 xchg %eax,%ebx
25822+ pax_force_retaddr
25823 ret
25824
25825 #define sk_negative_common(SIZE) \
25826@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
25827 sk_negative_common(4)
25828 mov (%rax), %eax
25829 bswap %eax
25830+ pax_force_retaddr
25831 ret
25832
25833 bpf_slow_path_half_neg:
25834@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
25835 mov (%rax),%ax
25836 rol $8,%ax
25837 movzwl %ax,%eax
25838+ pax_force_retaddr
25839 ret
25840
25841 bpf_slow_path_byte_neg:
25842@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
25843 .globl sk_load_byte_negative_offset
25844 sk_negative_common(1)
25845 movzbl (%rax), %eax
25846+ pax_force_retaddr
25847 ret
25848
25849 bpf_slow_path_byte_msh_neg:
25850@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
25851 and $15,%al
25852 shl $2,%al
25853 xchg %eax,%ebx
25854+ pax_force_retaddr
25855 ret
25856
25857 bpf_error:
25858@@ -197,4 +210,5 @@ bpf_error:
25859 xor %eax,%eax
25860 mov -8(%rbp),%rbx
25861 leaveq
25862+ pax_force_retaddr
25863 ret
25864diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
25865index 0597f95..a12c36e 100644
25866--- a/arch/x86/net/bpf_jit_comp.c
25867+++ b/arch/x86/net/bpf_jit_comp.c
25868@@ -120,6 +120,11 @@ static inline void bpf_flush_icache(void *start, void *end)
25869 set_fs(old_fs);
25870 }
25871
25872+struct bpf_jit_work {
25873+ struct work_struct work;
25874+ void *image;
25875+};
25876+
25877 #define CHOOSE_LOAD_FUNC(K, func) \
25878 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
25879
25880@@ -146,6 +151,10 @@ void bpf_jit_compile(struct sk_filter *fp)
25881 if (addrs == NULL)
25882 return;
25883
25884+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
25885+ if (!fp->work)
25886+ goto out;
25887+
25888 /* Before first pass, make a rough estimation of addrs[]
25889 * each bpf instruction is translated to less than 64 bytes
25890 */
25891@@ -589,17 +598,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25892 break;
25893 default:
25894 /* hmm, too complex filter, give up with jit compiler */
25895- goto out;
25896+ goto error;
25897 }
25898 ilen = prog - temp;
25899 if (image) {
25900 if (unlikely(proglen + ilen > oldproglen)) {
25901 pr_err("bpb_jit_compile fatal error\n");
25902- kfree(addrs);
25903- module_free(NULL, image);
25904- return;
25905+ module_free_exec(NULL, image);
25906+ goto error;
25907 }
25908+ pax_open_kernel();
25909 memcpy(image + proglen, temp, ilen);
25910+ pax_close_kernel();
25911 }
25912 proglen += ilen;
25913 addrs[i] = proglen;
25914@@ -620,11 +630,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25915 break;
25916 }
25917 if (proglen == oldproglen) {
25918- image = module_alloc(max_t(unsigned int,
25919- proglen,
25920- sizeof(struct work_struct)));
25921+ image = module_alloc_exec(proglen);
25922 if (!image)
25923- goto out;
25924+ goto error;
25925 }
25926 oldproglen = proglen;
25927 }
25928@@ -640,7 +648,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25929 bpf_flush_icache(image, image + proglen);
25930
25931 fp->bpf_func = (void *)image;
25932- }
25933+ } else
25934+error:
25935+ kfree(fp->work);
25936+
25937 out:
25938 kfree(addrs);
25939 return;
25940@@ -648,18 +659,20 @@ out:
25941
25942 static void jit_free_defer(struct work_struct *arg)
25943 {
25944- module_free(NULL, arg);
25945+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
25946+ kfree(arg);
25947 }
25948
25949 /* run from softirq, we must use a work_struct to call
25950- * module_free() from process context
25951+ * module_free_exec() from process context
25952 */
25953 void bpf_jit_free(struct sk_filter *fp)
25954 {
25955 if (fp->bpf_func != sk_run_filter) {
25956- struct work_struct *work = (struct work_struct *)fp->bpf_func;
25957+ struct work_struct *work = &fp->work->work;
25958
25959 INIT_WORK(work, jit_free_defer);
25960+ fp->work->image = fp->bpf_func;
25961 schedule_work(work);
25962 }
25963 }
25964diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
25965index d6aa6e8..266395a 100644
25966--- a/arch/x86/oprofile/backtrace.c
25967+++ b/arch/x86/oprofile/backtrace.c
25968@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
25969 struct stack_frame_ia32 *fp;
25970 unsigned long bytes;
25971
25972- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25973+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25974 if (bytes != sizeof(bufhead))
25975 return NULL;
25976
25977- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
25978+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
25979
25980 oprofile_add_trace(bufhead[0].return_address);
25981
25982@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
25983 struct stack_frame bufhead[2];
25984 unsigned long bytes;
25985
25986- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
25987+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
25988 if (bytes != sizeof(bufhead))
25989 return NULL;
25990
25991@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
25992 {
25993 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
25994
25995- if (!user_mode_vm(regs)) {
25996+ if (!user_mode(regs)) {
25997 unsigned long stack = kernel_stack_pointer(regs);
25998 if (depth)
25999 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26000diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26001index 140942f..8a5cc55 100644
26002--- a/arch/x86/pci/mrst.c
26003+++ b/arch/x86/pci/mrst.c
26004@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
26005 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
26006 pci_mmcfg_late_init();
26007 pcibios_enable_irq = mrst_pci_irq_enable;
26008- pci_root_ops = pci_mrst_ops;
26009+ pax_open_kernel();
26010+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26011+ pax_close_kernel();
26012 pci_soc_mode = 1;
26013 /* Continue with standard init */
26014 return 1;
26015diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26016index da8fe05..7ee6704 100644
26017--- a/arch/x86/pci/pcbios.c
26018+++ b/arch/x86/pci/pcbios.c
26019@@ -79,50 +79,93 @@ union bios32 {
26020 static struct {
26021 unsigned long address;
26022 unsigned short segment;
26023-} bios32_indirect = { 0, __KERNEL_CS };
26024+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26025
26026 /*
26027 * Returns the entry point for the given service, NULL on error
26028 */
26029
26030-static unsigned long bios32_service(unsigned long service)
26031+static unsigned long __devinit bios32_service(unsigned long service)
26032 {
26033 unsigned char return_code; /* %al */
26034 unsigned long address; /* %ebx */
26035 unsigned long length; /* %ecx */
26036 unsigned long entry; /* %edx */
26037 unsigned long flags;
26038+ struct desc_struct d, *gdt;
26039
26040 local_irq_save(flags);
26041- __asm__("lcall *(%%edi); cld"
26042+
26043+ gdt = get_cpu_gdt_table(smp_processor_id());
26044+
26045+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26046+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26047+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26048+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26049+
26050+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26051 : "=a" (return_code),
26052 "=b" (address),
26053 "=c" (length),
26054 "=d" (entry)
26055 : "0" (service),
26056 "1" (0),
26057- "D" (&bios32_indirect));
26058+ "D" (&bios32_indirect),
26059+ "r"(__PCIBIOS_DS)
26060+ : "memory");
26061+
26062+ pax_open_kernel();
26063+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26064+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26065+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26066+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26067+ pax_close_kernel();
26068+
26069 local_irq_restore(flags);
26070
26071 switch (return_code) {
26072- case 0:
26073- return address + entry;
26074- case 0x80: /* Not present */
26075- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26076- return 0;
26077- default: /* Shouldn't happen */
26078- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26079- service, return_code);
26080+ case 0: {
26081+ int cpu;
26082+ unsigned char flags;
26083+
26084+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26085+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26086+ printk(KERN_WARNING "bios32_service: not valid\n");
26087 return 0;
26088+ }
26089+ address = address + PAGE_OFFSET;
26090+ length += 16UL; /* some BIOSs underreport this... */
26091+ flags = 4;
26092+ if (length >= 64*1024*1024) {
26093+ length >>= PAGE_SHIFT;
26094+ flags |= 8;
26095+ }
26096+
26097+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26098+ gdt = get_cpu_gdt_table(cpu);
26099+ pack_descriptor(&d, address, length, 0x9b, flags);
26100+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26101+ pack_descriptor(&d, address, length, 0x93, flags);
26102+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26103+ }
26104+ return entry;
26105+ }
26106+ case 0x80: /* Not present */
26107+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26108+ return 0;
26109+ default: /* Shouldn't happen */
26110+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26111+ service, return_code);
26112+ return 0;
26113 }
26114 }
26115
26116 static struct {
26117 unsigned long address;
26118 unsigned short segment;
26119-} pci_indirect = { 0, __KERNEL_CS };
26120+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26121
26122-static int pci_bios_present;
26123+static int pci_bios_present __read_only;
26124
26125 static int __devinit check_pcibios(void)
26126 {
26127@@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26128 unsigned long flags, pcibios_entry;
26129
26130 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26131- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26132+ pci_indirect.address = pcibios_entry;
26133
26134 local_irq_save(flags);
26135- __asm__(
26136- "lcall *(%%edi); cld\n\t"
26137+ __asm__("movw %w6, %%ds\n\t"
26138+ "lcall *%%ss:(%%edi); cld\n\t"
26139+ "push %%ss\n\t"
26140+ "pop %%ds\n\t"
26141 "jc 1f\n\t"
26142 "xor %%ah, %%ah\n"
26143 "1:"
26144@@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26145 "=b" (ebx),
26146 "=c" (ecx)
26147 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26148- "D" (&pci_indirect)
26149+ "D" (&pci_indirect),
26150+ "r" (__PCIBIOS_DS)
26151 : "memory");
26152 local_irq_restore(flags);
26153
26154@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26155
26156 switch (len) {
26157 case 1:
26158- __asm__("lcall *(%%esi); cld\n\t"
26159+ __asm__("movw %w6, %%ds\n\t"
26160+ "lcall *%%ss:(%%esi); cld\n\t"
26161+ "push %%ss\n\t"
26162+ "pop %%ds\n\t"
26163 "jc 1f\n\t"
26164 "xor %%ah, %%ah\n"
26165 "1:"
26166@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26167 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26168 "b" (bx),
26169 "D" ((long)reg),
26170- "S" (&pci_indirect));
26171+ "S" (&pci_indirect),
26172+ "r" (__PCIBIOS_DS));
26173 /*
26174 * Zero-extend the result beyond 8 bits, do not trust the
26175 * BIOS having done it:
26176@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26177 *value &= 0xff;
26178 break;
26179 case 2:
26180- __asm__("lcall *(%%esi); cld\n\t"
26181+ __asm__("movw %w6, %%ds\n\t"
26182+ "lcall *%%ss:(%%esi); cld\n\t"
26183+ "push %%ss\n\t"
26184+ "pop %%ds\n\t"
26185 "jc 1f\n\t"
26186 "xor %%ah, %%ah\n"
26187 "1:"
26188@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26189 : "1" (PCIBIOS_READ_CONFIG_WORD),
26190 "b" (bx),
26191 "D" ((long)reg),
26192- "S" (&pci_indirect));
26193+ "S" (&pci_indirect),
26194+ "r" (__PCIBIOS_DS));
26195 /*
26196 * Zero-extend the result beyond 16 bits, do not trust the
26197 * BIOS having done it:
26198@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26199 *value &= 0xffff;
26200 break;
26201 case 4:
26202- __asm__("lcall *(%%esi); cld\n\t"
26203+ __asm__("movw %w6, %%ds\n\t"
26204+ "lcall *%%ss:(%%esi); cld\n\t"
26205+ "push %%ss\n\t"
26206+ "pop %%ds\n\t"
26207 "jc 1f\n\t"
26208 "xor %%ah, %%ah\n"
26209 "1:"
26210@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26211 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26212 "b" (bx),
26213 "D" ((long)reg),
26214- "S" (&pci_indirect));
26215+ "S" (&pci_indirect),
26216+ "r" (__PCIBIOS_DS));
26217 break;
26218 }
26219
26220@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26221
26222 switch (len) {
26223 case 1:
26224- __asm__("lcall *(%%esi); cld\n\t"
26225+ __asm__("movw %w6, %%ds\n\t"
26226+ "lcall *%%ss:(%%esi); cld\n\t"
26227+ "push %%ss\n\t"
26228+ "pop %%ds\n\t"
26229 "jc 1f\n\t"
26230 "xor %%ah, %%ah\n"
26231 "1:"
26232@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26233 "c" (value),
26234 "b" (bx),
26235 "D" ((long)reg),
26236- "S" (&pci_indirect));
26237+ "S" (&pci_indirect),
26238+ "r" (__PCIBIOS_DS));
26239 break;
26240 case 2:
26241- __asm__("lcall *(%%esi); cld\n\t"
26242+ __asm__("movw %w6, %%ds\n\t"
26243+ "lcall *%%ss:(%%esi); cld\n\t"
26244+ "push %%ss\n\t"
26245+ "pop %%ds\n\t"
26246 "jc 1f\n\t"
26247 "xor %%ah, %%ah\n"
26248 "1:"
26249@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26250 "c" (value),
26251 "b" (bx),
26252 "D" ((long)reg),
26253- "S" (&pci_indirect));
26254+ "S" (&pci_indirect),
26255+ "r" (__PCIBIOS_DS));
26256 break;
26257 case 4:
26258- __asm__("lcall *(%%esi); cld\n\t"
26259+ __asm__("movw %w6, %%ds\n\t"
26260+ "lcall *%%ss:(%%esi); cld\n\t"
26261+ "push %%ss\n\t"
26262+ "pop %%ds\n\t"
26263 "jc 1f\n\t"
26264 "xor %%ah, %%ah\n"
26265 "1:"
26266@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26267 "c" (value),
26268 "b" (bx),
26269 "D" ((long)reg),
26270- "S" (&pci_indirect));
26271+ "S" (&pci_indirect),
26272+ "r" (__PCIBIOS_DS));
26273 break;
26274 }
26275
26276@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26277
26278 DBG("PCI: Fetching IRQ routing table... ");
26279 __asm__("push %%es\n\t"
26280+ "movw %w8, %%ds\n\t"
26281 "push %%ds\n\t"
26282 "pop %%es\n\t"
26283- "lcall *(%%esi); cld\n\t"
26284+ "lcall *%%ss:(%%esi); cld\n\t"
26285 "pop %%es\n\t"
26286+ "push %%ss\n\t"
26287+ "pop %%ds\n"
26288 "jc 1f\n\t"
26289 "xor %%ah, %%ah\n"
26290 "1:"
26291@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26292 "1" (0),
26293 "D" ((long) &opt),
26294 "S" (&pci_indirect),
26295- "m" (opt)
26296+ "m" (opt),
26297+ "r" (__PCIBIOS_DS)
26298 : "memory");
26299 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26300 if (ret & 0xff00)
26301@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26302 {
26303 int ret;
26304
26305- __asm__("lcall *(%%esi); cld\n\t"
26306+ __asm__("movw %w5, %%ds\n\t"
26307+ "lcall *%%ss:(%%esi); cld\n\t"
26308+ "push %%ss\n\t"
26309+ "pop %%ds\n"
26310 "jc 1f\n\t"
26311 "xor %%ah, %%ah\n"
26312 "1:"
26313@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26314 : "0" (PCIBIOS_SET_PCI_HW_INT),
26315 "b" ((dev->bus->number << 8) | dev->devfn),
26316 "c" ((irq << 8) | (pin + 10)),
26317- "S" (&pci_indirect));
26318+ "S" (&pci_indirect),
26319+ "r" (__PCIBIOS_DS));
26320 return !(ret & 0xff00);
26321 }
26322 EXPORT_SYMBOL(pcibios_set_irq_routing);
26323diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26324index 40e4469..1ab536e 100644
26325--- a/arch/x86/platform/efi/efi_32.c
26326+++ b/arch/x86/platform/efi/efi_32.c
26327@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26328 {
26329 struct desc_ptr gdt_descr;
26330
26331+#ifdef CONFIG_PAX_KERNEXEC
26332+ struct desc_struct d;
26333+#endif
26334+
26335 local_irq_save(efi_rt_eflags);
26336
26337 load_cr3(initial_page_table);
26338 __flush_tlb_all();
26339
26340+#ifdef CONFIG_PAX_KERNEXEC
26341+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26342+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26343+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26344+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26345+#endif
26346+
26347 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26348 gdt_descr.size = GDT_SIZE - 1;
26349 load_gdt(&gdt_descr);
26350@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26351 {
26352 struct desc_ptr gdt_descr;
26353
26354+#ifdef CONFIG_PAX_KERNEXEC
26355+ struct desc_struct d;
26356+
26357+ memset(&d, 0, sizeof d);
26358+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26359+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26360+#endif
26361+
26362 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26363 gdt_descr.size = GDT_SIZE - 1;
26364 load_gdt(&gdt_descr);
26365diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26366index fbe66e6..eae5e38 100644
26367--- a/arch/x86/platform/efi/efi_stub_32.S
26368+++ b/arch/x86/platform/efi/efi_stub_32.S
26369@@ -6,7 +6,9 @@
26370 */
26371
26372 #include <linux/linkage.h>
26373+#include <linux/init.h>
26374 #include <asm/page_types.h>
26375+#include <asm/segment.h>
26376
26377 /*
26378 * efi_call_phys(void *, ...) is a function with variable parameters.
26379@@ -20,7 +22,7 @@
26380 * service functions will comply with gcc calling convention, too.
26381 */
26382
26383-.text
26384+__INIT
26385 ENTRY(efi_call_phys)
26386 /*
26387 * 0. The function can only be called in Linux kernel. So CS has been
26388@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
26389 * The mapping of lower virtual memory has been created in prelog and
26390 * epilog.
26391 */
26392- movl $1f, %edx
26393- subl $__PAGE_OFFSET, %edx
26394- jmp *%edx
26395+#ifdef CONFIG_PAX_KERNEXEC
26396+ movl $(__KERNEXEC_EFI_DS), %edx
26397+ mov %edx, %ds
26398+ mov %edx, %es
26399+ mov %edx, %ss
26400+ addl $2f,(1f)
26401+ ljmp *(1f)
26402+
26403+__INITDATA
26404+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
26405+.previous
26406+
26407+2:
26408+ subl $2b,(1b)
26409+#else
26410+ jmp 1f-__PAGE_OFFSET
26411 1:
26412+#endif
26413
26414 /*
26415 * 2. Now on the top of stack is the return
26416@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
26417 * parameter 2, ..., param n. To make things easy, we save the return
26418 * address of efi_call_phys in a global variable.
26419 */
26420- popl %edx
26421- movl %edx, saved_return_addr
26422- /* get the function pointer into ECX*/
26423- popl %ecx
26424- movl %ecx, efi_rt_function_ptr
26425- movl $2f, %edx
26426- subl $__PAGE_OFFSET, %edx
26427- pushl %edx
26428+ popl (saved_return_addr)
26429+ popl (efi_rt_function_ptr)
26430
26431 /*
26432 * 3. Clear PG bit in %CR0.
26433@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
26434 /*
26435 * 5. Call the physical function.
26436 */
26437- jmp *%ecx
26438+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
26439
26440-2:
26441 /*
26442 * 6. After EFI runtime service returns, control will return to
26443 * following instruction. We'd better readjust stack pointer first.
26444@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
26445 movl %cr0, %edx
26446 orl $0x80000000, %edx
26447 movl %edx, %cr0
26448- jmp 1f
26449-1:
26450+
26451 /*
26452 * 8. Now restore the virtual mode from flat mode by
26453 * adding EIP with PAGE_OFFSET.
26454 */
26455- movl $1f, %edx
26456- jmp *%edx
26457+#ifdef CONFIG_PAX_KERNEXEC
26458+ movl $(__KERNEL_DS), %edx
26459+ mov %edx, %ds
26460+ mov %edx, %es
26461+ mov %edx, %ss
26462+ ljmp $(__KERNEL_CS),$1f
26463+#else
26464+ jmp 1f+__PAGE_OFFSET
26465+#endif
26466 1:
26467
26468 /*
26469 * 9. Balance the stack. And because EAX contain the return value,
26470 * we'd better not clobber it.
26471 */
26472- leal efi_rt_function_ptr, %edx
26473- movl (%edx), %ecx
26474- pushl %ecx
26475+ pushl (efi_rt_function_ptr)
26476
26477 /*
26478- * 10. Push the saved return address onto the stack and return.
26479+ * 10. Return to the saved return address.
26480 */
26481- leal saved_return_addr, %edx
26482- movl (%edx), %ecx
26483- pushl %ecx
26484- ret
26485+ jmpl *(saved_return_addr)
26486 ENDPROC(efi_call_phys)
26487 .previous
26488
26489-.data
26490+__INITDATA
26491 saved_return_addr:
26492 .long 0
26493 efi_rt_function_ptr:
26494diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26495index 4c07cca..2c8427d 100644
26496--- a/arch/x86/platform/efi/efi_stub_64.S
26497+++ b/arch/x86/platform/efi/efi_stub_64.S
26498@@ -7,6 +7,7 @@
26499 */
26500
26501 #include <linux/linkage.h>
26502+#include <asm/alternative-asm.h>
26503
26504 #define SAVE_XMM \
26505 mov %rsp, %rax; \
26506@@ -40,6 +41,7 @@ ENTRY(efi_call0)
26507 call *%rdi
26508 addq $32, %rsp
26509 RESTORE_XMM
26510+ pax_force_retaddr 0, 1
26511 ret
26512 ENDPROC(efi_call0)
26513
26514@@ -50,6 +52,7 @@ ENTRY(efi_call1)
26515 call *%rdi
26516 addq $32, %rsp
26517 RESTORE_XMM
26518+ pax_force_retaddr 0, 1
26519 ret
26520 ENDPROC(efi_call1)
26521
26522@@ -60,6 +63,7 @@ ENTRY(efi_call2)
26523 call *%rdi
26524 addq $32, %rsp
26525 RESTORE_XMM
26526+ pax_force_retaddr 0, 1
26527 ret
26528 ENDPROC(efi_call2)
26529
26530@@ -71,6 +75,7 @@ ENTRY(efi_call3)
26531 call *%rdi
26532 addq $32, %rsp
26533 RESTORE_XMM
26534+ pax_force_retaddr 0, 1
26535 ret
26536 ENDPROC(efi_call3)
26537
26538@@ -83,6 +88,7 @@ ENTRY(efi_call4)
26539 call *%rdi
26540 addq $32, %rsp
26541 RESTORE_XMM
26542+ pax_force_retaddr 0, 1
26543 ret
26544 ENDPROC(efi_call4)
26545
26546@@ -96,6 +102,7 @@ ENTRY(efi_call5)
26547 call *%rdi
26548 addq $48, %rsp
26549 RESTORE_XMM
26550+ pax_force_retaddr 0, 1
26551 ret
26552 ENDPROC(efi_call5)
26553
26554@@ -112,5 +119,6 @@ ENTRY(efi_call6)
26555 call *%rdi
26556 addq $48, %rsp
26557 RESTORE_XMM
26558+ pax_force_retaddr 0, 1
26559 ret
26560 ENDPROC(efi_call6)
26561diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26562index fd41a92..9c33628 100644
26563--- a/arch/x86/platform/mrst/mrst.c
26564+++ b/arch/x86/platform/mrst/mrst.c
26565@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26566 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26567 int sfi_mrtc_num;
26568
26569-static void mrst_power_off(void)
26570+static __noreturn void mrst_power_off(void)
26571 {
26572+ BUG();
26573 }
26574
26575-static void mrst_reboot(void)
26576+static __noreturn void mrst_reboot(void)
26577 {
26578 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26579+ BUG();
26580 }
26581
26582 /* parse all the mtimer info to a static mtimer array */
26583diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26584index 218cdb1..fd55c08 100644
26585--- a/arch/x86/power/cpu.c
26586+++ b/arch/x86/power/cpu.c
26587@@ -132,7 +132,7 @@ static void do_fpu_end(void)
26588 static void fix_processor_context(void)
26589 {
26590 int cpu = smp_processor_id();
26591- struct tss_struct *t = &per_cpu(init_tss, cpu);
26592+ struct tss_struct *t = init_tss + cpu;
26593
26594 set_tss_desc(cpu, t); /*
26595 * This just modifies memory; should not be
26596@@ -142,7 +142,9 @@ static void fix_processor_context(void)
26597 */
26598
26599 #ifdef CONFIG_X86_64
26600+ pax_open_kernel();
26601 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26602+ pax_close_kernel();
26603
26604 syscall_init(); /* This sets MSR_*STAR and related */
26605 #endif
26606diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
26607index cbca565..35ce1d7 100644
26608--- a/arch/x86/realmode/init.c
26609+++ b/arch/x86/realmode/init.c
26610@@ -62,7 +62,13 @@ void __init setup_real_mode(void)
26611 __va(real_mode_header->trampoline_header);
26612
26613 #ifdef CONFIG_X86_32
26614- trampoline_header->start = __pa(startup_32_smp);
26615+ trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
26616+
26617+#ifdef CONFIG_PAX_KERNEXEC
26618+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
26619+#endif
26620+
26621+ trampoline_header->boot_cs = __BOOT_CS;
26622 trampoline_header->gdt_limit = __BOOT_DS + 7;
26623 trampoline_header->gdt_base = __pa(boot_gdt);
26624 #else
26625diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
26626index 5b84a2d..a004393 100644
26627--- a/arch/x86/realmode/rm/Makefile
26628+++ b/arch/x86/realmode/rm/Makefile
26629@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
26630 $(call cc-option, -fno-unit-at-a-time)) \
26631 $(call cc-option, -fno-stack-protector) \
26632 $(call cc-option, -mpreferred-stack-boundary=2)
26633+ifdef CONSTIFY_PLUGIN
26634+KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
26635+endif
26636 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
26637 GCOV_PROFILE := n
26638diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
26639index c1b2791..f9e31c7 100644
26640--- a/arch/x86/realmode/rm/trampoline_32.S
26641+++ b/arch/x86/realmode/rm/trampoline_32.S
26642@@ -25,6 +25,12 @@
26643 #include <asm/page_types.h>
26644 #include "realmode.h"
26645
26646+#ifdef CONFIG_PAX_KERNEXEC
26647+#define ta(X) (X)
26648+#else
26649+#define ta(X) (pa_ ## X)
26650+#endif
26651+
26652 .text
26653 .code16
26654
26655@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
26656
26657 cli # We should be safe anyway
26658
26659- movl tr_start, %eax # where we need to go
26660-
26661 movl $0xA5A5A5A5, trampoline_status
26662 # write marker for master knows we're running
26663
26664@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
26665 movw $1, %dx # protected mode (PE) bit
26666 lmsw %dx # into protected mode
26667
26668- ljmpl $__BOOT_CS, $pa_startup_32
26669+ ljmpl *(trampoline_header)
26670
26671 .section ".text32","ax"
26672 .code32
26673@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
26674 .balign 8
26675 GLOBAL(trampoline_header)
26676 tr_start: .space 4
26677- tr_gdt_pad: .space 2
26678+ tr_boot_cs: .space 2
26679 tr_gdt: .space 6
26680 END(trampoline_header)
26681
26682diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
26683index bb360dc..3e5945f 100644
26684--- a/arch/x86/realmode/rm/trampoline_64.S
26685+++ b/arch/x86/realmode/rm/trampoline_64.S
26686@@ -107,7 +107,7 @@ ENTRY(startup_32)
26687 wrmsr
26688
26689 # Enable paging and in turn activate Long Mode
26690- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
26691+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
26692 movl %eax, %cr0
26693
26694 /*
26695diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
26696index 5a1847d..deccb30 100644
26697--- a/arch/x86/tools/relocs.c
26698+++ b/arch/x86/tools/relocs.c
26699@@ -12,10 +12,13 @@
26700 #include <regex.h>
26701 #include <tools/le_byteshift.h>
26702
26703+#include "../../../include/generated/autoconf.h"
26704+
26705 static void die(char *fmt, ...);
26706
26707 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
26708 static Elf32_Ehdr ehdr;
26709+static Elf32_Phdr *phdr;
26710 static unsigned long reloc_count, reloc_idx;
26711 static unsigned long *relocs;
26712 static unsigned long reloc16_count, reloc16_idx;
26713@@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
26714 }
26715 }
26716
26717+static void read_phdrs(FILE *fp)
26718+{
26719+ unsigned int i;
26720+
26721+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
26722+ if (!phdr) {
26723+ die("Unable to allocate %d program headers\n",
26724+ ehdr.e_phnum);
26725+ }
26726+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
26727+ die("Seek to %d failed: %s\n",
26728+ ehdr.e_phoff, strerror(errno));
26729+ }
26730+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
26731+ die("Cannot read ELF program headers: %s\n",
26732+ strerror(errno));
26733+ }
26734+ for(i = 0; i < ehdr.e_phnum; i++) {
26735+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
26736+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
26737+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
26738+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
26739+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
26740+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
26741+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
26742+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
26743+ }
26744+
26745+}
26746+
26747 static void read_shdrs(FILE *fp)
26748 {
26749- int i;
26750+ unsigned int i;
26751 Elf32_Shdr shdr;
26752
26753 secs = calloc(ehdr.e_shnum, sizeof(struct section));
26754@@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
26755
26756 static void read_strtabs(FILE *fp)
26757 {
26758- int i;
26759+ unsigned int i;
26760 for (i = 0; i < ehdr.e_shnum; i++) {
26761 struct section *sec = &secs[i];
26762 if (sec->shdr.sh_type != SHT_STRTAB) {
26763@@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
26764
26765 static void read_symtabs(FILE *fp)
26766 {
26767- int i,j;
26768+ unsigned int i,j;
26769 for (i = 0; i < ehdr.e_shnum; i++) {
26770 struct section *sec = &secs[i];
26771 if (sec->shdr.sh_type != SHT_SYMTAB) {
26772@@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
26773 }
26774
26775
26776-static void read_relocs(FILE *fp)
26777+static void read_relocs(FILE *fp, int use_real_mode)
26778 {
26779- int i,j;
26780+ unsigned int i,j;
26781+ uint32_t base;
26782+
26783 for (i = 0; i < ehdr.e_shnum; i++) {
26784 struct section *sec = &secs[i];
26785 if (sec->shdr.sh_type != SHT_REL) {
26786@@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
26787 die("Cannot read symbol table: %s\n",
26788 strerror(errno));
26789 }
26790+ base = 0;
26791+
26792+#ifdef CONFIG_X86_32
26793+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
26794+ if (phdr[j].p_type != PT_LOAD )
26795+ continue;
26796+ 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)
26797+ continue;
26798+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
26799+ break;
26800+ }
26801+#endif
26802+
26803 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
26804 Elf32_Rel *rel = &sec->reltab[j];
26805- rel->r_offset = elf32_to_cpu(rel->r_offset);
26806+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
26807 rel->r_info = elf32_to_cpu(rel->r_info);
26808 }
26809 }
26810@@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
26811
26812 static void print_absolute_symbols(void)
26813 {
26814- int i;
26815+ unsigned int i;
26816 printf("Absolute symbols\n");
26817 printf(" Num: Value Size Type Bind Visibility Name\n");
26818 for (i = 0; i < ehdr.e_shnum; i++) {
26819 struct section *sec = &secs[i];
26820 char *sym_strtab;
26821- int j;
26822+ unsigned int j;
26823
26824 if (sec->shdr.sh_type != SHT_SYMTAB) {
26825 continue;
26826@@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
26827
26828 static void print_absolute_relocs(void)
26829 {
26830- int i, printed = 0;
26831+ unsigned int i, printed = 0;
26832
26833 for (i = 0; i < ehdr.e_shnum; i++) {
26834 struct section *sec = &secs[i];
26835 struct section *sec_applies, *sec_symtab;
26836 char *sym_strtab;
26837 Elf32_Sym *sh_symtab;
26838- int j;
26839+ unsigned int j;
26840 if (sec->shdr.sh_type != SHT_REL) {
26841 continue;
26842 }
26843@@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
26844 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26845 int use_real_mode)
26846 {
26847- int i;
26848+ unsigned int i;
26849 /* Walk through the relocations */
26850 for (i = 0; i < ehdr.e_shnum; i++) {
26851 char *sym_strtab;
26852 Elf32_Sym *sh_symtab;
26853 struct section *sec_applies, *sec_symtab;
26854- int j;
26855+ unsigned int j;
26856 struct section *sec = &secs[i];
26857
26858 if (sec->shdr.sh_type != SHT_REL) {
26859@@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26860 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
26861 r_type = ELF32_R_TYPE(rel->r_info);
26862
26863+ if (!use_real_mode) {
26864+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
26865+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
26866+ continue;
26867+
26868+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
26869+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
26870+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
26871+ continue;
26872+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
26873+ continue;
26874+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
26875+ continue;
26876+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
26877+ continue;
26878+#endif
26879+ }
26880+
26881 shn_abs = sym->st_shndx == SHN_ABS;
26882
26883 switch (r_type) {
26884@@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
26885
26886 static void emit_relocs(int as_text, int use_real_mode)
26887 {
26888- int i;
26889+ unsigned int i;
26890 /* Count how many relocations I have and allocate space for them. */
26891 reloc_count = 0;
26892 walk_relocs(count_reloc, use_real_mode);
26893@@ -808,10 +874,11 @@ int main(int argc, char **argv)
26894 fname, strerror(errno));
26895 }
26896 read_ehdr(fp);
26897+ read_phdrs(fp);
26898 read_shdrs(fp);
26899 read_strtabs(fp);
26900 read_symtabs(fp);
26901- read_relocs(fp);
26902+ read_relocs(fp, use_real_mode);
26903 if (show_absolute_syms) {
26904 print_absolute_symbols();
26905 return 0;
26906diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
26907index fd14be1..e3c79c0 100644
26908--- a/arch/x86/vdso/Makefile
26909+++ b/arch/x86/vdso/Makefile
26910@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
26911 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
26912 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
26913
26914-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26915+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26916 GCOV_PROFILE := n
26917
26918 #
26919diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
26920index 66e6d93..587f435 100644
26921--- a/arch/x86/vdso/vdso32-setup.c
26922+++ b/arch/x86/vdso/vdso32-setup.c
26923@@ -25,6 +25,7 @@
26924 #include <asm/tlbflush.h>
26925 #include <asm/vdso.h>
26926 #include <asm/proto.h>
26927+#include <asm/mman.h>
26928
26929 enum {
26930 VDSO_DISABLED = 0,
26931@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
26932 void enable_sep_cpu(void)
26933 {
26934 int cpu = get_cpu();
26935- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26936+ struct tss_struct *tss = init_tss + cpu;
26937
26938 if (!boot_cpu_has(X86_FEATURE_SEP)) {
26939 put_cpu();
26940@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
26941 gate_vma.vm_start = FIXADDR_USER_START;
26942 gate_vma.vm_end = FIXADDR_USER_END;
26943 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
26944- gate_vma.vm_page_prot = __P101;
26945+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
26946
26947 return 0;
26948 }
26949@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26950 if (compat)
26951 addr = VDSO_HIGH_BASE;
26952 else {
26953- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
26954+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
26955 if (IS_ERR_VALUE(addr)) {
26956 ret = addr;
26957 goto up_fail;
26958 }
26959 }
26960
26961- current->mm->context.vdso = (void *)addr;
26962+ current->mm->context.vdso = addr;
26963
26964 if (compat_uses_vma || !compat) {
26965 /*
26966@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26967 }
26968
26969 current_thread_info()->sysenter_return =
26970- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26971+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26972
26973 up_fail:
26974 if (ret)
26975- current->mm->context.vdso = NULL;
26976+ current->mm->context.vdso = 0;
26977
26978 up_write(&mm->mmap_sem);
26979
26980@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
26981
26982 const char *arch_vma_name(struct vm_area_struct *vma)
26983 {
26984- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26985+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26986 return "[vdso]";
26987+
26988+#ifdef CONFIG_PAX_SEGMEXEC
26989+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
26990+ return "[vdso]";
26991+#endif
26992+
26993 return NULL;
26994 }
26995
26996@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
26997 * Check to see if the corresponding task was created in compat vdso
26998 * mode.
26999 */
27000- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
27001+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
27002 return &gate_vma;
27003 return NULL;
27004 }
27005diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
27006index 00aaf04..4a26505 100644
27007--- a/arch/x86/vdso/vma.c
27008+++ b/arch/x86/vdso/vma.c
27009@@ -16,8 +16,6 @@
27010 #include <asm/vdso.h>
27011 #include <asm/page.h>
27012
27013-unsigned int __read_mostly vdso_enabled = 1;
27014-
27015 extern char vdso_start[], vdso_end[];
27016 extern unsigned short vdso_sync_cpuid;
27017
27018@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27019 * unaligned here as a result of stack start randomization.
27020 */
27021 addr = PAGE_ALIGN(addr);
27022- addr = align_addr(addr, NULL, ALIGN_VDSO);
27023
27024 return addr;
27025 }
27026@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
27027 unsigned size)
27028 {
27029 struct mm_struct *mm = current->mm;
27030- unsigned long addr;
27031+ unsigned long addr = 0;
27032 int ret;
27033
27034- if (!vdso_enabled)
27035- return 0;
27036-
27037 down_write(&mm->mmap_sem);
27038+
27039+#ifdef CONFIG_PAX_RANDMMAP
27040+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27041+#endif
27042+
27043 addr = vdso_addr(mm->start_stack, size);
27044+ addr = align_addr(addr, NULL, ALIGN_VDSO);
27045 addr = get_unmapped_area(NULL, addr, size, 0, 0);
27046 if (IS_ERR_VALUE(addr)) {
27047 ret = addr;
27048 goto up_fail;
27049 }
27050
27051- current->mm->context.vdso = (void *)addr;
27052+ mm->context.vdso = addr;
27053
27054 ret = install_special_mapping(mm, addr, size,
27055 VM_READ|VM_EXEC|
27056 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
27057 pages);
27058- if (ret) {
27059- current->mm->context.vdso = NULL;
27060- goto up_fail;
27061- }
27062+ if (ret)
27063+ mm->context.vdso = 0;
27064
27065 up_fail:
27066 up_write(&mm->mmap_sem);
27067@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27068 vdsox32_size);
27069 }
27070 #endif
27071-
27072-static __init int vdso_setup(char *s)
27073-{
27074- vdso_enabled = simple_strtoul(s, NULL, 0);
27075- return 0;
27076-}
27077-__setup("vdso=", vdso_setup);
27078diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27079index ff962d4..2bb5e83 100644
27080--- a/arch/x86/xen/enlighten.c
27081+++ b/arch/x86/xen/enlighten.c
27082@@ -97,8 +97,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27083
27084 struct shared_info xen_dummy_shared_info;
27085
27086-void *xen_initial_gdt;
27087-
27088 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27089 __read_mostly int xen_have_vector_callback;
27090 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27091@@ -1175,30 +1173,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27092 #endif
27093 };
27094
27095-static void xen_reboot(int reason)
27096+static __noreturn void xen_reboot(int reason)
27097 {
27098 struct sched_shutdown r = { .reason = reason };
27099
27100- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27101- BUG();
27102+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27103+ BUG();
27104 }
27105
27106-static void xen_restart(char *msg)
27107+static __noreturn void xen_restart(char *msg)
27108 {
27109 xen_reboot(SHUTDOWN_reboot);
27110 }
27111
27112-static void xen_emergency_restart(void)
27113+static __noreturn void xen_emergency_restart(void)
27114 {
27115 xen_reboot(SHUTDOWN_reboot);
27116 }
27117
27118-static void xen_machine_halt(void)
27119+static __noreturn void xen_machine_halt(void)
27120 {
27121 xen_reboot(SHUTDOWN_poweroff);
27122 }
27123
27124-static void xen_machine_power_off(void)
27125+static __noreturn void xen_machine_power_off(void)
27126 {
27127 if (pm_power_off)
27128 pm_power_off();
27129@@ -1301,7 +1299,17 @@ asmlinkage void __init xen_start_kernel(void)
27130 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27131
27132 /* Work out if we support NX */
27133- x86_configure_nx();
27134+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27135+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27136+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27137+ unsigned l, h;
27138+
27139+ __supported_pte_mask |= _PAGE_NX;
27140+ rdmsr(MSR_EFER, l, h);
27141+ l |= EFER_NX;
27142+ wrmsr(MSR_EFER, l, h);
27143+ }
27144+#endif
27145
27146 xen_setup_features();
27147
27148@@ -1332,13 +1340,6 @@ asmlinkage void __init xen_start_kernel(void)
27149
27150 machine_ops = xen_machine_ops;
27151
27152- /*
27153- * The only reliable way to retain the initial address of the
27154- * percpu gdt_page is to remember it here, so we can go and
27155- * mark it RW later, when the initial percpu area is freed.
27156- */
27157- xen_initial_gdt = &per_cpu(gdt_page, 0);
27158-
27159 xen_smp_init();
27160
27161 #ifdef CONFIG_ACPI_NUMA
27162diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27163index 3a73785..0d30df2 100644
27164--- a/arch/x86/xen/mmu.c
27165+++ b/arch/x86/xen/mmu.c
27166@@ -1738,6 +1738,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27167 convert_pfn_mfn(init_level4_pgt);
27168 convert_pfn_mfn(level3_ident_pgt);
27169 convert_pfn_mfn(level3_kernel_pgt);
27170+ convert_pfn_mfn(level3_vmalloc_start_pgt);
27171+ convert_pfn_mfn(level3_vmalloc_end_pgt);
27172+ convert_pfn_mfn(level3_vmemmap_pgt);
27173
27174 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27175 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27176@@ -1756,7 +1759,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27177 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27178 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27179 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27180+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27181+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27182+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27183 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27184+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27185 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27186 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27187
27188@@ -1940,6 +1947,7 @@ static void __init xen_post_allocator_init(void)
27189 pv_mmu_ops.set_pud = xen_set_pud;
27190 #if PAGETABLE_LEVELS == 4
27191 pv_mmu_ops.set_pgd = xen_set_pgd;
27192+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27193 #endif
27194
27195 /* This will work as long as patching hasn't happened yet
27196@@ -2021,6 +2029,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27197 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27198 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27199 .set_pgd = xen_set_pgd_hyper,
27200+ .set_pgd_batched = xen_set_pgd_hyper,
27201
27202 .alloc_pud = xen_alloc_pmd_init,
27203 .release_pud = xen_release_pmd_init,
27204diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27205index afb250d..627075f 100644
27206--- a/arch/x86/xen/smp.c
27207+++ b/arch/x86/xen/smp.c
27208@@ -231,11 +231,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27209 {
27210 BUG_ON(smp_processor_id() != 0);
27211 native_smp_prepare_boot_cpu();
27212-
27213- /* We've switched to the "real" per-cpu gdt, so make sure the
27214- old memory can be recycled */
27215- make_lowmem_page_readwrite(xen_initial_gdt);
27216-
27217 xen_filter_cpu_maps();
27218 xen_setup_vcpu_info_placement();
27219 }
27220@@ -302,12 +297,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27221 gdt = get_cpu_gdt_table(cpu);
27222
27223 ctxt->flags = VGCF_IN_KERNEL;
27224- ctxt->user_regs.ds = __USER_DS;
27225- ctxt->user_regs.es = __USER_DS;
27226+ ctxt->user_regs.ds = __KERNEL_DS;
27227+ ctxt->user_regs.es = __KERNEL_DS;
27228 ctxt->user_regs.ss = __KERNEL_DS;
27229 #ifdef CONFIG_X86_32
27230 ctxt->user_regs.fs = __KERNEL_PERCPU;
27231- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27232+ savesegment(gs, ctxt->user_regs.gs);
27233 #else
27234 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27235 #endif
27236@@ -357,13 +352,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
27237 int rc;
27238
27239 per_cpu(current_task, cpu) = idle;
27240+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
27241 #ifdef CONFIG_X86_32
27242 irq_ctx_init(cpu);
27243 #else
27244 clear_tsk_thread_flag(idle, TIF_FORK);
27245- per_cpu(kernel_stack, cpu) =
27246- (unsigned long)task_stack_page(idle) -
27247- KERNEL_STACK_OFFSET + THREAD_SIZE;
27248+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27249 #endif
27250 xen_setup_runstate_info(cpu);
27251 xen_setup_timer(cpu);
27252diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27253index f9643fc..602e8af 100644
27254--- a/arch/x86/xen/xen-asm_32.S
27255+++ b/arch/x86/xen/xen-asm_32.S
27256@@ -84,14 +84,14 @@ ENTRY(xen_iret)
27257 ESP_OFFSET=4 # bytes pushed onto stack
27258
27259 /*
27260- * Store vcpu_info pointer for easy access. Do it this way to
27261- * avoid having to reload %fs
27262+ * Store vcpu_info pointer for easy access.
27263 */
27264 #ifdef CONFIG_SMP
27265- GET_THREAD_INFO(%eax)
27266- movl TI_cpu(%eax), %eax
27267- movl __per_cpu_offset(,%eax,4), %eax
27268- mov xen_vcpu(%eax), %eax
27269+ push %fs
27270+ mov $(__KERNEL_PERCPU), %eax
27271+ mov %eax, %fs
27272+ mov PER_CPU_VAR(xen_vcpu), %eax
27273+ pop %fs
27274 #else
27275 movl xen_vcpu, %eax
27276 #endif
27277diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27278index aaa7291..3f77960 100644
27279--- a/arch/x86/xen/xen-head.S
27280+++ b/arch/x86/xen/xen-head.S
27281@@ -19,6 +19,17 @@ ENTRY(startup_xen)
27282 #ifdef CONFIG_X86_32
27283 mov %esi,xen_start_info
27284 mov $init_thread_union+THREAD_SIZE,%esp
27285+#ifdef CONFIG_SMP
27286+ movl $cpu_gdt_table,%edi
27287+ movl $__per_cpu_load,%eax
27288+ movw %ax,__KERNEL_PERCPU + 2(%edi)
27289+ rorl $16,%eax
27290+ movb %al,__KERNEL_PERCPU + 4(%edi)
27291+ movb %ah,__KERNEL_PERCPU + 7(%edi)
27292+ movl $__per_cpu_end - 1,%eax
27293+ subl $__per_cpu_start,%eax
27294+ movw %ax,__KERNEL_PERCPU + 0(%edi)
27295+#endif
27296 #else
27297 mov %rsi,xen_start_info
27298 mov $init_thread_union+THREAD_SIZE,%rsp
27299diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27300index 202d4c1..99b072a 100644
27301--- a/arch/x86/xen/xen-ops.h
27302+++ b/arch/x86/xen/xen-ops.h
27303@@ -10,8 +10,6 @@
27304 extern const char xen_hypervisor_callback[];
27305 extern const char xen_failsafe_callback[];
27306
27307-extern void *xen_initial_gdt;
27308-
27309 struct trap_info;
27310 void xen_copy_trap_info(struct trap_info *traps);
27311
27312diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27313index 525bd3d..ef888b1 100644
27314--- a/arch/xtensa/variants/dc232b/include/variant/core.h
27315+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27316@@ -119,9 +119,9 @@
27317 ----------------------------------------------------------------------*/
27318
27319 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27320-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27321 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27322 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27323+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27324
27325 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27326 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27327diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27328index 2f33760..835e50a 100644
27329--- a/arch/xtensa/variants/fsf/include/variant/core.h
27330+++ b/arch/xtensa/variants/fsf/include/variant/core.h
27331@@ -11,6 +11,7 @@
27332 #ifndef _XTENSA_CORE_H
27333 #define _XTENSA_CORE_H
27334
27335+#include <linux/const.h>
27336
27337 /****************************************************************************
27338 Parameters Useful for Any Code, USER or PRIVILEGED
27339@@ -112,9 +113,9 @@
27340 ----------------------------------------------------------------------*/
27341
27342 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27343-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27344 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27345 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27346+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27347
27348 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27349 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27350diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27351index af00795..2bb8105 100644
27352--- a/arch/xtensa/variants/s6000/include/variant/core.h
27353+++ b/arch/xtensa/variants/s6000/include/variant/core.h
27354@@ -11,6 +11,7 @@
27355 #ifndef _XTENSA_CORE_CONFIGURATION_H
27356 #define _XTENSA_CORE_CONFIGURATION_H
27357
27358+#include <linux/const.h>
27359
27360 /****************************************************************************
27361 Parameters Useful for Any Code, USER or PRIVILEGED
27362@@ -118,9 +119,9 @@
27363 ----------------------------------------------------------------------*/
27364
27365 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27366-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27367 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27368 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27369+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27370
27371 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27372 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27373diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27374index 58916af..9cb880b 100644
27375--- a/block/blk-iopoll.c
27376+++ b/block/blk-iopoll.c
27377@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27378 }
27379 EXPORT_SYMBOL(blk_iopoll_complete);
27380
27381-static void blk_iopoll_softirq(struct softirq_action *h)
27382+static void blk_iopoll_softirq(void)
27383 {
27384 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27385 int rearm = 0, budget = blk_iopoll_budget;
27386diff --git a/block/blk-map.c b/block/blk-map.c
27387index 623e1cd..ca1e109 100644
27388--- a/block/blk-map.c
27389+++ b/block/blk-map.c
27390@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27391 if (!len || !kbuf)
27392 return -EINVAL;
27393
27394- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27395+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27396 if (do_copy)
27397 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27398 else
27399diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27400index 467c8de..4bddc6d 100644
27401--- a/block/blk-softirq.c
27402+++ b/block/blk-softirq.c
27403@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27404 * Softirq action handler - move entries to local list and loop over them
27405 * while passing them to the queue registered handler.
27406 */
27407-static void blk_done_softirq(struct softirq_action *h)
27408+static void blk_done_softirq(void)
27409 {
27410 struct list_head *cpu_list, local_list;
27411
27412diff --git a/block/bsg.c b/block/bsg.c
27413index ff64ae3..593560c 100644
27414--- a/block/bsg.c
27415+++ b/block/bsg.c
27416@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27417 struct sg_io_v4 *hdr, struct bsg_device *bd,
27418 fmode_t has_write_perm)
27419 {
27420+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27421+ unsigned char *cmdptr;
27422+
27423 if (hdr->request_len > BLK_MAX_CDB) {
27424 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27425 if (!rq->cmd)
27426 return -ENOMEM;
27427- }
27428+ cmdptr = rq->cmd;
27429+ } else
27430+ cmdptr = tmpcmd;
27431
27432- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27433+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27434 hdr->request_len))
27435 return -EFAULT;
27436
27437+ if (cmdptr != rq->cmd)
27438+ memcpy(rq->cmd, cmdptr, hdr->request_len);
27439+
27440 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27441 if (blk_verify_command(rq->cmd, has_write_perm))
27442 return -EPERM;
27443diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27444index 7c668c8..db3521c 100644
27445--- a/block/compat_ioctl.c
27446+++ b/block/compat_ioctl.c
27447@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27448 err |= __get_user(f->spec1, &uf->spec1);
27449 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27450 err |= __get_user(name, &uf->name);
27451- f->name = compat_ptr(name);
27452+ f->name = (void __force_kernel *)compat_ptr(name);
27453 if (err) {
27454 err = -EFAULT;
27455 goto out;
27456diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27457index 6296b40..417c00f 100644
27458--- a/block/partitions/efi.c
27459+++ b/block/partitions/efi.c
27460@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27461 if (!gpt)
27462 return NULL;
27463
27464+ if (!le32_to_cpu(gpt->num_partition_entries))
27465+ return NULL;
27466+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27467+ if (!pte)
27468+ return NULL;
27469+
27470 count = le32_to_cpu(gpt->num_partition_entries) *
27471 le32_to_cpu(gpt->sizeof_partition_entry);
27472- if (!count)
27473- return NULL;
27474- pte = kzalloc(count, GFP_KERNEL);
27475- if (!pte)
27476- return NULL;
27477-
27478 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27479 (u8 *) pte,
27480 count) < count) {
27481diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27482index 9a87daa..fb17486 100644
27483--- a/block/scsi_ioctl.c
27484+++ b/block/scsi_ioctl.c
27485@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27486 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27487 struct sg_io_hdr *hdr, fmode_t mode)
27488 {
27489- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27490+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27491+ unsigned char *cmdptr;
27492+
27493+ if (rq->cmd != rq->__cmd)
27494+ cmdptr = rq->cmd;
27495+ else
27496+ cmdptr = tmpcmd;
27497+
27498+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27499 return -EFAULT;
27500+
27501+ if (cmdptr != rq->cmd)
27502+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27503+
27504 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27505 return -EPERM;
27506
27507@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27508 int err;
27509 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27510 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27511+ unsigned char tmpcmd[sizeof(rq->__cmd)];
27512+ unsigned char *cmdptr;
27513
27514 if (!sic)
27515 return -EINVAL;
27516@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27517 */
27518 err = -EFAULT;
27519 rq->cmd_len = cmdlen;
27520- if (copy_from_user(rq->cmd, sic->data, cmdlen))
27521+
27522+ if (rq->cmd != rq->__cmd)
27523+ cmdptr = rq->cmd;
27524+ else
27525+ cmdptr = tmpcmd;
27526+
27527+ if (copy_from_user(cmdptr, sic->data, cmdlen))
27528 goto error;
27529
27530+ if (rq->cmd != cmdptr)
27531+ memcpy(rq->cmd, cmdptr, cmdlen);
27532+
27533 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27534 goto error;
27535
27536diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27537index 671d4d6..5f24030 100644
27538--- a/crypto/cryptd.c
27539+++ b/crypto/cryptd.c
27540@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27541
27542 struct cryptd_blkcipher_request_ctx {
27543 crypto_completion_t complete;
27544-};
27545+} __no_const;
27546
27547 struct cryptd_hash_ctx {
27548 struct crypto_shash *child;
27549@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27550
27551 struct cryptd_aead_request_ctx {
27552 crypto_completion_t complete;
27553-};
27554+} __no_const;
27555
27556 static void cryptd_queue_worker(struct work_struct *work);
27557
27558diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27559index e6defd8..c26a225 100644
27560--- a/drivers/acpi/apei/cper.c
27561+++ b/drivers/acpi/apei/cper.c
27562@@ -38,12 +38,12 @@
27563 */
27564 u64 cper_next_record_id(void)
27565 {
27566- static atomic64_t seq;
27567+ static atomic64_unchecked_t seq;
27568
27569- if (!atomic64_read(&seq))
27570- atomic64_set(&seq, ((u64)get_seconds()) << 32);
27571+ if (!atomic64_read_unchecked(&seq))
27572+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27573
27574- return atomic64_inc_return(&seq);
27575+ return atomic64_inc_return_unchecked(&seq);
27576 }
27577 EXPORT_SYMBOL_GPL(cper_next_record_id);
27578
27579diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27580index 7586544..636a2f0 100644
27581--- a/drivers/acpi/ec_sys.c
27582+++ b/drivers/acpi/ec_sys.c
27583@@ -12,6 +12,7 @@
27584 #include <linux/acpi.h>
27585 #include <linux/debugfs.h>
27586 #include <linux/module.h>
27587+#include <linux/uaccess.h>
27588 #include "internal.h"
27589
27590 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27591@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27592 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27593 */
27594 unsigned int size = EC_SPACE_SIZE;
27595- u8 *data = (u8 *) buf;
27596+ u8 data;
27597 loff_t init_off = *off;
27598 int err = 0;
27599
27600@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27601 size = count;
27602
27603 while (size) {
27604- err = ec_read(*off, &data[*off - init_off]);
27605+ err = ec_read(*off, &data);
27606 if (err)
27607 return err;
27608+ if (put_user(data, &buf[*off - init_off]))
27609+ return -EFAULT;
27610 *off += 1;
27611 size--;
27612 }
27613@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27614
27615 unsigned int size = count;
27616 loff_t init_off = *off;
27617- u8 *data = (u8 *) buf;
27618 int err = 0;
27619
27620 if (*off >= EC_SPACE_SIZE)
27621@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27622 }
27623
27624 while (size) {
27625- u8 byte_write = data[*off - init_off];
27626+ u8 byte_write;
27627+ if (get_user(byte_write, &buf[*off - init_off]))
27628+ return -EFAULT;
27629 err = ec_write(*off, byte_write);
27630 if (err)
27631 return err;
27632diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27633index 251c7b62..000462d 100644
27634--- a/drivers/acpi/proc.c
27635+++ b/drivers/acpi/proc.c
27636@@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27637 size_t count, loff_t * ppos)
27638 {
27639 struct list_head *node, *next;
27640- char strbuf[5];
27641- char str[5] = "";
27642- unsigned int len = count;
27643+ char strbuf[5] = {0};
27644
27645- if (len > 4)
27646- len = 4;
27647- if (len < 0)
27648+ if (count > 4)
27649+ count = 4;
27650+ if (copy_from_user(strbuf, buffer, count))
27651 return -EFAULT;
27652-
27653- if (copy_from_user(strbuf, buffer, len))
27654- return -EFAULT;
27655- strbuf[len] = '\0';
27656- sscanf(strbuf, "%s", str);
27657+ strbuf[count] = '\0';
27658
27659 mutex_lock(&acpi_device_lock);
27660 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27661@@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27662 if (!dev->wakeup.flags.valid)
27663 continue;
27664
27665- if (!strncmp(dev->pnp.bus_id, str, 4)) {
27666+ if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27667 if (device_can_wakeup(&dev->dev)) {
27668 bool enable = !device_may_wakeup(&dev->dev);
27669 device_set_wakeup_enable(&dev->dev, enable);
27670diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27671index bbac51e..4c094f9 100644
27672--- a/drivers/acpi/processor_driver.c
27673+++ b/drivers/acpi/processor_driver.c
27674@@ -556,7 +556,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27675 return 0;
27676 #endif
27677
27678- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27679+ BUG_ON(pr->id >= nr_cpu_ids);
27680
27681 /*
27682 * Buggy BIOS check
27683diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27684index cece3a4..0845256 100644
27685--- a/drivers/ata/libata-core.c
27686+++ b/drivers/ata/libata-core.c
27687@@ -4743,7 +4743,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27688 struct ata_port *ap;
27689 unsigned int tag;
27690
27691- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27692+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27693 ap = qc->ap;
27694
27695 qc->flags = 0;
27696@@ -4759,7 +4759,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27697 struct ata_port *ap;
27698 struct ata_link *link;
27699
27700- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27701+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27702 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27703 ap = qc->ap;
27704 link = qc->dev->link;
27705@@ -5823,6 +5823,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27706 return;
27707
27708 spin_lock(&lock);
27709+ pax_open_kernel();
27710
27711 for (cur = ops->inherits; cur; cur = cur->inherits) {
27712 void **inherit = (void **)cur;
27713@@ -5836,8 +5837,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27714 if (IS_ERR(*pp))
27715 *pp = NULL;
27716
27717- ops->inherits = NULL;
27718+ *(struct ata_port_operations **)&ops->inherits = NULL;
27719
27720+ pax_close_kernel();
27721 spin_unlock(&lock);
27722 }
27723
27724diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27725index ac6a5be..c7176b1 100644
27726--- a/drivers/ata/pata_arasan_cf.c
27727+++ b/drivers/ata/pata_arasan_cf.c
27728@@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27729 /* Handle platform specific quirks */
27730 if (pdata->quirk) {
27731 if (pdata->quirk & CF_BROKEN_PIO) {
27732- ap->ops->set_piomode = NULL;
27733+ pax_open_kernel();
27734+ *(void **)&ap->ops->set_piomode = NULL;
27735+ pax_close_kernel();
27736 ap->pio_mask = 0;
27737 }
27738 if (pdata->quirk & CF_BROKEN_MWDMA)
27739diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27740index f9b983a..887b9d8 100644
27741--- a/drivers/atm/adummy.c
27742+++ b/drivers/atm/adummy.c
27743@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27744 vcc->pop(vcc, skb);
27745 else
27746 dev_kfree_skb_any(skb);
27747- atomic_inc(&vcc->stats->tx);
27748+ atomic_inc_unchecked(&vcc->stats->tx);
27749
27750 return 0;
27751 }
27752diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27753index 89b30f3..7964211 100644
27754--- a/drivers/atm/ambassador.c
27755+++ b/drivers/atm/ambassador.c
27756@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27757 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27758
27759 // VC layer stats
27760- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27761+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27762
27763 // free the descriptor
27764 kfree (tx_descr);
27765@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27766 dump_skb ("<<<", vc, skb);
27767
27768 // VC layer stats
27769- atomic_inc(&atm_vcc->stats->rx);
27770+ atomic_inc_unchecked(&atm_vcc->stats->rx);
27771 __net_timestamp(skb);
27772 // end of our responsibility
27773 atm_vcc->push (atm_vcc, skb);
27774@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27775 } else {
27776 PRINTK (KERN_INFO, "dropped over-size frame");
27777 // should we count this?
27778- atomic_inc(&atm_vcc->stats->rx_drop);
27779+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27780 }
27781
27782 } else {
27783@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
27784 }
27785
27786 if (check_area (skb->data, skb->len)) {
27787- atomic_inc(&atm_vcc->stats->tx_err);
27788+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
27789 return -ENOMEM; // ?
27790 }
27791
27792diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
27793index b22d71c..d6e1049 100644
27794--- a/drivers/atm/atmtcp.c
27795+++ b/drivers/atm/atmtcp.c
27796@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27797 if (vcc->pop) vcc->pop(vcc,skb);
27798 else dev_kfree_skb(skb);
27799 if (dev_data) return 0;
27800- atomic_inc(&vcc->stats->tx_err);
27801+ atomic_inc_unchecked(&vcc->stats->tx_err);
27802 return -ENOLINK;
27803 }
27804 size = skb->len+sizeof(struct atmtcp_hdr);
27805@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27806 if (!new_skb) {
27807 if (vcc->pop) vcc->pop(vcc,skb);
27808 else dev_kfree_skb(skb);
27809- atomic_inc(&vcc->stats->tx_err);
27810+ atomic_inc_unchecked(&vcc->stats->tx_err);
27811 return -ENOBUFS;
27812 }
27813 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
27814@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27815 if (vcc->pop) vcc->pop(vcc,skb);
27816 else dev_kfree_skb(skb);
27817 out_vcc->push(out_vcc,new_skb);
27818- atomic_inc(&vcc->stats->tx);
27819- atomic_inc(&out_vcc->stats->rx);
27820+ atomic_inc_unchecked(&vcc->stats->tx);
27821+ atomic_inc_unchecked(&out_vcc->stats->rx);
27822 return 0;
27823 }
27824
27825@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27826 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
27827 read_unlock(&vcc_sklist_lock);
27828 if (!out_vcc) {
27829- atomic_inc(&vcc->stats->tx_err);
27830+ atomic_inc_unchecked(&vcc->stats->tx_err);
27831 goto done;
27832 }
27833 skb_pull(skb,sizeof(struct atmtcp_hdr));
27834@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27835 __net_timestamp(new_skb);
27836 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
27837 out_vcc->push(out_vcc,new_skb);
27838- atomic_inc(&vcc->stats->tx);
27839- atomic_inc(&out_vcc->stats->rx);
27840+ atomic_inc_unchecked(&vcc->stats->tx);
27841+ atomic_inc_unchecked(&out_vcc->stats->rx);
27842 done:
27843 if (vcc->pop) vcc->pop(vcc,skb);
27844 else dev_kfree_skb(skb);
27845diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
27846index 2059ee4..faf51c7 100644
27847--- a/drivers/atm/eni.c
27848+++ b/drivers/atm/eni.c
27849@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
27850 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
27851 vcc->dev->number);
27852 length = 0;
27853- atomic_inc(&vcc->stats->rx_err);
27854+ atomic_inc_unchecked(&vcc->stats->rx_err);
27855 }
27856 else {
27857 length = ATM_CELL_SIZE-1; /* no HEC */
27858@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27859 size);
27860 }
27861 eff = length = 0;
27862- atomic_inc(&vcc->stats->rx_err);
27863+ atomic_inc_unchecked(&vcc->stats->rx_err);
27864 }
27865 else {
27866 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
27867@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27868 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
27869 vcc->dev->number,vcc->vci,length,size << 2,descr);
27870 length = eff = 0;
27871- atomic_inc(&vcc->stats->rx_err);
27872+ atomic_inc_unchecked(&vcc->stats->rx_err);
27873 }
27874 }
27875 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
27876@@ -767,7 +767,7 @@ rx_dequeued++;
27877 vcc->push(vcc,skb);
27878 pushed++;
27879 }
27880- atomic_inc(&vcc->stats->rx);
27881+ atomic_inc_unchecked(&vcc->stats->rx);
27882 }
27883 wake_up(&eni_dev->rx_wait);
27884 }
27885@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
27886 PCI_DMA_TODEVICE);
27887 if (vcc->pop) vcc->pop(vcc,skb);
27888 else dev_kfree_skb_irq(skb);
27889- atomic_inc(&vcc->stats->tx);
27890+ atomic_inc_unchecked(&vcc->stats->tx);
27891 wake_up(&eni_dev->tx_wait);
27892 dma_complete++;
27893 }
27894@@ -1567,7 +1567,7 @@ tx_complete++;
27895 /*--------------------------------- entries ---------------------------------*/
27896
27897
27898-static const char *media_name[] __devinitdata = {
27899+static const char *media_name[] __devinitconst = {
27900 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
27901 "UTP", "05?", "06?", "07?", /* 4- 7 */
27902 "TAXI","09?", "10?", "11?", /* 8-11 */
27903diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
27904index 86fed1b..6dc4721 100644
27905--- a/drivers/atm/firestream.c
27906+++ b/drivers/atm/firestream.c
27907@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
27908 }
27909 }
27910
27911- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27912+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27913
27914 fs_dprintk (FS_DEBUG_TXMEM, "i");
27915 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
27916@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27917 #endif
27918 skb_put (skb, qe->p1 & 0xffff);
27919 ATM_SKB(skb)->vcc = atm_vcc;
27920- atomic_inc(&atm_vcc->stats->rx);
27921+ atomic_inc_unchecked(&atm_vcc->stats->rx);
27922 __net_timestamp(skb);
27923 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
27924 atm_vcc->push (atm_vcc, skb);
27925@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27926 kfree (pe);
27927 }
27928 if (atm_vcc)
27929- atomic_inc(&atm_vcc->stats->rx_drop);
27930+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27931 break;
27932 case 0x1f: /* Reassembly abort: no buffers. */
27933 /* Silently increment error counter. */
27934 if (atm_vcc)
27935- atomic_inc(&atm_vcc->stats->rx_drop);
27936+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27937 break;
27938 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
27939 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
27940diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
27941index 361f5ae..7fc552d 100644
27942--- a/drivers/atm/fore200e.c
27943+++ b/drivers/atm/fore200e.c
27944@@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
27945 #endif
27946 /* check error condition */
27947 if (*entry->status & STATUS_ERROR)
27948- atomic_inc(&vcc->stats->tx_err);
27949+ atomic_inc_unchecked(&vcc->stats->tx_err);
27950 else
27951- atomic_inc(&vcc->stats->tx);
27952+ atomic_inc_unchecked(&vcc->stats->tx);
27953 }
27954 }
27955
27956@@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27957 if (skb == NULL) {
27958 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
27959
27960- atomic_inc(&vcc->stats->rx_drop);
27961+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27962 return -ENOMEM;
27963 }
27964
27965@@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27966
27967 dev_kfree_skb_any(skb);
27968
27969- atomic_inc(&vcc->stats->rx_drop);
27970+ atomic_inc_unchecked(&vcc->stats->rx_drop);
27971 return -ENOMEM;
27972 }
27973
27974 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27975
27976 vcc->push(vcc, skb);
27977- atomic_inc(&vcc->stats->rx);
27978+ atomic_inc_unchecked(&vcc->stats->rx);
27979
27980 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27981
27982@@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
27983 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
27984 fore200e->atm_dev->number,
27985 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
27986- atomic_inc(&vcc->stats->rx_err);
27987+ atomic_inc_unchecked(&vcc->stats->rx_err);
27988 }
27989 }
27990
27991@@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
27992 goto retry_here;
27993 }
27994
27995- atomic_inc(&vcc->stats->tx_err);
27996+ atomic_inc_unchecked(&vcc->stats->tx_err);
27997
27998 fore200e->tx_sat++;
27999 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
28000diff --git a/drivers/atm/he.c b/drivers/atm/he.c
28001index b182c2f..1c6fa8a 100644
28002--- a/drivers/atm/he.c
28003+++ b/drivers/atm/he.c
28004@@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28005
28006 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
28007 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
28008- atomic_inc(&vcc->stats->rx_drop);
28009+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28010 goto return_host_buffers;
28011 }
28012
28013@@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28014 RBRQ_LEN_ERR(he_dev->rbrq_head)
28015 ? "LEN_ERR" : "",
28016 vcc->vpi, vcc->vci);
28017- atomic_inc(&vcc->stats->rx_err);
28018+ atomic_inc_unchecked(&vcc->stats->rx_err);
28019 goto return_host_buffers;
28020 }
28021
28022@@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28023 vcc->push(vcc, skb);
28024 spin_lock(&he_dev->global_lock);
28025
28026- atomic_inc(&vcc->stats->rx);
28027+ atomic_inc_unchecked(&vcc->stats->rx);
28028
28029 return_host_buffers:
28030 ++pdus_assembled;
28031@@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
28032 tpd->vcc->pop(tpd->vcc, tpd->skb);
28033 else
28034 dev_kfree_skb_any(tpd->skb);
28035- atomic_inc(&tpd->vcc->stats->tx_err);
28036+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
28037 }
28038 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
28039 return;
28040@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28041 vcc->pop(vcc, skb);
28042 else
28043 dev_kfree_skb_any(skb);
28044- atomic_inc(&vcc->stats->tx_err);
28045+ atomic_inc_unchecked(&vcc->stats->tx_err);
28046 return -EINVAL;
28047 }
28048
28049@@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28050 vcc->pop(vcc, skb);
28051 else
28052 dev_kfree_skb_any(skb);
28053- atomic_inc(&vcc->stats->tx_err);
28054+ atomic_inc_unchecked(&vcc->stats->tx_err);
28055 return -EINVAL;
28056 }
28057 #endif
28058@@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28059 vcc->pop(vcc, skb);
28060 else
28061 dev_kfree_skb_any(skb);
28062- atomic_inc(&vcc->stats->tx_err);
28063+ atomic_inc_unchecked(&vcc->stats->tx_err);
28064 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28065 return -ENOMEM;
28066 }
28067@@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28068 vcc->pop(vcc, skb);
28069 else
28070 dev_kfree_skb_any(skb);
28071- atomic_inc(&vcc->stats->tx_err);
28072+ atomic_inc_unchecked(&vcc->stats->tx_err);
28073 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28074 return -ENOMEM;
28075 }
28076@@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28077 __enqueue_tpd(he_dev, tpd, cid);
28078 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28079
28080- atomic_inc(&vcc->stats->tx);
28081+ atomic_inc_unchecked(&vcc->stats->tx);
28082
28083 return 0;
28084 }
28085diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28086index 7d01c2a..4e3ac01 100644
28087--- a/drivers/atm/horizon.c
28088+++ b/drivers/atm/horizon.c
28089@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28090 {
28091 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28092 // VC layer stats
28093- atomic_inc(&vcc->stats->rx);
28094+ atomic_inc_unchecked(&vcc->stats->rx);
28095 __net_timestamp(skb);
28096 // end of our responsibility
28097 vcc->push (vcc, skb);
28098@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28099 dev->tx_iovec = NULL;
28100
28101 // VC layer stats
28102- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28103+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28104
28105 // free the skb
28106 hrz_kfree_skb (skb);
28107diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28108index 8974bd2..b856f85 100644
28109--- a/drivers/atm/idt77252.c
28110+++ b/drivers/atm/idt77252.c
28111@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28112 else
28113 dev_kfree_skb(skb);
28114
28115- atomic_inc(&vcc->stats->tx);
28116+ atomic_inc_unchecked(&vcc->stats->tx);
28117 }
28118
28119 atomic_dec(&scq->used);
28120@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28121 if ((sb = dev_alloc_skb(64)) == NULL) {
28122 printk("%s: Can't allocate buffers for aal0.\n",
28123 card->name);
28124- atomic_add(i, &vcc->stats->rx_drop);
28125+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
28126 break;
28127 }
28128 if (!atm_charge(vcc, sb->truesize)) {
28129 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28130 card->name);
28131- atomic_add(i - 1, &vcc->stats->rx_drop);
28132+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28133 dev_kfree_skb(sb);
28134 break;
28135 }
28136@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28137 ATM_SKB(sb)->vcc = vcc;
28138 __net_timestamp(sb);
28139 vcc->push(vcc, sb);
28140- atomic_inc(&vcc->stats->rx);
28141+ atomic_inc_unchecked(&vcc->stats->rx);
28142
28143 cell += ATM_CELL_PAYLOAD;
28144 }
28145@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28146 "(CDC: %08x)\n",
28147 card->name, len, rpp->len, readl(SAR_REG_CDC));
28148 recycle_rx_pool_skb(card, rpp);
28149- atomic_inc(&vcc->stats->rx_err);
28150+ atomic_inc_unchecked(&vcc->stats->rx_err);
28151 return;
28152 }
28153 if (stat & SAR_RSQE_CRC) {
28154 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28155 recycle_rx_pool_skb(card, rpp);
28156- atomic_inc(&vcc->stats->rx_err);
28157+ atomic_inc_unchecked(&vcc->stats->rx_err);
28158 return;
28159 }
28160 if (skb_queue_len(&rpp->queue) > 1) {
28161@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28162 RXPRINTK("%s: Can't alloc RX skb.\n",
28163 card->name);
28164 recycle_rx_pool_skb(card, rpp);
28165- atomic_inc(&vcc->stats->rx_err);
28166+ atomic_inc_unchecked(&vcc->stats->rx_err);
28167 return;
28168 }
28169 if (!atm_charge(vcc, skb->truesize)) {
28170@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28171 __net_timestamp(skb);
28172
28173 vcc->push(vcc, skb);
28174- atomic_inc(&vcc->stats->rx);
28175+ atomic_inc_unchecked(&vcc->stats->rx);
28176
28177 return;
28178 }
28179@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28180 __net_timestamp(skb);
28181
28182 vcc->push(vcc, skb);
28183- atomic_inc(&vcc->stats->rx);
28184+ atomic_inc_unchecked(&vcc->stats->rx);
28185
28186 if (skb->truesize > SAR_FB_SIZE_3)
28187 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28188@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28189 if (vcc->qos.aal != ATM_AAL0) {
28190 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28191 card->name, vpi, vci);
28192- atomic_inc(&vcc->stats->rx_drop);
28193+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28194 goto drop;
28195 }
28196
28197 if ((sb = dev_alloc_skb(64)) == NULL) {
28198 printk("%s: Can't allocate buffers for AAL0.\n",
28199 card->name);
28200- atomic_inc(&vcc->stats->rx_err);
28201+ atomic_inc_unchecked(&vcc->stats->rx_err);
28202 goto drop;
28203 }
28204
28205@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28206 ATM_SKB(sb)->vcc = vcc;
28207 __net_timestamp(sb);
28208 vcc->push(vcc, sb);
28209- atomic_inc(&vcc->stats->rx);
28210+ atomic_inc_unchecked(&vcc->stats->rx);
28211
28212 drop:
28213 skb_pull(queue, 64);
28214@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28215
28216 if (vc == NULL) {
28217 printk("%s: NULL connection in send().\n", card->name);
28218- atomic_inc(&vcc->stats->tx_err);
28219+ atomic_inc_unchecked(&vcc->stats->tx_err);
28220 dev_kfree_skb(skb);
28221 return -EINVAL;
28222 }
28223 if (!test_bit(VCF_TX, &vc->flags)) {
28224 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28225- atomic_inc(&vcc->stats->tx_err);
28226+ atomic_inc_unchecked(&vcc->stats->tx_err);
28227 dev_kfree_skb(skb);
28228 return -EINVAL;
28229 }
28230@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28231 break;
28232 default:
28233 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28234- atomic_inc(&vcc->stats->tx_err);
28235+ atomic_inc_unchecked(&vcc->stats->tx_err);
28236 dev_kfree_skb(skb);
28237 return -EINVAL;
28238 }
28239
28240 if (skb_shinfo(skb)->nr_frags != 0) {
28241 printk("%s: No scatter-gather yet.\n", card->name);
28242- atomic_inc(&vcc->stats->tx_err);
28243+ atomic_inc_unchecked(&vcc->stats->tx_err);
28244 dev_kfree_skb(skb);
28245 return -EINVAL;
28246 }
28247@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28248
28249 err = queue_skb(card, vc, skb, oam);
28250 if (err) {
28251- atomic_inc(&vcc->stats->tx_err);
28252+ atomic_inc_unchecked(&vcc->stats->tx_err);
28253 dev_kfree_skb(skb);
28254 return err;
28255 }
28256@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28257 skb = dev_alloc_skb(64);
28258 if (!skb) {
28259 printk("%s: Out of memory in send_oam().\n", card->name);
28260- atomic_inc(&vcc->stats->tx_err);
28261+ atomic_inc_unchecked(&vcc->stats->tx_err);
28262 return -ENOMEM;
28263 }
28264 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28265diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28266index d438601..8b98495 100644
28267--- a/drivers/atm/iphase.c
28268+++ b/drivers/atm/iphase.c
28269@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28270 status = (u_short) (buf_desc_ptr->desc_mode);
28271 if (status & (RX_CER | RX_PTE | RX_OFL))
28272 {
28273- atomic_inc(&vcc->stats->rx_err);
28274+ atomic_inc_unchecked(&vcc->stats->rx_err);
28275 IF_ERR(printk("IA: bad packet, dropping it");)
28276 if (status & RX_CER) {
28277 IF_ERR(printk(" cause: packet CRC error\n");)
28278@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28279 len = dma_addr - buf_addr;
28280 if (len > iadev->rx_buf_sz) {
28281 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28282- atomic_inc(&vcc->stats->rx_err);
28283+ atomic_inc_unchecked(&vcc->stats->rx_err);
28284 goto out_free_desc;
28285 }
28286
28287@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28288 ia_vcc = INPH_IA_VCC(vcc);
28289 if (ia_vcc == NULL)
28290 {
28291- atomic_inc(&vcc->stats->rx_err);
28292+ atomic_inc_unchecked(&vcc->stats->rx_err);
28293 atm_return(vcc, skb->truesize);
28294 dev_kfree_skb_any(skb);
28295 goto INCR_DLE;
28296@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28297 if ((length > iadev->rx_buf_sz) || (length >
28298 (skb->len - sizeof(struct cpcs_trailer))))
28299 {
28300- atomic_inc(&vcc->stats->rx_err);
28301+ atomic_inc_unchecked(&vcc->stats->rx_err);
28302 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28303 length, skb->len);)
28304 atm_return(vcc, skb->truesize);
28305@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28306
28307 IF_RX(printk("rx_dle_intr: skb push");)
28308 vcc->push(vcc,skb);
28309- atomic_inc(&vcc->stats->rx);
28310+ atomic_inc_unchecked(&vcc->stats->rx);
28311 iadev->rx_pkt_cnt++;
28312 }
28313 INCR_DLE:
28314@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28315 {
28316 struct k_sonet_stats *stats;
28317 stats = &PRIV(_ia_dev[board])->sonet_stats;
28318- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28319- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28320- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28321- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28322- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28323- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28324- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28325- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28326- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28327+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28328+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28329+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28330+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28331+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28332+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28333+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28334+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28335+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28336 }
28337 ia_cmds.status = 0;
28338 break;
28339@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28340 if ((desc == 0) || (desc > iadev->num_tx_desc))
28341 {
28342 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28343- atomic_inc(&vcc->stats->tx);
28344+ atomic_inc_unchecked(&vcc->stats->tx);
28345 if (vcc->pop)
28346 vcc->pop(vcc, skb);
28347 else
28348@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28349 ATM_DESC(skb) = vcc->vci;
28350 skb_queue_tail(&iadev->tx_dma_q, skb);
28351
28352- atomic_inc(&vcc->stats->tx);
28353+ atomic_inc_unchecked(&vcc->stats->tx);
28354 iadev->tx_pkt_cnt++;
28355 /* Increment transaction counter */
28356 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28357
28358 #if 0
28359 /* add flow control logic */
28360- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28361+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28362 if (iavcc->vc_desc_cnt > 10) {
28363 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28364 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28365diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28366index 68c7588..7036683 100644
28367--- a/drivers/atm/lanai.c
28368+++ b/drivers/atm/lanai.c
28369@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28370 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28371 lanai_endtx(lanai, lvcc);
28372 lanai_free_skb(lvcc->tx.atmvcc, skb);
28373- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28374+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28375 }
28376
28377 /* Try to fill the buffer - don't call unless there is backlog */
28378@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28379 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28380 __net_timestamp(skb);
28381 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28382- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28383+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28384 out:
28385 lvcc->rx.buf.ptr = end;
28386 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28387@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28388 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28389 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28390 lanai->stats.service_rxnotaal5++;
28391- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28392+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28393 return 0;
28394 }
28395 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28396@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28397 int bytes;
28398 read_unlock(&vcc_sklist_lock);
28399 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28400- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28401+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28402 lvcc->stats.x.aal5.service_trash++;
28403 bytes = (SERVICE_GET_END(s) * 16) -
28404 (((unsigned long) lvcc->rx.buf.ptr) -
28405@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28406 }
28407 if (s & SERVICE_STREAM) {
28408 read_unlock(&vcc_sklist_lock);
28409- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28410+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28411 lvcc->stats.x.aal5.service_stream++;
28412 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28413 "PDU on VCI %d!\n", lanai->number, vci);
28414@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28415 return 0;
28416 }
28417 DPRINTK("got rx crc error on vci %d\n", vci);
28418- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28419+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28420 lvcc->stats.x.aal5.service_rxcrc++;
28421 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28422 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28423diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28424index 1c70c45..300718d 100644
28425--- a/drivers/atm/nicstar.c
28426+++ b/drivers/atm/nicstar.c
28427@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28428 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28429 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28430 card->index);
28431- atomic_inc(&vcc->stats->tx_err);
28432+ atomic_inc_unchecked(&vcc->stats->tx_err);
28433 dev_kfree_skb_any(skb);
28434 return -EINVAL;
28435 }
28436@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28437 if (!vc->tx) {
28438 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28439 card->index);
28440- atomic_inc(&vcc->stats->tx_err);
28441+ atomic_inc_unchecked(&vcc->stats->tx_err);
28442 dev_kfree_skb_any(skb);
28443 return -EINVAL;
28444 }
28445@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28446 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28447 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28448 card->index);
28449- atomic_inc(&vcc->stats->tx_err);
28450+ atomic_inc_unchecked(&vcc->stats->tx_err);
28451 dev_kfree_skb_any(skb);
28452 return -EINVAL;
28453 }
28454
28455 if (skb_shinfo(skb)->nr_frags != 0) {
28456 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28457- atomic_inc(&vcc->stats->tx_err);
28458+ atomic_inc_unchecked(&vcc->stats->tx_err);
28459 dev_kfree_skb_any(skb);
28460 return -EINVAL;
28461 }
28462@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28463 }
28464
28465 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28466- atomic_inc(&vcc->stats->tx_err);
28467+ atomic_inc_unchecked(&vcc->stats->tx_err);
28468 dev_kfree_skb_any(skb);
28469 return -EIO;
28470 }
28471- atomic_inc(&vcc->stats->tx);
28472+ atomic_inc_unchecked(&vcc->stats->tx);
28473
28474 return 0;
28475 }
28476@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28477 printk
28478 ("nicstar%d: Can't allocate buffers for aal0.\n",
28479 card->index);
28480- atomic_add(i, &vcc->stats->rx_drop);
28481+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
28482 break;
28483 }
28484 if (!atm_charge(vcc, sb->truesize)) {
28485 RXPRINTK
28486 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28487 card->index);
28488- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28489+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28490 dev_kfree_skb_any(sb);
28491 break;
28492 }
28493@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28494 ATM_SKB(sb)->vcc = vcc;
28495 __net_timestamp(sb);
28496 vcc->push(vcc, sb);
28497- atomic_inc(&vcc->stats->rx);
28498+ atomic_inc_unchecked(&vcc->stats->rx);
28499 cell += ATM_CELL_PAYLOAD;
28500 }
28501
28502@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28503 if (iovb == NULL) {
28504 printk("nicstar%d: Out of iovec buffers.\n",
28505 card->index);
28506- atomic_inc(&vcc->stats->rx_drop);
28507+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28508 recycle_rx_buf(card, skb);
28509 return;
28510 }
28511@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28512 small or large buffer itself. */
28513 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28514 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28515- atomic_inc(&vcc->stats->rx_err);
28516+ atomic_inc_unchecked(&vcc->stats->rx_err);
28517 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28518 NS_MAX_IOVECS);
28519 NS_PRV_IOVCNT(iovb) = 0;
28520@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28521 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28522 card->index);
28523 which_list(card, skb);
28524- atomic_inc(&vcc->stats->rx_err);
28525+ atomic_inc_unchecked(&vcc->stats->rx_err);
28526 recycle_rx_buf(card, skb);
28527 vc->rx_iov = NULL;
28528 recycle_iov_buf(card, iovb);
28529@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28530 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28531 card->index);
28532 which_list(card, skb);
28533- atomic_inc(&vcc->stats->rx_err);
28534+ atomic_inc_unchecked(&vcc->stats->rx_err);
28535 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28536 NS_PRV_IOVCNT(iovb));
28537 vc->rx_iov = NULL;
28538@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28539 printk(" - PDU size mismatch.\n");
28540 else
28541 printk(".\n");
28542- atomic_inc(&vcc->stats->rx_err);
28543+ atomic_inc_unchecked(&vcc->stats->rx_err);
28544 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28545 NS_PRV_IOVCNT(iovb));
28546 vc->rx_iov = NULL;
28547@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28548 /* skb points to a small buffer */
28549 if (!atm_charge(vcc, skb->truesize)) {
28550 push_rxbufs(card, skb);
28551- atomic_inc(&vcc->stats->rx_drop);
28552+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28553 } else {
28554 skb_put(skb, len);
28555 dequeue_sm_buf(card, skb);
28556@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28557 ATM_SKB(skb)->vcc = vcc;
28558 __net_timestamp(skb);
28559 vcc->push(vcc, skb);
28560- atomic_inc(&vcc->stats->rx);
28561+ atomic_inc_unchecked(&vcc->stats->rx);
28562 }
28563 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28564 struct sk_buff *sb;
28565@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28566 if (len <= NS_SMBUFSIZE) {
28567 if (!atm_charge(vcc, sb->truesize)) {
28568 push_rxbufs(card, sb);
28569- atomic_inc(&vcc->stats->rx_drop);
28570+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28571 } else {
28572 skb_put(sb, len);
28573 dequeue_sm_buf(card, sb);
28574@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28575 ATM_SKB(sb)->vcc = vcc;
28576 __net_timestamp(sb);
28577 vcc->push(vcc, sb);
28578- atomic_inc(&vcc->stats->rx);
28579+ atomic_inc_unchecked(&vcc->stats->rx);
28580 }
28581
28582 push_rxbufs(card, skb);
28583@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28584
28585 if (!atm_charge(vcc, skb->truesize)) {
28586 push_rxbufs(card, skb);
28587- atomic_inc(&vcc->stats->rx_drop);
28588+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28589 } else {
28590 dequeue_lg_buf(card, skb);
28591 #ifdef NS_USE_DESTRUCTORS
28592@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28593 ATM_SKB(skb)->vcc = vcc;
28594 __net_timestamp(skb);
28595 vcc->push(vcc, skb);
28596- atomic_inc(&vcc->stats->rx);
28597+ atomic_inc_unchecked(&vcc->stats->rx);
28598 }
28599
28600 push_rxbufs(card, sb);
28601@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28602 printk
28603 ("nicstar%d: Out of huge buffers.\n",
28604 card->index);
28605- atomic_inc(&vcc->stats->rx_drop);
28606+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28607 recycle_iovec_rx_bufs(card,
28608 (struct iovec *)
28609 iovb->data,
28610@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28611 card->hbpool.count++;
28612 } else
28613 dev_kfree_skb_any(hb);
28614- atomic_inc(&vcc->stats->rx_drop);
28615+ atomic_inc_unchecked(&vcc->stats->rx_drop);
28616 } else {
28617 /* Copy the small buffer to the huge buffer */
28618 sb = (struct sk_buff *)iov->iov_base;
28619@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28620 #endif /* NS_USE_DESTRUCTORS */
28621 __net_timestamp(hb);
28622 vcc->push(vcc, hb);
28623- atomic_inc(&vcc->stats->rx);
28624+ atomic_inc_unchecked(&vcc->stats->rx);
28625 }
28626 }
28627
28628diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28629index 9851093..adb2b1e 100644
28630--- a/drivers/atm/solos-pci.c
28631+++ b/drivers/atm/solos-pci.c
28632@@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28633 }
28634 atm_charge(vcc, skb->truesize);
28635 vcc->push(vcc, skb);
28636- atomic_inc(&vcc->stats->rx);
28637+ atomic_inc_unchecked(&vcc->stats->rx);
28638 break;
28639
28640 case PKT_STATUS:
28641@@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28642 vcc = SKB_CB(oldskb)->vcc;
28643
28644 if (vcc) {
28645- atomic_inc(&vcc->stats->tx);
28646+ atomic_inc_unchecked(&vcc->stats->tx);
28647 solos_pop(vcc, oldskb);
28648 } else
28649 dev_kfree_skb_irq(oldskb);
28650diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28651index 0215934..ce9f5b1 100644
28652--- a/drivers/atm/suni.c
28653+++ b/drivers/atm/suni.c
28654@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28655
28656
28657 #define ADD_LIMITED(s,v) \
28658- atomic_add((v),&stats->s); \
28659- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28660+ atomic_add_unchecked((v),&stats->s); \
28661+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28662
28663
28664 static void suni_hz(unsigned long from_timer)
28665diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28666index 5120a96..e2572bd 100644
28667--- a/drivers/atm/uPD98402.c
28668+++ b/drivers/atm/uPD98402.c
28669@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28670 struct sonet_stats tmp;
28671 int error = 0;
28672
28673- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28674+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28675 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28676 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28677 if (zero && !error) {
28678@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28679
28680
28681 #define ADD_LIMITED(s,v) \
28682- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28683- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28684- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28685+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28686+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28687+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28688
28689
28690 static void stat_event(struct atm_dev *dev)
28691@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28692 if (reason & uPD98402_INT_PFM) stat_event(dev);
28693 if (reason & uPD98402_INT_PCO) {
28694 (void) GET(PCOCR); /* clear interrupt cause */
28695- atomic_add(GET(HECCT),
28696+ atomic_add_unchecked(GET(HECCT),
28697 &PRIV(dev)->sonet_stats.uncorr_hcs);
28698 }
28699 if ((reason & uPD98402_INT_RFO) &&
28700@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28701 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28702 uPD98402_INT_LOS),PIMR); /* enable them */
28703 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28704- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28705- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28706- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28707+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28708+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28709+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28710 return 0;
28711 }
28712
28713diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28714index abe4e20..83c4727 100644
28715--- a/drivers/atm/zatm.c
28716+++ b/drivers/atm/zatm.c
28717@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28718 }
28719 if (!size) {
28720 dev_kfree_skb_irq(skb);
28721- if (vcc) atomic_inc(&vcc->stats->rx_err);
28722+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28723 continue;
28724 }
28725 if (!atm_charge(vcc,skb->truesize)) {
28726@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28727 skb->len = size;
28728 ATM_SKB(skb)->vcc = vcc;
28729 vcc->push(vcc,skb);
28730- atomic_inc(&vcc->stats->rx);
28731+ atomic_inc_unchecked(&vcc->stats->rx);
28732 }
28733 zout(pos & 0xffff,MTA(mbx));
28734 #if 0 /* probably a stupid idea */
28735@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28736 skb_queue_head(&zatm_vcc->backlog,skb);
28737 break;
28738 }
28739- atomic_inc(&vcc->stats->tx);
28740+ atomic_inc_unchecked(&vcc->stats->tx);
28741 wake_up(&zatm_vcc->tx_wait);
28742 }
28743
28744diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28745index 765c3a2..771ace6 100644
28746--- a/drivers/base/devtmpfs.c
28747+++ b/drivers/base/devtmpfs.c
28748@@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
28749 if (!thread)
28750 return 0;
28751
28752- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28753+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28754 if (err)
28755 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28756 else
28757diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28758index cbb463b..babe2cf 100644
28759--- a/drivers/base/power/wakeup.c
28760+++ b/drivers/base/power/wakeup.c
28761@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
28762 * They need to be modified together atomically, so it's better to use one
28763 * atomic variable to hold them both.
28764 */
28765-static atomic_t combined_event_count = ATOMIC_INIT(0);
28766+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
28767
28768 #define IN_PROGRESS_BITS (sizeof(int) * 4)
28769 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
28770
28771 static void split_counters(unsigned int *cnt, unsigned int *inpr)
28772 {
28773- unsigned int comb = atomic_read(&combined_event_count);
28774+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
28775
28776 *cnt = (comb >> IN_PROGRESS_BITS);
28777 *inpr = comb & MAX_IN_PROGRESS;
28778@@ -385,7 +385,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
28779 ws->start_prevent_time = ws->last_time;
28780
28781 /* Increment the counter of events in progress. */
28782- cec = atomic_inc_return(&combined_event_count);
28783+ cec = atomic_inc_return_unchecked(&combined_event_count);
28784
28785 trace_wakeup_source_activate(ws->name, cec);
28786 }
28787@@ -511,7 +511,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
28788 * Increment the counter of registered wakeup events and decrement the
28789 * couter of wakeup events in progress simultaneously.
28790 */
28791- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
28792+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
28793 trace_wakeup_source_deactivate(ws->name, cec);
28794
28795 split_counters(&cnt, &inpr);
28796diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
28797index b0f553b..77b928b 100644
28798--- a/drivers/block/cciss.c
28799+++ b/drivers/block/cciss.c
28800@@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
28801 int err;
28802 u32 cp;
28803
28804+ memset(&arg64, 0, sizeof(arg64));
28805+
28806 err = 0;
28807 err |=
28808 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
28809@@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
28810 while (!list_empty(&h->reqQ)) {
28811 c = list_entry(h->reqQ.next, CommandList_struct, list);
28812 /* can't do anything if fifo is full */
28813- if ((h->access.fifo_full(h))) {
28814+ if ((h->access->fifo_full(h))) {
28815 dev_warn(&h->pdev->dev, "fifo full\n");
28816 break;
28817 }
28818@@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
28819 h->Qdepth--;
28820
28821 /* Tell the controller execute command */
28822- h->access.submit_command(h, c);
28823+ h->access->submit_command(h, c);
28824
28825 /* Put job onto the completed Q */
28826 addQ(&h->cmpQ, c);
28827@@ -3443,17 +3445,17 @@ startio:
28828
28829 static inline unsigned long get_next_completion(ctlr_info_t *h)
28830 {
28831- return h->access.command_completed(h);
28832+ return h->access->command_completed(h);
28833 }
28834
28835 static inline int interrupt_pending(ctlr_info_t *h)
28836 {
28837- return h->access.intr_pending(h);
28838+ return h->access->intr_pending(h);
28839 }
28840
28841 static inline long interrupt_not_for_us(ctlr_info_t *h)
28842 {
28843- return ((h->access.intr_pending(h) == 0) ||
28844+ return ((h->access->intr_pending(h) == 0) ||
28845 (h->interrupts_enabled == 0));
28846 }
28847
28848@@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
28849 u32 a;
28850
28851 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
28852- return h->access.command_completed(h);
28853+ return h->access->command_completed(h);
28854
28855 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
28856 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
28857@@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
28858 trans_support & CFGTBL_Trans_use_short_tags);
28859
28860 /* Change the access methods to the performant access methods */
28861- h->access = SA5_performant_access;
28862+ h->access = &SA5_performant_access;
28863 h->transMethod = CFGTBL_Trans_Performant;
28864
28865 return;
28866@@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
28867 if (prod_index < 0)
28868 return -ENODEV;
28869 h->product_name = products[prod_index].product_name;
28870- h->access = *(products[prod_index].access);
28871+ h->access = products[prod_index].access;
28872
28873 if (cciss_board_disabled(h)) {
28874 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
28875@@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
28876 }
28877
28878 /* make sure the board interrupts are off */
28879- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28880+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28881 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
28882 if (rc)
28883 goto clean2;
28884@@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
28885 * fake ones to scoop up any residual completions.
28886 */
28887 spin_lock_irqsave(&h->lock, flags);
28888- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28889+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28890 spin_unlock_irqrestore(&h->lock, flags);
28891 free_irq(h->intr[h->intr_mode], h);
28892 rc = cciss_request_irq(h, cciss_msix_discard_completions,
28893@@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
28894 dev_info(&h->pdev->dev, "Board READY.\n");
28895 dev_info(&h->pdev->dev,
28896 "Waiting for stale completions to drain.\n");
28897- h->access.set_intr_mask(h, CCISS_INTR_ON);
28898+ h->access->set_intr_mask(h, CCISS_INTR_ON);
28899 msleep(10000);
28900- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28901+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28902
28903 rc = controller_reset_failed(h->cfgtable);
28904 if (rc)
28905@@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
28906 cciss_scsi_setup(h);
28907
28908 /* Turn the interrupts on so we can service requests */
28909- h->access.set_intr_mask(h, CCISS_INTR_ON);
28910+ h->access->set_intr_mask(h, CCISS_INTR_ON);
28911
28912 /* Get the firmware version */
28913 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
28914@@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
28915 kfree(flush_buf);
28916 if (return_code != IO_OK)
28917 dev_warn(&h->pdev->dev, "Error flushing cache\n");
28918- h->access.set_intr_mask(h, CCISS_INTR_OFF);
28919+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
28920 free_irq(h->intr[h->intr_mode], h);
28921 }
28922
28923diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
28924index 7fda30e..eb5dfe0 100644
28925--- a/drivers/block/cciss.h
28926+++ b/drivers/block/cciss.h
28927@@ -101,7 +101,7 @@ struct ctlr_info
28928 /* information about each logical volume */
28929 drive_info_struct *drv[CISS_MAX_LUN];
28930
28931- struct access_method access;
28932+ struct access_method *access;
28933
28934 /* queue and queue Info */
28935 struct list_head reqQ;
28936diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
28937index 9125bbe..eede5c8 100644
28938--- a/drivers/block/cpqarray.c
28939+++ b/drivers/block/cpqarray.c
28940@@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28941 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
28942 goto Enomem4;
28943 }
28944- hba[i]->access.set_intr_mask(hba[i], 0);
28945+ hba[i]->access->set_intr_mask(hba[i], 0);
28946 if (request_irq(hba[i]->intr, do_ida_intr,
28947 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
28948 {
28949@@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28950 add_timer(&hba[i]->timer);
28951
28952 /* Enable IRQ now that spinlock and rate limit timer are set up */
28953- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28954+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28955
28956 for(j=0; j<NWD; j++) {
28957 struct gendisk *disk = ida_gendisk[i][j];
28958@@ -694,7 +694,7 @@ DBGINFO(
28959 for(i=0; i<NR_PRODUCTS; i++) {
28960 if (board_id == products[i].board_id) {
28961 c->product_name = products[i].product_name;
28962- c->access = *(products[i].access);
28963+ c->access = products[i].access;
28964 break;
28965 }
28966 }
28967@@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
28968 hba[ctlr]->intr = intr;
28969 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
28970 hba[ctlr]->product_name = products[j].product_name;
28971- hba[ctlr]->access = *(products[j].access);
28972+ hba[ctlr]->access = products[j].access;
28973 hba[ctlr]->ctlr = ctlr;
28974 hba[ctlr]->board_id = board_id;
28975 hba[ctlr]->pci_dev = NULL; /* not PCI */
28976@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
28977
28978 while((c = h->reqQ) != NULL) {
28979 /* Can't do anything if we're busy */
28980- if (h->access.fifo_full(h) == 0)
28981+ if (h->access->fifo_full(h) == 0)
28982 return;
28983
28984 /* Get the first entry from the request Q */
28985@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
28986 h->Qdepth--;
28987
28988 /* Tell the controller to do our bidding */
28989- h->access.submit_command(h, c);
28990+ h->access->submit_command(h, c);
28991
28992 /* Get onto the completion Q */
28993 addQ(&h->cmpQ, c);
28994@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28995 unsigned long flags;
28996 __u32 a,a1;
28997
28998- istat = h->access.intr_pending(h);
28999+ istat = h->access->intr_pending(h);
29000 /* Is this interrupt for us? */
29001 if (istat == 0)
29002 return IRQ_NONE;
29003@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29004 */
29005 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
29006 if (istat & FIFO_NOT_EMPTY) {
29007- while((a = h->access.command_completed(h))) {
29008+ while((a = h->access->command_completed(h))) {
29009 a1 = a; a &= ~3;
29010 if ((c = h->cmpQ) == NULL)
29011 {
29012@@ -1449,11 +1449,11 @@ static int sendcmd(
29013 /*
29014 * Disable interrupt
29015 */
29016- info_p->access.set_intr_mask(info_p, 0);
29017+ info_p->access->set_intr_mask(info_p, 0);
29018 /* Make sure there is room in the command FIFO */
29019 /* Actually it should be completely empty at this time. */
29020 for (i = 200000; i > 0; i--) {
29021- temp = info_p->access.fifo_full(info_p);
29022+ temp = info_p->access->fifo_full(info_p);
29023 if (temp != 0) {
29024 break;
29025 }
29026@@ -1466,7 +1466,7 @@ DBG(
29027 /*
29028 * Send the cmd
29029 */
29030- info_p->access.submit_command(info_p, c);
29031+ info_p->access->submit_command(info_p, c);
29032 complete = pollcomplete(ctlr);
29033
29034 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29035@@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29036 * we check the new geometry. Then turn interrupts back on when
29037 * we're done.
29038 */
29039- host->access.set_intr_mask(host, 0);
29040+ host->access->set_intr_mask(host, 0);
29041 getgeometry(ctlr);
29042- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29043+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29044
29045 for(i=0; i<NWD; i++) {
29046 struct gendisk *disk = ida_gendisk[ctlr][i];
29047@@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29048 /* Wait (up to 2 seconds) for a command to complete */
29049
29050 for (i = 200000; i > 0; i--) {
29051- done = hba[ctlr]->access.command_completed(hba[ctlr]);
29052+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
29053 if (done == 0) {
29054 udelay(10); /* a short fixed delay */
29055 } else
29056diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29057index be73e9d..7fbf140 100644
29058--- a/drivers/block/cpqarray.h
29059+++ b/drivers/block/cpqarray.h
29060@@ -99,7 +99,7 @@ struct ctlr_info {
29061 drv_info_t drv[NWD];
29062 struct proc_dir_entry *proc;
29063
29064- struct access_method access;
29065+ struct access_method *access;
29066
29067 cmdlist_t *reqQ;
29068 cmdlist_t *cmpQ;
29069diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29070index 02f013a..afeba24 100644
29071--- a/drivers/block/drbd/drbd_int.h
29072+++ b/drivers/block/drbd/drbd_int.h
29073@@ -735,7 +735,7 @@ struct drbd_request;
29074 struct drbd_epoch {
29075 struct list_head list;
29076 unsigned int barrier_nr;
29077- atomic_t epoch_size; /* increased on every request added. */
29078+ atomic_unchecked_t epoch_size; /* increased on every request added. */
29079 atomic_t active; /* increased on every req. added, and dec on every finished. */
29080 unsigned long flags;
29081 };
29082@@ -1110,7 +1110,7 @@ struct drbd_conf {
29083 void *int_dig_in;
29084 void *int_dig_vv;
29085 wait_queue_head_t seq_wait;
29086- atomic_t packet_seq;
29087+ atomic_unchecked_t packet_seq;
29088 unsigned int peer_seq;
29089 spinlock_t peer_seq_lock;
29090 unsigned int minor;
29091@@ -1651,30 +1651,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29092
29093 static inline void drbd_tcp_cork(struct socket *sock)
29094 {
29095- int __user val = 1;
29096+ int val = 1;
29097 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29098- (char __user *)&val, sizeof(val));
29099+ (char __force_user *)&val, sizeof(val));
29100 }
29101
29102 static inline void drbd_tcp_uncork(struct socket *sock)
29103 {
29104- int __user val = 0;
29105+ int val = 0;
29106 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29107- (char __user *)&val, sizeof(val));
29108+ (char __force_user *)&val, sizeof(val));
29109 }
29110
29111 static inline void drbd_tcp_nodelay(struct socket *sock)
29112 {
29113- int __user val = 1;
29114+ int val = 1;
29115 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29116- (char __user *)&val, sizeof(val));
29117+ (char __force_user *)&val, sizeof(val));
29118 }
29119
29120 static inline void drbd_tcp_quickack(struct socket *sock)
29121 {
29122- int __user val = 2;
29123+ int val = 2;
29124 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29125- (char __user *)&val, sizeof(val));
29126+ (char __force_user *)&val, sizeof(val));
29127 }
29128
29129 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29130diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29131index 920ede2..cb827ba 100644
29132--- a/drivers/block/drbd/drbd_main.c
29133+++ b/drivers/block/drbd/drbd_main.c
29134@@ -2555,7 +2555,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29135 p.sector = sector;
29136 p.block_id = block_id;
29137 p.blksize = blksize;
29138- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29139+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29140
29141 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29142 return false;
29143@@ -2853,7 +2853,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29144
29145 p.sector = cpu_to_be64(req->sector);
29146 p.block_id = (unsigned long)req;
29147- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29148+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29149
29150 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29151
29152@@ -3138,7 +3138,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29153 atomic_set(&mdev->unacked_cnt, 0);
29154 atomic_set(&mdev->local_cnt, 0);
29155 atomic_set(&mdev->net_cnt, 0);
29156- atomic_set(&mdev->packet_seq, 0);
29157+ atomic_set_unchecked(&mdev->packet_seq, 0);
29158 atomic_set(&mdev->pp_in_use, 0);
29159 atomic_set(&mdev->pp_in_use_by_net, 0);
29160 atomic_set(&mdev->rs_sect_in, 0);
29161@@ -3220,8 +3220,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29162 mdev->receiver.t_state);
29163
29164 /* no need to lock it, I'm the only thread alive */
29165- if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29166- dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29167+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29168+ dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29169 mdev->al_writ_cnt =
29170 mdev->bm_writ_cnt =
29171 mdev->read_cnt =
29172diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29173index 6d4de6a..7b7ad4b 100644
29174--- a/drivers/block/drbd/drbd_nl.c
29175+++ b/drivers/block/drbd/drbd_nl.c
29176@@ -2387,7 +2387,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29177 module_put(THIS_MODULE);
29178 }
29179
29180-static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29181+static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29182
29183 static unsigned short *
29184 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29185@@ -2458,7 +2458,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29186 cn_reply->id.idx = CN_IDX_DRBD;
29187 cn_reply->id.val = CN_VAL_DRBD;
29188
29189- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29190+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29191 cn_reply->ack = 0; /* not used here. */
29192 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29193 (int)((char *)tl - (char *)reply->tag_list);
29194@@ -2490,7 +2490,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29195 cn_reply->id.idx = CN_IDX_DRBD;
29196 cn_reply->id.val = CN_VAL_DRBD;
29197
29198- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29199+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29200 cn_reply->ack = 0; /* not used here. */
29201 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29202 (int)((char *)tl - (char *)reply->tag_list);
29203@@ -2568,7 +2568,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29204 cn_reply->id.idx = CN_IDX_DRBD;
29205 cn_reply->id.val = CN_VAL_DRBD;
29206
29207- cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29208+ cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29209 cn_reply->ack = 0; // not used here.
29210 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29211 (int)((char*)tl - (char*)reply->tag_list);
29212@@ -2607,7 +2607,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29213 cn_reply->id.idx = CN_IDX_DRBD;
29214 cn_reply->id.val = CN_VAL_DRBD;
29215
29216- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29217+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29218 cn_reply->ack = 0; /* not used here. */
29219 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29220 (int)((char *)tl - (char *)reply->tag_list);
29221diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29222index ea4836e..272d72a 100644
29223--- a/drivers/block/drbd/drbd_receiver.c
29224+++ b/drivers/block/drbd/drbd_receiver.c
29225@@ -893,7 +893,7 @@ retry:
29226 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29227 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29228
29229- atomic_set(&mdev->packet_seq, 0);
29230+ atomic_set_unchecked(&mdev->packet_seq, 0);
29231 mdev->peer_seq = 0;
29232
29233 if (drbd_send_protocol(mdev) == -1)
29234@@ -994,7 +994,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29235 do {
29236 next_epoch = NULL;
29237
29238- epoch_size = atomic_read(&epoch->epoch_size);
29239+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29240
29241 switch (ev & ~EV_CLEANUP) {
29242 case EV_PUT:
29243@@ -1030,7 +1030,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29244 rv = FE_DESTROYED;
29245 } else {
29246 epoch->flags = 0;
29247- atomic_set(&epoch->epoch_size, 0);
29248+ atomic_set_unchecked(&epoch->epoch_size, 0);
29249 /* atomic_set(&epoch->active, 0); is already zero */
29250 if (rv == FE_STILL_LIVE)
29251 rv = FE_RECYCLED;
29252@@ -1205,14 +1205,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29253 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29254 drbd_flush(mdev);
29255
29256- if (atomic_read(&mdev->current_epoch->epoch_size)) {
29257+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29258 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29259 if (epoch)
29260 break;
29261 }
29262
29263 epoch = mdev->current_epoch;
29264- wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29265+ wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29266
29267 D_ASSERT(atomic_read(&epoch->active) == 0);
29268 D_ASSERT(epoch->flags == 0);
29269@@ -1224,11 +1224,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29270 }
29271
29272 epoch->flags = 0;
29273- atomic_set(&epoch->epoch_size, 0);
29274+ atomic_set_unchecked(&epoch->epoch_size, 0);
29275 atomic_set(&epoch->active, 0);
29276
29277 spin_lock(&mdev->epoch_lock);
29278- if (atomic_read(&mdev->current_epoch->epoch_size)) {
29279+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29280 list_add(&epoch->list, &mdev->current_epoch->list);
29281 mdev->current_epoch = epoch;
29282 mdev->epochs++;
29283@@ -1695,7 +1695,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29284 spin_unlock(&mdev->peer_seq_lock);
29285
29286 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29287- atomic_inc(&mdev->current_epoch->epoch_size);
29288+ atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29289 return drbd_drain_block(mdev, data_size);
29290 }
29291
29292@@ -1721,7 +1721,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29293
29294 spin_lock(&mdev->epoch_lock);
29295 e->epoch = mdev->current_epoch;
29296- atomic_inc(&e->epoch->epoch_size);
29297+ atomic_inc_unchecked(&e->epoch->epoch_size);
29298 atomic_inc(&e->epoch->active);
29299 spin_unlock(&mdev->epoch_lock);
29300
29301@@ -3936,7 +3936,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29302 D_ASSERT(list_empty(&mdev->done_ee));
29303
29304 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29305- atomic_set(&mdev->current_epoch->epoch_size, 0);
29306+ atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29307 D_ASSERT(list_empty(&mdev->current_epoch->list));
29308 }
29309
29310diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29311index 3bba655..6151b66 100644
29312--- a/drivers/block/loop.c
29313+++ b/drivers/block/loop.c
29314@@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29315 mm_segment_t old_fs = get_fs();
29316
29317 set_fs(get_ds());
29318- bw = file->f_op->write(file, buf, len, &pos);
29319+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29320 set_fs(old_fs);
29321 if (likely(bw == len))
29322 return 0;
29323diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29324index ea6f632..eafb192 100644
29325--- a/drivers/char/Kconfig
29326+++ b/drivers/char/Kconfig
29327@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29328
29329 config DEVKMEM
29330 bool "/dev/kmem virtual device support"
29331- default y
29332+ default n
29333+ depends on !GRKERNSEC_KMEM
29334 help
29335 Say Y here if you want to support the /dev/kmem device. The
29336 /dev/kmem device is rarely used, but can be used for certain
29337@@ -581,6 +582,7 @@ config DEVPORT
29338 bool
29339 depends on !M68K
29340 depends on ISA || PCI
29341+ depends on !GRKERNSEC_KMEM
29342 default y
29343
29344 source "drivers/s390/char/Kconfig"
29345diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29346index 2e04433..22afc64 100644
29347--- a/drivers/char/agp/frontend.c
29348+++ b/drivers/char/agp/frontend.c
29349@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29350 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29351 return -EFAULT;
29352
29353- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29354+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29355 return -EFAULT;
29356
29357 client = agp_find_client_by_pid(reserve.pid);
29358diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29359index 21cb980..f15107c 100644
29360--- a/drivers/char/genrtc.c
29361+++ b/drivers/char/genrtc.c
29362@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29363 switch (cmd) {
29364
29365 case RTC_PLL_GET:
29366+ memset(&pll, 0, sizeof(pll));
29367 if (get_rtc_pll(&pll))
29368 return -EINVAL;
29369 else
29370diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29371index dfd7876..c0b0885 100644
29372--- a/drivers/char/hpet.c
29373+++ b/drivers/char/hpet.c
29374@@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29375 }
29376
29377 static int
29378-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29379+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29380 struct hpet_info *info)
29381 {
29382 struct hpet_timer __iomem *timer;
29383diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29384index 2c29942..604c5ba 100644
29385--- a/drivers/char/ipmi/ipmi_msghandler.c
29386+++ b/drivers/char/ipmi/ipmi_msghandler.c
29387@@ -420,7 +420,7 @@ struct ipmi_smi {
29388 struct proc_dir_entry *proc_dir;
29389 char proc_dir_name[10];
29390
29391- atomic_t stats[IPMI_NUM_STATS];
29392+ atomic_unchecked_t stats[IPMI_NUM_STATS];
29393
29394 /*
29395 * run_to_completion duplicate of smb_info, smi_info
29396@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29397
29398
29399 #define ipmi_inc_stat(intf, stat) \
29400- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29401+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29402 #define ipmi_get_stat(intf, stat) \
29403- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29404+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29405
29406 static int is_lan_addr(struct ipmi_addr *addr)
29407 {
29408@@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29409 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29410 init_waitqueue_head(&intf->waitq);
29411 for (i = 0; i < IPMI_NUM_STATS; i++)
29412- atomic_set(&intf->stats[i], 0);
29413+ atomic_set_unchecked(&intf->stats[i], 0);
29414
29415 intf->proc_dir = NULL;
29416
29417diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29418index 1e638ff..a869ef5 100644
29419--- a/drivers/char/ipmi/ipmi_si_intf.c
29420+++ b/drivers/char/ipmi/ipmi_si_intf.c
29421@@ -275,7 +275,7 @@ struct smi_info {
29422 unsigned char slave_addr;
29423
29424 /* Counters and things for the proc filesystem. */
29425- atomic_t stats[SI_NUM_STATS];
29426+ atomic_unchecked_t stats[SI_NUM_STATS];
29427
29428 struct task_struct *thread;
29429
29430@@ -284,9 +284,9 @@ struct smi_info {
29431 };
29432
29433 #define smi_inc_stat(smi, stat) \
29434- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29435+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29436 #define smi_get_stat(smi, stat) \
29437- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29438+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29439
29440 #define SI_MAX_PARMS 4
29441
29442@@ -3209,7 +3209,7 @@ static int try_smi_init(struct smi_info *new_smi)
29443 atomic_set(&new_smi->req_events, 0);
29444 new_smi->run_to_completion = 0;
29445 for (i = 0; i < SI_NUM_STATS; i++)
29446- atomic_set(&new_smi->stats[i], 0);
29447+ atomic_set_unchecked(&new_smi->stats[i], 0);
29448
29449 new_smi->interrupt_disabled = 1;
29450 atomic_set(&new_smi->stop_operation, 0);
29451diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29452index 47ff7e4..0c7d340 100644
29453--- a/drivers/char/mbcs.c
29454+++ b/drivers/char/mbcs.c
29455@@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
29456 return 0;
29457 }
29458
29459-static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29460+static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29461 {
29462 .part_num = MBCS_PART_NUM,
29463 .mfg_num = MBCS_MFG_NUM,
29464diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29465index 67c3371..ba8429d 100644
29466--- a/drivers/char/mem.c
29467+++ b/drivers/char/mem.c
29468@@ -18,6 +18,7 @@
29469 #include <linux/raw.h>
29470 #include <linux/tty.h>
29471 #include <linux/capability.h>
29472+#include <linux/security.h>
29473 #include <linux/ptrace.h>
29474 #include <linux/device.h>
29475 #include <linux/highmem.h>
29476@@ -35,6 +36,10 @@
29477 # include <linux/efi.h>
29478 #endif
29479
29480+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29481+extern const struct file_operations grsec_fops;
29482+#endif
29483+
29484 static inline unsigned long size_inside_page(unsigned long start,
29485 unsigned long size)
29486 {
29487@@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29488
29489 while (cursor < to) {
29490 if (!devmem_is_allowed(pfn)) {
29491+#ifdef CONFIG_GRKERNSEC_KMEM
29492+ gr_handle_mem_readwrite(from, to);
29493+#else
29494 printk(KERN_INFO
29495 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29496 current->comm, from, to);
29497+#endif
29498 return 0;
29499 }
29500 cursor += PAGE_SIZE;
29501@@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29502 }
29503 return 1;
29504 }
29505+#elif defined(CONFIG_GRKERNSEC_KMEM)
29506+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29507+{
29508+ return 0;
29509+}
29510 #else
29511 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29512 {
29513@@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29514
29515 while (count > 0) {
29516 unsigned long remaining;
29517+ char *temp;
29518
29519 sz = size_inside_page(p, count);
29520
29521@@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29522 if (!ptr)
29523 return -EFAULT;
29524
29525- remaining = copy_to_user(buf, ptr, sz);
29526+#ifdef CONFIG_PAX_USERCOPY
29527+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29528+ if (!temp) {
29529+ unxlate_dev_mem_ptr(p, ptr);
29530+ return -ENOMEM;
29531+ }
29532+ memcpy(temp, ptr, sz);
29533+#else
29534+ temp = ptr;
29535+#endif
29536+
29537+ remaining = copy_to_user(buf, temp, sz);
29538+
29539+#ifdef CONFIG_PAX_USERCOPY
29540+ kfree(temp);
29541+#endif
29542+
29543 unxlate_dev_mem_ptr(p, ptr);
29544 if (remaining)
29545 return -EFAULT;
29546@@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29547 size_t count, loff_t *ppos)
29548 {
29549 unsigned long p = *ppos;
29550- ssize_t low_count, read, sz;
29551+ ssize_t low_count, read, sz, err = 0;
29552 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29553- int err = 0;
29554
29555 read = 0;
29556 if (p < (unsigned long) high_memory) {
29557@@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29558 }
29559 #endif
29560 while (low_count > 0) {
29561+ char *temp;
29562+
29563 sz = size_inside_page(p, low_count);
29564
29565 /*
29566@@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29567 */
29568 kbuf = xlate_dev_kmem_ptr((char *)p);
29569
29570- if (copy_to_user(buf, kbuf, sz))
29571+#ifdef CONFIG_PAX_USERCOPY
29572+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29573+ if (!temp)
29574+ return -ENOMEM;
29575+ memcpy(temp, kbuf, sz);
29576+#else
29577+ temp = kbuf;
29578+#endif
29579+
29580+ err = copy_to_user(buf, temp, sz);
29581+
29582+#ifdef CONFIG_PAX_USERCOPY
29583+ kfree(temp);
29584+#endif
29585+
29586+ if (err)
29587 return -EFAULT;
29588 buf += sz;
29589 p += sz;
29590@@ -831,6 +878,9 @@ static const struct memdev {
29591 #ifdef CONFIG_CRASH_DUMP
29592 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29593 #endif
29594+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29595+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29596+#endif
29597 };
29598
29599 static int memory_open(struct inode *inode, struct file *filp)
29600diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29601index 9df78e2..01ba9ae 100644
29602--- a/drivers/char/nvram.c
29603+++ b/drivers/char/nvram.c
29604@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29605
29606 spin_unlock_irq(&rtc_lock);
29607
29608- if (copy_to_user(buf, contents, tmp - contents))
29609+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29610 return -EFAULT;
29611
29612 *ppos = i;
29613diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
29614index 0a484b4..f48ccd1 100644
29615--- a/drivers/char/pcmcia/synclink_cs.c
29616+++ b/drivers/char/pcmcia/synclink_cs.c
29617@@ -2340,9 +2340,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29618
29619 if (debug_level >= DEBUG_LEVEL_INFO)
29620 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
29621- __FILE__,__LINE__, info->device_name, port->count);
29622+ __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
29623
29624- WARN_ON(!port->count);
29625+ WARN_ON(!atomic_read(&port->count));
29626
29627 if (tty_port_close_start(port, tty, filp) == 0)
29628 goto cleanup;
29629@@ -2360,7 +2360,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29630 cleanup:
29631 if (debug_level >= DEBUG_LEVEL_INFO)
29632 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
29633- tty->driver->name, port->count);
29634+ tty->driver->name, atomic_read(&port->count));
29635 }
29636
29637 /* Wait until the transmitter is empty.
29638@@ -2502,7 +2502,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29639
29640 if (debug_level >= DEBUG_LEVEL_INFO)
29641 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
29642- __FILE__,__LINE__,tty->driver->name, port->count);
29643+ __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
29644
29645 /* If port is closing, signal caller to try again */
29646 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
29647@@ -2522,11 +2522,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29648 goto cleanup;
29649 }
29650 spin_lock(&port->lock);
29651- port->count++;
29652+ atomic_inc(&port->count);
29653 spin_unlock(&port->lock);
29654 spin_unlock_irqrestore(&info->netlock, flags);
29655
29656- if (port->count == 1) {
29657+ if (atomic_read(&port->count) == 1) {
29658 /* 1st open on this device, init hardware */
29659 retval = startup(info, tty);
29660 if (retval < 0)
29661@@ -3891,7 +3891,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
29662 unsigned short new_crctype;
29663
29664 /* return error if TTY interface open */
29665- if (info->port.count)
29666+ if (atomic_read(&info->port.count))
29667 return -EBUSY;
29668
29669 switch (encoding)
29670@@ -3994,7 +3994,7 @@ static int hdlcdev_open(struct net_device *dev)
29671
29672 /* arbitrate between network and tty opens */
29673 spin_lock_irqsave(&info->netlock, flags);
29674- if (info->port.count != 0 || info->netcount != 0) {
29675+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
29676 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
29677 spin_unlock_irqrestore(&info->netlock, flags);
29678 return -EBUSY;
29679@@ -4083,7 +4083,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
29680 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
29681
29682 /* return error if TTY interface open */
29683- if (info->port.count)
29684+ if (atomic_read(&info->port.count))
29685 return -EBUSY;
29686
29687 if (cmd != SIOCWANDEV)
29688diff --git a/drivers/char/random.c b/drivers/char/random.c
29689index d98b2a6..f0ceb97 100644
29690--- a/drivers/char/random.c
29691+++ b/drivers/char/random.c
29692@@ -272,8 +272,13 @@
29693 /*
29694 * Configuration information
29695 */
29696+#ifdef CONFIG_GRKERNSEC_RANDNET
29697+#define INPUT_POOL_WORDS 512
29698+#define OUTPUT_POOL_WORDS 128
29699+#else
29700 #define INPUT_POOL_WORDS 128
29701 #define OUTPUT_POOL_WORDS 32
29702+#endif
29703 #define SEC_XFER_SIZE 512
29704 #define EXTRACT_SIZE 10
29705
29706@@ -313,10 +318,17 @@ static struct poolinfo {
29707 int poolwords;
29708 int tap1, tap2, tap3, tap4, tap5;
29709 } poolinfo_table[] = {
29710+#ifdef CONFIG_GRKERNSEC_RANDNET
29711+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29712+ { 512, 411, 308, 208, 104, 1 },
29713+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29714+ { 128, 103, 76, 51, 25, 1 },
29715+#else
29716 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29717 { 128, 103, 76, 51, 25, 1 },
29718 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29719 { 32, 26, 20, 14, 7, 1 },
29720+#endif
29721 #if 0
29722 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29723 { 2048, 1638, 1231, 819, 411, 1 },
29724@@ -527,8 +539,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
29725 input_rotate += i ? 7 : 14;
29726 }
29727
29728- ACCESS_ONCE(r->input_rotate) = input_rotate;
29729- ACCESS_ONCE(r->add_ptr) = i;
29730+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
29731+ ACCESS_ONCE_RW(r->add_ptr) = i;
29732 smp_wmb();
29733
29734 if (out)
29735@@ -799,6 +811,17 @@ void add_disk_randomness(struct gendisk *disk)
29736 }
29737 #endif
29738
29739+#ifdef CONFIG_PAX_LATENT_ENTROPY
29740+u64 latent_entropy;
29741+
29742+__init void transfer_latent_entropy(void)
29743+{
29744+ mix_pool_bytes(&input_pool, &latent_entropy, sizeof(latent_entropy), NULL);
29745+ mix_pool_bytes(&nonblocking_pool, &latent_entropy, sizeof(latent_entropy), NULL);
29746+// printk(KERN_INFO "PAX: transferring latent entropy: %16llx\n", latent_entropy);
29747+}
29748+#endif
29749+
29750 /*********************************************************************
29751 *
29752 * Entropy extraction routines
29753@@ -1008,7 +1031,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29754
29755 extract_buf(r, tmp);
29756 i = min_t(int, nbytes, EXTRACT_SIZE);
29757- if (copy_to_user(buf, tmp, i)) {
29758+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29759 ret = -EFAULT;
29760 break;
29761 }
29762@@ -1342,7 +1365,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29763 #include <linux/sysctl.h>
29764
29765 static int min_read_thresh = 8, min_write_thresh;
29766-static int max_read_thresh = INPUT_POOL_WORDS * 32;
29767+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29768 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29769 static char sysctl_bootid[16];
29770
29771diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
29772index 45713f0..8286d21 100644
29773--- a/drivers/char/sonypi.c
29774+++ b/drivers/char/sonypi.c
29775@@ -54,6 +54,7 @@
29776
29777 #include <asm/uaccess.h>
29778 #include <asm/io.h>
29779+#include <asm/local.h>
29780
29781 #include <linux/sonypi.h>
29782
29783@@ -490,7 +491,7 @@ static struct sonypi_device {
29784 spinlock_t fifo_lock;
29785 wait_queue_head_t fifo_proc_list;
29786 struct fasync_struct *fifo_async;
29787- int open_count;
29788+ local_t open_count;
29789 int model;
29790 struct input_dev *input_jog_dev;
29791 struct input_dev *input_key_dev;
29792@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
29793 static int sonypi_misc_release(struct inode *inode, struct file *file)
29794 {
29795 mutex_lock(&sonypi_device.lock);
29796- sonypi_device.open_count--;
29797+ local_dec(&sonypi_device.open_count);
29798 mutex_unlock(&sonypi_device.lock);
29799 return 0;
29800 }
29801@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
29802 {
29803 mutex_lock(&sonypi_device.lock);
29804 /* Flush input queue on first open */
29805- if (!sonypi_device.open_count)
29806+ if (!local_read(&sonypi_device.open_count))
29807 kfifo_reset(&sonypi_device.fifo);
29808- sonypi_device.open_count++;
29809+ local_inc(&sonypi_device.open_count);
29810 mutex_unlock(&sonypi_device.lock);
29811
29812 return 0;
29813diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
29814index 08427ab..1ab10b7 100644
29815--- a/drivers/char/tpm/tpm.c
29816+++ b/drivers/char/tpm/tpm.c
29817@@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
29818 chip->vendor.req_complete_val)
29819 goto out_recv;
29820
29821- if ((status == chip->vendor.req_canceled)) {
29822+ if (status == chip->vendor.req_canceled) {
29823 dev_err(chip->dev, "Operation Canceled\n");
29824 rc = -ECANCELED;
29825 goto out;
29826diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
29827index 0636520..169c1d0 100644
29828--- a/drivers/char/tpm/tpm_bios.c
29829+++ b/drivers/char/tpm/tpm_bios.c
29830@@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
29831 event = addr;
29832
29833 if ((event->event_type == 0 && event->event_size == 0) ||
29834- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
29835+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
29836 return NULL;
29837
29838 return addr;
29839@@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
29840 return NULL;
29841
29842 if ((event->event_type == 0 && event->event_size == 0) ||
29843- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
29844+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
29845 return NULL;
29846
29847 (*pos)++;
29848@@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
29849 int i;
29850
29851 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
29852- seq_putc(m, data[i]);
29853+ if (!seq_putc(m, data[i]))
29854+ return -EFAULT;
29855
29856 return 0;
29857 }
29858@@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
29859 log->bios_event_log_end = log->bios_event_log + len;
29860
29861 virt = acpi_os_map_memory(start, len);
29862+ if (!virt) {
29863+ kfree(log->bios_event_log);
29864+ log->bios_event_log = NULL;
29865+ return -EFAULT;
29866+ }
29867
29868- memcpy(log->bios_event_log, virt, len);
29869+ memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
29870
29871 acpi_os_unmap_memory(virt, len);
29872 return 0;
29873diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
29874index cdf2f54..e55c197 100644
29875--- a/drivers/char/virtio_console.c
29876+++ b/drivers/char/virtio_console.c
29877@@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
29878 if (to_user) {
29879 ssize_t ret;
29880
29881- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
29882+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
29883 if (ret)
29884 return -EFAULT;
29885 } else {
29886@@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
29887 if (!port_has_data(port) && !port->host_connected)
29888 return 0;
29889
29890- return fill_readbuf(port, ubuf, count, true);
29891+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
29892 }
29893
29894 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
29895diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
29896index 97f5064..202b6e6 100644
29897--- a/drivers/edac/edac_pci_sysfs.c
29898+++ b/drivers/edac/edac_pci_sysfs.c
29899@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
29900 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
29901 static int edac_pci_poll_msec = 1000; /* one second workq period */
29902
29903-static atomic_t pci_parity_count = ATOMIC_INIT(0);
29904-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
29905+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
29906+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
29907
29908 static struct kobject *edac_pci_top_main_kobj;
29909 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
29910@@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29911 edac_printk(KERN_CRIT, EDAC_PCI,
29912 "Signaled System Error on %s\n",
29913 pci_name(dev));
29914- atomic_inc(&pci_nonparity_count);
29915+ atomic_inc_unchecked(&pci_nonparity_count);
29916 }
29917
29918 if (status & (PCI_STATUS_PARITY)) {
29919@@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29920 "Master Data Parity Error on %s\n",
29921 pci_name(dev));
29922
29923- atomic_inc(&pci_parity_count);
29924+ atomic_inc_unchecked(&pci_parity_count);
29925 }
29926
29927 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29928@@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29929 "Detected Parity Error on %s\n",
29930 pci_name(dev));
29931
29932- atomic_inc(&pci_parity_count);
29933+ atomic_inc_unchecked(&pci_parity_count);
29934 }
29935 }
29936
29937@@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29938 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
29939 "Signaled System Error on %s\n",
29940 pci_name(dev));
29941- atomic_inc(&pci_nonparity_count);
29942+ atomic_inc_unchecked(&pci_nonparity_count);
29943 }
29944
29945 if (status & (PCI_STATUS_PARITY)) {
29946@@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29947 "Master Data Parity Error on "
29948 "%s\n", pci_name(dev));
29949
29950- atomic_inc(&pci_parity_count);
29951+ atomic_inc_unchecked(&pci_parity_count);
29952 }
29953
29954 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29955@@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29956 "Detected Parity Error on %s\n",
29957 pci_name(dev));
29958
29959- atomic_inc(&pci_parity_count);
29960+ atomic_inc_unchecked(&pci_parity_count);
29961 }
29962 }
29963 }
29964@@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
29965 if (!check_pci_errors)
29966 return;
29967
29968- before_count = atomic_read(&pci_parity_count);
29969+ before_count = atomic_read_unchecked(&pci_parity_count);
29970
29971 /* scan all PCI devices looking for a Parity Error on devices and
29972 * bridges.
29973@@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
29974 /* Only if operator has selected panic on PCI Error */
29975 if (edac_pci_get_panic_on_pe()) {
29976 /* If the count is different 'after' from 'before' */
29977- if (before_count != atomic_read(&pci_parity_count))
29978+ if (before_count != atomic_read_unchecked(&pci_parity_count))
29979 panic("EDAC: PCI Parity Error");
29980 }
29981 }
29982diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
29983index 8c87a5e..a19cbd7 100644
29984--- a/drivers/edac/mce_amd.h
29985+++ b/drivers/edac/mce_amd.h
29986@@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
29987 struct amd_decoder_ops {
29988 bool (*dc_mce)(u16, u8);
29989 bool (*ic_mce)(u16, u8);
29990-};
29991+} __no_const;
29992
29993 void amd_report_gart_errors(bool);
29994 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
29995diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
29996index 57ea7f4..789e3c3 100644
29997--- a/drivers/firewire/core-card.c
29998+++ b/drivers/firewire/core-card.c
29999@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
30000
30001 void fw_core_remove_card(struct fw_card *card)
30002 {
30003- struct fw_card_driver dummy_driver = dummy_driver_template;
30004+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
30005
30006 card->driver->update_phy_reg(card, 4,
30007 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
30008diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
30009index 2783f69..9f4b0cc 100644
30010--- a/drivers/firewire/core-cdev.c
30011+++ b/drivers/firewire/core-cdev.c
30012@@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
30013 int ret;
30014
30015 if ((request->channels == 0 && request->bandwidth == 0) ||
30016- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
30017- request->bandwidth < 0)
30018+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
30019 return -EINVAL;
30020
30021 r = kmalloc(sizeof(*r), GFP_KERNEL);
30022diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
30023index 780708d..ad60a66 100644
30024--- a/drivers/firewire/core-transaction.c
30025+++ b/drivers/firewire/core-transaction.c
30026@@ -37,6 +37,7 @@
30027 #include <linux/timer.h>
30028 #include <linux/types.h>
30029 #include <linux/workqueue.h>
30030+#include <linux/sched.h>
30031
30032 #include <asm/byteorder.h>
30033
30034diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
30035index 515a42c..5ecf3ba 100644
30036--- a/drivers/firewire/core.h
30037+++ b/drivers/firewire/core.h
30038@@ -111,6 +111,7 @@ struct fw_card_driver {
30039
30040 int (*stop_iso)(struct fw_iso_context *ctx);
30041 };
30042+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
30043
30044 void fw_card_initialize(struct fw_card *card,
30045 const struct fw_card_driver *driver, struct device *device);
30046diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
30047index b298158..7ed8432 100644
30048--- a/drivers/firmware/dmi_scan.c
30049+++ b/drivers/firmware/dmi_scan.c
30050@@ -452,11 +452,6 @@ void __init dmi_scan_machine(void)
30051 }
30052 }
30053 else {
30054- /*
30055- * no iounmap() for that ioremap(); it would be a no-op, but
30056- * it's so early in setup that sucker gets confused into doing
30057- * what it shouldn't if we actually call it.
30058- */
30059 p = dmi_ioremap(0xF0000, 0x10000);
30060 if (p == NULL)
30061 goto error;
30062@@ -726,7 +721,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30063 if (buf == NULL)
30064 return -1;
30065
30066- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30067+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30068
30069 iounmap(buf);
30070 return 0;
30071diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30072index 82d5c20..44a7177 100644
30073--- a/drivers/gpio/gpio-vr41xx.c
30074+++ b/drivers/gpio/gpio-vr41xx.c
30075@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30076 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30077 maskl, pendl, maskh, pendh);
30078
30079- atomic_inc(&irq_err_count);
30080+ atomic_inc_unchecked(&irq_err_count);
30081
30082 return -EINVAL;
30083 }
30084diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30085index 3252e70..b5314ace 100644
30086--- a/drivers/gpu/drm/drm_crtc_helper.c
30087+++ b/drivers/gpu/drm/drm_crtc_helper.c
30088@@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30089 struct drm_crtc *tmp;
30090 int crtc_mask = 1;
30091
30092- WARN(!crtc, "checking null crtc?\n");
30093+ BUG_ON(!crtc);
30094
30095 dev = crtc->dev;
30096
30097diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30098index 8a9d079..606cdd5 100644
30099--- a/drivers/gpu/drm/drm_drv.c
30100+++ b/drivers/gpu/drm/drm_drv.c
30101@@ -318,7 +318,7 @@ module_exit(drm_core_exit);
30102 /**
30103 * Copy and IOCTL return string to user space
30104 */
30105-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30106+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30107 {
30108 int len;
30109
30110@@ -401,7 +401,7 @@ long drm_ioctl(struct file *filp,
30111 return -ENODEV;
30112
30113 atomic_inc(&dev->ioctl_count);
30114- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30115+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30116 ++file_priv->ioctl_count;
30117
30118 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30119diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30120index 123de28..43a0897 100644
30121--- a/drivers/gpu/drm/drm_fops.c
30122+++ b/drivers/gpu/drm/drm_fops.c
30123@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30124 }
30125
30126 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30127- atomic_set(&dev->counts[i], 0);
30128+ atomic_set_unchecked(&dev->counts[i], 0);
30129
30130 dev->sigdata.lock = NULL;
30131
30132@@ -138,8 +138,8 @@ int drm_open(struct inode *inode, struct file *filp)
30133
30134 retcode = drm_open_helper(inode, filp, dev);
30135 if (!retcode) {
30136- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30137- if (!dev->open_count++)
30138+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30139+ if (local_inc_return(&dev->open_count) == 1)
30140 retcode = drm_setup(dev);
30141 }
30142 if (!retcode) {
30143@@ -482,7 +482,7 @@ int drm_release(struct inode *inode, struct file *filp)
30144
30145 mutex_lock(&drm_global_mutex);
30146
30147- DRM_DEBUG("open_count = %d\n", dev->open_count);
30148+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30149
30150 if (dev->driver->preclose)
30151 dev->driver->preclose(dev, file_priv);
30152@@ -491,10 +491,10 @@ int drm_release(struct inode *inode, struct file *filp)
30153 * Begin inline drm_release
30154 */
30155
30156- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30157+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30158 task_pid_nr(current),
30159 (long)old_encode_dev(file_priv->minor->device),
30160- dev->open_count);
30161+ local_read(&dev->open_count));
30162
30163 /* Release any auth tokens that might point to this file_priv,
30164 (do that under the drm_global_mutex) */
30165@@ -584,8 +584,8 @@ int drm_release(struct inode *inode, struct file *filp)
30166 * End inline drm_release
30167 */
30168
30169- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30170- if (!--dev->open_count) {
30171+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30172+ if (local_dec_and_test(&dev->open_count)) {
30173 if (atomic_read(&dev->ioctl_count)) {
30174 DRM_ERROR("Device busy: %d\n",
30175 atomic_read(&dev->ioctl_count));
30176diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30177index c87dc96..326055d 100644
30178--- a/drivers/gpu/drm/drm_global.c
30179+++ b/drivers/gpu/drm/drm_global.c
30180@@ -36,7 +36,7 @@
30181 struct drm_global_item {
30182 struct mutex mutex;
30183 void *object;
30184- int refcount;
30185+ atomic_t refcount;
30186 };
30187
30188 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30189@@ -49,7 +49,7 @@ void drm_global_init(void)
30190 struct drm_global_item *item = &glob[i];
30191 mutex_init(&item->mutex);
30192 item->object = NULL;
30193- item->refcount = 0;
30194+ atomic_set(&item->refcount, 0);
30195 }
30196 }
30197
30198@@ -59,7 +59,7 @@ void drm_global_release(void)
30199 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30200 struct drm_global_item *item = &glob[i];
30201 BUG_ON(item->object != NULL);
30202- BUG_ON(item->refcount != 0);
30203+ BUG_ON(atomic_read(&item->refcount) != 0);
30204 }
30205 }
30206
30207@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30208 void *object;
30209
30210 mutex_lock(&item->mutex);
30211- if (item->refcount == 0) {
30212+ if (atomic_read(&item->refcount) == 0) {
30213 item->object = kzalloc(ref->size, GFP_KERNEL);
30214 if (unlikely(item->object == NULL)) {
30215 ret = -ENOMEM;
30216@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30217 goto out_err;
30218
30219 }
30220- ++item->refcount;
30221+ atomic_inc(&item->refcount);
30222 ref->object = item->object;
30223 object = item->object;
30224 mutex_unlock(&item->mutex);
30225@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30226 struct drm_global_item *item = &glob[ref->global_type];
30227
30228 mutex_lock(&item->mutex);
30229- BUG_ON(item->refcount == 0);
30230+ BUG_ON(atomic_read(&item->refcount) == 0);
30231 BUG_ON(ref->object != item->object);
30232- if (--item->refcount == 0) {
30233+ if (atomic_dec_and_test(&item->refcount)) {
30234 ref->release(ref);
30235 item->object = NULL;
30236 }
30237diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30238index ab1162d..42587b2 100644
30239--- a/drivers/gpu/drm/drm_info.c
30240+++ b/drivers/gpu/drm/drm_info.c
30241@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30242 struct drm_local_map *map;
30243 struct drm_map_list *r_list;
30244
30245- /* Hardcoded from _DRM_FRAME_BUFFER,
30246- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30247- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30248- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30249+ static const char * const types[] = {
30250+ [_DRM_FRAME_BUFFER] = "FB",
30251+ [_DRM_REGISTERS] = "REG",
30252+ [_DRM_SHM] = "SHM",
30253+ [_DRM_AGP] = "AGP",
30254+ [_DRM_SCATTER_GATHER] = "SG",
30255+ [_DRM_CONSISTENT] = "PCI",
30256+ [_DRM_GEM] = "GEM" };
30257 const char *type;
30258 int i;
30259
30260@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30261 map = r_list->map;
30262 if (!map)
30263 continue;
30264- if (map->type < 0 || map->type > 5)
30265+ if (map->type >= ARRAY_SIZE(types))
30266 type = "??";
30267 else
30268 type = types[map->type];
30269@@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30270 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30271 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30272 vma->vm_flags & VM_IO ? 'i' : '-',
30273+#ifdef CONFIG_GRKERNSEC_HIDESYM
30274+ 0);
30275+#else
30276 vma->vm_pgoff);
30277+#endif
30278
30279 #if defined(__i386__)
30280 pgprot = pgprot_val(vma->vm_page_prot);
30281diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30282index 637fcc3..e890b33 100644
30283--- a/drivers/gpu/drm/drm_ioc32.c
30284+++ b/drivers/gpu/drm/drm_ioc32.c
30285@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30286 request = compat_alloc_user_space(nbytes);
30287 if (!access_ok(VERIFY_WRITE, request, nbytes))
30288 return -EFAULT;
30289- list = (struct drm_buf_desc *) (request + 1);
30290+ list = (struct drm_buf_desc __user *) (request + 1);
30291
30292 if (__put_user(count, &request->count)
30293 || __put_user(list, &request->list))
30294@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30295 request = compat_alloc_user_space(nbytes);
30296 if (!access_ok(VERIFY_WRITE, request, nbytes))
30297 return -EFAULT;
30298- list = (struct drm_buf_pub *) (request + 1);
30299+ list = (struct drm_buf_pub __user *) (request + 1);
30300
30301 if (__put_user(count, &request->count)
30302 || __put_user(list, &request->list))
30303diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30304index 64a62c6..ceab35e 100644
30305--- a/drivers/gpu/drm/drm_ioctl.c
30306+++ b/drivers/gpu/drm/drm_ioctl.c
30307@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30308 stats->data[i].value =
30309 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30310 else
30311- stats->data[i].value = atomic_read(&dev->counts[i]);
30312+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30313 stats->data[i].type = dev->types[i];
30314 }
30315
30316diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30317index 5211520..c744d85 100644
30318--- a/drivers/gpu/drm/drm_lock.c
30319+++ b/drivers/gpu/drm/drm_lock.c
30320@@ -90,7 +90,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30321 if (drm_lock_take(&master->lock, lock->context)) {
30322 master->lock.file_priv = file_priv;
30323 master->lock.lock_time = jiffies;
30324- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30325+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30326 break; /* Got lock */
30327 }
30328
30329@@ -161,7 +161,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30330 return -EINVAL;
30331 }
30332
30333- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30334+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30335
30336 if (drm_lock_free(&master->lock, lock->context)) {
30337 /* FIXME: Should really bail out here. */
30338diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30339index 21bcd4a..8e074e0 100644
30340--- a/drivers/gpu/drm/drm_stub.c
30341+++ b/drivers/gpu/drm/drm_stub.c
30342@@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
30343
30344 drm_device_set_unplugged(dev);
30345
30346- if (dev->open_count == 0) {
30347+ if (local_read(&dev->open_count) == 0) {
30348 drm_put_dev(dev);
30349 }
30350 mutex_unlock(&drm_global_mutex);
30351diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30352index fa94391..ed26ec8 100644
30353--- a/drivers/gpu/drm/i810/i810_dma.c
30354+++ b/drivers/gpu/drm/i810/i810_dma.c
30355@@ -943,8 +943,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30356 dma->buflist[vertex->idx],
30357 vertex->discard, vertex->used);
30358
30359- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30360- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30361+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30362+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30363 sarea_priv->last_enqueue = dev_priv->counter - 1;
30364 sarea_priv->last_dispatch = (int)hw_status[5];
30365
30366@@ -1104,8 +1104,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30367 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30368 mc->last_render);
30369
30370- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30371- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30372+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30373+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30374 sarea_priv->last_enqueue = dev_priv->counter - 1;
30375 sarea_priv->last_dispatch = (int)hw_status[5];
30376
30377diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30378index c9339f4..f5e1b9d 100644
30379--- a/drivers/gpu/drm/i810/i810_drv.h
30380+++ b/drivers/gpu/drm/i810/i810_drv.h
30381@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30382 int page_flipping;
30383
30384 wait_queue_head_t irq_queue;
30385- atomic_t irq_received;
30386- atomic_t irq_emitted;
30387+ atomic_unchecked_t irq_received;
30388+ atomic_unchecked_t irq_emitted;
30389
30390 int front_offset;
30391 } drm_i810_private_t;
30392diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30393index 5363e9c..59360d1 100644
30394--- a/drivers/gpu/drm/i915/i915_debugfs.c
30395+++ b/drivers/gpu/drm/i915/i915_debugfs.c
30396@@ -518,7 +518,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30397 I915_READ(GTIMR));
30398 }
30399 seq_printf(m, "Interrupts received: %d\n",
30400- atomic_read(&dev_priv->irq_received));
30401+ atomic_read_unchecked(&dev_priv->irq_received));
30402 for (i = 0; i < I915_NUM_RINGS; i++) {
30403 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30404 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30405diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30406index 36822b9..b725e1b 100644
30407--- a/drivers/gpu/drm/i915/i915_dma.c
30408+++ b/drivers/gpu/drm/i915/i915_dma.c
30409@@ -1266,7 +1266,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30410 bool can_switch;
30411
30412 spin_lock(&dev->count_lock);
30413- can_switch = (dev->open_count == 0);
30414+ can_switch = (local_read(&dev->open_count) == 0);
30415 spin_unlock(&dev->count_lock);
30416 return can_switch;
30417 }
30418diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30419index b0b676a..d107105 100644
30420--- a/drivers/gpu/drm/i915/i915_drv.h
30421+++ b/drivers/gpu/drm/i915/i915_drv.h
30422@@ -268,7 +268,7 @@ struct drm_i915_display_funcs {
30423 /* render clock increase/decrease */
30424 /* display clock increase/decrease */
30425 /* pll clock increase/decrease */
30426-};
30427+} __no_const;
30428
30429 struct intel_device_info {
30430 u8 gen;
30431@@ -386,7 +386,7 @@ typedef struct drm_i915_private {
30432 int current_page;
30433 int page_flipping;
30434
30435- atomic_t irq_received;
30436+ atomic_unchecked_t irq_received;
30437
30438 /* protects the irq masks */
30439 spinlock_t irq_lock;
30440@@ -985,7 +985,7 @@ struct drm_i915_gem_object {
30441 * will be page flipped away on the next vblank. When it
30442 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30443 */
30444- atomic_t pending_flip;
30445+ atomic_unchecked_t pending_flip;
30446 };
30447
30448 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30449@@ -1434,7 +1434,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
30450 struct drm_i915_private *dev_priv, unsigned port);
30451 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30452 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30453-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30454+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30455 {
30456 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30457 }
30458diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30459index 974a9f1..b3ebd45 100644
30460--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30461+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30462@@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30463 i915_gem_clflush_object(obj);
30464
30465 if (obj->base.pending_write_domain)
30466- cd->flips |= atomic_read(&obj->pending_flip);
30467+ cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30468
30469 /* The actual obj->write_domain will be updated with
30470 * pending_write_domain after we emit the accumulated flush for all
30471@@ -916,9 +916,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30472
30473 static int
30474 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30475- int count)
30476+ unsigned int count)
30477 {
30478- int i;
30479+ unsigned int i;
30480
30481 for (i = 0; i < count; i++) {
30482 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30483diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30484index ed3224c..6618589 100644
30485--- a/drivers/gpu/drm/i915/i915_irq.c
30486+++ b/drivers/gpu/drm/i915/i915_irq.c
30487@@ -433,7 +433,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
30488 int vblank = 0;
30489 bool blc_event;
30490
30491- atomic_inc(&dev_priv->irq_received);
30492+ atomic_inc_unchecked(&dev_priv->irq_received);
30493
30494 vblank_status = PIPE_START_VBLANK_INTERRUPT_STATUS |
30495 PIPE_VBLANK_INTERRUPT_STATUS;
30496@@ -586,7 +586,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30497 irqreturn_t ret = IRQ_NONE;
30498 int i;
30499
30500- atomic_inc(&dev_priv->irq_received);
30501+ atomic_inc_unchecked(&dev_priv->irq_received);
30502
30503 /* disable master interrupt before clearing iir */
30504 de_ier = I915_READ(DEIER);
30505@@ -661,7 +661,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30506 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30507 u32 hotplug_mask;
30508
30509- atomic_inc(&dev_priv->irq_received);
30510+ atomic_inc_unchecked(&dev_priv->irq_received);
30511
30512 /* disable master interrupt before clearing iir */
30513 de_ier = I915_READ(DEIER);
30514@@ -1646,7 +1646,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30515 {
30516 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30517
30518- atomic_set(&dev_priv->irq_received, 0);
30519+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30520
30521
30522 I915_WRITE(HWSTAM, 0xeffe);
30523@@ -1673,7 +1673,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
30524 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30525 int pipe;
30526
30527- atomic_set(&dev_priv->irq_received, 0);
30528+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30529
30530 /* VLV magic */
30531 I915_WRITE(VLV_IMR, 0);
30532@@ -1969,7 +1969,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
30533 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30534 int pipe;
30535
30536- atomic_set(&dev_priv->irq_received, 0);
30537+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30538
30539 for_each_pipe(pipe)
30540 I915_WRITE(PIPESTAT(pipe), 0);
30541@@ -2020,7 +2020,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
30542 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
30543 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
30544
30545- atomic_inc(&dev_priv->irq_received);
30546+ atomic_inc_unchecked(&dev_priv->irq_received);
30547
30548 iir = I915_READ16(IIR);
30549 if (iir == 0)
30550@@ -2105,7 +2105,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
30551 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30552 int pipe;
30553
30554- atomic_set(&dev_priv->irq_received, 0);
30555+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30556
30557 if (I915_HAS_HOTPLUG(dev)) {
30558 I915_WRITE(PORT_HOTPLUG_EN, 0);
30559@@ -2200,7 +2200,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
30560 };
30561 int pipe, ret = IRQ_NONE;
30562
30563- atomic_inc(&dev_priv->irq_received);
30564+ atomic_inc_unchecked(&dev_priv->irq_received);
30565
30566 iir = I915_READ(IIR);
30567 do {
30568@@ -2326,7 +2326,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
30569 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30570 int pipe;
30571
30572- atomic_set(&dev_priv->irq_received, 0);
30573+ atomic_set_unchecked(&dev_priv->irq_received, 0);
30574
30575 if (I915_HAS_HOTPLUG(dev)) {
30576 I915_WRITE(PORT_HOTPLUG_EN, 0);
30577@@ -2436,7 +2436,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
30578 int irq_received;
30579 int ret = IRQ_NONE, pipe;
30580
30581- atomic_inc(&dev_priv->irq_received);
30582+ atomic_inc_unchecked(&dev_priv->irq_received);
30583
30584 iir = I915_READ(IIR);
30585
30586diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30587index 8a11131..46eeeaa 100644
30588--- a/drivers/gpu/drm/i915/intel_display.c
30589+++ b/drivers/gpu/drm/i915/intel_display.c
30590@@ -2000,7 +2000,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
30591
30592 wait_event(dev_priv->pending_flip_queue,
30593 atomic_read(&dev_priv->mm.wedged) ||
30594- atomic_read(&obj->pending_flip) == 0);
30595+ atomic_read_unchecked(&obj->pending_flip) == 0);
30596
30597 /* Big Hammer, we also need to ensure that any pending
30598 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30599@@ -5914,9 +5914,8 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30600
30601 obj = work->old_fb_obj;
30602
30603- atomic_clear_mask(1 << intel_crtc->plane,
30604- &obj->pending_flip.counter);
30605- if (atomic_read(&obj->pending_flip) == 0)
30606+ atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
30607+ if (atomic_read_unchecked(&obj->pending_flip) == 0)
30608 wake_up(&dev_priv->pending_flip_queue);
30609
30610 schedule_work(&work->work);
30611@@ -6253,7 +6252,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30612 /* Block clients from rendering to the new back buffer until
30613 * the flip occurs and the object is no longer visible.
30614 */
30615- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30616+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30617
30618 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30619 if (ret)
30620@@ -6268,7 +6267,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30621 return 0;
30622
30623 cleanup_pending:
30624- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30625+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30626 drm_gem_object_unreference(&work->old_fb_obj->base);
30627 drm_gem_object_unreference(&obj->base);
30628 mutex_unlock(&dev->struct_mutex);
30629diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30630index 54558a0..2d97005 100644
30631--- a/drivers/gpu/drm/mga/mga_drv.h
30632+++ b/drivers/gpu/drm/mga/mga_drv.h
30633@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30634 u32 clear_cmd;
30635 u32 maccess;
30636
30637- atomic_t vbl_received; /**< Number of vblanks received. */
30638+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30639 wait_queue_head_t fence_queue;
30640- atomic_t last_fence_retired;
30641+ atomic_unchecked_t last_fence_retired;
30642 u32 next_fence_to_post;
30643
30644 unsigned int fb_cpp;
30645diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30646index 2581202..f230a8d9 100644
30647--- a/drivers/gpu/drm/mga/mga_irq.c
30648+++ b/drivers/gpu/drm/mga/mga_irq.c
30649@@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30650 if (crtc != 0)
30651 return 0;
30652
30653- return atomic_read(&dev_priv->vbl_received);
30654+ return atomic_read_unchecked(&dev_priv->vbl_received);
30655 }
30656
30657
30658@@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30659 /* VBLANK interrupt */
30660 if (status & MGA_VLINEPEN) {
30661 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30662- atomic_inc(&dev_priv->vbl_received);
30663+ atomic_inc_unchecked(&dev_priv->vbl_received);
30664 drm_handle_vblank(dev, 0);
30665 handled = 1;
30666 }
30667@@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30668 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30669 MGA_WRITE(MGA_PRIMEND, prim_end);
30670
30671- atomic_inc(&dev_priv->last_fence_retired);
30672+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
30673 DRM_WAKEUP(&dev_priv->fence_queue);
30674 handled = 1;
30675 }
30676@@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30677 * using fences.
30678 */
30679 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30680- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30681+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30682 - *sequence) <= (1 << 23)));
30683
30684 *sequence = cur_fence;
30685diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30686index 2f11e16..191267e 100644
30687--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30688+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30689@@ -5340,7 +5340,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30690 struct bit_table {
30691 const char id;
30692 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30693-};
30694+} __no_const;
30695
30696 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30697
30698diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30699index b863a3a..c55e0dc 100644
30700--- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30701+++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30702@@ -302,7 +302,7 @@ struct nouveau_exec_engine {
30703 u32 handle, u16 class);
30704 void (*set_tile_region)(struct drm_device *dev, int i);
30705 void (*tlb_flush)(struct drm_device *, int engine);
30706-};
30707+} __no_const;
30708
30709 struct nouveau_instmem_engine {
30710 void *priv;
30711@@ -324,13 +324,13 @@ struct nouveau_instmem_engine {
30712 struct nouveau_mc_engine {
30713 int (*init)(struct drm_device *dev);
30714 void (*takedown)(struct drm_device *dev);
30715-};
30716+} __no_const;
30717
30718 struct nouveau_timer_engine {
30719 int (*init)(struct drm_device *dev);
30720 void (*takedown)(struct drm_device *dev);
30721 uint64_t (*read)(struct drm_device *dev);
30722-};
30723+} __no_const;
30724
30725 struct nouveau_fb_engine {
30726 int num_tiles;
30727@@ -547,7 +547,7 @@ struct nouveau_vram_engine {
30728 void (*put)(struct drm_device *, struct nouveau_mem **);
30729
30730 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30731-};
30732+} __no_const;
30733
30734 struct nouveau_engine {
30735 struct nouveau_instmem_engine instmem;
30736@@ -693,7 +693,7 @@ struct drm_nouveau_private {
30737 struct drm_global_reference mem_global_ref;
30738 struct ttm_bo_global_ref bo_global_ref;
30739 struct ttm_bo_device bdev;
30740- atomic_t validate_sequence;
30741+ atomic_unchecked_t validate_sequence;
30742 int (*move)(struct nouveau_channel *,
30743 struct ttm_buffer_object *,
30744 struct ttm_mem_reg *, struct ttm_mem_reg *);
30745diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30746index 30f5423..abca136 100644
30747--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30748+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30749@@ -319,7 +319,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30750 int trycnt = 0;
30751 int ret, i;
30752
30753- sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30754+ sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30755 retry:
30756 if (++trycnt > 100000) {
30757 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30758diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30759index 19706f0..f257368 100644
30760--- a/drivers/gpu/drm/nouveau/nouveau_state.c
30761+++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30762@@ -490,7 +490,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30763 bool can_switch;
30764
30765 spin_lock(&dev->count_lock);
30766- can_switch = (dev->open_count == 0);
30767+ can_switch = (local_read(&dev->open_count) == 0);
30768 spin_unlock(&dev->count_lock);
30769 return can_switch;
30770 }
30771diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
30772index a9514ea..369d511 100644
30773--- a/drivers/gpu/drm/nouveau/nv50_sor.c
30774+++ b/drivers/gpu/drm/nouveau/nv50_sor.c
30775@@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
30776 }
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 = nv50_sor_dp_link_set,
30782 .train_set = nv50_sor_dp_train_set,
30783 .train_adj = nv50_sor_dp_train_adj
30784diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
30785index c50b075..6b07dfc 100644
30786--- a/drivers/gpu/drm/nouveau/nvd0_display.c
30787+++ b/drivers/gpu/drm/nouveau/nvd0_display.c
30788@@ -1366,7 +1366,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
30789 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
30790
30791 if (nv_encoder->dcb->type == OUTPUT_DP) {
30792- struct dp_train_func func = {
30793+ static struct dp_train_func func = {
30794 .link_set = nvd0_sor_dp_link_set,
30795 .train_set = nvd0_sor_dp_train_set,
30796 .train_adj = nvd0_sor_dp_train_adj
30797diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
30798index bcac90b..53bfc76 100644
30799--- a/drivers/gpu/drm/r128/r128_cce.c
30800+++ b/drivers/gpu/drm/r128/r128_cce.c
30801@@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
30802
30803 /* GH: Simple idle check.
30804 */
30805- atomic_set(&dev_priv->idle_count, 0);
30806+ atomic_set_unchecked(&dev_priv->idle_count, 0);
30807
30808 /* We don't support anything other than bus-mastering ring mode,
30809 * but the ring can be in either AGP or PCI space for the ring
30810diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
30811index 930c71b..499aded 100644
30812--- a/drivers/gpu/drm/r128/r128_drv.h
30813+++ b/drivers/gpu/drm/r128/r128_drv.h
30814@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
30815 int is_pci;
30816 unsigned long cce_buffers_offset;
30817
30818- atomic_t idle_count;
30819+ atomic_unchecked_t idle_count;
30820
30821 int page_flipping;
30822 int current_page;
30823 u32 crtc_offset;
30824 u32 crtc_offset_cntl;
30825
30826- atomic_t vbl_received;
30827+ atomic_unchecked_t vbl_received;
30828
30829 u32 color_fmt;
30830 unsigned int front_offset;
30831diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
30832index 429d5a0..7e899ed 100644
30833--- a/drivers/gpu/drm/r128/r128_irq.c
30834+++ b/drivers/gpu/drm/r128/r128_irq.c
30835@@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
30836 if (crtc != 0)
30837 return 0;
30838
30839- return atomic_read(&dev_priv->vbl_received);
30840+ return atomic_read_unchecked(&dev_priv->vbl_received);
30841 }
30842
30843 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30844@@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
30845 /* VBLANK interrupt */
30846 if (status & R128_CRTC_VBLANK_INT) {
30847 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
30848- atomic_inc(&dev_priv->vbl_received);
30849+ atomic_inc_unchecked(&dev_priv->vbl_received);
30850 drm_handle_vblank(dev, 0);
30851 return IRQ_HANDLED;
30852 }
30853diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
30854index a9e33ce..09edd4b 100644
30855--- a/drivers/gpu/drm/r128/r128_state.c
30856+++ b/drivers/gpu/drm/r128/r128_state.c
30857@@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
30858
30859 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
30860 {
30861- if (atomic_read(&dev_priv->idle_count) == 0)
30862+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
30863 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
30864 else
30865- atomic_set(&dev_priv->idle_count, 0);
30866+ atomic_set_unchecked(&dev_priv->idle_count, 0);
30867 }
30868
30869 #endif
30870diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
30871index 5a82b6b..9e69c73 100644
30872--- a/drivers/gpu/drm/radeon/mkregtable.c
30873+++ b/drivers/gpu/drm/radeon/mkregtable.c
30874@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
30875 regex_t mask_rex;
30876 regmatch_t match[4];
30877 char buf[1024];
30878- size_t end;
30879+ long end;
30880 int len;
30881 int done = 0;
30882 int r;
30883 unsigned o;
30884 struct offset *offset;
30885 char last_reg_s[10];
30886- int last_reg;
30887+ unsigned long last_reg;
30888
30889 if (regcomp
30890 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
30891diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
30892index fefcca5..20a5b90 100644
30893--- a/drivers/gpu/drm/radeon/radeon.h
30894+++ b/drivers/gpu/drm/radeon/radeon.h
30895@@ -743,7 +743,7 @@ struct r600_blit_cp_primitives {
30896 int x2, int y2);
30897 void (*draw_auto)(struct radeon_device *rdev);
30898 void (*set_default_state)(struct radeon_device *rdev);
30899-};
30900+} __no_const;
30901
30902 struct r600_blit {
30903 struct radeon_bo *shader_obj;
30904@@ -1244,7 +1244,7 @@ struct radeon_asic {
30905 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
30906 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
30907 } pflip;
30908-};
30909+} __no_const;
30910
30911 /*
30912 * Asic structures
30913diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
30914index 066c98b..96ab858 100644
30915--- a/drivers/gpu/drm/radeon/radeon_device.c
30916+++ b/drivers/gpu/drm/radeon/radeon_device.c
30917@@ -692,7 +692,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
30918 bool can_switch;
30919
30920 spin_lock(&dev->count_lock);
30921- can_switch = (dev->open_count == 0);
30922+ can_switch = (local_read(&dev->open_count) == 0);
30923 spin_unlock(&dev->count_lock);
30924 return can_switch;
30925 }
30926diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
30927index a1b59ca..86f2d44 100644
30928--- a/drivers/gpu/drm/radeon/radeon_drv.h
30929+++ b/drivers/gpu/drm/radeon/radeon_drv.h
30930@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
30931
30932 /* SW interrupt */
30933 wait_queue_head_t swi_queue;
30934- atomic_t swi_emitted;
30935+ atomic_unchecked_t swi_emitted;
30936 int vblank_crtc;
30937 uint32_t irq_enable_reg;
30938 uint32_t r500_disp_irq_reg;
30939diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
30940index 48b7cea..342236f 100644
30941--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
30942+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
30943@@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
30944 request = compat_alloc_user_space(sizeof(*request));
30945 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
30946 || __put_user(req32.param, &request->param)
30947- || __put_user((void __user *)(unsigned long)req32.value,
30948+ || __put_user((unsigned long)req32.value,
30949 &request->value))
30950 return -EFAULT;
30951
30952diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
30953index 00da384..32f972d 100644
30954--- a/drivers/gpu/drm/radeon/radeon_irq.c
30955+++ b/drivers/gpu/drm/radeon/radeon_irq.c
30956@@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
30957 unsigned int ret;
30958 RING_LOCALS;
30959
30960- atomic_inc(&dev_priv->swi_emitted);
30961- ret = atomic_read(&dev_priv->swi_emitted);
30962+ atomic_inc_unchecked(&dev_priv->swi_emitted);
30963+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
30964
30965 BEGIN_RING(4);
30966 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
30967@@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
30968 drm_radeon_private_t *dev_priv =
30969 (drm_radeon_private_t *) dev->dev_private;
30970
30971- atomic_set(&dev_priv->swi_emitted, 0);
30972+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
30973 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
30974
30975 dev->max_vblank_count = 0x001fffff;
30976diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
30977index e8422ae..d22d4a8 100644
30978--- a/drivers/gpu/drm/radeon/radeon_state.c
30979+++ b/drivers/gpu/drm/radeon/radeon_state.c
30980@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
30981 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
30982 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
30983
30984- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30985+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
30986 sarea_priv->nbox * sizeof(depth_boxes[0])))
30987 return -EFAULT;
30988
30989@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
30990 {
30991 drm_radeon_private_t *dev_priv = dev->dev_private;
30992 drm_radeon_getparam_t *param = data;
30993- int value;
30994+ int value = 0;
30995
30996 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
30997
30998diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
30999index c94a225..5795d34 100644
31000--- a/drivers/gpu/drm/radeon/radeon_ttm.c
31001+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
31002@@ -852,8 +852,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
31003 }
31004 if (unlikely(ttm_vm_ops == NULL)) {
31005 ttm_vm_ops = vma->vm_ops;
31006- radeon_ttm_vm_ops = *ttm_vm_ops;
31007- radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31008+ pax_open_kernel();
31009+ memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
31010+ *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31011+ pax_close_kernel();
31012 }
31013 vma->vm_ops = &radeon_ttm_vm_ops;
31014 return 0;
31015diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31016index 159b6a4..fa82487 100644
31017--- a/drivers/gpu/drm/radeon/rs690.c
31018+++ b/drivers/gpu/drm/radeon/rs690.c
31019@@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31020 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31021 rdev->pm.sideport_bandwidth.full)
31022 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31023- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31024+ read_delay_latency.full = dfixed_const(800 * 1000);
31025 read_delay_latency.full = dfixed_div(read_delay_latency,
31026 rdev->pm.igp_sideport_mclk);
31027+ a.full = dfixed_const(370);
31028+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31029 } else {
31030 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31031 rdev->pm.k8_bandwidth.full)
31032diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31033index ebc6fac..a8313ed 100644
31034--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31035+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31036@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
31037 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31038 struct shrink_control *sc)
31039 {
31040- static atomic_t start_pool = ATOMIC_INIT(0);
31041+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31042 unsigned i;
31043- unsigned pool_offset = atomic_add_return(1, &start_pool);
31044+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31045 struct ttm_page_pool *pool;
31046 int shrink_pages = sc->nr_to_scan;
31047
31048diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31049index 88edacc..1e5412b 100644
31050--- a/drivers/gpu/drm/via/via_drv.h
31051+++ b/drivers/gpu/drm/via/via_drv.h
31052@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31053 typedef uint32_t maskarray_t[5];
31054
31055 typedef struct drm_via_irq {
31056- atomic_t irq_received;
31057+ atomic_unchecked_t irq_received;
31058 uint32_t pending_mask;
31059 uint32_t enable_mask;
31060 wait_queue_head_t irq_queue;
31061@@ -75,7 +75,7 @@ typedef struct drm_via_private {
31062 struct timeval last_vblank;
31063 int last_vblank_valid;
31064 unsigned usec_per_vblank;
31065- atomic_t vbl_received;
31066+ atomic_unchecked_t vbl_received;
31067 drm_via_state_t hc_state;
31068 char pci_buf[VIA_PCI_BUF_SIZE];
31069 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31070diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31071index d391f48..10c8ca3 100644
31072--- a/drivers/gpu/drm/via/via_irq.c
31073+++ b/drivers/gpu/drm/via/via_irq.c
31074@@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31075 if (crtc != 0)
31076 return 0;
31077
31078- return atomic_read(&dev_priv->vbl_received);
31079+ return atomic_read_unchecked(&dev_priv->vbl_received);
31080 }
31081
31082 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31083@@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31084
31085 status = VIA_READ(VIA_REG_INTERRUPT);
31086 if (status & VIA_IRQ_VBLANK_PENDING) {
31087- atomic_inc(&dev_priv->vbl_received);
31088- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31089+ atomic_inc_unchecked(&dev_priv->vbl_received);
31090+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31091 do_gettimeofday(&cur_vblank);
31092 if (dev_priv->last_vblank_valid) {
31093 dev_priv->usec_per_vblank =
31094@@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31095 dev_priv->last_vblank = cur_vblank;
31096 dev_priv->last_vblank_valid = 1;
31097 }
31098- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31099+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31100 DRM_DEBUG("US per vblank is: %u\n",
31101 dev_priv->usec_per_vblank);
31102 }
31103@@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31104
31105 for (i = 0; i < dev_priv->num_irqs; ++i) {
31106 if (status & cur_irq->pending_mask) {
31107- atomic_inc(&cur_irq->irq_received);
31108+ atomic_inc_unchecked(&cur_irq->irq_received);
31109 DRM_WAKEUP(&cur_irq->irq_queue);
31110 handled = 1;
31111 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31112@@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31113 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31114 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31115 masks[irq][4]));
31116- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31117+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31118 } else {
31119 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31120 (((cur_irq_sequence =
31121- atomic_read(&cur_irq->irq_received)) -
31122+ atomic_read_unchecked(&cur_irq->irq_received)) -
31123 *sequence) <= (1 << 23)));
31124 }
31125 *sequence = cur_irq_sequence;
31126@@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31127 }
31128
31129 for (i = 0; i < dev_priv->num_irqs; ++i) {
31130- atomic_set(&cur_irq->irq_received, 0);
31131+ atomic_set_unchecked(&cur_irq->irq_received, 0);
31132 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31133 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31134 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31135@@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31136 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31137 case VIA_IRQ_RELATIVE:
31138 irqwait->request.sequence +=
31139- atomic_read(&cur_irq->irq_received);
31140+ atomic_read_unchecked(&cur_irq->irq_received);
31141 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31142 case VIA_IRQ_ABSOLUTE:
31143 break;
31144diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31145index d0f2c07..9ebd9c3 100644
31146--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31147+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31148@@ -263,7 +263,7 @@ struct vmw_private {
31149 * Fencing and IRQs.
31150 */
31151
31152- atomic_t marker_seq;
31153+ atomic_unchecked_t marker_seq;
31154 wait_queue_head_t fence_queue;
31155 wait_queue_head_t fifo_queue;
31156 int fence_queue_waiters; /* Protected by hw_mutex */
31157diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31158index a0c2f12..68ae6cb 100644
31159--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31160+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31161@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31162 (unsigned int) min,
31163 (unsigned int) fifo->capabilities);
31164
31165- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31166+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31167 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31168 vmw_marker_queue_init(&fifo->marker_queue);
31169 return vmw_fifo_send_fence(dev_priv, &dummy);
31170@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31171 if (reserveable)
31172 iowrite32(bytes, fifo_mem +
31173 SVGA_FIFO_RESERVED);
31174- return fifo_mem + (next_cmd >> 2);
31175+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31176 } else {
31177 need_bounce = true;
31178 }
31179@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31180
31181 fm = vmw_fifo_reserve(dev_priv, bytes);
31182 if (unlikely(fm == NULL)) {
31183- *seqno = atomic_read(&dev_priv->marker_seq);
31184+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31185 ret = -ENOMEM;
31186 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31187 false, 3*HZ);
31188@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31189 }
31190
31191 do {
31192- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31193+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31194 } while (*seqno == 0);
31195
31196 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31197diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31198index cabc95f..14b3d77 100644
31199--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31200+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31201@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31202 * emitted. Then the fence is stale and signaled.
31203 */
31204
31205- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31206+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31207 > VMW_FENCE_WRAP);
31208
31209 return ret;
31210@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31211
31212 if (fifo_idle)
31213 down_read(&fifo_state->rwsem);
31214- signal_seq = atomic_read(&dev_priv->marker_seq);
31215+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31216 ret = 0;
31217
31218 for (;;) {
31219diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31220index 8a8725c..afed796 100644
31221--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31222+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31223@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31224 while (!vmw_lag_lt(queue, us)) {
31225 spin_lock(&queue->lock);
31226 if (list_empty(&queue->head))
31227- seqno = atomic_read(&dev_priv->marker_seq);
31228+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31229 else {
31230 marker = list_first_entry(&queue->head,
31231 struct vmw_marker, head);
31232diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31233index 1f6957c..b579481 100644
31234--- a/drivers/hid/hid-core.c
31235+++ b/drivers/hid/hid-core.c
31236@@ -2153,7 +2153,7 @@ static bool hid_ignore(struct hid_device *hdev)
31237
31238 int hid_add_device(struct hid_device *hdev)
31239 {
31240- static atomic_t id = ATOMIC_INIT(0);
31241+ static atomic_unchecked_t id = ATOMIC_INIT(0);
31242 int ret;
31243
31244 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31245@@ -2188,7 +2188,7 @@ int hid_add_device(struct hid_device *hdev)
31246 /* XXX hack, any other cleaner solution after the driver core
31247 * is converted to allow more than 20 bytes as the device name? */
31248 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31249- hdev->vendor, hdev->product, atomic_inc_return(&id));
31250+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31251
31252 hid_debug_register(hdev, dev_name(&hdev->dev));
31253 ret = device_add(&hdev->dev);
31254diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31255index eec3291..8ed706b 100644
31256--- a/drivers/hid/hid-wiimote-debug.c
31257+++ b/drivers/hid/hid-wiimote-debug.c
31258@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31259 else if (size == 0)
31260 return -EIO;
31261
31262- if (copy_to_user(u, buf, size))
31263+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
31264 return -EFAULT;
31265
31266 *off += size;
31267diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31268index 14599e2..711c965 100644
31269--- a/drivers/hid/usbhid/hiddev.c
31270+++ b/drivers/hid/usbhid/hiddev.c
31271@@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31272 break;
31273
31274 case HIDIOCAPPLICATION:
31275- if (arg < 0 || arg >= hid->maxapplication)
31276+ if (arg >= hid->maxapplication)
31277 break;
31278
31279 for (i = 0; i < hid->maxcollection; i++)
31280diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31281index 4065374..10ed7dc 100644
31282--- a/drivers/hv/channel.c
31283+++ b/drivers/hv/channel.c
31284@@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31285 int ret = 0;
31286 int t;
31287
31288- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31289- atomic_inc(&vmbus_connection.next_gpadl_handle);
31290+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31291+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31292
31293 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31294 if (ret)
31295diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31296index 86f8885..ab9cb2b 100644
31297--- a/drivers/hv/hv.c
31298+++ b/drivers/hv/hv.c
31299@@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31300 u64 output_address = (output) ? virt_to_phys(output) : 0;
31301 u32 output_address_hi = output_address >> 32;
31302 u32 output_address_lo = output_address & 0xFFFFFFFF;
31303- void *hypercall_page = hv_context.hypercall_page;
31304+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31305
31306 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31307 "=a"(hv_status_lo) : "d" (control_hi),
31308diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31309index b9426a6..677ce34 100644
31310--- a/drivers/hv/hyperv_vmbus.h
31311+++ b/drivers/hv/hyperv_vmbus.h
31312@@ -555,7 +555,7 @@ enum vmbus_connect_state {
31313 struct vmbus_connection {
31314 enum vmbus_connect_state conn_state;
31315
31316- atomic_t next_gpadl_handle;
31317+ atomic_unchecked_t next_gpadl_handle;
31318
31319 /*
31320 * Represents channel interrupts. Each bit position represents a
31321diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31322index a220e57..428f54d 100644
31323--- a/drivers/hv/vmbus_drv.c
31324+++ b/drivers/hv/vmbus_drv.c
31325@@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31326 {
31327 int ret = 0;
31328
31329- static atomic_t device_num = ATOMIC_INIT(0);
31330+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31331
31332 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31333- atomic_inc_return(&device_num));
31334+ atomic_inc_return_unchecked(&device_num));
31335
31336 child_device_obj->device.bus = &hv_bus;
31337 child_device_obj->device.parent = &hv_acpi_dev->dev;
31338diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
31339index 34ad5a2..e2b0ae8 100644
31340--- a/drivers/hwmon/acpi_power_meter.c
31341+++ b/drivers/hwmon/acpi_power_meter.c
31342@@ -308,8 +308,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
31343 return res;
31344
31345 temp /= 1000;
31346- if (temp < 0)
31347- return -EINVAL;
31348
31349 mutex_lock(&resource->lock);
31350 resource->trip[attr->index - 7] = temp;
31351diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31352index 8b011d0..3de24a1 100644
31353--- a/drivers/hwmon/sht15.c
31354+++ b/drivers/hwmon/sht15.c
31355@@ -166,7 +166,7 @@ struct sht15_data {
31356 int supply_uV;
31357 bool supply_uV_valid;
31358 struct work_struct update_supply_work;
31359- atomic_t interrupt_handled;
31360+ atomic_unchecked_t interrupt_handled;
31361 };
31362
31363 /**
31364@@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31365 return ret;
31366
31367 gpio_direction_input(data->pdata->gpio_data);
31368- atomic_set(&data->interrupt_handled, 0);
31369+ atomic_set_unchecked(&data->interrupt_handled, 0);
31370
31371 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31372 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31373 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31374 /* Only relevant if the interrupt hasn't occurred. */
31375- if (!atomic_read(&data->interrupt_handled))
31376+ if (!atomic_read_unchecked(&data->interrupt_handled))
31377 schedule_work(&data->read_work);
31378 }
31379 ret = wait_event_timeout(data->wait_queue,
31380@@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31381
31382 /* First disable the interrupt */
31383 disable_irq_nosync(irq);
31384- atomic_inc(&data->interrupt_handled);
31385+ atomic_inc_unchecked(&data->interrupt_handled);
31386 /* Then schedule a reading work struct */
31387 if (data->state != SHT15_READING_NOTHING)
31388 schedule_work(&data->read_work);
31389@@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31390 * If not, then start the interrupt again - care here as could
31391 * have gone low in meantime so verify it hasn't!
31392 */
31393- atomic_set(&data->interrupt_handled, 0);
31394+ atomic_set_unchecked(&data->interrupt_handled, 0);
31395 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31396 /* If still not occurred or another handler was scheduled */
31397 if (gpio_get_value(data->pdata->gpio_data)
31398- || atomic_read(&data->interrupt_handled))
31399+ || atomic_read_unchecked(&data->interrupt_handled))
31400 return;
31401 }
31402
31403diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31404index 378fcb5..5e91fa8 100644
31405--- a/drivers/i2c/busses/i2c-amd756-s4882.c
31406+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31407@@ -43,7 +43,7 @@
31408 extern struct i2c_adapter amd756_smbus;
31409
31410 static struct i2c_adapter *s4882_adapter;
31411-static struct i2c_algorithm *s4882_algo;
31412+static i2c_algorithm_no_const *s4882_algo;
31413
31414 /* Wrapper access functions for multiplexed SMBus */
31415 static DEFINE_MUTEX(amd756_lock);
31416diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31417index 29015eb..af2d8e9 100644
31418--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31419+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31420@@ -41,7 +41,7 @@
31421 extern struct i2c_adapter *nforce2_smbus;
31422
31423 static struct i2c_adapter *s4985_adapter;
31424-static struct i2c_algorithm *s4985_algo;
31425+static i2c_algorithm_no_const *s4985_algo;
31426
31427 /* Wrapper access functions for multiplexed SMBus */
31428 static DEFINE_MUTEX(nforce2_lock);
31429diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31430index 1038c38..eb92f51 100644
31431--- a/drivers/i2c/i2c-mux.c
31432+++ b/drivers/i2c/i2c-mux.c
31433@@ -30,7 +30,7 @@
31434 /* multiplexer per channel data */
31435 struct i2c_mux_priv {
31436 struct i2c_adapter adap;
31437- struct i2c_algorithm algo;
31438+ i2c_algorithm_no_const algo;
31439
31440 struct i2c_adapter *parent;
31441 void *mux_priv; /* the mux chip/device */
31442diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31443index 57d00ca..0145194 100644
31444--- a/drivers/ide/aec62xx.c
31445+++ b/drivers/ide/aec62xx.c
31446@@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31447 .cable_detect = atp86x_cable_detect,
31448 };
31449
31450-static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31451+static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31452 { /* 0: AEC6210 */
31453 .name = DRV_NAME,
31454 .init_chipset = init_chipset_aec62xx,
31455diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31456index 2c8016a..911a27c 100644
31457--- a/drivers/ide/alim15x3.c
31458+++ b/drivers/ide/alim15x3.c
31459@@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31460 .dma_sff_read_status = ide_dma_sff_read_status,
31461 };
31462
31463-static const struct ide_port_info ali15x3_chipset __devinitdata = {
31464+static const struct ide_port_info ali15x3_chipset __devinitconst = {
31465 .name = DRV_NAME,
31466 .init_chipset = init_chipset_ali15x3,
31467 .init_hwif = init_hwif_ali15x3,
31468diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31469index 3747b25..56fc995 100644
31470--- a/drivers/ide/amd74xx.c
31471+++ b/drivers/ide/amd74xx.c
31472@@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31473 .udma_mask = udma, \
31474 }
31475
31476-static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31477+static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31478 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31479 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31480 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31481diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31482index 15f0ead..cb43480 100644
31483--- a/drivers/ide/atiixp.c
31484+++ b/drivers/ide/atiixp.c
31485@@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31486 .cable_detect = atiixp_cable_detect,
31487 };
31488
31489-static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31490+static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31491 { /* 0: IXP200/300/400/700 */
31492 .name = DRV_NAME,
31493 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31494diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31495index 5f80312..d1fc438 100644
31496--- a/drivers/ide/cmd64x.c
31497+++ b/drivers/ide/cmd64x.c
31498@@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31499 .dma_sff_read_status = ide_dma_sff_read_status,
31500 };
31501
31502-static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31503+static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31504 { /* 0: CMD643 */
31505 .name = DRV_NAME,
31506 .init_chipset = init_chipset_cmd64x,
31507diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31508index 2c1e5f7..1444762 100644
31509--- a/drivers/ide/cs5520.c
31510+++ b/drivers/ide/cs5520.c
31511@@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31512 .set_dma_mode = cs5520_set_dma_mode,
31513 };
31514
31515-static const struct ide_port_info cyrix_chipset __devinitdata = {
31516+static const struct ide_port_info cyrix_chipset __devinitconst = {
31517 .name = DRV_NAME,
31518 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31519 .port_ops = &cs5520_port_ops,
31520diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31521index 4dc4eb9..49b40ad 100644
31522--- a/drivers/ide/cs5530.c
31523+++ b/drivers/ide/cs5530.c
31524@@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31525 .udma_filter = cs5530_udma_filter,
31526 };
31527
31528-static const struct ide_port_info cs5530_chipset __devinitdata = {
31529+static const struct ide_port_info cs5530_chipset __devinitconst = {
31530 .name = DRV_NAME,
31531 .init_chipset = init_chipset_cs5530,
31532 .init_hwif = init_hwif_cs5530,
31533diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31534index 5059faf..18d4c85 100644
31535--- a/drivers/ide/cs5535.c
31536+++ b/drivers/ide/cs5535.c
31537@@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31538 .cable_detect = cs5535_cable_detect,
31539 };
31540
31541-static const struct ide_port_info cs5535_chipset __devinitdata = {
31542+static const struct ide_port_info cs5535_chipset __devinitconst = {
31543 .name = DRV_NAME,
31544 .port_ops = &cs5535_port_ops,
31545 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31546diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31547index 847553f..3ffb49d 100644
31548--- a/drivers/ide/cy82c693.c
31549+++ b/drivers/ide/cy82c693.c
31550@@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31551 .set_dma_mode = cy82c693_set_dma_mode,
31552 };
31553
31554-static const struct ide_port_info cy82c693_chipset __devinitdata = {
31555+static const struct ide_port_info cy82c693_chipset __devinitconst = {
31556 .name = DRV_NAME,
31557 .init_iops = init_iops_cy82c693,
31558 .port_ops = &cy82c693_port_ops,
31559diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31560index 58c51cd..4aec3b8 100644
31561--- a/drivers/ide/hpt366.c
31562+++ b/drivers/ide/hpt366.c
31563@@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31564 }
31565 };
31566
31567-static const struct hpt_info hpt36x __devinitdata = {
31568+static const struct hpt_info hpt36x __devinitconst = {
31569 .chip_name = "HPT36x",
31570 .chip_type = HPT36x,
31571 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31572@@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31573 .timings = &hpt36x_timings
31574 };
31575
31576-static const struct hpt_info hpt370 __devinitdata = {
31577+static const struct hpt_info hpt370 __devinitconst = {
31578 .chip_name = "HPT370",
31579 .chip_type = HPT370,
31580 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31581@@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31582 .timings = &hpt37x_timings
31583 };
31584
31585-static const struct hpt_info hpt370a __devinitdata = {
31586+static const struct hpt_info hpt370a __devinitconst = {
31587 .chip_name = "HPT370A",
31588 .chip_type = HPT370A,
31589 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31590@@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31591 .timings = &hpt37x_timings
31592 };
31593
31594-static const struct hpt_info hpt374 __devinitdata = {
31595+static const struct hpt_info hpt374 __devinitconst = {
31596 .chip_name = "HPT374",
31597 .chip_type = HPT374,
31598 .udma_mask = ATA_UDMA5,
31599@@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31600 .timings = &hpt37x_timings
31601 };
31602
31603-static const struct hpt_info hpt372 __devinitdata = {
31604+static const struct hpt_info hpt372 __devinitconst = {
31605 .chip_name = "HPT372",
31606 .chip_type = HPT372,
31607 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31608@@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31609 .timings = &hpt37x_timings
31610 };
31611
31612-static const struct hpt_info hpt372a __devinitdata = {
31613+static const struct hpt_info hpt372a __devinitconst = {
31614 .chip_name = "HPT372A",
31615 .chip_type = HPT372A,
31616 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31617@@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31618 .timings = &hpt37x_timings
31619 };
31620
31621-static const struct hpt_info hpt302 __devinitdata = {
31622+static const struct hpt_info hpt302 __devinitconst = {
31623 .chip_name = "HPT302",
31624 .chip_type = HPT302,
31625 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31626@@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31627 .timings = &hpt37x_timings
31628 };
31629
31630-static const struct hpt_info hpt371 __devinitdata = {
31631+static const struct hpt_info hpt371 __devinitconst = {
31632 .chip_name = "HPT371",
31633 .chip_type = HPT371,
31634 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31635@@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31636 .timings = &hpt37x_timings
31637 };
31638
31639-static const struct hpt_info hpt372n __devinitdata = {
31640+static const struct hpt_info hpt372n __devinitconst = {
31641 .chip_name = "HPT372N",
31642 .chip_type = HPT372N,
31643 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31644@@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31645 .timings = &hpt37x_timings
31646 };
31647
31648-static const struct hpt_info hpt302n __devinitdata = {
31649+static const struct hpt_info hpt302n __devinitconst = {
31650 .chip_name = "HPT302N",
31651 .chip_type = HPT302N,
31652 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31653@@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31654 .timings = &hpt37x_timings
31655 };
31656
31657-static const struct hpt_info hpt371n __devinitdata = {
31658+static const struct hpt_info hpt371n __devinitconst = {
31659 .chip_name = "HPT371N",
31660 .chip_type = HPT371N,
31661 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31662@@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31663 .dma_sff_read_status = ide_dma_sff_read_status,
31664 };
31665
31666-static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31667+static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31668 { /* 0: HPT36x */
31669 .name = DRV_NAME,
31670 .init_chipset = init_chipset_hpt366,
31671diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31672index 8126824..55a2798 100644
31673--- a/drivers/ide/ide-cd.c
31674+++ b/drivers/ide/ide-cd.c
31675@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31676 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31677 if ((unsigned long)buf & alignment
31678 || blk_rq_bytes(rq) & q->dma_pad_mask
31679- || object_is_on_stack(buf))
31680+ || object_starts_on_stack(buf))
31681 drive->dma = 0;
31682 }
31683 }
31684diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31685index 7f56b73..dab5b67 100644
31686--- a/drivers/ide/ide-pci-generic.c
31687+++ b/drivers/ide/ide-pci-generic.c
31688@@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31689 .udma_mask = ATA_UDMA6, \
31690 }
31691
31692-static const struct ide_port_info generic_chipsets[] __devinitdata = {
31693+static const struct ide_port_info generic_chipsets[] __devinitconst = {
31694 /* 0: Unknown */
31695 DECLARE_GENERIC_PCI_DEV(0),
31696
31697diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31698index 560e66d..d5dd180 100644
31699--- a/drivers/ide/it8172.c
31700+++ b/drivers/ide/it8172.c
31701@@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31702 .set_dma_mode = it8172_set_dma_mode,
31703 };
31704
31705-static const struct ide_port_info it8172_port_info __devinitdata = {
31706+static const struct ide_port_info it8172_port_info __devinitconst = {
31707 .name = DRV_NAME,
31708 .port_ops = &it8172_port_ops,
31709 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31710diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31711index 46816ba..1847aeb 100644
31712--- a/drivers/ide/it8213.c
31713+++ b/drivers/ide/it8213.c
31714@@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31715 .cable_detect = it8213_cable_detect,
31716 };
31717
31718-static const struct ide_port_info it8213_chipset __devinitdata = {
31719+static const struct ide_port_info it8213_chipset __devinitconst = {
31720 .name = DRV_NAME,
31721 .enablebits = { {0x41, 0x80, 0x80} },
31722 .port_ops = &it8213_port_ops,
31723diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31724index 2e3169f..c5611db 100644
31725--- a/drivers/ide/it821x.c
31726+++ b/drivers/ide/it821x.c
31727@@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31728 .cable_detect = it821x_cable_detect,
31729 };
31730
31731-static const struct ide_port_info it821x_chipset __devinitdata = {
31732+static const struct ide_port_info it821x_chipset __devinitconst = {
31733 .name = DRV_NAME,
31734 .init_chipset = init_chipset_it821x,
31735 .init_hwif = init_hwif_it821x,
31736diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31737index 74c2c4a..efddd7d 100644
31738--- a/drivers/ide/jmicron.c
31739+++ b/drivers/ide/jmicron.c
31740@@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31741 .cable_detect = jmicron_cable_detect,
31742 };
31743
31744-static const struct ide_port_info jmicron_chipset __devinitdata = {
31745+static const struct ide_port_info jmicron_chipset __devinitconst = {
31746 .name = DRV_NAME,
31747 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31748 .port_ops = &jmicron_port_ops,
31749diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31750index 95327a2..73f78d8 100644
31751--- a/drivers/ide/ns87415.c
31752+++ b/drivers/ide/ns87415.c
31753@@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31754 .dma_sff_read_status = superio_dma_sff_read_status,
31755 };
31756
31757-static const struct ide_port_info ns87415_chipset __devinitdata = {
31758+static const struct ide_port_info ns87415_chipset __devinitconst = {
31759 .name = DRV_NAME,
31760 .init_hwif = init_hwif_ns87415,
31761 .tp_ops = &ns87415_tp_ops,
31762diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31763index 1a53a4c..39edc66 100644
31764--- a/drivers/ide/opti621.c
31765+++ b/drivers/ide/opti621.c
31766@@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31767 .set_pio_mode = opti621_set_pio_mode,
31768 };
31769
31770-static const struct ide_port_info opti621_chipset __devinitdata = {
31771+static const struct ide_port_info opti621_chipset __devinitconst = {
31772 .name = DRV_NAME,
31773 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31774 .port_ops = &opti621_port_ops,
31775diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31776index 9546fe2..2e5ceb6 100644
31777--- a/drivers/ide/pdc202xx_new.c
31778+++ b/drivers/ide/pdc202xx_new.c
31779@@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
31780 .udma_mask = udma, \
31781 }
31782
31783-static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
31784+static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
31785 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
31786 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
31787 };
31788diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
31789index 3a35ec6..5634510 100644
31790--- a/drivers/ide/pdc202xx_old.c
31791+++ b/drivers/ide/pdc202xx_old.c
31792@@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
31793 .max_sectors = sectors, \
31794 }
31795
31796-static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
31797+static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
31798 { /* 0: PDC20246 */
31799 .name = DRV_NAME,
31800 .init_chipset = init_chipset_pdc202xx,
31801diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
31802index 1892e81..fe0fd60 100644
31803--- a/drivers/ide/piix.c
31804+++ b/drivers/ide/piix.c
31805@@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
31806 .udma_mask = udma, \
31807 }
31808
31809-static const struct ide_port_info piix_pci_info[] __devinitdata = {
31810+static const struct ide_port_info piix_pci_info[] __devinitconst = {
31811 /* 0: MPIIX */
31812 { /*
31813 * MPIIX actually has only a single IDE channel mapped to
31814diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
31815index a6414a8..c04173e 100644
31816--- a/drivers/ide/rz1000.c
31817+++ b/drivers/ide/rz1000.c
31818@@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
31819 }
31820 }
31821
31822-static const struct ide_port_info rz1000_chipset __devinitdata = {
31823+static const struct ide_port_info rz1000_chipset __devinitconst = {
31824 .name = DRV_NAME,
31825 .host_flags = IDE_HFLAG_NO_DMA,
31826 };
31827diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
31828index 356b9b5..d4758eb 100644
31829--- a/drivers/ide/sc1200.c
31830+++ b/drivers/ide/sc1200.c
31831@@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
31832 .dma_sff_read_status = ide_dma_sff_read_status,
31833 };
31834
31835-static const struct ide_port_info sc1200_chipset __devinitdata = {
31836+static const struct ide_port_info sc1200_chipset __devinitconst = {
31837 .name = DRV_NAME,
31838 .port_ops = &sc1200_port_ops,
31839 .dma_ops = &sc1200_dma_ops,
31840diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
31841index b7f5b0c..9701038 100644
31842--- a/drivers/ide/scc_pata.c
31843+++ b/drivers/ide/scc_pata.c
31844@@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
31845 .dma_sff_read_status = scc_dma_sff_read_status,
31846 };
31847
31848-static const struct ide_port_info scc_chipset __devinitdata = {
31849+static const struct ide_port_info scc_chipset __devinitconst = {
31850 .name = "sccIDE",
31851 .init_iops = init_iops_scc,
31852 .init_dma = scc_init_dma,
31853diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
31854index 35fb8da..24d72ef 100644
31855--- a/drivers/ide/serverworks.c
31856+++ b/drivers/ide/serverworks.c
31857@@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
31858 .cable_detect = svwks_cable_detect,
31859 };
31860
31861-static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
31862+static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
31863 { /* 0: OSB4 */
31864 .name = DRV_NAME,
31865 .init_chipset = init_chipset_svwks,
31866diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
31867index ddeda44..46f7e30 100644
31868--- a/drivers/ide/siimage.c
31869+++ b/drivers/ide/siimage.c
31870@@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
31871 .udma_mask = ATA_UDMA6, \
31872 }
31873
31874-static const struct ide_port_info siimage_chipsets[] __devinitdata = {
31875+static const struct ide_port_info siimage_chipsets[] __devinitconst = {
31876 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
31877 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
31878 };
31879diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
31880index 4a00225..09e61b4 100644
31881--- a/drivers/ide/sis5513.c
31882+++ b/drivers/ide/sis5513.c
31883@@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
31884 .cable_detect = sis_cable_detect,
31885 };
31886
31887-static const struct ide_port_info sis5513_chipset __devinitdata = {
31888+static const struct ide_port_info sis5513_chipset __devinitconst = {
31889 .name = DRV_NAME,
31890 .init_chipset = init_chipset_sis5513,
31891 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
31892diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
31893index f21dc2a..d051cd2 100644
31894--- a/drivers/ide/sl82c105.c
31895+++ b/drivers/ide/sl82c105.c
31896@@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
31897 .dma_sff_read_status = ide_dma_sff_read_status,
31898 };
31899
31900-static const struct ide_port_info sl82c105_chipset __devinitdata = {
31901+static const struct ide_port_info sl82c105_chipset __devinitconst = {
31902 .name = DRV_NAME,
31903 .init_chipset = init_chipset_sl82c105,
31904 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
31905diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
31906index 864ffe0..863a5e9 100644
31907--- a/drivers/ide/slc90e66.c
31908+++ b/drivers/ide/slc90e66.c
31909@@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
31910 .cable_detect = slc90e66_cable_detect,
31911 };
31912
31913-static const struct ide_port_info slc90e66_chipset __devinitdata = {
31914+static const struct ide_port_info slc90e66_chipset __devinitconst = {
31915 .name = DRV_NAME,
31916 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
31917 .port_ops = &slc90e66_port_ops,
31918diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
31919index 4799d5c..1794678 100644
31920--- a/drivers/ide/tc86c001.c
31921+++ b/drivers/ide/tc86c001.c
31922@@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
31923 .dma_sff_read_status = ide_dma_sff_read_status,
31924 };
31925
31926-static const struct ide_port_info tc86c001_chipset __devinitdata = {
31927+static const struct ide_port_info tc86c001_chipset __devinitconst = {
31928 .name = DRV_NAME,
31929 .init_hwif = init_hwif_tc86c001,
31930 .port_ops = &tc86c001_port_ops,
31931diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
31932index 281c914..55ce1b8 100644
31933--- a/drivers/ide/triflex.c
31934+++ b/drivers/ide/triflex.c
31935@@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
31936 .set_dma_mode = triflex_set_mode,
31937 };
31938
31939-static const struct ide_port_info triflex_device __devinitdata = {
31940+static const struct ide_port_info triflex_device __devinitconst = {
31941 .name = DRV_NAME,
31942 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
31943 .port_ops = &triflex_port_ops,
31944diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
31945index 4b42ca0..e494a98 100644
31946--- a/drivers/ide/trm290.c
31947+++ b/drivers/ide/trm290.c
31948@@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
31949 .dma_check = trm290_dma_check,
31950 };
31951
31952-static const struct ide_port_info trm290_chipset __devinitdata = {
31953+static const struct ide_port_info trm290_chipset __devinitconst = {
31954 .name = DRV_NAME,
31955 .init_hwif = init_hwif_trm290,
31956 .tp_ops = &trm290_tp_ops,
31957diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
31958index f46f49c..eb77678 100644
31959--- a/drivers/ide/via82cxxx.c
31960+++ b/drivers/ide/via82cxxx.c
31961@@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
31962 .cable_detect = via82cxxx_cable_detect,
31963 };
31964
31965-static const struct ide_port_info via82cxxx_chipset __devinitdata = {
31966+static const struct ide_port_info via82cxxx_chipset __devinitconst = {
31967 .name = DRV_NAME,
31968 .init_chipset = init_chipset_via82cxxx,
31969 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
31970diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
31971index 73d4531..c90cd2d 100644
31972--- a/drivers/ieee802154/fakehard.c
31973+++ b/drivers/ieee802154/fakehard.c
31974@@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
31975 phy->transmit_power = 0xbf;
31976
31977 dev->netdev_ops = &fake_ops;
31978- dev->ml_priv = &fake_mlme;
31979+ dev->ml_priv = (void *)&fake_mlme;
31980
31981 priv = netdev_priv(dev);
31982 priv->phy = phy;
31983diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
31984index c889aae..6cf5aa7 100644
31985--- a/drivers/infiniband/core/cm.c
31986+++ b/drivers/infiniband/core/cm.c
31987@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
31988
31989 struct cm_counter_group {
31990 struct kobject obj;
31991- atomic_long_t counter[CM_ATTR_COUNT];
31992+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
31993 };
31994
31995 struct cm_counter_attribute {
31996@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
31997 struct ib_mad_send_buf *msg = NULL;
31998 int ret;
31999
32000- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32001+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32002 counter[CM_REQ_COUNTER]);
32003
32004 /* Quick state check to discard duplicate REQs. */
32005@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
32006 if (!cm_id_priv)
32007 return;
32008
32009- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32010+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32011 counter[CM_REP_COUNTER]);
32012 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
32013 if (ret)
32014@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32015 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32016 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32017 spin_unlock_irq(&cm_id_priv->lock);
32018- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32019+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32020 counter[CM_RTU_COUNTER]);
32021 goto out;
32022 }
32023@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32024 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32025 dreq_msg->local_comm_id);
32026 if (!cm_id_priv) {
32027- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32028+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32029 counter[CM_DREQ_COUNTER]);
32030 cm_issue_drep(work->port, work->mad_recv_wc);
32031 return -EINVAL;
32032@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32033 case IB_CM_MRA_REP_RCVD:
32034 break;
32035 case IB_CM_TIMEWAIT:
32036- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32037+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32038 counter[CM_DREQ_COUNTER]);
32039 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32040 goto unlock;
32041@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32042 cm_free_msg(msg);
32043 goto deref;
32044 case IB_CM_DREQ_RCVD:
32045- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32046+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32047 counter[CM_DREQ_COUNTER]);
32048 goto unlock;
32049 default:
32050@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32051 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32052 cm_id_priv->msg, timeout)) {
32053 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32054- atomic_long_inc(&work->port->
32055+ atomic_long_inc_unchecked(&work->port->
32056 counter_group[CM_RECV_DUPLICATES].
32057 counter[CM_MRA_COUNTER]);
32058 goto out;
32059@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32060 break;
32061 case IB_CM_MRA_REQ_RCVD:
32062 case IB_CM_MRA_REP_RCVD:
32063- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32064+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32065 counter[CM_MRA_COUNTER]);
32066 /* fall through */
32067 default:
32068@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32069 case IB_CM_LAP_IDLE:
32070 break;
32071 case IB_CM_MRA_LAP_SENT:
32072- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32073+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32074 counter[CM_LAP_COUNTER]);
32075 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32076 goto unlock;
32077@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32078 cm_free_msg(msg);
32079 goto deref;
32080 case IB_CM_LAP_RCVD:
32081- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32082+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32083 counter[CM_LAP_COUNTER]);
32084 goto unlock;
32085 default:
32086@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32087 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32088 if (cur_cm_id_priv) {
32089 spin_unlock_irq(&cm.lock);
32090- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32091+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32092 counter[CM_SIDR_REQ_COUNTER]);
32093 goto out; /* Duplicate message. */
32094 }
32095@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32096 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32097 msg->retries = 1;
32098
32099- atomic_long_add(1 + msg->retries,
32100+ atomic_long_add_unchecked(1 + msg->retries,
32101 &port->counter_group[CM_XMIT].counter[attr_index]);
32102 if (msg->retries)
32103- atomic_long_add(msg->retries,
32104+ atomic_long_add_unchecked(msg->retries,
32105 &port->counter_group[CM_XMIT_RETRIES].
32106 counter[attr_index]);
32107
32108@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32109 }
32110
32111 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32112- atomic_long_inc(&port->counter_group[CM_RECV].
32113+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32114 counter[attr_id - CM_ATTR_ID_OFFSET]);
32115
32116 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32117@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32118 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32119
32120 return sprintf(buf, "%ld\n",
32121- atomic_long_read(&group->counter[cm_attr->index]));
32122+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32123 }
32124
32125 static const struct sysfs_ops cm_counter_ops = {
32126diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32127index 176c8f9..2627b62 100644
32128--- a/drivers/infiniband/core/fmr_pool.c
32129+++ b/drivers/infiniband/core/fmr_pool.c
32130@@ -98,8 +98,8 @@ struct ib_fmr_pool {
32131
32132 struct task_struct *thread;
32133
32134- atomic_t req_ser;
32135- atomic_t flush_ser;
32136+ atomic_unchecked_t req_ser;
32137+ atomic_unchecked_t flush_ser;
32138
32139 wait_queue_head_t force_wait;
32140 };
32141@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32142 struct ib_fmr_pool *pool = pool_ptr;
32143
32144 do {
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 ib_fmr_batch_release(pool);
32148
32149- atomic_inc(&pool->flush_ser);
32150+ atomic_inc_unchecked(&pool->flush_ser);
32151 wake_up_interruptible(&pool->force_wait);
32152
32153 if (pool->flush_function)
32154@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32155 }
32156
32157 set_current_state(TASK_INTERRUPTIBLE);
32158- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32159+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32160 !kthread_should_stop())
32161 schedule();
32162 __set_current_state(TASK_RUNNING);
32163@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32164 pool->dirty_watermark = params->dirty_watermark;
32165 pool->dirty_len = 0;
32166 spin_lock_init(&pool->pool_lock);
32167- atomic_set(&pool->req_ser, 0);
32168- atomic_set(&pool->flush_ser, 0);
32169+ atomic_set_unchecked(&pool->req_ser, 0);
32170+ atomic_set_unchecked(&pool->flush_ser, 0);
32171 init_waitqueue_head(&pool->force_wait);
32172
32173 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32174@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32175 }
32176 spin_unlock_irq(&pool->pool_lock);
32177
32178- serial = atomic_inc_return(&pool->req_ser);
32179+ serial = atomic_inc_return_unchecked(&pool->req_ser);
32180 wake_up_process(pool->thread);
32181
32182 if (wait_event_interruptible(pool->force_wait,
32183- atomic_read(&pool->flush_ser) - serial >= 0))
32184+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32185 return -EINTR;
32186
32187 return 0;
32188@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32189 } else {
32190 list_add_tail(&fmr->list, &pool->dirty_list);
32191 if (++pool->dirty_len >= pool->dirty_watermark) {
32192- atomic_inc(&pool->req_ser);
32193+ atomic_inc_unchecked(&pool->req_ser);
32194 wake_up_process(pool->thread);
32195 }
32196 }
32197diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32198index 57e07c6..56d09d4 100644
32199--- a/drivers/infiniband/hw/cxgb4/mem.c
32200+++ b/drivers/infiniband/hw/cxgb4/mem.c
32201@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32202 int err;
32203 struct fw_ri_tpte tpt;
32204 u32 stag_idx;
32205- static atomic_t key;
32206+ static atomic_unchecked_t key;
32207
32208 if (c4iw_fatal_error(rdev))
32209 return -EIO;
32210@@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32211 if (rdev->stats.stag.cur > rdev->stats.stag.max)
32212 rdev->stats.stag.max = rdev->stats.stag.cur;
32213 mutex_unlock(&rdev->stats.lock);
32214- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32215+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32216 }
32217 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32218 __func__, stag_state, type, pdid, stag_idx);
32219diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32220index 79b3dbc..96e5fcc 100644
32221--- a/drivers/infiniband/hw/ipath/ipath_rc.c
32222+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32223@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32224 struct ib_atomic_eth *ateth;
32225 struct ipath_ack_entry *e;
32226 u64 vaddr;
32227- atomic64_t *maddr;
32228+ atomic64_unchecked_t *maddr;
32229 u64 sdata;
32230 u32 rkey;
32231 u8 next;
32232@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32233 IB_ACCESS_REMOTE_ATOMIC)))
32234 goto nack_acc_unlck;
32235 /* Perform atomic OP and save result. */
32236- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32237+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32238 sdata = be64_to_cpu(ateth->swap_data);
32239 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32240 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32241- (u64) atomic64_add_return(sdata, maddr) - sdata :
32242+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32243 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32244 be64_to_cpu(ateth->compare_data),
32245 sdata);
32246diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32247index 1f95bba..9530f87 100644
32248--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32249+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32250@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32251 unsigned long flags;
32252 struct ib_wc wc;
32253 u64 sdata;
32254- atomic64_t *maddr;
32255+ atomic64_unchecked_t *maddr;
32256 enum ib_wc_status send_status;
32257
32258 /*
32259@@ -382,11 +382,11 @@ again:
32260 IB_ACCESS_REMOTE_ATOMIC)))
32261 goto acc_err;
32262 /* Perform atomic OP and save result. */
32263- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32264+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32265 sdata = wqe->wr.wr.atomic.compare_add;
32266 *(u64 *) sqp->s_sge.sge.vaddr =
32267 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32268- (u64) atomic64_add_return(sdata, maddr) - sdata :
32269+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32270 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32271 sdata, wqe->wr.wr.atomic.swap);
32272 goto send_comp;
32273diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32274index 7140199..da60063 100644
32275--- a/drivers/infiniband/hw/nes/nes.c
32276+++ b/drivers/infiniband/hw/nes/nes.c
32277@@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32278 LIST_HEAD(nes_adapter_list);
32279 static LIST_HEAD(nes_dev_list);
32280
32281-atomic_t qps_destroyed;
32282+atomic_unchecked_t qps_destroyed;
32283
32284 static unsigned int ee_flsh_adapter;
32285 static unsigned int sysfs_nonidx_addr;
32286@@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32287 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32288 struct nes_adapter *nesadapter = nesdev->nesadapter;
32289
32290- atomic_inc(&qps_destroyed);
32291+ atomic_inc_unchecked(&qps_destroyed);
32292
32293 /* Free the control structures */
32294
32295diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32296index c438e46..ca30356 100644
32297--- a/drivers/infiniband/hw/nes/nes.h
32298+++ b/drivers/infiniband/hw/nes/nes.h
32299@@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32300 extern unsigned int wqm_quanta;
32301 extern struct list_head nes_adapter_list;
32302
32303-extern atomic_t cm_connects;
32304-extern atomic_t cm_accepts;
32305-extern atomic_t cm_disconnects;
32306-extern atomic_t cm_closes;
32307-extern atomic_t cm_connecteds;
32308-extern atomic_t cm_connect_reqs;
32309-extern atomic_t cm_rejects;
32310-extern atomic_t mod_qp_timouts;
32311-extern atomic_t qps_created;
32312-extern atomic_t qps_destroyed;
32313-extern atomic_t sw_qps_destroyed;
32314+extern atomic_unchecked_t cm_connects;
32315+extern atomic_unchecked_t cm_accepts;
32316+extern atomic_unchecked_t cm_disconnects;
32317+extern atomic_unchecked_t cm_closes;
32318+extern atomic_unchecked_t cm_connecteds;
32319+extern atomic_unchecked_t cm_connect_reqs;
32320+extern atomic_unchecked_t cm_rejects;
32321+extern atomic_unchecked_t mod_qp_timouts;
32322+extern atomic_unchecked_t qps_created;
32323+extern atomic_unchecked_t qps_destroyed;
32324+extern atomic_unchecked_t sw_qps_destroyed;
32325 extern u32 mh_detected;
32326 extern u32 mh_pauses_sent;
32327 extern u32 cm_packets_sent;
32328@@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32329 extern u32 cm_packets_received;
32330 extern u32 cm_packets_dropped;
32331 extern u32 cm_packets_retrans;
32332-extern atomic_t cm_listens_created;
32333-extern atomic_t cm_listens_destroyed;
32334+extern atomic_unchecked_t cm_listens_created;
32335+extern atomic_unchecked_t cm_listens_destroyed;
32336 extern u32 cm_backlog_drops;
32337-extern atomic_t cm_loopbacks;
32338-extern atomic_t cm_nodes_created;
32339-extern atomic_t cm_nodes_destroyed;
32340-extern atomic_t cm_accel_dropped_pkts;
32341-extern atomic_t cm_resets_recvd;
32342-extern atomic_t pau_qps_created;
32343-extern atomic_t pau_qps_destroyed;
32344+extern atomic_unchecked_t cm_loopbacks;
32345+extern atomic_unchecked_t cm_nodes_created;
32346+extern atomic_unchecked_t cm_nodes_destroyed;
32347+extern atomic_unchecked_t cm_accel_dropped_pkts;
32348+extern atomic_unchecked_t cm_resets_recvd;
32349+extern atomic_unchecked_t pau_qps_created;
32350+extern atomic_unchecked_t pau_qps_destroyed;
32351
32352 extern u32 int_mod_timer_init;
32353 extern u32 int_mod_cq_depth_256;
32354diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32355index 020e95c..fbb3450 100644
32356--- a/drivers/infiniband/hw/nes/nes_cm.c
32357+++ b/drivers/infiniband/hw/nes/nes_cm.c
32358@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32359 u32 cm_packets_retrans;
32360 u32 cm_packets_created;
32361 u32 cm_packets_received;
32362-atomic_t cm_listens_created;
32363-atomic_t cm_listens_destroyed;
32364+atomic_unchecked_t cm_listens_created;
32365+atomic_unchecked_t cm_listens_destroyed;
32366 u32 cm_backlog_drops;
32367-atomic_t cm_loopbacks;
32368-atomic_t cm_nodes_created;
32369-atomic_t cm_nodes_destroyed;
32370-atomic_t cm_accel_dropped_pkts;
32371-atomic_t cm_resets_recvd;
32372+atomic_unchecked_t cm_loopbacks;
32373+atomic_unchecked_t cm_nodes_created;
32374+atomic_unchecked_t cm_nodes_destroyed;
32375+atomic_unchecked_t cm_accel_dropped_pkts;
32376+atomic_unchecked_t cm_resets_recvd;
32377
32378 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32379 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32380@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32381
32382 static struct nes_cm_core *g_cm_core;
32383
32384-atomic_t cm_connects;
32385-atomic_t cm_accepts;
32386-atomic_t cm_disconnects;
32387-atomic_t cm_closes;
32388-atomic_t cm_connecteds;
32389-atomic_t cm_connect_reqs;
32390-atomic_t cm_rejects;
32391+atomic_unchecked_t cm_connects;
32392+atomic_unchecked_t cm_accepts;
32393+atomic_unchecked_t cm_disconnects;
32394+atomic_unchecked_t cm_closes;
32395+atomic_unchecked_t cm_connecteds;
32396+atomic_unchecked_t cm_connect_reqs;
32397+atomic_unchecked_t cm_rejects;
32398
32399 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32400 {
32401@@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32402 kfree(listener);
32403 listener = NULL;
32404 ret = 0;
32405- atomic_inc(&cm_listens_destroyed);
32406+ atomic_inc_unchecked(&cm_listens_destroyed);
32407 } else {
32408 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32409 }
32410@@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32411 cm_node->rem_mac);
32412
32413 add_hte_node(cm_core, cm_node);
32414- atomic_inc(&cm_nodes_created);
32415+ atomic_inc_unchecked(&cm_nodes_created);
32416
32417 return cm_node;
32418 }
32419@@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32420 }
32421
32422 atomic_dec(&cm_core->node_cnt);
32423- atomic_inc(&cm_nodes_destroyed);
32424+ atomic_inc_unchecked(&cm_nodes_destroyed);
32425 nesqp = cm_node->nesqp;
32426 if (nesqp) {
32427 nesqp->cm_node = NULL;
32428@@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32429
32430 static void drop_packet(struct sk_buff *skb)
32431 {
32432- atomic_inc(&cm_accel_dropped_pkts);
32433+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
32434 dev_kfree_skb_any(skb);
32435 }
32436
32437@@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32438 {
32439
32440 int reset = 0; /* whether to send reset in case of err.. */
32441- atomic_inc(&cm_resets_recvd);
32442+ atomic_inc_unchecked(&cm_resets_recvd);
32443 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32444 " refcnt=%d\n", cm_node, cm_node->state,
32445 atomic_read(&cm_node->ref_count));
32446@@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32447 rem_ref_cm_node(cm_node->cm_core, cm_node);
32448 return NULL;
32449 }
32450- atomic_inc(&cm_loopbacks);
32451+ atomic_inc_unchecked(&cm_loopbacks);
32452 loopbackremotenode->loopbackpartner = cm_node;
32453 loopbackremotenode->tcp_cntxt.rcv_wscale =
32454 NES_CM_DEFAULT_RCV_WND_SCALE;
32455@@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32456 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32457 else {
32458 rem_ref_cm_node(cm_core, cm_node);
32459- atomic_inc(&cm_accel_dropped_pkts);
32460+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
32461 dev_kfree_skb_any(skb);
32462 }
32463 break;
32464@@ -2891,7 +2891,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32465
32466 if ((cm_id) && (cm_id->event_handler)) {
32467 if (issue_disconn) {
32468- atomic_inc(&cm_disconnects);
32469+ atomic_inc_unchecked(&cm_disconnects);
32470 cm_event.event = IW_CM_EVENT_DISCONNECT;
32471 cm_event.status = disconn_status;
32472 cm_event.local_addr = cm_id->local_addr;
32473@@ -2913,7 +2913,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32474 }
32475
32476 if (issue_close) {
32477- atomic_inc(&cm_closes);
32478+ atomic_inc_unchecked(&cm_closes);
32479 nes_disconnect(nesqp, 1);
32480
32481 cm_id->provider_data = nesqp;
32482@@ -3049,7 +3049,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32483
32484 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32485 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32486- atomic_inc(&cm_accepts);
32487+ atomic_inc_unchecked(&cm_accepts);
32488
32489 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32490 netdev_refcnt_read(nesvnic->netdev));
32491@@ -3251,7 +3251,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32492 struct nes_cm_core *cm_core;
32493 u8 *start_buff;
32494
32495- atomic_inc(&cm_rejects);
32496+ atomic_inc_unchecked(&cm_rejects);
32497 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32498 loopback = cm_node->loopbackpartner;
32499 cm_core = cm_node->cm_core;
32500@@ -3311,7 +3311,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32501 ntohl(cm_id->local_addr.sin_addr.s_addr),
32502 ntohs(cm_id->local_addr.sin_port));
32503
32504- atomic_inc(&cm_connects);
32505+ atomic_inc_unchecked(&cm_connects);
32506 nesqp->active_conn = 1;
32507
32508 /* cache the cm_id in the qp */
32509@@ -3421,7 +3421,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32510 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32511 return err;
32512 }
32513- atomic_inc(&cm_listens_created);
32514+ atomic_inc_unchecked(&cm_listens_created);
32515 }
32516
32517 cm_id->add_ref(cm_id);
32518@@ -3522,7 +3522,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32519
32520 if (nesqp->destroyed)
32521 return;
32522- atomic_inc(&cm_connecteds);
32523+ atomic_inc_unchecked(&cm_connecteds);
32524 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32525 " local port 0x%04X. jiffies = %lu.\n",
32526 nesqp->hwqp.qp_id,
32527@@ -3709,7 +3709,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32528
32529 cm_id->add_ref(cm_id);
32530 ret = cm_id->event_handler(cm_id, &cm_event);
32531- atomic_inc(&cm_closes);
32532+ atomic_inc_unchecked(&cm_closes);
32533 cm_event.event = IW_CM_EVENT_CLOSE;
32534 cm_event.status = 0;
32535 cm_event.provider_data = cm_id->provider_data;
32536@@ -3745,7 +3745,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32537 return;
32538 cm_id = cm_node->cm_id;
32539
32540- atomic_inc(&cm_connect_reqs);
32541+ atomic_inc_unchecked(&cm_connect_reqs);
32542 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32543 cm_node, cm_id, jiffies);
32544
32545@@ -3785,7 +3785,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32546 return;
32547 cm_id = cm_node->cm_id;
32548
32549- atomic_inc(&cm_connect_reqs);
32550+ atomic_inc_unchecked(&cm_connect_reqs);
32551 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32552 cm_node, cm_id, jiffies);
32553
32554diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32555index 3ba7be3..c81f6ff 100644
32556--- a/drivers/infiniband/hw/nes/nes_mgt.c
32557+++ b/drivers/infiniband/hw/nes/nes_mgt.c
32558@@ -40,8 +40,8 @@
32559 #include "nes.h"
32560 #include "nes_mgt.h"
32561
32562-atomic_t pau_qps_created;
32563-atomic_t pau_qps_destroyed;
32564+atomic_unchecked_t pau_qps_created;
32565+atomic_unchecked_t pau_qps_destroyed;
32566
32567 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32568 {
32569@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32570 {
32571 struct sk_buff *skb;
32572 unsigned long flags;
32573- atomic_inc(&pau_qps_destroyed);
32574+ atomic_inc_unchecked(&pau_qps_destroyed);
32575
32576 /* Free packets that have not yet been forwarded */
32577 /* Lock is acquired by skb_dequeue when removing the skb */
32578@@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32579 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32580 skb_queue_head_init(&nesqp->pau_list);
32581 spin_lock_init(&nesqp->pau_lock);
32582- atomic_inc(&pau_qps_created);
32583+ atomic_inc_unchecked(&pau_qps_created);
32584 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32585 }
32586
32587diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32588index f3a3ecf..57d311d 100644
32589--- a/drivers/infiniband/hw/nes/nes_nic.c
32590+++ b/drivers/infiniband/hw/nes/nes_nic.c
32591@@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32592 target_stat_values[++index] = mh_detected;
32593 target_stat_values[++index] = mh_pauses_sent;
32594 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32595- target_stat_values[++index] = atomic_read(&cm_connects);
32596- target_stat_values[++index] = atomic_read(&cm_accepts);
32597- target_stat_values[++index] = atomic_read(&cm_disconnects);
32598- target_stat_values[++index] = atomic_read(&cm_connecteds);
32599- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32600- target_stat_values[++index] = atomic_read(&cm_rejects);
32601- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32602- target_stat_values[++index] = atomic_read(&qps_created);
32603- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32604- target_stat_values[++index] = atomic_read(&qps_destroyed);
32605- target_stat_values[++index] = atomic_read(&cm_closes);
32606+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32607+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32608+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32609+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32610+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32611+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32612+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32613+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32614+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32615+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32616+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32617 target_stat_values[++index] = cm_packets_sent;
32618 target_stat_values[++index] = cm_packets_bounced;
32619 target_stat_values[++index] = cm_packets_created;
32620 target_stat_values[++index] = cm_packets_received;
32621 target_stat_values[++index] = cm_packets_dropped;
32622 target_stat_values[++index] = cm_packets_retrans;
32623- target_stat_values[++index] = atomic_read(&cm_listens_created);
32624- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32625+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32626+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32627 target_stat_values[++index] = cm_backlog_drops;
32628- target_stat_values[++index] = atomic_read(&cm_loopbacks);
32629- target_stat_values[++index] = atomic_read(&cm_nodes_created);
32630- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32631- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32632- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32633+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32634+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32635+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32636+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32637+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32638 target_stat_values[++index] = nesadapter->free_4kpbl;
32639 target_stat_values[++index] = nesadapter->free_256pbl;
32640 target_stat_values[++index] = int_mod_timer_init;
32641 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32642 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32643 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32644- target_stat_values[++index] = atomic_read(&pau_qps_created);
32645- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32646+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32647+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32648 }
32649
32650 /**
32651diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32652index 8b8812d..a5e1133 100644
32653--- a/drivers/infiniband/hw/nes/nes_verbs.c
32654+++ b/drivers/infiniband/hw/nes/nes_verbs.c
32655@@ -46,9 +46,9 @@
32656
32657 #include <rdma/ib_umem.h>
32658
32659-atomic_t mod_qp_timouts;
32660-atomic_t qps_created;
32661-atomic_t sw_qps_destroyed;
32662+atomic_unchecked_t mod_qp_timouts;
32663+atomic_unchecked_t qps_created;
32664+atomic_unchecked_t sw_qps_destroyed;
32665
32666 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32667
32668@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32669 if (init_attr->create_flags)
32670 return ERR_PTR(-EINVAL);
32671
32672- atomic_inc(&qps_created);
32673+ atomic_inc_unchecked(&qps_created);
32674 switch (init_attr->qp_type) {
32675 case IB_QPT_RC:
32676 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32677@@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32678 struct iw_cm_event cm_event;
32679 int ret = 0;
32680
32681- atomic_inc(&sw_qps_destroyed);
32682+ atomic_inc_unchecked(&sw_qps_destroyed);
32683 nesqp->destroyed = 1;
32684
32685 /* Blow away the connection if it exists. */
32686diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32687index 7e62f41..4c2b8e2 100644
32688--- a/drivers/infiniband/hw/qib/qib.h
32689+++ b/drivers/infiniband/hw/qib/qib.h
32690@@ -51,6 +51,7 @@
32691 #include <linux/completion.h>
32692 #include <linux/kref.h>
32693 #include <linux/sched.h>
32694+#include <linux/slab.h>
32695
32696 #include "qib_common.h"
32697 #include "qib_verbs.h"
32698diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32699index da739d9..da1c7f4 100644
32700--- a/drivers/input/gameport/gameport.c
32701+++ b/drivers/input/gameport/gameport.c
32702@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32703 */
32704 static void gameport_init_port(struct gameport *gameport)
32705 {
32706- static atomic_t gameport_no = ATOMIC_INIT(0);
32707+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32708
32709 __module_get(THIS_MODULE);
32710
32711 mutex_init(&gameport->drv_mutex);
32712 device_initialize(&gameport->dev);
32713 dev_set_name(&gameport->dev, "gameport%lu",
32714- (unsigned long)atomic_inc_return(&gameport_no) - 1);
32715+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32716 gameport->dev.bus = &gameport_bus;
32717 gameport->dev.release = gameport_release_port;
32718 if (gameport->parent)
32719diff --git a/drivers/input/input.c b/drivers/input/input.c
32720index 8921c61..f5cd63d 100644
32721--- a/drivers/input/input.c
32722+++ b/drivers/input/input.c
32723@@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32724 */
32725 int input_register_device(struct input_dev *dev)
32726 {
32727- static atomic_t input_no = ATOMIC_INIT(0);
32728+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32729 struct input_handler *handler;
32730 const char *path;
32731 int error;
32732@@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32733 dev->setkeycode = input_default_setkeycode;
32734
32735 dev_set_name(&dev->dev, "input%ld",
32736- (unsigned long) atomic_inc_return(&input_no) - 1);
32737+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32738
32739 error = device_add(&dev->dev);
32740 if (error)
32741diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32742index 04c69af..5f92d00 100644
32743--- a/drivers/input/joystick/sidewinder.c
32744+++ b/drivers/input/joystick/sidewinder.c
32745@@ -30,6 +30,7 @@
32746 #include <linux/kernel.h>
32747 #include <linux/module.h>
32748 #include <linux/slab.h>
32749+#include <linux/sched.h>
32750 #include <linux/init.h>
32751 #include <linux/input.h>
32752 #include <linux/gameport.h>
32753diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32754index 83811e4..0822b90 100644
32755--- a/drivers/input/joystick/xpad.c
32756+++ b/drivers/input/joystick/xpad.c
32757@@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32758
32759 static int xpad_led_probe(struct usb_xpad *xpad)
32760 {
32761- static atomic_t led_seq = ATOMIC_INIT(0);
32762+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32763 long led_no;
32764 struct xpad_led *led;
32765 struct led_classdev *led_cdev;
32766@@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32767 if (!led)
32768 return -ENOMEM;
32769
32770- led_no = (long)atomic_inc_return(&led_seq) - 1;
32771+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32772
32773 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32774 led->xpad = xpad;
32775diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32776index 0110b5a..d3ad144 100644
32777--- a/drivers/input/mousedev.c
32778+++ b/drivers/input/mousedev.c
32779@@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32780
32781 spin_unlock_irq(&client->packet_lock);
32782
32783- if (copy_to_user(buffer, data, count))
32784+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
32785 return -EFAULT;
32786
32787 return count;
32788diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
32789index d0f7533..fb8215b 100644
32790--- a/drivers/input/serio/serio.c
32791+++ b/drivers/input/serio/serio.c
32792@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
32793 */
32794 static void serio_init_port(struct serio *serio)
32795 {
32796- static atomic_t serio_no = ATOMIC_INIT(0);
32797+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
32798
32799 __module_get(THIS_MODULE);
32800
32801@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
32802 mutex_init(&serio->drv_mutex);
32803 device_initialize(&serio->dev);
32804 dev_set_name(&serio->dev, "serio%ld",
32805- (long)atomic_inc_return(&serio_no) - 1);
32806+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
32807 serio->dev.bus = &serio_bus;
32808 serio->dev.release = serio_release_port;
32809 serio->dev.groups = serio_device_attr_groups;
32810diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
32811index 38c4bd8..58965d9 100644
32812--- a/drivers/isdn/capi/capi.c
32813+++ b/drivers/isdn/capi/capi.c
32814@@ -83,8 +83,8 @@ struct capiminor {
32815
32816 struct capi20_appl *ap;
32817 u32 ncci;
32818- atomic_t datahandle;
32819- atomic_t msgid;
32820+ atomic_unchecked_t datahandle;
32821+ atomic_unchecked_t msgid;
32822
32823 struct tty_port port;
32824 int ttyinstop;
32825@@ -392,7 +392,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
32826 capimsg_setu16(s, 2, mp->ap->applid);
32827 capimsg_setu8 (s, 4, CAPI_DATA_B3);
32828 capimsg_setu8 (s, 5, CAPI_RESP);
32829- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
32830+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
32831 capimsg_setu32(s, 8, mp->ncci);
32832 capimsg_setu16(s, 12, datahandle);
32833 }
32834@@ -513,14 +513,14 @@ static void handle_minor_send(struct capiminor *mp)
32835 mp->outbytes -= len;
32836 spin_unlock_bh(&mp->outlock);
32837
32838- datahandle = atomic_inc_return(&mp->datahandle);
32839+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
32840 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
32841 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32842 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
32843 capimsg_setu16(skb->data, 2, mp->ap->applid);
32844 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
32845 capimsg_setu8 (skb->data, 5, CAPI_REQ);
32846- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
32847+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
32848 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
32849 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
32850 capimsg_setu16(skb->data, 16, len); /* Data length */
32851diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
32852index a6d9fd2..afdb8a3 100644
32853--- a/drivers/isdn/gigaset/interface.c
32854+++ b/drivers/isdn/gigaset/interface.c
32855@@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
32856 }
32857 tty->driver_data = cs;
32858
32859- ++cs->port.count;
32860+ atomic_inc(&cs->port.count);
32861
32862- if (cs->port.count == 1) {
32863+ if (atomic_read(&cs->port.count) == 1) {
32864 tty_port_tty_set(&cs->port, tty);
32865 tty->low_latency = 1;
32866 }
32867@@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
32868
32869 if (!cs->connected)
32870 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
32871- else if (!cs->port.count)
32872+ else if (!atomic_read(&cs->port.count))
32873 dev_warn(cs->dev, "%s: device not opened\n", __func__);
32874- else if (!--cs->port.count)
32875+ else if (!atomic_dec_return(&cs->port.count))
32876 tty_port_tty_set(&cs->port, NULL);
32877
32878 mutex_unlock(&cs->mutex);
32879diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
32880index 821f7ac..28d4030 100644
32881--- a/drivers/isdn/hardware/avm/b1.c
32882+++ b/drivers/isdn/hardware/avm/b1.c
32883@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
32884 }
32885 if (left) {
32886 if (t4file->user) {
32887- if (copy_from_user(buf, dp, left))
32888+ if (left > sizeof buf || copy_from_user(buf, dp, left))
32889 return -EFAULT;
32890 } else {
32891 memcpy(buf, dp, left);
32892@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
32893 }
32894 if (left) {
32895 if (config->user) {
32896- if (copy_from_user(buf, dp, left))
32897+ if (left > sizeof buf || copy_from_user(buf, dp, left))
32898 return -EFAULT;
32899 } else {
32900 memcpy(buf, dp, left);
32901diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
32902index dd6b53a..19d9ee6 100644
32903--- a/drivers/isdn/hardware/eicon/divasync.h
32904+++ b/drivers/isdn/hardware/eicon/divasync.h
32905@@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
32906 } diva_didd_add_adapter_t;
32907 typedef struct _diva_didd_remove_adapter {
32908 IDI_CALL p_request;
32909-} diva_didd_remove_adapter_t;
32910+} __no_const diva_didd_remove_adapter_t;
32911 typedef struct _diva_didd_read_adapter_array {
32912 void *buffer;
32913 dword length;
32914diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
32915index d303e65..28bcb7b 100644
32916--- a/drivers/isdn/hardware/eicon/xdi_adapter.h
32917+++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
32918@@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
32919 typedef struct _diva_os_idi_adapter_interface {
32920 diva_init_card_proc_t cleanup_adapter_proc;
32921 diva_cmd_card_proc_t cmd_proc;
32922-} diva_os_idi_adapter_interface_t;
32923+} __no_const diva_os_idi_adapter_interface_t;
32924
32925 typedef struct _diva_os_xdi_adapter {
32926 struct list_head link;
32927diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
32928index 7bc5067..fd36232 100644
32929--- a/drivers/isdn/i4l/isdn_tty.c
32930+++ b/drivers/isdn/i4l/isdn_tty.c
32931@@ -1505,9 +1505,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
32932 port = &info->port;
32933 #ifdef ISDN_DEBUG_MODEM_OPEN
32934 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
32935- port->count);
32936+ atomic_read(&port->count))
32937 #endif
32938- port->count++;
32939+ atomic_inc(&port->count);
32940 tty->driver_data = info;
32941 port->tty = tty;
32942 tty->port = port;
32943@@ -1553,7 +1553,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
32944 #endif
32945 return;
32946 }
32947- if ((tty->count == 1) && (port->count != 1)) {
32948+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
32949 /*
32950 * Uh, oh. tty->count is 1, which means that the tty
32951 * structure will be freed. Info->count should always
32952@@ -1562,15 +1562,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
32953 * serial port won't be shutdown.
32954 */
32955 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
32956- "info->count is %d\n", port->count);
32957- port->count = 1;
32958+ "info->count is %d\n", atomic_read(&port->count));
32959+ atomic_set(&port->count, 1);
32960 }
32961- if (--port->count < 0) {
32962+ if (atomic_dec_return(&port->count) < 0) {
32963 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
32964- info->line, port->count);
32965- port->count = 0;
32966+ info->line, atomic_read(&port->count));
32967+ atomic_set(&port->count, 0);
32968 }
32969- if (port->count) {
32970+ if (atomic_read(&port->count)) {
32971 #ifdef ISDN_DEBUG_MODEM_OPEN
32972 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
32973 #endif
32974@@ -1624,7 +1624,7 @@ isdn_tty_hangup(struct tty_struct *tty)
32975 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
32976 return;
32977 isdn_tty_shutdown(info);
32978- port->count = 0;
32979+ atomic_set(&port->count, 0);
32980 port->flags &= ~ASYNC_NORMAL_ACTIVE;
32981 port->tty = NULL;
32982 wake_up_interruptible(&port->open_wait);
32983@@ -1964,7 +1964,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
32984 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
32985 modem_info *info = &dev->mdm.info[i];
32986
32987- if (info->port.count == 0)
32988+ if (atomic_read(&info->port.count) == 0)
32989 continue;
32990 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
32991 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
32992diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
32993index e74df7c..03a03ba 100644
32994--- a/drivers/isdn/icn/icn.c
32995+++ b/drivers/isdn/icn/icn.c
32996@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
32997 if (count > len)
32998 count = len;
32999 if (user) {
33000- if (copy_from_user(msg, buf, count))
33001+ if (count > sizeof msg || copy_from_user(msg, buf, count))
33002 return -EFAULT;
33003 } else
33004 memcpy(msg, buf, count);
33005diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
33006index b5fdcb7..5b6c59f 100644
33007--- a/drivers/lguest/core.c
33008+++ b/drivers/lguest/core.c
33009@@ -92,9 +92,17 @@ static __init int map_switcher(void)
33010 * it's worked so far. The end address needs +1 because __get_vm_area
33011 * allocates an extra guard page, so we need space for that.
33012 */
33013+
33014+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
33015+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33016+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
33017+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33018+#else
33019 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33020 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
33021 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33022+#endif
33023+
33024 if (!switcher_vma) {
33025 err = -ENOMEM;
33026 printk("lguest: could not map switcher pages high\n");
33027@@ -119,7 +127,7 @@ static __init int map_switcher(void)
33028 * Now the Switcher is mapped at the right address, we can't fail!
33029 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
33030 */
33031- memcpy(switcher_vma->addr, start_switcher_text,
33032+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
33033 end_switcher_text - start_switcher_text);
33034
33035 printk(KERN_INFO "lguest: mapped switcher at %p\n",
33036diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
33037index 39809035..ce25c5e 100644
33038--- a/drivers/lguest/x86/core.c
33039+++ b/drivers/lguest/x86/core.c
33040@@ -59,7 +59,7 @@ static struct {
33041 /* Offset from where switcher.S was compiled to where we've copied it */
33042 static unsigned long switcher_offset(void)
33043 {
33044- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
33045+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
33046 }
33047
33048 /* This cpu's struct lguest_pages. */
33049@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
33050 * These copies are pretty cheap, so we do them unconditionally: */
33051 /* Save the current Host top-level page directory.
33052 */
33053+
33054+#ifdef CONFIG_PAX_PER_CPU_PGD
33055+ pages->state.host_cr3 = read_cr3();
33056+#else
33057 pages->state.host_cr3 = __pa(current->mm->pgd);
33058+#endif
33059+
33060 /*
33061 * Set up the Guest's page tables to see this CPU's pages (and no
33062 * other CPU's pages).
33063@@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
33064 * compiled-in switcher code and the high-mapped copy we just made.
33065 */
33066 for (i = 0; i < IDT_ENTRIES; i++)
33067- default_idt_entries[i] += switcher_offset();
33068+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33069
33070 /*
33071 * Set up the Switcher's per-cpu areas.
33072@@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
33073 * it will be undisturbed when we switch. To change %cs and jump we
33074 * need this structure to feed to Intel's "lcall" instruction.
33075 */
33076- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33077+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33078 lguest_entry.segment = LGUEST_CS;
33079
33080 /*
33081diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33082index 40634b0..4f5855e 100644
33083--- a/drivers/lguest/x86/switcher_32.S
33084+++ b/drivers/lguest/x86/switcher_32.S
33085@@ -87,6 +87,7 @@
33086 #include <asm/page.h>
33087 #include <asm/segment.h>
33088 #include <asm/lguest.h>
33089+#include <asm/processor-flags.h>
33090
33091 // We mark the start of the code to copy
33092 // It's placed in .text tho it's never run here
33093@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33094 // Changes type when we load it: damn Intel!
33095 // For after we switch over our page tables
33096 // That entry will be read-only: we'd crash.
33097+
33098+#ifdef CONFIG_PAX_KERNEXEC
33099+ mov %cr0, %edx
33100+ xor $X86_CR0_WP, %edx
33101+ mov %edx, %cr0
33102+#endif
33103+
33104 movl $(GDT_ENTRY_TSS*8), %edx
33105 ltr %dx
33106
33107@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33108 // Let's clear it again for our return.
33109 // The GDT descriptor of the Host
33110 // Points to the table after two "size" bytes
33111- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33112+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33113 // Clear "used" from type field (byte 5, bit 2)
33114- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33115+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33116+
33117+#ifdef CONFIG_PAX_KERNEXEC
33118+ mov %cr0, %eax
33119+ xor $X86_CR0_WP, %eax
33120+ mov %eax, %cr0
33121+#endif
33122
33123 // Once our page table's switched, the Guest is live!
33124 // The Host fades as we run this final step.
33125@@ -295,13 +309,12 @@ deliver_to_host:
33126 // I consulted gcc, and it gave
33127 // These instructions, which I gladly credit:
33128 leal (%edx,%ebx,8), %eax
33129- movzwl (%eax),%edx
33130- movl 4(%eax), %eax
33131- xorw %ax, %ax
33132- orl %eax, %edx
33133+ movl 4(%eax), %edx
33134+ movw (%eax), %dx
33135 // Now the address of the handler's in %edx
33136 // We call it now: its "iret" drops us home.
33137- jmp *%edx
33138+ ljmp $__KERNEL_CS, $1f
33139+1: jmp *%edx
33140
33141 // Every interrupt can come to us here
33142 // But we must truly tell each apart.
33143diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33144index 20e5c2c..9e849a9 100644
33145--- a/drivers/macintosh/macio_asic.c
33146+++ b/drivers/macintosh/macio_asic.c
33147@@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33148 * MacIO is matched against any Apple ID, it's probe() function
33149 * will then decide wether it applies or not
33150 */
33151-static const struct pci_device_id __devinitdata pci_ids [] = { {
33152+static const struct pci_device_id __devinitconst pci_ids [] = { {
33153 .vendor = PCI_VENDOR_ID_APPLE,
33154 .device = PCI_ANY_ID,
33155 .subvendor = PCI_ANY_ID,
33156diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33157index 15dbe03..743fc65 100644
33158--- a/drivers/md/bitmap.c
33159+++ b/drivers/md/bitmap.c
33160@@ -1786,7 +1786,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33161 chunk_kb ? "KB" : "B");
33162 if (bitmap->storage.file) {
33163 seq_printf(seq, ", file: ");
33164- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
33165+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
33166 }
33167
33168 seq_printf(seq, "\n");
33169diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33170index a1a3e6d..1918bfc 100644
33171--- a/drivers/md/dm-ioctl.c
33172+++ b/drivers/md/dm-ioctl.c
33173@@ -1590,7 +1590,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33174 cmd == DM_LIST_VERSIONS_CMD)
33175 return 0;
33176
33177- if ((cmd == DM_DEV_CREATE_CMD)) {
33178+ if (cmd == DM_DEV_CREATE_CMD) {
33179 if (!*param->name) {
33180 DMWARN("name not supplied when creating device");
33181 return -EINVAL;
33182diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33183index b58b7a3..8018b19 100644
33184--- a/drivers/md/dm-raid1.c
33185+++ b/drivers/md/dm-raid1.c
33186@@ -40,7 +40,7 @@ enum dm_raid1_error {
33187
33188 struct mirror {
33189 struct mirror_set *ms;
33190- atomic_t error_count;
33191+ atomic_unchecked_t error_count;
33192 unsigned long error_type;
33193 struct dm_dev *dev;
33194 sector_t offset;
33195@@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33196 struct mirror *m;
33197
33198 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33199- if (!atomic_read(&m->error_count))
33200+ if (!atomic_read_unchecked(&m->error_count))
33201 return m;
33202
33203 return NULL;
33204@@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33205 * simple way to tell if a device has encountered
33206 * errors.
33207 */
33208- atomic_inc(&m->error_count);
33209+ atomic_inc_unchecked(&m->error_count);
33210
33211 if (test_and_set_bit(error_type, &m->error_type))
33212 return;
33213@@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33214 struct mirror *m = get_default_mirror(ms);
33215
33216 do {
33217- if (likely(!atomic_read(&m->error_count)))
33218+ if (likely(!atomic_read_unchecked(&m->error_count)))
33219 return m;
33220
33221 if (m-- == ms->mirror)
33222@@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33223 {
33224 struct mirror *default_mirror = get_default_mirror(m->ms);
33225
33226- return !atomic_read(&default_mirror->error_count);
33227+ return !atomic_read_unchecked(&default_mirror->error_count);
33228 }
33229
33230 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33231@@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33232 */
33233 if (likely(region_in_sync(ms, region, 1)))
33234 m = choose_mirror(ms, bio->bi_sector);
33235- else if (m && atomic_read(&m->error_count))
33236+ else if (m && atomic_read_unchecked(&m->error_count))
33237 m = NULL;
33238
33239 if (likely(m))
33240@@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33241 }
33242
33243 ms->mirror[mirror].ms = ms;
33244- atomic_set(&(ms->mirror[mirror].error_count), 0);
33245+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33246 ms->mirror[mirror].error_type = 0;
33247 ms->mirror[mirror].offset = offset;
33248
33249@@ -1352,7 +1352,7 @@ static void mirror_resume(struct dm_target *ti)
33250 */
33251 static char device_status_char(struct mirror *m)
33252 {
33253- if (!atomic_read(&(m->error_count)))
33254+ if (!atomic_read_unchecked(&(m->error_count)))
33255 return 'A';
33256
33257 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33258diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33259index 35c94ff..20d4c17 100644
33260--- a/drivers/md/dm-stripe.c
33261+++ b/drivers/md/dm-stripe.c
33262@@ -20,7 +20,7 @@ struct stripe {
33263 struct dm_dev *dev;
33264 sector_t physical_start;
33265
33266- atomic_t error_count;
33267+ atomic_unchecked_t error_count;
33268 };
33269
33270 struct stripe_c {
33271@@ -193,7 +193,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33272 kfree(sc);
33273 return r;
33274 }
33275- atomic_set(&(sc->stripe[i].error_count), 0);
33276+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33277 }
33278
33279 ti->private = sc;
33280@@ -315,7 +315,7 @@ static int stripe_status(struct dm_target *ti,
33281 DMEMIT("%d ", sc->stripes);
33282 for (i = 0; i < sc->stripes; i++) {
33283 DMEMIT("%s ", sc->stripe[i].dev->name);
33284- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33285+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33286 'D' : 'A';
33287 }
33288 buffer[i] = '\0';
33289@@ -362,8 +362,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33290 */
33291 for (i = 0; i < sc->stripes; i++)
33292 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33293- atomic_inc(&(sc->stripe[i].error_count));
33294- if (atomic_read(&(sc->stripe[i].error_count)) <
33295+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
33296+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33297 DM_IO_ERROR_THRESHOLD)
33298 schedule_work(&sc->trigger_event);
33299 }
33300diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33301index 2e227fb..44ead1f 100644
33302--- a/drivers/md/dm-table.c
33303+++ b/drivers/md/dm-table.c
33304@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33305 if (!dev_size)
33306 return 0;
33307
33308- if ((start >= dev_size) || (start + len > dev_size)) {
33309+ if ((start >= dev_size) || (len > dev_size - start)) {
33310 DMWARN("%s: %s too small for target: "
33311 "start=%llu, len=%llu, dev_size=%llu",
33312 dm_device_name(ti->table->md), bdevname(bdev, b),
33313diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33314index 3e2907f..c28851a 100644
33315--- a/drivers/md/dm-thin-metadata.c
33316+++ b/drivers/md/dm-thin-metadata.c
33317@@ -432,7 +432,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33318
33319 pmd->info.tm = tm;
33320 pmd->info.levels = 2;
33321- pmd->info.value_type.context = pmd->data_sm;
33322+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33323 pmd->info.value_type.size = sizeof(__le64);
33324 pmd->info.value_type.inc = data_block_inc;
33325 pmd->info.value_type.dec = data_block_dec;
33326@@ -451,7 +451,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33327
33328 pmd->bl_info.tm = tm;
33329 pmd->bl_info.levels = 1;
33330- pmd->bl_info.value_type.context = pmd->data_sm;
33331+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33332 pmd->bl_info.value_type.size = sizeof(__le64);
33333 pmd->bl_info.value_type.inc = data_block_inc;
33334 pmd->bl_info.value_type.dec = data_block_dec;
33335diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33336index e24143c..ce2f21a1 100644
33337--- a/drivers/md/dm.c
33338+++ b/drivers/md/dm.c
33339@@ -176,9 +176,9 @@ struct mapped_device {
33340 /*
33341 * Event handling.
33342 */
33343- atomic_t event_nr;
33344+ atomic_unchecked_t event_nr;
33345 wait_queue_head_t eventq;
33346- atomic_t uevent_seq;
33347+ atomic_unchecked_t uevent_seq;
33348 struct list_head uevent_list;
33349 spinlock_t uevent_lock; /* Protect access to uevent_list */
33350
33351@@ -1845,8 +1845,8 @@ static struct mapped_device *alloc_dev(int minor)
33352 rwlock_init(&md->map_lock);
33353 atomic_set(&md->holders, 1);
33354 atomic_set(&md->open_count, 0);
33355- atomic_set(&md->event_nr, 0);
33356- atomic_set(&md->uevent_seq, 0);
33357+ atomic_set_unchecked(&md->event_nr, 0);
33358+ atomic_set_unchecked(&md->uevent_seq, 0);
33359 INIT_LIST_HEAD(&md->uevent_list);
33360 spin_lock_init(&md->uevent_lock);
33361
33362@@ -1980,7 +1980,7 @@ static void event_callback(void *context)
33363
33364 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33365
33366- atomic_inc(&md->event_nr);
33367+ atomic_inc_unchecked(&md->event_nr);
33368 wake_up(&md->eventq);
33369 }
33370
33371@@ -2622,18 +2622,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33372
33373 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33374 {
33375- return atomic_add_return(1, &md->uevent_seq);
33376+ return atomic_add_return_unchecked(1, &md->uevent_seq);
33377 }
33378
33379 uint32_t dm_get_event_nr(struct mapped_device *md)
33380 {
33381- return atomic_read(&md->event_nr);
33382+ return atomic_read_unchecked(&md->event_nr);
33383 }
33384
33385 int dm_wait_event(struct mapped_device *md, int event_nr)
33386 {
33387 return wait_event_interruptible(md->eventq,
33388- (event_nr != atomic_read(&md->event_nr)));
33389+ (event_nr != atomic_read_unchecked(&md->event_nr)));
33390 }
33391
33392 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33393diff --git a/drivers/md/md.c b/drivers/md/md.c
33394index d5ab449..7e9ed7b 100644
33395--- a/drivers/md/md.c
33396+++ b/drivers/md/md.c
33397@@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33398 * start build, activate spare
33399 */
33400 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33401-static atomic_t md_event_count;
33402+static atomic_unchecked_t md_event_count;
33403 void md_new_event(struct mddev *mddev)
33404 {
33405- atomic_inc(&md_event_count);
33406+ atomic_inc_unchecked(&md_event_count);
33407 wake_up(&md_event_waiters);
33408 }
33409 EXPORT_SYMBOL_GPL(md_new_event);
33410@@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33411 */
33412 static void md_new_event_inintr(struct mddev *mddev)
33413 {
33414- atomic_inc(&md_event_count);
33415+ atomic_inc_unchecked(&md_event_count);
33416 wake_up(&md_event_waiters);
33417 }
33418
33419@@ -1565,7 +1565,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33420 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
33421 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
33422 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
33423- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33424+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33425
33426 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33427 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33428@@ -1809,7 +1809,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33429 else
33430 sb->resync_offset = cpu_to_le64(0);
33431
33432- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33433+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33434
33435 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33436 sb->size = cpu_to_le64(mddev->dev_sectors);
33437@@ -2803,7 +2803,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33438 static ssize_t
33439 errors_show(struct md_rdev *rdev, char *page)
33440 {
33441- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33442+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33443 }
33444
33445 static ssize_t
33446@@ -2812,7 +2812,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33447 char *e;
33448 unsigned long n = simple_strtoul(buf, &e, 10);
33449 if (*buf && (*e == 0 || *e == '\n')) {
33450- atomic_set(&rdev->corrected_errors, n);
33451+ atomic_set_unchecked(&rdev->corrected_errors, n);
33452 return len;
33453 }
33454 return -EINVAL;
33455@@ -3259,8 +3259,8 @@ int md_rdev_init(struct md_rdev *rdev)
33456 rdev->sb_loaded = 0;
33457 rdev->bb_page = NULL;
33458 atomic_set(&rdev->nr_pending, 0);
33459- atomic_set(&rdev->read_errors, 0);
33460- atomic_set(&rdev->corrected_errors, 0);
33461+ atomic_set_unchecked(&rdev->read_errors, 0);
33462+ atomic_set_unchecked(&rdev->corrected_errors, 0);
33463
33464 INIT_LIST_HEAD(&rdev->same_set);
33465 init_waitqueue_head(&rdev->blocked_wait);
33466@@ -6997,7 +6997,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33467
33468 spin_unlock(&pers_lock);
33469 seq_printf(seq, "\n");
33470- seq->poll_event = atomic_read(&md_event_count);
33471+ seq->poll_event = atomic_read_unchecked(&md_event_count);
33472 return 0;
33473 }
33474 if (v == (void*)2) {
33475@@ -7100,7 +7100,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33476 return error;
33477
33478 seq = file->private_data;
33479- seq->poll_event = atomic_read(&md_event_count);
33480+ seq->poll_event = atomic_read_unchecked(&md_event_count);
33481 return error;
33482 }
33483
33484@@ -7114,7 +7114,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33485 /* always allow read */
33486 mask = POLLIN | POLLRDNORM;
33487
33488- if (seq->poll_event != atomic_read(&md_event_count))
33489+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33490 mask |= POLLERR | POLLPRI;
33491 return mask;
33492 }
33493@@ -7158,7 +7158,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33494 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33495 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33496 (int)part_stat_read(&disk->part0, sectors[1]) -
33497- atomic_read(&disk->sync_io);
33498+ atomic_read_unchecked(&disk->sync_io);
33499 /* sync IO will cause sync_io to increase before the disk_stats
33500 * as sync_io is counted when a request starts, and
33501 * disk_stats is counted when it completes.
33502diff --git a/drivers/md/md.h b/drivers/md/md.h
33503index 7b4a3c3..994ad4f 100644
33504--- a/drivers/md/md.h
33505+++ b/drivers/md/md.h
33506@@ -94,13 +94,13 @@ struct md_rdev {
33507 * only maintained for arrays that
33508 * support hot removal
33509 */
33510- atomic_t read_errors; /* number of consecutive read errors that
33511+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
33512 * we have tried to ignore.
33513 */
33514 struct timespec last_read_error; /* monotonic time since our
33515 * last read error
33516 */
33517- atomic_t corrected_errors; /* number of corrected read errors,
33518+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33519 * for reporting to userspace and storing
33520 * in superblock.
33521 */
33522@@ -435,7 +435,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33523
33524 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33525 {
33526- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33527+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33528 }
33529
33530 struct md_personality
33531diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
33532index fc90c11..c8cd9a9 100644
33533--- a/drivers/md/persistent-data/dm-space-map-checker.c
33534+++ b/drivers/md/persistent-data/dm-space-map-checker.c
33535@@ -167,7 +167,7 @@ static int ca_commit(struct count_array *old, struct count_array *new)
33536 /*----------------------------------------------------------------*/
33537
33538 struct sm_checker {
33539- struct dm_space_map sm;
33540+ dm_space_map_no_const sm;
33541
33542 struct count_array old_counts;
33543 struct count_array counts;
33544diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33545index 3d0ed53..35dc592 100644
33546--- a/drivers/md/persistent-data/dm-space-map-disk.c
33547+++ b/drivers/md/persistent-data/dm-space-map-disk.c
33548@@ -23,7 +23,7 @@
33549 * Space map interface.
33550 */
33551 struct sm_disk {
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-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33558index e89ae5e..062e4c2 100644
33559--- a/drivers/md/persistent-data/dm-space-map-metadata.c
33560+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33561@@ -43,7 +43,7 @@ struct block_op {
33562 };
33563
33564 struct sm_metadata {
33565- struct dm_space_map sm;
33566+ dm_space_map_no_const sm;
33567
33568 struct ll_disk ll;
33569 struct ll_disk old_ll;
33570diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33571index 1cbfc6b..56e1dbb 100644
33572--- a/drivers/md/persistent-data/dm-space-map.h
33573+++ b/drivers/md/persistent-data/dm-space-map.h
33574@@ -60,6 +60,7 @@ struct dm_space_map {
33575 int (*root_size)(struct dm_space_map *sm, size_t *result);
33576 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33577 };
33578+typedef struct dm_space_map __no_const dm_space_map_no_const;
33579
33580 /*----------------------------------------------------------------*/
33581
33582diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33583index 53aec45..250851c 100644
33584--- a/drivers/md/raid1.c
33585+++ b/drivers/md/raid1.c
33586@@ -1685,7 +1685,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33587 if (r1_sync_page_io(rdev, sect, s,
33588 bio->bi_io_vec[idx].bv_page,
33589 READ) != 0)
33590- atomic_add(s, &rdev->corrected_errors);
33591+ atomic_add_unchecked(s, &rdev->corrected_errors);
33592 }
33593 sectors -= s;
33594 sect += s;
33595@@ -1907,7 +1907,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33596 test_bit(In_sync, &rdev->flags)) {
33597 if (r1_sync_page_io(rdev, sect, s,
33598 conf->tmppage, READ)) {
33599- atomic_add(s, &rdev->corrected_errors);
33600+ atomic_add_unchecked(s, &rdev->corrected_errors);
33601 printk(KERN_INFO
33602 "md/raid1:%s: read error corrected "
33603 "(%d sectors at %llu on %s)\n",
33604diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33605index 8da6282..8ec7103 100644
33606--- a/drivers/md/raid10.c
33607+++ b/drivers/md/raid10.c
33608@@ -1784,7 +1784,7 @@ static void end_sync_read(struct bio *bio, int error)
33609 /* The write handler will notice the lack of
33610 * R10BIO_Uptodate and record any errors etc
33611 */
33612- atomic_add(r10_bio->sectors,
33613+ atomic_add_unchecked(r10_bio->sectors,
33614 &conf->mirrors[d].rdev->corrected_errors);
33615
33616 /* for reconstruct, we always reschedule after a read.
33617@@ -2133,7 +2133,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33618 {
33619 struct timespec cur_time_mon;
33620 unsigned long hours_since_last;
33621- unsigned int read_errors = atomic_read(&rdev->read_errors);
33622+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33623
33624 ktime_get_ts(&cur_time_mon);
33625
33626@@ -2155,9 +2155,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33627 * overflowing the shift of read_errors by hours_since_last.
33628 */
33629 if (hours_since_last >= 8 * sizeof(read_errors))
33630- atomic_set(&rdev->read_errors, 0);
33631+ atomic_set_unchecked(&rdev->read_errors, 0);
33632 else
33633- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33634+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33635 }
33636
33637 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33638@@ -2211,8 +2211,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33639 return;
33640
33641 check_decay_read_errors(mddev, rdev);
33642- atomic_inc(&rdev->read_errors);
33643- if (atomic_read(&rdev->read_errors) > max_read_errors) {
33644+ atomic_inc_unchecked(&rdev->read_errors);
33645+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33646 char b[BDEVNAME_SIZE];
33647 bdevname(rdev->bdev, b);
33648
33649@@ -2220,7 +2220,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33650 "md/raid10:%s: %s: Raid device exceeded "
33651 "read_error threshold [cur %d:max %d]\n",
33652 mdname(mddev), b,
33653- atomic_read(&rdev->read_errors), max_read_errors);
33654+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33655 printk(KERN_NOTICE
33656 "md/raid10:%s: %s: Failing raid device\n",
33657 mdname(mddev), b);
33658@@ -2375,7 +2375,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33659 sect +
33660 choose_data_offset(r10_bio, rdev)),
33661 bdevname(rdev->bdev, b));
33662- atomic_add(s, &rdev->corrected_errors);
33663+ atomic_add_unchecked(s, &rdev->corrected_errors);
33664 }
33665
33666 rdev_dec_pending(rdev, mddev);
33667diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33668index 04348d7..62a4b9b 100644
33669--- a/drivers/md/raid5.c
33670+++ b/drivers/md/raid5.c
33671@@ -1736,19 +1736,19 @@ static void raid5_end_read_request(struct bio * bi, int error)
33672 mdname(conf->mddev), STRIPE_SECTORS,
33673 (unsigned long long)s,
33674 bdevname(rdev->bdev, b));
33675- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33676+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33677 clear_bit(R5_ReadError, &sh->dev[i].flags);
33678 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33679 }
33680- if (atomic_read(&rdev->read_errors))
33681- atomic_set(&rdev->read_errors, 0);
33682+ if (atomic_read_unchecked(&rdev->read_errors))
33683+ atomic_set_unchecked(&rdev->read_errors, 0);
33684 } else {
33685 const char *bdn = bdevname(rdev->bdev, b);
33686 int retry = 0;
33687 int set_bad = 0;
33688
33689 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33690- atomic_inc(&rdev->read_errors);
33691+ atomic_inc_unchecked(&rdev->read_errors);
33692 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33693 printk_ratelimited(
33694 KERN_WARNING
33695@@ -1776,7 +1776,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33696 mdname(conf->mddev),
33697 (unsigned long long)s,
33698 bdn);
33699- } else if (atomic_read(&rdev->read_errors)
33700+ } else if (atomic_read_unchecked(&rdev->read_errors)
33701 > conf->max_nr_stripes)
33702 printk(KERN_WARNING
33703 "md/raid:%s: Too many read errors, failing device %s.\n",
33704diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33705index 131b938..8572ed1 100644
33706--- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33707+++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33708@@ -1678,7 +1678,7 @@ static struct ddb_info ddb_v6 = {
33709 .subvendor = _subvend, .subdevice = _subdev, \
33710 .driver_data = (unsigned long)&_driverdata }
33711
33712-static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33713+static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33714 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33715 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33716 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33717diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33718index fa7188a..04a045e 100644
33719--- a/drivers/media/dvb/dvb-core/dvb_demux.h
33720+++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33721@@ -73,7 +73,7 @@ struct dvb_demux_feed {
33722 union {
33723 dmx_ts_cb ts;
33724 dmx_section_cb sec;
33725- } cb;
33726+ } __no_const cb;
33727
33728 struct dvb_demux *demux;
33729 void *priv;
33730diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33731index 39eab73..60033e7 100644
33732--- a/drivers/media/dvb/dvb-core/dvbdev.c
33733+++ b/drivers/media/dvb/dvb-core/dvbdev.c
33734@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33735 const struct dvb_device *template, void *priv, int type)
33736 {
33737 struct dvb_device *dvbdev;
33738- struct file_operations *dvbdevfops;
33739+ file_operations_no_const *dvbdevfops;
33740 struct device *clsdev;
33741 int minor;
33742 int id;
33743diff --git a/drivers/media/dvb/dvb-usb/az6007.c b/drivers/media/dvb/dvb-usb/az6007.c
33744index 4008b9c..ce714f5 100644
33745--- a/drivers/media/dvb/dvb-usb/az6007.c
33746+++ b/drivers/media/dvb/dvb-usb/az6007.c
33747@@ -590,7 +590,7 @@ static int az6007_read_mac_addr(struct dvb_usb_device *d, u8 mac[6])
33748 int ret;
33749
33750 ret = az6007_read(d, AZ6007_READ_DATA, 6, 0, st->data, 6);
33751- memcpy(mac, st->data, sizeof(mac));
33752+ memcpy(mac, st->data, 6);
33753
33754 if (ret > 0)
33755 deb_info("%s: mac is %02x:%02x:%02x:%02x:%02x:%02x\n",
33756diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33757index 3940bb0..fb3952a 100644
33758--- a/drivers/media/dvb/dvb-usb/cxusb.c
33759+++ b/drivers/media/dvb/dvb-usb/cxusb.c
33760@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33761
33762 struct dib0700_adapter_state {
33763 int (*set_param_save) (struct dvb_frontend *);
33764-};
33765+} __no_const;
33766
33767 static int dib7070_set_param_override(struct dvb_frontend *fe)
33768 {
33769diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33770index 9382895..ac8093c 100644
33771--- a/drivers/media/dvb/dvb-usb/dw2102.c
33772+++ b/drivers/media/dvb/dvb-usb/dw2102.c
33773@@ -95,7 +95,7 @@ struct su3000_state {
33774
33775 struct s6x0_state {
33776 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33777-};
33778+} __no_const;
33779
33780 /* debug */
33781 static int dvb_usb_dw2102_debug;
33782diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33783index 404f63a..4796533 100644
33784--- a/drivers/media/dvb/frontends/dib3000.h
33785+++ b/drivers/media/dvb/frontends/dib3000.h
33786@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33787 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33788 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33789 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33790-};
33791+} __no_const;
33792
33793 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33794 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33795diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33796index 7539a5d..06531a6 100644
33797--- a/drivers/media/dvb/ngene/ngene-cards.c
33798+++ b/drivers/media/dvb/ngene/ngene-cards.c
33799@@ -478,7 +478,7 @@ static struct ngene_info ngene_info_m780 = {
33800
33801 /****************************************************************************/
33802
33803-static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33804+static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
33805 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
33806 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
33807 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
33808diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
33809index 16a089f..1661b11 100644
33810--- a/drivers/media/radio/radio-cadet.c
33811+++ b/drivers/media/radio/radio-cadet.c
33812@@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33813 unsigned char readbuf[RDS_BUFFER];
33814 int i = 0;
33815
33816+ if (count > RDS_BUFFER)
33817+ return -EFAULT;
33818 mutex_lock(&dev->lock);
33819 if (dev->rdsstat == 0) {
33820 dev->rdsstat = 1;
33821@@ -347,7 +349,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33822 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
33823 mutex_unlock(&dev->lock);
33824
33825- if (copy_to_user(data, readbuf, i))
33826+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
33827 return -EFAULT;
33828 return i;
33829 }
33830diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
33831index 9cde353..8c6a1c3 100644
33832--- a/drivers/media/video/au0828/au0828.h
33833+++ b/drivers/media/video/au0828/au0828.h
33834@@ -191,7 +191,7 @@ struct au0828_dev {
33835
33836 /* I2C */
33837 struct i2c_adapter i2c_adap;
33838- struct i2c_algorithm i2c_algo;
33839+ i2c_algorithm_no_const i2c_algo;
33840 struct i2c_client i2c_client;
33841 u32 i2c_rc;
33842
33843diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
33844index 04bf662..e0ac026 100644
33845--- a/drivers/media/video/cx88/cx88-alsa.c
33846+++ b/drivers/media/video/cx88/cx88-alsa.c
33847@@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
33848 * Only boards with eeprom and byte 1 at eeprom=1 have it
33849 */
33850
33851-static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
33852+static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
33853 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33854 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
33855 {0, }
33856diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
33857index 88cf9d9..bbc4b2c 100644
33858--- a/drivers/media/video/omap/omap_vout.c
33859+++ b/drivers/media/video/omap/omap_vout.c
33860@@ -64,7 +64,6 @@ enum omap_vout_channels {
33861 OMAP_VIDEO2,
33862 };
33863
33864-static struct videobuf_queue_ops video_vbq_ops;
33865 /* Variables configurable through module params*/
33866 static u32 video1_numbuffers = 3;
33867 static u32 video2_numbuffers = 3;
33868@@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
33869 {
33870 struct videobuf_queue *q;
33871 struct omap_vout_device *vout = NULL;
33872+ static struct videobuf_queue_ops video_vbq_ops = {
33873+ .buf_setup = omap_vout_buffer_setup,
33874+ .buf_prepare = omap_vout_buffer_prepare,
33875+ .buf_release = omap_vout_buffer_release,
33876+ .buf_queue = omap_vout_buffer_queue,
33877+ };
33878
33879 vout = video_drvdata(file);
33880 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
33881@@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
33882 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
33883
33884 q = &vout->vbq;
33885- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
33886- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
33887- video_vbq_ops.buf_release = omap_vout_buffer_release;
33888- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
33889 spin_lock_init(&vout->vbq_lock);
33890
33891 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
33892diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33893index 036952f..80d356d 100644
33894--- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33895+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
33896@@ -196,7 +196,7 @@ struct pvr2_hdw {
33897
33898 /* I2C stuff */
33899 struct i2c_adapter i2c_adap;
33900- struct i2c_algorithm i2c_algo;
33901+ i2c_algorithm_no_const i2c_algo;
33902 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
33903 int i2c_cx25840_hack_state;
33904 int i2c_linked;
33905diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
33906index 02194c0..091733b 100644
33907--- a/drivers/media/video/timblogiw.c
33908+++ b/drivers/media/video/timblogiw.c
33909@@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
33910
33911 /* Platform device functions */
33912
33913-static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33914+static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
33915 .vidioc_querycap = timblogiw_querycap,
33916 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
33917 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
33918@@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
33919 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
33920 };
33921
33922-static __devinitconst struct v4l2_file_operations timblogiw_fops = {
33923+static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
33924 .owner = THIS_MODULE,
33925 .open = timblogiw_open,
33926 .release = timblogiw_close,
33927diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
33928index d99db56..a16b959 100644
33929--- a/drivers/message/fusion/mptbase.c
33930+++ b/drivers/message/fusion/mptbase.c
33931@@ -6751,8 +6751,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
33932 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
33933 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
33934
33935+#ifdef CONFIG_GRKERNSEC_HIDESYM
33936+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
33937+#else
33938 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
33939 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
33940+#endif
33941+
33942 /*
33943 * Rounding UP to nearest 4-kB boundary here...
33944 */
33945diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
33946index 551262e..7551198 100644
33947--- a/drivers/message/fusion/mptsas.c
33948+++ b/drivers/message/fusion/mptsas.c
33949@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
33950 return 0;
33951 }
33952
33953+static inline void
33954+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33955+{
33956+ if (phy_info->port_details) {
33957+ phy_info->port_details->rphy = rphy;
33958+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33959+ ioc->name, rphy));
33960+ }
33961+
33962+ if (rphy) {
33963+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33964+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33965+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33966+ ioc->name, rphy, rphy->dev.release));
33967+ }
33968+}
33969+
33970 /* no mutex */
33971 static void
33972 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
33973@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
33974 return NULL;
33975 }
33976
33977-static inline void
33978-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
33979-{
33980- if (phy_info->port_details) {
33981- phy_info->port_details->rphy = rphy;
33982- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
33983- ioc->name, rphy));
33984- }
33985-
33986- if (rphy) {
33987- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
33988- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
33989- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
33990- ioc->name, rphy, rphy->dev.release));
33991- }
33992-}
33993-
33994 static inline struct sas_port *
33995 mptsas_get_port(struct mptsas_phyinfo *phy_info)
33996 {
33997diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
33998index 0c3ced7..1fe34ec 100644
33999--- a/drivers/message/fusion/mptscsih.c
34000+++ b/drivers/message/fusion/mptscsih.c
34001@@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34002
34003 h = shost_priv(SChost);
34004
34005- if (h) {
34006- if (h->info_kbuf == NULL)
34007- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34008- return h->info_kbuf;
34009- h->info_kbuf[0] = '\0';
34010+ if (!h)
34011+ return NULL;
34012
34013- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34014- h->info_kbuf[size-1] = '\0';
34015- }
34016+ if (h->info_kbuf == NULL)
34017+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34018+ return h->info_kbuf;
34019+ h->info_kbuf[0] = '\0';
34020+
34021+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34022+ h->info_kbuf[size-1] = '\0';
34023
34024 return h->info_kbuf;
34025 }
34026diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34027index 506c36f..b137580 100644
34028--- a/drivers/message/i2o/i2o_proc.c
34029+++ b/drivers/message/i2o/i2o_proc.c
34030@@ -255,13 +255,6 @@ static char *scsi_devices[] = {
34031 "Array Controller Device"
34032 };
34033
34034-static char *chtostr(u8 * chars, int n)
34035-{
34036- char tmp[256];
34037- tmp[0] = 0;
34038- return strncat(tmp, (char *)chars, n);
34039-}
34040-
34041 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34042 char *group)
34043 {
34044@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34045
34046 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34047 seq_printf(seq, "%-#8x", ddm_table.module_id);
34048- seq_printf(seq, "%-29s",
34049- chtostr(ddm_table.module_name_version, 28));
34050+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34051 seq_printf(seq, "%9d ", ddm_table.data_size);
34052 seq_printf(seq, "%8d", ddm_table.code_size);
34053
34054@@ -927,8 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34055
34056 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34057 seq_printf(seq, "%-#8x", dst->module_id);
34058- seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
34059- seq_printf(seq, "%-9s", chtostr(dst->date, 8));
34060+ seq_printf(seq, "%-.28s", dst->module_name_version);
34061+ seq_printf(seq, "%-.8s", dst->date);
34062 seq_printf(seq, "%8d ", dst->module_size);
34063 seq_printf(seq, "%8d ", dst->mpb_size);
34064 seq_printf(seq, "0x%04x", dst->module_flags);
34065@@ -1259,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34066 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34067 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34068 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34069- seq_printf(seq, "Vendor info : %s\n",
34070- chtostr((u8 *) (work32 + 2), 16));
34071- seq_printf(seq, "Product info : %s\n",
34072- chtostr((u8 *) (work32 + 6), 16));
34073- seq_printf(seq, "Description : %s\n",
34074- chtostr((u8 *) (work32 + 10), 16));
34075- seq_printf(seq, "Product rev. : %s\n",
34076- chtostr((u8 *) (work32 + 14), 8));
34077+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34078+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34079+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34080+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34081
34082 seq_printf(seq, "Serial number : ");
34083 print_serial_number(seq, (u8 *) (work32 + 16),
34084@@ -1311,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34085 }
34086
34087 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34088- seq_printf(seq, "Module name : %s\n",
34089- chtostr(result.module_name, 24));
34090- seq_printf(seq, "Module revision : %s\n",
34091- chtostr(result.module_rev, 8));
34092+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
34093+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34094
34095 seq_printf(seq, "Serial number : ");
34096 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34097@@ -1345,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34098 return 0;
34099 }
34100
34101- seq_printf(seq, "Device name : %s\n",
34102- chtostr(result.device_name, 64));
34103- seq_printf(seq, "Service name : %s\n",
34104- chtostr(result.service_name, 64));
34105- seq_printf(seq, "Physical name : %s\n",
34106- chtostr(result.physical_location, 64));
34107- seq_printf(seq, "Instance number : %s\n",
34108- chtostr(result.instance_number, 4));
34109+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
34110+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
34111+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34112+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34113
34114 return 0;
34115 }
34116diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34117index a8c08f3..155fe3d 100644
34118--- a/drivers/message/i2o/iop.c
34119+++ b/drivers/message/i2o/iop.c
34120@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34121
34122 spin_lock_irqsave(&c->context_list_lock, flags);
34123
34124- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34125- atomic_inc(&c->context_list_counter);
34126+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34127+ atomic_inc_unchecked(&c->context_list_counter);
34128
34129- entry->context = atomic_read(&c->context_list_counter);
34130+ entry->context = atomic_read_unchecked(&c->context_list_counter);
34131
34132 list_add(&entry->list, &c->context_list);
34133
34134@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34135
34136 #if BITS_PER_LONG == 64
34137 spin_lock_init(&c->context_list_lock);
34138- atomic_set(&c->context_list_counter, 0);
34139+ atomic_set_unchecked(&c->context_list_counter, 0);
34140 INIT_LIST_HEAD(&c->context_list);
34141 #endif
34142
34143diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34144index 7ce65f4..e66e9bc 100644
34145--- a/drivers/mfd/abx500-core.c
34146+++ b/drivers/mfd/abx500-core.c
34147@@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34148
34149 struct abx500_device_entry {
34150 struct list_head list;
34151- struct abx500_ops ops;
34152+ abx500_ops_no_const ops;
34153 struct device *dev;
34154 };
34155
34156diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34157index 2ea9998..51dabee 100644
34158--- a/drivers/mfd/janz-cmodio.c
34159+++ b/drivers/mfd/janz-cmodio.c
34160@@ -13,6 +13,7 @@
34161
34162 #include <linux/kernel.h>
34163 #include <linux/module.h>
34164+#include <linux/slab.h>
34165 #include <linux/init.h>
34166 #include <linux/pci.h>
34167 #include <linux/interrupt.h>
34168diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34169index a981e2a..5ca0c8b 100644
34170--- a/drivers/misc/lis3lv02d/lis3lv02d.c
34171+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34172@@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34173 * the lid is closed. This leads to interrupts as soon as a little move
34174 * is done.
34175 */
34176- atomic_inc(&lis3->count);
34177+ atomic_inc_unchecked(&lis3->count);
34178
34179 wake_up_interruptible(&lis3->misc_wait);
34180 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34181@@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34182 if (lis3->pm_dev)
34183 pm_runtime_get_sync(lis3->pm_dev);
34184
34185- atomic_set(&lis3->count, 0);
34186+ atomic_set_unchecked(&lis3->count, 0);
34187 return 0;
34188 }
34189
34190@@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34191 add_wait_queue(&lis3->misc_wait, &wait);
34192 while (true) {
34193 set_current_state(TASK_INTERRUPTIBLE);
34194- data = atomic_xchg(&lis3->count, 0);
34195+ data = atomic_xchg_unchecked(&lis3->count, 0);
34196 if (data)
34197 break;
34198
34199@@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34200 struct lis3lv02d, miscdev);
34201
34202 poll_wait(file, &lis3->misc_wait, wait);
34203- if (atomic_read(&lis3->count))
34204+ if (atomic_read_unchecked(&lis3->count))
34205 return POLLIN | POLLRDNORM;
34206 return 0;
34207 }
34208diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34209index 2b1482a..5d33616 100644
34210--- a/drivers/misc/lis3lv02d/lis3lv02d.h
34211+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34212@@ -266,7 +266,7 @@ struct lis3lv02d {
34213 struct input_polled_dev *idev; /* input device */
34214 struct platform_device *pdev; /* platform device */
34215 struct regulator_bulk_data regulators[2];
34216- atomic_t count; /* interrupt count after last read */
34217+ atomic_unchecked_t count; /* interrupt count after last read */
34218 union axis_conversion ac; /* hw -> logical axis */
34219 int mapped_btns[3];
34220
34221diff --git a/drivers/misc/lkdtm.c b/drivers/misc/lkdtm.c
34222index 28adefe..08aad69 100644
34223--- a/drivers/misc/lkdtm.c
34224+++ b/drivers/misc/lkdtm.c
34225@@ -477,6 +477,8 @@ static ssize_t lkdtm_debugfs_read(struct file *f, char __user *user_buf,
34226 int i, n, out;
34227
34228 buf = (char *)__get_free_page(GFP_KERNEL);
34229+ if (buf == NULL)
34230+ return -ENOMEM;
34231
34232 n = snprintf(buf, PAGE_SIZE, "Available crash types:\n");
34233 for (i = 0; i < ARRAY_SIZE(cp_type); i++)
34234diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34235index 2f30bad..c4c13d0 100644
34236--- a/drivers/misc/sgi-gru/gruhandles.c
34237+++ b/drivers/misc/sgi-gru/gruhandles.c
34238@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34239 unsigned long nsec;
34240
34241 nsec = CLKS2NSEC(clks);
34242- atomic_long_inc(&mcs_op_statistics[op].count);
34243- atomic_long_add(nsec, &mcs_op_statistics[op].total);
34244+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34245+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34246 if (mcs_op_statistics[op].max < nsec)
34247 mcs_op_statistics[op].max = nsec;
34248 }
34249diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34250index 950dbe9..eeef0f8 100644
34251--- a/drivers/misc/sgi-gru/gruprocfs.c
34252+++ b/drivers/misc/sgi-gru/gruprocfs.c
34253@@ -32,9 +32,9 @@
34254
34255 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34256
34257-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34258+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34259 {
34260- unsigned long val = atomic_long_read(v);
34261+ unsigned long val = atomic_long_read_unchecked(v);
34262
34263 seq_printf(s, "%16lu %s\n", val, id);
34264 }
34265@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34266
34267 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34268 for (op = 0; op < mcsop_last; op++) {
34269- count = atomic_long_read(&mcs_op_statistics[op].count);
34270- total = atomic_long_read(&mcs_op_statistics[op].total);
34271+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34272+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34273 max = mcs_op_statistics[op].max;
34274 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34275 count ? total / count : 0, max);
34276diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34277index 5c3ce24..4915ccb 100644
34278--- a/drivers/misc/sgi-gru/grutables.h
34279+++ b/drivers/misc/sgi-gru/grutables.h
34280@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34281 * GRU statistics.
34282 */
34283 struct gru_stats_s {
34284- atomic_long_t vdata_alloc;
34285- atomic_long_t vdata_free;
34286- atomic_long_t gts_alloc;
34287- atomic_long_t gts_free;
34288- atomic_long_t gms_alloc;
34289- atomic_long_t gms_free;
34290- atomic_long_t gts_double_allocate;
34291- atomic_long_t assign_context;
34292- atomic_long_t assign_context_failed;
34293- atomic_long_t free_context;
34294- atomic_long_t load_user_context;
34295- atomic_long_t load_kernel_context;
34296- atomic_long_t lock_kernel_context;
34297- atomic_long_t unlock_kernel_context;
34298- atomic_long_t steal_user_context;
34299- atomic_long_t steal_kernel_context;
34300- atomic_long_t steal_context_failed;
34301- atomic_long_t nopfn;
34302- atomic_long_t asid_new;
34303- atomic_long_t asid_next;
34304- atomic_long_t asid_wrap;
34305- atomic_long_t asid_reuse;
34306- atomic_long_t intr;
34307- atomic_long_t intr_cbr;
34308- atomic_long_t intr_tfh;
34309- atomic_long_t intr_spurious;
34310- atomic_long_t intr_mm_lock_failed;
34311- atomic_long_t call_os;
34312- atomic_long_t call_os_wait_queue;
34313- atomic_long_t user_flush_tlb;
34314- atomic_long_t user_unload_context;
34315- atomic_long_t user_exception;
34316- atomic_long_t set_context_option;
34317- atomic_long_t check_context_retarget_intr;
34318- atomic_long_t check_context_unload;
34319- atomic_long_t tlb_dropin;
34320- atomic_long_t tlb_preload_page;
34321- atomic_long_t tlb_dropin_fail_no_asid;
34322- atomic_long_t tlb_dropin_fail_upm;
34323- atomic_long_t tlb_dropin_fail_invalid;
34324- atomic_long_t tlb_dropin_fail_range_active;
34325- atomic_long_t tlb_dropin_fail_idle;
34326- atomic_long_t tlb_dropin_fail_fmm;
34327- atomic_long_t tlb_dropin_fail_no_exception;
34328- atomic_long_t tfh_stale_on_fault;
34329- atomic_long_t mmu_invalidate_range;
34330- atomic_long_t mmu_invalidate_page;
34331- atomic_long_t flush_tlb;
34332- atomic_long_t flush_tlb_gru;
34333- atomic_long_t flush_tlb_gru_tgh;
34334- atomic_long_t flush_tlb_gru_zero_asid;
34335+ atomic_long_unchecked_t vdata_alloc;
34336+ atomic_long_unchecked_t vdata_free;
34337+ atomic_long_unchecked_t gts_alloc;
34338+ atomic_long_unchecked_t gts_free;
34339+ atomic_long_unchecked_t gms_alloc;
34340+ atomic_long_unchecked_t gms_free;
34341+ atomic_long_unchecked_t gts_double_allocate;
34342+ atomic_long_unchecked_t assign_context;
34343+ atomic_long_unchecked_t assign_context_failed;
34344+ atomic_long_unchecked_t free_context;
34345+ atomic_long_unchecked_t load_user_context;
34346+ atomic_long_unchecked_t load_kernel_context;
34347+ atomic_long_unchecked_t lock_kernel_context;
34348+ atomic_long_unchecked_t unlock_kernel_context;
34349+ atomic_long_unchecked_t steal_user_context;
34350+ atomic_long_unchecked_t steal_kernel_context;
34351+ atomic_long_unchecked_t steal_context_failed;
34352+ atomic_long_unchecked_t nopfn;
34353+ atomic_long_unchecked_t asid_new;
34354+ atomic_long_unchecked_t asid_next;
34355+ atomic_long_unchecked_t asid_wrap;
34356+ atomic_long_unchecked_t asid_reuse;
34357+ atomic_long_unchecked_t intr;
34358+ atomic_long_unchecked_t intr_cbr;
34359+ atomic_long_unchecked_t intr_tfh;
34360+ atomic_long_unchecked_t intr_spurious;
34361+ atomic_long_unchecked_t intr_mm_lock_failed;
34362+ atomic_long_unchecked_t call_os;
34363+ atomic_long_unchecked_t call_os_wait_queue;
34364+ atomic_long_unchecked_t user_flush_tlb;
34365+ atomic_long_unchecked_t user_unload_context;
34366+ atomic_long_unchecked_t user_exception;
34367+ atomic_long_unchecked_t set_context_option;
34368+ atomic_long_unchecked_t check_context_retarget_intr;
34369+ atomic_long_unchecked_t check_context_unload;
34370+ atomic_long_unchecked_t tlb_dropin;
34371+ atomic_long_unchecked_t tlb_preload_page;
34372+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34373+ atomic_long_unchecked_t tlb_dropin_fail_upm;
34374+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
34375+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
34376+ atomic_long_unchecked_t tlb_dropin_fail_idle;
34377+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
34378+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34379+ atomic_long_unchecked_t tfh_stale_on_fault;
34380+ atomic_long_unchecked_t mmu_invalidate_range;
34381+ atomic_long_unchecked_t mmu_invalidate_page;
34382+ atomic_long_unchecked_t flush_tlb;
34383+ atomic_long_unchecked_t flush_tlb_gru;
34384+ atomic_long_unchecked_t flush_tlb_gru_tgh;
34385+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34386
34387- atomic_long_t copy_gpa;
34388- atomic_long_t read_gpa;
34389+ atomic_long_unchecked_t copy_gpa;
34390+ atomic_long_unchecked_t read_gpa;
34391
34392- atomic_long_t mesq_receive;
34393- atomic_long_t mesq_receive_none;
34394- atomic_long_t mesq_send;
34395- atomic_long_t mesq_send_failed;
34396- atomic_long_t mesq_noop;
34397- atomic_long_t mesq_send_unexpected_error;
34398- atomic_long_t mesq_send_lb_overflow;
34399- atomic_long_t mesq_send_qlimit_reached;
34400- atomic_long_t mesq_send_amo_nacked;
34401- atomic_long_t mesq_send_put_nacked;
34402- atomic_long_t mesq_page_overflow;
34403- atomic_long_t mesq_qf_locked;
34404- atomic_long_t mesq_qf_noop_not_full;
34405- atomic_long_t mesq_qf_switch_head_failed;
34406- atomic_long_t mesq_qf_unexpected_error;
34407- atomic_long_t mesq_noop_unexpected_error;
34408- atomic_long_t mesq_noop_lb_overflow;
34409- atomic_long_t mesq_noop_qlimit_reached;
34410- atomic_long_t mesq_noop_amo_nacked;
34411- atomic_long_t mesq_noop_put_nacked;
34412- atomic_long_t mesq_noop_page_overflow;
34413+ atomic_long_unchecked_t mesq_receive;
34414+ atomic_long_unchecked_t mesq_receive_none;
34415+ atomic_long_unchecked_t mesq_send;
34416+ atomic_long_unchecked_t mesq_send_failed;
34417+ atomic_long_unchecked_t mesq_noop;
34418+ atomic_long_unchecked_t mesq_send_unexpected_error;
34419+ atomic_long_unchecked_t mesq_send_lb_overflow;
34420+ atomic_long_unchecked_t mesq_send_qlimit_reached;
34421+ atomic_long_unchecked_t mesq_send_amo_nacked;
34422+ atomic_long_unchecked_t mesq_send_put_nacked;
34423+ atomic_long_unchecked_t mesq_page_overflow;
34424+ atomic_long_unchecked_t mesq_qf_locked;
34425+ atomic_long_unchecked_t mesq_qf_noop_not_full;
34426+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
34427+ atomic_long_unchecked_t mesq_qf_unexpected_error;
34428+ atomic_long_unchecked_t mesq_noop_unexpected_error;
34429+ atomic_long_unchecked_t mesq_noop_lb_overflow;
34430+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
34431+ atomic_long_unchecked_t mesq_noop_amo_nacked;
34432+ atomic_long_unchecked_t mesq_noop_put_nacked;
34433+ atomic_long_unchecked_t mesq_noop_page_overflow;
34434
34435 };
34436
34437@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34438 tghop_invalidate, mcsop_last};
34439
34440 struct mcs_op_statistic {
34441- atomic_long_t count;
34442- atomic_long_t total;
34443+ atomic_long_unchecked_t count;
34444+ atomic_long_unchecked_t total;
34445 unsigned long max;
34446 };
34447
34448@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34449
34450 #define STAT(id) do { \
34451 if (gru_options & OPT_STATS) \
34452- atomic_long_inc(&gru_stats.id); \
34453+ atomic_long_inc_unchecked(&gru_stats.id); \
34454 } while (0)
34455
34456 #ifdef CONFIG_SGI_GRU_DEBUG
34457diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34458index c862cd4..0d176fe 100644
34459--- a/drivers/misc/sgi-xp/xp.h
34460+++ b/drivers/misc/sgi-xp/xp.h
34461@@ -288,7 +288,7 @@ struct xpc_interface {
34462 xpc_notify_func, void *);
34463 void (*received) (short, int, void *);
34464 enum xp_retval (*partid_to_nasids) (short, void *);
34465-};
34466+} __no_const;
34467
34468 extern struct xpc_interface xpc_interface;
34469
34470diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34471index b94d5f7..7f494c5 100644
34472--- a/drivers/misc/sgi-xp/xpc.h
34473+++ b/drivers/misc/sgi-xp/xpc.h
34474@@ -835,6 +835,7 @@ struct xpc_arch_operations {
34475 void (*received_payload) (struct xpc_channel *, void *);
34476 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34477 };
34478+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34479
34480 /* struct xpc_partition act_state values (for XPC HB) */
34481
34482@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34483 /* found in xpc_main.c */
34484 extern struct device *xpc_part;
34485 extern struct device *xpc_chan;
34486-extern struct xpc_arch_operations xpc_arch_ops;
34487+extern xpc_arch_operations_no_const xpc_arch_ops;
34488 extern int xpc_disengage_timelimit;
34489 extern int xpc_disengage_timedout;
34490 extern int xpc_activate_IRQ_rcvd;
34491diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34492index 8d082b4..aa749ae 100644
34493--- a/drivers/misc/sgi-xp/xpc_main.c
34494+++ b/drivers/misc/sgi-xp/xpc_main.c
34495@@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34496 .notifier_call = xpc_system_die,
34497 };
34498
34499-struct xpc_arch_operations xpc_arch_ops;
34500+xpc_arch_operations_no_const xpc_arch_ops;
34501
34502 /*
34503 * Timer function to enforce the timelimit on the partition disengage.
34504diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c
34505index 2b62232..acfaeeb 100644
34506--- a/drivers/misc/ti-st/st_core.c
34507+++ b/drivers/misc/ti-st/st_core.c
34508@@ -349,6 +349,11 @@ void st_int_recv(void *disc_data,
34509 st_gdata->rx_skb = alloc_skb(
34510 st_gdata->list[type]->max_frame_size,
34511 GFP_ATOMIC);
34512+ if (st_gdata->rx_skb == NULL) {
34513+ pr_err("out of memory: dropping\n");
34514+ goto done;
34515+ }
34516+
34517 skb_reserve(st_gdata->rx_skb,
34518 st_gdata->list[type]->reserve);
34519 /* next 2 required for BT only */
34520diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34521index 504da71..9722d43 100644
34522--- a/drivers/mmc/host/sdhci-pci.c
34523+++ b/drivers/mmc/host/sdhci-pci.c
34524@@ -653,7 +653,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34525 .probe = via_probe,
34526 };
34527
34528-static const struct pci_device_id pci_ids[] __devinitdata = {
34529+static const struct pci_device_id pci_ids[] __devinitconst = {
34530 {
34531 .vendor = PCI_VENDOR_ID_RICOH,
34532 .device = PCI_DEVICE_ID_RICOH_R5C822,
34533diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34534index a4eb8b5..8c0628f 100644
34535--- a/drivers/mtd/devices/doc2000.c
34536+++ b/drivers/mtd/devices/doc2000.c
34537@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34538
34539 /* The ECC will not be calculated correctly if less than 512 is written */
34540 /* DBB-
34541- if (len != 0x200 && eccbuf)
34542+ if (len != 0x200)
34543 printk(KERN_WARNING
34544 "ECC needs a full sector write (adr: %lx size %lx)\n",
34545 (long) to, (long) len);
34546diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34547index 0650aaf..7718762 100644
34548--- a/drivers/mtd/nand/denali.c
34549+++ b/drivers/mtd/nand/denali.c
34550@@ -26,6 +26,7 @@
34551 #include <linux/pci.h>
34552 #include <linux/mtd/mtd.h>
34553 #include <linux/module.h>
34554+#include <linux/slab.h>
34555
34556 #include "denali.h"
34557
34558diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34559index 51b9d6a..52af9a7 100644
34560--- a/drivers/mtd/nftlmount.c
34561+++ b/drivers/mtd/nftlmount.c
34562@@ -24,6 +24,7 @@
34563 #include <asm/errno.h>
34564 #include <linux/delay.h>
34565 #include <linux/slab.h>
34566+#include <linux/sched.h>
34567 #include <linux/mtd/mtd.h>
34568 #include <linux/mtd/nand.h>
34569 #include <linux/mtd/nftl.h>
34570diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34571index 6762dc4..9956862 100644
34572--- a/drivers/net/ethernet/atheros/atlx/atl2.c
34573+++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34574@@ -2859,7 +2859,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34575 */
34576
34577 #define ATL2_PARAM(X, desc) \
34578- static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34579+ static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34580 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34581 MODULE_PARM_DESC(X, desc);
34582 #else
34583diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34584index efd80bd..21fcff0 100644
34585--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34586+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34587@@ -487,7 +487,7 @@ struct bnx2x_rx_mode_obj {
34588
34589 int (*wait_comp)(struct bnx2x *bp,
34590 struct bnx2x_rx_mode_ramrod_params *p);
34591-};
34592+} __no_const;
34593
34594 /********************** Set multicast group ***********************************/
34595
34596diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34597index 93865f8..5448741 100644
34598--- a/drivers/net/ethernet/broadcom/tg3.h
34599+++ b/drivers/net/ethernet/broadcom/tg3.h
34600@@ -140,6 +140,7 @@
34601 #define CHIPREV_ID_5750_A0 0x4000
34602 #define CHIPREV_ID_5750_A1 0x4001
34603 #define CHIPREV_ID_5750_A3 0x4003
34604+#define CHIPREV_ID_5750_C1 0x4201
34605 #define CHIPREV_ID_5750_C2 0x4202
34606 #define CHIPREV_ID_5752_A0_HW 0x5000
34607 #define CHIPREV_ID_5752_A0 0x6000
34608diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34609index c4e8643..0979484 100644
34610--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34611+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34612@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34613 */
34614 struct l2t_skb_cb {
34615 arp_failure_handler_func arp_failure_handler;
34616-};
34617+} __no_const;
34618
34619 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34620
34621diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34622index d3cd489..0fd52dd 100644
34623--- a/drivers/net/ethernet/dec/tulip/de4x5.c
34624+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34625@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34626 for (i=0; i<ETH_ALEN; i++) {
34627 tmp.addr[i] = dev->dev_addr[i];
34628 }
34629- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34630+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34631 break;
34632
34633 case DE4X5_SET_HWADDR: /* Set the hardware address */
34634@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34635 spin_lock_irqsave(&lp->lock, flags);
34636 memcpy(&statbuf, &lp->pktStats, ioc->len);
34637 spin_unlock_irqrestore(&lp->lock, flags);
34638- if (copy_to_user(ioc->data, &statbuf, ioc->len))
34639+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34640 return -EFAULT;
34641 break;
34642 }
34643diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34644index ed7d1dc..d426748 100644
34645--- a/drivers/net/ethernet/dec/tulip/eeprom.c
34646+++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34647@@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34648 {NULL}};
34649
34650
34651-static const char *block_name[] __devinitdata = {
34652+static const char *block_name[] __devinitconst = {
34653 "21140 non-MII",
34654 "21140 MII PHY",
34655 "21142 Serial PHY",
34656diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
34657index 75d45f8..3d9c55b 100644
34658--- a/drivers/net/ethernet/dec/tulip/uli526x.c
34659+++ b/drivers/net/ethernet/dec/tulip/uli526x.c
34660@@ -129,7 +129,7 @@ struct uli526x_board_info {
34661 struct uli_phy_ops {
34662 void (*write)(struct uli526x_board_info *, u8, u8, u16);
34663 u16 (*read)(struct uli526x_board_info *, u8, u8);
34664- } phy;
34665+ } __no_const phy;
34666 struct net_device *next_dev; /* next device */
34667 struct pci_dev *pdev; /* PCI device */
34668 spinlock_t lock;
34669diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34670index 4d1ffca..7c1ec4d 100644
34671--- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34672+++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34673@@ -236,7 +236,7 @@ struct pci_id_info {
34674 int drv_flags; /* Driver use, intended as capability flags. */
34675 };
34676
34677-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34678+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34679 { /* Sometime a Level-One switch card. */
34680 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34681 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34682diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34683index d7bb52a..3b83588 100644
34684--- a/drivers/net/ethernet/dlink/sundance.c
34685+++ b/drivers/net/ethernet/dlink/sundance.c
34686@@ -218,7 +218,7 @@ enum {
34687 struct pci_id_info {
34688 const char *name;
34689 };
34690-static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34691+static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34692 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34693 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34694 {"D-Link DFE-580TX 4 port Server Adapter"},
34695diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34696index bd5cf7e..c165651 100644
34697--- a/drivers/net/ethernet/emulex/benet/be_main.c
34698+++ b/drivers/net/ethernet/emulex/benet/be_main.c
34699@@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34700
34701 if (wrapped)
34702 newacc += 65536;
34703- ACCESS_ONCE(*acc) = newacc;
34704+ ACCESS_ONCE_RW(*acc) = newacc;
34705 }
34706
34707 void be_parse_stats(struct be_adapter *adapter)
34708diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34709index 16b0704..d2c07d7 100644
34710--- a/drivers/net/ethernet/faraday/ftgmac100.c
34711+++ b/drivers/net/ethernet/faraday/ftgmac100.c
34712@@ -31,6 +31,8 @@
34713 #include <linux/netdevice.h>
34714 #include <linux/phy.h>
34715 #include <linux/platform_device.h>
34716+#include <linux/interrupt.h>
34717+#include <linux/irqreturn.h>
34718 #include <net/ip.h>
34719
34720 #include "ftgmac100.h"
34721diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34722index 829b109..4ae5f6a 100644
34723--- a/drivers/net/ethernet/faraday/ftmac100.c
34724+++ b/drivers/net/ethernet/faraday/ftmac100.c
34725@@ -31,6 +31,8 @@
34726 #include <linux/module.h>
34727 #include <linux/netdevice.h>
34728 #include <linux/platform_device.h>
34729+#include <linux/interrupt.h>
34730+#include <linux/irqreturn.h>
34731
34732 #include "ftmac100.h"
34733
34734diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34735index 9d71c9c..0e4a0ac 100644
34736--- a/drivers/net/ethernet/fealnx.c
34737+++ b/drivers/net/ethernet/fealnx.c
34738@@ -150,7 +150,7 @@ struct chip_info {
34739 int flags;
34740 };
34741
34742-static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
34743+static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
34744 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34745 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
34746 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34747diff --git a/drivers/net/ethernet/intel/e1000e/e1000.h b/drivers/net/ethernet/intel/e1000e/e1000.h
34748index 6e6fffb..588f361 100644
34749--- a/drivers/net/ethernet/intel/e1000e/e1000.h
34750+++ b/drivers/net/ethernet/intel/e1000e/e1000.h
34751@@ -181,7 +181,7 @@ struct e1000_info;
34752 #define E1000_TXDCTL_DMA_BURST_ENABLE \
34753 (E1000_TXDCTL_GRAN | /* set descriptor granularity */ \
34754 E1000_TXDCTL_COUNT_DESC | \
34755- (5 << 16) | /* wthresh must be +1 more than desired */\
34756+ (1 << 16) | /* wthresh must be +1 more than desired */\
34757 (1 << 8) | /* hthresh */ \
34758 0x1f) /* pthresh */
34759
34760diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34761index ed5b409..ec37828 100644
34762--- a/drivers/net/ethernet/intel/e1000e/hw.h
34763+++ b/drivers/net/ethernet/intel/e1000e/hw.h
34764@@ -797,6 +797,7 @@ struct e1000_mac_operations {
34765 void (*rar_set)(struct e1000_hw *, u8 *, u32);
34766 s32 (*read_mac_addr)(struct e1000_hw *);
34767 };
34768+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34769
34770 /*
34771 * When to use various PHY register access functions:
34772@@ -837,6 +838,7 @@ struct e1000_phy_operations {
34773 void (*power_up)(struct e1000_hw *);
34774 void (*power_down)(struct e1000_hw *);
34775 };
34776+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34777
34778 /* Function pointers for the NVM. */
34779 struct e1000_nvm_operations {
34780@@ -849,9 +851,10 @@ struct e1000_nvm_operations {
34781 s32 (*validate)(struct e1000_hw *);
34782 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34783 };
34784+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34785
34786 struct e1000_mac_info {
34787- struct e1000_mac_operations ops;
34788+ e1000_mac_operations_no_const ops;
34789 u8 addr[ETH_ALEN];
34790 u8 perm_addr[ETH_ALEN];
34791
34792@@ -892,7 +895,7 @@ struct e1000_mac_info {
34793 };
34794
34795 struct e1000_phy_info {
34796- struct e1000_phy_operations ops;
34797+ e1000_phy_operations_no_const ops;
34798
34799 enum e1000_phy_type type;
34800
34801@@ -926,7 +929,7 @@ struct e1000_phy_info {
34802 };
34803
34804 struct e1000_nvm_info {
34805- struct e1000_nvm_operations ops;
34806+ e1000_nvm_operations_no_const ops;
34807
34808 enum e1000_nvm_type type;
34809 enum e1000_nvm_override override;
34810diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
34811index c2a51dc..c2bd262 100644
34812--- a/drivers/net/ethernet/intel/igb/e1000_hw.h
34813+++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
34814@@ -327,6 +327,7 @@ struct e1000_mac_operations {
34815 void (*release_swfw_sync)(struct e1000_hw *, u16);
34816
34817 };
34818+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34819
34820 struct e1000_phy_operations {
34821 s32 (*acquire)(struct e1000_hw *);
34822@@ -343,6 +344,7 @@ struct e1000_phy_operations {
34823 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
34824 s32 (*write_reg)(struct e1000_hw *, u32, u16);
34825 };
34826+typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34827
34828 struct e1000_nvm_operations {
34829 s32 (*acquire)(struct e1000_hw *);
34830@@ -353,6 +355,7 @@ struct e1000_nvm_operations {
34831 s32 (*validate)(struct e1000_hw *);
34832 s32 (*valid_led_default)(struct e1000_hw *, u16 *);
34833 };
34834+typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34835
34836 struct e1000_info {
34837 s32 (*get_invariants)(struct e1000_hw *);
34838@@ -364,7 +367,7 @@ struct e1000_info {
34839 extern const struct e1000_info e1000_82575_info;
34840
34841 struct e1000_mac_info {
34842- struct e1000_mac_operations ops;
34843+ e1000_mac_operations_no_const ops;
34844
34845 u8 addr[6];
34846 u8 perm_addr[6];
34847@@ -402,7 +405,7 @@ struct e1000_mac_info {
34848 };
34849
34850 struct e1000_phy_info {
34851- struct e1000_phy_operations ops;
34852+ e1000_phy_operations_no_const ops;
34853
34854 enum e1000_phy_type type;
34855
34856@@ -437,7 +440,7 @@ struct e1000_phy_info {
34857 };
34858
34859 struct e1000_nvm_info {
34860- struct e1000_nvm_operations ops;
34861+ e1000_nvm_operations_no_const ops;
34862 enum e1000_nvm_type type;
34863 enum e1000_nvm_override override;
34864
34865@@ -482,6 +485,7 @@ struct e1000_mbx_operations {
34866 s32 (*check_for_ack)(struct e1000_hw *, u16);
34867 s32 (*check_for_rst)(struct e1000_hw *, u16);
34868 };
34869+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34870
34871 struct e1000_mbx_stats {
34872 u32 msgs_tx;
34873@@ -493,7 +497,7 @@ struct e1000_mbx_stats {
34874 };
34875
34876 struct e1000_mbx_info {
34877- struct e1000_mbx_operations ops;
34878+ e1000_mbx_operations_no_const ops;
34879 struct e1000_mbx_stats stats;
34880 u32 timeout;
34881 u32 usec_delay;
34882diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
34883index 57db3c6..aa825fc 100644
34884--- a/drivers/net/ethernet/intel/igbvf/vf.h
34885+++ b/drivers/net/ethernet/intel/igbvf/vf.h
34886@@ -189,9 +189,10 @@ struct e1000_mac_operations {
34887 s32 (*read_mac_addr)(struct e1000_hw *);
34888 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
34889 };
34890+typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34891
34892 struct e1000_mac_info {
34893- struct e1000_mac_operations ops;
34894+ e1000_mac_operations_no_const ops;
34895 u8 addr[6];
34896 u8 perm_addr[6];
34897
34898@@ -213,6 +214,7 @@ struct e1000_mbx_operations {
34899 s32 (*check_for_ack)(struct e1000_hw *);
34900 s32 (*check_for_rst)(struct e1000_hw *);
34901 };
34902+typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
34903
34904 struct e1000_mbx_stats {
34905 u32 msgs_tx;
34906@@ -224,7 +226,7 @@ struct e1000_mbx_stats {
34907 };
34908
34909 struct e1000_mbx_info {
34910- struct e1000_mbx_operations ops;
34911+ e1000_mbx_operations_no_const ops;
34912 struct e1000_mbx_stats stats;
34913 u32 timeout;
34914 u32 usec_delay;
34915diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34916index dcebd12..c1fe8be 100644
34917--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34918+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
34919@@ -805,7 +805,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
34920 /* store the new cycle speed */
34921 adapter->cycle_speed = cycle_speed;
34922
34923- ACCESS_ONCE(adapter->base_incval) = incval;
34924+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
34925 smp_mb();
34926
34927 /* grab the ptp lock */
34928diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34929index 204848d..d8aeaec 100644
34930--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34931+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
34932@@ -2791,6 +2791,7 @@ struct ixgbe_eeprom_operations {
34933 s32 (*update_checksum)(struct ixgbe_hw *);
34934 u16 (*calc_checksum)(struct ixgbe_hw *);
34935 };
34936+typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
34937
34938 struct ixgbe_mac_operations {
34939 s32 (*init_hw)(struct ixgbe_hw *);
34940@@ -2856,6 +2857,7 @@ struct ixgbe_mac_operations {
34941 s32 (*get_thermal_sensor_data)(struct ixgbe_hw *);
34942 s32 (*init_thermal_sensor_thresh)(struct ixgbe_hw *hw);
34943 };
34944+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
34945
34946 struct ixgbe_phy_operations {
34947 s32 (*identify)(struct ixgbe_hw *);
34948@@ -2875,9 +2877,10 @@ struct ixgbe_phy_operations {
34949 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
34950 s32 (*check_overtemp)(struct ixgbe_hw *);
34951 };
34952+typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
34953
34954 struct ixgbe_eeprom_info {
34955- struct ixgbe_eeprom_operations ops;
34956+ ixgbe_eeprom_operations_no_const ops;
34957 enum ixgbe_eeprom_type type;
34958 u32 semaphore_delay;
34959 u16 word_size;
34960@@ -2887,7 +2890,7 @@ struct ixgbe_eeprom_info {
34961
34962 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
34963 struct ixgbe_mac_info {
34964- struct ixgbe_mac_operations ops;
34965+ ixgbe_mac_operations_no_const ops;
34966 enum ixgbe_mac_type type;
34967 u8 addr[ETH_ALEN];
34968 u8 perm_addr[ETH_ALEN];
34969@@ -2916,7 +2919,7 @@ struct ixgbe_mac_info {
34970 };
34971
34972 struct ixgbe_phy_info {
34973- struct ixgbe_phy_operations ops;
34974+ ixgbe_phy_operations_no_const ops;
34975 struct mdio_if_info mdio;
34976 enum ixgbe_phy_type type;
34977 u32 id;
34978@@ -2944,6 +2947,7 @@ struct ixgbe_mbx_operations {
34979 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
34980 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
34981 };
34982+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
34983
34984 struct ixgbe_mbx_stats {
34985 u32 msgs_tx;
34986@@ -2955,7 +2959,7 @@ struct ixgbe_mbx_stats {
34987 };
34988
34989 struct ixgbe_mbx_info {
34990- struct ixgbe_mbx_operations ops;
34991+ ixgbe_mbx_operations_no_const ops;
34992 struct ixgbe_mbx_stats stats;
34993 u32 timeout;
34994 u32 usec_delay;
34995diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
34996index 25c951d..cc7cf33 100644
34997--- a/drivers/net/ethernet/intel/ixgbevf/vf.h
34998+++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
34999@@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35000 s32 (*clear_vfta)(struct ixgbe_hw *);
35001 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35002 };
35003+typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35004
35005 enum ixgbe_mac_type {
35006 ixgbe_mac_unknown = 0,
35007@@ -79,7 +80,7 @@ enum ixgbe_mac_type {
35008 };
35009
35010 struct ixgbe_mac_info {
35011- struct ixgbe_mac_operations ops;
35012+ ixgbe_mac_operations_no_const ops;
35013 u8 addr[6];
35014 u8 perm_addr[6];
35015
35016@@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35017 s32 (*check_for_ack)(struct ixgbe_hw *);
35018 s32 (*check_for_rst)(struct ixgbe_hw *);
35019 };
35020+typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35021
35022 struct ixgbe_mbx_stats {
35023 u32 msgs_tx;
35024@@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35025 };
35026
35027 struct ixgbe_mbx_info {
35028- struct ixgbe_mbx_operations ops;
35029+ ixgbe_mbx_operations_no_const ops;
35030 struct ixgbe_mbx_stats stats;
35031 u32 timeout;
35032 u32 udelay;
35033diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
35034index a0313de..e83a572 100644
35035--- a/drivers/net/ethernet/mellanox/mlx4/main.c
35036+++ b/drivers/net/ethernet/mellanox/mlx4/main.c
35037@@ -41,6 +41,7 @@
35038 #include <linux/slab.h>
35039 #include <linux/io-mapping.h>
35040 #include <linux/delay.h>
35041+#include <linux/sched.h>
35042
35043 #include <linux/mlx4/device.h>
35044 #include <linux/mlx4/doorbell.h>
35045diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35046index 5046a64..71ca936 100644
35047--- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35048+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35049@@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35050 void (*link_down)(struct __vxge_hw_device *devh);
35051 void (*crit_err)(struct __vxge_hw_device *devh,
35052 enum vxge_hw_event type, u64 ext_data);
35053-};
35054+} __no_const;
35055
35056 /*
35057 * struct __vxge_hw_blockpool_entry - Block private data structure
35058diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35059index 4a518a3..936b334 100644
35060--- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35061+++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35062@@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35063 struct vxge_hw_mempool_dma *dma_object,
35064 u32 index,
35065 u32 is_last);
35066-};
35067+} __no_const;
35068
35069 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35070 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35071diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35072index eb81da4..1592b62 100644
35073--- a/drivers/net/ethernet/realtek/r8169.c
35074+++ b/drivers/net/ethernet/realtek/r8169.c
35075@@ -723,22 +723,22 @@ struct rtl8169_private {
35076 struct mdio_ops {
35077 void (*write)(void __iomem *, int, int);
35078 int (*read)(void __iomem *, int);
35079- } mdio_ops;
35080+ } __no_const mdio_ops;
35081
35082 struct pll_power_ops {
35083 void (*down)(struct rtl8169_private *);
35084 void (*up)(struct rtl8169_private *);
35085- } pll_power_ops;
35086+ } __no_const pll_power_ops;
35087
35088 struct jumbo_ops {
35089 void (*enable)(struct rtl8169_private *);
35090 void (*disable)(struct rtl8169_private *);
35091- } jumbo_ops;
35092+ } __no_const jumbo_ops;
35093
35094 struct csi_ops {
35095 void (*write)(void __iomem *, int, int);
35096 u32 (*read)(void __iomem *, int);
35097- } csi_ops;
35098+ } __no_const csi_ops;
35099
35100 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35101 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35102diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35103index 4613591..d816601 100644
35104--- a/drivers/net/ethernet/sis/sis190.c
35105+++ b/drivers/net/ethernet/sis/sis190.c
35106@@ -1618,7 +1618,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35107 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35108 struct net_device *dev)
35109 {
35110- static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35111+ static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35112 struct sis190_private *tp = netdev_priv(dev);
35113 struct pci_dev *isa_bridge;
35114 u8 reg, tmp8;
35115diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35116index c07cfe9..81cbf7e 100644
35117--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35118+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35119@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35120
35121 writel(value, ioaddr + MMC_CNTRL);
35122
35123- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35124- MMC_CNTRL, value);
35125+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35126+// MMC_CNTRL, value);
35127 }
35128
35129 /* To mask all all interrupts.*/
35130diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35131index 2857ab0..9a1f9b0 100644
35132--- a/drivers/net/hyperv/hyperv_net.h
35133+++ b/drivers/net/hyperv/hyperv_net.h
35134@@ -99,7 +99,7 @@ struct rndis_device {
35135
35136 enum rndis_device_state state;
35137 bool link_state;
35138- atomic_t new_req_id;
35139+ atomic_unchecked_t new_req_id;
35140
35141 spinlock_t request_lock;
35142 struct list_head req_list;
35143diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35144index 981ebb1..b34959b 100644
35145--- a/drivers/net/hyperv/rndis_filter.c
35146+++ b/drivers/net/hyperv/rndis_filter.c
35147@@ -97,7 +97,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35148 * template
35149 */
35150 set = &rndis_msg->msg.set_req;
35151- set->req_id = atomic_inc_return(&dev->new_req_id);
35152+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35153
35154 /* Add to the request list */
35155 spin_lock_irqsave(&dev->request_lock, flags);
35156@@ -648,7 +648,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35157
35158 /* Setup the rndis set */
35159 halt = &request->request_msg.msg.halt_req;
35160- halt->req_id = atomic_inc_return(&dev->new_req_id);
35161+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35162
35163 /* Ignore return since this msg is optional. */
35164 rndis_filter_send_request(dev, request);
35165diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35166index 5c05572..389610b 100644
35167--- a/drivers/net/ppp/ppp_generic.c
35168+++ b/drivers/net/ppp/ppp_generic.c
35169@@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35170 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35171 struct ppp_stats stats;
35172 struct ppp_comp_stats cstats;
35173- char *vers;
35174
35175 switch (cmd) {
35176 case SIOCGPPPSTATS:
35177@@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35178 break;
35179
35180 case SIOCGPPPVER:
35181- vers = PPP_VERSION;
35182- if (copy_to_user(addr, vers, strlen(vers) + 1))
35183+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35184 break;
35185 err = 0;
35186 break;
35187diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35188index 62f30b4..ff99dfd 100644
35189--- a/drivers/net/usb/hso.c
35190+++ b/drivers/net/usb/hso.c
35191@@ -71,7 +71,7 @@
35192 #include <asm/byteorder.h>
35193 #include <linux/serial_core.h>
35194 #include <linux/serial.h>
35195-
35196+#include <asm/local.h>
35197
35198 #define MOD_AUTHOR "Option Wireless"
35199 #define MOD_DESCRIPTION "USB High Speed Option driver"
35200@@ -1182,7 +1182,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35201 struct urb *urb;
35202
35203 urb = serial->rx_urb[0];
35204- if (serial->port.count > 0) {
35205+ if (atomic_read(&serial->port.count) > 0) {
35206 count = put_rxbuf_data(urb, serial);
35207 if (count == -1)
35208 return;
35209@@ -1218,7 +1218,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35210 DUMP1(urb->transfer_buffer, urb->actual_length);
35211
35212 /* Anyone listening? */
35213- if (serial->port.count == 0)
35214+ if (atomic_read(&serial->port.count) == 0)
35215 return;
35216
35217 if (status == 0) {
35218@@ -1300,8 +1300,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35219 tty_port_tty_set(&serial->port, tty);
35220
35221 /* check for port already opened, if not set the termios */
35222- serial->port.count++;
35223- if (serial->port.count == 1) {
35224+ if (atomic_inc_return(&serial->port.count) == 1) {
35225 serial->rx_state = RX_IDLE;
35226 /* Force default termio settings */
35227 _hso_serial_set_termios(tty, NULL);
35228@@ -1313,7 +1312,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35229 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35230 if (result) {
35231 hso_stop_serial_device(serial->parent);
35232- serial->port.count--;
35233+ atomic_dec(&serial->port.count);
35234 kref_put(&serial->parent->ref, hso_serial_ref_free);
35235 }
35236 } else {
35237@@ -1350,10 +1349,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35238
35239 /* reset the rts and dtr */
35240 /* do the actual close */
35241- serial->port.count--;
35242+ atomic_dec(&serial->port.count);
35243
35244- if (serial->port.count <= 0) {
35245- serial->port.count = 0;
35246+ if (atomic_read(&serial->port.count) <= 0) {
35247+ atomic_set(&serial->port.count, 0);
35248 tty_port_tty_set(&serial->port, NULL);
35249 if (!usb_gone)
35250 hso_stop_serial_device(serial->parent);
35251@@ -1429,7 +1428,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35252
35253 /* the actual setup */
35254 spin_lock_irqsave(&serial->serial_lock, flags);
35255- if (serial->port.count)
35256+ if (atomic_read(&serial->port.count))
35257 _hso_serial_set_termios(tty, old);
35258 else
35259 tty->termios = old;
35260@@ -1888,7 +1887,7 @@ static void intr_callback(struct urb *urb)
35261 D1("Pending read interrupt on port %d\n", i);
35262 spin_lock(&serial->serial_lock);
35263 if (serial->rx_state == RX_IDLE &&
35264- serial->port.count > 0) {
35265+ atomic_read(&serial->port.count) > 0) {
35266 /* Setup and send a ctrl req read on
35267 * port i */
35268 if (!serial->rx_urb_filled[0]) {
35269@@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
35270 /* Start all serial ports */
35271 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35272 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35273- if (dev2ser(serial_table[i])->port.count) {
35274+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
35275 result =
35276 hso_start_serial_device(serial_table[i], GFP_NOIO);
35277 hso_kick_transmit(dev2ser(serial_table[i]));
35278diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35279index 420d69b..74f90a2 100644
35280--- a/drivers/net/wireless/ath/ath.h
35281+++ b/drivers/net/wireless/ath/ath.h
35282@@ -119,6 +119,7 @@ struct ath_ops {
35283 void (*write_flush) (void *);
35284 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35285 };
35286+typedef struct ath_ops __no_const ath_ops_no_const;
35287
35288 struct ath_common;
35289 struct ath_bus_ops;
35290diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35291index 8d78253..bebbb68 100644
35292--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35293+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35294@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35295 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35296 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35297
35298- ACCESS_ONCE(ads->ds_link) = i->link;
35299- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35300+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
35301+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35302
35303 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35304 ctl6 = SM(i->keytype, AR_EncrType);
35305@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35306
35307 if ((i->is_first || i->is_last) &&
35308 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35309- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35310+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35311 | set11nTries(i->rates, 1)
35312 | set11nTries(i->rates, 2)
35313 | set11nTries(i->rates, 3)
35314 | (i->dur_update ? AR_DurUpdateEna : 0)
35315 | SM(0, AR_BurstDur);
35316
35317- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35318+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35319 | set11nRate(i->rates, 1)
35320 | set11nRate(i->rates, 2)
35321 | set11nRate(i->rates, 3);
35322 } else {
35323- ACCESS_ONCE(ads->ds_ctl2) = 0;
35324- ACCESS_ONCE(ads->ds_ctl3) = 0;
35325+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35326+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35327 }
35328
35329 if (!i->is_first) {
35330- ACCESS_ONCE(ads->ds_ctl0) = 0;
35331- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35332- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35333+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35334+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35335+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35336 return;
35337 }
35338
35339@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35340 break;
35341 }
35342
35343- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35344+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35345 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35346 | SM(i->txpower, AR_XmitPower)
35347 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35348@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35349 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35350 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35351
35352- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35353- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35354+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35355+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35356
35357 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35358 return;
35359
35360- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35361+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35362 | set11nPktDurRTSCTS(i->rates, 1);
35363
35364- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35365+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35366 | set11nPktDurRTSCTS(i->rates, 3);
35367
35368- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35369+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35370 | set11nRateFlags(i->rates, 1)
35371 | set11nRateFlags(i->rates, 2)
35372 | set11nRateFlags(i->rates, 3)
35373diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35374index d9e0824..1a874e7 100644
35375--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35376+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35377@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35378 (i->qcu << AR_TxQcuNum_S) | desc_len;
35379
35380 checksum += val;
35381- ACCESS_ONCE(ads->info) = val;
35382+ ACCESS_ONCE_RW(ads->info) = val;
35383
35384 checksum += i->link;
35385- ACCESS_ONCE(ads->link) = i->link;
35386+ ACCESS_ONCE_RW(ads->link) = i->link;
35387
35388 checksum += i->buf_addr[0];
35389- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35390+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35391 checksum += i->buf_addr[1];
35392- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35393+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35394 checksum += i->buf_addr[2];
35395- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35396+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35397 checksum += i->buf_addr[3];
35398- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35399+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35400
35401 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35402- ACCESS_ONCE(ads->ctl3) = val;
35403+ ACCESS_ONCE_RW(ads->ctl3) = val;
35404 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35405- ACCESS_ONCE(ads->ctl5) = val;
35406+ ACCESS_ONCE_RW(ads->ctl5) = val;
35407 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35408- ACCESS_ONCE(ads->ctl7) = val;
35409+ ACCESS_ONCE_RW(ads->ctl7) = val;
35410 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35411- ACCESS_ONCE(ads->ctl9) = val;
35412+ ACCESS_ONCE_RW(ads->ctl9) = val;
35413
35414 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35415- ACCESS_ONCE(ads->ctl10) = checksum;
35416+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
35417
35418 if (i->is_first || i->is_last) {
35419- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35420+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35421 | set11nTries(i->rates, 1)
35422 | set11nTries(i->rates, 2)
35423 | set11nTries(i->rates, 3)
35424 | (i->dur_update ? AR_DurUpdateEna : 0)
35425 | SM(0, AR_BurstDur);
35426
35427- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35428+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35429 | set11nRate(i->rates, 1)
35430 | set11nRate(i->rates, 2)
35431 | set11nRate(i->rates, 3);
35432 } else {
35433- ACCESS_ONCE(ads->ctl13) = 0;
35434- ACCESS_ONCE(ads->ctl14) = 0;
35435+ ACCESS_ONCE_RW(ads->ctl13) = 0;
35436+ ACCESS_ONCE_RW(ads->ctl14) = 0;
35437 }
35438
35439 ads->ctl20 = 0;
35440@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35441
35442 ctl17 = SM(i->keytype, AR_EncrType);
35443 if (!i->is_first) {
35444- ACCESS_ONCE(ads->ctl11) = 0;
35445- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35446- ACCESS_ONCE(ads->ctl15) = 0;
35447- ACCESS_ONCE(ads->ctl16) = 0;
35448- ACCESS_ONCE(ads->ctl17) = ctl17;
35449- ACCESS_ONCE(ads->ctl18) = 0;
35450- ACCESS_ONCE(ads->ctl19) = 0;
35451+ ACCESS_ONCE_RW(ads->ctl11) = 0;
35452+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35453+ ACCESS_ONCE_RW(ads->ctl15) = 0;
35454+ ACCESS_ONCE_RW(ads->ctl16) = 0;
35455+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35456+ ACCESS_ONCE_RW(ads->ctl18) = 0;
35457+ ACCESS_ONCE_RW(ads->ctl19) = 0;
35458 return;
35459 }
35460
35461- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35462+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35463 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35464 | SM(i->txpower, AR_XmitPower)
35465 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35466@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35467 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35468 ctl12 |= SM(val, AR_PAPRDChainMask);
35469
35470- ACCESS_ONCE(ads->ctl12) = ctl12;
35471- ACCESS_ONCE(ads->ctl17) = ctl17;
35472+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35473+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35474
35475- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35476+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35477 | set11nPktDurRTSCTS(i->rates, 1);
35478
35479- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35480+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35481 | set11nPktDurRTSCTS(i->rates, 3);
35482
35483- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35484+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35485 | set11nRateFlags(i->rates, 1)
35486 | set11nRateFlags(i->rates, 2)
35487 | set11nRateFlags(i->rates, 3)
35488 | SM(i->rtscts_rate, AR_RTSCTSRate);
35489
35490- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35491+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35492 }
35493
35494 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35495diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35496index 02f5007..bd0bd8f 100644
35497--- a/drivers/net/wireless/ath/ath9k/hw.h
35498+++ b/drivers/net/wireless/ath/ath9k/hw.h
35499@@ -610,7 +610,7 @@ struct ath_hw_private_ops {
35500
35501 /* ANI */
35502 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35503-};
35504+} __no_const;
35505
35506 /**
35507 * struct ath_hw_ops - callbacks used by hardware code and driver code
35508@@ -640,7 +640,7 @@ struct ath_hw_ops {
35509 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35510 struct ath_hw_antcomb_conf *antconf);
35511
35512-};
35513+} __no_const;
35514
35515 struct ath_nf_limits {
35516 s16 max;
35517@@ -660,7 +660,7 @@ enum ath_cal_list {
35518 #define AH_FASTCC 0x4
35519
35520 struct ath_hw {
35521- struct ath_ops reg_ops;
35522+ ath_ops_no_const reg_ops;
35523
35524 struct ieee80211_hw *hw;
35525 struct ath_common common;
35526diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35527index af00e2c..ab04d34 100644
35528--- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35529+++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35530@@ -545,7 +545,7 @@ struct phy_func_ptr {
35531 void (*carrsuppr)(struct brcms_phy *);
35532 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35533 void (*detach)(struct brcms_phy *);
35534-};
35535+} __no_const;
35536
35537 struct brcms_phy {
35538 struct brcms_phy_pub pubpi_ro;
35539diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35540index faec404..a5277f1 100644
35541--- a/drivers/net/wireless/iwlegacy/3945-mac.c
35542+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35543@@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35544 */
35545 if (il3945_mod_params.disable_hw_scan) {
35546 D_INFO("Disabling hw_scan\n");
35547- il3945_mac_ops.hw_scan = NULL;
35548+ pax_open_kernel();
35549+ *(void **)&il3945_mac_ops.hw_scan = NULL;
35550+ pax_close_kernel();
35551 }
35552
35553 D_INFO("*** LOAD DRIVER ***\n");
35554diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35555index a0b7cfd..20b49f7 100644
35556--- a/drivers/net/wireless/mac80211_hwsim.c
35557+++ b/drivers/net/wireless/mac80211_hwsim.c
35558@@ -1752,9 +1752,11 @@ static int __init init_mac80211_hwsim(void)
35559 return -EINVAL;
35560
35561 if (fake_hw_scan) {
35562- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35563- mac80211_hwsim_ops.sw_scan_start = NULL;
35564- mac80211_hwsim_ops.sw_scan_complete = NULL;
35565+ pax_open_kernel();
35566+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35567+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35568+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35569+ pax_close_kernel();
35570 }
35571
35572 spin_lock_init(&hwsim_radio_lock);
35573diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35574index bd3b0bf..f9db92a 100644
35575--- a/drivers/net/wireless/mwifiex/main.h
35576+++ b/drivers/net/wireless/mwifiex/main.h
35577@@ -567,7 +567,7 @@ struct mwifiex_if_ops {
35578 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35579 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
35580 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
35581-};
35582+} __no_const;
35583
35584 struct mwifiex_adapter {
35585 u8 iface_type;
35586diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35587index dfcd02a..a42a59d 100644
35588--- a/drivers/net/wireless/rndis_wlan.c
35589+++ b/drivers/net/wireless/rndis_wlan.c
35590@@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35591
35592 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35593
35594- if (rts_threshold < 0 || rts_threshold > 2347)
35595+ if (rts_threshold > 2347)
35596 rts_threshold = 2347;
35597
35598 tmp = cpu_to_le32(rts_threshold);
35599diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
35600index 8f75402..eed109d 100644
35601--- a/drivers/net/wireless/rt2x00/rt2x00.h
35602+++ b/drivers/net/wireless/rt2x00/rt2x00.h
35603@@ -396,7 +396,7 @@ struct rt2x00_intf {
35604 * for hardware which doesn't support hardware
35605 * sequence counting.
35606 */
35607- atomic_t seqno;
35608+ atomic_unchecked_t seqno;
35609 };
35610
35611 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
35612diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
35613index 2fd8301..9767e8c 100644
35614--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
35615+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
35616@@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
35617 * sequence counter given by mac80211.
35618 */
35619 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
35620- seqno = atomic_add_return(0x10, &intf->seqno);
35621+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
35622 else
35623- seqno = atomic_read(&intf->seqno);
35624+ seqno = atomic_read_unchecked(&intf->seqno);
35625
35626 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
35627 hdr->seq_ctrl |= cpu_to_le16(seqno);
35628diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
35629index 9d8f581..0f6589e 100644
35630--- a/drivers/net/wireless/ti/wl1251/wl1251.h
35631+++ b/drivers/net/wireless/ti/wl1251/wl1251.h
35632@@ -266,7 +266,7 @@ struct wl1251_if_operations {
35633 void (*reset)(struct wl1251 *wl);
35634 void (*enable_irq)(struct wl1251 *wl);
35635 void (*disable_irq)(struct wl1251 *wl);
35636-};
35637+} __no_const;
35638
35639 struct wl1251 {
35640 struct ieee80211_hw *hw;
35641diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
35642index 0b3f0b5..62f68bd 100644
35643--- a/drivers/net/wireless/ti/wlcore/wlcore.h
35644+++ b/drivers/net/wireless/ti/wlcore/wlcore.h
35645@@ -61,7 +61,7 @@ struct wlcore_ops {
35646 struct wl12xx_vif *wlvif);
35647 s8 (*get_pg_ver)(struct wl1271 *wl);
35648 void (*get_mac)(struct wl1271 *wl);
35649-};
35650+} __no_const;
35651
35652 enum wlcore_partitions {
35653 PART_DOWN,
35654diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
35655index f34b5b2..b5abb9f 100644
35656--- a/drivers/oprofile/buffer_sync.c
35657+++ b/drivers/oprofile/buffer_sync.c
35658@@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
35659 if (cookie == NO_COOKIE)
35660 offset = pc;
35661 if (cookie == INVALID_COOKIE) {
35662- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35663+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35664 offset = pc;
35665 }
35666 if (cookie != last_cookie) {
35667@@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
35668 /* add userspace sample */
35669
35670 if (!mm) {
35671- atomic_inc(&oprofile_stats.sample_lost_no_mm);
35672+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
35673 return 0;
35674 }
35675
35676 cookie = lookup_dcookie(mm, s->eip, &offset);
35677
35678 if (cookie == INVALID_COOKIE) {
35679- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35680+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35681 return 0;
35682 }
35683
35684@@ -563,7 +563,7 @@ void sync_buffer(int cpu)
35685 /* ignore backtraces if failed to add a sample */
35686 if (state == sb_bt_start) {
35687 state = sb_bt_ignore;
35688- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
35689+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
35690 }
35691 }
35692 release_mm(mm);
35693diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
35694index c0cc4e7..44d4e54 100644
35695--- a/drivers/oprofile/event_buffer.c
35696+++ b/drivers/oprofile/event_buffer.c
35697@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
35698 }
35699
35700 if (buffer_pos == buffer_size) {
35701- atomic_inc(&oprofile_stats.event_lost_overflow);
35702+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
35703 return;
35704 }
35705
35706diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
35707index ed2c3ec..deda85a 100644
35708--- a/drivers/oprofile/oprof.c
35709+++ b/drivers/oprofile/oprof.c
35710@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
35711 if (oprofile_ops.switch_events())
35712 return;
35713
35714- atomic_inc(&oprofile_stats.multiplex_counter);
35715+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
35716 start_switch_worker();
35717 }
35718
35719diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
35720index 917d28e..d62d981 100644
35721--- a/drivers/oprofile/oprofile_stats.c
35722+++ b/drivers/oprofile/oprofile_stats.c
35723@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
35724 cpu_buf->sample_invalid_eip = 0;
35725 }
35726
35727- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
35728- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
35729- atomic_set(&oprofile_stats.event_lost_overflow, 0);
35730- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
35731- atomic_set(&oprofile_stats.multiplex_counter, 0);
35732+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
35733+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
35734+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
35735+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
35736+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
35737 }
35738
35739
35740diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
35741index 38b6fc0..b5cbfce 100644
35742--- a/drivers/oprofile/oprofile_stats.h
35743+++ b/drivers/oprofile/oprofile_stats.h
35744@@ -13,11 +13,11 @@
35745 #include <linux/atomic.h>
35746
35747 struct oprofile_stat_struct {
35748- atomic_t sample_lost_no_mm;
35749- atomic_t sample_lost_no_mapping;
35750- atomic_t bt_lost_no_mapping;
35751- atomic_t event_lost_overflow;
35752- atomic_t multiplex_counter;
35753+ atomic_unchecked_t sample_lost_no_mm;
35754+ atomic_unchecked_t sample_lost_no_mapping;
35755+ atomic_unchecked_t bt_lost_no_mapping;
35756+ atomic_unchecked_t event_lost_overflow;
35757+ atomic_unchecked_t multiplex_counter;
35758 };
35759
35760 extern struct oprofile_stat_struct oprofile_stats;
35761diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
35762index 849357c..b83c1e0 100644
35763--- a/drivers/oprofile/oprofilefs.c
35764+++ b/drivers/oprofile/oprofilefs.c
35765@@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
35766
35767
35768 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
35769- char const *name, atomic_t *val)
35770+ char const *name, atomic_unchecked_t *val)
35771 {
35772 return __oprofilefs_create_file(sb, root, name,
35773 &atomic_ro_fops, 0444, val);
35774diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
35775index 3f56bc0..707d642 100644
35776--- a/drivers/parport/procfs.c
35777+++ b/drivers/parport/procfs.c
35778@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
35779
35780 *ppos += len;
35781
35782- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
35783+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
35784 }
35785
35786 #ifdef CONFIG_PARPORT_1284
35787@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
35788
35789 *ppos += len;
35790
35791- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
35792+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
35793 }
35794 #endif /* IEEE1284.3 support. */
35795
35796diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
35797index 9fff878..ad0ad53 100644
35798--- a/drivers/pci/hotplug/cpci_hotplug.h
35799+++ b/drivers/pci/hotplug/cpci_hotplug.h
35800@@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
35801 int (*hardware_test) (struct slot* slot, u32 value);
35802 u8 (*get_power) (struct slot* slot);
35803 int (*set_power) (struct slot* slot, int value);
35804-};
35805+} __no_const;
35806
35807 struct cpci_hp_controller {
35808 unsigned int irq;
35809diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
35810index 76ba8a1..20ca857 100644
35811--- a/drivers/pci/hotplug/cpqphp_nvram.c
35812+++ b/drivers/pci/hotplug/cpqphp_nvram.c
35813@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
35814
35815 void compaq_nvram_init (void __iomem *rom_start)
35816 {
35817+
35818+#ifndef CONFIG_PAX_KERNEXEC
35819 if (rom_start) {
35820 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
35821 }
35822+#endif
35823+
35824 dbg("int15 entry = %p\n", compaq_int15_entry_point);
35825
35826 /* initialize our int15 lock */
35827diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
35828index b500840..d7159d3 100644
35829--- a/drivers/pci/pcie/aspm.c
35830+++ b/drivers/pci/pcie/aspm.c
35831@@ -27,9 +27,9 @@
35832 #define MODULE_PARAM_PREFIX "pcie_aspm."
35833
35834 /* Note: those are not register definitions */
35835-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
35836-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
35837-#define ASPM_STATE_L1 (4) /* L1 state */
35838+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
35839+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
35840+#define ASPM_STATE_L1 (4U) /* L1 state */
35841 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
35842 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
35843
35844diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
35845index 658ac97..05e1b90 100644
35846--- a/drivers/pci/probe.c
35847+++ b/drivers/pci/probe.c
35848@@ -137,7 +137,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
35849 u16 orig_cmd;
35850 struct pci_bus_region region;
35851
35852- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
35853+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
35854
35855 if (!dev->mmio_always_on) {
35856 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
35857diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
35858index 27911b5..5b6db88 100644
35859--- a/drivers/pci/proc.c
35860+++ b/drivers/pci/proc.c
35861@@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
35862 static int __init pci_proc_init(void)
35863 {
35864 struct pci_dev *dev = NULL;
35865+
35866+#ifdef CONFIG_GRKERNSEC_PROC_ADD
35867+#ifdef CONFIG_GRKERNSEC_PROC_USER
35868+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
35869+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
35870+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
35871+#endif
35872+#else
35873 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
35874+#endif
35875 proc_create("devices", 0, proc_bus_pci_dir,
35876 &proc_bus_pci_dev_operations);
35877 proc_initialized = 1;
35878diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
35879index 8b5610d..a4c22bb 100644
35880--- a/drivers/platform/x86/thinkpad_acpi.c
35881+++ b/drivers/platform/x86/thinkpad_acpi.c
35882@@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
35883 return 0;
35884 }
35885
35886-void static hotkey_mask_warn_incomplete_mask(void)
35887+static void hotkey_mask_warn_incomplete_mask(void)
35888 {
35889 /* log only what the user can fix... */
35890 const u32 wantedmask = hotkey_driver_mask &
35891@@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
35892 }
35893 }
35894
35895-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35896- struct tp_nvram_state *newn,
35897- const u32 event_mask)
35898-{
35899-
35900 #define TPACPI_COMPARE_KEY(__scancode, __member) \
35901 do { \
35902 if ((event_mask & (1 << __scancode)) && \
35903@@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35904 tpacpi_hotkey_send_key(__scancode); \
35905 } while (0)
35906
35907- void issue_volchange(const unsigned int oldvol,
35908- const unsigned int newvol)
35909- {
35910- unsigned int i = oldvol;
35911+static void issue_volchange(const unsigned int oldvol,
35912+ const unsigned int newvol,
35913+ const u32 event_mask)
35914+{
35915+ unsigned int i = oldvol;
35916
35917- while (i > newvol) {
35918- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35919- i--;
35920- }
35921- while (i < newvol) {
35922- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35923- i++;
35924- }
35925+ while (i > newvol) {
35926+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
35927+ i--;
35928 }
35929+ while (i < newvol) {
35930+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35931+ i++;
35932+ }
35933+}
35934
35935- void issue_brightnesschange(const unsigned int oldbrt,
35936- const unsigned int newbrt)
35937- {
35938- unsigned int i = oldbrt;
35939+static void issue_brightnesschange(const unsigned int oldbrt,
35940+ const unsigned int newbrt,
35941+ const u32 event_mask)
35942+{
35943+ unsigned int i = oldbrt;
35944
35945- while (i > newbrt) {
35946- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35947- i--;
35948- }
35949- while (i < newbrt) {
35950- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35951- i++;
35952- }
35953+ while (i > newbrt) {
35954+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
35955+ i--;
35956+ }
35957+ while (i < newbrt) {
35958+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
35959+ i++;
35960 }
35961+}
35962
35963+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35964+ struct tp_nvram_state *newn,
35965+ const u32 event_mask)
35966+{
35967 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
35968 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
35969 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
35970@@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35971 oldn->volume_level != newn->volume_level) {
35972 /* recently muted, or repeated mute keypress, or
35973 * multiple presses ending in mute */
35974- issue_volchange(oldn->volume_level, newn->volume_level);
35975+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35976 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
35977 }
35978 } else {
35979@@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35980 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
35981 }
35982 if (oldn->volume_level != newn->volume_level) {
35983- issue_volchange(oldn->volume_level, newn->volume_level);
35984+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
35985 } else if (oldn->volume_toggle != newn->volume_toggle) {
35986 /* repeated vol up/down keypress at end of scale ? */
35987 if (newn->volume_level == 0)
35988@@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35989 /* handle brightness */
35990 if (oldn->brightness_level != newn->brightness_level) {
35991 issue_brightnesschange(oldn->brightness_level,
35992- newn->brightness_level);
35993+ newn->brightness_level,
35994+ event_mask);
35995 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
35996 /* repeated key presses that didn't change state */
35997 if (newn->brightness_level == 0)
35998@@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
35999 && !tp_features.bright_unkfw)
36000 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36001 }
36002+}
36003
36004 #undef TPACPI_COMPARE_KEY
36005 #undef TPACPI_MAY_SEND_KEY
36006-}
36007
36008 /*
36009 * Polling driver
36010diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36011index 769d265..a3a05ca 100644
36012--- a/drivers/pnp/pnpbios/bioscalls.c
36013+++ b/drivers/pnp/pnpbios/bioscalls.c
36014@@ -58,7 +58,7 @@ do { \
36015 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36016 } while(0)
36017
36018-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36019+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36020 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36021
36022 /*
36023@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36024
36025 cpu = get_cpu();
36026 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36027+
36028+ pax_open_kernel();
36029 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36030+ pax_close_kernel();
36031
36032 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36033 spin_lock_irqsave(&pnp_bios_lock, flags);
36034@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36035 :"memory");
36036 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36037
36038+ pax_open_kernel();
36039 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36040+ pax_close_kernel();
36041+
36042 put_cpu();
36043
36044 /* If we get here and this is set then the PnP BIOS faulted on us. */
36045@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36046 return status;
36047 }
36048
36049-void pnpbios_calls_init(union pnp_bios_install_struct *header)
36050+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36051 {
36052 int i;
36053
36054@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36055 pnp_bios_callpoint.offset = header->fields.pm16offset;
36056 pnp_bios_callpoint.segment = PNP_CS16;
36057
36058+ pax_open_kernel();
36059+
36060 for_each_possible_cpu(i) {
36061 struct desc_struct *gdt = get_cpu_gdt_table(i);
36062 if (!gdt)
36063@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36064 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36065 (unsigned long)__va(header->fields.pm16dseg));
36066 }
36067+
36068+ pax_close_kernel();
36069 }
36070diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36071index b0ecacb..7c9da2e 100644
36072--- a/drivers/pnp/resource.c
36073+++ b/drivers/pnp/resource.c
36074@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36075 return 1;
36076
36077 /* check if the resource is valid */
36078- if (*irq < 0 || *irq > 15)
36079+ if (*irq > 15)
36080 return 0;
36081
36082 /* check if the resource is reserved */
36083@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36084 return 1;
36085
36086 /* check if the resource is valid */
36087- if (*dma < 0 || *dma == 4 || *dma > 7)
36088+ if (*dma == 4 || *dma > 7)
36089 return 0;
36090
36091 /* check if the resource is reserved */
36092diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36093index f5d6d37..739f6a9 100644
36094--- a/drivers/power/bq27x00_battery.c
36095+++ b/drivers/power/bq27x00_battery.c
36096@@ -72,7 +72,7 @@
36097 struct bq27x00_device_info;
36098 struct bq27x00_access_methods {
36099 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36100-};
36101+} __no_const;
36102
36103 enum bq27x00_chip { BQ27000, BQ27500 };
36104
36105diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36106index 8d53174..04c65de 100644
36107--- a/drivers/regulator/max8660.c
36108+++ b/drivers/regulator/max8660.c
36109@@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36110 max8660->shadow_regs[MAX8660_OVER1] = 5;
36111 } else {
36112 /* Otherwise devices can be toggled via software */
36113- max8660_dcdc_ops.enable = max8660_dcdc_enable;
36114- max8660_dcdc_ops.disable = max8660_dcdc_disable;
36115+ pax_open_kernel();
36116+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36117+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36118+ pax_close_kernel();
36119 }
36120
36121 /*
36122diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36123index 970a233..ee1f241 100644
36124--- a/drivers/regulator/mc13892-regulator.c
36125+++ b/drivers/regulator/mc13892-regulator.c
36126@@ -566,10 +566,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36127 }
36128 mc13xxx_unlock(mc13892);
36129
36130- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36131+ pax_open_kernel();
36132+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36133 = mc13892_vcam_set_mode;
36134- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36135+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36136 = mc13892_vcam_get_mode;
36137+ pax_close_kernel();
36138
36139 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36140 ARRAY_SIZE(mc13892_regulators));
36141diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36142index cace6d3..f623fda 100644
36143--- a/drivers/rtc/rtc-dev.c
36144+++ b/drivers/rtc/rtc-dev.c
36145@@ -14,6 +14,7 @@
36146 #include <linux/module.h>
36147 #include <linux/rtc.h>
36148 #include <linux/sched.h>
36149+#include <linux/grsecurity.h>
36150 #include "rtc-core.h"
36151
36152 static dev_t rtc_devt;
36153@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36154 if (copy_from_user(&tm, uarg, sizeof(tm)))
36155 return -EFAULT;
36156
36157+ gr_log_timechange();
36158+
36159 return rtc_set_time(rtc, &tm);
36160
36161 case RTC_PIE_ON:
36162diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36163index 3fcf627..f334910 100644
36164--- a/drivers/scsi/aacraid/aacraid.h
36165+++ b/drivers/scsi/aacraid/aacraid.h
36166@@ -492,7 +492,7 @@ struct adapter_ops
36167 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36168 /* Administrative operations */
36169 int (*adapter_comm)(struct aac_dev * dev, int comm);
36170-};
36171+} __no_const;
36172
36173 /*
36174 * Define which interrupt handler needs to be installed
36175diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36176index 0d279c44..3d25a97 100644
36177--- a/drivers/scsi/aacraid/linit.c
36178+++ b/drivers/scsi/aacraid/linit.c
36179@@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36180 #elif defined(__devinitconst)
36181 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36182 #else
36183-static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36184+static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36185 #endif
36186 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36187 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36188diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36189index ff80552..1c4120c 100644
36190--- a/drivers/scsi/aic94xx/aic94xx_init.c
36191+++ b/drivers/scsi/aic94xx/aic94xx_init.c
36192@@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36193 .lldd_ata_set_dmamode = asd_set_dmamode,
36194 };
36195
36196-static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36197+static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36198 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36199 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36200 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36201diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36202index 4ad7e36..d004679 100644
36203--- a/drivers/scsi/bfa/bfa.h
36204+++ b/drivers/scsi/bfa/bfa.h
36205@@ -196,7 +196,7 @@ struct bfa_hwif_s {
36206 u32 *end);
36207 int cpe_vec_q0;
36208 int rme_vec_q0;
36209-};
36210+} __no_const;
36211 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36212
36213 struct bfa_faa_cbfn_s {
36214diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36215index f0f80e2..8ec946b 100644
36216--- a/drivers/scsi/bfa/bfa_fcpim.c
36217+++ b/drivers/scsi/bfa/bfa_fcpim.c
36218@@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36219
36220 bfa_iotag_attach(fcp);
36221
36222- fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36223+ fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36224 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36225 (fcp->num_itns * sizeof(struct bfa_itn_s));
36226 memset(fcp->itn_arr, 0,
36227@@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36228 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36229 {
36230 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36231- struct bfa_itn_s *itn;
36232+ bfa_itn_s_no_const *itn;
36233
36234 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36235 itn->isr = isr;
36236diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36237index 36f26da..38a34a8 100644
36238--- a/drivers/scsi/bfa/bfa_fcpim.h
36239+++ b/drivers/scsi/bfa/bfa_fcpim.h
36240@@ -37,6 +37,7 @@ struct bfa_iotag_s {
36241 struct bfa_itn_s {
36242 bfa_isr_func_t isr;
36243 };
36244+typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36245
36246 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36247 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36248@@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36249 struct list_head iotag_tio_free_q; /* free IO resources */
36250 struct list_head iotag_unused_q; /* unused IO resources*/
36251 struct bfa_iotag_s *iotag_arr;
36252- struct bfa_itn_s *itn_arr;
36253+ bfa_itn_s_no_const *itn_arr;
36254 int num_ioim_reqs;
36255 int num_fwtio_reqs;
36256 int num_itns;
36257diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36258index 1a99d4b..e85d64b 100644
36259--- a/drivers/scsi/bfa/bfa_ioc.h
36260+++ b/drivers/scsi/bfa/bfa_ioc.h
36261@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36262 bfa_ioc_disable_cbfn_t disable_cbfn;
36263 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36264 bfa_ioc_reset_cbfn_t reset_cbfn;
36265-};
36266+} __no_const;
36267
36268 /*
36269 * IOC event notification mechanism.
36270@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36271 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36272 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36273 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36274-};
36275+} __no_const;
36276
36277 /*
36278 * Queue element to wait for room in request queue. FIFO order is
36279diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36280index b48c24f..dac0fbc 100644
36281--- a/drivers/scsi/hosts.c
36282+++ b/drivers/scsi/hosts.c
36283@@ -42,7 +42,7 @@
36284 #include "scsi_logging.h"
36285
36286
36287-static atomic_t scsi_host_next_hn; /* host_no for next new host */
36288+static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
36289
36290
36291 static void scsi_host_cls_release(struct device *dev)
36292@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36293 * subtract one because we increment first then return, but we need to
36294 * know what the next host number was before increment
36295 */
36296- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36297+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36298 shost->dma_channel = 0xff;
36299
36300 /* These three are default values which can be overridden */
36301diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36302index 796482b..d08435c 100644
36303--- a/drivers/scsi/hpsa.c
36304+++ b/drivers/scsi/hpsa.c
36305@@ -536,7 +536,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
36306 unsigned long flags;
36307
36308 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36309- return h->access.command_completed(h, q);
36310+ return h->access->command_completed(h, q);
36311
36312 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
36313 a = rq->head[rq->current_entry];
36314@@ -3354,7 +3354,7 @@ static void start_io(struct ctlr_info *h)
36315 while (!list_empty(&h->reqQ)) {
36316 c = list_entry(h->reqQ.next, struct CommandList, list);
36317 /* can't do anything if fifo is full */
36318- if ((h->access.fifo_full(h))) {
36319+ if ((h->access->fifo_full(h))) {
36320 dev_warn(&h->pdev->dev, "fifo full\n");
36321 break;
36322 }
36323@@ -3376,7 +3376,7 @@ static void start_io(struct ctlr_info *h)
36324
36325 /* Tell the controller execute command */
36326 spin_unlock_irqrestore(&h->lock, flags);
36327- h->access.submit_command(h, c);
36328+ h->access->submit_command(h, c);
36329 spin_lock_irqsave(&h->lock, flags);
36330 }
36331 spin_unlock_irqrestore(&h->lock, flags);
36332@@ -3384,17 +3384,17 @@ static void start_io(struct ctlr_info *h)
36333
36334 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
36335 {
36336- return h->access.command_completed(h, q);
36337+ return h->access->command_completed(h, q);
36338 }
36339
36340 static inline bool interrupt_pending(struct ctlr_info *h)
36341 {
36342- return h->access.intr_pending(h);
36343+ return h->access->intr_pending(h);
36344 }
36345
36346 static inline long interrupt_not_for_us(struct ctlr_info *h)
36347 {
36348- return (h->access.intr_pending(h) == 0) ||
36349+ return (h->access->intr_pending(h) == 0) ||
36350 (h->interrupts_enabled == 0);
36351 }
36352
36353@@ -4298,7 +4298,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36354 if (prod_index < 0)
36355 return -ENODEV;
36356 h->product_name = products[prod_index].product_name;
36357- h->access = *(products[prod_index].access);
36358+ h->access = products[prod_index].access;
36359
36360 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
36361 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
36362@@ -4580,7 +4580,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36363
36364 assert_spin_locked(&lockup_detector_lock);
36365 remove_ctlr_from_lockup_detector_list(h);
36366- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36367+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36368 spin_lock_irqsave(&h->lock, flags);
36369 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36370 spin_unlock_irqrestore(&h->lock, flags);
36371@@ -4758,7 +4758,7 @@ reinit_after_soft_reset:
36372 }
36373
36374 /* make sure the board interrupts are off */
36375- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36376+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36377
36378 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36379 goto clean2;
36380@@ -4792,7 +4792,7 @@ reinit_after_soft_reset:
36381 * fake ones to scoop up any residual completions.
36382 */
36383 spin_lock_irqsave(&h->lock, flags);
36384- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36385+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36386 spin_unlock_irqrestore(&h->lock, flags);
36387 free_irqs(h);
36388 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36389@@ -4811,9 +4811,9 @@ reinit_after_soft_reset:
36390 dev_info(&h->pdev->dev, "Board READY.\n");
36391 dev_info(&h->pdev->dev,
36392 "Waiting for stale completions to drain.\n");
36393- h->access.set_intr_mask(h, HPSA_INTR_ON);
36394+ h->access->set_intr_mask(h, HPSA_INTR_ON);
36395 msleep(10000);
36396- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36397+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36398
36399 rc = controller_reset_failed(h->cfgtable);
36400 if (rc)
36401@@ -4834,7 +4834,7 @@ reinit_after_soft_reset:
36402 }
36403
36404 /* Turn the interrupts on so we can service requests */
36405- h->access.set_intr_mask(h, HPSA_INTR_ON);
36406+ h->access->set_intr_mask(h, HPSA_INTR_ON);
36407
36408 hpsa_hba_inquiry(h);
36409 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36410@@ -4886,7 +4886,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36411 * To write all data in the battery backed cache to disks
36412 */
36413 hpsa_flush_cache(h);
36414- h->access.set_intr_mask(h, HPSA_INTR_OFF);
36415+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
36416 hpsa_free_irqs_and_disable_msix(h);
36417 }
36418
36419@@ -5055,7 +5055,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36420 return;
36421 }
36422 /* Change the access methods to the performant access methods */
36423- h->access = SA5_performant_access;
36424+ h->access = &SA5_performant_access;
36425 h->transMethod = CFGTBL_Trans_Performant;
36426 }
36427
36428diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36429index 9816479..c5d4e97 100644
36430--- a/drivers/scsi/hpsa.h
36431+++ b/drivers/scsi/hpsa.h
36432@@ -79,7 +79,7 @@ struct ctlr_info {
36433 unsigned int msix_vector;
36434 unsigned int msi_vector;
36435 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36436- struct access_method access;
36437+ struct access_method *access;
36438
36439 /* queue and queue Info */
36440 struct list_head reqQ;
36441diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36442index f2df059..a3a9930 100644
36443--- a/drivers/scsi/ips.h
36444+++ b/drivers/scsi/ips.h
36445@@ -1027,7 +1027,7 @@ typedef struct {
36446 int (*intr)(struct ips_ha *);
36447 void (*enableint)(struct ips_ha *);
36448 uint32_t (*statupd)(struct ips_ha *);
36449-} ips_hw_func_t;
36450+} __no_const ips_hw_func_t;
36451
36452 typedef struct ips_ha {
36453 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36454diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36455index aceffad..c35c08d 100644
36456--- a/drivers/scsi/libfc/fc_exch.c
36457+++ b/drivers/scsi/libfc/fc_exch.c
36458@@ -105,12 +105,12 @@ struct fc_exch_mgr {
36459 * all together if not used XXX
36460 */
36461 struct {
36462- atomic_t no_free_exch;
36463- atomic_t no_free_exch_xid;
36464- atomic_t xid_not_found;
36465- atomic_t xid_busy;
36466- atomic_t seq_not_found;
36467- atomic_t non_bls_resp;
36468+ atomic_unchecked_t no_free_exch;
36469+ atomic_unchecked_t no_free_exch_xid;
36470+ atomic_unchecked_t xid_not_found;
36471+ atomic_unchecked_t xid_busy;
36472+ atomic_unchecked_t seq_not_found;
36473+ atomic_unchecked_t non_bls_resp;
36474 } stats;
36475 };
36476
36477@@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36478 /* allocate memory for exchange */
36479 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36480 if (!ep) {
36481- atomic_inc(&mp->stats.no_free_exch);
36482+ atomic_inc_unchecked(&mp->stats.no_free_exch);
36483 goto out;
36484 }
36485 memset(ep, 0, sizeof(*ep));
36486@@ -780,7 +780,7 @@ out:
36487 return ep;
36488 err:
36489 spin_unlock_bh(&pool->lock);
36490- atomic_inc(&mp->stats.no_free_exch_xid);
36491+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36492 mempool_free(ep, mp->ep_pool);
36493 return NULL;
36494 }
36495@@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36496 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36497 ep = fc_exch_find(mp, xid);
36498 if (!ep) {
36499- atomic_inc(&mp->stats.xid_not_found);
36500+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36501 reject = FC_RJT_OX_ID;
36502 goto out;
36503 }
36504@@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36505 ep = fc_exch_find(mp, xid);
36506 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36507 if (ep) {
36508- atomic_inc(&mp->stats.xid_busy);
36509+ atomic_inc_unchecked(&mp->stats.xid_busy);
36510 reject = FC_RJT_RX_ID;
36511 goto rel;
36512 }
36513@@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36514 }
36515 xid = ep->xid; /* get our XID */
36516 } else if (!ep) {
36517- atomic_inc(&mp->stats.xid_not_found);
36518+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36519 reject = FC_RJT_RX_ID; /* XID not found */
36520 goto out;
36521 }
36522@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36523 } else {
36524 sp = &ep->seq;
36525 if (sp->id != fh->fh_seq_id) {
36526- atomic_inc(&mp->stats.seq_not_found);
36527+ atomic_inc_unchecked(&mp->stats.seq_not_found);
36528 if (f_ctl & FC_FC_END_SEQ) {
36529 /*
36530 * Update sequence_id based on incoming last
36531@@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36532
36533 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36534 if (!ep) {
36535- atomic_inc(&mp->stats.xid_not_found);
36536+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36537 goto out;
36538 }
36539 if (ep->esb_stat & ESB_ST_COMPLETE) {
36540- atomic_inc(&mp->stats.xid_not_found);
36541+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36542 goto rel;
36543 }
36544 if (ep->rxid == FC_XID_UNKNOWN)
36545 ep->rxid = ntohs(fh->fh_rx_id);
36546 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36547- atomic_inc(&mp->stats.xid_not_found);
36548+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36549 goto rel;
36550 }
36551 if (ep->did != ntoh24(fh->fh_s_id) &&
36552 ep->did != FC_FID_FLOGI) {
36553- atomic_inc(&mp->stats.xid_not_found);
36554+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36555 goto rel;
36556 }
36557 sof = fr_sof(fp);
36558@@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36559 sp->ssb_stat |= SSB_ST_RESP;
36560 sp->id = fh->fh_seq_id;
36561 } else if (sp->id != fh->fh_seq_id) {
36562- atomic_inc(&mp->stats.seq_not_found);
36563+ atomic_inc_unchecked(&mp->stats.seq_not_found);
36564 goto rel;
36565 }
36566
36567@@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36568 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36569
36570 if (!sp)
36571- atomic_inc(&mp->stats.xid_not_found);
36572+ atomic_inc_unchecked(&mp->stats.xid_not_found);
36573 else
36574- atomic_inc(&mp->stats.non_bls_resp);
36575+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
36576
36577 fc_frame_free(fp);
36578 }
36579diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36580index d109cc3..09f4e7d 100644
36581--- a/drivers/scsi/libsas/sas_ata.c
36582+++ b/drivers/scsi/libsas/sas_ata.c
36583@@ -529,7 +529,7 @@ static struct ata_port_operations sas_sata_ops = {
36584 .postreset = ata_std_postreset,
36585 .error_handler = ata_std_error_handler,
36586 .post_internal_cmd = sas_ata_post_internal,
36587- .qc_defer = ata_std_qc_defer,
36588+ .qc_defer = ata_std_qc_defer,
36589 .qc_prep = ata_noop_qc_prep,
36590 .qc_issue = sas_ata_qc_issue,
36591 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36592diff --git a/drivers/scsi/lpfc/Makefile b/drivers/scsi/lpfc/Makefile
36593index fe5d396..e93d526 100644
36594--- a/drivers/scsi/lpfc/Makefile
36595+++ b/drivers/scsi/lpfc/Makefile
36596@@ -22,7 +22,7 @@
36597 ccflags-$(GCOV) := -fprofile-arcs -ftest-coverage
36598 ccflags-$(GCOV) += -O0
36599
36600-ccflags-y += -Werror
36601+#ccflags-y += -Werror
36602
36603 obj-$(CONFIG_SCSI_LPFC) := lpfc.o
36604
36605diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36606index e5da6da..c888d48 100644
36607--- a/drivers/scsi/lpfc/lpfc.h
36608+++ b/drivers/scsi/lpfc/lpfc.h
36609@@ -416,7 +416,7 @@ struct lpfc_vport {
36610 struct dentry *debug_nodelist;
36611 struct dentry *vport_debugfs_root;
36612 struct lpfc_debugfs_trc *disc_trc;
36613- atomic_t disc_trc_cnt;
36614+ atomic_unchecked_t disc_trc_cnt;
36615 #endif
36616 uint8_t stat_data_enabled;
36617 uint8_t stat_data_blocked;
36618@@ -830,8 +830,8 @@ struct lpfc_hba {
36619 struct timer_list fabric_block_timer;
36620 unsigned long bit_flags;
36621 #define FABRIC_COMANDS_BLOCKED 0
36622- atomic_t num_rsrc_err;
36623- atomic_t num_cmd_success;
36624+ atomic_unchecked_t num_rsrc_err;
36625+ atomic_unchecked_t num_cmd_success;
36626 unsigned long last_rsrc_error_time;
36627 unsigned long last_ramp_down_time;
36628 unsigned long last_ramp_up_time;
36629@@ -867,7 +867,7 @@ struct lpfc_hba {
36630
36631 struct dentry *debug_slow_ring_trc;
36632 struct lpfc_debugfs_trc *slow_ring_trc;
36633- atomic_t slow_ring_trc_cnt;
36634+ atomic_unchecked_t slow_ring_trc_cnt;
36635 /* iDiag debugfs sub-directory */
36636 struct dentry *idiag_root;
36637 struct dentry *idiag_pci_cfg;
36638diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
36639index 3217d63..c417981 100644
36640--- a/drivers/scsi/lpfc/lpfc_debugfs.c
36641+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
36642@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
36643
36644 #include <linux/debugfs.h>
36645
36646-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36647+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36648 static unsigned long lpfc_debugfs_start_time = 0L;
36649
36650 /* iDiag */
36651@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
36652 lpfc_debugfs_enable = 0;
36653
36654 len = 0;
36655- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
36656+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
36657 (lpfc_debugfs_max_disc_trc - 1);
36658 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
36659 dtp = vport->disc_trc + i;
36660@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
36661 lpfc_debugfs_enable = 0;
36662
36663 len = 0;
36664- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
36665+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
36666 (lpfc_debugfs_max_slow_ring_trc - 1);
36667 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
36668 dtp = phba->slow_ring_trc + i;
36669@@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
36670 !vport || !vport->disc_trc)
36671 return;
36672
36673- index = atomic_inc_return(&vport->disc_trc_cnt) &
36674+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
36675 (lpfc_debugfs_max_disc_trc - 1);
36676 dtp = vport->disc_trc + index;
36677 dtp->fmt = fmt;
36678 dtp->data1 = data1;
36679 dtp->data2 = data2;
36680 dtp->data3 = data3;
36681- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36682+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36683 dtp->jif = jiffies;
36684 #endif
36685 return;
36686@@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
36687 !phba || !phba->slow_ring_trc)
36688 return;
36689
36690- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
36691+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
36692 (lpfc_debugfs_max_slow_ring_trc - 1);
36693 dtp = phba->slow_ring_trc + index;
36694 dtp->fmt = fmt;
36695 dtp->data1 = data1;
36696 dtp->data2 = data2;
36697 dtp->data3 = data3;
36698- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36699+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36700 dtp->jif = jiffies;
36701 #endif
36702 return;
36703@@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36704 "slow_ring buffer\n");
36705 goto debug_failed;
36706 }
36707- atomic_set(&phba->slow_ring_trc_cnt, 0);
36708+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
36709 memset(phba->slow_ring_trc, 0,
36710 (sizeof(struct lpfc_debugfs_trc) *
36711 lpfc_debugfs_max_slow_ring_trc));
36712@@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
36713 "buffer\n");
36714 goto debug_failed;
36715 }
36716- atomic_set(&vport->disc_trc_cnt, 0);
36717+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
36718
36719 snprintf(name, sizeof(name), "discovery_trace");
36720 vport->debug_disc_trc =
36721diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
36722index 411ed48..967f553 100644
36723--- a/drivers/scsi/lpfc/lpfc_init.c
36724+++ b/drivers/scsi/lpfc/lpfc_init.c
36725@@ -10341,8 +10341,10 @@ lpfc_init(void)
36726 "misc_register returned with status %d", error);
36727
36728 if (lpfc_enable_npiv) {
36729- lpfc_transport_functions.vport_create = lpfc_vport_create;
36730- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36731+ pax_open_kernel();
36732+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
36733+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
36734+ pax_close_kernel();
36735 }
36736 lpfc_transport_template =
36737 fc_attach_transport(&lpfc_transport_functions);
36738diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
36739index 66e0906..1620281 100644
36740--- a/drivers/scsi/lpfc/lpfc_scsi.c
36741+++ b/drivers/scsi/lpfc/lpfc_scsi.c
36742@@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
36743 uint32_t evt_posted;
36744
36745 spin_lock_irqsave(&phba->hbalock, flags);
36746- atomic_inc(&phba->num_rsrc_err);
36747+ atomic_inc_unchecked(&phba->num_rsrc_err);
36748 phba->last_rsrc_error_time = jiffies;
36749
36750 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
36751@@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
36752 unsigned long flags;
36753 struct lpfc_hba *phba = vport->phba;
36754 uint32_t evt_posted;
36755- atomic_inc(&phba->num_cmd_success);
36756+ atomic_inc_unchecked(&phba->num_cmd_success);
36757
36758 if (vport->cfg_lun_queue_depth <= queue_depth)
36759 return;
36760@@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36761 unsigned long num_rsrc_err, num_cmd_success;
36762 int i;
36763
36764- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
36765- num_cmd_success = atomic_read(&phba->num_cmd_success);
36766+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
36767+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
36768
36769 /*
36770 * The error and success command counters are global per
36771@@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
36772 }
36773 }
36774 lpfc_destroy_vport_work_array(phba, vports);
36775- atomic_set(&phba->num_rsrc_err, 0);
36776- atomic_set(&phba->num_cmd_success, 0);
36777+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
36778+ atomic_set_unchecked(&phba->num_cmd_success, 0);
36779 }
36780
36781 /**
36782@@ -460,8 +460,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
36783 }
36784 }
36785 lpfc_destroy_vport_work_array(phba, vports);
36786- atomic_set(&phba->num_rsrc_err, 0);
36787- atomic_set(&phba->num_cmd_success, 0);
36788+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
36789+ atomic_set_unchecked(&phba->num_cmd_success, 0);
36790 }
36791
36792 /**
36793diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
36794index ea8a0b4..812a124 100644
36795--- a/drivers/scsi/pmcraid.c
36796+++ b/drivers/scsi/pmcraid.c
36797@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
36798 res->scsi_dev = scsi_dev;
36799 scsi_dev->hostdata = res;
36800 res->change_detected = 0;
36801- atomic_set(&res->read_failures, 0);
36802- atomic_set(&res->write_failures, 0);
36803+ atomic_set_unchecked(&res->read_failures, 0);
36804+ atomic_set_unchecked(&res->write_failures, 0);
36805 rc = 0;
36806 }
36807 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
36808@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
36809
36810 /* If this was a SCSI read/write command keep count of errors */
36811 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
36812- atomic_inc(&res->read_failures);
36813+ atomic_inc_unchecked(&res->read_failures);
36814 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
36815- atomic_inc(&res->write_failures);
36816+ atomic_inc_unchecked(&res->write_failures);
36817
36818 if (!RES_IS_GSCSI(res->cfg_entry) &&
36819 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
36820@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
36821 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36822 * hrrq_id assigned here in queuecommand
36823 */
36824- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36825+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36826 pinstance->num_hrrq;
36827 cmd->cmd_done = pmcraid_io_done;
36828
36829@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
36830 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
36831 * hrrq_id assigned here in queuecommand
36832 */
36833- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
36834+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
36835 pinstance->num_hrrq;
36836
36837 if (request_size) {
36838@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
36839
36840 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
36841 /* add resources only after host is added into system */
36842- if (!atomic_read(&pinstance->expose_resources))
36843+ if (!atomic_read_unchecked(&pinstance->expose_resources))
36844 return;
36845
36846 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
36847@@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
36848 init_waitqueue_head(&pinstance->reset_wait_q);
36849
36850 atomic_set(&pinstance->outstanding_cmds, 0);
36851- atomic_set(&pinstance->last_message_id, 0);
36852- atomic_set(&pinstance->expose_resources, 0);
36853+ atomic_set_unchecked(&pinstance->last_message_id, 0);
36854+ atomic_set_unchecked(&pinstance->expose_resources, 0);
36855
36856 INIT_LIST_HEAD(&pinstance->free_res_q);
36857 INIT_LIST_HEAD(&pinstance->used_res_q);
36858@@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
36859 /* Schedule worker thread to handle CCN and take care of adding and
36860 * removing devices to OS
36861 */
36862- atomic_set(&pinstance->expose_resources, 1);
36863+ atomic_set_unchecked(&pinstance->expose_resources, 1);
36864 schedule_work(&pinstance->worker_q);
36865 return rc;
36866
36867diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
36868index e1d150f..6c6df44 100644
36869--- a/drivers/scsi/pmcraid.h
36870+++ b/drivers/scsi/pmcraid.h
36871@@ -748,7 +748,7 @@ struct pmcraid_instance {
36872 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
36873
36874 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
36875- atomic_t last_message_id;
36876+ atomic_unchecked_t last_message_id;
36877
36878 /* configuration table */
36879 struct pmcraid_config_table *cfg_table;
36880@@ -777,7 +777,7 @@ struct pmcraid_instance {
36881 atomic_t outstanding_cmds;
36882
36883 /* should add/delete resources to mid-layer now ?*/
36884- atomic_t expose_resources;
36885+ atomic_unchecked_t expose_resources;
36886
36887
36888
36889@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
36890 struct pmcraid_config_table_entry_ext cfg_entry_ext;
36891 };
36892 struct scsi_device *scsi_dev; /* Link scsi_device structure */
36893- atomic_t read_failures; /* count of failed READ commands */
36894- atomic_t write_failures; /* count of failed WRITE commands */
36895+ atomic_unchecked_t read_failures; /* count of failed READ commands */
36896+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
36897
36898 /* To indicate add/delete/modify during CCN */
36899 u8 change_detected;
36900diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
36901index 5ab9530..2dd80f7 100644
36902--- a/drivers/scsi/qla2xxx/qla_attr.c
36903+++ b/drivers/scsi/qla2xxx/qla_attr.c
36904@@ -1855,7 +1855,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
36905 return 0;
36906 }
36907
36908-struct fc_function_template qla2xxx_transport_functions = {
36909+fc_function_template_no_const qla2xxx_transport_functions = {
36910
36911 .show_host_node_name = 1,
36912 .show_host_port_name = 1,
36913@@ -1902,7 +1902,7 @@ struct fc_function_template qla2xxx_transport_functions = {
36914 .bsg_timeout = qla24xx_bsg_timeout,
36915 };
36916
36917-struct fc_function_template qla2xxx_transport_vport_functions = {
36918+fc_function_template_no_const qla2xxx_transport_vport_functions = {
36919
36920 .show_host_node_name = 1,
36921 .show_host_port_name = 1,
36922diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
36923index 39007f5..7fafc64 100644
36924--- a/drivers/scsi/qla2xxx/qla_def.h
36925+++ b/drivers/scsi/qla2xxx/qla_def.h
36926@@ -2284,7 +2284,7 @@ struct isp_operations {
36927 int (*start_scsi) (srb_t *);
36928 int (*abort_isp) (struct scsi_qla_host *);
36929 int (*iospace_config)(struct qla_hw_data*);
36930-};
36931+} __no_const;
36932
36933 /* MSI-X Support *************************************************************/
36934
36935diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
36936index 9eacd2d..d79629c 100644
36937--- a/drivers/scsi/qla2xxx/qla_gbl.h
36938+++ b/drivers/scsi/qla2xxx/qla_gbl.h
36939@@ -484,8 +484,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
36940 struct device_attribute;
36941 extern struct device_attribute *qla2x00_host_attrs[];
36942 struct fc_function_template;
36943-extern struct fc_function_template qla2xxx_transport_functions;
36944-extern struct fc_function_template qla2xxx_transport_vport_functions;
36945+extern fc_function_template_no_const qla2xxx_transport_functions;
36946+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
36947 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
36948 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
36949 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
36950diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
36951index 96a5616..eeb185a 100644
36952--- a/drivers/scsi/qla4xxx/ql4_def.h
36953+++ b/drivers/scsi/qla4xxx/ql4_def.h
36954@@ -268,7 +268,7 @@ struct ddb_entry {
36955 * (4000 only) */
36956 atomic_t relogin_timer; /* Max Time to wait for
36957 * relogin to complete */
36958- atomic_t relogin_retry_count; /* Num of times relogin has been
36959+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
36960 * retried */
36961 uint32_t default_time2wait; /* Default Min time between
36962 * relogins (+aens) */
36963diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
36964index cd15678..f7e6846 100644
36965--- a/drivers/scsi/qla4xxx/ql4_os.c
36966+++ b/drivers/scsi/qla4xxx/ql4_os.c
36967@@ -2615,12 +2615,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
36968 */
36969 if (!iscsi_is_session_online(cls_sess)) {
36970 /* Reset retry relogin timer */
36971- atomic_inc(&ddb_entry->relogin_retry_count);
36972+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
36973 DEBUG2(ql4_printk(KERN_INFO, ha,
36974 "%s: index[%d] relogin timed out-retrying"
36975 " relogin (%d), retry (%d)\n", __func__,
36976 ddb_entry->fw_ddb_index,
36977- atomic_read(&ddb_entry->relogin_retry_count),
36978+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
36979 ddb_entry->default_time2wait + 4));
36980 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
36981 atomic_set(&ddb_entry->retry_relogin_timer,
36982@@ -4517,7 +4517,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
36983
36984 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
36985 atomic_set(&ddb_entry->relogin_timer, 0);
36986- atomic_set(&ddb_entry->relogin_retry_count, 0);
36987+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
36988 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
36989 ddb_entry->default_relogin_timeout =
36990 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
36991diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
36992index bbbc9c9..ce22f77 100644
36993--- a/drivers/scsi/scsi.c
36994+++ b/drivers/scsi/scsi.c
36995@@ -659,7 +659,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
36996 unsigned long timeout;
36997 int rtn = 0;
36998
36999- atomic_inc(&cmd->device->iorequest_cnt);
37000+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37001
37002 /* check if the device is still usable */
37003 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37004diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37005index 495db80..fb37d59 100644
37006--- a/drivers/scsi/scsi_lib.c
37007+++ b/drivers/scsi/scsi_lib.c
37008@@ -1422,7 +1422,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37009 shost = sdev->host;
37010 scsi_init_cmd_errh(cmd);
37011 cmd->result = DID_NO_CONNECT << 16;
37012- atomic_inc(&cmd->device->iorequest_cnt);
37013+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37014
37015 /*
37016 * SCSI request completion path will do scsi_device_unbusy(),
37017@@ -1448,9 +1448,9 @@ static void scsi_softirq_done(struct request *rq)
37018
37019 INIT_LIST_HEAD(&cmd->eh_entry);
37020
37021- atomic_inc(&cmd->device->iodone_cnt);
37022+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
37023 if (cmd->result)
37024- atomic_inc(&cmd->device->ioerr_cnt);
37025+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37026
37027 disposition = scsi_decide_disposition(cmd);
37028 if (disposition != SUCCESS &&
37029diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37030index bb7c482..7551a95 100644
37031--- a/drivers/scsi/scsi_sysfs.c
37032+++ b/drivers/scsi/scsi_sysfs.c
37033@@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37034 char *buf) \
37035 { \
37036 struct scsi_device *sdev = to_scsi_device(dev); \
37037- unsigned long long count = atomic_read(&sdev->field); \
37038+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
37039 return snprintf(buf, 20, "0x%llx\n", count); \
37040 } \
37041 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37042diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37043index 84a1fdf..693b0d6 100644
37044--- a/drivers/scsi/scsi_tgt_lib.c
37045+++ b/drivers/scsi/scsi_tgt_lib.c
37046@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37047 int err;
37048
37049 dprintk("%lx %u\n", uaddr, len);
37050- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37051+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37052 if (err) {
37053 /*
37054 * TODO: need to fixup sg_tablesize, max_segment_size,
37055diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37056index 5797604..289a5b5 100644
37057--- a/drivers/scsi/scsi_transport_fc.c
37058+++ b/drivers/scsi/scsi_transport_fc.c
37059@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37060 * Netlink Infrastructure
37061 */
37062
37063-static atomic_t fc_event_seq;
37064+static atomic_unchecked_t fc_event_seq;
37065
37066 /**
37067 * fc_get_event_number - Obtain the next sequential FC event number
37068@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
37069 u32
37070 fc_get_event_number(void)
37071 {
37072- return atomic_add_return(1, &fc_event_seq);
37073+ return atomic_add_return_unchecked(1, &fc_event_seq);
37074 }
37075 EXPORT_SYMBOL(fc_get_event_number);
37076
37077@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
37078 {
37079 int error;
37080
37081- atomic_set(&fc_event_seq, 0);
37082+ atomic_set_unchecked(&fc_event_seq, 0);
37083
37084 error = transport_class_register(&fc_host_class);
37085 if (error)
37086@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37087 char *cp;
37088
37089 *val = simple_strtoul(buf, &cp, 0);
37090- if ((*cp && (*cp != '\n')) || (*val < 0))
37091+ if (*cp && (*cp != '\n'))
37092 return -EINVAL;
37093 /*
37094 * Check for overflow; dev_loss_tmo is u32
37095diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37096index 1cf640e..78e9014 100644
37097--- a/drivers/scsi/scsi_transport_iscsi.c
37098+++ b/drivers/scsi/scsi_transport_iscsi.c
37099@@ -79,7 +79,7 @@ struct iscsi_internal {
37100 struct transport_container session_cont;
37101 };
37102
37103-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37104+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37105 static struct workqueue_struct *iscsi_eh_timer_workq;
37106
37107 static DEFINE_IDA(iscsi_sess_ida);
37108@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37109 int err;
37110
37111 ihost = shost->shost_data;
37112- session->sid = atomic_add_return(1, &iscsi_session_nr);
37113+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37114
37115 if (target_id == ISCSI_MAX_TARGET) {
37116 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37117@@ -2940,7 +2940,7 @@ static __init int iscsi_transport_init(void)
37118 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37119 ISCSI_TRANSPORT_VERSION);
37120
37121- atomic_set(&iscsi_session_nr, 0);
37122+ atomic_set_unchecked(&iscsi_session_nr, 0);
37123
37124 err = class_register(&iscsi_transport_class);
37125 if (err)
37126diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37127index 21a045e..ec89e03 100644
37128--- a/drivers/scsi/scsi_transport_srp.c
37129+++ b/drivers/scsi/scsi_transport_srp.c
37130@@ -33,7 +33,7 @@
37131 #include "scsi_transport_srp_internal.h"
37132
37133 struct srp_host_attrs {
37134- atomic_t next_port_id;
37135+ atomic_unchecked_t next_port_id;
37136 };
37137 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37138
37139@@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37140 struct Scsi_Host *shost = dev_to_shost(dev);
37141 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37142
37143- atomic_set(&srp_host->next_port_id, 0);
37144+ atomic_set_unchecked(&srp_host->next_port_id, 0);
37145 return 0;
37146 }
37147
37148@@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37149 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37150 rport->roles = ids->roles;
37151
37152- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37153+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37154 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37155
37156 transport_setup_device(&rport->dev);
37157diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37158index 9c5c5f2..8414557 100644
37159--- a/drivers/scsi/sg.c
37160+++ b/drivers/scsi/sg.c
37161@@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37162 sdp->disk->disk_name,
37163 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37164 NULL,
37165- (char *)arg);
37166+ (char __user *)arg);
37167 case BLKTRACESTART:
37168 return blk_trace_startstop(sdp->device->request_queue, 1);
37169 case BLKTRACESTOP:
37170diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37171index 1041cb8..4a946fa 100644
37172--- a/drivers/spi/spi.c
37173+++ b/drivers/spi/spi.c
37174@@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
37175 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37176
37177 /* portable code must never pass more than 32 bytes */
37178-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37179+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37180
37181 static u8 *buf;
37182
37183diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37184index 34afc16..ffe44dd 100644
37185--- a/drivers/staging/octeon/ethernet-rx.c
37186+++ b/drivers/staging/octeon/ethernet-rx.c
37187@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37188 /* Increment RX stats for virtual ports */
37189 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37190 #ifdef CONFIG_64BIT
37191- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37192- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37193+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37194+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37195 #else
37196- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37197- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37198+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37199+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37200 #endif
37201 }
37202 netif_receive_skb(skb);
37203@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37204 dev->name);
37205 */
37206 #ifdef CONFIG_64BIT
37207- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37208+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37209 #else
37210- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37211+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37212 #endif
37213 dev_kfree_skb_irq(skb);
37214 }
37215diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37216index 18f7a79..cc3bc24 100644
37217--- a/drivers/staging/octeon/ethernet.c
37218+++ b/drivers/staging/octeon/ethernet.c
37219@@ -259,11 +259,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37220 * since the RX tasklet also increments it.
37221 */
37222 #ifdef CONFIG_64BIT
37223- atomic64_add(rx_status.dropped_packets,
37224- (atomic64_t *)&priv->stats.rx_dropped);
37225+ atomic64_add_unchecked(rx_status.dropped_packets,
37226+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37227 #else
37228- atomic_add(rx_status.dropped_packets,
37229- (atomic_t *)&priv->stats.rx_dropped);
37230+ atomic_add_unchecked(rx_status.dropped_packets,
37231+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
37232 #endif
37233 }
37234
37235diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37236index dc23395..cf7e9b1 100644
37237--- a/drivers/staging/rtl8712/rtl871x_io.h
37238+++ b/drivers/staging/rtl8712/rtl871x_io.h
37239@@ -108,7 +108,7 @@ struct _io_ops {
37240 u8 *pmem);
37241 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37242 u8 *pmem);
37243-};
37244+} __no_const;
37245
37246 struct io_req {
37247 struct list_head list;
37248diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37249index c7b5e8b..783d6cb 100644
37250--- a/drivers/staging/sbe-2t3e3/netdev.c
37251+++ b/drivers/staging/sbe-2t3e3/netdev.c
37252@@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37253 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37254
37255 if (rlen)
37256- if (copy_to_user(data, &resp, rlen))
37257+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37258 return -EFAULT;
37259
37260 return 0;
37261diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c
37262index 42cdafe..2769103 100644
37263--- a/drivers/staging/speakup/speakup_soft.c
37264+++ b/drivers/staging/speakup/speakup_soft.c
37265@@ -241,11 +241,11 @@ static ssize_t softsynth_read(struct file *fp, char *buf, size_t count,
37266 break;
37267 } else if (!initialized) {
37268 if (*init) {
37269- ch = *init;
37270 init++;
37271 } else {
37272 initialized = 1;
37273 }
37274+ ch = *init;
37275 } else {
37276 ch = synth_buffer_getc();
37277 }
37278diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37279index 5d89c0f..9261317 100644
37280--- a/drivers/staging/usbip/usbip_common.h
37281+++ b/drivers/staging/usbip/usbip_common.h
37282@@ -289,7 +289,7 @@ struct usbip_device {
37283 void (*shutdown)(struct usbip_device *);
37284 void (*reset)(struct usbip_device *);
37285 void (*unusable)(struct usbip_device *);
37286- } eh_ops;
37287+ } __no_const eh_ops;
37288 };
37289
37290 #define kthread_get_run(threadfn, data, namefmt, ...) \
37291diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37292index 88b3298..3783eee 100644
37293--- a/drivers/staging/usbip/vhci.h
37294+++ b/drivers/staging/usbip/vhci.h
37295@@ -88,7 +88,7 @@ struct vhci_hcd {
37296 unsigned resuming:1;
37297 unsigned long re_timeout;
37298
37299- atomic_t seqnum;
37300+ atomic_unchecked_t seqnum;
37301
37302 /*
37303 * NOTE:
37304diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37305index f708cba..2de6d72 100644
37306--- a/drivers/staging/usbip/vhci_hcd.c
37307+++ b/drivers/staging/usbip/vhci_hcd.c
37308@@ -488,7 +488,7 @@ static void vhci_tx_urb(struct urb *urb)
37309 return;
37310 }
37311
37312- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37313+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37314 if (priv->seqnum == 0xffff)
37315 dev_info(&urb->dev->dev, "seqnum max\n");
37316
37317@@ -740,7 +740,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37318 return -ENOMEM;
37319 }
37320
37321- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37322+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37323 if (unlink->seqnum == 0xffff)
37324 pr_info("seqnum max\n");
37325
37326@@ -928,7 +928,7 @@ static int vhci_start(struct usb_hcd *hcd)
37327 vdev->rhport = rhport;
37328 }
37329
37330- atomic_set(&vhci->seqnum, 0);
37331+ atomic_set_unchecked(&vhci->seqnum, 0);
37332 spin_lock_init(&vhci->lock);
37333
37334 hcd->power_budget = 0; /* no limit */
37335diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37336index f0eaf04..5a82e06 100644
37337--- a/drivers/staging/usbip/vhci_rx.c
37338+++ b/drivers/staging/usbip/vhci_rx.c
37339@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37340 if (!urb) {
37341 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37342 pr_info("max seqnum %d\n",
37343- atomic_read(&the_controller->seqnum));
37344+ atomic_read_unchecked(&the_controller->seqnum));
37345 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37346 return;
37347 }
37348diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37349index 7735027..30eed13 100644
37350--- a/drivers/staging/vt6655/hostap.c
37351+++ b/drivers/staging/vt6655/hostap.c
37352@@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
37353 *
37354 */
37355
37356+static net_device_ops_no_const apdev_netdev_ops;
37357+
37358 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37359 {
37360 PSDevice apdev_priv;
37361 struct net_device *dev = pDevice->dev;
37362 int ret;
37363- const struct net_device_ops apdev_netdev_ops = {
37364- .ndo_start_xmit = pDevice->tx_80211,
37365- };
37366
37367 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37368
37369@@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37370 *apdev_priv = *pDevice;
37371 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37372
37373+ /* only half broken now */
37374+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37375 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37376
37377 pDevice->apdev->type = ARPHRD_IEEE80211;
37378diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37379index 51b5adf..098e320 100644
37380--- a/drivers/staging/vt6656/hostap.c
37381+++ b/drivers/staging/vt6656/hostap.c
37382@@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
37383 *
37384 */
37385
37386+static net_device_ops_no_const apdev_netdev_ops;
37387+
37388 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37389 {
37390 PSDevice apdev_priv;
37391 struct net_device *dev = pDevice->dev;
37392 int ret;
37393- const struct net_device_ops apdev_netdev_ops = {
37394- .ndo_start_xmit = pDevice->tx_80211,
37395- };
37396
37397 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37398
37399@@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37400 *apdev_priv = *pDevice;
37401 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37402
37403+ /* only half broken now */
37404+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37405 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37406
37407 pDevice->apdev->type = ARPHRD_IEEE80211;
37408diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37409index 7843dfd..3db105f 100644
37410--- a/drivers/staging/wlan-ng/hfa384x_usb.c
37411+++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37412@@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37413
37414 struct usbctlx_completor {
37415 int (*complete) (struct usbctlx_completor *);
37416-};
37417+} __no_const;
37418
37419 static int
37420 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37421diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37422index 1ca66ea..76f1343 100644
37423--- a/drivers/staging/zcache/tmem.c
37424+++ b/drivers/staging/zcache/tmem.c
37425@@ -39,7 +39,7 @@
37426 * A tmem host implementation must use this function to register callbacks
37427 * for memory allocation.
37428 */
37429-static struct tmem_hostops tmem_hostops;
37430+static tmem_hostops_no_const tmem_hostops;
37431
37432 static void tmem_objnode_tree_init(void);
37433
37434@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37435 * A tmem host implementation must use this function to register
37436 * callbacks for a page-accessible memory (PAM) implementation
37437 */
37438-static struct tmem_pamops tmem_pamops;
37439+static tmem_pamops_no_const tmem_pamops;
37440
37441 void tmem_register_pamops(struct tmem_pamops *m)
37442 {
37443diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37444index 0d4aa82..f7832d4 100644
37445--- a/drivers/staging/zcache/tmem.h
37446+++ b/drivers/staging/zcache/tmem.h
37447@@ -180,6 +180,7 @@ struct tmem_pamops {
37448 void (*new_obj)(struct tmem_obj *);
37449 int (*replace_in_obj)(void *, struct tmem_obj *);
37450 };
37451+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37452 extern void tmem_register_pamops(struct tmem_pamops *m);
37453
37454 /* memory allocation methods provided by the host implementation */
37455@@ -189,6 +190,7 @@ struct tmem_hostops {
37456 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37457 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37458 };
37459+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37460 extern void tmem_register_hostops(struct tmem_hostops *m);
37461
37462 /* core tmem accessor functions */
37463diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37464index c6c385f..b23c65d 100644
37465--- a/drivers/target/target_core_transport.c
37466+++ b/drivers/target/target_core_transport.c
37467@@ -1233,7 +1233,7 @@ struct se_device *transport_add_device_to_core_hba(
37468 spin_lock_init(&dev->se_port_lock);
37469 spin_lock_init(&dev->se_tmr_lock);
37470 spin_lock_init(&dev->qf_cmd_lock);
37471- atomic_set(&dev->dev_ordered_id, 0);
37472+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
37473
37474 se_dev_set_default_attribs(dev, dev_limits);
37475
37476@@ -1402,7 +1402,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37477 * Used to determine when ORDERED commands should go from
37478 * Dormant to Active status.
37479 */
37480- cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37481+ cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37482 smp_mb__after_atomic_inc();
37483 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37484 cmd->se_ordered_id, cmd->sam_task_attr,
37485diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
37486index e61cabd..7617d26 100644
37487--- a/drivers/tty/cyclades.c
37488+++ b/drivers/tty/cyclades.c
37489@@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
37490 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
37491 info->port.count);
37492 #endif
37493- info->port.count++;
37494+ atomic_inc(&info->port.count);
37495 #ifdef CY_DEBUG_COUNT
37496 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
37497- current->pid, info->port.count);
37498+ current->pid, atomic_read(&info->port.count));
37499 #endif
37500
37501 /*
37502@@ -3987,7 +3987,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
37503 for (j = 0; j < cy_card[i].nports; j++) {
37504 info = &cy_card[i].ports[j];
37505
37506- if (info->port.count) {
37507+ if (atomic_read(&info->port.count)) {
37508 /* XXX is the ldisc num worth this? */
37509 struct tty_struct *tty;
37510 struct tty_ldisc *ld;
37511diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
37512index 2d691eb..be02ebd 100644
37513--- a/drivers/tty/hvc/hvc_console.c
37514+++ b/drivers/tty/hvc/hvc_console.c
37515@@ -315,7 +315,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
37516
37517 spin_lock_irqsave(&hp->port.lock, flags);
37518 /* Check and then increment for fast path open. */
37519- if (hp->port.count++ > 0) {
37520+ if (atomic_inc_return(&hp->port.count) > 1) {
37521 spin_unlock_irqrestore(&hp->port.lock, flags);
37522 hvc_kick();
37523 return 0;
37524@@ -366,7 +366,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37525
37526 spin_lock_irqsave(&hp->port.lock, flags);
37527
37528- if (--hp->port.count == 0) {
37529+ if (atomic_dec_return(&hp->port.count) == 0) {
37530 spin_unlock_irqrestore(&hp->port.lock, flags);
37531 /* We are done with the tty pointer now. */
37532 tty_port_tty_set(&hp->port, NULL);
37533@@ -384,9 +384,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37534 */
37535 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
37536 } else {
37537- if (hp->port.count < 0)
37538+ if (atomic_read(&hp->port.count) < 0)
37539 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
37540- hp->vtermno, hp->port.count);
37541+ hp->vtermno, atomic_read(&hp->port.count));
37542 spin_unlock_irqrestore(&hp->port.lock, flags);
37543 }
37544
37545@@ -412,13 +412,13 @@ static void hvc_hangup(struct tty_struct *tty)
37546 * open->hangup case this can be called after the final close so prevent
37547 * that from happening for now.
37548 */
37549- if (hp->port.count <= 0) {
37550+ if (atomic_read(&hp->port.count) <= 0) {
37551 spin_unlock_irqrestore(&hp->port.lock, flags);
37552 return;
37553 }
37554
37555- temp_open_count = hp->port.count;
37556- hp->port.count = 0;
37557+ temp_open_count = atomic_read(&hp->port.count);
37558+ atomic_set(&hp->port.count, 0);
37559 spin_unlock_irqrestore(&hp->port.lock, flags);
37560 tty_port_tty_set(&hp->port, NULL);
37561
37562@@ -471,7 +471,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
37563 return -EPIPE;
37564
37565 /* FIXME what's this (unprotected) check for? */
37566- if (hp->port.count <= 0)
37567+ if (atomic_read(&hp->port.count) <= 0)
37568 return -EIO;
37569
37570 spin_lock_irqsave(&hp->lock, flags);
37571diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37572index d56788c..12d8f85 100644
37573--- a/drivers/tty/hvc/hvcs.c
37574+++ b/drivers/tty/hvc/hvcs.c
37575@@ -83,6 +83,7 @@
37576 #include <asm/hvcserver.h>
37577 #include <asm/uaccess.h>
37578 #include <asm/vio.h>
37579+#include <asm/local.h>
37580
37581 /*
37582 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37583@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37584
37585 spin_lock_irqsave(&hvcsd->lock, flags);
37586
37587- if (hvcsd->port.count > 0) {
37588+ if (atomic_read(&hvcsd->port.count) > 0) {
37589 spin_unlock_irqrestore(&hvcsd->lock, flags);
37590 printk(KERN_INFO "HVCS: vterm state unchanged. "
37591 "The hvcs device node is still in use.\n");
37592@@ -1134,7 +1135,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37593 if ((retval = hvcs_partner_connect(hvcsd)))
37594 goto error_release;
37595
37596- hvcsd->port.count = 1;
37597+ atomic_set(&hvcsd->port.count, 1);
37598 hvcsd->port.tty = tty;
37599 tty->driver_data = hvcsd;
37600
37601@@ -1168,7 +1169,7 @@ fast_open:
37602
37603 spin_lock_irqsave(&hvcsd->lock, flags);
37604 tty_port_get(&hvcsd->port);
37605- hvcsd->port.count++;
37606+ atomic_inc(&hvcsd->port.count);
37607 hvcsd->todo_mask |= HVCS_SCHED_READ;
37608 spin_unlock_irqrestore(&hvcsd->lock, flags);
37609
37610@@ -1212,7 +1213,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37611 hvcsd = tty->driver_data;
37612
37613 spin_lock_irqsave(&hvcsd->lock, flags);
37614- if (--hvcsd->port.count == 0) {
37615+ if (atomic_dec_and_test(&hvcsd->port.count)) {
37616
37617 vio_disable_interrupts(hvcsd->vdev);
37618
37619@@ -1238,10 +1239,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37620 free_irq(irq, hvcsd);
37621 tty_port_put(&hvcsd->port);
37622 return;
37623- } else if (hvcsd->port.count < 0) {
37624+ } else if (atomic_read(&hvcsd->port.count) < 0) {
37625 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
37626 " is missmanaged.\n",
37627- hvcsd->vdev->unit_address, hvcsd->port.count);
37628+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
37629 }
37630
37631 spin_unlock_irqrestore(&hvcsd->lock, flags);
37632@@ -1257,7 +1258,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37633
37634 spin_lock_irqsave(&hvcsd->lock, flags);
37635 /* Preserve this so that we know how many kref refs to put */
37636- temp_open_count = hvcsd->port.count;
37637+ temp_open_count = atomic_read(&hvcsd->port.count);
37638
37639 /*
37640 * Don't kref put inside the spinlock because the destruction
37641@@ -1272,7 +1273,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37642 tty->driver_data = NULL;
37643 hvcsd->port.tty = NULL;
37644
37645- hvcsd->port.count = 0;
37646+ atomic_set(&hvcsd->port.count, 0);
37647
37648 /* This will drop any buffered data on the floor which is OK in a hangup
37649 * scenario. */
37650@@ -1343,7 +1344,7 @@ static int hvcs_write(struct tty_struct *tty,
37651 * the middle of a write operation? This is a crummy place to do this
37652 * but we want to keep it all in the spinlock.
37653 */
37654- if (hvcsd->port.count <= 0) {
37655+ if (atomic_read(&hvcsd->port.count) <= 0) {
37656 spin_unlock_irqrestore(&hvcsd->lock, flags);
37657 return -ENODEV;
37658 }
37659@@ -1417,7 +1418,7 @@ static int hvcs_write_room(struct tty_struct *tty)
37660 {
37661 struct hvcs_struct *hvcsd = tty->driver_data;
37662
37663- if (!hvcsd || hvcsd->port.count <= 0)
37664+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
37665 return 0;
37666
37667 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
37668diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
37669index f8b5fa0..4ba9f89 100644
37670--- a/drivers/tty/ipwireless/tty.c
37671+++ b/drivers/tty/ipwireless/tty.c
37672@@ -29,6 +29,7 @@
37673 #include <linux/tty_driver.h>
37674 #include <linux/tty_flip.h>
37675 #include <linux/uaccess.h>
37676+#include <asm/local.h>
37677
37678 #include "tty.h"
37679 #include "network.h"
37680@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37681 mutex_unlock(&tty->ipw_tty_mutex);
37682 return -ENODEV;
37683 }
37684- if (tty->port.count == 0)
37685+ if (atomic_read(&tty->port.count) == 0)
37686 tty->tx_bytes_queued = 0;
37687
37688- tty->port.count++;
37689+ atomic_inc(&tty->port.count);
37690
37691 tty->port.tty = linux_tty;
37692 linux_tty->driver_data = tty;
37693@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37694
37695 static void do_ipw_close(struct ipw_tty *tty)
37696 {
37697- tty->port.count--;
37698-
37699- if (tty->port.count == 0) {
37700+ if (atomic_dec_return(&tty->port.count) == 0) {
37701 struct tty_struct *linux_tty = tty->port.tty;
37702
37703 if (linux_tty != NULL) {
37704@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
37705 return;
37706
37707 mutex_lock(&tty->ipw_tty_mutex);
37708- if (tty->port.count == 0) {
37709+ if (atomic_read(&tty->port.count) == 0) {
37710 mutex_unlock(&tty->ipw_tty_mutex);
37711 return;
37712 }
37713@@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
37714 return;
37715 }
37716
37717- if (!tty->port.count) {
37718+ if (!atomic_read(&tty->port.count)) {
37719 mutex_unlock(&tty->ipw_tty_mutex);
37720 return;
37721 }
37722@@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
37723 return -ENODEV;
37724
37725 mutex_lock(&tty->ipw_tty_mutex);
37726- if (!tty->port.count) {
37727+ if (!atomic_read(&tty->port.count)) {
37728 mutex_unlock(&tty->ipw_tty_mutex);
37729 return -EINVAL;
37730 }
37731@@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
37732 if (!tty)
37733 return -ENODEV;
37734
37735- if (!tty->port.count)
37736+ if (!atomic_read(&tty->port.count))
37737 return -EINVAL;
37738
37739 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
37740@@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
37741 if (!tty)
37742 return 0;
37743
37744- if (!tty->port.count)
37745+ if (!atomic_read(&tty->port.count))
37746 return 0;
37747
37748 return tty->tx_bytes_queued;
37749@@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
37750 if (!tty)
37751 return -ENODEV;
37752
37753- if (!tty->port.count)
37754+ if (!atomic_read(&tty->port.count))
37755 return -EINVAL;
37756
37757 return get_control_lines(tty);
37758@@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
37759 if (!tty)
37760 return -ENODEV;
37761
37762- if (!tty->port.count)
37763+ if (!atomic_read(&tty->port.count))
37764 return -EINVAL;
37765
37766 return set_control_lines(tty, set, clear);
37767@@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
37768 if (!tty)
37769 return -ENODEV;
37770
37771- if (!tty->port.count)
37772+ if (!atomic_read(&tty->port.count))
37773 return -EINVAL;
37774
37775 /* FIXME: Exactly how is the tty object locked here .. */
37776@@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
37777 * are gone */
37778 mutex_lock(&ttyj->ipw_tty_mutex);
37779 }
37780- while (ttyj->port.count)
37781+ while (atomic_read(&ttyj->port.count))
37782 do_ipw_close(ttyj);
37783 ipwireless_disassociate_network_ttys(network,
37784 ttyj->channel_idx);
37785diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
37786index 324467d..504cc25 100644
37787--- a/drivers/tty/moxa.c
37788+++ b/drivers/tty/moxa.c
37789@@ -1172,7 +1172,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
37790 }
37791
37792 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
37793- ch->port.count++;
37794+ atomic_inc(&ch->port.count);
37795 tty->driver_data = ch;
37796 tty_port_tty_set(&ch->port, tty);
37797 mutex_lock(&ch->port.mutex);
37798diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
37799index c43b683..4dab83e 100644
37800--- a/drivers/tty/n_gsm.c
37801+++ b/drivers/tty/n_gsm.c
37802@@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
37803 kref_init(&dlci->ref);
37804 mutex_init(&dlci->mutex);
37805 dlci->fifo = &dlci->_fifo;
37806- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
37807+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
37808 kfree(dlci);
37809 return NULL;
37810 }
37811@@ -2895,7 +2895,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
37812 if (dlci == NULL)
37813 return -ENOMEM;
37814 port = &dlci->port;
37815- port->count++;
37816+ atomic_inc(&port->count);
37817 tty->driver_data = dlci;
37818 dlci_get(dlci);
37819 dlci_get(dlci->gsm->dlci[0]);
37820diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
37821index ee1c268..0e97caf 100644
37822--- a/drivers/tty/n_tty.c
37823+++ b/drivers/tty/n_tty.c
37824@@ -2123,6 +2123,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
37825 {
37826 *ops = tty_ldisc_N_TTY;
37827 ops->owner = NULL;
37828- ops->refcount = ops->flags = 0;
37829+ atomic_set(&ops->refcount, 0);
37830+ ops->flags = 0;
37831 }
37832 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
37833diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
37834index 5505ffc..7affff9 100644
37835--- a/drivers/tty/pty.c
37836+++ b/drivers/tty/pty.c
37837@@ -718,8 +718,10 @@ static void __init unix98_pty_init(void)
37838 panic("Couldn't register Unix98 pts driver");
37839
37840 /* Now create the /dev/ptmx special device */
37841+ pax_open_kernel();
37842 tty_default_fops(&ptmx_fops);
37843- ptmx_fops.open = ptmx_open;
37844+ *(void **)&ptmx_fops.open = ptmx_open;
37845+ pax_close_kernel();
37846
37847 cdev_init(&ptmx_cdev, &ptmx_fops);
37848 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
37849diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
37850index 777d5f9..56d67ca 100644
37851--- a/drivers/tty/rocket.c
37852+++ b/drivers/tty/rocket.c
37853@@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
37854 tty->driver_data = info;
37855 tty_port_tty_set(port, tty);
37856
37857- if (port->count++ == 0) {
37858+ if (atomic_inc_return(&port->count) == 1) {
37859 atomic_inc(&rp_num_ports_open);
37860
37861 #ifdef ROCKET_DEBUG_OPEN
37862@@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
37863 #endif
37864 }
37865 #ifdef ROCKET_DEBUG_OPEN
37866- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
37867+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
37868 #endif
37869
37870 /*
37871@@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
37872 spin_unlock_irqrestore(&info->port.lock, flags);
37873 return;
37874 }
37875- if (info->port.count)
37876+ if (atomic_read(&info->port.count))
37877 atomic_dec(&rp_num_ports_open);
37878 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
37879 spin_unlock_irqrestore(&info->port.lock, flags);
37880diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
37881index 2b42a01..32a2ed3 100644
37882--- a/drivers/tty/serial/kgdboc.c
37883+++ b/drivers/tty/serial/kgdboc.c
37884@@ -24,8 +24,9 @@
37885 #define MAX_CONFIG_LEN 40
37886
37887 static struct kgdb_io kgdboc_io_ops;
37888+static struct kgdb_io kgdboc_io_ops_console;
37889
37890-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
37891+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
37892 static int configured = -1;
37893
37894 static char config[MAX_CONFIG_LEN];
37895@@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
37896 kgdboc_unregister_kbd();
37897 if (configured == 1)
37898 kgdb_unregister_io_module(&kgdboc_io_ops);
37899+ else if (configured == 2)
37900+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
37901 }
37902
37903 static int configure_kgdboc(void)
37904@@ -157,13 +160,13 @@ static int configure_kgdboc(void)
37905 int err;
37906 char *cptr = config;
37907 struct console *cons;
37908+ int is_console = 0;
37909
37910 err = kgdboc_option_setup(config);
37911 if (err || !strlen(config) || isspace(config[0]))
37912 goto noconfig;
37913
37914 err = -ENODEV;
37915- kgdboc_io_ops.is_console = 0;
37916 kgdb_tty_driver = NULL;
37917
37918 kgdboc_use_kms = 0;
37919@@ -184,7 +187,7 @@ static int configure_kgdboc(void)
37920 int idx;
37921 if (cons->device && cons->device(cons, &idx) == p &&
37922 idx == tty_line) {
37923- kgdboc_io_ops.is_console = 1;
37924+ is_console = 1;
37925 break;
37926 }
37927 cons = cons->next;
37928@@ -194,12 +197,16 @@ static int configure_kgdboc(void)
37929 kgdb_tty_line = tty_line;
37930
37931 do_register:
37932- err = kgdb_register_io_module(&kgdboc_io_ops);
37933+ if (is_console) {
37934+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
37935+ configured = 2;
37936+ } else {
37937+ err = kgdb_register_io_module(&kgdboc_io_ops);
37938+ configured = 1;
37939+ }
37940 if (err)
37941 goto noconfig;
37942
37943- configured = 1;
37944-
37945 return 0;
37946
37947 noconfig:
37948@@ -213,7 +220,7 @@ noconfig:
37949 static int __init init_kgdboc(void)
37950 {
37951 /* Already configured? */
37952- if (configured == 1)
37953+ if (configured >= 1)
37954 return 0;
37955
37956 return configure_kgdboc();
37957@@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
37958 if (config[len - 1] == '\n')
37959 config[len - 1] = '\0';
37960
37961- if (configured == 1)
37962+ if (configured >= 1)
37963 cleanup_kgdboc();
37964
37965 /* Go and configure with the new params. */
37966@@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
37967 .post_exception = kgdboc_post_exp_handler,
37968 };
37969
37970+static struct kgdb_io kgdboc_io_ops_console = {
37971+ .name = "kgdboc",
37972+ .read_char = kgdboc_get_char,
37973+ .write_char = kgdboc_put_char,
37974+ .pre_exception = kgdboc_pre_exp_handler,
37975+ .post_exception = kgdboc_post_exp_handler,
37976+ .is_console = 1
37977+};
37978+
37979 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
37980 /* This is only available if kgdboc is a built in for early debugging */
37981 static int __init kgdboc_early_init(char *opt)
37982diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
37983index 246b823..9e0db76 100644
37984--- a/drivers/tty/serial/serial_core.c
37985+++ b/drivers/tty/serial/serial_core.c
37986@@ -1392,7 +1392,7 @@ static void uart_hangup(struct tty_struct *tty)
37987 uart_flush_buffer(tty);
37988 uart_shutdown(tty, state);
37989 spin_lock_irqsave(&port->lock, flags);
37990- port->count = 0;
37991+ atomic_set(&port->count, 0);
37992 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
37993 spin_unlock_irqrestore(&port->lock, flags);
37994 tty_port_tty_set(port, NULL);
37995@@ -1488,7 +1488,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
37996 goto end;
37997 }
37998
37999- port->count++;
38000+ atomic_inc(&port->count);
38001 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
38002 retval = -ENXIO;
38003 goto err_dec_count;
38004@@ -1515,7 +1515,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38005 /*
38006 * Make sure the device is in D0 state.
38007 */
38008- if (port->count == 1)
38009+ if (atomic_read(&port->count) == 1)
38010 uart_change_pm(state, 0);
38011
38012 /*
38013@@ -1533,7 +1533,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38014 end:
38015 return retval;
38016 err_dec_count:
38017- port->count--;
38018+ atomic_inc(&port->count);
38019 mutex_unlock(&port->mutex);
38020 goto end;
38021 }
38022diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
38023index 593d40a..bdc61f3 100644
38024--- a/drivers/tty/synclink.c
38025+++ b/drivers/tty/synclink.c
38026@@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38027
38028 if (debug_level >= DEBUG_LEVEL_INFO)
38029 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
38030- __FILE__,__LINE__, info->device_name, info->port.count);
38031+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38032
38033 if (tty_port_close_start(&info->port, tty, filp) == 0)
38034 goto cleanup;
38035@@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38036 cleanup:
38037 if (debug_level >= DEBUG_LEVEL_INFO)
38038 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
38039- tty->driver->name, info->port.count);
38040+ tty->driver->name, atomic_read(&info->port.count));
38041
38042 } /* end of mgsl_close() */
38043
38044@@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
38045
38046 mgsl_flush_buffer(tty);
38047 shutdown(info);
38048-
38049- info->port.count = 0;
38050+
38051+ atomic_set(&info->port.count, 0);
38052 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38053 info->port.tty = NULL;
38054
38055@@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38056
38057 if (debug_level >= DEBUG_LEVEL_INFO)
38058 printk("%s(%d):block_til_ready before block on %s count=%d\n",
38059- __FILE__,__LINE__, tty->driver->name, port->count );
38060+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38061
38062 spin_lock_irqsave(&info->irq_spinlock, flags);
38063 if (!tty_hung_up_p(filp)) {
38064 extra_count = true;
38065- port->count--;
38066+ atomic_dec(&port->count);
38067 }
38068 spin_unlock_irqrestore(&info->irq_spinlock, flags);
38069 port->blocked_open++;
38070@@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38071
38072 if (debug_level >= DEBUG_LEVEL_INFO)
38073 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
38074- __FILE__,__LINE__, tty->driver->name, port->count );
38075+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38076
38077 tty_unlock();
38078 schedule();
38079@@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38080
38081 /* FIXME: Racy on hangup during close wait */
38082 if (extra_count)
38083- port->count++;
38084+ atomic_inc(&port->count);
38085 port->blocked_open--;
38086
38087 if (debug_level >= DEBUG_LEVEL_INFO)
38088 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
38089- __FILE__,__LINE__, tty->driver->name, port->count );
38090+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38091
38092 if (!retval)
38093 port->flags |= ASYNC_NORMAL_ACTIVE;
38094@@ -3398,7 +3398,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38095
38096 if (debug_level >= DEBUG_LEVEL_INFO)
38097 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
38098- __FILE__,__LINE__,tty->driver->name, info->port.count);
38099+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38100
38101 /* If port is closing, signal caller to try again */
38102 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38103@@ -3417,10 +3417,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38104 spin_unlock_irqrestore(&info->netlock, flags);
38105 goto cleanup;
38106 }
38107- info->port.count++;
38108+ atomic_inc(&info->port.count);
38109 spin_unlock_irqrestore(&info->netlock, flags);
38110
38111- if (info->port.count == 1) {
38112+ if (atomic_read(&info->port.count) == 1) {
38113 /* 1st open on this device, init hardware */
38114 retval = startup(info);
38115 if (retval < 0)
38116@@ -3444,8 +3444,8 @@ cleanup:
38117 if (retval) {
38118 if (tty->count == 1)
38119 info->port.tty = NULL; /* tty layer will release tty struct */
38120- if(info->port.count)
38121- info->port.count--;
38122+ if (atomic_read(&info->port.count))
38123+ atomic_dec(&info->port.count);
38124 }
38125
38126 return retval;
38127@@ -7653,7 +7653,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38128 unsigned short new_crctype;
38129
38130 /* return error if TTY interface open */
38131- if (info->port.count)
38132+ if (atomic_read(&info->port.count))
38133 return -EBUSY;
38134
38135 switch (encoding)
38136@@ -7748,7 +7748,7 @@ static int hdlcdev_open(struct net_device *dev)
38137
38138 /* arbitrate between network and tty opens */
38139 spin_lock_irqsave(&info->netlock, flags);
38140- if (info->port.count != 0 || info->netcount != 0) {
38141+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38142 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38143 spin_unlock_irqrestore(&info->netlock, flags);
38144 return -EBUSY;
38145@@ -7834,7 +7834,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38146 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38147
38148 /* return error if TTY interface open */
38149- if (info->port.count)
38150+ if (atomic_read(&info->port.count))
38151 return -EBUSY;
38152
38153 if (cmd != SIOCWANDEV)
38154diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
38155index aa1debf..9297a16 100644
38156--- a/drivers/tty/synclink_gt.c
38157+++ b/drivers/tty/synclink_gt.c
38158@@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38159 tty->driver_data = info;
38160 info->port.tty = tty;
38161
38162- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
38163+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
38164
38165 /* If port is closing, signal caller to try again */
38166 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38167@@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38168 mutex_unlock(&info->port.mutex);
38169 goto cleanup;
38170 }
38171- info->port.count++;
38172+ atomic_inc(&info->port.count);
38173 spin_unlock_irqrestore(&info->netlock, flags);
38174
38175- if (info->port.count == 1) {
38176+ if (atomic_read(&info->port.count) == 1) {
38177 /* 1st open on this device, init hardware */
38178 retval = startup(info);
38179 if (retval < 0) {
38180@@ -716,8 +716,8 @@ cleanup:
38181 if (retval) {
38182 if (tty->count == 1)
38183 info->port.tty = NULL; /* tty layer will release tty struct */
38184- if(info->port.count)
38185- info->port.count--;
38186+ if(atomic_read(&info->port.count))
38187+ atomic_dec(&info->port.count);
38188 }
38189
38190 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
38191@@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38192
38193 if (sanity_check(info, tty->name, "close"))
38194 return;
38195- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
38196+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
38197
38198 if (tty_port_close_start(&info->port, tty, filp) == 0)
38199 goto cleanup;
38200@@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38201 tty_port_close_end(&info->port, tty);
38202 info->port.tty = NULL;
38203 cleanup:
38204- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
38205+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
38206 }
38207
38208 static void hangup(struct tty_struct *tty)
38209@@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
38210 shutdown(info);
38211
38212 spin_lock_irqsave(&info->port.lock, flags);
38213- info->port.count = 0;
38214+ atomic_set(&info->port.count, 0);
38215 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38216 info->port.tty = NULL;
38217 spin_unlock_irqrestore(&info->port.lock, flags);
38218@@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38219 unsigned short new_crctype;
38220
38221 /* return error if TTY interface open */
38222- if (info->port.count)
38223+ if (atomic_read(&info->port.count))
38224 return -EBUSY;
38225
38226 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
38227@@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
38228
38229 /* arbitrate between network and tty opens */
38230 spin_lock_irqsave(&info->netlock, flags);
38231- if (info->port.count != 0 || info->netcount != 0) {
38232+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38233 DBGINFO(("%s hdlc_open busy\n", dev->name));
38234 spin_unlock_irqrestore(&info->netlock, flags);
38235 return -EBUSY;
38236@@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38237 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
38238
38239 /* return error if TTY interface open */
38240- if (info->port.count)
38241+ if (atomic_read(&info->port.count))
38242 return -EBUSY;
38243
38244 if (cmd != SIOCWANDEV)
38245@@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
38246 if (port == NULL)
38247 continue;
38248 spin_lock(&port->lock);
38249- if ((port->port.count || port->netcount) &&
38250+ if ((atomic_read(&port->port.count) || port->netcount) &&
38251 port->pending_bh && !port->bh_running &&
38252 !port->bh_requested) {
38253 DBGISR(("%s bh queued\n", port->device_name));
38254@@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38255 spin_lock_irqsave(&info->lock, flags);
38256 if (!tty_hung_up_p(filp)) {
38257 extra_count = true;
38258- port->count--;
38259+ atomic_dec(&port->count);
38260 }
38261 spin_unlock_irqrestore(&info->lock, flags);
38262 port->blocked_open++;
38263@@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38264 remove_wait_queue(&port->open_wait, &wait);
38265
38266 if (extra_count)
38267- port->count++;
38268+ atomic_inc(&port->count);
38269 port->blocked_open--;
38270
38271 if (!retval)
38272diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
38273index a3dddc1..8905ab2 100644
38274--- a/drivers/tty/synclinkmp.c
38275+++ b/drivers/tty/synclinkmp.c
38276@@ -742,7 +742,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38277
38278 if (debug_level >= DEBUG_LEVEL_INFO)
38279 printk("%s(%d):%s open(), old ref count = %d\n",
38280- __FILE__,__LINE__,tty->driver->name, info->port.count);
38281+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38282
38283 /* If port is closing, signal caller to try again */
38284 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38285@@ -761,10 +761,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38286 spin_unlock_irqrestore(&info->netlock, flags);
38287 goto cleanup;
38288 }
38289- info->port.count++;
38290+ atomic_inc(&info->port.count);
38291 spin_unlock_irqrestore(&info->netlock, flags);
38292
38293- if (info->port.count == 1) {
38294+ if (atomic_read(&info->port.count) == 1) {
38295 /* 1st open on this device, init hardware */
38296 retval = startup(info);
38297 if (retval < 0)
38298@@ -788,8 +788,8 @@ cleanup:
38299 if (retval) {
38300 if (tty->count == 1)
38301 info->port.tty = NULL; /* tty layer will release tty struct */
38302- if(info->port.count)
38303- info->port.count--;
38304+ if(atomic_read(&info->port.count))
38305+ atomic_dec(&info->port.count);
38306 }
38307
38308 return retval;
38309@@ -807,7 +807,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38310
38311 if (debug_level >= DEBUG_LEVEL_INFO)
38312 printk("%s(%d):%s close() entry, count=%d\n",
38313- __FILE__,__LINE__, info->device_name, info->port.count);
38314+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38315
38316 if (tty_port_close_start(&info->port, tty, filp) == 0)
38317 goto cleanup;
38318@@ -826,7 +826,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38319 cleanup:
38320 if (debug_level >= DEBUG_LEVEL_INFO)
38321 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
38322- tty->driver->name, info->port.count);
38323+ tty->driver->name, atomic_read(&info->port.count));
38324 }
38325
38326 /* Called by tty_hangup() when a hangup is signaled.
38327@@ -849,7 +849,7 @@ static void hangup(struct tty_struct *tty)
38328 shutdown(info);
38329
38330 spin_lock_irqsave(&info->port.lock, flags);
38331- info->port.count = 0;
38332+ atomic_set(&info->port.count, 0);
38333 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38334 info->port.tty = NULL;
38335 spin_unlock_irqrestore(&info->port.lock, flags);
38336@@ -1557,7 +1557,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38337 unsigned short new_crctype;
38338
38339 /* return error if TTY interface open */
38340- if (info->port.count)
38341+ if (atomic_read(&info->port.count))
38342 return -EBUSY;
38343
38344 switch (encoding)
38345@@ -1652,7 +1652,7 @@ static int hdlcdev_open(struct net_device *dev)
38346
38347 /* arbitrate between network and tty opens */
38348 spin_lock_irqsave(&info->netlock, flags);
38349- if (info->port.count != 0 || info->netcount != 0) {
38350+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38351 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38352 spin_unlock_irqrestore(&info->netlock, flags);
38353 return -EBUSY;
38354@@ -1738,7 +1738,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38355 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38356
38357 /* return error if TTY interface open */
38358- if (info->port.count)
38359+ if (atomic_read(&info->port.count))
38360 return -EBUSY;
38361
38362 if (cmd != SIOCWANDEV)
38363@@ -2623,7 +2623,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
38364 * do not request bottom half processing if the
38365 * device is not open in a normal mode.
38366 */
38367- if ( port && (port->port.count || port->netcount) &&
38368+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
38369 port->pending_bh && !port->bh_running &&
38370 !port->bh_requested ) {
38371 if ( debug_level >= DEBUG_LEVEL_ISR )
38372@@ -3321,12 +3321,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38373
38374 if (debug_level >= DEBUG_LEVEL_INFO)
38375 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
38376- __FILE__,__LINE__, tty->driver->name, port->count );
38377+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38378
38379 spin_lock_irqsave(&info->lock, flags);
38380 if (!tty_hung_up_p(filp)) {
38381 extra_count = true;
38382- port->count--;
38383+ atomic_dec(&port->count);
38384 }
38385 spin_unlock_irqrestore(&info->lock, flags);
38386 port->blocked_open++;
38387@@ -3355,7 +3355,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38388
38389 if (debug_level >= DEBUG_LEVEL_INFO)
38390 printk("%s(%d):%s block_til_ready() count=%d\n",
38391- __FILE__,__LINE__, tty->driver->name, port->count );
38392+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38393
38394 tty_unlock();
38395 schedule();
38396@@ -3366,12 +3366,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38397 remove_wait_queue(&port->open_wait, &wait);
38398
38399 if (extra_count)
38400- port->count++;
38401+ atomic_inc(&port->count);
38402 port->blocked_open--;
38403
38404 if (debug_level >= DEBUG_LEVEL_INFO)
38405 printk("%s(%d):%s block_til_ready() after, count=%d\n",
38406- __FILE__,__LINE__, tty->driver->name, port->count );
38407+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38408
38409 if (!retval)
38410 port->flags |= ASYNC_NORMAL_ACTIVE;
38411diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38412index 05728894..b9d44c6 100644
38413--- a/drivers/tty/sysrq.c
38414+++ b/drivers/tty/sysrq.c
38415@@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38416 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38417 size_t count, loff_t *ppos)
38418 {
38419- if (count) {
38420+ if (count && capable(CAP_SYS_ADMIN)) {
38421 char c;
38422
38423 if (get_user(c, buf))
38424diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38425index b425c79..08a3f06 100644
38426--- a/drivers/tty/tty_io.c
38427+++ b/drivers/tty/tty_io.c
38428@@ -3283,7 +3283,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38429
38430 void tty_default_fops(struct file_operations *fops)
38431 {
38432- *fops = tty_fops;
38433+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38434 }
38435
38436 /*
38437diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38438index 9911eb6..5abe0e1 100644
38439--- a/drivers/tty/tty_ldisc.c
38440+++ b/drivers/tty/tty_ldisc.c
38441@@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38442 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38443 struct tty_ldisc_ops *ldo = ld->ops;
38444
38445- ldo->refcount--;
38446+ atomic_dec(&ldo->refcount);
38447 module_put(ldo->owner);
38448 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38449
38450@@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38451 spin_lock_irqsave(&tty_ldisc_lock, flags);
38452 tty_ldiscs[disc] = new_ldisc;
38453 new_ldisc->num = disc;
38454- new_ldisc->refcount = 0;
38455+ atomic_set(&new_ldisc->refcount, 0);
38456 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38457
38458 return ret;
38459@@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
38460 return -EINVAL;
38461
38462 spin_lock_irqsave(&tty_ldisc_lock, flags);
38463- if (tty_ldiscs[disc]->refcount)
38464+ if (atomic_read(&tty_ldiscs[disc]->refcount))
38465 ret = -EBUSY;
38466 else
38467 tty_ldiscs[disc] = NULL;
38468@@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38469 if (ldops) {
38470 ret = ERR_PTR(-EAGAIN);
38471 if (try_module_get(ldops->owner)) {
38472- ldops->refcount++;
38473+ atomic_inc(&ldops->refcount);
38474 ret = ldops;
38475 }
38476 }
38477@@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38478 unsigned long flags;
38479
38480 spin_lock_irqsave(&tty_ldisc_lock, flags);
38481- ldops->refcount--;
38482+ atomic_dec(&ldops->refcount);
38483 module_put(ldops->owner);
38484 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38485 }
38486diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
38487index bf6e238..d401c04 100644
38488--- a/drivers/tty/tty_port.c
38489+++ b/drivers/tty/tty_port.c
38490@@ -138,7 +138,7 @@ void tty_port_hangup(struct tty_port *port)
38491 unsigned long flags;
38492
38493 spin_lock_irqsave(&port->lock, flags);
38494- port->count = 0;
38495+ atomic_set(&port->count, 0);
38496 port->flags &= ~ASYNC_NORMAL_ACTIVE;
38497 if (port->tty) {
38498 set_bit(TTY_IO_ERROR, &port->tty->flags);
38499@@ -264,7 +264,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38500 /* The port lock protects the port counts */
38501 spin_lock_irqsave(&port->lock, flags);
38502 if (!tty_hung_up_p(filp))
38503- port->count--;
38504+ atomic_dec(&port->count);
38505 port->blocked_open++;
38506 spin_unlock_irqrestore(&port->lock, flags);
38507
38508@@ -306,7 +306,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38509 we must not mess that up further */
38510 spin_lock_irqsave(&port->lock, flags);
38511 if (!tty_hung_up_p(filp))
38512- port->count++;
38513+ atomic_inc(&port->count);
38514 port->blocked_open--;
38515 if (retval == 0)
38516 port->flags |= ASYNC_NORMAL_ACTIVE;
38517@@ -326,19 +326,19 @@ int tty_port_close_start(struct tty_port *port,
38518 return 0;
38519 }
38520
38521- if (tty->count == 1 && port->count != 1) {
38522+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
38523 printk(KERN_WARNING
38524 "tty_port_close_start: tty->count = 1 port count = %d.\n",
38525- port->count);
38526- port->count = 1;
38527+ atomic_read(&port->count));
38528+ atomic_set(&port->count, 1);
38529 }
38530- if (--port->count < 0) {
38531+ if (atomic_dec_return(&port->count) < 0) {
38532 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
38533- port->count);
38534- port->count = 0;
38535+ atomic_read(&port->count));
38536+ atomic_set(&port->count, 0);
38537 }
38538
38539- if (port->count) {
38540+ if (atomic_read(&port->count)) {
38541 spin_unlock_irqrestore(&port->lock, flags);
38542 if (port->ops->drop)
38543 port->ops->drop(port);
38544@@ -418,7 +418,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
38545 {
38546 spin_lock_irq(&port->lock);
38547 if (!tty_hung_up_p(filp))
38548- ++port->count;
38549+ atomic_inc(&port->count);
38550 spin_unlock_irq(&port->lock);
38551 tty_port_tty_set(port, tty);
38552
38553diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
38554index 48cc6f2..85584dd 100644
38555--- a/drivers/tty/vt/keyboard.c
38556+++ b/drivers/tty/vt/keyboard.c
38557@@ -659,6 +659,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
38558 kbd->kbdmode == VC_OFF) &&
38559 value != KVAL(K_SAK))
38560 return; /* SAK is allowed even in raw mode */
38561+
38562+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
38563+ {
38564+ void *func = fn_handler[value];
38565+ if (func == fn_show_state || func == fn_show_ptregs ||
38566+ func == fn_show_mem)
38567+ return;
38568+ }
38569+#endif
38570+
38571 fn_handler[value](vc);
38572 }
38573
38574@@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38575 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
38576 return -EFAULT;
38577
38578- if (!capable(CAP_SYS_TTY_CONFIG))
38579- perm = 0;
38580-
38581 switch (cmd) {
38582 case KDGKBENT:
38583 /* Ensure another thread doesn't free it under us */
38584@@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38585 spin_unlock_irqrestore(&kbd_event_lock, flags);
38586 return put_user(val, &user_kbe->kb_value);
38587 case KDSKBENT:
38588+ if (!capable(CAP_SYS_TTY_CONFIG))
38589+ perm = 0;
38590+
38591 if (!perm)
38592 return -EPERM;
38593 if (!i && v == K_NOSUCHMAP) {
38594@@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38595 int i, j, k;
38596 int ret;
38597
38598- if (!capable(CAP_SYS_TTY_CONFIG))
38599- perm = 0;
38600-
38601 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
38602 if (!kbs) {
38603 ret = -ENOMEM;
38604@@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38605 kfree(kbs);
38606 return ((p && *p) ? -EOVERFLOW : 0);
38607 case KDSKBSENT:
38608+ if (!capable(CAP_SYS_TTY_CONFIG))
38609+ perm = 0;
38610+
38611 if (!perm) {
38612 ret = -EPERM;
38613 goto reterr;
38614diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
38615index a783d53..cb30d94 100644
38616--- a/drivers/uio/uio.c
38617+++ b/drivers/uio/uio.c
38618@@ -25,6 +25,7 @@
38619 #include <linux/kobject.h>
38620 #include <linux/cdev.h>
38621 #include <linux/uio_driver.h>
38622+#include <asm/local.h>
38623
38624 #define UIO_MAX_DEVICES (1U << MINORBITS)
38625
38626@@ -32,10 +33,10 @@ struct uio_device {
38627 struct module *owner;
38628 struct device *dev;
38629 int minor;
38630- atomic_t event;
38631+ atomic_unchecked_t event;
38632 struct fasync_struct *async_queue;
38633 wait_queue_head_t wait;
38634- int vma_count;
38635+ local_t vma_count;
38636 struct uio_info *info;
38637 struct kobject *map_dir;
38638 struct kobject *portio_dir;
38639@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
38640 struct device_attribute *attr, char *buf)
38641 {
38642 struct uio_device *idev = dev_get_drvdata(dev);
38643- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
38644+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
38645 }
38646
38647 static struct device_attribute uio_class_attributes[] = {
38648@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
38649 {
38650 struct uio_device *idev = info->uio_dev;
38651
38652- atomic_inc(&idev->event);
38653+ atomic_inc_unchecked(&idev->event);
38654 wake_up_interruptible(&idev->wait);
38655 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
38656 }
38657@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
38658 }
38659
38660 listener->dev = idev;
38661- listener->event_count = atomic_read(&idev->event);
38662+ listener->event_count = atomic_read_unchecked(&idev->event);
38663 filep->private_data = listener;
38664
38665 if (idev->info->open) {
38666@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
38667 return -EIO;
38668
38669 poll_wait(filep, &idev->wait, wait);
38670- if (listener->event_count != atomic_read(&idev->event))
38671+ if (listener->event_count != atomic_read_unchecked(&idev->event))
38672 return POLLIN | POLLRDNORM;
38673 return 0;
38674 }
38675@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
38676 do {
38677 set_current_state(TASK_INTERRUPTIBLE);
38678
38679- event_count = atomic_read(&idev->event);
38680+ event_count = atomic_read_unchecked(&idev->event);
38681 if (event_count != listener->event_count) {
38682 if (copy_to_user(buf, &event_count, count))
38683 retval = -EFAULT;
38684@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
38685 static void uio_vma_open(struct vm_area_struct *vma)
38686 {
38687 struct uio_device *idev = vma->vm_private_data;
38688- idev->vma_count++;
38689+ local_inc(&idev->vma_count);
38690 }
38691
38692 static void uio_vma_close(struct vm_area_struct *vma)
38693 {
38694 struct uio_device *idev = vma->vm_private_data;
38695- idev->vma_count--;
38696+ local_dec(&idev->vma_count);
38697 }
38698
38699 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38700@@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
38701 idev->owner = owner;
38702 idev->info = info;
38703 init_waitqueue_head(&idev->wait);
38704- atomic_set(&idev->event, 0);
38705+ atomic_set_unchecked(&idev->event, 0);
38706
38707 ret = uio_get_minor(idev);
38708 if (ret)
38709diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
38710index b7eb86a..36d28af 100644
38711--- a/drivers/usb/atm/cxacru.c
38712+++ b/drivers/usb/atm/cxacru.c
38713@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
38714 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
38715 if (ret < 2)
38716 return -EINVAL;
38717- if (index < 0 || index > 0x7f)
38718+ if (index > 0x7f)
38719 return -EINVAL;
38720 pos += tmp;
38721
38722diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
38723index ee62b35..b663594 100644
38724--- a/drivers/usb/atm/usbatm.c
38725+++ b/drivers/usb/atm/usbatm.c
38726@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38727 if (printk_ratelimit())
38728 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
38729 __func__, vpi, vci);
38730- atomic_inc(&vcc->stats->rx_err);
38731+ atomic_inc_unchecked(&vcc->stats->rx_err);
38732 return;
38733 }
38734
38735@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38736 if (length > ATM_MAX_AAL5_PDU) {
38737 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
38738 __func__, length, vcc);
38739- atomic_inc(&vcc->stats->rx_err);
38740+ atomic_inc_unchecked(&vcc->stats->rx_err);
38741 goto out;
38742 }
38743
38744@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38745 if (sarb->len < pdu_length) {
38746 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
38747 __func__, pdu_length, sarb->len, vcc);
38748- atomic_inc(&vcc->stats->rx_err);
38749+ atomic_inc_unchecked(&vcc->stats->rx_err);
38750 goto out;
38751 }
38752
38753 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
38754 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
38755 __func__, vcc);
38756- atomic_inc(&vcc->stats->rx_err);
38757+ atomic_inc_unchecked(&vcc->stats->rx_err);
38758 goto out;
38759 }
38760
38761@@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38762 if (printk_ratelimit())
38763 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
38764 __func__, length);
38765- atomic_inc(&vcc->stats->rx_drop);
38766+ atomic_inc_unchecked(&vcc->stats->rx_drop);
38767 goto out;
38768 }
38769
38770@@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38771
38772 vcc->push(vcc, skb);
38773
38774- atomic_inc(&vcc->stats->rx);
38775+ atomic_inc_unchecked(&vcc->stats->rx);
38776 out:
38777 skb_trim(sarb, 0);
38778 }
38779@@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
38780 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
38781
38782 usbatm_pop(vcc, skb);
38783- atomic_inc(&vcc->stats->tx);
38784+ atomic_inc_unchecked(&vcc->stats->tx);
38785
38786 skb = skb_dequeue(&instance->sndqueue);
38787 }
38788@@ -770,11 +770,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
38789 if (!left--)
38790 return sprintf(page,
38791 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
38792- atomic_read(&atm_dev->stats.aal5.tx),
38793- atomic_read(&atm_dev->stats.aal5.tx_err),
38794- atomic_read(&atm_dev->stats.aal5.rx),
38795- atomic_read(&atm_dev->stats.aal5.rx_err),
38796- atomic_read(&atm_dev->stats.aal5.rx_drop));
38797+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
38798+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
38799+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
38800+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
38801+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
38802
38803 if (!left--) {
38804 if (instance->disconnected)
38805diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
38806index d956965..4179a77 100644
38807--- a/drivers/usb/core/devices.c
38808+++ b/drivers/usb/core/devices.c
38809@@ -126,7 +126,7 @@ static const char format_endpt[] =
38810 * time it gets called.
38811 */
38812 static struct device_connect_event {
38813- atomic_t count;
38814+ atomic_unchecked_t count;
38815 wait_queue_head_t wait;
38816 } device_event = {
38817 .count = ATOMIC_INIT(1),
38818@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
38819
38820 void usbfs_conn_disc_event(void)
38821 {
38822- atomic_add(2, &device_event.count);
38823+ atomic_add_unchecked(2, &device_event.count);
38824 wake_up(&device_event.wait);
38825 }
38826
38827@@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
38828
38829 poll_wait(file, &device_event.wait, wait);
38830
38831- event_count = atomic_read(&device_event.count);
38832+ event_count = atomic_read_unchecked(&device_event.count);
38833 if (file->f_version != event_count) {
38834 file->f_version = event_count;
38835 return POLLIN | POLLRDNORM;
38836diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
38837index 347bb05..63e1b73 100644
38838--- a/drivers/usb/early/ehci-dbgp.c
38839+++ b/drivers/usb/early/ehci-dbgp.c
38840@@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
38841
38842 #ifdef CONFIG_KGDB
38843 static struct kgdb_io kgdbdbgp_io_ops;
38844-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
38845+static struct kgdb_io kgdbdbgp_io_ops_console;
38846+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
38847 #else
38848 #define dbgp_kgdb_mode (0)
38849 #endif
38850@@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
38851 .write_char = kgdbdbgp_write_char,
38852 };
38853
38854+static struct kgdb_io kgdbdbgp_io_ops_console = {
38855+ .name = "kgdbdbgp",
38856+ .read_char = kgdbdbgp_read_char,
38857+ .write_char = kgdbdbgp_write_char,
38858+ .is_console = 1
38859+};
38860+
38861 static int kgdbdbgp_wait_time;
38862
38863 static int __init kgdbdbgp_parse_config(char *str)
38864@@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
38865 ptr++;
38866 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
38867 }
38868- kgdb_register_io_module(&kgdbdbgp_io_ops);
38869- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
38870+ if (early_dbgp_console.index != -1)
38871+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
38872+ else
38873+ kgdb_register_io_module(&kgdbdbgp_io_ops);
38874
38875 return 0;
38876 }
38877diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
38878index 5b3f5ff..6e00893 100644
38879--- a/drivers/usb/gadget/u_serial.c
38880+++ b/drivers/usb/gadget/u_serial.c
38881@@ -731,9 +731,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
38882 spin_lock_irq(&port->port_lock);
38883
38884 /* already open? Great. */
38885- if (port->port.count) {
38886+ if (atomic_read(&port->port.count)) {
38887 status = 0;
38888- port->port.count++;
38889+ atomic_inc(&port->port.count);
38890
38891 /* currently opening/closing? wait ... */
38892 } else if (port->openclose) {
38893@@ -792,7 +792,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
38894 tty->driver_data = port;
38895 port->port.tty = tty;
38896
38897- port->port.count = 1;
38898+ atomic_set(&port->port.count, 1);
38899 port->openclose = false;
38900
38901 /* if connected, start the I/O stream */
38902@@ -834,11 +834,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
38903
38904 spin_lock_irq(&port->port_lock);
38905
38906- if (port->port.count != 1) {
38907- if (port->port.count == 0)
38908+ if (atomic_read(&port->port.count) != 1) {
38909+ if (atomic_read(&port->port.count) == 0)
38910 WARN_ON(1);
38911 else
38912- --port->port.count;
38913+ atomic_dec(&port->port.count);
38914 goto exit;
38915 }
38916
38917@@ -848,7 +848,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
38918 * and sleep if necessary
38919 */
38920 port->openclose = true;
38921- port->port.count = 0;
38922+ atomic_set(&port->port.count, 0);
38923
38924 gser = port->port_usb;
38925 if (gser && gser->disconnect)
38926@@ -1152,7 +1152,7 @@ static int gs_closed(struct gs_port *port)
38927 int cond;
38928
38929 spin_lock_irq(&port->port_lock);
38930- cond = (port->port.count == 0) && !port->openclose;
38931+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
38932 spin_unlock_irq(&port->port_lock);
38933 return cond;
38934 }
38935@@ -1265,7 +1265,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
38936 /* if it's already open, start I/O ... and notify the serial
38937 * protocol about open/close status (connect/disconnect).
38938 */
38939- if (port->port.count) {
38940+ if (atomic_read(&port->port.count)) {
38941 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
38942 gs_start_io(port);
38943 if (gser->connect)
38944@@ -1312,7 +1312,7 @@ void gserial_disconnect(struct gserial *gser)
38945
38946 port->port_usb = NULL;
38947 gser->ioport = NULL;
38948- if (port->port.count > 0 || port->openclose) {
38949+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
38950 wake_up_interruptible(&port->drain_wait);
38951 if (port->port.tty)
38952 tty_hangup(port->port.tty);
38953@@ -1328,7 +1328,7 @@ void gserial_disconnect(struct gserial *gser)
38954
38955 /* finally, free any unused/unusable I/O buffers */
38956 spin_lock_irqsave(&port->port_lock, flags);
38957- if (port->port.count == 0 && !port->openclose)
38958+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
38959 gs_buf_free(&port->port_write_buf);
38960 gs_free_requests(gser->out, &port->read_pool, NULL);
38961 gs_free_requests(gser->out, &port->read_queue, NULL);
38962diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
38963index b9cca6d..75c75df 100644
38964--- a/drivers/usb/serial/console.c
38965+++ b/drivers/usb/serial/console.c
38966@@ -127,7 +127,7 @@ static int usb_console_setup(struct console *co, char *options)
38967
38968 info->port = port;
38969
38970- ++port->port.count;
38971+ atomic_inc(&port->port.count);
38972 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
38973 if (serial->type->set_termios) {
38974 /*
38975@@ -177,7 +177,7 @@ static int usb_console_setup(struct console *co, char *options)
38976 }
38977 /* Now that any required fake tty operations are completed restore
38978 * the tty port count */
38979- --port->port.count;
38980+ atomic_dec(&port->port.count);
38981 /* The console is special in terms of closing the device so
38982 * indicate this port is now acting as a system console. */
38983 port->port.console = 1;
38984@@ -190,7 +190,7 @@ static int usb_console_setup(struct console *co, char *options)
38985 free_tty:
38986 kfree(tty);
38987 reset_open_count:
38988- port->port.count = 0;
38989+ atomic_set(&port->port.count, 0);
38990 usb_autopm_put_interface(serial->interface);
38991 error_get_interface:
38992 usb_serial_put(serial);
38993diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
38994index d6bea3e..60b250e 100644
38995--- a/drivers/usb/wusbcore/wa-hc.h
38996+++ b/drivers/usb/wusbcore/wa-hc.h
38997@@ -192,7 +192,7 @@ struct wahc {
38998 struct list_head xfer_delayed_list;
38999 spinlock_t xfer_list_lock;
39000 struct work_struct xfer_work;
39001- atomic_t xfer_id_count;
39002+ atomic_unchecked_t xfer_id_count;
39003 };
39004
39005
39006@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
39007 INIT_LIST_HEAD(&wa->xfer_delayed_list);
39008 spin_lock_init(&wa->xfer_list_lock);
39009 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
39010- atomic_set(&wa->xfer_id_count, 1);
39011+ atomic_set_unchecked(&wa->xfer_id_count, 1);
39012 }
39013
39014 /**
39015diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
39016index 57c01ab..8a05959 100644
39017--- a/drivers/usb/wusbcore/wa-xfer.c
39018+++ b/drivers/usb/wusbcore/wa-xfer.c
39019@@ -296,7 +296,7 @@ out:
39020 */
39021 static void wa_xfer_id_init(struct wa_xfer *xfer)
39022 {
39023- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
39024+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
39025 }
39026
39027 /*
39028diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
39029index 112156f..eb81154 100644
39030--- a/drivers/vhost/vhost.c
39031+++ b/drivers/vhost/vhost.c
39032@@ -635,7 +635,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
39033 return 0;
39034 }
39035
39036-static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
39037+static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
39038 {
39039 struct file *eventfp, *filep = NULL,
39040 *pollstart = NULL, *pollstop = NULL;
39041diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
39042index b0b2ac3..89a4399 100644
39043--- a/drivers/video/aty/aty128fb.c
39044+++ b/drivers/video/aty/aty128fb.c
39045@@ -148,7 +148,7 @@ enum {
39046 };
39047
39048 /* Must match above enum */
39049-static const char *r128_family[] __devinitdata = {
39050+static const char *r128_family[] __devinitconst = {
39051 "AGP",
39052 "PCI",
39053 "PRO AGP",
39054diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
39055index 5c3960d..15cf8fc 100644
39056--- a/drivers/video/fbcmap.c
39057+++ b/drivers/video/fbcmap.c
39058@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
39059 rc = -ENODEV;
39060 goto out;
39061 }
39062- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
39063- !info->fbops->fb_setcmap)) {
39064+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
39065 rc = -EINVAL;
39066 goto out1;
39067 }
39068diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
39069index 0dff12a..2ef47b3 100644
39070--- a/drivers/video/fbmem.c
39071+++ b/drivers/video/fbmem.c
39072@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39073 image->dx += image->width + 8;
39074 }
39075 } else if (rotate == FB_ROTATE_UD) {
39076- for (x = 0; x < num && image->dx >= 0; x++) {
39077+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
39078 info->fbops->fb_imageblit(info, image);
39079 image->dx -= image->width + 8;
39080 }
39081@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39082 image->dy += image->height + 8;
39083 }
39084 } else if (rotate == FB_ROTATE_CCW) {
39085- for (x = 0; x < num && image->dy >= 0; x++) {
39086+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39087 info->fbops->fb_imageblit(info, image);
39088 image->dy -= image->height + 8;
39089 }
39090@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
39091 return -EFAULT;
39092 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39093 return -EINVAL;
39094- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39095+ if (con2fb.framebuffer >= FB_MAX)
39096 return -EINVAL;
39097 if (!registered_fb[con2fb.framebuffer])
39098 request_module("fb%d", con2fb.framebuffer);
39099diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
39100index 5a5d092..265c5ed 100644
39101--- a/drivers/video/geode/gx1fb_core.c
39102+++ b/drivers/video/geode/gx1fb_core.c
39103@@ -29,7 +29,7 @@ static int crt_option = 1;
39104 static char panel_option[32] = "";
39105
39106 /* Modes relevant to the GX1 (taken from modedb.c) */
39107-static const struct fb_videomode __devinitdata gx1_modedb[] = {
39108+static const struct fb_videomode __devinitconst gx1_modedb[] = {
39109 /* 640x480-60 VESA */
39110 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
39111 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
39112diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
39113index 0fad23f..0e9afa4 100644
39114--- a/drivers/video/gxt4500.c
39115+++ b/drivers/video/gxt4500.c
39116@@ -156,7 +156,7 @@ struct gxt4500_par {
39117 static char *mode_option;
39118
39119 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
39120-static const struct fb_videomode defaultmode __devinitdata = {
39121+static const struct fb_videomode defaultmode __devinitconst = {
39122 .refresh = 60,
39123 .xres = 1280,
39124 .yres = 1024,
39125@@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
39126 return 0;
39127 }
39128
39129-static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
39130+static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
39131 .id = "IBM GXT4500P",
39132 .type = FB_TYPE_PACKED_PIXELS,
39133 .visual = FB_VISUAL_PSEUDOCOLOR,
39134diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39135index 7672d2e..b56437f 100644
39136--- a/drivers/video/i810/i810_accel.c
39137+++ b/drivers/video/i810/i810_accel.c
39138@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39139 }
39140 }
39141 printk("ringbuffer lockup!!!\n");
39142+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39143 i810_report_error(mmio);
39144 par->dev_flags |= LOCKUP;
39145 info->pixmap.scan_align = 1;
39146diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
39147index b83f361..2b05a91 100644
39148--- a/drivers/video/i810/i810_main.c
39149+++ b/drivers/video/i810/i810_main.c
39150@@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
39151 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
39152
39153 /* PCI */
39154-static const char *i810_pci_list[] __devinitdata = {
39155+static const char *i810_pci_list[] __devinitconst = {
39156 "Intel(R) 810 Framebuffer Device" ,
39157 "Intel(R) 810-DC100 Framebuffer Device" ,
39158 "Intel(R) 810E Framebuffer Device" ,
39159diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
39160index de36693..3c63fc2 100644
39161--- a/drivers/video/jz4740_fb.c
39162+++ b/drivers/video/jz4740_fb.c
39163@@ -136,7 +136,7 @@ struct jzfb {
39164 uint32_t pseudo_palette[16];
39165 };
39166
39167-static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
39168+static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
39169 .id = "JZ4740 FB",
39170 .type = FB_TYPE_PACKED_PIXELS,
39171 .visual = FB_VISUAL_TRUECOLOR,
39172diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39173index 3c14e43..eafa544 100644
39174--- a/drivers/video/logo/logo_linux_clut224.ppm
39175+++ b/drivers/video/logo/logo_linux_clut224.ppm
39176@@ -1,1604 +1,1123 @@
39177 P3
39178-# Standard 224-color Linux logo
39179 80 80
39180 255
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- 6 6 6 6 6 6 10 10 10 10 10 10
39191- 10 10 10 6 6 6 6 6 6 6 6 6
39192- 0 0 0 0 0 0 0 0 0 0 0 0
39193- 0 0 0 0 0 0 0 0 0 0 0 0
39194- 0 0 0 0 0 0 0 0 0 0 0 0
39195- 0 0 0 0 0 0 0 0 0 0 0 0
39196- 0 0 0 0 0 0 0 0 0 0 0 0
39197- 0 0 0 0 0 0 0 0 0 0 0 0
39198- 0 0 0 0 0 0 0 0 0 0 0 0
39199- 0 0 0 0 0 0 0 0 0 0 0 0
39200- 0 0 0 0 0 0 0 0 0 0 0 0
39201- 0 0 0 0 0 0 0 0 0 0 0 0
39202- 0 0 0 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 6 6 6 10 10 10 14 14 14
39210- 22 22 22 26 26 26 30 30 30 34 34 34
39211- 30 30 30 30 30 30 26 26 26 18 18 18
39212- 14 14 14 10 10 10 6 6 6 0 0 0
39213- 0 0 0 0 0 0 0 0 0 0 0 0
39214- 0 0 0 0 0 0 0 0 0 0 0 0
39215- 0 0 0 0 0 0 0 0 0 0 0 0
39216- 0 0 0 0 0 0 0 0 0 0 0 0
39217- 0 0 0 0 0 0 0 0 0 0 0 0
39218- 0 0 0 0 0 0 0 0 0 0 0 0
39219- 0 0 0 0 0 0 0 0 0 0 0 0
39220- 0 0 0 0 0 0 0 0 0 0 0 0
39221- 0 0 0 0 0 0 0 0 0 0 0 0
39222- 0 0 0 0 0 1 0 0 1 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- 6 6 6 14 14 14 26 26 26 42 42 42
39230- 54 54 54 66 66 66 78 78 78 78 78 78
39231- 78 78 78 74 74 74 66 66 66 54 54 54
39232- 42 42 42 26 26 26 18 18 18 10 10 10
39233- 6 6 6 0 0 0 0 0 0 0 0 0
39234- 0 0 0 0 0 0 0 0 0 0 0 0
39235- 0 0 0 0 0 0 0 0 0 0 0 0
39236- 0 0 0 0 0 0 0 0 0 0 0 0
39237- 0 0 0 0 0 0 0 0 0 0 0 0
39238- 0 0 0 0 0 0 0 0 0 0 0 0
39239- 0 0 0 0 0 0 0 0 0 0 0 0
39240- 0 0 0 0 0 0 0 0 0 0 0 0
39241- 0 0 0 0 0 0 0 0 0 0 0 0
39242- 0 0 1 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 10 10 10
39249- 22 22 22 42 42 42 66 66 66 86 86 86
39250- 66 66 66 38 38 38 38 38 38 22 22 22
39251- 26 26 26 34 34 34 54 54 54 66 66 66
39252- 86 86 86 70 70 70 46 46 46 26 26 26
39253- 14 14 14 6 6 6 0 0 0 0 0 0
39254- 0 0 0 0 0 0 0 0 0 0 0 0
39255- 0 0 0 0 0 0 0 0 0 0 0 0
39256- 0 0 0 0 0 0 0 0 0 0 0 0
39257- 0 0 0 0 0 0 0 0 0 0 0 0
39258- 0 0 0 0 0 0 0 0 0 0 0 0
39259- 0 0 0 0 0 0 0 0 0 0 0 0
39260- 0 0 0 0 0 0 0 0 0 0 0 0
39261- 0 0 0 0 0 0 0 0 0 0 0 0
39262- 0 0 1 0 0 1 0 0 1 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 10 10 10 26 26 26
39269- 50 50 50 82 82 82 58 58 58 6 6 6
39270- 2 2 6 2 2 6 2 2 6 2 2 6
39271- 2 2 6 2 2 6 2 2 6 2 2 6
39272- 6 6 6 54 54 54 86 86 86 66 66 66
39273- 38 38 38 18 18 18 6 6 6 0 0 0
39274- 0 0 0 0 0 0 0 0 0 0 0 0
39275- 0 0 0 0 0 0 0 0 0 0 0 0
39276- 0 0 0 0 0 0 0 0 0 0 0 0
39277- 0 0 0 0 0 0 0 0 0 0 0 0
39278- 0 0 0 0 0 0 0 0 0 0 0 0
39279- 0 0 0 0 0 0 0 0 0 0 0 0
39280- 0 0 0 0 0 0 0 0 0 0 0 0
39281- 0 0 0 0 0 0 0 0 0 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 6 6 6 22 22 22 50 50 50
39289- 78 78 78 34 34 34 2 2 6 2 2 6
39290- 2 2 6 2 2 6 2 2 6 2 2 6
39291- 2 2 6 2 2 6 2 2 6 2 2 6
39292- 2 2 6 2 2 6 6 6 6 70 70 70
39293- 78 78 78 46 46 46 22 22 22 6 6 6
39294- 0 0 0 0 0 0 0 0 0 0 0 0
39295- 0 0 0 0 0 0 0 0 0 0 0 0
39296- 0 0 0 0 0 0 0 0 0 0 0 0
39297- 0 0 0 0 0 0 0 0 0 0 0 0
39298- 0 0 0 0 0 0 0 0 0 0 0 0
39299- 0 0 0 0 0 0 0 0 0 0 0 0
39300- 0 0 0 0 0 0 0 0 0 0 0 0
39301- 0 0 0 0 0 0 0 0 0 0 0 0
39302- 0 0 1 0 0 1 0 0 1 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- 6 6 6 18 18 18 42 42 42 82 82 82
39309- 26 26 26 2 2 6 2 2 6 2 2 6
39310- 2 2 6 2 2 6 2 2 6 2 2 6
39311- 2 2 6 2 2 6 2 2 6 14 14 14
39312- 46 46 46 34 34 34 6 6 6 2 2 6
39313- 42 42 42 78 78 78 42 42 42 18 18 18
39314- 6 6 6 0 0 0 0 0 0 0 0 0
39315- 0 0 0 0 0 0 0 0 0 0 0 0
39316- 0 0 0 0 0 0 0 0 0 0 0 0
39317- 0 0 0 0 0 0 0 0 0 0 0 0
39318- 0 0 0 0 0 0 0 0 0 0 0 0
39319- 0 0 0 0 0 0 0 0 0 0 0 0
39320- 0 0 0 0 0 0 0 0 0 0 0 0
39321- 0 0 0 0 0 0 0 0 0 0 0 0
39322- 0 0 1 0 0 0 0 0 1 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- 10 10 10 30 30 30 66 66 66 58 58 58
39329- 2 2 6 2 2 6 2 2 6 2 2 6
39330- 2 2 6 2 2 6 2 2 6 2 2 6
39331- 2 2 6 2 2 6 2 2 6 26 26 26
39332- 86 86 86 101 101 101 46 46 46 10 10 10
39333- 2 2 6 58 58 58 70 70 70 34 34 34
39334- 10 10 10 0 0 0 0 0 0 0 0 0
39335- 0 0 0 0 0 0 0 0 0 0 0 0
39336- 0 0 0 0 0 0 0 0 0 0 0 0
39337- 0 0 0 0 0 0 0 0 0 0 0 0
39338- 0 0 0 0 0 0 0 0 0 0 0 0
39339- 0 0 0 0 0 0 0 0 0 0 0 0
39340- 0 0 0 0 0 0 0 0 0 0 0 0
39341- 0 0 0 0 0 0 0 0 0 0 0 0
39342- 0 0 1 0 0 1 0 0 1 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- 14 14 14 42 42 42 86 86 86 10 10 10
39349- 2 2 6 2 2 6 2 2 6 2 2 6
39350- 2 2 6 2 2 6 2 2 6 2 2 6
39351- 2 2 6 2 2 6 2 2 6 30 30 30
39352- 94 94 94 94 94 94 58 58 58 26 26 26
39353- 2 2 6 6 6 6 78 78 78 54 54 54
39354- 22 22 22 6 6 6 0 0 0 0 0 0
39355- 0 0 0 0 0 0 0 0 0 0 0 0
39356- 0 0 0 0 0 0 0 0 0 0 0 0
39357- 0 0 0 0 0 0 0 0 0 0 0 0
39358- 0 0 0 0 0 0 0 0 0 0 0 0
39359- 0 0 0 0 0 0 0 0 0 0 0 0
39360- 0 0 0 0 0 0 0 0 0 0 0 0
39361- 0 0 0 0 0 0 0 0 0 0 0 0
39362- 0 0 0 0 0 0 0 0 0 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 6 6 6
39368- 22 22 22 62 62 62 62 62 62 2 2 6
39369- 2 2 6 2 2 6 2 2 6 2 2 6
39370- 2 2 6 2 2 6 2 2 6 2 2 6
39371- 2 2 6 2 2 6 2 2 6 26 26 26
39372- 54 54 54 38 38 38 18 18 18 10 10 10
39373- 2 2 6 2 2 6 34 34 34 82 82 82
39374- 38 38 38 14 14 14 0 0 0 0 0 0
39375- 0 0 0 0 0 0 0 0 0 0 0 0
39376- 0 0 0 0 0 0 0 0 0 0 0 0
39377- 0 0 0 0 0 0 0 0 0 0 0 0
39378- 0 0 0 0 0 0 0 0 0 0 0 0
39379- 0 0 0 0 0 0 0 0 0 0 0 0
39380- 0 0 0 0 0 0 0 0 0 0 0 0
39381- 0 0 0 0 0 0 0 0 0 0 0 0
39382- 0 0 0 0 0 1 0 0 1 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 6 6 6
39388- 30 30 30 78 78 78 30 30 30 2 2 6
39389- 2 2 6 2 2 6 2 2 6 2 2 6
39390- 2 2 6 2 2 6 2 2 6 2 2 6
39391- 2 2 6 2 2 6 2 2 6 10 10 10
39392- 10 10 10 2 2 6 2 2 6 2 2 6
39393- 2 2 6 2 2 6 2 2 6 78 78 78
39394- 50 50 50 18 18 18 6 6 6 0 0 0
39395- 0 0 0 0 0 0 0 0 0 0 0 0
39396- 0 0 0 0 0 0 0 0 0 0 0 0
39397- 0 0 0 0 0 0 0 0 0 0 0 0
39398- 0 0 0 0 0 0 0 0 0 0 0 0
39399- 0 0 0 0 0 0 0 0 0 0 0 0
39400- 0 0 0 0 0 0 0 0 0 0 0 0
39401- 0 0 0 0 0 0 0 0 0 0 0 0
39402- 0 0 1 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 10 10 10
39408- 38 38 38 86 86 86 14 14 14 2 2 6
39409- 2 2 6 2 2 6 2 2 6 2 2 6
39410- 2 2 6 2 2 6 2 2 6 2 2 6
39411- 2 2 6 2 2 6 2 2 6 2 2 6
39412- 2 2 6 2 2 6 2 2 6 2 2 6
39413- 2 2 6 2 2 6 2 2 6 54 54 54
39414- 66 66 66 26 26 26 6 6 6 0 0 0
39415- 0 0 0 0 0 0 0 0 0 0 0 0
39416- 0 0 0 0 0 0 0 0 0 0 0 0
39417- 0 0 0 0 0 0 0 0 0 0 0 0
39418- 0 0 0 0 0 0 0 0 0 0 0 0
39419- 0 0 0 0 0 0 0 0 0 0 0 0
39420- 0 0 0 0 0 0 0 0 0 0 0 0
39421- 0 0 0 0 0 0 0 0 0 0 0 0
39422- 0 0 0 0 0 1 0 0 1 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 14 14 14
39428- 42 42 42 82 82 82 2 2 6 2 2 6
39429- 2 2 6 6 6 6 10 10 10 2 2 6
39430- 2 2 6 2 2 6 2 2 6 2 2 6
39431- 2 2 6 2 2 6 2 2 6 6 6 6
39432- 14 14 14 10 10 10 2 2 6 2 2 6
39433- 2 2 6 2 2 6 2 2 6 18 18 18
39434- 82 82 82 34 34 34 10 10 10 0 0 0
39435- 0 0 0 0 0 0 0 0 0 0 0 0
39436- 0 0 0 0 0 0 0 0 0 0 0 0
39437- 0 0 0 0 0 0 0 0 0 0 0 0
39438- 0 0 0 0 0 0 0 0 0 0 0 0
39439- 0 0 0 0 0 0 0 0 0 0 0 0
39440- 0 0 0 0 0 0 0 0 0 0 0 0
39441- 0 0 0 0 0 0 0 0 0 0 0 0
39442- 0 0 1 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 14 14 14
39448- 46 46 46 86 86 86 2 2 6 2 2 6
39449- 6 6 6 6 6 6 22 22 22 34 34 34
39450- 6 6 6 2 2 6 2 2 6 2 2 6
39451- 2 2 6 2 2 6 18 18 18 34 34 34
39452- 10 10 10 50 50 50 22 22 22 2 2 6
39453- 2 2 6 2 2 6 2 2 6 10 10 10
39454- 86 86 86 42 42 42 14 14 14 0 0 0
39455- 0 0 0 0 0 0 0 0 0 0 0 0
39456- 0 0 0 0 0 0 0 0 0 0 0 0
39457- 0 0 0 0 0 0 0 0 0 0 0 0
39458- 0 0 0 0 0 0 0 0 0 0 0 0
39459- 0 0 0 0 0 0 0 0 0 0 0 0
39460- 0 0 0 0 0 0 0 0 0 0 0 0
39461- 0 0 0 0 0 0 0 0 0 0 0 0
39462- 0 0 1 0 0 1 0 0 1 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 14 14 14
39468- 46 46 46 86 86 86 2 2 6 2 2 6
39469- 38 38 38 116 116 116 94 94 94 22 22 22
39470- 22 22 22 2 2 6 2 2 6 2 2 6
39471- 14 14 14 86 86 86 138 138 138 162 162 162
39472-154 154 154 38 38 38 26 26 26 6 6 6
39473- 2 2 6 2 2 6 2 2 6 2 2 6
39474- 86 86 86 46 46 46 14 14 14 0 0 0
39475- 0 0 0 0 0 0 0 0 0 0 0 0
39476- 0 0 0 0 0 0 0 0 0 0 0 0
39477- 0 0 0 0 0 0 0 0 0 0 0 0
39478- 0 0 0 0 0 0 0 0 0 0 0 0
39479- 0 0 0 0 0 0 0 0 0 0 0 0
39480- 0 0 0 0 0 0 0 0 0 0 0 0
39481- 0 0 0 0 0 0 0 0 0 0 0 0
39482- 0 0 0 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 14 14 14
39488- 46 46 46 86 86 86 2 2 6 14 14 14
39489-134 134 134 198 198 198 195 195 195 116 116 116
39490- 10 10 10 2 2 6 2 2 6 6 6 6
39491-101 98 89 187 187 187 210 210 210 218 218 218
39492-214 214 214 134 134 134 14 14 14 6 6 6
39493- 2 2 6 2 2 6 2 2 6 2 2 6
39494- 86 86 86 50 50 50 18 18 18 6 6 6
39495- 0 0 0 0 0 0 0 0 0 0 0 0
39496- 0 0 0 0 0 0 0 0 0 0 0 0
39497- 0 0 0 0 0 0 0 0 0 0 0 0
39498- 0 0 0 0 0 0 0 0 0 0 0 0
39499- 0 0 0 0 0 0 0 0 0 0 0 0
39500- 0 0 0 0 0 0 0 0 0 0 0 0
39501- 0 0 0 0 0 0 0 0 1 0 0 0
39502- 0 0 1 0 0 1 0 0 1 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 14 14 14
39508- 46 46 46 86 86 86 2 2 6 54 54 54
39509-218 218 218 195 195 195 226 226 226 246 246 246
39510- 58 58 58 2 2 6 2 2 6 30 30 30
39511-210 210 210 253 253 253 174 174 174 123 123 123
39512-221 221 221 234 234 234 74 74 74 2 2 6
39513- 2 2 6 2 2 6 2 2 6 2 2 6
39514- 70 70 70 58 58 58 22 22 22 6 6 6
39515- 0 0 0 0 0 0 0 0 0 0 0 0
39516- 0 0 0 0 0 0 0 0 0 0 0 0
39517- 0 0 0 0 0 0 0 0 0 0 0 0
39518- 0 0 0 0 0 0 0 0 0 0 0 0
39519- 0 0 0 0 0 0 0 0 0 0 0 0
39520- 0 0 0 0 0 0 0 0 0 0 0 0
39521- 0 0 0 0 0 0 0 0 0 0 0 0
39522- 0 0 0 0 0 0 0 0 0 0 0 0
39523- 0 0 0 0 0 0 0 0 0 0 0 0
39524- 0 0 0 0 0 0 0 0 0 0 0 0
39525- 0 0 0 0 0 0 0 0 0 0 0 0
39526- 0 0 0 0 0 0 0 0 0 0 0 0
39527- 0 0 0 0 0 0 0 0 0 14 14 14
39528- 46 46 46 82 82 82 2 2 6 106 106 106
39529-170 170 170 26 26 26 86 86 86 226 226 226
39530-123 123 123 10 10 10 14 14 14 46 46 46
39531-231 231 231 190 190 190 6 6 6 70 70 70
39532- 90 90 90 238 238 238 158 158 158 2 2 6
39533- 2 2 6 2 2 6 2 2 6 2 2 6
39534- 70 70 70 58 58 58 22 22 22 6 6 6
39535- 0 0 0 0 0 0 0 0 0 0 0 0
39536- 0 0 0 0 0 0 0 0 0 0 0 0
39537- 0 0 0 0 0 0 0 0 0 0 0 0
39538- 0 0 0 0 0 0 0 0 0 0 0 0
39539- 0 0 0 0 0 0 0 0 0 0 0 0
39540- 0 0 0 0 0 0 0 0 0 0 0 0
39541- 0 0 0 0 0 0 0 0 1 0 0 0
39542- 0 0 1 0 0 1 0 0 1 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 14 14 14
39548- 42 42 42 86 86 86 6 6 6 116 116 116
39549-106 106 106 6 6 6 70 70 70 149 149 149
39550-128 128 128 18 18 18 38 38 38 54 54 54
39551-221 221 221 106 106 106 2 2 6 14 14 14
39552- 46 46 46 190 190 190 198 198 198 2 2 6
39553- 2 2 6 2 2 6 2 2 6 2 2 6
39554- 74 74 74 62 62 62 22 22 22 6 6 6
39555- 0 0 0 0 0 0 0 0 0 0 0 0
39556- 0 0 0 0 0 0 0 0 0 0 0 0
39557- 0 0 0 0 0 0 0 0 0 0 0 0
39558- 0 0 0 0 0 0 0 0 0 0 0 0
39559- 0 0 0 0 0 0 0 0 0 0 0 0
39560- 0 0 0 0 0 0 0 0 0 0 0 0
39561- 0 0 0 0 0 0 0 0 1 0 0 0
39562- 0 0 1 0 0 0 0 0 1 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 14 14 14
39568- 42 42 42 94 94 94 14 14 14 101 101 101
39569-128 128 128 2 2 6 18 18 18 116 116 116
39570-118 98 46 121 92 8 121 92 8 98 78 10
39571-162 162 162 106 106 106 2 2 6 2 2 6
39572- 2 2 6 195 195 195 195 195 195 6 6 6
39573- 2 2 6 2 2 6 2 2 6 2 2 6
39574- 74 74 74 62 62 62 22 22 22 6 6 6
39575- 0 0 0 0 0 0 0 0 0 0 0 0
39576- 0 0 0 0 0 0 0 0 0 0 0 0
39577- 0 0 0 0 0 0 0 0 0 0 0 0
39578- 0 0 0 0 0 0 0 0 0 0 0 0
39579- 0 0 0 0 0 0 0 0 0 0 0 0
39580- 0 0 0 0 0 0 0 0 0 0 0 0
39581- 0 0 0 0 0 0 0 0 1 0 0 1
39582- 0 0 1 0 0 0 0 0 1 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 10 10 10
39588- 38 38 38 90 90 90 14 14 14 58 58 58
39589-210 210 210 26 26 26 54 38 6 154 114 10
39590-226 170 11 236 186 11 225 175 15 184 144 12
39591-215 174 15 175 146 61 37 26 9 2 2 6
39592- 70 70 70 246 246 246 138 138 138 2 2 6
39593- 2 2 6 2 2 6 2 2 6 2 2 6
39594- 70 70 70 66 66 66 26 26 26 6 6 6
39595- 0 0 0 0 0 0 0 0 0 0 0 0
39596- 0 0 0 0 0 0 0 0 0 0 0 0
39597- 0 0 0 0 0 0 0 0 0 0 0 0
39598- 0 0 0 0 0 0 0 0 0 0 0 0
39599- 0 0 0 0 0 0 0 0 0 0 0 0
39600- 0 0 0 0 0 0 0 0 0 0 0 0
39601- 0 0 0 0 0 0 0 0 0 0 0 0
39602- 0 0 0 0 0 0 0 0 0 0 0 0
39603- 0 0 0 0 0 0 0 0 0 0 0 0
39604- 0 0 0 0 0 0 0 0 0 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 10 10 10
39608- 38 38 38 86 86 86 14 14 14 10 10 10
39609-195 195 195 188 164 115 192 133 9 225 175 15
39610-239 182 13 234 190 10 232 195 16 232 200 30
39611-245 207 45 241 208 19 232 195 16 184 144 12
39612-218 194 134 211 206 186 42 42 42 2 2 6
39613- 2 2 6 2 2 6 2 2 6 2 2 6
39614- 50 50 50 74 74 74 30 30 30 6 6 6
39615- 0 0 0 0 0 0 0 0 0 0 0 0
39616- 0 0 0 0 0 0 0 0 0 0 0 0
39617- 0 0 0 0 0 0 0 0 0 0 0 0
39618- 0 0 0 0 0 0 0 0 0 0 0 0
39619- 0 0 0 0 0 0 0 0 0 0 0 0
39620- 0 0 0 0 0 0 0 0 0 0 0 0
39621- 0 0 0 0 0 0 0 0 0 0 0 0
39622- 0 0 0 0 0 0 0 0 0 0 0 0
39623- 0 0 0 0 0 0 0 0 0 0 0 0
39624- 0 0 0 0 0 0 0 0 0 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 10 10 10
39628- 34 34 34 86 86 86 14 14 14 2 2 6
39629-121 87 25 192 133 9 219 162 10 239 182 13
39630-236 186 11 232 195 16 241 208 19 244 214 54
39631-246 218 60 246 218 38 246 215 20 241 208 19
39632-241 208 19 226 184 13 121 87 25 2 2 6
39633- 2 2 6 2 2 6 2 2 6 2 2 6
39634- 50 50 50 82 82 82 34 34 34 10 10 10
39635- 0 0 0 0 0 0 0 0 0 0 0 0
39636- 0 0 0 0 0 0 0 0 0 0 0 0
39637- 0 0 0 0 0 0 0 0 0 0 0 0
39638- 0 0 0 0 0 0 0 0 0 0 0 0
39639- 0 0 0 0 0 0 0 0 0 0 0 0
39640- 0 0 0 0 0 0 0 0 0 0 0 0
39641- 0 0 0 0 0 0 0 0 0 0 0 0
39642- 0 0 0 0 0 0 0 0 0 0 0 0
39643- 0 0 0 0 0 0 0 0 0 0 0 0
39644- 0 0 0 0 0 0 0 0 0 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 10 10 10
39648- 34 34 34 82 82 82 30 30 30 61 42 6
39649-180 123 7 206 145 10 230 174 11 239 182 13
39650-234 190 10 238 202 15 241 208 19 246 218 74
39651-246 218 38 246 215 20 246 215 20 246 215 20
39652-226 184 13 215 174 15 184 144 12 6 6 6
39653- 2 2 6 2 2 6 2 2 6 2 2 6
39654- 26 26 26 94 94 94 42 42 42 14 14 14
39655- 0 0 0 0 0 0 0 0 0 0 0 0
39656- 0 0 0 0 0 0 0 0 0 0 0 0
39657- 0 0 0 0 0 0 0 0 0 0 0 0
39658- 0 0 0 0 0 0 0 0 0 0 0 0
39659- 0 0 0 0 0 0 0 0 0 0 0 0
39660- 0 0 0 0 0 0 0 0 0 0 0 0
39661- 0 0 0 0 0 0 0 0 0 0 0 0
39662- 0 0 0 0 0 0 0 0 0 0 0 0
39663- 0 0 0 0 0 0 0 0 0 0 0 0
39664- 0 0 0 0 0 0 0 0 0 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 10 10 10
39668- 30 30 30 78 78 78 50 50 50 104 69 6
39669-192 133 9 216 158 10 236 178 12 236 186 11
39670-232 195 16 241 208 19 244 214 54 245 215 43
39671-246 215 20 246 215 20 241 208 19 198 155 10
39672-200 144 11 216 158 10 156 118 10 2 2 6
39673- 2 2 6 2 2 6 2 2 6 2 2 6
39674- 6 6 6 90 90 90 54 54 54 18 18 18
39675- 6 6 6 0 0 0 0 0 0 0 0 0
39676- 0 0 0 0 0 0 0 0 0 0 0 0
39677- 0 0 0 0 0 0 0 0 0 0 0 0
39678- 0 0 0 0 0 0 0 0 0 0 0 0
39679- 0 0 0 0 0 0 0 0 0 0 0 0
39680- 0 0 0 0 0 0 0 0 0 0 0 0
39681- 0 0 0 0 0 0 0 0 0 0 0 0
39682- 0 0 0 0 0 0 0 0 0 0 0 0
39683- 0 0 0 0 0 0 0 0 0 0 0 0
39684- 0 0 0 0 0 0 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 10 10 10
39688- 30 30 30 78 78 78 46 46 46 22 22 22
39689-137 92 6 210 162 10 239 182 13 238 190 10
39690-238 202 15 241 208 19 246 215 20 246 215 20
39691-241 208 19 203 166 17 185 133 11 210 150 10
39692-216 158 10 210 150 10 102 78 10 2 2 6
39693- 6 6 6 54 54 54 14 14 14 2 2 6
39694- 2 2 6 62 62 62 74 74 74 30 30 30
39695- 10 10 10 0 0 0 0 0 0 0 0 0
39696- 0 0 0 0 0 0 0 0 0 0 0 0
39697- 0 0 0 0 0 0 0 0 0 0 0 0
39698- 0 0 0 0 0 0 0 0 0 0 0 0
39699- 0 0 0 0 0 0 0 0 0 0 0 0
39700- 0 0 0 0 0 0 0 0 0 0 0 0
39701- 0 0 0 0 0 0 0 0 0 0 0 0
39702- 0 0 0 0 0 0 0 0 0 0 0 0
39703- 0 0 0 0 0 0 0 0 0 0 0 0
39704- 0 0 0 0 0 0 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 10 10 10
39708- 34 34 34 78 78 78 50 50 50 6 6 6
39709- 94 70 30 139 102 15 190 146 13 226 184 13
39710-232 200 30 232 195 16 215 174 15 190 146 13
39711-168 122 10 192 133 9 210 150 10 213 154 11
39712-202 150 34 182 157 106 101 98 89 2 2 6
39713- 2 2 6 78 78 78 116 116 116 58 58 58
39714- 2 2 6 22 22 22 90 90 90 46 46 46
39715- 18 18 18 6 6 6 0 0 0 0 0 0
39716- 0 0 0 0 0 0 0 0 0 0 0 0
39717- 0 0 0 0 0 0 0 0 0 0 0 0
39718- 0 0 0 0 0 0 0 0 0 0 0 0
39719- 0 0 0 0 0 0 0 0 0 0 0 0
39720- 0 0 0 0 0 0 0 0 0 0 0 0
39721- 0 0 0 0 0 0 0 0 0 0 0 0
39722- 0 0 0 0 0 0 0 0 0 0 0 0
39723- 0 0 0 0 0 0 0 0 0 0 0 0
39724- 0 0 0 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 10 10 10
39728- 38 38 38 86 86 86 50 50 50 6 6 6
39729-128 128 128 174 154 114 156 107 11 168 122 10
39730-198 155 10 184 144 12 197 138 11 200 144 11
39731-206 145 10 206 145 10 197 138 11 188 164 115
39732-195 195 195 198 198 198 174 174 174 14 14 14
39733- 2 2 6 22 22 22 116 116 116 116 116 116
39734- 22 22 22 2 2 6 74 74 74 70 70 70
39735- 30 30 30 10 10 10 0 0 0 0 0 0
39736- 0 0 0 0 0 0 0 0 0 0 0 0
39737- 0 0 0 0 0 0 0 0 0 0 0 0
39738- 0 0 0 0 0 0 0 0 0 0 0 0
39739- 0 0 0 0 0 0 0 0 0 0 0 0
39740- 0 0 0 0 0 0 0 0 0 0 0 0
39741- 0 0 0 0 0 0 0 0 0 0 0 0
39742- 0 0 0 0 0 0 0 0 0 0 0 0
39743- 0 0 0 0 0 0 0 0 0 0 0 0
39744- 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 6 6 6 18 18 18
39748- 50 50 50 101 101 101 26 26 26 10 10 10
39749-138 138 138 190 190 190 174 154 114 156 107 11
39750-197 138 11 200 144 11 197 138 11 192 133 9
39751-180 123 7 190 142 34 190 178 144 187 187 187
39752-202 202 202 221 221 221 214 214 214 66 66 66
39753- 2 2 6 2 2 6 50 50 50 62 62 62
39754- 6 6 6 2 2 6 10 10 10 90 90 90
39755- 50 50 50 18 18 18 6 6 6 0 0 0
39756- 0 0 0 0 0 0 0 0 0 0 0 0
39757- 0 0 0 0 0 0 0 0 0 0 0 0
39758- 0 0 0 0 0 0 0 0 0 0 0 0
39759- 0 0 0 0 0 0 0 0 0 0 0 0
39760- 0 0 0 0 0 0 0 0 0 0 0 0
39761- 0 0 0 0 0 0 0 0 0 0 0 0
39762- 0 0 0 0 0 0 0 0 0 0 0 0
39763- 0 0 0 0 0 0 0 0 0 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 10 10 10 34 34 34
39768- 74 74 74 74 74 74 2 2 6 6 6 6
39769-144 144 144 198 198 198 190 190 190 178 166 146
39770-154 121 60 156 107 11 156 107 11 168 124 44
39771-174 154 114 187 187 187 190 190 190 210 210 210
39772-246 246 246 253 253 253 253 253 253 182 182 182
39773- 6 6 6 2 2 6 2 2 6 2 2 6
39774- 2 2 6 2 2 6 2 2 6 62 62 62
39775- 74 74 74 34 34 34 14 14 14 0 0 0
39776- 0 0 0 0 0 0 0 0 0 0 0 0
39777- 0 0 0 0 0 0 0 0 0 0 0 0
39778- 0 0 0 0 0 0 0 0 0 0 0 0
39779- 0 0 0 0 0 0 0 0 0 0 0 0
39780- 0 0 0 0 0 0 0 0 0 0 0 0
39781- 0 0 0 0 0 0 0 0 0 0 0 0
39782- 0 0 0 0 0 0 0 0 0 0 0 0
39783- 0 0 0 0 0 0 0 0 0 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 10 10 10 22 22 22 54 54 54
39788- 94 94 94 18 18 18 2 2 6 46 46 46
39789-234 234 234 221 221 221 190 190 190 190 190 190
39790-190 190 190 187 187 187 187 187 187 190 190 190
39791-190 190 190 195 195 195 214 214 214 242 242 242
39792-253 253 253 253 253 253 253 253 253 253 253 253
39793- 82 82 82 2 2 6 2 2 6 2 2 6
39794- 2 2 6 2 2 6 2 2 6 14 14 14
39795- 86 86 86 54 54 54 22 22 22 6 6 6
39796- 0 0 0 0 0 0 0 0 0 0 0 0
39797- 0 0 0 0 0 0 0 0 0 0 0 0
39798- 0 0 0 0 0 0 0 0 0 0 0 0
39799- 0 0 0 0 0 0 0 0 0 0 0 0
39800- 0 0 0 0 0 0 0 0 0 0 0 0
39801- 0 0 0 0 0 0 0 0 0 0 0 0
39802- 0 0 0 0 0 0 0 0 0 0 0 0
39803- 0 0 0 0 0 0 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- 6 6 6 18 18 18 46 46 46 90 90 90
39808- 46 46 46 18 18 18 6 6 6 182 182 182
39809-253 253 253 246 246 246 206 206 206 190 190 190
39810-190 190 190 190 190 190 190 190 190 190 190 190
39811-206 206 206 231 231 231 250 250 250 253 253 253
39812-253 253 253 253 253 253 253 253 253 253 253 253
39813-202 202 202 14 14 14 2 2 6 2 2 6
39814- 2 2 6 2 2 6 2 2 6 2 2 6
39815- 42 42 42 86 86 86 42 42 42 18 18 18
39816- 6 6 6 0 0 0 0 0 0 0 0 0
39817- 0 0 0 0 0 0 0 0 0 0 0 0
39818- 0 0 0 0 0 0 0 0 0 0 0 0
39819- 0 0 0 0 0 0 0 0 0 0 0 0
39820- 0 0 0 0 0 0 0 0 0 0 0 0
39821- 0 0 0 0 0 0 0 0 0 0 0 0
39822- 0 0 0 0 0 0 0 0 0 0 0 0
39823- 0 0 0 0 0 0 0 0 0 0 0 0
39824- 0 0 0 0 0 0 0 0 0 0 0 0
39825- 0 0 0 0 0 0 0 0 0 0 0 0
39826- 0 0 0 0 0 0 0 0 0 6 6 6
39827- 14 14 14 38 38 38 74 74 74 66 66 66
39828- 2 2 6 6 6 6 90 90 90 250 250 250
39829-253 253 253 253 253 253 238 238 238 198 198 198
39830-190 190 190 190 190 190 195 195 195 221 221 221
39831-246 246 246 253 253 253 253 253 253 253 253 253
39832-253 253 253 253 253 253 253 253 253 253 253 253
39833-253 253 253 82 82 82 2 2 6 2 2 6
39834- 2 2 6 2 2 6 2 2 6 2 2 6
39835- 2 2 6 78 78 78 70 70 70 34 34 34
39836- 14 14 14 6 6 6 0 0 0 0 0 0
39837- 0 0 0 0 0 0 0 0 0 0 0 0
39838- 0 0 0 0 0 0 0 0 0 0 0 0
39839- 0 0 0 0 0 0 0 0 0 0 0 0
39840- 0 0 0 0 0 0 0 0 0 0 0 0
39841- 0 0 0 0 0 0 0 0 0 0 0 0
39842- 0 0 0 0 0 0 0 0 0 0 0 0
39843- 0 0 0 0 0 0 0 0 0 0 0 0
39844- 0 0 0 0 0 0 0 0 0 0 0 0
39845- 0 0 0 0 0 0 0 0 0 0 0 0
39846- 0 0 0 0 0 0 0 0 0 14 14 14
39847- 34 34 34 66 66 66 78 78 78 6 6 6
39848- 2 2 6 18 18 18 218 218 218 253 253 253
39849-253 253 253 253 253 253 253 253 253 246 246 246
39850-226 226 226 231 231 231 246 246 246 253 253 253
39851-253 253 253 253 253 253 253 253 253 253 253 253
39852-253 253 253 253 253 253 253 253 253 253 253 253
39853-253 253 253 178 178 178 2 2 6 2 2 6
39854- 2 2 6 2 2 6 2 2 6 2 2 6
39855- 2 2 6 18 18 18 90 90 90 62 62 62
39856- 30 30 30 10 10 10 0 0 0 0 0 0
39857- 0 0 0 0 0 0 0 0 0 0 0 0
39858- 0 0 0 0 0 0 0 0 0 0 0 0
39859- 0 0 0 0 0 0 0 0 0 0 0 0
39860- 0 0 0 0 0 0 0 0 0 0 0 0
39861- 0 0 0 0 0 0 0 0 0 0 0 0
39862- 0 0 0 0 0 0 0 0 0 0 0 0
39863- 0 0 0 0 0 0 0 0 0 0 0 0
39864- 0 0 0 0 0 0 0 0 0 0 0 0
39865- 0 0 0 0 0 0 0 0 0 0 0 0
39866- 0 0 0 0 0 0 10 10 10 26 26 26
39867- 58 58 58 90 90 90 18 18 18 2 2 6
39868- 2 2 6 110 110 110 253 253 253 253 253 253
39869-253 253 253 253 253 253 253 253 253 253 253 253
39870-250 250 250 253 253 253 253 253 253 253 253 253
39871-253 253 253 253 253 253 253 253 253 253 253 253
39872-253 253 253 253 253 253 253 253 253 253 253 253
39873-253 253 253 231 231 231 18 18 18 2 2 6
39874- 2 2 6 2 2 6 2 2 6 2 2 6
39875- 2 2 6 2 2 6 18 18 18 94 94 94
39876- 54 54 54 26 26 26 10 10 10 0 0 0
39877- 0 0 0 0 0 0 0 0 0 0 0 0
39878- 0 0 0 0 0 0 0 0 0 0 0 0
39879- 0 0 0 0 0 0 0 0 0 0 0 0
39880- 0 0 0 0 0 0 0 0 0 0 0 0
39881- 0 0 0 0 0 0 0 0 0 0 0 0
39882- 0 0 0 0 0 0 0 0 0 0 0 0
39883- 0 0 0 0 0 0 0 0 0 0 0 0
39884- 0 0 0 0 0 0 0 0 0 0 0 0
39885- 0 0 0 0 0 0 0 0 0 0 0 0
39886- 0 0 0 6 6 6 22 22 22 50 50 50
39887- 90 90 90 26 26 26 2 2 6 2 2 6
39888- 14 14 14 195 195 195 250 250 250 253 253 253
39889-253 253 253 253 253 253 253 253 253 253 253 253
39890-253 253 253 253 253 253 253 253 253 253 253 253
39891-253 253 253 253 253 253 253 253 253 253 253 253
39892-253 253 253 253 253 253 253 253 253 253 253 253
39893-250 250 250 242 242 242 54 54 54 2 2 6
39894- 2 2 6 2 2 6 2 2 6 2 2 6
39895- 2 2 6 2 2 6 2 2 6 38 38 38
39896- 86 86 86 50 50 50 22 22 22 6 6 6
39897- 0 0 0 0 0 0 0 0 0 0 0 0
39898- 0 0 0 0 0 0 0 0 0 0 0 0
39899- 0 0 0 0 0 0 0 0 0 0 0 0
39900- 0 0 0 0 0 0 0 0 0 0 0 0
39901- 0 0 0 0 0 0 0 0 0 0 0 0
39902- 0 0 0 0 0 0 0 0 0 0 0 0
39903- 0 0 0 0 0 0 0 0 0 0 0 0
39904- 0 0 0 0 0 0 0 0 0 0 0 0
39905- 0 0 0 0 0 0 0 0 0 0 0 0
39906- 6 6 6 14 14 14 38 38 38 82 82 82
39907- 34 34 34 2 2 6 2 2 6 2 2 6
39908- 42 42 42 195 195 195 246 246 246 253 253 253
39909-253 253 253 253 253 253 253 253 253 250 250 250
39910-242 242 242 242 242 242 250 250 250 253 253 253
39911-253 253 253 253 253 253 253 253 253 253 253 253
39912-253 253 253 250 250 250 246 246 246 238 238 238
39913-226 226 226 231 231 231 101 101 101 6 6 6
39914- 2 2 6 2 2 6 2 2 6 2 2 6
39915- 2 2 6 2 2 6 2 2 6 2 2 6
39916- 38 38 38 82 82 82 42 42 42 14 14 14
39917- 6 6 6 0 0 0 0 0 0 0 0 0
39918- 0 0 0 0 0 0 0 0 0 0 0 0
39919- 0 0 0 0 0 0 0 0 0 0 0 0
39920- 0 0 0 0 0 0 0 0 0 0 0 0
39921- 0 0 0 0 0 0 0 0 0 0 0 0
39922- 0 0 0 0 0 0 0 0 0 0 0 0
39923- 0 0 0 0 0 0 0 0 0 0 0 0
39924- 0 0 0 0 0 0 0 0 0 0 0 0
39925- 0 0 0 0 0 0 0 0 0 0 0 0
39926- 10 10 10 26 26 26 62 62 62 66 66 66
39927- 2 2 6 2 2 6 2 2 6 6 6 6
39928- 70 70 70 170 170 170 206 206 206 234 234 234
39929-246 246 246 250 250 250 250 250 250 238 238 238
39930-226 226 226 231 231 231 238 238 238 250 250 250
39931-250 250 250 250 250 250 246 246 246 231 231 231
39932-214 214 214 206 206 206 202 202 202 202 202 202
39933-198 198 198 202 202 202 182 182 182 18 18 18
39934- 2 2 6 2 2 6 2 2 6 2 2 6
39935- 2 2 6 2 2 6 2 2 6 2 2 6
39936- 2 2 6 62 62 62 66 66 66 30 30 30
39937- 10 10 10 0 0 0 0 0 0 0 0 0
39938- 0 0 0 0 0 0 0 0 0 0 0 0
39939- 0 0 0 0 0 0 0 0 0 0 0 0
39940- 0 0 0 0 0 0 0 0 0 0 0 0
39941- 0 0 0 0 0 0 0 0 0 0 0 0
39942- 0 0 0 0 0 0 0 0 0 0 0 0
39943- 0 0 0 0 0 0 0 0 0 0 0 0
39944- 0 0 0 0 0 0 0 0 0 0 0 0
39945- 0 0 0 0 0 0 0 0 0 0 0 0
39946- 14 14 14 42 42 42 82 82 82 18 18 18
39947- 2 2 6 2 2 6 2 2 6 10 10 10
39948- 94 94 94 182 182 182 218 218 218 242 242 242
39949-250 250 250 253 253 253 253 253 253 250 250 250
39950-234 234 234 253 253 253 253 253 253 253 253 253
39951-253 253 253 253 253 253 253 253 253 246 246 246
39952-238 238 238 226 226 226 210 210 210 202 202 202
39953-195 195 195 195 195 195 210 210 210 158 158 158
39954- 6 6 6 14 14 14 50 50 50 14 14 14
39955- 2 2 6 2 2 6 2 2 6 2 2 6
39956- 2 2 6 6 6 6 86 86 86 46 46 46
39957- 18 18 18 6 6 6 0 0 0 0 0 0
39958- 0 0 0 0 0 0 0 0 0 0 0 0
39959- 0 0 0 0 0 0 0 0 0 0 0 0
39960- 0 0 0 0 0 0 0 0 0 0 0 0
39961- 0 0 0 0 0 0 0 0 0 0 0 0
39962- 0 0 0 0 0 0 0 0 0 0 0 0
39963- 0 0 0 0 0 0 0 0 0 0 0 0
39964- 0 0 0 0 0 0 0 0 0 0 0 0
39965- 0 0 0 0 0 0 0 0 0 6 6 6
39966- 22 22 22 54 54 54 70 70 70 2 2 6
39967- 2 2 6 10 10 10 2 2 6 22 22 22
39968-166 166 166 231 231 231 250 250 250 253 253 253
39969-253 253 253 253 253 253 253 253 253 250 250 250
39970-242 242 242 253 253 253 253 253 253 253 253 253
39971-253 253 253 253 253 253 253 253 253 253 253 253
39972-253 253 253 253 253 253 253 253 253 246 246 246
39973-231 231 231 206 206 206 198 198 198 226 226 226
39974- 94 94 94 2 2 6 6 6 6 38 38 38
39975- 30 30 30 2 2 6 2 2 6 2 2 6
39976- 2 2 6 2 2 6 62 62 62 66 66 66
39977- 26 26 26 10 10 10 0 0 0 0 0 0
39978- 0 0 0 0 0 0 0 0 0 0 0 0
39979- 0 0 0 0 0 0 0 0 0 0 0 0
39980- 0 0 0 0 0 0 0 0 0 0 0 0
39981- 0 0 0 0 0 0 0 0 0 0 0 0
39982- 0 0 0 0 0 0 0 0 0 0 0 0
39983- 0 0 0 0 0 0 0 0 0 0 0 0
39984- 0 0 0 0 0 0 0 0 0 0 0 0
39985- 0 0 0 0 0 0 0 0 0 10 10 10
39986- 30 30 30 74 74 74 50 50 50 2 2 6
39987- 26 26 26 26 26 26 2 2 6 106 106 106
39988-238 238 238 253 253 253 253 253 253 253 253 253
39989-253 253 253 253 253 253 253 253 253 253 253 253
39990-253 253 253 253 253 253 253 253 253 253 253 253
39991-253 253 253 253 253 253 253 253 253 253 253 253
39992-253 253 253 253 253 253 253 253 253 253 253 253
39993-253 253 253 246 246 246 218 218 218 202 202 202
39994-210 210 210 14 14 14 2 2 6 2 2 6
39995- 30 30 30 22 22 22 2 2 6 2 2 6
39996- 2 2 6 2 2 6 18 18 18 86 86 86
39997- 42 42 42 14 14 14 0 0 0 0 0 0
39998- 0 0 0 0 0 0 0 0 0 0 0 0
39999- 0 0 0 0 0 0 0 0 0 0 0 0
40000- 0 0 0 0 0 0 0 0 0 0 0 0
40001- 0 0 0 0 0 0 0 0 0 0 0 0
40002- 0 0 0 0 0 0 0 0 0 0 0 0
40003- 0 0 0 0 0 0 0 0 0 0 0 0
40004- 0 0 0 0 0 0 0 0 0 0 0 0
40005- 0 0 0 0 0 0 0 0 0 14 14 14
40006- 42 42 42 90 90 90 22 22 22 2 2 6
40007- 42 42 42 2 2 6 18 18 18 218 218 218
40008-253 253 253 253 253 253 253 253 253 253 253 253
40009-253 253 253 253 253 253 253 253 253 253 253 253
40010-253 253 253 253 253 253 253 253 253 253 253 253
40011-253 253 253 253 253 253 253 253 253 253 253 253
40012-253 253 253 253 253 253 253 253 253 253 253 253
40013-253 253 253 253 253 253 250 250 250 221 221 221
40014-218 218 218 101 101 101 2 2 6 14 14 14
40015- 18 18 18 38 38 38 10 10 10 2 2 6
40016- 2 2 6 2 2 6 2 2 6 78 78 78
40017- 58 58 58 22 22 22 6 6 6 0 0 0
40018- 0 0 0 0 0 0 0 0 0 0 0 0
40019- 0 0 0 0 0 0 0 0 0 0 0 0
40020- 0 0 0 0 0 0 0 0 0 0 0 0
40021- 0 0 0 0 0 0 0 0 0 0 0 0
40022- 0 0 0 0 0 0 0 0 0 0 0 0
40023- 0 0 0 0 0 0 0 0 0 0 0 0
40024- 0 0 0 0 0 0 0 0 0 0 0 0
40025- 0 0 0 0 0 0 6 6 6 18 18 18
40026- 54 54 54 82 82 82 2 2 6 26 26 26
40027- 22 22 22 2 2 6 123 123 123 253 253 253
40028-253 253 253 253 253 253 253 253 253 253 253 253
40029-253 253 253 253 253 253 253 253 253 253 253 253
40030-253 253 253 253 253 253 253 253 253 253 253 253
40031-253 253 253 253 253 253 253 253 253 253 253 253
40032-253 253 253 253 253 253 253 253 253 253 253 253
40033-253 253 253 253 253 253 253 253 253 250 250 250
40034-238 238 238 198 198 198 6 6 6 38 38 38
40035- 58 58 58 26 26 26 38 38 38 2 2 6
40036- 2 2 6 2 2 6 2 2 6 46 46 46
40037- 78 78 78 30 30 30 10 10 10 0 0 0
40038- 0 0 0 0 0 0 0 0 0 0 0 0
40039- 0 0 0 0 0 0 0 0 0 0 0 0
40040- 0 0 0 0 0 0 0 0 0 0 0 0
40041- 0 0 0 0 0 0 0 0 0 0 0 0
40042- 0 0 0 0 0 0 0 0 0 0 0 0
40043- 0 0 0 0 0 0 0 0 0 0 0 0
40044- 0 0 0 0 0 0 0 0 0 0 0 0
40045- 0 0 0 0 0 0 10 10 10 30 30 30
40046- 74 74 74 58 58 58 2 2 6 42 42 42
40047- 2 2 6 22 22 22 231 231 231 253 253 253
40048-253 253 253 253 253 253 253 253 253 253 253 253
40049-253 253 253 253 253 253 253 253 253 250 250 250
40050-253 253 253 253 253 253 253 253 253 253 253 253
40051-253 253 253 253 253 253 253 253 253 253 253 253
40052-253 253 253 253 253 253 253 253 253 253 253 253
40053-253 253 253 253 253 253 253 253 253 253 253 253
40054-253 253 253 246 246 246 46 46 46 38 38 38
40055- 42 42 42 14 14 14 38 38 38 14 14 14
40056- 2 2 6 2 2 6 2 2 6 6 6 6
40057- 86 86 86 46 46 46 14 14 14 0 0 0
40058- 0 0 0 0 0 0 0 0 0 0 0 0
40059- 0 0 0 0 0 0 0 0 0 0 0 0
40060- 0 0 0 0 0 0 0 0 0 0 0 0
40061- 0 0 0 0 0 0 0 0 0 0 0 0
40062- 0 0 0 0 0 0 0 0 0 0 0 0
40063- 0 0 0 0 0 0 0 0 0 0 0 0
40064- 0 0 0 0 0 0 0 0 0 0 0 0
40065- 0 0 0 6 6 6 14 14 14 42 42 42
40066- 90 90 90 18 18 18 18 18 18 26 26 26
40067- 2 2 6 116 116 116 253 253 253 253 253 253
40068-253 253 253 253 253 253 253 253 253 253 253 253
40069-253 253 253 253 253 253 250 250 250 238 238 238
40070-253 253 253 253 253 253 253 253 253 253 253 253
40071-253 253 253 253 253 253 253 253 253 253 253 253
40072-253 253 253 253 253 253 253 253 253 253 253 253
40073-253 253 253 253 253 253 253 253 253 253 253 253
40074-253 253 253 253 253 253 94 94 94 6 6 6
40075- 2 2 6 2 2 6 10 10 10 34 34 34
40076- 2 2 6 2 2 6 2 2 6 2 2 6
40077- 74 74 74 58 58 58 22 22 22 6 6 6
40078- 0 0 0 0 0 0 0 0 0 0 0 0
40079- 0 0 0 0 0 0 0 0 0 0 0 0
40080- 0 0 0 0 0 0 0 0 0 0 0 0
40081- 0 0 0 0 0 0 0 0 0 0 0 0
40082- 0 0 0 0 0 0 0 0 0 0 0 0
40083- 0 0 0 0 0 0 0 0 0 0 0 0
40084- 0 0 0 0 0 0 0 0 0 0 0 0
40085- 0 0 0 10 10 10 26 26 26 66 66 66
40086- 82 82 82 2 2 6 38 38 38 6 6 6
40087- 14 14 14 210 210 210 253 253 253 253 253 253
40088-253 253 253 253 253 253 253 253 253 253 253 253
40089-253 253 253 253 253 253 246 246 246 242 242 242
40090-253 253 253 253 253 253 253 253 253 253 253 253
40091-253 253 253 253 253 253 253 253 253 253 253 253
40092-253 253 253 253 253 253 253 253 253 253 253 253
40093-253 253 253 253 253 253 253 253 253 253 253 253
40094-253 253 253 253 253 253 144 144 144 2 2 6
40095- 2 2 6 2 2 6 2 2 6 46 46 46
40096- 2 2 6 2 2 6 2 2 6 2 2 6
40097- 42 42 42 74 74 74 30 30 30 10 10 10
40098- 0 0 0 0 0 0 0 0 0 0 0 0
40099- 0 0 0 0 0 0 0 0 0 0 0 0
40100- 0 0 0 0 0 0 0 0 0 0 0 0
40101- 0 0 0 0 0 0 0 0 0 0 0 0
40102- 0 0 0 0 0 0 0 0 0 0 0 0
40103- 0 0 0 0 0 0 0 0 0 0 0 0
40104- 0 0 0 0 0 0 0 0 0 0 0 0
40105- 6 6 6 14 14 14 42 42 42 90 90 90
40106- 26 26 26 6 6 6 42 42 42 2 2 6
40107- 74 74 74 250 250 250 253 253 253 253 253 253
40108-253 253 253 253 253 253 253 253 253 253 253 253
40109-253 253 253 253 253 253 242 242 242 242 242 242
40110-253 253 253 253 253 253 253 253 253 253 253 253
40111-253 253 253 253 253 253 253 253 253 253 253 253
40112-253 253 253 253 253 253 253 253 253 253 253 253
40113-253 253 253 253 253 253 253 253 253 253 253 253
40114-253 253 253 253 253 253 182 182 182 2 2 6
40115- 2 2 6 2 2 6 2 2 6 46 46 46
40116- 2 2 6 2 2 6 2 2 6 2 2 6
40117- 10 10 10 86 86 86 38 38 38 10 10 10
40118- 0 0 0 0 0 0 0 0 0 0 0 0
40119- 0 0 0 0 0 0 0 0 0 0 0 0
40120- 0 0 0 0 0 0 0 0 0 0 0 0
40121- 0 0 0 0 0 0 0 0 0 0 0 0
40122- 0 0 0 0 0 0 0 0 0 0 0 0
40123- 0 0 0 0 0 0 0 0 0 0 0 0
40124- 0 0 0 0 0 0 0 0 0 0 0 0
40125- 10 10 10 26 26 26 66 66 66 82 82 82
40126- 2 2 6 22 22 22 18 18 18 2 2 6
40127-149 149 149 253 253 253 253 253 253 253 253 253
40128-253 253 253 253 253 253 253 253 253 253 253 253
40129-253 253 253 253 253 253 234 234 234 242 242 242
40130-253 253 253 253 253 253 253 253 253 253 253 253
40131-253 253 253 253 253 253 253 253 253 253 253 253
40132-253 253 253 253 253 253 253 253 253 253 253 253
40133-253 253 253 253 253 253 253 253 253 253 253 253
40134-253 253 253 253 253 253 206 206 206 2 2 6
40135- 2 2 6 2 2 6 2 2 6 38 38 38
40136- 2 2 6 2 2 6 2 2 6 2 2 6
40137- 6 6 6 86 86 86 46 46 46 14 14 14
40138- 0 0 0 0 0 0 0 0 0 0 0 0
40139- 0 0 0 0 0 0 0 0 0 0 0 0
40140- 0 0 0 0 0 0 0 0 0 0 0 0
40141- 0 0 0 0 0 0 0 0 0 0 0 0
40142- 0 0 0 0 0 0 0 0 0 0 0 0
40143- 0 0 0 0 0 0 0 0 0 0 0 0
40144- 0 0 0 0 0 0 0 0 0 6 6 6
40145- 18 18 18 46 46 46 86 86 86 18 18 18
40146- 2 2 6 34 34 34 10 10 10 6 6 6
40147-210 210 210 253 253 253 253 253 253 253 253 253
40148-253 253 253 253 253 253 253 253 253 253 253 253
40149-253 253 253 253 253 253 234 234 234 242 242 242
40150-253 253 253 253 253 253 253 253 253 253 253 253
40151-253 253 253 253 253 253 253 253 253 253 253 253
40152-253 253 253 253 253 253 253 253 253 253 253 253
40153-253 253 253 253 253 253 253 253 253 253 253 253
40154-253 253 253 253 253 253 221 221 221 6 6 6
40155- 2 2 6 2 2 6 6 6 6 30 30 30
40156- 2 2 6 2 2 6 2 2 6 2 2 6
40157- 2 2 6 82 82 82 54 54 54 18 18 18
40158- 6 6 6 0 0 0 0 0 0 0 0 0
40159- 0 0 0 0 0 0 0 0 0 0 0 0
40160- 0 0 0 0 0 0 0 0 0 0 0 0
40161- 0 0 0 0 0 0 0 0 0 0 0 0
40162- 0 0 0 0 0 0 0 0 0 0 0 0
40163- 0 0 0 0 0 0 0 0 0 0 0 0
40164- 0 0 0 0 0 0 0 0 0 10 10 10
40165- 26 26 26 66 66 66 62 62 62 2 2 6
40166- 2 2 6 38 38 38 10 10 10 26 26 26
40167-238 238 238 253 253 253 253 253 253 253 253 253
40168-253 253 253 253 253 253 253 253 253 253 253 253
40169-253 253 253 253 253 253 231 231 231 238 238 238
40170-253 253 253 253 253 253 253 253 253 253 253 253
40171-253 253 253 253 253 253 253 253 253 253 253 253
40172-253 253 253 253 253 253 253 253 253 253 253 253
40173-253 253 253 253 253 253 253 253 253 253 253 253
40174-253 253 253 253 253 253 231 231 231 6 6 6
40175- 2 2 6 2 2 6 10 10 10 30 30 30
40176- 2 2 6 2 2 6 2 2 6 2 2 6
40177- 2 2 6 66 66 66 58 58 58 22 22 22
40178- 6 6 6 0 0 0 0 0 0 0 0 0
40179- 0 0 0 0 0 0 0 0 0 0 0 0
40180- 0 0 0 0 0 0 0 0 0 0 0 0
40181- 0 0 0 0 0 0 0 0 0 0 0 0
40182- 0 0 0 0 0 0 0 0 0 0 0 0
40183- 0 0 0 0 0 0 0 0 0 0 0 0
40184- 0 0 0 0 0 0 0 0 0 10 10 10
40185- 38 38 38 78 78 78 6 6 6 2 2 6
40186- 2 2 6 46 46 46 14 14 14 42 42 42
40187-246 246 246 253 253 253 253 253 253 253 253 253
40188-253 253 253 253 253 253 253 253 253 253 253 253
40189-253 253 253 253 253 253 231 231 231 242 242 242
40190-253 253 253 253 253 253 253 253 253 253 253 253
40191-253 253 253 253 253 253 253 253 253 253 253 253
40192-253 253 253 253 253 253 253 253 253 253 253 253
40193-253 253 253 253 253 253 253 253 253 253 253 253
40194-253 253 253 253 253 253 234 234 234 10 10 10
40195- 2 2 6 2 2 6 22 22 22 14 14 14
40196- 2 2 6 2 2 6 2 2 6 2 2 6
40197- 2 2 6 66 66 66 62 62 62 22 22 22
40198- 6 6 6 0 0 0 0 0 0 0 0 0
40199- 0 0 0 0 0 0 0 0 0 0 0 0
40200- 0 0 0 0 0 0 0 0 0 0 0 0
40201- 0 0 0 0 0 0 0 0 0 0 0 0
40202- 0 0 0 0 0 0 0 0 0 0 0 0
40203- 0 0 0 0 0 0 0 0 0 0 0 0
40204- 0 0 0 0 0 0 6 6 6 18 18 18
40205- 50 50 50 74 74 74 2 2 6 2 2 6
40206- 14 14 14 70 70 70 34 34 34 62 62 62
40207-250 250 250 253 253 253 253 253 253 253 253 253
40208-253 253 253 253 253 253 253 253 253 253 253 253
40209-253 253 253 253 253 253 231 231 231 246 246 246
40210-253 253 253 253 253 253 253 253 253 253 253 253
40211-253 253 253 253 253 253 253 253 253 253 253 253
40212-253 253 253 253 253 253 253 253 253 253 253 253
40213-253 253 253 253 253 253 253 253 253 253 253 253
40214-253 253 253 253 253 253 234 234 234 14 14 14
40215- 2 2 6 2 2 6 30 30 30 2 2 6
40216- 2 2 6 2 2 6 2 2 6 2 2 6
40217- 2 2 6 66 66 66 62 62 62 22 22 22
40218- 6 6 6 0 0 0 0 0 0 0 0 0
40219- 0 0 0 0 0 0 0 0 0 0 0 0
40220- 0 0 0 0 0 0 0 0 0 0 0 0
40221- 0 0 0 0 0 0 0 0 0 0 0 0
40222- 0 0 0 0 0 0 0 0 0 0 0 0
40223- 0 0 0 0 0 0 0 0 0 0 0 0
40224- 0 0 0 0 0 0 6 6 6 18 18 18
40225- 54 54 54 62 62 62 2 2 6 2 2 6
40226- 2 2 6 30 30 30 46 46 46 70 70 70
40227-250 250 250 253 253 253 253 253 253 253 253 253
40228-253 253 253 253 253 253 253 253 253 253 253 253
40229-253 253 253 253 253 253 231 231 231 246 246 246
40230-253 253 253 253 253 253 253 253 253 253 253 253
40231-253 253 253 253 253 253 253 253 253 253 253 253
40232-253 253 253 253 253 253 253 253 253 253 253 253
40233-253 253 253 253 253 253 253 253 253 253 253 253
40234-253 253 253 253 253 253 226 226 226 10 10 10
40235- 2 2 6 6 6 6 30 30 30 2 2 6
40236- 2 2 6 2 2 6 2 2 6 2 2 6
40237- 2 2 6 66 66 66 58 58 58 22 22 22
40238- 6 6 6 0 0 0 0 0 0 0 0 0
40239- 0 0 0 0 0 0 0 0 0 0 0 0
40240- 0 0 0 0 0 0 0 0 0 0 0 0
40241- 0 0 0 0 0 0 0 0 0 0 0 0
40242- 0 0 0 0 0 0 0 0 0 0 0 0
40243- 0 0 0 0 0 0 0 0 0 0 0 0
40244- 0 0 0 0 0 0 6 6 6 22 22 22
40245- 58 58 58 62 62 62 2 2 6 2 2 6
40246- 2 2 6 2 2 6 30 30 30 78 78 78
40247-250 250 250 253 253 253 253 253 253 253 253 253
40248-253 253 253 253 253 253 253 253 253 253 253 253
40249-253 253 253 253 253 253 231 231 231 246 246 246
40250-253 253 253 253 253 253 253 253 253 253 253 253
40251-253 253 253 253 253 253 253 253 253 253 253 253
40252-253 253 253 253 253 253 253 253 253 253 253 253
40253-253 253 253 253 253 253 253 253 253 253 253 253
40254-253 253 253 253 253 253 206 206 206 2 2 6
40255- 22 22 22 34 34 34 18 14 6 22 22 22
40256- 26 26 26 18 18 18 6 6 6 2 2 6
40257- 2 2 6 82 82 82 54 54 54 18 18 18
40258- 6 6 6 0 0 0 0 0 0 0 0 0
40259- 0 0 0 0 0 0 0 0 0 0 0 0
40260- 0 0 0 0 0 0 0 0 0 0 0 0
40261- 0 0 0 0 0 0 0 0 0 0 0 0
40262- 0 0 0 0 0 0 0 0 0 0 0 0
40263- 0 0 0 0 0 0 0 0 0 0 0 0
40264- 0 0 0 0 0 0 6 6 6 26 26 26
40265- 62 62 62 106 106 106 74 54 14 185 133 11
40266-210 162 10 121 92 8 6 6 6 62 62 62
40267-238 238 238 253 253 253 253 253 253 253 253 253
40268-253 253 253 253 253 253 253 253 253 253 253 253
40269-253 253 253 253 253 253 231 231 231 246 246 246
40270-253 253 253 253 253 253 253 253 253 253 253 253
40271-253 253 253 253 253 253 253 253 253 253 253 253
40272-253 253 253 253 253 253 253 253 253 253 253 253
40273-253 253 253 253 253 253 253 253 253 253 253 253
40274-253 253 253 253 253 253 158 158 158 18 18 18
40275- 14 14 14 2 2 6 2 2 6 2 2 6
40276- 6 6 6 18 18 18 66 66 66 38 38 38
40277- 6 6 6 94 94 94 50 50 50 18 18 18
40278- 6 6 6 0 0 0 0 0 0 0 0 0
40279- 0 0 0 0 0 0 0 0 0 0 0 0
40280- 0 0 0 0 0 0 0 0 0 0 0 0
40281- 0 0 0 0 0 0 0 0 0 0 0 0
40282- 0 0 0 0 0 0 0 0 0 0 0 0
40283- 0 0 0 0 0 0 0 0 0 6 6 6
40284- 10 10 10 10 10 10 18 18 18 38 38 38
40285- 78 78 78 142 134 106 216 158 10 242 186 14
40286-246 190 14 246 190 14 156 118 10 10 10 10
40287- 90 90 90 238 238 238 253 253 253 253 253 253
40288-253 253 253 253 253 253 253 253 253 253 253 253
40289-253 253 253 253 253 253 231 231 231 250 250 250
40290-253 253 253 253 253 253 253 253 253 253 253 253
40291-253 253 253 253 253 253 253 253 253 253 253 253
40292-253 253 253 253 253 253 253 253 253 253 253 253
40293-253 253 253 253 253 253 253 253 253 246 230 190
40294-238 204 91 238 204 91 181 142 44 37 26 9
40295- 2 2 6 2 2 6 2 2 6 2 2 6
40296- 2 2 6 2 2 6 38 38 38 46 46 46
40297- 26 26 26 106 106 106 54 54 54 18 18 18
40298- 6 6 6 0 0 0 0 0 0 0 0 0
40299- 0 0 0 0 0 0 0 0 0 0 0 0
40300- 0 0 0 0 0 0 0 0 0 0 0 0
40301- 0 0 0 0 0 0 0 0 0 0 0 0
40302- 0 0 0 0 0 0 0 0 0 0 0 0
40303- 0 0 0 6 6 6 14 14 14 22 22 22
40304- 30 30 30 38 38 38 50 50 50 70 70 70
40305-106 106 106 190 142 34 226 170 11 242 186 14
40306-246 190 14 246 190 14 246 190 14 154 114 10
40307- 6 6 6 74 74 74 226 226 226 253 253 253
40308-253 253 253 253 253 253 253 253 253 253 253 253
40309-253 253 253 253 253 253 231 231 231 250 250 250
40310-253 253 253 253 253 253 253 253 253 253 253 253
40311-253 253 253 253 253 253 253 253 253 253 253 253
40312-253 253 253 253 253 253 253 253 253 253 253 253
40313-253 253 253 253 253 253 253 253 253 228 184 62
40314-241 196 14 241 208 19 232 195 16 38 30 10
40315- 2 2 6 2 2 6 2 2 6 2 2 6
40316- 2 2 6 6 6 6 30 30 30 26 26 26
40317-203 166 17 154 142 90 66 66 66 26 26 26
40318- 6 6 6 0 0 0 0 0 0 0 0 0
40319- 0 0 0 0 0 0 0 0 0 0 0 0
40320- 0 0 0 0 0 0 0 0 0 0 0 0
40321- 0 0 0 0 0 0 0 0 0 0 0 0
40322- 0 0 0 0 0 0 0 0 0 0 0 0
40323- 6 6 6 18 18 18 38 38 38 58 58 58
40324- 78 78 78 86 86 86 101 101 101 123 123 123
40325-175 146 61 210 150 10 234 174 13 246 186 14
40326-246 190 14 246 190 14 246 190 14 238 190 10
40327-102 78 10 2 2 6 46 46 46 198 198 198
40328-253 253 253 253 253 253 253 253 253 253 253 253
40329-253 253 253 253 253 253 234 234 234 242 242 242
40330-253 253 253 253 253 253 253 253 253 253 253 253
40331-253 253 253 253 253 253 253 253 253 253 253 253
40332-253 253 253 253 253 253 253 253 253 253 253 253
40333-253 253 253 253 253 253 253 253 253 224 178 62
40334-242 186 14 241 196 14 210 166 10 22 18 6
40335- 2 2 6 2 2 6 2 2 6 2 2 6
40336- 2 2 6 2 2 6 6 6 6 121 92 8
40337-238 202 15 232 195 16 82 82 82 34 34 34
40338- 10 10 10 0 0 0 0 0 0 0 0 0
40339- 0 0 0 0 0 0 0 0 0 0 0 0
40340- 0 0 0 0 0 0 0 0 0 0 0 0
40341- 0 0 0 0 0 0 0 0 0 0 0 0
40342- 0 0 0 0 0 0 0 0 0 0 0 0
40343- 14 14 14 38 38 38 70 70 70 154 122 46
40344-190 142 34 200 144 11 197 138 11 197 138 11
40345-213 154 11 226 170 11 242 186 14 246 190 14
40346-246 190 14 246 190 14 246 190 14 246 190 14
40347-225 175 15 46 32 6 2 2 6 22 22 22
40348-158 158 158 250 250 250 253 253 253 253 253 253
40349-253 253 253 253 253 253 253 253 253 253 253 253
40350-253 253 253 253 253 253 253 253 253 253 253 253
40351-253 253 253 253 253 253 253 253 253 253 253 253
40352-253 253 253 253 253 253 253 253 253 253 253 253
40353-253 253 253 250 250 250 242 242 242 224 178 62
40354-239 182 13 236 186 11 213 154 11 46 32 6
40355- 2 2 6 2 2 6 2 2 6 2 2 6
40356- 2 2 6 2 2 6 61 42 6 225 175 15
40357-238 190 10 236 186 11 112 100 78 42 42 42
40358- 14 14 14 0 0 0 0 0 0 0 0 0
40359- 0 0 0 0 0 0 0 0 0 0 0 0
40360- 0 0 0 0 0 0 0 0 0 0 0 0
40361- 0 0 0 0 0 0 0 0 0 0 0 0
40362- 0 0 0 0 0 0 0 0 0 6 6 6
40363- 22 22 22 54 54 54 154 122 46 213 154 11
40364-226 170 11 230 174 11 226 170 11 226 170 11
40365-236 178 12 242 186 14 246 190 14 246 190 14
40366-246 190 14 246 190 14 246 190 14 246 190 14
40367-241 196 14 184 144 12 10 10 10 2 2 6
40368- 6 6 6 116 116 116 242 242 242 253 253 253
40369-253 253 253 253 253 253 253 253 253 253 253 253
40370-253 253 253 253 253 253 253 253 253 253 253 253
40371-253 253 253 253 253 253 253 253 253 253 253 253
40372-253 253 253 253 253 253 253 253 253 253 253 253
40373-253 253 253 231 231 231 198 198 198 214 170 54
40374-236 178 12 236 178 12 210 150 10 137 92 6
40375- 18 14 6 2 2 6 2 2 6 2 2 6
40376- 6 6 6 70 47 6 200 144 11 236 178 12
40377-239 182 13 239 182 13 124 112 88 58 58 58
40378- 22 22 22 6 6 6 0 0 0 0 0 0
40379- 0 0 0 0 0 0 0 0 0 0 0 0
40380- 0 0 0 0 0 0 0 0 0 0 0 0
40381- 0 0 0 0 0 0 0 0 0 0 0 0
40382- 0 0 0 0 0 0 0 0 0 10 10 10
40383- 30 30 30 70 70 70 180 133 36 226 170 11
40384-239 182 13 242 186 14 242 186 14 246 186 14
40385-246 190 14 246 190 14 246 190 14 246 190 14
40386-246 190 14 246 190 14 246 190 14 246 190 14
40387-246 190 14 232 195 16 98 70 6 2 2 6
40388- 2 2 6 2 2 6 66 66 66 221 221 221
40389-253 253 253 253 253 253 253 253 253 253 253 253
40390-253 253 253 253 253 253 253 253 253 253 253 253
40391-253 253 253 253 253 253 253 253 253 253 253 253
40392-253 253 253 253 253 253 253 253 253 253 253 253
40393-253 253 253 206 206 206 198 198 198 214 166 58
40394-230 174 11 230 174 11 216 158 10 192 133 9
40395-163 110 8 116 81 8 102 78 10 116 81 8
40396-167 114 7 197 138 11 226 170 11 239 182 13
40397-242 186 14 242 186 14 162 146 94 78 78 78
40398- 34 34 34 14 14 14 6 6 6 0 0 0
40399- 0 0 0 0 0 0 0 0 0 0 0 0
40400- 0 0 0 0 0 0 0 0 0 0 0 0
40401- 0 0 0 0 0 0 0 0 0 0 0 0
40402- 0 0 0 0 0 0 0 0 0 6 6 6
40403- 30 30 30 78 78 78 190 142 34 226 170 11
40404-239 182 13 246 190 14 246 190 14 246 190 14
40405-246 190 14 246 190 14 246 190 14 246 190 14
40406-246 190 14 246 190 14 246 190 14 246 190 14
40407-246 190 14 241 196 14 203 166 17 22 18 6
40408- 2 2 6 2 2 6 2 2 6 38 38 38
40409-218 218 218 253 253 253 253 253 253 253 253 253
40410-253 253 253 253 253 253 253 253 253 253 253 253
40411-253 253 253 253 253 253 253 253 253 253 253 253
40412-253 253 253 253 253 253 253 253 253 253 253 253
40413-250 250 250 206 206 206 198 198 198 202 162 69
40414-226 170 11 236 178 12 224 166 10 210 150 10
40415-200 144 11 197 138 11 192 133 9 197 138 11
40416-210 150 10 226 170 11 242 186 14 246 190 14
40417-246 190 14 246 186 14 225 175 15 124 112 88
40418- 62 62 62 30 30 30 14 14 14 6 6 6
40419- 0 0 0 0 0 0 0 0 0 0 0 0
40420- 0 0 0 0 0 0 0 0 0 0 0 0
40421- 0 0 0 0 0 0 0 0 0 0 0 0
40422- 0 0 0 0 0 0 0 0 0 10 10 10
40423- 30 30 30 78 78 78 174 135 50 224 166 10
40424-239 182 13 246 190 14 246 190 14 246 190 14
40425-246 190 14 246 190 14 246 190 14 246 190 14
40426-246 190 14 246 190 14 246 190 14 246 190 14
40427-246 190 14 246 190 14 241 196 14 139 102 15
40428- 2 2 6 2 2 6 2 2 6 2 2 6
40429- 78 78 78 250 250 250 253 253 253 253 253 253
40430-253 253 253 253 253 253 253 253 253 253 253 253
40431-253 253 253 253 253 253 253 253 253 253 253 253
40432-253 253 253 253 253 253 253 253 253 253 253 253
40433-250 250 250 214 214 214 198 198 198 190 150 46
40434-219 162 10 236 178 12 234 174 13 224 166 10
40435-216 158 10 213 154 11 213 154 11 216 158 10
40436-226 170 11 239 182 13 246 190 14 246 190 14
40437-246 190 14 246 190 14 242 186 14 206 162 42
40438-101 101 101 58 58 58 30 30 30 14 14 14
40439- 6 6 6 0 0 0 0 0 0 0 0 0
40440- 0 0 0 0 0 0 0 0 0 0 0 0
40441- 0 0 0 0 0 0 0 0 0 0 0 0
40442- 0 0 0 0 0 0 0 0 0 10 10 10
40443- 30 30 30 74 74 74 174 135 50 216 158 10
40444-236 178 12 246 190 14 246 190 14 246 190 14
40445-246 190 14 246 190 14 246 190 14 246 190 14
40446-246 190 14 246 190 14 246 190 14 246 190 14
40447-246 190 14 246 190 14 241 196 14 226 184 13
40448- 61 42 6 2 2 6 2 2 6 2 2 6
40449- 22 22 22 238 238 238 253 253 253 253 253 253
40450-253 253 253 253 253 253 253 253 253 253 253 253
40451-253 253 253 253 253 253 253 253 253 253 253 253
40452-253 253 253 253 253 253 253 253 253 253 253 253
40453-253 253 253 226 226 226 187 187 187 180 133 36
40454-216 158 10 236 178 12 239 182 13 236 178 12
40455-230 174 11 226 170 11 226 170 11 230 174 11
40456-236 178 12 242 186 14 246 190 14 246 190 14
40457-246 190 14 246 190 14 246 186 14 239 182 13
40458-206 162 42 106 106 106 66 66 66 34 34 34
40459- 14 14 14 6 6 6 0 0 0 0 0 0
40460- 0 0 0 0 0 0 0 0 0 0 0 0
40461- 0 0 0 0 0 0 0 0 0 0 0 0
40462- 0 0 0 0 0 0 0 0 0 6 6 6
40463- 26 26 26 70 70 70 163 133 67 213 154 11
40464-236 178 12 246 190 14 246 190 14 246 190 14
40465-246 190 14 246 190 14 246 190 14 246 190 14
40466-246 190 14 246 190 14 246 190 14 246 190 14
40467-246 190 14 246 190 14 246 190 14 241 196 14
40468-190 146 13 18 14 6 2 2 6 2 2 6
40469- 46 46 46 246 246 246 253 253 253 253 253 253
40470-253 253 253 253 253 253 253 253 253 253 253 253
40471-253 253 253 253 253 253 253 253 253 253 253 253
40472-253 253 253 253 253 253 253 253 253 253 253 253
40473-253 253 253 221 221 221 86 86 86 156 107 11
40474-216 158 10 236 178 12 242 186 14 246 186 14
40475-242 186 14 239 182 13 239 182 13 242 186 14
40476-242 186 14 246 186 14 246 190 14 246 190 14
40477-246 190 14 246 190 14 246 190 14 246 190 14
40478-242 186 14 225 175 15 142 122 72 66 66 66
40479- 30 30 30 10 10 10 0 0 0 0 0 0
40480- 0 0 0 0 0 0 0 0 0 0 0 0
40481- 0 0 0 0 0 0 0 0 0 0 0 0
40482- 0 0 0 0 0 0 0 0 0 6 6 6
40483- 26 26 26 70 70 70 163 133 67 210 150 10
40484-236 178 12 246 190 14 246 190 14 246 190 14
40485-246 190 14 246 190 14 246 190 14 246 190 14
40486-246 190 14 246 190 14 246 190 14 246 190 14
40487-246 190 14 246 190 14 246 190 14 246 190 14
40488-232 195 16 121 92 8 34 34 34 106 106 106
40489-221 221 221 253 253 253 253 253 253 253 253 253
40490-253 253 253 253 253 253 253 253 253 253 253 253
40491-253 253 253 253 253 253 253 253 253 253 253 253
40492-253 253 253 253 253 253 253 253 253 253 253 253
40493-242 242 242 82 82 82 18 14 6 163 110 8
40494-216 158 10 236 178 12 242 186 14 246 190 14
40495-246 190 14 246 190 14 246 190 14 246 190 14
40496-246 190 14 246 190 14 246 190 14 246 190 14
40497-246 190 14 246 190 14 246 190 14 246 190 14
40498-246 190 14 246 190 14 242 186 14 163 133 67
40499- 46 46 46 18 18 18 6 6 6 0 0 0
40500- 0 0 0 0 0 0 0 0 0 0 0 0
40501- 0 0 0 0 0 0 0 0 0 0 0 0
40502- 0 0 0 0 0 0 0 0 0 10 10 10
40503- 30 30 30 78 78 78 163 133 67 210 150 10
40504-236 178 12 246 186 14 246 190 14 246 190 14
40505-246 190 14 246 190 14 246 190 14 246 190 14
40506-246 190 14 246 190 14 246 190 14 246 190 14
40507-246 190 14 246 190 14 246 190 14 246 190 14
40508-241 196 14 215 174 15 190 178 144 253 253 253
40509-253 253 253 253 253 253 253 253 253 253 253 253
40510-253 253 253 253 253 253 253 253 253 253 253 253
40511-253 253 253 253 253 253 253 253 253 253 253 253
40512-253 253 253 253 253 253 253 253 253 218 218 218
40513- 58 58 58 2 2 6 22 18 6 167 114 7
40514-216 158 10 236 178 12 246 186 14 246 190 14
40515-246 190 14 246 190 14 246 190 14 246 190 14
40516-246 190 14 246 190 14 246 190 14 246 190 14
40517-246 190 14 246 190 14 246 190 14 246 190 14
40518-246 190 14 246 186 14 242 186 14 190 150 46
40519- 54 54 54 22 22 22 6 6 6 0 0 0
40520- 0 0 0 0 0 0 0 0 0 0 0 0
40521- 0 0 0 0 0 0 0 0 0 0 0 0
40522- 0 0 0 0 0 0 0 0 0 14 14 14
40523- 38 38 38 86 86 86 180 133 36 213 154 11
40524-236 178 12 246 186 14 246 190 14 246 190 14
40525-246 190 14 246 190 14 246 190 14 246 190 14
40526-246 190 14 246 190 14 246 190 14 246 190 14
40527-246 190 14 246 190 14 246 190 14 246 190 14
40528-246 190 14 232 195 16 190 146 13 214 214 214
40529-253 253 253 253 253 253 253 253 253 253 253 253
40530-253 253 253 253 253 253 253 253 253 253 253 253
40531-253 253 253 253 253 253 253 253 253 253 253 253
40532-253 253 253 250 250 250 170 170 170 26 26 26
40533- 2 2 6 2 2 6 37 26 9 163 110 8
40534-219 162 10 239 182 13 246 186 14 246 190 14
40535-246 190 14 246 190 14 246 190 14 246 190 14
40536-246 190 14 246 190 14 246 190 14 246 190 14
40537-246 190 14 246 190 14 246 190 14 246 190 14
40538-246 186 14 236 178 12 224 166 10 142 122 72
40539- 46 46 46 18 18 18 6 6 6 0 0 0
40540- 0 0 0 0 0 0 0 0 0 0 0 0
40541- 0 0 0 0 0 0 0 0 0 0 0 0
40542- 0 0 0 0 0 0 6 6 6 18 18 18
40543- 50 50 50 109 106 95 192 133 9 224 166 10
40544-242 186 14 246 190 14 246 190 14 246 190 14
40545-246 190 14 246 190 14 246 190 14 246 190 14
40546-246 190 14 246 190 14 246 190 14 246 190 14
40547-246 190 14 246 190 14 246 190 14 246 190 14
40548-242 186 14 226 184 13 210 162 10 142 110 46
40549-226 226 226 253 253 253 253 253 253 253 253 253
40550-253 253 253 253 253 253 253 253 253 253 253 253
40551-253 253 253 253 253 253 253 253 253 253 253 253
40552-198 198 198 66 66 66 2 2 6 2 2 6
40553- 2 2 6 2 2 6 50 34 6 156 107 11
40554-219 162 10 239 182 13 246 186 14 246 190 14
40555-246 190 14 246 190 14 246 190 14 246 190 14
40556-246 190 14 246 190 14 246 190 14 246 190 14
40557-246 190 14 246 190 14 246 190 14 242 186 14
40558-234 174 13 213 154 11 154 122 46 66 66 66
40559- 30 30 30 10 10 10 0 0 0 0 0 0
40560- 0 0 0 0 0 0 0 0 0 0 0 0
40561- 0 0 0 0 0 0 0 0 0 0 0 0
40562- 0 0 0 0 0 0 6 6 6 22 22 22
40563- 58 58 58 154 121 60 206 145 10 234 174 13
40564-242 186 14 246 186 14 246 190 14 246 190 14
40565-246 190 14 246 190 14 246 190 14 246 190 14
40566-246 190 14 246 190 14 246 190 14 246 190 14
40567-246 190 14 246 190 14 246 190 14 246 190 14
40568-246 186 14 236 178 12 210 162 10 163 110 8
40569- 61 42 6 138 138 138 218 218 218 250 250 250
40570-253 253 253 253 253 253 253 253 253 250 250 250
40571-242 242 242 210 210 210 144 144 144 66 66 66
40572- 6 6 6 2 2 6 2 2 6 2 2 6
40573- 2 2 6 2 2 6 61 42 6 163 110 8
40574-216 158 10 236 178 12 246 190 14 246 190 14
40575-246 190 14 246 190 14 246 190 14 246 190 14
40576-246 190 14 246 190 14 246 190 14 246 190 14
40577-246 190 14 239 182 13 230 174 11 216 158 10
40578-190 142 34 124 112 88 70 70 70 38 38 38
40579- 18 18 18 6 6 6 0 0 0 0 0 0
40580- 0 0 0 0 0 0 0 0 0 0 0 0
40581- 0 0 0 0 0 0 0 0 0 0 0 0
40582- 0 0 0 0 0 0 6 6 6 22 22 22
40583- 62 62 62 168 124 44 206 145 10 224 166 10
40584-236 178 12 239 182 13 242 186 14 242 186 14
40585-246 186 14 246 190 14 246 190 14 246 190 14
40586-246 190 14 246 190 14 246 190 14 246 190 14
40587-246 190 14 246 190 14 246 190 14 246 190 14
40588-246 190 14 236 178 12 216 158 10 175 118 6
40589- 80 54 7 2 2 6 6 6 6 30 30 30
40590- 54 54 54 62 62 62 50 50 50 38 38 38
40591- 14 14 14 2 2 6 2 2 6 2 2 6
40592- 2 2 6 2 2 6 2 2 6 2 2 6
40593- 2 2 6 6 6 6 80 54 7 167 114 7
40594-213 154 11 236 178 12 246 190 14 246 190 14
40595-246 190 14 246 190 14 246 190 14 246 190 14
40596-246 190 14 242 186 14 239 182 13 239 182 13
40597-230 174 11 210 150 10 174 135 50 124 112 88
40598- 82 82 82 54 54 54 34 34 34 18 18 18
40599- 6 6 6 0 0 0 0 0 0 0 0 0
40600- 0 0 0 0 0 0 0 0 0 0 0 0
40601- 0 0 0 0 0 0 0 0 0 0 0 0
40602- 0 0 0 0 0 0 6 6 6 18 18 18
40603- 50 50 50 158 118 36 192 133 9 200 144 11
40604-216 158 10 219 162 10 224 166 10 226 170 11
40605-230 174 11 236 178 12 239 182 13 239 182 13
40606-242 186 14 246 186 14 246 190 14 246 190 14
40607-246 190 14 246 190 14 246 190 14 246 190 14
40608-246 186 14 230 174 11 210 150 10 163 110 8
40609-104 69 6 10 10 10 2 2 6 2 2 6
40610- 2 2 6 2 2 6 2 2 6 2 2 6
40611- 2 2 6 2 2 6 2 2 6 2 2 6
40612- 2 2 6 2 2 6 2 2 6 2 2 6
40613- 2 2 6 6 6 6 91 60 6 167 114 7
40614-206 145 10 230 174 11 242 186 14 246 190 14
40615-246 190 14 246 190 14 246 186 14 242 186 14
40616-239 182 13 230 174 11 224 166 10 213 154 11
40617-180 133 36 124 112 88 86 86 86 58 58 58
40618- 38 38 38 22 22 22 10 10 10 6 6 6
40619- 0 0 0 0 0 0 0 0 0 0 0 0
40620- 0 0 0 0 0 0 0 0 0 0 0 0
40621- 0 0 0 0 0 0 0 0 0 0 0 0
40622- 0 0 0 0 0 0 0 0 0 14 14 14
40623- 34 34 34 70 70 70 138 110 50 158 118 36
40624-167 114 7 180 123 7 192 133 9 197 138 11
40625-200 144 11 206 145 10 213 154 11 219 162 10
40626-224 166 10 230 174 11 239 182 13 242 186 14
40627-246 186 14 246 186 14 246 186 14 246 186 14
40628-239 182 13 216 158 10 185 133 11 152 99 6
40629-104 69 6 18 14 6 2 2 6 2 2 6
40630- 2 2 6 2 2 6 2 2 6 2 2 6
40631- 2 2 6 2 2 6 2 2 6 2 2 6
40632- 2 2 6 2 2 6 2 2 6 2 2 6
40633- 2 2 6 6 6 6 80 54 7 152 99 6
40634-192 133 9 219 162 10 236 178 12 239 182 13
40635-246 186 14 242 186 14 239 182 13 236 178 12
40636-224 166 10 206 145 10 192 133 9 154 121 60
40637- 94 94 94 62 62 62 42 42 42 22 22 22
40638- 14 14 14 6 6 6 0 0 0 0 0 0
40639- 0 0 0 0 0 0 0 0 0 0 0 0
40640- 0 0 0 0 0 0 0 0 0 0 0 0
40641- 0 0 0 0 0 0 0 0 0 0 0 0
40642- 0 0 0 0 0 0 0 0 0 6 6 6
40643- 18 18 18 34 34 34 58 58 58 78 78 78
40644-101 98 89 124 112 88 142 110 46 156 107 11
40645-163 110 8 167 114 7 175 118 6 180 123 7
40646-185 133 11 197 138 11 210 150 10 219 162 10
40647-226 170 11 236 178 12 236 178 12 234 174 13
40648-219 162 10 197 138 11 163 110 8 130 83 6
40649- 91 60 6 10 10 10 2 2 6 2 2 6
40650- 18 18 18 38 38 38 38 38 38 38 38 38
40651- 38 38 38 38 38 38 38 38 38 38 38 38
40652- 38 38 38 38 38 38 26 26 26 2 2 6
40653- 2 2 6 6 6 6 70 47 6 137 92 6
40654-175 118 6 200 144 11 219 162 10 230 174 11
40655-234 174 13 230 174 11 219 162 10 210 150 10
40656-192 133 9 163 110 8 124 112 88 82 82 82
40657- 50 50 50 30 30 30 14 14 14 6 6 6
40658- 0 0 0 0 0 0 0 0 0 0 0 0
40659- 0 0 0 0 0 0 0 0 0 0 0 0
40660- 0 0 0 0 0 0 0 0 0 0 0 0
40661- 0 0 0 0 0 0 0 0 0 0 0 0
40662- 0 0 0 0 0 0 0 0 0 0 0 0
40663- 6 6 6 14 14 14 22 22 22 34 34 34
40664- 42 42 42 58 58 58 74 74 74 86 86 86
40665-101 98 89 122 102 70 130 98 46 121 87 25
40666-137 92 6 152 99 6 163 110 8 180 123 7
40667-185 133 11 197 138 11 206 145 10 200 144 11
40668-180 123 7 156 107 11 130 83 6 104 69 6
40669- 50 34 6 54 54 54 110 110 110 101 98 89
40670- 86 86 86 82 82 82 78 78 78 78 78 78
40671- 78 78 78 78 78 78 78 78 78 78 78 78
40672- 78 78 78 82 82 82 86 86 86 94 94 94
40673-106 106 106 101 101 101 86 66 34 124 80 6
40674-156 107 11 180 123 7 192 133 9 200 144 11
40675-206 145 10 200 144 11 192 133 9 175 118 6
40676-139 102 15 109 106 95 70 70 70 42 42 42
40677- 22 22 22 10 10 10 0 0 0 0 0 0
40678- 0 0 0 0 0 0 0 0 0 0 0 0
40679- 0 0 0 0 0 0 0 0 0 0 0 0
40680- 0 0 0 0 0 0 0 0 0 0 0 0
40681- 0 0 0 0 0 0 0 0 0 0 0 0
40682- 0 0 0 0 0 0 0 0 0 0 0 0
40683- 0 0 0 0 0 0 6 6 6 10 10 10
40684- 14 14 14 22 22 22 30 30 30 38 38 38
40685- 50 50 50 62 62 62 74 74 74 90 90 90
40686-101 98 89 112 100 78 121 87 25 124 80 6
40687-137 92 6 152 99 6 152 99 6 152 99 6
40688-138 86 6 124 80 6 98 70 6 86 66 30
40689-101 98 89 82 82 82 58 58 58 46 46 46
40690- 38 38 38 34 34 34 34 34 34 34 34 34
40691- 34 34 34 34 34 34 34 34 34 34 34 34
40692- 34 34 34 34 34 34 38 38 38 42 42 42
40693- 54 54 54 82 82 82 94 86 76 91 60 6
40694-134 86 6 156 107 11 167 114 7 175 118 6
40695-175 118 6 167 114 7 152 99 6 121 87 25
40696-101 98 89 62 62 62 34 34 34 18 18 18
40697- 6 6 6 0 0 0 0 0 0 0 0 0
40698- 0 0 0 0 0 0 0 0 0 0 0 0
40699- 0 0 0 0 0 0 0 0 0 0 0 0
40700- 0 0 0 0 0 0 0 0 0 0 0 0
40701- 0 0 0 0 0 0 0 0 0 0 0 0
40702- 0 0 0 0 0 0 0 0 0 0 0 0
40703- 0 0 0 0 0 0 0 0 0 0 0 0
40704- 0 0 0 6 6 6 6 6 6 10 10 10
40705- 18 18 18 22 22 22 30 30 30 42 42 42
40706- 50 50 50 66 66 66 86 86 86 101 98 89
40707-106 86 58 98 70 6 104 69 6 104 69 6
40708-104 69 6 91 60 6 82 62 34 90 90 90
40709- 62 62 62 38 38 38 22 22 22 14 14 14
40710- 10 10 10 10 10 10 10 10 10 10 10 10
40711- 10 10 10 10 10 10 6 6 6 10 10 10
40712- 10 10 10 10 10 10 10 10 10 14 14 14
40713- 22 22 22 42 42 42 70 70 70 89 81 66
40714- 80 54 7 104 69 6 124 80 6 137 92 6
40715-134 86 6 116 81 8 100 82 52 86 86 86
40716- 58 58 58 30 30 30 14 14 14 6 6 6
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- 0 0 0 0 0 0 0 0 0 0 0 0
40721- 0 0 0 0 0 0 0 0 0 0 0 0
40722- 0 0 0 0 0 0 0 0 0 0 0 0
40723- 0 0 0 0 0 0 0 0 0 0 0 0
40724- 0 0 0 0 0 0 0 0 0 0 0 0
40725- 0 0 0 6 6 6 10 10 10 14 14 14
40726- 18 18 18 26 26 26 38 38 38 54 54 54
40727- 70 70 70 86 86 86 94 86 76 89 81 66
40728- 89 81 66 86 86 86 74 74 74 50 50 50
40729- 30 30 30 14 14 14 6 6 6 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 18 18 18 34 34 34 58 58 58
40734- 82 82 82 89 81 66 89 81 66 89 81 66
40735- 94 86 66 94 86 76 74 74 74 50 50 50
40736- 26 26 26 14 14 14 6 6 6 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 0 0 0 0 0 0 0 0 0
40741- 0 0 0 0 0 0 0 0 0 0 0 0
40742- 0 0 0 0 0 0 0 0 0 0 0 0
40743- 0 0 0 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- 6 6 6 6 6 6 14 14 14 18 18 18
40747- 30 30 30 38 38 38 46 46 46 54 54 54
40748- 50 50 50 42 42 42 30 30 30 18 18 18
40749- 10 10 10 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 6 6 6 14 14 14 26 26 26
40754- 38 38 38 50 50 50 58 58 58 58 58 58
40755- 54 54 54 42 42 42 30 30 30 18 18 18
40756- 10 10 10 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 0 0 0
40761- 0 0 0 0 0 0 0 0 0 0 0 0
40762- 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6
40767- 6 6 6 10 10 10 14 14 14 18 18 18
40768- 18 18 18 14 14 14 10 10 10 6 6 6
40769- 0 0 0 0 0 0 0 0 0 0 0 0
40770- 0 0 0 0 0 0 0 0 0 0 0 0
40771- 0 0 0 0 0 0 0 0 0 0 0 0
40772- 0 0 0 0 0 0 0 0 0 0 0 0
40773- 0 0 0 0 0 0 0 0 0 6 6 6
40774- 14 14 14 18 18 18 22 22 22 22 22 22
40775- 18 18 18 14 14 14 10 10 10 6 6 6
40776- 0 0 0 0 0 0 0 0 0 0 0 0
40777- 0 0 0 0 0 0 0 0 0 0 0 0
40778- 0 0 0 0 0 0 0 0 0 0 0 0
40779- 0 0 0 0 0 0 0 0 0 0 0 0
40780- 0 0 0 0 0 0 0 0 0 0 0 0
40781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40786+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40787+4 4 4 4 4 4 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
40795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40798+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40799+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40800+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40801+4 4 4 4 4 4 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
40809+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40811+4 4 4 4 4 4 4 4 4 4 4 4 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
40823+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40825+4 4 4 4 4 4 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
40837+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40838+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40839+4 4 4 4 4 4 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
40851+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40852+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
40857+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40858+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40859+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40860+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40862+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40863+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40864+4 4 4 4 4 4
40865+4 4 4 4 4 4 4 4 4 4 4 4 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 3 3 3 0 0 0 0 0 0
40870+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
40871+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40872+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40873+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40874+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
40875+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40876+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
40877+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40878+4 4 4 4 4 4
40879+4 4 4 4 4 4 4 4 4 4 4 4 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 2 2 2 0 0 0 3 4 3 26 28 28
40884+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
40885+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40886+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40887+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40888+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
40889+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
40890+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
40891+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40892+4 4 4 4 4 4
40893+4 4 4 4 4 4 4 4 4 4 4 4 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+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
40898+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
40899+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40900+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40901+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40902+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
40903+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
40904+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
40905+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
40906+4 4 4 4 4 4
40907+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40908+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40909+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40910+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
40911+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
40912+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
40913+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
40914+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40915+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40916+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
40917+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
40918+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
40919+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
40920+4 4 4 4 4 4
40921+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40922+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40923+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40924+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
40925+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
40926+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
40927+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
40928+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40929+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
40930+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
40931+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
40932+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
40933+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
40934+4 4 4 4 4 4
40935+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40936+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40937+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40938+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
40939+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
40940+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
40941+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
40942+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
40943+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
40944+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
40945+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
40946+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
40947+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
40948+4 4 4 4 4 4
40949+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40950+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40951+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
40952+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
40953+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
40954+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
40955+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
40956+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
40957+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
40958+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
40959+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
40960+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
40961+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
40962+4 4 4 4 4 4
40963+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40964+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40965+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
40966+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
40967+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
40968+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
40969+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
40970+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
40971+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
40972+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
40973+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
40974+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
40975+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
40976+4 4 4 4 4 4
40977+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40978+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40979+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
40980+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
40981+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
40982+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
40983+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
40984+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
40985+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
40986+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
40987+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
40988+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
40989+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40990+4 4 4 4 4 4
40991+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40992+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40993+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
40994+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
40995+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
40996+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
40997+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
40998+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
40999+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
41000+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
41001+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
41002+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
41003+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
41004+4 4 4 4 4 4
41005+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41006+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
41007+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
41008+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
41009+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
41010+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
41011+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
41012+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
41013+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
41014+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
41015+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
41016+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
41017+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
41018+4 4 4 4 4 4
41019+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41020+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
41021+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
41022+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
41023+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41024+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
41025+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
41026+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
41027+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
41028+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
41029+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
41030+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
41031+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
41032+0 0 0 4 4 4
41033+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41034+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
41035+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
41036+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
41037+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
41038+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
41039+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
41040+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
41041+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
41042+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
41043+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
41044+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
41045+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
41046+2 0 0 0 0 0
41047+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
41048+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
41049+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
41050+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
41051+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
41052+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
41053+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
41054+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
41055+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
41056+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
41057+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
41058+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
41059+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
41060+37 38 37 0 0 0
41061+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41062+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
41063+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
41064+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
41065+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
41066+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
41067+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
41068+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
41069+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
41070+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
41071+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
41072+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
41073+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
41074+85 115 134 4 0 0
41075+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
41076+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
41077+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
41078+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
41079+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
41080+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
41081+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
41082+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
41083+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
41084+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
41085+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
41086+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
41087+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
41088+60 73 81 4 0 0
41089+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
41090+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
41091+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
41092+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
41093+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
41094+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41095+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41096+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41097+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41098+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41099+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41100+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41101+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41102+16 19 21 4 0 0
41103+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41104+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41105+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41106+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41107+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41108+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41109+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41110+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41111+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41112+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41113+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41114+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41115+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41116+4 0 0 4 3 3
41117+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41118+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41119+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41120+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41121+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41122+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41123+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41124+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41125+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41126+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41127+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41128+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41129+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41130+3 2 2 4 4 4
41131+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41132+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41133+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41134+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41135+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41136+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41137+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41138+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41139+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41140+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41141+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41142+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41143+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41144+4 4 4 4 4 4
41145+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41146+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41147+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41148+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41149+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41150+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41151+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41152+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41153+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41154+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41155+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41156+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41157+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41158+4 4 4 4 4 4
41159+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41160+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41161+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41162+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41163+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41164+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41165+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41166+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41167+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41168+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41169+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41170+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41171+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41172+5 5 5 5 5 5
41173+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41174+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41175+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41176+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41177+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41178+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41179+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41180+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41181+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41182+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41183+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41184+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41185+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41186+5 5 5 4 4 4
41187+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41188+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41189+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41190+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41191+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41192+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41193+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41194+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41195+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41196+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41197+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41198+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41199+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41200+4 4 4 4 4 4
41201+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41202+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41203+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41204+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41205+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41206+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41207+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41208+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41209+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41210+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41211+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41212+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 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
41215+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
41216+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41217+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41218+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41219+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41220+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41221+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41222+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41223+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41224+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41225+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
41226+4 4 4 4 4 4 4 4 4 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
41229+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41230+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41231+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41232+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41233+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41234+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41235+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41236+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41237+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41238+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41239+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
41240+4 4 4 4 4 4 4 4 4 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
41243+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41244+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41245+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41246+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41247+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41248+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41249+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41250+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41251+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41252+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41253+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41254+4 4 4 4 4 4 4 4 4 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
41257+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41258+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
41259+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
41260+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
41261+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41262+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
41263+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
41264+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
41265+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
41266+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
41267+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
41268+4 4 4 4 4 4 4 4 4 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
41271+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
41272+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
41273+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
41274+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
41275+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41276+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
41277+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
41278+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
41279+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
41280+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
41281+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
41282+4 4 4 4 4 4 4 4 4 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
41285+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
41286+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
41287+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
41288+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41289+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
41290+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
41291+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
41292+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
41293+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
41294+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
41295+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41296+4 4 4 4 4 4 4 4 4 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
41299+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
41300+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
41301+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
41302+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41303+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41304+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
41305+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
41306+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
41307+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
41308+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
41309+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41310+4 4 4 4 4 4 4 4 4 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
41313+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
41314+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
41315+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41316+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41317+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41318+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
41319+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
41320+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
41321+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
41322+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
41323+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41324+4 4 4 4 4 4 4 4 4 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
41327+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41328+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41329+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41330+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41331+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41332+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41333+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41334+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41335+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41336+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41337+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41338+4 4 4 4 4 4 4 4 4 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
41341+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41342+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41343+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41344+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41345+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41346+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41347+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41348+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41349+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41350+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41351+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41352+4 4 4 4 4 4 4 4 4 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
41355+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41356+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41357+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41358+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41359+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41360+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41361+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41362+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41363+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41364+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41365+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41366+4 4 4 4 4 4 4 4 4 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
41369+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41370+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41371+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41372+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41373+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41374+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41375+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41376+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41377+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41378+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41379+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41380+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41381+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41382+4 4 4 4 4 4
41383+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41384+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41385+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41386+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41387+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41388+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41389+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41390+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41391+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41392+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41393+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41394+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41395+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41396+4 4 4 4 4 4
41397+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41398+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41399+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41400+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41401+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41402+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41403+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41404+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41405+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41406+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41407+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41408+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41409+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41410+4 4 4 4 4 4
41411+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41412+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41413+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41414+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41415+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41416+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41417+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41418+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41419+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41420+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41421+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41422+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41423+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41424+4 4 4 4 4 4
41425+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41426+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41427+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41428+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41429+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41430+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41431+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41432+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41433+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41434+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41435+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41436+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41437+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41438+4 4 4 4 4 4
41439+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41440+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41441+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41442+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41443+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41444+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41445+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41446+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41447+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41448+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41449+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41450+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41451+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41452+4 4 4 4 4 4
41453+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41454+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41455+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41456+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41457+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41458+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41459+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41460+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41461+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41462+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41463+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41464+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41465+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41466+4 4 4 4 4 4
41467+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41468+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41469+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41470+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41471+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41472+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41473+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41474+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41475+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41476+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41477+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41478+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41479+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41480+4 4 4 4 4 4
41481+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41482+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41483+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41484+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41485+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41486+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41487+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41488+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41489+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41490+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41491+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41492+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41493+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41494+4 4 4 4 4 4
41495+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41496+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41497+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41498+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41499+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41500+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41501+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41502+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41503+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41504+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41505+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41506+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41507+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41508+4 4 4 4 4 4
41509+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
41510+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
41511+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
41512+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
41513+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41514+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
41515+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
41516+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
41517+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
41518+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41519+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41520+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41521+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41522+4 4 4 4 4 4
41523+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41524+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
41525+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
41526+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
41527+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
41528+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
41529+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
41530+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
41531+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
41532+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41533+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41534+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41535+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41536+4 4 4 4 4 4
41537+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
41538+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
41539+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
41540+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
41541+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
41542+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
41543+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
41544+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
41545+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
41546+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
41547+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41548+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41549+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41550+4 4 4 4 4 4
41551+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
41552+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41553+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
41554+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
41555+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
41556+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
41557+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
41558+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
41559+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
41560+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
41561+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41562+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41563+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41564+4 4 4 4 4 4
41565+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
41566+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41567+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
41568+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
41569+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
41570+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
41571+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41572+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
41573+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
41574+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
41575+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41576+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41577+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41578+4 4 4 4 4 4
41579+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
41580+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
41581+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
41582+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
41583+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
41584+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
41585+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
41586+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
41587+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
41588+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
41589+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41590+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41591+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41592+4 4 4 4 4 4
41593+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
41594+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
41595+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41596+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
41597+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
41598+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
41599+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
41600+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
41601+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
41602+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
41603+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41604+4 4 4 4 4 4 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
41607+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41608+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
41609+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
41610+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
41611+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
41612+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
41613+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
41614+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
41615+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
41616+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41617+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41618+4 4 4 4 4 4 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
41621+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
41622+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
41623+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
41624+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
41625+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
41626+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
41627+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
41628+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
41629+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
41630+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41631+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41632+4 4 4 4 4 4 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
41635+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
41636+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
41637+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
41638+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
41639+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
41640+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
41641+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
41642+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
41643+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41644+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41645+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41646+4 4 4 4 4 4 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
41649+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
41650+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41651+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
41652+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41653+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
41654+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
41655+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
41656+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
41657+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
41658+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41659+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41660+4 4 4 4 4 4 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
41663+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
41664+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
41665+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
41666+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
41667+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
41668+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
41669+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
41670+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
41671+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
41672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41674+4 4 4 4 4 4 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
41677+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41678+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
41679+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
41680+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
41681+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
41682+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
41683+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
41684+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
41685+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41688+4 4 4 4 4 4 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
41691+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
41692+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
41693+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41694+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
41695+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
41696+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
41697+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
41698+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
41699+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41702+4 4 4 4 4 4 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
41705+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41706+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
41707+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
41708+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
41709+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
41710+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
41711+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
41712+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41713+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41715+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41716+4 4 4 4 4 4 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
41719+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41720+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
41721+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41722+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
41723+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
41724+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
41725+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
41726+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
41727+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41730+4 4 4 4 4 4 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
41733+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41734+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
41735+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
41736+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
41737+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
41738+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
41739+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
41740+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
41741+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41743+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41744+4 4 4 4 4 4 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
41747+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41748+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41749+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
41750+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41751+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
41752+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
41753+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
41754+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41755+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41757+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41758+4 4 4 4 4 4 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
41761+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41762+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41763+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41764+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
41765+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
41766+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
41767+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
41768+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41772+4 4 4 4 4 4 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
41775+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41778+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41779+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
41780+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
41781+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
41782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41786+4 4 4 4 4 4 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
41789+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41792+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41793+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41794+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
41795+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
41796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41798+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41799+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41800+4 4 4 4 4 4 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
41803+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41804+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41806+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41807+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41808+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41809+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
41810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41811+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41812+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41813+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41814+4 4 4 4 4 4 4 4 4 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
41817+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41818+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41820+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
41821+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
41822+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
41823+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
41824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41825+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41826+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41827+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41828+4 4 4 4 4 4 4 4 4 4 4 4 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
41831+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41834+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41835+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
41836+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41837+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41838+4 4 4 4 4 4 4 4 4 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
41845+4 4 4 4 4 4 4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
41850+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
41851+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41852+4 4 4 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
41859+4 4 4 4 4 4 4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
41864+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
41865+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
41873+4 4 4 4 4 4 4 4 4 4 4 4 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 5 5 5 4 3 3 6 6 6
41878+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
41879+4 4 4 4 4 4 4 4 4 4 4 4 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
41887+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41888+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41889+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41890+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41891+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41892+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
41893+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41894+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41895+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41896+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41897+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41898+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41899+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41900+4 4 4 4 4 4
41901diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
41902index 8af6414..658c030 100644
41903--- a/drivers/video/udlfb.c
41904+++ b/drivers/video/udlfb.c
41905@@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
41906 dlfb_urb_completion(urb);
41907
41908 error:
41909- atomic_add(bytes_sent, &dev->bytes_sent);
41910- atomic_add(bytes_identical, &dev->bytes_identical);
41911- atomic_add(width*height*2, &dev->bytes_rendered);
41912+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41913+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41914+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
41915 end_cycles = get_cycles();
41916- atomic_add(((unsigned int) ((end_cycles - start_cycles)
41917+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41918 >> 10)), /* Kcycles */
41919 &dev->cpu_kcycles_used);
41920
41921@@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
41922 dlfb_urb_completion(urb);
41923
41924 error:
41925- atomic_add(bytes_sent, &dev->bytes_sent);
41926- atomic_add(bytes_identical, &dev->bytes_identical);
41927- atomic_add(bytes_rendered, &dev->bytes_rendered);
41928+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41929+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41930+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
41931 end_cycles = get_cycles();
41932- atomic_add(((unsigned int) ((end_cycles - start_cycles)
41933+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41934 >> 10)), /* Kcycles */
41935 &dev->cpu_kcycles_used);
41936 }
41937@@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
41938 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41939 struct dlfb_data *dev = fb_info->par;
41940 return snprintf(buf, PAGE_SIZE, "%u\n",
41941- atomic_read(&dev->bytes_rendered));
41942+ atomic_read_unchecked(&dev->bytes_rendered));
41943 }
41944
41945 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41946@@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41947 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41948 struct dlfb_data *dev = fb_info->par;
41949 return snprintf(buf, PAGE_SIZE, "%u\n",
41950- atomic_read(&dev->bytes_identical));
41951+ atomic_read_unchecked(&dev->bytes_identical));
41952 }
41953
41954 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41955@@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41956 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41957 struct dlfb_data *dev = fb_info->par;
41958 return snprintf(buf, PAGE_SIZE, "%u\n",
41959- atomic_read(&dev->bytes_sent));
41960+ atomic_read_unchecked(&dev->bytes_sent));
41961 }
41962
41963 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41964@@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41965 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41966 struct dlfb_data *dev = fb_info->par;
41967 return snprintf(buf, PAGE_SIZE, "%u\n",
41968- atomic_read(&dev->cpu_kcycles_used));
41969+ atomic_read_unchecked(&dev->cpu_kcycles_used));
41970 }
41971
41972 static ssize_t edid_show(
41973@@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
41974 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41975 struct dlfb_data *dev = fb_info->par;
41976
41977- atomic_set(&dev->bytes_rendered, 0);
41978- atomic_set(&dev->bytes_identical, 0);
41979- atomic_set(&dev->bytes_sent, 0);
41980- atomic_set(&dev->cpu_kcycles_used, 0);
41981+ atomic_set_unchecked(&dev->bytes_rendered, 0);
41982+ atomic_set_unchecked(&dev->bytes_identical, 0);
41983+ atomic_set_unchecked(&dev->bytes_sent, 0);
41984+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
41985
41986 return count;
41987 }
41988diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
41989index b0e2a42..e2df3ad 100644
41990--- a/drivers/video/uvesafb.c
41991+++ b/drivers/video/uvesafb.c
41992@@ -19,6 +19,7 @@
41993 #include <linux/io.h>
41994 #include <linux/mutex.h>
41995 #include <linux/slab.h>
41996+#include <linux/moduleloader.h>
41997 #include <video/edid.h>
41998 #include <video/uvesafb.h>
41999 #ifdef CONFIG_X86
42000@@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
42001 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
42002 par->pmi_setpal = par->ypan = 0;
42003 } else {
42004+
42005+#ifdef CONFIG_PAX_KERNEXEC
42006+#ifdef CONFIG_MODULES
42007+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
42008+#endif
42009+ if (!par->pmi_code) {
42010+ par->pmi_setpal = par->ypan = 0;
42011+ return 0;
42012+ }
42013+#endif
42014+
42015 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
42016 + task->t.regs.edi);
42017+
42018+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42019+ pax_open_kernel();
42020+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
42021+ pax_close_kernel();
42022+
42023+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
42024+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
42025+#else
42026 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
42027 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
42028+#endif
42029+
42030 printk(KERN_INFO "uvesafb: protected mode interface info at "
42031 "%04x:%04x\n",
42032 (u16)task->t.regs.es, (u16)task->t.regs.edi);
42033@@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
42034 par->ypan = ypan;
42035
42036 if (par->pmi_setpal || par->ypan) {
42037+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
42038 if (__supported_pte_mask & _PAGE_NX) {
42039 par->pmi_setpal = par->ypan = 0;
42040 printk(KERN_WARNING "uvesafb: NX protection is actively."
42041 "We have better not to use the PMI.\n");
42042- } else {
42043+ } else
42044+#endif
42045 uvesafb_vbe_getpmi(task, par);
42046- }
42047 }
42048 #else
42049 /* The protected mode interface is not available on non-x86. */
42050@@ -1836,6 +1860,11 @@ out:
42051 if (par->vbe_modes)
42052 kfree(par->vbe_modes);
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 framebuffer_release(info);
42060 return err;
42061 }
42062@@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
42063 kfree(par->vbe_state_orig);
42064 if (par->vbe_state_saved)
42065 kfree(par->vbe_state_saved);
42066+
42067+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42068+ if (par->pmi_code)
42069+ module_free_exec(NULL, par->pmi_code);
42070+#endif
42071+
42072 }
42073
42074 framebuffer_release(info);
42075diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
42076index 501b340..86bd4cf 100644
42077--- a/drivers/video/vesafb.c
42078+++ b/drivers/video/vesafb.c
42079@@ -9,6 +9,7 @@
42080 */
42081
42082 #include <linux/module.h>
42083+#include <linux/moduleloader.h>
42084 #include <linux/kernel.h>
42085 #include <linux/errno.h>
42086 #include <linux/string.h>
42087@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
42088 static int vram_total __initdata; /* Set total amount of memory */
42089 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
42090 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
42091-static void (*pmi_start)(void) __read_mostly;
42092-static void (*pmi_pal) (void) __read_mostly;
42093+static void (*pmi_start)(void) __read_only;
42094+static void (*pmi_pal) (void) __read_only;
42095 static int depth __read_mostly;
42096 static int vga_compat __read_mostly;
42097 /* --------------------------------------------------------------------- */
42098@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
42099 unsigned int size_vmode;
42100 unsigned int size_remap;
42101 unsigned int size_total;
42102+ void *pmi_code = NULL;
42103
42104 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42105 return -ENODEV;
42106@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
42107 size_remap = size_total;
42108 vesafb_fix.smem_len = size_remap;
42109
42110-#ifndef __i386__
42111- screen_info.vesapm_seg = 0;
42112-#endif
42113-
42114 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42115 printk(KERN_WARNING
42116 "vesafb: cannot reserve video memory at 0x%lx\n",
42117@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42118 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42119 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42120
42121+#ifdef __i386__
42122+
42123+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42124+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
42125+ if (!pmi_code)
42126+#elif !defined(CONFIG_PAX_KERNEXEC)
42127+ if (0)
42128+#endif
42129+
42130+#endif
42131+ screen_info.vesapm_seg = 0;
42132+
42133 if (screen_info.vesapm_seg) {
42134- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42135- screen_info.vesapm_seg,screen_info.vesapm_off);
42136+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42137+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42138 }
42139
42140 if (screen_info.vesapm_seg < 0xc000)
42141@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42142
42143 if (ypan || pmi_setpal) {
42144 unsigned short *pmi_base;
42145+
42146 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42147- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42148- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42149+
42150+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42151+ pax_open_kernel();
42152+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42153+#else
42154+ pmi_code = pmi_base;
42155+#endif
42156+
42157+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42158+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42159+
42160+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42161+ pmi_start = ktva_ktla(pmi_start);
42162+ pmi_pal = ktva_ktla(pmi_pal);
42163+ pax_close_kernel();
42164+#endif
42165+
42166 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42167 if (pmi_base[3]) {
42168 printk(KERN_INFO "vesafb: pmi: ports = ");
42169@@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42170 info->node, info->fix.id);
42171 return 0;
42172 err:
42173+
42174+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42175+ module_free_exec(NULL, pmi_code);
42176+#endif
42177+
42178 if (info->screen_base)
42179 iounmap(info->screen_base);
42180 framebuffer_release(info);
42181diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42182index 88714ae..16c2e11 100644
42183--- a/drivers/video/via/via_clock.h
42184+++ b/drivers/video/via/via_clock.h
42185@@ -56,7 +56,7 @@ struct via_clock {
42186
42187 void (*set_engine_pll_state)(u8 state);
42188 void (*set_engine_pll)(struct via_pll_config config);
42189-};
42190+} __no_const;
42191
42192
42193 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42194diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
42195index e56c934..fc22f4b 100644
42196--- a/drivers/xen/xen-pciback/conf_space.h
42197+++ b/drivers/xen/xen-pciback/conf_space.h
42198@@ -44,15 +44,15 @@ struct config_field {
42199 struct {
42200 conf_dword_write write;
42201 conf_dword_read read;
42202- } dw;
42203+ } __no_const dw;
42204 struct {
42205 conf_word_write write;
42206 conf_word_read read;
42207- } w;
42208+ } __no_const w;
42209 struct {
42210 conf_byte_write write;
42211 conf_byte_read read;
42212- } b;
42213+ } __no_const b;
42214 } u;
42215 struct list_head list;
42216 };
42217diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
42218index 57ccb75..f6d05f8 100644
42219--- a/fs/9p/vfs_inode.c
42220+++ b/fs/9p/vfs_inode.c
42221@@ -1303,7 +1303,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42222 void
42223 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42224 {
42225- char *s = nd_get_link(nd);
42226+ const char *s = nd_get_link(nd);
42227
42228 p9_debug(P9_DEBUG_VFS, " %s %s\n",
42229 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
42230diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
42231index 0225742..1cd4732 100644
42232--- a/fs/Kconfig.binfmt
42233+++ b/fs/Kconfig.binfmt
42234@@ -89,7 +89,7 @@ config HAVE_AOUT
42235
42236 config BINFMT_AOUT
42237 tristate "Kernel support for a.out and ECOFF binaries"
42238- depends on HAVE_AOUT
42239+ depends on HAVE_AOUT && BROKEN
42240 ---help---
42241 A.out (Assembler.OUTput) is a set of formats for libraries and
42242 executables used in the earliest versions of UNIX. Linux used
42243diff --git a/fs/aio.c b/fs/aio.c
42244index 55c4c76..11aee6f 100644
42245--- a/fs/aio.c
42246+++ b/fs/aio.c
42247@@ -118,7 +118,7 @@ static int aio_setup_ring(struct kioctx *ctx)
42248 size += sizeof(struct io_event) * nr_events;
42249 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
42250
42251- if (nr_pages < 0)
42252+ if (nr_pages <= 0)
42253 return -EINVAL;
42254
42255 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
42256@@ -1440,18 +1440,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
42257 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42258 {
42259 ssize_t ret;
42260+ struct iovec iovstack;
42261
42262 #ifdef CONFIG_COMPAT
42263 if (compat)
42264 ret = compat_rw_copy_check_uvector(type,
42265 (struct compat_iovec __user *)kiocb->ki_buf,
42266- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42267+ kiocb->ki_nbytes, 1, &iovstack,
42268 &kiocb->ki_iovec);
42269 else
42270 #endif
42271 ret = rw_copy_check_uvector(type,
42272 (struct iovec __user *)kiocb->ki_buf,
42273- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42274+ kiocb->ki_nbytes, 1, &iovstack,
42275 &kiocb->ki_iovec);
42276 if (ret < 0)
42277 goto out;
42278@@ -1460,6 +1461,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42279 if (ret < 0)
42280 goto out;
42281
42282+ if (kiocb->ki_iovec == &iovstack) {
42283+ kiocb->ki_inline_vec = iovstack;
42284+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
42285+ }
42286 kiocb->ki_nr_segs = kiocb->ki_nbytes;
42287 kiocb->ki_cur_seg = 0;
42288 /* ki_nbytes/left now reflect bytes instead of segs */
42289diff --git a/fs/attr.c b/fs/attr.c
42290index 0da9095..1386693 100644
42291--- a/fs/attr.c
42292+++ b/fs/attr.c
42293@@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
42294 unsigned long limit;
42295
42296 limit = rlimit(RLIMIT_FSIZE);
42297+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
42298 if (limit != RLIM_INFINITY && offset > limit)
42299 goto out_sig;
42300 if (offset > inode->i_sb->s_maxbytes)
42301diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
42302index da8876d..4456166 100644
42303--- a/fs/autofs4/waitq.c
42304+++ b/fs/autofs4/waitq.c
42305@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
42306 {
42307 unsigned long sigpipe, flags;
42308 mm_segment_t fs;
42309- const char *data = (const char *)addr;
42310+ const char __user *data = (const char __force_user *)addr;
42311 ssize_t wr = 0;
42312
42313 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
42314@@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
42315 return 1;
42316 }
42317
42318+#ifdef CONFIG_GRKERNSEC_HIDESYM
42319+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
42320+#endif
42321+
42322 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42323 enum autofs_notify notify)
42324 {
42325@@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42326
42327 /* If this is a direct mount request create a dummy name */
42328 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
42329+#ifdef CONFIG_GRKERNSEC_HIDESYM
42330+ /* this name does get written to userland via autofs4_write() */
42331+ qstr.len = sprintf(name, "%08lx", atomic_inc_return_unchecked(&autofs_dummy_name_id));
42332+#else
42333 qstr.len = sprintf(name, "%p", dentry);
42334+#endif
42335 else {
42336 qstr.len = autofs4_getpath(sbi, dentry, &name);
42337 if (!qstr.len) {
42338diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
42339index e18da23..affc30e 100644
42340--- a/fs/befs/linuxvfs.c
42341+++ b/fs/befs/linuxvfs.c
42342@@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42343 {
42344 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
42345 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
42346- char *link = nd_get_link(nd);
42347+ const char *link = nd_get_link(nd);
42348 if (!IS_ERR(link))
42349 kfree(link);
42350 }
42351diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
42352index d146e18..12d1bd1 100644
42353--- a/fs/binfmt_aout.c
42354+++ b/fs/binfmt_aout.c
42355@@ -16,6 +16,7 @@
42356 #include <linux/string.h>
42357 #include <linux/fs.h>
42358 #include <linux/file.h>
42359+#include <linux/security.h>
42360 #include <linux/stat.h>
42361 #include <linux/fcntl.h>
42362 #include <linux/ptrace.h>
42363@@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42364 #endif
42365 # define START_STACK(u) ((void __user *)u.start_stack)
42366
42367+ memset(&dump, 0, sizeof(dump));
42368+
42369 fs = get_fs();
42370 set_fs(KERNEL_DS);
42371 has_dumped = 1;
42372@@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42373
42374 /* If the size of the dump file exceeds the rlimit, then see what would happen
42375 if we wrote the stack, but not the data area. */
42376+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42377 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42378 dump.u_dsize = 0;
42379
42380 /* Make sure we have enough room to write the stack and data areas. */
42381+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42382 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42383 dump.u_ssize = 0;
42384
42385@@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42386 rlim = rlimit(RLIMIT_DATA);
42387 if (rlim >= RLIM_INFINITY)
42388 rlim = ~0;
42389+
42390+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42391 if (ex.a_data + ex.a_bss > rlim)
42392 return -ENOMEM;
42393
42394@@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42395
42396 install_exec_creds(bprm);
42397
42398+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42399+ current->mm->pax_flags = 0UL;
42400+#endif
42401+
42402+#ifdef CONFIG_PAX_PAGEEXEC
42403+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42404+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42405+
42406+#ifdef CONFIG_PAX_EMUTRAMP
42407+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42408+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42409+#endif
42410+
42411+#ifdef CONFIG_PAX_MPROTECT
42412+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42413+ current->mm->pax_flags |= MF_PAX_MPROTECT;
42414+#endif
42415+
42416+ }
42417+#endif
42418+
42419 if (N_MAGIC(ex) == OMAGIC) {
42420 unsigned long text_addr, map_size;
42421 loff_t pos;
42422@@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42423 }
42424
42425 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42426- PROT_READ | PROT_WRITE | PROT_EXEC,
42427+ PROT_READ | PROT_WRITE,
42428 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42429 fd_offset + ex.a_text);
42430 if (error != N_DATADDR(ex)) {
42431diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42432index 1b52956..271266e 100644
42433--- a/fs/binfmt_elf.c
42434+++ b/fs/binfmt_elf.c
42435@@ -32,6 +32,7 @@
42436 #include <linux/elf.h>
42437 #include <linux/utsname.h>
42438 #include <linux/coredump.h>
42439+#include <linux/xattr.h>
42440 #include <asm/uaccess.h>
42441 #include <asm/param.h>
42442 #include <asm/page.h>
42443@@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42444 #define elf_core_dump NULL
42445 #endif
42446
42447+#ifdef CONFIG_PAX_MPROTECT
42448+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42449+#endif
42450+
42451 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42452 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42453 #else
42454@@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
42455 .load_binary = load_elf_binary,
42456 .load_shlib = load_elf_library,
42457 .core_dump = elf_core_dump,
42458+
42459+#ifdef CONFIG_PAX_MPROTECT
42460+ .handle_mprotect= elf_handle_mprotect,
42461+#endif
42462+
42463 .min_coredump = ELF_EXEC_PAGESIZE,
42464 };
42465
42466@@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
42467
42468 static int set_brk(unsigned long start, unsigned long end)
42469 {
42470+ unsigned long e = end;
42471+
42472 start = ELF_PAGEALIGN(start);
42473 end = ELF_PAGEALIGN(end);
42474 if (end > start) {
42475@@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
42476 if (BAD_ADDR(addr))
42477 return addr;
42478 }
42479- current->mm->start_brk = current->mm->brk = end;
42480+ current->mm->start_brk = current->mm->brk = e;
42481 return 0;
42482 }
42483
42484@@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42485 elf_addr_t __user *u_rand_bytes;
42486 const char *k_platform = ELF_PLATFORM;
42487 const char *k_base_platform = ELF_BASE_PLATFORM;
42488- unsigned char k_rand_bytes[16];
42489+ u32 k_rand_bytes[4];
42490 int items;
42491 elf_addr_t *elf_info;
42492 int ei_index = 0;
42493 const struct cred *cred = current_cred();
42494 struct vm_area_struct *vma;
42495+ unsigned long saved_auxv[AT_VECTOR_SIZE];
42496
42497 /*
42498 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42499@@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42500 * Generate 16 random bytes for userspace PRNG seeding.
42501 */
42502 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42503- u_rand_bytes = (elf_addr_t __user *)
42504- STACK_ALLOC(p, sizeof(k_rand_bytes));
42505+ srandom32(k_rand_bytes[0] ^ random32());
42506+ srandom32(k_rand_bytes[1] ^ random32());
42507+ srandom32(k_rand_bytes[2] ^ random32());
42508+ srandom32(k_rand_bytes[3] ^ random32());
42509+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
42510+ u_rand_bytes = (elf_addr_t __user *) p;
42511 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
42512 return -EFAULT;
42513
42514@@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42515 return -EFAULT;
42516 current->mm->env_end = p;
42517
42518+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
42519+
42520 /* Put the elf_info on the stack in the right place. */
42521 sp = (elf_addr_t __user *)envp + 1;
42522- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
42523+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
42524 return -EFAULT;
42525 return 0;
42526 }
42527@@ -378,10 +397,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42528 {
42529 struct elf_phdr *elf_phdata;
42530 struct elf_phdr *eppnt;
42531- unsigned long load_addr = 0;
42532+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
42533 int load_addr_set = 0;
42534 unsigned long last_bss = 0, elf_bss = 0;
42535- unsigned long error = ~0UL;
42536+ unsigned long error = -EINVAL;
42537 unsigned long total_size;
42538 int retval, i, size;
42539
42540@@ -427,6 +446,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42541 goto out_close;
42542 }
42543
42544+#ifdef CONFIG_PAX_SEGMEXEC
42545+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
42546+ pax_task_size = SEGMEXEC_TASK_SIZE;
42547+#endif
42548+
42549 eppnt = elf_phdata;
42550 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
42551 if (eppnt->p_type == PT_LOAD) {
42552@@ -470,8 +494,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42553 k = load_addr + eppnt->p_vaddr;
42554 if (BAD_ADDR(k) ||
42555 eppnt->p_filesz > eppnt->p_memsz ||
42556- eppnt->p_memsz > TASK_SIZE ||
42557- TASK_SIZE - eppnt->p_memsz < k) {
42558+ eppnt->p_memsz > pax_task_size ||
42559+ pax_task_size - eppnt->p_memsz < k) {
42560 error = -ENOMEM;
42561 goto out_close;
42562 }
42563@@ -523,6 +547,311 @@ out:
42564 return error;
42565 }
42566
42567+#ifdef CONFIG_PAX_PT_PAX_FLAGS
42568+#ifdef CONFIG_PAX_SOFTMODE
42569+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
42570+{
42571+ unsigned long pax_flags = 0UL;
42572+
42573+#ifdef CONFIG_PAX_PAGEEXEC
42574+ if (elf_phdata->p_flags & PF_PAGEEXEC)
42575+ pax_flags |= MF_PAX_PAGEEXEC;
42576+#endif
42577+
42578+#ifdef CONFIG_PAX_SEGMEXEC
42579+ if (elf_phdata->p_flags & PF_SEGMEXEC)
42580+ pax_flags |= MF_PAX_SEGMEXEC;
42581+#endif
42582+
42583+#ifdef CONFIG_PAX_EMUTRAMP
42584+ if (elf_phdata->p_flags & PF_EMUTRAMP)
42585+ pax_flags |= MF_PAX_EMUTRAMP;
42586+#endif
42587+
42588+#ifdef CONFIG_PAX_MPROTECT
42589+ if (elf_phdata->p_flags & PF_MPROTECT)
42590+ pax_flags |= MF_PAX_MPROTECT;
42591+#endif
42592+
42593+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42594+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
42595+ pax_flags |= MF_PAX_RANDMMAP;
42596+#endif
42597+
42598+ return pax_flags;
42599+}
42600+#endif
42601+
42602+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
42603+{
42604+ unsigned long pax_flags = 0UL;
42605+
42606+#ifdef CONFIG_PAX_PAGEEXEC
42607+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
42608+ pax_flags |= MF_PAX_PAGEEXEC;
42609+#endif
42610+
42611+#ifdef CONFIG_PAX_SEGMEXEC
42612+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
42613+ pax_flags |= MF_PAX_SEGMEXEC;
42614+#endif
42615+
42616+#ifdef CONFIG_PAX_EMUTRAMP
42617+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
42618+ pax_flags |= MF_PAX_EMUTRAMP;
42619+#endif
42620+
42621+#ifdef CONFIG_PAX_MPROTECT
42622+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
42623+ pax_flags |= MF_PAX_MPROTECT;
42624+#endif
42625+
42626+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42627+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
42628+ pax_flags |= MF_PAX_RANDMMAP;
42629+#endif
42630+
42631+ return pax_flags;
42632+}
42633+#endif
42634+
42635+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42636+#ifdef CONFIG_PAX_SOFTMODE
42637+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
42638+{
42639+ unsigned long pax_flags = 0UL;
42640+
42641+#ifdef CONFIG_PAX_PAGEEXEC
42642+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
42643+ pax_flags |= MF_PAX_PAGEEXEC;
42644+#endif
42645+
42646+#ifdef CONFIG_PAX_SEGMEXEC
42647+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
42648+ pax_flags |= MF_PAX_SEGMEXEC;
42649+#endif
42650+
42651+#ifdef CONFIG_PAX_EMUTRAMP
42652+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
42653+ pax_flags |= MF_PAX_EMUTRAMP;
42654+#endif
42655+
42656+#ifdef CONFIG_PAX_MPROTECT
42657+ if (pax_flags_softmode & MF_PAX_MPROTECT)
42658+ pax_flags |= MF_PAX_MPROTECT;
42659+#endif
42660+
42661+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42662+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
42663+ pax_flags |= MF_PAX_RANDMMAP;
42664+#endif
42665+
42666+ return pax_flags;
42667+}
42668+#endif
42669+
42670+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
42671+{
42672+ unsigned long pax_flags = 0UL;
42673+
42674+#ifdef CONFIG_PAX_PAGEEXEC
42675+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
42676+ pax_flags |= MF_PAX_PAGEEXEC;
42677+#endif
42678+
42679+#ifdef CONFIG_PAX_SEGMEXEC
42680+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
42681+ pax_flags |= MF_PAX_SEGMEXEC;
42682+#endif
42683+
42684+#ifdef CONFIG_PAX_EMUTRAMP
42685+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
42686+ pax_flags |= MF_PAX_EMUTRAMP;
42687+#endif
42688+
42689+#ifdef CONFIG_PAX_MPROTECT
42690+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
42691+ pax_flags |= MF_PAX_MPROTECT;
42692+#endif
42693+
42694+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42695+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
42696+ pax_flags |= MF_PAX_RANDMMAP;
42697+#endif
42698+
42699+ return pax_flags;
42700+}
42701+#endif
42702+
42703+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42704+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
42705+{
42706+ unsigned long pax_flags = 0UL;
42707+
42708+#ifdef CONFIG_PAX_EI_PAX
42709+
42710+#ifdef CONFIG_PAX_PAGEEXEC
42711+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
42712+ pax_flags |= MF_PAX_PAGEEXEC;
42713+#endif
42714+
42715+#ifdef CONFIG_PAX_SEGMEXEC
42716+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
42717+ pax_flags |= MF_PAX_SEGMEXEC;
42718+#endif
42719+
42720+#ifdef CONFIG_PAX_EMUTRAMP
42721+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
42722+ pax_flags |= MF_PAX_EMUTRAMP;
42723+#endif
42724+
42725+#ifdef CONFIG_PAX_MPROTECT
42726+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
42727+ pax_flags |= MF_PAX_MPROTECT;
42728+#endif
42729+
42730+#ifdef CONFIG_PAX_ASLR
42731+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
42732+ pax_flags |= MF_PAX_RANDMMAP;
42733+#endif
42734+
42735+#else
42736+
42737+#ifdef CONFIG_PAX_PAGEEXEC
42738+ pax_flags |= MF_PAX_PAGEEXEC;
42739+#endif
42740+
42741+#ifdef CONFIG_PAX_SEGMEXEC
42742+ pax_flags |= MF_PAX_SEGMEXEC;
42743+#endif
42744+
42745+#ifdef CONFIG_PAX_MPROTECT
42746+ pax_flags |= MF_PAX_MPROTECT;
42747+#endif
42748+
42749+#ifdef CONFIG_PAX_RANDMMAP
42750+ if (randomize_va_space)
42751+ pax_flags |= MF_PAX_RANDMMAP;
42752+#endif
42753+
42754+#endif
42755+
42756+ return pax_flags;
42757+}
42758+
42759+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
42760+{
42761+
42762+#ifdef CONFIG_PAX_PT_PAX_FLAGS
42763+ unsigned long i;
42764+
42765+ for (i = 0UL; i < elf_ex->e_phnum; i++)
42766+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
42767+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
42768+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
42769+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
42770+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
42771+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
42772+ return ~0UL;
42773+
42774+#ifdef CONFIG_PAX_SOFTMODE
42775+ if (pax_softmode)
42776+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
42777+ else
42778+#endif
42779+
42780+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
42781+ break;
42782+ }
42783+#endif
42784+
42785+ return ~0UL;
42786+}
42787+
42788+static unsigned long pax_parse_xattr_pax(struct file * const file)
42789+{
42790+
42791+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42792+ ssize_t xattr_size, i;
42793+ unsigned char xattr_value[5];
42794+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
42795+
42796+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
42797+ if (xattr_size <= 0)
42798+ return ~0UL;
42799+
42800+ for (i = 0; i < xattr_size; i++)
42801+ switch (xattr_value[i]) {
42802+ default:
42803+ return ~0UL;
42804+
42805+#define parse_flag(option1, option2, flag) \
42806+ case option1: \
42807+ pax_flags_hardmode |= MF_PAX_##flag; \
42808+ break; \
42809+ case option2: \
42810+ pax_flags_softmode |= MF_PAX_##flag; \
42811+ break;
42812+
42813+ parse_flag('p', 'P', PAGEEXEC);
42814+ parse_flag('e', 'E', EMUTRAMP);
42815+ parse_flag('m', 'M', MPROTECT);
42816+ parse_flag('r', 'R', RANDMMAP);
42817+ parse_flag('s', 'S', SEGMEXEC);
42818+
42819+#undef parse_flag
42820+ }
42821+
42822+ if (pax_flags_hardmode & pax_flags_softmode)
42823+ return ~0UL;
42824+
42825+#ifdef CONFIG_PAX_SOFTMODE
42826+ if (pax_softmode)
42827+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
42828+ else
42829+#endif
42830+
42831+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
42832+#else
42833+ return ~0UL;
42834+#endif
42835+
42836+}
42837+
42838+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
42839+{
42840+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
42841+
42842+ pax_flags = pax_parse_ei_pax(elf_ex);
42843+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
42844+ xattr_pax_flags = pax_parse_xattr_pax(file);
42845+
42846+ if (pt_pax_flags == ~0UL)
42847+ pt_pax_flags = xattr_pax_flags;
42848+ else if (xattr_pax_flags == ~0UL)
42849+ xattr_pax_flags = pt_pax_flags;
42850+ if (pt_pax_flags != xattr_pax_flags)
42851+ return -EINVAL;
42852+ if (pt_pax_flags != ~0UL)
42853+ pax_flags = pt_pax_flags;
42854+
42855+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42856+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42857+ if ((__supported_pte_mask & _PAGE_NX))
42858+ pax_flags &= ~MF_PAX_SEGMEXEC;
42859+ else
42860+ pax_flags &= ~MF_PAX_PAGEEXEC;
42861+ }
42862+#endif
42863+
42864+ if (0 > pax_check_flags(&pax_flags))
42865+ return -EINVAL;
42866+
42867+ current->mm->pax_flags = pax_flags;
42868+ return 0;
42869+}
42870+#endif
42871+
42872 /*
42873 * These are the functions used to load ELF style executables and shared
42874 * libraries. There is no binary dependent code anywhere else.
42875@@ -539,6 +868,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
42876 {
42877 unsigned int random_variable = 0;
42878
42879+#ifdef CONFIG_PAX_RANDUSTACK
42880+ if (randomize_va_space)
42881+ return stack_top - current->mm->delta_stack;
42882+#endif
42883+
42884 if ((current->flags & PF_RANDOMIZE) &&
42885 !(current->personality & ADDR_NO_RANDOMIZE)) {
42886 random_variable = get_random_int() & STACK_RND_MASK;
42887@@ -557,7 +891,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42888 unsigned long load_addr = 0, load_bias = 0;
42889 int load_addr_set = 0;
42890 char * elf_interpreter = NULL;
42891- unsigned long error;
42892+ unsigned long error = 0;
42893 struct elf_phdr *elf_ppnt, *elf_phdata;
42894 unsigned long elf_bss, elf_brk;
42895 int retval, i;
42896@@ -567,11 +901,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42897 unsigned long start_code, end_code, start_data, end_data;
42898 unsigned long reloc_func_desc __maybe_unused = 0;
42899 int executable_stack = EXSTACK_DEFAULT;
42900- unsigned long def_flags = 0;
42901 struct {
42902 struct elfhdr elf_ex;
42903 struct elfhdr interp_elf_ex;
42904 } *loc;
42905+ unsigned long pax_task_size = TASK_SIZE;
42906
42907 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
42908 if (!loc) {
42909@@ -707,11 +1041,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42910 goto out_free_dentry;
42911
42912 /* OK, This is the point of no return */
42913- current->mm->def_flags = def_flags;
42914+
42915+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42916+ current->mm->pax_flags = 0UL;
42917+#endif
42918+
42919+#ifdef CONFIG_PAX_DLRESOLVE
42920+ current->mm->call_dl_resolve = 0UL;
42921+#endif
42922+
42923+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
42924+ current->mm->call_syscall = 0UL;
42925+#endif
42926+
42927+#ifdef CONFIG_PAX_ASLR
42928+ current->mm->delta_mmap = 0UL;
42929+ current->mm->delta_stack = 0UL;
42930+#endif
42931+
42932+ current->mm->def_flags = 0;
42933+
42934+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42935+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
42936+ send_sig(SIGKILL, current, 0);
42937+ goto out_free_dentry;
42938+ }
42939+#endif
42940+
42941+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
42942+ pax_set_initial_flags(bprm);
42943+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
42944+ if (pax_set_initial_flags_func)
42945+ (pax_set_initial_flags_func)(bprm);
42946+#endif
42947+
42948+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
42949+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
42950+ current->mm->context.user_cs_limit = PAGE_SIZE;
42951+ current->mm->def_flags |= VM_PAGEEXEC;
42952+ }
42953+#endif
42954+
42955+#ifdef CONFIG_PAX_SEGMEXEC
42956+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
42957+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
42958+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
42959+ pax_task_size = SEGMEXEC_TASK_SIZE;
42960+ current->mm->def_flags |= VM_NOHUGEPAGE;
42961+ }
42962+#endif
42963+
42964+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
42965+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42966+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
42967+ put_cpu();
42968+ }
42969+#endif
42970
42971 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
42972 may depend on the personality. */
42973 SET_PERSONALITY(loc->elf_ex);
42974+
42975+#ifdef CONFIG_PAX_ASLR
42976+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42977+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
42978+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
42979+ }
42980+#endif
42981+
42982+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
42983+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42984+ executable_stack = EXSTACK_DISABLE_X;
42985+ current->personality &= ~READ_IMPLIES_EXEC;
42986+ } else
42987+#endif
42988+
42989 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
42990 current->personality |= READ_IMPLIES_EXEC;
42991
42992@@ -802,6 +1206,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42993 #else
42994 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
42995 #endif
42996+
42997+#ifdef CONFIG_PAX_RANDMMAP
42998+ /* PaX: randomize base address at the default exe base if requested */
42999+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
43000+#ifdef CONFIG_SPARC64
43001+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
43002+#else
43003+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
43004+#endif
43005+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
43006+ elf_flags |= MAP_FIXED;
43007+ }
43008+#endif
43009+
43010 }
43011
43012 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
43013@@ -834,9 +1252,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43014 * allowed task size. Note that p_filesz must always be
43015 * <= p_memsz so it is only necessary to check p_memsz.
43016 */
43017- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43018- elf_ppnt->p_memsz > TASK_SIZE ||
43019- TASK_SIZE - elf_ppnt->p_memsz < k) {
43020+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43021+ elf_ppnt->p_memsz > pax_task_size ||
43022+ pax_task_size - elf_ppnt->p_memsz < k) {
43023 /* set_brk can never work. Avoid overflows. */
43024 send_sig(SIGKILL, current, 0);
43025 retval = -EINVAL;
43026@@ -875,11 +1293,41 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43027 goto out_free_dentry;
43028 }
43029 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
43030- send_sig(SIGSEGV, current, 0);
43031- retval = -EFAULT; /* Nobody gets to see this, but.. */
43032- goto out_free_dentry;
43033+ /*
43034+ * This bss-zeroing can fail if the ELF
43035+ * file specifies odd protections. So
43036+ * we don't check the return value
43037+ */
43038 }
43039
43040+#ifdef CONFIG_PAX_RANDMMAP
43041+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43042+ unsigned long start, size;
43043+
43044+ start = ELF_PAGEALIGN(elf_brk);
43045+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
43046+ down_read(&current->mm->mmap_sem);
43047+ retval = -ENOMEM;
43048+ if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
43049+ unsigned long prot = PROT_NONE;
43050+
43051+ up_read(&current->mm->mmap_sem);
43052+ current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
43053+// if (current->personality & ADDR_NO_RANDOMIZE)
43054+// prot = PROT_READ;
43055+ start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
43056+ retval = IS_ERR_VALUE(start) ? start : 0;
43057+ } else
43058+ up_read(&current->mm->mmap_sem);
43059+ if (retval == 0)
43060+ retval = set_brk(start + size, start + size + PAGE_SIZE);
43061+ if (retval < 0) {
43062+ send_sig(SIGKILL, current, 0);
43063+ goto out_free_dentry;
43064+ }
43065+ }
43066+#endif
43067+
43068 if (elf_interpreter) {
43069 unsigned long uninitialized_var(interp_map_addr);
43070
43071@@ -1107,7 +1555,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
43072 * Decide what to dump of a segment, part, all or none.
43073 */
43074 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43075- unsigned long mm_flags)
43076+ unsigned long mm_flags, long signr)
43077 {
43078 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43079
43080@@ -1144,7 +1592,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
43081 if (vma->vm_file == NULL)
43082 return 0;
43083
43084- if (FILTER(MAPPED_PRIVATE))
43085+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43086 goto whole;
43087
43088 /*
43089@@ -1366,9 +1814,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
43090 {
43091 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
43092 int i = 0;
43093- do
43094+ do {
43095 i += 2;
43096- while (auxv[i - 2] != AT_NULL);
43097+ } while (auxv[i - 2] != AT_NULL);
43098 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43099 }
43100
43101@@ -1890,14 +2338,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
43102 }
43103
43104 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43105- unsigned long mm_flags)
43106+ struct coredump_params *cprm)
43107 {
43108 struct vm_area_struct *vma;
43109 size_t size = 0;
43110
43111 for (vma = first_vma(current, gate_vma); vma != NULL;
43112 vma = next_vma(vma, gate_vma))
43113- size += vma_dump_size(vma, mm_flags);
43114+ size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43115 return size;
43116 }
43117
43118@@ -1991,7 +2439,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43119
43120 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43121
43122- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43123+ offset += elf_core_vma_data_size(gate_vma, cprm);
43124 offset += elf_core_extra_data_size();
43125 e_shoff = offset;
43126
43127@@ -2005,10 +2453,12 @@ static int elf_core_dump(struct coredump_params *cprm)
43128 offset = dataoff;
43129
43130 size += sizeof(*elf);
43131+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43132 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43133 goto end_coredump;
43134
43135 size += sizeof(*phdr4note);
43136+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43137 if (size > cprm->limit
43138 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43139 goto end_coredump;
43140@@ -2022,7 +2472,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43141 phdr.p_offset = offset;
43142 phdr.p_vaddr = vma->vm_start;
43143 phdr.p_paddr = 0;
43144- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43145+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43146 phdr.p_memsz = vma->vm_end - vma->vm_start;
43147 offset += phdr.p_filesz;
43148 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43149@@ -2033,6 +2483,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43150 phdr.p_align = ELF_EXEC_PAGESIZE;
43151
43152 size += sizeof(phdr);
43153+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43154 if (size > cprm->limit
43155 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
43156 goto end_coredump;
43157@@ -2057,7 +2508,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43158 unsigned long addr;
43159 unsigned long end;
43160
43161- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
43162+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43163
43164 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43165 struct page *page;
43166@@ -2066,6 +2517,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43167 page = get_dump_page(addr);
43168 if (page) {
43169 void *kaddr = kmap(page);
43170+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43171 stop = ((size += PAGE_SIZE) > cprm->limit) ||
43172 !dump_write(cprm->file, kaddr,
43173 PAGE_SIZE);
43174@@ -2083,6 +2535,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43175
43176 if (e_phnum == PN_XNUM) {
43177 size += sizeof(*shdr4extnum);
43178+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
43179 if (size > cprm->limit
43180 || !dump_write(cprm->file, shdr4extnum,
43181 sizeof(*shdr4extnum)))
43182@@ -2103,6 +2556,97 @@ out:
43183
43184 #endif /* CONFIG_ELF_CORE */
43185
43186+#ifdef CONFIG_PAX_MPROTECT
43187+/* PaX: non-PIC ELF libraries need relocations on their executable segments
43188+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43189+ * we'll remove VM_MAYWRITE for good on RELRO segments.
43190+ *
43191+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43192+ * basis because we want to allow the common case and not the special ones.
43193+ */
43194+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43195+{
43196+ struct elfhdr elf_h;
43197+ struct elf_phdr elf_p;
43198+ unsigned long i;
43199+ unsigned long oldflags;
43200+ bool is_textrel_rw, is_textrel_rx, is_relro;
43201+
43202+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
43203+ return;
43204+
43205+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
43206+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
43207+
43208+#ifdef CONFIG_PAX_ELFRELOCS
43209+ /* possible TEXTREL */
43210+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
43211+ 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);
43212+#else
43213+ is_textrel_rw = false;
43214+ is_textrel_rx = false;
43215+#endif
43216+
43217+ /* possible RELRO */
43218+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
43219+
43220+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
43221+ return;
43222+
43223+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
43224+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
43225+
43226+#ifdef CONFIG_PAX_ETEXECRELOCS
43227+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43228+#else
43229+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
43230+#endif
43231+
43232+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43233+ !elf_check_arch(&elf_h) ||
43234+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
43235+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
43236+ return;
43237+
43238+ for (i = 0UL; i < elf_h.e_phnum; i++) {
43239+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
43240+ return;
43241+ switch (elf_p.p_type) {
43242+ case PT_DYNAMIC:
43243+ if (!is_textrel_rw && !is_textrel_rx)
43244+ continue;
43245+ i = 0UL;
43246+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
43247+ elf_dyn dyn;
43248+
43249+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
43250+ return;
43251+ if (dyn.d_tag == DT_NULL)
43252+ return;
43253+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
43254+ gr_log_textrel(vma);
43255+ if (is_textrel_rw)
43256+ vma->vm_flags |= VM_MAYWRITE;
43257+ else
43258+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
43259+ vma->vm_flags &= ~VM_MAYWRITE;
43260+ return;
43261+ }
43262+ i++;
43263+ }
43264+ return;
43265+
43266+ case PT_GNU_RELRO:
43267+ if (!is_relro)
43268+ continue;
43269+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
43270+ vma->vm_flags &= ~VM_MAYWRITE;
43271+ return;
43272+ }
43273+ }
43274+}
43275+#endif
43276+
43277 static int __init init_elf_binfmt(void)
43278 {
43279 register_binfmt(&elf_format);
43280diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
43281index 178cb70..8972997 100644
43282--- a/fs/binfmt_flat.c
43283+++ b/fs/binfmt_flat.c
43284@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
43285 realdatastart = (unsigned long) -ENOMEM;
43286 printk("Unable to allocate RAM for process data, errno %d\n",
43287 (int)-realdatastart);
43288+ down_write(&current->mm->mmap_sem);
43289 vm_munmap(textpos, text_len);
43290+ up_write(&current->mm->mmap_sem);
43291 ret = realdatastart;
43292 goto err;
43293 }
43294@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43295 }
43296 if (IS_ERR_VALUE(result)) {
43297 printk("Unable to read data+bss, errno %d\n", (int)-result);
43298+ down_write(&current->mm->mmap_sem);
43299 vm_munmap(textpos, text_len);
43300 vm_munmap(realdatastart, len);
43301+ up_write(&current->mm->mmap_sem);
43302 ret = result;
43303 goto err;
43304 }
43305@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43306 }
43307 if (IS_ERR_VALUE(result)) {
43308 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
43309+ down_write(&current->mm->mmap_sem);
43310 vm_munmap(textpos, text_len + data_len + extra +
43311 MAX_SHARED_LIBS * sizeof(unsigned long));
43312+ up_write(&current->mm->mmap_sem);
43313 ret = result;
43314 goto err;
43315 }
43316diff --git a/fs/bio.c b/fs/bio.c
43317index 73922ab..16642dd 100644
43318--- a/fs/bio.c
43319+++ b/fs/bio.c
43320@@ -841,7 +841,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
43321 /*
43322 * Overflow, abort
43323 */
43324- if (end < start)
43325+ if (end < start || end - start > INT_MAX - nr_pages)
43326 return ERR_PTR(-EINVAL);
43327
43328 nr_pages += end - start;
43329@@ -975,7 +975,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
43330 /*
43331 * Overflow, abort
43332 */
43333- if (end < start)
43334+ if (end < start || end - start > INT_MAX - nr_pages)
43335 return ERR_PTR(-EINVAL);
43336
43337 nr_pages += end - start;
43338@@ -1237,7 +1237,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43339 const int read = bio_data_dir(bio) == READ;
43340 struct bio_map_data *bmd = bio->bi_private;
43341 int i;
43342- char *p = bmd->sgvecs[0].iov_base;
43343+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43344
43345 __bio_for_each_segment(bvec, bio, i, 0) {
43346 char *addr = page_address(bvec->bv_page);
43347diff --git a/fs/block_dev.c b/fs/block_dev.c
43348index c2bbe1f..9dfbc23 100644
43349--- a/fs/block_dev.c
43350+++ b/fs/block_dev.c
43351@@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43352 else if (bdev->bd_contains == bdev)
43353 return true; /* is a whole device which isn't held */
43354
43355- else if (whole->bd_holder == bd_may_claim)
43356+ else if (whole->bd_holder == (void *)bd_may_claim)
43357 return true; /* is a partition of a device that is being partitioned */
43358 else if (whole->bd_holder != NULL)
43359 return false; /* is a partition of a held device */
43360diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
43361index da6e936..1598dd0 100644
43362--- a/fs/btrfs/check-integrity.c
43363+++ b/fs/btrfs/check-integrity.c
43364@@ -155,7 +155,7 @@ struct btrfsic_block {
43365 union {
43366 bio_end_io_t *bio;
43367 bh_end_io_t *bh;
43368- } orig_bio_bh_end_io;
43369+ } __no_const orig_bio_bh_end_io;
43370 int submit_bio_bh_rw;
43371 u64 flush_gen; /* only valid if !never_written */
43372 };
43373diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
43374index 8206b39..06d5654 100644
43375--- a/fs/btrfs/ctree.c
43376+++ b/fs/btrfs/ctree.c
43377@@ -973,9 +973,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
43378 free_extent_buffer(buf);
43379 add_root_to_dirty_list(root);
43380 } else {
43381- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43382- parent_start = parent->start;
43383- else
43384+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43385+ if (parent)
43386+ parent_start = parent->start;
43387+ else
43388+ parent_start = 0;
43389+ } else
43390 parent_start = 0;
43391
43392 WARN_ON(trans->transid != btrfs_header_generation(parent));
43393diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43394index a7d1921..a32dba2 100644
43395--- a/fs/btrfs/inode.c
43396+++ b/fs/btrfs/inode.c
43397@@ -7111,7 +7111,7 @@ fail:
43398 return -ENOMEM;
43399 }
43400
43401-static int btrfs_getattr(struct vfsmount *mnt,
43402+int btrfs_getattr(struct vfsmount *mnt,
43403 struct dentry *dentry, struct kstat *stat)
43404 {
43405 struct inode *inode = dentry->d_inode;
43406@@ -7125,6 +7125,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43407 return 0;
43408 }
43409
43410+EXPORT_SYMBOL(btrfs_getattr);
43411+
43412+dev_t get_btrfs_dev_from_inode(struct inode *inode)
43413+{
43414+ return BTRFS_I(inode)->root->anon_dev;
43415+}
43416+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43417+
43418 /*
43419 * If a file is moved, it will inherit the cow and compression flags of the new
43420 * directory.
43421diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43422index 0e92e57..8b560de 100644
43423--- a/fs/btrfs/ioctl.c
43424+++ b/fs/btrfs/ioctl.c
43425@@ -2902,9 +2902,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43426 for (i = 0; i < num_types; i++) {
43427 struct btrfs_space_info *tmp;
43428
43429+ /* Don't copy in more than we allocated */
43430 if (!slot_count)
43431 break;
43432
43433+ slot_count--;
43434+
43435 info = NULL;
43436 rcu_read_lock();
43437 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43438@@ -2926,10 +2929,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43439 memcpy(dest, &space, sizeof(space));
43440 dest++;
43441 space_args.total_spaces++;
43442- slot_count--;
43443 }
43444- if (!slot_count)
43445- break;
43446 }
43447 up_read(&info->groups_sem);
43448 }
43449diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43450index 646ee21..f020f87 100644
43451--- a/fs/btrfs/relocation.c
43452+++ b/fs/btrfs/relocation.c
43453@@ -1268,7 +1268,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43454 }
43455 spin_unlock(&rc->reloc_root_tree.lock);
43456
43457- BUG_ON((struct btrfs_root *)node->data != root);
43458+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
43459
43460 if (!del) {
43461 spin_lock(&rc->reloc_root_tree.lock);
43462diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43463index 622f469..e8d2d55 100644
43464--- a/fs/cachefiles/bind.c
43465+++ b/fs/cachefiles/bind.c
43466@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43467 args);
43468
43469 /* start by checking things over */
43470- ASSERT(cache->fstop_percent >= 0 &&
43471- cache->fstop_percent < cache->fcull_percent &&
43472+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
43473 cache->fcull_percent < cache->frun_percent &&
43474 cache->frun_percent < 100);
43475
43476- ASSERT(cache->bstop_percent >= 0 &&
43477- cache->bstop_percent < cache->bcull_percent &&
43478+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
43479 cache->bcull_percent < cache->brun_percent &&
43480 cache->brun_percent < 100);
43481
43482diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
43483index 0a1467b..6a53245 100644
43484--- a/fs/cachefiles/daemon.c
43485+++ b/fs/cachefiles/daemon.c
43486@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
43487 if (n > buflen)
43488 return -EMSGSIZE;
43489
43490- if (copy_to_user(_buffer, buffer, n) != 0)
43491+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
43492 return -EFAULT;
43493
43494 return n;
43495@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
43496 if (test_bit(CACHEFILES_DEAD, &cache->flags))
43497 return -EIO;
43498
43499- if (datalen < 0 || datalen > PAGE_SIZE - 1)
43500+ if (datalen > PAGE_SIZE - 1)
43501 return -EOPNOTSUPP;
43502
43503 /* drag the command string into the kernel so we can parse it */
43504@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
43505 if (args[0] != '%' || args[1] != '\0')
43506 return -EINVAL;
43507
43508- if (fstop < 0 || fstop >= cache->fcull_percent)
43509+ if (fstop >= cache->fcull_percent)
43510 return cachefiles_daemon_range_error(cache, args);
43511
43512 cache->fstop_percent = fstop;
43513@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
43514 if (args[0] != '%' || args[1] != '\0')
43515 return -EINVAL;
43516
43517- if (bstop < 0 || bstop >= cache->bcull_percent)
43518+ if (bstop >= cache->bcull_percent)
43519 return cachefiles_daemon_range_error(cache, args);
43520
43521 cache->bstop_percent = bstop;
43522diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
43523index bd6bc1b..b627b53 100644
43524--- a/fs/cachefiles/internal.h
43525+++ b/fs/cachefiles/internal.h
43526@@ -57,7 +57,7 @@ struct cachefiles_cache {
43527 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
43528 struct rb_root active_nodes; /* active nodes (can't be culled) */
43529 rwlock_t active_lock; /* lock for active_nodes */
43530- atomic_t gravecounter; /* graveyard uniquifier */
43531+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
43532 unsigned frun_percent; /* when to stop culling (% files) */
43533 unsigned fcull_percent; /* when to start culling (% files) */
43534 unsigned fstop_percent; /* when to stop allocating (% files) */
43535@@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
43536 * proc.c
43537 */
43538 #ifdef CONFIG_CACHEFILES_HISTOGRAM
43539-extern atomic_t cachefiles_lookup_histogram[HZ];
43540-extern atomic_t cachefiles_mkdir_histogram[HZ];
43541-extern atomic_t cachefiles_create_histogram[HZ];
43542+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43543+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43544+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
43545
43546 extern int __init cachefiles_proc_init(void);
43547 extern void cachefiles_proc_cleanup(void);
43548 static inline
43549-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
43550+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
43551 {
43552 unsigned long jif = jiffies - start_jif;
43553 if (jif >= HZ)
43554 jif = HZ - 1;
43555- atomic_inc(&histogram[jif]);
43556+ atomic_inc_unchecked(&histogram[jif]);
43557 }
43558
43559 #else
43560diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
43561index 7f0771d..87d4f36 100644
43562--- a/fs/cachefiles/namei.c
43563+++ b/fs/cachefiles/namei.c
43564@@ -318,7 +318,7 @@ try_again:
43565 /* first step is to make up a grave dentry in the graveyard */
43566 sprintf(nbuffer, "%08x%08x",
43567 (uint32_t) get_seconds(),
43568- (uint32_t) atomic_inc_return(&cache->gravecounter));
43569+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
43570
43571 /* do the multiway lock magic */
43572 trap = lock_rename(cache->graveyard, dir);
43573diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
43574index eccd339..4c1d995 100644
43575--- a/fs/cachefiles/proc.c
43576+++ b/fs/cachefiles/proc.c
43577@@ -14,9 +14,9 @@
43578 #include <linux/seq_file.h>
43579 #include "internal.h"
43580
43581-atomic_t cachefiles_lookup_histogram[HZ];
43582-atomic_t cachefiles_mkdir_histogram[HZ];
43583-atomic_t cachefiles_create_histogram[HZ];
43584+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43585+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43586+atomic_unchecked_t cachefiles_create_histogram[HZ];
43587
43588 /*
43589 * display the latency histogram
43590@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
43591 return 0;
43592 default:
43593 index = (unsigned long) v - 3;
43594- x = atomic_read(&cachefiles_lookup_histogram[index]);
43595- y = atomic_read(&cachefiles_mkdir_histogram[index]);
43596- z = atomic_read(&cachefiles_create_histogram[index]);
43597+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
43598+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
43599+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
43600 if (x == 0 && y == 0 && z == 0)
43601 return 0;
43602
43603diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
43604index 0e3c092..818480e 100644
43605--- a/fs/cachefiles/rdwr.c
43606+++ b/fs/cachefiles/rdwr.c
43607@@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
43608 old_fs = get_fs();
43609 set_fs(KERNEL_DS);
43610 ret = file->f_op->write(
43611- file, (const void __user *) data, len, &pos);
43612+ file, (const void __force_user *) data, len, &pos);
43613 set_fs(old_fs);
43614 kunmap(page);
43615 if (ret != len)
43616diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
43617index 3e8094b..cb3ff3d 100644
43618--- a/fs/ceph/dir.c
43619+++ b/fs/ceph/dir.c
43620@@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
43621 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
43622 struct ceph_mds_client *mdsc = fsc->mdsc;
43623 unsigned frag = fpos_frag(filp->f_pos);
43624- int off = fpos_off(filp->f_pos);
43625+ unsigned int off = fpos_off(filp->f_pos);
43626 int err;
43627 u32 ftype;
43628 struct ceph_mds_reply_info_parsed *rinfo;
43629@@ -598,7 +598,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
43630 if (nd &&
43631 (nd->flags & LOOKUP_OPEN) &&
43632 !(nd->intent.open.flags & O_CREAT)) {
43633- int mode = nd->intent.open.create_mode & ~current->fs->umask;
43634+ int mode = nd->intent.open.create_mode & ~current_umask();
43635 return ceph_lookup_open(dir, dentry, nd, mode, 1);
43636 }
43637
43638diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
43639index e814052..28dcdf7 100644
43640--- a/fs/cifs/cifs_debug.c
43641+++ b/fs/cifs/cifs_debug.c
43642@@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43643
43644 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
43645 #ifdef CONFIG_CIFS_STATS2
43646- atomic_set(&totBufAllocCount, 0);
43647- atomic_set(&totSmBufAllocCount, 0);
43648+ atomic_set_unchecked(&totBufAllocCount, 0);
43649+ atomic_set_unchecked(&totSmBufAllocCount, 0);
43650 #endif /* CONFIG_CIFS_STATS2 */
43651 spin_lock(&cifs_tcp_ses_lock);
43652 list_for_each(tmp1, &cifs_tcp_ses_list) {
43653@@ -281,25 +281,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43654 tcon = list_entry(tmp3,
43655 struct cifs_tcon,
43656 tcon_list);
43657- atomic_set(&tcon->num_smbs_sent, 0);
43658- atomic_set(&tcon->num_writes, 0);
43659- atomic_set(&tcon->num_reads, 0);
43660- atomic_set(&tcon->num_oplock_brks, 0);
43661- atomic_set(&tcon->num_opens, 0);
43662- atomic_set(&tcon->num_posixopens, 0);
43663- atomic_set(&tcon->num_posixmkdirs, 0);
43664- atomic_set(&tcon->num_closes, 0);
43665- atomic_set(&tcon->num_deletes, 0);
43666- atomic_set(&tcon->num_mkdirs, 0);
43667- atomic_set(&tcon->num_rmdirs, 0);
43668- atomic_set(&tcon->num_renames, 0);
43669- atomic_set(&tcon->num_t2renames, 0);
43670- atomic_set(&tcon->num_ffirst, 0);
43671- atomic_set(&tcon->num_fnext, 0);
43672- atomic_set(&tcon->num_fclose, 0);
43673- atomic_set(&tcon->num_hardlinks, 0);
43674- atomic_set(&tcon->num_symlinks, 0);
43675- atomic_set(&tcon->num_locks, 0);
43676+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
43677+ atomic_set_unchecked(&tcon->num_writes, 0);
43678+ atomic_set_unchecked(&tcon->num_reads, 0);
43679+ atomic_set_unchecked(&tcon->num_oplock_brks, 0);
43680+ atomic_set_unchecked(&tcon->num_opens, 0);
43681+ atomic_set_unchecked(&tcon->num_posixopens, 0);
43682+ atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
43683+ atomic_set_unchecked(&tcon->num_closes, 0);
43684+ atomic_set_unchecked(&tcon->num_deletes, 0);
43685+ atomic_set_unchecked(&tcon->num_mkdirs, 0);
43686+ atomic_set_unchecked(&tcon->num_rmdirs, 0);
43687+ atomic_set_unchecked(&tcon->num_renames, 0);
43688+ atomic_set_unchecked(&tcon->num_t2renames, 0);
43689+ atomic_set_unchecked(&tcon->num_ffirst, 0);
43690+ atomic_set_unchecked(&tcon->num_fnext, 0);
43691+ atomic_set_unchecked(&tcon->num_fclose, 0);
43692+ atomic_set_unchecked(&tcon->num_hardlinks, 0);
43693+ atomic_set_unchecked(&tcon->num_symlinks, 0);
43694+ atomic_set_unchecked(&tcon->num_locks, 0);
43695 }
43696 }
43697 }
43698@@ -329,8 +329,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43699 smBufAllocCount.counter, cifs_min_small);
43700 #ifdef CONFIG_CIFS_STATS2
43701 seq_printf(m, "Total Large %d Small %d Allocations\n",
43702- atomic_read(&totBufAllocCount),
43703- atomic_read(&totSmBufAllocCount));
43704+ atomic_read_unchecked(&totBufAllocCount),
43705+ atomic_read_unchecked(&totSmBufAllocCount));
43706 #endif /* CONFIG_CIFS_STATS2 */
43707
43708 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
43709@@ -359,41 +359,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43710 if (tcon->need_reconnect)
43711 seq_puts(m, "\tDISCONNECTED ");
43712 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
43713- atomic_read(&tcon->num_smbs_sent),
43714- atomic_read(&tcon->num_oplock_brks));
43715+ atomic_read_unchecked(&tcon->num_smbs_sent),
43716+ atomic_read_unchecked(&tcon->num_oplock_brks));
43717 seq_printf(m, "\nReads: %d Bytes: %lld",
43718- atomic_read(&tcon->num_reads),
43719+ atomic_read_unchecked(&tcon->num_reads),
43720 (long long)(tcon->bytes_read));
43721 seq_printf(m, "\nWrites: %d Bytes: %lld",
43722- atomic_read(&tcon->num_writes),
43723+ atomic_read_unchecked(&tcon->num_writes),
43724 (long long)(tcon->bytes_written));
43725 seq_printf(m, "\nFlushes: %d",
43726- atomic_read(&tcon->num_flushes));
43727+ atomic_read_unchecked(&tcon->num_flushes));
43728 seq_printf(m, "\nLocks: %d HardLinks: %d "
43729 "Symlinks: %d",
43730- atomic_read(&tcon->num_locks),
43731- atomic_read(&tcon->num_hardlinks),
43732- atomic_read(&tcon->num_symlinks));
43733+ atomic_read_unchecked(&tcon->num_locks),
43734+ atomic_read_unchecked(&tcon->num_hardlinks),
43735+ atomic_read_unchecked(&tcon->num_symlinks));
43736 seq_printf(m, "\nOpens: %d Closes: %d "
43737 "Deletes: %d",
43738- atomic_read(&tcon->num_opens),
43739- atomic_read(&tcon->num_closes),
43740- atomic_read(&tcon->num_deletes));
43741+ atomic_read_unchecked(&tcon->num_opens),
43742+ atomic_read_unchecked(&tcon->num_closes),
43743+ atomic_read_unchecked(&tcon->num_deletes));
43744 seq_printf(m, "\nPosix Opens: %d "
43745 "Posix Mkdirs: %d",
43746- atomic_read(&tcon->num_posixopens),
43747- atomic_read(&tcon->num_posixmkdirs));
43748+ atomic_read_unchecked(&tcon->num_posixopens),
43749+ atomic_read_unchecked(&tcon->num_posixmkdirs));
43750 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
43751- atomic_read(&tcon->num_mkdirs),
43752- atomic_read(&tcon->num_rmdirs));
43753+ atomic_read_unchecked(&tcon->num_mkdirs),
43754+ atomic_read_unchecked(&tcon->num_rmdirs));
43755 seq_printf(m, "\nRenames: %d T2 Renames %d",
43756- atomic_read(&tcon->num_renames),
43757- atomic_read(&tcon->num_t2renames));
43758+ atomic_read_unchecked(&tcon->num_renames),
43759+ atomic_read_unchecked(&tcon->num_t2renames));
43760 seq_printf(m, "\nFindFirst: %d FNext %d "
43761 "FClose %d",
43762- atomic_read(&tcon->num_ffirst),
43763- atomic_read(&tcon->num_fnext),
43764- atomic_read(&tcon->num_fclose));
43765+ atomic_read_unchecked(&tcon->num_ffirst),
43766+ atomic_read_unchecked(&tcon->num_fnext),
43767+ atomic_read_unchecked(&tcon->num_fclose));
43768 }
43769 }
43770 }
43771diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
43772index 8b6e344..303a662 100644
43773--- a/fs/cifs/cifsfs.c
43774+++ b/fs/cifs/cifsfs.c
43775@@ -994,7 +994,7 @@ cifs_init_request_bufs(void)
43776 cifs_req_cachep = kmem_cache_create("cifs_request",
43777 CIFSMaxBufSize +
43778 MAX_CIFS_HDR_SIZE, 0,
43779- SLAB_HWCACHE_ALIGN, NULL);
43780+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
43781 if (cifs_req_cachep == NULL)
43782 return -ENOMEM;
43783
43784@@ -1021,7 +1021,7 @@ cifs_init_request_bufs(void)
43785 efficient to alloc 1 per page off the slab compared to 17K (5page)
43786 alloc of large cifs buffers even when page debugging is on */
43787 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
43788- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
43789+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
43790 NULL);
43791 if (cifs_sm_req_cachep == NULL) {
43792 mempool_destroy(cifs_req_poolp);
43793@@ -1106,8 +1106,8 @@ init_cifs(void)
43794 atomic_set(&bufAllocCount, 0);
43795 atomic_set(&smBufAllocCount, 0);
43796 #ifdef CONFIG_CIFS_STATS2
43797- atomic_set(&totBufAllocCount, 0);
43798- atomic_set(&totSmBufAllocCount, 0);
43799+ atomic_set_unchecked(&totBufAllocCount, 0);
43800+ atomic_set_unchecked(&totSmBufAllocCount, 0);
43801 #endif /* CONFIG_CIFS_STATS2 */
43802
43803 atomic_set(&midCount, 0);
43804diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
43805index d86ba9f..e80049d 100644
43806--- a/fs/cifs/cifsglob.h
43807+++ b/fs/cifs/cifsglob.h
43808@@ -491,28 +491,28 @@ struct cifs_tcon {
43809 __u16 Flags; /* optional support bits */
43810 enum statusEnum tidStatus;
43811 #ifdef CONFIG_CIFS_STATS
43812- atomic_t num_smbs_sent;
43813- atomic_t num_writes;
43814- atomic_t num_reads;
43815- atomic_t num_flushes;
43816- atomic_t num_oplock_brks;
43817- atomic_t num_opens;
43818- atomic_t num_closes;
43819- atomic_t num_deletes;
43820- atomic_t num_mkdirs;
43821- atomic_t num_posixopens;
43822- atomic_t num_posixmkdirs;
43823- atomic_t num_rmdirs;
43824- atomic_t num_renames;
43825- atomic_t num_t2renames;
43826- atomic_t num_ffirst;
43827- atomic_t num_fnext;
43828- atomic_t num_fclose;
43829- atomic_t num_hardlinks;
43830- atomic_t num_symlinks;
43831- atomic_t num_locks;
43832- atomic_t num_acl_get;
43833- atomic_t num_acl_set;
43834+ atomic_unchecked_t num_smbs_sent;
43835+ atomic_unchecked_t num_writes;
43836+ atomic_unchecked_t num_reads;
43837+ atomic_unchecked_t num_flushes;
43838+ atomic_unchecked_t num_oplock_brks;
43839+ atomic_unchecked_t num_opens;
43840+ atomic_unchecked_t num_closes;
43841+ atomic_unchecked_t num_deletes;
43842+ atomic_unchecked_t num_mkdirs;
43843+ atomic_unchecked_t num_posixopens;
43844+ atomic_unchecked_t num_posixmkdirs;
43845+ atomic_unchecked_t num_rmdirs;
43846+ atomic_unchecked_t num_renames;
43847+ atomic_unchecked_t num_t2renames;
43848+ atomic_unchecked_t num_ffirst;
43849+ atomic_unchecked_t num_fnext;
43850+ atomic_unchecked_t num_fclose;
43851+ atomic_unchecked_t num_hardlinks;
43852+ atomic_unchecked_t num_symlinks;
43853+ atomic_unchecked_t num_locks;
43854+ atomic_unchecked_t num_acl_get;
43855+ atomic_unchecked_t num_acl_set;
43856 #ifdef CONFIG_CIFS_STATS2
43857 unsigned long long time_writes;
43858 unsigned long long time_reads;
43859@@ -735,7 +735,7 @@ convert_delimiter(char *path, char delim)
43860 }
43861
43862 #ifdef CONFIG_CIFS_STATS
43863-#define cifs_stats_inc atomic_inc
43864+#define cifs_stats_inc atomic_inc_unchecked
43865
43866 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
43867 unsigned int bytes)
43868@@ -1093,8 +1093,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
43869 /* Various Debug counters */
43870 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
43871 #ifdef CONFIG_CIFS_STATS2
43872-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
43873-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
43874+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
43875+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
43876 #endif
43877 GLOBAL_EXTERN atomic_t smBufAllocCount;
43878 GLOBAL_EXTERN atomic_t midCount;
43879diff --git a/fs/cifs/link.c b/fs/cifs/link.c
43880index 6b0e064..94e6c3c 100644
43881--- a/fs/cifs/link.c
43882+++ b/fs/cifs/link.c
43883@@ -600,7 +600,7 @@ symlink_exit:
43884
43885 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
43886 {
43887- char *p = nd_get_link(nd);
43888+ const char *p = nd_get_link(nd);
43889 if (!IS_ERR(p))
43890 kfree(p);
43891 }
43892diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
43893index 557506a..2fd3816 100644
43894--- a/fs/cifs/misc.c
43895+++ b/fs/cifs/misc.c
43896@@ -156,7 +156,7 @@ cifs_buf_get(void)
43897 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
43898 atomic_inc(&bufAllocCount);
43899 #ifdef CONFIG_CIFS_STATS2
43900- atomic_inc(&totBufAllocCount);
43901+ atomic_inc_unchecked(&totBufAllocCount);
43902 #endif /* CONFIG_CIFS_STATS2 */
43903 }
43904
43905@@ -191,7 +191,7 @@ cifs_small_buf_get(void)
43906 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
43907 atomic_inc(&smBufAllocCount);
43908 #ifdef CONFIG_CIFS_STATS2
43909- atomic_inc(&totSmBufAllocCount);
43910+ atomic_inc_unchecked(&totSmBufAllocCount);
43911 #endif /* CONFIG_CIFS_STATS2 */
43912
43913 }
43914diff --git a/fs/coda/cache.c b/fs/coda/cache.c
43915index 6901578..d402eb5 100644
43916--- a/fs/coda/cache.c
43917+++ b/fs/coda/cache.c
43918@@ -24,7 +24,7 @@
43919 #include "coda_linux.h"
43920 #include "coda_cache.h"
43921
43922-static atomic_t permission_epoch = ATOMIC_INIT(0);
43923+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
43924
43925 /* replace or extend an acl cache hit */
43926 void coda_cache_enter(struct inode *inode, int mask)
43927@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
43928 struct coda_inode_info *cii = ITOC(inode);
43929
43930 spin_lock(&cii->c_lock);
43931- cii->c_cached_epoch = atomic_read(&permission_epoch);
43932+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
43933 if (cii->c_uid != current_fsuid()) {
43934 cii->c_uid = current_fsuid();
43935 cii->c_cached_perm = mask;
43936@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
43937 {
43938 struct coda_inode_info *cii = ITOC(inode);
43939 spin_lock(&cii->c_lock);
43940- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
43941+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
43942 spin_unlock(&cii->c_lock);
43943 }
43944
43945 /* remove all acl caches */
43946 void coda_cache_clear_all(struct super_block *sb)
43947 {
43948- atomic_inc(&permission_epoch);
43949+ atomic_inc_unchecked(&permission_epoch);
43950 }
43951
43952
43953@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
43954 spin_lock(&cii->c_lock);
43955 hit = (mask & cii->c_cached_perm) == mask &&
43956 cii->c_uid == current_fsuid() &&
43957- cii->c_cached_epoch == atomic_read(&permission_epoch);
43958+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
43959 spin_unlock(&cii->c_lock);
43960
43961 return hit;
43962diff --git a/fs/compat.c b/fs/compat.c
43963index 6161255..9f28287 100644
43964--- a/fs/compat.c
43965+++ b/fs/compat.c
43966@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
43967
43968 set_fs(KERNEL_DS);
43969 /* The __user pointer cast is valid because of the set_fs() */
43970- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
43971+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
43972 set_fs(oldfs);
43973 /* truncating is ok because it's a user address */
43974 if (!ret)
43975@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
43976 goto out;
43977
43978 ret = -EINVAL;
43979- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
43980+ if (nr_segs > UIO_MAXIOV)
43981 goto out;
43982 if (nr_segs > fast_segs) {
43983 ret = -ENOMEM;
43984@@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
43985
43986 struct compat_readdir_callback {
43987 struct compat_old_linux_dirent __user *dirent;
43988+ struct file * file;
43989 int result;
43990 };
43991
43992@@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
43993 buf->result = -EOVERFLOW;
43994 return -EOVERFLOW;
43995 }
43996+
43997+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43998+ return 0;
43999+
44000 buf->result++;
44001 dirent = buf->dirent;
44002 if (!access_ok(VERIFY_WRITE, dirent,
44003@@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
44004
44005 buf.result = 0;
44006 buf.dirent = dirent;
44007+ buf.file = file;
44008
44009 error = vfs_readdir(file, compat_fillonedir, &buf);
44010 if (buf.result)
44011@@ -899,6 +905,7 @@ struct compat_linux_dirent {
44012 struct compat_getdents_callback {
44013 struct compat_linux_dirent __user *current_dir;
44014 struct compat_linux_dirent __user *previous;
44015+ struct file * file;
44016 int count;
44017 int error;
44018 };
44019@@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
44020 buf->error = -EOVERFLOW;
44021 return -EOVERFLOW;
44022 }
44023+
44024+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44025+ return 0;
44026+
44027 dirent = buf->previous;
44028 if (dirent) {
44029 if (__put_user(offset, &dirent->d_off))
44030@@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44031 buf.previous = NULL;
44032 buf.count = count;
44033 buf.error = 0;
44034+ buf.file = file;
44035
44036 error = vfs_readdir(file, compat_filldir, &buf);
44037 if (error >= 0)
44038@@ -986,6 +998,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44039 struct compat_getdents_callback64 {
44040 struct linux_dirent64 __user *current_dir;
44041 struct linux_dirent64 __user *previous;
44042+ struct file * file;
44043 int count;
44044 int error;
44045 };
44046@@ -1002,6 +1015,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
44047 buf->error = -EINVAL; /* only used if we fail.. */
44048 if (reclen > buf->count)
44049 return -EINVAL;
44050+
44051+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44052+ return 0;
44053+
44054 dirent = buf->previous;
44055
44056 if (dirent) {
44057@@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
44058 buf.previous = NULL;
44059 buf.count = count;
44060 buf.error = 0;
44061+ buf.file = file;
44062
44063 error = vfs_readdir(file, compat_filldir64, &buf);
44064 if (error >= 0)
44065 error = buf.error;
44066 lastdirent = buf.previous;
44067 if (lastdirent) {
44068- typeof(lastdirent->d_off) d_off = file->f_pos;
44069+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
44070 if (__put_user_unaligned(d_off, &lastdirent->d_off))
44071 error = -EFAULT;
44072 else
44073@@ -1155,11 +1173,14 @@ compat_sys_readv(unsigned long fd, const struct compat_iovec __user *vec,
44074 struct file *file;
44075 int fput_needed;
44076 ssize_t ret;
44077+ loff_t pos;
44078
44079 file = fget_light(fd, &fput_needed);
44080 if (!file)
44081 return -EBADF;
44082- ret = compat_readv(file, vec, vlen, &file->f_pos);
44083+ pos = file->f_pos;
44084+ ret = compat_readv(file, vec, vlen, &pos);
44085+ file->f_pos = pos;
44086 fput_light(file, fput_needed);
44087 return ret;
44088 }
44089@@ -1221,11 +1242,14 @@ compat_sys_writev(unsigned long fd, const struct compat_iovec __user *vec,
44090 struct file *file;
44091 int fput_needed;
44092 ssize_t ret;
44093+ loff_t pos;
44094
44095 file = fget_light(fd, &fput_needed);
44096 if (!file)
44097 return -EBADF;
44098- ret = compat_writev(file, vec, vlen, &file->f_pos);
44099+ pos = file->f_pos;
44100+ ret = compat_writev(file, vec, vlen, &pos);
44101+ file->f_pos = pos;
44102 fput_light(file, fput_needed);
44103 return ret;
44104 }
44105diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
44106index 112e45a..b59845b 100644
44107--- a/fs/compat_binfmt_elf.c
44108+++ b/fs/compat_binfmt_elf.c
44109@@ -30,11 +30,13 @@
44110 #undef elf_phdr
44111 #undef elf_shdr
44112 #undef elf_note
44113+#undef elf_dyn
44114 #undef elf_addr_t
44115 #define elfhdr elf32_hdr
44116 #define elf_phdr elf32_phdr
44117 #define elf_shdr elf32_shdr
44118 #define elf_note elf32_note
44119+#define elf_dyn Elf32_Dyn
44120 #define elf_addr_t Elf32_Addr
44121
44122 /*
44123diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
44124index debdfe0..75d31d4 100644
44125--- a/fs/compat_ioctl.c
44126+++ b/fs/compat_ioctl.c
44127@@ -210,6 +210,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
44128
44129 err = get_user(palp, &up->palette);
44130 err |= get_user(length, &up->length);
44131+ if (err)
44132+ return -EFAULT;
44133
44134 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
44135 err = put_user(compat_ptr(palp), &up_native->palette);
44136@@ -621,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
44137 return -EFAULT;
44138 if (__get_user(udata, &ss32->iomem_base))
44139 return -EFAULT;
44140- ss.iomem_base = compat_ptr(udata);
44141+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
44142 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
44143 __get_user(ss.port_high, &ss32->port_high))
44144 return -EFAULT;
44145@@ -796,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
44146 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
44147 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
44148 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
44149- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44150+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44151 return -EFAULT;
44152
44153 return ioctl_preallocate(file, p);
44154@@ -1610,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
44155 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
44156 {
44157 unsigned int a, b;
44158- a = *(unsigned int *)p;
44159- b = *(unsigned int *)q;
44160+ a = *(const unsigned int *)p;
44161+ b = *(const unsigned int *)q;
44162 if (a > b)
44163 return 1;
44164 if (a < b)
44165diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
44166index 7e6c52d..94bc756 100644
44167--- a/fs/configfs/dir.c
44168+++ b/fs/configfs/dir.c
44169@@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44170 }
44171 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
44172 struct configfs_dirent *next;
44173- const char * name;
44174+ const unsigned char * name;
44175+ char d_name[sizeof(next->s_dentry->d_iname)];
44176 int len;
44177 struct inode *inode = NULL;
44178
44179@@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44180 continue;
44181
44182 name = configfs_get_name(next);
44183- len = strlen(name);
44184+ if (next->s_dentry && name == next->s_dentry->d_iname) {
44185+ len = next->s_dentry->d_name.len;
44186+ memcpy(d_name, name, len);
44187+ name = d_name;
44188+ } else
44189+ len = strlen(name);
44190
44191 /*
44192 * We'll have a dentry and an inode for
44193diff --git a/fs/dcache.c b/fs/dcache.c
44194index 4046904..5e31505 100644
44195--- a/fs/dcache.c
44196+++ b/fs/dcache.c
44197@@ -3154,7 +3154,7 @@ void __init vfs_caches_init(unsigned long mempages)
44198 mempages -= reserve;
44199
44200 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
44201- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
44202+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
44203
44204 dcache_init();
44205 inode_init();
44206diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
44207index b80bc84..0d46d1a 100644
44208--- a/fs/debugfs/inode.c
44209+++ b/fs/debugfs/inode.c
44210@@ -408,7 +408,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
44211 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
44212 {
44213 return debugfs_create_file(name,
44214+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
44215+ S_IFDIR | S_IRWXU,
44216+#else
44217 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
44218+#endif
44219 parent, NULL, NULL);
44220 }
44221 EXPORT_SYMBOL_GPL(debugfs_create_dir);
44222diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
44223index a07441a..046fc0d 100644
44224--- a/fs/ecryptfs/inode.c
44225+++ b/fs/ecryptfs/inode.c
44226@@ -671,7 +671,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
44227 old_fs = get_fs();
44228 set_fs(get_ds());
44229 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
44230- (char __user *)lower_buf,
44231+ (char __force_user *)lower_buf,
44232 PATH_MAX);
44233 set_fs(old_fs);
44234 if (rc < 0)
44235@@ -703,7 +703,7 @@ out:
44236 static void
44237 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
44238 {
44239- char *buf = nd_get_link(nd);
44240+ const char *buf = nd_get_link(nd);
44241 if (!IS_ERR(buf)) {
44242 /* Free the char* */
44243 kfree(buf);
44244diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
44245index c0038f6..47ab347 100644
44246--- a/fs/ecryptfs/miscdev.c
44247+++ b/fs/ecryptfs/miscdev.c
44248@@ -355,7 +355,7 @@ check_list:
44249 goto out_unlock_msg_ctx;
44250 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
44251 if (msg_ctx->msg) {
44252- if (copy_to_user(&buf[i], packet_length, packet_length_size))
44253+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
44254 goto out_unlock_msg_ctx;
44255 i += packet_length_size;
44256 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
44257diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
44258index b2a34a1..162fa69 100644
44259--- a/fs/ecryptfs/read_write.c
44260+++ b/fs/ecryptfs/read_write.c
44261@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
44262 return -EIO;
44263 fs_save = get_fs();
44264 set_fs(get_ds());
44265- rc = vfs_write(lower_file, data, size, &offset);
44266+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
44267 set_fs(fs_save);
44268 mark_inode_dirty_sync(ecryptfs_inode);
44269 return rc;
44270@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
44271 return -EIO;
44272 fs_save = get_fs();
44273 set_fs(get_ds());
44274- rc = vfs_read(lower_file, data, size, &offset);
44275+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
44276 set_fs(fs_save);
44277 return rc;
44278 }
44279diff --git a/fs/eventpoll.c b/fs/eventpoll.c
44280index 1c8b556..eedec84 100644
44281--- a/fs/eventpoll.c
44282+++ b/fs/eventpoll.c
44283@@ -1654,8 +1654,8 @@ SYSCALL_DEFINE1(epoll_create1, int, flags)
44284 error = PTR_ERR(file);
44285 goto out_free_fd;
44286 }
44287- fd_install(fd, file);
44288 ep->file = file;
44289+ fd_install(fd, file);
44290 return fd;
44291
44292 out_free_fd:
44293diff --git a/fs/exec.c b/fs/exec.c
44294index e95aeed..a943469 100644
44295--- a/fs/exec.c
44296+++ b/fs/exec.c
44297@@ -55,6 +55,15 @@
44298 #include <linux/pipe_fs_i.h>
44299 #include <linux/oom.h>
44300 #include <linux/compat.h>
44301+#include <linux/random.h>
44302+#include <linux/seq_file.h>
44303+
44304+#ifdef CONFIG_PAX_REFCOUNT
44305+#include <linux/kallsyms.h>
44306+#include <linux/kdebug.h>
44307+#endif
44308+
44309+#include <trace/events/fs.h>
44310
44311 #include <asm/uaccess.h>
44312 #include <asm/mmu_context.h>
44313@@ -66,6 +75,18 @@
44314
44315 #include <trace/events/sched.h>
44316
44317+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
44318+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
44319+{
44320+ 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");
44321+}
44322+#endif
44323+
44324+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
44325+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
44326+EXPORT_SYMBOL(pax_set_initial_flags_func);
44327+#endif
44328+
44329 int core_uses_pid;
44330 char core_pattern[CORENAME_MAX_SIZE] = "core";
44331 unsigned int core_pipe_limit;
44332@@ -75,7 +96,7 @@ struct core_name {
44333 char *corename;
44334 int used, size;
44335 };
44336-static atomic_t call_count = ATOMIC_INIT(1);
44337+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
44338
44339 /* The maximal length of core_pattern is also specified in sysctl.c */
44340
44341@@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44342 int write)
44343 {
44344 struct page *page;
44345- int ret;
44346
44347-#ifdef CONFIG_STACK_GROWSUP
44348- if (write) {
44349- ret = expand_downwards(bprm->vma, pos);
44350- if (ret < 0)
44351- return NULL;
44352- }
44353-#endif
44354- ret = get_user_pages(current, bprm->mm, pos,
44355- 1, write, 1, &page, NULL);
44356- if (ret <= 0)
44357+ if (0 > expand_downwards(bprm->vma, pos))
44358+ return NULL;
44359+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
44360 return NULL;
44361
44362 if (write) {
44363@@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44364 if (size <= ARG_MAX)
44365 return page;
44366
44367+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44368+ // only allow 512KB for argv+env on suid/sgid binaries
44369+ // to prevent easy ASLR exhaustion
44370+ if (((bprm->cred->euid != current_euid()) ||
44371+ (bprm->cred->egid != current_egid())) &&
44372+ (size > (512 * 1024))) {
44373+ put_page(page);
44374+ return NULL;
44375+ }
44376+#endif
44377+
44378 /*
44379 * Limit to 1/4-th the stack size for the argv+env strings.
44380 * This ensures that:
44381@@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44382 vma->vm_end = STACK_TOP_MAX;
44383 vma->vm_start = vma->vm_end - PAGE_SIZE;
44384 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
44385+
44386+#ifdef CONFIG_PAX_SEGMEXEC
44387+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
44388+#endif
44389+
44390 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
44391 INIT_LIST_HEAD(&vma->anon_vma_chain);
44392
44393@@ -287,6 +316,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44394 mm->stack_vm = mm->total_vm = 1;
44395 up_write(&mm->mmap_sem);
44396 bprm->p = vma->vm_end - sizeof(void *);
44397+
44398+#ifdef CONFIG_PAX_RANDUSTACK
44399+ if (randomize_va_space)
44400+ bprm->p ^= random32() & ~PAGE_MASK;
44401+#endif
44402+
44403 return 0;
44404 err:
44405 up_write(&mm->mmap_sem);
44406@@ -395,19 +430,7 @@ err:
44407 return err;
44408 }
44409
44410-struct user_arg_ptr {
44411-#ifdef CONFIG_COMPAT
44412- bool is_compat;
44413-#endif
44414- union {
44415- const char __user *const __user *native;
44416-#ifdef CONFIG_COMPAT
44417- compat_uptr_t __user *compat;
44418-#endif
44419- } ptr;
44420-};
44421-
44422-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44423+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44424 {
44425 const char __user *native;
44426
44427@@ -416,14 +439,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44428 compat_uptr_t compat;
44429
44430 if (get_user(compat, argv.ptr.compat + nr))
44431- return ERR_PTR(-EFAULT);
44432+ return (const char __force_user *)ERR_PTR(-EFAULT);
44433
44434 return compat_ptr(compat);
44435 }
44436 #endif
44437
44438 if (get_user(native, argv.ptr.native + nr))
44439- return ERR_PTR(-EFAULT);
44440+ return (const char __force_user *)ERR_PTR(-EFAULT);
44441
44442 return native;
44443 }
44444@@ -442,7 +465,7 @@ static int count(struct user_arg_ptr argv, int max)
44445 if (!p)
44446 break;
44447
44448- if (IS_ERR(p))
44449+ if (IS_ERR((const char __force_kernel *)p))
44450 return -EFAULT;
44451
44452 if (i++ >= max)
44453@@ -476,7 +499,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
44454
44455 ret = -EFAULT;
44456 str = get_user_arg_ptr(argv, argc);
44457- if (IS_ERR(str))
44458+ if (IS_ERR((const char __force_kernel *)str))
44459 goto out;
44460
44461 len = strnlen_user(str, MAX_ARG_STRLEN);
44462@@ -558,7 +581,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
44463 int r;
44464 mm_segment_t oldfs = get_fs();
44465 struct user_arg_ptr argv = {
44466- .ptr.native = (const char __user *const __user *)__argv,
44467+ .ptr.native = (const char __force_user *const __force_user *)__argv,
44468 };
44469
44470 set_fs(KERNEL_DS);
44471@@ -593,7 +616,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44472 unsigned long new_end = old_end - shift;
44473 struct mmu_gather tlb;
44474
44475- BUG_ON(new_start > new_end);
44476+ if (new_start >= new_end || new_start < mmap_min_addr)
44477+ return -ENOMEM;
44478
44479 /*
44480 * ensure there are no vmas between where we want to go
44481@@ -602,6 +626,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44482 if (vma != find_vma(mm, new_start))
44483 return -EFAULT;
44484
44485+#ifdef CONFIG_PAX_SEGMEXEC
44486+ BUG_ON(pax_find_mirror_vma(vma));
44487+#endif
44488+
44489 /*
44490 * cover the whole range: [new_start, old_end)
44491 */
44492@@ -682,10 +710,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44493 stack_top = arch_align_stack(stack_top);
44494 stack_top = PAGE_ALIGN(stack_top);
44495
44496- if (unlikely(stack_top < mmap_min_addr) ||
44497- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
44498- return -ENOMEM;
44499-
44500 stack_shift = vma->vm_end - stack_top;
44501
44502 bprm->p -= stack_shift;
44503@@ -697,8 +721,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
44504 bprm->exec -= stack_shift;
44505
44506 down_write(&mm->mmap_sem);
44507+
44508+ /* Move stack pages down in memory. */
44509+ if (stack_shift) {
44510+ ret = shift_arg_pages(vma, stack_shift);
44511+ if (ret)
44512+ goto out_unlock;
44513+ }
44514+
44515 vm_flags = VM_STACK_FLAGS;
44516
44517+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44518+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44519+ vm_flags &= ~VM_EXEC;
44520+
44521+#ifdef CONFIG_PAX_MPROTECT
44522+ if (mm->pax_flags & MF_PAX_MPROTECT)
44523+ vm_flags &= ~VM_MAYEXEC;
44524+#endif
44525+
44526+ }
44527+#endif
44528+
44529 /*
44530 * Adjust stack execute permissions; explicitly enable for
44531 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
44532@@ -717,13 +761,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44533 goto out_unlock;
44534 BUG_ON(prev != vma);
44535
44536- /* Move stack pages down in memory. */
44537- if (stack_shift) {
44538- ret = shift_arg_pages(vma, stack_shift);
44539- if (ret)
44540- goto out_unlock;
44541- }
44542-
44543 /* mprotect_fixup is overkill to remove the temporary stack flags */
44544 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
44545
44546@@ -781,6 +818,8 @@ struct file *open_exec(const char *name)
44547
44548 fsnotify_open(file);
44549
44550+ trace_open_exec(name);
44551+
44552 err = deny_write_access(file);
44553 if (err)
44554 goto exit;
44555@@ -804,7 +843,7 @@ int kernel_read(struct file *file, loff_t offset,
44556 old_fs = get_fs();
44557 set_fs(get_ds());
44558 /* The cast to a user pointer is valid due to the set_fs() */
44559- result = vfs_read(file, (void __user *)addr, count, &pos);
44560+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
44561 set_fs(old_fs);
44562 return result;
44563 }
44564@@ -1257,7 +1296,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
44565 }
44566 rcu_read_unlock();
44567
44568- if (p->fs->users > n_fs) {
44569+ if (atomic_read(&p->fs->users) > n_fs) {
44570 bprm->unsafe |= LSM_UNSAFE_SHARE;
44571 } else {
44572 res = -EAGAIN;
44573@@ -1460,6 +1499,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
44574
44575 EXPORT_SYMBOL(search_binary_handler);
44576
44577+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44578+static DEFINE_PER_CPU(u64, exec_counter);
44579+static int __init init_exec_counters(void)
44580+{
44581+ unsigned int cpu;
44582+
44583+ for_each_possible_cpu(cpu) {
44584+ per_cpu(exec_counter, cpu) = (u64)cpu;
44585+ }
44586+
44587+ return 0;
44588+}
44589+early_initcall(init_exec_counters);
44590+static inline void increment_exec_counter(void)
44591+{
44592+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
44593+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
44594+}
44595+#else
44596+static inline void increment_exec_counter(void) {}
44597+#endif
44598+
44599 /*
44600 * sys_execve() executes a new program.
44601 */
44602@@ -1468,6 +1529,11 @@ static int do_execve_common(const char *filename,
44603 struct user_arg_ptr envp,
44604 struct pt_regs *regs)
44605 {
44606+#ifdef CONFIG_GRKERNSEC
44607+ struct file *old_exec_file;
44608+ struct acl_subject_label *old_acl;
44609+ struct rlimit old_rlim[RLIM_NLIMITS];
44610+#endif
44611 struct linux_binprm *bprm;
44612 struct file *file;
44613 struct files_struct *displaced;
44614@@ -1475,6 +1541,8 @@ static int do_execve_common(const char *filename,
44615 int retval;
44616 const struct cred *cred = current_cred();
44617
44618+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
44619+
44620 /*
44621 * We move the actual failure in case of RLIMIT_NPROC excess from
44622 * set*uid() to execve() because too many poorly written programs
44623@@ -1515,12 +1583,27 @@ static int do_execve_common(const char *filename,
44624 if (IS_ERR(file))
44625 goto out_unmark;
44626
44627+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
44628+ retval = -EPERM;
44629+ goto out_file;
44630+ }
44631+
44632 sched_exec();
44633
44634 bprm->file = file;
44635 bprm->filename = filename;
44636 bprm->interp = filename;
44637
44638+ if (gr_process_user_ban()) {
44639+ retval = -EPERM;
44640+ goto out_file;
44641+ }
44642+
44643+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
44644+ retval = -EACCES;
44645+ goto out_file;
44646+ }
44647+
44648 retval = bprm_mm_init(bprm);
44649 if (retval)
44650 goto out_file;
44651@@ -1537,24 +1620,65 @@ static int do_execve_common(const char *filename,
44652 if (retval < 0)
44653 goto out;
44654
44655+#ifdef CONFIG_GRKERNSEC
44656+ old_acl = current->acl;
44657+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
44658+ old_exec_file = current->exec_file;
44659+ get_file(file);
44660+ current->exec_file = file;
44661+#endif
44662+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44663+ /* limit suid stack to 8MB
44664+ we saved the old limits above and will restore them if this exec fails
44665+ */
44666+ if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
44667+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
44668+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
44669+#endif
44670+
44671+ if (!gr_tpe_allow(file)) {
44672+ retval = -EACCES;
44673+ goto out_fail;
44674+ }
44675+
44676+ if (gr_check_crash_exec(file)) {
44677+ retval = -EACCES;
44678+ goto out_fail;
44679+ }
44680+
44681+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
44682+ bprm->unsafe);
44683+ if (retval < 0)
44684+ goto out_fail;
44685+
44686 retval = copy_strings_kernel(1, &bprm->filename, bprm);
44687 if (retval < 0)
44688- goto out;
44689+ goto out_fail;
44690
44691 bprm->exec = bprm->p;
44692 retval = copy_strings(bprm->envc, envp, bprm);
44693 if (retval < 0)
44694- goto out;
44695+ goto out_fail;
44696
44697 retval = copy_strings(bprm->argc, argv, bprm);
44698 if (retval < 0)
44699- goto out;
44700+ goto out_fail;
44701+
44702+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
44703+
44704+ gr_handle_exec_args(bprm, argv);
44705
44706 retval = search_binary_handler(bprm,regs);
44707 if (retval < 0)
44708- goto out;
44709+ goto out_fail;
44710+#ifdef CONFIG_GRKERNSEC
44711+ if (old_exec_file)
44712+ fput(old_exec_file);
44713+#endif
44714
44715 /* execve succeeded */
44716+
44717+ increment_exec_counter();
44718 current->fs->in_exec = 0;
44719 current->in_execve = 0;
44720 acct_update_integrals(current);
44721@@ -1563,6 +1687,14 @@ static int do_execve_common(const char *filename,
44722 put_files_struct(displaced);
44723 return retval;
44724
44725+out_fail:
44726+#ifdef CONFIG_GRKERNSEC
44727+ current->acl = old_acl;
44728+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
44729+ fput(current->exec_file);
44730+ current->exec_file = old_exec_file;
44731+#endif
44732+
44733 out:
44734 if (bprm->mm) {
44735 acct_arg_size(bprm, 0);
44736@@ -1636,7 +1768,7 @@ static int expand_corename(struct core_name *cn)
44737 {
44738 char *old_corename = cn->corename;
44739
44740- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
44741+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
44742 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
44743
44744 if (!cn->corename) {
44745@@ -1733,7 +1865,7 @@ static int format_corename(struct core_name *cn, long signr)
44746 int pid_in_pattern = 0;
44747 int err = 0;
44748
44749- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
44750+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
44751 cn->corename = kmalloc(cn->size, GFP_KERNEL);
44752 cn->used = 0;
44753
44754@@ -1830,6 +1962,250 @@ out:
44755 return ispipe;
44756 }
44757
44758+int pax_check_flags(unsigned long *flags)
44759+{
44760+ int retval = 0;
44761+
44762+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
44763+ if (*flags & MF_PAX_SEGMEXEC)
44764+ {
44765+ *flags &= ~MF_PAX_SEGMEXEC;
44766+ retval = -EINVAL;
44767+ }
44768+#endif
44769+
44770+ if ((*flags & MF_PAX_PAGEEXEC)
44771+
44772+#ifdef CONFIG_PAX_PAGEEXEC
44773+ && (*flags & MF_PAX_SEGMEXEC)
44774+#endif
44775+
44776+ )
44777+ {
44778+ *flags &= ~MF_PAX_PAGEEXEC;
44779+ retval = -EINVAL;
44780+ }
44781+
44782+ if ((*flags & MF_PAX_MPROTECT)
44783+
44784+#ifdef CONFIG_PAX_MPROTECT
44785+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44786+#endif
44787+
44788+ )
44789+ {
44790+ *flags &= ~MF_PAX_MPROTECT;
44791+ retval = -EINVAL;
44792+ }
44793+
44794+ if ((*flags & MF_PAX_EMUTRAMP)
44795+
44796+#ifdef CONFIG_PAX_EMUTRAMP
44797+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44798+#endif
44799+
44800+ )
44801+ {
44802+ *flags &= ~MF_PAX_EMUTRAMP;
44803+ retval = -EINVAL;
44804+ }
44805+
44806+ return retval;
44807+}
44808+
44809+EXPORT_SYMBOL(pax_check_flags);
44810+
44811+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44812+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
44813+{
44814+ struct task_struct *tsk = current;
44815+ struct mm_struct *mm = current->mm;
44816+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
44817+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
44818+ char *path_exec = NULL;
44819+ char *path_fault = NULL;
44820+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
44821+
44822+ if (buffer_exec && buffer_fault) {
44823+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
44824+
44825+ down_read(&mm->mmap_sem);
44826+ vma = mm->mmap;
44827+ while (vma && (!vma_exec || !vma_fault)) {
44828+ if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
44829+ vma_exec = vma;
44830+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
44831+ vma_fault = vma;
44832+ vma = vma->vm_next;
44833+ }
44834+ if (vma_exec) {
44835+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
44836+ if (IS_ERR(path_exec))
44837+ path_exec = "<path too long>";
44838+ else {
44839+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
44840+ if (path_exec) {
44841+ *path_exec = 0;
44842+ path_exec = buffer_exec;
44843+ } else
44844+ path_exec = "<path too long>";
44845+ }
44846+ }
44847+ if (vma_fault) {
44848+ start = vma_fault->vm_start;
44849+ end = vma_fault->vm_end;
44850+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
44851+ if (vma_fault->vm_file) {
44852+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
44853+ if (IS_ERR(path_fault))
44854+ path_fault = "<path too long>";
44855+ else {
44856+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
44857+ if (path_fault) {
44858+ *path_fault = 0;
44859+ path_fault = buffer_fault;
44860+ } else
44861+ path_fault = "<path too long>";
44862+ }
44863+ } else
44864+ path_fault = "<anonymous mapping>";
44865+ }
44866+ up_read(&mm->mmap_sem);
44867+ }
44868+ if (tsk->signal->curr_ip)
44869+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
44870+ else
44871+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
44872+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
44873+ "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
44874+ task_uid(tsk), task_euid(tsk), pc, sp);
44875+ free_page((unsigned long)buffer_exec);
44876+ free_page((unsigned long)buffer_fault);
44877+ pax_report_insns(regs, pc, sp);
44878+ do_coredump(SIGKILL, SIGKILL, regs);
44879+}
44880+#endif
44881+
44882+#ifdef CONFIG_PAX_REFCOUNT
44883+void pax_report_refcount_overflow(struct pt_regs *regs)
44884+{
44885+ if (current->signal->curr_ip)
44886+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44887+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
44888+ else
44889+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44890+ current->comm, task_pid_nr(current), current_uid(), current_euid());
44891+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
44892+ show_regs(regs);
44893+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
44894+}
44895+#endif
44896+
44897+#ifdef CONFIG_PAX_USERCOPY
44898+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
44899+static noinline int check_stack_object(const void *obj, unsigned long len)
44900+{
44901+ const void * const stack = task_stack_page(current);
44902+ const void * const stackend = stack + THREAD_SIZE;
44903+
44904+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44905+ const void *frame = NULL;
44906+ const void *oldframe;
44907+#endif
44908+
44909+ if (obj + len < obj)
44910+ return -1;
44911+
44912+ if (obj + len <= stack || stackend <= obj)
44913+ return 0;
44914+
44915+ if (obj < stack || stackend < obj + len)
44916+ return -1;
44917+
44918+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44919+ oldframe = __builtin_frame_address(1);
44920+ if (oldframe)
44921+ frame = __builtin_frame_address(2);
44922+ /*
44923+ low ----------------------------------------------> high
44924+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
44925+ ^----------------^
44926+ allow copies only within here
44927+ */
44928+ while (stack <= frame && frame < stackend) {
44929+ /* if obj + len extends past the last frame, this
44930+ check won't pass and the next frame will be 0,
44931+ causing us to bail out and correctly report
44932+ the copy as invalid
44933+ */
44934+ if (obj + len <= frame)
44935+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
44936+ oldframe = frame;
44937+ frame = *(const void * const *)frame;
44938+ }
44939+ return -1;
44940+#else
44941+ return 1;
44942+#endif
44943+}
44944+
44945+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
44946+{
44947+ if (current->signal->curr_ip)
44948+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44949+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44950+ else
44951+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44952+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44953+ dump_stack();
44954+ gr_handle_kernel_exploit();
44955+ do_group_exit(SIGKILL);
44956+}
44957+#endif
44958+
44959+void check_object_size(const void *ptr, unsigned long n, bool to)
44960+{
44961+
44962+#ifdef CONFIG_PAX_USERCOPY
44963+ const char *type;
44964+
44965+ if (!n)
44966+ return;
44967+
44968+ type = check_heap_object(ptr, n, to);
44969+ if (!type) {
44970+ if (check_stack_object(ptr, n) != -1)
44971+ return;
44972+ type = "<process stack>";
44973+ }
44974+
44975+ pax_report_usercopy(ptr, n, to, type);
44976+#endif
44977+
44978+}
44979+EXPORT_SYMBOL(check_object_size);
44980+
44981+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
44982+void pax_track_stack(void)
44983+{
44984+ unsigned long sp = (unsigned long)&sp;
44985+ if (sp < current_thread_info()->lowest_stack &&
44986+ sp > (unsigned long)task_stack_page(current))
44987+ current_thread_info()->lowest_stack = sp;
44988+}
44989+EXPORT_SYMBOL(pax_track_stack);
44990+#endif
44991+
44992+#ifdef CONFIG_PAX_SIZE_OVERFLOW
44993+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
44994+{
44995+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
44996+ dump_stack();
44997+ do_group_exit(SIGKILL);
44998+}
44999+EXPORT_SYMBOL(report_size_overflow);
45000+#endif
45001+
45002 static int zap_process(struct task_struct *start, int exit_code)
45003 {
45004 struct task_struct *t;
45005@@ -2002,17 +2378,17 @@ static void coredump_finish(struct mm_struct *mm)
45006 void set_dumpable(struct mm_struct *mm, int value)
45007 {
45008 switch (value) {
45009- case 0:
45010+ case SUID_DUMPABLE_DISABLED:
45011 clear_bit(MMF_DUMPABLE, &mm->flags);
45012 smp_wmb();
45013 clear_bit(MMF_DUMP_SECURELY, &mm->flags);
45014 break;
45015- case 1:
45016+ case SUID_DUMPABLE_ENABLED:
45017 set_bit(MMF_DUMPABLE, &mm->flags);
45018 smp_wmb();
45019 clear_bit(MMF_DUMP_SECURELY, &mm->flags);
45020 break;
45021- case 2:
45022+ case SUID_DUMPABLE_SAFE:
45023 set_bit(MMF_DUMP_SECURELY, &mm->flags);
45024 smp_wmb();
45025 set_bit(MMF_DUMPABLE, &mm->flags);
45026@@ -2025,7 +2401,7 @@ static int __get_dumpable(unsigned long mm_flags)
45027 int ret;
45028
45029 ret = mm_flags & MMF_DUMPABLE_MASK;
45030- return (ret >= 2) ? 2 : ret;
45031+ return (ret > SUID_DUMPABLE_ENABLED) ? SUID_DUMPABLE_SAFE : ret;
45032 }
45033
45034 int get_dumpable(struct mm_struct *mm)
45035@@ -2040,17 +2416,17 @@ static void wait_for_dump_helpers(struct file *file)
45036 pipe = file->f_path.dentry->d_inode->i_pipe;
45037
45038 pipe_lock(pipe);
45039- pipe->readers++;
45040- pipe->writers--;
45041+ atomic_inc(&pipe->readers);
45042+ atomic_dec(&pipe->writers);
45043
45044- while ((pipe->readers > 1) && (!signal_pending(current))) {
45045+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
45046 wake_up_interruptible_sync(&pipe->wait);
45047 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45048 pipe_wait(pipe);
45049 }
45050
45051- pipe->readers--;
45052- pipe->writers++;
45053+ atomic_dec(&pipe->readers);
45054+ atomic_inc(&pipe->writers);
45055 pipe_unlock(pipe);
45056
45057 }
45058@@ -2111,7 +2487,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45059 int retval = 0;
45060 int flag = 0;
45061 int ispipe;
45062- static atomic_t core_dump_count = ATOMIC_INIT(0);
45063+ bool need_nonrelative = false;
45064+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
45065 struct coredump_params cprm = {
45066 .signr = signr,
45067 .regs = regs,
45068@@ -2126,6 +2503,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45069
45070 audit_core_dumps(signr);
45071
45072+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
45073+ gr_handle_brute_attach(current, cprm.mm_flags);
45074+
45075 binfmt = mm->binfmt;
45076 if (!binfmt || !binfmt->core_dump)
45077 goto fail;
45078@@ -2136,14 +2516,16 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45079 if (!cred)
45080 goto fail;
45081 /*
45082- * We cannot trust fsuid as being the "true" uid of the
45083- * process nor do we know its entire history. We only know it
45084- * was tainted so we dump it as root in mode 2.
45085+ * We cannot trust fsuid as being the "true" uid of the process
45086+ * nor do we know its entire history. We only know it was tainted
45087+ * so we dump it as root in mode 2, and only into a controlled
45088+ * environment (pipe handler or fully qualified path).
45089 */
45090- if (__get_dumpable(cprm.mm_flags) == 2) {
45091+ if (__get_dumpable(cprm.mm_flags) == SUID_DUMPABLE_SAFE) {
45092 /* Setuid core dump mode */
45093 flag = O_EXCL; /* Stop rewrite attacks */
45094 cred->fsuid = GLOBAL_ROOT_UID; /* Dump root private */
45095+ need_nonrelative = true;
45096 }
45097
45098 retval = coredump_wait(exit_code, &core_state);
45099@@ -2193,7 +2575,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45100 }
45101 cprm.limit = RLIM_INFINITY;
45102
45103- dump_count = atomic_inc_return(&core_dump_count);
45104+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
45105 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
45106 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
45107 task_tgid_vnr(current), current->comm);
45108@@ -2220,9 +2602,19 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45109 } else {
45110 struct inode *inode;
45111
45112+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
45113+
45114 if (cprm.limit < binfmt->min_coredump)
45115 goto fail_unlock;
45116
45117+ if (need_nonrelative && cn.corename[0] != '/') {
45118+ printk(KERN_WARNING "Pid %d(%s) can only dump core "\
45119+ "to fully qualified path!\n",
45120+ task_tgid_vnr(current), current->comm);
45121+ printk(KERN_WARNING "Skipping core dump\n");
45122+ goto fail_unlock;
45123+ }
45124+
45125 cprm.file = filp_open(cn.corename,
45126 O_CREAT | 2 | O_NOFOLLOW | O_LARGEFILE | flag,
45127 0600);
45128@@ -2263,7 +2655,7 @@ close_fail:
45129 filp_close(cprm.file, NULL);
45130 fail_dropcount:
45131 if (ispipe)
45132- atomic_dec(&core_dump_count);
45133+ atomic_dec_unchecked(&core_dump_count);
45134 fail_unlock:
45135 kfree(cn.corename);
45136 fail_corename:
45137@@ -2282,7 +2674,7 @@ fail:
45138 */
45139 int dump_write(struct file *file, const void *addr, int nr)
45140 {
45141- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
45142+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
45143 }
45144 EXPORT_SYMBOL(dump_write);
45145
45146diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
45147index 1c36139..cf6b350 100644
45148--- a/fs/ext2/balloc.c
45149+++ b/fs/ext2/balloc.c
45150@@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
45151
45152 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45153 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45154- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45155+ if (free_blocks < root_blocks + 1 &&
45156 !uid_eq(sbi->s_resuid, current_fsuid()) &&
45157 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45158- !in_group_p (sbi->s_resgid))) {
45159+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45160 return 0;
45161 }
45162 return 1;
45163diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
45164index 25cd608..9ed5294 100644
45165--- a/fs/ext3/balloc.c
45166+++ b/fs/ext3/balloc.c
45167@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
45168
45169 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45170 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45171- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45172+ if (free_blocks < root_blocks + 1 &&
45173 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
45174 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45175- !in_group_p (sbi->s_resgid))) {
45176+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45177 return 0;
45178 }
45179 return 1;
45180diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
45181index 1b50890..e56c5ad 100644
45182--- a/fs/ext4/balloc.c
45183+++ b/fs/ext4/balloc.c
45184@@ -500,8 +500,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
45185 /* Hm, nope. Are (enough) root reserved clusters available? */
45186 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
45187 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
45188- capable(CAP_SYS_RESOURCE) ||
45189- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
45190+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
45191+ capable_nolog(CAP_SYS_RESOURCE)) {
45192
45193 if (free_clusters >= (nclusters + dirty_clusters))
45194 return 1;
45195diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
45196index 01434f2..bd995b4 100644
45197--- a/fs/ext4/ext4.h
45198+++ b/fs/ext4/ext4.h
45199@@ -1246,19 +1246,19 @@ struct ext4_sb_info {
45200 unsigned long s_mb_last_start;
45201
45202 /* stats for buddy allocator */
45203- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45204- atomic_t s_bal_success; /* we found long enough chunks */
45205- atomic_t s_bal_allocated; /* in blocks */
45206- atomic_t s_bal_ex_scanned; /* total extents scanned */
45207- atomic_t s_bal_goals; /* goal hits */
45208- atomic_t s_bal_breaks; /* too long searches */
45209- atomic_t s_bal_2orders; /* 2^order hits */
45210+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45211+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45212+ atomic_unchecked_t s_bal_allocated; /* in blocks */
45213+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45214+ atomic_unchecked_t s_bal_goals; /* goal hits */
45215+ atomic_unchecked_t s_bal_breaks; /* too long searches */
45216+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45217 spinlock_t s_bal_lock;
45218 unsigned long s_mb_buddies_generated;
45219 unsigned long long s_mb_generation_time;
45220- atomic_t s_mb_lost_chunks;
45221- atomic_t s_mb_preallocated;
45222- atomic_t s_mb_discarded;
45223+ atomic_unchecked_t s_mb_lost_chunks;
45224+ atomic_unchecked_t s_mb_preallocated;
45225+ atomic_unchecked_t s_mb_discarded;
45226 atomic_t s_lock_busy;
45227
45228 /* locality groups */
45229diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
45230index 1cd6994..5799d45 100644
45231--- a/fs/ext4/mballoc.c
45232+++ b/fs/ext4/mballoc.c
45233@@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
45234 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45235
45236 if (EXT4_SB(sb)->s_mb_stats)
45237- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45238+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45239
45240 break;
45241 }
45242@@ -2041,7 +2041,7 @@ repeat:
45243 ac->ac_status = AC_STATUS_CONTINUE;
45244 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45245 cr = 3;
45246- atomic_inc(&sbi->s_mb_lost_chunks);
45247+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45248 goto repeat;
45249 }
45250 }
45251@@ -2545,25 +2545,25 @@ int ext4_mb_release(struct super_block *sb)
45252 if (sbi->s_mb_stats) {
45253 ext4_msg(sb, KERN_INFO,
45254 "mballoc: %u blocks %u reqs (%u success)",
45255- atomic_read(&sbi->s_bal_allocated),
45256- atomic_read(&sbi->s_bal_reqs),
45257- atomic_read(&sbi->s_bal_success));
45258+ atomic_read_unchecked(&sbi->s_bal_allocated),
45259+ atomic_read_unchecked(&sbi->s_bal_reqs),
45260+ atomic_read_unchecked(&sbi->s_bal_success));
45261 ext4_msg(sb, KERN_INFO,
45262 "mballoc: %u extents scanned, %u goal hits, "
45263 "%u 2^N hits, %u breaks, %u lost",
45264- atomic_read(&sbi->s_bal_ex_scanned),
45265- atomic_read(&sbi->s_bal_goals),
45266- atomic_read(&sbi->s_bal_2orders),
45267- atomic_read(&sbi->s_bal_breaks),
45268- atomic_read(&sbi->s_mb_lost_chunks));
45269+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45270+ atomic_read_unchecked(&sbi->s_bal_goals),
45271+ atomic_read_unchecked(&sbi->s_bal_2orders),
45272+ atomic_read_unchecked(&sbi->s_bal_breaks),
45273+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45274 ext4_msg(sb, KERN_INFO,
45275 "mballoc: %lu generated and it took %Lu",
45276 sbi->s_mb_buddies_generated,
45277 sbi->s_mb_generation_time);
45278 ext4_msg(sb, KERN_INFO,
45279 "mballoc: %u preallocated, %u discarded",
45280- atomic_read(&sbi->s_mb_preallocated),
45281- atomic_read(&sbi->s_mb_discarded));
45282+ atomic_read_unchecked(&sbi->s_mb_preallocated),
45283+ atomic_read_unchecked(&sbi->s_mb_discarded));
45284 }
45285
45286 free_percpu(sbi->s_locality_groups);
45287@@ -3047,16 +3047,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
45288 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45289
45290 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45291- atomic_inc(&sbi->s_bal_reqs);
45292- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45293+ atomic_inc_unchecked(&sbi->s_bal_reqs);
45294+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45295 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
45296- atomic_inc(&sbi->s_bal_success);
45297- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45298+ atomic_inc_unchecked(&sbi->s_bal_success);
45299+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45300 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45301 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45302- atomic_inc(&sbi->s_bal_goals);
45303+ atomic_inc_unchecked(&sbi->s_bal_goals);
45304 if (ac->ac_found > sbi->s_mb_max_to_scan)
45305- atomic_inc(&sbi->s_bal_breaks);
45306+ atomic_inc_unchecked(&sbi->s_bal_breaks);
45307 }
45308
45309 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45310@@ -3456,7 +3456,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
45311 trace_ext4_mb_new_inode_pa(ac, pa);
45312
45313 ext4_mb_use_inode_pa(ac, pa);
45314- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
45315+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
45316
45317 ei = EXT4_I(ac->ac_inode);
45318 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45319@@ -3516,7 +3516,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
45320 trace_ext4_mb_new_group_pa(ac, pa);
45321
45322 ext4_mb_use_group_pa(ac, pa);
45323- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45324+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45325
45326 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45327 lg = ac->ac_lg;
45328@@ -3605,7 +3605,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
45329 * from the bitmap and continue.
45330 */
45331 }
45332- atomic_add(free, &sbi->s_mb_discarded);
45333+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
45334
45335 return err;
45336 }
45337@@ -3623,7 +3623,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
45338 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
45339 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
45340 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
45341- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45342+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45343 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
45344
45345 return 0;
45346diff --git a/fs/fcntl.c b/fs/fcntl.c
45347index 81b70e6..d9ae6cf 100644
45348--- a/fs/fcntl.c
45349+++ b/fs/fcntl.c
45350@@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
45351 if (err)
45352 return err;
45353
45354+ if (gr_handle_chroot_fowner(pid, type))
45355+ return -ENOENT;
45356+ if (gr_check_protected_task_fowner(pid, type))
45357+ return -EACCES;
45358+
45359 f_modown(filp, pid, type, force);
45360 return 0;
45361 }
45362@@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
45363
45364 static int f_setown_ex(struct file *filp, unsigned long arg)
45365 {
45366- struct f_owner_ex * __user owner_p = (void * __user)arg;
45367+ struct f_owner_ex __user *owner_p = (void __user *)arg;
45368 struct f_owner_ex owner;
45369 struct pid *pid;
45370 int type;
45371@@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
45372
45373 static int f_getown_ex(struct file *filp, unsigned long arg)
45374 {
45375- struct f_owner_ex * __user owner_p = (void * __user)arg;
45376+ struct f_owner_ex __user *owner_p = (void __user *)arg;
45377 struct f_owner_ex owner;
45378 int ret = 0;
45379
45380@@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
45381 switch (cmd) {
45382 case F_DUPFD:
45383 case F_DUPFD_CLOEXEC:
45384+ gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
45385 if (arg >= rlimit(RLIMIT_NOFILE))
45386 break;
45387 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
45388diff --git a/fs/fifo.c b/fs/fifo.c
45389index cf6f434..3d7942c 100644
45390--- a/fs/fifo.c
45391+++ b/fs/fifo.c
45392@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
45393 */
45394 filp->f_op = &read_pipefifo_fops;
45395 pipe->r_counter++;
45396- if (pipe->readers++ == 0)
45397+ if (atomic_inc_return(&pipe->readers) == 1)
45398 wake_up_partner(inode);
45399
45400- if (!pipe->writers) {
45401+ if (!atomic_read(&pipe->writers)) {
45402 if ((filp->f_flags & O_NONBLOCK)) {
45403 /* suppress POLLHUP until we have
45404 * seen a writer */
45405@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
45406 * errno=ENXIO when there is no process reading the FIFO.
45407 */
45408 ret = -ENXIO;
45409- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
45410+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
45411 goto err;
45412
45413 filp->f_op = &write_pipefifo_fops;
45414 pipe->w_counter++;
45415- if (!pipe->writers++)
45416+ if (atomic_inc_return(&pipe->writers) == 1)
45417 wake_up_partner(inode);
45418
45419- if (!pipe->readers) {
45420+ if (!atomic_read(&pipe->readers)) {
45421 if (wait_for_partner(inode, &pipe->r_counter))
45422 goto err_wr;
45423 }
45424@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
45425 */
45426 filp->f_op = &rdwr_pipefifo_fops;
45427
45428- pipe->readers++;
45429- pipe->writers++;
45430+ atomic_inc(&pipe->readers);
45431+ atomic_inc(&pipe->writers);
45432 pipe->r_counter++;
45433 pipe->w_counter++;
45434- if (pipe->readers == 1 || pipe->writers == 1)
45435+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
45436 wake_up_partner(inode);
45437 break;
45438
45439@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
45440 return 0;
45441
45442 err_rd:
45443- if (!--pipe->readers)
45444+ if (atomic_dec_and_test(&pipe->readers))
45445 wake_up_interruptible(&pipe->wait);
45446 ret = -ERESTARTSYS;
45447 goto err;
45448
45449 err_wr:
45450- if (!--pipe->writers)
45451+ if (atomic_dec_and_test(&pipe->writers))
45452 wake_up_interruptible(&pipe->wait);
45453 ret = -ERESTARTSYS;
45454 goto err;
45455
45456 err:
45457- if (!pipe->readers && !pipe->writers)
45458+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
45459 free_pipe_info(inode);
45460
45461 err_nocleanup:
45462diff --git a/fs/file.c b/fs/file.c
45463index ba3f605..fade102 100644
45464--- a/fs/file.c
45465+++ b/fs/file.c
45466@@ -15,6 +15,7 @@
45467 #include <linux/slab.h>
45468 #include <linux/vmalloc.h>
45469 #include <linux/file.h>
45470+#include <linux/security.h>
45471 #include <linux/fdtable.h>
45472 #include <linux/bitops.h>
45473 #include <linux/interrupt.h>
45474@@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
45475 * N.B. For clone tasks sharing a files structure, this test
45476 * will limit the total number of files that can be opened.
45477 */
45478+ gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
45479 if (nr >= rlimit(RLIMIT_NOFILE))
45480 return -EMFILE;
45481
45482diff --git a/fs/filesystems.c b/fs/filesystems.c
45483index 96f2428..f5eeb8e 100644
45484--- a/fs/filesystems.c
45485+++ b/fs/filesystems.c
45486@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
45487 int len = dot ? dot - name : strlen(name);
45488
45489 fs = __get_fs_type(name, len);
45490+
45491+#ifdef CONFIG_GRKERNSEC_MODHARDEN
45492+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
45493+#else
45494 if (!fs && (request_module("%.*s", len, name) == 0))
45495+#endif
45496 fs = __get_fs_type(name, len);
45497
45498 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
45499diff --git a/fs/fs_struct.c b/fs/fs_struct.c
45500index e159e68..e7d2a6f 100644
45501--- a/fs/fs_struct.c
45502+++ b/fs/fs_struct.c
45503@@ -4,6 +4,7 @@
45504 #include <linux/path.h>
45505 #include <linux/slab.h>
45506 #include <linux/fs_struct.h>
45507+#include <linux/grsecurity.h>
45508 #include "internal.h"
45509
45510 static inline void path_get_longterm(struct path *path)
45511@@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
45512 write_seqcount_begin(&fs->seq);
45513 old_root = fs->root;
45514 fs->root = *path;
45515+ gr_set_chroot_entries(current, path);
45516 write_seqcount_end(&fs->seq);
45517 spin_unlock(&fs->lock);
45518 if (old_root.dentry)
45519@@ -65,6 +67,17 @@ static inline int replace_path(struct path *p, const struct path *old, const str
45520 return 1;
45521 }
45522
45523+static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
45524+{
45525+ if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
45526+ return 0;
45527+ *p = *new;
45528+
45529+ gr_set_chroot_entries(task, new);
45530+
45531+ return 1;
45532+}
45533+
45534 void chroot_fs_refs(struct path *old_root, struct path *new_root)
45535 {
45536 struct task_struct *g, *p;
45537@@ -79,7 +92,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
45538 int hits = 0;
45539 spin_lock(&fs->lock);
45540 write_seqcount_begin(&fs->seq);
45541- hits += replace_path(&fs->root, old_root, new_root);
45542+ hits += replace_root_path(p, &fs->root, old_root, new_root);
45543 hits += replace_path(&fs->pwd, old_root, new_root);
45544 write_seqcount_end(&fs->seq);
45545 while (hits--) {
45546@@ -111,7 +124,8 @@ void exit_fs(struct task_struct *tsk)
45547 task_lock(tsk);
45548 spin_lock(&fs->lock);
45549 tsk->fs = NULL;
45550- kill = !--fs->users;
45551+ gr_clear_chroot_entries(tsk);
45552+ kill = !atomic_dec_return(&fs->users);
45553 spin_unlock(&fs->lock);
45554 task_unlock(tsk);
45555 if (kill)
45556@@ -124,7 +138,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45557 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
45558 /* We don't need to lock fs - think why ;-) */
45559 if (fs) {
45560- fs->users = 1;
45561+ atomic_set(&fs->users, 1);
45562 fs->in_exec = 0;
45563 spin_lock_init(&fs->lock);
45564 seqcount_init(&fs->seq);
45565@@ -133,6 +147,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45566 spin_lock(&old->lock);
45567 fs->root = old->root;
45568 path_get_longterm(&fs->root);
45569+ /* instead of calling gr_set_chroot_entries here,
45570+ we call it from every caller of this function
45571+ */
45572 fs->pwd = old->pwd;
45573 path_get_longterm(&fs->pwd);
45574 spin_unlock(&old->lock);
45575@@ -151,8 +168,9 @@ int unshare_fs_struct(void)
45576
45577 task_lock(current);
45578 spin_lock(&fs->lock);
45579- kill = !--fs->users;
45580+ kill = !atomic_dec_return(&fs->users);
45581 current->fs = new_fs;
45582+ gr_set_chroot_entries(current, &new_fs->root);
45583 spin_unlock(&fs->lock);
45584 task_unlock(current);
45585
45586@@ -165,13 +183,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
45587
45588 int current_umask(void)
45589 {
45590- return current->fs->umask;
45591+ return current->fs->umask | gr_acl_umask();
45592 }
45593 EXPORT_SYMBOL(current_umask);
45594
45595 /* to be mentioned only in INIT_TASK */
45596 struct fs_struct init_fs = {
45597- .users = 1,
45598+ .users = ATOMIC_INIT(1),
45599 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
45600 .seq = SEQCNT_ZERO,
45601 .umask = 0022,
45602@@ -187,12 +205,13 @@ void daemonize_fs_struct(void)
45603 task_lock(current);
45604
45605 spin_lock(&init_fs.lock);
45606- init_fs.users++;
45607+ atomic_inc(&init_fs.users);
45608 spin_unlock(&init_fs.lock);
45609
45610 spin_lock(&fs->lock);
45611 current->fs = &init_fs;
45612- kill = !--fs->users;
45613+ gr_set_chroot_entries(current, &current->fs->root);
45614+ kill = !atomic_dec_return(&fs->users);
45615 spin_unlock(&fs->lock);
45616
45617 task_unlock(current);
45618diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
45619index 9905350..02eaec4 100644
45620--- a/fs/fscache/cookie.c
45621+++ b/fs/fscache/cookie.c
45622@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
45623 parent ? (char *) parent->def->name : "<no-parent>",
45624 def->name, netfs_data);
45625
45626- fscache_stat(&fscache_n_acquires);
45627+ fscache_stat_unchecked(&fscache_n_acquires);
45628
45629 /* if there's no parent cookie, then we don't create one here either */
45630 if (!parent) {
45631- fscache_stat(&fscache_n_acquires_null);
45632+ fscache_stat_unchecked(&fscache_n_acquires_null);
45633 _leave(" [no parent]");
45634 return NULL;
45635 }
45636@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
45637 /* allocate and initialise a cookie */
45638 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
45639 if (!cookie) {
45640- fscache_stat(&fscache_n_acquires_oom);
45641+ fscache_stat_unchecked(&fscache_n_acquires_oom);
45642 _leave(" [ENOMEM]");
45643 return NULL;
45644 }
45645@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45646
45647 switch (cookie->def->type) {
45648 case FSCACHE_COOKIE_TYPE_INDEX:
45649- fscache_stat(&fscache_n_cookie_index);
45650+ fscache_stat_unchecked(&fscache_n_cookie_index);
45651 break;
45652 case FSCACHE_COOKIE_TYPE_DATAFILE:
45653- fscache_stat(&fscache_n_cookie_data);
45654+ fscache_stat_unchecked(&fscache_n_cookie_data);
45655 break;
45656 default:
45657- fscache_stat(&fscache_n_cookie_special);
45658+ fscache_stat_unchecked(&fscache_n_cookie_special);
45659 break;
45660 }
45661
45662@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45663 if (fscache_acquire_non_index_cookie(cookie) < 0) {
45664 atomic_dec(&parent->n_children);
45665 __fscache_cookie_put(cookie);
45666- fscache_stat(&fscache_n_acquires_nobufs);
45667+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
45668 _leave(" = NULL");
45669 return NULL;
45670 }
45671 }
45672
45673- fscache_stat(&fscache_n_acquires_ok);
45674+ fscache_stat_unchecked(&fscache_n_acquires_ok);
45675 _leave(" = %p", cookie);
45676 return cookie;
45677 }
45678@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
45679 cache = fscache_select_cache_for_object(cookie->parent);
45680 if (!cache) {
45681 up_read(&fscache_addremove_sem);
45682- fscache_stat(&fscache_n_acquires_no_cache);
45683+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
45684 _leave(" = -ENOMEDIUM [no cache]");
45685 return -ENOMEDIUM;
45686 }
45687@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
45688 object = cache->ops->alloc_object(cache, cookie);
45689 fscache_stat_d(&fscache_n_cop_alloc_object);
45690 if (IS_ERR(object)) {
45691- fscache_stat(&fscache_n_object_no_alloc);
45692+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
45693 ret = PTR_ERR(object);
45694 goto error;
45695 }
45696
45697- fscache_stat(&fscache_n_object_alloc);
45698+ fscache_stat_unchecked(&fscache_n_object_alloc);
45699
45700 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
45701
45702@@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
45703 struct fscache_object *object;
45704 struct hlist_node *_p;
45705
45706- fscache_stat(&fscache_n_updates);
45707+ fscache_stat_unchecked(&fscache_n_updates);
45708
45709 if (!cookie) {
45710- fscache_stat(&fscache_n_updates_null);
45711+ fscache_stat_unchecked(&fscache_n_updates_null);
45712 _leave(" [no cookie]");
45713 return;
45714 }
45715@@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45716 struct fscache_object *object;
45717 unsigned long event;
45718
45719- fscache_stat(&fscache_n_relinquishes);
45720+ fscache_stat_unchecked(&fscache_n_relinquishes);
45721 if (retire)
45722- fscache_stat(&fscache_n_relinquishes_retire);
45723+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
45724
45725 if (!cookie) {
45726- fscache_stat(&fscache_n_relinquishes_null);
45727+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
45728 _leave(" [no cookie]");
45729 return;
45730 }
45731@@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45732
45733 /* wait for the cookie to finish being instantiated (or to fail) */
45734 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
45735- fscache_stat(&fscache_n_relinquishes_waitcrt);
45736+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
45737 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
45738 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
45739 }
45740diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
45741index f6aad48..88dcf26 100644
45742--- a/fs/fscache/internal.h
45743+++ b/fs/fscache/internal.h
45744@@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
45745 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
45746 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
45747
45748-extern atomic_t fscache_n_op_pend;
45749-extern atomic_t fscache_n_op_run;
45750-extern atomic_t fscache_n_op_enqueue;
45751-extern atomic_t fscache_n_op_deferred_release;
45752-extern atomic_t fscache_n_op_release;
45753-extern atomic_t fscache_n_op_gc;
45754-extern atomic_t fscache_n_op_cancelled;
45755-extern atomic_t fscache_n_op_rejected;
45756+extern atomic_unchecked_t fscache_n_op_pend;
45757+extern atomic_unchecked_t fscache_n_op_run;
45758+extern atomic_unchecked_t fscache_n_op_enqueue;
45759+extern atomic_unchecked_t fscache_n_op_deferred_release;
45760+extern atomic_unchecked_t fscache_n_op_release;
45761+extern atomic_unchecked_t fscache_n_op_gc;
45762+extern atomic_unchecked_t fscache_n_op_cancelled;
45763+extern atomic_unchecked_t fscache_n_op_rejected;
45764
45765-extern atomic_t fscache_n_attr_changed;
45766-extern atomic_t fscache_n_attr_changed_ok;
45767-extern atomic_t fscache_n_attr_changed_nobufs;
45768-extern atomic_t fscache_n_attr_changed_nomem;
45769-extern atomic_t fscache_n_attr_changed_calls;
45770+extern atomic_unchecked_t fscache_n_attr_changed;
45771+extern atomic_unchecked_t fscache_n_attr_changed_ok;
45772+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
45773+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
45774+extern atomic_unchecked_t fscache_n_attr_changed_calls;
45775
45776-extern atomic_t fscache_n_allocs;
45777-extern atomic_t fscache_n_allocs_ok;
45778-extern atomic_t fscache_n_allocs_wait;
45779-extern atomic_t fscache_n_allocs_nobufs;
45780-extern atomic_t fscache_n_allocs_intr;
45781-extern atomic_t fscache_n_allocs_object_dead;
45782-extern atomic_t fscache_n_alloc_ops;
45783-extern atomic_t fscache_n_alloc_op_waits;
45784+extern atomic_unchecked_t fscache_n_allocs;
45785+extern atomic_unchecked_t fscache_n_allocs_ok;
45786+extern atomic_unchecked_t fscache_n_allocs_wait;
45787+extern atomic_unchecked_t fscache_n_allocs_nobufs;
45788+extern atomic_unchecked_t fscache_n_allocs_intr;
45789+extern atomic_unchecked_t fscache_n_allocs_object_dead;
45790+extern atomic_unchecked_t fscache_n_alloc_ops;
45791+extern atomic_unchecked_t fscache_n_alloc_op_waits;
45792
45793-extern atomic_t fscache_n_retrievals;
45794-extern atomic_t fscache_n_retrievals_ok;
45795-extern atomic_t fscache_n_retrievals_wait;
45796-extern atomic_t fscache_n_retrievals_nodata;
45797-extern atomic_t fscache_n_retrievals_nobufs;
45798-extern atomic_t fscache_n_retrievals_intr;
45799-extern atomic_t fscache_n_retrievals_nomem;
45800-extern atomic_t fscache_n_retrievals_object_dead;
45801-extern atomic_t fscache_n_retrieval_ops;
45802-extern atomic_t fscache_n_retrieval_op_waits;
45803+extern atomic_unchecked_t fscache_n_retrievals;
45804+extern atomic_unchecked_t fscache_n_retrievals_ok;
45805+extern atomic_unchecked_t fscache_n_retrievals_wait;
45806+extern atomic_unchecked_t fscache_n_retrievals_nodata;
45807+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
45808+extern atomic_unchecked_t fscache_n_retrievals_intr;
45809+extern atomic_unchecked_t fscache_n_retrievals_nomem;
45810+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
45811+extern atomic_unchecked_t fscache_n_retrieval_ops;
45812+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
45813
45814-extern atomic_t fscache_n_stores;
45815-extern atomic_t fscache_n_stores_ok;
45816-extern atomic_t fscache_n_stores_again;
45817-extern atomic_t fscache_n_stores_nobufs;
45818-extern atomic_t fscache_n_stores_oom;
45819-extern atomic_t fscache_n_store_ops;
45820-extern atomic_t fscache_n_store_calls;
45821-extern atomic_t fscache_n_store_pages;
45822-extern atomic_t fscache_n_store_radix_deletes;
45823-extern atomic_t fscache_n_store_pages_over_limit;
45824+extern atomic_unchecked_t fscache_n_stores;
45825+extern atomic_unchecked_t fscache_n_stores_ok;
45826+extern atomic_unchecked_t fscache_n_stores_again;
45827+extern atomic_unchecked_t fscache_n_stores_nobufs;
45828+extern atomic_unchecked_t fscache_n_stores_oom;
45829+extern atomic_unchecked_t fscache_n_store_ops;
45830+extern atomic_unchecked_t fscache_n_store_calls;
45831+extern atomic_unchecked_t fscache_n_store_pages;
45832+extern atomic_unchecked_t fscache_n_store_radix_deletes;
45833+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
45834
45835-extern atomic_t fscache_n_store_vmscan_not_storing;
45836-extern atomic_t fscache_n_store_vmscan_gone;
45837-extern atomic_t fscache_n_store_vmscan_busy;
45838-extern atomic_t fscache_n_store_vmscan_cancelled;
45839+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45840+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
45841+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
45842+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45843
45844-extern atomic_t fscache_n_marks;
45845-extern atomic_t fscache_n_uncaches;
45846+extern atomic_unchecked_t fscache_n_marks;
45847+extern atomic_unchecked_t fscache_n_uncaches;
45848
45849-extern atomic_t fscache_n_acquires;
45850-extern atomic_t fscache_n_acquires_null;
45851-extern atomic_t fscache_n_acquires_no_cache;
45852-extern atomic_t fscache_n_acquires_ok;
45853-extern atomic_t fscache_n_acquires_nobufs;
45854-extern atomic_t fscache_n_acquires_oom;
45855+extern atomic_unchecked_t fscache_n_acquires;
45856+extern atomic_unchecked_t fscache_n_acquires_null;
45857+extern atomic_unchecked_t fscache_n_acquires_no_cache;
45858+extern atomic_unchecked_t fscache_n_acquires_ok;
45859+extern atomic_unchecked_t fscache_n_acquires_nobufs;
45860+extern atomic_unchecked_t fscache_n_acquires_oom;
45861
45862-extern atomic_t fscache_n_updates;
45863-extern atomic_t fscache_n_updates_null;
45864-extern atomic_t fscache_n_updates_run;
45865+extern atomic_unchecked_t fscache_n_updates;
45866+extern atomic_unchecked_t fscache_n_updates_null;
45867+extern atomic_unchecked_t fscache_n_updates_run;
45868
45869-extern atomic_t fscache_n_relinquishes;
45870-extern atomic_t fscache_n_relinquishes_null;
45871-extern atomic_t fscache_n_relinquishes_waitcrt;
45872-extern atomic_t fscache_n_relinquishes_retire;
45873+extern atomic_unchecked_t fscache_n_relinquishes;
45874+extern atomic_unchecked_t fscache_n_relinquishes_null;
45875+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
45876+extern atomic_unchecked_t fscache_n_relinquishes_retire;
45877
45878-extern atomic_t fscache_n_cookie_index;
45879-extern atomic_t fscache_n_cookie_data;
45880-extern atomic_t fscache_n_cookie_special;
45881+extern atomic_unchecked_t fscache_n_cookie_index;
45882+extern atomic_unchecked_t fscache_n_cookie_data;
45883+extern atomic_unchecked_t fscache_n_cookie_special;
45884
45885-extern atomic_t fscache_n_object_alloc;
45886-extern atomic_t fscache_n_object_no_alloc;
45887-extern atomic_t fscache_n_object_lookups;
45888-extern atomic_t fscache_n_object_lookups_negative;
45889-extern atomic_t fscache_n_object_lookups_positive;
45890-extern atomic_t fscache_n_object_lookups_timed_out;
45891-extern atomic_t fscache_n_object_created;
45892-extern atomic_t fscache_n_object_avail;
45893-extern atomic_t fscache_n_object_dead;
45894+extern atomic_unchecked_t fscache_n_object_alloc;
45895+extern atomic_unchecked_t fscache_n_object_no_alloc;
45896+extern atomic_unchecked_t fscache_n_object_lookups;
45897+extern atomic_unchecked_t fscache_n_object_lookups_negative;
45898+extern atomic_unchecked_t fscache_n_object_lookups_positive;
45899+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
45900+extern atomic_unchecked_t fscache_n_object_created;
45901+extern atomic_unchecked_t fscache_n_object_avail;
45902+extern atomic_unchecked_t fscache_n_object_dead;
45903
45904-extern atomic_t fscache_n_checkaux_none;
45905-extern atomic_t fscache_n_checkaux_okay;
45906-extern atomic_t fscache_n_checkaux_update;
45907-extern atomic_t fscache_n_checkaux_obsolete;
45908+extern atomic_unchecked_t fscache_n_checkaux_none;
45909+extern atomic_unchecked_t fscache_n_checkaux_okay;
45910+extern atomic_unchecked_t fscache_n_checkaux_update;
45911+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
45912
45913 extern atomic_t fscache_n_cop_alloc_object;
45914 extern atomic_t fscache_n_cop_lookup_object;
45915@@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
45916 atomic_inc(stat);
45917 }
45918
45919+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
45920+{
45921+ atomic_inc_unchecked(stat);
45922+}
45923+
45924 static inline void fscache_stat_d(atomic_t *stat)
45925 {
45926 atomic_dec(stat);
45927@@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
45928
45929 #define __fscache_stat(stat) (NULL)
45930 #define fscache_stat(stat) do {} while (0)
45931+#define fscache_stat_unchecked(stat) do {} while (0)
45932 #define fscache_stat_d(stat) do {} while (0)
45933 #endif
45934
45935diff --git a/fs/fscache/object.c b/fs/fscache/object.c
45936index b6b897c..0ffff9c 100644
45937--- a/fs/fscache/object.c
45938+++ b/fs/fscache/object.c
45939@@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45940 /* update the object metadata on disk */
45941 case FSCACHE_OBJECT_UPDATING:
45942 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
45943- fscache_stat(&fscache_n_updates_run);
45944+ fscache_stat_unchecked(&fscache_n_updates_run);
45945 fscache_stat(&fscache_n_cop_update_object);
45946 object->cache->ops->update_object(object);
45947 fscache_stat_d(&fscache_n_cop_update_object);
45948@@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45949 spin_lock(&object->lock);
45950 object->state = FSCACHE_OBJECT_DEAD;
45951 spin_unlock(&object->lock);
45952- fscache_stat(&fscache_n_object_dead);
45953+ fscache_stat_unchecked(&fscache_n_object_dead);
45954 goto terminal_transit;
45955
45956 /* handle the parent cache of this object being withdrawn from
45957@@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45958 spin_lock(&object->lock);
45959 object->state = FSCACHE_OBJECT_DEAD;
45960 spin_unlock(&object->lock);
45961- fscache_stat(&fscache_n_object_dead);
45962+ fscache_stat_unchecked(&fscache_n_object_dead);
45963 goto terminal_transit;
45964
45965 /* complain about the object being woken up once it is
45966@@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45967 parent->cookie->def->name, cookie->def->name,
45968 object->cache->tag->name);
45969
45970- fscache_stat(&fscache_n_object_lookups);
45971+ fscache_stat_unchecked(&fscache_n_object_lookups);
45972 fscache_stat(&fscache_n_cop_lookup_object);
45973 ret = object->cache->ops->lookup_object(object);
45974 fscache_stat_d(&fscache_n_cop_lookup_object);
45975@@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45976 if (ret == -ETIMEDOUT) {
45977 /* probably stuck behind another object, so move this one to
45978 * the back of the queue */
45979- fscache_stat(&fscache_n_object_lookups_timed_out);
45980+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
45981 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45982 }
45983
45984@@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
45985
45986 spin_lock(&object->lock);
45987 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45988- fscache_stat(&fscache_n_object_lookups_negative);
45989+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
45990
45991 /* transit here to allow write requests to begin stacking up
45992 * and read requests to begin returning ENODATA */
45993@@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
45994 * result, in which case there may be data available */
45995 spin_lock(&object->lock);
45996 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45997- fscache_stat(&fscache_n_object_lookups_positive);
45998+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
45999
46000 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
46001
46002@@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
46003 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46004 } else {
46005 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
46006- fscache_stat(&fscache_n_object_created);
46007+ fscache_stat_unchecked(&fscache_n_object_created);
46008
46009 object->state = FSCACHE_OBJECT_AVAILABLE;
46010 spin_unlock(&object->lock);
46011@@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
46012 fscache_enqueue_dependents(object);
46013
46014 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
46015- fscache_stat(&fscache_n_object_avail);
46016+ fscache_stat_unchecked(&fscache_n_object_avail);
46017
46018 _leave("");
46019 }
46020@@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46021 enum fscache_checkaux result;
46022
46023 if (!object->cookie->def->check_aux) {
46024- fscache_stat(&fscache_n_checkaux_none);
46025+ fscache_stat_unchecked(&fscache_n_checkaux_none);
46026 return FSCACHE_CHECKAUX_OKAY;
46027 }
46028
46029@@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46030 switch (result) {
46031 /* entry okay as is */
46032 case FSCACHE_CHECKAUX_OKAY:
46033- fscache_stat(&fscache_n_checkaux_okay);
46034+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
46035 break;
46036
46037 /* entry requires update */
46038 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
46039- fscache_stat(&fscache_n_checkaux_update);
46040+ fscache_stat_unchecked(&fscache_n_checkaux_update);
46041 break;
46042
46043 /* entry requires deletion */
46044 case FSCACHE_CHECKAUX_OBSOLETE:
46045- fscache_stat(&fscache_n_checkaux_obsolete);
46046+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
46047 break;
46048
46049 default:
46050diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
46051index 30afdfa..2256596 100644
46052--- a/fs/fscache/operation.c
46053+++ b/fs/fscache/operation.c
46054@@ -17,7 +17,7 @@
46055 #include <linux/slab.h>
46056 #include "internal.h"
46057
46058-atomic_t fscache_op_debug_id;
46059+atomic_unchecked_t fscache_op_debug_id;
46060 EXPORT_SYMBOL(fscache_op_debug_id);
46061
46062 /**
46063@@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
46064 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
46065 ASSERTCMP(atomic_read(&op->usage), >, 0);
46066
46067- fscache_stat(&fscache_n_op_enqueue);
46068+ fscache_stat_unchecked(&fscache_n_op_enqueue);
46069 switch (op->flags & FSCACHE_OP_TYPE) {
46070 case FSCACHE_OP_ASYNC:
46071 _debug("queue async");
46072@@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
46073 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
46074 if (op->processor)
46075 fscache_enqueue_operation(op);
46076- fscache_stat(&fscache_n_op_run);
46077+ fscache_stat_unchecked(&fscache_n_op_run);
46078 }
46079
46080 /*
46081@@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46082 if (object->n_ops > 1) {
46083 atomic_inc(&op->usage);
46084 list_add_tail(&op->pend_link, &object->pending_ops);
46085- fscache_stat(&fscache_n_op_pend);
46086+ fscache_stat_unchecked(&fscache_n_op_pend);
46087 } else if (!list_empty(&object->pending_ops)) {
46088 atomic_inc(&op->usage);
46089 list_add_tail(&op->pend_link, &object->pending_ops);
46090- fscache_stat(&fscache_n_op_pend);
46091+ fscache_stat_unchecked(&fscache_n_op_pend);
46092 fscache_start_operations(object);
46093 } else {
46094 ASSERTCMP(object->n_in_progress, ==, 0);
46095@@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46096 object->n_exclusive++; /* reads and writes must wait */
46097 atomic_inc(&op->usage);
46098 list_add_tail(&op->pend_link, &object->pending_ops);
46099- fscache_stat(&fscache_n_op_pend);
46100+ fscache_stat_unchecked(&fscache_n_op_pend);
46101 ret = 0;
46102 } else {
46103 /* not allowed to submit ops in any other state */
46104@@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
46105 if (object->n_exclusive > 0) {
46106 atomic_inc(&op->usage);
46107 list_add_tail(&op->pend_link, &object->pending_ops);
46108- fscache_stat(&fscache_n_op_pend);
46109+ fscache_stat_unchecked(&fscache_n_op_pend);
46110 } else if (!list_empty(&object->pending_ops)) {
46111 atomic_inc(&op->usage);
46112 list_add_tail(&op->pend_link, &object->pending_ops);
46113- fscache_stat(&fscache_n_op_pend);
46114+ fscache_stat_unchecked(&fscache_n_op_pend);
46115 fscache_start_operations(object);
46116 } else {
46117 ASSERTCMP(object->n_exclusive, ==, 0);
46118@@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
46119 object->n_ops++;
46120 atomic_inc(&op->usage);
46121 list_add_tail(&op->pend_link, &object->pending_ops);
46122- fscache_stat(&fscache_n_op_pend);
46123+ fscache_stat_unchecked(&fscache_n_op_pend);
46124 ret = 0;
46125 } else if (object->state == FSCACHE_OBJECT_DYING ||
46126 object->state == FSCACHE_OBJECT_LC_DYING ||
46127 object->state == FSCACHE_OBJECT_WITHDRAWING) {
46128- fscache_stat(&fscache_n_op_rejected);
46129+ fscache_stat_unchecked(&fscache_n_op_rejected);
46130 ret = -ENOBUFS;
46131 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
46132 fscache_report_unexpected_submission(object, op, ostate);
46133@@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
46134
46135 ret = -EBUSY;
46136 if (!list_empty(&op->pend_link)) {
46137- fscache_stat(&fscache_n_op_cancelled);
46138+ fscache_stat_unchecked(&fscache_n_op_cancelled);
46139 list_del_init(&op->pend_link);
46140 object->n_ops--;
46141 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
46142@@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
46143 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
46144 BUG();
46145
46146- fscache_stat(&fscache_n_op_release);
46147+ fscache_stat_unchecked(&fscache_n_op_release);
46148
46149 if (op->release) {
46150 op->release(op);
46151@@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
46152 * lock, and defer it otherwise */
46153 if (!spin_trylock(&object->lock)) {
46154 _debug("defer put");
46155- fscache_stat(&fscache_n_op_deferred_release);
46156+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
46157
46158 cache = object->cache;
46159 spin_lock(&cache->op_gc_list_lock);
46160@@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
46161
46162 _debug("GC DEFERRED REL OBJ%x OP%x",
46163 object->debug_id, op->debug_id);
46164- fscache_stat(&fscache_n_op_gc);
46165+ fscache_stat_unchecked(&fscache_n_op_gc);
46166
46167 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46168
46169diff --git a/fs/fscache/page.c b/fs/fscache/page.c
46170index 3f7a59b..cf196cc 100644
46171--- a/fs/fscache/page.c
46172+++ b/fs/fscache/page.c
46173@@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46174 val = radix_tree_lookup(&cookie->stores, page->index);
46175 if (!val) {
46176 rcu_read_unlock();
46177- fscache_stat(&fscache_n_store_vmscan_not_storing);
46178+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46179 __fscache_uncache_page(cookie, page);
46180 return true;
46181 }
46182@@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46183 spin_unlock(&cookie->stores_lock);
46184
46185 if (xpage) {
46186- fscache_stat(&fscache_n_store_vmscan_cancelled);
46187- fscache_stat(&fscache_n_store_radix_deletes);
46188+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46189+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46190 ASSERTCMP(xpage, ==, page);
46191 } else {
46192- fscache_stat(&fscache_n_store_vmscan_gone);
46193+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46194 }
46195
46196 wake_up_bit(&cookie->flags, 0);
46197@@ -107,7 +107,7 @@ page_busy:
46198 /* we might want to wait here, but that could deadlock the allocator as
46199 * the work threads writing to the cache may all end up sleeping
46200 * on memory allocation */
46201- fscache_stat(&fscache_n_store_vmscan_busy);
46202+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46203 return false;
46204 }
46205 EXPORT_SYMBOL(__fscache_maybe_release_page);
46206@@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
46207 FSCACHE_COOKIE_STORING_TAG);
46208 if (!radix_tree_tag_get(&cookie->stores, page->index,
46209 FSCACHE_COOKIE_PENDING_TAG)) {
46210- fscache_stat(&fscache_n_store_radix_deletes);
46211+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46212 xpage = radix_tree_delete(&cookie->stores, page->index);
46213 }
46214 spin_unlock(&cookie->stores_lock);
46215@@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
46216
46217 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46218
46219- fscache_stat(&fscache_n_attr_changed_calls);
46220+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46221
46222 if (fscache_object_is_active(object)) {
46223 fscache_stat(&fscache_n_cop_attr_changed);
46224@@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46225
46226 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46227
46228- fscache_stat(&fscache_n_attr_changed);
46229+ fscache_stat_unchecked(&fscache_n_attr_changed);
46230
46231 op = kzalloc(sizeof(*op), GFP_KERNEL);
46232 if (!op) {
46233- fscache_stat(&fscache_n_attr_changed_nomem);
46234+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46235 _leave(" = -ENOMEM");
46236 return -ENOMEM;
46237 }
46238@@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46239 if (fscache_submit_exclusive_op(object, op) < 0)
46240 goto nobufs;
46241 spin_unlock(&cookie->lock);
46242- fscache_stat(&fscache_n_attr_changed_ok);
46243+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46244 fscache_put_operation(op);
46245 _leave(" = 0");
46246 return 0;
46247@@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46248 nobufs:
46249 spin_unlock(&cookie->lock);
46250 kfree(op);
46251- fscache_stat(&fscache_n_attr_changed_nobufs);
46252+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46253 _leave(" = %d", -ENOBUFS);
46254 return -ENOBUFS;
46255 }
46256@@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
46257 /* allocate a retrieval operation and attempt to submit it */
46258 op = kzalloc(sizeof(*op), GFP_NOIO);
46259 if (!op) {
46260- fscache_stat(&fscache_n_retrievals_nomem);
46261+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46262 return NULL;
46263 }
46264
46265@@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46266 return 0;
46267 }
46268
46269- fscache_stat(&fscache_n_retrievals_wait);
46270+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
46271
46272 jif = jiffies;
46273 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46274 fscache_wait_bit_interruptible,
46275 TASK_INTERRUPTIBLE) != 0) {
46276- fscache_stat(&fscache_n_retrievals_intr);
46277+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
46278 _leave(" = -ERESTARTSYS");
46279 return -ERESTARTSYS;
46280 }
46281@@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46282 */
46283 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46284 struct fscache_retrieval *op,
46285- atomic_t *stat_op_waits,
46286- atomic_t *stat_object_dead)
46287+ atomic_unchecked_t *stat_op_waits,
46288+ atomic_unchecked_t *stat_object_dead)
46289 {
46290 int ret;
46291
46292@@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46293 goto check_if_dead;
46294
46295 _debug(">>> WT");
46296- fscache_stat(stat_op_waits);
46297+ fscache_stat_unchecked(stat_op_waits);
46298 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46299 fscache_wait_bit_interruptible,
46300 TASK_INTERRUPTIBLE) < 0) {
46301@@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46302
46303 check_if_dead:
46304 if (unlikely(fscache_object_is_dead(object))) {
46305- fscache_stat(stat_object_dead);
46306+ fscache_stat_unchecked(stat_object_dead);
46307 return -ENOBUFS;
46308 }
46309 return 0;
46310@@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46311
46312 _enter("%p,%p,,,", cookie, page);
46313
46314- fscache_stat(&fscache_n_retrievals);
46315+ fscache_stat_unchecked(&fscache_n_retrievals);
46316
46317 if (hlist_empty(&cookie->backing_objects))
46318 goto nobufs;
46319@@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46320 goto nobufs_unlock;
46321 spin_unlock(&cookie->lock);
46322
46323- fscache_stat(&fscache_n_retrieval_ops);
46324+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
46325
46326 /* pin the netfs read context in case we need to do the actual netfs
46327 * read because we've encountered a cache read failure */
46328@@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46329
46330 error:
46331 if (ret == -ENOMEM)
46332- fscache_stat(&fscache_n_retrievals_nomem);
46333+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46334 else if (ret == -ERESTARTSYS)
46335- fscache_stat(&fscache_n_retrievals_intr);
46336+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
46337 else if (ret == -ENODATA)
46338- fscache_stat(&fscache_n_retrievals_nodata);
46339+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46340 else if (ret < 0)
46341- fscache_stat(&fscache_n_retrievals_nobufs);
46342+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46343 else
46344- fscache_stat(&fscache_n_retrievals_ok);
46345+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
46346
46347 fscache_put_retrieval(op);
46348 _leave(" = %d", ret);
46349@@ -429,7 +429,7 @@ nobufs_unlock:
46350 spin_unlock(&cookie->lock);
46351 kfree(op);
46352 nobufs:
46353- fscache_stat(&fscache_n_retrievals_nobufs);
46354+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46355 _leave(" = -ENOBUFS");
46356 return -ENOBUFS;
46357 }
46358@@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46359
46360 _enter("%p,,%d,,,", cookie, *nr_pages);
46361
46362- fscache_stat(&fscache_n_retrievals);
46363+ fscache_stat_unchecked(&fscache_n_retrievals);
46364
46365 if (hlist_empty(&cookie->backing_objects))
46366 goto nobufs;
46367@@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46368 goto nobufs_unlock;
46369 spin_unlock(&cookie->lock);
46370
46371- fscache_stat(&fscache_n_retrieval_ops);
46372+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
46373
46374 /* pin the netfs read context in case we need to do the actual netfs
46375 * read because we've encountered a cache read failure */
46376@@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46377
46378 error:
46379 if (ret == -ENOMEM)
46380- fscache_stat(&fscache_n_retrievals_nomem);
46381+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46382 else if (ret == -ERESTARTSYS)
46383- fscache_stat(&fscache_n_retrievals_intr);
46384+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
46385 else if (ret == -ENODATA)
46386- fscache_stat(&fscache_n_retrievals_nodata);
46387+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46388 else if (ret < 0)
46389- fscache_stat(&fscache_n_retrievals_nobufs);
46390+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46391 else
46392- fscache_stat(&fscache_n_retrievals_ok);
46393+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
46394
46395 fscache_put_retrieval(op);
46396 _leave(" = %d", ret);
46397@@ -545,7 +545,7 @@ nobufs_unlock:
46398 spin_unlock(&cookie->lock);
46399 kfree(op);
46400 nobufs:
46401- fscache_stat(&fscache_n_retrievals_nobufs);
46402+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46403 _leave(" = -ENOBUFS");
46404 return -ENOBUFS;
46405 }
46406@@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46407
46408 _enter("%p,%p,,,", cookie, page);
46409
46410- fscache_stat(&fscache_n_allocs);
46411+ fscache_stat_unchecked(&fscache_n_allocs);
46412
46413 if (hlist_empty(&cookie->backing_objects))
46414 goto nobufs;
46415@@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46416 goto nobufs_unlock;
46417 spin_unlock(&cookie->lock);
46418
46419- fscache_stat(&fscache_n_alloc_ops);
46420+ fscache_stat_unchecked(&fscache_n_alloc_ops);
46421
46422 ret = fscache_wait_for_retrieval_activation(
46423 object, op,
46424@@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46425
46426 error:
46427 if (ret == -ERESTARTSYS)
46428- fscache_stat(&fscache_n_allocs_intr);
46429+ fscache_stat_unchecked(&fscache_n_allocs_intr);
46430 else if (ret < 0)
46431- fscache_stat(&fscache_n_allocs_nobufs);
46432+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46433 else
46434- fscache_stat(&fscache_n_allocs_ok);
46435+ fscache_stat_unchecked(&fscache_n_allocs_ok);
46436
46437 fscache_put_retrieval(op);
46438 _leave(" = %d", ret);
46439@@ -625,7 +625,7 @@ nobufs_unlock:
46440 spin_unlock(&cookie->lock);
46441 kfree(op);
46442 nobufs:
46443- fscache_stat(&fscache_n_allocs_nobufs);
46444+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46445 _leave(" = -ENOBUFS");
46446 return -ENOBUFS;
46447 }
46448@@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46449
46450 spin_lock(&cookie->stores_lock);
46451
46452- fscache_stat(&fscache_n_store_calls);
46453+ fscache_stat_unchecked(&fscache_n_store_calls);
46454
46455 /* find a page to store */
46456 page = NULL;
46457@@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46458 page = results[0];
46459 _debug("gang %d [%lx]", n, page->index);
46460 if (page->index > op->store_limit) {
46461- fscache_stat(&fscache_n_store_pages_over_limit);
46462+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
46463 goto superseded;
46464 }
46465
46466@@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46467 spin_unlock(&cookie->stores_lock);
46468 spin_unlock(&object->lock);
46469
46470- fscache_stat(&fscache_n_store_pages);
46471+ fscache_stat_unchecked(&fscache_n_store_pages);
46472 fscache_stat(&fscache_n_cop_write_page);
46473 ret = object->cache->ops->write_page(op, page);
46474 fscache_stat_d(&fscache_n_cop_write_page);
46475@@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46476 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46477 ASSERT(PageFsCache(page));
46478
46479- fscache_stat(&fscache_n_stores);
46480+ fscache_stat_unchecked(&fscache_n_stores);
46481
46482 op = kzalloc(sizeof(*op), GFP_NOIO);
46483 if (!op)
46484@@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46485 spin_unlock(&cookie->stores_lock);
46486 spin_unlock(&object->lock);
46487
46488- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
46489+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
46490 op->store_limit = object->store_limit;
46491
46492 if (fscache_submit_op(object, &op->op) < 0)
46493@@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46494
46495 spin_unlock(&cookie->lock);
46496 radix_tree_preload_end();
46497- fscache_stat(&fscache_n_store_ops);
46498- fscache_stat(&fscache_n_stores_ok);
46499+ fscache_stat_unchecked(&fscache_n_store_ops);
46500+ fscache_stat_unchecked(&fscache_n_stores_ok);
46501
46502 /* the work queue now carries its own ref on the object */
46503 fscache_put_operation(&op->op);
46504@@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46505 return 0;
46506
46507 already_queued:
46508- fscache_stat(&fscache_n_stores_again);
46509+ fscache_stat_unchecked(&fscache_n_stores_again);
46510 already_pending:
46511 spin_unlock(&cookie->stores_lock);
46512 spin_unlock(&object->lock);
46513 spin_unlock(&cookie->lock);
46514 radix_tree_preload_end();
46515 kfree(op);
46516- fscache_stat(&fscache_n_stores_ok);
46517+ fscache_stat_unchecked(&fscache_n_stores_ok);
46518 _leave(" = 0");
46519 return 0;
46520
46521@@ -851,14 +851,14 @@ nobufs:
46522 spin_unlock(&cookie->lock);
46523 radix_tree_preload_end();
46524 kfree(op);
46525- fscache_stat(&fscache_n_stores_nobufs);
46526+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
46527 _leave(" = -ENOBUFS");
46528 return -ENOBUFS;
46529
46530 nomem_free:
46531 kfree(op);
46532 nomem:
46533- fscache_stat(&fscache_n_stores_oom);
46534+ fscache_stat_unchecked(&fscache_n_stores_oom);
46535 _leave(" = -ENOMEM");
46536 return -ENOMEM;
46537 }
46538@@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
46539 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46540 ASSERTCMP(page, !=, NULL);
46541
46542- fscache_stat(&fscache_n_uncaches);
46543+ fscache_stat_unchecked(&fscache_n_uncaches);
46544
46545 /* cache withdrawal may beat us to it */
46546 if (!PageFsCache(page))
46547@@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
46548 unsigned long loop;
46549
46550 #ifdef CONFIG_FSCACHE_STATS
46551- atomic_add(pagevec->nr, &fscache_n_marks);
46552+ atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
46553 #endif
46554
46555 for (loop = 0; loop < pagevec->nr; loop++) {
46556diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
46557index 4765190..2a067f2 100644
46558--- a/fs/fscache/stats.c
46559+++ b/fs/fscache/stats.c
46560@@ -18,95 +18,95 @@
46561 /*
46562 * operation counters
46563 */
46564-atomic_t fscache_n_op_pend;
46565-atomic_t fscache_n_op_run;
46566-atomic_t fscache_n_op_enqueue;
46567-atomic_t fscache_n_op_requeue;
46568-atomic_t fscache_n_op_deferred_release;
46569-atomic_t fscache_n_op_release;
46570-atomic_t fscache_n_op_gc;
46571-atomic_t fscache_n_op_cancelled;
46572-atomic_t fscache_n_op_rejected;
46573+atomic_unchecked_t fscache_n_op_pend;
46574+atomic_unchecked_t fscache_n_op_run;
46575+atomic_unchecked_t fscache_n_op_enqueue;
46576+atomic_unchecked_t fscache_n_op_requeue;
46577+atomic_unchecked_t fscache_n_op_deferred_release;
46578+atomic_unchecked_t fscache_n_op_release;
46579+atomic_unchecked_t fscache_n_op_gc;
46580+atomic_unchecked_t fscache_n_op_cancelled;
46581+atomic_unchecked_t fscache_n_op_rejected;
46582
46583-atomic_t fscache_n_attr_changed;
46584-atomic_t fscache_n_attr_changed_ok;
46585-atomic_t fscache_n_attr_changed_nobufs;
46586-atomic_t fscache_n_attr_changed_nomem;
46587-atomic_t fscache_n_attr_changed_calls;
46588+atomic_unchecked_t fscache_n_attr_changed;
46589+atomic_unchecked_t fscache_n_attr_changed_ok;
46590+atomic_unchecked_t fscache_n_attr_changed_nobufs;
46591+atomic_unchecked_t fscache_n_attr_changed_nomem;
46592+atomic_unchecked_t fscache_n_attr_changed_calls;
46593
46594-atomic_t fscache_n_allocs;
46595-atomic_t fscache_n_allocs_ok;
46596-atomic_t fscache_n_allocs_wait;
46597-atomic_t fscache_n_allocs_nobufs;
46598-atomic_t fscache_n_allocs_intr;
46599-atomic_t fscache_n_allocs_object_dead;
46600-atomic_t fscache_n_alloc_ops;
46601-atomic_t fscache_n_alloc_op_waits;
46602+atomic_unchecked_t fscache_n_allocs;
46603+atomic_unchecked_t fscache_n_allocs_ok;
46604+atomic_unchecked_t fscache_n_allocs_wait;
46605+atomic_unchecked_t fscache_n_allocs_nobufs;
46606+atomic_unchecked_t fscache_n_allocs_intr;
46607+atomic_unchecked_t fscache_n_allocs_object_dead;
46608+atomic_unchecked_t fscache_n_alloc_ops;
46609+atomic_unchecked_t fscache_n_alloc_op_waits;
46610
46611-atomic_t fscache_n_retrievals;
46612-atomic_t fscache_n_retrievals_ok;
46613-atomic_t fscache_n_retrievals_wait;
46614-atomic_t fscache_n_retrievals_nodata;
46615-atomic_t fscache_n_retrievals_nobufs;
46616-atomic_t fscache_n_retrievals_intr;
46617-atomic_t fscache_n_retrievals_nomem;
46618-atomic_t fscache_n_retrievals_object_dead;
46619-atomic_t fscache_n_retrieval_ops;
46620-atomic_t fscache_n_retrieval_op_waits;
46621+atomic_unchecked_t fscache_n_retrievals;
46622+atomic_unchecked_t fscache_n_retrievals_ok;
46623+atomic_unchecked_t fscache_n_retrievals_wait;
46624+atomic_unchecked_t fscache_n_retrievals_nodata;
46625+atomic_unchecked_t fscache_n_retrievals_nobufs;
46626+atomic_unchecked_t fscache_n_retrievals_intr;
46627+atomic_unchecked_t fscache_n_retrievals_nomem;
46628+atomic_unchecked_t fscache_n_retrievals_object_dead;
46629+atomic_unchecked_t fscache_n_retrieval_ops;
46630+atomic_unchecked_t fscache_n_retrieval_op_waits;
46631
46632-atomic_t fscache_n_stores;
46633-atomic_t fscache_n_stores_ok;
46634-atomic_t fscache_n_stores_again;
46635-atomic_t fscache_n_stores_nobufs;
46636-atomic_t fscache_n_stores_oom;
46637-atomic_t fscache_n_store_ops;
46638-atomic_t fscache_n_store_calls;
46639-atomic_t fscache_n_store_pages;
46640-atomic_t fscache_n_store_radix_deletes;
46641-atomic_t fscache_n_store_pages_over_limit;
46642+atomic_unchecked_t fscache_n_stores;
46643+atomic_unchecked_t fscache_n_stores_ok;
46644+atomic_unchecked_t fscache_n_stores_again;
46645+atomic_unchecked_t fscache_n_stores_nobufs;
46646+atomic_unchecked_t fscache_n_stores_oom;
46647+atomic_unchecked_t fscache_n_store_ops;
46648+atomic_unchecked_t fscache_n_store_calls;
46649+atomic_unchecked_t fscache_n_store_pages;
46650+atomic_unchecked_t fscache_n_store_radix_deletes;
46651+atomic_unchecked_t fscache_n_store_pages_over_limit;
46652
46653-atomic_t fscache_n_store_vmscan_not_storing;
46654-atomic_t fscache_n_store_vmscan_gone;
46655-atomic_t fscache_n_store_vmscan_busy;
46656-atomic_t fscache_n_store_vmscan_cancelled;
46657+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46658+atomic_unchecked_t fscache_n_store_vmscan_gone;
46659+atomic_unchecked_t fscache_n_store_vmscan_busy;
46660+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46661
46662-atomic_t fscache_n_marks;
46663-atomic_t fscache_n_uncaches;
46664+atomic_unchecked_t fscache_n_marks;
46665+atomic_unchecked_t fscache_n_uncaches;
46666
46667-atomic_t fscache_n_acquires;
46668-atomic_t fscache_n_acquires_null;
46669-atomic_t fscache_n_acquires_no_cache;
46670-atomic_t fscache_n_acquires_ok;
46671-atomic_t fscache_n_acquires_nobufs;
46672-atomic_t fscache_n_acquires_oom;
46673+atomic_unchecked_t fscache_n_acquires;
46674+atomic_unchecked_t fscache_n_acquires_null;
46675+atomic_unchecked_t fscache_n_acquires_no_cache;
46676+atomic_unchecked_t fscache_n_acquires_ok;
46677+atomic_unchecked_t fscache_n_acquires_nobufs;
46678+atomic_unchecked_t fscache_n_acquires_oom;
46679
46680-atomic_t fscache_n_updates;
46681-atomic_t fscache_n_updates_null;
46682-atomic_t fscache_n_updates_run;
46683+atomic_unchecked_t fscache_n_updates;
46684+atomic_unchecked_t fscache_n_updates_null;
46685+atomic_unchecked_t fscache_n_updates_run;
46686
46687-atomic_t fscache_n_relinquishes;
46688-atomic_t fscache_n_relinquishes_null;
46689-atomic_t fscache_n_relinquishes_waitcrt;
46690-atomic_t fscache_n_relinquishes_retire;
46691+atomic_unchecked_t fscache_n_relinquishes;
46692+atomic_unchecked_t fscache_n_relinquishes_null;
46693+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46694+atomic_unchecked_t fscache_n_relinquishes_retire;
46695
46696-atomic_t fscache_n_cookie_index;
46697-atomic_t fscache_n_cookie_data;
46698-atomic_t fscache_n_cookie_special;
46699+atomic_unchecked_t fscache_n_cookie_index;
46700+atomic_unchecked_t fscache_n_cookie_data;
46701+atomic_unchecked_t fscache_n_cookie_special;
46702
46703-atomic_t fscache_n_object_alloc;
46704-atomic_t fscache_n_object_no_alloc;
46705-atomic_t fscache_n_object_lookups;
46706-atomic_t fscache_n_object_lookups_negative;
46707-atomic_t fscache_n_object_lookups_positive;
46708-atomic_t fscache_n_object_lookups_timed_out;
46709-atomic_t fscache_n_object_created;
46710-atomic_t fscache_n_object_avail;
46711-atomic_t fscache_n_object_dead;
46712+atomic_unchecked_t fscache_n_object_alloc;
46713+atomic_unchecked_t fscache_n_object_no_alloc;
46714+atomic_unchecked_t fscache_n_object_lookups;
46715+atomic_unchecked_t fscache_n_object_lookups_negative;
46716+atomic_unchecked_t fscache_n_object_lookups_positive;
46717+atomic_unchecked_t fscache_n_object_lookups_timed_out;
46718+atomic_unchecked_t fscache_n_object_created;
46719+atomic_unchecked_t fscache_n_object_avail;
46720+atomic_unchecked_t fscache_n_object_dead;
46721
46722-atomic_t fscache_n_checkaux_none;
46723-atomic_t fscache_n_checkaux_okay;
46724-atomic_t fscache_n_checkaux_update;
46725-atomic_t fscache_n_checkaux_obsolete;
46726+atomic_unchecked_t fscache_n_checkaux_none;
46727+atomic_unchecked_t fscache_n_checkaux_okay;
46728+atomic_unchecked_t fscache_n_checkaux_update;
46729+atomic_unchecked_t fscache_n_checkaux_obsolete;
46730
46731 atomic_t fscache_n_cop_alloc_object;
46732 atomic_t fscache_n_cop_lookup_object;
46733@@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
46734 seq_puts(m, "FS-Cache statistics\n");
46735
46736 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
46737- atomic_read(&fscache_n_cookie_index),
46738- atomic_read(&fscache_n_cookie_data),
46739- atomic_read(&fscache_n_cookie_special));
46740+ atomic_read_unchecked(&fscache_n_cookie_index),
46741+ atomic_read_unchecked(&fscache_n_cookie_data),
46742+ atomic_read_unchecked(&fscache_n_cookie_special));
46743
46744 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
46745- atomic_read(&fscache_n_object_alloc),
46746- atomic_read(&fscache_n_object_no_alloc),
46747- atomic_read(&fscache_n_object_avail),
46748- atomic_read(&fscache_n_object_dead));
46749+ atomic_read_unchecked(&fscache_n_object_alloc),
46750+ atomic_read_unchecked(&fscache_n_object_no_alloc),
46751+ atomic_read_unchecked(&fscache_n_object_avail),
46752+ atomic_read_unchecked(&fscache_n_object_dead));
46753 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
46754- atomic_read(&fscache_n_checkaux_none),
46755- atomic_read(&fscache_n_checkaux_okay),
46756- atomic_read(&fscache_n_checkaux_update),
46757- atomic_read(&fscache_n_checkaux_obsolete));
46758+ atomic_read_unchecked(&fscache_n_checkaux_none),
46759+ atomic_read_unchecked(&fscache_n_checkaux_okay),
46760+ atomic_read_unchecked(&fscache_n_checkaux_update),
46761+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
46762
46763 seq_printf(m, "Pages : mrk=%u unc=%u\n",
46764- atomic_read(&fscache_n_marks),
46765- atomic_read(&fscache_n_uncaches));
46766+ atomic_read_unchecked(&fscache_n_marks),
46767+ atomic_read_unchecked(&fscache_n_uncaches));
46768
46769 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
46770 " oom=%u\n",
46771- atomic_read(&fscache_n_acquires),
46772- atomic_read(&fscache_n_acquires_null),
46773- atomic_read(&fscache_n_acquires_no_cache),
46774- atomic_read(&fscache_n_acquires_ok),
46775- atomic_read(&fscache_n_acquires_nobufs),
46776- atomic_read(&fscache_n_acquires_oom));
46777+ atomic_read_unchecked(&fscache_n_acquires),
46778+ atomic_read_unchecked(&fscache_n_acquires_null),
46779+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
46780+ atomic_read_unchecked(&fscache_n_acquires_ok),
46781+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
46782+ atomic_read_unchecked(&fscache_n_acquires_oom));
46783
46784 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
46785- atomic_read(&fscache_n_object_lookups),
46786- atomic_read(&fscache_n_object_lookups_negative),
46787- atomic_read(&fscache_n_object_lookups_positive),
46788- atomic_read(&fscache_n_object_created),
46789- atomic_read(&fscache_n_object_lookups_timed_out));
46790+ atomic_read_unchecked(&fscache_n_object_lookups),
46791+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
46792+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
46793+ atomic_read_unchecked(&fscache_n_object_created),
46794+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
46795
46796 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
46797- atomic_read(&fscache_n_updates),
46798- atomic_read(&fscache_n_updates_null),
46799- atomic_read(&fscache_n_updates_run));
46800+ atomic_read_unchecked(&fscache_n_updates),
46801+ atomic_read_unchecked(&fscache_n_updates_null),
46802+ atomic_read_unchecked(&fscache_n_updates_run));
46803
46804 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
46805- atomic_read(&fscache_n_relinquishes),
46806- atomic_read(&fscache_n_relinquishes_null),
46807- atomic_read(&fscache_n_relinquishes_waitcrt),
46808- atomic_read(&fscache_n_relinquishes_retire));
46809+ atomic_read_unchecked(&fscache_n_relinquishes),
46810+ atomic_read_unchecked(&fscache_n_relinquishes_null),
46811+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
46812+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
46813
46814 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
46815- atomic_read(&fscache_n_attr_changed),
46816- atomic_read(&fscache_n_attr_changed_ok),
46817- atomic_read(&fscache_n_attr_changed_nobufs),
46818- atomic_read(&fscache_n_attr_changed_nomem),
46819- atomic_read(&fscache_n_attr_changed_calls));
46820+ atomic_read_unchecked(&fscache_n_attr_changed),
46821+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
46822+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
46823+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
46824+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
46825
46826 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
46827- atomic_read(&fscache_n_allocs),
46828- atomic_read(&fscache_n_allocs_ok),
46829- atomic_read(&fscache_n_allocs_wait),
46830- atomic_read(&fscache_n_allocs_nobufs),
46831- atomic_read(&fscache_n_allocs_intr));
46832+ atomic_read_unchecked(&fscache_n_allocs),
46833+ atomic_read_unchecked(&fscache_n_allocs_ok),
46834+ atomic_read_unchecked(&fscache_n_allocs_wait),
46835+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
46836+ atomic_read_unchecked(&fscache_n_allocs_intr));
46837 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
46838- atomic_read(&fscache_n_alloc_ops),
46839- atomic_read(&fscache_n_alloc_op_waits),
46840- atomic_read(&fscache_n_allocs_object_dead));
46841+ atomic_read_unchecked(&fscache_n_alloc_ops),
46842+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
46843+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
46844
46845 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
46846 " int=%u oom=%u\n",
46847- atomic_read(&fscache_n_retrievals),
46848- atomic_read(&fscache_n_retrievals_ok),
46849- atomic_read(&fscache_n_retrievals_wait),
46850- atomic_read(&fscache_n_retrievals_nodata),
46851- atomic_read(&fscache_n_retrievals_nobufs),
46852- atomic_read(&fscache_n_retrievals_intr),
46853- atomic_read(&fscache_n_retrievals_nomem));
46854+ atomic_read_unchecked(&fscache_n_retrievals),
46855+ atomic_read_unchecked(&fscache_n_retrievals_ok),
46856+ atomic_read_unchecked(&fscache_n_retrievals_wait),
46857+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
46858+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
46859+ atomic_read_unchecked(&fscache_n_retrievals_intr),
46860+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
46861 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
46862- atomic_read(&fscache_n_retrieval_ops),
46863- atomic_read(&fscache_n_retrieval_op_waits),
46864- atomic_read(&fscache_n_retrievals_object_dead));
46865+ atomic_read_unchecked(&fscache_n_retrieval_ops),
46866+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
46867+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
46868
46869 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
46870- atomic_read(&fscache_n_stores),
46871- atomic_read(&fscache_n_stores_ok),
46872- atomic_read(&fscache_n_stores_again),
46873- atomic_read(&fscache_n_stores_nobufs),
46874- atomic_read(&fscache_n_stores_oom));
46875+ atomic_read_unchecked(&fscache_n_stores),
46876+ atomic_read_unchecked(&fscache_n_stores_ok),
46877+ atomic_read_unchecked(&fscache_n_stores_again),
46878+ atomic_read_unchecked(&fscache_n_stores_nobufs),
46879+ atomic_read_unchecked(&fscache_n_stores_oom));
46880 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
46881- atomic_read(&fscache_n_store_ops),
46882- atomic_read(&fscache_n_store_calls),
46883- atomic_read(&fscache_n_store_pages),
46884- atomic_read(&fscache_n_store_radix_deletes),
46885- atomic_read(&fscache_n_store_pages_over_limit));
46886+ atomic_read_unchecked(&fscache_n_store_ops),
46887+ atomic_read_unchecked(&fscache_n_store_calls),
46888+ atomic_read_unchecked(&fscache_n_store_pages),
46889+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
46890+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
46891
46892 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
46893- atomic_read(&fscache_n_store_vmscan_not_storing),
46894- atomic_read(&fscache_n_store_vmscan_gone),
46895- atomic_read(&fscache_n_store_vmscan_busy),
46896- atomic_read(&fscache_n_store_vmscan_cancelled));
46897+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
46898+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
46899+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
46900+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
46901
46902 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
46903- atomic_read(&fscache_n_op_pend),
46904- atomic_read(&fscache_n_op_run),
46905- atomic_read(&fscache_n_op_enqueue),
46906- atomic_read(&fscache_n_op_cancelled),
46907- atomic_read(&fscache_n_op_rejected));
46908+ atomic_read_unchecked(&fscache_n_op_pend),
46909+ atomic_read_unchecked(&fscache_n_op_run),
46910+ atomic_read_unchecked(&fscache_n_op_enqueue),
46911+ atomic_read_unchecked(&fscache_n_op_cancelled),
46912+ atomic_read_unchecked(&fscache_n_op_rejected));
46913 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
46914- atomic_read(&fscache_n_op_deferred_release),
46915- atomic_read(&fscache_n_op_release),
46916- atomic_read(&fscache_n_op_gc));
46917+ atomic_read_unchecked(&fscache_n_op_deferred_release),
46918+ atomic_read_unchecked(&fscache_n_op_release),
46919+ atomic_read_unchecked(&fscache_n_op_gc));
46920
46921 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
46922 atomic_read(&fscache_n_cop_alloc_object),
46923diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
46924index 3426521..3b75162 100644
46925--- a/fs/fuse/cuse.c
46926+++ b/fs/fuse/cuse.c
46927@@ -587,10 +587,12 @@ static int __init cuse_init(void)
46928 INIT_LIST_HEAD(&cuse_conntbl[i]);
46929
46930 /* inherit and extend fuse_dev_operations */
46931- cuse_channel_fops = fuse_dev_operations;
46932- cuse_channel_fops.owner = THIS_MODULE;
46933- cuse_channel_fops.open = cuse_channel_open;
46934- cuse_channel_fops.release = cuse_channel_release;
46935+ pax_open_kernel();
46936+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
46937+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
46938+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
46939+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
46940+ pax_close_kernel();
46941
46942 cuse_class = class_create(THIS_MODULE, "cuse");
46943 if (IS_ERR(cuse_class))
46944diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
46945index 7df2b5e..5804aa7 100644
46946--- a/fs/fuse/dev.c
46947+++ b/fs/fuse/dev.c
46948@@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
46949 ret = 0;
46950 pipe_lock(pipe);
46951
46952- if (!pipe->readers) {
46953+ if (!atomic_read(&pipe->readers)) {
46954 send_sig(SIGPIPE, current, 0);
46955 if (!ret)
46956 ret = -EPIPE;
46957diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
46958index 334e0b1..fc571e8 100644
46959--- a/fs/fuse/dir.c
46960+++ b/fs/fuse/dir.c
46961@@ -1189,7 +1189,7 @@ static char *read_link(struct dentry *dentry)
46962 return link;
46963 }
46964
46965-static void free_link(char *link)
46966+static void free_link(const char *link)
46967 {
46968 if (!IS_ERR(link))
46969 free_page((unsigned long) link);
46970diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
46971index a9ba244..d9df391 100644
46972--- a/fs/gfs2/inode.c
46973+++ b/fs/gfs2/inode.c
46974@@ -1496,7 +1496,7 @@ out:
46975
46976 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46977 {
46978- char *s = nd_get_link(nd);
46979+ const char *s = nd_get_link(nd);
46980 if (!IS_ERR(s))
46981 kfree(s);
46982 }
46983diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
46984index cc9281b..58996fb 100644
46985--- a/fs/hugetlbfs/inode.c
46986+++ b/fs/hugetlbfs/inode.c
46987@@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
46988 .kill_sb = kill_litter_super,
46989 };
46990
46991-static struct vfsmount *hugetlbfs_vfsmount;
46992+struct vfsmount *hugetlbfs_vfsmount;
46993
46994 static int can_do_hugetlb_shm(void)
46995 {
46996diff --git a/fs/inode.c b/fs/inode.c
46997index c99163b..a11ad40 100644
46998--- a/fs/inode.c
46999+++ b/fs/inode.c
47000@@ -867,8 +867,8 @@ unsigned int get_next_ino(void)
47001
47002 #ifdef CONFIG_SMP
47003 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
47004- static atomic_t shared_last_ino;
47005- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
47006+ static atomic_unchecked_t shared_last_ino;
47007+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
47008
47009 res = next - LAST_INO_BATCH;
47010 }
47011diff --git a/fs/isofs/export.c b/fs/isofs/export.c
47012index aa4356d..1d38044 100644
47013--- a/fs/isofs/export.c
47014+++ b/fs/isofs/export.c
47015@@ -134,6 +134,7 @@ isofs_export_encode_fh(struct inode *inode,
47016 len = 3;
47017 fh32[0] = ei->i_iget5_block;
47018 fh16[2] = (__u16)ei->i_iget5_offset; /* fh16 [sic] */
47019+ fh16[3] = 0; /* avoid leaking uninitialized data */
47020 fh32[2] = inode->i_generation;
47021 if (parent) {
47022 struct iso_inode_info *eparent;
47023diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
47024index 4a6cf28..d3a29d3 100644
47025--- a/fs/jffs2/erase.c
47026+++ b/fs/jffs2/erase.c
47027@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
47028 struct jffs2_unknown_node marker = {
47029 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
47030 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47031- .totlen = cpu_to_je32(c->cleanmarker_size)
47032+ .totlen = cpu_to_je32(c->cleanmarker_size),
47033+ .hdr_crc = cpu_to_je32(0)
47034 };
47035
47036 jffs2_prealloc_raw_node_refs(c, jeb, 1);
47037diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
47038index 6f4529d..bf12806 100644
47039--- a/fs/jffs2/wbuf.c
47040+++ b/fs/jffs2/wbuf.c
47041@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
47042 {
47043 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
47044 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47045- .totlen = constant_cpu_to_je32(8)
47046+ .totlen = constant_cpu_to_je32(8),
47047+ .hdr_crc = constant_cpu_to_je32(0)
47048 };
47049
47050 /*
47051diff --git a/fs/jfs/super.c b/fs/jfs/super.c
47052index 4a82950..bcaa0cb 100644
47053--- a/fs/jfs/super.c
47054+++ b/fs/jfs/super.c
47055@@ -801,7 +801,7 @@ static int __init init_jfs_fs(void)
47056
47057 jfs_inode_cachep =
47058 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
47059- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
47060+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
47061 init_once);
47062 if (jfs_inode_cachep == NULL)
47063 return -ENOMEM;
47064diff --git a/fs/libfs.c b/fs/libfs.c
47065index f86ec27..4734776 100644
47066--- a/fs/libfs.c
47067+++ b/fs/libfs.c
47068@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47069
47070 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
47071 struct dentry *next;
47072+ char d_name[sizeof(next->d_iname)];
47073+ const unsigned char *name;
47074+
47075 next = list_entry(p, struct dentry, d_u.d_child);
47076 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
47077 if (!simple_positive(next)) {
47078@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47079
47080 spin_unlock(&next->d_lock);
47081 spin_unlock(&dentry->d_lock);
47082- if (filldir(dirent, next->d_name.name,
47083+ name = next->d_name.name;
47084+ if (name == next->d_iname) {
47085+ memcpy(d_name, name, next->d_name.len);
47086+ name = d_name;
47087+ }
47088+ if (filldir(dirent, name,
47089 next->d_name.len, filp->f_pos,
47090 next->d_inode->i_ino,
47091 dt_type(next->d_inode)) < 0)
47092diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
47093index 8392cb8..80d6193 100644
47094--- a/fs/lockd/clntproc.c
47095+++ b/fs/lockd/clntproc.c
47096@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
47097 /*
47098 * Cookie counter for NLM requests
47099 */
47100-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
47101+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
47102
47103 void nlmclnt_next_cookie(struct nlm_cookie *c)
47104 {
47105- u32 cookie = atomic_inc_return(&nlm_cookie);
47106+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
47107
47108 memcpy(c->data, &cookie, 4);
47109 c->len=4;
47110diff --git a/fs/locks.c b/fs/locks.c
47111index 82c3533..34e929c 100644
47112--- a/fs/locks.c
47113+++ b/fs/locks.c
47114@@ -2076,16 +2076,16 @@ void locks_remove_flock(struct file *filp)
47115 return;
47116
47117 if (filp->f_op && filp->f_op->flock) {
47118- struct file_lock fl = {
47119+ struct file_lock flock = {
47120 .fl_pid = current->tgid,
47121 .fl_file = filp,
47122 .fl_flags = FL_FLOCK,
47123 .fl_type = F_UNLCK,
47124 .fl_end = OFFSET_MAX,
47125 };
47126- filp->f_op->flock(filp, F_SETLKW, &fl);
47127- if (fl.fl_ops && fl.fl_ops->fl_release_private)
47128- fl.fl_ops->fl_release_private(&fl);
47129+ filp->f_op->flock(filp, F_SETLKW, &flock);
47130+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
47131+ flock.fl_ops->fl_release_private(&flock);
47132 }
47133
47134 lock_flocks();
47135diff --git a/fs/namei.c b/fs/namei.c
47136index 7d69419..10c6af6 100644
47137--- a/fs/namei.c
47138+++ b/fs/namei.c
47139@@ -265,16 +265,32 @@ int generic_permission(struct inode *inode, int mask)
47140 if (ret != -EACCES)
47141 return ret;
47142
47143+#ifdef CONFIG_GRKERNSEC
47144+ /* we'll block if we have to log due to a denied capability use */
47145+ if (mask & MAY_NOT_BLOCK)
47146+ return -ECHILD;
47147+#endif
47148+
47149 if (S_ISDIR(inode->i_mode)) {
47150 /* DACs are overridable for directories */
47151- if (inode_capable(inode, CAP_DAC_OVERRIDE))
47152- return 0;
47153 if (!(mask & MAY_WRITE))
47154- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47155+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47156+ inode_capable(inode, CAP_DAC_READ_SEARCH))
47157 return 0;
47158+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
47159+ return 0;
47160 return -EACCES;
47161 }
47162 /*
47163+ * Searching includes executable on directories, else just read.
47164+ */
47165+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47166+ if (mask == MAY_READ)
47167+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47168+ inode_capable(inode, CAP_DAC_READ_SEARCH))
47169+ return 0;
47170+
47171+ /*
47172 * Read/write DACs are always overridable.
47173 * Executable DACs are overridable when there is
47174 * at least one exec bit set.
47175@@ -283,14 +299,6 @@ int generic_permission(struct inode *inode, int mask)
47176 if (inode_capable(inode, CAP_DAC_OVERRIDE))
47177 return 0;
47178
47179- /*
47180- * Searching includes executable on directories, else just read.
47181- */
47182- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47183- if (mask == MAY_READ)
47184- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47185- return 0;
47186-
47187 return -EACCES;
47188 }
47189
47190@@ -639,11 +647,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47191 return error;
47192 }
47193
47194+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
47195+ dentry->d_inode, dentry, nd->path.mnt)) {
47196+ error = -EACCES;
47197+ *p = ERR_PTR(error); /* no ->put_link(), please */
47198+ path_put(&nd->path);
47199+ return error;
47200+ }
47201+
47202 nd->last_type = LAST_BIND;
47203 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
47204 error = PTR_ERR(*p);
47205 if (!IS_ERR(*p)) {
47206- char *s = nd_get_link(nd);
47207+ const char *s = nd_get_link(nd);
47208 error = 0;
47209 if (s)
47210 error = __vfs_follow_link(nd, s);
47211@@ -1386,6 +1402,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
47212 if (!res)
47213 res = walk_component(nd, path, &nd->last,
47214 nd->last_type, LOOKUP_FOLLOW);
47215+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
47216+ res = -EACCES;
47217 put_link(nd, &link, cookie);
47218 } while (res > 0);
47219
47220@@ -1779,6 +1797,8 @@ static int path_lookupat(int dfd, const char *name,
47221 err = follow_link(&link, nd, &cookie);
47222 if (!err)
47223 err = lookup_last(nd, &path);
47224+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
47225+ err = -EACCES;
47226 put_link(nd, &link, cookie);
47227 }
47228 }
47229@@ -1786,6 +1806,21 @@ static int path_lookupat(int dfd, const char *name,
47230 if (!err)
47231 err = complete_walk(nd);
47232
47233+ if (!(nd->flags & LOOKUP_PARENT)) {
47234+#ifdef CONFIG_GRKERNSEC
47235+ if (flags & LOOKUP_RCU) {
47236+ if (!err)
47237+ path_put(&nd->path);
47238+ err = -ECHILD;
47239+ } else
47240+#endif
47241+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47242+ if (!err)
47243+ path_put(&nd->path);
47244+ err = -ENOENT;
47245+ }
47246+ }
47247+
47248 if (!err && nd->flags & LOOKUP_DIRECTORY) {
47249 if (!nd->inode->i_op->lookup) {
47250 path_put(&nd->path);
47251@@ -1813,6 +1848,15 @@ static int do_path_lookup(int dfd, const char *name,
47252 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
47253
47254 if (likely(!retval)) {
47255+ if (*name != '/' && nd->path.dentry && nd->inode) {
47256+#ifdef CONFIG_GRKERNSEC
47257+ if (flags & LOOKUP_RCU)
47258+ return -ECHILD;
47259+#endif
47260+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
47261+ return -ENOENT;
47262+ }
47263+
47264 if (unlikely(!audit_dummy_context())) {
47265 if (nd->path.dentry && nd->inode)
47266 audit_inode(name, nd->path.dentry);
47267@@ -2155,6 +2199,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
47268 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
47269 return -EPERM;
47270
47271+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
47272+ return -EPERM;
47273+ if (gr_handle_rawio(inode))
47274+ return -EPERM;
47275+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
47276+ return -EACCES;
47277+
47278 return 0;
47279 }
47280
47281@@ -2190,7 +2241,7 @@ static inline int open_to_namei_flags(int flag)
47282 /*
47283 * Handle the last step of open()
47284 */
47285-static struct file *do_last(struct nameidata *nd, struct path *path,
47286+static struct file *do_last(struct nameidata *nd, struct path *path, struct path *link,
47287 const struct open_flags *op, const char *pathname)
47288 {
47289 struct dentry *dir = nd->path.dentry;
47290@@ -2220,16 +2271,44 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47291 error = complete_walk(nd);
47292 if (error)
47293 return ERR_PTR(error);
47294+#ifdef CONFIG_GRKERNSEC
47295+ if (nd->flags & LOOKUP_RCU) {
47296+ error = -ECHILD;
47297+ goto exit;
47298+ }
47299+#endif
47300+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47301+ error = -ENOENT;
47302+ goto exit;
47303+ }
47304 audit_inode(pathname, nd->path.dentry);
47305 if (open_flag & O_CREAT) {
47306 error = -EISDIR;
47307 goto exit;
47308 }
47309+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
47310+ error = -EACCES;
47311+ goto exit;
47312+ }
47313 goto ok;
47314 case LAST_BIND:
47315 error = complete_walk(nd);
47316 if (error)
47317 return ERR_PTR(error);
47318+#ifdef CONFIG_GRKERNSEC
47319+ if (nd->flags & LOOKUP_RCU) {
47320+ error = -ECHILD;
47321+ goto exit;
47322+ }
47323+#endif
47324+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
47325+ error = -ENOENT;
47326+ goto exit;
47327+ }
47328+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
47329+ error = -EACCES;
47330+ goto exit;
47331+ }
47332 audit_inode(pathname, dir);
47333 goto ok;
47334 }
47335@@ -2285,6 +2364,12 @@ retry_lookup:
47336 /* Negative dentry, just create the file */
47337 if (!dentry->d_inode) {
47338 umode_t mode = op->mode;
47339+
47340+ if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
47341+ error = -EACCES;
47342+ goto exit_mutex_unlock;
47343+ }
47344+
47345 if (!IS_POSIXACL(dir->d_inode))
47346 mode &= ~current_umask();
47347 /*
47348@@ -2308,6 +2393,8 @@ retry_lookup:
47349 error = vfs_create(dir->d_inode, dentry, mode, nd);
47350 if (error)
47351 goto exit_mutex_unlock;
47352+ else
47353+ gr_handle_create(path->dentry, path->mnt);
47354 mutex_unlock(&dir->d_inode->i_mutex);
47355 dput(nd->path.dentry);
47356 nd->path.dentry = dentry;
47357@@ -2317,6 +2404,23 @@ retry_lookup:
47358 /*
47359 * It already exists.
47360 */
47361+
47362+ if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
47363+ error = -ENOENT;
47364+ goto exit_mutex_unlock;
47365+ }
47366+ if (link && gr_handle_symlink_owner(link, dentry->d_inode)) {
47367+ error = -EACCES;
47368+ goto exit_mutex_unlock;
47369+ }
47370+
47371+ /* only check if O_CREAT is specified, all other checks need to go
47372+ into may_open */
47373+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
47374+ error = -EACCES;
47375+ goto exit_mutex_unlock;
47376+ }
47377+
47378 mutex_unlock(&dir->d_inode->i_mutex);
47379 audit_inode(pathname, path->dentry);
47380
47381@@ -2349,6 +2453,11 @@ finish_lookup:
47382 }
47383 }
47384 BUG_ON(inode != path->dentry->d_inode);
47385+ /* if we're resolving a symlink to another symlink */
47386+ if (link && gr_handle_symlink_owner(link, inode)) {
47387+ error = -EACCES;
47388+ goto exit;
47389+ }
47390 return NULL;
47391 }
47392
47393@@ -2358,7 +2467,6 @@ finish_lookup:
47394 save_parent.dentry = nd->path.dentry;
47395 save_parent.mnt = mntget(path->mnt);
47396 nd->path.dentry = path->dentry;
47397-
47398 }
47399 nd->inode = inode;
47400 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
47401@@ -2367,6 +2475,21 @@ finish_lookup:
47402 path_put(&save_parent);
47403 return ERR_PTR(error);
47404 }
47405+#ifdef CONFIG_GRKERNSEC
47406+ if (nd->flags & LOOKUP_RCU) {
47407+ error = -ECHILD;
47408+ goto exit;
47409+ }
47410+#endif
47411+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47412+ error = -ENOENT;
47413+ goto exit;
47414+ }
47415+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
47416+ error = -EACCES;
47417+ goto exit;
47418+ }
47419+
47420 error = -EISDIR;
47421 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
47422 goto exit;
47423@@ -2461,7 +2584,7 @@ static struct file *path_openat(int dfd, const char *pathname,
47424 if (unlikely(error))
47425 goto out_filp;
47426
47427- filp = do_last(nd, &path, op, pathname);
47428+ filp = do_last(nd, &path, NULL, op, pathname);
47429 while (unlikely(!filp)) { /* trailing symlink */
47430 struct path link = path;
47431 void *cookie;
47432@@ -2476,8 +2599,9 @@ static struct file *path_openat(int dfd, const char *pathname,
47433 error = follow_link(&link, nd, &cookie);
47434 if (unlikely(error))
47435 filp = ERR_PTR(error);
47436- else
47437- filp = do_last(nd, &path, op, pathname);
47438+ else {
47439+ filp = do_last(nd, &path, &link, op, pathname);
47440+ }
47441 put_link(nd, &link, cookie);
47442 }
47443 out:
47444@@ -2577,6 +2701,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
47445 *path = nd.path;
47446 return dentry;
47447 eexist:
47448+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
47449+ dput(dentry);
47450+ dentry = ERR_PTR(-ENOENT);
47451+ goto fail;
47452+ }
47453 dput(dentry);
47454 dentry = ERR_PTR(-EEXIST);
47455 fail:
47456@@ -2599,6 +2728,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
47457 }
47458 EXPORT_SYMBOL(user_path_create);
47459
47460+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
47461+{
47462+ char *tmp = getname(pathname);
47463+ struct dentry *res;
47464+ if (IS_ERR(tmp))
47465+ return ERR_CAST(tmp);
47466+ res = kern_path_create(dfd, tmp, path, is_dir);
47467+ if (IS_ERR(res))
47468+ putname(tmp);
47469+ else
47470+ *to = tmp;
47471+ return res;
47472+}
47473+
47474 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
47475 {
47476 int error = may_create(dir, dentry);
47477@@ -2665,6 +2808,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47478 error = mnt_want_write(path.mnt);
47479 if (error)
47480 goto out_dput;
47481+
47482+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
47483+ error = -EPERM;
47484+ goto out_drop_write;
47485+ }
47486+
47487+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
47488+ error = -EACCES;
47489+ goto out_drop_write;
47490+ }
47491+
47492 error = security_path_mknod(&path, dentry, mode, dev);
47493 if (error)
47494 goto out_drop_write;
47495@@ -2682,6 +2836,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47496 }
47497 out_drop_write:
47498 mnt_drop_write(path.mnt);
47499+
47500+ if (!error)
47501+ gr_handle_create(dentry, path.mnt);
47502 out_dput:
47503 dput(dentry);
47504 mutex_unlock(&path.dentry->d_inode->i_mutex);
47505@@ -2735,12 +2892,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
47506 error = mnt_want_write(path.mnt);
47507 if (error)
47508 goto out_dput;
47509+
47510+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
47511+ error = -EACCES;
47512+ goto out_drop_write;
47513+ }
47514+
47515 error = security_path_mkdir(&path, dentry, mode);
47516 if (error)
47517 goto out_drop_write;
47518 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
47519 out_drop_write:
47520 mnt_drop_write(path.mnt);
47521+
47522+ if (!error)
47523+ gr_handle_create(dentry, path.mnt);
47524 out_dput:
47525 dput(dentry);
47526 mutex_unlock(&path.dentry->d_inode->i_mutex);
47527@@ -2820,6 +2986,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47528 char * name;
47529 struct dentry *dentry;
47530 struct nameidata nd;
47531+ ino_t saved_ino = 0;
47532+ dev_t saved_dev = 0;
47533
47534 error = user_path_parent(dfd, pathname, &nd, &name);
47535 if (error)
47536@@ -2848,6 +3016,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
47537 error = -ENOENT;
47538 goto exit3;
47539 }
47540+
47541+ saved_ino = dentry->d_inode->i_ino;
47542+ saved_dev = gr_get_dev_from_dentry(dentry);
47543+
47544+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
47545+ error = -EACCES;
47546+ goto exit3;
47547+ }
47548+
47549 error = mnt_want_write(nd.path.mnt);
47550 if (error)
47551 goto exit3;
47552@@ -2855,6 +3032,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47553 if (error)
47554 goto exit4;
47555 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
47556+ if (!error && (saved_dev || saved_ino))
47557+ gr_handle_delete(saved_ino, saved_dev);
47558 exit4:
47559 mnt_drop_write(nd.path.mnt);
47560 exit3:
47561@@ -2917,6 +3096,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47562 struct dentry *dentry;
47563 struct nameidata nd;
47564 struct inode *inode = NULL;
47565+ ino_t saved_ino = 0;
47566+ dev_t saved_dev = 0;
47567
47568 error = user_path_parent(dfd, pathname, &nd, &name);
47569 if (error)
47570@@ -2939,6 +3120,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47571 if (!inode)
47572 goto slashes;
47573 ihold(inode);
47574+
47575+ if (inode->i_nlink <= 1) {
47576+ saved_ino = inode->i_ino;
47577+ saved_dev = gr_get_dev_from_dentry(dentry);
47578+ }
47579+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
47580+ error = -EACCES;
47581+ goto exit2;
47582+ }
47583+
47584 error = mnt_want_write(nd.path.mnt);
47585 if (error)
47586 goto exit2;
47587@@ -2946,6 +3137,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47588 if (error)
47589 goto exit3;
47590 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
47591+ if (!error && (saved_ino || saved_dev))
47592+ gr_handle_delete(saved_ino, saved_dev);
47593 exit3:
47594 mnt_drop_write(nd.path.mnt);
47595 exit2:
47596@@ -3021,10 +3214,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
47597 error = mnt_want_write(path.mnt);
47598 if (error)
47599 goto out_dput;
47600+
47601+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
47602+ error = -EACCES;
47603+ goto out_drop_write;
47604+ }
47605+
47606 error = security_path_symlink(&path, dentry, from);
47607 if (error)
47608 goto out_drop_write;
47609 error = vfs_symlink(path.dentry->d_inode, dentry, from);
47610+ if (!error)
47611+ gr_handle_create(dentry, path.mnt);
47612 out_drop_write:
47613 mnt_drop_write(path.mnt);
47614 out_dput:
47615@@ -3099,6 +3300,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47616 {
47617 struct dentry *new_dentry;
47618 struct path old_path, new_path;
47619+ char *to = NULL;
47620 int how = 0;
47621 int error;
47622
47623@@ -3122,7 +3324,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47624 if (error)
47625 return error;
47626
47627- new_dentry = user_path_create(newdfd, newname, &new_path, 0);
47628+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
47629 error = PTR_ERR(new_dentry);
47630 if (IS_ERR(new_dentry))
47631 goto out;
47632@@ -3133,13 +3335,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47633 error = mnt_want_write(new_path.mnt);
47634 if (error)
47635 goto out_dput;
47636+
47637+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
47638+ old_path.dentry->d_inode,
47639+ old_path.dentry->d_inode->i_mode, to)) {
47640+ error = -EACCES;
47641+ goto out_drop_write;
47642+ }
47643+
47644+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
47645+ old_path.dentry, old_path.mnt, to)) {
47646+ error = -EACCES;
47647+ goto out_drop_write;
47648+ }
47649+
47650 error = security_path_link(old_path.dentry, &new_path, new_dentry);
47651 if (error)
47652 goto out_drop_write;
47653 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
47654+ if (!error)
47655+ gr_handle_create(new_dentry, new_path.mnt);
47656 out_drop_write:
47657 mnt_drop_write(new_path.mnt);
47658 out_dput:
47659+ putname(to);
47660 dput(new_dentry);
47661 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
47662 path_put(&new_path);
47663@@ -3373,6 +3592,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47664 if (new_dentry == trap)
47665 goto exit5;
47666
47667+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
47668+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
47669+ to);
47670+ if (error)
47671+ goto exit5;
47672+
47673 error = mnt_want_write(oldnd.path.mnt);
47674 if (error)
47675 goto exit5;
47676@@ -3382,6 +3607,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47677 goto exit6;
47678 error = vfs_rename(old_dir->d_inode, old_dentry,
47679 new_dir->d_inode, new_dentry);
47680+ if (!error)
47681+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
47682+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
47683 exit6:
47684 mnt_drop_write(oldnd.path.mnt);
47685 exit5:
47686@@ -3407,6 +3635,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
47687
47688 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
47689 {
47690+ char tmpbuf[64];
47691+ const char *newlink;
47692 int len;
47693
47694 len = PTR_ERR(link);
47695@@ -3416,7 +3646,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
47696 len = strlen(link);
47697 if (len > (unsigned) buflen)
47698 len = buflen;
47699- if (copy_to_user(buffer, link, len))
47700+
47701+ if (len < sizeof(tmpbuf)) {
47702+ memcpy(tmpbuf, link, len);
47703+ newlink = tmpbuf;
47704+ } else
47705+ newlink = link;
47706+
47707+ if (copy_to_user(buffer, newlink, len))
47708 len = -EFAULT;
47709 out:
47710 return len;
47711diff --git a/fs/namespace.c b/fs/namespace.c
47712index 1e4a5fe..a5ce747 100644
47713--- a/fs/namespace.c
47714+++ b/fs/namespace.c
47715@@ -1157,6 +1157,9 @@ static int do_umount(struct mount *mnt, int flags)
47716 if (!(sb->s_flags & MS_RDONLY))
47717 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
47718 up_write(&sb->s_umount);
47719+
47720+ gr_log_remount(mnt->mnt_devname, retval);
47721+
47722 return retval;
47723 }
47724
47725@@ -1176,6 +1179,9 @@ static int do_umount(struct mount *mnt, int flags)
47726 br_write_unlock(&vfsmount_lock);
47727 up_write(&namespace_sem);
47728 release_mounts(&umount_list);
47729+
47730+ gr_log_unmount(mnt->mnt_devname, retval);
47731+
47732 return retval;
47733 }
47734
47735@@ -2177,6 +2183,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47736 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
47737 MS_STRICTATIME);
47738
47739+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
47740+ retval = -EPERM;
47741+ goto dput_out;
47742+ }
47743+
47744+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
47745+ retval = -EPERM;
47746+ goto dput_out;
47747+ }
47748+
47749 if (flags & MS_REMOUNT)
47750 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
47751 data_page);
47752@@ -2191,6 +2207,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47753 dev_name, data_page);
47754 dput_out:
47755 path_put(&path);
47756+
47757+ gr_log_mount(dev_name, dir_name, retval);
47758+
47759 return retval;
47760 }
47761
47762@@ -2472,6 +2491,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
47763 if (error)
47764 goto out2;
47765
47766+ if (gr_handle_chroot_pivot()) {
47767+ error = -EPERM;
47768+ goto out2;
47769+ }
47770+
47771 get_fs_root(current->fs, &root);
47772 error = lock_mount(&old);
47773 if (error)
47774diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
47775index f729698..2bac081 100644
47776--- a/fs/nfs/inode.c
47777+++ b/fs/nfs/inode.c
47778@@ -152,7 +152,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
47779 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
47780 nfsi->attrtimeo_timestamp = jiffies;
47781
47782- memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
47783+ memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
47784 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
47785 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
47786 else
47787@@ -1008,16 +1008,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
47788 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
47789 }
47790
47791-static atomic_long_t nfs_attr_generation_counter;
47792+static atomic_long_unchecked_t nfs_attr_generation_counter;
47793
47794 static unsigned long nfs_read_attr_generation_counter(void)
47795 {
47796- return atomic_long_read(&nfs_attr_generation_counter);
47797+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
47798 }
47799
47800 unsigned long nfs_inc_attr_generation_counter(void)
47801 {
47802- return atomic_long_inc_return(&nfs_attr_generation_counter);
47803+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
47804 }
47805
47806 void nfs_fattr_init(struct nfs_fattr *fattr)
47807diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
47808index c8bd9c3..4f83416 100644
47809--- a/fs/nfsd/vfs.c
47810+++ b/fs/nfsd/vfs.c
47811@@ -933,7 +933,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47812 } else {
47813 oldfs = get_fs();
47814 set_fs(KERNEL_DS);
47815- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
47816+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
47817 set_fs(oldfs);
47818 }
47819
47820@@ -1037,7 +1037,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47821
47822 /* Write the data. */
47823 oldfs = get_fs(); set_fs(KERNEL_DS);
47824- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
47825+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
47826 set_fs(oldfs);
47827 if (host_err < 0)
47828 goto out_nfserr;
47829@@ -1573,7 +1573,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
47830 */
47831
47832 oldfs = get_fs(); set_fs(KERNEL_DS);
47833- host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
47834+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
47835 set_fs(oldfs);
47836
47837 if (host_err < 0)
47838diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
47839index 3568c8a..e0240d8 100644
47840--- a/fs/notify/fanotify/fanotify_user.c
47841+++ b/fs/notify/fanotify/fanotify_user.c
47842@@ -278,7 +278,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
47843 goto out_close_fd;
47844
47845 ret = -EFAULT;
47846- if (copy_to_user(buf, &fanotify_event_metadata,
47847+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
47848+ copy_to_user(buf, &fanotify_event_metadata,
47849 fanotify_event_metadata.event_len))
47850 goto out_kill_access_response;
47851
47852diff --git a/fs/notify/notification.c b/fs/notify/notification.c
47853index c887b13..0fdf472 100644
47854--- a/fs/notify/notification.c
47855+++ b/fs/notify/notification.c
47856@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
47857 * get set to 0 so it will never get 'freed'
47858 */
47859 static struct fsnotify_event *q_overflow_event;
47860-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47861+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47862
47863 /**
47864 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
47865@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47866 */
47867 u32 fsnotify_get_cookie(void)
47868 {
47869- return atomic_inc_return(&fsnotify_sync_cookie);
47870+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
47871 }
47872 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
47873
47874diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
47875index 99e3610..02c1068 100644
47876--- a/fs/ntfs/dir.c
47877+++ b/fs/ntfs/dir.c
47878@@ -1329,7 +1329,7 @@ find_next_index_buffer:
47879 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
47880 ~(s64)(ndir->itype.index.block_size - 1)));
47881 /* Bounds checks. */
47882- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47883+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47884 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
47885 "inode 0x%lx or driver bug.", vdir->i_ino);
47886 goto err_out;
47887diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
47888index 7389d2d..dfd5dbe 100644
47889--- a/fs/ntfs/file.c
47890+++ b/fs/ntfs/file.c
47891@@ -2231,6 +2231,6 @@ const struct inode_operations ntfs_file_inode_ops = {
47892 #endif /* NTFS_RW */
47893 };
47894
47895-const struct file_operations ntfs_empty_file_ops = {};
47896+const struct file_operations ntfs_empty_file_ops __read_only;
47897
47898-const struct inode_operations ntfs_empty_inode_ops = {};
47899+const struct inode_operations ntfs_empty_inode_ops __read_only;
47900diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
47901index 210c352..a174f83 100644
47902--- a/fs/ocfs2/localalloc.c
47903+++ b/fs/ocfs2/localalloc.c
47904@@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
47905 goto bail;
47906 }
47907
47908- atomic_inc(&osb->alloc_stats.moves);
47909+ atomic_inc_unchecked(&osb->alloc_stats.moves);
47910
47911 bail:
47912 if (handle)
47913diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
47914index d355e6e..578d905 100644
47915--- a/fs/ocfs2/ocfs2.h
47916+++ b/fs/ocfs2/ocfs2.h
47917@@ -235,11 +235,11 @@ enum ocfs2_vol_state
47918
47919 struct ocfs2_alloc_stats
47920 {
47921- atomic_t moves;
47922- atomic_t local_data;
47923- atomic_t bitmap_data;
47924- atomic_t bg_allocs;
47925- atomic_t bg_extends;
47926+ atomic_unchecked_t moves;
47927+ atomic_unchecked_t local_data;
47928+ atomic_unchecked_t bitmap_data;
47929+ atomic_unchecked_t bg_allocs;
47930+ atomic_unchecked_t bg_extends;
47931 };
47932
47933 enum ocfs2_local_alloc_state
47934diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
47935index f169da4..9112253 100644
47936--- a/fs/ocfs2/suballoc.c
47937+++ b/fs/ocfs2/suballoc.c
47938@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
47939 mlog_errno(status);
47940 goto bail;
47941 }
47942- atomic_inc(&osb->alloc_stats.bg_extends);
47943+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
47944
47945 /* You should never ask for this much metadata */
47946 BUG_ON(bits_wanted >
47947@@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
47948 mlog_errno(status);
47949 goto bail;
47950 }
47951- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47952+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47953
47954 *suballoc_loc = res.sr_bg_blkno;
47955 *suballoc_bit_start = res.sr_bit_offset;
47956@@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
47957 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
47958 res->sr_bits);
47959
47960- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47961+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47962
47963 BUG_ON(res->sr_bits != 1);
47964
47965@@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
47966 mlog_errno(status);
47967 goto bail;
47968 }
47969- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47970+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47971
47972 BUG_ON(res.sr_bits != 1);
47973
47974@@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47975 cluster_start,
47976 num_clusters);
47977 if (!status)
47978- atomic_inc(&osb->alloc_stats.local_data);
47979+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
47980 } else {
47981 if (min_clusters > (osb->bitmap_cpg - 1)) {
47982 /* The only paths asking for contiguousness
47983@@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47984 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
47985 res.sr_bg_blkno,
47986 res.sr_bit_offset);
47987- atomic_inc(&osb->alloc_stats.bitmap_data);
47988+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
47989 *num_clusters = res.sr_bits;
47990 }
47991 }
47992diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
47993index 68f4541..89cfe6a 100644
47994--- a/fs/ocfs2/super.c
47995+++ b/fs/ocfs2/super.c
47996@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
47997 "%10s => GlobalAllocs: %d LocalAllocs: %d "
47998 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
47999 "Stats",
48000- atomic_read(&osb->alloc_stats.bitmap_data),
48001- atomic_read(&osb->alloc_stats.local_data),
48002- atomic_read(&osb->alloc_stats.bg_allocs),
48003- atomic_read(&osb->alloc_stats.moves),
48004- atomic_read(&osb->alloc_stats.bg_extends));
48005+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
48006+ atomic_read_unchecked(&osb->alloc_stats.local_data),
48007+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
48008+ atomic_read_unchecked(&osb->alloc_stats.moves),
48009+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
48010
48011 out += snprintf(buf + out, len - out,
48012 "%10s => State: %u Descriptor: %llu Size: %u bits "
48013@@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
48014 spin_lock_init(&osb->osb_xattr_lock);
48015 ocfs2_init_steal_slots(osb);
48016
48017- atomic_set(&osb->alloc_stats.moves, 0);
48018- atomic_set(&osb->alloc_stats.local_data, 0);
48019- atomic_set(&osb->alloc_stats.bitmap_data, 0);
48020- atomic_set(&osb->alloc_stats.bg_allocs, 0);
48021- atomic_set(&osb->alloc_stats.bg_extends, 0);
48022+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
48023+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
48024+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
48025+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
48026+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
48027
48028 /* Copy the blockcheck stats from the superblock probe */
48029 osb->osb_ecc_stats = *stats;
48030diff --git a/fs/open.c b/fs/open.c
48031index 1540632..79d7242 100644
48032--- a/fs/open.c
48033+++ b/fs/open.c
48034@@ -31,6 +31,8 @@
48035 #include <linux/ima.h>
48036 #include <linux/dnotify.h>
48037
48038+#define CREATE_TRACE_POINTS
48039+#include <trace/events/fs.h>
48040 #include "internal.h"
48041
48042 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
48043@@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
48044 error = locks_verify_truncate(inode, NULL, length);
48045 if (!error)
48046 error = security_path_truncate(&path);
48047+
48048+ if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
48049+ error = -EACCES;
48050+
48051 if (!error)
48052 error = do_truncate(path.dentry, length, 0, NULL);
48053
48054@@ -359,6 +365,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
48055 if (__mnt_is_readonly(path.mnt))
48056 res = -EROFS;
48057
48058+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
48059+ res = -EACCES;
48060+
48061 out_path_release:
48062 path_put(&path);
48063 out:
48064@@ -385,6 +394,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
48065 if (error)
48066 goto dput_and_out;
48067
48068+ gr_log_chdir(path.dentry, path.mnt);
48069+
48070 set_fs_pwd(current->fs, &path);
48071
48072 dput_and_out:
48073@@ -411,6 +422,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
48074 goto out_putf;
48075
48076 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
48077+
48078+ if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
48079+ error = -EPERM;
48080+
48081+ if (!error)
48082+ gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
48083+
48084 if (!error)
48085 set_fs_pwd(current->fs, &file->f_path);
48086 out_putf:
48087@@ -439,7 +457,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
48088 if (error)
48089 goto dput_and_out;
48090
48091+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
48092+ goto dput_and_out;
48093+
48094 set_fs_root(current->fs, &path);
48095+
48096+ gr_handle_chroot_chdir(&path);
48097+
48098 error = 0;
48099 dput_and_out:
48100 path_put(&path);
48101@@ -457,6 +481,16 @@ static int chmod_common(struct path *path, umode_t mode)
48102 if (error)
48103 return error;
48104 mutex_lock(&inode->i_mutex);
48105+
48106+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
48107+ error = -EACCES;
48108+ goto out_unlock;
48109+ }
48110+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
48111+ error = -EACCES;
48112+ goto out_unlock;
48113+ }
48114+
48115 error = security_path_chmod(path, mode);
48116 if (error)
48117 goto out_unlock;
48118@@ -512,6 +546,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
48119 uid = make_kuid(current_user_ns(), user);
48120 gid = make_kgid(current_user_ns(), group);
48121
48122+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
48123+ return -EACCES;
48124+
48125 newattrs.ia_valid = ATTR_CTIME;
48126 if (user != (uid_t) -1) {
48127 if (!uid_valid(uid))
48128@@ -1035,6 +1072,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
48129 } else {
48130 fsnotify_open(f);
48131 fd_install(fd, f);
48132+ trace_do_sys_open(tmp, flags, mode);
48133 }
48134 }
48135 putname(tmp);
48136diff --git a/fs/pipe.c b/fs/pipe.c
48137index 49c1065..13b9e12 100644
48138--- a/fs/pipe.c
48139+++ b/fs/pipe.c
48140@@ -438,9 +438,9 @@ redo:
48141 }
48142 if (bufs) /* More to do? */
48143 continue;
48144- if (!pipe->writers)
48145+ if (!atomic_read(&pipe->writers))
48146 break;
48147- if (!pipe->waiting_writers) {
48148+ if (!atomic_read(&pipe->waiting_writers)) {
48149 /* syscall merging: Usually we must not sleep
48150 * if O_NONBLOCK is set, or if we got some data.
48151 * But if a writer sleeps in kernel space, then
48152@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
48153 mutex_lock(&inode->i_mutex);
48154 pipe = inode->i_pipe;
48155
48156- if (!pipe->readers) {
48157+ if (!atomic_read(&pipe->readers)) {
48158 send_sig(SIGPIPE, current, 0);
48159 ret = -EPIPE;
48160 goto out;
48161@@ -553,7 +553,7 @@ redo1:
48162 for (;;) {
48163 int bufs;
48164
48165- if (!pipe->readers) {
48166+ if (!atomic_read(&pipe->readers)) {
48167 send_sig(SIGPIPE, current, 0);
48168 if (!ret)
48169 ret = -EPIPE;
48170@@ -644,9 +644,9 @@ redo2:
48171 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
48172 do_wakeup = 0;
48173 }
48174- pipe->waiting_writers++;
48175+ atomic_inc(&pipe->waiting_writers);
48176 pipe_wait(pipe);
48177- pipe->waiting_writers--;
48178+ atomic_dec(&pipe->waiting_writers);
48179 }
48180 out:
48181 mutex_unlock(&inode->i_mutex);
48182@@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48183 mask = 0;
48184 if (filp->f_mode & FMODE_READ) {
48185 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
48186- if (!pipe->writers && filp->f_version != pipe->w_counter)
48187+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
48188 mask |= POLLHUP;
48189 }
48190
48191@@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48192 * Most Unices do not set POLLERR for FIFOs but on Linux they
48193 * behave exactly like pipes for poll().
48194 */
48195- if (!pipe->readers)
48196+ if (!atomic_read(&pipe->readers))
48197 mask |= POLLERR;
48198 }
48199
48200@@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
48201
48202 mutex_lock(&inode->i_mutex);
48203 pipe = inode->i_pipe;
48204- pipe->readers -= decr;
48205- pipe->writers -= decw;
48206+ atomic_sub(decr, &pipe->readers);
48207+ atomic_sub(decw, &pipe->writers);
48208
48209- if (!pipe->readers && !pipe->writers) {
48210+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
48211 free_pipe_info(inode);
48212 } else {
48213 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
48214@@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
48215
48216 if (inode->i_pipe) {
48217 ret = 0;
48218- inode->i_pipe->readers++;
48219+ atomic_inc(&inode->i_pipe->readers);
48220 }
48221
48222 mutex_unlock(&inode->i_mutex);
48223@@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
48224
48225 if (inode->i_pipe) {
48226 ret = 0;
48227- inode->i_pipe->writers++;
48228+ atomic_inc(&inode->i_pipe->writers);
48229 }
48230
48231 mutex_unlock(&inode->i_mutex);
48232@@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
48233 if (inode->i_pipe) {
48234 ret = 0;
48235 if (filp->f_mode & FMODE_READ)
48236- inode->i_pipe->readers++;
48237+ atomic_inc(&inode->i_pipe->readers);
48238 if (filp->f_mode & FMODE_WRITE)
48239- inode->i_pipe->writers++;
48240+ atomic_inc(&inode->i_pipe->writers);
48241 }
48242
48243 mutex_unlock(&inode->i_mutex);
48244@@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
48245 inode->i_pipe = NULL;
48246 }
48247
48248-static struct vfsmount *pipe_mnt __read_mostly;
48249+struct vfsmount *pipe_mnt __read_mostly;
48250
48251 /*
48252 * pipefs_dname() is called from d_path().
48253@@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
48254 goto fail_iput;
48255 inode->i_pipe = pipe;
48256
48257- pipe->readers = pipe->writers = 1;
48258+ atomic_set(&pipe->readers, 1);
48259+ atomic_set(&pipe->writers, 1);
48260 inode->i_fop = &rdwr_pipefifo_fops;
48261
48262 /*
48263diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
48264index 15af622..0e9f4467 100644
48265--- a/fs/proc/Kconfig
48266+++ b/fs/proc/Kconfig
48267@@ -30,12 +30,12 @@ config PROC_FS
48268
48269 config PROC_KCORE
48270 bool "/proc/kcore support" if !ARM
48271- depends on PROC_FS && MMU
48272+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
48273
48274 config PROC_VMCORE
48275 bool "/proc/vmcore support"
48276- depends on PROC_FS && CRASH_DUMP
48277- default y
48278+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
48279+ default n
48280 help
48281 Exports the dump image of crashed kernel in ELF format.
48282
48283@@ -59,8 +59,8 @@ config PROC_SYSCTL
48284 limited in memory.
48285
48286 config PROC_PAGE_MONITOR
48287- default y
48288- depends on PROC_FS && MMU
48289+ default n
48290+ depends on PROC_FS && MMU && !GRKERNSEC
48291 bool "Enable /proc page monitoring" if EXPERT
48292 help
48293 Various /proc files exist to monitor process memory utilization:
48294diff --git a/fs/proc/array.c b/fs/proc/array.c
48295index c1c207c..5179411 100644
48296--- a/fs/proc/array.c
48297+++ b/fs/proc/array.c
48298@@ -60,6 +60,7 @@
48299 #include <linux/tty.h>
48300 #include <linux/string.h>
48301 #include <linux/mman.h>
48302+#include <linux/grsecurity.h>
48303 #include <linux/proc_fs.h>
48304 #include <linux/ioport.h>
48305 #include <linux/uaccess.h>
48306@@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
48307 seq_putc(m, '\n');
48308 }
48309
48310+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48311+static inline void task_pax(struct seq_file *m, struct task_struct *p)
48312+{
48313+ if (p->mm)
48314+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
48315+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
48316+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
48317+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
48318+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
48319+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
48320+ else
48321+ seq_printf(m, "PaX:\t-----\n");
48322+}
48323+#endif
48324+
48325 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48326 struct pid *pid, struct task_struct *task)
48327 {
48328@@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48329 task_cpus_allowed(m, task);
48330 cpuset_task_status_allowed(m, task);
48331 task_context_switch_counts(m, task);
48332+
48333+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48334+ task_pax(m, task);
48335+#endif
48336+
48337+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
48338+ task_grsec_rbac(m, task);
48339+#endif
48340+
48341 return 0;
48342 }
48343
48344+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48345+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48346+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
48347+ _mm->pax_flags & MF_PAX_SEGMEXEC))
48348+#endif
48349+
48350 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48351 struct pid *pid, struct task_struct *task, int whole)
48352 {
48353@@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48354 char tcomm[sizeof(task->comm)];
48355 unsigned long flags;
48356
48357+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48358+ if (current->exec_id != m->exec_id) {
48359+ gr_log_badprocpid("stat");
48360+ return 0;
48361+ }
48362+#endif
48363+
48364 state = *get_task_state(task);
48365 vsize = eip = esp = 0;
48366 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48367@@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48368 gtime = task->gtime;
48369 }
48370
48371+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48372+ if (PAX_RAND_FLAGS(mm)) {
48373+ eip = 0;
48374+ esp = 0;
48375+ wchan = 0;
48376+ }
48377+#endif
48378+#ifdef CONFIG_GRKERNSEC_HIDESYM
48379+ wchan = 0;
48380+ eip =0;
48381+ esp =0;
48382+#endif
48383+
48384 /* scale priority and nice values from timeslices to -20..20 */
48385 /* to make it look like a "normal" Unix priority/nice value */
48386 priority = task_prio(task);
48387@@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48388 seq_put_decimal_ull(m, ' ', vsize);
48389 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
48390 seq_put_decimal_ull(m, ' ', rsslim);
48391+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48392+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
48393+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
48394+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
48395+#else
48396 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
48397 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
48398 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
48399+#endif
48400 seq_put_decimal_ull(m, ' ', esp);
48401 seq_put_decimal_ull(m, ' ', eip);
48402 /* The signal information here is obsolete.
48403@@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48404 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
48405 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
48406
48407- if (mm && permitted) {
48408+ if (mm && permitted
48409+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48410+ && !PAX_RAND_FLAGS(mm)
48411+#endif
48412+ ) {
48413 seq_put_decimal_ull(m, ' ', mm->start_data);
48414 seq_put_decimal_ull(m, ' ', mm->end_data);
48415 seq_put_decimal_ull(m, ' ', mm->start_brk);
48416@@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48417 struct pid *pid, struct task_struct *task)
48418 {
48419 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
48420- struct mm_struct *mm = get_task_mm(task);
48421+ struct mm_struct *mm;
48422
48423+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48424+ if (current->exec_id != m->exec_id) {
48425+ gr_log_badprocpid("statm");
48426+ return 0;
48427+ }
48428+#endif
48429+ mm = get_task_mm(task);
48430 if (mm) {
48431 size = task_statm(mm, &shared, &text, &data, &resident);
48432 mmput(mm);
48433@@ -580,6 +648,21 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48434 return 0;
48435 }
48436
48437+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48438+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
48439+{
48440+ u32 curr_ip = 0;
48441+ unsigned long flags;
48442+
48443+ if (lock_task_sighand(task, &flags)) {
48444+ curr_ip = task->signal->curr_ip;
48445+ unlock_task_sighand(task, &flags);
48446+ }
48447+
48448+ return sprintf(buffer, "%pI4\n", &curr_ip);
48449+}
48450+#endif
48451+
48452 #ifdef CONFIG_CHECKPOINT_RESTORE
48453 static struct pid *
48454 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
48455diff --git a/fs/proc/base.c b/fs/proc/base.c
48456index 437195f..cd2210d 100644
48457--- a/fs/proc/base.c
48458+++ b/fs/proc/base.c
48459@@ -110,6 +110,14 @@ struct pid_entry {
48460 union proc_op op;
48461 };
48462
48463+struct getdents_callback {
48464+ struct linux_dirent __user * current_dir;
48465+ struct linux_dirent __user * previous;
48466+ struct file * file;
48467+ int count;
48468+ int error;
48469+};
48470+
48471 #define NOD(NAME, MODE, IOP, FOP, OP) { \
48472 .name = (NAME), \
48473 .len = sizeof(NAME) - 1, \
48474@@ -209,6 +217,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
48475 if (!mm->arg_end)
48476 goto out_mm; /* Shh! No looking before we're done */
48477
48478+ if (gr_acl_handle_procpidmem(task))
48479+ goto out_mm;
48480+
48481 len = mm->arg_end - mm->arg_start;
48482
48483 if (len > PAGE_SIZE)
48484@@ -236,12 +247,28 @@ out:
48485 return res;
48486 }
48487
48488+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48489+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48490+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
48491+ _mm->pax_flags & MF_PAX_SEGMEXEC))
48492+#endif
48493+
48494 static int proc_pid_auxv(struct task_struct *task, char *buffer)
48495 {
48496 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
48497 int res = PTR_ERR(mm);
48498 if (mm && !IS_ERR(mm)) {
48499 unsigned int nwords = 0;
48500+
48501+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48502+ /* allow if we're currently ptracing this task */
48503+ if (PAX_RAND_FLAGS(mm) &&
48504+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
48505+ mmput(mm);
48506+ return 0;
48507+ }
48508+#endif
48509+
48510 do {
48511 nwords += 2;
48512 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
48513@@ -255,7 +282,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
48514 }
48515
48516
48517-#ifdef CONFIG_KALLSYMS
48518+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48519 /*
48520 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
48521 * Returns the resolved symbol. If that fails, simply return the address.
48522@@ -294,7 +321,7 @@ static void unlock_trace(struct task_struct *task)
48523 mutex_unlock(&task->signal->cred_guard_mutex);
48524 }
48525
48526-#ifdef CONFIG_STACKTRACE
48527+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48528
48529 #define MAX_STACK_TRACE_DEPTH 64
48530
48531@@ -486,7 +513,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
48532 return count;
48533 }
48534
48535-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48536+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48537 static int proc_pid_syscall(struct task_struct *task, char *buffer)
48538 {
48539 long nr;
48540@@ -515,7 +542,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
48541 /************************************************************************/
48542
48543 /* permission checks */
48544-static int proc_fd_access_allowed(struct inode *inode)
48545+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
48546 {
48547 struct task_struct *task;
48548 int allowed = 0;
48549@@ -525,7 +552,10 @@ static int proc_fd_access_allowed(struct inode *inode)
48550 */
48551 task = get_proc_task(inode);
48552 if (task) {
48553- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48554+ if (log)
48555+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48556+ else
48557+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48558 put_task_struct(task);
48559 }
48560 return allowed;
48561@@ -563,10 +593,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
48562 struct task_struct *task,
48563 int hide_pid_min)
48564 {
48565+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48566+ return false;
48567+
48568+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48569+ rcu_read_lock();
48570+ {
48571+ const struct cred *tmpcred = current_cred();
48572+ const struct cred *cred = __task_cred(task);
48573+
48574+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
48575+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48576+ || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
48577+#endif
48578+ ) {
48579+ rcu_read_unlock();
48580+ return true;
48581+ }
48582+ }
48583+ rcu_read_unlock();
48584+
48585+ if (!pid->hide_pid)
48586+ return false;
48587+#endif
48588+
48589 if (pid->hide_pid < hide_pid_min)
48590 return true;
48591 if (in_group_p(pid->pid_gid))
48592 return true;
48593+
48594 return ptrace_may_access(task, PTRACE_MODE_READ);
48595 }
48596
48597@@ -584,7 +639,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
48598 put_task_struct(task);
48599
48600 if (!has_perms) {
48601+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48602+ {
48603+#else
48604 if (pid->hide_pid == 2) {
48605+#endif
48606 /*
48607 * Let's make getdents(), stat(), and open()
48608 * consistent with each other. If a process
48609@@ -682,6 +741,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
48610 if (!task)
48611 return -ESRCH;
48612
48613+ if (gr_acl_handle_procpidmem(task)) {
48614+ put_task_struct(task);
48615+ return -EPERM;
48616+ }
48617+
48618 mm = mm_access(task, mode);
48619 put_task_struct(task);
48620
48621@@ -695,16 +759,24 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
48622 mmput(mm);
48623 }
48624
48625- /* OK to pass negative loff_t, we can catch out-of-range */
48626- file->f_mode |= FMODE_UNSIGNED_OFFSET;
48627 file->private_data = mm;
48628
48629+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48630+ file->f_version = current->exec_id;
48631+#endif
48632+
48633 return 0;
48634 }
48635
48636 static int mem_open(struct inode *inode, struct file *file)
48637 {
48638- return __mem_open(inode, file, PTRACE_MODE_ATTACH);
48639+ int ret;
48640+ ret = __mem_open(inode, file, PTRACE_MODE_ATTACH);
48641+
48642+ /* OK to pass negative loff_t, we can catch out-of-range */
48643+ file->f_mode |= FMODE_UNSIGNED_OFFSET;
48644+
48645+ return ret;
48646 }
48647
48648 static ssize_t mem_rw(struct file *file, char __user *buf,
48649@@ -715,6 +787,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
48650 ssize_t copied;
48651 char *page;
48652
48653+#ifdef CONFIG_GRKERNSEC
48654+ if (write)
48655+ return -EPERM;
48656+#endif
48657+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48658+ if (file->f_version != current->exec_id) {
48659+ gr_log_badprocpid("mem");
48660+ return 0;
48661+ }
48662+#endif
48663+
48664 if (!mm)
48665 return 0;
48666
48667@@ -819,6 +902,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
48668 if (!mm)
48669 return 0;
48670
48671+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48672+ if (file->f_version != current->exec_id) {
48673+ gr_log_badprocpid("environ");
48674+ return 0;
48675+ }
48676+#endif
48677+
48678 page = (char *)__get_free_page(GFP_TEMPORARY);
48679 if (!page)
48680 return -ENOMEM;
48681@@ -827,15 +917,17 @@ static ssize_t environ_read(struct file *file, char __user *buf,
48682 if (!atomic_inc_not_zero(&mm->mm_users))
48683 goto free;
48684 while (count > 0) {
48685- int this_len, retval, max_len;
48686+ size_t this_len, max_len;
48687+ int retval;
48688+
48689+ if (src >= (mm->env_end - mm->env_start))
48690+ break;
48691
48692 this_len = mm->env_end - (mm->env_start + src);
48693
48694- if (this_len <= 0)
48695- break;
48696
48697- max_len = (count > PAGE_SIZE) ? PAGE_SIZE : count;
48698- this_len = (this_len > max_len) ? max_len : this_len;
48699+ max_len = min_t(size_t, PAGE_SIZE, count);
48700+ this_len = min(max_len, this_len);
48701
48702 retval = access_remote_vm(mm, (mm->env_start + src),
48703 page, this_len, 0);
48704@@ -1433,7 +1525,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
48705 path_put(&nd->path);
48706
48707 /* Are we allowed to snoop on the tasks file descriptors? */
48708- if (!proc_fd_access_allowed(inode))
48709+ if (!proc_fd_access_allowed(inode, 0))
48710 goto out;
48711
48712 error = PROC_I(inode)->op.proc_get_link(dentry, &nd->path);
48713@@ -1472,8 +1564,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
48714 struct path path;
48715
48716 /* Are we allowed to snoop on the tasks file descriptors? */
48717- if (!proc_fd_access_allowed(inode))
48718- goto out;
48719+ /* logging this is needed for learning on chromium to work properly,
48720+ but we don't want to flood the logs from 'ps' which does a readlink
48721+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
48722+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
48723+ */
48724+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
48725+ if (!proc_fd_access_allowed(inode,0))
48726+ goto out;
48727+ } else {
48728+ if (!proc_fd_access_allowed(inode,1))
48729+ goto out;
48730+ }
48731
48732 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
48733 if (error)
48734@@ -1538,7 +1640,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
48735 rcu_read_lock();
48736 cred = __task_cred(task);
48737 inode->i_uid = cred->euid;
48738+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48739+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48740+#else
48741 inode->i_gid = cred->egid;
48742+#endif
48743 rcu_read_unlock();
48744 }
48745 security_task_to_inode(task, inode);
48746@@ -1574,10 +1680,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
48747 return -ENOENT;
48748 }
48749 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48750+#ifdef CONFIG_GRKERNSEC_PROC_USER
48751+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48752+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48753+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48754+#endif
48755 task_dumpable(task)) {
48756 cred = __task_cred(task);
48757 stat->uid = cred->euid;
48758+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48759+ stat->gid = CONFIG_GRKERNSEC_PROC_GID;
48760+#else
48761 stat->gid = cred->egid;
48762+#endif
48763 }
48764 }
48765 rcu_read_unlock();
48766@@ -1615,11 +1730,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
48767
48768 if (task) {
48769 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48770+#ifdef CONFIG_GRKERNSEC_PROC_USER
48771+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48772+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48773+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48774+#endif
48775 task_dumpable(task)) {
48776 rcu_read_lock();
48777 cred = __task_cred(task);
48778 inode->i_uid = cred->euid;
48779+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48780+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48781+#else
48782 inode->i_gid = cred->egid;
48783+#endif
48784 rcu_read_unlock();
48785 } else {
48786 inode->i_uid = GLOBAL_ROOT_UID;
48787@@ -1737,7 +1861,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
48788 int fd = proc_fd(inode);
48789
48790 if (task) {
48791- files = get_files_struct(task);
48792+ if (!gr_acl_handle_procpidmem(task))
48793+ files = get_files_struct(task);
48794 put_task_struct(task);
48795 }
48796 if (files) {
48797@@ -2336,11 +2461,21 @@ static const struct file_operations proc_map_files_operations = {
48798 */
48799 static int proc_fd_permission(struct inode *inode, int mask)
48800 {
48801+ struct task_struct *task;
48802 int rv = generic_permission(inode, mask);
48803- if (rv == 0)
48804- return 0;
48805+
48806 if (task_pid(current) == proc_pid(inode))
48807 rv = 0;
48808+
48809+ task = get_proc_task(inode);
48810+ if (task == NULL)
48811+ return rv;
48812+
48813+ if (gr_acl_handle_procpidmem(task))
48814+ rv = -EACCES;
48815+
48816+ put_task_struct(task);
48817+
48818 return rv;
48819 }
48820
48821@@ -2450,6 +2585,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
48822 if (!task)
48823 goto out_no_task;
48824
48825+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48826+ goto out;
48827+
48828 /*
48829 * Yes, it does not scale. And it should not. Don't add
48830 * new entries into /proc/<tgid>/ without very good reasons.
48831@@ -2494,6 +2632,9 @@ static int proc_pident_readdir(struct file *filp,
48832 if (!task)
48833 goto out_no_task;
48834
48835+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48836+ goto out;
48837+
48838 ret = 0;
48839 i = filp->f_pos;
48840 switch (i) {
48841@@ -2764,7 +2905,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
48842 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
48843 void *cookie)
48844 {
48845- char *s = nd_get_link(nd);
48846+ const char *s = nd_get_link(nd);
48847 if (!IS_ERR(s))
48848 __putname(s);
48849 }
48850@@ -3033,7 +3174,7 @@ static const struct pid_entry tgid_base_stuff[] = {
48851 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
48852 #endif
48853 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48854-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48855+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48856 INF("syscall", S_IRUGO, proc_pid_syscall),
48857 #endif
48858 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48859@@ -3058,10 +3199,10 @@ static const struct pid_entry tgid_base_stuff[] = {
48860 #ifdef CONFIG_SECURITY
48861 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48862 #endif
48863-#ifdef CONFIG_KALLSYMS
48864+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48865 INF("wchan", S_IRUGO, proc_pid_wchan),
48866 #endif
48867-#ifdef CONFIG_STACKTRACE
48868+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48869 ONE("stack", S_IRUGO, proc_pid_stack),
48870 #endif
48871 #ifdef CONFIG_SCHEDSTATS
48872@@ -3095,6 +3236,9 @@ static const struct pid_entry tgid_base_stuff[] = {
48873 #ifdef CONFIG_HARDWALL
48874 INF("hardwall", S_IRUGO, proc_pid_hardwall),
48875 #endif
48876+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48877+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
48878+#endif
48879 #ifdef CONFIG_USER_NS
48880 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
48881 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
48882@@ -3225,7 +3369,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
48883 if (!inode)
48884 goto out;
48885
48886+#ifdef CONFIG_GRKERNSEC_PROC_USER
48887+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
48888+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48889+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48890+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
48891+#else
48892 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
48893+#endif
48894 inode->i_op = &proc_tgid_base_inode_operations;
48895 inode->i_fop = &proc_tgid_base_operations;
48896 inode->i_flags|=S_IMMUTABLE;
48897@@ -3267,7 +3418,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
48898 if (!task)
48899 goto out;
48900
48901+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48902+ goto out_put_task;
48903+
48904 result = proc_pid_instantiate(dir, dentry, task, NULL);
48905+out_put_task:
48906 put_task_struct(task);
48907 out:
48908 return result;
48909@@ -3330,6 +3485,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
48910 static int fake_filldir(void *buf, const char *name, int namelen,
48911 loff_t offset, u64 ino, unsigned d_type)
48912 {
48913+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
48914+ __buf->error = -EINVAL;
48915 return 0;
48916 }
48917
48918@@ -3396,7 +3553,7 @@ static const struct pid_entry tid_base_stuff[] = {
48919 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
48920 #endif
48921 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48922-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48923+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48924 INF("syscall", S_IRUGO, proc_pid_syscall),
48925 #endif
48926 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48927@@ -3423,10 +3580,10 @@ static const struct pid_entry tid_base_stuff[] = {
48928 #ifdef CONFIG_SECURITY
48929 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48930 #endif
48931-#ifdef CONFIG_KALLSYMS
48932+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48933 INF("wchan", S_IRUGO, proc_pid_wchan),
48934 #endif
48935-#ifdef CONFIG_STACKTRACE
48936+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48937 ONE("stack", S_IRUGO, proc_pid_stack),
48938 #endif
48939 #ifdef CONFIG_SCHEDSTATS
48940diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
48941index 82676e3..5f8518a 100644
48942--- a/fs/proc/cmdline.c
48943+++ b/fs/proc/cmdline.c
48944@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
48945
48946 static int __init proc_cmdline_init(void)
48947 {
48948+#ifdef CONFIG_GRKERNSEC_PROC_ADD
48949+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
48950+#else
48951 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
48952+#endif
48953 return 0;
48954 }
48955 module_init(proc_cmdline_init);
48956diff --git a/fs/proc/devices.c b/fs/proc/devices.c
48957index b143471..bb105e5 100644
48958--- a/fs/proc/devices.c
48959+++ b/fs/proc/devices.c
48960@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
48961
48962 static int __init proc_devices_init(void)
48963 {
48964+#ifdef CONFIG_GRKERNSEC_PROC_ADD
48965+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
48966+#else
48967 proc_create("devices", 0, NULL, &proc_devinfo_operations);
48968+#endif
48969 return 0;
48970 }
48971 module_init(proc_devices_init);
48972diff --git a/fs/proc/inode.c b/fs/proc/inode.c
48973index 7ac817b..abab1a5 100644
48974--- a/fs/proc/inode.c
48975+++ b/fs/proc/inode.c
48976@@ -21,11 +21,17 @@
48977 #include <linux/seq_file.h>
48978 #include <linux/slab.h>
48979 #include <linux/mount.h>
48980+#include <linux/grsecurity.h>
48981
48982 #include <asm/uaccess.h>
48983
48984 #include "internal.h"
48985
48986+#ifdef CONFIG_PROC_SYSCTL
48987+extern const struct inode_operations proc_sys_inode_operations;
48988+extern const struct inode_operations proc_sys_dir_operations;
48989+#endif
48990+
48991 static void proc_evict_inode(struct inode *inode)
48992 {
48993 struct proc_dir_entry *de;
48994@@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
48995 ns_ops = PROC_I(inode)->ns_ops;
48996 if (ns_ops && ns_ops->put)
48997 ns_ops->put(PROC_I(inode)->ns);
48998+
48999+#ifdef CONFIG_PROC_SYSCTL
49000+ if (inode->i_op == &proc_sys_inode_operations ||
49001+ inode->i_op == &proc_sys_dir_operations)
49002+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
49003+#endif
49004+
49005 }
49006
49007 static struct kmem_cache * proc_inode_cachep;
49008@@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
49009 if (de->mode) {
49010 inode->i_mode = de->mode;
49011 inode->i_uid = de->uid;
49012+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49013+ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
49014+#else
49015 inode->i_gid = de->gid;
49016+#endif
49017 }
49018 if (de->size)
49019 inode->i_size = de->size;
49020diff --git a/fs/proc/internal.h b/fs/proc/internal.h
49021index eca4aca..19166b2 100644
49022--- a/fs/proc/internal.h
49023+++ b/fs/proc/internal.h
49024@@ -52,6 +52,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49025 struct pid *pid, struct task_struct *task);
49026 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49027 struct pid *pid, struct task_struct *task);
49028+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49029+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
49030+#endif
49031 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
49032
49033 extern const struct file_operations proc_tid_children_operations;
49034diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
49035index 86c67ee..cdca321 100644
49036--- a/fs/proc/kcore.c
49037+++ b/fs/proc/kcore.c
49038@@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49039 * the addresses in the elf_phdr on our list.
49040 */
49041 start = kc_offset_to_vaddr(*fpos - elf_buflen);
49042- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
49043+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
49044+ if (tsz > buflen)
49045 tsz = buflen;
49046-
49047+
49048 while (buflen) {
49049 struct kcore_list *m;
49050
49051@@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49052 kfree(elf_buf);
49053 } else {
49054 if (kern_addr_valid(start)) {
49055- unsigned long n;
49056+ char *elf_buf;
49057+ mm_segment_t oldfs;
49058
49059- n = copy_to_user(buffer, (char *)start, tsz);
49060- /*
49061- * We cannot distinguish between fault on source
49062- * and fault on destination. When this happens
49063- * we clear too and hope it will trigger the
49064- * EFAULT again.
49065- */
49066- if (n) {
49067- if (clear_user(buffer + tsz - n,
49068- n))
49069+ elf_buf = kmalloc(tsz, GFP_KERNEL);
49070+ if (!elf_buf)
49071+ return -ENOMEM;
49072+ oldfs = get_fs();
49073+ set_fs(KERNEL_DS);
49074+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
49075+ set_fs(oldfs);
49076+ if (copy_to_user(buffer, elf_buf, tsz)) {
49077+ kfree(elf_buf);
49078 return -EFAULT;
49079+ }
49080 }
49081+ set_fs(oldfs);
49082+ kfree(elf_buf);
49083 } else {
49084 if (clear_user(buffer, tsz))
49085 return -EFAULT;
49086@@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49087
49088 static int open_kcore(struct inode *inode, struct file *filp)
49089 {
49090+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
49091+ return -EPERM;
49092+#endif
49093 if (!capable(CAP_SYS_RAWIO))
49094 return -EPERM;
49095 if (kcore_need_update)
49096diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
49097index 80e4645..53e5fcf 100644
49098--- a/fs/proc/meminfo.c
49099+++ b/fs/proc/meminfo.c
49100@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
49101 vmi.used >> 10,
49102 vmi.largest_chunk >> 10
49103 #ifdef CONFIG_MEMORY_FAILURE
49104- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
49105+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
49106 #endif
49107 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
49108 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
49109diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
49110index b1822dd..df622cb 100644
49111--- a/fs/proc/nommu.c
49112+++ b/fs/proc/nommu.c
49113@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
49114 if (len < 1)
49115 len = 1;
49116 seq_printf(m, "%*c", len, ' ');
49117- seq_path(m, &file->f_path, "");
49118+ seq_path(m, &file->f_path, "\n\\");
49119 }
49120
49121 seq_putc(m, '\n');
49122diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
49123index 06e1cc1..177cd98 100644
49124--- a/fs/proc/proc_net.c
49125+++ b/fs/proc/proc_net.c
49126@@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
49127 struct task_struct *task;
49128 struct nsproxy *ns;
49129 struct net *net = NULL;
49130+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49131+ const struct cred *cred = current_cred();
49132+#endif
49133+
49134+#ifdef CONFIG_GRKERNSEC_PROC_USER
49135+ if (cred->fsuid)
49136+ return net;
49137+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49138+ if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
49139+ return net;
49140+#endif
49141
49142 rcu_read_lock();
49143 task = pid_task(proc_pid(dir), PIDTYPE_PID);
49144diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
49145index 3476bca..cb6d86a 100644
49146--- a/fs/proc/proc_sysctl.c
49147+++ b/fs/proc/proc_sysctl.c
49148@@ -12,11 +12,15 @@
49149 #include <linux/module.h>
49150 #include "internal.h"
49151
49152+extern int gr_handle_chroot_sysctl(const int op);
49153+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
49154+ const int op);
49155+
49156 static const struct dentry_operations proc_sys_dentry_operations;
49157 static const struct file_operations proc_sys_file_operations;
49158-static const struct inode_operations proc_sys_inode_operations;
49159+const struct inode_operations proc_sys_inode_operations;
49160 static const struct file_operations proc_sys_dir_file_operations;
49161-static const struct inode_operations proc_sys_dir_operations;
49162+const struct inode_operations proc_sys_dir_operations;
49163
49164 void proc_sys_poll_notify(struct ctl_table_poll *poll)
49165 {
49166@@ -470,8 +474,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
49167
49168 err = NULL;
49169 d_set_d_op(dentry, &proc_sys_dentry_operations);
49170+
49171+ gr_handle_proc_create(dentry, inode);
49172+
49173 d_add(dentry, inode);
49174
49175+ if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt))
49176+ err = ERR_PTR(-ENOENT);
49177+
49178 out:
49179 sysctl_head_finish(head);
49180 return err;
49181@@ -483,18 +493,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49182 struct inode *inode = filp->f_path.dentry->d_inode;
49183 struct ctl_table_header *head = grab_header(inode);
49184 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
49185+ int op = write ? MAY_WRITE : MAY_READ;
49186 ssize_t error;
49187 size_t res;
49188
49189 if (IS_ERR(head))
49190 return PTR_ERR(head);
49191
49192+
49193 /*
49194 * At this point we know that the sysctl was not unregistered
49195 * and won't be until we finish.
49196 */
49197 error = -EPERM;
49198- if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
49199+ if (sysctl_perm(head->root, table, op))
49200 goto out;
49201
49202 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
49203@@ -502,6 +514,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49204 if (!table->proc_handler)
49205 goto out;
49206
49207+#ifdef CONFIG_GRKERNSEC
49208+ error = -EPERM;
49209+ if (gr_handle_chroot_sysctl(op))
49210+ goto out;
49211+ dget(filp->f_path.dentry);
49212+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
49213+ dput(filp->f_path.dentry);
49214+ goto out;
49215+ }
49216+ dput(filp->f_path.dentry);
49217+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
49218+ goto out;
49219+ if (write && !capable(CAP_SYS_ADMIN))
49220+ goto out;
49221+#endif
49222+
49223 /* careful: calling conventions are nasty here */
49224 res = count;
49225 error = table->proc_handler(table, write, buf, &res, ppos);
49226@@ -599,6 +627,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
49227 return -ENOMEM;
49228 } else {
49229 d_set_d_op(child, &proc_sys_dentry_operations);
49230+
49231+ gr_handle_proc_create(child, inode);
49232+
49233 d_add(child, inode);
49234 }
49235 } else {
49236@@ -642,6 +673,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
49237 if ((*pos)++ < file->f_pos)
49238 return 0;
49239
49240+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
49241+ return 0;
49242+
49243 if (unlikely(S_ISLNK(table->mode)))
49244 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
49245 else
49246@@ -759,6 +793,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
49247 if (IS_ERR(head))
49248 return PTR_ERR(head);
49249
49250+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
49251+ return -ENOENT;
49252+
49253 generic_fillattr(inode, stat);
49254 if (table)
49255 stat->mode = (stat->mode & S_IFMT) | table->mode;
49256@@ -781,13 +818,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
49257 .llseek = generic_file_llseek,
49258 };
49259
49260-static const struct inode_operations proc_sys_inode_operations = {
49261+const struct inode_operations proc_sys_inode_operations = {
49262 .permission = proc_sys_permission,
49263 .setattr = proc_sys_setattr,
49264 .getattr = proc_sys_getattr,
49265 };
49266
49267-static const struct inode_operations proc_sys_dir_operations = {
49268+const struct inode_operations proc_sys_dir_operations = {
49269 .lookup = proc_sys_lookup,
49270 .permission = proc_sys_permission,
49271 .setattr = proc_sys_setattr,
49272diff --git a/fs/proc/root.c b/fs/proc/root.c
49273index 7c30fce..b3d3aa2 100644
49274--- a/fs/proc/root.c
49275+++ b/fs/proc/root.c
49276@@ -188,7 +188,15 @@ void __init proc_root_init(void)
49277 #ifdef CONFIG_PROC_DEVICETREE
49278 proc_device_tree_init();
49279 #endif
49280+#ifdef CONFIG_GRKERNSEC_PROC_ADD
49281+#ifdef CONFIG_GRKERNSEC_PROC_USER
49282+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
49283+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49284+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
49285+#endif
49286+#else
49287 proc_mkdir("bus", NULL);
49288+#endif
49289 proc_sys_init();
49290 }
49291
49292diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
49293index 4540b8f..1b9772f 100644
49294--- a/fs/proc/task_mmu.c
49295+++ b/fs/proc/task_mmu.c
49296@@ -11,12 +11,19 @@
49297 #include <linux/rmap.h>
49298 #include <linux/swap.h>
49299 #include <linux/swapops.h>
49300+#include <linux/grsecurity.h>
49301
49302 #include <asm/elf.h>
49303 #include <asm/uaccess.h>
49304 #include <asm/tlbflush.h>
49305 #include "internal.h"
49306
49307+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49308+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49309+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
49310+ _mm->pax_flags & MF_PAX_SEGMEXEC))
49311+#endif
49312+
49313 void task_mem(struct seq_file *m, struct mm_struct *mm)
49314 {
49315 unsigned long data, text, lib, swap;
49316@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49317 "VmExe:\t%8lu kB\n"
49318 "VmLib:\t%8lu kB\n"
49319 "VmPTE:\t%8lu kB\n"
49320- "VmSwap:\t%8lu kB\n",
49321- hiwater_vm << (PAGE_SHIFT-10),
49322+ "VmSwap:\t%8lu kB\n"
49323+
49324+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49325+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
49326+#endif
49327+
49328+ ,hiwater_vm << (PAGE_SHIFT-10),
49329 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
49330 mm->locked_vm << (PAGE_SHIFT-10),
49331 mm->pinned_vm << (PAGE_SHIFT-10),
49332@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49333 data << (PAGE_SHIFT-10),
49334 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
49335 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
49336- swap << (PAGE_SHIFT-10));
49337+ swap << (PAGE_SHIFT-10)
49338+
49339+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49340+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49341+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
49342+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
49343+#else
49344+ , mm->context.user_cs_base
49345+ , mm->context.user_cs_limit
49346+#endif
49347+#endif
49348+
49349+ );
49350 }
49351
49352 unsigned long task_vsize(struct mm_struct *mm)
49353@@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49354 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
49355 }
49356
49357- /* We don't show the stack guard page in /proc/maps */
49358+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49359+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
49360+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
49361+#else
49362 start = vma->vm_start;
49363- if (stack_guard_page_start(vma, start))
49364- start += PAGE_SIZE;
49365 end = vma->vm_end;
49366- if (stack_guard_page_end(vma, end))
49367- end -= PAGE_SIZE;
49368+#endif
49369
49370 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
49371 start,
49372@@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49373 flags & VM_WRITE ? 'w' : '-',
49374 flags & VM_EXEC ? 'x' : '-',
49375 flags & VM_MAYSHARE ? 's' : 'p',
49376+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49377+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
49378+#else
49379 pgoff,
49380+#endif
49381 MAJOR(dev), MINOR(dev), ino, &len);
49382
49383 /*
49384@@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49385 */
49386 if (file) {
49387 pad_len_spaces(m, len);
49388- seq_path(m, &file->f_path, "\n");
49389+ seq_path(m, &file->f_path, "\n\\");
49390 goto done;
49391 }
49392
49393@@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49394 * Thread stack in /proc/PID/task/TID/maps or
49395 * the main process stack.
49396 */
49397- if (!is_pid || (vma->vm_start <= mm->start_stack &&
49398- vma->vm_end >= mm->start_stack)) {
49399+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
49400+ (vma->vm_start <= mm->start_stack &&
49401+ vma->vm_end >= mm->start_stack)) {
49402 name = "[stack]";
49403 } else {
49404 /* Thread stack in /proc/PID/maps */
49405@@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
49406 struct proc_maps_private *priv = m->private;
49407 struct task_struct *task = priv->task;
49408
49409+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49410+ if (current->exec_id != m->exec_id) {
49411+ gr_log_badprocpid("maps");
49412+ return 0;
49413+ }
49414+#endif
49415+
49416 show_map_vma(m, vma, is_pid);
49417
49418 if (m->count < m->size) /* vma is copied successfully */
49419@@ -492,12 +528,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49420 .private = &mss,
49421 };
49422
49423+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49424+ if (current->exec_id != m->exec_id) {
49425+ gr_log_badprocpid("smaps");
49426+ return 0;
49427+ }
49428+#endif
49429 memset(&mss, 0, sizeof mss);
49430- mss.vma = vma;
49431- /* mmap_sem is held in m_start */
49432- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49433- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49434-
49435+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49436+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
49437+#endif
49438+ mss.vma = vma;
49439+ /* mmap_sem is held in m_start */
49440+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49441+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49442+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49443+ }
49444+#endif
49445 show_map_vma(m, vma, is_pid);
49446
49447 seq_printf(m,
49448@@ -515,7 +562,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49449 "KernelPageSize: %8lu kB\n"
49450 "MMUPageSize: %8lu kB\n"
49451 "Locked: %8lu kB\n",
49452+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49453+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
49454+#else
49455 (vma->vm_end - vma->vm_start) >> 10,
49456+#endif
49457 mss.resident >> 10,
49458 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
49459 mss.shared_clean >> 10,
49460@@ -1164,6 +1215,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49461 int n;
49462 char buffer[50];
49463
49464+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49465+ if (current->exec_id != m->exec_id) {
49466+ gr_log_badprocpid("numa_maps");
49467+ return 0;
49468+ }
49469+#endif
49470+
49471 if (!mm)
49472 return 0;
49473
49474@@ -1181,11 +1239,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49475 mpol_to_str(buffer, sizeof(buffer), pol, 0);
49476 mpol_cond_put(pol);
49477
49478+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49479+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
49480+#else
49481 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
49482+#endif
49483
49484 if (file) {
49485 seq_printf(m, " file=");
49486- seq_path(m, &file->f_path, "\n\t= ");
49487+ seq_path(m, &file->f_path, "\n\t\\= ");
49488 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
49489 seq_printf(m, " heap");
49490 } else {
49491diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
49492index 1ccfa53..0848f95 100644
49493--- a/fs/proc/task_nommu.c
49494+++ b/fs/proc/task_nommu.c
49495@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49496 else
49497 bytes += kobjsize(mm);
49498
49499- if (current->fs && current->fs->users > 1)
49500+ if (current->fs && atomic_read(&current->fs->users) > 1)
49501 sbytes += kobjsize(current->fs);
49502 else
49503 bytes += kobjsize(current->fs);
49504@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
49505
49506 if (file) {
49507 pad_len_spaces(m, len);
49508- seq_path(m, &file->f_path, "");
49509+ seq_path(m, &file->f_path, "\n\\");
49510 } else if (mm) {
49511 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
49512
49513diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
49514index d67908b..d13f6a6 100644
49515--- a/fs/quota/netlink.c
49516+++ b/fs/quota/netlink.c
49517@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
49518 void quota_send_warning(short type, unsigned int id, dev_t dev,
49519 const char warntype)
49520 {
49521- static atomic_t seq;
49522+ static atomic_unchecked_t seq;
49523 struct sk_buff *skb;
49524 void *msg_head;
49525 int ret;
49526@@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
49527 "VFS: Not enough memory to send quota warning.\n");
49528 return;
49529 }
49530- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
49531+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
49532 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
49533 if (!msg_head) {
49534 printk(KERN_ERR
49535diff --git a/fs/readdir.c b/fs/readdir.c
49536index 39e3370..20d446d 100644
49537--- a/fs/readdir.c
49538+++ b/fs/readdir.c
49539@@ -17,6 +17,7 @@
49540 #include <linux/security.h>
49541 #include <linux/syscalls.h>
49542 #include <linux/unistd.h>
49543+#include <linux/namei.h>
49544
49545 #include <asm/uaccess.h>
49546
49547@@ -67,6 +68,7 @@ struct old_linux_dirent {
49548
49549 struct readdir_callback {
49550 struct old_linux_dirent __user * dirent;
49551+ struct file * file;
49552 int result;
49553 };
49554
49555@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
49556 buf->result = -EOVERFLOW;
49557 return -EOVERFLOW;
49558 }
49559+
49560+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49561+ return 0;
49562+
49563 buf->result++;
49564 dirent = buf->dirent;
49565 if (!access_ok(VERIFY_WRITE, dirent,
49566@@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
49567
49568 buf.result = 0;
49569 buf.dirent = dirent;
49570+ buf.file = file;
49571
49572 error = vfs_readdir(file, fillonedir, &buf);
49573 if (buf.result)
49574@@ -141,6 +148,7 @@ struct linux_dirent {
49575 struct getdents_callback {
49576 struct linux_dirent __user * current_dir;
49577 struct linux_dirent __user * previous;
49578+ struct file * file;
49579 int count;
49580 int error;
49581 };
49582@@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
49583 buf->error = -EOVERFLOW;
49584 return -EOVERFLOW;
49585 }
49586+
49587+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49588+ return 0;
49589+
49590 dirent = buf->previous;
49591 if (dirent) {
49592 if (__put_user(offset, &dirent->d_off))
49593@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49594 buf.previous = NULL;
49595 buf.count = count;
49596 buf.error = 0;
49597+ buf.file = file;
49598
49599 error = vfs_readdir(file, filldir, &buf);
49600 if (error >= 0)
49601@@ -226,6 +239,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49602 struct getdents_callback64 {
49603 struct linux_dirent64 __user * current_dir;
49604 struct linux_dirent64 __user * previous;
49605+ struct file *file;
49606 int count;
49607 int error;
49608 };
49609@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
49610 buf->error = -EINVAL; /* only used if we fail.. */
49611 if (reclen > buf->count)
49612 return -EINVAL;
49613+
49614+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49615+ return 0;
49616+
49617 dirent = buf->previous;
49618 if (dirent) {
49619 if (__put_user(offset, &dirent->d_off))
49620@@ -287,6 +305,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49621
49622 buf.current_dir = dirent;
49623 buf.previous = NULL;
49624+ buf.file = file;
49625 buf.count = count;
49626 buf.error = 0;
49627
49628@@ -295,7 +314,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49629 error = buf.error;
49630 lastdirent = buf.previous;
49631 if (lastdirent) {
49632- typeof(lastdirent->d_off) d_off = file->f_pos;
49633+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
49634 if (__put_user(d_off, &lastdirent->d_off))
49635 error = -EFAULT;
49636 else
49637diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
49638index 2b7882b..1c5ef48 100644
49639--- a/fs/reiserfs/do_balan.c
49640+++ b/fs/reiserfs/do_balan.c
49641@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
49642 return;
49643 }
49644
49645- atomic_inc(&(fs_generation(tb->tb_sb)));
49646+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
49647 do_balance_starts(tb);
49648
49649 /* balance leaf returns 0 except if combining L R and S into
49650diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
49651index 2c1ade6..8c59d8d 100644
49652--- a/fs/reiserfs/procfs.c
49653+++ b/fs/reiserfs/procfs.c
49654@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
49655 "SMALL_TAILS " : "NO_TAILS ",
49656 replay_only(sb) ? "REPLAY_ONLY " : "",
49657 convert_reiserfs(sb) ? "CONV " : "",
49658- atomic_read(&r->s_generation_counter),
49659+ atomic_read_unchecked(&r->s_generation_counter),
49660 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
49661 SF(s_do_balance), SF(s_unneeded_left_neighbor),
49662 SF(s_good_search_by_key_reada), SF(s_bmaps),
49663diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
49664index 33215f5..c5d427a 100644
49665--- a/fs/reiserfs/reiserfs.h
49666+++ b/fs/reiserfs/reiserfs.h
49667@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
49668 /* Comment? -Hans */
49669 wait_queue_head_t s_wait;
49670 /* To be obsoleted soon by per buffer seals.. -Hans */
49671- atomic_t s_generation_counter; // increased by one every time the
49672+ atomic_unchecked_t s_generation_counter; // increased by one every time the
49673 // tree gets re-balanced
49674 unsigned long s_properties; /* File system properties. Currently holds
49675 on-disk FS format */
49676@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
49677 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
49678
49679 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
49680-#define get_generation(s) atomic_read (&fs_generation(s))
49681+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
49682 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
49683 #define __fs_changed(gen,s) (gen != get_generation (s))
49684 #define fs_changed(gen,s) \
49685diff --git a/fs/select.c b/fs/select.c
49686index db14c78..3aae1bd 100644
49687--- a/fs/select.c
49688+++ b/fs/select.c
49689@@ -20,6 +20,7 @@
49690 #include <linux/export.h>
49691 #include <linux/slab.h>
49692 #include <linux/poll.h>
49693+#include <linux/security.h>
49694 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
49695 #include <linux/file.h>
49696 #include <linux/fdtable.h>
49697@@ -831,6 +832,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
49698 struct poll_list *walk = head;
49699 unsigned long todo = nfds;
49700
49701+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
49702 if (nfds > rlimit(RLIMIT_NOFILE))
49703 return -EINVAL;
49704
49705diff --git a/fs/seq_file.c b/fs/seq_file.c
49706index 0cbd049..64e705c 100644
49707--- a/fs/seq_file.c
49708+++ b/fs/seq_file.c
49709@@ -9,6 +9,7 @@
49710 #include <linux/export.h>
49711 #include <linux/seq_file.h>
49712 #include <linux/slab.h>
49713+#include <linux/sched.h>
49714
49715 #include <asm/uaccess.h>
49716 #include <asm/page.h>
49717@@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
49718 memset(p, 0, sizeof(*p));
49719 mutex_init(&p->lock);
49720 p->op = op;
49721+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49722+ p->exec_id = current->exec_id;
49723+#endif
49724
49725 /*
49726 * Wrappers around seq_open(e.g. swaps_open) need to be
49727@@ -92,7 +96,7 @@ static int traverse(struct seq_file *m, loff_t offset)
49728 return 0;
49729 }
49730 if (!m->buf) {
49731- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
49732+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
49733 if (!m->buf)
49734 return -ENOMEM;
49735 }
49736@@ -132,7 +136,7 @@ static int traverse(struct seq_file *m, loff_t offset)
49737 Eoverflow:
49738 m->op->stop(m, p);
49739 kfree(m->buf);
49740- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
49741+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
49742 return !m->buf ? -ENOMEM : -EAGAIN;
49743 }
49744
49745@@ -187,7 +191,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
49746
49747 /* grab buffer if we didn't have one */
49748 if (!m->buf) {
49749- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
49750+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
49751 if (!m->buf)
49752 goto Enomem;
49753 }
49754@@ -228,7 +232,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
49755 goto Fill;
49756 m->op->stop(m, p);
49757 kfree(m->buf);
49758- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
49759+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
49760 if (!m->buf)
49761 goto Enomem;
49762 m->count = 0;
49763@@ -567,7 +571,7 @@ static void single_stop(struct seq_file *p, void *v)
49764 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
49765 void *data)
49766 {
49767- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
49768+ seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
49769 int res = -ENOMEM;
49770
49771 if (op) {
49772diff --git a/fs/splice.c b/fs/splice.c
49773index 7bf08fa..eb35c2f 100644
49774--- a/fs/splice.c
49775+++ b/fs/splice.c
49776@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49777 pipe_lock(pipe);
49778
49779 for (;;) {
49780- if (!pipe->readers) {
49781+ if (!atomic_read(&pipe->readers)) {
49782 send_sig(SIGPIPE, current, 0);
49783 if (!ret)
49784 ret = -EPIPE;
49785@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49786 do_wakeup = 0;
49787 }
49788
49789- pipe->waiting_writers++;
49790+ atomic_inc(&pipe->waiting_writers);
49791 pipe_wait(pipe);
49792- pipe->waiting_writers--;
49793+ atomic_dec(&pipe->waiting_writers);
49794 }
49795
49796 pipe_unlock(pipe);
49797@@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
49798 old_fs = get_fs();
49799 set_fs(get_ds());
49800 /* The cast to a user pointer is valid due to the set_fs() */
49801- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
49802+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
49803 set_fs(old_fs);
49804
49805 return res;
49806@@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
49807 old_fs = get_fs();
49808 set_fs(get_ds());
49809 /* The cast to a user pointer is valid due to the set_fs() */
49810- res = vfs_write(file, (const char __user *)buf, count, &pos);
49811+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
49812 set_fs(old_fs);
49813
49814 return res;
49815@@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
49816 goto err;
49817
49818 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
49819- vec[i].iov_base = (void __user *) page_address(page);
49820+ vec[i].iov_base = (void __force_user *) page_address(page);
49821 vec[i].iov_len = this_len;
49822 spd.pages[i] = page;
49823 spd.nr_pages++;
49824@@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
49825 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
49826 {
49827 while (!pipe->nrbufs) {
49828- if (!pipe->writers)
49829+ if (!atomic_read(&pipe->writers))
49830 return 0;
49831
49832- if (!pipe->waiting_writers && sd->num_spliced)
49833+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
49834 return 0;
49835
49836 if (sd->flags & SPLICE_F_NONBLOCK)
49837@@ -1187,7 +1187,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
49838 * out of the pipe right after the splice_to_pipe(). So set
49839 * PIPE_READERS appropriately.
49840 */
49841- pipe->readers = 1;
49842+ atomic_set(&pipe->readers, 1);
49843
49844 current->splice_pipe = pipe;
49845 }
49846@@ -1740,9 +1740,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49847 ret = -ERESTARTSYS;
49848 break;
49849 }
49850- if (!pipe->writers)
49851+ if (!atomic_read(&pipe->writers))
49852 break;
49853- if (!pipe->waiting_writers) {
49854+ if (!atomic_read(&pipe->waiting_writers)) {
49855 if (flags & SPLICE_F_NONBLOCK) {
49856 ret = -EAGAIN;
49857 break;
49858@@ -1774,7 +1774,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49859 pipe_lock(pipe);
49860
49861 while (pipe->nrbufs >= pipe->buffers) {
49862- if (!pipe->readers) {
49863+ if (!atomic_read(&pipe->readers)) {
49864 send_sig(SIGPIPE, current, 0);
49865 ret = -EPIPE;
49866 break;
49867@@ -1787,9 +1787,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49868 ret = -ERESTARTSYS;
49869 break;
49870 }
49871- pipe->waiting_writers++;
49872+ atomic_inc(&pipe->waiting_writers);
49873 pipe_wait(pipe);
49874- pipe->waiting_writers--;
49875+ atomic_dec(&pipe->waiting_writers);
49876 }
49877
49878 pipe_unlock(pipe);
49879@@ -1825,14 +1825,14 @@ retry:
49880 pipe_double_lock(ipipe, opipe);
49881
49882 do {
49883- if (!opipe->readers) {
49884+ if (!atomic_read(&opipe->readers)) {
49885 send_sig(SIGPIPE, current, 0);
49886 if (!ret)
49887 ret = -EPIPE;
49888 break;
49889 }
49890
49891- if (!ipipe->nrbufs && !ipipe->writers)
49892+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
49893 break;
49894
49895 /*
49896@@ -1929,7 +1929,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49897 pipe_double_lock(ipipe, opipe);
49898
49899 do {
49900- if (!opipe->readers) {
49901+ if (!atomic_read(&opipe->readers)) {
49902 send_sig(SIGPIPE, current, 0);
49903 if (!ret)
49904 ret = -EPIPE;
49905@@ -1974,7 +1974,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49906 * return EAGAIN if we have the potential of some data in the
49907 * future, otherwise just return 0
49908 */
49909- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
49910+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
49911 ret = -EAGAIN;
49912
49913 pipe_unlock(ipipe);
49914diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
49915index e6bb9b2..d8e3951 100644
49916--- a/fs/sysfs/dir.c
49917+++ b/fs/sysfs/dir.c
49918@@ -678,6 +678,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
49919 struct sysfs_dirent *sd;
49920 int rc;
49921
49922+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
49923+ const char *parent_name = parent_sd->s_name;
49924+
49925+ mode = S_IFDIR | S_IRWXU;
49926+
49927+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
49928+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
49929+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
49930+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
49931+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
49932+#endif
49933+
49934 /* allocate */
49935 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
49936 if (!sd)
49937diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
49938index 00012e3..8392349 100644
49939--- a/fs/sysfs/file.c
49940+++ b/fs/sysfs/file.c
49941@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
49942
49943 struct sysfs_open_dirent {
49944 atomic_t refcnt;
49945- atomic_t event;
49946+ atomic_unchecked_t event;
49947 wait_queue_head_t poll;
49948 struct list_head buffers; /* goes through sysfs_buffer.list */
49949 };
49950@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
49951 if (!sysfs_get_active(attr_sd))
49952 return -ENODEV;
49953
49954- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
49955+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
49956 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
49957
49958 sysfs_put_active(attr_sd);
49959@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
49960 return -ENOMEM;
49961
49962 atomic_set(&new_od->refcnt, 0);
49963- atomic_set(&new_od->event, 1);
49964+ atomic_set_unchecked(&new_od->event, 1);
49965 init_waitqueue_head(&new_od->poll);
49966 INIT_LIST_HEAD(&new_od->buffers);
49967 goto retry;
49968@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
49969
49970 sysfs_put_active(attr_sd);
49971
49972- if (buffer->event != atomic_read(&od->event))
49973+ if (buffer->event != atomic_read_unchecked(&od->event))
49974 goto trigger;
49975
49976 return DEFAULT_POLLMASK;
49977@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
49978
49979 od = sd->s_attr.open;
49980 if (od) {
49981- atomic_inc(&od->event);
49982+ atomic_inc_unchecked(&od->event);
49983 wake_up_interruptible(&od->poll);
49984 }
49985
49986diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
49987index a7ac78f..02158e1 100644
49988--- a/fs/sysfs/symlink.c
49989+++ b/fs/sysfs/symlink.c
49990@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
49991
49992 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
49993 {
49994- char *page = nd_get_link(nd);
49995+ const char *page = nd_get_link(nd);
49996 if (!IS_ERR(page))
49997 free_page((unsigned long)page);
49998 }
49999diff --git a/fs/udf/misc.c b/fs/udf/misc.c
50000index c175b4d..8f36a16 100644
50001--- a/fs/udf/misc.c
50002+++ b/fs/udf/misc.c
50003@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
50004
50005 u8 udf_tag_checksum(const struct tag *t)
50006 {
50007- u8 *data = (u8 *)t;
50008+ const u8 *data = (const u8 *)t;
50009 u8 checksum = 0;
50010 int i;
50011 for (i = 0; i < sizeof(struct tag); ++i)
50012diff --git a/fs/udf/namei.c b/fs/udf/namei.c
50013index 1802417..c31deb3 100644
50014--- a/fs/udf/namei.c
50015+++ b/fs/udf/namei.c
50016@@ -1279,6 +1279,7 @@ static int udf_encode_fh(struct inode *inode, __u32 *fh, int *lenp,
50017 *lenp = 3;
50018 fid->udf.block = location.logicalBlockNum;
50019 fid->udf.partref = location.partitionReferenceNum;
50020+ fid->udf.parent_partref = 0;
50021 fid->udf.generation = inode->i_generation;
50022
50023 if (parent) {
50024diff --git a/fs/utimes.c b/fs/utimes.c
50025index fa4dbe4..e12d1b9 100644
50026--- a/fs/utimes.c
50027+++ b/fs/utimes.c
50028@@ -1,6 +1,7 @@
50029 #include <linux/compiler.h>
50030 #include <linux/file.h>
50031 #include <linux/fs.h>
50032+#include <linux/security.h>
50033 #include <linux/linkage.h>
50034 #include <linux/mount.h>
50035 #include <linux/namei.h>
50036@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
50037 goto mnt_drop_write_and_out;
50038 }
50039 }
50040+
50041+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
50042+ error = -EACCES;
50043+ goto mnt_drop_write_and_out;
50044+ }
50045+
50046 mutex_lock(&inode->i_mutex);
50047 error = notify_change(path->dentry, &newattrs);
50048 mutex_unlock(&inode->i_mutex);
50049diff --git a/fs/xattr.c b/fs/xattr.c
50050index 1d7ac37..23cb9ec 100644
50051--- a/fs/xattr.c
50052+++ b/fs/xattr.c
50053@@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
50054 * Extended attribute SET operations
50055 */
50056 static long
50057-setxattr(struct dentry *d, const char __user *name, const void __user *value,
50058+setxattr(struct path *path, const char __user *name, const void __user *value,
50059 size_t size, int flags)
50060 {
50061 int error;
50062@@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
50063 }
50064 }
50065
50066- error = vfs_setxattr(d, kname, kvalue, size, flags);
50067+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
50068+ error = -EACCES;
50069+ goto out;
50070+ }
50071+
50072+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
50073 out:
50074 if (vvalue)
50075 vfree(vvalue);
50076@@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
50077 return error;
50078 error = mnt_want_write(path.mnt);
50079 if (!error) {
50080- error = setxattr(path.dentry, name, value, size, flags);
50081+ error = setxattr(&path, name, value, size, flags);
50082 mnt_drop_write(path.mnt);
50083 }
50084 path_put(&path);
50085@@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
50086 return error;
50087 error = mnt_want_write(path.mnt);
50088 if (!error) {
50089- error = setxattr(path.dentry, name, value, size, flags);
50090+ error = setxattr(&path, name, value, size, flags);
50091 mnt_drop_write(path.mnt);
50092 }
50093 path_put(&path);
50094@@ -401,17 +406,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
50095 {
50096 int fput_needed;
50097 struct file *f;
50098- struct dentry *dentry;
50099 int error = -EBADF;
50100
50101 f = fget_light(fd, &fput_needed);
50102 if (!f)
50103 return error;
50104- dentry = f->f_path.dentry;
50105- audit_inode(NULL, dentry);
50106+ audit_inode(NULL, f->f_path.dentry);
50107 error = mnt_want_write_file(f);
50108 if (!error) {
50109- error = setxattr(dentry, name, value, size, flags);
50110+ error = setxattr(&f->f_path, name, value, size, flags);
50111 mnt_drop_write_file(f);
50112 }
50113 fput_light(f, fput_needed);
50114diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
50115index 69d06b0..c0996e5 100644
50116--- a/fs/xattr_acl.c
50117+++ b/fs/xattr_acl.c
50118@@ -17,8 +17,8 @@
50119 struct posix_acl *
50120 posix_acl_from_xattr(const void *value, size_t size)
50121 {
50122- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
50123- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
50124+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
50125+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
50126 int count;
50127 struct posix_acl *acl;
50128 struct posix_acl_entry *acl_e;
50129diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
50130index 58b815e..595ddee 100644
50131--- a/fs/xfs/xfs_bmap.c
50132+++ b/fs/xfs/xfs_bmap.c
50133@@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
50134 int nmap,
50135 int ret_nmap);
50136 #else
50137-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
50138+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
50139 #endif /* DEBUG */
50140
50141 STATIC int
50142diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
50143index 19bf0c5..9f26b02 100644
50144--- a/fs/xfs/xfs_dir2_sf.c
50145+++ b/fs/xfs/xfs_dir2_sf.c
50146@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
50147 }
50148
50149 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
50150- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50151+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
50152+ char name[sfep->namelen];
50153+ memcpy(name, sfep->name, sfep->namelen);
50154+ if (filldir(dirent, name, sfep->namelen,
50155+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
50156+ *offset = off & 0x7fffffff;
50157+ return 0;
50158+ }
50159+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50160 off & 0x7fffffff, ino, DT_UNKNOWN)) {
50161 *offset = off & 0x7fffffff;
50162 return 0;
50163diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c
50164index f9c3fe3..69cf4fc 100644
50165--- a/fs/xfs/xfs_discard.c
50166+++ b/fs/xfs/xfs_discard.c
50167@@ -179,12 +179,14 @@ xfs_ioc_trim(
50168 * used by the fstrim application. In the end it really doesn't
50169 * matter as trimming blocks is an advisory interface.
50170 */
50171+ if (range.start >= XFS_FSB_TO_B(mp, mp->m_sb.sb_dblocks) ||
50172+ range.minlen > XFS_FSB_TO_B(mp, XFS_ALLOC_AG_MAX_USABLE(mp)))
50173+ return -XFS_ERROR(EINVAL);
50174+
50175 start = BTOBB(range.start);
50176 end = start + BTOBBT(range.len) - 1;
50177 minlen = BTOBB(max_t(u64, granularity, range.minlen));
50178
50179- if (XFS_BB_TO_FSB(mp, start) >= mp->m_sb.sb_dblocks)
50180- return -XFS_ERROR(EINVAL);
50181 if (end > XFS_FSB_TO_BB(mp, mp->m_sb.sb_dblocks) - 1)
50182 end = XFS_FSB_TO_BB(mp, mp->m_sb.sb_dblocks)- 1;
50183
50184diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
50185index 3a05a41..320bec6 100644
50186--- a/fs/xfs/xfs_ioctl.c
50187+++ b/fs/xfs/xfs_ioctl.c
50188@@ -126,7 +126,7 @@ xfs_find_handle(
50189 }
50190
50191 error = -EFAULT;
50192- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
50193+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
50194 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
50195 goto out_put;
50196
50197diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
50198index 1a25fd8..e935581 100644
50199--- a/fs/xfs/xfs_iops.c
50200+++ b/fs/xfs/xfs_iops.c
50201@@ -394,7 +394,7 @@ xfs_vn_put_link(
50202 struct nameidata *nd,
50203 void *p)
50204 {
50205- char *s = nd_get_link(nd);
50206+ const char *s = nd_get_link(nd);
50207
50208 if (!IS_ERR(s))
50209 kfree(s);
50210diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
50211index 92d4331..ca28a4b 100644
50212--- a/fs/xfs/xfs_rtalloc.c
50213+++ b/fs/xfs/xfs_rtalloc.c
50214@@ -857,7 +857,7 @@ xfs_rtbuf_get(
50215 xfs_buf_t *bp; /* block buffer, result */
50216 xfs_inode_t *ip; /* bitmap or summary inode */
50217 xfs_bmbt_irec_t map;
50218- int nmap;
50219+ int nmap = 1;
50220 int error; /* error value */
50221
50222 ip = issum ? mp->m_rsumip : mp->m_rbmip;
50223diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
50224new file mode 100644
50225index 0000000..4d533f1
50226--- /dev/null
50227+++ b/grsecurity/Kconfig
50228@@ -0,0 +1,941 @@
50229+#
50230+# grecurity configuration
50231+#
50232+menu "Memory Protections"
50233+depends on GRKERNSEC
50234+
50235+config GRKERNSEC_KMEM
50236+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
50237+ default y if GRKERNSEC_CONFIG_AUTO
50238+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
50239+ help
50240+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
50241+ be written to or read from to modify or leak the contents of the running
50242+ kernel. /dev/port will also not be allowed to be opened. If you have module
50243+ support disabled, enabling this will close up four ways that are
50244+ currently used to insert malicious code into the running kernel.
50245+ Even with all these features enabled, we still highly recommend that
50246+ you use the RBAC system, as it is still possible for an attacker to
50247+ modify the running kernel through privileged I/O granted by ioperm/iopl.
50248+ If you are not using XFree86, you may be able to stop this additional
50249+ case by enabling the 'Disable privileged I/O' option. Though nothing
50250+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
50251+ but only to video memory, which is the only writing we allow in this
50252+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
50253+ not be allowed to mprotect it with PROT_WRITE later.
50254+ It is highly recommended that you say Y here if you meet all the
50255+ conditions above.
50256+
50257+config GRKERNSEC_VM86
50258+ bool "Restrict VM86 mode"
50259+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50260+ depends on X86_32
50261+
50262+ help
50263+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
50264+ make use of a special execution mode on 32bit x86 processors called
50265+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
50266+ video cards and will still work with this option enabled. The purpose
50267+ of the option is to prevent exploitation of emulation errors in
50268+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
50269+ Nearly all users should be able to enable this option.
50270+
50271+config GRKERNSEC_IO
50272+ bool "Disable privileged I/O"
50273+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50274+ depends on X86
50275+ select RTC_CLASS
50276+ select RTC_INTF_DEV
50277+ select RTC_DRV_CMOS
50278+
50279+ help
50280+ If you say Y here, all ioperm and iopl calls will return an error.
50281+ Ioperm and iopl can be used to modify the running kernel.
50282+ Unfortunately, some programs need this access to operate properly,
50283+ the most notable of which are XFree86 and hwclock. hwclock can be
50284+ remedied by having RTC support in the kernel, so real-time
50285+ clock support is enabled if this option is enabled, to ensure
50286+ that hwclock operates correctly. XFree86 still will not
50287+ operate correctly with this option enabled, so DO NOT CHOOSE Y
50288+ IF YOU USE XFree86. If you use XFree86 and you still want to
50289+ protect your kernel against modification, use the RBAC system.
50290+
50291+config GRKERNSEC_PROC_MEMMAP
50292+ bool "Harden ASLR against information leaks and entropy reduction"
50293+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
50294+ depends on PAX_NOEXEC || PAX_ASLR
50295+ help
50296+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
50297+ give no information about the addresses of its mappings if
50298+ PaX features that rely on random addresses are enabled on the task.
50299+ In addition to sanitizing this information and disabling other
50300+ dangerous sources of information, this option causes reads of sensitive
50301+ /proc/<pid> entries where the file descriptor was opened in a different
50302+ task than the one performing the read. Such attempts are logged.
50303+ This option also limits argv/env strings for suid/sgid binaries
50304+ to 512KB to prevent a complete exhaustion of the stack entropy provided
50305+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
50306+ binaries to prevent alternative mmap layouts from being abused.
50307+
50308+ If you use PaX it is essential that you say Y here as it closes up
50309+ several holes that make full ASLR useless locally.
50310+
50311+config GRKERNSEC_BRUTE
50312+ bool "Deter exploit bruteforcing"
50313+ default y if GRKERNSEC_CONFIG_AUTO
50314+ help
50315+ If you say Y here, attempts to bruteforce exploits against forking
50316+ daemons such as apache or sshd, as well as against suid/sgid binaries
50317+ will be deterred. When a child of a forking daemon is killed by PaX
50318+ or crashes due to an illegal instruction or other suspicious signal,
50319+ the parent process will be delayed 30 seconds upon every subsequent
50320+ fork until the administrator is able to assess the situation and
50321+ restart the daemon.
50322+ In the suid/sgid case, the attempt is logged, the user has all their
50323+ processes terminated, and they are prevented from executing any further
50324+ processes for 15 minutes.
50325+ It is recommended that you also enable signal logging in the auditing
50326+ section so that logs are generated when a process triggers a suspicious
50327+ signal.
50328+ If the sysctl option is enabled, a sysctl option with name
50329+ "deter_bruteforce" is created.
50330+
50331+
50332+config GRKERNSEC_MODHARDEN
50333+ bool "Harden module auto-loading"
50334+ default y if GRKERNSEC_CONFIG_AUTO
50335+ depends on MODULES
50336+ help
50337+ If you say Y here, module auto-loading in response to use of some
50338+ feature implemented by an unloaded module will be restricted to
50339+ root users. Enabling this option helps defend against attacks
50340+ by unprivileged users who abuse the auto-loading behavior to
50341+ cause a vulnerable module to load that is then exploited.
50342+
50343+ If this option prevents a legitimate use of auto-loading for a
50344+ non-root user, the administrator can execute modprobe manually
50345+ with the exact name of the module mentioned in the alert log.
50346+ Alternatively, the administrator can add the module to the list
50347+ of modules loaded at boot by modifying init scripts.
50348+
50349+ Modification of init scripts will most likely be needed on
50350+ Ubuntu servers with encrypted home directory support enabled,
50351+ as the first non-root user logging in will cause the ecb(aes),
50352+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
50353+
50354+config GRKERNSEC_HIDESYM
50355+ bool "Hide kernel symbols"
50356+ default y if GRKERNSEC_CONFIG_AUTO
50357+ select PAX_USERCOPY_SLABS
50358+ help
50359+ If you say Y here, getting information on loaded modules, and
50360+ displaying all kernel symbols through a syscall will be restricted
50361+ to users with CAP_SYS_MODULE. For software compatibility reasons,
50362+ /proc/kallsyms will be restricted to the root user. The RBAC
50363+ system can hide that entry even from root.
50364+
50365+ This option also prevents leaking of kernel addresses through
50366+ several /proc entries.
50367+
50368+ Note that this option is only effective provided the following
50369+ conditions are met:
50370+ 1) The kernel using grsecurity is not precompiled by some distribution
50371+ 2) You have also enabled GRKERNSEC_DMESG
50372+ 3) You are using the RBAC system and hiding other files such as your
50373+ kernel image and System.map. Alternatively, enabling this option
50374+ causes the permissions on /boot, /lib/modules, and the kernel
50375+ source directory to change at compile time to prevent
50376+ reading by non-root users.
50377+ If the above conditions are met, this option will aid in providing a
50378+ useful protection against local kernel exploitation of overflows
50379+ and arbitrary read/write vulnerabilities.
50380+
50381+config GRKERNSEC_KERN_LOCKOUT
50382+ bool "Active kernel exploit response"
50383+ default y if GRKERNSEC_CONFIG_AUTO
50384+ depends on X86 || ARM || PPC || SPARC
50385+ help
50386+ If you say Y here, when a PaX alert is triggered due to suspicious
50387+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
50388+ or an OOPS occurs due to bad memory accesses, instead of just
50389+ terminating the offending process (and potentially allowing
50390+ a subsequent exploit from the same user), we will take one of two
50391+ actions:
50392+ If the user was root, we will panic the system
50393+ If the user was non-root, we will log the attempt, terminate
50394+ all processes owned by the user, then prevent them from creating
50395+ any new processes until the system is restarted
50396+ This deters repeated kernel exploitation/bruteforcing attempts
50397+ and is useful for later forensics.
50398+
50399+endmenu
50400+menu "Role Based Access Control Options"
50401+depends on GRKERNSEC
50402+
50403+config GRKERNSEC_RBAC_DEBUG
50404+ bool
50405+
50406+config GRKERNSEC_NO_RBAC
50407+ bool "Disable RBAC system"
50408+ help
50409+ If you say Y here, the /dev/grsec device will be removed from the kernel,
50410+ preventing the RBAC system from being enabled. You should only say Y
50411+ here if you have no intention of using the RBAC system, so as to prevent
50412+ an attacker with root access from misusing the RBAC system to hide files
50413+ and processes when loadable module support and /dev/[k]mem have been
50414+ locked down.
50415+
50416+config GRKERNSEC_ACL_HIDEKERN
50417+ bool "Hide kernel processes"
50418+ help
50419+ If you say Y here, all kernel threads will be hidden to all
50420+ processes but those whose subject has the "view hidden processes"
50421+ flag.
50422+
50423+config GRKERNSEC_ACL_MAXTRIES
50424+ int "Maximum tries before password lockout"
50425+ default 3
50426+ help
50427+ This option enforces the maximum number of times a user can attempt
50428+ to authorize themselves with the grsecurity RBAC system before being
50429+ denied the ability to attempt authorization again for a specified time.
50430+ The lower the number, the harder it will be to brute-force a password.
50431+
50432+config GRKERNSEC_ACL_TIMEOUT
50433+ int "Time to wait after max password tries, in seconds"
50434+ default 30
50435+ help
50436+ This option specifies the time the user must wait after attempting to
50437+ authorize to the RBAC system with the maximum number of invalid
50438+ passwords. The higher the number, the harder it will be to brute-force
50439+ a password.
50440+
50441+endmenu
50442+menu "Filesystem Protections"
50443+depends on GRKERNSEC
50444+
50445+config GRKERNSEC_PROC
50446+ bool "Proc restrictions"
50447+ default y if GRKERNSEC_CONFIG_AUTO
50448+ help
50449+ If you say Y here, the permissions of the /proc filesystem
50450+ will be altered to enhance system security and privacy. You MUST
50451+ choose either a user only restriction or a user and group restriction.
50452+ Depending upon the option you choose, you can either restrict users to
50453+ see only the processes they themselves run, or choose a group that can
50454+ view all processes and files normally restricted to root if you choose
50455+ the "restrict to user only" option. NOTE: If you're running identd or
50456+ ntpd as a non-root user, you will have to run it as the group you
50457+ specify here.
50458+
50459+config GRKERNSEC_PROC_USER
50460+ bool "Restrict /proc to user only"
50461+ depends on GRKERNSEC_PROC
50462+ help
50463+ If you say Y here, non-root users will only be able to view their own
50464+ processes, and restricts them from viewing network-related information,
50465+ and viewing kernel symbol and module information.
50466+
50467+config GRKERNSEC_PROC_USERGROUP
50468+ bool "Allow special group"
50469+ default y if GRKERNSEC_CONFIG_AUTO
50470+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
50471+ help
50472+ If you say Y here, you will be able to select a group that will be
50473+ able to view all processes and network-related information. If you've
50474+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
50475+ remain hidden. This option is useful if you want to run identd as
50476+ a non-root user.
50477+
50478+config GRKERNSEC_PROC_GID
50479+ int "GID for special group"
50480+ depends on GRKERNSEC_PROC_USERGROUP
50481+ default 1001
50482+
50483+config GRKERNSEC_PROC_ADD
50484+ bool "Additional restrictions"
50485+ default y if GRKERNSEC_CONFIG_AUTO
50486+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
50487+ help
50488+ If you say Y here, additional restrictions will be placed on
50489+ /proc that keep normal users from viewing device information and
50490+ slabinfo information that could be useful for exploits.
50491+
50492+config GRKERNSEC_LINK
50493+ bool "Linking restrictions"
50494+ default y if GRKERNSEC_CONFIG_AUTO
50495+ help
50496+ If you say Y here, /tmp race exploits will be prevented, since users
50497+ will no longer be able to follow symlinks owned by other users in
50498+ world-writable +t directories (e.g. /tmp), unless the owner of the
50499+ symlink is the owner of the directory. users will also not be
50500+ able to hardlink to files they do not own. If the sysctl option is
50501+ enabled, a sysctl option with name "linking_restrictions" is created.
50502+
50503+config GRKERNSEC_SYMLINKOWN
50504+ bool "Kernel-enforced SymlinksIfOwnerMatch"
50505+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
50506+ help
50507+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
50508+ that prevents it from being used as a security feature. As Apache
50509+ verifies the symlink by performing a stat() against the target of
50510+ the symlink before it is followed, an attacker can setup a symlink
50511+ to point to a same-owned file, then replace the symlink with one
50512+ that targets another user's file just after Apache "validates" the
50513+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
50514+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
50515+ will be in place for the group you specify. If the sysctl option
50516+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
50517+ created.
50518+
50519+config GRKERNSEC_SYMLINKOWN_GID
50520+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
50521+ depends on GRKERNSEC_SYMLINKOWN
50522+ default 1006
50523+ help
50524+ Setting this GID determines what group kernel-enforced
50525+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
50526+ is enabled, a sysctl option with name "symlinkown_gid" is created.
50527+
50528+config GRKERNSEC_FIFO
50529+ bool "FIFO restrictions"
50530+ default y if GRKERNSEC_CONFIG_AUTO
50531+ help
50532+ If you say Y here, users will not be able to write to FIFOs they don't
50533+ own in world-writable +t directories (e.g. /tmp), unless the owner of
50534+ the FIFO is the same owner of the directory it's held in. If the sysctl
50535+ option is enabled, a sysctl option with name "fifo_restrictions" is
50536+ created.
50537+
50538+config GRKERNSEC_SYSFS_RESTRICT
50539+ bool "Sysfs/debugfs restriction"
50540+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50541+ depends on SYSFS
50542+ help
50543+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
50544+ any filesystem normally mounted under it (e.g. debugfs) will be
50545+ mostly accessible only by root. These filesystems generally provide access
50546+ to hardware and debug information that isn't appropriate for unprivileged
50547+ users of the system. Sysfs and debugfs have also become a large source
50548+ of new vulnerabilities, ranging from infoleaks to local compromise.
50549+ There has been very little oversight with an eye toward security involved
50550+ in adding new exporters of information to these filesystems, so their
50551+ use is discouraged.
50552+ For reasons of compatibility, a few directories have been whitelisted
50553+ for access by non-root users:
50554+ /sys/fs/selinux
50555+ /sys/fs/fuse
50556+ /sys/devices/system/cpu
50557+
50558+config GRKERNSEC_ROFS
50559+ bool "Runtime read-only mount protection"
50560+ help
50561+ If you say Y here, a sysctl option with name "romount_protect" will
50562+ be created. By setting this option to 1 at runtime, filesystems
50563+ will be protected in the following ways:
50564+ * No new writable mounts will be allowed
50565+ * Existing read-only mounts won't be able to be remounted read/write
50566+ * Write operations will be denied on all block devices
50567+ This option acts independently of grsec_lock: once it is set to 1,
50568+ it cannot be turned off. Therefore, please be mindful of the resulting
50569+ behavior if this option is enabled in an init script on a read-only
50570+ filesystem. This feature is mainly intended for secure embedded systems.
50571+
50572+config GRKERNSEC_CHROOT
50573+ bool "Chroot jail restrictions"
50574+ default y if GRKERNSEC_CONFIG_AUTO
50575+ help
50576+ If you say Y here, you will be able to choose several options that will
50577+ make breaking out of a chrooted jail much more difficult. If you
50578+ encounter no software incompatibilities with the following options, it
50579+ is recommended that you enable each one.
50580+
50581+config GRKERNSEC_CHROOT_MOUNT
50582+ bool "Deny mounts"
50583+ default y if GRKERNSEC_CONFIG_AUTO
50584+ depends on GRKERNSEC_CHROOT
50585+ help
50586+ If you say Y here, processes inside a chroot will not be able to
50587+ mount or remount filesystems. If the sysctl option is enabled, a
50588+ sysctl option with name "chroot_deny_mount" is created.
50589+
50590+config GRKERNSEC_CHROOT_DOUBLE
50591+ bool "Deny double-chroots"
50592+ default y if GRKERNSEC_CONFIG_AUTO
50593+ depends on GRKERNSEC_CHROOT
50594+ help
50595+ If you say Y here, processes inside a chroot will not be able to chroot
50596+ again outside the chroot. This is a widely used method of breaking
50597+ out of a chroot jail and should not be allowed. If the sysctl
50598+ option is enabled, a sysctl option with name
50599+ "chroot_deny_chroot" is created.
50600+
50601+config GRKERNSEC_CHROOT_PIVOT
50602+ bool "Deny pivot_root in chroot"
50603+ default y if GRKERNSEC_CONFIG_AUTO
50604+ depends on GRKERNSEC_CHROOT
50605+ help
50606+ If you say Y here, processes inside a chroot will not be able to use
50607+ a function called pivot_root() that was introduced in Linux 2.3.41. It
50608+ works similar to chroot in that it changes the root filesystem. This
50609+ function could be misused in a chrooted process to attempt to break out
50610+ of the chroot, and therefore should not be allowed. If the sysctl
50611+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
50612+ created.
50613+
50614+config GRKERNSEC_CHROOT_CHDIR
50615+ bool "Enforce chdir(\"/\") on all chroots"
50616+ default y if GRKERNSEC_CONFIG_AUTO
50617+ depends on GRKERNSEC_CHROOT
50618+ help
50619+ If you say Y here, the current working directory of all newly-chrooted
50620+ applications will be set to the the root directory of the chroot.
50621+ The man page on chroot(2) states:
50622+ Note that this call does not change the current working
50623+ directory, so that `.' can be outside the tree rooted at
50624+ `/'. In particular, the super-user can escape from a
50625+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
50626+
50627+ It is recommended that you say Y here, since it's not known to break
50628+ any software. If the sysctl option is enabled, a sysctl option with
50629+ name "chroot_enforce_chdir" is created.
50630+
50631+config GRKERNSEC_CHROOT_CHMOD
50632+ bool "Deny (f)chmod +s"
50633+ default y if GRKERNSEC_CONFIG_AUTO
50634+ depends on GRKERNSEC_CHROOT
50635+ help
50636+ If you say Y here, processes inside a chroot will not be able to chmod
50637+ or fchmod files to make them have suid or sgid bits. This protects
50638+ against another published method of breaking a chroot. If the sysctl
50639+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
50640+ created.
50641+
50642+config GRKERNSEC_CHROOT_FCHDIR
50643+ bool "Deny fchdir out of chroot"
50644+ default y if GRKERNSEC_CONFIG_AUTO
50645+ depends on GRKERNSEC_CHROOT
50646+ help
50647+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
50648+ to a file descriptor of the chrooting process that points to a directory
50649+ outside the filesystem will be stopped. If the sysctl option
50650+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
50651+
50652+config GRKERNSEC_CHROOT_MKNOD
50653+ bool "Deny mknod"
50654+ default y if GRKERNSEC_CONFIG_AUTO
50655+ depends on GRKERNSEC_CHROOT
50656+ help
50657+ If you say Y here, processes inside a chroot will not be allowed to
50658+ mknod. The problem with using mknod inside a chroot is that it
50659+ would allow an attacker to create a device entry that is the same
50660+ as one on the physical root of your system, which could range from
50661+ anything from the console device to a device for your harddrive (which
50662+ they could then use to wipe the drive or steal data). It is recommended
50663+ that you say Y here, unless you run into software incompatibilities.
50664+ If the sysctl option is enabled, a sysctl option with name
50665+ "chroot_deny_mknod" is created.
50666+
50667+config GRKERNSEC_CHROOT_SHMAT
50668+ bool "Deny shmat() out of chroot"
50669+ default y if GRKERNSEC_CONFIG_AUTO
50670+ depends on GRKERNSEC_CHROOT
50671+ help
50672+ If you say Y here, processes inside a chroot will not be able to attach
50673+ to shared memory segments that were created outside of the chroot jail.
50674+ It is recommended that you say Y here. If the sysctl option is enabled,
50675+ a sysctl option with name "chroot_deny_shmat" is created.
50676+
50677+config GRKERNSEC_CHROOT_UNIX
50678+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
50679+ default y if GRKERNSEC_CONFIG_AUTO
50680+ depends on GRKERNSEC_CHROOT
50681+ help
50682+ If you say Y here, processes inside a chroot will not be able to
50683+ connect to abstract (meaning not belonging to a filesystem) Unix
50684+ domain sockets that were bound outside of a chroot. It is recommended
50685+ that you say Y here. If the sysctl option is enabled, a sysctl option
50686+ with name "chroot_deny_unix" is created.
50687+
50688+config GRKERNSEC_CHROOT_FINDTASK
50689+ bool "Protect outside processes"
50690+ default y if GRKERNSEC_CONFIG_AUTO
50691+ depends on GRKERNSEC_CHROOT
50692+ help
50693+ If you say Y here, processes inside a chroot will not be able to
50694+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
50695+ getsid, or view any process outside of the chroot. If the sysctl
50696+ option is enabled, a sysctl option with name "chroot_findtask" is
50697+ created.
50698+
50699+config GRKERNSEC_CHROOT_NICE
50700+ bool "Restrict priority changes"
50701+ default y if GRKERNSEC_CONFIG_AUTO
50702+ depends on GRKERNSEC_CHROOT
50703+ help
50704+ If you say Y here, processes inside a chroot will not be able to raise
50705+ the priority of processes in the chroot, or alter the priority of
50706+ processes outside the chroot. This provides more security than simply
50707+ removing CAP_SYS_NICE from the process' capability set. If the
50708+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
50709+ is created.
50710+
50711+config GRKERNSEC_CHROOT_SYSCTL
50712+ bool "Deny sysctl writes"
50713+ default y if GRKERNSEC_CONFIG_AUTO
50714+ depends on GRKERNSEC_CHROOT
50715+ help
50716+ If you say Y here, an attacker in a chroot will not be able to
50717+ write to sysctl entries, either by sysctl(2) or through a /proc
50718+ interface. It is strongly recommended that you say Y here. If the
50719+ sysctl option is enabled, a sysctl option with name
50720+ "chroot_deny_sysctl" is created.
50721+
50722+config GRKERNSEC_CHROOT_CAPS
50723+ bool "Capability restrictions"
50724+ default y if GRKERNSEC_CONFIG_AUTO
50725+ depends on GRKERNSEC_CHROOT
50726+ help
50727+ If you say Y here, the capabilities on all processes within a
50728+ chroot jail will be lowered to stop module insertion, raw i/o,
50729+ system and net admin tasks, rebooting the system, modifying immutable
50730+ files, modifying IPC owned by another, and changing the system time.
50731+ This is left an option because it can break some apps. Disable this
50732+ if your chrooted apps are having problems performing those kinds of
50733+ tasks. If the sysctl option is enabled, a sysctl option with
50734+ name "chroot_caps" is created.
50735+
50736+endmenu
50737+menu "Kernel Auditing"
50738+depends on GRKERNSEC
50739+
50740+config GRKERNSEC_AUDIT_GROUP
50741+ bool "Single group for auditing"
50742+ help
50743+ If you say Y here, the exec, chdir, and (un)mount logging features
50744+ will only operate on a group you specify. This option is recommended
50745+ if you only want to watch certain users instead of having a large
50746+ amount of logs from the entire system. If the sysctl option is enabled,
50747+ a sysctl option with name "audit_group" is created.
50748+
50749+config GRKERNSEC_AUDIT_GID
50750+ int "GID for auditing"
50751+ depends on GRKERNSEC_AUDIT_GROUP
50752+ default 1007
50753+
50754+config GRKERNSEC_EXECLOG
50755+ bool "Exec logging"
50756+ help
50757+ If you say Y here, all execve() calls will be logged (since the
50758+ other exec*() calls are frontends to execve(), all execution
50759+ will be logged). Useful for shell-servers that like to keep track
50760+ of their users. If the sysctl option is enabled, a sysctl option with
50761+ name "exec_logging" is created.
50762+ WARNING: This option when enabled will produce a LOT of logs, especially
50763+ on an active system.
50764+
50765+config GRKERNSEC_RESLOG
50766+ bool "Resource logging"
50767+ default y if GRKERNSEC_CONFIG_AUTO
50768+ help
50769+ If you say Y here, all attempts to overstep resource limits will
50770+ be logged with the resource name, the requested size, and the current
50771+ limit. It is highly recommended that you say Y here. If the sysctl
50772+ option is enabled, a sysctl option with name "resource_logging" is
50773+ created. If the RBAC system is enabled, the sysctl value is ignored.
50774+
50775+config GRKERNSEC_CHROOT_EXECLOG
50776+ bool "Log execs within chroot"
50777+ help
50778+ If you say Y here, all executions inside a chroot jail will be logged
50779+ to syslog. This can cause a large amount of logs if certain
50780+ applications (eg. djb's daemontools) are installed on the system, and
50781+ is therefore left as an option. If the sysctl option is enabled, a
50782+ sysctl option with name "chroot_execlog" is created.
50783+
50784+config GRKERNSEC_AUDIT_PTRACE
50785+ bool "Ptrace logging"
50786+ help
50787+ If you say Y here, all attempts to attach to a process via ptrace
50788+ will be logged. If the sysctl option is enabled, a sysctl option
50789+ with name "audit_ptrace" is created.
50790+
50791+config GRKERNSEC_AUDIT_CHDIR
50792+ bool "Chdir logging"
50793+ help
50794+ If you say Y here, all chdir() calls will be logged. If the sysctl
50795+ option is enabled, a sysctl option with name "audit_chdir" is created.
50796+
50797+config GRKERNSEC_AUDIT_MOUNT
50798+ bool "(Un)Mount logging"
50799+ help
50800+ If you say Y here, all mounts and unmounts will be logged. If the
50801+ sysctl option is enabled, a sysctl option with name "audit_mount" is
50802+ created.
50803+
50804+config GRKERNSEC_SIGNAL
50805+ bool "Signal logging"
50806+ default y if GRKERNSEC_CONFIG_AUTO
50807+ help
50808+ If you say Y here, certain important signals will be logged, such as
50809+ SIGSEGV, which will as a result inform you of when a error in a program
50810+ occurred, which in some cases could mean a possible exploit attempt.
50811+ If the sysctl option is enabled, a sysctl option with name
50812+ "signal_logging" is created.
50813+
50814+config GRKERNSEC_FORKFAIL
50815+ bool "Fork failure logging"
50816+ help
50817+ If you say Y here, all failed fork() attempts will be logged.
50818+ This could suggest a fork bomb, or someone attempting to overstep
50819+ their process limit. If the sysctl option is enabled, a sysctl option
50820+ with name "forkfail_logging" is created.
50821+
50822+config GRKERNSEC_TIME
50823+ bool "Time change logging"
50824+ default y if GRKERNSEC_CONFIG_AUTO
50825+ help
50826+ If you say Y here, any changes of the system clock will be logged.
50827+ If the sysctl option is enabled, a sysctl option with name
50828+ "timechange_logging" is created.
50829+
50830+config GRKERNSEC_PROC_IPADDR
50831+ bool "/proc/<pid>/ipaddr support"
50832+ default y if GRKERNSEC_CONFIG_AUTO
50833+ help
50834+ If you say Y here, a new entry will be added to each /proc/<pid>
50835+ directory that contains the IP address of the person using the task.
50836+ The IP is carried across local TCP and AF_UNIX stream sockets.
50837+ This information can be useful for IDS/IPSes to perform remote response
50838+ to a local attack. The entry is readable by only the owner of the
50839+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
50840+ the RBAC system), and thus does not create privacy concerns.
50841+
50842+config GRKERNSEC_RWXMAP_LOG
50843+ bool 'Denied RWX mmap/mprotect logging'
50844+ default y if GRKERNSEC_CONFIG_AUTO
50845+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
50846+ help
50847+ If you say Y here, calls to mmap() and mprotect() with explicit
50848+ usage of PROT_WRITE and PROT_EXEC together will be logged when
50849+ denied by the PAX_MPROTECT feature. If the sysctl option is
50850+ enabled, a sysctl option with name "rwxmap_logging" is created.
50851+
50852+config GRKERNSEC_AUDIT_TEXTREL
50853+ bool 'ELF text relocations logging (READ HELP)'
50854+ depends on PAX_MPROTECT
50855+ help
50856+ If you say Y here, text relocations will be logged with the filename
50857+ of the offending library or binary. The purpose of the feature is
50858+ to help Linux distribution developers get rid of libraries and
50859+ binaries that need text relocations which hinder the future progress
50860+ of PaX. Only Linux distribution developers should say Y here, and
50861+ never on a production machine, as this option creates an information
50862+ leak that could aid an attacker in defeating the randomization of
50863+ a single memory region. If the sysctl option is enabled, a sysctl
50864+ option with name "audit_textrel" is created.
50865+
50866+endmenu
50867+
50868+menu "Executable Protections"
50869+depends on GRKERNSEC
50870+
50871+config GRKERNSEC_DMESG
50872+ bool "Dmesg(8) restriction"
50873+ default y if GRKERNSEC_CONFIG_AUTO
50874+ help
50875+ If you say Y here, non-root users will not be able to use dmesg(8)
50876+ to view up to the last 4kb of messages in the kernel's log buffer.
50877+ The kernel's log buffer often contains kernel addresses and other
50878+ identifying information useful to an attacker in fingerprinting a
50879+ system for a targeted exploit.
50880+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
50881+ created.
50882+
50883+config GRKERNSEC_HARDEN_PTRACE
50884+ bool "Deter ptrace-based process snooping"
50885+ default y if GRKERNSEC_CONFIG_AUTO
50886+ help
50887+ If you say Y here, TTY sniffers and other malicious monitoring
50888+ programs implemented through ptrace will be defeated. If you
50889+ have been using the RBAC system, this option has already been
50890+ enabled for several years for all users, with the ability to make
50891+ fine-grained exceptions.
50892+
50893+ This option only affects the ability of non-root users to ptrace
50894+ processes that are not a descendent of the ptracing process.
50895+ This means that strace ./binary and gdb ./binary will still work,
50896+ but attaching to arbitrary processes will not. If the sysctl
50897+ option is enabled, a sysctl option with name "harden_ptrace" is
50898+ created.
50899+
50900+config GRKERNSEC_PTRACE_READEXEC
50901+ bool "Require read access to ptrace sensitive binaries"
50902+ default y if GRKERNSEC_CONFIG_AUTO
50903+ help
50904+ If you say Y here, unprivileged users will not be able to ptrace unreadable
50905+ binaries. This option is useful in environments that
50906+ remove the read bits (e.g. file mode 4711) from suid binaries to
50907+ prevent infoleaking of their contents. This option adds
50908+ consistency to the use of that file mode, as the binary could normally
50909+ be read out when run without privileges while ptracing.
50910+
50911+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
50912+ is created.
50913+
50914+config GRKERNSEC_SETXID
50915+ bool "Enforce consistent multithreaded privileges"
50916+ default y if GRKERNSEC_CONFIG_AUTO
50917+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
50918+ help
50919+ If you say Y here, a change from a root uid to a non-root uid
50920+ in a multithreaded application will cause the resulting uids,
50921+ gids, supplementary groups, and capabilities in that thread
50922+ to be propagated to the other threads of the process. In most
50923+ cases this is unnecessary, as glibc will emulate this behavior
50924+ on behalf of the application. Other libcs do not act in the
50925+ same way, allowing the other threads of the process to continue
50926+ running with root privileges. If the sysctl option is enabled,
50927+ a sysctl option with name "consistent_setxid" is created.
50928+
50929+config GRKERNSEC_TPE
50930+ bool "Trusted Path Execution (TPE)"
50931+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
50932+ help
50933+ If you say Y here, you will be able to choose a gid to add to the
50934+ supplementary groups of users you want to mark as "untrusted."
50935+ These users will not be able to execute any files that are not in
50936+ root-owned directories writable only by root. If the sysctl option
50937+ is enabled, a sysctl option with name "tpe" is created.
50938+
50939+config GRKERNSEC_TPE_ALL
50940+ bool "Partially restrict all non-root users"
50941+ depends on GRKERNSEC_TPE
50942+ help
50943+ If you say Y here, all non-root users will be covered under
50944+ a weaker TPE restriction. This is separate from, and in addition to,
50945+ the main TPE options that you have selected elsewhere. Thus, if a
50946+ "trusted" GID is chosen, this restriction applies to even that GID.
50947+ Under this restriction, all non-root users will only be allowed to
50948+ execute files in directories they own that are not group or
50949+ world-writable, or in directories owned by root and writable only by
50950+ root. If the sysctl option is enabled, a sysctl option with name
50951+ "tpe_restrict_all" is created.
50952+
50953+config GRKERNSEC_TPE_INVERT
50954+ bool "Invert GID option"
50955+ depends on GRKERNSEC_TPE
50956+ help
50957+ If you say Y here, the group you specify in the TPE configuration will
50958+ decide what group TPE restrictions will be *disabled* for. This
50959+ option is useful if you want TPE restrictions to be applied to most
50960+ users on the system. If the sysctl option is enabled, a sysctl option
50961+ with name "tpe_invert" is created. Unlike other sysctl options, this
50962+ entry will default to on for backward-compatibility.
50963+
50964+config GRKERNSEC_TPE_GID
50965+ int "GID for untrusted users"
50966+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
50967+ default 1005
50968+ help
50969+ Setting this GID determines what group TPE restrictions will be
50970+ *enabled* for. If the sysctl option is enabled, a sysctl option
50971+ with name "tpe_gid" is created.
50972+
50973+config GRKERNSEC_TPE_GID
50974+ int "GID for trusted users"
50975+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
50976+ default 1005
50977+ help
50978+ Setting this GID determines what group TPE restrictions will be
50979+ *disabled* for. If the sysctl option is enabled, a sysctl option
50980+ with name "tpe_gid" is created.
50981+
50982+endmenu
50983+menu "Network Protections"
50984+depends on GRKERNSEC
50985+
50986+config GRKERNSEC_RANDNET
50987+ bool "Larger entropy pools"
50988+ default y if GRKERNSEC_CONFIG_AUTO
50989+ help
50990+ If you say Y here, the entropy pools used for many features of Linux
50991+ and grsecurity will be doubled in size. Since several grsecurity
50992+ features use additional randomness, it is recommended that you say Y
50993+ here. Saying Y here has a similar effect as modifying
50994+ /proc/sys/kernel/random/poolsize.
50995+
50996+config GRKERNSEC_BLACKHOLE
50997+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
50998+ default y if GRKERNSEC_CONFIG_AUTO
50999+ depends on NET
51000+ help
51001+ If you say Y here, neither TCP resets nor ICMP
51002+ destination-unreachable packets will be sent in response to packets
51003+ sent to ports for which no associated listening process exists.
51004+ This feature supports both IPV4 and IPV6 and exempts the
51005+ loopback interface from blackholing. Enabling this feature
51006+ makes a host more resilient to DoS attacks and reduces network
51007+ visibility against scanners.
51008+
51009+ The blackhole feature as-implemented is equivalent to the FreeBSD
51010+ blackhole feature, as it prevents RST responses to all packets, not
51011+ just SYNs. Under most application behavior this causes no
51012+ problems, but applications (like haproxy) may not close certain
51013+ connections in a way that cleanly terminates them on the remote
51014+ end, leaving the remote host in LAST_ACK state. Because of this
51015+ side-effect and to prevent intentional LAST_ACK DoSes, this
51016+ feature also adds automatic mitigation against such attacks.
51017+ The mitigation drastically reduces the amount of time a socket
51018+ can spend in LAST_ACK state. If you're using haproxy and not
51019+ all servers it connects to have this option enabled, consider
51020+ disabling this feature on the haproxy host.
51021+
51022+ If the sysctl option is enabled, two sysctl options with names
51023+ "ip_blackhole" and "lastack_retries" will be created.
51024+ While "ip_blackhole" takes the standard zero/non-zero on/off
51025+ toggle, "lastack_retries" uses the same kinds of values as
51026+ "tcp_retries1" and "tcp_retries2". The default value of 4
51027+ prevents a socket from lasting more than 45 seconds in LAST_ACK
51028+ state.
51029+
51030+config GRKERNSEC_SOCKET
51031+ bool "Socket restrictions"
51032+ depends on NET
51033+ help
51034+ If you say Y here, you will be able to choose from several options.
51035+ If you assign a GID on your system and add it to the supplementary
51036+ groups of users you want to restrict socket access to, this patch
51037+ will perform up to three things, based on the option(s) you choose.
51038+
51039+config GRKERNSEC_SOCKET_ALL
51040+ bool "Deny any sockets to group"
51041+ depends on GRKERNSEC_SOCKET
51042+ help
51043+ If you say Y here, you will be able to choose a GID of whose users will
51044+ be unable to connect to other hosts from your machine or run server
51045+ applications from your machine. If the sysctl option is enabled, a
51046+ sysctl option with name "socket_all" is created.
51047+
51048+config GRKERNSEC_SOCKET_ALL_GID
51049+ int "GID to deny all sockets for"
51050+ depends on GRKERNSEC_SOCKET_ALL
51051+ default 1004
51052+ help
51053+ Here you can choose the GID to disable socket access for. Remember to
51054+ add the users you want socket access disabled for to the GID
51055+ specified here. If the sysctl option is enabled, a sysctl option
51056+ with name "socket_all_gid" is created.
51057+
51058+config GRKERNSEC_SOCKET_CLIENT
51059+ bool "Deny client sockets to group"
51060+ depends on GRKERNSEC_SOCKET
51061+ help
51062+ If you say Y here, you will be able to choose a GID of whose users will
51063+ be unable to connect to other hosts from your machine, but will be
51064+ able to run servers. If this option is enabled, all users in the group
51065+ you specify will have to use passive mode when initiating ftp transfers
51066+ from the shell on your machine. If the sysctl option is enabled, a
51067+ sysctl option with name "socket_client" is created.
51068+
51069+config GRKERNSEC_SOCKET_CLIENT_GID
51070+ int "GID to deny client sockets for"
51071+ depends on GRKERNSEC_SOCKET_CLIENT
51072+ default 1003
51073+ help
51074+ Here you can choose the GID to disable client socket access for.
51075+ Remember to add the users you want client socket access disabled for to
51076+ the GID specified here. If the sysctl option is enabled, a sysctl
51077+ option with name "socket_client_gid" is created.
51078+
51079+config GRKERNSEC_SOCKET_SERVER
51080+ bool "Deny server sockets to group"
51081+ depends on GRKERNSEC_SOCKET
51082+ help
51083+ If you say Y here, you will be able to choose a GID of whose users will
51084+ be unable to run server applications from your machine. If the sysctl
51085+ option is enabled, a sysctl option with name "socket_server" is created.
51086+
51087+config GRKERNSEC_SOCKET_SERVER_GID
51088+ int "GID to deny server sockets for"
51089+ depends on GRKERNSEC_SOCKET_SERVER
51090+ default 1002
51091+ help
51092+ Here you can choose the GID to disable server socket access for.
51093+ Remember to add the users you want server socket access disabled for to
51094+ the GID specified here. If the sysctl option is enabled, a sysctl
51095+ option with name "socket_server_gid" is created.
51096+
51097+endmenu
51098+menu "Sysctl Support"
51099+depends on GRKERNSEC && SYSCTL
51100+
51101+config GRKERNSEC_SYSCTL
51102+ bool "Sysctl support"
51103+ default y if GRKERNSEC_CONFIG_AUTO
51104+ help
51105+ If you say Y here, you will be able to change the options that
51106+ grsecurity runs with at bootup, without having to recompile your
51107+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
51108+ to enable (1) or disable (0) various features. All the sysctl entries
51109+ are mutable until the "grsec_lock" entry is set to a non-zero value.
51110+ All features enabled in the kernel configuration are disabled at boot
51111+ if you do not say Y to the "Turn on features by default" option.
51112+ All options should be set at startup, and the grsec_lock entry should
51113+ be set to a non-zero value after all the options are set.
51114+ *THIS IS EXTREMELY IMPORTANT*
51115+
51116+config GRKERNSEC_SYSCTL_DISTRO
51117+ bool "Extra sysctl support for distro makers (READ HELP)"
51118+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
51119+ help
51120+ If you say Y here, additional sysctl options will be created
51121+ for features that affect processes running as root. Therefore,
51122+ it is critical when using this option that the grsec_lock entry be
51123+ enabled after boot. Only distros with prebuilt kernel packages
51124+ with this option enabled that can ensure grsec_lock is enabled
51125+ after boot should use this option.
51126+ *Failure to set grsec_lock after boot makes all grsec features
51127+ this option covers useless*
51128+
51129+ Currently this option creates the following sysctl entries:
51130+ "Disable Privileged I/O": "disable_priv_io"
51131+
51132+config GRKERNSEC_SYSCTL_ON
51133+ bool "Turn on features by default"
51134+ default y if GRKERNSEC_CONFIG_AUTO
51135+ depends on GRKERNSEC_SYSCTL
51136+ help
51137+ If you say Y here, instead of having all features enabled in the
51138+ kernel configuration disabled at boot time, the features will be
51139+ enabled at boot time. It is recommended you say Y here unless
51140+ there is some reason you would want all sysctl-tunable features to
51141+ be disabled by default. As mentioned elsewhere, it is important
51142+ to enable the grsec_lock entry once you have finished modifying
51143+ the sysctl entries.
51144+
51145+endmenu
51146+menu "Logging Options"
51147+depends on GRKERNSEC
51148+
51149+config GRKERNSEC_FLOODTIME
51150+ int "Seconds in between log messages (minimum)"
51151+ default 10
51152+ help
51153+ This option allows you to enforce the number of seconds between
51154+ grsecurity log messages. The default should be suitable for most
51155+ people, however, if you choose to change it, choose a value small enough
51156+ to allow informative logs to be produced, but large enough to
51157+ prevent flooding.
51158+
51159+config GRKERNSEC_FLOODBURST
51160+ int "Number of messages in a burst (maximum)"
51161+ default 6
51162+ help
51163+ This option allows you to choose the maximum number of messages allowed
51164+ within the flood time interval you chose in a separate option. The
51165+ default should be suitable for most people, however if you find that
51166+ many of your logs are being interpreted as flooding, you may want to
51167+ raise this value.
51168+
51169+endmenu
51170diff --git a/grsecurity/Makefile b/grsecurity/Makefile
51171new file mode 100644
51172index 0000000..1b9afa9
51173--- /dev/null
51174+++ b/grsecurity/Makefile
51175@@ -0,0 +1,38 @@
51176+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
51177+# during 2001-2009 it has been completely redesigned by Brad Spengler
51178+# into an RBAC system
51179+#
51180+# All code in this directory and various hooks inserted throughout the kernel
51181+# are copyright Brad Spengler - Open Source Security, Inc., and released
51182+# under the GPL v2 or higher
51183+
51184+KBUILD_CFLAGS += -Werror
51185+
51186+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
51187+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
51188+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
51189+
51190+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
51191+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
51192+ gracl_learn.o grsec_log.o
51193+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
51194+
51195+ifdef CONFIG_NET
51196+obj-y += grsec_sock.o
51197+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
51198+endif
51199+
51200+ifndef CONFIG_GRKERNSEC
51201+obj-y += grsec_disabled.o
51202+endif
51203+
51204+ifdef CONFIG_GRKERNSEC_HIDESYM
51205+extra-y := grsec_hidesym.o
51206+$(obj)/grsec_hidesym.o:
51207+ @-chmod -f 500 /boot
51208+ @-chmod -f 500 /lib/modules
51209+ @-chmod -f 500 /lib64/modules
51210+ @-chmod -f 500 /lib32/modules
51211+ @-chmod -f 700 .
51212+ @echo ' grsec: protected kernel image paths'
51213+endif
51214diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
51215new file mode 100644
51216index 0000000..1561617
51217--- /dev/null
51218+++ b/grsecurity/gracl.c
51219@@ -0,0 +1,4017 @@
51220+#include <linux/kernel.h>
51221+#include <linux/module.h>
51222+#include <linux/sched.h>
51223+#include <linux/mm.h>
51224+#include <linux/file.h>
51225+#include <linux/fs.h>
51226+#include <linux/namei.h>
51227+#include <linux/mount.h>
51228+#include <linux/tty.h>
51229+#include <linux/proc_fs.h>
51230+#include <linux/lglock.h>
51231+#include <linux/slab.h>
51232+#include <linux/vmalloc.h>
51233+#include <linux/types.h>
51234+#include <linux/sysctl.h>
51235+#include <linux/netdevice.h>
51236+#include <linux/ptrace.h>
51237+#include <linux/gracl.h>
51238+#include <linux/gralloc.h>
51239+#include <linux/security.h>
51240+#include <linux/grinternal.h>
51241+#include <linux/pid_namespace.h>
51242+#include <linux/stop_machine.h>
51243+#include <linux/fdtable.h>
51244+#include <linux/percpu.h>
51245+#include <linux/lglock.h>
51246+#include "../fs/mount.h"
51247+
51248+#include <asm/uaccess.h>
51249+#include <asm/errno.h>
51250+#include <asm/mman.h>
51251+
51252+extern struct lglock vfsmount_lock;
51253+
51254+static struct acl_role_db acl_role_set;
51255+static struct name_db name_set;
51256+static struct inodev_db inodev_set;
51257+
51258+/* for keeping track of userspace pointers used for subjects, so we
51259+ can share references in the kernel as well
51260+*/
51261+
51262+static struct path real_root;
51263+
51264+static struct acl_subj_map_db subj_map_set;
51265+
51266+static struct acl_role_label *default_role;
51267+
51268+static struct acl_role_label *role_list;
51269+
51270+static u16 acl_sp_role_value;
51271+
51272+extern char *gr_shared_page[4];
51273+static DEFINE_MUTEX(gr_dev_mutex);
51274+DEFINE_RWLOCK(gr_inode_lock);
51275+
51276+struct gr_arg *gr_usermode;
51277+
51278+static unsigned int gr_status __read_only = GR_STATUS_INIT;
51279+
51280+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51281+extern void gr_clear_learn_entries(void);
51282+
51283+#ifdef CONFIG_GRKERNSEC_RESLOG
51284+extern void gr_log_resource(const struct task_struct *task,
51285+ const int res, const unsigned long wanted, const int gt);
51286+#endif
51287+
51288+unsigned char *gr_system_salt;
51289+unsigned char *gr_system_sum;
51290+
51291+static struct sprole_pw **acl_special_roles = NULL;
51292+static __u16 num_sprole_pws = 0;
51293+
51294+static struct acl_role_label *kernel_role = NULL;
51295+
51296+static unsigned int gr_auth_attempts = 0;
51297+static unsigned long gr_auth_expires = 0UL;
51298+
51299+#ifdef CONFIG_NET
51300+extern struct vfsmount *sock_mnt;
51301+#endif
51302+
51303+extern struct vfsmount *pipe_mnt;
51304+extern struct vfsmount *shm_mnt;
51305+#ifdef CONFIG_HUGETLBFS
51306+extern struct vfsmount *hugetlbfs_vfsmount;
51307+#endif
51308+
51309+static struct acl_object_label *fakefs_obj_rw;
51310+static struct acl_object_label *fakefs_obj_rwx;
51311+
51312+extern int gr_init_uidset(void);
51313+extern void gr_free_uidset(void);
51314+extern void gr_remove_uid(uid_t uid);
51315+extern int gr_find_uid(uid_t uid);
51316+
51317+__inline__ int
51318+gr_acl_is_enabled(void)
51319+{
51320+ return (gr_status & GR_READY);
51321+}
51322+
51323+#ifdef CONFIG_BTRFS_FS
51324+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51325+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51326+#endif
51327+
51328+static inline dev_t __get_dev(const struct dentry *dentry)
51329+{
51330+#ifdef CONFIG_BTRFS_FS
51331+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51332+ return get_btrfs_dev_from_inode(dentry->d_inode);
51333+ else
51334+#endif
51335+ return dentry->d_inode->i_sb->s_dev;
51336+}
51337+
51338+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51339+{
51340+ return __get_dev(dentry);
51341+}
51342+
51343+static char gr_task_roletype_to_char(struct task_struct *task)
51344+{
51345+ switch (task->role->roletype &
51346+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51347+ GR_ROLE_SPECIAL)) {
51348+ case GR_ROLE_DEFAULT:
51349+ return 'D';
51350+ case GR_ROLE_USER:
51351+ return 'U';
51352+ case GR_ROLE_GROUP:
51353+ return 'G';
51354+ case GR_ROLE_SPECIAL:
51355+ return 'S';
51356+ }
51357+
51358+ return 'X';
51359+}
51360+
51361+char gr_roletype_to_char(void)
51362+{
51363+ return gr_task_roletype_to_char(current);
51364+}
51365+
51366+__inline__ int
51367+gr_acl_tpe_check(void)
51368+{
51369+ if (unlikely(!(gr_status & GR_READY)))
51370+ return 0;
51371+ if (current->role->roletype & GR_ROLE_TPE)
51372+ return 1;
51373+ else
51374+ return 0;
51375+}
51376+
51377+int
51378+gr_handle_rawio(const struct inode *inode)
51379+{
51380+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51381+ if (inode && S_ISBLK(inode->i_mode) &&
51382+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51383+ !capable(CAP_SYS_RAWIO))
51384+ return 1;
51385+#endif
51386+ return 0;
51387+}
51388+
51389+static int
51390+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51391+{
51392+ if (likely(lena != lenb))
51393+ return 0;
51394+
51395+ return !memcmp(a, b, lena);
51396+}
51397+
51398+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51399+{
51400+ *buflen -= namelen;
51401+ if (*buflen < 0)
51402+ return -ENAMETOOLONG;
51403+ *buffer -= namelen;
51404+ memcpy(*buffer, str, namelen);
51405+ return 0;
51406+}
51407+
51408+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51409+{
51410+ return prepend(buffer, buflen, name->name, name->len);
51411+}
51412+
51413+static int prepend_path(const struct path *path, struct path *root,
51414+ char **buffer, int *buflen)
51415+{
51416+ struct dentry *dentry = path->dentry;
51417+ struct vfsmount *vfsmnt = path->mnt;
51418+ struct mount *mnt = real_mount(vfsmnt);
51419+ bool slash = false;
51420+ int error = 0;
51421+
51422+ while (dentry != root->dentry || vfsmnt != root->mnt) {
51423+ struct dentry * parent;
51424+
51425+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51426+ /* Global root? */
51427+ if (!mnt_has_parent(mnt)) {
51428+ goto out;
51429+ }
51430+ dentry = mnt->mnt_mountpoint;
51431+ mnt = mnt->mnt_parent;
51432+ vfsmnt = &mnt->mnt;
51433+ continue;
51434+ }
51435+ parent = dentry->d_parent;
51436+ prefetch(parent);
51437+ spin_lock(&dentry->d_lock);
51438+ error = prepend_name(buffer, buflen, &dentry->d_name);
51439+ spin_unlock(&dentry->d_lock);
51440+ if (!error)
51441+ error = prepend(buffer, buflen, "/", 1);
51442+ if (error)
51443+ break;
51444+
51445+ slash = true;
51446+ dentry = parent;
51447+ }
51448+
51449+out:
51450+ if (!error && !slash)
51451+ error = prepend(buffer, buflen, "/", 1);
51452+
51453+ return error;
51454+}
51455+
51456+/* this must be called with vfsmount_lock and rename_lock held */
51457+
51458+static char *__our_d_path(const struct path *path, struct path *root,
51459+ char *buf, int buflen)
51460+{
51461+ char *res = buf + buflen;
51462+ int error;
51463+
51464+ prepend(&res, &buflen, "\0", 1);
51465+ error = prepend_path(path, root, &res, &buflen);
51466+ if (error)
51467+ return ERR_PTR(error);
51468+
51469+ return res;
51470+}
51471+
51472+static char *
51473+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
51474+{
51475+ char *retval;
51476+
51477+ retval = __our_d_path(path, root, buf, buflen);
51478+ if (unlikely(IS_ERR(retval)))
51479+ retval = strcpy(buf, "<path too long>");
51480+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
51481+ retval[1] = '\0';
51482+
51483+ return retval;
51484+}
51485+
51486+static char *
51487+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51488+ char *buf, int buflen)
51489+{
51490+ struct path path;
51491+ char *res;
51492+
51493+ path.dentry = (struct dentry *)dentry;
51494+ path.mnt = (struct vfsmount *)vfsmnt;
51495+
51496+ /* we can use real_root.dentry, real_root.mnt, because this is only called
51497+ by the RBAC system */
51498+ res = gen_full_path(&path, &real_root, buf, buflen);
51499+
51500+ return res;
51501+}
51502+
51503+static char *
51504+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51505+ char *buf, int buflen)
51506+{
51507+ char *res;
51508+ struct path path;
51509+ struct path root;
51510+ struct task_struct *reaper = init_pid_ns.child_reaper;
51511+
51512+ path.dentry = (struct dentry *)dentry;
51513+ path.mnt = (struct vfsmount *)vfsmnt;
51514+
51515+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
51516+ get_fs_root(reaper->fs, &root);
51517+
51518+ write_seqlock(&rename_lock);
51519+ br_read_lock(&vfsmount_lock);
51520+ res = gen_full_path(&path, &root, buf, buflen);
51521+ br_read_unlock(&vfsmount_lock);
51522+ write_sequnlock(&rename_lock);
51523+
51524+ path_put(&root);
51525+ return res;
51526+}
51527+
51528+static char *
51529+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51530+{
51531+ char *ret;
51532+ write_seqlock(&rename_lock);
51533+ br_read_lock(&vfsmount_lock);
51534+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51535+ PAGE_SIZE);
51536+ br_read_unlock(&vfsmount_lock);
51537+ write_sequnlock(&rename_lock);
51538+ return ret;
51539+}
51540+
51541+static char *
51542+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51543+{
51544+ char *ret;
51545+ char *buf;
51546+ int buflen;
51547+
51548+ write_seqlock(&rename_lock);
51549+ br_read_lock(&vfsmount_lock);
51550+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
51551+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
51552+ buflen = (int)(ret - buf);
51553+ if (buflen >= 5)
51554+ prepend(&ret, &buflen, "/proc", 5);
51555+ else
51556+ ret = strcpy(buf, "<path too long>");
51557+ br_read_unlock(&vfsmount_lock);
51558+ write_sequnlock(&rename_lock);
51559+ return ret;
51560+}
51561+
51562+char *
51563+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
51564+{
51565+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51566+ PAGE_SIZE);
51567+}
51568+
51569+char *
51570+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
51571+{
51572+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
51573+ PAGE_SIZE);
51574+}
51575+
51576+char *
51577+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
51578+{
51579+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
51580+ PAGE_SIZE);
51581+}
51582+
51583+char *
51584+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
51585+{
51586+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
51587+ PAGE_SIZE);
51588+}
51589+
51590+char *
51591+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
51592+{
51593+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
51594+ PAGE_SIZE);
51595+}
51596+
51597+__inline__ __u32
51598+to_gr_audit(const __u32 reqmode)
51599+{
51600+ /* masks off auditable permission flags, then shifts them to create
51601+ auditing flags, and adds the special case of append auditing if
51602+ we're requesting write */
51603+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
51604+}
51605+
51606+struct acl_subject_label *
51607+lookup_subject_map(const struct acl_subject_label *userp)
51608+{
51609+ unsigned int index = shash(userp, subj_map_set.s_size);
51610+ struct subject_map *match;
51611+
51612+ match = subj_map_set.s_hash[index];
51613+
51614+ while (match && match->user != userp)
51615+ match = match->next;
51616+
51617+ if (match != NULL)
51618+ return match->kernel;
51619+ else
51620+ return NULL;
51621+}
51622+
51623+static void
51624+insert_subj_map_entry(struct subject_map *subjmap)
51625+{
51626+ unsigned int index = shash(subjmap->user, subj_map_set.s_size);
51627+ struct subject_map **curr;
51628+
51629+ subjmap->prev = NULL;
51630+
51631+ curr = &subj_map_set.s_hash[index];
51632+ if (*curr != NULL)
51633+ (*curr)->prev = subjmap;
51634+
51635+ subjmap->next = *curr;
51636+ *curr = subjmap;
51637+
51638+ return;
51639+}
51640+
51641+static struct acl_role_label *
51642+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
51643+ const gid_t gid)
51644+{
51645+ unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
51646+ struct acl_role_label *match;
51647+ struct role_allowed_ip *ipp;
51648+ unsigned int x;
51649+ u32 curr_ip = task->signal->curr_ip;
51650+
51651+ task->signal->saved_ip = curr_ip;
51652+
51653+ match = acl_role_set.r_hash[index];
51654+
51655+ while (match) {
51656+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
51657+ for (x = 0; x < match->domain_child_num; x++) {
51658+ if (match->domain_children[x] == uid)
51659+ goto found;
51660+ }
51661+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
51662+ break;
51663+ match = match->next;
51664+ }
51665+found:
51666+ if (match == NULL) {
51667+ try_group:
51668+ index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
51669+ match = acl_role_set.r_hash[index];
51670+
51671+ while (match) {
51672+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
51673+ for (x = 0; x < match->domain_child_num; x++) {
51674+ if (match->domain_children[x] == gid)
51675+ goto found2;
51676+ }
51677+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
51678+ break;
51679+ match = match->next;
51680+ }
51681+found2:
51682+ if (match == NULL)
51683+ match = default_role;
51684+ if (match->allowed_ips == NULL)
51685+ return match;
51686+ else {
51687+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51688+ if (likely
51689+ ((ntohl(curr_ip) & ipp->netmask) ==
51690+ (ntohl(ipp->addr) & ipp->netmask)))
51691+ return match;
51692+ }
51693+ match = default_role;
51694+ }
51695+ } else if (match->allowed_ips == NULL) {
51696+ return match;
51697+ } else {
51698+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51699+ if (likely
51700+ ((ntohl(curr_ip) & ipp->netmask) ==
51701+ (ntohl(ipp->addr) & ipp->netmask)))
51702+ return match;
51703+ }
51704+ goto try_group;
51705+ }
51706+
51707+ return match;
51708+}
51709+
51710+struct acl_subject_label *
51711+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
51712+ const struct acl_role_label *role)
51713+{
51714+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
51715+ struct acl_subject_label *match;
51716+
51717+ match = role->subj_hash[index];
51718+
51719+ while (match && (match->inode != ino || match->device != dev ||
51720+ (match->mode & GR_DELETED))) {
51721+ match = match->next;
51722+ }
51723+
51724+ if (match && !(match->mode & GR_DELETED))
51725+ return match;
51726+ else
51727+ return NULL;
51728+}
51729+
51730+struct acl_subject_label *
51731+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
51732+ const struct acl_role_label *role)
51733+{
51734+ unsigned int index = fhash(ino, dev, role->subj_hash_size);
51735+ struct acl_subject_label *match;
51736+
51737+ match = role->subj_hash[index];
51738+
51739+ while (match && (match->inode != ino || match->device != dev ||
51740+ !(match->mode & GR_DELETED))) {
51741+ match = match->next;
51742+ }
51743+
51744+ if (match && (match->mode & GR_DELETED))
51745+ return match;
51746+ else
51747+ return NULL;
51748+}
51749+
51750+static struct acl_object_label *
51751+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
51752+ const struct acl_subject_label *subj)
51753+{
51754+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51755+ struct acl_object_label *match;
51756+
51757+ match = subj->obj_hash[index];
51758+
51759+ while (match && (match->inode != ino || match->device != dev ||
51760+ (match->mode & GR_DELETED))) {
51761+ match = match->next;
51762+ }
51763+
51764+ if (match && !(match->mode & GR_DELETED))
51765+ return match;
51766+ else
51767+ return NULL;
51768+}
51769+
51770+static struct acl_object_label *
51771+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
51772+ const struct acl_subject_label *subj)
51773+{
51774+ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51775+ struct acl_object_label *match;
51776+
51777+ match = subj->obj_hash[index];
51778+
51779+ while (match && (match->inode != ino || match->device != dev ||
51780+ !(match->mode & GR_DELETED))) {
51781+ match = match->next;
51782+ }
51783+
51784+ if (match && (match->mode & GR_DELETED))
51785+ return match;
51786+
51787+ match = subj->obj_hash[index];
51788+
51789+ while (match && (match->inode != ino || match->device != dev ||
51790+ (match->mode & GR_DELETED))) {
51791+ match = match->next;
51792+ }
51793+
51794+ if (match && !(match->mode & GR_DELETED))
51795+ return match;
51796+ else
51797+ return NULL;
51798+}
51799+
51800+static struct name_entry *
51801+lookup_name_entry(const char *name)
51802+{
51803+ unsigned int len = strlen(name);
51804+ unsigned int key = full_name_hash(name, len);
51805+ unsigned int index = key % name_set.n_size;
51806+ struct name_entry *match;
51807+
51808+ match = name_set.n_hash[index];
51809+
51810+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
51811+ match = match->next;
51812+
51813+ return match;
51814+}
51815+
51816+static struct name_entry *
51817+lookup_name_entry_create(const char *name)
51818+{
51819+ unsigned int len = strlen(name);
51820+ unsigned int key = full_name_hash(name, len);
51821+ unsigned int index = key % name_set.n_size;
51822+ struct name_entry *match;
51823+
51824+ match = name_set.n_hash[index];
51825+
51826+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51827+ !match->deleted))
51828+ match = match->next;
51829+
51830+ if (match && match->deleted)
51831+ return match;
51832+
51833+ match = name_set.n_hash[index];
51834+
51835+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51836+ match->deleted))
51837+ match = match->next;
51838+
51839+ if (match && !match->deleted)
51840+ return match;
51841+ else
51842+ return NULL;
51843+}
51844+
51845+static struct inodev_entry *
51846+lookup_inodev_entry(const ino_t ino, const dev_t dev)
51847+{
51848+ unsigned int index = fhash(ino, dev, inodev_set.i_size);
51849+ struct inodev_entry *match;
51850+
51851+ match = inodev_set.i_hash[index];
51852+
51853+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
51854+ match = match->next;
51855+
51856+ return match;
51857+}
51858+
51859+static void
51860+insert_inodev_entry(struct inodev_entry *entry)
51861+{
51862+ unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
51863+ inodev_set.i_size);
51864+ struct inodev_entry **curr;
51865+
51866+ entry->prev = NULL;
51867+
51868+ curr = &inodev_set.i_hash[index];
51869+ if (*curr != NULL)
51870+ (*curr)->prev = entry;
51871+
51872+ entry->next = *curr;
51873+ *curr = entry;
51874+
51875+ return;
51876+}
51877+
51878+static void
51879+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
51880+{
51881+ unsigned int index =
51882+ rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
51883+ struct acl_role_label **curr;
51884+ struct acl_role_label *tmp, *tmp2;
51885+
51886+ curr = &acl_role_set.r_hash[index];
51887+
51888+ /* simple case, slot is empty, just set it to our role */
51889+ if (*curr == NULL) {
51890+ *curr = role;
51891+ } else {
51892+ /* example:
51893+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
51894+ 2 -> 3
51895+ */
51896+ /* first check to see if we can already be reached via this slot */
51897+ tmp = *curr;
51898+ while (tmp && tmp != role)
51899+ tmp = tmp->next;
51900+ if (tmp == role) {
51901+ /* we don't need to add ourselves to this slot's chain */
51902+ return;
51903+ }
51904+ /* we need to add ourselves to this chain, two cases */
51905+ if (role->next == NULL) {
51906+ /* simple case, append the current chain to our role */
51907+ role->next = *curr;
51908+ *curr = role;
51909+ } else {
51910+ /* 1 -> 2 -> 3 -> 4
51911+ 2 -> 3 -> 4
51912+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
51913+ */
51914+ /* trickier case: walk our role's chain until we find
51915+ the role for the start of the current slot's chain */
51916+ tmp = role;
51917+ tmp2 = *curr;
51918+ while (tmp->next && tmp->next != tmp2)
51919+ tmp = tmp->next;
51920+ if (tmp->next == tmp2) {
51921+ /* from example above, we found 3, so just
51922+ replace this slot's chain with ours */
51923+ *curr = role;
51924+ } else {
51925+ /* we didn't find a subset of our role's chain
51926+ in the current slot's chain, so append their
51927+ chain to ours, and set us as the first role in
51928+ the slot's chain
51929+
51930+ we could fold this case with the case above,
51931+ but making it explicit for clarity
51932+ */
51933+ tmp->next = tmp2;
51934+ *curr = role;
51935+ }
51936+ }
51937+ }
51938+
51939+ return;
51940+}
51941+
51942+static void
51943+insert_acl_role_label(struct acl_role_label *role)
51944+{
51945+ int i;
51946+
51947+ if (role_list == NULL) {
51948+ role_list = role;
51949+ role->prev = NULL;
51950+ } else {
51951+ role->prev = role_list;
51952+ role_list = role;
51953+ }
51954+
51955+ /* used for hash chains */
51956+ role->next = NULL;
51957+
51958+ if (role->roletype & GR_ROLE_DOMAIN) {
51959+ for (i = 0; i < role->domain_child_num; i++)
51960+ __insert_acl_role_label(role, role->domain_children[i]);
51961+ } else
51962+ __insert_acl_role_label(role, role->uidgid);
51963+}
51964+
51965+static int
51966+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
51967+{
51968+ struct name_entry **curr, *nentry;
51969+ struct inodev_entry *ientry;
51970+ unsigned int len = strlen(name);
51971+ unsigned int key = full_name_hash(name, len);
51972+ unsigned int index = key % name_set.n_size;
51973+
51974+ curr = &name_set.n_hash[index];
51975+
51976+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
51977+ curr = &((*curr)->next);
51978+
51979+ if (*curr != NULL)
51980+ return 1;
51981+
51982+ nentry = acl_alloc(sizeof (struct name_entry));
51983+ if (nentry == NULL)
51984+ return 0;
51985+ ientry = acl_alloc(sizeof (struct inodev_entry));
51986+ if (ientry == NULL)
51987+ return 0;
51988+ ientry->nentry = nentry;
51989+
51990+ nentry->key = key;
51991+ nentry->name = name;
51992+ nentry->inode = inode;
51993+ nentry->device = device;
51994+ nentry->len = len;
51995+ nentry->deleted = deleted;
51996+
51997+ nentry->prev = NULL;
51998+ curr = &name_set.n_hash[index];
51999+ if (*curr != NULL)
52000+ (*curr)->prev = nentry;
52001+ nentry->next = *curr;
52002+ *curr = nentry;
52003+
52004+ /* insert us into the table searchable by inode/dev */
52005+ insert_inodev_entry(ientry);
52006+
52007+ return 1;
52008+}
52009+
52010+static void
52011+insert_acl_obj_label(struct acl_object_label *obj,
52012+ struct acl_subject_label *subj)
52013+{
52014+ unsigned int index =
52015+ fhash(obj->inode, obj->device, subj->obj_hash_size);
52016+ struct acl_object_label **curr;
52017+
52018+
52019+ obj->prev = NULL;
52020+
52021+ curr = &subj->obj_hash[index];
52022+ if (*curr != NULL)
52023+ (*curr)->prev = obj;
52024+
52025+ obj->next = *curr;
52026+ *curr = obj;
52027+
52028+ return;
52029+}
52030+
52031+static void
52032+insert_acl_subj_label(struct acl_subject_label *obj,
52033+ struct acl_role_label *role)
52034+{
52035+ unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
52036+ struct acl_subject_label **curr;
52037+
52038+ obj->prev = NULL;
52039+
52040+ curr = &role->subj_hash[index];
52041+ if (*curr != NULL)
52042+ (*curr)->prev = obj;
52043+
52044+ obj->next = *curr;
52045+ *curr = obj;
52046+
52047+ return;
52048+}
52049+
52050+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
52051+
52052+static void *
52053+create_table(__u32 * len, int elementsize)
52054+{
52055+ unsigned int table_sizes[] = {
52056+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
52057+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
52058+ 4194301, 8388593, 16777213, 33554393, 67108859
52059+ };
52060+ void *newtable = NULL;
52061+ unsigned int pwr = 0;
52062+
52063+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
52064+ table_sizes[pwr] <= *len)
52065+ pwr++;
52066+
52067+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
52068+ return newtable;
52069+
52070+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
52071+ newtable =
52072+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
52073+ else
52074+ newtable = vmalloc(table_sizes[pwr] * elementsize);
52075+
52076+ *len = table_sizes[pwr];
52077+
52078+ return newtable;
52079+}
52080+
52081+static int
52082+init_variables(const struct gr_arg *arg)
52083+{
52084+ struct task_struct *reaper = init_pid_ns.child_reaper;
52085+ unsigned int stacksize;
52086+
52087+ subj_map_set.s_size = arg->role_db.num_subjects;
52088+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
52089+ name_set.n_size = arg->role_db.num_objects;
52090+ inodev_set.i_size = arg->role_db.num_objects;
52091+
52092+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
52093+ !name_set.n_size || !inodev_set.i_size)
52094+ return 1;
52095+
52096+ if (!gr_init_uidset())
52097+ return 1;
52098+
52099+ /* set up the stack that holds allocation info */
52100+
52101+ stacksize = arg->role_db.num_pointers + 5;
52102+
52103+ if (!acl_alloc_stack_init(stacksize))
52104+ return 1;
52105+
52106+ /* grab reference for the real root dentry and vfsmount */
52107+ get_fs_root(reaper->fs, &real_root);
52108+
52109+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52110+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
52111+#endif
52112+
52113+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
52114+ if (fakefs_obj_rw == NULL)
52115+ return 1;
52116+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
52117+
52118+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
52119+ if (fakefs_obj_rwx == NULL)
52120+ return 1;
52121+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
52122+
52123+ subj_map_set.s_hash =
52124+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
52125+ acl_role_set.r_hash =
52126+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
52127+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
52128+ inodev_set.i_hash =
52129+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
52130+
52131+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
52132+ !name_set.n_hash || !inodev_set.i_hash)
52133+ return 1;
52134+
52135+ memset(subj_map_set.s_hash, 0,
52136+ sizeof(struct subject_map *) * subj_map_set.s_size);
52137+ memset(acl_role_set.r_hash, 0,
52138+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
52139+ memset(name_set.n_hash, 0,
52140+ sizeof (struct name_entry *) * name_set.n_size);
52141+ memset(inodev_set.i_hash, 0,
52142+ sizeof (struct inodev_entry *) * inodev_set.i_size);
52143+
52144+ return 0;
52145+}
52146+
52147+/* free information not needed after startup
52148+ currently contains user->kernel pointer mappings for subjects
52149+*/
52150+
52151+static void
52152+free_init_variables(void)
52153+{
52154+ __u32 i;
52155+
52156+ if (subj_map_set.s_hash) {
52157+ for (i = 0; i < subj_map_set.s_size; i++) {
52158+ if (subj_map_set.s_hash[i]) {
52159+ kfree(subj_map_set.s_hash[i]);
52160+ subj_map_set.s_hash[i] = NULL;
52161+ }
52162+ }
52163+
52164+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
52165+ PAGE_SIZE)
52166+ kfree(subj_map_set.s_hash);
52167+ else
52168+ vfree(subj_map_set.s_hash);
52169+ }
52170+
52171+ return;
52172+}
52173+
52174+static void
52175+free_variables(void)
52176+{
52177+ struct acl_subject_label *s;
52178+ struct acl_role_label *r;
52179+ struct task_struct *task, *task2;
52180+ unsigned int x;
52181+
52182+ gr_clear_learn_entries();
52183+
52184+ read_lock(&tasklist_lock);
52185+ do_each_thread(task2, task) {
52186+ task->acl_sp_role = 0;
52187+ task->acl_role_id = 0;
52188+ task->acl = NULL;
52189+ task->role = NULL;
52190+ } while_each_thread(task2, task);
52191+ read_unlock(&tasklist_lock);
52192+
52193+ /* release the reference to the real root dentry and vfsmount */
52194+ path_put(&real_root);
52195+ memset(&real_root, 0, sizeof(real_root));
52196+
52197+ /* free all object hash tables */
52198+
52199+ FOR_EACH_ROLE_START(r)
52200+ if (r->subj_hash == NULL)
52201+ goto next_role;
52202+ FOR_EACH_SUBJECT_START(r, s, x)
52203+ if (s->obj_hash == NULL)
52204+ break;
52205+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52206+ kfree(s->obj_hash);
52207+ else
52208+ vfree(s->obj_hash);
52209+ FOR_EACH_SUBJECT_END(s, x)
52210+ FOR_EACH_NESTED_SUBJECT_START(r, s)
52211+ if (s->obj_hash == NULL)
52212+ break;
52213+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52214+ kfree(s->obj_hash);
52215+ else
52216+ vfree(s->obj_hash);
52217+ FOR_EACH_NESTED_SUBJECT_END(s)
52218+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
52219+ kfree(r->subj_hash);
52220+ else
52221+ vfree(r->subj_hash);
52222+ r->subj_hash = NULL;
52223+next_role:
52224+ FOR_EACH_ROLE_END(r)
52225+
52226+ acl_free_all();
52227+
52228+ if (acl_role_set.r_hash) {
52229+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
52230+ PAGE_SIZE)
52231+ kfree(acl_role_set.r_hash);
52232+ else
52233+ vfree(acl_role_set.r_hash);
52234+ }
52235+ if (name_set.n_hash) {
52236+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
52237+ PAGE_SIZE)
52238+ kfree(name_set.n_hash);
52239+ else
52240+ vfree(name_set.n_hash);
52241+ }
52242+
52243+ if (inodev_set.i_hash) {
52244+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
52245+ PAGE_SIZE)
52246+ kfree(inodev_set.i_hash);
52247+ else
52248+ vfree(inodev_set.i_hash);
52249+ }
52250+
52251+ gr_free_uidset();
52252+
52253+ memset(&name_set, 0, sizeof (struct name_db));
52254+ memset(&inodev_set, 0, sizeof (struct inodev_db));
52255+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52256+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52257+
52258+ default_role = NULL;
52259+ kernel_role = NULL;
52260+ role_list = NULL;
52261+
52262+ return;
52263+}
52264+
52265+static __u32
52266+count_user_objs(struct acl_object_label *userp)
52267+{
52268+ struct acl_object_label o_tmp;
52269+ __u32 num = 0;
52270+
52271+ while (userp) {
52272+ if (copy_from_user(&o_tmp, userp,
52273+ sizeof (struct acl_object_label)))
52274+ break;
52275+
52276+ userp = o_tmp.prev;
52277+ num++;
52278+ }
52279+
52280+ return num;
52281+}
52282+
52283+static struct acl_subject_label *
52284+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
52285+
52286+static int
52287+copy_user_glob(struct acl_object_label *obj)
52288+{
52289+ struct acl_object_label *g_tmp, **guser;
52290+ unsigned int len;
52291+ char *tmp;
52292+
52293+ if (obj->globbed == NULL)
52294+ return 0;
52295+
52296+ guser = &obj->globbed;
52297+ while (*guser) {
52298+ g_tmp = (struct acl_object_label *)
52299+ acl_alloc(sizeof (struct acl_object_label));
52300+ if (g_tmp == NULL)
52301+ return -ENOMEM;
52302+
52303+ if (copy_from_user(g_tmp, *guser,
52304+ sizeof (struct acl_object_label)))
52305+ return -EFAULT;
52306+
52307+ len = strnlen_user(g_tmp->filename, PATH_MAX);
52308+
52309+ if (!len || len >= PATH_MAX)
52310+ return -EINVAL;
52311+
52312+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52313+ return -ENOMEM;
52314+
52315+ if (copy_from_user(tmp, g_tmp->filename, len))
52316+ return -EFAULT;
52317+ tmp[len-1] = '\0';
52318+ g_tmp->filename = tmp;
52319+
52320+ *guser = g_tmp;
52321+ guser = &(g_tmp->next);
52322+ }
52323+
52324+ return 0;
52325+}
52326+
52327+static int
52328+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52329+ struct acl_role_label *role)
52330+{
52331+ struct acl_object_label *o_tmp;
52332+ unsigned int len;
52333+ int ret;
52334+ char *tmp;
52335+
52336+ while (userp) {
52337+ if ((o_tmp = (struct acl_object_label *)
52338+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
52339+ return -ENOMEM;
52340+
52341+ if (copy_from_user(o_tmp, userp,
52342+ sizeof (struct acl_object_label)))
52343+ return -EFAULT;
52344+
52345+ userp = o_tmp->prev;
52346+
52347+ len = strnlen_user(o_tmp->filename, PATH_MAX);
52348+
52349+ if (!len || len >= PATH_MAX)
52350+ return -EINVAL;
52351+
52352+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52353+ return -ENOMEM;
52354+
52355+ if (copy_from_user(tmp, o_tmp->filename, len))
52356+ return -EFAULT;
52357+ tmp[len-1] = '\0';
52358+ o_tmp->filename = tmp;
52359+
52360+ insert_acl_obj_label(o_tmp, subj);
52361+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52362+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52363+ return -ENOMEM;
52364+
52365+ ret = copy_user_glob(o_tmp);
52366+ if (ret)
52367+ return ret;
52368+
52369+ if (o_tmp->nested) {
52370+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
52371+ if (IS_ERR(o_tmp->nested))
52372+ return PTR_ERR(o_tmp->nested);
52373+
52374+ /* insert into nested subject list */
52375+ o_tmp->nested->next = role->hash->first;
52376+ role->hash->first = o_tmp->nested;
52377+ }
52378+ }
52379+
52380+ return 0;
52381+}
52382+
52383+static __u32
52384+count_user_subjs(struct acl_subject_label *userp)
52385+{
52386+ struct acl_subject_label s_tmp;
52387+ __u32 num = 0;
52388+
52389+ while (userp) {
52390+ if (copy_from_user(&s_tmp, userp,
52391+ sizeof (struct acl_subject_label)))
52392+ break;
52393+
52394+ userp = s_tmp.prev;
52395+ /* do not count nested subjects against this count, since
52396+ they are not included in the hash table, but are
52397+ attached to objects. We have already counted
52398+ the subjects in userspace for the allocation
52399+ stack
52400+ */
52401+ if (!(s_tmp.mode & GR_NESTED))
52402+ num++;
52403+ }
52404+
52405+ return num;
52406+}
52407+
52408+static int
52409+copy_user_allowedips(struct acl_role_label *rolep)
52410+{
52411+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52412+
52413+ ruserip = rolep->allowed_ips;
52414+
52415+ while (ruserip) {
52416+ rlast = rtmp;
52417+
52418+ if ((rtmp = (struct role_allowed_ip *)
52419+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52420+ return -ENOMEM;
52421+
52422+ if (copy_from_user(rtmp, ruserip,
52423+ sizeof (struct role_allowed_ip)))
52424+ return -EFAULT;
52425+
52426+ ruserip = rtmp->prev;
52427+
52428+ if (!rlast) {
52429+ rtmp->prev = NULL;
52430+ rolep->allowed_ips = rtmp;
52431+ } else {
52432+ rlast->next = rtmp;
52433+ rtmp->prev = rlast;
52434+ }
52435+
52436+ if (!ruserip)
52437+ rtmp->next = NULL;
52438+ }
52439+
52440+ return 0;
52441+}
52442+
52443+static int
52444+copy_user_transitions(struct acl_role_label *rolep)
52445+{
52446+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
52447+
52448+ unsigned int len;
52449+ char *tmp;
52450+
52451+ rusertp = rolep->transitions;
52452+
52453+ while (rusertp) {
52454+ rlast = rtmp;
52455+
52456+ if ((rtmp = (struct role_transition *)
52457+ acl_alloc(sizeof (struct role_transition))) == NULL)
52458+ return -ENOMEM;
52459+
52460+ if (copy_from_user(rtmp, rusertp,
52461+ sizeof (struct role_transition)))
52462+ return -EFAULT;
52463+
52464+ rusertp = rtmp->prev;
52465+
52466+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52467+
52468+ if (!len || len >= GR_SPROLE_LEN)
52469+ return -EINVAL;
52470+
52471+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52472+ return -ENOMEM;
52473+
52474+ if (copy_from_user(tmp, rtmp->rolename, len))
52475+ return -EFAULT;
52476+ tmp[len-1] = '\0';
52477+ rtmp->rolename = tmp;
52478+
52479+ if (!rlast) {
52480+ rtmp->prev = NULL;
52481+ rolep->transitions = rtmp;
52482+ } else {
52483+ rlast->next = rtmp;
52484+ rtmp->prev = rlast;
52485+ }
52486+
52487+ if (!rusertp)
52488+ rtmp->next = NULL;
52489+ }
52490+
52491+ return 0;
52492+}
52493+
52494+static struct acl_subject_label *
52495+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
52496+{
52497+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
52498+ unsigned int len;
52499+ char *tmp;
52500+ __u32 num_objs;
52501+ struct acl_ip_label **i_tmp, *i_utmp2;
52502+ struct gr_hash_struct ghash;
52503+ struct subject_map *subjmap;
52504+ unsigned int i_num;
52505+ int err;
52506+
52507+ s_tmp = lookup_subject_map(userp);
52508+
52509+ /* we've already copied this subject into the kernel, just return
52510+ the reference to it, and don't copy it over again
52511+ */
52512+ if (s_tmp)
52513+ return(s_tmp);
52514+
52515+ if ((s_tmp = (struct acl_subject_label *)
52516+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
52517+ return ERR_PTR(-ENOMEM);
52518+
52519+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
52520+ if (subjmap == NULL)
52521+ return ERR_PTR(-ENOMEM);
52522+
52523+ subjmap->user = userp;
52524+ subjmap->kernel = s_tmp;
52525+ insert_subj_map_entry(subjmap);
52526+
52527+ if (copy_from_user(s_tmp, userp,
52528+ sizeof (struct acl_subject_label)))
52529+ return ERR_PTR(-EFAULT);
52530+
52531+ len = strnlen_user(s_tmp->filename, PATH_MAX);
52532+
52533+ if (!len || len >= PATH_MAX)
52534+ return ERR_PTR(-EINVAL);
52535+
52536+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52537+ return ERR_PTR(-ENOMEM);
52538+
52539+ if (copy_from_user(tmp, s_tmp->filename, len))
52540+ return ERR_PTR(-EFAULT);
52541+ tmp[len-1] = '\0';
52542+ s_tmp->filename = tmp;
52543+
52544+ if (!strcmp(s_tmp->filename, "/"))
52545+ role->root_label = s_tmp;
52546+
52547+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
52548+ return ERR_PTR(-EFAULT);
52549+
52550+ /* copy user and group transition tables */
52551+
52552+ if (s_tmp->user_trans_num) {
52553+ uid_t *uidlist;
52554+
52555+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
52556+ if (uidlist == NULL)
52557+ return ERR_PTR(-ENOMEM);
52558+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
52559+ return ERR_PTR(-EFAULT);
52560+
52561+ s_tmp->user_transitions = uidlist;
52562+ }
52563+
52564+ if (s_tmp->group_trans_num) {
52565+ gid_t *gidlist;
52566+
52567+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
52568+ if (gidlist == NULL)
52569+ return ERR_PTR(-ENOMEM);
52570+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
52571+ return ERR_PTR(-EFAULT);
52572+
52573+ s_tmp->group_transitions = gidlist;
52574+ }
52575+
52576+ /* set up object hash table */
52577+ num_objs = count_user_objs(ghash.first);
52578+
52579+ s_tmp->obj_hash_size = num_objs;
52580+ s_tmp->obj_hash =
52581+ (struct acl_object_label **)
52582+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
52583+
52584+ if (!s_tmp->obj_hash)
52585+ return ERR_PTR(-ENOMEM);
52586+
52587+ memset(s_tmp->obj_hash, 0,
52588+ s_tmp->obj_hash_size *
52589+ sizeof (struct acl_object_label *));
52590+
52591+ /* add in objects */
52592+ err = copy_user_objs(ghash.first, s_tmp, role);
52593+
52594+ if (err)
52595+ return ERR_PTR(err);
52596+
52597+ /* set pointer for parent subject */
52598+ if (s_tmp->parent_subject) {
52599+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
52600+
52601+ if (IS_ERR(s_tmp2))
52602+ return s_tmp2;
52603+
52604+ s_tmp->parent_subject = s_tmp2;
52605+ }
52606+
52607+ /* add in ip acls */
52608+
52609+ if (!s_tmp->ip_num) {
52610+ s_tmp->ips = NULL;
52611+ goto insert;
52612+ }
52613+
52614+ i_tmp =
52615+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
52616+ sizeof (struct acl_ip_label *));
52617+
52618+ if (!i_tmp)
52619+ return ERR_PTR(-ENOMEM);
52620+
52621+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
52622+ *(i_tmp + i_num) =
52623+ (struct acl_ip_label *)
52624+ acl_alloc(sizeof (struct acl_ip_label));
52625+ if (!*(i_tmp + i_num))
52626+ return ERR_PTR(-ENOMEM);
52627+
52628+ if (copy_from_user
52629+ (&i_utmp2, s_tmp->ips + i_num,
52630+ sizeof (struct acl_ip_label *)))
52631+ return ERR_PTR(-EFAULT);
52632+
52633+ if (copy_from_user
52634+ (*(i_tmp + i_num), i_utmp2,
52635+ sizeof (struct acl_ip_label)))
52636+ return ERR_PTR(-EFAULT);
52637+
52638+ if ((*(i_tmp + i_num))->iface == NULL)
52639+ continue;
52640+
52641+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
52642+ if (!len || len >= IFNAMSIZ)
52643+ return ERR_PTR(-EINVAL);
52644+ tmp = acl_alloc(len);
52645+ if (tmp == NULL)
52646+ return ERR_PTR(-ENOMEM);
52647+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
52648+ return ERR_PTR(-EFAULT);
52649+ (*(i_tmp + i_num))->iface = tmp;
52650+ }
52651+
52652+ s_tmp->ips = i_tmp;
52653+
52654+insert:
52655+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
52656+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
52657+ return ERR_PTR(-ENOMEM);
52658+
52659+ return s_tmp;
52660+}
52661+
52662+static int
52663+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
52664+{
52665+ struct acl_subject_label s_pre;
52666+ struct acl_subject_label * ret;
52667+ int err;
52668+
52669+ while (userp) {
52670+ if (copy_from_user(&s_pre, userp,
52671+ sizeof (struct acl_subject_label)))
52672+ return -EFAULT;
52673+
52674+ /* do not add nested subjects here, add
52675+ while parsing objects
52676+ */
52677+
52678+ if (s_pre.mode & GR_NESTED) {
52679+ userp = s_pre.prev;
52680+ continue;
52681+ }
52682+
52683+ ret = do_copy_user_subj(userp, role);
52684+
52685+ err = PTR_ERR(ret);
52686+ if (IS_ERR(ret))
52687+ return err;
52688+
52689+ insert_acl_subj_label(ret, role);
52690+
52691+ userp = s_pre.prev;
52692+ }
52693+
52694+ return 0;
52695+}
52696+
52697+static int
52698+copy_user_acl(struct gr_arg *arg)
52699+{
52700+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
52701+ struct sprole_pw *sptmp;
52702+ struct gr_hash_struct *ghash;
52703+ uid_t *domainlist;
52704+ unsigned int r_num;
52705+ unsigned int len;
52706+ char *tmp;
52707+ int err = 0;
52708+ __u16 i;
52709+ __u32 num_subjs;
52710+
52711+ /* we need a default and kernel role */
52712+ if (arg->role_db.num_roles < 2)
52713+ return -EINVAL;
52714+
52715+ /* copy special role authentication info from userspace */
52716+
52717+ num_sprole_pws = arg->num_sprole_pws;
52718+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
52719+
52720+ if (!acl_special_roles && num_sprole_pws)
52721+ return -ENOMEM;
52722+
52723+ for (i = 0; i < num_sprole_pws; i++) {
52724+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
52725+ if (!sptmp)
52726+ return -ENOMEM;
52727+ if (copy_from_user(sptmp, arg->sprole_pws + i,
52728+ sizeof (struct sprole_pw)))
52729+ return -EFAULT;
52730+
52731+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
52732+
52733+ if (!len || len >= GR_SPROLE_LEN)
52734+ return -EINVAL;
52735+
52736+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52737+ return -ENOMEM;
52738+
52739+ if (copy_from_user(tmp, sptmp->rolename, len))
52740+ return -EFAULT;
52741+
52742+ tmp[len-1] = '\0';
52743+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52744+ printk(KERN_ALERT "Copying special role %s\n", tmp);
52745+#endif
52746+ sptmp->rolename = tmp;
52747+ acl_special_roles[i] = sptmp;
52748+ }
52749+
52750+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
52751+
52752+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
52753+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
52754+
52755+ if (!r_tmp)
52756+ return -ENOMEM;
52757+
52758+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
52759+ sizeof (struct acl_role_label *)))
52760+ return -EFAULT;
52761+
52762+ if (copy_from_user(r_tmp, r_utmp2,
52763+ sizeof (struct acl_role_label)))
52764+ return -EFAULT;
52765+
52766+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
52767+
52768+ if (!len || len >= PATH_MAX)
52769+ return -EINVAL;
52770+
52771+ if ((tmp = (char *) acl_alloc(len)) == NULL)
52772+ return -ENOMEM;
52773+
52774+ if (copy_from_user(tmp, r_tmp->rolename, len))
52775+ return -EFAULT;
52776+
52777+ tmp[len-1] = '\0';
52778+ r_tmp->rolename = tmp;
52779+
52780+ if (!strcmp(r_tmp->rolename, "default")
52781+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
52782+ default_role = r_tmp;
52783+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
52784+ kernel_role = r_tmp;
52785+ }
52786+
52787+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
52788+ return -ENOMEM;
52789+
52790+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
52791+ return -EFAULT;
52792+
52793+ r_tmp->hash = ghash;
52794+
52795+ num_subjs = count_user_subjs(r_tmp->hash->first);
52796+
52797+ r_tmp->subj_hash_size = num_subjs;
52798+ r_tmp->subj_hash =
52799+ (struct acl_subject_label **)
52800+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
52801+
52802+ if (!r_tmp->subj_hash)
52803+ return -ENOMEM;
52804+
52805+ err = copy_user_allowedips(r_tmp);
52806+ if (err)
52807+ return err;
52808+
52809+ /* copy domain info */
52810+ if (r_tmp->domain_children != NULL) {
52811+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
52812+ if (domainlist == NULL)
52813+ return -ENOMEM;
52814+
52815+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
52816+ return -EFAULT;
52817+
52818+ r_tmp->domain_children = domainlist;
52819+ }
52820+
52821+ err = copy_user_transitions(r_tmp);
52822+ if (err)
52823+ return err;
52824+
52825+ memset(r_tmp->subj_hash, 0,
52826+ r_tmp->subj_hash_size *
52827+ sizeof (struct acl_subject_label *));
52828+
52829+ err = copy_user_subjs(r_tmp->hash->first, r_tmp);
52830+
52831+ if (err)
52832+ return err;
52833+
52834+ /* set nested subject list to null */
52835+ r_tmp->hash->first = NULL;
52836+
52837+ insert_acl_role_label(r_tmp);
52838+ }
52839+
52840+ if (default_role == NULL || kernel_role == NULL)
52841+ return -EINVAL;
52842+
52843+ return err;
52844+}
52845+
52846+static int
52847+gracl_init(struct gr_arg *args)
52848+{
52849+ int error = 0;
52850+
52851+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
52852+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
52853+
52854+ if (init_variables(args)) {
52855+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
52856+ error = -ENOMEM;
52857+ free_variables();
52858+ goto out;
52859+ }
52860+
52861+ error = copy_user_acl(args);
52862+ free_init_variables();
52863+ if (error) {
52864+ free_variables();
52865+ goto out;
52866+ }
52867+
52868+ if ((error = gr_set_acls(0))) {
52869+ free_variables();
52870+ goto out;
52871+ }
52872+
52873+ pax_open_kernel();
52874+ gr_status |= GR_READY;
52875+ pax_close_kernel();
52876+
52877+ out:
52878+ return error;
52879+}
52880+
52881+/* derived from glibc fnmatch() 0: match, 1: no match*/
52882+
52883+static int
52884+glob_match(const char *p, const char *n)
52885+{
52886+ char c;
52887+
52888+ while ((c = *p++) != '\0') {
52889+ switch (c) {
52890+ case '?':
52891+ if (*n == '\0')
52892+ return 1;
52893+ else if (*n == '/')
52894+ return 1;
52895+ break;
52896+ case '\\':
52897+ if (*n != c)
52898+ return 1;
52899+ break;
52900+ case '*':
52901+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
52902+ if (*n == '/')
52903+ return 1;
52904+ else if (c == '?') {
52905+ if (*n == '\0')
52906+ return 1;
52907+ else
52908+ ++n;
52909+ }
52910+ }
52911+ if (c == '\0') {
52912+ return 0;
52913+ } else {
52914+ const char *endp;
52915+
52916+ if ((endp = strchr(n, '/')) == NULL)
52917+ endp = n + strlen(n);
52918+
52919+ if (c == '[') {
52920+ for (--p; n < endp; ++n)
52921+ if (!glob_match(p, n))
52922+ return 0;
52923+ } else if (c == '/') {
52924+ while (*n != '\0' && *n != '/')
52925+ ++n;
52926+ if (*n == '/' && !glob_match(p, n + 1))
52927+ return 0;
52928+ } else {
52929+ for (--p; n < endp; ++n)
52930+ if (*n == c && !glob_match(p, n))
52931+ return 0;
52932+ }
52933+
52934+ return 1;
52935+ }
52936+ case '[':
52937+ {
52938+ int not;
52939+ char cold;
52940+
52941+ if (*n == '\0' || *n == '/')
52942+ return 1;
52943+
52944+ not = (*p == '!' || *p == '^');
52945+ if (not)
52946+ ++p;
52947+
52948+ c = *p++;
52949+ for (;;) {
52950+ unsigned char fn = (unsigned char)*n;
52951+
52952+ if (c == '\0')
52953+ return 1;
52954+ else {
52955+ if (c == fn)
52956+ goto matched;
52957+ cold = c;
52958+ c = *p++;
52959+
52960+ if (c == '-' && *p != ']') {
52961+ unsigned char cend = *p++;
52962+
52963+ if (cend == '\0')
52964+ return 1;
52965+
52966+ if (cold <= fn && fn <= cend)
52967+ goto matched;
52968+
52969+ c = *p++;
52970+ }
52971+ }
52972+
52973+ if (c == ']')
52974+ break;
52975+ }
52976+ if (!not)
52977+ return 1;
52978+ break;
52979+ matched:
52980+ while (c != ']') {
52981+ if (c == '\0')
52982+ return 1;
52983+
52984+ c = *p++;
52985+ }
52986+ if (not)
52987+ return 1;
52988+ }
52989+ break;
52990+ default:
52991+ if (c != *n)
52992+ return 1;
52993+ }
52994+
52995+ ++n;
52996+ }
52997+
52998+ if (*n == '\0')
52999+ return 0;
53000+
53001+ if (*n == '/')
53002+ return 0;
53003+
53004+ return 1;
53005+}
53006+
53007+static struct acl_object_label *
53008+chk_glob_label(struct acl_object_label *globbed,
53009+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
53010+{
53011+ struct acl_object_label *tmp;
53012+
53013+ if (*path == NULL)
53014+ *path = gr_to_filename_nolock(dentry, mnt);
53015+
53016+ tmp = globbed;
53017+
53018+ while (tmp) {
53019+ if (!glob_match(tmp->filename, *path))
53020+ return tmp;
53021+ tmp = tmp->next;
53022+ }
53023+
53024+ return NULL;
53025+}
53026+
53027+static struct acl_object_label *
53028+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53029+ const ino_t curr_ino, const dev_t curr_dev,
53030+ const struct acl_subject_label *subj, char **path, const int checkglob)
53031+{
53032+ struct acl_subject_label *tmpsubj;
53033+ struct acl_object_label *retval;
53034+ struct acl_object_label *retval2;
53035+
53036+ tmpsubj = (struct acl_subject_label *) subj;
53037+ read_lock(&gr_inode_lock);
53038+ do {
53039+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
53040+ if (retval) {
53041+ if (checkglob && retval->globbed) {
53042+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
53043+ if (retval2)
53044+ retval = retval2;
53045+ }
53046+ break;
53047+ }
53048+ } while ((tmpsubj = tmpsubj->parent_subject));
53049+ read_unlock(&gr_inode_lock);
53050+
53051+ return retval;
53052+}
53053+
53054+static __inline__ struct acl_object_label *
53055+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53056+ struct dentry *curr_dentry,
53057+ const struct acl_subject_label *subj, char **path, const int checkglob)
53058+{
53059+ int newglob = checkglob;
53060+ ino_t inode;
53061+ dev_t device;
53062+
53063+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
53064+ as we don't want a / * rule to match instead of the / object
53065+ don't do this for create lookups that call this function though, since they're looking up
53066+ on the parent and thus need globbing checks on all paths
53067+ */
53068+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
53069+ newglob = GR_NO_GLOB;
53070+
53071+ spin_lock(&curr_dentry->d_lock);
53072+ inode = curr_dentry->d_inode->i_ino;
53073+ device = __get_dev(curr_dentry);
53074+ spin_unlock(&curr_dentry->d_lock);
53075+
53076+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
53077+}
53078+
53079+static struct acl_object_label *
53080+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53081+ const struct acl_subject_label *subj, char *path, const int checkglob)
53082+{
53083+ struct dentry *dentry = (struct dentry *) l_dentry;
53084+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53085+ struct mount *real_mnt = real_mount(mnt);
53086+ struct acl_object_label *retval;
53087+ struct dentry *parent;
53088+
53089+ write_seqlock(&rename_lock);
53090+ br_read_lock(&vfsmount_lock);
53091+
53092+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
53093+#ifdef CONFIG_NET
53094+ mnt == sock_mnt ||
53095+#endif
53096+#ifdef CONFIG_HUGETLBFS
53097+ (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
53098+#endif
53099+ /* ignore Eric Biederman */
53100+ IS_PRIVATE(l_dentry->d_inode))) {
53101+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
53102+ goto out;
53103+ }
53104+
53105+ for (;;) {
53106+ if (dentry == real_root.dentry && mnt == real_root.mnt)
53107+ break;
53108+
53109+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53110+ if (!mnt_has_parent(real_mnt))
53111+ break;
53112+
53113+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53114+ if (retval != NULL)
53115+ goto out;
53116+
53117+ dentry = real_mnt->mnt_mountpoint;
53118+ real_mnt = real_mnt->mnt_parent;
53119+ mnt = &real_mnt->mnt;
53120+ continue;
53121+ }
53122+
53123+ parent = dentry->d_parent;
53124+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53125+ if (retval != NULL)
53126+ goto out;
53127+
53128+ dentry = parent;
53129+ }
53130+
53131+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53132+
53133+ /* real_root is pinned so we don't have to hold a reference */
53134+ if (retval == NULL)
53135+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
53136+out:
53137+ br_read_unlock(&vfsmount_lock);
53138+ write_sequnlock(&rename_lock);
53139+
53140+ BUG_ON(retval == NULL);
53141+
53142+ return retval;
53143+}
53144+
53145+static __inline__ struct acl_object_label *
53146+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53147+ const struct acl_subject_label *subj)
53148+{
53149+ char *path = NULL;
53150+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
53151+}
53152+
53153+static __inline__ struct acl_object_label *
53154+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53155+ const struct acl_subject_label *subj)
53156+{
53157+ char *path = NULL;
53158+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
53159+}
53160+
53161+static __inline__ struct acl_object_label *
53162+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53163+ const struct acl_subject_label *subj, char *path)
53164+{
53165+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
53166+}
53167+
53168+static struct acl_subject_label *
53169+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53170+ const struct acl_role_label *role)
53171+{
53172+ struct dentry *dentry = (struct dentry *) l_dentry;
53173+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53174+ struct mount *real_mnt = real_mount(mnt);
53175+ struct acl_subject_label *retval;
53176+ struct dentry *parent;
53177+
53178+ write_seqlock(&rename_lock);
53179+ br_read_lock(&vfsmount_lock);
53180+
53181+ for (;;) {
53182+ if (dentry == real_root.dentry && mnt == real_root.mnt)
53183+ break;
53184+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53185+ if (!mnt_has_parent(real_mnt))
53186+ break;
53187+
53188+ spin_lock(&dentry->d_lock);
53189+ read_lock(&gr_inode_lock);
53190+ retval =
53191+ lookup_acl_subj_label(dentry->d_inode->i_ino,
53192+ __get_dev(dentry), role);
53193+ read_unlock(&gr_inode_lock);
53194+ spin_unlock(&dentry->d_lock);
53195+ if (retval != NULL)
53196+ goto out;
53197+
53198+ dentry = real_mnt->mnt_mountpoint;
53199+ real_mnt = real_mnt->mnt_parent;
53200+ mnt = &real_mnt->mnt;
53201+ continue;
53202+ }
53203+
53204+ spin_lock(&dentry->d_lock);
53205+ read_lock(&gr_inode_lock);
53206+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53207+ __get_dev(dentry), role);
53208+ read_unlock(&gr_inode_lock);
53209+ parent = dentry->d_parent;
53210+ spin_unlock(&dentry->d_lock);
53211+
53212+ if (retval != NULL)
53213+ goto out;
53214+
53215+ dentry = parent;
53216+ }
53217+
53218+ spin_lock(&dentry->d_lock);
53219+ read_lock(&gr_inode_lock);
53220+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53221+ __get_dev(dentry), role);
53222+ read_unlock(&gr_inode_lock);
53223+ spin_unlock(&dentry->d_lock);
53224+
53225+ if (unlikely(retval == NULL)) {
53226+ /* real_root is pinned, we don't need to hold a reference */
53227+ read_lock(&gr_inode_lock);
53228+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
53229+ __get_dev(real_root.dentry), role);
53230+ read_unlock(&gr_inode_lock);
53231+ }
53232+out:
53233+ br_read_unlock(&vfsmount_lock);
53234+ write_sequnlock(&rename_lock);
53235+
53236+ BUG_ON(retval == NULL);
53237+
53238+ return retval;
53239+}
53240+
53241+static void
53242+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
53243+{
53244+ struct task_struct *task = current;
53245+ const struct cred *cred = current_cred();
53246+
53247+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53248+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53249+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53250+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53251+
53252+ return;
53253+}
53254+
53255+static void
53256+gr_log_learn_id_change(const char type, const unsigned int real,
53257+ const unsigned int effective, const unsigned int fs)
53258+{
53259+ struct task_struct *task = current;
53260+ const struct cred *cred = current_cred();
53261+
53262+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53263+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53264+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53265+ type, real, effective, fs, &task->signal->saved_ip);
53266+
53267+ return;
53268+}
53269+
53270+__u32
53271+gr_search_file(const struct dentry * dentry, const __u32 mode,
53272+ const struct vfsmount * mnt)
53273+{
53274+ __u32 retval = mode;
53275+ struct acl_subject_label *curracl;
53276+ struct acl_object_label *currobj;
53277+
53278+ if (unlikely(!(gr_status & GR_READY)))
53279+ return (mode & ~GR_AUDITS);
53280+
53281+ curracl = current->acl;
53282+
53283+ currobj = chk_obj_label(dentry, mnt, curracl);
53284+ retval = currobj->mode & mode;
53285+
53286+ /* if we're opening a specified transfer file for writing
53287+ (e.g. /dev/initctl), then transfer our role to init
53288+ */
53289+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53290+ current->role->roletype & GR_ROLE_PERSIST)) {
53291+ struct task_struct *task = init_pid_ns.child_reaper;
53292+
53293+ if (task->role != current->role) {
53294+ task->acl_sp_role = 0;
53295+ task->acl_role_id = current->acl_role_id;
53296+ task->role = current->role;
53297+ rcu_read_lock();
53298+ read_lock(&grsec_exec_file_lock);
53299+ gr_apply_subject_to_task(task);
53300+ read_unlock(&grsec_exec_file_lock);
53301+ rcu_read_unlock();
53302+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53303+ }
53304+ }
53305+
53306+ if (unlikely
53307+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53308+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53309+ __u32 new_mode = mode;
53310+
53311+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53312+
53313+ retval = new_mode;
53314+
53315+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53316+ new_mode |= GR_INHERIT;
53317+
53318+ if (!(mode & GR_NOLEARN))
53319+ gr_log_learn(dentry, mnt, new_mode);
53320+ }
53321+
53322+ return retval;
53323+}
53324+
53325+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
53326+ const struct dentry *parent,
53327+ const struct vfsmount *mnt)
53328+{
53329+ struct name_entry *match;
53330+ struct acl_object_label *matchpo;
53331+ struct acl_subject_label *curracl;
53332+ char *path;
53333+
53334+ if (unlikely(!(gr_status & GR_READY)))
53335+ return NULL;
53336+
53337+ preempt_disable();
53338+ path = gr_to_filename_rbac(new_dentry, mnt);
53339+ match = lookup_name_entry_create(path);
53340+
53341+ curracl = current->acl;
53342+
53343+ if (match) {
53344+ read_lock(&gr_inode_lock);
53345+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53346+ read_unlock(&gr_inode_lock);
53347+
53348+ if (matchpo) {
53349+ preempt_enable();
53350+ return matchpo;
53351+ }
53352+ }
53353+
53354+ // lookup parent
53355+
53356+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53357+
53358+ preempt_enable();
53359+ return matchpo;
53360+}
53361+
53362+__u32
53363+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53364+ const struct vfsmount * mnt, const __u32 mode)
53365+{
53366+ struct acl_object_label *matchpo;
53367+ __u32 retval;
53368+
53369+ if (unlikely(!(gr_status & GR_READY)))
53370+ return (mode & ~GR_AUDITS);
53371+
53372+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
53373+
53374+ retval = matchpo->mode & mode;
53375+
53376+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53377+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53378+ __u32 new_mode = mode;
53379+
53380+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53381+
53382+ gr_log_learn(new_dentry, mnt, new_mode);
53383+ return new_mode;
53384+ }
53385+
53386+ return retval;
53387+}
53388+
53389+__u32
53390+gr_check_link(const struct dentry * new_dentry,
53391+ const struct dentry * parent_dentry,
53392+ const struct vfsmount * parent_mnt,
53393+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53394+{
53395+ struct acl_object_label *obj;
53396+ __u32 oldmode, newmode;
53397+ __u32 needmode;
53398+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
53399+ GR_DELETE | GR_INHERIT;
53400+
53401+ if (unlikely(!(gr_status & GR_READY)))
53402+ return (GR_CREATE | GR_LINK);
53403+
53404+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53405+ oldmode = obj->mode;
53406+
53407+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
53408+ newmode = obj->mode;
53409+
53410+ needmode = newmode & checkmodes;
53411+
53412+ // old name for hardlink must have at least the permissions of the new name
53413+ if ((oldmode & needmode) != needmode)
53414+ goto bad;
53415+
53416+ // if old name had restrictions/auditing, make sure the new name does as well
53417+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53418+
53419+ // don't allow hardlinking of suid/sgid/fcapped files without permission
53420+ if (is_privileged_binary(old_dentry))
53421+ needmode |= GR_SETID;
53422+
53423+ if ((newmode & needmode) != needmode)
53424+ goto bad;
53425+
53426+ // enforce minimum permissions
53427+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53428+ return newmode;
53429+bad:
53430+ needmode = oldmode;
53431+ if (is_privileged_binary(old_dentry))
53432+ needmode |= GR_SETID;
53433+
53434+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53435+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
53436+ return (GR_CREATE | GR_LINK);
53437+ } else if (newmode & GR_SUPPRESS)
53438+ return GR_SUPPRESS;
53439+ else
53440+ return 0;
53441+}
53442+
53443+int
53444+gr_check_hidden_task(const struct task_struct *task)
53445+{
53446+ if (unlikely(!(gr_status & GR_READY)))
53447+ return 0;
53448+
53449+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53450+ return 1;
53451+
53452+ return 0;
53453+}
53454+
53455+int
53456+gr_check_protected_task(const struct task_struct *task)
53457+{
53458+ if (unlikely(!(gr_status & GR_READY) || !task))
53459+ return 0;
53460+
53461+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53462+ task->acl != current->acl)
53463+ return 1;
53464+
53465+ return 0;
53466+}
53467+
53468+int
53469+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53470+{
53471+ struct task_struct *p;
53472+ int ret = 0;
53473+
53474+ if (unlikely(!(gr_status & GR_READY) || !pid))
53475+ return ret;
53476+
53477+ read_lock(&tasklist_lock);
53478+ do_each_pid_task(pid, type, p) {
53479+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53480+ p->acl != current->acl) {
53481+ ret = 1;
53482+ goto out;
53483+ }
53484+ } while_each_pid_task(pid, type, p);
53485+out:
53486+ read_unlock(&tasklist_lock);
53487+
53488+ return ret;
53489+}
53490+
53491+void
53492+gr_copy_label(struct task_struct *tsk)
53493+{
53494+ tsk->signal->used_accept = 0;
53495+ tsk->acl_sp_role = 0;
53496+ tsk->acl_role_id = current->acl_role_id;
53497+ tsk->acl = current->acl;
53498+ tsk->role = current->role;
53499+ tsk->signal->curr_ip = current->signal->curr_ip;
53500+ tsk->signal->saved_ip = current->signal->saved_ip;
53501+ if (current->exec_file)
53502+ get_file(current->exec_file);
53503+ tsk->exec_file = current->exec_file;
53504+ tsk->is_writable = current->is_writable;
53505+ if (unlikely(current->signal->used_accept)) {
53506+ current->signal->curr_ip = 0;
53507+ current->signal->saved_ip = 0;
53508+ }
53509+
53510+ return;
53511+}
53512+
53513+static void
53514+gr_set_proc_res(struct task_struct *task)
53515+{
53516+ struct acl_subject_label *proc;
53517+ unsigned short i;
53518+
53519+ proc = task->acl;
53520+
53521+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
53522+ return;
53523+
53524+ for (i = 0; i < RLIM_NLIMITS; i++) {
53525+ if (!(proc->resmask & (1 << i)))
53526+ continue;
53527+
53528+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
53529+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
53530+ }
53531+
53532+ return;
53533+}
53534+
53535+extern int __gr_process_user_ban(struct user_struct *user);
53536+
53537+int
53538+gr_check_user_change(int real, int effective, int fs)
53539+{
53540+ unsigned int i;
53541+ __u16 num;
53542+ uid_t *uidlist;
53543+ int curuid;
53544+ int realok = 0;
53545+ int effectiveok = 0;
53546+ int fsok = 0;
53547+
53548+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
53549+ struct user_struct *user;
53550+
53551+ if (real == -1)
53552+ goto skipit;
53553+
53554+ user = find_user(real);
53555+ if (user == NULL)
53556+ goto skipit;
53557+
53558+ if (__gr_process_user_ban(user)) {
53559+ /* for find_user */
53560+ free_uid(user);
53561+ return 1;
53562+ }
53563+
53564+ /* for find_user */
53565+ free_uid(user);
53566+
53567+skipit:
53568+#endif
53569+
53570+ if (unlikely(!(gr_status & GR_READY)))
53571+ return 0;
53572+
53573+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53574+ gr_log_learn_id_change('u', real, effective, fs);
53575+
53576+ num = current->acl->user_trans_num;
53577+ uidlist = current->acl->user_transitions;
53578+
53579+ if (uidlist == NULL)
53580+ return 0;
53581+
53582+ if (real == -1)
53583+ realok = 1;
53584+ if (effective == -1)
53585+ effectiveok = 1;
53586+ if (fs == -1)
53587+ fsok = 1;
53588+
53589+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
53590+ for (i = 0; i < num; i++) {
53591+ curuid = (int)uidlist[i];
53592+ if (real == curuid)
53593+ realok = 1;
53594+ if (effective == curuid)
53595+ effectiveok = 1;
53596+ if (fs == curuid)
53597+ fsok = 1;
53598+ }
53599+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
53600+ for (i = 0; i < num; i++) {
53601+ curuid = (int)uidlist[i];
53602+ if (real == curuid)
53603+ break;
53604+ if (effective == curuid)
53605+ break;
53606+ if (fs == curuid)
53607+ break;
53608+ }
53609+ /* not in deny list */
53610+ if (i == num) {
53611+ realok = 1;
53612+ effectiveok = 1;
53613+ fsok = 1;
53614+ }
53615+ }
53616+
53617+ if (realok && effectiveok && fsok)
53618+ return 0;
53619+ else {
53620+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53621+ return 1;
53622+ }
53623+}
53624+
53625+int
53626+gr_check_group_change(int real, int effective, int fs)
53627+{
53628+ unsigned int i;
53629+ __u16 num;
53630+ gid_t *gidlist;
53631+ int curgid;
53632+ int realok = 0;
53633+ int effectiveok = 0;
53634+ int fsok = 0;
53635+
53636+ if (unlikely(!(gr_status & GR_READY)))
53637+ return 0;
53638+
53639+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53640+ gr_log_learn_id_change('g', real, effective, fs);
53641+
53642+ num = current->acl->group_trans_num;
53643+ gidlist = current->acl->group_transitions;
53644+
53645+ if (gidlist == NULL)
53646+ return 0;
53647+
53648+ if (real == -1)
53649+ realok = 1;
53650+ if (effective == -1)
53651+ effectiveok = 1;
53652+ if (fs == -1)
53653+ fsok = 1;
53654+
53655+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
53656+ for (i = 0; i < num; i++) {
53657+ curgid = (int)gidlist[i];
53658+ if (real == curgid)
53659+ realok = 1;
53660+ if (effective == curgid)
53661+ effectiveok = 1;
53662+ if (fs == curgid)
53663+ fsok = 1;
53664+ }
53665+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
53666+ for (i = 0; i < num; i++) {
53667+ curgid = (int)gidlist[i];
53668+ if (real == curgid)
53669+ break;
53670+ if (effective == curgid)
53671+ break;
53672+ if (fs == curgid)
53673+ break;
53674+ }
53675+ /* not in deny list */
53676+ if (i == num) {
53677+ realok = 1;
53678+ effectiveok = 1;
53679+ fsok = 1;
53680+ }
53681+ }
53682+
53683+ if (realok && effectiveok && fsok)
53684+ return 0;
53685+ else {
53686+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53687+ return 1;
53688+ }
53689+}
53690+
53691+extern int gr_acl_is_capable(const int cap);
53692+
53693+void
53694+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
53695+{
53696+ struct acl_role_label *role = task->role;
53697+ struct acl_subject_label *subj = NULL;
53698+ struct acl_object_label *obj;
53699+ struct file *filp;
53700+
53701+ if (unlikely(!(gr_status & GR_READY)))
53702+ return;
53703+
53704+ filp = task->exec_file;
53705+
53706+ /* kernel process, we'll give them the kernel role */
53707+ if (unlikely(!filp)) {
53708+ task->role = kernel_role;
53709+ task->acl = kernel_role->root_label;
53710+ return;
53711+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
53712+ role = lookup_acl_role_label(task, uid, gid);
53713+
53714+ /* don't change the role if we're not a privileged process */
53715+ if (role && task->role != role &&
53716+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
53717+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
53718+ return;
53719+
53720+ /* perform subject lookup in possibly new role
53721+ we can use this result below in the case where role == task->role
53722+ */
53723+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
53724+
53725+ /* if we changed uid/gid, but result in the same role
53726+ and are using inheritance, don't lose the inherited subject
53727+ if current subject is other than what normal lookup
53728+ would result in, we arrived via inheritance, don't
53729+ lose subject
53730+ */
53731+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
53732+ (subj == task->acl)))
53733+ task->acl = subj;
53734+
53735+ task->role = role;
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(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53742+ if (unlikely(obj->mode & GR_WRITE))
53743+ task->is_writable = 1;
53744+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53745+ if (unlikely(obj->mode & GR_WRITE))
53746+ task->is_writable = 1;
53747+
53748+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53749+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53750+#endif
53751+
53752+ gr_set_proc_res(task);
53753+
53754+ return;
53755+}
53756+
53757+int
53758+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
53759+ const int unsafe_flags)
53760+{
53761+ struct task_struct *task = current;
53762+ struct acl_subject_label *newacl;
53763+ struct acl_object_label *obj;
53764+ __u32 retmode;
53765+
53766+ if (unlikely(!(gr_status & GR_READY)))
53767+ return 0;
53768+
53769+ newacl = chk_subj_label(dentry, mnt, task->role);
53770+
53771+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
53772+ did an exec
53773+ */
53774+ rcu_read_lock();
53775+ read_lock(&tasklist_lock);
53776+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
53777+ (task->parent->acl->mode & GR_POVERRIDE))) {
53778+ read_unlock(&tasklist_lock);
53779+ rcu_read_unlock();
53780+ goto skip_check;
53781+ }
53782+ read_unlock(&tasklist_lock);
53783+ rcu_read_unlock();
53784+
53785+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
53786+ !(task->role->roletype & GR_ROLE_GOD) &&
53787+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
53788+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53789+ if (unsafe_flags & LSM_UNSAFE_SHARE)
53790+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
53791+ else
53792+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
53793+ return -EACCES;
53794+ }
53795+
53796+skip_check:
53797+
53798+ obj = chk_obj_label(dentry, mnt, task->acl);
53799+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
53800+
53801+ if (!(task->acl->mode & GR_INHERITLEARN) &&
53802+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
53803+ if (obj->nested)
53804+ task->acl = obj->nested;
53805+ else
53806+ task->acl = newacl;
53807+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
53808+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
53809+
53810+ task->is_writable = 0;
53811+
53812+ /* ignore additional mmap checks for processes that are writable
53813+ by the default ACL */
53814+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
53815+ if (unlikely(obj->mode & GR_WRITE))
53816+ task->is_writable = 1;
53817+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
53818+ if (unlikely(obj->mode & GR_WRITE))
53819+ task->is_writable = 1;
53820+
53821+ gr_set_proc_res(task);
53822+
53823+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53824+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53825+#endif
53826+ return 0;
53827+}
53828+
53829+/* always called with valid inodev ptr */
53830+static void
53831+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
53832+{
53833+ struct acl_object_label *matchpo;
53834+ struct acl_subject_label *matchps;
53835+ struct acl_subject_label *subj;
53836+ struct acl_role_label *role;
53837+ unsigned int x;
53838+
53839+ FOR_EACH_ROLE_START(role)
53840+ FOR_EACH_SUBJECT_START(role, subj, x)
53841+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
53842+ matchpo->mode |= GR_DELETED;
53843+ FOR_EACH_SUBJECT_END(subj,x)
53844+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
53845+ if (subj->inode == ino && subj->device == dev)
53846+ subj->mode |= GR_DELETED;
53847+ FOR_EACH_NESTED_SUBJECT_END(subj)
53848+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
53849+ matchps->mode |= GR_DELETED;
53850+ FOR_EACH_ROLE_END(role)
53851+
53852+ inodev->nentry->deleted = 1;
53853+
53854+ return;
53855+}
53856+
53857+void
53858+gr_handle_delete(const ino_t ino, const dev_t dev)
53859+{
53860+ struct inodev_entry *inodev;
53861+
53862+ if (unlikely(!(gr_status & GR_READY)))
53863+ return;
53864+
53865+ write_lock(&gr_inode_lock);
53866+ inodev = lookup_inodev_entry(ino, dev);
53867+ if (inodev != NULL)
53868+ do_handle_delete(inodev, ino, dev);
53869+ write_unlock(&gr_inode_lock);
53870+
53871+ return;
53872+}
53873+
53874+static void
53875+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
53876+ const ino_t newinode, const dev_t newdevice,
53877+ struct acl_subject_label *subj)
53878+{
53879+ unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
53880+ struct acl_object_label *match;
53881+
53882+ match = subj->obj_hash[index];
53883+
53884+ while (match && (match->inode != oldinode ||
53885+ match->device != olddevice ||
53886+ !(match->mode & GR_DELETED)))
53887+ match = match->next;
53888+
53889+ if (match && (match->inode == oldinode)
53890+ && (match->device == olddevice)
53891+ && (match->mode & GR_DELETED)) {
53892+ if (match->prev == NULL) {
53893+ subj->obj_hash[index] = match->next;
53894+ if (match->next != NULL)
53895+ match->next->prev = NULL;
53896+ } else {
53897+ match->prev->next = match->next;
53898+ if (match->next != NULL)
53899+ match->next->prev = match->prev;
53900+ }
53901+ match->prev = NULL;
53902+ match->next = NULL;
53903+ match->inode = newinode;
53904+ match->device = newdevice;
53905+ match->mode &= ~GR_DELETED;
53906+
53907+ insert_acl_obj_label(match, subj);
53908+ }
53909+
53910+ return;
53911+}
53912+
53913+static void
53914+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
53915+ const ino_t newinode, const dev_t newdevice,
53916+ struct acl_role_label *role)
53917+{
53918+ unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
53919+ struct acl_subject_label *match;
53920+
53921+ match = role->subj_hash[index];
53922+
53923+ while (match && (match->inode != oldinode ||
53924+ match->device != olddevice ||
53925+ !(match->mode & GR_DELETED)))
53926+ match = match->next;
53927+
53928+ if (match && (match->inode == oldinode)
53929+ && (match->device == olddevice)
53930+ && (match->mode & GR_DELETED)) {
53931+ if (match->prev == NULL) {
53932+ role->subj_hash[index] = match->next;
53933+ if (match->next != NULL)
53934+ match->next->prev = NULL;
53935+ } else {
53936+ match->prev->next = match->next;
53937+ if (match->next != NULL)
53938+ match->next->prev = match->prev;
53939+ }
53940+ match->prev = NULL;
53941+ match->next = NULL;
53942+ match->inode = newinode;
53943+ match->device = newdevice;
53944+ match->mode &= ~GR_DELETED;
53945+
53946+ insert_acl_subj_label(match, role);
53947+ }
53948+
53949+ return;
53950+}
53951+
53952+static void
53953+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
53954+ const ino_t newinode, const dev_t newdevice)
53955+{
53956+ unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
53957+ struct inodev_entry *match;
53958+
53959+ match = inodev_set.i_hash[index];
53960+
53961+ while (match && (match->nentry->inode != oldinode ||
53962+ match->nentry->device != olddevice || !match->nentry->deleted))
53963+ match = match->next;
53964+
53965+ if (match && (match->nentry->inode == oldinode)
53966+ && (match->nentry->device == olddevice) &&
53967+ match->nentry->deleted) {
53968+ if (match->prev == NULL) {
53969+ inodev_set.i_hash[index] = match->next;
53970+ if (match->next != NULL)
53971+ match->next->prev = NULL;
53972+ } else {
53973+ match->prev->next = match->next;
53974+ if (match->next != NULL)
53975+ match->next->prev = match->prev;
53976+ }
53977+ match->prev = NULL;
53978+ match->next = NULL;
53979+ match->nentry->inode = newinode;
53980+ match->nentry->device = newdevice;
53981+ match->nentry->deleted = 0;
53982+
53983+ insert_inodev_entry(match);
53984+ }
53985+
53986+ return;
53987+}
53988+
53989+static void
53990+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
53991+{
53992+ struct acl_subject_label *subj;
53993+ struct acl_role_label *role;
53994+ unsigned int x;
53995+
53996+ FOR_EACH_ROLE_START(role)
53997+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
53998+
53999+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
54000+ if ((subj->inode == ino) && (subj->device == dev)) {
54001+ subj->inode = ino;
54002+ subj->device = dev;
54003+ }
54004+ FOR_EACH_NESTED_SUBJECT_END(subj)
54005+ FOR_EACH_SUBJECT_START(role, subj, x)
54006+ update_acl_obj_label(matchn->inode, matchn->device,
54007+ ino, dev, subj);
54008+ FOR_EACH_SUBJECT_END(subj,x)
54009+ FOR_EACH_ROLE_END(role)
54010+
54011+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
54012+
54013+ return;
54014+}
54015+
54016+static void
54017+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
54018+ const struct vfsmount *mnt)
54019+{
54020+ ino_t ino = dentry->d_inode->i_ino;
54021+ dev_t dev = __get_dev(dentry);
54022+
54023+ __do_handle_create(matchn, ino, dev);
54024+
54025+ return;
54026+}
54027+
54028+void
54029+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54030+{
54031+ struct name_entry *matchn;
54032+
54033+ if (unlikely(!(gr_status & GR_READY)))
54034+ return;
54035+
54036+ preempt_disable();
54037+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
54038+
54039+ if (unlikely((unsigned long)matchn)) {
54040+ write_lock(&gr_inode_lock);
54041+ do_handle_create(matchn, dentry, mnt);
54042+ write_unlock(&gr_inode_lock);
54043+ }
54044+ preempt_enable();
54045+
54046+ return;
54047+}
54048+
54049+void
54050+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
54051+{
54052+ struct name_entry *matchn;
54053+
54054+ if (unlikely(!(gr_status & GR_READY)))
54055+ return;
54056+
54057+ preempt_disable();
54058+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
54059+
54060+ if (unlikely((unsigned long)matchn)) {
54061+ write_lock(&gr_inode_lock);
54062+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
54063+ write_unlock(&gr_inode_lock);
54064+ }
54065+ preempt_enable();
54066+
54067+ return;
54068+}
54069+
54070+void
54071+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54072+ struct dentry *old_dentry,
54073+ struct dentry *new_dentry,
54074+ struct vfsmount *mnt, const __u8 replace)
54075+{
54076+ struct name_entry *matchn;
54077+ struct inodev_entry *inodev;
54078+ struct inode *inode = new_dentry->d_inode;
54079+ ino_t old_ino = old_dentry->d_inode->i_ino;
54080+ dev_t old_dev = __get_dev(old_dentry);
54081+
54082+ /* vfs_rename swaps the name and parent link for old_dentry and
54083+ new_dentry
54084+ at this point, old_dentry has the new name, parent link, and inode
54085+ for the renamed file
54086+ if a file is being replaced by a rename, new_dentry has the inode
54087+ and name for the replaced file
54088+ */
54089+
54090+ if (unlikely(!(gr_status & GR_READY)))
54091+ return;
54092+
54093+ preempt_disable();
54094+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
54095+
54096+ /* we wouldn't have to check d_inode if it weren't for
54097+ NFS silly-renaming
54098+ */
54099+
54100+ write_lock(&gr_inode_lock);
54101+ if (unlikely(replace && inode)) {
54102+ ino_t new_ino = inode->i_ino;
54103+ dev_t new_dev = __get_dev(new_dentry);
54104+
54105+ inodev = lookup_inodev_entry(new_ino, new_dev);
54106+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
54107+ do_handle_delete(inodev, new_ino, new_dev);
54108+ }
54109+
54110+ inodev = lookup_inodev_entry(old_ino, old_dev);
54111+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
54112+ do_handle_delete(inodev, old_ino, old_dev);
54113+
54114+ if (unlikely((unsigned long)matchn))
54115+ do_handle_create(matchn, old_dentry, mnt);
54116+
54117+ write_unlock(&gr_inode_lock);
54118+ preempt_enable();
54119+
54120+ return;
54121+}
54122+
54123+static int
54124+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
54125+ unsigned char **sum)
54126+{
54127+ struct acl_role_label *r;
54128+ struct role_allowed_ip *ipp;
54129+ struct role_transition *trans;
54130+ unsigned int i;
54131+ int found = 0;
54132+ u32 curr_ip = current->signal->curr_ip;
54133+
54134+ current->signal->saved_ip = curr_ip;
54135+
54136+ /* check transition table */
54137+
54138+ for (trans = current->role->transitions; trans; trans = trans->next) {
54139+ if (!strcmp(rolename, trans->rolename)) {
54140+ found = 1;
54141+ break;
54142+ }
54143+ }
54144+
54145+ if (!found)
54146+ return 0;
54147+
54148+ /* handle special roles that do not require authentication
54149+ and check ip */
54150+
54151+ FOR_EACH_ROLE_START(r)
54152+ if (!strcmp(rolename, r->rolename) &&
54153+ (r->roletype & GR_ROLE_SPECIAL)) {
54154+ found = 0;
54155+ if (r->allowed_ips != NULL) {
54156+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
54157+ if ((ntohl(curr_ip) & ipp->netmask) ==
54158+ (ntohl(ipp->addr) & ipp->netmask))
54159+ found = 1;
54160+ }
54161+ } else
54162+ found = 2;
54163+ if (!found)
54164+ return 0;
54165+
54166+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
54167+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
54168+ *salt = NULL;
54169+ *sum = NULL;
54170+ return 1;
54171+ }
54172+ }
54173+ FOR_EACH_ROLE_END(r)
54174+
54175+ for (i = 0; i < num_sprole_pws; i++) {
54176+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
54177+ *salt = acl_special_roles[i]->salt;
54178+ *sum = acl_special_roles[i]->sum;
54179+ return 1;
54180+ }
54181+ }
54182+
54183+ return 0;
54184+}
54185+
54186+static void
54187+assign_special_role(char *rolename)
54188+{
54189+ struct acl_object_label *obj;
54190+ struct acl_role_label *r;
54191+ struct acl_role_label *assigned = NULL;
54192+ struct task_struct *tsk;
54193+ struct file *filp;
54194+
54195+ FOR_EACH_ROLE_START(r)
54196+ if (!strcmp(rolename, r->rolename) &&
54197+ (r->roletype & GR_ROLE_SPECIAL)) {
54198+ assigned = r;
54199+ break;
54200+ }
54201+ FOR_EACH_ROLE_END(r)
54202+
54203+ if (!assigned)
54204+ return;
54205+
54206+ read_lock(&tasklist_lock);
54207+ read_lock(&grsec_exec_file_lock);
54208+
54209+ tsk = current->real_parent;
54210+ if (tsk == NULL)
54211+ goto out_unlock;
54212+
54213+ filp = tsk->exec_file;
54214+ if (filp == NULL)
54215+ goto out_unlock;
54216+
54217+ tsk->is_writable = 0;
54218+
54219+ tsk->acl_sp_role = 1;
54220+ tsk->acl_role_id = ++acl_sp_role_value;
54221+ tsk->role = assigned;
54222+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
54223+
54224+ /* ignore additional mmap checks for processes that are writable
54225+ by the default ACL */
54226+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54227+ if (unlikely(obj->mode & GR_WRITE))
54228+ tsk->is_writable = 1;
54229+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
54230+ if (unlikely(obj->mode & GR_WRITE))
54231+ tsk->is_writable = 1;
54232+
54233+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54234+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
54235+#endif
54236+
54237+out_unlock:
54238+ read_unlock(&grsec_exec_file_lock);
54239+ read_unlock(&tasklist_lock);
54240+ return;
54241+}
54242+
54243+int gr_check_secure_terminal(struct task_struct *task)
54244+{
54245+ struct task_struct *p, *p2, *p3;
54246+ struct files_struct *files;
54247+ struct fdtable *fdt;
54248+ struct file *our_file = NULL, *file;
54249+ int i;
54250+
54251+ if (task->signal->tty == NULL)
54252+ return 1;
54253+
54254+ files = get_files_struct(task);
54255+ if (files != NULL) {
54256+ rcu_read_lock();
54257+ fdt = files_fdtable(files);
54258+ for (i=0; i < fdt->max_fds; i++) {
54259+ file = fcheck_files(files, i);
54260+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54261+ get_file(file);
54262+ our_file = file;
54263+ }
54264+ }
54265+ rcu_read_unlock();
54266+ put_files_struct(files);
54267+ }
54268+
54269+ if (our_file == NULL)
54270+ return 1;
54271+
54272+ read_lock(&tasklist_lock);
54273+ do_each_thread(p2, p) {
54274+ files = get_files_struct(p);
54275+ if (files == NULL ||
54276+ (p->signal && p->signal->tty == task->signal->tty)) {
54277+ if (files != NULL)
54278+ put_files_struct(files);
54279+ continue;
54280+ }
54281+ rcu_read_lock();
54282+ fdt = files_fdtable(files);
54283+ for (i=0; i < fdt->max_fds; i++) {
54284+ file = fcheck_files(files, i);
54285+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54286+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54287+ p3 = task;
54288+ while (p3->pid > 0) {
54289+ if (p3 == p)
54290+ break;
54291+ p3 = p3->real_parent;
54292+ }
54293+ if (p3 == p)
54294+ break;
54295+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54296+ gr_handle_alertkill(p);
54297+ rcu_read_unlock();
54298+ put_files_struct(files);
54299+ read_unlock(&tasklist_lock);
54300+ fput(our_file);
54301+ return 0;
54302+ }
54303+ }
54304+ rcu_read_unlock();
54305+ put_files_struct(files);
54306+ } while_each_thread(p2, p);
54307+ read_unlock(&tasklist_lock);
54308+
54309+ fput(our_file);
54310+ return 1;
54311+}
54312+
54313+static int gr_rbac_disable(void *unused)
54314+{
54315+ pax_open_kernel();
54316+ gr_status &= ~GR_READY;
54317+ pax_close_kernel();
54318+
54319+ return 0;
54320+}
54321+
54322+ssize_t
54323+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54324+{
54325+ struct gr_arg_wrapper uwrap;
54326+ unsigned char *sprole_salt = NULL;
54327+ unsigned char *sprole_sum = NULL;
54328+ int error = sizeof (struct gr_arg_wrapper);
54329+ int error2 = 0;
54330+
54331+ mutex_lock(&gr_dev_mutex);
54332+
54333+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54334+ error = -EPERM;
54335+ goto out;
54336+ }
54337+
54338+ if (count != sizeof (struct gr_arg_wrapper)) {
54339+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54340+ error = -EINVAL;
54341+ goto out;
54342+ }
54343+
54344+
54345+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54346+ gr_auth_expires = 0;
54347+ gr_auth_attempts = 0;
54348+ }
54349+
54350+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54351+ error = -EFAULT;
54352+ goto out;
54353+ }
54354+
54355+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54356+ error = -EINVAL;
54357+ goto out;
54358+ }
54359+
54360+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54361+ error = -EFAULT;
54362+ goto out;
54363+ }
54364+
54365+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54366+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54367+ time_after(gr_auth_expires, get_seconds())) {
54368+ error = -EBUSY;
54369+ goto out;
54370+ }
54371+
54372+ /* if non-root trying to do anything other than use a special role,
54373+ do not attempt authentication, do not count towards authentication
54374+ locking
54375+ */
54376+
54377+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54378+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54379+ !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
54380+ error = -EPERM;
54381+ goto out;
54382+ }
54383+
54384+ /* ensure pw and special role name are null terminated */
54385+
54386+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54387+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54388+
54389+ /* Okay.
54390+ * We have our enough of the argument structure..(we have yet
54391+ * to copy_from_user the tables themselves) . Copy the tables
54392+ * only if we need them, i.e. for loading operations. */
54393+
54394+ switch (gr_usermode->mode) {
54395+ case GR_STATUS:
54396+ if (gr_status & GR_READY) {
54397+ error = 1;
54398+ if (!gr_check_secure_terminal(current))
54399+ error = 3;
54400+ } else
54401+ error = 2;
54402+ goto out;
54403+ case GR_SHUTDOWN:
54404+ if ((gr_status & GR_READY)
54405+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54406+ stop_machine(gr_rbac_disable, NULL, NULL);
54407+ free_variables();
54408+ memset(gr_usermode, 0, sizeof (struct gr_arg));
54409+ memset(gr_system_salt, 0, GR_SALT_LEN);
54410+ memset(gr_system_sum, 0, GR_SHA_LEN);
54411+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54412+ } else if (gr_status & GR_READY) {
54413+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54414+ error = -EPERM;
54415+ } else {
54416+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54417+ error = -EAGAIN;
54418+ }
54419+ break;
54420+ case GR_ENABLE:
54421+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54422+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54423+ else {
54424+ if (gr_status & GR_READY)
54425+ error = -EAGAIN;
54426+ else
54427+ error = error2;
54428+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54429+ }
54430+ break;
54431+ case GR_RELOAD:
54432+ if (!(gr_status & GR_READY)) {
54433+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54434+ error = -EAGAIN;
54435+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54436+ stop_machine(gr_rbac_disable, NULL, NULL);
54437+ free_variables();
54438+ error2 = gracl_init(gr_usermode);
54439+ if (!error2)
54440+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54441+ else {
54442+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54443+ error = error2;
54444+ }
54445+ } else {
54446+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54447+ error = -EPERM;
54448+ }
54449+ break;
54450+ case GR_SEGVMOD:
54451+ if (unlikely(!(gr_status & GR_READY))) {
54452+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54453+ error = -EAGAIN;
54454+ break;
54455+ }
54456+
54457+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54458+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54459+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
54460+ struct acl_subject_label *segvacl;
54461+ segvacl =
54462+ lookup_acl_subj_label(gr_usermode->segv_inode,
54463+ gr_usermode->segv_device,
54464+ current->role);
54465+ if (segvacl) {
54466+ segvacl->crashes = 0;
54467+ segvacl->expires = 0;
54468+ }
54469+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
54470+ gr_remove_uid(gr_usermode->segv_uid);
54471+ }
54472+ } else {
54473+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
54474+ error = -EPERM;
54475+ }
54476+ break;
54477+ case GR_SPROLE:
54478+ case GR_SPROLEPAM:
54479+ if (unlikely(!(gr_status & GR_READY))) {
54480+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
54481+ error = -EAGAIN;
54482+ break;
54483+ }
54484+
54485+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
54486+ current->role->expires = 0;
54487+ current->role->auth_attempts = 0;
54488+ }
54489+
54490+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54491+ time_after(current->role->expires, get_seconds())) {
54492+ error = -EBUSY;
54493+ goto out;
54494+ }
54495+
54496+ if (lookup_special_role_auth
54497+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
54498+ && ((!sprole_salt && !sprole_sum)
54499+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
54500+ char *p = "";
54501+ assign_special_role(gr_usermode->sp_role);
54502+ read_lock(&tasklist_lock);
54503+ if (current->real_parent)
54504+ p = current->real_parent->role->rolename;
54505+ read_unlock(&tasklist_lock);
54506+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
54507+ p, acl_sp_role_value);
54508+ } else {
54509+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
54510+ error = -EPERM;
54511+ if(!(current->role->auth_attempts++))
54512+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54513+
54514+ goto out;
54515+ }
54516+ break;
54517+ case GR_UNSPROLE:
54518+ if (unlikely(!(gr_status & GR_READY))) {
54519+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
54520+ error = -EAGAIN;
54521+ break;
54522+ }
54523+
54524+ if (current->role->roletype & GR_ROLE_SPECIAL) {
54525+ char *p = "";
54526+ int i = 0;
54527+
54528+ read_lock(&tasklist_lock);
54529+ if (current->real_parent) {
54530+ p = current->real_parent->role->rolename;
54531+ i = current->real_parent->acl_role_id;
54532+ }
54533+ read_unlock(&tasklist_lock);
54534+
54535+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
54536+ gr_set_acls(1);
54537+ } else {
54538+ error = -EPERM;
54539+ goto out;
54540+ }
54541+ break;
54542+ default:
54543+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
54544+ error = -EINVAL;
54545+ break;
54546+ }
54547+
54548+ if (error != -EPERM)
54549+ goto out;
54550+
54551+ if(!(gr_auth_attempts++))
54552+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54553+
54554+ out:
54555+ mutex_unlock(&gr_dev_mutex);
54556+ return error;
54557+}
54558+
54559+/* must be called with
54560+ rcu_read_lock();
54561+ read_lock(&tasklist_lock);
54562+ read_lock(&grsec_exec_file_lock);
54563+*/
54564+int gr_apply_subject_to_task(struct task_struct *task)
54565+{
54566+ struct acl_object_label *obj;
54567+ char *tmpname;
54568+ struct acl_subject_label *tmpsubj;
54569+ struct file *filp;
54570+ struct name_entry *nmatch;
54571+
54572+ filp = task->exec_file;
54573+ if (filp == NULL)
54574+ return 0;
54575+
54576+ /* the following is to apply the correct subject
54577+ on binaries running when the RBAC system
54578+ is enabled, when the binaries have been
54579+ replaced or deleted since their execution
54580+ -----
54581+ when the RBAC system starts, the inode/dev
54582+ from exec_file will be one the RBAC system
54583+ is unaware of. It only knows the inode/dev
54584+ of the present file on disk, or the absence
54585+ of it.
54586+ */
54587+ preempt_disable();
54588+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
54589+
54590+ nmatch = lookup_name_entry(tmpname);
54591+ preempt_enable();
54592+ tmpsubj = NULL;
54593+ if (nmatch) {
54594+ if (nmatch->deleted)
54595+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
54596+ else
54597+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
54598+ if (tmpsubj != NULL)
54599+ task->acl = tmpsubj;
54600+ }
54601+ if (tmpsubj == NULL)
54602+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
54603+ task->role);
54604+ if (task->acl) {
54605+ task->is_writable = 0;
54606+ /* ignore additional mmap checks for processes that are writable
54607+ by the default ACL */
54608+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54609+ if (unlikely(obj->mode & GR_WRITE))
54610+ task->is_writable = 1;
54611+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54612+ if (unlikely(obj->mode & GR_WRITE))
54613+ task->is_writable = 1;
54614+
54615+ gr_set_proc_res(task);
54616+
54617+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54618+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54619+#endif
54620+ } else {
54621+ return 1;
54622+ }
54623+
54624+ return 0;
54625+}
54626+
54627+int
54628+gr_set_acls(const int type)
54629+{
54630+ struct task_struct *task, *task2;
54631+ struct acl_role_label *role = current->role;
54632+ __u16 acl_role_id = current->acl_role_id;
54633+ const struct cred *cred;
54634+ int ret;
54635+
54636+ rcu_read_lock();
54637+ read_lock(&tasklist_lock);
54638+ read_lock(&grsec_exec_file_lock);
54639+ do_each_thread(task2, task) {
54640+ /* check to see if we're called from the exit handler,
54641+ if so, only replace ACLs that have inherited the admin
54642+ ACL */
54643+
54644+ if (type && (task->role != role ||
54645+ task->acl_role_id != acl_role_id))
54646+ continue;
54647+
54648+ task->acl_role_id = 0;
54649+ task->acl_sp_role = 0;
54650+
54651+ if (task->exec_file) {
54652+ cred = __task_cred(task);
54653+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
54654+ ret = gr_apply_subject_to_task(task);
54655+ if (ret) {
54656+ read_unlock(&grsec_exec_file_lock);
54657+ read_unlock(&tasklist_lock);
54658+ rcu_read_unlock();
54659+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
54660+ return ret;
54661+ }
54662+ } else {
54663+ // it's a kernel process
54664+ task->role = kernel_role;
54665+ task->acl = kernel_role->root_label;
54666+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
54667+ task->acl->mode &= ~GR_PROCFIND;
54668+#endif
54669+ }
54670+ } while_each_thread(task2, task);
54671+ read_unlock(&grsec_exec_file_lock);
54672+ read_unlock(&tasklist_lock);
54673+ rcu_read_unlock();
54674+
54675+ return 0;
54676+}
54677+
54678+void
54679+gr_learn_resource(const struct task_struct *task,
54680+ const int res, const unsigned long wanted, const int gt)
54681+{
54682+ struct acl_subject_label *acl;
54683+ const struct cred *cred;
54684+
54685+ if (unlikely((gr_status & GR_READY) &&
54686+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
54687+ goto skip_reslog;
54688+
54689+#ifdef CONFIG_GRKERNSEC_RESLOG
54690+ gr_log_resource(task, res, wanted, gt);
54691+#endif
54692+ skip_reslog:
54693+
54694+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
54695+ return;
54696+
54697+ acl = task->acl;
54698+
54699+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
54700+ !(acl->resmask & (1 << (unsigned short) res))))
54701+ return;
54702+
54703+ if (wanted >= acl->res[res].rlim_cur) {
54704+ unsigned long res_add;
54705+
54706+ res_add = wanted;
54707+ switch (res) {
54708+ case RLIMIT_CPU:
54709+ res_add += GR_RLIM_CPU_BUMP;
54710+ break;
54711+ case RLIMIT_FSIZE:
54712+ res_add += GR_RLIM_FSIZE_BUMP;
54713+ break;
54714+ case RLIMIT_DATA:
54715+ res_add += GR_RLIM_DATA_BUMP;
54716+ break;
54717+ case RLIMIT_STACK:
54718+ res_add += GR_RLIM_STACK_BUMP;
54719+ break;
54720+ case RLIMIT_CORE:
54721+ res_add += GR_RLIM_CORE_BUMP;
54722+ break;
54723+ case RLIMIT_RSS:
54724+ res_add += GR_RLIM_RSS_BUMP;
54725+ break;
54726+ case RLIMIT_NPROC:
54727+ res_add += GR_RLIM_NPROC_BUMP;
54728+ break;
54729+ case RLIMIT_NOFILE:
54730+ res_add += GR_RLIM_NOFILE_BUMP;
54731+ break;
54732+ case RLIMIT_MEMLOCK:
54733+ res_add += GR_RLIM_MEMLOCK_BUMP;
54734+ break;
54735+ case RLIMIT_AS:
54736+ res_add += GR_RLIM_AS_BUMP;
54737+ break;
54738+ case RLIMIT_LOCKS:
54739+ res_add += GR_RLIM_LOCKS_BUMP;
54740+ break;
54741+ case RLIMIT_SIGPENDING:
54742+ res_add += GR_RLIM_SIGPENDING_BUMP;
54743+ break;
54744+ case RLIMIT_MSGQUEUE:
54745+ res_add += GR_RLIM_MSGQUEUE_BUMP;
54746+ break;
54747+ case RLIMIT_NICE:
54748+ res_add += GR_RLIM_NICE_BUMP;
54749+ break;
54750+ case RLIMIT_RTPRIO:
54751+ res_add += GR_RLIM_RTPRIO_BUMP;
54752+ break;
54753+ case RLIMIT_RTTIME:
54754+ res_add += GR_RLIM_RTTIME_BUMP;
54755+ break;
54756+ }
54757+
54758+ acl->res[res].rlim_cur = res_add;
54759+
54760+ if (wanted > acl->res[res].rlim_max)
54761+ acl->res[res].rlim_max = res_add;
54762+
54763+ /* only log the subject filename, since resource logging is supported for
54764+ single-subject learning only */
54765+ rcu_read_lock();
54766+ cred = __task_cred(task);
54767+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54768+ task->role->roletype, cred->uid, cred->gid, acl->filename,
54769+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
54770+ "", (unsigned long) res, &task->signal->saved_ip);
54771+ rcu_read_unlock();
54772+ }
54773+
54774+ return;
54775+}
54776+
54777+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
54778+void
54779+pax_set_initial_flags(struct linux_binprm *bprm)
54780+{
54781+ struct task_struct *task = current;
54782+ struct acl_subject_label *proc;
54783+ unsigned long flags;
54784+
54785+ if (unlikely(!(gr_status & GR_READY)))
54786+ return;
54787+
54788+ flags = pax_get_flags(task);
54789+
54790+ proc = task->acl;
54791+
54792+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
54793+ flags &= ~MF_PAX_PAGEEXEC;
54794+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
54795+ flags &= ~MF_PAX_SEGMEXEC;
54796+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
54797+ flags &= ~MF_PAX_RANDMMAP;
54798+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
54799+ flags &= ~MF_PAX_EMUTRAMP;
54800+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
54801+ flags &= ~MF_PAX_MPROTECT;
54802+
54803+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
54804+ flags |= MF_PAX_PAGEEXEC;
54805+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
54806+ flags |= MF_PAX_SEGMEXEC;
54807+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
54808+ flags |= MF_PAX_RANDMMAP;
54809+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
54810+ flags |= MF_PAX_EMUTRAMP;
54811+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
54812+ flags |= MF_PAX_MPROTECT;
54813+
54814+ pax_set_flags(task, flags);
54815+
54816+ return;
54817+}
54818+#endif
54819+
54820+int
54821+gr_handle_proc_ptrace(struct task_struct *task)
54822+{
54823+ struct file *filp;
54824+ struct task_struct *tmp = task;
54825+ struct task_struct *curtemp = current;
54826+ __u32 retmode;
54827+
54828+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54829+ if (unlikely(!(gr_status & GR_READY)))
54830+ return 0;
54831+#endif
54832+
54833+ read_lock(&tasklist_lock);
54834+ read_lock(&grsec_exec_file_lock);
54835+ filp = task->exec_file;
54836+
54837+ while (tmp->pid > 0) {
54838+ if (tmp == curtemp)
54839+ break;
54840+ tmp = tmp->real_parent;
54841+ }
54842+
54843+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
54844+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
54845+ read_unlock(&grsec_exec_file_lock);
54846+ read_unlock(&tasklist_lock);
54847+ return 1;
54848+ }
54849+
54850+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54851+ if (!(gr_status & GR_READY)) {
54852+ read_unlock(&grsec_exec_file_lock);
54853+ read_unlock(&tasklist_lock);
54854+ return 0;
54855+ }
54856+#endif
54857+
54858+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
54859+ read_unlock(&grsec_exec_file_lock);
54860+ read_unlock(&tasklist_lock);
54861+
54862+ if (retmode & GR_NOPTRACE)
54863+ return 1;
54864+
54865+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
54866+ && (current->acl != task->acl || (current->acl != current->role->root_label
54867+ && current->pid != task->pid)))
54868+ return 1;
54869+
54870+ return 0;
54871+}
54872+
54873+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
54874+{
54875+ if (unlikely(!(gr_status & GR_READY)))
54876+ return;
54877+
54878+ if (!(current->role->roletype & GR_ROLE_GOD))
54879+ return;
54880+
54881+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
54882+ p->role->rolename, gr_task_roletype_to_char(p),
54883+ p->acl->filename);
54884+}
54885+
54886+int
54887+gr_handle_ptrace(struct task_struct *task, const long request)
54888+{
54889+ struct task_struct *tmp = task;
54890+ struct task_struct *curtemp = current;
54891+ __u32 retmode;
54892+
54893+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54894+ if (unlikely(!(gr_status & GR_READY)))
54895+ return 0;
54896+#endif
54897+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
54898+ read_lock(&tasklist_lock);
54899+ while (tmp->pid > 0) {
54900+ if (tmp == curtemp)
54901+ break;
54902+ tmp = tmp->real_parent;
54903+ }
54904+
54905+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
54906+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
54907+ read_unlock(&tasklist_lock);
54908+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54909+ return 1;
54910+ }
54911+ read_unlock(&tasklist_lock);
54912+ }
54913+
54914+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54915+ if (!(gr_status & GR_READY))
54916+ return 0;
54917+#endif
54918+
54919+ read_lock(&grsec_exec_file_lock);
54920+ if (unlikely(!task->exec_file)) {
54921+ read_unlock(&grsec_exec_file_lock);
54922+ return 0;
54923+ }
54924+
54925+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
54926+ read_unlock(&grsec_exec_file_lock);
54927+
54928+ if (retmode & GR_NOPTRACE) {
54929+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54930+ return 1;
54931+ }
54932+
54933+ if (retmode & GR_PTRACERD) {
54934+ switch (request) {
54935+ case PTRACE_SEIZE:
54936+ case PTRACE_POKETEXT:
54937+ case PTRACE_POKEDATA:
54938+ case PTRACE_POKEUSR:
54939+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
54940+ case PTRACE_SETREGS:
54941+ case PTRACE_SETFPREGS:
54942+#endif
54943+#ifdef CONFIG_X86
54944+ case PTRACE_SETFPXREGS:
54945+#endif
54946+#ifdef CONFIG_ALTIVEC
54947+ case PTRACE_SETVRREGS:
54948+#endif
54949+ return 1;
54950+ default:
54951+ return 0;
54952+ }
54953+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
54954+ !(current->role->roletype & GR_ROLE_GOD) &&
54955+ (current->acl != task->acl)) {
54956+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54957+ return 1;
54958+ }
54959+
54960+ return 0;
54961+}
54962+
54963+static int is_writable_mmap(const struct file *filp)
54964+{
54965+ struct task_struct *task = current;
54966+ struct acl_object_label *obj, *obj2;
54967+
54968+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
54969+ !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))) {
54970+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54971+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
54972+ task->role->root_label);
54973+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
54974+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
54975+ return 1;
54976+ }
54977+ }
54978+ return 0;
54979+}
54980+
54981+int
54982+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
54983+{
54984+ __u32 mode;
54985+
54986+ if (unlikely(!file || !(prot & PROT_EXEC)))
54987+ return 1;
54988+
54989+ if (is_writable_mmap(file))
54990+ return 0;
54991+
54992+ mode =
54993+ gr_search_file(file->f_path.dentry,
54994+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54995+ file->f_path.mnt);
54996+
54997+ if (!gr_tpe_allow(file))
54998+ return 0;
54999+
55000+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55001+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55002+ return 0;
55003+ } else if (unlikely(!(mode & GR_EXEC))) {
55004+ return 0;
55005+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55006+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55007+ return 1;
55008+ }
55009+
55010+ return 1;
55011+}
55012+
55013+int
55014+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55015+{
55016+ __u32 mode;
55017+
55018+ if (unlikely(!file || !(prot & PROT_EXEC)))
55019+ return 1;
55020+
55021+ if (is_writable_mmap(file))
55022+ return 0;
55023+
55024+ mode =
55025+ gr_search_file(file->f_path.dentry,
55026+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55027+ file->f_path.mnt);
55028+
55029+ if (!gr_tpe_allow(file))
55030+ return 0;
55031+
55032+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55033+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55034+ return 0;
55035+ } else if (unlikely(!(mode & GR_EXEC))) {
55036+ return 0;
55037+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55038+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55039+ return 1;
55040+ }
55041+
55042+ return 1;
55043+}
55044+
55045+void
55046+gr_acl_handle_psacct(struct task_struct *task, const long code)
55047+{
55048+ unsigned long runtime;
55049+ unsigned long cputime;
55050+ unsigned int wday, cday;
55051+ __u8 whr, chr;
55052+ __u8 wmin, cmin;
55053+ __u8 wsec, csec;
55054+ struct timespec timeval;
55055+
55056+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
55057+ !(task->acl->mode & GR_PROCACCT)))
55058+ return;
55059+
55060+ do_posix_clock_monotonic_gettime(&timeval);
55061+ runtime = timeval.tv_sec - task->start_time.tv_sec;
55062+ wday = runtime / (3600 * 24);
55063+ runtime -= wday * (3600 * 24);
55064+ whr = runtime / 3600;
55065+ runtime -= whr * 3600;
55066+ wmin = runtime / 60;
55067+ runtime -= wmin * 60;
55068+ wsec = runtime;
55069+
55070+ cputime = (task->utime + task->stime) / HZ;
55071+ cday = cputime / (3600 * 24);
55072+ cputime -= cday * (3600 * 24);
55073+ chr = cputime / 3600;
55074+ cputime -= chr * 3600;
55075+ cmin = cputime / 60;
55076+ cputime -= cmin * 60;
55077+ csec = cputime;
55078+
55079+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
55080+
55081+ return;
55082+}
55083+
55084+void gr_set_kernel_label(struct task_struct *task)
55085+{
55086+ if (gr_status & GR_READY) {
55087+ task->role = kernel_role;
55088+ task->acl = kernel_role->root_label;
55089+ }
55090+ return;
55091+}
55092+
55093+#ifdef CONFIG_TASKSTATS
55094+int gr_is_taskstats_denied(int pid)
55095+{
55096+ struct task_struct *task;
55097+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55098+ const struct cred *cred;
55099+#endif
55100+ int ret = 0;
55101+
55102+ /* restrict taskstats viewing to un-chrooted root users
55103+ who have the 'view' subject flag if the RBAC system is enabled
55104+ */
55105+
55106+ rcu_read_lock();
55107+ read_lock(&tasklist_lock);
55108+ task = find_task_by_vpid(pid);
55109+ if (task) {
55110+#ifdef CONFIG_GRKERNSEC_CHROOT
55111+ if (proc_is_chrooted(task))
55112+ ret = -EACCES;
55113+#endif
55114+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55115+ cred = __task_cred(task);
55116+#ifdef CONFIG_GRKERNSEC_PROC_USER
55117+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
55118+ ret = -EACCES;
55119+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55120+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
55121+ ret = -EACCES;
55122+#endif
55123+#endif
55124+ if (gr_status & GR_READY) {
55125+ if (!(task->acl->mode & GR_VIEW))
55126+ ret = -EACCES;
55127+ }
55128+ } else
55129+ ret = -ENOENT;
55130+
55131+ read_unlock(&tasklist_lock);
55132+ rcu_read_unlock();
55133+
55134+ return ret;
55135+}
55136+#endif
55137+
55138+/* AUXV entries are filled via a descendant of search_binary_handler
55139+ after we've already applied the subject for the target
55140+*/
55141+int gr_acl_enable_at_secure(void)
55142+{
55143+ if (unlikely(!(gr_status & GR_READY)))
55144+ return 0;
55145+
55146+ if (current->acl->mode & GR_ATSECURE)
55147+ return 1;
55148+
55149+ return 0;
55150+}
55151+
55152+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
55153+{
55154+ struct task_struct *task = current;
55155+ struct dentry *dentry = file->f_path.dentry;
55156+ struct vfsmount *mnt = file->f_path.mnt;
55157+ struct acl_object_label *obj, *tmp;
55158+ struct acl_subject_label *subj;
55159+ unsigned int bufsize;
55160+ int is_not_root;
55161+ char *path;
55162+ dev_t dev = __get_dev(dentry);
55163+
55164+ if (unlikely(!(gr_status & GR_READY)))
55165+ return 1;
55166+
55167+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55168+ return 1;
55169+
55170+ /* ignore Eric Biederman */
55171+ if (IS_PRIVATE(dentry->d_inode))
55172+ return 1;
55173+
55174+ subj = task->acl;
55175+ read_lock(&gr_inode_lock);
55176+ do {
55177+ obj = lookup_acl_obj_label(ino, dev, subj);
55178+ if (obj != NULL) {
55179+ read_unlock(&gr_inode_lock);
55180+ return (obj->mode & GR_FIND) ? 1 : 0;
55181+ }
55182+ } while ((subj = subj->parent_subject));
55183+ read_unlock(&gr_inode_lock);
55184+
55185+ /* this is purely an optimization since we're looking for an object
55186+ for the directory we're doing a readdir on
55187+ if it's possible for any globbed object to match the entry we're
55188+ filling into the directory, then the object we find here will be
55189+ an anchor point with attached globbed objects
55190+ */
55191+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
55192+ if (obj->globbed == NULL)
55193+ return (obj->mode & GR_FIND) ? 1 : 0;
55194+
55195+ is_not_root = ((obj->filename[0] == '/') &&
55196+ (obj->filename[1] == '\0')) ? 0 : 1;
55197+ bufsize = PAGE_SIZE - namelen - is_not_root;
55198+
55199+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
55200+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
55201+ return 1;
55202+
55203+ preempt_disable();
55204+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55205+ bufsize);
55206+
55207+ bufsize = strlen(path);
55208+
55209+ /* if base is "/", don't append an additional slash */
55210+ if (is_not_root)
55211+ *(path + bufsize) = '/';
55212+ memcpy(path + bufsize + is_not_root, name, namelen);
55213+ *(path + bufsize + namelen + is_not_root) = '\0';
55214+
55215+ tmp = obj->globbed;
55216+ while (tmp) {
55217+ if (!glob_match(tmp->filename, path)) {
55218+ preempt_enable();
55219+ return (tmp->mode & GR_FIND) ? 1 : 0;
55220+ }
55221+ tmp = tmp->next;
55222+ }
55223+ preempt_enable();
55224+ return (obj->mode & GR_FIND) ? 1 : 0;
55225+}
55226+
55227+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55228+EXPORT_SYMBOL(gr_acl_is_enabled);
55229+#endif
55230+EXPORT_SYMBOL(gr_learn_resource);
55231+EXPORT_SYMBOL(gr_set_kernel_label);
55232+#ifdef CONFIG_SECURITY
55233+EXPORT_SYMBOL(gr_check_user_change);
55234+EXPORT_SYMBOL(gr_check_group_change);
55235+#endif
55236+
55237diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
55238new file mode 100644
55239index 0000000..34fefda
55240--- /dev/null
55241+++ b/grsecurity/gracl_alloc.c
55242@@ -0,0 +1,105 @@
55243+#include <linux/kernel.h>
55244+#include <linux/mm.h>
55245+#include <linux/slab.h>
55246+#include <linux/vmalloc.h>
55247+#include <linux/gracl.h>
55248+#include <linux/grsecurity.h>
55249+
55250+static unsigned long alloc_stack_next = 1;
55251+static unsigned long alloc_stack_size = 1;
55252+static void **alloc_stack;
55253+
55254+static __inline__ int
55255+alloc_pop(void)
55256+{
55257+ if (alloc_stack_next == 1)
55258+ return 0;
55259+
55260+ kfree(alloc_stack[alloc_stack_next - 2]);
55261+
55262+ alloc_stack_next--;
55263+
55264+ return 1;
55265+}
55266+
55267+static __inline__ int
55268+alloc_push(void *buf)
55269+{
55270+ if (alloc_stack_next >= alloc_stack_size)
55271+ return 1;
55272+
55273+ alloc_stack[alloc_stack_next - 1] = buf;
55274+
55275+ alloc_stack_next++;
55276+
55277+ return 0;
55278+}
55279+
55280+void *
55281+acl_alloc(unsigned long len)
55282+{
55283+ void *ret = NULL;
55284+
55285+ if (!len || len > PAGE_SIZE)
55286+ goto out;
55287+
55288+ ret = kmalloc(len, GFP_KERNEL);
55289+
55290+ if (ret) {
55291+ if (alloc_push(ret)) {
55292+ kfree(ret);
55293+ ret = NULL;
55294+ }
55295+ }
55296+
55297+out:
55298+ return ret;
55299+}
55300+
55301+void *
55302+acl_alloc_num(unsigned long num, unsigned long len)
55303+{
55304+ if (!len || (num > (PAGE_SIZE / len)))
55305+ return NULL;
55306+
55307+ return acl_alloc(num * len);
55308+}
55309+
55310+void
55311+acl_free_all(void)
55312+{
55313+ if (gr_acl_is_enabled() || !alloc_stack)
55314+ return;
55315+
55316+ while (alloc_pop()) ;
55317+
55318+ if (alloc_stack) {
55319+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
55320+ kfree(alloc_stack);
55321+ else
55322+ vfree(alloc_stack);
55323+ }
55324+
55325+ alloc_stack = NULL;
55326+ alloc_stack_size = 1;
55327+ alloc_stack_next = 1;
55328+
55329+ return;
55330+}
55331+
55332+int
55333+acl_alloc_stack_init(unsigned long size)
55334+{
55335+ if ((size * sizeof (void *)) <= PAGE_SIZE)
55336+ alloc_stack =
55337+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
55338+ else
55339+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
55340+
55341+ alloc_stack_size = size;
55342+
55343+ if (!alloc_stack)
55344+ return 0;
55345+ else
55346+ return 1;
55347+}
55348diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
55349new file mode 100644
55350index 0000000..6d21049
55351--- /dev/null
55352+++ b/grsecurity/gracl_cap.c
55353@@ -0,0 +1,110 @@
55354+#include <linux/kernel.h>
55355+#include <linux/module.h>
55356+#include <linux/sched.h>
55357+#include <linux/gracl.h>
55358+#include <linux/grsecurity.h>
55359+#include <linux/grinternal.h>
55360+
55361+extern const char *captab_log[];
55362+extern int captab_log_entries;
55363+
55364+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
55365+{
55366+ struct acl_subject_label *curracl;
55367+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55368+ kernel_cap_t cap_audit = __cap_empty_set;
55369+
55370+ if (!gr_acl_is_enabled())
55371+ return 1;
55372+
55373+ curracl = task->acl;
55374+
55375+ cap_drop = curracl->cap_lower;
55376+ cap_mask = curracl->cap_mask;
55377+ cap_audit = curracl->cap_invert_audit;
55378+
55379+ while ((curracl = curracl->parent_subject)) {
55380+ /* if the cap isn't specified in the current computed mask but is specified in the
55381+ current level subject, and is lowered in the current level subject, then add
55382+ it to the set of dropped capabilities
55383+ otherwise, add the current level subject's mask to the current computed mask
55384+ */
55385+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55386+ cap_raise(cap_mask, cap);
55387+ if (cap_raised(curracl->cap_lower, cap))
55388+ cap_raise(cap_drop, cap);
55389+ if (cap_raised(curracl->cap_invert_audit, cap))
55390+ cap_raise(cap_audit, cap);
55391+ }
55392+ }
55393+
55394+ if (!cap_raised(cap_drop, cap)) {
55395+ if (cap_raised(cap_audit, cap))
55396+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55397+ return 1;
55398+ }
55399+
55400+ curracl = task->acl;
55401+
55402+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55403+ && cap_raised(cred->cap_effective, cap)) {
55404+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55405+ task->role->roletype, cred->uid,
55406+ cred->gid, task->exec_file ?
55407+ gr_to_filename(task->exec_file->f_path.dentry,
55408+ task->exec_file->f_path.mnt) : curracl->filename,
55409+ curracl->filename, 0UL,
55410+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55411+ return 1;
55412+ }
55413+
55414+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55415+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55416+
55417+ return 0;
55418+}
55419+
55420+int
55421+gr_acl_is_capable(const int cap)
55422+{
55423+ return gr_task_acl_is_capable(current, current_cred(), cap);
55424+}
55425+
55426+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
55427+{
55428+ struct acl_subject_label *curracl;
55429+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55430+
55431+ if (!gr_acl_is_enabled())
55432+ return 1;
55433+
55434+ curracl = task->acl;
55435+
55436+ cap_drop = curracl->cap_lower;
55437+ cap_mask = curracl->cap_mask;
55438+
55439+ while ((curracl = curracl->parent_subject)) {
55440+ /* if the cap isn't specified in the current computed mask but is specified in the
55441+ current level subject, and is lowered in the current level subject, then add
55442+ it to the set of dropped capabilities
55443+ otherwise, add the current level subject's mask to the current computed mask
55444+ */
55445+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55446+ cap_raise(cap_mask, cap);
55447+ if (cap_raised(curracl->cap_lower, cap))
55448+ cap_raise(cap_drop, cap);
55449+ }
55450+ }
55451+
55452+ if (!cap_raised(cap_drop, cap))
55453+ return 1;
55454+
55455+ return 0;
55456+}
55457+
55458+int
55459+gr_acl_is_capable_nolog(const int cap)
55460+{
55461+ return gr_task_acl_is_capable_nolog(current, cap);
55462+}
55463+
55464diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
55465new file mode 100644
55466index 0000000..d28e241
55467--- /dev/null
55468+++ b/grsecurity/gracl_fs.c
55469@@ -0,0 +1,437 @@
55470+#include <linux/kernel.h>
55471+#include <linux/sched.h>
55472+#include <linux/types.h>
55473+#include <linux/fs.h>
55474+#include <linux/file.h>
55475+#include <linux/stat.h>
55476+#include <linux/grsecurity.h>
55477+#include <linux/grinternal.h>
55478+#include <linux/gracl.h>
55479+
55480+umode_t
55481+gr_acl_umask(void)
55482+{
55483+ if (unlikely(!gr_acl_is_enabled()))
55484+ return 0;
55485+
55486+ return current->role->umask;
55487+}
55488+
55489+__u32
55490+gr_acl_handle_hidden_file(const struct dentry * dentry,
55491+ const struct vfsmount * mnt)
55492+{
55493+ __u32 mode;
55494+
55495+ if (unlikely(!dentry->d_inode))
55496+ return GR_FIND;
55497+
55498+ mode =
55499+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55500+
55501+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55502+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55503+ return mode;
55504+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55505+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55506+ return 0;
55507+ } else if (unlikely(!(mode & GR_FIND)))
55508+ return 0;
55509+
55510+ return GR_FIND;
55511+}
55512+
55513+__u32
55514+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55515+ int acc_mode)
55516+{
55517+ __u32 reqmode = GR_FIND;
55518+ __u32 mode;
55519+
55520+ if (unlikely(!dentry->d_inode))
55521+ return reqmode;
55522+
55523+ if (acc_mode & MAY_APPEND)
55524+ reqmode |= GR_APPEND;
55525+ else if (acc_mode & MAY_WRITE)
55526+ reqmode |= GR_WRITE;
55527+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
55528+ reqmode |= GR_READ;
55529+
55530+ mode =
55531+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55532+ mnt);
55533+
55534+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55535+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55536+ reqmode & GR_READ ? " reading" : "",
55537+ reqmode & GR_WRITE ? " writing" : reqmode &
55538+ GR_APPEND ? " appending" : "");
55539+ return reqmode;
55540+ } else
55541+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55542+ {
55543+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55544+ reqmode & GR_READ ? " reading" : "",
55545+ reqmode & GR_WRITE ? " writing" : reqmode &
55546+ GR_APPEND ? " appending" : "");
55547+ return 0;
55548+ } else if (unlikely((mode & reqmode) != reqmode))
55549+ return 0;
55550+
55551+ return reqmode;
55552+}
55553+
55554+__u32
55555+gr_acl_handle_creat(const struct dentry * dentry,
55556+ const struct dentry * p_dentry,
55557+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
55558+ const int imode)
55559+{
55560+ __u32 reqmode = GR_WRITE | GR_CREATE;
55561+ __u32 mode;
55562+
55563+ if (acc_mode & MAY_APPEND)
55564+ reqmode |= GR_APPEND;
55565+ // if a directory was required or the directory already exists, then
55566+ // don't count this open as a read
55567+ if ((acc_mode & MAY_READ) &&
55568+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
55569+ reqmode |= GR_READ;
55570+ if ((open_flags & O_CREAT) &&
55571+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
55572+ reqmode |= GR_SETID;
55573+
55574+ mode =
55575+ gr_check_create(dentry, p_dentry, p_mnt,
55576+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55577+
55578+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55579+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55580+ reqmode & GR_READ ? " reading" : "",
55581+ reqmode & GR_WRITE ? " writing" : reqmode &
55582+ GR_APPEND ? " appending" : "");
55583+ return reqmode;
55584+ } else
55585+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55586+ {
55587+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55588+ reqmode & GR_READ ? " reading" : "",
55589+ reqmode & GR_WRITE ? " writing" : reqmode &
55590+ GR_APPEND ? " appending" : "");
55591+ return 0;
55592+ } else if (unlikely((mode & reqmode) != reqmode))
55593+ return 0;
55594+
55595+ return reqmode;
55596+}
55597+
55598+__u32
55599+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
55600+ const int fmode)
55601+{
55602+ __u32 mode, reqmode = GR_FIND;
55603+
55604+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
55605+ reqmode |= GR_EXEC;
55606+ if (fmode & S_IWOTH)
55607+ reqmode |= GR_WRITE;
55608+ if (fmode & S_IROTH)
55609+ reqmode |= GR_READ;
55610+
55611+ mode =
55612+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55613+ mnt);
55614+
55615+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55616+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55617+ reqmode & GR_READ ? " reading" : "",
55618+ reqmode & GR_WRITE ? " writing" : "",
55619+ reqmode & GR_EXEC ? " executing" : "");
55620+ return reqmode;
55621+ } else
55622+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55623+ {
55624+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55625+ reqmode & GR_READ ? " reading" : "",
55626+ reqmode & GR_WRITE ? " writing" : "",
55627+ reqmode & GR_EXEC ? " executing" : "");
55628+ return 0;
55629+ } else if (unlikely((mode & reqmode) != reqmode))
55630+ return 0;
55631+
55632+ return reqmode;
55633+}
55634+
55635+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55636+{
55637+ __u32 mode;
55638+
55639+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55640+
55641+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55642+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55643+ return mode;
55644+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55645+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55646+ return 0;
55647+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
55648+ return 0;
55649+
55650+ return (reqmode);
55651+}
55652+
55653+__u32
55654+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
55655+{
55656+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
55657+}
55658+
55659+__u32
55660+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
55661+{
55662+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
55663+}
55664+
55665+__u32
55666+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
55667+{
55668+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
55669+}
55670+
55671+__u32
55672+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
55673+{
55674+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
55675+}
55676+
55677+__u32
55678+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
55679+ umode_t *modeptr)
55680+{
55681+ umode_t mode;
55682+
55683+ *modeptr &= ~gr_acl_umask();
55684+ mode = *modeptr;
55685+
55686+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
55687+ return 1;
55688+
55689+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
55690+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
55691+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55692+ GR_CHMOD_ACL_MSG);
55693+ } else {
55694+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
55695+ }
55696+}
55697+
55698+__u32
55699+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
55700+{
55701+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
55702+}
55703+
55704+__u32
55705+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
55706+{
55707+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
55708+}
55709+
55710+__u32
55711+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
55712+{
55713+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
55714+}
55715+
55716+__u32
55717+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
55718+{
55719+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
55720+ GR_UNIXCONNECT_ACL_MSG);
55721+}
55722+
55723+/* hardlinks require at minimum create and link permission,
55724+ any additional privilege required is based on the
55725+ privilege of the file being linked to
55726+*/
55727+__u32
55728+gr_acl_handle_link(const struct dentry * new_dentry,
55729+ const struct dentry * parent_dentry,
55730+ const struct vfsmount * parent_mnt,
55731+ const struct dentry * old_dentry,
55732+ const struct vfsmount * old_mnt, const char *to)
55733+{
55734+ __u32 mode;
55735+ __u32 needmode = GR_CREATE | GR_LINK;
55736+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
55737+
55738+ mode =
55739+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
55740+ old_mnt);
55741+
55742+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
55743+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55744+ return mode;
55745+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55746+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55747+ return 0;
55748+ } else if (unlikely((mode & needmode) != needmode))
55749+ return 0;
55750+
55751+ return 1;
55752+}
55753+
55754+__u32
55755+gr_acl_handle_symlink(const struct dentry * new_dentry,
55756+ const struct dentry * parent_dentry,
55757+ const struct vfsmount * parent_mnt, const char *from)
55758+{
55759+ __u32 needmode = GR_WRITE | GR_CREATE;
55760+ __u32 mode;
55761+
55762+ mode =
55763+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
55764+ GR_CREATE | GR_AUDIT_CREATE |
55765+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
55766+
55767+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
55768+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55769+ return mode;
55770+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55771+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55772+ return 0;
55773+ } else if (unlikely((mode & needmode) != needmode))
55774+ return 0;
55775+
55776+ return (GR_WRITE | GR_CREATE);
55777+}
55778+
55779+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)
55780+{
55781+ __u32 mode;
55782+
55783+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55784+
55785+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55786+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
55787+ return mode;
55788+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55789+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
55790+ return 0;
55791+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
55792+ return 0;
55793+
55794+ return (reqmode);
55795+}
55796+
55797+__u32
55798+gr_acl_handle_mknod(const struct dentry * new_dentry,
55799+ const struct dentry * parent_dentry,
55800+ const struct vfsmount * parent_mnt,
55801+ const int mode)
55802+{
55803+ __u32 reqmode = GR_WRITE | GR_CREATE;
55804+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
55805+ reqmode |= GR_SETID;
55806+
55807+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55808+ reqmode, GR_MKNOD_ACL_MSG);
55809+}
55810+
55811+__u32
55812+gr_acl_handle_mkdir(const struct dentry *new_dentry,
55813+ const struct dentry *parent_dentry,
55814+ const struct vfsmount *parent_mnt)
55815+{
55816+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55817+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
55818+}
55819+
55820+#define RENAME_CHECK_SUCCESS(old, new) \
55821+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
55822+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
55823+
55824+int
55825+gr_acl_handle_rename(struct dentry *new_dentry,
55826+ struct dentry *parent_dentry,
55827+ const struct vfsmount *parent_mnt,
55828+ struct dentry *old_dentry,
55829+ struct inode *old_parent_inode,
55830+ struct vfsmount *old_mnt, const char *newname)
55831+{
55832+ __u32 comp1, comp2;
55833+ int error = 0;
55834+
55835+ if (unlikely(!gr_acl_is_enabled()))
55836+ return 0;
55837+
55838+ if (!new_dentry->d_inode) {
55839+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
55840+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
55841+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
55842+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
55843+ GR_DELETE | GR_AUDIT_DELETE |
55844+ GR_AUDIT_READ | GR_AUDIT_WRITE |
55845+ GR_SUPPRESS, old_mnt);
55846+ } else {
55847+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
55848+ GR_CREATE | GR_DELETE |
55849+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
55850+ GR_AUDIT_READ | GR_AUDIT_WRITE |
55851+ GR_SUPPRESS, parent_mnt);
55852+ comp2 =
55853+ gr_search_file(old_dentry,
55854+ GR_READ | GR_WRITE | GR_AUDIT_READ |
55855+ GR_DELETE | GR_AUDIT_DELETE |
55856+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
55857+ }
55858+
55859+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
55860+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
55861+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55862+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
55863+ && !(comp2 & GR_SUPPRESS)) {
55864+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55865+ error = -EACCES;
55866+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
55867+ error = -EACCES;
55868+
55869+ return error;
55870+}
55871+
55872+void
55873+gr_acl_handle_exit(void)
55874+{
55875+ u16 id;
55876+ char *rolename;
55877+ struct file *exec_file;
55878+
55879+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
55880+ !(current->role->roletype & GR_ROLE_PERSIST))) {
55881+ id = current->acl_role_id;
55882+ rolename = current->role->rolename;
55883+ gr_set_acls(1);
55884+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
55885+ }
55886+
55887+ write_lock(&grsec_exec_file_lock);
55888+ exec_file = current->exec_file;
55889+ current->exec_file = NULL;
55890+ write_unlock(&grsec_exec_file_lock);
55891+
55892+ if (exec_file)
55893+ fput(exec_file);
55894+}
55895+
55896+int
55897+gr_acl_handle_procpidmem(const struct task_struct *task)
55898+{
55899+ if (unlikely(!gr_acl_is_enabled()))
55900+ return 0;
55901+
55902+ if (task != current && task->acl->mode & GR_PROTPROCFD)
55903+ return -EACCES;
55904+
55905+ return 0;
55906+}
55907diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
55908new file mode 100644
55909index 0000000..58800a7
55910--- /dev/null
55911+++ b/grsecurity/gracl_ip.c
55912@@ -0,0 +1,384 @@
55913+#include <linux/kernel.h>
55914+#include <asm/uaccess.h>
55915+#include <asm/errno.h>
55916+#include <net/sock.h>
55917+#include <linux/file.h>
55918+#include <linux/fs.h>
55919+#include <linux/net.h>
55920+#include <linux/in.h>
55921+#include <linux/skbuff.h>
55922+#include <linux/ip.h>
55923+#include <linux/udp.h>
55924+#include <linux/types.h>
55925+#include <linux/sched.h>
55926+#include <linux/netdevice.h>
55927+#include <linux/inetdevice.h>
55928+#include <linux/gracl.h>
55929+#include <linux/grsecurity.h>
55930+#include <linux/grinternal.h>
55931+
55932+#define GR_BIND 0x01
55933+#define GR_CONNECT 0x02
55934+#define GR_INVERT 0x04
55935+#define GR_BINDOVERRIDE 0x08
55936+#define GR_CONNECTOVERRIDE 0x10
55937+#define GR_SOCK_FAMILY 0x20
55938+
55939+static const char * gr_protocols[IPPROTO_MAX] = {
55940+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
55941+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
55942+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
55943+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
55944+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
55945+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
55946+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
55947+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
55948+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
55949+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
55950+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
55951+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
55952+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
55953+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
55954+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
55955+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
55956+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
55957+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
55958+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
55959+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
55960+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
55961+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
55962+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
55963+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
55964+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
55965+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
55966+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
55967+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
55968+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
55969+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
55970+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
55971+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
55972+ };
55973+
55974+static const char * gr_socktypes[SOCK_MAX] = {
55975+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
55976+ "unknown:7", "unknown:8", "unknown:9", "packet"
55977+ };
55978+
55979+static const char * gr_sockfamilies[AF_MAX+1] = {
55980+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
55981+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
55982+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
55983+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
55984+ };
55985+
55986+const char *
55987+gr_proto_to_name(unsigned char proto)
55988+{
55989+ return gr_protocols[proto];
55990+}
55991+
55992+const char *
55993+gr_socktype_to_name(unsigned char type)
55994+{
55995+ return gr_socktypes[type];
55996+}
55997+
55998+const char *
55999+gr_sockfamily_to_name(unsigned char family)
56000+{
56001+ return gr_sockfamilies[family];
56002+}
56003+
56004+int
56005+gr_search_socket(const int domain, const int type, const int protocol)
56006+{
56007+ struct acl_subject_label *curr;
56008+ const struct cred *cred = current_cred();
56009+
56010+ if (unlikely(!gr_acl_is_enabled()))
56011+ goto exit;
56012+
56013+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
56014+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
56015+ goto exit; // let the kernel handle it
56016+
56017+ curr = current->acl;
56018+
56019+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
56020+ /* the family is allowed, if this is PF_INET allow it only if
56021+ the extra sock type/protocol checks pass */
56022+ if (domain == PF_INET)
56023+ goto inet_check;
56024+ goto exit;
56025+ } else {
56026+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56027+ __u32 fakeip = 0;
56028+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56029+ current->role->roletype, cred->uid,
56030+ cred->gid, current->exec_file ?
56031+ gr_to_filename(current->exec_file->f_path.dentry,
56032+ current->exec_file->f_path.mnt) :
56033+ curr->filename, curr->filename,
56034+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
56035+ &current->signal->saved_ip);
56036+ goto exit;
56037+ }
56038+ goto exit_fail;
56039+ }
56040+
56041+inet_check:
56042+ /* the rest of this checking is for IPv4 only */
56043+ if (!curr->ips)
56044+ goto exit;
56045+
56046+ if ((curr->ip_type & (1 << type)) &&
56047+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
56048+ goto exit;
56049+
56050+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56051+ /* we don't place acls on raw sockets , and sometimes
56052+ dgram/ip sockets are opened for ioctl and not
56053+ bind/connect, so we'll fake a bind learn log */
56054+ if (type == SOCK_RAW || type == SOCK_PACKET) {
56055+ __u32 fakeip = 0;
56056+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56057+ current->role->roletype, cred->uid,
56058+ cred->gid, current->exec_file ?
56059+ gr_to_filename(current->exec_file->f_path.dentry,
56060+ current->exec_file->f_path.mnt) :
56061+ curr->filename, curr->filename,
56062+ &fakeip, 0, type,
56063+ protocol, GR_CONNECT, &current->signal->saved_ip);
56064+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
56065+ __u32 fakeip = 0;
56066+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56067+ current->role->roletype, cred->uid,
56068+ cred->gid, current->exec_file ?
56069+ gr_to_filename(current->exec_file->f_path.dentry,
56070+ current->exec_file->f_path.mnt) :
56071+ curr->filename, curr->filename,
56072+ &fakeip, 0, type,
56073+ protocol, GR_BIND, &current->signal->saved_ip);
56074+ }
56075+ /* we'll log when they use connect or bind */
56076+ goto exit;
56077+ }
56078+
56079+exit_fail:
56080+ if (domain == PF_INET)
56081+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
56082+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
56083+ else
56084+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
56085+ gr_socktype_to_name(type), protocol);
56086+
56087+ return 0;
56088+exit:
56089+ return 1;
56090+}
56091+
56092+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)
56093+{
56094+ if ((ip->mode & mode) &&
56095+ (ip_port >= ip->low) &&
56096+ (ip_port <= ip->high) &&
56097+ ((ntohl(ip_addr) & our_netmask) ==
56098+ (ntohl(our_addr) & our_netmask))
56099+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
56100+ && (ip->type & (1 << type))) {
56101+ if (ip->mode & GR_INVERT)
56102+ return 2; // specifically denied
56103+ else
56104+ return 1; // allowed
56105+ }
56106+
56107+ return 0; // not specifically allowed, may continue parsing
56108+}
56109+
56110+static int
56111+gr_search_connectbind(const int full_mode, struct sock *sk,
56112+ struct sockaddr_in *addr, const int type)
56113+{
56114+ char iface[IFNAMSIZ] = {0};
56115+ struct acl_subject_label *curr;
56116+ struct acl_ip_label *ip;
56117+ struct inet_sock *isk;
56118+ struct net_device *dev;
56119+ struct in_device *idev;
56120+ unsigned long i;
56121+ int ret;
56122+ int mode = full_mode & (GR_BIND | GR_CONNECT);
56123+ __u32 ip_addr = 0;
56124+ __u32 our_addr;
56125+ __u32 our_netmask;
56126+ char *p;
56127+ __u16 ip_port = 0;
56128+ const struct cred *cred = current_cred();
56129+
56130+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
56131+ return 0;
56132+
56133+ curr = current->acl;
56134+ isk = inet_sk(sk);
56135+
56136+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
56137+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
56138+ addr->sin_addr.s_addr = curr->inaddr_any_override;
56139+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
56140+ struct sockaddr_in saddr;
56141+ int err;
56142+
56143+ saddr.sin_family = AF_INET;
56144+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
56145+ saddr.sin_port = isk->inet_sport;
56146+
56147+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56148+ if (err)
56149+ return err;
56150+
56151+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56152+ if (err)
56153+ return err;
56154+ }
56155+
56156+ if (!curr->ips)
56157+ return 0;
56158+
56159+ ip_addr = addr->sin_addr.s_addr;
56160+ ip_port = ntohs(addr->sin_port);
56161+
56162+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56163+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56164+ current->role->roletype, cred->uid,
56165+ cred->gid, current->exec_file ?
56166+ gr_to_filename(current->exec_file->f_path.dentry,
56167+ current->exec_file->f_path.mnt) :
56168+ curr->filename, curr->filename,
56169+ &ip_addr, ip_port, type,
56170+ sk->sk_protocol, mode, &current->signal->saved_ip);
56171+ return 0;
56172+ }
56173+
56174+ for (i = 0; i < curr->ip_num; i++) {
56175+ ip = *(curr->ips + i);
56176+ if (ip->iface != NULL) {
56177+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
56178+ p = strchr(iface, ':');
56179+ if (p != NULL)
56180+ *p = '\0';
56181+ dev = dev_get_by_name(sock_net(sk), iface);
56182+ if (dev == NULL)
56183+ continue;
56184+ idev = in_dev_get(dev);
56185+ if (idev == NULL) {
56186+ dev_put(dev);
56187+ continue;
56188+ }
56189+ rcu_read_lock();
56190+ for_ifa(idev) {
56191+ if (!strcmp(ip->iface, ifa->ifa_label)) {
56192+ our_addr = ifa->ifa_address;
56193+ our_netmask = 0xffffffff;
56194+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56195+ if (ret == 1) {
56196+ rcu_read_unlock();
56197+ in_dev_put(idev);
56198+ dev_put(dev);
56199+ return 0;
56200+ } else if (ret == 2) {
56201+ rcu_read_unlock();
56202+ in_dev_put(idev);
56203+ dev_put(dev);
56204+ goto denied;
56205+ }
56206+ }
56207+ } endfor_ifa(idev);
56208+ rcu_read_unlock();
56209+ in_dev_put(idev);
56210+ dev_put(dev);
56211+ } else {
56212+ our_addr = ip->addr;
56213+ our_netmask = ip->netmask;
56214+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56215+ if (ret == 1)
56216+ return 0;
56217+ else if (ret == 2)
56218+ goto denied;
56219+ }
56220+ }
56221+
56222+denied:
56223+ if (mode == GR_BIND)
56224+ 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));
56225+ else if (mode == GR_CONNECT)
56226+ 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));
56227+
56228+ return -EACCES;
56229+}
56230+
56231+int
56232+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56233+{
56234+ /* always allow disconnection of dgram sockets with connect */
56235+ if (addr->sin_family == AF_UNSPEC)
56236+ return 0;
56237+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56238+}
56239+
56240+int
56241+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56242+{
56243+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56244+}
56245+
56246+int gr_search_listen(struct socket *sock)
56247+{
56248+ struct sock *sk = sock->sk;
56249+ struct sockaddr_in addr;
56250+
56251+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56252+ addr.sin_port = inet_sk(sk)->inet_sport;
56253+
56254+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56255+}
56256+
56257+int gr_search_accept(struct socket *sock)
56258+{
56259+ struct sock *sk = sock->sk;
56260+ struct sockaddr_in addr;
56261+
56262+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56263+ addr.sin_port = inet_sk(sk)->inet_sport;
56264+
56265+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56266+}
56267+
56268+int
56269+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56270+{
56271+ if (addr)
56272+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56273+ else {
56274+ struct sockaddr_in sin;
56275+ const struct inet_sock *inet = inet_sk(sk);
56276+
56277+ sin.sin_addr.s_addr = inet->inet_daddr;
56278+ sin.sin_port = inet->inet_dport;
56279+
56280+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56281+ }
56282+}
56283+
56284+int
56285+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56286+{
56287+ struct sockaddr_in sin;
56288+
56289+ if (unlikely(skb->len < sizeof (struct udphdr)))
56290+ return 0; // skip this packet
56291+
56292+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56293+ sin.sin_port = udp_hdr(skb)->source;
56294+
56295+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56296+}
56297diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
56298new file mode 100644
56299index 0000000..25f54ef
56300--- /dev/null
56301+++ b/grsecurity/gracl_learn.c
56302@@ -0,0 +1,207 @@
56303+#include <linux/kernel.h>
56304+#include <linux/mm.h>
56305+#include <linux/sched.h>
56306+#include <linux/poll.h>
56307+#include <linux/string.h>
56308+#include <linux/file.h>
56309+#include <linux/types.h>
56310+#include <linux/vmalloc.h>
56311+#include <linux/grinternal.h>
56312+
56313+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56314+ size_t count, loff_t *ppos);
56315+extern int gr_acl_is_enabled(void);
56316+
56317+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56318+static int gr_learn_attached;
56319+
56320+/* use a 512k buffer */
56321+#define LEARN_BUFFER_SIZE (512 * 1024)
56322+
56323+static DEFINE_SPINLOCK(gr_learn_lock);
56324+static DEFINE_MUTEX(gr_learn_user_mutex);
56325+
56326+/* we need to maintain two buffers, so that the kernel context of grlearn
56327+ uses a semaphore around the userspace copying, and the other kernel contexts
56328+ use a spinlock when copying into the buffer, since they cannot sleep
56329+*/
56330+static char *learn_buffer;
56331+static char *learn_buffer_user;
56332+static int learn_buffer_len;
56333+static int learn_buffer_user_len;
56334+
56335+static ssize_t
56336+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56337+{
56338+ DECLARE_WAITQUEUE(wait, current);
56339+ ssize_t retval = 0;
56340+
56341+ add_wait_queue(&learn_wait, &wait);
56342+ set_current_state(TASK_INTERRUPTIBLE);
56343+ do {
56344+ mutex_lock(&gr_learn_user_mutex);
56345+ spin_lock(&gr_learn_lock);
56346+ if (learn_buffer_len)
56347+ break;
56348+ spin_unlock(&gr_learn_lock);
56349+ mutex_unlock(&gr_learn_user_mutex);
56350+ if (file->f_flags & O_NONBLOCK) {
56351+ retval = -EAGAIN;
56352+ goto out;
56353+ }
56354+ if (signal_pending(current)) {
56355+ retval = -ERESTARTSYS;
56356+ goto out;
56357+ }
56358+
56359+ schedule();
56360+ } while (1);
56361+
56362+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56363+ learn_buffer_user_len = learn_buffer_len;
56364+ retval = learn_buffer_len;
56365+ learn_buffer_len = 0;
56366+
56367+ spin_unlock(&gr_learn_lock);
56368+
56369+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56370+ retval = -EFAULT;
56371+
56372+ mutex_unlock(&gr_learn_user_mutex);
56373+out:
56374+ set_current_state(TASK_RUNNING);
56375+ remove_wait_queue(&learn_wait, &wait);
56376+ return retval;
56377+}
56378+
56379+static unsigned int
56380+poll_learn(struct file * file, poll_table * wait)
56381+{
56382+ poll_wait(file, &learn_wait, wait);
56383+
56384+ if (learn_buffer_len)
56385+ return (POLLIN | POLLRDNORM);
56386+
56387+ return 0;
56388+}
56389+
56390+void
56391+gr_clear_learn_entries(void)
56392+{
56393+ char *tmp;
56394+
56395+ mutex_lock(&gr_learn_user_mutex);
56396+ spin_lock(&gr_learn_lock);
56397+ tmp = learn_buffer;
56398+ learn_buffer = NULL;
56399+ spin_unlock(&gr_learn_lock);
56400+ if (tmp)
56401+ vfree(tmp);
56402+ if (learn_buffer_user != NULL) {
56403+ vfree(learn_buffer_user);
56404+ learn_buffer_user = NULL;
56405+ }
56406+ learn_buffer_len = 0;
56407+ mutex_unlock(&gr_learn_user_mutex);
56408+
56409+ return;
56410+}
56411+
56412+void
56413+gr_add_learn_entry(const char *fmt, ...)
56414+{
56415+ va_list args;
56416+ unsigned int len;
56417+
56418+ if (!gr_learn_attached)
56419+ return;
56420+
56421+ spin_lock(&gr_learn_lock);
56422+
56423+ /* leave a gap at the end so we know when it's "full" but don't have to
56424+ compute the exact length of the string we're trying to append
56425+ */
56426+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56427+ spin_unlock(&gr_learn_lock);
56428+ wake_up_interruptible(&learn_wait);
56429+ return;
56430+ }
56431+ if (learn_buffer == NULL) {
56432+ spin_unlock(&gr_learn_lock);
56433+ return;
56434+ }
56435+
56436+ va_start(args, fmt);
56437+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56438+ va_end(args);
56439+
56440+ learn_buffer_len += len + 1;
56441+
56442+ spin_unlock(&gr_learn_lock);
56443+ wake_up_interruptible(&learn_wait);
56444+
56445+ return;
56446+}
56447+
56448+static int
56449+open_learn(struct inode *inode, struct file *file)
56450+{
56451+ if (file->f_mode & FMODE_READ && gr_learn_attached)
56452+ return -EBUSY;
56453+ if (file->f_mode & FMODE_READ) {
56454+ int retval = 0;
56455+ mutex_lock(&gr_learn_user_mutex);
56456+ if (learn_buffer == NULL)
56457+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56458+ if (learn_buffer_user == NULL)
56459+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56460+ if (learn_buffer == NULL) {
56461+ retval = -ENOMEM;
56462+ goto out_error;
56463+ }
56464+ if (learn_buffer_user == NULL) {
56465+ retval = -ENOMEM;
56466+ goto out_error;
56467+ }
56468+ learn_buffer_len = 0;
56469+ learn_buffer_user_len = 0;
56470+ gr_learn_attached = 1;
56471+out_error:
56472+ mutex_unlock(&gr_learn_user_mutex);
56473+ return retval;
56474+ }
56475+ return 0;
56476+}
56477+
56478+static int
56479+close_learn(struct inode *inode, struct file *file)
56480+{
56481+ if (file->f_mode & FMODE_READ) {
56482+ char *tmp = NULL;
56483+ mutex_lock(&gr_learn_user_mutex);
56484+ spin_lock(&gr_learn_lock);
56485+ tmp = learn_buffer;
56486+ learn_buffer = NULL;
56487+ spin_unlock(&gr_learn_lock);
56488+ if (tmp)
56489+ vfree(tmp);
56490+ if (learn_buffer_user != NULL) {
56491+ vfree(learn_buffer_user);
56492+ learn_buffer_user = NULL;
56493+ }
56494+ learn_buffer_len = 0;
56495+ learn_buffer_user_len = 0;
56496+ gr_learn_attached = 0;
56497+ mutex_unlock(&gr_learn_user_mutex);
56498+ }
56499+
56500+ return 0;
56501+}
56502+
56503+const struct file_operations grsec_fops = {
56504+ .read = read_learn,
56505+ .write = write_grsec_handler,
56506+ .open = open_learn,
56507+ .release = close_learn,
56508+ .poll = poll_learn,
56509+};
56510diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
56511new file mode 100644
56512index 0000000..39645c9
56513--- /dev/null
56514+++ b/grsecurity/gracl_res.c
56515@@ -0,0 +1,68 @@
56516+#include <linux/kernel.h>
56517+#include <linux/sched.h>
56518+#include <linux/gracl.h>
56519+#include <linux/grinternal.h>
56520+
56521+static const char *restab_log[] = {
56522+ [RLIMIT_CPU] = "RLIMIT_CPU",
56523+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56524+ [RLIMIT_DATA] = "RLIMIT_DATA",
56525+ [RLIMIT_STACK] = "RLIMIT_STACK",
56526+ [RLIMIT_CORE] = "RLIMIT_CORE",
56527+ [RLIMIT_RSS] = "RLIMIT_RSS",
56528+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
56529+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56530+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56531+ [RLIMIT_AS] = "RLIMIT_AS",
56532+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56533+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56534+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56535+ [RLIMIT_NICE] = "RLIMIT_NICE",
56536+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56537+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56538+ [GR_CRASH_RES] = "RLIMIT_CRASH"
56539+};
56540+
56541+void
56542+gr_log_resource(const struct task_struct *task,
56543+ const int res, const unsigned long wanted, const int gt)
56544+{
56545+ const struct cred *cred;
56546+ unsigned long rlim;
56547+
56548+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
56549+ return;
56550+
56551+ // not yet supported resource
56552+ if (unlikely(!restab_log[res]))
56553+ return;
56554+
56555+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56556+ rlim = task_rlimit_max(task, res);
56557+ else
56558+ rlim = task_rlimit(task, res);
56559+
56560+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
56561+ return;
56562+
56563+ rcu_read_lock();
56564+ cred = __task_cred(task);
56565+
56566+ if (res == RLIMIT_NPROC &&
56567+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
56568+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
56569+ goto out_rcu_unlock;
56570+ else if (res == RLIMIT_MEMLOCK &&
56571+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
56572+ goto out_rcu_unlock;
56573+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
56574+ goto out_rcu_unlock;
56575+ rcu_read_unlock();
56576+
56577+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
56578+
56579+ return;
56580+out_rcu_unlock:
56581+ rcu_read_unlock();
56582+ return;
56583+}
56584diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
56585new file mode 100644
56586index 0000000..25197e9
56587--- /dev/null
56588+++ b/grsecurity/gracl_segv.c
56589@@ -0,0 +1,299 @@
56590+#include <linux/kernel.h>
56591+#include <linux/mm.h>
56592+#include <asm/uaccess.h>
56593+#include <asm/errno.h>
56594+#include <asm/mman.h>
56595+#include <net/sock.h>
56596+#include <linux/file.h>
56597+#include <linux/fs.h>
56598+#include <linux/net.h>
56599+#include <linux/in.h>
56600+#include <linux/slab.h>
56601+#include <linux/types.h>
56602+#include <linux/sched.h>
56603+#include <linux/timer.h>
56604+#include <linux/gracl.h>
56605+#include <linux/grsecurity.h>
56606+#include <linux/grinternal.h>
56607+
56608+static struct crash_uid *uid_set;
56609+static unsigned short uid_used;
56610+static DEFINE_SPINLOCK(gr_uid_lock);
56611+extern rwlock_t gr_inode_lock;
56612+extern struct acl_subject_label *
56613+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
56614+ struct acl_role_label *role);
56615+
56616+#ifdef CONFIG_BTRFS_FS
56617+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56618+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56619+#endif
56620+
56621+static inline dev_t __get_dev(const struct dentry *dentry)
56622+{
56623+#ifdef CONFIG_BTRFS_FS
56624+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56625+ return get_btrfs_dev_from_inode(dentry->d_inode);
56626+ else
56627+#endif
56628+ return dentry->d_inode->i_sb->s_dev;
56629+}
56630+
56631+int
56632+gr_init_uidset(void)
56633+{
56634+ uid_set =
56635+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56636+ uid_used = 0;
56637+
56638+ return uid_set ? 1 : 0;
56639+}
56640+
56641+void
56642+gr_free_uidset(void)
56643+{
56644+ if (uid_set)
56645+ kfree(uid_set);
56646+
56647+ return;
56648+}
56649+
56650+int
56651+gr_find_uid(const uid_t uid)
56652+{
56653+ struct crash_uid *tmp = uid_set;
56654+ uid_t buid;
56655+ int low = 0, high = uid_used - 1, mid;
56656+
56657+ while (high >= low) {
56658+ mid = (low + high) >> 1;
56659+ buid = tmp[mid].uid;
56660+ if (buid == uid)
56661+ return mid;
56662+ if (buid > uid)
56663+ high = mid - 1;
56664+ if (buid < uid)
56665+ low = mid + 1;
56666+ }
56667+
56668+ return -1;
56669+}
56670+
56671+static __inline__ void
56672+gr_insertsort(void)
56673+{
56674+ unsigned short i, j;
56675+ struct crash_uid index;
56676+
56677+ for (i = 1; i < uid_used; i++) {
56678+ index = uid_set[i];
56679+ j = i;
56680+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
56681+ uid_set[j] = uid_set[j - 1];
56682+ j--;
56683+ }
56684+ uid_set[j] = index;
56685+ }
56686+
56687+ return;
56688+}
56689+
56690+static __inline__ void
56691+gr_insert_uid(const uid_t uid, const unsigned long expires)
56692+{
56693+ int loc;
56694+
56695+ if (uid_used == GR_UIDTABLE_MAX)
56696+ return;
56697+
56698+ loc = gr_find_uid(uid);
56699+
56700+ if (loc >= 0) {
56701+ uid_set[loc].expires = expires;
56702+ return;
56703+ }
56704+
56705+ uid_set[uid_used].uid = uid;
56706+ uid_set[uid_used].expires = expires;
56707+ uid_used++;
56708+
56709+ gr_insertsort();
56710+
56711+ return;
56712+}
56713+
56714+void
56715+gr_remove_uid(const unsigned short loc)
56716+{
56717+ unsigned short i;
56718+
56719+ for (i = loc + 1; i < uid_used; i++)
56720+ uid_set[i - 1] = uid_set[i];
56721+
56722+ uid_used--;
56723+
56724+ return;
56725+}
56726+
56727+int
56728+gr_check_crash_uid(const uid_t uid)
56729+{
56730+ int loc;
56731+ int ret = 0;
56732+
56733+ if (unlikely(!gr_acl_is_enabled()))
56734+ return 0;
56735+
56736+ spin_lock(&gr_uid_lock);
56737+ loc = gr_find_uid(uid);
56738+
56739+ if (loc < 0)
56740+ goto out_unlock;
56741+
56742+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
56743+ gr_remove_uid(loc);
56744+ else
56745+ ret = 1;
56746+
56747+out_unlock:
56748+ spin_unlock(&gr_uid_lock);
56749+ return ret;
56750+}
56751+
56752+static __inline__ int
56753+proc_is_setxid(const struct cred *cred)
56754+{
56755+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
56756+ !uid_eq(cred->uid, cred->fsuid))
56757+ return 1;
56758+ if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
56759+ !uid_eq(cred->gid, cred->fsgid))
56760+ return 1;
56761+
56762+ return 0;
56763+}
56764+
56765+extern int gr_fake_force_sig(int sig, struct task_struct *t);
56766+
56767+void
56768+gr_handle_crash(struct task_struct *task, const int sig)
56769+{
56770+ struct acl_subject_label *curr;
56771+ struct task_struct *tsk, *tsk2;
56772+ const struct cred *cred;
56773+ const struct cred *cred2;
56774+
56775+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
56776+ return;
56777+
56778+ if (unlikely(!gr_acl_is_enabled()))
56779+ return;
56780+
56781+ curr = task->acl;
56782+
56783+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
56784+ return;
56785+
56786+ if (time_before_eq(curr->expires, get_seconds())) {
56787+ curr->expires = 0;
56788+ curr->crashes = 0;
56789+ }
56790+
56791+ curr->crashes++;
56792+
56793+ if (!curr->expires)
56794+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
56795+
56796+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56797+ time_after(curr->expires, get_seconds())) {
56798+ rcu_read_lock();
56799+ cred = __task_cred(task);
56800+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
56801+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56802+ spin_lock(&gr_uid_lock);
56803+ gr_insert_uid(cred->uid, curr->expires);
56804+ spin_unlock(&gr_uid_lock);
56805+ curr->expires = 0;
56806+ curr->crashes = 0;
56807+ read_lock(&tasklist_lock);
56808+ do_each_thread(tsk2, tsk) {
56809+ cred2 = __task_cred(tsk);
56810+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
56811+ gr_fake_force_sig(SIGKILL, tsk);
56812+ } while_each_thread(tsk2, tsk);
56813+ read_unlock(&tasklist_lock);
56814+ } else {
56815+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56816+ read_lock(&tasklist_lock);
56817+ read_lock(&grsec_exec_file_lock);
56818+ do_each_thread(tsk2, tsk) {
56819+ if (likely(tsk != task)) {
56820+ // if this thread has the same subject as the one that triggered
56821+ // RES_CRASH and it's the same binary, kill it
56822+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
56823+ gr_fake_force_sig(SIGKILL, tsk);
56824+ }
56825+ } while_each_thread(tsk2, tsk);
56826+ read_unlock(&grsec_exec_file_lock);
56827+ read_unlock(&tasklist_lock);
56828+ }
56829+ rcu_read_unlock();
56830+ }
56831+
56832+ return;
56833+}
56834+
56835+int
56836+gr_check_crash_exec(const struct file *filp)
56837+{
56838+ struct acl_subject_label *curr;
56839+
56840+ if (unlikely(!gr_acl_is_enabled()))
56841+ return 0;
56842+
56843+ read_lock(&gr_inode_lock);
56844+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
56845+ __get_dev(filp->f_path.dentry),
56846+ current->role);
56847+ read_unlock(&gr_inode_lock);
56848+
56849+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
56850+ (!curr->crashes && !curr->expires))
56851+ return 0;
56852+
56853+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56854+ time_after(curr->expires, get_seconds()))
56855+ return 1;
56856+ else if (time_before_eq(curr->expires, get_seconds())) {
56857+ curr->crashes = 0;
56858+ curr->expires = 0;
56859+ }
56860+
56861+ return 0;
56862+}
56863+
56864+void
56865+gr_handle_alertkill(struct task_struct *task)
56866+{
56867+ struct acl_subject_label *curracl;
56868+ __u32 curr_ip;
56869+ struct task_struct *p, *p2;
56870+
56871+ if (unlikely(!gr_acl_is_enabled()))
56872+ return;
56873+
56874+ curracl = task->acl;
56875+ curr_ip = task->signal->curr_ip;
56876+
56877+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
56878+ read_lock(&tasklist_lock);
56879+ do_each_thread(p2, p) {
56880+ if (p->signal->curr_ip == curr_ip)
56881+ gr_fake_force_sig(SIGKILL, p);
56882+ } while_each_thread(p2, p);
56883+ read_unlock(&tasklist_lock);
56884+ } else if (curracl->mode & GR_KILLPROC)
56885+ gr_fake_force_sig(SIGKILL, task);
56886+
56887+ return;
56888+}
56889diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
56890new file mode 100644
56891index 0000000..9d83a69
56892--- /dev/null
56893+++ b/grsecurity/gracl_shm.c
56894@@ -0,0 +1,40 @@
56895+#include <linux/kernel.h>
56896+#include <linux/mm.h>
56897+#include <linux/sched.h>
56898+#include <linux/file.h>
56899+#include <linux/ipc.h>
56900+#include <linux/gracl.h>
56901+#include <linux/grsecurity.h>
56902+#include <linux/grinternal.h>
56903+
56904+int
56905+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56906+ const time_t shm_createtime, const uid_t cuid, const int shmid)
56907+{
56908+ struct task_struct *task;
56909+
56910+ if (!gr_acl_is_enabled())
56911+ return 1;
56912+
56913+ rcu_read_lock();
56914+ read_lock(&tasklist_lock);
56915+
56916+ task = find_task_by_vpid(shm_cprid);
56917+
56918+ if (unlikely(!task))
56919+ task = find_task_by_vpid(shm_lapid);
56920+
56921+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
56922+ (task->pid == shm_lapid)) &&
56923+ (task->acl->mode & GR_PROTSHM) &&
56924+ (task->acl != current->acl))) {
56925+ read_unlock(&tasklist_lock);
56926+ rcu_read_unlock();
56927+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
56928+ return 0;
56929+ }
56930+ read_unlock(&tasklist_lock);
56931+ rcu_read_unlock();
56932+
56933+ return 1;
56934+}
56935diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
56936new file mode 100644
56937index 0000000..bc0be01
56938--- /dev/null
56939+++ b/grsecurity/grsec_chdir.c
56940@@ -0,0 +1,19 @@
56941+#include <linux/kernel.h>
56942+#include <linux/sched.h>
56943+#include <linux/fs.h>
56944+#include <linux/file.h>
56945+#include <linux/grsecurity.h>
56946+#include <linux/grinternal.h>
56947+
56948+void
56949+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
56950+{
56951+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
56952+ if ((grsec_enable_chdir && grsec_enable_group &&
56953+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
56954+ !grsec_enable_group)) {
56955+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
56956+ }
56957+#endif
56958+ return;
56959+}
56960diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
56961new file mode 100644
56962index 0000000..9807ee2
56963--- /dev/null
56964+++ b/grsecurity/grsec_chroot.c
56965@@ -0,0 +1,368 @@
56966+#include <linux/kernel.h>
56967+#include <linux/module.h>
56968+#include <linux/sched.h>
56969+#include <linux/file.h>
56970+#include <linux/fs.h>
56971+#include <linux/mount.h>
56972+#include <linux/types.h>
56973+#include "../fs/mount.h"
56974+#include <linux/grsecurity.h>
56975+#include <linux/grinternal.h>
56976+
56977+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
56978+{
56979+#ifdef CONFIG_GRKERNSEC
56980+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
56981+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
56982+ task->gr_is_chrooted = 1;
56983+ else
56984+ task->gr_is_chrooted = 0;
56985+
56986+ task->gr_chroot_dentry = path->dentry;
56987+#endif
56988+ return;
56989+}
56990+
56991+void gr_clear_chroot_entries(struct task_struct *task)
56992+{
56993+#ifdef CONFIG_GRKERNSEC
56994+ task->gr_is_chrooted = 0;
56995+ task->gr_chroot_dentry = NULL;
56996+#endif
56997+ return;
56998+}
56999+
57000+int
57001+gr_handle_chroot_unix(const pid_t pid)
57002+{
57003+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57004+ struct task_struct *p;
57005+
57006+ if (unlikely(!grsec_enable_chroot_unix))
57007+ return 1;
57008+
57009+ if (likely(!proc_is_chrooted(current)))
57010+ return 1;
57011+
57012+ rcu_read_lock();
57013+ read_lock(&tasklist_lock);
57014+ p = find_task_by_vpid_unrestricted(pid);
57015+ if (unlikely(p && !have_same_root(current, p))) {
57016+ read_unlock(&tasklist_lock);
57017+ rcu_read_unlock();
57018+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
57019+ return 0;
57020+ }
57021+ read_unlock(&tasklist_lock);
57022+ rcu_read_unlock();
57023+#endif
57024+ return 1;
57025+}
57026+
57027+int
57028+gr_handle_chroot_nice(void)
57029+{
57030+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57031+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
57032+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
57033+ return -EPERM;
57034+ }
57035+#endif
57036+ return 0;
57037+}
57038+
57039+int
57040+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
57041+{
57042+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57043+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
57044+ && proc_is_chrooted(current)) {
57045+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
57046+ return -EACCES;
57047+ }
57048+#endif
57049+ return 0;
57050+}
57051+
57052+int
57053+gr_handle_chroot_rawio(const struct inode *inode)
57054+{
57055+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57056+ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57057+ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
57058+ return 1;
57059+#endif
57060+ return 0;
57061+}
57062+
57063+int
57064+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
57065+{
57066+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57067+ struct task_struct *p;
57068+ int ret = 0;
57069+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
57070+ return ret;
57071+
57072+ read_lock(&tasklist_lock);
57073+ do_each_pid_task(pid, type, p) {
57074+ if (!have_same_root(current, p)) {
57075+ ret = 1;
57076+ goto out;
57077+ }
57078+ } while_each_pid_task(pid, type, p);
57079+out:
57080+ read_unlock(&tasklist_lock);
57081+ return ret;
57082+#endif
57083+ return 0;
57084+}
57085+
57086+int
57087+gr_pid_is_chrooted(struct task_struct *p)
57088+{
57089+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57090+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
57091+ return 0;
57092+
57093+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
57094+ !have_same_root(current, p)) {
57095+ return 1;
57096+ }
57097+#endif
57098+ return 0;
57099+}
57100+
57101+EXPORT_SYMBOL(gr_pid_is_chrooted);
57102+
57103+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
57104+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
57105+{
57106+ struct path path, currentroot;
57107+ int ret = 0;
57108+
57109+ path.dentry = (struct dentry *)u_dentry;
57110+ path.mnt = (struct vfsmount *)u_mnt;
57111+ get_fs_root(current->fs, &currentroot);
57112+ if (path_is_under(&path, &currentroot))
57113+ ret = 1;
57114+ path_put(&currentroot);
57115+
57116+ return ret;
57117+}
57118+#endif
57119+
57120+int
57121+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
57122+{
57123+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57124+ if (!grsec_enable_chroot_fchdir)
57125+ return 1;
57126+
57127+ if (!proc_is_chrooted(current))
57128+ return 1;
57129+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
57130+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
57131+ return 0;
57132+ }
57133+#endif
57134+ return 1;
57135+}
57136+
57137+int
57138+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57139+ const time_t shm_createtime)
57140+{
57141+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57142+ struct task_struct *p;
57143+ time_t starttime;
57144+
57145+ if (unlikely(!grsec_enable_chroot_shmat))
57146+ return 1;
57147+
57148+ if (likely(!proc_is_chrooted(current)))
57149+ return 1;
57150+
57151+ rcu_read_lock();
57152+ read_lock(&tasklist_lock);
57153+
57154+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
57155+ starttime = p->start_time.tv_sec;
57156+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
57157+ if (have_same_root(current, p)) {
57158+ goto allow;
57159+ } else {
57160+ read_unlock(&tasklist_lock);
57161+ rcu_read_unlock();
57162+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57163+ return 0;
57164+ }
57165+ }
57166+ /* creator exited, pid reuse, fall through to next check */
57167+ }
57168+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
57169+ if (unlikely(!have_same_root(current, p))) {
57170+ read_unlock(&tasklist_lock);
57171+ rcu_read_unlock();
57172+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57173+ return 0;
57174+ }
57175+ }
57176+
57177+allow:
57178+ read_unlock(&tasklist_lock);
57179+ rcu_read_unlock();
57180+#endif
57181+ return 1;
57182+}
57183+
57184+void
57185+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
57186+{
57187+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57188+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
57189+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
57190+#endif
57191+ return;
57192+}
57193+
57194+int
57195+gr_handle_chroot_mknod(const struct dentry *dentry,
57196+ const struct vfsmount *mnt, const int mode)
57197+{
57198+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57199+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
57200+ proc_is_chrooted(current)) {
57201+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57202+ return -EPERM;
57203+ }
57204+#endif
57205+ return 0;
57206+}
57207+
57208+int
57209+gr_handle_chroot_mount(const struct dentry *dentry,
57210+ const struct vfsmount *mnt, const char *dev_name)
57211+{
57212+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57213+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57214+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
57215+ return -EPERM;
57216+ }
57217+#endif
57218+ return 0;
57219+}
57220+
57221+int
57222+gr_handle_chroot_pivot(void)
57223+{
57224+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57225+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57226+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57227+ return -EPERM;
57228+ }
57229+#endif
57230+ return 0;
57231+}
57232+
57233+int
57234+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57235+{
57236+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57237+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57238+ !gr_is_outside_chroot(dentry, mnt)) {
57239+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57240+ return -EPERM;
57241+ }
57242+#endif
57243+ return 0;
57244+}
57245+
57246+extern const char *captab_log[];
57247+extern int captab_log_entries;
57248+
57249+int
57250+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57251+{
57252+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57253+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57254+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57255+ if (cap_raised(chroot_caps, cap)) {
57256+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
57257+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
57258+ }
57259+ return 0;
57260+ }
57261+ }
57262+#endif
57263+ return 1;
57264+}
57265+
57266+int
57267+gr_chroot_is_capable(const int cap)
57268+{
57269+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57270+ return gr_task_chroot_is_capable(current, current_cred(), cap);
57271+#endif
57272+ return 1;
57273+}
57274+
57275+int
57276+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
57277+{
57278+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57279+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57280+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57281+ if (cap_raised(chroot_caps, cap)) {
57282+ return 0;
57283+ }
57284+ }
57285+#endif
57286+ return 1;
57287+}
57288+
57289+int
57290+gr_chroot_is_capable_nolog(const int cap)
57291+{
57292+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57293+ return gr_task_chroot_is_capable_nolog(current, cap);
57294+#endif
57295+ return 1;
57296+}
57297+
57298+int
57299+gr_handle_chroot_sysctl(const int op)
57300+{
57301+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57302+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57303+ proc_is_chrooted(current))
57304+ return -EACCES;
57305+#endif
57306+ return 0;
57307+}
57308+
57309+void
57310+gr_handle_chroot_chdir(struct path *path)
57311+{
57312+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57313+ if (grsec_enable_chroot_chdir)
57314+ set_fs_pwd(current->fs, path);
57315+#endif
57316+ return;
57317+}
57318+
57319+int
57320+gr_handle_chroot_chmod(const struct dentry *dentry,
57321+ const struct vfsmount *mnt, const int mode)
57322+{
57323+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57324+ /* allow chmod +s on directories, but not files */
57325+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57326+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57327+ proc_is_chrooted(current)) {
57328+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57329+ return -EPERM;
57330+ }
57331+#endif
57332+ return 0;
57333+}
57334diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
57335new file mode 100644
57336index 0000000..213ad8b
57337--- /dev/null
57338+++ b/grsecurity/grsec_disabled.c
57339@@ -0,0 +1,437 @@
57340+#include <linux/kernel.h>
57341+#include <linux/module.h>
57342+#include <linux/sched.h>
57343+#include <linux/file.h>
57344+#include <linux/fs.h>
57345+#include <linux/kdev_t.h>
57346+#include <linux/net.h>
57347+#include <linux/in.h>
57348+#include <linux/ip.h>
57349+#include <linux/skbuff.h>
57350+#include <linux/sysctl.h>
57351+
57352+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57353+void
57354+pax_set_initial_flags(struct linux_binprm *bprm)
57355+{
57356+ return;
57357+}
57358+#endif
57359+
57360+#ifdef CONFIG_SYSCTL
57361+__u32
57362+gr_handle_sysctl(const struct ctl_table * table, const int op)
57363+{
57364+ return 0;
57365+}
57366+#endif
57367+
57368+#ifdef CONFIG_TASKSTATS
57369+int gr_is_taskstats_denied(int pid)
57370+{
57371+ return 0;
57372+}
57373+#endif
57374+
57375+int
57376+gr_acl_is_enabled(void)
57377+{
57378+ return 0;
57379+}
57380+
57381+void
57382+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57383+{
57384+ return;
57385+}
57386+
57387+int
57388+gr_handle_rawio(const struct inode *inode)
57389+{
57390+ return 0;
57391+}
57392+
57393+void
57394+gr_acl_handle_psacct(struct task_struct *task, const long code)
57395+{
57396+ return;
57397+}
57398+
57399+int
57400+gr_handle_ptrace(struct task_struct *task, const long request)
57401+{
57402+ return 0;
57403+}
57404+
57405+int
57406+gr_handle_proc_ptrace(struct task_struct *task)
57407+{
57408+ return 0;
57409+}
57410+
57411+void
57412+gr_learn_resource(const struct task_struct *task,
57413+ const int res, const unsigned long wanted, const int gt)
57414+{
57415+ return;
57416+}
57417+
57418+int
57419+gr_set_acls(const int type)
57420+{
57421+ return 0;
57422+}
57423+
57424+int
57425+gr_check_hidden_task(const struct task_struct *tsk)
57426+{
57427+ return 0;
57428+}
57429+
57430+int
57431+gr_check_protected_task(const struct task_struct *task)
57432+{
57433+ return 0;
57434+}
57435+
57436+int
57437+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57438+{
57439+ return 0;
57440+}
57441+
57442+void
57443+gr_copy_label(struct task_struct *tsk)
57444+{
57445+ return;
57446+}
57447+
57448+void
57449+gr_set_pax_flags(struct task_struct *task)
57450+{
57451+ return;
57452+}
57453+
57454+int
57455+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57456+ const int unsafe_share)
57457+{
57458+ return 0;
57459+}
57460+
57461+void
57462+gr_handle_delete(const ino_t ino, const dev_t dev)
57463+{
57464+ return;
57465+}
57466+
57467+void
57468+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57469+{
57470+ return;
57471+}
57472+
57473+void
57474+gr_handle_crash(struct task_struct *task, const int sig)
57475+{
57476+ return;
57477+}
57478+
57479+int
57480+gr_check_crash_exec(const struct file *filp)
57481+{
57482+ return 0;
57483+}
57484+
57485+int
57486+gr_check_crash_uid(const uid_t uid)
57487+{
57488+ return 0;
57489+}
57490+
57491+void
57492+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57493+ struct dentry *old_dentry,
57494+ struct dentry *new_dentry,
57495+ struct vfsmount *mnt, const __u8 replace)
57496+{
57497+ return;
57498+}
57499+
57500+int
57501+gr_search_socket(const int family, const int type, const int protocol)
57502+{
57503+ return 1;
57504+}
57505+
57506+int
57507+gr_search_connectbind(const int mode, const struct socket *sock,
57508+ const struct sockaddr_in *addr)
57509+{
57510+ return 0;
57511+}
57512+
57513+void
57514+gr_handle_alertkill(struct task_struct *task)
57515+{
57516+ return;
57517+}
57518+
57519+__u32
57520+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57521+{
57522+ return 1;
57523+}
57524+
57525+__u32
57526+gr_acl_handle_hidden_file(const struct dentry * dentry,
57527+ const struct vfsmount * mnt)
57528+{
57529+ return 1;
57530+}
57531+
57532+__u32
57533+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57534+ int acc_mode)
57535+{
57536+ return 1;
57537+}
57538+
57539+__u32
57540+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57541+{
57542+ return 1;
57543+}
57544+
57545+__u32
57546+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57547+{
57548+ return 1;
57549+}
57550+
57551+int
57552+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57553+ unsigned int *vm_flags)
57554+{
57555+ return 1;
57556+}
57557+
57558+__u32
57559+gr_acl_handle_truncate(const struct dentry * dentry,
57560+ const struct vfsmount * mnt)
57561+{
57562+ return 1;
57563+}
57564+
57565+__u32
57566+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
57567+{
57568+ return 1;
57569+}
57570+
57571+__u32
57572+gr_acl_handle_access(const struct dentry * dentry,
57573+ const struct vfsmount * mnt, const int fmode)
57574+{
57575+ return 1;
57576+}
57577+
57578+__u32
57579+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
57580+ umode_t *mode)
57581+{
57582+ return 1;
57583+}
57584+
57585+__u32
57586+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
57587+{
57588+ return 1;
57589+}
57590+
57591+__u32
57592+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
57593+{
57594+ return 1;
57595+}
57596+
57597+void
57598+grsecurity_init(void)
57599+{
57600+ return;
57601+}
57602+
57603+umode_t gr_acl_umask(void)
57604+{
57605+ return 0;
57606+}
57607+
57608+__u32
57609+gr_acl_handle_mknod(const struct dentry * new_dentry,
57610+ const struct dentry * parent_dentry,
57611+ const struct vfsmount * parent_mnt,
57612+ const int mode)
57613+{
57614+ return 1;
57615+}
57616+
57617+__u32
57618+gr_acl_handle_mkdir(const struct dentry * new_dentry,
57619+ const struct dentry * parent_dentry,
57620+ const struct vfsmount * parent_mnt)
57621+{
57622+ return 1;
57623+}
57624+
57625+__u32
57626+gr_acl_handle_symlink(const struct dentry * new_dentry,
57627+ const struct dentry * parent_dentry,
57628+ const struct vfsmount * parent_mnt, const char *from)
57629+{
57630+ return 1;
57631+}
57632+
57633+__u32
57634+gr_acl_handle_link(const struct dentry * new_dentry,
57635+ const struct dentry * parent_dentry,
57636+ const struct vfsmount * parent_mnt,
57637+ const struct dentry * old_dentry,
57638+ const struct vfsmount * old_mnt, const char *to)
57639+{
57640+ return 1;
57641+}
57642+
57643+int
57644+gr_acl_handle_rename(const struct dentry *new_dentry,
57645+ const struct dentry *parent_dentry,
57646+ const struct vfsmount *parent_mnt,
57647+ const struct dentry *old_dentry,
57648+ const struct inode *old_parent_inode,
57649+ const struct vfsmount *old_mnt, const char *newname)
57650+{
57651+ return 0;
57652+}
57653+
57654+int
57655+gr_acl_handle_filldir(const struct file *file, const char *name,
57656+ const int namelen, const ino_t ino)
57657+{
57658+ return 1;
57659+}
57660+
57661+int
57662+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57663+ const time_t shm_createtime, const uid_t cuid, const int shmid)
57664+{
57665+ return 1;
57666+}
57667+
57668+int
57669+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
57670+{
57671+ return 0;
57672+}
57673+
57674+int
57675+gr_search_accept(const struct socket *sock)
57676+{
57677+ return 0;
57678+}
57679+
57680+int
57681+gr_search_listen(const struct socket *sock)
57682+{
57683+ return 0;
57684+}
57685+
57686+int
57687+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
57688+{
57689+ return 0;
57690+}
57691+
57692+__u32
57693+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
57694+{
57695+ return 1;
57696+}
57697+
57698+__u32
57699+gr_acl_handle_creat(const struct dentry * dentry,
57700+ const struct dentry * p_dentry,
57701+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
57702+ const int imode)
57703+{
57704+ return 1;
57705+}
57706+
57707+void
57708+gr_acl_handle_exit(void)
57709+{
57710+ return;
57711+}
57712+
57713+int
57714+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57715+{
57716+ return 1;
57717+}
57718+
57719+void
57720+gr_set_role_label(const uid_t uid, const gid_t gid)
57721+{
57722+ return;
57723+}
57724+
57725+int
57726+gr_acl_handle_procpidmem(const struct task_struct *task)
57727+{
57728+ return 0;
57729+}
57730+
57731+int
57732+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
57733+{
57734+ return 0;
57735+}
57736+
57737+int
57738+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
57739+{
57740+ return 0;
57741+}
57742+
57743+void
57744+gr_set_kernel_label(struct task_struct *task)
57745+{
57746+ return;
57747+}
57748+
57749+int
57750+gr_check_user_change(int real, int effective, int fs)
57751+{
57752+ return 0;
57753+}
57754+
57755+int
57756+gr_check_group_change(int real, int effective, int fs)
57757+{
57758+ return 0;
57759+}
57760+
57761+int gr_acl_enable_at_secure(void)
57762+{
57763+ return 0;
57764+}
57765+
57766+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57767+{
57768+ return dentry->d_inode->i_sb->s_dev;
57769+}
57770+
57771+EXPORT_SYMBOL(gr_learn_resource);
57772+EXPORT_SYMBOL(gr_set_kernel_label);
57773+#ifdef CONFIG_SECURITY
57774+EXPORT_SYMBOL(gr_check_user_change);
57775+EXPORT_SYMBOL(gr_check_group_change);
57776+#endif
57777diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
57778new file mode 100644
57779index 0000000..abfa971
57780--- /dev/null
57781+++ b/grsecurity/grsec_exec.c
57782@@ -0,0 +1,174 @@
57783+#include <linux/kernel.h>
57784+#include <linux/sched.h>
57785+#include <linux/file.h>
57786+#include <linux/binfmts.h>
57787+#include <linux/fs.h>
57788+#include <linux/types.h>
57789+#include <linux/grdefs.h>
57790+#include <linux/grsecurity.h>
57791+#include <linux/grinternal.h>
57792+#include <linux/capability.h>
57793+#include <linux/module.h>
57794+
57795+#include <asm/uaccess.h>
57796+
57797+#ifdef CONFIG_GRKERNSEC_EXECLOG
57798+static char gr_exec_arg_buf[132];
57799+static DEFINE_MUTEX(gr_exec_arg_mutex);
57800+#endif
57801+
57802+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
57803+
57804+void
57805+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
57806+{
57807+#ifdef CONFIG_GRKERNSEC_EXECLOG
57808+ char *grarg = gr_exec_arg_buf;
57809+ unsigned int i, x, execlen = 0;
57810+ char c;
57811+
57812+ if (!((grsec_enable_execlog && grsec_enable_group &&
57813+ in_group_p(grsec_audit_gid))
57814+ || (grsec_enable_execlog && !grsec_enable_group)))
57815+ return;
57816+
57817+ mutex_lock(&gr_exec_arg_mutex);
57818+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
57819+
57820+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
57821+ const char __user *p;
57822+ unsigned int len;
57823+
57824+ p = get_user_arg_ptr(argv, i);
57825+ if (IS_ERR(p))
57826+ goto log;
57827+
57828+ len = strnlen_user(p, 128 - execlen);
57829+ if (len > 128 - execlen)
57830+ len = 128 - execlen;
57831+ else if (len > 0)
57832+ len--;
57833+ if (copy_from_user(grarg + execlen, p, len))
57834+ goto log;
57835+
57836+ /* rewrite unprintable characters */
57837+ for (x = 0; x < len; x++) {
57838+ c = *(grarg + execlen + x);
57839+ if (c < 32 || c > 126)
57840+ *(grarg + execlen + x) = ' ';
57841+ }
57842+
57843+ execlen += len;
57844+ *(grarg + execlen) = ' ';
57845+ *(grarg + execlen + 1) = '\0';
57846+ execlen++;
57847+ }
57848+
57849+ log:
57850+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
57851+ bprm->file->f_path.mnt, grarg);
57852+ mutex_unlock(&gr_exec_arg_mutex);
57853+#endif
57854+ return;
57855+}
57856+
57857+#ifdef CONFIG_GRKERNSEC
57858+extern int gr_acl_is_capable(const int cap);
57859+extern int gr_acl_is_capable_nolog(const int cap);
57860+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57861+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
57862+extern int gr_chroot_is_capable(const int cap);
57863+extern int gr_chroot_is_capable_nolog(const int cap);
57864+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57865+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
57866+#endif
57867+
57868+const char *captab_log[] = {
57869+ "CAP_CHOWN",
57870+ "CAP_DAC_OVERRIDE",
57871+ "CAP_DAC_READ_SEARCH",
57872+ "CAP_FOWNER",
57873+ "CAP_FSETID",
57874+ "CAP_KILL",
57875+ "CAP_SETGID",
57876+ "CAP_SETUID",
57877+ "CAP_SETPCAP",
57878+ "CAP_LINUX_IMMUTABLE",
57879+ "CAP_NET_BIND_SERVICE",
57880+ "CAP_NET_BROADCAST",
57881+ "CAP_NET_ADMIN",
57882+ "CAP_NET_RAW",
57883+ "CAP_IPC_LOCK",
57884+ "CAP_IPC_OWNER",
57885+ "CAP_SYS_MODULE",
57886+ "CAP_SYS_RAWIO",
57887+ "CAP_SYS_CHROOT",
57888+ "CAP_SYS_PTRACE",
57889+ "CAP_SYS_PACCT",
57890+ "CAP_SYS_ADMIN",
57891+ "CAP_SYS_BOOT",
57892+ "CAP_SYS_NICE",
57893+ "CAP_SYS_RESOURCE",
57894+ "CAP_SYS_TIME",
57895+ "CAP_SYS_TTY_CONFIG",
57896+ "CAP_MKNOD",
57897+ "CAP_LEASE",
57898+ "CAP_AUDIT_WRITE",
57899+ "CAP_AUDIT_CONTROL",
57900+ "CAP_SETFCAP",
57901+ "CAP_MAC_OVERRIDE",
57902+ "CAP_MAC_ADMIN",
57903+ "CAP_SYSLOG",
57904+ "CAP_WAKE_ALARM"
57905+};
57906+
57907+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
57908+
57909+int gr_is_capable(const int cap)
57910+{
57911+#ifdef CONFIG_GRKERNSEC
57912+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
57913+ return 1;
57914+ return 0;
57915+#else
57916+ return 1;
57917+#endif
57918+}
57919+
57920+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57921+{
57922+#ifdef CONFIG_GRKERNSEC
57923+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
57924+ return 1;
57925+ return 0;
57926+#else
57927+ return 1;
57928+#endif
57929+}
57930+
57931+int gr_is_capable_nolog(const int cap)
57932+{
57933+#ifdef CONFIG_GRKERNSEC
57934+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
57935+ return 1;
57936+ return 0;
57937+#else
57938+ return 1;
57939+#endif
57940+}
57941+
57942+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
57943+{
57944+#ifdef CONFIG_GRKERNSEC
57945+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
57946+ return 1;
57947+ return 0;
57948+#else
57949+ return 1;
57950+#endif
57951+}
57952+
57953+EXPORT_SYMBOL(gr_is_capable);
57954+EXPORT_SYMBOL(gr_is_capable_nolog);
57955+EXPORT_SYMBOL(gr_task_is_capable);
57956+EXPORT_SYMBOL(gr_task_is_capable_nolog);
57957diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
57958new file mode 100644
57959index 0000000..d3ee748
57960--- /dev/null
57961+++ b/grsecurity/grsec_fifo.c
57962@@ -0,0 +1,24 @@
57963+#include <linux/kernel.h>
57964+#include <linux/sched.h>
57965+#include <linux/fs.h>
57966+#include <linux/file.h>
57967+#include <linux/grinternal.h>
57968+
57969+int
57970+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
57971+ const struct dentry *dir, const int flag, const int acc_mode)
57972+{
57973+#ifdef CONFIG_GRKERNSEC_FIFO
57974+ const struct cred *cred = current_cred();
57975+
57976+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
57977+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
57978+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
57979+ (cred->fsuid != dentry->d_inode->i_uid)) {
57980+ if (!inode_permission(dentry->d_inode, acc_mode))
57981+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
57982+ return -EACCES;
57983+ }
57984+#endif
57985+ return 0;
57986+}
57987diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
57988new file mode 100644
57989index 0000000..8ca18bf
57990--- /dev/null
57991+++ b/grsecurity/grsec_fork.c
57992@@ -0,0 +1,23 @@
57993+#include <linux/kernel.h>
57994+#include <linux/sched.h>
57995+#include <linux/grsecurity.h>
57996+#include <linux/grinternal.h>
57997+#include <linux/errno.h>
57998+
57999+void
58000+gr_log_forkfail(const int retval)
58001+{
58002+#ifdef CONFIG_GRKERNSEC_FORKFAIL
58003+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
58004+ switch (retval) {
58005+ case -EAGAIN:
58006+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
58007+ break;
58008+ case -ENOMEM:
58009+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
58010+ break;
58011+ }
58012+ }
58013+#endif
58014+ return;
58015+}
58016diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
58017new file mode 100644
58018index 0000000..05a6015
58019--- /dev/null
58020+++ b/grsecurity/grsec_init.c
58021@@ -0,0 +1,283 @@
58022+#include <linux/kernel.h>
58023+#include <linux/sched.h>
58024+#include <linux/mm.h>
58025+#include <linux/gracl.h>
58026+#include <linux/slab.h>
58027+#include <linux/vmalloc.h>
58028+#include <linux/percpu.h>
58029+#include <linux/module.h>
58030+
58031+int grsec_enable_ptrace_readexec;
58032+int grsec_enable_setxid;
58033+int grsec_enable_symlinkown;
58034+int grsec_symlinkown_gid;
58035+int grsec_enable_brute;
58036+int grsec_enable_link;
58037+int grsec_enable_dmesg;
58038+int grsec_enable_harden_ptrace;
58039+int grsec_enable_fifo;
58040+int grsec_enable_execlog;
58041+int grsec_enable_signal;
58042+int grsec_enable_forkfail;
58043+int grsec_enable_audit_ptrace;
58044+int grsec_enable_time;
58045+int grsec_enable_audit_textrel;
58046+int grsec_enable_group;
58047+int grsec_audit_gid;
58048+int grsec_enable_chdir;
58049+int grsec_enable_mount;
58050+int grsec_enable_rofs;
58051+int grsec_enable_chroot_findtask;
58052+int grsec_enable_chroot_mount;
58053+int grsec_enable_chroot_shmat;
58054+int grsec_enable_chroot_fchdir;
58055+int grsec_enable_chroot_double;
58056+int grsec_enable_chroot_pivot;
58057+int grsec_enable_chroot_chdir;
58058+int grsec_enable_chroot_chmod;
58059+int grsec_enable_chroot_mknod;
58060+int grsec_enable_chroot_nice;
58061+int grsec_enable_chroot_execlog;
58062+int grsec_enable_chroot_caps;
58063+int grsec_enable_chroot_sysctl;
58064+int grsec_enable_chroot_unix;
58065+int grsec_enable_tpe;
58066+int grsec_tpe_gid;
58067+int grsec_enable_blackhole;
58068+#ifdef CONFIG_IPV6_MODULE
58069+EXPORT_SYMBOL(grsec_enable_blackhole);
58070+#endif
58071+int grsec_lastack_retries;
58072+int grsec_enable_tpe_all;
58073+int grsec_enable_tpe_invert;
58074+int grsec_enable_socket_all;
58075+int grsec_socket_all_gid;
58076+int grsec_enable_socket_client;
58077+int grsec_socket_client_gid;
58078+int grsec_enable_socket_server;
58079+int grsec_socket_server_gid;
58080+int grsec_resource_logging;
58081+int grsec_disable_privio;
58082+int grsec_enable_log_rwxmaps;
58083+int grsec_lock;
58084+
58085+DEFINE_SPINLOCK(grsec_alert_lock);
58086+unsigned long grsec_alert_wtime = 0;
58087+unsigned long grsec_alert_fyet = 0;
58088+
58089+DEFINE_SPINLOCK(grsec_audit_lock);
58090+
58091+DEFINE_RWLOCK(grsec_exec_file_lock);
58092+
58093+char *gr_shared_page[4];
58094+
58095+char *gr_alert_log_fmt;
58096+char *gr_audit_log_fmt;
58097+char *gr_alert_log_buf;
58098+char *gr_audit_log_buf;
58099+
58100+extern struct gr_arg *gr_usermode;
58101+extern unsigned char *gr_system_salt;
58102+extern unsigned char *gr_system_sum;
58103+
58104+void __init
58105+grsecurity_init(void)
58106+{
58107+ int j;
58108+ /* create the per-cpu shared pages */
58109+
58110+#ifdef CONFIG_X86
58111+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
58112+#endif
58113+
58114+ for (j = 0; j < 4; j++) {
58115+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
58116+ if (gr_shared_page[j] == NULL) {
58117+ panic("Unable to allocate grsecurity shared page");
58118+ return;
58119+ }
58120+ }
58121+
58122+ /* allocate log buffers */
58123+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
58124+ if (!gr_alert_log_fmt) {
58125+ panic("Unable to allocate grsecurity alert log format buffer");
58126+ return;
58127+ }
58128+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
58129+ if (!gr_audit_log_fmt) {
58130+ panic("Unable to allocate grsecurity audit log format buffer");
58131+ return;
58132+ }
58133+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58134+ if (!gr_alert_log_buf) {
58135+ panic("Unable to allocate grsecurity alert log buffer");
58136+ return;
58137+ }
58138+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58139+ if (!gr_audit_log_buf) {
58140+ panic("Unable to allocate grsecurity audit log buffer");
58141+ return;
58142+ }
58143+
58144+ /* allocate memory for authentication structure */
58145+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
58146+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
58147+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
58148+
58149+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
58150+ panic("Unable to allocate grsecurity authentication structure");
58151+ return;
58152+ }
58153+
58154+
58155+#ifdef CONFIG_GRKERNSEC_IO
58156+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
58157+ grsec_disable_privio = 1;
58158+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58159+ grsec_disable_privio = 1;
58160+#else
58161+ grsec_disable_privio = 0;
58162+#endif
58163+#endif
58164+
58165+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58166+ /* for backward compatibility, tpe_invert always defaults to on if
58167+ enabled in the kernel
58168+ */
58169+ grsec_enable_tpe_invert = 1;
58170+#endif
58171+
58172+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58173+#ifndef CONFIG_GRKERNSEC_SYSCTL
58174+ grsec_lock = 1;
58175+#endif
58176+
58177+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58178+ grsec_enable_audit_textrel = 1;
58179+#endif
58180+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58181+ grsec_enable_log_rwxmaps = 1;
58182+#endif
58183+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58184+ grsec_enable_group = 1;
58185+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
58186+#endif
58187+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58188+ grsec_enable_ptrace_readexec = 1;
58189+#endif
58190+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58191+ grsec_enable_chdir = 1;
58192+#endif
58193+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58194+ grsec_enable_harden_ptrace = 1;
58195+#endif
58196+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58197+ grsec_enable_mount = 1;
58198+#endif
58199+#ifdef CONFIG_GRKERNSEC_LINK
58200+ grsec_enable_link = 1;
58201+#endif
58202+#ifdef CONFIG_GRKERNSEC_BRUTE
58203+ grsec_enable_brute = 1;
58204+#endif
58205+#ifdef CONFIG_GRKERNSEC_DMESG
58206+ grsec_enable_dmesg = 1;
58207+#endif
58208+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58209+ grsec_enable_blackhole = 1;
58210+ grsec_lastack_retries = 4;
58211+#endif
58212+#ifdef CONFIG_GRKERNSEC_FIFO
58213+ grsec_enable_fifo = 1;
58214+#endif
58215+#ifdef CONFIG_GRKERNSEC_EXECLOG
58216+ grsec_enable_execlog = 1;
58217+#endif
58218+#ifdef CONFIG_GRKERNSEC_SETXID
58219+ grsec_enable_setxid = 1;
58220+#endif
58221+#ifdef CONFIG_GRKERNSEC_SIGNAL
58222+ grsec_enable_signal = 1;
58223+#endif
58224+#ifdef CONFIG_GRKERNSEC_FORKFAIL
58225+ grsec_enable_forkfail = 1;
58226+#endif
58227+#ifdef CONFIG_GRKERNSEC_TIME
58228+ grsec_enable_time = 1;
58229+#endif
58230+#ifdef CONFIG_GRKERNSEC_RESLOG
58231+ grsec_resource_logging = 1;
58232+#endif
58233+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58234+ grsec_enable_chroot_findtask = 1;
58235+#endif
58236+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58237+ grsec_enable_chroot_unix = 1;
58238+#endif
58239+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58240+ grsec_enable_chroot_mount = 1;
58241+#endif
58242+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58243+ grsec_enable_chroot_fchdir = 1;
58244+#endif
58245+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58246+ grsec_enable_chroot_shmat = 1;
58247+#endif
58248+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58249+ grsec_enable_audit_ptrace = 1;
58250+#endif
58251+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58252+ grsec_enable_chroot_double = 1;
58253+#endif
58254+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58255+ grsec_enable_chroot_pivot = 1;
58256+#endif
58257+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58258+ grsec_enable_chroot_chdir = 1;
58259+#endif
58260+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58261+ grsec_enable_chroot_chmod = 1;
58262+#endif
58263+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58264+ grsec_enable_chroot_mknod = 1;
58265+#endif
58266+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58267+ grsec_enable_chroot_nice = 1;
58268+#endif
58269+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58270+ grsec_enable_chroot_execlog = 1;
58271+#endif
58272+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58273+ grsec_enable_chroot_caps = 1;
58274+#endif
58275+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58276+ grsec_enable_chroot_sysctl = 1;
58277+#endif
58278+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58279+ grsec_enable_symlinkown = 1;
58280+ grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
58281+#endif
58282+#ifdef CONFIG_GRKERNSEC_TPE
58283+ grsec_enable_tpe = 1;
58284+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58285+#ifdef CONFIG_GRKERNSEC_TPE_ALL
58286+ grsec_enable_tpe_all = 1;
58287+#endif
58288+#endif
58289+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58290+ grsec_enable_socket_all = 1;
58291+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58292+#endif
58293+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58294+ grsec_enable_socket_client = 1;
58295+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58296+#endif
58297+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58298+ grsec_enable_socket_server = 1;
58299+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58300+#endif
58301+#endif
58302+
58303+ return;
58304+}
58305diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
58306new file mode 100644
58307index 0000000..589481f
58308--- /dev/null
58309+++ b/grsecurity/grsec_link.c
58310@@ -0,0 +1,58 @@
58311+#include <linux/kernel.h>
58312+#include <linux/sched.h>
58313+#include <linux/fs.h>
58314+#include <linux/file.h>
58315+#include <linux/grinternal.h>
58316+
58317+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
58318+{
58319+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58320+ const struct inode *link_inode = link->dentry->d_inode;
58321+
58322+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
58323+ /* ignore root-owned links, e.g. /proc/self */
58324+ !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
58325+ !uid_eq(link_inode->i_uid, target->i_uid)) {
58326+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
58327+ return 1;
58328+ }
58329+#endif
58330+ return 0;
58331+}
58332+
58333+int
58334+gr_handle_follow_link(const struct inode *parent,
58335+ const struct inode *inode,
58336+ const struct dentry *dentry, const struct vfsmount *mnt)
58337+{
58338+#ifdef CONFIG_GRKERNSEC_LINK
58339+ const struct cred *cred = current_cred();
58340+
58341+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58342+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
58343+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
58344+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58345+ return -EACCES;
58346+ }
58347+#endif
58348+ return 0;
58349+}
58350+
58351+int
58352+gr_handle_hardlink(const struct dentry *dentry,
58353+ const struct vfsmount *mnt,
58354+ struct inode *inode, const int mode, const char *to)
58355+{
58356+#ifdef CONFIG_GRKERNSEC_LINK
58357+ const struct cred *cred = current_cred();
58358+
58359+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
58360+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
58361+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58362+ !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
58363+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
58364+ return -EPERM;
58365+ }
58366+#endif
58367+ return 0;
58368+}
58369diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
58370new file mode 100644
58371index 0000000..a45d2e9
58372--- /dev/null
58373+++ b/grsecurity/grsec_log.c
58374@@ -0,0 +1,322 @@
58375+#include <linux/kernel.h>
58376+#include <linux/sched.h>
58377+#include <linux/file.h>
58378+#include <linux/tty.h>
58379+#include <linux/fs.h>
58380+#include <linux/grinternal.h>
58381+
58382+#ifdef CONFIG_TREE_PREEMPT_RCU
58383+#define DISABLE_PREEMPT() preempt_disable()
58384+#define ENABLE_PREEMPT() preempt_enable()
58385+#else
58386+#define DISABLE_PREEMPT()
58387+#define ENABLE_PREEMPT()
58388+#endif
58389+
58390+#define BEGIN_LOCKS(x) \
58391+ DISABLE_PREEMPT(); \
58392+ rcu_read_lock(); \
58393+ read_lock(&tasklist_lock); \
58394+ read_lock(&grsec_exec_file_lock); \
58395+ if (x != GR_DO_AUDIT) \
58396+ spin_lock(&grsec_alert_lock); \
58397+ else \
58398+ spin_lock(&grsec_audit_lock)
58399+
58400+#define END_LOCKS(x) \
58401+ if (x != GR_DO_AUDIT) \
58402+ spin_unlock(&grsec_alert_lock); \
58403+ else \
58404+ spin_unlock(&grsec_audit_lock); \
58405+ read_unlock(&grsec_exec_file_lock); \
58406+ read_unlock(&tasklist_lock); \
58407+ rcu_read_unlock(); \
58408+ ENABLE_PREEMPT(); \
58409+ if (x == GR_DONT_AUDIT) \
58410+ gr_handle_alertkill(current)
58411+
58412+enum {
58413+ FLOODING,
58414+ NO_FLOODING
58415+};
58416+
58417+extern char *gr_alert_log_fmt;
58418+extern char *gr_audit_log_fmt;
58419+extern char *gr_alert_log_buf;
58420+extern char *gr_audit_log_buf;
58421+
58422+static int gr_log_start(int audit)
58423+{
58424+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58425+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58426+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58427+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
58428+ unsigned long curr_secs = get_seconds();
58429+
58430+ if (audit == GR_DO_AUDIT)
58431+ goto set_fmt;
58432+
58433+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
58434+ grsec_alert_wtime = curr_secs;
58435+ grsec_alert_fyet = 0;
58436+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
58437+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58438+ grsec_alert_fyet++;
58439+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58440+ grsec_alert_wtime = curr_secs;
58441+ grsec_alert_fyet++;
58442+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58443+ return FLOODING;
58444+ }
58445+ else return FLOODING;
58446+
58447+set_fmt:
58448+#endif
58449+ memset(buf, 0, PAGE_SIZE);
58450+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
58451+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58452+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58453+ } else if (current->signal->curr_ip) {
58454+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58455+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58456+ } else if (gr_acl_is_enabled()) {
58457+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58458+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58459+ } else {
58460+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
58461+ strcpy(buf, fmt);
58462+ }
58463+
58464+ return NO_FLOODING;
58465+}
58466+
58467+static void gr_log_middle(int audit, const char *msg, va_list ap)
58468+ __attribute__ ((format (printf, 2, 0)));
58469+
58470+static void gr_log_middle(int audit, const char *msg, va_list ap)
58471+{
58472+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58473+ unsigned int len = strlen(buf);
58474+
58475+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58476+
58477+ return;
58478+}
58479+
58480+static void gr_log_middle_varargs(int audit, const char *msg, ...)
58481+ __attribute__ ((format (printf, 2, 3)));
58482+
58483+static void gr_log_middle_varargs(int audit, const char *msg, ...)
58484+{
58485+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58486+ unsigned int len = strlen(buf);
58487+ va_list ap;
58488+
58489+ va_start(ap, msg);
58490+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58491+ va_end(ap);
58492+
58493+ return;
58494+}
58495+
58496+static void gr_log_end(int audit, int append_default)
58497+{
58498+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58499+
58500+ if (append_default) {
58501+ unsigned int len = strlen(buf);
58502+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58503+ }
58504+
58505+ printk("%s\n", buf);
58506+
58507+ return;
58508+}
58509+
58510+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58511+{
58512+ int logtype;
58513+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58514+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58515+ void *voidptr = NULL;
58516+ int num1 = 0, num2 = 0;
58517+ unsigned long ulong1 = 0, ulong2 = 0;
58518+ struct dentry *dentry = NULL;
58519+ struct vfsmount *mnt = NULL;
58520+ struct file *file = NULL;
58521+ struct task_struct *task = NULL;
58522+ const struct cred *cred, *pcred;
58523+ va_list ap;
58524+
58525+ BEGIN_LOCKS(audit);
58526+ logtype = gr_log_start(audit);
58527+ if (logtype == FLOODING) {
58528+ END_LOCKS(audit);
58529+ return;
58530+ }
58531+ va_start(ap, argtypes);
58532+ switch (argtypes) {
58533+ case GR_TTYSNIFF:
58534+ task = va_arg(ap, struct task_struct *);
58535+ 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);
58536+ break;
58537+ case GR_SYSCTL_HIDDEN:
58538+ str1 = va_arg(ap, char *);
58539+ gr_log_middle_varargs(audit, msg, result, str1);
58540+ break;
58541+ case GR_RBAC:
58542+ dentry = va_arg(ap, struct dentry *);
58543+ mnt = va_arg(ap, struct vfsmount *);
58544+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58545+ break;
58546+ case GR_RBAC_STR:
58547+ dentry = va_arg(ap, struct dentry *);
58548+ mnt = va_arg(ap, struct vfsmount *);
58549+ str1 = va_arg(ap, char *);
58550+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58551+ break;
58552+ case GR_STR_RBAC:
58553+ str1 = va_arg(ap, char *);
58554+ dentry = va_arg(ap, struct dentry *);
58555+ mnt = va_arg(ap, struct vfsmount *);
58556+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
58557+ break;
58558+ case GR_RBAC_MODE2:
58559+ dentry = va_arg(ap, struct dentry *);
58560+ mnt = va_arg(ap, struct vfsmount *);
58561+ str1 = va_arg(ap, char *);
58562+ str2 = va_arg(ap, char *);
58563+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
58564+ break;
58565+ case GR_RBAC_MODE3:
58566+ dentry = va_arg(ap, struct dentry *);
58567+ mnt = va_arg(ap, struct vfsmount *);
58568+ str1 = va_arg(ap, char *);
58569+ str2 = va_arg(ap, char *);
58570+ str3 = va_arg(ap, char *);
58571+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
58572+ break;
58573+ case GR_FILENAME:
58574+ dentry = va_arg(ap, struct dentry *);
58575+ mnt = va_arg(ap, struct vfsmount *);
58576+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
58577+ break;
58578+ case GR_STR_FILENAME:
58579+ str1 = va_arg(ap, char *);
58580+ dentry = va_arg(ap, struct dentry *);
58581+ mnt = va_arg(ap, struct vfsmount *);
58582+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
58583+ break;
58584+ case GR_FILENAME_STR:
58585+ dentry = va_arg(ap, struct dentry *);
58586+ mnt = va_arg(ap, struct vfsmount *);
58587+ str1 = va_arg(ap, char *);
58588+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
58589+ break;
58590+ case GR_FILENAME_TWO_INT:
58591+ dentry = va_arg(ap, struct dentry *);
58592+ mnt = va_arg(ap, struct vfsmount *);
58593+ num1 = va_arg(ap, int);
58594+ num2 = va_arg(ap, int);
58595+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
58596+ break;
58597+ case GR_FILENAME_TWO_INT_STR:
58598+ dentry = va_arg(ap, struct dentry *);
58599+ mnt = va_arg(ap, struct vfsmount *);
58600+ num1 = va_arg(ap, int);
58601+ num2 = va_arg(ap, int);
58602+ str1 = va_arg(ap, char *);
58603+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
58604+ break;
58605+ case GR_TEXTREL:
58606+ file = va_arg(ap, struct file *);
58607+ ulong1 = va_arg(ap, unsigned long);
58608+ ulong2 = va_arg(ap, unsigned long);
58609+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
58610+ break;
58611+ case GR_PTRACE:
58612+ task = va_arg(ap, struct task_struct *);
58613+ 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);
58614+ break;
58615+ case GR_RESOURCE:
58616+ task = va_arg(ap, struct task_struct *);
58617+ cred = __task_cred(task);
58618+ pcred = __task_cred(task->real_parent);
58619+ ulong1 = va_arg(ap, unsigned long);
58620+ str1 = va_arg(ap, char *);
58621+ ulong2 = va_arg(ap, unsigned long);
58622+ 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);
58623+ break;
58624+ case GR_CAP:
58625+ task = va_arg(ap, struct task_struct *);
58626+ cred = __task_cred(task);
58627+ pcred = __task_cred(task->real_parent);
58628+ str1 = va_arg(ap, char *);
58629+ 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);
58630+ break;
58631+ case GR_SIG:
58632+ str1 = va_arg(ap, char *);
58633+ voidptr = va_arg(ap, void *);
58634+ gr_log_middle_varargs(audit, msg, str1, voidptr);
58635+ break;
58636+ case GR_SIG2:
58637+ task = va_arg(ap, struct task_struct *);
58638+ cred = __task_cred(task);
58639+ pcred = __task_cred(task->real_parent);
58640+ num1 = va_arg(ap, int);
58641+ 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);
58642+ break;
58643+ case GR_CRASH1:
58644+ task = va_arg(ap, struct task_struct *);
58645+ cred = __task_cred(task);
58646+ pcred = __task_cred(task->real_parent);
58647+ ulong1 = va_arg(ap, unsigned long);
58648+ 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);
58649+ break;
58650+ case GR_CRASH2:
58651+ task = va_arg(ap, struct task_struct *);
58652+ cred = __task_cred(task);
58653+ pcred = __task_cred(task->real_parent);
58654+ ulong1 = va_arg(ap, unsigned long);
58655+ 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);
58656+ break;
58657+ case GR_RWXMAP:
58658+ file = va_arg(ap, struct file *);
58659+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
58660+ break;
58661+ case GR_PSACCT:
58662+ {
58663+ unsigned int wday, cday;
58664+ __u8 whr, chr;
58665+ __u8 wmin, cmin;
58666+ __u8 wsec, csec;
58667+ char cur_tty[64] = { 0 };
58668+ char parent_tty[64] = { 0 };
58669+
58670+ task = va_arg(ap, struct task_struct *);
58671+ wday = va_arg(ap, unsigned int);
58672+ cday = va_arg(ap, unsigned int);
58673+ whr = va_arg(ap, int);
58674+ chr = va_arg(ap, int);
58675+ wmin = va_arg(ap, int);
58676+ cmin = va_arg(ap, int);
58677+ wsec = va_arg(ap, int);
58678+ csec = va_arg(ap, int);
58679+ ulong1 = va_arg(ap, unsigned long);
58680+ cred = __task_cred(task);
58681+ pcred = __task_cred(task->real_parent);
58682+
58683+ 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);
58684+ }
58685+ break;
58686+ default:
58687+ gr_log_middle(audit, msg, ap);
58688+ }
58689+ va_end(ap);
58690+ // these don't need DEFAULTSECARGS printed on the end
58691+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
58692+ gr_log_end(audit, 0);
58693+ else
58694+ gr_log_end(audit, 1);
58695+ END_LOCKS(audit);
58696+}
58697diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
58698new file mode 100644
58699index 0000000..f536303
58700--- /dev/null
58701+++ b/grsecurity/grsec_mem.c
58702@@ -0,0 +1,40 @@
58703+#include <linux/kernel.h>
58704+#include <linux/sched.h>
58705+#include <linux/mm.h>
58706+#include <linux/mman.h>
58707+#include <linux/grinternal.h>
58708+
58709+void
58710+gr_handle_ioperm(void)
58711+{
58712+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
58713+ return;
58714+}
58715+
58716+void
58717+gr_handle_iopl(void)
58718+{
58719+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
58720+ return;
58721+}
58722+
58723+void
58724+gr_handle_mem_readwrite(u64 from, u64 to)
58725+{
58726+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
58727+ return;
58728+}
58729+
58730+void
58731+gr_handle_vm86(void)
58732+{
58733+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
58734+ return;
58735+}
58736+
58737+void
58738+gr_log_badprocpid(const char *entry)
58739+{
58740+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
58741+ return;
58742+}
58743diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
58744new file mode 100644
58745index 0000000..2131422
58746--- /dev/null
58747+++ b/grsecurity/grsec_mount.c
58748@@ -0,0 +1,62 @@
58749+#include <linux/kernel.h>
58750+#include <linux/sched.h>
58751+#include <linux/mount.h>
58752+#include <linux/grsecurity.h>
58753+#include <linux/grinternal.h>
58754+
58755+void
58756+gr_log_remount(const char *devname, const int retval)
58757+{
58758+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58759+ if (grsec_enable_mount && (retval >= 0))
58760+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
58761+#endif
58762+ return;
58763+}
58764+
58765+void
58766+gr_log_unmount(const char *devname, const int retval)
58767+{
58768+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58769+ if (grsec_enable_mount && (retval >= 0))
58770+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
58771+#endif
58772+ return;
58773+}
58774+
58775+void
58776+gr_log_mount(const char *from, const char *to, const int retval)
58777+{
58778+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58779+ if (grsec_enable_mount && (retval >= 0))
58780+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
58781+#endif
58782+ return;
58783+}
58784+
58785+int
58786+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
58787+{
58788+#ifdef CONFIG_GRKERNSEC_ROFS
58789+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
58790+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
58791+ return -EPERM;
58792+ } else
58793+ return 0;
58794+#endif
58795+ return 0;
58796+}
58797+
58798+int
58799+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
58800+{
58801+#ifdef CONFIG_GRKERNSEC_ROFS
58802+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
58803+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
58804+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
58805+ return -EPERM;
58806+ } else
58807+ return 0;
58808+#endif
58809+ return 0;
58810+}
58811diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
58812new file mode 100644
58813index 0000000..a3b12a0
58814--- /dev/null
58815+++ b/grsecurity/grsec_pax.c
58816@@ -0,0 +1,36 @@
58817+#include <linux/kernel.h>
58818+#include <linux/sched.h>
58819+#include <linux/mm.h>
58820+#include <linux/file.h>
58821+#include <linux/grinternal.h>
58822+#include <linux/grsecurity.h>
58823+
58824+void
58825+gr_log_textrel(struct vm_area_struct * vma)
58826+{
58827+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58828+ if (grsec_enable_audit_textrel)
58829+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
58830+#endif
58831+ return;
58832+}
58833+
58834+void
58835+gr_log_rwxmmap(struct file *file)
58836+{
58837+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58838+ if (grsec_enable_log_rwxmaps)
58839+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
58840+#endif
58841+ return;
58842+}
58843+
58844+void
58845+gr_log_rwxmprotect(struct file *file)
58846+{
58847+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58848+ if (grsec_enable_log_rwxmaps)
58849+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
58850+#endif
58851+ return;
58852+}
58853diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
58854new file mode 100644
58855index 0000000..f7f29aa
58856--- /dev/null
58857+++ b/grsecurity/grsec_ptrace.c
58858@@ -0,0 +1,30 @@
58859+#include <linux/kernel.h>
58860+#include <linux/sched.h>
58861+#include <linux/grinternal.h>
58862+#include <linux/security.h>
58863+
58864+void
58865+gr_audit_ptrace(struct task_struct *task)
58866+{
58867+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58868+ if (grsec_enable_audit_ptrace)
58869+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
58870+#endif
58871+ return;
58872+}
58873+
58874+int
58875+gr_ptrace_readexec(struct file *file, int unsafe_flags)
58876+{
58877+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58878+ const struct dentry *dentry = file->f_path.dentry;
58879+ const struct vfsmount *mnt = file->f_path.mnt;
58880+
58881+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
58882+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
58883+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
58884+ return -EACCES;
58885+ }
58886+#endif
58887+ return 0;
58888+}
58889diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
58890new file mode 100644
58891index 0000000..b4ac94c
58892--- /dev/null
58893+++ b/grsecurity/grsec_sig.c
58894@@ -0,0 +1,209 @@
58895+#include <linux/kernel.h>
58896+#include <linux/sched.h>
58897+#include <linux/delay.h>
58898+#include <linux/grsecurity.h>
58899+#include <linux/grinternal.h>
58900+#include <linux/hardirq.h>
58901+
58902+char *signames[] = {
58903+ [SIGSEGV] = "Segmentation fault",
58904+ [SIGILL] = "Illegal instruction",
58905+ [SIGABRT] = "Abort",
58906+ [SIGBUS] = "Invalid alignment/Bus error"
58907+};
58908+
58909+void
58910+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
58911+{
58912+#ifdef CONFIG_GRKERNSEC_SIGNAL
58913+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
58914+ (sig == SIGABRT) || (sig == SIGBUS))) {
58915+ if (t->pid == current->pid) {
58916+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
58917+ } else {
58918+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
58919+ }
58920+ }
58921+#endif
58922+ return;
58923+}
58924+
58925+int
58926+gr_handle_signal(const struct task_struct *p, const int sig)
58927+{
58928+#ifdef CONFIG_GRKERNSEC
58929+ /* ignore the 0 signal for protected task checks */
58930+ if (current->pid > 1 && sig && gr_check_protected_task(p)) {
58931+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
58932+ return -EPERM;
58933+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
58934+ return -EPERM;
58935+ }
58936+#endif
58937+ return 0;
58938+}
58939+
58940+#ifdef CONFIG_GRKERNSEC
58941+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
58942+
58943+int gr_fake_force_sig(int sig, struct task_struct *t)
58944+{
58945+ unsigned long int flags;
58946+ int ret, blocked, ignored;
58947+ struct k_sigaction *action;
58948+
58949+ spin_lock_irqsave(&t->sighand->siglock, flags);
58950+ action = &t->sighand->action[sig-1];
58951+ ignored = action->sa.sa_handler == SIG_IGN;
58952+ blocked = sigismember(&t->blocked, sig);
58953+ if (blocked || ignored) {
58954+ action->sa.sa_handler = SIG_DFL;
58955+ if (blocked) {
58956+ sigdelset(&t->blocked, sig);
58957+ recalc_sigpending_and_wake(t);
58958+ }
58959+ }
58960+ if (action->sa.sa_handler == SIG_DFL)
58961+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
58962+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
58963+
58964+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
58965+
58966+ return ret;
58967+}
58968+#endif
58969+
58970+#ifdef CONFIG_GRKERNSEC_BRUTE
58971+#define GR_USER_BAN_TIME (15 * 60)
58972+
58973+static int __get_dumpable(unsigned long mm_flags)
58974+{
58975+ int ret;
58976+
58977+ ret = mm_flags & MMF_DUMPABLE_MASK;
58978+ return (ret >= 2) ? 2 : ret;
58979+}
58980+#endif
58981+
58982+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
58983+{
58984+#ifdef CONFIG_GRKERNSEC_BRUTE
58985+ kuid_t uid = GLOBAL_ROOT_UID;
58986+
58987+ if (!grsec_enable_brute)
58988+ return;
58989+
58990+ rcu_read_lock();
58991+ read_lock(&tasklist_lock);
58992+ read_lock(&grsec_exec_file_lock);
58993+ if (p->real_parent && p->real_parent->exec_file == p->exec_file)
58994+ p->real_parent->brute = 1;
58995+ else {
58996+ const struct cred *cred = __task_cred(p), *cred2;
58997+ struct task_struct *tsk, *tsk2;
58998+
58999+ if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
59000+ struct user_struct *user;
59001+
59002+ uid = cred->uid;
59003+
59004+ /* this is put upon execution past expiration */
59005+ user = find_user(uid);
59006+ if (user == NULL)
59007+ goto unlock;
59008+ user->banned = 1;
59009+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
59010+ if (user->ban_expires == ~0UL)
59011+ user->ban_expires--;
59012+
59013+ do_each_thread(tsk2, tsk) {
59014+ cred2 = __task_cred(tsk);
59015+ if (tsk != p && uid_eq(cred2->uid, uid))
59016+ gr_fake_force_sig(SIGKILL, tsk);
59017+ } while_each_thread(tsk2, tsk);
59018+ }
59019+ }
59020+unlock:
59021+ read_unlock(&grsec_exec_file_lock);
59022+ read_unlock(&tasklist_lock);
59023+ rcu_read_unlock();
59024+
59025+ if (!uid_eq(uid, GLOBAL_ROOT_UID))
59026+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
59027+ from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
59028+
59029+#endif
59030+ return;
59031+}
59032+
59033+void gr_handle_brute_check(void)
59034+{
59035+#ifdef CONFIG_GRKERNSEC_BRUTE
59036+ if (current->brute)
59037+ msleep(30 * 1000);
59038+#endif
59039+ return;
59040+}
59041+
59042+void gr_handle_kernel_exploit(void)
59043+{
59044+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
59045+ const struct cred *cred;
59046+ struct task_struct *tsk, *tsk2;
59047+ struct user_struct *user;
59048+ kuid_t uid;
59049+
59050+ if (in_irq() || in_serving_softirq() || in_nmi())
59051+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
59052+
59053+ uid = current_uid();
59054+
59055+ if (uid_eq(uid, GLOBAL_ROOT_UID))
59056+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
59057+ else {
59058+ /* kill all the processes of this user, hold a reference
59059+ to their creds struct, and prevent them from creating
59060+ another process until system reset
59061+ */
59062+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
59063+ from_kuid_munged(&init_user_ns, uid));
59064+ /* we intentionally leak this ref */
59065+ user = get_uid(current->cred->user);
59066+ if (user) {
59067+ user->banned = 1;
59068+ user->ban_expires = ~0UL;
59069+ }
59070+
59071+ read_lock(&tasklist_lock);
59072+ do_each_thread(tsk2, tsk) {
59073+ cred = __task_cred(tsk);
59074+ if (uid_eq(cred->uid, uid))
59075+ gr_fake_force_sig(SIGKILL, tsk);
59076+ } while_each_thread(tsk2, tsk);
59077+ read_unlock(&tasklist_lock);
59078+ }
59079+#endif
59080+}
59081+
59082+int __gr_process_user_ban(struct user_struct *user)
59083+{
59084+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59085+ if (unlikely(user->banned)) {
59086+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
59087+ user->banned = 0;
59088+ user->ban_expires = 0;
59089+ free_uid(user);
59090+ } else
59091+ return -EPERM;
59092+ }
59093+#endif
59094+ return 0;
59095+}
59096+
59097+int gr_process_user_ban(void)
59098+{
59099+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59100+ return __gr_process_user_ban(current->cred->user);
59101+#endif
59102+ return 0;
59103+}
59104diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
59105new file mode 100644
59106index 0000000..4030d57
59107--- /dev/null
59108+++ b/grsecurity/grsec_sock.c
59109@@ -0,0 +1,244 @@
59110+#include <linux/kernel.h>
59111+#include <linux/module.h>
59112+#include <linux/sched.h>
59113+#include <linux/file.h>
59114+#include <linux/net.h>
59115+#include <linux/in.h>
59116+#include <linux/ip.h>
59117+#include <net/sock.h>
59118+#include <net/inet_sock.h>
59119+#include <linux/grsecurity.h>
59120+#include <linux/grinternal.h>
59121+#include <linux/gracl.h>
59122+
59123+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
59124+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
59125+
59126+EXPORT_SYMBOL(gr_search_udp_recvmsg);
59127+EXPORT_SYMBOL(gr_search_udp_sendmsg);
59128+
59129+#ifdef CONFIG_UNIX_MODULE
59130+EXPORT_SYMBOL(gr_acl_handle_unix);
59131+EXPORT_SYMBOL(gr_acl_handle_mknod);
59132+EXPORT_SYMBOL(gr_handle_chroot_unix);
59133+EXPORT_SYMBOL(gr_handle_create);
59134+#endif
59135+
59136+#ifdef CONFIG_GRKERNSEC
59137+#define gr_conn_table_size 32749
59138+struct conn_table_entry {
59139+ struct conn_table_entry *next;
59140+ struct signal_struct *sig;
59141+};
59142+
59143+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
59144+DEFINE_SPINLOCK(gr_conn_table_lock);
59145+
59146+extern const char * gr_socktype_to_name(unsigned char type);
59147+extern const char * gr_proto_to_name(unsigned char proto);
59148+extern const char * gr_sockfamily_to_name(unsigned char family);
59149+
59150+static __inline__ int
59151+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
59152+{
59153+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
59154+}
59155+
59156+static __inline__ int
59157+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
59158+ __u16 sport, __u16 dport)
59159+{
59160+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
59161+ sig->gr_sport == sport && sig->gr_dport == dport))
59162+ return 1;
59163+ else
59164+ return 0;
59165+}
59166+
59167+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
59168+{
59169+ struct conn_table_entry **match;
59170+ unsigned int index;
59171+
59172+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59173+ sig->gr_sport, sig->gr_dport,
59174+ gr_conn_table_size);
59175+
59176+ newent->sig = sig;
59177+
59178+ match = &gr_conn_table[index];
59179+ newent->next = *match;
59180+ *match = newent;
59181+
59182+ return;
59183+}
59184+
59185+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
59186+{
59187+ struct conn_table_entry *match, *last = NULL;
59188+ unsigned int index;
59189+
59190+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59191+ sig->gr_sport, sig->gr_dport,
59192+ gr_conn_table_size);
59193+
59194+ match = gr_conn_table[index];
59195+ while (match && !conn_match(match->sig,
59196+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
59197+ sig->gr_dport)) {
59198+ last = match;
59199+ match = match->next;
59200+ }
59201+
59202+ if (match) {
59203+ if (last)
59204+ last->next = match->next;
59205+ else
59206+ gr_conn_table[index] = NULL;
59207+ kfree(match);
59208+ }
59209+
59210+ return;
59211+}
59212+
59213+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
59214+ __u16 sport, __u16 dport)
59215+{
59216+ struct conn_table_entry *match;
59217+ unsigned int index;
59218+
59219+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
59220+
59221+ match = gr_conn_table[index];
59222+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
59223+ match = match->next;
59224+
59225+ if (match)
59226+ return match->sig;
59227+ else
59228+ return NULL;
59229+}
59230+
59231+#endif
59232+
59233+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59234+{
59235+#ifdef CONFIG_GRKERNSEC
59236+ struct signal_struct *sig = task->signal;
59237+ struct conn_table_entry *newent;
59238+
59239+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59240+ if (newent == NULL)
59241+ return;
59242+ /* no bh lock needed since we are called with bh disabled */
59243+ spin_lock(&gr_conn_table_lock);
59244+ gr_del_task_from_ip_table_nolock(sig);
59245+ sig->gr_saddr = inet->inet_rcv_saddr;
59246+ sig->gr_daddr = inet->inet_daddr;
59247+ sig->gr_sport = inet->inet_sport;
59248+ sig->gr_dport = inet->inet_dport;
59249+ gr_add_to_task_ip_table_nolock(sig, newent);
59250+ spin_unlock(&gr_conn_table_lock);
59251+#endif
59252+ return;
59253+}
59254+
59255+void gr_del_task_from_ip_table(struct task_struct *task)
59256+{
59257+#ifdef CONFIG_GRKERNSEC
59258+ spin_lock_bh(&gr_conn_table_lock);
59259+ gr_del_task_from_ip_table_nolock(task->signal);
59260+ spin_unlock_bh(&gr_conn_table_lock);
59261+#endif
59262+ return;
59263+}
59264+
59265+void
59266+gr_attach_curr_ip(const struct sock *sk)
59267+{
59268+#ifdef CONFIG_GRKERNSEC
59269+ struct signal_struct *p, *set;
59270+ const struct inet_sock *inet = inet_sk(sk);
59271+
59272+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59273+ return;
59274+
59275+ set = current->signal;
59276+
59277+ spin_lock_bh(&gr_conn_table_lock);
59278+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59279+ inet->inet_dport, inet->inet_sport);
59280+ if (unlikely(p != NULL)) {
59281+ set->curr_ip = p->curr_ip;
59282+ set->used_accept = 1;
59283+ gr_del_task_from_ip_table_nolock(p);
59284+ spin_unlock_bh(&gr_conn_table_lock);
59285+ return;
59286+ }
59287+ spin_unlock_bh(&gr_conn_table_lock);
59288+
59289+ set->curr_ip = inet->inet_daddr;
59290+ set->used_accept = 1;
59291+#endif
59292+ return;
59293+}
59294+
59295+int
59296+gr_handle_sock_all(const int family, const int type, const int protocol)
59297+{
59298+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59299+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59300+ (family != AF_UNIX)) {
59301+ if (family == AF_INET)
59302+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59303+ else
59304+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59305+ return -EACCES;
59306+ }
59307+#endif
59308+ return 0;
59309+}
59310+
59311+int
59312+gr_handle_sock_server(const struct sockaddr *sck)
59313+{
59314+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59315+ if (grsec_enable_socket_server &&
59316+ in_group_p(grsec_socket_server_gid) &&
59317+ sck && (sck->sa_family != AF_UNIX) &&
59318+ (sck->sa_family != AF_LOCAL)) {
59319+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59320+ return -EACCES;
59321+ }
59322+#endif
59323+ return 0;
59324+}
59325+
59326+int
59327+gr_handle_sock_server_other(const struct sock *sck)
59328+{
59329+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59330+ if (grsec_enable_socket_server &&
59331+ in_group_p(grsec_socket_server_gid) &&
59332+ sck && (sck->sk_family != AF_UNIX) &&
59333+ (sck->sk_family != AF_LOCAL)) {
59334+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59335+ return -EACCES;
59336+ }
59337+#endif
59338+ return 0;
59339+}
59340+
59341+int
59342+gr_handle_sock_client(const struct sockaddr *sck)
59343+{
59344+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59345+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59346+ sck && (sck->sa_family != AF_UNIX) &&
59347+ (sck->sa_family != AF_LOCAL)) {
59348+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59349+ return -EACCES;
59350+ }
59351+#endif
59352+ return 0;
59353+}
59354diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
59355new file mode 100644
59356index 0000000..f55ef0f
59357--- /dev/null
59358+++ b/grsecurity/grsec_sysctl.c
59359@@ -0,0 +1,469 @@
59360+#include <linux/kernel.h>
59361+#include <linux/sched.h>
59362+#include <linux/sysctl.h>
59363+#include <linux/grsecurity.h>
59364+#include <linux/grinternal.h>
59365+
59366+int
59367+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59368+{
59369+#ifdef CONFIG_GRKERNSEC_SYSCTL
59370+ if (dirname == NULL || name == NULL)
59371+ return 0;
59372+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59373+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59374+ return -EACCES;
59375+ }
59376+#endif
59377+ return 0;
59378+}
59379+
59380+#ifdef CONFIG_GRKERNSEC_ROFS
59381+static int __maybe_unused one = 1;
59382+#endif
59383+
59384+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59385+struct ctl_table grsecurity_table[] = {
59386+#ifdef CONFIG_GRKERNSEC_SYSCTL
59387+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59388+#ifdef CONFIG_GRKERNSEC_IO
59389+ {
59390+ .procname = "disable_priv_io",
59391+ .data = &grsec_disable_privio,
59392+ .maxlen = sizeof(int),
59393+ .mode = 0600,
59394+ .proc_handler = &proc_dointvec,
59395+ },
59396+#endif
59397+#endif
59398+#ifdef CONFIG_GRKERNSEC_LINK
59399+ {
59400+ .procname = "linking_restrictions",
59401+ .data = &grsec_enable_link,
59402+ .maxlen = sizeof(int),
59403+ .mode = 0600,
59404+ .proc_handler = &proc_dointvec,
59405+ },
59406+#endif
59407+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59408+ {
59409+ .procname = "enforce_symlinksifowner",
59410+ .data = &grsec_enable_symlinkown,
59411+ .maxlen = sizeof(int),
59412+ .mode = 0600,
59413+ .proc_handler = &proc_dointvec,
59414+ },
59415+ {
59416+ .procname = "symlinkown_gid",
59417+ .data = &grsec_symlinkown_gid,
59418+ .maxlen = sizeof(int),
59419+ .mode = 0600,
59420+ .proc_handler = &proc_dointvec,
59421+ },
59422+#endif
59423+#ifdef CONFIG_GRKERNSEC_BRUTE
59424+ {
59425+ .procname = "deter_bruteforce",
59426+ .data = &grsec_enable_brute,
59427+ .maxlen = sizeof(int),
59428+ .mode = 0600,
59429+ .proc_handler = &proc_dointvec,
59430+ },
59431+#endif
59432+#ifdef CONFIG_GRKERNSEC_FIFO
59433+ {
59434+ .procname = "fifo_restrictions",
59435+ .data = &grsec_enable_fifo,
59436+ .maxlen = sizeof(int),
59437+ .mode = 0600,
59438+ .proc_handler = &proc_dointvec,
59439+ },
59440+#endif
59441+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59442+ {
59443+ .procname = "ptrace_readexec",
59444+ .data = &grsec_enable_ptrace_readexec,
59445+ .maxlen = sizeof(int),
59446+ .mode = 0600,
59447+ .proc_handler = &proc_dointvec,
59448+ },
59449+#endif
59450+#ifdef CONFIG_GRKERNSEC_SETXID
59451+ {
59452+ .procname = "consistent_setxid",
59453+ .data = &grsec_enable_setxid,
59454+ .maxlen = sizeof(int),
59455+ .mode = 0600,
59456+ .proc_handler = &proc_dointvec,
59457+ },
59458+#endif
59459+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59460+ {
59461+ .procname = "ip_blackhole",
59462+ .data = &grsec_enable_blackhole,
59463+ .maxlen = sizeof(int),
59464+ .mode = 0600,
59465+ .proc_handler = &proc_dointvec,
59466+ },
59467+ {
59468+ .procname = "lastack_retries",
59469+ .data = &grsec_lastack_retries,
59470+ .maxlen = sizeof(int),
59471+ .mode = 0600,
59472+ .proc_handler = &proc_dointvec,
59473+ },
59474+#endif
59475+#ifdef CONFIG_GRKERNSEC_EXECLOG
59476+ {
59477+ .procname = "exec_logging",
59478+ .data = &grsec_enable_execlog,
59479+ .maxlen = sizeof(int),
59480+ .mode = 0600,
59481+ .proc_handler = &proc_dointvec,
59482+ },
59483+#endif
59484+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59485+ {
59486+ .procname = "rwxmap_logging",
59487+ .data = &grsec_enable_log_rwxmaps,
59488+ .maxlen = sizeof(int),
59489+ .mode = 0600,
59490+ .proc_handler = &proc_dointvec,
59491+ },
59492+#endif
59493+#ifdef CONFIG_GRKERNSEC_SIGNAL
59494+ {
59495+ .procname = "signal_logging",
59496+ .data = &grsec_enable_signal,
59497+ .maxlen = sizeof(int),
59498+ .mode = 0600,
59499+ .proc_handler = &proc_dointvec,
59500+ },
59501+#endif
59502+#ifdef CONFIG_GRKERNSEC_FORKFAIL
59503+ {
59504+ .procname = "forkfail_logging",
59505+ .data = &grsec_enable_forkfail,
59506+ .maxlen = sizeof(int),
59507+ .mode = 0600,
59508+ .proc_handler = &proc_dointvec,
59509+ },
59510+#endif
59511+#ifdef CONFIG_GRKERNSEC_TIME
59512+ {
59513+ .procname = "timechange_logging",
59514+ .data = &grsec_enable_time,
59515+ .maxlen = sizeof(int),
59516+ .mode = 0600,
59517+ .proc_handler = &proc_dointvec,
59518+ },
59519+#endif
59520+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59521+ {
59522+ .procname = "chroot_deny_shmat",
59523+ .data = &grsec_enable_chroot_shmat,
59524+ .maxlen = sizeof(int),
59525+ .mode = 0600,
59526+ .proc_handler = &proc_dointvec,
59527+ },
59528+#endif
59529+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59530+ {
59531+ .procname = "chroot_deny_unix",
59532+ .data = &grsec_enable_chroot_unix,
59533+ .maxlen = sizeof(int),
59534+ .mode = 0600,
59535+ .proc_handler = &proc_dointvec,
59536+ },
59537+#endif
59538+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59539+ {
59540+ .procname = "chroot_deny_mount",
59541+ .data = &grsec_enable_chroot_mount,
59542+ .maxlen = sizeof(int),
59543+ .mode = 0600,
59544+ .proc_handler = &proc_dointvec,
59545+ },
59546+#endif
59547+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59548+ {
59549+ .procname = "chroot_deny_fchdir",
59550+ .data = &grsec_enable_chroot_fchdir,
59551+ .maxlen = sizeof(int),
59552+ .mode = 0600,
59553+ .proc_handler = &proc_dointvec,
59554+ },
59555+#endif
59556+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59557+ {
59558+ .procname = "chroot_deny_chroot",
59559+ .data = &grsec_enable_chroot_double,
59560+ .maxlen = sizeof(int),
59561+ .mode = 0600,
59562+ .proc_handler = &proc_dointvec,
59563+ },
59564+#endif
59565+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59566+ {
59567+ .procname = "chroot_deny_pivot",
59568+ .data = &grsec_enable_chroot_pivot,
59569+ .maxlen = sizeof(int),
59570+ .mode = 0600,
59571+ .proc_handler = &proc_dointvec,
59572+ },
59573+#endif
59574+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59575+ {
59576+ .procname = "chroot_enforce_chdir",
59577+ .data = &grsec_enable_chroot_chdir,
59578+ .maxlen = sizeof(int),
59579+ .mode = 0600,
59580+ .proc_handler = &proc_dointvec,
59581+ },
59582+#endif
59583+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59584+ {
59585+ .procname = "chroot_deny_chmod",
59586+ .data = &grsec_enable_chroot_chmod,
59587+ .maxlen = sizeof(int),
59588+ .mode = 0600,
59589+ .proc_handler = &proc_dointvec,
59590+ },
59591+#endif
59592+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59593+ {
59594+ .procname = "chroot_deny_mknod",
59595+ .data = &grsec_enable_chroot_mknod,
59596+ .maxlen = sizeof(int),
59597+ .mode = 0600,
59598+ .proc_handler = &proc_dointvec,
59599+ },
59600+#endif
59601+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59602+ {
59603+ .procname = "chroot_restrict_nice",
59604+ .data = &grsec_enable_chroot_nice,
59605+ .maxlen = sizeof(int),
59606+ .mode = 0600,
59607+ .proc_handler = &proc_dointvec,
59608+ },
59609+#endif
59610+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59611+ {
59612+ .procname = "chroot_execlog",
59613+ .data = &grsec_enable_chroot_execlog,
59614+ .maxlen = sizeof(int),
59615+ .mode = 0600,
59616+ .proc_handler = &proc_dointvec,
59617+ },
59618+#endif
59619+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59620+ {
59621+ .procname = "chroot_caps",
59622+ .data = &grsec_enable_chroot_caps,
59623+ .maxlen = sizeof(int),
59624+ .mode = 0600,
59625+ .proc_handler = &proc_dointvec,
59626+ },
59627+#endif
59628+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59629+ {
59630+ .procname = "chroot_deny_sysctl",
59631+ .data = &grsec_enable_chroot_sysctl,
59632+ .maxlen = sizeof(int),
59633+ .mode = 0600,
59634+ .proc_handler = &proc_dointvec,
59635+ },
59636+#endif
59637+#ifdef CONFIG_GRKERNSEC_TPE
59638+ {
59639+ .procname = "tpe",
59640+ .data = &grsec_enable_tpe,
59641+ .maxlen = sizeof(int),
59642+ .mode = 0600,
59643+ .proc_handler = &proc_dointvec,
59644+ },
59645+ {
59646+ .procname = "tpe_gid",
59647+ .data = &grsec_tpe_gid,
59648+ .maxlen = sizeof(int),
59649+ .mode = 0600,
59650+ .proc_handler = &proc_dointvec,
59651+ },
59652+#endif
59653+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59654+ {
59655+ .procname = "tpe_invert",
59656+ .data = &grsec_enable_tpe_invert,
59657+ .maxlen = sizeof(int),
59658+ .mode = 0600,
59659+ .proc_handler = &proc_dointvec,
59660+ },
59661+#endif
59662+#ifdef CONFIG_GRKERNSEC_TPE_ALL
59663+ {
59664+ .procname = "tpe_restrict_all",
59665+ .data = &grsec_enable_tpe_all,
59666+ .maxlen = sizeof(int),
59667+ .mode = 0600,
59668+ .proc_handler = &proc_dointvec,
59669+ },
59670+#endif
59671+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59672+ {
59673+ .procname = "socket_all",
59674+ .data = &grsec_enable_socket_all,
59675+ .maxlen = sizeof(int),
59676+ .mode = 0600,
59677+ .proc_handler = &proc_dointvec,
59678+ },
59679+ {
59680+ .procname = "socket_all_gid",
59681+ .data = &grsec_socket_all_gid,
59682+ .maxlen = sizeof(int),
59683+ .mode = 0600,
59684+ .proc_handler = &proc_dointvec,
59685+ },
59686+#endif
59687+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59688+ {
59689+ .procname = "socket_client",
59690+ .data = &grsec_enable_socket_client,
59691+ .maxlen = sizeof(int),
59692+ .mode = 0600,
59693+ .proc_handler = &proc_dointvec,
59694+ },
59695+ {
59696+ .procname = "socket_client_gid",
59697+ .data = &grsec_socket_client_gid,
59698+ .maxlen = sizeof(int),
59699+ .mode = 0600,
59700+ .proc_handler = &proc_dointvec,
59701+ },
59702+#endif
59703+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59704+ {
59705+ .procname = "socket_server",
59706+ .data = &grsec_enable_socket_server,
59707+ .maxlen = sizeof(int),
59708+ .mode = 0600,
59709+ .proc_handler = &proc_dointvec,
59710+ },
59711+ {
59712+ .procname = "socket_server_gid",
59713+ .data = &grsec_socket_server_gid,
59714+ .maxlen = sizeof(int),
59715+ .mode = 0600,
59716+ .proc_handler = &proc_dointvec,
59717+ },
59718+#endif
59719+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
59720+ {
59721+ .procname = "audit_group",
59722+ .data = &grsec_enable_group,
59723+ .maxlen = sizeof(int),
59724+ .mode = 0600,
59725+ .proc_handler = &proc_dointvec,
59726+ },
59727+ {
59728+ .procname = "audit_gid",
59729+ .data = &grsec_audit_gid,
59730+ .maxlen = sizeof(int),
59731+ .mode = 0600,
59732+ .proc_handler = &proc_dointvec,
59733+ },
59734+#endif
59735+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59736+ {
59737+ .procname = "audit_chdir",
59738+ .data = &grsec_enable_chdir,
59739+ .maxlen = sizeof(int),
59740+ .mode = 0600,
59741+ .proc_handler = &proc_dointvec,
59742+ },
59743+#endif
59744+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59745+ {
59746+ .procname = "audit_mount",
59747+ .data = &grsec_enable_mount,
59748+ .maxlen = sizeof(int),
59749+ .mode = 0600,
59750+ .proc_handler = &proc_dointvec,
59751+ },
59752+#endif
59753+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59754+ {
59755+ .procname = "audit_textrel",
59756+ .data = &grsec_enable_audit_textrel,
59757+ .maxlen = sizeof(int),
59758+ .mode = 0600,
59759+ .proc_handler = &proc_dointvec,
59760+ },
59761+#endif
59762+#ifdef CONFIG_GRKERNSEC_DMESG
59763+ {
59764+ .procname = "dmesg",
59765+ .data = &grsec_enable_dmesg,
59766+ .maxlen = sizeof(int),
59767+ .mode = 0600,
59768+ .proc_handler = &proc_dointvec,
59769+ },
59770+#endif
59771+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59772+ {
59773+ .procname = "chroot_findtask",
59774+ .data = &grsec_enable_chroot_findtask,
59775+ .maxlen = sizeof(int),
59776+ .mode = 0600,
59777+ .proc_handler = &proc_dointvec,
59778+ },
59779+#endif
59780+#ifdef CONFIG_GRKERNSEC_RESLOG
59781+ {
59782+ .procname = "resource_logging",
59783+ .data = &grsec_resource_logging,
59784+ .maxlen = sizeof(int),
59785+ .mode = 0600,
59786+ .proc_handler = &proc_dointvec,
59787+ },
59788+#endif
59789+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59790+ {
59791+ .procname = "audit_ptrace",
59792+ .data = &grsec_enable_audit_ptrace,
59793+ .maxlen = sizeof(int),
59794+ .mode = 0600,
59795+ .proc_handler = &proc_dointvec,
59796+ },
59797+#endif
59798+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59799+ {
59800+ .procname = "harden_ptrace",
59801+ .data = &grsec_enable_harden_ptrace,
59802+ .maxlen = sizeof(int),
59803+ .mode = 0600,
59804+ .proc_handler = &proc_dointvec,
59805+ },
59806+#endif
59807+ {
59808+ .procname = "grsec_lock",
59809+ .data = &grsec_lock,
59810+ .maxlen = sizeof(int),
59811+ .mode = 0600,
59812+ .proc_handler = &proc_dointvec,
59813+ },
59814+#endif
59815+#ifdef CONFIG_GRKERNSEC_ROFS
59816+ {
59817+ .procname = "romount_protect",
59818+ .data = &grsec_enable_rofs,
59819+ .maxlen = sizeof(int),
59820+ .mode = 0600,
59821+ .proc_handler = &proc_dointvec_minmax,
59822+ .extra1 = &one,
59823+ .extra2 = &one,
59824+ },
59825+#endif
59826+ { }
59827+};
59828+#endif
59829diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
59830new file mode 100644
59831index 0000000..0dc13c3
59832--- /dev/null
59833+++ b/grsecurity/grsec_time.c
59834@@ -0,0 +1,16 @@
59835+#include <linux/kernel.h>
59836+#include <linux/sched.h>
59837+#include <linux/grinternal.h>
59838+#include <linux/module.h>
59839+
59840+void
59841+gr_log_timechange(void)
59842+{
59843+#ifdef CONFIG_GRKERNSEC_TIME
59844+ if (grsec_enable_time)
59845+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
59846+#endif
59847+ return;
59848+}
59849+
59850+EXPORT_SYMBOL(gr_log_timechange);
59851diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
59852new file mode 100644
59853index 0000000..07e0dc0
59854--- /dev/null
59855+++ b/grsecurity/grsec_tpe.c
59856@@ -0,0 +1,73 @@
59857+#include <linux/kernel.h>
59858+#include <linux/sched.h>
59859+#include <linux/file.h>
59860+#include <linux/fs.h>
59861+#include <linux/grinternal.h>
59862+
59863+extern int gr_acl_tpe_check(void);
59864+
59865+int
59866+gr_tpe_allow(const struct file *file)
59867+{
59868+#ifdef CONFIG_GRKERNSEC
59869+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
59870+ const struct cred *cred = current_cred();
59871+ char *msg = NULL;
59872+ char *msg2 = NULL;
59873+
59874+ // never restrict root
59875+ if (!cred->uid)
59876+ return 1;
59877+
59878+ if (grsec_enable_tpe) {
59879+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59880+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
59881+ msg = "not being in trusted group";
59882+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
59883+ msg = "being in untrusted group";
59884+#else
59885+ if (in_group_p(grsec_tpe_gid))
59886+ msg = "being in untrusted group";
59887+#endif
59888+ }
59889+ if (!msg && gr_acl_tpe_check())
59890+ msg = "being in untrusted role";
59891+
59892+ // not in any affected group/role
59893+ if (!msg)
59894+ goto next_check;
59895+
59896+ if (inode->i_uid)
59897+ msg2 = "file in non-root-owned directory";
59898+ else if (inode->i_mode & S_IWOTH)
59899+ msg2 = "file in world-writable directory";
59900+ else if (inode->i_mode & S_IWGRP)
59901+ msg2 = "file in group-writable directory";
59902+
59903+ if (msg && msg2) {
59904+ char fullmsg[70] = {0};
59905+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
59906+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
59907+ return 0;
59908+ }
59909+ msg = NULL;
59910+next_check:
59911+#ifdef CONFIG_GRKERNSEC_TPE_ALL
59912+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
59913+ return 1;
59914+
59915+ if (inode->i_uid && (inode->i_uid != cred->uid))
59916+ msg = "directory not owned by user";
59917+ else if (inode->i_mode & S_IWOTH)
59918+ msg = "file in world-writable directory";
59919+ else if (inode->i_mode & S_IWGRP)
59920+ msg = "file in group-writable directory";
59921+
59922+ if (msg) {
59923+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
59924+ return 0;
59925+ }
59926+#endif
59927+#endif
59928+ return 1;
59929+}
59930diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
59931new file mode 100644
59932index 0000000..9f7b1ac
59933--- /dev/null
59934+++ b/grsecurity/grsum.c
59935@@ -0,0 +1,61 @@
59936+#include <linux/err.h>
59937+#include <linux/kernel.h>
59938+#include <linux/sched.h>
59939+#include <linux/mm.h>
59940+#include <linux/scatterlist.h>
59941+#include <linux/crypto.h>
59942+#include <linux/gracl.h>
59943+
59944+
59945+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
59946+#error "crypto and sha256 must be built into the kernel"
59947+#endif
59948+
59949+int
59950+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
59951+{
59952+ char *p;
59953+ struct crypto_hash *tfm;
59954+ struct hash_desc desc;
59955+ struct scatterlist sg;
59956+ unsigned char temp_sum[GR_SHA_LEN];
59957+ volatile int retval = 0;
59958+ volatile int dummy = 0;
59959+ unsigned int i;
59960+
59961+ sg_init_table(&sg, 1);
59962+
59963+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
59964+ if (IS_ERR(tfm)) {
59965+ /* should never happen, since sha256 should be built in */
59966+ return 1;
59967+ }
59968+
59969+ desc.tfm = tfm;
59970+ desc.flags = 0;
59971+
59972+ crypto_hash_init(&desc);
59973+
59974+ p = salt;
59975+ sg_set_buf(&sg, p, GR_SALT_LEN);
59976+ crypto_hash_update(&desc, &sg, sg.length);
59977+
59978+ p = entry->pw;
59979+ sg_set_buf(&sg, p, strlen(p));
59980+
59981+ crypto_hash_update(&desc, &sg, sg.length);
59982+
59983+ crypto_hash_final(&desc, temp_sum);
59984+
59985+ memset(entry->pw, 0, GR_PW_LEN);
59986+
59987+ for (i = 0; i < GR_SHA_LEN; i++)
59988+ if (sum[i] != temp_sum[i])
59989+ retval = 1;
59990+ else
59991+ dummy = 1; // waste a cycle
59992+
59993+ crypto_free_hash(tfm);
59994+
59995+ return retval;
59996+}
59997diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
59998index 9e6e1c6..d47b906 100644
59999--- a/include/acpi/acpi_bus.h
60000+++ b/include/acpi/acpi_bus.h
60001@@ -138,7 +138,7 @@ struct acpi_device_ops {
60002 acpi_op_bind bind;
60003 acpi_op_unbind unbind;
60004 acpi_op_notify notify;
60005-};
60006+} __no_const;
60007
60008 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
60009
60010diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
60011index b7babf0..3ba8aee 100644
60012--- a/include/asm-generic/atomic-long.h
60013+++ b/include/asm-generic/atomic-long.h
60014@@ -22,6 +22,12 @@
60015
60016 typedef atomic64_t atomic_long_t;
60017
60018+#ifdef CONFIG_PAX_REFCOUNT
60019+typedef atomic64_unchecked_t atomic_long_unchecked_t;
60020+#else
60021+typedef atomic64_t atomic_long_unchecked_t;
60022+#endif
60023+
60024 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
60025
60026 static inline long atomic_long_read(atomic_long_t *l)
60027@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60028 return (long)atomic64_read(v);
60029 }
60030
60031+#ifdef CONFIG_PAX_REFCOUNT
60032+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60033+{
60034+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60035+
60036+ return (long)atomic64_read_unchecked(v);
60037+}
60038+#endif
60039+
60040 static inline void atomic_long_set(atomic_long_t *l, long i)
60041 {
60042 atomic64_t *v = (atomic64_t *)l;
60043@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60044 atomic64_set(v, i);
60045 }
60046
60047+#ifdef CONFIG_PAX_REFCOUNT
60048+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60049+{
60050+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60051+
60052+ atomic64_set_unchecked(v, i);
60053+}
60054+#endif
60055+
60056 static inline void atomic_long_inc(atomic_long_t *l)
60057 {
60058 atomic64_t *v = (atomic64_t *)l;
60059@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60060 atomic64_inc(v);
60061 }
60062
60063+#ifdef CONFIG_PAX_REFCOUNT
60064+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60065+{
60066+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60067+
60068+ atomic64_inc_unchecked(v);
60069+}
60070+#endif
60071+
60072 static inline void atomic_long_dec(atomic_long_t *l)
60073 {
60074 atomic64_t *v = (atomic64_t *)l;
60075@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60076 atomic64_dec(v);
60077 }
60078
60079+#ifdef CONFIG_PAX_REFCOUNT
60080+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60081+{
60082+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60083+
60084+ atomic64_dec_unchecked(v);
60085+}
60086+#endif
60087+
60088 static inline void atomic_long_add(long i, atomic_long_t *l)
60089 {
60090 atomic64_t *v = (atomic64_t *)l;
60091@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60092 atomic64_add(i, v);
60093 }
60094
60095+#ifdef CONFIG_PAX_REFCOUNT
60096+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60097+{
60098+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60099+
60100+ atomic64_add_unchecked(i, v);
60101+}
60102+#endif
60103+
60104 static inline void atomic_long_sub(long i, atomic_long_t *l)
60105 {
60106 atomic64_t *v = (atomic64_t *)l;
60107@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60108 atomic64_sub(i, v);
60109 }
60110
60111+#ifdef CONFIG_PAX_REFCOUNT
60112+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60113+{
60114+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60115+
60116+ atomic64_sub_unchecked(i, v);
60117+}
60118+#endif
60119+
60120 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60121 {
60122 atomic64_t *v = (atomic64_t *)l;
60123@@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60124 return (long)atomic64_inc_return(v);
60125 }
60126
60127+#ifdef CONFIG_PAX_REFCOUNT
60128+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60129+{
60130+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60131+
60132+ return (long)atomic64_inc_return_unchecked(v);
60133+}
60134+#endif
60135+
60136 static inline long atomic_long_dec_return(atomic_long_t *l)
60137 {
60138 atomic64_t *v = (atomic64_t *)l;
60139@@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60140
60141 typedef atomic_t atomic_long_t;
60142
60143+#ifdef CONFIG_PAX_REFCOUNT
60144+typedef atomic_unchecked_t atomic_long_unchecked_t;
60145+#else
60146+typedef atomic_t atomic_long_unchecked_t;
60147+#endif
60148+
60149 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
60150 static inline long atomic_long_read(atomic_long_t *l)
60151 {
60152@@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60153 return (long)atomic_read(v);
60154 }
60155
60156+#ifdef CONFIG_PAX_REFCOUNT
60157+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60158+{
60159+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60160+
60161+ return (long)atomic_read_unchecked(v);
60162+}
60163+#endif
60164+
60165 static inline void atomic_long_set(atomic_long_t *l, long i)
60166 {
60167 atomic_t *v = (atomic_t *)l;
60168@@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60169 atomic_set(v, i);
60170 }
60171
60172+#ifdef CONFIG_PAX_REFCOUNT
60173+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60174+{
60175+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60176+
60177+ atomic_set_unchecked(v, i);
60178+}
60179+#endif
60180+
60181 static inline void atomic_long_inc(atomic_long_t *l)
60182 {
60183 atomic_t *v = (atomic_t *)l;
60184@@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60185 atomic_inc(v);
60186 }
60187
60188+#ifdef CONFIG_PAX_REFCOUNT
60189+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60190+{
60191+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60192+
60193+ atomic_inc_unchecked(v);
60194+}
60195+#endif
60196+
60197 static inline void atomic_long_dec(atomic_long_t *l)
60198 {
60199 atomic_t *v = (atomic_t *)l;
60200@@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60201 atomic_dec(v);
60202 }
60203
60204+#ifdef CONFIG_PAX_REFCOUNT
60205+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60206+{
60207+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60208+
60209+ atomic_dec_unchecked(v);
60210+}
60211+#endif
60212+
60213 static inline void atomic_long_add(long i, atomic_long_t *l)
60214 {
60215 atomic_t *v = (atomic_t *)l;
60216@@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60217 atomic_add(i, v);
60218 }
60219
60220+#ifdef CONFIG_PAX_REFCOUNT
60221+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60222+{
60223+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60224+
60225+ atomic_add_unchecked(i, v);
60226+}
60227+#endif
60228+
60229 static inline void atomic_long_sub(long i, atomic_long_t *l)
60230 {
60231 atomic_t *v = (atomic_t *)l;
60232@@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60233 atomic_sub(i, v);
60234 }
60235
60236+#ifdef CONFIG_PAX_REFCOUNT
60237+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60238+{
60239+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60240+
60241+ atomic_sub_unchecked(i, v);
60242+}
60243+#endif
60244+
60245 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60246 {
60247 atomic_t *v = (atomic_t *)l;
60248@@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60249 return (long)atomic_inc_return(v);
60250 }
60251
60252+#ifdef CONFIG_PAX_REFCOUNT
60253+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60254+{
60255+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60256+
60257+ return (long)atomic_inc_return_unchecked(v);
60258+}
60259+#endif
60260+
60261 static inline long atomic_long_dec_return(atomic_long_t *l)
60262 {
60263 atomic_t *v = (atomic_t *)l;
60264@@ -255,4 +393,55 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60265
60266 #endif /* BITS_PER_LONG == 64 */
60267
60268+#ifdef CONFIG_PAX_REFCOUNT
60269+static inline void pax_refcount_needs_these_functions(void)
60270+{
60271+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
60272+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
60273+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
60274+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
60275+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
60276+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
60277+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
60278+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
60279+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
60280+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
60281+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
60282+#ifdef CONFIG_X86
60283+ atomic_clear_mask_unchecked(0, NULL);
60284+ atomic_set_mask_unchecked(0, NULL);
60285+#endif
60286+
60287+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
60288+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
60289+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
60290+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
60291+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
60292+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
60293+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
60294+}
60295+#else
60296+#define atomic_read_unchecked(v) atomic_read(v)
60297+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
60298+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
60299+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
60300+#define atomic_inc_unchecked(v) atomic_inc(v)
60301+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
60302+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
60303+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
60304+#define atomic_dec_unchecked(v) atomic_dec(v)
60305+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
60306+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
60307+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
60308+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
60309+
60310+#define atomic_long_read_unchecked(v) atomic_long_read(v)
60311+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
60312+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
60313+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
60314+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
60315+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
60316+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
60317+#endif
60318+
60319 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
60320diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
60321index 1ced641..c896ee8 100644
60322--- a/include/asm-generic/atomic.h
60323+++ b/include/asm-generic/atomic.h
60324@@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
60325 * Atomically clears the bits set in @mask from @v
60326 */
60327 #ifndef atomic_clear_mask
60328-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
60329+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
60330 {
60331 unsigned long flags;
60332
60333diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
60334index b18ce4f..2ee2843 100644
60335--- a/include/asm-generic/atomic64.h
60336+++ b/include/asm-generic/atomic64.h
60337@@ -16,6 +16,8 @@ typedef struct {
60338 long long counter;
60339 } atomic64_t;
60340
60341+typedef atomic64_t atomic64_unchecked_t;
60342+
60343 #define ATOMIC64_INIT(i) { (i) }
60344
60345 extern long long atomic64_read(const atomic64_t *v);
60346@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
60347 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
60348 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
60349
60350+#define atomic64_read_unchecked(v) atomic64_read(v)
60351+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
60352+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
60353+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
60354+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
60355+#define atomic64_inc_unchecked(v) atomic64_inc(v)
60356+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
60357+#define atomic64_dec_unchecked(v) atomic64_dec(v)
60358+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
60359+
60360 #endif /* _ASM_GENERIC_ATOMIC64_H */
60361diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
60362index 1bfcfe5..e04c5c9 100644
60363--- a/include/asm-generic/cache.h
60364+++ b/include/asm-generic/cache.h
60365@@ -6,7 +6,7 @@
60366 * cache lines need to provide their own cache.h.
60367 */
60368
60369-#define L1_CACHE_SHIFT 5
60370-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
60371+#define L1_CACHE_SHIFT 5UL
60372+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
60373
60374 #endif /* __ASM_GENERIC_CACHE_H */
60375diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
60376index 0d68a1e..b74a761 100644
60377--- a/include/asm-generic/emergency-restart.h
60378+++ b/include/asm-generic/emergency-restart.h
60379@@ -1,7 +1,7 @@
60380 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
60381 #define _ASM_GENERIC_EMERGENCY_RESTART_H
60382
60383-static inline void machine_emergency_restart(void)
60384+static inline __noreturn void machine_emergency_restart(void)
60385 {
60386 machine_restart(NULL);
60387 }
60388diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
60389index 0232ccb..13d9165 100644
60390--- a/include/asm-generic/kmap_types.h
60391+++ b/include/asm-generic/kmap_types.h
60392@@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
60393 KMAP_D(17) KM_NMI,
60394 KMAP_D(18) KM_NMI_PTE,
60395 KMAP_D(19) KM_KDB,
60396+KMAP_D(20) KM_CLEARPAGE,
60397 /*
60398 * Remember to update debug_kmap_atomic() when adding new kmap types!
60399 */
60400-KMAP_D(20) KM_TYPE_NR
60401+KMAP_D(21) KM_TYPE_NR
60402 };
60403
60404 #undef KMAP_D
60405diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
60406index 9ceb03b..2efbcbd 100644
60407--- a/include/asm-generic/local.h
60408+++ b/include/asm-generic/local.h
60409@@ -39,6 +39,7 @@ typedef struct
60410 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
60411 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
60412 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
60413+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
60414
60415 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
60416 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
60417diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
60418index 725612b..9cc513a 100644
60419--- a/include/asm-generic/pgtable-nopmd.h
60420+++ b/include/asm-generic/pgtable-nopmd.h
60421@@ -1,14 +1,19 @@
60422 #ifndef _PGTABLE_NOPMD_H
60423 #define _PGTABLE_NOPMD_H
60424
60425-#ifndef __ASSEMBLY__
60426-
60427 #include <asm-generic/pgtable-nopud.h>
60428
60429-struct mm_struct;
60430-
60431 #define __PAGETABLE_PMD_FOLDED
60432
60433+#define PMD_SHIFT PUD_SHIFT
60434+#define PTRS_PER_PMD 1
60435+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
60436+#define PMD_MASK (~(PMD_SIZE-1))
60437+
60438+#ifndef __ASSEMBLY__
60439+
60440+struct mm_struct;
60441+
60442 /*
60443 * Having the pmd type consist of a pud gets the size right, and allows
60444 * us to conceptually access the pud entry that this pmd is folded into
60445@@ -16,11 +21,6 @@ struct mm_struct;
60446 */
60447 typedef struct { pud_t pud; } pmd_t;
60448
60449-#define PMD_SHIFT PUD_SHIFT
60450-#define PTRS_PER_PMD 1
60451-#define PMD_SIZE (1UL << PMD_SHIFT)
60452-#define PMD_MASK (~(PMD_SIZE-1))
60453-
60454 /*
60455 * The "pud_xxx()" functions here are trivial for a folded two-level
60456 * setup: the pmd is never bad, and a pmd always exists (as it's folded
60457diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
60458index 810431d..0ec4804f 100644
60459--- a/include/asm-generic/pgtable-nopud.h
60460+++ b/include/asm-generic/pgtable-nopud.h
60461@@ -1,10 +1,15 @@
60462 #ifndef _PGTABLE_NOPUD_H
60463 #define _PGTABLE_NOPUD_H
60464
60465-#ifndef __ASSEMBLY__
60466-
60467 #define __PAGETABLE_PUD_FOLDED
60468
60469+#define PUD_SHIFT PGDIR_SHIFT
60470+#define PTRS_PER_PUD 1
60471+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
60472+#define PUD_MASK (~(PUD_SIZE-1))
60473+
60474+#ifndef __ASSEMBLY__
60475+
60476 /*
60477 * Having the pud type consist of a pgd gets the size right, and allows
60478 * us to conceptually access the pgd entry that this pud is folded into
60479@@ -12,11 +17,6 @@
60480 */
60481 typedef struct { pgd_t pgd; } pud_t;
60482
60483-#define PUD_SHIFT PGDIR_SHIFT
60484-#define PTRS_PER_PUD 1
60485-#define PUD_SIZE (1UL << PUD_SHIFT)
60486-#define PUD_MASK (~(PUD_SIZE-1))
60487-
60488 /*
60489 * The "pgd_xxx()" functions here are trivial for a folded two-level
60490 * setup: the pud is never bad, and a pud always exists (as it's folded
60491@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
60492 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
60493
60494 #define pgd_populate(mm, pgd, pud) do { } while (0)
60495+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
60496 /*
60497 * (puds are folded into pgds so this doesn't get actually called,
60498 * but the define is needed for a generic inline function.)
60499diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
60500index ff4947b..f48183f 100644
60501--- a/include/asm-generic/pgtable.h
60502+++ b/include/asm-generic/pgtable.h
60503@@ -530,6 +530,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
60504 #endif
60505 }
60506
60507+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
60508+static inline unsigned long pax_open_kernel(void) { return 0; }
60509+#endif
60510+
60511+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
60512+static inline unsigned long pax_close_kernel(void) { return 0; }
60513+#endif
60514+
60515 #endif /* CONFIG_MMU */
60516
60517 #endif /* !__ASSEMBLY__ */
60518diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
60519index 4e2e1cc..12c266b 100644
60520--- a/include/asm-generic/vmlinux.lds.h
60521+++ b/include/asm-generic/vmlinux.lds.h
60522@@ -218,6 +218,7 @@
60523 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
60524 VMLINUX_SYMBOL(__start_rodata) = .; \
60525 *(.rodata) *(.rodata.*) \
60526+ *(.data..read_only) \
60527 *(__vermagic) /* Kernel version magic */ \
60528 . = ALIGN(8); \
60529 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
60530@@ -716,17 +717,18 @@
60531 * section in the linker script will go there too. @phdr should have
60532 * a leading colon.
60533 *
60534- * Note that this macros defines __per_cpu_load as an absolute symbol.
60535+ * Note that this macros defines per_cpu_load as an absolute symbol.
60536 * If there is no need to put the percpu section at a predetermined
60537 * address, use PERCPU_SECTION.
60538 */
60539 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
60540- VMLINUX_SYMBOL(__per_cpu_load) = .; \
60541- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
60542+ per_cpu_load = .; \
60543+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
60544 - LOAD_OFFSET) { \
60545+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
60546 PERCPU_INPUT(cacheline) \
60547 } phdr \
60548- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
60549+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
60550
60551 /**
60552 * PERCPU_SECTION - define output section for percpu area, simple version
60553diff --git a/include/drm/drmP.h b/include/drm/drmP.h
60554index 31ad880..4e79884 100644
60555--- a/include/drm/drmP.h
60556+++ b/include/drm/drmP.h
60557@@ -72,6 +72,7 @@
60558 #include <linux/workqueue.h>
60559 #include <linux/poll.h>
60560 #include <asm/pgalloc.h>
60561+#include <asm/local.h>
60562 #include "drm.h"
60563
60564 #include <linux/idr.h>
60565@@ -1074,7 +1075,7 @@ struct drm_device {
60566
60567 /** \name Usage Counters */
60568 /*@{ */
60569- int open_count; /**< Outstanding files open */
60570+ local_t open_count; /**< Outstanding files open */
60571 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
60572 atomic_t vma_count; /**< Outstanding vma areas open */
60573 int buf_use; /**< Buffers in use -- cannot alloc */
60574@@ -1085,7 +1086,7 @@ struct drm_device {
60575 /*@{ */
60576 unsigned long counters;
60577 enum drm_stat_type types[15];
60578- atomic_t counts[15];
60579+ atomic_unchecked_t counts[15];
60580 /*@} */
60581
60582 struct list_head filelist;
60583diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
60584index 7988e55..ec974c9 100644
60585--- a/include/drm/drm_crtc_helper.h
60586+++ b/include/drm/drm_crtc_helper.h
60587@@ -81,7 +81,7 @@ struct drm_crtc_helper_funcs {
60588
60589 /* disable crtc when not in use - more explicit than dpms off */
60590 void (*disable)(struct drm_crtc *crtc);
60591-};
60592+} __no_const;
60593
60594 /**
60595 * drm_encoder_helper_funcs - helper operations for encoders
60596@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
60597 struct drm_connector *connector);
60598 /* disable encoder when not in use - more explicit than dpms off */
60599 void (*disable)(struct drm_encoder *encoder);
60600-};
60601+} __no_const;
60602
60603 /**
60604 * drm_connector_helper_funcs - helper operations for connectors
60605diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
60606index d6d1da4..fdd1ac5 100644
60607--- a/include/drm/ttm/ttm_memory.h
60608+++ b/include/drm/ttm/ttm_memory.h
60609@@ -48,7 +48,7 @@
60610
60611 struct ttm_mem_shrink {
60612 int (*do_shrink) (struct ttm_mem_shrink *);
60613-};
60614+} __no_const;
60615
60616 /**
60617 * struct ttm_mem_global - Global memory accounting structure.
60618diff --git a/include/linux/a.out.h b/include/linux/a.out.h
60619index e86dfca..40cc55f 100644
60620--- a/include/linux/a.out.h
60621+++ b/include/linux/a.out.h
60622@@ -39,6 +39,14 @@ enum machine_type {
60623 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
60624 };
60625
60626+/* Constants for the N_FLAGS field */
60627+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60628+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
60629+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
60630+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
60631+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60632+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60633+
60634 #if !defined (N_MAGIC)
60635 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
60636 #endif
60637diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
60638index 06fd4bb..1caec0d 100644
60639--- a/include/linux/atmdev.h
60640+++ b/include/linux/atmdev.h
60641@@ -237,7 +237,7 @@ struct compat_atm_iobuf {
60642 #endif
60643
60644 struct k_atm_aal_stats {
60645-#define __HANDLE_ITEM(i) atomic_t i
60646+#define __HANDLE_ITEM(i) atomic_unchecked_t i
60647 __AAL_STAT_ITEMS
60648 #undef __HANDLE_ITEM
60649 };
60650diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
60651index 366422b..1fa7f84 100644
60652--- a/include/linux/binfmts.h
60653+++ b/include/linux/binfmts.h
60654@@ -89,6 +89,7 @@ struct linux_binfmt {
60655 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
60656 int (*load_shlib)(struct file *);
60657 int (*core_dump)(struct coredump_params *cprm);
60658+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
60659 unsigned long min_coredump; /* minimal dump size */
60660 };
60661
60662diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
60663index 07954b0..cb2ae71 100644
60664--- a/include/linux/blkdev.h
60665+++ b/include/linux/blkdev.h
60666@@ -1393,7 +1393,7 @@ struct block_device_operations {
60667 /* this callback is with swap_lock and sometimes page table lock held */
60668 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
60669 struct module *owner;
60670-};
60671+} __do_const;
60672
60673 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
60674 unsigned long);
60675diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
60676index 4d1a074..88f929a 100644
60677--- a/include/linux/blktrace_api.h
60678+++ b/include/linux/blktrace_api.h
60679@@ -162,7 +162,7 @@ struct blk_trace {
60680 struct dentry *dir;
60681 struct dentry *dropped_file;
60682 struct dentry *msg_file;
60683- atomic_t dropped;
60684+ atomic_unchecked_t dropped;
60685 };
60686
60687 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
60688diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
60689index 83195fb..0b0f77d 100644
60690--- a/include/linux/byteorder/little_endian.h
60691+++ b/include/linux/byteorder/little_endian.h
60692@@ -42,51 +42,51 @@
60693
60694 static inline __le64 __cpu_to_le64p(const __u64 *p)
60695 {
60696- return (__force __le64)*p;
60697+ return (__force const __le64)*p;
60698 }
60699 static inline __u64 __le64_to_cpup(const __le64 *p)
60700 {
60701- return (__force __u64)*p;
60702+ return (__force const __u64)*p;
60703 }
60704 static inline __le32 __cpu_to_le32p(const __u32 *p)
60705 {
60706- return (__force __le32)*p;
60707+ return (__force const __le32)*p;
60708 }
60709 static inline __u32 __le32_to_cpup(const __le32 *p)
60710 {
60711- return (__force __u32)*p;
60712+ return (__force const __u32)*p;
60713 }
60714 static inline __le16 __cpu_to_le16p(const __u16 *p)
60715 {
60716- return (__force __le16)*p;
60717+ return (__force const __le16)*p;
60718 }
60719 static inline __u16 __le16_to_cpup(const __le16 *p)
60720 {
60721- return (__force __u16)*p;
60722+ return (__force const __u16)*p;
60723 }
60724 static inline __be64 __cpu_to_be64p(const __u64 *p)
60725 {
60726- return (__force __be64)__swab64p(p);
60727+ return (__force const __be64)__swab64p(p);
60728 }
60729 static inline __u64 __be64_to_cpup(const __be64 *p)
60730 {
60731- return __swab64p((__u64 *)p);
60732+ return __swab64p((const __u64 *)p);
60733 }
60734 static inline __be32 __cpu_to_be32p(const __u32 *p)
60735 {
60736- return (__force __be32)__swab32p(p);
60737+ return (__force const __be32)__swab32p(p);
60738 }
60739 static inline __u32 __be32_to_cpup(const __be32 *p)
60740 {
60741- return __swab32p((__u32 *)p);
60742+ return __swab32p((const __u32 *)p);
60743 }
60744 static inline __be16 __cpu_to_be16p(const __u16 *p)
60745 {
60746- return (__force __be16)__swab16p(p);
60747+ return (__force const __be16)__swab16p(p);
60748 }
60749 static inline __u16 __be16_to_cpup(const __be16 *p)
60750 {
60751- return __swab16p((__u16 *)p);
60752+ return __swab16p((const __u16 *)p);
60753 }
60754 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
60755 #define __le64_to_cpus(x) do { (void)(x); } while (0)
60756diff --git a/include/linux/cache.h b/include/linux/cache.h
60757index 4c57065..4307975 100644
60758--- a/include/linux/cache.h
60759+++ b/include/linux/cache.h
60760@@ -16,6 +16,10 @@
60761 #define __read_mostly
60762 #endif
60763
60764+#ifndef __read_only
60765+#define __read_only __read_mostly
60766+#endif
60767+
60768 #ifndef ____cacheline_aligned
60769 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
60770 #endif
60771diff --git a/include/linux/capability.h b/include/linux/capability.h
60772index d10b7ed..0288b79 100644
60773--- a/include/linux/capability.h
60774+++ b/include/linux/capability.h
60775@@ -553,10 +553,15 @@ extern bool capable(int cap);
60776 extern bool ns_capable(struct user_namespace *ns, int cap);
60777 extern bool nsown_capable(int cap);
60778 extern bool inode_capable(const struct inode *inode, int cap);
60779+extern bool capable_nolog(int cap);
60780+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
60781+extern bool inode_capable_nolog(const struct inode *inode, int cap);
60782
60783 /* audit system wants to get cap info from files as well */
60784 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
60785
60786+extern int is_privileged_binary(const struct dentry *dentry);
60787+
60788 #endif /* __KERNEL__ */
60789
60790 #endif /* !_LINUX_CAPABILITY_H */
60791diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
60792index 42e55de..1cd0e66 100644
60793--- a/include/linux/cleancache.h
60794+++ b/include/linux/cleancache.h
60795@@ -31,7 +31,7 @@ struct cleancache_ops {
60796 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
60797 void (*invalidate_inode)(int, struct cleancache_filekey);
60798 void (*invalidate_fs)(int);
60799-};
60800+} __no_const;
60801
60802 extern struct cleancache_ops
60803 cleancache_register_ops(struct cleancache_ops *ops);
60804diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
60805index 4a0b483..f1f70ba 100644
60806--- a/include/linux/clk-provider.h
60807+++ b/include/linux/clk-provider.h
60808@@ -110,6 +110,7 @@ struct clk_ops {
60809 unsigned long);
60810 void (*init)(struct clk_hw *hw);
60811 };
60812+typedef struct clk_ops __no_const clk_ops_no_const;
60813
60814 /**
60815 * struct clk_init_data - holds init data that's common to all clocks and is
60816diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
60817index 2f40791..9c9e13c 100644
60818--- a/include/linux/compiler-gcc4.h
60819+++ b/include/linux/compiler-gcc4.h
60820@@ -32,6 +32,20 @@
60821 #define __linktime_error(message) __attribute__((__error__(message)))
60822
60823 #if __GNUC_MINOR__ >= 5
60824+
60825+#ifdef CONSTIFY_PLUGIN
60826+#define __no_const __attribute__((no_const))
60827+#define __do_const __attribute__((do_const))
60828+#endif
60829+
60830+#ifdef SIZE_OVERFLOW_PLUGIN
60831+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
60832+#endif
60833+
60834+#ifdef LATENT_ENTROPY_PLUGIN
60835+#define __latent_entropy __attribute__((latent_entropy))
60836+#endif
60837+
60838 /*
60839 * Mark a position in code as unreachable. This can be used to
60840 * suppress control flow warnings after asm blocks that transfer
60841@@ -47,6 +61,11 @@
60842 #define __noclone __attribute__((__noclone__))
60843
60844 #endif
60845+
60846+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
60847+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
60848+#define __bos0(ptr) __bos((ptr), 0)
60849+#define __bos1(ptr) __bos((ptr), 1)
60850 #endif
60851
60852 #if __GNUC_MINOR__ > 0
60853diff --git a/include/linux/compiler.h b/include/linux/compiler.h
60854index 923d093..1fef491 100644
60855--- a/include/linux/compiler.h
60856+++ b/include/linux/compiler.h
60857@@ -5,31 +5,62 @@
60858
60859 #ifdef __CHECKER__
60860 # define __user __attribute__((noderef, address_space(1)))
60861+# define __force_user __force __user
60862 # define __kernel __attribute__((address_space(0)))
60863+# define __force_kernel __force __kernel
60864 # define __safe __attribute__((safe))
60865 # define __force __attribute__((force))
60866 # define __nocast __attribute__((nocast))
60867 # define __iomem __attribute__((noderef, address_space(2)))
60868+# define __force_iomem __force __iomem
60869 # define __acquires(x) __attribute__((context(x,0,1)))
60870 # define __releases(x) __attribute__((context(x,1,0)))
60871 # define __acquire(x) __context__(x,1)
60872 # define __release(x) __context__(x,-1)
60873 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
60874 # define __percpu __attribute__((noderef, address_space(3)))
60875+# define __force_percpu __force __percpu
60876 #ifdef CONFIG_SPARSE_RCU_POINTER
60877 # define __rcu __attribute__((noderef, address_space(4)))
60878+# define __force_rcu __force __rcu
60879 #else
60880 # define __rcu
60881+# define __force_rcu
60882 #endif
60883 extern void __chk_user_ptr(const volatile void __user *);
60884 extern void __chk_io_ptr(const volatile void __iomem *);
60885+#elif defined(CHECKER_PLUGIN)
60886+//# define __user
60887+//# define __force_user
60888+//# define __kernel
60889+//# define __force_kernel
60890+# define __safe
60891+# define __force
60892+# define __nocast
60893+# define __iomem
60894+# define __force_iomem
60895+# define __chk_user_ptr(x) (void)0
60896+# define __chk_io_ptr(x) (void)0
60897+# define __builtin_warning(x, y...) (1)
60898+# define __acquires(x)
60899+# define __releases(x)
60900+# define __acquire(x) (void)0
60901+# define __release(x) (void)0
60902+# define __cond_lock(x,c) (c)
60903+# define __percpu
60904+# define __force_percpu
60905+# define __rcu
60906+# define __force_rcu
60907 #else
60908 # define __user
60909+# define __force_user
60910 # define __kernel
60911+# define __force_kernel
60912 # define __safe
60913 # define __force
60914 # define __nocast
60915 # define __iomem
60916+# define __force_iomem
60917 # define __chk_user_ptr(x) (void)0
60918 # define __chk_io_ptr(x) (void)0
60919 # define __builtin_warning(x, y...) (1)
60920@@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
60921 # define __release(x) (void)0
60922 # define __cond_lock(x,c) (c)
60923 # define __percpu
60924+# define __force_percpu
60925 # define __rcu
60926+# define __force_rcu
60927 #endif
60928
60929 #ifdef __KERNEL__
60930@@ -264,6 +297,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60931 # define __attribute_const__ /* unimplemented */
60932 #endif
60933
60934+#ifndef __no_const
60935+# define __no_const
60936+#endif
60937+
60938+#ifndef __do_const
60939+# define __do_const
60940+#endif
60941+
60942+#ifndef __size_overflow
60943+# define __size_overflow(...)
60944+#endif
60945+
60946+#ifndef __latent_entropy
60947+# define __latent_entropy
60948+#endif
60949+
60950 /*
60951 * Tell gcc if a function is cold. The compiler will assume any path
60952 * directly leading to the call is unlikely.
60953@@ -273,6 +322,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60954 #define __cold
60955 #endif
60956
60957+#ifndef __alloc_size
60958+#define __alloc_size(...)
60959+#endif
60960+
60961+#ifndef __bos
60962+#define __bos(ptr, arg)
60963+#endif
60964+
60965+#ifndef __bos0
60966+#define __bos0(ptr)
60967+#endif
60968+
60969+#ifndef __bos1
60970+#define __bos1(ptr)
60971+#endif
60972+
60973 /* Simple shorthand for a section definition */
60974 #ifndef __section
60975 # define __section(S) __attribute__ ((__section__(#S)))
60976@@ -308,6 +373,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60977 * use is to mediate communication between process-level code and irq/NMI
60978 * handlers, all running on the same CPU.
60979 */
60980-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
60981+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
60982+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
60983
60984 #endif /* __LINUX_COMPILER_H */
60985diff --git a/include/linux/cred.h b/include/linux/cred.h
60986index ebbed2c..908cc2c 100644
60987--- a/include/linux/cred.h
60988+++ b/include/linux/cred.h
60989@@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
60990 static inline void validate_process_creds(void)
60991 {
60992 }
60993+static inline void validate_task_creds(struct task_struct *task)
60994+{
60995+}
60996 #endif
60997
60998 /**
60999diff --git a/include/linux/crypto.h b/include/linux/crypto.h
61000index b92eadf..b4ecdc1 100644
61001--- a/include/linux/crypto.h
61002+++ b/include/linux/crypto.h
61003@@ -373,7 +373,7 @@ struct cipher_tfm {
61004 const u8 *key, unsigned int keylen);
61005 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61006 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61007-};
61008+} __no_const;
61009
61010 struct hash_tfm {
61011 int (*init)(struct hash_desc *desc);
61012@@ -394,13 +394,13 @@ struct compress_tfm {
61013 int (*cot_decompress)(struct crypto_tfm *tfm,
61014 const u8 *src, unsigned int slen,
61015 u8 *dst, unsigned int *dlen);
61016-};
61017+} __no_const;
61018
61019 struct rng_tfm {
61020 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
61021 unsigned int dlen);
61022 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
61023-};
61024+} __no_const;
61025
61026 #define crt_ablkcipher crt_u.ablkcipher
61027 #define crt_aead crt_u.aead
61028diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
61029index 7925bf0..d5143d2 100644
61030--- a/include/linux/decompress/mm.h
61031+++ b/include/linux/decompress/mm.h
61032@@ -77,7 +77,7 @@ static void free(void *where)
61033 * warnings when not needed (indeed large_malloc / large_free are not
61034 * needed by inflate */
61035
61036-#define malloc(a) kmalloc(a, GFP_KERNEL)
61037+#define malloc(a) kmalloc((a), GFP_KERNEL)
61038 #define free(a) kfree(a)
61039
61040 #define large_malloc(a) vmalloc(a)
61041diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
61042index dfc099e..e583e66 100644
61043--- a/include/linux/dma-mapping.h
61044+++ b/include/linux/dma-mapping.h
61045@@ -51,7 +51,7 @@ struct dma_map_ops {
61046 u64 (*get_required_mask)(struct device *dev);
61047 #endif
61048 int is_phys;
61049-};
61050+} __do_const;
61051
61052 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
61053
61054diff --git a/include/linux/efi.h b/include/linux/efi.h
61055index ec45ccd..9923c32 100644
61056--- a/include/linux/efi.h
61057+++ b/include/linux/efi.h
61058@@ -635,7 +635,7 @@ struct efivar_operations {
61059 efi_get_variable_t *get_variable;
61060 efi_get_next_variable_t *get_next_variable;
61061 efi_set_variable_t *set_variable;
61062-};
61063+} __no_const;
61064
61065 struct efivars {
61066 /*
61067diff --git a/include/linux/elf.h b/include/linux/elf.h
61068index 999b4f5..57753b4 100644
61069--- a/include/linux/elf.h
61070+++ b/include/linux/elf.h
61071@@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
61072 #define PT_GNU_EH_FRAME 0x6474e550
61073
61074 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
61075+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
61076+
61077+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
61078+
61079+/* Constants for the e_flags field */
61080+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61081+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
61082+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
61083+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
61084+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61085+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61086
61087 /*
61088 * Extended Numbering
61089@@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
61090 #define DT_DEBUG 21
61091 #define DT_TEXTREL 22
61092 #define DT_JMPREL 23
61093+#define DT_FLAGS 30
61094+ #define DF_TEXTREL 0x00000004
61095 #define DT_ENCODING 32
61096 #define OLD_DT_LOOS 0x60000000
61097 #define DT_LOOS 0x6000000d
61098@@ -243,6 +256,19 @@ typedef struct elf64_hdr {
61099 #define PF_W 0x2
61100 #define PF_X 0x1
61101
61102+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
61103+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
61104+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
61105+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
61106+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
61107+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
61108+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
61109+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
61110+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
61111+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
61112+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
61113+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
61114+
61115 typedef struct elf32_phdr{
61116 Elf32_Word p_type;
61117 Elf32_Off p_offset;
61118@@ -335,6 +361,8 @@ typedef struct elf64_shdr {
61119 #define EI_OSABI 7
61120 #define EI_PAD 8
61121
61122+#define EI_PAX 14
61123+
61124 #define ELFMAG0 0x7f /* EI_MAG */
61125 #define ELFMAG1 'E'
61126 #define ELFMAG2 'L'
61127@@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
61128 #define elf_note elf32_note
61129 #define elf_addr_t Elf32_Off
61130 #define Elf_Half Elf32_Half
61131+#define elf_dyn Elf32_Dyn
61132
61133 #else
61134
61135@@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
61136 #define elf_note elf64_note
61137 #define elf_addr_t Elf64_Off
61138 #define Elf_Half Elf64_Half
61139+#define elf_dyn Elf64_Dyn
61140
61141 #endif
61142
61143diff --git a/include/linux/filter.h b/include/linux/filter.h
61144index 82b0135..917914d 100644
61145--- a/include/linux/filter.h
61146+++ b/include/linux/filter.h
61147@@ -146,6 +146,7 @@ struct compat_sock_fprog {
61148
61149 struct sk_buff;
61150 struct sock;
61151+struct bpf_jit_work;
61152
61153 struct sk_filter
61154 {
61155@@ -153,6 +154,9 @@ struct sk_filter
61156 unsigned int len; /* Number of filter blocks */
61157 unsigned int (*bpf_func)(const struct sk_buff *skb,
61158 const struct sock_filter *filter);
61159+#ifdef CONFIG_BPF_JIT
61160+ struct bpf_jit_work *work;
61161+#endif
61162 struct rcu_head rcu;
61163 struct sock_filter insns[0];
61164 };
61165diff --git a/include/linux/firewire.h b/include/linux/firewire.h
61166index 7edcf10..714d5e8 100644
61167--- a/include/linux/firewire.h
61168+++ b/include/linux/firewire.h
61169@@ -430,7 +430,7 @@ struct fw_iso_context {
61170 union {
61171 fw_iso_callback_t sc;
61172 fw_iso_mc_callback_t mc;
61173- } callback;
61174+ } __no_const callback;
61175 void *callback_data;
61176 };
61177
61178diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
61179index 0e4e2ee..4ff4312 100644
61180--- a/include/linux/frontswap.h
61181+++ b/include/linux/frontswap.h
61182@@ -11,7 +11,7 @@ struct frontswap_ops {
61183 int (*load)(unsigned, pgoff_t, struct page *);
61184 void (*invalidate_page)(unsigned, pgoff_t);
61185 void (*invalidate_area)(unsigned);
61186-};
61187+} __no_const;
61188
61189 extern bool frontswap_enabled;
61190 extern struct frontswap_ops
61191diff --git a/include/linux/fs.h b/include/linux/fs.h
61192index 17fd887..8eebca0 100644
61193--- a/include/linux/fs.h
61194+++ b/include/linux/fs.h
61195@@ -1663,7 +1663,8 @@ struct file_operations {
61196 int (*setlease)(struct file *, long, struct file_lock **);
61197 long (*fallocate)(struct file *file, int mode, loff_t offset,
61198 loff_t len);
61199-};
61200+} __do_const;
61201+typedef struct file_operations __no_const file_operations_no_const;
61202
61203 struct inode_operations {
61204 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
61205diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
61206index 003dc0f..3c4ea97 100644
61207--- a/include/linux/fs_struct.h
61208+++ b/include/linux/fs_struct.h
61209@@ -6,7 +6,7 @@
61210 #include <linux/seqlock.h>
61211
61212 struct fs_struct {
61213- int users;
61214+ atomic_t users;
61215 spinlock_t lock;
61216 seqcount_t seq;
61217 int umask;
61218diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
61219index ce31408..b1ad003 100644
61220--- a/include/linux/fscache-cache.h
61221+++ b/include/linux/fscache-cache.h
61222@@ -102,7 +102,7 @@ struct fscache_operation {
61223 fscache_operation_release_t release;
61224 };
61225
61226-extern atomic_t fscache_op_debug_id;
61227+extern atomic_unchecked_t fscache_op_debug_id;
61228 extern void fscache_op_work_func(struct work_struct *work);
61229
61230 extern void fscache_enqueue_operation(struct fscache_operation *);
61231@@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
61232 {
61233 INIT_WORK(&op->work, fscache_op_work_func);
61234 atomic_set(&op->usage, 1);
61235- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
61236+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61237 op->processor = processor;
61238 op->release = release;
61239 INIT_LIST_HEAD(&op->pend_link);
61240diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
61241index a6dfe69..569586df 100644
61242--- a/include/linux/fsnotify.h
61243+++ b/include/linux/fsnotify.h
61244@@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
61245 */
61246 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
61247 {
61248- return kstrdup(name, GFP_KERNEL);
61249+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
61250 }
61251
61252 /*
61253diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
61254index 63d966d..cdcb717 100644
61255--- a/include/linux/fsnotify_backend.h
61256+++ b/include/linux/fsnotify_backend.h
61257@@ -105,6 +105,7 @@ struct fsnotify_ops {
61258 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
61259 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
61260 };
61261+typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
61262
61263 /*
61264 * A group is a "thing" that wants to receive notification about filesystem
61265diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
61266index 176a939..1462211 100644
61267--- a/include/linux/ftrace_event.h
61268+++ b/include/linux/ftrace_event.h
61269@@ -97,7 +97,7 @@ struct trace_event_functions {
61270 trace_print_func raw;
61271 trace_print_func hex;
61272 trace_print_func binary;
61273-};
61274+} __no_const;
61275
61276 struct trace_event {
61277 struct hlist_node node;
61278@@ -263,7 +263,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
61279 extern int trace_add_event_call(struct ftrace_event_call *call);
61280 extern void trace_remove_event_call(struct ftrace_event_call *call);
61281
61282-#define is_signed_type(type) (((type)(-1)) < 0)
61283+#define is_signed_type(type) (((type)(-1)) < (type)1)
61284
61285 int trace_set_clr_event(const char *system, const char *event, int set);
61286
61287diff --git a/include/linux/genhd.h b/include/linux/genhd.h
61288index 017a7fb..33a8507 100644
61289--- a/include/linux/genhd.h
61290+++ b/include/linux/genhd.h
61291@@ -185,7 +185,7 @@ struct gendisk {
61292 struct kobject *slave_dir;
61293
61294 struct timer_rand_state *random;
61295- atomic_t sync_io; /* RAID */
61296+ atomic_unchecked_t sync_io; /* RAID */
61297 struct disk_events *ev;
61298 #ifdef CONFIG_BLK_DEV_INTEGRITY
61299 struct blk_integrity *integrity;
61300diff --git a/include/linux/gfp.h b/include/linux/gfp.h
61301index 1e49be4..b8a9305 100644
61302--- a/include/linux/gfp.h
61303+++ b/include/linux/gfp.h
61304@@ -38,6 +38,12 @@ struct vm_area_struct;
61305 #define ___GFP_OTHER_NODE 0x800000u
61306 #define ___GFP_WRITE 0x1000000u
61307
61308+#ifdef CONFIG_PAX_USERCOPY_SLABS
61309+#define ___GFP_USERCOPY 0x2000000u
61310+#else
61311+#define ___GFP_USERCOPY 0
61312+#endif
61313+
61314 /*
61315 * GFP bitmasks..
61316 *
61317@@ -87,6 +93,7 @@ struct vm_area_struct;
61318 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
61319 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
61320 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
61321+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
61322
61323 /*
61324 * This may seem redundant, but it's a way of annotating false positives vs.
61325@@ -94,7 +101,7 @@ struct vm_area_struct;
61326 */
61327 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
61328
61329-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
61330+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
61331 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
61332
61333 /* This equals 0, but use constants in case they ever change */
61334@@ -148,6 +155,8 @@ struct vm_area_struct;
61335 /* 4GB DMA on some platforms */
61336 #define GFP_DMA32 __GFP_DMA32
61337
61338+#define GFP_USERCOPY __GFP_USERCOPY
61339+
61340 /* Convert GFP flags to their corresponding migrate type */
61341 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
61342 {
61343diff --git a/include/linux/gracl.h b/include/linux/gracl.h
61344new file mode 100644
61345index 0000000..c938b1f
61346--- /dev/null
61347+++ b/include/linux/gracl.h
61348@@ -0,0 +1,319 @@
61349+#ifndef GR_ACL_H
61350+#define GR_ACL_H
61351+
61352+#include <linux/grdefs.h>
61353+#include <linux/resource.h>
61354+#include <linux/capability.h>
61355+#include <linux/dcache.h>
61356+#include <asm/resource.h>
61357+
61358+/* Major status information */
61359+
61360+#define GR_VERSION "grsecurity 2.9.1"
61361+#define GRSECURITY_VERSION 0x2901
61362+
61363+enum {
61364+ GR_SHUTDOWN = 0,
61365+ GR_ENABLE = 1,
61366+ GR_SPROLE = 2,
61367+ GR_RELOAD = 3,
61368+ GR_SEGVMOD = 4,
61369+ GR_STATUS = 5,
61370+ GR_UNSPROLE = 6,
61371+ GR_PASSSET = 7,
61372+ GR_SPROLEPAM = 8,
61373+};
61374+
61375+/* Password setup definitions
61376+ * kernel/grhash.c */
61377+enum {
61378+ GR_PW_LEN = 128,
61379+ GR_SALT_LEN = 16,
61380+ GR_SHA_LEN = 32,
61381+};
61382+
61383+enum {
61384+ GR_SPROLE_LEN = 64,
61385+};
61386+
61387+enum {
61388+ GR_NO_GLOB = 0,
61389+ GR_REG_GLOB,
61390+ GR_CREATE_GLOB
61391+};
61392+
61393+#define GR_NLIMITS 32
61394+
61395+/* Begin Data Structures */
61396+
61397+struct sprole_pw {
61398+ unsigned char *rolename;
61399+ unsigned char salt[GR_SALT_LEN];
61400+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
61401+};
61402+
61403+struct name_entry {
61404+ __u32 key;
61405+ ino_t inode;
61406+ dev_t device;
61407+ char *name;
61408+ __u16 len;
61409+ __u8 deleted;
61410+ struct name_entry *prev;
61411+ struct name_entry *next;
61412+};
61413+
61414+struct inodev_entry {
61415+ struct name_entry *nentry;
61416+ struct inodev_entry *prev;
61417+ struct inodev_entry *next;
61418+};
61419+
61420+struct acl_role_db {
61421+ struct acl_role_label **r_hash;
61422+ __u32 r_size;
61423+};
61424+
61425+struct inodev_db {
61426+ struct inodev_entry **i_hash;
61427+ __u32 i_size;
61428+};
61429+
61430+struct name_db {
61431+ struct name_entry **n_hash;
61432+ __u32 n_size;
61433+};
61434+
61435+struct crash_uid {
61436+ uid_t uid;
61437+ unsigned long expires;
61438+};
61439+
61440+struct gr_hash_struct {
61441+ void **table;
61442+ void **nametable;
61443+ void *first;
61444+ __u32 table_size;
61445+ __u32 used_size;
61446+ int type;
61447+};
61448+
61449+/* Userspace Grsecurity ACL data structures */
61450+
61451+struct acl_subject_label {
61452+ char *filename;
61453+ ino_t inode;
61454+ dev_t device;
61455+ __u32 mode;
61456+ kernel_cap_t cap_mask;
61457+ kernel_cap_t cap_lower;
61458+ kernel_cap_t cap_invert_audit;
61459+
61460+ struct rlimit res[GR_NLIMITS];
61461+ __u32 resmask;
61462+
61463+ __u8 user_trans_type;
61464+ __u8 group_trans_type;
61465+ uid_t *user_transitions;
61466+ gid_t *group_transitions;
61467+ __u16 user_trans_num;
61468+ __u16 group_trans_num;
61469+
61470+ __u32 sock_families[2];
61471+ __u32 ip_proto[8];
61472+ __u32 ip_type;
61473+ struct acl_ip_label **ips;
61474+ __u32 ip_num;
61475+ __u32 inaddr_any_override;
61476+
61477+ __u32 crashes;
61478+ unsigned long expires;
61479+
61480+ struct acl_subject_label *parent_subject;
61481+ struct gr_hash_struct *hash;
61482+ struct acl_subject_label *prev;
61483+ struct acl_subject_label *next;
61484+
61485+ struct acl_object_label **obj_hash;
61486+ __u32 obj_hash_size;
61487+ __u16 pax_flags;
61488+};
61489+
61490+struct role_allowed_ip {
61491+ __u32 addr;
61492+ __u32 netmask;
61493+
61494+ struct role_allowed_ip *prev;
61495+ struct role_allowed_ip *next;
61496+};
61497+
61498+struct role_transition {
61499+ char *rolename;
61500+
61501+ struct role_transition *prev;
61502+ struct role_transition *next;
61503+};
61504+
61505+struct acl_role_label {
61506+ char *rolename;
61507+ uid_t uidgid;
61508+ __u16 roletype;
61509+
61510+ __u16 auth_attempts;
61511+ unsigned long expires;
61512+
61513+ struct acl_subject_label *root_label;
61514+ struct gr_hash_struct *hash;
61515+
61516+ struct acl_role_label *prev;
61517+ struct acl_role_label *next;
61518+
61519+ struct role_transition *transitions;
61520+ struct role_allowed_ip *allowed_ips;
61521+ uid_t *domain_children;
61522+ __u16 domain_child_num;
61523+
61524+ umode_t umask;
61525+
61526+ struct acl_subject_label **subj_hash;
61527+ __u32 subj_hash_size;
61528+};
61529+
61530+struct user_acl_role_db {
61531+ struct acl_role_label **r_table;
61532+ __u32 num_pointers; /* Number of allocations to track */
61533+ __u32 num_roles; /* Number of roles */
61534+ __u32 num_domain_children; /* Number of domain children */
61535+ __u32 num_subjects; /* Number of subjects */
61536+ __u32 num_objects; /* Number of objects */
61537+};
61538+
61539+struct acl_object_label {
61540+ char *filename;
61541+ ino_t inode;
61542+ dev_t device;
61543+ __u32 mode;
61544+
61545+ struct acl_subject_label *nested;
61546+ struct acl_object_label *globbed;
61547+
61548+ /* next two structures not used */
61549+
61550+ struct acl_object_label *prev;
61551+ struct acl_object_label *next;
61552+};
61553+
61554+struct acl_ip_label {
61555+ char *iface;
61556+ __u32 addr;
61557+ __u32 netmask;
61558+ __u16 low, high;
61559+ __u8 mode;
61560+ __u32 type;
61561+ __u32 proto[8];
61562+
61563+ /* next two structures not used */
61564+
61565+ struct acl_ip_label *prev;
61566+ struct acl_ip_label *next;
61567+};
61568+
61569+struct gr_arg {
61570+ struct user_acl_role_db role_db;
61571+ unsigned char pw[GR_PW_LEN];
61572+ unsigned char salt[GR_SALT_LEN];
61573+ unsigned char sum[GR_SHA_LEN];
61574+ unsigned char sp_role[GR_SPROLE_LEN];
61575+ struct sprole_pw *sprole_pws;
61576+ dev_t segv_device;
61577+ ino_t segv_inode;
61578+ uid_t segv_uid;
61579+ __u16 num_sprole_pws;
61580+ __u16 mode;
61581+};
61582+
61583+struct gr_arg_wrapper {
61584+ struct gr_arg *arg;
61585+ __u32 version;
61586+ __u32 size;
61587+};
61588+
61589+struct subject_map {
61590+ struct acl_subject_label *user;
61591+ struct acl_subject_label *kernel;
61592+ struct subject_map *prev;
61593+ struct subject_map *next;
61594+};
61595+
61596+struct acl_subj_map_db {
61597+ struct subject_map **s_hash;
61598+ __u32 s_size;
61599+};
61600+
61601+/* End Data Structures Section */
61602+
61603+/* Hash functions generated by empirical testing by Brad Spengler
61604+ Makes good use of the low bits of the inode. Generally 0-1 times
61605+ in loop for successful match. 0-3 for unsuccessful match.
61606+ Shift/add algorithm with modulus of table size and an XOR*/
61607+
61608+static __inline__ unsigned int
61609+rhash(const uid_t uid, const __u16 type, const unsigned int sz)
61610+{
61611+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
61612+}
61613+
61614+ static __inline__ unsigned int
61615+shash(const struct acl_subject_label *userp, const unsigned int sz)
61616+{
61617+ return ((const unsigned long)userp % sz);
61618+}
61619+
61620+static __inline__ unsigned int
61621+fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
61622+{
61623+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
61624+}
61625+
61626+static __inline__ unsigned int
61627+nhash(const char *name, const __u16 len, const unsigned int sz)
61628+{
61629+ return full_name_hash((const unsigned char *)name, len) % sz;
61630+}
61631+
61632+#define FOR_EACH_ROLE_START(role) \
61633+ role = role_list; \
61634+ while (role) {
61635+
61636+#define FOR_EACH_ROLE_END(role) \
61637+ role = role->prev; \
61638+ }
61639+
61640+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
61641+ subj = NULL; \
61642+ iter = 0; \
61643+ while (iter < role->subj_hash_size) { \
61644+ if (subj == NULL) \
61645+ subj = role->subj_hash[iter]; \
61646+ if (subj == NULL) { \
61647+ iter++; \
61648+ continue; \
61649+ }
61650+
61651+#define FOR_EACH_SUBJECT_END(subj,iter) \
61652+ subj = subj->next; \
61653+ if (subj == NULL) \
61654+ iter++; \
61655+ }
61656+
61657+
61658+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
61659+ subj = role->hash->first; \
61660+ while (subj != NULL) {
61661+
61662+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
61663+ subj = subj->next; \
61664+ }
61665+
61666+#endif
61667+
61668diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
61669new file mode 100644
61670index 0000000..323ecf2
61671--- /dev/null
61672+++ b/include/linux/gralloc.h
61673@@ -0,0 +1,9 @@
61674+#ifndef __GRALLOC_H
61675+#define __GRALLOC_H
61676+
61677+void acl_free_all(void);
61678+int acl_alloc_stack_init(unsigned long size);
61679+void *acl_alloc(unsigned long len);
61680+void *acl_alloc_num(unsigned long num, unsigned long len);
61681+
61682+#endif
61683diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
61684new file mode 100644
61685index 0000000..b30e9bc
61686--- /dev/null
61687+++ b/include/linux/grdefs.h
61688@@ -0,0 +1,140 @@
61689+#ifndef GRDEFS_H
61690+#define GRDEFS_H
61691+
61692+/* Begin grsecurity status declarations */
61693+
61694+enum {
61695+ GR_READY = 0x01,
61696+ GR_STATUS_INIT = 0x00 // disabled state
61697+};
61698+
61699+/* Begin ACL declarations */
61700+
61701+/* Role flags */
61702+
61703+enum {
61704+ GR_ROLE_USER = 0x0001,
61705+ GR_ROLE_GROUP = 0x0002,
61706+ GR_ROLE_DEFAULT = 0x0004,
61707+ GR_ROLE_SPECIAL = 0x0008,
61708+ GR_ROLE_AUTH = 0x0010,
61709+ GR_ROLE_NOPW = 0x0020,
61710+ GR_ROLE_GOD = 0x0040,
61711+ GR_ROLE_LEARN = 0x0080,
61712+ GR_ROLE_TPE = 0x0100,
61713+ GR_ROLE_DOMAIN = 0x0200,
61714+ GR_ROLE_PAM = 0x0400,
61715+ GR_ROLE_PERSIST = 0x0800
61716+};
61717+
61718+/* ACL Subject and Object mode flags */
61719+enum {
61720+ GR_DELETED = 0x80000000
61721+};
61722+
61723+/* ACL Object-only mode flags */
61724+enum {
61725+ GR_READ = 0x00000001,
61726+ GR_APPEND = 0x00000002,
61727+ GR_WRITE = 0x00000004,
61728+ GR_EXEC = 0x00000008,
61729+ GR_FIND = 0x00000010,
61730+ GR_INHERIT = 0x00000020,
61731+ GR_SETID = 0x00000040,
61732+ GR_CREATE = 0x00000080,
61733+ GR_DELETE = 0x00000100,
61734+ GR_LINK = 0x00000200,
61735+ GR_AUDIT_READ = 0x00000400,
61736+ GR_AUDIT_APPEND = 0x00000800,
61737+ GR_AUDIT_WRITE = 0x00001000,
61738+ GR_AUDIT_EXEC = 0x00002000,
61739+ GR_AUDIT_FIND = 0x00004000,
61740+ GR_AUDIT_INHERIT= 0x00008000,
61741+ GR_AUDIT_SETID = 0x00010000,
61742+ GR_AUDIT_CREATE = 0x00020000,
61743+ GR_AUDIT_DELETE = 0x00040000,
61744+ GR_AUDIT_LINK = 0x00080000,
61745+ GR_PTRACERD = 0x00100000,
61746+ GR_NOPTRACE = 0x00200000,
61747+ GR_SUPPRESS = 0x00400000,
61748+ GR_NOLEARN = 0x00800000,
61749+ GR_INIT_TRANSFER= 0x01000000
61750+};
61751+
61752+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
61753+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
61754+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
61755+
61756+/* ACL subject-only mode flags */
61757+enum {
61758+ GR_KILL = 0x00000001,
61759+ GR_VIEW = 0x00000002,
61760+ GR_PROTECTED = 0x00000004,
61761+ GR_LEARN = 0x00000008,
61762+ GR_OVERRIDE = 0x00000010,
61763+ /* just a placeholder, this mode is only used in userspace */
61764+ GR_DUMMY = 0x00000020,
61765+ GR_PROTSHM = 0x00000040,
61766+ GR_KILLPROC = 0x00000080,
61767+ GR_KILLIPPROC = 0x00000100,
61768+ /* just a placeholder, this mode is only used in userspace */
61769+ GR_NOTROJAN = 0x00000200,
61770+ GR_PROTPROCFD = 0x00000400,
61771+ GR_PROCACCT = 0x00000800,
61772+ GR_RELAXPTRACE = 0x00001000,
61773+ GR_NESTED = 0x00002000,
61774+ GR_INHERITLEARN = 0x00004000,
61775+ GR_PROCFIND = 0x00008000,
61776+ GR_POVERRIDE = 0x00010000,
61777+ GR_KERNELAUTH = 0x00020000,
61778+ GR_ATSECURE = 0x00040000,
61779+ GR_SHMEXEC = 0x00080000
61780+};
61781+
61782+enum {
61783+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
61784+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
61785+ GR_PAX_ENABLE_MPROTECT = 0x0004,
61786+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
61787+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
61788+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
61789+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
61790+ GR_PAX_DISABLE_MPROTECT = 0x0400,
61791+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
61792+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
61793+};
61794+
61795+enum {
61796+ GR_ID_USER = 0x01,
61797+ GR_ID_GROUP = 0x02,
61798+};
61799+
61800+enum {
61801+ GR_ID_ALLOW = 0x01,
61802+ GR_ID_DENY = 0x02,
61803+};
61804+
61805+#define GR_CRASH_RES 31
61806+#define GR_UIDTABLE_MAX 500
61807+
61808+/* begin resource learning section */
61809+enum {
61810+ GR_RLIM_CPU_BUMP = 60,
61811+ GR_RLIM_FSIZE_BUMP = 50000,
61812+ GR_RLIM_DATA_BUMP = 10000,
61813+ GR_RLIM_STACK_BUMP = 1000,
61814+ GR_RLIM_CORE_BUMP = 10000,
61815+ GR_RLIM_RSS_BUMP = 500000,
61816+ GR_RLIM_NPROC_BUMP = 1,
61817+ GR_RLIM_NOFILE_BUMP = 5,
61818+ GR_RLIM_MEMLOCK_BUMP = 50000,
61819+ GR_RLIM_AS_BUMP = 500000,
61820+ GR_RLIM_LOCKS_BUMP = 2,
61821+ GR_RLIM_SIGPENDING_BUMP = 5,
61822+ GR_RLIM_MSGQUEUE_BUMP = 10000,
61823+ GR_RLIM_NICE_BUMP = 1,
61824+ GR_RLIM_RTPRIO_BUMP = 1,
61825+ GR_RLIM_RTTIME_BUMP = 1000000
61826+};
61827+
61828+#endif
61829diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
61830new file mode 100644
61831index 0000000..c9292f7
61832--- /dev/null
61833+++ b/include/linux/grinternal.h
61834@@ -0,0 +1,223 @@
61835+#ifndef __GRINTERNAL_H
61836+#define __GRINTERNAL_H
61837+
61838+#ifdef CONFIG_GRKERNSEC
61839+
61840+#include <linux/fs.h>
61841+#include <linux/mnt_namespace.h>
61842+#include <linux/nsproxy.h>
61843+#include <linux/gracl.h>
61844+#include <linux/grdefs.h>
61845+#include <linux/grmsg.h>
61846+
61847+void gr_add_learn_entry(const char *fmt, ...)
61848+ __attribute__ ((format (printf, 1, 2)));
61849+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
61850+ const struct vfsmount *mnt);
61851+__u32 gr_check_create(const struct dentry *new_dentry,
61852+ const struct dentry *parent,
61853+ const struct vfsmount *mnt, const __u32 mode);
61854+int gr_check_protected_task(const struct task_struct *task);
61855+__u32 to_gr_audit(const __u32 reqmode);
61856+int gr_set_acls(const int type);
61857+int gr_apply_subject_to_task(struct task_struct *task);
61858+int gr_acl_is_enabled(void);
61859+char gr_roletype_to_char(void);
61860+
61861+void gr_handle_alertkill(struct task_struct *task);
61862+char *gr_to_filename(const struct dentry *dentry,
61863+ const struct vfsmount *mnt);
61864+char *gr_to_filename1(const struct dentry *dentry,
61865+ const struct vfsmount *mnt);
61866+char *gr_to_filename2(const struct dentry *dentry,
61867+ const struct vfsmount *mnt);
61868+char *gr_to_filename3(const struct dentry *dentry,
61869+ const struct vfsmount *mnt);
61870+
61871+extern int grsec_enable_ptrace_readexec;
61872+extern int grsec_enable_harden_ptrace;
61873+extern int grsec_enable_link;
61874+extern int grsec_enable_fifo;
61875+extern int grsec_enable_execve;
61876+extern int grsec_enable_shm;
61877+extern int grsec_enable_execlog;
61878+extern int grsec_enable_signal;
61879+extern int grsec_enable_audit_ptrace;
61880+extern int grsec_enable_forkfail;
61881+extern int grsec_enable_time;
61882+extern int grsec_enable_rofs;
61883+extern int grsec_enable_chroot_shmat;
61884+extern int grsec_enable_chroot_mount;
61885+extern int grsec_enable_chroot_double;
61886+extern int grsec_enable_chroot_pivot;
61887+extern int grsec_enable_chroot_chdir;
61888+extern int grsec_enable_chroot_chmod;
61889+extern int grsec_enable_chroot_mknod;
61890+extern int grsec_enable_chroot_fchdir;
61891+extern int grsec_enable_chroot_nice;
61892+extern int grsec_enable_chroot_execlog;
61893+extern int grsec_enable_chroot_caps;
61894+extern int grsec_enable_chroot_sysctl;
61895+extern int grsec_enable_chroot_unix;
61896+extern int grsec_enable_symlinkown;
61897+extern int grsec_symlinkown_gid;
61898+extern int grsec_enable_tpe;
61899+extern int grsec_tpe_gid;
61900+extern int grsec_enable_tpe_all;
61901+extern int grsec_enable_tpe_invert;
61902+extern int grsec_enable_socket_all;
61903+extern int grsec_socket_all_gid;
61904+extern int grsec_enable_socket_client;
61905+extern int grsec_socket_client_gid;
61906+extern int grsec_enable_socket_server;
61907+extern int grsec_socket_server_gid;
61908+extern int grsec_audit_gid;
61909+extern int grsec_enable_group;
61910+extern int grsec_enable_audit_textrel;
61911+extern int grsec_enable_log_rwxmaps;
61912+extern int grsec_enable_mount;
61913+extern int grsec_enable_chdir;
61914+extern int grsec_resource_logging;
61915+extern int grsec_enable_blackhole;
61916+extern int grsec_lastack_retries;
61917+extern int grsec_enable_brute;
61918+extern int grsec_lock;
61919+
61920+extern spinlock_t grsec_alert_lock;
61921+extern unsigned long grsec_alert_wtime;
61922+extern unsigned long grsec_alert_fyet;
61923+
61924+extern spinlock_t grsec_audit_lock;
61925+
61926+extern rwlock_t grsec_exec_file_lock;
61927+
61928+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
61929+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
61930+ (tsk)->exec_file->f_vfsmnt) : "/")
61931+
61932+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
61933+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
61934+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61935+
61936+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
61937+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
61938+ (tsk)->exec_file->f_vfsmnt) : "/")
61939+
61940+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
61941+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
61942+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61943+
61944+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
61945+
61946+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
61947+
61948+#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
61949+ (task)->pid, (cred)->uid, \
61950+ (cred)->euid, (cred)->gid, (cred)->egid, \
61951+ gr_parent_task_fullpath(task), \
61952+ (task)->real_parent->comm, (task)->real_parent->pid, \
61953+ (pcred)->uid, (pcred)->euid, \
61954+ (pcred)->gid, (pcred)->egid
61955+
61956+#define GR_CHROOT_CAPS {{ \
61957+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
61958+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
61959+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
61960+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
61961+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
61962+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
61963+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
61964+
61965+#define security_learn(normal_msg,args...) \
61966+({ \
61967+ read_lock(&grsec_exec_file_lock); \
61968+ gr_add_learn_entry(normal_msg "\n", ## args); \
61969+ read_unlock(&grsec_exec_file_lock); \
61970+})
61971+
61972+enum {
61973+ GR_DO_AUDIT,
61974+ GR_DONT_AUDIT,
61975+ /* used for non-audit messages that we shouldn't kill the task on */
61976+ GR_DONT_AUDIT_GOOD
61977+};
61978+
61979+enum {
61980+ GR_TTYSNIFF,
61981+ GR_RBAC,
61982+ GR_RBAC_STR,
61983+ GR_STR_RBAC,
61984+ GR_RBAC_MODE2,
61985+ GR_RBAC_MODE3,
61986+ GR_FILENAME,
61987+ GR_SYSCTL_HIDDEN,
61988+ GR_NOARGS,
61989+ GR_ONE_INT,
61990+ GR_ONE_INT_TWO_STR,
61991+ GR_ONE_STR,
61992+ GR_STR_INT,
61993+ GR_TWO_STR_INT,
61994+ GR_TWO_INT,
61995+ GR_TWO_U64,
61996+ GR_THREE_INT,
61997+ GR_FIVE_INT_TWO_STR,
61998+ GR_TWO_STR,
61999+ GR_THREE_STR,
62000+ GR_FOUR_STR,
62001+ GR_STR_FILENAME,
62002+ GR_FILENAME_STR,
62003+ GR_FILENAME_TWO_INT,
62004+ GR_FILENAME_TWO_INT_STR,
62005+ GR_TEXTREL,
62006+ GR_PTRACE,
62007+ GR_RESOURCE,
62008+ GR_CAP,
62009+ GR_SIG,
62010+ GR_SIG2,
62011+ GR_CRASH1,
62012+ GR_CRASH2,
62013+ GR_PSACCT,
62014+ GR_RWXMAP
62015+};
62016+
62017+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
62018+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
62019+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
62020+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
62021+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
62022+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
62023+#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)
62024+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
62025+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
62026+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
62027+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
62028+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
62029+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
62030+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
62031+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
62032+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
62033+#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)
62034+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
62035+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
62036+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
62037+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
62038+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
62039+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
62040+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
62041+#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)
62042+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
62043+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
62044+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
62045+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
62046+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
62047+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
62048+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
62049+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
62050+#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)
62051+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
62052+
62053+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
62054+
62055+#endif
62056+
62057+#endif
62058diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
62059new file mode 100644
62060index 0000000..54f4e85
62061--- /dev/null
62062+++ b/include/linux/grmsg.h
62063@@ -0,0 +1,110 @@
62064+#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"
62065+#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"
62066+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
62067+#define GR_STOPMOD_MSG "denied modification of module state by "
62068+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
62069+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
62070+#define GR_IOPERM_MSG "denied use of ioperm() by "
62071+#define GR_IOPL_MSG "denied use of iopl() by "
62072+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
62073+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
62074+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
62075+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
62076+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
62077+#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"
62078+#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"
62079+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
62080+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
62081+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
62082+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
62083+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
62084+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
62085+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
62086+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
62087+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
62088+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
62089+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
62090+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
62091+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
62092+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
62093+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
62094+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
62095+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
62096+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
62097+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
62098+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
62099+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
62100+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
62101+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
62102+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
62103+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
62104+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
62105+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
62106+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
62107+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
62108+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
62109+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
62110+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
62111+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
62112+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
62113+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
62114+#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"
62115+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
62116+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
62117+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
62118+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
62119+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
62120+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
62121+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
62122+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
62123+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
62124+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
62125+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
62126+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
62127+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
62128+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
62129+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
62130+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
62131+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
62132+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
62133+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
62134+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
62135+#define GR_FAILFORK_MSG "failed fork with errno %s by "
62136+#define GR_NICE_CHROOT_MSG "denied priority change by "
62137+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
62138+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
62139+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
62140+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
62141+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
62142+#define GR_TIME_MSG "time set by "
62143+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
62144+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
62145+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
62146+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
62147+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
62148+#define GR_BIND_MSG "denied bind() by "
62149+#define GR_CONNECT_MSG "denied connect() by "
62150+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
62151+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
62152+#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"
62153+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
62154+#define GR_CAP_ACL_MSG "use of %s denied for "
62155+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
62156+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
62157+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
62158+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
62159+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
62160+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
62161+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
62162+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
62163+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
62164+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
62165+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
62166+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
62167+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
62168+#define GR_VM86_MSG "denied use of vm86 by "
62169+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
62170+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
62171+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
62172+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
62173+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
62174diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
62175new file mode 100644
62176index 0000000..38bfb04
62177--- /dev/null
62178+++ b/include/linux/grsecurity.h
62179@@ -0,0 +1,233 @@
62180+#ifndef GR_SECURITY_H
62181+#define GR_SECURITY_H
62182+#include <linux/fs.h>
62183+#include <linux/fs_struct.h>
62184+#include <linux/binfmts.h>
62185+#include <linux/gracl.h>
62186+
62187+/* notify of brain-dead configs */
62188+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62189+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
62190+#endif
62191+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
62192+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
62193+#endif
62194+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
62195+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
62196+#endif
62197+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
62198+#error "CONFIG_PAX enabled, but no PaX options are enabled."
62199+#endif
62200+
62201+#include <linux/compat.h>
62202+
62203+struct user_arg_ptr {
62204+#ifdef CONFIG_COMPAT
62205+ bool is_compat;
62206+#endif
62207+ union {
62208+ const char __user *const __user *native;
62209+#ifdef CONFIG_COMPAT
62210+ compat_uptr_t __user *compat;
62211+#endif
62212+ } ptr;
62213+};
62214+
62215+void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
62216+void gr_handle_brute_check(void);
62217+void gr_handle_kernel_exploit(void);
62218+int gr_process_user_ban(void);
62219+
62220+char gr_roletype_to_char(void);
62221+
62222+int gr_acl_enable_at_secure(void);
62223+
62224+int gr_check_user_change(int real, int effective, int fs);
62225+int gr_check_group_change(int real, int effective, int fs);
62226+
62227+void gr_del_task_from_ip_table(struct task_struct *p);
62228+
62229+int gr_pid_is_chrooted(struct task_struct *p);
62230+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
62231+int gr_handle_chroot_nice(void);
62232+int gr_handle_chroot_sysctl(const int op);
62233+int gr_handle_chroot_setpriority(struct task_struct *p,
62234+ const int niceval);
62235+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
62236+int gr_handle_chroot_chroot(const struct dentry *dentry,
62237+ const struct vfsmount *mnt);
62238+void gr_handle_chroot_chdir(struct path *path);
62239+int gr_handle_chroot_chmod(const struct dentry *dentry,
62240+ const struct vfsmount *mnt, const int mode);
62241+int gr_handle_chroot_mknod(const struct dentry *dentry,
62242+ const struct vfsmount *mnt, const int mode);
62243+int gr_handle_chroot_mount(const struct dentry *dentry,
62244+ const struct vfsmount *mnt,
62245+ const char *dev_name);
62246+int gr_handle_chroot_pivot(void);
62247+int gr_handle_chroot_unix(const pid_t pid);
62248+
62249+int gr_handle_rawio(const struct inode *inode);
62250+
62251+void gr_handle_ioperm(void);
62252+void gr_handle_iopl(void);
62253+
62254+umode_t gr_acl_umask(void);
62255+
62256+int gr_tpe_allow(const struct file *file);
62257+
62258+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
62259+void gr_clear_chroot_entries(struct task_struct *task);
62260+
62261+void gr_log_forkfail(const int retval);
62262+void gr_log_timechange(void);
62263+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
62264+void gr_log_chdir(const struct dentry *dentry,
62265+ const struct vfsmount *mnt);
62266+void gr_log_chroot_exec(const struct dentry *dentry,
62267+ const struct vfsmount *mnt);
62268+void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
62269+void gr_log_remount(const char *devname, const int retval);
62270+void gr_log_unmount(const char *devname, const int retval);
62271+void gr_log_mount(const char *from, const char *to, const int retval);
62272+void gr_log_textrel(struct vm_area_struct *vma);
62273+void gr_log_rwxmmap(struct file *file);
62274+void gr_log_rwxmprotect(struct file *file);
62275+
62276+int gr_handle_follow_link(const struct inode *parent,
62277+ const struct inode *inode,
62278+ const struct dentry *dentry,
62279+ const struct vfsmount *mnt);
62280+int gr_handle_fifo(const struct dentry *dentry,
62281+ const struct vfsmount *mnt,
62282+ const struct dentry *dir, const int flag,
62283+ const int acc_mode);
62284+int gr_handle_hardlink(const struct dentry *dentry,
62285+ const struct vfsmount *mnt,
62286+ struct inode *inode,
62287+ const int mode, const char *to);
62288+
62289+int gr_is_capable(const int cap);
62290+int gr_is_capable_nolog(const int cap);
62291+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
62292+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
62293+
62294+void gr_learn_resource(const struct task_struct *task, const int limit,
62295+ const unsigned long wanted, const int gt);
62296+void gr_copy_label(struct task_struct *tsk);
62297+void gr_handle_crash(struct task_struct *task, const int sig);
62298+int gr_handle_signal(const struct task_struct *p, const int sig);
62299+int gr_check_crash_uid(const uid_t uid);
62300+int gr_check_protected_task(const struct task_struct *task);
62301+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
62302+int gr_acl_handle_mmap(const struct file *file,
62303+ const unsigned long prot);
62304+int gr_acl_handle_mprotect(const struct file *file,
62305+ const unsigned long prot);
62306+int gr_check_hidden_task(const struct task_struct *tsk);
62307+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
62308+ const struct vfsmount *mnt);
62309+__u32 gr_acl_handle_utime(const struct dentry *dentry,
62310+ const struct vfsmount *mnt);
62311+__u32 gr_acl_handle_access(const struct dentry *dentry,
62312+ const struct vfsmount *mnt, const int fmode);
62313+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
62314+ const struct vfsmount *mnt, umode_t *mode);
62315+__u32 gr_acl_handle_chown(const struct dentry *dentry,
62316+ const struct vfsmount *mnt);
62317+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
62318+ const struct vfsmount *mnt);
62319+int gr_handle_ptrace(struct task_struct *task, const long request);
62320+int gr_handle_proc_ptrace(struct task_struct *task);
62321+__u32 gr_acl_handle_execve(const struct dentry *dentry,
62322+ const struct vfsmount *mnt);
62323+int gr_check_crash_exec(const struct file *filp);
62324+int gr_acl_is_enabled(void);
62325+void gr_set_kernel_label(struct task_struct *task);
62326+void gr_set_role_label(struct task_struct *task, const uid_t uid,
62327+ const gid_t gid);
62328+int gr_set_proc_label(const struct dentry *dentry,
62329+ const struct vfsmount *mnt,
62330+ const int unsafe_flags);
62331+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
62332+ const struct vfsmount *mnt);
62333+__u32 gr_acl_handle_open(const struct dentry *dentry,
62334+ const struct vfsmount *mnt, int acc_mode);
62335+__u32 gr_acl_handle_creat(const struct dentry *dentry,
62336+ const struct dentry *p_dentry,
62337+ const struct vfsmount *p_mnt,
62338+ int open_flags, int acc_mode, const int imode);
62339+void gr_handle_create(const struct dentry *dentry,
62340+ const struct vfsmount *mnt);
62341+void gr_handle_proc_create(const struct dentry *dentry,
62342+ const struct inode *inode);
62343+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
62344+ const struct dentry *parent_dentry,
62345+ const struct vfsmount *parent_mnt,
62346+ const int mode);
62347+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
62348+ const struct dentry *parent_dentry,
62349+ const struct vfsmount *parent_mnt);
62350+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
62351+ const struct vfsmount *mnt);
62352+void gr_handle_delete(const ino_t ino, const dev_t dev);
62353+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
62354+ const struct vfsmount *mnt);
62355+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
62356+ const struct dentry *parent_dentry,
62357+ const struct vfsmount *parent_mnt,
62358+ const char *from);
62359+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
62360+ const struct dentry *parent_dentry,
62361+ const struct vfsmount *parent_mnt,
62362+ const struct dentry *old_dentry,
62363+ const struct vfsmount *old_mnt, const char *to);
62364+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
62365+int gr_acl_handle_rename(struct dentry *new_dentry,
62366+ struct dentry *parent_dentry,
62367+ const struct vfsmount *parent_mnt,
62368+ struct dentry *old_dentry,
62369+ struct inode *old_parent_inode,
62370+ struct vfsmount *old_mnt, const char *newname);
62371+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
62372+ struct dentry *old_dentry,
62373+ struct dentry *new_dentry,
62374+ struct vfsmount *mnt, const __u8 replace);
62375+__u32 gr_check_link(const struct dentry *new_dentry,
62376+ const struct dentry *parent_dentry,
62377+ const struct vfsmount *parent_mnt,
62378+ const struct dentry *old_dentry,
62379+ const struct vfsmount *old_mnt);
62380+int gr_acl_handle_filldir(const struct file *file, const char *name,
62381+ const unsigned int namelen, const ino_t ino);
62382+
62383+__u32 gr_acl_handle_unix(const struct dentry *dentry,
62384+ const struct vfsmount *mnt);
62385+void gr_acl_handle_exit(void);
62386+void gr_acl_handle_psacct(struct task_struct *task, const long code);
62387+int gr_acl_handle_procpidmem(const struct task_struct *task);
62388+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
62389+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
62390+void gr_audit_ptrace(struct task_struct *task);
62391+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
62392+
62393+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
62394+
62395+#ifdef CONFIG_GRKERNSEC
62396+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
62397+void gr_handle_vm86(void);
62398+void gr_handle_mem_readwrite(u64 from, u64 to);
62399+
62400+void gr_log_badprocpid(const char *entry);
62401+
62402+extern int grsec_enable_dmesg;
62403+extern int grsec_disable_privio;
62404+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62405+extern int grsec_enable_chroot_findtask;
62406+#endif
62407+#ifdef CONFIG_GRKERNSEC_SETXID
62408+extern int grsec_enable_setxid;
62409+#endif
62410+#endif
62411+
62412+#endif
62413diff --git a/include/linux/grsock.h b/include/linux/grsock.h
62414new file mode 100644
62415index 0000000..e7ffaaf
62416--- /dev/null
62417+++ b/include/linux/grsock.h
62418@@ -0,0 +1,19 @@
62419+#ifndef __GRSOCK_H
62420+#define __GRSOCK_H
62421+
62422+extern void gr_attach_curr_ip(const struct sock *sk);
62423+extern int gr_handle_sock_all(const int family, const int type,
62424+ const int protocol);
62425+extern int gr_handle_sock_server(const struct sockaddr *sck);
62426+extern int gr_handle_sock_server_other(const struct sock *sck);
62427+extern int gr_handle_sock_client(const struct sockaddr *sck);
62428+extern int gr_search_connect(struct socket * sock,
62429+ struct sockaddr_in * addr);
62430+extern int gr_search_bind(struct socket * sock,
62431+ struct sockaddr_in * addr);
62432+extern int gr_search_listen(struct socket * sock);
62433+extern int gr_search_accept(struct socket * sock);
62434+extern int gr_search_socket(const int domain, const int type,
62435+ const int protocol);
62436+
62437+#endif
62438diff --git a/include/linux/hid.h b/include/linux/hid.h
62439index 449fa38..b37c8cc 100644
62440--- a/include/linux/hid.h
62441+++ b/include/linux/hid.h
62442@@ -704,7 +704,7 @@ struct hid_ll_driver {
62443 unsigned int code, int value);
62444
62445 int (*parse)(struct hid_device *hdev);
62446-};
62447+} __no_const;
62448
62449 #define PM_HINT_FULLON 1<<5
62450 #define PM_HINT_NORMAL 1<<1
62451diff --git a/include/linux/highmem.h b/include/linux/highmem.h
62452index d3999b4..1304cb4 100644
62453--- a/include/linux/highmem.h
62454+++ b/include/linux/highmem.h
62455@@ -221,6 +221,18 @@ static inline void clear_highpage(struct page *page)
62456 kunmap_atomic(kaddr);
62457 }
62458
62459+static inline void sanitize_highpage(struct page *page)
62460+{
62461+ void *kaddr;
62462+ unsigned long flags;
62463+
62464+ local_irq_save(flags);
62465+ kaddr = kmap_atomic(page);
62466+ clear_page(kaddr);
62467+ kunmap_atomic(kaddr);
62468+ local_irq_restore(flags);
62469+}
62470+
62471 static inline void zero_user_segments(struct page *page,
62472 unsigned start1, unsigned end1,
62473 unsigned start2, unsigned end2)
62474diff --git a/include/linux/i2c.h b/include/linux/i2c.h
62475index ddfa041..a44cfff 100644
62476--- a/include/linux/i2c.h
62477+++ b/include/linux/i2c.h
62478@@ -366,6 +366,7 @@ struct i2c_algorithm {
62479 /* To determine what the adapter supports */
62480 u32 (*functionality) (struct i2c_adapter *);
62481 };
62482+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
62483
62484 /*
62485 * i2c_adapter is the structure used to identify a physical i2c bus along
62486diff --git a/include/linux/i2o.h b/include/linux/i2o.h
62487index d23c3c2..eb63c81 100644
62488--- a/include/linux/i2o.h
62489+++ b/include/linux/i2o.h
62490@@ -565,7 +565,7 @@ struct i2o_controller {
62491 struct i2o_device *exec; /* Executive */
62492 #if BITS_PER_LONG == 64
62493 spinlock_t context_list_lock; /* lock for context_list */
62494- atomic_t context_list_counter; /* needed for unique contexts */
62495+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
62496 struct list_head context_list; /* list of context id's
62497 and pointers */
62498 #endif
62499diff --git a/include/linux/if_team.h b/include/linux/if_team.h
62500index 8185f57..7b2d222 100644
62501--- a/include/linux/if_team.h
62502+++ b/include/linux/if_team.h
62503@@ -74,6 +74,7 @@ struct team_mode_ops {
62504 void (*port_leave)(struct team *team, struct team_port *port);
62505 void (*port_change_mac)(struct team *team, struct team_port *port);
62506 };
62507+typedef struct team_mode_ops __no_const team_mode_ops_no_const;
62508
62509 enum team_option_type {
62510 TEAM_OPTION_TYPE_U32,
62511@@ -136,7 +137,7 @@ struct team {
62512 struct list_head option_inst_list; /* list of option instances */
62513
62514 const struct team_mode *mode;
62515- struct team_mode_ops ops;
62516+ team_mode_ops_no_const ops;
62517 long mode_priv[TEAM_MODE_PRIV_LONGS];
62518 };
62519
62520diff --git a/include/linux/init.h b/include/linux/init.h
62521index 6b95109..7616d09 100644
62522--- a/include/linux/init.h
62523+++ b/include/linux/init.h
62524@@ -39,9 +39,15 @@
62525 * Also note, that this data cannot be "const".
62526 */
62527
62528+#ifdef MODULE
62529+#define add_latent_entropy
62530+#else
62531+#define add_latent_entropy __latent_entropy
62532+#endif
62533+
62534 /* These are for everybody (although not all archs will actually
62535 discard it in modules) */
62536-#define __init __section(.init.text) __cold notrace
62537+#define __init __section(.init.text) __cold notrace add_latent_entropy
62538 #define __initdata __section(.init.data)
62539 #define __initconst __section(.init.rodata)
62540 #define __exitdata __section(.exit.data)
62541@@ -83,7 +89,7 @@
62542 #define __exit __section(.exit.text) __exitused __cold notrace
62543
62544 /* Used for HOTPLUG */
62545-#define __devinit __section(.devinit.text) __cold notrace
62546+#define __devinit __section(.devinit.text) __cold notrace add_latent_entropy
62547 #define __devinitdata __section(.devinit.data)
62548 #define __devinitconst __section(.devinit.rodata)
62549 #define __devexit __section(.devexit.text) __exitused __cold notrace
62550@@ -91,7 +97,7 @@
62551 #define __devexitconst __section(.devexit.rodata)
62552
62553 /* Used for HOTPLUG_CPU */
62554-#define __cpuinit __section(.cpuinit.text) __cold notrace
62555+#define __cpuinit __section(.cpuinit.text) __cold notrace add_latent_entropy
62556 #define __cpuinitdata __section(.cpuinit.data)
62557 #define __cpuinitconst __section(.cpuinit.rodata)
62558 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
62559@@ -99,7 +105,7 @@
62560 #define __cpuexitconst __section(.cpuexit.rodata)
62561
62562 /* Used for MEMORY_HOTPLUG */
62563-#define __meminit __section(.meminit.text) __cold notrace
62564+#define __meminit __section(.meminit.text) __cold notrace add_latent_entropy
62565 #define __meminitdata __section(.meminit.data)
62566 #define __meminitconst __section(.meminit.rodata)
62567 #define __memexit __section(.memexit.text) __exitused __cold notrace
62568diff --git a/include/linux/init_task.h b/include/linux/init_task.h
62569index 9e65eff..b131e8b 100644
62570--- a/include/linux/init_task.h
62571+++ b/include/linux/init_task.h
62572@@ -134,6 +134,12 @@ extern struct cred init_cred;
62573
62574 #define INIT_TASK_COMM "swapper"
62575
62576+#ifdef CONFIG_X86
62577+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
62578+#else
62579+#define INIT_TASK_THREAD_INFO
62580+#endif
62581+
62582 /*
62583 * INIT_TASK is used to set up the first task table, touch at
62584 * your own risk!. Base=0, limit=0x1fffff (=2MB)
62585@@ -172,6 +178,7 @@ extern struct cred init_cred;
62586 RCU_INIT_POINTER(.cred, &init_cred), \
62587 .comm = INIT_TASK_COMM, \
62588 .thread = INIT_THREAD, \
62589+ INIT_TASK_THREAD_INFO \
62590 .fs = &init_fs, \
62591 .files = &init_files, \
62592 .signal = &init_signals, \
62593diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
62594index e6ca56d..8583707 100644
62595--- a/include/linux/intel-iommu.h
62596+++ b/include/linux/intel-iommu.h
62597@@ -296,7 +296,7 @@ struct iommu_flush {
62598 u8 fm, u64 type);
62599 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
62600 unsigned int size_order, u64 type);
62601-};
62602+} __no_const;
62603
62604 enum {
62605 SR_DMAR_FECTL_REG,
62606diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
62607index e68a8e5..811b9af 100644
62608--- a/include/linux/interrupt.h
62609+++ b/include/linux/interrupt.h
62610@@ -435,7 +435,7 @@ enum
62611 /* map softirq index to softirq name. update 'softirq_to_name' in
62612 * kernel/softirq.c when adding a new softirq.
62613 */
62614-extern char *softirq_to_name[NR_SOFTIRQS];
62615+extern const char * const softirq_to_name[NR_SOFTIRQS];
62616
62617 /* softirq mask and active fields moved to irq_cpustat_t in
62618 * asm/hardirq.h to get better cache usage. KAO
62619@@ -443,12 +443,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
62620
62621 struct softirq_action
62622 {
62623- void (*action)(struct softirq_action *);
62624+ void (*action)(void);
62625 };
62626
62627 asmlinkage void do_softirq(void);
62628 asmlinkage void __do_softirq(void);
62629-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
62630+extern void open_softirq(int nr, void (*action)(void));
62631 extern void softirq_init(void);
62632 extern void __raise_softirq_irqoff(unsigned int nr);
62633
62634diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
62635index 6883e19..06992b1 100644
62636--- a/include/linux/kallsyms.h
62637+++ b/include/linux/kallsyms.h
62638@@ -15,7 +15,8 @@
62639
62640 struct module;
62641
62642-#ifdef CONFIG_KALLSYMS
62643+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
62644+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62645 /* Lookup the address for a symbol. Returns 0 if not found. */
62646 unsigned long kallsyms_lookup_name(const char *name);
62647
62648@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
62649 /* Stupid that this does nothing, but I didn't create this mess. */
62650 #define __print_symbol(fmt, addr)
62651 #endif /*CONFIG_KALLSYMS*/
62652+#else /* when included by kallsyms.c, vsnprintf.c, or
62653+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
62654+extern void __print_symbol(const char *fmt, unsigned long address);
62655+extern int sprint_backtrace(char *buffer, unsigned long address);
62656+extern int sprint_symbol(char *buffer, unsigned long address);
62657+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
62658+const char *kallsyms_lookup(unsigned long addr,
62659+ unsigned long *symbolsize,
62660+ unsigned long *offset,
62661+ char **modname, char *namebuf);
62662+#endif
62663
62664 /* This macro allows us to keep printk typechecking */
62665 static __printf(1, 2)
62666diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
62667index c4d2fc1..5df9c19 100644
62668--- a/include/linux/kgdb.h
62669+++ b/include/linux/kgdb.h
62670@@ -53,7 +53,7 @@ extern int kgdb_connected;
62671 extern int kgdb_io_module_registered;
62672
62673 extern atomic_t kgdb_setting_breakpoint;
62674-extern atomic_t kgdb_cpu_doing_single_step;
62675+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
62676
62677 extern struct task_struct *kgdb_usethread;
62678 extern struct task_struct *kgdb_contthread;
62679@@ -252,7 +252,7 @@ struct kgdb_arch {
62680 void (*disable_hw_break)(struct pt_regs *regs);
62681 void (*remove_all_hw_break)(void);
62682 void (*correct_hw_break)(void);
62683-};
62684+} __do_const;
62685
62686 /**
62687 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
62688@@ -277,7 +277,7 @@ struct kgdb_io {
62689 void (*pre_exception) (void);
62690 void (*post_exception) (void);
62691 int is_console;
62692-};
62693+} __do_const;
62694
62695 extern struct kgdb_arch arch_kgdb_ops;
62696
62697diff --git a/include/linux/kmod.h b/include/linux/kmod.h
62698index 5398d58..5883a34 100644
62699--- a/include/linux/kmod.h
62700+++ b/include/linux/kmod.h
62701@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
62702 * usually useless though. */
62703 extern __printf(2, 3)
62704 int __request_module(bool wait, const char *name, ...);
62705+extern __printf(3, 4)
62706+int ___request_module(bool wait, char *param_name, const char *name, ...);
62707 #define request_module(mod...) __request_module(true, mod)
62708 #define request_module_nowait(mod...) __request_module(false, mod)
62709 #define try_then_request_module(x, mod...) \
62710diff --git a/include/linux/kref.h b/include/linux/kref.h
62711index 9c07dce..a92fa71 100644
62712--- a/include/linux/kref.h
62713+++ b/include/linux/kref.h
62714@@ -63,7 +63,7 @@ static inline void kref_get(struct kref *kref)
62715 static inline int kref_sub(struct kref *kref, unsigned int count,
62716 void (*release)(struct kref *kref))
62717 {
62718- WARN_ON(release == NULL);
62719+ BUG_ON(release == NULL);
62720
62721 if (atomic_sub_and_test((int) count, &kref->refcount)) {
62722 release(kref);
62723diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
62724index 96c158a..1864db5 100644
62725--- a/include/linux/kvm_host.h
62726+++ b/include/linux/kvm_host.h
62727@@ -345,7 +345,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
62728 void vcpu_load(struct kvm_vcpu *vcpu);
62729 void vcpu_put(struct kvm_vcpu *vcpu);
62730
62731-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62732+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62733 struct module *module);
62734 void kvm_exit(void);
62735
62736@@ -511,7 +511,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
62737 struct kvm_guest_debug *dbg);
62738 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
62739
62740-int kvm_arch_init(void *opaque);
62741+int kvm_arch_init(const void *opaque);
62742 void kvm_arch_exit(void);
62743
62744 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
62745diff --git a/include/linux/libata.h b/include/linux/libata.h
62746index 6e887c7..4539601 100644
62747--- a/include/linux/libata.h
62748+++ b/include/linux/libata.h
62749@@ -910,7 +910,7 @@ struct ata_port_operations {
62750 * fields must be pointers.
62751 */
62752 const struct ata_port_operations *inherits;
62753-};
62754+} __do_const;
62755
62756 struct ata_port_info {
62757 unsigned long flags;
62758diff --git a/include/linux/memory.h b/include/linux/memory.h
62759index 1ac7f6e..a5794d0 100644
62760--- a/include/linux/memory.h
62761+++ b/include/linux/memory.h
62762@@ -143,7 +143,7 @@ struct memory_accessor {
62763 size_t count);
62764 ssize_t (*write)(struct memory_accessor *, const char *buf,
62765 off_t offset, size_t count);
62766-};
62767+} __no_const;
62768
62769 /*
62770 * Kernel text modification mutex, used for code patching. Users of this lock
62771diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
62772index 1318ca6..7521340 100644
62773--- a/include/linux/mfd/abx500.h
62774+++ b/include/linux/mfd/abx500.h
62775@@ -452,6 +452,7 @@ struct abx500_ops {
62776 int (*event_registers_startup_state_get) (struct device *, u8 *);
62777 int (*startup_irq_enabled) (struct device *, unsigned int);
62778 };
62779+typedef struct abx500_ops __no_const abx500_ops_no_const;
62780
62781 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
62782 void abx500_remove_ops(struct device *dev);
62783diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
62784index 9b07725..3d55001 100644
62785--- a/include/linux/mfd/abx500/ux500_chargalg.h
62786+++ b/include/linux/mfd/abx500/ux500_chargalg.h
62787@@ -19,7 +19,7 @@ struct ux500_charger_ops {
62788 int (*enable) (struct ux500_charger *, int, int, int);
62789 int (*kick_wd) (struct ux500_charger *);
62790 int (*update_curr) (struct ux500_charger *, int);
62791-};
62792+} __no_const;
62793
62794 /**
62795 * struct ux500_charger - power supply ux500 charger sub class
62796diff --git a/include/linux/mm.h b/include/linux/mm.h
62797index f9f279c..198da78 100644
62798--- a/include/linux/mm.h
62799+++ b/include/linux/mm.h
62800@@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
62801
62802 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
62803 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
62804+
62805+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
62806+#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
62807+#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
62808+#else
62809 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
62810+#endif
62811+
62812 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
62813 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
62814
62815@@ -1009,34 +1016,6 @@ int set_page_dirty(struct page *page);
62816 int set_page_dirty_lock(struct page *page);
62817 int clear_page_dirty_for_io(struct page *page);
62818
62819-/* Is the vma a continuation of the stack vma above it? */
62820-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
62821-{
62822- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
62823-}
62824-
62825-static inline int stack_guard_page_start(struct vm_area_struct *vma,
62826- unsigned long addr)
62827-{
62828- return (vma->vm_flags & VM_GROWSDOWN) &&
62829- (vma->vm_start == addr) &&
62830- !vma_growsdown(vma->vm_prev, addr);
62831-}
62832-
62833-/* Is the vma a continuation of the stack vma below it? */
62834-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
62835-{
62836- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
62837-}
62838-
62839-static inline int stack_guard_page_end(struct vm_area_struct *vma,
62840- unsigned long addr)
62841-{
62842- return (vma->vm_flags & VM_GROWSUP) &&
62843- (vma->vm_end == addr) &&
62844- !vma_growsup(vma->vm_next, addr);
62845-}
62846-
62847 extern pid_t
62848 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
62849
62850@@ -1135,6 +1114,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
62851 }
62852 #endif
62853
62854+#ifdef CONFIG_MMU
62855+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
62856+#else
62857+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
62858+{
62859+ return __pgprot(0);
62860+}
62861+#endif
62862+
62863 int vma_wants_writenotify(struct vm_area_struct *vma);
62864
62865 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
62866@@ -1153,8 +1141,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
62867 {
62868 return 0;
62869 }
62870+
62871+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
62872+ unsigned long address)
62873+{
62874+ return 0;
62875+}
62876 #else
62877 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
62878+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
62879 #endif
62880
62881 #ifdef __PAGETABLE_PMD_FOLDED
62882@@ -1163,8 +1158,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
62883 {
62884 return 0;
62885 }
62886+
62887+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
62888+ unsigned long address)
62889+{
62890+ return 0;
62891+}
62892 #else
62893 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
62894+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
62895 #endif
62896
62897 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
62898@@ -1182,11 +1184,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
62899 NULL: pud_offset(pgd, address);
62900 }
62901
62902+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
62903+{
62904+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
62905+ NULL: pud_offset(pgd, address);
62906+}
62907+
62908 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
62909 {
62910 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
62911 NULL: pmd_offset(pud, address);
62912 }
62913+
62914+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
62915+{
62916+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
62917+ NULL: pmd_offset(pud, address);
62918+}
62919 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
62920
62921 #if USE_SPLIT_PTLOCKS
62922@@ -1396,6 +1410,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
62923 unsigned long, unsigned long,
62924 unsigned long, unsigned long);
62925 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
62926+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
62927
62928 /* These take the mm semaphore themselves */
62929 extern unsigned long vm_brk(unsigned long, unsigned long);
62930@@ -1458,6 +1473,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
62931 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
62932 struct vm_area_struct **pprev);
62933
62934+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
62935+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
62936+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
62937+
62938 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
62939 NULL if none. Assume start_addr < end_addr. */
62940 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
62941@@ -1486,15 +1505,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
62942 return vma;
62943 }
62944
62945-#ifdef CONFIG_MMU
62946-pgprot_t vm_get_page_prot(unsigned long vm_flags);
62947-#else
62948-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
62949-{
62950- return __pgprot(0);
62951-}
62952-#endif
62953-
62954 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
62955 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
62956 unsigned long pfn, unsigned long size, pgprot_t);
62957@@ -1599,7 +1609,7 @@ extern int unpoison_memory(unsigned long pfn);
62958 extern int sysctl_memory_failure_early_kill;
62959 extern int sysctl_memory_failure_recovery;
62960 extern void shake_page(struct page *p, int access);
62961-extern atomic_long_t mce_bad_pages;
62962+extern atomic_long_unchecked_t mce_bad_pages;
62963 extern int soft_offline_page(struct page *page, int flags);
62964
62965 extern void dump_page(struct page *page);
62966@@ -1630,5 +1640,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
62967 static inline bool page_is_guard(struct page *page) { return false; }
62968 #endif /* CONFIG_DEBUG_PAGEALLOC */
62969
62970+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
62971+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
62972+#else
62973+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
62974+#endif
62975+
62976 #endif /* __KERNEL__ */
62977 #endif /* _LINUX_MM_H */
62978diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
62979index 704a626..bb0705a 100644
62980--- a/include/linux/mm_types.h
62981+++ b/include/linux/mm_types.h
62982@@ -263,6 +263,8 @@ struct vm_area_struct {
62983 #ifdef CONFIG_NUMA
62984 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
62985 #endif
62986+
62987+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
62988 };
62989
62990 struct core_thread {
62991@@ -337,7 +339,7 @@ struct mm_struct {
62992 unsigned long def_flags;
62993 unsigned long nr_ptes; /* Page table pages */
62994 unsigned long start_code, end_code, start_data, end_data;
62995- unsigned long start_brk, brk, start_stack;
62996+ unsigned long brk_gap, start_brk, brk, start_stack;
62997 unsigned long arg_start, arg_end, env_start, env_end;
62998
62999 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
63000@@ -389,6 +391,24 @@ struct mm_struct {
63001 struct cpumask cpumask_allocation;
63002 #endif
63003 struct uprobes_state uprobes_state;
63004+
63005+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63006+ unsigned long pax_flags;
63007+#endif
63008+
63009+#ifdef CONFIG_PAX_DLRESOLVE
63010+ unsigned long call_dl_resolve;
63011+#endif
63012+
63013+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
63014+ unsigned long call_syscall;
63015+#endif
63016+
63017+#ifdef CONFIG_PAX_ASLR
63018+ unsigned long delta_mmap; /* randomized offset */
63019+ unsigned long delta_stack; /* randomized offset */
63020+#endif
63021+
63022 };
63023
63024 static inline void mm_init_cpumask(struct mm_struct *mm)
63025diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
63026index 1d1b1e1..2a13c78 100644
63027--- a/include/linux/mmu_notifier.h
63028+++ b/include/linux/mmu_notifier.h
63029@@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
63030 */
63031 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
63032 ({ \
63033- pte_t __pte; \
63034+ pte_t ___pte; \
63035 struct vm_area_struct *___vma = __vma; \
63036 unsigned long ___address = __address; \
63037- __pte = ptep_clear_flush(___vma, ___address, __ptep); \
63038+ ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
63039 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
63040- __pte; \
63041+ ___pte; \
63042 })
63043
63044 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
63045diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
63046index 68c569f..5f43753 100644
63047--- a/include/linux/mmzone.h
63048+++ b/include/linux/mmzone.h
63049@@ -411,7 +411,7 @@ struct zone {
63050 unsigned long flags; /* zone flags, see below */
63051
63052 /* Zone statistics */
63053- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63054+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63055
63056 /*
63057 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
63058diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
63059index 5db9382..50e801d 100644
63060--- a/include/linux/mod_devicetable.h
63061+++ b/include/linux/mod_devicetable.h
63062@@ -12,7 +12,7 @@
63063 typedef unsigned long kernel_ulong_t;
63064 #endif
63065
63066-#define PCI_ANY_ID (~0)
63067+#define PCI_ANY_ID ((__u16)~0)
63068
63069 struct pci_device_id {
63070 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
63071@@ -131,7 +131,7 @@ struct usb_device_id {
63072 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
63073 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
63074
63075-#define HID_ANY_ID (~0)
63076+#define HID_ANY_ID (~0U)
63077 #define HID_BUS_ANY 0xffff
63078 #define HID_GROUP_ANY 0x0000
63079
63080diff --git a/include/linux/module.h b/include/linux/module.h
63081index fbcafe2..e5d9587 100644
63082--- a/include/linux/module.h
63083+++ b/include/linux/module.h
63084@@ -17,6 +17,7 @@
63085 #include <linux/moduleparam.h>
63086 #include <linux/tracepoint.h>
63087 #include <linux/export.h>
63088+#include <linux/fs.h>
63089
63090 #include <linux/percpu.h>
63091 #include <asm/module.h>
63092@@ -273,19 +274,16 @@ struct module
63093 int (*init)(void);
63094
63095 /* If this is non-NULL, vfree after init() returns */
63096- void *module_init;
63097+ void *module_init_rx, *module_init_rw;
63098
63099 /* Here is the actual code + data, vfree'd on unload. */
63100- void *module_core;
63101+ void *module_core_rx, *module_core_rw;
63102
63103 /* Here are the sizes of the init and core sections */
63104- unsigned int init_size, core_size;
63105+ unsigned int init_size_rw, core_size_rw;
63106
63107 /* The size of the executable code in each section. */
63108- unsigned int init_text_size, core_text_size;
63109-
63110- /* Size of RO sections of the module (text+rodata) */
63111- unsigned int init_ro_size, core_ro_size;
63112+ unsigned int init_size_rx, core_size_rx;
63113
63114 /* Arch-specific module values */
63115 struct mod_arch_specific arch;
63116@@ -341,6 +339,10 @@ struct module
63117 #ifdef CONFIG_EVENT_TRACING
63118 struct ftrace_event_call **trace_events;
63119 unsigned int num_trace_events;
63120+ struct file_operations trace_id;
63121+ struct file_operations trace_enable;
63122+ struct file_operations trace_format;
63123+ struct file_operations trace_filter;
63124 #endif
63125 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
63126 unsigned int num_ftrace_callsites;
63127@@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
63128 bool is_module_percpu_address(unsigned long addr);
63129 bool is_module_text_address(unsigned long addr);
63130
63131+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
63132+{
63133+
63134+#ifdef CONFIG_PAX_KERNEXEC
63135+ if (ktla_ktva(addr) >= (unsigned long)start &&
63136+ ktla_ktva(addr) < (unsigned long)start + size)
63137+ return 1;
63138+#endif
63139+
63140+ return ((void *)addr >= start && (void *)addr < start + size);
63141+}
63142+
63143+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
63144+{
63145+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
63146+}
63147+
63148+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
63149+{
63150+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
63151+}
63152+
63153+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
63154+{
63155+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
63156+}
63157+
63158+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
63159+{
63160+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
63161+}
63162+
63163 static inline int within_module_core(unsigned long addr, struct module *mod)
63164 {
63165- return (unsigned long)mod->module_core <= addr &&
63166- addr < (unsigned long)mod->module_core + mod->core_size;
63167+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
63168 }
63169
63170 static inline int within_module_init(unsigned long addr, struct module *mod)
63171 {
63172- return (unsigned long)mod->module_init <= addr &&
63173- addr < (unsigned long)mod->module_init + mod->init_size;
63174+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
63175 }
63176
63177 /* Search for module by name: must hold module_mutex. */
63178diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
63179index b2be02e..72d2f78 100644
63180--- a/include/linux/moduleloader.h
63181+++ b/include/linux/moduleloader.h
63182@@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
63183
63184 /* Allocator used for allocating struct module, core sections and init
63185 sections. Returns NULL on failure. */
63186-void *module_alloc(unsigned long size);
63187+void *module_alloc(unsigned long size) __size_overflow(1);
63188+
63189+#ifdef CONFIG_PAX_KERNEXEC
63190+void *module_alloc_exec(unsigned long size) __size_overflow(1);
63191+#else
63192+#define module_alloc_exec(x) module_alloc(x)
63193+#endif
63194
63195 /* Free memory returned from module_alloc. */
63196 void module_free(struct module *mod, void *module_region);
63197
63198+#ifdef CONFIG_PAX_KERNEXEC
63199+void module_free_exec(struct module *mod, void *module_region);
63200+#else
63201+#define module_free_exec(x, y) module_free((x), (y))
63202+#endif
63203+
63204 /* Apply the given relocation to the (simplified) ELF. Return -error
63205 or 0. */
63206 int apply_relocate(Elf_Shdr *sechdrs,
63207diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
63208index d6a5806..7c13347 100644
63209--- a/include/linux/moduleparam.h
63210+++ b/include/linux/moduleparam.h
63211@@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
63212 * @len is usually just sizeof(string).
63213 */
63214 #define module_param_string(name, string, len, perm) \
63215- static const struct kparam_string __param_string_##name \
63216+ static const struct kparam_string __param_string_##name __used \
63217 = { len, string }; \
63218 __module_param_call(MODULE_PARAM_PREFIX, name, \
63219 &param_ops_string, \
63220@@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
63221 */
63222 #define module_param_array_named(name, array, type, nump, perm) \
63223 param_check_##type(name, &(array)[0]); \
63224- static const struct kparam_array __param_arr_##name \
63225+ static const struct kparam_array __param_arr_##name __used \
63226 = { .max = ARRAY_SIZE(array), .num = nump, \
63227 .ops = &param_ops_##type, \
63228 .elemsize = sizeof(array[0]), .elem = array }; \
63229diff --git a/include/linux/namei.h b/include/linux/namei.h
63230index ffc0213..2c1f2cb 100644
63231--- a/include/linux/namei.h
63232+++ b/include/linux/namei.h
63233@@ -24,7 +24,7 @@ struct nameidata {
63234 unsigned seq;
63235 int last_type;
63236 unsigned depth;
63237- char *saved_names[MAX_NESTED_LINKS + 1];
63238+ const char *saved_names[MAX_NESTED_LINKS + 1];
63239
63240 /* Intent data */
63241 union {
63242@@ -94,12 +94,12 @@ extern int follow_up(struct path *);
63243 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
63244 extern void unlock_rename(struct dentry *, struct dentry *);
63245
63246-static inline void nd_set_link(struct nameidata *nd, char *path)
63247+static inline void nd_set_link(struct nameidata *nd, const char *path)
63248 {
63249 nd->saved_names[nd->depth] = path;
63250 }
63251
63252-static inline char *nd_get_link(struct nameidata *nd)
63253+static inline const char *nd_get_link(const struct nameidata *nd)
63254 {
63255 return nd->saved_names[nd->depth];
63256 }
63257diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
63258index d94cb14..e64c951 100644
63259--- a/include/linux/netdevice.h
63260+++ b/include/linux/netdevice.h
63261@@ -1026,6 +1026,7 @@ struct net_device_ops {
63262 struct net_device *dev,
63263 int idx);
63264 };
63265+typedef struct net_device_ops __no_const net_device_ops_no_const;
63266
63267 /*
63268 * The DEVICE structure.
63269@@ -1087,7 +1088,7 @@ struct net_device {
63270 int iflink;
63271
63272 struct net_device_stats stats;
63273- atomic_long_t rx_dropped; /* dropped packets by core network
63274+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
63275 * Do not use this in drivers.
63276 */
63277
63278diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
63279new file mode 100644
63280index 0000000..33f4af8
63281--- /dev/null
63282+++ b/include/linux/netfilter/xt_gradm.h
63283@@ -0,0 +1,9 @@
63284+#ifndef _LINUX_NETFILTER_XT_GRADM_H
63285+#define _LINUX_NETFILTER_XT_GRADM_H 1
63286+
63287+struct xt_gradm_mtinfo {
63288+ __u16 flags;
63289+ __u16 invflags;
63290+};
63291+
63292+#endif
63293diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
63294index c65a18a..0c05f3a 100644
63295--- a/include/linux/of_pdt.h
63296+++ b/include/linux/of_pdt.h
63297@@ -32,7 +32,7 @@ struct of_pdt_ops {
63298
63299 /* return 0 on success; fill in 'len' with number of bytes in path */
63300 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
63301-};
63302+} __no_const;
63303
63304 extern void *prom_early_alloc(unsigned long size);
63305
63306diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
63307index a4c5624..79d6d88 100644
63308--- a/include/linux/oprofile.h
63309+++ b/include/linux/oprofile.h
63310@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
63311 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
63312 char const * name, ulong * val);
63313
63314-/** Create a file for read-only access to an atomic_t. */
63315+/** Create a file for read-only access to an atomic_unchecked_t. */
63316 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
63317- char const * name, atomic_t * val);
63318+ char const * name, atomic_unchecked_t * val);
63319
63320 /** create a directory */
63321 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
63322diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
63323index 45db49f..386788e 100644
63324--- a/include/linux/perf_event.h
63325+++ b/include/linux/perf_event.h
63326@@ -879,8 +879,8 @@ struct perf_event {
63327
63328 enum perf_event_active_state state;
63329 unsigned int attach_state;
63330- local64_t count;
63331- atomic64_t child_count;
63332+ local64_t count; /* PaX: fix it one day */
63333+ atomic64_unchecked_t child_count;
63334
63335 /*
63336 * These are the total time in nanoseconds that the event
63337@@ -931,8 +931,8 @@ struct perf_event {
63338 * These accumulate total time (in nanoseconds) that children
63339 * events have been enabled and running, respectively.
63340 */
63341- atomic64_t child_total_time_enabled;
63342- atomic64_t child_total_time_running;
63343+ atomic64_unchecked_t child_total_time_enabled;
63344+ atomic64_unchecked_t child_total_time_running;
63345
63346 /*
63347 * Protect attach/detach and child_list:
63348diff --git a/include/linux/personality.h b/include/linux/personality.h
63349index 8fc7dd1a..c19d89e 100644
63350--- a/include/linux/personality.h
63351+++ b/include/linux/personality.h
63352@@ -44,6 +44,7 @@ enum {
63353 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
63354 ADDR_NO_RANDOMIZE | \
63355 ADDR_COMPAT_LAYOUT | \
63356+ ADDR_LIMIT_3GB | \
63357 MMAP_PAGE_ZERO)
63358
63359 /*
63360diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
63361index e1ac1ce..0675fed 100644
63362--- a/include/linux/pipe_fs_i.h
63363+++ b/include/linux/pipe_fs_i.h
63364@@ -45,9 +45,9 @@ struct pipe_buffer {
63365 struct pipe_inode_info {
63366 wait_queue_head_t wait;
63367 unsigned int nrbufs, curbuf, buffers;
63368- unsigned int readers;
63369- unsigned int writers;
63370- unsigned int waiting_writers;
63371+ atomic_t readers;
63372+ atomic_t writers;
63373+ atomic_t waiting_writers;
63374 unsigned int r_counter;
63375 unsigned int w_counter;
63376 struct page *tmp_page;
63377diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
63378index f271860..6b3bec5 100644
63379--- a/include/linux/pm_runtime.h
63380+++ b/include/linux/pm_runtime.h
63381@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
63382
63383 static inline void pm_runtime_mark_last_busy(struct device *dev)
63384 {
63385- ACCESS_ONCE(dev->power.last_busy) = jiffies;
63386+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
63387 }
63388
63389 #else /* !CONFIG_PM_RUNTIME */
63390diff --git a/include/linux/poison.h b/include/linux/poison.h
63391index 2110a81..13a11bb 100644
63392--- a/include/linux/poison.h
63393+++ b/include/linux/poison.h
63394@@ -19,8 +19,8 @@
63395 * under normal circumstances, used to verify that nobody uses
63396 * non-initialized list entries.
63397 */
63398-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
63399-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
63400+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
63401+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
63402
63403 /********** include/linux/timer.h **********/
63404 /*
63405diff --git a/include/linux/preempt.h b/include/linux/preempt.h
63406index 5a710b9..0b0dab9 100644
63407--- a/include/linux/preempt.h
63408+++ b/include/linux/preempt.h
63409@@ -126,7 +126,7 @@ struct preempt_ops {
63410 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
63411 void (*sched_out)(struct preempt_notifier *notifier,
63412 struct task_struct *next);
63413-};
63414+} __no_const;
63415
63416 /**
63417 * preempt_notifier - key for installing preemption notifiers
63418diff --git a/include/linux/printk.h b/include/linux/printk.h
63419index 1bec2f7..b66e833 100644
63420--- a/include/linux/printk.h
63421+++ b/include/linux/printk.h
63422@@ -94,6 +94,8 @@ void early_printk(const char *fmt, ...);
63423 extern int printk_needs_cpu(int cpu);
63424 extern void printk_tick(void);
63425
63426+extern int kptr_restrict;
63427+
63428 #ifdef CONFIG_PRINTK
63429 asmlinkage __printf(5, 0)
63430 int vprintk_emit(int facility, int level,
63431@@ -128,7 +130,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
63432
63433 extern int printk_delay_msec;
63434 extern int dmesg_restrict;
63435-extern int kptr_restrict;
63436
63437 void log_buf_kexec_setup(void);
63438 void __init setup_log_buf(int early);
63439diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
63440index 3fd2e87..d93a721 100644
63441--- a/include/linux/proc_fs.h
63442+++ b/include/linux/proc_fs.h
63443@@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
63444 return proc_create_data(name, mode, parent, proc_fops, NULL);
63445 }
63446
63447+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
63448+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
63449+{
63450+#ifdef CONFIG_GRKERNSEC_PROC_USER
63451+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
63452+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63453+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
63454+#else
63455+ return proc_create_data(name, mode, parent, proc_fops, NULL);
63456+#endif
63457+}
63458+
63459 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
63460 umode_t mode, struct proc_dir_entry *base,
63461 read_proc_t *read_proc, void * data)
63462@@ -258,7 +270,7 @@ union proc_op {
63463 int (*proc_show)(struct seq_file *m,
63464 struct pid_namespace *ns, struct pid *pid,
63465 struct task_struct *task);
63466-};
63467+} __no_const;
63468
63469 struct ctl_table_header;
63470 struct ctl_table;
63471diff --git a/include/linux/random.h b/include/linux/random.h
63472index ac621ce..c1215f3 100644
63473--- a/include/linux/random.h
63474+++ b/include/linux/random.h
63475@@ -53,6 +53,10 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
63476 unsigned int value);
63477 extern void add_interrupt_randomness(int irq, int irq_flags);
63478
63479+#ifdef CONFIG_PAX_LATENT_ENTROPY
63480+extern void transfer_latent_entropy(void);
63481+#endif
63482+
63483 extern void get_random_bytes(void *buf, int nbytes);
63484 extern void get_random_bytes_arch(void *buf, int nbytes);
63485 void generate_random_uuid(unsigned char uuid_out[16]);
63486@@ -69,12 +73,17 @@ void srandom32(u32 seed);
63487
63488 u32 prandom32(struct rnd_state *);
63489
63490+static inline unsigned long pax_get_random_long(void)
63491+{
63492+ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
63493+}
63494+
63495 /*
63496 * Handle minimum values for seeds
63497 */
63498 static inline u32 __seed(u32 x, u32 m)
63499 {
63500- return (x < m) ? x + m : x;
63501+ return (x <= m) ? x + m + 1 : x;
63502 }
63503
63504 /**
63505diff --git a/include/linux/reboot.h b/include/linux/reboot.h
63506index e0879a7..a12f962 100644
63507--- a/include/linux/reboot.h
63508+++ b/include/linux/reboot.h
63509@@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
63510 * Architecture-specific implementations of sys_reboot commands.
63511 */
63512
63513-extern void machine_restart(char *cmd);
63514-extern void machine_halt(void);
63515-extern void machine_power_off(void);
63516+extern void machine_restart(char *cmd) __noreturn;
63517+extern void machine_halt(void) __noreturn;
63518+extern void machine_power_off(void) __noreturn;
63519
63520 extern void machine_shutdown(void);
63521 struct pt_regs;
63522@@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
63523 */
63524
63525 extern void kernel_restart_prepare(char *cmd);
63526-extern void kernel_restart(char *cmd);
63527-extern void kernel_halt(void);
63528-extern void kernel_power_off(void);
63529+extern void kernel_restart(char *cmd) __noreturn;
63530+extern void kernel_halt(void) __noreturn;
63531+extern void kernel_power_off(void) __noreturn;
63532
63533 extern int C_A_D; /* for sysctl */
63534 void ctrl_alt_del(void);
63535@@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
63536 * Emergency restart, callable from an interrupt handler.
63537 */
63538
63539-extern void emergency_restart(void);
63540+extern void emergency_restart(void) __noreturn;
63541 #include <asm/emergency-restart.h>
63542
63543 #endif
63544diff --git a/include/linux/relay.h b/include/linux/relay.h
63545index 91cacc3..b55ff74 100644
63546--- a/include/linux/relay.h
63547+++ b/include/linux/relay.h
63548@@ -160,7 +160,7 @@ struct rchan_callbacks
63549 * The callback should return 0 if successful, negative if not.
63550 */
63551 int (*remove_buf_file)(struct dentry *dentry);
63552-};
63553+} __no_const;
63554
63555 /*
63556 * CONFIG_RELAY kernel API, kernel/relay.c
63557diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
63558index 6fdf027..ff72610 100644
63559--- a/include/linux/rfkill.h
63560+++ b/include/linux/rfkill.h
63561@@ -147,6 +147,7 @@ struct rfkill_ops {
63562 void (*query)(struct rfkill *rfkill, void *data);
63563 int (*set_block)(void *data, bool blocked);
63564 };
63565+typedef struct rfkill_ops __no_const rfkill_ops_no_const;
63566
63567 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
63568 /**
63569diff --git a/include/linux/rio.h b/include/linux/rio.h
63570index a90ebad..fd87b5d 100644
63571--- a/include/linux/rio.h
63572+++ b/include/linux/rio.h
63573@@ -321,7 +321,7 @@ struct rio_ops {
63574 int mbox, void *buffer, size_t len);
63575 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
63576 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
63577-};
63578+} __no_const;
63579
63580 #define RIO_RESOURCE_MEM 0x00000100
63581 #define RIO_RESOURCE_DOORBELL 0x00000200
63582diff --git a/include/linux/rmap.h b/include/linux/rmap.h
63583index 3fce545..b4fed6e 100644
63584--- a/include/linux/rmap.h
63585+++ b/include/linux/rmap.h
63586@@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
63587 void anon_vma_init(void); /* create anon_vma_cachep */
63588 int anon_vma_prepare(struct vm_area_struct *);
63589 void unlink_anon_vmas(struct vm_area_struct *);
63590-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
63591+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
63592 void anon_vma_moveto_tail(struct vm_area_struct *);
63593-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
63594+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
63595
63596 static inline void anon_vma_merge(struct vm_area_struct *vma,
63597 struct vm_area_struct *next)
63598diff --git a/include/linux/sched.h b/include/linux/sched.h
63599index 4a1f493..5812aeb 100644
63600--- a/include/linux/sched.h
63601+++ b/include/linux/sched.h
63602@@ -101,6 +101,7 @@ struct bio_list;
63603 struct fs_struct;
63604 struct perf_event_context;
63605 struct blk_plug;
63606+struct linux_binprm;
63607
63608 /*
63609 * List of flags we want to share for kernel threads,
63610@@ -384,10 +385,13 @@ struct user_namespace;
63611 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
63612
63613 extern int sysctl_max_map_count;
63614+extern unsigned long sysctl_heap_stack_gap;
63615
63616 #include <linux/aio.h>
63617
63618 #ifdef CONFIG_MMU
63619+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
63620+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
63621 extern void arch_pick_mmap_layout(struct mm_struct *mm);
63622 extern unsigned long
63623 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
63624@@ -406,6 +410,11 @@ static inline void arch_pick_mmap_layout(struct mm_struct *mm) {}
63625 extern void set_dumpable(struct mm_struct *mm, int value);
63626 extern int get_dumpable(struct mm_struct *mm);
63627
63628+/* get/set_dumpable() values */
63629+#define SUID_DUMPABLE_DISABLED 0
63630+#define SUID_DUMPABLE_ENABLED 1
63631+#define SUID_DUMPABLE_SAFE 2
63632+
63633 /* mm flags */
63634 /* dumpable bits */
63635 #define MMF_DUMPABLE 0 /* core dump is permitted */
63636@@ -646,6 +655,17 @@ struct signal_struct {
63637 #ifdef CONFIG_TASKSTATS
63638 struct taskstats *stats;
63639 #endif
63640+
63641+#ifdef CONFIG_GRKERNSEC
63642+ u32 curr_ip;
63643+ u32 saved_ip;
63644+ u32 gr_saddr;
63645+ u32 gr_daddr;
63646+ u16 gr_sport;
63647+ u16 gr_dport;
63648+ u8 used_accept:1;
63649+#endif
63650+
63651 #ifdef CONFIG_AUDIT
63652 unsigned audit_tty;
63653 struct tty_audit_buf *tty_audit_buf;
63654@@ -729,6 +749,11 @@ struct user_struct {
63655 struct key *session_keyring; /* UID's default session keyring */
63656 #endif
63657
63658+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
63659+ unsigned int banned;
63660+ unsigned long ban_expires;
63661+#endif
63662+
63663 /* Hash table maintenance information */
63664 struct hlist_node uidhash_node;
63665 kuid_t uid;
63666@@ -1348,8 +1373,8 @@ struct task_struct {
63667 struct list_head thread_group;
63668
63669 struct completion *vfork_done; /* for vfork() */
63670- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
63671- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63672+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
63673+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63674
63675 cputime_t utime, stime, utimescaled, stimescaled;
63676 cputime_t gtime;
63677@@ -1365,11 +1390,6 @@ struct task_struct {
63678 struct task_cputime cputime_expires;
63679 struct list_head cpu_timers[3];
63680
63681-/* process credentials */
63682- const struct cred __rcu *real_cred; /* objective and real subjective task
63683- * credentials (COW) */
63684- const struct cred __rcu *cred; /* effective (overridable) subjective task
63685- * credentials (COW) */
63686 char comm[TASK_COMM_LEN]; /* executable name excluding path
63687 - access with [gs]et_task_comm (which lock
63688 it with task_lock())
63689@@ -1386,8 +1406,16 @@ struct task_struct {
63690 #endif
63691 /* CPU-specific state of this task */
63692 struct thread_struct thread;
63693+/* thread_info moved to task_struct */
63694+#ifdef CONFIG_X86
63695+ struct thread_info tinfo;
63696+#endif
63697 /* filesystem information */
63698 struct fs_struct *fs;
63699+
63700+ const struct cred __rcu *cred; /* effective (overridable) subjective task
63701+ * credentials (COW) */
63702+
63703 /* open file information */
63704 struct files_struct *files;
63705 /* namespaces */
63706@@ -1431,6 +1459,11 @@ struct task_struct {
63707 struct rt_mutex_waiter *pi_blocked_on;
63708 #endif
63709
63710+/* process credentials */
63711+ const struct cred __rcu *real_cred; /* objective and real subjective task
63712+ * credentials (COW) */
63713+ struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63714+
63715 #ifdef CONFIG_DEBUG_MUTEXES
63716 /* mutex deadlock detection */
63717 struct mutex_waiter *blocked_on;
63718@@ -1547,6 +1580,27 @@ struct task_struct {
63719 unsigned long default_timer_slack_ns;
63720
63721 struct list_head *scm_work_list;
63722+
63723+#ifdef CONFIG_GRKERNSEC
63724+ /* grsecurity */
63725+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63726+ u64 exec_id;
63727+#endif
63728+#ifdef CONFIG_GRKERNSEC_SETXID
63729+ const struct cred *delayed_cred;
63730+#endif
63731+ struct dentry *gr_chroot_dentry;
63732+ struct acl_subject_label *acl;
63733+ struct acl_role_label *role;
63734+ struct file *exec_file;
63735+ u16 acl_role_id;
63736+ /* is this the task that authenticated to the special role */
63737+ u8 acl_sp_role;
63738+ u8 is_writable;
63739+ u8 brute;
63740+ u8 gr_is_chrooted;
63741+#endif
63742+
63743 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
63744 /* Index of current stored address in ret_stack */
63745 int curr_ret_stack;
63746@@ -1585,6 +1639,51 @@ struct task_struct {
63747 #endif
63748 };
63749
63750+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
63751+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
63752+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
63753+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
63754+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
63755+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
63756+
63757+#ifdef CONFIG_PAX_SOFTMODE
63758+extern int pax_softmode;
63759+#endif
63760+
63761+extern int pax_check_flags(unsigned long *);
63762+
63763+/* if tsk != current then task_lock must be held on it */
63764+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63765+static inline unsigned long pax_get_flags(struct task_struct *tsk)
63766+{
63767+ if (likely(tsk->mm))
63768+ return tsk->mm->pax_flags;
63769+ else
63770+ return 0UL;
63771+}
63772+
63773+/* if tsk != current then task_lock must be held on it */
63774+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
63775+{
63776+ if (likely(tsk->mm)) {
63777+ tsk->mm->pax_flags = flags;
63778+ return 0;
63779+ }
63780+ return -EINVAL;
63781+}
63782+#endif
63783+
63784+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
63785+extern void pax_set_initial_flags(struct linux_binprm *bprm);
63786+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
63787+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
63788+#endif
63789+
63790+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
63791+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
63792+extern void pax_report_refcount_overflow(struct pt_regs *regs);
63793+extern void check_object_size(const void *ptr, unsigned long n, bool to);
63794+
63795 /* Future-safe accessor for struct task_struct's cpus_allowed. */
63796 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
63797
63798@@ -2112,7 +2211,9 @@ void yield(void);
63799 extern struct exec_domain default_exec_domain;
63800
63801 union thread_union {
63802+#ifndef CONFIG_X86
63803 struct thread_info thread_info;
63804+#endif
63805 unsigned long stack[THREAD_SIZE/sizeof(long)];
63806 };
63807
63808@@ -2145,6 +2246,7 @@ extern struct pid_namespace init_pid_ns;
63809 */
63810
63811 extern struct task_struct *find_task_by_vpid(pid_t nr);
63812+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
63813 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
63814 struct pid_namespace *ns);
63815
63816@@ -2301,7 +2403,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
63817 extern void exit_itimers(struct signal_struct *);
63818 extern void flush_itimer_signals(void);
63819
63820-extern void do_group_exit(int);
63821+extern __noreturn void do_group_exit(int);
63822
63823 extern void daemonize(const char *, ...);
63824 extern int allow_signal(int);
63825@@ -2502,9 +2604,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
63826
63827 #endif
63828
63829-static inline int object_is_on_stack(void *obj)
63830+static inline int object_starts_on_stack(void *obj)
63831 {
63832- void *stack = task_stack_page(current);
63833+ const void *stack = task_stack_page(current);
63834
63835 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
63836 }
63837diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
63838index 899fbb4..1cb4138 100644
63839--- a/include/linux/screen_info.h
63840+++ b/include/linux/screen_info.h
63841@@ -43,7 +43,8 @@ struct screen_info {
63842 __u16 pages; /* 0x32 */
63843 __u16 vesa_attributes; /* 0x34 */
63844 __u32 capabilities; /* 0x36 */
63845- __u8 _reserved[6]; /* 0x3a */
63846+ __u16 vesapm_size; /* 0x3a */
63847+ __u8 _reserved[4]; /* 0x3c */
63848 } __attribute__((packed));
63849
63850 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
63851diff --git a/include/linux/security.h b/include/linux/security.h
63852index 3dea6a9..81fd81f 100644
63853--- a/include/linux/security.h
63854+++ b/include/linux/security.h
63855@@ -26,6 +26,7 @@
63856 #include <linux/capability.h>
63857 #include <linux/slab.h>
63858 #include <linux/err.h>
63859+#include <linux/grsecurity.h>
63860
63861 struct linux_binprm;
63862 struct cred;
63863diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
63864index fc61854..d7c490b 100644
63865--- a/include/linux/seq_file.h
63866+++ b/include/linux/seq_file.h
63867@@ -25,6 +25,9 @@ struct seq_file {
63868 struct mutex lock;
63869 const struct seq_operations *op;
63870 int poll_event;
63871+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63872+ u64 exec_id;
63873+#endif
63874 void *private;
63875 };
63876
63877@@ -34,6 +37,7 @@ struct seq_operations {
63878 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
63879 int (*show) (struct seq_file *m, void *v);
63880 };
63881+typedef struct seq_operations __no_const seq_operations_no_const;
63882
63883 #define SEQ_SKIP 1
63884
63885diff --git a/include/linux/shm.h b/include/linux/shm.h
63886index 92808b8..c28cac4 100644
63887--- a/include/linux/shm.h
63888+++ b/include/linux/shm.h
63889@@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
63890
63891 /* The task created the shm object. NULL if the task is dead. */
63892 struct task_struct *shm_creator;
63893+#ifdef CONFIG_GRKERNSEC
63894+ time_t shm_createtime;
63895+ pid_t shm_lapid;
63896+#endif
63897 };
63898
63899 /* shm_mode upper byte flags */
63900diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
63901index 642cb73..7ff7f9f 100644
63902--- a/include/linux/skbuff.h
63903+++ b/include/linux/skbuff.h
63904@@ -680,7 +680,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
63905 */
63906 static inline int skb_queue_empty(const struct sk_buff_head *list)
63907 {
63908- return list->next == (struct sk_buff *)list;
63909+ return list->next == (const struct sk_buff *)list;
63910 }
63911
63912 /**
63913@@ -693,7 +693,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
63914 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63915 const struct sk_buff *skb)
63916 {
63917- return skb->next == (struct sk_buff *)list;
63918+ return skb->next == (const struct sk_buff *)list;
63919 }
63920
63921 /**
63922@@ -706,7 +706,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63923 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
63924 const struct sk_buff *skb)
63925 {
63926- return skb->prev == (struct sk_buff *)list;
63927+ return skb->prev == (const struct sk_buff *)list;
63928 }
63929
63930 /**
63931@@ -1605,7 +1605,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
63932 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
63933 */
63934 #ifndef NET_SKB_PAD
63935-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
63936+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
63937 #endif
63938
63939 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
63940diff --git a/include/linux/slab.h b/include/linux/slab.h
63941index 67d5d94..bbd740b 100644
63942--- a/include/linux/slab.h
63943+++ b/include/linux/slab.h
63944@@ -11,12 +11,20 @@
63945
63946 #include <linux/gfp.h>
63947 #include <linux/types.h>
63948+#include <linux/err.h>
63949
63950 /*
63951 * Flags to pass to kmem_cache_create().
63952 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
63953 */
63954 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
63955+
63956+#ifdef CONFIG_PAX_USERCOPY_SLABS
63957+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
63958+#else
63959+#define SLAB_USERCOPY 0x00000000UL
63960+#endif
63961+
63962 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
63963 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
63964 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
63965@@ -87,10 +95,13 @@
63966 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
63967 * Both make kfree a no-op.
63968 */
63969-#define ZERO_SIZE_PTR ((void *)16)
63970+#define ZERO_SIZE_PTR \
63971+({ \
63972+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
63973+ (void *)(-MAX_ERRNO-1L); \
63974+})
63975
63976-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
63977- (unsigned long)ZERO_SIZE_PTR)
63978+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
63979
63980 /*
63981 * struct kmem_cache related prototypes
63982@@ -161,6 +172,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
63983 void kfree(const void *);
63984 void kzfree(const void *);
63985 size_t ksize(const void *);
63986+const char *check_heap_object(const void *ptr, unsigned long n, bool to);
63987+bool is_usercopy_object(const void *ptr);
63988
63989 /*
63990 * Allocator specific definitions. These are mainly used to establish optimized
63991@@ -298,7 +311,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
63992 */
63993 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63994 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63995-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63996+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
63997 #define kmalloc_track_caller(size, flags) \
63998 __kmalloc_track_caller(size, flags, _RET_IP_)
63999 #else
64000@@ -317,7 +330,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64001 */
64002 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64003 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64004-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
64005+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
64006 #define kmalloc_node_track_caller(size, flags, node) \
64007 __kmalloc_node_track_caller(size, flags, node, \
64008 _RET_IP_)
64009diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
64010index fbd1117..0a3d314 100644
64011--- a/include/linux/slab_def.h
64012+++ b/include/linux/slab_def.h
64013@@ -66,10 +66,10 @@ struct kmem_cache {
64014 unsigned long node_allocs;
64015 unsigned long node_frees;
64016 unsigned long node_overflow;
64017- atomic_t allochit;
64018- atomic_t allocmiss;
64019- atomic_t freehit;
64020- atomic_t freemiss;
64021+ atomic_unchecked_t allochit;
64022+ atomic_unchecked_t allocmiss;
64023+ atomic_unchecked_t freehit;
64024+ atomic_unchecked_t freemiss;
64025
64026 /*
64027 * If debugging is enabled, then the allocator can add additional
64028@@ -103,11 +103,16 @@ struct cache_sizes {
64029 #ifdef CONFIG_ZONE_DMA
64030 struct kmem_cache *cs_dmacachep;
64031 #endif
64032+
64033+#ifdef CONFIG_PAX_USERCOPY_SLABS
64034+ struct kmem_cache *cs_usercopycachep;
64035+#endif
64036+
64037 };
64038 extern struct cache_sizes malloc_sizes[];
64039
64040 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64041-void *__kmalloc(size_t size, gfp_t flags);
64042+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
64043
64044 #ifdef CONFIG_TRACING
64045 extern void *kmem_cache_alloc_trace(size_t size,
64046@@ -150,6 +155,13 @@ found:
64047 cachep = malloc_sizes[i].cs_dmacachep;
64048 else
64049 #endif
64050+
64051+#ifdef CONFIG_PAX_USERCOPY_SLABS
64052+ if (flags & GFP_USERCOPY)
64053+ cachep = malloc_sizes[i].cs_usercopycachep;
64054+ else
64055+#endif
64056+
64057 cachep = malloc_sizes[i].cs_cachep;
64058
64059 ret = kmem_cache_alloc_trace(size, cachep, flags);
64060@@ -160,7 +172,7 @@ found:
64061 }
64062
64063 #ifdef CONFIG_NUMA
64064-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
64065+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64066 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64067
64068 #ifdef CONFIG_TRACING
64069@@ -203,6 +215,13 @@ found:
64070 cachep = malloc_sizes[i].cs_dmacachep;
64071 else
64072 #endif
64073+
64074+#ifdef CONFIG_PAX_USERCOPY_SLABS
64075+ if (flags & GFP_USERCOPY)
64076+ cachep = malloc_sizes[i].cs_usercopycachep;
64077+ else
64078+#endif
64079+
64080 cachep = malloc_sizes[i].cs_cachep;
64081
64082 return kmem_cache_alloc_node_trace(size, cachep, flags, node);
64083diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
64084index 0ec00b3..22b4715 100644
64085--- a/include/linux/slob_def.h
64086+++ b/include/linux/slob_def.h
64087@@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
64088 return kmem_cache_alloc_node(cachep, flags, -1);
64089 }
64090
64091-void *__kmalloc_node(size_t size, gfp_t flags, int node);
64092+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64093
64094 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
64095 {
64096@@ -29,7 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64097 return __kmalloc_node(size, flags, -1);
64098 }
64099
64100-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
64101+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
64102 {
64103 return kmalloc(size, flags);
64104 }
64105diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
64106index c2f8c8b..d992a41 100644
64107--- a/include/linux/slub_def.h
64108+++ b/include/linux/slub_def.h
64109@@ -92,7 +92,7 @@ struct kmem_cache {
64110 struct kmem_cache_order_objects max;
64111 struct kmem_cache_order_objects min;
64112 gfp_t allocflags; /* gfp flags to use on each alloc */
64113- int refcount; /* Refcount for slab cache destroy */
64114+ atomic_t refcount; /* Refcount for slab cache destroy */
64115 void (*ctor)(void *);
64116 int inuse; /* Offset to metadata */
64117 int align; /* Alignment */
64118@@ -153,7 +153,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
64119 * Sorry that the following has to be that ugly but some versions of GCC
64120 * have trouble with constant propagation and loops.
64121 */
64122-static __always_inline int kmalloc_index(size_t size)
64123+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
64124 {
64125 if (!size)
64126 return 0;
64127@@ -218,7 +218,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
64128 }
64129
64130 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64131-void *__kmalloc(size_t size, gfp_t flags);
64132+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
64133
64134 static __always_inline void *
64135 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
64136@@ -259,7 +259,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
64137 }
64138 #endif
64139
64140-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
64141+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
64142 {
64143 unsigned int order = get_order(size);
64144 return kmalloc_order_trace(size, flags, order);
64145@@ -284,7 +284,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64146 }
64147
64148 #ifdef CONFIG_NUMA
64149-void *__kmalloc_node(size_t size, gfp_t flags, int node);
64150+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64151 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64152
64153 #ifdef CONFIG_TRACING
64154diff --git a/include/linux/sonet.h b/include/linux/sonet.h
64155index de8832d..0147b46 100644
64156--- a/include/linux/sonet.h
64157+++ b/include/linux/sonet.h
64158@@ -61,7 +61,7 @@ struct sonet_stats {
64159 #include <linux/atomic.h>
64160
64161 struct k_sonet_stats {
64162-#define __HANDLE_ITEM(i) atomic_t i
64163+#define __HANDLE_ITEM(i) atomic_unchecked_t i
64164 __SONET_ITEMS
64165 #undef __HANDLE_ITEM
64166 };
64167diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
64168index 523547e..2cb7140 100644
64169--- a/include/linux/sunrpc/clnt.h
64170+++ b/include/linux/sunrpc/clnt.h
64171@@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
64172 {
64173 switch (sap->sa_family) {
64174 case AF_INET:
64175- return ntohs(((struct sockaddr_in *)sap)->sin_port);
64176+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
64177 case AF_INET6:
64178- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
64179+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
64180 }
64181 return 0;
64182 }
64183@@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
64184 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
64185 const struct sockaddr *src)
64186 {
64187- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
64188+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
64189 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
64190
64191 dsin->sin_family = ssin->sin_family;
64192@@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
64193 if (sa->sa_family != AF_INET6)
64194 return 0;
64195
64196- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
64197+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
64198 }
64199
64200 #endif /* __KERNEL__ */
64201diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
64202index dc0c3cc..8503fb6 100644
64203--- a/include/linux/sunrpc/sched.h
64204+++ b/include/linux/sunrpc/sched.h
64205@@ -106,6 +106,7 @@ struct rpc_call_ops {
64206 void (*rpc_count_stats)(struct rpc_task *, void *);
64207 void (*rpc_release)(void *);
64208 };
64209+typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
64210
64211 struct rpc_task_setup {
64212 struct rpc_task *task;
64213diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
64214index 0b8e3e6..33e0a01 100644
64215--- a/include/linux/sunrpc/svc_rdma.h
64216+++ b/include/linux/sunrpc/svc_rdma.h
64217@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
64218 extern unsigned int svcrdma_max_requests;
64219 extern unsigned int svcrdma_max_req_size;
64220
64221-extern atomic_t rdma_stat_recv;
64222-extern atomic_t rdma_stat_read;
64223-extern atomic_t rdma_stat_write;
64224-extern atomic_t rdma_stat_sq_starve;
64225-extern atomic_t rdma_stat_rq_starve;
64226-extern atomic_t rdma_stat_rq_poll;
64227-extern atomic_t rdma_stat_rq_prod;
64228-extern atomic_t rdma_stat_sq_poll;
64229-extern atomic_t rdma_stat_sq_prod;
64230+extern atomic_unchecked_t rdma_stat_recv;
64231+extern atomic_unchecked_t rdma_stat_read;
64232+extern atomic_unchecked_t rdma_stat_write;
64233+extern atomic_unchecked_t rdma_stat_sq_starve;
64234+extern atomic_unchecked_t rdma_stat_rq_starve;
64235+extern atomic_unchecked_t rdma_stat_rq_poll;
64236+extern atomic_unchecked_t rdma_stat_rq_prod;
64237+extern atomic_unchecked_t rdma_stat_sq_poll;
64238+extern atomic_unchecked_t rdma_stat_sq_prod;
64239
64240 #define RPCRDMA_VERSION 1
64241
64242diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
64243index c34b4c8..a65b67d 100644
64244--- a/include/linux/sysctl.h
64245+++ b/include/linux/sysctl.h
64246@@ -155,7 +155,11 @@ enum
64247 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
64248 };
64249
64250-
64251+#ifdef CONFIG_PAX_SOFTMODE
64252+enum {
64253+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
64254+};
64255+#endif
64256
64257 /* CTL_VM names: */
64258 enum
64259@@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
64260
64261 extern int proc_dostring(struct ctl_table *, int,
64262 void __user *, size_t *, loff_t *);
64263+extern int proc_dostring_modpriv(struct ctl_table *, int,
64264+ void __user *, size_t *, loff_t *);
64265 extern int proc_dointvec(struct ctl_table *, int,
64266 void __user *, size_t *, loff_t *);
64267 extern int proc_dointvec_minmax(struct ctl_table *, int,
64268diff --git a/include/linux/tty.h b/include/linux/tty.h
64269index 9f47ab5..73da944 100644
64270--- a/include/linux/tty.h
64271+++ b/include/linux/tty.h
64272@@ -225,7 +225,7 @@ struct tty_port {
64273 const struct tty_port_operations *ops; /* Port operations */
64274 spinlock_t lock; /* Lock protecting tty field */
64275 int blocked_open; /* Waiting to open */
64276- int count; /* Usage count */
64277+ atomic_t count; /* Usage count */
64278 wait_queue_head_t open_wait; /* Open waiters */
64279 wait_queue_head_t close_wait; /* Close waiters */
64280 wait_queue_head_t delta_msr_wait; /* Modem status change */
64281@@ -525,7 +525,7 @@ extern int tty_port_open(struct tty_port *port,
64282 struct tty_struct *tty, struct file *filp);
64283 static inline int tty_port_users(struct tty_port *port)
64284 {
64285- return port->count + port->blocked_open;
64286+ return atomic_read(&port->count) + port->blocked_open;
64287 }
64288
64289 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
64290diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
64291index fb79dd8d..07d4773 100644
64292--- a/include/linux/tty_ldisc.h
64293+++ b/include/linux/tty_ldisc.h
64294@@ -149,7 +149,7 @@ struct tty_ldisc_ops {
64295
64296 struct module *owner;
64297
64298- int refcount;
64299+ atomic_t refcount;
64300 };
64301
64302 struct tty_ldisc {
64303diff --git a/include/linux/types.h b/include/linux/types.h
64304index 9c1bd53..c2370f6 100644
64305--- a/include/linux/types.h
64306+++ b/include/linux/types.h
64307@@ -220,10 +220,26 @@ typedef struct {
64308 int counter;
64309 } atomic_t;
64310
64311+#ifdef CONFIG_PAX_REFCOUNT
64312+typedef struct {
64313+ int counter;
64314+} atomic_unchecked_t;
64315+#else
64316+typedef atomic_t atomic_unchecked_t;
64317+#endif
64318+
64319 #ifdef CONFIG_64BIT
64320 typedef struct {
64321 long counter;
64322 } atomic64_t;
64323+
64324+#ifdef CONFIG_PAX_REFCOUNT
64325+typedef struct {
64326+ long counter;
64327+} atomic64_unchecked_t;
64328+#else
64329+typedef atomic64_t atomic64_unchecked_t;
64330+#endif
64331 #endif
64332
64333 struct list_head {
64334diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
64335index 5ca0951..ab496a5 100644
64336--- a/include/linux/uaccess.h
64337+++ b/include/linux/uaccess.h
64338@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
64339 long ret; \
64340 mm_segment_t old_fs = get_fs(); \
64341 \
64342- set_fs(KERNEL_DS); \
64343 pagefault_disable(); \
64344- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
64345- pagefault_enable(); \
64346+ set_fs(KERNEL_DS); \
64347+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
64348 set_fs(old_fs); \
64349+ pagefault_enable(); \
64350 ret; \
64351 })
64352
64353diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
64354index 99c1b4d..bb94261 100644
64355--- a/include/linux/unaligned/access_ok.h
64356+++ b/include/linux/unaligned/access_ok.h
64357@@ -6,32 +6,32 @@
64358
64359 static inline u16 get_unaligned_le16(const void *p)
64360 {
64361- return le16_to_cpup((__le16 *)p);
64362+ return le16_to_cpup((const __le16 *)p);
64363 }
64364
64365 static inline u32 get_unaligned_le32(const void *p)
64366 {
64367- return le32_to_cpup((__le32 *)p);
64368+ return le32_to_cpup((const __le32 *)p);
64369 }
64370
64371 static inline u64 get_unaligned_le64(const void *p)
64372 {
64373- return le64_to_cpup((__le64 *)p);
64374+ return le64_to_cpup((const __le64 *)p);
64375 }
64376
64377 static inline u16 get_unaligned_be16(const void *p)
64378 {
64379- return be16_to_cpup((__be16 *)p);
64380+ return be16_to_cpup((const __be16 *)p);
64381 }
64382
64383 static inline u32 get_unaligned_be32(const void *p)
64384 {
64385- return be32_to_cpup((__be32 *)p);
64386+ return be32_to_cpup((const __be32 *)p);
64387 }
64388
64389 static inline u64 get_unaligned_be64(const void *p)
64390 {
64391- return be64_to_cpup((__be64 *)p);
64392+ return be64_to_cpup((const __be64 *)p);
64393 }
64394
64395 static inline void put_unaligned_le16(u16 val, void *p)
64396diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
64397index 547e59c..db6ad19 100644
64398--- a/include/linux/usb/renesas_usbhs.h
64399+++ b/include/linux/usb/renesas_usbhs.h
64400@@ -39,7 +39,7 @@ enum {
64401 */
64402 struct renesas_usbhs_driver_callback {
64403 int (*notify_hotplug)(struct platform_device *pdev);
64404-};
64405+} __no_const;
64406
64407 /*
64408 * callback functions for platform
64409@@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
64410 * VBUS control is needed for Host
64411 */
64412 int (*set_vbus)(struct platform_device *pdev, int enable);
64413-};
64414+} __no_const;
64415
64416 /*
64417 * parameters for renesas usbhs
64418diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
64419index 6f8fbcf..8259001 100644
64420--- a/include/linux/vermagic.h
64421+++ b/include/linux/vermagic.h
64422@@ -25,9 +25,35 @@
64423 #define MODULE_ARCH_VERMAGIC ""
64424 #endif
64425
64426+#ifdef CONFIG_PAX_REFCOUNT
64427+#define MODULE_PAX_REFCOUNT "REFCOUNT "
64428+#else
64429+#define MODULE_PAX_REFCOUNT ""
64430+#endif
64431+
64432+#ifdef CONSTIFY_PLUGIN
64433+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
64434+#else
64435+#define MODULE_CONSTIFY_PLUGIN ""
64436+#endif
64437+
64438+#ifdef STACKLEAK_PLUGIN
64439+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
64440+#else
64441+#define MODULE_STACKLEAK_PLUGIN ""
64442+#endif
64443+
64444+#ifdef CONFIG_GRKERNSEC
64445+#define MODULE_GRSEC "GRSEC "
64446+#else
64447+#define MODULE_GRSEC ""
64448+#endif
64449+
64450 #define VERMAGIC_STRING \
64451 UTS_RELEASE " " \
64452 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
64453 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
64454- MODULE_ARCH_VERMAGIC
64455+ MODULE_ARCH_VERMAGIC \
64456+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
64457+ MODULE_GRSEC
64458
64459diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
64460index dcdfc2b..ec79ab5 100644
64461--- a/include/linux/vmalloc.h
64462+++ b/include/linux/vmalloc.h
64463@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
64464 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
64465 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
64466 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
64467+
64468+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
64469+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
64470+#endif
64471+
64472 /* bits [20..32] reserved for arch specific ioremap internals */
64473
64474 /*
64475@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
64476 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
64477 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
64478 unsigned long start, unsigned long end, gfp_t gfp_mask,
64479- pgprot_t prot, int node, void *caller);
64480+ pgprot_t prot, int node, void *caller) __size_overflow(1);
64481 extern void vfree(const void *addr);
64482
64483 extern void *vmap(struct page **pages, unsigned int count,
64484@@ -123,8 +128,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
64485 extern void free_vm_area(struct vm_struct *area);
64486
64487 /* for /dev/kmem */
64488-extern long vread(char *buf, char *addr, unsigned long count);
64489-extern long vwrite(char *buf, char *addr, unsigned long count);
64490+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
64491+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
64492
64493 /*
64494 * Internals. Dont't use..
64495diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
64496index 65efb92..137adbb 100644
64497--- a/include/linux/vmstat.h
64498+++ b/include/linux/vmstat.h
64499@@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
64500 /*
64501 * Zone based page accounting with per cpu differentials.
64502 */
64503-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64504+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64505
64506 static inline void zone_page_state_add(long x, struct zone *zone,
64507 enum zone_stat_item item)
64508 {
64509- atomic_long_add(x, &zone->vm_stat[item]);
64510- atomic_long_add(x, &vm_stat[item]);
64511+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
64512+ atomic_long_add_unchecked(x, &vm_stat[item]);
64513 }
64514
64515 static inline unsigned long global_page_state(enum zone_stat_item item)
64516 {
64517- long x = atomic_long_read(&vm_stat[item]);
64518+ long x = atomic_long_read_unchecked(&vm_stat[item]);
64519 #ifdef CONFIG_SMP
64520 if (x < 0)
64521 x = 0;
64522@@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
64523 static inline unsigned long zone_page_state(struct zone *zone,
64524 enum zone_stat_item item)
64525 {
64526- long x = atomic_long_read(&zone->vm_stat[item]);
64527+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64528 #ifdef CONFIG_SMP
64529 if (x < 0)
64530 x = 0;
64531@@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
64532 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
64533 enum zone_stat_item item)
64534 {
64535- long x = atomic_long_read(&zone->vm_stat[item]);
64536+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64537
64538 #ifdef CONFIG_SMP
64539 int cpu;
64540@@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
64541
64542 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
64543 {
64544- atomic_long_inc(&zone->vm_stat[item]);
64545- atomic_long_inc(&vm_stat[item]);
64546+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
64547+ atomic_long_inc_unchecked(&vm_stat[item]);
64548 }
64549
64550 static inline void __inc_zone_page_state(struct page *page,
64551@@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
64552
64553 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
64554 {
64555- atomic_long_dec(&zone->vm_stat[item]);
64556- atomic_long_dec(&vm_stat[item]);
64557+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
64558+ atomic_long_dec_unchecked(&vm_stat[item]);
64559 }
64560
64561 static inline void __dec_zone_page_state(struct page *page,
64562diff --git a/include/linux/xattr.h b/include/linux/xattr.h
64563index e5d1220..ef6e406 100644
64564--- a/include/linux/xattr.h
64565+++ b/include/linux/xattr.h
64566@@ -57,6 +57,11 @@
64567 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
64568 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
64569
64570+/* User namespace */
64571+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
64572+#define XATTR_PAX_FLAGS_SUFFIX "flags"
64573+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
64574+
64575 #ifdef __KERNEL__
64576
64577 #include <linux/types.h>
64578diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
64579index 944ecdf..a3994fc 100644
64580--- a/include/media/saa7146_vv.h
64581+++ b/include/media/saa7146_vv.h
64582@@ -161,8 +161,8 @@ struct saa7146_ext_vv
64583 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
64584
64585 /* the extension can override this */
64586- struct v4l2_ioctl_ops vid_ops;
64587- struct v4l2_ioctl_ops vbi_ops;
64588+ v4l2_ioctl_ops_no_const vid_ops;
64589+ v4l2_ioctl_ops_no_const vbi_ops;
64590 /* pointer to the saa7146 core ops */
64591 const struct v4l2_ioctl_ops *core_ops;
64592
64593diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
64594index a056e6e..31023a5 100644
64595--- a/include/media/v4l2-dev.h
64596+++ b/include/media/v4l2-dev.h
64597@@ -73,7 +73,8 @@ struct v4l2_file_operations {
64598 int (*mmap) (struct file *, struct vm_area_struct *);
64599 int (*open) (struct file *);
64600 int (*release) (struct file *);
64601-};
64602+} __do_const;
64603+typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
64604
64605 /*
64606 * Newer version of video_device, handled by videodev2.c
64607diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
64608index d8b76f7..7d5aa18 100644
64609--- a/include/media/v4l2-ioctl.h
64610+++ b/include/media/v4l2-ioctl.h
64611@@ -287,7 +287,7 @@ struct v4l2_ioctl_ops {
64612 long (*vidioc_default) (struct file *file, void *fh,
64613 bool valid_prio, int cmd, void *arg);
64614 };
64615-
64616+typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
64617
64618 /* v4l debugging and diagnostics */
64619
64620diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
64621index 439dadc..1c67e3f 100644
64622--- a/include/net/caif/caif_hsi.h
64623+++ b/include/net/caif/caif_hsi.h
64624@@ -98,7 +98,7 @@ struct cfhsi_drv {
64625 void (*rx_done_cb) (struct cfhsi_drv *drv);
64626 void (*wake_up_cb) (struct cfhsi_drv *drv);
64627 void (*wake_down_cb) (struct cfhsi_drv *drv);
64628-};
64629+} __no_const;
64630
64631 /* Structure implemented by HSI device. */
64632 struct cfhsi_dev {
64633diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
64634index 9e5425b..8136ffc 100644
64635--- a/include/net/caif/cfctrl.h
64636+++ b/include/net/caif/cfctrl.h
64637@@ -52,7 +52,7 @@ struct cfctrl_rsp {
64638 void (*radioset_rsp)(void);
64639 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
64640 struct cflayer *client_layer);
64641-};
64642+} __no_const;
64643
64644 /* Link Setup Parameters for CAIF-Links. */
64645 struct cfctrl_link_param {
64646@@ -101,8 +101,8 @@ struct cfctrl_request_info {
64647 struct cfctrl {
64648 struct cfsrvl serv;
64649 struct cfctrl_rsp res;
64650- atomic_t req_seq_no;
64651- atomic_t rsp_seq_no;
64652+ atomic_unchecked_t req_seq_no;
64653+ atomic_unchecked_t rsp_seq_no;
64654 struct list_head list;
64655 /* Protects from simultaneous access to first_req list */
64656 spinlock_t info_list_lock;
64657diff --git a/include/net/flow.h b/include/net/flow.h
64658index 6c469db..7743b8e 100644
64659--- a/include/net/flow.h
64660+++ b/include/net/flow.h
64661@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
64662
64663 extern void flow_cache_flush(void);
64664 extern void flow_cache_flush_deferred(void);
64665-extern atomic_t flow_cache_genid;
64666+extern atomic_unchecked_t flow_cache_genid;
64667
64668 #endif
64669diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
64670index 2040bff..f4c0733 100644
64671--- a/include/net/inetpeer.h
64672+++ b/include/net/inetpeer.h
64673@@ -51,8 +51,8 @@ struct inet_peer {
64674 */
64675 union {
64676 struct {
64677- atomic_t rid; /* Frag reception counter */
64678- atomic_t ip_id_count; /* IP ID for the next packet */
64679+ atomic_unchecked_t rid; /* Frag reception counter */
64680+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
64681 __u32 tcp_ts;
64682 __u32 tcp_ts_stamp;
64683 };
64684@@ -118,11 +118,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
64685 more++;
64686 inet_peer_refcheck(p);
64687 do {
64688- old = atomic_read(&p->ip_id_count);
64689+ old = atomic_read_unchecked(&p->ip_id_count);
64690 new = old + more;
64691 if (!new)
64692 new = 1;
64693- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
64694+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
64695 return new;
64696 }
64697
64698diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
64699index 78df0866..00e5c9b 100644
64700--- a/include/net/ip_fib.h
64701+++ b/include/net/ip_fib.h
64702@@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
64703
64704 #define FIB_RES_SADDR(net, res) \
64705 ((FIB_RES_NH(res).nh_saddr_genid == \
64706- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
64707+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
64708 FIB_RES_NH(res).nh_saddr : \
64709 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
64710 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
64711diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
64712index 95374d1..2300e36 100644
64713--- a/include/net/ip_vs.h
64714+++ b/include/net/ip_vs.h
64715@@ -510,7 +510,7 @@ struct ip_vs_conn {
64716 struct ip_vs_conn *control; /* Master control connection */
64717 atomic_t n_control; /* Number of controlled ones */
64718 struct ip_vs_dest *dest; /* real server */
64719- atomic_t in_pkts; /* incoming packet counter */
64720+ atomic_unchecked_t in_pkts; /* incoming packet counter */
64721
64722 /* packet transmitter for different forwarding methods. If it
64723 mangles the packet, it must return NF_DROP or better NF_STOLEN,
64724@@ -648,7 +648,7 @@ struct ip_vs_dest {
64725 __be16 port; /* port number of the server */
64726 union nf_inet_addr addr; /* IP address of the server */
64727 volatile unsigned int flags; /* dest status flags */
64728- atomic_t conn_flags; /* flags to copy to conn */
64729+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
64730 atomic_t weight; /* server weight */
64731
64732 atomic_t refcnt; /* reference counter */
64733diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
64734index 69b610a..fe3962c 100644
64735--- a/include/net/irda/ircomm_core.h
64736+++ b/include/net/irda/ircomm_core.h
64737@@ -51,7 +51,7 @@ typedef struct {
64738 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
64739 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
64740 struct ircomm_info *);
64741-} call_t;
64742+} __no_const call_t;
64743
64744 struct ircomm_cb {
64745 irda_queue_t queue;
64746diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
64747index 59ba38bc..d515662 100644
64748--- a/include/net/irda/ircomm_tty.h
64749+++ b/include/net/irda/ircomm_tty.h
64750@@ -35,6 +35,7 @@
64751 #include <linux/termios.h>
64752 #include <linux/timer.h>
64753 #include <linux/tty.h> /* struct tty_struct */
64754+#include <asm/local.h>
64755
64756 #include <net/irda/irias_object.h>
64757 #include <net/irda/ircomm_core.h>
64758@@ -105,8 +106,8 @@ struct ircomm_tty_cb {
64759 unsigned short close_delay;
64760 unsigned short closing_wait; /* time to wait before closing */
64761
64762- int open_count;
64763- int blocked_open; /* # of blocked opens */
64764+ local_t open_count;
64765+ local_t blocked_open; /* # of blocked opens */
64766
64767 /* Protect concurent access to :
64768 * o self->open_count
64769diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
64770index cc7c197..9f2da2a 100644
64771--- a/include/net/iucv/af_iucv.h
64772+++ b/include/net/iucv/af_iucv.h
64773@@ -141,7 +141,7 @@ struct iucv_sock {
64774 struct iucv_sock_list {
64775 struct hlist_head head;
64776 rwlock_t lock;
64777- atomic_t autobind_name;
64778+ atomic_unchecked_t autobind_name;
64779 };
64780
64781 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
64782diff --git a/include/net/neighbour.h b/include/net/neighbour.h
64783index 6cdfeed..55a0256 100644
64784--- a/include/net/neighbour.h
64785+++ b/include/net/neighbour.h
64786@@ -123,7 +123,7 @@ struct neigh_ops {
64787 void (*error_report)(struct neighbour *, struct sk_buff *);
64788 int (*output)(struct neighbour *, struct sk_buff *);
64789 int (*connected_output)(struct neighbour *, struct sk_buff *);
64790-};
64791+} __do_const;
64792
64793 struct pneigh_entry {
64794 struct pneigh_entry *next;
64795diff --git a/include/net/netlink.h b/include/net/netlink.h
64796index 785f37a..c81dc0c 100644
64797--- a/include/net/netlink.h
64798+++ b/include/net/netlink.h
64799@@ -520,7 +520,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
64800 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
64801 {
64802 if (mark)
64803- skb_trim(skb, (unsigned char *) mark - skb->data);
64804+ skb_trim(skb, (const unsigned char *) mark - skb->data);
64805 }
64806
64807 /**
64808diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
64809index bbd023a..97c6d0d 100644
64810--- a/include/net/netns/ipv4.h
64811+++ b/include/net/netns/ipv4.h
64812@@ -57,8 +57,8 @@ struct netns_ipv4 {
64813 unsigned int sysctl_ping_group_range[2];
64814 long sysctl_tcp_mem[3];
64815
64816- atomic_t rt_genid;
64817- atomic_t dev_addr_genid;
64818+ atomic_unchecked_t rt_genid;
64819+ atomic_unchecked_t dev_addr_genid;
64820
64821 #ifdef CONFIG_IP_MROUTE
64822 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
64823diff --git a/include/net/scm.h b/include/net/scm.h
64824index d456f4c..0c0017c 100644
64825--- a/include/net/scm.h
64826+++ b/include/net/scm.h
64827@@ -71,9 +71,11 @@ static __inline__ void scm_destroy(struct scm_cookie *scm)
64828 }
64829
64830 static __inline__ int scm_send(struct socket *sock, struct msghdr *msg,
64831- struct scm_cookie *scm)
64832+ struct scm_cookie *scm, bool forcecreds)
64833 {
64834 memset(scm, 0, sizeof(*scm));
64835+ if (forcecreds)
64836+ scm_set_cred(scm, task_tgid(current), current_cred());
64837 unix_get_peersec_dgram(sock, scm);
64838 if (msg->msg_controllen <= 0)
64839 return 0;
64840diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
64841index a2ef814..31a8e3f 100644
64842--- a/include/net/sctp/sctp.h
64843+++ b/include/net/sctp/sctp.h
64844@@ -318,9 +318,9 @@ do { \
64845
64846 #else /* SCTP_DEBUG */
64847
64848-#define SCTP_DEBUG_PRINTK(whatever...)
64849-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
64850-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
64851+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
64852+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
64853+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
64854 #define SCTP_ENABLE_DEBUG
64855 #define SCTP_DISABLE_DEBUG
64856 #define SCTP_ASSERT(expr, str, func)
64857diff --git a/include/net/sock.h b/include/net/sock.h
64858index 4a45216..7af2578 100644
64859--- a/include/net/sock.h
64860+++ b/include/net/sock.h
64861@@ -303,7 +303,7 @@ struct sock {
64862 #ifdef CONFIG_RPS
64863 __u32 sk_rxhash;
64864 #endif
64865- atomic_t sk_drops;
64866+ atomic_unchecked_t sk_drops;
64867 int sk_rcvbuf;
64868
64869 struct sk_filter __rcu *sk_filter;
64870@@ -1726,7 +1726,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
64871 }
64872
64873 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
64874- char __user *from, char *to,
64875+ char __user *from, unsigned char *to,
64876 int copy, int offset)
64877 {
64878 if (skb->ip_summed == CHECKSUM_NONE) {
64879diff --git a/include/net/tcp.h b/include/net/tcp.h
64880index e79aa48..9929421 100644
64881--- a/include/net/tcp.h
64882+++ b/include/net/tcp.h
64883@@ -1459,7 +1459,7 @@ struct tcp_seq_afinfo {
64884 char *name;
64885 sa_family_t family;
64886 const struct file_operations *seq_fops;
64887- struct seq_operations seq_ops;
64888+ seq_operations_no_const seq_ops;
64889 };
64890
64891 struct tcp_iter_state {
64892diff --git a/include/net/udp.h b/include/net/udp.h
64893index 065f379..b661b40 100644
64894--- a/include/net/udp.h
64895+++ b/include/net/udp.h
64896@@ -244,7 +244,7 @@ struct udp_seq_afinfo {
64897 sa_family_t family;
64898 struct udp_table *udp_table;
64899 const struct file_operations *seq_fops;
64900- struct seq_operations seq_ops;
64901+ seq_operations_no_const seq_ops;
64902 };
64903
64904 struct udp_iter_state {
64905diff --git a/include/net/xfrm.h b/include/net/xfrm.h
64906index e0a55df..5890bca07 100644
64907--- a/include/net/xfrm.h
64908+++ b/include/net/xfrm.h
64909@@ -505,7 +505,7 @@ struct xfrm_policy {
64910 struct timer_list timer;
64911
64912 struct flow_cache_object flo;
64913- atomic_t genid;
64914+ atomic_unchecked_t genid;
64915 u32 priority;
64916 u32 index;
64917 struct xfrm_mark mark;
64918diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
64919index 1a046b1..ee0bef0 100644
64920--- a/include/rdma/iw_cm.h
64921+++ b/include/rdma/iw_cm.h
64922@@ -122,7 +122,7 @@ struct iw_cm_verbs {
64923 int backlog);
64924
64925 int (*destroy_listen)(struct iw_cm_id *cm_id);
64926-};
64927+} __no_const;
64928
64929 /**
64930 * iw_create_cm_id - Create an IW CM identifier.
64931diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
64932index 8f9dfba..610ab6c 100644
64933--- a/include/scsi/libfc.h
64934+++ b/include/scsi/libfc.h
64935@@ -756,6 +756,7 @@ struct libfc_function_template {
64936 */
64937 void (*disc_stop_final) (struct fc_lport *);
64938 };
64939+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
64940
64941 /**
64942 * struct fc_disc - Discovery context
64943@@ -861,7 +862,7 @@ struct fc_lport {
64944 struct fc_vport *vport;
64945
64946 /* Operational Information */
64947- struct libfc_function_template tt;
64948+ libfc_function_template_no_const tt;
64949 u8 link_up;
64950 u8 qfull;
64951 enum fc_lport_state state;
64952diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
64953index ba96988..ecf2eb9 100644
64954--- a/include/scsi/scsi_device.h
64955+++ b/include/scsi/scsi_device.h
64956@@ -163,9 +163,9 @@ struct scsi_device {
64957 unsigned int max_device_blocked; /* what device_blocked counts down from */
64958 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
64959
64960- atomic_t iorequest_cnt;
64961- atomic_t iodone_cnt;
64962- atomic_t ioerr_cnt;
64963+ atomic_unchecked_t iorequest_cnt;
64964+ atomic_unchecked_t iodone_cnt;
64965+ atomic_unchecked_t ioerr_cnt;
64966
64967 struct device sdev_gendev,
64968 sdev_dev;
64969diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
64970index 719faf1..07b6728 100644
64971--- a/include/scsi/scsi_transport_fc.h
64972+++ b/include/scsi/scsi_transport_fc.h
64973@@ -739,7 +739,8 @@ struct fc_function_template {
64974 unsigned long show_host_system_hostname:1;
64975
64976 unsigned long disable_target_scan:1;
64977-};
64978+} __do_const;
64979+typedef struct fc_function_template __no_const fc_function_template_no_const;
64980
64981
64982 /**
64983diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
64984index 030b87c..98a6954 100644
64985--- a/include/sound/ak4xxx-adda.h
64986+++ b/include/sound/ak4xxx-adda.h
64987@@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
64988 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
64989 unsigned char val);
64990 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
64991-};
64992+} __no_const;
64993
64994 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
64995
64996diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
64997index 8c05e47..2b5df97 100644
64998--- a/include/sound/hwdep.h
64999+++ b/include/sound/hwdep.h
65000@@ -49,7 +49,7 @@ struct snd_hwdep_ops {
65001 struct snd_hwdep_dsp_status *status);
65002 int (*dsp_load)(struct snd_hwdep *hw,
65003 struct snd_hwdep_dsp_image *image);
65004-};
65005+} __no_const;
65006
65007 struct snd_hwdep {
65008 struct snd_card *card;
65009diff --git a/include/sound/info.h b/include/sound/info.h
65010index 9ca1a49..aba1728 100644
65011--- a/include/sound/info.h
65012+++ b/include/sound/info.h
65013@@ -44,7 +44,7 @@ struct snd_info_entry_text {
65014 struct snd_info_buffer *buffer);
65015 void (*write)(struct snd_info_entry *entry,
65016 struct snd_info_buffer *buffer);
65017-};
65018+} __no_const;
65019
65020 struct snd_info_entry_ops {
65021 int (*open)(struct snd_info_entry *entry,
65022diff --git a/include/sound/pcm.h b/include/sound/pcm.h
65023index 0d11128..814178e 100644
65024--- a/include/sound/pcm.h
65025+++ b/include/sound/pcm.h
65026@@ -81,6 +81,7 @@ struct snd_pcm_ops {
65027 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
65028 int (*ack)(struct snd_pcm_substream *substream);
65029 };
65030+typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
65031
65032 /*
65033 *
65034diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
65035index af1b49e..a5d55a5 100644
65036--- a/include/sound/sb16_csp.h
65037+++ b/include/sound/sb16_csp.h
65038@@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
65039 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
65040 int (*csp_stop) (struct snd_sb_csp * p);
65041 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
65042-};
65043+} __no_const;
65044
65045 /*
65046 * CSP private data
65047diff --git a/include/sound/soc.h b/include/sound/soc.h
65048index c703871..f7fbbbd 100644
65049--- a/include/sound/soc.h
65050+++ b/include/sound/soc.h
65051@@ -757,7 +757,7 @@ struct snd_soc_platform_driver {
65052 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
65053 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
65054 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
65055-};
65056+} __do_const;
65057
65058 struct snd_soc_platform {
65059 const char *name;
65060@@ -949,7 +949,7 @@ struct snd_soc_pcm_runtime {
65061 struct snd_soc_dai_link *dai_link;
65062 struct mutex pcm_mutex;
65063 enum snd_soc_pcm_subclass pcm_subclass;
65064- struct snd_pcm_ops ops;
65065+ snd_pcm_ops_no_const ops;
65066
65067 unsigned int dev_registered:1;
65068
65069diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
65070index 0c3c2fb..d9d9990 100644
65071--- a/include/sound/tea575x-tuner.h
65072+++ b/include/sound/tea575x-tuner.h
65073@@ -44,7 +44,7 @@ struct snd_tea575x_ops {
65074
65075 struct snd_tea575x {
65076 struct v4l2_device *v4l2_dev;
65077- struct v4l2_file_operations fops;
65078+ v4l2_file_operations_no_const fops;
65079 struct video_device vd; /* video device */
65080 int radio_nr; /* radio_nr */
65081 bool tea5759; /* 5759 chip is present */
65082diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
65083index 4119966..1a4671c 100644
65084--- a/include/sound/ymfpci.h
65085+++ b/include/sound/ymfpci.h
65086@@ -358,7 +358,7 @@ struct snd_ymfpci {
65087 spinlock_t reg_lock;
65088 spinlock_t voice_lock;
65089 wait_queue_head_t interrupt_sleep;
65090- atomic_t interrupt_sleep_count;
65091+ atomic_unchecked_t interrupt_sleep_count;
65092 struct snd_info_entry *proc_entry;
65093 const struct firmware *dsp_microcode;
65094 const struct firmware *controller_microcode;
65095diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
65096index 362e0d9..36b9a83 100644
65097--- a/include/target/target_core_base.h
65098+++ b/include/target/target_core_base.h
65099@@ -441,7 +441,7 @@ struct t10_reservation_ops {
65100 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
65101 int (*t10_pr_register)(struct se_cmd *);
65102 int (*t10_pr_clear)(struct se_cmd *);
65103-};
65104+} __no_const;
65105
65106 struct t10_reservation {
65107 /* Reservation effects all target ports */
65108@@ -780,7 +780,7 @@ struct se_device {
65109 spinlock_t stats_lock;
65110 /* Active commands on this virtual SE device */
65111 atomic_t simple_cmds;
65112- atomic_t dev_ordered_id;
65113+ atomic_unchecked_t dev_ordered_id;
65114 atomic_t execute_tasks;
65115 atomic_t dev_ordered_sync;
65116 atomic_t dev_qf_count;
65117diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
65118new file mode 100644
65119index 0000000..2efe49d
65120--- /dev/null
65121+++ b/include/trace/events/fs.h
65122@@ -0,0 +1,53 @@
65123+#undef TRACE_SYSTEM
65124+#define TRACE_SYSTEM fs
65125+
65126+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
65127+#define _TRACE_FS_H
65128+
65129+#include <linux/fs.h>
65130+#include <linux/tracepoint.h>
65131+
65132+TRACE_EVENT(do_sys_open,
65133+
65134+ TP_PROTO(char *filename, int flags, int mode),
65135+
65136+ TP_ARGS(filename, flags, mode),
65137+
65138+ TP_STRUCT__entry(
65139+ __string( filename, filename )
65140+ __field( int, flags )
65141+ __field( int, mode )
65142+ ),
65143+
65144+ TP_fast_assign(
65145+ __assign_str(filename, filename);
65146+ __entry->flags = flags;
65147+ __entry->mode = mode;
65148+ ),
65149+
65150+ TP_printk("\"%s\" %x %o",
65151+ __get_str(filename), __entry->flags, __entry->mode)
65152+);
65153+
65154+TRACE_EVENT(open_exec,
65155+
65156+ TP_PROTO(const char *filename),
65157+
65158+ TP_ARGS(filename),
65159+
65160+ TP_STRUCT__entry(
65161+ __string( filename, filename )
65162+ ),
65163+
65164+ TP_fast_assign(
65165+ __assign_str(filename, filename);
65166+ ),
65167+
65168+ TP_printk("\"%s\"",
65169+ __get_str(filename))
65170+);
65171+
65172+#endif /* _TRACE_FS_H */
65173+
65174+/* This part must be outside protection */
65175+#include <trace/define_trace.h>
65176diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
65177index 1c09820..7f5ec79 100644
65178--- a/include/trace/events/irq.h
65179+++ b/include/trace/events/irq.h
65180@@ -36,7 +36,7 @@ struct softirq_action;
65181 */
65182 TRACE_EVENT(irq_handler_entry,
65183
65184- TP_PROTO(int irq, struct irqaction *action),
65185+ TP_PROTO(int irq, const struct irqaction *action),
65186
65187 TP_ARGS(irq, action),
65188
65189@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
65190 */
65191 TRACE_EVENT(irq_handler_exit,
65192
65193- TP_PROTO(int irq, struct irqaction *action, int ret),
65194+ TP_PROTO(int irq, const struct irqaction *action, int ret),
65195
65196 TP_ARGS(irq, action, ret),
65197
65198diff --git a/include/video/udlfb.h b/include/video/udlfb.h
65199index f9466fa..f4e2b81 100644
65200--- a/include/video/udlfb.h
65201+++ b/include/video/udlfb.h
65202@@ -53,10 +53,10 @@ struct dlfb_data {
65203 u32 pseudo_palette[256];
65204 int blank_mode; /*one of FB_BLANK_ */
65205 /* blit-only rendering path metrics, exposed through sysfs */
65206- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65207- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
65208- atomic_t bytes_sent; /* to usb, after compression including overhead */
65209- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
65210+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65211+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
65212+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
65213+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
65214 };
65215
65216 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
65217diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
65218index 0993a22..32ba2fe 100644
65219--- a/include/video/uvesafb.h
65220+++ b/include/video/uvesafb.h
65221@@ -177,6 +177,7 @@ struct uvesafb_par {
65222 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
65223 u8 pmi_setpal; /* PMI for palette changes */
65224 u16 *pmi_base; /* protected mode interface location */
65225+ u8 *pmi_code; /* protected mode code location */
65226 void *pmi_start;
65227 void *pmi_pal;
65228 u8 *vbe_state_orig; /*
65229diff --git a/init/Kconfig b/init/Kconfig
65230index d07dcf9..fa47d0e 100644
65231--- a/init/Kconfig
65232+++ b/init/Kconfig
65233@@ -835,6 +835,7 @@ endif # CGROUPS
65234
65235 config CHECKPOINT_RESTORE
65236 bool "Checkpoint/restore support" if EXPERT
65237+ depends on !GRKERNSEC
65238 default n
65239 help
65240 Enables additional kernel features in a sake of checkpoint/restore.
65241@@ -1014,6 +1015,7 @@ config UIDGID_CONVERTED
65242 # Security modules
65243 depends on SECURITY_TOMOYO = n
65244 depends on SECURITY_APPARMOR = n
65245+ depends on GRKERNSEC = n
65246
65247 config UIDGID_STRICT_TYPE_CHECKS
65248 bool "Require conversions between uid/gids and their internal representation"
65249@@ -1401,7 +1403,7 @@ config SLUB_DEBUG
65250
65251 config COMPAT_BRK
65252 bool "Disable heap randomization"
65253- default y
65254+ default n
65255 help
65256 Randomizing heap placement makes heap exploits harder, but it
65257 also breaks ancient binaries (including anything libc5 based).
65258@@ -1584,7 +1586,7 @@ config INIT_ALL_POSSIBLE
65259 config STOP_MACHINE
65260 bool
65261 default y
65262- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
65263+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
65264 help
65265 Need stop_machine() primitive.
65266
65267diff --git a/init/Makefile b/init/Makefile
65268index 7bc47ee..6da2dc7 100644
65269--- a/init/Makefile
65270+++ b/init/Makefile
65271@@ -2,6 +2,9 @@
65272 # Makefile for the linux kernel.
65273 #
65274
65275+ccflags-y := $(GCC_PLUGINS_CFLAGS)
65276+asflags-y := $(GCC_PLUGINS_AFLAGS)
65277+
65278 obj-y := main.o version.o mounts.o
65279 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
65280 obj-y += noinitramfs.o
65281diff --git a/init/do_mounts.c b/init/do_mounts.c
65282index d3f0aee..c9322f5 100644
65283--- a/init/do_mounts.c
65284+++ b/init/do_mounts.c
65285@@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
65286 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
65287 {
65288 struct super_block *s;
65289- int err = sys_mount(name, "/root", fs, flags, data);
65290+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
65291 if (err)
65292 return err;
65293
65294- sys_chdir("/root");
65295+ sys_chdir((const char __force_user *)"/root");
65296 s = current->fs->pwd.dentry->d_sb;
65297 ROOT_DEV = s->s_dev;
65298 printk(KERN_INFO
65299@@ -460,18 +460,18 @@ void __init change_floppy(char *fmt, ...)
65300 va_start(args, fmt);
65301 vsprintf(buf, fmt, args);
65302 va_end(args);
65303- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
65304+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
65305 if (fd >= 0) {
65306 sys_ioctl(fd, FDEJECT, 0);
65307 sys_close(fd);
65308 }
65309 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
65310- fd = sys_open("/dev/console", O_RDWR, 0);
65311+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
65312 if (fd >= 0) {
65313 sys_ioctl(fd, TCGETS, (long)&termios);
65314 termios.c_lflag &= ~ICANON;
65315 sys_ioctl(fd, TCSETSF, (long)&termios);
65316- sys_read(fd, &c, 1);
65317+ sys_read(fd, (char __user *)&c, 1);
65318 termios.c_lflag |= ICANON;
65319 sys_ioctl(fd, TCSETSF, (long)&termios);
65320 sys_close(fd);
65321@@ -565,6 +565,6 @@ void __init prepare_namespace(void)
65322 mount_root();
65323 out:
65324 devtmpfs_mount("dev");
65325- sys_mount(".", "/", NULL, MS_MOVE, NULL);
65326- sys_chroot(".");
65327+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65328+ sys_chroot((const char __force_user *)".");
65329 }
65330diff --git a/init/do_mounts.h b/init/do_mounts.h
65331index f5b978a..69dbfe8 100644
65332--- a/init/do_mounts.h
65333+++ b/init/do_mounts.h
65334@@ -15,15 +15,15 @@ extern int root_mountflags;
65335
65336 static inline int create_dev(char *name, dev_t dev)
65337 {
65338- sys_unlink(name);
65339- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
65340+ sys_unlink((char __force_user *)name);
65341+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
65342 }
65343
65344 #if BITS_PER_LONG == 32
65345 static inline u32 bstat(char *name)
65346 {
65347 struct stat64 stat;
65348- if (sys_stat64(name, &stat) != 0)
65349+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
65350 return 0;
65351 if (!S_ISBLK(stat.st_mode))
65352 return 0;
65353@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
65354 static inline u32 bstat(char *name)
65355 {
65356 struct stat stat;
65357- if (sys_newstat(name, &stat) != 0)
65358+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
65359 return 0;
65360 if (!S_ISBLK(stat.st_mode))
65361 return 0;
65362diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
65363index 135959a2..28a3f43 100644
65364--- a/init/do_mounts_initrd.c
65365+++ b/init/do_mounts_initrd.c
65366@@ -53,13 +53,13 @@ static void __init handle_initrd(void)
65367 create_dev("/dev/root.old", Root_RAM0);
65368 /* mount initrd on rootfs' /root */
65369 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
65370- sys_mkdir("/old", 0700);
65371- root_fd = sys_open("/", 0, 0);
65372- old_fd = sys_open("/old", 0, 0);
65373+ sys_mkdir((const char __force_user *)"/old", 0700);
65374+ root_fd = sys_open((const char __force_user *)"/", 0, 0);
65375+ old_fd = sys_open((const char __force_user *)"/old", 0, 0);
65376 /* move initrd over / and chdir/chroot in initrd root */
65377- sys_chdir("/root");
65378- sys_mount(".", "/", NULL, MS_MOVE, NULL);
65379- sys_chroot(".");
65380+ sys_chdir((const char __force_user *)"/root");
65381+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65382+ sys_chroot((const char __force_user *)".");
65383
65384 /*
65385 * In case that a resume from disk is carried out by linuxrc or one of
65386@@ -76,15 +76,15 @@ static void __init handle_initrd(void)
65387
65388 /* move initrd to rootfs' /old */
65389 sys_fchdir(old_fd);
65390- sys_mount("/", ".", NULL, MS_MOVE, NULL);
65391+ sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
65392 /* switch root and cwd back to / of rootfs */
65393 sys_fchdir(root_fd);
65394- sys_chroot(".");
65395+ sys_chroot((const char __force_user *)".");
65396 sys_close(old_fd);
65397 sys_close(root_fd);
65398
65399 if (new_decode_dev(real_root_dev) == Root_RAM0) {
65400- sys_chdir("/old");
65401+ sys_chdir((const char __force_user *)"/old");
65402 return;
65403 }
65404
65405@@ -92,17 +92,17 @@ static void __init handle_initrd(void)
65406 mount_root();
65407
65408 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
65409- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
65410+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
65411 if (!error)
65412 printk("okay\n");
65413 else {
65414- int fd = sys_open("/dev/root.old", O_RDWR, 0);
65415+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
65416 if (error == -ENOENT)
65417 printk("/initrd does not exist. Ignored.\n");
65418 else
65419 printk("failed\n");
65420 printk(KERN_NOTICE "Unmounting old root\n");
65421- sys_umount("/old", MNT_DETACH);
65422+ sys_umount((char __force_user *)"/old", MNT_DETACH);
65423 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
65424 if (fd < 0) {
65425 error = fd;
65426@@ -125,11 +125,11 @@ int __init initrd_load(void)
65427 * mounted in the normal path.
65428 */
65429 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
65430- sys_unlink("/initrd.image");
65431+ sys_unlink((const char __force_user *)"/initrd.image");
65432 handle_initrd();
65433 return 1;
65434 }
65435 }
65436- sys_unlink("/initrd.image");
65437+ sys_unlink((const char __force_user *)"/initrd.image");
65438 return 0;
65439 }
65440diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
65441index 8cb6db5..d729f50 100644
65442--- a/init/do_mounts_md.c
65443+++ b/init/do_mounts_md.c
65444@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
65445 partitioned ? "_d" : "", minor,
65446 md_setup_args[ent].device_names);
65447
65448- fd = sys_open(name, 0, 0);
65449+ fd = sys_open((char __force_user *)name, 0, 0);
65450 if (fd < 0) {
65451 printk(KERN_ERR "md: open failed - cannot start "
65452 "array %s\n", name);
65453@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
65454 * array without it
65455 */
65456 sys_close(fd);
65457- fd = sys_open(name, 0, 0);
65458+ fd = sys_open((char __force_user *)name, 0, 0);
65459 sys_ioctl(fd, BLKRRPART, 0);
65460 }
65461 sys_close(fd);
65462@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
65463
65464 wait_for_device_probe();
65465
65466- fd = sys_open("/dev/md0", 0, 0);
65467+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
65468 if (fd >= 0) {
65469 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
65470 sys_close(fd);
65471diff --git a/init/init_task.c b/init/init_task.c
65472index 8b2f399..f0797c9 100644
65473--- a/init/init_task.c
65474+++ b/init/init_task.c
65475@@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
65476 * Initial thread structure. Alignment of this is handled by a special
65477 * linker map entry.
65478 */
65479+#ifdef CONFIG_X86
65480+union thread_union init_thread_union __init_task_data;
65481+#else
65482 union thread_union init_thread_union __init_task_data =
65483 { INIT_THREAD_INFO(init_task) };
65484+#endif
65485diff --git a/init/initramfs.c b/init/initramfs.c
65486index 84c6bf1..8899338 100644
65487--- a/init/initramfs.c
65488+++ b/init/initramfs.c
65489@@ -84,7 +84,7 @@ static void __init free_hash(void)
65490 }
65491 }
65492
65493-static long __init do_utime(char *filename, time_t mtime)
65494+static long __init do_utime(char __force_user *filename, time_t mtime)
65495 {
65496 struct timespec t[2];
65497
65498@@ -119,7 +119,7 @@ static void __init dir_utime(void)
65499 struct dir_entry *de, *tmp;
65500 list_for_each_entry_safe(de, tmp, &dir_list, list) {
65501 list_del(&de->list);
65502- do_utime(de->name, de->mtime);
65503+ do_utime((char __force_user *)de->name, de->mtime);
65504 kfree(de->name);
65505 kfree(de);
65506 }
65507@@ -281,7 +281,7 @@ static int __init maybe_link(void)
65508 if (nlink >= 2) {
65509 char *old = find_link(major, minor, ino, mode, collected);
65510 if (old)
65511- return (sys_link(old, collected) < 0) ? -1 : 1;
65512+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
65513 }
65514 return 0;
65515 }
65516@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
65517 {
65518 struct stat st;
65519
65520- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
65521+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
65522 if (S_ISDIR(st.st_mode))
65523- sys_rmdir(path);
65524+ sys_rmdir((char __force_user *)path);
65525 else
65526- sys_unlink(path);
65527+ sys_unlink((char __force_user *)path);
65528 }
65529 }
65530
65531@@ -315,7 +315,7 @@ static int __init do_name(void)
65532 int openflags = O_WRONLY|O_CREAT;
65533 if (ml != 1)
65534 openflags |= O_TRUNC;
65535- wfd = sys_open(collected, openflags, mode);
65536+ wfd = sys_open((char __force_user *)collected, openflags, mode);
65537
65538 if (wfd >= 0) {
65539 sys_fchown(wfd, uid, gid);
65540@@ -327,17 +327,17 @@ static int __init do_name(void)
65541 }
65542 }
65543 } else if (S_ISDIR(mode)) {
65544- sys_mkdir(collected, mode);
65545- sys_chown(collected, uid, gid);
65546- sys_chmod(collected, mode);
65547+ sys_mkdir((char __force_user *)collected, mode);
65548+ sys_chown((char __force_user *)collected, uid, gid);
65549+ sys_chmod((char __force_user *)collected, mode);
65550 dir_add(collected, mtime);
65551 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
65552 S_ISFIFO(mode) || S_ISSOCK(mode)) {
65553 if (maybe_link() == 0) {
65554- sys_mknod(collected, mode, rdev);
65555- sys_chown(collected, uid, gid);
65556- sys_chmod(collected, mode);
65557- do_utime(collected, mtime);
65558+ sys_mknod((char __force_user *)collected, mode, rdev);
65559+ sys_chown((char __force_user *)collected, uid, gid);
65560+ sys_chmod((char __force_user *)collected, mode);
65561+ do_utime((char __force_user *)collected, mtime);
65562 }
65563 }
65564 return 0;
65565@@ -346,15 +346,15 @@ static int __init do_name(void)
65566 static int __init do_copy(void)
65567 {
65568 if (count >= body_len) {
65569- sys_write(wfd, victim, body_len);
65570+ sys_write(wfd, (char __force_user *)victim, body_len);
65571 sys_close(wfd);
65572- do_utime(vcollected, mtime);
65573+ do_utime((char __force_user *)vcollected, mtime);
65574 kfree(vcollected);
65575 eat(body_len);
65576 state = SkipIt;
65577 return 0;
65578 } else {
65579- sys_write(wfd, victim, count);
65580+ sys_write(wfd, (char __force_user *)victim, count);
65581 body_len -= count;
65582 eat(count);
65583 return 1;
65584@@ -365,9 +365,9 @@ static int __init do_symlink(void)
65585 {
65586 collected[N_ALIGN(name_len) + body_len] = '\0';
65587 clean_path(collected, 0);
65588- sys_symlink(collected + N_ALIGN(name_len), collected);
65589- sys_lchown(collected, uid, gid);
65590- do_utime(collected, mtime);
65591+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
65592+ sys_lchown((char __force_user *)collected, uid, gid);
65593+ do_utime((char __force_user *)collected, mtime);
65594 state = SkipIt;
65595 next_state = Reset;
65596 return 0;
65597diff --git a/init/main.c b/init/main.c
65598index b5cc0a7..5605c91 100644
65599--- a/init/main.c
65600+++ b/init/main.c
65601@@ -95,6 +95,8 @@ static inline void mark_rodata_ro(void) { }
65602 extern void tc_init(void);
65603 #endif
65604
65605+extern void grsecurity_init(void);
65606+
65607 /*
65608 * Debug helper: via this flag we know that we are in 'early bootup code'
65609 * where only the boot processor is running with IRQ disabled. This means
65610@@ -148,6 +150,49 @@ static int __init set_reset_devices(char *str)
65611
65612 __setup("reset_devices", set_reset_devices);
65613
65614+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
65615+extern char pax_enter_kernel_user[];
65616+extern char pax_exit_kernel_user[];
65617+extern pgdval_t clone_pgd_mask;
65618+#endif
65619+
65620+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
65621+static int __init setup_pax_nouderef(char *str)
65622+{
65623+#ifdef CONFIG_X86_32
65624+ unsigned int cpu;
65625+ struct desc_struct *gdt;
65626+
65627+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
65628+ gdt = get_cpu_gdt_table(cpu);
65629+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
65630+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
65631+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
65632+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
65633+ }
65634+ asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
65635+#else
65636+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
65637+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
65638+ clone_pgd_mask = ~(pgdval_t)0UL;
65639+#endif
65640+
65641+ return 0;
65642+}
65643+early_param("pax_nouderef", setup_pax_nouderef);
65644+#endif
65645+
65646+#ifdef CONFIG_PAX_SOFTMODE
65647+int pax_softmode;
65648+
65649+static int __init setup_pax_softmode(char *str)
65650+{
65651+ get_option(&str, &pax_softmode);
65652+ return 1;
65653+}
65654+__setup("pax_softmode=", setup_pax_softmode);
65655+#endif
65656+
65657 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
65658 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
65659 static const char *panic_later, *panic_param;
65660@@ -674,6 +719,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
65661 {
65662 int count = preempt_count();
65663 int ret;
65664+ const char *msg1 = "", *msg2 = "";
65665
65666 if (initcall_debug)
65667 ret = do_one_initcall_debug(fn);
65668@@ -686,15 +732,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
65669 sprintf(msgbuf, "error code %d ", ret);
65670
65671 if (preempt_count() != count) {
65672- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
65673+ msg1 = " preemption imbalance";
65674 preempt_count() = count;
65675 }
65676 if (irqs_disabled()) {
65677- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
65678+ msg2 = " disabled interrupts";
65679 local_irq_enable();
65680 }
65681- if (msgbuf[0]) {
65682- printk("initcall %pF returned with %s\n", fn, msgbuf);
65683+ if (msgbuf[0] || *msg1 || *msg2) {
65684+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
65685 }
65686
65687 return ret;
65688@@ -747,8 +793,14 @@ static void __init do_initcall_level(int level)
65689 level, level,
65690 &repair_env_string);
65691
65692- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
65693+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
65694 do_one_initcall(*fn);
65695+
65696+#ifdef CONFIG_PAX_LATENT_ENTROPY
65697+ transfer_latent_entropy();
65698+#endif
65699+
65700+ }
65701 }
65702
65703 static void __init do_initcalls(void)
65704@@ -782,8 +834,14 @@ static void __init do_pre_smp_initcalls(void)
65705 {
65706 initcall_t *fn;
65707
65708- for (fn = __initcall_start; fn < __initcall0_start; fn++)
65709+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
65710 do_one_initcall(*fn);
65711+
65712+#ifdef CONFIG_PAX_LATENT_ENTROPY
65713+ transfer_latent_entropy();
65714+#endif
65715+
65716+ }
65717 }
65718
65719 static void run_init_process(const char *init_filename)
65720@@ -865,7 +923,7 @@ static int __init kernel_init(void * unused)
65721 do_basic_setup();
65722
65723 /* Open the /dev/console on the rootfs, this should never fail */
65724- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
65725+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
65726 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
65727
65728 (void) sys_dup(0);
65729@@ -878,11 +936,13 @@ static int __init kernel_init(void * unused)
65730 if (!ramdisk_execute_command)
65731 ramdisk_execute_command = "/init";
65732
65733- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
65734+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
65735 ramdisk_execute_command = NULL;
65736 prepare_namespace();
65737 }
65738
65739+ grsecurity_init();
65740+
65741 /*
65742 * Ok, we have completed the initial bootup, and
65743 * we're essentially up and running. Get rid of the
65744diff --git a/ipc/mqueue.c b/ipc/mqueue.c
65745index 8ce5769..4666884 100644
65746--- a/ipc/mqueue.c
65747+++ b/ipc/mqueue.c
65748@@ -279,6 +279,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
65749 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
65750 info->attr.mq_msgsize);
65751
65752+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
65753 spin_lock(&mq_lock);
65754 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
65755 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
65756diff --git a/ipc/msg.c b/ipc/msg.c
65757index 7385de2..a8180e08 100644
65758--- a/ipc/msg.c
65759+++ b/ipc/msg.c
65760@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
65761 return security_msg_queue_associate(msq, msgflg);
65762 }
65763
65764+static struct ipc_ops msg_ops = {
65765+ .getnew = newque,
65766+ .associate = msg_security,
65767+ .more_checks = NULL
65768+};
65769+
65770 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
65771 {
65772 struct ipc_namespace *ns;
65773- struct ipc_ops msg_ops;
65774 struct ipc_params msg_params;
65775
65776 ns = current->nsproxy->ipc_ns;
65777
65778- msg_ops.getnew = newque;
65779- msg_ops.associate = msg_security;
65780- msg_ops.more_checks = NULL;
65781-
65782 msg_params.key = key;
65783 msg_params.flg = msgflg;
65784
65785diff --git a/ipc/sem.c b/ipc/sem.c
65786index 5215a81..cfc0cac 100644
65787--- a/ipc/sem.c
65788+++ b/ipc/sem.c
65789@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
65790 return 0;
65791 }
65792
65793+static struct ipc_ops sem_ops = {
65794+ .getnew = newary,
65795+ .associate = sem_security,
65796+ .more_checks = sem_more_checks
65797+};
65798+
65799 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65800 {
65801 struct ipc_namespace *ns;
65802- struct ipc_ops sem_ops;
65803 struct ipc_params sem_params;
65804
65805 ns = current->nsproxy->ipc_ns;
65806@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65807 if (nsems < 0 || nsems > ns->sc_semmsl)
65808 return -EINVAL;
65809
65810- sem_ops.getnew = newary;
65811- sem_ops.associate = sem_security;
65812- sem_ops.more_checks = sem_more_checks;
65813-
65814 sem_params.key = key;
65815 sem_params.flg = semflg;
65816 sem_params.u.nsems = nsems;
65817diff --git a/ipc/shm.c b/ipc/shm.c
65818index 41c1285..cf6404c 100644
65819--- a/ipc/shm.c
65820+++ b/ipc/shm.c
65821@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
65822 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
65823 #endif
65824
65825+#ifdef CONFIG_GRKERNSEC
65826+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65827+ const time_t shm_createtime, const uid_t cuid,
65828+ const int shmid);
65829+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65830+ const time_t shm_createtime);
65831+#endif
65832+
65833 void shm_init_ns(struct ipc_namespace *ns)
65834 {
65835 ns->shm_ctlmax = SHMMAX;
65836@@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
65837 shp->shm_lprid = 0;
65838 shp->shm_atim = shp->shm_dtim = 0;
65839 shp->shm_ctim = get_seconds();
65840+#ifdef CONFIG_GRKERNSEC
65841+ {
65842+ struct timespec timeval;
65843+ do_posix_clock_monotonic_gettime(&timeval);
65844+
65845+ shp->shm_createtime = timeval.tv_sec;
65846+ }
65847+#endif
65848 shp->shm_segsz = size;
65849 shp->shm_nattch = 0;
65850 shp->shm_file = file;
65851@@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
65852 return 0;
65853 }
65854
65855+static struct ipc_ops shm_ops = {
65856+ .getnew = newseg,
65857+ .associate = shm_security,
65858+ .more_checks = shm_more_checks
65859+};
65860+
65861 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
65862 {
65863 struct ipc_namespace *ns;
65864- struct ipc_ops shm_ops;
65865 struct ipc_params shm_params;
65866
65867 ns = current->nsproxy->ipc_ns;
65868
65869- shm_ops.getnew = newseg;
65870- shm_ops.associate = shm_security;
65871- shm_ops.more_checks = shm_more_checks;
65872-
65873 shm_params.key = key;
65874 shm_params.flg = shmflg;
65875 shm_params.u.size = size;
65876@@ -1000,6 +1017,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65877 f_mode = FMODE_READ | FMODE_WRITE;
65878 }
65879 if (shmflg & SHM_EXEC) {
65880+
65881+#ifdef CONFIG_PAX_MPROTECT
65882+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
65883+ goto out;
65884+#endif
65885+
65886 prot |= PROT_EXEC;
65887 acc_mode |= S_IXUGO;
65888 }
65889@@ -1023,9 +1046,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65890 if (err)
65891 goto out_unlock;
65892
65893+#ifdef CONFIG_GRKERNSEC
65894+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
65895+ shp->shm_perm.cuid, shmid) ||
65896+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
65897+ err = -EACCES;
65898+ goto out_unlock;
65899+ }
65900+#endif
65901+
65902 path = shp->shm_file->f_path;
65903 path_get(&path);
65904 shp->shm_nattch++;
65905+#ifdef CONFIG_GRKERNSEC
65906+ shp->shm_lapid = current->pid;
65907+#endif
65908 size = i_size_read(path.dentry->d_inode);
65909 shm_unlock(shp);
65910
65911diff --git a/kernel/acct.c b/kernel/acct.c
65912index 02e6167..54824f7 100644
65913--- a/kernel/acct.c
65914+++ b/kernel/acct.c
65915@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
65916 */
65917 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
65918 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
65919- file->f_op->write(file, (char *)&ac,
65920+ file->f_op->write(file, (char __force_user *)&ac,
65921 sizeof(acct_t), &file->f_pos);
65922 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
65923 set_fs(fs);
65924diff --git a/kernel/audit.c b/kernel/audit.c
65925index 1c7f2c6..9ba5359 100644
65926--- a/kernel/audit.c
65927+++ b/kernel/audit.c
65928@@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
65929 3) suppressed due to audit_rate_limit
65930 4) suppressed due to audit_backlog_limit
65931 */
65932-static atomic_t audit_lost = ATOMIC_INIT(0);
65933+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
65934
65935 /* The netlink socket. */
65936 static struct sock *audit_sock;
65937@@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
65938 unsigned long now;
65939 int print;
65940
65941- atomic_inc(&audit_lost);
65942+ atomic_inc_unchecked(&audit_lost);
65943
65944 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
65945
65946@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
65947 printk(KERN_WARNING
65948 "audit: audit_lost=%d audit_rate_limit=%d "
65949 "audit_backlog_limit=%d\n",
65950- atomic_read(&audit_lost),
65951+ atomic_read_unchecked(&audit_lost),
65952 audit_rate_limit,
65953 audit_backlog_limit);
65954 audit_panic(message);
65955@@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
65956 status_set.pid = audit_pid;
65957 status_set.rate_limit = audit_rate_limit;
65958 status_set.backlog_limit = audit_backlog_limit;
65959- status_set.lost = atomic_read(&audit_lost);
65960+ status_set.lost = atomic_read_unchecked(&audit_lost);
65961 status_set.backlog = skb_queue_len(&audit_skb_queue);
65962 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
65963 &status_set, sizeof(status_set));
65964diff --git a/kernel/auditsc.c b/kernel/auditsc.c
65965index 4b96415..d8c16ee 100644
65966--- a/kernel/auditsc.c
65967+++ b/kernel/auditsc.c
65968@@ -2289,7 +2289,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
65969 }
65970
65971 /* global counter which is incremented every time something logs in */
65972-static atomic_t session_id = ATOMIC_INIT(0);
65973+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
65974
65975 /**
65976 * audit_set_loginuid - set current task's audit_context loginuid
65977@@ -2313,7 +2313,7 @@ int audit_set_loginuid(uid_t loginuid)
65978 return -EPERM;
65979 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
65980
65981- sessionid = atomic_inc_return(&session_id);
65982+ sessionid = atomic_inc_return_unchecked(&session_id);
65983 if (context && context->in_syscall) {
65984 struct audit_buffer *ab;
65985
65986diff --git a/kernel/capability.c b/kernel/capability.c
65987index 493d972..ea17248 100644
65988--- a/kernel/capability.c
65989+++ b/kernel/capability.c
65990@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
65991 * before modification is attempted and the application
65992 * fails.
65993 */
65994+ if (tocopy > ARRAY_SIZE(kdata))
65995+ return -EFAULT;
65996+
65997 if (copy_to_user(dataptr, kdata, tocopy
65998 * sizeof(struct __user_cap_data_struct))) {
65999 return -EFAULT;
66000@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
66001 int ret;
66002
66003 rcu_read_lock();
66004- ret = security_capable(__task_cred(t), ns, cap);
66005+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
66006+ gr_task_is_capable(t, __task_cred(t), cap);
66007 rcu_read_unlock();
66008
66009- return (ret == 0);
66010+ return ret;
66011 }
66012
66013 /**
66014@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
66015 int ret;
66016
66017 rcu_read_lock();
66018- ret = security_capable_noaudit(__task_cred(t), ns, cap);
66019+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
66020 rcu_read_unlock();
66021
66022- return (ret == 0);
66023+ return ret;
66024 }
66025
66026 /**
66027@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
66028 BUG();
66029 }
66030
66031- if (security_capable(current_cred(), ns, cap) == 0) {
66032+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
66033 current->flags |= PF_SUPERPRIV;
66034 return true;
66035 }
66036@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
66037 }
66038 EXPORT_SYMBOL(ns_capable);
66039
66040+bool ns_capable_nolog(struct user_namespace *ns, int cap)
66041+{
66042+ if (unlikely(!cap_valid(cap))) {
66043+ printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
66044+ BUG();
66045+ }
66046+
66047+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
66048+ current->flags |= PF_SUPERPRIV;
66049+ return true;
66050+ }
66051+ return false;
66052+}
66053+EXPORT_SYMBOL(ns_capable_nolog);
66054+
66055 /**
66056 * capable - Determine if the current task has a superior capability in effect
66057 * @cap: The capability to be tested for
66058@@ -408,6 +427,12 @@ bool capable(int cap)
66059 }
66060 EXPORT_SYMBOL(capable);
66061
66062+bool capable_nolog(int cap)
66063+{
66064+ return ns_capable_nolog(&init_user_ns, cap);
66065+}
66066+EXPORT_SYMBOL(capable_nolog);
66067+
66068 /**
66069 * nsown_capable - Check superior capability to one's own user_ns
66070 * @cap: The capability in question
66071@@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
66072
66073 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66074 }
66075+
66076+bool inode_capable_nolog(const struct inode *inode, int cap)
66077+{
66078+ struct user_namespace *ns = current_user_ns();
66079+
66080+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66081+}
66082diff --git a/kernel/compat.c b/kernel/compat.c
66083index c28a306..b4d0cf3 100644
66084--- a/kernel/compat.c
66085+++ b/kernel/compat.c
66086@@ -13,6 +13,7 @@
66087
66088 #include <linux/linkage.h>
66089 #include <linux/compat.h>
66090+#include <linux/module.h>
66091 #include <linux/errno.h>
66092 #include <linux/time.h>
66093 #include <linux/signal.h>
66094@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
66095 mm_segment_t oldfs;
66096 long ret;
66097
66098- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
66099+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
66100 oldfs = get_fs();
66101 set_fs(KERNEL_DS);
66102 ret = hrtimer_nanosleep_restart(restart);
66103@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
66104 oldfs = get_fs();
66105 set_fs(KERNEL_DS);
66106 ret = hrtimer_nanosleep(&tu,
66107- rmtp ? (struct timespec __user *)&rmt : NULL,
66108+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
66109 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
66110 set_fs(oldfs);
66111
66112@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
66113 mm_segment_t old_fs = get_fs();
66114
66115 set_fs(KERNEL_DS);
66116- ret = sys_sigpending((old_sigset_t __user *) &s);
66117+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
66118 set_fs(old_fs);
66119 if (ret == 0)
66120 ret = put_user(s, set);
66121@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
66122 mm_segment_t old_fs = get_fs();
66123
66124 set_fs(KERNEL_DS);
66125- ret = sys_old_getrlimit(resource, &r);
66126+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
66127 set_fs(old_fs);
66128
66129 if (!ret) {
66130@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
66131 mm_segment_t old_fs = get_fs();
66132
66133 set_fs(KERNEL_DS);
66134- ret = sys_getrusage(who, (struct rusage __user *) &r);
66135+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
66136 set_fs(old_fs);
66137
66138 if (ret)
66139@@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
66140 set_fs (KERNEL_DS);
66141 ret = sys_wait4(pid,
66142 (stat_addr ?
66143- (unsigned int __user *) &status : NULL),
66144- options, (struct rusage __user *) &r);
66145+ (unsigned int __force_user *) &status : NULL),
66146+ options, (struct rusage __force_user *) &r);
66147 set_fs (old_fs);
66148
66149 if (ret > 0) {
66150@@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
66151 memset(&info, 0, sizeof(info));
66152
66153 set_fs(KERNEL_DS);
66154- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
66155- uru ? (struct rusage __user *)&ru : NULL);
66156+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
66157+ uru ? (struct rusage __force_user *)&ru : NULL);
66158 set_fs(old_fs);
66159
66160 if ((ret < 0) || (info.si_signo == 0))
66161@@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
66162 oldfs = get_fs();
66163 set_fs(KERNEL_DS);
66164 err = sys_timer_settime(timer_id, flags,
66165- (struct itimerspec __user *) &newts,
66166- (struct itimerspec __user *) &oldts);
66167+ (struct itimerspec __force_user *) &newts,
66168+ (struct itimerspec __force_user *) &oldts);
66169 set_fs(oldfs);
66170 if (!err && old && put_compat_itimerspec(old, &oldts))
66171 return -EFAULT;
66172@@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
66173 oldfs = get_fs();
66174 set_fs(KERNEL_DS);
66175 err = sys_timer_gettime(timer_id,
66176- (struct itimerspec __user *) &ts);
66177+ (struct itimerspec __force_user *) &ts);
66178 set_fs(oldfs);
66179 if (!err && put_compat_itimerspec(setting, &ts))
66180 return -EFAULT;
66181@@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
66182 oldfs = get_fs();
66183 set_fs(KERNEL_DS);
66184 err = sys_clock_settime(which_clock,
66185- (struct timespec __user *) &ts);
66186+ (struct timespec __force_user *) &ts);
66187 set_fs(oldfs);
66188 return err;
66189 }
66190@@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
66191 oldfs = get_fs();
66192 set_fs(KERNEL_DS);
66193 err = sys_clock_gettime(which_clock,
66194- (struct timespec __user *) &ts);
66195+ (struct timespec __force_user *) &ts);
66196 set_fs(oldfs);
66197 if (!err && put_compat_timespec(&ts, tp))
66198 return -EFAULT;
66199@@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
66200
66201 oldfs = get_fs();
66202 set_fs(KERNEL_DS);
66203- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
66204+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
66205 set_fs(oldfs);
66206
66207 err = compat_put_timex(utp, &txc);
66208@@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
66209 oldfs = get_fs();
66210 set_fs(KERNEL_DS);
66211 err = sys_clock_getres(which_clock,
66212- (struct timespec __user *) &ts);
66213+ (struct timespec __force_user *) &ts);
66214 set_fs(oldfs);
66215 if (!err && tp && put_compat_timespec(&ts, tp))
66216 return -EFAULT;
66217@@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
66218 long err;
66219 mm_segment_t oldfs;
66220 struct timespec tu;
66221- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
66222+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
66223
66224- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
66225+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
66226 oldfs = get_fs();
66227 set_fs(KERNEL_DS);
66228 err = clock_nanosleep_restart(restart);
66229@@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
66230 oldfs = get_fs();
66231 set_fs(KERNEL_DS);
66232 err = sys_clock_nanosleep(which_clock, flags,
66233- (struct timespec __user *) &in,
66234- (struct timespec __user *) &out);
66235+ (struct timespec __force_user *) &in,
66236+ (struct timespec __force_user *) &out);
66237 set_fs(oldfs);
66238
66239 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
66240diff --git a/kernel/configs.c b/kernel/configs.c
66241index 42e8fa0..9e7406b 100644
66242--- a/kernel/configs.c
66243+++ b/kernel/configs.c
66244@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
66245 struct proc_dir_entry *entry;
66246
66247 /* create the current config file */
66248+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66249+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
66250+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
66251+ &ikconfig_file_ops);
66252+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66253+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
66254+ &ikconfig_file_ops);
66255+#endif
66256+#else
66257 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
66258 &ikconfig_file_ops);
66259+#endif
66260+
66261 if (!entry)
66262 return -ENOMEM;
66263
66264diff --git a/kernel/cred.c b/kernel/cred.c
66265index de728ac..e3c267c 100644
66266--- a/kernel/cred.c
66267+++ b/kernel/cred.c
66268@@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
66269 validate_creds(cred);
66270 alter_cred_subscribers(cred, -1);
66271 put_cred(cred);
66272+
66273+#ifdef CONFIG_GRKERNSEC_SETXID
66274+ cred = (struct cred *) tsk->delayed_cred;
66275+ if (cred != NULL) {
66276+ tsk->delayed_cred = NULL;
66277+ validate_creds(cred);
66278+ alter_cred_subscribers(cred, -1);
66279+ put_cred(cred);
66280+ }
66281+#endif
66282 }
66283
66284 /**
66285@@ -469,7 +479,7 @@ error_put:
66286 * Always returns 0 thus allowing this function to be tail-called at the end
66287 * of, say, sys_setgid().
66288 */
66289-int commit_creds(struct cred *new)
66290+static int __commit_creds(struct cred *new)
66291 {
66292 struct task_struct *task = current;
66293 const struct cred *old = task->real_cred;
66294@@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
66295
66296 get_cred(new); /* we will require a ref for the subj creds too */
66297
66298+ gr_set_role_label(task, new->uid, new->gid);
66299+
66300 /* dumpability changes */
66301 if (!uid_eq(old->euid, new->euid) ||
66302 !gid_eq(old->egid, new->egid) ||
66303@@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
66304 put_cred(old);
66305 return 0;
66306 }
66307+#ifdef CONFIG_GRKERNSEC_SETXID
66308+extern int set_user(struct cred *new);
66309+
66310+void gr_delayed_cred_worker(void)
66311+{
66312+ const struct cred *new = current->delayed_cred;
66313+ struct cred *ncred;
66314+
66315+ current->delayed_cred = NULL;
66316+
66317+ if (current_uid() && new != NULL) {
66318+ // from doing get_cred on it when queueing this
66319+ put_cred(new);
66320+ return;
66321+ } else if (new == NULL)
66322+ return;
66323+
66324+ ncred = prepare_creds();
66325+ if (!ncred)
66326+ goto die;
66327+ // uids
66328+ ncred->uid = new->uid;
66329+ ncred->euid = new->euid;
66330+ ncred->suid = new->suid;
66331+ ncred->fsuid = new->fsuid;
66332+ // gids
66333+ ncred->gid = new->gid;
66334+ ncred->egid = new->egid;
66335+ ncred->sgid = new->sgid;
66336+ ncred->fsgid = new->fsgid;
66337+ // groups
66338+ if (set_groups(ncred, new->group_info) < 0) {
66339+ abort_creds(ncred);
66340+ goto die;
66341+ }
66342+ // caps
66343+ ncred->securebits = new->securebits;
66344+ ncred->cap_inheritable = new->cap_inheritable;
66345+ ncred->cap_permitted = new->cap_permitted;
66346+ ncred->cap_effective = new->cap_effective;
66347+ ncred->cap_bset = new->cap_bset;
66348+
66349+ if (set_user(ncred)) {
66350+ abort_creds(ncred);
66351+ goto die;
66352+ }
66353+
66354+ // from doing get_cred on it when queueing this
66355+ put_cred(new);
66356+
66357+ __commit_creds(ncred);
66358+ return;
66359+die:
66360+ // from doing get_cred on it when queueing this
66361+ put_cred(new);
66362+ do_group_exit(SIGKILL);
66363+}
66364+#endif
66365+
66366+int commit_creds(struct cred *new)
66367+{
66368+#ifdef CONFIG_GRKERNSEC_SETXID
66369+ int ret;
66370+ int schedule_it = 0;
66371+ struct task_struct *t;
66372+
66373+ /* we won't get called with tasklist_lock held for writing
66374+ and interrupts disabled as the cred struct in that case is
66375+ init_cred
66376+ */
66377+ if (grsec_enable_setxid && !current_is_single_threaded() &&
66378+ !current_uid() && new->uid) {
66379+ schedule_it = 1;
66380+ }
66381+ ret = __commit_creds(new);
66382+ if (schedule_it) {
66383+ rcu_read_lock();
66384+ read_lock(&tasklist_lock);
66385+ for (t = next_thread(current); t != current;
66386+ t = next_thread(t)) {
66387+ if (t->delayed_cred == NULL) {
66388+ t->delayed_cred = get_cred(new);
66389+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
66390+ set_tsk_need_resched(t);
66391+ }
66392+ }
66393+ read_unlock(&tasklist_lock);
66394+ rcu_read_unlock();
66395+ }
66396+ return ret;
66397+#else
66398+ return __commit_creds(new);
66399+#endif
66400+}
66401+
66402 EXPORT_SYMBOL(commit_creds);
66403
66404 /**
66405diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
66406index 0557f24..1a00d9a 100644
66407--- a/kernel/debug/debug_core.c
66408+++ b/kernel/debug/debug_core.c
66409@@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
66410 */
66411 static atomic_t masters_in_kgdb;
66412 static atomic_t slaves_in_kgdb;
66413-static atomic_t kgdb_break_tasklet_var;
66414+static atomic_unchecked_t kgdb_break_tasklet_var;
66415 atomic_t kgdb_setting_breakpoint;
66416
66417 struct task_struct *kgdb_usethread;
66418@@ -132,7 +132,7 @@ int kgdb_single_step;
66419 static pid_t kgdb_sstep_pid;
66420
66421 /* to keep track of the CPU which is doing the single stepping*/
66422-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66423+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66424
66425 /*
66426 * If you are debugging a problem where roundup (the collection of
66427@@ -540,7 +540,7 @@ return_normal:
66428 * kernel will only try for the value of sstep_tries before
66429 * giving up and continuing on.
66430 */
66431- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
66432+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
66433 (kgdb_info[cpu].task &&
66434 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
66435 atomic_set(&kgdb_active, -1);
66436@@ -634,8 +634,8 @@ cpu_master_loop:
66437 }
66438
66439 kgdb_restore:
66440- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
66441- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
66442+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
66443+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
66444 if (kgdb_info[sstep_cpu].task)
66445 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
66446 else
66447@@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
66448 static void kgdb_tasklet_bpt(unsigned long ing)
66449 {
66450 kgdb_breakpoint();
66451- atomic_set(&kgdb_break_tasklet_var, 0);
66452+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
66453 }
66454
66455 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
66456
66457 void kgdb_schedule_breakpoint(void)
66458 {
66459- if (atomic_read(&kgdb_break_tasklet_var) ||
66460+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
66461 atomic_read(&kgdb_active) != -1 ||
66462 atomic_read(&kgdb_setting_breakpoint))
66463 return;
66464- atomic_inc(&kgdb_break_tasklet_var);
66465+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
66466 tasklet_schedule(&kgdb_tasklet_breakpoint);
66467 }
66468 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
66469diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
66470index 1f91413..362a0a1 100644
66471--- a/kernel/debug/kdb/kdb_main.c
66472+++ b/kernel/debug/kdb/kdb_main.c
66473@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
66474 list_for_each_entry(mod, kdb_modules, list) {
66475
66476 kdb_printf("%-20s%8u 0x%p ", mod->name,
66477- mod->core_size, (void *)mod);
66478+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
66479 #ifdef CONFIG_MODULE_UNLOAD
66480 kdb_printf("%4ld ", module_refcount(mod));
66481 #endif
66482@@ -1994,7 +1994,7 @@ static int kdb_lsmod(int argc, const char **argv)
66483 kdb_printf(" (Loading)");
66484 else
66485 kdb_printf(" (Live)");
66486- kdb_printf(" 0x%p", mod->module_core);
66487+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
66488
66489 #ifdef CONFIG_MODULE_UNLOAD
66490 {
66491diff --git a/kernel/events/core.c b/kernel/events/core.c
66492index d7d71d6..f54b76f 100644
66493--- a/kernel/events/core.c
66494+++ b/kernel/events/core.c
66495@@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
66496 return 0;
66497 }
66498
66499-static atomic64_t perf_event_id;
66500+static atomic64_unchecked_t perf_event_id;
66501
66502 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
66503 enum event_type_t event_type);
66504@@ -2663,7 +2663,7 @@ static void __perf_event_read(void *info)
66505
66506 static inline u64 perf_event_count(struct perf_event *event)
66507 {
66508- return local64_read(&event->count) + atomic64_read(&event->child_count);
66509+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
66510 }
66511
66512 static u64 perf_event_read(struct perf_event *event)
66513@@ -2987,9 +2987,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
66514 mutex_lock(&event->child_mutex);
66515 total += perf_event_read(event);
66516 *enabled += event->total_time_enabled +
66517- atomic64_read(&event->child_total_time_enabled);
66518+ atomic64_read_unchecked(&event->child_total_time_enabled);
66519 *running += event->total_time_running +
66520- atomic64_read(&event->child_total_time_running);
66521+ atomic64_read_unchecked(&event->child_total_time_running);
66522
66523 list_for_each_entry(child, &event->child_list, child_list) {
66524 total += perf_event_read(child);
66525@@ -3396,10 +3396,10 @@ void perf_event_update_userpage(struct perf_event *event)
66526 userpg->offset -= local64_read(&event->hw.prev_count);
66527
66528 userpg->time_enabled = enabled +
66529- atomic64_read(&event->child_total_time_enabled);
66530+ atomic64_read_unchecked(&event->child_total_time_enabled);
66531
66532 userpg->time_running = running +
66533- atomic64_read(&event->child_total_time_running);
66534+ atomic64_read_unchecked(&event->child_total_time_running);
66535
66536 arch_perf_update_userpage(userpg, now);
66537
66538@@ -3832,11 +3832,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
66539 values[n++] = perf_event_count(event);
66540 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
66541 values[n++] = enabled +
66542- atomic64_read(&event->child_total_time_enabled);
66543+ atomic64_read_unchecked(&event->child_total_time_enabled);
66544 }
66545 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
66546 values[n++] = running +
66547- atomic64_read(&event->child_total_time_running);
66548+ atomic64_read_unchecked(&event->child_total_time_running);
66549 }
66550 if (read_format & PERF_FORMAT_ID)
66551 values[n++] = primary_event_id(event);
66552@@ -4514,12 +4514,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
66553 * need to add enough zero bytes after the string to handle
66554 * the 64bit alignment we do later.
66555 */
66556- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
66557+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
66558 if (!buf) {
66559 name = strncpy(tmp, "//enomem", sizeof(tmp));
66560 goto got_name;
66561 }
66562- name = d_path(&file->f_path, buf, PATH_MAX);
66563+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
66564 if (IS_ERR(name)) {
66565 name = strncpy(tmp, "//toolong", sizeof(tmp));
66566 goto got_name;
66567@@ -5931,7 +5931,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
66568 event->parent = parent_event;
66569
66570 event->ns = get_pid_ns(current->nsproxy->pid_ns);
66571- event->id = atomic64_inc_return(&perf_event_id);
66572+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
66573
66574 event->state = PERF_EVENT_STATE_INACTIVE;
66575
66576@@ -6493,10 +6493,10 @@ static void sync_child_event(struct perf_event *child_event,
66577 /*
66578 * Add back the child's count to the parent's count:
66579 */
66580- atomic64_add(child_val, &parent_event->child_count);
66581- atomic64_add(child_event->total_time_enabled,
66582+ atomic64_add_unchecked(child_val, &parent_event->child_count);
66583+ atomic64_add_unchecked(child_event->total_time_enabled,
66584 &parent_event->child_total_time_enabled);
66585- atomic64_add(child_event->total_time_running,
66586+ atomic64_add_unchecked(child_event->total_time_running,
66587 &parent_event->child_total_time_running);
66588
66589 /*
66590diff --git a/kernel/exit.c b/kernel/exit.c
66591index 46ce8da..c648f3a 100644
66592--- a/kernel/exit.c
66593+++ b/kernel/exit.c
66594@@ -59,6 +59,10 @@
66595 #include <asm/pgtable.h>
66596 #include <asm/mmu_context.h>
66597
66598+#ifdef CONFIG_GRKERNSEC
66599+extern rwlock_t grsec_exec_file_lock;
66600+#endif
66601+
66602 static void exit_mm(struct task_struct * tsk);
66603
66604 static void __unhash_process(struct task_struct *p, bool group_dead)
66605@@ -182,6 +186,10 @@ void release_task(struct task_struct * p)
66606 struct task_struct *leader;
66607 int zap_leader;
66608 repeat:
66609+#ifdef CONFIG_NET
66610+ gr_del_task_from_ip_table(p);
66611+#endif
66612+
66613 /* don't need to get the RCU readlock here - the process is dead and
66614 * can't be modifying its own credentials. But shut RCU-lockdep up */
66615 rcu_read_lock();
66616@@ -394,7 +402,7 @@ int allow_signal(int sig)
66617 * know it'll be handled, so that they don't get converted to
66618 * SIGKILL or just silently dropped.
66619 */
66620- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
66621+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
66622 recalc_sigpending();
66623 spin_unlock_irq(&current->sighand->siglock);
66624 return 0;
66625@@ -430,6 +438,17 @@ void daemonize(const char *name, ...)
66626 vsnprintf(current->comm, sizeof(current->comm), name, args);
66627 va_end(args);
66628
66629+#ifdef CONFIG_GRKERNSEC
66630+ write_lock(&grsec_exec_file_lock);
66631+ if (current->exec_file) {
66632+ fput(current->exec_file);
66633+ current->exec_file = NULL;
66634+ }
66635+ write_unlock(&grsec_exec_file_lock);
66636+#endif
66637+
66638+ gr_set_kernel_label(current);
66639+
66640 /*
66641 * If we were started as result of loading a module, close all of the
66642 * user space pages. We don't need them, and if we didn't close them
66643@@ -907,6 +926,8 @@ void do_exit(long code)
66644 struct task_struct *tsk = current;
66645 int group_dead;
66646
66647+ set_fs(USER_DS);
66648+
66649 profile_task_exit(tsk);
66650
66651 WARN_ON(blk_needs_flush_plug(tsk));
66652@@ -923,7 +944,6 @@ void do_exit(long code)
66653 * mm_release()->clear_child_tid() from writing to a user-controlled
66654 * kernel address.
66655 */
66656- set_fs(USER_DS);
66657
66658 ptrace_event(PTRACE_EVENT_EXIT, code);
66659
66660@@ -985,6 +1005,9 @@ void do_exit(long code)
66661 tsk->exit_code = code;
66662 taskstats_exit(tsk, group_dead);
66663
66664+ gr_acl_handle_psacct(tsk, code);
66665+ gr_acl_handle_exit();
66666+
66667 exit_mm(tsk);
66668
66669 if (group_dead)
66670@@ -1101,7 +1124,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
66671 * Take down every thread in the group. This is called by fatal signals
66672 * as well as by sys_exit_group (below).
66673 */
66674-void
66675+__noreturn void
66676 do_group_exit(int exit_code)
66677 {
66678 struct signal_struct *sig = current->signal;
66679diff --git a/kernel/fork.c b/kernel/fork.c
66680index f00e319..c212fbc 100644
66681--- a/kernel/fork.c
66682+++ b/kernel/fork.c
66683@@ -321,7 +321,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
66684 *stackend = STACK_END_MAGIC; /* for overflow detection */
66685
66686 #ifdef CONFIG_CC_STACKPROTECTOR
66687- tsk->stack_canary = get_random_int();
66688+ tsk->stack_canary = pax_get_random_long();
66689 #endif
66690
66691 /*
66692@@ -345,13 +345,78 @@ out:
66693 }
66694
66695 #ifdef CONFIG_MMU
66696+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
66697+{
66698+ struct vm_area_struct *tmp;
66699+ unsigned long charge;
66700+ struct mempolicy *pol;
66701+ struct file *file;
66702+
66703+ charge = 0;
66704+ if (mpnt->vm_flags & VM_ACCOUNT) {
66705+ unsigned long len;
66706+ len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66707+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
66708+ goto fail_nomem;
66709+ charge = len;
66710+ }
66711+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66712+ if (!tmp)
66713+ goto fail_nomem;
66714+ *tmp = *mpnt;
66715+ tmp->vm_mm = mm;
66716+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
66717+ pol = mpol_dup(vma_policy(mpnt));
66718+ if (IS_ERR(pol))
66719+ goto fail_nomem_policy;
66720+ vma_set_policy(tmp, pol);
66721+ if (anon_vma_fork(tmp, mpnt))
66722+ goto fail_nomem_anon_vma_fork;
66723+ tmp->vm_flags &= ~VM_LOCKED;
66724+ tmp->vm_next = tmp->vm_prev = NULL;
66725+ tmp->vm_mirror = NULL;
66726+ file = tmp->vm_file;
66727+ if (file) {
66728+ struct inode *inode = file->f_path.dentry->d_inode;
66729+ struct address_space *mapping = file->f_mapping;
66730+
66731+ get_file(file);
66732+ if (tmp->vm_flags & VM_DENYWRITE)
66733+ atomic_dec(&inode->i_writecount);
66734+ mutex_lock(&mapping->i_mmap_mutex);
66735+ if (tmp->vm_flags & VM_SHARED)
66736+ mapping->i_mmap_writable++;
66737+ flush_dcache_mmap_lock(mapping);
66738+ /* insert tmp into the share list, just after mpnt */
66739+ vma_prio_tree_add(tmp, mpnt);
66740+ flush_dcache_mmap_unlock(mapping);
66741+ mutex_unlock(&mapping->i_mmap_mutex);
66742+ }
66743+
66744+ /*
66745+ * Clear hugetlb-related page reserves for children. This only
66746+ * affects MAP_PRIVATE mappings. Faults generated by the child
66747+ * are not guaranteed to succeed, even if read-only
66748+ */
66749+ if (is_vm_hugetlb_page(tmp))
66750+ reset_vma_resv_huge_pages(tmp);
66751+
66752+ return tmp;
66753+
66754+fail_nomem_anon_vma_fork:
66755+ mpol_put(pol);
66756+fail_nomem_policy:
66757+ kmem_cache_free(vm_area_cachep, tmp);
66758+fail_nomem:
66759+ vm_unacct_memory(charge);
66760+ return NULL;
66761+}
66762+
66763 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66764 {
66765 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
66766 struct rb_node **rb_link, *rb_parent;
66767 int retval;
66768- unsigned long charge;
66769- struct mempolicy *pol;
66770
66771 down_write(&oldmm->mmap_sem);
66772 flush_cache_dup_mm(oldmm);
66773@@ -363,8 +428,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66774 mm->locked_vm = 0;
66775 mm->mmap = NULL;
66776 mm->mmap_cache = NULL;
66777- mm->free_area_cache = oldmm->mmap_base;
66778- mm->cached_hole_size = ~0UL;
66779+ mm->free_area_cache = oldmm->free_area_cache;
66780+ mm->cached_hole_size = oldmm->cached_hole_size;
66781 mm->map_count = 0;
66782 cpumask_clear(mm_cpumask(mm));
66783 mm->mm_rb = RB_ROOT;
66784@@ -380,8 +445,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66785
66786 prev = NULL;
66787 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
66788- struct file *file;
66789-
66790 if (mpnt->vm_flags & VM_DONTCOPY) {
66791 long pages = vma_pages(mpnt);
66792 mm->total_vm -= pages;
66793@@ -389,54 +452,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66794 -pages);
66795 continue;
66796 }
66797- charge = 0;
66798- if (mpnt->vm_flags & VM_ACCOUNT) {
66799- unsigned long len;
66800- len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66801- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
66802- goto fail_nomem;
66803- charge = len;
66804+ tmp = dup_vma(mm, oldmm, mpnt);
66805+ if (!tmp) {
66806+ retval = -ENOMEM;
66807+ goto out;
66808 }
66809- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66810- if (!tmp)
66811- goto fail_nomem;
66812- *tmp = *mpnt;
66813- INIT_LIST_HEAD(&tmp->anon_vma_chain);
66814- pol = mpol_dup(vma_policy(mpnt));
66815- retval = PTR_ERR(pol);
66816- if (IS_ERR(pol))
66817- goto fail_nomem_policy;
66818- vma_set_policy(tmp, pol);
66819- tmp->vm_mm = mm;
66820- if (anon_vma_fork(tmp, mpnt))
66821- goto fail_nomem_anon_vma_fork;
66822- tmp->vm_flags &= ~VM_LOCKED;
66823- tmp->vm_next = tmp->vm_prev = NULL;
66824- file = tmp->vm_file;
66825- if (file) {
66826- struct inode *inode = file->f_path.dentry->d_inode;
66827- struct address_space *mapping = file->f_mapping;
66828-
66829- get_file(file);
66830- if (tmp->vm_flags & VM_DENYWRITE)
66831- atomic_dec(&inode->i_writecount);
66832- mutex_lock(&mapping->i_mmap_mutex);
66833- if (tmp->vm_flags & VM_SHARED)
66834- mapping->i_mmap_writable++;
66835- flush_dcache_mmap_lock(mapping);
66836- /* insert tmp into the share list, just after mpnt */
66837- vma_prio_tree_add(tmp, mpnt);
66838- flush_dcache_mmap_unlock(mapping);
66839- mutex_unlock(&mapping->i_mmap_mutex);
66840- }
66841-
66842- /*
66843- * Clear hugetlb-related page reserves for children. This only
66844- * affects MAP_PRIVATE mappings. Faults generated by the child
66845- * are not guaranteed to succeed, even if read-only
66846- */
66847- if (is_vm_hugetlb_page(tmp))
66848- reset_vma_resv_huge_pages(tmp);
66849
66850 /*
66851 * Link in the new vma and copy the page table entries.
66852@@ -459,9 +479,34 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66853 if (retval)
66854 goto out;
66855
66856- if (file && uprobe_mmap(tmp))
66857+ if (tmp->vm_file && uprobe_mmap(tmp))
66858 goto out;
66859 }
66860+
66861+#ifdef CONFIG_PAX_SEGMEXEC
66862+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
66863+ struct vm_area_struct *mpnt_m;
66864+
66865+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
66866+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
66867+
66868+ if (!mpnt->vm_mirror)
66869+ continue;
66870+
66871+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
66872+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
66873+ mpnt->vm_mirror = mpnt_m;
66874+ } else {
66875+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
66876+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
66877+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
66878+ mpnt->vm_mirror->vm_mirror = mpnt;
66879+ }
66880+ }
66881+ BUG_ON(mpnt_m);
66882+ }
66883+#endif
66884+
66885 /* a new mm has just been created */
66886 arch_dup_mmap(oldmm, mm);
66887 retval = 0;
66888@@ -470,14 +515,6 @@ out:
66889 flush_tlb_mm(oldmm);
66890 up_write(&oldmm->mmap_sem);
66891 return retval;
66892-fail_nomem_anon_vma_fork:
66893- mpol_put(pol);
66894-fail_nomem_policy:
66895- kmem_cache_free(vm_area_cachep, tmp);
66896-fail_nomem:
66897- retval = -ENOMEM;
66898- vm_unacct_memory(charge);
66899- goto out;
66900 }
66901
66902 static inline int mm_alloc_pgd(struct mm_struct *mm)
66903@@ -714,8 +751,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
66904 return ERR_PTR(err);
66905
66906 mm = get_task_mm(task);
66907- if (mm && mm != current->mm &&
66908- !ptrace_may_access(task, mode)) {
66909+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
66910+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
66911 mmput(mm);
66912 mm = ERR_PTR(-EACCES);
66913 }
66914@@ -936,13 +973,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
66915 spin_unlock(&fs->lock);
66916 return -EAGAIN;
66917 }
66918- fs->users++;
66919+ atomic_inc(&fs->users);
66920 spin_unlock(&fs->lock);
66921 return 0;
66922 }
66923 tsk->fs = copy_fs_struct(fs);
66924 if (!tsk->fs)
66925 return -ENOMEM;
66926+ gr_set_chroot_entries(tsk, &tsk->fs->root);
66927 return 0;
66928 }
66929
66930@@ -1209,6 +1247,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66931 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
66932 #endif
66933 retval = -EAGAIN;
66934+
66935+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
66936+
66937 if (atomic_read(&p->real_cred->user->processes) >=
66938 task_rlimit(p, RLIMIT_NPROC)) {
66939 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
66940@@ -1431,6 +1472,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66941 /* Need tasklist lock for parent etc handling! */
66942 write_lock_irq(&tasklist_lock);
66943
66944+ /* synchronizes with gr_set_acls() */
66945+ gr_copy_label(p);
66946+
66947 /* CLONE_PARENT re-uses the old parent */
66948 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
66949 p->real_parent = current->real_parent;
66950@@ -1541,6 +1585,8 @@ bad_fork_cleanup_count:
66951 bad_fork_free:
66952 free_task(p);
66953 fork_out:
66954+ gr_log_forkfail(retval);
66955+
66956 return ERR_PTR(retval);
66957 }
66958
66959@@ -1641,6 +1687,8 @@ long do_fork(unsigned long clone_flags,
66960 if (clone_flags & CLONE_PARENT_SETTID)
66961 put_user(nr, parent_tidptr);
66962
66963+ gr_handle_brute_check();
66964+
66965 if (clone_flags & CLONE_VFORK) {
66966 p->vfork_done = &vfork;
66967 init_completion(&vfork);
66968@@ -1739,7 +1787,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
66969 return 0;
66970
66971 /* don't need lock here; in the worst case we'll do useless copy */
66972- if (fs->users == 1)
66973+ if (atomic_read(&fs->users) == 1)
66974 return 0;
66975
66976 *new_fsp = copy_fs_struct(fs);
66977@@ -1828,7 +1876,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
66978 fs = current->fs;
66979 spin_lock(&fs->lock);
66980 current->fs = new_fs;
66981- if (--fs->users)
66982+ gr_set_chroot_entries(current, &current->fs->root);
66983+ if (atomic_dec_return(&fs->users))
66984 new_fs = NULL;
66985 else
66986 new_fs = fs;
66987diff --git a/kernel/futex.c b/kernel/futex.c
66988index 3717e7b..473c750 100644
66989--- a/kernel/futex.c
66990+++ b/kernel/futex.c
66991@@ -54,6 +54,7 @@
66992 #include <linux/mount.h>
66993 #include <linux/pagemap.h>
66994 #include <linux/syscalls.h>
66995+#include <linux/ptrace.h>
66996 #include <linux/signal.h>
66997 #include <linux/export.h>
66998 #include <linux/magic.h>
66999@@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
67000 struct page *page, *page_head;
67001 int err, ro = 0;
67002
67003+#ifdef CONFIG_PAX_SEGMEXEC
67004+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
67005+ return -EFAULT;
67006+#endif
67007+
67008 /*
67009 * The futex address must be "naturally" aligned.
67010 */
67011@@ -2714,6 +2720,7 @@ static int __init futex_init(void)
67012 {
67013 u32 curval;
67014 int i;
67015+ mm_segment_t oldfs;
67016
67017 /*
67018 * This will fail and we want it. Some arch implementations do
67019@@ -2725,8 +2732,11 @@ static int __init futex_init(void)
67020 * implementation, the non-functional ones will return
67021 * -ENOSYS.
67022 */
67023+ oldfs = get_fs();
67024+ set_fs(USER_DS);
67025 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
67026 futex_cmpxchg_enabled = 1;
67027+ set_fs(oldfs);
67028
67029 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
67030 plist_head_init(&futex_queues[i].chain);
67031diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
67032index 9b22d03..6295b62 100644
67033--- a/kernel/gcov/base.c
67034+++ b/kernel/gcov/base.c
67035@@ -102,11 +102,6 @@ void gcov_enable_events(void)
67036 }
67037
67038 #ifdef CONFIG_MODULES
67039-static inline int within(void *addr, void *start, unsigned long size)
67040-{
67041- return ((addr >= start) && (addr < start + size));
67042-}
67043-
67044 /* Update list and generate events when modules are unloaded. */
67045 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67046 void *data)
67047@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67048 prev = NULL;
67049 /* Remove entries located in module from linked list. */
67050 for (info = gcov_info_head; info; info = info->next) {
67051- if (within(info, mod->module_core, mod->core_size)) {
67052+ if (within_module_core_rw((unsigned long)info, mod)) {
67053 if (prev)
67054 prev->next = info->next;
67055 else
67056diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
67057index 6db7a5e..25b6648 100644
67058--- a/kernel/hrtimer.c
67059+++ b/kernel/hrtimer.c
67060@@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
67061 local_irq_restore(flags);
67062 }
67063
67064-static void run_hrtimer_softirq(struct softirq_action *h)
67065+static void run_hrtimer_softirq(void)
67066 {
67067 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
67068
67069diff --git a/kernel/jump_label.c b/kernel/jump_label.c
67070index 4304919..408c4c0 100644
67071--- a/kernel/jump_label.c
67072+++ b/kernel/jump_label.c
67073@@ -13,6 +13,7 @@
67074 #include <linux/sort.h>
67075 #include <linux/err.h>
67076 #include <linux/static_key.h>
67077+#include <linux/mm.h>
67078
67079 #ifdef HAVE_JUMP_LABEL
67080
67081@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
67082
67083 size = (((unsigned long)stop - (unsigned long)start)
67084 / sizeof(struct jump_entry));
67085+ pax_open_kernel();
67086 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
67087+ pax_close_kernel();
67088 }
67089
67090 static void jump_label_update(struct static_key *key, int enable);
67091@@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
67092 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
67093 struct jump_entry *iter;
67094
67095+ pax_open_kernel();
67096 for (iter = iter_start; iter < iter_stop; iter++) {
67097 if (within_module_init(iter->code, mod))
67098 iter->code = 0;
67099 }
67100+ pax_close_kernel();
67101 }
67102
67103 static int
67104diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
67105index 2169fee..45c017a 100644
67106--- a/kernel/kallsyms.c
67107+++ b/kernel/kallsyms.c
67108@@ -11,6 +11,9 @@
67109 * Changed the compression method from stem compression to "table lookup"
67110 * compression (see scripts/kallsyms.c for a more complete description)
67111 */
67112+#ifdef CONFIG_GRKERNSEC_HIDESYM
67113+#define __INCLUDED_BY_HIDESYM 1
67114+#endif
67115 #include <linux/kallsyms.h>
67116 #include <linux/module.h>
67117 #include <linux/init.h>
67118@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
67119
67120 static inline int is_kernel_inittext(unsigned long addr)
67121 {
67122+ if (system_state != SYSTEM_BOOTING)
67123+ return 0;
67124+
67125 if (addr >= (unsigned long)_sinittext
67126 && addr <= (unsigned long)_einittext)
67127 return 1;
67128 return 0;
67129 }
67130
67131+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67132+#ifdef CONFIG_MODULES
67133+static inline int is_module_text(unsigned long addr)
67134+{
67135+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
67136+ return 1;
67137+
67138+ addr = ktla_ktva(addr);
67139+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
67140+}
67141+#else
67142+static inline int is_module_text(unsigned long addr)
67143+{
67144+ return 0;
67145+}
67146+#endif
67147+#endif
67148+
67149 static inline int is_kernel_text(unsigned long addr)
67150 {
67151 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
67152@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
67153
67154 static inline int is_kernel(unsigned long addr)
67155 {
67156+
67157+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67158+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
67159+ return 1;
67160+
67161+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
67162+#else
67163 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
67164+#endif
67165+
67166 return 1;
67167 return in_gate_area_no_mm(addr);
67168 }
67169
67170 static int is_ksym_addr(unsigned long addr)
67171 {
67172+
67173+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67174+ if (is_module_text(addr))
67175+ return 0;
67176+#endif
67177+
67178 if (all_var)
67179 return is_kernel(addr);
67180
67181@@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
67182
67183 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
67184 {
67185- iter->name[0] = '\0';
67186 iter->nameoff = get_symbol_offset(new_pos);
67187 iter->pos = new_pos;
67188 }
67189@@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
67190 {
67191 struct kallsym_iter *iter = m->private;
67192
67193+#ifdef CONFIG_GRKERNSEC_HIDESYM
67194+ if (current_uid())
67195+ return 0;
67196+#endif
67197+
67198 /* Some debugging symbols have no name. Ignore them. */
67199 if (!iter->name[0])
67200 return 0;
67201@@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
67202 */
67203 type = iter->exported ? toupper(iter->type) :
67204 tolower(iter->type);
67205+
67206 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
67207 type, iter->name, iter->module_name);
67208 } else
67209@@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
67210 struct kallsym_iter *iter;
67211 int ret;
67212
67213- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
67214+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
67215 if (!iter)
67216 return -ENOMEM;
67217 reset_iter(iter, 0);
67218diff --git a/kernel/kexec.c b/kernel/kexec.c
67219index 4e2e472..cd0c7ae 100644
67220--- a/kernel/kexec.c
67221+++ b/kernel/kexec.c
67222@@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
67223 unsigned long flags)
67224 {
67225 struct compat_kexec_segment in;
67226- struct kexec_segment out, __user *ksegments;
67227+ struct kexec_segment out;
67228+ struct kexec_segment __user *ksegments;
67229 unsigned long i, result;
67230
67231 /* Don't allow clients that don't understand the native
67232diff --git a/kernel/kmod.c b/kernel/kmod.c
67233index ff2c7cb..085d7af 100644
67234--- a/kernel/kmod.c
67235+++ b/kernel/kmod.c
67236@@ -66,7 +66,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
67237 kfree(info->argv);
67238 }
67239
67240-static int call_modprobe(char *module_name, int wait)
67241+static int call_modprobe(char *module_name, char *module_param, int wait)
67242 {
67243 static char *envp[] = {
67244 "HOME=/",
67245@@ -75,7 +75,7 @@ static int call_modprobe(char *module_name, int wait)
67246 NULL
67247 };
67248
67249- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
67250+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
67251 if (!argv)
67252 goto out;
67253
67254@@ -87,7 +87,8 @@ static int call_modprobe(char *module_name, int wait)
67255 argv[1] = "-q";
67256 argv[2] = "--";
67257 argv[3] = module_name; /* check free_modprobe_argv() */
67258- argv[4] = NULL;
67259+ argv[4] = module_param;
67260+ argv[5] = NULL;
67261
67262 return call_usermodehelper_fns(modprobe_path, argv, envp,
67263 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
67264@@ -112,9 +113,8 @@ out:
67265 * If module auto-loading support is disabled then this function
67266 * becomes a no-operation.
67267 */
67268-int __request_module(bool wait, const char *fmt, ...)
67269+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
67270 {
67271- va_list args;
67272 char module_name[MODULE_NAME_LEN];
67273 unsigned int max_modprobes;
67274 int ret;
67275@@ -122,9 +122,7 @@ int __request_module(bool wait, const char *fmt, ...)
67276 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
67277 static int kmod_loop_msg;
67278
67279- va_start(args, fmt);
67280- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
67281- va_end(args);
67282+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
67283 if (ret >= MODULE_NAME_LEN)
67284 return -ENAMETOOLONG;
67285
67286@@ -132,6 +130,20 @@ int __request_module(bool wait, const char *fmt, ...)
67287 if (ret)
67288 return ret;
67289
67290+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67291+ if (!current_uid()) {
67292+ /* hack to workaround consolekit/udisks stupidity */
67293+ read_lock(&tasklist_lock);
67294+ if (!strcmp(current->comm, "mount") &&
67295+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
67296+ read_unlock(&tasklist_lock);
67297+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
67298+ return -EPERM;
67299+ }
67300+ read_unlock(&tasklist_lock);
67301+ }
67302+#endif
67303+
67304 /* If modprobe needs a service that is in a module, we get a recursive
67305 * loop. Limit the number of running kmod threads to max_threads/2 or
67306 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
67307@@ -160,11 +172,52 @@ int __request_module(bool wait, const char *fmt, ...)
67308
67309 trace_module_request(module_name, wait, _RET_IP_);
67310
67311- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67312+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67313
67314 atomic_dec(&kmod_concurrent);
67315 return ret;
67316 }
67317+
67318+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
67319+{
67320+ va_list args;
67321+ int ret;
67322+
67323+ va_start(args, fmt);
67324+ ret = ____request_module(wait, module_param, fmt, args);
67325+ va_end(args);
67326+
67327+ return ret;
67328+}
67329+
67330+int __request_module(bool wait, const char *fmt, ...)
67331+{
67332+ va_list args;
67333+ int ret;
67334+
67335+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67336+ if (current_uid()) {
67337+ char module_param[MODULE_NAME_LEN];
67338+
67339+ memset(module_param, 0, sizeof(module_param));
67340+
67341+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
67342+
67343+ va_start(args, fmt);
67344+ ret = ____request_module(wait, module_param, fmt, args);
67345+ va_end(args);
67346+
67347+ return ret;
67348+ }
67349+#endif
67350+
67351+ va_start(args, fmt);
67352+ ret = ____request_module(wait, NULL, fmt, args);
67353+ va_end(args);
67354+
67355+ return ret;
67356+}
67357+
67358 EXPORT_SYMBOL(__request_module);
67359 #endif /* CONFIG_MODULES */
67360
67361@@ -266,7 +319,7 @@ static int wait_for_helper(void *data)
67362 *
67363 * Thus the __user pointer cast is valid here.
67364 */
67365- sys_wait4(pid, (int __user *)&ret, 0, NULL);
67366+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
67367
67368 /*
67369 * If ret is 0, either ____call_usermodehelper failed and the
67370diff --git a/kernel/kprobes.c b/kernel/kprobes.c
67371index c62b854..cb67968 100644
67372--- a/kernel/kprobes.c
67373+++ b/kernel/kprobes.c
67374@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
67375 * kernel image and loaded module images reside. This is required
67376 * so x86_64 can correctly handle the %rip-relative fixups.
67377 */
67378- kip->insns = module_alloc(PAGE_SIZE);
67379+ kip->insns = module_alloc_exec(PAGE_SIZE);
67380 if (!kip->insns) {
67381 kfree(kip);
67382 return NULL;
67383@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
67384 */
67385 if (!list_is_singular(&kip->list)) {
67386 list_del(&kip->list);
67387- module_free(NULL, kip->insns);
67388+ module_free_exec(NULL, kip->insns);
67389 kfree(kip);
67390 }
67391 return 1;
67392@@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
67393 {
67394 int i, err = 0;
67395 unsigned long offset = 0, size = 0;
67396- char *modname, namebuf[128];
67397+ char *modname, namebuf[KSYM_NAME_LEN];
67398 const char *symbol_name;
67399 void *addr;
67400 struct kprobe_blackpoint *kb;
67401@@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
67402 const char *sym = NULL;
67403 unsigned int i = *(loff_t *) v;
67404 unsigned long offset = 0;
67405- char *modname, namebuf[128];
67406+ char *modname, namebuf[KSYM_NAME_LEN];
67407
67408 head = &kprobe_table[i];
67409 preempt_disable();
67410diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
67411index 4e316e1..5501eef 100644
67412--- a/kernel/ksysfs.c
67413+++ b/kernel/ksysfs.c
67414@@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
67415 {
67416 if (count+1 > UEVENT_HELPER_PATH_LEN)
67417 return -ENOENT;
67418+ if (!capable(CAP_SYS_ADMIN))
67419+ return -EPERM;
67420 memcpy(uevent_helper, buf, count);
67421 uevent_helper[count] = '\0';
67422 if (count && uevent_helper[count-1] == '\n')
67423diff --git a/kernel/lockdep.c b/kernel/lockdep.c
67424index ea9ee45..67ebc8f 100644
67425--- a/kernel/lockdep.c
67426+++ b/kernel/lockdep.c
67427@@ -590,6 +590,10 @@ static int static_obj(void *obj)
67428 end = (unsigned long) &_end,
67429 addr = (unsigned long) obj;
67430
67431+#ifdef CONFIG_PAX_KERNEXEC
67432+ start = ktla_ktva(start);
67433+#endif
67434+
67435 /*
67436 * static variable?
67437 */
67438@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
67439 if (!static_obj(lock->key)) {
67440 debug_locks_off();
67441 printk("INFO: trying to register non-static key.\n");
67442+ printk("lock:%pS key:%pS.\n", lock, lock->key);
67443 printk("the code is fine but needs lockdep annotation.\n");
67444 printk("turning off the locking correctness validator.\n");
67445 dump_stack();
67446@@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
67447 if (!class)
67448 return 0;
67449 }
67450- atomic_inc((atomic_t *)&class->ops);
67451+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
67452 if (very_verbose(class)) {
67453 printk("\nacquire class [%p] %s", class->key, class->name);
67454 if (class->name_version > 1)
67455diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
67456index 91c32a0..b2c71c5 100644
67457--- a/kernel/lockdep_proc.c
67458+++ b/kernel/lockdep_proc.c
67459@@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
67460
67461 static void print_name(struct seq_file *m, struct lock_class *class)
67462 {
67463- char str[128];
67464+ char str[KSYM_NAME_LEN];
67465 const char *name = class->name;
67466
67467 if (!name) {
67468diff --git a/kernel/module.c b/kernel/module.c
67469index 4edbd9c..165e780 100644
67470--- a/kernel/module.c
67471+++ b/kernel/module.c
67472@@ -58,6 +58,7 @@
67473 #include <linux/jump_label.h>
67474 #include <linux/pfn.h>
67475 #include <linux/bsearch.h>
67476+#include <linux/grsecurity.h>
67477
67478 #define CREATE_TRACE_POINTS
67479 #include <trace/events/module.h>
67480@@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
67481
67482 /* Bounds of module allocation, for speeding __module_address.
67483 * Protected by module_mutex. */
67484-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
67485+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
67486+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
67487
67488 int register_module_notifier(struct notifier_block * nb)
67489 {
67490@@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
67491 return true;
67492
67493 list_for_each_entry_rcu(mod, &modules, list) {
67494- struct symsearch arr[] = {
67495+ struct symsearch modarr[] = {
67496 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
67497 NOT_GPL_ONLY, false },
67498 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
67499@@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
67500 #endif
67501 };
67502
67503- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
67504+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
67505 return true;
67506 }
67507 return false;
67508@@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
67509 static int percpu_modalloc(struct module *mod,
67510 unsigned long size, unsigned long align)
67511 {
67512- if (align > PAGE_SIZE) {
67513+ if (align-1 >= PAGE_SIZE) {
67514 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
67515 mod->name, align, PAGE_SIZE);
67516 align = PAGE_SIZE;
67517@@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
67518 static ssize_t show_coresize(struct module_attribute *mattr,
67519 struct module_kobject *mk, char *buffer)
67520 {
67521- return sprintf(buffer, "%u\n", mk->mod->core_size);
67522+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
67523 }
67524
67525 static struct module_attribute modinfo_coresize =
67526@@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
67527 static ssize_t show_initsize(struct module_attribute *mattr,
67528 struct module_kobject *mk, char *buffer)
67529 {
67530- return sprintf(buffer, "%u\n", mk->mod->init_size);
67531+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
67532 }
67533
67534 static struct module_attribute modinfo_initsize =
67535@@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
67536 */
67537 #ifdef CONFIG_SYSFS
67538
67539-#ifdef CONFIG_KALLSYMS
67540+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
67541 static inline bool sect_empty(const Elf_Shdr *sect)
67542 {
67543 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
67544@@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
67545
67546 static void unset_module_core_ro_nx(struct module *mod)
67547 {
67548- set_page_attributes(mod->module_core + mod->core_text_size,
67549- mod->module_core + mod->core_size,
67550+ set_page_attributes(mod->module_core_rw,
67551+ mod->module_core_rw + mod->core_size_rw,
67552 set_memory_x);
67553- set_page_attributes(mod->module_core,
67554- mod->module_core + mod->core_ro_size,
67555+ set_page_attributes(mod->module_core_rx,
67556+ mod->module_core_rx + mod->core_size_rx,
67557 set_memory_rw);
67558 }
67559
67560 static void unset_module_init_ro_nx(struct module *mod)
67561 {
67562- set_page_attributes(mod->module_init + mod->init_text_size,
67563- mod->module_init + mod->init_size,
67564+ set_page_attributes(mod->module_init_rw,
67565+ mod->module_init_rw + mod->init_size_rw,
67566 set_memory_x);
67567- set_page_attributes(mod->module_init,
67568- mod->module_init + mod->init_ro_size,
67569+ set_page_attributes(mod->module_init_rx,
67570+ mod->module_init_rx + mod->init_size_rx,
67571 set_memory_rw);
67572 }
67573
67574@@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
67575
67576 mutex_lock(&module_mutex);
67577 list_for_each_entry_rcu(mod, &modules, list) {
67578- if ((mod->module_core) && (mod->core_text_size)) {
67579- set_page_attributes(mod->module_core,
67580- mod->module_core + mod->core_text_size,
67581+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
67582+ set_page_attributes(mod->module_core_rx,
67583+ mod->module_core_rx + mod->core_size_rx,
67584 set_memory_rw);
67585 }
67586- if ((mod->module_init) && (mod->init_text_size)) {
67587- set_page_attributes(mod->module_init,
67588- mod->module_init + mod->init_text_size,
67589+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
67590+ set_page_attributes(mod->module_init_rx,
67591+ mod->module_init_rx + mod->init_size_rx,
67592 set_memory_rw);
67593 }
67594 }
67595@@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
67596
67597 mutex_lock(&module_mutex);
67598 list_for_each_entry_rcu(mod, &modules, list) {
67599- if ((mod->module_core) && (mod->core_text_size)) {
67600- set_page_attributes(mod->module_core,
67601- mod->module_core + mod->core_text_size,
67602+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
67603+ set_page_attributes(mod->module_core_rx,
67604+ mod->module_core_rx + mod->core_size_rx,
67605 set_memory_ro);
67606 }
67607- if ((mod->module_init) && (mod->init_text_size)) {
67608- set_page_attributes(mod->module_init,
67609- mod->module_init + mod->init_text_size,
67610+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
67611+ set_page_attributes(mod->module_init_rx,
67612+ mod->module_init_rx + mod->init_size_rx,
67613 set_memory_ro);
67614 }
67615 }
67616@@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
67617
67618 /* This may be NULL, but that's OK */
67619 unset_module_init_ro_nx(mod);
67620- module_free(mod, mod->module_init);
67621+ module_free(mod, mod->module_init_rw);
67622+ module_free_exec(mod, mod->module_init_rx);
67623 kfree(mod->args);
67624 percpu_modfree(mod);
67625
67626 /* Free lock-classes: */
67627- lockdep_free_key_range(mod->module_core, mod->core_size);
67628+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
67629+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
67630
67631 /* Finally, free the core (containing the module structure) */
67632 unset_module_core_ro_nx(mod);
67633- module_free(mod, mod->module_core);
67634+ module_free_exec(mod, mod->module_core_rx);
67635+ module_free(mod, mod->module_core_rw);
67636
67637 #ifdef CONFIG_MPU
67638 update_protections(current->mm);
67639@@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67640 int ret = 0;
67641 const struct kernel_symbol *ksym;
67642
67643+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67644+ int is_fs_load = 0;
67645+ int register_filesystem_found = 0;
67646+ char *p;
67647+
67648+ p = strstr(mod->args, "grsec_modharden_fs");
67649+ if (p) {
67650+ char *endptr = p + strlen("grsec_modharden_fs");
67651+ /* copy \0 as well */
67652+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
67653+ is_fs_load = 1;
67654+ }
67655+#endif
67656+
67657 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
67658 const char *name = info->strtab + sym[i].st_name;
67659
67660+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67661+ /* it's a real shame this will never get ripped and copied
67662+ upstream! ;(
67663+ */
67664+ if (is_fs_load && !strcmp(name, "register_filesystem"))
67665+ register_filesystem_found = 1;
67666+#endif
67667+
67668 switch (sym[i].st_shndx) {
67669 case SHN_COMMON:
67670 /* We compiled with -fno-common. These are not
67671@@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67672 ksym = resolve_symbol_wait(mod, info, name);
67673 /* Ok if resolved. */
67674 if (ksym && !IS_ERR(ksym)) {
67675+ pax_open_kernel();
67676 sym[i].st_value = ksym->value;
67677+ pax_close_kernel();
67678 break;
67679 }
67680
67681@@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
67682 secbase = (unsigned long)mod_percpu(mod);
67683 else
67684 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
67685+ pax_open_kernel();
67686 sym[i].st_value += secbase;
67687+ pax_close_kernel();
67688 break;
67689 }
67690 }
67691
67692+#ifdef CONFIG_GRKERNSEC_MODHARDEN
67693+ if (is_fs_load && !register_filesystem_found) {
67694+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
67695+ ret = -EPERM;
67696+ }
67697+#endif
67698+
67699 return ret;
67700 }
67701
67702@@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
67703 || s->sh_entsize != ~0UL
67704 || strstarts(sname, ".init"))
67705 continue;
67706- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
67707+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67708+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
67709+ else
67710+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
67711 pr_debug("\t%s\n", sname);
67712 }
67713- switch (m) {
67714- case 0: /* executable */
67715- mod->core_size = debug_align(mod->core_size);
67716- mod->core_text_size = mod->core_size;
67717- break;
67718- case 1: /* RO: text and ro-data */
67719- mod->core_size = debug_align(mod->core_size);
67720- mod->core_ro_size = mod->core_size;
67721- break;
67722- case 3: /* whole core */
67723- mod->core_size = debug_align(mod->core_size);
67724- break;
67725- }
67726 }
67727
67728 pr_debug("Init section allocation order:\n");
67729@@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
67730 || s->sh_entsize != ~0UL
67731 || !strstarts(sname, ".init"))
67732 continue;
67733- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
67734- | INIT_OFFSET_MASK);
67735+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
67736+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
67737+ else
67738+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
67739+ s->sh_entsize |= INIT_OFFSET_MASK;
67740 pr_debug("\t%s\n", sname);
67741 }
67742- switch (m) {
67743- case 0: /* executable */
67744- mod->init_size = debug_align(mod->init_size);
67745- mod->init_text_size = mod->init_size;
67746- break;
67747- case 1: /* RO: text and ro-data */
67748- mod->init_size = debug_align(mod->init_size);
67749- mod->init_ro_size = mod->init_size;
67750- break;
67751- case 3: /* whole init */
67752- mod->init_size = debug_align(mod->init_size);
67753- break;
67754- }
67755 }
67756 }
67757
67758@@ -2266,7 +2284,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67759
67760 /* Put symbol section at end of init part of module. */
67761 symsect->sh_flags |= SHF_ALLOC;
67762- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
67763+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
67764 info->index.sym) | INIT_OFFSET_MASK;
67765 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
67766
67767@@ -2281,13 +2299,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67768 }
67769
67770 /* Append room for core symbols at end of core part. */
67771- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
67772- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
67773- mod->core_size += strtab_size;
67774+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
67775+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
67776+ mod->core_size_rx += strtab_size;
67777
67778 /* Put string table section at end of init part of module. */
67779 strsect->sh_flags |= SHF_ALLOC;
67780- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
67781+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
67782 info->index.str) | INIT_OFFSET_MASK;
67783 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
67784 }
67785@@ -2305,12 +2323,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67786 /* Make sure we get permanent strtab: don't use info->strtab. */
67787 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
67788
67789+ pax_open_kernel();
67790+
67791 /* Set types up while we still have access to sections. */
67792 for (i = 0; i < mod->num_symtab; i++)
67793 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
67794
67795- mod->core_symtab = dst = mod->module_core + info->symoffs;
67796- mod->core_strtab = s = mod->module_core + info->stroffs;
67797+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
67798+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
67799 src = mod->symtab;
67800 *dst = *src;
67801 *s++ = 0;
67802@@ -2323,6 +2343,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67803 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
67804 }
67805 mod->core_num_syms = ndst;
67806+
67807+ pax_close_kernel();
67808 }
67809 #else
67810 static inline void layout_symtab(struct module *mod, struct load_info *info)
67811@@ -2356,17 +2378,33 @@ void * __weak module_alloc(unsigned long size)
67812 return size == 0 ? NULL : vmalloc_exec(size);
67813 }
67814
67815-static void *module_alloc_update_bounds(unsigned long size)
67816+static void *module_alloc_update_bounds_rw(unsigned long size)
67817 {
67818 void *ret = module_alloc(size);
67819
67820 if (ret) {
67821 mutex_lock(&module_mutex);
67822 /* Update module bounds. */
67823- if ((unsigned long)ret < module_addr_min)
67824- module_addr_min = (unsigned long)ret;
67825- if ((unsigned long)ret + size > module_addr_max)
67826- module_addr_max = (unsigned long)ret + size;
67827+ if ((unsigned long)ret < module_addr_min_rw)
67828+ module_addr_min_rw = (unsigned long)ret;
67829+ if ((unsigned long)ret + size > module_addr_max_rw)
67830+ module_addr_max_rw = (unsigned long)ret + size;
67831+ mutex_unlock(&module_mutex);
67832+ }
67833+ return ret;
67834+}
67835+
67836+static void *module_alloc_update_bounds_rx(unsigned long size)
67837+{
67838+ void *ret = module_alloc_exec(size);
67839+
67840+ if (ret) {
67841+ mutex_lock(&module_mutex);
67842+ /* Update module bounds. */
67843+ if ((unsigned long)ret < module_addr_min_rx)
67844+ module_addr_min_rx = (unsigned long)ret;
67845+ if ((unsigned long)ret + size > module_addr_max_rx)
67846+ module_addr_max_rx = (unsigned long)ret + size;
67847 mutex_unlock(&module_mutex);
67848 }
67849 return ret;
67850@@ -2544,8 +2582,14 @@ static struct module *setup_load_info(struct load_info *info)
67851 static int check_modinfo(struct module *mod, struct load_info *info)
67852 {
67853 const char *modmagic = get_modinfo(info, "vermagic");
67854+ const char *license = get_modinfo(info, "license");
67855 int err;
67856
67857+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
67858+ if (!license || !license_is_gpl_compatible(license))
67859+ return -ENOEXEC;
67860+#endif
67861+
67862 /* This is allowed: modprobe --force will invalidate it. */
67863 if (!modmagic) {
67864 err = try_to_force_load(mod, "bad vermagic");
67865@@ -2568,7 +2612,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
67866 }
67867
67868 /* Set up license info based on the info section */
67869- set_license(mod, get_modinfo(info, "license"));
67870+ set_license(mod, license);
67871
67872 return 0;
67873 }
67874@@ -2662,7 +2706,7 @@ static int move_module(struct module *mod, struct load_info *info)
67875 void *ptr;
67876
67877 /* Do the allocs. */
67878- ptr = module_alloc_update_bounds(mod->core_size);
67879+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
67880 /*
67881 * The pointer to this block is stored in the module structure
67882 * which is inside the block. Just mark it as not being a
67883@@ -2672,23 +2716,50 @@ static int move_module(struct module *mod, struct load_info *info)
67884 if (!ptr)
67885 return -ENOMEM;
67886
67887- memset(ptr, 0, mod->core_size);
67888- mod->module_core = ptr;
67889+ memset(ptr, 0, mod->core_size_rw);
67890+ mod->module_core_rw = ptr;
67891
67892- ptr = module_alloc_update_bounds(mod->init_size);
67893+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
67894 /*
67895 * The pointer to this block is stored in the module structure
67896 * which is inside the block. This block doesn't need to be
67897 * scanned as it contains data and code that will be freed
67898 * after the module is initialized.
67899 */
67900- kmemleak_ignore(ptr);
67901- if (!ptr && mod->init_size) {
67902- module_free(mod, mod->module_core);
67903+ kmemleak_not_leak(ptr);
67904+ if (!ptr && mod->init_size_rw) {
67905+ module_free(mod, mod->module_core_rw);
67906 return -ENOMEM;
67907 }
67908- memset(ptr, 0, mod->init_size);
67909- mod->module_init = ptr;
67910+ memset(ptr, 0, mod->init_size_rw);
67911+ mod->module_init_rw = ptr;
67912+
67913+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
67914+ kmemleak_not_leak(ptr);
67915+ if (!ptr) {
67916+ module_free(mod, mod->module_init_rw);
67917+ module_free(mod, mod->module_core_rw);
67918+ return -ENOMEM;
67919+ }
67920+
67921+ pax_open_kernel();
67922+ memset(ptr, 0, mod->core_size_rx);
67923+ pax_close_kernel();
67924+ mod->module_core_rx = ptr;
67925+
67926+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
67927+ kmemleak_not_leak(ptr);
67928+ if (!ptr && mod->init_size_rx) {
67929+ module_free_exec(mod, mod->module_core_rx);
67930+ module_free(mod, mod->module_init_rw);
67931+ module_free(mod, mod->module_core_rw);
67932+ return -ENOMEM;
67933+ }
67934+
67935+ pax_open_kernel();
67936+ memset(ptr, 0, mod->init_size_rx);
67937+ pax_close_kernel();
67938+ mod->module_init_rx = ptr;
67939
67940 /* Transfer each section which specifies SHF_ALLOC */
67941 pr_debug("final section addresses:\n");
67942@@ -2699,16 +2770,45 @@ static int move_module(struct module *mod, struct load_info *info)
67943 if (!(shdr->sh_flags & SHF_ALLOC))
67944 continue;
67945
67946- if (shdr->sh_entsize & INIT_OFFSET_MASK)
67947- dest = mod->module_init
67948- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67949- else
67950- dest = mod->module_core + shdr->sh_entsize;
67951+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
67952+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67953+ dest = mod->module_init_rw
67954+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67955+ else
67956+ dest = mod->module_init_rx
67957+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67958+ } else {
67959+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67960+ dest = mod->module_core_rw + shdr->sh_entsize;
67961+ else
67962+ dest = mod->module_core_rx + shdr->sh_entsize;
67963+ }
67964+
67965+ if (shdr->sh_type != SHT_NOBITS) {
67966+
67967+#ifdef CONFIG_PAX_KERNEXEC
67968+#ifdef CONFIG_X86_64
67969+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
67970+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
67971+#endif
67972+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
67973+ pax_open_kernel();
67974+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67975+ pax_close_kernel();
67976+ } else
67977+#endif
67978
67979- if (shdr->sh_type != SHT_NOBITS)
67980 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67981+ }
67982 /* Update sh_addr to point to copy in image. */
67983- shdr->sh_addr = (unsigned long)dest;
67984+
67985+#ifdef CONFIG_PAX_KERNEXEC
67986+ if (shdr->sh_flags & SHF_EXECINSTR)
67987+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
67988+ else
67989+#endif
67990+
67991+ shdr->sh_addr = (unsigned long)dest;
67992 pr_debug("\t0x%lx %s\n",
67993 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
67994 }
67995@@ -2759,12 +2859,12 @@ static void flush_module_icache(const struct module *mod)
67996 * Do it before processing of module parameters, so the module
67997 * can provide parameter accessor functions of its own.
67998 */
67999- if (mod->module_init)
68000- flush_icache_range((unsigned long)mod->module_init,
68001- (unsigned long)mod->module_init
68002- + mod->init_size);
68003- flush_icache_range((unsigned long)mod->module_core,
68004- (unsigned long)mod->module_core + mod->core_size);
68005+ if (mod->module_init_rx)
68006+ flush_icache_range((unsigned long)mod->module_init_rx,
68007+ (unsigned long)mod->module_init_rx
68008+ + mod->init_size_rx);
68009+ flush_icache_range((unsigned long)mod->module_core_rx,
68010+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
68011
68012 set_fs(old_fs);
68013 }
68014@@ -2834,8 +2934,10 @@ out:
68015 static void module_deallocate(struct module *mod, struct load_info *info)
68016 {
68017 percpu_modfree(mod);
68018- module_free(mod, mod->module_init);
68019- module_free(mod, mod->module_core);
68020+ module_free_exec(mod, mod->module_init_rx);
68021+ module_free_exec(mod, mod->module_core_rx);
68022+ module_free(mod, mod->module_init_rw);
68023+ module_free(mod, mod->module_core_rw);
68024 }
68025
68026 int __weak module_finalize(const Elf_Ehdr *hdr,
68027@@ -2848,7 +2950,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
68028 static int post_relocation(struct module *mod, const struct load_info *info)
68029 {
68030 /* Sort exception table now relocations are done. */
68031+ pax_open_kernel();
68032 sort_extable(mod->extable, mod->extable + mod->num_exentries);
68033+ pax_close_kernel();
68034
68035 /* Copy relocated percpu area over. */
68036 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
68037@@ -2899,9 +3003,38 @@ static struct module *load_module(void __user *umod,
68038 if (err)
68039 goto free_unload;
68040
68041+ /* Now copy in args */
68042+ mod->args = strndup_user(uargs, ~0UL >> 1);
68043+ if (IS_ERR(mod->args)) {
68044+ err = PTR_ERR(mod->args);
68045+ goto free_unload;
68046+ }
68047+
68048 /* Set up MODINFO_ATTR fields */
68049 setup_modinfo(mod, &info);
68050
68051+#ifdef CONFIG_GRKERNSEC_MODHARDEN
68052+ {
68053+ char *p, *p2;
68054+
68055+ if (strstr(mod->args, "grsec_modharden_netdev")) {
68056+ 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);
68057+ err = -EPERM;
68058+ goto free_modinfo;
68059+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
68060+ p += strlen("grsec_modharden_normal");
68061+ p2 = strstr(p, "_");
68062+ if (p2) {
68063+ *p2 = '\0';
68064+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
68065+ *p2 = '_';
68066+ }
68067+ err = -EPERM;
68068+ goto free_modinfo;
68069+ }
68070+ }
68071+#endif
68072+
68073 /* Fix up syms, so that st_value is a pointer to location. */
68074 err = simplify_symbols(mod, &info);
68075 if (err < 0)
68076@@ -2917,13 +3050,6 @@ static struct module *load_module(void __user *umod,
68077
68078 flush_module_icache(mod);
68079
68080- /* Now copy in args */
68081- mod->args = strndup_user(uargs, ~0UL >> 1);
68082- if (IS_ERR(mod->args)) {
68083- err = PTR_ERR(mod->args);
68084- goto free_arch_cleanup;
68085- }
68086-
68087 /* Mark state as coming so strong_try_module_get() ignores us. */
68088 mod->state = MODULE_STATE_COMING;
68089
68090@@ -2981,11 +3107,10 @@ static struct module *load_module(void __user *umod,
68091 unlock:
68092 mutex_unlock(&module_mutex);
68093 synchronize_sched();
68094- kfree(mod->args);
68095- free_arch_cleanup:
68096 module_arch_cleanup(mod);
68097 free_modinfo:
68098 free_modinfo(mod);
68099+ kfree(mod->args);
68100 free_unload:
68101 module_unload_free(mod);
68102 free_module:
68103@@ -3026,16 +3151,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68104 MODULE_STATE_COMING, mod);
68105
68106 /* Set RO and NX regions for core */
68107- set_section_ro_nx(mod->module_core,
68108- mod->core_text_size,
68109- mod->core_ro_size,
68110- mod->core_size);
68111+ set_section_ro_nx(mod->module_core_rx,
68112+ mod->core_size_rx,
68113+ mod->core_size_rx,
68114+ mod->core_size_rx);
68115
68116 /* Set RO and NX regions for init */
68117- set_section_ro_nx(mod->module_init,
68118- mod->init_text_size,
68119- mod->init_ro_size,
68120- mod->init_size);
68121+ set_section_ro_nx(mod->module_init_rx,
68122+ mod->init_size_rx,
68123+ mod->init_size_rx,
68124+ mod->init_size_rx);
68125
68126 do_mod_ctors(mod);
68127 /* Start the module */
68128@@ -3081,11 +3206,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68129 mod->strtab = mod->core_strtab;
68130 #endif
68131 unset_module_init_ro_nx(mod);
68132- module_free(mod, mod->module_init);
68133- mod->module_init = NULL;
68134- mod->init_size = 0;
68135- mod->init_ro_size = 0;
68136- mod->init_text_size = 0;
68137+ module_free(mod, mod->module_init_rw);
68138+ module_free_exec(mod, mod->module_init_rx);
68139+ mod->module_init_rw = NULL;
68140+ mod->module_init_rx = NULL;
68141+ mod->init_size_rw = 0;
68142+ mod->init_size_rx = 0;
68143 mutex_unlock(&module_mutex);
68144
68145 return 0;
68146@@ -3116,10 +3242,16 @@ static const char *get_ksymbol(struct module *mod,
68147 unsigned long nextval;
68148
68149 /* At worse, next value is at end of module */
68150- if (within_module_init(addr, mod))
68151- nextval = (unsigned long)mod->module_init+mod->init_text_size;
68152+ if (within_module_init_rx(addr, mod))
68153+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
68154+ else if (within_module_init_rw(addr, mod))
68155+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
68156+ else if (within_module_core_rx(addr, mod))
68157+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
68158+ else if (within_module_core_rw(addr, mod))
68159+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
68160 else
68161- nextval = (unsigned long)mod->module_core+mod->core_text_size;
68162+ return NULL;
68163
68164 /* Scan for closest preceding symbol, and next symbol. (ELF
68165 starts real symbols at 1). */
68166@@ -3354,7 +3486,7 @@ static int m_show(struct seq_file *m, void *p)
68167 char buf[8];
68168
68169 seq_printf(m, "%s %u",
68170- mod->name, mod->init_size + mod->core_size);
68171+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
68172 print_unload_info(m, mod);
68173
68174 /* Informative for users. */
68175@@ -3363,7 +3495,7 @@ static int m_show(struct seq_file *m, void *p)
68176 mod->state == MODULE_STATE_COMING ? "Loading":
68177 "Live");
68178 /* Used by oprofile and other similar tools. */
68179- seq_printf(m, " 0x%pK", mod->module_core);
68180+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
68181
68182 /* Taints info */
68183 if (mod->taints)
68184@@ -3399,7 +3531,17 @@ static const struct file_operations proc_modules_operations = {
68185
68186 static int __init proc_modules_init(void)
68187 {
68188+#ifndef CONFIG_GRKERNSEC_HIDESYM
68189+#ifdef CONFIG_GRKERNSEC_PROC_USER
68190+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68191+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68192+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
68193+#else
68194 proc_create("modules", 0, NULL, &proc_modules_operations);
68195+#endif
68196+#else
68197+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68198+#endif
68199 return 0;
68200 }
68201 module_init(proc_modules_init);
68202@@ -3458,12 +3600,12 @@ struct module *__module_address(unsigned long addr)
68203 {
68204 struct module *mod;
68205
68206- if (addr < module_addr_min || addr > module_addr_max)
68207+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
68208+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
68209 return NULL;
68210
68211 list_for_each_entry_rcu(mod, &modules, list)
68212- if (within_module_core(addr, mod)
68213- || within_module_init(addr, mod))
68214+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
68215 return mod;
68216 return NULL;
68217 }
68218@@ -3497,11 +3639,20 @@ bool is_module_text_address(unsigned long addr)
68219 */
68220 struct module *__module_text_address(unsigned long addr)
68221 {
68222- struct module *mod = __module_address(addr);
68223+ struct module *mod;
68224+
68225+#ifdef CONFIG_X86_32
68226+ addr = ktla_ktva(addr);
68227+#endif
68228+
68229+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
68230+ return NULL;
68231+
68232+ mod = __module_address(addr);
68233+
68234 if (mod) {
68235 /* Make sure it's within the text section. */
68236- if (!within(addr, mod->module_init, mod->init_text_size)
68237- && !within(addr, mod->module_core, mod->core_text_size))
68238+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
68239 mod = NULL;
68240 }
68241 return mod;
68242diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
68243index 7e3443f..b2a1e6b 100644
68244--- a/kernel/mutex-debug.c
68245+++ b/kernel/mutex-debug.c
68246@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
68247 }
68248
68249 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68250- struct thread_info *ti)
68251+ struct task_struct *task)
68252 {
68253 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
68254
68255 /* Mark the current thread as blocked on the lock: */
68256- ti->task->blocked_on = waiter;
68257+ task->blocked_on = waiter;
68258 }
68259
68260 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68261- struct thread_info *ti)
68262+ struct task_struct *task)
68263 {
68264 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
68265- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
68266- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
68267- ti->task->blocked_on = NULL;
68268+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
68269+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
68270+ task->blocked_on = NULL;
68271
68272 list_del_init(&waiter->list);
68273 waiter->task = NULL;
68274diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
68275index 0799fd3..d06ae3b 100644
68276--- a/kernel/mutex-debug.h
68277+++ b/kernel/mutex-debug.h
68278@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
68279 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
68280 extern void debug_mutex_add_waiter(struct mutex *lock,
68281 struct mutex_waiter *waiter,
68282- struct thread_info *ti);
68283+ struct task_struct *task);
68284 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68285- struct thread_info *ti);
68286+ struct task_struct *task);
68287 extern void debug_mutex_unlock(struct mutex *lock);
68288 extern void debug_mutex_init(struct mutex *lock, const char *name,
68289 struct lock_class_key *key);
68290diff --git a/kernel/mutex.c b/kernel/mutex.c
68291index a307cc9..27fd2e9 100644
68292--- a/kernel/mutex.c
68293+++ b/kernel/mutex.c
68294@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68295 spin_lock_mutex(&lock->wait_lock, flags);
68296
68297 debug_mutex_lock_common(lock, &waiter);
68298- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
68299+ debug_mutex_add_waiter(lock, &waiter, task);
68300
68301 /* add waiting tasks to the end of the waitqueue (FIFO): */
68302 list_add_tail(&waiter.list, &lock->wait_list);
68303@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68304 * TASK_UNINTERRUPTIBLE case.)
68305 */
68306 if (unlikely(signal_pending_state(state, task))) {
68307- mutex_remove_waiter(lock, &waiter,
68308- task_thread_info(task));
68309+ mutex_remove_waiter(lock, &waiter, task);
68310 mutex_release(&lock->dep_map, 1, ip);
68311 spin_unlock_mutex(&lock->wait_lock, flags);
68312
68313@@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68314 done:
68315 lock_acquired(&lock->dep_map, ip);
68316 /* got the lock - rejoice! */
68317- mutex_remove_waiter(lock, &waiter, current_thread_info());
68318+ mutex_remove_waiter(lock, &waiter, task);
68319 mutex_set_owner(lock);
68320
68321 /* set it to 0 if there are no waiters left: */
68322diff --git a/kernel/panic.c b/kernel/panic.c
68323index d2a5f4e..5edc1d9 100644
68324--- a/kernel/panic.c
68325+++ b/kernel/panic.c
68326@@ -75,6 +75,14 @@ void panic(const char *fmt, ...)
68327 int state = 0;
68328
68329 /*
68330+ * Disable local interrupts. This will prevent panic_smp_self_stop
68331+ * from deadlocking the first cpu that invokes the panic, since
68332+ * there is nothing to prevent an interrupt handler (that runs
68333+ * after the panic_lock is acquired) from invoking panic again.
68334+ */
68335+ local_irq_disable();
68336+
68337+ /*
68338 * It's possible to come here directly from a panic-assertion and
68339 * not have preempt disabled. Some functions called from here want
68340 * preempt to be disabled. No point enabling it later though...
68341@@ -402,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
68342 const char *board;
68343
68344 printk(KERN_WARNING "------------[ cut here ]------------\n");
68345- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
68346+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
68347 board = dmi_get_system_info(DMI_PRODUCT_NAME);
68348 if (board)
68349 printk(KERN_WARNING "Hardware name: %s\n", board);
68350@@ -457,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
68351 */
68352 void __stack_chk_fail(void)
68353 {
68354- panic("stack-protector: Kernel stack is corrupted in: %p\n",
68355+ dump_stack();
68356+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
68357 __builtin_return_address(0));
68358 }
68359 EXPORT_SYMBOL(__stack_chk_fail);
68360diff --git a/kernel/pid.c b/kernel/pid.c
68361index e86b291a..e8b0fb5 100644
68362--- a/kernel/pid.c
68363+++ b/kernel/pid.c
68364@@ -33,6 +33,7 @@
68365 #include <linux/rculist.h>
68366 #include <linux/bootmem.h>
68367 #include <linux/hash.h>
68368+#include <linux/security.h>
68369 #include <linux/pid_namespace.h>
68370 #include <linux/init_task.h>
68371 #include <linux/syscalls.h>
68372@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
68373
68374 int pid_max = PID_MAX_DEFAULT;
68375
68376-#define RESERVED_PIDS 300
68377+#define RESERVED_PIDS 500
68378
68379 int pid_max_min = RESERVED_PIDS + 1;
68380 int pid_max_max = PID_MAX_LIMIT;
68381@@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
68382 */
68383 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
68384 {
68385+ struct task_struct *task;
68386+
68387 rcu_lockdep_assert(rcu_read_lock_held(),
68388 "find_task_by_pid_ns() needs rcu_read_lock()"
68389 " protection");
68390- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68391+
68392+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68393+
68394+ if (gr_pid_is_chrooted(task))
68395+ return NULL;
68396+
68397+ return task;
68398 }
68399
68400 struct task_struct *find_task_by_vpid(pid_t vnr)
68401@@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
68402 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
68403 }
68404
68405+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
68406+{
68407+ rcu_lockdep_assert(rcu_read_lock_held(),
68408+ "find_task_by_pid_ns() needs rcu_read_lock()"
68409+ " protection");
68410+ return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
68411+}
68412+
68413 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
68414 {
68415 struct pid *pid;
68416diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
68417index 125cb67..a4d1c30 100644
68418--- a/kernel/posix-cpu-timers.c
68419+++ b/kernel/posix-cpu-timers.c
68420@@ -6,6 +6,7 @@
68421 #include <linux/posix-timers.h>
68422 #include <linux/errno.h>
68423 #include <linux/math64.h>
68424+#include <linux/security.h>
68425 #include <asm/uaccess.h>
68426 #include <linux/kernel_stat.h>
68427 #include <trace/events/timer.h>
68428@@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
68429
68430 static __init int init_posix_cpu_timers(void)
68431 {
68432- struct k_clock process = {
68433+ static struct k_clock process = {
68434 .clock_getres = process_cpu_clock_getres,
68435 .clock_get = process_cpu_clock_get,
68436 .timer_create = process_cpu_timer_create,
68437 .nsleep = process_cpu_nsleep,
68438 .nsleep_restart = process_cpu_nsleep_restart,
68439 };
68440- struct k_clock thread = {
68441+ static struct k_clock thread = {
68442 .clock_getres = thread_cpu_clock_getres,
68443 .clock_get = thread_cpu_clock_get,
68444 .timer_create = thread_cpu_timer_create,
68445diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
68446index 69185ae..cc2847a 100644
68447--- a/kernel/posix-timers.c
68448+++ b/kernel/posix-timers.c
68449@@ -43,6 +43,7 @@
68450 #include <linux/idr.h>
68451 #include <linux/posix-clock.h>
68452 #include <linux/posix-timers.h>
68453+#include <linux/grsecurity.h>
68454 #include <linux/syscalls.h>
68455 #include <linux/wait.h>
68456 #include <linux/workqueue.h>
68457@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
68458 * which we beg off on and pass to do_sys_settimeofday().
68459 */
68460
68461-static struct k_clock posix_clocks[MAX_CLOCKS];
68462+static struct k_clock *posix_clocks[MAX_CLOCKS];
68463
68464 /*
68465 * These ones are defined below.
68466@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
68467 */
68468 static __init int init_posix_timers(void)
68469 {
68470- struct k_clock clock_realtime = {
68471+ static struct k_clock clock_realtime = {
68472 .clock_getres = hrtimer_get_res,
68473 .clock_get = posix_clock_realtime_get,
68474 .clock_set = posix_clock_realtime_set,
68475@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
68476 .timer_get = common_timer_get,
68477 .timer_del = common_timer_del,
68478 };
68479- struct k_clock clock_monotonic = {
68480+ static struct k_clock clock_monotonic = {
68481 .clock_getres = hrtimer_get_res,
68482 .clock_get = posix_ktime_get_ts,
68483 .nsleep = common_nsleep,
68484@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
68485 .timer_get = common_timer_get,
68486 .timer_del = common_timer_del,
68487 };
68488- struct k_clock clock_monotonic_raw = {
68489+ static struct k_clock clock_monotonic_raw = {
68490 .clock_getres = hrtimer_get_res,
68491 .clock_get = posix_get_monotonic_raw,
68492 };
68493- struct k_clock clock_realtime_coarse = {
68494+ static struct k_clock clock_realtime_coarse = {
68495 .clock_getres = posix_get_coarse_res,
68496 .clock_get = posix_get_realtime_coarse,
68497 };
68498- struct k_clock clock_monotonic_coarse = {
68499+ static struct k_clock clock_monotonic_coarse = {
68500 .clock_getres = posix_get_coarse_res,
68501 .clock_get = posix_get_monotonic_coarse,
68502 };
68503- struct k_clock clock_boottime = {
68504+ static struct k_clock clock_boottime = {
68505 .clock_getres = hrtimer_get_res,
68506 .clock_get = posix_get_boottime,
68507 .nsleep = common_nsleep,
68508@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
68509 return;
68510 }
68511
68512- posix_clocks[clock_id] = *new_clock;
68513+ posix_clocks[clock_id] = new_clock;
68514 }
68515 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
68516
68517@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
68518 return (id & CLOCKFD_MASK) == CLOCKFD ?
68519 &clock_posix_dynamic : &clock_posix_cpu;
68520
68521- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
68522+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
68523 return NULL;
68524- return &posix_clocks[id];
68525+ return posix_clocks[id];
68526 }
68527
68528 static int common_timer_create(struct k_itimer *new_timer)
68529@@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
68530 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
68531 return -EFAULT;
68532
68533+ /* only the CLOCK_REALTIME clock can be set, all other clocks
68534+ have their clock_set fptr set to a nosettime dummy function
68535+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
68536+ call common_clock_set, which calls do_sys_settimeofday, which
68537+ we hook
68538+ */
68539+
68540 return kc->clock_set(which_clock, &new_tp);
68541 }
68542
68543diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
68544index d523593..68197a4 100644
68545--- a/kernel/power/poweroff.c
68546+++ b/kernel/power/poweroff.c
68547@@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
68548 .enable_mask = SYSRQ_ENABLE_BOOT,
68549 };
68550
68551-static int pm_sysrq_init(void)
68552+static int __init pm_sysrq_init(void)
68553 {
68554 register_sysrq_key('o', &sysrq_poweroff_op);
68555 return 0;
68556diff --git a/kernel/power/process.c b/kernel/power/process.c
68557index 19db29f..33b52b6 100644
68558--- a/kernel/power/process.c
68559+++ b/kernel/power/process.c
68560@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
68561 u64 elapsed_csecs64;
68562 unsigned int elapsed_csecs;
68563 bool wakeup = false;
68564+ bool timedout = false;
68565
68566 do_gettimeofday(&start);
68567
68568@@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
68569
68570 while (true) {
68571 todo = 0;
68572+ if (time_after(jiffies, end_time))
68573+ timedout = true;
68574 read_lock(&tasklist_lock);
68575 do_each_thread(g, p) {
68576 if (p == current || !freeze_task(p))
68577@@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
68578 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
68579 * transition can't race with task state testing here.
68580 */
68581- if (!task_is_stopped_or_traced(p) &&
68582- !freezer_should_skip(p))
68583+ if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
68584 todo++;
68585+ if (timedout) {
68586+ printk(KERN_ERR "Task refusing to freeze:\n");
68587+ sched_show_task(p);
68588+ }
68589+ }
68590 } while_each_thread(g, p);
68591 read_unlock(&tasklist_lock);
68592
68593@@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
68594 todo += wq_busy;
68595 }
68596
68597- if (!todo || time_after(jiffies, end_time))
68598+ if (!todo || timedout)
68599 break;
68600
68601 if (pm_wakeup_pending()) {
68602diff --git a/kernel/printk.c b/kernel/printk.c
68603index 146827f..a501fec 100644
68604--- a/kernel/printk.c
68605+++ b/kernel/printk.c
68606@@ -782,6 +782,11 @@ static int check_syslog_permissions(int type, bool from_file)
68607 if (from_file && type != SYSLOG_ACTION_OPEN)
68608 return 0;
68609
68610+#ifdef CONFIG_GRKERNSEC_DMESG
68611+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
68612+ return -EPERM;
68613+#endif
68614+
68615 if (syslog_action_restricted(type)) {
68616 if (capable(CAP_SYSLOG))
68617 return 0;
68618diff --git a/kernel/profile.c b/kernel/profile.c
68619index 76b8e77..a2930e8 100644
68620--- a/kernel/profile.c
68621+++ b/kernel/profile.c
68622@@ -39,7 +39,7 @@ struct profile_hit {
68623 /* Oprofile timer tick hook */
68624 static int (*timer_hook)(struct pt_regs *) __read_mostly;
68625
68626-static atomic_t *prof_buffer;
68627+static atomic_unchecked_t *prof_buffer;
68628 static unsigned long prof_len, prof_shift;
68629
68630 int prof_on __read_mostly;
68631@@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
68632 hits[i].pc = 0;
68633 continue;
68634 }
68635- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
68636+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
68637 hits[i].hits = hits[i].pc = 0;
68638 }
68639 }
68640@@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
68641 * Add the current hit(s) and flush the write-queue out
68642 * to the global buffer:
68643 */
68644- atomic_add(nr_hits, &prof_buffer[pc]);
68645+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
68646 for (i = 0; i < NR_PROFILE_HIT; ++i) {
68647- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
68648+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
68649 hits[i].pc = hits[i].hits = 0;
68650 }
68651 out:
68652@@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
68653 {
68654 unsigned long pc;
68655 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
68656- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68657+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
68658 }
68659 #endif /* !CONFIG_SMP */
68660
68661@@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
68662 return -EFAULT;
68663 buf++; p++; count--; read++;
68664 }
68665- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
68666+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
68667 if (copy_to_user(buf, (void *)pnt, count))
68668 return -EFAULT;
68669 read += count;
68670@@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
68671 }
68672 #endif
68673 profile_discard_flip_buffers();
68674- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
68675+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
68676 return count;
68677 }
68678
68679diff --git a/kernel/ptrace.c b/kernel/ptrace.c
68680index a232bb5..2a65ef9 100644
68681--- a/kernel/ptrace.c
68682+++ b/kernel/ptrace.c
68683@@ -279,7 +279,7 @@ static int ptrace_attach(struct task_struct *task, long request,
68684
68685 if (seize)
68686 flags |= PT_SEIZED;
68687- if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
68688+ if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
68689 flags |= PT_PTRACE_CAP;
68690 task->ptrace = flags;
68691
68692@@ -486,7 +486,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
68693 break;
68694 return -EIO;
68695 }
68696- if (copy_to_user(dst, buf, retval))
68697+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
68698 return -EFAULT;
68699 copied += retval;
68700 src += retval;
68701@@ -671,7 +671,7 @@ int ptrace_request(struct task_struct *child, long request,
68702 bool seized = child->ptrace & PT_SEIZED;
68703 int ret = -EIO;
68704 siginfo_t siginfo, *si;
68705- void __user *datavp = (void __user *) data;
68706+ void __user *datavp = (__force void __user *) data;
68707 unsigned long __user *datalp = datavp;
68708 unsigned long flags;
68709
68710@@ -873,14 +873,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
68711 goto out;
68712 }
68713
68714+ if (gr_handle_ptrace(child, request)) {
68715+ ret = -EPERM;
68716+ goto out_put_task_struct;
68717+ }
68718+
68719 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68720 ret = ptrace_attach(child, request, addr, data);
68721 /*
68722 * Some architectures need to do book-keeping after
68723 * a ptrace attach.
68724 */
68725- if (!ret)
68726+ if (!ret) {
68727 arch_ptrace_attach(child);
68728+ gr_audit_ptrace(child);
68729+ }
68730 goto out_put_task_struct;
68731 }
68732
68733@@ -906,7 +913,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
68734 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
68735 if (copied != sizeof(tmp))
68736 return -EIO;
68737- return put_user(tmp, (unsigned long __user *)data);
68738+ return put_user(tmp, (__force unsigned long __user *)data);
68739 }
68740
68741 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
68742@@ -1016,14 +1023,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
68743 goto out;
68744 }
68745
68746+ if (gr_handle_ptrace(child, request)) {
68747+ ret = -EPERM;
68748+ goto out_put_task_struct;
68749+ }
68750+
68751 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68752 ret = ptrace_attach(child, request, addr, data);
68753 /*
68754 * Some architectures need to do book-keeping after
68755 * a ptrace attach.
68756 */
68757- if (!ret)
68758+ if (!ret) {
68759 arch_ptrace_attach(child);
68760+ gr_audit_ptrace(child);
68761+ }
68762 goto out_put_task_struct;
68763 }
68764
68765diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
68766index 37a5444..eec170a 100644
68767--- a/kernel/rcutiny.c
68768+++ b/kernel/rcutiny.c
68769@@ -46,7 +46,7 @@
68770 struct rcu_ctrlblk;
68771 static void invoke_rcu_callbacks(void);
68772 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
68773-static void rcu_process_callbacks(struct softirq_action *unused);
68774+static void rcu_process_callbacks(void);
68775 static void __call_rcu(struct rcu_head *head,
68776 void (*func)(struct rcu_head *rcu),
68777 struct rcu_ctrlblk *rcp);
68778@@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
68779 rcu_is_callbacks_kthread()));
68780 }
68781
68782-static void rcu_process_callbacks(struct softirq_action *unused)
68783+static void rcu_process_callbacks(void)
68784 {
68785 __rcu_process_callbacks(&rcu_sched_ctrlblk);
68786 __rcu_process_callbacks(&rcu_bh_ctrlblk);
68787diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
68788index fc31a2d..be2ec04 100644
68789--- a/kernel/rcutiny_plugin.h
68790+++ b/kernel/rcutiny_plugin.h
68791@@ -939,7 +939,7 @@ static int rcu_kthread(void *arg)
68792 have_rcu_kthread_work = morework;
68793 local_irq_restore(flags);
68794 if (work)
68795- rcu_process_callbacks(NULL);
68796+ rcu_process_callbacks();
68797 schedule_timeout_interruptible(1); /* Leave CPU for others. */
68798 }
68799
68800diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
68801index e66b34a..4b8b626 100644
68802--- a/kernel/rcutorture.c
68803+++ b/kernel/rcutorture.c
68804@@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
68805 { 0 };
68806 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
68807 { 0 };
68808-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68809-static atomic_t n_rcu_torture_alloc;
68810-static atomic_t n_rcu_torture_alloc_fail;
68811-static atomic_t n_rcu_torture_free;
68812-static atomic_t n_rcu_torture_mberror;
68813-static atomic_t n_rcu_torture_error;
68814+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68815+static atomic_unchecked_t n_rcu_torture_alloc;
68816+static atomic_unchecked_t n_rcu_torture_alloc_fail;
68817+static atomic_unchecked_t n_rcu_torture_free;
68818+static atomic_unchecked_t n_rcu_torture_mberror;
68819+static atomic_unchecked_t n_rcu_torture_error;
68820 static long n_rcu_torture_barrier_error;
68821 static long n_rcu_torture_boost_ktrerror;
68822 static long n_rcu_torture_boost_rterror;
68823@@ -265,11 +265,11 @@ rcu_torture_alloc(void)
68824
68825 spin_lock_bh(&rcu_torture_lock);
68826 if (list_empty(&rcu_torture_freelist)) {
68827- atomic_inc(&n_rcu_torture_alloc_fail);
68828+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
68829 spin_unlock_bh(&rcu_torture_lock);
68830 return NULL;
68831 }
68832- atomic_inc(&n_rcu_torture_alloc);
68833+ atomic_inc_unchecked(&n_rcu_torture_alloc);
68834 p = rcu_torture_freelist.next;
68835 list_del_init(p);
68836 spin_unlock_bh(&rcu_torture_lock);
68837@@ -282,7 +282,7 @@ rcu_torture_alloc(void)
68838 static void
68839 rcu_torture_free(struct rcu_torture *p)
68840 {
68841- atomic_inc(&n_rcu_torture_free);
68842+ atomic_inc_unchecked(&n_rcu_torture_free);
68843 spin_lock_bh(&rcu_torture_lock);
68844 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
68845 spin_unlock_bh(&rcu_torture_lock);
68846@@ -403,7 +403,7 @@ rcu_torture_cb(struct rcu_head *p)
68847 i = rp->rtort_pipe_count;
68848 if (i > RCU_TORTURE_PIPE_LEN)
68849 i = RCU_TORTURE_PIPE_LEN;
68850- atomic_inc(&rcu_torture_wcount[i]);
68851+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
68852 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68853 rp->rtort_mbtest = 0;
68854 rcu_torture_free(rp);
68855@@ -451,7 +451,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
68856 i = rp->rtort_pipe_count;
68857 if (i > RCU_TORTURE_PIPE_LEN)
68858 i = RCU_TORTURE_PIPE_LEN;
68859- atomic_inc(&rcu_torture_wcount[i]);
68860+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
68861 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68862 rp->rtort_mbtest = 0;
68863 list_del(&rp->rtort_free);
68864@@ -983,7 +983,7 @@ rcu_torture_writer(void *arg)
68865 i = old_rp->rtort_pipe_count;
68866 if (i > RCU_TORTURE_PIPE_LEN)
68867 i = RCU_TORTURE_PIPE_LEN;
68868- atomic_inc(&rcu_torture_wcount[i]);
68869+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
68870 old_rp->rtort_pipe_count++;
68871 cur_ops->deferred_free(old_rp);
68872 }
68873@@ -1064,7 +1064,7 @@ static void rcu_torture_timer(unsigned long unused)
68874 }
68875 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
68876 if (p->rtort_mbtest == 0)
68877- atomic_inc(&n_rcu_torture_mberror);
68878+ atomic_inc_unchecked(&n_rcu_torture_mberror);
68879 spin_lock(&rand_lock);
68880 cur_ops->read_delay(&rand);
68881 n_rcu_torture_timers++;
68882@@ -1128,7 +1128,7 @@ rcu_torture_reader(void *arg)
68883 }
68884 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
68885 if (p->rtort_mbtest == 0)
68886- atomic_inc(&n_rcu_torture_mberror);
68887+ atomic_inc_unchecked(&n_rcu_torture_mberror);
68888 cur_ops->read_delay(&rand);
68889 preempt_disable();
68890 pipe_count = p->rtort_pipe_count;
68891@@ -1191,10 +1191,10 @@ rcu_torture_printk(char *page)
68892 rcu_torture_current,
68893 rcu_torture_current_version,
68894 list_empty(&rcu_torture_freelist),
68895- atomic_read(&n_rcu_torture_alloc),
68896- atomic_read(&n_rcu_torture_alloc_fail),
68897- atomic_read(&n_rcu_torture_free),
68898- atomic_read(&n_rcu_torture_mberror),
68899+ atomic_read_unchecked(&n_rcu_torture_alloc),
68900+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
68901+ atomic_read_unchecked(&n_rcu_torture_free),
68902+ atomic_read_unchecked(&n_rcu_torture_mberror),
68903 n_rcu_torture_boost_ktrerror,
68904 n_rcu_torture_boost_rterror,
68905 n_rcu_torture_boost_failure,
68906@@ -1208,14 +1208,14 @@ rcu_torture_printk(char *page)
68907 n_barrier_attempts,
68908 n_rcu_torture_barrier_error);
68909 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
68910- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
68911+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
68912 n_rcu_torture_barrier_error != 0 ||
68913 n_rcu_torture_boost_ktrerror != 0 ||
68914 n_rcu_torture_boost_rterror != 0 ||
68915 n_rcu_torture_boost_failure != 0 ||
68916 i > 1) {
68917 cnt += sprintf(&page[cnt], "!!! ");
68918- atomic_inc(&n_rcu_torture_error);
68919+ atomic_inc_unchecked(&n_rcu_torture_error);
68920 WARN_ON_ONCE(1);
68921 }
68922 cnt += sprintf(&page[cnt], "Reader Pipe: ");
68923@@ -1229,7 +1229,7 @@ rcu_torture_printk(char *page)
68924 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
68925 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68926 cnt += sprintf(&page[cnt], " %d",
68927- atomic_read(&rcu_torture_wcount[i]));
68928+ atomic_read_unchecked(&rcu_torture_wcount[i]));
68929 }
68930 cnt += sprintf(&page[cnt], "\n");
68931 if (cur_ops->stats)
68932@@ -1888,7 +1888,7 @@ rcu_torture_cleanup(void)
68933
68934 if (cur_ops->cleanup)
68935 cur_ops->cleanup();
68936- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
68937+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
68938 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
68939 else if (n_online_successes != n_online_attempts ||
68940 n_offline_successes != n_offline_attempts)
68941@@ -1958,18 +1958,18 @@ rcu_torture_init(void)
68942
68943 rcu_torture_current = NULL;
68944 rcu_torture_current_version = 0;
68945- atomic_set(&n_rcu_torture_alloc, 0);
68946- atomic_set(&n_rcu_torture_alloc_fail, 0);
68947- atomic_set(&n_rcu_torture_free, 0);
68948- atomic_set(&n_rcu_torture_mberror, 0);
68949- atomic_set(&n_rcu_torture_error, 0);
68950+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
68951+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
68952+ atomic_set_unchecked(&n_rcu_torture_free, 0);
68953+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
68954+ atomic_set_unchecked(&n_rcu_torture_error, 0);
68955 n_rcu_torture_barrier_error = 0;
68956 n_rcu_torture_boost_ktrerror = 0;
68957 n_rcu_torture_boost_rterror = 0;
68958 n_rcu_torture_boost_failure = 0;
68959 n_rcu_torture_boosts = 0;
68960 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
68961- atomic_set(&rcu_torture_wcount[i], 0);
68962+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
68963 for_each_possible_cpu(cpu) {
68964 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68965 per_cpu(rcu_torture_count, cpu)[i] = 0;
68966diff --git a/kernel/rcutree.c b/kernel/rcutree.c
68967index 4b97bba..b92c9d2 100644
68968--- a/kernel/rcutree.c
68969+++ b/kernel/rcutree.c
68970@@ -366,9 +366,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
68971 rcu_prepare_for_idle(smp_processor_id());
68972 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68973 smp_mb__before_atomic_inc(); /* See above. */
68974- atomic_inc(&rdtp->dynticks);
68975+ atomic_inc_unchecked(&rdtp->dynticks);
68976 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
68977- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68978+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68979
68980 /*
68981 * The idle task is not permitted to enter the idle loop while
68982@@ -457,10 +457,10 @@ void rcu_irq_exit(void)
68983 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
68984 {
68985 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
68986- atomic_inc(&rdtp->dynticks);
68987+ atomic_inc_unchecked(&rdtp->dynticks);
68988 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68989 smp_mb__after_atomic_inc(); /* See above. */
68990- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68991+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68992 rcu_cleanup_after_idle(smp_processor_id());
68993 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
68994 if (!is_idle_task(current)) {
68995@@ -554,14 +554,14 @@ void rcu_nmi_enter(void)
68996 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
68997
68998 if (rdtp->dynticks_nmi_nesting == 0 &&
68999- (atomic_read(&rdtp->dynticks) & 0x1))
69000+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
69001 return;
69002 rdtp->dynticks_nmi_nesting++;
69003 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
69004- atomic_inc(&rdtp->dynticks);
69005+ atomic_inc_unchecked(&rdtp->dynticks);
69006 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69007 smp_mb__after_atomic_inc(); /* See above. */
69008- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69009+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69010 }
69011
69012 /**
69013@@ -580,9 +580,9 @@ void rcu_nmi_exit(void)
69014 return;
69015 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69016 smp_mb__before_atomic_inc(); /* See above. */
69017- atomic_inc(&rdtp->dynticks);
69018+ atomic_inc_unchecked(&rdtp->dynticks);
69019 smp_mb__after_atomic_inc(); /* Force delay to next write. */
69020- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69021+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69022 }
69023
69024 #ifdef CONFIG_PROVE_RCU
69025@@ -598,7 +598,7 @@ int rcu_is_cpu_idle(void)
69026 int ret;
69027
69028 preempt_disable();
69029- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69030+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69031 preempt_enable();
69032 return ret;
69033 }
69034@@ -668,7 +668,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
69035 */
69036 static int dyntick_save_progress_counter(struct rcu_data *rdp)
69037 {
69038- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
69039+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69040 return (rdp->dynticks_snap & 0x1) == 0;
69041 }
69042
69043@@ -683,7 +683,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
69044 unsigned int curr;
69045 unsigned int snap;
69046
69047- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
69048+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69049 snap = (unsigned int)rdp->dynticks_snap;
69050
69051 /*
69052@@ -713,10 +713,10 @@ static int jiffies_till_stall_check(void)
69053 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
69054 */
69055 if (till_stall_check < 3) {
69056- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
69057+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
69058 till_stall_check = 3;
69059 } else if (till_stall_check > 300) {
69060- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
69061+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
69062 till_stall_check = 300;
69063 }
69064 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
69065@@ -1824,7 +1824,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
69066 /*
69067 * Do RCU core processing for the current CPU.
69068 */
69069-static void rcu_process_callbacks(struct softirq_action *unused)
69070+static void rcu_process_callbacks(void)
69071 {
69072 trace_rcu_utilization("Start RCU core");
69073 __rcu_process_callbacks(&rcu_sched_state,
69074@@ -2042,8 +2042,8 @@ void synchronize_rcu_bh(void)
69075 }
69076 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
69077
69078-static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
69079-static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
69080+static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
69081+static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
69082
69083 static int synchronize_sched_expedited_cpu_stop(void *data)
69084 {
69085@@ -2104,7 +2104,7 @@ void synchronize_sched_expedited(void)
69086 int firstsnap, s, snap, trycount = 0;
69087
69088 /* Note that atomic_inc_return() implies full memory barrier. */
69089- firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
69090+ firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
69091 get_online_cpus();
69092 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
69093
69094@@ -2126,7 +2126,7 @@ void synchronize_sched_expedited(void)
69095 }
69096
69097 /* Check to see if someone else did our work for us. */
69098- s = atomic_read(&sync_sched_expedited_done);
69099+ s = atomic_read_unchecked(&sync_sched_expedited_done);
69100 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
69101 smp_mb(); /* ensure test happens before caller kfree */
69102 return;
69103@@ -2141,7 +2141,7 @@ void synchronize_sched_expedited(void)
69104 * grace period works for us.
69105 */
69106 get_online_cpus();
69107- snap = atomic_read(&sync_sched_expedited_started);
69108+ snap = atomic_read_unchecked(&sync_sched_expedited_started);
69109 smp_mb(); /* ensure read is before try_stop_cpus(). */
69110 }
69111
69112@@ -2152,12 +2152,12 @@ void synchronize_sched_expedited(void)
69113 * than we did beat us to the punch.
69114 */
69115 do {
69116- s = atomic_read(&sync_sched_expedited_done);
69117+ s = atomic_read_unchecked(&sync_sched_expedited_done);
69118 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
69119 smp_mb(); /* ensure test happens before caller kfree */
69120 break;
69121 }
69122- } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
69123+ } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
69124
69125 put_online_cpus();
69126 }
69127@@ -2421,7 +2421,7 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
69128 rdp->qlen = 0;
69129 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
69130 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
69131- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
69132+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
69133 rdp->cpu = cpu;
69134 rdp->rsp = rsp;
69135 raw_spin_unlock_irqrestore(&rnp->lock, flags);
69136@@ -2449,8 +2449,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
69137 rdp->n_force_qs_snap = rsp->n_force_qs;
69138 rdp->blimit = blimit;
69139 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
69140- atomic_set(&rdp->dynticks->dynticks,
69141- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
69142+ atomic_set_unchecked(&rdp->dynticks->dynticks,
69143+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
69144 rcu_prepare_for_idle_init(cpu);
69145 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
69146
69147diff --git a/kernel/rcutree.h b/kernel/rcutree.h
69148index 19b61ac..5c60a94 100644
69149--- a/kernel/rcutree.h
69150+++ b/kernel/rcutree.h
69151@@ -83,7 +83,7 @@ struct rcu_dynticks {
69152 long long dynticks_nesting; /* Track irq/process nesting level. */
69153 /* Process level is worth LLONG_MAX/2. */
69154 int dynticks_nmi_nesting; /* Track NMI nesting level. */
69155- atomic_t dynticks; /* Even value for idle, else odd. */
69156+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
69157 #ifdef CONFIG_RCU_FAST_NO_HZ
69158 int dyntick_drain; /* Prepare-for-idle state variable. */
69159 unsigned long dyntick_holdoff;
69160diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
69161index 3e48994..d94f03a 100644
69162--- a/kernel/rcutree_plugin.h
69163+++ b/kernel/rcutree_plugin.h
69164@@ -909,7 +909,7 @@ void synchronize_rcu_expedited(void)
69165
69166 /* Clean up and exit. */
69167 smp_mb(); /* ensure expedited GP seen before counter increment. */
69168- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
69169+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
69170 unlock_mb_ret:
69171 mutex_unlock(&sync_rcu_preempt_exp_mutex);
69172 mb_ret:
69173diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
69174index d4bc16d..c234a5c 100644
69175--- a/kernel/rcutree_trace.c
69176+++ b/kernel/rcutree_trace.c
69177@@ -68,7 +68,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
69178 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69179 rdp->qs_pending);
69180 seq_printf(m, " dt=%d/%llx/%d df=%lu",
69181- atomic_read(&rdp->dynticks->dynticks),
69182+ atomic_read_unchecked(&rdp->dynticks->dynticks),
69183 rdp->dynticks->dynticks_nesting,
69184 rdp->dynticks->dynticks_nmi_nesting,
69185 rdp->dynticks_fqs);
69186@@ -140,7 +140,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
69187 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69188 rdp->qs_pending);
69189 seq_printf(m, ",%d,%llx,%d,%lu",
69190- atomic_read(&rdp->dynticks->dynticks),
69191+ atomic_read_unchecked(&rdp->dynticks->dynticks),
69192 rdp->dynticks->dynticks_nesting,
69193 rdp->dynticks->dynticks_nmi_nesting,
69194 rdp->dynticks_fqs);
69195diff --git a/kernel/resource.c b/kernel/resource.c
69196index e1d2b8e..24820bb 100644
69197--- a/kernel/resource.c
69198+++ b/kernel/resource.c
69199@@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
69200
69201 static int __init ioresources_init(void)
69202 {
69203+#ifdef CONFIG_GRKERNSEC_PROC_ADD
69204+#ifdef CONFIG_GRKERNSEC_PROC_USER
69205+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
69206+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
69207+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69208+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
69209+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
69210+#endif
69211+#else
69212 proc_create("ioports", 0, NULL, &proc_ioports_operations);
69213 proc_create("iomem", 0, NULL, &proc_iomem_operations);
69214+#endif
69215 return 0;
69216 }
69217 __initcall(ioresources_init);
69218diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
69219index 98ec494..4241d6d 100644
69220--- a/kernel/rtmutex-tester.c
69221+++ b/kernel/rtmutex-tester.c
69222@@ -20,7 +20,7 @@
69223 #define MAX_RT_TEST_MUTEXES 8
69224
69225 static spinlock_t rttest_lock;
69226-static atomic_t rttest_event;
69227+static atomic_unchecked_t rttest_event;
69228
69229 struct test_thread_data {
69230 int opcode;
69231@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69232
69233 case RTTEST_LOCKCONT:
69234 td->mutexes[td->opdata] = 1;
69235- td->event = atomic_add_return(1, &rttest_event);
69236+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69237 return 0;
69238
69239 case RTTEST_RESET:
69240@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69241 return 0;
69242
69243 case RTTEST_RESETEVENT:
69244- atomic_set(&rttest_event, 0);
69245+ atomic_set_unchecked(&rttest_event, 0);
69246 return 0;
69247
69248 default:
69249@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69250 return ret;
69251
69252 td->mutexes[id] = 1;
69253- td->event = atomic_add_return(1, &rttest_event);
69254+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69255 rt_mutex_lock(&mutexes[id]);
69256- td->event = atomic_add_return(1, &rttest_event);
69257+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69258 td->mutexes[id] = 4;
69259 return 0;
69260
69261@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69262 return ret;
69263
69264 td->mutexes[id] = 1;
69265- td->event = atomic_add_return(1, &rttest_event);
69266+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69267 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
69268- td->event = atomic_add_return(1, &rttest_event);
69269+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69270 td->mutexes[id] = ret ? 0 : 4;
69271 return ret ? -EINTR : 0;
69272
69273@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69274 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
69275 return ret;
69276
69277- td->event = atomic_add_return(1, &rttest_event);
69278+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69279 rt_mutex_unlock(&mutexes[id]);
69280- td->event = atomic_add_return(1, &rttest_event);
69281+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69282 td->mutexes[id] = 0;
69283 return 0;
69284
69285@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69286 break;
69287
69288 td->mutexes[dat] = 2;
69289- td->event = atomic_add_return(1, &rttest_event);
69290+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69291 break;
69292
69293 default:
69294@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69295 return;
69296
69297 td->mutexes[dat] = 3;
69298- td->event = atomic_add_return(1, &rttest_event);
69299+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69300 break;
69301
69302 case RTTEST_LOCKNOWAIT:
69303@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69304 return;
69305
69306 td->mutexes[dat] = 1;
69307- td->event = atomic_add_return(1, &rttest_event);
69308+ td->event = atomic_add_return_unchecked(1, &rttest_event);
69309 return;
69310
69311 default:
69312diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
69313index 0984a21..939f183 100644
69314--- a/kernel/sched/auto_group.c
69315+++ b/kernel/sched/auto_group.c
69316@@ -11,7 +11,7 @@
69317
69318 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
69319 static struct autogroup autogroup_default;
69320-static atomic_t autogroup_seq_nr;
69321+static atomic_unchecked_t autogroup_seq_nr;
69322
69323 void __init autogroup_init(struct task_struct *init_task)
69324 {
69325@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
69326
69327 kref_init(&ag->kref);
69328 init_rwsem(&ag->lock);
69329- ag->id = atomic_inc_return(&autogroup_seq_nr);
69330+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
69331 ag->tg = tg;
69332 #ifdef CONFIG_RT_GROUP_SCHED
69333 /*
69334diff --git a/kernel/sched/core.c b/kernel/sched/core.c
69335index 468bdd4..b941572 100644
69336--- a/kernel/sched/core.c
69337+++ b/kernel/sched/core.c
69338@@ -4097,6 +4097,8 @@ int can_nice(const struct task_struct *p, const int nice)
69339 /* convert nice value [19,-20] to rlimit style value [1,40] */
69340 int nice_rlim = 20 - nice;
69341
69342+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
69343+
69344 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
69345 capable(CAP_SYS_NICE));
69346 }
69347@@ -4130,7 +4132,8 @@ SYSCALL_DEFINE1(nice, int, increment)
69348 if (nice > 19)
69349 nice = 19;
69350
69351- if (increment < 0 && !can_nice(current, nice))
69352+ if (increment < 0 && (!can_nice(current, nice) ||
69353+ gr_handle_chroot_nice()))
69354 return -EPERM;
69355
69356 retval = security_task_setnice(current, nice);
69357@@ -4284,6 +4287,7 @@ recheck:
69358 unsigned long rlim_rtprio =
69359 task_rlimit(p, RLIMIT_RTPRIO);
69360
69361+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
69362 /* can't set/change the rt policy */
69363 if (policy != p->policy && !rlim_rtprio)
69364 return -EPERM;
69365diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
69366index c099cc6..06aec4f 100644
69367--- a/kernel/sched/fair.c
69368+++ b/kernel/sched/fair.c
69369@@ -4846,7 +4846,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
69370 * run_rebalance_domains is triggered when needed from the scheduler tick.
69371 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
69372 */
69373-static void run_rebalance_domains(struct softirq_action *h)
69374+static void run_rebalance_domains(void)
69375 {
69376 int this_cpu = smp_processor_id();
69377 struct rq *this_rq = cpu_rq(this_cpu);
69378diff --git a/kernel/signal.c b/kernel/signal.c
69379index 6771027..763e51e 100644
69380--- a/kernel/signal.c
69381+++ b/kernel/signal.c
69382@@ -48,12 +48,12 @@ static struct kmem_cache *sigqueue_cachep;
69383
69384 int print_fatal_signals __read_mostly;
69385
69386-static void __user *sig_handler(struct task_struct *t, int sig)
69387+static __sighandler_t sig_handler(struct task_struct *t, int sig)
69388 {
69389 return t->sighand->action[sig - 1].sa.sa_handler;
69390 }
69391
69392-static int sig_handler_ignored(void __user *handler, int sig)
69393+static int sig_handler_ignored(__sighandler_t handler, int sig)
69394 {
69395 /* Is it explicitly or implicitly ignored? */
69396 return handler == SIG_IGN ||
69397@@ -62,7 +62,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
69398
69399 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
69400 {
69401- void __user *handler;
69402+ __sighandler_t handler;
69403
69404 handler = sig_handler(t, sig);
69405
69406@@ -366,6 +366,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
69407 atomic_inc(&user->sigpending);
69408 rcu_read_unlock();
69409
69410+ if (!override_rlimit)
69411+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
69412+
69413 if (override_rlimit ||
69414 atomic_read(&user->sigpending) <=
69415 task_rlimit(t, RLIMIT_SIGPENDING)) {
69416@@ -490,7 +493,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
69417
69418 int unhandled_signal(struct task_struct *tsk, int sig)
69419 {
69420- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
69421+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
69422 if (is_global_init(tsk))
69423 return 1;
69424 if (handler != SIG_IGN && handler != SIG_DFL)
69425@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
69426 }
69427 }
69428
69429+ /* allow glibc communication via tgkill to other threads in our
69430+ thread group */
69431+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
69432+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
69433+ && gr_handle_signal(t, sig))
69434+ return -EPERM;
69435+
69436 return security_task_kill(t, info, sig, 0);
69437 }
69438
69439@@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69440 return send_signal(sig, info, p, 1);
69441 }
69442
69443-static int
69444+int
69445 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69446 {
69447 return send_signal(sig, info, t, 0);
69448@@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69449 unsigned long int flags;
69450 int ret, blocked, ignored;
69451 struct k_sigaction *action;
69452+ int is_unhandled = 0;
69453
69454 spin_lock_irqsave(&t->sighand->siglock, flags);
69455 action = &t->sighand->action[sig-1];
69456@@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
69457 }
69458 if (action->sa.sa_handler == SIG_DFL)
69459 t->signal->flags &= ~SIGNAL_UNKILLABLE;
69460+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
69461+ is_unhandled = 1;
69462 ret = specific_send_sig_info(sig, info, t);
69463 spin_unlock_irqrestore(&t->sighand->siglock, flags);
69464
69465+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
69466+ normal operation */
69467+ if (is_unhandled) {
69468+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
69469+ gr_handle_crash(t, sig);
69470+ }
69471+
69472 return ret;
69473 }
69474
69475@@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69476 ret = check_kill_permission(sig, info, p);
69477 rcu_read_unlock();
69478
69479- if (!ret && sig)
69480+ if (!ret && sig) {
69481 ret = do_send_sig_info(sig, info, p, true);
69482+ if (!ret)
69483+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
69484+ }
69485
69486 return ret;
69487 }
69488@@ -2858,7 +2881,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
69489 int error = -ESRCH;
69490
69491 rcu_read_lock();
69492- p = find_task_by_vpid(pid);
69493+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69494+ /* allow glibc communication via tgkill to other threads in our
69495+ thread group */
69496+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
69497+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
69498+ p = find_task_by_vpid_unrestricted(pid);
69499+ else
69500+#endif
69501+ p = find_task_by_vpid(pid);
69502 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
69503 error = check_kill_permission(sig, info, p);
69504 /*
69505diff --git a/kernel/smp.c b/kernel/smp.c
69506index d0ae5b2..b87c5a8 100644
69507--- a/kernel/smp.c
69508+++ b/kernel/smp.c
69509@@ -582,22 +582,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
69510 }
69511 EXPORT_SYMBOL(smp_call_function);
69512
69513-void ipi_call_lock(void)
69514+void ipi_call_lock(void) __acquires(call_function.lock)
69515 {
69516 raw_spin_lock(&call_function.lock);
69517 }
69518
69519-void ipi_call_unlock(void)
69520+void ipi_call_unlock(void) __releases(call_function.lock)
69521 {
69522 raw_spin_unlock(&call_function.lock);
69523 }
69524
69525-void ipi_call_lock_irq(void)
69526+void ipi_call_lock_irq(void) __acquires(call_function.lock)
69527 {
69528 raw_spin_lock_irq(&call_function.lock);
69529 }
69530
69531-void ipi_call_unlock_irq(void)
69532+void ipi_call_unlock_irq(void) __releases(call_function.lock)
69533 {
69534 raw_spin_unlock_irq(&call_function.lock);
69535 }
69536diff --git a/kernel/softirq.c b/kernel/softirq.c
69537index 671f959..91c51cb 100644
69538--- a/kernel/softirq.c
69539+++ b/kernel/softirq.c
69540@@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
69541
69542 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
69543
69544-char *softirq_to_name[NR_SOFTIRQS] = {
69545+const char * const softirq_to_name[NR_SOFTIRQS] = {
69546 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
69547 "TASKLET", "SCHED", "HRTIMER", "RCU"
69548 };
69549@@ -235,7 +235,7 @@ restart:
69550 kstat_incr_softirqs_this_cpu(vec_nr);
69551
69552 trace_softirq_entry(vec_nr);
69553- h->action(h);
69554+ h->action();
69555 trace_softirq_exit(vec_nr);
69556 if (unlikely(prev_count != preempt_count())) {
69557 printk(KERN_ERR "huh, entered softirq %u %s %p"
69558@@ -381,9 +381,11 @@ void __raise_softirq_irqoff(unsigned int nr)
69559 or_softirq_pending(1UL << nr);
69560 }
69561
69562-void open_softirq(int nr, void (*action)(struct softirq_action *))
69563+void open_softirq(int nr, void (*action)(void))
69564 {
69565- softirq_vec[nr].action = action;
69566+ pax_open_kernel();
69567+ *(void **)&softirq_vec[nr].action = action;
69568+ pax_close_kernel();
69569 }
69570
69571 /*
69572@@ -437,7 +439,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
69573
69574 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
69575
69576-static void tasklet_action(struct softirq_action *a)
69577+static void tasklet_action(void)
69578 {
69579 struct tasklet_struct *list;
69580
69581@@ -472,7 +474,7 @@ static void tasklet_action(struct softirq_action *a)
69582 }
69583 }
69584
69585-static void tasklet_hi_action(struct softirq_action *a)
69586+static void tasklet_hi_action(void)
69587 {
69588 struct tasklet_struct *list;
69589
69590diff --git a/kernel/srcu.c b/kernel/srcu.c
69591index 2095be3..9a5b89d 100644
69592--- a/kernel/srcu.c
69593+++ b/kernel/srcu.c
69594@@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
69595 preempt_disable();
69596 idx = rcu_dereference_index_check(sp->completed,
69597 rcu_read_lock_sched_held()) & 0x1;
69598- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
69599+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
69600 smp_mb(); /* B */ /* Avoid leaking the critical section. */
69601- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
69602+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
69603 preempt_enable();
69604 return idx;
69605 }
69606@@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
69607 {
69608 preempt_disable();
69609 smp_mb(); /* C */ /* Avoid leaking the critical section. */
69610- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
69611+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
69612 preempt_enable();
69613 }
69614 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
69615diff --git a/kernel/sys.c b/kernel/sys.c
69616index 2d39a84..f778b49 100644
69617--- a/kernel/sys.c
69618+++ b/kernel/sys.c
69619@@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
69620 error = -EACCES;
69621 goto out;
69622 }
69623+
69624+ if (gr_handle_chroot_setpriority(p, niceval)) {
69625+ error = -EACCES;
69626+ goto out;
69627+ }
69628+
69629 no_nice = security_task_setnice(p, niceval);
69630 if (no_nice) {
69631 error = no_nice;
69632@@ -594,6 +600,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
69633 goto error;
69634 }
69635
69636+ if (gr_check_group_change(new->gid, new->egid, -1))
69637+ goto error;
69638+
69639 if (rgid != (gid_t) -1 ||
69640 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
69641 new->sgid = new->egid;
69642@@ -629,6 +638,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
69643 old = current_cred();
69644
69645 retval = -EPERM;
69646+
69647+ if (gr_check_group_change(kgid, kgid, kgid))
69648+ goto error;
69649+
69650 if (nsown_capable(CAP_SETGID))
69651 new->gid = new->egid = new->sgid = new->fsgid = kgid;
69652 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
69653@@ -646,7 +659,7 @@ error:
69654 /*
69655 * change the user struct in a credentials set to match the new UID
69656 */
69657-static int set_user(struct cred *new)
69658+int set_user(struct cred *new)
69659 {
69660 struct user_struct *new_user;
69661
69662@@ -726,6 +739,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
69663 goto error;
69664 }
69665
69666+ if (gr_check_user_change(new->uid, new->euid, -1))
69667+ goto error;
69668+
69669 if (!uid_eq(new->uid, old->uid)) {
69670 retval = set_user(new);
69671 if (retval < 0)
69672@@ -776,6 +792,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
69673 old = current_cred();
69674
69675 retval = -EPERM;
69676+
69677+ if (gr_check_crash_uid(kuid))
69678+ goto error;
69679+ if (gr_check_user_change(kuid, kuid, kuid))
69680+ goto error;
69681+
69682 if (nsown_capable(CAP_SETUID)) {
69683 new->suid = new->uid = kuid;
69684 if (!uid_eq(kuid, old->uid)) {
69685@@ -845,6 +867,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
69686 goto error;
69687 }
69688
69689+ if (gr_check_user_change(kruid, keuid, -1))
69690+ goto error;
69691+
69692 if (ruid != (uid_t) -1) {
69693 new->uid = kruid;
69694 if (!uid_eq(kruid, old->uid)) {
69695@@ -927,6 +952,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
69696 goto error;
69697 }
69698
69699+ if (gr_check_group_change(krgid, kegid, -1))
69700+ goto error;
69701+
69702 if (rgid != (gid_t) -1)
69703 new->gid = krgid;
69704 if (egid != (gid_t) -1)
69705@@ -980,6 +1008,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69706 if (!uid_valid(kuid))
69707 return old_fsuid;
69708
69709+ if (gr_check_user_change(-1, -1, kuid))
69710+ goto error;
69711+
69712 new = prepare_creds();
69713 if (!new)
69714 return old_fsuid;
69715@@ -994,6 +1025,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
69716 }
69717 }
69718
69719+error:
69720 abort_creds(new);
69721 return old_fsuid;
69722
69723@@ -1026,12 +1058,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
69724 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
69725 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
69726 nsown_capable(CAP_SETGID)) {
69727+ if (gr_check_group_change(-1, -1, kgid))
69728+ goto error;
69729+
69730 if (!gid_eq(kgid, old->fsgid)) {
69731 new->fsgid = kgid;
69732 goto change_okay;
69733 }
69734 }
69735
69736+error:
69737 abort_creds(new);
69738 return old_fsgid;
69739
69740@@ -1283,7 +1319,10 @@ static int override_release(char __user *release, int len)
69741 }
69742 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
69743 snprintf(buf, len, "2.6.%u%s", v, rest);
69744- ret = copy_to_user(release, buf, len);
69745+ if (len > sizeof(buf))
69746+ ret = -EFAULT;
69747+ else
69748+ ret = copy_to_user(release, buf, len);
69749 }
69750 return ret;
69751 }
69752@@ -1337,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
69753 return -EFAULT;
69754
69755 down_read(&uts_sem);
69756- error = __copy_to_user(&name->sysname, &utsname()->sysname,
69757+ error = __copy_to_user(name->sysname, &utsname()->sysname,
69758 __OLD_UTS_LEN);
69759 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
69760- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
69761+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
69762 __OLD_UTS_LEN);
69763 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
69764- error |= __copy_to_user(&name->release, &utsname()->release,
69765+ error |= __copy_to_user(name->release, &utsname()->release,
69766 __OLD_UTS_LEN);
69767 error |= __put_user(0, name->release + __OLD_UTS_LEN);
69768- error |= __copy_to_user(&name->version, &utsname()->version,
69769+ error |= __copy_to_user(name->version, &utsname()->version,
69770 __OLD_UTS_LEN);
69771 error |= __put_user(0, name->version + __OLD_UTS_LEN);
69772- error |= __copy_to_user(&name->machine, &utsname()->machine,
69773+ error |= __copy_to_user(name->machine, &utsname()->machine,
69774 __OLD_UTS_LEN);
69775 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
69776 up_read(&uts_sem);
69777@@ -2024,7 +2063,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
69778 error = get_dumpable(me->mm);
69779 break;
69780 case PR_SET_DUMPABLE:
69781- if (arg2 < 0 || arg2 > 1) {
69782+ if (arg2 > 1) {
69783 error = -EINVAL;
69784 break;
69785 }
69786diff --git a/kernel/sysctl.c b/kernel/sysctl.c
69787index 4ab1187..33f4f2b 100644
69788--- a/kernel/sysctl.c
69789+++ b/kernel/sysctl.c
69790@@ -91,7 +91,6 @@
69791
69792
69793 #if defined(CONFIG_SYSCTL)
69794-
69795 /* External variables not in a header file. */
69796 extern int sysctl_overcommit_memory;
69797 extern int sysctl_overcommit_ratio;
69798@@ -169,10 +168,13 @@ static int proc_taint(struct ctl_table *table, int write,
69799 void __user *buffer, size_t *lenp, loff_t *ppos);
69800 #endif
69801
69802-#ifdef CONFIG_PRINTK
69803 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69804 void __user *buffer, size_t *lenp, loff_t *ppos);
69805-#endif
69806+
69807+static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
69808+ void __user *buffer, size_t *lenp, loff_t *ppos);
69809+static int proc_dostring_coredump(struct ctl_table *table, int write,
69810+ void __user *buffer, size_t *lenp, loff_t *ppos);
69811
69812 #ifdef CONFIG_MAGIC_SYSRQ
69813 /* Note: sysrq code uses it's own private copy */
69814@@ -196,6 +198,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
69815
69816 #endif
69817
69818+extern struct ctl_table grsecurity_table[];
69819+
69820 static struct ctl_table kern_table[];
69821 static struct ctl_table vm_table[];
69822 static struct ctl_table fs_table[];
69823@@ -210,6 +214,20 @@ extern struct ctl_table epoll_table[];
69824 int sysctl_legacy_va_layout;
69825 #endif
69826
69827+#ifdef CONFIG_PAX_SOFTMODE
69828+static ctl_table pax_table[] = {
69829+ {
69830+ .procname = "softmode",
69831+ .data = &pax_softmode,
69832+ .maxlen = sizeof(unsigned int),
69833+ .mode = 0600,
69834+ .proc_handler = &proc_dointvec,
69835+ },
69836+
69837+ { }
69838+};
69839+#endif
69840+
69841 /* The default sysctl tables: */
69842
69843 static struct ctl_table sysctl_base_table[] = {
69844@@ -256,6 +274,22 @@ static int max_extfrag_threshold = 1000;
69845 #endif
69846
69847 static struct ctl_table kern_table[] = {
69848+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
69849+ {
69850+ .procname = "grsecurity",
69851+ .mode = 0500,
69852+ .child = grsecurity_table,
69853+ },
69854+#endif
69855+
69856+#ifdef CONFIG_PAX_SOFTMODE
69857+ {
69858+ .procname = "pax",
69859+ .mode = 0500,
69860+ .child = pax_table,
69861+ },
69862+#endif
69863+
69864 {
69865 .procname = "sched_child_runs_first",
69866 .data = &sysctl_sched_child_runs_first,
69867@@ -410,7 +444,7 @@ static struct ctl_table kern_table[] = {
69868 .data = core_pattern,
69869 .maxlen = CORENAME_MAX_SIZE,
69870 .mode = 0644,
69871- .proc_handler = proc_dostring,
69872+ .proc_handler = proc_dostring_coredump,
69873 },
69874 {
69875 .procname = "core_pipe_limit",
69876@@ -540,7 +574,7 @@ static struct ctl_table kern_table[] = {
69877 .data = &modprobe_path,
69878 .maxlen = KMOD_PATH_LEN,
69879 .mode = 0644,
69880- .proc_handler = proc_dostring,
69881+ .proc_handler = proc_dostring_modpriv,
69882 },
69883 {
69884 .procname = "modules_disabled",
69885@@ -707,16 +741,20 @@ static struct ctl_table kern_table[] = {
69886 .extra1 = &zero,
69887 .extra2 = &one,
69888 },
69889+#endif
69890 {
69891 .procname = "kptr_restrict",
69892 .data = &kptr_restrict,
69893 .maxlen = sizeof(int),
69894 .mode = 0644,
69895 .proc_handler = proc_dointvec_minmax_sysadmin,
69896+#ifdef CONFIG_GRKERNSEC_HIDESYM
69897+ .extra1 = &two,
69898+#else
69899 .extra1 = &zero,
69900+#endif
69901 .extra2 = &two,
69902 },
69903-#endif
69904 {
69905 .procname = "ngroups_max",
69906 .data = &ngroups_max,
69907@@ -1215,6 +1253,13 @@ static struct ctl_table vm_table[] = {
69908 .proc_handler = proc_dointvec_minmax,
69909 .extra1 = &zero,
69910 },
69911+ {
69912+ .procname = "heap_stack_gap",
69913+ .data = &sysctl_heap_stack_gap,
69914+ .maxlen = sizeof(sysctl_heap_stack_gap),
69915+ .mode = 0644,
69916+ .proc_handler = proc_doulongvec_minmax,
69917+ },
69918 #else
69919 {
69920 .procname = "nr_trim_pages",
69921@@ -1498,7 +1543,7 @@ static struct ctl_table fs_table[] = {
69922 .data = &suid_dumpable,
69923 .maxlen = sizeof(int),
69924 .mode = 0644,
69925- .proc_handler = proc_dointvec_minmax,
69926+ .proc_handler = proc_dointvec_minmax_coredump,
69927 .extra1 = &zero,
69928 .extra2 = &two,
69929 },
69930@@ -1645,6 +1690,16 @@ int proc_dostring(struct ctl_table *table, int write,
69931 buffer, lenp, ppos);
69932 }
69933
69934+int proc_dostring_modpriv(struct ctl_table *table, int write,
69935+ void __user *buffer, size_t *lenp, loff_t *ppos)
69936+{
69937+ if (write && !capable(CAP_SYS_MODULE))
69938+ return -EPERM;
69939+
69940+ return _proc_do_string(table->data, table->maxlen, write,
69941+ buffer, lenp, ppos);
69942+}
69943+
69944 static size_t proc_skip_spaces(char **buf)
69945 {
69946 size_t ret;
69947@@ -1750,6 +1805,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
69948 len = strlen(tmp);
69949 if (len > *size)
69950 len = *size;
69951+ if (len > sizeof(tmp))
69952+ len = sizeof(tmp);
69953 if (copy_to_user(*buf, tmp, len))
69954 return -EFAULT;
69955 *size -= len;
69956@@ -1942,7 +1999,6 @@ static int proc_taint(struct ctl_table *table, int write,
69957 return err;
69958 }
69959
69960-#ifdef CONFIG_PRINTK
69961 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69962 void __user *buffer, size_t *lenp, loff_t *ppos)
69963 {
69964@@ -1951,7 +2007,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69965
69966 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
69967 }
69968-#endif
69969
69970 struct do_proc_dointvec_minmax_conv_param {
69971 int *min;
69972@@ -2009,6 +2064,34 @@ int proc_dointvec_minmax(struct ctl_table *table, int write,
69973 do_proc_dointvec_minmax_conv, &param);
69974 }
69975
69976+static void validate_coredump_safety(void)
69977+{
69978+ if (suid_dumpable == SUID_DUMPABLE_SAFE &&
69979+ core_pattern[0] != '/' && core_pattern[0] != '|') {
69980+ printk(KERN_WARNING "Unsafe core_pattern used with "\
69981+ "suid_dumpable=2. Pipe handler or fully qualified "\
69982+ "core dump path required.\n");
69983+ }
69984+}
69985+
69986+static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
69987+ void __user *buffer, size_t *lenp, loff_t *ppos)
69988+{
69989+ int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
69990+ if (!error)
69991+ validate_coredump_safety();
69992+ return error;
69993+}
69994+
69995+static int proc_dostring_coredump(struct ctl_table *table, int write,
69996+ void __user *buffer, size_t *lenp, loff_t *ppos)
69997+{
69998+ int error = proc_dostring(table, write, buffer, lenp, ppos);
69999+ if (!error)
70000+ validate_coredump_safety();
70001+ return error;
70002+}
70003+
70004 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
70005 void __user *buffer,
70006 size_t *lenp, loff_t *ppos,
70007@@ -2066,8 +2149,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
70008 *i = val;
70009 } else {
70010 val = convdiv * (*i) / convmul;
70011- if (!first)
70012+ if (!first) {
70013 err = proc_put_char(&buffer, &left, '\t');
70014+ if (err)
70015+ break;
70016+ }
70017 err = proc_put_long(&buffer, &left, val, false);
70018 if (err)
70019 break;
70020@@ -2459,6 +2545,12 @@ int proc_dostring(struct ctl_table *table, int write,
70021 return -ENOSYS;
70022 }
70023
70024+int proc_dostring_modpriv(struct ctl_table *table, int write,
70025+ void __user *buffer, size_t *lenp, loff_t *ppos)
70026+{
70027+ return -ENOSYS;
70028+}
70029+
70030 int proc_dointvec(struct ctl_table *table, int write,
70031 void __user *buffer, size_t *lenp, loff_t *ppos)
70032 {
70033@@ -2515,5 +2607,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
70034 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
70035 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
70036 EXPORT_SYMBOL(proc_dostring);
70037+EXPORT_SYMBOL(proc_dostring_modpriv);
70038 EXPORT_SYMBOL(proc_doulongvec_minmax);
70039 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
70040diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
70041index a650694..aaeeb20 100644
70042--- a/kernel/sysctl_binary.c
70043+++ b/kernel/sysctl_binary.c
70044@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
70045 int i;
70046
70047 set_fs(KERNEL_DS);
70048- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70049+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70050 set_fs(old_fs);
70051 if (result < 0)
70052 goto out_kfree;
70053@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
70054 }
70055
70056 set_fs(KERNEL_DS);
70057- result = vfs_write(file, buffer, str - buffer, &pos);
70058+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70059 set_fs(old_fs);
70060 if (result < 0)
70061 goto out_kfree;
70062@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
70063 int i;
70064
70065 set_fs(KERNEL_DS);
70066- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70067+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70068 set_fs(old_fs);
70069 if (result < 0)
70070 goto out_kfree;
70071@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
70072 }
70073
70074 set_fs(KERNEL_DS);
70075- result = vfs_write(file, buffer, str - buffer, &pos);
70076+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70077 set_fs(old_fs);
70078 if (result < 0)
70079 goto out_kfree;
70080@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
70081 int i;
70082
70083 set_fs(KERNEL_DS);
70084- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70085+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70086 set_fs(old_fs);
70087 if (result < 0)
70088 goto out;
70089@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70090 __le16 dnaddr;
70091
70092 set_fs(KERNEL_DS);
70093- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70094+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70095 set_fs(old_fs);
70096 if (result < 0)
70097 goto out;
70098@@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70099 le16_to_cpu(dnaddr) & 0x3ff);
70100
70101 set_fs(KERNEL_DS);
70102- result = vfs_write(file, buf, len, &pos);
70103+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
70104 set_fs(old_fs);
70105 if (result < 0)
70106 goto out;
70107diff --git a/kernel/taskstats.c b/kernel/taskstats.c
70108index e660464..c8b9e67 100644
70109--- a/kernel/taskstats.c
70110+++ b/kernel/taskstats.c
70111@@ -27,9 +27,12 @@
70112 #include <linux/cgroup.h>
70113 #include <linux/fs.h>
70114 #include <linux/file.h>
70115+#include <linux/grsecurity.h>
70116 #include <net/genetlink.h>
70117 #include <linux/atomic.h>
70118
70119+extern int gr_is_taskstats_denied(int pid);
70120+
70121 /*
70122 * Maximum length of a cpumask that can be specified in
70123 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
70124@@ -556,6 +559,9 @@ err:
70125
70126 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
70127 {
70128+ if (gr_is_taskstats_denied(current->pid))
70129+ return -EACCES;
70130+
70131 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
70132 return cmd_attr_register_cpumask(info);
70133 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
70134diff --git a/kernel/time.c b/kernel/time.c
70135index ba744cf..267b7c5 100644
70136--- a/kernel/time.c
70137+++ b/kernel/time.c
70138@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
70139 return error;
70140
70141 if (tz) {
70142+ /* we log in do_settimeofday called below, so don't log twice
70143+ */
70144+ if (!tv)
70145+ gr_log_timechange();
70146+
70147 sys_tz = *tz;
70148 update_vsyscall_tz();
70149 if (firsttime) {
70150diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
70151index aa27d39..34d221c 100644
70152--- a/kernel/time/alarmtimer.c
70153+++ b/kernel/time/alarmtimer.c
70154@@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
70155 struct platform_device *pdev;
70156 int error = 0;
70157 int i;
70158- struct k_clock alarm_clock = {
70159+ static struct k_clock alarm_clock = {
70160 .clock_getres = alarm_clock_getres,
70161 .clock_get = alarm_clock_get,
70162 .timer_create = alarm_timer_create,
70163diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
70164index f113755..ec24223 100644
70165--- a/kernel/time/tick-broadcast.c
70166+++ b/kernel/time/tick-broadcast.c
70167@@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
70168 * then clear the broadcast bit.
70169 */
70170 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
70171- int cpu = smp_processor_id();
70172+ cpu = smp_processor_id();
70173
70174 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
70175 tick_broadcast_clear_oneshot(cpu);
70176diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
70177index 3447cfa..291806b 100644
70178--- a/kernel/time/timekeeping.c
70179+++ b/kernel/time/timekeeping.c
70180@@ -14,6 +14,7 @@
70181 #include <linux/init.h>
70182 #include <linux/mm.h>
70183 #include <linux/sched.h>
70184+#include <linux/grsecurity.h>
70185 #include <linux/syscore_ops.h>
70186 #include <linux/clocksource.h>
70187 #include <linux/jiffies.h>
70188@@ -387,6 +388,8 @@ int do_settimeofday(const struct timespec *tv)
70189 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
70190 return -EINVAL;
70191
70192+ gr_log_timechange();
70193+
70194 write_seqlock_irqsave(&timekeeper.lock, flags);
70195
70196 timekeeping_forward_now();
70197diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
70198index 3258455..f35227d 100644
70199--- a/kernel/time/timer_list.c
70200+++ b/kernel/time/timer_list.c
70201@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
70202
70203 static void print_name_offset(struct seq_file *m, void *sym)
70204 {
70205+#ifdef CONFIG_GRKERNSEC_HIDESYM
70206+ SEQ_printf(m, "<%p>", NULL);
70207+#else
70208 char symname[KSYM_NAME_LEN];
70209
70210 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
70211 SEQ_printf(m, "<%pK>", sym);
70212 else
70213 SEQ_printf(m, "%s", symname);
70214+#endif
70215 }
70216
70217 static void
70218@@ -112,7 +116,11 @@ next_one:
70219 static void
70220 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
70221 {
70222+#ifdef CONFIG_GRKERNSEC_HIDESYM
70223+ SEQ_printf(m, " .base: %p\n", NULL);
70224+#else
70225 SEQ_printf(m, " .base: %pK\n", base);
70226+#endif
70227 SEQ_printf(m, " .index: %d\n",
70228 base->index);
70229 SEQ_printf(m, " .resolution: %Lu nsecs\n",
70230@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
70231 {
70232 struct proc_dir_entry *pe;
70233
70234+#ifdef CONFIG_GRKERNSEC_PROC_ADD
70235+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
70236+#else
70237 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
70238+#endif
70239 if (!pe)
70240 return -ENOMEM;
70241 return 0;
70242diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
70243index 0b537f2..9e71eca 100644
70244--- a/kernel/time/timer_stats.c
70245+++ b/kernel/time/timer_stats.c
70246@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
70247 static unsigned long nr_entries;
70248 static struct entry entries[MAX_ENTRIES];
70249
70250-static atomic_t overflow_count;
70251+static atomic_unchecked_t overflow_count;
70252
70253 /*
70254 * The entries are in a hash-table, for fast lookup:
70255@@ -140,7 +140,7 @@ static void reset_entries(void)
70256 nr_entries = 0;
70257 memset(entries, 0, sizeof(entries));
70258 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
70259- atomic_set(&overflow_count, 0);
70260+ atomic_set_unchecked(&overflow_count, 0);
70261 }
70262
70263 static struct entry *alloc_entry(void)
70264@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70265 if (likely(entry))
70266 entry->count++;
70267 else
70268- atomic_inc(&overflow_count);
70269+ atomic_inc_unchecked(&overflow_count);
70270
70271 out_unlock:
70272 raw_spin_unlock_irqrestore(lock, flags);
70273@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70274
70275 static void print_name_offset(struct seq_file *m, unsigned long addr)
70276 {
70277+#ifdef CONFIG_GRKERNSEC_HIDESYM
70278+ seq_printf(m, "<%p>", NULL);
70279+#else
70280 char symname[KSYM_NAME_LEN];
70281
70282 if (lookup_symbol_name(addr, symname) < 0)
70283 seq_printf(m, "<%p>", (void *)addr);
70284 else
70285 seq_printf(m, "%s", symname);
70286+#endif
70287 }
70288
70289 static int tstats_show(struct seq_file *m, void *v)
70290@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
70291
70292 seq_puts(m, "Timer Stats Version: v0.2\n");
70293 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
70294- if (atomic_read(&overflow_count))
70295+ if (atomic_read_unchecked(&overflow_count))
70296 seq_printf(m, "Overflow: %d entries\n",
70297- atomic_read(&overflow_count));
70298+ atomic_read_unchecked(&overflow_count));
70299
70300 for (i = 0; i < nr_entries; i++) {
70301 entry = entries + i;
70302@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
70303 {
70304 struct proc_dir_entry *pe;
70305
70306+#ifdef CONFIG_GRKERNSEC_PROC_ADD
70307+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
70308+#else
70309 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
70310+#endif
70311 if (!pe)
70312 return -ENOMEM;
70313 return 0;
70314diff --git a/kernel/timer.c b/kernel/timer.c
70315index 6ec7e7e..cbc448b 100644
70316--- a/kernel/timer.c
70317+++ b/kernel/timer.c
70318@@ -1362,7 +1362,7 @@ void update_process_times(int user_tick)
70319 /*
70320 * This function runs timers and the timer-tq in bottom half context.
70321 */
70322-static void run_timer_softirq(struct softirq_action *h)
70323+static void run_timer_softirq(void)
70324 {
70325 struct tvec_base *base = __this_cpu_read(tvec_bases);
70326
70327diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
70328index c0bd030..62a1927 100644
70329--- a/kernel/trace/blktrace.c
70330+++ b/kernel/trace/blktrace.c
70331@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
70332 struct blk_trace *bt = filp->private_data;
70333 char buf[16];
70334
70335- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
70336+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
70337
70338 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
70339 }
70340@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
70341 return 1;
70342
70343 bt = buf->chan->private_data;
70344- atomic_inc(&bt->dropped);
70345+ atomic_inc_unchecked(&bt->dropped);
70346 return 0;
70347 }
70348
70349@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
70350
70351 bt->dir = dir;
70352 bt->dev = dev;
70353- atomic_set(&bt->dropped, 0);
70354+ atomic_set_unchecked(&bt->dropped, 0);
70355
70356 ret = -EIO;
70357 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
70358diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
70359index a008663..30d7429 100644
70360--- a/kernel/trace/ftrace.c
70361+++ b/kernel/trace/ftrace.c
70362@@ -1785,12 +1785,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
70363 if (unlikely(ftrace_disabled))
70364 return 0;
70365
70366+ ret = ftrace_arch_code_modify_prepare();
70367+ FTRACE_WARN_ON(ret);
70368+ if (ret)
70369+ return 0;
70370+
70371 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
70372+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
70373 if (ret) {
70374 ftrace_bug(ret, ip);
70375- return 0;
70376 }
70377- return 1;
70378+ return ret ? 0 : 1;
70379 }
70380
70381 /*
70382@@ -2885,7 +2890,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
70383
70384 int
70385 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
70386- void *data)
70387+ void *data)
70388 {
70389 struct ftrace_func_probe *entry;
70390 struct ftrace_page *pg;
70391@@ -3697,8 +3702,10 @@ static int ftrace_process_locs(struct module *mod,
70392 if (!count)
70393 return 0;
70394
70395+ pax_open_kernel();
70396 sort(start, count, sizeof(*start),
70397 ftrace_cmp_ips, ftrace_swap_ips);
70398+ pax_close_kernel();
70399
70400 start_pg = ftrace_allocate_pages(count);
70401 if (!start_pg)
70402diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
70403index a7fa070..403bc8d 100644
70404--- a/kernel/trace/trace.c
70405+++ b/kernel/trace/trace.c
70406@@ -4421,10 +4421,9 @@ static const struct file_operations tracing_dyn_info_fops = {
70407 };
70408 #endif
70409
70410-static struct dentry *d_tracer;
70411-
70412 struct dentry *tracing_init_dentry(void)
70413 {
70414+ static struct dentry *d_tracer;
70415 static int once;
70416
70417 if (d_tracer)
70418@@ -4444,10 +4443,9 @@ struct dentry *tracing_init_dentry(void)
70419 return d_tracer;
70420 }
70421
70422-static struct dentry *d_percpu;
70423-
70424 struct dentry *tracing_dentry_percpu(void)
70425 {
70426+ static struct dentry *d_percpu;
70427 static int once;
70428 struct dentry *d_tracer;
70429
70430diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
70431index 29111da..d190fe2 100644
70432--- a/kernel/trace/trace_events.c
70433+++ b/kernel/trace/trace_events.c
70434@@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
70435 struct ftrace_module_file_ops {
70436 struct list_head list;
70437 struct module *mod;
70438- struct file_operations id;
70439- struct file_operations enable;
70440- struct file_operations format;
70441- struct file_operations filter;
70442 };
70443
70444 static struct ftrace_module_file_ops *
70445@@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
70446
70447 file_ops->mod = mod;
70448
70449- file_ops->id = ftrace_event_id_fops;
70450- file_ops->id.owner = mod;
70451-
70452- file_ops->enable = ftrace_enable_fops;
70453- file_ops->enable.owner = mod;
70454-
70455- file_ops->filter = ftrace_event_filter_fops;
70456- file_ops->filter.owner = mod;
70457-
70458- file_ops->format = ftrace_event_format_fops;
70459- file_ops->format.owner = mod;
70460+ pax_open_kernel();
70461+ *(void **)&mod->trace_id.owner = mod;
70462+ *(void **)&mod->trace_enable.owner = mod;
70463+ *(void **)&mod->trace_filter.owner = mod;
70464+ *(void **)&mod->trace_format.owner = mod;
70465+ pax_close_kernel();
70466
70467 list_add(&file_ops->list, &ftrace_module_file_list);
70468
70469@@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
70470
70471 for_each_event(call, start, end) {
70472 __trace_add_event_call(*call, mod,
70473- &file_ops->id, &file_ops->enable,
70474- &file_ops->filter, &file_ops->format);
70475+ &mod->trace_id, &mod->trace_enable,
70476+ &mod->trace_filter, &mod->trace_format);
70477 }
70478 }
70479
70480diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
70481index fd3c8aa..5f324a6 100644
70482--- a/kernel/trace/trace_mmiotrace.c
70483+++ b/kernel/trace/trace_mmiotrace.c
70484@@ -24,7 +24,7 @@ struct header_iter {
70485 static struct trace_array *mmio_trace_array;
70486 static bool overrun_detected;
70487 static unsigned long prev_overruns;
70488-static atomic_t dropped_count;
70489+static atomic_unchecked_t dropped_count;
70490
70491 static void mmio_reset_data(struct trace_array *tr)
70492 {
70493@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
70494
70495 static unsigned long count_overruns(struct trace_iterator *iter)
70496 {
70497- unsigned long cnt = atomic_xchg(&dropped_count, 0);
70498+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
70499 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
70500
70501 if (over > prev_overruns)
70502@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
70503 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
70504 sizeof(*entry), 0, pc);
70505 if (!event) {
70506- atomic_inc(&dropped_count);
70507+ atomic_inc_unchecked(&dropped_count);
70508 return;
70509 }
70510 entry = ring_buffer_event_data(event);
70511@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
70512 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
70513 sizeof(*entry), 0, pc);
70514 if (!event) {
70515- atomic_inc(&dropped_count);
70516+ atomic_inc_unchecked(&dropped_count);
70517 return;
70518 }
70519 entry = ring_buffer_event_data(event);
70520diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
70521index df611a0..10d8b32 100644
70522--- a/kernel/trace/trace_output.c
70523+++ b/kernel/trace/trace_output.c
70524@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
70525
70526 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
70527 if (!IS_ERR(p)) {
70528- p = mangle_path(s->buffer + s->len, p, "\n");
70529+ p = mangle_path(s->buffer + s->len, p, "\n\\");
70530 if (p) {
70531 s->len = p - s->buffer;
70532 return 1;
70533diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
70534index d4545f4..a9010a1 100644
70535--- a/kernel/trace/trace_stack.c
70536+++ b/kernel/trace/trace_stack.c
70537@@ -53,7 +53,7 @@ static inline void check_stack(void)
70538 return;
70539
70540 /* we do not handle interrupt stacks yet */
70541- if (!object_is_on_stack(&this_size))
70542+ if (!object_starts_on_stack(&this_size))
70543 return;
70544
70545 local_irq_save(flags);
70546diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
70547index ff5bdee..3eaeba6 100644
70548--- a/lib/Kconfig.debug
70549+++ b/lib/Kconfig.debug
70550@@ -1165,6 +1165,7 @@ config LATENCYTOP
70551 depends on DEBUG_KERNEL
70552 depends on STACKTRACE_SUPPORT
70553 depends on PROC_FS
70554+ depends on !GRKERNSEC_HIDESYM
70555 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
70556 select KALLSYMS
70557 select KALLSYMS_ALL
70558diff --git a/lib/bitmap.c b/lib/bitmap.c
70559index 06fdfa1..97c5c7d 100644
70560--- a/lib/bitmap.c
70561+++ b/lib/bitmap.c
70562@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
70563 {
70564 int c, old_c, totaldigits, ndigits, nchunks, nbits;
70565 u32 chunk;
70566- const char __user __force *ubuf = (const char __user __force *)buf;
70567+ const char __user *ubuf = (const char __force_user *)buf;
70568
70569 bitmap_zero(maskp, nmaskbits);
70570
70571@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
70572 {
70573 if (!access_ok(VERIFY_READ, ubuf, ulen))
70574 return -EFAULT;
70575- return __bitmap_parse((const char __force *)ubuf,
70576+ return __bitmap_parse((const char __force_kernel *)ubuf,
70577 ulen, 1, maskp, nmaskbits);
70578
70579 }
70580@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
70581 {
70582 unsigned a, b;
70583 int c, old_c, totaldigits;
70584- const char __user __force *ubuf = (const char __user __force *)buf;
70585+ const char __user *ubuf = (const char __force_user *)buf;
70586 int exp_digit, in_range;
70587
70588 totaldigits = c = 0;
70589@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
70590 {
70591 if (!access_ok(VERIFY_READ, ubuf, ulen))
70592 return -EFAULT;
70593- return __bitmap_parselist((const char __force *)ubuf,
70594+ return __bitmap_parselist((const char __force_kernel *)ubuf,
70595 ulen, 1, maskp, nmaskbits);
70596 }
70597 EXPORT_SYMBOL(bitmap_parselist_user);
70598diff --git a/lib/bug.c b/lib/bug.c
70599index a28c141..2bd3d95 100644
70600--- a/lib/bug.c
70601+++ b/lib/bug.c
70602@@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
70603 return BUG_TRAP_TYPE_NONE;
70604
70605 bug = find_bug(bugaddr);
70606+ if (!bug)
70607+ return BUG_TRAP_TYPE_NONE;
70608
70609 file = NULL;
70610 line = 0;
70611diff --git a/lib/debugobjects.c b/lib/debugobjects.c
70612index d11808c..dc2d6f8 100644
70613--- a/lib/debugobjects.c
70614+++ b/lib/debugobjects.c
70615@@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
70616 if (limit > 4)
70617 return;
70618
70619- is_on_stack = object_is_on_stack(addr);
70620+ is_on_stack = object_starts_on_stack(addr);
70621 if (is_on_stack == onstack)
70622 return;
70623
70624diff --git a/lib/devres.c b/lib/devres.c
70625index 80b9c76..9e32279 100644
70626--- a/lib/devres.c
70627+++ b/lib/devres.c
70628@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
70629 void devm_iounmap(struct device *dev, void __iomem *addr)
70630 {
70631 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
70632- (void *)addr));
70633+ (void __force *)addr));
70634 iounmap(addr);
70635 }
70636 EXPORT_SYMBOL(devm_iounmap);
70637@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
70638 {
70639 ioport_unmap(addr);
70640 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
70641- devm_ioport_map_match, (void *)addr));
70642+ devm_ioport_map_match, (void __force *)addr));
70643 }
70644 EXPORT_SYMBOL(devm_ioport_unmap);
70645
70646diff --git a/lib/dma-debug.c b/lib/dma-debug.c
70647index 66ce414..6f0a0dd 100644
70648--- a/lib/dma-debug.c
70649+++ b/lib/dma-debug.c
70650@@ -924,7 +924,7 @@ out:
70651
70652 static void check_for_stack(struct device *dev, void *addr)
70653 {
70654- if (object_is_on_stack(addr))
70655+ if (object_starts_on_stack(addr))
70656 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
70657 "stack [addr=%p]\n", addr);
70658 }
70659diff --git a/lib/inflate.c b/lib/inflate.c
70660index 013a761..c28f3fc 100644
70661--- a/lib/inflate.c
70662+++ b/lib/inflate.c
70663@@ -269,7 +269,7 @@ static void free(void *where)
70664 malloc_ptr = free_mem_ptr;
70665 }
70666 #else
70667-#define malloc(a) kmalloc(a, GFP_KERNEL)
70668+#define malloc(a) kmalloc((a), GFP_KERNEL)
70669 #define free(a) kfree(a)
70670 #endif
70671
70672diff --git a/lib/ioremap.c b/lib/ioremap.c
70673index 0c9216c..863bd89 100644
70674--- a/lib/ioremap.c
70675+++ b/lib/ioremap.c
70676@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
70677 unsigned long next;
70678
70679 phys_addr -= addr;
70680- pmd = pmd_alloc(&init_mm, pud, addr);
70681+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
70682 if (!pmd)
70683 return -ENOMEM;
70684 do {
70685@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
70686 unsigned long next;
70687
70688 phys_addr -= addr;
70689- pud = pud_alloc(&init_mm, pgd, addr);
70690+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
70691 if (!pud)
70692 return -ENOMEM;
70693 do {
70694diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
70695index bd2bea9..6b3c95e 100644
70696--- a/lib/is_single_threaded.c
70697+++ b/lib/is_single_threaded.c
70698@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
70699 struct task_struct *p, *t;
70700 bool ret;
70701
70702+ if (!mm)
70703+ return true;
70704+
70705 if (atomic_read(&task->signal->live) != 1)
70706 return false;
70707
70708diff --git a/lib/radix-tree.c b/lib/radix-tree.c
70709index e796429..6e38f9f 100644
70710--- a/lib/radix-tree.c
70711+++ b/lib/radix-tree.c
70712@@ -92,7 +92,7 @@ struct radix_tree_preload {
70713 int nr;
70714 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
70715 };
70716-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
70717+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
70718
70719 static inline void *ptr_to_indirect(void *ptr)
70720 {
70721diff --git a/lib/vsprintf.c b/lib/vsprintf.c
70722index 598a73e..5c5aeb5 100644
70723--- a/lib/vsprintf.c
70724+++ b/lib/vsprintf.c
70725@@ -16,6 +16,9 @@
70726 * - scnprintf and vscnprintf
70727 */
70728
70729+#ifdef CONFIG_GRKERNSEC_HIDESYM
70730+#define __INCLUDED_BY_HIDESYM 1
70731+#endif
70732 #include <stdarg.h>
70733 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
70734 #include <linux/types.h>
70735@@ -536,7 +539,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
70736 char sym[KSYM_SYMBOL_LEN];
70737 if (ext == 'B')
70738 sprint_backtrace(sym, value);
70739- else if (ext != 'f' && ext != 's')
70740+ else if (ext != 'f' && ext != 's' && ext != 'a')
70741 sprint_symbol(sym, value);
70742 else
70743 sprint_symbol_no_offset(sym, value);
70744@@ -912,7 +915,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
70745 return number(buf, end, *(const netdev_features_t *)addr, spec);
70746 }
70747
70748+#ifdef CONFIG_GRKERNSEC_HIDESYM
70749+int kptr_restrict __read_mostly = 2;
70750+#else
70751 int kptr_restrict __read_mostly;
70752+#endif
70753
70754 /*
70755 * Show a '%p' thing. A kernel extension is that the '%p' is followed
70756@@ -926,6 +933,8 @@ int kptr_restrict __read_mostly;
70757 * - 'S' For symbolic direct pointers with offset
70758 * - 's' For symbolic direct pointers without offset
70759 * - 'B' For backtraced symbolic direct pointers with offset
70760+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
70761+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
70762 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
70763 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
70764 * - 'M' For a 6-byte MAC address, it prints the address in the
70765@@ -973,12 +982,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70766
70767 if (!ptr && *fmt != 'K') {
70768 /*
70769- * Print (null) with the same width as a pointer so it makes
70770+ * Print (nil) with the same width as a pointer so it makes
70771 * tabular output look nice.
70772 */
70773 if (spec.field_width == -1)
70774 spec.field_width = default_width;
70775- return string(buf, end, "(null)", spec);
70776+ return string(buf, end, "(nil)", spec);
70777 }
70778
70779 switch (*fmt) {
70780@@ -988,6 +997,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70781 /* Fallthrough */
70782 case 'S':
70783 case 's':
70784+#ifdef CONFIG_GRKERNSEC_HIDESYM
70785+ break;
70786+#else
70787+ return symbol_string(buf, end, ptr, spec, *fmt);
70788+#endif
70789+ case 'A':
70790+ case 'a':
70791 case 'B':
70792 return symbol_string(buf, end, ptr, spec, *fmt);
70793 case 'R':
70794@@ -1025,6 +1041,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70795 va_end(va);
70796 return buf;
70797 }
70798+ case 'P':
70799+ break;
70800 case 'K':
70801 /*
70802 * %pK cannot be used in IRQ context because its test
70803@@ -1048,6 +1066,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70804 }
70805 break;
70806 }
70807+
70808+#ifdef CONFIG_GRKERNSEC_HIDESYM
70809+ /* 'P' = approved pointers to copy to userland,
70810+ as in the /proc/kallsyms case, as we make it display nothing
70811+ for non-root users, and the real contents for root users
70812+ Also ignore 'K' pointers, since we force their NULLing for non-root users
70813+ above
70814+ */
70815+ if (ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
70816+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
70817+ dump_stack();
70818+ ptr = NULL;
70819+ }
70820+#endif
70821+
70822 spec.flags |= SMALL;
70823 if (spec.field_width == -1) {
70824 spec.field_width = default_width;
70825@@ -1759,11 +1792,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70826 typeof(type) value; \
70827 if (sizeof(type) == 8) { \
70828 args = PTR_ALIGN(args, sizeof(u32)); \
70829- *(u32 *)&value = *(u32 *)args; \
70830- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
70831+ *(u32 *)&value = *(const u32 *)args; \
70832+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
70833 } else { \
70834 args = PTR_ALIGN(args, sizeof(type)); \
70835- value = *(typeof(type) *)args; \
70836+ value = *(const typeof(type) *)args; \
70837 } \
70838 args += sizeof(type); \
70839 value; \
70840@@ -1826,7 +1859,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70841 case FORMAT_TYPE_STR: {
70842 const char *str_arg = args;
70843 args += strlen(str_arg) + 1;
70844- str = string(str, end, (char *)str_arg, spec);
70845+ str = string(str, end, str_arg, spec);
70846 break;
70847 }
70848
70849diff --git a/localversion-grsec b/localversion-grsec
70850new file mode 100644
70851index 0000000..7cd6065
70852--- /dev/null
70853+++ b/localversion-grsec
70854@@ -0,0 +1 @@
70855+-grsec
70856diff --git a/mm/Kconfig b/mm/Kconfig
70857index 82fed4e..979e814 100644
70858--- a/mm/Kconfig
70859+++ b/mm/Kconfig
70860@@ -247,10 +247,10 @@ config KSM
70861 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
70862
70863 config DEFAULT_MMAP_MIN_ADDR
70864- int "Low address space to protect from user allocation"
70865+ int "Low address space to protect from user allocation"
70866 depends on MMU
70867- default 4096
70868- help
70869+ default 65536
70870+ help
70871 This is the portion of low virtual memory which should be protected
70872 from userspace allocation. Keeping a user from writing to low pages
70873 can help reduce the impact of kernel NULL pointer bugs.
70874@@ -280,7 +280,7 @@ config MEMORY_FAILURE
70875
70876 config HWPOISON_INJECT
70877 tristate "HWPoison pages injector"
70878- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
70879+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
70880 select PROC_PAGE_MONITOR
70881
70882 config NOMMU_INITIAL_TRIM_EXCESS
70883diff --git a/mm/filemap.c b/mm/filemap.c
70884index a4a5260..6151dc5 100644
70885--- a/mm/filemap.c
70886+++ b/mm/filemap.c
70887@@ -1723,7 +1723,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
70888 struct address_space *mapping = file->f_mapping;
70889
70890 if (!mapping->a_ops->readpage)
70891- return -ENOEXEC;
70892+ return -ENODEV;
70893 file_accessed(file);
70894 vma->vm_ops = &generic_file_vm_ops;
70895 vma->vm_flags |= VM_CAN_NONLINEAR;
70896@@ -2064,6 +2064,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
70897 *pos = i_size_read(inode);
70898
70899 if (limit != RLIM_INFINITY) {
70900+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
70901 if (*pos >= limit) {
70902 send_sig(SIGXFSZ, current, 0);
70903 return -EFBIG;
70904diff --git a/mm/fremap.c b/mm/fremap.c
70905index 9ed4fd4..c42648d 100644
70906--- a/mm/fremap.c
70907+++ b/mm/fremap.c
70908@@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
70909 retry:
70910 vma = find_vma(mm, start);
70911
70912+#ifdef CONFIG_PAX_SEGMEXEC
70913+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
70914+ goto out;
70915+#endif
70916+
70917 /*
70918 * Make sure the vma is shared, that it supports prefaulting,
70919 * and that the remapped range is valid and fully within
70920diff --git a/mm/highmem.c b/mm/highmem.c
70921index 57d82c6..e9e0552 100644
70922--- a/mm/highmem.c
70923+++ b/mm/highmem.c
70924@@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
70925 * So no dangers, even with speculative execution.
70926 */
70927 page = pte_page(pkmap_page_table[i]);
70928+ pax_open_kernel();
70929 pte_clear(&init_mm, (unsigned long)page_address(page),
70930 &pkmap_page_table[i]);
70931-
70932+ pax_close_kernel();
70933 set_page_address(page, NULL);
70934 need_flush = 1;
70935 }
70936@@ -186,9 +187,11 @@ start:
70937 }
70938 }
70939 vaddr = PKMAP_ADDR(last_pkmap_nr);
70940+
70941+ pax_open_kernel();
70942 set_pte_at(&init_mm, vaddr,
70943 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
70944-
70945+ pax_close_kernel();
70946 pkmap_count[last_pkmap_nr] = 1;
70947 set_page_address(page, (void *)vaddr);
70948
70949diff --git a/mm/huge_memory.c b/mm/huge_memory.c
70950index 57c4b93..24b8f59 100644
70951--- a/mm/huge_memory.c
70952+++ b/mm/huge_memory.c
70953@@ -735,7 +735,7 @@ out:
70954 * run pte_offset_map on the pmd, if an huge pmd could
70955 * materialize from under us from a different thread.
70956 */
70957- if (unlikely(__pte_alloc(mm, vma, pmd, address)))
70958+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
70959 return VM_FAULT_OOM;
70960 /* if an huge pmd materialized from under us just retry later */
70961 if (unlikely(pmd_trans_huge(*pmd)))
70962diff --git a/mm/hugetlb.c b/mm/hugetlb.c
70963index 19558df..f7743b3 100644
70964--- a/mm/hugetlb.c
70965+++ b/mm/hugetlb.c
70966@@ -2463,6 +2463,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
70967 return 1;
70968 }
70969
70970+#ifdef CONFIG_PAX_SEGMEXEC
70971+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
70972+{
70973+ struct mm_struct *mm = vma->vm_mm;
70974+ struct vm_area_struct *vma_m;
70975+ unsigned long address_m;
70976+ pte_t *ptep_m;
70977+
70978+ vma_m = pax_find_mirror_vma(vma);
70979+ if (!vma_m)
70980+ return;
70981+
70982+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70983+ address_m = address + SEGMEXEC_TASK_SIZE;
70984+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
70985+ get_page(page_m);
70986+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
70987+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
70988+}
70989+#endif
70990+
70991 /*
70992 * Hugetlb_cow() should be called with page lock of the original hugepage held.
70993 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
70994@@ -2575,6 +2596,11 @@ retry_avoidcopy:
70995 make_huge_pte(vma, new_page, 1));
70996 page_remove_rmap(old_page);
70997 hugepage_add_new_anon_rmap(new_page, vma, address);
70998+
70999+#ifdef CONFIG_PAX_SEGMEXEC
71000+ pax_mirror_huge_pte(vma, address, new_page);
71001+#endif
71002+
71003 /* Make the old page be freed below */
71004 new_page = old_page;
71005 mmu_notifier_invalidate_range_end(mm,
71006@@ -2729,6 +2755,10 @@ retry:
71007 && (vma->vm_flags & VM_SHARED)));
71008 set_huge_pte_at(mm, address, ptep, new_pte);
71009
71010+#ifdef CONFIG_PAX_SEGMEXEC
71011+ pax_mirror_huge_pte(vma, address, page);
71012+#endif
71013+
71014 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
71015 /* Optimization, do the COW without a second fault */
71016 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
71017@@ -2758,6 +2788,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71018 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
71019 struct hstate *h = hstate_vma(vma);
71020
71021+#ifdef CONFIG_PAX_SEGMEXEC
71022+ struct vm_area_struct *vma_m;
71023+#endif
71024+
71025 address &= huge_page_mask(h);
71026
71027 ptep = huge_pte_offset(mm, address);
71028@@ -2771,6 +2805,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71029 VM_FAULT_SET_HINDEX(h - hstates);
71030 }
71031
71032+#ifdef CONFIG_PAX_SEGMEXEC
71033+ vma_m = pax_find_mirror_vma(vma);
71034+ if (vma_m) {
71035+ unsigned long address_m;
71036+
71037+ if (vma->vm_start > vma_m->vm_start) {
71038+ address_m = address;
71039+ address -= SEGMEXEC_TASK_SIZE;
71040+ vma = vma_m;
71041+ h = hstate_vma(vma);
71042+ } else
71043+ address_m = address + SEGMEXEC_TASK_SIZE;
71044+
71045+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
71046+ return VM_FAULT_OOM;
71047+ address_m &= HPAGE_MASK;
71048+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
71049+ }
71050+#endif
71051+
71052 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
71053 if (!ptep)
71054 return VM_FAULT_OOM;
71055diff --git a/mm/internal.h b/mm/internal.h
71056index 8052379..47029d1 100644
71057--- a/mm/internal.h
71058+++ b/mm/internal.h
71059@@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
71060 * in mm/page_alloc.c
71061 */
71062 extern void __free_pages_bootmem(struct page *page, unsigned int order);
71063+extern void free_compound_page(struct page *page);
71064 extern void prep_compound_page(struct page *page, unsigned long order);
71065 #ifdef CONFIG_MEMORY_FAILURE
71066 extern bool is_free_buddy_page(struct page *page);
71067diff --git a/mm/kmemleak.c b/mm/kmemleak.c
71068index 45eb621..6ccd8ea 100644
71069--- a/mm/kmemleak.c
71070+++ b/mm/kmemleak.c
71071@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
71072
71073 for (i = 0; i < object->trace_len; i++) {
71074 void *ptr = (void *)object->trace[i];
71075- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
71076+ seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
71077 }
71078 }
71079
71080diff --git a/mm/maccess.c b/mm/maccess.c
71081index d53adf9..03a24bf 100644
71082--- a/mm/maccess.c
71083+++ b/mm/maccess.c
71084@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
71085 set_fs(KERNEL_DS);
71086 pagefault_disable();
71087 ret = __copy_from_user_inatomic(dst,
71088- (__force const void __user *)src, size);
71089+ (const void __force_user *)src, size);
71090 pagefault_enable();
71091 set_fs(old_fs);
71092
71093@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
71094
71095 set_fs(KERNEL_DS);
71096 pagefault_disable();
71097- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
71098+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
71099 pagefault_enable();
71100 set_fs(old_fs);
71101
71102diff --git a/mm/madvise.c b/mm/madvise.c
71103index 14d260f..b2a80fd 100644
71104--- a/mm/madvise.c
71105+++ b/mm/madvise.c
71106@@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
71107 pgoff_t pgoff;
71108 unsigned long new_flags = vma->vm_flags;
71109
71110+#ifdef CONFIG_PAX_SEGMEXEC
71111+ struct vm_area_struct *vma_m;
71112+#endif
71113+
71114 switch (behavior) {
71115 case MADV_NORMAL:
71116 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
71117@@ -119,6 +123,13 @@ success:
71118 /*
71119 * vm_flags is protected by the mmap_sem held in write mode.
71120 */
71121+
71122+#ifdef CONFIG_PAX_SEGMEXEC
71123+ vma_m = pax_find_mirror_vma(vma);
71124+ if (vma_m)
71125+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
71126+#endif
71127+
71128 vma->vm_flags = new_flags;
71129
71130 out:
71131@@ -177,6 +188,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71132 struct vm_area_struct ** prev,
71133 unsigned long start, unsigned long end)
71134 {
71135+
71136+#ifdef CONFIG_PAX_SEGMEXEC
71137+ struct vm_area_struct *vma_m;
71138+#endif
71139+
71140 *prev = vma;
71141 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
71142 return -EINVAL;
71143@@ -189,6 +205,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71144 zap_page_range(vma, start, end - start, &details);
71145 } else
71146 zap_page_range(vma, start, end - start, NULL);
71147+
71148+#ifdef CONFIG_PAX_SEGMEXEC
71149+ vma_m = pax_find_mirror_vma(vma);
71150+ if (vma_m) {
71151+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
71152+ struct zap_details details = {
71153+ .nonlinear_vma = vma_m,
71154+ .last_index = ULONG_MAX,
71155+ };
71156+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
71157+ } else
71158+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
71159+ }
71160+#endif
71161+
71162 return 0;
71163 }
71164
71165@@ -393,6 +424,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
71166 if (end < start)
71167 goto out;
71168
71169+#ifdef CONFIG_PAX_SEGMEXEC
71170+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
71171+ if (end > SEGMEXEC_TASK_SIZE)
71172+ goto out;
71173+ } else
71174+#endif
71175+
71176+ if (end > TASK_SIZE)
71177+ goto out;
71178+
71179 error = 0;
71180 if (end == start)
71181 goto out;
71182diff --git a/mm/memory-failure.c b/mm/memory-failure.c
71183index 6de0d61..da836cf 100644
71184--- a/mm/memory-failure.c
71185+++ b/mm/memory-failure.c
71186@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
71187
71188 int sysctl_memory_failure_recovery __read_mostly = 1;
71189
71190-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71191+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71192
71193 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
71194
71195@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
71196 pfn, t->comm, t->pid);
71197 si.si_signo = SIGBUS;
71198 si.si_errno = 0;
71199- si.si_addr = (void *)addr;
71200+ si.si_addr = (void __user *)addr;
71201 #ifdef __ARCH_SI_TRAPNO
71202 si.si_trapno = trapno;
71203 #endif
71204@@ -1038,7 +1038,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71205 }
71206
71207 nr_pages = 1 << compound_trans_order(hpage);
71208- atomic_long_add(nr_pages, &mce_bad_pages);
71209+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
71210
71211 /*
71212 * We need/can do nothing about count=0 pages.
71213@@ -1068,7 +1068,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71214 if (!PageHWPoison(hpage)
71215 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
71216 || (p != hpage && TestSetPageHWPoison(hpage))) {
71217- atomic_long_sub(nr_pages, &mce_bad_pages);
71218+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71219 return 0;
71220 }
71221 set_page_hwpoison_huge_page(hpage);
71222@@ -1126,7 +1126,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71223 }
71224 if (hwpoison_filter(p)) {
71225 if (TestClearPageHWPoison(p))
71226- atomic_long_sub(nr_pages, &mce_bad_pages);
71227+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71228 unlock_page(hpage);
71229 put_page(hpage);
71230 return 0;
71231@@ -1321,7 +1321,7 @@ int unpoison_memory(unsigned long pfn)
71232 return 0;
71233 }
71234 if (TestClearPageHWPoison(p))
71235- atomic_long_sub(nr_pages, &mce_bad_pages);
71236+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71237 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
71238 return 0;
71239 }
71240@@ -1335,7 +1335,7 @@ int unpoison_memory(unsigned long pfn)
71241 */
71242 if (TestClearPageHWPoison(page)) {
71243 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
71244- atomic_long_sub(nr_pages, &mce_bad_pages);
71245+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71246 freeit = 1;
71247 if (PageHuge(page))
71248 clear_page_hwpoison_huge_page(page);
71249@@ -1448,7 +1448,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
71250 }
71251 done:
71252 if (!PageHWPoison(hpage))
71253- atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
71254+ atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
71255 set_page_hwpoison_huge_page(hpage);
71256 dequeue_hwpoisoned_huge_page(hpage);
71257 /* keep elevated page count for bad page */
71258@@ -1579,7 +1579,7 @@ int soft_offline_page(struct page *page, int flags)
71259 return ret;
71260
71261 done:
71262- atomic_long_add(1, &mce_bad_pages);
71263+ atomic_long_add_unchecked(1, &mce_bad_pages);
71264 SetPageHWPoison(page);
71265 /* keep elevated page count for bad page */
71266 return ret;
71267diff --git a/mm/memory.c b/mm/memory.c
71268index 2466d12..08be4f6 100644
71269--- a/mm/memory.c
71270+++ b/mm/memory.c
71271@@ -434,8 +434,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71272 return;
71273
71274 pmd = pmd_offset(pud, start);
71275+
71276+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
71277 pud_clear(pud);
71278 pmd_free_tlb(tlb, pmd, start);
71279+#endif
71280+
71281 }
71282
71283 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71284@@ -466,9 +470,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71285 if (end - 1 > ceiling - 1)
71286 return;
71287
71288+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
71289 pud = pud_offset(pgd, start);
71290 pgd_clear(pgd);
71291 pud_free_tlb(tlb, pud, start);
71292+#endif
71293+
71294 }
71295
71296 /*
71297@@ -1602,12 +1609,6 @@ no_page_table:
71298 return page;
71299 }
71300
71301-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
71302-{
71303- return stack_guard_page_start(vma, addr) ||
71304- stack_guard_page_end(vma, addr+PAGE_SIZE);
71305-}
71306-
71307 /**
71308 * __get_user_pages() - pin user pages in memory
71309 * @tsk: task_struct of target task
71310@@ -1680,10 +1681,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71311 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
71312 i = 0;
71313
71314- do {
71315+ while (nr_pages) {
71316 struct vm_area_struct *vma;
71317
71318- vma = find_extend_vma(mm, start);
71319+ vma = find_vma(mm, start);
71320 if (!vma && in_gate_area(mm, start)) {
71321 unsigned long pg = start & PAGE_MASK;
71322 pgd_t *pgd;
71323@@ -1731,7 +1732,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71324 goto next_page;
71325 }
71326
71327- if (!vma ||
71328+ if (!vma || start < vma->vm_start ||
71329 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
71330 !(vm_flags & vma->vm_flags))
71331 return i ? : -EFAULT;
71332@@ -1758,11 +1759,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71333 int ret;
71334 unsigned int fault_flags = 0;
71335
71336- /* For mlock, just skip the stack guard page. */
71337- if (foll_flags & FOLL_MLOCK) {
71338- if (stack_guard_page(vma, start))
71339- goto next_page;
71340- }
71341 if (foll_flags & FOLL_WRITE)
71342 fault_flags |= FAULT_FLAG_WRITE;
71343 if (nonblocking)
71344@@ -1836,7 +1832,7 @@ next_page:
71345 start += PAGE_SIZE;
71346 nr_pages--;
71347 } while (nr_pages && start < vma->vm_end);
71348- } while (nr_pages);
71349+ }
71350 return i;
71351 }
71352 EXPORT_SYMBOL(__get_user_pages);
71353@@ -2043,6 +2039,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
71354 page_add_file_rmap(page);
71355 set_pte_at(mm, addr, pte, mk_pte(page, prot));
71356
71357+#ifdef CONFIG_PAX_SEGMEXEC
71358+ pax_mirror_file_pte(vma, addr, page, ptl);
71359+#endif
71360+
71361 retval = 0;
71362 pte_unmap_unlock(pte, ptl);
71363 return retval;
71364@@ -2077,10 +2077,22 @@ out:
71365 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
71366 struct page *page)
71367 {
71368+
71369+#ifdef CONFIG_PAX_SEGMEXEC
71370+ struct vm_area_struct *vma_m;
71371+#endif
71372+
71373 if (addr < vma->vm_start || addr >= vma->vm_end)
71374 return -EFAULT;
71375 if (!page_count(page))
71376 return -EINVAL;
71377+
71378+#ifdef CONFIG_PAX_SEGMEXEC
71379+ vma_m = pax_find_mirror_vma(vma);
71380+ if (vma_m)
71381+ vma_m->vm_flags |= VM_INSERTPAGE;
71382+#endif
71383+
71384 vma->vm_flags |= VM_INSERTPAGE;
71385 return insert_page(vma, addr, page, vma->vm_page_prot);
71386 }
71387@@ -2166,6 +2178,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
71388 unsigned long pfn)
71389 {
71390 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
71391+ BUG_ON(vma->vm_mirror);
71392
71393 if (addr < vma->vm_start || addr >= vma->vm_end)
71394 return -EFAULT;
71395@@ -2373,7 +2386,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
71396
71397 BUG_ON(pud_huge(*pud));
71398
71399- pmd = pmd_alloc(mm, pud, addr);
71400+ pmd = (mm == &init_mm) ?
71401+ pmd_alloc_kernel(mm, pud, addr) :
71402+ pmd_alloc(mm, pud, addr);
71403 if (!pmd)
71404 return -ENOMEM;
71405 do {
71406@@ -2393,7 +2408,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
71407 unsigned long next;
71408 int err;
71409
71410- pud = pud_alloc(mm, pgd, addr);
71411+ pud = (mm == &init_mm) ?
71412+ pud_alloc_kernel(mm, pgd, addr) :
71413+ pud_alloc(mm, pgd, addr);
71414 if (!pud)
71415 return -ENOMEM;
71416 do {
71417@@ -2481,6 +2498,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
71418 copy_user_highpage(dst, src, va, vma);
71419 }
71420
71421+#ifdef CONFIG_PAX_SEGMEXEC
71422+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
71423+{
71424+ struct mm_struct *mm = vma->vm_mm;
71425+ spinlock_t *ptl;
71426+ pte_t *pte, entry;
71427+
71428+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
71429+ entry = *pte;
71430+ if (!pte_present(entry)) {
71431+ if (!pte_none(entry)) {
71432+ BUG_ON(pte_file(entry));
71433+ free_swap_and_cache(pte_to_swp_entry(entry));
71434+ pte_clear_not_present_full(mm, address, pte, 0);
71435+ }
71436+ } else {
71437+ struct page *page;
71438+
71439+ flush_cache_page(vma, address, pte_pfn(entry));
71440+ entry = ptep_clear_flush(vma, address, pte);
71441+ BUG_ON(pte_dirty(entry));
71442+ page = vm_normal_page(vma, address, entry);
71443+ if (page) {
71444+ update_hiwater_rss(mm);
71445+ if (PageAnon(page))
71446+ dec_mm_counter_fast(mm, MM_ANONPAGES);
71447+ else
71448+ dec_mm_counter_fast(mm, MM_FILEPAGES);
71449+ page_remove_rmap(page);
71450+ page_cache_release(page);
71451+ }
71452+ }
71453+ pte_unmap_unlock(pte, ptl);
71454+}
71455+
71456+/* PaX: if vma is mirrored, synchronize the mirror's PTE
71457+ *
71458+ * the ptl of the lower mapped page is held on entry and is not released on exit
71459+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
71460+ */
71461+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71462+{
71463+ struct mm_struct *mm = vma->vm_mm;
71464+ unsigned long address_m;
71465+ spinlock_t *ptl_m;
71466+ struct vm_area_struct *vma_m;
71467+ pmd_t *pmd_m;
71468+ pte_t *pte_m, entry_m;
71469+
71470+ BUG_ON(!page_m || !PageAnon(page_m));
71471+
71472+ vma_m = pax_find_mirror_vma(vma);
71473+ if (!vma_m)
71474+ return;
71475+
71476+ BUG_ON(!PageLocked(page_m));
71477+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71478+ address_m = address + SEGMEXEC_TASK_SIZE;
71479+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71480+ pte_m = pte_offset_map(pmd_m, address_m);
71481+ ptl_m = pte_lockptr(mm, pmd_m);
71482+ if (ptl != ptl_m) {
71483+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71484+ if (!pte_none(*pte_m))
71485+ goto out;
71486+ }
71487+
71488+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71489+ page_cache_get(page_m);
71490+ page_add_anon_rmap(page_m, vma_m, address_m);
71491+ inc_mm_counter_fast(mm, MM_ANONPAGES);
71492+ set_pte_at(mm, address_m, pte_m, entry_m);
71493+ update_mmu_cache(vma_m, address_m, entry_m);
71494+out:
71495+ if (ptl != ptl_m)
71496+ spin_unlock(ptl_m);
71497+ pte_unmap(pte_m);
71498+ unlock_page(page_m);
71499+}
71500+
71501+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71502+{
71503+ struct mm_struct *mm = vma->vm_mm;
71504+ unsigned long address_m;
71505+ spinlock_t *ptl_m;
71506+ struct vm_area_struct *vma_m;
71507+ pmd_t *pmd_m;
71508+ pte_t *pte_m, entry_m;
71509+
71510+ BUG_ON(!page_m || PageAnon(page_m));
71511+
71512+ vma_m = pax_find_mirror_vma(vma);
71513+ if (!vma_m)
71514+ return;
71515+
71516+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71517+ address_m = address + SEGMEXEC_TASK_SIZE;
71518+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71519+ pte_m = pte_offset_map(pmd_m, address_m);
71520+ ptl_m = pte_lockptr(mm, pmd_m);
71521+ if (ptl != ptl_m) {
71522+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71523+ if (!pte_none(*pte_m))
71524+ goto out;
71525+ }
71526+
71527+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
71528+ page_cache_get(page_m);
71529+ page_add_file_rmap(page_m);
71530+ inc_mm_counter_fast(mm, MM_FILEPAGES);
71531+ set_pte_at(mm, address_m, pte_m, entry_m);
71532+ update_mmu_cache(vma_m, address_m, entry_m);
71533+out:
71534+ if (ptl != ptl_m)
71535+ spin_unlock(ptl_m);
71536+ pte_unmap(pte_m);
71537+}
71538+
71539+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
71540+{
71541+ struct mm_struct *mm = vma->vm_mm;
71542+ unsigned long address_m;
71543+ spinlock_t *ptl_m;
71544+ struct vm_area_struct *vma_m;
71545+ pmd_t *pmd_m;
71546+ pte_t *pte_m, entry_m;
71547+
71548+ vma_m = pax_find_mirror_vma(vma);
71549+ if (!vma_m)
71550+ return;
71551+
71552+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71553+ address_m = address + SEGMEXEC_TASK_SIZE;
71554+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71555+ pte_m = pte_offset_map(pmd_m, address_m);
71556+ ptl_m = pte_lockptr(mm, pmd_m);
71557+ if (ptl != ptl_m) {
71558+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71559+ if (!pte_none(*pte_m))
71560+ goto out;
71561+ }
71562+
71563+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
71564+ set_pte_at(mm, address_m, pte_m, entry_m);
71565+out:
71566+ if (ptl != ptl_m)
71567+ spin_unlock(ptl_m);
71568+ pte_unmap(pte_m);
71569+}
71570+
71571+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
71572+{
71573+ struct page *page_m;
71574+ pte_t entry;
71575+
71576+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
71577+ goto out;
71578+
71579+ entry = *pte;
71580+ page_m = vm_normal_page(vma, address, entry);
71581+ if (!page_m)
71582+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
71583+ else if (PageAnon(page_m)) {
71584+ if (pax_find_mirror_vma(vma)) {
71585+ pte_unmap_unlock(pte, ptl);
71586+ lock_page(page_m);
71587+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
71588+ if (pte_same(entry, *pte))
71589+ pax_mirror_anon_pte(vma, address, page_m, ptl);
71590+ else
71591+ unlock_page(page_m);
71592+ }
71593+ } else
71594+ pax_mirror_file_pte(vma, address, page_m, ptl);
71595+
71596+out:
71597+ pte_unmap_unlock(pte, ptl);
71598+}
71599+#endif
71600+
71601 /*
71602 * This routine handles present pages, when users try to write
71603 * to a shared page. It is done by copying the page to a new address
71604@@ -2692,6 +2889,12 @@ gotten:
71605 */
71606 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71607 if (likely(pte_same(*page_table, orig_pte))) {
71608+
71609+#ifdef CONFIG_PAX_SEGMEXEC
71610+ if (pax_find_mirror_vma(vma))
71611+ BUG_ON(!trylock_page(new_page));
71612+#endif
71613+
71614 if (old_page) {
71615 if (!PageAnon(old_page)) {
71616 dec_mm_counter_fast(mm, MM_FILEPAGES);
71617@@ -2743,6 +2946,10 @@ gotten:
71618 page_remove_rmap(old_page);
71619 }
71620
71621+#ifdef CONFIG_PAX_SEGMEXEC
71622+ pax_mirror_anon_pte(vma, address, new_page, ptl);
71623+#endif
71624+
71625 /* Free the old page.. */
71626 new_page = old_page;
71627 ret |= VM_FAULT_WRITE;
71628@@ -3022,6 +3229,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
71629 swap_free(entry);
71630 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
71631 try_to_free_swap(page);
71632+
71633+#ifdef CONFIG_PAX_SEGMEXEC
71634+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
71635+#endif
71636+
71637 unlock_page(page);
71638 if (swapcache) {
71639 /*
71640@@ -3045,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
71641
71642 /* No need to invalidate - it was non-present before */
71643 update_mmu_cache(vma, address, page_table);
71644+
71645+#ifdef CONFIG_PAX_SEGMEXEC
71646+ pax_mirror_anon_pte(vma, address, page, ptl);
71647+#endif
71648+
71649 unlock:
71650 pte_unmap_unlock(page_table, ptl);
71651 out:
71652@@ -3064,40 +3281,6 @@ out_release:
71653 }
71654
71655 /*
71656- * This is like a special single-page "expand_{down|up}wards()",
71657- * except we must first make sure that 'address{-|+}PAGE_SIZE'
71658- * doesn't hit another vma.
71659- */
71660-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
71661-{
71662- address &= PAGE_MASK;
71663- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
71664- struct vm_area_struct *prev = vma->vm_prev;
71665-
71666- /*
71667- * Is there a mapping abutting this one below?
71668- *
71669- * That's only ok if it's the same stack mapping
71670- * that has gotten split..
71671- */
71672- if (prev && prev->vm_end == address)
71673- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
71674-
71675- expand_downwards(vma, address - PAGE_SIZE);
71676- }
71677- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
71678- struct vm_area_struct *next = vma->vm_next;
71679-
71680- /* As VM_GROWSDOWN but s/below/above/ */
71681- if (next && next->vm_start == address + PAGE_SIZE)
71682- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
71683-
71684- expand_upwards(vma, address + PAGE_SIZE);
71685- }
71686- return 0;
71687-}
71688-
71689-/*
71690 * We enter with non-exclusive mmap_sem (to exclude vma changes,
71691 * but allow concurrent faults), and pte mapped but not yet locked.
71692 * We return with mmap_sem still held, but pte unmapped and unlocked.
71693@@ -3106,27 +3289,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71694 unsigned long address, pte_t *page_table, pmd_t *pmd,
71695 unsigned int flags)
71696 {
71697- struct page *page;
71698+ struct page *page = NULL;
71699 spinlock_t *ptl;
71700 pte_t entry;
71701
71702- pte_unmap(page_table);
71703-
71704- /* Check if we need to add a guard page to the stack */
71705- if (check_stack_guard_page(vma, address) < 0)
71706- return VM_FAULT_SIGBUS;
71707-
71708- /* Use the zero-page for reads */
71709 if (!(flags & FAULT_FLAG_WRITE)) {
71710 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
71711 vma->vm_page_prot));
71712- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71713+ ptl = pte_lockptr(mm, pmd);
71714+ spin_lock(ptl);
71715 if (!pte_none(*page_table))
71716 goto unlock;
71717 goto setpte;
71718 }
71719
71720 /* Allocate our own private page. */
71721+ pte_unmap(page_table);
71722+
71723 if (unlikely(anon_vma_prepare(vma)))
71724 goto oom;
71725 page = alloc_zeroed_user_highpage_movable(vma, address);
71726@@ -3145,6 +3324,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71727 if (!pte_none(*page_table))
71728 goto release;
71729
71730+#ifdef CONFIG_PAX_SEGMEXEC
71731+ if (pax_find_mirror_vma(vma))
71732+ BUG_ON(!trylock_page(page));
71733+#endif
71734+
71735 inc_mm_counter_fast(mm, MM_ANONPAGES);
71736 page_add_new_anon_rmap(page, vma, address);
71737 setpte:
71738@@ -3152,6 +3336,12 @@ setpte:
71739
71740 /* No need to invalidate - it was non-present before */
71741 update_mmu_cache(vma, address, page_table);
71742+
71743+#ifdef CONFIG_PAX_SEGMEXEC
71744+ if (page)
71745+ pax_mirror_anon_pte(vma, address, page, ptl);
71746+#endif
71747+
71748 unlock:
71749 pte_unmap_unlock(page_table, ptl);
71750 return 0;
71751@@ -3295,6 +3485,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71752 */
71753 /* Only go through if we didn't race with anybody else... */
71754 if (likely(pte_same(*page_table, orig_pte))) {
71755+
71756+#ifdef CONFIG_PAX_SEGMEXEC
71757+ if (anon && pax_find_mirror_vma(vma))
71758+ BUG_ON(!trylock_page(page));
71759+#endif
71760+
71761 flush_icache_page(vma, page);
71762 entry = mk_pte(page, vma->vm_page_prot);
71763 if (flags & FAULT_FLAG_WRITE)
71764@@ -3314,6 +3510,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71765
71766 /* no need to invalidate: a not-present page won't be cached */
71767 update_mmu_cache(vma, address, page_table);
71768+
71769+#ifdef CONFIG_PAX_SEGMEXEC
71770+ if (anon)
71771+ pax_mirror_anon_pte(vma, address, page, ptl);
71772+ else
71773+ pax_mirror_file_pte(vma, address, page, ptl);
71774+#endif
71775+
71776 } else {
71777 if (cow_page)
71778 mem_cgroup_uncharge_page(cow_page);
71779@@ -3467,6 +3671,12 @@ int handle_pte_fault(struct mm_struct *mm,
71780 if (flags & FAULT_FLAG_WRITE)
71781 flush_tlb_fix_spurious_fault(vma, address);
71782 }
71783+
71784+#ifdef CONFIG_PAX_SEGMEXEC
71785+ pax_mirror_pte(vma, address, pte, pmd, ptl);
71786+ return 0;
71787+#endif
71788+
71789 unlock:
71790 pte_unmap_unlock(pte, ptl);
71791 return 0;
71792@@ -3483,6 +3693,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71793 pmd_t *pmd;
71794 pte_t *pte;
71795
71796+#ifdef CONFIG_PAX_SEGMEXEC
71797+ struct vm_area_struct *vma_m;
71798+#endif
71799+
71800 __set_current_state(TASK_RUNNING);
71801
71802 count_vm_event(PGFAULT);
71803@@ -3494,6 +3708,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71804 if (unlikely(is_vm_hugetlb_page(vma)))
71805 return hugetlb_fault(mm, vma, address, flags);
71806
71807+#ifdef CONFIG_PAX_SEGMEXEC
71808+ vma_m = pax_find_mirror_vma(vma);
71809+ if (vma_m) {
71810+ unsigned long address_m;
71811+ pgd_t *pgd_m;
71812+ pud_t *pud_m;
71813+ pmd_t *pmd_m;
71814+
71815+ if (vma->vm_start > vma_m->vm_start) {
71816+ address_m = address;
71817+ address -= SEGMEXEC_TASK_SIZE;
71818+ vma = vma_m;
71819+ } else
71820+ address_m = address + SEGMEXEC_TASK_SIZE;
71821+
71822+ pgd_m = pgd_offset(mm, address_m);
71823+ pud_m = pud_alloc(mm, pgd_m, address_m);
71824+ if (!pud_m)
71825+ return VM_FAULT_OOM;
71826+ pmd_m = pmd_alloc(mm, pud_m, address_m);
71827+ if (!pmd_m)
71828+ return VM_FAULT_OOM;
71829+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
71830+ return VM_FAULT_OOM;
71831+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
71832+ }
71833+#endif
71834+
71835 retry:
71836 pgd = pgd_offset(mm, address);
71837 pud = pud_alloc(mm, pgd, address);
71838@@ -3535,7 +3777,7 @@ retry:
71839 * run pte_offset_map on the pmd, if an huge pmd could
71840 * materialize from under us from a different thread.
71841 */
71842- if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
71843+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71844 return VM_FAULT_OOM;
71845 /* if an huge pmd materialized from under us just retry later */
71846 if (unlikely(pmd_trans_huge(*pmd)))
71847@@ -3572,6 +3814,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
71848 spin_unlock(&mm->page_table_lock);
71849 return 0;
71850 }
71851+
71852+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
71853+{
71854+ pud_t *new = pud_alloc_one(mm, address);
71855+ if (!new)
71856+ return -ENOMEM;
71857+
71858+ smp_wmb(); /* See comment in __pte_alloc */
71859+
71860+ spin_lock(&mm->page_table_lock);
71861+ if (pgd_present(*pgd)) /* Another has populated it */
71862+ pud_free(mm, new);
71863+ else
71864+ pgd_populate_kernel(mm, pgd, new);
71865+ spin_unlock(&mm->page_table_lock);
71866+ return 0;
71867+}
71868 #endif /* __PAGETABLE_PUD_FOLDED */
71869
71870 #ifndef __PAGETABLE_PMD_FOLDED
71871@@ -3602,6 +3861,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
71872 spin_unlock(&mm->page_table_lock);
71873 return 0;
71874 }
71875+
71876+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
71877+{
71878+ pmd_t *new = pmd_alloc_one(mm, address);
71879+ if (!new)
71880+ return -ENOMEM;
71881+
71882+ smp_wmb(); /* See comment in __pte_alloc */
71883+
71884+ spin_lock(&mm->page_table_lock);
71885+#ifndef __ARCH_HAS_4LEVEL_HACK
71886+ if (pud_present(*pud)) /* Another has populated it */
71887+ pmd_free(mm, new);
71888+ else
71889+ pud_populate_kernel(mm, pud, new);
71890+#else
71891+ if (pgd_present(*pud)) /* Another has populated it */
71892+ pmd_free(mm, new);
71893+ else
71894+ pgd_populate_kernel(mm, pud, new);
71895+#endif /* __ARCH_HAS_4LEVEL_HACK */
71896+ spin_unlock(&mm->page_table_lock);
71897+ return 0;
71898+}
71899 #endif /* __PAGETABLE_PMD_FOLDED */
71900
71901 int make_pages_present(unsigned long addr, unsigned long end)
71902@@ -3639,7 +3922,7 @@ static int __init gate_vma_init(void)
71903 gate_vma.vm_start = FIXADDR_USER_START;
71904 gate_vma.vm_end = FIXADDR_USER_END;
71905 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
71906- gate_vma.vm_page_prot = __P101;
71907+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
71908
71909 return 0;
71910 }
71911diff --git a/mm/mempolicy.c b/mm/mempolicy.c
71912index 1d771e4..f9a6808 100644
71913--- a/mm/mempolicy.c
71914+++ b/mm/mempolicy.c
71915@@ -619,6 +619,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71916 unsigned long vmstart;
71917 unsigned long vmend;
71918
71919+#ifdef CONFIG_PAX_SEGMEXEC
71920+ struct vm_area_struct *vma_m;
71921+#endif
71922+
71923 vma = find_vma(mm, start);
71924 if (!vma || vma->vm_start > start)
71925 return -EFAULT;
71926@@ -672,6 +676,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71927 if (err)
71928 goto out;
71929 }
71930+
71931+#ifdef CONFIG_PAX_SEGMEXEC
71932+ vma_m = pax_find_mirror_vma(vma);
71933+ if (vma_m && vma_m->vm_ops && vma_m->vm_ops->set_policy) {
71934+ err = vma_m->vm_ops->set_policy(vma_m, new_pol);
71935+ if (err)
71936+ goto out;
71937+ }
71938+#endif
71939+
71940 }
71941
71942 out:
71943@@ -1125,6 +1139,17 @@ static long do_mbind(unsigned long start, unsigned long len,
71944
71945 if (end < start)
71946 return -EINVAL;
71947+
71948+#ifdef CONFIG_PAX_SEGMEXEC
71949+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
71950+ if (end > SEGMEXEC_TASK_SIZE)
71951+ return -EINVAL;
71952+ } else
71953+#endif
71954+
71955+ if (end > TASK_SIZE)
71956+ return -EINVAL;
71957+
71958 if (end == start)
71959 return 0;
71960
71961@@ -1348,8 +1373,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71962 */
71963 tcred = __task_cred(task);
71964 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
71965- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
71966- !capable(CAP_SYS_NICE)) {
71967+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
71968 rcu_read_unlock();
71969 err = -EPERM;
71970 goto out_put;
71971@@ -1380,6 +1404,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71972 goto out;
71973 }
71974
71975+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71976+ if (mm != current->mm &&
71977+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
71978+ mmput(mm);
71979+ err = -EPERM;
71980+ goto out;
71981+ }
71982+#endif
71983+
71984 err = do_migrate_pages(mm, old, new,
71985 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
71986
71987diff --git a/mm/mlock.c b/mm/mlock.c
71988index ef726e8..cd7f1ec 100644
71989--- a/mm/mlock.c
71990+++ b/mm/mlock.c
71991@@ -13,6 +13,7 @@
71992 #include <linux/pagemap.h>
71993 #include <linux/mempolicy.h>
71994 #include <linux/syscalls.h>
71995+#include <linux/security.h>
71996 #include <linux/sched.h>
71997 #include <linux/export.h>
71998 #include <linux/rmap.h>
71999@@ -376,7 +377,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
72000 {
72001 unsigned long nstart, end, tmp;
72002 struct vm_area_struct * vma, * prev;
72003- int error;
72004+ int error = 0;
72005
72006 VM_BUG_ON(start & ~PAGE_MASK);
72007 VM_BUG_ON(len != PAGE_ALIGN(len));
72008@@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
72009 return -EINVAL;
72010 if (end == start)
72011 return 0;
72012+ if (end > TASK_SIZE)
72013+ return -EINVAL;
72014+
72015 vma = find_vma(current->mm, start);
72016 if (!vma || vma->vm_start > start)
72017 return -ENOMEM;
72018@@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
72019 for (nstart = start ; ; ) {
72020 vm_flags_t newflags;
72021
72022+#ifdef CONFIG_PAX_SEGMEXEC
72023+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72024+ break;
72025+#endif
72026+
72027 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
72028
72029 newflags = vma->vm_flags | VM_LOCKED;
72030@@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
72031 lock_limit >>= PAGE_SHIFT;
72032
72033 /* check against resource limits */
72034+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
72035 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
72036 error = do_mlock(start, len, 1);
72037 up_write(&current->mm->mmap_sem);
72038@@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
72039 static int do_mlockall(int flags)
72040 {
72041 struct vm_area_struct * vma, * prev = NULL;
72042- unsigned int def_flags = 0;
72043
72044 if (flags & MCL_FUTURE)
72045- def_flags = VM_LOCKED;
72046- current->mm->def_flags = def_flags;
72047+ current->mm->def_flags |= VM_LOCKED;
72048+ else
72049+ current->mm->def_flags &= ~VM_LOCKED;
72050 if (flags == MCL_FUTURE)
72051 goto out;
72052
72053 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
72054 vm_flags_t newflags;
72055
72056+#ifdef CONFIG_PAX_SEGMEXEC
72057+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72058+ break;
72059+#endif
72060+
72061+ BUG_ON(vma->vm_end > TASK_SIZE);
72062 newflags = vma->vm_flags | VM_LOCKED;
72063 if (!(flags & MCL_CURRENT))
72064 newflags &= ~VM_LOCKED;
72065@@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
72066 lock_limit >>= PAGE_SHIFT;
72067
72068 ret = -ENOMEM;
72069+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
72070 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
72071 capable(CAP_IPC_LOCK))
72072 ret = do_mlockall(flags);
72073diff --git a/mm/mmap.c b/mm/mmap.c
72074index 3edfcdf..4a27ae9 100644
72075--- a/mm/mmap.c
72076+++ b/mm/mmap.c
72077@@ -47,6 +47,16 @@
72078 #define arch_rebalance_pgtables(addr, len) (addr)
72079 #endif
72080
72081+static inline void verify_mm_writelocked(struct mm_struct *mm)
72082+{
72083+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
72084+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72085+ up_read(&mm->mmap_sem);
72086+ BUG();
72087+ }
72088+#endif
72089+}
72090+
72091 static void unmap_region(struct mm_struct *mm,
72092 struct vm_area_struct *vma, struct vm_area_struct *prev,
72093 unsigned long start, unsigned long end);
72094@@ -72,22 +82,32 @@ static void unmap_region(struct mm_struct *mm,
72095 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
72096 *
72097 */
72098-pgprot_t protection_map[16] = {
72099+pgprot_t protection_map[16] __read_only = {
72100 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
72101 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
72102 };
72103
72104-pgprot_t vm_get_page_prot(unsigned long vm_flags)
72105+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
72106 {
72107- return __pgprot(pgprot_val(protection_map[vm_flags &
72108+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
72109 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
72110 pgprot_val(arch_vm_get_page_prot(vm_flags)));
72111+
72112+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72113+ if (!(__supported_pte_mask & _PAGE_NX) &&
72114+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
72115+ (vm_flags & (VM_READ | VM_WRITE)))
72116+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
72117+#endif
72118+
72119+ return prot;
72120 }
72121 EXPORT_SYMBOL(vm_get_page_prot);
72122
72123 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
72124 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
72125 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
72126+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
72127 /*
72128 * Make sure vm_committed_as in one cacheline and not cacheline shared with
72129 * other variables. It can be updated by several CPUs frequently.
72130@@ -229,6 +249,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
72131 struct vm_area_struct *next = vma->vm_next;
72132
72133 might_sleep();
72134+ BUG_ON(vma->vm_mirror);
72135 if (vma->vm_ops && vma->vm_ops->close)
72136 vma->vm_ops->close(vma);
72137 if (vma->vm_file) {
72138@@ -275,6 +296,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
72139 * not page aligned -Ram Gupta
72140 */
72141 rlim = rlimit(RLIMIT_DATA);
72142+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
72143 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
72144 (mm->end_data - mm->start_data) > rlim)
72145 goto out;
72146@@ -708,6 +730,12 @@ static int
72147 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
72148 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72149 {
72150+
72151+#ifdef CONFIG_PAX_SEGMEXEC
72152+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
72153+ return 0;
72154+#endif
72155+
72156 if (is_mergeable_vma(vma, file, vm_flags) &&
72157 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72158 if (vma->vm_pgoff == vm_pgoff)
72159@@ -727,6 +755,12 @@ static int
72160 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72161 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72162 {
72163+
72164+#ifdef CONFIG_PAX_SEGMEXEC
72165+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
72166+ return 0;
72167+#endif
72168+
72169 if (is_mergeable_vma(vma, file, vm_flags) &&
72170 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72171 pgoff_t vm_pglen;
72172@@ -769,13 +803,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72173 struct vm_area_struct *vma_merge(struct mm_struct *mm,
72174 struct vm_area_struct *prev, unsigned long addr,
72175 unsigned long end, unsigned long vm_flags,
72176- struct anon_vma *anon_vma, struct file *file,
72177+ struct anon_vma *anon_vma, struct file *file,
72178 pgoff_t pgoff, struct mempolicy *policy)
72179 {
72180 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
72181 struct vm_area_struct *area, *next;
72182 int err;
72183
72184+#ifdef CONFIG_PAX_SEGMEXEC
72185+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
72186+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
72187+
72188+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
72189+#endif
72190+
72191 /*
72192 * We later require that vma->vm_flags == vm_flags,
72193 * so this tests vma->vm_flags & VM_SPECIAL, too.
72194@@ -791,6 +832,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72195 if (next && next->vm_end == end) /* cases 6, 7, 8 */
72196 next = next->vm_next;
72197
72198+#ifdef CONFIG_PAX_SEGMEXEC
72199+ if (prev)
72200+ prev_m = pax_find_mirror_vma(prev);
72201+ if (area)
72202+ area_m = pax_find_mirror_vma(area);
72203+ if (next)
72204+ next_m = pax_find_mirror_vma(next);
72205+#endif
72206+
72207 /*
72208 * Can it merge with the predecessor?
72209 */
72210@@ -810,9 +860,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72211 /* cases 1, 6 */
72212 err = vma_adjust(prev, prev->vm_start,
72213 next->vm_end, prev->vm_pgoff, NULL);
72214- } else /* cases 2, 5, 7 */
72215+
72216+#ifdef CONFIG_PAX_SEGMEXEC
72217+ if (!err && prev_m)
72218+ err = vma_adjust(prev_m, prev_m->vm_start,
72219+ next_m->vm_end, prev_m->vm_pgoff, NULL);
72220+#endif
72221+
72222+ } else { /* cases 2, 5, 7 */
72223 err = vma_adjust(prev, prev->vm_start,
72224 end, prev->vm_pgoff, NULL);
72225+
72226+#ifdef CONFIG_PAX_SEGMEXEC
72227+ if (!err && prev_m)
72228+ err = vma_adjust(prev_m, prev_m->vm_start,
72229+ end_m, prev_m->vm_pgoff, NULL);
72230+#endif
72231+
72232+ }
72233 if (err)
72234 return NULL;
72235 khugepaged_enter_vma_merge(prev);
72236@@ -826,12 +891,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72237 mpol_equal(policy, vma_policy(next)) &&
72238 can_vma_merge_before(next, vm_flags,
72239 anon_vma, file, pgoff+pglen)) {
72240- if (prev && addr < prev->vm_end) /* case 4 */
72241+ if (prev && addr < prev->vm_end) { /* case 4 */
72242 err = vma_adjust(prev, prev->vm_start,
72243 addr, prev->vm_pgoff, NULL);
72244- else /* cases 3, 8 */
72245+
72246+#ifdef CONFIG_PAX_SEGMEXEC
72247+ if (!err && prev_m)
72248+ err = vma_adjust(prev_m, prev_m->vm_start,
72249+ addr_m, prev_m->vm_pgoff, NULL);
72250+#endif
72251+
72252+ } else { /* cases 3, 8 */
72253 err = vma_adjust(area, addr, next->vm_end,
72254 next->vm_pgoff - pglen, NULL);
72255+
72256+#ifdef CONFIG_PAX_SEGMEXEC
72257+ if (!err && area_m)
72258+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
72259+ next_m->vm_pgoff - pglen, NULL);
72260+#endif
72261+
72262+ }
72263 if (err)
72264 return NULL;
72265 khugepaged_enter_vma_merge(area);
72266@@ -940,14 +1020,11 @@ none:
72267 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
72268 struct file *file, long pages)
72269 {
72270- const unsigned long stack_flags
72271- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
72272-
72273 if (file) {
72274 mm->shared_vm += pages;
72275 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
72276 mm->exec_vm += pages;
72277- } else if (flags & stack_flags)
72278+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
72279 mm->stack_vm += pages;
72280 if (flags & (VM_RESERVED|VM_IO))
72281 mm->reserved_vm += pages;
72282@@ -985,7 +1062,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72283 * (the exception is when the underlying filesystem is noexec
72284 * mounted, in which case we dont add PROT_EXEC.)
72285 */
72286- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72287+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72288 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
72289 prot |= PROT_EXEC;
72290
72291@@ -1011,7 +1088,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72292 /* Obtain the address to map to. we verify (or select) it and ensure
72293 * that it represents a valid section of the address space.
72294 */
72295- addr = get_unmapped_area(file, addr, len, pgoff, flags);
72296+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
72297 if (addr & ~PAGE_MASK)
72298 return addr;
72299
72300@@ -1022,6 +1099,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72301 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
72302 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
72303
72304+#ifdef CONFIG_PAX_MPROTECT
72305+ if (mm->pax_flags & MF_PAX_MPROTECT) {
72306+#ifndef CONFIG_PAX_MPROTECT_COMPAT
72307+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
72308+ gr_log_rwxmmap(file);
72309+
72310+#ifdef CONFIG_PAX_EMUPLT
72311+ vm_flags &= ~VM_EXEC;
72312+#else
72313+ return -EPERM;
72314+#endif
72315+
72316+ }
72317+
72318+ if (!(vm_flags & VM_EXEC))
72319+ vm_flags &= ~VM_MAYEXEC;
72320+#else
72321+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72322+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72323+#endif
72324+ else
72325+ vm_flags &= ~VM_MAYWRITE;
72326+ }
72327+#endif
72328+
72329+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72330+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
72331+ vm_flags &= ~VM_PAGEEXEC;
72332+#endif
72333+
72334 if (flags & MAP_LOCKED)
72335 if (!can_do_mlock())
72336 return -EPERM;
72337@@ -1033,6 +1140,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72338 locked += mm->locked_vm;
72339 lock_limit = rlimit(RLIMIT_MEMLOCK);
72340 lock_limit >>= PAGE_SHIFT;
72341+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72342 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
72343 return -EAGAIN;
72344 }
72345@@ -1099,6 +1207,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72346 }
72347 }
72348
72349+ if (!gr_acl_handle_mmap(file, prot))
72350+ return -EACCES;
72351+
72352 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
72353 }
72354
72355@@ -1175,7 +1286,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
72356 vm_flags_t vm_flags = vma->vm_flags;
72357
72358 /* If it was private or non-writable, the write bit is already clear */
72359- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
72360+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
72361 return 0;
72362
72363 /* The backer wishes to know when pages are first written to? */
72364@@ -1224,14 +1335,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
72365 unsigned long charged = 0;
72366 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
72367
72368+#ifdef CONFIG_PAX_SEGMEXEC
72369+ struct vm_area_struct *vma_m = NULL;
72370+#endif
72371+
72372+ /*
72373+ * mm->mmap_sem is required to protect against another thread
72374+ * changing the mappings in case we sleep.
72375+ */
72376+ verify_mm_writelocked(mm);
72377+
72378 /* Clear old maps */
72379 error = -ENOMEM;
72380-munmap_back:
72381 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72382 if (vma && vma->vm_start < addr + len) {
72383 if (do_munmap(mm, addr, len))
72384 return -ENOMEM;
72385- goto munmap_back;
72386+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72387+ BUG_ON(vma && vma->vm_start < addr + len);
72388 }
72389
72390 /* Check against address space limit. */
72391@@ -1280,6 +1401,16 @@ munmap_back:
72392 goto unacct_error;
72393 }
72394
72395+#ifdef CONFIG_PAX_SEGMEXEC
72396+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
72397+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72398+ if (!vma_m) {
72399+ error = -ENOMEM;
72400+ goto free_vma;
72401+ }
72402+ }
72403+#endif
72404+
72405 vma->vm_mm = mm;
72406 vma->vm_start = addr;
72407 vma->vm_end = addr + len;
72408@@ -1304,6 +1435,19 @@ munmap_back:
72409 error = file->f_op->mmap(file, vma);
72410 if (error)
72411 goto unmap_and_free_vma;
72412+
72413+#ifdef CONFIG_PAX_SEGMEXEC
72414+ if (vma_m && (vm_flags & VM_EXECUTABLE))
72415+ added_exe_file_vma(mm);
72416+#endif
72417+
72418+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72419+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
72420+ vma->vm_flags |= VM_PAGEEXEC;
72421+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72422+ }
72423+#endif
72424+
72425 if (vm_flags & VM_EXECUTABLE)
72426 added_exe_file_vma(mm);
72427
72428@@ -1341,6 +1485,11 @@ munmap_back:
72429 vma_link(mm, vma, prev, rb_link, rb_parent);
72430 file = vma->vm_file;
72431
72432+#ifdef CONFIG_PAX_SEGMEXEC
72433+ if (vma_m)
72434+ BUG_ON(pax_mirror_vma(vma_m, vma));
72435+#endif
72436+
72437 /* Once vma denies write, undo our temporary denial count */
72438 if (correct_wcount)
72439 atomic_inc(&inode->i_writecount);
72440@@ -1349,6 +1498,7 @@ out:
72441
72442 mm->total_vm += len >> PAGE_SHIFT;
72443 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
72444+ track_exec_limit(mm, addr, addr + len, vm_flags);
72445 if (vm_flags & VM_LOCKED) {
72446 if (!mlock_vma_pages_range(vma, addr, addr + len))
72447 mm->locked_vm += (len >> PAGE_SHIFT);
72448@@ -1371,6 +1521,12 @@ unmap_and_free_vma:
72449 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
72450 charged = 0;
72451 free_vma:
72452+
72453+#ifdef CONFIG_PAX_SEGMEXEC
72454+ if (vma_m)
72455+ kmem_cache_free(vm_area_cachep, vma_m);
72456+#endif
72457+
72458 kmem_cache_free(vm_area_cachep, vma);
72459 unacct_error:
72460 if (charged)
72461@@ -1378,6 +1534,44 @@ unacct_error:
72462 return error;
72463 }
72464
72465+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
72466+{
72467+ if (!vma) {
72468+#ifdef CONFIG_STACK_GROWSUP
72469+ if (addr > sysctl_heap_stack_gap)
72470+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
72471+ else
72472+ vma = find_vma(current->mm, 0);
72473+ if (vma && (vma->vm_flags & VM_GROWSUP))
72474+ return false;
72475+#endif
72476+ return true;
72477+ }
72478+
72479+ if (addr + len > vma->vm_start)
72480+ return false;
72481+
72482+ if (vma->vm_flags & VM_GROWSDOWN)
72483+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
72484+#ifdef CONFIG_STACK_GROWSUP
72485+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
72486+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
72487+#endif
72488+
72489+ return true;
72490+}
72491+
72492+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
72493+{
72494+ if (vma->vm_start < len)
72495+ return -ENOMEM;
72496+ if (!(vma->vm_flags & VM_GROWSDOWN))
72497+ return vma->vm_start - len;
72498+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
72499+ return vma->vm_start - len - sysctl_heap_stack_gap;
72500+ return -ENOMEM;
72501+}
72502+
72503 /* Get an address range which is currently unmapped.
72504 * For shmat() with addr=0.
72505 *
72506@@ -1404,18 +1598,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
72507 if (flags & MAP_FIXED)
72508 return addr;
72509
72510+#ifdef CONFIG_PAX_RANDMMAP
72511+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
72512+#endif
72513+
72514 if (addr) {
72515 addr = PAGE_ALIGN(addr);
72516- vma = find_vma(mm, addr);
72517- if (TASK_SIZE - len >= addr &&
72518- (!vma || addr + len <= vma->vm_start))
72519- return addr;
72520+ if (TASK_SIZE - len >= addr) {
72521+ vma = find_vma(mm, addr);
72522+ if (check_heap_stack_gap(vma, addr, len))
72523+ return addr;
72524+ }
72525 }
72526 if (len > mm->cached_hole_size) {
72527- start_addr = addr = mm->free_area_cache;
72528+ start_addr = addr = mm->free_area_cache;
72529 } else {
72530- start_addr = addr = TASK_UNMAPPED_BASE;
72531- mm->cached_hole_size = 0;
72532+ start_addr = addr = mm->mmap_base;
72533+ mm->cached_hole_size = 0;
72534 }
72535
72536 full_search:
72537@@ -1426,34 +1625,40 @@ full_search:
72538 * Start a new search - just in case we missed
72539 * some holes.
72540 */
72541- if (start_addr != TASK_UNMAPPED_BASE) {
72542- addr = TASK_UNMAPPED_BASE;
72543- start_addr = addr;
72544+ if (start_addr != mm->mmap_base) {
72545+ start_addr = addr = mm->mmap_base;
72546 mm->cached_hole_size = 0;
72547 goto full_search;
72548 }
72549 return -ENOMEM;
72550 }
72551- if (!vma || addr + len <= vma->vm_start) {
72552- /*
72553- * Remember the place where we stopped the search:
72554- */
72555- mm->free_area_cache = addr + len;
72556- return addr;
72557- }
72558+ if (check_heap_stack_gap(vma, addr, len))
72559+ break;
72560 if (addr + mm->cached_hole_size < vma->vm_start)
72561 mm->cached_hole_size = vma->vm_start - addr;
72562 addr = vma->vm_end;
72563 }
72564+
72565+ /*
72566+ * Remember the place where we stopped the search:
72567+ */
72568+ mm->free_area_cache = addr + len;
72569+ return addr;
72570 }
72571 #endif
72572
72573 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
72574 {
72575+
72576+#ifdef CONFIG_PAX_SEGMEXEC
72577+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72578+ return;
72579+#endif
72580+
72581 /*
72582 * Is this a new hole at the lowest possible address?
72583 */
72584- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
72585+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
72586 mm->free_area_cache = addr;
72587 }
72588
72589@@ -1469,7 +1674,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72590 {
72591 struct vm_area_struct *vma;
72592 struct mm_struct *mm = current->mm;
72593- unsigned long addr = addr0, start_addr;
72594+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
72595
72596 /* requested length too big for entire address space */
72597 if (len > TASK_SIZE)
72598@@ -1478,13 +1683,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
72599 if (flags & MAP_FIXED)
72600 return addr;
72601
72602+#ifdef CONFIG_PAX_RANDMMAP
72603+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
72604+#endif
72605+
72606 /* requesting a specific address */
72607 if (addr) {
72608 addr = PAGE_ALIGN(addr);
72609- vma = find_vma(mm, addr);
72610- if (TASK_SIZE - len >= addr &&
72611- (!vma || addr + len <= vma->vm_start))
72612- return addr;
72613+ if (TASK_SIZE - len >= addr) {
72614+ vma = find_vma(mm, addr);
72615+ if (check_heap_stack_gap(vma, addr, len))
72616+ return addr;
72617+ }
72618 }
72619
72620 /* check if free_area_cache is useful for us */
72621@@ -1508,7 +1718,7 @@ try_again:
72622 * return with success:
72623 */
72624 vma = find_vma(mm, addr);
72625- if (!vma || addr+len <= vma->vm_start)
72626+ if (check_heap_stack_gap(vma, addr, len))
72627 /* remember the address as a hint for next time */
72628 return (mm->free_area_cache = addr);
72629
72630@@ -1517,8 +1727,8 @@ try_again:
72631 mm->cached_hole_size = vma->vm_start - addr;
72632
72633 /* try just below the current vma->vm_start */
72634- addr = vma->vm_start-len;
72635- } while (len < vma->vm_start);
72636+ addr = skip_heap_stack_gap(vma, len);
72637+ } while (!IS_ERR_VALUE(addr));
72638
72639 fail:
72640 /*
72641@@ -1541,13 +1751,21 @@ fail:
72642 * can happen with large stack limits and large mmap()
72643 * allocations.
72644 */
72645+ mm->mmap_base = TASK_UNMAPPED_BASE;
72646+
72647+#ifdef CONFIG_PAX_RANDMMAP
72648+ if (mm->pax_flags & MF_PAX_RANDMMAP)
72649+ mm->mmap_base += mm->delta_mmap;
72650+#endif
72651+
72652+ mm->free_area_cache = mm->mmap_base;
72653 mm->cached_hole_size = ~0UL;
72654- mm->free_area_cache = TASK_UNMAPPED_BASE;
72655 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
72656 /*
72657 * Restore the topdown base:
72658 */
72659- mm->free_area_cache = mm->mmap_base;
72660+ mm->mmap_base = base;
72661+ mm->free_area_cache = base;
72662 mm->cached_hole_size = ~0UL;
72663
72664 return addr;
72665@@ -1556,6 +1774,12 @@ fail:
72666
72667 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72668 {
72669+
72670+#ifdef CONFIG_PAX_SEGMEXEC
72671+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72672+ return;
72673+#endif
72674+
72675 /*
72676 * Is this a new hole at the highest possible address?
72677 */
72678@@ -1563,8 +1787,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72679 mm->free_area_cache = addr;
72680
72681 /* dont allow allocations above current base */
72682- if (mm->free_area_cache > mm->mmap_base)
72683+ if (mm->free_area_cache > mm->mmap_base) {
72684 mm->free_area_cache = mm->mmap_base;
72685+ mm->cached_hole_size = ~0UL;
72686+ }
72687 }
72688
72689 unsigned long
72690@@ -1663,6 +1889,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
72691 return vma;
72692 }
72693
72694+#ifdef CONFIG_PAX_SEGMEXEC
72695+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
72696+{
72697+ struct vm_area_struct *vma_m;
72698+
72699+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
72700+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
72701+ BUG_ON(vma->vm_mirror);
72702+ return NULL;
72703+ }
72704+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
72705+ vma_m = vma->vm_mirror;
72706+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
72707+ BUG_ON(vma->vm_file != vma_m->vm_file);
72708+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
72709+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
72710+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
72711+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
72712+ return vma_m;
72713+}
72714+#endif
72715+
72716 /*
72717 * Verify that the stack growth is acceptable and
72718 * update accounting. This is shared with both the
72719@@ -1679,6 +1927,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72720 return -ENOMEM;
72721
72722 /* Stack limit test */
72723+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
72724 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
72725 return -ENOMEM;
72726
72727@@ -1689,6 +1938,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72728 locked = mm->locked_vm + grow;
72729 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
72730 limit >>= PAGE_SHIFT;
72731+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72732 if (locked > limit && !capable(CAP_IPC_LOCK))
72733 return -ENOMEM;
72734 }
72735@@ -1719,37 +1969,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72736 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
72737 * vma is the last one with address > vma->vm_end. Have to extend vma.
72738 */
72739+#ifndef CONFIG_IA64
72740+static
72741+#endif
72742 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72743 {
72744 int error;
72745+ bool locknext;
72746
72747 if (!(vma->vm_flags & VM_GROWSUP))
72748 return -EFAULT;
72749
72750+ /* Also guard against wrapping around to address 0. */
72751+ if (address < PAGE_ALIGN(address+1))
72752+ address = PAGE_ALIGN(address+1);
72753+ else
72754+ return -ENOMEM;
72755+
72756 /*
72757 * We must make sure the anon_vma is allocated
72758 * so that the anon_vma locking is not a noop.
72759 */
72760 if (unlikely(anon_vma_prepare(vma)))
72761 return -ENOMEM;
72762+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
72763+ if (locknext && anon_vma_prepare(vma->vm_next))
72764+ return -ENOMEM;
72765 vma_lock_anon_vma(vma);
72766+ if (locknext)
72767+ vma_lock_anon_vma(vma->vm_next);
72768
72769 /*
72770 * vma->vm_start/vm_end cannot change under us because the caller
72771 * is required to hold the mmap_sem in read mode. We need the
72772- * anon_vma lock to serialize against concurrent expand_stacks.
72773- * Also guard against wrapping around to address 0.
72774+ * anon_vma locks to serialize against concurrent expand_stacks
72775+ * and expand_upwards.
72776 */
72777- if (address < PAGE_ALIGN(address+4))
72778- address = PAGE_ALIGN(address+4);
72779- else {
72780- vma_unlock_anon_vma(vma);
72781- return -ENOMEM;
72782- }
72783 error = 0;
72784
72785 /* Somebody else might have raced and expanded it already */
72786- if (address > vma->vm_end) {
72787+ 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)
72788+ error = -ENOMEM;
72789+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
72790 unsigned long size, grow;
72791
72792 size = address - vma->vm_start;
72793@@ -1764,6 +2025,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72794 }
72795 }
72796 }
72797+ if (locknext)
72798+ vma_unlock_anon_vma(vma->vm_next);
72799 vma_unlock_anon_vma(vma);
72800 khugepaged_enter_vma_merge(vma);
72801 return error;
72802@@ -1777,6 +2040,8 @@ int expand_downwards(struct vm_area_struct *vma,
72803 unsigned long address)
72804 {
72805 int error;
72806+ bool lockprev = false;
72807+ struct vm_area_struct *prev;
72808
72809 /*
72810 * We must make sure the anon_vma is allocated
72811@@ -1790,6 +2055,15 @@ int expand_downwards(struct vm_area_struct *vma,
72812 if (error)
72813 return error;
72814
72815+ prev = vma->vm_prev;
72816+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
72817+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
72818+#endif
72819+ if (lockprev && anon_vma_prepare(prev))
72820+ return -ENOMEM;
72821+ if (lockprev)
72822+ vma_lock_anon_vma(prev);
72823+
72824 vma_lock_anon_vma(vma);
72825
72826 /*
72827@@ -1799,9 +2073,17 @@ int expand_downwards(struct vm_area_struct *vma,
72828 */
72829
72830 /* Somebody else might have raced and expanded it already */
72831- if (address < vma->vm_start) {
72832+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
72833+ error = -ENOMEM;
72834+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
72835 unsigned long size, grow;
72836
72837+#ifdef CONFIG_PAX_SEGMEXEC
72838+ struct vm_area_struct *vma_m;
72839+
72840+ vma_m = pax_find_mirror_vma(vma);
72841+#endif
72842+
72843 size = vma->vm_end - address;
72844 grow = (vma->vm_start - address) >> PAGE_SHIFT;
72845
72846@@ -1811,11 +2093,22 @@ int expand_downwards(struct vm_area_struct *vma,
72847 if (!error) {
72848 vma->vm_start = address;
72849 vma->vm_pgoff -= grow;
72850+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
72851+
72852+#ifdef CONFIG_PAX_SEGMEXEC
72853+ if (vma_m) {
72854+ vma_m->vm_start -= grow << PAGE_SHIFT;
72855+ vma_m->vm_pgoff -= grow;
72856+ }
72857+#endif
72858+
72859 perf_event_mmap(vma);
72860 }
72861 }
72862 }
72863 vma_unlock_anon_vma(vma);
72864+ if (lockprev)
72865+ vma_unlock_anon_vma(prev);
72866 khugepaged_enter_vma_merge(vma);
72867 return error;
72868 }
72869@@ -1887,6 +2180,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
72870 do {
72871 long nrpages = vma_pages(vma);
72872
72873+#ifdef CONFIG_PAX_SEGMEXEC
72874+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
72875+ vma = remove_vma(vma);
72876+ continue;
72877+ }
72878+#endif
72879+
72880 if (vma->vm_flags & VM_ACCOUNT)
72881 nr_accounted += nrpages;
72882 mm->total_vm -= nrpages;
72883@@ -1933,6 +2233,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
72884 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
72885 vma->vm_prev = NULL;
72886 do {
72887+
72888+#ifdef CONFIG_PAX_SEGMEXEC
72889+ if (vma->vm_mirror) {
72890+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
72891+ vma->vm_mirror->vm_mirror = NULL;
72892+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
72893+ vma->vm_mirror = NULL;
72894+ }
72895+#endif
72896+
72897 rb_erase(&vma->vm_rb, &mm->mm_rb);
72898 mm->map_count--;
72899 tail_vma = vma;
72900@@ -1961,14 +2271,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72901 struct vm_area_struct *new;
72902 int err = -ENOMEM;
72903
72904+#ifdef CONFIG_PAX_SEGMEXEC
72905+ struct vm_area_struct *vma_m, *new_m = NULL;
72906+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
72907+#endif
72908+
72909 if (is_vm_hugetlb_page(vma) && (addr &
72910 ~(huge_page_mask(hstate_vma(vma)))))
72911 return -EINVAL;
72912
72913+#ifdef CONFIG_PAX_SEGMEXEC
72914+ vma_m = pax_find_mirror_vma(vma);
72915+#endif
72916+
72917 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72918 if (!new)
72919 goto out_err;
72920
72921+#ifdef CONFIG_PAX_SEGMEXEC
72922+ if (vma_m) {
72923+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72924+ if (!new_m) {
72925+ kmem_cache_free(vm_area_cachep, new);
72926+ goto out_err;
72927+ }
72928+ }
72929+#endif
72930+
72931 /* most fields are the same, copy all, and then fixup */
72932 *new = *vma;
72933
72934@@ -1981,6 +2310,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72935 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
72936 }
72937
72938+#ifdef CONFIG_PAX_SEGMEXEC
72939+ if (vma_m) {
72940+ *new_m = *vma_m;
72941+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
72942+ new_m->vm_mirror = new;
72943+ new->vm_mirror = new_m;
72944+
72945+ if (new_below)
72946+ new_m->vm_end = addr_m;
72947+ else {
72948+ new_m->vm_start = addr_m;
72949+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
72950+ }
72951+ }
72952+#endif
72953+
72954 pol = mpol_dup(vma_policy(vma));
72955 if (IS_ERR(pol)) {
72956 err = PTR_ERR(pol);
72957@@ -2006,6 +2351,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72958 else
72959 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
72960
72961+#ifdef CONFIG_PAX_SEGMEXEC
72962+ if (!err && vma_m) {
72963+ if (anon_vma_clone(new_m, vma_m))
72964+ goto out_free_mpol;
72965+
72966+ mpol_get(pol);
72967+ vma_set_policy(new_m, pol);
72968+
72969+ if (new_m->vm_file) {
72970+ get_file(new_m->vm_file);
72971+ if (vma_m->vm_flags & VM_EXECUTABLE)
72972+ added_exe_file_vma(mm);
72973+ }
72974+
72975+ if (new_m->vm_ops && new_m->vm_ops->open)
72976+ new_m->vm_ops->open(new_m);
72977+
72978+ if (new_below)
72979+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
72980+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
72981+ else
72982+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
72983+
72984+ if (err) {
72985+ if (new_m->vm_ops && new_m->vm_ops->close)
72986+ new_m->vm_ops->close(new_m);
72987+ if (new_m->vm_file) {
72988+ if (vma_m->vm_flags & VM_EXECUTABLE)
72989+ removed_exe_file_vma(mm);
72990+ fput(new_m->vm_file);
72991+ }
72992+ mpol_put(pol);
72993+ }
72994+ }
72995+#endif
72996+
72997 /* Success. */
72998 if (!err)
72999 return 0;
73000@@ -2018,10 +2399,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73001 removed_exe_file_vma(mm);
73002 fput(new->vm_file);
73003 }
73004- unlink_anon_vmas(new);
73005 out_free_mpol:
73006 mpol_put(pol);
73007 out_free_vma:
73008+
73009+#ifdef CONFIG_PAX_SEGMEXEC
73010+ if (new_m) {
73011+ unlink_anon_vmas(new_m);
73012+ kmem_cache_free(vm_area_cachep, new_m);
73013+ }
73014+#endif
73015+
73016+ unlink_anon_vmas(new);
73017 kmem_cache_free(vm_area_cachep, new);
73018 out_err:
73019 return err;
73020@@ -2034,6 +2423,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73021 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73022 unsigned long addr, int new_below)
73023 {
73024+
73025+#ifdef CONFIG_PAX_SEGMEXEC
73026+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
73027+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
73028+ if (mm->map_count >= sysctl_max_map_count-1)
73029+ return -ENOMEM;
73030+ } else
73031+#endif
73032+
73033 if (mm->map_count >= sysctl_max_map_count)
73034 return -ENOMEM;
73035
73036@@ -2045,11 +2443,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73037 * work. This now handles partial unmappings.
73038 * Jeremy Fitzhardinge <jeremy@goop.org>
73039 */
73040+#ifdef CONFIG_PAX_SEGMEXEC
73041 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73042 {
73043+ int ret = __do_munmap(mm, start, len);
73044+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
73045+ return ret;
73046+
73047+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
73048+}
73049+
73050+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73051+#else
73052+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73053+#endif
73054+{
73055 unsigned long end;
73056 struct vm_area_struct *vma, *prev, *last;
73057
73058+ /*
73059+ * mm->mmap_sem is required to protect against another thread
73060+ * changing the mappings in case we sleep.
73061+ */
73062+ verify_mm_writelocked(mm);
73063+
73064 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
73065 return -EINVAL;
73066
73067@@ -2124,6 +2541,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73068 /* Fix up all other VM information */
73069 remove_vma_list(mm, vma);
73070
73071+ track_exec_limit(mm, start, end, 0UL);
73072+
73073 return 0;
73074 }
73075
73076@@ -2132,6 +2551,13 @@ int vm_munmap(unsigned long start, size_t len)
73077 int ret;
73078 struct mm_struct *mm = current->mm;
73079
73080+
73081+#ifdef CONFIG_PAX_SEGMEXEC
73082+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
73083+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
73084+ return -EINVAL;
73085+#endif
73086+
73087 down_write(&mm->mmap_sem);
73088 ret = do_munmap(mm, start, len);
73089 up_write(&mm->mmap_sem);
73090@@ -2145,16 +2571,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
73091 return vm_munmap(addr, len);
73092 }
73093
73094-static inline void verify_mm_writelocked(struct mm_struct *mm)
73095-{
73096-#ifdef CONFIG_DEBUG_VM
73097- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
73098- WARN_ON(1);
73099- up_read(&mm->mmap_sem);
73100- }
73101-#endif
73102-}
73103-
73104 /*
73105 * this is really a simplified "do_mmap". it only handles
73106 * anonymous maps. eventually we may be able to do some
73107@@ -2168,6 +2584,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73108 struct rb_node ** rb_link, * rb_parent;
73109 pgoff_t pgoff = addr >> PAGE_SHIFT;
73110 int error;
73111+ unsigned long charged;
73112
73113 len = PAGE_ALIGN(len);
73114 if (!len)
73115@@ -2175,16 +2592,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73116
73117 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
73118
73119+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
73120+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
73121+ flags &= ~VM_EXEC;
73122+
73123+#ifdef CONFIG_PAX_MPROTECT
73124+ if (mm->pax_flags & MF_PAX_MPROTECT)
73125+ flags &= ~VM_MAYEXEC;
73126+#endif
73127+
73128+ }
73129+#endif
73130+
73131 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
73132 if (error & ~PAGE_MASK)
73133 return error;
73134
73135+ charged = len >> PAGE_SHIFT;
73136+
73137 /*
73138 * mlock MCL_FUTURE?
73139 */
73140 if (mm->def_flags & VM_LOCKED) {
73141 unsigned long locked, lock_limit;
73142- locked = len >> PAGE_SHIFT;
73143+ locked = charged;
73144 locked += mm->locked_vm;
73145 lock_limit = rlimit(RLIMIT_MEMLOCK);
73146 lock_limit >>= PAGE_SHIFT;
73147@@ -2201,22 +2632,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73148 /*
73149 * Clear old maps. this also does some error checking for us
73150 */
73151- munmap_back:
73152 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73153 if (vma && vma->vm_start < addr + len) {
73154 if (do_munmap(mm, addr, len))
73155 return -ENOMEM;
73156- goto munmap_back;
73157- }
73158+ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73159+ BUG_ON(vma && vma->vm_start < addr + len);
73160+ }
73161
73162 /* Check against address space limits *after* clearing old maps... */
73163- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
73164+ if (!may_expand_vm(mm, charged))
73165 return -ENOMEM;
73166
73167 if (mm->map_count > sysctl_max_map_count)
73168 return -ENOMEM;
73169
73170- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
73171+ if (security_vm_enough_memory_mm(mm, charged))
73172 return -ENOMEM;
73173
73174 /* Can we just expand an old private anonymous mapping? */
73175@@ -2230,7 +2661,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73176 */
73177 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73178 if (!vma) {
73179- vm_unacct_memory(len >> PAGE_SHIFT);
73180+ vm_unacct_memory(charged);
73181 return -ENOMEM;
73182 }
73183
73184@@ -2244,11 +2675,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73185 vma_link(mm, vma, prev, rb_link, rb_parent);
73186 out:
73187 perf_event_mmap(vma);
73188- mm->total_vm += len >> PAGE_SHIFT;
73189+ mm->total_vm += charged;
73190 if (flags & VM_LOCKED) {
73191 if (!mlock_vma_pages_range(vma, addr, addr + len))
73192- mm->locked_vm += (len >> PAGE_SHIFT);
73193+ mm->locked_vm += charged;
73194 }
73195+ track_exec_limit(mm, addr, addr + len, flags);
73196 return addr;
73197 }
73198
73199@@ -2306,6 +2738,7 @@ void exit_mmap(struct mm_struct *mm)
73200 while (vma) {
73201 if (vma->vm_flags & VM_ACCOUNT)
73202 nr_accounted += vma_pages(vma);
73203+ vma->vm_mirror = NULL;
73204 vma = remove_vma(vma);
73205 }
73206 vm_unacct_memory(nr_accounted);
73207@@ -2322,6 +2755,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73208 struct vm_area_struct * __vma, * prev;
73209 struct rb_node ** rb_link, * rb_parent;
73210
73211+#ifdef CONFIG_PAX_SEGMEXEC
73212+ struct vm_area_struct *vma_m = NULL;
73213+#endif
73214+
73215+ if (security_mmap_addr(vma->vm_start))
73216+ return -EPERM;
73217+
73218 /*
73219 * The vm_pgoff of a purely anonymous vma should be irrelevant
73220 * until its first write fault, when page's anon_vma and index
73221@@ -2348,7 +2788,21 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73222 if (vma->vm_file && uprobe_mmap(vma))
73223 return -EINVAL;
73224
73225+#ifdef CONFIG_PAX_SEGMEXEC
73226+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
73227+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73228+ if (!vma_m)
73229+ return -ENOMEM;
73230+ }
73231+#endif
73232+
73233 vma_link(mm, vma, prev, rb_link, rb_parent);
73234+
73235+#ifdef CONFIG_PAX_SEGMEXEC
73236+ if (vma_m)
73237+ BUG_ON(pax_mirror_vma(vma_m, vma));
73238+#endif
73239+
73240 return 0;
73241 }
73242
73243@@ -2367,6 +2821,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73244 struct mempolicy *pol;
73245 bool faulted_in_anon_vma = true;
73246
73247+ BUG_ON(vma->vm_mirror);
73248+
73249 /*
73250 * If anonymous vma has not yet been faulted, update new pgoff
73251 * to match new location, to increase its chance of merging.
73252@@ -2438,6 +2894,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73253 return NULL;
73254 }
73255
73256+#ifdef CONFIG_PAX_SEGMEXEC
73257+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
73258+{
73259+ struct vm_area_struct *prev_m;
73260+ struct rb_node **rb_link_m, *rb_parent_m;
73261+ struct mempolicy *pol_m;
73262+
73263+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
73264+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
73265+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
73266+ *vma_m = *vma;
73267+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
73268+ if (anon_vma_clone(vma_m, vma))
73269+ return -ENOMEM;
73270+ pol_m = vma_policy(vma_m);
73271+ mpol_get(pol_m);
73272+ vma_set_policy(vma_m, pol_m);
73273+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
73274+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
73275+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
73276+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
73277+ if (vma_m->vm_file)
73278+ get_file(vma_m->vm_file);
73279+ if (vma_m->vm_ops && vma_m->vm_ops->open)
73280+ vma_m->vm_ops->open(vma_m);
73281+ find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
73282+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
73283+ vma_m->vm_mirror = vma;
73284+ vma->vm_mirror = vma_m;
73285+ return 0;
73286+}
73287+#endif
73288+
73289 /*
73290 * Return true if the calling process may expand its vm space by the passed
73291 * number of pages
73292@@ -2449,6 +2938,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
73293
73294 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
73295
73296+#ifdef CONFIG_PAX_RANDMMAP
73297+ if (mm->pax_flags & MF_PAX_RANDMMAP)
73298+ cur -= mm->brk_gap;
73299+#endif
73300+
73301+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
73302 if (cur + npages > lim)
73303 return 0;
73304 return 1;
73305@@ -2519,6 +3014,22 @@ int install_special_mapping(struct mm_struct *mm,
73306 vma->vm_start = addr;
73307 vma->vm_end = addr + len;
73308
73309+#ifdef CONFIG_PAX_MPROTECT
73310+ if (mm->pax_flags & MF_PAX_MPROTECT) {
73311+#ifndef CONFIG_PAX_MPROTECT_COMPAT
73312+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
73313+ return -EPERM;
73314+ if (!(vm_flags & VM_EXEC))
73315+ vm_flags &= ~VM_MAYEXEC;
73316+#else
73317+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73318+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73319+#endif
73320+ else
73321+ vm_flags &= ~VM_MAYWRITE;
73322+ }
73323+#endif
73324+
73325 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
73326 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73327
73328diff --git a/mm/mprotect.c b/mm/mprotect.c
73329index a409926..8b32e6d 100644
73330--- a/mm/mprotect.c
73331+++ b/mm/mprotect.c
73332@@ -23,10 +23,17 @@
73333 #include <linux/mmu_notifier.h>
73334 #include <linux/migrate.h>
73335 #include <linux/perf_event.h>
73336+
73337+#ifdef CONFIG_PAX_MPROTECT
73338+#include <linux/elf.h>
73339+#include <linux/binfmts.h>
73340+#endif
73341+
73342 #include <asm/uaccess.h>
73343 #include <asm/pgtable.h>
73344 #include <asm/cacheflush.h>
73345 #include <asm/tlbflush.h>
73346+#include <asm/mmu_context.h>
73347
73348 #ifndef pgprot_modify
73349 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
73350@@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
73351 flush_tlb_range(vma, start, end);
73352 }
73353
73354+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73355+/* called while holding the mmap semaphor for writing except stack expansion */
73356+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
73357+{
73358+ unsigned long oldlimit, newlimit = 0UL;
73359+
73360+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
73361+ return;
73362+
73363+ spin_lock(&mm->page_table_lock);
73364+ oldlimit = mm->context.user_cs_limit;
73365+ if ((prot & VM_EXEC) && oldlimit < end)
73366+ /* USER_CS limit moved up */
73367+ newlimit = end;
73368+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
73369+ /* USER_CS limit moved down */
73370+ newlimit = start;
73371+
73372+ if (newlimit) {
73373+ mm->context.user_cs_limit = newlimit;
73374+
73375+#ifdef CONFIG_SMP
73376+ wmb();
73377+ cpus_clear(mm->context.cpu_user_cs_mask);
73378+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
73379+#endif
73380+
73381+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
73382+ }
73383+ spin_unlock(&mm->page_table_lock);
73384+ if (newlimit == end) {
73385+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
73386+
73387+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
73388+ if (is_vm_hugetlb_page(vma))
73389+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
73390+ else
73391+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
73392+ }
73393+}
73394+#endif
73395+
73396 int
73397 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73398 unsigned long start, unsigned long end, unsigned long newflags)
73399@@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73400 int error;
73401 int dirty_accountable = 0;
73402
73403+#ifdef CONFIG_PAX_SEGMEXEC
73404+ struct vm_area_struct *vma_m = NULL;
73405+ unsigned long start_m, end_m;
73406+
73407+ start_m = start + SEGMEXEC_TASK_SIZE;
73408+ end_m = end + SEGMEXEC_TASK_SIZE;
73409+#endif
73410+
73411 if (newflags == oldflags) {
73412 *pprev = vma;
73413 return 0;
73414 }
73415
73416+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
73417+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
73418+
73419+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
73420+ return -ENOMEM;
73421+
73422+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
73423+ return -ENOMEM;
73424+ }
73425+
73426 /*
73427 * If we make a private mapping writable we increase our commit;
73428 * but (without finer accounting) cannot reduce our commit if we
73429@@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73430 }
73431 }
73432
73433+#ifdef CONFIG_PAX_SEGMEXEC
73434+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
73435+ if (start != vma->vm_start) {
73436+ error = split_vma(mm, vma, start, 1);
73437+ if (error)
73438+ goto fail;
73439+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
73440+ *pprev = (*pprev)->vm_next;
73441+ }
73442+
73443+ if (end != vma->vm_end) {
73444+ error = split_vma(mm, vma, end, 0);
73445+ if (error)
73446+ goto fail;
73447+ }
73448+
73449+ if (pax_find_mirror_vma(vma)) {
73450+ error = __do_munmap(mm, start_m, end_m - start_m);
73451+ if (error)
73452+ goto fail;
73453+ } else {
73454+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73455+ if (!vma_m) {
73456+ error = -ENOMEM;
73457+ goto fail;
73458+ }
73459+ vma->vm_flags = newflags;
73460+ error = pax_mirror_vma(vma_m, vma);
73461+ if (error) {
73462+ vma->vm_flags = oldflags;
73463+ goto fail;
73464+ }
73465+ }
73466+ }
73467+#endif
73468+
73469 /*
73470 * First try to merge with previous and/or next vma.
73471 */
73472@@ -204,9 +307,21 @@ success:
73473 * vm_flags and vm_page_prot are protected by the mmap_sem
73474 * held in write mode.
73475 */
73476+
73477+#ifdef CONFIG_PAX_SEGMEXEC
73478+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
73479+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
73480+#endif
73481+
73482 vma->vm_flags = newflags;
73483+
73484+#ifdef CONFIG_PAX_MPROTECT
73485+ if (mm->binfmt && mm->binfmt->handle_mprotect)
73486+ mm->binfmt->handle_mprotect(vma, newflags);
73487+#endif
73488+
73489 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
73490- vm_get_page_prot(newflags));
73491+ vm_get_page_prot(vma->vm_flags));
73492
73493 if (vma_wants_writenotify(vma)) {
73494 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
73495@@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73496 end = start + len;
73497 if (end <= start)
73498 return -ENOMEM;
73499+
73500+#ifdef CONFIG_PAX_SEGMEXEC
73501+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
73502+ if (end > SEGMEXEC_TASK_SIZE)
73503+ return -EINVAL;
73504+ } else
73505+#endif
73506+
73507+ if (end > TASK_SIZE)
73508+ return -EINVAL;
73509+
73510 if (!arch_validate_prot(prot))
73511 return -EINVAL;
73512
73513@@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73514 /*
73515 * Does the application expect PROT_READ to imply PROT_EXEC:
73516 */
73517- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
73518+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
73519 prot |= PROT_EXEC;
73520
73521 vm_flags = calc_vm_prot_bits(prot);
73522@@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73523 if (start > vma->vm_start)
73524 prev = vma;
73525
73526+#ifdef CONFIG_PAX_MPROTECT
73527+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
73528+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
73529+#endif
73530+
73531 for (nstart = start ; ; ) {
73532 unsigned long newflags;
73533
73534@@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73535
73536 /* newflags >> 4 shift VM_MAY% in place of VM_% */
73537 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
73538+ if (prot & (PROT_WRITE | PROT_EXEC))
73539+ gr_log_rwxmprotect(vma->vm_file);
73540+
73541+ error = -EACCES;
73542+ goto out;
73543+ }
73544+
73545+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
73546 error = -EACCES;
73547 goto out;
73548 }
73549@@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
73550 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
73551 if (error)
73552 goto out;
73553+
73554+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
73555+
73556 nstart = tmp;
73557
73558 if (nstart < prev->vm_end)
73559diff --git a/mm/mremap.c b/mm/mremap.c
73560index 21fed20..6822658 100644
73561--- a/mm/mremap.c
73562+++ b/mm/mremap.c
73563@@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
73564 continue;
73565 pte = ptep_get_and_clear(mm, old_addr, old_pte);
73566 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
73567+
73568+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73569+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
73570+ pte = pte_exprotect(pte);
73571+#endif
73572+
73573 set_pte_at(mm, new_addr, new_pte, pte);
73574 }
73575
73576@@ -299,6 +305,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
73577 if (is_vm_hugetlb_page(vma))
73578 goto Einval;
73579
73580+#ifdef CONFIG_PAX_SEGMEXEC
73581+ if (pax_find_mirror_vma(vma))
73582+ goto Einval;
73583+#endif
73584+
73585 /* We can't remap across vm area boundaries */
73586 if (old_len > vma->vm_end - addr)
73587 goto Efault;
73588@@ -355,20 +366,25 @@ static unsigned long mremap_to(unsigned long addr,
73589 unsigned long ret = -EINVAL;
73590 unsigned long charged = 0;
73591 unsigned long map_flags;
73592+ unsigned long pax_task_size = TASK_SIZE;
73593
73594 if (new_addr & ~PAGE_MASK)
73595 goto out;
73596
73597- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
73598+#ifdef CONFIG_PAX_SEGMEXEC
73599+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
73600+ pax_task_size = SEGMEXEC_TASK_SIZE;
73601+#endif
73602+
73603+ pax_task_size -= PAGE_SIZE;
73604+
73605+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
73606 goto out;
73607
73608 /* Check if the location we're moving into overlaps the
73609 * old location at all, and fail if it does.
73610 */
73611- if ((new_addr <= addr) && (new_addr+new_len) > addr)
73612- goto out;
73613-
73614- if ((addr <= new_addr) && (addr+old_len) > new_addr)
73615+ if (addr + old_len > new_addr && new_addr + new_len > addr)
73616 goto out;
73617
73618 ret = do_munmap(mm, new_addr, new_len);
73619@@ -436,6 +452,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73620 struct vm_area_struct *vma;
73621 unsigned long ret = -EINVAL;
73622 unsigned long charged = 0;
73623+ unsigned long pax_task_size = TASK_SIZE;
73624
73625 down_write(&current->mm->mmap_sem);
73626
73627@@ -456,6 +473,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73628 if (!new_len)
73629 goto out;
73630
73631+#ifdef CONFIG_PAX_SEGMEXEC
73632+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
73633+ pax_task_size = SEGMEXEC_TASK_SIZE;
73634+#endif
73635+
73636+ pax_task_size -= PAGE_SIZE;
73637+
73638+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
73639+ old_len > pax_task_size || addr > pax_task_size-old_len)
73640+ goto out;
73641+
73642 if (flags & MREMAP_FIXED) {
73643 if (flags & MREMAP_MAYMOVE)
73644 ret = mremap_to(addr, old_len, new_addr, new_len);
73645@@ -505,6 +533,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73646 addr + new_len);
73647 }
73648 ret = addr;
73649+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
73650 goto out;
73651 }
73652 }
73653@@ -528,7 +557,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
73654 goto out;
73655 }
73656
73657+ map_flags = vma->vm_flags;
73658 ret = move_vma(vma, addr, old_len, new_len, new_addr);
73659+ if (!(ret & ~PAGE_MASK)) {
73660+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
73661+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
73662+ }
73663 }
73664 out:
73665 if (ret & ~PAGE_MASK)
73666diff --git a/mm/nommu.c b/mm/nommu.c
73667index d4b0c10..ed421b5 100644
73668--- a/mm/nommu.c
73669+++ b/mm/nommu.c
73670@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
73671 int sysctl_overcommit_ratio = 50; /* default is 50% */
73672 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
73673 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
73674-int heap_stack_gap = 0;
73675
73676 atomic_long_t mmap_pages_allocated;
73677
73678@@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
73679 EXPORT_SYMBOL(find_vma);
73680
73681 /*
73682- * find a VMA
73683- * - we don't extend stack VMAs under NOMMU conditions
73684- */
73685-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
73686-{
73687- return find_vma(mm, addr);
73688-}
73689-
73690-/*
73691 * expand a stack to a given address
73692 * - not supported under NOMMU conditions
73693 */
73694@@ -1551,6 +1541,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73695
73696 /* most fields are the same, copy all, and then fixup */
73697 *new = *vma;
73698+ INIT_LIST_HEAD(&new->anon_vma_chain);
73699 *region = *vma->vm_region;
73700 new->vm_region = region;
73701
73702diff --git a/mm/page_alloc.c b/mm/page_alloc.c
73703index 201b508..1fb51ca 100644
73704--- a/mm/page_alloc.c
73705+++ b/mm/page_alloc.c
73706@@ -336,7 +336,7 @@ out:
73707 * This usage means that zero-order pages may not be compound.
73708 */
73709
73710-static void free_compound_page(struct page *page)
73711+void free_compound_page(struct page *page)
73712 {
73713 __free_pages_ok(page, compound_order(page));
73714 }
73715@@ -693,6 +693,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73716 int i;
73717 int bad = 0;
73718
73719+#ifdef CONFIG_PAX_MEMORY_SANITIZE
73720+ unsigned long index = 1UL << order;
73721+#endif
73722+
73723 trace_mm_page_free(page, order);
73724 kmemcheck_free_shadow(page, order);
73725
73726@@ -708,6 +712,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73727 debug_check_no_obj_freed(page_address(page),
73728 PAGE_SIZE << order);
73729 }
73730+
73731+#ifdef CONFIG_PAX_MEMORY_SANITIZE
73732+ for (; index; --index)
73733+ sanitize_highpage(page + index - 1);
73734+#endif
73735+
73736 arch_free_page(page, order);
73737 kernel_map_pages(page, 1 << order, 0);
73738
73739@@ -849,8 +859,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
73740 arch_alloc_page(page, order);
73741 kernel_map_pages(page, 1 << order, 1);
73742
73743+#ifndef CONFIG_PAX_MEMORY_SANITIZE
73744 if (gfp_flags & __GFP_ZERO)
73745 prep_zero_page(page, order, gfp_flags);
73746+#endif
73747
73748 if (order && (gfp_flags & __GFP_COMP))
73749 prep_compound_page(page, order);
73750@@ -3579,7 +3591,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
73751 unsigned long pfn;
73752
73753 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
73754+#ifdef CONFIG_X86_32
73755+ /* boot failures in VMware 8 on 32bit vanilla since
73756+ this change */
73757+ if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
73758+#else
73759 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
73760+#endif
73761 return 1;
73762 }
73763 return 0;
73764diff --git a/mm/percpu.c b/mm/percpu.c
73765index bb4be74..a43ea85 100644
73766--- a/mm/percpu.c
73767+++ b/mm/percpu.c
73768@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
73769 static unsigned int pcpu_high_unit_cpu __read_mostly;
73770
73771 /* the address of the first chunk which starts with the kernel static area */
73772-void *pcpu_base_addr __read_mostly;
73773+void *pcpu_base_addr __read_only;
73774 EXPORT_SYMBOL_GPL(pcpu_base_addr);
73775
73776 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
73777diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
73778index 926b466..b23df53 100644
73779--- a/mm/process_vm_access.c
73780+++ b/mm/process_vm_access.c
73781@@ -13,6 +13,7 @@
73782 #include <linux/uio.h>
73783 #include <linux/sched.h>
73784 #include <linux/highmem.h>
73785+#include <linux/security.h>
73786 #include <linux/ptrace.h>
73787 #include <linux/slab.h>
73788 #include <linux/syscalls.h>
73789@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73790 size_t iov_l_curr_offset = 0;
73791 ssize_t iov_len;
73792
73793+ return -ENOSYS; // PaX: until properly audited
73794+
73795 /*
73796 * Work out how many pages of struct pages we're going to need
73797 * when eventually calling get_user_pages
73798 */
73799 for (i = 0; i < riovcnt; i++) {
73800 iov_len = rvec[i].iov_len;
73801- if (iov_len > 0) {
73802- nr_pages_iov = ((unsigned long)rvec[i].iov_base
73803- + iov_len)
73804- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
73805- / PAGE_SIZE + 1;
73806- nr_pages = max(nr_pages, nr_pages_iov);
73807- }
73808+ if (iov_len <= 0)
73809+ continue;
73810+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
73811+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
73812+ nr_pages = max(nr_pages, nr_pages_iov);
73813 }
73814
73815 if (nr_pages == 0)
73816@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73817 goto free_proc_pages;
73818 }
73819
73820+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
73821+ rc = -EPERM;
73822+ goto put_task_struct;
73823+ }
73824+
73825 mm = mm_access(task, PTRACE_MODE_ATTACH);
73826 if (!mm || IS_ERR(mm)) {
73827 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
73828diff --git a/mm/rmap.c b/mm/rmap.c
73829index 0f3b7cd..c5652b6 100644
73830--- a/mm/rmap.c
73831+++ b/mm/rmap.c
73832@@ -167,6 +167,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73833 struct anon_vma *anon_vma = vma->anon_vma;
73834 struct anon_vma_chain *avc;
73835
73836+#ifdef CONFIG_PAX_SEGMEXEC
73837+ struct anon_vma_chain *avc_m = NULL;
73838+#endif
73839+
73840 might_sleep();
73841 if (unlikely(!anon_vma)) {
73842 struct mm_struct *mm = vma->vm_mm;
73843@@ -176,6 +180,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73844 if (!avc)
73845 goto out_enomem;
73846
73847+#ifdef CONFIG_PAX_SEGMEXEC
73848+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
73849+ if (!avc_m)
73850+ goto out_enomem_free_avc;
73851+#endif
73852+
73853 anon_vma = find_mergeable_anon_vma(vma);
73854 allocated = NULL;
73855 if (!anon_vma) {
73856@@ -189,6 +199,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73857 /* page_table_lock to protect against threads */
73858 spin_lock(&mm->page_table_lock);
73859 if (likely(!vma->anon_vma)) {
73860+
73861+#ifdef CONFIG_PAX_SEGMEXEC
73862+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
73863+
73864+ if (vma_m) {
73865+ BUG_ON(vma_m->anon_vma);
73866+ vma_m->anon_vma = anon_vma;
73867+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
73868+ avc_m = NULL;
73869+ }
73870+#endif
73871+
73872 vma->anon_vma = anon_vma;
73873 anon_vma_chain_link(vma, avc, anon_vma);
73874 allocated = NULL;
73875@@ -199,12 +221,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73876
73877 if (unlikely(allocated))
73878 put_anon_vma(allocated);
73879+
73880+#ifdef CONFIG_PAX_SEGMEXEC
73881+ if (unlikely(avc_m))
73882+ anon_vma_chain_free(avc_m);
73883+#endif
73884+
73885 if (unlikely(avc))
73886 anon_vma_chain_free(avc);
73887 }
73888 return 0;
73889
73890 out_enomem_free_avc:
73891+
73892+#ifdef CONFIG_PAX_SEGMEXEC
73893+ if (avc_m)
73894+ anon_vma_chain_free(avc_m);
73895+#endif
73896+
73897 anon_vma_chain_free(avc);
73898 out_enomem:
73899 return -ENOMEM;
73900@@ -240,7 +274,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
73901 * Attach the anon_vmas from src to dst.
73902 * Returns 0 on success, -ENOMEM on failure.
73903 */
73904-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
73905+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
73906 {
73907 struct anon_vma_chain *avc, *pavc;
73908 struct anon_vma *root = NULL;
73909@@ -318,7 +352,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
73910 * the corresponding VMA in the parent process is attached to.
73911 * Returns 0 on success, non-zero on failure.
73912 */
73913-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
73914+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
73915 {
73916 struct anon_vma_chain *avc;
73917 struct anon_vma *anon_vma;
73918diff --git a/mm/shmem.c b/mm/shmem.c
73919index bd10636..5c16d49 100644
73920--- a/mm/shmem.c
73921+++ b/mm/shmem.c
73922@@ -31,7 +31,7 @@
73923 #include <linux/export.h>
73924 #include <linux/swap.h>
73925
73926-static struct vfsmount *shm_mnt;
73927+struct vfsmount *shm_mnt;
73928
73929 #ifdef CONFIG_SHMEM
73930 /*
73931@@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
73932 #define BOGO_DIRENT_SIZE 20
73933
73934 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
73935-#define SHORT_SYMLINK_LEN 128
73936+#define SHORT_SYMLINK_LEN 64
73937
73938 struct shmem_xattr {
73939 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
73940@@ -2590,8 +2590,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
73941 int err = -ENOMEM;
73942
73943 /* Round up to L1_CACHE_BYTES to resist false sharing */
73944- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
73945- L1_CACHE_BYTES), GFP_KERNEL);
73946+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
73947 if (!sbinfo)
73948 return -ENOMEM;
73949
73950diff --git a/mm/slab.c b/mm/slab.c
73951index e901a36..ca479fc 100644
73952--- a/mm/slab.c
73953+++ b/mm/slab.c
73954@@ -153,7 +153,7 @@
73955
73956 /* Legal flag mask for kmem_cache_create(). */
73957 #if DEBUG
73958-# define CREATE_MASK (SLAB_RED_ZONE | \
73959+# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
73960 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
73961 SLAB_CACHE_DMA | \
73962 SLAB_STORE_USER | \
73963@@ -161,7 +161,7 @@
73964 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73965 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
73966 #else
73967-# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
73968+# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
73969 SLAB_CACHE_DMA | \
73970 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
73971 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73972@@ -290,7 +290,7 @@ struct kmem_list3 {
73973 * Need this for bootstrapping a per node allocator.
73974 */
73975 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
73976-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
73977+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
73978 #define CACHE_CACHE 0
73979 #define SIZE_AC MAX_NUMNODES
73980 #define SIZE_L3 (2 * MAX_NUMNODES)
73981@@ -391,10 +391,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
73982 if ((x)->max_freeable < i) \
73983 (x)->max_freeable = i; \
73984 } while (0)
73985-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
73986-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
73987-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
73988-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
73989+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
73990+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
73991+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
73992+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
73993 #else
73994 #define STATS_INC_ACTIVE(x) do { } while (0)
73995 #define STATS_DEC_ACTIVE(x) do { } while (0)
73996@@ -542,7 +542,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
73997 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
73998 */
73999 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
74000- const struct slab *slab, void *obj)
74001+ const struct slab *slab, const void *obj)
74002 {
74003 u32 offset = (obj - slab->s_mem);
74004 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
74005@@ -563,12 +563,13 @@ EXPORT_SYMBOL(malloc_sizes);
74006 struct cache_names {
74007 char *name;
74008 char *name_dma;
74009+ char *name_usercopy;
74010 };
74011
74012 static struct cache_names __initdata cache_names[] = {
74013-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
74014+#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
74015 #include <linux/kmalloc_sizes.h>
74016- {NULL,}
74017+ {NULL}
74018 #undef CACHE
74019 };
74020
74021@@ -756,6 +757,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
74022 if (unlikely(gfpflags & GFP_DMA))
74023 return csizep->cs_dmacachep;
74024 #endif
74025+
74026+#ifdef CONFIG_PAX_USERCOPY_SLABS
74027+ if (unlikely(gfpflags & GFP_USERCOPY))
74028+ return csizep->cs_usercopycachep;
74029+#endif
74030+
74031 return csizep->cs_cachep;
74032 }
74033
74034@@ -1588,7 +1595,7 @@ void __init kmem_cache_init(void)
74035 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
74036 sizes[INDEX_AC].cs_size,
74037 ARCH_KMALLOC_MINALIGN,
74038- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74039+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74040 NULL);
74041
74042 if (INDEX_AC != INDEX_L3) {
74043@@ -1596,7 +1603,7 @@ void __init kmem_cache_init(void)
74044 kmem_cache_create(names[INDEX_L3].name,
74045 sizes[INDEX_L3].cs_size,
74046 ARCH_KMALLOC_MINALIGN,
74047- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74048+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74049 NULL);
74050 }
74051
74052@@ -1614,7 +1621,7 @@ void __init kmem_cache_init(void)
74053 sizes->cs_cachep = kmem_cache_create(names->name,
74054 sizes->cs_size,
74055 ARCH_KMALLOC_MINALIGN,
74056- ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74057+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74058 NULL);
74059 }
74060 #ifdef CONFIG_ZONE_DMA
74061@@ -1626,6 +1633,16 @@ void __init kmem_cache_init(void)
74062 SLAB_PANIC,
74063 NULL);
74064 #endif
74065+
74066+#ifdef CONFIG_PAX_USERCOPY_SLABS
74067+ sizes->cs_usercopycachep = kmem_cache_create(
74068+ names->name_usercopy,
74069+ sizes->cs_size,
74070+ ARCH_KMALLOC_MINALIGN,
74071+ ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74072+ NULL);
74073+#endif
74074+
74075 sizes++;
74076 names++;
74077 }
74078@@ -4390,10 +4407,10 @@ static int s_show(struct seq_file *m, void *p)
74079 }
74080 /* cpu stats */
74081 {
74082- unsigned long allochit = atomic_read(&cachep->allochit);
74083- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
74084- unsigned long freehit = atomic_read(&cachep->freehit);
74085- unsigned long freemiss = atomic_read(&cachep->freemiss);
74086+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
74087+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
74088+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
74089+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
74090
74091 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
74092 allochit, allocmiss, freehit, freemiss);
74093@@ -4652,13 +4669,68 @@ static int __init slab_proc_init(void)
74094 {
74095 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
74096 #ifdef CONFIG_DEBUG_SLAB_LEAK
74097- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
74098+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
74099 #endif
74100 return 0;
74101 }
74102 module_init(slab_proc_init);
74103 #endif
74104
74105+bool is_usercopy_object(const void *ptr)
74106+{
74107+ struct page *page;
74108+ struct kmem_cache *cachep;
74109+
74110+ if (ZERO_OR_NULL_PTR(ptr))
74111+ return false;
74112+
74113+ if (!virt_addr_valid(ptr))
74114+ return false;
74115+
74116+ page = virt_to_head_page(ptr);
74117+
74118+ if (!PageSlab(page))
74119+ return false;
74120+
74121+ cachep = page_get_cache(page);
74122+ return cachep->flags & SLAB_USERCOPY;
74123+}
74124+
74125+#ifdef CONFIG_PAX_USERCOPY
74126+const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74127+{
74128+ struct page *page;
74129+ struct kmem_cache *cachep;
74130+ struct slab *slabp;
74131+ unsigned int objnr;
74132+ unsigned long offset;
74133+
74134+ if (ZERO_OR_NULL_PTR(ptr))
74135+ return "<null>";
74136+
74137+ if (!virt_addr_valid(ptr))
74138+ return NULL;
74139+
74140+ page = virt_to_head_page(ptr);
74141+
74142+ if (!PageSlab(page))
74143+ return NULL;
74144+
74145+ cachep = page_get_cache(page);
74146+ if (!(cachep->flags & SLAB_USERCOPY))
74147+ return cachep->name;
74148+
74149+ slabp = page_get_slab(page);
74150+ objnr = obj_to_index(cachep, slabp, ptr);
74151+ BUG_ON(objnr >= cachep->num);
74152+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
74153+ if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
74154+ return NULL;
74155+
74156+ return cachep->name;
74157+}
74158+#endif
74159+
74160 /**
74161 * ksize - get the actual amount of memory allocated for a given object
74162 * @objp: Pointer to the object
74163diff --git a/mm/slob.c b/mm/slob.c
74164index 8105be4..3c15e57 100644
74165--- a/mm/slob.c
74166+++ b/mm/slob.c
74167@@ -29,7 +29,7 @@
74168 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
74169 * alloc_pages() directly, allocating compound pages so the page order
74170 * does not have to be separately tracked, and also stores the exact
74171- * allocation size in page->private so that it can be used to accurately
74172+ * allocation size in slob_page->size so that it can be used to accurately
74173 * provide ksize(). These objects are detected in kfree() because slob_page()
74174 * is false for them.
74175 *
74176@@ -58,6 +58,7 @@
74177 */
74178
74179 #include <linux/kernel.h>
74180+#include <linux/sched.h>
74181 #include <linux/slab.h>
74182 #include <linux/mm.h>
74183 #include <linux/swap.h> /* struct reclaim_state */
74184@@ -102,7 +103,8 @@ struct slob_page {
74185 unsigned long flags; /* mandatory */
74186 atomic_t _count; /* mandatory */
74187 slobidx_t units; /* free units left in page */
74188- unsigned long pad[2];
74189+ unsigned long pad[1];
74190+ unsigned long size; /* size when >=PAGE_SIZE */
74191 slob_t *free; /* first free slob_t in page */
74192 struct list_head list; /* linked list of free pages */
74193 };
74194@@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
74195 */
74196 static inline int is_slob_page(struct slob_page *sp)
74197 {
74198- return PageSlab((struct page *)sp);
74199+ return PageSlab((struct page *)sp) && !sp->size;
74200 }
74201
74202 static inline void set_slob_page(struct slob_page *sp)
74203@@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
74204
74205 static inline struct slob_page *slob_page(const void *addr)
74206 {
74207- return (struct slob_page *)virt_to_page(addr);
74208+ return (struct slob_page *)virt_to_head_page(addr);
74209 }
74210
74211 /*
74212@@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
74213 /*
74214 * Return the size of a slob block.
74215 */
74216-static slobidx_t slob_units(slob_t *s)
74217+static slobidx_t slob_units(const slob_t *s)
74218 {
74219 if (s->units > 0)
74220 return s->units;
74221@@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
74222 /*
74223 * Return the next free slob block pointer after this one.
74224 */
74225-static slob_t *slob_next(slob_t *s)
74226+static slob_t *slob_next(const slob_t *s)
74227 {
74228 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
74229 slobidx_t next;
74230@@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
74231 /*
74232 * Returns true if s is the last free block in its page.
74233 */
74234-static int slob_last(slob_t *s)
74235+static int slob_last(const slob_t *s)
74236 {
74237 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
74238 }
74239@@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
74240 if (!page)
74241 return NULL;
74242
74243+ set_slob_page(page);
74244 return page_address(page);
74245 }
74246
74247@@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
74248 if (!b)
74249 return NULL;
74250 sp = slob_page(b);
74251- set_slob_page(sp);
74252
74253 spin_lock_irqsave(&slob_lock, flags);
74254 sp->units = SLOB_UNITS(PAGE_SIZE);
74255 sp->free = b;
74256+ sp->size = 0;
74257 INIT_LIST_HEAD(&sp->list);
74258 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
74259 set_slob_page_free(sp, slob_list);
74260@@ -476,10 +479,9 @@ out:
74261 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
74262 */
74263
74264-void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74265+static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
74266 {
74267- unsigned int *m;
74268- int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74269+ slob_t *m;
74270 void *ret;
74271
74272 gfp &= gfp_allowed_mask;
74273@@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74274
74275 if (!m)
74276 return NULL;
74277- *m = size;
74278+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
74279+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
74280+ m[0].units = size;
74281+ m[1].units = align;
74282 ret = (void *)m + align;
74283
74284 trace_kmalloc_node(_RET_IP_, ret,
74285@@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74286 gfp |= __GFP_COMP;
74287 ret = slob_new_pages(gfp, order, node);
74288 if (ret) {
74289- struct page *page;
74290- page = virt_to_page(ret);
74291- page->private = size;
74292+ struct slob_page *sp;
74293+ sp = slob_page(ret);
74294+ sp->size = size;
74295 }
74296
74297 trace_kmalloc_node(_RET_IP_, ret,
74298 size, PAGE_SIZE << order, gfp, node);
74299 }
74300
74301- kmemleak_alloc(ret, size, 1, gfp);
74302+ return ret;
74303+}
74304+
74305+void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74306+{
74307+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74308+ void *ret = __kmalloc_node_align(size, gfp, node, align);
74309+
74310+ if (!ZERO_OR_NULL_PTR(ret))
74311+ kmemleak_alloc(ret, size, 1, gfp);
74312 return ret;
74313 }
74314 EXPORT_SYMBOL(__kmalloc_node);
74315@@ -533,13 +547,83 @@ void kfree(const void *block)
74316 sp = slob_page(block);
74317 if (is_slob_page(sp)) {
74318 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74319- unsigned int *m = (unsigned int *)(block - align);
74320- slob_free(m, *m + align);
74321- } else
74322+ slob_t *m = (slob_t *)(block - align);
74323+ slob_free(m, m[0].units + align);
74324+ } else {
74325+ clear_slob_page(sp);
74326+ free_slob_page(sp);
74327+ sp->size = 0;
74328 put_page(&sp->page);
74329+ }
74330 }
74331 EXPORT_SYMBOL(kfree);
74332
74333+bool is_usercopy_object(const void *ptr)
74334+{
74335+ return false;
74336+}
74337+
74338+#ifdef CONFIG_PAX_USERCOPY
74339+const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74340+{
74341+ struct slob_page *sp;
74342+ const slob_t *free;
74343+ const void *base;
74344+ unsigned long flags;
74345+
74346+ if (ZERO_OR_NULL_PTR(ptr))
74347+ return "<null>";
74348+
74349+ if (!virt_addr_valid(ptr))
74350+ return NULL;
74351+
74352+ sp = slob_page(ptr);
74353+ if (!PageSlab((struct page *)sp))
74354+ return NULL;
74355+
74356+ if (sp->size) {
74357+ base = page_address(&sp->page);
74358+ if (base <= ptr && n <= sp->size - (ptr - base))
74359+ return NULL;
74360+ return "<slob>";
74361+ }
74362+
74363+ /* some tricky double walking to find the chunk */
74364+ spin_lock_irqsave(&slob_lock, flags);
74365+ base = (void *)((unsigned long)ptr & PAGE_MASK);
74366+ free = sp->free;
74367+
74368+ while (!slob_last(free) && (void *)free <= ptr) {
74369+ base = free + slob_units(free);
74370+ free = slob_next(free);
74371+ }
74372+
74373+ while (base < (void *)free) {
74374+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
74375+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
74376+ int offset;
74377+
74378+ if (ptr < base + align)
74379+ break;
74380+
74381+ offset = ptr - base - align;
74382+ if (offset >= m) {
74383+ base += size;
74384+ continue;
74385+ }
74386+
74387+ if (n > m - offset)
74388+ break;
74389+
74390+ spin_unlock_irqrestore(&slob_lock, flags);
74391+ return NULL;
74392+ }
74393+
74394+ spin_unlock_irqrestore(&slob_lock, flags);
74395+ return "<slob>";
74396+}
74397+#endif
74398+
74399 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
74400 size_t ksize(const void *block)
74401 {
74402@@ -552,10 +636,10 @@ size_t ksize(const void *block)
74403 sp = slob_page(block);
74404 if (is_slob_page(sp)) {
74405 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74406- unsigned int *m = (unsigned int *)(block - align);
74407- return SLOB_UNITS(*m) * SLOB_UNIT;
74408+ slob_t *m = (slob_t *)(block - align);
74409+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
74410 } else
74411- return sp->page.private;
74412+ return sp->size;
74413 }
74414 EXPORT_SYMBOL(ksize);
74415
74416@@ -571,8 +655,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74417 {
74418 struct kmem_cache *c;
74419
74420+#ifdef CONFIG_PAX_USERCOPY_SLABS
74421+ c = __kmalloc_node_align(sizeof(struct kmem_cache),
74422+ GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
74423+#else
74424 c = slob_alloc(sizeof(struct kmem_cache),
74425 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
74426+#endif
74427
74428 if (c) {
74429 c->name = name;
74430@@ -614,17 +703,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
74431
74432 lockdep_trace_alloc(flags);
74433
74434+#ifdef CONFIG_PAX_USERCOPY_SLABS
74435+ b = __kmalloc_node_align(c->size, flags, node, c->align);
74436+#else
74437 if (c->size < PAGE_SIZE) {
74438 b = slob_alloc(c->size, flags, c->align, node);
74439 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74440 SLOB_UNITS(c->size) * SLOB_UNIT,
74441 flags, node);
74442 } else {
74443+ struct slob_page *sp;
74444+
74445 b = slob_new_pages(flags, get_order(c->size), node);
74446+ sp = slob_page(b);
74447+ sp->size = c->size;
74448 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74449 PAGE_SIZE << get_order(c->size),
74450 flags, node);
74451 }
74452+#endif
74453
74454 if (c->ctor)
74455 c->ctor(b);
74456@@ -636,10 +733,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
74457
74458 static void __kmem_cache_free(void *b, int size)
74459 {
74460- if (size < PAGE_SIZE)
74461+ struct slob_page *sp = slob_page(b);
74462+
74463+ if (is_slob_page(sp))
74464 slob_free(b, size);
74465- else
74466+ else {
74467+ clear_slob_page(sp);
74468+ free_slob_page(sp);
74469+ sp->size = 0;
74470 slob_free_pages(b, get_order(size));
74471+ }
74472 }
74473
74474 static void kmem_rcu_free(struct rcu_head *head)
74475@@ -652,17 +755,31 @@ static void kmem_rcu_free(struct rcu_head *head)
74476
74477 void kmem_cache_free(struct kmem_cache *c, void *b)
74478 {
74479+ int size = c->size;
74480+
74481+#ifdef CONFIG_PAX_USERCOPY_SLABS
74482+ if (size + c->align < PAGE_SIZE) {
74483+ size += c->align;
74484+ b -= c->align;
74485+ }
74486+#endif
74487+
74488 kmemleak_free_recursive(b, c->flags);
74489 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
74490 struct slob_rcu *slob_rcu;
74491- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
74492- slob_rcu->size = c->size;
74493+ slob_rcu = b + (size - sizeof(struct slob_rcu));
74494+ slob_rcu->size = size;
74495 call_rcu(&slob_rcu->head, kmem_rcu_free);
74496 } else {
74497- __kmem_cache_free(b, c->size);
74498+ __kmem_cache_free(b, size);
74499 }
74500
74501+#ifdef CONFIG_PAX_USERCOPY_SLABS
74502+ trace_kfree(_RET_IP_, b);
74503+#else
74504 trace_kmem_cache_free(_RET_IP_, b);
74505+#endif
74506+
74507 }
74508 EXPORT_SYMBOL(kmem_cache_free);
74509
74510diff --git a/mm/slub.c b/mm/slub.c
74511index 8c691fa..ff23a85 100644
74512--- a/mm/slub.c
74513+++ b/mm/slub.c
74514@@ -209,7 +209,7 @@ struct track {
74515
74516 enum track_item { TRACK_ALLOC, TRACK_FREE };
74517
74518-#ifdef CONFIG_SYSFS
74519+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74520 static int sysfs_slab_add(struct kmem_cache *);
74521 static int sysfs_slab_alias(struct kmem_cache *, const char *);
74522 static void sysfs_slab_remove(struct kmem_cache *);
74523@@ -538,7 +538,7 @@ static void print_track(const char *s, struct track *t)
74524 if (!t->addr)
74525 return;
74526
74527- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
74528+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
74529 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
74530 #ifdef CONFIG_STACKTRACE
74531 {
74532@@ -2603,6 +2603,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
74533
74534 page = virt_to_head_page(x);
74535
74536+ BUG_ON(!PageSlab(page));
74537+
74538 slab_free(s, page, x, _RET_IP_);
74539
74540 trace_kmem_cache_free(_RET_IP_, x);
74541@@ -2636,7 +2638,7 @@ static int slub_min_objects;
74542 * Merge control. If this is set then no merging of slab caches will occur.
74543 * (Could be removed. This was introduced to pacify the merge skeptics.)
74544 */
74545-static int slub_nomerge;
74546+static int slub_nomerge = 1;
74547
74548 /*
74549 * Calculate the order of allocation given an slab object size.
74550@@ -3089,7 +3091,7 @@ static int kmem_cache_open(struct kmem_cache *s,
74551 else
74552 s->cpu_partial = 30;
74553
74554- s->refcount = 1;
74555+ atomic_set(&s->refcount, 1);
74556 #ifdef CONFIG_NUMA
74557 s->remote_node_defrag_ratio = 1000;
74558 #endif
74559@@ -3193,8 +3195,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
74560 void kmem_cache_destroy(struct kmem_cache *s)
74561 {
74562 down_write(&slub_lock);
74563- s->refcount--;
74564- if (!s->refcount) {
74565+ if (atomic_dec_and_test(&s->refcount)) {
74566 list_del(&s->list);
74567 up_write(&slub_lock);
74568 if (kmem_cache_close(s)) {
74569@@ -3223,6 +3224,10 @@ static struct kmem_cache *kmem_cache;
74570 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
74571 #endif
74572
74573+#ifdef CONFIG_PAX_USERCOPY_SLABS
74574+static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
74575+#endif
74576+
74577 static int __init setup_slub_min_order(char *str)
74578 {
74579 get_option(&str, &slub_min_order);
74580@@ -3337,6 +3342,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
74581 return kmalloc_dma_caches[index];
74582
74583 #endif
74584+
74585+#ifdef CONFIG_PAX_USERCOPY_SLABS
74586+ if (flags & SLAB_USERCOPY)
74587+ return kmalloc_usercopy_caches[index];
74588+
74589+#endif
74590+
74591 return kmalloc_caches[index];
74592 }
74593
74594@@ -3405,6 +3417,56 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
74595 EXPORT_SYMBOL(__kmalloc_node);
74596 #endif
74597
74598+bool is_usercopy_object(const void *ptr)
74599+{
74600+ struct page *page;
74601+ struct kmem_cache *s;
74602+
74603+ if (ZERO_OR_NULL_PTR(ptr))
74604+ return false;
74605+
74606+ if (!virt_addr_valid(ptr))
74607+ return false;
74608+
74609+ page = virt_to_head_page(ptr);
74610+
74611+ if (!PageSlab(page))
74612+ return false;
74613+
74614+ s = page->slab;
74615+ return s->flags & SLAB_USERCOPY;
74616+}
74617+
74618+#ifdef CONFIG_PAX_USERCOPY
74619+const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74620+{
74621+ struct page *page;
74622+ struct kmem_cache *s;
74623+ unsigned long offset;
74624+
74625+ if (ZERO_OR_NULL_PTR(ptr))
74626+ return "<null>";
74627+
74628+ if (!virt_addr_valid(ptr))
74629+ return NULL;
74630+
74631+ page = virt_to_head_page(ptr);
74632+
74633+ if (!PageSlab(page))
74634+ return NULL;
74635+
74636+ s = page->slab;
74637+ if (!(s->flags & SLAB_USERCOPY))
74638+ return s->name;
74639+
74640+ offset = (ptr - page_address(page)) % s->size;
74641+ if (offset <= s->objsize && n <= s->objsize - offset)
74642+ return NULL;
74643+
74644+ return s->name;
74645+}
74646+#endif
74647+
74648 size_t ksize(const void *object)
74649 {
74650 struct page *page;
74651@@ -3679,7 +3741,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
74652 int node;
74653
74654 list_add(&s->list, &slab_caches);
74655- s->refcount = -1;
74656+ atomic_set(&s->refcount, -1);
74657
74658 for_each_node_state(node, N_NORMAL_MEMORY) {
74659 struct kmem_cache_node *n = get_node(s, node);
74660@@ -3799,17 +3861,17 @@ void __init kmem_cache_init(void)
74661
74662 /* Caches that are not of the two-to-the-power-of size */
74663 if (KMALLOC_MIN_SIZE <= 32) {
74664- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
74665+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
74666 caches++;
74667 }
74668
74669 if (KMALLOC_MIN_SIZE <= 64) {
74670- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
74671+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
74672 caches++;
74673 }
74674
74675 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
74676- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
74677+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
74678 caches++;
74679 }
74680
74681@@ -3851,6 +3913,22 @@ void __init kmem_cache_init(void)
74682 }
74683 }
74684 #endif
74685+
74686+#ifdef CONFIG_PAX_USERCOPY_SLABS
74687+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
74688+ struct kmem_cache *s = kmalloc_caches[i];
74689+
74690+ if (s && s->size) {
74691+ char *name = kasprintf(GFP_NOWAIT,
74692+ "usercopy-kmalloc-%d", s->objsize);
74693+
74694+ BUG_ON(!name);
74695+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
74696+ s->objsize, SLAB_USERCOPY);
74697+ }
74698+ }
74699+#endif
74700+
74701 printk(KERN_INFO
74702 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
74703 " CPUs=%d, Nodes=%d\n",
74704@@ -3877,7 +3955,7 @@ static int slab_unmergeable(struct kmem_cache *s)
74705 /*
74706 * We may have set a slab to be unmergeable during bootstrap.
74707 */
74708- if (s->refcount < 0)
74709+ if (atomic_read(&s->refcount) < 0)
74710 return 1;
74711
74712 return 0;
74713@@ -3936,7 +4014,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74714 down_write(&slub_lock);
74715 s = find_mergeable(size, align, flags, name, ctor);
74716 if (s) {
74717- s->refcount++;
74718+ atomic_inc(&s->refcount);
74719 /*
74720 * Adjust the object sizes so that we clear
74721 * the complete object on kzalloc.
74722@@ -3945,7 +4023,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
74723 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
74724
74725 if (sysfs_slab_alias(s, name)) {
74726- s->refcount--;
74727+ atomic_dec(&s->refcount);
74728 goto err;
74729 }
74730 up_write(&slub_lock);
74731@@ -4074,7 +4152,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
74732 }
74733 #endif
74734
74735-#ifdef CONFIG_SYSFS
74736+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74737 static int count_inuse(struct page *page)
74738 {
74739 return page->inuse;
74740@@ -4461,12 +4539,12 @@ static void resiliency_test(void)
74741 validate_slab_cache(kmalloc_caches[9]);
74742 }
74743 #else
74744-#ifdef CONFIG_SYSFS
74745+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74746 static void resiliency_test(void) {};
74747 #endif
74748 #endif
74749
74750-#ifdef CONFIG_SYSFS
74751+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74752 enum slab_stat_type {
74753 SL_ALL, /* All slabs */
74754 SL_PARTIAL, /* Only partially allocated slabs */
74755@@ -4709,7 +4787,7 @@ SLAB_ATTR_RO(ctor);
74756
74757 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
74758 {
74759- return sprintf(buf, "%d\n", s->refcount - 1);
74760+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
74761 }
74762 SLAB_ATTR_RO(aliases);
74763
74764@@ -5280,6 +5358,7 @@ static char *create_unique_id(struct kmem_cache *s)
74765 return name;
74766 }
74767
74768+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74769 static int sysfs_slab_add(struct kmem_cache *s)
74770 {
74771 int err;
74772@@ -5342,6 +5421,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
74773 kobject_del(&s->kobj);
74774 kobject_put(&s->kobj);
74775 }
74776+#endif
74777
74778 /*
74779 * Need to buffer aliases during bootup until sysfs becomes
74780@@ -5355,6 +5435,7 @@ struct saved_alias {
74781
74782 static struct saved_alias *alias_list;
74783
74784+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74785 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74786 {
74787 struct saved_alias *al;
74788@@ -5377,6 +5458,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74789 alias_list = al;
74790 return 0;
74791 }
74792+#endif
74793
74794 static int __init slab_sysfs_init(void)
74795 {
74796diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
74797index 1b7e22a..3fcd4f3 100644
74798--- a/mm/sparse-vmemmap.c
74799+++ b/mm/sparse-vmemmap.c
74800@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
74801 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
74802 if (!p)
74803 return NULL;
74804- pud_populate(&init_mm, pud, p);
74805+ pud_populate_kernel(&init_mm, pud, p);
74806 }
74807 return pud;
74808 }
74809@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
74810 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
74811 if (!p)
74812 return NULL;
74813- pgd_populate(&init_mm, pgd, p);
74814+ pgd_populate_kernel(&init_mm, pgd, p);
74815 }
74816 return pgd;
74817 }
74818diff --git a/mm/swap.c b/mm/swap.c
74819index 4e7e2ec..0c57830 100644
74820--- a/mm/swap.c
74821+++ b/mm/swap.c
74822@@ -30,6 +30,7 @@
74823 #include <linux/backing-dev.h>
74824 #include <linux/memcontrol.h>
74825 #include <linux/gfp.h>
74826+#include <linux/hugetlb.h>
74827
74828 #include "internal.h"
74829
74830@@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
74831
74832 __page_cache_release(page);
74833 dtor = get_compound_page_dtor(page);
74834+ if (!PageHuge(page))
74835+ BUG_ON(dtor != free_compound_page);
74836 (*dtor)(page);
74837 }
74838
74839diff --git a/mm/swapfile.c b/mm/swapfile.c
74840index 71373d0..11fa7d9 100644
74841--- a/mm/swapfile.c
74842+++ b/mm/swapfile.c
74843@@ -63,7 +63,7 @@ static DEFINE_MUTEX(swapon_mutex);
74844
74845 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
74846 /* Activity counter to indicate that a swapon or swapoff has occurred */
74847-static atomic_t proc_poll_event = ATOMIC_INIT(0);
74848+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
74849
74850 static inline unsigned char swap_count(unsigned char ent)
74851 {
74852@@ -1663,7 +1663,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
74853 }
74854 filp_close(swap_file, NULL);
74855 err = 0;
74856- atomic_inc(&proc_poll_event);
74857+ atomic_inc_unchecked(&proc_poll_event);
74858 wake_up_interruptible(&proc_poll_wait);
74859
74860 out_dput:
74861@@ -1679,8 +1679,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
74862
74863 poll_wait(file, &proc_poll_wait, wait);
74864
74865- if (seq->poll_event != atomic_read(&proc_poll_event)) {
74866- seq->poll_event = atomic_read(&proc_poll_event);
74867+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
74868+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74869 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
74870 }
74871
74872@@ -1778,7 +1778,7 @@ static int swaps_open(struct inode *inode, struct file *file)
74873 return ret;
74874
74875 seq = file->private_data;
74876- seq->poll_event = atomic_read(&proc_poll_event);
74877+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74878 return 0;
74879 }
74880
74881@@ -2120,7 +2120,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
74882 (frontswap_map) ? "FS" : "");
74883
74884 mutex_unlock(&swapon_mutex);
74885- atomic_inc(&proc_poll_event);
74886+ atomic_inc_unchecked(&proc_poll_event);
74887 wake_up_interruptible(&proc_poll_wait);
74888
74889 if (S_ISREG(inode->i_mode))
74890diff --git a/mm/util.c b/mm/util.c
74891index 8c7265a..c96d884 100644
74892--- a/mm/util.c
74893+++ b/mm/util.c
74894@@ -285,6 +285,12 @@ done:
74895 void arch_pick_mmap_layout(struct mm_struct *mm)
74896 {
74897 mm->mmap_base = TASK_UNMAPPED_BASE;
74898+
74899+#ifdef CONFIG_PAX_RANDMMAP
74900+ if (mm->pax_flags & MF_PAX_RANDMMAP)
74901+ mm->mmap_base += mm->delta_mmap;
74902+#endif
74903+
74904 mm->get_unmapped_area = arch_get_unmapped_area;
74905 mm->unmap_area = arch_unmap_area;
74906 }
74907diff --git a/mm/vmalloc.c b/mm/vmalloc.c
74908index 2aad499..4006a74 100644
74909--- a/mm/vmalloc.c
74910+++ b/mm/vmalloc.c
74911@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
74912
74913 pte = pte_offset_kernel(pmd, addr);
74914 do {
74915- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74916- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74917+
74918+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74919+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
74920+ BUG_ON(!pte_exec(*pte));
74921+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
74922+ continue;
74923+ }
74924+#endif
74925+
74926+ {
74927+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74928+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74929+ }
74930 } while (pte++, addr += PAGE_SIZE, addr != end);
74931 }
74932
74933@@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74934 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
74935 {
74936 pte_t *pte;
74937+ int ret = -ENOMEM;
74938
74939 /*
74940 * nr is a running index into the array which helps higher level
74941@@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74942 pte = pte_alloc_kernel(pmd, addr);
74943 if (!pte)
74944 return -ENOMEM;
74945+
74946+ pax_open_kernel();
74947 do {
74948 struct page *page = pages[*nr];
74949
74950- if (WARN_ON(!pte_none(*pte)))
74951- return -EBUSY;
74952- if (WARN_ON(!page))
74953- return -ENOMEM;
74954+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74955+ if (pgprot_val(prot) & _PAGE_NX)
74956+#endif
74957+
74958+ if (WARN_ON(!pte_none(*pte))) {
74959+ ret = -EBUSY;
74960+ goto out;
74961+ }
74962+ if (WARN_ON(!page)) {
74963+ ret = -ENOMEM;
74964+ goto out;
74965+ }
74966 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
74967 (*nr)++;
74968 } while (pte++, addr += PAGE_SIZE, addr != end);
74969- return 0;
74970+ ret = 0;
74971+out:
74972+ pax_close_kernel();
74973+ return ret;
74974 }
74975
74976 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
74977@@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
74978 pmd_t *pmd;
74979 unsigned long next;
74980
74981- pmd = pmd_alloc(&init_mm, pud, addr);
74982+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
74983 if (!pmd)
74984 return -ENOMEM;
74985 do {
74986@@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
74987 pud_t *pud;
74988 unsigned long next;
74989
74990- pud = pud_alloc(&init_mm, pgd, addr);
74991+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
74992 if (!pud)
74993 return -ENOMEM;
74994 do {
74995@@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
74996 * and fall back on vmalloc() if that fails. Others
74997 * just put it in the vmalloc space.
74998 */
74999-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
75000+#ifdef CONFIG_MODULES
75001+#ifdef MODULES_VADDR
75002 unsigned long addr = (unsigned long)x;
75003 if (addr >= MODULES_VADDR && addr < MODULES_END)
75004 return 1;
75005 #endif
75006+
75007+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75008+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
75009+ return 1;
75010+#endif
75011+
75012+#endif
75013+
75014 return is_vmalloc_addr(x);
75015 }
75016
75017@@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
75018
75019 if (!pgd_none(*pgd)) {
75020 pud_t *pud = pud_offset(pgd, addr);
75021+#ifdef CONFIG_X86
75022+ if (!pud_large(*pud))
75023+#endif
75024 if (!pud_none(*pud)) {
75025 pmd_t *pmd = pmd_offset(pud, addr);
75026+#ifdef CONFIG_X86
75027+ if (!pmd_large(*pmd))
75028+#endif
75029 if (!pmd_none(*pmd)) {
75030 pte_t *ptep, pte;
75031
75032@@ -329,7 +369,7 @@ static void purge_vmap_area_lazy(void);
75033 * Allocate a region of KVA of the specified size and alignment, within the
75034 * vstart and vend.
75035 */
75036-static struct vmap_area *alloc_vmap_area(unsigned long size,
75037+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
75038 unsigned long align,
75039 unsigned long vstart, unsigned long vend,
75040 int node, gfp_t gfp_mask)
75041@@ -1320,6 +1360,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
75042 struct vm_struct *area;
75043
75044 BUG_ON(in_interrupt());
75045+
75046+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75047+ if (flags & VM_KERNEXEC) {
75048+ if (start != VMALLOC_START || end != VMALLOC_END)
75049+ return NULL;
75050+ start = (unsigned long)MODULES_EXEC_VADDR;
75051+ end = (unsigned long)MODULES_EXEC_END;
75052+ }
75053+#endif
75054+
75055 if (flags & VM_IOREMAP) {
75056 int bit = fls(size);
75057
75058@@ -1552,6 +1602,11 @@ void *vmap(struct page **pages, unsigned int count,
75059 if (count > totalram_pages)
75060 return NULL;
75061
75062+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75063+ if (!(pgprot_val(prot) & _PAGE_NX))
75064+ flags |= VM_KERNEXEC;
75065+#endif
75066+
75067 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
75068 __builtin_return_address(0));
75069 if (!area)
75070@@ -1653,6 +1708,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
75071 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
75072 goto fail;
75073
75074+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75075+ if (!(pgprot_val(prot) & _PAGE_NX))
75076+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
75077+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
75078+ else
75079+#endif
75080+
75081 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
75082 start, end, node, gfp_mask, caller);
75083 if (!area)
75084@@ -1826,10 +1888,9 @@ EXPORT_SYMBOL(vzalloc_node);
75085 * For tight control over page level allocator and protection flags
75086 * use __vmalloc() instead.
75087 */
75088-
75089 void *vmalloc_exec(unsigned long size)
75090 {
75091- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
75092+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
75093 -1, __builtin_return_address(0));
75094 }
75095
75096@@ -2124,6 +2185,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
75097 unsigned long uaddr = vma->vm_start;
75098 unsigned long usize = vma->vm_end - vma->vm_start;
75099
75100+ BUG_ON(vma->vm_mirror);
75101+
75102 if ((PAGE_SIZE-1) & (unsigned long)addr)
75103 return -EINVAL;
75104
75105diff --git a/mm/vmstat.c b/mm/vmstat.c
75106index 1bbbbd9..ff35669 100644
75107--- a/mm/vmstat.c
75108+++ b/mm/vmstat.c
75109@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
75110 *
75111 * vm_stat contains the global counters
75112 */
75113-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75114+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75115 EXPORT_SYMBOL(vm_stat);
75116
75117 #ifdef CONFIG_SMP
75118@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
75119 v = p->vm_stat_diff[i];
75120 p->vm_stat_diff[i] = 0;
75121 local_irq_restore(flags);
75122- atomic_long_add(v, &zone->vm_stat[i]);
75123+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
75124 global_diff[i] += v;
75125 #ifdef CONFIG_NUMA
75126 /* 3 seconds idle till flush */
75127@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
75128
75129 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
75130 if (global_diff[i])
75131- atomic_long_add(global_diff[i], &vm_stat[i]);
75132+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
75133 }
75134
75135 #endif
75136@@ -1211,10 +1211,20 @@ static int __init setup_vmstat(void)
75137 start_cpu_timer(cpu);
75138 #endif
75139 #ifdef CONFIG_PROC_FS
75140- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
75141- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
75142- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
75143- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
75144+ {
75145+ mode_t gr_mode = S_IRUGO;
75146+#ifdef CONFIG_GRKERNSEC_PROC_ADD
75147+ gr_mode = S_IRUSR;
75148+#endif
75149+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
75150+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
75151+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
75152+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
75153+#else
75154+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
75155+#endif
75156+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
75157+ }
75158 #endif
75159 return 0;
75160 }
75161diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
75162index 9096bcb..43ed7bb 100644
75163--- a/net/8021q/vlan.c
75164+++ b/net/8021q/vlan.c
75165@@ -557,8 +557,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
75166 err = -EPERM;
75167 if (!capable(CAP_NET_ADMIN))
75168 break;
75169- if ((args.u.name_type >= 0) &&
75170- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
75171+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
75172 struct vlan_net *vn;
75173
75174 vn = net_generic(net, vlan_net_id);
75175diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
75176index 6449bae..8c1f454 100644
75177--- a/net/9p/trans_fd.c
75178+++ b/net/9p/trans_fd.c
75179@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
75180 oldfs = get_fs();
75181 set_fs(get_ds());
75182 /* The cast to a user pointer is valid due to the set_fs() */
75183- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
75184+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
75185 set_fs(oldfs);
75186
75187 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
75188diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
75189index 876fbe8..8bbea9f 100644
75190--- a/net/atm/atm_misc.c
75191+++ b/net/atm/atm_misc.c
75192@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
75193 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
75194 return 1;
75195 atm_return(vcc, truesize);
75196- atomic_inc(&vcc->stats->rx_drop);
75197+ atomic_inc_unchecked(&vcc->stats->rx_drop);
75198 return 0;
75199 }
75200 EXPORT_SYMBOL(atm_charge);
75201@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
75202 }
75203 }
75204 atm_return(vcc, guess);
75205- atomic_inc(&vcc->stats->rx_drop);
75206+ atomic_inc_unchecked(&vcc->stats->rx_drop);
75207 return NULL;
75208 }
75209 EXPORT_SYMBOL(atm_alloc_charge);
75210@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
75211
75212 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75213 {
75214-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75215+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75216 __SONET_ITEMS
75217 #undef __HANDLE_ITEM
75218 }
75219@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
75220
75221 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75222 {
75223-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75224+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
75225 __SONET_ITEMS
75226 #undef __HANDLE_ITEM
75227 }
75228diff --git a/net/atm/common.c b/net/atm/common.c
75229index b4b44db..0c0ad93 100644
75230--- a/net/atm/common.c
75231+++ b/net/atm/common.c
75232@@ -812,6 +812,7 @@ int vcc_getsockopt(struct socket *sock, int level, int optname,
75233
75234 if (!vcc->dev || !test_bit(ATM_VF_ADDR, &vcc->flags))
75235 return -ENOTCONN;
75236+ memset(&pvc, 0, sizeof(pvc));
75237 pvc.sap_family = AF_ATMPVC;
75238 pvc.sap_addr.itf = vcc->dev->number;
75239 pvc.sap_addr.vpi = vcc->vpi;
75240diff --git a/net/atm/lec.h b/net/atm/lec.h
75241index a86aff9..3a0d6f6 100644
75242--- a/net/atm/lec.h
75243+++ b/net/atm/lec.h
75244@@ -48,7 +48,7 @@ struct lane2_ops {
75245 const u8 *tlvs, u32 sizeoftlvs);
75246 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
75247 const u8 *tlvs, u32 sizeoftlvs);
75248-};
75249+} __no_const;
75250
75251 /*
75252 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
75253diff --git a/net/atm/mpc.h b/net/atm/mpc.h
75254index 0919a88..a23d54e 100644
75255--- a/net/atm/mpc.h
75256+++ b/net/atm/mpc.h
75257@@ -33,7 +33,7 @@ struct mpoa_client {
75258 struct mpc_parameters parameters; /* parameters for this client */
75259
75260 const struct net_device_ops *old_ops;
75261- struct net_device_ops new_ops;
75262+ net_device_ops_no_const new_ops;
75263 };
75264
75265
75266diff --git a/net/atm/proc.c b/net/atm/proc.c
75267index 0d020de..011c7bb 100644
75268--- a/net/atm/proc.c
75269+++ b/net/atm/proc.c
75270@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
75271 const struct k_atm_aal_stats *stats)
75272 {
75273 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
75274- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
75275- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
75276- atomic_read(&stats->rx_drop));
75277+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
75278+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
75279+ atomic_read_unchecked(&stats->rx_drop));
75280 }
75281
75282 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
75283diff --git a/net/atm/pvc.c b/net/atm/pvc.c
75284index 3a73491..ae03240 100644
75285--- a/net/atm/pvc.c
75286+++ b/net/atm/pvc.c
75287@@ -95,6 +95,7 @@ static int pvc_getname(struct socket *sock, struct sockaddr *sockaddr,
75288 return -ENOTCONN;
75289 *sockaddr_len = sizeof(struct sockaddr_atmpvc);
75290 addr = (struct sockaddr_atmpvc *)sockaddr;
75291+ memset(addr, 0, sizeof(*addr));
75292 addr->sap_family = AF_ATMPVC;
75293 addr->sap_addr.itf = vcc->dev->number;
75294 addr->sap_addr.vpi = vcc->vpi;
75295diff --git a/net/atm/resources.c b/net/atm/resources.c
75296index 23f45ce..c748f1a 100644
75297--- a/net/atm/resources.c
75298+++ b/net/atm/resources.c
75299@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
75300 static void copy_aal_stats(struct k_atm_aal_stats *from,
75301 struct atm_aal_stats *to)
75302 {
75303-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75304+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75305 __AAL_STAT_ITEMS
75306 #undef __HANDLE_ITEM
75307 }
75308@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
75309 static void subtract_aal_stats(struct k_atm_aal_stats *from,
75310 struct atm_aal_stats *to)
75311 {
75312-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75313+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
75314 __AAL_STAT_ITEMS
75315 #undef __HANDLE_ITEM
75316 }
75317diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
75318index dc53798..dc66333 100644
75319--- a/net/batman-adv/bat_iv_ogm.c
75320+++ b/net/batman-adv/bat_iv_ogm.c
75321@@ -63,7 +63,7 @@ static int bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
75322
75323 /* randomize initial seqno to avoid collision */
75324 get_random_bytes(&random_seqno, sizeof(random_seqno));
75325- atomic_set(&hard_iface->seqno, random_seqno);
75326+ atomic_set_unchecked(&hard_iface->seqno, random_seqno);
75327
75328 hard_iface->packet_len = BATMAN_OGM_HLEN;
75329 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
75330@@ -572,7 +572,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
75331
75332 /* change sequence number to network order */
75333 batman_ogm_packet->seqno =
75334- htonl((uint32_t)atomic_read(&hard_iface->seqno));
75335+ htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
75336
75337 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
75338 batman_ogm_packet->tt_crc = htons((uint16_t)
75339@@ -592,7 +592,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
75340 else
75341 batman_ogm_packet->gw_flags = NO_FLAGS;
75342
75343- atomic_inc(&hard_iface->seqno);
75344+ atomic_inc_unchecked(&hard_iface->seqno);
75345
75346 slide_own_bcast_window(hard_iface);
75347 bat_iv_ogm_queue_add(bat_priv, hard_iface->packet_buff,
75348@@ -956,7 +956,7 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
75349 return;
75350
75351 /* could be changed by schedule_own_packet() */
75352- if_incoming_seqno = atomic_read(&if_incoming->seqno);
75353+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
75354
75355 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
75356
75357diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
75358index dc334fa..766a01a 100644
75359--- a/net/batman-adv/hard-interface.c
75360+++ b/net/batman-adv/hard-interface.c
75361@@ -321,7 +321,7 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
75362 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
75363 dev_add_pack(&hard_iface->batman_adv_ptype);
75364
75365- atomic_set(&hard_iface->frag_seqno, 1);
75366+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
75367 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
75368 hard_iface->net_dev->name);
75369
75370@@ -444,7 +444,7 @@ static struct hard_iface *hardif_add_interface(struct net_device *net_dev)
75371 * This can't be called via a bat_priv callback because
75372 * we have no bat_priv yet.
75373 */
75374- atomic_set(&hard_iface->seqno, 1);
75375+ atomic_set_unchecked(&hard_iface->seqno, 1);
75376 hard_iface->packet_buff = NULL;
75377
75378 return hard_iface;
75379diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
75380index a0ec0e4..7beb587 100644
75381--- a/net/batman-adv/soft-interface.c
75382+++ b/net/batman-adv/soft-interface.c
75383@@ -214,7 +214,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
75384
75385 /* set broadcast sequence number */
75386 bcast_packet->seqno =
75387- htonl(atomic_inc_return(&bat_priv->bcast_seqno));
75388+ htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
75389
75390 add_bcast_packet_to_list(bat_priv, skb, 1);
75391
75392@@ -390,7 +390,7 @@ struct net_device *softif_create(const char *name)
75393 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
75394
75395 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
75396- atomic_set(&bat_priv->bcast_seqno, 1);
75397+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
75398 atomic_set(&bat_priv->ttvn, 0);
75399 atomic_set(&bat_priv->tt_local_changes, 0);
75400 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
75401diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
75402index 61308e8..2e142b2 100644
75403--- a/net/batman-adv/types.h
75404+++ b/net/batman-adv/types.h
75405@@ -38,8 +38,8 @@ struct hard_iface {
75406 int16_t if_num;
75407 char if_status;
75408 struct net_device *net_dev;
75409- atomic_t seqno;
75410- atomic_t frag_seqno;
75411+ atomic_unchecked_t seqno;
75412+ atomic_unchecked_t frag_seqno;
75413 unsigned char *packet_buff;
75414 int packet_len;
75415 struct kobject *hardif_obj;
75416@@ -163,7 +163,7 @@ struct bat_priv {
75417 atomic_t orig_interval; /* uint */
75418 atomic_t hop_penalty; /* uint */
75419 atomic_t log_level; /* uint */
75420- atomic_t bcast_seqno;
75421+ atomic_unchecked_t bcast_seqno;
75422 atomic_t bcast_queue_left;
75423 atomic_t batman_queue_left;
75424 atomic_t ttvn; /* translation table version number */
75425diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
75426index 74175c2..32f8901 100644
75427--- a/net/batman-adv/unicast.c
75428+++ b/net/batman-adv/unicast.c
75429@@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
75430 frag1->flags = UNI_FRAG_HEAD | large_tail;
75431 frag2->flags = large_tail;
75432
75433- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
75434+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
75435 frag1->seqno = htons(seqno - 1);
75436 frag2->seqno = htons(seqno);
75437
75438diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
75439index 5914623..bedc768 100644
75440--- a/net/bluetooth/hci_sock.c
75441+++ b/net/bluetooth/hci_sock.c
75442@@ -706,6 +706,7 @@ static int hci_sock_getname(struct socket *sock, struct sockaddr *addr, int *add
75443 *addr_len = sizeof(*haddr);
75444 haddr->hci_family = AF_BLUETOOTH;
75445 haddr->hci_dev = hdev->id;
75446+ haddr->hci_channel= 0;
75447
75448 release_sock(sk);
75449 return 0;
75450@@ -1016,6 +1017,7 @@ static int hci_sock_getsockopt(struct socket *sock, int level, int optname, char
75451 {
75452 struct hci_filter *f = &hci_pi(sk)->filter;
75453
75454+ memset(&uf, 0, sizeof(uf));
75455 uf.type_mask = f->type_mask;
75456 uf.opcode = f->opcode;
75457 uf.event_mask[0] = *((u32 *) f->event_mask + 0);
75458diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
75459index 4554e80..b778671 100644
75460--- a/net/bluetooth/l2cap_core.c
75461+++ b/net/bluetooth/l2cap_core.c
75462@@ -2798,8 +2798,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
75463 break;
75464
75465 case L2CAP_CONF_RFC:
75466- if (olen == sizeof(rfc))
75467- memcpy(&rfc, (void *)val, olen);
75468+ if (olen != sizeof(rfc))
75469+ break;
75470+
75471+ memcpy(&rfc, (void *)val, olen);
75472
75473 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
75474 rfc.mode != chan->mode)
75475diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
75476index 3bb1611..fcf656b 100644
75477--- a/net/bluetooth/l2cap_sock.c
75478+++ b/net/bluetooth/l2cap_sock.c
75479@@ -246,6 +246,7 @@ static int l2cap_sock_getname(struct socket *sock, struct sockaddr *addr, int *l
75480
75481 BT_DBG("sock %p, sk %p", sock, sk);
75482
75483+ memset(la, 0, sizeof(struct sockaddr_l2));
75484 addr->sa_family = AF_BLUETOOTH;
75485 *len = sizeof(struct sockaddr_l2);
75486
75487diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
75488index e8707de..2df6956 100644
75489--- a/net/bluetooth/rfcomm/sock.c
75490+++ b/net/bluetooth/rfcomm/sock.c
75491@@ -547,6 +547,7 @@ static int rfcomm_sock_getname(struct socket *sock, struct sockaddr *addr, int *
75492
75493 BT_DBG("sock %p, sk %p", sock, sk);
75494
75495+ memset(sa, 0, sizeof(*sa));
75496 sa->rc_family = AF_BLUETOOTH;
75497 sa->rc_channel = rfcomm_pi(sk)->channel;
75498 if (peer)
75499@@ -841,6 +842,7 @@ static int rfcomm_sock_getsockopt(struct socket *sock, int level, int optname, c
75500 }
75501
75502 sec.level = rfcomm_pi(sk)->sec_level;
75503+ sec.key_size = 0;
75504
75505 len = min_t(unsigned int, len, sizeof(sec));
75506 if (copy_to_user(optval, (char *) &sec, len))
75507diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
75508index d1820ff..4f8c8f6 100644
75509--- a/net/bluetooth/rfcomm/tty.c
75510+++ b/net/bluetooth/rfcomm/tty.c
75511@@ -314,7 +314,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
75512 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
75513
75514 spin_lock_irqsave(&dev->port.lock, flags);
75515- if (dev->port.count > 0) {
75516+ if (atomic_read(&dev->port.count) > 0) {
75517 spin_unlock_irqrestore(&dev->port.lock, flags);
75518 return;
75519 }
75520@@ -461,7 +461,7 @@ static int rfcomm_get_dev_list(void __user *arg)
75521
75522 size = sizeof(*dl) + dev_num * sizeof(*di);
75523
75524- dl = kmalloc(size, GFP_KERNEL);
75525+ dl = kzalloc(size, GFP_KERNEL);
75526 if (!dl)
75527 return -ENOMEM;
75528
75529@@ -669,10 +669,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
75530 return -ENODEV;
75531
75532 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
75533- dev->channel, dev->port.count);
75534+ dev->channel, atomic_read(&dev->port.count));
75535
75536 spin_lock_irqsave(&dev->port.lock, flags);
75537- if (++dev->port.count > 1) {
75538+ if (atomic_inc_return(&dev->port.count) > 1) {
75539 spin_unlock_irqrestore(&dev->port.lock, flags);
75540 return 0;
75541 }
75542@@ -737,10 +737,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
75543 return;
75544
75545 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
75546- dev->port.count);
75547+ atomic_read(&dev->port.count));
75548
75549 spin_lock_irqsave(&dev->port.lock, flags);
75550- if (!--dev->port.count) {
75551+ if (!atomic_dec_return(&dev->port.count)) {
75552 spin_unlock_irqrestore(&dev->port.lock, flags);
75553 if (dev->tty_dev->parent)
75554 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
75555diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
75556index 5fe2ff3..10968b5 100644
75557--- a/net/bridge/netfilter/ebtables.c
75558+++ b/net/bridge/netfilter/ebtables.c
75559@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
75560 tmp.valid_hooks = t->table->valid_hooks;
75561 }
75562 mutex_unlock(&ebt_mutex);
75563- if (copy_to_user(user, &tmp, *len) != 0){
75564+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
75565 BUGPRINT("c2u Didn't work\n");
75566 ret = -EFAULT;
75567 break;
75568diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
75569index 047cd0e..461fd28 100644
75570--- a/net/caif/cfctrl.c
75571+++ b/net/caif/cfctrl.c
75572@@ -10,6 +10,7 @@
75573 #include <linux/spinlock.h>
75574 #include <linux/slab.h>
75575 #include <linux/pkt_sched.h>
75576+#include <linux/sched.h>
75577 #include <net/caif/caif_layer.h>
75578 #include <net/caif/cfpkt.h>
75579 #include <net/caif/cfctrl.h>
75580@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
75581 memset(&dev_info, 0, sizeof(dev_info));
75582 dev_info.id = 0xff;
75583 cfsrvl_init(&this->serv, 0, &dev_info, false);
75584- atomic_set(&this->req_seq_no, 1);
75585- atomic_set(&this->rsp_seq_no, 1);
75586+ atomic_set_unchecked(&this->req_seq_no, 1);
75587+ atomic_set_unchecked(&this->rsp_seq_no, 1);
75588 this->serv.layer.receive = cfctrl_recv;
75589 sprintf(this->serv.layer.name, "ctrl");
75590 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
75591@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
75592 struct cfctrl_request_info *req)
75593 {
75594 spin_lock_bh(&ctrl->info_list_lock);
75595- atomic_inc(&ctrl->req_seq_no);
75596- req->sequence_no = atomic_read(&ctrl->req_seq_no);
75597+ atomic_inc_unchecked(&ctrl->req_seq_no);
75598+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
75599 list_add_tail(&req->list, &ctrl->list);
75600 spin_unlock_bh(&ctrl->info_list_lock);
75601 }
75602@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
75603 if (p != first)
75604 pr_warn("Requests are not received in order\n");
75605
75606- atomic_set(&ctrl->rsp_seq_no,
75607+ atomic_set_unchecked(&ctrl->rsp_seq_no,
75608 p->sequence_no);
75609 list_del(&p->list);
75610 goto out;
75611diff --git a/net/caif/chnl_net.c b/net/caif/chnl_net.c
75612index 69771c0..e597733 100644
75613--- a/net/caif/chnl_net.c
75614+++ b/net/caif/chnl_net.c
75615@@ -94,6 +94,10 @@ static int chnl_recv_cb(struct cflayer *layr, struct cfpkt *pkt)
75616
75617 /* check the version of IP */
75618 ip_version = skb_header_pointer(skb, 0, 1, &buf);
75619+ if (!ip_version) {
75620+ kfree_skb(skb);
75621+ return -EINVAL;
75622+ }
75623
75624 switch (*ip_version >> 4) {
75625 case 4:
75626diff --git a/net/can/gw.c b/net/can/gw.c
75627index b41acf2..3affb3a 100644
75628--- a/net/can/gw.c
75629+++ b/net/can/gw.c
75630@@ -96,7 +96,7 @@ struct cf_mod {
75631 struct {
75632 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
75633 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
75634- } csumfunc;
75635+ } __no_const csumfunc;
75636 };
75637
75638
75639diff --git a/net/compat.c b/net/compat.c
75640index 74ed1d7..62f7ea6 100644
75641--- a/net/compat.c
75642+++ b/net/compat.c
75643@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
75644 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
75645 __get_user(kmsg->msg_flags, &umsg->msg_flags))
75646 return -EFAULT;
75647- kmsg->msg_name = compat_ptr(tmp1);
75648- kmsg->msg_iov = compat_ptr(tmp2);
75649- kmsg->msg_control = compat_ptr(tmp3);
75650+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
75651+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
75652+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
75653 return 0;
75654 }
75655
75656@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75657
75658 if (kern_msg->msg_namelen) {
75659 if (mode == VERIFY_READ) {
75660- int err = move_addr_to_kernel(kern_msg->msg_name,
75661+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
75662 kern_msg->msg_namelen,
75663 kern_address);
75664 if (err < 0)
75665@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75666 kern_msg->msg_name = NULL;
75667
75668 tot_len = iov_from_user_compat_to_kern(kern_iov,
75669- (struct compat_iovec __user *)kern_msg->msg_iov,
75670+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
75671 kern_msg->msg_iovlen);
75672 if (tot_len >= 0)
75673 kern_msg->msg_iov = kern_iov;
75674@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
75675
75676 #define CMSG_COMPAT_FIRSTHDR(msg) \
75677 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
75678- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
75679+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
75680 (struct compat_cmsghdr __user *)NULL)
75681
75682 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
75683 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
75684 (ucmlen) <= (unsigned long) \
75685 ((mhdr)->msg_controllen - \
75686- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
75687+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
75688
75689 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
75690 struct compat_cmsghdr __user *cmsg, int cmsg_len)
75691 {
75692 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
75693- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
75694+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
75695 msg->msg_controllen)
75696 return NULL;
75697 return (struct compat_cmsghdr __user *)ptr;
75698@@ -219,7 +219,7 @@ Efault:
75699
75700 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
75701 {
75702- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
75703+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
75704 struct compat_cmsghdr cmhdr;
75705 struct compat_timeval ctv;
75706 struct compat_timespec cts[3];
75707@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
75708
75709 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
75710 {
75711- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
75712+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
75713 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
75714 int fdnum = scm->fp->count;
75715 struct file **fp = scm->fp->fp;
75716@@ -364,7 +364,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
75717 return -EFAULT;
75718 old_fs = get_fs();
75719 set_fs(KERNEL_DS);
75720- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
75721+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
75722 set_fs(old_fs);
75723
75724 return err;
75725@@ -425,7 +425,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
75726 len = sizeof(ktime);
75727 old_fs = get_fs();
75728 set_fs(KERNEL_DS);
75729- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
75730+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
75731 set_fs(old_fs);
75732
75733 if (!err) {
75734@@ -568,7 +568,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75735 case MCAST_JOIN_GROUP:
75736 case MCAST_LEAVE_GROUP:
75737 {
75738- struct compat_group_req __user *gr32 = (void *)optval;
75739+ struct compat_group_req __user *gr32 = (void __user *)optval;
75740 struct group_req __user *kgr =
75741 compat_alloc_user_space(sizeof(struct group_req));
75742 u32 interface;
75743@@ -589,7 +589,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75744 case MCAST_BLOCK_SOURCE:
75745 case MCAST_UNBLOCK_SOURCE:
75746 {
75747- struct compat_group_source_req __user *gsr32 = (void *)optval;
75748+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
75749 struct group_source_req __user *kgsr = compat_alloc_user_space(
75750 sizeof(struct group_source_req));
75751 u32 interface;
75752@@ -610,7 +610,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75753 }
75754 case MCAST_MSFILTER:
75755 {
75756- struct compat_group_filter __user *gf32 = (void *)optval;
75757+ struct compat_group_filter __user *gf32 = (void __user *)optval;
75758 struct group_filter __user *kgf;
75759 u32 interface, fmode, numsrc;
75760
75761@@ -648,7 +648,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
75762 char __user *optval, int __user *optlen,
75763 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
75764 {
75765- struct compat_group_filter __user *gf32 = (void *)optval;
75766+ struct compat_group_filter __user *gf32 = (void __user *)optval;
75767 struct group_filter __user *kgf;
75768 int __user *koptlen;
75769 u32 interface, fmode, numsrc;
75770diff --git a/net/core/datagram.c b/net/core/datagram.c
75771index ae6acf6..d5c8f66 100644
75772--- a/net/core/datagram.c
75773+++ b/net/core/datagram.c
75774@@ -290,7 +290,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
75775 }
75776
75777 kfree_skb(skb);
75778- atomic_inc(&sk->sk_drops);
75779+ atomic_inc_unchecked(&sk->sk_drops);
75780 sk_mem_reclaim_partial(sk);
75781
75782 return err;
75783diff --git a/net/core/dev.c b/net/core/dev.c
75784index a000840..566cee1 100644
75785--- a/net/core/dev.c
75786+++ b/net/core/dev.c
75787@@ -1135,9 +1135,13 @@ void dev_load(struct net *net, const char *name)
75788 if (no_module && capable(CAP_NET_ADMIN))
75789 no_module = request_module("netdev-%s", name);
75790 if (no_module && capable(CAP_SYS_MODULE)) {
75791+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75792+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
75793+#else
75794 if (!request_module("%s", name))
75795 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
75796 name);
75797+#endif
75798 }
75799 }
75800 EXPORT_SYMBOL(dev_load);
75801@@ -1602,7 +1606,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75802 {
75803 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
75804 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
75805- atomic_long_inc(&dev->rx_dropped);
75806+ atomic_long_inc_unchecked(&dev->rx_dropped);
75807 kfree_skb(skb);
75808 return NET_RX_DROP;
75809 }
75810@@ -1612,7 +1616,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75811 nf_reset(skb);
75812
75813 if (unlikely(!is_skb_forwardable(dev, skb))) {
75814- atomic_long_inc(&dev->rx_dropped);
75815+ atomic_long_inc_unchecked(&dev->rx_dropped);
75816 kfree_skb(skb);
75817 return NET_RX_DROP;
75818 }
75819@@ -2041,7 +2045,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
75820
75821 struct dev_gso_cb {
75822 void (*destructor)(struct sk_buff *skb);
75823-};
75824+} __no_const;
75825
75826 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
75827
75828@@ -2876,7 +2880,7 @@ enqueue:
75829
75830 local_irq_restore(flags);
75831
75832- atomic_long_inc(&skb->dev->rx_dropped);
75833+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75834 kfree_skb(skb);
75835 return NET_RX_DROP;
75836 }
75837@@ -2948,7 +2952,7 @@ int netif_rx_ni(struct sk_buff *skb)
75838 }
75839 EXPORT_SYMBOL(netif_rx_ni);
75840
75841-static void net_tx_action(struct softirq_action *h)
75842+static void net_tx_action(void)
75843 {
75844 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75845
75846@@ -3235,7 +3239,7 @@ ncls:
75847 if (pt_prev) {
75848 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
75849 } else {
75850- atomic_long_inc(&skb->dev->rx_dropped);
75851+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75852 kfree_skb(skb);
75853 /* Jamal, now you will not able to escape explaining
75854 * me how you were going to use this. :-)
75855@@ -3800,7 +3804,7 @@ void netif_napi_del(struct napi_struct *napi)
75856 }
75857 EXPORT_SYMBOL(netif_napi_del);
75858
75859-static void net_rx_action(struct softirq_action *h)
75860+static void net_rx_action(void)
75861 {
75862 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75863 unsigned long time_limit = jiffies + 2;
75864@@ -4270,8 +4274,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
75865 else
75866 seq_printf(seq, "%04x", ntohs(pt->type));
75867
75868+#ifdef CONFIG_GRKERNSEC_HIDESYM
75869+ seq_printf(seq, " %-8s %p\n",
75870+ pt->dev ? pt->dev->name : "", NULL);
75871+#else
75872 seq_printf(seq, " %-8s %pF\n",
75873 pt->dev ? pt->dev->name : "", pt->func);
75874+#endif
75875 }
75876
75877 return 0;
75878@@ -5823,7 +5832,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
75879 } else {
75880 netdev_stats_to_stats64(storage, &dev->stats);
75881 }
75882- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
75883+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
75884 return storage;
75885 }
75886 EXPORT_SYMBOL(dev_get_stats);
75887diff --git a/net/core/flow.c b/net/core/flow.c
75888index e318c7e..168b1d0 100644
75889--- a/net/core/flow.c
75890+++ b/net/core/flow.c
75891@@ -61,7 +61,7 @@ struct flow_cache {
75892 struct timer_list rnd_timer;
75893 };
75894
75895-atomic_t flow_cache_genid = ATOMIC_INIT(0);
75896+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
75897 EXPORT_SYMBOL(flow_cache_genid);
75898 static struct flow_cache flow_cache_global;
75899 static struct kmem_cache *flow_cachep __read_mostly;
75900@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
75901
75902 static int flow_entry_valid(struct flow_cache_entry *fle)
75903 {
75904- if (atomic_read(&flow_cache_genid) != fle->genid)
75905+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
75906 return 0;
75907 if (fle->object && !fle->object->ops->check(fle->object))
75908 return 0;
75909@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
75910 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
75911 fcp->hash_count++;
75912 }
75913- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
75914+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
75915 flo = fle->object;
75916 if (!flo)
75917 goto ret_object;
75918@@ -280,7 +280,7 @@ nocache:
75919 }
75920 flo = resolver(net, key, family, dir, flo, ctx);
75921 if (fle) {
75922- fle->genid = atomic_read(&flow_cache_genid);
75923+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
75924 if (!IS_ERR(flo))
75925 fle->object = flo;
75926 else
75927diff --git a/net/core/iovec.c b/net/core/iovec.c
75928index 7e7aeb0..2a998cb 100644
75929--- a/net/core/iovec.c
75930+++ b/net/core/iovec.c
75931@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
75932 if (m->msg_namelen) {
75933 if (mode == VERIFY_READ) {
75934 void __user *namep;
75935- namep = (void __user __force *) m->msg_name;
75936+ namep = (void __force_user *) m->msg_name;
75937 err = move_addr_to_kernel(namep, m->msg_namelen,
75938 address);
75939 if (err < 0)
75940@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
75941 }
75942
75943 size = m->msg_iovlen * sizeof(struct iovec);
75944- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
75945+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
75946 return -EFAULT;
75947
75948 m->msg_iov = iov;
75949diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
75950index 6c50ac0..6b4c038 100644
75951--- a/net/core/rtnetlink.c
75952+++ b/net/core/rtnetlink.c
75953@@ -58,7 +58,7 @@ struct rtnl_link {
75954 rtnl_doit_func doit;
75955 rtnl_dumpit_func dumpit;
75956 rtnl_calcit_func calcit;
75957-};
75958+} __no_const;
75959
75960 static DEFINE_MUTEX(rtnl_mutex);
75961
75962diff --git a/net/core/scm.c b/net/core/scm.c
75963index 611c5ef..88f6d6d 100644
75964--- a/net/core/scm.c
75965+++ b/net/core/scm.c
75966@@ -219,7 +219,7 @@ EXPORT_SYMBOL(__scm_send);
75967 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75968 {
75969 struct cmsghdr __user *cm
75970- = (__force struct cmsghdr __user *)msg->msg_control;
75971+ = (struct cmsghdr __force_user *)msg->msg_control;
75972 struct cmsghdr cmhdr;
75973 int cmlen = CMSG_LEN(len);
75974 int err;
75975@@ -242,7 +242,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75976 err = -EFAULT;
75977 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
75978 goto out;
75979- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
75980+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
75981 goto out;
75982 cmlen = CMSG_SPACE(len);
75983 if (msg->msg_controllen < cmlen)
75984@@ -258,7 +258,7 @@ EXPORT_SYMBOL(put_cmsg);
75985 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75986 {
75987 struct cmsghdr __user *cm
75988- = (__force struct cmsghdr __user*)msg->msg_control;
75989+ = (struct cmsghdr __force_user *)msg->msg_control;
75990
75991 int fdmax = 0;
75992 int fdnum = scm->fp->count;
75993@@ -278,7 +278,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75994 if (fdnum < fdmax)
75995 fdmax = fdnum;
75996
75997- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
75998+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
75999 i++, cmfptr++)
76000 {
76001 int new_fd;
76002diff --git a/net/core/sock.c b/net/core/sock.c
76003index 9e5b71f..66dec30 100644
76004--- a/net/core/sock.c
76005+++ b/net/core/sock.c
76006@@ -344,7 +344,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76007 struct sk_buff_head *list = &sk->sk_receive_queue;
76008
76009 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
76010- atomic_inc(&sk->sk_drops);
76011+ atomic_inc_unchecked(&sk->sk_drops);
76012 trace_sock_rcvqueue_full(sk, skb);
76013 return -ENOMEM;
76014 }
76015@@ -354,7 +354,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76016 return err;
76017
76018 if (!sk_rmem_schedule(sk, skb->truesize)) {
76019- atomic_inc(&sk->sk_drops);
76020+ atomic_inc_unchecked(&sk->sk_drops);
76021 return -ENOBUFS;
76022 }
76023
76024@@ -374,7 +374,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76025 skb_dst_force(skb);
76026
76027 spin_lock_irqsave(&list->lock, flags);
76028- skb->dropcount = atomic_read(&sk->sk_drops);
76029+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
76030 __skb_queue_tail(list, skb);
76031 spin_unlock_irqrestore(&list->lock, flags);
76032
76033@@ -394,7 +394,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
76034 skb->dev = NULL;
76035
76036 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
76037- atomic_inc(&sk->sk_drops);
76038+ atomic_inc_unchecked(&sk->sk_drops);
76039 goto discard_and_relse;
76040 }
76041 if (nested)
76042@@ -412,7 +412,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
76043 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
76044 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
76045 bh_unlock_sock(sk);
76046- atomic_inc(&sk->sk_drops);
76047+ atomic_inc_unchecked(&sk->sk_drops);
76048 goto discard_and_relse;
76049 }
76050
76051@@ -976,7 +976,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76052 if (len > sizeof(peercred))
76053 len = sizeof(peercred);
76054 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
76055- if (copy_to_user(optval, &peercred, len))
76056+ if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
76057 return -EFAULT;
76058 goto lenout;
76059 }
76060@@ -989,7 +989,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76061 return -ENOTCONN;
76062 if (lv < len)
76063 return -EINVAL;
76064- if (copy_to_user(optval, address, len))
76065+ if (len > sizeof(address) || copy_to_user(optval, address, len))
76066 return -EFAULT;
76067 goto lenout;
76068 }
76069@@ -1035,7 +1035,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76070
76071 if (len > lv)
76072 len = lv;
76073- if (copy_to_user(optval, &v, len))
76074+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
76075 return -EFAULT;
76076 lenout:
76077 if (put_user(len, optlen))
76078@@ -2124,7 +2124,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
76079 */
76080 smp_wmb();
76081 atomic_set(&sk->sk_refcnt, 1);
76082- atomic_set(&sk->sk_drops, 0);
76083+ atomic_set_unchecked(&sk->sk_drops, 0);
76084 }
76085 EXPORT_SYMBOL(sock_init_data);
76086
76087diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
76088index 5fd1467..8b70900 100644
76089--- a/net/core/sock_diag.c
76090+++ b/net/core/sock_diag.c
76091@@ -16,20 +16,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
76092
76093 int sock_diag_check_cookie(void *sk, __u32 *cookie)
76094 {
76095+#ifndef CONFIG_GRKERNSEC_HIDESYM
76096 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
76097 cookie[1] != INET_DIAG_NOCOOKIE) &&
76098 ((u32)(unsigned long)sk != cookie[0] ||
76099 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
76100 return -ESTALE;
76101 else
76102+#endif
76103 return 0;
76104 }
76105 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
76106
76107 void sock_diag_save_cookie(void *sk, __u32 *cookie)
76108 {
76109+#ifdef CONFIG_GRKERNSEC_HIDESYM
76110+ cookie[0] = 0;
76111+ cookie[1] = 0;
76112+#else
76113 cookie[0] = (u32)(unsigned long)sk;
76114 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
76115+#endif
76116 }
76117 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
76118
76119diff --git a/net/dccp/ccid.h b/net/dccp/ccid.h
76120index 75c3582..fb85d37 100644
76121--- a/net/dccp/ccid.h
76122+++ b/net/dccp/ccid.h
76123@@ -246,7 +246,7 @@ static inline int ccid_hc_rx_getsockopt(struct ccid *ccid, struct sock *sk,
76124 u32 __user *optval, int __user *optlen)
76125 {
76126 int rc = -ENOPROTOOPT;
76127- if (ccid->ccid_ops->ccid_hc_rx_getsockopt != NULL)
76128+ if (ccid != NULL && ccid->ccid_ops->ccid_hc_rx_getsockopt != NULL)
76129 rc = ccid->ccid_ops->ccid_hc_rx_getsockopt(sk, optname, len,
76130 optval, optlen);
76131 return rc;
76132@@ -257,7 +257,7 @@ static inline int ccid_hc_tx_getsockopt(struct ccid *ccid, struct sock *sk,
76133 u32 __user *optval, int __user *optlen)
76134 {
76135 int rc = -ENOPROTOOPT;
76136- if (ccid->ccid_ops->ccid_hc_tx_getsockopt != NULL)
76137+ if (ccid != NULL && ccid->ccid_ops->ccid_hc_tx_getsockopt != NULL)
76138 rc = ccid->ccid_ops->ccid_hc_tx_getsockopt(sk, optname, len,
76139 optval, optlen);
76140 return rc;
76141diff --git a/net/dccp/ccids/ccid3.c b/net/dccp/ccids/ccid3.c
76142index 8c67bed..ce0d140 100644
76143--- a/net/dccp/ccids/ccid3.c
76144+++ b/net/dccp/ccids/ccid3.c
76145@@ -531,6 +531,7 @@ static int ccid3_hc_tx_getsockopt(struct sock *sk, const int optname, int len,
76146 case DCCP_SOCKOPT_CCID_TX_INFO:
76147 if (len < sizeof(tfrc))
76148 return -EINVAL;
76149+ memset(&tfrc, 0, sizeof(tfrc));
76150 tfrc.tfrctx_x = hc->tx_x;
76151 tfrc.tfrctx_x_recv = hc->tx_x_recv;
76152 tfrc.tfrctx_x_calc = hc->tx_x_calc;
76153diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
76154index a55eecc..dd8428c 100644
76155--- a/net/decnet/sysctl_net_decnet.c
76156+++ b/net/decnet/sysctl_net_decnet.c
76157@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
76158
76159 if (len > *lenp) len = *lenp;
76160
76161- if (copy_to_user(buffer, addr, len))
76162+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
76163 return -EFAULT;
76164
76165 *lenp = len;
76166@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
76167
76168 if (len > *lenp) len = *lenp;
76169
76170- if (copy_to_user(buffer, devname, len))
76171+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
76172 return -EFAULT;
76173
76174 *lenp = len;
76175diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
76176index 3854411..2201a94 100644
76177--- a/net/ipv4/fib_frontend.c
76178+++ b/net/ipv4/fib_frontend.c
76179@@ -969,12 +969,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
76180 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76181 fib_sync_up(dev);
76182 #endif
76183- atomic_inc(&net->ipv4.dev_addr_genid);
76184+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76185 rt_cache_flush(dev_net(dev), -1);
76186 break;
76187 case NETDEV_DOWN:
76188 fib_del_ifaddr(ifa, NULL);
76189- atomic_inc(&net->ipv4.dev_addr_genid);
76190+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76191 if (ifa->ifa_dev->ifa_list == NULL) {
76192 /* Last address was deleted from this interface.
76193 * Disable IP.
76194@@ -1010,7 +1010,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
76195 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76196 fib_sync_up(dev);
76197 #endif
76198- atomic_inc(&net->ipv4.dev_addr_genid);
76199+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76200 rt_cache_flush(dev_net(dev), -1);
76201 break;
76202 case NETDEV_DOWN:
76203diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
76204index e5b7182..570a90e 100644
76205--- a/net/ipv4/fib_semantics.c
76206+++ b/net/ipv4/fib_semantics.c
76207@@ -698,7 +698,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
76208 nh->nh_saddr = inet_select_addr(nh->nh_dev,
76209 nh->nh_gw,
76210 nh->nh_parent->fib_scope);
76211- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
76212+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
76213
76214 return nh->nh_saddr;
76215 }
76216diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
76217index 7880af9..70f92a3 100644
76218--- a/net/ipv4/inet_hashtables.c
76219+++ b/net/ipv4/inet_hashtables.c
76220@@ -18,12 +18,15 @@
76221 #include <linux/sched.h>
76222 #include <linux/slab.h>
76223 #include <linux/wait.h>
76224+#include <linux/security.h>
76225
76226 #include <net/inet_connection_sock.h>
76227 #include <net/inet_hashtables.h>
76228 #include <net/secure_seq.h>
76229 #include <net/ip.h>
76230
76231+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
76232+
76233 /*
76234 * Allocate and initialize a new local port bind bucket.
76235 * The bindhash mutex for snum's hash chain must be held here.
76236@@ -530,6 +533,8 @@ ok:
76237 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
76238 spin_unlock(&head->lock);
76239
76240+ gr_update_task_in_ip_table(current, inet_sk(sk));
76241+
76242 if (tw) {
76243 inet_twsk_deschedule(tw, death_row);
76244 while (twrefcnt) {
76245diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
76246index dfba343..c827d50 100644
76247--- a/net/ipv4/inetpeer.c
76248+++ b/net/ipv4/inetpeer.c
76249@@ -487,8 +487,8 @@ relookup:
76250 if (p) {
76251 p->daddr = *daddr;
76252 atomic_set(&p->refcnt, 1);
76253- atomic_set(&p->rid, 0);
76254- atomic_set(&p->ip_id_count,
76255+ atomic_set_unchecked(&p->rid, 0);
76256+ atomic_set_unchecked(&p->ip_id_count,
76257 (daddr->family == AF_INET) ?
76258 secure_ip_id(daddr->addr.a4) :
76259 secure_ipv6_id(daddr->addr.a6));
76260diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
76261index 9dbd3dd..0c59fb2 100644
76262--- a/net/ipv4/ip_fragment.c
76263+++ b/net/ipv4/ip_fragment.c
76264@@ -318,7 +318,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
76265 return 0;
76266
76267 start = qp->rid;
76268- end = atomic_inc_return(&peer->rid);
76269+ end = atomic_inc_return_unchecked(&peer->rid);
76270 qp->rid = end;
76271
76272 rc = qp->q.fragments && (end - start) > max;
76273diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
76274index 0d11f23..2bb3f64 100644
76275--- a/net/ipv4/ip_sockglue.c
76276+++ b/net/ipv4/ip_sockglue.c
76277@@ -1142,7 +1142,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
76278 len = min_t(unsigned int, len, opt->optlen);
76279 if (put_user(len, optlen))
76280 return -EFAULT;
76281- if (copy_to_user(optval, opt->__data, len))
76282+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
76283+ copy_to_user(optval, opt->__data, len))
76284 return -EFAULT;
76285 return 0;
76286 }
76287@@ -1273,7 +1274,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
76288 if (sk->sk_type != SOCK_STREAM)
76289 return -ENOPROTOOPT;
76290
76291- msg.msg_control = optval;
76292+ msg.msg_control = (void __force_kernel *)optval;
76293 msg.msg_controllen = len;
76294 msg.msg_flags = flags;
76295
76296diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
76297index 67e8a6b..386764d 100644
76298--- a/net/ipv4/ipconfig.c
76299+++ b/net/ipv4/ipconfig.c
76300@@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
76301
76302 mm_segment_t oldfs = get_fs();
76303 set_fs(get_ds());
76304- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
76305+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
76306 set_fs(oldfs);
76307 return res;
76308 }
76309@@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
76310
76311 mm_segment_t oldfs = get_fs();
76312 set_fs(get_ds());
76313- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
76314+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
76315 set_fs(oldfs);
76316 return res;
76317 }
76318@@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
76319
76320 mm_segment_t oldfs = get_fs();
76321 set_fs(get_ds());
76322- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
76323+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
76324 set_fs(oldfs);
76325 return res;
76326 }
76327diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
76328index 2c00e8b..45b3bdd 100644
76329--- a/net/ipv4/ping.c
76330+++ b/net/ipv4/ping.c
76331@@ -845,7 +845,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
76332 sk_rmem_alloc_get(sp),
76333 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76334 atomic_read(&sp->sk_refcnt), sp,
76335- atomic_read(&sp->sk_drops), len);
76336+ atomic_read_unchecked(&sp->sk_drops), len);
76337 }
76338
76339 static int ping_seq_show(struct seq_file *seq, void *v)
76340diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
76341index 4032b81..625143c 100644
76342--- a/net/ipv4/raw.c
76343+++ b/net/ipv4/raw.c
76344@@ -304,7 +304,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
76345 int raw_rcv(struct sock *sk, struct sk_buff *skb)
76346 {
76347 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
76348- atomic_inc(&sk->sk_drops);
76349+ atomic_inc_unchecked(&sk->sk_drops);
76350 kfree_skb(skb);
76351 return NET_RX_DROP;
76352 }
76353@@ -740,16 +740,20 @@ static int raw_init(struct sock *sk)
76354
76355 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
76356 {
76357+ struct icmp_filter filter;
76358+
76359 if (optlen > sizeof(struct icmp_filter))
76360 optlen = sizeof(struct icmp_filter);
76361- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
76362+ if (copy_from_user(&filter, optval, optlen))
76363 return -EFAULT;
76364+ raw_sk(sk)->filter = filter;
76365 return 0;
76366 }
76367
76368 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
76369 {
76370 int len, ret = -EFAULT;
76371+ struct icmp_filter filter;
76372
76373 if (get_user(len, optlen))
76374 goto out;
76375@@ -759,8 +763,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
76376 if (len > sizeof(struct icmp_filter))
76377 len = sizeof(struct icmp_filter);
76378 ret = -EFAULT;
76379- if (put_user(len, optlen) ||
76380- copy_to_user(optval, &raw_sk(sk)->filter, len))
76381+ filter = raw_sk(sk)->filter;
76382+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
76383 goto out;
76384 ret = 0;
76385 out: return ret;
76386@@ -988,7 +992,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76387 sk_wmem_alloc_get(sp),
76388 sk_rmem_alloc_get(sp),
76389 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76390- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76391+ atomic_read(&sp->sk_refcnt),
76392+#ifdef CONFIG_GRKERNSEC_HIDESYM
76393+ NULL,
76394+#else
76395+ sp,
76396+#endif
76397+ atomic_read_unchecked(&sp->sk_drops));
76398 }
76399
76400 static int raw_seq_show(struct seq_file *seq, void *v)
76401diff --git a/net/ipv4/route.c b/net/ipv4/route.c
76402index 98b30d0..cfa3cf7 100644
76403--- a/net/ipv4/route.c
76404+++ b/net/ipv4/route.c
76405@@ -313,7 +313,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
76406
76407 static inline int rt_genid(struct net *net)
76408 {
76409- return atomic_read(&net->ipv4.rt_genid);
76410+ return atomic_read_unchecked(&net->ipv4.rt_genid);
76411 }
76412
76413 #ifdef CONFIG_PROC_FS
76414@@ -937,7 +937,7 @@ static void rt_cache_invalidate(struct net *net)
76415 unsigned char shuffle;
76416
76417 get_random_bytes(&shuffle, sizeof(shuffle));
76418- atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
76419+ atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
76420 inetpeer_invalidate_tree(AF_INET);
76421 }
76422
76423@@ -3011,7 +3011,7 @@ static int rt_fill_info(struct net *net,
76424 error = rt->dst.error;
76425 if (peer) {
76426 inet_peer_refcheck(rt->peer);
76427- id = atomic_read(&peer->ip_id_count) & 0xffff;
76428+ id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
76429 if (peer->tcp_ts_stamp) {
76430 ts = peer->tcp_ts;
76431 tsage = get_seconds() - peer->tcp_ts_stamp;
76432diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
76433index c8d28c4..e40f75a 100644
76434--- a/net/ipv4/tcp_ipv4.c
76435+++ b/net/ipv4/tcp_ipv4.c
76436@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
76437 EXPORT_SYMBOL(sysctl_tcp_low_latency);
76438
76439
76440+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76441+extern int grsec_enable_blackhole;
76442+#endif
76443+
76444 #ifdef CONFIG_TCP_MD5SIG
76445 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
76446 __be32 daddr, __be32 saddr, const struct tcphdr *th);
76447@@ -1656,6 +1660,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
76448 return 0;
76449
76450 reset:
76451+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76452+ if (!grsec_enable_blackhole)
76453+#endif
76454 tcp_v4_send_reset(rsk, skb);
76455 discard:
76456 kfree_skb(skb);
76457@@ -1718,12 +1725,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
76458 TCP_SKB_CB(skb)->sacked = 0;
76459
76460 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76461- if (!sk)
76462+ if (!sk) {
76463+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76464+ ret = 1;
76465+#endif
76466 goto no_tcp_socket;
76467-
76468+ }
76469 process:
76470- if (sk->sk_state == TCP_TIME_WAIT)
76471+ if (sk->sk_state == TCP_TIME_WAIT) {
76472+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76473+ ret = 2;
76474+#endif
76475 goto do_time_wait;
76476+ }
76477
76478 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
76479 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76480@@ -1774,6 +1788,10 @@ no_tcp_socket:
76481 bad_packet:
76482 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76483 } else {
76484+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76485+ if (!grsec_enable_blackhole || (ret == 1 &&
76486+ (skb->dev->flags & IFF_LOOPBACK)))
76487+#endif
76488 tcp_v4_send_reset(NULL, skb);
76489 }
76490
76491@@ -2386,7 +2404,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
76492 0, /* non standard timer */
76493 0, /* open_requests have no inode */
76494 atomic_read(&sk->sk_refcnt),
76495+#ifdef CONFIG_GRKERNSEC_HIDESYM
76496+ NULL,
76497+#else
76498 req,
76499+#endif
76500 len);
76501 }
76502
76503@@ -2436,7 +2458,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
76504 sock_i_uid(sk),
76505 icsk->icsk_probes_out,
76506 sock_i_ino(sk),
76507- atomic_read(&sk->sk_refcnt), sk,
76508+ atomic_read(&sk->sk_refcnt),
76509+#ifdef CONFIG_GRKERNSEC_HIDESYM
76510+ NULL,
76511+#else
76512+ sk,
76513+#endif
76514 jiffies_to_clock_t(icsk->icsk_rto),
76515 jiffies_to_clock_t(icsk->icsk_ack.ato),
76516 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
76517@@ -2464,7 +2491,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
76518 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
76519 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
76520 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76521- atomic_read(&tw->tw_refcnt), tw, len);
76522+ atomic_read(&tw->tw_refcnt),
76523+#ifdef CONFIG_GRKERNSEC_HIDESYM
76524+ NULL,
76525+#else
76526+ tw,
76527+#endif
76528+ len);
76529 }
76530
76531 #define TMPSZ 150
76532diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
76533index b85d9fe..4b0eed9 100644
76534--- a/net/ipv4/tcp_minisocks.c
76535+++ b/net/ipv4/tcp_minisocks.c
76536@@ -27,6 +27,10 @@
76537 #include <net/inet_common.h>
76538 #include <net/xfrm.h>
76539
76540+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76541+extern int grsec_enable_blackhole;
76542+#endif
76543+
76544 int sysctl_tcp_syncookies __read_mostly = 1;
76545 EXPORT_SYMBOL(sysctl_tcp_syncookies);
76546
76547@@ -754,6 +758,10 @@ listen_overflow:
76548
76549 embryonic_reset:
76550 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
76551+
76552+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76553+ if (!grsec_enable_blackhole)
76554+#endif
76555 if (!(flg & TCP_FLAG_RST))
76556 req->rsk_ops->send_reset(sk, skb);
76557
76558diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
76559index 4526fe6..1a34e43 100644
76560--- a/net/ipv4/tcp_probe.c
76561+++ b/net/ipv4/tcp_probe.c
76562@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
76563 if (cnt + width >= len)
76564 break;
76565
76566- if (copy_to_user(buf + cnt, tbuf, width))
76567+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
76568 return -EFAULT;
76569 cnt += width;
76570 }
76571diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
76572index e911e6c..d0a9356 100644
76573--- a/net/ipv4/tcp_timer.c
76574+++ b/net/ipv4/tcp_timer.c
76575@@ -22,6 +22,10 @@
76576 #include <linux/gfp.h>
76577 #include <net/tcp.h>
76578
76579+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76580+extern int grsec_lastack_retries;
76581+#endif
76582+
76583 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
76584 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
76585 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
76586@@ -196,6 +200,13 @@ static int tcp_write_timeout(struct sock *sk)
76587 }
76588 }
76589
76590+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76591+ if ((sk->sk_state == TCP_LAST_ACK) &&
76592+ (grsec_lastack_retries > 0) &&
76593+ (grsec_lastack_retries < retry_until))
76594+ retry_until = grsec_lastack_retries;
76595+#endif
76596+
76597 if (retransmits_timed_out(sk, retry_until,
76598 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
76599 /* Has it gone just too far? */
76600diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
76601index eaca736..60488ae 100644
76602--- a/net/ipv4/udp.c
76603+++ b/net/ipv4/udp.c
76604@@ -87,6 +87,7 @@
76605 #include <linux/types.h>
76606 #include <linux/fcntl.h>
76607 #include <linux/module.h>
76608+#include <linux/security.h>
76609 #include <linux/socket.h>
76610 #include <linux/sockios.h>
76611 #include <linux/igmp.h>
76612@@ -110,6 +111,10 @@
76613 #include <linux/static_key.h>
76614 #include "udp_impl.h"
76615
76616+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76617+extern int grsec_enable_blackhole;
76618+#endif
76619+
76620 struct udp_table udp_table __read_mostly;
76621 EXPORT_SYMBOL(udp_table);
76622
76623@@ -568,6 +573,9 @@ found:
76624 return s;
76625 }
76626
76627+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
76628+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
76629+
76630 /*
76631 * This routine is called by the ICMP module when it gets some
76632 * sort of error condition. If err < 0 then the socket should
76633@@ -859,9 +867,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
76634 dport = usin->sin_port;
76635 if (dport == 0)
76636 return -EINVAL;
76637+
76638+ err = gr_search_udp_sendmsg(sk, usin);
76639+ if (err)
76640+ return err;
76641 } else {
76642 if (sk->sk_state != TCP_ESTABLISHED)
76643 return -EDESTADDRREQ;
76644+
76645+ err = gr_search_udp_sendmsg(sk, NULL);
76646+ if (err)
76647+ return err;
76648+
76649 daddr = inet->inet_daddr;
76650 dport = inet->inet_dport;
76651 /* Open fast path for connected socket.
76652@@ -1103,7 +1120,7 @@ static unsigned int first_packet_length(struct sock *sk)
76653 udp_lib_checksum_complete(skb)) {
76654 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76655 IS_UDPLITE(sk));
76656- atomic_inc(&sk->sk_drops);
76657+ atomic_inc_unchecked(&sk->sk_drops);
76658 __skb_unlink(skb, rcvq);
76659 __skb_queue_tail(&list_kill, skb);
76660 }
76661@@ -1189,6 +1206,10 @@ try_again:
76662 if (!skb)
76663 goto out;
76664
76665+ err = gr_search_udp_recvmsg(sk, skb);
76666+ if (err)
76667+ goto out_free;
76668+
76669 ulen = skb->len - sizeof(struct udphdr);
76670 copied = len;
76671 if (copied > ulen)
76672@@ -1498,7 +1519,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76673
76674 drop:
76675 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76676- atomic_inc(&sk->sk_drops);
76677+ atomic_inc_unchecked(&sk->sk_drops);
76678 kfree_skb(skb);
76679 return -1;
76680 }
76681@@ -1517,7 +1538,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76682 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
76683
76684 if (!skb1) {
76685- atomic_inc(&sk->sk_drops);
76686+ atomic_inc_unchecked(&sk->sk_drops);
76687 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
76688 IS_UDPLITE(sk));
76689 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76690@@ -1686,6 +1707,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76691 goto csum_error;
76692
76693 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
76694+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76695+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76696+#endif
76697 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
76698
76699 /*
76700@@ -2104,8 +2128,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
76701 sk_wmem_alloc_get(sp),
76702 sk_rmem_alloc_get(sp),
76703 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76704- atomic_read(&sp->sk_refcnt), sp,
76705- atomic_read(&sp->sk_drops), len);
76706+ atomic_read(&sp->sk_refcnt),
76707+#ifdef CONFIG_GRKERNSEC_HIDESYM
76708+ NULL,
76709+#else
76710+ sp,
76711+#endif
76712+ atomic_read_unchecked(&sp->sk_drops), len);
76713 }
76714
76715 int udp4_seq_show(struct seq_file *seq, void *v)
76716diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
76717index 8f6411c..5767579 100644
76718--- a/net/ipv6/addrconf.c
76719+++ b/net/ipv6/addrconf.c
76720@@ -2145,7 +2145,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
76721 p.iph.ihl = 5;
76722 p.iph.protocol = IPPROTO_IPV6;
76723 p.iph.ttl = 64;
76724- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
76725+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
76726
76727 if (ops->ndo_do_ioctl) {
76728 mm_segment_t oldfs = get_fs();
76729diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
76730index e6cee52..cf47476 100644
76731--- a/net/ipv6/inet6_connection_sock.c
76732+++ b/net/ipv6/inet6_connection_sock.c
76733@@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
76734 #ifdef CONFIG_XFRM
76735 {
76736 struct rt6_info *rt = (struct rt6_info *)dst;
76737- rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
76738+ rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
76739 }
76740 #endif
76741 }
76742@@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
76743 #ifdef CONFIG_XFRM
76744 if (dst) {
76745 struct rt6_info *rt = (struct rt6_info *)dst;
76746- if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
76747+ if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
76748 __sk_dst_reset(sk);
76749 dst = NULL;
76750 }
76751diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
76752index ba6d13d..6899122 100644
76753--- a/net/ipv6/ipv6_sockglue.c
76754+++ b/net/ipv6/ipv6_sockglue.c
76755@@ -989,7 +989,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
76756 if (sk->sk_type != SOCK_STREAM)
76757 return -ENOPROTOOPT;
76758
76759- msg.msg_control = optval;
76760+ msg.msg_control = (void __force_kernel *)optval;
76761 msg.msg_controllen = len;
76762 msg.msg_flags = flags;
76763
76764diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
76765index 93d6983..8e54c4d 100644
76766--- a/net/ipv6/raw.c
76767+++ b/net/ipv6/raw.c
76768@@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
76769 {
76770 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
76771 skb_checksum_complete(skb)) {
76772- atomic_inc(&sk->sk_drops);
76773+ atomic_inc_unchecked(&sk->sk_drops);
76774 kfree_skb(skb);
76775 return NET_RX_DROP;
76776 }
76777@@ -405,7 +405,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76778 struct raw6_sock *rp = raw6_sk(sk);
76779
76780 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
76781- atomic_inc(&sk->sk_drops);
76782+ atomic_inc_unchecked(&sk->sk_drops);
76783 kfree_skb(skb);
76784 return NET_RX_DROP;
76785 }
76786@@ -429,7 +429,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76787
76788 if (inet->hdrincl) {
76789 if (skb_checksum_complete(skb)) {
76790- atomic_inc(&sk->sk_drops);
76791+ atomic_inc_unchecked(&sk->sk_drops);
76792 kfree_skb(skb);
76793 return NET_RX_DROP;
76794 }
76795@@ -602,7 +602,7 @@ out:
76796 return err;
76797 }
76798
76799-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
76800+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
76801 struct flowi6 *fl6, struct dst_entry **dstp,
76802 unsigned int flags)
76803 {
76804@@ -914,12 +914,15 @@ do_confirm:
76805 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
76806 char __user *optval, int optlen)
76807 {
76808+ struct icmp6_filter filter;
76809+
76810 switch (optname) {
76811 case ICMPV6_FILTER:
76812 if (optlen > sizeof(struct icmp6_filter))
76813 optlen = sizeof(struct icmp6_filter);
76814- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
76815+ if (copy_from_user(&filter, optval, optlen))
76816 return -EFAULT;
76817+ raw6_sk(sk)->filter = filter;
76818 return 0;
76819 default:
76820 return -ENOPROTOOPT;
76821@@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76822 char __user *optval, int __user *optlen)
76823 {
76824 int len;
76825+ struct icmp6_filter filter;
76826
76827 switch (optname) {
76828 case ICMPV6_FILTER:
76829@@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76830 len = sizeof(struct icmp6_filter);
76831 if (put_user(len, optlen))
76832 return -EFAULT;
76833- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
76834+ filter = raw6_sk(sk)->filter;
76835+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
76836 return -EFAULT;
76837 return 0;
76838 default:
76839@@ -1250,7 +1255,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76840 0, 0L, 0,
76841 sock_i_uid(sp), 0,
76842 sock_i_ino(sp),
76843- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76844+ atomic_read(&sp->sk_refcnt),
76845+#ifdef CONFIG_GRKERNSEC_HIDESYM
76846+ NULL,
76847+#else
76848+ sp,
76849+#endif
76850+ atomic_read_unchecked(&sp->sk_drops));
76851 }
76852
76853 static int raw6_seq_show(struct seq_file *seq, void *v)
76854diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
76855index 9df64a5..39875da 100644
76856--- a/net/ipv6/tcp_ipv6.c
76857+++ b/net/ipv6/tcp_ipv6.c
76858@@ -94,6 +94,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
76859 }
76860 #endif
76861
76862+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76863+extern int grsec_enable_blackhole;
76864+#endif
76865+
76866 static void tcp_v6_hash(struct sock *sk)
76867 {
76868 if (sk->sk_state != TCP_CLOSE) {
76869@@ -1544,6 +1548,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
76870 return 0;
76871
76872 reset:
76873+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76874+ if (!grsec_enable_blackhole)
76875+#endif
76876 tcp_v6_send_reset(sk, skb);
76877 discard:
76878 if (opt_skb)
76879@@ -1625,12 +1632,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
76880 TCP_SKB_CB(skb)->sacked = 0;
76881
76882 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76883- if (!sk)
76884+ if (!sk) {
76885+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76886+ ret = 1;
76887+#endif
76888 goto no_tcp_socket;
76889+ }
76890
76891 process:
76892- if (sk->sk_state == TCP_TIME_WAIT)
76893+ if (sk->sk_state == TCP_TIME_WAIT) {
76894+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76895+ ret = 2;
76896+#endif
76897 goto do_time_wait;
76898+ }
76899
76900 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
76901 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76902@@ -1679,6 +1694,10 @@ no_tcp_socket:
76903 bad_packet:
76904 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76905 } else {
76906+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76907+ if (!grsec_enable_blackhole || (ret == 1 &&
76908+ (skb->dev->flags & IFF_LOOPBACK)))
76909+#endif
76910 tcp_v6_send_reset(NULL, skb);
76911 }
76912
76913@@ -1885,7 +1904,13 @@ static void get_openreq6(struct seq_file *seq,
76914 uid,
76915 0, /* non standard timer */
76916 0, /* open_requests have no inode */
76917- 0, req);
76918+ 0,
76919+#ifdef CONFIG_GRKERNSEC_HIDESYM
76920+ NULL
76921+#else
76922+ req
76923+#endif
76924+ );
76925 }
76926
76927 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76928@@ -1935,7 +1960,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76929 sock_i_uid(sp),
76930 icsk->icsk_probes_out,
76931 sock_i_ino(sp),
76932- atomic_read(&sp->sk_refcnt), sp,
76933+ atomic_read(&sp->sk_refcnt),
76934+#ifdef CONFIG_GRKERNSEC_HIDESYM
76935+ NULL,
76936+#else
76937+ sp,
76938+#endif
76939 jiffies_to_clock_t(icsk->icsk_rto),
76940 jiffies_to_clock_t(icsk->icsk_ack.ato),
76941 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
76942@@ -1970,7 +2000,13 @@ static void get_timewait6_sock(struct seq_file *seq,
76943 dest->s6_addr32[2], dest->s6_addr32[3], destp,
76944 tw->tw_substate, 0, 0,
76945 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76946- atomic_read(&tw->tw_refcnt), tw);
76947+ atomic_read(&tw->tw_refcnt),
76948+#ifdef CONFIG_GRKERNSEC_HIDESYM
76949+ NULL
76950+#else
76951+ tw
76952+#endif
76953+ );
76954 }
76955
76956 static int tcp6_seq_show(struct seq_file *seq, void *v)
76957diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
76958index f05099f..ea613f0 100644
76959--- a/net/ipv6/udp.c
76960+++ b/net/ipv6/udp.c
76961@@ -50,6 +50,10 @@
76962 #include <linux/seq_file.h>
76963 #include "udp_impl.h"
76964
76965+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76966+extern int grsec_enable_blackhole;
76967+#endif
76968+
76969 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
76970 {
76971 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
76972@@ -615,7 +619,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76973 return rc;
76974 drop:
76975 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76976- atomic_inc(&sk->sk_drops);
76977+ atomic_inc_unchecked(&sk->sk_drops);
76978 kfree_skb(skb);
76979 return -1;
76980 }
76981@@ -673,7 +677,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76982 if (likely(skb1 == NULL))
76983 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
76984 if (!skb1) {
76985- atomic_inc(&sk->sk_drops);
76986+ atomic_inc_unchecked(&sk->sk_drops);
76987 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
76988 IS_UDPLITE(sk));
76989 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
76990@@ -844,6 +848,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76991 goto discard;
76992
76993 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
76994+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76995+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76996+#endif
76997 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
76998
76999 kfree_skb(skb);
77000@@ -1453,8 +1460,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
77001 0, 0L, 0,
77002 sock_i_uid(sp), 0,
77003 sock_i_ino(sp),
77004- atomic_read(&sp->sk_refcnt), sp,
77005- atomic_read(&sp->sk_drops));
77006+ atomic_read(&sp->sk_refcnt),
77007+#ifdef CONFIG_GRKERNSEC_HIDESYM
77008+ NULL,
77009+#else
77010+ sp,
77011+#endif
77012+ atomic_read_unchecked(&sp->sk_drops));
77013 }
77014
77015 int udp6_seq_show(struct seq_file *seq, void *v)
77016diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
77017index 6b9d5a0..4dffaf1 100644
77018--- a/net/irda/ircomm/ircomm_tty.c
77019+++ b/net/irda/ircomm/ircomm_tty.c
77020@@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77021 add_wait_queue(&self->open_wait, &wait);
77022
77023 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
77024- __FILE__,__LINE__, tty->driver->name, self->open_count );
77025+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77026
77027 /* As far as I can see, we protect open_count - Jean II */
77028 spin_lock_irqsave(&self->spinlock, flags);
77029 if (!tty_hung_up_p(filp)) {
77030 extra_count = 1;
77031- self->open_count--;
77032+ local_dec(&self->open_count);
77033 }
77034 spin_unlock_irqrestore(&self->spinlock, flags);
77035- self->blocked_open++;
77036+ local_inc(&self->blocked_open);
77037
77038 while (1) {
77039 if (tty->termios->c_cflag & CBAUD) {
77040@@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77041 }
77042
77043 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
77044- __FILE__,__LINE__, tty->driver->name, self->open_count );
77045+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77046
77047 schedule();
77048 }
77049@@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77050 if (extra_count) {
77051 /* ++ is not atomic, so this should be protected - Jean II */
77052 spin_lock_irqsave(&self->spinlock, flags);
77053- self->open_count++;
77054+ local_inc(&self->open_count);
77055 spin_unlock_irqrestore(&self->spinlock, flags);
77056 }
77057- self->blocked_open--;
77058+ local_dec(&self->blocked_open);
77059
77060 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
77061- __FILE__,__LINE__, tty->driver->name, self->open_count);
77062+ __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
77063
77064 if (!retval)
77065 self->flags |= ASYNC_NORMAL_ACTIVE;
77066@@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
77067 }
77068 /* ++ is not atomic, so this should be protected - Jean II */
77069 spin_lock_irqsave(&self->spinlock, flags);
77070- self->open_count++;
77071+ local_inc(&self->open_count);
77072
77073 tty->driver_data = self;
77074 self->tty = tty;
77075 spin_unlock_irqrestore(&self->spinlock, flags);
77076
77077 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
77078- self->line, self->open_count);
77079+ self->line, local_read(&self->open_count));
77080
77081 /* Not really used by us, but lets do it anyway */
77082 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
77083@@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77084 return;
77085 }
77086
77087- if ((tty->count == 1) && (self->open_count != 1)) {
77088+ if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
77089 /*
77090 * Uh, oh. tty->count is 1, which means that the tty
77091 * structure will be freed. state->count should always
77092@@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77093 */
77094 IRDA_DEBUG(0, "%s(), bad serial port count; "
77095 "tty->count is 1, state->count is %d\n", __func__ ,
77096- self->open_count);
77097- self->open_count = 1;
77098+ local_read(&self->open_count));
77099+ local_set(&self->open_count, 1);
77100 }
77101
77102- if (--self->open_count < 0) {
77103+ if (local_dec_return(&self->open_count) < 0) {
77104 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
77105- __func__, self->line, self->open_count);
77106- self->open_count = 0;
77107+ __func__, self->line, local_read(&self->open_count));
77108+ local_set(&self->open_count, 0);
77109 }
77110- if (self->open_count) {
77111+ if (local_read(&self->open_count)) {
77112 spin_unlock_irqrestore(&self->spinlock, flags);
77113
77114 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
77115@@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77116 tty->closing = 0;
77117 self->tty = NULL;
77118
77119- if (self->blocked_open) {
77120+ if (local_read(&self->blocked_open)) {
77121 if (self->close_delay)
77122 schedule_timeout_interruptible(self->close_delay);
77123 wake_up_interruptible(&self->open_wait);
77124@@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
77125 spin_lock_irqsave(&self->spinlock, flags);
77126 self->flags &= ~ASYNC_NORMAL_ACTIVE;
77127 self->tty = NULL;
77128- self->open_count = 0;
77129+ local_set(&self->open_count, 0);
77130 spin_unlock_irqrestore(&self->spinlock, flags);
77131
77132 wake_up_interruptible(&self->open_wait);
77133@@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
77134 seq_putc(m, '\n');
77135
77136 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
77137- seq_printf(m, "Open count: %d\n", self->open_count);
77138+ seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
77139 seq_printf(m, "Max data size: %d\n", self->max_data_size);
77140 seq_printf(m, "Max header size: %d\n", self->max_header_size);
77141
77142diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
77143index cd6f7a9..e63fe89 100644
77144--- a/net/iucv/af_iucv.c
77145+++ b/net/iucv/af_iucv.c
77146@@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
77147
77148 write_lock_bh(&iucv_sk_list.lock);
77149
77150- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
77151+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77152 while (__iucv_get_sock_by_name(name)) {
77153 sprintf(name, "%08x",
77154- atomic_inc_return(&iucv_sk_list.autobind_name));
77155+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77156 }
77157
77158 write_unlock_bh(&iucv_sk_list.lock);
77159diff --git a/net/key/af_key.c b/net/key/af_key.c
77160index 34e4185..8823368 100644
77161--- a/net/key/af_key.c
77162+++ b/net/key/af_key.c
77163@@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
77164 static u32 get_acqseq(void)
77165 {
77166 u32 res;
77167- static atomic_t acqseq;
77168+ static atomic_unchecked_t acqseq;
77169
77170 do {
77171- res = atomic_inc_return(&acqseq);
77172+ res = atomic_inc_return_unchecked(&acqseq);
77173 } while (!res);
77174 return res;
77175 }
77176diff --git a/net/l2tp/l2tp_ip6.c b/net/l2tp/l2tp_ip6.c
77177index 35e1e4b..9275471 100644
77178--- a/net/l2tp/l2tp_ip6.c
77179+++ b/net/l2tp/l2tp_ip6.c
77180@@ -410,6 +410,7 @@ static int l2tp_ip6_getname(struct socket *sock, struct sockaddr *uaddr,
77181 lsa->l2tp_family = AF_INET6;
77182 lsa->l2tp_flowinfo = 0;
77183 lsa->l2tp_scope_id = 0;
77184+ lsa->l2tp_unused = 0;
77185 if (peer) {
77186 if (!lsk->peer_conn_id)
77187 return -ENOTCONN;
77188diff --git a/net/llc/af_llc.c b/net/llc/af_llc.c
77189index fe5453c..a13c3e23 100644
77190--- a/net/llc/af_llc.c
77191+++ b/net/llc/af_llc.c
77192@@ -969,14 +969,13 @@ static int llc_ui_getname(struct socket *sock, struct sockaddr *uaddr,
77193 struct sockaddr_llc sllc;
77194 struct sock *sk = sock->sk;
77195 struct llc_sock *llc = llc_sk(sk);
77196- int rc = 0;
77197+ int rc = -EBADF;
77198
77199 memset(&sllc, 0, sizeof(sllc));
77200 lock_sock(sk);
77201 if (sock_flag(sk, SOCK_ZAPPED))
77202 goto out;
77203 *uaddrlen = sizeof(sllc);
77204- memset(uaddr, 0, *uaddrlen);
77205 if (peer) {
77206 rc = -ENOTCONN;
77207 if (sk->sk_state != TCP_ESTABLISHED)
77208diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
77209index 3f3cd50..d2cf249 100644
77210--- a/net/mac80211/ieee80211_i.h
77211+++ b/net/mac80211/ieee80211_i.h
77212@@ -28,6 +28,7 @@
77213 #include <net/ieee80211_radiotap.h>
77214 #include <net/cfg80211.h>
77215 #include <net/mac80211.h>
77216+#include <asm/local.h>
77217 #include "key.h"
77218 #include "sta_info.h"
77219
77220@@ -863,7 +864,7 @@ struct ieee80211_local {
77221 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
77222 spinlock_t queue_stop_reason_lock;
77223
77224- int open_count;
77225+ local_t open_count;
77226 int monitors, cooked_mntrs;
77227 /* number of interfaces with corresponding FIF_ flags */
77228 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
77229diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
77230index 8664111..1d6a065 100644
77231--- a/net/mac80211/iface.c
77232+++ b/net/mac80211/iface.c
77233@@ -328,7 +328,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77234 break;
77235 }
77236
77237- if (local->open_count == 0) {
77238+ if (local_read(&local->open_count) == 0) {
77239 res = drv_start(local);
77240 if (res)
77241 goto err_del_bss;
77242@@ -371,7 +371,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77243 break;
77244 }
77245
77246- if (local->monitors == 0 && local->open_count == 0) {
77247+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
77248 res = ieee80211_add_virtual_monitor(local);
77249 if (res)
77250 goto err_stop;
77251@@ -468,7 +468,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77252 mutex_unlock(&local->mtx);
77253
77254 if (coming_up)
77255- local->open_count++;
77256+ local_inc(&local->open_count);
77257
77258 if (hw_reconf_flags)
77259 ieee80211_hw_config(local, hw_reconf_flags);
77260@@ -481,7 +481,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77261 err_del_interface:
77262 drv_remove_interface(local, sdata);
77263 err_stop:
77264- if (!local->open_count)
77265+ if (!local_read(&local->open_count))
77266 drv_stop(local);
77267 err_del_bss:
77268 sdata->bss = NULL;
77269@@ -613,7 +613,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77270 }
77271
77272 if (going_down)
77273- local->open_count--;
77274+ local_dec(&local->open_count);
77275
77276 switch (sdata->vif.type) {
77277 case NL80211_IFTYPE_AP_VLAN:
77278@@ -685,7 +685,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77279
77280 ieee80211_recalc_ps(local, -1);
77281
77282- if (local->open_count == 0) {
77283+ if (local_read(&local->open_count) == 0) {
77284 if (local->ops->napi_poll)
77285 napi_disable(&local->napi);
77286 ieee80211_clear_tx_pending(local);
77287@@ -717,7 +717,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77288 }
77289 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
77290
77291- if (local->monitors == local->open_count && local->monitors > 0)
77292+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
77293 ieee80211_add_virtual_monitor(local);
77294 }
77295
77296diff --git a/net/mac80211/main.c b/net/mac80211/main.c
77297index f5548e9..474a15f 100644
77298--- a/net/mac80211/main.c
77299+++ b/net/mac80211/main.c
77300@@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
77301 local->hw.conf.power_level = power;
77302 }
77303
77304- if (changed && local->open_count) {
77305+ if (changed && local_read(&local->open_count)) {
77306 ret = drv_config(local, changed);
77307 /*
77308 * Goal:
77309diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
77310index af1c4e2..24dbbe3 100644
77311--- a/net/mac80211/pm.c
77312+++ b/net/mac80211/pm.c
77313@@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77314 struct ieee80211_sub_if_data *sdata;
77315 struct sta_info *sta;
77316
77317- if (!local->open_count)
77318+ if (!local_read(&local->open_count))
77319 goto suspend;
77320
77321 ieee80211_scan_cancel(local);
77322@@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77323 cancel_work_sync(&local->dynamic_ps_enable_work);
77324 del_timer_sync(&local->dynamic_ps_timer);
77325
77326- local->wowlan = wowlan && local->open_count;
77327+ local->wowlan = wowlan && local_read(&local->open_count);
77328 if (local->wowlan) {
77329 int err = drv_suspend(local, wowlan);
77330 if (err < 0) {
77331@@ -132,7 +132,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77332 drv_remove_interface(local, sdata);
77333
77334 /* stop hardware - this must stop RX */
77335- if (local->open_count)
77336+ if (local_read(&local->open_count))
77337 ieee80211_stop_device(local);
77338
77339 suspend:
77340diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
77341index 3313c11..bec9f17 100644
77342--- a/net/mac80211/rate.c
77343+++ b/net/mac80211/rate.c
77344@@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
77345
77346 ASSERT_RTNL();
77347
77348- if (local->open_count)
77349+ if (local_read(&local->open_count))
77350 return -EBUSY;
77351
77352 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
77353diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
77354index c97a065..ff61928 100644
77355--- a/net/mac80211/rc80211_pid_debugfs.c
77356+++ b/net/mac80211/rc80211_pid_debugfs.c
77357@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
77358
77359 spin_unlock_irqrestore(&events->lock, status);
77360
77361- if (copy_to_user(buf, pb, p))
77362+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
77363 return -EFAULT;
77364
77365 return p;
77366diff --git a/net/mac80211/util.c b/net/mac80211/util.c
77367index f564b5e..22fee47 100644
77368--- a/net/mac80211/util.c
77369+++ b/net/mac80211/util.c
77370@@ -1224,7 +1224,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
77371 }
77372 #endif
77373 /* everything else happens only if HW was up & running */
77374- if (!local->open_count)
77375+ if (!local_read(&local->open_count))
77376 goto wake_up;
77377
77378 /*
77379diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
77380index 209c1ed..39484dc 100644
77381--- a/net/netfilter/Kconfig
77382+++ b/net/netfilter/Kconfig
77383@@ -851,6 +851,16 @@ config NETFILTER_XT_MATCH_ESP
77384
77385 To compile it as a module, choose M here. If unsure, say N.
77386
77387+config NETFILTER_XT_MATCH_GRADM
77388+ tristate '"gradm" match support'
77389+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
77390+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
77391+ ---help---
77392+ The gradm match allows to match on grsecurity RBAC being enabled.
77393+ It is useful when iptables rules are applied early on bootup to
77394+ prevent connections to the machine (except from a trusted host)
77395+ while the RBAC system is disabled.
77396+
77397 config NETFILTER_XT_MATCH_HASHLIMIT
77398 tristate '"hashlimit" match support'
77399 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
77400diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
77401index 4e7960c..89e48d4 100644
77402--- a/net/netfilter/Makefile
77403+++ b/net/netfilter/Makefile
77404@@ -87,6 +87,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
77405 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
77406 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
77407 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
77408+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
77409 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
77410 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
77411 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
77412diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
77413index 1548df9..98ad9b4 100644
77414--- a/net/netfilter/ipvs/ip_vs_conn.c
77415+++ b/net/netfilter/ipvs/ip_vs_conn.c
77416@@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
77417 /* Increase the refcnt counter of the dest */
77418 atomic_inc(&dest->refcnt);
77419
77420- conn_flags = atomic_read(&dest->conn_flags);
77421+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
77422 if (cp->protocol != IPPROTO_UDP)
77423 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
77424 flags = cp->flags;
77425@@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
77426 atomic_set(&cp->refcnt, 1);
77427
77428 atomic_set(&cp->n_control, 0);
77429- atomic_set(&cp->in_pkts, 0);
77430+ atomic_set_unchecked(&cp->in_pkts, 0);
77431
77432 atomic_inc(&ipvs->conn_count);
77433 if (flags & IP_VS_CONN_F_NO_CPORT)
77434@@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
77435
77436 /* Don't drop the entry if its number of incoming packets is not
77437 located in [0, 8] */
77438- i = atomic_read(&cp->in_pkts);
77439+ i = atomic_read_unchecked(&cp->in_pkts);
77440 if (i > 8 || i < 0) return 0;
77441
77442 if (!todrop_rate[i]) return 0;
77443diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
77444index a54b018c..07e0120 100644
77445--- a/net/netfilter/ipvs/ip_vs_core.c
77446+++ b/net/netfilter/ipvs/ip_vs_core.c
77447@@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
77448 ret = cp->packet_xmit(skb, cp, pd->pp);
77449 /* do not touch skb anymore */
77450
77451- atomic_inc(&cp->in_pkts);
77452+ atomic_inc_unchecked(&cp->in_pkts);
77453 ip_vs_conn_put(cp);
77454 return ret;
77455 }
77456@@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
77457 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
77458 pkts = sysctl_sync_threshold(ipvs);
77459 else
77460- pkts = atomic_add_return(1, &cp->in_pkts);
77461+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77462
77463 if (ipvs->sync_state & IP_VS_STATE_MASTER)
77464 ip_vs_sync_conn(net, cp, pkts);
77465diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
77466index 84444dd..f91c066 100644
77467--- a/net/netfilter/ipvs/ip_vs_ctl.c
77468+++ b/net/netfilter/ipvs/ip_vs_ctl.c
77469@@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
77470 ip_vs_rs_hash(ipvs, dest);
77471 write_unlock_bh(&ipvs->rs_lock);
77472 }
77473- atomic_set(&dest->conn_flags, conn_flags);
77474+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
77475
77476 /* bind the service */
77477 if (!dest->svc) {
77478@@ -2074,7 +2074,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
77479 " %-7s %-6d %-10d %-10d\n",
77480 &dest->addr.in6,
77481 ntohs(dest->port),
77482- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77483+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77484 atomic_read(&dest->weight),
77485 atomic_read(&dest->activeconns),
77486 atomic_read(&dest->inactconns));
77487@@ -2085,7 +2085,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
77488 "%-7s %-6d %-10d %-10d\n",
77489 ntohl(dest->addr.ip),
77490 ntohs(dest->port),
77491- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
77492+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
77493 atomic_read(&dest->weight),
77494 atomic_read(&dest->activeconns),
77495 atomic_read(&dest->inactconns));
77496@@ -2555,7 +2555,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
77497
77498 entry.addr = dest->addr.ip;
77499 entry.port = dest->port;
77500- entry.conn_flags = atomic_read(&dest->conn_flags);
77501+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
77502 entry.weight = atomic_read(&dest->weight);
77503 entry.u_threshold = dest->u_threshold;
77504 entry.l_threshold = dest->l_threshold;
77505@@ -2759,6 +2759,7 @@ do_ip_vs_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77506 {
77507 struct ip_vs_timeout_user t;
77508
77509+ memset(&t, 0, sizeof(t));
77510 __ip_vs_get_timeouts(net, &t);
77511 if (copy_to_user(user, &t, sizeof(t)) != 0)
77512 ret = -EFAULT;
77513@@ -3089,7 +3090,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
77514 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
77515 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
77516 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
77517- (atomic_read(&dest->conn_flags) &
77518+ (atomic_read_unchecked(&dest->conn_flags) &
77519 IP_VS_CONN_F_FWD_MASK)) ||
77520 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
77521 atomic_read(&dest->weight)) ||
77522diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
77523index effa10c..9058928 100644
77524--- a/net/netfilter/ipvs/ip_vs_sync.c
77525+++ b/net/netfilter/ipvs/ip_vs_sync.c
77526@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
77527 cp = cp->control;
77528 if (cp) {
77529 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
77530- pkts = atomic_add_return(1, &cp->in_pkts);
77531+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77532 else
77533 pkts = sysctl_sync_threshold(ipvs);
77534 ip_vs_sync_conn(net, cp->control, pkts);
77535@@ -758,7 +758,7 @@ control:
77536 if (!cp)
77537 return;
77538 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
77539- pkts = atomic_add_return(1, &cp->in_pkts);
77540+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
77541 else
77542 pkts = sysctl_sync_threshold(ipvs);
77543 goto sloop;
77544@@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
77545
77546 if (opt)
77547 memcpy(&cp->in_seq, opt, sizeof(*opt));
77548- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77549+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
77550 cp->state = state;
77551 cp->old_state = cp->state;
77552 /*
77553diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
77554index 7fd66de..e6fb361 100644
77555--- a/net/netfilter/ipvs/ip_vs_xmit.c
77556+++ b/net/netfilter/ipvs/ip_vs_xmit.c
77557@@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
77558 else
77559 rc = NF_ACCEPT;
77560 /* do not touch skb anymore */
77561- atomic_inc(&cp->in_pkts);
77562+ atomic_inc_unchecked(&cp->in_pkts);
77563 goto out;
77564 }
77565
77566@@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
77567 else
77568 rc = NF_ACCEPT;
77569 /* do not touch skb anymore */
77570- atomic_inc(&cp->in_pkts);
77571+ atomic_inc_unchecked(&cp->in_pkts);
77572 goto out;
77573 }
77574
77575diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
77576index ac3af97..c134c21 100644
77577--- a/net/netfilter/nf_conntrack_core.c
77578+++ b/net/netfilter/nf_conntrack_core.c
77579@@ -1530,6 +1530,10 @@ err_proto:
77580 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
77581 #define DYING_NULLS_VAL ((1<<30)+1)
77582
77583+#ifdef CONFIG_GRKERNSEC_HIDESYM
77584+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
77585+#endif
77586+
77587 static int nf_conntrack_init_net(struct net *net)
77588 {
77589 int ret;
77590@@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
77591 goto err_stat;
77592 }
77593
77594+#ifdef CONFIG_GRKERNSEC_HIDESYM
77595+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
77596+#else
77597 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
77598+#endif
77599 if (!net->ct.slabname) {
77600 ret = -ENOMEM;
77601 goto err_slabname;
77602diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
77603index 3c3cfc0..7a6ea1a 100644
77604--- a/net/netfilter/nfnetlink_log.c
77605+++ b/net/netfilter/nfnetlink_log.c
77606@@ -70,7 +70,7 @@ struct nfulnl_instance {
77607 };
77608
77609 static DEFINE_SPINLOCK(instances_lock);
77610-static atomic_t global_seq;
77611+static atomic_unchecked_t global_seq;
77612
77613 #define INSTANCE_BUCKETS 16
77614 static struct hlist_head instance_table[INSTANCE_BUCKETS];
77615@@ -517,7 +517,7 @@ __build_packet_message(struct nfulnl_instance *inst,
77616 /* global sequence number */
77617 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
77618 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
77619- htonl(atomic_inc_return(&global_seq))))
77620+ htonl(atomic_inc_return_unchecked(&global_seq))))
77621 goto nla_put_failure;
77622
77623 if (data_len) {
77624diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
77625new file mode 100644
77626index 0000000..6905327
77627--- /dev/null
77628+++ b/net/netfilter/xt_gradm.c
77629@@ -0,0 +1,51 @@
77630+/*
77631+ * gradm match for netfilter
77632